diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f42fad86..2c9fb8c92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ set(DUCKDB_INCLUDE_DIRS src/duckdb/third_party/brotli/common src/duckdb/third_party/brotli/dec src/duckdb/third_party/brotli/enc + src/duckdb/third_party/mbedtls src/duckdb/third_party/mbedtls/include src/duckdb/third_party/mbedtls/library src/duckdb/third_party/miniz @@ -104,7 +105,6 @@ set(DUCKDB_SRC_FILES src/duckdb/ub_src_common_crypto.cpp src/duckdb/ub_src_common_enums.cpp src/duckdb/ub_src_common_exception.cpp - src/duckdb/ub_src_common_multi_file.cpp src/duckdb/ub_src_common_operator.cpp src/duckdb/ub_src_common_progress_bar.cpp src/duckdb/ub_src_common_row_operations.cpp @@ -279,14 +279,16 @@ set(DUCKDB_SRC_FILES src/duckdb/third_party/libpg_query/src_backend_parser_scansup.cpp src/duckdb/third_party/libpg_query/src_common_keywords.cpp src/duckdb/third_party/mbedtls/library/aes.cpp + src/duckdb/third_party/mbedtls/library/aria.cpp src/duckdb/third_party/mbedtls/library/asn1parse.cpp - src/duckdb/third_party/mbedtls/library/asn1write.cpp src/duckdb/third_party/mbedtls/library/base64.cpp src/duckdb/third_party/mbedtls/library/bignum.cpp - src/duckdb/third_party/mbedtls/library/bignum_core.cpp + src/duckdb/third_party/mbedtls/library/camellia.cpp src/duckdb/third_party/mbedtls/library/cipher.cpp src/duckdb/third_party/mbedtls/library/cipher_wrap.cpp src/duckdb/third_party/mbedtls/library/constant_time.cpp + src/duckdb/third_party/mbedtls/library/entropy.cpp + src/duckdb/third_party/mbedtls/library/entropy_poll.cpp src/duckdb/third_party/mbedtls/library/gcm.cpp src/duckdb/third_party/mbedtls/library/md.cpp src/duckdb/third_party/mbedtls/library/oid.cpp @@ -294,12 +296,12 @@ set(DUCKDB_SRC_FILES src/duckdb/third_party/mbedtls/library/pk.cpp src/duckdb/third_party/mbedtls/library/pk_wrap.cpp src/duckdb/third_party/mbedtls/library/pkparse.cpp - src/duckdb/third_party/mbedtls/library/platform.cpp src/duckdb/third_party/mbedtls/library/platform_util.cpp src/duckdb/third_party/mbedtls/library/rsa.cpp src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.cpp src/duckdb/third_party/mbedtls/library/sha1.cpp src/duckdb/third_party/mbedtls/library/sha256.cpp + src/duckdb/third_party/mbedtls/library/sha512.cpp src/duckdb/third_party/mbedtls/mbedtls_wrapper.cpp src/duckdb/third_party/yyjson/yyjson.cpp src/duckdb/third_party/zstd/common/debug.cpp @@ -334,45 +336,41 @@ set(DUCKDB_SRC_FILES src/duckdb/third_party/zstd/dict/divsufsort.cpp src/duckdb/third_party/zstd/dict/fastcover.cpp src/duckdb/third_party/zstd/dict/zdict.cpp - src/duckdb/extension/core_functions/lambda_functions.cpp src/duckdb/extension/core_functions/core_functions_extension.cpp + src/duckdb/extension/core_functions/lambda_functions.cpp src/duckdb/extension/core_functions/function_list.cpp + src/duckdb/ub_extension_core_functions_aggregate_algebraic.cpp src/duckdb/ub_extension_core_functions_aggregate_distributive.cpp - src/duckdb/ub_extension_core_functions_aggregate_regression.cpp - src/duckdb/ub_extension_core_functions_aggregate_nested.cpp src/duckdb/ub_extension_core_functions_aggregate_holistic.cpp - src/duckdb/ub_extension_core_functions_aggregate_algebraic.cpp - src/duckdb/ub_extension_core_functions_scalar_union.cpp + src/duckdb/ub_extension_core_functions_aggregate_nested.cpp + src/duckdb/ub_extension_core_functions_aggregate_regression.cpp + src/duckdb/ub_extension_core_functions_scalar_struct.cpp src/duckdb/ub_extension_core_functions_scalar_generic.cpp - src/duckdb/ub_extension_core_functions_scalar_enum.cpp + src/duckdb/ub_extension_core_functions_scalar_string.cpp src/duckdb/ub_extension_core_functions_scalar_blob.cpp - src/duckdb/ub_extension_core_functions_scalar_array.cpp - src/duckdb/ub_extension_core_functions_scalar_map.cpp + src/duckdb/ub_extension_core_functions_scalar_enum.cpp + src/duckdb/ub_extension_core_functions_scalar_bit.cpp src/duckdb/ub_extension_core_functions_scalar_math.cpp - src/duckdb/ub_extension_core_functions_scalar_debug.cpp - src/duckdb/ub_extension_core_functions_scalar_list.cpp - src/duckdb/ub_extension_core_functions_scalar_string.cpp src/duckdb/ub_extension_core_functions_scalar_random.cpp src/duckdb/ub_extension_core_functions_scalar_date.cpp - src/duckdb/ub_extension_core_functions_scalar_struct.cpp + src/duckdb/ub_extension_core_functions_scalar_debug.cpp + src/duckdb/ub_extension_core_functions_scalar_list.cpp + src/duckdb/ub_extension_core_functions_scalar_array.cpp src/duckdb/ub_extension_core_functions_scalar_operators.cpp - src/duckdb/ub_extension_core_functions_scalar_bit.cpp + src/duckdb/ub_extension_core_functions_scalar_union.cpp + src/duckdb/ub_extension_core_functions_scalar_map.cpp + src/duckdb/extension/parquet/column_reader.cpp src/duckdb/extension/parquet/column_writer.cpp - src/duckdb/extension/parquet/serialize_parquet.cpp - src/duckdb/extension/parquet/parquet_float16.cpp + src/duckdb/extension/parquet/parquet_crypto.cpp + src/duckdb/extension/parquet/parquet_extension.cpp + src/duckdb/extension/parquet/parquet_metadata.cpp src/duckdb/extension/parquet/parquet_reader.cpp src/duckdb/extension/parquet/parquet_statistics.cpp + src/duckdb/extension/parquet/parquet_timestamp.cpp src/duckdb/extension/parquet/parquet_writer.cpp + src/duckdb/extension/parquet/serialize_parquet.cpp src/duckdb/extension/parquet/zstd_file_system.cpp - src/duckdb/extension/parquet/parquet_crypto.cpp - src/duckdb/extension/parquet/parquet_extension.cpp - src/duckdb/extension/parquet/column_reader.cpp src/duckdb/extension/parquet/geo_parquet.cpp - src/duckdb/extension/parquet/parquet_metadata.cpp - src/duckdb/extension/parquet/parquet_timestamp.cpp - src/duckdb/ub_extension_parquet_writer.cpp - src/duckdb/ub_extension_parquet_reader.cpp - src/duckdb/ub_extension_parquet_decoder.cpp src/duckdb/third_party/parquet/parquet_types.cpp src/duckdb/third_party/thrift/thrift/protocol/TProtocol.cpp src/duckdb/third_party/thrift/thrift/transport/TTransportException.cpp @@ -411,32 +409,31 @@ set(DUCKDB_SRC_FILES src/duckdb/third_party/brotli/enc/metablock.cpp src/duckdb/third_party/brotli/enc/static_dict.cpp src/duckdb/third_party/brotli/enc/utf8_util.cpp - src/duckdb/extension/icu/./icu-timezone.cpp + src/duckdb/extension/icu/./icu-current.cpp + src/duckdb/extension/icu/./icu-datepart.cpp src/duckdb/extension/icu/./icu-timebucket.cpp - src/duckdb/extension/icu/./icu-strptime.cpp src/duckdb/extension/icu/./icu-datefunc.cpp - src/duckdb/extension/icu/./icu_extension.cpp - src/duckdb/extension/icu/./icu-table-range.cpp - src/duckdb/extension/icu/./icu-datesub.cpp - src/duckdb/extension/icu/./icu-list-range.cpp src/duckdb/extension/icu/./icu-makedate.cpp src/duckdb/extension/icu/./icu-datetrunc.cpp - src/duckdb/extension/icu/./icu-datepart.cpp - src/duckdb/extension/icu/./icu-current.cpp + src/duckdb/extension/icu/./icu-strptime.cpp + src/duckdb/extension/icu/./icu-datesub.cpp + src/duckdb/extension/icu/./icu-timezone.cpp + src/duckdb/extension/icu/./icu_extension.cpp src/duckdb/extension/icu/./icu-dateadd.cpp + src/duckdb/extension/icu/./icu-list-range.cpp + src/duckdb/extension/icu/./icu-table-range.cpp src/duckdb/ub_extension_icu_third_party_icu_common.cpp src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp src/duckdb/extension/icu/third_party/icu/stubdata/stubdata.cpp - src/duckdb/extension/json/json_multi_file_info.cpp - src/duckdb/extension/json/json_deserializer.cpp + src/duckdb/extension/json/buffered_json_reader.cpp src/duckdb/extension/json/json_enums.cpp - src/duckdb/extension/json/json_scan.cpp - src/duckdb/extension/json/json_functions.cpp - src/duckdb/extension/json/serialize_json.cpp - src/duckdb/extension/json/json_common.cpp - src/duckdb/extension/json/json_reader.cpp src/duckdb/extension/json/json_extension.cpp + src/duckdb/extension/json/json_common.cpp + src/duckdb/extension/json/json_functions.cpp + src/duckdb/extension/json/json_scan.cpp src/duckdb/extension/json/json_serializer.cpp + src/duckdb/extension/json/json_deserializer.cpp + src/duckdb/extension/json/serialize_json.cpp src/duckdb/ub_extension_json_json_functions.cpp) set(JEMACLLOC_SRC_FILES diff --git a/src/duckdb/extension/core_functions/aggregate/algebraic/avg.cpp b/src/duckdb/extension/core_functions/aggregate/algebraic/avg.cpp index 450f388b5..f242b2770 100644 --- a/src/duckdb/extension/core_functions/aggregate/algebraic/avg.cpp +++ b/src/duckdb/extension/core_functions/aggregate/algebraic/avg.cpp @@ -1,7 +1,6 @@ #include "core_functions/aggregate/algebraic_functions.hpp" #include "core_functions/aggregate/sum_helpers.hpp" #include "duckdb/common/types/hugeint.hpp" -#include "duckdb/common/types/time.hpp" #include "duckdb/common/exception.hpp" #include "duckdb/function/function_set.hpp" #include "duckdb/planner/expression.hpp" @@ -23,21 +22,6 @@ struct AvgState { } }; -struct IntervalAvgState { - int64_t count; - interval_t value; - - void Initialize() { - this->count = 0; - this->value = interval_t(); - } - - void Combine(const IntervalAvgState &other) { - this->count += other.count; - this->value = AddOperator::Operation(this->value, other.value); - } -}; - struct KahanAvgState { uint64_t count; double value; @@ -121,20 +105,6 @@ struct IntegerAverageOperationHugeint : public BaseSumOperation { - template - static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) { - if (state.count == 0) { - finalize_data.ReturnNull(); - } else { - hugeint_t remainder; - target = Hugeint::Cast(Hugeint::DivMod(state.value, state.count, remainder)); - // Round the result - target += (remainder > (state.count / 2)); - } - } -}; - struct HugeintAverageOperation : public BaseSumOperation { template static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) { @@ -169,74 +139,6 @@ struct KahanAverageOperation : public BaseSumOperation { - // Override BaseSumOperation::Initialize because - // IntervalAvgState does not have an assignment constructor from 0 - static void Initialize(IntervalAvgState &state) { - AverageSetOperation::Initialize(state); - } - - template - static void Finalize(STATE &state, RESULT_TYPE &target, AggregateFinalizeData &finalize_data) { - if (state.count == 0) { - finalize_data.ReturnNull(); - } else { - // DivideOperator does not borrow fractions right, - // TODO: Maybe it should? - // Copy PG implementation. - const auto &value = state.value; - const auto count = UnsafeNumericCast(state.count); - - target.months = value.months / count; - auto months_remainder = value.months % count; - - target.days = value.days / count; - auto days_remainder = value.days % count; - - target.micros = value.micros / count; - auto micros_remainder = value.micros % count; - - // Shift the remainders right - months_remainder *= Interval::DAYS_PER_MONTH; - target.days += months_remainder / count; - days_remainder += months_remainder % count; - - days_remainder *= Interval::MICROS_PER_DAY; - micros_remainder += days_remainder / count; - target.micros += micros_remainder; - } - } -}; - -struct TimeTZAverageOperation : public BaseSumOperation { - template - static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &aggr_unary) { - const auto micros = Time::NormalizeTimeTZ(input).micros; - AverageSetOperation::template AddValues(state, 1); - AddToHugeint::template AddNumber(state, micros); - } - - template - static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &aggr_unary, idx_t count) { - const auto micros = Time::NormalizeTimeTZ(input).micros; - AverageSetOperation::template AddValues(state, count); - AddToHugeint::template AddConstant(state, micros, count); - } - - template - static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) { - if (state.count == 0) { - finalize_data.ReturnNull(); - } else { - uint64_t remainder; - auto micros = Hugeint::Cast(Hugeint::DivModPositive(state.value, state.count, remainder)); - // Round the result - micros += (remainder > (state.count / 2)); - target = dtime_tz_t(dtime_t(micros), 0); - } - } -}; - AggregateFunction GetAverageAggregate(PhysicalType type) { switch (type) { case PhysicalType::INT16: { @@ -255,10 +157,6 @@ AggregateFunction GetAverageAggregate(PhysicalType type) { return AggregateFunction::UnaryAggregate, hugeint_t, double, HugeintAverageOperation>( LogicalType::HUGEINT, LogicalType::DOUBLE); } - case PhysicalType::INTERVAL: { - return AggregateFunction::UnaryAggregate( - LogicalType::INTERVAL, LogicalType::INTERVAL); - } default: throw InternalException("Unimplemented average aggregate"); } @@ -285,20 +183,8 @@ AggregateFunctionSet AvgFun::GetFunctions() { avg.AddFunction(GetAverageAggregate(PhysicalType::INT32)); avg.AddFunction(GetAverageAggregate(PhysicalType::INT64)); avg.AddFunction(GetAverageAggregate(PhysicalType::INT128)); - avg.AddFunction(GetAverageAggregate(PhysicalType::INTERVAL)); avg.AddFunction(AggregateFunction::UnaryAggregate, double, double, NumericAverageOperation>( LogicalType::DOUBLE, LogicalType::DOUBLE)); - - avg.AddFunction(AggregateFunction::UnaryAggregate, int64_t, int64_t, DiscreteAverageOperation>( - LogicalType::TIMESTAMP, LogicalType::TIMESTAMP)); - avg.AddFunction(AggregateFunction::UnaryAggregate, int64_t, int64_t, DiscreteAverageOperation>( - LogicalType::TIMESTAMP_TZ, LogicalType::TIMESTAMP_TZ)); - avg.AddFunction(AggregateFunction::UnaryAggregate, int64_t, int64_t, DiscreteAverageOperation>( - LogicalType::TIME, LogicalType::TIME)); - avg.AddFunction( - AggregateFunction::UnaryAggregate, dtime_tz_t, dtime_tz_t, TimeTZAverageOperation>( - LogicalType::TIME_TZ, LogicalType::TIME_TZ)); - return avg; } diff --git a/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp b/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp index edb6c77c5..63c112b3c 100644 --- a/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp +++ b/src/duckdb/extension/core_functions/aggregate/distributive/arg_min_max.cpp @@ -545,8 +545,8 @@ class ArgMinMaxNState { BinaryAggregateHeap heap; bool is_initialized = false; - void Initialize(ArenaAllocator &allocator, idx_t nval) { - heap.Initialize(allocator, nval); + void Initialize(idx_t nval) { + heap.Initialize(nval); is_initialized = true; } }; @@ -601,7 +601,7 @@ static void ArgMinMaxNUpdate(Vector inputs[], AggregateInputData &aggr_input, id if (nval >= MAX_N) { throw InvalidInputException("Invalid input for arg_min/arg_max: n value must be < %d", MAX_N); } - state.Initialize(aggr_input.allocator, UnsafeNumericCast(nval)); + state.Initialize(UnsafeNumericCast(nval)); } // Now add the input to the heap diff --git a/src/duckdb/extension/core_functions/core_functions_extension.cpp b/src/duckdb/extension/core_functions/core_functions_extension.cpp index 0fe3f26f9..8bf09b800 100644 --- a/src/duckdb/extension/core_functions/core_functions_extension.cpp +++ b/src/duckdb/extension/core_functions/core_functions_extension.cpp @@ -12,7 +12,6 @@ namespace duckdb { template static void FillExtraInfo(const StaticFunctionDefinition &function, T &info) { info.internal = true; - info.alias_of = function.alias_of; FillFunctionDescriptions(function, info); info.on_conflict = OnCreateConflict::ALTER_ON_CONFLICT; } diff --git a/src/duckdb/extension/core_functions/function_list.cpp b/src/duckdb/extension/core_functions/function_list.cpp index 1582fae08..fb8550c67 100644 --- a/src/duckdb/extension/core_functions/function_list.cpp +++ b/src/duckdb/extension/core_functions/function_list.cpp @@ -24,27 +24,27 @@ namespace duckdb { // Scalar Function -#define DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, _PARAM::GetFunction, nullptr, nullptr, nullptr } -#define DUCKDB_SCALAR_FUNCTION(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_SCALAR_FUNCTION_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::GetFunction, nullptr, nullptr, nullptr } +#define DUCKDB_SCALAR_FUNCTION(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_SCALAR_FUNCTION_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name) // Scalar Function Set -#define DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, nullptr, _PARAM::GetFunctions, nullptr, nullptr } -#define DUCKDB_SCALAR_FUNCTION_SET(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_SCALAR_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, nullptr, _PARAM::GetFunctions, nullptr, nullptr } +#define DUCKDB_SCALAR_FUNCTION_SET(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_SCALAR_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name) // Aggregate Function -#define DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, nullptr, nullptr, _PARAM::GetFunction, nullptr } -#define DUCKDB_AGGREGATE_FUNCTION(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_AGGREGATE_FUNCTION_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, nullptr, nullptr, _PARAM::GetFunction, nullptr } +#define DUCKDB_AGGREGATE_FUNCTION(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_AGGREGATE_FUNCTION_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name) // Aggregate Function Set -#define DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, nullptr, nullptr, nullptr, _PARAM::GetFunctions } -#define DUCKDB_AGGREGATE_FUNCTION_SET(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_AGGREGATE_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, nullptr, nullptr, nullptr, _PARAM::GetFunctions } +#define DUCKDB_AGGREGATE_FUNCTION_SET(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_AGGREGATE_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name) #define FINAL_FUNCTION \ - { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } + { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } // this list is generated by scripts/generate_functions.py static const StaticFunctionDefinition core_functions[] = { @@ -94,7 +94,7 @@ static const StaticFunctionDefinition core_functions[] = { DUCKDB_SCALAR_FUNCTION_SET(ArrayInnerProductFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ArrayNegativeDotProductFun), DUCKDB_SCALAR_FUNCTION_SET(ArrayNegativeInnerProductFun), - DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ArrayReduceFun), + DUCKDB_SCALAR_FUNCTION_ALIAS(ArrayReduceFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ArrayReverseSortFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ArraySliceFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ArraySortFun), @@ -243,7 +243,7 @@ static const StaticFunctionDefinition core_functions[] = { DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ListNegativeDotProductFun), DUCKDB_SCALAR_FUNCTION_SET(ListNegativeInnerProductFun), DUCKDB_SCALAR_FUNCTION_ALIAS(ListPackFun), - DUCKDB_SCALAR_FUNCTION_SET(ListReduceFun), + DUCKDB_SCALAR_FUNCTION(ListReduceFun), DUCKDB_SCALAR_FUNCTION_SET(ListReverseSortFun), DUCKDB_SCALAR_FUNCTION_SET(ListSliceFun), DUCKDB_SCALAR_FUNCTION_SET(ListSortFun), @@ -304,7 +304,7 @@ static const StaticFunctionDefinition core_functions[] = { DUCKDB_SCALAR_FUNCTION(RadiansFun), DUCKDB_SCALAR_FUNCTION(RandomFun), DUCKDB_SCALAR_FUNCTION_SET(ListRangeFun), - DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ReduceFun), + DUCKDB_SCALAR_FUNCTION_ALIAS(ReduceFun), DUCKDB_AGGREGATE_FUNCTION(RegrAvgxFun), DUCKDB_AGGREGATE_FUNCTION(RegrAvgyFun), DUCKDB_AGGREGATE_FUNCTION(RegrCountFun), @@ -354,21 +354,21 @@ static const StaticFunctionDefinition core_functions[] = { DUCKDB_SCALAR_FUNCTION_SET(ToBaseFun), DUCKDB_SCALAR_FUNCTION(ToBase64Fun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ToBinaryFun), - DUCKDB_SCALAR_FUNCTION_SET(ToCenturiesFun), - DUCKDB_SCALAR_FUNCTION_SET(ToDaysFun), - DUCKDB_SCALAR_FUNCTION_SET(ToDecadesFun), + DUCKDB_SCALAR_FUNCTION(ToCenturiesFun), + DUCKDB_SCALAR_FUNCTION(ToDaysFun), + DUCKDB_SCALAR_FUNCTION(ToDecadesFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ToHexFun), DUCKDB_SCALAR_FUNCTION(ToHoursFun), DUCKDB_SCALAR_FUNCTION(ToMicrosecondsFun), - DUCKDB_SCALAR_FUNCTION_SET(ToMillenniaFun), + DUCKDB_SCALAR_FUNCTION(ToMillenniaFun), DUCKDB_SCALAR_FUNCTION(ToMillisecondsFun), DUCKDB_SCALAR_FUNCTION(ToMinutesFun), - DUCKDB_SCALAR_FUNCTION_SET(ToMonthsFun), - DUCKDB_SCALAR_FUNCTION_SET(ToQuartersFun), + DUCKDB_SCALAR_FUNCTION(ToMonthsFun), + DUCKDB_SCALAR_FUNCTION(ToQuartersFun), DUCKDB_SCALAR_FUNCTION(ToSecondsFun), DUCKDB_SCALAR_FUNCTION(ToTimestampFun), - DUCKDB_SCALAR_FUNCTION_SET(ToWeeksFun), - DUCKDB_SCALAR_FUNCTION_SET(ToYearsFun), + DUCKDB_SCALAR_FUNCTION(ToWeeksFun), + DUCKDB_SCALAR_FUNCTION(ToYearsFun), DUCKDB_SCALAR_FUNCTION_ALIAS(TransactionTimestampFun), DUCKDB_SCALAR_FUNCTION(TranslateFun), DUCKDB_SCALAR_FUNCTION_SET(TrimFun), @@ -385,10 +385,6 @@ static const StaticFunctionDefinition core_functions[] = { DUCKDB_SCALAR_FUNCTION(UrlDecodeFun), DUCKDB_SCALAR_FUNCTION(UrlEncodeFun), DUCKDB_SCALAR_FUNCTION(UUIDFun), - DUCKDB_SCALAR_FUNCTION(UUIDExtractTimestampFun), - DUCKDB_SCALAR_FUNCTION(UUIDExtractVersionFun), - DUCKDB_SCALAR_FUNCTION(UUIDv4Fun), - DUCKDB_SCALAR_FUNCTION(UUIDv7Fun), DUCKDB_AGGREGATE_FUNCTION(VarPopFun), DUCKDB_AGGREGATE_FUNCTION(VarSampFun), DUCKDB_AGGREGATE_FUNCTION_ALIAS(VarianceFun), diff --git a/src/duckdb/extension/core_functions/include/core_functions/aggregate/algebraic_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/aggregate/algebraic_functions.hpp index e6e6f1757..da08c769a 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/aggregate/algebraic_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/aggregate/algebraic_functions.hpp @@ -20,7 +20,6 @@ struct AvgFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Calculates the average value for all tuples in x."; static constexpr const char *Example = "SUM(x) / COUNT(*)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -36,7 +35,6 @@ struct CorrFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the correlation coefficient for non-null pairs in a group."; static constexpr const char *Example = "COVAR_POP(y, x) / (STDDEV_POP(x) * STDDEV_POP(y))"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -46,7 +44,6 @@ struct CovarPopFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the population covariance of input values."; static constexpr const char *Example = "(SUM(x*y) - SUM(x) * SUM(y) / COUNT(*)) / COUNT(*)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -56,7 +53,6 @@ struct CovarSampFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the sample covariance for non-null pairs in a group."; static constexpr const char *Example = "(SUM(x*y) - SUM(x) * SUM(y) / COUNT(*)) / (COUNT(*) - 1)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -66,7 +62,6 @@ struct FAvgFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Calculates the average using a more accurate floating point summation (Kahan Sum)"; static constexpr const char *Example = "favg(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -76,7 +71,6 @@ struct StandardErrorOfTheMeanFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the standard error of the mean"; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -86,7 +80,6 @@ struct StdDevPopFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the population standard deviation."; static constexpr const char *Example = "sqrt(var_pop(x))"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -96,7 +89,6 @@ struct StdDevSampFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the sample standard deviation"; static constexpr const char *Example = "sqrt(var_samp(x))"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -112,7 +104,6 @@ struct VarPopFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the population variance."; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -122,7 +113,6 @@ struct VarSampFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the sample variance of all input values."; static constexpr const char *Example = "(SUM(x^2) - SUM(x)^2 / COUNT(x)) / (COUNT(x) - 1)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/aggregate/distributive_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/aggregate/distributive_functions.hpp index 5bee28da1..50c0197a9 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/aggregate/distributive_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/aggregate/distributive_functions.hpp @@ -20,7 +20,6 @@ struct ApproxCountDistinctFun { static constexpr const char *Parameters = "any"; static constexpr const char *Description = "Computes the approximate count of distinct elements using HyperLogLog."; static constexpr const char *Example = "approx_count_distinct(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct ArgMinFun { static constexpr const char *Parameters = "arg,val"; static constexpr const char *Description = "Finds the row with the minimum val. Calculates the non-NULL arg expression at that row."; static constexpr const char *Example = "arg_min(A,B)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -52,7 +50,6 @@ struct ArgMinNullFun { static constexpr const char *Parameters = "arg,val"; static constexpr const char *Description = "Finds the row with the minimum val. Calculates the arg expression at that row."; static constexpr const char *Example = "arg_min_null(A,B)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -62,7 +59,6 @@ struct ArgMaxFun { static constexpr const char *Parameters = "arg,val"; static constexpr const char *Description = "Finds the row with the maximum val. Calculates the non-NULL arg expression at that row."; static constexpr const char *Example = "arg_max(A,B)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -84,7 +80,6 @@ struct ArgMaxNullFun { static constexpr const char *Parameters = "arg,val"; static constexpr const char *Description = "Finds the row with the maximum val. Calculates the arg expression at that row."; static constexpr const char *Example = "arg_max_null(A,B)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -94,7 +89,6 @@ struct BitAndFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the bitwise AND of all bits in a given expression."; static constexpr const char *Example = "bit_and(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -104,7 +98,6 @@ struct BitOrFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the bitwise OR of all bits in a given expression."; static constexpr const char *Example = "bit_or(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -114,7 +107,6 @@ struct BitXorFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the bitwise XOR of all bits in a given expression."; static constexpr const char *Example = "bit_xor(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -124,7 +116,6 @@ struct BitstringAggFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns a bitstring with bits set for each distinct value."; static constexpr const char *Example = "bitstring_agg(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -134,7 +125,6 @@ struct BoolAndFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns TRUE if every input value is TRUE, otherwise FALSE."; static constexpr const char *Example = "bool_and(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -144,7 +134,6 @@ struct BoolOrFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns TRUE if any input value is TRUE, otherwise FALSE."; static constexpr const char *Example = "bool_or(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -154,7 +143,6 @@ struct CountIfFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Counts the total number of TRUE values for a boolean column"; static constexpr const char *Example = "count_if(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -170,7 +158,6 @@ struct EntropyFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the log-2 entropy of count input-values."; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -180,7 +167,6 @@ struct KahanSumFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Calculates the sum using a more accurate floating point summation (Kahan Sum)."; static constexpr const char *Example = "kahan_sum(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -202,7 +188,6 @@ struct KurtosisFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the excess kurtosis (Fisher’s definition) of all input values, with a bias correction according to the sample size"; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -212,7 +197,6 @@ struct KurtosisPopFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the excess kurtosis (Fisher’s definition) of all input values, without bias correction"; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -222,7 +206,6 @@ struct ProductFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Calculates the product of all tuples in arg."; static constexpr const char *Example = "product(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -232,7 +215,6 @@ struct SkewnessFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the skewness of all input values."; static constexpr const char *Example = "skewness(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -242,7 +224,6 @@ struct StringAggFun { static constexpr const char *Parameters = "str,arg"; static constexpr const char *Description = "Concatenates the column string values with an optional separator."; static constexpr const char *Example = "string_agg(A, '-')"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -264,7 +245,6 @@ struct SumFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Calculates the sum value for all tuples in arg."; static constexpr const char *Example = "sum(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -274,7 +254,6 @@ struct SumNoOverflowFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Internal only. Calculates the sum value for all tuples in arg without overflow checks."; static constexpr const char *Example = "sum_no_overflow(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/aggregate/holistic_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/aggregate/holistic_functions.hpp index db3eb634a..f8b96a166 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/aggregate/holistic_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/aggregate/holistic_functions.hpp @@ -20,7 +20,6 @@ struct ApproxQuantileFun { static constexpr const char *Parameters = "x,pos"; static constexpr const char *Description = "Computes the approximate quantile using T-Digest."; static constexpr const char *Example = "approx_quantile(x, 0.5)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -30,7 +29,6 @@ struct MadFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the median absolute deviation for the values within x. NULL values are ignored. Temporal types return a positive INTERVAL. "; static constexpr const char *Example = "mad(x)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -38,9 +36,8 @@ struct MadFun { struct MedianFun { static constexpr const char *Name = "median"; static constexpr const char *Parameters = "x"; - static constexpr const char *Description = "Returns the middle value of the set. NULL values are ignored. For even value counts, interpolate-able types (numeric, date/time) return the average of the two middle values. Non-interpolate-able types (everything else) return the lower of the two middle values."; + static constexpr const char *Description = "Returns the middle value of the set. NULL values are ignored. For even value counts, quantitative values are averaged and ordinal values return the lower value."; static constexpr const char *Example = "median(x)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -50,7 +47,6 @@ struct ModeFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the most frequent value for the values within x. NULL values are ignored."; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -60,7 +56,6 @@ struct QuantileDiscFun { static constexpr const char *Parameters = "x,pos"; static constexpr const char *Description = "Returns the exact quantile number between 0 and 1 . If pos is a LIST of FLOATs, then the result is a LIST of the corresponding exact quantiles."; static constexpr const char *Example = "quantile_disc(x, 0.5)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -76,7 +71,6 @@ struct QuantileContFun { static constexpr const char *Parameters = "x,pos"; static constexpr const char *Description = "Returns the interpolated quantile number between 0 and 1 . If pos is a LIST of FLOATs, then the result is a LIST of the corresponding interpolated quantiles. "; static constexpr const char *Example = "quantile_cont(x, 0.5)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -86,7 +80,6 @@ struct ReservoirQuantileFun { static constexpr const char *Parameters = "x,quantile,sample_size"; static constexpr const char *Description = "Gives the approximate quantile using reservoir sampling, the sample size is optional and uses 8192 as a default size."; static constexpr const char *Example = "reservoir_quantile(A,0.5,1024)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -96,7 +89,6 @@ struct ApproxTopKFun { static constexpr const char *Parameters = "val,k"; static constexpr const char *Description = "Finds the k approximately most occurring values in the data set"; static constexpr const char *Example = "approx_top_k(x, 5)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/aggregate/nested_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/aggregate/nested_functions.hpp index 84bd4ad6b..eb83e5e15 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/aggregate/nested_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/aggregate/nested_functions.hpp @@ -20,7 +20,6 @@ struct HistogramFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns a LIST of STRUCTs with the fields bucket and count."; static constexpr const char *Example = "histogram(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); static AggregateFunction GetHistogramUnorderedMap(LogicalType &type); @@ -32,7 +31,6 @@ struct HistogramExactFun { static constexpr const char *Parameters = "arg,bins"; static constexpr const char *Description = "Returns a LIST of STRUCTs with the fields bucket and count matching the buckets exactly."; static constexpr const char *Example = "histogram_exact(A, [0, 1, 2])"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -42,7 +40,6 @@ struct ListFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns a LIST containing all the values of a column."; static constexpr const char *Example = "list(A)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/aggregate/regression_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/aggregate/regression_functions.hpp index 65c6d6fdc..e82b9fdff 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/aggregate/regression_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/aggregate/regression_functions.hpp @@ -20,7 +20,6 @@ struct RegrAvgxFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the average of the independent variable for non-null pairs in a group, where x is the independent variable and y is the dependent variable."; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct RegrAvgyFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the average of the dependent variable for non-null pairs in a group, where x is the independent variable and y is the dependent variable."; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -40,7 +38,6 @@ struct RegrCountFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the number of non-null number pairs in a group."; static constexpr const char *Example = "(SUM(x*y) - SUM(x) * SUM(y) / COUNT(*)) / COUNT(*)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -50,7 +47,6 @@ struct RegrInterceptFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the intercept of the univariate linear regression line for non-null pairs in a group."; static constexpr const char *Example = "AVG(y)-REGR_SLOPE(y,x)*AVG(x)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -60,7 +56,6 @@ struct RegrR2Fun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the coefficient of determination for non-null pairs in a group."; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -70,7 +65,6 @@ struct RegrSlopeFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the slope of the linear regression line for non-null pairs in a group."; static constexpr const char *Example = "COVAR_POP(x,y) / VAR_POP(x)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -80,7 +74,6 @@ struct RegrSXXFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = ""; static constexpr const char *Example = "REGR_COUNT(y, x) * VAR_POP(x)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -90,7 +83,6 @@ struct RegrSXYFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Returns the population covariance of input values"; static constexpr const char *Example = "REGR_COUNT(y, x) * COVAR_POP(y, x)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -100,7 +92,6 @@ struct RegrSYYFun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = ""; static constexpr const char *Example = "REGR_COUNT(y, x) * VAR_POP(y)"; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/aggregate/sum_helpers.hpp b/src/duckdb/extension/core_functions/include/core_functions/aggregate/sum_helpers.hpp index 189f63301..562f61ade 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/aggregate/sum_helpers.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/aggregate/sum_helpers.hpp @@ -8,11 +8,9 @@ #pragma once -#include "duckdb/common/types/hugeint.hpp" -#include "duckdb/common/operator/add.hpp" -#include "duckdb/common/operator/multiply.hpp" -#include "duckdb/function/aggregate_state.hpp" -#include "duckdb/common/operator/cast_operators.hpp" +#include "duckdb/common/common.hpp" +#include "duckdb/common/types.hpp" +#include "duckdb/common/types/vector.hpp" namespace duckdb { @@ -79,20 +77,6 @@ struct HugeintAdd { } }; -struct IntervalAdd { - template - static void AddNumber(STATE &state, T input) { - state.value = AddOperator::Operation(state.value, input); - } - - template - static void AddConstant(STATE &state, T input, idx_t count) { - const auto count64 = Cast::Operation(count); - input = MultiplyOperator::Operation(input, count64); - state.value = AddOperator::Operation(state.value, input); - } -}; - struct KahanAdd { template static void AddNumber(STATE &state, T input) { diff --git a/src/duckdb/extension/core_functions/include/core_functions/function_list.hpp b/src/duckdb/extension/core_functions/include/core_functions/function_list.hpp index e18eef6b3..024ca49f8 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/function_list.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/function_list.hpp @@ -19,11 +19,9 @@ typedef AggregateFunctionSet (*get_aggregate_function_set_t)(); struct StaticFunctionDefinition { const char *name; - const char *alias_of; const char *parameters; const char *description; const char *example; - const char *categories; get_scalar_function_t get_function; get_scalar_function_set_t get_function_set; get_aggregate_function_t get_aggregate_function; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/array_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/array_functions.hpp index 48780bc0f..561643be4 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/array_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/array_functions.hpp @@ -20,7 +20,6 @@ struct ArrayValueFun { static constexpr const char *Parameters = "any,..."; static constexpr const char *Description = "Create an ARRAY containing the argument values."; static constexpr const char *Example = "array_value(4, 5, 6)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct ArrayCrossProductFun { static constexpr const char *Parameters = "array, array"; static constexpr const char *Description = "Compute the cross product of two arrays of size 3. The array elements can not be NULL."; static constexpr const char *Example = "array_cross_product([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -40,7 +38,6 @@ struct ArrayCosineSimilarityFun { static constexpr const char *Parameters = "array1,array2"; static constexpr const char *Description = "Compute the cosine similarity between two arrays of the same size. The array elements can not be NULL. The arrays can have any size as long as the size is the same for both arguments."; static constexpr const char *Example = "array_cosine_similarity([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -50,7 +47,6 @@ struct ArrayCosineDistanceFun { static constexpr const char *Parameters = "array1,array2"; static constexpr const char *Description = "Compute the cosine distance between two arrays of the same size. The array elements can not be NULL. The arrays can have any size as long as the size is the same for both arguments."; static constexpr const char *Example = "array_cosine_distance([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -60,7 +56,6 @@ struct ArrayDistanceFun { static constexpr const char *Parameters = "array1,array2"; static constexpr const char *Description = "Compute the distance between two arrays of the same size. The array elements can not be NULL. The arrays can have any size as long as the size is the same for both arguments."; static constexpr const char *Example = "array_distance([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -70,7 +65,6 @@ struct ArrayInnerProductFun { static constexpr const char *Parameters = "array1,array2"; static constexpr const char *Description = "Compute the inner product between two arrays of the same size. The array elements can not be NULL. The arrays can have any size as long as the size is the same for both arguments."; static constexpr const char *Example = "array_inner_product([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -86,7 +80,6 @@ struct ArrayNegativeInnerProductFun { static constexpr const char *Parameters = "array1,array2"; static constexpr const char *Description = "Compute the negative inner product between two arrays of the same size. The array elements can not be NULL. The arrays can have any size as long as the size is the same for both arguments."; static constexpr const char *Example = "array_negative_inner_product([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/bit_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/bit_functions.hpp index 056d5f477..e01a2fc58 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/bit_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/bit_functions.hpp @@ -20,7 +20,6 @@ struct GetBitFun { static constexpr const char *Parameters = "bitstring,index"; static constexpr const char *Description = "Extracts the nth bit from bitstring; the first (leftmost) bit is indexed 0"; static constexpr const char *Example = "get_bit('0110010'::BIT, 2)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct SetBitFun { static constexpr const char *Parameters = "bitstring,index,new_value"; static constexpr const char *Description = "Sets the nth bit in bitstring to newvalue; the first (leftmost) bit is indexed 0. Returns a new bitstring"; static constexpr const char *Example = "set_bit('0110010'::BIT, 2, 0)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -40,7 +38,6 @@ struct BitPositionFun { static constexpr const char *Parameters = "substring,bitstring"; static constexpr const char *Description = "Returns first starting index of the specified substring within bits, or zero if it is not present. The first (leftmost) bit is indexed 1"; static constexpr const char *Example = "bit_position('010'::BIT, '1110101'::BIT)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -50,7 +47,6 @@ struct BitStringFun { static constexpr const char *Parameters = "bitstring,length"; static constexpr const char *Description = "Pads the bitstring until the specified length"; static constexpr const char *Example = "bitstring('1010'::BIT, 7)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/blob_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/blob_functions.hpp index 42ccd92d5..051e212c1 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/blob_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/blob_functions.hpp @@ -18,9 +18,8 @@ namespace duckdb { struct DecodeFun { static constexpr const char *Name = "decode"; static constexpr const char *Parameters = "blob"; - static constexpr const char *Description = "Converts `blob` to `VARCHAR`. Fails if `blob` is not valid UTF-8."; + static constexpr const char *Description = "Convert blob to varchar. Fails if blob is not valid utf-8"; static constexpr const char *Example = "decode('\\xC3\\xBC'::BLOB)"; - static constexpr const char *Categories = "blob"; static ScalarFunction GetFunction(); }; @@ -28,9 +27,8 @@ struct DecodeFun { struct EncodeFun { static constexpr const char *Name = "encode"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Converts the `string` to `BLOB`. Converts UTF-8 characters into literal encoding."; + static constexpr const char *Description = "Convert varchar to blob. Converts utf-8 characters into literal encoding"; static constexpr const char *Example = "encode('my_string_with_ü')"; - static constexpr const char *Categories = "blob"; static ScalarFunction GetFunction(); }; @@ -38,9 +36,8 @@ struct EncodeFun { struct FromBase64Fun { static constexpr const char *Name = "from_base64"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Converts a base64 encoded `string` to a character string (`BLOB`)."; + static constexpr const char *Description = "Convert a base64 encoded string to a character string"; static constexpr const char *Example = "from_base64('QQ==')"; - static constexpr const char *Categories = "string,blob"; static ScalarFunction GetFunction(); }; @@ -48,9 +45,8 @@ struct FromBase64Fun { struct ToBase64Fun { static constexpr const char *Name = "to_base64"; static constexpr const char *Parameters = "blob"; - static constexpr const char *Description = "Converts a `blob` to a base64 encoded `string`."; - static constexpr const char *Example = "base64('A'::BLOB)"; - static constexpr const char *Categories = "string,blob"; + static constexpr const char *Description = "Convert a blob to a base64 encoded string"; + static constexpr const char *Example = "base64('A'::blob)"; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/date_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/date_functions.hpp index c36fd3681..7256502a9 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/date_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/date_functions.hpp @@ -20,7 +20,6 @@ struct AgeFun { static constexpr const char *Parameters = "timestamp,timestamp"; static constexpr const char *Description = "Subtract arguments, resulting in the time difference between the two timestamps"; static constexpr const char *Example = "age(TIMESTAMP '2001-04-10', TIMESTAMP '1992-09-20')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -30,7 +29,6 @@ struct CenturyFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the century component from a date or timestamp"; static constexpr const char *Example = "century(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -40,7 +38,6 @@ struct DateDiffFun { static constexpr const char *Parameters = "part,startdate,enddate"; static constexpr const char *Description = "The number of partition boundaries between the timestamps"; static constexpr const char *Example = "date_diff('hour', TIMESTAMPTZ '1992-09-30 23:59:59', TIMESTAMPTZ '1992-10-01 01:58:00')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -56,7 +53,6 @@ struct DatePartFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Get subfield (equivalent to extract)"; static constexpr const char *Example = "date_part('minute', TIMESTAMP '1992-09-20 20:38:40')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -72,7 +68,6 @@ struct DateSubFun { static constexpr const char *Parameters = "part,startdate,enddate"; static constexpr const char *Description = "The number of complete partitions between the timestamps"; static constexpr const char *Example = "date_sub('hour', TIMESTAMPTZ '1992-09-30 23:59:59', TIMESTAMPTZ '1992-10-01 01:58:00')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -88,7 +83,6 @@ struct DateTruncFun { static constexpr const char *Parameters = "part,timestamp"; static constexpr const char *Description = "Truncate to specified precision"; static constexpr const char *Example = "date_trunc('hour', TIMESTAMPTZ '1992-09-20 20:38:40')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -104,7 +98,6 @@ struct DayFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the day component from a date or timestamp"; static constexpr const char *Example = "day(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -114,7 +107,6 @@ struct DayNameFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "The (English) name of the weekday"; static constexpr const char *Example = "dayname(TIMESTAMP '1992-03-22')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -124,7 +116,6 @@ struct DayOfMonthFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the dayofmonth component from a date or timestamp"; static constexpr const char *Example = "dayofmonth(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -134,7 +125,6 @@ struct DayOfWeekFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the dayofweek component from a date or timestamp"; static constexpr const char *Example = "dayofweek(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -144,7 +134,6 @@ struct DayOfYearFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the dayofyear component from a date or timestamp"; static constexpr const char *Example = "dayofyear(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -154,7 +143,6 @@ struct DecadeFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the decade component from a date or timestamp"; static constexpr const char *Example = "decade(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -164,7 +152,6 @@ struct EpochFun { static constexpr const char *Parameters = "temporal"; static constexpr const char *Description = "Extract the epoch component from a temporal type"; static constexpr const char *Example = "epoch(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -174,7 +161,6 @@ struct EpochMsFun { static constexpr const char *Parameters = "temporal"; static constexpr const char *Description = "Extract the epoch component in milliseconds from a temporal type"; static constexpr const char *Example = "epoch_ms(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -184,7 +170,6 @@ struct EpochUsFun { static constexpr const char *Parameters = "temporal"; static constexpr const char *Description = "Extract the epoch component in microseconds from a temporal type"; static constexpr const char *Example = "epoch_us(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -194,7 +179,6 @@ struct EpochNsFun { static constexpr const char *Parameters = "temporal"; static constexpr const char *Description = "Extract the epoch component in nanoseconds from a temporal type"; static constexpr const char *Example = "epoch_ns(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -204,7 +188,6 @@ struct EraFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the era component from a date or timestamp"; static constexpr const char *Example = "era(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -214,7 +197,6 @@ struct GetCurrentTimestampFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns the current timestamp"; static constexpr const char *Example = "get_current_timestamp()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -236,7 +218,6 @@ struct HoursFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the hour component from a date or timestamp"; static constexpr const char *Example = "hour(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -246,7 +227,6 @@ struct ISODayOfWeekFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the isodow component from a date or timestamp"; static constexpr const char *Example = "isodow(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -256,7 +236,6 @@ struct ISOYearFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the isoyear component from a date or timestamp"; static constexpr const char *Example = "isoyear(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -266,7 +245,6 @@ struct JulianDayFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the Julian Day number from a date or timestamp"; static constexpr const char *Example = "julian(timestamp '2006-01-01 12:00')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -276,7 +254,6 @@ struct LastDayFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Returns the last day of the month"; static constexpr const char *Example = "last_day(TIMESTAMP '1992-03-22 01:02:03.1234')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -286,7 +263,6 @@ struct MakeDateFun { static constexpr const char *Parameters = "year,month,day\1date-struct::STRUCT(year BIGINT, month BIGINT, day BIGINT)"; static constexpr const char *Description = "The date for the given parts\1The date for the given struct."; static constexpr const char *Example = "make_date(1992, 9, 20)\1make_date({'year': 2024, 'month': 11, 'day': 14})"; - static constexpr const char *Categories = "\1"; static ScalarFunctionSet GetFunctions(); }; @@ -296,7 +272,6 @@ struct MakeTimeFun { static constexpr const char *Parameters = "hour,minute,seconds"; static constexpr const char *Description = "The time for the given parts"; static constexpr const char *Example = "make_time(13, 34, 27.123456)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -306,7 +281,6 @@ struct MakeTimestampFun { static constexpr const char *Parameters = "year,month,day,hour,minute,seconds"; static constexpr const char *Description = "The timestamp for the given parts"; static constexpr const char *Example = "make_timestamp(1992, 9, 20, 13, 34, 27.123456)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -316,7 +290,6 @@ struct MakeTimestampNsFun { static constexpr const char *Parameters = "nanos"; static constexpr const char *Description = "The timestamp for the given nanoseconds since epoch"; static constexpr const char *Example = "make_timestamp(1732117793000000000)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -326,7 +299,6 @@ struct MicrosecondsFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the microsecond component from a date or timestamp"; static constexpr const char *Example = "microsecond(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -336,7 +308,6 @@ struct MillenniumFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the millennium component from a date or timestamp"; static constexpr const char *Example = "millennium(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -346,7 +317,6 @@ struct MillisecondsFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the millisecond component from a date or timestamp"; static constexpr const char *Example = "millisecond(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -356,7 +326,6 @@ struct MinutesFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the minute component from a date or timestamp"; static constexpr const char *Example = "minute(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -366,7 +335,6 @@ struct MonthFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the month component from a date or timestamp"; static constexpr const char *Example = "month(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -376,7 +344,6 @@ struct MonthNameFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "The (English) name of the month"; static constexpr const char *Example = "monthname(TIMESTAMP '1992-09-20')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -385,8 +352,7 @@ struct NanosecondsFun { static constexpr const char *Name = "nanosecond"; static constexpr const char *Parameters = "tsns"; static constexpr const char *Description = "Extract the nanosecond component from a date or timestamp"; - static constexpr const char *Example = "nanosecond(timestamp_ns '2021-08-03 11:59:44.123456789')"; - static constexpr const char *Categories = ""; + static constexpr const char *Example = "nanosecond(timestamp_ns '2021-08-03 11:59:44.123456789') => 44123456789"; static ScalarFunctionSet GetFunctions(); }; @@ -396,7 +362,6 @@ struct NormalizedIntervalFun { static constexpr const char *Parameters = "interval"; static constexpr const char *Description = "Normalizes an INTERVAL to an equivalent interval"; static constexpr const char *Example = "normalized_interval(INTERVAL '30 days')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -406,7 +371,6 @@ struct QuarterFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the quarter component from a date or timestamp"; static constexpr const char *Example = "quarter(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -416,7 +380,6 @@ struct SecondsFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the second component from a date or timestamp"; static constexpr const char *Example = "second(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -426,7 +389,6 @@ struct TimeBucketFun { static constexpr const char *Parameters = "bucket_width,timestamp,origin"; static constexpr const char *Description = "Truncate TIMESTAMPTZ by the specified interval bucket_width. Buckets are aligned relative to origin TIMESTAMPTZ. The origin defaults to 2000-01-03 00:00:00+00 for buckets that do not include a month or year interval, and to 2000-01-01 00:00:00+00 for month and year buckets"; static constexpr const char *Example = "time_bucket(INTERVAL '2 weeks', TIMESTAMP '1992-04-20 15:26:00-07', TIMESTAMP '1992-04-01 00:00:00-07')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -436,7 +398,6 @@ struct TimezoneFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the timezone component from a date or timestamp"; static constexpr const char *Example = "timezone(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -446,7 +407,6 @@ struct TimezoneHourFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the timezone_hour component from a date or timestamp"; static constexpr const char *Example = "timezone_hour(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -456,7 +416,6 @@ struct TimezoneMinuteFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the timezone_minute component from a date or timestamp"; static constexpr const char *Example = "timezone_minute(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -466,7 +425,6 @@ struct TimeTZSortKeyFun { static constexpr const char *Parameters = "time_tz"; static constexpr const char *Description = "Converts a TIME WITH TIME ZONE to an integer sort key"; static constexpr const char *Example = "timetz_byte_comparable('18:18:16.21-07:00'::TIME_TZ)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -476,9 +434,8 @@ struct ToCenturiesFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a century interval"; static constexpr const char *Example = "to_centuries(5)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ToDaysFun { @@ -486,9 +443,8 @@ struct ToDaysFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a day interval"; static constexpr const char *Example = "to_days(5)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ToDecadesFun { @@ -496,9 +452,8 @@ struct ToDecadesFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a decade interval"; static constexpr const char *Example = "to_decades(5)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ToHoursFun { @@ -506,7 +461,6 @@ struct ToHoursFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a hour interval"; static constexpr const char *Example = "to_hours(5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -516,7 +470,6 @@ struct ToMicrosecondsFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a microsecond interval"; static constexpr const char *Example = "to_microseconds(5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -526,9 +479,8 @@ struct ToMillenniaFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a millenium interval"; static constexpr const char *Example = "to_millennia(1)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ToMillisecondsFun { @@ -536,7 +488,6 @@ struct ToMillisecondsFun { static constexpr const char *Parameters = "double"; static constexpr const char *Description = "Construct a millisecond interval"; static constexpr const char *Example = "to_milliseconds(5.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -546,7 +497,6 @@ struct ToMinutesFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a minute interval"; static constexpr const char *Example = "to_minutes(5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -556,9 +506,8 @@ struct ToMonthsFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a month interval"; static constexpr const char *Example = "to_months(5)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ToQuartersFun { @@ -566,9 +515,8 @@ struct ToQuartersFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a quarter interval"; static constexpr const char *Example = "to_quarters(5)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ToSecondsFun { @@ -576,7 +524,6 @@ struct ToSecondsFun { static constexpr const char *Parameters = "double"; static constexpr const char *Description = "Construct a second interval"; static constexpr const char *Example = "to_seconds(5.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -586,7 +533,6 @@ struct ToTimestampFun { static constexpr const char *Parameters = "sec"; static constexpr const char *Description = "Converts secs since epoch to a timestamp with time zone"; static constexpr const char *Example = "to_timestamp(1284352323.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -596,9 +542,8 @@ struct ToWeeksFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a week interval"; static constexpr const char *Example = "to_weeks(5)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ToYearsFun { @@ -606,9 +551,8 @@ struct ToYearsFun { static constexpr const char *Parameters = "integer"; static constexpr const char *Description = "Construct a year interval"; static constexpr const char *Example = "to_years(5)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct WeekFun { @@ -616,7 +560,6 @@ struct WeekFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the week component from a date or timestamp"; static constexpr const char *Example = "week(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -626,7 +569,6 @@ struct WeekDayFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the weekday component from a date or timestamp"; static constexpr const char *Example = "weekday(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -636,7 +578,6 @@ struct WeekOfYearFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the weekofyear component from a date or timestamp"; static constexpr const char *Example = "weekofyear(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -646,7 +587,6 @@ struct YearFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the year component from a date or timestamp"; static constexpr const char *Example = "year(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -656,7 +596,6 @@ struct YearWeekFun { static constexpr const char *Parameters = "ts"; static constexpr const char *Description = "Extract the yearweek component from a date or timestamp"; static constexpr const char *Example = "yearweek(timestamp '2021-08-03 11:59:44.123456')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/debug_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/debug_functions.hpp index 65368b2a9..ce4debc6d 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/debug_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/debug_functions.hpp @@ -20,7 +20,6 @@ struct VectorTypeFun { static constexpr const char *Parameters = "col"; static constexpr const char *Description = "Returns the VectorType of a given column"; static constexpr const char *Example = "vector_type(col)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/enum_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/enum_functions.hpp index ccf3b6fae..73791f8a5 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/enum_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/enum_functions.hpp @@ -20,7 +20,6 @@ struct EnumFirstFun { static constexpr const char *Parameters = "enum"; static constexpr const char *Description = "Returns the first value of the input enum type"; static constexpr const char *Example = "enum_first(NULL::mood)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct EnumLastFun { static constexpr const char *Parameters = "enum"; static constexpr const char *Description = "Returns the last value of the input enum type"; static constexpr const char *Example = "enum_last(NULL::mood)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -40,7 +38,6 @@ struct EnumCodeFun { static constexpr const char *Parameters = "enum"; static constexpr const char *Description = "Returns the numeric value backing the given enum value"; static constexpr const char *Example = "enum_code('happy'::mood)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -50,7 +47,6 @@ struct EnumRangeFun { static constexpr const char *Parameters = "enum"; static constexpr const char *Description = "Returns all values of the input enum type as an array"; static constexpr const char *Example = "enum_range(NULL::mood)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -60,7 +56,6 @@ struct EnumRangeBoundaryFun { static constexpr const char *Parameters = "start,end"; static constexpr const char *Description = "Returns the range between the two given enum values as an array. The values must be of the same enum type. When the first parameter is NULL, the result starts with the first value of the enum type. When the second parameter is NULL, the result ends with the last value of the enum type"; static constexpr const char *Example = "enum_range_boundary(NULL, 'happy'::mood)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/generic_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/generic_functions.hpp index 4a8332309..d874e72a9 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/generic_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/generic_functions.hpp @@ -20,7 +20,6 @@ struct AliasFun { static constexpr const char *Parameters = "expr"; static constexpr const char *Description = "Returns the name of a given expression"; static constexpr const char *Example = "alias(42 + 1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct CurrentSettingFun { static constexpr const char *Parameters = "setting_name"; static constexpr const char *Description = "Returns the current value of the configuration setting"; static constexpr const char *Example = "current_setting('access_mode')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -40,7 +38,6 @@ struct HashFun { static constexpr const char *Parameters = "param"; static constexpr const char *Description = "Returns an integer with the hash of the value. Note that this is not a cryptographic hash"; static constexpr const char *Example = "hash('🦆')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -50,7 +47,6 @@ struct LeastFun { static constexpr const char *Parameters = "arg1, arg2, ..."; static constexpr const char *Description = "Returns the lowest value of the set of input parameters"; static constexpr const char *Example = "least(42, 84)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -60,7 +56,6 @@ struct GreatestFun { static constexpr const char *Parameters = "arg1, arg2, ..."; static constexpr const char *Description = "Returns the highest value of the set of input parameters"; static constexpr const char *Example = "greatest(42, 84)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -70,7 +65,6 @@ struct StatsFun { static constexpr const char *Parameters = "expression"; static constexpr const char *Description = "Returns a string with statistics about the expression. Expression can be a column, constant, or SQL expression"; static constexpr const char *Example = "stats(5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -80,7 +74,6 @@ struct TypeOfFun { static constexpr const char *Parameters = "expression"; static constexpr const char *Description = "Returns the name of the data type of the result of the expression"; static constexpr const char *Example = "typeof('abc')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -90,7 +83,6 @@ struct CanCastImplicitlyFun { static constexpr const char *Parameters = "source_type,target_type"; static constexpr const char *Description = "Whether or not we can implicitly cast from the source type to the other type"; static constexpr const char *Example = "can_implicitly_cast(NULL::INTEGER, NULL::BIGINT)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -100,7 +92,6 @@ struct CurrentQueryFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns the current query as a string"; static constexpr const char *Example = "current_query()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -110,7 +101,6 @@ struct CurrentSchemaFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns the name of the currently active schema. Default is main"; static constexpr const char *Example = "current_schema()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -120,7 +110,6 @@ struct CurrentSchemasFun { static constexpr const char *Parameters = "include_implicit"; static constexpr const char *Description = "Returns list of schemas. Pass a parameter of True to include implicit schemas"; static constexpr const char *Example = "current_schemas(true)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -130,7 +119,6 @@ struct CurrentDatabaseFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns the name of the currently active database"; static constexpr const char *Example = "current_database()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -140,7 +128,6 @@ struct InSearchPathFun { static constexpr const char *Parameters = "database_name,schema_name"; static constexpr const char *Description = "Returns whether or not the database/schema are in the search path"; static constexpr const char *Example = "in_search_path('memory', 'main')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -150,7 +137,6 @@ struct CurrentTransactionIdFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns the current transaction’s ID (a BIGINT). It will assign a new one if the current transaction does not have one already"; static constexpr const char *Example = "txid_current()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -160,7 +146,6 @@ struct VersionFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns the currently active version of DuckDB in this format: v0.3.2 "; static constexpr const char *Example = "version()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -170,7 +155,6 @@ struct EquiWidthBinsFun { static constexpr const char *Parameters = "min,max,bin_count,nice_rounding"; static constexpr const char *Description = "Generates bin_count equi-width bins between the min and max. If enabled nice_rounding makes the numbers more readable/less jagged"; static constexpr const char *Example = "equi_width_bins(0, 10, 2, true)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -180,7 +164,6 @@ struct IsHistogramOtherBinFun { static constexpr const char *Parameters = "val"; static constexpr const char *Description = "Whether or not the provided value is the histogram \"other\" bin (used for values not belonging to any provided bin)"; static constexpr const char *Example = "is_histogram_other_bin(v)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/list_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/list_functions.hpp index 6ef7a7c68..2b9318b40 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/list_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/list_functions.hpp @@ -20,7 +20,6 @@ struct ListFlattenFun { static constexpr const char *Parameters = "nested_list"; static constexpr const char *Description = "Flatten a nested list by one level"; static constexpr const char *Example = "flatten([[1, 2, 3], [4, 5]])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct ListAggregateFun { static constexpr const char *Parameters = "list,name"; static constexpr const char *Description = "Executes the aggregate function name on the elements of list"; static constexpr const char *Example = "list_aggregate([1, 2, NULL], 'min')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -64,7 +62,6 @@ struct ListDistinctFun { static constexpr const char *Parameters = "list"; static constexpr const char *Description = "Removes all duplicates and NULLs from a list. Does not preserve the original order"; static constexpr const char *Example = "list_distinct([1, 1, NULL, -3, 1, 5])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -80,7 +77,6 @@ struct ListUniqueFun { static constexpr const char *Parameters = "list"; static constexpr const char *Description = "Counts the unique elements of a list"; static constexpr const char *Example = "list_unique([1, 1, NULL, -3, 1, 5])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -96,7 +92,6 @@ struct ListValueFun { static constexpr const char *Parameters = "any,..."; static constexpr const char *Description = "Create a LIST containing the argument values"; static constexpr const char *Example = "list_value(4, 5, 6)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -112,7 +107,6 @@ struct ListSliceFun { static constexpr const char *Parameters = "list,begin,end\1list,begin,end,step"; static constexpr const char *Description = "Extract a sublist using slice conventions. Negative values are accepted.\1list_slice with added step feature."; static constexpr const char *Example = "list_slice([4, 5, 6], 2, 3)\2array_slice('DuckDB', 3, 4)\2array_slice('DuckDB', 3, NULL)\2array_slice('DuckDB', 0, -3)\1list_slice([4, 5, 6], 1, 3, 2)"; - static constexpr const char *Categories = "\1"; static ScalarFunctionSet GetFunctions(); }; @@ -128,7 +122,6 @@ struct ListSortFun { static constexpr const char *Parameters = "list"; static constexpr const char *Description = "Sorts the elements of the list"; static constexpr const char *Example = "list_sort([3, 6, 1, 2])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -144,7 +137,6 @@ struct ListGradeUpFun { static constexpr const char *Parameters = "list"; static constexpr const char *Description = "Returns the index of their sorted position."; static constexpr const char *Example = "list_grade_up([3, 6, 1, 2])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -166,7 +158,6 @@ struct ListReverseSortFun { static constexpr const char *Parameters = "list"; static constexpr const char *Description = "Sorts the elements of the list in reverse order"; static constexpr const char *Example = "list_reverse_sort([3, 6, 1, 2])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -182,7 +173,6 @@ struct ListTransformFun { static constexpr const char *Parameters = "list,lambda"; static constexpr const char *Description = "Returns a list that is the result of applying the lambda function to each element of the input list. See the Lambda Functions section for more details"; static constexpr const char *Example = "list_transform([1, 2, 3], x -> x + 1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -216,7 +206,6 @@ struct ListFilterFun { static constexpr const char *Parameters = "list,lambda"; static constexpr const char *Description = "Constructs a list from those elements of the input list for which the lambda function returns true"; static constexpr const char *Example = "list_filter([3, 4, 5], x -> x > 4)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -235,12 +224,11 @@ struct FilterFun { struct ListReduceFun { static constexpr const char *Name = "list_reduce"; - static constexpr const char *Parameters = "list,lambda[,initial]"; - static constexpr const char *Description = "Returns a single value that is the result of applying the lambda function to each element of the input list, starting with the first element and then repeatedly applying the lambda function to the result of the previous application and the next element of the list. When an initial value is provided, it is used as the first argument to the lambda function"; + static constexpr const char *Parameters = "list,lambda"; + static constexpr const char *Description = "Returns a single value that is the result of applying the lambda function to each element of the input list, starting with the first element and then repeatedly applying the lambda function to the result of the previous application and the next element of the list."; static constexpr const char *Example = "list_reduce([1, 2, 3], (x, y) -> x + y)"; - static constexpr const char *Categories = ""; - static ScalarFunctionSet GetFunctions(); + static ScalarFunction GetFunction(); }; struct ArrayReduceFun { @@ -260,7 +248,6 @@ struct GenerateSeriesFun { static constexpr const char *Parameters = "start,stop,step"; static constexpr const char *Description = "Create a list of values between start and stop - the stop parameter is inclusive"; static constexpr const char *Example = "generate_series(2, 5, 3)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -270,7 +257,6 @@ struct ListRangeFun { static constexpr const char *Parameters = "start,stop,step"; static constexpr const char *Description = "Create a list of values between start and stop - the stop parameter is exclusive"; static constexpr const char *Example = "range(2, 5, 3)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -280,7 +266,6 @@ struct ListCosineDistanceFun { static constexpr const char *Parameters = "list1,list2"; static constexpr const char *Description = "Compute the cosine distance between two lists"; static constexpr const char *Example = "list_cosine_distance([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -296,7 +281,6 @@ struct ListCosineSimilarityFun { static constexpr const char *Parameters = "list1,list2"; static constexpr const char *Description = "Compute the cosine similarity between two lists"; static constexpr const char *Example = "list_cosine_similarity([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -306,7 +290,6 @@ struct ListDistanceFun { static constexpr const char *Parameters = "list1,list2"; static constexpr const char *Description = "Compute the distance between two lists"; static constexpr const char *Example = "list_distance([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -322,7 +305,6 @@ struct ListInnerProductFun { static constexpr const char *Parameters = "list1,list2"; static constexpr const char *Description = "Compute the inner product between two lists"; static constexpr const char *Example = "list_inner_product([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -338,7 +320,6 @@ struct ListNegativeInnerProductFun { static constexpr const char *Parameters = "list1,list2"; static constexpr const char *Description = "Compute the negative inner product between two lists"; static constexpr const char *Example = "list_negative_inner_product([1, 2, 3], [1, 2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -354,7 +335,6 @@ struct UnpivotListFun { static constexpr const char *Parameters = "any,..."; static constexpr const char *Description = "Identical to list_value, but generated as part of unpivot for better error messages"; static constexpr const char *Example = "unpivot_list(4, 5, 6)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -364,7 +344,6 @@ struct ListHasAnyFun { static constexpr const char *Parameters = "l1, l2"; static constexpr const char *Description = "Returns true if the lists have any element in common. NULLs are ignored."; static constexpr const char *Example = "list_has_any([1, 2, 3], [2, 3, 4])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -386,7 +365,6 @@ struct ListHasAllFun { static constexpr const char *Parameters = "l1, l2"; static constexpr const char *Description = "Returns true if all elements of l2 are in l1. NULLs are ignored."; static constexpr const char *Example = "list_has_all([1, 2, 3], [2, 3])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/map_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/map_functions.hpp index 38784bc76..c8698eb78 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/map_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/map_functions.hpp @@ -20,7 +20,6 @@ struct CardinalityFun { static constexpr const char *Parameters = "map"; static constexpr const char *Description = "Returns the size of the map (or the number of entries in the map)"; static constexpr const char *Example = "cardinality( map([4, 2], ['a', 'b']) );"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct MapFun { static constexpr const char *Parameters = "keys,values"; static constexpr const char *Description = "Creates a map from a set of keys and values"; static constexpr const char *Example = "map(['key1', 'key2'], ['val1', 'val2'])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -40,7 +38,6 @@ struct MapEntriesFun { static constexpr const char *Parameters = "map"; static constexpr const char *Description = "Returns the map entries as a list of keys/values"; static constexpr const char *Example = "map_entries(map(['key'], ['val']))"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -50,7 +47,6 @@ struct MapExtractFun { static constexpr const char *Parameters = "map,key"; static constexpr const char *Description = "Returns a list containing the value for a given key or an empty list if the key is not contained in the map. The type of the key provided in the second parameter must match the type of the map’s keys else an error is returned"; static constexpr const char *Example = "map_extract(map(['key'], ['val']), 'key')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -66,7 +62,6 @@ struct MapExtractValueFun { static constexpr const char *Parameters = "map,key"; static constexpr const char *Description = "Returns the value for a given key or NULL if the key is not contained in the map. The type of the key provided in the second parameter must match the type of the map’s keys else an error is returned"; static constexpr const char *Example = "map_extract_value(map(['key'], ['val']), 'key')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -76,7 +71,6 @@ struct MapFromEntriesFun { static constexpr const char *Parameters = "map"; static constexpr const char *Description = "Returns a map created from the entries of the array"; static constexpr const char *Example = "map_from_entries([{k: 5, v: 'val1'}, {k: 3, v: 'val2'}]);"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -86,7 +80,6 @@ struct MapConcatFun { static constexpr const char *Parameters = "any,..."; static constexpr const char *Description = "Returns a map created from merging the input maps, on key collision the value is taken from the last map with that key"; static constexpr const char *Example = "map_concat(map([1,2], ['a', 'b']), map([2,3], ['c', 'd']));"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -96,7 +89,6 @@ struct MapKeysFun { static constexpr const char *Parameters = "map"; static constexpr const char *Description = "Returns the keys of a map as a list"; static constexpr const char *Example = "map_keys(map(['key'], ['val']))"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -106,7 +98,6 @@ struct MapValuesFun { static constexpr const char *Parameters = "map"; static constexpr const char *Description = "Returns the values of a map as a list"; static constexpr const char *Example = "map_values(map(['key'], ['val']))"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/math_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/math_functions.hpp index 8b9da8efa..7b8e2befd 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/math_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/math_functions.hpp @@ -20,7 +20,6 @@ struct AbsOperatorFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Absolute value"; static constexpr const char *Example = "abs(-17.4)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -36,7 +35,6 @@ struct PowOperatorFun { static constexpr const char *Parameters = "x,y"; static constexpr const char *Description = "Computes x to the power of y"; static constexpr const char *Example = "pow(2, 3)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -64,7 +62,6 @@ struct FactorialOperatorFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Factorial of x. Computes the product of the current integer and all integers below it"; static constexpr const char *Example = "4!"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -80,7 +77,6 @@ struct AcosFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the arccosine of x"; static constexpr const char *Example = "acos(0.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -90,7 +86,6 @@ struct AsinFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the arcsine of x"; static constexpr const char *Example = "asin(0.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -100,7 +95,6 @@ struct AtanFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the arctangent of x"; static constexpr const char *Example = "atan(0.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -110,7 +104,6 @@ struct Atan2Fun { static constexpr const char *Parameters = "y,x"; static constexpr const char *Description = "Computes the arctangent (y, x)"; static constexpr const char *Example = "atan2(1.0, 0.0)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -120,7 +113,6 @@ struct BitCountFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the number of bits that are set"; static constexpr const char *Example = "bit_count(31)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -130,7 +122,6 @@ struct CbrtFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the cube root of x"; static constexpr const char *Example = "cbrt(8)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -140,7 +131,6 @@ struct CeilFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Rounds the number up"; static constexpr const char *Example = "ceil(17.4)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -156,7 +146,6 @@ struct CosFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the cos of x"; static constexpr const char *Example = "cos(90)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -166,7 +155,6 @@ struct CotFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the cotangent of x"; static constexpr const char *Example = "cot(0.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -176,7 +164,6 @@ struct DegreesFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Converts radians to degrees"; static constexpr const char *Example = "degrees(pi())"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -186,7 +173,6 @@ struct EvenFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Rounds x to next even number by rounding away from zero"; static constexpr const char *Example = "even(2.9)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -196,7 +182,6 @@ struct ExpFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes e to the power of x"; static constexpr const char *Example = "exp(1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -206,7 +191,6 @@ struct FloorFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Rounds the number down"; static constexpr const char *Example = "floor(17.4)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -216,7 +200,6 @@ struct IsFiniteFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns true if the floating point value is finite, false otherwise"; static constexpr const char *Example = "isfinite(5.5)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -226,7 +209,6 @@ struct IsInfiniteFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns true if the floating point value is infinite, false otherwise"; static constexpr const char *Example = "isinf('Infinity'::float)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -236,7 +218,6 @@ struct IsNanFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns true if the floating point value is not a number, false otherwise"; static constexpr const char *Example = "isnan('NaN'::FLOAT)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -246,7 +227,6 @@ struct GammaFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Interpolation of (x-1) factorial (so decimal inputs are allowed)"; static constexpr const char *Example = "gamma(5.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -256,7 +236,6 @@ struct GreatestCommonDivisorFun { static constexpr const char *Parameters = "x,y"; static constexpr const char *Description = "Computes the greatest common divisor of x and y"; static constexpr const char *Example = "greatest_common_divisor(42, 57)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -272,7 +251,6 @@ struct LeastCommonMultipleFun { static constexpr const char *Parameters = "x,y"; static constexpr const char *Description = "Computes the least common multiple of x and y"; static constexpr const char *Example = "least_common_multiple(42, 57)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -288,7 +266,6 @@ struct LogGammaFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the log of the gamma function"; static constexpr const char *Example = "lgamma(2)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -298,7 +275,6 @@ struct LnFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the natural logarithm of x"; static constexpr const char *Example = "ln(2)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -308,7 +284,6 @@ struct Log2Fun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the 2-log of x"; static constexpr const char *Example = "log2(8)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -318,7 +293,6 @@ struct Log10Fun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the 10-log of x"; static constexpr const char *Example = "log10(1000)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -328,7 +302,6 @@ struct LogFun { static constexpr const char *Parameters = "b, x"; static constexpr const char *Description = "Computes the logarithm of x to base b. b may be omitted, in which case the default 10"; static constexpr const char *Example = "log(2, 64)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -338,7 +311,6 @@ struct NextAfterFun { static constexpr const char *Parameters = "x, y"; static constexpr const char *Description = "Returns the next floating point value after x in the direction of y"; static constexpr const char *Example = "nextafter(1::float, 2::float)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -348,7 +320,6 @@ struct PiFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns the value of pi"; static constexpr const char *Example = "pi()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -358,7 +329,6 @@ struct RadiansFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Converts degrees to radians"; static constexpr const char *Example = "radians(90)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -368,7 +338,6 @@ struct RoundFun { static constexpr const char *Parameters = "x,precision"; static constexpr const char *Description = "Rounds x to s decimal places"; static constexpr const char *Example = "round(42.4332, 2)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -378,7 +347,6 @@ struct SignFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the sign of x as -1, 0 or 1"; static constexpr const char *Example = "sign(-349)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -388,7 +356,6 @@ struct SignBitFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns whether the signbit is set or not"; static constexpr const char *Example = "signbit(-0.0)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -398,7 +365,6 @@ struct SinFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the sin of x"; static constexpr const char *Example = "sin(90)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -408,7 +374,6 @@ struct SqrtFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Returns the square root of x"; static constexpr const char *Example = "sqrt(4)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -418,7 +383,6 @@ struct TanFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the tan of x"; static constexpr const char *Example = "tan(90)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -428,7 +392,6 @@ struct TruncFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Truncates the number"; static constexpr const char *Example = "trunc(17.4)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -438,7 +401,6 @@ struct CoshFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the hyperbolic cos of x"; static constexpr const char *Example = "cosh(1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -448,7 +410,6 @@ struct SinhFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the hyperbolic sin of x"; static constexpr const char *Example = "sinh(1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -458,7 +419,6 @@ struct TanhFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the hyperbolic tan of x"; static constexpr const char *Example = "tanh(1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -468,7 +428,6 @@ struct AcoshFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the inverse hyperbolic cos of x"; static constexpr const char *Example = "acosh(2.3)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -478,7 +437,6 @@ struct AsinhFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the inverse hyperbolic sin of x"; static constexpr const char *Example = "asinh(0.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -488,7 +446,6 @@ struct AtanhFun { static constexpr const char *Parameters = "x"; static constexpr const char *Description = "Computes the inverse hyperbolic tan of x"; static constexpr const char *Example = "atanh(0.5)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/operators_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/operators_functions.hpp index a92258f0a..3bbfc565a 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/operators_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/operators_functions.hpp @@ -20,7 +20,6 @@ struct BitwiseAndFun { static constexpr const char *Parameters = "left,right"; static constexpr const char *Description = "Bitwise AND"; static constexpr const char *Example = "91 & 15"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -30,7 +29,6 @@ struct BitwiseOrFun { static constexpr const char *Parameters = "left,right"; static constexpr const char *Description = "Bitwise OR"; static constexpr const char *Example = "32 | 3"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -40,7 +38,6 @@ struct BitwiseNotFun { static constexpr const char *Parameters = "input"; static constexpr const char *Description = "Bitwise NOT"; static constexpr const char *Example = "~15"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -50,7 +47,6 @@ struct LeftShiftFun { static constexpr const char *Parameters = "input"; static constexpr const char *Description = "Bitwise shift left"; static constexpr const char *Example = "1 << 4"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -60,7 +56,6 @@ struct RightShiftFun { static constexpr const char *Parameters = "input"; static constexpr const char *Description = "Bitwise shift right"; static constexpr const char *Example = "8 >> 2"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -70,7 +65,6 @@ struct BitwiseXorFun { static constexpr const char *Parameters = "left,right"; static constexpr const char *Description = "Bitwise XOR"; static constexpr const char *Example = "xor(17, 5)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/random_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/random_functions.hpp index b5616fbb8..1002f0e44 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/random_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/random_functions.hpp @@ -20,7 +20,6 @@ struct RandomFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Returns a random number between 0 and 1"; static constexpr const char *Example = "random()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct SetseedFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = "Sets the seed to be used for the random function"; static constexpr const char *Example = "setseed(0.42)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -38,9 +36,8 @@ struct SetseedFun { struct UUIDFun { static constexpr const char *Name = "uuid"; static constexpr const char *Parameters = ""; - static constexpr const char *Description = "Returns a random UUID v4 similar to this: eeccb8c5-9943-b2bb-bb5e-222f4e14b687"; + static constexpr const char *Description = "Returns a random UUID similar to this: eeccb8c5-9943-b2bb-bb5e-222f4e14b687"; static constexpr const char *Example = "uuid()"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -51,44 +48,4 @@ struct GenRandomUuidFun { static constexpr const char *Name = "gen_random_uuid"; }; -struct UUIDv4Fun { - static constexpr const char *Name = "uuidv4"; - static constexpr const char *Parameters = ""; - static constexpr const char *Description = "Returns a random UUIDv4 similar to this: eeccb8c5-9943-b2bb-bb5e-222f4e14b687"; - static constexpr const char *Example = "uuidv4()"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - -struct UUIDv7Fun { - static constexpr const char *Name = "uuidv7"; - static constexpr const char *Parameters = ""; - static constexpr const char *Description = "Returns a random UUID v7 similar to this: 019482e4-1441-7aad-8127-eec99573b0a0"; - static constexpr const char *Example = "uuidv7()"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - -struct UUIDExtractVersionFun { - static constexpr const char *Name = "uuid_extract_version"; - static constexpr const char *Parameters = "uuid"; - static constexpr const char *Description = "Extract a version for the given UUID."; - static constexpr const char *Example = "uuid_extract_version('019482e4-1441-7aad-8127-eec99573b0a0')"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - -struct UUIDExtractTimestampFun { - static constexpr const char *Name = "uuid_extract_timestamp"; - static constexpr const char *Parameters = "uuid"; - static constexpr const char *Description = "Extract the timestamp for the given UUID v7."; - static constexpr const char *Example = "uuid_extract_timestamp('019482e4-1441-7aad-8127-eec99573b0a0')"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - } // namespace duckdb diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/string_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/string_functions.hpp index e37ce8af7..6a6db36da 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/string_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/string_functions.hpp @@ -20,7 +20,6 @@ struct StartsWithOperatorFun { static constexpr const char *Parameters = "string,search_string"; static constexpr const char *Description = "Returns true if string begins with search_string"; static constexpr const char *Example = "starts_with('abc','a')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -36,7 +35,6 @@ struct ASCIIFun { static constexpr const char *Parameters = "string"; static constexpr const char *Description = "Returns an integer that represents the Unicode code point of the first character of the string"; static constexpr const char *Example = "ascii('Ω')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -46,7 +44,6 @@ struct BarFun { static constexpr const char *Parameters = "x,min,max,width"; static constexpr const char *Description = "Draws a band whose width is proportional to (x - min) and equal to width characters when x = max. width defaults to 80"; static constexpr const char *Example = "bar(5, 0, 20, 10)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -56,7 +53,6 @@ struct BinFun { static constexpr const char *Parameters = "value"; static constexpr const char *Description = "Converts the value to binary representation"; static constexpr const char *Example = "bin(42)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -72,7 +68,6 @@ struct ChrFun { static constexpr const char *Parameters = "code_point"; static constexpr const char *Description = "Returns a character which is corresponding the ASCII code value or Unicode code point"; static constexpr const char *Example = "chr(65)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -82,7 +77,6 @@ struct DamerauLevenshteinFun { static constexpr const char *Parameters = "str1,str2"; static constexpr const char *Description = "Extension of Levenshtein distance to also include transposition of adjacent characters as an allowed edit operation. In other words, the minimum number of edit operations (insertions, deletions, substitutions or transpositions) required to change one string to another. Different case is considered different"; static constexpr const char *Example = "damerau_levenshtein('hello', 'world')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -92,7 +86,6 @@ struct FormatFun { static constexpr const char *Parameters = "format,parameters..."; static constexpr const char *Description = "Formats a string using fmt syntax"; static constexpr const char *Example = "format('Benchmark \"{}\" took {} seconds', 'CSV', 42)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -102,7 +95,6 @@ struct FormatBytesFun { static constexpr const char *Parameters = "bytes"; static constexpr const char *Description = "Converts bytes to a human-readable presentation (e.g. 16000 -> 15.6 KiB)"; static constexpr const char *Example = "format_bytes(1000 * 16)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -118,7 +110,6 @@ struct FormatreadabledecimalsizeFun { static constexpr const char *Parameters = "bytes"; static constexpr const char *Description = "Converts bytes to a human-readable presentation (e.g. 16000 -> 16.0 KB)"; static constexpr const char *Example = "format_bytes(1000 * 16)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -128,7 +119,6 @@ struct HammingFun { static constexpr const char *Parameters = "str1,str2"; static constexpr const char *Description = "The number of positions with different characters for 2 strings of equal length. Different case is considered different"; static constexpr const char *Example = "hamming('duck','luck')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -141,10 +131,9 @@ struct MismatchesFun { struct HexFun { static constexpr const char *Name = "hex"; - static constexpr const char *Parameters = "string::VARCHAR\1blob::BLOB\1value::ANY"; - static constexpr const char *Description = "Converts the string to hexadecimal representation.\1Converts `blob` to `VARCHAR` using hexadecimal encoding.\1Converts the value to hexadecimal representation."; - static constexpr const char *Example = "hex('Hello')\1hex('\\xAA\\xBB'::BLOB)\1hex(42)"; - static constexpr const char *Categories = "string\1blob\1numeric"; + static constexpr const char *Parameters = "value"; + static constexpr const char *Description = "Converts the value to hexadecimal representation"; + static constexpr const char *Example = "hex(42)"; static ScalarFunctionSet GetFunctions(); }; @@ -160,7 +149,6 @@ struct InstrFun { static constexpr const char *Parameters = "haystack,needle"; static constexpr const char *Description = "Returns location of first occurrence of needle in haystack, counting from 1. Returns 0 if no match found"; static constexpr const char *Example = "instr('test test','es')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -182,7 +170,6 @@ struct JaccardFun { static constexpr const char *Parameters = "str1,str2"; static constexpr const char *Description = "The Jaccard similarity between two strings. Different case is considered different. Returns a number between 0 and 1"; static constexpr const char *Example = "jaccard('duck','luck')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -192,7 +179,6 @@ struct JaroSimilarityFun { static constexpr const char *Parameters = "str1,str2,score_cutoff"; static constexpr const char *Description = "The Jaro similarity between two strings. Different case is considered different. Returns a number between 0 and 1"; static constexpr const char *Example = "jaro_similarity('duck', 'duckdb', 0.5)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -202,7 +188,6 @@ struct JaroWinklerSimilarityFun { static constexpr const char *Parameters = "str1,str2,score_cutoff"; static constexpr const char *Description = "The Jaro-Winkler similarity between two strings. Different case is considered different. Returns a number between 0 and 1"; static constexpr const char *Example = "jaro_winkler_similarity('duck', 'duckdb', 0.5)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -210,9 +195,8 @@ struct JaroWinklerSimilarityFun { struct LeftFun { static constexpr const char *Name = "left"; static constexpr const char *Parameters = "string,count"; - static constexpr const char *Description = "Extracts the left-most count characters"; + static constexpr const char *Description = "Extract the left-most count characters"; static constexpr const char *Example = "left('Hello🦆', 2)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -220,9 +204,8 @@ struct LeftFun { struct LeftGraphemeFun { static constexpr const char *Name = "left_grapheme"; static constexpr const char *Parameters = "string,count"; - static constexpr const char *Description = "Extracts the left-most count grapheme clusters"; + static constexpr const char *Description = "Extract the left-most count grapheme clusters"; static constexpr const char *Example = "left_grapheme('🤦🏼‍♂️🤦🏽‍♀️', 1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -232,7 +215,6 @@ struct LevenshteinFun { static constexpr const char *Parameters = "str1,str2"; static constexpr const char *Description = "The minimum number of single-character edits (insertions, deletions or substitutions) required to change one string to the other. Different case is considered different"; static constexpr const char *Example = "levenshtein('duck','db')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -248,7 +230,6 @@ struct LpadFun { static constexpr const char *Parameters = "string,count,character"; static constexpr const char *Description = "Pads the string with the character from the left until it has count characters"; static constexpr const char *Example = "lpad('hello', 10, '>')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -258,7 +239,6 @@ struct LtrimFun { static constexpr const char *Parameters = "string,characters"; static constexpr const char *Description = "Removes any occurrences of any of the characters from the left side of the string"; static constexpr const char *Example = "ltrim('>>>>test<<', '><')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -268,7 +248,6 @@ struct ParseDirnameFun { static constexpr const char *Parameters = "string,separator"; static constexpr const char *Description = "Returns the top-level directory name. separator options: system, both_slash (default), forward_slash, backslash"; static constexpr const char *Example = "parse_dirname('path/to/file.csv', 'system')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -278,7 +257,6 @@ struct ParseDirpathFun { static constexpr const char *Parameters = "string,separator"; static constexpr const char *Description = "Returns the head of the path similarly to Python's os.path.dirname. separator options: system, both_slash (default), forward_slash, backslash"; static constexpr const char *Example = "parse_dirpath('path/to/file.csv', 'system')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -288,7 +266,6 @@ struct ParseFilenameFun { static constexpr const char *Parameters = "string,trim_extension,separator"; static constexpr const char *Description = "Returns the last component of the path similarly to Python's os.path.basename. If trim_extension is true, the file extension will be removed (it defaults to false). separator options: system, both_slash (default), forward_slash, backslash"; static constexpr const char *Example = "parse_filename('path/to/file.csv', true, 'forward_slash')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -298,7 +275,6 @@ struct ParsePathFun { static constexpr const char *Parameters = "string,separator"; static constexpr const char *Description = "Returns a list of the components (directories and filename) in the path similarly to Python's pathlib.PurePath::parts. separator options: system, both_slash (default), forward_slash, backslash"; static constexpr const char *Example = "parse_path('path/to/file.csv', 'system')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -308,7 +284,6 @@ struct PrintfFun { static constexpr const char *Parameters = "format,parameters..."; static constexpr const char *Description = "Formats a string using printf syntax"; static constexpr const char *Example = "printf('Benchmark \"%s\" took %d seconds', 'CSV', 42)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -318,7 +293,6 @@ struct RepeatFun { static constexpr const char *Parameters = "string,count"; static constexpr const char *Description = "Repeats the string count number of times"; static constexpr const char *Example = "repeat('A', 5)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -328,7 +302,6 @@ struct ReplaceFun { static constexpr const char *Parameters = "string,source,target"; static constexpr const char *Description = "Replaces any occurrences of the source with target in string"; static constexpr const char *Example = "replace('hello', 'l', '-')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -338,7 +311,6 @@ struct ReverseFun { static constexpr const char *Parameters = "string"; static constexpr const char *Description = "Reverses the string"; static constexpr const char *Example = "reverse('hello')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -348,7 +320,6 @@ struct RightFun { static constexpr const char *Parameters = "string,count"; static constexpr const char *Description = "Extract the right-most count characters"; static constexpr const char *Example = "right('Hello🦆', 3)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -356,9 +327,8 @@ struct RightFun { struct RightGraphemeFun { static constexpr const char *Name = "right_grapheme"; static constexpr const char *Parameters = "string,count"; - static constexpr const char *Description = "Extracts the right-most count grapheme clusters"; + static constexpr const char *Description = "Extract the right-most count grapheme clusters"; static constexpr const char *Example = "right_grapheme('🤦🏼‍♂️🤦🏽‍♀️', 1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -368,7 +338,6 @@ struct RpadFun { static constexpr const char *Parameters = "string,count,character"; static constexpr const char *Description = "Pads the string with the character from the right until it has count characters"; static constexpr const char *Example = "rpad('hello', 10, '<')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -378,7 +347,6 @@ struct RtrimFun { static constexpr const char *Parameters = "string,characters"; static constexpr const char *Description = "Removes any occurrences of any of the characters from the right side of the string"; static constexpr const char *Example = "rtrim('>>>>test<<', '><')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -388,7 +356,6 @@ struct TranslateFun { static constexpr const char *Parameters = "string,from,to"; static constexpr const char *Description = "Replaces each character in string that matches a character in the from set with the corresponding character in the to set. If from is longer than to, occurrences of the extra characters in from are deleted"; static constexpr const char *Example = "translate('12345', '143', 'ax')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -398,7 +365,6 @@ struct TrimFun { static constexpr const char *Parameters = "string::VARCHAR\1string::VARCHAR,characters::VARCHAR"; static constexpr const char *Description = "Removes any spaces from either side of the string.\1Removes any occurrences of any of the characters from either side of the string"; static constexpr const char *Example = "trim(' test ')\1trim('>>>>test<<', '><')"; - static constexpr const char *Categories = "\1"; static ScalarFunctionSet GetFunctions(); }; @@ -406,9 +372,8 @@ struct TrimFun { struct UnbinFun { static constexpr const char *Name = "unbin"; static constexpr const char *Parameters = "value"; - static constexpr const char *Description = "Converts a value from binary representation to a blob."; + static constexpr const char *Description = "Converts a value from binary representation to a blob"; static constexpr const char *Example = "unbin('0110')"; - static constexpr const char *Categories = "string,blob"; static ScalarFunction GetFunction(); }; @@ -422,9 +387,8 @@ struct FromBinaryFun { struct UnhexFun { static constexpr const char *Name = "unhex"; static constexpr const char *Parameters = "value"; - static constexpr const char *Description = "Converts a value from hexadecimal representation to a blob."; + static constexpr const char *Description = "Converts a value from hexadecimal representation to a blob"; static constexpr const char *Example = "unhex('2A')"; - static constexpr const char *Categories = "string,blob"; static ScalarFunction GetFunction(); }; @@ -440,7 +404,6 @@ struct UnicodeFun { static constexpr const char *Parameters = "str"; static constexpr const char *Description = "Returns the unicode codepoint of the first character of the string"; static constexpr const char *Example = "unicode('ü')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -456,7 +419,6 @@ struct ToBaseFun { static constexpr const char *Parameters = "number,radix,min_length"; static constexpr const char *Description = "Converts a value to a string in the given base radix, optionally padding with leading zeros to the minimum length"; static constexpr const char *Example = "to_base(42, 16)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -466,7 +428,6 @@ struct UrlEncodeFun { static constexpr const char *Parameters = "input"; static constexpr const char *Description = "Escapes the input string by encoding it so that it can be included in a URL query parameter."; static constexpr const char *Example = "url_encode('this string has/ special+ characters>')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -476,7 +437,6 @@ struct UrlDecodeFun { static constexpr const char *Parameters = "input"; static constexpr const char *Description = "Unescapes the URL encoded input."; static constexpr const char *Example = "url_decode('this%20string%20is%2BFencoded')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/struct_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/struct_functions.hpp index e409eaf1c..f921bf434 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/struct_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/struct_functions.hpp @@ -20,7 +20,6 @@ struct StructInsertFun { static constexpr const char *Parameters = "struct,any"; static constexpr const char *Description = "Adds field(s)/value(s) to an existing STRUCT with the argument values. The entry name(s) will be the bound variable name(s)"; static constexpr const char *Example = "struct_insert({'a': 1}, b := 2)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/include/core_functions/scalar/union_functions.hpp b/src/duckdb/extension/core_functions/include/core_functions/scalar/union_functions.hpp index afd692e27..766c12e8f 100644 --- a/src/duckdb/extension/core_functions/include/core_functions/scalar/union_functions.hpp +++ b/src/duckdb/extension/core_functions/include/core_functions/scalar/union_functions.hpp @@ -20,7 +20,6 @@ struct UnionExtractFun { static constexpr const char *Parameters = "union,tag"; static constexpr const char *Description = "Extract the value with the named tags from the union. NULL if the tag is not currently selected"; static constexpr const char *Example = "union_extract(s, 'k')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct UnionTagFun { static constexpr const char *Parameters = "union"; static constexpr const char *Description = "Retrieve the currently selected tag of the union as an ENUM"; static constexpr const char *Example = "union_tag(union_value(k := 'foo'))"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -40,7 +38,6 @@ struct UnionValueFun { static constexpr const char *Parameters = "tag"; static constexpr const char *Description = "Create a single member UNION containing the argument value. The tag of the value will be the bound variable name"; static constexpr const char *Example = "union_value(k := 'hello')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/extension/core_functions/lambda_functions.cpp b/src/duckdb/extension/core_functions/lambda_functions.cpp index 665d79a72..29e583591 100644 --- a/src/duckdb/extension/core_functions/lambda_functions.cpp +++ b/src/duckdb/extension/core_functions/lambda_functions.cpp @@ -229,7 +229,6 @@ void ListLambdaBindData::Serialize(Serializer &serializer, const optional_ptr()); serializer.WriteProperty(102, "has_index", bind_data.has_index); - serializer.WriteProperty(103, "has_initial", bind_data.has_initial); } unique_ptr ListLambdaBindData::Deserialize(Deserializer &deserializer, ScalarFunction &) { @@ -237,8 +236,7 @@ unique_ptr ListLambdaBindData::Deserialize(Deserializer &deseriali auto lambda_expr = deserializer.ReadPropertyWithExplicitDefault>(101, "lambda_expr", unique_ptr()); auto has_index = deserializer.ReadProperty(102, "has_index"); - auto has_initial = deserializer.ReadProperty(103, "has_initial"); - return make_uniq(return_type, std::move(lambda_expr), has_index, has_initial); + return make_uniq(return_type, std::move(lambda_expr), has_index); } //===--------------------------------------------------------------------===// diff --git a/src/duckdb/extension/core_functions/scalar/date/to_interval.cpp b/src/duckdb/extension/core_functions/scalar/date/to_interval.cpp index fbe1c7939..c8d508883 100644 --- a/src/duckdb/extension/core_functions/scalar/date/to_interval.cpp +++ b/src/duckdb/extension/core_functions/scalar/date/to_interval.cpp @@ -14,12 +14,11 @@ bool TryMultiplyOperator::Operation(double left, int64_t right, int64_t &result) struct ToMillenniaOperator { template static inline TR Operation(TA input) { - const auto iinput = Cast::Operation(input); interval_t result; result.days = 0; result.micros = 0; - if (!TryMultiplyOperator::Operation(iinput, Interval::MONTHS_PER_MILLENIUM, - result.months)) { + if (!TryMultiplyOperator::Operation(input, Interval::MONTHS_PER_MILLENIUM, + result.months)) { throw OutOfRangeException("Interval value %s millennia out of range", NumericHelper::ToString(input)); } return result; @@ -29,12 +28,10 @@ struct ToMillenniaOperator { struct ToCenturiesOperator { template static inline TR Operation(TA input) { - const auto iinput = Cast::Operation(input); interval_t result; result.days = 0; result.micros = 0; - if (!TryMultiplyOperator::Operation(iinput, Interval::MONTHS_PER_CENTURY, - result.months)) { + if (!TryMultiplyOperator::Operation(input, Interval::MONTHS_PER_CENTURY, result.months)) { throw OutOfRangeException("Interval value %s centuries out of range", NumericHelper::ToString(input)); } return result; @@ -44,12 +41,10 @@ struct ToCenturiesOperator { struct ToDecadesOperator { template static inline TR Operation(TA input) { - const auto iinput = Cast::Operation(input); interval_t result; result.days = 0; result.micros = 0; - if (!TryMultiplyOperator::Operation(iinput, Interval::MONTHS_PER_DECADE, - result.months)) { + if (!TryMultiplyOperator::Operation(input, Interval::MONTHS_PER_DECADE, result.months)) { throw OutOfRangeException("Interval value %s decades out of range", NumericHelper::ToString(input)); } return result; @@ -59,11 +54,10 @@ struct ToDecadesOperator { struct ToYearsOperator { template static inline TR Operation(TA input) { - const auto iinput = Cast::Operation(input); interval_t result; result.days = 0; result.micros = 0; - if (!TryMultiplyOperator::Operation(iinput, Interval::MONTHS_PER_YEAR, + if (!TryMultiplyOperator::Operation(input, Interval::MONTHS_PER_YEAR, result.months)) { throw OutOfRangeException("Interval value %d years out of range", input); } @@ -74,9 +68,8 @@ struct ToYearsOperator { struct ToQuartersOperator { template static inline TR Operation(TA input) { - const auto iinput = Cast::Operation(input); interval_t result; - if (!TryMultiplyOperator::Operation(iinput, Interval::MONTHS_PER_QUARTER, + if (!TryMultiplyOperator::Operation(input, Interval::MONTHS_PER_QUARTER, result.months)) { throw OutOfRangeException("Interval value %d quarters out of range", input); } @@ -90,8 +83,7 @@ struct ToMonthsOperator { template static inline TR Operation(TA input) { interval_t result; - result.months = Cast::Operation(input); - ; + result.months = input; result.days = 0; result.micros = 0; return result; @@ -101,10 +93,9 @@ struct ToMonthsOperator { struct ToWeeksOperator { template static inline TR Operation(TA input) { - const auto iinput = Cast::Operation(input); interval_t result; result.months = 0; - if (!TryMultiplyOperator::Operation(iinput, Interval::DAYS_PER_WEEK, result.days)) { + if (!TryMultiplyOperator::Operation(input, Interval::DAYS_PER_WEEK, result.days)) { throw OutOfRangeException("Interval value %d weeks out of range", input); } result.micros = 0; @@ -117,7 +108,7 @@ struct ToDaysOperator { static inline TR Operation(TA input) { interval_t result; result.months = 0; - result.days = Cast::Operation(input); + result.days = input; result.micros = 0; return result; } @@ -173,49 +164,60 @@ struct ToMicroSecondsOperator { } }; -template -ScalarFunctionSet GetIntegerIntervalFunctions() { - ScalarFunctionSet function_set; - function_set.AddFunction(ScalarFunction({LogicalType::INTEGER}, LogicalType::INTERVAL, - ScalarFunction::UnaryFunction)); - function_set.AddFunction(ScalarFunction({LogicalType::BIGINT}, LogicalType::INTERVAL, - ScalarFunction::UnaryFunction)); - for (auto &func : function_set.functions) { - BaseScalarFunction::SetReturnsError(func); - } - return function_set; -} - -ScalarFunctionSet ToMillenniaFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToMillenniaFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } -ScalarFunctionSet ToCenturiesFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToCenturiesFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } -ScalarFunctionSet ToDecadesFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToDecadesFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } -ScalarFunctionSet ToYearsFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToYearsFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } -ScalarFunctionSet ToQuartersFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToQuartersFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } -ScalarFunctionSet ToMonthsFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToMonthsFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } -ScalarFunctionSet ToWeeksFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToWeeksFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } -ScalarFunctionSet ToDaysFun::GetFunctions() { - return GetIntegerIntervalFunctions(); +ScalarFunction ToDaysFun::GetFunction() { + ScalarFunction function({LogicalType::INTEGER}, LogicalType::INTERVAL, + ScalarFunction::UnaryFunction); + BaseScalarFunction::SetReturnsError(function); + return function; } ScalarFunction ToHoursFun::GetFunction() { diff --git a/src/duckdb/extension/core_functions/scalar/generic/least.cpp b/src/duckdb/extension/core_functions/scalar/generic/least.cpp index 886e909ca..40a943101 100644 --- a/src/duckdb/extension/core_functions/scalar/generic/least.cpp +++ b/src/duckdb/extension/core_functions/scalar/generic/least.cpp @@ -2,7 +2,6 @@ #include "core_functions/scalar/generic_functions.hpp" #include "duckdb/function/create_sort_key.hpp" #include "duckdb/planner/expression/bound_function_expression.hpp" -#include "duckdb/planner/expression_binder.hpp" namespace duckdb { diff --git a/src/duckdb/extension/core_functions/scalar/list/array_slice.cpp b/src/duckdb/extension/core_functions/scalar/list/array_slice.cpp index cefa9548e..0962b3c2e 100644 --- a/src/duckdb/extension/core_functions/scalar/list/array_slice.cpp +++ b/src/duckdb/extension/core_functions/scalar/list/array_slice.cpp @@ -416,13 +416,7 @@ static unique_ptr ArraySliceBind(ClientContext &context, ScalarFun "Slice with steps has not been implemented for string types, you can consider rewriting your query as " "follows:\n SELECT array_to_string((str_split(string, '')[begin:end:step], '');"); } - if (arguments[0]->return_type.IsJSONType()) { - // This is needed to avoid producing invalid JSON - bound_function.arguments[0] = LogicalType::VARCHAR; - bound_function.return_type = LogicalType::VARCHAR; - } else { - bound_function.return_type = arguments[0]->return_type; - } + bound_function.return_type = arguments[0]->return_type; for (idx_t i = 1; i < 3; i++) { if (arguments[i]->return_type.id() != LogicalTypeId::LIST) { bound_function.arguments[i] = LogicalType::BIGINT; diff --git a/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp b/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp index 1cb2fabeb..173b52699 100644 --- a/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp +++ b/src/duckdb/extension/core_functions/scalar/list/list_reduce.cpp @@ -8,9 +8,6 @@ namespace duckdb { struct ReduceExecuteInfo { ReduceExecuteInfo(LambdaFunctions::LambdaInfo &info, ClientContext &context) : left_slice(make_uniq(*info.child_vector)) { - if (info.has_initial) { - initial_value_offset = 0; - } SelectionVector left_vector(info.row_count); active_rows.Resize(info.row_count); active_rows.SetAllValid(info.row_count); @@ -20,14 +17,10 @@ struct ReduceExecuteInfo { idx_t reduced_row_idx = 0; - if (info.has_initial) { - left_vector.set_index(0, 0); - } - for (idx_t original_row_idx = 0; original_row_idx < info.row_count; original_row_idx++) { auto list_column_format_index = info.list_column_format.sel->get_index(original_row_idx); if (info.list_column_format.validity.RowIsValid(list_column_format_index)) { - if (info.list_entries[list_column_format_index].length == 0 && !info.has_initial) { + if (info.list_entries[list_column_format_index].length == 0) { throw ParameterNotAllowedException("Cannot perform list_reduce on an empty input list"); } left_vector.set_index(reduced_row_idx, info.list_entries[list_column_format_index].offset); @@ -45,34 +38,29 @@ struct ReduceExecuteInfo { } input_types.push_back(left_slice->GetType()); input_types.push_back(left_slice->GetType()); - // skip the first entry if there is an initial value - for (idx_t i = info.has_initial ? 1 : 0; i < info.column_infos.size(); i++) { - input_types.push_back(info.column_infos[i].vector.get().GetType()); + for (auto &entry : info.column_infos) { + input_types.push_back(entry.vector.get().GetType()); } expr_executor = make_uniq(context, *info.lambda_expr); }; - ValidityMask active_rows; unique_ptr left_slice; unique_ptr expr_executor; vector input_types; - idx_t initial_value_offset = 1; SelectionVector left_sel; SelectionVector active_rows_sel; }; -static bool ExecuteReduce(const idx_t loops, ReduceExecuteInfo &execute_info, LambdaFunctions::LambdaInfo &info, +static bool ExecuteReduce(idx_t loops, ReduceExecuteInfo &execute_info, LambdaFunctions::LambdaInfo &info, DataChunk &result_chunk) { idx_t original_row_idx = 0; idx_t reduced_row_idx = 0; idx_t valid_row_idx = 0; - idx_t loops_offset = loops + execute_info.initial_value_offset; - // create selection vectors for the left and right slice - const auto data = execute_info.active_rows.GetData(); + auto data = execute_info.active_rows.GetData(); // reset right_sel each iteration to prevent referencing issues SelectionVector right_sel; @@ -91,21 +79,13 @@ static bool ExecuteReduce(const idx_t loops, ReduceExecuteInfo &execute_info, La continue; } auto list_column_format_index = info.list_column_format.sel->get_index(original_row_idx); - if (info.list_entries[list_column_format_index].length > loops_offset) { - // While the list has more entries set the right slice to the next entry - right_sel.set_index(reduced_row_idx, info.list_entries[list_column_format_index].offset + loops_offset); + if (info.list_entries[list_column_format_index].length > loops + 1) { + right_sel.set_index(reduced_row_idx, info.list_entries[list_column_format_index].offset + loops + 1); execute_info.left_sel.set_index(reduced_row_idx, valid_row_idx); execute_info.active_rows_sel.set_index(reduced_row_idx, original_row_idx); reduced_row_idx++; - } else if (info.list_entries[list_column_format_index].length == 0 && info.has_initial && - loops_offset == 0) { - // If the list is empty and there is an initial value, use the initial value - execute_info.active_rows.SetInvalid(original_row_idx); - auto val = info.column_infos[0].vector.get().GetValue(original_row_idx); - info.result.SetValue(original_row_idx, val); } else { - // If the list has no more entries, write the result execute_info.active_rows.SetInvalid(original_row_idx); auto val = execute_info.left_slice->GetValue(valid_row_idx); info.result.SetValue(original_row_idx, val); @@ -120,8 +100,8 @@ static bool ExecuteReduce(const idx_t loops, ReduceExecuteInfo &execute_info, La return true; } - // create the index vector, where the index is that of the current node. - Vector index_vector(Value::BIGINT(UnsafeNumericCast(loops_offset + 1))); + // create the index vector + Vector index_vector(Value::BIGINT(UnsafeNumericCast(loops + 2))); // slice the left and right slice execute_info.left_slice->Slice(*execute_info.left_slice, execute_info.left_sel, reduced_row_idx); @@ -132,31 +112,22 @@ static bool ExecuteReduce(const idx_t loops, ReduceExecuteInfo &execute_info, La input_chunk.InitializeEmpty(execute_info.input_types); input_chunk.SetCardinality(reduced_row_idx); - const idx_t slice_offset = info.has_index ? 1 : 0; + idx_t slice_offset = info.has_index ? 1 : 0; if (info.has_index) { input_chunk.data[0].Reference(index_vector); } - - if (loops == 0 && info.has_initial) { - info.column_infos[0].vector.get().Slice(execute_info.active_rows_sel, reduced_row_idx); - input_chunk.data[slice_offset + 1].Reference(info.column_infos[0].vector); - } else { - input_chunk.data[slice_offset + 1].Reference(*execute_info.left_slice); - } + input_chunk.data[slice_offset + 1].Reference(*execute_info.left_slice); input_chunk.data[slice_offset].Reference(right_slice); // add the other columns - // skip the initial value if there is one vector slices; - const idx_t initial_offset = info.has_initial ? 1 : 0; - for (idx_t i = 0; i < info.column_infos.size() - initial_offset; i++) { + for (idx_t i = 0; i < info.column_infos.size(); i++) { if (info.column_infos[i].vector.get().GetVectorType() == VectorType::CONSTANT_VECTOR) { // only reference constant vectors - input_chunk.data[slice_offset + 2 + i].Reference(info.column_infos[initial_offset + i].vector); + input_chunk.data[slice_offset + 2 + i].Reference(info.column_infos[i].vector); } else { // slice the other vectors - slices.emplace_back(info.column_infos[initial_offset + i].vector, execute_info.active_rows_sel, - reduced_row_idx); + slices.emplace_back(info.column_infos[i].vector, execute_info.active_rows_sel, reduced_row_idx); input_chunk.data[slice_offset + 2 + i].Reference(slices.back()); } } @@ -175,7 +146,7 @@ static bool ExecuteReduce(const idx_t loops, ReduceExecuteInfo &execute_info, La void LambdaFunctions::ListReduceFunction(DataChunk &args, ExpressionState &state, Vector &result) { // Initializes the left slice from the list entries, active rows, the expression executor and the input types bool completed = false; - LambdaInfo info(args, state, result, completed); + LambdaFunctions::LambdaInfo info(args, state, result, completed); if (completed) { return; } @@ -212,7 +183,7 @@ static unique_ptr ListReduceBind(ClientContext &context, ScalarFun vector> &arguments) { // the list column and the bound lambda expression - D_ASSERT(arguments.size() == 2 || arguments.size() == 3); + D_ASSERT(arguments.size() == 2); if (arguments[1]->GetExpressionClass() != ExpressionClass::BOUND_LAMBDA) { throw BinderException("Invalid lambda expression!"); } @@ -233,41 +204,20 @@ static unique_ptr ListReduceBind(ClientContext &context, ScalarFun auto list_child_type = arguments[0]->return_type; list_child_type = ListType::GetChildType(list_child_type); - bool has_initial = arguments.size() == 3; - if (has_initial) { - const auto initial_value_type = arguments[2]->return_type; - // Check if the initial value type is the same as the list child type and if not find the max logical type - if (list_child_type != initial_value_type) { - LogicalType max_logical_type; - const auto has_max_logical_type = - LogicalType::TryGetMaxLogicalType(context, list_child_type, initial_value_type, max_logical_type); - if (!has_max_logical_type) { - throw BinderException( - "The initial value type must be the same as the list child type or a common super type"); - } - - list_child_type = max_logical_type; - arguments[0] = BoundCastExpression::AddCastToType(context, std::move(arguments[0]), - LogicalType::LIST(max_logical_type)); - arguments[2] = BoundCastExpression::AddCastToType(context, std::move(arguments[2]), max_logical_type); - } - } - auto cast_lambda_expr = - BoundCastExpression::AddCastToType(context, std::move(bound_lambda_expr.lambda_expr), list_child_type); + BoundCastExpression::AddCastToType(context, std::move(bound_lambda_expr.lambda_expr), list_child_type, false); if (!cast_lambda_expr) { throw BinderException("Could not cast lambda expression to list child type"); } bound_function.return_type = cast_lambda_expr->return_type; - return make_uniq(bound_function.return_type, std::move(cast_lambda_expr), has_index, - has_initial); + return make_uniq(bound_function.return_type, std::move(cast_lambda_expr), has_index); } static LogicalType ListReduceBindLambda(const idx_t parameter_idx, const LogicalType &list_child_type) { return LambdaFunctions::BindTernaryLambda(parameter_idx, list_child_type); } -ScalarFunctionSet ListReduceFun::GetFunctions() { +ScalarFunction ListReduceFun::GetFunction() { ScalarFunction fun({LogicalType::LIST(LogicalType::ANY), LogicalType::LAMBDA}, LogicalType::ANY, LambdaFunctions::ListReduceFunction, ListReduceBind, nullptr, nullptr); @@ -276,11 +226,7 @@ ScalarFunctionSet ListReduceFun::GetFunctions() { fun.deserialize = ListLambdaBindData::Deserialize; fun.bind_lambda = ListReduceBindLambda; - ScalarFunctionSet set; - set.AddFunction(fun); - fun.arguments.push_back(LogicalType::ANY); - set.AddFunction(fun); - return set; + return fun; } } // namespace duckdb diff --git a/src/duckdb/extension/core_functions/scalar/list/list_sort.cpp b/src/duckdb/extension/core_functions/scalar/list/list_sort.cpp index f7c0bbeef..5ab523d20 100644 --- a/src/duckdb/extension/core_functions/scalar/list/list_sort.cpp +++ b/src/duckdb/extension/core_functions/scalar/list/list_sort.cpp @@ -118,7 +118,7 @@ static void ListSortFunction(DataChunk &args, ExpressionState &state, Vector &re // initialize the global and local sorting state auto &buffer_manager = BufferManager::GetBufferManager(info.context); - GlobalSortState global_sort_state(info.context, info.orders, info.payload_layout); + GlobalSortState global_sort_state(buffer_manager, info.orders, info.payload_layout); LocalSortState local_sort_state; local_sort_state.Initialize(global_sort_state, buffer_manager); diff --git a/src/duckdb/extension/core_functions/scalar/random/random.cpp b/src/duckdb/extension/core_functions/scalar/random/random.cpp index 4ffaaa3eb..3054170ff 100644 --- a/src/duckdb/extension/core_functions/scalar/random/random.cpp +++ b/src/duckdb/extension/core_functions/scalar/random/random.cpp @@ -5,56 +5,9 @@ #include "duckdb/planner/expression/bound_function_expression.hpp" #include "duckdb/common/random_engine.hpp" #include "duckdb/common/types/uuid.hpp" -#include "duckdb/common/types/timestamp.hpp" namespace duckdb { -struct ExtractVersionUuidOperator { - template - static RESULT_TYPE Operation(INPUT_TYPE input, Vector &result) { - char uuid[36]; // Intentionally no initialize. - BaseUUID::ToString(input, uuid); - // UUIDv4 and UUIDv7 stores version as the 15-th uint8_t. - return uuid[14] - '0'; - } -}; - -struct ExtractTimestampUuidOperator { - template - static RESULT_TYPE Operation(INPUT_TYPE input, Vector &result) { - // Validate whether the given UUID is v7. - const uint8_t version = (static_cast((input.upper) >> 8) & 0xf0) >> 4; - if (version != 7) { - throw InvalidInputException("Given UUID is with version %u, not version 7.", version); - } - - // UUID v7 begins with a 48 bit big-endian Unix Epoch timestamp with millisecond granularity. - const int64_t upper = input.upper; - int64_t unix_ts_milli = upper; - unix_ts_milli = unix_ts_milli >> 16; - - static constexpr int64_t kMilliToMicro = 1000; - const int64_t unix_ts_ms = kMilliToMicro * unix_ts_milli; - return timestamp_t {unix_ts_ms}; - } -}; - -template -static void ExtractVersionFunction(DataChunk &args, ExpressionState &state, Vector &result) { - D_ASSERT(args.ColumnCount() == 1); - auto &input = args.data[0]; - idx_t count = args.size(); - UnaryExecutor::ExecuteString(input, result, count); -} - -template -static void ExtractTimestampFunction(DataChunk &args, ExpressionState &state, Vector &result) { - D_ASSERT(args.ColumnCount() == 1); - auto &input = args.data[0]; - idx_t count = args.size(); - UnaryExecutor::ExecuteString(input, result, count); -} - struct RandomLocalState : public FunctionLocalState { explicit RandomLocalState(uint64_t seed) : random_engine(0) { random_engine.SetSeed(seed); @@ -88,19 +41,7 @@ ScalarFunction RandomFun::GetFunction() { return random; } -static void GenerateUUIDv4Function(DataChunk &args, ExpressionState &state, Vector &result) { - D_ASSERT(args.ColumnCount() == 0); - auto &lstate = ExecuteFunctionState::GetFunctionState(state)->Cast(); - - result.SetVectorType(VectorType::FLAT_VECTOR); - auto result_data = FlatVector::GetData(result); - - for (idx_t i = 0; i < args.size(); i++) { - result_data[i] = UUIDv4::GenerateRandomUUID(lstate.random_engine); - } -} - -static void GenerateUUIDv7Function(DataChunk &args, ExpressionState &state, Vector &result) { +static void GenerateUUIDFunction(DataChunk &args, ExpressionState &state, Vector &result) { D_ASSERT(args.ColumnCount() == 0); auto &lstate = ExecuteFunctionState::GetFunctionState(state)->Cast(); @@ -108,38 +49,16 @@ static void GenerateUUIDv7Function(DataChunk &args, ExpressionState &state, Vect auto result_data = FlatVector::GetData(result); for (idx_t i = 0; i < args.size(); i++) { - result_data[i] = UUIDv7::GenerateRandomUUID(lstate.random_engine); + result_data[i] = UUID::GenerateRandomUUID(lstate.random_engine); } } ScalarFunction UUIDFun::GetFunction() { - return UUIDv4Fun::GetFunction(); -} - -ScalarFunction UUIDv4Fun::GetFunction() { - ScalarFunction uuid_v4_function({}, LogicalType::UUID, GenerateUUIDv4Function, nullptr, nullptr, nullptr, - RandomInitLocalState); - // generate a random uuid v4 - uuid_v4_function.stability = FunctionStability::VOLATILE; - return uuid_v4_function; -} - -ScalarFunction UUIDv7Fun::GetFunction() { - ScalarFunction uuid_v7_function({}, LogicalType::UUID, GenerateUUIDv7Function, nullptr, nullptr, nullptr, - RandomInitLocalState); - // generate a random uuid v7 - uuid_v7_function.stability = FunctionStability::VOLATILE; - return uuid_v7_function; -} - -ScalarFunction UUIDExtractVersionFun::GetFunction() { - return ScalarFunction({LogicalType::UUID}, LogicalType::UINTEGER, - ExtractVersionFunction); -} - -ScalarFunction UUIDExtractTimestampFun::GetFunction() { - return ScalarFunction({LogicalType::UUID}, LogicalType::TIMESTAMP_TZ, - ExtractTimestampFunction); + ScalarFunction uuid_function({}, LogicalType::UUID, GenerateUUIDFunction, nullptr, nullptr, nullptr, + RandomInitLocalState); + // generate a random uuid + uuid_function.stability = FunctionStability::VOLATILE; + return uuid_function; } } // namespace duckdb diff --git a/src/duckdb/extension/icu/icu-dateadd.cpp b/src/duckdb/extension/icu/icu-dateadd.cpp index 32fe9ad1a..29b0cf73b 100644 --- a/src/duckdb/extension/icu/icu-dateadd.cpp +++ b/src/duckdb/extension/icu/icu-dateadd.cpp @@ -8,27 +8,26 @@ #include "duckdb/parser/parsed_data/create_scalar_function_info.hpp" #include "duckdb/planner/expression/bound_function_expression.hpp" #include "include/icu-datefunc.hpp" -#include "icu-helpers.hpp" namespace duckdb { struct ICUCalendarAdd { template - static inline TR Operation(TA left, TB right, TZCalendar &calendar_p) { + static inline TR Operation(TA left, TB right, icu::Calendar *calendar) { throw InternalException("Unimplemented type for ICUCalendarAdd"); } }; struct ICUCalendarSub : public ICUDateFunc { template - static inline TR Operation(TA left, TB right, TZCalendar &calendar_p) { + static inline TR Operation(TA left, TB right, icu::Calendar *calendar) { throw InternalException("Unimplemented type for ICUCalendarSub"); } }; struct ICUCalendarAge : public ICUDateFunc { template - static inline TR Operation(TA left, TB right, TZCalendar &calendar_p) { + static inline TR Operation(TA left, TB right, icu::Calendar *calendar) { throw InternalException("Unimplemented type for ICUCalendarAge"); } }; @@ -54,11 +53,10 @@ static inline void CalendarAddHour(icu::Calendar *calendar, int64_t interval_hou } template <> -timestamp_t ICUCalendarAdd::Operation(timestamp_t timestamp, interval_t interval, TZCalendar &calendar_p) { +timestamp_t ICUCalendarAdd::Operation(timestamp_t timestamp, interval_t interval, icu::Calendar *calendar) { if (!Timestamp::IsFinite(timestamp)) { return timestamp; } - auto calendar = calendar_p.GetICUCalendar(); int64_t millis = timestamp.value / Interval::MICROS_PER_MSEC; int64_t micros = timestamp.value % Interval::MICROS_PER_MSEC; @@ -122,26 +120,25 @@ timestamp_t ICUCalendarAdd::Operation(timestamp_t timestamp, interval_t interval } template <> -timestamp_t ICUCalendarAdd::Operation(interval_t interval, timestamp_t timestamp, TZCalendar &calendar) { +timestamp_t ICUCalendarAdd::Operation(interval_t interval, timestamp_t timestamp, icu::Calendar *calendar) { return Operation(timestamp, interval, calendar); } template <> -timestamp_t ICUCalendarSub::Operation(timestamp_t timestamp, interval_t interval, TZCalendar &calendar) { +timestamp_t ICUCalendarSub::Operation(timestamp_t timestamp, interval_t interval, icu::Calendar *calendar) { const interval_t negated {-interval.months, -interval.days, -interval.micros}; return ICUCalendarAdd::template Operation(timestamp, negated, calendar); } template <> -interval_t ICUCalendarSub::Operation(timestamp_t end_date, timestamp_t start_date, TZCalendar &calendar_p) { +interval_t ICUCalendarSub::Operation(timestamp_t end_date, timestamp_t start_date, icu::Calendar *calendar) { if (!Timestamp::IsFinite(end_date) || !Timestamp::IsFinite(start_date)) { throw InvalidInputException("Cannot subtract infinite timestamps"); } if (start_date > end_date) { - auto negated = Operation(start_date, end_date, calendar_p); + auto negated = Operation(start_date, end_date, calendar); return {-negated.months, -negated.days, -negated.micros}; } - auto calendar = calendar_p.GetICUCalendar(); auto start_micros = ICUDateFunc::SetTime(calendar, start_date); auto end_micros = (uint64_t)(end_date.value % Interval::MICROS_PER_MSEC); @@ -169,16 +166,9 @@ interval_t ICUCalendarSub::Operation(timestamp_t end_date, timestamp_t start_dat } template <> -interval_t ICUCalendarAge::Operation(timestamp_t end_date, timestamp_t start_date, TZCalendar &calendar_p) { - auto calendar = calendar_p.GetICUCalendar(); - if (calendar_p.IsGregorian()) { - auto start_data = ICUHelpers::GetComponents(timestamp_tz_t(start_date.value), calendar); - auto end_data = ICUHelpers::GetComponents(timestamp_tz_t(end_date.value), calendar); - return Interval::GetAge(end_data, start_data, start_date > end_date); - } - // fallback for non-gregorian calendars, since Interval::GetAge does not handle +interval_t ICUCalendarAge::Operation(timestamp_t end_date, timestamp_t start_date, icu::Calendar *calendar) { if (start_date > end_date) { - auto negated = Operation(start_date, end_date, calendar_p); + auto negated = Operation(start_date, end_date, calendar); return {-negated.months, -negated.days, -negated.micros}; } @@ -215,13 +205,13 @@ struct ICUDateAdd : public ICUDateFunc { auto &func_expr = state.expr.Cast(); auto &info = func_expr.bind_info->Cast(); - TZCalendar calendar(*info.calendar, info.cal_setting); + CalendarPtr calendar(info.calendar->clone()); // Subtract argument from current_date (at midnight) - const auto end_date = CurrentMidnight(calendar.GetICUCalendar(), state); + const auto end_date = CurrentMidnight(calendar.get(), state); UnaryExecutor::Execute(args.data[0], result, args.size(), [&](TA start_date) { - return OP::template Operation(end_date, start_date, calendar); + return OP::template Operation(end_date, start_date, calendar.get()); }); } @@ -237,10 +227,10 @@ struct ICUDateAdd : public ICUDateFunc { auto &func_expr = state.expr.Cast(); auto &info = func_expr.bind_info->Cast(); - TZCalendar calendar(*info.calendar, info.cal_setting); + CalendarPtr calendar(info.calendar->clone()); BinaryExecutor::Execute(args.data[0], args.data[1], result, args.size(), [&](TA left, TB right) { - return OP::template Operation(left, right, calendar); + return OP::template Operation(left, right, calendar.get()); }); } @@ -297,15 +287,15 @@ struct ICUDateAdd : public ICUDateFunc { } }; -timestamp_t ICUDateFunc::Add(TZCalendar &calendar, timestamp_t timestamp, interval_t interval) { +timestamp_t ICUDateFunc::Add(icu::Calendar *calendar, timestamp_t timestamp, interval_t interval) { return ICUCalendarAdd::Operation(timestamp, interval, calendar); } -timestamp_t ICUDateFunc::Sub(TZCalendar &calendar, timestamp_t timestamp, interval_t interval) { +timestamp_t ICUDateFunc::Sub(icu::Calendar *calendar, timestamp_t timestamp, interval_t interval) { return ICUCalendarSub::Operation(timestamp, interval, calendar); } -interval_t ICUDateFunc::Sub(TZCalendar &calendar, timestamp_t end_date, timestamp_t start_date) { +interval_t ICUDateFunc::Sub(icu::Calendar *calendar, timestamp_t end_date, timestamp_t start_date) { return ICUCalendarSub::Operation(end_date, start_date, calendar); } diff --git a/src/duckdb/extension/icu/icu-datefunc.cpp b/src/duckdb/extension/icu/icu-datefunc.cpp index 5b0c2255c..0c38827ba 100644 --- a/src/duckdb/extension/icu/icu-datefunc.cpp +++ b/src/duckdb/extension/icu/icu-datefunc.cpp @@ -5,7 +5,6 @@ #include "duckdb/common/operator/multiply.hpp" #include "duckdb/common/types/timestamp.hpp" #include "duckdb/common/exception/conversion_exception.hpp" -#include "icu-helpers.hpp" #include "unicode/ucal.h" namespace duckdb { @@ -60,7 +59,7 @@ void ICUDateFunc::BindData::InitCalendar() { bool ICUDateFunc::BindData::Equals(const FunctionData &other_p) const { auto &other = other_p.Cast(); - return calendar->isEquivalentTo(*other.calendar); + return *calendar == *other.calendar; } unique_ptr ICUDateFunc::BindData::Copy() const { @@ -73,19 +72,19 @@ unique_ptr ICUDateFunc::Bind(ClientContext &context, ScalarFunctio } bool ICUDateFunc::TrySetTimeZone(icu::Calendar *calendar, const string_t &tz_id) { - string tz_str = tz_id.GetString(); - auto tz = ICUHelpers::TryGetTimeZone(tz_str); - if (!tz) { + auto tz = icu_66::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(icu::StringPiece(tz_id.GetString()))); + if (*tz == icu::TimeZone::getUnknown()) { + delete tz; return false; } - calendar->adoptTimeZone(tz.release()); + calendar->adoptTimeZone(tz); return true; } void ICUDateFunc::SetTimeZone(icu::Calendar *calendar, const string_t &tz_id) { - string tz_str = tz_id.GetString(); - auto tz = ICUHelpers::GetTimeZone(tz_str); - calendar->adoptTimeZone(tz.release()); + if (!TrySetTimeZone(calendar, tz_id)) { + throw NotImplementedException("Unknown TimeZone '%s'", tz_id.GetString()); + } } timestamp_t ICUDateFunc::GetTimeUnsafe(icu::Calendar *calendar, uint64_t micros) { diff --git a/src/duckdb/extension/icu/icu-list-range.cpp b/src/duckdb/extension/icu/icu-list-range.cpp index 490627954..ea50d7be3 100644 --- a/src/duckdb/extension/icu/icu-list-range.cpp +++ b/src/duckdb/extension/icu/icu-list-range.cpp @@ -60,7 +60,7 @@ struct ICUListRange : public ICUDateFunc { increment_value = ListIncrementValue(row_idx); } - uint64_t ListLength(idx_t row_idx, TZCalendar &calendar) { + uint64_t ListLength(idx_t row_idx, icu::Calendar *calendar) { timestamp_t start_value; timestamp_t end_value; interval_t increment_value; @@ -68,7 +68,7 @@ struct ICUListRange : public ICUDateFunc { return ListLength(start_value, end_value, increment_value, INCLUSIVE_BOUND, calendar); } - void Increment(timestamp_t &input, interval_t increment, TZCalendar &calendar) { + void Increment(timestamp_t &input, interval_t increment, icu::Calendar *calendar) { input = Add(calendar, input, increment); } @@ -77,7 +77,7 @@ struct ICUListRange : public ICUDateFunc { UnifiedVectorFormat vdata[3]; uint64_t ListLength(timestamp_t start_value, timestamp_t end_value, interval_t increment_value, - bool inclusive_bound, TZCalendar &calendar) { + bool inclusive_bound, icu::Calendar *calendar) { bool is_positive = increment_value.months > 0 || increment_value.days > 0 || increment_value.micros > 0; bool is_negative = increment_value.months < 0 || increment_value.days < 0 || increment_value.micros < 0; if (!is_negative && !is_positive) { @@ -130,7 +130,8 @@ struct ICUListRange : public ICUDateFunc { auto &func_expr = state.expr.Cast(); auto &bind_info = func_expr.bind_info->Cast(); - TZCalendar calendar(*bind_info.calendar, bind_info.cal_setting); + CalendarPtr calendar_ptr(bind_info.calendar->clone()); + auto calendar = calendar_ptr.get(); RangeInfoStruct info(args); idx_t args_size = 1; diff --git a/src/duckdb/extension/icu/icu-strptime.cpp b/src/duckdb/extension/icu/icu-strptime.cpp index 696b63df7..37c125595 100644 --- a/src/duckdb/extension/icu/icu-strptime.cpp +++ b/src/duckdb/extension/icu/icu-strptime.cpp @@ -1,6 +1,5 @@ #include "include/icu-strptime.hpp" #include "include/icu-datefunc.hpp" -#include "include/icu-helpers.hpp" #include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp" #include "duckdb/common/operator/cast_operators.hpp" @@ -18,28 +17,6 @@ namespace duckdb { -TimestampComponents ICUHelpers::GetComponents(timestamp_tz_t ts, icu::Calendar *calendar) { - // Get the parts in the given time zone - uint64_t micros = ICUDateFunc::SetTime(calendar, timestamp_t(ts.value)); - - TimestampComponents ts_data; - ts_data.year = ICUDateFunc::ExtractField(calendar, UCAL_EXTENDED_YEAR); - ts_data.month = ICUDateFunc::ExtractField(calendar, UCAL_MONTH) + 1; - ts_data.day = ICUDateFunc::ExtractField(calendar, UCAL_DATE); - - ts_data.hour = ICUDateFunc::ExtractField(calendar, UCAL_HOUR_OF_DAY); - ts_data.minute = ICUDateFunc::ExtractField(calendar, UCAL_MINUTE); - ts_data.second = ICUDateFunc::ExtractField(calendar, UCAL_SECOND); - ts_data.microsecond = UnsafeNumericCast( - ICUDateFunc::ExtractField(calendar, UCAL_MILLISECOND) * Interval::MICROS_PER_MSEC + micros); - return ts_data; -} - -timestamp_t ICUHelpers::ToTimestamp(TimestampComponents data) { - date_t date_val = Date::FromDate(data.year, data.month, data.day); - dtime_t time_val = Time::FromTime(data.hour, data.minute, data.second, data.microsecond); - return Timestamp::FromDatetime(date_val, time_val); -} struct ICUStrptime : public ICUDateFunc { using ParseResult = StrpTimeFormat::ParseResult; @@ -89,13 +66,13 @@ struct ICUStrptime : public ICUDateFunc { calendar->set(UCAL_HOUR_OF_DAY, parsed.data[3]); calendar->set(UCAL_MINUTE, parsed.data[4]); calendar->set(UCAL_SECOND, parsed.data[5]); - calendar->set(UCAL_MILLISECOND, UnsafeNumericCast(micros / Interval::MICROS_PER_MSEC)); + calendar->set(UCAL_MILLISECOND, micros / Interval::MICROS_PER_MSEC); micros %= Interval::MICROS_PER_MSEC; // This overrides the TZ setting, so only use it if an offset was parsed. // Note that we don't bother/worry about the DST setting because the two just combine. if (format.HasFormatSpecifier(StrTimeSpecifier::UTC_OFFSET)) { - calendar->set(UCAL_ZONE_OFFSET, UnsafeNumericCast(parsed.data[7] * Interval::MSECS_PER_SEC)); + calendar->set(UCAL_ZONE_OFFSET, parsed.data[7] * Interval::MSECS_PER_SEC * Interval::SECS_PER_MINUTE); } return micros; @@ -394,11 +371,11 @@ struct ICUStrftime : public ICUDateFunc { data[3] = ExtractField(calendar, UCAL_HOUR_OF_DAY); data[4] = ExtractField(calendar, UCAL_MINUTE); data[5] = ExtractField(calendar, UCAL_SECOND); - data[6] = - UnsafeNumericCast(ExtractField(calendar, UCAL_MILLISECOND) * Interval::MICROS_PER_MSEC + micros); + data[6] = ExtractField(calendar, UCAL_MILLISECOND) * Interval::MICROS_PER_MSEC + micros; data[7] = ExtractField(calendar, UCAL_ZONE_OFFSET) + ExtractField(calendar, UCAL_DST_OFFSET); data[7] /= Interval::MSECS_PER_SEC; + data[7] /= Interval::SECS_PER_MINUTE; const auto date = Date::FromDate(data[0], data[1], data[2]); const auto time = Time::FromTime(data[3], data[4], data[5], data[6]); @@ -468,15 +445,26 @@ struct ICUStrftime : public ICUDateFunc { return StringVector::AddString(result, Timestamp::ToString(input)); } - // decompose the timestamp - auto ts_data = ICUHelpers::GetComponents(timestamp_tz_t(input.value), calendar); + // Get the parts in the given time zone + uint64_t micros = SetTime(calendar, input); + + int32_t date_units[3]; + date_units[0] = ExtractField(calendar, UCAL_EXTENDED_YEAR); // strftime doesn't understand eras. + date_units[1] = ExtractField(calendar, UCAL_MONTH) + 1; + date_units[2] = ExtractField(calendar, UCAL_DATE); + + int32_t time_units[4]; + time_units[0] = ExtractField(calendar, UCAL_HOUR_OF_DAY); + time_units[1] = ExtractField(calendar, UCAL_MINUTE); + time_units[2] = ExtractField(calendar, UCAL_SECOND); + time_units[3] = ExtractField(calendar, UCAL_MILLISECOND) * Interval::MICROS_PER_MSEC + micros; idx_t year_length; bool add_bc; - const auto date_len = DateToStringCast::YearLength(ts_data.year, year_length, add_bc); + const auto date_len = DateToStringCast::Length(date_units, year_length, add_bc); char micro_buffer[6]; - const auto time_len = TimeToStringCast::MicrosLength(ts_data.microsecond, micro_buffer); + const auto time_len = TimeToStringCast::Length(time_units, micro_buffer); auto offset = ExtractField(calendar, UCAL_ZONE_OFFSET) + ExtractField(calendar, UCAL_DST_OFFSET); offset /= Interval::MSECS_PER_SEC; @@ -490,12 +478,11 @@ struct ICUStrftime : public ICUDateFunc { string_t target = StringVector::EmptyString(result, len); auto buffer = target.GetDataWriteable(); - DateToStringCast::Format(buffer, ts_data.year, ts_data.month, ts_data.day, year_length, add_bc); + DateToStringCast::Format(buffer, date_units, year_length, add_bc); buffer += date_len; *buffer++ = ' '; - TimeToStringCast::Format(buffer, time_len, ts_data.hour, ts_data.minute, ts_data.second, ts_data.microsecond, - micro_buffer); + TimeToStringCast::Format(buffer, time_len, time_units, micro_buffer); buffer += time_len; memcpy(buffer, offset_str.c_str(), offset_len); diff --git a/src/duckdb/extension/icu/icu-table-range.cpp b/src/duckdb/extension/icu/icu-table-range.cpp index 70572ba3c..51dd5de77 100644 --- a/src/duckdb/extension/icu/icu-table-range.cpp +++ b/src/duckdb/extension/icu/icu-table-range.cpp @@ -7,7 +7,6 @@ #include "duckdb/parser/parsed_data/create_table_function_info.hpp" #include "include/icu-datefunc.hpp" #include "unicode/calendar.h" -#include "tz_calendar.hpp" namespace duckdb { @@ -64,8 +63,6 @@ struct ICUTableRange { bool inclusive_bound; bool greater_than_check; - bool empty_range = false; - bool Finished(timestamp_t current_value) const { if (greater_than_check) { if (inclusive_bound) { @@ -116,12 +113,14 @@ struct ICUTableRange { } result.greater_than_check = true; if (result.start > result.end) { - result.empty_range = true; + throw BinderException( + "start is bigger than end, but increment is positive: cannot generate infinite series"); } } else { result.greater_than_check = false; if (result.start < result.end) { - result.empty_range = true; + throw BinderException( + "start is smaller than end, but increment is negative: cannot generate infinite series"); } } result.inclusive_bound = GENERATE_SERIES; @@ -152,7 +151,8 @@ struct ICUTableRange { DataChunk &input, DataChunk &output) { auto &bind_data = data_p.bind_data->Cast(); auto &state = data_p.local_state->Cast(); - TZCalendar calendar(*bind_data.calendar, bind_data.cal_setting); + CalendarPtr calendar_ptr(bind_data.calendar->clone()); + auto calendar = calendar_ptr.get(); while (true) { if (!state.initialized_row) { // initialize for the current input row @@ -166,13 +166,6 @@ struct ICUTableRange { state.initialized_row = true; state.current_state = state.start; } - if (state.empty_range) { - // empty range - output.SetCardinality(0); - state.current_input_row++; - state.initialized_row = false; - return OperatorResultType::HAVE_MORE_OUTPUT; - } idx_t size = 0; auto data = FlatVector::GetData(output.data[0]); while (true) { diff --git a/src/duckdb/extension/icu/icu-timebucket.cpp b/src/duckdb/extension/icu/icu-timebucket.cpp index 8db9012c9..ffb62ca1b 100644 --- a/src/duckdb/extension/icu/icu-timebucket.cpp +++ b/src/duckdb/extension/icu/icu-timebucket.cpp @@ -62,7 +62,7 @@ struct ICUTimeBucket : public ICUDateFunc { } static inline timestamp_t WidthConvertibleToMicrosCommon(int64_t bucket_width_micros, const timestamp_t ts, - const timestamp_t origin, TZCalendar &calendar) { + const timestamp_t origin, icu::Calendar *calendar) { if (!bucket_width_micros) { throw OutOfRangeException("Can't bucket using zero microseconds"); } @@ -78,13 +78,13 @@ struct ICUTimeBucket : public ICUDateFunc { } static inline timestamp_t WidthConvertibleToDaysCommon(int32_t bucket_width_days, const timestamp_t ts, - const timestamp_t origin, TZCalendar &calendar) { + const timestamp_t origin, icu::Calendar *calendar) { if (!bucket_width_days) { throw OutOfRangeException("Can't bucket using zero days"); } const auto sub_days = SubtractFactory(DatePartSpecifier::DAY); - int64_t ts_days = sub_days(calendar.GetICUCalendar(), origin, ts); + int64_t ts_days = sub_days(calendar, origin, ts); int64_t result_days = (ts_days / bucket_width_days) * bucket_width_days; if (result_days < NumericLimits::Minimum() || result_days > NumericLimits::Maximum()) { throw OutOfRangeException("Timestamp out of range"); @@ -100,14 +100,13 @@ struct ICUTimeBucket : public ICUDateFunc { } static inline timestamp_t WidthConvertibleToMonthsCommon(int32_t bucket_width_months, const timestamp_t ts, - const timestamp_t origin, TZCalendar &calendar_p) { + const timestamp_t origin, icu::Calendar *calendar) { if (!bucket_width_months) { throw OutOfRangeException("Can't bucket using zero months"); } const auto trunc_months = TruncationFactory(DatePartSpecifier::MONTH); const auto sub_months = SubtractFactory(DatePartSpecifier::MONTH); - auto calendar = calendar_p.GetICUCalendar(); uint64_t tmp_micros = SetTime(calendar, ts); trunc_months(calendar, tmp_micros); timestamp_t truncated_ts = GetTimeUnsafe(calendar, tmp_micros); @@ -127,7 +126,7 @@ struct ICUTimeBucket : public ICUDateFunc { SubtractOperatorOverflowCheck::Operation(result_months, bucket_width_months); } - return Add(calendar_p, truncated_origin, interval_t {static_cast(result_months), 0, 0}); + return Add(calendar, truncated_origin, interval_t {static_cast(result_months), 0, 0}); } template @@ -158,7 +157,7 @@ struct ICUTimeBucket : public ICUDateFunc { } struct WidthConvertibleToMicrosBinaryOperator { - static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, TZCalendar &calendar) { + static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -168,7 +167,7 @@ struct ICUTimeBucket : public ICUDateFunc { }; struct WidthConvertibleToDaysBinaryOperator { - static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, TZCalendar &calendar) { + static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -178,7 +177,7 @@ struct ICUTimeBucket : public ICUDateFunc { }; struct WidthConvertibleToMonthsBinaryOperator { - static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, TZCalendar &calendar) { + static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -188,7 +187,7 @@ struct ICUTimeBucket : public ICUDateFunc { }; struct BinaryOperator { - static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, TZCalendar &calendar) { + static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, icu::Calendar *calendar) { BucketWidthType bucket_width_type = ClassifyBucketWidthErrorThrow(bucket_width); switch (bucket_width_type) { case BucketWidthType::CONVERTIBLE_TO_MICROS: @@ -205,7 +204,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OffsetWidthConvertibleToMicrosTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, interval_t offset, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -218,7 +217,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OffsetWidthConvertibleToDaysTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, interval_t offset, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -231,7 +230,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OffsetWidthConvertibleToMonthsTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, interval_t offset, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -244,7 +243,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OffsetTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, interval_t offset, - TZCalendar &calendar) { + icu::Calendar *calendar) { BucketWidthType bucket_width_type = ClassifyBucketWidthErrorThrow(bucket_width); switch (bucket_width_type) { case BucketWidthType::CONVERTIBLE_TO_MICROS: @@ -261,7 +260,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OriginWidthConvertibleToMicrosTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, timestamp_t origin, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -271,7 +270,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OriginWidthConvertibleToDaysTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, timestamp_t origin, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -281,7 +280,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OriginWidthConvertibleToMonthsTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, timestamp_t origin, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -291,7 +290,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct OriginTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, timestamp_t origin, - ValidityMask &mask, idx_t idx, TZCalendar &calendar) { + ValidityMask &mask, idx_t idx, icu::Calendar *calendar) { if (!Value::IsFinite(origin)) { mask.SetInvalid(idx); return timestamp_t(0); @@ -312,7 +311,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct TimeZoneWidthConvertibleToMicrosBinaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, timestamp_t origin, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -322,7 +321,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct TimeZoneWidthConvertibleToDaysBinaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, timestamp_t origin, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -332,7 +331,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct TimeZoneWidthConvertibleToMonthsBinaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, timestamp_t origin, - TZCalendar &calendar) { + icu::Calendar *calendar) { if (!Value::IsFinite(ts)) { return ts; } @@ -342,8 +341,7 @@ struct ICUTimeBucket : public ICUDateFunc { struct TimeZoneTernaryOperator { static inline timestamp_t Operation(interval_t bucket_width, timestamp_t ts, string_t tz, - TZCalendar &calendar_p) { - auto calendar = calendar_p.GetICUCalendar(); + icu::Calendar *calendar) { SetTimeZone(calendar, tz); timestamp_t origin; @@ -351,13 +349,13 @@ struct ICUTimeBucket : public ICUDateFunc { switch (bucket_width_type) { case BucketWidthType::CONVERTIBLE_TO_MICROS: origin = ICUDateFunc::FromNaive(calendar, Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_1)); - return TimeZoneWidthConvertibleToMicrosBinaryOperator::Operation(bucket_width, ts, origin, calendar_p); + return TimeZoneWidthConvertibleToMicrosBinaryOperator::Operation(bucket_width, ts, origin, calendar); case BucketWidthType::CONVERTIBLE_TO_DAYS: origin = ICUDateFunc::FromNaive(calendar, Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_1)); - return TimeZoneWidthConvertibleToDaysBinaryOperator::Operation(bucket_width, ts, origin, calendar_p); + return TimeZoneWidthConvertibleToDaysBinaryOperator::Operation(bucket_width, ts, origin, calendar); case BucketWidthType::CONVERTIBLE_TO_MONTHS: origin = ICUDateFunc::FromNaive(calendar, Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_2)); - return TimeZoneWidthConvertibleToMonthsBinaryOperator::Operation(bucket_width, ts, origin, calendar_p); + return TimeZoneWidthConvertibleToMonthsBinaryOperator::Operation(bucket_width, ts, origin, calendar); default: throw NotImplementedException("Bucket type not implemented for ICU TIME_BUCKET"); } @@ -369,8 +367,9 @@ struct ICUTimeBucket : public ICUDateFunc { auto &func_expr = state.expr.Cast(); auto &info = func_expr.bind_info->Cast(); - TZCalendar calendar(*info.calendar, info.cal_setting); - SetTimeZone(calendar.GetICUCalendar(), string_t("UTC")); + CalendarPtr calendar_ptr(info.calendar->clone()); + auto calendar = calendar_ptr.get(); + SetTimeZone(calendar, string_t("UTC")); auto &bucket_width_arg = args.data[0]; auto &ts_arg = args.data[1]; @@ -424,8 +423,9 @@ struct ICUTimeBucket : public ICUDateFunc { auto &func_expr = state.expr.Cast(); auto &info = func_expr.bind_info->Cast(); - TZCalendar calendar(*info.calendar, info.cal_setting); - SetTimeZone(calendar.GetICUCalendar(), string_t("UTC")); + CalendarPtr calendar_ptr(info.calendar->clone()); + auto calendar = calendar_ptr.get(); + SetTimeZone(calendar, string_t("UTC")); auto &bucket_width_arg = args.data[0]; auto &ts_arg = args.data[1]; @@ -488,8 +488,9 @@ struct ICUTimeBucket : public ICUDateFunc { auto &func_expr = state.expr.Cast(); auto &info = func_expr.bind_info->Cast(); - TZCalendar calendar(*info.calendar, info.cal_setting); - SetTimeZone(calendar.GetICUCalendar(), string_t("UTC")); + CalendarPtr calendar_ptr(info.calendar->clone()); + auto calendar = calendar_ptr.get(); + SetTimeZone(calendar, string_t("UTC")); auto &bucket_width_arg = args.data[0]; auto &ts_arg = args.data[1]; @@ -555,7 +556,8 @@ struct ICUTimeBucket : public ICUDateFunc { auto &func_expr = state.expr.Cast(); auto &info = func_expr.bind_info->Cast(); - TZCalendar calendar(*info.calendar, info.cal_setting); + CalendarPtr calendar_ptr(info.calendar->clone()); + auto calendar = calendar_ptr.get(); auto &bucket_width_arg = args.data[0]; auto &ts_arg = args.data[1]; @@ -568,13 +570,13 @@ struct ICUTimeBucket : public ICUDateFunc { ConstantVector::SetNull(result, true); } else { interval_t bucket_width = *ConstantVector::GetData(bucket_width_arg); - SetTimeZone(calendar.GetICUCalendar(), *ConstantVector::GetData(tz_arg)); + SetTimeZone(calendar, *ConstantVector::GetData(tz_arg)); timestamp_t origin; BucketWidthType bucket_width_type = ClassifyBucketWidth(bucket_width); switch (bucket_width_type) { case BucketWidthType::CONVERTIBLE_TO_MICROS: - origin = ICUDateFunc::FromNaive(calendar.GetICUCalendar(), - Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_1)); + origin = + ICUDateFunc::FromNaive(calendar, Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_1)); BinaryExecutor::Execute( bucket_width_arg, ts_arg, result, args.size(), [&](interval_t bucket_width, timestamp_t ts) { return TimeZoneWidthConvertibleToMicrosBinaryOperator::Operation(bucket_width, ts, origin, @@ -582,8 +584,8 @@ struct ICUTimeBucket : public ICUDateFunc { }); break; case BucketWidthType::CONVERTIBLE_TO_DAYS: - origin = ICUDateFunc::FromNaive(calendar.GetICUCalendar(), - Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_1)); + origin = + ICUDateFunc::FromNaive(calendar, Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_1)); BinaryExecutor::Execute( bucket_width_arg, ts_arg, result, args.size(), [&](interval_t bucket_width, timestamp_t ts) { return TimeZoneWidthConvertibleToDaysBinaryOperator::Operation(bucket_width, ts, origin, @@ -591,8 +593,8 @@ struct ICUTimeBucket : public ICUDateFunc { }); break; case BucketWidthType::CONVERTIBLE_TO_MONTHS: - origin = ICUDateFunc::FromNaive(calendar.GetICUCalendar(), - Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_2)); + origin = + ICUDateFunc::FromNaive(calendar, Timestamp::FromEpochMicroSeconds(DEFAULT_ORIGIN_MICROS_2)); BinaryExecutor::Execute( bucket_width_arg, ts_arg, result, args.size(), [&](interval_t bucket_width, timestamp_t ts) { return TimeZoneWidthConvertibleToMonthsBinaryOperator::Operation(bucket_width, ts, origin, diff --git a/src/duckdb/extension/icu/icu_extension.cpp b/src/duckdb/extension/icu/icu_extension.cpp index 755c07170..380dc42d3 100644 --- a/src/duckdb/extension/icu/icu_extension.cpp +++ b/src/duckdb/extension/icu/icu_extension.cpp @@ -32,7 +32,6 @@ #include "unicode/stringpiece.h" #include "unicode/timezone.h" #include "unicode/ucol.h" -#include "icu-helpers.hpp" #include @@ -211,63 +210,41 @@ static ScalarFunction GetICUCollateFunction(const string &collation, const strin return result; } -unique_ptr GetTimeZoneInternal(string &tz_str, vector &candidates) { - icu::StringPiece tz_name_utf8(tz_str); - const auto uid = icu::UnicodeString::fromUTF8(tz_name_utf8); +static void SetICUTimeZone(ClientContext &context, SetScope scope, Value ¶meter) { + auto str = StringValue::Get(parameter); + icu::StringPiece utf8(str); + const auto uid = icu::UnicodeString::fromUTF8(utf8); duckdb::unique_ptr tz(icu::TimeZone::createTimeZone(uid)); if (*tz != icu::TimeZone::getUnknown()) { - return tz; + return; } - // Try to be friendlier - // Go through all the zone names and look for a case insensitive match - // If we don't find one, make a suggestion - // FIXME: this is very inefficient + // Try to be friendlier + // Go through all the zone names and look for a case insensitive match + // If we don't find one, make a suggestion UErrorCode status = U_ZERO_ERROR; duckdb::unique_ptr calendar(icu::Calendar::createInstance(status)); duckdb::unique_ptr tzs(icu::TimeZone::createEnumeration()); + vector candidates; for (;;) { auto long_id = tzs->snext(status); if (U_FAILURE(status) || !long_id) { break; } - std::string candidate_tz_name; - long_id->toUTF8String(candidate_tz_name); - if (StringUtil::CIEquals(candidate_tz_name, tz_str)) { - // case insensitive match - return this timezone instead - tz_str = candidate_tz_name; - icu::StringPiece utf8(tz_str); - const auto tz_unicode_str = icu::UnicodeString::fromUTF8(utf8); - duckdb::unique_ptr insensitive_tz(icu::TimeZone::createTimeZone(tz_unicode_str)); - return insensitive_tz; + std::string utf8; + long_id->toUTF8String(utf8); + if (StringUtil::CIEquals(utf8, str)) { + parameter = Value(utf8); + return; } - candidates.emplace_back(candidate_tz_name); + candidates.emplace_back(utf8); } - return nullptr; -} -unique_ptr ICUHelpers::TryGetTimeZone(string &tz_str) { - vector candidates; - return GetTimeZoneInternal(tz_str, candidates); -} - -unique_ptr ICUHelpers::GetTimeZone(string &tz_str) { - vector candidates; - auto tz = GetTimeZoneInternal(tz_str, candidates); - if (tz) { - return tz; - } string candidate_str = - StringUtil::CandidatesMessage(StringUtil::TopNJaroWinkler(candidates, tz_str), "Candidate time zones"); - - throw NotImplementedException("Unknown TimeZone '%s'!\n%s", tz_str, candidate_str); -} + StringUtil::CandidatesMessage(StringUtil::TopNJaroWinkler(candidates, str), "Candidate time zones"); -static void SetICUTimeZone(ClientContext &context, SetScope scope, Value ¶meter) { - auto tz_str = StringValue::Get(parameter); - ICUHelpers::GetTimeZone(tz_str); - parameter = Value(tz_str); + throw NotImplementedException("Unknown TimeZone '%s'!\n%s", str, candidate_str); } struct ICUCalendarData : public GlobalTableFunctionState { diff --git a/src/duckdb/extension/icu/include/icu-datefunc.hpp b/src/duckdb/extension/icu/include/icu-datefunc.hpp index 13c7be47e..cc1420324 100644 --- a/src/duckdb/extension/icu/include/icu-datefunc.hpp +++ b/src/duckdb/extension/icu/include/icu-datefunc.hpp @@ -13,11 +13,12 @@ #include "duckdb/common/enums/date_part_specifier.hpp" #include "duckdb/planner/expression/bound_function_expression.hpp" #include "unicode/calendar.h" -#include "tz_calendar.hpp" namespace duckdb { struct ICUDateFunc { + using CalendarPtr = duckdb::unique_ptr; + struct BindData : public FunctionData { explicit BindData(ClientContext &context); BindData(const string &tz_setting, const string &cal_setting); @@ -65,11 +66,11 @@ struct ICUDateFunc { //! Subtracts the field of the given date from the calendar static int32_t SubtractField(icu::Calendar *calendar, UCalendarDateFields field, timestamp_t end_date); //! Adds the timestamp and the interval using the calendar - static timestamp_t Add(TZCalendar &calendar, timestamp_t timestamp, interval_t interval); + static timestamp_t Add(icu::Calendar *calendar, timestamp_t timestamp, interval_t interval); //! Subtracts the interval from the timestamp using the calendar - static timestamp_t Sub(TZCalendar &calendar, timestamp_t timestamp, interval_t interval); + static timestamp_t Sub(icu::Calendar *calendar, timestamp_t timestamp, interval_t interval); //! Subtracts the latter timestamp from the former timestamp using the calendar - static interval_t Sub(TZCalendar &calendar, timestamp_t end_date, timestamp_t start_date); + static interval_t Sub(icu::Calendar *calendar, timestamp_t end_date, timestamp_t start_date); //! Pulls out the bin values from the timestamp assuming it is an instant, //! constructs an ICU timestamp, and then converts that back to a DuckDB instant //! Adding offset doesn't really work around DST because the bin values are ambiguous diff --git a/src/duckdb/extension/json/buffered_json_reader.cpp b/src/duckdb/extension/json/buffered_json_reader.cpp new file mode 100644 index 000000000..4ee0c35d6 --- /dev/null +++ b/src/duckdb/extension/json/buffered_json_reader.cpp @@ -0,0 +1,341 @@ +#include "buffered_json_reader.hpp" + +#include "duckdb/common/file_opener.hpp" +#include "duckdb/common/serializer/deserializer.hpp" +#include "duckdb/common/serializer/serializer.hpp" + +#include + +namespace duckdb { + +JSONBufferHandle::JSONBufferHandle(idx_t buffer_index_p, idx_t readers_p, AllocatedData &&buffer_p, idx_t buffer_size_p) + : buffer_index(buffer_index_p), readers(readers_p), buffer(std::move(buffer_p)), buffer_size(buffer_size_p) { +} + +JSONFileHandle::JSONFileHandle(unique_ptr file_handle_p, Allocator &allocator_p) + : file_handle(std::move(file_handle_p)), allocator(allocator_p), can_seek(file_handle->CanSeek()), + file_size(file_handle->GetFileSize()), read_position(0), requested_reads(0), actual_reads(0), + last_read_requested(false), cached_size(0) { +} + +bool JSONFileHandle::IsOpen() const { + return file_handle != nullptr; +} + +void JSONFileHandle::Close() { + if (IsOpen() && !file_handle->IsPipe()) { + file_handle->Close(); + file_handle = nullptr; + } +} + +void JSONFileHandle::Reset() { + D_ASSERT(RequestedReadsComplete()); + read_position = 0; + requested_reads = 0; + actual_reads = 0; + last_read_requested = false; + if (IsOpen() && !file_handle->IsPipe()) { + file_handle->Reset(); + } +} + +bool JSONFileHandle::RequestedReadsComplete() { + return requested_reads == actual_reads; +} + +bool JSONFileHandle::LastReadRequested() const { + return last_read_requested; +} + +idx_t JSONFileHandle::FileSize() const { + return file_size; +} + +idx_t JSONFileHandle::Remaining() const { + return file_size - read_position; +} + +bool JSONFileHandle::CanSeek() const { + return can_seek; +} + +bool JSONFileHandle::IsPipe() const { + return file_handle->IsPipe(); +} + +FileHandle &JSONFileHandle::GetHandle() { + return *file_handle; +} + +bool JSONFileHandle::GetPositionAndSize(idx_t &position, idx_t &size, idx_t requested_size) { + D_ASSERT(requested_size != 0); + if (last_read_requested) { + return false; + } + + position = read_position; + size = MinValue(requested_size, Remaining()); + read_position += size; + + requested_reads++; + if (size == 0) { + last_read_requested = true; + } + + return true; +} + +void JSONFileHandle::ReadAtPosition(char *pointer, idx_t size, idx_t position, bool &file_done, bool sample_run, + optional_ptr override_handle) { + if (size != 0) { + auto &handle = override_handle ? *override_handle.get() : *file_handle.get(); + + if (!cached_buffers.empty() || position < cached_size) { + ReadFromCache(pointer, size, position); + } + + handle.Read(pointer, size, position); + if (file_handle->IsPipe()) { // Cache the buffer + cached_buffers.emplace_back(allocator.Allocate(size)); + memcpy(cached_buffers.back().get(), pointer, size); + cached_size += size; + } + } + + const auto incremented_actual_reads = ++actual_reads; + if (incremented_actual_reads > requested_reads) { + throw InternalException("JSONFileHandle performed more actual reads than requested reads"); + } + + if (last_read_requested && incremented_actual_reads == requested_reads) { + file_done = true; + } +} + +bool JSONFileHandle::Read(char *pointer, idx_t &read_size, idx_t requested_size, bool &file_done, bool sample_run) { + D_ASSERT(requested_size != 0); + read_size = 0; + if (last_read_requested) { + return false; + } + + if (!cached_buffers.empty() || read_position < cached_size) { + read_size += ReadFromCache(pointer, requested_size, read_position); + } + + auto temp_read_size = ReadInternal(pointer, requested_size); + if (file_handle->IsPipe() && temp_read_size != 0) { // Cache the buffer + cached_buffers.emplace_back(allocator.Allocate(temp_read_size)); + memcpy(cached_buffers.back().get(), pointer, temp_read_size); + } + cached_size += temp_read_size; + read_position += temp_read_size; + read_size += temp_read_size; + + if (read_size == 0) { + last_read_requested = true; + file_done = true; + } + + return true; +} + +idx_t JSONFileHandle::ReadInternal(char *pointer, const idx_t requested_size) { + // Deal with reading from pipes + idx_t total_read_size = 0; + while (total_read_size < requested_size) { + auto read_size = file_handle->Read(pointer + total_read_size, requested_size - total_read_size); + if (read_size == 0) { + break; + } + total_read_size += read_size; + } + return total_read_size; +} + +idx_t JSONFileHandle::ReadFromCache(char *&pointer, idx_t &size, idx_t &position) { + idx_t read_size = 0; + idx_t total_offset = 0; + + idx_t cached_buffer_idx; + for (cached_buffer_idx = 0; cached_buffer_idx < cached_buffers.size(); cached_buffer_idx++) { + auto &cached_buffer = cached_buffers[cached_buffer_idx]; + if (size == 0) { + break; + } + if (position < total_offset + cached_buffer.GetSize()) { + idx_t within_buffer_offset = position - total_offset; + idx_t copy_size = MinValue(size, cached_buffer.GetSize() - within_buffer_offset); + memcpy(pointer, cached_buffer.get() + within_buffer_offset, copy_size); + + read_size += copy_size; + pointer += copy_size; + size -= copy_size; + position += copy_size; + } + total_offset += cached_buffer.GetSize(); + } + + return read_size; +} + +BufferedJSONReader::BufferedJSONReader(ClientContext &context, BufferedJSONReaderOptions options_p, string file_name_p) + : context(context), options(std::move(options_p)), file_name(std::move(file_name_p)), buffer_index(0), + thrown(false) { +} + +void BufferedJSONReader::OpenJSONFile() { + lock_guard guard(lock); + if (!IsOpen()) { + auto &fs = FileSystem::GetFileSystem(context); + auto regular_file_handle = fs.OpenFile(file_name, FileFlags::FILE_FLAGS_READ | options.compression); + file_handle = make_uniq(std::move(regular_file_handle), BufferAllocator::Get(context)); + } + Reset(); +} + +void BufferedJSONReader::Reset() { + buffer_index = 0; + buffer_map.clear(); + buffer_line_or_object_counts.clear(); + if (HasFileHandle()) { + file_handle->Reset(); + } +} + +bool BufferedJSONReader::HasFileHandle() const { + return file_handle != nullptr; +} + +bool BufferedJSONReader::IsOpen() const { + if (HasFileHandle()) { + return file_handle->IsOpen(); + } + return false; +} + +BufferedJSONReaderOptions &BufferedJSONReader::GetOptions() { + return options; +} + +JSONFormat BufferedJSONReader::GetFormat() const { + return options.format; +} + +void BufferedJSONReader::SetFormat(JSONFormat format) { + D_ASSERT(options.format == JSONFormat::AUTO_DETECT); + options.format = format; +} + +JSONRecordType BufferedJSONReader::GetRecordType() const { + return options.record_type; +} + +void BufferedJSONReader::SetRecordType(duckdb::JSONRecordType type) { + D_ASSERT(options.record_type == JSONRecordType::AUTO_DETECT); + options.record_type = type; +} + +const string &BufferedJSONReader::GetFileName() const { + return file_name; +} + +JSONFileHandle &BufferedJSONReader::GetFileHandle() const { + D_ASSERT(HasFileHandle()); + return *file_handle; +} + +void BufferedJSONReader::InsertBuffer(idx_t buffer_idx, unique_ptr &&buffer) { + lock_guard guard(lock); + buffer_map.insert(make_pair(buffer_idx, std::move(buffer))); +} + +optional_ptr BufferedJSONReader::GetBuffer(idx_t buffer_idx) { + lock_guard guard(lock); + auto it = buffer_map.find(buffer_idx); + return it == buffer_map.end() ? nullptr : it->second.get(); +} + +AllocatedData BufferedJSONReader::RemoveBuffer(JSONBufferHandle &handle) { + lock_guard guard(lock); + auto it = buffer_map.find(handle.buffer_index); + D_ASSERT(it != buffer_map.end()); + D_ASSERT(RefersToSameObject(handle, *it->second)); + auto result = std::move(it->second->buffer); + buffer_map.erase(it); + return result; +} + +idx_t BufferedJSONReader::GetBufferIndex() { + buffer_line_or_object_counts.push_back(-1); + return buffer_index++; +} + +void BufferedJSONReader::SetBufferLineOrObjectCount(JSONBufferHandle &handle, idx_t count) { + lock_guard guard(lock); + D_ASSERT(buffer_map.find(handle.buffer_index) != buffer_map.end()); + D_ASSERT(RefersToSameObject(handle, *buffer_map.find(handle.buffer_index)->second)); + D_ASSERT(buffer_line_or_object_counts[handle.buffer_index] == -1); + buffer_line_or_object_counts[handle.buffer_index] = count; +} + +idx_t BufferedJSONReader::GetLineNumber(idx_t buf_index, idx_t line_or_object_in_buf) { + D_ASSERT(options.format != JSONFormat::AUTO_DETECT); + while (true) { + idx_t line = line_or_object_in_buf; + bool can_throw = true; + { + lock_guard guard(lock); + if (thrown) { + return DConstants::INVALID_INDEX; + } + for (idx_t b_idx = 0; b_idx < buf_index; b_idx++) { + if (buffer_line_or_object_counts[b_idx] == -1) { + can_throw = false; + break; + } else { + line += buffer_line_or_object_counts[b_idx]; + } + } + if (can_throw) { + thrown = true; + // SQL uses 1-based indexing so I guess we will do that in our exception here as well + return line + 1; + } + } + TaskScheduler::YieldThread(); + } +} + +void BufferedJSONReader::ThrowParseError(idx_t buf_index, idx_t line_or_object_in_buf, yyjson_read_err &err, + const string &extra) { + string unit = options.format == JSONFormat::NEWLINE_DELIMITED ? "line" : "record/value"; + auto line = GetLineNumber(buf_index, line_or_object_in_buf); + throw InvalidInputException("Malformed JSON in file \"%s\", at byte %llu in %s %llu: %s. %s", file_name, + err.pos + 1, unit, line + 1, err.msg, extra); +} + +void BufferedJSONReader::ThrowTransformError(idx_t buf_index, idx_t line_or_object_in_buf, + const string &error_message) { + string unit = options.format == JSONFormat::NEWLINE_DELIMITED ? "line" : "record/value"; + auto line = GetLineNumber(buf_index, line_or_object_in_buf); + throw InvalidInputException("JSON transform error in file \"%s\", in %s %llu: %s", file_name, unit, line, + error_message); +} + +bool BufferedJSONReader::HasThrown() { + lock_guard guard(lock); + return thrown; +} + +double BufferedJSONReader::GetProgress() const { + lock_guard guard(lock); + if (HasFileHandle()) { + return 100.0 - 100.0 * double(file_handle->Remaining()) / double(file_handle->FileSize()); + } else { + return 0; + } +} + +} // namespace duckdb diff --git a/src/duckdb/extension/json/include/buffered_json_reader.hpp b/src/duckdb/extension/json/include/buffered_json_reader.hpp new file mode 100644 index 000000000..3069546b0 --- /dev/null +++ b/src/duckdb/extension/json/include/buffered_json_reader.hpp @@ -0,0 +1,172 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// buffered_json_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "duckdb/common/atomic.hpp" +#include "duckdb/common/enum_util.hpp" +#include "duckdb/common/enums/file_compression_type.hpp" +#include "duckdb/common/file_system.hpp" +#include "duckdb/common/multi_file_reader.hpp" +#include "duckdb/common/mutex.hpp" +#include "json_common.hpp" +#include "json_enums.hpp" + +namespace duckdb { + +struct BufferedJSONReaderOptions { +public: + //! The format of the JSON + JSONFormat format = JSONFormat::AUTO_DETECT; + //! Whether record types in the JSON + JSONRecordType record_type = JSONRecordType::AUTO_DETECT; + //! Whether file is compressed or not, and if so which compression type + FileCompressionType compression = FileCompressionType::AUTO_DETECT; + //! Multi-file reader options + MultiFileReaderOptions file_options; + +public: + void Serialize(Serializer &serializer) const; + static BufferedJSONReaderOptions Deserialize(Deserializer &deserializer); +}; + +struct JSONBufferHandle { +public: + JSONBufferHandle(idx_t buffer_index, idx_t readers, AllocatedData &&buffer, idx_t buffer_size); + +public: + //! Buffer index (within same file) + const idx_t buffer_index; + + //! Number of readers for this buffer + atomic readers; + //! The buffer + AllocatedData buffer; + //! The size of the data in the buffer (can be less than buffer.GetSize()) + const idx_t buffer_size; +}; + +struct JSONFileHandle { +public: + JSONFileHandle(unique_ptr file_handle, Allocator &allocator); + + bool IsOpen() const; + void Close(); + + void Reset(); + bool RequestedReadsComplete(); + bool LastReadRequested() const; + + idx_t FileSize() const; + idx_t Remaining() const; + + bool CanSeek() const; + bool IsPipe() const; + + FileHandle &GetHandle(); + + //! The next two functions return whether the read was successful + bool GetPositionAndSize(idx_t &position, idx_t &size, idx_t requested_size); + bool Read(char *pointer, idx_t &read_size, idx_t requested_size, bool &file_done, bool sample_run); + //! Read at position optionally allows passing a custom handle to read from, otherwise the default one is used + void ReadAtPosition(char *pointer, idx_t size, idx_t position, bool &file_done, bool sample_run, + optional_ptr override_handle = nullptr); + +private: + idx_t ReadInternal(char *pointer, const idx_t requested_size); + idx_t ReadFromCache(char *&pointer, idx_t &size, idx_t &position); + +private: + //! The JSON file handle + unique_ptr file_handle; + Allocator &allocator; + + //! File properties + const bool can_seek; + const idx_t file_size; + + //! Read properties + idx_t read_position; + atomic requested_reads; + atomic actual_reads; + atomic last_read_requested; + + //! Cached buffers for resetting when reading stream + vector cached_buffers; + idx_t cached_size; +}; + +class BufferedJSONReader { +public: + BufferedJSONReader(ClientContext &context, BufferedJSONReaderOptions options, string file_name); + + void OpenJSONFile(); + void Reset(); + + bool HasFileHandle() const; + bool IsOpen() const; + + BufferedJSONReaderOptions &GetOptions(); + + JSONFormat GetFormat() const; + void SetFormat(JSONFormat format); + + JSONRecordType GetRecordType() const; + void SetRecordType(JSONRecordType type); + + const string &GetFileName() const; + JSONFileHandle &GetFileHandle() const; + +public: + //! Insert/get/remove buffer (grabs the lock) + void InsertBuffer(idx_t buffer_idx, unique_ptr &&buffer); + optional_ptr GetBuffer(idx_t buffer_idx); + AllocatedData RemoveBuffer(JSONBufferHandle &handle); + + //! Get a new buffer index (must hold the lock) + idx_t GetBufferIndex(); + //! Set line count for a buffer that is done (grabs the lock) + void SetBufferLineOrObjectCount(JSONBufferHandle &handle, idx_t count); + //! Throws a parse error that mentions the file name and line number + void ThrowParseError(idx_t buf_index, idx_t line_or_object_in_buf, yyjson_read_err &err, const string &extra = ""); + //! Throws a transform error that mentions the file name and line number + void ThrowTransformError(idx_t buf_index, idx_t line_or_object_in_buf, const string &error_message); + //! Whether this reader has thrown if an error has occurred + bool HasThrown(); + + //! Scan progress + double GetProgress() const; + +private: + idx_t GetLineNumber(idx_t buf_index, idx_t line_or_object_in_buf); + +private: + ClientContext &context; + BufferedJSONReaderOptions options; + + //! File name + const string file_name; + //! File handle + unique_ptr file_handle; + + //! Next buffer index within the file + idx_t buffer_index; + //! Mapping from batch index to currently held buffers + unordered_map> buffer_map; + + //! Line count per buffer + vector buffer_line_or_object_counts; + //! Whether any of the reading threads has thrown an error + bool thrown; + +public: + mutable mutex lock; + MultiFileReaderData reader_data; +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/json/include/json_enums.hpp b/src/duckdb/extension/json/include/json_enums.hpp index b5dbab3e6..86e8b3093 100644 --- a/src/duckdb/extension/json/include/json_enums.hpp +++ b/src/duckdb/extension/json/include/json_enums.hpp @@ -15,7 +15,9 @@ enum class JSONScanType : uint8_t { //! Read JSON straight to columnar data READ_JSON = 1, //! Read JSON values as strings - READ_JSON_OBJECTS = 2 + READ_JSON_OBJECTS = 2, + //! Sample run for schema detection + SAMPLE = 3, }; enum class JSONRecordType : uint8_t { diff --git a/src/duckdb/extension/json/include/json_scan.hpp b/src/duckdb/extension/json/include/json_scan.hpp index 5a54be913..4fd7bc0a0 100644 --- a/src/duckdb/extension/json/include/json_scan.hpp +++ b/src/duckdb/extension/json/include/json_scan.hpp @@ -8,8 +8,8 @@ #pragma once -#include "json_reader.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "buffered_json_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/mutex.hpp" #include "duckdb/common/pair.hpp" #include "duckdb/common/types/type_map.hpp" @@ -17,31 +17,182 @@ #include "duckdb/function/table_function.hpp" #include "json_enums.hpp" #include "json_transform.hpp" -#include "json_reader_options.hpp" namespace duckdb { +struct JSONString { +public: + JSONString() { + } + JSONString(const char *pointer_p, idx_t size_p) : pointer(pointer_p), size(size_p) { + } + + const char *pointer; + idx_t size; + +public: + string ToString() { + return string(pointer, size); + } + + const char &operator[](size_t i) const { + return pointer[i]; + } +}; + +struct DateFormatMap { +public: + DateFormatMap() { + } + + DateFormatMap(DateFormatMap &&other) noexcept { + candidate_formats = other.candidate_formats; + } + + DateFormatMap &operator=(DateFormatMap &&other) noexcept { + candidate_formats = other.candidate_formats; + return *this; + } + +public: + void Initialize(const type_id_map_t> &format_templates) { + for (const auto &entry : format_templates) { + const auto &type = entry.first; + for (const auto &format_string : entry.second) { + AddFormat(type, format_string); + } + } + } + + DateFormatMap Copy() const { + DateFormatMap result; + result.candidate_formats = candidate_formats; + return result; + } + + void AddFormat(LogicalTypeId type, const string &format_string) { + auto &formats = candidate_formats[type]; + formats.emplace_back(); + formats.back().format_specifier = format_string; + StrpTimeFormat::ParseFormatSpecifier(formats.back().format_specifier, formats.back()); + } + + bool HasFormats(LogicalTypeId type) const { + lock_guard guard(lock); + return candidate_formats.find(type) != candidate_formats.end(); + } + + idx_t NumberOfFormats(LogicalTypeId type) { + lock_guard guard(lock); + return candidate_formats[type].size(); + } + + bool GetFormatAtIndex(LogicalTypeId type, idx_t index, StrpTimeFormat &format) { + lock_guard guard(lock); + auto &formats = candidate_formats[type]; + if (index >= formats.size()) { + return false; + } + format = formats[index]; + return true; + } + + void ShrinkFormatsToSize(LogicalTypeId type, idx_t size) { + lock_guard guard(lock); + auto &formats = candidate_formats[type]; + while (formats.size() > size) { + formats.pop_back(); + } + } + + StrpTimeFormat &GetFormat(LogicalTypeId type) { + lock_guard guard(lock); + D_ASSERT(candidate_formats.find(type) != candidate_formats.end()); + return candidate_formats.find(type)->second.back(); + } + + const StrpTimeFormat &GetFormat(LogicalTypeId type) const { + lock_guard guard(lock); + D_ASSERT(candidate_formats.find(type) != candidate_formats.end()); + return candidate_formats.find(type)->second.back(); + } + +private: + mutable mutex lock; + type_id_map_t> candidate_formats; +}; + struct JSONScanData : public TableFunctionData { public: JSONScanData(); + void Bind(ClientContext &context, TableFunctionBindInput &input); + + void InitializeReaders(ClientContext &context); void InitializeFormats(); void InitializeFormats(bool auto_detect); + void SetCompression(const string &compression); -public: - //! JSON reader options - JSONReaderOptions options; + void Serialize(Serializer &serializer) const; + static unique_ptr Deserialize(Deserializer &deserializer); - //! The set of keys to extract (case sensitive) - vector key_names; +public: + //! Scan type + JSONScanType type; - //! The date format map - unique_ptr date_format_map; + //! File-specific options + BufferedJSONReaderOptions options; + + //! Multi-file reader stuff + MultiFileReaderBindData reader_bind; + + //! The files we're reading + vector files; + //! Initial file reader + unique_ptr initial_reader; + //! The readers + vector> union_readers; + + //! Whether or not we should ignore malformed JSON (default to NULL) + bool ignore_errors = false; + //! Maximum JSON object size (defaults to 16MB minimum) + idx_t maximum_object_size = 16777216; + //! Whether we auto-detect a schema + bool auto_detect = false; + //! Sample size for detecting schema + idx_t sample_size = idx_t(STANDARD_VECTOR_SIZE) * 10; + //! Max depth we go to detect nested JSON schema (defaults to unlimited) + idx_t max_depth = NumericLimits::Maximum(); + //! We divide the number of appearances of each JSON field by the auto-detection sample size + //! If the average over the fields of an object is less than this threshold, + //! we default to the MAP type with value type of merged field types + double field_appearance_threshold = 0.1; + //! The maximum number of files we sample to sample sample_size rows + idx_t maximum_sample_files = 32; + //! Whether we auto-detect and convert JSON strings to integers + bool convert_strings_to_integers = false; + //! If a struct contains more fields than this threshold with at least 80% similar types, + //! we infer it as MAP type + idx_t map_inference_threshold = 200; + + //! All column names (in order) + vector names; //! Options when transforming the JSON to columnar data JSONTransformOptions transform_options; + //! Forced date/timestamp formats + string date_format; + string timestamp_format; + //! Candidate date formats + DateFormatMap date_format_map; + + //! The inferred avg tuple size + idx_t avg_tuple_size = 420; + +private: + JSONScanData(ClientContext &context, vector files, string date_format, string timestamp_format); - optional_idx max_threads; - optional_idx estimated_cardinality_per_file; + string GetDateFormat() const; + string GetTimestampFormat() const; }; struct JSONScanInfo : public TableFunctionInfo { @@ -59,12 +210,11 @@ struct JSONScanInfo : public TableFunctionInfo { struct JSONScanGlobalState { public: - JSONScanGlobalState(ClientContext &context, const MultiFileBindData &bind_data); + JSONScanGlobalState(ClientContext &context, const JSONScanData &bind_data); public: //! Bound data - const MultiFileBindData &bind_data; - const JSONScanData &json_data; + const JSONScanData &bind_data; //! Options when transforming the JSON to columnar data JSONTransformOptions transform_options; @@ -78,13 +228,17 @@ struct JSONScanGlobalState { //! The current buffer capacity idx_t buffer_capacity; + mutex lock; + //! One JSON reader per file + vector> json_readers; + //! Current file/batch index + atomic file_index; + atomic batch_index; + //! Current number of threads active idx_t system_threads; //! Whether we enable parallel scans (only if less files than threads) bool enable_parallel_scans; - - bool file_is_assigned = false; - bool initialized = false; }; struct JSONScanLocalState { @@ -92,34 +246,88 @@ struct JSONScanLocalState { JSONScanLocalState(ClientContext &context, JSONScanGlobalState &gstate); public: - idx_t Read(); - void AddTransformError(idx_t object_index, const string &error_message); + idx_t ReadNext(JSONScanGlobalState &gstate); + void ThrowTransformError(idx_t object_index, const string &error_message); - JSONReaderScanState &GetScanState() { - return scan_state; - } + yyjson_alc *GetAllocator(); + const MultiFileReaderData &GetReaderData() const; - const JSONReaderScanState &GetScanState() const { - return scan_state; - } +public: + //! Current scan data + idx_t scan_count; + JSONString units[STANDARD_VECTOR_SIZE]; + yyjson_val *values[STANDARD_VECTOR_SIZE]; - bool TryInitializeScan(JSONScanGlobalState &gstate, JSONReader &reader); + //! Batch index for order-preserving parallelism + idx_t batch_index; -public: //! Options when transforming the JSON to columnar data + DateFormatMap date_format_map; JSONTransformOptions transform_options; + //! For determining average tuple size + idx_t total_read_size; + idx_t total_tuple_count; + private: + bool ReadNextBuffer(JSONScanGlobalState &gstate); + bool ReadNextBufferInternal(JSONScanGlobalState &gstate, AllocatedData &buffer, optional_idx &buffer_index, + bool &file_done); + bool ReadNextBufferSeek(JSONScanGlobalState &gstate, AllocatedData &buffer, optional_idx &buffer_index, + bool &file_done); + bool ReadNextBufferNoSeek(JSONScanGlobalState &gstate, AllocatedData &buffer, optional_idx &buffer_index, + bool &file_done); + AllocatedData AllocateBuffer(JSONScanGlobalState &gstate); + data_ptr_t GetReconstructBuffer(JSONScanGlobalState &gstate); + + void SkipOverArrayStart(); + + void ReadAndAutoDetect(JSONScanGlobalState &gstate, AllocatedData &buffer, optional_idx &buffer_index, + bool &file_done); + bool ReconstructFirstObject(JSONScanGlobalState &gstate); + void ParseNextChunk(JSONScanGlobalState &gstate); + void ParseJSON(char *const json_start, const idx_t json_size, const idx_t remaining); + void ThrowObjectSizeError(const idx_t object_size); + + //! Must hold the lock + void TryIncrementFileIndex(JSONScanGlobalState &gstate) const; + bool IsParallel(JSONScanGlobalState &gstate) const; private: - //! Scan state - JSONReaderScanState scan_state; + //! Bind data + const JSONScanData &bind_data; + //! Thread-local allocator + JSONAllocator allocator; + + //! Current reader and buffer handle + optional_ptr current_reader; + optional_ptr current_buffer_handle; + //! Whether this is the last batch of the file + bool is_last; + + //! The current main filesystem + FileSystem &fs; + + //! For some filesystems (e.g. S3), using a filehandle per thread increases performance + unique_ptr thread_local_filehandle; + + //! Current buffer read info + char *buffer_ptr; + idx_t buffer_size; + idx_t buffer_offset; + idx_t prev_buffer_remainder; + idx_t lines_or_objects_in_buffer; + + //! Buffer to reconstruct split values + AllocatedData reconstruct_buffer; }; struct JSONGlobalTableFunctionState : public GlobalTableFunctionState { public: - JSONGlobalTableFunctionState(ClientContext &context, const MultiFileBindData &bind_data); + JSONGlobalTableFunctionState(ClientContext &context, TableFunctionInitInput &input); + static unique_ptr Init(ClientContext &context, TableFunctionInitInput &input); + idx_t MaxThreads() const override; public: JSONScanGlobalState state; @@ -128,6 +336,9 @@ struct JSONGlobalTableFunctionState : public GlobalTableFunctionState { struct JSONLocalTableFunctionState : public LocalTableFunctionState { public: JSONLocalTableFunctionState(ClientContext &context, JSONScanGlobalState &gstate); + static unique_ptr Init(ExecutionContext &context, TableFunctionInitInput &input, + GlobalTableFunctionState *global_state); + idx_t GetBatchIndex() const; public: JSONScanLocalState state; @@ -135,9 +346,16 @@ struct JSONLocalTableFunctionState : public LocalTableFunctionState { struct JSONScan { public: - static void AutoDetect(ClientContext &context, MultiFileBindData &bind_data, vector &return_types, + static void AutoDetect(ClientContext &context, JSONScanData &bind_data, vector &return_types, vector &names); + static double ScanProgress(ClientContext &context, const FunctionData *bind_data_p, + const GlobalTableFunctionState *global_state); + static OperatorPartitionData GetPartitionData(ClientContext &context, TableFunctionGetPartitionInput &input); + static unique_ptr Cardinality(ClientContext &context, const FunctionData *bind_data); + static void ComplexFilterPushdown(ClientContext &context, LogicalGet &get, FunctionData *bind_data_p, + vector> &filters); + static void Serialize(Serializer &serializer, const optional_ptr bind_data, const TableFunction &function); static unique_ptr Deserialize(Deserializer &deserializer, TableFunction &function); diff --git a/src/duckdb/extension/json/include/json_structure.hpp b/src/duckdb/extension/json/include/json_structure.hpp index 584069981..baf06520d 100644 --- a/src/duckdb/extension/json/include/json_structure.hpp +++ b/src/duckdb/extension/json/include/json_structure.hpp @@ -15,7 +15,6 @@ namespace duckdb { struct JSONStructureDescription; struct DateFormatMap; struct StrpTimeFormat; -class MutableDateFormatMap; struct JSONStructureNode { public: @@ -35,18 +34,18 @@ struct JSONStructureNode { bool ContainsVarchar() const; void InitializeCandidateTypes(idx_t max_depth, bool convert_strings_to_integers, idx_t depth = 0); void RefineCandidateTypes(yyjson_val *vals[], idx_t val_count, Vector &string_vector, ArenaAllocator &allocator, - MutableDateFormatMap &date_format_map); + DateFormatMap &date_format_map); private: void RefineCandidateTypesArray(yyjson_val *vals[], idx_t val_count, Vector &string_vector, - ArenaAllocator &allocator, MutableDateFormatMap &date_format_map); + ArenaAllocator &allocator, DateFormatMap &date_format_map); void RefineCandidateTypesObject(yyjson_val *vals[], idx_t val_count, Vector &string_vector, - ArenaAllocator &allocator, MutableDateFormatMap &date_format_map); + ArenaAllocator &allocator, DateFormatMap &date_format_map); void RefineCandidateTypesString(yyjson_val *vals[], idx_t val_count, Vector &string_vector, - MutableDateFormatMap &date_format_map); - void EliminateCandidateTypes(idx_t vec_count, Vector &string_vector, MutableDateFormatMap &date_format_map); + DateFormatMap &date_format_map); + void EliminateCandidateTypes(idx_t vec_count, Vector &string_vector, DateFormatMap &date_format_map); bool EliminateCandidateFormats(idx_t vec_count, Vector &string_vector, const Vector &result_vector, - MutableDateFormatMap &date_format_map); + DateFormatMap &date_format_map); public: unique_ptr key; diff --git a/src/duckdb/extension/json/include/json_transform.hpp b/src/duckdb/extension/json/include/json_transform.hpp index d3f9f23e6..0ae6b57bf 100644 --- a/src/duckdb/extension/json/include/json_transform.hpp +++ b/src/duckdb/extension/json/include/json_transform.hpp @@ -16,7 +16,7 @@ namespace duckdb { struct DateFormatMap; -class JSONReader; +class BufferedJSONReader; //! Options for error handling while transforming JSON struct JSONTransformOptions { @@ -37,7 +37,7 @@ struct JSONTransformOptions { //! Whether to delay the error when transforming (e.g., when non-strict casting or reading from file) bool delay_error = false; //! Date format used for parsing (can be NULL) - optional_ptr date_format_map = nullptr; + optional_ptr date_format_map = nullptr; //! String to store errors in string error_message; //! Index of the object where the error occurred @@ -52,16 +52,14 @@ struct JSONTransformOptions { struct TryParseDate { template - static inline bool Operation(const StrpTimeFormat &format, const string_t &input, T &result, - string &error_message) { + static inline bool Operation(StrpTimeFormat &format, const string_t &input, T &result, string &error_message) { return format.TryParseDate(input, result, error_message); } }; struct TryParseTimeStamp { template - static inline bool Operation(const StrpTimeFormat &format, const string_t &input, T &result, - string &error_message) { + static inline bool Operation(StrpTimeFormat &format, const string_t &input, T &result, string &error_message) { return format.TryParseTimestamp(input, result, error_message); } }; diff --git a/src/duckdb/extension/json/json_enums.cpp b/src/duckdb/extension/json/json_enums.cpp index 6863f6887..06e03f85e 100644 --- a/src/duckdb/extension/json/json_enums.cpp +++ b/src/duckdb/extension/json/json_enums.cpp @@ -17,6 +17,8 @@ const char* EnumUtil::ToChars(JSONScanType value) { return "READ_JSON"; case JSONScanType::READ_JSON_OBJECTS: return "READ_JSON_OBJECTS"; + case JSONScanType::SAMPLE: + return "SAMPLE"; default: throw NotImplementedException(StringUtil::Format("Enum value of type JSONScanType: '%d' not implemented", value)); } @@ -33,6 +35,9 @@ JSONScanType EnumUtil::FromString(const char *value) { if (StringUtil::Equals(value, "READ_JSON_OBJECTS")) { return JSONScanType::READ_JSON_OBJECTS; } + if (StringUtil::Equals(value, "SAMPLE")) { + return JSONScanType::SAMPLE; + } throw NotImplementedException(StringUtil::Format("Enum value of type JSONScanType: '%s' not implemented", value)); } diff --git a/src/duckdb/extension/json/json_functions/copy_json.cpp b/src/duckdb/extension/json/json_functions/copy_json.cpp index 564e4aeaa..cdd464d0d 100644 --- a/src/duckdb/extension/json/json_functions/copy_json.cpp +++ b/src/duckdb/extension/json/json_functions/copy_json.cpp @@ -9,7 +9,6 @@ #include "json_functions.hpp" #include "json_scan.hpp" #include "json_transform.hpp" -#include "json_multi_file_info.hpp" namespace duckdb { @@ -112,15 +111,82 @@ static BoundStatement CopyToJSONPlan(Binder &binder, CopyStatement &stmt) { return binder.Bind(*stmt_copy); } +static unique_ptr CopyFromJSONBind(ClientContext &context, CopyInfo &info, vector &expected_names, + vector &expected_types) { + auto bind_data = make_uniq(); + bind_data->type = JSONScanType::READ_JSON; + bind_data->options.record_type = JSONRecordType::RECORDS; + bind_data->options.format = JSONFormat::NEWLINE_DELIMITED; + + bind_data->files.emplace_back(info.file_path); + bind_data->names = expected_names; + + bool auto_detect = false; + for (auto &kv : info.options) { + const auto &loption = StringUtil::Lower(kv.first); + if (loption == "dateformat" || loption == "date_format") { + if (kv.second.size() != 1) { + ThrowJSONCopyParameterException(loption); + } + bind_data->date_format = StringValue::Get(kv.second.back()); + } else if (loption == "timestampformat" || loption == "timestamp_format") { + if (kv.second.size() != 1) { + ThrowJSONCopyParameterException(loption); + } + bind_data->timestamp_format = StringValue::Get(kv.second.back()); + } else if (loption == "auto_detect") { + if (kv.second.empty()) { + auto_detect = true; + } else if (kv.second.size() != 1) { + ThrowJSONCopyParameterException(loption); + } else { + auto_detect = BooleanValue::Get(kv.second.back().DefaultCastAs(LogicalTypeId::BOOLEAN)); + } + } else if (loption == "compression") { + if (kv.second.size() != 1) { + ThrowJSONCopyParameterException(loption); + } + bind_data->SetCompression(StringValue::Get(kv.second.back())); + } else if (loption == "array") { + if (kv.second.empty()) { + bind_data->options.format = JSONFormat::ARRAY; + } else if (kv.second.size() != 1) { + ThrowJSONCopyParameterException(loption); + } else if (BooleanValue::Get(kv.second.back().DefaultCastAs(LogicalTypeId::BOOLEAN))) { + bind_data->options.format = JSONFormat::ARRAY; + } + } else { + throw BinderException("Unknown option for COPY ... FROM ... (FORMAT JSON): \"%s\".", loption); + } + } + bind_data->InitializeFormats(auto_detect); + if (auto_detect && bind_data->options.format != JSONFormat::ARRAY) { + bind_data->options.format = JSONFormat::AUTO_DETECT; + } + + bind_data->transform_options = JSONTransformOptions(true, true, true, true); + bind_data->transform_options.delay_error = true; + + bind_data->InitializeReaders(context); + if (auto_detect) { + JSONScan::AutoDetect(context, *bind_data, expected_types, expected_names); + bind_data->auto_detect = true; + } + + bind_data->transform_options.date_format_map = &bind_data->date_format_map; + + return std::move(bind_data); +} + CopyFunction JSONFunctions::GetJSONCopyFunction() { CopyFunction function("json"); function.extension = "json"; function.plan = CopyToJSONPlan; - function.copy_from_bind = MultiFileFunction::MultiFileBindCopy; + function.copy_from_bind = CopyFromJSONBind; function.copy_from_function = JSONFunctions::GetReadJSONTableFunction(make_shared_ptr( - JSONScanType::READ_JSON, JSONFormat::AUTO_DETECT, JSONRecordType::RECORDS, false)); + JSONScanType::READ_JSON, JSONFormat::NEWLINE_DELIMITED, JSONRecordType::RECORDS, false)); return function; } diff --git a/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp b/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp index c24c53fcd..11a1b999f 100644 --- a/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +++ b/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp @@ -161,10 +161,6 @@ ScalarFunctionSet JSONFunctions::GetSerializeSqlFunction() { {LogicalType::VARCHAR, LogicalType::BOOLEAN, LogicalType::BOOLEAN, LogicalType::BOOLEAN}, LogicalType::JSON(), JsonSerializeFunction, JsonSerializeBind, nullptr, nullptr, JSONFunctionLocalState::Init)); - set.AddFunction(ScalarFunction( - {LogicalType::VARCHAR, LogicalType::BOOLEAN, LogicalType::BOOLEAN, LogicalType::BOOLEAN, LogicalType::BOOLEAN}, - LogicalType::JSON(), JsonSerializeFunction, JsonSerializeBind, nullptr, nullptr, JSONFunctionLocalState::Init)); - return set; } diff --git a/src/duckdb/extension/json/json_functions/json_structure.cpp b/src/duckdb/extension/json/json_functions/json_structure.cpp index 7dc46de55..260f7984a 100644 --- a/src/duckdb/extension/json/json_functions/json_structure.cpp +++ b/src/duckdb/extension/json/json_functions/json_structure.cpp @@ -129,7 +129,7 @@ void JSONStructureNode::InitializeCandidateTypes(const idx_t max_depth, const bo } void JSONStructureNode::RefineCandidateTypes(yyjson_val *vals[], const idx_t val_count, Vector &string_vector, - ArenaAllocator &allocator, MutableDateFormatMap &date_format_map) { + ArenaAllocator &allocator, DateFormatMap &date_format_map) { if (descriptions.size() != 1) { // We can't refine types if we have more than 1 description (yet), defaults to JSON type for now return; @@ -151,7 +151,7 @@ void JSONStructureNode::RefineCandidateTypes(yyjson_val *vals[], const idx_t val } void JSONStructureNode::RefineCandidateTypesArray(yyjson_val *vals[], const idx_t val_count, Vector &string_vector, - ArenaAllocator &allocator, MutableDateFormatMap &date_format_map) { + ArenaAllocator &allocator, DateFormatMap &date_format_map) { D_ASSERT(descriptions.size() == 1 && descriptions[0].type == LogicalTypeId::LIST); auto &desc = descriptions[0]; D_ASSERT(desc.children.size() == 1); @@ -182,7 +182,7 @@ void JSONStructureNode::RefineCandidateTypesArray(yyjson_val *vals[], const idx_ } void JSONStructureNode::RefineCandidateTypesObject(yyjson_val *vals[], const idx_t val_count, Vector &string_vector, - ArenaAllocator &allocator, MutableDateFormatMap &date_format_map) { + ArenaAllocator &allocator, DateFormatMap &date_format_map) { D_ASSERT(descriptions.size() == 1 && descriptions[0].type == LogicalTypeId::STRUCT); auto &desc = descriptions[0]; @@ -239,7 +239,7 @@ void JSONStructureNode::RefineCandidateTypesObject(yyjson_val *vals[], const idx } void JSONStructureNode::RefineCandidateTypesString(yyjson_val *vals[], const idx_t val_count, Vector &string_vector, - MutableDateFormatMap &date_format_map) { + DateFormatMap &date_format_map) { D_ASSERT(descriptions.size() == 1 && descriptions[0].type == LogicalTypeId::VARCHAR); if (descriptions[0].candidate_types.empty()) { return; @@ -250,7 +250,7 @@ void JSONStructureNode::RefineCandidateTypesString(yyjson_val *vals[], const idx } void JSONStructureNode::EliminateCandidateTypes(const idx_t vec_count, Vector &string_vector, - MutableDateFormatMap &date_format_map) { + DateFormatMap &date_format_map) { D_ASSERT(descriptions.size() == 1 && descriptions[0].type == LogicalTypeId::VARCHAR); auto &description = descriptions[0]; auto &candidate_types = description.candidate_types; @@ -303,7 +303,7 @@ bool TryParse(Vector &string_vector, StrpTimeFormat &format, const idx_t count) } bool JSONStructureNode::EliminateCandidateFormats(const idx_t vec_count, Vector &string_vector, - const Vector &result_vector, MutableDateFormatMap &date_format_map) { + const Vector &result_vector, DateFormatMap &date_format_map) { D_ASSERT(descriptions.size() == 1 && descriptions[0].type == LogicalTypeId::VARCHAR); const auto type = result_vector.GetType().id(); diff --git a/src/duckdb/extension/json/json_functions/json_transform.cpp b/src/duckdb/extension/json/json_functions/json_transform.cpp index 6aec44d03..5b4b64e06 100644 --- a/src/duckdb/extension/json/json_functions/json_transform.cpp +++ b/src/duckdb/extension/json/json_functions/json_transform.cpp @@ -294,8 +294,8 @@ static bool TransformFromString(yyjson_val *vals[], Vector &result, const idx_t } template -static bool TransformStringWithFormat(Vector &string_vector, const StrpTimeFormat &format, const idx_t count, - Vector &result, JSONTransformOptions &options) { +static bool TransformStringWithFormat(Vector &string_vector, StrpTimeFormat &format, const idx_t count, Vector &result, + JSONTransformOptions &options) { const auto source_strings = FlatVector::GetData(string_vector); const auto &source_validity = FlatVector::Validity(string_vector); diff --git a/src/duckdb/extension/json/json_functions/read_json.cpp b/src/duckdb/extension/json/json_functions/read_json.cpp index fa7016047..6ee8fa237 100644 --- a/src/duckdb/extension/json/json_functions/read_json.cpp +++ b/src/duckdb/extension/json/json_functions/read_json.cpp @@ -1,10 +1,9 @@ #include "duckdb/common/helper.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "json_functions.hpp" #include "json_scan.hpp" #include "json_structure.hpp" #include "json_transform.hpp" -#include "json_multi_file_info.hpp" #include "duckdb/parallel/task_executor.hpp" namespace duckdb { @@ -38,72 +37,37 @@ static inline LogicalType RemoveDuplicateStructKeys(const LogicalType &type, con } } -struct AutoDetectState { - AutoDetectState(ClientContext &context_p, MultiFileBindData &bind_data_p, const vector &files, - MutableDateFormatMap &date_format_map) - : context(context_p), bind_data(bind_data_p), files(files), date_format_map(date_format_map), files_scanned(0), - tuples_scanned(0), bytes_scanned(0), total_file_size(0) { - } - - ClientContext &context; - MultiFileBindData &bind_data; - const vector &files; - MutableDateFormatMap &date_format_map; - atomic files_scanned; - atomic tuples_scanned; - atomic bytes_scanned; - atomic total_file_size; -}; - class JSONSchemaTask : public BaseExecutorTask { public: - JSONSchemaTask(TaskExecutor &executor, AutoDetectState &auto_detect_state, JSONStructureNode &node_p, - const idx_t file_idx_start_p, const idx_t file_idx_end_p) - : BaseExecutorTask(executor), auto_detect_state(auto_detect_state), node(node_p), - file_idx_start(file_idx_start_p), file_idx_end(file_idx_end_p), - allocator(BufferAllocator::Get(auto_detect_state.context)), string_vector(LogicalType::VARCHAR) { + JSONSchemaTask(TaskExecutor &executor, ClientContext &context_p, JSONScanData &bind_data_p, + JSONStructureNode &node_p, const idx_t file_idx_start_p, const idx_t file_idx_end_p) + : BaseExecutorTask(executor), context(context_p), bind_data(bind_data_p), node(node_p), + file_idx_start(file_idx_start_p), file_idx_end(file_idx_end_p), allocator(BufferAllocator::Get(context)), + string_vector(LogicalType::VARCHAR) { } - static idx_t ExecuteInternal(AutoDetectState &auto_detect_state, JSONStructureNode &node, const idx_t file_idx, - ArenaAllocator &allocator, Vector &string_vector, idx_t remaining) { - auto &context = auto_detect_state.context; - auto &bind_data = auto_detect_state.bind_data; - auto &files = auto_detect_state.files; - auto &json_data = bind_data.bind_data->Cast(); - auto json_reader = make_shared_ptr(context, json_data.options, files[file_idx]); - if (bind_data.union_readers[file_idx]) { - throw InternalException("Union data already set"); + static idx_t ExecuteInternal(ClientContext &context, JSONScanData &bind_data, JSONStructureNode &node, + const idx_t file_idx, ArenaAllocator &allocator, Vector &string_vector, + idx_t remaining) { + JSONScanGlobalState gstate(context, bind_data); + JSONScanLocalState lstate(context, gstate); + if (file_idx == 0) { + gstate.json_readers.emplace_back(bind_data.initial_reader.get()); + } else { + gstate.json_readers.emplace_back(bind_data.union_readers[file_idx - 1].get()); } - auto &reader = *json_reader; - auto union_data = make_uniq(files[file_idx]); - union_data->reader = std::move(json_reader); - bind_data.union_readers[file_idx] = std::move(union_data); - - auto &global_allocator = Allocator::Get(context); - idx_t buffer_capacity = json_data.options.maximum_object_size * 2; - JSONReaderScanState scan_state(context, global_allocator, buffer_capacity); - auto &options = json_data.options; - // Read and detect schema - idx_t total_tuple_count = 0; - idx_t total_read_size = 0; - - reader.Initialize(global_allocator, buffer_capacity); - reader.InitializeScan(scan_state, JSONFileReadType::SCAN_ENTIRE_FILE); - auto file_size = reader.GetFileHandle().GetHandle().GetFileSize(); + // Read and detect schema while (remaining != 0) { allocator.Reset(); - auto buffer_offset_before = scan_state.buffer_offset; - auto read_count = reader.Scan(scan_state); + const auto read_count = lstate.ReadNext(gstate); if (read_count == 0) { break; } - total_read_size += scan_state.buffer_offset - buffer_offset_before; - total_tuple_count += read_count; const auto next = MinValue(read_count, remaining); for (idx_t i = 0; i < next; i++) { - const auto &val = scan_state.values[i]; + const auto &val = lstate.values[i]; if (val) { JSONStructure::ExtractStructure(val, node, true); } @@ -111,29 +75,27 @@ class JSONSchemaTask : public BaseExecutorTask { if (!node.ContainsVarchar()) { // Can't refine non-VARCHAR types continue; } - node.InitializeCandidateTypes(options.max_depth, options.convert_strings_to_integers); - node.RefineCandidateTypes(scan_state.values, next, string_vector, allocator, - auto_detect_state.date_format_map); + node.InitializeCandidateTypes(bind_data.max_depth, bind_data.convert_strings_to_integers); + node.RefineCandidateTypes(lstate.values, next, string_vector, allocator, bind_data.date_format_map); remaining -= next; } - auto_detect_state.total_file_size += file_size; - auto_detect_state.bytes_scanned += total_read_size; - auto_detect_state.tuples_scanned += total_tuple_count; - ++auto_detect_state.files_scanned; + + if (file_idx == 0 && lstate.total_tuple_count != 0) { + bind_data.avg_tuple_size = lstate.total_read_size / lstate.total_tuple_count; + } return remaining; } void ExecuteTask() override { - auto &json_data = auto_detect_state.bind_data.bind_data->Cast(); - auto &options = json_data.options; for (idx_t file_idx = file_idx_start; file_idx < file_idx_end; file_idx++) { - ExecuteInternal(auto_detect_state, node, file_idx, allocator, string_vector, options.sample_size); + ExecuteInternal(context, bind_data, node, file_idx, allocator, string_vector, bind_data.sample_size); } } private: - AutoDetectState &auto_detect_state; + ClientContext &context; + JSONScanData &bind_data; JSONStructureNode &node; const idx_t file_idx_start; const idx_t file_idx_end; @@ -142,29 +104,23 @@ class JSONSchemaTask : public BaseExecutorTask { Vector string_vector; }; -void JSONScan::AutoDetect(ClientContext &context, MultiFileBindData &bind_data, vector &return_types, +void JSONScan::AutoDetect(ClientContext &context, JSONScanData &bind_data, vector &return_types, vector &names) { - auto &json_data = bind_data.bind_data->Cast(); + // Change scan type during detection + bind_data.type = JSONScanType::SAMPLE; - MutableDateFormatMap date_format_map(*json_data.date_format_map); JSONStructureNode node; - auto &options = json_data.options; - auto files = bind_data.file_list->GetAllFiles(); - auto file_count = files.size(); - bind_data.union_readers.resize(files.empty() ? 0 : files.size()); - - AutoDetectState auto_detect_state(context, bind_data, files, date_format_map); - if (bind_data.file_options.union_by_name) { + if (bind_data.options.file_options.union_by_name) { const auto num_threads = NumericCast(TaskScheduler::GetScheduler(context).NumberOfThreads()); - const auto files_per_task = (file_count + num_threads - 1) / num_threads; - const auto num_tasks = file_count / files_per_task; + const auto files_per_task = (bind_data.files.size() + num_threads - 1) / num_threads; + const auto num_tasks = bind_data.files.size() / files_per_task; vector task_nodes(num_tasks); // Same idea as in union_by_name.hpp TaskExecutor executor(context); for (idx_t task_idx = 0; task_idx < num_tasks; task_idx++) { const auto file_idx_start = task_idx * files_per_task; - auto task = make_uniq(executor, auto_detect_state, task_nodes[task_idx], file_idx_start, + auto task = make_uniq(executor, context, bind_data, task_nodes[task_idx], file_idx_start, file_idx_start + files_per_task); executor.ScheduleTask(std::move(task)); } @@ -177,51 +133,46 @@ void JSONScan::AutoDetect(ClientContext &context, MultiFileBindData &bind_data, } else { ArenaAllocator allocator(BufferAllocator::Get(context)); Vector string_vector(LogicalType::VARCHAR); - idx_t remaining = options.sample_size; - for (idx_t file_idx = 0; file_idx < file_count; file_idx++) { - remaining = - JSONSchemaTask::ExecuteInternal(auto_detect_state, node, file_idx, allocator, string_vector, remaining); - if (remaining == 0 || file_idx == options.maximum_sample_files - 1) { + idx_t remaining = bind_data.sample_size; + for (idx_t file_idx = 0; file_idx < bind_data.files.size(); file_idx++) { + remaining = JSONSchemaTask::ExecuteInternal(context, bind_data, node, file_idx, allocator, string_vector, + remaining); + if (remaining == 0 || file_idx == bind_data.maximum_sample_files - 1) { break; // We sample sample_size in total (across the first maximum_sample_files files) } } } - // set the max threads/estimated per-file cardinality - if (auto_detect_state.files_scanned > 0 && auto_detect_state.tuples_scanned > 0) { - auto average_tuple_size = auto_detect_state.bytes_scanned / auto_detect_state.tuples_scanned; - json_data.estimated_cardinality_per_file = auto_detect_state.total_file_size / average_tuple_size; - if (auto_detect_state.files_scanned == 1) { - json_data.max_threads = - MaxValue(auto_detect_state.total_file_size / json_data.options.maximum_object_size, 1); - } - } + + // Restore the scan type + bind_data.type = JSONScanType::READ_JSON; // Convert structure to logical type - auto type = JSONStructure::StructureToType(context, node, options.max_depth, options.field_appearance_threshold, - options.map_inference_threshold); + auto type = JSONStructure::StructureToType(context, node, bind_data.max_depth, bind_data.field_appearance_threshold, + bind_data.map_inference_threshold); // Auto-detect record type - if (json_data.options.record_type == JSONRecordType::AUTO_DETECT) { + if (bind_data.options.record_type == JSONRecordType::AUTO_DETECT) { if (type.id() == LogicalTypeId::STRUCT) { - json_data.options.record_type = JSONRecordType::RECORDS; + bind_data.options.record_type = JSONRecordType::RECORDS; } else { - json_data.options.record_type = JSONRecordType::VALUES; + bind_data.options.record_type = JSONRecordType::VALUES; } } - if (!names.empty()) { - // COPY - we already have names/types + if (!bind_data.auto_detect) { return; } + bind_data.transform_options.date_format_map = &bind_data.date_format_map; + // Auto-detect columns - if (json_data.options.record_type == JSONRecordType::RECORDS) { + if (bind_data.options.record_type == JSONRecordType::RECORDS) { if (type.id() == LogicalTypeId::STRUCT) { const auto &child_types = StructType::GetChildTypes(type); return_types.reserve(child_types.size()); names.reserve(child_types.size()); for (auto &child_type : child_types) { - return_types.emplace_back(RemoveDuplicateStructKeys(child_type.second, options.ignore_errors)); + return_types.emplace_back(RemoveDuplicateStructKeys(child_type.second, bind_data.ignore_errors)); names.emplace_back(child_type.first); } } else { @@ -229,14 +180,243 @@ void JSONScan::AutoDetect(ClientContext &context, MultiFileBindData &bind_data, "\n Try setting records='auto' or records='false'."); } } else { - D_ASSERT(json_data.options.record_type == JSONRecordType::VALUES); - return_types.emplace_back(RemoveDuplicateStructKeys(type, options.ignore_errors)); + D_ASSERT(bind_data.options.record_type == JSONRecordType::VALUES); + return_types.emplace_back(RemoveDuplicateStructKeys(type, bind_data.ignore_errors)); names.emplace_back("json"); } } +unique_ptr ReadJSONBind(ClientContext &context, TableFunctionBindInput &input, + vector &return_types, vector &names) { + // First bind default params + auto bind_data = make_uniq(); + bind_data->Bind(context, input); + + for (auto &kv : input.named_parameters) { + if (kv.second.IsNull()) { + throw BinderException("Cannot use NULL as function argument"); + } + auto loption = StringUtil::Lower(kv.first); + if (kv.second.IsNull()) { + throw BinderException("read_json parameter \"%s\" cannot be NULL.", loption); + } + if (loption == "columns") { + auto &child_type = kv.second.type(); + if (child_type.id() != LogicalTypeId::STRUCT) { + throw BinderException("read_json \"columns\" parameter requires a struct as input."); + } + auto &struct_children = StructValue::GetChildren(kv.second); + D_ASSERT(StructType::GetChildCount(child_type) == struct_children.size()); + for (idx_t i = 0; i < struct_children.size(); i++) { + auto &name = StructType::GetChildName(child_type, i); + auto &val = struct_children[i]; + names.push_back(name); + if (val.type().id() != LogicalTypeId::VARCHAR) { + throw BinderException("read_json \"columns\" parameter type specification must be VARCHAR."); + } + return_types.emplace_back(TransformStringToLogicalType(StringValue::Get(val), context)); + } + D_ASSERT(names.size() == return_types.size()); + if (names.empty()) { + throw BinderException("read_json \"columns\" parameter needs at least one column."); + } + bind_data->names = names; + } else if (loption == "auto_detect") { + bind_data->auto_detect = BooleanValue::Get(kv.second); + } else if (loption == "sample_size") { + auto arg = BigIntValue::Get(kv.second); + if (arg == -1) { + bind_data->sample_size = NumericLimits::Maximum(); + } else if (arg > 0) { + bind_data->sample_size = arg; + } else { + throw BinderException("read_json \"sample_size\" parameter must be positive, or -1 to sample all input " + "files entirely, up to \"maximum_sample_files\" files."); + } + } else if (loption == "maximum_depth") { + auto arg = BigIntValue::Get(kv.second); + if (arg == -1) { + bind_data->max_depth = NumericLimits::Maximum(); + } else { + bind_data->max_depth = arg; + } + } else if (loption == "field_appearance_threshold") { + auto arg = DoubleValue::Get(kv.second); + if (arg < 0 || arg > 1) { + throw BinderException( + "read_json_auto \"field_appearance_threshold\" parameter must be between 0 and 1"); + } + bind_data->field_appearance_threshold = arg; + } else if (loption == "map_inference_threshold") { + auto arg = BigIntValue::Get(kv.second); + if (arg == -1) { + bind_data->map_inference_threshold = NumericLimits::Maximum(); + } else if (arg >= 0) { + bind_data->map_inference_threshold = arg; + } else { + throw BinderException("read_json_auto \"map_inference_threshold\" parameter must be 0 or positive, " + "or -1 to disable map inference for consistent objects."); + } + } else if (loption == "dateformat" || loption == "date_format") { + auto format_string = StringValue::Get(kv.second); + if (StringUtil::Lower(format_string) == "iso") { + format_string = "%Y-%m-%d"; + } + bind_data->date_format = format_string; + + StrpTimeFormat format; + auto error = StrTimeFormat::ParseFormatSpecifier(format_string, format); + if (!error.empty()) { + throw BinderException("read_json could not parse \"dateformat\": '%s'.", error.c_str()); + } + } else if (loption == "timestampformat" || loption == "timestamp_format") { + auto format_string = StringValue::Get(kv.second); + if (StringUtil::Lower(format_string) == "iso") { + format_string = "%Y-%m-%dT%H:%M:%S.%fZ"; + } + bind_data->timestamp_format = format_string; + + StrpTimeFormat format; + auto error = StrTimeFormat::ParseFormatSpecifier(format_string, format); + if (!error.empty()) { + throw BinderException("read_json could not parse \"timestampformat\": '%s'.", error.c_str()); + } + } else if (loption == "records") { + auto arg = StringValue::Get(kv.second); + if (arg == "auto") { + bind_data->options.record_type = JSONRecordType::AUTO_DETECT; + } else if (arg == "true") { + bind_data->options.record_type = JSONRecordType::RECORDS; + } else if (arg == "false") { + bind_data->options.record_type = JSONRecordType::VALUES; + } else { + throw BinderException("read_json requires \"records\" to be one of ['auto', 'true', 'false']."); + } + } else if (loption == "maximum_sample_files") { + auto arg = BigIntValue::Get(kv.second); + if (arg == -1) { + bind_data->maximum_sample_files = NumericLimits::Maximum(); + } else if (arg > 0) { + bind_data->maximum_sample_files = arg; + } else { + throw BinderException("read_json \"maximum_sample_files\" parameter must be positive, or -1 to remove " + "the limit on the number of files used to sample \"sample_size\" rows."); + } + } else if (loption == "convert_strings_to_integers") { + bind_data->convert_strings_to_integers = BooleanValue::Get(kv.second); + } + } + + if (bind_data->options.record_type == JSONRecordType::AUTO_DETECT && return_types.size() > 1) { + // More than one specified column implies records + bind_data->options.record_type = JSONRecordType::RECORDS; + } + + // Specifying column names overrides auto-detect + if (!return_types.empty()) { + bind_data->auto_detect = false; + } + + if (!bind_data->auto_detect) { + // Need to specify columns if RECORDS and not auto-detecting + if (return_types.empty()) { + throw BinderException("When auto_detect=false, read_json requires columns to be specified through the " + "\"columns\" parameter."); + } + // If we are reading VALUES, we can only have one column + if (bind_data->options.record_type == JSONRecordType::VALUES && return_types.size() != 1) { + throw BinderException("read_json requires a single column to be specified through the \"columns\" " + "parameter when \"records\" is set to 'false'."); + } + } + + bind_data->InitializeFormats(); + + if (bind_data->auto_detect || bind_data->options.record_type == JSONRecordType::AUTO_DETECT) { + JSONScan::AutoDetect(context, *bind_data, return_types, names); + bind_data->names = names; + D_ASSERT(return_types.size() == names.size()); + } + + SimpleMultiFileList file_list(std::move(bind_data->files)); + MultiFileReader().BindOptions(bind_data->options.file_options, file_list, return_types, names, + bind_data->reader_bind); + bind_data->files = file_list.GetAllFiles(); + + auto &transform_options = bind_data->transform_options; + transform_options.strict_cast = !bind_data->ignore_errors; + transform_options.error_duplicate_key = !bind_data->ignore_errors; + transform_options.error_missing_key = false; + transform_options.error_unknown_key = bind_data->auto_detect && !bind_data->ignore_errors; + transform_options.delay_error = true; + + if (bind_data->auto_detect) { + // JSON may contain columns such as "id" and "Id", which are duplicates for us due to case-insensitivity + // We rename them so we can parse the file anyway. Note that we can't change bind_data->names, + // because the JSON reader gets columns by exact name, not position + case_insensitive_map_t name_collision_count; + for (auto &col_name : names) { + // Taken from CSV header_detection.cpp + while (name_collision_count.find(col_name) != name_collision_count.end()) { + name_collision_count[col_name] += 1; + col_name = col_name + "_" + to_string(name_collision_count[col_name]); + } + name_collision_count[col_name] = 0; + } + } + + return std::move(bind_data); +} + +static void ReadJSONFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { + auto &gstate = data_p.global_state->Cast().state; + auto &lstate = data_p.local_state->Cast().state; + + const auto count = lstate.ReadNext(gstate); + yyjson_val **values = lstate.values; + output.SetCardinality(count); + + if (!gstate.names.empty()) { + vector result_vectors; + result_vectors.reserve(gstate.column_ids.size()); + for (const auto &col_idx : gstate.column_ids) { + result_vectors.emplace_back(&output.data[col_idx]); + } + + D_ASSERT(gstate.bind_data.options.record_type != JSONRecordType::AUTO_DETECT); + bool success; + if (gstate.bind_data.options.record_type == JSONRecordType::RECORDS) { + success = JSONTransform::TransformObject(values, lstate.GetAllocator(), count, gstate.names, result_vectors, + lstate.transform_options, gstate.column_indices, + lstate.transform_options.error_unknown_key); + } else { + D_ASSERT(gstate.bind_data.options.record_type == JSONRecordType::VALUES); + success = JSONTransform::Transform(values, lstate.GetAllocator(), *result_vectors[0], count, + lstate.transform_options, gstate.column_indices[0]); + } + + if (!success) { + string hint = + gstate.bind_data.auto_detect + ? "\nTry increasing 'sample_size', reducing 'maximum_depth', specifying 'columns', 'format' or " + "'records' manually, setting 'ignore_errors' to true, or setting 'union_by_name' to true when " + "reading multiple files with a different structure." + : "\nTry setting 'auto_detect' to true, specifying 'format' or 'records' manually, or setting " + "'ignore_errors' to true."; + lstate.ThrowTransformError(lstate.transform_options.object_index, + lstate.transform_options.error_message + hint); + } + } + + if (output.size() != 0) { + MultiFileReader().FinalizeChunk(context, gstate.bind_data.reader_bind, lstate.GetReaderData(), output, nullptr); + } +} + TableFunction JSONFunctions::GetReadJSONTableFunction(shared_ptr function_info) { - MultiFileFunction table_function("read_json"); + TableFunction table_function({LogicalType::VARCHAR}, ReadJSONFunction, ReadJSONBind, + JSONGlobalTableFunctionState::Init, JSONLocalTableFunctionState::Init); + table_function.name = "read_json"; JSONScan::TableFunctionDefaults(table_function); table_function.named_parameters["columns"] = LogicalType::ANY; @@ -250,9 +430,10 @@ TableFunction JSONFunctions::GetReadJSONTableFunction(shared_ptr f table_function.named_parameters["maximum_sample_files"] = LogicalType::BIGINT; // TODO: might be able to do filter pushdown/prune ? + table_function.function_info = std::move(function_info); - return static_cast(table_function); + return table_function; } TableFunctionSet CreateJSONFunctionInfo(string name, shared_ptr info) { diff --git a/src/duckdb/extension/json/json_functions/read_json_objects.cpp b/src/duckdb/extension/json/json_functions/read_json_objects.cpp index fd2818ffd..c58b85fd7 100644 --- a/src/duckdb/extension/json/json_functions/read_json_objects.cpp +++ b/src/duckdb/extension/json/json_functions/read_json_objects.cpp @@ -2,36 +2,91 @@ #include "json_functions.hpp" #include "json_scan.hpp" #include "duckdb/common/helper.hpp" -#include "json_multi_file_info.hpp" namespace duckdb { -TableFunction GetReadJSONObjectsTableFunction(string name, shared_ptr function_info) { - MultiFileFunction table_function(std::move(name)); +unique_ptr ReadJSONObjectsBind(ClientContext &context, TableFunctionBindInput &input, + vector &return_types, vector &names) { + auto bind_data = make_uniq(); + bind_data->Bind(context, input); + + bind_data->names.emplace_back("json"); + return_types.push_back(LogicalType::JSON()); + names.emplace_back("json"); + + SimpleMultiFileList file_list(std::move(bind_data->files)); + MultiFileReader().BindOptions(bind_data->options.file_options, file_list, return_types, names, + bind_data->reader_bind); + bind_data->files = file_list.GetAllFiles(); + + return std::move(bind_data); +} + +static void ReadJSONObjectsFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { + auto &gstate = data_p.global_state->Cast().state; + auto &lstate = data_p.local_state->Cast().state; + + // Fetch next lines + const auto count = lstate.ReadNext(gstate); + const auto units = lstate.units; + const auto objects = lstate.values; + + if (!gstate.names.empty()) { + // Create the strings without copying them + const auto col_idx = gstate.column_ids[0]; + auto strings = FlatVector::GetData(output.data[col_idx]); + auto &validity = FlatVector::Validity(output.data[col_idx]); + for (idx_t i = 0; i < count; i++) { + if (objects[i]) { + strings[i] = string_t(units[i].pointer, units[i].size); + } else { + validity.SetInvalid(i); + } + } + } + + output.SetCardinality(count); + + if (output.size() != 0) { + MultiFileReader().FinalizeChunk(context, gstate.bind_data.reader_bind, lstate.GetReaderData(), output, nullptr); + } +} + +TableFunction GetReadJSONObjectsTableFunction(bool list_parameter, shared_ptr function_info) { + auto parameter = list_parameter ? LogicalType::LIST(LogicalType::VARCHAR) : LogicalType::VARCHAR; + TableFunction table_function({parameter}, ReadJSONObjectsFunction, ReadJSONObjectsBind, + JSONGlobalTableFunctionState::Init, JSONLocalTableFunctionState::Init); JSONScan::TableFunctionDefaults(table_function); table_function.function_info = std::move(function_info); - return static_cast(table_function); + + return table_function; } TableFunctionSet JSONFunctions::GetReadJSONObjectsFunction() { + TableFunctionSet function_set("read_json_objects"); auto function_info = make_shared_ptr(JSONScanType::READ_JSON_OBJECTS, JSONFormat::AUTO_DETECT, JSONRecordType::RECORDS); - auto table_function = GetReadJSONObjectsTableFunction("read_json_objects", std::move(function_info)); - return MultiFileReader::CreateFunctionSet(std::move(table_function)); + function_set.AddFunction(GetReadJSONObjectsTableFunction(false, function_info)); + function_set.AddFunction(GetReadJSONObjectsTableFunction(true, function_info)); + return function_set; } TableFunctionSet JSONFunctions::GetReadNDJSONObjectsFunction() { + TableFunctionSet function_set("read_ndjson_objects"); auto function_info = make_shared_ptr(JSONScanType::READ_JSON_OBJECTS, JSONFormat::NEWLINE_DELIMITED, JSONRecordType::RECORDS); - auto table_function = GetReadJSONObjectsTableFunction("read_ndjson_objects", std::move(function_info)); - return MultiFileReader::CreateFunctionSet(std::move(table_function)); + function_set.AddFunction(GetReadJSONObjectsTableFunction(false, function_info)); + function_set.AddFunction(GetReadJSONObjectsTableFunction(true, function_info)); + return function_set; } TableFunctionSet JSONFunctions::GetReadJSONObjectsAutoFunction() { + TableFunctionSet function_set("read_json_objects_auto"); auto function_info = make_shared_ptr(JSONScanType::READ_JSON_OBJECTS, JSONFormat::AUTO_DETECT, JSONRecordType::RECORDS); - auto table_function = GetReadJSONObjectsTableFunction("read_json_objects_auto", std::move(function_info)); - return MultiFileReader::CreateFunctionSet(std::move(table_function)); + function_set.AddFunction(GetReadJSONObjectsTableFunction(false, function_info)); + function_set.AddFunction(GetReadJSONObjectsTableFunction(true, function_info)); + return function_set; } } // namespace duckdb diff --git a/src/duckdb/extension/json/json_scan.cpp b/src/duckdb/extension/json/json_scan.cpp index 966d8e595..6fd732a0b 100644 --- a/src/duckdb/extension/json/json_scan.cpp +++ b/src/duckdb/extension/json/json_scan.cpp @@ -1,31 +1,100 @@ #include "json_scan.hpp" #include "duckdb/common/enum_util.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/serializer/deserializer.hpp" #include "duckdb/common/serializer/serializer.hpp" #include "duckdb/main/extension_helper.hpp" #include "duckdb/parallel/task_scheduler.hpp" #include "duckdb/storage/buffer_manager.hpp" -#include "json_multi_file_info.hpp" namespace duckdb { JSONScanData::JSONScanData() { } +JSONScanData::JSONScanData(ClientContext &context, vector files_p, string date_format_p, + string timestamp_format_p) + : files(std::move(files_p)), date_format(std::move(date_format_p)), + timestamp_format(std::move(timestamp_format_p)) { + InitializeReaders(context); + InitializeFormats(); +} + +void JSONScanData::Bind(ClientContext &context, TableFunctionBindInput &input) { + auto &info = input.info->Cast(); + type = info.type; + options.format = info.format; + options.record_type = info.record_type; + auto_detect = info.auto_detect; + + for (auto &kv : input.named_parameters) { + if (kv.second.IsNull()) { + throw BinderException("Cannot use NULL as function argument"); + } + if (MultiFileReader().ParseOption(kv.first, kv.second, options.file_options, context)) { + continue; + } + auto loption = StringUtil::Lower(kv.first); + if (loption == "ignore_errors") { + ignore_errors = BooleanValue::Get(kv.second); + } else if (loption == "maximum_object_size") { + maximum_object_size = MaxValue(UIntegerValue::Get(kv.second), maximum_object_size); + } else if (loption == "format") { + auto arg = StringUtil::Lower(StringValue::Get(kv.second)); + static const auto FORMAT_OPTIONS = + case_insensitive_map_t {{"auto", JSONFormat::AUTO_DETECT}, + {"unstructured", JSONFormat::UNSTRUCTURED}, + {"newline_delimited", JSONFormat::NEWLINE_DELIMITED}, + {"nd", JSONFormat::NEWLINE_DELIMITED}, + {"array", JSONFormat::ARRAY}}; + auto lookup = FORMAT_OPTIONS.find(arg); + if (lookup == FORMAT_OPTIONS.end()) { + vector valid_options; + for (auto &pair : FORMAT_OPTIONS) { + valid_options.push_back(StringUtil::Format("'%s'", pair.first)); + } + throw BinderException("format must be one of [%s], not '%s'", StringUtil::Join(valid_options, ", "), + arg); + } + options.format = lookup->second; + } else if (loption == "compression") { + SetCompression(StringUtil::Lower(StringValue::Get(kv.second))); + } + } + + auto multi_file_reader = MultiFileReader::Create(input.table_function); + auto file_list = multi_file_reader->CreateFileList(context, input.inputs[0]); + options.file_options.AutoDetectHivePartitioning(*file_list, context); + + // TODO: store the MultiFilelist instead + files = file_list->GetAllFiles(); + + InitializeReaders(context); +} + +void JSONScanData::InitializeReaders(ClientContext &context) { + union_readers.resize(files.empty() ? 0 : files.size() - 1); + for (idx_t file_idx = 0; file_idx < files.size(); file_idx++) { + if (file_idx == 0) { + initial_reader = make_uniq(context, options, files[0]); + } else { + union_readers[file_idx - 1] = make_uniq(context, options, files[file_idx]); + } + } +} + void JSONScanData::InitializeFormats() { - InitializeFormats(options.auto_detect); + InitializeFormats(auto_detect); } void JSONScanData::InitializeFormats(bool auto_detect_p) { - type_id_map_t> candidate_formats; // Initialize date_format_map if anything was specified - if (!options.date_format.empty()) { - DateFormatMap::AddFormat(candidate_formats, LogicalTypeId::DATE, options.date_format); + if (!date_format.empty()) { + date_format_map.AddFormat(LogicalTypeId::DATE, date_format); } - if (!options.timestamp_format.empty()) { - DateFormatMap::AddFormat(candidate_formats, LogicalTypeId::TIMESTAMP, options.timestamp_format); + if (!timestamp_format.empty()) { + date_format_map.AddFormat(LogicalTypeId::TIMESTAMP, timestamp_format); } if (auto_detect_p) { @@ -39,90 +108,942 @@ void JSONScanData::InitializeFormats(bool auto_detect_p) { // Populate possible date/timestamp formats, assume this is consistent across columns for (auto &kv : FORMAT_TEMPLATES) { const auto &logical_type = kv.first; - if (DateFormatMap::HasFormats(candidate_formats, logical_type)) { + if (date_format_map.HasFormats(logical_type)) { continue; // Already populated } const auto &format_strings = kv.second; for (auto &format_string : format_strings) { - DateFormatMap::AddFormat(candidate_formats, logical_type, format_string); + date_format_map.AddFormat(logical_type, format_string); } } } - date_format_map = make_uniq(std::move(candidate_formats)); } -JSONScanGlobalState::JSONScanGlobalState(ClientContext &context, const MultiFileBindData &bind_data_p) - : bind_data(bind_data_p), json_data(bind_data.bind_data->Cast()), - transform_options(json_data.transform_options), allocator(BufferAllocator::Get(context)), - buffer_capacity(json_data.options.maximum_object_size * 2), +void JSONScanData::SetCompression(const string &compression) { + options.compression = EnumUtil::FromString(StringUtil::Upper(compression)); +} + +string JSONScanData::GetDateFormat() const { + if (!date_format.empty()) { + return date_format; + } else if (date_format_map.HasFormats(LogicalTypeId::DATE)) { + return date_format_map.GetFormat(LogicalTypeId::DATE).format_specifier; + } else { + return string(); + } +} + +string JSONScanData::GetTimestampFormat() const { + if (!timestamp_format.empty()) { + return timestamp_format; + } else if (date_format_map.HasFormats(LogicalTypeId::TIMESTAMP)) { + return date_format_map.GetFormat(LogicalTypeId::TIMESTAMP).format_specifier; + } else { + return string(); + } +} + +JSONScanGlobalState::JSONScanGlobalState(ClientContext &context, const JSONScanData &bind_data_p) + : bind_data(bind_data_p), transform_options(bind_data.transform_options), allocator(BufferAllocator::Get(context)), + buffer_capacity(bind_data.maximum_object_size * 2), file_index(0), batch_index(0), system_threads(TaskScheduler::GetScheduler(context).NumberOfThreads()), - enable_parallel_scans(bind_data.file_list->GetTotalFileCount() < system_threads) { + enable_parallel_scans(bind_data.files.size() < system_threads) { } JSONScanLocalState::JSONScanLocalState(ClientContext &context, JSONScanGlobalState &gstate) - : scan_state(context, gstate.allocator, gstate.buffer_capacity) { + : scan_count(0), batch_index(DConstants::INVALID_INDEX), total_read_size(0), total_tuple_count(0), + bind_data(gstate.bind_data), allocator(BufferAllocator::Get(context)), is_last(false), + fs(FileSystem::GetFileSystem(context)), buffer_size(0), buffer_offset(0), prev_buffer_remainder(0) { } -JSONGlobalTableFunctionState::JSONGlobalTableFunctionState(ClientContext &context, const MultiFileBindData &bind_data) - : state(context, bind_data) { +JSONGlobalTableFunctionState::JSONGlobalTableFunctionState(ClientContext &context, TableFunctionInitInput &input) + : state(context, input.bind_data->Cast()) { +} + +unique_ptr JSONGlobalTableFunctionState::Init(ClientContext &context, + TableFunctionInitInput &input) { + auto &bind_data = input.bind_data->Cast(); + auto result = make_uniq(context, input); + auto &gstate = result->state; + + // Perform projection pushdown + for (idx_t col_idx = 0; col_idx < input.column_ids.size(); col_idx++) { + const auto &col_id = input.column_ids[col_idx]; + + // Skip any multi-file reader / row id stuff + if (col_id == bind_data.reader_bind.filename_idx || IsRowIdColumnId(col_id)) { + continue; + } + bool skip = false; + for (const auto &hive_partitioning_index : bind_data.reader_bind.hive_partitioning_indexes) { + if (col_id == hive_partitioning_index.index) { + skip = true; + break; + } + } + if (skip) { + continue; + } + + gstate.names.push_back(bind_data.names[col_id]); + gstate.column_ids.push_back(col_idx); + gstate.column_indices.push_back(input.column_indexes[col_idx]); + } + + if (gstate.names.size() < bind_data.names.size() || bind_data.options.file_options.union_by_name) { + // If we are auto-detecting, but don't need all columns present in the file, + // then we don't need to throw an error if we encounter an unseen column + gstate.transform_options.error_unknown_key = false; + } + + // Place readers where they belong + if (bind_data.initial_reader) { + bind_data.initial_reader->Reset(); + gstate.json_readers.emplace_back(bind_data.initial_reader.get()); + } + for (const auto &reader : bind_data.union_readers) { + reader->Reset(); + gstate.json_readers.emplace_back(reader.get()); + } + + vector dummy_global_types(bind_data.names.size(), LogicalType::ANY); + vector dummy_local_types(gstate.names.size(), LogicalType::ANY); + auto local_columns = MultiFileReaderColumnDefinition::ColumnsFromNamesAndTypes(gstate.names, dummy_local_types); + auto global_columns = + MultiFileReaderColumnDefinition::ColumnsFromNamesAndTypes(bind_data.names, dummy_global_types); + for (auto &reader : gstate.json_readers) { + MultiFileReader().FinalizeBind(reader->GetOptions().file_options, gstate.bind_data.reader_bind, + reader->GetFileName(), local_columns, global_columns, input.column_indexes, + reader->reader_data, context, nullptr); + } + + return std::move(result); +} + +idx_t JSONGlobalTableFunctionState::MaxThreads() const { + auto &bind_data = state.bind_data; + + if (!state.json_readers.empty() && state.json_readers[0]->HasFileHandle()) { + // We opened and auto-detected a file, so we can get a better estimate + auto &reader = *state.json_readers[0]; + if (bind_data.options.format == JSONFormat::NEWLINE_DELIMITED || + reader.GetFormat() == JSONFormat::NEWLINE_DELIMITED) { + return MaxValue(state.json_readers[0]->GetFileHandle().FileSize() / bind_data.maximum_object_size, + 1); + } + } + + if (bind_data.options.format == JSONFormat::NEWLINE_DELIMITED) { + // We haven't opened any files, so this is our best bet + return state.system_threads; + } + + // One reader per file + return bind_data.files.size(); } JSONLocalTableFunctionState::JSONLocalTableFunctionState(ClientContext &context, JSONScanGlobalState &gstate) : state(context, gstate) { } -idx_t JSONScanLocalState::Read() { - return scan_state.current_reader->Scan(scan_state); +unique_ptr JSONLocalTableFunctionState::Init(ExecutionContext &context, + TableFunctionInitInput &, + GlobalTableFunctionState *global_state) { + auto &gstate = global_state->Cast(); + auto result = make_uniq(context.client, gstate.state); + + // Copy the transform options / date format map because we need to do thread-local stuff + result->state.date_format_map = gstate.state.bind_data.date_format_map.Copy(); + result->state.transform_options = gstate.state.transform_options; + result->state.transform_options.date_format_map = &result->state.date_format_map; + + return std::move(result); +} + +idx_t JSONLocalTableFunctionState::GetBatchIndex() const { + return state.batch_index; +} + +static inline void SkipWhitespace(const char *buffer_ptr, idx_t &buffer_offset, const idx_t &buffer_size) { + for (; buffer_offset != buffer_size; buffer_offset++) { + if (!StringUtil::CharacterIsSpace(buffer_ptr[buffer_offset])) { + break; + } + } +} + +idx_t JSONScanLocalState::ReadNext(JSONScanGlobalState &gstate) { + allocator.Reset(); + scan_count = 0; + + // We have to wrap this in a loop otherwise we stop scanning too early when there's an empty JSON file + while (scan_count == 0) { + if (buffer_offset == buffer_size) { + if (!ReadNextBuffer(gstate)) { + break; + } + if (current_buffer_handle->buffer_index != 0 && + current_reader->GetFormat() == JSONFormat::NEWLINE_DELIMITED) { + if (ReconstructFirstObject(gstate)) { + scan_count++; + } + } + } + + ParseNextChunk(gstate); + } + + return scan_count; +} + +static inline const char *NextNewline(const char *ptr, const idx_t size) { + return const_char_ptr_cast(memchr(ptr, '\n', size)); +} + +static inline const char *PreviousNewline(const char *ptr, const idx_t size) { + const auto end = ptr - size; + for (ptr--; ptr != end; ptr--) { + if (*ptr == '\n') { + break; + } + } + return ptr; +} + +static inline const char *NextJSONDefault(const char *ptr, const char *const end) { + idx_t parents = 0; + while (ptr != end) { + switch (*ptr++) { + case '{': + case '[': + parents++; + continue; + case '}': + case ']': + parents--; + break; + case '"': + while (ptr != end) { + auto string_char = *ptr++; + if (string_char == '"') { + break; + } else if (string_char == '\\') { + if (ptr != end) { + ptr++; // Skip the escaped char + } + } + } + break; + default: + continue; + } + + if (parents == 0) { + break; + } + } + + return ptr; +} + +static inline const char *NextJSON(const char *ptr, const idx_t size) { + D_ASSERT(!StringUtil::CharacterIsSpace(*ptr)); // Should be handled before + + const char *const end = ptr + size; + switch (*ptr) { + case '{': + case '[': + case '"': + ptr = NextJSONDefault(ptr, end); + break; + default: + // Special case: JSON array containing JSON without clear "parents", i.e., not obj/arr/str + while (ptr != end) { + switch (*ptr++) { + case ',': + case ']': + ptr--; + break; + default: + continue; + } + break; + } + } + + return ptr == end ? nullptr : ptr; +} + +static inline void TrimWhitespace(JSONString &line) { + while (line.size != 0 && StringUtil::CharacterIsSpace(line[0])) { + line.pointer++; + line.size--; + } + while (line.size != 0 && StringUtil::CharacterIsSpace(line[line.size - 1])) { + line.size--; + } } void JSONScanLocalState::ParseJSON(char *const json_start, const idx_t json_size, const idx_t remaining) { - scan_state.current_reader->ParseJSON(scan_state, json_start, json_size, remaining); -} - -bool JSONScanLocalState::TryInitializeScan(JSONScanGlobalState &gstate, JSONReader &reader) { - // try to initialize a scan in the given reader - // three scenarios: - // scenario 1 - unseekable file - Read from the file and setup the buffers - // scenario 2 - seekable file - get the position from the file to read and return - // scenario 3 - entire file readers - if we are reading an entire file at once, do not do anything here, except for - // setting up the basics - auto read_type = JSONFileReadType::SCAN_PARTIAL; - if (!gstate.enable_parallel_scans || reader.GetFormat() != JSONFormat::NEWLINE_DELIMITED) { - read_type = JSONFileReadType::SCAN_ENTIRE_FILE; - } - if (read_type == JSONFileReadType::SCAN_ENTIRE_FILE) { - if (gstate.file_is_assigned) { + yyjson_doc *doc; + yyjson_read_err err; + if (bind_data.type == JSONScanType::READ_JSON_OBJECTS) { // If we return strings, we cannot parse INSITU + doc = JSONCommon::ReadDocumentUnsafe(json_start, json_size, JSONCommon::READ_STOP_FLAG, allocator.GetYYAlc(), + &err); + } else { + doc = JSONCommon::ReadDocumentUnsafe(json_start, remaining, JSONCommon::READ_INSITU_FLAG, allocator.GetYYAlc(), + &err); + } + if (err.code != YYJSON_READ_SUCCESS) { + auto can_ignore_this_error = bind_data.ignore_errors; + string extra; + if (current_reader->GetFormat() != JSONFormat::NEWLINE_DELIMITED) { + can_ignore_this_error = false; + extra = bind_data.ignore_errors + ? "Parse errors cannot be ignored for JSON formats other than 'newline_delimited'" + : ""; + } + if (!can_ignore_this_error) { + current_reader->ThrowParseError(current_buffer_handle->buffer_index, lines_or_objects_in_buffer, err, + extra); + } + } + + // We parse with YYJSON_STOP_WHEN_DONE, so we need to check this by hand + const auto read_size = yyjson_doc_get_read_size(doc); + if (read_size > json_size) { + // Can't go past the boundary, even with ignore_errors + err.code = YYJSON_READ_ERROR_UNEXPECTED_END; + err.msg = "unexpected end of data"; + err.pos = json_size; + current_reader->ThrowParseError(current_buffer_handle->buffer_index, lines_or_objects_in_buffer, err, + "Try auto-detecting the JSON format"); + } else if (!bind_data.ignore_errors && read_size < json_size) { + idx_t off = read_size; + idx_t rem = json_size; + SkipWhitespace(json_start, off, rem); + if (off != rem) { // Between end of document and boundary should be whitespace only + err.code = YYJSON_READ_ERROR_UNEXPECTED_CONTENT; + err.msg = "unexpected content after document"; + err.pos = read_size; + current_reader->ThrowParseError(current_buffer_handle->buffer_index, lines_or_objects_in_buffer, err, + "Try auto-detecting the JSON format"); + } + } + + lines_or_objects_in_buffer++; + if (!doc) { + values[scan_count] = nullptr; + return; + } + + // Set the JSONLine and trim + units[scan_count] = JSONString(json_start, json_size); + TrimWhitespace(units[scan_count]); + values[scan_count] = doc->root; +} + +void JSONScanLocalState::ThrowObjectSizeError(const idx_t object_size) { + throw InvalidInputException( + "\"maximum_object_size\" of %llu bytes exceeded while reading file \"%s\" (>%llu bytes)." + "\n Try increasing \"maximum_object_size\".", + bind_data.maximum_object_size, current_reader->GetFileName(), object_size); +} + +void JSONScanLocalState::TryIncrementFileIndex(JSONScanGlobalState &gstate) const { + if (gstate.file_index < gstate.json_readers.size() && + RefersToSameObject(*current_reader, *gstate.json_readers[gstate.file_index])) { + gstate.file_index++; + } +} + +bool JSONScanLocalState::IsParallel(JSONScanGlobalState &gstate) const { + if (bind_data.files.size() >= gstate.system_threads) { + return false; // More files than threads, just parallelize over the files + } + + // NDJSON can be read in parallel + return current_reader->GetFormat() == JSONFormat::NEWLINE_DELIMITED; +} + +static pair DetectFormatAndRecordType(char *const buffer_ptr, const idx_t buffer_size, + yyjson_alc *alc) { + // First we do the easy check whether it's NEWLINE_DELIMITED + auto line_end = NextNewline(buffer_ptr, buffer_size); + if (line_end != nullptr) { + idx_t line_size = line_end - buffer_ptr; + SkipWhitespace(buffer_ptr, line_size, buffer_size); + + yyjson_read_err error; + auto doc = JSONCommon::ReadDocumentUnsafe(buffer_ptr, line_size, JSONCommon::READ_FLAG, alc, &error); + if (error.code == YYJSON_READ_SUCCESS) { // We successfully read the line + if (yyjson_is_arr(doc->root) && line_size == buffer_size) { + // It's just one array, let's actually assume ARRAY, not NEWLINE_DELIMITED + if (yyjson_arr_size(doc->root) == 0 || yyjson_is_obj(yyjson_arr_get(doc->root, 0))) { + // Either an empty array (assume records), or an array of objects + return make_pair(JSONFormat::ARRAY, JSONRecordType::RECORDS); + } else { + return make_pair(JSONFormat::ARRAY, JSONRecordType::VALUES); + } + } else if (yyjson_is_obj(doc->root)) { + return make_pair(JSONFormat::NEWLINE_DELIMITED, JSONRecordType::RECORDS); + } else { + return make_pair(JSONFormat::NEWLINE_DELIMITED, JSONRecordType::VALUES); + } + } + } + + // Skip whitespace + idx_t buffer_offset = 0; + SkipWhitespace(buffer_ptr, buffer_offset, buffer_size); + auto remaining = buffer_size - buffer_offset; + + // We know it's not NEWLINE_DELIMITED at this point, if there's a '{', we know it's not ARRAY either + // Also if it's fully whitespace we just return something because we don't know + if (remaining == 0 || buffer_ptr[buffer_offset] == '{') { + return make_pair(JSONFormat::UNSTRUCTURED, JSONRecordType::RECORDS); + } + + // We know it's not top-level records, if it's not '[', it's not ARRAY either + if (buffer_ptr[buffer_offset] != '[') { + return make_pair(JSONFormat::UNSTRUCTURED, JSONRecordType::VALUES); + } + + // It's definitely an ARRAY, but now we have to figure out if there's more than one top-level array + yyjson_read_err error; + auto doc = + JSONCommon::ReadDocumentUnsafe(buffer_ptr + buffer_offset, remaining, JSONCommon::READ_STOP_FLAG, alc, &error); + if (error.code == YYJSON_READ_SUCCESS) { + D_ASSERT(yyjson_is_arr(doc->root)); + + // We successfully read something! + buffer_offset += yyjson_doc_get_read_size(doc); + SkipWhitespace(buffer_ptr, buffer_offset, buffer_size); + remaining = buffer_size - buffer_offset; + + if (remaining != 0) { // There's more + return make_pair(JSONFormat::UNSTRUCTURED, JSONRecordType::VALUES); + } + + // Just one array, check what's in there + if (yyjson_arr_size(doc->root) == 0 || yyjson_is_obj(yyjson_arr_get(doc->root, 0))) { + // Either an empty array (assume records), or an array of objects + return make_pair(JSONFormat::ARRAY, JSONRecordType::RECORDS); + } else { + return make_pair(JSONFormat::ARRAY, JSONRecordType::VALUES); + } + } + + // We weren't able to parse an array, could be broken or an array larger than our buffer size, let's skip over '[' + SkipWhitespace(buffer_ptr, ++buffer_offset, --remaining); + remaining = buffer_size - buffer_offset; + + // If it's '{' we know there's RECORDS in the ARRAY, else it's VALUES + if (remaining == 0 || buffer_ptr[buffer_offset] == '{') { + return make_pair(JSONFormat::ARRAY, JSONRecordType::RECORDS); + } + + // It's not RECORDS, so it must be VALUES + return make_pair(JSONFormat::ARRAY, JSONRecordType::VALUES); +} + +bool JSONScanLocalState::ReadNextBuffer(JSONScanGlobalState &gstate) { + // First we make sure we have a buffer to read into + AllocatedData buffer; + + // Try to re-use a buffer that was used before + if (current_reader && current_buffer_handle) { + current_reader->SetBufferLineOrObjectCount(*current_buffer_handle, lines_or_objects_in_buffer); + if (--current_buffer_handle->readers == 0) { + buffer = current_reader->RemoveBuffer(*current_buffer_handle); + } + } + + // Copy last bit of previous buffer + if (current_reader && current_reader->GetFormat() != JSONFormat::NEWLINE_DELIMITED && !is_last) { + if (!buffer.IsSet()) { + buffer = AllocateBuffer(gstate); + } + memcpy(buffer_ptr, GetReconstructBuffer(gstate), prev_buffer_remainder); + } + + optional_idx buffer_index; + while (true) { + // Continue with the current reader + if (current_reader) { + // Try to read (if we were not the last read in the previous iteration) + bool file_done = false; + bool read_success = ReadNextBufferInternal(gstate, buffer, buffer_index, file_done); + if (!is_last && read_success) { + // We read something + if (buffer_index.GetIndex() == 0 && current_reader->GetFormat() == JSONFormat::ARRAY) { + SkipOverArrayStart(); + } + } + + if (file_done) { + lock_guard guard(gstate.lock); + TryIncrementFileIndex(gstate); + lock_guard reader_guard(current_reader->lock); + current_reader->GetFileHandle().Close(); + } + + if (read_success) { + break; + } + + // We were the last reader last time, or we didn't read anything this time + current_reader = nullptr; + current_buffer_handle = nullptr; + is_last = false; + } + D_ASSERT(!current_buffer_handle); + + // If we got here, we don't have a reader (anymore). Try to get one + unique_lock guard(gstate.lock); + if (gstate.file_index == gstate.json_readers.size()) { + return false; // No more files left + } + + // Assign the next reader to this thread + current_reader = gstate.json_readers[gstate.file_index].get(); + + batch_index = gstate.batch_index++; + if (!gstate.enable_parallel_scans) { + // Non-parallel scans, increment file index and unlock + gstate.file_index++; + guard.unlock(); + } + + // Open the file if it is not yet open + if (!current_reader->IsOpen()) { + current_reader->OpenJSONFile(); + } + + // Auto-detect if we haven't yet done this during the bind + if (gstate.bind_data.options.record_type == JSONRecordType::AUTO_DETECT || + current_reader->GetFormat() == JSONFormat::AUTO_DETECT) { + bool file_done = false; + ReadAndAutoDetect(gstate, buffer, buffer_index, file_done); + if (file_done) { + TryIncrementFileIndex(gstate); + lock_guard reader_guard(current_reader->lock); + current_reader->GetFileHandle().Close(); + } + } + + if (gstate.enable_parallel_scans) { + if (!IsParallel(gstate)) { + // We still have the lock here if parallel scans are enabled + TryIncrementFileIndex(gstate); + } + } + + if (!buffer_index.IsValid() || buffer_size == 0) { + // If we didn't get a buffer index (because not auto-detecting), or the file was empty, just re-enter loop + continue; + } + + break; + } + D_ASSERT(buffer_index.IsValid()); + + idx_t readers = 1; + if (current_reader->GetFormat() == JSONFormat::NEWLINE_DELIMITED) { + readers = is_last ? 1 : 2; + } + + // Create an entry and insert it into the map + auto json_buffer_handle = + make_uniq(buffer_index.GetIndex(), readers, std::move(buffer), buffer_size); + current_buffer_handle = json_buffer_handle.get(); + current_reader->InsertBuffer(buffer_index.GetIndex(), std::move(json_buffer_handle)); + + prev_buffer_remainder = 0; + lines_or_objects_in_buffer = 0; + + // YYJSON needs this + memset(buffer_ptr + buffer_size, 0, YYJSON_PADDING_SIZE); + + return true; +} + +void JSONScanLocalState::ReadAndAutoDetect(JSONScanGlobalState &gstate, AllocatedData &buffer, + optional_idx &buffer_index, bool &file_done) { + // We have to detect the JSON format - hold the gstate lock while we do this + if (!ReadNextBufferInternal(gstate, buffer, buffer_index, file_done)) { + return; + } + if (buffer_size == 0) { + return; + } + + auto format_and_record_type = DetectFormatAndRecordType(buffer_ptr, buffer_size, allocator.GetYYAlc()); + if (current_reader->GetFormat() == JSONFormat::AUTO_DETECT) { + current_reader->SetFormat(format_and_record_type.first); + } + if (current_reader->GetRecordType() == JSONRecordType::AUTO_DETECT) { + current_reader->SetRecordType(format_and_record_type.second); + } + if (current_reader->GetFormat() == JSONFormat::ARRAY) { + SkipOverArrayStart(); + } + + if (!bind_data.ignore_errors && bind_data.options.record_type == JSONRecordType::RECORDS && + current_reader->GetRecordType() != JSONRecordType::RECORDS) { + current_reader->ThrowTransformError(buffer_index.GetIndex(), 0, + "Expected records, detected non-record JSON instead."); + } +} + +bool JSONScanLocalState::ReadNextBufferInternal(JSONScanGlobalState &gstate, AllocatedData &buffer, + optional_idx &buffer_index, bool &file_done) { + if (current_reader->GetFileHandle().CanSeek()) { + if (!ReadNextBufferSeek(gstate, buffer, buffer_index, file_done)) { + return false; + } + } else { + if (!ReadNextBufferNoSeek(gstate, buffer, buffer_index, file_done)) { return false; } - gstate.file_is_assigned = true; } - return reader.InitializeScan(scan_state, read_type); + + buffer_offset = 0; + + return true; } -void JSONScanLocalState::AddTransformError(idx_t object_index, const string &error_message) { - scan_state.current_reader->AddTransformError(scan_state, object_index, error_message); +bool JSONScanLocalState::ReadNextBufferSeek(JSONScanGlobalState &gstate, AllocatedData &buffer, + optional_idx &buffer_index, bool &file_done) { + auto &file_handle = current_reader->GetFileHandle(); + + idx_t request_size = gstate.buffer_capacity - prev_buffer_remainder - YYJSON_PADDING_SIZE; + idx_t read_position; + idx_t read_size; + + { + lock_guard reader_guard(current_reader->lock); + if (file_handle.LastReadRequested()) { + return false; + } + if (!buffer.IsSet()) { + buffer = AllocateBuffer(gstate); + } + if (!file_handle.GetPositionAndSize(read_position, read_size, request_size)) { + return false; // We weren't able to read + } + buffer_index = current_reader->GetBufferIndex(); + is_last = read_size == 0; + + if (current_reader->GetFormat() == JSONFormat::NEWLINE_DELIMITED) { + batch_index = gstate.batch_index++; + } + } + buffer_size = prev_buffer_remainder + read_size; + + if (read_size != 0) { + auto &raw_handle = file_handle.GetHandle(); + // For non-on-disk files, we create a handle per thread: this is faster for e.g. S3Filesystem where throttling + // per tcp connection can occur meaning that using multiple connections is faster. + if (!raw_handle.OnDiskFile() && raw_handle.CanSeek()) { + if (!thread_local_filehandle || thread_local_filehandle->GetPath() != raw_handle.GetPath()) { + thread_local_filehandle = + fs.OpenFile(raw_handle.GetPath(), FileFlags::FILE_FLAGS_READ | FileFlags::FILE_FLAGS_DIRECT_IO); + } + } else if (thread_local_filehandle) { + thread_local_filehandle = nullptr; + } + } + + // Now read the file lock-free! + file_handle.ReadAtPosition(buffer_ptr + prev_buffer_remainder, read_size, read_position, file_done, + gstate.bind_data.type == JSONScanType::SAMPLE, thread_local_filehandle); + + return true; +} + +bool JSONScanLocalState::ReadNextBufferNoSeek(JSONScanGlobalState &gstate, AllocatedData &buffer, + optional_idx &buffer_index, bool &file_done) { + idx_t request_size = gstate.buffer_capacity - prev_buffer_remainder - YYJSON_PADDING_SIZE; + idx_t read_size; + + { + lock_guard reader_guard(current_reader->lock); + if (!current_reader->HasFileHandle() || !current_reader->IsOpen()) { + return false; // Couldn't read anything + } + auto &file_handle = current_reader->GetFileHandle(); + if (file_handle.LastReadRequested()) { + return false; + } + if (!buffer.IsSet()) { + buffer = AllocateBuffer(gstate); + } + if (!file_handle.Read(buffer_ptr + prev_buffer_remainder, read_size, request_size, file_done, + gstate.bind_data.type == JSONScanType::SAMPLE)) { + return false; // Couldn't read anything + } + buffer_index = current_reader->GetBufferIndex(); + is_last = read_size == 0; + + if (current_reader->GetFormat() == JSONFormat::NEWLINE_DELIMITED) { + batch_index = gstate.batch_index++; + } + } + buffer_size = prev_buffer_remainder + read_size; + + return true; +} + +AllocatedData JSONScanLocalState::AllocateBuffer(JSONScanGlobalState &gstate) { + auto buffer = gstate.allocator.Allocate(gstate.buffer_capacity); + buffer_ptr = char_ptr_cast(buffer.get()); + return buffer; +} + +data_ptr_t JSONScanLocalState::GetReconstructBuffer(JSONScanGlobalState &gstate) { + if (!reconstruct_buffer.IsSet()) { + reconstruct_buffer = gstate.allocator.Allocate(gstate.buffer_capacity); + } + return reconstruct_buffer.get(); +} + +void JSONScanLocalState::SkipOverArrayStart() { + // First read of this buffer, check if it's actually an array and skip over the bytes + SkipWhitespace(buffer_ptr, buffer_offset, buffer_size); + if (buffer_offset == buffer_size) { + return; // Empty file + } + if (buffer_ptr[buffer_offset] != '[') { + throw InvalidInputException( + "Expected top-level JSON array with format='array', but first character is '%c' in file \"%s\"." + "\n Try setting format='auto' or format='newline_delimited'.", + buffer_ptr[buffer_offset], current_reader->GetFileName()); + } + SkipWhitespace(buffer_ptr, ++buffer_offset, buffer_size); + if (buffer_offset >= buffer_size) { + throw InvalidInputException("Missing closing brace ']' in JSON array with format='array' in file \"%s\"", + current_reader->GetFileName()); + } + if (buffer_ptr[buffer_offset] == ']') { + // Empty array + SkipWhitespace(buffer_ptr, ++buffer_offset, buffer_size); + if (buffer_offset != buffer_size) { + throw InvalidInputException( + "Empty array with trailing data when parsing JSON array with format='array' in file \"%s\"", + current_reader->GetFileName()); + } + return; + } +} + +bool JSONScanLocalState::ReconstructFirstObject(JSONScanGlobalState &gstate) { + D_ASSERT(current_buffer_handle->buffer_index != 0); + D_ASSERT(current_reader->GetFormat() == JSONFormat::NEWLINE_DELIMITED); + + // Spinlock until the previous batch index has also read its buffer + optional_ptr previous_buffer_handle; + while (!previous_buffer_handle) { + if (current_reader->HasThrown()) { + return false; + } + previous_buffer_handle = current_reader->GetBuffer(current_buffer_handle->buffer_index - 1); + } + + // First we find the newline in the previous block + auto prev_buffer_ptr = char_ptr_cast(previous_buffer_handle->buffer.get()) + previous_buffer_handle->buffer_size; + auto part1_ptr = PreviousNewline(prev_buffer_ptr, previous_buffer_handle->buffer_size); + auto part1_size = prev_buffer_ptr - part1_ptr; + + // Now copy the data to our reconstruct buffer + const auto reconstruct_ptr = GetReconstructBuffer(gstate); + memcpy(reconstruct_ptr, part1_ptr, part1_size); + + // We copied the object, so we are no longer reading the previous buffer + if (--previous_buffer_handle->readers == 0) { + current_reader->RemoveBuffer(*previous_buffer_handle); + } + + if (part1_size == 1) { + // Just a newline + return false; + } + + idx_t line_size = part1_size; + if (buffer_size != 0) { + // Now find the newline in the current block + auto line_end = NextNewline(buffer_ptr, buffer_size); + if (line_end == nullptr) { + ThrowObjectSizeError(buffer_size - buffer_offset); + } else { + line_end++; + } + idx_t part2_size = line_end - buffer_ptr; + + line_size += part2_size; + if (line_size > bind_data.maximum_object_size) { + ThrowObjectSizeError(line_size); + } + + // And copy the remainder of the line to the reconstruct buffer + memcpy(reconstruct_ptr + part1_size, buffer_ptr, part2_size); + memset(reconstruct_ptr + line_size, 0, YYJSON_PADDING_SIZE); + buffer_offset += part2_size; + } + + ParseJSON(char_ptr_cast(reconstruct_ptr), line_size, line_size); + + return true; +} + +void JSONScanLocalState::ParseNextChunk(JSONScanGlobalState &gstate) { + auto buffer_offset_before = buffer_offset; + + const auto format = current_reader->GetFormat(); + for (; scan_count < STANDARD_VECTOR_SIZE; scan_count++) { + SkipWhitespace(buffer_ptr, buffer_offset, buffer_size); + auto json_start = buffer_ptr + buffer_offset; + idx_t remaining = buffer_size - buffer_offset; + if (remaining == 0) { + break; + } + D_ASSERT(format != JSONFormat::AUTO_DETECT); + const char *json_end = format == JSONFormat::NEWLINE_DELIMITED ? NextNewline(json_start, remaining) + : NextJSON(json_start, remaining); + if (json_end == nullptr) { + // We reached the end of the buffer + if (!is_last) { + // Last bit of data belongs to the next batch + if (format != JSONFormat::NEWLINE_DELIMITED) { + if (remaining > bind_data.maximum_object_size) { + ThrowObjectSizeError(remaining); + } + memcpy(GetReconstructBuffer(gstate), json_start, remaining); + prev_buffer_remainder = remaining; + } + buffer_offset = buffer_size; + break; + } + json_end = json_start + remaining; + } + + idx_t json_size = json_end - json_start; + ParseJSON(json_start, json_size, remaining); + buffer_offset += json_size; + + if (format == JSONFormat::ARRAY) { + SkipWhitespace(buffer_ptr, buffer_offset, buffer_size); + if (buffer_ptr[buffer_offset] == ',' || buffer_ptr[buffer_offset] == ']') { + buffer_offset++; + } else { // We can't ignore this error, even with 'ignore_errors' + yyjson_read_err err; + err.code = YYJSON_READ_ERROR_UNEXPECTED_CHARACTER; + err.msg = "unexpected character"; + err.pos = json_size; + current_reader->ThrowParseError(current_buffer_handle->buffer_index, lines_or_objects_in_buffer, err); + } + } + SkipWhitespace(buffer_ptr, buffer_offset, buffer_size); + } + + total_read_size += buffer_offset - buffer_offset_before; + total_tuple_count += scan_count; +} + +yyjson_alc *JSONScanLocalState::GetAllocator() { + return allocator.GetYYAlc(); +} + +const MultiFileReaderData &JSONScanLocalState::GetReaderData() const { + return current_reader->reader_data; +} + +void JSONScanLocalState::ThrowTransformError(idx_t object_index, const string &error_message) { + D_ASSERT(current_reader); + D_ASSERT(current_buffer_handle); + D_ASSERT(object_index != DConstants::INVALID_INDEX); + auto line_or_object_in_buffer = lines_or_objects_in_buffer - scan_count + object_index; + current_reader->ThrowTransformError(current_buffer_handle->buffer_index, line_or_object_in_buffer, error_message); +} + +double JSONScan::ScanProgress(ClientContext &, const FunctionData *, const GlobalTableFunctionState *global_state) { + auto &gstate = global_state->Cast().state; + double progress = 0; + for (auto &reader : gstate.json_readers) { + progress += reader->GetProgress(); + } + return progress / double(gstate.json_readers.size()); +} + +OperatorPartitionData JSONScan::GetPartitionData(ClientContext &, TableFunctionGetPartitionInput &input) { + if (input.partition_info.RequiresPartitionColumns()) { + throw InternalException("JSONScan::GetPartitionData: partition columns not supported"); + } + auto &lstate = input.local_state->Cast(); + return OperatorPartitionData(lstate.GetBatchIndex()); +} + +unique_ptr JSONScan::Cardinality(ClientContext &, const FunctionData *bind_data) { + auto &data = bind_data->Cast(); + idx_t per_file_cardinality; + if (data.initial_reader && data.initial_reader->HasFileHandle()) { + per_file_cardinality = data.initial_reader->GetFileHandle().FileSize() / data.avg_tuple_size; + } else { + per_file_cardinality = 42; // The cardinality of an unknown JSON file is the almighty number 42 + } + return make_uniq(per_file_cardinality * data.files.size()); +} + +void JSONScan::ComplexFilterPushdown(ClientContext &context, LogicalGet &get, FunctionData *bind_data_p, + vector> &filters) { + auto &data = bind_data_p->Cast(); + + SimpleMultiFileList file_list(std::move(data.files)); + + MultiFilePushdownInfo info(get); + auto filtered_list = + MultiFileReader().ComplexFilterPushdown(context, file_list, data.options.file_options, info, filters); + if (filtered_list) { + MultiFileReader().PruneReaders(data, *filtered_list); + data.files = filtered_list->GetAllFiles(); + } else { + data.files = file_list.GetAllFiles(); + } } void JSONScan::Serialize(Serializer &serializer, const optional_ptr bind_data_p, const TableFunction &) { - throw NotImplementedException("JSONScan Serialize not implemented"); + auto &bind_data = bind_data_p->Cast(); + serializer.WriteProperty(100, "scan_data", &bind_data); } unique_ptr JSONScan::Deserialize(Deserializer &deserializer, TableFunction &) { - throw NotImplementedException("JSONScan Deserialize not implemented"); + unique_ptr result; + deserializer.ReadProperty(100, "scan_data", result); + result->InitializeReaders(deserializer.Get()); + result->InitializeFormats(); + result->transform_options.date_format_map = &result->date_format_map; + return std::move(result); } void JSONScan::TableFunctionDefaults(TableFunction &table_function) { + MultiFileReader().AddParameters(table_function); + table_function.named_parameters["maximum_object_size"] = LogicalType::UINTEGER; table_function.named_parameters["ignore_errors"] = LogicalType::BOOLEAN; table_function.named_parameters["format"] = LogicalType::VARCHAR; table_function.named_parameters["compression"] = LogicalType::VARCHAR; + table_function.table_scan_progress = ScanProgress; + table_function.get_partition_data = GetPartitionData; + table_function.cardinality = Cardinality; + table_function.serialize = Serialize; table_function.deserialize = Deserialize; table_function.projection_pushdown = true; table_function.filter_pushdown = false; table_function.filter_prune = false; + table_function.pushdown_complex_filter = ComplexFilterPushdown; } } // namespace duckdb diff --git a/src/duckdb/extension/json/serialize_json.cpp b/src/duckdb/extension/json/serialize_json.cpp index c8ac272e8..b5724e77e 100644 --- a/src/duckdb/extension/json/serialize_json.cpp +++ b/src/duckdb/extension/json/serialize_json.cpp @@ -5,10 +5,80 @@ #include "duckdb/common/serializer/serializer.hpp" #include "duckdb/common/serializer/deserializer.hpp" +#include "buffered_json_reader.hpp" #include "json_transform.hpp" +#include "json_scan.hpp" namespace duckdb { +void BufferedJSONReaderOptions::Serialize(Serializer &serializer) const { + serializer.WriteProperty(100, "format", format); + serializer.WriteProperty(101, "record_type", record_type); + serializer.WriteProperty(102, "compression", compression); + serializer.WriteProperty(103, "file_options", file_options); +} + +BufferedJSONReaderOptions BufferedJSONReaderOptions::Deserialize(Deserializer &deserializer) { + BufferedJSONReaderOptions result; + deserializer.ReadProperty(100, "format", result.format); + deserializer.ReadProperty(101, "record_type", result.record_type); + deserializer.ReadProperty(102, "compression", result.compression); + deserializer.ReadProperty(103, "file_options", result.file_options); + return result; +} + +void JSONScanData::Serialize(Serializer &serializer) const { + serializer.WriteProperty(100, "json_type", type); + serializer.WriteProperty(101, "options", options); + serializer.WriteProperty(102, "reader_bind", reader_bind); + serializer.WritePropertyWithDefault>(103, "files", files); + serializer.WritePropertyWithDefault(104, "ignore_errors", ignore_errors); + serializer.WritePropertyWithDefault(105, "maximum_object_size", maximum_object_size); + serializer.WritePropertyWithDefault(106, "auto_detect", auto_detect); + serializer.WritePropertyWithDefault(107, "sample_size", sample_size); + serializer.WritePropertyWithDefault(108, "max_depth", max_depth); + serializer.WriteProperty(109, "transform_options", transform_options); + serializer.WritePropertyWithDefault>(110, "names", names); + serializer.WritePropertyWithDefault(111, "date_format", GetDateFormat()); + serializer.WritePropertyWithDefault(112, "timestamp_format", GetTimestampFormat()); + serializer.WritePropertyWithDefault(113, "field_appearance_threshold", field_appearance_threshold, 0.1); + serializer.WritePropertyWithDefault(114, "maximum_sample_files", maximum_sample_files, 32); + serializer.WritePropertyWithDefault(115, "convert_strings_to_integers", convert_strings_to_integers, false); + serializer.WritePropertyWithDefault(116, "map_inference_threshold", map_inference_threshold, 200); +} + +unique_ptr JSONScanData::Deserialize(Deserializer &deserializer) { + auto type = deserializer.ReadProperty(100, "json_type"); + auto options = deserializer.ReadProperty(101, "options"); + auto reader_bind = deserializer.ReadProperty(102, "reader_bind"); + auto files = deserializer.ReadPropertyWithDefault>(103, "files"); + auto ignore_errors = deserializer.ReadPropertyWithDefault(104, "ignore_errors"); + auto maximum_object_size = deserializer.ReadPropertyWithDefault(105, "maximum_object_size"); + auto auto_detect = deserializer.ReadPropertyWithDefault(106, "auto_detect"); + auto sample_size = deserializer.ReadPropertyWithDefault(107, "sample_size"); + auto max_depth = deserializer.ReadPropertyWithDefault(108, "max_depth"); + auto transform_options = deserializer.ReadProperty(109, "transform_options"); + auto names = deserializer.ReadPropertyWithDefault>(110, "names"); + auto date_format = deserializer.ReadPropertyWithDefault(111, "date_format"); + auto timestamp_format = deserializer.ReadPropertyWithDefault(112, "timestamp_format"); + auto result = duckdb::unique_ptr(new JSONScanData(deserializer.Get(), std::move(files), std::move(date_format), std::move(timestamp_format))); + result->type = type; + result->options = options; + result->reader_bind = reader_bind; + result->ignore_errors = ignore_errors; + result->maximum_object_size = maximum_object_size; + result->auto_detect = auto_detect; + result->sample_size = sample_size; + result->max_depth = max_depth; + result->transform_options = transform_options; + result->names = std::move(names); + deserializer.ReadPropertyWithExplicitDefault(113, "field_appearance_threshold", result->field_appearance_threshold, 0.1); + deserializer.ReadPropertyWithExplicitDefault(114, "maximum_sample_files", result->maximum_sample_files, 32); + deserializer.ReadPropertyWithExplicitDefault(115, "convert_strings_to_integers", result->convert_strings_to_integers, false); + deserializer.ReadPropertyWithExplicitDefault(116, "map_inference_threshold", result->map_inference_threshold, 200); + return result; +} + void JSONTransformOptions::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault(100, "strict_cast", strict_cast); serializer.WritePropertyWithDefault(101, "error_duplicate_key", error_duplicate_key); diff --git a/src/duckdb/extension/parquet/column_reader.cpp b/src/duckdb/extension/parquet/column_reader.cpp index 6118653fc..73db368bc 100644 --- a/src/duckdb/extension/parquet/column_reader.cpp +++ b/src/duckdb/extension/parquet/column_reader.cpp @@ -1,32 +1,31 @@ #include "column_reader.hpp" -#include "reader/boolean_column_reader.hpp" +#include "boolean_column_reader.hpp" #include "brotli/decode.h" -#include "reader/callback_column_reader.hpp" -#include "reader/decimal_column_reader.hpp" +#include "callback_column_reader.hpp" +#include "cast_column_reader.hpp" #include "duckdb.hpp" -#include "reader/expression_column_reader.hpp" -#include "reader/interval_column_reader.hpp" -#include "reader/list_column_reader.hpp" +#include "expression_column_reader.hpp" +#include "list_column_reader.hpp" #include "lz4.hpp" #include "miniz_wrapper.hpp" -#include "reader/null_column_reader.hpp" +#include "null_column_reader.hpp" +#include "parquet_decimal_utils.hpp" #include "parquet_reader.hpp" #include "parquet_timestamp.hpp" -#include "parquet_float16.hpp" - -#include "reader/row_number_column_reader.hpp" +#include "row_number_column_reader.hpp" #include "snappy.h" -#include "reader/string_column_reader.hpp" -#include "reader/struct_column_reader.hpp" -#include "reader/templated_column_reader.hpp" -#include "reader/uuid_column_reader.hpp" - +#include "string_column_reader.hpp" +#include "struct_column_reader.hpp" +#include "templated_column_reader.hpp" +#include "utf8proc_wrapper.hpp" #include "zstd.h" -#include "duckdb/storage/table/column_segment.hpp" +#ifndef DUCKDB_AMALGAMATION #include "duckdb/common/helper.hpp" #include "duckdb/common/types/bit.hpp" +#include "duckdb/common/types/blob.hpp" +#endif namespace duckdb { @@ -106,10 +105,15 @@ const uint64_t ParquetDecodeUtils::BITPACK_MASKS_SIZE = sizeof(ParquetDecodeUtil const uint8_t ParquetDecodeUtils::BITPACK_DLEN = 8; -ColumnReader::ColumnReader(ParquetReader &reader, const ParquetColumnSchema &schema_p) - : column_schema(schema_p), reader(reader), page_rows_available(0), dictionary_decoder(*this), - delta_binary_packed_decoder(*this), rle_decoder(*this), delta_length_byte_array_decoder(*this), - delta_byte_array_decoder(*this), byte_stream_split_decoder(*this) { +ColumnReader::ColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t file_idx_p, + idx_t max_define_p, idx_t max_repeat_p) + : schema(schema_p), file_idx(file_idx_p), max_define(max_define_p), max_repeat(max_repeat_p), reader(reader), + type(std::move(type_p)), page_rows_available(0), dictionary_selection_vector(STANDARD_VECTOR_SIZE), + dictionary_size(0) { + + // dummies for Skip() + dummy_define.resize(reader.allocator, STANDARD_VECTOR_SIZE); + dummy_repeat.resize(reader.allocator, STANDARD_VECTOR_SIZE); } ColumnReader::~ColumnReader() { @@ -123,6 +127,34 @@ ParquetReader &ColumnReader::Reader() { return reader; } +const LogicalType &ColumnReader::Type() const { + return type; +} + +const SchemaElement &ColumnReader::Schema() const { + return schema; +} + +optional_ptr ColumnReader::GetParentSchema() const { + return parent_schema; +} + +void ColumnReader::SetParentSchema(const SchemaElement &parent_schema_p) { + parent_schema = &parent_schema_p; +} + +idx_t ColumnReader::FileIdx() const { + return file_idx; +} + +idx_t ColumnReader::MaxDefine() const { + return max_define; +} + +idx_t ColumnReader::MaxRepeat() const { + return max_repeat; +} + void ColumnReader::RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge) { if (chunk) { uint64_t size = chunk->meta_data.total_compressed_size; @@ -130,10 +162,6 @@ void ColumnReader::RegisterPrefetch(ThriftFileTransport &transport, bool allow_m } } -unique_ptr ColumnReader::Stats(idx_t row_group_idx_p, const vector &columns) { - return Schema().Stats(reader, row_group_idx_p, columns); -} - uint64_t ColumnReader::TotalCompressedSize() { if (!chunk) { return 0; @@ -165,28 +193,34 @@ idx_t ColumnReader::GroupRowsAvailable() { return group_rows_available; } -void ColumnReader::PlainSkip(ByteBuffer &plain_data, uint8_t *defines, idx_t num_values) { - throw NotImplementedException("PlainSkip not implemented"); +unique_ptr ColumnReader::Stats(idx_t row_group_idx_p, const vector &columns) { + return ParquetStatisticsUtils::TransformColumnStatistics(*this, columns); +} + +void ColumnReader::Plain(shared_ptr plain_data, uint8_t *defines, idx_t num_values, // NOLINT + parquet_filter_t *filter, idx_t result_offset, Vector &result) { + throw NotImplementedException("Plain"); +} + +void ColumnReader::PrepareDeltaLengthByteArray(ResizeableBuffer &buffer) { + throw std::runtime_error("DELTA_LENGTH_BYTE_ARRAY encoding is only supported for text or binary data"); } -void ColumnReader::Plain(ByteBuffer &plain_data, uint8_t *defines, idx_t num_values, // NOLINT - idx_t result_offset, Vector &result) { - throw NotImplementedException("Plain not implemented"); +void ColumnReader::PrepareDeltaByteArray(ResizeableBuffer &buffer) { + throw std::runtime_error("DELTA_BYTE_ARRAY encoding is only supported for text or binary data"); } -void ColumnReader::Plain(shared_ptr &plain_data, uint8_t *defines, idx_t num_values, - idx_t result_offset, Vector &result) { - Plain(*plain_data, defines, num_values, result_offset, result); +void ColumnReader::DeltaByteArray(uint8_t *defines, idx_t num_values, // NOLINT + parquet_filter_t &filter, idx_t result_offset, Vector &result) { + throw NotImplementedException("DeltaByteArray"); } -void ColumnReader::PlainSelect(shared_ptr &plain_data, uint8_t *defines, idx_t num_values, - Vector &result, const SelectionVector &sel, idx_t count) { - throw NotImplementedException("PlainSelect not implemented"); +void ColumnReader::PlainReference(shared_ptr, Vector &result) { // NOLINT } void ColumnReader::InitializeRead(idx_t row_group_idx_p, const vector &columns, TProtocol &protocol_p) { - D_ASSERT(ColumnIndex() < columns.size()); - chunk = &columns[ColumnIndex()]; + D_ASSERT(file_idx < columns.size()); + chunk = &columns[file_idx]; protocol = &protocol_p; D_ASSERT(chunk); D_ASSERT(chunk->__isset.meta_data); @@ -204,62 +238,18 @@ void ColumnReader::InitializeRead(idx_t row_group_idx_p, const vectormeta_data.num_values; } -bool ColumnReader::PageIsFilteredOut(PageHeader &page_hdr) { - if (!dictionary_decoder.HasFilteredOutAllValues()) { - return false; - } - if (page_hdr.type != PageType::DATA_PAGE && page_hdr.type != PageType::DATA_PAGE_V2) { - // we can only filter out data pages - return false; - } - bool is_v1 = page_hdr.type == PageType::DATA_PAGE; - auto &v1_header = page_hdr.data_page_header; - auto &v2_header = page_hdr.data_page_header_v2; - auto page_encoding = is_v1 ? v1_header.encoding : v2_header.encoding; - if (page_encoding != Encoding::PLAIN_DICTIONARY && page_encoding != Encoding::RLE_DICTIONARY) { - // not a dictionary page - return false; - } - // the page has been filtered out! - // skip forward - auto &trans = reinterpret_cast(*protocol->getTransport()); - trans.Skip(page_hdr.compressed_page_size); - - page_rows_available = is_v1 ? v1_header.num_values : v2_header.num_values; - encoding = ColumnEncoding::DICTIONARY; - page_is_filtered_out = true; - return true; -} - -void ColumnReader::PrepareRead(optional_ptr filter, optional_ptr filter_state) { - encoding = ColumnEncoding::INVALID; +void ColumnReader::PrepareRead(parquet_filter_t &filter) { + dict_decoder.reset(); defined_decoder.reset(); - page_is_filtered_out = false; + bss_decoder.reset(); block.reset(); PageHeader page_hdr; - auto &trans = reinterpret_cast(*protocol->getTransport()); - if (trans.HasPrefetch()) { - // Already has some data prefetched, let's not mess with it - reader.Read(page_hdr, *protocol); - } else { - // No prefetch yet, prefetch the full header in one go (so thrift won't read byte-by-byte from storage) - // 256 bytes should cover almost all headers (unless it's a V2 header with really LONG string statistics) - static constexpr idx_t ASSUMED_HEADER_SIZE = 256; - const auto prefetch_size = MinValue(trans.GetSize() - trans.GetLocation(), ASSUMED_HEADER_SIZE); - trans.Prefetch(trans.GetLocation(), prefetch_size); - reader.Read(page_hdr, *protocol); - trans.ClearPrefetch(); - } + reader.Read(page_hdr, *protocol); // some basic sanity check if (page_hdr.compressed_page_size < 0 || page_hdr.uncompressed_page_size < 0) { throw std::runtime_error("Page sizes can't be < 0"); } - if (PageIsFilteredOut(page_hdr)) { - // this page has been filtered out so we don't need to read it - return; - } - switch (page_hdr.type) { case PageType::DATA_PAGE_V2: PreparePageV2(page_hdr); @@ -271,11 +261,22 @@ void ColumnReader::PrepareRead(optional_ptr filter, optional_ break; case PageType::DICTIONARY_PAGE: { PreparePage(page_hdr); - auto dictionary_size = page_hdr.dictionary_page_header.num_values; - if (dictionary_size < 0) { + if (page_hdr.dictionary_page_header.num_values < 0) { throw std::runtime_error("Invalid dictionary page header (num_values < 0)"); } - dictionary_decoder.InitializeDictionary(dictionary_size, filter, filter_state, HasDefines()); + auto old_dict_size = dictionary_size; + // we use the first value in the dictionary to keep a NULL + dictionary_size = page_hdr.dictionary_page_header.num_values; + if (!dictionary) { + dictionary = make_uniq(type, dictionary_size + 1); + } else if (dictionary_size > old_dict_size) { + dictionary->Resize(old_dict_size, dictionary_size + 1); + } + dictionary_id = reader.file_name + "_" + schema.name + "_" + std::to_string(chunk_read_offset); + // we use the first entry as a NULL, dictionary vectors don't have a separate validity mask + FlatVector::Validity(*dictionary).SetInvalid(0); + PlainReference(block, *dictionary); + Plain(block, nullptr, dictionary_size, nullptr, 1, *dictionary); break; } default: @@ -318,14 +319,12 @@ void ColumnReader::PreparePageV2(PageHeader &page_hdr) { auto compressed_bytes = page_hdr.compressed_page_size - uncompressed_bytes; - if (compressed_bytes > 0) { - ResizeableBuffer compressed_buffer; - compressed_buffer.resize(GetAllocator(), compressed_bytes); - reader.ReadData(*protocol, compressed_buffer.ptr, compressed_bytes); + ResizeableBuffer compressed_buffer; + compressed_buffer.resize(GetAllocator(), compressed_bytes); + reader.ReadData(*protocol, compressed_buffer.ptr, compressed_bytes); - DecompressInternal(chunk->meta_data.codec, compressed_buffer.ptr, compressed_bytes, - block->ptr + uncompressed_bytes, page_hdr.uncompressed_page_size - uncompressed_bytes); - } + DecompressInternal(chunk->meta_data.codec, compressed_buffer.ptr, compressed_bytes, block->ptr + uncompressed_bytes, + page_hdr.uncompressed_page_size - uncompressed_bytes); } void ColumnReader::AllocateBlock(idx_t size) { @@ -440,7 +439,7 @@ void ColumnReader::PrepareDataPage(PageHeader &page_hdr) { if (HasRepeats()) { uint32_t rep_length = is_v1 ? block->read() : v2_header.repetition_levels_byte_length; block->available(rep_length); - repeated_decoder = make_uniq(block->ptr, rep_length, RleBpDecoder::ComputeBitWidth(MaxRepeat())); + repeated_decoder = make_uniq(block->ptr, rep_length, RleBpDecoder::ComputeBitWidth(max_repeat)); block->inc(rep_length); } else if (is_v2 && v2_header.repetition_levels_byte_length > 0) { block->inc(v2_header.repetition_levels_byte_length); @@ -449,7 +448,7 @@ void ColumnReader::PrepareDataPage(PageHeader &page_hdr) { if (HasDefines()) { uint32_t def_length = is_v1 ? block->read() : v2_header.definition_levels_byte_length; block->available(def_length); - defined_decoder = make_uniq(block->ptr, def_length, RleBpDecoder::ComputeBitWidth(MaxDefine())); + defined_decoder = make_uniq(block->ptr, def_length, RleBpDecoder::ComputeBitWidth(max_define)); block->inc(def_length); } else if (is_v2 && v2_header.definition_levels_byte_length > 0) { block->inc(v2_header.definition_levels_byte_length); @@ -458,38 +457,43 @@ void ColumnReader::PrepareDataPage(PageHeader &page_hdr) { switch (page_encoding) { case Encoding::RLE_DICTIONARY: case Encoding::PLAIN_DICTIONARY: { - encoding = ColumnEncoding::DICTIONARY; - dictionary_decoder.InitializePage(); + // where is it otherwise?? + auto dict_width = block->read(); + // TODO somehow dict_width can be 0 ? + dict_decoder = make_uniq(block->ptr, block->len, dict_width); + block->inc(block->len); break; } case Encoding::RLE: { - encoding = ColumnEncoding::RLE; - rle_decoder.InitializePage(); + if (type.id() != LogicalTypeId::BOOLEAN) { + throw std::runtime_error("RLE encoding is only supported for boolean data"); + } + block->inc(sizeof(uint32_t)); + rle_decoder = make_uniq(block->ptr, block->len, 1); break; } case Encoding::DELTA_BINARY_PACKED: { - encoding = ColumnEncoding::DELTA_BINARY_PACKED; - delta_binary_packed_decoder.InitializePage(); + dbp_decoder = make_uniq(block->ptr, block->len); + block->inc(block->len); break; } case Encoding::DELTA_LENGTH_BYTE_ARRAY: { - encoding = ColumnEncoding::DELTA_LENGTH_BYTE_ARRAY; - delta_length_byte_array_decoder.InitializePage(); + PrepareDeltaLengthByteArray(*block); break; } case Encoding::DELTA_BYTE_ARRAY: { - encoding = ColumnEncoding::DELTA_BYTE_ARRAY; - delta_byte_array_decoder.InitializePage(); + PrepareDeltaByteArray(*block); break; } case Encoding::BYTE_STREAM_SPLIT: { - encoding = ColumnEncoding::BYTE_STREAM_SPLIT; - byte_stream_split_decoder.InitializePage(); + // Subtract 1 from length as the block is allocated with 1 extra byte, + // but the byte stream split encoder needs to know the correct data size. + bss_decoder = make_uniq(block->ptr, block->len - 1); + block->inc(block->len); break; } case Encoding::PLAIN: // nothing to do here, will be read directly below - encoding = ColumnEncoding::PLAIN; break; default: @@ -497,383 +501,1230 @@ void ColumnReader::PrepareDataPage(PageHeader &page_hdr) { } } -void ColumnReader::BeginRead(data_ptr_t define_out, data_ptr_t repeat_out) { +void ColumnReader::ConvertDictToSelVec(uint32_t *offsets, uint8_t *defines, parquet_filter_t &filter, idx_t read_now, + idx_t result_offset) { + D_ASSERT(read_now <= STANDARD_VECTOR_SIZE); + idx_t offset_idx = 0; + for (idx_t row_idx = 0; row_idx < read_now; row_idx++) { + if (HasDefines() && defines[row_idx + result_offset] != max_define) { + dictionary_selection_vector.set_index(row_idx, 0); // dictionary entry 0 is NULL + continue; // we don't have a dict entry for NULLs + } + if (filter.test(row_idx + result_offset)) { + auto offset = offsets[offset_idx++]; + if (offset >= dictionary_size) { + throw std::runtime_error("Parquet file is likely corrupted, dictionary offset out of range"); + } + dictionary_selection_vector.set_index(row_idx, offset + 1); + } else { + dictionary_selection_vector.set_index(row_idx, 0); // just set NULL if the filter excludes this row + offset_idx++; + } + } +#ifdef DEBUG + dictionary_selection_vector.Verify(read_now, dictionary_size + 1); +#endif +} + +idx_t ColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, data_ptr_t repeat_out, + Vector &result) { // we need to reset the location because multiple column readers share the same protocol auto &trans = reinterpret_cast(*protocol->getTransport()); trans.SetLocation(chunk_read_offset); // Perform any skips that were not applied yet. - if (define_out && repeat_out) { - ApplyPendingSkips(define_out, repeat_out); + if (pending_skips > 0) { + ApplyPendingSkips(pending_skips); } -} -idx_t ColumnReader::ReadPageHeaders(idx_t max_read, optional_ptr filter, - optional_ptr filter_state) { - while (page_rows_available == 0) { - PrepareRead(filter, filter_state); + idx_t result_offset = 0; + auto to_read = num_values; + D_ASSERT(to_read <= STANDARD_VECTOR_SIZE); + + while (to_read > 0) { + while (page_rows_available == 0) { + PrepareRead(filter); + } + + D_ASSERT(block); + auto read_now = MinValue(to_read, page_rows_available); + + D_ASSERT(read_now + result_offset <= STANDARD_VECTOR_SIZE); + + if (HasRepeats()) { + D_ASSERT(repeated_decoder); + repeated_decoder->GetBatch(repeat_out + result_offset, read_now); + } + + if (HasDefines()) { + D_ASSERT(defined_decoder); + defined_decoder->GetBatch(define_out + result_offset, read_now); + } + + idx_t null_count = 0; + + if ((dict_decoder || dbp_decoder || rle_decoder || bss_decoder) && HasDefines()) { + // we need the null count because the dictionary offsets have no entries for nulls + for (idx_t i = result_offset; i < result_offset + read_now; i++) { + null_count += (define_out[i] != max_define); + } + } + + if (result_offset != 0 && result.GetVectorType() != VectorType::FLAT_VECTOR) { + result.Flatten(result_offset); + result.Resize(result_offset, STANDARD_VECTOR_SIZE); + } + + if (dict_decoder) { + if ((!dictionary || dictionary_size == 0) && null_count < read_now) { + throw std::runtime_error("Parquet file is likely corrupted, missing dictionary"); + } + offset_buffer.resize(reader.allocator, sizeof(uint32_t) * (read_now - null_count)); + dict_decoder->GetBatch(offset_buffer.ptr, read_now - null_count); + ConvertDictToSelVec(reinterpret_cast(offset_buffer.ptr), + reinterpret_cast(define_out), filter, read_now, result_offset); + if (result_offset == 0) { + result.Dictionary(*dictionary, dictionary_size + 1, dictionary_selection_vector, read_now); + DictionaryVector::SetDictionaryId(result, dictionary_id); + D_ASSERT(result.GetVectorType() == VectorType::DICTIONARY_VECTOR); + } else { + D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR); + VectorOperations::Copy(*dictionary, result, dictionary_selection_vector, read_now, 0, result_offset); + } + } else if (dbp_decoder) { + // TODO keep this in the state + auto read_buf = make_shared_ptr(); + + switch (schema.type) { + case duckdb_parquet::Type::INT32: + read_buf->resize(reader.allocator, sizeof(int32_t) * (read_now - null_count)); + dbp_decoder->GetBatch(read_buf->ptr, read_now - null_count); + + break; + case duckdb_parquet::Type::INT64: + read_buf->resize(reader.allocator, sizeof(int64_t) * (read_now - null_count)); + dbp_decoder->GetBatch(read_buf->ptr, read_now - null_count); + break; + + default: + throw std::runtime_error("DELTA_BINARY_PACKED should only be INT32 or INT64"); + } + // Plain() will put NULLs in the right place + Plain(read_buf, define_out, read_now, &filter, result_offset, result); + } else if (rle_decoder) { + // RLE encoding for boolean + D_ASSERT(type.id() == LogicalTypeId::BOOLEAN); + auto read_buf = make_shared_ptr(); + read_buf->resize(reader.allocator, sizeof(bool) * (read_now - null_count)); + rle_decoder->GetBatch(read_buf->ptr, read_now - null_count); + PlainTemplated>(read_buf, define_out, read_now, &filter, + result_offset, result); + } else if (byte_array_data) { + // DELTA_BYTE_ARRAY or DELTA_LENGTH_BYTE_ARRAY + DeltaByteArray(define_out, read_now, filter, result_offset, result); + } else if (bss_decoder) { + auto read_buf = make_shared_ptr(); + + switch (schema.type) { + case duckdb_parquet::Type::FLOAT: + read_buf->resize(reader.allocator, sizeof(float) * (read_now - null_count)); + bss_decoder->GetBatch(read_buf->ptr, read_now - null_count); + break; + case duckdb_parquet::Type::DOUBLE: + read_buf->resize(reader.allocator, sizeof(double) * (read_now - null_count)); + bss_decoder->GetBatch(read_buf->ptr, read_now - null_count); + break; + default: + throw std::runtime_error("BYTE_STREAM_SPLIT encoding is only supported for FLOAT or DOUBLE data"); + } + + Plain(read_buf, define_out, read_now, &filter, result_offset, result); + } else { + PlainReference(block, result); + Plain(block, define_out, read_now, &filter, result_offset, result); + } + + result_offset += read_now; + page_rows_available -= read_now; + to_read -= read_now; } - return MinValue(MinValue(max_read, page_rows_available), STANDARD_VECTOR_SIZE); + group_rows_available -= num_values; + chunk_read_offset = trans.GetLocation(); + + return num_values; } -bool ColumnReader::PrepareRead(idx_t read_now, data_ptr_t define_out, data_ptr_t repeat_out, idx_t result_offset) { - D_ASSERT(block); +void ColumnReader::Skip(idx_t num_values) { + pending_skips += num_values; +} - D_ASSERT(read_now + result_offset <= STANDARD_VECTOR_SIZE); - D_ASSERT(!page_is_filtered_out); +void ColumnReader::ApplyPendingSkips(idx_t num_values) { + pending_skips -= num_values; - if (HasRepeats()) { - D_ASSERT(repeated_decoder); - repeated_decoder->GetBatch(repeat_out + result_offset, read_now); + dummy_define.zero(); + dummy_repeat.zero(); + + // TODO this can be optimized, for example we dont actually have to bitunpack offsets + Vector base_result(type, nullptr); + + idx_t remaining = num_values; + idx_t read = 0; + + while (remaining) { + Vector dummy_result(base_result); + idx_t to_read = MinValue(remaining, STANDARD_VECTOR_SIZE); + read += Read(to_read, none_filter, dummy_define.ptr, dummy_repeat.ptr, dummy_result); + remaining -= to_read; } - if (HasDefines()) { - D_ASSERT(defined_decoder); - const auto max_define = NumericCast(MaxDefine()); - if (!HasRepeats() && defined_decoder->HasRepeatedBatch(read_now, max_define)) { - // Fast path: no repeats and all valid - defined_decoder->GetRepeatedBatch(read_now, max_define); - return true; - } - defined_decoder->GetBatch(define_out + result_offset, read_now); - return false; + if (read != num_values) { + throw std::runtime_error("Row count mismatch when skipping rows"); } +} - return true; // No defines, so everything is valid +//===--------------------------------------------------------------------===// +// String Column Reader +//===--------------------------------------------------------------------===// +StringColumnReader::StringColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, + idx_t schema_idx_p, idx_t max_define_p, idx_t max_repeat_p) + : TemplatedColumnReader(reader, std::move(type_p), schema_p, schema_idx_p, + max_define_p, max_repeat_p) { + fixed_width_string_length = 0; + if (schema_p.type == Type::FIXED_LEN_BYTE_ARRAY) { + D_ASSERT(schema_p.__isset.type_length); + fixed_width_string_length = schema_p.type_length; + } } -void ColumnReader::ReadData(idx_t read_now, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result, - idx_t result_offset) { - // flatten the result vector if required - if (result_offset != 0 && result.GetVectorType() != VectorType::FLAT_VECTOR) { - result.Flatten(result_offset); - result.Resize(result_offset, STANDARD_VECTOR_SIZE); +uint32_t StringColumnReader::VerifyString(const char *str_data, uint32_t str_len, const bool is_varchar) { + if (!is_varchar) { + return str_len; } - if (page_is_filtered_out) { - // page is filtered out - emit NULL for any rows - auto &validity = FlatVector::Validity(result); - for (idx_t i = 0; i < read_now; i++) { - validity.SetInvalid(result_offset + i); - } - page_rows_available -= read_now; + // verify if a string is actually UTF8, and if there are no null bytes in the middle of the string + // technically Parquet should guarantee this, but reality is often disappointing + UnicodeInvalidReason reason; + size_t pos; + auto utf_type = Utf8Proc::Analyze(str_data, str_len, &reason, &pos); + if (utf_type == UnicodeType::INVALID) { + throw InvalidInputException("Invalid string encoding found in Parquet file: value \"" + + Blob::ToString(string_t(str_data, str_len)) + "\" is not valid UTF8!"); + } + return str_len; +} + +uint32_t StringColumnReader::VerifyString(const char *str_data, uint32_t str_len) { + return VerifyString(str_data, str_len, Type() == LogicalTypeId::VARCHAR); +} + +static shared_ptr ReadDbpData(Allocator &allocator, ResizeableBuffer &buffer, idx_t &value_count) { + auto decoder = make_uniq(buffer.ptr, buffer.len); + value_count = decoder->TotalValues(); + auto result = make_shared_ptr(); + result->resize(allocator, sizeof(uint32_t) * value_count); + decoder->GetBatch(result->ptr, value_count); + decoder->Finalize(); + buffer.inc(buffer.len - decoder->BufferPtr().len); + return result; +} + +void StringColumnReader::PrepareDeltaLengthByteArray(ResizeableBuffer &buffer) { + idx_t value_count; + auto length_buffer = ReadDbpData(reader.allocator, buffer, value_count); + if (value_count == 0) { + // no values + byte_array_data = make_uniq(LogicalType::VARCHAR, nullptr); return; } - // read the defines/repeats - const auto all_valid = PrepareRead(read_now, define_out, repeat_out, result_offset); - // read the data according to the encoder - const auto define_ptr = all_valid ? nullptr : static_cast(define_out); - switch (encoding) { - case ColumnEncoding::DICTIONARY: - dictionary_decoder.Read(define_ptr, read_now, result, result_offset); - break; - case ColumnEncoding::DELTA_BINARY_PACKED: - delta_binary_packed_decoder.Read(define_ptr, read_now, result, result_offset); - break; - case ColumnEncoding::RLE: - rle_decoder.Read(define_ptr, read_now, result, result_offset); - break; - case ColumnEncoding::DELTA_LENGTH_BYTE_ARRAY: - delta_length_byte_array_decoder.Read(block, define_ptr, read_now, result, result_offset); - break; - case ColumnEncoding::DELTA_BYTE_ARRAY: - delta_byte_array_decoder.Read(define_ptr, read_now, result, result_offset); - break; - case ColumnEncoding::BYTE_STREAM_SPLIT: - byte_stream_split_decoder.Read(define_ptr, read_now, result, result_offset); - break; - default: - Plain(block, define_ptr, read_now, result_offset, result); - break; + auto length_data = reinterpret_cast(length_buffer->ptr); + byte_array_data = make_uniq(LogicalType::VARCHAR, value_count); + byte_array_count = value_count; + delta_offset = 0; + auto string_data = FlatVector::GetData(*byte_array_data); + for (idx_t i = 0; i < value_count; i++) { + auto str_len = length_data[i]; + buffer.available(str_len); + string_data[i] = StringVector::EmptyString(*byte_array_data, str_len); + auto result_data = string_data[i].GetDataWriteable(); + memcpy(result_data, buffer.ptr, length_data[i]); + buffer.inc(length_data[i]); + string_data[i].Finalize(); } - page_rows_available -= read_now; } -void ColumnReader::FinishRead(idx_t read_count) { - auto &trans = reinterpret_cast(*protocol->getTransport()); - chunk_read_offset = trans.GetLocation(); +void StringColumnReader::PrepareDeltaByteArray(ResizeableBuffer &buffer) { + idx_t prefix_count, suffix_count; + auto prefix_buffer = ReadDbpData(reader.allocator, buffer, prefix_count); + auto suffix_buffer = ReadDbpData(reader.allocator, buffer, suffix_count); + if (prefix_count != suffix_count) { + throw std::runtime_error("DELTA_BYTE_ARRAY - prefix and suffix counts are different - corrupt file?"); + } + if (prefix_count == 0) { + // no values + byte_array_data = make_uniq(LogicalType::VARCHAR, nullptr); + return; + } + auto prefix_data = reinterpret_cast(prefix_buffer->ptr); + auto suffix_data = reinterpret_cast(suffix_buffer->ptr); + byte_array_data = make_uniq(LogicalType::VARCHAR, prefix_count); + byte_array_count = prefix_count; + delta_offset = 0; + auto string_data = FlatVector::GetData(*byte_array_data); + for (idx_t i = 0; i < prefix_count; i++) { + auto str_len = prefix_data[i] + suffix_data[i]; + buffer.available(suffix_data[i]); + string_data[i] = StringVector::EmptyString(*byte_array_data, str_len); + auto result_data = string_data[i].GetDataWriteable(); + if (prefix_data[i] > 0) { + if (i == 0 || prefix_data[i] > string_data[i - 1].GetSize()) { + throw std::runtime_error("DELTA_BYTE_ARRAY - prefix is out of range - corrupt file?"); + } + memcpy(result_data, string_data[i - 1].GetData(), prefix_data[i]); + } + memcpy(result_data + prefix_data[i], buffer.ptr, suffix_data[i]); + buffer.inc(suffix_data[i]); + string_data[i].Finalize(); + } +} + +void StringColumnReader::DeltaByteArray(uint8_t *defines, idx_t num_values, parquet_filter_t &filter, + idx_t result_offset, Vector &result) { + if (!byte_array_data) { + throw std::runtime_error("Internal error - DeltaByteArray called but there was no byte_array_data set"); + } + auto result_ptr = FlatVector::GetData(result); + auto &result_mask = FlatVector::Validity(result); + auto string_data = FlatVector::GetData(*byte_array_data); + for (idx_t row_idx = 0; row_idx < num_values; row_idx++) { + if (HasDefines() && defines[row_idx + result_offset] != max_define) { + result_mask.SetInvalid(row_idx + result_offset); + continue; + } + if (filter.test(row_idx + result_offset)) { + if (delta_offset >= byte_array_count) { + throw IOException("DELTA_BYTE_ARRAY - length mismatch between values and byte array lengths (attempted " + "read of %d from %d entries) - corrupt file?", + delta_offset + 1, byte_array_count); + } + result_ptr[row_idx + result_offset] = string_data[delta_offset++]; + } else { + delta_offset++; + } + } + StringVector::AddHeapReference(result, *byte_array_data); +} + +class ParquetStringVectorBuffer : public VectorBuffer { +public: + explicit ParquetStringVectorBuffer(shared_ptr buffer_p) + : VectorBuffer(VectorBufferType::OPAQUE_BUFFER), buffer(std::move(buffer_p)) { + } + +private: + shared_ptr buffer; +}; + +void StringColumnReader::PlainReference(shared_ptr plain_data, Vector &result) { + StringVector::AddBuffer(result, make_buffer(std::move(plain_data))); +} + +string_t StringParquetValueConversion::PlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + auto &scr = reader.Cast(); + uint32_t str_len = scr.fixed_width_string_length == 0 ? plain_data.read() : scr.fixed_width_string_length; + plain_data.available(str_len); + auto plain_str = char_ptr_cast(plain_data.ptr); + auto actual_str_len = reader.Cast().VerifyString(plain_str, str_len); + auto ret_str = string_t(plain_str, actual_str_len); + plain_data.inc(str_len); + return ret_str; +} - group_rows_available -= read_count; +void StringParquetValueConversion::PlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + auto &scr = reader.Cast(); + uint32_t str_len = scr.fixed_width_string_length == 0 ? plain_data.read() : scr.fixed_width_string_length; + plain_data.inc(str_len); +} + +bool StringParquetValueConversion::PlainAvailable(const ByteBuffer &plain_data, const idx_t count) { + return true; } -idx_t ColumnReader::ReadInternal(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result) { +string_t StringParquetValueConversion::UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + return PlainRead(plain_data, reader); +} + +void StringParquetValueConversion::UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + PlainSkip(plain_data, reader); +} + +//===--------------------------------------------------------------------===// +// List Column Reader +//===--------------------------------------------------------------------===// +idx_t ListColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, + data_ptr_t repeat_out, Vector &result_out) { idx_t result_offset = 0; - auto to_read = num_values; - D_ASSERT(to_read <= STANDARD_VECTOR_SIZE); + auto result_ptr = FlatVector::GetData(result_out); + auto &result_mask = FlatVector::Validity(result_out); - while (to_read > 0) { - auto read_now = ReadPageHeaders(to_read); + if (pending_skips > 0) { + ApplyPendingSkips(pending_skips); + } - ReadData(read_now, define_out, repeat_out, result, result_offset); + D_ASSERT(ListVector::GetListSize(result_out) == 0); + // if an individual list is longer than STANDARD_VECTOR_SIZE we actually have to loop the child read to fill it + bool finished = false; + while (!finished) { + idx_t child_actual_num_values = 0; + + // check if we have any overflow from a previous read + if (overflow_child_count == 0) { + // we don't: read elements from the child reader + child_defines.zero(); + child_repeats.zero(); + // we don't know in advance how many values to read because of the beautiful repetition/definition setup + // we just read (up to) a vector from the child column, and see if we have read enough + // if we have not read enough, we read another vector + // if we have read enough, we leave any unhandled elements in the overflow vector for a subsequent read + auto child_req_num_values = + MinValue(STANDARD_VECTOR_SIZE, child_column_reader->GroupRowsAvailable()); + read_vector.ResetFromCache(read_cache); + child_actual_num_values = child_column_reader->Read(child_req_num_values, child_filter, child_defines_ptr, + child_repeats_ptr, read_vector); + } else { + // we do: use the overflow values + child_actual_num_values = overflow_child_count; + overflow_child_count = 0; + } - result_offset += read_now; - to_read -= read_now; + if (child_actual_num_values == 0) { + // no more elements available: we are done + break; + } + read_vector.Verify(child_actual_num_values); + idx_t current_chunk_offset = ListVector::GetListSize(result_out); + + // hard-won piece of code this, modify at your own risk + // the intuition is that we have to only collapse values into lists that are repeated *on this level* + // the rest is pretty much handed up as-is as a single-valued list or NULL + idx_t child_idx; + for (child_idx = 0; child_idx < child_actual_num_values; child_idx++) { + if (child_repeats_ptr[child_idx] == max_repeat) { + // value repeats on this level, append + D_ASSERT(result_offset > 0); + result_ptr[result_offset - 1].length++; + continue; + } + + if (result_offset >= num_values) { + // we ran out of output space + finished = true; + break; + } + if (child_defines_ptr[child_idx] >= max_define) { + // value has been defined down the stack, hence its NOT NULL + result_ptr[result_offset].offset = child_idx + current_chunk_offset; + result_ptr[result_offset].length = 1; + } else if (child_defines_ptr[child_idx] == max_define - 1) { + // empty list + result_ptr[result_offset].offset = child_idx + current_chunk_offset; + result_ptr[result_offset].length = 0; + } else { + // value is NULL somewhere up the stack + result_mask.SetInvalid(result_offset); + result_ptr[result_offset].offset = 0; + result_ptr[result_offset].length = 0; + } + + repeat_out[result_offset] = child_repeats_ptr[child_idx]; + define_out[result_offset] = child_defines_ptr[child_idx]; + + result_offset++; + } + // actually append the required elements to the child list + ListVector::Append(result_out, read_vector, child_idx); + + // we have read more values from the child reader than we can fit into the result for this read + // we have to pass everything from child_idx to child_actual_num_values into the next call + if (child_idx < child_actual_num_values && result_offset == num_values) { + read_vector.Slice(read_vector, child_idx, child_actual_num_values); + overflow_child_count = child_actual_num_values - child_idx; + read_vector.Verify(overflow_child_count); + + // move values in the child repeats and defines *backward* by child_idx + for (idx_t repdef_idx = 0; repdef_idx < overflow_child_count; repdef_idx++) { + child_defines_ptr[repdef_idx] = child_defines_ptr[child_idx + repdef_idx]; + child_repeats_ptr[repdef_idx] = child_repeats_ptr[child_idx + repdef_idx]; + } + } + } + result_out.Verify(result_offset); + return result_offset; +} + +ListColumnReader::ListColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, + idx_t schema_idx_p, idx_t max_define_p, idx_t max_repeat_p, + unique_ptr child_column_reader_p) + : ColumnReader(reader, std::move(type_p), schema_p, schema_idx_p, max_define_p, max_repeat_p), + child_column_reader(std::move(child_column_reader_p)), + read_cache(reader.allocator, ListType::GetChildType(Type())), read_vector(read_cache), overflow_child_count(0) { + + child_defines.resize(reader.allocator, STANDARD_VECTOR_SIZE); + child_repeats.resize(reader.allocator, STANDARD_VECTOR_SIZE); + child_defines_ptr = (uint8_t *)child_defines.ptr; + child_repeats_ptr = (uint8_t *)child_repeats.ptr; + + child_filter.set(); +} + +void ListColumnReader::ApplyPendingSkips(idx_t num_values) { + pending_skips -= num_values; + + auto define_out = unique_ptr(new uint8_t[num_values]); + auto repeat_out = unique_ptr(new uint8_t[num_values]); + + idx_t remaining = num_values; + idx_t read = 0; + + while (remaining) { + Vector result_out(Type()); + parquet_filter_t filter; + idx_t to_read = MinValue(remaining, STANDARD_VECTOR_SIZE); + read += Read(to_read, filter, define_out.get(), repeat_out.get(), result_out); + remaining -= to_read; + } + + if (read != num_values) { + throw InternalException("Not all skips done!"); + } +} + +//===--------------------------------------------------------------------===// +// Row NumberColumn Reader +//===--------------------------------------------------------------------===// +RowNumberColumnReader::RowNumberColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, + idx_t schema_idx_p, idx_t max_define_p, idx_t max_repeat_p) + : ColumnReader(reader, std::move(type_p), schema_p, schema_idx_p, max_define_p, max_repeat_p) { +} + +unique_ptr RowNumberColumnReader::Stats(idx_t row_group_idx_p, const vector &columns) { + auto stats = NumericStats::CreateUnknown(type); + auto &row_groups = reader.GetFileMetadata()->row_groups; + D_ASSERT(row_group_idx_p < row_groups.size()); + idx_t row_group_offset_min = 0; + for (idx_t i = 0; i < row_group_idx_p; i++) { + row_group_offset_min += row_groups[i].num_rows; } - FinishRead(num_values); + NumericStats::SetMin(stats, Value::BIGINT(UnsafeNumericCast(row_group_offset_min))); + NumericStats::SetMax( + stats, Value::BIGINT(UnsafeNumericCast(row_group_offset_min + row_groups[row_group_idx_p].num_rows))); + stats.Set(StatsInfo::CANNOT_HAVE_NULL_VALUES); + return stats.ToUnique(); +} + +void RowNumberColumnReader::InitializeRead(idx_t row_group_idx_p, const vector &columns, + TProtocol &protocol_p) { + row_group_offset = 0; + auto &row_groups = reader.GetFileMetadata()->row_groups; + for (idx_t i = 0; i < row_group_idx_p; i++) { + row_group_offset += row_groups[i].num_rows; + } +} + +idx_t RowNumberColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, + data_ptr_t repeat_out, Vector &result) { + + auto data_ptr = FlatVector::GetData(result); + for (idx_t i = 0; i < num_values; i++) { + data_ptr[i] = UnsafeNumericCast(row_group_offset++); + } return num_values; } -idx_t ColumnReader::Read(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result) { - BeginRead(define_out, repeat_out); - return ReadInternal(num_values, define_out, repeat_out, result); +//===--------------------------------------------------------------------===// +// Cast Column Reader +//===--------------------------------------------------------------------===// +CastColumnReader::CastColumnReader(unique_ptr child_reader_p, LogicalType target_type_p) + : ColumnReader(child_reader_p->Reader(), std::move(target_type_p), child_reader_p->Schema(), + child_reader_p->FileIdx(), child_reader_p->MaxDefine(), child_reader_p->MaxRepeat()), + child_reader(std::move(child_reader_p)) { + vector intermediate_types {child_reader->Type()}; + intermediate_chunk.Initialize(reader.allocator, intermediate_types); } -void ColumnReader::Select(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result_out, - const SelectionVector &sel, idx_t approved_tuple_count) { - if (SupportsDirectSelect() && approved_tuple_count < num_values) { - DirectSelect(num_values, define_out, repeat_out, result_out, sel, approved_tuple_count); - return; +unique_ptr CastColumnReader::Stats(idx_t row_group_idx_p, const vector &columns) { + // casting stats is not supported (yet) + return nullptr; +} + +void CastColumnReader::InitializeRead(idx_t row_group_idx_p, const vector &columns, + TProtocol &protocol_p) { + child_reader->InitializeRead(row_group_idx_p, columns, protocol_p); +} + +idx_t CastColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, + data_ptr_t repeat_out, Vector &result) { + intermediate_chunk.Reset(); + auto &intermediate_vector = intermediate_chunk.data[0]; + + auto amount = child_reader->Read(num_values, filter, define_out, repeat_out, intermediate_vector); + if (!filter.all()) { + // work-around for filters: set all values that are filtered to NULL to prevent the cast from failing on + // uninitialized data + intermediate_vector.Flatten(amount); + auto &validity = FlatVector::Validity(intermediate_vector); + for (idx_t i = 0; i < amount; i++) { + if (!filter.test(i)) { + validity.SetInvalid(i); + } + } } - Read(num_values, define_out, repeat_out, result_out); + string error_message; + bool all_succeeded = VectorOperations::DefaultTryCast(intermediate_vector, result, amount, &error_message); + if (!all_succeeded) { + string extended_error; + if (!reader.table_columns.empty()) { + // COPY .. FROM + extended_error = StringUtil::Format( + "In file \"%s\" the column \"%s\" has type %s, but we are trying to load it into column ", + reader.file_name, schema.name, intermediate_vector.GetType()); + if (FileIdx() < reader.table_columns.size()) { + extended_error += "\"" + reader.table_columns[FileIdx()] + "\" "; + } + extended_error += StringUtil::Format("with type %s.", result.GetType()); + extended_error += "\nThis means the Parquet schema does not match the schema of the table."; + extended_error += "\nPossible solutions:"; + extended_error += "\n* Insert by name instead of by position using \"INSERT INTO tbl BY NAME SELECT * FROM " + "read_parquet(...)\""; + extended_error += "\n* Manually specify which columns to insert using \"INSERT INTO tbl SELECT ... FROM " + "read_parquet(...)\""; + } else { + // read_parquet() with multiple files + extended_error = StringUtil::Format( + "In file \"%s\" the column \"%s\" has type %s, but we are trying to read it as type %s.", + reader.file_name, schema.name, intermediate_vector.GetType(), result.GetType()); + extended_error += + "\nThis can happen when reading multiple Parquet files. The schema information is taken from " + "the first Parquet file by default. Possible solutions:\n"; + extended_error += "* Enable the union_by_name=True option to combine the schema of all Parquet files " + "(duckdb.org/docs/data/multiple_files/combining_schemas)\n"; + extended_error += "* Use a COPY statement to automatically derive types from an existing table."; + } + throw ConversionException( + "In Parquet reader of file \"%s\": failed to cast column \"%s\" from type %s to %s: %s\n\n%s", + reader.file_name, schema.name, intermediate_vector.GetType(), result.GetType(), error_message, + extended_error); + } + return amount; } -void ColumnReader::DirectSelect(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result, - const SelectionVector &sel, idx_t approved_tuple_count) { - auto to_read = num_values; +void CastColumnReader::Skip(idx_t num_values) { + child_reader->Skip(num_values); +} - // prepare the first read if we haven't yet - BeginRead(define_out, repeat_out); - auto read_now = ReadPageHeaders(num_values); +idx_t CastColumnReader::GroupRowsAvailable() { + return child_reader->GroupRowsAvailable(); +} - // we can only push the filter into the decoder if we are reading the ENTIRE vector in one go - if (read_now == to_read && encoding == ColumnEncoding::PLAIN) { - const auto all_valid = PrepareRead(read_now, define_out, repeat_out, 0); - const auto define_ptr = all_valid ? nullptr : static_cast(define_out); - PlainSelect(block, define_ptr, read_now, result, sel, approved_tuple_count); +//===--------------------------------------------------------------------===// +// Expression Column Reader +//===--------------------------------------------------------------------===// +ExpressionColumnReader::ExpressionColumnReader(ClientContext &context, unique_ptr child_reader_p, + unique_ptr expr_p) + : ColumnReader(child_reader_p->Reader(), expr_p->return_type, child_reader_p->Schema(), child_reader_p->FileIdx(), + child_reader_p->MaxDefine(), child_reader_p->MaxRepeat()), + child_reader(std::move(child_reader_p)), expr(std::move(expr_p)), executor(context, expr.get()) { + vector intermediate_types {child_reader->Type()}; + intermediate_chunk.Initialize(reader.allocator, intermediate_types); +} - page_rows_available -= read_now; - FinishRead(num_values); - return; +unique_ptr ExpressionColumnReader::Stats(idx_t row_group_idx_p, const vector &columns) { + // expression stats is not supported (yet) + return nullptr; +} + +void ExpressionColumnReader::InitializeRead(idx_t row_group_idx_p, const vector &columns, + TProtocol &protocol_p) { + child_reader->InitializeRead(row_group_idx_p, columns, protocol_p); +} + +idx_t ExpressionColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, + data_ptr_t repeat_out, Vector &result) { + intermediate_chunk.Reset(); + auto &intermediate_vector = intermediate_chunk.data[0]; + + auto amount = child_reader->Read(num_values, filter, define_out, repeat_out, intermediate_vector); + if (!filter.all()) { + // work-around for filters: set all values that are filtered to NULL to prevent the cast from failing on + // uninitialized data + intermediate_vector.Flatten(amount); + auto &validity = FlatVector::Validity(intermediate_vector); + for (idx_t i = 0; i < amount; i++) { + if (!filter[i]) { + validity.SetInvalid(i); + } + } } - // fallback to regular read + filter - ReadInternal(num_values, define_out, repeat_out, result); + // Execute the expression + intermediate_chunk.SetCardinality(amount); + executor.ExecuteExpression(intermediate_chunk, result); + return amount; } -void ColumnReader::Filter(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result, - const TableFilter &filter, TableFilterState &filter_state, SelectionVector &sel, - idx_t &approved_tuple_count, bool is_first_filter) { - if (SupportsDirectFilter() && is_first_filter) { - DirectFilter(num_values, define_out, repeat_out, result, filter, filter_state, sel, approved_tuple_count); - return; +void ExpressionColumnReader::Skip(idx_t num_values) { + child_reader->Skip(num_values); +} + +idx_t ExpressionColumnReader::GroupRowsAvailable() { + return child_reader->GroupRowsAvailable(); +} + +//===--------------------------------------------------------------------===// +// Struct Column Reader +//===--------------------------------------------------------------------===// +StructColumnReader::StructColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, + idx_t schema_idx_p, idx_t max_define_p, idx_t max_repeat_p, + vector> child_readers_p) + : ColumnReader(reader, std::move(type_p), schema_p, schema_idx_p, max_define_p, max_repeat_p), + child_readers(std::move(child_readers_p)) { + D_ASSERT(type.InternalType() == PhysicalType::STRUCT); +} + +ColumnReader &StructColumnReader::GetChildReader(idx_t child_idx) { + if (!child_readers[child_idx]) { + throw InternalException("StructColumnReader::GetChildReader(%d) - but this child reader is not set", child_idx); } - Select(num_values, define_out, repeat_out, result, sel, approved_tuple_count); - ApplyFilter(result, filter, filter_state, num_values, sel, approved_tuple_count); + return *child_readers[child_idx].get(); } -void ColumnReader::DirectFilter(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result, - const TableFilter &filter, TableFilterState &filter_state, SelectionVector &sel, - idx_t &approved_tuple_count) { - auto to_read = num_values; +void StructColumnReader::InitializeRead(idx_t row_group_idx_p, const vector &columns, + TProtocol &protocol_p) { + for (auto &child : child_readers) { + if (!child) { + continue; + } + child->InitializeRead(row_group_idx_p, columns, protocol_p); + } +} - // prepare the first read if we haven't yet - BeginRead(define_out, repeat_out); - auto read_now = ReadPageHeaders(num_values, &filter, &filter_state); +idx_t StructColumnReader::Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, + data_ptr_t repeat_out, Vector &result) { + auto &struct_entries = StructVector::GetEntries(result); + D_ASSERT(StructType::GetChildTypes(Type()).size() == struct_entries.size()); - // we can only push the filter into the decoder if we are reading the ENTIRE vector in one go - if (encoding == ColumnEncoding::DICTIONARY && read_now == to_read && dictionary_decoder.HasFilter()) { - if (page_is_filtered_out) { - // the page has been filtered out entirely - skip - approved_tuple_count = 0; - } else { - // Push filter into dictionary directly - // read the defines/repeats - const auto all_valid = PrepareRead(read_now, define_out, repeat_out, 0); - const auto define_ptr = all_valid ? nullptr : static_cast(define_out); - dictionary_decoder.Filter(define_ptr, read_now, result, sel, approved_tuple_count); + if (pending_skips > 0) { + ApplyPendingSkips(pending_skips); + } + + optional_idx read_count; + for (idx_t i = 0; i < child_readers.size(); i++) { + auto &child = child_readers[i]; + auto &target_vector = *struct_entries[i]; + if (!child) { + // if we are not scanning this vector - set it to NULL + target_vector.SetVectorType(VectorType::CONSTANT_VECTOR); + ConstantVector::SetNull(target_vector, true); + continue; } - page_rows_available -= read_now; - FinishRead(num_values); - return; + auto child_num_values = child->Read(num_values, filter, define_out, repeat_out, target_vector); + if (!read_count.IsValid()) { + read_count = child_num_values; + } else if (read_count.GetIndex() != child_num_values) { + throw std::runtime_error("Struct child row count mismatch"); + } + } + if (!read_count.IsValid()) { + read_count = num_values; } - // fallback to regular read + filter - ReadInternal(num_values, define_out, repeat_out, result); - ApplyFilter(result, filter, filter_state, num_values, sel, approved_tuple_count); + // set the validity mask for this level + auto &validity = FlatVector::Validity(result); + for (idx_t i = 0; i < read_count.GetIndex(); i++) { + if (define_out[i] < max_define) { + validity.SetInvalid(i); + } + } + + return read_count.GetIndex(); } -void ColumnReader::ApplyFilter(Vector &v, const TableFilter &filter, TableFilterState &filter_state, idx_t scan_count, - SelectionVector &sel, idx_t &approved_tuple_count) { - UnifiedVectorFormat vdata; - v.ToUnifiedFormat(scan_count, vdata); - ColumnSegment::FilterSelection(sel, v, vdata, filter, filter_state, scan_count, approved_tuple_count); +void StructColumnReader::Skip(idx_t num_values) { + for (auto &child : child_readers) { + if (!child) { + continue; + } + child->Skip(num_values); + } } -void ColumnReader::Skip(idx_t num_values) { - pending_skips += num_values; +void StructColumnReader::RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge) { + for (auto &child : child_readers) { + if (!child) { + continue; + } + child->RegisterPrefetch(transport, allow_merge); + } } -void ColumnReader::ApplyPendingSkips(data_ptr_t define_out, data_ptr_t repeat_out) { - if (pending_skips == 0) { - return; +uint64_t StructColumnReader::TotalCompressedSize() { + uint64_t size = 0; + for (auto &child : child_readers) { + if (!child) { + continue; + } + size += child->TotalCompressedSize(); + } + return size; +} + +static bool TypeHasExactRowCount(const LogicalType &type) { + switch (type.id()) { + case LogicalTypeId::LIST: + case LogicalTypeId::MAP: + return false; + case LogicalTypeId::STRUCT: + for (auto &kv : StructType::GetChildTypes(type)) { + if (TypeHasExactRowCount(kv.second)) { + return true; + } + } + return false; + default: + return true; } - idx_t num_values = pending_skips; - pending_skips = 0; +} - auto to_skip = num_values; - // start reading but do not apply skips (we are skipping now) - BeginRead(nullptr, nullptr); +idx_t StructColumnReader::GroupRowsAvailable() { + for (idx_t i = 0; i < child_readers.size(); i++) { + if (TypeHasExactRowCount(child_readers[i]->Type())) { + return child_readers[i]->GroupRowsAvailable(); + } + } + return child_readers[0]->GroupRowsAvailable(); +} - while (to_skip > 0) { - auto skip_now = ReadPageHeaders(to_skip); - const auto all_valid = PrepareRead(skip_now, define_out, repeat_out, 0); +//===--------------------------------------------------------------------===// +// Decimal Column Reader +//===--------------------------------------------------------------------===// +template +struct DecimalParquetValueConversion { - const auto define_ptr = all_valid ? nullptr : static_cast(define_out); - switch (encoding) { - case ColumnEncoding::DICTIONARY: - dictionary_decoder.Skip(define_ptr, skip_now); - break; - case ColumnEncoding::DELTA_BINARY_PACKED: - delta_binary_packed_decoder.Skip(define_ptr, skip_now); - break; - case ColumnEncoding::RLE: - rle_decoder.Skip(define_ptr, skip_now); - break; - case ColumnEncoding::DELTA_LENGTH_BYTE_ARRAY: - delta_length_byte_array_decoder.Skip(define_ptr, skip_now); - break; - case ColumnEncoding::DELTA_BYTE_ARRAY: - delta_byte_array_decoder.Skip(define_ptr, skip_now); - break; - case ColumnEncoding::BYTE_STREAM_SPLIT: - byte_stream_split_decoder.Skip(define_ptr, skip_now); - break; - default: - PlainSkip(*block, define_ptr, skip_now); - break; + static DUCKDB_PHYSICAL_TYPE PlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + idx_t byte_len; + if (FIXED_LENGTH) { + byte_len = (idx_t)reader.Schema().type_length; /* sure, type length needs to be a signed int */ + } else { + byte_len = plain_data.read(); + } + plain_data.available(byte_len); + auto res = ParquetDecimalUtils::ReadDecimalValue(const_data_ptr_cast(plain_data.ptr), + byte_len, reader.Schema()); + + plain_data.inc(byte_len); + return res; + } + + static void PlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + uint32_t decimal_len = FIXED_LENGTH ? reader.Schema().type_length : plain_data.read(); + plain_data.inc(decimal_len); + } + + static bool PlainAvailable(const ByteBuffer &plain_data, const idx_t count) { + return true; + } + + static DUCKDB_PHYSICAL_TYPE UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + return PlainRead(plain_data, reader); + } + + static void UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + PlainSkip(plain_data, reader); + } +}; + +template +class DecimalColumnReader + : public TemplatedColumnReader> { + using BaseType = + TemplatedColumnReader>; + +public: + DecimalColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, // NOLINT + idx_t file_idx_p, idx_t max_define_p, idx_t max_repeat_p) + : TemplatedColumnReader>( + reader, std::move(type_p), schema_p, file_idx_p, max_define_p, max_repeat_p) {}; + +protected: +}; + +template +static unique_ptr CreateDecimalReaderInternal(ParquetReader &reader, const LogicalType &type_p, + const SchemaElement &schema_p, idx_t file_idx_p, + idx_t max_define, idx_t max_repeat) { + switch (type_p.InternalType()) { + case PhysicalType::INT16: + return make_uniq>(reader, type_p, schema_p, file_idx_p, max_define, + max_repeat); + case PhysicalType::INT32: + return make_uniq>(reader, type_p, schema_p, file_idx_p, max_define, + max_repeat); + case PhysicalType::INT64: + return make_uniq>(reader, type_p, schema_p, file_idx_p, max_define, + max_repeat); + case PhysicalType::INT128: + return make_uniq>(reader, type_p, schema_p, file_idx_p, max_define, + max_repeat); + case PhysicalType::DOUBLE: + return make_uniq>(reader, type_p, schema_p, file_idx_p, max_define, + max_repeat); + default: + throw InternalException("Unrecognized type for Decimal"); + } +} + +template <> +double ParquetDecimalUtils::ReadDecimalValue(const_data_ptr_t pointer, idx_t size, + const duckdb_parquet::SchemaElement &schema_ele) { + double res = 0; + bool positive = (*pointer & 0x80) == 0; + for (idx_t i = 0; i < size; i += 8) { + auto byte_size = MinValue(sizeof(uint64_t), size - i); + uint64_t input = 0; + auto res_ptr = reinterpret_cast(&input); + for (idx_t k = 0; k < byte_size; k++) { + auto byte = pointer[i + k]; + res_ptr[sizeof(uint64_t) - k - 1] = positive ? byte : byte ^ 0xFF; } - page_rows_available -= skip_now; - to_skip -= skip_now; + res *= double(NumericLimits::Maximum()) + 1; + res += static_cast(input); + } + if (!positive) { + res += 1; + res /= pow(10, schema_ele.scale); + return -res; } - FinishRead(num_values); + res /= pow(10, schema_ele.scale); + return res; } +unique_ptr ParquetDecimalUtils::CreateReader(ParquetReader &reader, const LogicalType &type_p, + const SchemaElement &schema_p, idx_t file_idx_p, + idx_t max_define, idx_t max_repeat) { + if (schema_p.__isset.type_length) { + return CreateDecimalReaderInternal(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else { + return CreateDecimalReaderInternal(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } +} + +//===--------------------------------------------------------------------===// +// UUID Column Reader +//===--------------------------------------------------------------------===// +struct UUIDValueConversion { + static hugeint_t ReadParquetUUID(const_data_ptr_t input) { + hugeint_t result; + result.lower = 0; + uint64_t unsigned_upper = 0; + for (idx_t i = 0; i < sizeof(uint64_t); i++) { + unsigned_upper <<= 8; + unsigned_upper += input[i]; + } + for (idx_t i = sizeof(uint64_t); i < sizeof(hugeint_t); i++) { + result.lower <<= 8; + result.lower += input[i]; + } + result.upper = static_cast(unsigned_upper ^ (uint64_t(1) << 63)); + return result; + } + + static hugeint_t PlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.available(sizeof(hugeint_t)); + return UnsafePlainRead(plain_data, reader); + } + + static void PlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.inc(sizeof(hugeint_t)); + } + + static bool PlainAvailable(const ByteBuffer &plain_data, const idx_t count) { + return plain_data.check_available(count * sizeof(hugeint_t)); + } + + static hugeint_t UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + auto res = ReadParquetUUID(const_data_ptr_cast(plain_data.ptr)); + plain_data.unsafe_inc(sizeof(hugeint_t)); + return res; + } + + static void UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.unsafe_inc(sizeof(hugeint_t)); + } +}; + +class UUIDColumnReader : public TemplatedColumnReader { + +public: + UUIDColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t file_idx_p, + idx_t max_define_p, idx_t max_repeat_p) + : TemplatedColumnReader(reader, std::move(type_p), schema_p, file_idx_p, + max_define_p, max_repeat_p) {}; +}; + +//===--------------------------------------------------------------------===// +// Interval Column Reader +//===--------------------------------------------------------------------===// +struct IntervalValueConversion { + static constexpr const idx_t PARQUET_INTERVAL_SIZE = 12; + + static interval_t ReadParquetInterval(const_data_ptr_t input) { + interval_t result; + result.months = Load(input); + result.days = Load(input + sizeof(uint32_t)); + result.micros = int64_t(Load(input + sizeof(uint32_t) * 2)) * 1000; + return result; + } + + static interval_t PlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.available(PARQUET_INTERVAL_SIZE); + return UnsafePlainRead(plain_data, reader); + } + + static void PlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.inc(PARQUET_INTERVAL_SIZE); + } + + static bool PlainAvailable(const ByteBuffer &plain_data, const idx_t count) { + return plain_data.check_available(count * PARQUET_INTERVAL_SIZE); + } + + static interval_t UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + auto res = ReadParquetInterval(const_data_ptr_cast(plain_data.ptr)); + plain_data.unsafe_inc(PARQUET_INTERVAL_SIZE); + return res; + } + + static void UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.unsafe_inc(PARQUET_INTERVAL_SIZE); + } +}; + +class IntervalColumnReader : public TemplatedColumnReader { + +public: + IntervalColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t file_idx_p, + idx_t max_define_p, idx_t max_repeat_p) + : TemplatedColumnReader(reader, std::move(type_p), schema_p, file_idx_p, + max_define_p, max_repeat_p) {}; +}; + //===--------------------------------------------------------------------===// // Create Column Reader //===--------------------------------------------------------------------===// template -unique_ptr CreateDecimalReader(ParquetReader &reader, const ParquetColumnSchema &schema) { - switch (schema.type.InternalType()) { +unique_ptr CreateDecimalReader(ParquetReader &reader, const LogicalType &type_p, + const SchemaElement &schema_p, idx_t file_idx_p, idx_t max_define, + idx_t max_repeat) { + switch (type_p.InternalType()) { case PhysicalType::INT16: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case PhysicalType::INT32: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case PhysicalType::INT64: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); default: throw NotImplementedException("Unimplemented internal type for CreateDecimalReader"); } } -unique_ptr ColumnReader::CreateReader(ParquetReader &reader, const ParquetColumnSchema &schema) { - switch (schema.type.id()) { +unique_ptr ColumnReader::CreateReader(ParquetReader &reader, const LogicalType &type_p, + const SchemaElement &schema_p, idx_t file_idx_p, idx_t max_define, + idx_t max_repeat) { + switch (type_p.id()) { case LogicalTypeId::BOOLEAN: - return make_uniq(reader, schema); + return make_uniq(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::UTINYINT: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::USMALLINT: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::UINTEGER: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::UBIGINT: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::TINYINT: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::SMALLINT: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::INTEGER: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::BIGINT: - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::FLOAT: - if (schema.type_info == ParquetExtraTypeInfo::FLOAT16) { - return make_uniq>(reader, schema); - } - return make_uniq>>(reader, schema); + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::DOUBLE: - if (schema.type_info == ParquetExtraTypeInfo::DECIMAL_BYTE_ARRAY) { - return ParquetDecimalUtils::CreateReader(reader, schema); + switch (schema_p.type) { + case Type::BYTE_ARRAY: + case Type::FIXED_LEN_BYTE_ARRAY: + return ParquetDecimalUtils::CreateReader(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + default: + return make_uniq>>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); } - return make_uniq>>(reader, schema); case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIMESTAMP_TZ: - switch (schema.type_info) { - case ParquetExtraTypeInfo::IMPALA_TIMESTAMP: - return make_uniq>(reader, schema); - case ParquetExtraTypeInfo::UNIT_MS: - return make_uniq>(reader, schema); - case ParquetExtraTypeInfo::UNIT_MICROS: - return make_uniq>(reader, - schema); - case ParquetExtraTypeInfo::UNIT_NS: - return make_uniq>(reader, schema); + switch (schema_p.type) { + case Type::INT96: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + case Type::INT64: + if (schema_p.__isset.logicalType && schema_p.logicalType.__isset.TIMESTAMP) { + if (schema_p.logicalType.TIMESTAMP.unit.__isset.MILLIS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIMESTAMP.unit.__isset.MICROS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIMESTAMP.unit.__isset.NANOS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } + } else if (schema_p.__isset.converted_type) { + switch (schema_p.converted_type) { + case ConvertedType::TIMESTAMP_MICROS: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + case ConvertedType::TIMESTAMP_MILLIS: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + default: + break; + } + } default: - throw InternalException("TIMESTAMP requires type info"); + break; } + break; case LogicalTypeId::TIMESTAMP_NS: - switch (schema.type_info) { - case ParquetExtraTypeInfo::IMPALA_TIMESTAMP: - return make_uniq>(reader, schema); - case ParquetExtraTypeInfo::UNIT_MS: - return make_uniq>(reader, - schema); - case ParquetExtraTypeInfo::UNIT_MICROS: - return make_uniq>(reader, - schema); - case ParquetExtraTypeInfo::UNIT_NS: - return make_uniq>(reader, - schema); + switch (schema_p.type) { + case Type::INT96: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + case Type::INT64: + if (schema_p.__isset.logicalType && schema_p.logicalType.__isset.TIMESTAMP) { + if (schema_p.logicalType.TIMESTAMP.unit.__isset.MILLIS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIMESTAMP.unit.__isset.MICROS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIMESTAMP.unit.__isset.NANOS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } + } else if (schema_p.__isset.converted_type) { + switch (schema_p.converted_type) { + case ConvertedType::TIMESTAMP_MICROS: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + case ConvertedType::TIMESTAMP_MILLIS: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + default: + break; + } + } default: - throw InternalException("TIMESTAMP_NS requires type info"); + break; } + break; case LogicalTypeId::DATE: - return make_uniq>(reader, schema); + return make_uniq>(reader, type_p, schema_p, file_idx_p, + max_define, max_repeat); case LogicalTypeId::TIME: - switch (schema.type_info) { - case ParquetExtraTypeInfo::UNIT_MS: - return make_uniq>(reader, schema); - case ParquetExtraTypeInfo::UNIT_MICROS: - return make_uniq>(reader, schema); - case ParquetExtraTypeInfo::UNIT_NS: - return make_uniq>(reader, schema); - default: - throw InternalException("TIME requires type info"); + if (schema_p.__isset.logicalType && schema_p.logicalType.__isset.TIME) { + if (schema_p.logicalType.TIME.unit.__isset.MILLIS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIME.unit.__isset.MICROS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIME.unit.__isset.NANOS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } + } else if (schema_p.__isset.converted_type) { + switch (schema_p.converted_type) { + case ConvertedType::TIME_MICROS: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + case ConvertedType::TIME_MILLIS: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + default: + break; + } } + throw NotImplementedException("Unsupported time encoding in Parquet file"); case LogicalTypeId::TIME_TZ: - switch (schema.type_info) { - case ParquetExtraTypeInfo::UNIT_MS: - return make_uniq>(reader, schema); - case ParquetExtraTypeInfo::UNIT_MICROS: - return make_uniq>(reader, schema); - case ParquetExtraTypeInfo::UNIT_NS: - return make_uniq>(reader, schema); - default: - throw InternalException("TIME_TZ requires type info"); + if (schema_p.__isset.logicalType && schema_p.logicalType.__isset.TIME) { + if (schema_p.logicalType.TIME.unit.__isset.MILLIS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIME.unit.__isset.MICROS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } else if (schema_p.logicalType.TIME.unit.__isset.NANOS) { + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + } + } else if (schema_p.__isset.converted_type) { + switch (schema_p.converted_type) { + case ConvertedType::TIME_MICROS: + return make_uniq>( + reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + default: + break; + } } + throw NotImplementedException("Unsupported time encoding in Parquet file"); case LogicalTypeId::BLOB: case LogicalTypeId::VARCHAR: - return make_uniq(reader, schema); + return make_uniq(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::DECIMAL: // we have to figure out what kind of int we need - switch (schema.type_info) { - case ParquetExtraTypeInfo::DECIMAL_INT32: - return CreateDecimalReader(reader, schema); - case ParquetExtraTypeInfo::DECIMAL_INT64: - return CreateDecimalReader(reader, schema); - case ParquetExtraTypeInfo::DECIMAL_BYTE_ARRAY: - return ParquetDecimalUtils::CreateReader(reader, schema); + switch (schema_p.type) { + case Type::INT32: + return CreateDecimalReader(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + case Type::INT64: + return CreateDecimalReader(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); + case Type::BYTE_ARRAY: + case Type::FIXED_LEN_BYTE_ARRAY: + return ParquetDecimalUtils::CreateReader(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); default: throw NotImplementedException("Unrecognized Parquet type for Decimal"); } break; case LogicalTypeId::UUID: - return make_uniq(reader, schema); + return make_uniq(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::INTERVAL: - return make_uniq(reader, schema); + return make_uniq(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); case LogicalTypeId::SQLNULL: - return make_uniq(reader, schema); + return make_uniq(reader, type_p, schema_p, file_idx_p, max_define, max_repeat); default: break; } - throw NotImplementedException(schema.type.ToString()); + throw NotImplementedException(type_p.ToString()); } } // namespace duckdb diff --git a/src/duckdb/extension/parquet/column_writer.cpp b/src/duckdb/extension/parquet/column_writer.cpp index 1279e08b4..b4c33ef41 100644 --- a/src/duckdb/extension/parquet/column_writer.cpp +++ b/src/duckdb/extension/parquet/column_writer.cpp @@ -2,18 +2,14 @@ #include "duckdb.hpp" #include "geo_parquet.hpp" +#include "parquet_dbp_encoder.hpp" +#include "parquet_dlba_encoder.hpp" #include "parquet_rle_bp_decoder.hpp" +#include "parquet_rle_bp_encoder.hpp" #include "parquet_bss_encoder.hpp" #include "parquet_statistics.hpp" #include "parquet_writer.hpp" -#include "writer/array_column_writer.hpp" -#include "writer/boolean_column_writer.hpp" -#include "writer/decimal_column_writer.hpp" -#include "writer/enum_column_writer.hpp" -#include "writer/list_column_writer.hpp" -#include "writer/primitive_column_writer.hpp" -#include "writer/struct_column_writer.hpp" -#include "writer/templated_column_writer.hpp" +#ifndef DUCKDB_AMALGAMATION #include "duckdb/common/exception.hpp" #include "duckdb/common/operator/comparison_operators.hpp" #include "duckdb/common/serializer/buffered_file_writer.hpp" @@ -23,13 +19,16 @@ #include "duckdb/common/types/hugeint.hpp" #include "duckdb/common/types/time.hpp" #include "duckdb/common/types/timestamp.hpp" +#include "duckdb/common/types/uhugeint.hpp" #include "duckdb/execution/expression_executor.hpp" +#endif #include "brotli/encode.h" #include "lz4.hpp" #include "miniz_wrapper.hpp" #include "snappy.h" #include "zstd.h" +#include "zstd/common/xxhash.hpp" #include @@ -48,7 +47,7 @@ using duckdb_parquet::PageType; using ParquetRowGroup = duckdb_parquet::RowGroup; using duckdb_parquet::Type; -constexpr uint16_t ColumnWriter::PARQUET_DEFINE_VALID; +#define PARQUET_DEFINE_VALID 65535 //===--------------------------------------------------------------------===// // ColumnWriterStatistics @@ -76,29 +75,99 @@ string ColumnWriterStatistics::GetMaxValue() { return string(); } -bool ColumnWriterStatistics::CanHaveNaN() { - return false; +//===--------------------------------------------------------------------===// +// RleBpEncoder +//===--------------------------------------------------------------------===// +RleBpEncoder::RleBpEncoder(uint32_t bit_width) + : byte_width((bit_width + 7) / 8), byte_count(idx_t(-1)), run_count(idx_t(-1)) { } -bool ColumnWriterStatistics::HasNaN() { - return false; +// we always RLE everything (for now) +void RleBpEncoder::BeginPrepare(uint32_t first_value) { + byte_count = 0; + run_count = 1; + current_run_count = 1; + last_value = first_value; +} + +void RleBpEncoder::FinishRun() { + // last value, or value has changed + // write out the current run + byte_count += ParquetDecodeUtils::GetVarintSize(current_run_count << 1) + byte_width; + current_run_count = 1; + run_count++; +} + +void RleBpEncoder::PrepareValue(uint32_t value) { + if (value != last_value) { + FinishRun(); + last_value = value; + } else { + current_run_count++; + } +} + +void RleBpEncoder::FinishPrepare() { + FinishRun(); +} + +idx_t RleBpEncoder::GetByteCount() { + D_ASSERT(byte_count != idx_t(-1)); + return byte_count; +} + +void RleBpEncoder::BeginWrite(WriteStream &writer, uint32_t first_value) { + // start the RLE runs + last_value = first_value; + current_run_count = 1; } -bool ColumnWriterStatistics::MinIsExact() { - return true; +void RleBpEncoder::WriteRun(WriteStream &writer) { + // write the header of the run + ParquetDecodeUtils::VarintEncode(current_run_count << 1, writer); + // now write the value + D_ASSERT(last_value >> (byte_width * 8) == 0); + switch (byte_width) { + case 1: + writer.Write(last_value); + break; + case 2: + writer.Write(last_value); + break; + case 3: + writer.Write(last_value & 0xFF); + writer.Write((last_value >> 8) & 0xFF); + writer.Write((last_value >> 16) & 0xFF); + break; + case 4: + writer.Write(last_value); + break; + default: + throw InternalException("unsupported byte width for RLE encoding"); + } + current_run_count = 1; +} + +void RleBpEncoder::WriteValue(WriteStream &writer, uint32_t value) { + if (value != last_value) { + WriteRun(writer); + last_value = value; + } else { + current_run_count++; + } } -bool ColumnWriterStatistics::MaxIsExact() { - return true; +void RleBpEncoder::FinishWrite(WriteStream &writer) { + WriteRun(writer); } //===--------------------------------------------------------------------===// // ColumnWriter //===--------------------------------------------------------------------===// -ColumnWriter::ColumnWriter(ParquetWriter &writer, const ParquetColumnSchema &column_schema, - vector schema_path_p, bool can_have_nulls) - : writer(writer), column_schema(column_schema), schema_path(std::move(schema_path_p)), - can_have_nulls(can_have_nulls) { +ColumnWriter::ColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, idx_t max_repeat, + idx_t max_define, bool can_have_nulls) + : writer(writer), schema_idx(schema_idx), schema_path(std::move(schema_path_p)), max_repeat(max_repeat), + max_define(max_define), can_have_nulls(can_have_nulls) { } ColumnWriter::~ColumnWriter() { } @@ -107,7 +176,7 @@ ColumnWriterState::~ColumnWriterState() { } void ColumnWriter::CompressPage(MemoryStream &temp_writer, size_t &compressed_size, data_ptr_t &compressed_data, - AllocatedData &compressed_buf) { + unique_ptr &compressed_buf) { switch (writer.GetCodec()) { case CompressionCodec::UNCOMPRESSED: compressed_size = temp_writer.GetPosition(); @@ -116,7 +185,7 @@ void ColumnWriter::CompressPage(MemoryStream &temp_writer, size_t &compressed_si case CompressionCodec::SNAPPY: { compressed_size = duckdb_snappy::MaxCompressedLength(temp_writer.GetPosition()); - compressed_buf = BufferAllocator::Get(writer.GetContext()).Allocate(compressed_size); + compressed_buf = unique_ptr(new data_t[compressed_size]); duckdb_snappy::RawCompress(const_char_ptr_cast(temp_writer.GetData()), temp_writer.GetPosition(), char_ptr_cast(compressed_buf.get()), &compressed_size); compressed_data = compressed_buf.get(); @@ -125,7 +194,7 @@ void ColumnWriter::CompressPage(MemoryStream &temp_writer, size_t &compressed_si } case CompressionCodec::LZ4_RAW: { compressed_size = duckdb_lz4::LZ4_compressBound(UnsafeNumericCast(temp_writer.GetPosition())); - compressed_buf = BufferAllocator::Get(writer.GetContext()).Allocate(compressed_size); + compressed_buf = unique_ptr(new data_t[compressed_size]); compressed_size = duckdb_lz4::LZ4_compress_default( const_char_ptr_cast(temp_writer.GetData()), char_ptr_cast(compressed_buf.get()), UnsafeNumericCast(temp_writer.GetPosition()), UnsafeNumericCast(compressed_size)); @@ -135,7 +204,7 @@ void ColumnWriter::CompressPage(MemoryStream &temp_writer, size_t &compressed_si case CompressionCodec::GZIP: { MiniZStream s; compressed_size = s.MaxCompressedLength(temp_writer.GetPosition()); - compressed_buf = BufferAllocator::Get(writer.GetContext()).Allocate(compressed_size); + compressed_buf = unique_ptr(new data_t[compressed_size]); s.Compress(const_char_ptr_cast(temp_writer.GetData()), temp_writer.GetPosition(), char_ptr_cast(compressed_buf.get()), &compressed_size); compressed_data = compressed_buf.get(); @@ -143,7 +212,7 @@ void ColumnWriter::CompressPage(MemoryStream &temp_writer, size_t &compressed_si } case CompressionCodec::ZSTD: { compressed_size = duckdb_zstd::ZSTD_compressBound(temp_writer.GetPosition()); - compressed_buf = BufferAllocator::Get(writer.GetContext()).Allocate(compressed_size); + compressed_buf = unique_ptr(new data_t[compressed_size]); compressed_size = duckdb_zstd::ZSTD_compress((void *)compressed_buf.get(), compressed_size, (const void *)temp_writer.GetData(), temp_writer.GetPosition(), UnsafeNumericCast(writer.CompressionLevel())); @@ -151,12 +220,15 @@ void ColumnWriter::CompressPage(MemoryStream &temp_writer, size_t &compressed_si break; } case CompressionCodec::BROTLI: { + compressed_size = duckdb_brotli::BrotliEncoderMaxCompressedSize(temp_writer.GetPosition()); - compressed_buf = BufferAllocator::Get(writer.GetContext()).Allocate(compressed_size); + compressed_buf = unique_ptr(new data_t[compressed_size]); + duckdb_brotli::BrotliEncoderCompress(BROTLI_DEFAULT_QUALITY, BROTLI_DEFAULT_WINDOW, BROTLI_DEFAULT_MODE, temp_writer.GetPosition(), temp_writer.GetData(), &compressed_size, compressed_buf.get()); compressed_data = compressed_buf.get(); + break; } default: @@ -175,60 +247,1478 @@ void ColumnWriter::HandleRepeatLevels(ColumnWriterState &state, ColumnWriterStat // no repeat levels without a parent node return; } - while (state.repetition_levels.size() < parent->repetition_levels.size()) { - state.repetition_levels.push_back(parent->repetition_levels[state.repetition_levels.size()]); + while (state.repetition_levels.size() < parent->repetition_levels.size()) { + state.repetition_levels.push_back(parent->repetition_levels[state.repetition_levels.size()]); + } +} + +void ColumnWriter::HandleDefineLevels(ColumnWriterState &state, ColumnWriterState *parent, const ValidityMask &validity, + const idx_t count, const uint16_t define_value, const uint16_t null_value) const { + if (parent) { + // parent node: inherit definition level from the parent + idx_t vector_index = 0; + while (state.definition_levels.size() < parent->definition_levels.size()) { + idx_t current_index = state.definition_levels.size(); + if (parent->definition_levels[current_index] != PARQUET_DEFINE_VALID) { + state.definition_levels.push_back(parent->definition_levels[current_index]); + } else if (validity.RowIsValid(vector_index)) { + state.definition_levels.push_back(define_value); + } else { + if (!can_have_nulls) { + throw IOException("Parquet writer: map key column is not allowed to contain NULL values"); + } + state.null_count++; + state.definition_levels.push_back(null_value); + } + if (parent->is_empty.empty() || !parent->is_empty[current_index]) { + vector_index++; + } + } + } else { + // no parent: set definition levels only from this validity mask + for (idx_t i = 0; i < count; i++) { + const auto is_null = !validity.RowIsValid(i); + state.definition_levels.emplace_back(is_null ? null_value : define_value); + state.null_count += is_null; + } + if (!can_have_nulls && state.null_count != 0) { + throw IOException("Parquet writer: map key column is not allowed to contain NULL values"); + } + } +} + +class ColumnWriterPageState { +public: + virtual ~ColumnWriterPageState() { + } + +public: + template + TARGET &Cast() { + DynamicCastCheck(this); + return reinterpret_cast(*this); + } + template + const TARGET &Cast() const { + D_ASSERT(dynamic_cast(this)); + return reinterpret_cast(*this); + } +}; + +struct PageInformation { + idx_t offset = 0; + idx_t row_count = 0; + idx_t empty_count = 0; + idx_t null_count = 0; + idx_t estimated_page_size = 0; +}; + +struct PageWriteInformation { + PageHeader page_header; + unique_ptr temp_writer; + unique_ptr page_state; + idx_t write_page_idx = 0; + idx_t write_count = 0; + idx_t max_write_count = 0; + size_t compressed_size; + data_ptr_t compressed_data; + unique_ptr compressed_buf; +}; + +class BasicColumnWriterState : public ColumnWriterState { +public: + BasicColumnWriterState(duckdb_parquet::RowGroup &row_group, idx_t col_idx) + : row_group(row_group), col_idx(col_idx) { + page_info.emplace_back(); + } + ~BasicColumnWriterState() override = default; + + duckdb_parquet::RowGroup &row_group; + idx_t col_idx; + vector page_info; + vector write_info; + unique_ptr stats_state; + idx_t current_page = 0; + + unique_ptr bloom_filter; +}; + +//===--------------------------------------------------------------------===// +// BasicColumnWriter +// A base class for writing all non-compound types (ex. numerics, strings) +//===--------------------------------------------------------------------===// +class BasicColumnWriter : public ColumnWriter { +public: + BasicColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path, idx_t max_repeat, + idx_t max_define, bool can_have_nulls) + : ColumnWriter(writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls) { + } + + ~BasicColumnWriter() override = default; + + //! We limit the uncompressed page size to 100MB + //! The max size in Parquet is 2GB, but we choose a more conservative limit + static constexpr const idx_t MAX_UNCOMPRESSED_PAGE_SIZE = 100000000; + //! Dictionary pages must be below 2GB. Unlike data pages, there's only one dictionary page. + //! For this reason we go with a much higher, but still a conservative upper bound of 1GB; + static constexpr const idx_t MAX_UNCOMPRESSED_DICT_PAGE_SIZE = 1e9; + //! If the dictionary has this many entries, we stop creating the dictionary + static constexpr const idx_t DICTIONARY_ANALYZE_THRESHOLD = 1e4; + //! The maximum size a key entry in an RLE page takes + static constexpr const idx_t MAX_DICTIONARY_KEY_SIZE = sizeof(uint32_t); + //! The size of encoding the string length + static constexpr const idx_t STRING_LENGTH_SIZE = sizeof(uint32_t); + +public: + unique_ptr InitializeWriteState(duckdb_parquet::RowGroup &row_group) override; + void Prepare(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count) override; + void BeginWrite(ColumnWriterState &state) override; + void Write(ColumnWriterState &state, Vector &vector, idx_t count) override; + void FinalizeWrite(ColumnWriterState &state) override; + +protected: + static void WriteLevels(WriteStream &temp_writer, const unsafe_vector &levels, idx_t max_value, + idx_t start_offset, idx_t count); + + virtual duckdb_parquet::Encoding::type GetEncoding(BasicColumnWriterState &state); + + void NextPage(BasicColumnWriterState &state); + void FlushPage(BasicColumnWriterState &state); + + //! Initializes the state used to track statistics during writing. Only used for scalar types. + virtual unique_ptr InitializeStatsState(); + + //! Initialize the writer for a specific page. Only used for scalar types. + virtual unique_ptr InitializePageState(BasicColumnWriterState &state, idx_t page_idx); + + //! Flushes the writer for a specific page. Only used for scalar types. + virtual void FlushPageState(WriteStream &temp_writer, ColumnWriterPageState *state); + + //! Retrieves the row size of a vector at the specified location. Only used for scalar types. + virtual idx_t GetRowSize(const Vector &vector, const idx_t index, const BasicColumnWriterState &state) const; + //! Writes a (subset of a) vector to the specified serializer. Only used for scalar types. + virtual void WriteVector(WriteStream &temp_writer, ColumnWriterStatistics *stats, ColumnWriterPageState *page_state, + Vector &vector, idx_t chunk_start, idx_t chunk_end) = 0; + + virtual bool HasDictionary(BasicColumnWriterState &state_p) { + return false; + } + //! The number of elements in the dictionary + virtual idx_t DictionarySize(BasicColumnWriterState &state_p); + void WriteDictionary(BasicColumnWriterState &state, unique_ptr temp_writer, idx_t row_count); + virtual void FlushDictionary(BasicColumnWriterState &state, ColumnWriterStatistics *stats); + + void SetParquetStatistics(BasicColumnWriterState &state, duckdb_parquet::ColumnChunk &column); + void RegisterToRowGroup(duckdb_parquet::RowGroup &row_group); +}; + +unique_ptr BasicColumnWriter::InitializeWriteState(duckdb_parquet::RowGroup &row_group) { + auto result = make_uniq(row_group, row_group.columns.size()); + RegisterToRowGroup(row_group); + return std::move(result); +} + +void BasicColumnWriter::RegisterToRowGroup(duckdb_parquet::RowGroup &row_group) { + duckdb_parquet::ColumnChunk column_chunk; + column_chunk.__isset.meta_data = true; + column_chunk.meta_data.codec = writer.GetCodec(); + column_chunk.meta_data.path_in_schema = schema_path; + column_chunk.meta_data.num_values = 0; + column_chunk.meta_data.type = writer.GetType(schema_idx); + row_group.columns.push_back(std::move(column_chunk)); +} + +unique_ptr BasicColumnWriter::InitializePageState(BasicColumnWriterState &state, + idx_t page_idx) { + return nullptr; +} + +void BasicColumnWriter::FlushPageState(WriteStream &temp_writer, ColumnWriterPageState *state) { +} + +void BasicColumnWriter::Prepare(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + auto &col_chunk = state.row_group.columns[state.col_idx]; + + idx_t start = 0; + idx_t vcount = parent ? parent->definition_levels.size() - state.definition_levels.size() : count; + idx_t parent_index = state.definition_levels.size(); + auto &validity = FlatVector::Validity(vector); + HandleRepeatLevels(state, parent, count, max_repeat); + HandleDefineLevels(state, parent, validity, count, max_define, max_define - 1); + + idx_t vector_index = 0; + reference page_info_ref = state.page_info.back(); + for (idx_t i = start; i < vcount; i++) { + auto &page_info = page_info_ref.get(); + page_info.row_count++; + col_chunk.meta_data.num_values++; + if (parent && !parent->is_empty.empty() && parent->is_empty[parent_index + i]) { + page_info.empty_count++; + continue; + } + if (validity.RowIsValid(vector_index)) { + page_info.estimated_page_size += GetRowSize(vector, vector_index, state); + if (page_info.estimated_page_size >= MAX_UNCOMPRESSED_PAGE_SIZE) { + PageInformation new_info; + new_info.offset = page_info.offset + page_info.row_count; + state.page_info.push_back(new_info); + page_info_ref = state.page_info.back(); + } + } else { + page_info.null_count++; + } + vector_index++; + } +} + +duckdb_parquet::Encoding::type BasicColumnWriter::GetEncoding(BasicColumnWriterState &state) { + return Encoding::PLAIN; +} + +void BasicColumnWriter::BeginWrite(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + + // set up the page write info + state.stats_state = InitializeStatsState(); + for (idx_t page_idx = 0; page_idx < state.page_info.size(); page_idx++) { + auto &page_info = state.page_info[page_idx]; + if (page_info.row_count == 0) { + D_ASSERT(page_idx + 1 == state.page_info.size()); + state.page_info.erase_at(page_idx); + break; + } + PageWriteInformation write_info; + // set up the header + auto &hdr = write_info.page_header; + hdr.compressed_page_size = 0; + hdr.uncompressed_page_size = 0; + hdr.type = PageType::DATA_PAGE; + hdr.__isset.data_page_header = true; + + hdr.data_page_header.num_values = UnsafeNumericCast(page_info.row_count); + hdr.data_page_header.encoding = GetEncoding(state); + hdr.data_page_header.definition_level_encoding = Encoding::RLE; + hdr.data_page_header.repetition_level_encoding = Encoding::RLE; + + write_info.temp_writer = make_uniq( + Allocator::Get(writer.GetContext()), + MaxValue(NextPowerOfTwo(page_info.estimated_page_size), MemoryStream::DEFAULT_INITIAL_CAPACITY)); + write_info.write_count = page_info.empty_count; + write_info.max_write_count = page_info.row_count; + write_info.page_state = InitializePageState(state, page_idx); + + write_info.compressed_size = 0; + write_info.compressed_data = nullptr; + + state.write_info.push_back(std::move(write_info)); + } + + // start writing the first page + NextPage(state); +} + +void BasicColumnWriter::WriteLevels(WriteStream &temp_writer, const unsafe_vector &levels, idx_t max_value, + idx_t offset, idx_t count) { + if (levels.empty() || count == 0) { + return; + } + + // write the levels using the RLE-BP encoding + auto bit_width = RleBpDecoder::ComputeBitWidth((max_value)); + RleBpEncoder rle_encoder(bit_width); + + rle_encoder.BeginPrepare(levels[offset]); + for (idx_t i = offset + 1; i < offset + count; i++) { + rle_encoder.PrepareValue(levels[i]); + } + rle_encoder.FinishPrepare(); + + // start off by writing the byte count as a uint32_t + temp_writer.Write(rle_encoder.GetByteCount()); + rle_encoder.BeginWrite(temp_writer, levels[offset]); + for (idx_t i = offset + 1; i < offset + count; i++) { + rle_encoder.WriteValue(temp_writer, levels[i]); + } + rle_encoder.FinishWrite(temp_writer); +} + +void BasicColumnWriter::NextPage(BasicColumnWriterState &state) { + if (state.current_page > 0) { + // need to flush the current page + FlushPage(state); + } + if (state.current_page >= state.write_info.size()) { + state.current_page = state.write_info.size() + 1; + return; + } + auto &page_info = state.page_info[state.current_page]; + auto &write_info = state.write_info[state.current_page]; + state.current_page++; + + auto &temp_writer = *write_info.temp_writer; + + // write the repetition levels + WriteLevels(temp_writer, state.repetition_levels, max_repeat, page_info.offset, page_info.row_count); + + // write the definition levels + WriteLevels(temp_writer, state.definition_levels, max_define, page_info.offset, page_info.row_count); +} + +void BasicColumnWriter::FlushPage(BasicColumnWriterState &state) { + D_ASSERT(state.current_page > 0); + if (state.current_page > state.write_info.size()) { + return; + } + + // compress the page info + auto &write_info = state.write_info[state.current_page - 1]; + auto &temp_writer = *write_info.temp_writer; + auto &hdr = write_info.page_header; + + FlushPageState(temp_writer, write_info.page_state.get()); + + // now that we have finished writing the data we know the uncompressed size + if (temp_writer.GetPosition() > idx_t(NumericLimits::Maximum())) { + throw InternalException("Parquet writer: %d uncompressed page size out of range for type integer", + temp_writer.GetPosition()); + } + hdr.uncompressed_page_size = UnsafeNumericCast(temp_writer.GetPosition()); + + // compress the data + CompressPage(temp_writer, write_info.compressed_size, write_info.compressed_data, write_info.compressed_buf); + hdr.compressed_page_size = UnsafeNumericCast(write_info.compressed_size); + D_ASSERT(hdr.uncompressed_page_size > 0); + D_ASSERT(hdr.compressed_page_size > 0); + + if (write_info.compressed_buf) { + // if the data has been compressed, we no longer need the uncompressed data + D_ASSERT(write_info.compressed_buf.get() == write_info.compressed_data); + write_info.temp_writer.reset(); + } +} + +unique_ptr BasicColumnWriter::InitializeStatsState() { + return make_uniq(); +} + +idx_t BasicColumnWriter::GetRowSize(const Vector &vector, const idx_t index, + const BasicColumnWriterState &state) const { + throw InternalException("GetRowSize unsupported for struct/list column writers"); +} + +void BasicColumnWriter::Write(ColumnWriterState &state_p, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + + idx_t remaining = count; + idx_t offset = 0; + while (remaining > 0) { + auto &write_info = state.write_info[state.current_page - 1]; + if (!write_info.temp_writer) { + throw InternalException("Writes are not correctly aligned!?"); + } + auto &temp_writer = *write_info.temp_writer; + idx_t write_count = MinValue(remaining, write_info.max_write_count - write_info.write_count); + D_ASSERT(write_count > 0); + + WriteVector(temp_writer, state.stats_state.get(), write_info.page_state.get(), vector, offset, + offset + write_count); + + write_info.write_count += write_count; + if (write_info.write_count == write_info.max_write_count) { + NextPage(state); + } + offset += write_count; + remaining -= write_count; + } +} + +void BasicColumnWriter::SetParquetStatistics(BasicColumnWriterState &state, duckdb_parquet::ColumnChunk &column_chunk) { + if (!state.stats_state) { + return; + } + if (max_repeat == 0) { + column_chunk.meta_data.statistics.null_count = NumericCast(state.null_count); + column_chunk.meta_data.statistics.__isset.null_count = true; + column_chunk.meta_data.__isset.statistics = true; + } + // set min/max/min_value/max_value + // this code is not going to win any beauty contests, but well + auto min = state.stats_state->GetMin(); + if (!min.empty()) { + column_chunk.meta_data.statistics.min = std::move(min); + column_chunk.meta_data.statistics.__isset.min = true; + column_chunk.meta_data.__isset.statistics = true; + } + auto max = state.stats_state->GetMax(); + if (!max.empty()) { + column_chunk.meta_data.statistics.max = std::move(max); + column_chunk.meta_data.statistics.__isset.max = true; + column_chunk.meta_data.__isset.statistics = true; + } + if (state.stats_state->HasStats()) { + column_chunk.meta_data.statistics.min_value = state.stats_state->GetMinValue(); + column_chunk.meta_data.statistics.__isset.min_value = true; + column_chunk.meta_data.__isset.statistics = true; + + column_chunk.meta_data.statistics.max_value = state.stats_state->GetMaxValue(); + column_chunk.meta_data.statistics.__isset.max_value = true; + column_chunk.meta_data.__isset.statistics = true; + } + if (HasDictionary(state)) { + column_chunk.meta_data.statistics.distinct_count = UnsafeNumericCast(DictionarySize(state)); + column_chunk.meta_data.statistics.__isset.distinct_count = true; + column_chunk.meta_data.__isset.statistics = true; + } + for (const auto &write_info : state.write_info) { + // only care about data page encodings, data_page_header.encoding is meaningless for dict + if (write_info.page_header.type != PageType::DATA_PAGE && + write_info.page_header.type != PageType::DATA_PAGE_V2) { + continue; + } + column_chunk.meta_data.encodings.push_back(write_info.page_header.data_page_header.encoding); + } +} + +void BasicColumnWriter::FinalizeWrite(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + auto &column_chunk = state.row_group.columns[state.col_idx]; + + // flush the last page (if any remains) + FlushPage(state); + + auto &column_writer = writer.GetWriter(); + auto start_offset = column_writer.GetTotalWritten(); + // flush the dictionary + if (HasDictionary(state)) { + column_chunk.meta_data.statistics.distinct_count = UnsafeNumericCast(DictionarySize(state)); + column_chunk.meta_data.statistics.__isset.distinct_count = true; + column_chunk.meta_data.dictionary_page_offset = UnsafeNumericCast(column_writer.GetTotalWritten()); + column_chunk.meta_data.__isset.dictionary_page_offset = true; + FlushDictionary(state, state.stats_state.get()); + } + + // record the start position of the pages for this column + column_chunk.meta_data.data_page_offset = 0; + SetParquetStatistics(state, column_chunk); + + // write the individual pages to disk + idx_t total_uncompressed_size = 0; + for (auto &write_info : state.write_info) { + // set the data page offset whenever we see the *first* data page + if (column_chunk.meta_data.data_page_offset == 0 && (write_info.page_header.type == PageType::DATA_PAGE || + write_info.page_header.type == PageType::DATA_PAGE_V2)) { + column_chunk.meta_data.data_page_offset = UnsafeNumericCast(column_writer.GetTotalWritten()); + ; + } + D_ASSERT(write_info.page_header.uncompressed_page_size > 0); + auto header_start_offset = column_writer.GetTotalWritten(); + writer.Write(write_info.page_header); + // total uncompressed size in the column chunk includes the header size (!) + total_uncompressed_size += column_writer.GetTotalWritten() - header_start_offset; + total_uncompressed_size += write_info.page_header.uncompressed_page_size; + writer.WriteData(write_info.compressed_data, write_info.compressed_size); + } + column_chunk.meta_data.total_compressed_size = + UnsafeNumericCast(column_writer.GetTotalWritten() - start_offset); + column_chunk.meta_data.total_uncompressed_size = UnsafeNumericCast(total_uncompressed_size); + state.row_group.total_byte_size += column_chunk.meta_data.total_uncompressed_size; + + if (state.bloom_filter) { + writer.BufferBloomFilter(state.col_idx, std::move(state.bloom_filter)); + } + // which row group is this? +} + +void BasicColumnWriter::FlushDictionary(BasicColumnWriterState &state, ColumnWriterStatistics *stats) { + throw InternalException("This page does not have a dictionary"); +} + +idx_t BasicColumnWriter::DictionarySize(BasicColumnWriterState &state) { + throw InternalException("This page does not have a dictionary"); +} + +void BasicColumnWriter::WriteDictionary(BasicColumnWriterState &state, unique_ptr temp_writer, + idx_t row_count) { + D_ASSERT(temp_writer); + D_ASSERT(temp_writer->GetPosition() > 0); + + // write the dictionary page header + PageWriteInformation write_info; + // set up the header + auto &hdr = write_info.page_header; + hdr.uncompressed_page_size = UnsafeNumericCast(temp_writer->GetPosition()); + hdr.type = PageType::DICTIONARY_PAGE; + hdr.__isset.dictionary_page_header = true; + + hdr.dictionary_page_header.encoding = Encoding::PLAIN; + hdr.dictionary_page_header.is_sorted = false; + hdr.dictionary_page_header.num_values = UnsafeNumericCast(row_count); + + write_info.temp_writer = std::move(temp_writer); + write_info.write_count = 0; + write_info.max_write_count = 0; + + // compress the contents of the dictionary page + CompressPage(*write_info.temp_writer, write_info.compressed_size, write_info.compressed_data, + write_info.compressed_buf); + hdr.compressed_page_size = UnsafeNumericCast(write_info.compressed_size); + + // insert the dictionary page as the first page to write for this column + state.write_info.insert(state.write_info.begin(), std::move(write_info)); +} + +//===--------------------------------------------------------------------===// +// Standard Column Writer +//===--------------------------------------------------------------------===// +template +class NumericStatisticsState : public ColumnWriterStatistics { +public: + NumericStatisticsState() : min(NumericLimits::Maximum()), max(NumericLimits::Minimum()) { + } + + T min; + T max; + +public: + bool HasStats() override { + return min <= max; + } + + string GetMin() override { + return NumericLimits::IsSigned() ? GetMinValue() : string(); + } + string GetMax() override { + return NumericLimits::IsSigned() ? GetMaxValue() : string(); + } + string GetMinValue() override { + return HasStats() ? string(char_ptr_cast(&min), sizeof(T)) : string(); + } + string GetMaxValue() override { + return HasStats() ? string(char_ptr_cast(&max), sizeof(T)) : string(); + } +}; + +struct BaseParquetOperator { + template + static void WriteToStream(const TGT &input, WriteStream &ser) { + ser.WriteData(const_data_ptr_cast(&input), sizeof(TGT)); + } + + template + static uint64_t XXHash64(const TGT &target_value) { + return duckdb_zstd::XXH64(&target_value, sizeof(target_value), 0); + } + + template + static unique_ptr InitializeStats() { + return nullptr; + } + + template + static void HandleStats(ColumnWriterStatistics *stats, TGT target_value) { + } + + template + static idx_t GetRowSize(const Vector &, idx_t) { + return sizeof(TGT); + } +}; + +struct ParquetCastOperator : public BaseParquetOperator { + template + static TGT Operation(SRC input) { + return TGT(input); + } + template + static unique_ptr InitializeStats() { + return make_uniq>(); + } + + template + static void HandleStats(ColumnWriterStatistics *stats, TGT target_value) { + auto &numeric_stats = (NumericStatisticsState &)*stats; + if (LessThan::Operation(target_value, numeric_stats.min)) { + numeric_stats.min = target_value; + } + if (GreaterThan::Operation(target_value, numeric_stats.max)) { + numeric_stats.max = target_value; + } + } +}; + +struct ParquetTimestampNSOperator : public ParquetCastOperator { + template + static TGT Operation(SRC input) { + return TGT(input); + } +}; + +struct ParquetTimestampSOperator : public ParquetCastOperator { + template + static TGT Operation(SRC input) { + return Timestamp::FromEpochSecondsPossiblyInfinite(input).value; + } +}; + +class StringStatisticsState : public ColumnWriterStatistics { + static constexpr const idx_t MAX_STRING_STATISTICS_SIZE = 10000; + +public: + StringStatisticsState() : has_stats(false), values_too_big(false), min(), max() { + } + + bool has_stats; + bool values_too_big; + string min; + string max; + +public: + bool HasStats() override { + return has_stats; + } + + void Update(const string_t &val) { + if (values_too_big) { + return; + } + auto str_len = val.GetSize(); + if (str_len > MAX_STRING_STATISTICS_SIZE) { + // we avoid gathering stats when individual string values are too large + // this is because the statistics are copied into the Parquet file meta data in uncompressed format + // ideally we avoid placing several mega or giga-byte long strings there + // we put a threshold of 10KB, if we see strings that exceed this threshold we avoid gathering stats + values_too_big = true; + has_stats = false; + min = string(); + max = string(); + return; + } + if (!has_stats || LessThan::Operation(val, string_t(min))) { + min = val.GetString(); + } + if (!has_stats || GreaterThan::Operation(val, string_t(max))) { + max = val.GetString(); + } + has_stats = true; + } + + string GetMin() override { + return GetMinValue(); + } + string GetMax() override { + return GetMaxValue(); + } + string GetMinValue() override { + return HasStats() ? min : string(); + } + string GetMaxValue() override { + return HasStats() ? max : string(); + } +}; + +struct ParquetStringOperator : public BaseParquetOperator { + template + static TGT Operation(SRC input) { + return input; + } + + template + static unique_ptr InitializeStats() { + return make_uniq(); + } + + template + static void HandleStats(ColumnWriterStatistics *stats, TGT target_value) { + auto &string_stats = stats->Cast(); + string_stats.Update(target_value); + } + + template + static void WriteToStream(const TGT &target_value, WriteStream &ser) { + ser.Write(target_value.GetSize()); + ser.WriteData(const_data_ptr_cast(target_value.GetData()), target_value.GetSize()); + } + + template + static uint64_t XXHash64(const TGT &target_value) { + return duckdb_zstd::XXH64(target_value.GetData(), target_value.GetSize(), 0); + } + + template + static idx_t GetRowSize(const Vector &vector, idx_t index) { + return FlatVector::GetData(vector)[index].GetSize(); + } +}; + +struct ParquetIntervalTargetType { + static constexpr const idx_t PARQUET_INTERVAL_SIZE = 12; + data_t bytes[PARQUET_INTERVAL_SIZE]; +}; + +struct ParquetIntervalOperator : public BaseParquetOperator { + template + static TGT Operation(SRC input) { + + if (input.days < 0 || input.months < 0 || input.micros < 0) { + throw IOException("Parquet files do not support negative intervals"); + } + TGT result; + Store(input.months, result.bytes); + Store(input.days, result.bytes + sizeof(uint32_t)); + Store(input.micros / 1000, result.bytes + sizeof(uint32_t) * 2); + return result; + } + + template + static void WriteToStream(const TGT &target_value, WriteStream &ser) { + ser.WriteData(target_value.bytes, ParquetIntervalTargetType::PARQUET_INTERVAL_SIZE); + } + + template + static uint64_t XXHash64(const TGT &target_value) { + return duckdb_zstd::XXH64(target_value.bytes, ParquetIntervalTargetType::PARQUET_INTERVAL_SIZE, 0); + } +}; + +struct ParquetUUIDTargetType { + static constexpr const idx_t PARQUET_UUID_SIZE = 16; + data_t bytes[PARQUET_UUID_SIZE]; +}; + +struct ParquetUUIDOperator : public BaseParquetOperator { + template + static TGT Operation(SRC input) { + TGT result; + uint64_t high_bytes = input.upper ^ (int64_t(1) << 63); + uint64_t low_bytes = input.lower; + for (idx_t i = 0; i < sizeof(uint64_t); i++) { + auto shift_count = (sizeof(uint64_t) - i - 1) * 8; + result.bytes[i] = (high_bytes >> shift_count) & 0xFF; + } + for (idx_t i = 0; i < sizeof(uint64_t); i++) { + auto shift_count = (sizeof(uint64_t) - i - 1) * 8; + result.bytes[sizeof(uint64_t) + i] = (low_bytes >> shift_count) & 0xFF; + } + return result; + } + + template + static void WriteToStream(const TGT &target_value, WriteStream &ser) { + ser.WriteData(target_value.bytes, ParquetUUIDTargetType::PARQUET_UUID_SIZE); + } + + template + static uint64_t XXHash64(const TGT &target_value) { + return duckdb_zstd::XXH64(target_value.bytes, ParquetUUIDTargetType::PARQUET_UUID_SIZE, 0); + } +}; + +struct ParquetTimeTZOperator : public BaseParquetOperator { + template + static TGT Operation(SRC input) { + return input.time().micros; + } +}; + +struct ParquetHugeintOperator : public BaseParquetOperator { + template + static TGT Operation(SRC input) { + return Hugeint::Cast(input); + } + + template + static unique_ptr InitializeStats() { + return make_uniq(); + } + + template + static void HandleStats(ColumnWriterStatistics *stats, TGT target_value) { + } +}; + +struct ParquetUhugeintOperator : public BaseParquetOperator { + template + static TGT Operation(SRC input) { + return Uhugeint::Cast(input); + } + + template + static unique_ptr InitializeStats() { + return make_uniq(); + } + + template + static void HandleStats(ColumnWriterStatistics *stats, TGT target_value) { + } +}; + +template +static void TemplatedWritePlain(Vector &col, ColumnWriterStatistics *stats, const idx_t chunk_start, + const idx_t chunk_end, const ValidityMask &mask, WriteStream &ser) { + + const auto *ptr = FlatVector::GetData(col); + for (idx_t r = chunk_start; r < chunk_end; r++) { + if (!mask.RowIsValid(r)) { + continue; + } + TGT target_value = OP::template Operation(ptr[r]); + OP::template HandleStats(stats, target_value); + OP::template WriteToStream(target_value, ser); + } +} + +template +class StandardColumnWriterState : public BasicColumnWriterState { +public: + StandardColumnWriterState(duckdb_parquet::RowGroup &row_group, idx_t col_idx) + : BasicColumnWriterState(row_group, col_idx) { + } + ~StandardColumnWriterState() override = default; + + // analysis state for integer values for DELTA_BINARY_PACKED/DELTA_LENGTH_BYTE_ARRAY + idx_t total_value_count = 0; + idx_t total_string_size = 0; + uint32_t key_bit_width = 0; + + unordered_map dictionary; + duckdb_parquet::Encoding::type encoding; +}; + +template +class StandardWriterPageState : public ColumnWriterPageState { +public: + explicit StandardWriterPageState(const idx_t total_value_count, const idx_t total_string_size, + Encoding::type encoding_p, const unordered_map &dictionary_p) + : encoding(encoding_p), dbp_initialized(false), dbp_encoder(total_value_count), dlba_initialized(false), + dlba_encoder(total_value_count, total_string_size), bss_encoder(total_value_count, sizeof(TGT)), + dictionary(dictionary_p), dict_written_value(false), + dict_bit_width(RleBpDecoder::ComputeBitWidth(dictionary.size())), dict_encoder(dict_bit_width) { + } + duckdb_parquet::Encoding::type encoding; + + bool dbp_initialized; + DbpEncoder dbp_encoder; + + bool dlba_initialized; + DlbaEncoder dlba_encoder; + + BssEncoder bss_encoder; + + const unordered_map &dictionary; + bool dict_written_value; + uint32_t dict_bit_width; + RleBpEncoder dict_encoder; +}; + +namespace dbp_encoder { + +template +void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const T &first_value) { + throw InternalException("Can't write type to DELTA_BINARY_PACKED column"); +} + +template <> +void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const int64_t &first_value) { + encoder.BeginWrite(writer, first_value); +} + +template <> +void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const int32_t &first_value) { + BeginWrite(encoder, writer, UnsafeNumericCast(first_value)); +} + +template <> +void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const uint64_t &first_value) { + encoder.BeginWrite(writer, UnsafeNumericCast(first_value)); +} + +template <> +void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const uint32_t &first_value) { + BeginWrite(encoder, writer, UnsafeNumericCast(first_value)); +} + +template +void WriteValue(DbpEncoder &encoder, WriteStream &writer, const T &value) { + throw InternalException("Can't write type to DELTA_BINARY_PACKED column"); +} + +template <> +void WriteValue(DbpEncoder &encoder, WriteStream &writer, const int64_t &value) { + encoder.WriteValue(writer, value); +} + +template <> +void WriteValue(DbpEncoder &encoder, WriteStream &writer, const int32_t &value) { + WriteValue(encoder, writer, UnsafeNumericCast(value)); +} + +template <> +void WriteValue(DbpEncoder &encoder, WriteStream &writer, const uint64_t &value) { + encoder.WriteValue(writer, UnsafeNumericCast(value)); +} + +template <> +void WriteValue(DbpEncoder &encoder, WriteStream &writer, const uint32_t &value) { + WriteValue(encoder, writer, UnsafeNumericCast(value)); +} + +} // namespace dbp_encoder + +namespace dlba_encoder { + +template +void BeginWrite(DlbaEncoder &encoder, WriteStream &writer, const T &first_value) { + throw InternalException("Can't write type to DELTA_LENGTH_BYTE_ARRAY column"); +} + +template <> +void BeginWrite(DlbaEncoder &encoder, WriteStream &writer, const string_t &first_value) { + encoder.BeginWrite(writer, first_value); +} + +template +void WriteValue(DlbaEncoder &encoder, WriteStream &writer, const T &value) { + throw InternalException("Can't write type to DELTA_LENGTH_BYTE_ARRAY column"); +} + +template <> +void WriteValue(DlbaEncoder &encoder, WriteStream &writer, const string_t &value) { + encoder.WriteValue(writer, value); +} + +// helpers to get size from strings +template +static idx_t GetDlbaStringSize(const SRC &src_value) { + return 0; +} + +template <> +idx_t GetDlbaStringSize(const string_t &src_value) { + return src_value.GetSize(); +} + +} // namespace dlba_encoder + +namespace bss_encoder { + +template +void WriteValue(BssEncoder &encoder, const T &value) { + throw InternalException("Can't write type to BYTE_STREAM_SPLIT column"); +} + +template <> +void WriteValue(BssEncoder &encoder, const float &value) { + encoder.WriteValue(value); +} + +template <> +void WriteValue(BssEncoder &encoder, const double &value) { + encoder.WriteValue(value); +} + +} // namespace bss_encoder + +template +class StandardColumnWriter : public BasicColumnWriter { +public: + StandardColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, // NOLINT + idx_t max_repeat, idx_t max_define, bool can_have_nulls) + : BasicColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, can_have_nulls) { + } + ~StandardColumnWriter() override = default; + +public: + unique_ptr InitializeWriteState(duckdb_parquet::RowGroup &row_group) override { + auto result = make_uniq>(row_group, row_group.columns.size()); + result->encoding = Encoding::RLE_DICTIONARY; + RegisterToRowGroup(row_group); + return std::move(result); + } + + unique_ptr InitializePageState(BasicColumnWriterState &state_p, idx_t page_idx) override { + auto &state = state_p.Cast>(); + const auto &page_info = state_p.page_info[page_idx]; + auto result = make_uniq>( + page_info.row_count - (page_info.empty_count + page_info.null_count), state.total_string_size, + state.encoding, state.dictionary); + return std::move(result); + } + + void FlushPageState(WriteStream &temp_writer, ColumnWriterPageState *state_p) override { + auto &page_state = state_p->Cast>(); + switch (page_state.encoding) { + case Encoding::DELTA_BINARY_PACKED: + if (!page_state.dbp_initialized) { + dbp_encoder::BeginWrite(page_state.dbp_encoder, temp_writer, 0); + } + page_state.dbp_encoder.FinishWrite(temp_writer); + break; + case Encoding::RLE_DICTIONARY: + D_ASSERT(page_state.dict_bit_width != 0); + if (!page_state.dict_written_value) { + // all values are null + // just write the bit width + temp_writer.Write(page_state.dict_bit_width); + return; + } + page_state.dict_encoder.FinishWrite(temp_writer); + break; + case Encoding::DELTA_LENGTH_BYTE_ARRAY: + if (!page_state.dlba_initialized) { + dlba_encoder::BeginWrite(page_state.dlba_encoder, temp_writer, string_t("")); + } + page_state.dlba_encoder.FinishWrite(temp_writer); + break; + case Encoding::BYTE_STREAM_SPLIT: + page_state.bss_encoder.FinishWrite(temp_writer); + break; + case Encoding::PLAIN: + break; + default: + throw InternalException("Unknown encoding"); + } + } + + Encoding::type GetEncoding(BasicColumnWriterState &state_p) override { + auto &state = state_p.Cast>(); + return state.encoding; + } + + bool HasAnalyze() override { + return true; + } + + void Analyze(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) override { + auto &state = state_p.Cast>(); + + auto data_ptr = FlatVector::GetData(vector); + idx_t vector_index = 0; + uint32_t new_value_index = state.dictionary.size(); + + const bool check_parent_empty = parent && !parent->is_empty.empty(); + const idx_t parent_index = state.definition_levels.size(); + + const idx_t vcount = + check_parent_empty ? parent->definition_levels.size() - state.definition_levels.size() : count; + + const auto &validity = FlatVector::Validity(vector); + + for (idx_t i = 0; i < vcount; i++) { + if (check_parent_empty && parent->is_empty[parent_index + i]) { + continue; + } + if (validity.RowIsValid(vector_index)) { + const auto &src_value = data_ptr[vector_index]; + if (state.dictionary.size() <= writer.DictionarySizeLimit()) { + if (state.dictionary.find(src_value) == state.dictionary.end()) { + state.dictionary[src_value] = new_value_index; + new_value_index++; + } + } + state.total_value_count++; + state.total_string_size += dlba_encoder::GetDlbaStringSize(src_value); + } + vector_index++; + } + } + + void FinalizeAnalyze(ColumnWriterState &state_p) override { + const auto type = writer.GetType(schema_idx); + + auto &state = state_p.Cast>(); + if (state.dictionary.size() == 0 || state.dictionary.size() > writer.DictionarySizeLimit()) { + if (writer.GetParquetVersion() == ParquetVersion::V1) { + // Can't do the cool stuff for V1 + state.encoding = Encoding::PLAIN; + } else { + // If we aren't doing dictionary encoding, these encodings are virtually always better than PLAIN + switch (type) { + case Type::type::INT32: + case Type::type::INT64: + state.encoding = Encoding::DELTA_BINARY_PACKED; + break; + case Type::type::BYTE_ARRAY: + state.encoding = Encoding::DELTA_LENGTH_BYTE_ARRAY; + break; + case Type::type::FLOAT: + case Type::type::DOUBLE: + state.encoding = Encoding::BYTE_STREAM_SPLIT; + break; + default: + state.encoding = Encoding::PLAIN; + } + } + state.dictionary.clear(); + } else { + state.key_bit_width = RleBpDecoder::ComputeBitWidth(state.dictionary.size()); + } + } + + unique_ptr InitializeStatsState() override { + return OP::template InitializeStats(); + } + + bool HasDictionary(BasicColumnWriterState &state_p) override { + auto &state = state_p.Cast>(); + return state.encoding == Encoding::RLE_DICTIONARY; + } + + idx_t DictionarySize(BasicColumnWriterState &state_p) override { + auto &state = state_p.Cast>(); + return state.dictionary.size(); + } + + void WriteVector(WriteStream &temp_writer, ColumnWriterStatistics *stats, ColumnWriterPageState *page_state_p, + Vector &input_column, idx_t chunk_start, idx_t chunk_end) override { + auto &page_state = page_state_p->Cast>(); + + const auto &mask = FlatVector::Validity(input_column); + const auto *data_ptr = FlatVector::GetData(input_column); + + switch (page_state.encoding) { + case Encoding::RLE_DICTIONARY: { + for (idx_t r = chunk_start; r < chunk_end; r++) { + if (!mask.RowIsValid(r)) { + continue; + } + auto &src_val = data_ptr[r]; + auto value_index = page_state.dictionary.at(src_val); + if (!page_state.dict_written_value) { + // first value + // write the bit-width as a one-byte entry + temp_writer.Write(page_state.dict_bit_width); + // now begin writing the actual value + page_state.dict_encoder.BeginWrite(temp_writer, value_index); + page_state.dict_written_value = true; + } else { + page_state.dict_encoder.WriteValue(temp_writer, value_index); + } + } + break; + } + case Encoding::DELTA_BINARY_PACKED: { + idx_t r = chunk_start; + if (!page_state.dbp_initialized) { + // find first non-null value + for (; r < chunk_end; r++) { + if (!mask.RowIsValid(r)) { + continue; + } + const TGT target_value = OP::template Operation(data_ptr[r]); + OP::template HandleStats(stats, target_value); + dbp_encoder::BeginWrite(page_state.dbp_encoder, temp_writer, target_value); + page_state.dbp_initialized = true; + r++; // skip over + break; + } + } + + for (; r < chunk_end; r++) { + if (!mask.RowIsValid(r)) { + continue; + } + const TGT target_value = OP::template Operation(data_ptr[r]); + OP::template HandleStats(stats, target_value); + dbp_encoder::WriteValue(page_state.dbp_encoder, temp_writer, target_value); + } + break; + } + case Encoding::DELTA_LENGTH_BYTE_ARRAY: { + idx_t r = chunk_start; + if (!page_state.dlba_initialized) { + // find first non-null value + for (; r < chunk_end; r++) { + if (!mask.RowIsValid(r)) { + continue; + } + const TGT target_value = OP::template Operation(data_ptr[r]); + OP::template HandleStats(stats, target_value); + dlba_encoder::BeginWrite(page_state.dlba_encoder, temp_writer, target_value); + page_state.dlba_initialized = true; + r++; // skip over + break; + } + } + + for (; r < chunk_end; r++) { + if (!mask.RowIsValid(r)) { + continue; + } + const TGT target_value = OP::template Operation(data_ptr[r]); + OP::template HandleStats(stats, target_value); + dlba_encoder::WriteValue(page_state.dlba_encoder, temp_writer, target_value); + } + break; + } + case Encoding::BYTE_STREAM_SPLIT: { + for (idx_t r = chunk_start; r < chunk_end; r++) { + if (!mask.RowIsValid(r)) { + continue; + } + const TGT target_value = OP::template Operation(data_ptr[r]); + OP::template HandleStats(stats, target_value); + bss_encoder::WriteValue(page_state.bss_encoder, target_value); + } + break; + } + case Encoding::PLAIN: { + D_ASSERT(page_state.encoding == Encoding::PLAIN); + TemplatedWritePlain(input_column, stats, chunk_start, chunk_end, mask, temp_writer); + break; + } + default: + throw InternalException("Unknown encoding"); + } + } + + void FlushDictionary(BasicColumnWriterState &state_p, ColumnWriterStatistics *stats) override { + auto &state = state_p.Cast>(); + + D_ASSERT(state.encoding == Encoding::RLE_DICTIONARY); + + // first we need to sort the values in index order + auto values = vector(state.dictionary.size()); + for (const auto &entry : state.dictionary) { + values[entry.second] = entry.first; + } + + state.bloom_filter = + make_uniq(state.dictionary.size(), writer.BloomFilterFalsePositiveRatio()); + + // first write the contents of the dictionary page to a temporary buffer + auto temp_writer = make_uniq( + Allocator::Get(writer.GetContext()), MaxValue(NextPowerOfTwo(state.dictionary.size() * sizeof(TGT)), + MemoryStream::DEFAULT_INITIAL_CAPACITY)); + for (idx_t r = 0; r < values.size(); r++) { + const TGT target_value = OP::template Operation(values[r]); + // update the statistics + OP::template HandleStats(stats, target_value); + // update the bloom filter + auto hash = OP::template XXHash64(target_value); + state.bloom_filter->FilterInsert(hash); + // actually write the dictionary value + OP::template WriteToStream(target_value, *temp_writer); + } + // flush the dictionary page and add it to the to-be-written pages + WriteDictionary(state, std::move(temp_writer), values.size()); + // bloom filter will be queued for writing in ParquetWriter::BufferBloomFilter one level up + } + + idx_t GetRowSize(const Vector &vector, const idx_t index, const BasicColumnWriterState &state_p) const override { + auto &state = state_p.Cast>(); + if (state.encoding == Encoding::RLE_DICTIONARY) { + return (state.key_bit_width + 7) / 8; + } else { + return OP::template GetRowSize(vector, index); + } + } +}; + +//===--------------------------------------------------------------------===// +// Boolean Column Writer +//===--------------------------------------------------------------------===// +class BooleanStatisticsState : public ColumnWriterStatistics { +public: + BooleanStatisticsState() : min(true), max(false) { + } + + bool min; + bool max; + +public: + bool HasStats() override { + return !(min && !max); + } + + string GetMin() override { + return GetMinValue(); + } + string GetMax() override { + return GetMaxValue(); + } + string GetMinValue() override { + return HasStats() ? string(const_char_ptr_cast(&min), sizeof(bool)) : string(); + } + string GetMaxValue() override { + return HasStats() ? string(const_char_ptr_cast(&max), sizeof(bool)) : string(); + } +}; + +class BooleanWriterPageState : public ColumnWriterPageState { +public: + uint8_t byte = 0; + uint8_t byte_pos = 0; +}; + +class BooleanColumnWriter : public BasicColumnWriter { +public: + BooleanColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, idx_t max_repeat, + idx_t max_define, bool can_have_nulls) + : BasicColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, can_have_nulls) { + } + ~BooleanColumnWriter() override = default; + +public: + unique_ptr InitializeStatsState() override { + return make_uniq(); + } + + void WriteVector(WriteStream &temp_writer, ColumnWriterStatistics *stats_p, ColumnWriterPageState *state_p, + Vector &input_column, idx_t chunk_start, idx_t chunk_end) override { + auto &stats = stats_p->Cast(); + auto &state = state_p->Cast(); + auto &mask = FlatVector::Validity(input_column); + + auto *ptr = FlatVector::GetData(input_column); + for (idx_t r = chunk_start; r < chunk_end; r++) { + if (mask.RowIsValid(r)) { + // only encode if non-null + if (ptr[r]) { + stats.max = true; + state.byte |= 1 << state.byte_pos; + } else { + stats.min = false; + } + state.byte_pos++; + + if (state.byte_pos == 8) { + temp_writer.Write(state.byte); + state.byte = 0; + state.byte_pos = 0; + } + } + } + } + + unique_ptr InitializePageState(BasicColumnWriterState &state, idx_t page_idx) override { + return make_uniq(); + } + + void FlushPageState(WriteStream &temp_writer, ColumnWriterPageState *state_p) override { + auto &state = state_p->Cast(); + if (state.byte_pos > 0) { + temp_writer.Write(state.byte); + state.byte = 0; + state.byte_pos = 0; + } + } + + idx_t GetRowSize(const Vector &vector, const idx_t index, const BasicColumnWriterState &state) const override { + return sizeof(bool); + } +}; + +//===--------------------------------------------------------------------===// +// Decimal Column Writer +//===--------------------------------------------------------------------===// +static void WriteParquetDecimal(hugeint_t input, data_ptr_t result) { + bool positive = input >= 0; + // numbers are stored as two's complement so some muckery is required + if (!positive) { + input = NumericLimits::Maximum() + input + 1; + } + uint64_t high_bytes = uint64_t(input.upper); + uint64_t low_bytes = input.lower; + + for (idx_t i = 0; i < sizeof(uint64_t); i++) { + auto shift_count = (sizeof(uint64_t) - i - 1) * 8; + result[i] = (high_bytes >> shift_count) & 0xFF; + } + for (idx_t i = 0; i < sizeof(uint64_t); i++) { + auto shift_count = (sizeof(uint64_t) - i - 1) * 8; + result[sizeof(uint64_t) + i] = (low_bytes >> shift_count) & 0xFF; + } + if (!positive) { + result[0] |= 0x80; + } +} + +class FixedDecimalStatistics : public ColumnWriterStatistics { +public: + FixedDecimalStatistics() : min(NumericLimits::Maximum()), max(NumericLimits::Minimum()) { + } + + hugeint_t min; + hugeint_t max; + +public: + string GetStats(hugeint_t &input) { + data_t buffer[16]; + WriteParquetDecimal(input, buffer); + return string(const_char_ptr_cast(buffer), 16); + } + + bool HasStats() override { + return min <= max; + } + + void Update(hugeint_t &val) { + if (LessThan::Operation(val, min)) { + min = val; + } + if (GreaterThan::Operation(val, max)) { + max = val; + } + } + + string GetMin() override { + return GetMinValue(); + } + string GetMax() override { + return GetMaxValue(); + } + string GetMinValue() override { + return HasStats() ? GetStats(min) : string(); + } + string GetMaxValue() override { + return HasStats() ? GetStats(max) : string(); + } +}; + +class FixedDecimalColumnWriter : public BasicColumnWriter { +public: + FixedDecimalColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, idx_t max_repeat, + idx_t max_define, bool can_have_nulls) + : BasicColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, can_have_nulls) { + } + ~FixedDecimalColumnWriter() override = default; + +public: + unique_ptr InitializeStatsState() override { + return make_uniq(); } -} -void ColumnWriter::HandleDefineLevels(ColumnWriterState &state, ColumnWriterState *parent, const ValidityMask &validity, - const idx_t count, const uint16_t define_value, const uint16_t null_value) const { - if (parent) { - // parent node: inherit definition level from the parent - idx_t vector_index = 0; - while (state.definition_levels.size() < parent->definition_levels.size()) { - idx_t current_index = state.definition_levels.size(); - if (parent->definition_levels[current_index] != PARQUET_DEFINE_VALID) { - state.definition_levels.push_back(parent->definition_levels[current_index]); - state.parent_null_count++; - } else if (validity.RowIsValid(vector_index)) { - state.definition_levels.push_back(define_value); - } else { - if (!can_have_nulls) { - throw IOException("Parquet writer: map key column is not allowed to contain NULL values"); - } - state.null_count++; - state.definition_levels.push_back(null_value); - } - if (parent->is_empty.empty() || !parent->is_empty[current_index]) { - vector_index++; - } - } - } else { - // no parent: set definition levels only from this validity mask - if (validity.AllValid()) { - state.definition_levels.insert(state.definition_levels.end(), count, define_value); - } else { - for (idx_t i = 0; i < count; i++) { - const auto is_null = !validity.RowIsValid(i); - state.definition_levels.emplace_back(is_null ? null_value : define_value); - state.null_count += is_null; + void WriteVector(WriteStream &temp_writer, ColumnWriterStatistics *stats_p, ColumnWriterPageState *page_state, + Vector &input_column, idx_t chunk_start, idx_t chunk_end) override { + auto &mask = FlatVector::Validity(input_column); + auto *ptr = FlatVector::GetData(input_column); + auto &stats = stats_p->Cast(); + + data_t temp_buffer[16]; + for (idx_t r = chunk_start; r < chunk_end; r++) { + if (mask.RowIsValid(r)) { + stats.Update(ptr[r]); + WriteParquetDecimal(ptr[r], temp_buffer); + temp_writer.WriteData(temp_buffer, 16); } } - if (!can_have_nulls && state.null_count != 0) { - throw IOException("Parquet writer: map key column is not allowed to contain NULL values"); - } } -} + + idx_t GetRowSize(const Vector &vector, const idx_t index, const BasicColumnWriterState &state) const override { + return sizeof(hugeint_t); + } +}; //===--------------------------------------------------------------------===// // WKB Column Writer //===--------------------------------------------------------------------===// // Used to store the metadata for a WKB-encoded geometry column when writing // GeoParquet files. -class WKBColumnWriterState final : public StandardColumnWriterState { +class WKBColumnWriterState final : public StandardColumnWriterState { public: - WKBColumnWriterState(ParquetWriter &writer, duckdb_parquet::RowGroup &row_group, idx_t col_idx) - : StandardColumnWriterState(writer, row_group, col_idx), geo_data(), geo_data_writer(writer.GetContext()) { + WKBColumnWriterState(ClientContext &context, duckdb_parquet::RowGroup &row_group, idx_t col_idx) + : StandardColumnWriterState(row_group, col_idx), geo_data(), geo_data_writer(context) { } GeoParquetColumnMetadata geo_data; @@ -237,16 +1727,16 @@ class WKBColumnWriterState final : public StandardColumnWriterState { public: - WKBColumnWriter(ParquetWriter &writer, const ParquetColumnSchema &column_schema, vector schema_path_p, - bool can_have_nulls, string name) - : StandardColumnWriter(writer, column_schema, std::move(schema_path_p), can_have_nulls), - column_name(std::move(name)) { + WKBColumnWriter(ClientContext &context_p, ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, + idx_t max_repeat, idx_t max_define, bool can_have_nulls, string name) + : StandardColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, can_have_nulls), + column_name(std::move(name)), context(context_p) { this->writer.GetGeoParquetData().RegisterGeometryColumn(column_name); } unique_ptr InitializeWriteState(duckdb_parquet::RowGroup &row_group) override { - auto result = make_uniq(writer, row_group, row_group.columns.size()); + auto result = make_uniq(context, row_group, row_group.columns.size()); result->encoding = Encoding::RLE_DICTIONARY; RegisterToRowGroup(row_group); return std::move(result); @@ -271,8 +1761,512 @@ class WKBColumnWriter final : public StandardColumnWriter schema_path_p, + idx_t max_repeat, idx_t max_define, bool can_have_nulls) + : BasicColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, can_have_nulls), + enum_type(std::move(enum_type_p)) { + bit_width = RleBpDecoder::ComputeBitWidth(EnumType::GetSize(enum_type)); + } + ~EnumColumnWriter() override = default; + + LogicalType enum_type; + uint32_t bit_width; + +public: + unique_ptr InitializeStatsState() override { + return make_uniq(); + } + + template + void WriteEnumInternal(WriteStream &temp_writer, Vector &input_column, idx_t chunk_start, idx_t chunk_end, + EnumWriterPageState &page_state) { + auto &mask = FlatVector::Validity(input_column); + auto *ptr = FlatVector::GetData(input_column); + for (idx_t r = chunk_start; r < chunk_end; r++) { + if (mask.RowIsValid(r)) { + if (!page_state.written_value) { + // first value + // write the bit-width as a one-byte entry + temp_writer.Write(bit_width); + // now begin writing the actual value + page_state.encoder.BeginWrite(temp_writer, ptr[r]); + page_state.written_value = true; + } else { + page_state.encoder.WriteValue(temp_writer, ptr[r]); + } + } + } + } + + void WriteVector(WriteStream &temp_writer, ColumnWriterStatistics *stats_p, ColumnWriterPageState *page_state_p, + Vector &input_column, idx_t chunk_start, idx_t chunk_end) override { + auto &page_state = page_state_p->Cast(); + switch (enum_type.InternalType()) { + case PhysicalType::UINT8: + WriteEnumInternal(temp_writer, input_column, chunk_start, chunk_end, page_state); + break; + case PhysicalType::UINT16: + WriteEnumInternal(temp_writer, input_column, chunk_start, chunk_end, page_state); + break; + case PhysicalType::UINT32: + WriteEnumInternal(temp_writer, input_column, chunk_start, chunk_end, page_state); + break; + default: + throw InternalException("Unsupported internal enum type"); + } + } + + unique_ptr InitializePageState(BasicColumnWriterState &state, idx_t page_idx) override { + return make_uniq(bit_width); + } + + void FlushPageState(WriteStream &temp_writer, ColumnWriterPageState *state_p) override { + auto &page_state = state_p->Cast(); + if (!page_state.written_value) { + // all values are null + // just write the bit width + temp_writer.Write(bit_width); + return; + } + page_state.encoder.FinishWrite(temp_writer); + } + + duckdb_parquet::Encoding::type GetEncoding(BasicColumnWriterState &state) override { + return Encoding::RLE_DICTIONARY; + } + + bool HasDictionary(BasicColumnWriterState &state) override { + return true; + } + + idx_t DictionarySize(BasicColumnWriterState &state_p) override { + return EnumType::GetSize(enum_type); + } + + void FlushDictionary(BasicColumnWriterState &state, ColumnWriterStatistics *stats_p) override { + auto &stats = stats_p->Cast(); + // write the enum values to a dictionary page + auto &enum_values = EnumType::GetValuesInsertOrder(enum_type); + auto enum_count = EnumType::GetSize(enum_type); + auto string_values = FlatVector::GetData(enum_values); + // first write the contents of the dictionary page to a temporary buffer + auto temp_writer = make_uniq(Allocator::Get(writer.GetContext())); + for (idx_t r = 0; r < enum_count; r++) { + D_ASSERT(!FlatVector::IsNull(enum_values, r)); + // update the statistics + stats.Update(string_values[r]); + // write this string value to the dictionary + temp_writer->Write(string_values[r].GetSize()); + temp_writer->WriteData(const_data_ptr_cast(string_values[r].GetData()), string_values[r].GetSize()); + } + // flush the dictionary page and add it to the to-be-written pages + WriteDictionary(state, std::move(temp_writer), enum_count); + } + + idx_t GetRowSize(const Vector &vector, const idx_t index, const BasicColumnWriterState &state) const override { + return (bit_width + 7) / 8; + } +}; + +//===--------------------------------------------------------------------===// +// Struct Column Writer +//===--------------------------------------------------------------------===// +class StructColumnWriter : public ColumnWriter { +public: + StructColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, idx_t max_repeat, + idx_t max_define, vector> child_writers_p, bool can_have_nulls) + : ColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, can_have_nulls), + child_writers(std::move(child_writers_p)) { + } + ~StructColumnWriter() override = default; + + vector> child_writers; + +public: + unique_ptr InitializeWriteState(duckdb_parquet::RowGroup &row_group) override; + bool HasAnalyze() override; + void Analyze(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count) override; + void FinalizeAnalyze(ColumnWriterState &state) override; + void Prepare(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count) override; + + void BeginWrite(ColumnWriterState &state) override; + void Write(ColumnWriterState &state, Vector &vector, idx_t count) override; + void FinalizeWrite(ColumnWriterState &state) override; +}; + +class StructColumnWriterState : public ColumnWriterState { +public: + StructColumnWriterState(duckdb_parquet::RowGroup &row_group, idx_t col_idx) + : row_group(row_group), col_idx(col_idx) { + } + ~StructColumnWriterState() override = default; + + duckdb_parquet::RowGroup &row_group; + idx_t col_idx; + vector> child_states; +}; + +unique_ptr StructColumnWriter::InitializeWriteState(duckdb_parquet::RowGroup &row_group) { + auto result = make_uniq(row_group, row_group.columns.size()); + + result->child_states.reserve(child_writers.size()); + for (auto &child_writer : child_writers) { + result->child_states.push_back(child_writer->InitializeWriteState(row_group)); + } + return std::move(result); +} + +bool StructColumnWriter::HasAnalyze() { + for (auto &child_writer : child_writers) { + if (child_writer->HasAnalyze()) { + return true; + } + } + return false; +} + +void StructColumnWriter::Analyze(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + auto &child_vectors = StructVector::GetEntries(vector); + for (idx_t child_idx = 0; child_idx < child_writers.size(); child_idx++) { + // Need to check again. It might be that just one child needs it but the rest not + if (child_writers[child_idx]->HasAnalyze()) { + child_writers[child_idx]->Analyze(*state.child_states[child_idx], &state_p, *child_vectors[child_idx], + count); + } + } +} + +void StructColumnWriter::FinalizeAnalyze(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + for (idx_t child_idx = 0; child_idx < child_writers.size(); child_idx++) { + // Need to check again. It might be that just one child needs it but the rest not + if (child_writers[child_idx]->HasAnalyze()) { + child_writers[child_idx]->FinalizeAnalyze(*state.child_states[child_idx]); + } + } +} + +void StructColumnWriter::Prepare(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + + auto &validity = FlatVector::Validity(vector); + if (parent) { + // propagate empty entries from the parent + while (state.is_empty.size() < parent->is_empty.size()) { + state.is_empty.push_back(parent->is_empty[state.is_empty.size()]); + } + } + HandleRepeatLevels(state_p, parent, count, max_repeat); + HandleDefineLevels(state_p, parent, validity, count, PARQUET_DEFINE_VALID, max_define - 1); + auto &child_vectors = StructVector::GetEntries(vector); + for (idx_t child_idx = 0; child_idx < child_writers.size(); child_idx++) { + child_writers[child_idx]->Prepare(*state.child_states[child_idx], &state_p, *child_vectors[child_idx], count); + } +} + +void StructColumnWriter::BeginWrite(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + for (idx_t child_idx = 0; child_idx < child_writers.size(); child_idx++) { + child_writers[child_idx]->BeginWrite(*state.child_states[child_idx]); + } +} + +void StructColumnWriter::Write(ColumnWriterState &state_p, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + auto &child_vectors = StructVector::GetEntries(vector); + for (idx_t child_idx = 0; child_idx < child_writers.size(); child_idx++) { + child_writers[child_idx]->Write(*state.child_states[child_idx], *child_vectors[child_idx], count); + } +} + +void StructColumnWriter::FinalizeWrite(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + for (idx_t child_idx = 0; child_idx < child_writers.size(); child_idx++) { + // we add the null count of the struct to the null count of the children + state.child_states[child_idx]->null_count += state_p.null_count; + child_writers[child_idx]->FinalizeWrite(*state.child_states[child_idx]); + } +} + +//===--------------------------------------------------------------------===// +// List Column Writer +//===--------------------------------------------------------------------===// +class ListColumnWriter : public ColumnWriter { +public: + ListColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, idx_t max_repeat, + idx_t max_define, unique_ptr child_writer_p, bool can_have_nulls) + : ColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, can_have_nulls), + child_writer(std::move(child_writer_p)) { + } + ~ListColumnWriter() override = default; + + unique_ptr child_writer; + +public: + unique_ptr InitializeWriteState(duckdb_parquet::RowGroup &row_group) override; + bool HasAnalyze() override; + void Analyze(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count) override; + void FinalizeAnalyze(ColumnWriterState &state) override; + void Prepare(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count) override; + + void BeginWrite(ColumnWriterState &state) override; + void Write(ColumnWriterState &state, Vector &vector, idx_t count) override; + void FinalizeWrite(ColumnWriterState &state) override; +}; + +class ListColumnWriterState : public ColumnWriterState { +public: + ListColumnWriterState(duckdb_parquet::RowGroup &row_group, idx_t col_idx) : row_group(row_group), col_idx(col_idx) { + } + ~ListColumnWriterState() override = default; + + duckdb_parquet::RowGroup &row_group; + idx_t col_idx; + unique_ptr child_state; + idx_t parent_index = 0; +}; + +unique_ptr ListColumnWriter::InitializeWriteState(duckdb_parquet::RowGroup &row_group) { + auto result = make_uniq(row_group, row_group.columns.size()); + result->child_state = child_writer->InitializeWriteState(row_group); + return std::move(result); +} + +bool ListColumnWriter::HasAnalyze() { + return child_writer->HasAnalyze(); +} +void ListColumnWriter::Analyze(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + auto &list_child = ListVector::GetEntry(vector); + auto list_count = ListVector::GetListSize(vector); + child_writer->Analyze(*state.child_state, &state_p, list_child, list_count); +} + +void ListColumnWriter::FinalizeAnalyze(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + child_writer->FinalizeAnalyze(*state.child_state); +} + +idx_t GetConsecutiveChildList(Vector &list, Vector &result, idx_t offset, idx_t count) { + // returns a consecutive child list that fully flattens and repeats all required elements + auto &validity = FlatVector::Validity(list); + auto list_entries = FlatVector::GetData(list); + bool is_consecutive = true; + idx_t total_length = 0; + for (idx_t c = offset; c < offset + count; c++) { + if (!validity.RowIsValid(c)) { + continue; + } + if (list_entries[c].offset != total_length) { + is_consecutive = false; + } + total_length += list_entries[c].length; + } + if (is_consecutive) { + // already consecutive - leave it as-is + return total_length; + } + SelectionVector sel(total_length); + idx_t index = 0; + for (idx_t c = offset; c < offset + count; c++) { + if (!validity.RowIsValid(c)) { + continue; + } + for (idx_t k = 0; k < list_entries[c].length; k++) { + sel.set_index(index++, list_entries[c].offset + k); + } + } + result.Slice(sel, total_length); + result.Flatten(total_length); + return total_length; +} + +void ListColumnWriter::Prepare(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + + auto list_data = FlatVector::GetData(vector); + auto &validity = FlatVector::Validity(vector); + + // write definition levels and repeats + idx_t start = 0; + idx_t vcount = parent ? parent->definition_levels.size() - state.parent_index : count; + idx_t vector_index = 0; + for (idx_t i = start; i < vcount; i++) { + idx_t parent_index = state.parent_index + i; + if (parent && !parent->is_empty.empty() && parent->is_empty[parent_index]) { + state.definition_levels.push_back(parent->definition_levels[parent_index]); + state.repetition_levels.push_back(parent->repetition_levels[parent_index]); + state.is_empty.push_back(true); + continue; + } + auto first_repeat_level = + parent && !parent->repetition_levels.empty() ? parent->repetition_levels[parent_index] : max_repeat; + if (parent && parent->definition_levels[parent_index] != PARQUET_DEFINE_VALID) { + state.definition_levels.push_back(parent->definition_levels[parent_index]); + state.repetition_levels.push_back(first_repeat_level); + state.is_empty.push_back(true); + } else if (validity.RowIsValid(vector_index)) { + // push the repetition levels + if (list_data[vector_index].length == 0) { + state.definition_levels.push_back(max_define); + state.is_empty.push_back(true); + } else { + state.definition_levels.push_back(PARQUET_DEFINE_VALID); + state.is_empty.push_back(false); + } + state.repetition_levels.push_back(first_repeat_level); + for (idx_t k = 1; k < list_data[vector_index].length; k++) { + state.repetition_levels.push_back(max_repeat + 1); + state.definition_levels.push_back(PARQUET_DEFINE_VALID); + state.is_empty.push_back(false); + } + } else { + if (!can_have_nulls) { + throw IOException("Parquet writer: map key column is not allowed to contain NULL values"); + } + state.definition_levels.push_back(max_define - 1); + state.repetition_levels.push_back(first_repeat_level); + state.is_empty.push_back(true); + } + vector_index++; + } + state.parent_index += vcount; + + auto &list_child = ListVector::GetEntry(vector); + Vector child_list(list_child); + auto child_length = GetConsecutiveChildList(vector, child_list, 0, count); + child_writer->Prepare(*state.child_state, &state_p, child_list, child_length); +} + +void ListColumnWriter::BeginWrite(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + child_writer->BeginWrite(*state.child_state); +} + +void ListColumnWriter::Write(ColumnWriterState &state_p, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + + auto &list_child = ListVector::GetEntry(vector); + Vector child_list(list_child); + auto child_length = GetConsecutiveChildList(vector, child_list, 0, count); + child_writer->Write(*state.child_state, child_list, child_length); +} + +void ListColumnWriter::FinalizeWrite(ColumnWriterState &state_p) { + auto &state = state_p.Cast(); + child_writer->FinalizeWrite(*state.child_state); +} + +//===--------------------------------------------------------------------===// +// Array Column Writer +//===--------------------------------------------------------------------===// +class ArrayColumnWriter : public ListColumnWriter { +public: + ArrayColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path_p, idx_t max_repeat, + idx_t max_define, unique_ptr child_writer_p, bool can_have_nulls) + : ListColumnWriter(writer, schema_idx, std::move(schema_path_p), max_repeat, max_define, + std::move(child_writer_p), can_have_nulls) { + } + ~ArrayColumnWriter() override = default; + +public: + void Analyze(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count) override; + void Prepare(ColumnWriterState &state, ColumnWriterState *parent, Vector &vector, idx_t count) override; + void Write(ColumnWriterState &state, Vector &vector, idx_t count) override; }; +void ArrayColumnWriter::Analyze(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + auto &array_child = ArrayVector::GetEntry(vector); + auto array_size = ArrayType::GetSize(vector.GetType()); + child_writer->Analyze(*state.child_state, &state_p, array_child, array_size * count); +} + +void ArrayColumnWriter::Prepare(ColumnWriterState &state_p, ColumnWriterState *parent, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + + auto array_size = ArrayType::GetSize(vector.GetType()); + auto &validity = FlatVector::Validity(vector); + + // write definition levels and repeats + // the main difference between this and ListColumnWriter::Prepare is that we need to make sure to write out + // repetition levels and definitions for the child elements of the array even if the array itself is NULL. + idx_t start = 0; + idx_t vcount = parent ? parent->definition_levels.size() - state.parent_index : count; + idx_t vector_index = 0; + for (idx_t i = start; i < vcount; i++) { + idx_t parent_index = state.parent_index + i; + if (parent && !parent->is_empty.empty() && parent->is_empty[parent_index]) { + state.definition_levels.push_back(parent->definition_levels[parent_index]); + state.repetition_levels.push_back(parent->repetition_levels[parent_index]); + state.is_empty.push_back(true); + continue; + } + auto first_repeat_level = + parent && !parent->repetition_levels.empty() ? parent->repetition_levels[parent_index] : max_repeat; + if (parent && parent->definition_levels[parent_index] != PARQUET_DEFINE_VALID) { + state.definition_levels.push_back(parent->definition_levels[parent_index]); + state.repetition_levels.push_back(first_repeat_level); + state.is_empty.push_back(false); + for (idx_t k = 1; k < array_size; k++) { + state.repetition_levels.push_back(max_repeat + 1); + state.definition_levels.push_back(parent->definition_levels[parent_index]); + state.is_empty.push_back(false); + } + } else if (validity.RowIsValid(vector_index)) { + // push the repetition levels + state.definition_levels.push_back(PARQUET_DEFINE_VALID); + state.is_empty.push_back(false); + + state.repetition_levels.push_back(first_repeat_level); + for (idx_t k = 1; k < array_size; k++) { + state.repetition_levels.push_back(max_repeat + 1); + state.definition_levels.push_back(PARQUET_DEFINE_VALID); + state.is_empty.push_back(false); + } + } else { + state.definition_levels.push_back(max_define - 1); + state.repetition_levels.push_back(first_repeat_level); + state.is_empty.push_back(false); + for (idx_t k = 1; k < array_size; k++) { + state.repetition_levels.push_back(max_repeat + 1); + state.definition_levels.push_back(max_define - 1); + state.is_empty.push_back(false); + } + } + vector_index++; + } + state.parent_index += vcount; + + auto &array_child = ArrayVector::GetEntry(vector); + child_writer->Prepare(*state.child_state, &state_p, array_child, count * array_size); +} + +void ArrayColumnWriter::Write(ColumnWriterState &state_p, Vector &vector, idx_t count) { + auto &state = state_p.Cast(); + auto array_size = ArrayType::GetSize(vector.GetType()); + auto &array_child = ArrayVector::GetEntry(vector); + child_writer->Write(*state.child_state, array_child, count * array_size); +} + // special double/float class to deal with dictionary encoding and NaN equality struct double_na_equal { double_na_equal() : val(0) { @@ -290,11 +2284,6 @@ struct double_na_equal { } return val == right; } - - bool operator!=(const double &right) const { - return !(*this == right); - } - double val; }; @@ -307,18 +2296,12 @@ struct float_na_equal { operator float() const { return val; } - bool operator==(const float &right) const { if (std::isnan(val) && std::isnan(right)) { return true; } return val == right; } - - bool operator!=(const float &right) const { - return !(*this == right); - } - float val; }; @@ -326,10 +2309,12 @@ struct float_na_equal { // Create Column Writer //===--------------------------------------------------------------------===// -ParquetColumnSchema ColumnWriter::FillParquetSchema(vector &schemas, - const LogicalType &type, const string &name, - optional_ptr field_ids, idx_t max_repeat, - idx_t max_define, bool can_have_nulls) { +unique_ptr ColumnWriter::CreateWriterRecursive(ClientContext &context, + vector &schemas, + ParquetWriter &writer, const LogicalType &type, + const string &name, vector schema_path, + optional_ptr field_ids, + idx_t max_repeat, idx_t max_define, bool can_have_nulls) { auto null_type = can_have_nulls ? FieldRepetitionType::OPTIONAL : FieldRepetitionType::REQUIRED; if (!can_have_nulls) { max_define--; @@ -361,15 +2346,17 @@ ParquetColumnSchema ColumnWriter::FillParquetSchema(vectorfield_id; } schemas.push_back(std::move(schema_element)); + schema_path.push_back(name); - ParquetColumnSchema struct_column(name, type, max_define, max_repeat, schema_idx, 0); - // construct the child schemas recursively - struct_column.children.reserve(child_types.size()); + // construct the child types recursively + vector> child_writers; + child_writers.reserve(child_types.size()); for (auto &child_type : child_types) { - struct_column.children.emplace_back(FillParquetSchema(schemas, child_type.second, child_type.first, - child_field_ids, max_repeat, max_define + 1)); + child_writers.push_back(CreateWriterRecursive(context, schemas, writer, child_type.second, child_type.first, + schema_path, child_field_ids, max_repeat, max_define + 1)); } - return struct_column; + return make_uniq(writer, schema_idx, std::move(schema_path), max_repeat, max_define, + std::move(child_writers), can_have_nulls); } if (type.id() == LogicalTypeId::LIST || type.id() == LogicalTypeId::ARRAY) { auto is_list = type.id() == LogicalTypeId::LIST; @@ -391,6 +2378,7 @@ ParquetColumnSchema ColumnWriter::FillParquetSchema(vectorfield_id; } schemas.push_back(std::move(optional_element)); + schema_path.push_back(name); // then a REPEATED element duckdb_parquet::SchemaElement repeated_element; @@ -401,11 +2389,17 @@ ParquetColumnSchema ColumnWriter::FillParquetSchema(vector(writer, schema_idx, std::move(schema_path), max_repeat, max_define, + std::move(child_writer), can_have_nulls); + } else { + return make_uniq(writer, schema_idx, std::move(schema_path), max_repeat, max_define, + std::move(child_writer), can_have_nulls); + } } if (type.id() == LogicalTypeId::MAP) { // map type @@ -431,6 +2425,7 @@ ParquetColumnSchema ColumnWriter::FillParquetSchema(vectorfield_id; } schemas.push_back(std::move(top_element)); + schema_path.push_back(name); // key_value element duckdb_parquet::SchemaElement kv_element; @@ -441,22 +2436,25 @@ ParquetColumnSchema ColumnWriter::FillParquetSchema(vector kv_types {MapType::KeyType(type), MapType::ValueType(type)}; vector kv_names {"key", "value"}; - - ParquetColumnSchema map_column(name, type, max_define, max_repeat, schema_idx, 0); - map_column.children.reserve(2); + vector> child_writers; + child_writers.reserve(2); for (idx_t i = 0; i < 2; i++) { // key needs to be marked as REQUIRED bool is_key = i == 0; - auto child_schema = FillParquetSchema(schemas, kv_types[i], kv_names[i], child_field_ids, max_repeat + 1, - max_define + 2, !is_key); + auto child_writer = CreateWriterRecursive(context, schemas, writer, kv_types[i], kv_names[i], schema_path, + child_field_ids, max_repeat + 1, max_define + 2, !is_key); - map_column.children.push_back(std::move(child_schema)); + child_writers.push_back(std::move(child_writer)); } - return map_column; + auto struct_writer = make_uniq(writer, schema_idx, schema_path, max_repeat, max_define, + std::move(child_writers), can_have_nulls); + return make_uniq(writer, schema_idx, schema_path, max_repeat, max_define, + std::move(struct_writer), can_have_nulls); } duckdb_parquet::SchemaElement schema_element; schema_element.type = ParquetWriter::DuckDBTypeToParquetType(type); @@ -471,140 +2469,95 @@ ParquetColumnSchema ColumnWriter::FillParquetSchema(vector -ColumnWriter::CreateWriterRecursive(ClientContext &context, ParquetWriter &writer, - const vector &parquet_schemas, - const ParquetColumnSchema &schema, vector path_in_schema) { - auto &type = schema.type; - auto can_have_nulls = parquet_schemas[schema.schema_index].repetition_type == FieldRepetitionType::OPTIONAL; - path_in_schema.push_back(schema.name); - if (type.id() == LogicalTypeId::STRUCT || type.id() == LogicalTypeId::UNION) { - // construct the child writers recursively - vector> child_writers; - child_writers.reserve(schema.children.size()); - for (auto &child_column : schema.children) { - child_writers.push_back( - CreateWriterRecursive(context, writer, parquet_schemas, child_column, path_in_schema)); - } - return make_uniq(writer, schema, std::move(path_in_schema), std::move(child_writers), - can_have_nulls); - } - if (type.id() == LogicalTypeId::LIST || type.id() == LogicalTypeId::ARRAY) { - auto is_list = type.id() == LogicalTypeId::LIST; - path_in_schema.push_back(is_list ? "list" : "array"); - auto child_writer = CreateWriterRecursive(context, writer, parquet_schemas, schema.children[0], path_in_schema); - if (is_list) { - return make_uniq(writer, schema, std::move(path_in_schema), std::move(child_writer), - can_have_nulls); - } else { - return make_uniq(writer, schema, std::move(path_in_schema), std::move(child_writer), - can_have_nulls); - } - } - if (type.id() == LogicalTypeId::MAP) { - path_in_schema.push_back("key_value"); - // construct the child types recursively - vector> child_writers; - child_writers.reserve(2); - for (idx_t i = 0; i < 2; i++) { - // key needs to be marked as REQUIRED - auto child_writer = - CreateWriterRecursive(context, writer, parquet_schemas, schema.children[i], path_in_schema); - child_writers.push_back(std::move(child_writer)); - } - auto struct_writer = - make_uniq(writer, schema, path_in_schema, std::move(child_writers), can_have_nulls); - return make_uniq(writer, schema, path_in_schema, std::move(struct_writer), can_have_nulls); - } + schema_path.push_back(name); if (type.id() == LogicalTypeId::BLOB && type.GetAlias() == "WKB_BLOB" && GeoParquetFileMetadata::IsGeoParquetConversionEnabled(context)) { - return make_uniq(writer, schema, std::move(path_in_schema), can_have_nulls, schema.name); + return make_uniq(context, writer, schema_idx, std::move(schema_path), max_repeat, max_define, + can_have_nulls, name); } switch (type.id()) { case LogicalTypeId::BOOLEAN: - return make_uniq(writer, schema, std::move(path_in_schema), can_have_nulls); + return make_uniq(writer, schema_idx, std::move(schema_path), max_repeat, max_define, + can_have_nulls); case LogicalTypeId::TINYINT: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), max_repeat, + max_define, can_have_nulls); case LogicalTypeId::SMALLINT: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), max_repeat, + max_define, can_have_nulls); case LogicalTypeId::INTEGER: case LogicalTypeId::DATE: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), max_repeat, + max_define, can_have_nulls); case LogicalTypeId::BIGINT: case LogicalTypeId::TIME: case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIMESTAMP_TZ: case LogicalTypeId::TIMESTAMP_MS: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), max_repeat, + max_define, can_have_nulls); case LogicalTypeId::TIME_TZ: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::HUGEINT: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::UHUGEINT: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::TIMESTAMP_NS: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::TIMESTAMP_SEC: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::UTINYINT: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), max_repeat, + max_define, can_have_nulls); case LogicalTypeId::USMALLINT: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); case LogicalTypeId::UINTEGER: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); case LogicalTypeId::UBIGINT: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); case LogicalTypeId::FLOAT: - return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); case LogicalTypeId::DOUBLE: - return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); case LogicalTypeId::DECIMAL: switch (type.InternalType()) { case PhysicalType::INT16: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); case PhysicalType::INT32: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); case PhysicalType::INT64: - return make_uniq>(writer, schema, std::move(path_in_schema), - can_have_nulls); + return make_uniq>(writer, schema_idx, std::move(schema_path), + max_repeat, max_define, can_have_nulls); default: - return make_uniq(writer, schema, std::move(path_in_schema), can_have_nulls); + return make_uniq(writer, schema_idx, std::move(schema_path), max_repeat, + max_define, can_have_nulls); } case LogicalTypeId::BLOB: - return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); case LogicalTypeId::VARCHAR: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::UUID: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::INTERVAL: return make_uniq>( - writer, schema, std::move(path_in_schema), can_have_nulls); + writer, schema_idx, std::move(schema_path), max_repeat, max_define, can_have_nulls); case LogicalTypeId::ENUM: - return make_uniq(writer, schema, std::move(path_in_schema), can_have_nulls); + return make_uniq(writer, type, schema_idx, std::move(schema_path), max_repeat, max_define, + can_have_nulls); default: throw InternalException("Unsupported type \"%s\" in Parquet writer", type.ToString()); } @@ -642,30 +2595,41 @@ struct NumericLimits { } }; -template <> -hash_t Hash(ParquetIntervalTargetType val) { - return Hash(const_char_ptr_cast(val.bytes), ParquetIntervalTargetType::PARQUET_INTERVAL_SIZE); -} +} // namespace duckdb +namespace std { template <> -hash_t Hash(ParquetUUIDTargetType val) { - return Hash(const_char_ptr_cast(val.bytes), ParquetUUIDTargetType::PARQUET_UUID_SIZE); -} +struct hash { + size_t operator()(const duckdb::ParquetIntervalTargetType &val) const { + return duckdb::Hash(duckdb::const_char_ptr_cast(val.bytes), + duckdb::ParquetIntervalTargetType::PARQUET_INTERVAL_SIZE); + } +}; template <> -hash_t Hash(float_na_equal val) { - if (std::isnan(val.val)) { - return Hash(std::numeric_limits::quiet_NaN()); +struct hash { + size_t operator()(const duckdb::ParquetUUIDTargetType &val) const { + return duckdb::Hash(duckdb::const_char_ptr_cast(val.bytes), duckdb::ParquetUUIDTargetType::PARQUET_UUID_SIZE); } - return Hash(val.val); -} +}; template <> -hash_t Hash(double_na_equal val) { - if (std::isnan(val.val)) { - return Hash(std::numeric_limits::quiet_NaN()); +struct hash { + size_t operator()(const duckdb::float_na_equal &val) const { + if (std::isnan(val.val)) { + return duckdb::Hash(std::numeric_limits::quiet_NaN()); + } + return duckdb::Hash(val.val); } - return Hash(val.val); -} +}; -} // namespace duckdb +template <> +struct hash { + inline size_t operator()(const duckdb::double_na_equal &val) const { + if (std::isnan(val.val)) { + return duckdb::Hash(std::numeric_limits::quiet_NaN()); + } + return duckdb::Hash(val.val); + } +}; +} // namespace std diff --git a/src/duckdb/extension/parquet/geo_parquet.cpp b/src/duckdb/extension/parquet/geo_parquet.cpp index 6a283342f..ec252a50d 100644 --- a/src/duckdb/extension/parquet/geo_parquet.cpp +++ b/src/duckdb/extension/parquet/geo_parquet.cpp @@ -8,7 +8,7 @@ #include "duckdb/planner/expression/bound_function_expression.hpp" #include "duckdb/planner/expression/bound_reference_expression.hpp" #include "duckdb/main/extension_helper.hpp" -#include "reader/expression_column_reader.hpp" +#include "expression_column_reader.hpp" #include "parquet_reader.hpp" #include "yyjson.hpp" @@ -60,9 +60,13 @@ GeoParquetColumnMetadataWriter::GeoParquetColumnMetadataWriter(ClientContext &co auto &catalog = Catalog::GetSystemCatalog(context); // These functions are required to extract the geometry type, ZM flag and bounding box from a WKB blob - auto &type_func_set = catalog.GetEntry(context, DEFAULT_SCHEMA, "st_geometrytype"); - auto &flag_func_set = catalog.GetEntry(context, DEFAULT_SCHEMA, "st_zmflag"); - auto &bbox_func_set = catalog.GetEntry(context, DEFAULT_SCHEMA, "st_extent"); + auto &type_func_set = + catalog.GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, DEFAULT_SCHEMA, "st_geometrytype") + .Cast(); + auto &flag_func_set = catalog.GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, DEFAULT_SCHEMA, "st_zmflag") + .Cast(); + auto &bbox_func_set = catalog.GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, DEFAULT_SCHEMA, "st_extent") + .Cast(); auto wkb_type = LogicalType(LogicalTypeId::BLOB); wkb_type.SetAlias("WKB_BLOB"); @@ -378,29 +382,25 @@ bool GeoParquetFileMetadata::IsGeoParquetConversionEnabled(const ClientContext & return true; } -LogicalType GeoParquetFileMetadata::GeometryType() { - auto blob_type = LogicalType(LogicalTypeId::BLOB); - blob_type.SetAlias("GEOMETRY"); - return blob_type; -} - unique_ptr GeoParquetFileMetadata::CreateColumnReader(ParquetReader &reader, - const ParquetColumnSchema &schema, + const LogicalType &logical_type, + const SchemaElement &s_ele, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p, ClientContext &context) { - D_ASSERT(IsGeometryColumn(schema.name)); + D_ASSERT(IsGeometryColumn(s_ele.name)); - const auto &column = geometry_columns[schema.name]; + const auto &column = geometry_columns[s_ele.name]; // Get the catalog auto &catalog = Catalog::GetSystemCatalog(context); // WKB encoding - if (schema.children[0].type.id() == LogicalTypeId::BLOB && - column.geometry_encoding == GeoParquetColumnEncoding::WKB) { + if (logical_type.id() == LogicalTypeId::BLOB && column.geometry_encoding == GeoParquetColumnEncoding::WKB) { // Look for a conversion function in the catalog auto &conversion_func_set = - catalog.GetEntry(context, DEFAULT_SCHEMA, "st_geomfromwkb"); + catalog.GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, DEFAULT_SCHEMA, "st_geomfromwkb") + .Cast(); auto conversion_func = conversion_func_set.functions.GetFunctionByArguments(context, {LogicalType::BLOB}); // Create a bound function call expression @@ -410,7 +410,8 @@ unique_ptr GeoParquetFileMetadata::CreateColumnReader(ParquetReade make_uniq(conversion_func.return_type, conversion_func, std::move(args), nullptr); // Create a child reader - auto child_reader = ColumnReader::CreateReader(reader, schema.children[0]); + auto child_reader = + ColumnReader::CreateReader(reader, logical_type, s_ele, schema_idx_p, max_define_p, max_repeat_p); // Create an expression reader that applies the conversion function to the child reader return make_uniq(context, std::move(child_reader), std::move(expr)); diff --git a/src/duckdb/extension/parquet/include/boolean_column_reader.hpp b/src/duckdb/extension/parquet/include/boolean_column_reader.hpp new file mode 100644 index 000000000..c37c62098 --- /dev/null +++ b/src/duckdb/extension/parquet/include/boolean_column_reader.hpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// boolean_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "templated_column_reader.hpp" + +namespace duckdb { + +struct BooleanParquetValueConversion; + +class BooleanColumnReader : public TemplatedColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::BOOL; + +public: + BooleanColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p) + : TemplatedColumnReader(reader, std::move(type_p), schema_p, schema_idx_p, + max_define_p, max_repeat_p), + byte_pos(0) {}; + + uint8_t byte_pos; + + void InitializeRead(idx_t row_group_idx_p, const vector &columns, TProtocol &protocol_p) override { + byte_pos = 0; + TemplatedColumnReader::InitializeRead(row_group_idx_p, columns, + protocol_p); + } + + void ResetPage() override { + byte_pos = 0; + } +}; + +struct BooleanParquetValueConversion { + static bool PlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.available(1); + return UnsafePlainRead(plain_data, reader); + } + + static void PlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + PlainRead(plain_data, reader); + } + + static bool PlainAvailable(const ByteBuffer &plain_data, const idx_t count) { + return plain_data.check_available((count + 7) / 8); + } + + static bool UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + auto &byte_pos = reader.Cast().byte_pos; + bool ret = (*plain_data.ptr >> byte_pos) & 1; + if (++byte_pos == 8) { + byte_pos = 0; + plain_data.unsafe_inc(1); + } + return ret; + } + + static void UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + UnsafePlainRead(plain_data, reader); + } +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/callback_column_reader.hpp b/src/duckdb/extension/parquet/include/callback_column_reader.hpp new file mode 100644 index 000000000..45c3e726e --- /dev/null +++ b/src/duckdb/extension/parquet/include/callback_column_reader.hpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// callback_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "templated_column_reader.hpp" +#include "parquet_reader.hpp" + +namespace duckdb { + +template +class CallbackColumnReader + : public TemplatedColumnReader> { + using BaseType = + TemplatedColumnReader>; + +public: + static constexpr const PhysicalType TYPE = PhysicalType::INVALID; + +public: + CallbackColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t file_idx_p, + idx_t max_define_p, idx_t max_repeat_p) + : TemplatedColumnReader>( + reader, std::move(type_p), schema_p, file_idx_p, max_define_p, max_repeat_p) { + } + +protected: + void Dictionary(shared_ptr dictionary_data, idx_t num_entries) { + BaseType::AllocateDict(num_entries * sizeof(DUCKDB_PHYSICAL_TYPE)); + auto dict_ptr = (DUCKDB_PHYSICAL_TYPE *)this->dict->ptr; + for (idx_t i = 0; i < num_entries; i++) { + dict_ptr[i] = FUNC(dictionary_data->read()); + } + } +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/cast_column_reader.hpp b/src/duckdb/extension/parquet/include/cast_column_reader.hpp new file mode 100644 index 000000000..640a77bda --- /dev/null +++ b/src/duckdb/extension/parquet/include/cast_column_reader.hpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// cast_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "templated_column_reader.hpp" + +namespace duckdb { + +//! A column reader that represents a cast over a child reader +class CastColumnReader : public ColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::INVALID; + +public: + CastColumnReader(unique_ptr child_reader, LogicalType target_type); + + unique_ptr child_reader; + DataChunk intermediate_chunk; + +public: + unique_ptr Stats(idx_t row_group_idx_p, const vector &columns) override; + void InitializeRead(idx_t row_group_idx_p, const vector &columns, TProtocol &protocol_p) override; + + idx_t Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, data_ptr_t repeat_out, + Vector &result) override; + + void Skip(idx_t num_values) override; + idx_t GroupRowsAvailable() override; + + uint64_t TotalCompressedSize() override { + return child_reader->TotalCompressedSize(); + } + + idx_t FileOffset() const override { + return child_reader->FileOffset(); + } + + void RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge) override { + child_reader->RegisterPrefetch(transport, allow_merge); + } +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/column_reader.hpp b/src/duckdb/extension/parquet/include/column_reader.hpp index ed223c4ba..2b0962395 100644 --- a/src/duckdb/extension/parquet/include/column_reader.hpp +++ b/src/duckdb/extension/parquet/include/column_reader.hpp @@ -10,17 +10,12 @@ #include "duckdb.hpp" #include "parquet_bss_decoder.hpp" +#include "parquet_dbp_decoder.hpp" +#include "parquet_rle_bp_decoder.hpp" #include "parquet_statistics.hpp" #include "parquet_types.h" #include "resizable_buffer.hpp" #include "thrift_tools.hpp" -#include "decoder/byte_stream_split_decoder.hpp" -#include "decoder/delta_binary_packed_decoder.hpp" -#include "decoder/dictionary_decoder.hpp" -#include "decoder/rle_decoder.hpp" -#include "decoder/delta_length_byte_array_decoder.hpp" -#include "decoder/delta_byte_array_decoder.hpp" -#include "parquet_column_schema.hpp" #ifndef DUCKDB_AMALGAMATION #include "duckdb/common/operator/cast_operators.hpp" @@ -31,7 +26,6 @@ namespace duckdb { class ParquetReader; -struct TableFilterState; using duckdb_apache::thrift::protocol::TProtocol; @@ -42,59 +36,33 @@ using duckdb_parquet::PageHeader; using duckdb_parquet::SchemaElement; using duckdb_parquet::Type; -enum class ColumnEncoding { - INVALID, - DICTIONARY, - DELTA_BINARY_PACKED, - RLE, - DELTA_LENGTH_BYTE_ARRAY, - DELTA_BYTE_ARRAY, - BYTE_STREAM_SPLIT, - PLAIN -}; +typedef std::bitset parquet_filter_t; class ColumnReader { - friend class ByteStreamSplitDecoder; - friend class DeltaBinaryPackedDecoder; - friend class DeltaByteArrayDecoder; - friend class DeltaLengthByteArrayDecoder; - friend class DictionaryDecoder; - friend class RLEDecoder; - public: - ColumnReader(ParquetReader &reader, const ParquetColumnSchema &schema_p); + ColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t file_idx_p, + idx_t max_define_p, idx_t max_repeat_p); virtual ~ColumnReader(); public: - static unique_ptr CreateReader(ParquetReader &reader, const ParquetColumnSchema &schema); + static unique_ptr CreateReader(ParquetReader &reader, const LogicalType &type_p, + const SchemaElement &schema_p, idx_t schema_idx_p, idx_t max_define, + idx_t max_repeat); virtual void InitializeRead(idx_t row_group_index, const vector &columns, TProtocol &protocol_p); - virtual idx_t Read(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result_out); - virtual void Select(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result_out, - const SelectionVector &sel, idx_t approved_tuple_count); - virtual void Filter(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result_out, - const TableFilter &filter, TableFilterState &filter_state, SelectionVector &sel, - idx_t &approved_tuple_count, bool is_first_filter); - static void ApplyFilter(Vector &v, const TableFilter &filter, TableFilterState &filter_state, idx_t scan_count, - SelectionVector &sel, idx_t &approved_tuple_count); + virtual idx_t Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, data_ptr_t repeat_out, + Vector &result_out); + virtual void Skip(idx_t num_values); ParquetReader &Reader(); - const LogicalType &Type() const { - return column_schema.type; - } - const ParquetColumnSchema &Schema() const { - return column_schema; - } + const LogicalType &Type() const; + const SchemaElement &Schema() const; + optional_ptr GetParentSchema() const; + void SetParentSchema(const SchemaElement &parent_schema); - inline idx_t ColumnIndex() const { - return column_schema.column_index; - } - inline idx_t MaxDefine() const { - return column_schema.max_define; - } - idx_t MaxRepeat() const { - return column_schema.max_repeat; - } + idx_t FileIdx() const; + idx_t MaxDefine() const; + idx_t MaxRepeat() const; virtual idx_t FileOffset() const; virtual uint64_t TotalCompressedSize(); @@ -103,202 +71,103 @@ class ColumnReader { // register the range this reader will touch for prefetching virtual void RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge); - unique_ptr Stats(idx_t row_group_idx_p, const vector &columns); - - template - void PlainTemplatedDefines(ByteBuffer &plain_data, const uint8_t *defines, uint64_t num_values, idx_t result_offset, - Vector &result) { - if (CONVERSION::PlainAvailable(plain_data, num_values)) { - PlainTemplatedInternal(plain_data, defines, num_values, - result_offset, result); - } else { - PlainTemplatedInternal(plain_data, defines, num_values, - result_offset, result); - } - } - template - void PlainTemplated(ByteBuffer &plain_data, const uint8_t *defines, uint64_t num_values, idx_t result_offset, - Vector &result) { - if (HasDefines() && defines) { - PlainTemplatedDefines(plain_data, defines, num_values, result_offset, result); - } else { - PlainTemplatedDefines(plain_data, defines, num_values, result_offset, - result); - } - } - - template - void PlainSkipTemplatedDefines(ByteBuffer &plain_data, const uint8_t *defines, uint64_t num_values) { - if (CONVERSION::PlainAvailable(plain_data, num_values)) { - PlainSkipTemplatedInternal(plain_data, defines, num_values); - } else { - PlainSkipTemplatedInternal(plain_data, defines, num_values); - } - } - template - void PlainSkipTemplated(ByteBuffer &plain_data, const uint8_t *defines, uint64_t num_values) { - if (HasDefines() && defines) { - PlainSkipTemplatedDefines(plain_data, defines, num_values); - } else { - PlainSkipTemplatedDefines(plain_data, defines, num_values); - } - } + virtual unique_ptr Stats(idx_t row_group_idx_p, const vector &columns); template - void PlainSelectTemplated(ByteBuffer &plain_data, const uint8_t *defines, uint64_t num_values, Vector &result, - const SelectionVector &sel, idx_t approved_tuple_count) { - if (HasDefines() && defines) { - PlainSelectTemplatedInternal(plain_data, defines, num_values, result, - sel, approved_tuple_count); + void PlainTemplated(shared_ptr plain_data, uint8_t *defines, uint64_t num_values, + parquet_filter_t *filter, idx_t result_offset, Vector &result) { + if (HasDefines()) { + if (CONVERSION::PlainAvailable(*plain_data, num_values)) { + PlainTemplatedInternal(*plain_data, defines, num_values, filter, + result_offset, result); + } else { + PlainTemplatedInternal(*plain_data, defines, num_values, filter, + result_offset, result); + } } else { - PlainSelectTemplatedInternal(plain_data, defines, num_values, result, - sel, approved_tuple_count); - } - } - - idx_t GetValidCount(uint8_t *defines, idx_t count, idx_t offset = 0) const { - if (!defines) { - return count; - } - idx_t valid_count = 0; - for (idx_t i = offset; i < offset + count; i++) { - valid_count += defines[i] == MaxDefine(); + if (CONVERSION::PlainAvailable(*plain_data, num_values)) { + PlainTemplatedInternal(*plain_data, defines, num_values, filter, + result_offset, result); + } else { + PlainTemplatedInternal(*plain_data, defines, num_values, filter, + result_offset, result); + } } - return valid_count; - } - -protected: - virtual bool SupportsDirectFilter() const { - return false; - } - virtual bool SupportsDirectSelect() const { - return false; } - void DirectFilter(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result_out, - const TableFilter &filter, TableFilterState &filter_state, SelectionVector &sel, - idx_t &approved_tuple_count); - void DirectSelect(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result, - const SelectionVector &sel, idx_t approved_tuple_count); private: - //! Check if a previous table filter has filtered out this page - bool PageIsFilteredOut(PageHeader &page_hdr); - void BeginRead(data_ptr_t define_out, data_ptr_t repeat_out); - void FinishRead(idx_t read_count); - idx_t ReadPageHeaders(idx_t max_read, optional_ptr filter = nullptr, - optional_ptr filter_state = nullptr); - idx_t ReadInternal(uint64_t num_values, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result); - //! Prepare a read of up to "max_read" rows and read the defines/repeats. - //! Returns whether all values are valid (i.e., not NULL) - bool PrepareRead(idx_t read_count, data_ptr_t define_out, data_ptr_t repeat_out, idx_t result_offset); - void ReadData(idx_t read_now, data_ptr_t define_out, data_ptr_t repeat_out, Vector &result, idx_t result_offset); - - template + template void PlainTemplatedInternal(ByteBuffer &plain_data, const uint8_t *__restrict defines, const uint64_t num_values, - const idx_t result_offset, Vector &result) { + const parquet_filter_t *filter, const idx_t result_offset, Vector &result) { const auto result_ptr = FlatVector::GetData(result); - if (!HAS_DEFINES && !CHECKED && CONVERSION::PlainConstantSize() == sizeof(VALUE_TYPE)) { - // we can memcpy - idx_t copy_count = num_values * CONVERSION::PlainConstantSize(); - memcpy(result_ptr + result_offset, plain_data.ptr, copy_count); - plain_data.unsafe_inc(copy_count); - return; - } auto &result_mask = FlatVector::Validity(result); for (idx_t row_idx = result_offset; row_idx < result_offset + num_values; row_idx++) { - if (HAS_DEFINES && defines[row_idx] != MaxDefine()) { + if (HAS_DEFINES && defines && defines[row_idx] != max_define) { result_mask.SetInvalid(row_idx); - continue; - } - result_ptr[row_idx] = CONVERSION::template PlainRead(plain_data, *this); - } - } - - template - void PlainSkipTemplatedInternal(ByteBuffer &plain_data, const uint8_t *__restrict defines, - const uint64_t num_values, idx_t row_offset = 0) { - if (!HAS_DEFINES && CONVERSION::PlainConstantSize() > 0) { - if (CHECKED) { - plain_data.inc(num_values * CONVERSION::PlainConstantSize()); - } else { - plain_data.unsafe_inc(num_values * CONVERSION::PlainConstantSize()); - } - return; - } - for (idx_t row_idx = row_offset; row_idx < row_offset + num_values; row_idx++) { - if (HAS_DEFINES && defines[row_idx] != MaxDefine()) { - continue; - } - CONVERSION::template PlainSkip(plain_data, *this); - } - } - - template - void PlainSelectTemplatedInternal(ByteBuffer &plain_data, const uint8_t *__restrict defines, - const uint64_t num_values, Vector &result, const SelectionVector &sel, - idx_t approved_tuple_count) { - const auto result_ptr = FlatVector::GetData(result); - auto &result_mask = FlatVector::Validity(result); - idx_t current_entry = 0; - for (idx_t i = 0; i < approved_tuple_count; i++) { - auto next_entry = sel.get_index(i); - D_ASSERT(current_entry <= next_entry); - // perform any skips forward if required - PlainSkipTemplatedInternal(plain_data, defines, - next_entry - current_entry, current_entry); - // read this row - if (HAS_DEFINES && defines[next_entry] != MaxDefine()) { - result_mask.SetInvalid(next_entry); - } else { - result_ptr[next_entry] = CONVERSION::template PlainRead(plain_data, *this); + } else if (!filter || filter->test(row_idx)) { + result_ptr[row_idx] = + UNSAFE ? CONVERSION::UnsafePlainRead(plain_data, *this) : CONVERSION::PlainRead(plain_data, *this); + } else { // there is still some data there that we have to skip over + if (UNSAFE) { + CONVERSION::UnsafePlainSkip(plain_data, *this); + } else { + CONVERSION::PlainSkip(plain_data, *this); + } } - current_entry = next_entry + 1; - } - if (current_entry < num_values) { - // skip forward to the end of where we are selecting - PlainSkipTemplatedInternal(plain_data, defines, - num_values - current_entry, current_entry); } } protected: Allocator &GetAllocator(); // readers that use the default Read() need to implement those - virtual void PlainSkip(ByteBuffer &plain_data, uint8_t *defines, idx_t num_values); - virtual void Plain(ByteBuffer &plain_data, uint8_t *defines, idx_t num_values, idx_t result_offset, Vector &result); - virtual void Plain(shared_ptr &plain_data, uint8_t *defines, idx_t num_values, + virtual void Plain(shared_ptr plain_data, uint8_t *defines, idx_t num_values, parquet_filter_t *filter, idx_t result_offset, Vector &result); - virtual void PlainSelect(shared_ptr &plain_data, uint8_t *defines, idx_t num_values, - Vector &result, const SelectionVector &sel, idx_t count); + // these are nops for most types, but not for strings + virtual void PlainReference(shared_ptr, Vector &result); + + virtual void PrepareDeltaLengthByteArray(ResizeableBuffer &buffer); + virtual void PrepareDeltaByteArray(ResizeableBuffer &buffer); + virtual void DeltaByteArray(uint8_t *defines, idx_t num_values, parquet_filter_t &filter, idx_t result_offset, + Vector &result); // applies any skips that were registered using Skip() - virtual void ApplyPendingSkips(data_ptr_t define_out, data_ptr_t repeat_out); + virtual void ApplyPendingSkips(idx_t num_values); - inline bool HasDefines() const { - return MaxDefine() > 0; + bool HasDefines() const { + return max_define > 0; } - inline bool HasRepeats() const { - return MaxRepeat() > 0; + bool HasRepeats() const { + return max_repeat > 0; } protected: - const ParquetColumnSchema &column_schema; + const SchemaElement &schema; + optional_ptr parent_schema; + + idx_t file_idx; + idx_t max_define; + idx_t max_repeat; ParquetReader &reader; + LogicalType type; + unique_ptr byte_array_data; + idx_t byte_array_count = 0; + idx_t pending_skips = 0; - bool page_is_filtered_out = false; virtual void ResetPage(); private: void AllocateBlock(idx_t size); - void PrepareRead(optional_ptr filter, optional_ptr filter_state); + void PrepareRead(parquet_filter_t &filter); void PreparePage(PageHeader &page_hdr); void PrepareDataPage(PageHeader &page_hdr); void PreparePageV2(PageHeader &page_hdr); void DecompressInternal(CompressionCodec::type codec, const_data_ptr_t src, idx_t src_size, data_ptr_t dst, idx_t dst_size); + void ConvertDictToSelVec(uint32_t *offsets, uint8_t *defines, parquet_filter_t &filter, idx_t read_now, + idx_t result_offset); const ColumnChunk *chunk = nullptr; TProtocol *protocol; @@ -308,23 +177,29 @@ class ColumnReader { shared_ptr block; - ColumnEncoding encoding = ColumnEncoding::INVALID; + ResizeableBuffer offset_buffer; + + unique_ptr dict_decoder; unique_ptr defined_decoder; unique_ptr repeated_decoder; - DictionaryDecoder dictionary_decoder; - DeltaBinaryPackedDecoder delta_binary_packed_decoder; - RLEDecoder rle_decoder; - DeltaLengthByteArrayDecoder delta_length_byte_array_decoder; - DeltaByteArrayDecoder delta_byte_array_decoder; - ByteStreamSplitDecoder byte_stream_split_decoder; + unique_ptr dbp_decoder; + unique_ptr rle_decoder; + unique_ptr bss_decoder; + + // dummies for Skip() + parquet_filter_t none_filter; + ResizeableBuffer dummy_define; + ResizeableBuffer dummy_repeat; - //! Resizeable buffers used for the various encodings above - ResizeableBuffer encoding_buffers[2]; + SelectionVector dictionary_selection_vector; + idx_t dictionary_size; + unique_ptr dictionary; + string dictionary_id; public: template TARGET &Cast() { - if (TARGET::TYPE != PhysicalType::INVALID && Type().InternalType() != TARGET::TYPE) { + if (TARGET::TYPE != PhysicalType::INVALID && type.InternalType() != TARGET::TYPE) { throw InternalException("Failed to cast column reader to type - type mismatch"); } return reinterpret_cast(*this); @@ -332,7 +207,7 @@ class ColumnReader { template const TARGET &Cast() const { - if (TARGET::TYPE != PhysicalType::INVALID && Type().InternalType() != TARGET::TYPE) { + if (TARGET::TYPE != PhysicalType::INVALID && type.InternalType() != TARGET::TYPE) { throw InternalException("Failed to cast column reader to type - type mismatch"); } return reinterpret_cast(*this); diff --git a/src/duckdb/extension/parquet/include/column_writer.hpp b/src/duckdb/extension/parquet/include/column_writer.hpp index 1a889c209..b27254f74 100644 --- a/src/duckdb/extension/parquet/include/column_writer.hpp +++ b/src/duckdb/extension/parquet/include/column_writer.hpp @@ -10,13 +10,12 @@ #include "duckdb.hpp" #include "parquet_types.h" -#include "parquet_column_schema.hpp" namespace duckdb { class MemoryStream; class ParquetWriter; class ColumnWriterPageState; -class PrimitiveColumnWriterState; +class BasicColumnWriterState; struct ChildFieldIDs; class ResizeableBuffer; class ParquetBloomFilter; @@ -28,7 +27,6 @@ class ColumnWriterState { unsafe_vector definition_levels; unsafe_vector repetition_levels; vector is_empty; - idx_t parent_null_count = 0; idx_t null_count = 0; public: @@ -44,10 +42,15 @@ class ColumnWriterState { } }; -class ColumnWriterPageState { +class ColumnWriterStatistics { public: - virtual ~ColumnWriterPageState() { - } + virtual ~ColumnWriterStatistics(); + + virtual bool HasStats(); + virtual string GetMin(); + virtual string GetMax(); + virtual string GetMinValue(); + virtual string GetMaxValue(); public: template @@ -63,45 +66,26 @@ class ColumnWriterPageState { }; class ColumnWriter { -protected: - static constexpr uint16_t PARQUET_DEFINE_VALID = UINT16_C(65535); public: - ColumnWriter(ParquetWriter &writer, const ParquetColumnSchema &column_schema, vector schema_path, - bool can_have_nulls); + ColumnWriter(ParquetWriter &writer, idx_t schema_idx, vector schema_path, idx_t max_repeat, + idx_t max_define, bool can_have_nulls); virtual ~ColumnWriter(); ParquetWriter &writer; - const ParquetColumnSchema &column_schema; + idx_t schema_idx; vector schema_path; + idx_t max_repeat; + idx_t max_define; bool can_have_nulls; public: - const LogicalType &Type() const { - return column_schema.type; - } - const ParquetColumnSchema &Schema() const { - return column_schema; - } - inline idx_t SchemaIndex() const { - return column_schema.schema_index; - } - inline idx_t MaxDefine() const { - return column_schema.max_define; - } - idx_t MaxRepeat() const { - return column_schema.max_repeat; - } - - static ParquetColumnSchema FillParquetSchema(vector &schemas, - const LogicalType &type, const string &name, - optional_ptr field_ids, idx_t max_repeat = 0, - idx_t max_define = 1, bool can_have_nulls = true); //! Create the column writer for a specific type recursively - static unique_ptr CreateWriterRecursive(ClientContext &context, ParquetWriter &writer, - const vector &parquet_schemas, - const ParquetColumnSchema &schema, - vector path_in_schema); + static unique_ptr + CreateWriterRecursive(ClientContext &context, vector &schemas, ParquetWriter &writer, + const LogicalType &type, const string &name, vector schema_path, + optional_ptr field_ids, idx_t max_repeat = 0, idx_t max_define = 1, + bool can_have_nulls = true); virtual unique_ptr InitializeWriteState(duckdb_parquet::RowGroup &row_group) = 0; @@ -131,7 +115,7 @@ class ColumnWriter { void HandleRepeatLevels(ColumnWriterState &state_p, ColumnWriterState *parent, idx_t count, idx_t max_repeat) const; void CompressPage(MemoryStream &temp_writer, size_t &compressed_size, data_ptr_t &compressed_data, - AllocatedData &compressed_buf); + unique_ptr &compressed_buf); }; } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/decode_utils.hpp b/src/duckdb/extension/parquet/include/decode_utils.hpp index 20ba91dd3..d6c4a854b 100644 --- a/src/duckdb/extension/parquet/include/decode_utils.hpp +++ b/src/duckdb/extension/parquet/include/decode_utils.hpp @@ -8,7 +8,6 @@ #pragma once -#include "duckdb/common/fast_mem.hpp" #include "duckdb/common/bitpacking.hpp" #include "resizable_buffer.hpp" @@ -59,25 +58,6 @@ class ParquetDecodeUtils { } } - static void Skip(ByteBuffer &src, bitpacking_width_t &bitpack_pos, idx_t count, const bitpacking_width_t width) { - CheckWidth(width); - src.available(count * width / BITPACK_DLEN); // check if buffer has enough space available once - if (bitpack_pos == 0 && count >= BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE) { - idx_t remainder = count % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE; - idx_t aligned_count = count - remainder; - SkipAligned(src, aligned_count, width); - count = remainder; - } - // FIXME: we should be able to just do this in one go instead of having this loop - for (idx_t i = 0; i < count; i++) { - bitpack_pos += width; - while (bitpack_pos > BITPACK_DLEN) { - src.unsafe_inc(1); - bitpack_pos -= BITPACK_DLEN; - } - } - } - template static void BitPackAligned(T *src, data_ptr_t dst, const idx_t count, const bitpacking_width_t width) { D_ASSERT(width < BITPACK_MASKS_SIZE); @@ -87,22 +67,14 @@ class ParquetDecodeUtils { template static void BitUnpackAlignedInternal(ByteBuffer &src, T *dst, const idx_t count, const bitpacking_width_t width) { - D_ASSERT(count % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE == 0); - if (cast_pointer_to_uint64(src.ptr) % sizeof(T) == 0) { - // Fast path: aligned - BitpackingPrimitives::UnPackBuffer(data_ptr_cast(dst), src.ptr, count, width); - src.unsafe_inc(count * width / BITPACK_DLEN); - return; - } - for (idx_t i = 0; i < count; i += BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE) { - const auto next_read = BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE * width / BITPACK_DLEN; + const auto next_read = BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE * width / 8; // Buffer for alignment T aligned_data[BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE]; // Copy over to aligned buffer - FastMemcpy(aligned_data, src.ptr, next_read); + memcpy(aligned_data, src.ptr, next_read); // Unpack BitpackingPrimitives::UnPackBlock(data_ptr_cast(dst), data_ptr_cast(aligned_data), width, true); @@ -124,16 +96,6 @@ class ParquetDecodeUtils { BitUnpackAlignedInternal(src, dst, count, width); } - static void SkipAligned(ByteBuffer &src, const idx_t count, const bitpacking_width_t width) { - CheckWidth(width); - if (count % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE != 0) { - throw InvalidInputException("Aligned bitpacking count must be a multiple of %llu", - BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE); - } - const auto read_size = count * width / BITPACK_DLEN; - src.inc(read_size); - } - //===--------------------------------------------------------------------===// // Zigzag //===--------------------------------------------------------------------===// @@ -195,17 +157,12 @@ class ParquetDecodeUtils { } while (val != 0); } - template + template static T VarintDecode(ByteBuffer &buf) { T result = 0; uint8_t shift = 0; while (true) { - uint8_t byte; - if (CHECKED) { - byte = buf.read(); - } else { - byte = buf.unsafe_read(); - } + auto byte = buf.read(); result |= T(byte & 127) << shift; if ((byte & 128) == 0) { break; diff --git a/src/duckdb/extension/parquet/include/expression_column_reader.hpp b/src/duckdb/extension/parquet/include/expression_column_reader.hpp new file mode 100644 index 000000000..c94a816d3 --- /dev/null +++ b/src/duckdb/extension/parquet/include/expression_column_reader.hpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// expression_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "templated_column_reader.hpp" + +namespace duckdb { + +//! A column reader that executes an expression over a child reader +class ExpressionColumnReader : public ColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::INVALID; + +public: + ExpressionColumnReader(ClientContext &context, unique_ptr child_reader, unique_ptr expr); + + unique_ptr child_reader; + DataChunk intermediate_chunk; + unique_ptr expr; + ExpressionExecutor executor; + +public: + unique_ptr Stats(idx_t row_group_idx_p, const vector &columns) override; + void InitializeRead(idx_t row_group_idx_p, const vector &columns, TProtocol &protocol_p) override; + + idx_t Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, data_ptr_t repeat_out, + Vector &result) override; + + void Skip(idx_t num_values) override; + idx_t GroupRowsAvailable() override; + + uint64_t TotalCompressedSize() override { + return child_reader->TotalCompressedSize(); + } + + idx_t FileOffset() const override { + return child_reader->FileOffset(); + } + + void RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge) override { + child_reader->RegisterPrefetch(transport, allow_merge); + } +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/geo_parquet.hpp b/src/duckdb/extension/parquet/include/geo_parquet.hpp index 5980fff34..0a9b0966f 100644 --- a/src/duckdb/extension/parquet/include/geo_parquet.hpp +++ b/src/duckdb/extension/parquet/include/geo_parquet.hpp @@ -16,7 +16,6 @@ #include "parquet_types.h" namespace duckdb { -struct ParquetColumnSchema; enum class WKBGeometryType : uint16_t { POINT = 1, @@ -128,14 +127,14 @@ class GeoParquetFileMetadata { void FlushColumnMeta(const string &column_name, const GeoParquetColumnMetadata &meta); const unordered_map &GetColumnMeta() const; - unique_ptr CreateColumnReader(ParquetReader &reader, const ParquetColumnSchema &schema, - ClientContext &context); + unique_ptr CreateColumnReader(ParquetReader &reader, const LogicalType &logical_type, + const duckdb_parquet::SchemaElement &s_ele, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p, ClientContext &context); bool IsGeometryColumn(const string &column_name) const; void RegisterGeometryColumn(const string &column_name); static bool IsGeoParquetConversionEnabled(const ClientContext &context); - static LogicalType GeometryType(); private: mutex write_lock; diff --git a/src/duckdb/extension/parquet/include/list_column_reader.hpp b/src/duckdb/extension/parquet/include/list_column_reader.hpp new file mode 100644 index 000000000..67565dfbf --- /dev/null +++ b/src/duckdb/extension/parquet/include/list_column_reader.hpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// list_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "templated_column_reader.hpp" + +namespace duckdb { + +class ListColumnReader : public ColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::LIST; + +public: + ListColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p, unique_ptr child_column_reader_p); + + idx_t Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, data_ptr_t repeat_out, + Vector &result_out) override; + + void ApplyPendingSkips(idx_t num_values) override; + + void InitializeRead(idx_t row_group_idx_p, const vector &columns, TProtocol &protocol_p) override { + child_column_reader->InitializeRead(row_group_idx_p, columns, protocol_p); + } + + idx_t GroupRowsAvailable() override { + return child_column_reader->GroupRowsAvailable() + overflow_child_count; + } + + uint64_t TotalCompressedSize() override { + return child_column_reader->TotalCompressedSize(); + } + + void RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge) override { + child_column_reader->RegisterPrefetch(transport, allow_merge); + } + +private: + unique_ptr child_column_reader; + ResizeableBuffer child_defines; + ResizeableBuffer child_repeats; + uint8_t *child_defines_ptr; + uint8_t *child_repeats_ptr; + + VectorCache read_cache; + Vector read_vector; + + parquet_filter_t child_filter; + + idx_t overflow_child_count; +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/null_column_reader.hpp b/src/duckdb/extension/parquet/include/null_column_reader.hpp new file mode 100644 index 000000000..6d89c906b --- /dev/null +++ b/src/duckdb/extension/parquet/include/null_column_reader.hpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// null_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "duckdb/common/helper.hpp" + +namespace duckdb { + +class NullColumnReader : public ColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::INVALID; + +public: + NullColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p) + : ColumnReader(reader, std::move(type_p), schema_p, schema_idx_p, max_define_p, max_repeat_p) {}; + + shared_ptr dict; + +public: + void Plain(shared_ptr plain_data, uint8_t *defines, uint64_t num_values, parquet_filter_t *filter, + idx_t result_offset, Vector &result) override { + (void)defines; + (void)plain_data; + (void)filter; + + auto &result_mask = FlatVector::Validity(result); + for (idx_t row_idx = 0; row_idx < num_values; row_idx++) { + result_mask.SetInvalid(row_idx + result_offset); + } + } +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/parquet_bss_decoder.hpp b/src/duckdb/extension/parquet/include/parquet_bss_decoder.hpp index 28ba8d3ea..b8cd8d11c 100644 --- a/src/duckdb/extension/parquet/include/parquet_bss_decoder.hpp +++ b/src/duckdb/extension/parquet/include/parquet_bss_decoder.hpp @@ -41,18 +41,6 @@ class BssDecoder { value_offset_ += batch_size; } - template - void Skip(uint32_t batch_size) { - if (buffer_.len % sizeof(T) != 0) { - std::stringstream error; - error << "Data buffer size for the BYTE_STREAM_SPLIT encoding (" << buffer_.len - << ") should be a multiple of the type size (" << sizeof(T) << ")"; - throw std::runtime_error(error.str()); - } - buffer_.available((value_offset_ + batch_size) * sizeof(T)); - value_offset_ += batch_size; - } - private: ByteBuffer buffer_; uint32_t value_offset_; diff --git a/src/duckdb/extension/parquet/include/parquet_bss_encoder.hpp b/src/duckdb/extension/parquet/include/parquet_bss_encoder.hpp index 78f75a0c7..65561eb25 100644 --- a/src/duckdb/extension/parquet/include/parquet_bss_encoder.hpp +++ b/src/duckdb/extension/parquet/include/parquet_bss_encoder.hpp @@ -41,23 +41,4 @@ class BssEncoder { AllocatedData buffer; }; -namespace bss_encoder { - -template -void WriteValue(BssEncoder &encoder, const T &value) { - throw InternalException("Can't write type to BYTE_STREAM_SPLIT column"); -} - -template <> -void WriteValue(BssEncoder &encoder, const float &value) { - encoder.WriteValue(value); -} - -template <> -void WriteValue(BssEncoder &encoder, const double &value) { - encoder.WriteValue(value); -} - -} // namespace bss_encoder - } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp b/src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp index 31fb26cc9..4925a0ff9 100644 --- a/src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp +++ b/src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp @@ -50,15 +50,6 @@ class DbpDecoder { GetBatchInternal(target_values_ptr, batch_size); } - template - void Skip(idx_t skip_count) { - if (read_values + skip_count > total_value_count) { - throw std::runtime_error("DBP decode did not find enough values"); - } - read_values += skip_count; - GetBatchInternal(nullptr, skip_count); - } - void Finalize() { if (miniblock_offset == number_of_values_in_a_miniblock) { return; @@ -68,22 +59,16 @@ class DbpDecoder { } private: - template + template void GetBatchInternal(const data_ptr_t target_values_ptr, const idx_t batch_size) { if (batch_size == 0) { return; } - D_ASSERT(target_values_ptr || SKIP_READ); - T *target_values = nullptr; - if (!SKIP_READ) { - target_values = reinterpret_cast(target_values_ptr); - } + auto target_values = reinterpret_cast(target_values_ptr); idx_t target_values_offset = 0; if (is_first_value) { - if (!SKIP_READ) { - target_values[0] = static_cast(previous_value); - } + target_values[0] = static_cast(previous_value); target_values_offset++; is_first_value = false; } @@ -94,13 +79,11 @@ class DbpDecoder { BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE - unpacked_data_offset); if (next != 0) { for (idx_t i = 0; i < next; i++) { + auto &target = target_values[target_values_offset + i]; const auto &unpacked_value = unpacked_data[unpacked_data_offset + i]; - auto current_value = static_cast(static_cast(previous_value) + - static_cast(min_delta) + unpacked_value); - if (!SKIP_READ) { - target_values[target_values_offset + i] = current_value; - } - previous_value = static_cast(current_value); + target = static_cast(static_cast(previous_value) + static_cast(min_delta) + + unpacked_value); + previous_value = static_cast(target); } target_values_offset += next; unpacked_data_offset += next; diff --git a/src/duckdb/extension/parquet/include/parquet_dbp_encoder.hpp b/src/duckdb/extension/parquet/include/parquet_dbp_encoder.hpp index c775e2cdc..791d10e08 100644 --- a/src/duckdb/extension/parquet/include/parquet_dbp_encoder.hpp +++ b/src/duckdb/extension/parquet/include/parquet_dbp_encoder.hpp @@ -176,58 +176,4 @@ class DbpEncoder { data_t data_packed[NUMBER_OF_VALUES_IN_A_MINIBLOCK * sizeof(int64_t)]; }; -namespace dbp_encoder { - -template -void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const T &first_value) { - throw InternalException("Can't write type to DELTA_BINARY_PACKED column"); -} - -template <> -void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const int64_t &first_value) { - encoder.BeginWrite(writer, first_value); -} - -template <> -void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const int32_t &first_value) { - BeginWrite(encoder, writer, UnsafeNumericCast(first_value)); -} - -template <> -void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const uint64_t &first_value) { - encoder.BeginWrite(writer, UnsafeNumericCast(first_value)); -} - -template <> -void BeginWrite(DbpEncoder &encoder, WriteStream &writer, const uint32_t &first_value) { - BeginWrite(encoder, writer, UnsafeNumericCast(first_value)); -} - -template -void WriteValue(DbpEncoder &encoder, WriteStream &writer, const T &value) { - throw InternalException("Can't write type to DELTA_BINARY_PACKED column"); -} - -template <> -void WriteValue(DbpEncoder &encoder, WriteStream &writer, const int64_t &value) { - encoder.WriteValue(writer, value); -} - -template <> -void WriteValue(DbpEncoder &encoder, WriteStream &writer, const int32_t &value) { - WriteValue(encoder, writer, UnsafeNumericCast(value)); -} - -template <> -void WriteValue(DbpEncoder &encoder, WriteStream &writer, const uint64_t &value) { - encoder.WriteValue(writer, UnsafeNumericCast(value)); -} - -template <> -void WriteValue(DbpEncoder &encoder, WriteStream &writer, const uint32_t &value) { - WriteValue(encoder, writer, UnsafeNumericCast(value)); -} - -} // namespace dbp_encoder - } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/parquet_decimal_utils.hpp b/src/duckdb/extension/parquet/include/parquet_decimal_utils.hpp index de042c302..119ed5672 100644 --- a/src/duckdb/extension/parquet/include/parquet_decimal_utils.hpp +++ b/src/duckdb/extension/parquet/include/parquet_decimal_utils.hpp @@ -9,14 +9,14 @@ #pragma once #include "column_reader.hpp" -#include "reader/templated_column_reader.hpp" +#include "templated_column_reader.hpp" namespace duckdb { class ParquetDecimalUtils { public: template - static PHYSICAL_TYPE ReadDecimalValue(const_data_ptr_t pointer, idx_t size, const ParquetColumnSchema &) { + static PHYSICAL_TYPE ReadDecimalValue(const_data_ptr_t pointer, idx_t size, const duckdb_parquet::SchemaElement &) { PHYSICAL_TYPE res = 0; auto res_ptr = (uint8_t *)&res; @@ -46,10 +46,13 @@ class ParquetDecimalUtils { return res; } - static unique_ptr CreateReader(ParquetReader &reader, const ParquetColumnSchema &schema); + static unique_ptr CreateReader(ParquetReader &reader, const LogicalType &type_p, + const SchemaElement &schema_p, idx_t file_idx_p, idx_t max_define, + idx_t max_repeat); }; template <> -double ParquetDecimalUtils::ReadDecimalValue(const_data_ptr_t pointer, idx_t size, const ParquetColumnSchema &schema); +double ParquetDecimalUtils::ReadDecimalValue(const_data_ptr_t pointer, idx_t size, + const duckdb_parquet::SchemaElement &schema_ele); } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/parquet_dlba_encoder.hpp b/src/duckdb/extension/parquet/include/parquet_dlba_encoder.hpp index 897dc9c5f..89702fc12 100644 --- a/src/duckdb/extension/parquet/include/parquet_dlba_encoder.hpp +++ b/src/duckdb/extension/parquet/include/parquet_dlba_encoder.hpp @@ -44,39 +44,4 @@ class DlbaEncoder { unsafe_unique_ptr stream; }; -namespace dlba_encoder { - -template -void BeginWrite(DlbaEncoder &encoder, WriteStream &writer, const T &first_value) { - throw InternalException("Can't write type to DELTA_LENGTH_BYTE_ARRAY column"); -} - -template <> -void BeginWrite(DlbaEncoder &encoder, WriteStream &writer, const string_t &first_value) { - encoder.BeginWrite(writer, first_value); -} - -template -void WriteValue(DlbaEncoder &encoder, WriteStream &writer, const T &value) { - throw InternalException("Can't write type to DELTA_LENGTH_BYTE_ARRAY column"); -} - -template <> -void WriteValue(DlbaEncoder &encoder, WriteStream &writer, const string_t &value) { - encoder.WriteValue(writer, value); -} - -// helpers to get size from strings -template -static idx_t GetDlbaStringSize(const SRC &) { - return 0; -} - -template <> -idx_t GetDlbaStringSize(const string_t &src_value) { - return src_value.GetSize(); -} - -} // namespace dlba_encoder - } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/parquet_reader.hpp b/src/duckdb/extension/parquet/include/parquet_reader.hpp index 50fd78e15..0061ede2d 100644 --- a/src/duckdb/extension/parquet/include/parquet_reader.hpp +++ b/src/duckdb/extension/parquet/include/parquet_reader.hpp @@ -9,19 +9,24 @@ #pragma once #include "duckdb.hpp" +#ifndef DUCKDB_AMALGAMATION #include "duckdb/common/common.hpp" #include "duckdb/common/encryption_state.hpp" #include "duckdb/common/exception.hpp" -#include "duckdb/common/multi_file/base_file_reader.hpp" -#include "duckdb/common/multi_file/multi_file_options.hpp" +#include "duckdb/common/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader_options.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/common/types/data_chunk.hpp" +#include "duckdb/planner/filter/conjunction_filter.hpp" +#include "duckdb/planner/filter/constant_filter.hpp" +#include "duckdb/planner/filter/null_filter.hpp" +#include "duckdb/planner/table_filter.hpp" +#endif #include "column_reader.hpp" #include "parquet_file_metadata_cache.hpp" #include "parquet_rle_bp_decoder.hpp" #include "parquet_types.h" #include "resizable_buffer.hpp" -#include "duckdb/execution/adaptive_filter.hpp" #include @@ -37,27 +42,15 @@ class ClientContext; class BaseStatistics; class TableFilterSet; class ParquetEncryptionConfig; -class ParquetReader; struct ParquetReaderPrefetchConfig { // Percentage of data in a row group span that should be scanned for enabling whole group prefetch static constexpr double WHOLE_GROUP_PREFETCH_MINIMUM_SCAN = 0.95; }; -struct ParquetScanFilter { - ParquetScanFilter(ClientContext &context, idx_t filter_idx, TableFilter &filter); - ~ParquetScanFilter(); - ParquetScanFilter(ParquetScanFilter &&) = default; - - idx_t filter_idx; - TableFilter &filter; - unique_ptr filter_state; -}; - struct ParquetReaderScanState { vector group_idx_list; int64_t current_group; - idx_t offset_in_group; idx_t group_offset; unique_ptr file_handle; unique_ptr root_reader; @@ -71,11 +64,6 @@ struct ParquetReaderScanState { bool prefetch_mode = false; bool current_group_prefetched = false; - - //! Adaptive filter - unique_ptr adaptive_filter; - //! Table filter list - vector scan_filters; }; struct ParquetColumnDefinition { @@ -105,81 +93,108 @@ struct ParquetOptions { shared_ptr encryption_config; bool debug_use_openssl = true; + MultiFileReaderOptions file_options; vector schema; idx_t explicit_cardinality = 0; -}; - -struct ParquetOptionsSerialization { - ParquetOptionsSerialization() = default; - ParquetOptionsSerialization(ParquetOptions parquet_options_p, MultiFileOptions file_options_p) - : parquet_options(std::move(parquet_options_p)), file_options(std::move(file_options_p)) { - } - - ParquetOptions parquet_options; - MultiFileOptions file_options; public: void Serialize(Serializer &serializer) const; - static ParquetOptionsSerialization Deserialize(Deserializer &deserializer); + static ParquetOptions Deserialize(Deserializer &deserializer); }; -struct ParquetUnionData : public BaseUnionData { - explicit ParquetUnionData(string file_name_p) : BaseUnionData(std::move(file_name_p)) { - } - ~ParquetUnionData() override; +struct ParquetUnionData { + ~ParquetUnionData(); + string file_name; + vector names; + vector types; ParquetOptions options; shared_ptr metadata; + unique_ptr reader; + + const string &GetFileName() { + return file_name; + } }; -class ParquetReader : public BaseFileReader { +class ParquetReader { public: - // Reserved field id used for the "ord" field according to the iceberg spec (used for file_row_number) - static constexpr int32_t ORDINAL_FIELD_ID = 2147483645; + using UNION_READER_DATA = unique_ptr; public: ParquetReader(ClientContext &context, string file_name, ParquetOptions parquet_options, shared_ptr metadata = nullptr); - ~ParquetReader() override; + ~ParquetReader(); FileSystem &fs; Allocator &allocator; + string file_name; + vector columns; shared_ptr metadata; ParquetOptions parquet_options; - unique_ptr root_schema; + MultiFileReaderData reader_data; + unique_ptr root_reader; shared_ptr encryption_util; - //! How many rows have been read from this file - atomic rows_read; + + //! Parquet schema for the generated columns + vector generated_column_schema; + //! Table column names - set when using COPY tbl FROM file.parquet + vector table_columns; public: void InitializeScan(ClientContext &context, ParquetReaderScanState &state, vector groups_to_read); - void Scan(ClientContext &context, ParquetReaderScanState &state, DataChunk &output); + void Scan(ParquetReaderScanState &state, DataChunk &output); + + static unique_ptr StoreUnionReader(unique_ptr reader_p, idx_t file_idx) { + auto result = make_uniq(); + result->file_name = reader_p->file_name; + if (file_idx == 0) { + for (auto &column : reader_p->columns) { + result->names.push_back(column.name); + result->types.push_back(column.type); + } + result->options = reader_p->parquet_options; + result->metadata = reader_p->metadata; + result->reader = std::move(reader_p); + } else { + for (auto &column : reader_p->columns) { + result->names.push_back(column.name); + result->types.push_back(column.type); + } + reader_p->columns.clear(); + result->options = std::move(reader_p->parquet_options); + result->metadata = std::move(reader_p->metadata); + } + + return result; + } - idx_t NumRows() const; - idx_t NumRowGroups() const; + idx_t NumRows(); + idx_t NumRowGroups(); - const duckdb_parquet::FileMetaData *GetFileMetadata() const; + const duckdb_parquet::FileMetaData *GetFileMetadata(); uint32_t Read(duckdb_apache::thrift::TBase &object, TProtocol &iprot); uint32_t ReadData(duckdb_apache::thrift::protocol::TProtocol &iprot, const data_ptr_t buffer, const uint32_t buffer_size); unique_ptr ReadStatistics(const string &name); + static LogicalType DeriveLogicalType(const SchemaElement &s_ele, bool binary_as_string); FileHandle &GetHandle() { return *file_handle; } - static unique_ptr ReadStatistics(ClientContext &context, ParquetOptions parquet_options, - shared_ptr metadata, const string &name); - - LogicalType DeriveLogicalType(const SchemaElement &s_ele, ParquetColumnSchema &schema) const; + const string &GetFileName() { + return file_name; + } - string GetReaderType() const override { - return "Parquet"; + const vector &GetColumns() { + return columns; } - void AddVirtualColumn(column_t virtual_column_id) override; + static unique_ptr ReadStatistics(ClientContext &context, ParquetOptions parquet_options, + shared_ptr metadata, const string &name); private: //! Construct a parquet reader but **do not** open a file, used in ReadStatistics only @@ -187,28 +202,19 @@ class ParquetReader : public BaseFileReader { shared_ptr metadata); void InitializeSchema(ClientContext &context); - bool ScanInternal(ClientContext &context, ParquetReaderScanState &state, DataChunk &output); - //! Parse the schema of the file - unique_ptr ParseSchema(); - ParquetColumnSchema ParseSchemaRecursive(idx_t depth, idx_t max_define, idx_t max_repeat, idx_t &next_schema_idx, - idx_t &next_file_idx); - + bool ScanInternal(ParquetReaderScanState &state, DataChunk &output); unique_ptr CreateReader(ClientContext &context); unique_ptr CreateReaderRecursive(ClientContext &context, const vector &indexes, - const ParquetColumnSchema &schema); + idx_t depth, idx_t max_define, idx_t max_repeat, + idx_t &next_schema_idx, idx_t &next_file_idx); const duckdb_parquet::RowGroup &GetGroup(ParquetReaderScanState &state); uint64_t GetGroupCompressedSize(ParquetReaderScanState &state); idx_t GetGroupOffset(ParquetReaderScanState &state); // Group span is the distance between the min page offset and the max page offset plus the max page compressed size uint64_t GetGroupSpan(ParquetReaderScanState &state); void PrepareRowGroupBuffer(ParquetReaderScanState &state, idx_t out_col_idx); - ParquetColumnSchema ParseColumnSchema(const SchemaElement &s_ele, idx_t max_define, idx_t max_repeat, - idx_t schema_index, idx_t column_index, - ParquetColumnSchemaType type = ParquetColumnSchemaType::COLUMN); - - MultiFileColumnDefinition ParseColumnDefinition(const duckdb_parquet::FileMetaData &file_meta_data, - ParquetColumnSchema &element); + LogicalType DeriveLogicalType(const SchemaElement &s_ele); private: unique_ptr file_handle; diff --git a/src/duckdb/extension/parquet/include/parquet_rle_bp_decoder.hpp b/src/duckdb/extension/parquet/include/parquet_rle_bp_decoder.hpp index 6b91aec11..b8dc35b35 100644 --- a/src/duckdb/extension/parquet/include/parquet_rle_bp_decoder.hpp +++ b/src/duckdb/extension/parquet/include/parquet_rle_bp_decoder.hpp @@ -27,61 +27,34 @@ class RleBpDecoder { max_val = (uint64_t(1) << bit_width_) - 1; } - template - bool HasRepeatedBatch(const uint32_t batch_size, const T value) { - if (repeat_count_ == 0 && literal_count_ == 0) { - NextCounts(); - } - return repeat_count_ >= batch_size && current_value_ == static_cast(value); - } - - template - void GetRepeatedBatch(const uint32_t batch_size, const T value) { - D_ASSERT(repeat_count_ >= batch_size && current_value_ == static_cast(value)); - repeat_count_ -= batch_size; - } - template - void GetBatch(data_ptr_t values_target_ptr, const uint32_t batch_size) { + void GetBatch(data_ptr_t values_target_ptr, uint32_t batch_size) { auto values = reinterpret_cast(values_target_ptr); uint32_t values_read = 0; while (values_read < batch_size) { if (repeat_count_ > 0) { - auto repeat_batch = MinValue(batch_size - values_read, repeat_count_); + int repeat_batch = MinValue(batch_size - values_read, static_cast(repeat_count_)); std::fill_n(values + values_read, repeat_batch, static_cast(current_value_)); repeat_count_ -= repeat_batch; values_read += repeat_batch; } else if (literal_count_ > 0) { - auto literal_batch = MinValue(batch_size - values_read, literal_count_); + uint32_t literal_batch = MinValue(batch_size - values_read, static_cast(literal_count_)); ParquetDecodeUtils::BitUnpack(buffer_, bitpack_pos, values + values_read, literal_batch, bit_width_); literal_count_ -= literal_batch; values_read += literal_batch; } else { - NextCounts(); + if (!NextCounts()) { + if (values_read != batch_size) { + throw std::runtime_error("RLE decode did not find enough values"); + } + return; + } } } - D_ASSERT(values_read == batch_size); - } - - void Skip(uint32_t batch_size) { - uint32_t values_skipped = 0; - - while (values_skipped < batch_size) { - if (repeat_count_ > 0) { - auto repeat_batch = MinValue(batch_size - values_skipped, repeat_count_); - repeat_count_ -= repeat_batch; - values_skipped += repeat_batch; - } else if (literal_count_ > 0) { - auto literal_batch = MinValue(batch_size - values_skipped, literal_count_); - ParquetDecodeUtils::Skip(buffer_, bitpack_pos, literal_batch, bit_width_); - literal_count_ -= literal_batch; - values_skipped += literal_batch; - } else { - NextCounts(); - } + if (values_read != batch_size) { + throw std::runtime_error("RLE decode did not find enough values"); } - D_ASSERT(values_skipped == batch_size); } static uint8_t ComputeBitWidth(idx_t val) { @@ -110,19 +83,15 @@ class RleBpDecoder { /// Fills literal_count_ and repeat_count_ with next values. Returns false if there /// are no more. - template - void NextCountsTemplated() { + template + bool NextCounts() { // Read the next run's indicator int, it could be a literal or repeated run. // The int is encoded as a vlq-encoded value. if (bitpack_pos != 0) { - if (CHECKED) { - buffer_.inc(1); - } else { - buffer_.unsafe_inc(1); - } + buffer_.inc(1); bitpack_pos = 0; } - auto indicator_value = ParquetDecodeUtils::VarintDecode(buffer_); + auto indicator_value = ParquetDecodeUtils::VarintDecode(buffer_); // lsb indicates if it is a literal run or repeated run bool is_literal = indicator_value & 1; @@ -132,27 +101,16 @@ class RleBpDecoder { repeat_count_ = indicator_value >> 1; // (ARROW-4018) this is not big-endian compatible, lol current_value_ = 0; - if (CHECKED) { - buffer_.available(byte_encoded_len); - } for (auto i = 0; i < byte_encoded_len; i++) { - auto next_byte = Load(buffer_.ptr + i); - current_value_ |= (next_byte << (i * 8)); + current_value_ |= (buffer_.read() << (i * 8)); } - buffer_.unsafe_inc(byte_encoded_len); // sanity check if (repeat_count_ > 0 && current_value_ > max_val) { throw std::runtime_error("Payload value bigger than allowed. Corrupted file?"); } } - } - - void NextCounts() { - if (buffer_.check_available(byte_encoded_len + sizeof(uint32_t) + 2)) { - NextCountsTemplated(); - } else { - NextCountsTemplated(); - } + // TODO complain if we run out of buffer + return true; } }; } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/parquet_rle_bp_encoder.hpp b/src/duckdb/extension/parquet/include/parquet_rle_bp_encoder.hpp index 3a7292fd5..029dd06eb 100644 --- a/src/duckdb/extension/parquet/include/parquet_rle_bp_encoder.hpp +++ b/src/duckdb/extension/parquet/include/parquet_rle_bp_encoder.hpp @@ -8,145 +8,42 @@ #pragma once -#include "decode_utils.hpp" +#include "parquet_types.h" +#include "thrift_tools.hpp" +#include "resizable_buffer.hpp" namespace duckdb { class RleBpEncoder { public: - explicit RleBpEncoder(uint32_t bit_width_p) : bit_width(bit_width_p), byte_width((bit_width + 7) / 8) { - } + explicit RleBpEncoder(uint32_t bit_width); public: - void BeginWrite() { - rle_count = 0; - bp_block_count = 0; - } + //! NOTE: Prepare is only required if a byte count is required BEFORE writing + //! This is the case with e.g. writing repetition/definition levels + //! If GetByteCount() is not required, prepare can be safely skipped + void BeginPrepare(uint32_t first_value); + void PrepareValue(uint32_t value); + void FinishPrepare(); - void WriteValue(WriteStream &writer, const uint32_t &value) { - if (bp_block_count != 0) { - // We already committed to a BP run - D_ASSERT(rle_count == 0); - bp_block[bp_block_count++] = value; - if (bp_block_count == BP_BLOCK_SIZE) { - WriteRun(writer); - } - return; - } + void BeginWrite(WriteStream &writer, uint32_t first_value); + void WriteValue(WriteStream &writer, uint32_t value); + void FinishWrite(WriteStream &writer); - if (rle_count == 0) { - // Starting fresh, try for an RLE run first - rle_value = value; - rle_count = 1; - return; - } - - // We're trying for an RLE run - if (rle_value == value) { - // Same as current RLE value - rle_count++; - return; - } - - // Value differs from current RLE value - if (rle_count >= MINIMUM_RLE_COUNT) { - // We have enough values for an RLE run - WriteRun(writer); - rle_value = value; - rle_count = 1; - return; - } - - // Not enough values, convert and commit to a BP run - D_ASSERT(bp_block_count == 0); - for (idx_t i = 0; i < rle_count; i++) { - bp_block[bp_block_count++] = rle_value; - } - bp_block[bp_block_count++] = value; - rle_count = 0; - } - - void WriteMany(WriteStream &writer, uint32_t value, idx_t count) { - if (rle_count != 0) { - // If an RLE run is going on, write a single value to either finish it or convert to BP - WriteValue(writer, value); - count--; - } - - if (bp_block_count != 0) { - // If a BP run is going on, finish it - while (bp_block_count != 0 && count > 0) { - WriteValue(writer, value); - count--; - } - } - - // Set remaining as current RLE run - rle_value = value; - rle_count += count; - } - - void FinishWrite(WriteStream &writer) { - WriteRun(writer); - } + idx_t GetByteCount(); private: - //! Meta information - uint32_t bit_width; + //! meta information uint32_t byte_width; - - //! RLE stuff - static constexpr idx_t MINIMUM_RLE_COUNT = 4; - uint32_t rle_value; - idx_t rle_count; - - //! BP stuff - static constexpr idx_t BP_BLOCK_SIZE = 256; - static_assert(BP_BLOCK_SIZE % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE == 0, - "BP_BLOCK_SIZE must be divisible by BITPACKING_ALGORITHM_GROUP_SIZE"); - uint32_t bp_block[BP_BLOCK_SIZE] = {0}; - uint32_t bp_block_packed[BP_BLOCK_SIZE] = {0}; - idx_t bp_block_count; + //! RLE run information + idx_t byte_count; + idx_t run_count; + idx_t current_run_count; + uint32_t last_value; private: - void WriteRun(WriteStream &writer) { - if (rle_count != 0) { - WriteCurrentBlockRLE(writer); - } else { - WriteCurrentBlockBP(writer); - } - } - - void WriteCurrentBlockRLE(WriteStream &writer) { - ParquetDecodeUtils::VarintEncode(rle_count << 1 | 0, writer); // (... | 0) signals RLE run - D_ASSERT(rle_value >> (byte_width * 8) == 0); - switch (byte_width) { - case 1: - writer.Write(rle_value); - break; - case 2: - writer.Write(rle_value); - break; - case 3: - writer.Write(rle_value & 0xFF); - writer.Write((rle_value >> 8) & 0xFF); - writer.Write((rle_value >> 16) & 0xFF); - break; - case 4: - writer.Write(rle_value); - break; - default: - throw InternalException("unsupported byte width for RLE encoding"); - } - rle_count = 0; - } - - void WriteCurrentBlockBP(WriteStream &writer) { - ParquetDecodeUtils::VarintEncode(BP_BLOCK_SIZE / 8 << 1 | 1, writer); // (... | 1) signals BP run - ParquetDecodeUtils::BitPackAligned(bp_block, data_ptr_cast(bp_block_packed), BP_BLOCK_SIZE, bit_width); - writer.WriteData(data_ptr_cast(bp_block_packed), BP_BLOCK_SIZE * bit_width / 8); - bp_block_count = 0; - } + void FinishRun(); + void WriteRun(WriteStream &writer); }; } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/parquet_statistics.hpp b/src/duckdb/extension/parquet/include/parquet_statistics.hpp index 2991a0415..ad1f939c8 100644 --- a/src/duckdb/extension/parquet/include/parquet_statistics.hpp +++ b/src/duckdb/extension/parquet/include/parquet_statistics.hpp @@ -13,7 +13,6 @@ #include "duckdb/storage/statistics/base_statistics.hpp" #endif #include "parquet_types.h" -#include "resizable_buffer.hpp" namespace duckdb { @@ -21,26 +20,24 @@ using duckdb_parquet::ColumnChunk; using duckdb_parquet::SchemaElement; struct LogicalType; -struct ParquetColumnSchema; +class ColumnReader; class ResizeableBuffer; struct ParquetStatisticsUtils { - static unique_ptr TransformColumnStatistics(const ParquetColumnSchema &reader, + static unique_ptr TransformColumnStatistics(const ColumnReader &reader, const vector &columns); - static Value ConvertValue(const LogicalType &type, const ParquetColumnSchema &schema_ele, const std::string &stats); + static Value ConvertValue(const LogicalType &type, const duckdb_parquet::SchemaElement &schema_ele, + const std::string &stats); static bool BloomFilterSupported(const LogicalTypeId &type_id); static bool BloomFilterExcludes(const TableFilter &filter, const duckdb_parquet::ColumnMetaData &column_meta_data, duckdb_apache::thrift::protocol::TProtocol &file_proto, Allocator &allocator); - static unique_ptr CreateNumericStats(const LogicalType &type, const ParquetColumnSchema &schema_ele, - const duckdb_parquet::Statistics &parquet_stats); - private: - static Value ConvertValueInternal(const LogicalType &type, const ParquetColumnSchema &schema_ele, + static Value ConvertValueInternal(const LogicalType &type, const duckdb_parquet::SchemaElement &schema_ele, const std::string &stats); }; diff --git a/src/duckdb/extension/parquet/include/parquet_writer.hpp b/src/duckdb/extension/parquet/include/parquet_writer.hpp index 763488646..1ad586489 100644 --- a/src/duckdb/extension/parquet/include/parquet_writer.hpp +++ b/src/duckdb/extension/parquet/include/parquet_writer.hpp @@ -9,37 +9,34 @@ #pragma once #include "duckdb.hpp" +#ifndef DUCKDB_AMALGAMATION #include "duckdb/common/common.hpp" #include "duckdb/common/encryption_state.hpp" #include "duckdb/common/exception.hpp" #include "duckdb/common/mutex.hpp" -#include "duckdb/common/atomic.hpp" #include "duckdb/common/serializer/buffered_file_writer.hpp" #include "duckdb/common/types/column/column_data_collection.hpp" #include "duckdb/function/copy_function.hpp" +#endif #include "parquet_statistics.hpp" #include "column_writer.hpp" #include "parquet_types.h" #include "geo_parquet.hpp" -#include "writer/parquet_write_stats.hpp" #include "thrift/protocol/TCompactProtocol.h" namespace duckdb { class FileSystem; class FileOpener; class ParquetEncryptionConfig; -class ParquetStatsAccumulator; class Serializer; class Deserializer; -class ColumnWriterStatistics; -struct CopyFunctionFileStatistics; - struct PreparedRowGroup { duckdb_parquet::RowGroup row_group; vector> states; + vector> heaps; }; struct FieldID; @@ -82,9 +79,8 @@ class ParquetWriter { vector names, duckdb_parquet::CompressionCodec::type codec, ChildFieldIDs field_ids, const vector> &kv_metadata, shared_ptr encryption_config, idx_t dictionary_size_limit, - idx_t string_dictionary_page_size_limit, double bloom_filter_false_positive_ratio, - int64_t compression_level, bool debug_use_openssl, ParquetVersion parquet_version); - ~ParquetWriter(); + double bloom_filter_false_positive_ratio, int64_t compression_level, bool debug_use_openssl, + ParquetVersion parquet_version); public: void PrepareRowGroup(ColumnDataCollection &buffer, PreparedRowGroup &result); @@ -114,14 +110,12 @@ class ParquetWriter { return *writer; } idx_t FileSize() { - return total_written; + lock_guard glock(lock); + return writer->total_written; } idx_t DictionarySizeLimit() const { return dictionary_size_limit; } - idx_t StringDictionaryPageSizeLimit() const { - return string_dictionary_page_size_limit; - } double BloomFilterFalsePositiveRatio() const { return bloom_filter_false_positive_ratio; } @@ -129,7 +123,8 @@ class ParquetWriter { return compression_level; } idx_t NumberOfRowGroups() { - return num_row_groups; + lock_guard glock(lock); + return file_meta_data.row_groups.size(); } ParquetVersion GetParquetVersion() const { return parquet_version; @@ -144,12 +139,6 @@ class ParquetWriter { optional_ptr type = nullptr); void BufferBloomFilter(idx_t col_idx, unique_ptr bloom_filter); - void SetWrittenStatistics(CopyFunctionFileStatistics &written_stats); - void FlushColumnStats(idx_t col_idx, duckdb_parquet::ColumnChunk &chunk, - optional_ptr writer_stats); - -private: - void GatherWrittenStatistics(); private: ClientContext &context; @@ -160,18 +149,13 @@ class ParquetWriter { ChildFieldIDs field_ids; shared_ptr encryption_config; idx_t dictionary_size_limit; - idx_t string_dictionary_page_size_limit; double bloom_filter_false_positive_ratio; int64_t compression_level; bool debug_use_openssl; shared_ptr encryption_util; ParquetVersion parquet_version; - vector column_schemas; unique_ptr writer; - //! Atomics to reduce contention when rotating writes to multiple Parquet files - atomic total_written; - atomic num_row_groups; std::shared_ptr protocol; duckdb_parquet::FileMetaData file_meta_data; std::mutex lock; @@ -180,9 +164,6 @@ class ParquetWriter { unique_ptr geoparquet_data; vector bloom_filters; - - optional_ptr written_stats; - unique_ptr stats_accumulator; }; } // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/resizable_buffer.hpp b/src/duckdb/extension/parquet/include/resizable_buffer.hpp index be00a0a7a..1e225d510 100644 --- a/src/duckdb/extension/parquet/include/resizable_buffer.hpp +++ b/src/duckdb/extension/parquet/include/resizable_buffer.hpp @@ -103,10 +103,6 @@ class ResizeableBuffer : public ByteBuffer { ptr = allocated_data.get(); } } - void reset() { - ptr = allocated_data.get(); - len = alloc_len; - } private: AllocatedData allocated_data; diff --git a/src/duckdb/extension/parquet/include/row_number_column_reader.hpp b/src/duckdb/extension/parquet/include/row_number_column_reader.hpp new file mode 100644 index 000000000..cdd5df1f3 --- /dev/null +++ b/src/duckdb/extension/parquet/include/row_number_column_reader.hpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// row_number_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#ifndef DUCKDB_AMALGAMATION +#include "duckdb/common/limits.hpp" +#endif +#include "column_reader.hpp" +#include "templated_column_reader.hpp" + +namespace duckdb { + +//! Reads a file-absolute row number as a virtual column that's not actually stored in the file +class RowNumberColumnReader : public ColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::INT64; + +public: + RowNumberColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p); + +public: + idx_t Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, data_ptr_t repeat_out, + Vector &result) override; + + unique_ptr Stats(idx_t row_group_idx_p, const vector &columns) override; + + void InitializeRead(idx_t row_group_idx_p, const vector &columns, TProtocol &protocol_p) override; + + void Skip(idx_t num_values) override { + row_group_offset += num_values; + } + idx_t GroupRowsAvailable() override { + return NumericLimits::Maximum(); + }; + uint64_t TotalCompressedSize() override { + return 0; + } + idx_t FileOffset() const override { + return 0; + } + void RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge) override { + } + +private: + idx_t row_group_offset; +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/string_column_reader.hpp b/src/duckdb/extension/parquet/include/string_column_reader.hpp new file mode 100644 index 000000000..2ab96a296 --- /dev/null +++ b/src/duckdb/extension/parquet/include/string_column_reader.hpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// string_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" + +namespace duckdb { + +struct StringParquetValueConversion { + static string_t PlainRead(ByteBuffer &plain_data, ColumnReader &reader); + static void PlainSkip(ByteBuffer &plain_data, ColumnReader &reader); + static bool PlainAvailable(const ByteBuffer &plain_data, const idx_t count); + static string_t UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader); + static void UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader); +}; + +class StringColumnReader : public TemplatedColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::VARCHAR; + +public: + StringColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p); + idx_t fixed_width_string_length; + idx_t delta_offset = 0; + +public: + void PrepareDeltaLengthByteArray(ResizeableBuffer &buffer) override; + void PrepareDeltaByteArray(ResizeableBuffer &buffer) override; + void DeltaByteArray(uint8_t *defines, idx_t num_values, parquet_filter_t &filter, idx_t result_offset, + Vector &result) override; + static uint32_t VerifyString(const char *str_data, uint32_t str_len, const bool isVarchar); + uint32_t VerifyString(const char *str_data, uint32_t str_len); + +protected: + void PlainReference(shared_ptr plain_data, Vector &result) override; +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/struct_column_reader.hpp b/src/duckdb/extension/parquet/include/struct_column_reader.hpp new file mode 100644 index 000000000..4a0254695 --- /dev/null +++ b/src/duckdb/extension/parquet/include/struct_column_reader.hpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// struct_column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "templated_column_reader.hpp" + +namespace duckdb { + +class StructColumnReader : public ColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::STRUCT; + +public: + StructColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p, vector> child_readers_p); + + vector> child_readers; + +public: + ColumnReader &GetChildReader(idx_t child_idx); + + void InitializeRead(idx_t row_group_idx_p, const vector &columns, TProtocol &protocol_p) override; + + idx_t Read(uint64_t num_values, parquet_filter_t &filter, data_ptr_t define_out, data_ptr_t repeat_out, + Vector &result) override; + + void Skip(idx_t num_values) override; + idx_t GroupRowsAvailable() override; + uint64_t TotalCompressedSize() override; + void RegisterPrefetch(ThriftFileTransport &transport, bool allow_merge) override; +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/templated_column_reader.hpp b/src/duckdb/extension/parquet/include/templated_column_reader.hpp new file mode 100644 index 000000000..d85865309 --- /dev/null +++ b/src/duckdb/extension/parquet/include/templated_column_reader.hpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// templated__column_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "column_reader.hpp" +#include "duckdb/common/helper.hpp" + +namespace duckdb { + +template +struct TemplatedParquetValueConversion { + + static VALUE_TYPE PlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + return plain_data.read(); + } + + static void PlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.inc(sizeof(VALUE_TYPE)); + } + + static bool PlainAvailable(const ByteBuffer &plain_data, const idx_t count) { + return plain_data.check_available(count * sizeof(VALUE_TYPE)); + } + + static VALUE_TYPE UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + return plain_data.unsafe_read(); + } + + static void UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.unsafe_inc(sizeof(VALUE_TYPE)); + } +}; + +template +class TemplatedColumnReader : public ColumnReader { +public: + static constexpr const PhysicalType TYPE = PhysicalType::INVALID; + +public: + TemplatedColumnReader(ParquetReader &reader, LogicalType type_p, const SchemaElement &schema_p, idx_t schema_idx_p, + idx_t max_define_p, idx_t max_repeat_p) + : ColumnReader(reader, std::move(type_p), schema_p, schema_idx_p, max_define_p, max_repeat_p) {}; + + shared_ptr dict; + +public: + void AllocateDict(idx_t size) { + if (!dict) { + dict = make_shared_ptr(GetAllocator(), size); + } else { + dict->resize(GetAllocator(), size); + } + } + + void Plain(shared_ptr plain_data, uint8_t *defines, uint64_t num_values, parquet_filter_t *filter, + idx_t result_offset, Vector &result) override { + PlainTemplated(std::move(plain_data), defines, num_values, filter, result_offset, + result); + } +}; + +template +struct CallbackParquetValueConversion { + + static DUCKDB_PHYSICAL_TYPE PlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + return FUNC(plain_data.read()); + } + + static void PlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.inc(sizeof(PARQUET_PHYSICAL_TYPE)); + } + + static bool PlainAvailable(const ByteBuffer &plain_data, const idx_t count) { + return plain_data.check_available(count * sizeof(PARQUET_PHYSICAL_TYPE)); + } + + static DUCKDB_PHYSICAL_TYPE UnsafePlainRead(ByteBuffer &plain_data, ColumnReader &reader) { + return FUNC(plain_data.unsafe_read()); + } + + static void UnsafePlainSkip(ByteBuffer &plain_data, ColumnReader &reader) { + plain_data.unsafe_inc(sizeof(PARQUET_PHYSICAL_TYPE)); + } +}; + +} // namespace duckdb diff --git a/src/duckdb/extension/parquet/include/thrift_tools.hpp b/src/duckdb/extension/parquet/include/thrift_tools.hpp index 0051f7752..de1eaca34 100644 --- a/src/duckdb/extension/parquet/include/thrift_tools.hpp +++ b/src/duckdb/extension/parquet/include/thrift_tools.hpp @@ -135,8 +135,8 @@ class ThriftFileTransport : public duckdb_apache::thrift::transport::TVirtualTra static constexpr uint64_t PREFETCH_FALLBACK_BUFFERSIZE = 1000000; ThriftFileTransport(Allocator &allocator, FileHandle &handle_p, bool prefetch_mode_p) - : handle(handle_p), location(0), size(handle.GetFileSize()), allocator(allocator), - ra_buffer(ReadAheadBuffer(allocator, handle_p)), prefetch_mode(prefetch_mode_p) { + : handle(handle_p), location(0), allocator(allocator), ra_buffer(ReadAheadBuffer(allocator, handle_p)), + prefetch_mode(prefetch_mode_p) { } uint32_t read(uint8_t *buf, uint32_t len) { @@ -191,14 +191,6 @@ class ThriftFileTransport : public duckdb_apache::thrift::transport::TVirtualTra ra_buffer.merge_set.clear(); } - void Skip(idx_t skip_count) { - location += skip_count; - } - - bool HasPrefetch() const { - return !ra_buffer.read_heads.empty() || !ra_buffer.merge_set.empty(); - } - void SetLocation(idx_t location_p) { location = location_p; } @@ -207,13 +199,12 @@ class ThriftFileTransport : public duckdb_apache::thrift::transport::TVirtualTra return location; } idx_t GetSize() { - return size; + return handle.file_system.GetFileSize(handle); } private: FileHandle &handle; idx_t location; - idx_t size; Allocator &allocator; diff --git a/src/duckdb/extension/parquet/parquet_extension.cpp b/src/duckdb/extension/parquet/parquet_extension.cpp index 9c6d39cac..d4a08fb82 100644 --- a/src/duckdb/extension/parquet/parquet_extension.cpp +++ b/src/duckdb/extension/parquet/parquet_extension.cpp @@ -2,6 +2,7 @@ #include "parquet_extension.hpp" +#include "cast_column_reader.hpp" #include "duckdb.hpp" #include "duckdb/parser/expression/positional_reference_expression.hpp" #include "duckdb/parser/expression/constant_expression.hpp" @@ -14,7 +15,7 @@ #include "parquet_metadata.hpp" #include "parquet_reader.hpp" #include "parquet_writer.hpp" -#include "reader/struct_column_reader.hpp" +#include "struct_column_reader.hpp" #include "zstd_file_system.hpp" #include @@ -29,7 +30,7 @@ #include "duckdb/common/enums/file_compression_type.hpp" #include "duckdb/common/file_system.hpp" #include "duckdb/common/helper.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/serializer/deserializer.hpp" #include "duckdb/common/serializer/serializer.hpp" #include "duckdb/common/type_visitor.hpp" @@ -48,84 +49,198 @@ #include "duckdb/planner/operator/logical_get.hpp" #include "duckdb/storage/statistics/base_statistics.hpp" #include "duckdb/storage/table/row_group.hpp" -#include "duckdb/common/multi_file/multi_file_function.hpp" -#include "duckdb/common/primitive_dictionary.hpp" #endif namespace duckdb { -class ParquetFileReaderOptions : public BaseFileReaderOptions { -public: - explicit ParquetFileReaderOptions(ParquetOptions options_p) : options(std::move(options_p)) { - } - explicit ParquetFileReaderOptions(ClientContext &context) : options(context) { - } +struct ParquetReadBindData : public TableFunctionData { + shared_ptr file_list; + unique_ptr multi_file_reader; - ParquetOptions options; -}; + shared_ptr initial_reader; + atomic chunk_count; + vector names; + vector types; + vector columns; + //! Table column names - set when using COPY tbl FROM file.parquet + vector table_columns; + + // The union readers are created (when parquet union_by_name option is on) during binding + // Those readers can be re-used during ParquetParallelStateNext + vector> union_readers; -struct ParquetReadBindData : public TableFunctionData { // These come from the initial_reader, but need to be stored in case the initial_reader is removed by a filter idx_t initial_file_cardinality; idx_t initial_file_row_groups; idx_t explicit_cardinality = 0; // can be set to inject exterior cardinality knowledge (e.g. from a data lake) ParquetOptions parquet_options; + MultiFileReaderBindData reader_bind; + + void Initialize(shared_ptr reader) { + initial_reader = std::move(reader); + initial_file_cardinality = initial_reader->NumRows(); + initial_file_row_groups = initial_reader->NumRowGroups(); + parquet_options = initial_reader->parquet_options; + } + void Initialize(ClientContext &, unique_ptr &union_data) { + Initialize(std::move(union_data->reader)); + } +}; + +struct ParquetReadLocalState : public LocalTableFunctionState { + shared_ptr reader; + ParquetReaderScanState scan_state; + bool is_parallel; + idx_t batch_index; + idx_t file_index; + //! The DataChunk containing all read columns (even columns that are immediately removed) + DataChunk all_columns; +}; + +enum class ParquetFileState : uint8_t { UNOPENED, OPENING, OPEN, CLOSED }; + +struct ParquetFileReaderData { + // Create data for an unopened file + explicit ParquetFileReaderData(const string &file_to_be_opened) + : reader(nullptr), file_state(ParquetFileState::UNOPENED), file_mutex(make_uniq()), + file_to_be_opened(file_to_be_opened) { + } + // Create data for an existing reader + explicit ParquetFileReaderData(shared_ptr reader_p) + : reader(std::move(reader_p)), file_state(ParquetFileState::OPEN), file_mutex(make_uniq()) { + } + // Create data for an existing reader + explicit ParquetFileReaderData(unique_ptr union_data_p) : file_mutex(make_uniq()) { + if (union_data_p->reader) { + reader = std::move(union_data_p->reader); + file_state = ParquetFileState::OPEN; + } else { + union_data = std::move(union_data_p); + file_state = ParquetFileState::UNOPENED; + } + } + + //! Currently opened reader for the file + shared_ptr reader; + //! Flag to indicate the file is being opened + ParquetFileState file_state; + //! Mutexes to wait for the file when it is being opened + unique_ptr file_mutex; + //! Parquet options for opening the file + unique_ptr union_data; + + //! (only set when file_state is UNOPENED) the file to be opened + string file_to_be_opened; }; struct ParquetReadGlobalState : public GlobalTableFunctionState { + explicit ParquetReadGlobalState(MultiFileList &file_list_p) : file_list(file_list_p) { + } + explicit ParquetReadGlobalState(unique_ptr owned_file_list_p) + : file_list(*owned_file_list_p), owned_file_list(std::move(owned_file_list_p)) { + } + + //! The file list to scan + MultiFileList &file_list; + //! The scan over the file_list + MultiFileListScanData file_list_scan; + //! Owned multi file list - if filters have been dynamically pushed into the reader + unique_ptr owned_file_list; + + unique_ptr multi_file_reader_state; + + mutex lock; + + //! The current set of parquet readers + vector> readers; + + //! Signal to other threads that a file failed to open, letting every thread abort. + bool error_opening_file = false; + + //! Index of file currently up for scanning + atomic file_index; //! Index of row group within file currently up for scanning idx_t row_group_index; //! Batch index of the next row group to be scanned idx_t batch_index; + + idx_t max_threads; + vector projection_ids; + vector scanned_types; + vector column_indexes; + optional_ptr filters; + + idx_t MaxThreads() const override { + return max_threads; + } + + bool CanRemoveColumns() const { + return !projection_ids.empty(); + } }; -struct ParquetReadLocalState : public LocalTableFunctionState { - ParquetReaderScanState scan_state; +struct ParquetWriteBindData : public TableFunctionData { + vector sql_types; + vector column_names; + duckdb_parquet::CompressionCodec::type codec = duckdb_parquet::CompressionCodec::SNAPPY; + vector> kv_metadata; + idx_t row_group_size = DEFAULT_ROW_GROUP_SIZE; + idx_t row_group_size_bytes = NumericLimits::Maximum(); + + //! How/Whether to encrypt the data + shared_ptr encryption_config; + bool debug_use_openssl = true; + + //! After how many distinct values should we abandon dictionary compression and bloom filters? + idx_t dictionary_size_limit = row_group_size / 100; + + //! What false positive rate are we willing to accept for bloom filters + double bloom_filter_false_positive_ratio = 0.01; + + //! After how many row groups to rotate to a new file + optional_idx row_groups_per_file; + + ChildFieldIDs field_ids; + //! The compression level, higher value is more + int64_t compression_level = ZStdFileSystem::DefaultCompressionLevel(); + + //! Which encodings to include when writing + ParquetVersion parquet_version = ParquetVersion::V1; +}; + +struct ParquetWriteGlobalState : public GlobalFunctionData { + unique_ptr writer; }; -struct ParquetMultiFileInfo { - static unique_ptr InitializeOptions(ClientContext &context, - optional_ptr info); - static bool ParseCopyOption(ClientContext &context, const string &key, const vector &values, - BaseFileReaderOptions &options, vector &expected_names, - vector &expected_types); - static bool ParseOption(ClientContext &context, const string &key, const Value &val, MultiFileOptions &file_options, - BaseFileReaderOptions &options); - static void FinalizeCopyBind(ClientContext &context, BaseFileReaderOptions &options_p, - const vector &expected_names, const vector &expected_types); - static void BindReader(ClientContext &context, vector &return_types, vector &names, - MultiFileBindData &bind_data); - static unique_ptr InitializeBindData(MultiFileBindData &multi_file_data, - unique_ptr options); - static void FinalizeBindData(MultiFileBindData &multi_file_data); - static void GetBindInfo(const TableFunctionData &bind_data, BindInfo &info); - static optional_idx MaxThreads(const MultiFileBindData &bind_data, const MultiFileGlobalState &global_state, - FileExpandResult expand_result); - static unique_ptr - InitializeGlobalState(ClientContext &context, MultiFileBindData &bind_data, MultiFileGlobalState &global_state); - static unique_ptr InitializeLocalState(ExecutionContext &, GlobalTableFunctionState &); - static shared_ptr CreateReader(ClientContext &context, GlobalTableFunctionState &gstate, - BaseUnionData &union_data, const MultiFileBindData &bind_data_p); - static shared_ptr CreateReader(ClientContext &context, GlobalTableFunctionState &gstate, - const string &filename, idx_t file_idx, - const MultiFileBindData &bind_data); - static shared_ptr CreateReader(ClientContext &context, const string &filename, - ParquetOptions &options, const MultiFileOptions &file_options); - static shared_ptr GetUnionData(shared_ptr scan_p, idx_t file_idx); - static void FinalizeReader(ClientContext &context, BaseFileReader &reader, GlobalTableFunctionState &); - static void Scan(ClientContext &context, BaseFileReader &reader, GlobalTableFunctionState &global_state, - LocalTableFunctionState &local_state, DataChunk &chunk); - static bool TryInitializeScan(ClientContext &context, shared_ptr &reader, - GlobalTableFunctionState &gstate, LocalTableFunctionState &lstate); - static void FinishFile(ClientContext &context, GlobalTableFunctionState &global_state, BaseFileReader &reader); - static void FinishReading(ClientContext &context, GlobalTableFunctionState &global_state, - LocalTableFunctionState &local_state); - static unique_ptr GetCardinality(const MultiFileBindData &bind_data, idx_t file_count); - static unique_ptr GetStatistics(ClientContext &context, BaseFileReader &reader, const string &name); - static double GetProgressInFile(ClientContext &context, const BaseFileReader &reader); - static void GetVirtualColumns(ClientContext &context, MultiFileBindData &bind_data, virtual_column_map_t &result); +struct ParquetWriteLocalState : public LocalFunctionData { + explicit ParquetWriteLocalState(ClientContext &context, const vector &types) + : buffer(BufferAllocator::Get(context), types) { + buffer.InitializeAppend(append_state); + } + + ColumnDataCollection buffer; + ColumnDataAppendState append_state; }; +BindInfo ParquetGetBindInfo(const optional_ptr bind_data) { + auto bind_info = BindInfo(ScanType::PARQUET); + auto &parquet_bind = bind_data->Cast(); + + vector file_path; + for (const auto &file : parquet_bind.file_list->Files()) { + file_path.emplace_back(file); + } + + // LCOV_EXCL_START + bind_info.InsertOption("file_path", Value::LIST(LogicalType::VARCHAR, file_path)); + bind_info.InsertOption("binary_as_string", Value::BOOLEAN(parquet_bind.parquet_options.binary_as_string)); + bind_info.InsertOption("file_row_number", Value::BOOLEAN(parquet_bind.parquet_options.file_row_number)); + bind_info.InsertOption("debug_use_openssl", Value::BOOLEAN(parquet_bind.parquet_options.debug_use_openssl)); + parquet_bind.parquet_options.file_options.AddBatchInfo(bind_info); + // LCOV_EXCL_STOP + return bind_info; +} + static void ParseFileRowNumberOption(MultiFileReaderBindData &bind_data, ParquetOptions &options, vector &return_types, vector &names) { if (options.file_row_number) { @@ -134,25 +249,26 @@ static void ParseFileRowNumberOption(MultiFileReaderBindData &bind_data, Parquet "Using file_row_number option on file with column named file_row_number is not supported"); } + bind_data.file_row_number_idx = names.size(); return_types.emplace_back(LogicalType::BIGINT); names.emplace_back("file_row_number"); } } -static void BindSchema(ClientContext &context, vector &return_types, vector &names, - MultiFileBindData &bind_data) { - auto &parquet_bind = bind_data.bind_data->Cast(); - auto &options = parquet_bind.parquet_options; +static MultiFileReaderBindData BindSchema(ClientContext &context, vector &return_types, + vector &names, ParquetReadBindData &result, ParquetOptions &options) { D_ASSERT(!options.schema.empty()); - auto &file_options = bind_data.file_options; + options.file_options.AutoDetectHivePartitioning(*result.file_list, context); + + auto &file_options = options.file_options; if (file_options.union_by_name || file_options.hive_partitioning) { throw BinderException("Parquet schema cannot be combined with union_by_name=true or hive_partitioning=true"); } - auto &reader_bind = bind_data.reader_bind; vector schema_col_names; vector schema_col_types; + MultiFileReaderBindData bind_data; schema_col_names.reserve(options.schema.size()); schema_col_types.reserve(options.schema.size()); bool match_by_field_id; @@ -172,7 +288,7 @@ static void BindSchema(ClientContext &context, vector &return_types schema_col_names.push_back(column.name); schema_col_types.push_back(column.type); - auto res = MultiFileColumnDefinition(column.name, column.type); + auto res = MultiFileReaderColumnDefinition(column.name, column.type); res.identifier = column.identifier; #ifdef DEBUG if (match_by_field_id) { @@ -183,61 +299,74 @@ static void BindSchema(ClientContext &context, vector &return_types #endif res.default_expression = make_uniq(column.default_value); - reader_bind.schema.emplace_back(std::move(res)); - } - ParseFileRowNumberOption(reader_bind, options, return_types, names); - if (options.file_row_number) { - MultiFileColumnDefinition res("file_row_number", LogicalType::BIGINT); - res.identifier = Value::INTEGER(ParquetReader::ORDINAL_FIELD_ID); - schema_col_names.push_back(res.name); - schema_col_types.push_back(res.type); - reader_bind.schema.emplace_back(std::move(res)); + bind_data.schema.emplace_back(std::move(res)); } if (match_by_field_id) { - reader_bind.mapping = MultiFileColumnMappingMode::BY_FIELD_ID; + bind_data.mapping = MultiFileReaderColumnMappingMode::BY_FIELD_ID; } else { - reader_bind.mapping = MultiFileColumnMappingMode::BY_NAME; + bind_data.mapping = MultiFileReaderColumnMappingMode::BY_NAME; } // perform the binding on the obtained set of names + types - bind_data.multi_file_reader->BindOptions(file_options, *bind_data.file_list, schema_col_types, schema_col_names, - reader_bind); + result.multi_file_reader->BindOptions(options.file_options, *result.file_list, schema_col_types, schema_col_names, + bind_data); names = schema_col_names; return_types = schema_col_types; D_ASSERT(names.size() == return_types.size()); + + ParseFileRowNumberOption(bind_data, options, return_types, names); + + return bind_data; } -void ParquetMultiFileInfo::BindReader(ClientContext &context, vector &return_types, vector &names, - MultiFileBindData &bind_data) { - auto &parquet_bind = bind_data.bind_data->Cast(); - auto &options = parquet_bind.parquet_options; - if (!options.schema.empty()) { - BindSchema(context, return_types, names, bind_data); - } else { - bind_data.reader_bind = bind_data.multi_file_reader->BindReader( - context, return_types, names, *bind_data.file_list, bind_data, options, bind_data.file_options); - } +static void InitializeParquetReader(ParquetReader &reader, const ParquetReadBindData &bind_data, + const vector &global_column_ids, + optional_ptr table_filters, ClientContext &context, + optional_idx file_idx, optional_ptr reader_state) { + auto &parquet_options = bind_data.parquet_options; + auto &reader_data = reader.reader_data; + + reader.table_columns = bind_data.table_columns; + // Mark the file in the file list we are scanning here + reader_data.file_list_idx = file_idx; + + // 'reader_bind.schema' could be set explicitly by: + // 1. The MultiFileReader::Bind call + // 2. The 'schema' parquet option + auto &global_columns = bind_data.reader_bind.schema.empty() ? bind_data.columns : bind_data.reader_bind.schema; + bind_data.multi_file_reader->InitializeReader(reader, parquet_options.file_options, bind_data.reader_bind, + global_columns, global_column_ids, table_filters, + bind_data.file_list->GetFirstFile(), context, reader_state); } -static bool GetBooleanArgument(const string &key, const vector &option_values) { - if (option_values.empty()) { +static bool GetBooleanArgument(const pair> &option) { + if (option.second.empty()) { return true; } Value boolean_value; string error_message; - if (!option_values[0].DefaultTryCastAs(LogicalType::BOOLEAN, boolean_value, &error_message)) { + if (!option.second[0].DefaultTryCastAs(LogicalType::BOOLEAN, boolean_value, &error_message)) { throw InvalidInputException("Unable to cast \"%s\" to BOOLEAN for Parquet option \"%s\"", - option_values[0].ToString(), key); + option.second[0].ToString(), option.first); } return BooleanValue::Get(boolean_value); } +TablePartitionInfo ParquetGetPartitionInfo(ClientContext &context, TableFunctionPartitionInput &input) { + auto &parquet_bind = input.bind_data->Cast(); + return parquet_bind.multi_file_reader->GetPartitionInfo(context, parquet_bind.reader_bind, input); +} + class ParquetScanFunction { public: static TableFunctionSet GetFunctionSet() { - MultiFileFunction table_function("parquet_scan"); + TableFunction table_function("parquet_scan", {LogicalType::VARCHAR}, ParquetScanImplementation, ParquetScanBind, + ParquetScanInitGlobal, ParquetScanInitLocal); + table_function.statistics = ParquetScanStats; + table_function.cardinality = ParquetCardinality; + table_function.table_scan_progress = ParquetProgress; table_function.named_parameters["binary_as_string"] = LogicalType::BOOLEAN; table_function.named_parameters["file_row_number"] = LogicalType::BOOLEAN; table_function.named_parameters["debug_use_openssl"] = LogicalType::BOOLEAN; @@ -246,13 +375,156 @@ class ParquetScanFunction { table_function.named_parameters["schema"] = LogicalTypeId::ANY; table_function.named_parameters["encryption_config"] = LogicalTypeId::ANY; table_function.named_parameters["parquet_version"] = LogicalType::VARCHAR; - table_function.statistics = MultiFileFunction::MultiFileScanStats; + table_function.get_partition_data = ParquetScanGetPartitionData; table_function.serialize = ParquetScanSerialize; table_function.deserialize = ParquetScanDeserialize; + table_function.get_bind_info = ParquetGetBindInfo; + table_function.projection_pushdown = true; table_function.filter_pushdown = true; table_function.filter_prune = true; + table_function.pushdown_complex_filter = ParquetComplexFilterPushdown; + table_function.get_partition_info = ParquetGetPartitionInfo; + + MultiFileReader::AddParameters(table_function); + + return MultiFileReader::CreateFunctionSet(table_function); + } + + static unique_ptr ParquetReadBind(ClientContext &context, CopyInfo &info, + vector &expected_names, + vector &expected_types) { + D_ASSERT(expected_names.size() == expected_types.size()); + ParquetOptions parquet_options(context); + + for (auto &option : info.options) { + auto loption = StringUtil::Lower(option.first); + if (loption == "compression" || loption == "codec" || loption == "row_group_size") { + // CODEC/COMPRESSION and ROW_GROUP_SIZE options have no effect on parquet read. + // These options are determined from the file. + continue; + } else if (loption == "binary_as_string") { + parquet_options.binary_as_string = GetBooleanArgument(option); + } else if (loption == "file_row_number") { + parquet_options.file_row_number = GetBooleanArgument(option); + } else if (loption == "debug_use_openssl") { + parquet_options.debug_use_openssl = GetBooleanArgument(option); + } else if (loption == "encryption_config") { + if (option.second.size() != 1) { + throw BinderException("Parquet encryption_config cannot be empty!"); + } + parquet_options.encryption_config = ParquetEncryptionConfig::Create(context, option.second[0]); + } else { + throw NotImplementedException("Unsupported option for COPY FROM parquet: %s", option.first); + } + } + + // TODO: Allow overriding the MultiFileReader for COPY FROM? + auto multi_file_reader = MultiFileReader::CreateDefault("ParquetCopy"); + vector paths = {info.file_path}; + auto file_list = multi_file_reader->CreateFileList(context, paths); + + return ParquetScanBindInternal(context, std::move(multi_file_reader), std::move(file_list), expected_types, + expected_names, parquet_options); + } + + static unique_ptr ParquetScanStats(ClientContext &context, const FunctionData *bind_data_p, + column_t column_index) { + auto &bind_data = bind_data_p->Cast(); + + if (IsRowIdColumnId(column_index)) { + return nullptr; + } + + // NOTE: we do not want to parse the Parquet metadata for the sole purpose of getting column statistics + if (bind_data.file_list->GetExpandResult() == FileExpandResult::MULTIPLE_FILES) { + // multiple files, no luck! + return nullptr; + } + if (!bind_data.initial_reader) { + // no reader + return nullptr; + } + // scanning single parquet file and we have the metadata read already + return bind_data.initial_reader->ReadStatistics(bind_data.names[column_index]); + + return nullptr; + } + + static unique_ptr ParquetScanBindInternal(ClientContext &context, + unique_ptr multi_file_reader, + shared_ptr file_list, + vector &return_types, vector &names, + ParquetOptions parquet_options) { + auto result = make_uniq(); + result->multi_file_reader = std::move(multi_file_reader); + result->file_list = std::move(file_list); + + bool bound_on_first_file = true; + if (result->multi_file_reader->Bind(parquet_options.file_options, *result->file_list, result->types, + result->names, result->reader_bind)) { + result->multi_file_reader->BindOptions(parquet_options.file_options, *result->file_list, result->types, + result->names, result->reader_bind); + // Enable the parquet file_row_number on the parquet options if the file_row_number_idx was set + if (result->reader_bind.file_row_number_idx != DConstants::INVALID_INDEX) { + parquet_options.file_row_number = true; + } + bound_on_first_file = false; + } else if (!parquet_options.schema.empty()) { + // A schema was supplied: use the schema for binding + result->reader_bind = BindSchema(context, result->types, result->names, *result, parquet_options); + } else { + parquet_options.file_options.AutoDetectHivePartitioning(*result->file_list, context); + // Default bind + result->reader_bind = result->multi_file_reader->BindReader( + context, result->types, result->names, *result->file_list, *result, parquet_options); + } + + // Set the explicit cardinality if requested + if (parquet_options.explicit_cardinality) { + auto file_count = result->file_list->GetTotalFileCount(); + result->explicit_cardinality = parquet_options.explicit_cardinality; + result->initial_file_cardinality = result->explicit_cardinality / (file_count ? file_count : 1); + } - return MultiFileReader::CreateFunctionSet(static_cast(table_function)); + if (return_types.empty()) { + // no expected types - just copy the types + return_types = result->types; + names = result->names; + } else { + // We're deserializing from a previously successful bind call + // verify that the amount of columns still matches + if (return_types.size() != result->types.size()) { + auto file_string = bound_on_first_file ? result->file_list->GetFirstFile() + : StringUtil::Join(result->file_list->GetPaths(), ","); + string extended_error; + extended_error = "Table schema: "; + for (idx_t col_idx = 0; col_idx < return_types.size(); col_idx++) { + if (col_idx > 0) { + extended_error += ", "; + } + extended_error += names[col_idx] + " " + return_types[col_idx].ToString(); + } + extended_error += "\nParquet schema: "; + for (idx_t col_idx = 0; col_idx < result->types.size(); col_idx++) { + if (col_idx > 0) { + extended_error += ", "; + } + extended_error += result->names[col_idx] + " " + result->types[col_idx].ToString(); + } + extended_error += "\n\nPossible solutions:"; + extended_error += "\n* Manually specify which columns to insert using \"INSERT INTO tbl SELECT ... " + "FROM read_parquet(...)\""; + throw ConversionException( + "Failed to read file(s) \"%s\" - column count mismatch: expected %d columns but found %d\n%s", + file_string, return_types.size(), result->types.size(), extended_error); + } + // expected types - overwrite the types we want to read instead + result->types = return_types; + result->table_columns = names; + } + result->parquet_options = parquet_options; + result->columns = MultiFileReaderColumnDefinition::ColumnsFromNamesAndTypes(result->names, result->types); + return std::move(result); } static void VerifyParquetSchemaParameter(const Value &schema) { @@ -301,16 +573,218 @@ class ParquetScanFunction { } } + static unique_ptr ParquetScanBind(ClientContext &context, TableFunctionBindInput &input, + vector &return_types, vector &names) { + auto multi_file_reader = MultiFileReader::Create(input.table_function); + + ParquetOptions parquet_options(context); + for (auto &kv : input.named_parameters) { + if (kv.second.IsNull()) { + throw BinderException("Cannot use NULL as function argument"); + } + auto loption = StringUtil::Lower(kv.first); + if (multi_file_reader->ParseOption(kv.first, kv.second, parquet_options.file_options, context)) { + continue; + } + if (loption == "binary_as_string") { + parquet_options.binary_as_string = BooleanValue::Get(kv.second); + } else if (loption == "file_row_number") { + parquet_options.file_row_number = BooleanValue::Get(kv.second); + } else if (loption == "debug_use_openssl") { + parquet_options.debug_use_openssl = BooleanValue::Get(kv.second); + } else if (loption == "schema") { + // Argument is a map that defines the schema + const auto &schema_value = kv.second; + VerifyParquetSchemaParameter(schema_value); + const auto column_values = ListValue::GetChildren(schema_value); + if (column_values.empty()) { + throw BinderException("Parquet schema cannot be empty"); + } + parquet_options.schema.reserve(column_values.size()); + for (idx_t i = 0; i < column_values.size(); i++) { + parquet_options.schema.emplace_back( + ParquetColumnDefinition::FromSchemaValue(context, column_values[i])); + } + + // cannot be combined with hive_partitioning=true, so we disable auto-detection + parquet_options.file_options.auto_detect_hive_partitioning = false; + } else if (loption == "explicit_cardinality") { + parquet_options.explicit_cardinality = UBigIntValue::Get(kv.second); + } else if (loption == "encryption_config") { + parquet_options.encryption_config = ParquetEncryptionConfig::Create(context, kv.second); + } + } + + auto file_list = multi_file_reader->CreateFileList(context, input.inputs[0]); + return ParquetScanBindInternal(context, std::move(multi_file_reader), std::move(file_list), return_types, names, + parquet_options); + } + + static double ParquetProgress(ClientContext &context, const FunctionData *bind_data_p, + const GlobalTableFunctionState *global_state) { + auto &bind_data = bind_data_p->Cast(); + auto &gstate = global_state->Cast(); + + auto total_count = gstate.file_list.GetTotalFileCount(); + if (total_count == 0) { + return 100.0; + } + if (bind_data.initial_file_cardinality == 0) { + return (100.0 * (static_cast(gstate.file_index) + 1.0)) / static_cast(total_count); + } + auto percentage = MinValue(100.0, (static_cast(bind_data.chunk_count) * STANDARD_VECTOR_SIZE * + 100.0 / static_cast(bind_data.initial_file_cardinality))); + return (percentage + 100.0 * static_cast(gstate.file_index)) / static_cast(total_count); + } + + static unique_ptr + ParquetScanInitLocal(ExecutionContext &context, TableFunctionInitInput &input, GlobalTableFunctionState *gstate_p) { + auto &bind_data = input.bind_data->Cast(); + auto &gstate = gstate_p->Cast(); + + auto result = make_uniq(); + result->is_parallel = true; + result->batch_index = 0; + + if (gstate.CanRemoveColumns()) { + result->all_columns.Initialize(context.client, gstate.scanned_types); + } + if (!ParquetParallelStateNext(context.client, bind_data, *result, gstate)) { + return nullptr; + } + return std::move(result); + } + + static unique_ptr ParquetDynamicFilterPushdown(ClientContext &context, + const ParquetReadBindData &data, + const vector &column_ids, + optional_ptr filters) { + if (!filters) { + return nullptr; + } + auto new_list = data.multi_file_reader->DynamicFilterPushdown( + context, *data.file_list, data.parquet_options.file_options, data.names, data.types, column_ids, *filters); + return new_list; + } + + static unique_ptr ParquetScanInitGlobal(ClientContext &context, + TableFunctionInitInput &input) { + auto &bind_data = input.bind_data->CastNoConst(); + unique_ptr result; + + // before instantiating a scan trigger a dynamic filter pushdown if possible + auto new_list = ParquetDynamicFilterPushdown(context, bind_data, input.column_ids, input.filters); + if (new_list) { + result = make_uniq(std::move(new_list)); + } else { + result = make_uniq(*bind_data.file_list); + } + auto &file_list = result->file_list; + file_list.InitializeScan(result->file_list_scan); + + auto &global_columns = bind_data.reader_bind.schema.empty() ? bind_data.columns : bind_data.reader_bind.schema; + result->multi_file_reader_state = bind_data.multi_file_reader->InitializeGlobalState( + context, bind_data.parquet_options.file_options, bind_data.reader_bind, file_list, global_columns, + input.column_indexes); + + if (file_list.IsEmpty()) { + result->readers = {}; + } else if (!bind_data.union_readers.empty()) { + // TODO: confirm we are not changing behaviour by modifying the order here? + for (auto &reader : bind_data.union_readers) { + if (!reader) { + break; + } + result->readers.push_back(make_uniq(std::move(reader))); + } + if (result->readers.size() != file_list.GetTotalFileCount()) { + // This case happens with recursive CTEs: the first execution the readers have already + // been moved out of the bind data. + // FIXME: clean up this process and make it more explicit + result->readers = {}; + } + } else if (bind_data.initial_reader) { + // we can only use the initial reader if it was constructed from the first file + if (bind_data.initial_reader->file_name == file_list.GetFirstFile()) { + result->readers.push_back(make_uniq(std::move(bind_data.initial_reader))); + } + } + + // Ensure all readers are initialized and FileListScan is sync with readers list + for (auto &reader_data : result->readers) { + string file_name; + idx_t file_idx = result->file_list_scan.current_file_idx; + file_list.Scan(result->file_list_scan, file_name); + if (reader_data->union_data) { + if (file_name != reader_data->union_data->GetFileName()) { + throw InternalException("Mismatch in filename order and union reader order in parquet scan"); + } + } else { + D_ASSERT(reader_data->reader); + if (file_name != reader_data->reader->file_name) { + throw InternalException("Mismatch in filename order and reader order in parquet scan"); + } + InitializeParquetReader(*reader_data->reader, bind_data, input.column_indexes, input.filters, context, + file_idx, result->multi_file_reader_state); + } + } + + result->column_indexes = input.column_indexes; + result->filters = input.filters.get(); + result->row_group_index = 0; + result->file_index = 0; + result->batch_index = 0; + result->max_threads = ParquetScanMaxThreads(context, input.bind_data.get()); + + bool require_extra_columns = + result->multi_file_reader_state && result->multi_file_reader_state->RequiresExtraColumns(); + if (input.CanRemoveFilterColumns() || require_extra_columns) { + if (!input.projection_ids.empty()) { + result->projection_ids = input.projection_ids; + } else { + result->projection_ids.resize(input.column_indexes.size()); + iota(begin(result->projection_ids), end(result->projection_ids), 0); + } + + const auto table_types = bind_data.types; + for (const auto &col_idx : input.column_indexes) { + if (col_idx.IsRowIdColumn()) { + result->scanned_types.emplace_back(LogicalType::ROW_TYPE); + } else { + result->scanned_types.push_back(table_types[col_idx.GetPrimaryIndex()]); + } + } + } + + if (require_extra_columns) { + for (const auto &column_type : result->multi_file_reader_state->extra_columns) { + result->scanned_types.push_back(column_type); + } + } + + return std::move(result); + } + + static OperatorPartitionData ParquetScanGetPartitionData(ClientContext &context, + TableFunctionGetPartitionInput &input) { + auto &bind_data = input.bind_data->CastNoConst(); + auto &data = input.local_state->Cast(); + auto &gstate = input.global_state->Cast(); + OperatorPartitionData partition_data(data.batch_index); + bind_data.multi_file_reader->GetPartitionData(context, bind_data.reader_bind, data.reader->reader_data, + gstate.multi_file_reader_state, input.partition_info, + partition_data); + return partition_data; + } + static void ParquetScanSerialize(Serializer &serializer, const optional_ptr bind_data_p, const TableFunction &function) { - auto &bind_data = bind_data_p->Cast(); - auto &parquet_data = bind_data.bind_data->Cast(); + auto &bind_data = bind_data_p->Cast(); serializer.WriteProperty(100, "files", bind_data.file_list->GetAllFiles()); serializer.WriteProperty(101, "types", bind_data.types); serializer.WriteProperty(102, "names", bind_data.names); - ParquetOptionsSerialization serialization(parquet_data.parquet_options, bind_data.file_options); - serializer.WriteProperty(103, "parquet_options", serialization); + serializer.WriteProperty(103, "parquet_options", bind_data.parquet_options); if (serializer.ShouldSerialize(3)) { serializer.WriteProperty(104, "table_columns", bind_data.table_columns); } @@ -321,7 +795,7 @@ class ParquetScanFunction { auto files = deserializer.ReadProperty>(100, "files"); auto types = deserializer.ReadProperty>(101, "types"); auto names = deserializer.ReadProperty>(102, "names"); - auto serialization = deserializer.ReadProperty(103, "parquet_options"); + auto parquet_options = deserializer.ReadProperty(103, "parquet_options"); auto table_columns = deserializer.ReadPropertyWithExplicitDefault>(104, "table_columns", vector {}); @@ -333,265 +807,228 @@ class ParquetScanFunction { auto multi_file_reader = MultiFileReader::Create(function); auto file_list = multi_file_reader->CreateFileList(context, Value::LIST(LogicalType::VARCHAR, file_path), FileGlobOptions::DISALLOW_EMPTY); - auto parquet_options = make_uniq(std::move(serialization.parquet_options)); - auto bind_data = MultiFileFunction::MultiFileBindInternal( - context, std::move(multi_file_reader), std::move(file_list), types, names, - std::move(serialization.file_options), std::move(parquet_options)); - bind_data->Cast().table_columns = std::move(table_columns); + auto bind_data = ParquetScanBindInternal(context, std::move(multi_file_reader), std::move(file_list), types, + names, parquet_options); + bind_data->Cast().table_columns = std::move(table_columns); return bind_data; } -}; -unique_ptr ParquetMultiFileInfo::InitializeOptions(ClientContext &context, - optional_ptr info) { - return make_uniq(context); -} + static void ParquetScanImplementation(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { + if (!data_p.local_state) { + return; + } + auto &data = data_p.local_state->Cast(); + auto &gstate = data_p.global_state->Cast(); + auto &bind_data = data_p.bind_data->CastNoConst(); + + bool rowgroup_finished; + do { + if (gstate.CanRemoveColumns()) { + data.all_columns.Reset(); + data.reader->Scan(data.scan_state, data.all_columns); + rowgroup_finished = data.all_columns.size() == 0; + bind_data.multi_file_reader->FinalizeChunk(context, bind_data.reader_bind, data.reader->reader_data, + data.all_columns, gstate.multi_file_reader_state); + output.ReferenceColumns(data.all_columns, gstate.projection_ids); + } else { + data.reader->Scan(data.scan_state, output); + rowgroup_finished = output.size() == 0; + bind_data.multi_file_reader->FinalizeChunk(context, bind_data.reader_bind, data.reader->reader_data, + output, gstate.multi_file_reader_state); + } -bool ParquetMultiFileInfo::ParseCopyOption(ClientContext &context, const string &key, const vector &values, - BaseFileReaderOptions &file_options, vector &expected_names, - vector &expected_types) { - auto &parquet_options = file_options.Cast(); - auto &options = parquet_options.options; - if (key == "compression" || key == "codec" || key == "row_group_size") { - // CODEC/COMPRESSION and ROW_GROUP_SIZE options have no effect on parquet read. - // These options are determined from the file. - return true; - } - if (key == "binary_as_string") { - options.binary_as_string = GetBooleanArgument(key, values); - return true; - } - if (key == "file_row_number") { - options.file_row_number = GetBooleanArgument(key, values); - return true; - } - if (key == "debug_use_openssl") { - options.debug_use_openssl = GetBooleanArgument(key, values); - return true; + bind_data.chunk_count++; + if (output.size() > 0) { + return; + } + if (rowgroup_finished && !ParquetParallelStateNext(context, bind_data, data, gstate)) { + return; + } + } while (true); } - if (key == "encryption_config") { - if (values.size() != 1) { - throw BinderException("Parquet encryption_config cannot be empty!"); + + static unique_ptr ParquetCardinality(ClientContext &context, const FunctionData *bind_data) { + auto &data = bind_data->Cast(); + if (data.explicit_cardinality) { + return make_uniq(data.explicit_cardinality); } - options.encryption_config = ParquetEncryptionConfig::Create(context, values[0]); - return true; + auto file_list_cardinality_estimate = data.file_list->GetCardinality(context); + if (file_list_cardinality_estimate) { + return file_list_cardinality_estimate; + } + return make_uniq(MaxValue(data.initial_file_cardinality, (idx_t)1) * + data.file_list->GetTotalFileCount()); } - return false; -} -void ParquetMultiFileInfo::FinalizeCopyBind(ClientContext &context, BaseFileReaderOptions &options_p, - const vector &expected_names, - const vector &expected_types) { -} + static idx_t ParquetScanMaxThreads(ClientContext &context, const FunctionData *bind_data) { + auto &data = bind_data->Cast(); -bool ParquetMultiFileInfo::ParseOption(ClientContext &context, const string &original_key, const Value &val, - MultiFileOptions &file_options, BaseFileReaderOptions &base_options) { - auto &parquet_options = base_options.Cast(); - auto &options = parquet_options.options; - auto key = StringUtil::Lower(original_key); - if (val.IsNull()) { - throw BinderException("Cannot use NULL as argument to %s", original_key); - } - if (key == "compression") { - // COMPRESSION has no effect on parquet read. - // These options are determined from the file. - return true; - } - if (key == "binary_as_string") { - options.binary_as_string = BooleanValue::Get(val); - return true; - } - if (key == "file_row_number") { - options.file_row_number = BooleanValue::Get(val); - return true; - } - if (key == "debug_use_openssl") { - options.debug_use_openssl = BooleanValue::Get(val); - return true; - } - if (key == "schema") { - // Argument is a map that defines the schema - const auto &schema_value = val; - ParquetScanFunction::VerifyParquetSchemaParameter(schema_value); - const auto column_values = ListValue::GetChildren(schema_value); - if (column_values.empty()) { - throw BinderException("Parquet schema cannot be empty"); - } - options.schema.reserve(column_values.size()); - for (idx_t i = 0; i < column_values.size(); i++) { - options.schema.emplace_back(ParquetColumnDefinition::FromSchemaValue(context, column_values[i])); + if (data.file_list->GetExpandResult() == FileExpandResult::MULTIPLE_FILES) { + return TaskScheduler::GetScheduler(context).NumberOfThreads(); } - file_options.auto_detect_hive_partitioning = false; - return true; - } - if (key == "explicit_cardinality") { - options.explicit_cardinality = UBigIntValue::Get(val); - return true; - } - if (key == "encryption_config") { - options.encryption_config = ParquetEncryptionConfig::Create(context, val); - return true; - } - return false; -} -unique_ptr ParquetMultiFileInfo::InitializeBindData(MultiFileBindData &multi_file_data, - unique_ptr options_p) { - auto result = make_uniq(); - // Set the explicit cardinality if requested - auto &options = options_p->Cast(); - result->parquet_options = std::move(options.options); - if (result->parquet_options.explicit_cardinality) { - auto file_count = multi_file_data.file_list->GetTotalFileCount(); - result->explicit_cardinality = result->parquet_options.explicit_cardinality; - result->initial_file_cardinality = result->explicit_cardinality / (file_count ? file_count : 1); + return MaxValue(data.initial_file_row_groups, (idx_t)1); } - return std::move(result); -} -void ParquetMultiFileInfo::GetBindInfo(const TableFunctionData &bind_data_p, BindInfo &info) { - auto &bind_data = bind_data_p.Cast(); - info.type = ScanType::PARQUET; - info.InsertOption("binary_as_string", Value::BOOLEAN(bind_data.parquet_options.binary_as_string)); - info.InsertOption("file_row_number", Value::BOOLEAN(bind_data.parquet_options.file_row_number)); - info.InsertOption("debug_use_openssl", Value::BOOLEAN(bind_data.parquet_options.debug_use_openssl)); -} + // Queries the metadataprovider for another file to scan, updating the files/reader lists in the process. + // Returns true if resized + static bool ResizeFiles(ParquetReadGlobalState ¶llel_state) { + string scanned_file; + if (!parallel_state.file_list.Scan(parallel_state.file_list_scan, scanned_file)) { + return false; + } -optional_idx ParquetMultiFileInfo::MaxThreads(const MultiFileBindData &bind_data_p, - const MultiFileGlobalState &global_state, - FileExpandResult expand_result) { - if (expand_result == FileExpandResult::MULTIPLE_FILES) { - // always launch max threads if we are reading multiple files - return optional_idx(); - } - auto &bind_data = bind_data_p.bind_data->Cast(); - return MaxValue(bind_data.initial_file_row_groups, static_cast(1)); -} + // Push the file in the reader data, to be opened later + parallel_state.readers.push_back(make_uniq(scanned_file)); -void ParquetMultiFileInfo::FinalizeBindData(MultiFileBindData &multi_file_data) { - auto &bind_data = multi_file_data.bind_data->Cast(); - if (multi_file_data.initial_reader) { - auto &initial_reader = multi_file_data.initial_reader->Cast(); - bind_data.initial_file_cardinality = initial_reader.NumRows(); - bind_data.initial_file_row_groups = initial_reader.NumRowGroups(); - bind_data.parquet_options = initial_reader.parquet_options; + return true; } -} -unique_ptr ParquetMultiFileInfo::GetCardinality(const MultiFileBindData &bind_data_p, - idx_t file_count) { - auto &bind_data = bind_data_p.bind_data->Cast(); - if (bind_data.explicit_cardinality) { - return make_uniq(bind_data.explicit_cardinality); - } - return make_uniq(MaxValue(bind_data.initial_file_cardinality, (idx_t)1) * file_count); -} + // This function looks for the next available row group. If not available, it will open files from bind_data.files + // until there is a row group available for scanning or the files runs out + static bool ParquetParallelStateNext(ClientContext &context, const ParquetReadBindData &bind_data, + ParquetReadLocalState &scan_data, ParquetReadGlobalState ¶llel_state) { + unique_lock parallel_lock(parallel_state.lock); -unique_ptr ParquetMultiFileInfo::GetStatistics(ClientContext &context, BaseFileReader &reader_p, - const string &name) { - auto &reader = reader_p.Cast(); - return reader.ReadStatistics(name); -} + while (true) { + if (parallel_state.error_opening_file) { + return false; + } -double ParquetMultiFileInfo::GetProgressInFile(ClientContext &context, const BaseFileReader &reader) { - auto &parquet_reader = reader.Cast(); - auto read_rows = parquet_reader.rows_read.load(); - return 100.0 * (static_cast(read_rows) / static_cast(parquet_reader.NumRows())); -} + if (parallel_state.file_index >= parallel_state.readers.size() && !ResizeFiles(parallel_state)) { + return false; + } -void ParquetMultiFileInfo::GetVirtualColumns(ClientContext &, MultiFileBindData &, virtual_column_map_t &result) { - result.insert(make_pair(MultiFileReader::COLUMN_IDENTIFIER_FILE_ROW_NUMBER, - TableColumn("file_row_number", LogicalType::BIGINT))); -} + auto ¤t_reader_data = *parallel_state.readers[parallel_state.file_index]; + if (current_reader_data.file_state == ParquetFileState::OPEN) { + if (parallel_state.row_group_index < current_reader_data.reader->NumRowGroups()) { + // The current reader has rowgroups left to be scanned + scan_data.reader = current_reader_data.reader; + vector group_indexes {parallel_state.row_group_index}; + scan_data.reader->InitializeScan(context, scan_data.scan_state, group_indexes); + scan_data.batch_index = parallel_state.batch_index++; + scan_data.file_index = parallel_state.file_index; + parallel_state.row_group_index++; + return true; + } else { + // Close current file + current_reader_data.file_state = ParquetFileState::CLOSED; + current_reader_data.reader = nullptr; -shared_ptr ParquetMultiFileInfo::CreateReader(ClientContext &context, GlobalTableFunctionState &, - BaseUnionData &union_data_p, - const MultiFileBindData &bind_data_p) { - auto &union_data = union_data_p.Cast(); - return make_shared_ptr(context, union_data.file_name, union_data.options, union_data.metadata); -} + // Set state to the next file + parallel_state.file_index++; + parallel_state.row_group_index = 0; -shared_ptr ParquetMultiFileInfo::CreateReader(ClientContext &context, GlobalTableFunctionState &, - const string &filename, idx_t file_idx, - const MultiFileBindData &multi_bind_data) { - auto &bind_data = multi_bind_data.bind_data->Cast(); - return make_shared_ptr(context, filename, bind_data.parquet_options); -} + continue; + } + } -shared_ptr ParquetMultiFileInfo::CreateReader(ClientContext &context, const string &filename, - ParquetOptions &options, const MultiFileOptions &) { - return make_shared_ptr(context, filename, options); -} + if (TryOpenNextFile(context, bind_data, scan_data, parallel_state, parallel_lock)) { + continue; + } -shared_ptr ParquetMultiFileInfo::GetUnionData(shared_ptr scan_p, idx_t file_idx) { - auto &scan = scan_p->Cast(); - auto result = make_uniq(scan.file_name); - if (file_idx == 0) { - for (auto &column : scan.columns) { - result->names.push_back(column.name); - result->types.push_back(column.type); - } - result->options = scan.parquet_options; - result->metadata = scan.metadata; - result->reader = std::move(scan_p); - } else { - for (auto &column : scan.columns) { - result->names.push_back(column.name); - result->types.push_back(column.type); + // Check if the current file is being opened, in that case we need to wait for it. + if (current_reader_data.file_state == ParquetFileState::OPENING) { + WaitForFile(parallel_state.file_index, parallel_state, parallel_lock); + } } - scan.columns.clear(); - result->options = std::move(scan.parquet_options); - result->metadata = std::move(scan.metadata); } - return std::move(result); -} + static void ParquetComplexFilterPushdown(ClientContext &context, LogicalGet &get, FunctionData *bind_data_p, + vector> &filters) { + auto &data = bind_data_p->Cast(); -void ParquetMultiFileInfo::FinalizeReader(ClientContext &context, BaseFileReader &reader, GlobalTableFunctionState &) { -} + MultiFilePushdownInfo info(get); + auto new_list = data.multi_file_reader->ComplexFilterPushdown(context, *data.file_list, + data.parquet_options.file_options, info, filters); -unique_ptr ParquetMultiFileInfo::InitializeGlobalState(ClientContext &, MultiFileBindData &, - MultiFileGlobalState &) { - return make_uniq(); -} - -unique_ptr ParquetMultiFileInfo::InitializeLocalState(ExecutionContext &, - GlobalTableFunctionState &) { - return make_uniq(); -} + if (new_list) { + data.file_list = std::move(new_list); + MultiFileReader::PruneReaders(data, *data.file_list); + } + } -bool ParquetMultiFileInfo::TryInitializeScan(ClientContext &context, shared_ptr &reader_p, - GlobalTableFunctionState &gstate_p, LocalTableFunctionState &lstate_p) { - auto &gstate = gstate_p.Cast(); - auto &lstate = lstate_p.Cast(); - auto &reader = reader_p->Cast(); - if (gstate.row_group_index >= reader.NumRowGroups()) { - // scanned all row groups in this file - return false; + //! Wait for a file to become available. Parallel lock should be locked when calling. + static void WaitForFile(idx_t file_index, ParquetReadGlobalState ¶llel_state, + unique_lock ¶llel_lock) { + while (true) { + // Get pointer to file mutex before unlocking + auto &file_mutex = *parallel_state.readers[file_index]->file_mutex; + + // To get the file lock, we first need to release the parallel_lock to prevent deadlocking. Note that this + // requires getting the ref to the file mutex pointer with the lock stil held: readers get be resized + parallel_lock.unlock(); + unique_lock current_file_lock(file_mutex); + parallel_lock.lock(); + + // Here we have both locks which means we can stop waiting if: + // - the thread opening the file is done and the file is available + // - the thread opening the file has failed + // - the file was somehow scanned till the end while we were waiting + if (parallel_state.file_index >= parallel_state.readers.size() || + parallel_state.readers[parallel_state.file_index]->file_state != ParquetFileState::OPENING || + parallel_state.error_opening_file) { + return; + } + } } - // The current reader has rowgroups left to be scanned - vector group_indexes {gstate.row_group_index}; - reader.InitializeScan(context, lstate.scan_state, group_indexes); - gstate.row_group_index++; - return true; -} -void ParquetMultiFileInfo::FinishFile(ClientContext &context, GlobalTableFunctionState &gstate_p, - BaseFileReader &reader) { - auto &gstate = gstate_p.Cast(); - gstate.row_group_index = 0; -} + //! Helper function that try to start opening a next file. Parallel lock should be locked when calling. + static bool TryOpenNextFile(ClientContext &context, const ParquetReadBindData &bind_data, + ParquetReadLocalState &scan_data, ParquetReadGlobalState ¶llel_state, + unique_lock ¶llel_lock) { + const auto file_index_limit = + parallel_state.file_index + TaskScheduler::GetScheduler(context).NumberOfThreads(); -void ParquetMultiFileInfo::FinishReading(ClientContext &context, GlobalTableFunctionState &global_state, - LocalTableFunctionState &local_state) { -} + for (idx_t i = parallel_state.file_index; i < file_index_limit; i++) { + // We check if we can resize files in this loop too otherwise we will only ever open 1 file ahead + if (i >= parallel_state.readers.size() && !ResizeFiles(parallel_state)) { + return false; + } -void ParquetMultiFileInfo::Scan(ClientContext &context, BaseFileReader &reader_p, GlobalTableFunctionState &gstate_p, - LocalTableFunctionState &local_state_p, DataChunk &chunk) { - auto &local_state = local_state_p.Cast(); - auto &reader = reader_p.Cast(); - reader.Scan(context, local_state.scan_state, chunk); -} + auto ¤t_reader_data = *parallel_state.readers[i]; + if (current_reader_data.file_state == ParquetFileState::UNOPENED) { + current_reader_data.file_state = ParquetFileState::OPENING; + auto pq_options = bind_data.parquet_options; + + // Get pointer to file mutex before unlocking + auto ¤t_file_lock = *current_reader_data.file_mutex; + + // Now we switch which lock we are holding, instead of locking the global state, we grab the lock on + // the file we are opening. This file lock allows threads to wait for a file to be opened. + parallel_lock.unlock(); + unique_lock file_lock(current_file_lock); + + shared_ptr reader; + try { + if (current_reader_data.union_data) { + auto &union_data = *current_reader_data.union_data; + reader = make_shared_ptr(context, union_data.file_name, union_data.options, + union_data.metadata); + } else { + reader = + make_shared_ptr(context, current_reader_data.file_to_be_opened, pq_options); + } + InitializeParquetReader(*reader, bind_data, parallel_state.column_indexes, parallel_state.filters, + context, i, parallel_state.multi_file_reader_state); + } catch (...) { + parallel_lock.lock(); + parallel_state.error_opening_file = true; + throw; + } + + // Now re-lock the state and add the reader + parallel_lock.lock(); + current_reader_data.reader = std::move(reader); + current_reader_data.file_state = ParquetFileState::OPEN; + + return true; + } + } + + return false; + } +}; static case_insensitive_map_t GetChildNameToTypeMap(const LogicalType &type) { case_insensitive_map_t name_to_type_map; @@ -743,65 +1180,11 @@ static void GetFieldIDs(const Value &field_ids_value, ChildFieldIDs &field_ids, } } -struct ParquetWriteBindData : public TableFunctionData { - vector sql_types; - vector column_names; - duckdb_parquet::CompressionCodec::type codec = duckdb_parquet::CompressionCodec::SNAPPY; - vector> kv_metadata; - idx_t row_group_size = DEFAULT_ROW_GROUP_SIZE; - idx_t row_group_size_bytes = NumericLimits::Maximum(); - - //! How/Whether to encrypt the data - shared_ptr encryption_config; - bool debug_use_openssl = true; - - //! After how many distinct values should we abandon dictionary compression and bloom filters? - idx_t dictionary_size_limit = row_group_size / 20; - - void SetToDefaultDictionarySizeLimit() { - // This depends on row group size so we should "reset" if the row group size is changed - dictionary_size_limit = row_group_size / 20; - } - - idx_t string_dictionary_page_size_limit = 1048576; - - //! What false positive rate are we willing to accept for bloom filters - double bloom_filter_false_positive_ratio = 0.01; - - //! After how many row groups to rotate to a new file - optional_idx row_groups_per_file; - - ChildFieldIDs field_ids; - //! The compression level, higher value is more - int64_t compression_level = ZStdFileSystem::DefaultCompressionLevel(); - - //! Which encodings to include when writing - ParquetVersion parquet_version = ParquetVersion::V1; -}; - -struct ParquetWriteGlobalState : public GlobalFunctionData { - unique_ptr writer; - - mutex lock; - unique_ptr combine_buffer; -}; - -struct ParquetWriteLocalState : public LocalFunctionData { - explicit ParquetWriteLocalState(ClientContext &context, const vector &types) : buffer(context, types) { - buffer.SetPartitionIndex(0); // Makes the buffer manager less likely to spill this data - buffer.InitializeAppend(append_state); - } - - ColumnDataCollection buffer; - ColumnDataAppendState append_state; -}; - unique_ptr ParquetWriteBind(ClientContext &context, CopyFunctionBindInput &input, const vector &names, const vector &sql_types) { D_ASSERT(names.size() == sql_types.size()); bool row_group_size_bytes_set = false; bool compression_level_set = false; - bool dictionary_size_limit_set = false; auto bind_data = make_uniq(); for (auto &option : input.info.options) { const auto loption = StringUtil::Lower(option.first); @@ -811,9 +1194,6 @@ unique_ptr ParquetWriteBind(ClientContext &context, CopyFunctionBi } if (loption == "row_group_size" || loption == "chunk_size") { bind_data->row_group_size = option.second[0].GetValue(); - if (!dictionary_size_limit_set) { - bind_data->SetToDefaultDictionarySizeLimit(); - } } else if (loption == "row_group_size_bytes") { auto roption = option.second[0]; if (roption.GetTypeMutable().id() == LogicalTypeId::VARCHAR) { @@ -869,7 +1249,7 @@ unique_ptr ParquetWriteBind(ClientContext &context, CopyFunctionBi } auto values = StructValue::GetChildren(kv_struct); for (idx_t i = 0; i < values.size(); i++) { - auto &value = values[i]; + auto value = values[i]; auto key = StructType::GetChildName(kv_struct_type, i); // If the value is a blob, write the raw blob bytes // otherwise, cast to string @@ -889,14 +1269,6 @@ unique_ptr ParquetWriteBind(ClientContext &context, CopyFunctionBi throw BinderException("dictionary_size_limit must be greater than 0 or 0 to disable"); } bind_data->dictionary_size_limit = val; - dictionary_size_limit_set = true; - } else if (loption == "string_dictionary_page_size_limit") { - auto val = option.second[0].GetValue(); - if (val > PrimitiveDictionary::MAXIMUM_POSSIBLE_SIZE) { - throw BinderException("string_dictionary_page_size_limit must be less than or equal to %llu", - PrimitiveDictionary::MAXIMUM_POSSIBLE_SIZE); - } - bind_data->string_dictionary_page_size_limit = val; } else if (loption == "bloom_filter_false_positive_ratio") { auto val = option.second[0].GetValue(); if (val <= 0) { @@ -959,18 +1331,11 @@ unique_ptr ParquetWriteInitializeGlobal(ClientContext &conte global_state->writer = make_uniq( context, fs, file_path, parquet_bind.sql_types, parquet_bind.column_names, parquet_bind.codec, parquet_bind.field_ids.Copy(), parquet_bind.kv_metadata, parquet_bind.encryption_config, - parquet_bind.dictionary_size_limit, parquet_bind.string_dictionary_page_size_limit, - parquet_bind.bloom_filter_false_positive_ratio, parquet_bind.compression_level, parquet_bind.debug_use_openssl, - parquet_bind.parquet_version); + parquet_bind.dictionary_size_limit, parquet_bind.bloom_filter_false_positive_ratio, + parquet_bind.compression_level, parquet_bind.debug_use_openssl, parquet_bind.parquet_version); return std::move(global_state); } -void ParquetWriteGetWrittenStatistics(ClientContext &context, FunctionData &bind_data, GlobalFunctionData &gstate, - CopyFunctionFileStatistics &statistics) { - auto &global_state = gstate.Cast(); - global_state.writer->SetWrittenStatistics(statistics); -} - void ParquetWriteSink(ExecutionContext &context, FunctionData &bind_data_p, GlobalFunctionData &gstate, LocalFunctionData &lstate, DataChunk &input) { auto &bind_data = bind_data_p.Cast(); @@ -989,45 +1354,16 @@ void ParquetWriteSink(ExecutionContext &context, FunctionData &bind_data_p, Glob } } -void ParquetWriteCombine(ExecutionContext &context, FunctionData &bind_data_p, GlobalFunctionData &gstate, +void ParquetWriteCombine(ExecutionContext &context, FunctionData &bind_data, GlobalFunctionData &gstate, LocalFunctionData &lstate) { - auto &bind_data = bind_data_p.Cast(); auto &global_state = gstate.Cast(); auto &local_state = lstate.Cast(); - - if (local_state.buffer.Count() >= bind_data.row_group_size / 2 || - local_state.buffer.SizeInBytes() >= bind_data.row_group_size_bytes / 2) { - // local state buffer is more than half of the row_group_size(_bytes), just flush it - global_state.writer->Flush(local_state.buffer); - return; - } - - unique_lock guard(global_state.lock); - if (global_state.combine_buffer) { - // There is still some data, combine it - global_state.combine_buffer->Combine(local_state.buffer); - if (global_state.combine_buffer->Count() >= bind_data.row_group_size / 2 || - global_state.combine_buffer->SizeInBytes() >= bind_data.row_group_size_bytes / 2) { - // After combining, the combine buffer is more than half of the row_group_size(_bytes), so we flush - auto owned_combine_buffer = std::move(global_state.combine_buffer); - guard.unlock(); - // Lock free, of course - global_state.writer->Flush(*owned_combine_buffer); - } - return; - } - - global_state.combine_buffer = make_uniq(context.client, local_state.buffer.Types()); - global_state.combine_buffer->Combine(local_state.buffer); + // flush any data left in the local state to the file + global_state.writer->Flush(local_state.buffer); } void ParquetWriteFinalize(ClientContext &context, FunctionData &bind_data, GlobalFunctionData &gstate) { auto &global_state = gstate.Cast(); - // flush the combine buffer (if it's there) - if (global_state.combine_buffer) { - global_state.writer->Flush(*global_state.combine_buffer); - } - // finalize: write any additional metadata to the file here global_state.writer->Finalize(); } @@ -1174,9 +1510,6 @@ static void ParquetCopySerialize(Serializer &serializer, const FunctionData &bin default_value.bloom_filter_false_positive_ratio); serializer.WritePropertyWithDefault(114, "parquet_version", bind_data.parquet_version, default_value.parquet_version); - serializer.WritePropertyWithDefault(115, "string_dictionary_page_size_limit", - bind_data.string_dictionary_page_size_limit, - default_value.string_dictionary_page_size_limit); } static unique_ptr ParquetCopyDeserialize(Deserializer &deserializer, CopyFunction &function) { @@ -1207,8 +1540,6 @@ static unique_ptr ParquetCopyDeserialize(Deserializer &deserialize 113, "bloom_filter_false_positive_ratio", default_value.bloom_filter_false_positive_ratio); data->parquet_version = deserializer.ReadPropertyWithExplicitDefault(114, "parquet_version", default_value.parquet_version); - data->string_dictionary_page_size_limit = deserializer.ReadPropertyWithExplicitDefault( - 115, "string_dictionary_page_size_limit", default_value.string_dictionary_page_size_limit); return std::move(data); } @@ -1420,12 +1751,11 @@ void ParquetExtension::Load(DuckDB &db) { function.copy_to_bind = ParquetWriteBind; function.copy_to_initialize_global = ParquetWriteInitializeGlobal; function.copy_to_initialize_local = ParquetWriteInitializeLocal; - function.copy_to_get_written_statistics = ParquetWriteGetWrittenStatistics; function.copy_to_sink = ParquetWriteSink; function.copy_to_combine = ParquetWriteCombine; function.copy_to_finalize = ParquetWriteFinalize; function.execution_mode = ParquetWriteExecutionMode; - function.copy_from_bind = MultiFileFunction::MultiFileBindCopy; + function.copy_from_bind = ParquetScanFunction::ParquetReadBind; function.copy_from_function = scan_fun.functions[0]; function.prepare_batch = ParquetWritePrepareBatch; function.flush_batch = ParquetWriteFlushBatch; diff --git a/src/duckdb/extension/parquet/parquet_metadata.cpp b/src/duckdb/extension/parquet/parquet_metadata.cpp index 8bcef76ca..31c7d0870 100644 --- a/src/duckdb/extension/parquet/parquet_metadata.cpp +++ b/src/duckdb/extension/parquet/parquet_metadata.cpp @@ -5,7 +5,7 @@ #include #ifndef DUCKDB_AMALGAMATION -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/types/blob.hpp" #include "duckdb/common/types/column/column_data_collection.hpp" #include "duckdb/planner/filter/constant_filter.hpp" @@ -104,13 +104,6 @@ Value ParquetElementBigint(T &&value, bool is_iset) { return Value::BIGINT(value); } -Value ParquetElementBoolean(bool value, bool is_iset) { - if (!is_iset) { - return Value(); - } - return Value::BOOLEAN(value); -} - //===--------------------------------------------------------------------===// // Row Group Meta Data //===--------------------------------------------------------------------===// @@ -192,15 +185,9 @@ void ParquetMetaDataOperatorData::BindMetaData(vector &return_types names.emplace_back("bloom_filter_length"); return_types.emplace_back(LogicalType::BIGINT); - - names.emplace_back("min_is_exact"); - return_types.emplace_back(LogicalType::BOOLEAN); - - names.emplace_back("max_is_exact"); - return_types.emplace_back(LogicalType::BOOLEAN); } -Value ConvertParquetStats(const LogicalType &type, const ParquetColumnSchema &schema_ele, bool stats_is_set, +Value ConvertParquetStats(const LogicalType &type, const duckdb_parquet::SchemaElement &schema_ele, bool stats_is_set, const std::string &stats) { if (!stats_is_set) { return Value(LogicalType::VARCHAR); @@ -212,34 +199,34 @@ void ParquetMetaDataOperatorData::LoadRowGroupMetadata(ClientContext &context, c const string &file_path) { collection.Reset(); ParquetOptions parquet_options(context); - ParquetReader reader(context, file_path, parquet_options); + auto reader = make_uniq(context, file_path, parquet_options); idx_t count = 0; DataChunk current_chunk; current_chunk.Initialize(context, return_types); - auto meta_data = reader.GetFileMetadata(); - vector column_schemas; + auto meta_data = reader->GetFileMetadata(); + vector column_types; + vector schema_indexes; for (idx_t schema_idx = 0; schema_idx < meta_data->schema.size(); schema_idx++) { auto &schema_element = meta_data->schema[schema_idx]; if (schema_element.num_children > 0) { continue; } - ParquetColumnSchema column_schema; - column_schema.type = reader.DeriveLogicalType(schema_element, column_schema); - column_schemas.push_back(std::move(column_schema)); + column_types.push_back(ParquetReader::DeriveLogicalType(schema_element, false)); + schema_indexes.push_back(schema_idx); } for (idx_t row_group_idx = 0; row_group_idx < meta_data->row_groups.size(); row_group_idx++) { auto &row_group = meta_data->row_groups[row_group_idx]; - if (row_group.columns.size() > column_schemas.size()) { + if (row_group.columns.size() > column_types.size()) { throw InternalException("Too many column in row group: corrupt file?"); } for (idx_t col_idx = 0; col_idx < row_group.columns.size(); col_idx++) { auto &column = row_group.columns[col_idx]; - auto &column_schema = column_schemas[col_idx]; auto &col_meta = column.meta_data; auto &stats = col_meta.statistics; - auto &column_type = column_schema.type; + auto &schema_element = meta_data->schema[schema_indexes[col_idx]]; + auto &column_type = column_types[col_idx]; // file_name, LogicalType::VARCHAR current_chunk.SetValue(0, count, file_path); @@ -273,11 +260,11 @@ void ParquetMetaDataOperatorData::LoadRowGroupMetadata(ClientContext &context, c // stats_min, LogicalType::VARCHAR current_chunk.SetValue(10, count, - ConvertParquetStats(column_type, column_schema, stats.__isset.min, stats.min)); + ConvertParquetStats(column_type, schema_element, stats.__isset.min, stats.min)); // stats_max, LogicalType::VARCHAR current_chunk.SetValue(11, count, - ConvertParquetStats(column_type, column_schema, stats.__isset.max, stats.max)); + ConvertParquetStats(column_type, schema_element, stats.__isset.max, stats.max)); // stats_null_count, LogicalType::BIGINT current_chunk.SetValue(12, count, ParquetElementBigint(stats.null_count, stats.__isset.null_count)); @@ -287,11 +274,11 @@ void ParquetMetaDataOperatorData::LoadRowGroupMetadata(ClientContext &context, c // stats_min_value, LogicalType::VARCHAR current_chunk.SetValue( - 14, count, ConvertParquetStats(column_type, column_schema, stats.__isset.min_value, stats.min_value)); + 14, count, ConvertParquetStats(column_type, schema_element, stats.__isset.min_value, stats.min_value)); // stats_max_value, LogicalType::VARCHAR current_chunk.SetValue( - 15, count, ConvertParquetStats(column_type, column_schema, stats.__isset.max_value, stats.max_value)); + 15, count, ConvertParquetStats(column_type, schema_element, stats.__isset.max_value, stats.max_value)); // compression, LogicalType::VARCHAR current_chunk.SetValue(16, count, ConvertParquetElementToString(col_meta.codec)); @@ -340,14 +327,6 @@ void ParquetMetaDataOperatorData::LoadRowGroupMetadata(ClientContext &context, c current_chunk.SetValue( 25, count, ParquetElementBigint(col_meta.bloom_filter_length, col_meta.__isset.bloom_filter_length)); - // min_is_exact, LogicalType::BOOLEAN - current_chunk.SetValue(26, count, - ParquetElementBoolean(stats.is_min_value_exact, stats.__isset.is_min_value_exact)); - - // max_is_exact, LogicalType::BOOLEAN - current_chunk.SetValue(27, count, - ParquetElementBoolean(stats.is_max_value_exact, stats.__isset.is_max_value_exact)); - count++; if (count >= STANDARD_VECTOR_SIZE) { current_chunk.SetCardinality(count); @@ -445,9 +424,6 @@ Value ParquetLogicalTypeToString(const duckdb_parquet::LogicalType &type, bool i if (type.__isset.UUID) { return Value(PrintParquetElementToString(type.UUID)); } - if (type.__isset.FLOAT16) { - return Value(PrintParquetElementToString(type.FLOAT16)); - } return Value(); } @@ -792,7 +768,7 @@ void ParquetMetaDataImplementation(ClientContext &context, TableFunctionInput &d break; case ParquetMetadataOperatorType::BLOOM_PROBE: { auto &bloom_probe_bind_data = data_p.bind_data->Cast(); - data.ExecuteBloomProbe(context, bind_data.return_types, data.current_file, + data.ExecuteBloomProbe(context, bind_data.return_types, bind_data.file_list->GetFirstFile(), bloom_probe_bind_data.probe_column_name, bloom_probe_bind_data.probe_constant); break; } diff --git a/src/duckdb/extension/parquet/parquet_reader.cpp b/src/duckdb/extension/parquet/parquet_reader.cpp index cec9aba5c..c16c3b183 100644 --- a/src/duckdb/extension/parquet/parquet_reader.cpp +++ b/src/duckdb/extension/parquet/parquet_reader.cpp @@ -1,33 +1,38 @@ #include "parquet_reader.hpp" -#include "reader/boolean_column_reader.hpp" -#include "reader/callback_column_reader.hpp" +#include "boolean_column_reader.hpp" +#include "callback_column_reader.hpp" +#include "cast_column_reader.hpp" #include "column_reader.hpp" #include "duckdb.hpp" -#include "reader/expression_column_reader.hpp" +#include "expression_column_reader.hpp" #include "geo_parquet.hpp" -#include "reader/list_column_reader.hpp" +#include "list_column_reader.hpp" #include "parquet_crypto.hpp" #include "parquet_file_metadata_cache.hpp" #include "parquet_statistics.hpp" #include "parquet_timestamp.hpp" #include "mbedtls_wrapper.hpp" -#include "reader/row_number_column_reader.hpp" -#include "reader/string_column_reader.hpp" -#include "reader/struct_column_reader.hpp" -#include "reader/templated_column_reader.hpp" +#include "row_number_column_reader.hpp" +#include "string_column_reader.hpp" +#include "struct_column_reader.hpp" +#include "templated_column_reader.hpp" #include "thrift_tools.hpp" #include "duckdb/main/config.hpp" + +#ifndef DUCKDB_AMALGAMATION #include "duckdb/common/encryption_state.hpp" #include "duckdb/common/file_system.hpp" #include "duckdb/common/helper.hpp" #include "duckdb/common/hive_partitioning.hpp" #include "duckdb/common/string_util.hpp" +#include "duckdb/planner/filter/conjunction_filter.hpp" +#include "duckdb/planner/filter/constant_filter.hpp" +#include "duckdb/planner/filter/struct_filter.hpp" +#include "duckdb/planner/filter/optional_filter.hpp" #include "duckdb/planner/table_filter.hpp" #include "duckdb/storage/object_cache.hpp" -#include "duckdb/optimizer/statistics_propagator.hpp" -#include "duckdb/planner/table_filter_state.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#endif #include #include @@ -36,8 +41,6 @@ namespace duckdb { -constexpr int32_t ParquetReader::ORDINAL_FIELD_ID; - using duckdb_parquet::ColumnChunk; using duckdb_parquet::ConvertedType; using duckdb_parquet::FieldRepetitionType; @@ -120,37 +123,17 @@ LoadMetadata(ClientContext &context, Allocator &allocator, FileHandle &file_hand return make_shared_ptr(std::move(metadata), current_time, std::move(geo_metadata)); } -LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, ParquetColumnSchema &schema) const { +LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, bool binary_as_string) { // inner node if (s_ele.type == Type::FIXED_LEN_BYTE_ARRAY && !s_ele.__isset.type_length) { throw IOException("FIXED_LEN_BYTE_ARRAY requires length to be set"); } - if (s_ele.__isset.type_length) { - schema.type_length = NumericCast(s_ele.type_length); - } - schema.parquet_type = s_ele.type; if (s_ele.__isset.logicalType) { - if (s_ele.logicalType.__isset.UNKNOWN) { - return LogicalType::SQLNULL; - } else if (s_ele.logicalType.__isset.UUID) { + if (s_ele.logicalType.__isset.UUID) { if (s_ele.type == Type::FIXED_LEN_BYTE_ARRAY) { return LogicalType::UUID; } - } else if (s_ele.logicalType.__isset.FLOAT16) { - if (s_ele.type == Type::FIXED_LEN_BYTE_ARRAY && s_ele.type_length == 2) { - schema.type_info = ParquetExtraTypeInfo::FLOAT16; - return LogicalType::FLOAT; - } } else if (s_ele.logicalType.__isset.TIMESTAMP) { - if (s_ele.logicalType.TIMESTAMP.unit.__isset.MILLIS) { - schema.type_info = ParquetExtraTypeInfo::UNIT_MS; - } else if (s_ele.logicalType.TIMESTAMP.unit.__isset.MICROS) { - schema.type_info = ParquetExtraTypeInfo::UNIT_MICROS; - } else if (s_ele.logicalType.TIMESTAMP.unit.__isset.NANOS) { - schema.type_info = ParquetExtraTypeInfo::UNIT_NS; - } else { - throw NotImplementedException("Unimplemented TIMESTAMP encoding - missing UNIT"); - } if (s_ele.logicalType.TIMESTAMP.isAdjustedToUTC) { return LogicalType::TIMESTAMP_TZ; } else if (s_ele.logicalType.TIMESTAMP.unit.__isset.NANOS) { @@ -158,15 +141,6 @@ LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, Parquet } return LogicalType::TIMESTAMP; } else if (s_ele.logicalType.__isset.TIME) { - if (s_ele.logicalType.TIME.unit.__isset.MILLIS) { - schema.type_info = ParquetExtraTypeInfo::UNIT_MS; - } else if (s_ele.logicalType.TIME.unit.__isset.MICROS) { - schema.type_info = ParquetExtraTypeInfo::UNIT_MICROS; - } else if (s_ele.logicalType.TIME.unit.__isset.NANOS) { - schema.type_info = ParquetExtraTypeInfo::UNIT_NS; - } else { - throw NotImplementedException("Unimplemented TIME encoding - missing UNIT"); - } if (s_ele.logicalType.TIME.isAdjustedToUTC) { return LogicalType::TIME_TZ; } @@ -234,14 +208,7 @@ LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, Parquet throw IOException("DATE converted type can only be set for value of Type::INT32"); } case ConvertedType::TIMESTAMP_MICROS: - schema.type_info = ParquetExtraTypeInfo::UNIT_MICROS; - if (s_ele.type == Type::INT64) { - return LogicalType::TIMESTAMP; - } else { - throw IOException("TIMESTAMP converted type can only be set for value of Type::INT64"); - } case ConvertedType::TIMESTAMP_MILLIS: - schema.type_info = ParquetExtraTypeInfo::UNIT_MS; if (s_ele.type == Type::INT64) { return LogicalType::TIMESTAMP; } else { @@ -251,27 +218,19 @@ LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, Parquet if (!s_ele.__isset.precision || !s_ele.__isset.scale) { throw IOException("DECIMAL requires a length and scale specifier!"); } - schema.type_scale = NumericCast(s_ele.scale); if (s_ele.precision > DecimalType::MaxWidth()) { - schema.type_info = ParquetExtraTypeInfo::DECIMAL_BYTE_ARRAY; return LogicalType::DOUBLE; } switch (s_ele.type) { case Type::BYTE_ARRAY: case Type::FIXED_LEN_BYTE_ARRAY: - schema.type_info = ParquetExtraTypeInfo::DECIMAL_BYTE_ARRAY; - break; case Type::INT32: - schema.type_info = ParquetExtraTypeInfo::DECIMAL_INT32; - break; case Type::INT64: - schema.type_info = ParquetExtraTypeInfo::DECIMAL_INT64; - break; + return LogicalType::DECIMAL(s_ele.precision, s_ele.scale); default: throw IOException( "DECIMAL converted type can only be set for value of Type::(FIXED_LEN_)BYTE_ARRAY/INT32/INT64"); } - return LogicalType::DECIMAL(s_ele.precision, s_ele.scale); case ConvertedType::UTF8: case ConvertedType::ENUM: switch (s_ele.type) { @@ -282,14 +241,12 @@ LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, Parquet throw IOException("UTF8 converted type can only be set for Type::(FIXED_LEN_)BYTE_ARRAY"); } case ConvertedType::TIME_MILLIS: - schema.type_info = ParquetExtraTypeInfo::UNIT_MS; if (s_ele.type == Type::INT32) { return LogicalType::TIME; } else { throw IOException("TIME_MILLIS converted type can only be set for value of Type::INT32"); } case ConvertedType::TIME_MICROS: - schema.type_info = ParquetExtraTypeInfo::UNIT_MICROS; if (s_ele.type == Type::INT64) { return LogicalType::TIME; } else { @@ -317,7 +274,6 @@ LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, Parquet case Type::INT64: return LogicalType::BIGINT; case Type::INT96: // always a timestamp it would seem - schema.type_info = ParquetExtraTypeInfo::IMPALA_TIMESTAMP; return LogicalType::TIMESTAMP; case Type::FLOAT: return LogicalType::FLOAT; @@ -325,7 +281,7 @@ LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, Parquet return LogicalType::DOUBLE; case Type::BYTE_ARRAY: case Type::FIXED_LEN_BYTE_ARRAY: - if (parquet_options.binary_as_string) { + if (binary_as_string) { return LogicalType::VARCHAR; } return LogicalType::BLOB; @@ -335,122 +291,14 @@ LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele, Parquet } } -ParquetColumnSchema ParquetReader::ParseColumnSchema(const SchemaElement &s_ele, idx_t max_define, idx_t max_repeat, - idx_t schema_index, idx_t column_index, - ParquetColumnSchemaType type) { - ParquetColumnSchema schema(max_define, max_repeat, schema_index, column_index, type); - schema.name = s_ele.name; - schema.type = DeriveLogicalType(s_ele, schema); - return schema; +LogicalType ParquetReader::DeriveLogicalType(const SchemaElement &s_ele) { + return DeriveLogicalType(s_ele, parquet_options.binary_as_string); } unique_ptr ParquetReader::CreateReaderRecursive(ClientContext &context, - const vector &indexes, - const ParquetColumnSchema &schema) { - switch (schema.schema_type) { - case ParquetColumnSchemaType::GEOMETRY: - return metadata->geo_metadata->CreateColumnReader(*this, schema, context); - case ParquetColumnSchemaType::FILE_ROW_NUMBER: - return make_uniq(*this, schema); - case ParquetColumnSchemaType::COLUMN: { - if (schema.children.empty()) { - // leaf reader - return ColumnReader::CreateReader(*this, schema); - } - vector> children; - children.resize(schema.children.size()); - if (indexes.empty()) { - for (idx_t child_index = 0; child_index < schema.children.size(); child_index++) { - children[child_index] = CreateReaderRecursive(context, indexes, schema.children[child_index]); - } - } else { - for (idx_t i = 0; i < indexes.size(); i++) { - auto child_index = indexes[i].GetPrimaryIndex(); - children[child_index] = - CreateReaderRecursive(context, indexes[i].GetChildIndexes(), schema.children[child_index]); - } - } - switch (schema.type.id()) { - case LogicalTypeId::LIST: - case LogicalTypeId::MAP: - D_ASSERT(children.size() == 1); - return make_uniq(*this, schema, std::move(children[0])); - case LogicalTypeId::STRUCT: - return make_uniq(*this, schema, std::move(children)); - default: - throw InternalException("Unsupported schema type for schema with children"); - } - } - default: - throw InternalException("Unsupported ParquetColumnSchemaType"); - } -} - -unique_ptr ParquetReader::CreateReader(ClientContext &context) { - auto ret = CreateReaderRecursive(context, column_indexes, *root_schema); - if (ret->Type().id() != LogicalTypeId::STRUCT) { - throw InternalException("Root element of Parquet file must be a struct"); - } - // add expressions if required - auto &root_struct_reader = ret->Cast(); - for (auto &entry : expression_map) { - auto column_id = entry.first; - auto &expression = entry.second; - auto child_reader = std::move(root_struct_reader.child_readers[column_id]); - auto expr_schema = make_uniq(child_reader->Schema(), expression->return_type, - ParquetColumnSchemaType::EXPRESSION); - auto expr_reader = make_uniq(context, std::move(child_reader), expression->Copy(), - std::move(expr_schema)); - root_struct_reader.child_readers[column_id] = std::move(expr_reader); - } - return ret; -} - -ParquetColumnSchema::ParquetColumnSchema(idx_t max_define, idx_t max_repeat, idx_t schema_index, idx_t column_index, - ParquetColumnSchemaType schema_type) - : ParquetColumnSchema(string(), LogicalTypeId::INVALID, max_define, max_repeat, schema_index, column_index, - schema_type) { -} - -ParquetColumnSchema::ParquetColumnSchema(string name_p, LogicalType type_p, idx_t max_define, idx_t max_repeat, - idx_t schema_index, idx_t column_index, ParquetColumnSchemaType schema_type) - : schema_type(schema_type), name(std::move(name_p)), type(std::move(type_p)), max_define(max_define), - max_repeat(max_repeat), schema_index(schema_index), column_index(column_index) { -} - -ParquetColumnSchema::ParquetColumnSchema(ParquetColumnSchema parent, LogicalType result_type, - ParquetColumnSchemaType schema_type) - : schema_type(schema_type), name(parent.name), type(std::move(result_type)), max_define(parent.max_define), - max_repeat(parent.max_repeat), schema_index(parent.schema_index), column_index(parent.column_index) { - children.push_back(std::move(parent)); -} - -unique_ptr ParquetColumnSchema::Stats(ParquetReader &reader, idx_t row_group_idx_p, - const vector &columns) const { - if (schema_type == ParquetColumnSchemaType::EXPRESSION) { - return nullptr; - } - if (schema_type == ParquetColumnSchemaType::FILE_ROW_NUMBER) { - auto stats = NumericStats::CreateUnknown(type); - auto &row_groups = reader.GetFileMetadata()->row_groups; - D_ASSERT(row_group_idx_p < row_groups.size()); - idx_t row_group_offset_min = 0; - for (idx_t i = 0; i < row_group_idx_p; i++) { - row_group_offset_min += row_groups[i].num_rows; - } - - NumericStats::SetMin(stats, Value::BIGINT(UnsafeNumericCast(row_group_offset_min))); - NumericStats::SetMax(stats, Value::BIGINT(UnsafeNumericCast(row_group_offset_min + - row_groups[row_group_idx_p].num_rows))); - stats.Set(StatsInfo::CANNOT_HAVE_NULL_VALUES); - return stats.ToUnique(); - } - return ParquetStatisticsUtils::TransformColumnStatistics(*this, columns); -} - -ParquetColumnSchema ParquetReader::ParseSchemaRecursive(idx_t depth, idx_t max_define, idx_t max_repeat, - idx_t &next_schema_idx, idx_t &next_file_idx) { - + const vector &indexes, idx_t depth, + idx_t max_define, idx_t max_repeat, + idx_t &next_schema_idx, idx_t &next_file_idx) { auto file_meta_data = GetFileMetadata(); D_ASSERT(file_meta_data); D_ASSERT(next_schema_idx < file_meta_data->schema.size()); @@ -472,37 +320,66 @@ ParquetColumnSchema ParquetReader::ParseSchemaRecursive(idx_t depth, idx_t max_d if (depth == 1) { // geoparquet types have to be at the root of the schema, and have to be present in the kv metadata if (metadata->geo_metadata && metadata->geo_metadata->IsGeometryColumn(s_ele.name)) { - auto root_schema = ParseColumnSchema(s_ele, max_define, max_repeat, this_idx, next_file_idx++); - return ParquetColumnSchema(std::move(root_schema), GeoParquetFileMetadata::GeometryType(), - ParquetColumnSchemaType::GEOMETRY); + return metadata->geo_metadata->CreateColumnReader(*this, DeriveLogicalType(s_ele), s_ele, next_file_idx++, + max_define, max_repeat, context); } } if (s_ele.__isset.num_children && s_ele.num_children > 0) { // inner node - vector child_schemas; + child_list_t child_types; + vector> child_readers; + // this type is a nested type - it has child columns specified + // create a mapping for which column readers we should create + unordered_map> required_readers; + for (auto &index : indexes) { + required_readers.insert(make_pair(index.GetPrimaryIndex(), index.GetChildIndexes())); + } idx_t c_idx = 0; - while (c_idx < NumericCast(s_ele.num_children)) { + while (c_idx < (idx_t)s_ele.num_children) { next_schema_idx++; - auto child_schema = ParseSchemaRecursive(depth + 1, max_define, max_repeat, next_schema_idx, next_file_idx); - child_schemas.push_back(std::move(child_schema)); + auto &child_ele = file_meta_data->schema[next_schema_idx]; + + // figure out which child columns we should read of this child column + vector child_indexes; + auto entry = required_readers.find(c_idx); + if (entry != required_readers.end()) { + child_indexes = entry->second; + } + auto child_reader = CreateReaderRecursive(context, child_indexes, depth + 1, max_define, max_repeat, + next_schema_idx, next_file_idx); + child_types.push_back(make_pair(child_ele.name, child_reader->Type())); + if (indexes.empty() || entry != required_readers.end()) { + // either (1) indexes is empty, meaning we need to read all child columns, or (2) we need to read this + // column + child_readers.push_back(std::move(child_reader)); + } else { + // this column was explicitly not required - push an empty child reader here + child_readers.push_back(nullptr); + } + c_idx++; } // rename child type entries if there are case-insensitive duplicates by appending _1, _2 etc. // behavior consistent with CSV reader fwiw case_insensitive_map_t name_collision_count; - for (auto &child_schema : child_schemas) { - auto &col_name = child_schema.name; + // get header names from CSV + for (auto &child_type : child_types) { + auto col_name = child_type.first; // avoid duplicate header names while (name_collision_count.find(col_name) != name_collision_count.end()) { name_collision_count[col_name] += 1; col_name = col_name + "_" + to_string(name_collision_count[col_name]); } - child_schema.name = col_name; + child_type.first = col_name; name_collision_count[col_name] = 0; } + D_ASSERT(!child_types.empty()); + unique_ptr result; + LogicalType result_type; + bool is_repeated = repetition_type == FieldRepetitionType::REPEATED; bool is_list = s_ele.__isset.converted_type && s_ele.converted_type == ConvertedType::LIST; bool is_map = s_ele.__isset.converted_type && s_ele.converted_type == ConvertedType::MAP; @@ -516,72 +393,59 @@ ParquetColumnSchema ParquetReader::ParseSchemaRecursive(idx_t depth, idx_t max_d } if (is_map_kv) { - if (child_schemas.size() != 2) { + if (child_types.size() != 2) { throw IOException("MAP_KEY_VALUE requires two children"); } if (!is_repeated) { throw IOException("MAP_KEY_VALUE needs to be repeated"); } - auto result_type = LogicalType::MAP(child_schemas[0].type, child_schemas[1].type); - ParquetColumnSchema struct_schema(s_ele.name, ListType::GetChildType(result_type), max_define - 1, - max_repeat - 1, this_idx, next_file_idx); - struct_schema.children = std::move(child_schemas); - - ParquetColumnSchema map_schema(s_ele.name, std::move(result_type), max_define, max_repeat, this_idx, - next_file_idx); - map_schema.children.push_back(std::move(struct_schema)); - return map_schema; - } - ParquetColumnSchema result; - if (child_schemas.size() > 1 || (!is_list && !is_map && !is_repeated)) { - child_list_t struct_types; - for (auto &child_schema : child_schemas) { - struct_types.emplace_back(make_pair(child_schema.name, child_schema.type)); - } + result_type = LogicalType::MAP(std::move(child_types[0].second), std::move(child_types[1].second)); - auto result_type = LogicalType::STRUCT(std::move(struct_types)); - ParquetColumnSchema struct_schema(s_ele.name, std::move(result_type), max_define, max_repeat, this_idx, - next_file_idx); - struct_schema.children = std::move(child_schemas); - result = std::move(struct_schema); + auto struct_reader = + make_uniq(*this, ListType::GetChildType(result_type), s_ele, this_idx, + max_define - 1, max_repeat - 1, std::move(child_readers)); + return make_uniq(*this, result_type, s_ele, this_idx, max_define, max_repeat, + std::move(struct_reader)); + } + if (child_types.size() > 1 || (!is_list && !is_map && !is_repeated)) { + result_type = LogicalType::STRUCT(child_types); + result = make_uniq(*this, result_type, s_ele, this_idx, max_define, max_repeat, + std::move(child_readers)); } else { // if we have a struct with only a single type, pull up - result = std::move(child_schemas[0]); - result.name = s_ele.name; + result_type = child_types[0].second; + result = std::move(child_readers[0]); } if (is_repeated) { - auto list_type = LogicalType::LIST(result.type); - ParquetColumnSchema list_schema(s_ele.name, std::move(list_type), max_define, max_repeat, this_idx, - next_file_idx); - list_schema.children.push_back(std::move(result)); - result = std::move(list_schema); + result_type = LogicalType::LIST(result_type); + result = make_uniq(*this, result_type, s_ele, this_idx, max_define, max_repeat, + std::move(result)); } - result.parent_schema_index = this_idx; + result->SetParentSchema(s_ele); return result; } else { // leaf node if (!s_ele.__isset.type) { throw InvalidInputException( - "Node '%s' has neither num_children nor type set - this violates the Parquet spec (corrupted file)", - s_ele.name.c_str()); + "Node has neither num_children nor type set - this violates the Parquet spec (corrupted file)"); } - auto result = ParseColumnSchema(s_ele, max_define, max_repeat, this_idx, next_file_idx++); if (s_ele.repetition_type == FieldRepetitionType::REPEATED) { - auto list_type = LogicalType::LIST(result.type); - ParquetColumnSchema list_schema(s_ele.name, std::move(list_type), max_define, max_repeat, this_idx, - next_file_idx); - list_schema.children.push_back(std::move(result)); - return list_schema; + const auto derived_type = DeriveLogicalType(s_ele); + auto list_type = LogicalType::LIST(derived_type); + + auto element_reader = + ColumnReader::CreateReader(*this, derived_type, s_ele, next_file_idx++, max_define, max_repeat); + + return make_uniq(*this, list_type, s_ele, this_idx, max_define, max_repeat, + std::move(element_reader)); } - return result; + // TODO check return value of derive type or should we only do this on read() + return ColumnReader::CreateReader(*this, DeriveLogicalType(s_ele), s_ele, next_file_idx++, max_define, + max_repeat); } } -ParquetColumnSchema FileRowNumberSchema() { - return ParquetColumnSchema("file_row_number", LogicalType::BIGINT, 0, 0, 0, 0, - ParquetColumnSchemaType::FILE_ROW_NUMBER); -} - -unique_ptr ParquetReader::ParseSchema() { +// TODO we don't need readers for columns we are not going to read ay +unique_ptr ParquetReader::CreateReader(ClientContext &context) { auto file_meta_data = GetFileMetadata(); idx_t next_schema_idx = 0; idx_t next_file_idx = 0; @@ -592,46 +456,29 @@ unique_ptr ParquetReader::ParseSchema() { if (file_meta_data->schema[0].num_children == 0) { throw IOException("Parquet reader: root schema element has no children"); } - auto root = ParseSchemaRecursive(0, 0, 0, next_schema_idx, next_file_idx); - if (root.type.id() != LogicalTypeId::STRUCT) { + auto ret = CreateReaderRecursive(context, reader_data.column_indexes, 0, 0, 0, next_schema_idx, next_file_idx); + if (ret->Type().id() != LogicalTypeId::STRUCT) { throw InvalidInputException("Root element of Parquet file must be a struct"); } D_ASSERT(next_schema_idx == file_meta_data->schema.size() - 1); D_ASSERT(file_meta_data->row_groups.empty() || next_file_idx == file_meta_data->row_groups[0].columns.size()); - if (parquet_options.file_row_number) { - for (auto &column : root.children) { - auto &name = column.name; - if (StringUtil::CIEquals(name, "file_row_number")) { - throw BinderException( - "Using file_row_number option on file with column named file_row_number is not supported"); - } - } - root.children.push_back(FileRowNumberSchema()); - } - return make_uniq(root); -} -MultiFileColumnDefinition ParquetReader::ParseColumnDefinition(const FileMetaData &file_meta_data, - ParquetColumnSchema &element) { - MultiFileColumnDefinition result(element.name, element.type); - if (element.schema_type == ParquetColumnSchemaType::FILE_ROW_NUMBER) { - result.identifier = Value::INTEGER(ORDINAL_FIELD_ID); - return result; - } - auto &column_schema = file_meta_data.schema[element.schema_index]; - - if (column_schema.__isset.field_id) { - result.identifier = Value::INTEGER(column_schema.field_id); - } else if (element.parent_schema_index.IsValid()) { - auto &parent_column_schema = file_meta_data.schema[element.parent_schema_index.GetIndex()]; - if (parent_column_schema.__isset.field_id) { - result.identifier = Value::INTEGER(parent_column_schema.field_id); - } + auto &root_struct_reader = ret->Cast(); + // add casts if required + for (auto &entry : reader_data.cast_map) { + auto column_idx = entry.first; + auto &expected_type = entry.second; + auto child_reader = std::move(root_struct_reader.child_readers[column_idx]); + auto cast_reader = make_uniq(std::move(child_reader), expected_type); + root_struct_reader.child_readers[column_idx] = std::move(cast_reader); } - for (auto &child : element.children) { - result.children.push_back(ParseColumnDefinition(file_meta_data, child)); + if (parquet_options.file_row_number) { + generated_column_schema.push_back(SchemaElement()); + root_struct_reader.child_readers.push_back(make_uniq( + *this, LogicalType::BIGINT, generated_column_schema.back(), next_file_idx, 0, 0)); } - return result; + + return ret; } void ParquetReader::InitializeSchema(ClientContext &context) { @@ -648,18 +495,42 @@ void ParquetReader::InitializeSchema(ClientContext &context) { throw InvalidInputException("Failed to read Parquet file '%s': Need at least one non-root column in the file", file_name); } - root_schema = ParseSchema(); - for (idx_t i = 0; i < root_schema->children.size(); i++) { - auto &element = root_schema->children[i]; - columns.push_back(ParseColumnDefinition(*file_meta_data, element)); + root_reader = CreateReader(context); + auto &root_type = root_reader->Type(); + auto &child_types = StructType::GetChildTypes(root_type); + + auto &struct_reader = root_reader->Cast(); + auto &child_readers = struct_reader.child_readers; + D_ASSERT(root_type.id() == LogicalTypeId::STRUCT); + + D_ASSERT(child_readers.size() >= child_types.size()); + for (idx_t i = 0; i < child_types.size(); i++) { + auto &type_pair = child_types[i]; + auto column = MultiFileReaderColumnDefinition(type_pair.first, type_pair.second); + auto &column_reader = *child_readers[i]; + auto &column_schema = column_reader.Schema(); + + if (column_schema.__isset.field_id) { + column.identifier = Value::INTEGER(column_schema.field_id); + } else if (column_reader.GetParentSchema()) { + auto &parent_column_schema = *column_reader.GetParentSchema(); + if (parent_column_schema.__isset.field_id) { + column.identifier = Value::INTEGER(parent_column_schema.field_id); + } + } + columns.emplace_back(std::move(column)); } -} -void ParquetReader::AddVirtualColumn(column_t virtual_column_id) { - if (virtual_column_id == MultiFileReader::COLUMN_IDENTIFIER_FILE_ROW_NUMBER) { - root_schema->children.push_back(FileRowNumberSchema()); - } else { - throw InternalException("Unsupported virtual column id %d for parquet reader", virtual_column_id); + // Add generated constant column for row number + if (parquet_options.file_row_number) { + for (auto &column : columns) { + auto &name = column.name; + if (StringUtil::CIEquals(name, "file_row_number")) { + throw BinderException( + "Using file_row_number option on file with column named file_row_number is not supported"); + } + } + columns.emplace_back("file_row_number", LogicalType::BIGINT); } } @@ -692,8 +563,9 @@ ParquetColumnDefinition ParquetColumnDefinition::FromSchemaValue(ClientContext & ParquetReader::ParquetReader(ClientContext &context_p, string file_name_p, ParquetOptions parquet_options_p, shared_ptr metadata_p) - : BaseFileReader(std::move(file_name_p)), fs(FileSystem::GetFileSystem(context_p)), - allocator(BufferAllocator::Get(context_p)), parquet_options(std::move(parquet_options_p)) { + : fs(FileSystem::GetFileSystem(context_p)), allocator(BufferAllocator::Get(context_p)), + parquet_options(std::move(parquet_options_p)) { + file_name = std::move(file_name_p); file_handle = fs.OpenFile(file_name, FileFlags::FILE_FLAGS_READ); if (!file_handle->CanSeek()) { throw NotImplementedException( @@ -738,15 +610,15 @@ ParquetUnionData::~ParquetUnionData() { ParquetReader::ParquetReader(ClientContext &context_p, ParquetOptions parquet_options_p, shared_ptr metadata_p) - : BaseFileReader(string()), fs(FileSystem::GetFileSystem(context_p)), allocator(BufferAllocator::Get(context_p)), - metadata(std::move(metadata_p)), parquet_options(std::move(parquet_options_p)), rows_read(0) { + : fs(FileSystem::GetFileSystem(context_p)), allocator(BufferAllocator::Get(context_p)), + metadata(std::move(metadata_p)), parquet_options(std::move(parquet_options_p)) { InitializeSchema(context_p); } ParquetReader::~ParquetReader() { } -const FileMetaData *ParquetReader::GetFileMetadata() const { +const FileMetaData *ParquetReader::GetFileMetadata() { D_ASSERT(metadata); D_ASSERT(metadata->metadata); return metadata->metadata.get(); @@ -765,11 +637,11 @@ unique_ptr ParquetReader::ReadStatistics(const string &name) { unique_ptr column_stats; auto file_meta_data = GetFileMetadata(); - auto &column_schema = root_schema->children[file_col_idx]; + auto &column_reader = root_reader->Cast().GetChildReader(file_col_idx); for (idx_t row_group_idx = 0; row_group_idx < file_meta_data->row_groups.size(); row_group_idx++) { auto &row_group = file_meta_data->row_groups[row_group_idx]; - auto chunk_stats = column_schema.Stats(*this, row_group_idx, row_group.columns); + auto chunk_stats = column_reader.Stats(row_group_idx, row_group.columns); if (!chunk_stats) { return nullptr; } @@ -807,15 +679,6 @@ uint32_t ParquetReader::ReadData(duckdb_apache::thrift::protocol::TProtocol &ipr } } -idx_t GetRowGroupOffset(ParquetReader &reader, idx_t group_idx) { - idx_t row_group_offset = 0; - auto &row_groups = reader.GetFileMetadata()->row_groups; - for (idx_t i = 0; i < group_idx; i++) { - row_group_offset += row_groups[i].num_rows; - } - return row_group_offset; -} - const ParquetRowGroup &ParquetReader::GetGroup(ParquetReaderScanState &state) { auto file_meta_data = GetFileMetadata(); D_ASSERT(state.current_group >= 0 && (idx_t)state.current_group < state.group_idx_list.size()); @@ -886,116 +749,74 @@ idx_t ParquetReader::GetGroupOffset(ParquetReaderScanState &state) { static FilterPropagateResult CheckParquetStringFilter(BaseStatistics &stats, const Statistics &pq_col_stats, TableFilter &filter) { - switch (filter.filter_type) { - case TableFilterType::CONJUNCTION_AND: { - auto &conjunction_filter = filter.Cast(); - auto and_result = FilterPropagateResult::FILTER_ALWAYS_TRUE; - for (auto &child_filter : conjunction_filter.child_filters) { - auto child_prune_result = CheckParquetStringFilter(stats, pq_col_stats, *child_filter); - if (child_prune_result == FilterPropagateResult::FILTER_ALWAYS_FALSE) { - return FilterPropagateResult::FILTER_ALWAYS_FALSE; - } - if (child_prune_result != and_result) { - and_result = FilterPropagateResult::NO_PRUNING_POSSIBLE; - } - } - return and_result; - } - case TableFilterType::CONSTANT_COMPARISON: { + if (filter.filter_type == TableFilterType::CONSTANT_COMPARISON) { auto &constant_filter = filter.Cast(); auto &min_value = pq_col_stats.min_value; auto &max_value = pq_col_stats.max_value; return StringStats::CheckZonemap(const_data_ptr_cast(min_value.c_str()), min_value.size(), const_data_ptr_cast(max_value.c_str()), max_value.size(), constant_filter.comparison_type, StringValue::Get(constant_filter.constant)); - } - default: + } else { return filter.CheckStatistics(stats); } } -static FilterPropagateResult CheckParquetFloatFilter(ColumnReader &reader, const Statistics &pq_col_stats, - TableFilter &filter) { - // floating point values can have values in the [min, max] domain AND nan values - // check both stats against the filter - auto &type = reader.Type(); - auto nan_stats = NumericStats::CreateUnknown(type); - auto nan_value = Value("nan").DefaultCastAs(type); - NumericStats::SetMin(nan_stats, nan_value); - NumericStats::SetMax(nan_stats, nan_value); - auto nan_prune = filter.CheckStatistics(nan_stats); - - auto min_max_stats = ParquetStatisticsUtils::CreateNumericStats(reader.Type(), reader.Schema(), pq_col_stats); - auto prune = filter.CheckStatistics(*min_max_stats); - - // if EITHER of them cannot be pruned - we cannot prune - if (prune == FilterPropagateResult::NO_PRUNING_POSSIBLE || - nan_prune == FilterPropagateResult::NO_PRUNING_POSSIBLE) { - return FilterPropagateResult::NO_PRUNING_POSSIBLE; - } - // if both are the same we can return that value - if (prune == nan_prune) { - return prune; - } - // if they are different we need to return that we cannot prune - // e.g. prune = always false, nan_prune = always true -> we don't know - return FilterPropagateResult::NO_PRUNING_POSSIBLE; -} - -void ParquetReader::PrepareRowGroupBuffer(ParquetReaderScanState &state, idx_t i) { +void ParquetReader::PrepareRowGroupBuffer(ParquetReaderScanState &state, idx_t col_idx) { auto &group = GetGroup(state); - auto col_idx = MultiFileLocalIndex(i); - auto column_id = column_ids[col_idx]; + auto column_id = reader_data.column_ids[col_idx]; auto &column_reader = state.root_reader->Cast().GetChildReader(column_id); - if (filters) { + // TODO move this to columnreader too + if (reader_data.filters) { auto stats = column_reader.Stats(state.group_idx_list[state.current_group], group.columns); // filters contain output chunk index, not file col idx! - auto filter_entry = filters->filters.find(col_idx); - if (stats && filter_entry != filters->filters.end()) { + auto global_id = reader_data.column_mapping[col_idx]; + auto filter_entry = reader_data.filters->filters.find(global_id); + + if (stats && filter_entry != reader_data.filters->filters.end()) { auto &filter = *filter_entry->second; FilterPropagateResult prune_result; // TODO we might not have stats but STILL a bloom filter so move this up // check the bloom filter if present - bool is_generated_column = column_reader.ColumnIndex() >= group.columns.size(); - bool is_expression = column_reader.Schema().schema_type == ::duckdb::ParquetColumnSchemaType::EXPRESSION; - bool has_min_max = false; - if (!is_generated_column) { - has_min_max = group.columns[column_reader.ColumnIndex()].meta_data.statistics.__isset.min_value && - group.columns[column_reader.ColumnIndex()].meta_data.statistics.__isset.max_value; - } - if (is_expression) { - // no pruning possible for expressions - prune_result = FilterPropagateResult::NO_PRUNING_POSSIBLE; - } else if (!is_generated_column && has_min_max && column_reader.Type().id() == LogicalTypeId::VARCHAR) { + bool is_generated_column = column_reader.FileIdx() >= group.columns.size(); + if (!column_reader.Type().IsNested() && !is_generated_column && + ParquetStatisticsUtils::BloomFilterSupported(column_reader.Type().id()) && + ParquetStatisticsUtils::BloomFilterExcludes(filter, group.columns[column_reader.FileIdx()].meta_data, + *state.thrift_file_proto, allocator)) { + prune_result = FilterPropagateResult::FILTER_ALWAYS_FALSE; + } else if (column_reader.Type().id() == LogicalTypeId::VARCHAR && !is_generated_column && + group.columns[column_reader.FileIdx()].meta_data.statistics.__isset.min_value && + group.columns[column_reader.FileIdx()].meta_data.statistics.__isset.max_value) { + // our StringStats only store the first 8 bytes of strings (even if Parquet has longer string stats) // however, when reading remote Parquet files, skipping row groups is really important // here, we implement a special case to check the full length for string filters - prune_result = CheckParquetStringFilter( - *stats, group.columns[column_reader.ColumnIndex()].meta_data.statistics, filter); - } else if (!is_generated_column && has_min_max && - (column_reader.Type().id() == LogicalTypeId::FLOAT || - column_reader.Type().id() == LogicalTypeId::DOUBLE)) { - // floating point columns can have NaN values in addition to the min/max bounds defined in the file - // in order to do optimal pruning - we prune based on the [min, max] of the file followed by pruning - // based on nan - prune_result = CheckParquetFloatFilter( - column_reader, group.columns[column_reader.ColumnIndex()].meta_data.statistics, filter); + if (filter.filter_type == TableFilterType::CONJUNCTION_AND) { + const auto &and_filter = filter.Cast(); + auto and_result = FilterPropagateResult::FILTER_ALWAYS_TRUE; + for (auto &child_filter : and_filter.child_filters) { + auto child_prune_result = CheckParquetStringFilter( + *stats, group.columns[column_reader.FileIdx()].meta_data.statistics, *child_filter); + if (child_prune_result == FilterPropagateResult::FILTER_ALWAYS_FALSE) { + and_result = FilterPropagateResult::FILTER_ALWAYS_FALSE; + break; + } else if (child_prune_result != and_result) { + and_result = FilterPropagateResult::NO_PRUNING_POSSIBLE; + } + } + prune_result = and_result; + } else { + prune_result = CheckParquetStringFilter( + *stats, group.columns[column_reader.FileIdx()].meta_data.statistics, filter); + } } else { prune_result = filter.CheckStatistics(*stats); } - if (prune_result == FilterPropagateResult::NO_PRUNING_POSSIBLE && !column_reader.Type().IsNested() && - !is_generated_column && ParquetStatisticsUtils::BloomFilterSupported(column_reader.Type().id()) && - ParquetStatisticsUtils::BloomFilterExcludes(filter, - group.columns[column_reader.ColumnIndex()].meta_data, - *state.thrift_file_proto, allocator)) { - prune_result = FilterPropagateResult::FILTER_ALWAYS_FALSE; - } if (prune_result == FilterPropagateResult::FILTER_ALWAYS_FALSE) { // this effectively will skip this chunk - state.offset_in_group = group.num_rows; + state.group_offset = group.num_rows; return; } } @@ -1005,27 +826,19 @@ void ParquetReader::PrepareRowGroupBuffer(ParquetReaderScanState &state, idx_t i *state.thrift_file_proto); } -idx_t ParquetReader::NumRows() const { +idx_t ParquetReader::NumRows() { return GetFileMetadata()->num_rows; } -idx_t ParquetReader::NumRowGroups() const { +idx_t ParquetReader::NumRowGroups() { return GetFileMetadata()->row_groups.size(); } -ParquetScanFilter::ParquetScanFilter(ClientContext &context, idx_t filter_idx, TableFilter &filter) - : filter_idx(filter_idx), filter(filter) { - filter_state = TableFilterState::Initialize(filter); -} - -ParquetScanFilter::~ParquetScanFilter() { -} - void ParquetReader::InitializeScan(ClientContext &context, ParquetReaderScanState &state, vector groups_to_read) { state.current_group = -1; state.finished = false; - state.offset_in_group = 0; + state.group_offset = 0; state.group_idx_list = std::move(groups_to_read); state.sel.Initialize(STANDARD_VECTOR_SIZE); if (!state.file_handle || state.file_handle->path != file_handle->path) { @@ -1047,14 +860,6 @@ void ParquetReader::InitializeScan(ClientContext &context, ParquetReaderScanStat state.file_handle = fs.OpenFile(file_handle->path, flags); } - state.adaptive_filter.reset(); - state.scan_filters.clear(); - if (filters) { - state.adaptive_filter = make_uniq(*filters); - for (auto &entry : filters->filters) { - state.scan_filters.emplace_back(context, entry.first, *entry.second); - } - } state.thrift_file_proto = CreateThriftFileProtocol(allocator, *state.file_handle, state.prefetch_mode); state.root_reader = CreateReader(context); @@ -1062,8 +867,216 @@ void ParquetReader::InitializeScan(ClientContext &context, ParquetReaderScanStat state.repeat_buf.resize(allocator, STANDARD_VECTOR_SIZE); } -void ParquetReader::Scan(ClientContext &context, ParquetReaderScanState &state, DataChunk &result) { - while (ScanInternal(context, state, result)) { +void FilterIsNull(Vector &v, parquet_filter_t &filter_mask, idx_t count) { + if (v.GetVectorType() == VectorType::CONSTANT_VECTOR) { + auto &mask = ConstantVector::Validity(v); + if (mask.RowIsValid(0)) { + filter_mask.reset(); + } + return; + } + + UnifiedVectorFormat unified; + v.ToUnifiedFormat(count, unified); + + if (unified.validity.AllValid()) { + filter_mask.reset(); + } else { + for (idx_t i = 0; i < count; i++) { + if (filter_mask.test(i)) { + filter_mask.set(i, !unified.validity.RowIsValid(unified.sel->get_index(i))); + } + } + } +} + +void FilterIsNotNull(Vector &v, parquet_filter_t &filter_mask, idx_t count) { + if (v.GetVectorType() == VectorType::CONSTANT_VECTOR) { + auto &mask = ConstantVector::Validity(v); + if (!mask.RowIsValid(0)) { + filter_mask.reset(); + } + return; + } + + UnifiedVectorFormat unified; + v.ToUnifiedFormat(count, unified); + + if (!unified.validity.AllValid()) { + for (idx_t i = 0; i < count; i++) { + if (filter_mask.test(i)) { + filter_mask.set(i, unified.validity.RowIsValid(unified.sel->get_index(i))); + } + } + } +} + +template +void TemplatedFilterOperation(Vector &v, T constant, parquet_filter_t &filter_mask, idx_t count) { + if (v.GetVectorType() == VectorType::CONSTANT_VECTOR) { + auto v_ptr = ConstantVector::GetData(v); + auto &mask = ConstantVector::Validity(v); + + if (mask.RowIsValid(0)) { + if (!OP::Operation(v_ptr[0], constant)) { + filter_mask.reset(); + } + } else { + filter_mask.reset(); + } + return; + } + + UnifiedVectorFormat unified; + v.ToUnifiedFormat(count, unified); + auto data_ptr = UnifiedVectorFormat::GetData(unified); + + if (!unified.validity.AllValid()) { + for (idx_t i = 0; i < count; i++) { + if (filter_mask.test(i)) { + auto idx = unified.sel->get_index(i); + bool is_valid = unified.validity.RowIsValid(idx); + if (is_valid) { + filter_mask.set(i, OP::Operation(data_ptr[idx], constant)); + } else { + filter_mask.set(i, false); + } + } + } + } else { + for (idx_t i = 0; i < count; i++) { + if (filter_mask.test(i)) { + filter_mask.set(i, OP::Operation(data_ptr[unified.sel->get_index(i)], constant)); + } + } + } +} + +template +void TemplatedFilterOperation(Vector &v, const Value &constant, parquet_filter_t &filter_mask, idx_t count) { + TemplatedFilterOperation(v, constant.template GetValueUnsafe(), filter_mask, count); +} + +template +static void FilterOperationSwitch(Vector &v, Value &constant, parquet_filter_t &filter_mask, idx_t count) { + if (filter_mask.none() || count == 0) { + return; + } + switch (v.GetType().InternalType()) { + case PhysicalType::BOOL: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::UINT8: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::UINT16: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::UINT32: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::UINT64: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::INT8: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::INT16: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::INT32: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::INT64: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::INT128: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::FLOAT: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::DOUBLE: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + case PhysicalType::VARCHAR: + TemplatedFilterOperation(v, constant, filter_mask, count); + break; + default: + throw NotImplementedException("Unsupported type for filter %s", v.ToString()); + } +} + +static void ApplyFilter(Vector &v, TableFilter &filter, parquet_filter_t &filter_mask, idx_t count) { + switch (filter.filter_type) { + case TableFilterType::CONJUNCTION_AND: { + auto &conjunction = filter.Cast(); + for (auto &child_filter : conjunction.child_filters) { + ApplyFilter(v, *child_filter, filter_mask, count); + } + break; + } + case TableFilterType::CONJUNCTION_OR: { + auto &conjunction = filter.Cast(); + parquet_filter_t or_mask; + for (auto &child_filter : conjunction.child_filters) { + parquet_filter_t child_mask = filter_mask; + ApplyFilter(v, *child_filter, child_mask, count); + or_mask |= child_mask; + } + filter_mask &= or_mask; + break; + } + case TableFilterType::CONSTANT_COMPARISON: { + auto &constant_filter = filter.Cast(); + switch (constant_filter.comparison_type) { + case ExpressionType::COMPARE_EQUAL: + FilterOperationSwitch(v, constant_filter.constant, filter_mask, count); + break; + case ExpressionType::COMPARE_LESSTHAN: + FilterOperationSwitch(v, constant_filter.constant, filter_mask, count); + break; + case ExpressionType::COMPARE_LESSTHANOREQUALTO: + FilterOperationSwitch(v, constant_filter.constant, filter_mask, count); + break; + case ExpressionType::COMPARE_GREATERTHAN: + FilterOperationSwitch(v, constant_filter.constant, filter_mask, count); + break; + case ExpressionType::COMPARE_GREATERTHANOREQUALTO: + FilterOperationSwitch(v, constant_filter.constant, filter_mask, count); + break; + case ExpressionType::COMPARE_NOTEQUAL: + FilterOperationSwitch(v, constant_filter.constant, filter_mask, count); + break; + default: + throw InternalException("Unsupported comparison for Parquet filter pushdown"); + } + break; + } + case TableFilterType::IS_NOT_NULL: + FilterIsNotNull(v, filter_mask, count); + break; + case TableFilterType::IS_NULL: + FilterIsNull(v, filter_mask, count); + break; + case TableFilterType::STRUCT_EXTRACT: { + auto &struct_filter = filter.Cast(); + auto &child = StructVector::GetEntries(v)[struct_filter.child_idx]; + ApplyFilter(*child, *struct_filter.child_filter, filter_mask, count); + } + case TableFilterType::OPTIONAL_FILTER: { + // we don't execute zone map filters here - we only consider them for zone map pruning + // do nothing to the mask. + break; + } + default: + D_ASSERT(0); + break; + } +} + +void ParquetReader::Scan(ParquetReaderScanState &state, DataChunk &result) { + while (ScanInternal(state, result)) { if (result.size() > 0) { break; } @@ -1071,15 +1084,15 @@ void ParquetReader::Scan(ClientContext &context, ParquetReaderScanState &state, } } -bool ParquetReader::ScanInternal(ClientContext &context, ParquetReaderScanState &state, DataChunk &result) { +bool ParquetReader::ScanInternal(ParquetReaderScanState &state, DataChunk &result) { if (state.finished) { return false; } // see if we have to switch to the next row group in the parquet file - if (state.current_group < 0 || (int64_t)state.offset_in_group >= GetGroup(state).num_rows) { + if (state.current_group < 0 || (int64_t)state.group_offset >= GetGroup(state).num_rows) { state.current_group++; - state.offset_in_group = 0; + state.group_offset = 0; auto &trans = reinterpret_cast(*state.thrift_file_proto->getTransport()); trans.ClearPrefetch(); @@ -1090,22 +1103,18 @@ bool ParquetReader::ScanInternal(ClientContext &context, ParquetReaderScanState return false; } - // TODO: only need this if we have a deletion vector? - state.group_offset = GetRowGroupOffset(state.root_reader->Reader(), state.group_idx_list[state.current_group]); - uint64_t to_scan_compressed_bytes = 0; - for (idx_t i = 0; i < column_ids.size(); i++) { - auto col_idx = MultiFileLocalIndex(i); + for (idx_t col_idx = 0; col_idx < reader_data.column_ids.size(); col_idx++) { PrepareRowGroupBuffer(state, col_idx); - auto file_col_idx = column_ids[col_idx]; + auto file_col_idx = reader_data.column_ids[col_idx]; auto &root_reader = state.root_reader->Cast(); to_scan_compressed_bytes += root_reader.GetChildReader(file_col_idx).TotalCompressedSize(); } auto &group = GetGroup(state); - if (state.prefetch_mode && state.offset_in_group != (idx_t)group.num_rows) { + if (state.prefetch_mode && state.group_offset != (idx_t)group.num_rows) { uint64_t total_row_group_span = GetGroupSpan(state); double scan_percentage = (double)(to_scan_compressed_bytes) / static_cast(total_row_group_span); @@ -1118,7 +1127,8 @@ bool ParquetReader::ScanInternal(ClientContext &context, ParquetReaderScanState file_name); } - if (!filters && scan_percentage > ParquetReaderPrefetchConfig::WHOLE_GROUP_PREFETCH_MINIMUM_SCAN) { + if (!reader_data.filters && + scan_percentage > ParquetReaderPrefetchConfig::WHOLE_GROUP_PREFETCH_MINIMUM_SCAN) { // Prefetch the whole row group if (!state.current_group_prefetched) { auto total_compressed_size = GetGroupCompressedSize(state); @@ -1130,18 +1140,17 @@ bool ParquetReader::ScanInternal(ClientContext &context, ParquetReaderScanState } else { // lazy fetching is when all tuples in a column can be skipped. With lazy fetching the buffer is only // fetched on the first read to that buffer. - bool lazy_fetch = filters != nullptr; + bool lazy_fetch = reader_data.filters; // Prefetch column-wise - for (idx_t i = 0; i < column_ids.size(); i++) { - auto col_idx = MultiFileLocalIndex(i); - auto file_col_idx = column_ids[col_idx]; + for (idx_t col_idx = 0; col_idx < reader_data.column_ids.size(); col_idx++) { + auto file_col_idx = reader_data.column_ids[col_idx]; auto &root_reader = state.root_reader->Cast(); bool has_filter = false; - if (filters) { - auto entry = filters->filters.find(col_idx); - has_filter = entry != filters->filters.end(); + if (reader_data.filters) { + auto entry = reader_data.filters->filters.find(reader_data.column_mapping[col_idx]); + has_filter = entry != reader_data.filters->filters.end(); } root_reader.GetChildReader(file_col_idx).RegisterPrefetch(trans, !(lazy_fetch && !has_filter)); } @@ -1156,15 +1165,23 @@ bool ParquetReader::ScanInternal(ClientContext &context, ParquetReaderScanState return true; } - auto scan_count = MinValue(STANDARD_VECTOR_SIZE, GetGroup(state).num_rows - state.offset_in_group); - result.SetCardinality(scan_count); + auto this_output_chunk_rows = MinValue(STANDARD_VECTOR_SIZE, GetGroup(state).num_rows - state.group_offset); + result.SetCardinality(this_output_chunk_rows); - if (scan_count == 0) { + if (this_output_chunk_rows == 0) { state.finished = true; return false; // end of last group, we are done } - auto &deletion_filter = state.root_reader->Reader().deletion_filter; + // we evaluate simple table filters directly in this scan so we can skip decoding column data that's never going to + // be relevant + parquet_filter_t filter_mask; + filter_mask.set(); + + // mask out unused part of bitset + for (idx_t i = this_output_chunk_rows; i < STANDARD_VECTOR_SIZE; i++) { + filter_mask.set(i, false); + } state.define_buf.zero(); state.repeat_buf.zero(); @@ -1174,78 +1191,72 @@ bool ParquetReader::ScanInternal(ClientContext &context, ParquetReaderScanState auto &root_reader = state.root_reader->Cast(); - if (filters || deletion_filter) { - idx_t filter_count = result.size(); - D_ASSERT(filter_count == scan_count); - vector need_to_read(column_ids.size(), true); + if (reader_data.filters) { + vector need_to_read(reader_data.column_ids.size(), true); - state.sel.Initialize(nullptr); - D_ASSERT(!filters || state.scan_filters.size() == filters->filters.size()); + // first load the columns that are used in filters + for (auto &filter_col : reader_data.filters->filters) { + if (filter_mask.none()) { + // if no rows are left we can stop checking filters + break; + } + auto filter_entry = reader_data.filter_map[filter_col.first]; + if (filter_entry.is_constant) { + // this is a constant vector, look for the constant + auto &constant = reader_data.constant_map[filter_entry.index].value; + Vector constant_vector(constant); + ApplyFilter(constant_vector, *filter_col.second, filter_mask, this_output_chunk_rows); + } else { + auto id = filter_entry.index; + auto file_col_idx = reader_data.column_ids[id]; + auto result_idx = reader_data.column_mapping[id]; - bool is_first_filter = true; - if (deletion_filter) { - filter_count = deletion_filter->Filter(state.offset_in_group + state.group_offset, scan_count, state.sel); - //! FIXME: does this need to be set? - //! As part of 'DirectFilter' we also initialize reads of the child readers - is_first_filter = false; - } + auto &result_vector = result.data[result_idx]; + auto &child_reader = root_reader.GetChildReader(file_col_idx); + child_reader.Read(result.size(), filter_mask, define_ptr, repeat_ptr, result_vector); + need_to_read[id] = false; - if (filters) { - // first load the columns that are used in filters - auto filter_state = state.adaptive_filter->BeginFilter(); - for (idx_t i = 0; i < state.scan_filters.size(); i++) { - if (filter_count == 0) { - // if no rows are left we can stop checking filters - break; - } - auto &scan_filter = state.scan_filters[state.adaptive_filter->permutation[i]]; - auto local_idx = MultiFileLocalIndex(scan_filter.filter_idx); - auto column_id = column_ids[local_idx]; - - auto &result_vector = result.data[local_idx.GetIndex()]; - auto &child_reader = root_reader.GetChildReader(column_id); - child_reader.Filter(scan_count, define_ptr, repeat_ptr, result_vector, scan_filter.filter, - *scan_filter.filter_state, state.sel, filter_count, is_first_filter); - need_to_read[local_idx.GetIndex()] = false; - is_first_filter = false; + ApplyFilter(result_vector, *filter_col.second, filter_mask, this_output_chunk_rows); } - state.adaptive_filter->EndFilter(filter_state); } // we still may have to read some cols - for (idx_t i = 0; i < column_ids.size(); i++) { - auto col_idx = MultiFileLocalIndex(i); + for (idx_t col_idx = 0; col_idx < reader_data.column_ids.size(); col_idx++) { if (!need_to_read[col_idx]) { continue; } - auto file_col_idx = column_ids[col_idx]; - if (filter_count == 0) { + auto file_col_idx = reader_data.column_ids[col_idx]; + if (filter_mask.none()) { root_reader.GetChildReader(file_col_idx).Skip(result.size()); continue; } - auto &result_vector = result.data[i]; + auto &result_vector = result.data[reader_data.column_mapping[col_idx]]; auto &child_reader = root_reader.GetChildReader(file_col_idx); - child_reader.Select(result.size(), define_ptr, repeat_ptr, result_vector, state.sel, filter_count); + child_reader.Read(result.size(), filter_mask, define_ptr, repeat_ptr, result_vector); } - if (scan_count != filter_count) { - result.Slice(state.sel, filter_count); + + idx_t sel_size = 0; + for (idx_t i = 0; i < this_output_chunk_rows; i++) { + if (filter_mask.test(i)) { + state.sel.set_index(sel_size++, i); + } } + + result.Slice(state.sel, sel_size); } else { - for (idx_t i = 0; i < column_ids.size(); i++) { - auto col_idx = MultiFileLocalIndex(i); - auto file_col_idx = column_ids[col_idx]; - auto &result_vector = result.data[i]; + for (idx_t col_idx = 0; col_idx < reader_data.column_ids.size(); col_idx++) { + auto file_col_idx = reader_data.column_ids[col_idx]; + auto &result_vector = result.data[reader_data.column_mapping[col_idx]]; auto &child_reader = root_reader.GetChildReader(file_col_idx); - auto rows_read = child_reader.Read(scan_count, define_ptr, repeat_ptr, result_vector); - if (rows_read != scan_count) { + auto rows_read = child_reader.Read(result.size(), filter_mask, define_ptr, repeat_ptr, result_vector); + if (rows_read != result.size()) { throw InvalidInputException("Mismatch in parquet read for column %llu, expected %llu rows, got %llu", - file_col_idx, scan_count, rows_read); + file_col_idx, result.size(), rows_read); } } } - rows_read += scan_count; - state.offset_in_group += scan_count; + state.group_offset += this_output_chunk_rows; return true; } diff --git a/src/duckdb/extension/parquet/parquet_statistics.cpp b/src/duckdb/extension/parquet/parquet_statistics.cpp index 228ec6cbe..7e4ceac40 100644 --- a/src/duckdb/extension/parquet/parquet_statistics.cpp +++ b/src/duckdb/extension/parquet/parquet_statistics.cpp @@ -3,10 +3,8 @@ #include "duckdb.hpp" #include "parquet_decimal_utils.hpp" #include "parquet_timestamp.hpp" -#include "parquet_float16.hpp" -#include "parquet_reader.hpp" -#include "reader/string_column_reader.hpp" -#include "reader/struct_column_reader.hpp" +#include "string_column_reader.hpp" +#include "struct_column_reader.hpp" #include "zstd/common/xxhash.hpp" #ifndef DUCKDB_AMALGAMATION @@ -15,7 +13,6 @@ #include "duckdb/common/types/value.hpp" #include "duckdb/storage/statistics/struct_stats.hpp" #include "duckdb/planner/filter/constant_filter.hpp" -#include "reader/uuid_column_reader.hpp" #endif namespace duckdb { @@ -23,9 +20,9 @@ namespace duckdb { using duckdb_parquet::ConvertedType; using duckdb_parquet::Type; -unique_ptr ParquetStatisticsUtils::CreateNumericStats(const LogicalType &type, - const ParquetColumnSchema &schema_ele, - const duckdb_parquet::Statistics &parquet_stats) { +static unique_ptr CreateNumericStats(const LogicalType &type, + const duckdb_parquet::SchemaElement &schema_ele, + const duckdb_parquet::Statistics &parquet_stats) { auto stats = NumericStats::CreateUnknown(type); // for reasons unknown to science, Parquet defines *both* `min` and `min_value` as well as `max` and @@ -51,28 +48,7 @@ unique_ptr ParquetStatisticsUtils::CreateNumericStats(const Logi return stats.ToUnique(); } -static unique_ptr CreateFloatingPointStats(const LogicalType &type, - const ParquetColumnSchema &schema_ele, - const duckdb_parquet::Statistics &parquet_stats) { - auto stats = NumericStats::CreateUnknown(type); - - // floating point values can always have NaN values - hence we cannot use the max value from the file - Value min; - Value max; - if (parquet_stats.__isset.min_value) { - min = ParquetStatisticsUtils::ConvertValue(type, schema_ele, parquet_stats.min_value); - } else if (parquet_stats.__isset.min) { - min = ParquetStatisticsUtils::ConvertValue(type, schema_ele, parquet_stats.min); - } else { - min = Value(type); - } - max = Value("nan").DefaultCastAs(type); - NumericStats::SetMin(stats, min); - NumericStats::SetMax(stats, max); - return stats.ToUnique(); -} - -Value ParquetStatisticsUtils::ConvertValue(const LogicalType &type, const ParquetColumnSchema &schema_ele, +Value ParquetStatisticsUtils::ConvertValue(const LogicalType &type, const duckdb_parquet::SchemaElement &schema_ele, const std::string &stats) { Value result; string error; @@ -82,7 +58,8 @@ Value ParquetStatisticsUtils::ConvertValue(const LogicalType &type, const Parque } return result; } -Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, const ParquetColumnSchema &schema_ele, +Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, + const duckdb_parquet::SchemaElement &schema_ele, const std::string &stats) { auto stats_data = const_data_ptr_cast(stats.c_str()); switch (type.id()) { @@ -117,27 +94,23 @@ Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, cons } return Value::BIGINT(Load(stats_data)); case LogicalTypeId::FLOAT: { - float val; - if (schema_ele.type_info == ParquetExtraTypeInfo::FLOAT16) { - if (stats.size() != sizeof(uint16_t)) { - throw InvalidInputException("Incorrect stats size for type FLOAT16"); - } - val = Float16ToFloat32(Load(stats_data)); - } else { - if (stats.size() != sizeof(float)) { - throw InvalidInputException("Incorrect stats size for type FLOAT"); - } - val = Load(stats_data); + if (stats.size() != sizeof(float)) { + throw InvalidInputException("Incorrect stats size for type FLOAT"); } + auto val = Load(stats_data); if (!Value::FloatIsFinite(val)) { return Value(); } return Value::FLOAT(val); } case LogicalTypeId::DOUBLE: { - if (schema_ele.type_info == ParquetExtraTypeInfo::DECIMAL_BYTE_ARRAY) { + switch (schema_ele.type) { + case Type::FIXED_LEN_BYTE_ARRAY: + case Type::BYTE_ARRAY: // decimals cast to double return Value::DOUBLE(ParquetDecimalUtils::ReadDecimalValue(stats_data, stats.size(), schema_ele)); + default: + break; } if (stats.size() != sizeof(double)) { throw InvalidInputException("Incorrect stats size for type DOUBLE"); @@ -151,18 +124,21 @@ Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, cons case LogicalTypeId::DECIMAL: { auto width = DecimalType::GetWidth(type); auto scale = DecimalType::GetScale(type); - switch (schema_ele.type_info) { - case ParquetExtraTypeInfo::DECIMAL_INT32: + switch (schema_ele.type) { + case Type::INT32: { if (stats.size() != sizeof(int32_t)) { throw InvalidInputException("Incorrect stats size for type %s", type.ToString()); } return Value::DECIMAL(Load(stats_data), width, scale); - case ParquetExtraTypeInfo::DECIMAL_INT64: + } + case Type::INT64: { if (stats.size() != sizeof(int64_t)) { throw InvalidInputException("Incorrect stats size for type %s", type.ToString()); } return Value::DECIMAL(Load(stats_data), width, scale); - case ParquetExtraTypeInfo::DECIMAL_BYTE_ARRAY: + } + case Type::BYTE_ARRAY: + case Type::FIXED_LEN_BYTE_ARRAY: switch (type.InternalType()) { case PhysicalType::INT16: return Value::DECIMAL( @@ -181,7 +157,7 @@ Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, cons throw InvalidInputException("Unsupported internal type for decimal"); } default: - throw NotImplementedException("Unrecognized Parquet type for Decimal"); + throw InternalException("Unsupported internal type for decimal?.."); } } case LogicalTypeId::VARCHAR: @@ -204,13 +180,21 @@ Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, cons } else { throw InvalidInputException("Incorrect stats size for type TIME"); } - switch (schema_ele.type_info) { - case ParquetExtraTypeInfo::UNIT_MS: + if (schema_ele.__isset.logicalType && schema_ele.logicalType.__isset.TIME) { + // logical type + if (schema_ele.logicalType.TIME.unit.__isset.MILLIS) { + return Value::TIME(Time::FromTimeMs(val)); + } else if (schema_ele.logicalType.TIME.unit.__isset.NANOS) { + return Value::TIME(Time::FromTimeNs(val)); + } else if (schema_ele.logicalType.TIME.unit.__isset.MICROS) { + return Value::TIME(dtime_t(val)); + } else { + throw InternalException("Time logicalType is set but unit is not defined"); + } + } + if (schema_ele.converted_type == duckdb_parquet::ConvertedType::TIME_MILLIS) { return Value::TIME(Time::FromTimeMs(val)); - case ParquetExtraTypeInfo::UNIT_NS: - return Value::TIME(Time::FromTimeNs(val)); - case ParquetExtraTypeInfo::UNIT_MICROS: - default: + } else { return Value::TIME(dtime_t(val)); } } @@ -223,40 +207,49 @@ Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, cons } else { throw InvalidInputException("Incorrect stats size for type TIMETZ"); } - switch (schema_ele.type_info) { - case ParquetExtraTypeInfo::UNIT_MS: - return Value::TIMETZ(ParquetIntToTimeMsTZ(NumericCast(val))); - case ParquetExtraTypeInfo::UNIT_NS: - return Value::TIMETZ(ParquetIntToTimeNsTZ(val)); - case ParquetExtraTypeInfo::UNIT_MICROS: - default: - return Value::TIMETZ(ParquetIntToTimeTZ(val)); + if (schema_ele.__isset.logicalType && schema_ele.logicalType.__isset.TIME) { + // logical type + if (schema_ele.logicalType.TIME.unit.__isset.MILLIS) { + return Value::TIMETZ(ParquetIntToTimeMsTZ(NumericCast(val))); + } else if (schema_ele.logicalType.TIME.unit.__isset.MICROS) { + return Value::TIMETZ(ParquetIntToTimeTZ(val)); + } else if (schema_ele.logicalType.TIME.unit.__isset.NANOS) { + return Value::TIMETZ(ParquetIntToTimeNsTZ(val)); + } else { + throw InternalException("Time With Time Zone logicalType is set but unit is not defined"); + } } + return Value::TIMETZ(ParquetIntToTimeTZ(val)); } case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIMESTAMP_TZ: { timestamp_t timestamp_value; - if (schema_ele.type_info == ParquetExtraTypeInfo::IMPALA_TIMESTAMP) { + if (schema_ele.type == Type::INT96) { if (stats.size() != sizeof(Int96)) { throw InvalidInputException("Incorrect stats size for type TIMESTAMP"); } timestamp_value = ImpalaTimestampToTimestamp(Load(stats_data)); } else { + D_ASSERT(schema_ele.type == Type::INT64); if (stats.size() != sizeof(int64_t)) { throw InvalidInputException("Incorrect stats size for type TIMESTAMP"); } auto val = Load(stats_data); - switch (schema_ele.type_info) { - case ParquetExtraTypeInfo::UNIT_MS: + if (schema_ele.__isset.logicalType && schema_ele.logicalType.__isset.TIMESTAMP) { + // logical type + if (schema_ele.logicalType.TIMESTAMP.unit.__isset.MILLIS) { + timestamp_value = Timestamp::FromEpochMs(val); + } else if (schema_ele.logicalType.TIMESTAMP.unit.__isset.NANOS) { + timestamp_value = Timestamp::FromEpochNanoSeconds(val); + } else if (schema_ele.logicalType.TIMESTAMP.unit.__isset.MICROS) { + timestamp_value = timestamp_t(val); + } else { + throw InternalException("Timestamp logicalType is set but unit is not defined"); + } + } else if (schema_ele.converted_type == duckdb_parquet::ConvertedType::TIMESTAMP_MILLIS) { timestamp_value = Timestamp::FromEpochMs(val); - break; - case ParquetExtraTypeInfo::UNIT_NS: - timestamp_value = Timestamp::FromEpochNanoSeconds(val); - break; - case ParquetExtraTypeInfo::UNIT_MICROS: - default: + } else { timestamp_value = timestamp_t(val); - break; } } if (type.id() == LogicalTypeId::TIMESTAMP_TZ) { @@ -266,61 +259,63 @@ Value ParquetStatisticsUtils::ConvertValueInternal(const LogicalType &type, cons } case LogicalTypeId::TIMESTAMP_NS: { timestamp_ns_t timestamp_value; - if (schema_ele.type_info == ParquetExtraTypeInfo::IMPALA_TIMESTAMP) { + if (schema_ele.type == Type::INT96) { if (stats.size() != sizeof(Int96)) { throw InvalidInputException("Incorrect stats size for type TIMESTAMP_NS"); } timestamp_value = ImpalaTimestampToTimestampNS(Load(stats_data)); } else { + D_ASSERT(schema_ele.type == Type::INT64); if (stats.size() != sizeof(int64_t)) { throw InvalidInputException("Incorrect stats size for type TIMESTAMP_NS"); } auto val = Load(stats_data); - switch (schema_ele.type_info) { - case ParquetExtraTypeInfo::UNIT_MS: + if (schema_ele.__isset.logicalType && schema_ele.logicalType.__isset.TIMESTAMP) { + // logical type + if (schema_ele.logicalType.TIMESTAMP.unit.__isset.MILLIS) { + timestamp_value = ParquetTimestampMsToTimestampNs(val); + } else if (schema_ele.logicalType.TIMESTAMP.unit.__isset.NANOS) { + timestamp_value = ParquetTimestampNsToTimestampNs(val); + } else if (schema_ele.logicalType.TIMESTAMP.unit.__isset.MICROS) { + timestamp_value = ParquetTimestampUsToTimestampNs(val); + } else { + throw InternalException("Timestamp (NS) logicalType is set but unit is unknown"); + } + } else if (schema_ele.converted_type == duckdb_parquet::ConvertedType::TIMESTAMP_MILLIS) { timestamp_value = ParquetTimestampMsToTimestampNs(val); - break; - case ParquetExtraTypeInfo::UNIT_NS: - timestamp_value = ParquetTimestampNsToTimestampNs(val); - break; - case ParquetExtraTypeInfo::UNIT_MICROS: - default: + } else { timestamp_value = ParquetTimestampUsToTimestampNs(val); - break; } } return Value::TIMESTAMPNS(timestamp_value); } - case LogicalTypeId::UUID: { - if (stats.size() != 16) { - throw InvalidInputException("Incorrect stats size for type UUID"); - } - auto uuid_val = UUIDValueConversion::ReadParquetUUID(const_data_ptr_cast(stats.c_str())); - return Value::UUID(uuid_val); - } default: throw InternalException("Unsupported type for stats %s", type.ToString()); } } -unique_ptr ParquetStatisticsUtils::TransformColumnStatistics(const ParquetColumnSchema &schema, +unique_ptr ParquetStatisticsUtils::TransformColumnStatistics(const ColumnReader &reader, const vector &columns) { // Not supported types - auto &type = schema.type; - if (type.id() == LogicalTypeId::ARRAY || type.id() == LogicalTypeId::MAP || type.id() == LogicalTypeId::LIST) { + if (reader.Type().id() == LogicalTypeId::ARRAY || reader.Type().id() == LogicalTypeId::MAP || + reader.Type().id() == LogicalTypeId::LIST) { return nullptr; } unique_ptr row_group_stats; // Structs are handled differently (they dont have stats) - if (type.id() == LogicalTypeId::STRUCT) { - auto struct_stats = StructStats::CreateUnknown(type); + if (reader.Type().id() == LogicalTypeId::STRUCT) { + auto struct_stats = StructStats::CreateUnknown(reader.Type()); + auto &struct_reader = reader.Cast(); // Recurse into child readers - for (idx_t i = 0; i < schema.children.size(); i++) { - auto &child_schema = schema.children[i]; - auto child_stats = ParquetStatisticsUtils::TransformColumnStatistics(child_schema, columns); + for (idx_t i = 0; i < struct_reader.child_readers.size(); i++) { + if (!struct_reader.child_readers[i]) { + continue; + } + auto &child_reader = *struct_reader.child_readers[i]; + auto child_stats = ParquetStatisticsUtils::TransformColumnStatistics(child_reader, columns); StructStats::SetChildStats(struct_stats, i, std::move(child_stats)); } row_group_stats = struct_stats.ToUnique(); @@ -334,13 +329,16 @@ unique_ptr ParquetStatisticsUtils::TransformColumnStatistics(con // Otherwise, its a standard column with stats - auto &column_chunk = columns[schema.column_index]; + auto &column_chunk = columns[reader.FileIdx()]; if (!column_chunk.__isset.meta_data || !column_chunk.meta_data.__isset.statistics) { // no stats present for row group return nullptr; } auto &parquet_stats = column_chunk.meta_data.statistics; + auto &type = reader.Type(); + auto &s_ele = reader.Schema(); + switch (type.id()) { case LogicalTypeId::UTINYINT: case LogicalTypeId::USMALLINT: @@ -350,6 +348,8 @@ unique_ptr ParquetStatisticsUtils::TransformColumnStatistics(con case LogicalTypeId::SMALLINT: case LogicalTypeId::INTEGER: case LogicalTypeId::BIGINT: + case LogicalTypeId::FLOAT: + case LogicalTypeId::DOUBLE: case LogicalTypeId::DATE: case LogicalTypeId::TIME: case LogicalTypeId::TIME_TZ: @@ -359,11 +359,7 @@ unique_ptr ParquetStatisticsUtils::TransformColumnStatistics(con case LogicalTypeId::TIMESTAMP_MS: case LogicalTypeId::TIMESTAMP_NS: case LogicalTypeId::DECIMAL: - row_group_stats = CreateNumericStats(type, schema, parquet_stats); - break; - case LogicalTypeId::FLOAT: - case LogicalTypeId::DOUBLE: - row_group_stats = CreateFloatingPointStats(type, schema, parquet_stats); + row_group_stats = CreateNumericStats(type, s_ele, parquet_stats); break; case LogicalTypeId::VARCHAR: { auto string_stats = StringStats::CreateEmpty(type); diff --git a/src/duckdb/extension/parquet/parquet_writer.cpp b/src/duckdb/extension/parquet/parquet_writer.cpp index 8605bfce7..9977f67ec 100644 --- a/src/duckdb/extension/parquet/parquet_writer.cpp +++ b/src/duckdb/extension/parquet/parquet_writer.cpp @@ -18,7 +18,6 @@ #include "duckdb/main/connection.hpp" #include "duckdb/parser/parsed_data/create_copy_function_info.hpp" #include "duckdb/parser/parsed_data/create_table_function_info.hpp" -#include "duckdb/common/types/blob.hpp" #endif namespace duckdb { @@ -317,47 +316,21 @@ void VerifyUniqueNames(const vector &names) { #endif } -struct ColumnStatsUnifier { - virtual ~ColumnStatsUnifier() = default; - - string column_name; - string global_min; - string global_max; - idx_t null_count = 0; - bool all_min_max_set = true; - bool all_nulls_set = true; - bool min_is_set = false; - bool max_is_set = false; - idx_t column_size_bytes = 0; - bool can_have_nan = false; - bool has_nan = false; - - virtual void UnifyMinMax(const string &new_min, const string &new_max) = 0; - virtual string StatsToString(const string &stats) = 0; -}; - -class ParquetStatsAccumulator { -public: - vector> stats_unifiers; -}; - ParquetWriter::ParquetWriter(ClientContext &context, FileSystem &fs, string file_name_p, vector types_p, vector names_p, CompressionCodec::type codec, ChildFieldIDs field_ids_p, const vector> &kv_metadata, shared_ptr encryption_config_p, idx_t dictionary_size_limit_p, - idx_t string_dictionary_page_size_limit_p, double bloom_filter_false_positive_ratio_p, - int64_t compression_level_p, bool debug_use_openssl_p, ParquetVersion parquet_version) + double bloom_filter_false_positive_ratio_p, int64_t compression_level_p, + bool debug_use_openssl_p, ParquetVersion parquet_version) : context(context), file_name(std::move(file_name_p)), sql_types(std::move(types_p)), column_names(std::move(names_p)), codec(codec), field_ids(std::move(field_ids_p)), encryption_config(std::move(encryption_config_p)), dictionary_size_limit(dictionary_size_limit_p), - string_dictionary_page_size_limit(string_dictionary_page_size_limit_p), bloom_filter_false_positive_ratio(bloom_filter_false_positive_ratio_p), compression_level(compression_level_p), - debug_use_openssl(debug_use_openssl_p), parquet_version(parquet_version), total_written(0), num_row_groups(0) { + debug_use_openssl(debug_use_openssl_p), parquet_version(parquet_version) { // initialize the file writer writer = make_uniq(fs, file_name.c_str(), FileFlags::FILE_FLAGS_WRITE | FileFlags::FILE_FLAGS_FILE_CREATE_NEW); - if (encryption_config) { auto &config = DBConfig::GetConfig(context); if (config.encryption_util && debug_use_openssl) { @@ -374,7 +347,6 @@ ParquetWriter::ParquetWriter(ClientContext &context, FileSystem &fs, string file // parquet files start with the string "PAR1" writer->WriteData(const_data_ptr_cast("PAR1"), 4); } - TCompactProtocolFactoryT tproto_factory; protocol = tproto_factory.getProtocol(std::make_shared(*writer)); @@ -405,29 +377,20 @@ ParquetWriter::ParquetWriter(ClientContext &context, FileSystem &fs, string file auto &unique_names = column_names; VerifyUniqueNames(unique_names); - // construct the child schemas + vector schema_path; for (idx_t i = 0; i < sql_types.size(); i++) { - auto child_schema = - ColumnWriter::FillParquetSchema(file_meta_data.schema, sql_types[i], unique_names[i], &field_ids); - column_schemas.push_back(std::move(child_schema)); - } - // now construct the writers based on the schemas - for (auto &child_schema : column_schemas) { - vector path_in_schema; - column_writers.push_back( - ColumnWriter::CreateWriterRecursive(context, *this, file_meta_data.schema, child_schema, path_in_schema)); + column_writers.push_back(ColumnWriter::CreateWriterRecursive( + context, file_meta_data.schema, *this, sql_types[i], unique_names[i], schema_path, &field_ids)); } } -ParquetWriter::~ParquetWriter() { -} - void ParquetWriter::PrepareRowGroup(ColumnDataCollection &buffer, PreparedRowGroup &result) { // We write 8 columns at a time so that iterating over ColumnDataCollection is more efficient static constexpr idx_t COLUMNS_PER_PASS = 8; - // We want these to be buffer-managed - D_ASSERT(buffer.GetAllocatorType() == ColumnDataAllocatorType::BUFFER_MANAGER_ALLOCATOR); + // We want these to be in-memory/hybrid so we don't have to copy over strings to the dictionary + D_ASSERT(buffer.GetAllocatorType() == ColumnDataAllocatorType::IN_MEMORY_ALLOCATOR || + buffer.GetAllocatorType() == ColumnDataAllocatorType::HYBRID); // set up a new row group for this chunk collection auto &row_group = result.row_group; @@ -487,6 +450,7 @@ void ParquetWriter::PrepareRowGroup(ColumnDataCollection &buffer, PreparedRowGro states.push_back(std::move(write_state)); } } + result.heaps = buffer.GetHeapReferences(); } // Validation code adapted from Impala @@ -545,8 +509,7 @@ void ParquetWriter::FlushRowGroup(PreparedRowGroup &prepared) { file_meta_data.row_groups.push_back(row_group); file_meta_data.num_rows += row_group.num_rows; - total_written = writer->GetTotalWritten(); - num_row_groups++; + prepared.heaps.clear(); } void ParquetWriter::Flush(ColumnDataCollection &buffer) { @@ -561,275 +524,6 @@ void ParquetWriter::Flush(ColumnDataCollection &buffer) { FlushRowGroup(prepared_row_group); } -template -struct BaseNumericStatsUnifier : public ColumnStatsUnifier { - void UnifyMinMax(const string &new_min, const string &new_max) override { - if (new_min.size() != sizeof(T) || new_max.size() != sizeof(T)) { - throw InternalException("Incorrect size for stats in UnifyMinMax"); - } - if (!min_is_set) { - global_min = new_min; - min_is_set = true; - } else { - auto min_val = Load(const_data_ptr_cast(new_min.data())); - auto global_min_val = Load(const_data_ptr_cast(global_min.data())); - if (LessThan::Operation(min_val, global_min_val)) { - global_min = new_min; - } - } - if (!max_is_set) { - global_max = new_max; - max_is_set = true; - } else { - auto max_val = Load(const_data_ptr_cast(new_max.data())); - auto global_max_val = Load(const_data_ptr_cast(global_max.data())); - if (GreaterThan::Operation(max_val, global_max_val)) { - global_max = new_max; - } - } - } -}; - -template -struct NumericStatsUnifier : public BaseNumericStatsUnifier { - string StatsToString(const string &stats) override { - if (stats.empty()) { - return string(); - } - return Value::CreateValue(Load(const_data_ptr_cast(stats.data()))).ToString(); - } -}; - -template -struct DecimalStatsUnifier : public NumericStatsUnifier { - DecimalStatsUnifier(uint8_t width, uint8_t scale) : width(width), scale(scale) { - } - - uint8_t width; - uint8_t scale; - - string StatsToString(const string &stats) override { - if (stats.empty()) { - return string(); - } - auto numeric_val = Load(const_data_ptr_cast(stats.data())); - return Value::DECIMAL(numeric_val, width, scale).ToString(); - } -}; - -struct BaseStringStatsUnifier : public ColumnStatsUnifier { - void UnifyMinMax(const string &new_min, const string &new_max) override { - if (!min_is_set) { - global_min = new_min; - min_is_set = true; - } else { - if (LessThan::Operation(string_t(new_min), string_t(global_min))) { - global_min = new_min; - } - } - if (!max_is_set) { - global_max = new_max; - max_is_set = true; - } else { - if (GreaterThan::Operation(string_t(new_max), string_t(global_max))) { - global_max = new_max; - } - } - } -}; - -struct StringStatsUnifier : public BaseStringStatsUnifier { - string StatsToString(const string &stats) override { - return stats; - } -}; - -struct BlobStatsUnifier : public BaseStringStatsUnifier { - string StatsToString(const string &stats) override { - // convert blobs to hexadecimal - auto data = const_data_ptr_cast(stats.c_str()); - auto len = stats.size(); - string result; - result.reserve(len * 2); - for (idx_t i = 0; i < len; i++) { - auto byte_a = data[i] >> 4; - auto byte_b = data[i] & 0x0F; - result += Blob::HEX_TABLE[byte_a]; - result += Blob::HEX_TABLE[byte_b]; - } - return result; - } -}; - -struct UUIDStatsUnifier : public BaseStringStatsUnifier { - string StatsToString(const string &stats) override { - if (stats.size() != 16) { - return string(); - } - auto data_ptr = const_data_ptr_cast(stats.c_str()); - static char const UUID_DIGITS[] = "0123456789abcdef"; - string result; - // UUID format is XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX - // i.e. dashes are at bytes 4, 6, 8, 10 - for (idx_t i = 0; i < 16; i++) { - if (i == 4 || i == 6 || i == 8 || i == 10) { - result += "-"; - } - result += UUID_DIGITS[data_ptr[i] >> 4]; - result += UUID_DIGITS[data_ptr[i] & 0xf]; - } - return result; - } -}; -struct NullStatsUnifier : public ColumnStatsUnifier { - void UnifyMinMax(const string &new_min, const string &new_max) override { - } - - string StatsToString(const string &stats) override { - return string(); - } -}; - -unique_ptr GetBaseStatsUnifier(const LogicalType &type) { - switch (type.id()) { - case LogicalTypeId::BOOLEAN: - return make_uniq(); - case LogicalTypeId::TINYINT: - case LogicalTypeId::SMALLINT: - case LogicalTypeId::INTEGER: - case LogicalTypeId::UTINYINT: - case LogicalTypeId::USMALLINT: - return make_uniq>(); - case LogicalTypeId::DATE: - return make_uniq>(); - case LogicalTypeId::BIGINT: - return make_uniq>(); - case LogicalTypeId::TIME: - return make_uniq>(); - case LogicalTypeId::TIMESTAMP_SEC: - case LogicalTypeId::TIMESTAMP: - return make_uniq>(); - case LogicalTypeId::TIMESTAMP_TZ: - return make_uniq>(); - case LogicalTypeId::TIMESTAMP_MS: - return make_uniq>(); - case LogicalTypeId::TIMESTAMP_NS: - return make_uniq>(); - case LogicalTypeId::TIME_TZ: - return make_uniq>(); - case LogicalTypeId::UINTEGER: - return make_uniq>(); - case LogicalTypeId::UBIGINT: - return make_uniq>(); - case LogicalTypeId::FLOAT: - return make_uniq>(); - case LogicalTypeId::HUGEINT: - case LogicalTypeId::UHUGEINT: - case LogicalTypeId::DOUBLE: - return make_uniq>(); - case LogicalTypeId::DECIMAL: { - auto width = DecimalType::GetWidth(type); - auto scale = DecimalType::GetScale(type); - switch (type.InternalType()) { - case PhysicalType::INT16: - case PhysicalType::INT32: - return make_uniq>(width, scale); - case PhysicalType::INT64: - return make_uniq>(width, scale); - default: - return make_uniq(); - } - } - case LogicalTypeId::BLOB: - return make_uniq(); - case LogicalTypeId::VARCHAR: - return make_uniq(); - case LogicalTypeId::UUID: - return make_uniq(); - case LogicalTypeId::INTERVAL:; - case LogicalTypeId::ENUM: - default: - return make_uniq(); - } -} - -void GetStatsUnifier(const ParquetColumnSchema &schema, vector> &unifiers, - string base_name = string()) { - if (!base_name.empty()) { - base_name += "."; - } - base_name += KeywordHelper::WriteQuoted(schema.name, '\"'); - if (schema.children.empty()) { - auto unifier = GetBaseStatsUnifier(schema.type); - unifier->column_name = std::move(base_name); - unifiers.push_back(std::move(unifier)); - return; - } - for (auto &child_schema : schema.children) { - GetStatsUnifier(child_schema, unifiers, base_name); - } -} - -void ParquetWriter::FlushColumnStats(idx_t col_idx, duckdb_parquet::ColumnChunk &column, - optional_ptr writer_stats) { - if (!written_stats) { - return; - } - // push the stats of this column into the unifier - auto &stats_unifier = stats_accumulator->stats_unifiers[col_idx]; - bool has_nan = false; - if (writer_stats) { - stats_unifier->can_have_nan = writer_stats->CanHaveNaN(); - has_nan = writer_stats->HasNaN(); - stats_unifier->has_nan = has_nan; - } - if (column.meta_data.__isset.statistics) { - if (has_nan && writer_stats->HasStats()) { - // if we have NaN values we have not written the min/max to the Parquet file - // BUT we can return them as part of RETURN STATS by fetching them from the stats directly - stats_unifier->UnifyMinMax(writer_stats->GetMin(), writer_stats->GetMax()); - } else if (column.meta_data.statistics.__isset.min_value && column.meta_data.statistics.__isset.max_value) { - stats_unifier->UnifyMinMax(column.meta_data.statistics.min_value, column.meta_data.statistics.max_value); - } else { - stats_unifier->all_min_max_set = false; - } - if (column.meta_data.statistics.__isset.null_count) { - stats_unifier->null_count += column.meta_data.statistics.null_count; - } else { - stats_unifier->all_nulls_set = false; - } - stats_unifier->column_size_bytes += column.meta_data.total_compressed_size; - } -} - -void ParquetWriter::GatherWrittenStatistics() { - written_stats->row_count = file_meta_data.num_rows; - - // finalize the min/max values and write to column stats - for (idx_t c = 0; c < stats_accumulator->stats_unifiers.size(); c++) { - auto &stats_unifier = stats_accumulator->stats_unifiers[c]; - case_insensitive_map_t column_stats; - column_stats["column_size_bytes"] = Value::UBIGINT(stats_unifier->column_size_bytes); - if (stats_unifier->all_min_max_set) { - auto min_value = stats_unifier->StatsToString(stats_unifier->global_min); - auto max_value = stats_unifier->StatsToString(stats_unifier->global_max); - if (stats_unifier->min_is_set) { - column_stats["min"] = min_value; - } - if (stats_unifier->max_is_set) { - column_stats["max"] = max_value; - } - } - if (stats_unifier->all_nulls_set) { - column_stats["null_count"] = Value::UBIGINT(stats_unifier->null_count); - } - if (stats_unifier->can_have_nan) { - column_stats["has_nan"] = Value::BOOLEAN(stats_unifier->has_nan); - } - written_stats->column_statistics.insert(make_pair(stats_unifier->column_name, std::move(column_stats))); - } -} - void ParquetWriter::Finalize() { // dump the bloom filters right before footer, not if stuff is encrypted @@ -878,8 +572,7 @@ void ParquetWriter::Finalize() { Write(file_meta_data); - uint32_t footer_size = writer->GetTotalWritten() - metadata_start_offset; - writer->Write(footer_size); + writer->Write(writer->GetTotalWritten() - metadata_start_offset); if (encryption_config) { // encrypted parquet files also end with the string "PARE" @@ -888,12 +581,6 @@ void ParquetWriter::Finalize() { // parquet files also end with the string "PAR1" writer->WriteData(const_data_ptr_cast("PAR1"), 4); } - if (written_stats) { - // gather written statistics from the metadata - GatherWrittenStatistics(); - written_stats->file_size_bytes = writer->GetTotalWritten(); - written_stats->footer_size_bytes = Value::UBIGINT(footer_size); - } // flush to disk writer->Close(); @@ -918,13 +605,4 @@ void ParquetWriter::BufferBloomFilter(idx_t col_idx, unique_ptr(); - // create the per-column stats unifiers - for (auto &column_writer : column_writers) { - GetStatsUnifier(column_writer->Schema(), stats_accumulator->stats_unifiers); - } -} - } // namespace duckdb diff --git a/src/duckdb/extension/parquet/serialize_parquet.cpp b/src/duckdb/extension/parquet/serialize_parquet.cpp index 2fde0ee56..5fa792cd3 100644 --- a/src/duckdb/extension/parquet/serialize_parquet.cpp +++ b/src/duckdb/extension/parquet/serialize_parquet.cpp @@ -65,25 +65,25 @@ shared_ptr ParquetEncryptionConfig::Deserialize(Deseria return result; } -void ParquetOptionsSerialization::Serialize(Serializer &serializer) const { - serializer.WritePropertyWithDefault(100, "binary_as_string", parquet_options.binary_as_string); - serializer.WritePropertyWithDefault(101, "file_row_number", parquet_options.file_row_number); - serializer.WriteProperty(102, "file_options", file_options); - serializer.WritePropertyWithDefault>(103, "schema", parquet_options.schema); - serializer.WritePropertyWithDefault>(104, "encryption_config", parquet_options.encryption_config, nullptr); - serializer.WritePropertyWithDefault(105, "debug_use_openssl", parquet_options.debug_use_openssl, true); - serializer.WritePropertyWithDefault(106, "explicit_cardinality", parquet_options.explicit_cardinality, 0); +void ParquetOptions::Serialize(Serializer &serializer) const { + serializer.WritePropertyWithDefault(100, "binary_as_string", binary_as_string); + serializer.WritePropertyWithDefault(101, "file_row_number", file_row_number); + serializer.WriteProperty(102, "file_options", file_options); + serializer.WritePropertyWithDefault>(103, "schema", schema); + serializer.WritePropertyWithDefault>(104, "encryption_config", encryption_config, nullptr); + serializer.WritePropertyWithDefault(105, "debug_use_openssl", debug_use_openssl, true); + serializer.WritePropertyWithDefault(106, "explicit_cardinality", explicit_cardinality, 0); } -ParquetOptionsSerialization ParquetOptionsSerialization::Deserialize(Deserializer &deserializer) { - ParquetOptionsSerialization result; - deserializer.ReadPropertyWithDefault(100, "binary_as_string", result.parquet_options.binary_as_string); - deserializer.ReadPropertyWithDefault(101, "file_row_number", result.parquet_options.file_row_number); - deserializer.ReadProperty(102, "file_options", result.file_options); - deserializer.ReadPropertyWithDefault>(103, "schema", result.parquet_options.schema); - deserializer.ReadPropertyWithExplicitDefault>(104, "encryption_config", result.parquet_options.encryption_config, nullptr); - deserializer.ReadPropertyWithExplicitDefault(105, "debug_use_openssl", result.parquet_options.debug_use_openssl, true); - deserializer.ReadPropertyWithExplicitDefault(106, "explicit_cardinality", result.parquet_options.explicit_cardinality, 0); +ParquetOptions ParquetOptions::Deserialize(Deserializer &deserializer) { + ParquetOptions result; + deserializer.ReadPropertyWithDefault(100, "binary_as_string", result.binary_as_string); + deserializer.ReadPropertyWithDefault(101, "file_row_number", result.file_row_number); + deserializer.ReadProperty(102, "file_options", result.file_options); + deserializer.ReadPropertyWithDefault>(103, "schema", result.schema); + deserializer.ReadPropertyWithExplicitDefault>(104, "encryption_config", result.encryption_config, nullptr); + deserializer.ReadPropertyWithExplicitDefault(105, "debug_use_openssl", result.debug_use_openssl, true); + deserializer.ReadPropertyWithExplicitDefault(106, "explicit_cardinality", result.explicit_cardinality, 0); return result; } diff --git a/src/duckdb/src/catalog/catalog.cpp b/src/duckdb/src/catalog/catalog.cpp index 6c7ad8c90..6821de734 100644 --- a/src/duckdb/src/catalog/catalog.cpp +++ b/src/duckdb/src/catalog/catalog.cpp @@ -325,17 +325,13 @@ unique_ptr Catalog::BindAlterAddIndex(Binder &binder, TableCata // Lookup Structures //===--------------------------------------------------------------------===// struct CatalogLookup { - CatalogLookup(Catalog &catalog, CatalogType catalog_type, string schema_p, string name_p) - : catalog(catalog), schema(std::move(schema_p)), name(std::move(name_p)), lookup_info(catalog_type, name) { - } - CatalogLookup(Catalog &catalog, string schema_p, const EntryLookupInfo &lookup_p) - : catalog(catalog), schema(std::move(schema_p)), name(lookup_p.GetEntryName()), lookup_info(lookup_p, name) { + CatalogLookup(Catalog &catalog, string schema_p, string name_p) + : catalog(catalog), schema(std::move(schema_p)), name(std::move(name_p)) { } Catalog &catalog; string schema; string name; - EntryLookupInfo lookup_info; }; //===--------------------------------------------------------------------===// @@ -349,8 +345,7 @@ void Catalog::DropEntry(ClientContext &context, DropInfo &info) { } CatalogEntryRetriever retriever(context); - EntryLookupInfo lookup_info(info.type, info.name); - auto lookup = LookupEntry(retriever, info.schema, lookup_info, info.if_not_found); + auto lookup = LookupEntry(retriever, info.type, info.schema, info.name, info.if_not_found); if (!lookup.Found()) { return; } @@ -358,69 +353,36 @@ void Catalog::DropEntry(ClientContext &context, DropInfo &info) { lookup.schema->DropEntry(context, info); } -SchemaCatalogEntry &Catalog::GetSchema(ClientContext &context, const string &schema) { - return GetSchema(GetCatalogTransaction(context), schema); -} - -SchemaCatalogEntry &Catalog::GetSchema(CatalogTransaction transaction, const string &schema) { - EntryLookupInfo schema_lookup(CatalogType::SCHEMA_ENTRY, schema); - return GetSchema(transaction, schema_lookup); -} - -SchemaCatalogEntry &Catalog::GetSchema(ClientContext &context, const EntryLookupInfo &schema_lookup) { - return *Catalog::GetSchema(context, schema_lookup, OnEntryNotFound::THROW_EXCEPTION); -} - -SchemaCatalogEntry &Catalog::GetSchema(ClientContext &context, const string &catalog_name, const string &schema) { - return *GetSchema(context, catalog_name, schema, OnEntryNotFound::THROW_EXCEPTION); -} - -optional_ptr Catalog::GetSchema(ClientContext &context, const string &schema, - OnEntryNotFound if_not_found) { - return GetSchema(GetCatalogTransaction(context), schema, if_not_found); -} - -optional_ptr Catalog::GetSchema(CatalogTransaction transaction, const string &schema, - OnEntryNotFound if_not_found) { - EntryLookupInfo schema_lookup(CatalogType::SCHEMA_ENTRY, schema); - return LookupSchema(transaction, schema_lookup, if_not_found); -} - -optional_ptr Catalog::GetSchema(ClientContext &context, const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found) { - return LookupSchema(GetCatalogTransaction(context), schema_lookup, if_not_found); -} - -optional_ptr Catalog::GetSchema(ClientContext &context, const string &catalog_name, - const string &schema, OnEntryNotFound if_not_found) { - EntryLookupInfo schema_lookup(CatalogType::SCHEMA_ENTRY, schema); - return GetSchema(context, catalog_name, schema_lookup, if_not_found); +SchemaCatalogEntry &Catalog::GetSchema(ClientContext &context, const string &name, QueryErrorContext error_context) { + return *Catalog::GetSchema(context, name, OnEntryNotFound::THROW_EXCEPTION, error_context); } -SchemaCatalogEntry &Catalog::GetSchema(ClientContext &context, const string &catalog_name, - const EntryLookupInfo &schema_lookup) { - return *Catalog::GetSchema(context, catalog_name, schema_lookup, OnEntryNotFound::THROW_EXCEPTION); +optional_ptr Catalog::GetSchema(ClientContext &context, const string &schema_name, + OnEntryNotFound if_not_found, QueryErrorContext error_context) { + return GetSchema(GetCatalogTransaction(context), schema_name, if_not_found, error_context); } -SchemaCatalogEntry &Catalog::GetSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup) { - return *LookupSchema(transaction, schema_lookup, OnEntryNotFound::THROW_EXCEPTION); +SchemaCatalogEntry &Catalog::GetSchema(ClientContext &context, const string &catalog_name, const string &schema_name, + QueryErrorContext error_context) { + return *Catalog::GetSchema(context, catalog_name, schema_name, OnEntryNotFound::THROW_EXCEPTION, error_context); } -bool Catalog::CheckAmbiguousCatalogOrSchema(ClientContext &context, const string &schema) { - EntryLookupInfo schema_lookup(CatalogType::SCHEMA_ENTRY, schema); - return !!GetSchema(context, schema_lookup, OnEntryNotFound::RETURN_NULL); +SchemaCatalogEntry &Catalog::GetSchema(CatalogTransaction transaction, const string &name, + QueryErrorContext error_context) { + return *GetSchema(transaction, name, OnEntryNotFound::THROW_EXCEPTION, error_context); } //===--------------------------------------------------------------------===// // Lookup //===--------------------------------------------------------------------===// -vector Catalog::SimilarEntriesInSchemas(ClientContext &context, const EntryLookupInfo &lookup_info, +vector Catalog::SimilarEntriesInSchemas(ClientContext &context, const string &entry_name, + CatalogType type, const reference_set_t &schemas) { vector results; for (auto schema_ref : schemas) { auto &schema = schema_ref.get(); auto transaction = schema.catalog.GetCatalogTransaction(context); - auto entry = schema.GetSimilarEntry(transaction, lookup_info); + auto entry = schema.GetSimilarEntry(transaction, type, entry_name); if (!entry.Found()) { // no similar entry found continue; @@ -644,11 +606,12 @@ CatalogException Catalog::UnrecognizedConfigurationError(ClientContext &context, throw CatalogException::MissingEntry("configuration parameter", name, potential_names); } -CatalogException Catalog::CreateMissingEntryException(CatalogEntryRetriever &retriever, - const EntryLookupInfo &lookup_info, - const reference_set_t &schemas) { +CatalogException Catalog::CreateMissingEntryException(CatalogEntryRetriever &retriever, const string &entry_name, + CatalogType type, + const reference_set_t &schemas, + QueryErrorContext error_context) { auto &context = retriever.GetContext(); - auto entries = SimilarEntriesInSchemas(context, lookup_info, schemas); + auto entries = SimilarEntriesInSchemas(context, entry_name, type, schemas); reference_set_t unseen_schemas; auto &db_manager = DatabaseManager::Get(context); @@ -671,8 +634,6 @@ CatalogException Catalog::CreateMissingEntryException(CatalogEntryRetriever &ret } // check if the entry exists in any extension string extension_name; - auto type = lookup_info.GetCatalogType(); - auto &entry_name = lookup_info.GetEntryName(); if (type == CatalogType::TABLE_FUNCTION_ENTRY || type == CatalogType::SCALAR_FUNCTION_ENTRY || type == CatalogType::AGGREGATE_FUNCTION_ENTRY || type == CatalogType::PRAGMA_FUNCTION_ENTRY) { auto lookup_result = ExtensionHelper::FindExtensionInFunctionEntries(entry_name, EXTENSION_FUNCTIONS); @@ -730,7 +691,7 @@ CatalogException Catalog::CreateMissingEntryException(CatalogEntryRetriever &ret // entries in other schemas get a penalty // however, if there is an exact match in another schema, we will always show it static constexpr const double UNSEEN_PENALTY = 0.2; - auto unseen_entries = SimilarEntriesInSchemas(context, lookup_info, unseen_schemas); + auto unseen_entries = SimilarEntriesInSchemas(context, entry_name, type, unseen_schemas); set suggestions; if (!unseen_entries.empty() && (unseen_entries[0].score == 1.0 || unseen_entries[0].score - UNSEEN_PENALTY > (entries.empty() ? 0.0 : entries[0].score))) { @@ -760,28 +721,25 @@ CatalogException Catalog::CreateMissingEntryException(CatalogEntryRetriever &ret did_you_mean = StringUtil::Join(suggestions, " or "); } - return CatalogException::MissingEntry(lookup_info, did_you_mean); + return CatalogException::MissingEntry(type, entry_name, did_you_mean, error_context); } -CatalogEntryLookup Catalog::TryLookupEntryInternal(CatalogTransaction transaction, const string &schema, - const EntryLookupInfo &lookup_info) { - if (lookup_info.GetAtClause() && !SupportsTimeTravel()) { - return {nullptr, nullptr, ErrorData(BinderException("Catalog type does not support time travel"))}; - } - auto schema_lookup = EntryLookupInfo::SchemaLookup(lookup_info, schema); - auto schema_entry = LookupSchema(transaction, schema_lookup, OnEntryNotFound::RETURN_NULL); +CatalogEntryLookup Catalog::TryLookupEntryInternal(CatalogTransaction transaction, CatalogType type, + const string &schema, const string &name) { + auto schema_entry = GetSchema(transaction, schema, OnEntryNotFound::RETURN_NULL); if (!schema_entry) { return {nullptr, nullptr, ErrorData()}; } - auto entry = schema_entry->LookupEntry(transaction, lookup_info); + auto entry = schema_entry->GetEntry(transaction, type, name); if (!entry) { return {schema_entry, nullptr, ErrorData()}; } return {schema_entry, entry, ErrorData()}; } -CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found) { +CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &schema, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { auto &context = retriever.GetContext(); reference_set_t schemas; if (IsInvalidSchema(schema)) { @@ -790,7 +748,7 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con for (auto &entry : entries) { auto &candidate_schema = entry.schema; auto transaction = GetCatalogTransaction(context); - auto result = TryLookupEntryInternal(transaction, candidate_schema, lookup_info); + auto result = TryLookupEntryInternal(transaction, type, candidate_schema, name); if (result.Found()) { return result; } @@ -800,7 +758,7 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con } } else { auto transaction = GetCatalogTransaction(context); - auto result = TryLookupEntryInternal(transaction, schema, lookup_info); + auto result = TryLookupEntryInternal(transaction, type, schema, name); if (result.Found()) { return result; } @@ -815,18 +773,18 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con // Check if the default database is actually attached. CreateMissingEntryException will throw binder exception // otherwise. if (!GetCatalogEntry(context, GetDefaultCatalog(retriever))) { - auto except = CatalogException("%s with name %s does not exist!", - CatalogTypeToString(lookup_info.GetCatalogType()), lookup_info.GetEntryName()); + auto except = CatalogException("%s with name %s does not exist!", CatalogTypeToString(type), name); return {nullptr, nullptr, ErrorData(except)}; } else { - auto except = CreateMissingEntryException(retriever, lookup_info, schemas); + auto except = CreateMissingEntryException(retriever, name, type, schemas, error_context); return {nullptr, nullptr, ErrorData(except)}; } } -CatalogEntryLookup Catalog::LookupEntry(CatalogEntryRetriever &retriever, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found) { - auto res = TryLookupEntry(retriever, schema, lookup_info, if_not_found); +CatalogEntryLookup Catalog::LookupEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &schema, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { + auto res = TryLookupEntry(retriever, type, schema, name, if_not_found, error_context); if (res.error.HasError()) { res.error.Throw(); @@ -835,29 +793,20 @@ CatalogEntryLookup Catalog::LookupEntry(CatalogEntryRetriever &retriever, const return res; } -CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, const vector &lookups, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found) { +CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, vector &lookups, + CatalogType type, const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { auto &context = retriever.GetContext(); reference_set_t schemas; - bool all_errors = true; - ErrorData error_data; for (auto &lookup : lookups) { auto transaction = lookup.catalog.GetCatalogTransaction(context); - auto result = lookup.catalog.TryLookupEntryInternal(transaction, lookup.schema, lookup.lookup_info); + auto result = lookup.catalog.TryLookupEntryInternal(transaction, type, lookup.schema, lookup.name); if (result.Found()) { return result; } if (result.schema) { schemas.insert(*result.schema); } - if (!result.error.HasError()) { - all_errors = false; - } else { - error_data = std::move(result.error); - } - } - if (all_errors && error_data.HasError()) { - error_data.Throw(); } if (if_not_found == OnEntryNotFound::RETURN_NULL) { @@ -866,32 +815,30 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con // Check if the default database is actually attached. CreateMissingEntryException will throw binder exception // otherwise. if (!GetCatalogEntry(context, GetDefaultCatalog(retriever))) { - auto except = CatalogException("%s with name %s does not exist!", - CatalogTypeToString(lookup_info.GetCatalogType()), lookup_info.GetEntryName()); + auto except = CatalogException("%s with name %s does not exist!", CatalogTypeToString(type), name); return {nullptr, nullptr, ErrorData(except)}; } else { - auto except = CreateMissingEntryException(retriever, lookup_info, schemas); + auto except = CreateMissingEntryException(retriever, name, type, schemas, error_context); return {nullptr, nullptr, ErrorData(except)}; } } -CatalogEntryLookup Catalog::TryLookupDefaultTable(CatalogEntryRetriever &retriever, const string &catalog, - const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound if_not_found) { +CatalogEntryLookup Catalog::TryLookupDefaultTable(CatalogEntryRetriever &retriever, CatalogType type, + const string &catalog, const string &schema, const string &name, + OnEntryNotFound if_not_found, QueryErrorContext error_context) { // Default tables of catalogs can only be accessed by the catalog name directly if (!schema.empty() || !catalog.empty()) { return {nullptr, nullptr, ErrorData()}; } vector catalog_by_name_lookups; - auto catalog_by_name = GetCatalogEntry(retriever, lookup_info.GetEntryName()); + auto catalog_by_name = GetCatalogEntry(retriever, name); if (catalog_by_name && catalog_by_name->HasDefaultTable()) { - catalog_by_name_lookups.emplace_back(*catalog_by_name, CatalogType::TABLE_ENTRY, - catalog_by_name->GetDefaultTableSchema(), + catalog_by_name_lookups.emplace_back(*catalog_by_name, catalog_by_name->GetDefaultTableSchema(), catalog_by_name->GetDefaultTable()); } - return TryLookupEntry(retriever, catalog_by_name_lookups, lookup_info, if_not_found); + return TryLookupEntry(retriever, catalog_by_name_lookups, type, name, if_not_found, error_context); } static void ThrowDefaultTableAmbiguityException(CatalogEntryLookup &base_lookup, CatalogEntryLookup &default_table, @@ -912,9 +859,9 @@ static void ThrowDefaultTableAmbiguityException(CatalogEntryLookup &base_lookup, name, entry_type, name, name, entry_type, fully_qualified_name_hint, fully_qualified_catalog_name_hint); } -CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, const string &catalog, - const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound if_not_found) { +CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &catalog, + const string &schema, const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { auto entries = GetCatalogEntries(retriever, catalog, schema); vector lookups; vector final_lookups; @@ -930,11 +877,11 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con return {nullptr, nullptr, ErrorData()}; } D_ASSERT(catalog_entry); - auto lookup_behavior = catalog_entry->CatalogTypeLookupRule(lookup_info.GetCatalogType()); + auto lookup_behavior = catalog_entry->CatalogTypeLookupRule(type); if (lookup_behavior == CatalogLookupBehavior::STANDARD) { - lookups.emplace_back(*catalog_entry, entry.schema, lookup_info); + lookups.emplace_back(*catalog_entry, entry.schema, name); } else if (lookup_behavior == CatalogLookupBehavior::LOWER_PRIORITY) { - final_lookups.emplace_back(*catalog_entry, entry.schema, lookup_info); + final_lookups.emplace_back(*catalog_entry, entry.schema, name); } } @@ -943,16 +890,16 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con } // Do the main lookup - auto lookup_result = TryLookupEntry(retriever, lookups, lookup_info, if_not_found); + auto lookup_result = TryLookupEntry(retriever, lookups, type, name, if_not_found, error_context); // Special case for tables: we do a second lookup searching for catalogs with default tables that also match this // lookup - if (lookup_info.GetCatalogType() == CatalogType::TABLE_ENTRY) { + if (type == CatalogType::TABLE_ENTRY) { auto lookup_result_default_table = - TryLookupDefaultTable(retriever, catalog, schema, lookup_info, OnEntryNotFound::RETURN_NULL); + TryLookupDefaultTable(retriever, type, catalog, schema, name, OnEntryNotFound::RETURN_NULL, error_context); if (lookup_result_default_table.Found() && lookup_result.Found()) { - ThrowDefaultTableAmbiguityException(lookup_result, lookup_result_default_table, lookup_info.GetEntryName()); + ThrowDefaultTableAmbiguityException(lookup_result, lookup_result_default_table, name); } if (lookup_result_default_table.Found()) { @@ -963,33 +910,15 @@ CatalogEntryLookup Catalog::TryLookupEntry(CatalogEntryRetriever &retriever, con return lookup_result; } -CatalogEntry &Catalog::GetEntry(ClientContext &context, CatalogType catalog_type, const string &catalog_name, - const string &schema_name, const string &name) { - EntryLookupInfo lookup_info(catalog_type, name); - return GetEntry(context, catalog_name, schema_name, lookup_info); -} - -optional_ptr Catalog::GetEntry(ClientContext &context, CatalogType catalog_type, const string &schema, - const string &name, OnEntryNotFound if_not_found) { - EntryLookupInfo lookup_info(catalog_type, name); - return GetEntry(context, schema, lookup_info, if_not_found); -} - -CatalogEntry &Catalog::GetEntry(ClientContext &context, CatalogType catalog_type, const string &schema_name, - const string &name) { - EntryLookupInfo lookup_info(catalog_type, name); - return GetEntry(context, schema_name, lookup_info); -} - -optional_ptr Catalog::GetEntry(CatalogEntryRetriever &retriever, const string &schema_name, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found) { - auto lookup_entry = TryLookupEntry(retriever, schema_name, lookup_info, if_not_found); +optional_ptr Catalog::GetEntry(CatalogEntryRetriever &retriever, CatalogType type, + const string &schema_name, const string &name, + OnEntryNotFound if_not_found, QueryErrorContext error_context) { + auto lookup_entry = TryLookupEntry(retriever, type, schema_name, name, if_not_found, error_context); // Try autoloading extension to resolve lookup if (!lookup_entry.Found()) { - if (AutoLoadExtensionByCatalogEntry(*retriever.GetContext().db, lookup_info.GetCatalogType(), - lookup_info.GetEntryName())) { - lookup_entry = TryLookupEntry(retriever, schema_name, lookup_info, if_not_found); + if (AutoLoadExtensionByCatalogEntry(*retriever.GetContext().db, type, name)) { + lookup_entry = TryLookupEntry(retriever, type, schema_name, name, if_not_found, error_context); } } @@ -1000,26 +929,27 @@ optional_ptr Catalog::GetEntry(CatalogEntryRetriever &retriever, c return lookup_entry.entry.get(); } -optional_ptr Catalog::GetEntry(ClientContext &context, const string &schema_name, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found) { +optional_ptr Catalog::GetEntry(ClientContext &context, CatalogType type, const string &schema_name, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { CatalogEntryRetriever retriever(context); - return GetEntry(retriever, schema_name, lookup_info, if_not_found); + return GetEntry(retriever, type, schema_name, name, if_not_found, error_context); } -CatalogEntry &Catalog::GetEntry(ClientContext &context, const string &schema, const EntryLookupInfo &lookup_info) { - return *Catalog::GetEntry(context, schema, lookup_info, OnEntryNotFound::THROW_EXCEPTION); +CatalogEntry &Catalog::GetEntry(ClientContext &context, CatalogType type, const string &schema, const string &name, + QueryErrorContext error_context) { + return *Catalog::GetEntry(context, type, schema, name, OnEntryNotFound::THROW_EXCEPTION, error_context); } -optional_ptr Catalog::GetEntry(CatalogEntryRetriever &retriever, const string &catalog, - const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound if_not_found) { - auto result = TryLookupEntry(retriever, catalog, schema, lookup_info, if_not_found); +optional_ptr Catalog::GetEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &catalog, + const string &schema, const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { + auto result = TryLookupEntry(retriever, type, catalog, schema, name, if_not_found, error_context); // Try autoloading extension to resolve lookup if (!result.Found()) { - if (AutoLoadExtensionByCatalogEntry(*retriever.GetContext().db, lookup_info.GetCatalogType(), - lookup_info.GetEntryName())) { - result = TryLookupEntry(retriever, catalog, schema, lookup_info, if_not_found); + if (AutoLoadExtensionByCatalogEntry(*retriever.GetContext().db, type, name)) { + result = TryLookupEntry(retriever, type, catalog, schema, name, if_not_found, error_context); } } @@ -1033,21 +963,22 @@ optional_ptr Catalog::GetEntry(CatalogEntryRetriever &retriever, c } return result.entry.get(); } -optional_ptr Catalog::GetEntry(ClientContext &context, const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found) { +optional_ptr Catalog::GetEntry(ClientContext &context, CatalogType type, const string &catalog, + const string &schema, const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { CatalogEntryRetriever retriever(context); - return GetEntry(retriever, catalog, schema, lookup_info, if_not_found); + return GetEntry(retriever, type, catalog, schema, name, if_not_found, error_context); } -CatalogEntry &Catalog::GetEntry(ClientContext &context, const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info) { - return *Catalog::GetEntry(context, catalog, schema, lookup_info, OnEntryNotFound::THROW_EXCEPTION); +CatalogEntry &Catalog::GetEntry(ClientContext &context, CatalogType type, const string &catalog, const string &schema, + const string &name, QueryErrorContext error_context) { + return *Catalog::GetEntry(context, type, catalog, schema, name, OnEntryNotFound::THROW_EXCEPTION, error_context); } optional_ptr Catalog::GetSchema(CatalogEntryRetriever &retriever, const string &catalog_name, - const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found) { - auto entries = GetCatalogEntries(retriever, catalog_name, schema_lookup.GetEntryName()); + const string &schema_name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { + auto entries = GetCatalogEntries(retriever, catalog_name, schema_name); for (idx_t i = 0; i < entries.size(); i++) { auto catalog = Catalog::GetCatalogEntry(retriever, entries[i].catalog); if (!catalog) { @@ -1055,23 +986,23 @@ optional_ptr Catalog::GetSchema(CatalogEntryRetriever &retri continue; } const auto on_not_found = i + 1 == entries.size() ? if_not_found : OnEntryNotFound::RETURN_NULL; - auto result = catalog->GetSchema(retriever.GetContext(), schema_lookup, on_not_found); + auto result = catalog->GetSchema(retriever.GetContext(), schema_name, on_not_found, error_context); if (result) { return result; } } // Catalog has not been found. if (if_not_found == OnEntryNotFound::THROW_EXCEPTION) { - throw CatalogException(schema_lookup.GetErrorContext(), "Catalog with name %s does not exist!", catalog_name); + throw CatalogException(error_context, "Catalog with name %s does not exist!", catalog_name); } return nullptr; } optional_ptr Catalog::GetSchema(ClientContext &context, const string &catalog_name, - const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found) { + const string &schema_name, OnEntryNotFound if_not_found, + QueryErrorContext error_context) { CatalogEntryRetriever retriever(context); - return GetSchema(retriever, catalog_name, schema_lookup, if_not_found); + return GetSchema(retriever, catalog_name, schema_name, if_not_found, error_context); } vector> Catalog::GetSchemas(ClientContext &context) { @@ -1140,8 +1071,7 @@ vector> Catalog::GetAllSchemas(ClientContext &cont void Catalog::Alter(CatalogTransaction transaction, AlterInfo &info) { if (transaction.HasContext()) { CatalogEntryRetriever retriever(transaction.GetContext()); - EntryLookupInfo lookup_info(info.GetCatalogType(), info.name); - auto lookup = LookupEntry(retriever, info.schema, lookup_info, info.if_not_found); + auto lookup = LookupEntry(retriever, info.GetCatalogType(), info.schema, info.name, info.if_not_found); if (!lookup.Found()) { return; } @@ -1197,8 +1127,4 @@ bool Catalog::IsTemporaryCatalog() const { return db.IsTemporary(); } -void Catalog::Initialize(optional_ptr context, bool load_builtin) { - Initialize(load_builtin); -} - } // namespace duckdb diff --git a/src/duckdb/src/catalog/catalog_entry.cpp b/src/duckdb/src/catalog/catalog_entry.cpp index 7fdc0c3be..d6a96d6ec 100644 --- a/src/duckdb/src/catalog/catalog_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry.cpp @@ -112,9 +112,6 @@ void CatalogEntry::Verify(Catalog &catalog_p) { void CatalogEntry::Rollback(CatalogEntry &prev_entry) { } -void CatalogEntry::OnDrop() { -} - InCatalogEntry::InCatalogEntry(CatalogType type, Catalog &catalog, string name) : CatalogEntry(type, catalog, std::move(name)), catalog(catalog) { } diff --git a/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp b/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp index dd8a91305..9f07d4acf 100644 --- a/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp @@ -67,6 +67,19 @@ static void FindForeignKeyInformation(TableCatalogEntry &table, AlterForeignKeyT } } +static void LazyLoadIndexes(ClientContext &context, CatalogEntry &entry) { + if (entry.type == CatalogType::TABLE_ENTRY) { + auto &table_entry = entry.Cast(); + table_entry.GetStorage().InitializeIndexes(context); + } else if (entry.type == CatalogType::INDEX_ENTRY) { + auto &index_entry = entry.Cast(); + auto &table_entry = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, index_entry.catalog.GetName(), + index_entry.GetSchemaName(), index_entry.GetTableName()) + .Cast(); + table_entry.GetStorage().InitializeIndexes(context); + } +} + DuckSchemaEntry::DuckSchemaEntry(Catalog &catalog, CreateSchemaInfo &info) : SchemaCatalogEntry(catalog, info), tables(catalog, make_uniq(catalog, *this)), indexes(catalog), table_functions(catalog, make_uniq(catalog, *this)), @@ -316,6 +329,9 @@ void DuckSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) { CatalogTypeToString(existing_entry->type), CatalogTypeToString(info.type)); } + // if this is a index or table with indexes, initialize any unknown index instances + LazyLoadIndexes(context, *existing_entry); + vector> fk_arrays; if (existing_entry->type == CatalogType::TABLE_ENTRY) { // if there is a foreign key constraint, get that information @@ -348,19 +364,19 @@ void DuckSchemaEntry::OnDropEntry(CatalogTransaction transaction, CatalogEntry & local_storage.DropTable(table_entry.GetStorage()); } -optional_ptr DuckSchemaEntry::LookupEntry(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info) { - return GetCatalogSet(lookup_info.GetCatalogType()).GetEntry(transaction, lookup_info.GetEntryName()); +optional_ptr DuckSchemaEntry::GetEntry(CatalogTransaction transaction, CatalogType type, + const string &name) { + return GetCatalogSet(type).GetEntry(transaction, name); } -CatalogSet::EntryLookup DuckSchemaEntry::LookupEntryDetailed(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info) { - return GetCatalogSet(lookup_info.GetCatalogType()).GetEntryDetailed(transaction, lookup_info.GetEntryName()); +CatalogSet::EntryLookup DuckSchemaEntry::GetEntryDetailed(CatalogTransaction transaction, CatalogType type, + const string &name) { + return GetCatalogSet(type).GetEntryDetailed(transaction, name); } -SimilarCatalogEntry DuckSchemaEntry::GetSimilarEntry(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info) { - return GetCatalogSet(lookup_info.GetCatalogType()).SimilarEntry(transaction, lookup_info.GetEntryName()); +SimilarCatalogEntry DuckSchemaEntry::GetSimilarEntry(CatalogTransaction transaction, CatalogType type, + const string &name) { + return GetCatalogSet(type).SimilarEntry(transaction, name); } CatalogSet &DuckSchemaEntry::GetCatalogSet(CatalogType type) { diff --git a/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp b/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp index da78ac471..3c8fcb75d 100644 --- a/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp @@ -20,7 +20,6 @@ #include "duckdb/planner/operator/logical_projection.hpp" #include "duckdb/planner/operator/logical_update.hpp" #include "duckdb/planner/parsed_data/bound_create_table_info.hpp" -#include "duckdb/parser/expression/function_expression.hpp" #include "duckdb/storage/storage_manager.hpp" #include "duckdb/storage/table_storage_info.hpp" @@ -181,10 +180,6 @@ unique_ptr DuckTableEntry::AlterEntry(ClientContext &context, Alte auto &rename_info = table_info.Cast(); return RenameColumn(context, rename_info); } - case AlterTableType::RENAME_FIELD: { - auto &rename_info = table_info.Cast(); - return RenameField(context, rename_info); - } case AlterTableType::RENAME_TABLE: { auto &rename_info = table_info.Cast(); auto copied_table = Copy(context); @@ -196,18 +191,10 @@ unique_ptr DuckTableEntry::AlterEntry(ClientContext &context, Alte auto &add_info = table_info.Cast(); return AddColumn(context, add_info); } - case AlterTableType::ADD_FIELD: { - auto &add_info = table_info.Cast(); - return AddField(context, add_info); - } case AlterTableType::REMOVE_COLUMN: { auto &remove_info = table_info.Cast(); return RemoveColumn(context, remove_info); } - case AlterTableType::REMOVE_FIELD: { - auto &remove_info = table_info.Cast(); - return RemoveField(context, remove_info); - } case AlterTableType::SET_DEFAULT: { auto &set_default_info = table_info.Cast(); return SetDefault(context, set_default_info); @@ -236,10 +223,6 @@ unique_ptr DuckTableEntry::AlterEntry(ClientContext &context, Alte auto &add_constraint_info = table_info.Cast(); return AddConstraint(context, add_constraint_info); } - case AlterTableType::SET_PARTITIONED_BY: - throw NotImplementedException("SET PARTITIONED BY is not supported for DuckDB tables"); - case AlterTableType::SET_SORTED_BY: - throw NotImplementedException("SET SORTED BY is not supported for DuckDB tables"); default: throw InternalException("Unrecognized alter table type!"); } @@ -374,119 +357,6 @@ unique_ptr DuckTableEntry::AddColumn(ClientContext &context, AddCo return make_uniq(catalog, schema, *bound_create_info, new_storage); } -struct StructMappingInfo { - LogicalType new_type; - unique_ptr default_value; - ErrorData error; -}; - -unique_ptr PackExpression(unique_ptr expr, string name) { - expr->SetAlias(std::move(name)); - vector> children; - children.push_back(std::move(expr)); - auto res = make_uniq("struct_pack", std::move(children)); - return std::move(res); -} - -Value ConstructMapping(const string &name, const LogicalType &type) { - if (type.id() != LogicalTypeId::STRUCT) { - return Value(name); - } - child_list_t child_mapping; - auto &child_types = StructType::GetChildTypes(type); - for (auto &entry : child_types) { - auto mapping_value = ConstructMapping(entry.first, entry.second); - if (entry.second.id() == LogicalTypeId::STRUCT) { - child_list_t child_values; - child_values.emplace_back(string(), Value(entry.first)); - child_values.emplace_back(string(), std::move(mapping_value)); - mapping_value = Value::STRUCT(std::move(child_values)); - } - child_mapping.emplace_back(entry.first, std::move(mapping_value)); - } - return Value::STRUCT(std::move(child_mapping)); -} - -StructMappingInfo AddFieldToStruct(const LogicalType &type, const vector &column_path, - const ColumnDefinition &new_field, idx_t depth = 0) { - if (type.id() != LogicalTypeId::STRUCT) { - throw BinderException("Column %s is not a struct - ALTER TABLE can only add fields to structs", - column_path[depth]); - } - StructMappingInfo result; - auto child_list = StructType::GetChildTypes(type); - if (column_path.size() == depth + 1) { - // root path - we are adding at this level - // check if a field with this name already exists - for (auto &entry : child_list) { - if (StringUtil::CIEquals(entry.first, new_field.Name())) { - // already exists! - result.error = ErrorData(CatalogException("Duplicate field \"%s\" - field already exists in struct %s", - new_field.Name(), column_path.back())); - return result; - } - } - // add the new type - child_list.emplace_back(new_field.Name(), new_field.Type()); - result.new_type = LogicalType::STRUCT(std::move(child_list)); - // set the default value - unique_ptr default_value; - if (new_field.HasDefaultValue()) { - default_value = new_field.DefaultValue().Copy(); - } else { - default_value = make_uniq(Value(new_field.Type())); - } - result.default_value = PackExpression(std::move(default_value), new_field.Name()); - return result; - } - // not the root path - we need to recurse - auto &next_component = column_path[depth + 1]; - bool found = false; - for (auto &entry : child_list) { - if (StringUtil::CIEquals(entry.first, next_component)) { - // found the entry - recurse - auto child_res = AddFieldToStruct(entry.second, column_path, new_field, depth + 1); - if (child_res.error.HasError()) { - return child_res; - } - entry.second = std::move(child_res.new_type); - result.default_value = PackExpression(std::move(child_res.default_value), entry.first); - found = true; - break; - } - } - result.new_type = LogicalType::STRUCT(std::move(child_list)); - if (!found) { - throw BinderException("Sub-field %s does not exist in column %s", next_component, column_path[depth]); - } - return result; -} - -unique_ptr DuckTableEntry::AddField(ClientContext &context, AddFieldInfo &info) { - // follow the path - auto &col = GetColumn(info.column_path[0]); - auto res = AddFieldToStruct(col.Type(), info.column_path, info.new_field); - if (res.error.HasError()) { - if (!info.if_field_not_exists) { - res.error.Throw(); - } - return nullptr; - } - - // construct the struct remapping expression - vector> children; - children.push_back(make_uniq(info.column_path[0])); - children.push_back(make_uniq(Value(res.new_type))); - children.push_back(make_uniq(ConstructMapping(col.Name(), col.Type()))); - children.push_back(std::move(res.default_value)); - - auto function = make_uniq("remap_struct", std::move(children)); - - ChangeColumnTypeInfo change_column_type(info.GetAlterEntryData(), info.column_path[0], std::move(res.new_type), - std::move(function)); - return ChangeColumnType(context, change_column_type); -} - void DuckTableEntry::UpdateConstraintsOnColumnDrop(const LogicalIndex &removed_index, const vector &adjusted_indices, const RemoveColumnInfo &info, CreateTableInfo &create_info, @@ -627,190 +497,6 @@ unique_ptr DuckTableEntry::RemoveColumn(ClientContext &context, Re return make_uniq(catalog, schema, *bound_create_info, new_storage); } -struct DroppedFieldMapping { - Value mapping; - LogicalType new_type; - ErrorData error; -}; - -DroppedFieldMapping DropFieldFromStruct(const LogicalType &type, const vector &column_path, idx_t depth) { - if (type.id() != LogicalTypeId::STRUCT) { - throw CatalogException("Cannot drop field from column \"%s\" - not a struct", column_path[0]); - } - auto &dropped_entry = column_path[depth]; - bool last_entry = depth + 1 == column_path.size(); - bool found = false; - DroppedFieldMapping result; - child_list_t child_mapping; - child_list_t new_type_children; - auto &child_types = StructType::GetChildTypes(type); - for (auto &entry : child_types) { - Value mapping_value; - LogicalType type_value; - if (StringUtil::CIEquals(entry.first, dropped_entry)) { - // this is the entry we are dropping - found = true; - if (last_entry) { - // we are dropping this entry in its entirety - just skip - if (child_types.size() == 1) { - throw CatalogException("Cannot drop field %s from column %s - it is the last field of the struct", - column_path.back(), column_path.front()); - } - continue; - } else { - // we are dropping a field in this entry - recurse - auto child_result = DropFieldFromStruct(entry.second, column_path, depth + 1); - if (child_result.error.HasError()) { - // bubble up error - return child_result; - } - mapping_value = std::move(child_result.mapping); - type_value = std::move(child_result.new_type); - } - } else { - // we are not adjusting this entry - copy the type and create a straightforward mapping - mapping_value = ConstructMapping(entry.first, entry.second); - type_value = entry.second; - } - if (entry.second.id() == LogicalTypeId::STRUCT) { - child_list_t child_values; - child_values.emplace_back(string(), Value(entry.first)); - child_values.emplace_back(string(), std::move(mapping_value)); - mapping_value = Value::STRUCT(std::move(child_values)); - } - child_mapping.emplace_back(entry.first, std::move(mapping_value)); - new_type_children.emplace_back(entry.first, type_value); - } - if (!found) { - result.error = ErrorData(CatalogException("Cannot drop field \"%s\" - it does not exist", dropped_entry)); - } else { - result.mapping = Value::STRUCT(std::move(child_mapping)); - result.new_type = LogicalType::STRUCT(std::move(new_type_children)); - } - return result; -} - -unique_ptr DuckTableEntry::RemoveField(ClientContext &context, RemoveFieldInfo &info) { - if (!ColumnExists(info.column_path[0])) { - if (!info.if_column_exists) { - throw CatalogException("Cannot drop field from column \"%s\" - it does not exist", info.column_path[0]); - } - return nullptr; - } - // follow the path - auto &col = GetColumn(info.column_path[0]); - auto res = DropFieldFromStruct(col.Type(), info.column_path, 1); - if (res.error.HasError()) { - if (!info.if_column_exists) { - res.error.Throw(); - } - return nullptr; - } - - // construct the struct remapping expression - vector> children; - children.push_back(make_uniq(info.column_path[0])); - children.push_back(make_uniq(Value(res.new_type))); - children.push_back(make_uniq(std::move(res.mapping))); - children.push_back(make_uniq(Value())); - - auto function = make_uniq("remap_struct", std::move(children)); - - ChangeColumnTypeInfo change_column_type(info.GetAlterEntryData(), info.column_path[0], std::move(res.new_type), - std::move(function)); - return ChangeColumnType(context, change_column_type); -} - -DroppedFieldMapping RenameFieldFromStruct(const LogicalType &type, const vector &column_path, - const string &new_name, idx_t depth) { - if (type.id() != LogicalTypeId::STRUCT) { - throw CatalogException("Cannot rename field from column \"%s\" - not a struct", column_path[0]); - } - auto &rename_entry = column_path[depth]; - bool last_entry = depth + 1 == column_path.size(); - bool found = false; - DroppedFieldMapping result; - child_list_t child_mapping; - child_list_t new_type_children; - auto &child_types = StructType::GetChildTypes(type); - for (auto &entry : child_types) { - auto field_name = entry.first; - Value mapping_value; - LogicalType type_value; - if (StringUtil::CIEquals(field_name, rename_entry)) { - // this is the entry we are dropping - found = true; - if (last_entry) { - // we are renaming this entry - for (auto &sub_entry : child_types) { - if (StringUtil::CIEquals(new_name, sub_entry.first)) { - throw CatalogException( - "Cannot rename field %s from column %s to %s - a field with this name already exists", - column_path.back(), column_path.front(), new_name); - } - } - field_name = new_name; - mapping_value = ConstructMapping(entry.first, entry.second); - type_value = entry.second; - } else { - // we are dropping a field in this entry - recurse - auto child_result = RenameFieldFromStruct(entry.second, column_path, new_name, depth + 1); - if (child_result.error.HasError()) { - // bubble up error - return child_result; - } - mapping_value = std::move(child_result.mapping); - type_value = std::move(child_result.new_type); - } - } else { - // we are not adjusting this entry - copy the type and create a straightforward mapping - mapping_value = ConstructMapping(entry.first, entry.second); - type_value = entry.second; - } - if (entry.second.id() == LogicalTypeId::STRUCT) { - child_list_t child_values; - child_values.emplace_back(string(), Value(entry.first)); - child_values.emplace_back(string(), std::move(mapping_value)); - mapping_value = Value::STRUCT(std::move(child_values)); - } - child_mapping.emplace_back(field_name, std::move(mapping_value)); - new_type_children.emplace_back(field_name, type_value); - } - if (!found) { - result.error = ErrorData(CatalogException("Cannot rename field \"%s\" - it does not exist", rename_entry)); - } else { - result.mapping = Value::STRUCT(std::move(child_mapping)); - result.new_type = LogicalType::STRUCT(std::move(new_type_children)); - } - return result; -} - -unique_ptr DuckTableEntry::RenameField(ClientContext &context, RenameFieldInfo &info) { - if (!ColumnExists(info.column_path[0])) { - throw CatalogException("Cannot rename field from column \"%s\" - it does not exist", info.column_path[0]); - } - // follow the path - auto &col = GetColumn(info.column_path[0]); - auto res = RenameFieldFromStruct(col.Type(), info.column_path, info.new_name, 1); - if (res.error.HasError()) { - res.error.Throw(); - return nullptr; - } - - // construct the struct remapping expression - vector> children; - children.push_back(make_uniq(info.column_path[0])); - children.push_back(make_uniq(Value(res.new_type))); - children.push_back(make_uniq(std::move(res.mapping))); - children.push_back(make_uniq(Value())); - - auto function = make_uniq("remap_struct", std::move(children)); - - ChangeColumnTypeInfo change_column_type(info.GetAlterEntryData(), info.column_path[0], std::move(res.new_type), - std::move(function)); - return ChangeColumnType(context, change_column_type); -} - unique_ptr DuckTableEntry::SetDefault(ClientContext &context, SetDefaultInfo &info) { auto create_info = make_uniq(schema, name); create_info->comment = comment; @@ -1131,10 +817,6 @@ void DuckTableEntry::Rollback(CatalogEntry &prev_entry) { } } -void DuckTableEntry::OnDrop() { - storage->SetAsDropped(); -} - unique_ptr DuckTableEntry::AddConstraint(ClientContext &context, AddConstraintInfo &info) { auto create_info = make_uniq(schema, name); create_info->comment = comment; @@ -1186,7 +868,7 @@ unique_ptr DuckTableEntry::Copy(ClientContext &context) const { } void DuckTableEntry::SetAsRoot() { - storage->SetAsMainTable(); + storage->SetAsRoot(); storage->SetTableName(name); } @@ -1203,10 +885,7 @@ void DuckTableEntry::CommitAlter(string &column_name) { break; } } - - auto logical_column_index = LogicalIndex(removed_index.GetIndex()); - auto column_index = columns.LogicalToPhysical(logical_column_index).index; - storage->CommitDropColumn(column_index); + storage->CommitDropColumn(columns.LogicalToPhysical(LogicalIndex(removed_index.GetIndex())).index); } void DuckTableEntry::CommitDrop() { diff --git a/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp b/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp index 5cf75cf4b..ef14221ff 100644 --- a/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp @@ -27,11 +27,11 @@ optional_ptr SchemaCatalogEntry::CreateIndex(ClientContext &contex return CreateIndex(GetCatalogTransaction(context), info, table); } -SimilarCatalogEntry SchemaCatalogEntry::GetSimilarEntry(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info) { +SimilarCatalogEntry SchemaCatalogEntry::GetSimilarEntry(CatalogTransaction transaction, CatalogType type, + const string &name) { SimilarCatalogEntry result; - Scan(transaction.GetContext(), lookup_info.GetCatalogType(), [&](CatalogEntry &entry) { - auto entry_score = StringUtil::SimilarityRating(entry.name, lookup_info.GetEntryName()); + Scan(transaction.GetContext(), type, [&](CatalogEntry &entry) { + auto entry_score = StringUtil::SimilarityRating(entry.name, name); if (entry_score > result.score) { result.score = entry_score; result.name = entry.name; @@ -40,18 +40,12 @@ SimilarCatalogEntry SchemaCatalogEntry::GetSimilarEntry(CatalogTransaction trans return result; } -optional_ptr SchemaCatalogEntry::GetEntry(CatalogTransaction transaction, CatalogType type, - const string &name) { - EntryLookupInfo lookup_info(type, name); - return LookupEntry(transaction, lookup_info); -} - //! This should not be used, it's only implemented to not put the burden of implementing it on every derived class of //! SchemaCatalogEntry -CatalogSet::EntryLookup SchemaCatalogEntry::LookupEntryDetailed(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info) { +CatalogSet::EntryLookup SchemaCatalogEntry::GetEntryDetailed(CatalogTransaction transaction, CatalogType type, + const string &name) { CatalogSet::EntryLookup result; - result.result = LookupEntry(transaction, lookup_info); + result.result = GetEntry(transaction, type, name); if (!result.result) { result.reason = CatalogSet::EntryLookup::FailureReason::DELETED; } else { diff --git a/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp b/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp index 67819fa34..3070b2e30 100644 --- a/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp @@ -203,11 +203,6 @@ string TableCatalogEntry::ToSQL() const { return create_info->ToString(); } -TableFunction TableCatalogEntry::GetScanFunction(ClientContext &context, unique_ptr &bind_data, - const EntryLookupInfo &lookup_info) { - return GetScanFunction(context, bind_data); -} - const ColumnList &TableCatalogEntry::GetColumns() const { return columns; } @@ -337,16 +332,4 @@ bool TableCatalogEntry::HasPrimaryKey() const { return GetPrimaryKey() != nullptr; } -virtual_column_map_t TableCatalogEntry::GetVirtualColumns() const { - virtual_column_map_t virtual_columns; - virtual_columns.insert(make_pair(COLUMN_IDENTIFIER_ROW_ID, TableColumn("rowid", LogicalType::ROW_TYPE))); - return virtual_columns; -} - -vector TableCatalogEntry::GetRowIdColumns() const { - vector result; - result.push_back(COLUMN_IDENTIFIER_ROW_ID); - return result; -} - } // namespace duckdb diff --git a/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp b/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp index a02de0cec..9f029f214 100644 --- a/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +++ b/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp @@ -36,7 +36,7 @@ unique_ptr ViewCatalogEntry::GetInfo() const { result->schema = schema.name; result->view_name = name; result->sql = sql; - result->query = query ? unique_ptr_cast(query->Copy()) : nullptr; + result->query = unique_ptr_cast(query->Copy()); result->aliases = aliases; result->names = names; result->types = types; @@ -100,10 +100,6 @@ string ViewCatalogEntry::ToSQL() const { return result; } -const SelectStatement &ViewCatalogEntry::GetQuery() { - return *query; -} - unique_ptr ViewCatalogEntry::Copy(ClientContext &context) const { D_ASSERT(!internal); auto create_info = GetInfo(); diff --git a/src/duckdb/src/catalog/catalog_entry_retriever.cpp b/src/duckdb/src/catalog/catalog_entry_retriever.cpp index ece24b1e0..eb283de5b 100644 --- a/src/duckdb/src/catalog/catalog_entry_retriever.cpp +++ b/src/duckdb/src/catalog/catalog_entry_retriever.cpp @@ -13,8 +13,8 @@ namespace duckdb { LogicalType CatalogEntryRetriever::GetType(Catalog &catalog, const string &schema, const string &name, OnEntryNotFound on_entry_not_found) { - EntryLookupInfo lookup_info(CatalogType::TYPE_ENTRY, name); - auto result = GetEntry(catalog, schema, lookup_info, on_entry_not_found); + QueryErrorContext error_context; + auto result = GetEntry(CatalogType::TYPE_ENTRY, catalog, schema, name, on_entry_not_found, error_context); if (!result) { return LogicalType::INVALID; } @@ -24,8 +24,8 @@ LogicalType CatalogEntryRetriever::GetType(Catalog &catalog, const string &schem LogicalType CatalogEntryRetriever::GetType(const string &catalog, const string &schema, const string &name, OnEntryNotFound on_entry_not_found) { - EntryLookupInfo lookup_info(CatalogType::TYPE_ENTRY, name); - auto result = GetEntry(catalog, schema, lookup_info, on_entry_not_found); + QueryErrorContext error_context; + auto result = GetEntry(CatalogType::TYPE_ENTRY, catalog, schema, name, on_entry_not_found, error_context); if (!result) { return LogicalType::INVALID; } @@ -33,17 +33,17 @@ LogicalType CatalogEntryRetriever::GetType(const string &catalog, const string & return type_entry.user_type; } -optional_ptr CatalogEntryRetriever::GetEntry(const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info, - OnEntryNotFound on_entry_not_found) { - return ReturnAndCallback(Catalog::GetEntry(*this, catalog, schema, lookup_info, on_entry_not_found)); +optional_ptr CatalogEntryRetriever::GetEntry(CatalogType type, const string &catalog, + const string &schema, const string &name, + OnEntryNotFound on_entry_not_found, + QueryErrorContext error_context) { + return ReturnAndCallback(Catalog::GetEntry(*this, type, catalog, schema, name, on_entry_not_found, error_context)); } -optional_ptr CatalogEntryRetriever::GetSchema(const string &catalog, - const EntryLookupInfo &schema_lookup_p, - OnEntryNotFound on_entry_not_found) { - EntryLookupInfo schema_lookup(schema_lookup_p, at_clause); - auto result = Catalog::GetSchema(*this, catalog, schema_lookup, on_entry_not_found); +optional_ptr CatalogEntryRetriever::GetSchema(const string &catalog, const string &name, + OnEntryNotFound on_entry_not_found, + QueryErrorContext error_context) { + auto result = Catalog::GetSchema(*this, catalog, name, on_entry_not_found, error_context); if (!result) { return result; } @@ -54,10 +54,10 @@ optional_ptr CatalogEntryRetriever::GetSchema(const string & return result; } -optional_ptr CatalogEntryRetriever::GetEntry(Catalog &catalog, const string &schema, - const EntryLookupInfo &lookup_info, - OnEntryNotFound on_entry_not_found) { - return ReturnAndCallback(catalog.GetEntry(*this, schema, lookup_info, on_entry_not_found)); +optional_ptr CatalogEntryRetriever::GetEntry(CatalogType type, Catalog &catalog, const string &schema, + const string &name, OnEntryNotFound on_entry_not_found, + QueryErrorContext error_context) { + return ReturnAndCallback(catalog.GetEntry(*this, type, schema, name, on_entry_not_found, error_context)); } optional_ptr CatalogEntryRetriever::ReturnAndCallback(optional_ptr result) { @@ -74,7 +74,6 @@ optional_ptr CatalogEntryRetriever::ReturnAndCallback(optional_ptr void CatalogEntryRetriever::Inherit(const CatalogEntryRetriever &parent) { this->callback = parent.callback; this->search_path = parent.search_path; - this->at_clause = parent.at_clause; } const CatalogSearchPath &CatalogEntryRetriever::GetSearchPath() const { @@ -109,14 +108,6 @@ void CatalogEntryRetriever::SetSearchPath(vector entries) { this->search_path = make_shared_ptr(context, std::move(new_path)); } -optional_ptr CatalogEntryRetriever::GetAtClause() const { - return at_clause; -} - -void CatalogEntryRetriever::SetAtClause(optional_ptr at_clause_p) { - at_clause = at_clause_p; -} - void CatalogEntryRetriever::SetCallback(catalog_entry_callback_t callback) { this->callback = std::move(callback); } diff --git a/src/duckdb/src/catalog/catalog_set.cpp b/src/duckdb/src/catalog/catalog_set.cpp index f9e20758a..dc2cf1035 100644 --- a/src/duckdb/src/catalog/catalog_set.cpp +++ b/src/duckdb/src/catalog/catalog_set.cpp @@ -400,8 +400,6 @@ bool CatalogSet::DropEntryInternal(CatalogTransaction transaction, const string throw CatalogException("Cannot drop entry \"%s\" because it is an internal system entry", entry->name); } - entry->OnDrop(); - // create a new tombstone entry and replace the currently stored one // set the timestamp to the timestamp of the current transaction // and point it at the tombstone node diff --git a/src/duckdb/src/catalog/default/default_views.cpp b/src/duckdb/src/catalog/default/default_views.cpp index 74536ee2d..4d57938cf 100644 --- a/src/duckdb/src/catalog/default/default_views.cpp +++ b/src/duckdb/src/catalog/default/default_views.cpp @@ -28,7 +28,6 @@ static const DefaultView internal_views[] = { {DEFAULT_SCHEMA, "duckdb_views", "SELECT * FROM duckdb_views() WHERE NOT internal"}, {DEFAULT_SCHEMA, "duckdb_logs", "SELECT * exclude (l.context_id, c.context_id) FROM duckdb_logs() as l JOIN duckdb_log_contexts() as c ON l.context_id=c.context_id order by timestamp;"}, {"pg_catalog", "pg_am", "SELECT 0 oid, 'art' amname, NULL amhandler, 'i' amtype"}, - {"pg_catalog", "pg_prepared_statements", "SELECT name, statement, NULL prepare_time, parameter_types, result_types, NULL from_sql, NULL generic_plans, NULL custom_plans from duckdb_prepared_statements()"}, {"pg_catalog", "pg_attribute", "SELECT table_oid attrelid, column_name attname, data_type_id atttypid, 0 attstattarget, NULL attlen, column_index attnum, 0 attndims, -1 attcacheoff, case when data_type ilike '%decimal%' then numeric_precision*1000+numeric_scale else -1 end atttypmod, false attbyval, NULL attstorage, NULL attalign, NOT is_nullable attnotnull, column_default IS NOT NULL atthasdef, false atthasmissing, '' attidentity, '' attgenerated, false attisdropped, true attislocal, 0 attinhcount, 0 attcollation, NULL attcompression, NULL attacl, NULL attoptions, NULL attfdwoptions, NULL attmissingval FROM duckdb_columns()"}, {"pg_catalog", "pg_attrdef", "SELECT column_index oid, table_oid adrelid, column_index adnum, column_default adbin from duckdb_columns() where column_default is not null;"}, {"pg_catalog", "pg_class", "SELECT table_oid oid, table_name relname, schema_oid relnamespace, 0 reltype, 0 reloftype, 0 relowner, 0 relam, 0 relfilenode, 0 reltablespace, 0 relpages, estimated_size::real reltuples, 0 relallvisible, 0 reltoastrelid, 0 reltoastidxid, index_count > 0 relhasindex, false relisshared, case when temporary then 't' else 'p' end relpersistence, 'r' relkind, column_count relnatts, check_constraint_count relchecks, false relhasoids, has_primary_key relhaspkey, false relhasrules, false relhastriggers, false relhassubclass, false relrowsecurity, true relispopulated, NULL relreplident, false relispartition, 0 relrewrite, 0 relfrozenxid, NULL relminmxid, NULL relacl, NULL reloptions, NULL relpartbound FROM duckdb_tables() UNION ALL SELECT view_oid oid, view_name relname, schema_oid relnamespace, 0 reltype, 0 reloftype, 0 relowner, 0 relam, 0 relfilenode, 0 reltablespace, 0 relpages, 0 reltuples, 0 relallvisible, 0 reltoastrelid, 0 reltoastidxid, false relhasindex, false relisshared, case when temporary then 't' else 'p' end relpersistence, 'v' relkind, column_count relnatts, 0 relchecks, false relhasoids, false relhaspkey, false relhasrules, false relhastriggers, false relhassubclass, false relrowsecurity, true relispopulated, NULL relreplident, false relispartition, 0 relrewrite, 0 relfrozenxid, NULL relminmxid, NULL relacl, NULL reloptions, NULL relpartbound FROM duckdb_views() UNION ALL SELECT sequence_oid oid, sequence_name relname, schema_oid relnamespace, 0 reltype, 0 reloftype, 0 relowner, 0 relam, 0 relfilenode, 0 reltablespace, 0 relpages, 0 reltuples, 0 relallvisible, 0 reltoastrelid, 0 reltoastidxid, false relhasindex, false relisshared, case when temporary then 't' else 'p' end relpersistence, 'S' relkind, 0 relnatts, 0 relchecks, false relhasoids, false relhaspkey, false relhasrules, false relhastriggers, false relhassubclass, false relrowsecurity, true relispopulated, NULL relreplident, false relispartition, 0 relrewrite, 0 relfrozenxid, NULL relminmxid, NULL relacl, NULL reloptions, NULL relpartbound FROM duckdb_sequences() UNION ALL SELECT index_oid oid, index_name relname, schema_oid relnamespace, 0 reltype, 0 reloftype, 0 relowner, 0 relam, 0 relfilenode, 0 reltablespace, 0 relpages, 0 reltuples, 0 relallvisible, 0 reltoastrelid, 0 reltoastidxid, false relhasindex, false relisshared, 't' relpersistence, 'i' relkind, NULL relnatts, 0 relchecks, false relhasoids, false relhaspkey, false relhasrules, false relhastriggers, false relhassubclass, false relrowsecurity, true relispopulated, NULL relreplident, false relispartition, 0 relrewrite, 0 relfrozenxid, NULL relminmxid, NULL relacl, NULL reloptions, NULL relpartbound FROM duckdb_indexes()"}, @@ -39,7 +38,7 @@ static const DefaultView internal_views[] = { {"pg_catalog", "pg_enum", "SELECT NULL oid, a.type_oid enumtypid, list_position(b.labels, a.elabel) enumsortorder, a.elabel enumlabel FROM (SELECT UNNEST(labels) elabel, type_oid FROM duckdb_types() WHERE logical_type='ENUM') a JOIN duckdb_types() b ON a.type_oid=b.type_oid;"}, {"pg_catalog", "pg_index", "SELECT index_oid indexrelid, table_oid indrelid, 0 indnatts, 0 indnkeyatts, is_unique indisunique, is_primary indisprimary, false indisexclusion, true indimmediate, false indisclustered, true indisvalid, false indcheckxmin, true indisready, true indislive, false indisreplident, NULL::INT[] indkey, NULL::OID[] indcollation, NULL::OID[] indclass, NULL::INT[] indoption, expressions indexprs, NULL indpred FROM duckdb_indexes()"}, {"pg_catalog", "pg_indexes", "SELECT schema_name schemaname, table_name tablename, index_name indexname, NULL \"tablespace\", sql indexdef FROM duckdb_indexes()"}, - {"pg_catalog", "pg_namespace", "SELECT oid, schema_name nspname, 0 nspowner, NULL nspacl FROM duckdb_schemas() where database_name=current_database()"}, + {"pg_catalog", "pg_namespace", "SELECT oid, schema_name nspname, 0 nspowner, NULL nspacl FROM duckdb_schemas()"}, {"pg_catalog", "pg_proc", "SELECT f.function_oid oid, function_name proname, s.oid pronamespace, NULL proowner, NULL prolang, 0 procost, 0 prorows, varargs provariadic, 0 prosupport, CASE function_type WHEN 'aggregate' THEN 'a' ELSE 'f' END prokind, false prosecdef, false proleakproof, false proisstrict, function_type = 'table' proretset, case (stability) when 'CONSISTENT' then 'i' when 'CONSISTENT_WITHIN_QUERY' then 's' when 'VOLATILE' then 'v' end provolatile, 'u' proparallel, length(parameters) pronargs, 0 pronargdefaults, return_type prorettype, parameter_types proargtypes, NULL proallargtypes, NULL proargmodes, parameters proargnames, NULL proargdefaults, NULL protrftypes, NULL prosrc, NULL probin, macro_definition prosqlbody, NULL proconfig, NULL proacl, function_type = 'aggregate' proisagg, FROM duckdb_functions() f LEFT JOIN duckdb_schemas() s USING (database_name, schema_name)"}, {"pg_catalog", "pg_sequence", "SELECT sequence_oid seqrelid, 0 seqtypid, start_value seqstart, increment_by seqincrement, max_value seqmax, min_value seqmin, 0 seqcache, cycle seqcycle FROM duckdb_sequences()"}, {"pg_catalog", "pg_sequences", "SELECT schema_name schemaname, sequence_name sequencename, 'duckdb' sequenceowner, 0 data_type, start_value, min_value, max_value, increment_by, cycle, 0 cache_size, last_value FROM duckdb_sequences()"}, diff --git a/src/duckdb/src/catalog/dependency_manager.cpp b/src/duckdb/src/catalog/dependency_manager.cpp index ddd7550a7..4fcb4d4d1 100644 --- a/src/duckdb/src/catalog/dependency_manager.cpp +++ b/src/duckdb/src/catalog/dependency_manager.cpp @@ -455,8 +455,7 @@ void DependencyManager::VerifyExistence(CatalogTransaction transaction, Dependen if (type != CatalogType::SCHEMA_ENTRY && lookup_result.result) { auto &schema_entry = lookup_result.result->Cast(); - EntryLookupInfo lookup_info(type, name); - lookup_result = schema_entry.LookupEntryDetailed(transaction, lookup_info); + lookup_result = schema_entry.GetEntryDetailed(transaction, type, name); } if (lookup_result.reason == CatalogSet::EntryLookup::FailureReason::DELETED) { diff --git a/src/duckdb/src/catalog/duck_catalog.cpp b/src/duckdb/src/catalog/duck_catalog.cpp index 558a0fec9..a55349a74 100644 --- a/src/duckdb/src/catalog/duck_catalog.cpp +++ b/src/duckdb/src/catalog/duck_catalog.cpp @@ -123,15 +123,13 @@ CatalogSet &DuckCatalog::GetSchemaCatalogSet() { return *schemas; } -optional_ptr DuckCatalog::LookupSchema(CatalogTransaction transaction, - const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found) { - auto &schema_name = schema_lookup.GetEntryName(); +optional_ptr DuckCatalog::GetSchema(CatalogTransaction transaction, const string &schema_name, + OnEntryNotFound if_not_found, QueryErrorContext error_context) { D_ASSERT(!schema_name.empty()); auto entry = schemas->GetEntry(transaction, schema_name); if (!entry) { if (if_not_found == OnEntryNotFound::THROW_EXCEPTION) { - throw CatalogException(schema_lookup.GetErrorContext(), "Schema with name %s does not exist!", schema_name); + throw CatalogException(error_context, "Schema with name %s does not exist!", schema_name); } return nullptr; } diff --git a/src/duckdb/src/common/adbc/adbc.cpp b/src/duckdb/src/common/adbc/adbc.cpp index e9dd12f76..675326c08 100644 --- a/src/duckdb/src/common/adbc/adbc.cpp +++ b/src/duckdb/src/common/adbc/adbc.cpp @@ -229,10 +229,10 @@ AdbcStatusCode ConnectionGetTableSchema(struct AdbcConnection *connection, const std::string query = "SELECT * FROM "; if (catalog != nullptr && strlen(catalog) > 0) { - query += duckdb::KeywordHelper::WriteOptionallyQuoted(catalog) + "."; + query += std::string(catalog) + "."; } - query += duckdb::KeywordHelper::WriteOptionallyQuoted(db_schema) + "."; - query += duckdb::KeywordHelper::WriteOptionallyQuoted(table_name) + " LIMIT 0;"; + query += std::string(db_schema) + "."; + query += std::string(table_name) + " LIMIT 0;"; auto success = QueryInternal(connection, &arrow_stream, query.c_str(), error); if (success != ADBC_STATUS_OK) { @@ -622,12 +622,13 @@ AdbcStatusCode Ingest(duckdb_connection connection, const char *table_name, cons break; case IngestionMode::APPEND: { arrow_scan->CreateView("temp_adbc_view", true, true); - std::string query = "insert into "; + std::string query; if (schema) { - query += duckdb::KeywordHelper::WriteOptionallyQuoted(schema) + "."; + query = duckdb::StringUtil::Format("insert into \"%s.%s\" select * from temp_adbc_view", schema, + table_name); + } else { + query = duckdb::StringUtil::Format("insert into \"%s\" select * from temp_adbc_view", table_name); } - query += duckdb::KeywordHelper::WriteOptionallyQuoted(table_name); - query += " select * from temp_adbc_view"; auto result = cconn->Query(query); break; } @@ -909,46 +910,8 @@ AdbcStatusCode StatementSetSqlQuery(struct AdbcStatement *statement, const char duckdb_destroy_prepare(&wrapper->statement); wrapper->statement = nullptr; } - duckdb_extracted_statements extracted_statements = nullptr; - auto extract_statements_size = duckdb_extract_statements(wrapper->connection, query, &extracted_statements); - auto error_msg_extract_statements = duckdb_extract_statements_error(extracted_statements); - if (error_msg_extract_statements != nullptr) { - // Things went wrong when executing internal prepared statement - duckdb_destroy_extracted(&extracted_statements); - SetError(error, error_msg_extract_statements); - return ADBC_STATUS_INTERNAL; - } - // Now lets loop over the statements, and execute every one - for (idx_t i = 0; i < extract_statements_size - 1; i++) { - duckdb_prepared_statement statement_internal = nullptr; - auto res = - duckdb_prepare_extracted_statement(wrapper->connection, extracted_statements, i, &statement_internal); - auto error_msg = duckdb_prepare_error(statement_internal); - auto adbc_status = CheckResult(res, error, error_msg); - if (adbc_status != ADBC_STATUS_OK) { - duckdb_destroy_prepare(&statement_internal); - duckdb_destroy_extracted(&extracted_statements); - return adbc_status; - } - // Execute - duckdb_arrow out_result; - res = duckdb_execute_prepared_arrow(statement_internal, &out_result); - if (res != DuckDBSuccess) { - SetError(error, duckdb_query_arrow_error(out_result)); - duckdb_destroy_arrow(&out_result); - duckdb_destroy_prepare(&statement_internal); - duckdb_destroy_extracted(&extracted_statements); - return ADBC_STATUS_INVALID_ARGUMENT; - } - duckdb_destroy_arrow(&out_result); - duckdb_destroy_prepare(&statement_internal); - } - - // Final statement (returned to caller) - auto res = duckdb_prepare_extracted_statement(wrapper->connection, extracted_statements, - extract_statements_size - 1, &wrapper->statement); + auto res = duckdb_prepare(wrapper->connection, query, &wrapper->statement); auto error_msg = duckdb_prepare_error(wrapper->statement); - duckdb_destroy_extracted(&extracted_statements); return CheckResult(res, error, error_msg); } diff --git a/src/duckdb/src/common/arrow/physical_arrow_collector.cpp b/src/duckdb/src/common/arrow/physical_arrow_collector.cpp index 7cfbf595b..50a663b0b 100644 --- a/src/duckdb/src/common/arrow/physical_arrow_collector.cpp +++ b/src/duckdb/src/common/arrow/physical_arrow_collector.cpp @@ -10,10 +10,10 @@ namespace duckdb { unique_ptr PhysicalArrowCollector::Create(ClientContext &context, PreparedStatementData &data, idx_t batch_size) { - if (!PhysicalPlanGenerator::PreserveInsertionOrder(context, data.physical_plan->Root())) { + if (!PhysicalPlanGenerator::PreserveInsertionOrder(context, *data.plan)) { // the plan is not order preserving, so we just use the parallel materialized collector return make_uniq_base(data, true, batch_size); - } else if (!PhysicalPlanGenerator::UseBatchIndex(context, data.physical_plan->Root())) { + } else if (!PhysicalPlanGenerator::UseBatchIndex(context, *data.plan)) { // the plan is order preserving, but we cannot use the batch index: use a single-threaded result collector return make_uniq_base(data, false, batch_size); } else { diff --git a/src/duckdb/src/common/arrow/schema_metadata.cpp b/src/duckdb/src/common/arrow/schema_metadata.cpp index 9024f3ac8..f78f2ebfb 100644 --- a/src/duckdb/src/common/arrow/schema_metadata.cpp +++ b/src/duckdb/src/common/arrow/schema_metadata.cpp @@ -31,15 +31,7 @@ ArrowSchemaMetadata::ArrowSchemaMetadata(const char *metadata) { schema_metadata_map[key] = value; } } - // We ignore errors of the metadata parsing if the extension is different from arrow.opaque - const bool ignore_errors = - schema_metadata_map[ARROW_EXTENSION_NAME] != ArrowExtensionMetadata::ARROW_EXTENSION_NON_CANONICAL; - extension_metadata_map = StringUtil::ParseJSONMap(schema_metadata_map[ARROW_METADATA_KEY], ignore_errors); -} - -ArrowSchemaMetadata::ArrowSchemaMetadata() { - // Always initialize out metadata map - extension_metadata_map = make_uniq(); + extension_metadata_map = StringUtil::ParseJSONMap(schema_metadata_map[ARROW_METADATA_KEY]); } void ArrowSchemaMetadata::AddOption(const string &key, const string &value) { @@ -66,9 +58,9 @@ ArrowSchemaMetadata ArrowSchemaMetadata::NonCanonicalType(const string &type_nam ArrowSchemaMetadata metadata; metadata.AddOption(ARROW_EXTENSION_NAME, ArrowExtensionMetadata::ARROW_EXTENSION_NON_CANONICAL); // We have to set the metadata key with type_name and vendor_name. - metadata.extension_metadata_map->AddObject("vendor_name", make_uniq(vendor_name)); - metadata.extension_metadata_map->AddObject("type_name", make_uniq(type_name)); - metadata.AddOption(ARROW_METADATA_KEY, StringUtil::ToComplexJSONMap(*metadata.extension_metadata_map)); + metadata.extension_metadata_map["vendor_name"] = vendor_name; + metadata.extension_metadata_map["type_name"] = type_name; + metadata.AddOption(ARROW_METADATA_KEY, StringUtil::ToJSONMap(metadata.extension_metadata_map)); return metadata; } @@ -78,8 +70,8 @@ bool ArrowSchemaMetadata::HasExtension() const { } ArrowExtensionMetadata ArrowSchemaMetadata::GetExtensionInfo(string format) { - return {schema_metadata_map[ARROW_EXTENSION_NAME], extension_metadata_map->GetValue("vendor_name"), - extension_metadata_map->GetValue("type_name"), std::move(format)}; + return {schema_metadata_map[ARROW_EXTENSION_NAME], extension_metadata_map["vendor_name"], + extension_metadata_map["type_name"], std::move(format)}; } unsafe_unique_array ArrowSchemaMetadata::SerializeMetadata() const { diff --git a/src/duckdb/src/common/cgroups.cpp b/src/duckdb/src/common/cgroups.cpp index cb3a5e264..d7ddd980c 100644 --- a/src/duckdb/src/common/cgroups.cpp +++ b/src/duckdb/src/common/cgroups.cpp @@ -5,297 +5,182 @@ #include "duckdb/common/limits.hpp" #include "duckdb/common/types/cast_helpers.hpp" #include "duckdb/common/operator/cast_operators.hpp" -#include "duckdb/common/printer.hpp" #include namespace duckdb { -#if defined(__linux__) && !defined(DUCKDB_WASM) +optional_idx CGroups::GetMemoryLimit(FileSystem &fs) { + // First, try cgroup v2 + auto cgroup_v2_limit = GetCGroupV2MemoryLimit(fs); + if (cgroup_v2_limit.IsValid()) { + return cgroup_v2_limit; + } -namespace { + // If cgroup v2 fails, try cgroup v1 + return GetCGroupV1MemoryLimit(fs); +} -static constexpr const char *CGROUP_PATH = "/proc/self/cgroup"; -static constexpr const int64_t DEFAULT_CGROUP_FILE_BUFFER_SIZE = 1024; +optional_idx CGroups::GetCGroupV2MemoryLimit(FileSystem &fs) { +#if defined(__linux__) && !defined(DUCKDB_WASM) + const char *cgroup_self = "/proc/self/cgroup"; + const char *memory_max = "/sys/fs/cgroup/%s/memory.max"; -struct CGroupEntry { -public: - CGroupEntry(idx_t hierarchy_id, vector &&controller_list, const string &cgroup_path) - : hierarchy_id(hierarchy_id), controller_list(std::move(controller_list)), cgroup_path(cgroup_path) { + if (!fs.FileExists(cgroup_self)) { + return optional_idx(); } -public: - bool IsRoot() const { - if (hierarchy_id != 0) { - return false; - } - if (controller_list.size() != 1) { - return false; - } - return controller_list[0].empty(); + string cgroup_path = ReadCGroupPath(fs, cgroup_self); + if (cgroup_path.empty()) { + return optional_idx(); } -public: - idx_t hierarchy_id; - vector controller_list; - string cgroup_path; -}; + char memory_max_path[256]; + snprintf(memory_max_path, sizeof(memory_max_path), memory_max, cgroup_path.c_str()); -static vector ParseGroupEntries(FileSystem &fs) { - vector result; - if (!fs.FileExists(CGROUP_PATH)) { - return result; + if (!fs.FileExists(memory_max_path)) { + return optional_idx(); } - auto handle = fs.OpenFile(CGROUP_PATH, FileFlags::FILE_FLAGS_READ); - - char buffer[DEFAULT_CGROUP_FILE_BUFFER_SIZE]; - int64_t bytes_read; - string cgroup_file_content; - do { - bytes_read = fs.Read(*handle, buffer, DEFAULT_CGROUP_FILE_BUFFER_SIZE - 1); - buffer[bytes_read] = '\0'; - cgroup_file_content += string(buffer); - } while (bytes_read >= DEFAULT_CGROUP_FILE_BUFFER_SIZE - 1); - - auto lines = StringUtil::Split(cgroup_file_content, "\n"); - for (auto &line : lines) { - //! NOTE: this can not use StringUtil::Split, as it counts '::' as a single delimiter - vector parts; - auto it = line.begin(); - while (it != line.end()) { - //! Don't make more than 3 splits - auto next = parts.size() == 2 ? line.end() : std::find_if(it, line.end(), [](char c) { return c == ':'; }); - - parts.emplace_back(it, next); - if (next == line.end()) { - break; - } - it = std::next(next); - } - - if (parts.size() < 3) { - //! cgroup entries are in this format: - // hierarchy-ID:controller-list:cgroup-path - break; - } - auto hierarchy_id = std::stoi(parts[0]); - auto controller_list = StringUtil::Split(parts[1], ","); - auto cgroup_path = parts[2] == "/" ? "" : parts[2]; - result.emplace_back(hierarchy_id, std::move(controller_list), cgroup_path); - } - return result; + return ReadCGroupValue(fs, memory_max_path); +#else + return optional_idx(); +#endif } -static optional_idx GetCPUCountV2(const string &cgroup_path, FileSystem &fs) { - static constexpr const char *CPU_MAX = "/sys/fs/cgroup%s/cpu.max"; - - auto cpu_max = StringUtil::Format(CPU_MAX, cgroup_path); - - //! See https://docs.kernel.org/scheduler/sched-bwc.html - //! run-time replenished within a period (in microseconds) - int64_t quota; - //! the length of a period (in microseconds) - int64_t period; +optional_idx CGroups::GetCGroupV1MemoryLimit(FileSystem &fs) { +#if defined(__linux__) && !defined(DUCKDB_WASM) + const char *cgroup_self = "/proc/self/cgroup"; + const char *memory_limit = "/sys/fs/cgroup/memory/%s/memory.limit_in_bytes"; - if (!fs.FileExists(cpu_max)) { + if (!fs.FileExists(cgroup_self)) { return optional_idx(); } - // cgroup v2 - char byte_buffer[1000]; - auto handle = fs.OpenFile(cpu_max, FileFlags::FILE_FLAGS_READ); - int64_t read_bytes = fs.Read(*handle, (void *)byte_buffer, 999); - byte_buffer[read_bytes] = '\0'; - if (std::sscanf(byte_buffer, "%" SCNd64 " %" SCNd64 "", "a, &period) != 2) { + string memory_cgroup_path = ReadMemoryCGroupPath(fs, cgroup_self); + if (memory_cgroup_path.empty()) { return optional_idx(); } - if (quota > 0 && period > 0) { - return idx_t(std::ceil((double)quota / (double)period)); + char memory_limit_path[256]; + snprintf(memory_limit_path, sizeof(memory_limit_path), memory_limit, memory_cgroup_path.c_str()); + + if (!fs.FileExists(memory_limit_path)) { + return optional_idx(); } + + return ReadCGroupValue(fs, memory_limit_path); +#else return optional_idx(); +#endif } -static optional_idx GetCPUCountV1(const string &cgroup_path, FileSystem &fs) { - static constexpr const char *CFS_QUOTA = "/sys/fs/cgroup/cpu%s/cpu.cfs_quota_us"; - static constexpr const char *CFS_PERIOD = "/sys/fs/cgroup/cpu%s/cpu.cfs_period_us"; - - auto cfs_quota = StringUtil::Format(CFS_QUOTA, cgroup_path); - auto cfs_period = StringUtil::Format(CFS_PERIOD, cgroup_path); +string CGroups::ReadCGroupPath(FileSystem &fs, const char *cgroup_file) { +#if defined(__linux__) && !defined(DUCKDB_WASM) + auto handle = fs.OpenFile(cgroup_file, FileFlags::FILE_FLAGS_READ); + char buffer[1024]; + auto bytes_read = fs.Read(*handle, buffer, sizeof(buffer) - 1); + buffer[bytes_read] = '\0'; - if (!fs.FileExists(cfs_quota) || !fs.FileExists(cfs_period)) { - return optional_idx(); + // For cgroup v2, we're looking for a single line with "0::/path" + string content(buffer); + auto pos = content.find("::"); + if (pos != string::npos) { + // remove trailing \n + auto pos2 = content.find('\n', pos + 2); + if (pos2 != string::npos) { + return content.substr(pos + 2, pos2 - (pos + 2)); + } else { + return content.substr(pos + 2); + } } +#endif + return ""; +} - //! See https://docs.kernel.org/scheduler/sched-bwc.html - //! run-time replenished within a period (in microseconds) - int64_t quota; - //! the length of a period (in microseconds) - int64_t period; +string CGroups::ReadMemoryCGroupPath(FileSystem &fs, const char *cgroup_file) { +#if defined(__linux__) && !defined(DUCKDB_WASM) + auto handle = fs.OpenFile(cgroup_file, FileFlags::FILE_FLAGS_READ); + char buffer[1024]; + auto bytes_read = fs.Read(*handle, buffer, sizeof(buffer) - 1); + buffer[bytes_read] = '\0'; - // cgroup v1 - char byte_buffer[1000]; - { - auto handle = fs.OpenFile(cfs_quota, FileFlags::FILE_FLAGS_READ); - int64_t read_bytes = fs.Read(*handle, (void *)byte_buffer, 999); - byte_buffer[read_bytes] = '\0'; - if (std::sscanf(byte_buffer, "%" SCNd64 "", "a) != 1) { - return optional_idx(); - } - } - { - auto handle = fs.OpenFile(cfs_period, FileFlags::FILE_FLAGS_READ); - int64_t read_bytes = fs.Read(*handle, (void *)byte_buffer, 999); - byte_buffer[read_bytes] = '\0'; - if (std::sscanf(byte_buffer, "%" SCNd64 "", &period) != 1) { - return optional_idx(); + // For cgroup v1, we're looking for a line with "memory:/path" + string content(buffer); + size_t pos = 0; + string line; + while ((pos = content.find('\n')) != string::npos) { + line = content.substr(0, pos); + if (line.find("memory:") == 0) { + return line.substr(line.find(':') + 1); } + content.erase(0, pos + 1); } - - if (quota > 0 && period > 0) { - return idx_t(std::ceil((double)quota / (double)period)); - } - return optional_idx(); +#endif + return ""; } -static optional_idx ReadMemoryLimit(FileSystem &fs, const string &file_path) { - if (!fs.FileExists(file_path)) { - return optional_idx(); - } - +optional_idx CGroups::ReadCGroupValue(FileSystem &fs, const char *file_path) { +#if defined(__linux__) && !defined(DUCKDB_WASM) auto handle = fs.OpenFile(file_path, FileFlags::FILE_FLAGS_READ); char buffer[100]; auto bytes_read = fs.Read(*handle, buffer, 99); buffer[bytes_read] = '\0'; - auto contents = string_t(buffer); idx_t value; - if (TryCast::Operation(contents, value)) { + if (TryCast::Operation(string_t(buffer), value)) { return optional_idx(value); } - return optional_idx(); -} - -} // namespace - -optional_idx CGroups::GetMemoryLimit(FileSystem &fs) { - static constexpr const char *MEMORY_LIMIT_IN_BYTES = "/sys/fs/cgroup/memory%s/memory.limit_in_bytes"; - static constexpr const char *MEMORY_MAX = "/sys/fs/cgroup%s/memory.max"; - - optional_idx root_entry; - optional_idx memory_entry; - - auto cgroup_entries = ParseGroupEntries(fs); - for (idx_t i = 0; i < cgroup_entries.size(); i++) { - auto &entry = cgroup_entries[i]; - auto &controller_list = entry.controller_list; - if (entry.IsRoot()) { - root_entry = i; - continue; - } - for (auto &controller : controller_list) { - if (controller == "memory") { - memory_entry = i; - break; - } - } - } - - // TODO: we currently fall back to the root directory, because in virtual environments - // the cgroups are often mapped to the root directory. - // To properly handle this, we should parse and use the mapping in `/proc/self/mountinfo` - if (memory_entry.IsValid()) { - auto &entry = cgroup_entries[memory_entry.GetIndex()]; - auto path = StringUtil::Format(MEMORY_LIMIT_IN_BYTES, entry.cgroup_path); - auto memory_limit = ReadMemoryLimit(fs, path.c_str()); - if (memory_limit.IsValid()) { - return memory_limit; - } - //! try falling back to the root directory - path = StringUtil::Format(MEMORY_LIMIT_IN_BYTES, ""); - memory_limit = ReadMemoryLimit(fs, path.c_str()); - if (memory_limit.IsValid()) { - return memory_limit; - } - } - if (root_entry.IsValid()) { - auto &entry = cgroup_entries[root_entry.GetIndex()]; - auto path = StringUtil::Format(MEMORY_MAX, entry.cgroup_path); - auto memory_limit = ReadMemoryLimit(fs, path.c_str()); - if (memory_limit.IsValid()) { - return memory_limit; - } - //! try falling back to the root directory - path = StringUtil::Format(MEMORY_MAX, ""); - memory_limit = ReadMemoryLimit(fs, path.c_str()); - if (memory_limit.IsValid()) { - return memory_limit; - } - } +#endif return optional_idx(); } idx_t CGroups::GetCPULimit(FileSystem &fs, idx_t physical_cores) { - optional_idx root_entry; - optional_idx cpu_entry; +#if defined(__linux__) && !defined(DUCKDB_WASM) + static constexpr const char *cpu_max = "/sys/fs/cgroup/cpu.max"; + static constexpr const char *cfs_quota = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"; + static constexpr const char *cfs_period = "/sys/fs/cgroup/cpu/cpu.cfs_period_us"; - auto cgroup_entries = ParseGroupEntries(fs); - for (idx_t i = 0; i < cgroup_entries.size(); i++) { - auto &entry = cgroup_entries[i]; - auto &controller_list = entry.controller_list; - if (entry.IsRoot()) { - root_entry = i; - continue; + int64_t quota, period; + char byte_buffer[1000]; + unique_ptr handle; + int64_t read_bytes; + + if (fs.FileExists(cpu_max)) { + // cgroup v2 + handle = fs.OpenFile(cpu_max, FileFlags::FILE_FLAGS_READ); + read_bytes = fs.Read(*handle, (void *)byte_buffer, 999); + byte_buffer[read_bytes] = '\0'; + if (std::sscanf(byte_buffer, "%" SCNd64 " %" SCNd64 "", "a, &period) != 2) { + return physical_cores; } - for (auto &controller : controller_list) { - if (controller == "cpu") { - cpu_entry = i; - continue; - } + } else if (fs.FileExists(cfs_quota) && fs.FileExists(cfs_period)) { + // cgroup v1 + handle = fs.OpenFile(cfs_quota, FileFlags::FILE_FLAGS_READ); + read_bytes = fs.Read(*handle, (void *)byte_buffer, 999); + byte_buffer[read_bytes] = '\0'; + if (std::sscanf(byte_buffer, "%" SCNd64 "", "a) != 1) { + return physical_cores; } - } - // TODO: we currently fall back to the root directory, because in virtual environments - // the cgroups are often mapped to the root directory. - // To properly handle this, we should parse and use the mapping in `/proc/self/mountinfo` - if (cpu_entry.IsValid()) { - auto &entry = cgroup_entries[cpu_entry.GetIndex()]; - auto res = GetCPUCountV1(entry.cgroup_path, fs); - if (res.IsValid()) { - return res.GetIndex(); - } - //! try falling back to the root directory - res = GetCPUCountV1("", fs); - if (res.IsValid()) { - return res.GetIndex(); + handle = fs.OpenFile(cfs_period, FileFlags::FILE_FLAGS_READ); + read_bytes = fs.Read(*handle, (void *)byte_buffer, 999); + byte_buffer[read_bytes] = '\0'; + if (std::sscanf(byte_buffer, "%" SCNd64 "", &period) != 1) { + return physical_cores; } + } else { + // No cgroup quota + return physical_cores; } - if (root_entry.IsValid()) { - auto &entry = cgroup_entries[root_entry.GetIndex()]; - auto res = GetCPUCountV2(entry.cgroup_path, fs); - if (res.IsValid()) { - return res.GetIndex(); - } - //! try falling back to the root directory - res = GetCPUCountV2("", fs); - if (res.IsValid()) { - return res.GetIndex(); - } + if (quota > 0 && period > 0) { + return idx_t(std::ceil((double)quota / (double)period)); + } else { + return physical_cores; } - return physical_cores; -} - #else - -optional_idx CGroups::GetMemoryLimit(FileSystem &fs) { - return optional_idx(); -} - -idx_t CGroups::GetCPULimit(FileSystem &fs, idx_t physical_cores) { return physical_cores; -} - #endif +} } // namespace duckdb diff --git a/src/duckdb/src/common/checksum.cpp b/src/duckdb/src/common/checksum.cpp index ca44a83c8..2fbca299e 100644 --- a/src/duckdb/src/common/checksum.cpp +++ b/src/duckdb/src/common/checksum.cpp @@ -1,6 +1,5 @@ #include "duckdb/common/checksum.hpp" - -#include "duckdb/common/helper.hpp" +#include "duckdb/common/types/hash.hpp" namespace duckdb { @@ -8,62 +7,6 @@ hash_t Checksum(uint64_t x) { return x * UINT64_C(0xbf58476d1ce4e5b9); } -// MIT License -// Copyright (c) 2018-2021 Martin Ankerl -// https://github.com/martinus/robin-hood-hashing/blob/3.11.5/LICENSE -hash_t ChecksumRemainder(void *ptr, size_t len) noexcept { - static constexpr uint64_t M = UINT64_C(0xc6a4a7935bd1e995); - static constexpr uint64_t SEED = UINT64_C(0xe17a1465); - static constexpr unsigned int R = 47; - - auto const *const data64 = static_cast(ptr); - uint64_t h = SEED ^ (len * M); - - size_t const n_blocks = len / 8; - for (size_t i = 0; i < n_blocks; ++i) { - auto k = Load(reinterpret_cast(data64 + i)); - - k *= M; - k ^= k >> R; - k *= M; - - h ^= k; - h *= M; - } - - auto const *const data8 = reinterpret_cast(data64 + n_blocks); - switch (len & 7U) { - case 7: - h ^= static_cast(data8[6]) << 48U; - DUCKDB_EXPLICIT_FALLTHROUGH; - case 6: - h ^= static_cast(data8[5]) << 40U; - DUCKDB_EXPLICIT_FALLTHROUGH; - case 5: - h ^= static_cast(data8[4]) << 32U; - DUCKDB_EXPLICIT_FALLTHROUGH; - case 4: - h ^= static_cast(data8[3]) << 24U; - DUCKDB_EXPLICIT_FALLTHROUGH; - case 3: - h ^= static_cast(data8[2]) << 16U; - DUCKDB_EXPLICIT_FALLTHROUGH; - case 2: - h ^= static_cast(data8[1]) << 8U; - DUCKDB_EXPLICIT_FALLTHROUGH; - case 1: - h ^= static_cast(data8[0]); - h *= M; - DUCKDB_EXPLICIT_FALLTHROUGH; - default: - break; - } - h ^= h >> R; - h *= M; - h ^= h >> R; - return static_cast(h); -} - uint64_t Checksum(uint8_t *buffer, size_t size) { uint64_t result = 5381; uint64_t *ptr = reinterpret_cast(buffer); @@ -74,7 +17,7 @@ uint64_t Checksum(uint8_t *buffer, size_t size) { } if (size - i * 8 > 0) { // the remaining 0-7 bytes we hash using a string hash - result ^= ChecksumRemainder(buffer + i * 8, size - i * 8); + result ^= Hash(buffer + i * 8, size - i * 8); } return result; } diff --git a/src/duckdb/src/common/constants.cpp b/src/duckdb/src/common/constants.cpp index 2bddd6195..edafe6b67 100644 --- a/src/duckdb/src/common/constants.cpp +++ b/src/duckdb/src/common/constants.cpp @@ -9,9 +9,7 @@ namespace duckdb { constexpr const idx_t DConstants::INVALID_INDEX; const row_t MAX_ROW_ID = 36028797018960000ULL; // 2^55 const row_t MAX_ROW_ID_LOCAL = 72057594037920000ULL; // 2^56 -const column_t COLUMN_IDENTIFIER_ROW_ID = UINT64_C(18446744073709551615); -const column_t COLUMN_IDENTIFIER_EMPTY = UINT64_C(18446744073709551614); -const column_t VIRTUAL_COLUMN_START = UINT64_C(9223372036854775808); // 2^63 +const column_t COLUMN_IDENTIFIER_ROW_ID = (column_t)-1; const double PI = 3.141592653589793; const transaction_t TRANSACTION_ID_START = 4611686018427388000ULL; // 2^62 @@ -58,8 +56,4 @@ bool IsRowIdColumnId(column_t column_id) { return column_id == COLUMN_IDENTIFIER_ROW_ID; } -bool IsVirtualColumn(column_t column_id) { - return column_id >= VIRTUAL_COLUMN_START; -} - } // namespace duckdb diff --git a/src/duckdb/src/common/enum_util.cpp b/src/duckdb/src/common/enum_util.cpp index 151ae5114..49e7bb2b9 100644 --- a/src/duckdb/src/common/enum_util.cpp +++ b/src/duckdb/src/common/enum_util.cpp @@ -22,7 +22,6 @@ #include "duckdb/common/enums/cte_materialize.hpp" #include "duckdb/common/enums/date_part_specifier.hpp" #include "duckdb/common/enums/debug_initialize.hpp" -#include "duckdb/common/enums/debug_vector_verification.hpp" #include "duckdb/common/enums/destroy_buffer_upon.hpp" #include "duckdb/common/enums/explain_format.hpp" #include "duckdb/common/enums/expression_type.hpp" @@ -66,9 +65,8 @@ #include "duckdb/common/extra_type_info.hpp" #include "duckdb/common/file_buffer.hpp" #include "duckdb/common/file_open_flags.hpp" -#include "duckdb/common/multi_file/multi_file_data.hpp" -#include "duckdb/common/multi_file/multi_file_list.hpp" -#include "duckdb/common/multi_file/multi_file_options.hpp" +#include "duckdb/common/multi_file_list.hpp" +#include "duckdb/common/multi_file_reader_options.hpp" #include "duckdb/common/operator/decimal_cast_operators.hpp" #include "duckdb/common/printer.hpp" #include "duckdb/common/sort/partition_state.hpp" @@ -84,7 +82,6 @@ #include "duckdb/common/types/vector.hpp" #include "duckdb/common/types/vector_buffer.hpp" #include "duckdb/execution/index/art/art.hpp" -#include "duckdb/execution/index/art/art_scanner.hpp" #include "duckdb/execution/index/art/node.hpp" #include "duckdb/execution/index/bound_index.hpp" #include "duckdb/execution/operator/csv_scanner/csv_option.hpp" @@ -120,7 +117,6 @@ #include "duckdb/parallel/task.hpp" #include "duckdb/parser/constraint.hpp" #include "duckdb/parser/expression/parameter_expression.hpp" -#include "duckdb/parser/expression/star_expression.hpp" #include "duckdb/parser/expression/window_expression.hpp" #include "duckdb/parser/parsed_data/alter_info.hpp" #include "duckdb/parser/parsed_data/alter_scalar_function_info.hpp" @@ -174,43 +170,6 @@ ARTConflictType EnumUtil::FromString(const char *value) { return static_cast(StringUtil::StringToEnum(GetARTConflictTypeValues(), 3, "ARTConflictType", value)); } -const StringUtil::EnumStringLiteral *GetARTScanHandlingValues() { - static constexpr StringUtil::EnumStringLiteral values[] { - { static_cast(ARTScanHandling::EMPLACE), "EMPLACE" }, - { static_cast(ARTScanHandling::POP), "POP" } - }; - return values; -} - -template<> -const char* EnumUtil::ToChars(ARTScanHandling value) { - return StringUtil::EnumToString(GetARTScanHandlingValues(), 2, "ARTScanHandling", static_cast(value)); -} - -template<> -ARTScanHandling EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetARTScanHandlingValues(), 2, "ARTScanHandling", value)); -} - -const StringUtil::EnumStringLiteral *GetARTScanHandlingResultValues() { - static constexpr StringUtil::EnumStringLiteral values[] { - { static_cast(ARTScanHandlingResult::CONTINUE), "CONTINUE" }, - { static_cast(ARTScanHandlingResult::SKIP), "SKIP" }, - { static_cast(ARTScanHandlingResult::YIELD), "YIELD" } - }; - return values; -} - -template<> -const char* EnumUtil::ToChars(ARTScanHandlingResult value) { - return StringUtil::EnumToString(GetARTScanHandlingResultValues(), 3, "ARTScanHandlingResult", static_cast(value)); -} - -template<> -ARTScanHandlingResult EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetARTScanHandlingResultValues(), 3, "ARTScanHandlingResult", value)); -} - const StringUtil::EnumStringLiteral *GetAccessModeValues() { static constexpr StringUtil::EnumStringLiteral values[] { { static_cast(AccessMode::UNDEFINED), "UNDEFINED" }, @@ -389,24 +348,19 @@ const StringUtil::EnumStringLiteral *GetAlterTableTypeValues() { { static_cast(AlterTableType::SET_NOT_NULL), "SET_NOT_NULL" }, { static_cast(AlterTableType::DROP_NOT_NULL), "DROP_NOT_NULL" }, { static_cast(AlterTableType::SET_COLUMN_COMMENT), "SET_COLUMN_COMMENT" }, - { static_cast(AlterTableType::ADD_CONSTRAINT), "ADD_CONSTRAINT" }, - { static_cast(AlterTableType::SET_PARTITIONED_BY), "SET_PARTITIONED_BY" }, - { static_cast(AlterTableType::SET_SORTED_BY), "SET_SORTED_BY" }, - { static_cast(AlterTableType::ADD_FIELD), "ADD_FIELD" }, - { static_cast(AlterTableType::REMOVE_FIELD), "REMOVE_FIELD" }, - { static_cast(AlterTableType::RENAME_FIELD), "RENAME_FIELD" } + { static_cast(AlterTableType::ADD_CONSTRAINT), "ADD_CONSTRAINT" } }; return values; } template<> const char* EnumUtil::ToChars(AlterTableType value) { - return StringUtil::EnumToString(GetAlterTableTypeValues(), 17, "AlterTableType", static_cast(value)); + return StringUtil::EnumToString(GetAlterTableTypeValues(), 12, "AlterTableType", static_cast(value)); } template<> AlterTableType EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetAlterTableTypeValues(), 17, "AlterTableType", value)); + return static_cast(StringUtil::StringToEnum(GetAlterTableTypeValues(), 12, "AlterTableType", value)); } const StringUtil::EnumStringLiteral *GetAlterTypeValues() { @@ -967,20 +921,19 @@ ConstraintType EnumUtil::FromString(const char *value) { const StringUtil::EnumStringLiteral *GetCopyFunctionReturnTypeValues() { static constexpr StringUtil::EnumStringLiteral values[] { { static_cast(CopyFunctionReturnType::CHANGED_ROWS), "CHANGED_ROWS" }, - { static_cast(CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST), "CHANGED_ROWS_AND_FILE_LIST" }, - { static_cast(CopyFunctionReturnType::WRITTEN_FILE_STATISTICS), "WRITTEN_FILE_STATISTICS" } + { static_cast(CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST), "CHANGED_ROWS_AND_FILE_LIST" } }; return values; } template<> const char* EnumUtil::ToChars(CopyFunctionReturnType value) { - return StringUtil::EnumToString(GetCopyFunctionReturnTypeValues(), 3, "CopyFunctionReturnType", static_cast(value)); + return StringUtil::EnumToString(GetCopyFunctionReturnTypeValues(), 2, "CopyFunctionReturnType", static_cast(value)); } template<> CopyFunctionReturnType EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetCopyFunctionReturnTypeValues(), 3, "CopyFunctionReturnType", value)); + return static_cast(StringUtil::StringToEnum(GetCopyFunctionReturnTypeValues(), 2, "CopyFunctionReturnType", value)); } const StringUtil::EnumStringLiteral *GetCopyOverwriteModeValues() { @@ -1120,28 +1073,6 @@ DebugInitialize EnumUtil::FromString(const char *value) { return static_cast(StringUtil::StringToEnum(GetDebugInitializeValues(), 3, "DebugInitialize", value)); } -const StringUtil::EnumStringLiteral *GetDebugVectorVerificationValues() { - static constexpr StringUtil::EnumStringLiteral values[] { - { static_cast(DebugVectorVerification::NONE), "NONE" }, - { static_cast(DebugVectorVerification::DICTIONARY_EXPRESSION), "DICTIONARY_EXPRESSION" }, - { static_cast(DebugVectorVerification::DICTIONARY_OPERATOR), "DICTIONARY_OPERATOR" }, - { static_cast(DebugVectorVerification::CONSTANT_OPERATOR), "CONSTANT_OPERATOR" }, - { static_cast(DebugVectorVerification::SEQUENCE_OPERATOR), "SEQUENCE_OPERATOR" }, - { static_cast(DebugVectorVerification::NESTED_SHUFFLE), "NESTED_SHUFFLE" } - }; - return values; -} - -template<> -const char* EnumUtil::ToChars(DebugVectorVerification value) { - return StringUtil::EnumToString(GetDebugVectorVerificationValues(), 6, "DebugVectorVerification", static_cast(value)); -} - -template<> -DebugVectorVerification EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetDebugVectorVerificationValues(), 6, "DebugVectorVerification", value)); -} - const StringUtil::EnumStringLiteral *GetDefaultOrderByNullTypeValues() { static constexpr StringUtil::EnumStringLiteral values[] { { static_cast(DefaultOrderByNullType::INVALID), "INVALID" }, @@ -1476,7 +1407,6 @@ const StringUtil::EnumStringLiteral *GetExpressionTypeValues() { { static_cast(ExpressionType::OPERATOR_NOT), "OPERATOR_NOT" }, { static_cast(ExpressionType::OPERATOR_IS_NULL), "OPERATOR_IS_NULL" }, { static_cast(ExpressionType::OPERATOR_IS_NOT_NULL), "OPERATOR_IS_NOT_NULL" }, - { static_cast(ExpressionType::OPERATOR_UNPACK), "OPERATOR_UNPACK" }, { static_cast(ExpressionType::COMPARE_EQUAL), "COMPARE_EQUAL" }, { static_cast(ExpressionType::COMPARE_NOTEQUAL), "COMPARE_NOTEQUAL" }, { static_cast(ExpressionType::COMPARE_LESSTHAN), "COMPARE_LESSTHAN" }, @@ -1524,7 +1454,6 @@ const StringUtil::EnumStringLiteral *GetExpressionTypeValues() { { static_cast(ExpressionType::STRUCT_EXTRACT), "STRUCT_EXTRACT" }, { static_cast(ExpressionType::ARRAY_CONSTRUCTOR), "ARRAY_CONSTRUCTOR" }, { static_cast(ExpressionType::ARROW), "ARROW" }, - { static_cast(ExpressionType::OPERATOR_TRY), "OPERATOR_TRY" }, { static_cast(ExpressionType::SUBQUERY), "SUBQUERY" }, { static_cast(ExpressionType::STAR), "STAR" }, { static_cast(ExpressionType::TABLE_STAR), "TABLE_STAR" }, @@ -1548,12 +1477,12 @@ const StringUtil::EnumStringLiteral *GetExpressionTypeValues() { template<> const char* EnumUtil::ToChars(ExpressionType value) { - return StringUtil::EnumToString(GetExpressionTypeValues(), 71, "ExpressionType", static_cast(value)); + return StringUtil::EnumToString(GetExpressionTypeValues(), 69, "ExpressionType", static_cast(value)); } template<> ExpressionType EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetExpressionTypeValues(), 71, "ExpressionType", value)); + return static_cast(StringUtil::StringToEnum(GetExpressionTypeValues(), 69, "ExpressionType", value)); } const StringUtil::EnumStringLiteral *GetExtensionABITypeValues() { @@ -2488,43 +2417,22 @@ MetricsType EnumUtil::FromString(const char *value) { return static_cast(StringUtil::StringToEnum(GetMetricsTypeValues(), 49, "MetricsType", value)); } -const StringUtil::EnumStringLiteral *GetMultiFileColumnMappingModeValues() { +const StringUtil::EnumStringLiteral *GetMultiFileReaderColumnMappingModeValues() { static constexpr StringUtil::EnumStringLiteral values[] { - { static_cast(MultiFileColumnMappingMode::BY_NAME), "BY_NAME" }, - { static_cast(MultiFileColumnMappingMode::BY_FIELD_ID), "BY_FIELD_ID" } + { static_cast(MultiFileReaderColumnMappingMode::BY_NAME), "BY_NAME" }, + { static_cast(MultiFileReaderColumnMappingMode::BY_FIELD_ID), "BY_FIELD_ID" } }; return values; } template<> -const char* EnumUtil::ToChars(MultiFileColumnMappingMode value) { - return StringUtil::EnumToString(GetMultiFileColumnMappingModeValues(), 2, "MultiFileColumnMappingMode", static_cast(value)); -} - -template<> -MultiFileColumnMappingMode EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetMultiFileColumnMappingModeValues(), 2, "MultiFileColumnMappingMode", value)); -} - -const StringUtil::EnumStringLiteral *GetMultiFileFileStateValues() { - static constexpr StringUtil::EnumStringLiteral values[] { - { static_cast(MultiFileFileState::UNOPENED), "UNOPENED" }, - { static_cast(MultiFileFileState::OPENING), "OPENING" }, - { static_cast(MultiFileFileState::OPEN), "OPEN" }, - { static_cast(MultiFileFileState::SKIPPED), "SKIPPED" }, - { static_cast(MultiFileFileState::CLOSED), "CLOSED" } - }; - return values; +const char* EnumUtil::ToChars(MultiFileReaderColumnMappingMode value) { + return StringUtil::EnumToString(GetMultiFileReaderColumnMappingModeValues(), 2, "MultiFileReaderColumnMappingMode", static_cast(value)); } template<> -const char* EnumUtil::ToChars(MultiFileFileState value) { - return StringUtil::EnumToString(GetMultiFileFileStateValues(), 5, "MultiFileFileState", static_cast(value)); -} - -template<> -MultiFileFileState EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetMultiFileFileStateValues(), 5, "MultiFileFileState", value)); +MultiFileReaderColumnMappingMode EnumUtil::FromString(const char *value) { + return static_cast(StringUtil::StringToEnum(GetMultiFileReaderColumnMappingModeValues(), 2, "MultiFileReaderColumnMappingMode", value)); } const StringUtil::EnumStringLiteral *GetNTypeValues() { @@ -2957,7 +2865,6 @@ const StringUtil::EnumStringLiteral *GetPhysicalOperatorTypeValues() { { static_cast(PhysicalOperatorType::COLUMN_DATA_SCAN), "COLUMN_DATA_SCAN" }, { static_cast(PhysicalOperatorType::CHUNK_SCAN), "CHUNK_SCAN" }, { static_cast(PhysicalOperatorType::RECURSIVE_CTE_SCAN), "RECURSIVE_CTE_SCAN" }, - { static_cast(PhysicalOperatorType::RECURSIVE_RECURRING_CTE_SCAN), "RECURSIVE_RECURRING_CTE_SCAN" }, { static_cast(PhysicalOperatorType::CTE_SCAN), "CTE_SCAN" }, { static_cast(PhysicalOperatorType::DELIM_SCAN), "DELIM_SCAN" }, { static_cast(PhysicalOperatorType::EXPRESSION_SCAN), "EXPRESSION_SCAN" }, @@ -2974,7 +2881,6 @@ const StringUtil::EnumStringLiteral *GetPhysicalOperatorTypeValues() { { static_cast(PhysicalOperatorType::ASOF_JOIN), "ASOF_JOIN" }, { static_cast(PhysicalOperatorType::UNION), "UNION" }, { static_cast(PhysicalOperatorType::RECURSIVE_CTE), "RECURSIVE_CTE" }, - { static_cast(PhysicalOperatorType::RECURSIVE_KEY_CTE), "RECURSIVE_KEY_CTE" }, { static_cast(PhysicalOperatorType::CTE), "CTE" }, { static_cast(PhysicalOperatorType::INSERT), "INSERT" }, { static_cast(PhysicalOperatorType::BATCH_INSERT), "BATCH_INSERT" }, @@ -3018,12 +2924,12 @@ const StringUtil::EnumStringLiteral *GetPhysicalOperatorTypeValues() { template<> const char* EnumUtil::ToChars(PhysicalOperatorType value) { - return StringUtil::EnumToString(GetPhysicalOperatorTypeValues(), 81, "PhysicalOperatorType", static_cast(value)); + return StringUtil::EnumToString(GetPhysicalOperatorTypeValues(), 79, "PhysicalOperatorType", static_cast(value)); } template<> PhysicalOperatorType EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetPhysicalOperatorTypeValues(), 81, "PhysicalOperatorType", value)); + return static_cast(StringUtil::StringToEnum(GetPhysicalOperatorTypeValues(), 79, "PhysicalOperatorType", value)); } const StringUtil::EnumStringLiteral *GetPhysicalTypeValues() { @@ -3671,26 +3577,6 @@ SourceResultType EnumUtil::FromString(const char *value) { return static_cast(StringUtil::StringToEnum(GetSourceResultTypeValues(), 3, "SourceResultType", value)); } -const StringUtil::EnumStringLiteral *GetStarExpressionTypeValues() { - static constexpr StringUtil::EnumStringLiteral values[] { - { static_cast(StarExpressionType::STAR), "STAR" }, - { static_cast(StarExpressionType::COLUMNS), "COLUMNS" }, - { static_cast(StarExpressionType::UNPACKED), "UNPACKED" }, - { static_cast(StarExpressionType::NONE), "NONE" } - }; - return values; -} - -template<> -const char* EnumUtil::ToChars(StarExpressionType value) { - return StringUtil::EnumToString(GetStarExpressionTypeValues(), 4, "StarExpressionType", static_cast(value)); -} - -template<> -StarExpressionType EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetStarExpressionTypeValues(), 4, "StarExpressionType", value)); -} - const StringUtil::EnumStringLiteral *GetStatementReturnTypeValues() { static constexpr StringUtil::EnumStringLiteral values[] { { static_cast(StatementReturnType::QUERY_RESULT), "QUERY_RESULT" }, @@ -4098,20 +3984,19 @@ const StringUtil::EnumStringLiteral *GetTimestampCastResultValues() { { static_cast(TimestampCastResult::SUCCESS), "SUCCESS" }, { static_cast(TimestampCastResult::ERROR_INCORRECT_FORMAT), "ERROR_INCORRECT_FORMAT" }, { static_cast(TimestampCastResult::ERROR_NON_UTC_TIMEZONE), "ERROR_NON_UTC_TIMEZONE" }, - { static_cast(TimestampCastResult::ERROR_RANGE), "ERROR_RANGE" }, - { static_cast(TimestampCastResult::STRICT_UTC), "STRICT_UTC" } + { static_cast(TimestampCastResult::ERROR_RANGE), "ERROR_RANGE" } }; return values; } template<> const char* EnumUtil::ToChars(TimestampCastResult value) { - return StringUtil::EnumToString(GetTimestampCastResultValues(), 5, "TimestampCastResult", static_cast(value)); + return StringUtil::EnumToString(GetTimestampCastResultValues(), 4, "TimestampCastResult", static_cast(value)); } template<> TimestampCastResult EnumUtil::FromString(const char *value) { - return static_cast(StringUtil::StringToEnum(GetTimestampCastResultValues(), 5, "TimestampCastResult", value)); + return static_cast(StringUtil::StringToEnum(GetTimestampCastResultValues(), 4, "TimestampCastResult", value)); } const StringUtil::EnumStringLiteral *GetTransactionModifierTypeValues() { diff --git a/src/duckdb/src/common/enums/expression_type.cpp b/src/duckdb/src/common/enums/expression_type.cpp index 53b6cb6c4..105f4dfa7 100644 --- a/src/duckdb/src/common/enums/expression_type.cpp +++ b/src/duckdb/src/common/enums/expression_type.cpp @@ -15,8 +15,6 @@ string ExpressionTypeToString(ExpressionType type) { return "IS_NULL"; case ExpressionType::OPERATOR_IS_NOT_NULL: return "IS_NOT_NULL"; - case ExpressionType::OPERATOR_UNPACK: - return "UNPACK"; case ExpressionType::COMPARE_EQUAL: return "EQUAL"; case ExpressionType::COMPARE_NOTEQUAL: @@ -87,8 +85,6 @@ string ExpressionTypeToString(ExpressionType type) { return "NULLIF"; case ExpressionType::OPERATOR_COALESCE: return "COALESCE"; - case ExpressionType::OPERATOR_TRY: - return "TRY"; case ExpressionType::ARRAY_EXTRACT: return "ARRAY_EXTRACT"; case ExpressionType::ARRAY_SLICE: diff --git a/src/duckdb/src/common/enums/physical_operator_type.cpp b/src/duckdb/src/common/enums/physical_operator_type.cpp index 4691aec4e..f520cb448 100644 --- a/src/duckdb/src/common/enums/physical_operator_type.cpp +++ b/src/duckdb/src/common/enums/physical_operator_type.cpp @@ -103,14 +103,10 @@ string PhysicalOperatorToString(PhysicalOperatorType type) { return "VACUUM"; case PhysicalOperatorType::RECURSIVE_CTE: return "REC_CTE"; - case PhysicalOperatorType::RECURSIVE_KEY_CTE: - return "REC_KEY_CTE"; case PhysicalOperatorType::CTE: return "CTE"; case PhysicalOperatorType::RECURSIVE_CTE_SCAN: return "REC_CTE_SCAN"; - case PhysicalOperatorType::RECURSIVE_RECURRING_CTE_SCAN: - return "REC_REC_CTE_SCAN"; case PhysicalOperatorType::CTE_SCAN: return "CTE_SCAN"; case PhysicalOperatorType::EXPRESSION_SCAN: diff --git a/src/duckdb/src/common/error_data.cpp b/src/duckdb/src/common/error_data.cpp index c1e564217..d79799876 100644 --- a/src/duckdb/src/common/error_data.cpp +++ b/src/duckdb/src/common/error_data.cpp @@ -36,7 +36,7 @@ ErrorData::ErrorData(const string &message) raw_message = message; } } else { - auto info = StringUtil::ParseJSONMap(message)->Flatten(); + auto info = StringUtil::ParseJSONMap(message); for (auto &entry : info) { if (entry.first == "exception_type") { type = Exception::StringToExceptionType(entry.second); @@ -64,7 +64,7 @@ string ErrorData::ConstructFinalMessage() const { if (type == ExceptionType::INTERNAL) { error += "\nThis error signals an assertion failure within DuckDB. This usually occurs due to " "unexpected conditions or errors in the program's logic.\nFor more information, see " - "https://duckdb.org/docs/stable/dev/internal_errors"; + "https://duckdb.org/docs/dev/internal_errors"; } return error; } diff --git a/src/duckdb/src/common/exception.cpp b/src/duckdb/src/common/exception.cpp index 99b3d2662..71c5fa51e 100644 --- a/src/duckdb/src/common/exception.cpp +++ b/src/duckdb/src/common/exception.cpp @@ -32,7 +32,7 @@ string Exception::ToJSON(ExceptionType type, const string &message) { string Exception::ToJSON(ExceptionType type, const string &message, const unordered_map &extra_info) { #ifndef DUCKDB_DEBUG_STACKTRACE // by default we only enable stack traces for internal exceptions - if (type == ExceptionType::INTERNAL || type == ExceptionType::FATAL) + if (type == ExceptionType::INTERNAL) #endif { auto extended_extra_info = extra_info; @@ -194,17 +194,6 @@ unordered_map Exception::InitializeExtraInfo(optional_idx error_ return result; } -bool Exception::IsExecutionError(ExceptionType type) { - switch (type) { - case ExceptionType::INVALID_INPUT: - case ExceptionType::OUT_OF_RANGE: - case ExceptionType::CONVERSION: - return true; - default: - return false; - } -} - unordered_map Exception::InitializeExtraInfo(const string &subtype, optional_idx error_location) { unordered_map result; result["error_subtype"] = subtype; diff --git a/src/duckdb/src/common/exception/catalog_exception.cpp b/src/duckdb/src/common/exception/catalog_exception.cpp index 5d890f1cd..2ab210f0e 100644 --- a/src/duckdb/src/common/exception/catalog_exception.cpp +++ b/src/duckdb/src/common/exception/catalog_exception.cpp @@ -1,8 +1,6 @@ #include "duckdb/common/exception/catalog_exception.hpp" #include "duckdb/common/to_string.hpp" #include "duckdb/common/string_util.hpp" -#include "duckdb/catalog/entry_lookup_info.hpp" -#include "duckdb/planner/tableref/bound_at_clause.hpp" namespace duckdb { @@ -13,20 +11,12 @@ CatalogException::CatalogException(const string &msg, const unordered_mapUnit()) + " " + at_clause->GetValue().ToString(); - } auto extra_info = Exception::InitializeExtraInfo("MISSING_ENTRY", context.query_location); @@ -35,15 +25,9 @@ CatalogException CatalogException::MissingEntry(const EntryLookupInfo &lookup_in if (!suggestion.empty()) { extra_info["candidates"] = suggestion; } - return CatalogException(StringUtil::Format("%s with name %s does not exist%s!%s", CatalogTypeToString(type), name, - version_info, did_you_mean), - extra_info); -} - -CatalogException CatalogException::MissingEntry(CatalogType type, const string &name, const string &suggestion, - QueryErrorContext context) { - EntryLookupInfo lookup_info(type, name, context); - return MissingEntry(lookup_info, suggestion); + return CatalogException( + StringUtil::Format("%s with name %s does not exist!%s", CatalogTypeToString(type), name, did_you_mean), + extra_info); } CatalogException CatalogException::MissingEntry(const string &type, const string &name, diff --git a/src/duckdb/src/common/file_system.cpp b/src/duckdb/src/common/file_system.cpp index e109efbee..fbcf0cede 100644 --- a/src/duckdb/src/common/file_system.cpp +++ b/src/duckdb/src/common/file_system.cpp @@ -399,11 +399,6 @@ time_t FileSystem::GetLastModifiedTime(FileHandle &handle) { throw NotImplementedException("%s: GetLastModifiedTime is not implemented!", GetName()); } -string FileSystem::GetVersionTag(FileHandle &handle) { - // Used to check cache invalidation for httpfs files with an ETag in CachingFileSystem - return ""; -} - FileType FileSystem::GetFileType(FileHandle &handle) { return FileType::FILE_TYPE_INVALID; } @@ -479,10 +474,6 @@ void FileSystem::UnregisterSubSystem(const string &name) { throw NotImplementedException("%s: Can't unregister a sub system on a non-virtual file system", GetName()); } -unique_ptr FileSystem::ExtractSubSystem(const string &name) { - throw NotImplementedException("%s: Can't extract a sub system on a non-virtual file system", GetName()); -} - void FileSystem::SetDisabledFileSystems(const vector &names) { throw NotImplementedException("%s: Can't disable file systems on a non-virtual file system", GetName()); } diff --git a/src/duckdb/src/common/fsst.cpp b/src/duckdb/src/common/fsst.cpp index d4a0aca7b..1e28ad5ab 100644 --- a/src/duckdb/src/common/fsst.cpp +++ b/src/duckdb/src/common/fsst.cpp @@ -1,11 +1,30 @@ +#include "duckdb/storage/string_uncompressed.hpp" +#include "duckdb/common/types/value.hpp" #include "duckdb/common/fsst.hpp" +#include "fsst.h" namespace duckdb { +string_t FSSTPrimitives::DecompressValue(void *duckdb_fsst_decoder, Vector &result, const char *compressed_string, + const idx_t compressed_string_len, vector &decompress_buffer) { + + D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR); + auto fsst_decoder = reinterpret_cast(duckdb_fsst_decoder); + auto compressed_string_ptr = (unsigned char *)compressed_string; // NOLINT + auto decompressed_string_size = duckdb_fsst_decompress(fsst_decoder, compressed_string_len, compressed_string_ptr, + decompress_buffer.size(), decompress_buffer.data()); + + D_ASSERT(!decompress_buffer.empty()); + D_ASSERT(decompressed_string_size <= decompress_buffer.size() - 1); + return StringVector::AddStringOrBlob(result, const_char_ptr_cast(decompress_buffer.data()), + decompressed_string_size); +} + string FSSTPrimitives::DecompressValue(void *duckdb_fsst_decoder, const char *compressed_string, const idx_t compressed_string_len, vector &decompress_buffer) { - auto compressed_string_ptr = reinterpret_cast(compressed_string); - auto fsst_decoder = static_cast(duckdb_fsst_decoder); + + auto compressed_string_ptr = (unsigned char *)compressed_string; // NOLINT + auto fsst_decoder = reinterpret_cast(duckdb_fsst_decoder); auto decompressed_string_size = duckdb_fsst_decompress(fsst_decoder, compressed_string_len, compressed_string_ptr, decompress_buffer.size(), decompress_buffer.data()); diff --git a/src/duckdb/src/common/hive_partitioning.cpp b/src/duckdb/src/common/hive_partitioning.cpp index 97f6abdbc..dc13c8724 100644 --- a/src/duckdb/src/common/hive_partitioning.cpp +++ b/src/duckdb/src/common/hive_partitioning.cpp @@ -7,7 +7,7 @@ #include "duckdb/planner/expression/bound_reference_expression.hpp" #include "duckdb/planner/expression_iterator.hpp" #include "duckdb/planner/table_filter.hpp" -#include "duckdb/common/multi_file/multi_file_list.hpp" +#include "duckdb/common/multi_file_list.hpp" namespace duckdb { diff --git a/src/duckdb/src/common/local_file_system.cpp b/src/duckdb/src/common/local_file_system.cpp index 731bccf2a..751da9f5a 100644 --- a/src/duckdb/src/common/local_file_system.cpp +++ b/src/duckdb/src/common/local_file_system.cpp @@ -433,7 +433,7 @@ unique_ptr LocalFileSystem::OpenFile(const string &path_p, FileOpenF if (rc == -1) { extended_error += ". Also, failed closing file"; } - extended_error += ". See also https://duckdb.org/docs/stable/connect/concurrency"; + extended_error += ". See also https://duckdb.org/docs/connect/concurrency"; throw IOException("Could not set lock on file \"%s\": %s", {{"errno", std::to_string(retained_errno)}}, path, extended_error); } diff --git a/src/duckdb/src/common/multi_file_list.cpp b/src/duckdb/src/common/multi_file_list.cpp new file mode 100644 index 000000000..668a5b363 --- /dev/null +++ b/src/duckdb/src/common/multi_file_list.cpp @@ -0,0 +1,379 @@ +#include "duckdb/common/multi_file_reader.hpp" + +#include "duckdb/common/exception.hpp" +#include "duckdb/common/hive_partitioning.hpp" +#include "duckdb/common/types.hpp" +#include "duckdb/function/function_set.hpp" +#include "duckdb/function/table_function.hpp" +#include "duckdb/main/config.hpp" +#include "duckdb/planner/operator/logical_get.hpp" +#include "duckdb/common/string_util.hpp" + +#include + +namespace duckdb { + +MultiFilePushdownInfo::MultiFilePushdownInfo(LogicalGet &get) + : table_index(get.table_index), column_names(get.names), column_indexes(get.GetColumnIds()), + extra_info(get.extra_info) { + for (auto &col_id : column_indexes) { + column_ids.push_back(col_id.GetPrimaryIndex()); + } +} + +MultiFilePushdownInfo::MultiFilePushdownInfo(idx_t table_index, const vector &column_names, + const vector &column_ids, ExtraOperatorInfo &extra_info) + : table_index(table_index), column_names(column_names), column_ids(column_ids), extra_info(extra_info) { +} + +// Helper method to do Filter Pushdown into a MultiFileList +bool PushdownInternal(ClientContext &context, const MultiFileReaderOptions &options, MultiFilePushdownInfo &info, + vector> &filters, vector &expanded_files) { + HivePartitioningFilterInfo filter_info; + for (idx_t i = 0; i < info.column_ids.size(); i++) { + if (!IsRowIdColumnId(info.column_ids[i])) { + filter_info.column_map.insert({info.column_names[info.column_ids[i]], i}); + } + } + filter_info.hive_enabled = options.hive_partitioning; + filter_info.filename_enabled = options.filename; + + auto start_files = expanded_files.size(); + HivePartitioning::ApplyFiltersToFileList(context, expanded_files, filters, filter_info, info); + + if (expanded_files.size() != start_files) { + return true; + } + + return false; +} + +bool PushdownInternal(ClientContext &context, const MultiFileReaderOptions &options, const vector &names, + const vector &types, const vector &column_ids, + const TableFilterSet &filters, vector &expanded_files) { + idx_t table_index = 0; + ExtraOperatorInfo extra_info; + + // construct the pushdown info + MultiFilePushdownInfo info(table_index, names, column_ids, extra_info); + + // construct the set of expressions from the table filters + vector> filter_expressions; + for (auto &entry : filters.filters) { + auto column_idx = column_ids[entry.first]; + auto column_ref = + make_uniq(types[column_idx], ColumnBinding(table_index, entry.first)); + auto filter_expr = entry.second->ToExpression(*column_ref); + filter_expressions.push_back(std::move(filter_expr)); + } + + // call the original PushdownInternal method + return PushdownInternal(context, options, info, filter_expressions, expanded_files); +} + +//===--------------------------------------------------------------------===// +// MultiFileListIterator +//===--------------------------------------------------------------------===// +MultiFileListIterationHelper MultiFileList::Files() { + return MultiFileListIterationHelper(*this); +} + +MultiFileListIterationHelper::MultiFileListIterationHelper(MultiFileList &file_list_p) : file_list(file_list_p) { +} + +MultiFileListIterationHelper::MultiFileListIterator::MultiFileListIterator(MultiFileList *file_list_p) + : file_list(file_list_p) { + if (!file_list) { + return; + } + + file_list->InitializeScan(file_scan_data); + if (!file_list->Scan(file_scan_data, current_file)) { + // There is no first file: move iterator to nop state + file_list = nullptr; + file_scan_data.current_file_idx = DConstants::INVALID_INDEX; + } +} + +void MultiFileListIterationHelper::MultiFileListIterator::Next() { + if (!file_list) { + return; + } + + if (!file_list->Scan(file_scan_data, current_file)) { + // exhausted collection: move iterator to nop state + file_list = nullptr; + file_scan_data.current_file_idx = DConstants::INVALID_INDEX; + } +} + +MultiFileListIterationHelper::MultiFileListIterator MultiFileListIterationHelper::begin() { // NOLINT: match stl API + return MultiFileListIterationHelper::MultiFileListIterator( + file_list.GetExpandResult() == FileExpandResult::NO_FILES ? nullptr : &file_list); +} +MultiFileListIterationHelper::MultiFileListIterator MultiFileListIterationHelper::end() { // NOLINT: match stl API + return MultiFileListIterationHelper::MultiFileListIterator(nullptr); +} + +MultiFileListIterationHelper::MultiFileListIterator &MultiFileListIterationHelper::MultiFileListIterator::operator++() { + Next(); + return *this; +} + +bool MultiFileListIterationHelper::MultiFileListIterator::operator!=(const MultiFileListIterator &other) const { + return file_list != other.file_list || file_scan_data.current_file_idx != other.file_scan_data.current_file_idx; +} + +const string &MultiFileListIterationHelper::MultiFileListIterator::operator*() const { + return current_file; +} + +//===--------------------------------------------------------------------===// +// MultiFileList +//===--------------------------------------------------------------------===// +MultiFileList::MultiFileList(vector paths, FileGlobOptions options) + : paths(std::move(paths)), glob_options(options) { +} + +MultiFileList::~MultiFileList() { +} + +const vector MultiFileList::GetPaths() const { + return paths; +} + +void MultiFileList::InitializeScan(MultiFileListScanData &iterator) { + iterator.current_file_idx = 0; +} + +bool MultiFileList::Scan(MultiFileListScanData &iterator, string &result_file) { + D_ASSERT(iterator.current_file_idx != DConstants::INVALID_INDEX); + auto maybe_file = GetFile(iterator.current_file_idx); + + if (maybe_file.empty()) { + D_ASSERT(iterator.current_file_idx >= GetTotalFileCount()); + return false; + } + + result_file = maybe_file; + iterator.current_file_idx++; + return true; +} + +unique_ptr MultiFileList::ComplexFilterPushdown(ClientContext &context, + const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters) { + // By default the filter pushdown into a multifilelist does nothing + return nullptr; +} + +unique_ptr +MultiFileList::DynamicFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, + const vector &names, const vector &types, + const vector &column_ids, TableFilterSet &filters) const { + // By default the filter pushdown into a multifilelist does nothing + return nullptr; +} + +unique_ptr MultiFileList::GetCardinality(ClientContext &context) { + return nullptr; +} + +string MultiFileList::GetFirstFile() { + return GetFile(0); +} + +bool MultiFileList::IsEmpty() { + return GetExpandResult() == FileExpandResult::NO_FILES; +} + +//===--------------------------------------------------------------------===// +// SimpleMultiFileList +//===--------------------------------------------------------------------===// +SimpleMultiFileList::SimpleMultiFileList(vector paths_p) + : MultiFileList(std::move(paths_p), FileGlobOptions::ALLOW_EMPTY) { +} + +unique_ptr SimpleMultiFileList::ComplexFilterPushdown(ClientContext &context_p, + const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters) { + if (!options.hive_partitioning && !options.filename) { + return nullptr; + } + + // FIXME: don't copy list until first file is filtered + auto file_copy = paths; + auto res = PushdownInternal(context_p, options, info, filters, file_copy); + + if (res) { + return make_uniq(file_copy); + } + + return nullptr; +} + +unique_ptr +SimpleMultiFileList::DynamicFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, + const vector &names, const vector &types, + const vector &column_ids, TableFilterSet &filters) const { + if (!options.hive_partitioning && !options.filename) { + return nullptr; + } + + // FIXME: don't copy list until first file is filtered + auto file_copy = paths; + auto res = PushdownInternal(context, options, names, types, column_ids, filters, file_copy); + if (res) { + return make_uniq(file_copy); + } + + return nullptr; +} + +vector SimpleMultiFileList::GetAllFiles() { + return paths; +} + +FileExpandResult SimpleMultiFileList::GetExpandResult() { + if (paths.size() > 1) { + return FileExpandResult::MULTIPLE_FILES; + } else if (paths.size() == 1) { + return FileExpandResult::SINGLE_FILE; + } + + return FileExpandResult::NO_FILES; +} + +string SimpleMultiFileList::GetFile(idx_t i) { + if (paths.empty() || i >= paths.size()) { + return ""; + } + + return paths[i]; +} + +idx_t SimpleMultiFileList::GetTotalFileCount() { + return paths.size(); +} + +//===--------------------------------------------------------------------===// +// GlobMultiFileList +//===--------------------------------------------------------------------===// +GlobMultiFileList::GlobMultiFileList(ClientContext &context_p, vector paths_p, FileGlobOptions options) + : MultiFileList(std::move(paths_p), options), context(context_p), current_path(0) { +} + +unique_ptr GlobMultiFileList::ComplexFilterPushdown(ClientContext &context_p, + const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters) { + lock_guard lck(lock); + + // Expand all + // FIXME: lazy expansion + // FIXME: push down filters into glob + while (ExpandNextPath()) { + } + + if (!options.hive_partitioning && !options.filename) { + return nullptr; + } + auto res = PushdownInternal(context, options, info, filters, expanded_files); + if (res) { + return make_uniq(expanded_files); + } + + return nullptr; +} + +unique_ptr +GlobMultiFileList::DynamicFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, + const vector &names, const vector &types, + const vector &column_ids, TableFilterSet &filters) const { + if (!options.hive_partitioning && !options.filename) { + return nullptr; + } + lock_guard lck(lock); + + // Expand all paths into a copy + // FIXME: lazy expansion and push filters into glob + idx_t path_index = current_path; + auto file_list = expanded_files; + while (ExpandPathInternal(path_index, file_list)) { + } + + auto res = PushdownInternal(context, options, names, types, column_ids, filters, file_list); + if (res) { + return make_uniq(file_list); + } + + return nullptr; +} + +vector GlobMultiFileList::GetAllFiles() { + lock_guard lck(lock); + while (ExpandNextPath()) { + } + return expanded_files; +} + +idx_t GlobMultiFileList::GetTotalFileCount() { + lock_guard lck(lock); + while (ExpandNextPath()) { + } + return expanded_files.size(); +} + +FileExpandResult GlobMultiFileList::GetExpandResult() { + // GetFile(1) will ensure at least the first 2 files are expanded if they are available + GetFile(1); + + if (expanded_files.size() > 1) { + return FileExpandResult::MULTIPLE_FILES; + } else if (expanded_files.size() == 1) { + return FileExpandResult::SINGLE_FILE; + } + + return FileExpandResult::NO_FILES; +} + +string GlobMultiFileList::GetFile(idx_t i) { + lock_guard lck(lock); + return GetFileInternal(i); +} + +string GlobMultiFileList::GetFileInternal(idx_t i) { + while (expanded_files.size() <= i) { + if (!ExpandNextPath()) { + return ""; + } + } + D_ASSERT(expanded_files.size() > i); + return expanded_files[i]; +} + +bool GlobMultiFileList::ExpandPathInternal(idx_t ¤t_path, vector &result) const { + if (current_path >= paths.size()) { + return false; + } + + auto &fs = FileSystem::GetFileSystem(context); + auto glob_files = fs.GlobFiles(paths[current_path], context, glob_options); + std::sort(glob_files.begin(), glob_files.end()); + result.insert(result.end(), glob_files.begin(), glob_files.end()); + + current_path++; + return true; +} + +bool GlobMultiFileList::ExpandNextPath() { + return ExpandPathInternal(current_path, expanded_files); +} + +bool GlobMultiFileList::IsFullyExpanded() const { + return current_path == paths.size(); +} + +} // namespace duckdb diff --git a/src/duckdb/src/common/multi_file_reader.cpp b/src/duckdb/src/common/multi_file_reader.cpp new file mode 100644 index 000000000..be17aaf95 --- /dev/null +++ b/src/duckdb/src/common/multi_file_reader.cpp @@ -0,0 +1,746 @@ +#include "duckdb/common/multi_file_reader.hpp" + +#include "duckdb/common/exception.hpp" +#include "duckdb/common/hive_partitioning.hpp" +#include "duckdb/common/types.hpp" +#include "duckdb/common/types/value.hpp" +#include "duckdb/function/function_set.hpp" +#include "duckdb/function/table_function.hpp" +#include "duckdb/main/config.hpp" +#include "duckdb/planner/expression/bound_columnref_expression.hpp" +#include "duckdb/parser/expression/constant_expression.hpp" +#include "duckdb/common/string_util.hpp" + +#include + +namespace duckdb { + +MultiFileReaderGlobalState::~MultiFileReaderGlobalState() { +} + +MultiFileReader::~MultiFileReader() { +} + +unique_ptr MultiFileReader::Create(const TableFunction &table_function) { + unique_ptr res; + if (table_function.get_multi_file_reader) { + res = table_function.get_multi_file_reader(table_function); + res->function_name = table_function.name; + } else { + res = make_uniq(); + res->function_name = table_function.name; + } + return res; +} + +unique_ptr MultiFileReader::CreateDefault(const string &function_name) { + auto res = make_uniq(); + res->function_name = function_name; + return res; +} + +Value MultiFileReader::CreateValueFromFileList(const vector &file_list) { + vector files; + for (auto &file : file_list) { + files.push_back(file); + } + return Value::LIST(LogicalType::VARCHAR, std::move(files)); +} + +void MultiFileReader::AddParameters(TableFunction &table_function) { + table_function.named_parameters["filename"] = LogicalType::ANY; + table_function.named_parameters["hive_partitioning"] = LogicalType::BOOLEAN; + table_function.named_parameters["union_by_name"] = LogicalType::BOOLEAN; + table_function.named_parameters["hive_types"] = LogicalType::ANY; + table_function.named_parameters["hive_types_autocast"] = LogicalType::BOOLEAN; +} + +vector MultiFileReader::ParsePaths(const Value &input) { + if (input.IsNull()) { + throw ParserException("%s cannot take NULL list as parameter", function_name); + } + + if (input.type().id() == LogicalTypeId::VARCHAR) { + return {StringValue::Get(input)}; + } else if (input.type().id() == LogicalTypeId::LIST) { + vector paths; + for (auto &val : ListValue::GetChildren(input)) { + if (val.IsNull()) { + throw ParserException("%s reader cannot take NULL input as parameter", function_name); + } + if (val.type().id() != LogicalTypeId::VARCHAR) { + throw ParserException("%s reader can only take a list of strings as a parameter", function_name); + } + paths.push_back(StringValue::Get(val)); + } + return paths; + } else { + throw InternalException("Unsupported type for MultiFileReader::ParsePaths called with: '%s'"); + } +} + +shared_ptr MultiFileReader::CreateFileList(ClientContext &context, const vector &paths, + FileGlobOptions options) { + vector result_files; + + auto res = make_uniq(context, paths, options); + if (res->GetExpandResult() == FileExpandResult::NO_FILES && options == FileGlobOptions::DISALLOW_EMPTY) { + throw IOException("%s needs at least one file to read", function_name); + } + return std::move(res); +} + +shared_ptr MultiFileReader::CreateFileList(ClientContext &context, const Value &input, + FileGlobOptions options) { + auto paths = ParsePaths(input); + return CreateFileList(context, paths, options); +} + +bool MultiFileReader::ParseOption(const string &key, const Value &val, MultiFileReaderOptions &options, + ClientContext &context) { + auto loption = StringUtil::Lower(key); + if (loption == "filename") { + if (val.type() == LogicalType::VARCHAR) { + // If not, we interpret it as the name of the column containing the filename + options.filename = true; + options.filename_column = StringValue::Get(val); + } else { + Value boolean_value; + string error_message; + if (val.DefaultTryCastAs(LogicalType::BOOLEAN, boolean_value, &error_message)) { + // If the argument can be cast to boolean, we just interpret it as a boolean + options.filename = BooleanValue::Get(boolean_value); + } + } + } else if (loption == "hive_partitioning") { + options.hive_partitioning = BooleanValue::Get(val); + options.auto_detect_hive_partitioning = false; + } else if (loption == "union_by_name") { + options.union_by_name = BooleanValue::Get(val); + } else if (loption == "hive_types_autocast" || loption == "hive_type_autocast") { + options.hive_types_autocast = BooleanValue::Get(val); + } else if (loption == "hive_types" || loption == "hive_type") { + if (val.type().id() != LogicalTypeId::STRUCT) { + throw InvalidInputException( + "'hive_types' only accepts a STRUCT('name':VARCHAR, ...), but '%s' was provided", + val.type().ToString()); + } + // verify that all the children of the struct value are VARCHAR + auto &children = StructValue::GetChildren(val); + for (idx_t i = 0; i < children.size(); i++) { + const Value &child = children[i]; + if (child.type().id() != LogicalType::VARCHAR) { + throw InvalidInputException("hive_types: '%s' must be a VARCHAR, instead: '%s' was provided", + StructType::GetChildName(val.type(), i), child.type().ToString()); + } + // for every child of the struct, get the logical type + LogicalType transformed_type = TransformStringToLogicalType(child.ToString(), context); + const string &name = StructType::GetChildName(val.type(), i); + options.hive_types_schema[name] = transformed_type; + } + D_ASSERT(!options.hive_types_schema.empty()); + } else { + return false; + } + return true; +} + +unique_ptr MultiFileReader::ComplexFilterPushdown(ClientContext &context, MultiFileList &files, + const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters) { + return files.ComplexFilterPushdown(context, options, info, filters); +} + +unique_ptr MultiFileReader::DynamicFilterPushdown(ClientContext &context, const MultiFileList &files, + const MultiFileReaderOptions &options, + const vector &names, + const vector &types, + const vector &column_ids, + TableFilterSet &filters) { + return files.DynamicFilterPushdown(context, options, names, types, column_ids, filters); +} + +bool MultiFileReader::Bind(MultiFileReaderOptions &options, MultiFileList &files, vector &return_types, + vector &names, MultiFileReaderBindData &bind_data) { + // The Default MultiFileReader can not perform any binding as it uses MultiFileLists with no schema information. + return false; +} + +void MultiFileReader::BindOptions(MultiFileReaderOptions &options, MultiFileList &files, + vector &return_types, vector &names, + MultiFileReaderBindData &bind_data) { + // Add generated constant column for filename + if (options.filename) { + if (std::find(names.begin(), names.end(), options.filename_column) != names.end()) { + throw BinderException("Option filename adds column \"%s\", but a column with this name is also in the " + "file. Try setting a different name: filename=''", + options.filename_column); + } + bind_data.filename_idx = names.size(); + return_types.emplace_back(LogicalType::VARCHAR); + names.emplace_back(options.filename_column); + } + + // Add generated constant columns from hive partitioning scheme + if (options.hive_partitioning) { + D_ASSERT(files.GetExpandResult() != FileExpandResult::NO_FILES); + auto partitions = HivePartitioning::Parse(files.GetFirstFile()); + // verify that all files have the same hive partitioning scheme + for (const auto &file : files.Files()) { + auto file_partitions = HivePartitioning::Parse(file); + for (auto &part_info : partitions) { + if (file_partitions.find(part_info.first) == file_partitions.end()) { + string error = "Hive partition mismatch between file \"%s\" and \"%s\": key \"%s\" not found"; + if (options.auto_detect_hive_partitioning == true) { + throw InternalException(error + "(hive partitioning was autodetected)", files.GetFirstFile(), + file, part_info.first); + } + throw BinderException(error.c_str(), files.GetFirstFile(), file, part_info.first); + } + } + if (partitions.size() != file_partitions.size()) { + string error_msg = "Hive partition mismatch between file \"%s\" and \"%s\""; + if (options.auto_detect_hive_partitioning == true) { + throw InternalException(error_msg + "(hive partitioning was autodetected)", files.GetFirstFile(), + file); + } + throw BinderException(error_msg.c_str(), files.GetFirstFile(), file); + } + } + + if (!options.hive_types_schema.empty()) { + // verify that all hive_types are existing partitions + options.VerifyHiveTypesArePartitions(partitions); + } + + for (auto &part : partitions) { + idx_t hive_partitioning_index; + auto lookup = std::find_if(names.begin(), names.end(), [&](const string &col_name) { + return StringUtil::CIEquals(col_name, part.first); + }); + if (lookup != names.end()) { + // hive partitioning column also exists in file - override + auto idx = NumericCast(lookup - names.begin()); + hive_partitioning_index = idx; + return_types[idx] = options.GetHiveLogicalType(part.first); + } else { + // hive partitioning column does not exist in file - add a new column containing the key + hive_partitioning_index = names.size(); + return_types.emplace_back(options.GetHiveLogicalType(part.first)); + names.emplace_back(part.first); + } + bind_data.hive_partitioning_indexes.emplace_back(part.first, hive_partitioning_index); + } + } +} + +void MultiFileReader::FinalizeBind(const MultiFileReaderOptions &file_options, const MultiFileReaderBindData &options, + const string &filename, const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, MultiFileReaderData &reader_data, + ClientContext &context, optional_ptr global_state) { + + // create a map of name -> column index + case_insensitive_map_t name_map; + if (file_options.union_by_name) { + for (idx_t col_idx = 0; col_idx < local_columns.size(); col_idx++) { + auto &column = local_columns[col_idx]; + name_map[column.name] = col_idx; + } + } + for (idx_t i = 0; i < global_column_ids.size(); i++) { + auto &col_idx = global_column_ids[i]; + if (col_idx.IsRowIdColumn()) { + // row-id + reader_data.constant_map.emplace_back(i, Value::BIGINT(42)); + continue; + } + auto column_id = col_idx.GetPrimaryIndex(); + if (column_id == options.filename_idx) { + // filename + reader_data.constant_map.emplace_back(i, Value(filename)); + continue; + } + if (!options.hive_partitioning_indexes.empty()) { + // hive partition constants + auto partitions = HivePartitioning::Parse(filename); + D_ASSERT(partitions.size() == options.hive_partitioning_indexes.size()); + bool found_partition = false; + for (auto &entry : options.hive_partitioning_indexes) { + if (column_id == entry.index) { + Value value = file_options.GetHivePartitionValue(partitions[entry.value], entry.value, context); + reader_data.constant_map.emplace_back(i, value); + found_partition = true; + break; + } + } + if (found_partition) { + continue; + } + } + if (file_options.union_by_name) { + auto &column = global_columns[column_id]; + auto &name = column.name; + auto &type = column.type; + + auto entry = name_map.find(name); + bool not_present_in_file = entry == name_map.end(); + if (not_present_in_file) { + // we need to project a column with name \"global_name\" - but it does not exist in the current file + // push a NULL value of the specified type + reader_data.constant_map.emplace_back(i, Value(type)); + continue; + } + } + } +} + +unique_ptr +MultiFileReader::InitializeGlobalState(ClientContext &context, const MultiFileReaderOptions &file_options, + const MultiFileReaderBindData &bind_data, const MultiFileList &file_list, + const vector &global_columns, + const vector &global_column_ids) { + // By default, the multifilereader does not require any global state + return nullptr; +} + +void MultiFileReader::CreateColumnMappingByName(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, + MultiFileReaderData &reader_data, + const MultiFileReaderBindData &bind_data, const string &initial_file, + optional_ptr global_state) { + + // we have expected types: create a map of name -> column index + case_insensitive_map_t name_map; + for (idx_t col_idx = 0; col_idx < local_columns.size(); col_idx++) { + auto &column = local_columns[col_idx]; + name_map[column.name] = col_idx; + } + for (idx_t i = 0; i < global_column_ids.size(); i++) { + // check if this is a constant column + bool constant = false; + for (auto &entry : reader_data.constant_map) { + if (entry.column_id == i) { + constant = true; + break; + } + } + if (constant) { + // this column is constant for this file + continue; + } + // not constant - look up the column in the name map + auto &global_idx = global_column_ids[i]; + auto global_id = global_idx.GetPrimaryIndex(); + if (global_id >= global_columns.size()) { + throw InternalException( + "MultiFileReader::CreateColumnMappingByName - global_id is out of range in global_types for this file"); + } + auto &global_column = global_columns[global_id]; + auto identifier = global_column.GetIdentifierName(); + auto entry = name_map.find(identifier); + if (entry == name_map.end()) { + // identiier not present in file, use default value + if (global_column.default_expression) { + reader_data.constant_map.emplace_back(i, global_column.GetDefaultValue()); + continue; + } else { + string candidate_names; + for (auto &column : local_columns) { + if (!candidate_names.empty()) { + candidate_names += ", "; + } + candidate_names += column.name; + } + throw IOException(StringUtil::Format( + "Failed to read file \"%s\": schema mismatch in glob: column \"%s\" was read from " + "the original file \"%s\", but could not be found in file \"%s\".\nCandidate names: " + "%s\nIf you are trying to " + "read files with different schemas, try setting union_by_name=True", + file_name, identifier, initial_file, file_name, candidate_names)); + } + } + // we found the column in the local file - check if the types are the same + auto local_id = entry->second; + D_ASSERT(global_id < global_columns.size()); + D_ASSERT(local_id < local_columns.size()); + auto &global_type = global_columns[global_id].type; + auto &local_type = local_columns[local_id].type; + ColumnIndex local_index(local_id); + if (global_type != local_type) { + // the types are not the same - add a cast + reader_data.cast_map[local_id] = global_type; + } else { + local_index = ColumnIndex(local_id, global_idx.GetChildIndexes()); + } + // create the mapping + reader_data.column_mapping.push_back(i); + reader_data.column_ids.push_back(local_id); + reader_data.column_indexes.push_back(std::move(local_index)); + } + + reader_data.empty_columns = reader_data.column_indexes.empty(); +} + +void MultiFileReader::CreateColumnMappingByFieldId(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, + MultiFileReaderData &reader_data, + const MultiFileReaderBindData &bind_data, const string &initial_file, + optional_ptr global_state) { +#ifdef DEBUG + //! Make sure the global columns have field_ids to match on + for (auto &column : global_columns) { + D_ASSERT(!column.identifier.IsNull()); + D_ASSERT(column.identifier.type().id() == LogicalTypeId::INTEGER); + } +#endif + + // we have expected types: create a map of field_id -> column index + unordered_map field_id_map; + for (idx_t col_idx = 0; col_idx < local_columns.size(); col_idx++) { + auto &column = local_columns[col_idx]; + if (column.identifier.IsNull()) { + // Extra columns at the end will not have a field_id + break; + } + auto field_id = column.GetIdentifierFieldId(); + field_id_map[field_id] = col_idx; + } + + // loop through the schema definition + for (idx_t i = 0; i < global_column_ids.size(); i++) { + + // check if this is a constant column + bool constant = false; + for (auto &entry : reader_data.constant_map) { + if (entry.column_id == i) { + constant = true; + break; + } + } + if (constant) { + // this column is constant for this file + continue; + } + + // Handle any generate columns that are not in the schema (currently only file_row_number) + auto &global_idx = global_column_ids[i]; + auto global_id = global_column_ids[i].GetPrimaryIndex(); + if (global_id >= global_columns.size()) { + if (bind_data.file_row_number_idx == global_id) { + reader_data.column_mapping.push_back(i); + // FIXME: this needs a more extensible solution + reader_data.column_ids.push_back(field_id_map.size()); + } else { + throw InternalException("Unexpected generated column"); + } + continue; + } + + const auto &global_column = global_columns[global_id]; + D_ASSERT(!global_column.identifier.IsNull()); + auto it = field_id_map.find(global_column.GetIdentifierFieldId()); + if (it == field_id_map.end()) { + // field id not present in file, use default value + auto &default_val = global_column.default_expression; + D_ASSERT(default_val); + if (default_val->type != ExpressionType::VALUE_CONSTANT) { + throw NotImplementedException("Default expression that isn't constant is not supported yet"); + } + auto &constant_expr = default_val->Cast(); + reader_data.constant_map.emplace_back(i, constant_expr.value); + continue; + } + + const auto &local_id = it->second; + auto &local_column = local_columns[local_id]; + ColumnIndex local_index(local_id); + if (local_column.type != global_column.type) { + // differing types, wrap in a cast column reader + reader_data.cast_map[local_id] = global_column.type; + } else { + local_index = ColumnIndex(local_id, global_idx.GetChildIndexes()); + } + + reader_data.column_mapping.push_back(i); + reader_data.column_ids.push_back(local_id); + reader_data.column_indexes.push_back(std::move(local_index)); + } + reader_data.empty_columns = reader_data.column_ids.empty(); +} + +void MultiFileReader::CreateColumnMapping(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, + MultiFileReaderData &reader_data, const MultiFileReaderBindData &bind_data, + const string &initial_file, + optional_ptr global_state) { + switch (bind_data.mapping) { + case MultiFileReaderColumnMappingMode::BY_NAME: { + CreateColumnMappingByName(file_name, local_columns, global_columns, global_column_ids, reader_data, bind_data, + initial_file, global_state); + break; + } + case MultiFileReaderColumnMappingMode::BY_FIELD_ID: { + CreateColumnMappingByFieldId(file_name, local_columns, global_columns, global_column_ids, reader_data, + bind_data, initial_file, global_state); + break; + } + default: { + throw InternalException("Unsupported MultiFileReaderColumnMappingMode type"); + } + } +} + +void MultiFileReader::CreateMapping(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, optional_ptr filters, + MultiFileReaderData &reader_data, const string &initial_file, + const MultiFileReaderBindData &bind_data, + optional_ptr global_state) { + // copy global columns and inject any different defaults + CreateColumnMapping(file_name, local_columns, global_columns, global_column_ids, reader_data, bind_data, + initial_file, global_state); + CreateFilterMap(global_column_ids, filters, reader_data, global_state); +} + +void MultiFileReader::CreateFilterMap(const vector &global_column_ids, + optional_ptr filters, MultiFileReaderData &reader_data, + optional_ptr global_state) { + if (filters) { + auto filter_map_size = global_column_ids.size(); + if (global_state) { + filter_map_size += global_state->extra_columns.size(); + } + reader_data.filter_map.resize(filter_map_size); + + for (idx_t c = 0; c < reader_data.column_mapping.size(); c++) { + auto map_index = reader_data.column_mapping[c]; + reader_data.filter_map[map_index].index = c; + reader_data.filter_map[map_index].is_constant = false; + } + for (idx_t c = 0; c < reader_data.constant_map.size(); c++) { + auto constant_index = reader_data.constant_map[c].column_id; + reader_data.filter_map[constant_index].index = c; + reader_data.filter_map[constant_index].is_constant = true; + } + } +} + +void MultiFileReader::FinalizeChunk(ClientContext &context, const MultiFileReaderBindData &bind_data, + const MultiFileReaderData &reader_data, DataChunk &chunk, + optional_ptr global_state) { + // reference all the constants set up in MultiFileReader::FinalizeBind + for (auto &entry : reader_data.constant_map) { + chunk.data[entry.column_id].Reference(entry.value); + } + chunk.Verify(); +} + +void MultiFileReader::GetPartitionData(ClientContext &context, const MultiFileReaderBindData &bind_data, + const MultiFileReaderData &reader_data, + optional_ptr global_state, + const OperatorPartitionInfo &partition_info, + OperatorPartitionData &partition_data) { + for (auto &col : partition_info.partition_columns) { + bool found_constant = false; + for (auto &constant : reader_data.constant_map) { + if (constant.column_id == col) { + found_constant = true; + partition_data.partition_data.emplace_back(constant.value); + break; + } + } + if (!found_constant) { + throw InternalException( + "MultiFileReader::GetPartitionData - did not find constant for the given partition"); + } + } +} + +TablePartitionInfo MultiFileReader::GetPartitionInfo(ClientContext &context, const MultiFileReaderBindData &bind_data, + TableFunctionPartitionInput &input) { + // check if all of the columns are in the hive partition set + for (auto &partition_col : input.partition_ids) { + // check if this column is in the hive partitioned set + bool found = false; + for (auto &partition : bind_data.hive_partitioning_indexes) { + if (partition.index == partition_col) { + found = true; + break; + } + } + if (!found) { + // the column is not partitioned - hive partitioning alone can't guarantee the groups are partitioned + return TablePartitionInfo::NOT_PARTITIONED; + } + } + // if all columns are in the hive partitioning set, we know that each partition will only have a single value + // i.e. if the hive partitioning is by (YEAR, MONTH), each partition will have a single unique (YEAR, MONTH) + return TablePartitionInfo::SINGLE_VALUE_PARTITIONS; +} + +TableFunctionSet MultiFileReader::CreateFunctionSet(TableFunction table_function) { + TableFunctionSet function_set(table_function.name); + function_set.AddFunction(table_function); + D_ASSERT(table_function.arguments.size() >= 1 && table_function.arguments[0] == LogicalType::VARCHAR); + table_function.arguments[0] = LogicalType::LIST(LogicalType::VARCHAR); + function_set.AddFunction(std::move(table_function)); + return function_set; +} + +HivePartitioningIndex::HivePartitioningIndex(string value_p, idx_t index) : value(std::move(value_p)), index(index) { +} + +void MultiFileReaderOptions::AddBatchInfo(BindInfo &bind_info) const { + bind_info.InsertOption("filename", Value(filename_column)); + bind_info.InsertOption("hive_partitioning", Value::BOOLEAN(hive_partitioning)); + bind_info.InsertOption("auto_detect_hive_partitioning", Value::BOOLEAN(auto_detect_hive_partitioning)); + bind_info.InsertOption("union_by_name", Value::BOOLEAN(union_by_name)); + bind_info.InsertOption("hive_types_autocast", Value::BOOLEAN(hive_types_autocast)); +} + +void UnionByName::CombineUnionTypes(const vector &col_names, const vector &sql_types, + vector &union_col_types, vector &union_col_names, + case_insensitive_map_t &union_names_map) { + D_ASSERT(col_names.size() == sql_types.size()); + + for (idx_t col = 0; col < col_names.size(); ++col) { + auto union_find = union_names_map.find(col_names[col]); + + if (union_find != union_names_map.end()) { + // given same name , union_col's type must compatible with col's type + auto ¤t_type = union_col_types[union_find->second]; + auto compatible_type = LogicalType::ForceMaxLogicalType(current_type, sql_types[col]); + union_col_types[union_find->second] = compatible_type; + } else { + union_names_map[col_names[col]] = union_col_names.size(); + union_col_names.emplace_back(col_names[col]); + union_col_types.emplace_back(sql_types[col]); + } + } +} + +bool MultiFileReaderOptions::AutoDetectHivePartitioningInternal(MultiFileList &files, ClientContext &context) { + auto first_file = files.GetFirstFile(); + auto partitions = HivePartitioning::Parse(first_file); + if (partitions.empty()) { + // no partitions found in first file + return false; + } + + for (const auto &file : files.Files()) { + auto new_partitions = HivePartitioning::Parse(file); + if (new_partitions.size() != partitions.size()) { + // partition count mismatch + return false; + } + for (auto &part : new_partitions) { + auto entry = partitions.find(part.first); + if (entry == partitions.end()) { + // differing partitions between files + return false; + } + } + } + return true; +} +void MultiFileReaderOptions::AutoDetectHiveTypesInternal(MultiFileList &files, ClientContext &context) { + const LogicalType candidates[] = {LogicalType::DATE, LogicalType::TIMESTAMP, LogicalType::BIGINT}; + + unordered_map detected_types; + for (const auto &file : files.Files()) { + auto partitions = HivePartitioning::Parse(file); + if (partitions.empty()) { + return; + } + + for (auto &part : partitions) { + const string &name = part.first; + if (hive_types_schema.find(name) != hive_types_schema.end()) { + // type was explicitly provided by the user + continue; + } + LogicalType detected_type = LogicalType::VARCHAR; + Value value(part.second); + for (auto &candidate : candidates) { + const bool success = value.TryCastAs(context, candidate, true); + if (success) { + detected_type = candidate; + break; + } + } + auto entry = detected_types.find(name); + if (entry == detected_types.end()) { + // type was not yet detected - insert it + detected_types.insert(make_pair(name, std::move(detected_type))); + } else { + // type was already detected - check if the type matches + // if not promote to VARCHAR + if (entry->second != detected_type) { + entry->second = LogicalType::VARCHAR; + } + } + } + } + for (auto &entry : detected_types) { + hive_types_schema.insert(make_pair(entry.first, std::move(entry.second))); + } +} +void MultiFileReaderOptions::AutoDetectHivePartitioning(MultiFileList &files, ClientContext &context) { + D_ASSERT(files.GetExpandResult() != FileExpandResult::NO_FILES); + const bool hp_explicitly_disabled = !auto_detect_hive_partitioning && !hive_partitioning; + const bool ht_enabled = !hive_types_schema.empty(); + if (hp_explicitly_disabled && ht_enabled) { + throw InvalidInputException("cannot disable hive_partitioning when hive_types is enabled"); + } + if (ht_enabled && auto_detect_hive_partitioning && !hive_partitioning) { + // hive_types flag implies hive_partitioning + hive_partitioning = true; + auto_detect_hive_partitioning = false; + } + if (auto_detect_hive_partitioning) { + hive_partitioning = AutoDetectHivePartitioningInternal(files, context); + } + if (hive_partitioning && hive_types_autocast) { + AutoDetectHiveTypesInternal(files, context); + } +} +void MultiFileReaderOptions::VerifyHiveTypesArePartitions(const std::map &partitions) const { + for (auto &hive_type : hive_types_schema) { + if (partitions.find(hive_type.first) == partitions.end()) { + throw InvalidInputException("Unknown hive_type: \"%s\" does not appear to be a partition", hive_type.first); + } + } +} +LogicalType MultiFileReaderOptions::GetHiveLogicalType(const string &hive_partition_column) const { + if (!hive_types_schema.empty()) { + auto it = hive_types_schema.find(hive_partition_column); + if (it != hive_types_schema.end()) { + return it->second; + } + } + return LogicalType::VARCHAR; +} + +bool MultiFileReaderOptions::AnySet() { + return filename || hive_partitioning || union_by_name; +} + +Value MultiFileReaderOptions::GetHivePartitionValue(const string &value, const string &key, + ClientContext &context) const { + auto it = hive_types_schema.find(key); + if (it == hive_types_schema.end()) { + return HivePartitioning::GetValue(context, key, value, LogicalType::VARCHAR); + } + return HivePartitioning::GetValue(context, key, value, it->second); +} + +} // namespace duckdb diff --git a/src/duckdb/src/common/operator/cast_operators.cpp b/src/duckdb/src/common/operator/cast_operators.cpp index 602c2e1c8..9742c6087 100644 --- a/src/duckdb/src/common/operator/cast_operators.cpp +++ b/src/duckdb/src/common/operator/cast_operators.cpp @@ -1556,7 +1556,6 @@ template <> bool TryCastErrorMessage::Operation(string_t input, timestamp_t &result, CastParameters ¶meters) { switch (Timestamp::TryConvertTimestamp(input.GetData(), input.GetSize(), result)) { case TimestampCastResult::SUCCESS: - case TimestampCastResult::STRICT_UTC: return true; case TimestampCastResult::ERROR_INCORRECT_FORMAT: HandleCastError::AssignError(Timestamp::FormatError(input), parameters); diff --git a/src/duckdb/src/common/radix_partitioning.cpp b/src/duckdb/src/common/radix_partitioning.cpp index 4b19a8819..8b091a803 100644 --- a/src/duckdb/src/common/radix_partitioning.cpp +++ b/src/duckdb/src/common/radix_partitioning.cpp @@ -83,34 +83,16 @@ idx_t RadixPartitioning::Select(Vector &hashes, const SelectionVector *sel, cons struct ComputePartitionIndicesFunctor { template - static void Operation(Vector &hashes, Vector &partition_indices, const idx_t original_count, - const SelectionVector &append_sel, const idx_t append_count) { + static void Operation(Vector &hashes, Vector &partition_indices, const SelectionVector &append_sel, + const idx_t append_count) { using CONSTANTS = RadixPartitioningConstants; - if (!append_sel.IsSet() || hashes.GetVectorType() == VectorType::CONSTANT_VECTOR) { - UnaryExecutor::Execute(hashes, partition_indices, append_count, + if (append_sel.IsSet()) { + auto hashes_sliced = Vector(hashes, append_sel, append_count); + UnaryExecutor::Execute(hashes_sliced, partition_indices, append_count, [&](hash_t hash) { return CONSTANTS::ApplyMask(hash); }); } else { - // We could just slice the "hashes" vector and use the UnaryExecutor - // But slicing a dictionary vector causes SelectionData to be allocated - // Instead, we just directly compute the partition indices using the selection vectors - UnifiedVectorFormat format; - hashes.ToUnifiedFormat(original_count, format); - const auto source_data = UnifiedVectorFormat::GetData(format); - const auto &source_sel = *format.sel; - - const auto target = FlatVector::GetData(partition_indices); - - if (source_sel.IsSet()) { - for (idx_t i = 0; i < append_count; i++) { - const auto source_idx = source_sel.get_index(append_sel[i]); - target[i] = CONSTANTS::ApplyMask(source_data[source_idx]); - } - } else { - for (idx_t i = 0; i < append_count; i++) { - const auto source_idx = append_sel[i]; - target[i] = CONSTANTS::ApplyMask(source_data[source_idx]); - } - } + UnaryExecutor::Execute(hashes, partition_indices, append_count, + [&](hash_t hash) { return CONSTANTS::ApplyMask(hash); }); } } }; @@ -161,20 +143,24 @@ void RadixPartitionedColumnData::ComputePartitionIndices(PartitionedColumnDataAp D_ASSERT(partitions.size() == RadixPartitioning::NumberOfPartitions(radix_bits)); D_ASSERT(state.partition_buffers.size() == RadixPartitioning::NumberOfPartitions(radix_bits)); RadixBitsSwitch(radix_bits, input.data[hash_col_idx], state.partition_indices, - input.size(), *FlatVector::IncrementalSelectionVector(), - input.size()); + *FlatVector::IncrementalSelectionVector(), input.size()); } //===--------------------------------------------------------------------===// // Tuple Data Partitioning //===--------------------------------------------------------------------===// -RadixPartitionedTupleData::RadixPartitionedTupleData(BufferManager &buffer_manager, - shared_ptr layout_ptr, const idx_t radix_bits_p, - const idx_t hash_col_idx_p) - : PartitionedTupleData(PartitionedTupleDataType::RADIX, buffer_manager, layout_ptr), radix_bits(radix_bits_p), +RadixPartitionedTupleData::RadixPartitionedTupleData(BufferManager &buffer_manager, const TupleDataLayout &layout_p, + const idx_t radix_bits_p, const idx_t hash_col_idx_p) + : PartitionedTupleData(PartitionedTupleDataType::RADIX, buffer_manager, layout_p.Copy()), radix_bits(radix_bits_p), hash_col_idx(hash_col_idx_p) { D_ASSERT(radix_bits <= RadixPartitioning::MAX_RADIX_BITS); D_ASSERT(hash_col_idx < layout.GetTypes().size()); + const auto num_partitions = RadixPartitioning::NumberOfPartitions(radix_bits); + allocators->allocators.reserve(num_partitions); + for (idx_t i = 0; i < num_partitions; i++) { + CreateAllocator(); + } + D_ASSERT(allocators->allocators.size() == num_partitions); Initialize(); } @@ -200,8 +186,8 @@ void RadixPartitionedTupleData::InitializeAppendStateInternal(PartitionedTupleDa const auto num_partitions = RadixPartitioning::NumberOfPartitions(radix_bits); state.partition_pin_states.reserve(num_partitions); for (idx_t i = 0; i < num_partitions; i++) { - state.partition_pin_states.emplace_back(); - partitions[i]->InitializeAppend(state.partition_pin_states[i], properties); + state.partition_pin_states.emplace_back(make_unsafe_uniq()); + partitions[i]->InitializeAppend(*state.partition_pin_states[i], properties); } // Init single chunk state @@ -221,18 +207,15 @@ void RadixPartitionedTupleData::ComputePartitionIndices(PartitionedTupleDataAppe const SelectionVector &append_sel, const idx_t append_count) { D_ASSERT(partitions.size() == RadixPartitioning::NumberOfPartitions(radix_bits)); RadixBitsSwitch(radix_bits, input.data[hash_col_idx], state.partition_indices, - input.size(), append_sel, append_count); + append_sel, append_count); } -void RadixPartitionedTupleData::ComputePartitionIndices(Vector &row_locations, idx_t count, Vector &partition_indices, - unique_ptr &utility_vector) const { - if (!utility_vector) { - utility_vector = make_uniq(LogicalType::HASH); - } - Vector &intermediate = *utility_vector; +void RadixPartitionedTupleData::ComputePartitionIndices(Vector &row_locations, idx_t count, + Vector &partition_indices) const { + Vector intermediate(LogicalType::HASH); partitions[0]->Gather(row_locations, *FlatVector::IncrementalSelectionVector(), count, hash_col_idx, intermediate, *FlatVector::IncrementalSelectionVector(), nullptr); - RadixBitsSwitch(radix_bits, intermediate, partition_indices, count, + RadixBitsSwitch(radix_bits, intermediate, partition_indices, *FlatVector::IncrementalSelectionVector(), count); } @@ -257,7 +240,7 @@ void RadixPartitionedTupleData::RepartitionFinalizeStates(PartitionedTupleData & auto &partitions = new_partitioned_data.GetPartitions(); for (idx_t partition_index = from_idx; partition_index < to_idx; partition_index++) { auto &partition = *partitions[partition_index]; - auto &partition_pin_state = state.partition_pin_states[partition_index]; + auto &partition_pin_state = *state.partition_pin_states[partition_index]; partition.FinalizePinState(partition_pin_state); } } diff --git a/src/duckdb/src/common/row_operations/row_aggregate.cpp b/src/duckdb/src/common/row_operations/row_aggregate.cpp index 4d39ca7ee..fb433eb5b 100644 --- a/src/duckdb/src/common/row_operations/row_aggregate.cpp +++ b/src/duckdb/src/common/row_operations/row_aggregate.cpp @@ -102,10 +102,7 @@ void RowOperations::CombineStates(RowOperationsState &state, TupleDataLayout &la void RowOperations::FinalizeStates(RowOperationsState &state, TupleDataLayout &layout, Vector &addresses, DataChunk &result, idx_t aggr_idx) { // Copy the addresses - if (!state.addresses) { - state.addresses = make_uniq(LogicalType::POINTER); - } - auto &addresses_copy = *state.addresses; + Vector addresses_copy(LogicalType::POINTER); VectorOperations::Copy(addresses, addresses_copy, result.size(), 0, 0); // Move to the first aggregate state diff --git a/src/duckdb/src/common/serializer/memory_stream.cpp b/src/duckdb/src/common/serializer/memory_stream.cpp index d608392e8..92419b8d0 100644 --- a/src/duckdb/src/common/serializer/memory_stream.cpp +++ b/src/duckdb/src/common/serializer/memory_stream.cpp @@ -102,8 +102,4 @@ idx_t MemoryStream::GetCapacity() const { return capacity; } -void MemoryStream::SetPosition(idx_t position_p) { - position = position_p; -} - } // namespace duckdb diff --git a/src/duckdb/src/common/sort/merge_sorter.cpp b/src/duckdb/src/common/sort/merge_sorter.cpp index c670fd574..b36887e66 100644 --- a/src/duckdb/src/common/sort/merge_sorter.cpp +++ b/src/duckdb/src/common/sort/merge_sorter.cpp @@ -10,10 +10,6 @@ MergeSorter::MergeSorter(GlobalSortState &state, BufferManager &buffer_manager) void MergeSorter::PerformInMergeRound() { while (true) { - // Check for interrupts after merging a partition - if (state.context.interrupted) { - throw InterruptException(); - } { lock_guard pair_guard(state.lock); if (state.pair_idx == state.num_pairs) { diff --git a/src/duckdb/src/common/sort/partition_state.cpp b/src/duckdb/src/common/sort/partition_state.cpp index 6ae2f1c5a..9c4379695 100644 --- a/src/duckdb/src/common/sort/partition_state.cpp +++ b/src/duckdb/src/common/sort/partition_state.cpp @@ -1,18 +1,21 @@ #include "duckdb/common/sort/partition_state.hpp" +#include "duckdb/common/types/column/column_data_consumer.hpp" #include "duckdb/common/row_operations/row_operations.hpp" #include "duckdb/main/config.hpp" #include "duckdb/parallel/executor_task.hpp" +#include + namespace duckdb { -PartitionGlobalHashGroup::PartitionGlobalHashGroup(ClientContext &context, const Orders &partitions, +PartitionGlobalHashGroup::PartitionGlobalHashGroup(BufferManager &buffer_manager, const Orders &partitions, const Orders &orders, const Types &payload_types, bool external) : count(0) { RowLayout payload_layout; payload_layout.Initialize(payload_types); - global_sort = make_uniq(context, orders, payload_layout); + global_sort = make_uniq(buffer_manager, orders, payload_layout); global_sort->external = external; // Set up a comparator for the partition subset @@ -96,17 +99,17 @@ PartitionGlobalSinkState::PartitionGlobalSinkState(ClientContext &context, ++max_bits; } - grouping_types_ptr = make_shared_ptr(); if (!orders.empty()) { if (partitions.empty()) { // Sort early into a dedicated hash group if we only sort. - grouping_types_ptr->Initialize(payload_types); - auto new_group = make_uniq(context, partitions, orders, payload_types, external); + grouping_types.Initialize(payload_types); + auto new_group = + make_uniq(buffer_manager, partitions, orders, payload_types, external); hash_groups.emplace_back(std::move(new_group)); } else { auto types = payload_types; types.push_back(LogicalType::HASH); - grouping_types_ptr->Initialize(types); + grouping_types.Initialize(types); ResizeGroupingData(estimated_cardinality); } } @@ -130,14 +133,13 @@ void PartitionGlobalSinkState::SyncPartitioning(const PartitionGlobalSinkState & const auto old_bits = grouping_data ? grouping_data->GetRadixBits() : 0; if (fixed_bits != old_bits) { const auto hash_col_idx = payload_types.size(); - grouping_data = - make_uniq(buffer_manager, grouping_types_ptr, fixed_bits, hash_col_idx); + grouping_data = make_uniq(buffer_manager, grouping_types, fixed_bits, hash_col_idx); } } unique_ptr PartitionGlobalSinkState::CreatePartition(idx_t new_bits) const { const auto hash_col_idx = payload_types.size(); - return make_uniq(buffer_manager, grouping_types_ptr, new_bits, hash_col_idx); + return make_uniq(buffer_manager, grouping_types, new_bits, hash_col_idx); } void PartitionGlobalSinkState::ResizeGroupingData(idx_t cardinality) { @@ -170,7 +172,7 @@ void PartitionGlobalSinkState::SyncLocalPartition(GroupingPartition &local_parti // If the local partition is now too small, flush it and reallocate auto new_partition = CreatePartition(new_bits); local_partition->FlushAppendState(*local_append); - local_partition->Repartition(context, *new_partition); + local_partition->Repartition(*new_partition); local_partition = std::move(new_partition); local_append = make_uniq(); @@ -405,8 +407,8 @@ PartitionGlobalMergeState::PartitionGlobalMergeState(PartitionGlobalSinkState &s num_threads(NumericCast(TaskScheduler::GetScheduler(sink.context).NumberOfThreads())), stage(PartitionSortStage::INIT), total_tasks(0), tasks_assigned(0), tasks_completed(0) { - auto new_group = make_uniq(sink.context, sink.partitions, sink.orders, sink.payload_types, - sink.external); + auto new_group = make_uniq(sink.buffer_manager, sink.partitions, sink.orders, + sink.payload_types, sink.external); sink.hash_groups.emplace_back(std::move(new_group)); hash_group = sink.hash_groups[group_idx].get(); @@ -475,7 +477,7 @@ void PartitionLocalMergeState::ExecuteTask() { bool PartitionGlobalMergeState::AssignTask(PartitionLocalMergeState &local_state) { lock_guard guard(lock); - if (tasks_assigned >= total_tasks && !TryPrepareNextStage()) { + if (tasks_assigned >= total_tasks) { return false; } @@ -494,13 +496,15 @@ void PartitionGlobalMergeState::CompleteTask() { } bool PartitionGlobalMergeState::TryPrepareNextStage() { + lock_guard guard(lock); + if (tasks_completed < total_tasks) { return false; } tasks_assigned = tasks_completed = 0; - switch (stage.load()) { + switch (stage) { case PartitionSortStage::INIT: // If the partitions are unordered, don't scan in parallel // because it produces non-deterministic orderings. @@ -629,6 +633,23 @@ bool PartitionGlobalMergeStates::ExecuteTask(PartitionLocalMergeState &local_sta break; } + // Hash group global state couldn't assign a task to this thread + // Try to prepare the next stage + if (!global_state->TryPrepareNextStage()) { + // This current hash group is not yet done + // But we were not able to assign a task for it to this thread + // See if the next hash group is better + continue; + } + + // We were able to prepare the next stage for this hash group! + // Try to assign a task once more + if (global_state->AssignTask(local_state)) { + // We assigned a task to this thread! + // Break out of this loop to re-enter the top-level loop and execute the task + break; + } + // We were able to prepare the next merge round, // but we were not able to assign a task for it to this thread // The tasks were assigned to other threads while this thread waited for the lock diff --git a/src/duckdb/src/common/sort/sort_state.cpp b/src/duckdb/src/common/sort/sort_state.cpp index 369f032f1..386f3498e 100644 --- a/src/duckdb/src/common/sort/sort_state.cpp +++ b/src/duckdb/src/common/sort/sort_state.cpp @@ -363,10 +363,10 @@ void LocalSortState::ReOrder(GlobalSortState &gstate, bool reorder_heap) { ReOrder(*sb.payload_data, sorting_ptr, *payload_heap, gstate, reorder_heap); } -GlobalSortState::GlobalSortState(ClientContext &context_p, const vector &orders, +GlobalSortState::GlobalSortState(BufferManager &buffer_manager, const vector &orders, RowLayout &payload_layout) - : context(context_p), buffer_manager(BufferManager::GetBufferManager(context)), sort_layout(SortLayout(orders)), - payload_layout(payload_layout), block_capacity(0), external(false) { + : buffer_manager(buffer_manager), sort_layout(SortLayout(orders)), payload_layout(payload_layout), + block_capacity(0), external(false) { } void GlobalSortState::AddLocalState(LocalSortState &local_sort_state) { diff --git a/src/duckdb/src/common/string_util.cpp b/src/duckdb/src/common/string_util.cpp index f7a817b50..f96e3d64e 100644 --- a/src/duckdb/src/common/string_util.cpp +++ b/src/duckdb/src/common/string_util.cpp @@ -297,12 +297,12 @@ uint64_t StringUtil::CIHash(const string &str) { return hash; } -bool StringUtil::CIEquals(const char *l1, idx_t l1_size, const char *l2, idx_t l2_size) { - if (l1_size != l2_size) { +bool StringUtil::CIEquals(const string &l1, const string &l2) { + if (l1.size() != l2.size()) { return false; } const auto charmap = ASCII_TO_LOWER_MAP; - for (idx_t c = 0; c < l1_size; c++) { + for (idx_t c = 0; c < l1.size(); c++) { if (charmap[(uint8_t)l1[c]] != charmap[(uint8_t)l2[c]]) { return false; } @@ -310,10 +310,6 @@ bool StringUtil::CIEquals(const char *l1, idx_t l1_size, const char *l2, idx_t l return true; } -bool StringUtil::CIEquals(const string &l1, const string &l2) { - return CIEquals(l1.c_str(), l1.size(), l2.c_str(), l2.size()); -} - bool StringUtil::CILessThan(const string &s1, const string &s2) { const auto charmap = ASCII_TO_UPPER_MAP; @@ -536,25 +532,19 @@ string StringUtil::CandidatesErrorMessage(const vector &strings, const s return StringUtil::CandidatesMessage(closest_strings, message_prefix); } -unique_ptr StringUtil::ParseJSONMap(const string &json, bool ignore_errors) { - auto result = make_uniq(json); +unordered_map StringUtil::ParseJSONMap(const string &json) { + unordered_map result; if (json.empty()) { return result; } yyjson_read_flag flags = YYJSON_READ_ALLOW_INVALID_UNICODE; yyjson_doc *doc = yyjson_read(json.c_str(), json.size(), flags); if (!doc) { - if (ignore_errors) { - return result; - } throw SerializationException("Failed to parse JSON string: %s", json); } yyjson_val *root = yyjson_doc_get_root(doc); if (!root || yyjson_get_type(root) != YYJSON_TYPE_OBJ) { yyjson_doc_free(doc); - if (ignore_errors) { - return result; - } throw SerializationException("Failed to parse JSON string: %s", json); } yyjson_obj_iter iter; @@ -562,46 +552,26 @@ unique_ptr StringUtil::ParseJSONMap(const string &json, bool ignore yyjson_val *key, *value; while ((key = yyjson_obj_iter_next(&iter))) { value = yyjson_obj_iter_get_val(key); - auto type = yyjson_get_type(value); - if (type == YYJSON_TYPE_STR) { - // Since this is a string, we can directly add the value - const auto key_val = yyjson_get_str(key); - const auto key_len = yyjson_get_len(key); - const auto value_val = yyjson_get_str(value); - const auto value_len = yyjson_get_len(value); - result->AddObject(string(key_val, key_len), make_uniq(string(value_val, value_len))); - } else if (type == YYJSON_TYPE_OBJ) { - // We recurse, this is a complex json - const auto key_val = yyjson_get_str(key); - const auto key_len = yyjson_get_len(key); - // Convert the object value to a JSON string and recurse - size_t json_str_len; - char *json_str = yyjson_val_write(value, 0, &json_str_len); - if (json_str) { - auto nested_result = ParseJSONMap(string(json_str, json_str_len), ignore_errors); - result->AddObject(string(key_val, key_len), std::move(nested_result)); - free(json_str); // Clean up the allocated string - } else { - yyjson_doc_free(doc); - if (ignore_errors) { - return result; - } - throw SerializationException("Failed to stringify nested JSON object"); - } - } else { - // Anything else is invalid. + if (yyjson_get_type(value) != YYJSON_TYPE_STR) { yyjson_doc_free(doc); - if (ignore_errors) { - return result; - } throw SerializationException("Failed to parse JSON string: %s", json); } + auto key_val = yyjson_get_str(key); + auto key_len = yyjson_get_len(key); + auto value_val = yyjson_get_str(value); + auto value_len = yyjson_get_len(value); + result.emplace(string(key_val, key_len), string(value_val, value_len)); } yyjson_doc_free(doc); return result; } -string WriteJsonToString(yyjson_mut_doc *doc) { +string ToJsonMapInternal(const unordered_map &map, yyjson_mut_doc *doc, yyjson_mut_val *root) { + for (auto &entry : map) { + auto key = yyjson_mut_strncpy(doc, entry.first.c_str(), entry.first.size()); + auto value = yyjson_mut_strncpy(doc, entry.second.c_str(), entry.second.size()); + yyjson_mut_obj_add(root, key, value); + } yyjson_write_err err; size_t len; constexpr yyjson_write_flag flags = YYJSON_WRITE_ALLOW_INVALID_UNICODE; @@ -620,15 +590,6 @@ string WriteJsonToString(yyjson_mut_doc *doc) { // Return the result return result; } - -string ToJsonMapInternal(const unordered_map &map, yyjson_mut_doc *doc, yyjson_mut_val *root) { - for (auto &entry : map) { - auto key = yyjson_mut_strncpy(doc, entry.first.c_str(), entry.first.size()); - auto value = yyjson_mut_strncpy(doc, entry.second.c_str(), entry.second.size()); - yyjson_mut_obj_add(root, key, value); - } - return WriteJsonToString(doc); -} string StringUtil::ToJSONMap(const unordered_map &map) { yyjson_mut_doc *doc = yyjson_mut_doc_new(nullptr); yyjson_mut_val *root = yyjson_mut_obj(doc); @@ -637,38 +598,6 @@ string StringUtil::ToJSONMap(const unordered_map &map) { return ToJsonMapInternal(map, doc, root); } -string ComplexJSON::GetValue(const string &key) const { - if (is_object) { - if (obj_value.find(key) != obj_value.end()) { - return GetValueRecursive(*obj_value.at(key)); - } - } - // Object either doesn't exist or this is just a string - return ""; -} - -string ComplexJSON::GetValueRecursive(const ComplexJSON &child) { - if (child.is_object) { - // We have to construct the nested json - yyjson_mut_doc *doc = yyjson_mut_doc_new(nullptr); - yyjson_mut_val *root = yyjson_mut_obj(doc); - yyjson_mut_doc_set_root(doc, root); - for (const auto &object : child.obj_value) { - auto key = yyjson_mut_strncpy(doc, object.first.c_str(), object.first.size()); - auto value_str = GetValueRecursive(*object.second); - auto value = yyjson_mut_strncpy(doc, value_str.c_str(), value_str.size()); - yyjson_mut_obj_add(root, key, value); - } - return WriteJsonToString(doc); - } else { - // simple string we can just write - return child.str_value; - } -} -string StringUtil::ToComplexJSONMap(const ComplexJSON &complex_json) { - return ComplexJSON::GetValueRecursive(complex_json); -} - string StringUtil::ExceptionToJSONMap(ExceptionType type, const string &message, const unordered_map &map) { D_ASSERT(map.find("exception_type") == map.end()); @@ -846,13 +775,6 @@ void StringUtil::URLDecodeBuffer(const char *input, idx_t input_size, char *outp } } -void StringUtil::SkipBOM(const char *buffer_ptr, const idx_t &buffer_size, idx_t &buffer_pos) { - if (buffer_size >= 3 && buffer_ptr[0] == '\xEF' && buffer_ptr[1] == '\xBB' && buffer_ptr[2] == '\xBF' && - buffer_pos == 0) { - buffer_pos = 3; - } -} - string StringUtil::URLDecode(const string &input, bool plus_to_space) { idx_t result_size = URLDecodeSize(input.c_str(), input.size(), plus_to_space); auto result_data = make_uniq_array(result_size); diff --git a/src/duckdb/src/common/types.cpp b/src/duckdb/src/common/types.cpp index bea896849..4ec1ce3f3 100644 --- a/src/duckdb/src/common/types.cpp +++ b/src/duckdb/src/common/types.cpp @@ -648,16 +648,6 @@ bool LogicalType::IsIntegral() const { } } -bool LogicalType::IsFloating() const { - switch (id_) { - case LogicalTypeId::FLOAT: - case LogicalTypeId::DOUBLE: - return true; - default: - return false; - } -} - bool LogicalType::IsNumeric() const { switch (id_) { case LogicalTypeId::TINYINT: diff --git a/src/duckdb/src/common/types/bit.cpp b/src/duckdb/src/common/types/bit.cpp index 4ac841153..2f9489ef9 100644 --- a/src/duckdb/src/common/types/bit.cpp +++ b/src/duckdb/src/common/types/bit.cpp @@ -24,7 +24,7 @@ idx_t Bit::ComputeBitstringLen(idx_t len) { static inline idx_t GetBitPadding(const bitstring_t &bit_string) { auto data = const_data_ptr_cast(bit_string.GetData()); - D_ASSERT(idx_t(data[0]) < 8); + D_ASSERT(idx_t(data[0]) <= 8); return data[0]; } diff --git a/src/duckdb/src/common/types/column/column_data_collection.cpp b/src/duckdb/src/common/types/column/column_data_collection.cpp index e45228b8c..17be67223 100644 --- a/src/duckdb/src/common/types/column/column_data_collection.cpp +++ b/src/duckdb/src/common/types/column/column_data_collection.cpp @@ -417,21 +417,12 @@ static void TemplatedColumnDataCopy(ColumnDataMetaData &meta_data, const Unified // initialize the validity mask to set all to valid result_validity.SetAllValid(STANDARD_VECTOR_SIZE); } - if (source_data.validity.AllValid()) { - // Fast path: all valid - for (idx_t i = 0; i < append_count; i++) { - auto source_idx = source_data.sel->get_index(offset + i); + for (idx_t i = 0; i < append_count; i++) { + auto source_idx = source_data.sel->get_index(offset + i); + if (source_data.validity.RowIsValid(source_idx)) { OP::template Assign(meta_data, base_ptr, source_data.data, current_segment.count + i, source_idx); - } - } else { - for (idx_t i = 0; i < append_count; i++) { - auto source_idx = source_data.sel->get_index(offset + i); - if (source_data.validity.RowIsValid(source_idx)) { - OP::template Assign(meta_data, base_ptr, source_data.data, current_segment.count + i, - source_idx); - } else { - result_validity.SetInvalid(current_segment.count + i); - } + } else { + result_validity.SetInvalid(current_segment.count + i); } } current_segment.count += append_count; @@ -571,7 +562,7 @@ void ColumnDataCopy(ColumnDataMetaData &meta_data, const UnifiedVector offset += append_count; remaining -= append_count; - if (remaining != 0 && vector_remaining - append_count == 0) { + if (vector_remaining - append_count == 0) { // need to append more, check if we need to allocate a new vector or not if (!current_segment.next_data.IsValid()) { segment.AllocateVector(source.GetType(), meta_data.chunk_data, append_state, current_index); diff --git a/src/duckdb/src/common/types/data_chunk.cpp b/src/duckdb/src/common/types/data_chunk.cpp index a5444c99b..9b1a182c4 100644 --- a/src/duckdb/src/common/types/data_chunk.cpp +++ b/src/duckdb/src/common/types/data_chunk.cpp @@ -76,7 +76,6 @@ idx_t DataChunk::GetAllocationSize() const { } void DataChunk::Reset() { - SetCardinality(0); if (data.empty() || vector_caches.empty()) { return; } @@ -87,6 +86,7 @@ void DataChunk::Reset() { data[i].ResetFromCache(vector_caches[i]); } capacity = STANDARD_VECTOR_SIZE; + SetCardinality(0); } void DataChunk::Destroy() { @@ -246,7 +246,7 @@ string DataChunk::ToString() const { return retval; } -void DataChunk::Serialize(Serializer &serializer, bool compressed_serialization) const { +void DataChunk::Serialize(Serializer &serializer) const { // write the count auto row_count = size(); @@ -266,7 +266,7 @@ void DataChunk::Serialize(Serializer &serializer, bool compressed_serialization) // Reference the vector to avoid potentially mutating it during serialization Vector serialized_vector(data[i].GetType()); serialized_vector.Reference(data[i]); - serialized_vector.Serialize(object, row_count, compressed_serialization); + serialized_vector.Serialize(object, row_count); }); }); } diff --git a/src/duckdb/src/common/types/hash.cpp b/src/duckdb/src/common/types/hash.cpp index 333389020..83a1ef223 100644 --- a/src/duckdb/src/common/types/hash.cpp +++ b/src/duckdb/src/common/types/hash.cpp @@ -65,101 +65,83 @@ hash_t Hash(interval_t val) { return Hash(days) ^ Hash(months) ^ Hash(micros); } -template <> -hash_t Hash(dtime_tz_t val) { - return Hash(val.bits); -} - template <> hash_t Hash(const char *str) { return Hash(str, strlen(str)); } -template -hash_t HashBytes(const_data_ptr_t ptr, const idx_t len) noexcept { - // This seed slightly improves bit distribution, taken from here: - // https://github.com/martinus/robin-hood-hashing/blob/3.11.5/LICENSE - // MIT License Copyright (c) 2018-2021 Martin Ankerl - hash_t h = 0xe17a1465U ^ (len * 0xc6a4a7935bd1e995U); - - // Hash/combine in blocks of 8 bytes - const auto remainder = len & 7U; - for (const auto end = ptr + len - remainder; ptr != end; ptr += 8U) { - h ^= Load(ptr); - h *= 0xd6e8feb86659fd93U; - } - - if (remainder != 0) { - if (AT_LEAST_8_BYTES) { - D_ASSERT(len >= 8); - // Load remaining (<8) bytes (with a Load instead of a memcpy) - const auto inv_rem = 8U - remainder; - const auto hr = Load(ptr - inv_rem) >> (inv_rem * 8U); - - h ^= hr; - h *= 0xd6e8feb86659fd93U; - } else { - // Load remaining (<8) bytes (with a memcpy) - hash_t hr = 0; - memcpy(&hr, ptr, remainder); - - h ^= hr; - h *= 0xd6e8feb86659fd93U; - } - } - - // Finalize - return Hash(h); +template <> +hash_t Hash(string_t val) { + return Hash(val.GetData(), val.GetSize()); } template <> -hash_t Hash(string_t val) { - // If the string is inlined, we can do a branchless hash - if (val.IsInlined()) { - // This seed slightly improves bit distribution, taken from here: - // https://github.com/martinus/robin-hood-hashing/blob/3.11.5/LICENSE - // MIT License Copyright (c) 2018-2021 Martin Ankerl - hash_t h = 0xe17a1465U ^ (val.GetSize() * 0xc6a4a7935bd1e995U); - - // Hash/combine the first 8-byte block - if (!val.Empty()) { - h ^= Load(const_data_ptr_cast(val.GetPrefix())); - h *= 0xd6e8feb86659fd93U; - } +hash_t Hash(char *val) { + return Hash(val); +} - // Load remaining 4 bytes - if (val.GetSize() > sizeof(hash_t)) { - hash_t hr = 0; - memcpy(&hr, const_data_ptr_cast(val.GetPrefix()) + sizeof(hash_t), 4U); +// MIT License +// Copyright (c) 2018-2021 Martin Ankerl +// https://github.com/martinus/robin-hood-hashing/blob/3.11.5/LICENSE +hash_t HashBytes(void *ptr, size_t len) noexcept { + static constexpr uint64_t M = UINT64_C(0xc6a4a7935bd1e995); + static constexpr uint64_t SEED = UINT64_C(0xe17a1465); + static constexpr unsigned int R = 47; - h ^= hr; - h *= 0xd6e8feb86659fd93U; - } + auto const *const data64 = static_cast(ptr); + uint64_t h = SEED ^ (len * M); - // Finalize - h = Hash(h); + size_t const n_blocks = len / 8; + for (size_t i = 0; i < n_blocks; ++i) { + auto k = Load(reinterpret_cast(data64 + i)); - // This is just an optimization. It should not change the result - // This property is important for verification (e.g., DUCKDB_DEBUG_NO_INLINE) - D_ASSERT(h == Hash(val.GetData(), val.GetSize())); + k *= M; + k ^= k >> R; + k *= M; - return h; + h ^= k; + h *= M; } - // Required for DUCKDB_DEBUG_NO_INLINE - return HashBytes= sizeof(hash_t)>(const_data_ptr_cast(val.GetData()), val.GetSize()); -} -template <> -hash_t Hash(char *val) { - return Hash(val); + auto const *const data8 = reinterpret_cast(data64 + n_blocks); + switch (len & 7U) { + case 7: + h ^= static_cast(data8[6]) << 48U; + DUCKDB_EXPLICIT_FALLTHROUGH; + case 6: + h ^= static_cast(data8[5]) << 40U; + DUCKDB_EXPLICIT_FALLTHROUGH; + case 5: + h ^= static_cast(data8[4]) << 32U; + DUCKDB_EXPLICIT_FALLTHROUGH; + case 4: + h ^= static_cast(data8[3]) << 24U; + DUCKDB_EXPLICIT_FALLTHROUGH; + case 3: + h ^= static_cast(data8[2]) << 16U; + DUCKDB_EXPLICIT_FALLTHROUGH; + case 2: + h ^= static_cast(data8[1]) << 8U; + DUCKDB_EXPLICIT_FALLTHROUGH; + case 1: + h ^= static_cast(data8[0]); + h *= M; + DUCKDB_EXPLICIT_FALLTHROUGH; + default: + break; + } + h ^= h >> R; + h *= M; + h ^= h >> R; + return static_cast(h); } hash_t Hash(const char *val, size_t size) { - return HashBytes(const_data_ptr_cast(val), size); + return HashBytes((void *)val, size); } hash_t Hash(uint8_t *val, size_t size) { - return HashBytes(const_data_ptr_cast(val), size); + return HashBytes((void *)val, size); } } // namespace duckdb diff --git a/src/duckdb/src/common/types/interval.cpp b/src/duckdb/src/common/types/interval.cpp index e900b2402..719e9ee2c 100644 --- a/src/duckdb/src/common/types/interval.cpp +++ b/src/duckdb/src/common/types/interval.cpp @@ -342,20 +342,38 @@ int64_t Interval::GetNanoseconds(const interval_t &val) { return nano; } -interval_t Interval::GetAge(TimestampComponents ts1, TimestampComponents ts2, bool is_negative) { - // perform the differences - auto year_diff = ts1.year - ts2.year; - auto month_diff = ts1.month - ts2.month; - auto day_diff = ts1.day - ts2.day; - - auto hour_diff = ts1.hour - ts2.hour; - auto min_diff = ts1.minute - ts2.minute; - auto sec_diff = ts1.second - ts2.second; - auto micros_diff = ts1.microsecond - ts2.microsecond; +interval_t Interval::GetAge(timestamp_t timestamp_1, timestamp_t timestamp_2) { + D_ASSERT(Timestamp::IsFinite(timestamp_1) && Timestamp::IsFinite(timestamp_2)); + date_t date1, date2; + dtime_t time1, time2; + + Timestamp::Convert(timestamp_1, date1, time1); + Timestamp::Convert(timestamp_2, date2, time2); + + // and from date extract the years, months and days + int32_t year1, month1, day1; + int32_t year2, month2, day2; + Date::Convert(date1, year1, month1, day1); + Date::Convert(date2, year2, month2, day2); + // finally perform the differences + auto year_diff = year1 - year2; + auto month_diff = month1 - month2; + auto day_diff = day1 - day2; + + // and from time extract hours, minutes, seconds and milliseconds + int32_t hour1, min1, sec1, micros1; + int32_t hour2, min2, sec2, micros2; + Time::Convert(time1, hour1, min1, sec1, micros1); + Time::Convert(time2, hour2, min2, sec2, micros2); + // finally perform the differences + auto hour_diff = hour1 - hour2; + auto min_diff = min1 - min2; + auto sec_diff = sec1 - sec2; + auto micros_diff = micros1 - micros2; // flip sign if necessary bool sign_flipped = false; - if (is_negative) { + if (timestamp_1 < timestamp_2) { year_diff = -year_diff; month_diff = -month_diff; day_diff = -day_diff; @@ -383,11 +401,11 @@ interval_t Interval::GetAge(TimestampComponents ts1, TimestampComponents ts2, bo day_diff--; } while (day_diff < 0) { - if (is_negative) { - day_diff += Date::IsLeapYear(ts1.year) ? Date::LEAP_DAYS[ts1.month] : Date::NORMAL_DAYS[ts1.month]; + if (timestamp_1 < timestamp_2) { + day_diff += Date::IsLeapYear(year1) ? Date::LEAP_DAYS[month1] : Date::NORMAL_DAYS[month1]; month_diff--; } else { - day_diff += Date::IsLeapYear(ts2.year) ? Date::LEAP_DAYS[ts2.month] : Date::NORMAL_DAYS[ts2.month]; + day_diff += Date::IsLeapYear(year2) ? Date::LEAP_DAYS[month2] : Date::NORMAL_DAYS[month2]; month_diff--; } } @@ -414,15 +432,6 @@ interval_t Interval::GetAge(TimestampComponents ts1, TimestampComponents ts2, bo return interval; } -interval_t Interval::GetAge(timestamp_t timestamp_1, timestamp_t timestamp_2) { - D_ASSERT(Timestamp::IsFinite(timestamp_1) && Timestamp::IsFinite(timestamp_2)); - - auto ts_component1 = Timestamp::GetComponents(timestamp_1); - auto ts_component2 = Timestamp::GetComponents(timestamp_2); - - return Interval::GetAge(ts_component1, ts_component2, timestamp_1 < timestamp_2); -} - interval_t Interval::GetDifference(timestamp_t timestamp_1, timestamp_t timestamp_2) { if (!Timestamp::IsFinite(timestamp_1) || !Timestamp::IsFinite(timestamp_2)) { throw InvalidInputException("Cannot subtract infinite timestamps"); diff --git a/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp b/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp index 2f749d916..b77463d8c 100644 --- a/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp +++ b/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp @@ -7,25 +7,20 @@ namespace duckdb { PartitionedTupleData::PartitionedTupleData(PartitionedTupleDataType type_p, BufferManager &buffer_manager_p, - shared_ptr &layout_ptr_p) - : type(type_p), buffer_manager(buffer_manager_p), layout_ptr(layout_ptr_p), layout(*layout_ptr), count(0), - data_size(0) { + const TupleDataLayout &layout_p) + : type(type_p), buffer_manager(buffer_manager_p), layout(layout_p.Copy()), count(0), data_size(0), + allocators(make_shared_ptr()) { } PartitionedTupleData::PartitionedTupleData(const PartitionedTupleData &other) - : type(other.type), buffer_manager(other.buffer_manager), layout_ptr(other.layout_ptr), layout(*layout_ptr), - count(0), data_size(0) { + : type(other.type), buffer_manager(other.buffer_manager), layout(other.layout.Copy()), count(0), data_size(0) { } PartitionedTupleData::~PartitionedTupleData() { } -shared_ptr PartitionedTupleData::GetLayoutPtr() const { - return layout_ptr; -} - const TupleDataLayout &PartitionedTupleData::GetLayout() const { - return *layout_ptr; + return layout; } PartitionedTupleDataType PartitionedTupleData::GetType() const { @@ -64,7 +59,7 @@ void PartitionedTupleData::AppendUnified(PartitionedTupleDataAppendState &state, const auto partition_index = state.GetPartitionIndexIfSinglePartition(UseFixedSizeMap()); if (partition_index.IsValid()) { auto &partition = *partitions[partition_index.GetIndex()]; - auto &partition_pin_state = state.partition_pin_states[partition_index.GetIndex()]; + auto &partition_pin_state = *state.partition_pin_states[partition_index.GetIndex()]; const auto size_before = partition.SizeInBytes(); partition.AppendUnified(partition_pin_state, state.chunk_state, input, append_sel, actual_append_count); @@ -89,7 +84,7 @@ void PartitionedTupleData::AppendUnified(PartitionedTupleDataAppendState &state, void PartitionedTupleData::Append(PartitionedTupleDataAppendState &state, TupleDataChunkState &input, const idx_t append_count) { // Compute partition indices and store them in state.partition_indices - ComputePartitionIndices(input.row_locations, append_count, state.partition_indices, state.utility_vector); + ComputePartitionIndices(input.row_locations, append_count, state.partition_indices); // Build the selection vector for the partitions BuildPartitionSel(state, *FlatVector::IncrementalSelectionVector(), append_count); @@ -98,7 +93,7 @@ void PartitionedTupleData::Append(PartitionedTupleDataAppendState &state, TupleD auto partition_index = state.GetPartitionIndexIfSinglePartition(UseFixedSizeMap()); if (partition_index.IsValid()) { auto &partition = *partitions[partition_index.GetIndex()]; - auto &partition_pin_state = state.partition_pin_states[partition_index.GetIndex()]; + auto &partition_pin_state = *state.partition_pin_states[partition_index.GetIndex()]; state.chunk_state.heap_sizes.Reference(input.heap_sizes); @@ -203,7 +198,7 @@ void PartitionedTupleData::BuildBufferSpace(PartitionedTupleDataAppendState &sta // Partition, pin state for this partition index auto &partition = *partitions[partition_index]; - auto &partition_pin_state = state.partition_pin_states[partition_index]; + auto &partition_pin_state = *state.partition_pin_states[partition_index]; // Length and offset for this partition const auto &partition_entry = GETTER::GetValue(it); @@ -220,7 +215,7 @@ void PartitionedTupleData::BuildBufferSpace(PartitionedTupleDataAppendState &sta void PartitionedTupleData::FlushAppendState(PartitionedTupleDataAppendState &state) { for (idx_t partition_index = 0; partition_index < partitions.size(); partition_index++) { auto &partition = *partitions[partition_index]; - auto &partition_pin_state = state.partition_pin_states[partition_index]; + auto &partition_pin_state = *state.partition_pin_states[partition_index]; partition.FinalizePinState(partition_pin_state); } } @@ -256,7 +251,7 @@ void PartitionedTupleData::Reset() { Verify(); } -void PartitionedTupleData::Repartition(ClientContext &context, PartitionedTupleData &new_partitioned_data) { +void PartitionedTupleData::Repartition(PartitionedTupleData &new_partitioned_data) { D_ASSERT(layout.GetTypes() == new_partitioned_data.layout.GetTypes()); if (partitions.size() == new_partitioned_data.partitions.size()) { @@ -274,10 +269,6 @@ void PartitionedTupleData::Repartition(ClientContext &context, PartitionedTupleD TupleDataChunkIterator iterator(partition, TupleDataPinProperties::DESTROY_AFTER_DONE, true); auto &chunk_state = iterator.GetChunkState(); do { - // Check for interrupts with each chunk - if (context.interrupted) { - throw InterruptException(); - } new_partitioned_data.Append(append_state, chunk_state, iterator.GetCurrentChunkCount()); } while (iterator.Next()); @@ -305,7 +296,7 @@ unsafe_vector> &PartitionedTupleData::GetPartiti unique_ptr PartitionedTupleData::GetUnpartitioned() { auto data_collection = std::move(partitions[0]); - partitions[0] = make_uniq(buffer_manager, layout_ptr); + partitions[0] = make_uniq(buffer_manager, layout); for (idx_t i = 1; i < partitions.size(); i++) { data_collection->Combine(*partitions[i]); @@ -374,4 +365,8 @@ void PartitionedTupleData::Print() { } // LCOV_EXCL_STOP +void PartitionedTupleData::CreateAllocator() { + allocators->allocators.emplace_back(make_shared_ptr(buffer_manager, layout)); +} + } // namespace duckdb diff --git a/src/duckdb/src/common/types/row/tuple_data_allocator.cpp b/src/duckdb/src/common/types/row/tuple_data_allocator.cpp index c8755c238..ed9145a11 100644 --- a/src/duckdb/src/common/types/row/tuple_data_allocator.cpp +++ b/src/duckdb/src/common/types/row/tuple_data_allocator.cpp @@ -29,12 +29,12 @@ TupleDataBlock &TupleDataBlock::operator=(TupleDataBlock &&other) noexcept { return *this; } -TupleDataAllocator::TupleDataAllocator(BufferManager &buffer_manager, shared_ptr &layout_ptr_p) - : buffer_manager(buffer_manager), layout_ptr(layout_ptr_p), layout(*layout_ptr) { +TupleDataAllocator::TupleDataAllocator(BufferManager &buffer_manager, const TupleDataLayout &layout) + : buffer_manager(buffer_manager), layout(layout.Copy()) { } TupleDataAllocator::TupleDataAllocator(TupleDataAllocator &allocator) - : buffer_manager(allocator.buffer_manager), layout_ptr(allocator.layout_ptr), layout(*layout_ptr) { + : buffer_manager(allocator.buffer_manager), layout(allocator.layout.Copy()) { } void TupleDataAllocator::SetDestroyBufferUponUnpin() { @@ -62,10 +62,6 @@ Allocator &TupleDataAllocator::GetAllocator() { return buffer_manager.GetBufferAllocator(); } -shared_ptr TupleDataAllocator::GetLayoutPtr() const { - return layout_ptr; -} - const TupleDataLayout &TupleDataAllocator::GetLayout() const { return layout; } @@ -103,8 +99,8 @@ void TupleDataAllocator::Build(TupleDataSegment &segment, TupleDataPinState &pin // Build the next part auto next = MinValue(append_count - offset, STANDARD_VECTOR_SIZE - chunk.count); - auto &chunk_part = - chunk.AddPart(segment, BuildChunkPart(pin_state, chunk_state, append_offset + offset, next, chunk)); + chunk.AddPart(BuildChunkPart(pin_state, chunk_state, append_offset + offset, next, chunk), layout); + auto &chunk_part = chunk.parts.back(); next = chunk_part.count; segment.count += next; @@ -126,19 +122,19 @@ void TupleDataAllocator::Build(TupleDataSegment &segment, TupleDataPinState &pin } offset += next; - chunk_part_indices.emplace_back(chunks.size() - 1, chunk.part_ids.End() - 1); + chunk_part_indices.emplace_back(chunks.size() - 1, chunk.parts.size() - 1); } // Now initialize the pointers to write the data to chunk_parts.clear(); - for (const auto &indices : chunk_part_indices) { - chunk_parts.emplace_back(segment.chunk_parts[indices.second]); + for (auto &indices : chunk_part_indices) { + chunk_parts.emplace_back(segment.chunks[indices.first].parts[indices.second]); } InitializeChunkStateInternal(pin_state, chunk_state, append_offset, false, true, false, chunk_parts); // To reduce metadata, we try to merge chunk parts where possible // Due to the way chunk parts are constructed, only the last part of the first chunk is eligible for merging - segment.chunks[chunk_part_indices[0].first].MergeLastChunkPart(segment); + segment.chunks[chunk_part_indices[0].first].MergeLastChunkPart(layout); segment.Verify(); } @@ -235,14 +231,15 @@ void TupleDataAllocator::InitializeChunkState(TupleDataSegment &segment, TupleDa // We can't release the heap here if the current chunk's heap_block_ids is empty, because if we are iterating with // PinProperties::DESTROY_AFTER_DONE, we might destroy a heap block that is needed by a later chunk, e.g., // when chunk 0 needs heap block 0, chunk 1 does not need any heap blocks, and chunk 2 needs heap block 0 again - ReleaseOrStoreHandles(pin_state, segment, chunk, !chunk.heap_block_ids.Empty()); + ReleaseOrStoreHandles(pin_state, segment, chunk, !chunk.heap_block_ids.empty()); - chunk_state.parts.clear(); - for (auto part_id = chunk.part_ids.Start(); part_id < chunk.part_ids.End(); part_id++) { - chunk_state.parts.emplace_back(segment.chunk_parts[part_id]); + unsafe_vector> parts; + parts.reserve(chunk.parts.size()); + for (auto &part : chunk.parts) { + parts.emplace_back(part); } - InitializeChunkStateInternal(pin_state, chunk_state, 0, true, init_heap, init_heap, chunk_state.parts); + InitializeChunkStateInternal(pin_state, chunk_state, 0, true, init_heap, init_heap, parts); } static inline void InitializeHeapSizes(const data_ptr_t row_locations[], idx_t heap_sizes[], const idx_t offset, @@ -450,17 +447,15 @@ void TupleDataAllocator::ReleaseOrStoreHandles(TupleDataPinState &pin_state, Tup ReleaseOrStoreHandles(pin_state, segment, DUMMY_CHUNK, true); } -void TupleDataAllocator::ReleaseOrStoreHandlesInternal(TupleDataSegment &segment, - unsafe_vector &pinned_handles, - buffer_handle_map_t &handles, const ContinuousIdSet &block_ids, - unsafe_vector &blocks, - TupleDataPinProperties properties) { +void TupleDataAllocator::ReleaseOrStoreHandlesInternal( + TupleDataSegment &segment, unsafe_vector &pinned_handles, perfect_map_t &handles, + const perfect_set_t &block_ids, unsafe_vector &blocks, TupleDataPinProperties properties) { bool found_handle; do { found_handle = false; for (auto it = handles.begin(); it != handles.end(); it++) { const auto block_id = it->first; - if (block_ids.Contains(block_id)) { + if (block_ids.find(block_id) != block_ids.end()) { // still required: do not release continue; } diff --git a/src/duckdb/src/common/types/row/tuple_data_collection.cpp b/src/duckdb/src/common/types/row/tuple_data_collection.cpp index 504579ad2..7db3ba37a 100644 --- a/src/duckdb/src/common/types/row/tuple_data_collection.cpp +++ b/src/duckdb/src/common/types/row/tuple_data_collection.cpp @@ -12,9 +12,13 @@ namespace duckdb { using ValidityBytes = TupleDataLayout::ValidityBytes; -TupleDataCollection::TupleDataCollection(BufferManager &buffer_manager, shared_ptr layout_ptr_p) - : layout_ptr(std::move(layout_ptr_p)), layout(*layout_ptr), - allocator(make_shared_ptr(buffer_manager, layout_ptr)) { +TupleDataCollection::TupleDataCollection(BufferManager &buffer_manager, const TupleDataLayout &layout_p) + : layout(layout_p.Copy()), allocator(make_shared_ptr(buffer_manager, layout)) { + Initialize(); +} + +TupleDataCollection::TupleDataCollection(shared_ptr allocator) + : layout(allocator->GetLayout().Copy()), allocator(std::move(allocator)) { Initialize(); } diff --git a/src/duckdb/src/common/types/row/tuple_data_segment.cpp b/src/duckdb/src/common/types/row/tuple_data_segment.cpp index 1b69dbf83..c3383f3cb 100644 --- a/src/duckdb/src/common/types/row/tuple_data_segment.cpp +++ b/src/duckdb/src/common/types/row/tuple_data_segment.cpp @@ -15,11 +15,32 @@ void TupleDataChunkPart::SetHeapEmpty() { base_heap_ptr = nullptr; } +void MoveTupleDataChunkPart(TupleDataChunkPart &a, TupleDataChunkPart &b) { + a.row_block_index = b.row_block_index; + a.row_block_offset = b.row_block_offset; + a.heap_block_index = b.heap_block_index; + a.heap_block_offset = b.heap_block_offset; + a.base_heap_ptr = b.base_heap_ptr; + a.total_heap_size = b.total_heap_size; + a.count = b.count; + std::swap(a.lock, b.lock); +} + +TupleDataChunkPart::TupleDataChunkPart(TupleDataChunkPart &&other) noexcept : lock((other.lock)) { + MoveTupleDataChunkPart(*this, other); +} + +TupleDataChunkPart &TupleDataChunkPart::operator=(TupleDataChunkPart &&other) noexcept { + MoveTupleDataChunkPart(*this, other); + return *this; +} + TupleDataChunk::TupleDataChunk() : count(0), lock(make_unsafe_uniq()) { + parts.reserve(2); } static inline void SwapTupleDataChunk(TupleDataChunk &a, TupleDataChunk &b) noexcept { - std::swap(a.part_ids, b.part_ids); + std::swap(a.parts, b.parts); std::swap(a.row_block_ids, b.row_block_ids); std::swap(a.heap_block_ids, b.heap_block_ids); std::swap(a.count, b.count); @@ -35,53 +56,46 @@ TupleDataChunk &TupleDataChunk::operator=(TupleDataChunk &&other) noexcept { return *this; } -TupleDataChunkPart &TupleDataChunk::AddPart(TupleDataSegment &segment, TupleDataChunkPart &&part) { +void TupleDataChunk::AddPart(TupleDataChunkPart &&part, const TupleDataLayout &layout) { count += part.count; - row_block_ids.Insert(part.row_block_index); - if (!segment.layout.get().AllConstant() && part.total_heap_size > 0) { - heap_block_ids.Insert(part.heap_block_index); + row_block_ids.insert(part.row_block_index); + if (!layout.AllConstant() && part.total_heap_size > 0) { + heap_block_ids.insert(part.heap_block_index); } part.lock = *lock; - part_ids.Insert(UnsafeNumericCast(segment.chunk_parts.size())); - segment.chunk_parts.emplace_back(std::move(part)); - return segment.chunk_parts.back(); + parts.emplace_back(std::move(part)); } -void TupleDataChunk::Verify(const TupleDataSegment &segment) const { +void TupleDataChunk::Verify() const { #ifdef DEBUG idx_t total_count = 0; - for (auto part_id = part_ids.Start(); part_id < part_ids.End(); part_id++) { - total_count += segment.chunk_parts[part_id].count; + for (const auto &part : parts) { + total_count += part.count; } D_ASSERT(this->count == total_count); D_ASSERT(this->count <= STANDARD_VECTOR_SIZE); #endif } -void TupleDataChunk::MergeLastChunkPart(TupleDataSegment &segment) { - if (part_ids.Size() < 2) { +void TupleDataChunk::MergeLastChunkPart(const TupleDataLayout &layout) { + if (parts.size() < 2) { return; } - auto &second_to_last = segment.chunk_parts[part_ids.End() - 2]; - auto &last = segment.chunk_parts[part_ids.End() - 1]; + auto &second_to_last = parts[parts.size() - 2]; + auto &last = parts[parts.size() - 1]; - auto rows_align = last.row_block_index == second_to_last.row_block_index && - last.row_block_offset == - second_to_last.row_block_offset + second_to_last.count * segment.layout.get().GetRowWidth(); + auto rows_align = + last.row_block_index == second_to_last.row_block_index && + last.row_block_offset == second_to_last.row_block_offset + second_to_last.count * layout.GetRowWidth(); if (!rows_align) { // If rows don't align we can never merge return; } - if (segment.layout.get().AllConstant()) { // No heap and rows align - merge + if (layout.AllConstant()) { // No heap and rows align - merge second_to_last.count += last.count; - if (segment.chunk_parts.size() == part_ids.End()) { - // Can only remove if the part we're merging was the last added chunk part - // If not, we just leave it there (no chunk will reference it anyway) - segment.chunk_parts.pop_back(); - } - part_ids.DecrementMax(); + parts.pop_back(); return; } @@ -90,19 +104,12 @@ void TupleDataChunk::MergeLastChunkPart(TupleDataSegment &segment) { last.base_heap_ptr == second_to_last.base_heap_ptr) { // There is a heap and it aligns - merge second_to_last.total_heap_size += last.total_heap_size; second_to_last.count += last.count; - if (segment.chunk_parts.size() == part_ids.End()) { - segment.chunk_parts.pop_back(); // Same as above - } - part_ids.DecrementMax(); + parts.pop_back(); } } TupleDataSegment::TupleDataSegment(shared_ptr allocator_p) - : allocator(std::move(allocator_p)), layout(allocator->GetLayout()), count(0), data_size(0) { - // We initialize these with plenty of room so that we can avoid allocations - static constexpr idx_t CHUNK_RESERVATION = 64; - chunks.reserve(CHUNK_RESERVATION); - chunk_parts.reserve(CHUNK_RESERVATION); + : allocator(std::move(allocator_p)), count(0), data_size(0) { } TupleDataSegment::~TupleDataSegment() { @@ -117,16 +124,14 @@ TupleDataSegment::~TupleDataSegment() { void SwapTupleDataSegment(TupleDataSegment &a, TupleDataSegment &b) { std::swap(a.allocator, b.allocator); - std::swap(a.layout, b.layout); std::swap(a.chunks, b.chunks); - std::swap(a.chunk_parts, b.chunk_parts); std::swap(a.count, b.count); std::swap(a.data_size, b.data_size); std::swap(a.pinned_row_handles, b.pinned_row_handles); std::swap(a.pinned_heap_handles, b.pinned_heap_handles); } -TupleDataSegment::TupleDataSegment(TupleDataSegment &&other) noexcept : layout(other.layout) { +TupleDataSegment::TupleDataSegment(TupleDataSegment &&other) noexcept { SwapTupleDataSegment(*this, other); } @@ -156,13 +161,13 @@ void TupleDataSegment::Verify() const { idx_t total_count = 0; idx_t total_size = 0; for (const auto &chunk : chunks) { - chunk.Verify(*this); + chunk.Verify(); total_count += chunk.count; total_size += chunk.count * layout.GetRowWidth(); if (!layout.AllConstant()) { - for (auto part_id = chunk.part_ids.Start(); part_id < chunk.part_ids.End(); part_id++) { - total_size += chunk_parts[part_id].total_heap_size; + for (const auto &part : chunk.parts) { + total_size += part.total_heap_size; } } } diff --git a/src/duckdb/src/common/types/selection_vector.cpp b/src/duckdb/src/common/types/selection_vector.cpp index a65319a31..7b6fda414 100644 --- a/src/duckdb/src/common/types/selection_vector.cpp +++ b/src/duckdb/src/common/types/selection_vector.cpp @@ -6,11 +6,10 @@ namespace duckdb { SelectionData::SelectionData(idx_t count) { - owned_data = Allocator::DefaultAllocator().Allocate(MaxValue(count, 1) * sizeof(sel_t)); + owned_data = make_unsafe_uniq_array_uninitialized(count); #ifdef DEBUG - auto data_ptr = reinterpret_cast(owned_data.get()); for (idx_t i = 0; i < count; i++) { - data_ptr[i] = std::numeric_limits::max(); + owned_data[i] = std::numeric_limits::max(); } #endif } @@ -35,7 +34,7 @@ void SelectionVector::Print(idx_t count) const { buffer_ptr SelectionVector::Slice(const SelectionVector &sel, idx_t count) const { auto data = make_buffer(count); - auto result_ptr = reinterpret_cast(data->owned_data.get()); + auto result_ptr = data->owned_data.get(); // for every element, we perform result[i] = target[new[i]] for (idx_t i = 0; i < count; i++) { auto new_idx = sel.get_index(i); diff --git a/src/duckdb/src/common/types/time.cpp b/src/duckdb/src/common/types/time.cpp index 54e43628a..fa4d135f5 100644 --- a/src/duckdb/src/common/types/time.cpp +++ b/src/duckdb/src/common/types/time.cpp @@ -1,5 +1,6 @@ #include "duckdb/common/types/time.hpp" +#include "duckdb/common/exception.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/common/types/cast_helpers.hpp" #include "duckdb/common/types/date.hpp" @@ -10,6 +11,7 @@ #include #include +#include namespace duckdb { static_assert(sizeof(dtime_t) == sizeof(int64_t), "dtime_t was padded"); @@ -180,18 +182,27 @@ bool Time::TryConvertTimeTZ(const char *buf, idx_t len, idx_t &pos, dtime_tz_t & pos++; } - // Get the ±HH[:MM[:SS]] part - // (PG claims they don't support :SS but they do...) + // Get the ±HH[:MM] part int hh = 0; int mm = 0; - int ss = 0; has_offset = (pos < len); - if (has_offset && !Timestamp::TryParseUTCOffset(buf, pos, len, hh, mm, ss)) { + if (has_offset && !Timestamp::TryParseUTCOffset(buf, pos, len, hh, mm)) { return false; } // Offsets are in seconds in the open interval (-16:00:00, +16:00:00) - int32_t offset = ((hh * Interval::MINS_PER_HOUR) + mm) * Interval::SECS_PER_MINUTE + ss; + int32_t offset = ((hh * Interval::MINS_PER_HOUR) + mm) * Interval::SECS_PER_MINUTE; + + // Check for trailing seconds. + // (PG claims they don't support this but they do...) + if (pos < len && buf[pos] == ':') { + ++pos; + int ss = 0; + if (!Date::ParseDoubleDigit(buf, len, pos, ss)) { + return false; + } + offset += (offset < 0) ? -ss : ss; + } if (offset < dtime_tz_t::MIN_OFFSET || offset > dtime_tz_t::MAX_OFFSET) { return false; diff --git a/src/duckdb/src/common/types/timestamp.cpp b/src/duckdb/src/common/types/timestamp.cpp index 0cd4abc9d..d596e7530 100644 --- a/src/duckdb/src/common/types/timestamp.cpp +++ b/src/duckdb/src/common/types/timestamp.cpp @@ -10,6 +10,7 @@ #include "duckdb/common/operator/multiply.hpp" #include "duckdb/common/operator/subtract.hpp" #include "duckdb/common/exception/conversion_exception.hpp" +#include "duckdb/common/limits.hpp" #include namespace duckdb { @@ -17,7 +18,7 @@ namespace duckdb { static_assert(sizeof(timestamp_t) == sizeof(int64_t), "timestamp_t was padded"); // Temporal values need to round down when changing precision, -// but C/C++ rounds towards 0 when you simply divide. +// but C/C++ rounds towrds 0 when you simply divide. // This piece of bit banging solves that problem. template static inline T TemporalRound(T value, T scale) { @@ -110,13 +111,12 @@ TimestampCastResult Timestamp::TryConvertTimestampTZ(const char *str, idx_t len, } if (pos < len) { // skip a "Z" at the end (as per the ISO8601 specs) - int hh, mm, ss; + int hour_offset, minute_offset; if (str[pos] == 'Z') { pos++; has_offset = true; - } else if (Timestamp::TryParseUTCOffset(str, pos, len, hh, mm, ss)) { - const int64_t delta = - hh * Interval::MICROS_PER_HOUR + mm * Interval::MICROS_PER_MINUTE + ss * Interval::MICROS_PER_SEC; + } else if (Timestamp::TryParseUTCOffset(str, pos, len, hour_offset, minute_offset)) { + const int64_t delta = hour_offset * Interval::MICROS_PER_HOUR + minute_offset * Interval::MICROS_PER_MINUTE; if (!TrySubtractOperator::Operation(result.value, delta, result.value)) { return TimestampCastResult::ERROR_RANGE; } @@ -149,7 +149,7 @@ TimestampCastResult Timestamp::TryConvertTimestampTZ(const char *str, idx_t len, } TimestampCastResult Timestamp::TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result, - optional_ptr nanos, bool strict) { + optional_ptr nanos) { string_t tz(nullptr, 0); bool has_offset = false; // We don't understand TZ without an extension, so fail if one was provided. @@ -159,9 +159,6 @@ TimestampCastResult Timestamp::TryConvertTimestamp(const char *str, idx_t len, t } if (tz.GetSize() == 0) { // no timezone provided - success! - if (strict && has_offset) { - return TimestampCastResult::STRICT_UTC; - } return TimestampCastResult::SUCCESS; } if (tz.GetSize() == 3) { @@ -169,9 +166,6 @@ TimestampCastResult Timestamp::TryConvertTimestamp(const char *str, idx_t len, t auto tz_ptr = tz.GetData(); if ((tz_ptr[0] == 'u' || tz_ptr[0] == 'U') && (tz_ptr[1] == 't' || tz_ptr[1] == 'T') && (tz_ptr[2] == 'c' || tz_ptr[2] == 'C')) { - if (strict && has_offset) { - return TimestampCastResult::STRICT_UTC; - } return TimestampCastResult::SUCCESS; } } @@ -209,7 +203,7 @@ TimestampCastResult Timestamp::TryConvertTimestamp(const char *str, idx_t len, t string Timestamp::FormatError(const string &str) { return StringUtil::Format("invalid timestamp field format: \"%s\", " - "expected format is (YYYY-MM-DD HH:MM:SS[.US][±HH[:MM[:SS]]| ZONE])", + "expected format is (YYYY-MM-DD HH:MM:SS[.US][±HH:MM| ZONE])", str); } @@ -239,7 +233,6 @@ timestamp_t Timestamp::FromCString(const char *str, idx_t len, optional_ptr len) { @@ -270,9 +262,9 @@ bool Timestamp::TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &h // expected +HH or -HH return false; } - hh = (str[curpos] - '0') * 10 + (str[curpos + 1] - '0'); + hour_offset = (str[curpos] - '0') * 10 + (str[curpos + 1] - '0'); if (sign_char == '-') { - hh = -hh; + hour_offset = -hour_offset; } curpos += 2; @@ -282,8 +274,7 @@ bool Timestamp::TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &h pos = curpos; return true; } - const bool colons_used = (str[curpos] == ':'); - if (colons_used) { + if (str[curpos] == ':') { curpos++; } if (curpos + 2 > len || !StringUtil::CharacterIsDigit(str[curpos]) || @@ -293,33 +284,11 @@ bool Timestamp::TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &h return true; } // we have an MM specifier: parse it - mm = (str[curpos] - '0') * 10 + (str[curpos + 1] - '0'); - if (sign_char == '-') { - mm = -mm; - } - curpos += 2; - - // optional seconds specifier: must be ":SS" - if (curpos >= len || !colons_used || (str[curpos] != ':')) { - // done, nothing left - pos = curpos; - return true; - } - // Skip colon and read seconds - curpos++; - if (curpos + 2 > len || !StringUtil::CharacterIsDigit(str[curpos]) || - !StringUtil::CharacterIsDigit(str[curpos + 1])) { - // no SS specifier - pos = curpos; - return true; - } - // we have an SS specifier: parse it - ss = (str[curpos] - '0') * 10 + (str[curpos + 1] - '0'); + minute_offset = (str[curpos] - '0') * 10 + (str[curpos + 1] - '0'); if (sign_char == '-') { - ss = -ss; + minute_offset = -minute_offset; } pos = curpos + 2; - return true; } @@ -535,16 +504,4 @@ double Timestamp::GetJulianDay(timestamp_t timestamp) { return result; } -TimestampComponents Timestamp::GetComponents(timestamp_t timestamp) { - date_t date; - dtime_t time; - - Convert(timestamp, date, time); - - TimestampComponents result; - Date::Convert(date, result.year, result.month, result.day); - Time::Convert(time, result.hour, result.minute, result.second, result.microsecond); - return result; -} - } // namespace duckdb diff --git a/src/duckdb/src/common/types/uuid.cpp b/src/duckdb/src/common/types/uuid.cpp index 79875fba4..a0196ae81 100644 --- a/src/duckdb/src/common/types/uuid.cpp +++ b/src/duckdb/src/common/types/uuid.cpp @@ -3,10 +3,7 @@ namespace duckdb { -////////////////// -// Base UUID -////////////////// -bool BaseUUID::FromString(const string &str, hugeint_t &result) { +bool UUID::FromString(const string &str, hugeint_t &result) { auto hex2char = [](char ch) -> unsigned char { if (ch >= '0' && ch <= '9') { return UnsafeNumericCast(ch - '0'); @@ -56,7 +53,7 @@ bool BaseUUID::FromString(const string &str, hugeint_t &result) { return count == 32; } -void BaseUUID::ToString(hugeint_t input, char *buf) { +void UUID::ToString(hugeint_t input, char *buf) { auto byte_to_hex = [](uint64_t byte_val, char *buf, idx_t &pos) { D_ASSERT(byte_val <= 0xFF); static char const HEX_DIGITS[] = "0123456789abcdef"; @@ -89,7 +86,7 @@ void BaseUUID::ToString(hugeint_t input, char *buf) { byte_to_hex(input.lower & 0xFF, buf, pos); } -hugeint_t BaseUUID::FromUHugeint(uhugeint_t input) { +hugeint_t UUID::FromUHugeint(uhugeint_t input) { hugeint_t result; result.lower = input.lower; if (input.upper > uint64_t(NumericLimits::Maximum())) { @@ -100,7 +97,7 @@ hugeint_t BaseUUID::FromUHugeint(uhugeint_t input) { return result; } -uhugeint_t BaseUUID::ToUHugeint(hugeint_t input) { +uhugeint_t UUID::ToUHugeint(hugeint_t input) { uhugeint_t result; result.lower = input.lower; if (input.upper >= 0) { @@ -111,7 +108,18 @@ uhugeint_t BaseUUID::ToUHugeint(hugeint_t input) { return result; } -hugeint_t BaseUUID::Convert(const std::array &bytes) { +hugeint_t UUID::GenerateRandomUUID(RandomEngine &engine) { + uint8_t bytes[16]; + for (int i = 0; i < 16; i += 4) { + *reinterpret_cast(bytes + i) = engine.NextRandomInteger(); + } + // variant must be 10xxxxxx + bytes[8] &= 0xBF; + bytes[8] |= 0x80; + // version must be 0100xxxx + bytes[6] &= 0x4F; + bytes[6] |= 0x40; + hugeint_t result; result.upper = 0; result.upper |= ((int64_t)bytes[0] << 56); @@ -134,75 +142,7 @@ hugeint_t BaseUUID::Convert(const std::array &bytes) { return result; } -////////////////// -// UUIDv4 -////////////////// -hugeint_t UUIDv4::GenerateRandomUUID(RandomEngine &engine) { - std::array bytes; - for (int i = 0; i < 16; i += 4) { - *reinterpret_cast(bytes.data() + i) = engine.NextRandomInteger(); - } - // variant must be 10xxxxxx - bytes[8] &= 0xBF; - bytes[8] |= 0x80; - // version must be 0100xxxx - bytes[6] &= 0x4F; - bytes[6] |= 0x40; - - return Convert(bytes); -} - -hugeint_t UUIDv4::GenerateRandomUUID() { - RandomEngine engine; - return GenerateRandomUUID(engine); -} - -////////////////// -// UUIDv7 -////////////////// -hugeint_t UUIDv7::GenerateRandomUUID(RandomEngine &engine) { - std::array bytes; // Intentionally no initialization. - - const auto now = std::chrono::system_clock::now(); - const auto time_ns = std::chrono::time_point_cast(now); - const auto unix_ts_ns = static_cast(time_ns.time_since_epoch().count()); - - // Begins with a 48 bit big-endian Unix Epoch timestamp with millisecond granularity. - static constexpr uint64_t kNanoToMilli = 1000000; - const uint64_t unix_ts_ms = unix_ts_ns / kNanoToMilli; - bytes[0] = static_cast(unix_ts_ms >> 40); - bytes[1] = static_cast(unix_ts_ms >> 32); - bytes[2] = static_cast(unix_ts_ms >> 24); - bytes[3] = static_cast(unix_ts_ms >> 16); - bytes[4] = static_cast(unix_ts_ms >> 8); - bytes[5] = static_cast(unix_ts_ms); - - // Fill in random bits. - const uint32_t random_a = engine.NextRandomInteger(); - const uint32_t random_b = engine.NextRandomInteger(); - const uint32_t random_c = engine.NextRandomInteger(); - bytes[6] = static_cast(random_a >> 24); - bytes[7] = static_cast(random_a >> 16); - bytes[8] = static_cast(random_a >> 8); - bytes[9] = static_cast(random_a); - bytes[10] = static_cast(random_b >> 24); - bytes[11] = static_cast(random_b >> 16); - bytes[12] = static_cast(random_b >> 8); - bytes[13] = static_cast(random_b); - bytes[14] = static_cast(random_c >> 24); - bytes[15] = static_cast(random_c >> 16); - - // Fill in version number. - constexpr uint8_t kVersion = 7; - bytes[6] = (bytes[6] & 0x0f) | (kVersion << 4); - - // Fill in variant field. - bytes[8] = (bytes[8] & 0x3f) | 0x80; - - return Convert(bytes); -} - -hugeint_t UUIDv7::GenerateRandomUUID() { +hugeint_t UUID::GenerateRandomUUID() { RandomEngine engine; return GenerateRandomUUID(engine); } diff --git a/src/duckdb/src/common/types/value.cpp b/src/duckdb/src/common/types/value.cpp index 42c50a829..4e8566c9a 100644 --- a/src/duckdb/src/common/types/value.cpp +++ b/src/duckdb/src/common/types/value.cpp @@ -1347,7 +1347,19 @@ Value Value::Numeric(const LogicalType &type, int64_t value) { case LogicalTypeId::TIMESTAMP_TZ: return Value::TIMESTAMPTZ(timestamp_tz_t(value)); case LogicalTypeId::ENUM: - return Value::ENUM(NumericCast(value), type); + switch (type.InternalType()) { + case PhysicalType::UINT8: + D_ASSERT(value >= NumericLimits::Minimum() && value <= NumericLimits::Maximum()); + return Value::UTINYINT((uint8_t)value); + case PhysicalType::UINT16: + D_ASSERT(value >= NumericLimits::Minimum() && value <= NumericLimits::Maximum()); + return Value::USMALLINT((uint16_t)value); + case PhysicalType::UINT32: + D_ASSERT(value >= NumericLimits::Minimum() && value <= NumericLimits::Maximum()); + return Value::UINTEGER((uint32_t)value); + default: + throw InternalException("Enum doesn't accept this physical type"); + } default: throw InvalidTypeException(type, "Numeric requires numeric type"); } diff --git a/src/duckdb/src/common/types/vector.cpp b/src/duckdb/src/common/types/vector.cpp index be6318a28..722b8b699 100644 --- a/src/duckdb/src/common/types/vector.cpp +++ b/src/duckdb/src/common/types/vector.cpp @@ -25,6 +25,7 @@ #include "fsst.h" #include // strlen() on Solaris + namespace duckdb { UnifiedVectorFormat::UnifiedVectorFormat() : sel(nullptr), data(nullptr) { @@ -160,13 +161,7 @@ void Vector::Reinterpret(const Vector &other) { D_ASSERT((not_nested && type_size_equal) || type_is_same); #endif AssignSharedPointer(buffer, other.buffer); - if (vector_type == VectorType::DICTIONARY_VECTOR) { - Vector new_vector(GetType(), nullptr); - new_vector.Reinterpret(DictionaryVector::Child(other)); - auxiliary = make_shared_ptr(std::move(new_vector)); - } else { - AssignSharedPointer(auxiliary, other.auxiliary); - } + AssignSharedPointer(auxiliary, other.auxiliary); data = other.data; validity = other.validity; } @@ -412,7 +407,7 @@ void Vector::Resize(idx_t current_size, idx_t new_size) { } // Copy the data buffer to a resized buffer. - auto new_data = Allocator::DefaultAllocator().Allocate(target_size); + auto new_data = make_unsafe_uniq_array_uninitialized(target_size); memcpy(new_data.get(), resize_info_entry.data, old_size); resize_info_entry.buffer->SetData(std::move(new_data)); resize_info_entry.vec.data = resize_info_entry.buffer->GetData(); @@ -439,6 +434,7 @@ void Vector::SetValue(idx_t index, const Value &val) { } D_ASSERT(val.IsNull() || (val.type().InternalType() == GetType().InternalType())); + validity.EnsureWritable(); validity.Set(index, !val.IsNull()); auto physical_type = GetType().InternalType(); if (val.IsNull() && !IsStructOrArrayRecursive(GetType())) { @@ -1211,61 +1207,10 @@ void Vector::Sequence(int64_t start, int64_t increment, idx_t count) { } // FIXME: This should ideally be const -void Vector::Serialize(Serializer &serializer, idx_t count, bool compressed_serialization) { +void Vector::Serialize(Serializer &serializer, idx_t count) { auto &logical_type = GetType(); UnifiedVectorFormat vdata; - - // serialize compressed vectors to save space, but skip this if serializing into older versions - if (!serializer.ShouldSerialize(5)) { - compressed_serialization = false; - } - if (compressed_serialization) { - auto vtype = GetVectorType(); - if (vtype == VectorType::DICTIONARY_VECTOR && DictionaryVector::DictionarySize(*this).IsValid()) { - auto dict = DictionaryVector::Child(*this); - if (dict.GetVectorType() == VectorType::FLAT_VECTOR) { - idx_t dict_count = DictionaryVector::DictionarySize(*this).GetIndex(); - auto old_sel = DictionaryVector::SelVector(*this); - SelectionVector new_sel(count), used_sel(count), map_sel(dict_count); - - // dictionaries may be large (row-group level). A vector may use only a small part. - // So, restrict dict to the used_sel subset & remap old_sel into new_sel to the new dict positions - sel_t CODE_UNSEEN = static_cast(dict_count); - for (sel_t i = 0; i < dict_count; ++i) { - map_sel[i] = CODE_UNSEEN; // initialize with unused marker - } - idx_t used_count = 0; - for (idx_t i = 0; i < count; ++i) { - auto pos = old_sel[i]; - if (map_sel[pos] == CODE_UNSEEN) { - map_sel[pos] = static_cast(used_count); - used_sel[used_count++] = pos; - } - new_sel[i] = map_sel[pos]; - } - if (used_count * 2 < count) { // only serialize as a dict vector if that makes things smaller - auto sel_data = reinterpret_cast(new_sel.data()); - dict.Slice(used_sel, used_count); - serializer.WriteProperty(90, "vector_type", VectorType::DICTIONARY_VECTOR); - serializer.WriteProperty(91, "sel_vector", sel_data, sizeof(sel_t) * count); - serializer.WriteProperty(92, "dict_count", used_count); - return dict.Serialize(serializer, used_count, false); - } - } - } else if (vtype == VectorType::CONSTANT_VECTOR && count >= 1) { - serializer.WriteProperty(90, "vector_type", VectorType::CONSTANT_VECTOR); - return Vector::Serialize(serializer, 1, false); // just serialize one value - } else if (vtype == VectorType::SEQUENCE_VECTOR) { - serializer.WriteProperty(90, "vector_type", VectorType::SEQUENCE_VECTOR); - auto data = reinterpret_cast(buffer->GetData()); - serializer.WriteProperty(91, "seq_start", data[0]); - serializer.WriteProperty(92, "seq_increment", data[1]); - return; // for sequence vectors we do not serialize anything else - } else { - // TODO: other compressed vector types (FSST) - } - } ToUnifiedFormat(count, vdata); const bool has_validity_mask = (count > 0) && !vdata.validity.AllValid(); @@ -1304,8 +1249,7 @@ void Vector::Serialize(Serializer &serializer, idx_t count, bool compressed_seri // Serialize entries as a list serializer.WriteList(103, "children", entries.size(), [&](Serializer::List &list, idx_t i) { - list.WriteObject( - [&](Serializer &object) { entries[i]->Serialize(object, count, compressed_serialization); }); + list.WriteObject([&](Serializer &object) { entries[i]->Serialize(object, count); }); }); break; } @@ -1334,9 +1278,7 @@ void Vector::Serialize(Serializer &serializer, idx_t count, bool compressed_seri object.WriteProperty(101, "length", entries[i].length); }); }); - serializer.WriteObject(106, "child", [&](Serializer &object) { - child.Serialize(object, list_size, compressed_serialization); - }); + serializer.WriteObject(106, "child", [&](Serializer &object) { child.Serialize(object, list_size); }); break; } case PhysicalType::ARRAY: { @@ -1347,9 +1289,7 @@ void Vector::Serialize(Serializer &serializer, idx_t count, bool compressed_seri auto array_size = ArrayType::GetSize(serialized_vector.GetType()); auto child_size = array_size * count; serializer.WriteProperty(103, "array_size", array_size); - serializer.WriteObject(104, "child", [&](Serializer &object) { - child.Serialize(object, child_size, compressed_serialization); - }); + serializer.WriteObject(104, "child", [&](Serializer &object) { child.Serialize(object, child_size); }); break; } default: @@ -1360,27 +1300,6 @@ void Vector::Serialize(Serializer &serializer, idx_t count, bool compressed_seri void Vector::Deserialize(Deserializer &deserializer, idx_t count) { auto &logical_type = GetType(); - const auto vtype = // older versions that only supported flat vectors did not serialize vector_type, - deserializer.ReadPropertyWithExplicitDefault(90, "vector_type", VectorType::FLAT_VECTOR); - - // first handle deserialization of compressed vector types - if (vtype == VectorType::CONSTANT_VECTOR) { - Vector::Deserialize(deserializer, 1); // read a vector of size 1 - Vector::SetVectorType(VectorType::CONSTANT_VECTOR); - return; - } else if (vtype == VectorType::DICTIONARY_VECTOR) { - SelectionVector sel(count); - deserializer.ReadProperty(91, "sel_vector", reinterpret_cast(sel.data()), sizeof(sel_t) * count); - const auto dict_count = deserializer.ReadProperty(92, "dict_count"); - Vector::Deserialize(deserializer, dict_count); // deserialize the dictionary in this vector - Vector::Slice(sel, count); // will create a dictionary vector - return; - } else if (vtype == VectorType::SEQUENCE_VECTOR) { - const int64_t seq_start = deserializer.ReadProperty(91, "seq_start"); - const int64_t seq_increment = deserializer.ReadProperty(92, "seq_increment"); - Vector::Sequence(seq_start, seq_increment, count); - return; - } auto &validity = FlatVector::Validity(*this); auto validity_count = MaxValue(count, STANDARD_VECTOR_SIZE); @@ -1602,7 +1521,7 @@ void Vector::Verify(Vector &vector_p, const SelectionVector &sel_p, idx_t count) auto oidx = sel->get_index(i); if (validity.RowIsValid(oidx)) { auto buf = strings[oidx].GetData(); - D_ASSERT(idx_t(*buf) < 8); + D_ASSERT(*buf >= 0 && *buf < 8); Bit::Verify(strings[oidx]); } } @@ -2046,25 +1965,17 @@ string_t StringVector::AddString(Vector &vector, const string &data) { return StringVector::AddString(vector, string_t(data.c_str(), UnsafeNumericCast(data.size()))); } -VectorStringBuffer &StringVector::GetStringBuffer(Vector &vector) { - if (vector.GetType().InternalType() != PhysicalType::VARCHAR) { - throw InternalException("StringVector::GetStringBuffer - vector is not of internal type VARCHAR but of type %s", - vector.GetType()); - } - if (!vector.auxiliary) { - vector.auxiliary = make_buffer(); - } - D_ASSERT(vector.auxiliary->GetBufferType() == VectorBufferType::STRING_BUFFER); - return vector.auxiliary.get()->Cast(); -} - string_t StringVector::AddString(Vector &vector, string_t data) { D_ASSERT(vector.GetType().id() == LogicalTypeId::VARCHAR || vector.GetType().id() == LogicalTypeId::BIT); if (data.IsInlined()) { // string will be inlined: no need to store in string heap return data; } - auto &string_buffer = GetStringBuffer(vector); + if (!vector.auxiliary) { + vector.auxiliary = make_buffer(); + } + D_ASSERT(vector.auxiliary->GetBufferType() == VectorBufferType::STRING_BUFFER); + auto &string_buffer = vector.auxiliary.get()->Cast(); return string_buffer.AddString(data); } @@ -2074,7 +1985,11 @@ string_t StringVector::AddStringOrBlob(Vector &vector, string_t data) { // string will be inlined: no need to store in string heap return data; } - auto &string_buffer = GetStringBuffer(vector); + if (!vector.auxiliary) { + vector.auxiliary = make_buffer(); + } + D_ASSERT(vector.auxiliary->GetBufferType() == VectorBufferType::STRING_BUFFER); + auto &string_buffer = vector.auxiliary.get()->Cast(); return string_buffer.AddBlob(data); } @@ -2083,18 +1998,30 @@ string_t StringVector::EmptyString(Vector &vector, idx_t len) { if (len <= string_t::INLINE_LENGTH) { return string_t(UnsafeNumericCast(len)); } - auto &string_buffer = GetStringBuffer(vector); + if (!vector.auxiliary) { + vector.auxiliary = make_buffer(); + } + D_ASSERT(vector.auxiliary->GetBufferType() == VectorBufferType::STRING_BUFFER); + auto &string_buffer = vector.auxiliary.get()->Cast(); return string_buffer.EmptyString(len); } void StringVector::AddHandle(Vector &vector, BufferHandle handle) { - auto &string_buffer = GetStringBuffer(vector); + D_ASSERT(vector.GetType().InternalType() == PhysicalType::VARCHAR); + if (!vector.auxiliary) { + vector.auxiliary = make_buffer(); + } + auto &string_buffer = vector.auxiliary->Cast(); string_buffer.AddHeapReference(make_buffer(std::move(handle))); } void StringVector::AddBuffer(Vector &vector, buffer_ptr buffer) { + D_ASSERT(vector.GetType().InternalType() == PhysicalType::VARCHAR); D_ASSERT(buffer.get() != vector.auxiliary.get()); - auto &string_buffer = GetStringBuffer(vector); + if (!vector.auxiliary) { + vector.auxiliary = make_buffer(); + } + auto &string_buffer = vector.auxiliary->Cast(); string_buffer.AddHeapReference(std::move(buffer)); } @@ -2197,15 +2124,15 @@ void FSSTVector::DecompressVector(const Vector &src, Vector &dst, idx_t src_offs auto dst_mask = FlatVector::Validity(dst); auto ldata = FSSTVector::GetCompressedData(src); auto tdata = FlatVector::GetData(dst); - auto &str_buffer = StringVector::GetStringBuffer(dst); for (idx_t i = 0; i < copy_count; i++) { auto source_idx = sel->get_index(src_offset + i); auto target_idx = dst_offset + i; string_t compressed_string = ldata[source_idx]; if (dst_mask.RowIsValid(target_idx) && compressed_string.GetSize() > 0) { auto decoder = FSSTVector::GetDecoder(src); - tdata[target_idx] = FSSTPrimitives::DecompressValue(decoder, str_buffer, compressed_string.GetData(), - compressed_string.GetSize()); + auto &decompress_buffer = FSSTVector::GetDecompressBuffer(src); + tdata[target_idx] = FSSTPrimitives::DecompressValue(decoder, dst, compressed_string.GetData(), + compressed_string.GetSize(), decompress_buffer); } else { tdata[target_idx] = string_t(nullptr, 0); } diff --git a/src/duckdb/src/common/virtual_file_system.cpp b/src/duckdb/src/common/virtual_file_system.cpp index 587316b3a..74892a4e0 100644 --- a/src/duckdb/src/common/virtual_file_system.cpp +++ b/src/duckdb/src/common/virtual_file_system.cpp @@ -139,26 +139,6 @@ void VirtualFileSystem::RegisterSubSystem(FileCompressionType compression_type, compressed_fs[compression_type] = std::move(fs); } -unique_ptr VirtualFileSystem::ExtractSubSystem(const string &name) { - // If the subsystem has been disabled, we don't allow extraction and return nullptr here. - if (disabled_file_systems.find(name) != disabled_file_systems.end()) { - return nullptr; - } - - unique_ptr extracted_filesystem; - for (auto iter = sub_systems.begin(); iter != sub_systems.end(); ++iter) { - auto &cur_filesystem = *iter; - if (cur_filesystem->GetName() == name) { - extracted_filesystem = std::move(cur_filesystem); - sub_systems.erase(iter); - return extracted_filesystem; - } - } - - // Requested subfilesystem is not registered. - return nullptr; -} - vector VirtualFileSystem::ListSubSystems() { vector names(sub_systems.size()); for (idx_t i = 0; i < sub_systems.size(); i++) { diff --git a/src/duckdb/src/execution/adaptive_filter.cpp b/src/duckdb/src/execution/adaptive_filter.cpp index b67423f56..6077ae3ff 100644 --- a/src/duckdb/src/execution/adaptive_filter.cpp +++ b/src/duckdb/src/execution/adaptive_filter.cpp @@ -1,5 +1,4 @@ #include "duckdb/planner/expression/bound_conjunction_expression.hpp" -#include "duckdb/optimizer/expression_heuristics.hpp" #include "duckdb/execution/adaptive_filter.hpp" #include "duckdb/planner/table_filter.hpp" #include "duckdb/common/numeric_utils.hpp" @@ -24,10 +23,11 @@ AdaptiveFilter::AdaptiveFilter(const Expression &expr) : observe_interval(10), e AdaptiveFilter::AdaptiveFilter(const TableFilterSet &table_filters) : observe_interval(10), execute_interval(20), warmup(true) { - permutation = ExpressionHeuristics::GetInitialOrder(table_filters); - for (idx_t idx = 1; idx < table_filters.filters.size(); idx++) { + for (idx_t idx = 0; idx < table_filters.filters.size(); idx++) { + permutation.push_back(idx); swap_likeliness.push_back(100); } + swap_likeliness.pop_back(); right_random_border = 100 * (table_filters.filters.size() - 1); } diff --git a/src/duckdb/src/execution/aggregate_hashtable.cpp b/src/duckdb/src/execution/aggregate_hashtable.cpp index ae74060a2..96b9d1f18 100644 --- a/src/duckdb/src/execution/aggregate_hashtable.cpp +++ b/src/duckdb/src/execution/aggregate_hashtable.cpp @@ -29,30 +29,26 @@ GroupedAggregateHashTable::GroupedAggregateHashTable(ClientContext &context, All : GroupedAggregateHashTable(context, allocator, std::move(group_types), {}, vector()) { } -GroupedAggregateHashTable::AggregateHTAppendState::AggregateHTAppendState(ArenaAllocator &allocator) - : hashes(LogicalType::HASH), ht_offsets(LogicalType::UBIGINT), hash_salts(LogicalType::HASH), - group_compare_vector(STANDARD_VECTOR_SIZE), no_match_vector(STANDARD_VECTOR_SIZE), - empty_vector(STANDARD_VECTOR_SIZE), new_groups(STANDARD_VECTOR_SIZE), addresses(LogicalType::POINTER), - row_state(allocator) { +GroupedAggregateHashTable::AggregateHTAppendState::AggregateHTAppendState() + : ht_offsets(LogicalType::UBIGINT), hash_salts(LogicalType::HASH), group_compare_vector(STANDARD_VECTOR_SIZE), + no_match_vector(STANDARD_VECTOR_SIZE), empty_vector(STANDARD_VECTOR_SIZE), new_groups(STANDARD_VECTOR_SIZE), + addresses(LogicalType::POINTER) { } -GroupedAggregateHashTable::GroupedAggregateHashTable(ClientContext &context_p, Allocator &allocator, +GroupedAggregateHashTable::GroupedAggregateHashTable(ClientContext &context, Allocator &allocator, vector group_types_p, vector payload_types_p, vector aggregate_objects_p, idx_t initial_capacity, idx_t radix_bits) - : BaseAggregateHashTable(context_p, allocator, aggregate_objects_p, std::move(payload_types_p)), context(context_p), + : BaseAggregateHashTable(context, allocator, aggregate_objects_p, std::move(payload_types_p)), radix_bits(radix_bits), count(0), capacity(0), skip_lookups(false), - aggregate_allocator(make_shared_ptr(allocator)), state(*aggregate_allocator) { + aggregate_allocator(make_shared_ptr(allocator)) { // Append hash column to the end and initialise the row layout group_types_p.emplace_back(LogicalType::HASH); + layout.Initialize(std::move(group_types_p), std::move(aggregate_objects_p)); - auto layout = make_shared_ptr(); - layout->Initialize(std::move(group_types_p), std::move(aggregate_objects_p)); - layout_ptr = std::move(layout); - - hash_offset = layout_ptr->GetOffsets()[layout_ptr->ColumnCount() - 1]; + hash_offset = layout.GetOffsets()[layout.ColumnCount() - 1]; // Partitioned data and pointer table InitializePartitionedData(); @@ -62,8 +58,8 @@ GroupedAggregateHashTable::GroupedAggregateHashTable(ClientContext &context_p, A Resize(initial_capacity); // Predicates - predicates.resize(layout_ptr->ColumnCount() - 1, ExpressionType::COMPARE_NOT_DISTINCT_FROM); - row_matcher.Initialize(true, *layout_ptr, predicates); + predicates.resize(layout.ColumnCount() - 1, ExpressionType::COMPARE_NOT_DISTINCT_FROM); + row_matcher.Initialize(true, layout, predicates); } void GroupedAggregateHashTable::InitializePartitionedData() { @@ -71,14 +67,14 @@ void GroupedAggregateHashTable::InitializePartitionedData() { RadixPartitioning::RadixBitsOfPowerOfTwo(partitioned_data->PartitionCount()) != radix_bits) { D_ASSERT(!partitioned_data || partitioned_data->Count() == 0); partitioned_data = - make_uniq(buffer_manager, layout_ptr, radix_bits, layout_ptr->ColumnCount() - 1); + make_uniq(buffer_manager, layout, radix_bits, layout.ColumnCount() - 1); } else { partitioned_data->Reset(); } - D_ASSERT(GetLayout().GetAggrWidth() == layout_ptr->GetAggrWidth()); - D_ASSERT(GetLayout().GetDataWidth() == layout_ptr->GetDataWidth()); - D_ASSERT(GetLayout().GetRowWidth() == layout_ptr->GetRowWidth()); + D_ASSERT(GetLayout().GetAggrWidth() == layout.GetAggrWidth()); + D_ASSERT(GetLayout().GetDataWidth() == layout.GetDataWidth()); + D_ASSERT(GetLayout().GetRowWidth() == layout.GetRowWidth()); partitioned_data->InitializeAppendState(state.partitioned_append_state, TupleDataPinProperties::KEEP_EVERYTHING_PINNED); @@ -88,7 +84,7 @@ void GroupedAggregateHashTable::InitializeUnpartitionedData() { D_ASSERT(radix_bits >= UNPARTITIONED_RADIX_BITS_THRESHOLD); if (!unpartitioned_data) { unpartitioned_data = - make_uniq(buffer_manager, layout_ptr, 0ULL, layout_ptr->ColumnCount() - 1); + make_uniq(buffer_manager, layout, 0ULL, layout.ColumnCount() - 1); } else { unpartitioned_data->Reset(); } @@ -110,7 +106,7 @@ unique_ptr GroupedAggregateHashTable::AcquirePartitionedDa if (unpartitioned_data) { unpartitioned_data->FlushAppendState(state.unpartitioned_append_state); unpartitioned_data->Unpin(); - unpartitioned_data->Repartition(context, *partitioned_data); + unpartitioned_data->Repartition(*partitioned_data); } InitializeUnpartitionedData(); } @@ -127,7 +123,7 @@ void GroupedAggregateHashTable::Abandon() { if (unpartitioned_data) { unpartitioned_data->FlushAppendState(state.unpartitioned_append_state); unpartitioned_data->Unpin(); - unpartitioned_data->Repartition(context, *partitioned_data); + unpartitioned_data->Repartition(*partitioned_data); } InitializeUnpartitionedData(); } @@ -143,7 +139,7 @@ void GroupedAggregateHashTable::Abandon() { void GroupedAggregateHashTable::Repartition() { auto old = AcquirePartitionedData(); D_ASSERT(old->GetPartitions().size() != partitioned_data->GetPartitions().size()); - old->Repartition(context, *partitioned_data); + old->Repartition(*partitioned_data); } shared_ptr GroupedAggregateHashTable::GetAggregateAllocator() { @@ -155,13 +151,14 @@ GroupedAggregateHashTable::~GroupedAggregateHashTable() { } void GroupedAggregateHashTable::Destroy() { - if (!partitioned_data || partitioned_data->Count() == 0 || !layout_ptr->HasDestructor()) { + if (!partitioned_data || partitioned_data->Count() == 0 || !layout.HasDestructor()) { return; } // There are aggregates with destructors: Call the destructor for each of the aggregates // Currently does not happen because aggregate destructors are called while scanning in RadixPartitionedHashTable // LCOV_EXCL_START + RowOperationsState row_state(*aggregate_allocator); for (auto &data_collection : partitioned_data->GetPartitions()) { if (data_collection->Count() == 0) { continue; @@ -169,17 +166,13 @@ void GroupedAggregateHashTable::Destroy() { TupleDataChunkIterator iterator(*data_collection, TupleDataPinProperties::DESTROY_AFTER_DONE, false); auto &row_locations = iterator.GetChunkState().row_locations; do { - RowOperations::DestroyStates(state.row_state, *layout_ptr, row_locations, iterator.GetCurrentChunkCount()); + RowOperations::DestroyStates(row_state, layout, row_locations, iterator.GetCurrentChunkCount()); } while (iterator.Next()); data_collection->Reset(); } // LCOV_EXCL_STOP } -shared_ptr GroupedAggregateHashTable::GetLayoutPtr() { - return partitioned_data->GetLayoutPtr(); -} - const TupleDataLayout &GroupedAggregateHashTable::GetLayout() const { return partitioned_data->GetLayout(); } @@ -306,7 +299,7 @@ void GroupedAggregateHashTable::ReinsertTuples(PartitionedTupleData &data) { idx_t GroupedAggregateHashTable::AddChunk(DataChunk &groups, DataChunk &payload, AggregateType filter) { unsafe_vector aggregate_filter; - auto &aggregates = layout_ptr->GetAggregates(); + auto &aggregates = layout.GetAggregates(); for (idx_t i = 0; i < aggregates.size(); i++) { auto &aggregate = aggregates[i]; if (aggregate.aggr_type == filter) { @@ -394,7 +387,7 @@ optional_idx GroupedAggregateHashTable::TryAddDictionaryGroups(DataChunk &groups // add the dictionary groups to the hash table new_group_count = FindOrCreateGroups(unique_values, hashes, new_dictionary_pointers, state.new_groups); } - auto &aggregates = layout_ptr->GetAggregates(); + auto &aggregates = layout.GetAggregates(); if (aggregates.empty()) { // early-out - no aggregates to update return new_group_count; @@ -407,7 +400,7 @@ optional_idx GroupedAggregateHashTable::TryAddDictionaryGroups(DataChunk &groups auto dict_addresses = FlatVector::GetData(dictionary_addresses); for (idx_t i = 0; i < unique_count; i++) { auto dict_idx = unique_entries.get_index(i); - dict_addresses[dict_idx] = new_dict_addresses[i] + layout_ptr->GetAggrOffset(); + dict_addresses[dict_idx] = new_dict_addresses[i] + layout.GetAggrOffset(); } // now set up the addresses for the aggregates auto result_addresses = FlatVector::GetData(state.addresses); @@ -447,7 +440,7 @@ optional_idx GroupedAggregateHashTable::TryAddConstantGroups(DataChunk &groups, auto &new_dictionary_pointers = dict_state.new_dictionary_pointers; auto new_group_count = FindOrCreateGroups(unique_values, hashes, new_dictionary_pointers, state.new_groups); - auto &aggregates = layout_ptr->GetAggregates(); + auto &aggregates = layout.GetAggregates(); if (aggregates.empty()) { // early-out - no aggregates to update return new_group_count; @@ -455,7 +448,7 @@ optional_idx GroupedAggregateHashTable::TryAddConstantGroups(DataChunk &groups, auto new_dict_addresses = FlatVector::GetData(new_dictionary_pointers); auto result_addresses = FlatVector::GetData(state.addresses); - uintptr_t aggregate_address = new_dict_addresses[0] + layout_ptr->GetAggrOffset(); + uintptr_t aggregate_address = new_dict_addresses[0] + layout.GetAggrOffset(); for (idx_t i = 0; i < payload.size(); i++) { result_addresses[i] = aggregate_address; } @@ -488,16 +481,18 @@ idx_t GroupedAggregateHashTable::AddChunk(DataChunk &groups, DataChunk &payload, return result.GetIndex(); } // otherwise append the raw values - groups.Hash(state.hashes); + Vector hashes(LogicalType::HASH); + groups.Hash(hashes); - return AddChunk(groups, state.hashes, payload, filter); + return AddChunk(groups, hashes, payload, filter); } void GroupedAggregateHashTable::UpdateAggregates(DataChunk &payload, const unsafe_vector &filter) { // Now every cell has an entry, update the aggregates - auto &aggregates = layout_ptr->GetAggregates(); + auto &aggregates = layout.GetAggregates(); idx_t filter_idx = 0; idx_t payload_idx = 0; + RowOperationsState row_state(*aggregate_allocator); for (idx_t i = 0; i < aggregates.size(); i++) { auto &aggr = aggregates[i]; if (filter_idx >= filter.size() || i < filter[filter_idx]) { @@ -509,10 +504,10 @@ void GroupedAggregateHashTable::UpdateAggregates(DataChunk &payload, const unsaf D_ASSERT(i == filter[filter_idx]); if (aggr.aggr_type != AggregateType::DISTINCT && aggr.filter) { - RowOperations::UpdateFilteredStates(state.row_state, filter_set.GetFilterData(i), aggr, state.addresses, - payload, payload_idx); + RowOperations::UpdateFilteredStates(row_state, filter_set.GetFilterData(i), aggr, state.addresses, payload, + payload_idx); } else { - RowOperations::UpdateStates(state.row_state, aggr, state.addresses, payload, payload_idx, payload.size()); + RowOperations::UpdateStates(row_state, aggr, state.addresses, payload, payload_idx, payload.size()); } // Move to the next aggregate @@ -531,14 +526,14 @@ idx_t GroupedAggregateHashTable::AddChunk(DataChunk &groups, Vector &group_hashe } #ifdef DEBUG - D_ASSERT(groups.ColumnCount() + 1 == layout_ptr->ColumnCount()); + D_ASSERT(groups.ColumnCount() + 1 == layout.ColumnCount()); for (idx_t i = 0; i < groups.ColumnCount(); i++) { - D_ASSERT(groups.GetTypes()[i] == layout_ptr->GetTypes()[i]); + D_ASSERT(groups.GetTypes()[i] == layout.GetTypes()[i]); } #endif const auto new_group_count = FindOrCreateGroups(groups, group_hashes, state.addresses, state.new_groups); - VectorOperations::AddInPlace(state.addresses, NumericCast(layout_ptr->GetAggrOffset()), payload.size()); + VectorOperations::AddInPlace(state.addresses, NumericCast(layout.GetAggrOffset()), payload.size()); UpdateAggregates(payload, filter); @@ -548,7 +543,7 @@ idx_t GroupedAggregateHashTable::AddChunk(DataChunk &groups, Vector &group_hashe void GroupedAggregateHashTable::FetchAggregates(DataChunk &groups, DataChunk &result) { #ifdef DEBUG groups.Verify(); - D_ASSERT(groups.ColumnCount() + 1 == layout_ptr->ColumnCount()); + D_ASSERT(groups.ColumnCount() + 1 == layout.ColumnCount()); for (idx_t i = 0; i < result.ColumnCount(); i++) { D_ASSERT(result.data[i].GetType() == payload_types[i]); } @@ -561,14 +556,16 @@ void GroupedAggregateHashTable::FetchAggregates(DataChunk &groups, DataChunk &re // find the groups associated with the addresses // FIXME: this should not use the FindOrCreateGroups, creating them is unnecessary - FindOrCreateGroups(groups, state.addresses); + Vector addresses(LogicalType::POINTER); + FindOrCreateGroups(groups, addresses); // now fetch the aggregates - RowOperations::FinalizeStates(state.row_state, *layout_ptr, state.addresses, result, 0); + RowOperationsState row_state(*aggregate_allocator); + RowOperations::FinalizeStates(row_state, layout, addresses, result, 0); } idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, Vector &group_hashes_v, Vector &addresses_v, SelectionVector &new_groups_out) { - D_ASSERT(groups.ColumnCount() + 1 == layout_ptr->ColumnCount()); + D_ASSERT(groups.ColumnCount() + 1 == layout.ColumnCount()); D_ASSERT(group_hashes_v.GetType() == LogicalType::HASH); D_ASSERT(state.ht_offsets.GetVectorType() == VectorType::FLAT_VECTOR); D_ASSERT(state.ht_offsets.GetType() == LogicalType::UBIGINT); @@ -588,9 +585,9 @@ idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, V // Make a chunk that references the groups and the hashes and convert to unified format if (state.group_chunk.ColumnCount() == 0) { - state.group_chunk.InitializeEmpty(layout_ptr->GetTypes()); + state.group_chunk.InitializeEmpty(layout.GetTypes()); } - D_ASSERT(state.group_chunk.ColumnCount() == layout_ptr->GetTypes().size()); + D_ASSERT(state.group_chunk.ColumnCount() == layout.GetTypes().size()); for (idx_t grp_idx = 0; grp_idx < groups.ColumnCount(); grp_idx++) { state.group_chunk.data[grp_idx].Reference(groups.data[grp_idx]); } @@ -599,6 +596,10 @@ idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, V // convert all vectors to unified format TupleDataCollection::ToUnifiedFormat(state.partitioned_append_state.chunk_state, state.group_chunk); + if (!state.group_data) { + state.group_data = make_unsafe_uniq_array_uninitialized(state.group_chunk.ColumnCount()); + } + TupleDataCollection::GetVectorData(state.partitioned_append_state.chunk_state, state.group_data.get()); group_hashes_v.Flatten(chunk_size); const auto hashes = FlatVector::GetData(group_hashes_v); @@ -610,7 +611,7 @@ idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, V // Just appending now partitioned_data->AppendUnified(state.partitioned_append_state, state.group_chunk, *FlatVector::IncrementalSelectionVector(), chunk_size); - RowOperations::InitializeStates(*layout_ptr, state.partitioned_append_state.chunk_state.row_locations, + RowOperations::InitializeStates(layout, state.partitioned_append_state.chunk_state.row_locations, *FlatVector::IncrementalSelectionVector(), chunk_size); const auto row_locations = @@ -701,7 +702,7 @@ idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, V append_state = &state.partitioned_append_state; } data->AppendUnified(*append_state, state.group_chunk, state.empty_vector, new_entry_count); - RowOperations::InitializeStates(*layout_ptr, append_state->chunk_state.row_locations, + RowOperations::InitializeStates(layout, append_state->chunk_state.row_locations, *FlatVector::IncrementalSelectionVector(), new_entry_count); // Set the entry pointers in the 1st part of the HT now that the data has been appended @@ -729,7 +730,7 @@ idx_t GroupedAggregateHashTable::FindOrCreateGroupsInternal(DataChunk &groups, V // Perform group comparisons row_matcher.Match(state.group_chunk, state.partitioned_append_state.chunk_state.vector_data, - state.group_compare_vector, need_compare_count, *layout_ptr, addresses_v, + state.group_compare_vector, need_compare_count, layout, addresses_v, &state.no_match_vector, no_match_count); } @@ -764,8 +765,9 @@ void GroupedAggregateHashTable::FindOrCreateGroups(DataChunk &groups, Vector &ad idx_t GroupedAggregateHashTable::FindOrCreateGroups(DataChunk &groups, Vector &addresses_out, SelectionVector &new_groups_out) { - groups.Hash(state.hashes); - return FindOrCreateGroups(groups, state.hashes, addresses_out, new_groups_out); + Vector hashes(LogicalType::HASH); + groups.Hash(hashes); + return FindOrCreateGroups(groups, hashes, addresses_out, new_groups_out); } struct FlushMoveState { @@ -818,29 +820,26 @@ void GroupedAggregateHashTable::Combine(GroupedAggregateHashTable &other) { } void GroupedAggregateHashTable::Combine(TupleDataCollection &other_data, optional_ptr> progress) { - D_ASSERT(other_data.GetLayout().GetAggrWidth() == layout_ptr->GetAggrWidth()); - D_ASSERT(other_data.GetLayout().GetDataWidth() == layout_ptr->GetDataWidth()); - D_ASSERT(other_data.GetLayout().GetRowWidth() == layout_ptr->GetRowWidth()); + D_ASSERT(other_data.GetLayout().GetAggrWidth() == layout.GetAggrWidth()); + D_ASSERT(other_data.GetLayout().GetDataWidth() == layout.GetDataWidth()); + D_ASSERT(other_data.GetLayout().GetRowWidth() == layout.GetRowWidth()); if (other_data.Count() == 0) { return; } FlushMoveState fm_state(other_data); + RowOperationsState row_state(*aggregate_allocator); idx_t chunk_idx = 0; const auto chunk_count = other_data.ChunkCount(); while (fm_state.Scan()) { - // Check for interrupts with each chunk - if (context.interrupted) { - throw InterruptException(); - } const auto input_chunk_size = fm_state.groups.size(); FindOrCreateGroups(fm_state.groups, fm_state.hashes, fm_state.group_addresses, fm_state.new_groups_sel); - RowOperations::CombineStates(state.row_state, *layout_ptr, fm_state.scan_state.chunk_state.row_locations, + RowOperations::CombineStates(row_state, layout, fm_state.scan_state.chunk_state.row_locations, fm_state.group_addresses, input_chunk_size); - if (layout_ptr->HasDestructor()) { - RowOperations::DestroyStates(state.row_state, *layout_ptr, fm_state.scan_state.chunk_state.row_locations, + if (layout.HasDestructor()) { + RowOperations::DestroyStates(row_state, layout, fm_state.scan_state.chunk_state.row_locations, input_chunk_size); } @@ -852,38 +851,4 @@ void GroupedAggregateHashTable::Combine(TupleDataCollection &other_data, optiona Verify(); } -void GroupedAggregateHashTable::InitializeScan(AggregateHTScanState &scan_state) { - scan_state.partition_idx = 0; - vector group_indexes(layout_ptr->ColumnCount() - 1); - for (idx_t i = 0; i < group_indexes.size(); i++) { - group_indexes[i] = i; - } - - auto &partition = partitioned_data->GetPartitions()[scan_state.partition_idx]; - partition->InitializeScan(scan_state.scan_states, group_indexes); -} - -bool GroupedAggregateHashTable::Scan(AggregateHTScanState &scan_state, DataChunk &distinct_rows, - DataChunk &payload_rows) { - if (scan_state.partition_idx >= partitioned_data->PartitionCount()) { - return false; - } - - payload_rows.Reset(); - distinct_rows.Reset(); - auto ¤t_partition = partitioned_data->GetPartitions()[scan_state.partition_idx]; - - if (current_partition->Scan(scan_state.scan_states, distinct_rows)) { - FetchAggregates(distinct_rows, payload_rows); - return true; - } else { - if (++(scan_state.partition_idx) >= partitioned_data->PartitionCount()) { - return false; - } else { - auto &new_partition = partitioned_data->GetPartitions()[scan_state.partition_idx]; - new_partition->InitializeScan(scan_state.scan_states); - return true; - } - } -} } // namespace duckdb diff --git a/src/duckdb/src/execution/base_aggregate_hashtable.cpp b/src/duckdb/src/execution/base_aggregate_hashtable.cpp index b558a326c..eec99f9e3 100644 --- a/src/duckdb/src/execution/base_aggregate_hashtable.cpp +++ b/src/duckdb/src/execution/base_aggregate_hashtable.cpp @@ -8,7 +8,7 @@ BaseAggregateHashTable::BaseAggregateHashTable(ClientContext &context, Allocator const vector &aggregates, vector payload_types_p) : allocator(allocator), buffer_manager(BufferManager::GetBufferManager(context)), - layout_ptr(make_shared_ptr()), payload_types(std::move(payload_types_p)) { + payload_types(std::move(payload_types_p)) { filter_set.Initialize(context, aggregates, payload_types); } diff --git a/src/duckdb/src/execution/column_binding_resolver.cpp b/src/duckdb/src/execution/column_binding_resolver.cpp index b4af89223..3a931a3f5 100644 --- a/src/duckdb/src/execution/column_binding_resolver.cpp +++ b/src/duckdb/src/execution/column_binding_resolver.cpp @@ -9,7 +9,6 @@ #include "duckdb/planner/operator/logical_create_index.hpp" #include "duckdb/planner/operator/logical_extension_operator.hpp" #include "duckdb/planner/operator/logical_insert.hpp" -#include "duckdb/planner/operator/logical_recursive_cte.hpp" namespace duckdb { @@ -134,16 +133,6 @@ void ColumnBindingResolver::VisitOperator(LogicalOperator &op) { ext_op.ResolveColumnBindings(*this, bindings); return; } - case LogicalOperatorType::LOGICAL_RECURSIVE_CTE: { - auto &rec = op.Cast(); - VisitOperatorChildren(op); - bindings = op.GetColumnBindings(); - - for (auto &expr : rec.key_targets) { - VisitExpression(&expr); - } - return; - } default: break; } diff --git a/src/duckdb/src/execution/expression_executor.cpp b/src/duckdb/src/execution/expression_executor.cpp index c3cd2ca89..567deb326 100644 --- a/src/duckdb/src/execution/expression_executor.cpp +++ b/src/duckdb/src/execution/expression_executor.cpp @@ -8,8 +8,6 @@ namespace duckdb { ExpressionExecutor::ExpressionExecutor(ClientContext &context) : context(&context) { - auto &config = DBConfig::GetConfig(context); - debug_vector_verification = config.options.debug_verify_vector; } ExpressionExecutor::ExpressionExecutor(ClientContext &context, const Expression *expression) @@ -64,11 +62,6 @@ void ExpressionExecutor::AddExpression(const Expression &expr) { states.push_back(std::move(state)); } -void ExpressionExecutor::ClearExpressions() { - states.clear(); - expressions.clear(); -} - void ExpressionExecutor::Initialize(const Expression &expression, ExpressionExecutorState &state) { state.executor = this; state.root_state = InitializeState(expression, state); @@ -141,9 +134,9 @@ void ExpressionExecutor::Verify(const Expression &expr, Vector &vector, idx_t co if (expr.verification_stats) { expr.verification_stats->Verify(vector, count); } - if (debug_vector_verification == DebugVectorVerification::DICTIONARY_EXPRESSION) { - Vector::DebugTransformToDictionary(vector, count); - } +#ifdef DUCKDB_VERIFY_DICTIONARY_EXPRESSION + Vector::DebugTransformToDictionary(vector, count); +#endif } unique_ptr ExpressionExecutor::InitializeState(const Expression &expr, diff --git a/src/duckdb/src/execution/expression_executor/execute_operator.cpp b/src/duckdb/src/execution/expression_executor/execute_operator.cpp index 04883c5de..b543679e8 100644 --- a/src/duckdb/src/execution/expression_executor/execute_operator.cpp +++ b/src/duckdb/src/execution/expression_executor/execute_operator.cpp @@ -19,8 +19,8 @@ void ExpressionExecutor::Execute(const BoundOperatorExpression &expr, Expression const SelectionVector *sel, idx_t count, Vector &result) { // special handling for special snowflake 'IN' // IN has n children - auto expression_type = expr.GetExpressionType(); - if (expression_type == ExpressionType::COMPARE_IN || expression_type == ExpressionType::COMPARE_NOT_IN) { + if (expr.GetExpressionType() == ExpressionType::COMPARE_IN || + expr.GetExpressionType() == ExpressionType::COMPARE_NOT_IN) { if (expr.children.size() < 2) { throw InvalidInputException("IN needs at least two children"); } @@ -54,14 +54,14 @@ void ExpressionExecutor::Execute(const BoundOperatorExpression &expr, Expression intermediate.Reference(new_result); } } - if (expression_type == ExpressionType::COMPARE_NOT_IN) { + if (expr.GetExpressionType() == ExpressionType::COMPARE_NOT_IN) { // NOT IN: invert result VectorOperations::Not(intermediate, result, count); } else { // directly use the result result.Reference(intermediate); } - } else if (expression_type == ExpressionType::OPERATOR_COALESCE) { + } else if (expr.GetExpressionType() == ExpressionType::OPERATOR_COALESCE) { SelectionVector sel_a(count); SelectionVector sel_b(count); SelectionVector slice_sel(count); @@ -111,41 +111,6 @@ void ExpressionExecutor::Execute(const BoundOperatorExpression &expr, Expression } else if (count == 1) { result.SetVectorType(VectorType::CONSTANT_VECTOR); } - } else if (expression_type == ExpressionType::OPERATOR_TRY) { - auto &child_state = *state->child_states[0]; - try { - Execute(*expr.children[0], &child_state, sel, count, result); - return; - } catch (std::exception &ex) { - ErrorData error(ex); - auto error_type = error.Type(); - if (!Exception::IsExecutionError(error_type)) { - throw; - } - } - SelectionVector selvec(1); - DataChunk intermediate; - intermediate.Initialize(GetAllocator(), {result.GetType()}, 1); - for (idx_t i = 0; i < count; i++) { - intermediate.Reset(); - intermediate.SetCardinality(1); - selvec.set_index(0, sel ? sel->get_index(i) : i); - Value val(result.GetType()); - try { - Execute(*expr.children[0], &child_state, &selvec, 1, intermediate.data[0]); - val = intermediate.GetValue(0, 0); - } catch (std::exception &ex) { - ErrorData error(ex); - auto error_type = error.Type(); - if (!Exception::IsExecutionError(error_type)) { - throw; - } - } - result.SetValue(i, val); - } - if (count == 1) { - result.SetVectorType(VectorType::CONSTANT_VECTOR); - } } else if (expr.children.size() == 1) { state->intermediate_chunk.Reset(); auto &child = state->intermediate_chunk.data[0]; diff --git a/src/duckdb/src/execution/index/art/art.cpp b/src/duckdb/src/execution/index/art/art.cpp index f785db0ba..68aad532c 100644 --- a/src/duckdb/src/execution/index/art/art.cpp +++ b/src/duckdb/src/execution/index/art/art.cpp @@ -1234,7 +1234,7 @@ void ART::TransformToDeprecated() { if (deprecated_allocator) { prefix_count = Prefix::DEPRECATED_COUNT; - D_ASSERT((*allocators)[idx]->Empty()); + D_ASSERT((*allocators)[idx]->IsEmpty()); (*allocators)[idx]->Reset(); (*allocators)[idx] = std::move(deprecated_allocator); } @@ -1259,9 +1259,9 @@ IndexStorageInfo ART::GetStorageInfo(const case_insensitive_map_t &option #ifdef DEBUG if (v1_0_0_storage) { - D_ASSERT((*allocators)[Node::GetAllocatorIdx(NType::NODE_7_LEAF)]->Empty()); - D_ASSERT((*allocators)[Node::GetAllocatorIdx(NType::NODE_15_LEAF)]->Empty()); - D_ASSERT((*allocators)[Node::GetAllocatorIdx(NType::NODE_256_LEAF)]->Empty()); + D_ASSERT((*allocators)[Node::GetAllocatorIdx(NType::NODE_7_LEAF)]->IsEmpty()); + D_ASSERT((*allocators)[Node::GetAllocatorIdx(NType::NODE_15_LEAF)]->IsEmpty()); + D_ASSERT((*allocators)[Node::GetAllocatorIdx(NType::NODE_256_LEAF)]->IsEmpty()); D_ASSERT((*allocators)[Node::GetAllocatorIdx(NType::PREFIX)]->GetSegmentSize() == Prefix::DEPRECATED_COUNT + Prefix::METADATA_SIZE); } @@ -1440,7 +1440,7 @@ bool ART::MergeIndexes(IndexLock &state, BoundIndex &other_index) { // Verification //===--------------------------------------------------------------------===// -string ART::VerifyAndToString(IndexLock &l, const bool only_verify) { +string ART::VerifyAndToString(IndexLock &state, const bool only_verify) { return VerifyAndToStringInternal(only_verify); } @@ -1451,7 +1451,7 @@ string ART::VerifyAndToStringInternal(const bool only_verify) { return "[empty]"; } -void ART::VerifyAllocations(IndexLock &l) { +void ART::VerifyAllocations(IndexLock &state) { return VerifyAllocationsInternal(); } @@ -1473,12 +1473,6 @@ void ART::VerifyAllocationsInternal() { #endif } -void ART::VerifyBuffers(IndexLock &l) { - for (auto &allocator : *allocators) { - allocator->VerifyBuffers(); - } -} - constexpr const char *ART::TYPE_NAME; } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/node.cpp b/src/duckdb/src/execution/index/art/node.cpp index 1a4bbef6c..7b9c7a7da 100644 --- a/src/duckdb/src/execution/index/art/node.cpp +++ b/src/duckdb/src/execution/index/art/node.cpp @@ -7,7 +7,6 @@ #include "duckdb/execution/index/art/base_leaf.hpp" #include "duckdb/execution/index/art/base_node.hpp" #include "duckdb/execution/index/art/iterator.hpp" -#include "duckdb/execution/index/art/art_scanner.hpp" #include "duckdb/execution/index/art/leaf.hpp" #include "duckdb/execution/index/art/node256.hpp" #include "duckdb/execution/index/art/node256_leaf.hpp" @@ -363,23 +362,35 @@ bool Node::IsAnyLeaf() const { void Node::InitMerge(ART &art, const unsafe_vector &upper_bounds) { D_ASSERT(HasMetadata()); - ARTScanner scanner(art); + auto type = GetType(); - auto handler = [&upper_bounds](Node &node) { - const auto type = node.GetType(); - if (node.GetType() == NType::LEAF_INLINED) { - return ARTScanHandlingResult::CONTINUE; - } - if (type == NType::LEAF) { - throw InternalException("deprecated ART storage in InitMerge"); - } - const auto idx = GetAllocatorIdx(type); - node.IncreaseBufferId(upper_bounds[idx]); - return ARTScanHandlingResult::CONTINUE; - }; + switch (type) { + case NType::PREFIX: + return Prefix::InitializeMerge(art, *this, upper_bounds); + case NType::LEAF: + throw InternalException("Failed to initialize merge due to deprecated ART storage."); + case NType::NODE_4: + InitMergeInternal(art, Ref(art, *this, type), upper_bounds); + break; + case NType::NODE_16: + InitMergeInternal(art, Ref(art, *this, type), upper_bounds); + break; + case NType::NODE_48: + InitMergeInternal(art, Ref(art, *this, type), upper_bounds); + break; + case NType::NODE_256: + InitMergeInternal(art, Ref(art, *this, type), upper_bounds); + break; + case NType::LEAF_INLINED: + return; + case NType::NODE_7_LEAF: + case NType::NODE_15_LEAF: + case NType::NODE_256_LEAF: + break; + } - scanner.Init(handler, *this); - scanner.Scan(handler); + auto idx = GetAllocatorIdx(type); + IncreaseBufferId(upper_bounds[idx]); } bool Node::MergeNormalNodes(ART &art, Node &l_node, Node &r_node, uint8_t &byte, const GateStatus status) { @@ -586,61 +597,55 @@ bool Node::MergeInternal(ART &art, Node &other, const GateStatus status) { void Node::Vacuum(ART &art, const unordered_set &indexes) { D_ASSERT(HasMetadata()); - ARTScanner scanner(art); - - auto handler = [&art, &indexes](Node &node) { - ARTScanHandlingResult result; - const auto type = node.GetType(); - switch (type) { - case NType::LEAF_INLINED: - return ARTScanHandlingResult::SKIP; - case NType::LEAF: { - if (indexes.find(GetAllocatorIdx(type)) == indexes.end()) { - return ARTScanHandlingResult::SKIP; - } - Leaf::DeprecatedVacuum(art, node); - return ARTScanHandlingResult::SKIP; - } - case NType::NODE_7_LEAF: - case NType::NODE_15_LEAF: - case NType::NODE_256_LEAF: { - result = ARTScanHandlingResult::SKIP; - break; - } - case NType::PREFIX: - case NType::NODE_4: - case NType::NODE_16: - case NType::NODE_48: - case NType::NODE_256: { - result = ARTScanHandlingResult::CONTINUE; - break; - } - default: - throw InternalException("invalid node type for Vacuum: %s", EnumUtil::ToString(type)); - } - const auto idx = GetAllocatorIdx(type); - auto &allocator = GetAllocator(art, type); - const auto needs_vacuum = indexes.find(idx) != indexes.end() && allocator.NeedsVacuum(node); - if (needs_vacuum) { - const auto status = node.GetGateStatus(); - node = allocator.VacuumPointer(node); - node.SetMetadata(static_cast(type)); - node.SetGateStatus(status); + auto type = GetType(); + switch (type) { + case NType::LEAF_INLINED: + return; + case NType::PREFIX: + return Prefix::Vacuum(art, *this, indexes); + case NType::LEAF: + if (indexes.find(GetAllocatorIdx(type)) == indexes.end()) { + return; } - return result; - }; + return Leaf::DeprecatedVacuum(art, *this); + default: + break; + } + + auto idx = GetAllocatorIdx(type); + auto &allocator = GetAllocator(art, type); + auto needs_vacuum = indexes.find(idx) != indexes.end() && allocator.NeedsVacuum(*this); + if (needs_vacuum) { + auto status = GetGateStatus(); + *this = allocator.VacuumPointer(*this); + SetMetadata(static_cast(type)); + SetGateStatus(status); + } - scanner.Init(handler, *this); - scanner.Scan(handler); + switch (type) { + case NType::NODE_4: + return VacuumInternal(art, Ref(art, *this, type), indexes); + case NType::NODE_16: + return VacuumInternal(art, Ref(art, *this, type), indexes); + case NType::NODE_48: + return VacuumInternal(art, Ref(art, *this, type), indexes); + case NType::NODE_256: + return VacuumInternal(art, Ref(art, *this, type), indexes); + case NType::NODE_7_LEAF: + case NType::NODE_15_LEAF: + case NType::NODE_256_LEAF: + return; + default: + throw InternalException("Invalid node type for Vacuum: %s.", EnumUtil::ToString(type)); + } } //===--------------------------------------------------------------------===// // TransformToDeprecated //===--------------------------------------------------------------------===// -void Node::TransformToDeprecated(ART &art, Node &node, - unsafe_unique_ptr &deprecated_prefix_allocator) { +void Node::TransformToDeprecated(ART &art, Node &node, unsafe_unique_ptr &allocator) { D_ASSERT(node.HasMetadata()); if (node.GetGateStatus() == GateStatus::GATE_SET) { @@ -651,21 +656,21 @@ void Node::TransformToDeprecated(ART &art, Node &node, auto type = node.GetType(); switch (type) { case NType::PREFIX: - return Prefix::TransformToDeprecated(art, node, deprecated_prefix_allocator); + return Prefix::TransformToDeprecated(art, node, allocator); case NType::LEAF_INLINED: return; case NType::LEAF: return; case NType::NODE_4: - return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), deprecated_prefix_allocator); + return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), allocator); case NType::NODE_16: - return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), deprecated_prefix_allocator); + return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), allocator); case NType::NODE_48: - return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), deprecated_prefix_allocator); + return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), allocator); case NType::NODE_256: - return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), deprecated_prefix_allocator); + return TransformToDeprecatedInternal(art, InMemoryRef(art, node, type), allocator); default: - throw InternalException("invalid node type for TransformToDeprecated: %s", EnumUtil::ToString(type)); + throw InternalException("Invalid node type for TransformToDeprecated: %s.", EnumUtil::ToString(type)); } } @@ -727,42 +732,34 @@ string Node::VerifyAndToString(ART &art, const bool only_verify) const { void Node::VerifyAllocations(ART &art, unordered_map &node_counts) const { D_ASSERT(HasMetadata()); - ARTScanner scanner(art); - - auto handler = [&art, &node_counts](const Node &node) { - ARTScanHandlingResult result; - const auto type = node.GetType(); - switch (type) { - case NType::LEAF_INLINED: - return ARTScanHandlingResult::SKIP; - case NType::LEAF: { - auto &leaf = Ref(art, node, type); - leaf.DeprecatedVerifyAllocations(art, node_counts); - return ARTScanHandlingResult::SKIP; - } - case NType::NODE_7_LEAF: - case NType::NODE_15_LEAF: - case NType::NODE_256_LEAF: { - result = ARTScanHandlingResult::SKIP; - break; - } - case NType::PREFIX: - case NType::NODE_4: - case NType::NODE_16: - case NType::NODE_48: - case NType::NODE_256: { - result = ARTScanHandlingResult::CONTINUE; - break; - } - default: - throw InternalException("invalid node type for VerifyAllocations: %s", EnumUtil::ToString(type)); - } - node_counts[GetAllocatorIdx(type)]++; - return result; - }; - scanner.Init(handler, *this); - scanner.Scan(handler); + auto type = GetType(); + switch (type) { + case NType::PREFIX: + return Prefix::VerifyAllocations(art, *this, node_counts); + case NType::LEAF: + return Ref(art, *this, type).DeprecatedVerifyAllocations(art, node_counts); + case NType::LEAF_INLINED: + return; + case NType::NODE_4: + VerifyAllocationsInternal(art, Ref(art, *this, type), node_counts); + break; + case NType::NODE_16: + VerifyAllocationsInternal(art, Ref(art, *this, type), node_counts); + break; + case NType::NODE_48: + VerifyAllocationsInternal(art, Ref(art, *this, type), node_counts); + break; + case NType::NODE_256: + VerifyAllocationsInternal(art, Ref(art, *this, type), node_counts); + break; + case NType::NODE_7_LEAF: + case NType::NODE_15_LEAF: + case NType::NODE_256_LEAF: + break; + } + + node_counts[GetAllocatorIdx(type)]++; } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/plan_art.cpp b/src/duckdb/src/execution/index/art/plan_art.cpp index 644086868..ce459b290 100644 --- a/src/duckdb/src/execution/index/art/plan_art.cpp +++ b/src/duckdb/src/execution/index/art/plan_art.cpp @@ -9,9 +9,8 @@ namespace duckdb { -PhysicalOperator &ART::CreatePlan(PlanIndexInput &input) { +unique_ptr ART::CreatePlan(PlanIndexInput &input) { auto &op = input.op; - auto &planner = input.planner; // PROJECTION on indexed columns. vector new_column_types; @@ -23,11 +22,11 @@ PhysicalOperator &ART::CreatePlan(PlanIndexInput &input) { new_column_types.emplace_back(LogicalType::ROW_TYPE); select_list.push_back(make_uniq(LogicalType::ROW_TYPE, op.info->scan_types.size() - 1)); - auto &proj = planner.Make(new_column_types, std::move(select_list), op.estimated_cardinality); - proj.children.push_back(input.table_scan); + auto projection = make_uniq(new_column_types, std::move(select_list), op.estimated_cardinality); + projection->children.push_back(std::move(input.table_scan)); // Optional NOT NULL filter. - reference prev_op(proj); + unique_ptr prev_operator; auto is_alter = op.alter_table_info != nullptr; if (!is_alter) { vector filter_types; @@ -42,10 +41,13 @@ PhysicalOperator &ART::CreatePlan(PlanIndexInput &input) { filter_select_list.push_back(std::move(is_not_null_expr)); } - prev_op = planner.Make(std::move(filter_types), std::move(filter_select_list), - op.estimated_cardinality); - prev_op.get().types.emplace_back(LogicalType::ROW_TYPE); - prev_op.get().children.push_back(proj); + prev_operator = + make_uniq(std::move(filter_types), std::move(filter_select_list), op.estimated_cardinality); + prev_operator->types.emplace_back(LogicalType::ROW_TYPE); + prev_operator->children.push_back(std::move(projection)); + + } else { + prev_operator = std::move(projection); } // Determine whether to push an ORDER BY operator. @@ -57,13 +59,13 @@ PhysicalOperator &ART::CreatePlan(PlanIndexInput &input) { } // CREATE INDEX operator. - auto &create_idx = planner.Make(op, op.table, op.info->column_ids, std::move(op.info), - std::move(op.unbound_expressions), op.estimated_cardinality, - sort, std::move(op.alter_table_info)); + auto physical_create_index = make_uniq( + op, op.table, op.info->column_ids, std::move(op.info), std::move(op.unbound_expressions), + op.estimated_cardinality, sort, std::move(op.alter_table_info)); if (!sort) { - create_idx.children.push_back(prev_op); - return create_idx; + physical_create_index->children.push_back(std::move(prev_operator)); + return std::move(physical_create_index); } // ORDER BY operator. @@ -76,11 +78,12 @@ PhysicalOperator &ART::CreatePlan(PlanIndexInput &input) { } projections.emplace_back(new_column_types.size() - 1); - auto &order = planner.Make(new_column_types, std::move(orders), std::move(projections), - op.estimated_cardinality); - order.children.push_back(prev_op); - create_idx.children.push_back(order); - return create_idx; + auto physical_order = + make_uniq(new_column_types, std::move(orders), std::move(projections), op.estimated_cardinality); + + physical_order->children.push_back(std::move(prev_operator)); + physical_create_index->children.push_back(std::move(physical_order)); + return std::move(physical_create_index); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/art/prefix.cpp b/src/duckdb/src/execution/index/art/prefix.cpp index 32fceef93..13b5d02ac 100644 --- a/src/duckdb/src/execution/index/art/prefix.cpp +++ b/src/duckdb/src/execution/index/art/prefix.cpp @@ -99,6 +99,23 @@ void Prefix::Free(ART &art, Node &node) { node.Clear(); } +void Prefix::InitializeMerge(ART &art, Node &node, const unsafe_vector &upper_bounds) { + auto buffer_count = upper_bounds[Node::GetAllocatorIdx(PREFIX)]; + Node next = node; + Prefix prefix(art, next, true); + + while (next.GetType() == PREFIX) { + next = *prefix.ptr; + if (prefix.ptr->GetType() == PREFIX) { + prefix.ptr->IncreaseBufferId(buffer_count); + prefix = Prefix(art, next, true); + } + } + + node.IncreaseBufferId(buffer_count); + prefix.ptr->InitMerge(art, upper_bounds); +} + void Prefix::Concat(ART &art, Node &parent, uint8_t byte, const GateStatus old_status, const Node &child, const GateStatus status) { D_ASSERT(!parent.IsAnyLeaf()); @@ -342,6 +359,32 @@ string Prefix::VerifyAndToString(ART &art, const Node &node, const bool only_ver return only_verify ? "" : str + child; } +void Prefix::VerifyAllocations(ART &art, const Node &node, unordered_map &node_counts) { + auto idx = Node::GetAllocatorIdx(PREFIX); + reference ref(node); + Iterator(art, ref, false, false, [&](Prefix &prefix) { node_counts[idx]++; }); + return ref.get().VerifyAllocations(art, node_counts); +} + +void Prefix::Vacuum(ART &art, Node &node, const unordered_set &indexes) { + bool set = indexes.find(Node::GetAllocatorIdx(PREFIX)) != indexes.end(); + auto &allocator = Node::GetAllocator(art, PREFIX); + + reference ref(node); + while (ref.get().GetType() == PREFIX) { + if (set && allocator.NeedsVacuum(ref)) { + auto status = ref.get().GetGateStatus(); + ref.get() = allocator.VacuumPointer(ref); + ref.get().SetMetadata(static_cast(PREFIX)); + ref.get().SetGateStatus(status); + } + Prefix prefix(art, ref, true); + ref = *prefix.ptr; + } + + ref.get().Vacuum(art, indexes); +} + void Prefix::TransformToDeprecated(ART &art, Node &node, unsafe_unique_ptr &allocator) { // Early-out, if we do not need any transformations. if (!allocator) { diff --git a/src/duckdb/src/execution/index/bound_index.cpp b/src/duckdb/src/execution/index/bound_index.cpp index d85f689d7..26933680a 100644 --- a/src/duckdb/src/execution/index/bound_index.cpp +++ b/src/duckdb/src/execution/index/bound_index.cpp @@ -80,25 +80,15 @@ bool BoundIndex::MergeIndexes(BoundIndex &other_index) { } string BoundIndex::VerifyAndToString(const bool only_verify) { - IndexLock l; - InitializeLock(l); - return VerifyAndToString(l, only_verify); + IndexLock state; + InitializeLock(state); + return VerifyAndToString(state, only_verify); } void BoundIndex::VerifyAllocations() { - IndexLock l; - InitializeLock(l); - return VerifyAllocations(l); -} - -void BoundIndex::VerifyBuffers(IndexLock &l) { - throw NotImplementedException("this implementation of VerifyBuffers does not exist"); -} - -void BoundIndex::VerifyBuffers() { - IndexLock l; - InitializeLock(l); - return VerifyBuffers(l); + IndexLock state; + InitializeLock(state); + return VerifyAllocations(state); } void BoundIndex::Vacuum() { diff --git a/src/duckdb/src/execution/index/fixed_size_allocator.cpp b/src/duckdb/src/execution/index/fixed_size_allocator.cpp index 2ed4d0bde..7da8b5478 100644 --- a/src/duckdb/src/execution/index/fixed_size_allocator.cpp +++ b/src/duckdb/src/execution/index/fixed_size_allocator.cpp @@ -44,25 +44,32 @@ FixedSizeAllocator::FixedSizeAllocator(const idx_t segment_size, BlockManager &b } IndexPointer FixedSizeAllocator::New() { - // No more free segments available. - if (!buffer_with_free_space.IsValid()) { - // Add a new buffer. + // no more segments available + if (buffers_with_free_space.empty()) { + + // add a new buffer auto buffer_id = GetAvailableBufferId(); buffers[buffer_id] = make_uniq(block_manager); buffers_with_free_space.insert(buffer_id); - buffer_with_free_space = buffer_id; - // Set and initialize the bitmask of the new buffer. + // set the bitmask D_ASSERT(buffers.find(buffer_id) != buffers.end()); auto &buffer = buffers.find(buffer_id)->second; ValidityMask mask(reinterpret_cast(buffer->Get()), available_segments_per_buffer); + + // zero-initialize the bitmask to avoid leaking memory to disk + auto data = mask.GetData(); + for (idx_t i = 0; i < bitmask_count; i++) { + data[i] = 0; + } + + // initializing the bitmask of the new buffer mask.SetAllValid(available_segments_per_buffer); } - // Extract an index pointer to a free segment. - - D_ASSERT(buffer_with_free_space.IsValid()); - auto buffer_id = buffer_with_free_space.GetIndex(); + // return a pointer to a free segment + D_ASSERT(!buffers_with_free_space.empty()); + auto buffer_id = uint32_t(*buffers_with_free_space.begin()); D_ASSERT(buffers.find(buffer_id) != buffers.end()); auto &buffer = buffers.find(buffer_id)->second; @@ -70,23 +77,25 @@ IndexPointer FixedSizeAllocator::New() { total_segment_count++; buffer->segment_count++; - - // If the buffer is full, we cache the next buffer that we're going to fill. if (buffer->segment_count == available_segments_per_buffer) { buffers_with_free_space.erase(buffer_id); - NextBufferWithFreeSpace(); } - return IndexPointer(uint32_t(buffer_id), offset); + // zero-initialize that segment + auto buffer_ptr = buffer->Get(); + auto offset_in_buffer = buffer_ptr + offset * segment_size + bitmask_offset; + memset(offset_in_buffer, 0, segment_size); + + return IndexPointer(buffer_id, offset); } void FixedSizeAllocator::Free(const IndexPointer ptr) { + auto buffer_id = ptr.GetBufferId(); auto offset = ptr.GetOffset(); - auto buffer_it = buffers.find(buffer_id); - D_ASSERT(buffer_it != buffers.end()); - auto &buffer = buffer_it->second; + D_ASSERT(buffers.find(buffer_id) != buffers.end()); + auto &buffer = buffers.find(buffer_id)->second; auto bitmask_ptr = reinterpret_cast(buffer->Get()); ValidityMask mask(bitmask_ptr, offset + 1); // FIXME @@ -96,42 +105,15 @@ void FixedSizeAllocator::Free(const IndexPointer ptr) { D_ASSERT(total_segment_count > 0); D_ASSERT(buffer->segment_count > 0); - // Adjust the allocator fields. + // adjust the allocator fields + buffers_with_free_space.insert(buffer_id); total_segment_count--; buffer->segment_count--; - - // Early-out, if the buffer is not empty. - if (buffer->segment_count != 0) { - buffers_with_free_space.insert(buffer_id); - if (!buffer_with_free_space.IsValid()) { - buffer_with_free_space = buffer_id; - } - return; - } - - // The segment count went to 0, i.e, the buffer is now empty. - // We keep the buffer alive, if it is the only buffer with free space. - // We do so to prevent too much buffer creation fluctuation. - if (buffers_with_free_space.size() == 1) { - D_ASSERT(*buffers_with_free_space.begin() == buffer_id); - D_ASSERT(buffer_with_free_space.GetIndex() == buffer_id); - return; - } - - D_ASSERT(buffer_with_free_space.IsValid()); - buffers_with_free_space.erase(buffer_id); - buffers.erase(buffer_it); - - // Cache the next buffer that we're going to fill. - if (buffer_with_free_space.GetIndex() == buffer_id) { - NextBufferWithFreeSpace(); - } } void FixedSizeAllocator::Reset() { buffers.clear(); buffers_with_free_space.clear(); - buffer_with_free_space.SetInvalid(); total_segment_count = 0; } @@ -156,6 +138,7 @@ idx_t FixedSizeAllocator::GetUpperBoundBufferId() const { } void FixedSizeAllocator::Merge(FixedSizeAllocator &other) { + D_ASSERT(segment_size == other.segment_size); // remember the buffer count and merge the buffers @@ -170,13 +153,13 @@ void FixedSizeAllocator::Merge(FixedSizeAllocator &other) { buffers_with_free_space.insert(buffer_id + upper_bound_id); } other.buffers_with_free_space.clear(); - NextBufferWithFreeSpace(); // add the total allocations total_segment_count += other.total_segment_count; } bool FixedSizeAllocator::InitializeVacuum() { + // NOTE: we do not vacuum buffers that are not in memory. We might consider changing this // in the future, although buffers on disk should almost never be eligible for a vacuum @@ -232,16 +215,16 @@ bool FixedSizeAllocator::InitializeVacuum() { buffers.find(buffer_id)->second->vacuum = true; buffers_with_free_space.erase(buffer_id); } - D_ASSERT(!buffers_with_free_space.empty()); - NextBufferWithFreeSpace(); for (auto &vacuum_buffer : temporary_vacuum_buffers) { vacuum_buffers.insert(vacuum_buffer.second); } + return true; } void FixedSizeAllocator::FinalizeVacuum() { + for (auto &buffer_id : vacuum_buffers) { D_ASSERT(buffers.find(buffer_id) != buffers.end()); D_ASSERT(buffers.find(buffer_id)->second->InMemory()); @@ -251,6 +234,7 @@ void FixedSizeAllocator::FinalizeVacuum() { } IndexPointer FixedSizeAllocator::VacuumPointer(const IndexPointer ptr) { + // we do not need to adjust the bitmask of the old buffer, because we will free the entire // buffer after the vacuum operation @@ -263,6 +247,7 @@ IndexPointer FixedSizeAllocator::VacuumPointer(const IndexPointer ptr) { } FixedSizeAllocatorInfo FixedSizeAllocator::GetInfo() const { + FixedSizeAllocatorInfo info; info.segment_size = segment_size; @@ -293,6 +278,7 @@ void FixedSizeAllocator::SerializeBuffers(PartialBlockManager &partial_block_man } vector FixedSizeAllocator::InitSerializationToWAL() { + vector buffer_infos; for (auto &buffer : buffers) { buffer.second->SetAllocationSize(available_segments_per_buffer, segment_size, bitmask_offset); @@ -328,10 +314,10 @@ void FixedSizeAllocator::Init(const FixedSizeAllocatorInfo &info) { for (const auto &buffer_id : info.buffers_with_free_space) { buffers_with_free_space.insert(buffer_id); } - NextBufferWithFreeSpace(); } void FixedSizeAllocator::Deserialize(MetadataManager &metadata_manager, const BlockPointer &block_pointer) { + MetadataReader reader(metadata_manager, block_pointer); segment_size = reader.Read(); auto buffer_count = reader.Read(); @@ -363,39 +349,17 @@ idx_t FixedSizeAllocator::GetAvailableBufferId() const { } void FixedSizeAllocator::RemoveEmptyBuffers() { + auto buffer_it = buffers.begin(); while (buffer_it != buffers.end()) { if (buffer_it->second->segment_count != 0) { ++buffer_it; continue; } + buffers_with_free_space.erase(buffer_it->first); buffer_it = buffers.erase(buffer_it); } - NextBufferWithFreeSpace(); -} - -void FixedSizeAllocator::VerifyBuffers() { - idx_t count = 0; - auto buffer_it = buffers.begin(); - while (buffer_it != buffers.end()) { - if (buffer_it->second->segment_count == 0) { - count++; - } - buffer_it++; - } - - if (count > 1) { - throw InternalException("expected one, but got %d empty buffers in allocator", count); - } -} - -void FixedSizeAllocator::NextBufferWithFreeSpace() { - if (!buffers_with_free_space.empty()) { - buffer_with_free_space = *buffers_with_free_space.begin(); - return; - } - buffer_with_free_space.SetInvalid(); } } // namespace duckdb diff --git a/src/duckdb/src/execution/index/fixed_size_buffer.cpp b/src/duckdb/src/execution/index/fixed_size_buffer.cpp index eb08a0a07..d334541f6 100644 --- a/src/duckdb/src/execution/index/fixed_size_buffer.cpp +++ b/src/duckdb/src/execution/index/fixed_size_buffer.cpp @@ -40,12 +40,8 @@ FixedSizeBuffer::FixedSizeBuffer(BlockManager &block_manager) block_handle(nullptr) { auto &buffer_manager = block_manager.buffer_manager; - auto block_size = block_manager.GetBlockSize(); - buffer_handle = buffer_manager.Allocate(MemoryTag::ART_INDEX, block_size, false); + buffer_handle = buffer_manager.Allocate(MemoryTag::ART_INDEX, block_manager.GetBlockSize(), false); block_handle = buffer_handle.GetBlockHandle(); - - // Zero-initialize the buffer as it might get serialized to storage. - memset(buffer_handle.Ptr(), 0, block_size); } FixedSizeBuffer::FixedSizeBuffer(BlockManager &block_manager, const idx_t segment_count, const idx_t allocation_size, @@ -111,12 +107,16 @@ void FixedSizeBuffer::Serialize(PartialBlockManager &partial_block_manager, cons auto &p_block_for_index = allocation.partial_block->Cast(); auto dst_handle = buffer_manager.Pin(p_block_for_index.block_handle); memcpy(dst_handle.Ptr() + block_pointer.offset, buffer_handle.Ptr(), allocation_size); + SetUninitializedRegions(p_block_for_index, segment_size, block_pointer.offset, bitmask_offset, + available_segments); } else { // create a new block that can potentially be used as a partial block D_ASSERT(block_handle); D_ASSERT(!block_pointer.offset); auto p_block_for_index = make_uniq(allocation.state, block_manager, block_handle); + SetUninitializedRegions(*p_block_for_index, segment_size, block_pointer.offset, bitmask_offset, + available_segments); allocation.partial_block = std::move(p_block_for_index); } @@ -221,4 +221,28 @@ void FixedSizeBuffer::SetAllocationSize(const idx_t available_segments, const id allocation_size = max_offset * segment_size + bitmask_offset; } +void FixedSizeBuffer::SetUninitializedRegions(PartialBlockForIndex &p_block_for_index, const idx_t segment_size, + const idx_t offset, const idx_t bitmask_offset, + const idx_t available_segments) { + + // this function calls Get() on the buffer + D_ASSERT(InMemory()); + + auto bitmask_ptr = reinterpret_cast(Get()); + ValidityMask mask(bitmask_ptr, available_segments); + + idx_t i = 0; + idx_t max_offset = offset + allocation_size; + idx_t current_offset = offset + bitmask_offset; + while (current_offset < max_offset) { + + if (mask.RowIsValid(i)) { + D_ASSERT(current_offset + segment_size <= max_offset); + p_block_for_index.AddUninitializedRegion(current_offset, current_offset + segment_size); + } + current_offset += segment_size; + i++; + } +} + } // namespace duckdb diff --git a/src/duckdb/src/execution/join_hashtable.cpp b/src/duckdb/src/execution/join_hashtable.cpp index c15ff103f..14abdc61e 100644 --- a/src/duckdb/src/execution/join_hashtable.cpp +++ b/src/duckdb/src/execution/join_hashtable.cpp @@ -29,9 +29,9 @@ JoinHashTable::InsertState::InsertState(const JoinHashTable &ht) ht.data_collection->InitializeChunkState(chunk_state, ht.equality_predicate_columns); } -JoinHashTable::JoinHashTable(ClientContext &context_p, const vector &conditions_p, +JoinHashTable::JoinHashTable(ClientContext &context, const vector &conditions_p, vector btypes, JoinType type_p, const vector &output_columns_p) - : context(context_p), buffer_manager(BufferManager::GetBufferManager(context)), conditions(conditions_p), + : buffer_manager(BufferManager::GetBufferManager(context)), conditions(conditions_p), build_types(std::move(btypes)), output_columns(output_columns_p), entry_size(0), tuple_size(0), vfound(Value::BOOLEAN(false)), join_type(type_p), finalized(false), has_null(false), radix_bits(INITIAL_RADIX_BITS) { @@ -64,7 +64,6 @@ JoinHashTable::JoinHashTable(ClientContext &context_p, const vector(); vector layout_types(condition_types); layout_types.insert(layout_types.end(), build_types.begin(), build_types.end()); if (PropagatesBuildSide(join_type)) { @@ -73,8 +72,7 @@ JoinHashTable::JoinHashTable(ClientContext &context_p, const vectorInitialize(layout_types, false); - layout_ptr = std::move(layout); + layout.Initialize(layout_types, false); // Initialize the row matcher that are used for filtering during the probing only if there are non-equality if (!non_equality_predicates.empty()) { @@ -82,8 +80,8 @@ JoinHashTable::JoinHashTable(ClientContext &context_p, const vector(new RowMatcher()); row_matcher_probe_no_match_sel = unique_ptr(new RowMatcher()); - row_matcher_probe->Initialize(false, *layout_ptr, non_equality_predicates, non_equality_predicate_columns); - row_matcher_probe_no_match_sel->Initialize(true, *layout_ptr, non_equality_predicates, + row_matcher_probe->Initialize(false, layout, non_equality_predicates, non_equality_predicate_columns); + row_matcher_probe_no_match_sel->Initialize(true, layout, non_equality_predicates, non_equality_predicate_columns); needs_chain_matcher = true; @@ -92,19 +90,19 @@ JoinHashTable::JoinHashTable(ClientContext &context_p, const vectorGetOffsets(); + const auto &offsets = layout.GetOffsets(); tuple_size = offsets[condition_types.size() + build_types.size()]; pointer_offset = offsets.back(); - entry_size = layout_ptr->GetRowWidth(); + entry_size = layout.GetRowWidth(); - data_collection = make_uniq(buffer_manager, layout_ptr); + data_collection = make_uniq(buffer_manager, layout); sink_collection = - make_uniq(buffer_manager, layout_ptr, radix_bits, layout_ptr->ColumnCount() - 1); + make_uniq(buffer_manager, layout, radix_bits, layout.ColumnCount() - 1); - dead_end = make_unsafe_uniq_array_uninitialized(layout_ptr->GetRowWidth()); - memset(dead_end.get(), 0, layout_ptr->GetRowWidth()); + dead_end = make_unsafe_uniq_array_uninitialized(layout.GetRowWidth()); + memset(dead_end.get(), 0, layout.GetRowWidth()); if (join_type == JoinType::SINGLE) { auto &config = ClientConfig::GetConfig(context); @@ -264,9 +262,9 @@ static inline void GetRowPointersInternal(DataChunk &keys, TupleDataChunkState & if (salt_match_count != 0) { // Perform row comparisons, after function call salt_match_sel will point to the keys that match - idx_t key_match_count = ht.row_matcher_build.Match( - keys, key_state.vector_data, state.salt_match_sel, salt_match_count, *ht.layout_ptr, - state.rhs_row_locations, &state.key_no_match_sel, key_no_match_count); + idx_t key_match_count = ht.row_matcher_build.Match(keys, key_state.vector_data, state.salt_match_sel, + salt_match_count, ht.layout, state.rhs_row_locations, + &state.key_no_match_sel, key_no_match_count); D_ASSERT(key_match_count + key_no_match_count == salt_match_count); @@ -369,7 +367,7 @@ void JoinHashTable::Build(PartitionedTupleDataAppendState &append_state, DataChu // build a chunk to append to the data collection [keys, payload, (optional "found" boolean), hash] DataChunk source_chunk; - source_chunk.InitializeEmpty(layout_ptr->GetTypes()); + source_chunk.InitializeEmpty(layout.GetTypes()); for (idx_t i = 0; i < keys.ColumnCount(); i++) { source_chunk.data[i].Reference(keys.data[i]); } @@ -509,9 +507,9 @@ static inline void PerformKeyComparison(JoinHashTable::InsertState &state, JoinH } // Perform row comparisons - key_match_count = ht.row_matcher_build.Match(state.lhs_data, state.chunk_state.vector_data, state.key_match_sel, - count, *ht.layout_ptr, state.rhs_row_locations, - &state.key_no_match_sel, key_no_match_count); + key_match_count = + ht.row_matcher_build.Match(state.lhs_data, state.chunk_state.vector_data, state.key_match_sel, count, ht.layout, + state.rhs_row_locations, &state.key_no_match_sel, key_no_match_count); D_ASSERT(key_match_count + key_no_match_count == count); } @@ -679,7 +677,7 @@ void JoinHashTable::InsertHashes(Vector &hashes_v, const idx_t count, TupleDataC } } -void JoinHashTable::AllocatePointerTable() { +void JoinHashTable::InitializePointerTable() { capacity = PointerTableCapacity(Count()); D_ASSERT(IsPowerOfTwo(capacity)); @@ -701,12 +699,10 @@ void JoinHashTable::AllocatePointerTable() { } D_ASSERT(hash_map.GetSize() == capacity * sizeof(ht_entry_t)); - bitmask = capacity - 1; -} - -void JoinHashTable::InitializePointerTable(idx_t entry_idx_from, idx_t entry_idx_to) { // initialize HT with all-zero entries - std::fill_n(entries + entry_idx_from, entry_idx_to - entry_idx_from, ht_entry_t()); + std::fill_n(entries, capacity, ht_entry_t()); + + bitmask = capacity - 1; } void JoinHashTable::Finalize(idx_t chunk_idx_from, idx_t chunk_idx_to, bool parallel) { @@ -836,8 +832,8 @@ idx_t ScanStructure::ResolvePredicates(DataChunk &keys, SelectionVector &match_s // we need to only use the vectors with the indices of the columns that are used in the probe phase, namely // the non-equality columns - return matcher->Match(keys, key_state.vector_data, match_sel, this->count, *ht.layout_ptr, pointers, - no_match_sel, no_match_count, ht.non_equality_predicate_columns); + return matcher->Match(keys, key_state.vector_data, match_sel, this->count, ht.layout, pointers, no_match_sel, + no_match_count, ht.non_equality_predicate_columns); } else { // no match sel is the opposite of match sel return this->count; @@ -966,7 +962,7 @@ void ScanStructure::NextInnerJoin(DataChunk &keys, DataChunk &left, DataChunk &r for (idx_t i = 0; i < ht.output_columns.size(); i++) { auto &vector = result.data[left.ColumnCount() + i]; const auto output_col_idx = ht.output_columns[i]; - D_ASSERT(vector.GetType() == ht.layout_ptr->GetTypes()[output_col_idx]); + D_ASSERT(vector.GetType() == ht.layout.GetTypes()[output_col_idx]); GatherResult(vector, chain_match_sel_vector, result_count, output_col_idx); } @@ -991,7 +987,7 @@ void ScanStructure::NextInnerJoin(DataChunk &keys, DataChunk &left, DataChunk &r for (idx_t i = 0; i < ht.output_columns.size(); i++) { auto &vector = result.data[left.ColumnCount() + i]; const auto output_col_idx = ht.output_columns[i]; - D_ASSERT(vector.GetType() == ht.layout_ptr->GetTypes()[output_col_idx]); + D_ASSERT(vector.GetType() == ht.layout.GetTypes()[output_col_idx]); GatherResult(vector, base_count, output_col_idx); } } @@ -1115,16 +1111,17 @@ void ScanStructure::ConstructMarkJoinResult(DataChunk &join_keys, DataChunk &chi if (!jdata.validity.AllValid()) { for (idx_t i = 0; i < join_keys.size(); i++) { auto jidx = jdata.sel->get_index(i); - if (!jdata.validity.RowIsValidUnsafe(jidx)) { - mask.SetInvalid(i); - } + mask.Set(i, jdata.validity.RowIsValidUnsafe(jidx)); } } } // now set the remaining entries to either true or false based on whether a match was found - D_ASSERT(found_match); - for (idx_t i = 0; i < child.size(); i++) { - bool_result[i] = found_match[i]; + if (found_match) { + for (idx_t i = 0; i < child.size(); i++) { + bool_result[i] = found_match[i]; + } + } else { + memset(bool_result, 0, sizeof(bool) * child.size()); } // if the right side contains NULL values, the result of any FALSE becomes NULL if (ht.has_null) { @@ -1280,7 +1277,7 @@ void ScanStructure::NextSingleJoin(DataChunk &keys, DataChunk &left, DataChunk & } } const auto output_col_idx = ht.output_columns[i]; - D_ASSERT(vector.GetType() == ht.layout_ptr->GetTypes()[output_col_idx]); + D_ASSERT(vector.GetType() == ht.layout.GetTypes()[output_col_idx]); GatherResult(vector, result_sel, result_sel, result_count, output_col_idx); } result.SetCardinality(left.size()); @@ -1366,7 +1363,7 @@ void JoinHashTable::ScanFullOuter(JoinHTScanState &state, Vector &addresses, Dat for (idx_t i = 0; i < output_columns.size(); i++) { auto &vector = result.data[left_column_count + i]; const auto output_col_idx = output_columns[i]; - D_ASSERT(vector.GetType() == layout_ptr->GetTypes()[output_col_idx]); + D_ASSERT(vector.GetType() == layout.GetTypes()[output_col_idx]); data_collection->Gather(addresses, sel_vector, found_entries, output_col_idx, vector, sel_vector, nullptr); } } @@ -1471,7 +1468,7 @@ void JoinHashTable::SetRepartitionRadixBits(const idx_t max_ht_size, const idx_t } radix_bits += added_bits; sink_collection = - make_uniq(buffer_manager, layout_ptr, radix_bits, layout_ptr->ColumnCount() - 1); + make_uniq(buffer_manager, layout, radix_bits, layout.ColumnCount() - 1); // Need to initialize again after changing the number of bits InitializePartitionMasks(); @@ -1501,9 +1498,9 @@ idx_t JoinHashTable::FinishedPartitionCount() const { } void JoinHashTable::Repartition(JoinHashTable &global_ht) { - auto new_sink_collection = make_uniq(buffer_manager, layout_ptr, global_ht.radix_bits, - layout_ptr->ColumnCount() - 1); - sink_collection->Repartition(context, *new_sink_collection); + auto new_sink_collection = + make_uniq(buffer_manager, layout, global_ht.radix_bits, layout.ColumnCount() - 1); + sink_collection->Repartition(*new_sink_collection); sink_collection = std::move(new_sink_collection); global_ht.Merge(*this); } diff --git a/src/duckdb/src/execution/operator/aggregate/physical_partitioned_aggregate.cpp b/src/duckdb/src/execution/operator/aggregate/physical_partitioned_aggregate.cpp index 83a7dd60d..32bf4ecc2 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_partitioned_aggregate.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_partitioned_aggregate.cpp @@ -82,7 +82,7 @@ unique_ptr PhysicalPartitionedAggregate::GetGlobalSinkState(Cli unique_ptr PhysicalPartitionedAggregate::GetLocalSinkState(ExecutionContext &context) const { D_ASSERT(sink_state); - return make_uniq(*this, children[0].get().GetTypes(), context); + return make_uniq(*this, children[0]->GetTypes(), context); } //===--------------------------------------------------------------------===// diff --git a/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp b/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp index 7ec754d4e..aa165678b 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp @@ -486,7 +486,7 @@ void PhysicalStreamingWindow::ExecuteFunctions(ExecutionContext &context, DataCh // Compute window functions const idx_t count = output.size(); - const column_t input_width = children[0].get().GetTypes().size(); + const column_t input_width = children[0]->GetTypes().size(); for (column_t expr_idx = 0; expr_idx < select_list.size(); expr_idx++) { column_t col_idx = input_width + expr_idx; auto &expr = *select_list[expr_idx]; diff --git a/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp b/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp index 693daee0b..0ec4bd2a3 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp @@ -282,7 +282,7 @@ unique_ptr PhysicalUngroupedAggregate::GetGlobalSinkState(Clien unique_ptr PhysicalUngroupedAggregate::GetLocalSinkState(ExecutionContext &context) const { D_ASSERT(sink_state); auto &gstate = sink_state->Cast(); - return make_uniq(*this, children[0].get().GetTypes(), gstate, context); + return make_uniq(*this, children[0]->GetTypes(), gstate, context); } void PhysicalUngroupedAggregate::SinkDistinct(ExecutionContext &context, DataChunk &chunk, diff --git a/src/duckdb/src/execution/operator/aggregate/physical_window.cpp b/src/duckdb/src/execution/operator/aggregate/physical_window.cpp index 9dac15409..956c50ee1 100644 --- a/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +++ b/src/duckdb/src/execution/operator/aggregate/physical_window.cpp @@ -18,23 +18,6 @@ class WindowGlobalSinkState; enum WindowGroupStage : uint8_t { SINK, FINALIZE, GETDATA, DONE }; -struct WindowSourceTask { - WindowSourceTask(WindowGroupStage stage, idx_t group_idx, idx_t max_idx) - : stage(stage), group_idx(group_idx), thread_idx(0), max_idx(max_idx) { - } - WindowGroupStage stage; - //! The hash group - idx_t group_idx; - //! The thread index (for local state) - idx_t thread_idx; - //! The total block index count - idx_t max_idx; - //! The first block index count - idx_t begin_idx = 0; - //! The end block index count - idx_t end_idx = 0; -}; - class WindowHashGroup { public: using HashGroupPtr = unique_ptr; @@ -44,8 +27,6 @@ class WindowHashGroup { using ExecutorLocalStatePtr = unique_ptr; using ExecutorLocalStates = vector; using ThreadLocalStates = vector; - using Task = WindowSourceTask; - using TaskPtr = optional_ptr; WindowHashGroup(WindowGlobalSinkState &gstate, const idx_t hash_bin_p); @@ -92,20 +73,6 @@ class WindowHashGroup { } } - bool TryNextTask(TaskPtr &task) { - if (next_task >= tasks.size()) { - return false; - } - task = tasks[next_task]; - auto group_stage = GetStage(); - if (task->stage == group_stage) { - ++next_task; - return true; - } - - return false; - } - //! The hash partition data HashGroupPtr hash_group; //! The size of the group @@ -134,16 +101,12 @@ class WindowHashGroup { idx_t hash_bin; //! Single threading lock mutex lock; - //! The list of tasks for this group - vector tasks; - //! The next task to process - idx_t next_task = 0; //! Count of sunk rows std::atomic sunk; //! Count of finalized blocks std::atomic finalized; - //! Count of completed tasks - std::atomic completed; + //! The number of tasks left before we should be deleted + std::atomic tasks_remaining; //! The output ordering batch index this hash group starts at idx_t batch_base; @@ -177,7 +140,7 @@ class WindowPartitionGlobalSinkState : public PartitionGlobalSinkState { using WindowHashGroupPtr = unique_ptr; WindowPartitionGlobalSinkState(WindowGlobalSinkState &gsink, const BoundWindowExpression &wexpr) - : PartitionGlobalSinkState(gsink.context, wexpr.partitions, wexpr.orders, gsink.op.children[0].get().GetTypes(), + : PartitionGlobalSinkState(gsink.context, wexpr.partitions, wexpr.orders, gsink.op.children[0]->types, wexpr.partitions_stats, gsink.op.estimated_cardinality), gsink(gsink) { } @@ -349,9 +312,24 @@ SinkFinalizeType PhysicalWindow::Finalize(Pipeline &pipeline, Event &event, Clie class WindowGlobalSourceState : public GlobalSourceState { public: using ScannerPtr = unique_ptr; - using Task = WindowSourceTask; + + struct Task { + Task(WindowGroupStage stage, idx_t group_idx, idx_t max_idx) + : stage(stage), group_idx(group_idx), thread_idx(0), max_idx(max_idx) { + } + WindowGroupStage stage; + //! The hash group + idx_t group_idx; + //! The thread index (for local state) + idx_t thread_idx; + //! The total block index count + idx_t max_idx; + //! The first block index count + idx_t begin_idx = 0; + //! The end block index count + idx_t end_idx = 0; + }; using TaskPtr = optional_ptr; - using PartitionBlock = std::pair; WindowGlobalSourceState(ClientContext &context_p, WindowGlobalSinkState &gsink_p); @@ -360,13 +338,17 @@ class WindowGlobalSourceState : public GlobalSourceState { //! Are there any more tasks? bool HasMoreTasks() const { - return !stopped && started < total_tasks; + return !stopped && next_task < tasks.size(); } bool HasUnfinishedTasks() const { - return !stopped && finished < total_tasks; + return !stopped && finished < tasks.size(); } + //! Try to advance the group stage + bool TryPrepareNextStage(); //! Get the next task given the current state bool TryNextTask(TaskPtr &task); + //! Finish a task + void FinishTask(TaskPtr task); //! Context for executing computations ClientContext &context; @@ -374,19 +356,13 @@ class WindowGlobalSourceState : public GlobalSourceState { WindowGlobalSinkState &gsink; //! The total number of blocks to process; idx_t total_blocks = 0; - //! The sorted list of (blocks, group_idx) pairs - vector partition_blocks; - //! The ordered set of active groups - vector active_groups; - //! The number of started tasks - atomic next_group; //! The number of local states atomic locals; - //! The total number of tasks - idx_t total_tasks = 0; - //! The number of started tasks - atomic started; - //! The number of finished tasks + //! The list of tasks + vector tasks; + //! The the next task + atomic next_task; + //! The the number of finished tasks atomic finished; //! Stop producing tasks atomic stopped; @@ -397,15 +373,10 @@ class WindowGlobalSourceState : public GlobalSourceState { idx_t MaxThreads() override { return total_blocks; } - -protected: - //! Finish a task - void FinishTask(TaskPtr task); }; WindowGlobalSourceState::WindowGlobalSourceState(ClientContext &context_p, WindowGlobalSinkState &gsink_p) - : context(context_p), gsink(gsink_p), next_group(0), locals(0), started(0), finished(0), stopped(false), - returned(0) { + : context(context_p), gsink(gsink_p), locals(0), next_task(0), finished(0), stopped(false), returned(0) { auto &gpart = gsink.global_partition; auto &window_hash_groups = gsink.global_partition->window_hash_groups; @@ -437,14 +408,14 @@ WindowGlobalSourceState::WindowGlobalSourceState(ClientContext &context_p, Windo void WindowGlobalSourceState::CreateTaskList() { // Check whether we have a task list outside the mutex. - if (started.load()) { + if (next_task.load()) { return; } auto guard = Lock(); auto &window_hash_groups = gsink.global_partition->window_hash_groups; - if (!partition_blocks.empty()) { + if (!tasks.empty()) { return; } @@ -453,6 +424,8 @@ void WindowGlobalSourceState::CreateTaskList() { return; } + using PartitionBlock = std::pair; + vector partition_blocks; for (idx_t group_idx = 0; group_idx < window_hash_groups.size(); ++group_idx) { auto &window_hash_group = window_hash_groups[group_idx]; partition_blocks.emplace_back(window_hash_group->rows->blocks.size(), group_idx); @@ -469,17 +442,16 @@ void WindowGlobalSourceState::CreateTaskList() { } // TODO: Generate dynamically instead of building a big list? - vector stages {WindowGroupStage::SINK, WindowGroupStage::FINALIZE, WindowGroupStage::GETDATA}; + vector states {WindowGroupStage::SINK, WindowGroupStage::FINALIZE, WindowGroupStage::GETDATA}; for (const auto &b : partition_blocks) { auto &window_hash_group = *window_hash_groups[b.second]; - auto &tasks = window_hash_group.tasks; - for (const auto &stage : stages) { + for (const auto &state : states) { idx_t thread_count = 0; - for (Task task(stage, b.second, b.first); task.begin_idx < task.max_idx; task.begin_idx += per_thread) { + for (Task task(state, b.second, b.first); task.begin_idx < task.max_idx; task.begin_idx += per_thread) { task.end_idx = MinValue(task.begin_idx + per_thread, task.max_idx); tasks.emplace_back(task); + window_hash_group.tasks_remaining++; thread_count = ++task.thread_idx; - ++total_tasks; } window_hash_group.thread_states.resize(thread_count); } @@ -526,8 +498,8 @@ void WindowHashGroup::MaterializeSortedData() { } WindowHashGroup::WindowHashGroup(WindowGlobalSinkState &gstate, const idx_t hash_bin_p) - : count(0), blocks(0), stage(WindowGroupStage::SINK), hash_bin(hash_bin_p), sunk(0), finalized(0), completed(0), - batch_base(0) { + : count(0), blocks(0), stage(WindowGroupStage::SINK), hash_bin(hash_bin_p), sunk(0), finalized(0), + tasks_remaining(0), batch_base(0) { // There are three types of partitions: // 1. No partition (no sorting) // 2. One partition (sorting, but no hashing) @@ -788,46 +760,25 @@ WindowLocalSourceState::WindowLocalSourceState(WindowGlobalSourceState &gsource) bool WindowGlobalSourceState::TryNextTask(TaskPtr &task) { auto guard = Lock(); - FinishTask(task); - - if (!HasMoreTasks()) { + if (next_task >= tasks.size() || stopped) { task = nullptr; return false; } - // Run through the active groups looking for one that can assign a task - auto &gpart = *gsink.global_partition; - for (const auto &group_idx : active_groups) { - auto &window_hash_group = gpart.window_hash_groups[group_idx]; - if (window_hash_group->TryPrepareNextStage()) { - UnblockTasks(guard); - } - if (window_hash_group->TryNextTask(task)) { - ++started; - return true; - } - } + // If the next task matches the current state of its group, then we can use it + // Otherwise block. + task = &tasks[next_task]; - // All active groups are busy or blocked, so start the next one (if any) - while (next_group < partition_blocks.size()) { - const auto group_idx = partition_blocks[next_group++].second; - active_groups.emplace_back(group_idx); - - auto &window_hash_group = gpart.window_hash_groups[group_idx]; - if (window_hash_group->TryPrepareNextStage()) { - UnblockTasks(guard); - } - if (!window_hash_group->TryNextTask(task)) { - // Group has no tasks (empty?) - continue; - } + auto &gpart = *gsink.global_partition; + auto &window_hash_group = gpart.window_hash_groups[task->group_idx]; + auto group_stage = window_hash_group->GetStage(); - ++started; + if (task->stage == group_stage) { + ++next_task; return true; } task = nullptr; - return false; } @@ -837,15 +788,11 @@ void WindowGlobalSourceState::FinishTask(TaskPtr task) { } auto &gpart = *gsink.global_partition; - const auto group_idx = task->group_idx; - auto &finished_hash_group = gpart.window_hash_groups[group_idx]; + auto &finished_hash_group = gpart.window_hash_groups[task->group_idx]; D_ASSERT(finished_hash_group); - if (++finished_hash_group->completed >= finished_hash_group->tasks.size()) { + if (!--finished_hash_group->tasks_remaining) { finished_hash_group.reset(); - // Remove it from the active groups - auto &v = active_groups; - v.erase(std::remove(v.begin(), v.end(), group_idx), v.end()); } } @@ -853,7 +800,7 @@ bool WindowLocalSourceState::TryAssignTask() { D_ASSERT(TaskFinished()); if (task && task->stage == WindowGroupStage::GETDATA) { // If this state completed the last block in the previous iteration, - // release our local state memory. + // release out local state memory. ReleaseLocalStates(); } // Because downstream operators may be using our internal buffers, @@ -861,10 +808,21 @@ bool WindowLocalSourceState::TryAssignTask() { // Scanner first, as it may be referencing sort blocks in the hash group scanner.reset(); + gsource.FinishTask(task); return gsource.TryNextTask(task); } +bool WindowGlobalSourceState::TryPrepareNextStage() { + if (next_task >= tasks.size() || stopped) { + return true; + } + + auto task = &tasks[next_task]; + auto window_hash_group = gsink.global_partition->window_hash_groups[task->group_idx].get(); + return window_hash_group->TryPrepareNextStage(); +} + void WindowLocalSourceState::ExecuteTask(DataChunk &result) { auto &gsink = gsource.gsink; @@ -1027,6 +985,10 @@ SourceResultType PhysicalWindow::GetData(ExecutionContext &context, DataChunk &c // no more tasks - exit gsource.UnblockTasks(guard); break; + } + if (gsource.TryPrepareNextStage()) { + // we successfully prepared the next stage - unblock tasks + gsource.UnblockTasks(guard); } else { // there are more tasks available, but we can't execute them yet // block the source diff --git a/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer.cpp b/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer.cpp index 575d69d7d..1b3b7e1c9 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer.cpp @@ -4,8 +4,9 @@ namespace duckdb { CSVBuffer::CSVBuffer(ClientContext &context, idx_t buffer_size_p, CSVFileHandle &file_handle, - const idx_t &global_csv_current_position) - : context(context), requested_size(buffer_size_p), can_seek(file_handle.CanSeek()), is_pipe(file_handle.IsPipe()) { + const idx_t &global_csv_current_position, idx_t file_number_p) + : context(context), requested_size(buffer_size_p), file_number(file_number_p), can_seek(file_handle.CanSeek()), + is_pipe(file_handle.IsPipe()) { AllocateBuffer(buffer_size_p); auto buffer = Ptr(); actual_buffer_size = file_handle.Read(buffer, buffer_size_p); @@ -18,9 +19,10 @@ CSVBuffer::CSVBuffer(ClientContext &context, idx_t buffer_size_p, CSVFileHandle } CSVBuffer::CSVBuffer(CSVFileHandle &file_handle, ClientContext &context, idx_t buffer_size, - idx_t global_csv_current_position, idx_t buffer_idx_p) + idx_t global_csv_current_position, idx_t file_number_p, idx_t buffer_idx_p) : context(context), requested_size(buffer_size), global_csv_start(global_csv_current_position), - can_seek(file_handle.CanSeek()), is_pipe(file_handle.IsPipe()), buffer_idx(buffer_idx_p) { + file_number(file_number_p), can_seek(file_handle.CanSeek()), is_pipe(file_handle.IsPipe()), + buffer_idx(buffer_idx_p) { AllocateBuffer(buffer_size); auto buffer = handle.Ptr(); actual_buffer_size = file_handle.Read(handle.Ptr(), buffer_size); @@ -31,15 +33,16 @@ CSVBuffer::CSVBuffer(CSVFileHandle &file_handle, ClientContext &context, idx_t b last_buffer = file_handle.FinishedReading(); } -shared_ptr CSVBuffer::Next(CSVFileHandle &file_handle, idx_t buffer_size, bool &has_seaked) const { +shared_ptr CSVBuffer::Next(CSVFileHandle &file_handle, idx_t buffer_size, idx_t file_number_p, + bool &has_seaked) const { if (has_seaked) { // This means that at some point a reload was done, and we are currently on the incorrect position in our file // handle file_handle.Seek(global_csv_start + actual_buffer_size); has_seaked = false; } - auto next_csv_buffer = make_shared_ptr(file_handle, context, buffer_size, - global_csv_start + actual_buffer_size, buffer_idx + 1); + auto next_csv_buffer = make_shared_ptr( + file_handle, context, buffer_size, global_csv_start + actual_buffer_size, file_number_p, buffer_idx + 1); if (next_csv_buffer->GetBufferSize() == 0) { // We are done reading return nullptr; @@ -75,7 +78,7 @@ shared_ptr CSVBuffer::Pin(CSVFileHandle &file_handle, bool &has has_seeked = true; } return make_shared_ptr(buffer_manager.Pin(block), actual_buffer_size, requested_size, last_buffer, - buffer_idx); + file_number, buffer_idx); } void CSVBuffer::Unpin() { diff --git a/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer_manager.cpp b/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer_manager.cpp index fa3ba2a02..811689917 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer_manager.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer_manager.cpp @@ -4,9 +4,10 @@ namespace duckdb { CSVBufferManager::CSVBufferManager(ClientContext &context_p, const CSVReaderOptions &options, const string &file_path_p, - bool per_file_single_threaded_p, unique_ptr file_handle_p) - : context(context_p), per_file_single_threaded(per_file_single_threaded_p), file_path(file_path_p), - buffer_size(options.buffer_size_option.GetValue()) { + const idx_t file_idx_p, bool per_file_single_threaded_p, + unique_ptr file_handle_p) + : context(context_p), per_file_single_threaded(per_file_single_threaded_p), file_idx(file_idx_p), + file_path(file_path_p), buffer_size(options.buffer_size_option.GetValue()) { D_ASSERT(!file_path.empty()); if (file_handle_p) { file_handle = std::move(file_handle_p); @@ -26,7 +27,8 @@ void CSVBufferManager::UnpinBuffer(const idx_t cache_idx) { void CSVBufferManager::Initialize() { if (cached_buffers.empty()) { - cached_buffers.emplace_back(make_shared_ptr(context, buffer_size, *file_handle, global_csv_pos)); + cached_buffers.emplace_back( + make_shared_ptr(context, buffer_size, *file_handle, global_csv_pos, file_idx)); last_buffer = cached_buffers.front(); } } @@ -35,7 +37,7 @@ bool CSVBufferManager::ReadNextAndCacheIt() { D_ASSERT(last_buffer); for (idx_t i = 0; i < 2; i++) { if (!last_buffer->IsCSVFileLastBuffer()) { - auto maybe_last_buffer = last_buffer->Next(*file_handle, buffer_size, has_seeked); + auto maybe_last_buffer = last_buffer->Next(*file_handle, buffer_size, file_idx, has_seeked); if (!maybe_last_buffer) { last_buffer->last_buffer = true; return false; diff --git a/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp b/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp index 3b5fdc34a..203a626e8 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp @@ -63,9 +63,9 @@ StringValueResult::StringValueResult(CSVStates &states, CSVStateMachine &state_m "Mismatch between the number of columns (%d) in the CSV file and what is expected in the scanner (%d).", number_of_columns, csv_file_scan->file_types.size()); } - icu_loaded = csv_file_scan->buffer_manager->context.db->ExtensionIsLoaded("icu"); + bool icu_loaded = csv_file_scan->buffer_manager->context.db->ExtensionIsLoaded("icu"); for (idx_t i = 0; i < csv_file_scan->file_types.size(); i++) { - auto type = csv_file_scan->file_types[i]; + auto &type = csv_file_scan->file_types[i]; if (type.IsJSONType()) { type = LogicalType::VARCHAR; } @@ -675,9 +675,6 @@ bool LineError::HandleErrors(StringValueResult &result) { result.current_line_position.begin.GetGlobalPosition(result.requested_size, first_nl), line_pos.GetGlobalPosition(result.requested_size), result.path); } - if (!StringValueScanner::CanDirectlyCast(result.csv_file_scan->file_types[col_idx], result.icu_loaded)) { - result.number_of_rows--; - } break; } case UNTERMINATED_QUOTES: @@ -935,16 +932,7 @@ void StringValueResult::InvalidState(StringValueResult &result) { if (result.quoted) { result.current_errors.Insert(UNTERMINATED_QUOTES, result.cur_col_id, result.chunk_col_id, result.last_position); } else { - LinesPerBoundary lines_per_batch(result.iterator.GetBoundaryIdx(), result.lines_read); - bool first_nl = false; - auto borked_line = result.current_line_position.ReconstructCurrentLine(first_nl, result.buffer_handles, - result.PrintErrorLine()); - CSVError csv_error; - auto error = CSVError::InvalidState( - result.state_machine.options, result.cur_col_id, lines_per_batch, borked_line, - result.current_line_position.begin.GetGlobalPosition(result.requested_size, first_nl), - result.last_position.GetGlobalPosition(result.requested_size, first_nl), result.path); - result.error_handler.Error(error, true); + result.current_errors.Insert(INVALID_STATE, result.cur_col_id, result.chunk_col_id, result.last_position); } } @@ -1006,8 +994,7 @@ StringValueScanner::StringValueScanner(const shared_ptr &buffe iterator.buffer_size = state_machine->options.buffer_size_option.GetValue(); } -unique_ptr StringValueScanner::GetCSVScanner(ClientContext &context, CSVReaderOptions &options, - const MultiFileOptions &file_options) { +unique_ptr StringValueScanner::GetCSVScanner(ClientContext &context, CSVReaderOptions &options) { auto state_machine = make_shared_ptr(options, options.dialect_options.state_machine_options, CSVStateMachineCache::Get(context)); @@ -1020,7 +1007,7 @@ unique_ptr StringValueScanner::GetCSVScanner(ClientContext & auto it = BaseScanner::SkipCSVRows(buffer_manager, state_machine, rows_to_skip); auto scanner = make_uniq(buffer_manager, state_machine, make_shared_ptr(), STANDARD_VECTOR_SIZE, it); - scanner->csv_file_scan = make_shared_ptr(context, options.file_path, options, file_options); + scanner->csv_file_scan = make_shared_ptr(context, options.file_path, options); scanner->csv_file_scan->InitializeProjection(); return scanner; } @@ -1036,67 +1023,96 @@ StringValueResult &StringValueScanner::ParseChunk() { } void StringValueScanner::Flush(DataChunk &insert_chunk) { - bool continue_processing; - do { - continue_processing = false; - auto &process_result = ParseChunk(); - // First Get Parsed Chunk - auto &parse_chunk = process_result.ToChunk(); - insert_chunk.Reset(); - // We have to check if we got to error - error_handler->ErrorIfNeeded(); - if (parse_chunk.size() == 0) { - return; - } - // convert the columns in the parsed chunk to the types of the table - insert_chunk.SetCardinality(parse_chunk); - - // We keep track of the borked lines, in case we are ignoring errors - D_ASSERT(csv_file_scan); - - auto &names = csv_file_scan->GetNames(); - // Now Do the cast-aroo - for (idx_t i = 0; i < csv_file_scan->column_ids.size(); i++) { - idx_t result_idx = i; - if (!csv_file_scan->projection_ids.empty()) { - result_idx = csv_file_scan->projection_ids[i].second; - } - if (i >= parse_chunk.ColumnCount()) { - throw InvalidInputException("Mismatch between the schema of different files"); - } - auto &parse_vector = parse_chunk.data[i]; - auto &result_vector = insert_chunk.data[result_idx]; - auto &type = result_vector.GetType(); - auto &parse_type = parse_vector.GetType(); - if (!type.IsJSONType() && (type == LogicalType::VARCHAR || - (type != LogicalType::VARCHAR && parse_type != LogicalType::VARCHAR))) { - // reinterpret rather than reference - result_vector.Reinterpret(parse_vector); - } else { - string error_message; - idx_t line_error = 0; - if (VectorOperations::TryCast(buffer_manager->context, parse_vector, result_vector, parse_chunk.size(), - &error_message, false, true)) { - continue; + insert_chunk.Reset(); + auto &process_result = ParseChunk(); + // First Get Parsed Chunk + auto &parse_chunk = process_result.ToChunk(); + // We have to check if we got to error + error_handler->ErrorIfNeeded(); + if (parse_chunk.size() == 0) { + return; + } + // convert the columns in the parsed chunk to the types of the table + insert_chunk.SetCardinality(parse_chunk); + + // We keep track of the borked lines, in case we are ignoring errors + D_ASSERT(csv_file_scan); + + auto &names = csv_file_scan->GetNames(); + auto &reader_data = csv_file_scan->reader_data; + // Now Do the cast-aroo + for (idx_t c = 0; c < reader_data.column_ids.size(); c++) { + idx_t col_idx = c; + idx_t result_idx = reader_data.column_mapping[c]; + if (!csv_file_scan->projection_ids.empty()) { + result_idx = reader_data.column_mapping[csv_file_scan->projection_ids[c].second]; + } + if (col_idx >= parse_chunk.ColumnCount()) { + throw InvalidInputException("Mismatch between the schema of different files"); + } + auto &parse_vector = parse_chunk.data[col_idx]; + auto &result_vector = insert_chunk.data[result_idx]; + const auto &type = result_vector.GetType(); + auto &parse_type = parse_vector.GetType(); + if (!type.IsJSONType() && + (type == LogicalType::VARCHAR || (type != LogicalType::VARCHAR && parse_type != LogicalType::VARCHAR))) { + // reinterpret rather than reference + result_vector.Reinterpret(parse_vector); + } else { + string error_message; + idx_t line_error = 0; + if (VectorOperations::TryCast(buffer_manager->context, parse_vector, result_vector, parse_chunk.size(), + &error_message, false, true)) { + continue; + } + // An error happened, to propagate it we need to figure out the exact line where the casting failed. + UnifiedVectorFormat inserted_column_data; + result_vector.ToUnifiedFormat(parse_chunk.size(), inserted_column_data); + UnifiedVectorFormat parse_column_data; + parse_vector.ToUnifiedFormat(parse_chunk.size(), parse_column_data); + + for (; line_error < parse_chunk.size(); line_error++) { + if (!inserted_column_data.validity.RowIsValid(line_error) && + parse_column_data.validity.RowIsValid(line_error)) { + break; } - // An error happened, to propagate it we need to figure out the exact line where the casting failed. - UnifiedVectorFormat inserted_column_data; - result_vector.ToUnifiedFormat(parse_chunk.size(), inserted_column_data); - UnifiedVectorFormat parse_column_data; - parse_vector.ToUnifiedFormat(parse_chunk.size(), parse_column_data); - - for (; line_error < parse_chunk.size(); line_error++) { - if (!inserted_column_data.validity.RowIsValid(line_error) && - parse_column_data.validity.RowIsValid(line_error)) { - break; + } + { + + if (state_machine->options.ignore_errors.GetValue()) { + vector row; + for (idx_t col = 0; col < parse_chunk.ColumnCount(); col++) { + row.push_back(parse_chunk.GetValue(col, line_error)); } } - { - if (state_machine->options.ignore_errors.GetValue()) { - vector row; - for (idx_t col = 0; col < parse_chunk.ColumnCount(); col++) { - row.push_back(parse_chunk.GetValue(col, line_error)); - } + if (!state_machine->options.IgnoreErrors()) { + LinesPerBoundary lines_per_batch(iterator.GetBoundaryIdx(), + lines_read - parse_chunk.size() + line_error); + bool first_nl = false; + auto borked_line = result.line_positions_per_row[line_error].ReconstructCurrentLine( + first_nl, result.buffer_handles, result.PrintErrorLine()); + std::ostringstream error; + error << "Could not convert string \"" << parse_vector.GetValue(line_error) << "\" to \'" + << type.ToString() << "\'"; + string error_msg = error.str(); + SanitizeError(error_msg); + auto csv_error = CSVError::CastError( + state_machine->options, names[col_idx], error_msg, col_idx, borked_line, lines_per_batch, + result.line_positions_per_row[line_error].begin.GetGlobalPosition(result.result_size, first_nl), + optional_idx::Invalid(), result_vector.GetType().id(), result.path); + error_handler->Error(csv_error); + } + } + result.borked_rows.insert(line_error++); + D_ASSERT(state_machine->options.ignore_errors.GetValue()); + // We are ignoring errors. We must continue but ignoring borked-rows + for (; line_error < parse_chunk.size(); line_error++) { + if (!inserted_column_data.validity.RowIsValid(line_error) && + parse_column_data.validity.RowIsValid(line_error)) { + result.borked_rows.insert(line_error); + vector row; + for (idx_t col = 0; col < parse_chunk.ColumnCount(); col++) { + row.push_back(parse_chunk.GetValue(col, line_error)); } if (!state_machine->options.IgnoreErrors()) { LinesPerBoundary lines_per_batch(iterator.GetBoundaryIdx(), @@ -1105,86 +1121,35 @@ void StringValueScanner::Flush(DataChunk &insert_chunk) { auto borked_line = result.line_positions_per_row[line_error].ReconstructCurrentLine( first_nl, result.buffer_handles, result.PrintErrorLine()); std::ostringstream error; + // Casting Error Message error << "Could not convert string \"" << parse_vector.GetValue(line_error) << "\" to \'" - << type.ToString() << "\'"; + << LogicalTypeIdToString(type.id()) << "\'"; string error_msg = error.str(); SanitizeError(error_msg); - idx_t row_byte_pos = 0; - if (!(result.line_positions_per_row[line_error].begin == - result.line_positions_per_row[line_error].end)) { - row_byte_pos = result.line_positions_per_row[line_error].begin.GetGlobalPosition( - result.result_size, first_nl); - } auto csv_error = CSVError::CastError( - state_machine->options, names[i], error_msg, i, borked_line, lines_per_batch, row_byte_pos, + state_machine->options, names[col_idx], error_msg, col_idx, borked_line, lines_per_batch, + result.line_positions_per_row[line_error].begin.GetGlobalPosition(result.result_size, + first_nl), optional_idx::Invalid(), result_vector.GetType().id(), result.path); error_handler->Error(csv_error); } } - result.borked_rows.insert(line_error++); - D_ASSERT(state_machine->options.ignore_errors.GetValue()); - // We are ignoring errors. We must continue but ignoring borked-rows - for (; line_error < parse_chunk.size(); line_error++) { - if (!inserted_column_data.validity.RowIsValid(line_error) && - parse_column_data.validity.RowIsValid(line_error)) { - result.borked_rows.insert(line_error); - vector row; - for (idx_t col = 0; col < parse_chunk.ColumnCount(); col++) { - row.push_back(parse_chunk.GetValue(col, line_error)); - } - if (!state_machine->options.IgnoreErrors()) { - LinesPerBoundary lines_per_batch(iterator.GetBoundaryIdx(), - lines_read - parse_chunk.size() + line_error); - bool first_nl = false; - auto borked_line = result.line_positions_per_row[line_error].ReconstructCurrentLine( - first_nl, result.buffer_handles, result.PrintErrorLine()); - std::ostringstream error; - // Casting Error Message - error << "Could not convert string \"" << parse_vector.GetValue(line_error) << "\" to \'" - << LogicalTypeIdToString(type.id()) << "\'"; - string error_msg = error.str(); - SanitizeError(error_msg); - auto csv_error = CSVError::CastError( - state_machine->options, names[i], error_msg, i, borked_line, lines_per_batch, - result.line_positions_per_row[line_error].begin.GetGlobalPosition(result.result_size, - first_nl), - optional_idx::Invalid(), result_vector.GetType().id(), result.path); - error_handler->Error(csv_error); - } - } - } - } - } - if (!result.borked_rows.empty()) { - // We must remove the borked lines from our chunk - SelectionVector successful_rows(parse_chunk.size()); - idx_t sel_idx = 0; - for (idx_t row_idx = 0; row_idx < parse_chunk.size(); row_idx++) { - if (result.borked_rows.find(row_idx) == result.borked_rows.end()) { - successful_rows.set_index(sel_idx++, row_idx); - } } - // Now we slice the result - insert_chunk.Slice(successful_rows, sel_idx); - result.borked_rows.clear(); } - if (insert_chunk.size() == 0 && cur_buffer_handle) { - idx_t to_pos; - if (iterator.IsBoundarySet()) { - to_pos = iterator.GetEndPos(); - if (to_pos > cur_buffer_handle->actual_size) { - to_pos = cur_buffer_handle->actual_size; - } - } else { - to_pos = cur_buffer_handle->actual_size; - } - if (iterator.pos.buffer_pos < to_pos) { - // If a chunk is complete with errors, we might get to this situation where we must proceed with the - // scanning - continue_processing = true; + } + if (!result.borked_rows.empty()) { + // We must remove the borked lines from our chunk + SelectionVector successful_rows(parse_chunk.size()); + idx_t sel_idx = 0; + for (idx_t row_idx = 0; row_idx < parse_chunk.size(); row_idx++) { + if (result.borked_rows.find(row_idx) == result.borked_rows.end()) { + successful_rows.set_index(sel_idx++, row_idx); } } - } while (continue_processing); + // Now we slice the result + insert_chunk.Slice(successful_rows, sel_idx); + result.borked_rows.clear(); + } } void StringValueScanner::Initialize() { @@ -1385,39 +1350,8 @@ void StringValueScanner::ProcessOverBufferValue() { } if (over_buffer_string.empty() && state_machine->dialect_options.state_machine_options.new_line == NewLineIdentifier::CARRY_ON) { - if (!iterator.IsBoundarySet()) { - if (buffer_handle_ptr[iterator.pos.buffer_pos] == '\n') { - iterator.pos.buffer_pos++; - } - } else { - while (iterator.pos.buffer_pos < cur_buffer_handle->actual_size && - (buffer_handle_ptr[iterator.pos.buffer_pos] == '\n' || - buffer_handle_ptr[iterator.pos.buffer_pos] == '\r')) { - if (buffer_handle_ptr[iterator.pos.buffer_pos] == '\r') { - if (result.last_position.buffer_pos <= previous_buffer_handle->actual_size) { - // we add the value - result.AddValue(result, previous_buffer_handle->actual_size); - if (result.IsCommentSet(result)) { - result.UnsetComment(result, iterator.pos.buffer_pos); - } else { - result.AddRow(result, previous_buffer_handle->actual_size); - } - state_machine->Transition(states, buffer_handle_ptr[iterator.pos.buffer_pos++]); - while (iterator.pos.buffer_pos < cur_buffer_handle->actual_size && - (buffer_handle_ptr[iterator.pos.buffer_pos] == '\r' || - buffer_handle_ptr[iterator.pos.buffer_pos] == '\n')) { - state_machine->Transition(states, buffer_handle_ptr[iterator.pos.buffer_pos++]); - } - return; - } - } else { - if (iterator.pos.buffer_pos + 1 == cur_buffer_handle->actual_size) { - return; - } - } - state_machine->Transition(states, buffer_handle_ptr[iterator.pos.buffer_pos]); - iterator.pos.buffer_pos++; - } + if (buffer_handle_ptr[iterator.pos.buffer_pos] == '\n') { + iterator.pos.buffer_pos++; } } // second buffer @@ -1492,13 +1426,12 @@ void StringValueScanner::ProcessOverBufferValue() { result.EmptyLine(result, iterator.pos.buffer_pos); } else if (!states.IsNotSet() && (!result.comment || !value.Empty())) { idx_t value_size = value.GetSize(); - if (states.IsDelimiter() && - !result.state_machine.dialect_options.state_machine_options.delimiter.GetValue().empty()) { + if (states.IsDelimiter()) { idx_t extra_delimiter_bytes = result.state_machine.dialect_options.state_machine_options.delimiter.GetValue().size() - 1; if (extra_delimiter_bytes > value_size) { throw InternalException( - "Value size is lower than the number of extra delimiter bytes in the ProcessOverBufferValue()"); + "Value size is lower than the number of extra delimiter bytes in the ProcesOverBufferValue()"); } value_size -= extra_delimiter_bytes; } @@ -1598,7 +1531,10 @@ bool StringValueScanner::MoveToNextBuffer() { } void StringValueResult::SkipBOM() const { - StringUtil::SkipBOM(buffer_ptr, buffer_size, iterator.pos.buffer_pos); + if (buffer_size >= 3 && buffer_ptr[0] == '\xEF' && buffer_ptr[1] == '\xBB' && buffer_ptr[2] == '\xBF' && + iterator.pos.buffer_pos == 0) { + iterator.pos.buffer_pos = 3; + } } void StringValueResult::RemoveLastLine() { @@ -1714,14 +1650,13 @@ bool StringValueScanner::CanDirectlyCast(const LogicalType &type, bool icu_loade case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIME: case LogicalTypeId::DECIMAL: + case LogicalType::VARCHAR: case LogicalType::BOOLEAN: return true; case LogicalType::TIMESTAMP_TZ: // We only try to do direct cast of timestamp tz if the ICU extension is not loaded, otherwise, it needs to go // through string -> timestamp_tz casting return !icu_loaded; - case LogicalType::VARCHAR: - return !type.IsJSONType(); default: return false; } @@ -1891,16 +1826,17 @@ void StringValueScanner::FinalizeChunkProcess() { if (cur_buffer_handle->is_last_buffer && iterator.pos.buffer_pos >= cur_buffer_handle->actual_size) { MoveToNextBuffer(); } - } - if (result.current_errors.HasErrorType(UNTERMINATED_QUOTES)) { - found_error = true; - type = UNTERMINATED_QUOTES; - } else if (result.current_errors.HasErrorType(INVALID_STATE)) { - found_error = true; - type = INVALID_STATE; - } - if (result.current_errors.HandleErrors(result)) { - result.number_of_rows++; + } else { + if (result.current_errors.HasErrorType(UNTERMINATED_QUOTES)) { + found_error = true; + type = UNTERMINATED_QUOTES; + } else if (result.current_errors.HasErrorType(INVALID_STATE)) { + found_error = true; + type = INVALID_STATE; + } + if (result.current_errors.HandleErrors(result)) { + result.number_of_rows++; + } } if (states.IsQuotedCurrent() && !found_error && state_machine->dialect_options.state_machine_options.strict_mode.GetValue()) { diff --git a/src/duckdb/src/execution/operator/csv_scanner/sniffer/csv_sniffer.cpp b/src/duckdb/src/execution/operator/csv_scanner/sniffer/csv_sniffer.cpp index bcaed8e5f..c8740ebde 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/sniffer/csv_sniffer.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/sniffer/csv_sniffer.cpp @@ -3,12 +3,10 @@ namespace duckdb { -CSVSniffer::CSVSniffer(CSVReaderOptions &options_p, const MultiFileOptions &file_options, - shared_ptr buffer_manager_p, CSVStateMachineCache &state_machine_cache_p, - bool default_null_to_varchar_p) - : state_machine_cache(state_machine_cache_p), options(options_p), file_options(file_options), - buffer_manager(std::move(buffer_manager_p)), lines_sniffed(0), - default_null_to_varchar(default_null_to_varchar_p) { +CSVSniffer::CSVSniffer(CSVReaderOptions &options_p, shared_ptr buffer_manager_p, + CSVStateMachineCache &state_machine_cache_p, bool default_null_to_varchar_p) + : state_machine_cache(state_machine_cache_p), options(options_p), buffer_manager(std::move(buffer_manager_p)), + lines_sniffed(0), default_null_to_varchar(default_null_to_varchar_p) { // Initialize Format Candidates for (const auto &format_template : format_template_candidates) { auto &logical_type = format_template.first; @@ -23,6 +21,20 @@ CSVSniffer::CSVSniffer(CSVReaderOptions &options_p, const MultiFileOptions &file } } +bool SetColumns::IsSet() const { + if (!types) { + return false; + } + return !types->empty(); +} + +idx_t SetColumns::Size() const { + if (!types) { + return 0; + } + return types->size(); +} + template void MatchAndReplace(CSVOption &original, CSVOption &sniffed, const string &name, string &error) { if (original.IsSetByUser()) { @@ -131,7 +143,7 @@ AdaptiveSnifferResult CSVSniffer::MinimalSniff() { } auto names = DetectHeaderInternal(buffer_manager->context, potential_header, *state_machine, set_columns, - best_sql_types_candidates_per_column_idx, options, file_options, *error_handler); + best_sql_types_candidates_per_column_idx, options, *error_handler); for (idx_t column_idx = 0; column_idx < best_sql_types_candidates_per_column_idx.size(); column_idx++) { LogicalType d_type = best_sql_types_candidates_per_column_idx[column_idx].back(); @@ -149,7 +161,7 @@ SnifferResult CSVSniffer::AdaptiveSniff(const CSVSchema &file_schema) { // Check if we are happy with the result or if we need to do more sniffing if (!error_handler->AnyErrors() && !detection_error_handler->AnyErrors()) { // If we got no errors, we also run full if schemas do not match. - if (!set_columns.IsSet() && !file_options.AnySet()) { + if (!set_columns.IsSet() && !options.file_options.AnySet()) { string error; run_full = !file_schema.SchemasMatch(error, min_sniff_res, options.file_path, true); } @@ -157,7 +169,7 @@ SnifferResult CSVSniffer::AdaptiveSniff(const CSVSchema &file_schema) { if (run_full) { // We run full sniffer auto full_sniffer = SniffCSV(); - if (!set_columns.IsSet() && !file_options.AnySet()) { + if (!set_columns.IsSet() && !options.file_options.AnySet()) { string error; if (!file_schema.SchemasMatch(error, full_sniffer, options.file_path, false) && !options.ignore_errors.GetValue()) { diff --git a/src/duckdb/src/execution/operator/csv_scanner/sniffer/dialect_detection.cpp b/src/duckdb/src/execution/operator/csv_scanner/sniffer/dialect_detection.cpp index a1eb04a03..ae17695f4 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/sniffer/dialect_detection.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/sniffer/dialect_detection.cpp @@ -259,7 +259,6 @@ void CSVSniffer::AnalyzeDialectCandidate(unique_ptr scanner, } if (set_columns.IsCandidateUnacceptable(num_cols, options.null_padding, ignore_errors, sniffed_column_counts[0].last_value_always_empty)) { - max_columns_found_error = num_cols > max_columns_found_error ? num_cols : max_columns_found_error; // Not acceptable return; } @@ -267,9 +266,6 @@ void CSVSniffer::AnalyzeDialectCandidate(unique_ptr scanner, for (idx_t row = 0; row < sniffed_column_counts.result_position; row++) { if (set_columns.IsCandidateUnacceptable(sniffed_column_counts[row].number_of_columns, options.null_padding, ignore_errors, sniffed_column_counts[row].last_value_always_empty)) { - max_columns_found_error = sniffed_column_counts[row].number_of_columns > max_columns_found_error - ? sniffed_column_counts[row].number_of_columns - : max_columns_found_error; // Not acceptable return; } @@ -365,8 +361,6 @@ void CSVSniffer::AnalyzeDialectCandidate(unique_ptr scanner, (num_cols == set_columns.Size() + 1 && sniffed_column_counts[0].last_value_always_empty) || !set_columns.IsSet(); - max_columns_found_error = num_cols > max_columns_found_error ? num_cols : max_columns_found_error; - // If rows are consistent and no invalid padding happens, this is the best suitable candidate if one of the // following is valid: // - There's a single column before. @@ -608,7 +602,7 @@ void CSVSniffer::DetectDialect() { // if no dialect candidate was found, we throw an exception if (candidates.empty()) { - auto error = CSVError::SniffingError(options, dialect_candidates.Print(), max_columns_found_error, set_columns); + auto error = CSVError::SniffingError(options, dialect_candidates.Print()); error_handler->Error(error, true); } } diff --git a/src/duckdb/src/execution/operator/csv_scanner/sniffer/header_detection.cpp b/src/duckdb/src/execution/operator/csv_scanner/sniffer/header_detection.cpp index 71611742f..0e84320ad 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/sniffer/header_detection.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/sniffer/header_detection.cpp @@ -103,11 +103,11 @@ static string NormalizeColumnName(const string &col_name) { static void ReplaceNames(vector &detected_names, CSVStateMachine &state_machine, unordered_map> &best_sql_types_candidates_per_column_idx, - CSVReaderOptions &options, const MultiFileOptions &file_options, - const vector &best_header_row, CSVErrorHandler &error_handler) { + CSVReaderOptions &options, const vector &best_header_row, + CSVErrorHandler &error_handler) { auto &dialect_options = state_machine.dialect_options; if (!options.columns_set) { - if (file_options.hive_partitioning || file_options.union_by_name || options.multi_file_reader) { + if (options.file_options.hive_partitioning || options.file_options.union_by_name || options.multi_file_reader) { // Just do the replacement for (idx_t i = 0; i < MinValue(detected_names.size(), options.name_list.size()); i++) { detected_names[i] = options.name_list[i]; @@ -216,10 +216,11 @@ bool EmptyHeader(const string &col_name, bool is_null, bool normalize) { return true; } -vector CSVSniffer::DetectHeaderInternal( - ClientContext &context, vector &best_header_row, CSVStateMachine &state_machine, - const SetColumns &set_columns, unordered_map> &best_sql_types_candidates_per_column_idx, - CSVReaderOptions &options, const MultiFileOptions &file_options, CSVErrorHandler &error_handler) { +vector +CSVSniffer::DetectHeaderInternal(ClientContext &context, vector &best_header_row, + CSVStateMachine &state_machine, const SetColumns &set_columns, + unordered_map> &best_sql_types_candidates_per_column_idx, + CSVReaderOptions &options, CSVErrorHandler &error_handler) { vector detected_names; auto &dialect_options = state_machine.dialect_options; dialect_options.num_cols = best_sql_types_candidates_per_column_idx.size(); @@ -229,8 +230,8 @@ vector CSVSniffer::DetectHeaderInternal( detected_names.push_back(GenerateColumnName(dialect_options.num_cols, col)); } // If the user provided names, we must replace our header with the user provided names - ReplaceNames(detected_names, state_machine, best_sql_types_candidates_per_column_idx, options, file_options, - best_header_row, error_handler); + ReplaceNames(detected_names, state_machine, best_sql_types_candidates_per_column_idx, options, best_header_row, + error_handler); return detected_names; } // information for header detection @@ -244,7 +245,7 @@ vector CSVSniffer::DetectHeaderInternal( detected_names.push_back(GenerateColumnName(dialect_options.num_cols, col)); } dialect_options.rows_until_header += 1; - ReplaceNames(detected_names, state_machine, best_sql_types_candidates_per_column_idx, options, file_options, + ReplaceNames(detected_names, state_machine, best_sql_types_candidates_per_column_idx, options, best_header_row, error_handler); return detected_names; } @@ -337,14 +338,14 @@ vector CSVSniffer::DetectHeaderInternal( } // If the user provided names, we must replace our header with the user provided names - ReplaceNames(detected_names, state_machine, best_sql_types_candidates_per_column_idx, options, file_options, - best_header_row, error_handler); + ReplaceNames(detected_names, state_machine, best_sql_types_candidates_per_column_idx, options, best_header_row, + error_handler); return detected_names; } void CSVSniffer::DetectHeader() { auto &sniffer_state_machine = best_candidate->GetStateMachine(); names = DetectHeaderInternal(buffer_manager->context, best_header_row, sniffer_state_machine, set_columns, - best_sql_types_candidates_per_column_idx, options, file_options, *error_handler); + best_sql_types_candidates_per_column_idx, options, *error_handler); if (EmptyOrOnlyHeader()) { // This file only contains a header, lets default to the lowest type of all. detected_types.clear(); diff --git a/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_detection.cpp b/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_detection.cpp index 339408363..f362c8952 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_detection.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_detection.cpp @@ -73,12 +73,12 @@ static bool StartsWithNumericDate(string &separator, const string_t &value) { string GenerateDateFormat(const string &separator, const char *format_template) { string format_specifier = format_template; - const auto amount_of_dashes = NumericCast(std::count(format_specifier.begin(), format_specifier.end(), '-')); + auto amount_of_dashes = NumericCast(std::count(format_specifier.begin(), format_specifier.end(), '-')); // All our date formats must have at least one - D_ASSERT(amount_of_dashes); string result; result.reserve(format_specifier.size() - amount_of_dashes + (amount_of_dashes * separator.size())); - for (const auto &character : format_specifier) { + for (auto &character : format_specifier) { if (character == '-') { result += separator; } else { @@ -176,8 +176,7 @@ bool CSVSniffer::CanYouCastIt(ClientContext &context, const string_t value, cons ->second.GetValue() .TryParseTimestamp(value, dummy_value, error_message); } - return Timestamp::TryConvertTimestamp(value_ptr, value_size, dummy_value, nullptr, true) == - TimestampCastResult::SUCCESS; + return Timestamp::TryConvertTimestamp(value_ptr, value_size, dummy_value) == TimestampCastResult::SUCCESS; } case LogicalTypeId::TIME: { idx_t pos; @@ -250,8 +249,7 @@ bool CSVSniffer::CanYouCastIt(ClientContext &context, const string_t value, cons Value new_value; string error_message; Value str_value(value); - bool success = str_value.TryCastAs(context, type, new_value, &error_message, true); - return success && error_message.empty(); + return str_value.TryCastAs(context, type, new_value, &error_message, true); } } } @@ -376,13 +374,10 @@ void CSVSniffer::SniffTypes(DataChunk &data_chunk, CSVStateMachine &state_machin !null_mask.RowIsValid(row_idx), state_machine.options.decimal_separator[0])) { break; } - D_ASSERT(cur_top_candidate.id() == LogicalTypeId::VARCHAR || col_type_candidates.size() > 1); + if (row_idx != start_idx_detection && (cur_top_candidate == LogicalType::BOOLEAN || cur_top_candidate == LogicalType::DATE || - cur_top_candidate == LogicalType::TIME || - (cur_top_candidate == LogicalType::TIMESTAMP && - col_type_candidates[col_type_candidates.size() - 2] != LogicalType::TIMESTAMP_TZ) || - cur_top_candidate == LogicalType::TIMESTAMP_TZ)) { + cur_top_candidate == LogicalType::TIME || cur_top_candidate == LogicalType::TIMESTAMP)) { // If we thought this was a boolean value (i.e., T,F, True, False) and it is not, we // immediately pop to varchar. while (col_type_candidates.back() != LogicalType::VARCHAR) { @@ -493,7 +488,7 @@ void CSVSniffer::DetectTypes() { } if (!best_candidate) { DialectCandidates dialect_candidates(options.dialect_options.state_machine_options); - auto error = CSVError::SniffingError(options, dialect_candidates.Print(), max_columns_found, set_columns); + auto error = CSVError::SniffingError(options, dialect_candidates.Print()); error_handler->Error(error, true); } // Assert that it's all good at this point. diff --git a/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_replacement.cpp b/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_replacement.cpp index bf6f85888..a693144de 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_replacement.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_replacement.cpp @@ -22,7 +22,8 @@ void CSVSniffer::ReplaceTypes() { found++; } } - if (!file_options.union_by_name && found < sniffing_state_machine.options.sql_types_per_column.size()) { + if (!sniffing_state_machine.options.file_options.union_by_name && + found < sniffing_state_machine.options.sql_types_per_column.size()) { auto error_msg = CSVError::ColumnTypesError(options.sql_types_per_column, names); error_handler->Error(error_msg); } diff --git a/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.cpp b/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.cpp index 332937d5b..93d76a0ee 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.cpp @@ -42,15 +42,6 @@ void CSVStateMachineCache::Insert(const CSVStateMachineOptions &state_machine_op case CSVState::COMMENT: InitializeTransitionArray(transition_array, cur_state, CSVState::COMMENT); break; - case CSVState::CARRIAGE_RETURN: - if (state_machine_options.strict_mode.GetValue()) { - // If we have an unquoted state, following rfc 4180, our base state is invalid - InitializeTransitionArray(transition_array, cur_state, CSVState::INVALID); - } else { - // This will allow us to accept unescaped quotes - InitializeTransitionArray(transition_array, cur_state, CSVState::STANDARD); - } - break; default: InitializeTransitionArray(transition_array, cur_state, CSVState::STANDARD); break; @@ -94,25 +85,10 @@ void CSVStateMachineCache::Insert(const CSVStateMachineOptions &state_machine_op } else { transition_array[static_cast('\n')][state] = CSVState::INVALID; } - } else if (new_line_id == NewLineIdentifier::SINGLE_N) { - transition_array[static_cast('\n')][state] = CSVState::RECORD_SEPARATOR; - if (!state_machine_options.strict_mode.GetValue()) { - transition_array[static_cast('\r')][state] = CSVState::RECORD_SEPARATOR; - } else { - transition_array[static_cast('\r')][state] = CSVState::INVALID; - } - } else if (new_line_id == NewLineIdentifier::SINGLE_R) { - transition_array[static_cast('\r')][state] = CSVState::RECORD_SEPARATOR; - if (!state_machine_options.strict_mode.GetValue()) { - transition_array[static_cast('\n')][state] = CSVState::RECORD_SEPARATOR; - } else { - transition_array[static_cast('\n')][state] = CSVState::INVALID; - } } else { transition_array[static_cast('\r')][state] = CSVState::RECORD_SEPARATOR; transition_array[static_cast('\n')][state] = CSVState::RECORD_SEPARATOR; } - if (comment != '\0') { transition_array[comment][state] = CSVState::COMMENT; } @@ -210,34 +186,12 @@ void CSVStateMachineCache::Insert(const CSVStateMachineOptions &state_machine_op if (enable_unquoted_escape) { transition_array[escape][static_cast(CSVState::RECORD_SEPARATOR)] = CSVState::UNQUOTED_ESCAPE; } - if (state_machine_options.strict_mode.GetValue()) { - // strict rules to error on the new line delimiter - switch (new_line_id) { - case NewLineIdentifier::CARRY_ON: - case NewLineIdentifier::SINGLE_R: - transition_array[static_cast('\n')][static_cast(CSVState::RECORD_SEPARATOR)] = - CSVState::INVALID; - break; - case NewLineIdentifier::SINGLE_N: - transition_array[static_cast('\r')][static_cast(CSVState::RECORD_SEPARATOR)] = - CSVState::INVALID; - break; - default: - break; - } - } // 4) Carriage Return State transition_array[static_cast('\n')][static_cast(CSVState::CARRIAGE_RETURN)] = CSVState::RECORD_SEPARATOR; - if (state_machine_options.strict_mode.GetValue()) { - transition_array[static_cast('\r')][static_cast(CSVState::CARRIAGE_RETURN)] = - CSVState::INVALID; - } else { - transition_array[static_cast('\r')][static_cast(CSVState::CARRIAGE_RETURN)] = - CSVState::CARRIAGE_RETURN; - } - + transition_array[static_cast('\r')][static_cast(CSVState::CARRIAGE_RETURN)] = + CSVState::CARRIAGE_RETURN; if (quote != '\0') { transition_array[quote][static_cast(CSVState::CARRIAGE_RETURN)] = CSVState::QUOTED; } @@ -278,20 +232,7 @@ void CSVStateMachineCache::Insert(const CSVStateMachineOptions &state_machine_op if (state_machine_options.quote == state_machine_options.escape) { transition_array[quote][static_cast(CSVState::UNQUOTED)] = CSVState::QUOTED; } - if (state_machine_options.strict_mode.GetValue()) { - // strict rules to error on the new line delimiter - switch (new_line_id) { - case NewLineIdentifier::CARRY_ON: - case NewLineIdentifier::SINGLE_R: - transition_array[static_cast('\n')][static_cast(CSVState::UNQUOTED)] = CSVState::INVALID; - break; - case NewLineIdentifier::SINGLE_N: - transition_array[static_cast('\r')][static_cast(CSVState::UNQUOTED)] = CSVState::INVALID; - break; - default: - break; - } - } else { + if (state_machine_options.strict_mode == false) { if (escape == '\0') { // If escape is defined, it limits a bit how relaxed quotes can be in a reliable way. transition_array[quote][static_cast(CSVState::UNQUOTED)] = CSVState::MAYBE_QUOTED; diff --git a/src/duckdb/src/execution/operator/csv_scanner/table_function/csv_file_scanner.cpp b/src/duckdb/src/execution/operator/csv_scanner/table_function/csv_file_scanner.cpp index 000592a0a..ed251cbd0 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/table_function/csv_file_scanner.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/table_function/csv_file_scanner.cpp @@ -5,36 +5,138 @@ #include "duckdb/function/table/read_csv.hpp" namespace duckdb { +CSVUnionData::~CSVUnionData() { +} -CSVFileScan::CSVFileScan(ClientContext &context, const string &file_path_p, CSVReaderOptions options_p, - const MultiFileOptions &file_options, const vector &names, - const vector &types, CSVSchema &file_schema, bool per_file_single_threaded, - shared_ptr buffer_manager_p, bool fixed_schema) - : BaseFileReader(file_path_p), buffer_manager(std::move(buffer_manager_p)), +CSVFileScan::CSVFileScan(ClientContext &context, shared_ptr buffer_manager_p, + shared_ptr state_machine_p, const CSVReaderOptions &options_p, + const ReadCSVData &bind_data, const vector &column_ids, CSVSchema &file_schema) + : file_path(options_p.file_path), file_idx(0), buffer_manager(std::move(buffer_manager_p)), + state_machine(std::move(state_machine_p)), file_size(buffer_manager->file_handle->FileSize()), error_handler(make_shared_ptr(options_p.ignore_errors.GetValue())), - options(std::move(options_p)) { + on_disk_file(buffer_manager->file_handle->OnDiskFile()), options(options_p) { + + auto global_columns = + MultiFileReaderColumnDefinition::ColumnsFromNamesAndTypes(bind_data.return_names, bind_data.return_types); + + auto multi_file_reader = MultiFileReader::CreateDefault("CSV Scan"); + if (bind_data.initial_reader.get()) { + auto &union_reader = *bind_data.initial_reader; + SetNamesAndTypes(union_reader.GetNames(), union_reader.GetTypes()); + options = union_reader.options; + multi_file_reader->InitializeReader(*this, options.file_options, bind_data.reader_bind, global_columns, + column_ids, nullptr, file_path, context, nullptr); + InitializeFileNamesTypes(); + return; + } + if (!bind_data.column_info.empty()) { + // Serialized Union By name + SetNamesAndTypes(bind_data.column_info[0].names, bind_data.column_info[0].types); + multi_file_reader->InitializeReader(*this, options.file_options, bind_data.reader_bind, global_columns, + column_ids, nullptr, file_path, context, nullptr); + InitializeFileNamesTypes(); + return; + } + SetNamesAndTypes(bind_data.csv_names, bind_data.csv_types); - // Initialize Buffer Manager - if (!buffer_manager) { - buffer_manager = make_shared_ptr(context, options, file_name, per_file_single_threaded); + file_schema.Initialize(names, types, file_path); + multi_file_reader->InitializeReader(*this, options.file_options, bind_data.reader_bind, global_columns, column_ids, + nullptr, file_path, context, nullptr); + + InitializeFileNamesTypes(); + SetStart(); +} + +void CSVFileScan::SetStart() { + idx_t rows_to_skip = options.GetSkipRows() + state_machine->dialect_options.header.GetValue(); + rows_to_skip = std::max(rows_to_skip, state_machine->dialect_options.rows_until_header + + state_machine->dialect_options.header.GetValue()); + if (rows_to_skip == 0) { + start_iterator.first_one = true; + return; } + SkipScanner skip_scanner(buffer_manager, state_machine, error_handler, rows_to_skip); + skip_scanner.ParseChunk(); + start_iterator = skip_scanner.GetIterator(); +} + +void CSVFileScan::SetNamesAndTypes(const vector &names_p, const vector &types_p) { + names = names_p; + types = types_p; + columns = MultiFileReaderColumnDefinition::ColumnsFromNamesAndTypes(names, types); +} + +CSVFileScan::CSVFileScan(ClientContext &context, const string &file_path_p, const CSVReaderOptions &options_p, + idx_t file_idx_p, const ReadCSVData &bind_data, const vector &column_ids, + CSVSchema &file_schema, bool per_file_single_threaded) + : file_path(file_path_p), file_idx(file_idx_p), + error_handler(make_shared_ptr(options_p.ignore_errors.GetValue())), options(options_p) { + auto multi_file_reader = MultiFileReader::CreateDefault("CSV Scan"); + + auto global_columns = + MultiFileReaderColumnDefinition::ColumnsFromNamesAndTypes(bind_data.return_names, bind_data.return_types); + + if (file_idx == 0 && bind_data.initial_reader) { + auto &union_reader = *bind_data.initial_reader; + // Initialize Buffer Manager + buffer_manager = union_reader.buffer_manager; + // Initialize On Disk and Size of file + on_disk_file = union_reader.on_disk_file; + file_size = union_reader.file_size; + options = union_reader.options; + SetNamesAndTypes(union_reader.GetNames(), union_reader.GetTypes()); + state_machine = union_reader.state_machine; + multi_file_reader->InitializeReader(*this, options.file_options, bind_data.reader_bind, global_columns, + column_ids, nullptr, file_path, context, nullptr); + + InitializeFileNamesTypes(); + SetStart(); + return; + } + + // Initialize Buffer Manager + buffer_manager = make_shared_ptr(context, options, file_path, file_idx, per_file_single_threaded); // Initialize On Disk and Size of file on_disk_file = buffer_manager->file_handle->OnDiskFile(); file_size = buffer_manager->file_handle->FileSize(); // Initialize State Machine auto &state_machine_cache = CSVStateMachineCache::Get(context); - SetNamesAndTypes(names, types); - if (options.auto_detect) { - if (fixed_schema) { - // schema of the file is fixed - only run the sniffer - CSVSniffer sniffer(options, file_options, buffer_manager, state_machine_cache); - sniffer.SniffCSV(); - } else if (file_schema.Empty()) { - throw InternalException("CSV File Scanner cannot be created without a schema"); - } else if (buffer_manager->file_handle->FileSize() > 0) { - options.file_path = file_name; - CSVSniffer sniffer(options, file_options, buffer_manager, state_machine_cache, false); + if (file_idx < bind_data.column_info.size()) { + // (Serialized) Union By name + SetNamesAndTypes(bind_data.column_info[file_idx].names, bind_data.column_info[file_idx].types); + if (file_idx < bind_data.union_readers.size()) { + // union readers - use cached options + D_ASSERT(names == bind_data.union_readers[file_idx]->names); + D_ASSERT(types == bind_data.union_readers[file_idx]->types); + options = bind_data.union_readers[file_idx]->options; + } else { + // Serialized union by name - sniff again + options.dialect_options.num_cols = names.size(); + if (options.auto_detect) { + CSVSniffer sniffer(options, buffer_manager, state_machine_cache); + sniffer.SniffCSV(); + } + } + state_machine = make_shared_ptr( + state_machine_cache.Get(options.dialect_options.state_machine_options), options); + + multi_file_reader->InitializeReader(*this, options.file_options, bind_data.reader_bind, global_columns, + column_ids, nullptr, file_path, context, nullptr); + InitializeFileNamesTypes(); + SetStart(); + return; + } + // Sniff it! + SetNamesAndTypes(bind_data.csv_names, bind_data.csv_types); + if (options.auto_detect && bind_data.files.size() > 1) { + if (file_schema.Empty()) { + CSVSniffer sniffer(options, buffer_manager, state_machine_cache); + auto result = sniffer.SniffCSV(); + file_schema.Initialize(bind_data.csv_names, bind_data.csv_types, options.file_path); + } else if (file_idx > 0 && buffer_manager->file_handle->FileSize() > 0) { + options.file_path = file_path; + CSVSniffer sniffer(options, buffer_manager, state_machine_cache, false); auto result = sniffer.AdaptiveSniff(file_schema); SetNamesAndTypes(result.names, result.return_types); } @@ -48,13 +150,16 @@ CSVFileScan::CSVFileScan(ClientContext &context, const string &file_path_p, CSVR } state_machine = make_shared_ptr( state_machine_cache.Get(options.dialect_options.state_machine_options), options); + multi_file_reader->InitializeReader(*this, options.file_options, bind_data.reader_bind, global_columns, column_ids, + nullptr, file_path, context, nullptr); + InitializeFileNamesTypes(); + SetStart(); } -CSVFileScan::CSVFileScan(ClientContext &context, const string &file_name, const CSVReaderOptions &options_p, - const MultiFileOptions &file_options) - : BaseFileReader(file_name), error_handler(make_shared_ptr(options_p.ignore_errors.GetValue())), - options(options_p) { - buffer_manager = make_shared_ptr(context, options, file_name); +CSVFileScan::CSVFileScan(ClientContext &context, const string &file_name, const CSVReaderOptions &options_p) + : file_path(file_name), file_idx(0), + error_handler(make_shared_ptr(options_p.ignore_errors.GetValue())), options(options_p) { + buffer_manager = make_shared_ptr(context, options, file_path, file_idx); // Initialize On Disk and Size of file on_disk_file = buffer_manager->file_handle->OnDiskFile(); file_size = buffer_manager->file_handle->FileSize(); @@ -62,8 +167,8 @@ CSVFileScan::CSVFileScan(ClientContext &context, const string &file_name, const // error out during scanning) auto &state_machine_cache = CSVStateMachineCache::Get(context); // We sniff file if it has not been sniffed yet and either auto-detect is on, or union by name is on - if ((options.auto_detect || file_options.union_by_name) && options.dialect_options.num_cols == 0) { - CSVSniffer sniffer(options, file_options, buffer_manager, state_machine_cache); + if ((options.auto_detect || options.file_options.union_by_name) && options.dialect_options.num_cols == 0) { + CSVSniffer sniffer(options, buffer_manager, state_machine_cache); auto sniffer_result = sniffer.SniffCSV(); if (names.empty()) { SetNamesAndTypes(sniffer_result.names, sniffer_result.return_types); @@ -79,30 +184,8 @@ CSVFileScan::CSVFileScan(ClientContext &context, const string &file_name, const SetStart(); } -CSVUnionData::~CSVUnionData() { -} - -void CSVFileScan::SetStart() { - idx_t rows_to_skip = options.GetSkipRows() + state_machine->dialect_options.header.GetValue(); - rows_to_skip = std::max(rows_to_skip, state_machine->dialect_options.rows_until_header + - state_machine->dialect_options.header.GetValue()); - if (rows_to_skip == 0) { - start_iterator.first_one = true; - return; - } - SkipScanner skip_scanner(buffer_manager, state_machine, error_handler, rows_to_skip); - skip_scanner.ParseChunk(); - start_iterator = skip_scanner.GetIterator(); -} - -void CSVFileScan::SetNamesAndTypes(const vector &names_p, const vector &types_p) { - names = names_p; - types = types_p; - columns = MultiFileColumnDefinition::ColumnsFromNamesAndTypes(names, types); -} - void CSVFileScan::InitializeFileNamesTypes() { - if (column_ids.empty()) { + if (reader_data.empty_columns && reader_data.column_ids.empty()) { // This means that the columns from this file are irrelevant. // just read the first column file_types.emplace_back(LogicalType::VARCHAR); @@ -111,25 +194,22 @@ void CSVFileScan::InitializeFileNamesTypes() { return; } - for (idx_t i = 0; i < column_ids.size(); i++) { - auto col_idx = MultiFileLocalIndex(i); - auto column_id = column_ids[col_idx]; - file_types.emplace_back(types[column_id.GetId()]); - projected_columns.insert(column_id.GetId()); - projection_ids.emplace_back(column_id.GetId(), col_idx); + for (idx_t i = 0; i < reader_data.column_ids.size(); i++) { + idx_t result_idx = reader_data.column_ids[i]; + file_types.emplace_back(types[result_idx]); + projected_columns.insert(result_idx); + projection_ids.emplace_back(result_idx, i); } - if (column_ids.empty()) { + if (reader_data.column_ids.empty()) { file_types = types; } // We need to be sure that our types are also following the cast_map - if (!cast_map.empty()) { - for (idx_t i = 0; i < column_ids.size(); i++) { - auto local_idx = MultiFileLocalIndex(i); - auto entry = cast_map.find(column_ids[local_idx].GetId()); - if (entry != cast_map.end()) { - file_types[i] = entry->second; + if (!reader_data.cast_map.empty()) { + for (idx_t i = 0; i < reader_data.column_ids.size(); i++) { + if (reader_data.cast_map.find(reader_data.column_ids[i]) != reader_data.cast_map.end()) { + file_types[i] = reader_data.cast_map[reader_data.column_ids[i]]; } } } @@ -143,16 +223,24 @@ void CSVFileScan::InitializeFileNamesTypes() { file_types = sorted_types; } +const string &CSVFileScan::GetFileName() const { + return file_path; +} const vector &CSVFileScan::GetNames() { return names; } const vector &CSVFileScan::GetTypes() { return types; } +const vector &CSVFileScan::GetColumns() { + D_ASSERT(types.size() == columns.size()); + return columns; +} void CSVFileScan::InitializeProjection() { for (idx_t i = 0; i < options.dialect_options.num_cols; i++) { - column_ids.push_back(MultiFileLocalColumnId(i)); + reader_data.column_ids.push_back(i); + reader_data.column_mapping.push_back(i); } } diff --git a/src/duckdb/src/execution/operator/csv_scanner/table_function/global_csv_state.cpp b/src/duckdb/src/execution/operator/csv_scanner/table_function/global_csv_state.cpp index 8276028a1..283a96719 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/table_function/global_csv_state.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/table_function/global_csv_state.cpp @@ -5,103 +5,215 @@ #include "duckdb/execution/operator/persistent/csv_rejects_table.hpp" #include "duckdb/main/appender.hpp" #include "duckdb/main/client_data.hpp" -#include "duckdb/execution/operator/csv_scanner/csv_multi_file_info.hpp" namespace duckdb { -CSVGlobalState::CSVGlobalState(ClientContext &context_p, const CSVReaderOptions &options, idx_t total_file_count, - const MultiFileBindData &bind_data) - : context(context_p), bind_data(bind_data), sniffer_mismatch_error(options.sniffer_user_mismatch_error) { +CSVGlobalState::CSVGlobalState(ClientContext &context_p, const shared_ptr &buffer_manager, + const CSVReaderOptions &options, idx_t system_threads_p, const vector &files, + vector column_ids_p, const ReadCSVData &bind_data_p) + : context(context_p), system_threads(system_threads_p), column_ids(std::move(column_ids_p)), + sniffer_mismatch_error(options.sniffer_user_mismatch_error), bind_data(bind_data_p) { + + if (buffer_manager && buffer_manager->GetFilePath() == files[0]) { + auto state_machine = make_shared_ptr( + CSVStateMachineCache::Get(context).Get(options.dialect_options.state_machine_options), options); + // If we already have a buffer manager, we don't need to reconstruct it to the first file + file_scans.emplace_back(make_uniq(context, buffer_manager, state_machine, options, bind_data, + column_ids, file_schema)); + } else { + // If not we need to construct it for the first file + file_scans.emplace_back( + make_uniq(context, files[0], options, 0U, bind_data, column_ids, file_schema, false)); + } + idx_t cur_file_idx = 0; + while (file_scans.back()->start_iterator.done && file_scans.size() < files.size()) { + cur_file_idx++; + file_scans.emplace_back(make_uniq(context, files[cur_file_idx], options, cur_file_idx, bind_data, + column_ids, file_schema, false)); + } // There are situations where we only support single threaded scanning - auto system_threads = context.db->NumberOfThreads(); - bool many_csv_files = total_file_count > 1 && total_file_count > system_threads * 2; + bool many_csv_files = files.size() > 1 && files.size() > system_threads * 2; single_threaded = many_csv_files || !options.parallel; + last_file_idx = 0; scanner_idx = 0; - initialized = false; + running_threads = CSVGlobalState::MaxThreads(); + current_boundary = file_scans.back()->start_iterator; + current_boundary.SetCurrentBoundaryToPosition(single_threaded, options); + if (current_boundary.done && context.client_data->debug_set_max_line_length) { + context.client_data->debug_max_line_length = current_boundary.pos.buffer_pos; + } + current_buffer_in_use = + make_shared_ptr(*file_scans.back()->buffer_manager, current_boundary.GetBufferIdx()); } -void CSVGlobalState::FinishTask(CSVFileScan &scan) { - auto started_tasks = scan.started_tasks.load(); - auto finished_tasks = ++scan.finished_tasks; - if (finished_tasks == started_tasks) { - // all scans finished for this file - FinishFile(scan); - } else if (finished_tasks > scan.started_tasks) { - throw InternalException("Finished more tasks than were started for this file"); - } +bool CSVGlobalState::IsDone() const { + lock_guard parallel_lock(main_mutex); + return current_boundary.done; } -void CSVGlobalState::FinishScan(unique_ptr scanner) { - if (!scanner) { - return; +double CSVGlobalState::GetProgress(const ReadCSVData &bind_data_p) const { + lock_guard parallel_lock(main_mutex); + idx_t total_files = bind_data.files.size(); + // get the progress WITHIN the current file + double percentage = 0; + if (file_scans.front()->file_size == 0) { + percentage = 1.0; + } else { + // for compressed files, read bytes may greater than files size. + for (auto &file : file_scans) { + double file_progress; + if (!file->buffer_manager) { + // We are done with this file, so it's 100% + file_progress = 1.0; + } else if (file->buffer_manager->file_handle->compression_type == FileCompressionType::GZIP || + file->buffer_manager->file_handle->compression_type == FileCompressionType::ZSTD) { + // This file is not done, and is a compressed file + file_progress = file->buffer_manager->file_handle->GetProgress(); + } else { + file_progress = static_cast(file->bytes_read); + } + // This file is an uncompressed file, so we use the more price bytes_read from the scanner + percentage += (static_cast(1) / static_cast(total_files)) * + std::min(1.0, file_progress / static_cast(file->file_size)); + } } - // We have to insert information for validation - auto previous_file = scanner->csv_file_scan; - previous_file->validator.Insert(scanner->scanner_idx, scanner->GetValidationLine()); - scanner.reset(); - FinishTask(*previous_file); + return percentage * 100; } -unique_ptr CSVGlobalState::Next(shared_ptr ¤t_file_ptr) { - auto ¤t_file = *current_file_ptr; - if (!initialized) { - // initialize the boundary for this file - current_boundary = current_file.start_iterator; - current_boundary.SetCurrentBoundaryToPosition(single_threaded, current_file.options); - if (current_boundary.done && context.client_data->debug_set_max_line_length) { - context.client_data->debug_max_line_length = - MaxValue(context.client_data->debug_max_line_length, current_boundary.pos.buffer_pos); - } - current_buffer_in_use = - make_shared_ptr(*current_file.buffer_manager, current_boundary.GetBufferIdx()); - initialized = true; - } else { - // produce the next boundary for this file - if (current_boundary.done || !current_boundary.Next(*current_file.buffer_manager, current_file.options)) { - // finished processing this file - return - return nullptr; +unique_ptr CSVGlobalState::Next(optional_ptr previous_scanner) { + if (previous_scanner) { + // We have to insert information for validation + lock_guard parallel_lock(main_mutex); + validator.Insert(previous_scanner->csv_file_scan->file_idx, previous_scanner->scanner_idx, + previous_scanner->GetValidationLine()); + } + if (single_threaded) { + { + lock_guard parallel_lock(main_mutex); + if (previous_scanner) { + // Cleanup previous scanner. + previous_scanner->buffer_tracker.reset(); + current_buffer_in_use.reset(); + previous_scanner->csv_file_scan->Finish(); + } } + idx_t cur_idx; + bool empty_file = false; + do { + { + lock_guard parallel_lock(main_mutex); + cur_idx = last_file_idx++; + if (cur_idx >= bind_data.files.size()) { + // No more files to scan + return nullptr; + } + if (cur_idx == 0) { + D_ASSERT(!previous_scanner); + auto current_file = file_scans.front(); + return make_uniq(scanner_idx++, current_file->buffer_manager, + current_file->state_machine, current_file->error_handler, + current_file, false, current_boundary); + } + } + auto file_scan = make_shared_ptr(context, bind_data.files[cur_idx], bind_data.options, cur_idx, + bind_data, column_ids, file_schema, true); + empty_file = file_scan->file_size == 0; + + if (!empty_file) { + lock_guard parallel_lock(main_mutex); + file_scans.emplace_back(std::move(file_scan)); + auto current_file = file_scans.back(); + current_boundary = current_file->start_iterator; + current_boundary.SetCurrentBoundaryToPosition(single_threaded, bind_data.options); + current_buffer_in_use = make_shared_ptr(*file_scans.back()->buffer_manager, + current_boundary.GetBufferIdx()); + + return make_uniq(scanner_idx++, current_file->buffer_manager, + current_file->state_machine, current_file->error_handler, + current_file, false, current_boundary); + } + } while (empty_file); + } + lock_guard parallel_lock(main_mutex); + if (finished) { + return nullptr; } - // create the scanner for this file if (current_buffer_in_use->buffer_idx != current_boundary.GetBufferIdx()) { current_buffer_in_use = - make_shared_ptr(*current_file.buffer_manager, current_boundary.GetBufferIdx()); + make_shared_ptr(*file_scans.back()->buffer_manager, current_boundary.GetBufferIdx()); } - ++current_file.started_tasks; // We first create the scanner for the current boundary + auto ¤t_file = *file_scans.back(); auto csv_scanner = make_uniq(scanner_idx++, current_file.buffer_manager, current_file.state_machine, - current_file.error_handler, current_file_ptr, false, current_boundary); + current_file.error_handler, file_scans.back(), false, current_boundary); + threads_per_file[csv_scanner->csv_file_scan->file_idx]++; + if (previous_scanner) { + threads_per_file[previous_scanner->csv_file_scan->file_idx]--; + if (threads_per_file[previous_scanner->csv_file_scan->file_idx] == 0) { + previous_scanner->buffer_tracker.reset(); + previous_scanner->csv_file_scan->Finish(); + } + } csv_scanner->buffer_tracker = current_buffer_in_use; + + // We then produce the next boundary + if (!current_boundary.Next(*current_file.buffer_manager, bind_data.options)) { + // This means we are done scanning the current file + do { + auto current_file_idx = file_scans.back()->file_idx + 1; + if (current_file_idx < bind_data.files.size()) { + // If we have a next file we have to construct the file scan for that + file_scans.emplace_back(make_shared_ptr(context, bind_data.files[current_file_idx], + bind_data.options, current_file_idx, bind_data, + column_ids, file_schema, false)); + // And re-start the boundary-iterator + current_boundary = file_scans.back()->start_iterator; + current_boundary.SetCurrentBoundaryToPosition(single_threaded, bind_data.options); + current_buffer_in_use = make_shared_ptr(*file_scans.back()->buffer_manager, + current_boundary.GetBufferIdx()); + } else { + // If not we are done with this CSV Scanning + finished = true; + break; + } + } while (current_boundary.done); + } // We initialize the scan return csv_scanner; } -void CSVGlobalState::FinishLaunchingTasks(CSVFileScan &file) { - initialized = false; - current_buffer_in_use.reset(); - // we are finished launching tasks for this file - // finish a task to indicate we can begin cleanup once all scans are done - FinishTask(file); -} - -void CSVGlobalState::FinishFile(CSVFileScan &scan) { - if (current_buffer_in_use && RefersToSameObject(current_buffer_in_use->buffer_manager, *scan.buffer_manager)) { - current_buffer_in_use.reset(); +idx_t CSVGlobalState::MaxThreads() const { + // We initialize max one thread per our set bytes per thread limit + if (single_threaded || !file_scans.front()->on_disk_file) { + return system_threads; } - scan.Finish(); - auto &csv_data = bind_data.bind_data->Cast(); - const bool ignore_or_store_errors = - csv_data.options.ignore_errors.GetValue() || csv_data.options.store_rejects.GetValue(); - if (!single_threaded && !ignore_or_store_errors) { - // If we are running multithreaded and not ignoring errors, we must run the validator - scan.validator.Verify(); + const idx_t bytes_per_thread = CSVIterator::BytesPerThread(file_scans.front()->options); + const idx_t total_threads = file_scans.front()->file_size / bytes_per_thread + 1; + if (total_threads < system_threads) { + return total_threads; } - scan.error_handler->ErrorIfAny(); - FillRejectsTable(scan); - if (context.client_data->debug_set_max_line_length) { - context.client_data->debug_max_line_length = - MaxValue(context.client_data->debug_max_line_length, scan.error_handler->GetMaxLineLength()); + return system_threads; +} + +void CSVGlobalState::DecrementThread() { + lock_guard parallel_lock(main_mutex); + D_ASSERT(running_threads > 0); + running_threads--; + if (running_threads == 0) { + const bool ignore_or_store_errors = + bind_data.options.ignore_errors.GetValue() || bind_data.options.store_rejects.GetValue(); + if (!single_threaded && !ignore_or_store_errors) { + // If we are running multithreaded and not ignoring errors, we must run the validator + validator.Verify(); + } + for (const auto &file : file_scans) { + file->error_handler->ErrorIfNeeded(); + } + FillRejectsTable(); + if (context.client_data->debug_set_max_line_length) { + context.client_data->debug_max_line_length = file_scans[0]->error_handler->GetMaxLineLength(); + } } } @@ -114,7 +226,7 @@ void FillScanErrorTable(InternalAppender &scan_appender, idx_t scan_idx, idx_t f // 2. File Idx scan_appender.Append(file_idx); // 3. File Path - scan_appender.Append(string_t(file.GetFileName())); + scan_appender.Append(string_t(file.file_path)); // 4. Delimiter scan_appender.Append(string_t(options.dialect_options.state_machine_options.delimiter.FormatValue())); // 5. Quote @@ -162,45 +274,38 @@ void FillScanErrorTable(InternalAppender &scan_appender, idx_t scan_idx, idx_t f if (options.user_defined_parameters.empty()) { scan_appender.Append(Value()); } else { - auto parameters = options.GetUserDefinedParameters(); - scan_appender.Append(string_t(parameters)); + scan_appender.Append(string_t(options.user_defined_parameters)); } // Finish the row to the rejects table scan_appender.EndRow(); } -void CSVGlobalState::FillRejectsTable(CSVFileScan &scan) { - auto &csv_data = bind_data.bind_data->Cast(); - auto &options = csv_data.options; - - if (!options.store_rejects.GetValue()) { - return; - } - auto limit = options.rejects_limit; - auto rejects = CSVRejectsTable::GetOrCreate(context, options.rejects_scan_name.GetValue(), - options.rejects_table_name.GetValue()); - lock_guard lock(rejects->write_lock); - auto &errors_table = rejects->GetErrorsTable(context); - auto &scans_table = rejects->GetScansTable(context); - InternalAppender errors_appender(context, errors_table); - InternalAppender scans_appender(context, scans_table); - idx_t scan_idx = context.transaction.GetActiveQuery(); - - // get the file indexes for the rejects table - // we store these so that they are deterministic (i.e. file index 0 always gets the lowest rejects index) - // otherwise parallelism can result in out-of-order file indexes - auto file_idx = scan.GetFileIndex(); - for (idx_t i = rejects_file_indexes.size(); i <= file_idx; i++) { - rejects_file_indexes.push_back(rejects->GetCurrentFileIndex(scan_idx)); - } - const idx_t rejects_file_idx = rejects_file_indexes[file_idx]; - scan.error_handler->FillRejectsTable(errors_appender, rejects_file_idx, scan_idx, scan, *rejects, bind_data, limit); - if (rejects->count != 0) { - rejects->count = 0; - FillScanErrorTable(scans_appender, scan_idx, rejects_file_idx, scan); - } - errors_appender.Close(); - scans_appender.Close(); +void CSVGlobalState::FillRejectsTable() const { + auto &options = bind_data.options; + + if (options.store_rejects.GetValue()) { + auto limit = options.rejects_limit; + auto rejects = CSVRejectsTable::GetOrCreate(context, options.rejects_scan_name.GetValue(), + options.rejects_table_name.GetValue()); + lock_guard lock(rejects->write_lock); + auto &errors_table = rejects->GetErrorsTable(context); + auto &scans_table = rejects->GetScansTable(context); + InternalAppender errors_appender(context, errors_table); + InternalAppender scans_appender(context, scans_table); + idx_t scan_idx = context.transaction.GetActiveQuery(); + for (auto &file : file_scans) { + const idx_t file_idx = rejects->GetCurrentFileIndex(scan_idx); + auto file_name = file->file_path; + file->error_handler->FillRejectsTable(errors_appender, file_idx, scan_idx, *file, *rejects, bind_data, + limit); + if (rejects->count != 0) { + rejects->count = 0; + FillScanErrorTable(scans_appender, scan_idx, file_idx, *file); + } + } + errors_appender.Close(); + scans_appender.Close(); + } } } // namespace duckdb diff --git a/src/duckdb/src/execution/operator/csv_scanner/util/csv_error.cpp b/src/duckdb/src/execution/operator/csv_scanner/util/csv_error.cpp index 9f09e1c10..d08c2b07f 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/util/csv_error.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/util/csv_error.cpp @@ -5,7 +5,6 @@ #include "duckdb/execution/operator/persistent/csv_rejects_table.hpp" #include "duckdb/execution/operator/csv_scanner/csv_file_scanner.hpp" #include "duckdb/main/appender.hpp" -#include "duckdb/common/multi_file/multi_file_function.hpp" #include namespace duckdb { @@ -81,18 +80,6 @@ void CSVErrorHandler::ErrorIfNeeded() { } } -void CSVErrorHandler::ErrorIfAny() { - lock_guard parallel_lock(main_mutex); - if (ignore_errors || errors.empty()) { - // Nothing to error - return; - } - if (!CanGetLine(errors[0].error_info.boundary_idx)) { - throw InternalException("Failed to get error information for boundary index"); - } - ThrowError(errors[0]); -} - void CSVErrorHandler::ErrorIfTypeExists(CSVErrorType error_type) { lock_guard parallel_lock(main_mutex); for (auto &error : errors) { @@ -173,8 +160,8 @@ string CSVErrorTypeToEnum(CSVErrorType type) { } void CSVErrorHandler::FillRejectsTable(InternalAppender &errors_appender, const idx_t file_idx, const idx_t scan_idx, - const CSVFileScan &file, CSVRejectsTable &rejects, - const MultiFileBindData &bind_data, const idx_t limit) { + const CSVFileScan &file, CSVRejectsTable &rejects, const ReadCSVData &bind_data, + const idx_t limit) { lock_guard parallel_lock(main_mutex); // We first insert the file into the file scans table for (auto &error : file.error_handler->errors) { @@ -220,15 +207,15 @@ void CSVErrorHandler::FillRejectsTable(InternalAppender &errors_appender, const errors_appender.Append(Value()); break; case CSVErrorType::TOO_FEW_COLUMNS: - if (col_idx + 1 < bind_data.names.size()) { - errors_appender.Append(string_t(bind_data.names[col_idx + 1])); + if (col_idx + 1 < bind_data.return_names.size()) { + errors_appender.Append(string_t(bind_data.return_names[col_idx + 1])); } else { errors_appender.Append(Value()); } break; default: - if (col_idx < bind_data.names.size()) { - errors_appender.Append(string_t(bind_data.names[col_idx])); + if (col_idx < bind_data.return_names.size()) { + errors_appender.Append(string_t(bind_data.return_names[col_idx])); } else { errors_appender.Append(Value()); } @@ -423,8 +410,7 @@ CSVError CSVError::HeaderSniffingError(const CSVReaderOptions &options, const ve return CSVError(error.str(), SNIFFING, {}); } -CSVError CSVError::SniffingError(const CSVReaderOptions &options, const string &search_space, idx_t max_columns_found, - SetColumns &set_columns) { +CSVError CSVError::SniffingError(const CSVReaderOptions &options, const string &search_space) { std::ostringstream error; // 1. Which file error << "Error when sniffing file \"" << options.file_path << "\"." << '\n'; @@ -434,25 +420,14 @@ CSVError CSVError::SniffingError(const CSVReaderOptions &options, const string & // 2. What was the search space? error << "The search space used was:" << '\n'; error << search_space; - error << "Encoding: " << options.encoding << '\n'; // 3. Suggest how to fix it! error << "Possible fixes:" << '\n'; - // 3.0 Inform the user about the strict_mode // 3.1 Inform the reader of the dialect if (options.dialect_options.state_machine_options.strict_mode.GetValue()) { error << "* Disable the parser's strict mode (strict_mode=false) to allow reading rows that do not comply with " "the CSV standard." << '\n'; } - if (options.columns_set) { - // If columns are set, suggest to either unset it or validate that it matches the schema - error << "* Columns are set as: \"" << set_columns.ToString() << "\", and they contain: " << set_columns.Size() - << " columns. It does not match the number of columns found by the sniffer: " << max_columns_found << "." - << " Verify the columns parameter is correctly set." << '\n'; - } - // 3.0.1 Inform the user about encoding - error << "* Make sure you are using the correct file encoding. If not, set it (e.g., encoding = 'utf-16')." << '\n'; - // 3.1 Inform the reader of the dialect // delimiter if (!options.dialect_options.state_machine_options.delimiter.IsSetByUser()) { error << "* Set delimiter (e.g., delim=\',\')" << '\n'; diff --git a/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp b/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp index a6f12977f..3371b0710 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp @@ -3,7 +3,7 @@ #include "duckdb/common/vector_size.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/common/enum_util.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/set.hpp" namespace duckdb { @@ -197,29 +197,25 @@ bool CSVReaderOptions::IgnoreErrors() const { return ignore_errors.GetValue() && !store_rejects.GetValue(); } -CSVOption CSVReaderOptions::GetSingleByteDelimiter() const { - auto &delim = dialect_options.state_machine_options.delimiter; - return CSVOption(delim.GetValue()[0], delim.IsSetByUser()); +char CSVReaderOptions::GetSingleByteDelimiter() const { + return dialect_options.state_machine_options.delimiter.GetValue()[0]; } -CSVOption CSVReaderOptions::GetMultiByteDelimiter() const { - return dialect_options.state_machine_options.delimiter; +string CSVReaderOptions::GetMultiByteDelimiter() const { + return dialect_options.state_machine_options.delimiter.GetValue(); } void CSVReaderOptions::SetDateFormat(LogicalTypeId type, const string &format, bool read_format) { string error; - const string auto_format = StringUtil::Lower(format); - if (auto_format != "auto") { - if (read_format) { - StrpTimeFormat strpformat; - error = StrTimeFormat::ParseFormatSpecifier(format, strpformat); - dialect_options.date_format[type].Set(strpformat); - } else { - write_date_format[type] = Value(format); - } - if (!error.empty()) { - throw InvalidInputException("Could not parse DATEFORMAT: %s", error.c_str()); - } + if (read_format) { + StrpTimeFormat strpformat; + error = StrTimeFormat::ParseFormatSpecifier(format, strpformat); + dialect_options.date_format[type].Set(strpformat); + } else { + write_date_format[type] = Value(format); + } + if (!error.empty()) { + throw InvalidInputException("Could not parse DATEFORMAT: %s", error.c_str()); } } @@ -511,13 +507,13 @@ static Value StringVectorToValue(const vector &vec) { static uint8_t GetCandidateSpecificity(const LogicalType &candidate_type) { //! Const ht with accepted auto_types and their weights in specificity const duckdb::unordered_map auto_type_candidates_specificity { - {static_cast(LogicalTypeId::VARCHAR), 0}, {static_cast(LogicalTypeId::DOUBLE), 1}, - {static_cast(LogicalTypeId::FLOAT), 2}, {static_cast(LogicalTypeId::DECIMAL), 3}, - {static_cast(LogicalTypeId::BIGINT), 4}, {static_cast(LogicalTypeId::INTEGER), 5}, - {static_cast(LogicalTypeId::SMALLINT), 6}, {static_cast(LogicalTypeId::TINYINT), 7}, - {static_cast(LogicalTypeId::TIMESTAMP_TZ), 8}, {static_cast(LogicalTypeId::TIMESTAMP), 9}, - {static_cast(LogicalTypeId::DATE), 10}, {static_cast(LogicalTypeId::TIME), 11}, - {static_cast(LogicalTypeId::BOOLEAN), 12}, {static_cast(LogicalTypeId::SQLNULL), 13}}; + {static_cast(LogicalTypeId::VARCHAR), 0}, {static_cast(LogicalTypeId::DOUBLE), 1}, + {static_cast(LogicalTypeId::FLOAT), 2}, {static_cast(LogicalTypeId::DECIMAL), 3}, + {static_cast(LogicalTypeId::BIGINT), 4}, {static_cast(LogicalTypeId::INTEGER), 5}, + {static_cast(LogicalTypeId::SMALLINT), 6}, {static_cast(LogicalTypeId::TINYINT), 7}, + {static_cast(LogicalTypeId::TIMESTAMP), 8}, {static_cast(LogicalTypeId::DATE), 9}, + {static_cast(LogicalTypeId::TIME), 10}, {static_cast(LogicalTypeId::BOOLEAN), 11}, + {static_cast(LogicalTypeId::SQLNULL), 12}}; auto id = static_cast(candidate_type.id()); auto it = auto_type_candidates_specificity.find(id); @@ -537,7 +533,7 @@ bool StoreUserDefinedParameter(const string &option) { return true; } -void CSVReaderOptions::Verify(MultiFileOptions &file_options) { +void CSVReaderOptions::Verify() { if (rejects_table_name.IsSetByUser() && !store_rejects.GetValue() && store_rejects.IsSetByUser()) { throw BinderException("REJECTS_TABLE option is only supported when store_rejects is not manually set to false"); } @@ -577,167 +573,157 @@ void CSVReaderOptions::Verify(MultiFileOptions &file_options) { } } -bool GetBooleanValue(const string &loption, const Value &val) { - if (val.IsNull()) { - throw BinderException("read_csv %s cannot be NULL", loption); +bool GetBooleanValue(const pair &option) { + if (option.second.IsNull()) { + throw BinderException("read_csv %s cannot be NULL", option.first); } - return BooleanValue::Get(val); + return BooleanValue::Get(option.second); } -string CSVReaderOptions::GetUserDefinedParameters() const { - string result; - for (auto &udf_parameter : user_defined_parameters) { - if (!result.empty()) { - result += ", "; - } - result += udf_parameter.first + "=" + udf_parameter.second; - } - return result; -} - -void CSVReaderOptions::FromNamedParameters(const named_parameter_map_t &in, ClientContext &context, - MultiFileOptions &file_options) { +void CSVReaderOptions::FromNamedParameters(const named_parameter_map_t &in, ClientContext &context) { + map ordered_user_defined_parameters; for (auto &kv : in) { - auto loption = StringUtil::Lower(kv.first); - if (MultiFileReader().ParseOption(loption, kv.second, file_options, context)) { + if (MultiFileReader().ParseOption(kv.first, kv.second, file_options, context)) { continue; } - ParseOption(context, kv.first, kv.second); - } -} - -void CSVReaderOptions::ParseOption(ClientContext &context, const string &key, const Value &val) { - auto loption = StringUtil::Lower(key); - // skip variables that are specific to auto-detection - if (StoreUserDefinedParameter(loption)) { - user_defined_parameters[loption] = val.ToSQLString(); - } - if (loption == "columns") { - if (!name_list.empty()) { - throw BinderException("read_csv column_names/names can only be supplied once"); - } - columns_set = true; - auto &child_type = val.type(); - if (child_type.id() != LogicalTypeId::STRUCT) { - throw BinderException("read_csv columns requires a struct as input"); - } - auto &struct_children = StructValue::GetChildren(val); - D_ASSERT(StructType::GetChildCount(child_type) == struct_children.size()); - for (idx_t i = 0; i < struct_children.size(); i++) { - auto &name = StructType::GetChildName(child_type, i); - auto &val = struct_children[i]; - name_list.push_back(name); - if (val.type().id() != LogicalTypeId::VARCHAR) { - throw BinderException("read_csv requires a type specification as string"); - } - sql_types_per_column[name] = i; - sql_type_list.emplace_back(TransformStringToLogicalType(StringValue::Get(val), context)); - } - if (name_list.empty()) { - throw BinderException("read_csv requires at least a single column as input!"); - } - } else if (loption == "auto_type_candidates") { - auto_type_candidates.clear(); - map candidate_types; - // We always have the extremes of Null and Varchar, so we can default to varchar if the - // sniffer is not able to confidently detect that column type - candidate_types[GetCandidateSpecificity(LogicalType::VARCHAR)] = LogicalType::VARCHAR; - candidate_types[GetCandidateSpecificity(LogicalType::SQLNULL)] = LogicalType::SQLNULL; - - auto &child_type = val.type(); - if (child_type.id() != LogicalTypeId::LIST) { - throw BinderException("read_csv auto_types requires a list as input"); - } - auto &list_children = ListValue::GetChildren(val); - if (list_children.empty()) { - throw BinderException("auto_type_candidates requires at least one type"); - } - for (auto &child : list_children) { - if (child.type().id() != LogicalTypeId::VARCHAR) { - throw BinderException("auto_type_candidates requires a type specification as string"); - } - auto candidate_type = TransformStringToLogicalType(StringValue::Get(child), context); - candidate_types[GetCandidateSpecificity(candidate_type)] = candidate_type; - } - for (auto &candidate_type : candidate_types) { - auto_type_candidates.emplace_back(candidate_type.second); - } - } else if (loption == "column_names" || loption == "names") { - unordered_set column_names; - if (!name_list.empty()) { - throw BinderException("read_csv column_names/names can only be supplied once"); - } - if (val.IsNull()) { - throw BinderException("read_csv %s cannot be NULL", key); - } - auto &children = ListValue::GetChildren(val); - for (auto &child : children) { - if (child.IsNull()) { - throw BinderException("read_csv %s parameter cannot have a NULL value", key); - } - name_list.push_back(StringValue::Get(child)); + auto loption = StringUtil::Lower(kv.first); + // skip variables that are specific to auto-detection + if (StoreUserDefinedParameter(loption)) { + ordered_user_defined_parameters[loption] = kv.second.ToSQLString(); } - for (auto &name : name_list) { - bool empty = true; - for (auto &c : name) { - if (!StringUtil::CharacterIsSpace(c)) { - empty = false; - break; - } - } - if (empty) { - throw BinderException("read_csv %s cannot have empty (or all whitespace) value", key); + if (loption == "columns") { + if (!name_list.empty()) { + throw BinderException("read_csv column_names/names can only be supplied once"); } - if (column_names.find(name) != column_names.end()) { - throw BinderException("read_csv %s must have unique values. \"%s\" is repeated.", key, name); + columns_set = true; + auto &child_type = kv.second.type(); + if (child_type.id() != LogicalTypeId::STRUCT) { + throw BinderException("read_csv columns requires a struct as input"); } - column_names.insert(name); - } - } else if (loption == "column_types" || loption == "types" || loption == "dtypes") { - auto &child_type = val.type(); - if (child_type.id() != LogicalTypeId::STRUCT && child_type.id() != LogicalTypeId::LIST) { - throw BinderException("read_csv %s requires a struct or list as input", key); - } - if (!sql_type_list.empty()) { - throw BinderException("read_csv column_types/types/dtypes can only be supplied once"); - } - vector sql_type_names; - if (child_type.id() == LogicalTypeId::STRUCT) { - auto &struct_children = StructValue::GetChildren(val); + auto &struct_children = StructValue::GetChildren(kv.second); D_ASSERT(StructType::GetChildCount(child_type) == struct_children.size()); for (idx_t i = 0; i < struct_children.size(); i++) { auto &name = StructType::GetChildName(child_type, i); auto &val = struct_children[i]; + name_list.push_back(name); if (val.type().id() != LogicalTypeId::VARCHAR) { - throw BinderException("read_csv %s requires a type specification as string", key); + throw BinderException("read_csv requires a type specification as string"); } - sql_type_names.push_back(StringValue::Get(val)); sql_types_per_column[name] = i; + sql_type_list.emplace_back(TransformStringToLogicalType(StringValue::Get(val), context)); } - } else { - auto &list_child = ListType::GetChildType(child_type); - if (list_child.id() != LogicalTypeId::VARCHAR) { - throw BinderException("read_csv %s requires a list of types (varchar) as input", key); + if (name_list.empty()) { + throw BinderException("read_csv requires at least a single column as input!"); + } + } else if (loption == "auto_type_candidates") { + auto_type_candidates.clear(); + map candidate_types; + // We always have the extremes of Null and Varchar, so we can default to varchar if the + // sniffer is not able to confidently detect that column type + candidate_types[GetCandidateSpecificity(LogicalType::VARCHAR)] = LogicalType::VARCHAR; + candidate_types[GetCandidateSpecificity(LogicalType::SQLNULL)] = LogicalType::SQLNULL; + + auto &child_type = kv.second.type(); + if (child_type.id() != LogicalTypeId::LIST) { + throw BinderException("read_csv auto_types requires a list as input"); } - auto &children = ListValue::GetChildren(val); + auto &list_children = ListValue::GetChildren(kv.second); + if (list_children.empty()) { + throw BinderException("auto_type_candidates requires at least one type"); + } + for (auto &child : list_children) { + if (child.type().id() != LogicalTypeId::VARCHAR) { + throw BinderException("auto_type_candidates requires a type specification as string"); + } + auto candidate_type = TransformStringToLogicalType(StringValue::Get(child), context); + candidate_types[GetCandidateSpecificity(candidate_type)] = candidate_type; + } + for (auto &candidate_type : candidate_types) { + auto_type_candidates.emplace_back(candidate_type.second); + } + } else if (loption == "column_names" || loption == "names") { + unordered_set column_names; + if (!name_list.empty()) { + throw BinderException("read_csv column_names/names can only be supplied once"); + } + if (kv.second.IsNull()) { + throw BinderException("read_csv %s cannot be NULL", kv.first); + } + auto &children = ListValue::GetChildren(kv.second); for (auto &child : children) { - sql_type_names.push_back(StringValue::Get(child)); + if (child.IsNull()) { + throw BinderException("read_csv %s parameter cannot have a NULL value", kv.first); + } + name_list.push_back(StringValue::Get(child)); } - } - sql_type_list.reserve(sql_type_names.size()); - for (auto &sql_type : sql_type_names) { - auto def_type = TransformStringToLogicalType(sql_type, context); - if (def_type.id() == LogicalTypeId::USER) { - throw BinderException("Unrecognized type \"%s\" for read_csv %s definition", sql_type, key); + for (auto &name : name_list) { + bool empty = true; + for (auto &c : name) { + if (!StringUtil::CharacterIsSpace(c)) { + empty = false; + break; + } + } + if (empty) { + throw BinderException("read_csv %s cannot have empty (or all whitespace) value", kv.first); + } + if (column_names.find(name) != column_names.end()) { + throw BinderException("read_csv %s must have unique values. \"%s\" is repeated.", kv.first, name); + } + column_names.insert(name); + } + } else if (loption == "column_types" || loption == "types" || loption == "dtypes") { + auto &child_type = kv.second.type(); + if (child_type.id() != LogicalTypeId::STRUCT && child_type.id() != LogicalTypeId::LIST) { + throw BinderException("read_csv %s requires a struct or list as input", kv.first); } - sql_type_list.push_back(std::move(def_type)); + if (!sql_type_list.empty()) { + throw BinderException("read_csv column_types/types/dtypes can only be supplied once"); + } + vector sql_type_names; + if (child_type.id() == LogicalTypeId::STRUCT) { + auto &struct_children = StructValue::GetChildren(kv.second); + D_ASSERT(StructType::GetChildCount(child_type) == struct_children.size()); + for (idx_t i = 0; i < struct_children.size(); i++) { + auto &name = StructType::GetChildName(child_type, i); + auto &val = struct_children[i]; + if (val.type().id() != LogicalTypeId::VARCHAR) { + throw BinderException("read_csv %s requires a type specification as string", kv.first); + } + sql_type_names.push_back(StringValue::Get(val)); + sql_types_per_column[name] = i; + } + } else { + auto &list_child = ListType::GetChildType(child_type); + if (list_child.id() != LogicalTypeId::VARCHAR) { + throw BinderException("read_csv %s requires a list of types (varchar) as input", kv.first); + } + auto &children = ListValue::GetChildren(kv.second); + for (auto &child : children) { + sql_type_names.push_back(StringValue::Get(child)); + } + } + sql_type_list.reserve(sql_type_names.size()); + for (auto &sql_type : sql_type_names) { + auto def_type = TransformStringToLogicalType(sql_type, context); + if (def_type.id() == LogicalTypeId::USER) { + throw BinderException("Unrecognized type \"%s\" for read_csv %s definition", sql_type, kv.first); + } + sql_type_list.push_back(std::move(def_type)); + } + } else if (loption == "all_varchar") { + all_varchar = GetBooleanValue(kv); + } else if (loption == "normalize_names") { + normalize_names = GetBooleanValue(kv); + } else { + SetReadOption(loption, kv.second, name_list); } - } else if (loption == "all_varchar") { - all_varchar = GetBooleanValue(loption, val); - } else if (loption == "normalize_names") { - normalize_names = GetBooleanValue(loption, val); - } else { - SetReadOption(loption, val, name_list); + } + for (auto &udf_parameter : ordered_user_defined_parameters) { + user_defined_parameters += udf_parameter.first + "=" + udf_parameter.second + ", "; + } + if (user_defined_parameters.size() >= 2) { + user_defined_parameters.erase(user_defined_parameters.size() - 2); } } //! This function is used to remember options set by the sniffer, for use in ReadCSVRelation diff --git a/src/duckdb/src/execution/operator/csv_scanner/util/csv_validator.cpp b/src/duckdb/src/execution/operator/csv_scanner/util/csv_validator.cpp index 09c2ea4c2..1b8d3f348 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/util/csv_validator.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/util/csv_validator.cpp @@ -43,16 +43,21 @@ void ThreadLines::Verify() const { } } -void CSVValidator::Insert(idx_t thread_idx, ValidatorLine line_info) { - thread_lines.Insert(thread_idx, line_info); +void CSVValidator::Insert(idx_t file_idx, idx_t thread_idx, ValidatorLine line_info) { + if (per_file_thread_lines.size() <= file_idx) { + per_file_thread_lines.resize(file_idx + 1); + } + per_file_thread_lines[file_idx].Insert(thread_idx, line_info); } void CSVValidator::Verify() const { - thread_lines.Verify(); + for (auto &file : per_file_thread_lines) { + file.Verify(); + } } -string CSVValidator::Print() const { - return thread_lines.Print(); +string CSVValidator::Print(idx_t file_idx) const { + return per_file_thread_lines[file_idx].Print(); } } // namespace duckdb diff --git a/src/duckdb/src/execution/operator/helper/physical_create_secret.cpp b/src/duckdb/src/execution/operator/helper/physical_create_secret.cpp index ac06b3950..3a1dbe8b6 100644 --- a/src/duckdb/src/execution/operator/helper/physical_create_secret.cpp +++ b/src/duckdb/src/execution/operator/helper/physical_create_secret.cpp @@ -10,7 +10,7 @@ SourceResultType PhysicalCreateSecret::GetData(ExecutionContext &context, DataCh auto &client = context.client; auto &secret_manager = SecretManager::Get(client); - secret_manager.CreateSecret(client, create_input); + secret_manager.CreateSecret(client, info); chunk.SetValue(0, 0, true); chunk.SetCardinality(1); diff --git a/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp b/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp index c2212e499..5dcb356e7 100644 --- a/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp +++ b/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp @@ -15,20 +15,19 @@ namespace duckdb { PhysicalResultCollector::PhysicalResultCollector(PreparedStatementData &data) : PhysicalOperator(PhysicalOperatorType::RESULT_COLLECTOR, {LogicalType::BOOLEAN}, 0), - statement_type(data.statement_type), properties(data.properties), plan(data.physical_plan->Root()), - names(data.names) { + statement_type(data.statement_type), properties(data.properties), plan(*data.plan), names(data.names) { this->types = data.types; } unique_ptr PhysicalResultCollector::GetResultCollector(ClientContext &context, PreparedStatementData &data) { - if (!PhysicalPlanGenerator::PreserveInsertionOrder(context, data.physical_plan->Root())) { + if (!PhysicalPlanGenerator::PreserveInsertionOrder(context, *data.plan)) { // the plan is not order preserving, so we just use the parallel materialized collector if (data.is_streaming) { return make_uniq_base(data, true); } return make_uniq_base(data, true); - } else if (!PhysicalPlanGenerator::UseBatchIndex(context, data.physical_plan->Root())) { + } else if (!PhysicalPlanGenerator::UseBatchIndex(context, *data.plan)) { // the plan is order preserving, but we cannot use the batch index: use a single-threaded result collector if (data.is_streaming) { return make_uniq_base(data, false); diff --git a/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp b/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp index a80e6081d..345745df8 100644 --- a/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +++ b/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp @@ -94,9 +94,6 @@ SinkFinalizeType PhysicalVacuum::Finalize(Pipeline &pipeline, Event &event, Clie for (idx_t col_idx = 0; col_idx < sink.column_distinct_stats.size(); col_idx++) { tbl->GetStorage().SetDistinct(column_id_map.at(col_idx), std::move(sink.column_distinct_stats[col_idx])); } - if (tbl) { - tbl->GetStorage().VacuumIndexes(); - } return SinkFinalizeType::READY; } diff --git a/src/duckdb/src/execution/operator/helper/physical_verify_vector.cpp b/src/duckdb/src/execution/operator/helper/physical_verify_vector.cpp index 2186e3173..ea19d7ca9 100644 --- a/src/duckdb/src/execution/operator/helper/physical_verify_vector.cpp +++ b/src/duckdb/src/execution/operator/helper/physical_verify_vector.cpp @@ -5,10 +5,9 @@ namespace duckdb { -PhysicalVerifyVector::PhysicalVerifyVector(PhysicalOperator &child, DebugVectorVerification verification) - : PhysicalOperator(PhysicalOperatorType::VERIFY_VECTOR, child.GetTypes(), child.estimated_cardinality), - verification(verification) { - children.push_back(child); +PhysicalVerifyVector::PhysicalVerifyVector(unique_ptr child) + : PhysicalOperator(PhysicalOperatorType::VERIFY_VECTOR, child->types, child->estimated_cardinality) { + children.push_back(std::move(child)); } class VerifyVectorState : public OperatorState { @@ -217,18 +216,19 @@ unique_ptr PhysicalVerifyVector::GetOperatorState(ExecutionContex OperatorResultType PhysicalVerifyVector::Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk, GlobalOperatorState &gstate, OperatorState &state) const { - switch (verification) { - case DebugVectorVerification::DICTIONARY_OPERATOR: - return VerifyEmitDictionaryVectors(input, chunk, state); - case DebugVectorVerification::CONSTANT_OPERATOR: - return VerifyEmitConstantVectors(input, chunk, state); - case DebugVectorVerification::SEQUENCE_OPERATOR: - return VerifyEmitSequenceVector(input, chunk, state); - case DebugVectorVerification::NESTED_SHUFFLE: - return VerifyEmitNestedShuffleVector(input, chunk, state); - default: - throw InternalException("PhysicalVerifyVector created but no verification code present"); - } +#ifdef DUCKDB_VERIFY_CONSTANT_OPERATOR + return VerifyEmitConstantVectors(input, chunk, state); +#endif +#ifdef DUCKDB_VERIFY_DICTIONARY_OPERATOR + return VerifyEmitDictionaryVectors(input, chunk, state); +#endif +#ifdef DUCKDB_VERIFY_SEQUENCE_OPERATOR + return VerifyEmitSequenceVector(input, chunk, state); +#endif +#ifdef DUCKDB_VERIFY_NESTED_SHUFFLE + return VerifyEmitNestedShuffleVector(input, chunk, state); +#endif + throw InternalException("PhysicalVerifyVector created but no verification code present"); } } // namespace duckdb diff --git a/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp b/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp index a48eaee4f..123d94161 100644 --- a/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp +++ b/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp @@ -76,7 +76,7 @@ bool PerfectHashJoinExecutor::CanDoPerfectHashJoin(const PhysicalHashJoin &op, c } // We bail out if there are nested types on the RHS - for (auto &type : op.children[1].get().GetTypes()) { + for (auto &type : op.children[1]->types) { switch (type.InternalType()) { case PhysicalType::STRUCT: case PhysicalType::LIST: @@ -178,7 +178,7 @@ bool PerfectHashJoinExecutor::FullScanHashTable(LogicalType &key_type) { for (idx_t i = 0; i < join.rhs_output_columns.col_types.size(); i++) { auto &vector = perfect_hash_table[i]; const auto output_col_idx = ht.output_columns[i]; - D_ASSERT(vector.GetType() == ht.layout_ptr->GetTypes()[output_col_idx]); + D_ASSERT(vector.GetType() == ht.layout.GetTypes()[output_col_idx]); if (build_size > STANDARD_VECTOR_SIZE) { auto &col_mask = FlatVector::Validity(vector); col_mask.Initialize(build_size); @@ -301,7 +301,7 @@ OperatorResultType PerfectHashJoinExecutor::ProbePerfectHashTable(ExecutionConte // on the build side, we need to fetch the data and build dictionary vectors with the sel_vec for (idx_t i = 0; i < join.rhs_output_columns.col_types.size(); i++) { auto &result_vector = result.data[lhs_output_columns.ColumnCount() + i]; - D_ASSERT(result_vector.GetType() == ht.layout_ptr->GetTypes()[ht.output_columns[i]]); + D_ASSERT(result_vector.GetType() == ht.layout.GetTypes()[ht.output_columns[i]]); auto &build_vec = perfect_hash_table[i]; result_vector.Reference(build_vec); result_vector.Slice(state.build_sel_vec, probe_sel_count); diff --git a/src/duckdb/src/execution/operator/join/physical_asof_join.cpp b/src/duckdb/src/execution/operator/join/physical_asof_join.cpp index f78872d00..91dda01e6 100644 --- a/src/duckdb/src/execution/operator/join/physical_asof_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_asof_join.cpp @@ -1,6 +1,9 @@ #include "duckdb/execution/operator/join/physical_asof_join.hpp" +#include "duckdb/common/fast_mem.hpp" +#include "duckdb/common/operator/comparison_operators.hpp" #include "duckdb/common/row_operations/row_operations.hpp" +#include "duckdb/common/sort/comparators.hpp" #include "duckdb/common/sort/partition_state.hpp" #include "duckdb/common/sort/sort.hpp" #include "duckdb/common/vector_operations/vector_operations.hpp" @@ -10,9 +13,12 @@ #include "duckdb/parallel/event.hpp" #include "duckdb/parallel/thread_context.hpp" +#include + namespace duckdb { -PhysicalAsOfJoin::PhysicalAsOfJoin(LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right) +PhysicalAsOfJoin::PhysicalAsOfJoin(LogicalComparisonJoin &op, unique_ptr left, + unique_ptr right) : PhysicalComparisonJoin(op, PhysicalOperatorType::ASOF_JOIN, std::move(op.conditions), op.join_type, op.estimated_cardinality), comparison_type(ExpressionType::INVALID) { @@ -54,13 +60,13 @@ PhysicalAsOfJoin::PhysicalAsOfJoin(LogicalComparisonJoin &op, PhysicalOperator & D_ASSERT(!lhs_orders.empty()); D_ASSERT(!rhs_orders.empty()); - children.push_back(left); - children.push_back(right); + children.push_back(std::move(left)); + children.push_back(std::move(right)); // Fill out the right projection map. right_projection_map = op.right_projection_map; if (right_projection_map.empty()) { - const auto right_count = children[1].get().GetTypes().size(); + const auto right_count = children[1]->types.size(); right_projection_map.reserve(right_count); for (column_t i = 0; i < right_count; ++i) { right_projection_map.emplace_back(i); @@ -74,8 +80,7 @@ PhysicalAsOfJoin::PhysicalAsOfJoin(LogicalComparisonJoin &op, PhysicalOperator & class AsOfGlobalSinkState : public GlobalSinkState { public: AsOfGlobalSinkState(ClientContext &context, const PhysicalAsOfJoin &op) - : rhs_sink(context, op.rhs_partitions, op.rhs_orders, op.children[1].get().GetTypes(), {}, - op.estimated_cardinality), + : rhs_sink(context, op.rhs_partitions, op.rhs_orders, op.children[1]->types, {}, op.estimated_cardinality), is_outer(IsRightOuterJoin(op.join_type)), has_null(false) { } @@ -153,8 +158,8 @@ SinkFinalizeType PhysicalAsOfJoin::Finalize(Pipeline &pipeline, Event &event, Cl // The data is all in so we can initialise the left partitioning. const vector> partitions_stats; - gstate.lhs_sink = make_uniq(context, lhs_partitions, lhs_orders, - children[0].get().GetTypes(), partitions_stats, 0U); + gstate.lhs_sink = make_uniq(context, lhs_partitions, lhs_orders, children[0]->types, + partitions_stats, 0U); gstate.lhs_sink->SyncPartitioning(gstate.rhs_sink); // Find the first group to sort @@ -202,7 +207,7 @@ class AsOfLocalState : public CachingOperatorState { lhs_executor.AddExpression(*cond.left); } - lhs_payload.Initialize(allocator, op.children[0].get().GetTypes()); + lhs_payload.Initialize(allocator, op.children[0]->types); lhs_sel.Initialize(); left_outer.Initialize(STANDARD_VECTOR_SIZE); @@ -343,7 +348,7 @@ class AsOfProbeBuffer { } void BeginLeftScan(hash_t scan_bin); bool NextLeft(); - void EndLeftScan(); + void EndScan(); // resolve joins that output max N elements (SEMI, ANTI, MARK) void ResolveSimpleJoin(ExecutionContext &context, DataChunk &chunk); @@ -370,7 +375,6 @@ class AsOfProbeBuffer { unique_ptr left_itr; unique_ptr lhs_scanner; DataChunk lhs_payload; - idx_t left_group = 0; // RHS scanning optional_ptr right_hash; @@ -378,7 +382,6 @@ class AsOfProbeBuffer { unique_ptr right_itr; unique_ptr rhs_scanner; DataChunk rhs_payload; - idx_t right_group = 0; idx_t lhs_match_count; bool fetch_next_left; @@ -395,8 +398,8 @@ AsOfProbeBuffer::AsOfProbeBuffer(ClientContext &context, const PhysicalAsOfJoin partition_stats); // We sort the row numbers of the incoming block, not the rows - lhs_payload.Initialize(allocator, op.children[0].get().GetTypes()); - rhs_payload.Initialize(allocator, op.children[1].get().GetTypes()); + lhs_payload.Initialize(allocator, op.children[0]->types); + rhs_payload.Initialize(allocator, op.children[1]->types); lhs_sel.Initialize(); left_outer.Initialize(STANDARD_VECTOR_SIZE); @@ -404,18 +407,8 @@ AsOfProbeBuffer::AsOfProbeBuffer(ClientContext &context, const PhysicalAsOfJoin void AsOfProbeBuffer::BeginLeftScan(hash_t scan_bin) { auto &gsink = op.sink_state->Cast(); - auto &lhs_sink = *gsink.lhs_sink; - left_group = lhs_sink.bin_groups[scan_bin]; - - // Always set right_group too for memory management - auto &rhs_sink = gsink.rhs_sink; - if (scan_bin < rhs_sink.bin_groups.size()) { - right_group = rhs_sink.bin_groups[scan_bin]; - } else { - right_group = rhs_sink.bin_groups.size(); - } - + const auto left_group = lhs_sink.bin_groups[scan_bin]; if (left_group >= lhs_sink.bin_groups.size()) { return; } @@ -448,6 +441,8 @@ void AsOfProbeBuffer::BeginLeftScan(hash_t scan_bin) { // We are only probing the corresponding right side bin, which may be empty // If they are empty, we leave the iterator as null so we can emit left matches + auto &rhs_sink = gsink.rhs_sink; + const auto right_group = rhs_sink.bin_groups[scan_bin]; if (right_group < rhs_sink.bin_groups.size()) { right_hash = rhs_sink.hash_groups[right_group].get(); right_outer = gsink.right_outers.data() + right_group; @@ -470,27 +465,15 @@ bool AsOfProbeBuffer::NextLeft() { return true; } -void AsOfProbeBuffer::EndLeftScan() { - auto &gsink = op.sink_state->Cast(); - +void AsOfProbeBuffer::EndScan() { right_hash = nullptr; right_itr.reset(); rhs_scanner.reset(); right_outer = nullptr; - auto &rhs_sink = gsink.rhs_sink; - if (!gsink.is_outer && right_group < rhs_sink.bin_groups.size()) { - rhs_sink.hash_groups[right_group].reset(); - } - left_hash = nullptr; left_itr.reset(); lhs_scanner.reset(); - - auto &lhs_sink = *gsink.lhs_sink; - if (left_group < lhs_sink.bin_groups.size()) { - lhs_sink.hash_groups[left_group].reset(); - } } void AsOfProbeBuffer::ResolveJoin(bool *found_match, idx_t *matches) { @@ -820,7 +803,7 @@ SourceResultType PhysicalAsOfJoin::GetData(ExecutionContext &context, DataChunk // Join the next partition continue; } else { - lsource.probe_buffer.EndLeftScan(); + lsource.probe_buffer.EndScan(); gsource.flushed++; } } @@ -873,7 +856,7 @@ SourceResultType PhysicalAsOfJoin::GetData(ExecutionContext &context, DataChunk if (result_count > 0) { // if there were any tuples that didn't find a match, output them - const idx_t left_column_count = children[0].get().GetTypes().size(); + const idx_t left_column_count = children[0]->types.size(); for (idx_t col_idx = 0; col_idx < left_column_count; ++col_idx) { chunk.data[col_idx].SetVectorType(VectorType::CONSTANT_VECTOR); ConstantVector::SetNull(chunk.data[col_idx], true); diff --git a/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp b/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp index 134b9e9d2..deabb6f89 100644 --- a/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp @@ -10,13 +10,13 @@ namespace duckdb { -PhysicalBlockwiseNLJoin::PhysicalBlockwiseNLJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, - unique_ptr condition, JoinType join_type, - idx_t estimated_cardinality) +PhysicalBlockwiseNLJoin::PhysicalBlockwiseNLJoin(LogicalOperator &op, unique_ptr left, + unique_ptr right, unique_ptr condition, + JoinType join_type, idx_t estimated_cardinality) : PhysicalJoin(op, PhysicalOperatorType::BLOCKWISE_NL_JOIN, join_type, estimated_cardinality), condition(std::move(condition)) { - children.push_back(left); - children.push_back(right); + children.push_back(std::move(left)); + children.push_back(std::move(right)); // MARK and SINGLE joins not handled D_ASSERT(join_type != JoinType::MARK); D_ASSERT(join_type != JoinType::SINGLE); @@ -34,7 +34,7 @@ class BlockwiseNLJoinLocalState : public LocalSinkState { class BlockwiseNLJoinGlobalState : public GlobalSinkState { public: explicit BlockwiseNLJoinGlobalState(ClientContext &context, const PhysicalBlockwiseNLJoin &op) - : right_chunks(context, op.children[1].get().GetTypes()), right_outer(PropagatesBuildSide(op.join_type)) { + : right_chunks(context, op.children[1]->GetTypes()), right_outer(PropagatesBuildSide(op.join_type)) { } mutex lock; @@ -108,10 +108,10 @@ unique_ptr PhysicalBlockwiseNLJoin::GetOperatorState(ExecutionCon auto result = make_uniq(context, gstate.right_chunks, *this); if (join_type == JoinType::SEMI || join_type == JoinType::ANTI) { vector intermediate_types; - for (auto &type : children[0].get().GetTypes()) { + for (auto &type : children[0]->types) { intermediate_types.emplace_back(type); } - for (auto &type : children[1].get().GetTypes()) { + for (auto &type : children[1]->types) { intermediate_types.emplace_back(type); } result->intermediate_chunk.Initialize(Allocator::DefaultAllocator(), intermediate_types); diff --git a/src/duckdb/src/execution/operator/join/physical_comparison_join.cpp b/src/duckdb/src/execution/operator/join/physical_comparison_join.cpp index 59c8ba6e5..1091e2165 100644 --- a/src/duckdb/src/execution/operator/join/physical_comparison_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_comparison_join.cpp @@ -82,6 +82,7 @@ void PhysicalComparisonJoin::ConstructEmptyJoinResult(JoinType join_type, bool h result.Reference(input); } else if (join_type == JoinType::MARK) { // MARK join with empty hash table + D_ASSERT(join_type == JoinType::MARK); D_ASSERT(result.ColumnCount() == input.ColumnCount() + 1); auto &result_vector = result.data.back(); D_ASSERT(result_vector.GetType() == LogicalType::BOOLEAN); diff --git a/src/duckdb/src/execution/operator/join/physical_cross_product.cpp b/src/duckdb/src/execution/operator/join/physical_cross_product.cpp index 2fbb98be3..a1175017e 100644 --- a/src/duckdb/src/execution/operator/join/physical_cross_product.cpp +++ b/src/duckdb/src/execution/operator/join/physical_cross_product.cpp @@ -6,11 +6,11 @@ namespace duckdb { -PhysicalCrossProduct::PhysicalCrossProduct(vector types, PhysicalOperator &left, PhysicalOperator &right, - idx_t estimated_cardinality) +PhysicalCrossProduct::PhysicalCrossProduct(vector types, unique_ptr left, + unique_ptr right, idx_t estimated_cardinality) : CachingPhysicalOperator(PhysicalOperatorType::CROSS_PRODUCT, std::move(types), estimated_cardinality) { - children.push_back(left); - children.push_back(right); + children.push_back(std::move(left)); + children.push_back(std::move(right)); } //===--------------------------------------------------------------------===// @@ -19,7 +19,7 @@ PhysicalCrossProduct::PhysicalCrossProduct(vector types, PhysicalOp class CrossProductGlobalState : public GlobalSinkState { public: explicit CrossProductGlobalState(ClientContext &context, const PhysicalCrossProduct &op) - : rhs_materialized(context, op.children[1].get().GetTypes()) { + : rhs_materialized(context, op.children[1]->GetTypes()) { rhs_materialized.InitializeAppend(append_state); } @@ -140,7 +140,7 @@ void PhysicalCrossProduct::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_ } vector> PhysicalCrossProduct::GetSources() const { - return children[0].get().GetSources(); + return children[0]->GetSources(); } } // namespace duckdb diff --git a/src/duckdb/src/execution/operator/join/physical_delim_join.cpp b/src/duckdb/src/execution/operator/join/physical_delim_join.cpp index d392b0c3b..1da39904d 100644 --- a/src/duckdb/src/execution/operator/join/physical_delim_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_delim_join.cpp @@ -5,26 +5,26 @@ namespace duckdb { PhysicalDelimJoin::PhysicalDelimJoin(PhysicalOperatorType type, vector types, - PhysicalOperator &original_join, PhysicalOperator &distinct, - const vector> &delim_scans, - idx_t estimated_cardinality, optional_idx delim_idx) - : PhysicalOperator(type, std::move(types), estimated_cardinality), join(original_join), - distinct(distinct.Cast()), delim_scans(delim_scans), delim_idx(delim_idx) { + unique_ptr original_join, + vector> delim_scans, idx_t estimated_cardinality, + optional_idx delim_idx) + : PhysicalOperator(type, std::move(types), estimated_cardinality), join(std::move(original_join)), + delim_scans(std::move(delim_scans)), delim_idx(delim_idx) { D_ASSERT(type == PhysicalOperatorType::LEFT_DELIM_JOIN || type == PhysicalOperatorType::RIGHT_DELIM_JOIN); } vector> PhysicalDelimJoin::GetChildren() const { vector> result; for (auto &child : children) { - result.push_back(child.get()); + result.push_back(*child); } - result.push_back(join); - result.push_back(distinct); + result.push_back(*join); + result.push_back(*distinct); return result; } InsertionOrderPreservingMap PhysicalDelimJoin::ParamsToString() const { - auto result = join.ParamsToString(); + auto result = join->ParamsToString(); result["Delim Index"] = StringUtil::Format("%llu", delim_idx.GetIndex()); return result; } diff --git a/src/duckdb/src/execution/operator/join/physical_hash_join.cpp b/src/duckdb/src/execution/operator/join/physical_hash_join.cpp index ab39f27c6..a66cb8cc6 100644 --- a/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_hash_join.cpp @@ -29,8 +29,8 @@ namespace duckdb { -PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, - vector cond, JoinType join_type, +PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, unique_ptr left, + unique_ptr right, vector cond, JoinType join_type, const vector &left_projection_map, const vector &right_projection_map, vector delim_types, idx_t estimated_cardinality, unique_ptr pushdown_info_p) @@ -39,8 +39,8 @@ PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, filter_pushdown = std::move(pushdown_info_p); - children.push_back(left); - children.push_back(right); + children.push_back(std::move(left)); + children.push_back(std::move(right)); // Collect condition types, and which conditions are just references (so we won't duplicate them in the payload) unordered_map build_columns_in_conditions; @@ -52,7 +52,7 @@ PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, } } - auto &lhs_input_types = children[0].get().GetTypes(); + auto &lhs_input_types = children[0]->GetTypes(); // Create a projection map for the LHS (if it was empty), for convenience lhs_output_columns.col_idxs = left_projection_map; @@ -73,7 +73,7 @@ PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, return; } - auto &rhs_input_types = children[1].get().GetTypes(); + auto &rhs_input_types = children[1]->GetTypes(); // Create a projection map for the RHS (if it was empty), for convenience auto right_projection_map_copy = right_projection_map; @@ -102,9 +102,11 @@ PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, } } -PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, - vector cond, JoinType join_type, idx_t estimated_cardinality) - : PhysicalHashJoin(op, left, right, std::move(cond), join_type, {}, {}, {}, estimated_cardinality, nullptr) { +PhysicalHashJoin::PhysicalHashJoin(LogicalOperator &op, unique_ptr left, + unique_ptr right, vector cond, JoinType join_type, + idx_t estimated_cardinality) + : PhysicalHashJoin(op, std::move(left), std::move(right), std::move(cond), join_type, {}, {}, {}, + estimated_cardinality, nullptr) { } //===--------------------------------------------------------------------===// @@ -150,7 +152,7 @@ class HashJoinGlobalSinkState : public GlobalSinkState { // For external hash join external = ClientConfig::GetConfig(context).GetSetting(context); // Set probe types - probe_types = op.children[0].get().GetTypes(); + probe_types = op.children[0]->types; probe_types.emplace_back(LogicalType::HASH); if (op.filter_pushdown) { @@ -372,45 +374,6 @@ SinkCombineResultType PhysicalHashJoin::Combine(ExecutionContext &context, Opera //===--------------------------------------------------------------------===// // Finalize //===--------------------------------------------------------------------===// - -static constexpr idx_t PARALLEL_CONSTRUCT_THRESHOLD = 1048576; -static constexpr double SKEW_SINGLE_THREADED_THRESHOLD = 0.33; - -//! If the data is very skewed (many of the exact same key), our finalize will become slow, -//! due to completely slamming the same atomic using compare-and-swaps. -//! We can detect this because we partition the data, and go for a single-threaded finalize instead. -static bool KeysAreSkewed(const HashJoinGlobalSinkState &sink) { - const auto max_partition_ht_size = - sink.max_partition_size + sink.hash_table->PointerTableSize(sink.max_partition_count); - const auto skew = static_cast(max_partition_ht_size) / static_cast(sink.total_size); - return skew > SKEW_SINGLE_THREADED_THRESHOLD; -} - -//! If we have only one thread, always finalize single-threaded. Otherwise, we finalize in parallel if we -//! have more than 1M rows or if we want to verify parallelism. -static bool FinalizeSingleThreaded(const HashJoinGlobalSinkState &sink, const bool consider_skew) { - - // if only one thread, finalize single-threaded - const auto num_threads = NumericCast(sink.num_threads); - if (num_threads == 1) { - return true; - } - - // if we want to verify parallelism, finalize parallel - if (sink.context.config.verify_parallelism) { - return false; - } - - // finalize single-threaded if we have less than 1M rows - const auto &ht = *sink.hash_table; - const bool ht_is_small = ht.Count() < PARALLEL_CONSTRUCT_THRESHOLD; - - if (consider_skew) { - return ht_is_small || KeysAreSkewed(sink); - } - return ht_is_small; -} - static idx_t GetTupleWidth(const vector &types, bool &all_constant) { idx_t tuple_width = 0; all_constant = true; @@ -445,72 +408,16 @@ void PhysicalHashJoin::PrepareFinalize(ClientContext &context, GlobalSinkState & gstate.total_size = ht.GetTotalSize(gstate.local_hash_tables, gstate.max_partition_size, gstate.max_partition_count); gstate.probe_side_requirement = - GetPartitioningSpaceRequirement(context, children[0].get().GetTypes(), ht.GetRadixBits(), gstate.num_threads); + GetPartitioningSpaceRequirement(context, children[0]->types, ht.GetRadixBits(), gstate.num_threads); const auto max_partition_ht_size = - gstate.max_partition_size + gstate.hash_table->PointerTableSize(gstate.max_partition_count); + gstate.max_partition_size + JoinHashTable::PointerTableSize(gstate.max_partition_count); gstate.temporary_memory_state->SetMinimumReservation(max_partition_ht_size + gstate.probe_side_requirement); bool all_constant; - gstate.temporary_memory_state->SetMaterializationPenalty(GetTupleWidth(children[0].get().GetTypes(), all_constant)); + gstate.temporary_memory_state->SetMaterializationPenalty(GetTupleWidth(children[0]->types, all_constant)); gstate.temporary_memory_state->SetRemainingSize(gstate.total_size); } -class HashJoinTableInitTask : public ExecutorTask { -public: - HashJoinTableInitTask(shared_ptr event_p, ClientContext &context, HashJoinGlobalSinkState &sink_p, - idx_t entry_idx_from_p, idx_t entry_idx_to_p, const PhysicalOperator &op_p) - : ExecutorTask(context, std::move(event_p), op_p), sink(sink_p), entry_idx_from(entry_idx_from_p), - entry_idx_to(entry_idx_to_p) { - } - - TaskExecutionResult ExecuteTask(TaskExecutionMode mode) override { - sink.hash_table->InitializePointerTable(entry_idx_from, entry_idx_to); - event->FinishTask(); - return TaskExecutionResult::TASK_FINISHED; - } - -private: - HashJoinGlobalSinkState &sink; - idx_t entry_idx_from; - idx_t entry_idx_to; -}; - -class HashJoinTableInitEvent : public BasePipelineEvent { -public: - HashJoinTableInitEvent(Pipeline &pipeline_p, HashJoinGlobalSinkState &sink) - : BasePipelineEvent(pipeline_p), sink(sink) { - } - - HashJoinGlobalSinkState &sink; - -public: - void Schedule() override { - auto &context = pipeline->GetClientContext(); - vector> finalize_tasks; - auto &ht = *sink.hash_table; - const auto entry_count = ht.capacity; - auto num_threads = NumericCast(sink.num_threads); - - // we don't have to check whether it is too skewed here, as we only initialize the pointer table - if (FinalizeSingleThreaded(sink, false)) { - // Single-threaded memset - finalize_tasks.push_back( - make_uniq(shared_from_this(), context, sink, 0U, entry_count, sink.op)); - } else { - // have 4 times more tasks than threads, but bound the to a minimum - const idx_t entries_per_task = MaxValue(entry_count / num_threads / 4, MINIMUM_ENTRIES_PER_TASK); - // Parallel memset - for (idx_t entry_idx = 0; entry_idx < entry_count; entry_idx += entries_per_task) { - auto entry_idx_to = MinValue(entry_idx + entries_per_task, entry_count); - finalize_tasks.push_back(make_uniq(shared_from_this(), context, sink, entry_idx, - entry_idx_to, sink.op)); - } - } - SetTasks(std::move(finalize_tasks)); - } - static constexpr const idx_t MINIMUM_ENTRIES_PER_TASK = 131072; -}; - class HashJoinFinalizeTask : public ExecutorTask { public: HashJoinFinalizeTask(shared_ptr event_p, ClientContext &context, HashJoinGlobalSinkState &sink_p, @@ -547,9 +454,17 @@ class HashJoinFinalizeEvent : public BasePipelineEvent { vector> finalize_tasks; auto &ht = *sink.hash_table; const auto chunk_count = ht.GetDataCollection().ChunkCount(); + const auto num_threads = NumericCast(sink.num_threads); - // if the keys are too skewed, we finalize single-threaded - if (FinalizeSingleThreaded(sink, true)) { + // If the data is very skewed (many of the exact same key), our finalize will become slow, + // due to completely slamming the same atomic using compare-and-swaps. + // We can detect this because we partition the data, and go for a single-threaded finalize instead. + const auto max_partition_ht_size = + sink.max_partition_size + JoinHashTable::PointerTableSize(sink.max_partition_count); + const auto skew = static_cast(max_partition_ht_size) / static_cast(sink.total_size); + + if (num_threads == 1 || (ht.Count() < PARALLEL_CONSTRUCT_THRESHOLD && skew > SKEW_SINGLE_THREADED_THRESHOLD && + !context.config.verify_parallelism)) { // Single-threaded finalize finalize_tasks.push_back( make_uniq(shared_from_this(), context, sink, 0U, chunk_count, false, sink.op)); @@ -570,7 +485,9 @@ class HashJoinFinalizeEvent : public BasePipelineEvent { sink.hash_table->finalized = true; } + static constexpr idx_t PARALLEL_CONSTRUCT_THRESHOLD = 1048576; static constexpr idx_t CHUNKS_PER_TASK = 64; + static constexpr double SKEW_SINGLE_THREADED_THRESHOLD = 0.33; }; void HashJoinGlobalSinkState::ScheduleFinalize(Pipeline &pipeline, Event &event) { @@ -578,13 +495,9 @@ void HashJoinGlobalSinkState::ScheduleFinalize(Pipeline &pipeline, Event &event) hash_table->finalized = true; return; } - hash_table->AllocatePointerTable(); - - auto new_init_event = make_shared_ptr(pipeline, *this); - event.InsertEvent(new_init_event); - - auto new_finalize_event = make_shared_ptr(pipeline, *this); - new_init_event->InsertEvent(std::move(new_finalize_event)); + hash_table->InitializePointerTable(); + auto new_event = make_shared_ptr(pipeline, *this); + event.InsertEvent(std::move(new_event)); } void HashJoinGlobalSinkState::InitializeProbeSpill() { @@ -677,7 +590,7 @@ class HashJoinRepartitionEvent : public BasePipelineEvent { GetPartitioningSpaceRequirement(sink.context, op.types, sink.hash_table->GetRadixBits(), sink.num_threads); sink.temporary_memory_state->SetMinimumReservation(sink.max_partition_size + - sink.hash_table->PointerTableSize(sink.max_partition_count) + + JoinHashTable::PointerTableSize(sink.max_partition_count) + sink.probe_side_requirement); sink.temporary_memory_state->UpdateReservation(executor.context); @@ -705,7 +618,7 @@ void JoinFilterPushdownInfo::PushInFilter(const JoinFilterPushdownFilter &info, idx_t key_count = ht.FillWithHTOffsets(join_ht_state, tuples_addresses); // Scan the build keys in the hash table - Vector build_vector(ht.layout_ptr->GetTypes()[build_idx], key_count); + Vector build_vector(ht.layout.GetTypes()[build_idx], key_count); data_collection.Gather(tuples_addresses, *FlatVector::IncrementalSelectionVector(), key_count, build_idx, build_vector, *FlatVector::IncrementalSelectionVector(), nullptr); @@ -797,32 +710,12 @@ SinkFinalizeType PhysicalHashJoin::Finalize(Pipeline &pipeline, Event &event, Cl sink.temporary_memory_state->UpdateReservation(context); sink.external = sink.temporary_memory_state->GetReservation() < sink.total_size; - if (sink.external) { - // For external join we reduce the load factor, this may even prevent the external join altogether - ht.load_factor = JoinHashTable::EXTERNAL_LOAD_FACTOR; - - idx_t temp_max_partition_size; - idx_t temp_max_partition_count; - idx_t temp_total_size = - ht.GetTotalSize(sink.local_hash_tables, temp_max_partition_size, temp_max_partition_count); - - if (temp_total_size < sink.temporary_memory_state->GetReservation()) { - // We prevented the external join by reducing the load factor. Update the state accordingly - sink.temporary_memory_state->SetMinimumReservation(temp_total_size); - sink.temporary_memory_state->SetRemainingSizeAndUpdateReservation(context, temp_total_size); - - sink.total_size = temp_total_size; - sink.max_partition_size = temp_max_partition_size; - sink.max_partition_count = temp_max_partition_count; - - sink.external = false; - } - } if (sink.external) { // External Hash Join sink.perfect_join_executor.reset(); - const auto max_partition_ht_size = sink.max_partition_size + ht.PointerTableSize(sink.max_partition_count); + const auto max_partition_ht_size = + sink.max_partition_size + JoinHashTable::PointerTableSize(sink.max_partition_count); const auto very_very_skewed = // No point in repartitioning if it's this skewed static_cast(max_partition_ht_size) >= 0.8 * static_cast(sink.total_size); if (!very_very_skewed && @@ -1114,7 +1007,7 @@ unique_ptr PhysicalHashJoin::GetLocalSourceState(ExecutionCont HashJoinGlobalSourceState::HashJoinGlobalSourceState(const PhysicalHashJoin &op, const ClientContext &context) : op(op), global_stage(HashJoinSourceStage::INIT), build_chunk_count(0), build_chunk_done(0), probe_chunk_count(0), - probe_chunk_done(0), probe_count(op.children[0].get().estimated_cardinality), + probe_chunk_done(0), probe_count(op.children[0]->estimated_cardinality), parallel_scan_chunk_count(context.config.verify_parallelism ? 1 : 120) { } @@ -1196,7 +1089,11 @@ void HashJoinGlobalSourceState::PrepareBuild(HashJoinGlobalSinkState &sink) { if (sink.context.config.verify_parallelism) { build_chunks_per_thread = 1; } else { - if (KeysAreSkewed(sink)) { + const auto max_partition_ht_size = + sink.max_partition_size + JoinHashTable::PointerTableSize(sink.max_partition_count); + const auto skew = static_cast(max_partition_ht_size) / static_cast(sink.total_size); + + if (skew > HashJoinFinalizeEvent::SKEW_SINGLE_THREADED_THRESHOLD) { build_chunks_per_thread = build_chunk_count; // This forces single-threaded building } else { build_chunks_per_thread = // Same task size as in HashJoinFinalizeEvent @@ -1204,8 +1101,7 @@ void HashJoinGlobalSourceState::PrepareBuild(HashJoinGlobalSinkState &sink) { } } - ht.AllocatePointerTable(); - ht.InitializePointerTable(0, ht.capacity); + ht.InitializePointerTable(); global_stage = HashJoinSourceStage::BUILD; } diff --git a/src/duckdb/src/execution/operator/join/physical_iejoin.cpp b/src/duckdb/src/execution/operator/join/physical_iejoin.cpp index 20a517c15..c5d5810fa 100644 --- a/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +++ b/src/duckdb/src/execution/operator/join/physical_iejoin.cpp @@ -17,10 +17,11 @@ namespace duckdb { -PhysicalIEJoin::PhysicalIEJoin(LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right, - vector cond, JoinType join_type, idx_t estimated_cardinality) - : PhysicalRangeJoin(op, PhysicalOperatorType::IE_JOIN, left, right, std::move(cond), join_type, - estimated_cardinality) { +PhysicalIEJoin::PhysicalIEJoin(LogicalComparisonJoin &op, unique_ptr left, + unique_ptr right, vector cond, JoinType join_type, + idx_t estimated_cardinality) + : PhysicalRangeJoin(op, PhysicalOperatorType::IE_JOIN, std::move(left), std::move(right), std::move(cond), + join_type, estimated_cardinality) { // 1. let L1 (resp. L2) be the array of column X (resp. Y) D_ASSERT(conditions.size() >= 2); @@ -84,13 +85,13 @@ class IEJoinGlobalState : public GlobalSinkState { IEJoinGlobalState(ClientContext &context, const PhysicalIEJoin &op) : child(0) { tables.resize(2); RowLayout lhs_layout; - lhs_layout.Initialize(op.children[0].get().GetTypes()); + lhs_layout.Initialize(op.children[0]->types); vector lhs_order; lhs_order.emplace_back(op.lhs_orders[0].Copy()); tables[0] = make_uniq(context, lhs_order, lhs_layout, op); RowLayout rhs_layout; - rhs_layout.Initialize(op.children[1].get().GetTypes()); + rhs_layout.Initialize(op.children[1]->types); vector rhs_order; rhs_order.emplace_back(op.rhs_orders[0].Copy()); tables[1] = make_uniq(context, rhs_order, rhs_layout, op); @@ -691,7 +692,7 @@ void PhysicalIEJoin::ResolveComplexJoin(ExecutionContext &context, DataChunk &re auto &left_table = *ie_sink.tables[0]; auto &right_table = *ie_sink.tables[1]; - const auto left_cols = children[0].get().GetTypes().size(); + const auto left_cols = children[0]->GetTypes().size(); auto &chunk = state.unprojected; do { SelectionVector lsel(STANDARD_VECTOR_SIZE); @@ -972,7 +973,7 @@ SourceResultType PhysicalIEJoin::GetData(ExecutionContext &context, DataChunk &r } // Process LEFT OUTER results - const auto left_cols = children[0].get().GetTypes().size(); + const auto left_cols = children[0]->GetTypes().size(); while (ie_lstate.left_matches) { const idx_t count = ie_lstate.SelectOuterRows(ie_lstate.left_matches); if (!count) { @@ -1043,11 +1044,11 @@ void PhysicalIEJoin::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipeli // Build out LHS auto lhs_pipeline = child_meta_pipeline.GetBasePipeline(); - children[0].get().BuildPipelines(*lhs_pipeline, child_meta_pipeline); + children[0]->BuildPipelines(*lhs_pipeline, child_meta_pipeline); // Build out RHS auto &rhs_pipeline = child_meta_pipeline.CreatePipeline(); - children[1].get().BuildPipelines(rhs_pipeline, child_meta_pipeline); + children[1]->BuildPipelines(rhs_pipeline, child_meta_pipeline); // Despite having the same sink, RHS and everything created after it need their own (same) PipelineFinishEvent child_meta_pipeline.AddFinishEvent(rhs_pipeline); diff --git a/src/duckdb/src/execution/operator/join/physical_join.cpp b/src/duckdb/src/execution/operator/join/physical_join.cpp index 78512d481..bb7011a3a 100644 --- a/src/duckdb/src/execution/operator/join/physical_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_join.cpp @@ -47,8 +47,8 @@ void PhysicalJoin::BuildJoinPipelines(Pipeline ¤t, MetaPipeline &meta_pipe if (build_rhs) { // on the RHS (build side), we construct a child MetaPipeline with this operator as its sink auto &child_meta_pipeline = meta_pipeline.CreateChildMetaPipeline(current, op, MetaPipelineType::JOIN_BUILD); - child_meta_pipeline.Build(op.children[1]); - if (op.children[1].get().CanSaturateThreads(current.GetClientContext())) { + child_meta_pipeline.Build(*op.children[1]); + if (op.children[1]->CanSaturateThreads(current.GetClientContext())) { // if the build side can saturate all available threads, // we don't just make the LHS pipeline depend on the RHS, but recursively all LHS children too. // this prevents breadth-first plan evaluation @@ -58,7 +58,7 @@ void PhysicalJoin::BuildJoinPipelines(Pipeline ¤t, MetaPipeline &meta_pipe } // continue building the current pipeline on the LHS (probe side) - op.children[0].get().BuildPipelines(current, meta_pipeline); + op.children[0]->BuildPipelines(current, meta_pipeline); if (last_child_ptr) { // the pointer was set, set up the dependencies @@ -87,7 +87,7 @@ void PhysicalJoin::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipeline } vector> PhysicalJoin::GetSources() const { - auto result = children[0].get().GetSources(); + auto result = children[0]->GetSources(); if (IsSource()) { result.push_back(*this); } diff --git a/src/duckdb/src/execution/operator/join/physical_left_delim_join.cpp b/src/duckdb/src/execution/operator/join/physical_left_delim_join.cpp index 238dcc036..49f259abc 100644 --- a/src/duckdb/src/execution/operator/join/physical_left_delim_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_left_delim_join.cpp @@ -9,26 +9,24 @@ namespace duckdb { -PhysicalLeftDelimJoin::PhysicalLeftDelimJoin(PhysicalPlanGenerator &planner, vector types, - PhysicalOperator &original_join, PhysicalOperator &distinct, - const vector> &delim_scans, +PhysicalLeftDelimJoin::PhysicalLeftDelimJoin(vector types, unique_ptr original_join, + vector> delim_scans, idx_t estimated_cardinality, optional_idx delim_idx) - : PhysicalDelimJoin(PhysicalOperatorType::LEFT_DELIM_JOIN, std::move(types), original_join, distinct, delim_scans, - estimated_cardinality, delim_idx) { - D_ASSERT(join.children.size() == 2); + : PhysicalDelimJoin(PhysicalOperatorType::LEFT_DELIM_JOIN, std::move(types), std::move(original_join), + std::move(delim_scans), estimated_cardinality, delim_idx) { + D_ASSERT(join->children.size() == 2); // now for the original join // we take its left child, this is the side that we will duplicate eliminate - children.push_back(join.children[0]); + children.push_back(std::move(join->children[0])); // we replace it with a PhysicalColumnDataScan, that scans the ColumnDataCollection that we keep cached // the actual chunk collection to scan will be created in the LeftDelimJoinGlobalState - auto &cached_scan = planner.Make( - children[0].get().GetTypes(), PhysicalOperatorType::COLUMN_DATA_SCAN, estimated_cardinality, nullptr); + auto cached_chunk_scan = make_uniq( + children[0]->GetTypes(), PhysicalOperatorType::COLUMN_DATA_SCAN, estimated_cardinality, nullptr); if (delim_idx.IsValid()) { - auto &cast_cached_scan = cached_scan.Cast(); - cast_cached_scan.cte_index = delim_idx.GetIndex(); + cached_chunk_scan->cte_index = delim_idx.GetIndex(); } - join.children[0] = cached_scan; + join->children[0] = std::move(cached_chunk_scan); } //===--------------------------------------------------------------------===// @@ -37,11 +35,11 @@ PhysicalLeftDelimJoin::PhysicalLeftDelimJoin(PhysicalPlanGenerator &planner, vec class LeftDelimJoinGlobalState : public GlobalSinkState { public: explicit LeftDelimJoinGlobalState(ClientContext &context, const PhysicalLeftDelimJoin &delim_join) - : lhs_data(context, delim_join.children[0].get().GetTypes()) { + : lhs_data(context, delim_join.children[0]->GetTypes()) { D_ASSERT(!delim_join.delim_scans.empty()); // set up the delim join chunk to scan in the original join - auto &cast_cached_scan = delim_join.join.children[0].get().Cast(); - cast_cached_scan.collection = &lhs_data; + auto &cached_chunk_scan = delim_join.join->children[0]->Cast(); + cached_chunk_scan.collection = &lhs_data; } ColumnDataCollection lhs_data; @@ -56,7 +54,7 @@ class LeftDelimJoinGlobalState : public GlobalSinkState { class LeftDelimJoinLocalState : public LocalSinkState { public: explicit LeftDelimJoinLocalState(ClientContext &context, const PhysicalLeftDelimJoin &delim_join) - : lhs_data(context, delim_join.children[0].get().GetTypes()) { + : lhs_data(context, delim_join.children[0]->GetTypes()) { lhs_data.InitializeAppend(append_state); } @@ -71,16 +69,16 @@ class LeftDelimJoinLocalState : public LocalSinkState { unique_ptr PhysicalLeftDelimJoin::GetGlobalSinkState(ClientContext &context) const { auto state = make_uniq(context, *this); - distinct.sink_state = distinct.GetGlobalSinkState(context); + distinct->sink_state = distinct->GetGlobalSinkState(context); if (delim_scans.size() > 1) { - PhysicalHashAggregate::SetMultiScan(*distinct.sink_state); + PhysicalHashAggregate::SetMultiScan(*distinct->sink_state); } return std::move(state); } unique_ptr PhysicalLeftDelimJoin::GetLocalSinkState(ExecutionContext &context) const { auto state = make_uniq(context.client, *this); - state->distinct_state = distinct.GetLocalSinkState(context); + state->distinct_state = distinct->GetLocalSinkState(context); return std::move(state); } @@ -88,8 +86,8 @@ SinkResultType PhysicalLeftDelimJoin::Sink(ExecutionContext &context, DataChunk OperatorSinkInput &input) const { auto &lstate = input.local_state.Cast(); lstate.lhs_data.Append(lstate.append_state, chunk); - OperatorSinkInput distinct_sink_input {*distinct.sink_state, *lstate.distinct_state, input.interrupt_state}; - distinct.Sink(context, chunk, distinct_sink_input); + OperatorSinkInput distinct_sink_input {*distinct->sink_state, *lstate.distinct_state, input.interrupt_state}; + distinct->Sink(context, chunk, distinct_sink_input); return SinkResultType::NEED_MORE_INPUT; } @@ -98,22 +96,24 @@ SinkCombineResultType PhysicalLeftDelimJoin::Combine(ExecutionContext &context, auto &gstate = input.global_state.Cast(); gstate.Merge(lstate.lhs_data); - OperatorSinkCombineInput distinct_combine_input {*distinct.sink_state, *lstate.distinct_state, + OperatorSinkCombineInput distinct_combine_input {*distinct->sink_state, *lstate.distinct_state, input.interrupt_state}; - distinct.Combine(context, distinct_combine_input); + distinct->Combine(context, distinct_combine_input); return SinkCombineResultType::FINISHED; } void PhysicalLeftDelimJoin::PrepareFinalize(ClientContext &context, GlobalSinkState &sink_state) const { - distinct.PrepareFinalize(context, *distinct.sink_state); + distinct->PrepareFinalize(context, *distinct->sink_state); } SinkFinalizeType PhysicalLeftDelimJoin::Finalize(Pipeline &pipeline, Event &event, ClientContext &client, OperatorSinkFinalizeInput &input) const { - // Finalize the distinct hash table. - OperatorSinkFinalizeInput finalize_input {*distinct.sink_state, input.interrupt_state}; - distinct.Finalize(pipeline, event, client, finalize_input); + // finalize the distinct HT + D_ASSERT(distinct); + + OperatorSinkFinalizeInput finalize_input {*distinct->sink_state, input.interrupt_state}; + distinct->Finalize(pipeline, event, client, finalize_input); return SinkFinalizeType::READY; } @@ -125,7 +125,7 @@ void PhysicalLeftDelimJoin::BuildPipelines(Pipeline ¤t, MetaPipeline &meta sink_state.reset(); auto &child_meta_pipeline = meta_pipeline.CreateChildMetaPipeline(current, *this); - child_meta_pipeline.Build(children[0]); + child_meta_pipeline.Build(*children[0]); D_ASSERT(type == PhysicalOperatorType::LEFT_DELIM_JOIN); // recurse into the actual join @@ -137,7 +137,7 @@ void PhysicalLeftDelimJoin::BuildPipelines(Pipeline ¤t, MetaPipeline &meta state.delim_join_dependencies.insert( make_pair(delim_scan, reference(*child_meta_pipeline.GetBasePipeline()))); } - join.BuildPipelines(current, meta_pipeline); + join->BuildPipelines(current, meta_pipeline); } } // namespace duckdb diff --git a/src/duckdb/src/execution/operator/join/physical_nested_loop_join.cpp b/src/duckdb/src/execution/operator/join/physical_nested_loop_join.cpp index 9be36df1b..022337e5a 100644 --- a/src/duckdb/src/execution/operator/join/physical_nested_loop_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_nested_loop_join.cpp @@ -9,13 +9,13 @@ namespace duckdb { -PhysicalNestedLoopJoin::PhysicalNestedLoopJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, - vector cond, JoinType join_type, - idx_t estimated_cardinality) +PhysicalNestedLoopJoin::PhysicalNestedLoopJoin(LogicalOperator &op, unique_ptr left, + unique_ptr right, vector cond, + JoinType join_type, idx_t estimated_cardinality) : PhysicalComparisonJoin(op, PhysicalOperatorType::NESTED_LOOP_JOIN, std::move(cond), join_type, estimated_cardinality) { - children.push_back(left); - children.push_back(right); + children.push_back(std::move(left)); + children.push_back(std::move(right)); } bool PhysicalJoin::HasNullValues(DataChunk &chunk) { @@ -151,9 +151,8 @@ class NestedLoopJoinLocalState : public LocalSinkState { class NestedLoopJoinGlobalState : public GlobalSinkState { public: explicit NestedLoopJoinGlobalState(ClientContext &context, const PhysicalNestedLoopJoin &op) - : right_payload_data(context, op.children[1].get().GetTypes()), - right_condition_data(context, op.GetJoinTypes()), has_null(false), - right_outer(PropagatesBuildSide(op.join_type)) { + : right_payload_data(context, op.children[1]->types), right_condition_data(context, op.GetJoinTypes()), + has_null(false), right_outer(PropagatesBuildSide(op.join_type)) { } mutex nj_lock; @@ -242,7 +241,7 @@ class PhysicalNestedLoopJoinState : public CachingOperatorState { auto &allocator = Allocator::Get(context); left_condition.Initialize(allocator, condition_types); right_condition.Initialize(allocator, condition_types); - right_payload.Initialize(allocator, op.children[1].get().GetTypes()); + right_payload.Initialize(allocator, op.children[1]->GetTypes()); left_outer.Initialize(STANDARD_VECTOR_SIZE); } diff --git a/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp b/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp index 350d51649..8216d91ab 100644 --- a/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp @@ -14,11 +14,11 @@ namespace duckdb { -PhysicalPiecewiseMergeJoin::PhysicalPiecewiseMergeJoin(LogicalComparisonJoin &op, PhysicalOperator &left, - PhysicalOperator &right, vector cond, +PhysicalPiecewiseMergeJoin::PhysicalPiecewiseMergeJoin(LogicalComparisonJoin &op, unique_ptr left, + unique_ptr right, vector cond, JoinType join_type, idx_t estimated_cardinality) - : PhysicalRangeJoin(op, PhysicalOperatorType::PIECEWISE_MERGE_JOIN, left, right, std::move(cond), join_type, - estimated_cardinality) { + : PhysicalRangeJoin(op, PhysicalOperatorType::PIECEWISE_MERGE_JOIN, std::move(left), std::move(right), + std::move(cond), join_type, estimated_cardinality) { for (auto &cond : conditions) { D_ASSERT(cond.left->return_type == cond.right->return_type); @@ -73,7 +73,7 @@ class MergeJoinGlobalState : public GlobalSinkState { public: MergeJoinGlobalState(ClientContext &context, const PhysicalPiecewiseMergeJoin &op) { RowLayout rhs_layout; - rhs_layout.Initialize(op.children[1].get().GetTypes()); + rhs_layout.Initialize(op.children[1]->types); vector rhs_order; rhs_order.emplace_back(op.rhs_orders[0].Copy()); table = make_uniq(context, rhs_order, rhs_layout, op); @@ -171,8 +171,8 @@ class PiecewiseMergeJoinState : public CachingOperatorState { condition_types.push_back(order.expression->return_type); } left_outer.Initialize(STANDARD_VECTOR_SIZE); - lhs_layout.Initialize(op.children[0].get().GetTypes()); - lhs_payload.Initialize(allocator, op.children[0].get().GetTypes()); + lhs_layout.Initialize(op.children[0]->types); + lhs_payload.Initialize(allocator, op.children[0]->types); lhs_order.emplace_back(op.lhs_orders[0].Copy()); @@ -222,7 +222,7 @@ class PiecewiseMergeJoinState : public CachingOperatorState { public: void ResolveJoinKeys(DataChunk &input) { // sort by join key - lhs_global_state = make_uniq(context, lhs_order, lhs_layout); + lhs_global_state = make_uniq(buffer_manager, lhs_order, lhs_layout); lhs_local_table = make_uniq(context, op, 0U); lhs_local_table->Sink(input, *lhs_global_state); @@ -747,12 +747,13 @@ SourceResultType PhysicalPiecewiseMergeJoin::GetData(ExecutionContext &context, if (result_count > 0) { // if there were any tuples that didn't find a match, output them - const idx_t left_column_count = children[0].get().GetTypes().size(); + const idx_t left_column_count = children[0]->types.size(); for (idx_t col_idx = 0; col_idx < left_column_count; ++col_idx) { result.data[col_idx].SetVectorType(VectorType::CONSTANT_VECTOR); ConstantVector::SetNull(result.data[col_idx], true); } - const idx_t right_column_count = children[1].get().GetTypes().size(); + const idx_t right_column_count = children[1]->types.size(); + ; for (idx_t col_idx = 0; col_idx < right_column_count; ++col_idx) { result.data[left_column_count + col_idx].Slice(rhs_chunk.data[col_idx], rsel, result_count); } diff --git a/src/duckdb/src/execution/operator/join/physical_positional_join.cpp b/src/duckdb/src/execution/operator/join/physical_positional_join.cpp index 98187a7d8..bcf4b498b 100644 --- a/src/duckdb/src/execution/operator/join/physical_positional_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_positional_join.cpp @@ -5,11 +5,11 @@ namespace duckdb { -PhysicalPositionalJoin::PhysicalPositionalJoin(vector types, PhysicalOperator &left, - PhysicalOperator &right, idx_t estimated_cardinality) +PhysicalPositionalJoin::PhysicalPositionalJoin(vector types, unique_ptr left, + unique_ptr right, idx_t estimated_cardinality) : PhysicalOperator(PhysicalOperatorType::POSITIONAL_JOIN, std::move(types), estimated_cardinality) { - children.push_back(left); - children.push_back(right); + children.push_back(std::move(left)); + children.push_back(std::move(right)); } //===--------------------------------------------------------------------===// @@ -18,7 +18,7 @@ PhysicalPositionalJoin::PhysicalPositionalJoin(vector types, Physic class PositionalJoinGlobalState : public GlobalSinkState { public: explicit PositionalJoinGlobalState(ClientContext &context, const PhysicalPositionalJoin &op) - : rhs(context, op.children[1].get().GetTypes()), initialized(false), source_offset(0), exhausted(false) { + : rhs(context, op.children[1]->GetTypes()), initialized(false), source_offset(0), exhausted(false) { rhs.InitializeAppend(append_state); } @@ -186,7 +186,7 @@ void PhysicalPositionalJoin::BuildPipelines(Pipeline ¤t, MetaPipeline &met } vector> PhysicalPositionalJoin::GetSources() const { - auto result = children[0].get().GetSources(); + auto result = children[0]->GetSources(); if (IsSource()) { result.push_back(*this); } diff --git a/src/duckdb/src/execution/operator/join/physical_range_join.cpp b/src/duckdb/src/execution/operator/join/physical_range_join.cpp index bddbd86b9..f7701f845 100644 --- a/src/duckdb/src/execution/operator/join/physical_range_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_range_join.cpp @@ -60,7 +60,8 @@ void PhysicalRangeJoin::LocalSortedTable::Sink(DataChunk &input, GlobalSortState PhysicalRangeJoin::GlobalSortedTable::GlobalSortedTable(ClientContext &context, const vector &orders, RowLayout &payload_layout, const PhysicalOperator &op_p) - : op(op_p), global_sort_state(context, orders, payload_layout), has_null(0), count(0), memory_per_thread(0) { + : op(op_p), global_sort_state(BufferManager::GetBufferManager(context), orders, payload_layout), has_null(0), + count(0), memory_per_thread(0) { // Set external (can be forced with the PRAGMA) auto &config = ClientConfig::GetConfig(context); @@ -161,9 +162,9 @@ void PhysicalRangeJoin::GlobalSortedTable::Finalize(Pipeline &pipeline, Event &e } } -PhysicalRangeJoin::PhysicalRangeJoin(LogicalComparisonJoin &op, PhysicalOperatorType type, PhysicalOperator &left, - PhysicalOperator &right, vector cond, JoinType join_type, - idx_t estimated_cardinality) +PhysicalRangeJoin::PhysicalRangeJoin(LogicalComparisonJoin &op, PhysicalOperatorType type, + unique_ptr left, unique_ptr right, + vector cond, JoinType join_type, idx_t estimated_cardinality) : PhysicalComparisonJoin(op, type, std::move(cond), join_type, estimated_cardinality) { // Reorder the conditions so that ranges are at the front. // TODO: use stats to improve the choice? @@ -188,13 +189,13 @@ PhysicalRangeJoin::PhysicalRangeJoin(LogicalComparisonJoin &op, PhysicalOperator } } - children.push_back(left); - children.push_back(right); + children.push_back(std::move(left)); + children.push_back(std::move(right)); // Fill out the left projection map. left_projection_map = op.left_projection_map; if (left_projection_map.empty()) { - const auto left_count = children[0].get().GetTypes().size(); + const auto left_count = children[0]->types.size(); left_projection_map.reserve(left_count); for (column_t i = 0; i < left_count; ++i) { left_projection_map.emplace_back(i); @@ -203,7 +204,7 @@ PhysicalRangeJoin::PhysicalRangeJoin(LogicalComparisonJoin &op, PhysicalOperator // Fill out the right projection map. right_projection_map = op.right_projection_map; if (right_projection_map.empty()) { - const auto right_count = children[1].get().GetTypes().size(); + const auto right_count = children[1]->types.size(); right_projection_map.reserve(right_count); for (column_t i = 0; i < right_count; ++i) { right_projection_map.emplace_back(i); @@ -211,8 +212,8 @@ PhysicalRangeJoin::PhysicalRangeJoin(LogicalComparisonJoin &op, PhysicalOperator } // Construct the unprojected type layout from the children's types - unprojected_types = children[0].get().GetTypes(); - auto &types = children[1].get().GetTypes(); + unprojected_types = children[0]->GetTypes(); + auto &types = children[1]->GetTypes(); unprojected_types.insert(unprojected_types.end(), types.begin(), types.end()); } @@ -313,7 +314,7 @@ void PhysicalRangeJoin::ProjectResult(DataChunk &chunk, DataChunk &result) const for (idx_t i = 0; i < left_projected; ++i) { result.data[i].Reference(chunk.data[left_projection_map[i]]); } - const auto left_width = children[0].get().GetTypes().size(); + const auto left_width = children[0]->types.size(); for (idx_t i = 0; i < right_projection_map.size(); ++i) { result.data[left_projected + i].Reference(chunk.data[left_width + right_projection_map[i]]); } diff --git a/src/duckdb/src/execution/operator/join/physical_right_delim_join.cpp b/src/duckdb/src/execution/operator/join/physical_right_delim_join.cpp index daad6a1a8..60aaeaca8 100644 --- a/src/duckdb/src/execution/operator/join/physical_right_delim_join.cpp +++ b/src/duckdb/src/execution/operator/join/physical_right_delim_join.cpp @@ -10,19 +10,18 @@ namespace duckdb { -PhysicalRightDelimJoin::PhysicalRightDelimJoin(PhysicalPlanGenerator &planner, vector types, - PhysicalOperator &original_join, PhysicalOperator &distinct, - const vector> &delim_scans, +PhysicalRightDelimJoin::PhysicalRightDelimJoin(vector types, unique_ptr original_join, + vector> delim_scans, idx_t estimated_cardinality, optional_idx delim_idx) - : PhysicalDelimJoin(PhysicalOperatorType::RIGHT_DELIM_JOIN, std::move(types), original_join, distinct, delim_scans, - estimated_cardinality, delim_idx) { - D_ASSERT(join.children.size() == 2); + : PhysicalDelimJoin(PhysicalOperatorType::RIGHT_DELIM_JOIN, std::move(types), std::move(original_join), + std::move(delim_scans), estimated_cardinality, delim_idx) { + D_ASSERT(join->children.size() == 2); // now for the original join // we take its right child, this is the side that we will duplicate eliminate - children.push_back(join.children[1]); + children.push_back(std::move(join->children[1])); // we replace it with a PhysicalDummyScan, which contains no data, just the types, it won't be scanned anyway - join.children[1] = planner.Make(children[0].get().GetTypes(), estimated_cardinality); + join->children[1] = make_uniq(children[0]->GetTypes(), estimated_cardinality); } //===--------------------------------------------------------------------===// @@ -38,18 +37,18 @@ class RightDelimJoinLocalState : public LocalSinkState { unique_ptr PhysicalRightDelimJoin::GetGlobalSinkState(ClientContext &context) const { auto state = make_uniq(); - join.sink_state = join.GetGlobalSinkState(context); - distinct.sink_state = distinct.GetGlobalSinkState(context); + join->sink_state = join->GetGlobalSinkState(context); + distinct->sink_state = distinct->GetGlobalSinkState(context); if (delim_scans.size() > 1) { - PhysicalHashAggregate::SetMultiScan(*distinct.sink_state); + PhysicalHashAggregate::SetMultiScan(*distinct->sink_state); } return std::move(state); } unique_ptr PhysicalRightDelimJoin::GetLocalSinkState(ExecutionContext &context) const { auto state = make_uniq(); - state->join_state = join.GetLocalSinkState(context); - state->distinct_state = distinct.GetLocalSinkState(context); + state->join_state = join->GetLocalSinkState(context); + state->distinct_state = distinct->GetLocalSinkState(context); return std::move(state); } @@ -57,11 +56,11 @@ SinkResultType PhysicalRightDelimJoin::Sink(ExecutionContext &context, DataChunk OperatorSinkInput &input) const { auto &lstate = input.local_state.Cast(); - OperatorSinkInput join_sink_input {*join.sink_state, *lstate.join_state, input.interrupt_state}; - join.Sink(context, chunk, join_sink_input); + OperatorSinkInput join_sink_input {*join->sink_state, *lstate.join_state, input.interrupt_state}; + join->Sink(context, chunk, join_sink_input); - OperatorSinkInput distinct_sink_input {*distinct.sink_state, *lstate.distinct_state, input.interrupt_state}; - distinct.Sink(context, chunk, distinct_sink_input); + OperatorSinkInput distinct_sink_input {*distinct->sink_state, *lstate.distinct_state, input.interrupt_state}; + distinct->Sink(context, chunk, distinct_sink_input); return SinkResultType::NEED_MORE_INPUT; } @@ -70,28 +69,31 @@ SinkCombineResultType PhysicalRightDelimJoin::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const { auto &lstate = input.local_state.Cast(); - OperatorSinkCombineInput join_combine_input {*join.sink_state, *lstate.join_state, input.interrupt_state}; - join.Combine(context, join_combine_input); + OperatorSinkCombineInput join_combine_input {*join->sink_state, *lstate.join_state, input.interrupt_state}; + join->Combine(context, join_combine_input); - OperatorSinkCombineInput distinct_combine_input {*distinct.sink_state, *lstate.distinct_state, + OperatorSinkCombineInput distinct_combine_input {*distinct->sink_state, *lstate.distinct_state, input.interrupt_state}; - distinct.Combine(context, distinct_combine_input); + distinct->Combine(context, distinct_combine_input); return SinkCombineResultType::FINISHED; } void PhysicalRightDelimJoin::PrepareFinalize(ClientContext &context, GlobalSinkState &sink_state) const { - join.PrepareFinalize(context, *join.sink_state); - distinct.PrepareFinalize(context, *distinct.sink_state); + join->PrepareFinalize(context, *join->sink_state); + distinct->PrepareFinalize(context, *distinct->sink_state); } SinkFinalizeType PhysicalRightDelimJoin::Finalize(Pipeline &pipeline, Event &event, ClientContext &client, OperatorSinkFinalizeInput &input) const { - OperatorSinkFinalizeInput join_finalize_input {*join.sink_state, input.interrupt_state}; - join.Finalize(pipeline, event, client, join_finalize_input); + D_ASSERT(join); + D_ASSERT(distinct); - OperatorSinkFinalizeInput distinct_finalize_input {*distinct.sink_state, input.interrupt_state}; - distinct.Finalize(pipeline, event, client, distinct_finalize_input); + OperatorSinkFinalizeInput join_finalize_input {*join->sink_state, input.interrupt_state}; + join->Finalize(pipeline, event, client, join_finalize_input); + + OperatorSinkFinalizeInput distinct_finalize_input {*distinct->sink_state, input.interrupt_state}; + distinct->Finalize(pipeline, event, client, distinct_finalize_input); return SinkFinalizeType::READY; } @@ -104,7 +106,7 @@ void PhysicalRightDelimJoin::BuildPipelines(Pipeline ¤t, MetaPipeline &met sink_state.reset(); auto &child_meta_pipeline = meta_pipeline.CreateChildMetaPipeline(current, *this); - child_meta_pipeline.Build(children[0]); + child_meta_pipeline.Build(*children[0]); D_ASSERT(type == PhysicalOperatorType::RIGHT_DELIM_JOIN); // recurse into the actual join @@ -118,7 +120,7 @@ void PhysicalRightDelimJoin::BuildPipelines(Pipeline ¤t, MetaPipeline &met } // Build join pipelines without building the RHS (already built in the Sink of this op) - PhysicalJoin::BuildJoinPipelines(current, meta_pipeline, join, false); + PhysicalJoin::BuildJoinPipelines(current, meta_pipeline, *join, false); } } // namespace duckdb diff --git a/src/duckdb/src/execution/operator/order/physical_order.cpp b/src/duckdb/src/execution/operator/order/physical_order.cpp index c3c043466..71294e9b7 100644 --- a/src/duckdb/src/execution/operator/order/physical_order.cpp +++ b/src/duckdb/src/execution/operator/order/physical_order.cpp @@ -21,8 +21,8 @@ PhysicalOrder::PhysicalOrder(vector types, vector //===--------------------------------------------------------------------===// class OrderGlobalSinkState : public GlobalSinkState { public: - OrderGlobalSinkState(ClientContext &context, const PhysicalOrder &order, RowLayout &payload_layout) - : order(order), global_sort_state(context, order.orders, payload_layout) { + OrderGlobalSinkState(BufferManager &buffer_manager, const PhysicalOrder &order, RowLayout &payload_layout) + : order(order), global_sort_state(buffer_manager, order.orders, payload_layout) { } const PhysicalOrder ℴ @@ -60,7 +60,7 @@ unique_ptr PhysicalOrder::GetGlobalSinkState(ClientContext &con // Get the payload layout from the return types RowLayout payload_layout; payload_layout.Initialize(types); - auto state = make_uniq(context, *this, payload_layout); + auto state = make_uniq(BufferManager::GetBufferManager(context), *this, payload_layout); // Set external (can be force with the PRAGMA) state->global_sort_state.external = ClientConfig::GetConfig(context).force_external; state->memory_per_thread = GetMaxThreadMemory(context); diff --git a/src/duckdb/src/execution/operator/persistent/csv_rejects_table.cpp b/src/duckdb/src/execution/operator/persistent/csv_rejects_table.cpp index 36e599a40..0674181f2 100644 --- a/src/duckdb/src/execution/operator/persistent/csv_rejects_table.cpp +++ b/src/duckdb/src/execution/operator/persistent/csv_rejects_table.cpp @@ -38,10 +38,10 @@ shared_ptr CSVRejectsTable::GetOrCreate(ClientContext &context, "CSV_REJECTS_TABLE_CACHE_ENTRY_" + StringUtil::Upper(rejects_scan) + "_" + StringUtil::Upper(rejects_error); auto &cache = ObjectCache::GetObjectCache(context); auto &catalog = Catalog::GetCatalog(context, TEMP_CATALOG); - auto rejects_scan_exist = catalog.GetEntry(context, DEFAULT_SCHEMA, rejects_scan, - OnEntryNotFound::RETURN_NULL) != nullptr; - auto rejects_error_exist = catalog.GetEntry(context, DEFAULT_SCHEMA, rejects_error, - OnEntryNotFound::RETURN_NULL) != nullptr; + auto rejects_scan_exist = catalog.GetEntry(context, CatalogType::TABLE_ENTRY, DEFAULT_SCHEMA, rejects_scan, + OnEntryNotFound::RETURN_NULL) != nullptr; + auto rejects_error_exist = catalog.GetEntry(context, CatalogType::TABLE_ENTRY, DEFAULT_SCHEMA, rejects_error, + OnEntryNotFound::RETURN_NULL) != nullptr; if ((rejects_scan_exist || rejects_error_exist) && !cache.Get(key)) { std::ostringstream error; if (rejects_scan_exist) { diff --git a/src/duckdb/src/execution/operator/persistent/physical_batch_copy_to_file.cpp b/src/duckdb/src/execution/operator/persistent/physical_batch_copy_to_file.cpp index 86560e256..4effccaff 100644 --- a/src/duckdb/src/execution/operator/persistent/physical_batch_copy_to_file.cpp +++ b/src/duckdb/src/execution/operator/persistent/physical_batch_copy_to_file.cpp @@ -67,9 +67,10 @@ class FixedBatchCopyGlobalState : public GlobalSinkState { static constexpr const idx_t MINIMUM_MEMORY_PER_COLUMN_PER_THREAD = 4ULL * 1024ULL * 1024ULL; public: - explicit FixedBatchCopyGlobalState(ClientContext &context_p, idx_t minimum_memory_per_thread) - : memory_manager(context_p, minimum_memory_per_thread), initialized(false), rows_copied(0), batch_size(0), - scheduled_batch_index(0), flushed_batch_index(0), any_flushing(false), any_finished(false), + explicit FixedBatchCopyGlobalState(ClientContext &context_p, unique_ptr global_state, + idx_t minimum_memory_per_thread) + : memory_manager(context_p, minimum_memory_per_thread), rows_copied(0), global_state(std::move(global_state)), + batch_size(0), scheduled_batch_index(0), flushed_batch_index(0), any_flushing(false), any_finished(false), minimum_memory_per_thread(minimum_memory_per_thread) { } @@ -77,8 +78,6 @@ class FixedBatchCopyGlobalState : public GlobalSinkState { BatchTaskManager task_manager; mutex lock; mutex flush_lock; - //! Whether or not the copy has been initialized - atomic initialized; //! The total number of rows copied to the file atomic rows_copied; //! Global copy state @@ -99,26 +98,6 @@ class FixedBatchCopyGlobalState : public GlobalSinkState { atomic any_finished; //! Minimum memory per thread idx_t minimum_memory_per_thread; - //! Written file info (for RETURN_STATS) - unique_ptr written_file_info; - - void Initialize(ClientContext &context, const PhysicalBatchCopyToFile &op) { - if (initialized) { - return; - } - lock_guard guard(lock); - if (initialized) { - return; - } - // initialize writing to the file - global_state = op.function.copy_to_initialize_global(context, *op.bind_data, op.file_path); - if (op.return_type == CopyFunctionReturnType::WRITTEN_FILE_STATISTICS) { - written_file_info = make_uniq(op.file_path); - written_file_info->file_stats = make_uniq(); - op.function.copy_to_get_written_statistics(context, *op.bind_data, *global_state, - *written_file_info->file_stats); - } - } void AddBatchData(idx_t batch_index, unique_ptr new_batch, idx_t memory_usage) { // move the batch data to the set of prepared batch data @@ -164,8 +143,7 @@ class FixedBatchCopyLocalState : public LocalSinkState { FixedBatchCopyState current_task = FixedBatchCopyState::SINKING_DATA; void InitializeCollection(ClientContext &context, const PhysicalOperator &op) { - collection = make_uniq(context, op.children[0].get().GetTypes()); - collection->SetPartitionIndex(0); // Makes the buffer manager less likely to spill this data + collection = make_uniq(BufferAllocator::Get(context), op.children[0]->types); collection->InitializeAppend(append_state); local_memory_usage = 0; } @@ -205,10 +183,6 @@ SinkResultType PhysicalBatchCopyToFile::Sink(ExecutionContext &context, DataChun return Sink(context, chunk, input); } } - if (!write_empty_file) { - // if we are not writing empty files - initialize after we have received rows - gstate.Initialize(context.client, *this); - } if (!state.collection) { state.InitializeCollection(context.client, *this); state.batch_index = batch_index; @@ -311,7 +285,7 @@ SinkFinalizeType PhysicalBatchCopyToFile::FinalFlush(ClientContext &context, Glo if (gstate.scheduled_batch_index != gstate.flushed_batch_index) { throw InternalException("Not all batches were flushed to disk - incomplete file?"); } - if (function.copy_to_finalize && gstate.global_state) { + if (function.copy_to_finalize) { function.copy_to_finalize(context, *bind_data, *gstate.global_state); if (use_tmp_file) { @@ -459,8 +433,8 @@ void PhysicalBatchCopyToFile::RepartitionBatches(ClientContext &context, GlobalS } else { // the collection is too large for a batch - we need to repartition // create an empty collection - auto new_collection = make_uniq(context, children[0].get().GetTypes()); - new_collection->SetPartitionIndex(0); // Makes the buffer manager less likely to spill this data + auto new_collection = + make_uniq(BufferAllocator::Get(context), children[0]->types); append_batch = make_uniq(0U, std::move(new_collection)); } if (append_batch) { @@ -484,8 +458,7 @@ void PhysicalBatchCopyToFile::RepartitionBatches(ClientContext &context, GlobalS // the collection is full - move it to the result and create a new one task_manager.AddTask(make_uniq(gstate.scheduled_batch_index++, std::move(append_batch))); - auto new_collection = make_uniq(context, children[0].get().GetTypes()); - new_collection->SetPartitionIndex(0); // Makes the buffer manager less likely to spill this data + auto new_collection = make_uniq(BufferAllocator::Get(context), children[0]->types); append_batch = make_uniq(0U, std::move(new_collection)); append_batch->collection->InitializeAppend(append_state); } @@ -621,12 +594,9 @@ unique_ptr PhysicalBatchCopyToFile::GetLocalSinkState(ExecutionC unique_ptr PhysicalBatchCopyToFile::GetGlobalSinkState(ClientContext &context) const { // request memory based on the minimum amount of memory per column auto minimum_memory_per_thread = - FixedBatchCopyGlobalState::MINIMUM_MEMORY_PER_COLUMN_PER_THREAD * children[0].get().GetTypes().size(); - auto result = make_uniq(context, minimum_memory_per_thread); - if (write_empty_file) { - // if we are writing the file also if it is empty - initialize now - result->Initialize(context, *this); - } + FixedBatchCopyGlobalState::MINIMUM_MEMORY_PER_COLUMN_PER_THREAD * children[0]->types.size(); + auto result = make_uniq( + context, function.copy_to_initialize_global(context, *bind_data, file_path), minimum_memory_per_thread); result->batch_size = function.desired_batch_size ? function.desired_batch_size(context, *bind_data) : 0; return std::move(result); } @@ -637,28 +607,16 @@ unique_ptr PhysicalBatchCopyToFile::GetGlobalSinkState(ClientCo SourceResultType PhysicalBatchCopyToFile::GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const { auto &g = sink_state->Cast(); - auto fp = use_tmp_file ? PhysicalCopyToFile::GetNonTmpFile(context.client, file_path) : file_path; + + chunk.SetCardinality(1); switch (return_type) { case CopyFunctionReturnType::CHANGED_ROWS: chunk.SetValue(0, 0, Value::BIGINT(NumericCast(g.rows_copied.load()))); - chunk.SetCardinality(1); break; case CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST: { - vector file_list; - if (g.global_state) { - file_list.emplace_back(std::move(fp)); - } chunk.SetValue(0, 0, Value::BIGINT(NumericCast(g.rows_copied.load()))); - chunk.SetValue(1, 0, Value::LIST(LogicalType::VARCHAR, std::move(file_list))); - chunk.SetCardinality(1); - break; - } - case CopyFunctionReturnType::WRITTEN_FILE_STATISTICS: { - if (g.written_file_info) { - g.written_file_info->file_path = std::move(fp); - PhysicalCopyToFile::ReturnStatistics(chunk, 0, *g.written_file_info); - chunk.SetCardinality(1); - } + auto fp = use_tmp_file ? PhysicalCopyToFile::GetNonTmpFile(context.client, file_path) : file_path; + chunk.SetValue(1, 0, Value::LIST(LogicalType::VARCHAR, {fp})); break; } default: diff --git a/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp b/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp index 553b67f33..de4d0e1a5 100644 --- a/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +++ b/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp @@ -15,17 +15,20 @@ namespace duckdb { PhysicalBatchInsert::PhysicalBatchInsert(vector types_p, TableCatalogEntry &table, + physical_index_vector_t column_index_map_p, + vector> bound_defaults_p, vector> bound_constraints_p, idx_t estimated_cardinality) : PhysicalOperator(PhysicalOperatorType::BATCH_INSERT, std::move(types_p), estimated_cardinality), - insert_table(&table), insert_types(table.GetTypes()), bound_constraints(std::move(bound_constraints_p)) { + column_index_map(std::move(column_index_map_p)), insert_table(&table), insert_types(table.GetTypes()), + bound_defaults(std::move(bound_defaults_p)), bound_constraints(std::move(bound_constraints_p)) { } PhysicalBatchInsert::PhysicalBatchInsert(LogicalOperator &op, SchemaCatalogEntry &schema, unique_ptr info_p, idx_t estimated_cardinality) : PhysicalOperator(PhysicalOperatorType::BATCH_CREATE_TABLE_AS, op.types, estimated_cardinality), insert_table(nullptr), schema(&schema), info(std::move(info_p)) { - PhysicalInsert::GetInsertInfo(*info, insert_types); + PhysicalInsert::GetInsertInfo(*info, insert_types, bound_defaults); } //===--------------------------------------------------------------------===// @@ -35,47 +38,38 @@ enum class RowGroupBatchType : uint8_t { FLUSHED, NOT_FLUSHED }; class CollectionMerger { public: - explicit CollectionMerger(ClientContext &context, DataTable &data_table) - : context(context), data_table(data_table), batch_type(RowGroupBatchType::NOT_FLUSHED) { + explicit CollectionMerger(ClientContext &context) : context(context) { } - //! The transaction context. ClientContext &context; - //! The data table. - DataTable &data_table; - //! Indexes to the optimistic row group collection vector of the local table storage for this transaction. - vector collection_indexes; - //! The batch type for merging collections. - RowGroupBatchType batch_type; + vector> current_collections; + RowGroupBatchType batch_type = RowGroupBatchType::NOT_FLUSHED; public: - void AddCollection(const PhysicalIndex collection_index, RowGroupBatchType type) { - collection_indexes.push_back(collection_index); + void AddCollection(unique_ptr collection, RowGroupBatchType type) { + current_collections.push_back(std::move(collection)); if (type == RowGroupBatchType::FLUSHED) { batch_type = RowGroupBatchType::FLUSHED; - if (collection_indexes.size() > 1) { + if (current_collections.size() > 1) { throw InternalException("Cannot merge flushed collections"); } } } bool Empty() { - return collection_indexes.empty(); + return current_collections.empty(); } - PhysicalIndex Flush(OptimisticDataWriter &writer) { + unique_ptr Flush(OptimisticDataWriter &writer) { if (Empty()) { - return PhysicalIndex(DConstants::INVALID_INDEX); + return nullptr; } - - auto result_collection_index = collection_indexes[0]; - auto &result_collection = data_table.GetOptimisticCollection(context, result_collection_index); - - if (collection_indexes.size() > 1) { - // Merge all collections into one result collection. - auto &types = result_collection.GetTypes(); + unique_ptr new_collection = std::move(current_collections[0]); + if (current_collections.size() > 1) { + // we have gathered multiple collections: create one big collection and merge that + auto &types = new_collection->GetTypes(); TableAppendState append_state; - result_collection.InitializeAppend(append_state); + new_collection->InitializeAppend(append_state); DataChunk scan_chunk; scan_chunk.Initialize(context, types); @@ -84,11 +78,13 @@ class CollectionMerger { for (idx_t i = 0; i < types.size(); i++) { column_ids.emplace_back(i); } - for (idx_t i = 1; i < collection_indexes.size(); i++) { - auto &collection = data_table.GetOptimisticCollection(context, collection_indexes[i]); + for (auto &collection : current_collections) { + if (!collection) { + continue; + } TableScanState scan_state; scan_state.Initialize(column_ids); - collection.InitializeScan(scan_state.local_state, column_ids, nullptr); + collection->InitializeScan(scan_state.local_state, column_ids, nullptr); while (true) { scan_chunk.Reset(); @@ -96,38 +92,35 @@ class CollectionMerger { if (scan_chunk.size() == 0) { break; } - auto new_row_group = result_collection.Append(scan_chunk, append_state); + auto new_row_group = new_collection->Append(scan_chunk, append_state); if (new_row_group) { - writer.WriteNewRowGroup(result_collection); + writer.WriteNewRowGroup(*new_collection); } } - data_table.ResetOptimisticCollection(context, collection_indexes[i]); } - result_collection.FinalizeAppend(TransactionData(0, 0), append_state); - writer.WriteLastRowGroup(result_collection); + new_collection->FinalizeAppend(TransactionData(0, 0), append_state); + writer.WriteLastRowGroup(*new_collection); } else if (batch_type == RowGroupBatchType::NOT_FLUSHED) { - writer.WriteLastRowGroup(result_collection); + writer.WriteLastRowGroup(*new_collection); } - - collection_indexes.clear(); - return result_collection_index; + current_collections.clear(); + return new_collection; } }; struct RowGroupBatchEntry { - RowGroupBatchEntry(RowGroupCollection &collection, const idx_t batch_idx, const PhysicalIndex collection_index, - const RowGroupBatchType type) - : batch_idx(batch_idx), total_rows(collection.GetTotalRows()), unflushed_memory(0), - collection_index(collection_index), type(type) { + RowGroupBatchEntry(idx_t batch_idx, unique_ptr collection_p, RowGroupBatchType type) + : batch_idx(batch_idx), total_rows(collection_p->GetTotalRows()), unflushed_memory(0), + collection(std::move(collection_p)), type(type) { if (type == RowGroupBatchType::NOT_FLUSHED) { - unflushed_memory = collection.GetAllocationSize(); + unflushed_memory = collection->GetAllocationSize(); } } idx_t batch_idx; idx_t total_rows; idx_t unflushed_memory; - PhysicalIndex collection_index; + unique_ptr collection; RowGroupBatchType type; }; @@ -145,7 +138,7 @@ class BatchInsertTask { class BatchInsertGlobalState : public GlobalSinkState { public: - BatchInsertGlobalState(ClientContext &context, DuckTableEntry &table, const idx_t minimum_memory_per_thread) + explicit BatchInsertGlobalState(ClientContext &context, DuckTableEntry &table, idx_t minimum_memory_per_thread) : memory_manager(context, minimum_memory_per_thread), table(table), insert_count(0), optimistically_written(false), minimum_memory_per_thread(minimum_memory_per_thread) { row_group_size = table.GetStorage().GetRowGroupSize(); @@ -162,14 +155,16 @@ class BatchInsertGlobalState : public GlobalSinkState { atomic optimistically_written; idx_t minimum_memory_per_thread; - bool ReadyToMerge(const idx_t count) const; - void ScheduleMergeTasks(ClientContext &context, const idx_t min_batch_index); - PhysicalIndex MergeCollections(ClientContext &context, const vector &merge_collections, - OptimisticDataWriter &writer); - void AddCollection(ClientContext &context, const idx_t batch_index, const idx_t min_batch_index, - const PhysicalIndex collection_index, optional_ptr writer = nullptr); + bool ReadyToMerge(idx_t count) const; + void ScheduleMergeTasks(idx_t min_batch_index); + unique_ptr MergeCollections(ClientContext &context, + vector merge_collections, + OptimisticDataWriter &writer); + void AddCollection(ClientContext &context, idx_t batch_index, idx_t min_batch_index, + unique_ptr current_collection, + optional_ptr writer = nullptr); - idx_t MaxThreads(const idx_t source_max_threads) override { + idx_t MaxThreads(idx_t source_max_threads) override { // try to request 4MB per column per thread memory_manager.SetMemorySize(source_max_threads * minimum_memory_per_thread); // cap the concurrent threads working on this task based on the amount of available memory @@ -179,29 +174,27 @@ class BatchInsertGlobalState : public GlobalSinkState { class BatchInsertLocalState : public LocalSinkState { public: - BatchInsertLocalState(ClientContext &context, const vector &types) - : collection_index(DConstants::INVALID_INDEX) { + BatchInsertLocalState(ClientContext &context, const vector &types, + const vector> &bound_defaults) + : default_executor(context, bound_defaults) { + insert_chunk.Initialize(Allocator::Get(context), types); } - idx_t current_index = 0; + DataChunk insert_chunk; + ExpressionExecutor default_executor; + idx_t current_index; TableAppendState current_append_state; - PhysicalIndex collection_index; - unique_ptr optimistic_writer; + unique_ptr current_collection; + optional_ptr writer; unique_ptr constraint_state; - void CreateNewCollection(ClientContext &context, DuckTableEntry &table_entry, - const vector &insert_types) { - auto table_info = table_entry.GetStorage().GetDataTableInfo(); - auto &io_manager = TableIOManager::Get(table_entry.GetStorage()); - - // Create the local row group collection. - auto max_row_id = NumericCast(MAX_ROW_ID); - auto collection = make_uniq(std::move(table_info), io_manager, insert_types, max_row_id); - collection->InitializeEmpty(); - collection->InitializeAppend(current_append_state); - - auto &data_table = table_entry.GetStorage(); - collection_index = data_table.CreateOptimisticCollection(context, std::move(collection)); + void CreateNewCollection(DuckTableEntry &table, const vector &insert_types) { + auto table_info = table.GetStorage().GetDataTableInfo(); + auto &io_manager = TableIOManager::Get(table.GetStorage()); + current_collection = make_uniq(std::move(table_info), io_manager, insert_types, + NumericCast(MAX_ROW_ID)); + current_collection->InitializeEmpty(); + current_collection->InitializeAppend(current_append_state); } }; @@ -217,31 +210,25 @@ class MergeCollectionTask : public BatchInsertTask { vector merge_collections; idx_t merged_batch_index; - void Execute(const PhysicalBatchInsert &op, ClientContext &context, GlobalSinkState &g_state_p, - LocalSinkState &l_state_p) override { - auto &g_state = g_state_p.Cast(); - auto &l_state = l_state_p.Cast(); - - // Merge the collections. - if (!l_state.optimistic_writer) { - l_state.optimistic_writer = make_uniq(g_state.table.GetStorage()); + void Execute(const PhysicalBatchInsert &op, ClientContext &context, GlobalSinkState &gstate_p, + LocalSinkState &lstate_p) override { + auto &gstate = gstate_p.Cast(); + auto &lstate = lstate_p.Cast(); + // merge together the collections + if (!lstate.writer) { + lstate.writer = &gstate.table.GetStorage().CreateOptimisticWriter(context); } - auto result_collection_index = g_state.MergeCollections(context, merge_collections, *l_state.optimistic_writer); - merge_collections.clear(); - - lock_guard l(g_state.lock); - auto &result_collection = g_state.table.GetStorage().GetOptimisticCollection(context, result_collection_index); - RowGroupBatchEntry new_entry(result_collection, merged_batch_index, result_collection_index, - RowGroupBatchType::FLUSHED); - - // Add the result collection to the set of batch indexes. + auto final_collection = gstate.MergeCollections(context, std::move(merge_collections), *lstate.writer); + // add the merged-together collection to the set of batch indexes + lock_guard l(gstate.lock); + RowGroupBatchEntry new_entry(merged_batch_index, std::move(final_collection), RowGroupBatchType::FLUSHED); auto it = std::lower_bound( - g_state.collections.begin(), g_state.collections.end(), new_entry, + gstate.collections.begin(), gstate.collections.end(), new_entry, [&](const RowGroupBatchEntry &a, const RowGroupBatchEntry &b) { return a.batch_idx < b.batch_idx; }); if (it->batch_idx != merged_batch_index) { throw InternalException("Merged batch index was no longer present in collection"); } - it->collection_index = new_entry.collection_index; + it->collection = std::move(new_entry.collection); } }; @@ -254,7 +241,7 @@ struct BatchMergeTask { idx_t total_count; }; -bool BatchInsertGlobalState::ReadyToMerge(const idx_t count) const { +bool BatchInsertGlobalState::ReadyToMerge(idx_t count) const { // we try to merge so the count fits nicely into row groups if (count >= row_group_size / 10 * 9 && count <= row_group_size) { // 90%-100% of row group size @@ -275,8 +262,9 @@ bool BatchInsertGlobalState::ReadyToMerge(const idx_t count) const { return false; } -void BatchInsertGlobalState::ScheduleMergeTasks(ClientContext &context, const idx_t min_batch_index) { +void BatchInsertGlobalState::ScheduleMergeTasks(idx_t min_batch_index) { idx_t current_idx; + vector to_be_scheduled_tasks; BatchMergeTask current_task(next_start); @@ -322,21 +310,19 @@ void BatchInsertGlobalState::ScheduleMergeTasks(ClientContext &context, const id for (auto &scheduled_task : to_be_scheduled_tasks) { D_ASSERT(scheduled_task.total_count > 0); D_ASSERT(current_idx > scheduled_task.start_index); - auto merged_batch_index = collections[scheduled_task.start_index].batch_idx; + idx_t merged_batch_index = collections[scheduled_task.start_index].batch_idx; vector merge_collections; for (idx_t idx = scheduled_task.start_index; idx < scheduled_task.end_index; idx++) { auto &entry = collections[idx]; - if (!entry.collection_index.IsValid() || entry.type == RowGroupBatchType::FLUSHED) { + if (!entry.collection || entry.type == RowGroupBatchType::FLUSHED) { throw InternalException("Adding a row group collection that should not be flushed"); } - auto &collection = table.GetStorage().GetOptimisticCollection(context, entry.collection_index); - RowGroupBatchEntry added_entry(collection, collections[scheduled_task.start_index].batch_idx, - entry.collection_index, RowGroupBatchType::FLUSHED); + RowGroupBatchEntry added_entry(collections[scheduled_task.start_index].batch_idx, + std::move(entry.collection), RowGroupBatchType::FLUSHED); added_entry.unflushed_memory = entry.unflushed_memory; - merge_collections.push_back(added_entry); + merge_collections.push_back(std::move(added_entry)); entry.total_rows = scheduled_task.total_count; entry.type = RowGroupBatchType::FLUSHED; - entry.collection_index = PhysicalIndex(DConstants::INVALID_INDEX); } task_manager.AddTask(make_uniq(std::move(merge_collections), merged_batch_index)); } @@ -351,14 +337,14 @@ void BatchInsertGlobalState::ScheduleMergeTasks(ClientContext &context, const id } } -PhysicalIndex BatchInsertGlobalState::MergeCollections(ClientContext &context, - const vector &merge_collections, - OptimisticDataWriter &writer) { +unique_ptr BatchInsertGlobalState::MergeCollections(ClientContext &context, + vector merge_collections, + OptimisticDataWriter &writer) { D_ASSERT(!merge_collections.empty()); - CollectionMerger merger(context, table.GetStorage()); + CollectionMerger merger(context); idx_t written_data = 0; for (auto &entry : merge_collections) { - merger.AddCollection(entry.collection_index, RowGroupBatchType::NOT_FLUSHED); + merger.AddCollection(std::move(entry.collection), RowGroupBatchType::NOT_FLUSHED); written_data += entry.unflushed_memory; } optimistically_written = true; @@ -366,23 +352,22 @@ PhysicalIndex BatchInsertGlobalState::MergeCollections(ClientContext &context, return merger.Flush(writer); } -void BatchInsertGlobalState::AddCollection(ClientContext &context, const idx_t batch_index, const idx_t min_batch_index, - const PhysicalIndex collection_index, +void BatchInsertGlobalState::AddCollection(ClientContext &context, idx_t batch_index, idx_t min_batch_index, + unique_ptr current_collection, optional_ptr writer) { if (batch_index < min_batch_index) { throw InternalException("Batch index of the added collection (%llu) is smaller than the min batch index (%llu)", batch_index, min_batch_index); } - auto &collection = table.GetStorage().GetOptimisticCollection(context, collection_index); - auto new_count = collection.GetTotalRows(); + auto new_count = current_collection->GetTotalRows(); auto batch_type = new_count < row_group_size ? RowGroupBatchType::NOT_FLUSHED : RowGroupBatchType::FLUSHED; if (batch_type == RowGroupBatchType::FLUSHED && writer) { - writer->WriteLastRowGroup(collection); + writer->WriteLastRowGroup(*current_collection); } lock_guard l(lock); insert_count += new_count; // add the collection to the batch index - RowGroupBatchEntry new_entry(collection, batch_index, collection_index, batch_type); + RowGroupBatchEntry new_entry(batch_index, std::move(current_collection), batch_type); if (batch_type == RowGroupBatchType::NOT_FLUSHED) { memory_manager.IncreaseUnflushedMemory(new_entry.unflushed_memory); } @@ -396,9 +381,9 @@ void BatchInsertGlobalState::AddCollection(ClientContext &context, const idx_t b "batch indexes are not uniquely distributed over threads", batch_index); } - collections.insert(it, new_entry); + collections.insert(it, std::move(new_entry)); if (writer) { - ScheduleMergeTasks(context, min_batch_index); + ScheduleMergeTasks(min_batch_index); } } @@ -426,7 +411,7 @@ unique_ptr PhysicalBatchInsert::GetGlobalSinkState(ClientContex } unique_ptr PhysicalBatchInsert::GetLocalSinkState(ExecutionContext &context) const { - return make_uniq(context.client, insert_types); + return make_uniq(context.client, insert_types, bound_defaults); } //===--------------------------------------------------------------------===// @@ -458,16 +443,15 @@ SinkNextBatchType PhysicalBatchInsert::NextBatch(ExecutionContext &context, Oper auto &memory_manager = gstate.memory_manager; auto batch_index = lstate.partition_info.batch_index.GetIndex(); - if (lstate.collection_index.IsValid()) { + if (lstate.current_collection) { if (lstate.current_index == batch_index) { throw InternalException("NextBatch called with the same batch index?"); } // batch index has changed: move the old collection to the global state and create a new collection TransactionData tdata(0, 0); - auto &collection = gstate.table.GetStorage().GetOptimisticCollection(context.client, lstate.collection_index); - collection.FinalizeAppend(tdata, lstate.current_append_state); + lstate.current_collection->FinalizeAppend(tdata, lstate.current_append_state); gstate.AddCollection(context.client, lstate.current_index, lstate.partition_info.min_batch_index.GetIndex(), - lstate.collection_index, lstate.optimistic_writer); + std::move(lstate.current_collection), lstate.writer); bool any_unblocked; { @@ -477,7 +461,7 @@ SinkNextBatchType PhysicalBatchInsert::NextBatch(ExecutionContext &context, Oper if (!any_unblocked) { ExecuteTasks(context.client, gstate, lstate); } - lstate.collection_index.index = DConstants::INVALID_INDEX; + lstate.current_collection.reset(); } lstate.current_index = batch_index; @@ -491,14 +475,13 @@ SinkNextBatchType PhysicalBatchInsert::NextBatch(ExecutionContext &context, Oper //===--------------------------------------------------------------------===// // Sink //===--------------------------------------------------------------------===// -SinkResultType PhysicalBatchInsert::Sink(ExecutionContext &context, DataChunk &insert_chunk, - OperatorSinkInput &input) const { +SinkResultType PhysicalBatchInsert::Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const { auto &gstate = input.global_state.Cast(); auto &lstate = input.local_state.Cast(); auto &memory_manager = gstate.memory_manager; auto &table = gstate.table; - insert_chunk.Flatten(); + PhysicalInsert::ResolveDefaults(table, chunk, column_index_map, lstate.default_executor, lstate.insert_chunk); auto batch_index = lstate.partition_info.batch_index.GetIndex(); // check if we should process this batch @@ -520,12 +503,12 @@ SinkResultType PhysicalBatchInsert::Sink(ExecutionContext &context, DataChunk &i } } } - if (!lstate.collection_index.IsValid()) { + if (!lstate.current_collection) { lock_guard l(gstate.lock); // no collection yet: create a new one - lstate.CreateNewCollection(context.client, table, insert_types); - if (!lstate.optimistic_writer) { - lstate.optimistic_writer = make_uniq(table.GetStorage()); + lstate.CreateNewCollection(table, insert_types); + if (!lstate.writer) { + lstate.writer = &table.GetStorage().CreateOptimisticWriter(context.client); } } @@ -540,14 +523,13 @@ SinkResultType PhysicalBatchInsert::Sink(ExecutionContext &context, DataChunk &i auto &storage = table.GetStorage(); auto &local_storage = LocalStorage::Get(context.client, storage.db); auto local_table_storage = local_storage.GetStorage(table.GetStorage()); - storage.VerifyAppendConstraints(*lstate.constraint_state, context.client, insert_chunk, local_table_storage, + storage.VerifyAppendConstraints(*lstate.constraint_state, context.client, lstate.insert_chunk, local_table_storage, nullptr); - auto &collection = table.GetStorage().GetOptimisticCollection(context.client, lstate.collection_index); - auto new_row_group = collection.Append(insert_chunk, lstate.current_append_state); + auto new_row_group = lstate.current_collection->Append(lstate.insert_chunk, lstate.current_append_state); if (new_row_group) { // we have already written to disk - flush the next row group as well - lstate.optimistic_writer->WriteNewRowGroup(collection); + lstate.writer->WriteNewRowGroup(*lstate.current_collection); } return SinkResultType::NEED_MORE_INPUT; } @@ -565,20 +547,17 @@ SinkCombineResultType PhysicalBatchInsert::Combine(ExecutionContext &context, Op memory_manager.UpdateMinBatchIndex(lstate.partition_info.min_batch_index.GetIndex()); - if (lstate.collection_index.IsValid()) { + if (lstate.current_collection) { TransactionData tdata(0, 0); - auto &collection = gstate.table.GetStorage().GetOptimisticCollection(context.client, lstate.collection_index); - collection.FinalizeAppend(tdata, lstate.current_append_state); - if (collection.GetTotalRows() > 0) { - auto batch_index = lstate.partition_info.min_batch_index.GetIndex(); - gstate.AddCollection(context.client, lstate.current_index, batch_index, lstate.collection_index); - lstate.collection_index = PhysicalIndex(DConstants::INVALID_INDEX); + lstate.current_collection->FinalizeAppend(tdata, lstate.current_append_state); + if (lstate.current_collection->GetTotalRows() > 0) { + gstate.AddCollection(context.client, lstate.current_index, lstate.partition_info.min_batch_index.GetIndex(), + std::move(lstate.current_collection)); } } - if (lstate.optimistic_writer) { + if (lstate.writer) { lock_guard l(gstate.lock); - auto &optimistic_writer = gstate.table.GetStorage().GetOptimisticWriter(context.client); - optimistic_writer.Merge(*lstate.optimistic_writer); + gstate.table.GetStorage().FinalizeOptimisticWriter(context.client, *lstate.writer); } // unblock any blocked tasks @@ -593,87 +572,75 @@ SinkCombineResultType PhysicalBatchInsert::Combine(ExecutionContext &context, Op //===--------------------------------------------------------------------===// SinkFinalizeType PhysicalBatchInsert::Finalize(Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const { - auto &g_state = input.global_state.Cast(); - auto &table = g_state.table; - auto &data_table = g_state.table.GetStorage(); - auto &memory_manager = g_state.memory_manager; + auto &gstate = input.global_state.Cast(); + auto &memory_manager = gstate.memory_manager; - if (g_state.optimistically_written || g_state.insert_count >= g_state.row_group_size) { + if (gstate.optimistically_written || gstate.insert_count >= gstate.row_group_size) { // we have written data to disk optimistically or are inserting a large amount of data // perform a final pass over all of the row groups and merge them together vector> mergers; unique_ptr current_merger; - for (auto &entry : g_state.collections) { + auto &storage = gstate.table.GetStorage(); + for (auto &entry : gstate.collections) { if (entry.type == RowGroupBatchType::NOT_FLUSHED) { // this collection has not been flushed: add it to the merge set if (!current_merger) { - current_merger = make_uniq(context, data_table); + current_merger = make_uniq(context); } - current_merger->AddCollection(entry.collection_index, entry.type); + current_merger->AddCollection(std::move(entry.collection), entry.type); memory_manager.ReduceUnflushedMemory(entry.unflushed_memory); - continue; - } - - // This collection has been flushed, so it does not need to be merged. - // Create a separate collection merger for it. - if (current_merger) { - // Flush any remaining small allocations. - mergers.push_back(std::move(current_merger)); - current_merger.reset(); + } else { + // this collection has been flushed: it does not need to be merged + // create a separate collection merger only for this entry + if (current_merger) { + // we have small collections remaining: flush them + mergers.push_back(std::move(current_merger)); + current_merger.reset(); + } + auto larger_merger = make_uniq(context); + larger_merger->AddCollection(std::move(entry.collection), entry.type); + mergers.push_back(std::move(larger_merger)); } - auto larger_merger = make_uniq(context, data_table); - larger_merger->AddCollection(entry.collection_index, entry.type); - mergers.push_back(std::move(larger_merger)); } - - g_state.collections.clear(); if (current_merger) { mergers.push_back(std::move(current_merger)); } // now that we have created all of the mergers, perform the actual merging - vector final_collections; + vector> final_collections; final_collections.reserve(mergers.size()); - auto writer = make_uniq(data_table); + auto &writer = storage.CreateOptimisticWriter(context); for (auto &merger : mergers) { - final_collections.push_back(merger->Flush(*writer)); + final_collections.push_back(merger->Flush(writer)); } // finally, merge the row groups into the local storage - for (const auto collection_index : final_collections) { - auto &collection = data_table.GetOptimisticCollection(context, collection_index); - data_table.LocalMerge(context, collection); - data_table.ResetOptimisticCollection(context, collection_index); + for (auto &collection : final_collections) { + storage.LocalMerge(context, *collection); } + storage.FinalizeOptimisticWriter(context, writer); + } else { + // we are writing a small amount of data to disk + // append directly to transaction local storage + auto &table = gstate.table; + auto &storage = table.GetStorage(); + LocalAppendState append_state; + storage.InitializeLocalAppend(append_state, table, context, bound_constraints); + auto &transaction = DuckTransaction::Get(context, table.catalog); + for (auto &entry : gstate.collections) { + if (entry.type != RowGroupBatchType::NOT_FLUSHED) { + throw InternalException("Encountered a flushed batch"); + } - auto &optimistic_writer = data_table.GetOptimisticWriter(context); - optimistic_writer.Merge(*writer); - memory_manager.FinalCheck(); - return SinkFinalizeType::READY; - } - - // We are writing a small amount of data to disk. - // Thus, we append directly to the transaction local storage. - LocalAppendState append_state; - data_table.InitializeLocalAppend(append_state, table, context, bound_constraints); - auto &transaction = DuckTransaction::Get(context, table.catalog); - for (auto &entry : g_state.collections) { - if (entry.type != RowGroupBatchType::NOT_FLUSHED) { - throw InternalException("Encountered a flushed batch"); + memory_manager.ReduceUnflushedMemory(entry.unflushed_memory); + entry.collection->Scan(transaction, [&](DataChunk &insert_chunk) { + storage.LocalAppend(append_state, context, insert_chunk, false); + return true; + }); } - - memory_manager.ReduceUnflushedMemory(entry.unflushed_memory); - auto &collection = data_table.GetOptimisticCollection(context, entry.collection_index); - collection.Scan(transaction, [&](DataChunk &insert_chunk) { - data_table.LocalAppend(append_state, context, insert_chunk, false); - return true; - }); - data_table.ResetOptimisticCollection(context, entry.collection_index); + storage.FinalizeLocalAppend(append_state); } - - g_state.collections.clear(); - data_table.FinalizeLocalAppend(append_state); memory_manager.FinalCheck(); return SinkFinalizeType::READY; } diff --git a/src/duckdb/src/execution/operator/persistent/physical_copy_database.cpp b/src/duckdb/src/execution/operator/persistent/physical_copy_database.cpp index f5c24bae5..7563bc016 100644 --- a/src/duckdb/src/execution/operator/persistent/physical_copy_database.cpp +++ b/src/duckdb/src/execution/operator/persistent/physical_copy_database.cpp @@ -73,8 +73,9 @@ SourceResultType PhysicalCopyDatabase::GetData(ExecutionContext &context, DataCh catalog.CreateIndex(context.client, create_info->Cast()); auto &create_index_info = create_info->Cast(); - auto &table_entry = - catalog.GetEntry(context.client, create_index_info.schema, create_index_info.table); + auto &catalog_table = catalog.GetEntry(context.client, CatalogType::TABLE_ENTRY, create_index_info.schema, + create_index_info.table); + auto &table_entry = catalog_table.Cast(); auto &data_table = table_entry.GetStorage(); IndexStorageInfo storage_info(create_index_info.index_name); diff --git a/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp b/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp index 0bd1d4089..fa85d670b 100644 --- a/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +++ b/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp @@ -47,13 +47,11 @@ using vector_of_value_map_t = unordered_map, T, VectorOfValuesHash class CopyToFunctionGlobalState : public GlobalSinkState { public: - explicit CopyToFunctionGlobalState(ClientContext &context) - : initialized(false), rows_copied(0), last_file_offset(0), - file_write_lock_if_rotating(make_uniq()) { + explicit CopyToFunctionGlobalState(ClientContext &context, unique_ptr global_state) + : rows_copied(0), last_file_offset(0), global_state(std::move(global_state)) { max_open_files = ClientConfig::GetConfig(context).partitioned_write_max_open_files; } StorageLock lock; - atomic initialized; atomic rows_copied; atomic last_file_offset; unique_ptr global_state; @@ -61,30 +59,10 @@ class CopyToFunctionGlobalState : public GlobalSinkState { unordered_set created_directories; //! shared state for HivePartitionedColumnData shared_ptr partition_state; - //! Written file info and stats - vector> written_files; + //! File names + vector file_names; //! Max open files idx_t max_open_files; - //! If rotate is true, this lock is used - unique_ptr file_write_lock_if_rotating; - - void Initialize(ClientContext &context, const PhysicalCopyToFile &op) { - if (initialized) { - return; - } - auto write_lock = lock.GetExclusiveLock(); - if (initialized) { - return; - } - // initialize writing to the file - global_state = op.function.copy_to_initialize_global(context, *op.bind_data, op.file_path); - auto written_file_info = AddFile(*write_lock, op.file_path, op.return_type); - if (written_file_info) { - op.function.copy_to_get_written_statistics(context, *op.bind_data, *global_state, - *written_file_info->file_stats); - } - initialized = true; - } void CreateDir(const string &dir_path, FileSystem &fs) { if (created_directories.find(dir_path) != created_directories.end()) { @@ -113,17 +91,9 @@ class CopyToFunctionGlobalState : public GlobalSinkState { return path; } - optional_ptr AddFile(const StorageLockKey &l, const string &file_name, - CopyFunctionReturnType return_type) { + void AddFileName(const StorageLockKey &l, const string &file_name) { D_ASSERT(l.GetType() == StorageLockType::EXCLUSIVE); - auto file_info = make_uniq(file_name); - optional_ptr result; - if (return_type == CopyFunctionReturnType::WRITTEN_FILE_STATISTICS) { - file_info->file_stats = make_uniq(); - result = file_info.get(); - } - written_files.push_back(std::move(file_info)); - return result; + file_names.emplace_back(file_name); } void FinalizePartition(ClientContext &context, const PhysicalCopyToFile &op, PartitionWriteInfo &info) { @@ -186,30 +156,12 @@ class CopyToFunctionGlobalState : public GlobalSinkState { full_path = op.filename_pattern.CreateFilename(fs, hive_path, op.file_extension, offset); } } - optional_ptr written_file_info; - if (op.return_type != CopyFunctionReturnType::CHANGED_ROWS) { - written_file_info = AddFile(*global_lock, full_path, op.return_type); + if (op.return_type == CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST) { + AddFileName(*global_lock, full_path); } // initialize writes auto info = make_uniq(); info->global_state = op.function.copy_to_initialize_global(context.client, *op.bind_data, full_path); - if (written_file_info) { - // set up the file stats for the copy - op.function.copy_to_get_written_statistics(context.client, *op.bind_data, *info->global_state, - *written_file_info->file_stats); - - // set the partition info - vector partition_keys; - vector partition_values; - for (idx_t i = 0; i < op.partition_columns.size(); i++) { - const auto &partition_col_name = op.names[op.partition_columns[i]]; - const auto &partition_value = values[i]; - partition_keys.emplace_back(partition_col_name); - partition_values.push_back(partition_value.DefaultCastAs(LogicalType::VARCHAR)); - } - written_file_info->partition_keys = Value::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR, - std::move(partition_keys), std::move(partition_values)); - } auto &result = *info; info->active_writes = 1; // store in active write map @@ -336,15 +288,10 @@ unique_ptr PhysicalCopyToFile::CreateFileState(ClientContext idx_t this_file_offset = g.last_file_offset++; auto &fs = FileSystem::GetFileSystem(context); string output_path(filename_pattern.CreateFilename(fs, file_path, file_extension, this_file_offset)); - optional_ptr written_file_info; - if (return_type != CopyFunctionReturnType::CHANGED_ROWS) { - written_file_info = g.AddFile(global_lock, output_path, return_type); + if (return_type == CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST) { + g.AddFileName(global_lock, output_path); } - auto result = function.copy_to_initialize_global(context, *bind_data, output_path); - if (written_file_info) { - function.copy_to_get_written_statistics(context, *bind_data, *result, *written_file_info->file_stats); - } - return result; + return function.copy_to_initialize_global(context, *bind_data, output_path); } unique_ptr PhysicalCopyToFile::GetLocalSinkState(ExecutionContext &context) const { @@ -422,7 +369,7 @@ unique_ptr PhysicalCopyToFile::GetGlobalSinkState(ClientContext CheckDirectory(fs, file_path, overwrite_mode); } - auto state = make_uniq(context); + auto state = make_uniq(context, nullptr); if (!per_thread_output && rotate) { auto global_lock = state->lock.GetExclusiveLock(); state->global_state = CreateFileState(context, *state, *global_lock); @@ -435,10 +382,13 @@ unique_ptr PhysicalCopyToFile::GetGlobalSinkState(ClientContext return std::move(state); } - auto state = make_uniq(context); - if (write_empty_file) { - // if we are writing the file also if it is empty - initialize now - state->Initialize(context, *this); + auto state = make_uniq( + context, function.copy_to_initialize_global(context, *bind_data, file_path)); + if (use_tmp_file) { + auto global_lock = state->lock.GetExclusiveLock(); + state->AddFileName(*global_lock, file_path); + } else { + state->file_names.emplace_back(file_path); } return std::move(state); } @@ -475,51 +425,10 @@ PhysicalCopyToFile::PhysicalCopyToFile(vector types, CopyFunction f function(std::move(function_p)), bind_data(std::move(bind_data)), parallel(false) { } -void PhysicalCopyToFile::WriteRotateInternal(ExecutionContext &context, GlobalSinkState &global_state, - const std::function &fun) const { - auto &g = global_state.Cast(); - - // Loop until we can write (synchronize using locks when using parallel writes to the same files and "rotate") - while (true) { - // Grab global lock and dereference the current file state (and corresponding lock) - auto global_guard = g.lock.GetExclusiveLock(); - auto &file_state = *g.global_state; - auto &file_lock = *g.file_write_lock_if_rotating; - if (rotate && function.rotate_next_file(file_state, *bind_data, file_size_bytes)) { - // Global state must be rotated. Move to local scope, create an new one, and immediately release global lock - auto owned_gstate = std::move(g.global_state); - g.global_state = CreateFileState(context.client, *sink_state, *global_guard); - auto owned_lock = std::move(g.file_write_lock_if_rotating); - g.file_write_lock_if_rotating = make_uniq(); - global_guard.reset(); - - // This thread now waits for the exclusive lock on this file while other threads complete their writes - // Note that new writes can still start, as there is already a new global state - auto file_guard = owned_lock->GetExclusiveLock(); - function.copy_to_finalize(context.client, *bind_data, *owned_gstate); - } else { - // Get shared file write lock while holding global lock, - // so file can't be rotated before we get the write lock - auto file_guard = file_lock.GetSharedLock(); - - // Because we got the shared lock on the file, we're sure that it will keep existing until we release it - global_guard.reset(); - - // Sink/Combine! - fun(file_state); - break; - } - } -} - SinkResultType PhysicalCopyToFile::Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const { auto &g = input.global_state.Cast(); auto &l = input.local_state.Cast(); - if (!write_empty_file) { - // if we are only writing the file when there are rows to write we need to initialize here - g.Initialize(context.client, *this); - } g.rows_copied += chunk.size(); if (partition_output) { @@ -547,9 +456,20 @@ SinkResultType PhysicalCopyToFile::Sink(ExecutionContext &context, DataChunk &ch return SinkResultType::NEED_MORE_INPUT; } - WriteRotateInternal(context, input.global_state, [&](GlobalFunctionData &gstate) { - function.copy_to_sink(context, *bind_data, gstate, *l.local_state, chunk); - }); + // FILE_SIZE_BYTES/rotate is set, but threads write to the same file, synchronize using lock + auto &gstate = g.global_state; + auto global_lock = g.lock.GetExclusiveLock(); + if (rotate && function.rotate_next_file(*gstate, *bind_data, file_size_bytes)) { + auto owned_gstate = std::move(gstate); + gstate = CreateFileState(context.client, *sink_state, *global_lock); + global_lock.reset(); + function.copy_to_finalize(context.client, *bind_data, *owned_gstate); + } else { + global_lock.reset(); + } + + global_lock = g.lock.GetSharedLock(); + function.copy_to_sink(context, *bind_data, *gstate, *l.local_state, chunk); return SinkResultType::NEED_MORE_INPUT; } @@ -569,10 +489,10 @@ SinkCombineResultType PhysicalCopyToFile::Combine(ExecutionContext &context, Ope function.copy_to_finalize(context.client, *bind_data, *l.global_state); } } else if (rotate) { - WriteRotateInternal(context, input.global_state, [&](GlobalFunctionData &gstate) { - function.copy_to_combine(context, *bind_data, gstate, *l.local_state); - }); - } else if (g.global_state) { + // File in global state may change with FILE_SIZE_BYTES/rotate, need to grab lock + auto lock = g.lock.GetSharedLock(); + function.copy_to_combine(context, *bind_data, *g.global_state, *l.local_state); + } else { function.copy_to_combine(context, *bind_data, *g.global_state, *l.local_state); } } @@ -580,8 +500,9 @@ SinkCombineResultType PhysicalCopyToFile::Combine(ExecutionContext &context, Ope return SinkCombineResultType::FINISHED; } -SinkFinalizeType PhysicalCopyToFile::FinalizeInternal(ClientContext &context, GlobalSinkState &global_state) const { - auto &gstate = global_state.Cast(); +SinkFinalizeType PhysicalCopyToFile::Finalize(Pipeline &pipeline, Event &event, ClientContext &context, + OperatorSinkFinalizeInput &input) const { + auto &gstate = input.global_state.Cast(); if (partition_output) { // finalize any outstanding partitions gstate.FinalizePartitions(context, *this); @@ -597,7 +518,7 @@ SinkFinalizeType PhysicalCopyToFile::FinalizeInternal(ClientContext &context, Gl } return SinkFinalizeType::READY; } - if (function.copy_to_finalize && gstate.global_state) { + if (function.copy_to_finalize) { function.copy_to_finalize(context, *bind_data, *gstate.global_state); if (use_tmp_file) { @@ -611,110 +532,23 @@ SinkFinalizeType PhysicalCopyToFile::FinalizeInternal(ClientContext &context, Gl return SinkFinalizeType::READY; } -SinkFinalizeType PhysicalCopyToFile::Finalize(Pipeline &pipeline, Event &event, ClientContext &context, - OperatorSinkFinalizeInput &input) const { - return FinalizeInternal(context, input.global_state); -} - //===--------------------------------------------------------------------===// // Source //===--------------------------------------------------------------------===// -class CopyToFileGlobalSourceState : public GlobalSourceState { -public: - CopyToFileGlobalSourceState() { - } - - idx_t offset = 0; - - idx_t MaxThreads() override { - return 1; - } -}; - -unique_ptr PhysicalCopyToFile::GetGlobalSourceState(ClientContext &context) const { - return make_uniq(); -} - -void PhysicalCopyToFile::ReturnStatistics(DataChunk &chunk, idx_t row_idx, CopyToFileInfo &info) { - auto &file_stats = *info.file_stats; - - // filename VARCHAR - chunk.SetValue(0, row_idx, info.file_path); - // count BIGINT - chunk.SetValue(1, row_idx, Value::UBIGINT(file_stats.row_count)); - // file size bytes BIGINT - chunk.SetValue(2, row_idx, Value::UBIGINT(file_stats.file_size_bytes)); - // footer size bytes BIGINT - chunk.SetValue(3, row_idx, file_stats.footer_size_bytes); - // column statistics map(varchar, map(varchar, varchar)) - map stats; - for (auto &entry : file_stats.column_statistics) { - map per_column_stats; - for (auto &stats_entry : entry.second) { - per_column_stats.insert(make_pair(stats_entry.first, stats_entry.second)); - } - vector stats_keys; - vector stats_values; - for (auto &stats_entry : per_column_stats) { - stats_keys.emplace_back(stats_entry.first); - stats_values.emplace_back(std::move(stats_entry.second)); - } - auto map_value = - Value::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR, std::move(stats_keys), std::move(stats_values)); - stats.insert(make_pair(entry.first, std::move(map_value))); - } - vector keys; - vector values; - for (auto &entry : stats) { - keys.emplace_back(entry.first); - values.emplace_back(std::move(entry.second)); - } - auto map_val_type = LogicalType::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR); - chunk.SetValue(4, row_idx, Value::MAP(LogicalType::VARCHAR, map_val_type, std::move(keys), std::move(values))); - - // partition_keys map(varchar, varchar) - chunk.SetValue(5, row_idx, info.partition_keys); -} - SourceResultType PhysicalCopyToFile::GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const { auto &g = sink_state->Cast(); - if (return_type == CopyFunctionReturnType::WRITTEN_FILE_STATISTICS) { - auto &source_state = input.global_state.Cast(); - idx_t next_end = MinValue(source_state.offset + STANDARD_VECTOR_SIZE, g.written_files.size()); - idx_t count = next_end - source_state.offset; - for (idx_t i = 0; i < count; i++) { - auto &file_entry = *g.written_files[source_state.offset + i]; - if (use_tmp_file) { - file_entry.file_path = GetNonTmpFile(context.client, file_entry.file_path); - } - ReturnStatistics(chunk, i, file_entry); - } - chunk.SetCardinality(count); - source_state.offset += count; - return source_state.offset < g.written_files.size() ? SourceResultType::HAVE_MORE_OUTPUT - : SourceResultType::FINISHED; - } chunk.SetCardinality(1); switch (return_type) { case CopyFunctionReturnType::CHANGED_ROWS: chunk.SetValue(0, 0, Value::BIGINT(NumericCast(g.rows_copied.load()))); break; - case CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST: { + case CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST: chunk.SetValue(0, 0, Value::BIGINT(NumericCast(g.rows_copied.load()))); - vector file_name_list; - for (auto &file_info : g.written_files) { - if (use_tmp_file) { - file_name_list.emplace_back(GetNonTmpFile(context.client, file_info->file_path)); - } else { - file_name_list.emplace_back(file_info->file_path); - } - } - chunk.SetValue(1, 0, Value::LIST(LogicalType::VARCHAR, std::move(file_name_list))); + chunk.SetValue(1, 0, Value::LIST(LogicalType::VARCHAR, g.file_names)); break; - } default: throw NotImplementedException("Unknown CopyFunctionReturnType"); } diff --git a/src/duckdb/src/execution/operator/persistent/physical_insert.cpp b/src/duckdb/src/execution/operator/persistent/physical_insert.cpp index 0ecec8f10..ced0850d9 100644 --- a/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +++ b/src/duckdb/src/execution/operator/persistent/physical_insert.cpp @@ -22,18 +22,18 @@ namespace duckdb { -PhysicalInsert::PhysicalInsert(vector types_p, TableCatalogEntry &table, - vector> bound_constraints_p, - vector> set_expressions, vector set_columns, - vector set_types, idx_t estimated_cardinality, bool return_chunk, - bool parallel, OnConflictAction action_type, - unique_ptr on_conflict_condition_p, - unique_ptr do_update_condition_p, unordered_set conflict_target_p, - vector columns_to_fetch_p, bool update_is_del_and_insert) - : PhysicalOperator(PhysicalOperatorType::INSERT, std::move(types_p), estimated_cardinality), insert_table(&table), - insert_types(table.GetTypes()), bound_constraints(std::move(bound_constraints_p)), return_chunk(return_chunk), - parallel(parallel), action_type(action_type), set_expressions(std::move(set_expressions)), - set_columns(std::move(set_columns)), set_types(std::move(set_types)), +PhysicalInsert::PhysicalInsert( + vector types_p, TableCatalogEntry &table, physical_index_vector_t column_index_map, + vector> bound_defaults, vector> bound_constraints_p, + vector> set_expressions, vector set_columns, vector set_types, + idx_t estimated_cardinality, bool return_chunk, bool parallel, OnConflictAction action_type, + unique_ptr on_conflict_condition_p, unique_ptr do_update_condition_p, + unordered_set conflict_target_p, vector columns_to_fetch_p, bool update_is_del_and_insert) + : PhysicalOperator(PhysicalOperatorType::INSERT, std::move(types_p), estimated_cardinality), + column_index_map(std::move(column_index_map)), insert_table(&table), insert_types(table.GetTypes()), + bound_defaults(std::move(bound_defaults)), bound_constraints(std::move(bound_constraints_p)), + return_chunk(return_chunk), parallel(parallel), action_type(action_type), + set_expressions(std::move(set_expressions)), set_columns(std::move(set_columns)), set_types(std::move(set_types)), on_conflict_condition(std::move(on_conflict_condition_p)), do_update_condition(std::move(do_update_condition_p)), conflict_target(std::move(conflict_target_p)), update_is_del_and_insert(update_is_del_and_insert) { @@ -59,13 +59,15 @@ PhysicalInsert::PhysicalInsert(LogicalOperator &op, SchemaCatalogEntry &schema, : PhysicalOperator(PhysicalOperatorType::CREATE_TABLE_AS, op.types, estimated_cardinality), insert_table(nullptr), return_chunk(false), schema(&schema), info(std::move(info_p)), parallel(parallel), action_type(OnConflictAction::THROW), update_is_del_and_insert(false) { - GetInsertInfo(*info, insert_types); + GetInsertInfo(*info, insert_types, bound_defaults); } -void PhysicalInsert::GetInsertInfo(const BoundCreateTableInfo &info, vector &insert_types) { +void PhysicalInsert::GetInsertInfo(const BoundCreateTableInfo &info, vector &insert_types, + vector> &bound_defaults) { auto &create_info = info.base->Cast(); for (auto &col : create_info.columns.Physical()) { insert_types.push_back(col.GetType()); + bound_defaults.push_back(make_uniq(Value(col.GetType()))); } } @@ -79,10 +81,12 @@ InsertGlobalState::InsertGlobalState(ClientContext &context, const vector &types, + const vector> &bound_defaults, const vector> &bound_constraints) - : collection_index(DConstants::INVALID_INDEX), bound_constraints(bound_constraints) { + : default_executor(context, bound_defaults), bound_constraints(bound_constraints) { auto &allocator = Allocator::Get(context); + insert_chunk.Initialize(allocator, types); update_chunk.Initialize(allocator, types); append_chunk.Initialize(allocator, types); } @@ -120,7 +124,40 @@ unique_ptr PhysicalInsert::GetGlobalSinkState(ClientContext &co } unique_ptr PhysicalInsert::GetLocalSinkState(ExecutionContext &context) const { - return make_uniq(context.client, insert_types, bound_constraints); + return make_uniq(context.client, insert_types, bound_defaults, bound_constraints); +} + +void PhysicalInsert::ResolveDefaults(const TableCatalogEntry &table, DataChunk &chunk, + const physical_index_vector_t &column_index_map, + ExpressionExecutor &default_executor, DataChunk &result) { + chunk.Flatten(); + default_executor.SetChunk(chunk); + + result.Reset(); + result.SetCardinality(chunk); + + if (!column_index_map.empty()) { + // columns specified by the user, use column_index_map + for (auto &col : table.GetColumns().Physical()) { + auto storage_idx = col.StorageOid(); + auto mapped_index = column_index_map[col.Physical()]; + if (mapped_index == DConstants::INVALID_INDEX) { + // insert default value + default_executor.ExecuteExpression(storage_idx, result.data[storage_idx]); + } else { + // get value from child chunk + D_ASSERT((idx_t)mapped_index < chunk.ColumnCount()); + D_ASSERT(result.data[storage_idx].GetType() == chunk.data[mapped_index].GetType()); + result.data[storage_idx].Reference(chunk.data[mapped_index]); + } + } + } else { + // no columns specified, just append directly + for (idx_t i = 0; i < result.ColumnCount(); i++) { + D_ASSERT(result.data[i].GetType() == chunk.data[i].GetType()); + result.data[i].Reference(chunk.data[i]); + } + } } bool AllConflictsMeetCondition(DataChunk &result) { @@ -515,14 +552,14 @@ static idx_t HandleInsertConflicts(TableCatalogEntry &table, ExecutionContext &c } idx_t PhysicalInsert::OnConflictHandling(TableCatalogEntry &table, ExecutionContext &context, InsertGlobalState &gstate, - InsertLocalState &lstate, DataChunk &insert_chunk) const { + InsertLocalState &lstate) const { auto &data_table = table.GetStorage(); auto &local_storage = LocalStorage::Get(context.client, data_table.db); if (action_type == OnConflictAction::THROW) { auto &constraint_state = lstate.GetConstraintState(data_table, table); auto storage = local_storage.GetStorage(data_table); - data_table.VerifyAppendConstraints(constraint_state, context.client, insert_chunk, storage, nullptr); + data_table.VerifyAppendConstraints(constraint_state, context.client, lstate.insert_chunk, storage, nullptr); return 0; } @@ -558,8 +595,8 @@ idx_t PhysicalInsert::OnConflictHandling(TableCatalogEntry &table, ExecutionCont }); } - auto inner_conflicts = CheckDistinctness(insert_chunk, conflict_info, matched_indexes); - idx_t count = insert_chunk.size(); + auto inner_conflicts = CheckDistinctness(lstate.insert_chunk, conflict_info, matched_indexes); + idx_t count = lstate.insert_chunk.size(); if (!inner_conflicts.empty()) { // We have at least one inner conflict, filter it out ManagedSelection sel_vec(count); @@ -594,33 +631,32 @@ idx_t PhysicalInsert::OnConflictHandling(TableCatalogEntry &table, ExecutionCont last_occurrences.Append(idx); } - lstate.update_chunk.Reference(insert_chunk); + lstate.update_chunk.Reference(lstate.insert_chunk); lstate.update_chunk.Slice(last_occurrences.Selection(), last_occurrences.Count()); lstate.update_chunk.SetCardinality(last_occurrences.Count()); } - insert_chunk.Slice(sel_vec.Selection(), sel_vec.Count()); - insert_chunk.SetCardinality(sel_vec.Count()); + lstate.insert_chunk.Slice(sel_vec.Selection(), sel_vec.Count()); + lstate.insert_chunk.SetCardinality(sel_vec.Count()); } // Check whether any conflicts arise, and if they all meet the conflict_target + condition // If that's not the case - We throw the first error idx_t updated_tuples = 0; - updated_tuples += HandleInsertConflicts(table, context, lstate, gstate, insert_chunk, *this); + updated_tuples += HandleInsertConflicts(table, context, lstate, gstate, lstate.insert_chunk, *this); // Also check the transaction-local storage+ART so we can detect conflicts within this transaction - updated_tuples += HandleInsertConflicts(table, context, lstate, gstate, insert_chunk, *this); + updated_tuples += HandleInsertConflicts(table, context, lstate, gstate, lstate.insert_chunk, *this); return updated_tuples; } -SinkResultType PhysicalInsert::Sink(ExecutionContext &context, DataChunk &insert_chunk, - OperatorSinkInput &input) const { +SinkResultType PhysicalInsert::Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const { auto &gstate = input.global_state.Cast(); auto &lstate = input.local_state.Cast(); auto &table = gstate.table; auto &storage = table.GetStorage(); - insert_chunk.Flatten(); + PhysicalInsert::ResolveDefaults(table, chunk, column_index_map, lstate.default_executor, lstate.insert_chunk); if (!parallel) { if (!gstate.initialized) { @@ -628,49 +664,43 @@ SinkResultType PhysicalInsert::Sink(ExecutionContext &context, DataChunk &insert gstate.initialized = true; } - idx_t updated_tuples = OnConflictHandling(table, context, gstate, lstate, insert_chunk); + idx_t updated_tuples = OnConflictHandling(table, context, gstate, lstate); - gstate.insert_count += insert_chunk.size(); + gstate.insert_count += lstate.insert_chunk.size(); gstate.insert_count += updated_tuples; - if (return_chunk) { - gstate.return_collection.Append(insert_chunk); + if (!parallel && return_chunk) { + gstate.return_collection.Append(lstate.insert_chunk); } - storage.LocalAppend(gstate.append_state, context.client, insert_chunk, true); + storage.LocalAppend(gstate.append_state, context.client, lstate.insert_chunk, true); if (action_type == OnConflictAction::UPDATE && lstate.update_chunk.size() != 0) { (void)HandleInsertConflicts(table, context, lstate, gstate, lstate.update_chunk, *this); (void)HandleInsertConflicts(table, context, lstate, gstate, lstate.update_chunk, *this); // All of the tuples should have been turned into an update, leaving the chunk empty afterwards D_ASSERT(lstate.update_chunk.size() == 0); } - return SinkResultType::NEED_MORE_INPUT; - } - - // Parallel append. - D_ASSERT(!return_chunk); - auto &data_table = gstate.table.GetStorage(); - if (!lstate.collection_index.IsValid()) { - auto table_info = storage.GetDataTableInfo(); - auto &io_manager = TableIOManager::Get(table.GetStorage()); - - // Create the local row group collection. - auto max_row_id = NumericCast(MAX_ROW_ID); - auto collection = make_uniq(std::move(table_info), io_manager, insert_types, max_row_id); - collection->InitializeEmpty(); - collection->InitializeAppend(lstate.local_append_state); + } else { + //! FIXME: can't we enable this by using a BatchedDataCollection ? + D_ASSERT(!return_chunk); + // parallel append + if (!lstate.local_collection) { + lock_guard l(gstate.lock); + auto table_info = storage.GetDataTableInfo(); + auto &io_manager = TableIOManager::Get(table.GetStorage()); + lstate.local_collection = make_uniq(std::move(table_info), io_manager, insert_types, + NumericCast(MAX_ROW_ID)); + lstate.local_collection->InitializeEmpty(); + lstate.local_collection->InitializeAppend(lstate.local_append_state); + lstate.writer = &gstate.table.GetStorage().CreateOptimisticWriter(context.client); + } + OnConflictHandling(table, context, gstate, lstate); + D_ASSERT(action_type != OnConflictAction::UPDATE); - lock_guard l(gstate.lock); - lstate.optimistic_writer = make_uniq(data_table); - lstate.collection_index = data_table.CreateOptimisticCollection(context.client, std::move(collection)); + auto new_row_group = lstate.local_collection->Append(lstate.insert_chunk, lstate.local_append_state); + if (new_row_group) { + lstate.writer->WriteNewRowGroup(*lstate.local_collection); + } } - OnConflictHandling(table, context, gstate, lstate, insert_chunk); - D_ASSERT(action_type != OnConflictAction::UPDATE); - - auto &collection = data_table.GetOptimisticCollection(context.client, lstate.collection_index); - auto new_row_group = collection.Append(insert_chunk, lstate.local_append_state); - if (new_row_group) { - lstate.optimistic_writer->WriteNewRowGroup(collection); - } return SinkResultType::NEED_MORE_INPUT; } @@ -681,7 +711,7 @@ SinkCombineResultType PhysicalInsert::Combine(ExecutionContext &context, Operato context.thread.profiler.Flush(*this); client_profiler.Flush(context.thread.profiler); - if (!parallel || !lstate.collection_index.IsValid()) { + if (!parallel || !lstate.local_collection) { return SinkCombineResultType::FINISHED; } @@ -691,11 +721,9 @@ SinkCombineResultType PhysicalInsert::Combine(ExecutionContext &context, Operato // parallel append: finalize the append TransactionData tdata(0, 0); - auto &data_table = gstate.table.GetStorage(); - auto &collection = data_table.GetOptimisticCollection(context.client, lstate.collection_index); - collection.FinalizeAppend(tdata, lstate.local_append_state); + lstate.local_collection->FinalizeAppend(tdata, lstate.local_append_state); - auto append_count = collection.GetTotalRows(); + auto append_count = lstate.local_collection->GetTotalRows(); lock_guard lock(gstate.lock); gstate.insert_count += append_count; @@ -703,18 +731,17 @@ SinkCombineResultType PhysicalInsert::Combine(ExecutionContext &context, Operato // we have few rows - append to the local storage directly storage.InitializeLocalAppend(gstate.append_state, table, context.client, bound_constraints); auto &transaction = DuckTransaction::Get(context.client, table.catalog); - collection.Scan(transaction, [&](DataChunk &insert_chunk) { + lstate.local_collection->Scan(transaction, [&](DataChunk &insert_chunk) { storage.LocalAppend(gstate.append_state, context.client, insert_chunk, false); return true; }); storage.FinalizeLocalAppend(gstate.append_state); } else { // we have written rows to disk optimistically - merge directly into the transaction-local storage - lstate.optimistic_writer->WriteLastRowGroup(collection); - lstate.optimistic_writer->FinalFlush(); - gstate.table.GetStorage().LocalMerge(context.client, collection); - auto &optimistic_writer = gstate.table.GetStorage().GetOptimisticWriter(context.client); - optimistic_writer.Merge(*lstate.optimistic_writer); + lstate.writer->WriteLastRowGroup(*lstate.local_collection); + lstate.writer->FinalFlush(); + gstate.table.GetStorage().LocalMerge(context.client, *lstate.local_collection); + gstate.table.GetStorage().FinalizeOptimisticWriter(context.client, *lstate.writer); } return SinkCombineResultType::FINISHED; diff --git a/src/duckdb/src/execution/operator/projection/physical_pivot.cpp b/src/duckdb/src/execution/operator/projection/physical_pivot.cpp index 005ac4b49..d3def4c0c 100644 --- a/src/duckdb/src/execution/operator/projection/physical_pivot.cpp +++ b/src/duckdb/src/execution/operator/projection/physical_pivot.cpp @@ -3,10 +3,11 @@ namespace duckdb { -PhysicalPivot::PhysicalPivot(vector types_p, PhysicalOperator &child, BoundPivotInfo bound_pivot_p) - : PhysicalOperator(PhysicalOperatorType::PIVOT, std::move(types_p), child.estimated_cardinality), +PhysicalPivot::PhysicalPivot(vector types_p, unique_ptr child, + BoundPivotInfo bound_pivot_p) + : PhysicalOperator(PhysicalOperatorType::PIVOT, std::move(types_p), child->estimated_cardinality), bound_pivot(std::move(bound_pivot_p)) { - children.push_back(child); + children.push_back(std::move(child)); for (idx_t p = 0; p < bound_pivot.pivot_values.size(); p++) { auto entry = pivot_map.find(bound_pivot.pivot_values[p]); if (entry != pivot_map.end()) { diff --git a/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp b/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp index d9096f798..fa150693e 100644 --- a/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp +++ b/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp @@ -39,7 +39,7 @@ unique_ptr PhysicalTableInOutFunction::GetOperatorState(Execution } if (!projected_input.empty()) { vector input_types; - auto &child_types = children[0].get().GetTypes(); + auto &child_types = children[0]->types; idx_t input_length = child_types.size() - projected_input.size(); for (idx_t k = 0; k < input_length; k++) { input_types.push_back(child_types[k]); diff --git a/src/duckdb/src/execution/operator/projection/physical_unnest.cpp b/src/duckdb/src/execution/operator/projection/physical_unnest.cpp index 5a08173c9..4f32fd291 100644 --- a/src/duckdb/src/execution/operator/projection/physical_unnest.cpp +++ b/src/duckdb/src/execution/operator/projection/physical_unnest.cpp @@ -12,7 +12,8 @@ namespace duckdb { class UnnestOperatorState : public OperatorState { public: UnnestOperatorState(ClientContext &context, const vector> &select_list) - : current_row(0), list_position(0), first_fetch(true), input_sel(STANDARD_VECTOR_SIZE), executor(context) { + : current_row(0), list_position(0), longest_list_length(DConstants::INVALID_INDEX), first_fetch(true), + executor(context) { // for each UNNEST in the select_list, we add the child expression to the expression executor // and set the return type in the list_data chunk, which will contain the evaluated expression results @@ -22,11 +23,7 @@ class UnnestOperatorState : public OperatorState { auto &bue = exp->Cast(); list_data_types.push_back(bue.child->return_type); executor.AddExpression(*bue.child.get()); - - unnest_sels.emplace_back(STANDARD_VECTOR_SIZE); - null_sels.emplace_back(STANDARD_VECTOR_SIZE); } - null_counts.resize(list_data_types.size()); auto &allocator = Allocator::Get(context); list_data.Initialize(allocator, list_data_types); @@ -37,12 +34,8 @@ class UnnestOperatorState : public OperatorState { idx_t current_row; idx_t list_position; - unsafe_vector unnest_lengths; + idx_t longest_list_length; bool first_fetch; - SelectionVector input_sel; - vector unnest_sels; - vector null_sels; - vector null_counts; ExpressionExecutor executor; DataChunk list_data; @@ -52,76 +45,224 @@ class UnnestOperatorState : public OperatorState { public: //! Reset the fields of the unnest operator state void Reset(); - //! Prepare the input for the next unnest - void PrepareInput(DataChunk &input, const vector> &select_list); + //! Set the longest list's length for the current row + void SetLongestListLength(); }; void UnnestOperatorState::Reset() { current_row = 0; list_position = 0; + longest_list_length = DConstants::INVALID_INDEX; first_fetch = true; } +void UnnestOperatorState::SetLongestListLength() { + longest_list_length = 0; + for (idx_t col_idx = 0; col_idx < list_data.ColumnCount(); col_idx++) { + + auto &vector_data = list_vector_data[col_idx]; + auto current_idx = vector_data.sel->get_index(current_row); + + if (vector_data.validity.RowIsValid(current_idx)) { + + // check if this list is longer + auto list_data_entries = UnifiedVectorFormat::GetData(vector_data); + auto list_entry = list_data_entries[current_idx]; + if (list_entry.length > longest_list_length) { + longest_list_length = list_entry.length; + } + } + } +} + PhysicalUnnest::PhysicalUnnest(vector types, vector> select_list, idx_t estimated_cardinality, PhysicalOperatorType type) : PhysicalOperator(type, std::move(types), estimated_cardinality), select_list(std::move(select_list)) { D_ASSERT(!this->select_list.empty()); } -void UnnestOperatorState::PrepareInput(DataChunk &input, const vector> &select_list) { - list_data.Reset(); +static void UnnestNull(idx_t start, idx_t end, Vector &result) { + + D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR); + auto &validity = FlatVector::Validity(result); + for (idx_t i = start; i < end; i++) { + validity.SetInvalid(i); + } + + const auto &logical_type = result.GetType(); + if (logical_type.InternalType() == PhysicalType::STRUCT) { + const auto &struct_children = StructVector::GetEntries(result); + for (auto &child : struct_children) { + UnnestNull(start, end, *child); + } + } else if (logical_type.InternalType() == PhysicalType::ARRAY) { + auto &array_child = ArrayVector::GetEntry(result); + auto array_size = ArrayType::GetSize(logical_type); + UnnestNull(start * array_size, end * array_size, array_child); + } +} + +template +static void TemplatedUnnest(UnifiedVectorFormat &vector_data, idx_t start, idx_t end, Vector &result) { + + auto source_data = UnifiedVectorFormat::GetData(vector_data); + auto &source_mask = vector_data.validity; + + D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR); + auto result_data = FlatVector::GetData(result); + auto &result_mask = FlatVector::Validity(result); + + for (idx_t i = start; i < end; i++) { + auto source_idx = vector_data.sel->get_index(i); + auto target_idx = i - start; + if (source_mask.RowIsValid(source_idx)) { + result_data[target_idx] = source_data[source_idx]; + result_mask.SetValid(target_idx); + } else { + result_mask.SetInvalid(target_idx); + } + } +} + +static void UnnestValidity(UnifiedVectorFormat &vector_data, idx_t start, idx_t end, Vector &result) { + + auto &source_mask = vector_data.validity; + D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR); + auto &result_mask = FlatVector::Validity(result); + + for (idx_t i = start; i < end; i++) { + auto source_idx = vector_data.sel->get_index(i); + auto target_idx = i - start; + result_mask.Set(target_idx, source_mask.RowIsValid(source_idx)); + } +} + +static void UnnestVector(UnifiedVectorFormat &child_vector_data, Vector &child_vector, idx_t list_size, idx_t start, + idx_t end, Vector &result) { + + D_ASSERT(child_vector.GetType() == result.GetType()); + switch (result.GetType().InternalType()) { + case PhysicalType::BOOL: + case PhysicalType::INT8: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::INT16: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::INT32: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::INT64: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::INT128: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::UINT8: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::UINT16: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::UINT32: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::UINT64: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::UINT128: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::FLOAT: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::DOUBLE: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::INTERVAL: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::VARCHAR: + TemplatedUnnest(child_vector_data, start, end, result); + break; + case PhysicalType::LIST: { + // the child vector of result now references the child vector source + // FIXME: only reference relevant children (start - end) instead of all + auto &target = ListVector::GetEntry(result); + target.Reference(ListVector::GetEntry(child_vector)); + ListVector::SetListSize(result, ListVector::GetListSize(child_vector)); + // unnest + TemplatedUnnest(child_vector_data, start, end, result); + break; + } + case PhysicalType::STRUCT: { + auto &child_vector_entries = StructVector::GetEntries(child_vector); + auto &result_entries = StructVector::GetEntries(result); + + // set the validity mask for the 'outer' struct vector before unnesting its children + UnnestValidity(child_vector_data, start, end, result); + + for (idx_t i = 0; i < child_vector_entries.size(); i++) { + UnifiedVectorFormat child_vector_entries_data; + child_vector_entries[i]->ToUnifiedFormat(list_size, child_vector_entries_data); + UnnestVector(child_vector_entries_data, *child_vector_entries[i], list_size, start, end, + *result_entries[i]); + } + break; + } + case PhysicalType::ARRAY: { + auto array_size = ArrayType::GetSize(child_vector.GetType()); + auto &source_array = ArrayVector::GetEntry(child_vector); + auto &target_array = ArrayVector::GetEntry(result); + + UnnestValidity(child_vector_data, start, end, result); + + UnifiedVectorFormat child_array_data; + source_array.ToUnifiedFormat(list_size * array_size, child_array_data); + UnnestVector(child_array_data, source_array, list_size * array_size, start * array_size, end * array_size, + target_array); + break; + } + default: + throw InternalException("Unimplemented type for UNNEST."); + } +} + +static void PrepareInput(UnnestOperatorState &state, DataChunk &input, + const vector> &select_list) { + + state.list_data.Reset(); // execute the expressions inside each UNNEST in the select_list to get the list data - // execution results (lists) are kept in list_data chunk - executor.Execute(input, list_data); + // execution results (lists) are kept in state.list_data chunk + state.executor.Execute(input, state.list_data); // verify incoming lists - list_data.Verify(); - D_ASSERT(input.size() == list_data.size()); - D_ASSERT(list_data.ColumnCount() == select_list.size()); - D_ASSERT(list_vector_data.size() == list_data.ColumnCount()); - D_ASSERT(list_child_data.size() == list_data.ColumnCount()); + state.list_data.Verify(); + D_ASSERT(input.size() == state.list_data.size()); + D_ASSERT(state.list_data.ColumnCount() == select_list.size()); + D_ASSERT(state.list_vector_data.size() == state.list_data.ColumnCount()); + D_ASSERT(state.list_child_data.size() == state.list_data.ColumnCount()); // get the UnifiedVectorFormat of each list_data vector (LIST vectors for the different UNNESTs) // both for the vector itself and its child vector - for (idx_t col_idx = 0; col_idx < list_data.ColumnCount(); col_idx++) { - auto &list_vector = list_data.data[col_idx]; - list_vector.ToUnifiedFormat(list_data.size(), list_vector_data[col_idx]); + for (idx_t col_idx = 0; col_idx < state.list_data.ColumnCount(); col_idx++) { + + auto &list_vector = state.list_data.data[col_idx]; + list_vector.ToUnifiedFormat(state.list_data.size(), state.list_vector_data[col_idx]); if (list_vector.GetType() == LogicalType::SQLNULL) { // UNNEST(NULL): SQLNULL vectors don't have child vectors, but we need to point to the child vector of // each vector, so we just get the UnifiedVectorFormat of the vector itself auto &child_vector = list_vector; - child_vector.ToUnifiedFormat(0, list_child_data[col_idx]); + child_vector.ToUnifiedFormat(0, state.list_child_data[col_idx]); } else { auto list_size = ListVector::GetListSize(list_vector); auto &child_vector = ListVector::GetEntry(list_vector); - child_vector.ToUnifiedFormat(list_size, list_child_data[col_idx]); - } - } - // get the unnest lengths - if (list_data.size() > unnest_lengths.size()) { - unnest_lengths.resize(list_data.size()); - } - for (idx_t r = 0; r < list_data.size(); r++) { - unnest_lengths[r] = 0; - } - for (idx_t col_idx = 0; col_idx < list_data.ColumnCount(); col_idx++) { - auto &vector_data = list_vector_data[col_idx]; - for (idx_t r = 0; r < list_data.size(); r++) { - auto current_idx = vector_data.sel->get_index(r); - if (!vector_data.validity.RowIsValid(current_idx)) { - continue; - } - // check if this list is longer than the current unnest length - auto list_data_entries = UnifiedVectorFormat::GetData(vector_data); - auto list_entry = list_data_entries[current_idx]; - if (list_entry.length > unnest_lengths[r]) { - unnest_lengths[r] = list_entry.length; - } + child_vector.ToUnifiedFormat(list_size, state.list_child_data[col_idx]); } } - first_fetch = false; + state.first_fetch = false; } unique_ptr PhysicalUnnest::GetOperatorState(ExecutionContext &context) const { @@ -141,10 +282,15 @@ OperatorResultType PhysicalUnnest::ExecuteInternal(ExecutionContext &context, Da auto &state = state_p.Cast(); do { + // reset validities, if previous loop iteration contained UNNEST(NULL) + if (include_input) { + chunk.Reset(); + } + // prepare the input data by executing any expressions and getting the // UnifiedVectorFormat of each LIST vector (list_vector_data) and its child vector (list_child_data) if (state.first_fetch) { - state.PrepareInput(input, select_list); + PrepareInput(state, input, select_list); } // finished with all rows of this input chunk, reset @@ -153,105 +299,82 @@ OperatorResultType PhysicalUnnest::ExecuteInternal(ExecutionContext &context, Da return OperatorResultType::NEED_MORE_INPUT; } - // we essentially create two different SelectionVectors to slice - // one is for the input (if include_input is set) - // the other is for the list we are unnesting - // construct these - idx_t result_length = 0; - idx_t unnest_list_count = 0; - auto initial_row = state.current_row; - for (idx_t col_idx = 0; col_idx < state.list_data.ColumnCount(); col_idx++) { - state.null_counts[col_idx] = 0; - } - while (result_length < STANDARD_VECTOR_SIZE && state.current_row < input.size()) { - auto current_row_length = MinValue(STANDARD_VECTOR_SIZE - result_length, - state.unnest_lengths[state.current_row] - state.list_position); - - if (current_row_length > 0) { - // set up the selection vectors - if (include_input) { - for (idx_t r = 0; r < current_row_length; r++) { - state.input_sel.set_index(result_length + r, state.current_row); - } - } - for (idx_t col_idx = 0; col_idx < state.list_data.ColumnCount(); col_idx++) { - auto &vector_data = state.list_vector_data[col_idx]; - auto current_idx = vector_data.sel->get_index(state.current_row); - idx_t list_length = 0; - idx_t list_offset = 0; - if (vector_data.validity.RowIsValid(current_idx)) { - auto list_data = UnifiedVectorFormat::GetData(vector_data); - auto list_entry = list_data[current_idx]; - list_length = list_entry.length; - list_offset = list_entry.offset; - } - // unnest any entries we can - idx_t unnest_length = MinValue( - list_length - MinValue(list_length, state.list_position), current_row_length); - auto &unnest_sel = state.unnest_sels[col_idx]; - for (idx_t r = 0; r < unnest_length; r++) { - unnest_sel.set_index(result_length + r, list_offset + state.list_position + r); - } - // for any remaining entries (if any) - set them in the null selection - auto &null_sel = state.null_sels[col_idx]; - for (idx_t r = unnest_length; r < current_row_length; r++) { - // we unnest the first row in the child list - // this is chosen arbitrarily - we will override it with `NULL` afterwards - // FIXME if the child list has a `NULL` entry we can directly unnest that and avoid having - // to override it - this is a potential optimization we could do in the future - unnest_sel.set_index(result_length + r, 0); - null_sel.set_index(state.null_counts[col_idx]++, result_length + r); - } - } - - // move to the next row - result_length += current_row_length; - state.list_position += current_row_length; - } - unnest_list_count++; - if (state.list_position == state.unnest_lengths[state.current_row]) { - state.current_row++; - state.list_position = 0; - } + // each UNNEST in the select_list contains a list (or NULL) for this row, find the longest list + // because this length determines how many times we need to repeat for the current row + if (state.longest_list_length == DConstants::INVALID_INDEX) { + state.SetLongestListLength(); } + D_ASSERT(state.longest_list_length != DConstants::INVALID_INDEX); + + // we emit chunks of either STANDARD_VECTOR_SIZE or smaller + auto this_chunk_len = MinValue(STANDARD_VECTOR_SIZE, state.longest_list_length - state.list_position); + chunk.SetCardinality(this_chunk_len); + + // if we include other projection input columns, e.g. SELECT 1, UNNEST([1, 2]);, then + // we need to add them as a constant vector to the resulting chunk + // FIXME: emit multiple unnested rows. Currently, we never emit a chunk containing multiple unnested input rows, + // so setting a constant vector for the value at state.current_row is fine idx_t col_offset = 0; - chunk.SetCardinality(result_length); if (include_input) { for (idx_t col_idx = 0; col_idx < input.ColumnCount(); col_idx++) { - if (unnest_list_count == 1) { - // everything belongs to the same row - we can do a constant reference - ConstantVector::Reference(chunk.data[col_idx], input.data[col_idx], initial_row, input.size()); - } else { - // input values come from different rows - we need to slice - chunk.data[col_idx].Slice(input.data[col_idx], state.input_sel, result_length); - } + ConstantVector::Reference(chunk.data[col_idx], input.data[col_idx], state.current_row, input.size()); } col_offset = input.ColumnCount(); } + + // unnest the lists for (idx_t col_idx = 0; col_idx < state.list_data.ColumnCount(); col_idx++) { - auto &list_vector = state.list_data.data[col_idx]; - auto &result_vector = chunk.data[col_offset + col_idx]; - if (state.list_data.data[col_idx].GetType() == LogicalType::SQLNULL || - ListType::GetChildType(state.list_data.data[col_idx].GetType()) == LogicalType::SQLNULL || - ListVector::GetListSize(list_vector) == 0) { - // UNNEST(NULL) or UNNEST([]) - // we cannot slice empty lists - but if our child list is empty we can only return NULL anyway - result_vector.SetVectorType(VectorType::CONSTANT_VECTOR); - ConstantVector::SetNull(result_vector, true); + + auto &result_vector = chunk.data[col_idx + col_offset]; + + if (state.list_data.data[col_idx].GetType() == LogicalType::SQLNULL) { + // UNNEST(NULL) + chunk.SetCardinality(0); + break; + } + + auto &vector_data = state.list_vector_data[col_idx]; + auto current_idx = vector_data.sel->get_index(state.current_row); + + if (!vector_data.validity.RowIsValid(current_idx)) { + UnnestNull(0, this_chunk_len, result_vector); continue; } - auto &child_vector = ListVector::GetEntry(list_vector); - result_vector.Slice(child_vector, state.unnest_sels[col_idx], result_length); - if (state.null_counts[col_idx] > 0) { - // we have NULL values that we need to set - flatten - result_vector.Flatten(result_length); - auto &null_sel = state.null_sels[col_idx]; - for (idx_t idx = 0; idx < state.null_counts[col_idx]; idx++) { - auto null_index = null_sel.get_index(idx); - FlatVector::SetNull(result_vector, null_index, true); - } + + auto list_data = UnifiedVectorFormat::GetData(vector_data); + auto list_entry = list_data[current_idx]; + + idx_t list_count = 0; + if (state.list_position < list_entry.length) { + // there are still list_count elements to unnest + list_count = MinValue(this_chunk_len, list_entry.length - state.list_position); + + auto &list_vector = state.list_data.data[col_idx]; + auto &child_vector = ListVector::GetEntry(list_vector); + auto list_size = ListVector::GetListSize(list_vector); + auto &child_vector_data = state.list_child_data[col_idx]; + + auto base_offset = list_entry.offset + state.list_position; + UnnestVector(child_vector_data, child_vector, list_size, base_offset, base_offset + list_count, + result_vector); + } + + // fill the rest with NULLs + if (list_count != this_chunk_len) { + UnnestNull(list_count, this_chunk_len, result_vector); } } + + chunk.Verify(); + + state.list_position += this_chunk_len; + if (state.list_position == state.longest_list_length) { + state.current_row++; + state.longest_list_length = DConstants::INVALID_INDEX; + state.list_position = 0; + } + + // we only emit one unnested row (that contains data) at a time } while (chunk.size() == 0); return OperatorResultType::HAVE_MORE_OUTPUT; } diff --git a/src/duckdb/src/execution/operator/scan/physical_column_data_scan.cpp b/src/duckdb/src/execution/operator/scan/physical_column_data_scan.cpp index 1e4f1b5c6..e864f3a2e 100644 --- a/src/duckdb/src/execution/operator/scan/physical_column_data_scan.cpp +++ b/src/duckdb/src/execution/operator/scan/physical_column_data_scan.cpp @@ -78,7 +78,7 @@ void PhysicalColumnDataScan::BuildPipelines(Pipeline ¤t, MetaPipeline &met delim_sink->type == PhysicalOperatorType::RIGHT_DELIM_JOIN); auto &delim_join = delim_sink->Cast(); current.AddDependency(delim_dependency); - state.SetPipelineSource(current, delim_join.distinct.Cast()); + state.SetPipelineSource(current, delim_join.distinct->Cast()); return; } case PhysicalOperatorType::CTE_SCAN: { @@ -95,7 +95,6 @@ void PhysicalColumnDataScan::BuildPipelines(Pipeline ¤t, MetaPipeline &met state.SetPipelineSource(current, *this); return; } - case PhysicalOperatorType::RECURSIVE_RECURRING_CTE_SCAN: case PhysicalOperatorType::RECURSIVE_CTE_SCAN: if (!meta_pipeline.HasRecursiveCTE()) { throw InternalException("Recursive CTE scan found without recursive CTE node"); @@ -116,7 +115,6 @@ InsertionOrderPreservingMap PhysicalColumnDataScan::ParamsToString() con result["Delim Index"] = StringUtil::Format("%llu", delim_index.GetIndex()); } break; - case PhysicalOperatorType::RECURSIVE_RECURRING_CTE_SCAN: case PhysicalOperatorType::CTE_SCAN: case PhysicalOperatorType::RECURSIVE_CTE_SCAN: { result["CTE Index"] = StringUtil::Format("%llu", cte_index); diff --git a/src/duckdb/src/execution/operator/scan/physical_positional_scan.cpp b/src/duckdb/src/execution/operator/scan/physical_positional_scan.cpp index deb6e669a..c1e2707b2 100644 --- a/src/duckdb/src/execution/operator/scan/physical_positional_scan.cpp +++ b/src/duckdb/src/execution/operator/scan/physical_positional_scan.cpp @@ -10,25 +10,25 @@ namespace duckdb { -PhysicalPositionalScan::PhysicalPositionalScan(vector types, PhysicalOperator &left, - PhysicalOperator &right) +PhysicalPositionalScan::PhysicalPositionalScan(vector types, unique_ptr left, + unique_ptr right) : PhysicalOperator(PhysicalOperatorType::POSITIONAL_SCAN, std::move(types), - MaxValue(left.estimated_cardinality, right.estimated_cardinality)) { + MaxValue(left->estimated_cardinality, right->estimated_cardinality)) { // Manage the children ourselves - if (left.type == PhysicalOperatorType::TABLE_SCAN) { - child_tables.emplace_back(left); - } else if (left.type == PhysicalOperatorType::POSITIONAL_SCAN) { - auto &left_scan = left.Cast(); + if (left->type == PhysicalOperatorType::TABLE_SCAN) { + child_tables.emplace_back(std::move(left)); + } else if (left->type == PhysicalOperatorType::POSITIONAL_SCAN) { + auto &left_scan = left->Cast(); child_tables = std::move(left_scan.child_tables); } else { throw InternalException("Invalid left input for PhysicalPositionalScan"); } - if (right.type == PhysicalOperatorType::TABLE_SCAN) { - child_tables.emplace_back(right); - } else if (right.type == PhysicalOperatorType::POSITIONAL_SCAN) { - auto &right_scan = right.Cast(); + if (right->type == PhysicalOperatorType::TABLE_SCAN) { + child_tables.emplace_back(std::move(right)); + } else if (right->type == PhysicalOperatorType::POSITIONAL_SCAN) { + auto &right_scan = right->Cast(); auto &right_tables = right_scan.child_tables; child_tables.reserve(child_tables.size() + right_tables.size()); std::move(right_tables.begin(), right_tables.end(), std::back_inserter(child_tables)); @@ -41,7 +41,7 @@ class PositionalScanGlobalSourceState : public GlobalSourceState { public: PositionalScanGlobalSourceState(ClientContext &context, const PhysicalPositionalScan &op) { for (const auto &table : op.child_tables) { - global_states.emplace_back(table.get().GetGlobalSourceState(context)); + global_states.emplace_back(table->GetGlobalSourceState(context)); } } @@ -136,7 +136,7 @@ class PositionalScanLocalSourceState : public LocalSourceState { PositionalScanLocalSourceState(ExecutionContext &context, PositionalScanGlobalSourceState &gstate, const PhysicalPositionalScan &op) { for (size_t i = 0; i < op.child_tables.size(); ++i) { - auto &child = op.child_tables[i]; + auto &child = *op.child_tables[i]; auto &global_state = *gstate.global_states[i]; scanners.emplace_back(make_uniq(context, child, global_state)); } @@ -185,7 +185,7 @@ ProgressData PhysicalPositionalScan::GetProgress(ClientContext &context, GlobalS ProgressData res; for (size_t t = 0; t < child_tables.size(); ++t) { - res.Add(child_tables[t].get().GetProgress(context, *gstate.global_states[t])); + res.Add(child_tables[t]->GetProgress(context, *gstate.global_states[t])); } return res; @@ -201,7 +201,7 @@ bool PhysicalPositionalScan::Equals(const PhysicalOperator &other_p) const { return false; } for (size_t i = 0; i < child_tables.size(); ++i) { - if (!child_tables[i].get().Equals(other.child_tables[i])) { + if (!child_tables[i]->Equals(*other.child_tables[i])) { return false; } } @@ -212,7 +212,7 @@ bool PhysicalPositionalScan::Equals(const PhysicalOperator &other_p) const { vector> PhysicalPositionalScan::GetChildren() const { auto result = PhysicalOperator::GetChildren(); for (auto &entry : child_tables) { - result.push_back(entry.get()); + result.push_back(*entry); } return result; } diff --git a/src/duckdb/src/execution/operator/scan/physical_table_scan.cpp b/src/duckdb/src/execution/operator/scan/physical_table_scan.cpp index 496adb25b..e4d3a1f87 100644 --- a/src/duckdb/src/execution/operator/scan/physical_table_scan.cpp +++ b/src/duckdb/src/execution/operator/scan/physical_table_scan.cpp @@ -14,12 +14,11 @@ PhysicalTableScan::PhysicalTableScan(vector types, TableFunction fu vector column_ids_p, vector projection_ids_p, vector names_p, unique_ptr table_filters_p, idx_t estimated_cardinality, ExtraOperatorInfo extra_info, - vector parameters_p, virtual_column_map_t virtual_columns_p) + vector parameters_p) : PhysicalOperator(PhysicalOperatorType::TABLE_SCAN, std::move(types), estimated_cardinality), function(std::move(function_p)), bind_data(std::move(bind_data_p)), returned_types(std::move(returned_types_p)), column_ids(std::move(column_ids_p)), projection_ids(std::move(projection_ids_p)), names(std::move(names_p)), - table_filters(std::move(table_filters_p)), extra_info(extra_info), parameters(std::move(parameters_p)), - virtual_columns(std::move(virtual_columns_p)) { + table_filters(std::move(table_filters_p)), extra_info(extra_info), parameters(std::move(parameters_p)) { } class TableScanGlobalSourceState : public GlobalSourceState { @@ -225,12 +224,8 @@ InsertionOrderPreservingMap PhysicalTableScan::ParamsToString() const { first_item = false; const auto col_id = column_ids[column_index].GetPrimaryIndex(); - if (IsVirtualColumn(col_id)) { - auto entry = virtual_columns.find(col_id); - if (entry == virtual_columns.end()) { - throw InternalException("Virtual column not found"); - } - filters_info += filter->ToString(entry->second.name); + if (col_id == COLUMN_IDENTIFIER_ROW_ID) { + filters_info += filter->ToString("rowid"); } else { filters_info += filter->ToString(names[col_id]); } @@ -279,16 +274,4 @@ bool PhysicalTableScan::ParallelSource() const { return true; } -InsertionOrderPreservingMap PhysicalTableScan::ExtraSourceParams(GlobalSourceState &gstate_p, - LocalSourceState &lstate) const { - if (!function.dynamic_to_string) { - return InsertionOrderPreservingMap(); - } - auto &gstate = gstate_p.Cast(); - auto &state = lstate.Cast(); - TableFunctionDynamicToStringInput input(function, bind_data.get(), state.local_state.get(), - gstate.global_state.get()); - return function.dynamic_to_string(input); -} - } // namespace duckdb diff --git a/src/duckdb/src/execution/operator/schema/physical_attach.cpp b/src/duckdb/src/execution/operator/schema/physical_attach.cpp index d3646f32b..523f0d57e 100644 --- a/src/duckdb/src/execution/operator/schema/physical_attach.cpp +++ b/src/duckdb/src/execution/operator/schema/physical_attach.cpp @@ -32,8 +32,7 @@ SourceResultType PhysicalAttach::GetData(ExecutionContext &context, DataChunk &c // check ATTACH IF NOT EXISTS auto &db_manager = DatabaseManager::Get(context.client); - if (info->on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT || - info->on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { + if (info->on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { // constant-time lookup in the catalog for the db name auto existing_db = db_manager.GetDatabase(context.client, name); if (existing_db) { @@ -49,16 +48,7 @@ SourceResultType PhysicalAttach::GetData(ExecutionContext &context, DataChunk &c if (!options.default_table.name.empty()) { existing_db->GetCatalog().SetDefaultTable(options.default_table.schema, options.default_table.name); } - if (info->on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { - // same path, name and type, DB does not need replacing - auto const db_type = options.db_type.empty() ? "duckdb" : options.db_type; - if (existing_db->GetCatalog().GetDBPath() == path && - existing_db->GetCatalog().GetCatalogType() == db_type) { - return SourceResultType::FINISHED; - } - } else { - return SourceResultType::FINISHED; - } + return SourceResultType::FINISHED; } } @@ -82,7 +72,7 @@ SourceResultType PhysicalAttach::GetData(ExecutionContext &context, DataChunk &c //! Initialize the database. const auto storage_options = info->GetStorageOptions(); - attached_db->Initialize(context.client, storage_options); + attached_db->Initialize(storage_options); if (!options.default_table.name.empty()) { attached_db->GetCatalog().SetDefaultTable(options.default_table.schema, options.default_table.name); } diff --git a/src/duckdb/src/execution/operator/schema/physical_create_art_index.cpp b/src/duckdb/src/execution/operator/schema/physical_create_art_index.cpp index ecfaa918e..c5f51fb12 100644 --- a/src/duckdb/src/execution/operator/schema/physical_create_art_index.cpp +++ b/src/duckdb/src/execution/operator/schema/physical_create_art_index.cpp @@ -174,9 +174,8 @@ SinkFinalizeType PhysicalCreateARTIndex::Finalize(Pipeline &pipeline, Event &eve state.global_index->VerifyAllocations(); auto &storage = table.GetStorage(); - if (!storage.IsMainTable()) { - throw TransactionException( - "Transaction conflict: cannot add an index to a table that has been altered or dropped"); + if (!storage.IsRoot()) { + throw TransactionException("cannot add an index to a table that has been altered"); } auto &schema = table.schema; diff --git a/src/duckdb/src/execution/operator/schema/physical_create_type.cpp b/src/duckdb/src/execution/operator/schema/physical_create_type.cpp index e73ca2662..68bc258b3 100644 --- a/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +++ b/src/duckdb/src/execution/operator/schema/physical_create_type.cpp @@ -51,7 +51,7 @@ SinkResultType PhysicalCreateType::Sink(ExecutionContext &context, DataChunk &ch for (idx_t i = 0; i < chunk.size(); i++) { idx_t idx = sdata.sel->get_index(i); if (!sdata.validity.RowIsValid(idx)) { - continue; + throw InvalidInputException("Attempted to create ENUM type with NULL value!"); } auto str = src_ptr[idx]; auto entry = gstate.found_strings.find(src_ptr[idx]); diff --git a/src/duckdb/src/execution/operator/set/physical_cte.cpp b/src/duckdb/src/execution/operator/set/physical_cte.cpp index 1a1801a1a..fad76bbdd 100644 --- a/src/duckdb/src/execution/operator/set/physical_cte.cpp +++ b/src/duckdb/src/execution/operator/set/physical_cte.cpp @@ -9,12 +9,12 @@ namespace duckdb { -PhysicalCTE::PhysicalCTE(string ctename, idx_t table_index, vector types, PhysicalOperator &top, - PhysicalOperator &bottom, idx_t estimated_cardinality) +PhysicalCTE::PhysicalCTE(string ctename, idx_t table_index, vector types, unique_ptr top, + unique_ptr bottom, idx_t estimated_cardinality) : PhysicalOperator(PhysicalOperatorType::CTE, std::move(types), estimated_cardinality), table_index(table_index), ctename(std::move(ctename)) { - children.push_back(top); - children.push_back(bottom); + children.push_back(std::move(top)); + children.push_back(std::move(bottom)); } PhysicalCTE::~PhysicalCTE() { @@ -89,17 +89,17 @@ void PhysicalCTE::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipeline) auto &state = meta_pipeline.GetState(); auto &child_meta_pipeline = meta_pipeline.CreateChildMetaPipeline(current, *this); - child_meta_pipeline.Build(children[0]); + child_meta_pipeline.Build(*children[0]); for (auto &cte_scan : cte_scans) { state.cte_dependencies.insert(make_pair(cte_scan, reference(*child_meta_pipeline.GetBasePipeline()))); } - children[1].get().BuildPipelines(current, meta_pipeline); + children[1]->BuildPipelines(current, meta_pipeline); } vector> PhysicalCTE::GetSources() const { - return children[1].get().GetSources(); + return children[1]->GetSources(); } InsertionOrderPreservingMap PhysicalCTE::ParamsToString() const { diff --git a/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp b/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp index a20a1ea19..328e0822b 100644 --- a/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +++ b/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp @@ -11,16 +11,15 @@ #include "duckdb/parallel/task_scheduler.hpp" #include "duckdb/storage/buffer_manager.hpp" -#include - namespace duckdb { PhysicalRecursiveCTE::PhysicalRecursiveCTE(string ctename, idx_t table_index, vector types, bool union_all, - PhysicalOperator &top, PhysicalOperator &bottom, idx_t estimated_cardinality) + unique_ptr top, unique_ptr bottom, + idx_t estimated_cardinality) : PhysicalOperator(PhysicalOperatorType::RECURSIVE_CTE, std::move(types), estimated_cardinality), ctename(std::move(ctename)), table_index(table_index), union_all(union_all) { - children.push_back(top); - children.push_back(bottom); + children.push_back(std::move(top)); + children.push_back(std::move(bottom)); } PhysicalRecursiveCTE::~PhysicalRecursiveCTE() { @@ -33,26 +32,19 @@ class RecursiveCTEState : public GlobalSinkState { public: explicit RecursiveCTEState(ClientContext &context, const PhysicalRecursiveCTE &op) : intermediate_table(context, op.GetTypes()), new_groups(STANDARD_VECTOR_SIZE) { - - vector payload_aggregates_ptr; - for (idx_t i = 0; i < op.payload_aggregates.size(); i++) { - auto &dat = op.payload_aggregates[i]; - payload_aggregates_ptr.push_back(dat.get()); - } - - ht = make_uniq(context, BufferAllocator::Get(context), op.distinct_types, - op.payload_types, payload_aggregates_ptr); + ht = make_uniq(context, BufferAllocator::Get(context), op.types, + vector(), vector()); } unique_ptr ht; + bool intermediate_empty = true; mutex intermediate_table_lock; ColumnDataCollection intermediate_table; ColumnDataScanState scan_state; bool initialized = false; bool finished_scan = false; SelectionVector new_groups; - AggregateHTScanState ht_scan_state; }; unique_ptr PhysicalRecursiveCTE::GetGlobalSinkState(ClientContext &context) const { @@ -71,50 +63,18 @@ idx_t PhysicalRecursiveCTE::ProbeHT(DataChunk &chunk, RecursiveCTEState &state) return new_group_count; } -void PopulateChunk(DataChunk &group_chunk, DataChunk &input_chunk, const vector &idx_set, bool reference) { - idx_t chunk_index = 0; - // Populate the group_chunk - for (auto &group_idx : idx_set) { - if (reference) { - // Reference from input_chunk[chunk_index] -> group_chunk[group_idx] - group_chunk.data[chunk_index++].Reference(input_chunk.data[group_idx]); - } else { - // Reference from input_chunk[group.index] -> group_chunk[chunk_index] - group_chunk.data[group_idx].Reference(input_chunk.data[chunk_index++]); - } - } - group_chunk.SetCardinality(input_chunk.size()); -} - SinkResultType PhysicalRecursiveCTE::Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const { auto &gstate = input.global_state.Cast(); lock_guard guard(gstate.intermediate_table_lock); - if (!using_key) { - if (!union_all) { - idx_t match_count = ProbeHT(chunk, gstate); - if (match_count > 0) { - gstate.intermediate_table.Append(chunk); - } - } else { + if (!union_all) { + idx_t match_count = ProbeHT(chunk, gstate); + if (match_count > 0) { gstate.intermediate_table.Append(chunk); } } else { - // Split incoming DataChunk into payload and keys - DataChunk distinct_rows; - distinct_rows.Initialize(Allocator::DefaultAllocator(), distinct_types); - PopulateChunk(distinct_rows, chunk, distinct_idx, true); - DataChunk payload_rows; - if (!payload_types.empty()) { - payload_rows.Initialize(Allocator::DefaultAllocator(), payload_types); - } - PopulateChunk(payload_rows, chunk, payload_idx, true); - - // Add the chunk to the hash table and append it to the intermediate table - gstate.ht->AddChunk(distinct_rows, payload_rows, AggregateType::NON_DISTINCT); gstate.intermediate_table.Append(chunk); } - return SinkResultType::NEED_MORE_INPUT; } @@ -125,21 +85,14 @@ SourceResultType PhysicalRecursiveCTE::GetData(ExecutionContext &context, DataCh OperatorSourceInput &input) const { auto &gstate = sink_state->Cast(); if (!gstate.initialized) { - if (!using_key) { - gstate.intermediate_table.InitializeScan(gstate.scan_state); - } else { - gstate.ht->InitializeScan(gstate.ht_scan_state); - recurring_table->InitializeScan(gstate.scan_state); - } + gstate.intermediate_table.InitializeScan(gstate.scan_state); gstate.finished_scan = false; gstate.initialized = true; } while (chunk.size() == 0) { if (!gstate.finished_scan) { - if (!using_key) { - // scan any chunks we have collected so far - gstate.intermediate_table.Scan(gstate.scan_state, chunk); - } + // scan any chunks we have collected so far + gstate.intermediate_table.Scan(gstate.scan_state, chunk); if (chunk.size() == 0) { gstate.finished_scan = true; } else { @@ -149,35 +102,6 @@ SourceResultType PhysicalRecursiveCTE::GetData(ExecutionContext &context, DataCh // we have run out of chunks // now we need to recurse // we set up the working table as the data we gathered in this iteration of the recursion - - // After an iteration, we reset the recurring table - // and fill it up with the new hash table rows for the next iteration. - if (using_key && ref_recurring && gstate.intermediate_table.Count() != 0) { - recurring_table->Reset(); - AggregateHTScanState scan_state; - gstate.ht->InitializeScan(scan_state); - - // Initialise the DataChunks to read the resulting rows. - // One DataChunk for the payload, one for the keys. - // Create a new DataChunk to store the result. - DataChunk result; - DataChunk payload_rows; - DataChunk distinct_rows; - distinct_rows.Initialize(Allocator::DefaultAllocator(), distinct_types); - if (!payload_types.empty()) { - payload_rows.Initialize(Allocator::DefaultAllocator(), payload_types); - } - result.Initialize(Allocator::DefaultAllocator(), chunk.GetTypes()); - - while (gstate.ht->Scan(scan_state, distinct_rows, payload_rows)) { - // Populate the result DataChunk with the keys and the payload. - PopulateChunk(result, distinct_rows, distinct_idx, false); - PopulateChunk(result, payload_rows, payload_idx, false); - // Append the result to the recurring table. - recurring_table->Append(result); - } - } - working_table->Reset(); working_table->Combine(gstate.intermediate_table); // and we clear the intermediate table @@ -190,26 +114,10 @@ SourceResultType PhysicalRecursiveCTE::GetData(ExecutionContext &context, DataCh // if not, we are done if (gstate.intermediate_table.Count() == 0) { gstate.finished_scan = true; - if (using_key) { - // Initialise the DataChunks to read the ht. - // One DataChunk for payload, one for keys. - DataChunk payload_rows; - DataChunk distinct_rows; - distinct_rows.Initialize(Allocator::DefaultAllocator(), distinct_types); - if (!payload_types.empty()) { - payload_rows.Initialize(Allocator::DefaultAllocator(), payload_types); - } - - gstate.ht->Scan(gstate.ht_scan_state, distinct_rows, payload_rows); - PopulateChunk(chunk, distinct_rows, distinct_idx, false); - PopulateChunk(chunk, payload_rows, payload_idx, false); - } break; } - if (!using_key) { - // set up the scan again - gstate.intermediate_table.InitializeScan(gstate.scan_state); - } + // set up the scan again + gstate.intermediate_table.InitializeScan(gstate.scan_state); } } @@ -272,7 +180,7 @@ static void GatherColumnDataScans(const PhysicalOperator &op, vector(executor, state, this); recursive_meta_pipeline->SetRecursiveCTE(); - recursive_meta_pipeline->Build(children[1]); + recursive_meta_pipeline->Build(*children[1]); vector> ops; - GatherColumnDataScans(children[1], ops); + GatherColumnDataScans(*children[1], ops); for (auto op : ops) { auto entry = state.cte_dependencies.find(op); diff --git a/src/duckdb/src/execution/operator/set/physical_union.cpp b/src/duckdb/src/execution/operator/set/physical_union.cpp index 0071de251..1194b9539 100644 --- a/src/duckdb/src/execution/operator/set/physical_union.cpp +++ b/src/duckdb/src/execution/operator/set/physical_union.cpp @@ -6,29 +6,17 @@ namespace duckdb { -PhysicalUnion::PhysicalUnion(vector types, PhysicalOperator &top, PhysicalOperator &bottom, - idx_t estimated_cardinality, bool allow_out_of_order) +PhysicalUnion::PhysicalUnion(vector types, unique_ptr top, + unique_ptr bottom, idx_t estimated_cardinality, bool allow_out_of_order) : PhysicalOperator(PhysicalOperatorType::UNION, std::move(types), estimated_cardinality), allow_out_of_order(allow_out_of_order) { - children.push_back(top); - children.push_back(bottom); + children.push_back(std::move(top)); + children.push_back(std::move(bottom)); } //===--------------------------------------------------------------------===// // Pipeline Construction //===--------------------------------------------------------------------===// -static bool ContainsSink(PhysicalOperator &op) { - if (op.IsSink()) { - return true; - } - for (auto &child : op.children) { - if (ContainsSink(child)) { - return true; - } - } - return false; -} - void PhysicalUnion::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipeline) { op_state.reset(); sink_state.reset(); @@ -60,15 +48,11 @@ void PhysicalUnion::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipelin auto &union_pipeline = meta_pipeline.CreateUnionPipeline(current, order_matters); // continue with the current pipeline - children[0].get().BuildPipelines(current, meta_pipeline); + children[0]->BuildPipelines(current, meta_pipeline); vector> dependencies; optional_ptr last_child_ptr; - // users commonly UNION ALL together a bunch of cheap scan pipelines (e.g., instead of a multi file list) - // in these cases, we don't want to avoid breadth-first plan evaluation, - // as it doesn't pose a threat to memory usage (it's just a bunch of straight scans) - const auto can_saturate_threads = - ContainsSink(children[0]) && children[0].get().CanSaturateThreads(current.GetClientContext()); + const auto can_saturate_threads = children[0]->CanSaturateThreads(current.GetClientContext()); if (order_matters || can_saturate_threads) { // we add dependencies if order matters: union_pipeline comes after all pipelines created by building current dependencies = meta_pipeline.AddDependenciesFrom(union_pipeline, union_pipeline, false); @@ -81,7 +65,7 @@ void PhysicalUnion::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipelin } // build the union pipeline - children[1].get().BuildPipelines(union_pipeline, meta_pipeline); + children[1]->BuildPipelines(union_pipeline, meta_pipeline); if (last_child_ptr) { // the pointer was set, set up the dependencies @@ -96,7 +80,7 @@ void PhysicalUnion::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipelin vector> PhysicalUnion::GetSources() const { vector> result; for (auto &child : children) { - auto child_sources = child.get().GetSources(); + auto child_sources = child->GetSources(); result.insert(result.end(), child_sources.begin(), child_sources.end()); } return result; diff --git a/src/duckdb/src/execution/perfect_aggregate_hashtable.cpp b/src/duckdb/src/execution/perfect_aggregate_hashtable.cpp index 48f05f88a..c378e61ed 100644 --- a/src/duckdb/src/execution/perfect_aggregate_hashtable.cpp +++ b/src/duckdb/src/execution/perfect_aggregate_hashtable.cpp @@ -22,8 +22,8 @@ PerfectAggregateHashTable::PerfectAggregateHashTable(ClientContext &context, All total_groups = (uint64_t)1 << total_required_bits; // we don't need to store the groups in a perfect hash table, since the group keys can be deduced by their location grouping_columns = group_types_p.size(); - layout_ptr->Initialize(std::move(aggregate_objects_p)); - tuple_size = layout_ptr->GetRowWidth(); + layout.Initialize(std::move(aggregate_objects_p)); + tuple_size = layout.GetRowWidth(); // allocate and null initialize the data owned_data = make_unsafe_uniq_array_uninitialized(tuple_size * total_groups); @@ -40,12 +40,11 @@ PerfectAggregateHashTable::PerfectAggregateHashTable(ClientContext &context, All address_data[init_count] = uintptr_t(data) + (tuple_size * i); init_count++; if (init_count == STANDARD_VECTOR_SIZE) { - RowOperations::InitializeStates(*layout_ptr, addresses, *FlatVector::IncrementalSelectionVector(), - init_count); + RowOperations::InitializeStates(layout, addresses, *FlatVector::IncrementalSelectionVector(), init_count); init_count = 0; } } - RowOperations::InitializeStates(*layout_ptr, addresses, *FlatVector::IncrementalSelectionVector(), init_count); + RowOperations::InitializeStates(layout, addresses, *FlatVector::IncrementalSelectionVector(), init_count); } PerfectAggregateHashTable::~PerfectAggregateHashTable() { @@ -143,7 +142,7 @@ void PerfectAggregateHashTable::AddChunk(DataChunk &groups, DataChunk &payload) // after finding the group location we update the aggregates idx_t payload_idx = 0; - auto &aggregates = layout_ptr->GetAggregates(); + auto &aggregates = layout.GetAggregates(); RowOperationsState row_state(*aggregate_allocator); for (idx_t aggr_idx = 0; aggr_idx < aggregates.size(); aggr_idx++) { auto &aggregate = aggregates[aggr_idx]; @@ -183,14 +182,14 @@ void PerfectAggregateHashTable::Combine(PerfectAggregateHashTable &other) { target_addresses_ptr[combine_count] = target_ptr; combine_count++; if (combine_count == STANDARD_VECTOR_SIZE) { - RowOperations::CombineStates(row_state, *layout_ptr, source_addresses, target_addresses, combine_count); + RowOperations::CombineStates(row_state, layout, source_addresses, target_addresses, combine_count); combine_count = 0; } } source_ptr += tuple_size; target_ptr += tuple_size; } - RowOperations::CombineStates(row_state, *layout_ptr, source_addresses, target_addresses, combine_count); + RowOperations::CombineStates(row_state, layout, source_addresses, target_addresses, combine_count); // FIXME: after moving the arena allocator, we currently have to ensure that the pointer is not nullptr, because the // FIXME: Destroy()-function of the hash table expects an allocator in some cases (e.g., for sorted aggregates) @@ -283,13 +282,13 @@ void PerfectAggregateHashTable::Scan(idx_t &scan_position, DataChunk &result) { // then construct the payloads result.SetCardinality(entry_count); RowOperationsState row_state(*aggregate_allocator); - RowOperations::FinalizeStates(row_state, *layout_ptr, addresses, result, grouping_columns); + RowOperations::FinalizeStates(row_state, layout, addresses, result, grouping_columns); } void PerfectAggregateHashTable::Destroy() { // check if there is any destructor to call bool has_destructor = false; - for (auto &aggr : layout_ptr->GetAggregates()) { + for (auto &aggr : layout.GetAggregates()) { if (aggr.function.destructor) { has_destructor = true; } @@ -308,12 +307,12 @@ void PerfectAggregateHashTable::Destroy() { for (idx_t i = 0; i < total_groups; i++) { data_pointers[count++] = payload_ptr; if (count == STANDARD_VECTOR_SIZE) { - RowOperations::DestroyStates(row_state, *layout_ptr, addresses, count); + RowOperations::DestroyStates(row_state, layout, addresses, count); count = 0; } payload_ptr += tuple_size; } - RowOperations::DestroyStates(row_state, *layout_ptr, addresses, count); + RowOperations::DestroyStates(row_state, layout, addresses, count); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_operator.cpp b/src/duckdb/src/execution/physical_operator.cpp index 3409f2bdd..c5119620b 100644 --- a/src/duckdb/src/execution/physical_operator.cpp +++ b/src/duckdb/src/execution/physical_operator.cpp @@ -36,7 +36,7 @@ void PhysicalOperator::Print() const { vector> PhysicalOperator::GetChildren() const { vector> result; for (auto &child : children) { - result.push_back(child.get()); + result.push_back(*child); } return result; } @@ -54,12 +54,12 @@ idx_t PhysicalOperator::EstimatedThreadCount() const { } else if (type == PhysicalOperatorType::UNION) { // We can run union pipelines in parallel, so we sum up the thread count of the children for (auto &child : children) { - result += child.get().EstimatedThreadCount(); + result += child->EstimatedThreadCount(); } } else { // For other operators we take the maximum of the children for (auto &child : children) { - result = MaxValue(child.get().EstimatedThreadCount(), result); + result = MaxValue(child->EstimatedThreadCount(), result); } } return result; @@ -207,7 +207,7 @@ void PhysicalOperator::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipe // we create a new pipeline starting from the child auto &child_meta_pipeline = meta_pipeline.CreateChildMetaPipeline(current, *this); - child_meta_pipeline.Build(children[0]); + child_meta_pipeline.Build(*children[0]); } else { // operator is not a sink! recurse in children if (children.empty()) { @@ -218,7 +218,7 @@ void PhysicalOperator::BuildPipelines(Pipeline ¤t, MetaPipeline &meta_pipe throw InternalException("Operator not supported in BuildPipelines"); } state.AddPipelineOperator(current, *this); - children[0].get().BuildPipelines(current, meta_pipeline); + children[0]->BuildPipelines(current, meta_pipeline); } } } @@ -238,7 +238,7 @@ vector> PhysicalOperator::GetSources() const { if (children.size() != 1) { throw InternalException("Operator not supported in GetSource"); } - return children[0].get().GetSources(); + return children[0]->GetSources(); } } } @@ -258,7 +258,7 @@ void PhysicalOperator::Verify() { auto sources = GetSources(); D_ASSERT(!sources.empty()); for (auto &child : children) { - child.get().Verify(); + child->Verify(); } #endif } diff --git a/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp b/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp index 0831ee153..c61781a33 100644 --- a/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp @@ -72,12 +72,12 @@ static bool CanUsePartitionedAggregate(ClientContext &context, LogicalAggregate } // continue into child node with new columns partition_columns = std::move(new_columns); - child_ref = child_op.children[0]; + child_ref = *child_op.children[0]; break; } case PhysicalOperatorType::FILTER: // continue into child operators - child_ref = child_op.children[0]; + child_ref = *child_op.children[0]; break; default: // unsupported operator for partition pass-through @@ -233,11 +233,13 @@ static bool CanUsePerfectHashAggregate(ClientContext &context, LogicalAggregate return true; } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalAggregate &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalAggregate &op) { + unique_ptr groupby; D_ASSERT(op.children.size() == 1); - reference plan = CreatePlan(*op.children[0]); - plan = ExtractAggregateExpressions(plan, op.expressions, op.groups); + auto plan = CreatePlan(*op.children[0]); + + plan = ExtractAggregateExpressions(std::move(plan), op.expressions, op.groups); bool can_use_simple_aggregation = true; for (auto &expression : op.expressions) { @@ -248,52 +250,43 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalAggregate &op) { break; } } - if (op.groups.empty() && op.grouping_sets.size() <= 1) { // no groups, check if we can use a simple aggregation // special case: aggregate entire columns together if (can_use_simple_aggregation) { - auto &group_by = - Make(op.types, std::move(op.expressions), op.estimated_cardinality); - group_by.children.push_back(plan); - return group_by; + groupby = make_uniq_base(op.types, std::move(op.expressions), + op.estimated_cardinality); + } else { + groupby = make_uniq_base( + context, op.types, std::move(op.expressions), op.estimated_cardinality); + } + } else { + // groups! create a GROUP BY aggregator + // use a partitioned or perfect hash aggregate if possible + vector partition_columns; + vector required_bits; + if (can_use_simple_aggregation && CanUsePartitionedAggregate(context, op, *plan, partition_columns)) { + groupby = make_uniq_base( + context, op.types, std::move(op.expressions), std::move(op.groups), std::move(partition_columns), + op.estimated_cardinality); + } else if (CanUsePerfectHashAggregate(context, op, required_bits)) { + groupby = make_uniq_base( + context, op.types, std::move(op.expressions), std::move(op.groups), std::move(op.group_stats), + std::move(required_bits), op.estimated_cardinality); + } else { + groupby = make_uniq_base( + context, op.types, std::move(op.expressions), std::move(op.groups), std::move(op.grouping_sets), + std::move(op.grouping_functions), op.estimated_cardinality); } - auto &group_by = - Make(context, op.types, std::move(op.expressions), op.estimated_cardinality); - group_by.children.push_back(plan); - return group_by; - } - - // groups! create a GROUP BY aggregator - // use a partitioned or perfect hash aggregate if possible - vector partition_columns; - vector required_bits; - if (can_use_simple_aggregation && CanUsePartitionedAggregate(context, op, plan, partition_columns)) { - auto &group_by = - Make(context, op.types, std::move(op.expressions), std::move(op.groups), - std::move(partition_columns), op.estimated_cardinality); - group_by.children.push_back(plan); - return group_by; - } - - if (CanUsePerfectHashAggregate(context, op, required_bits)) { - auto &group_by = Make(context, op.types, std::move(op.expressions), - std::move(op.groups), std::move(op.group_stats), - std::move(required_bits), op.estimated_cardinality); - group_by.children.push_back(plan); - return group_by; } - - auto &group_by = Make(context, op.types, std::move(op.expressions), std::move(op.groups), - std::move(op.grouping_sets), std::move(op.grouping_functions), - op.estimated_cardinality); - group_by.children.push_back(plan); - return group_by; + groupby->children.push_back(std::move(plan)); + return groupby; } -PhysicalOperator &PhysicalPlanGenerator::ExtractAggregateExpressions(PhysicalOperator &child, - vector> &aggregates, - vector> &groups) { +unique_ptr +PhysicalPlanGenerator::ExtractAggregateExpressions(unique_ptr child, + vector> &aggregates, + vector> &groups) { vector> expressions; vector types; @@ -330,9 +323,10 @@ PhysicalOperator &PhysicalPlanGenerator::ExtractAggregateExpressions(PhysicalOpe if (expressions.empty()) { return child; } - auto &proj = Make(std::move(types), std::move(expressions), child.estimated_cardinality); - proj.children.push_back(child); - return proj; + auto projection = + make_uniq(std::move(types), std::move(expressions), child->estimated_cardinality); + projection->children.push_back(std::move(child)); + return std::move(projection); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_any_join.cpp b/src/duckdb/src/execution/physical_plan/plan_any_join.cpp index 7193ad6c8..5e8ee6223 100644 --- a/src/duckdb/src/execution/physical_plan/plan_any_join.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_any_join.cpp @@ -4,16 +4,17 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalAnyJoin &op) { - // Visit the child nodes. +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalAnyJoin &op) { + // first visit the child nodes D_ASSERT(op.children.size() == 2); D_ASSERT(op.condition); - auto &left = CreatePlan(*op.children[0]); - auto &right = CreatePlan(*op.children[1]); - // Create the blockwise NL join. - return Make(op, left, right, std::move(op.condition), op.join_type, - op.estimated_cardinality); + auto left = CreatePlan(*op.children[0]); + auto right = CreatePlan(*op.children[1]); + + // create the blockwise NL join + return make_uniq(op, std::move(left), std::move(right), std::move(op.condition), + op.join_type, op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_asof_join.cpp b/src/duckdb/src/execution/physical_plan/plan_asof_join.cpp index eb1286ee1..927defa4f 100644 --- a/src/duckdb/src/execution/physical_plan/plan_asof_join.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_asof_join.cpp @@ -1,14 +1,8 @@ -#include "duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp" -#include "duckdb/execution/operator/aggregate/physical_hash_aggregate.hpp" -#include "duckdb/execution/operator/aggregate/physical_streaming_window.hpp" #include "duckdb/execution/operator/aggregate/physical_window.hpp" #include "duckdb/execution/operator/join/physical_asof_join.hpp" #include "duckdb/execution/operator/join/physical_iejoin.hpp" -#include "duckdb/execution/operator/join/physical_nested_loop_join.hpp" #include "duckdb/execution/operator/projection/physical_projection.hpp" -#include "duckdb/function/aggregate/distributive_function_utils.hpp" #include "duckdb/execution/physical_plan_generator.hpp" -#include "duckdb/function/function_binder.hpp" #include "duckdb/main/client_context.hpp" #include "duckdb/planner/expression/bound_constant_expression.hpp" #include "duckdb/planner/expression/bound_reference_expression.hpp" @@ -16,230 +10,14 @@ namespace duckdb { -optional_ptr -PhysicalPlanGenerator::PlanAsOfLoopJoin(LogicalComparisonJoin &op, PhysicalOperator &probe, PhysicalOperator &build) { - - // Plan a inverse nested loop join, then aggregate the values to choose the optimal match for each probe row. - // Use a row number primary key to handle duplicate probe values. - // aggregate the fields to produce at most one match per probe row, - // then project the columns back into the correct order and drop the primary key. - // - // ∏ * \ pk - // | - // Γ pk;first(P),arg_xxx(B,inequality) - // | - // ∏ *,inequality - // | - // ⨝ swapped - // / \  - // B W pk:row_number - // | - // P - - LogicalComparisonJoin join_op(InverseJoinType(op.join_type)); - - join_op.types = op.children[1]->types; - const auto &probe_types = op.children[0]->types; - join_op.types.insert(join_op.types.end(), probe_types.begin(), probe_types.end()); - - // Fill in the projection maps to simplify the code below - // Since NLJ doesn't support projection, but ASOF does, - // we have to track this carefully... - join_op.left_projection_map = op.right_projection_map; - if (join_op.left_projection_map.empty()) { - for (idx_t i = 0; i < op.children[1]->types.size(); ++i) { - join_op.left_projection_map.emplace_back(i); - } - } - - join_op.right_projection_map = op.left_projection_map; - if (join_op.right_projection_map.empty()) { - for (idx_t i = 0; i < op.children[0]->types.size(); ++i) { - join_op.right_projection_map.emplace_back(i); - } - } - - // Project pk - LogicalType pk_type = LogicalType::BIGINT; - join_op.types.emplace_back(pk_type); - - auto binder = Binder::CreateBinder(context); - FunctionBinder function_binder(*binder); - auto asof_idx = op.conditions.size(); - string arg_min_max; - for (idx_t i = 0; i < op.conditions.size(); ++i) { - const auto &cond = op.conditions[i]; - JoinCondition nested_cond; - nested_cond.left = cond.right->Copy(); - nested_cond.right = cond.left->Copy(); - if (!nested_cond.left || !nested_cond.right) { - return nullptr; - } - nested_cond.comparison = FlipComparisonExpression(cond.comparison); - join_op.conditions.emplace_back(std::move(nested_cond)); - switch (cond.comparison) { - case ExpressionType::COMPARE_GREATERTHANOREQUALTO: - case ExpressionType::COMPARE_GREATERTHAN: - D_ASSERT(asof_idx == op.conditions.size()); - asof_idx = i; - arg_min_max = "arg_max"; - break; - case ExpressionType::COMPARE_LESSTHANOREQUALTO: - case ExpressionType::COMPARE_LESSTHAN: - D_ASSERT(asof_idx == op.conditions.size()); - asof_idx = i; - arg_min_max = "arg_min"; - break; - default: - break; - } - } - - // NLJ does not support some join types - switch (join_op.join_type) { - case JoinType::SEMI: - case JoinType::ANTI: - case JoinType::MARK: - case JoinType::INNER: - case JoinType::RIGHT: - // Unfortunately, this does not check all the join types... - if (!PhysicalNestedLoopJoin::IsSupported(op.conditions, op.join_type)) { - return nullptr; - } - break; - case JoinType::OUTER: - case JoinType::LEFT: - // RIGHT ASOF JOINs produce the entire build table and would require grouping on all build rows, - // which defeats the purpose of this optimisation. - default: - return nullptr; - } - - EntryLookupInfo function_lookup(CatalogType::SCALAR_FUNCTION_ENTRY, arg_min_max); - auto arg_min_max_func = - binder->GetCatalogEntry(SYSTEM_CATALOG, DEFAULT_SCHEMA, function_lookup, OnEntryNotFound::RETURN_NULL); - // Can't find the arg_min/max aggregate we need, so give up before we break anything. - if (!arg_min_max_func || arg_min_max_func->type != CatalogType::AGGREGATE_FUNCTION_ENTRY) { - return nullptr; - } - auto &arg_min_max_entry = arg_min_max_func->Cast(); - - // PhysicalHashAggregate requires that the arguments to aggregate functions be bound references, - // so we Project the (shared) ordering argument on the end of the join results. - vector> comp_list; - for (const auto &col_type : join_op.types) { - const auto col_idx = comp_list.size(); - comp_list.emplace_back(make_uniq(col_type, col_idx)); - } - vector comp_types = join_op.types; - auto comp_expr = op.conditions[asof_idx].right->Copy(); - comp_types.emplace_back(comp_expr->return_type); - comp_list.emplace_back(std::move(comp_expr)); - - // Bind the aggregates first so we can abort safely if we can't find one. - vector aggr_types(1, pk_type); - - // Wrap all the projected non-pk probe fields in `first` aggregates; - vector> aggregates; - for (const auto &i : join_op.right_projection_map) { - const auto col_idx = op.children[1]->types.size() + i; - const auto col_type = join_op.types[col_idx]; - aggr_types.emplace_back(col_type); - - vector> aggr_children; - auto col_ref = make_uniq(col_type, col_idx); - aggr_children.push_back(std::move(col_ref)); - - auto first_aggregate = FirstFunctionGetter::GetFunction(col_type); - auto aggr_expr = make_uniq(std::move(first_aggregate), std::move(aggr_children), - nullptr, nullptr, AggregateType::NON_DISTINCT); - D_ASSERT(col_type == aggr_expr->return_type); - aggregates.emplace_back(std::move(aggr_expr)); - } - - // Wrap all the projected build fields in `arg_max/min` aggregates using the inequality ordering; - // We are doing all this first in case we can't find a matching function. - for (const auto &col_idx : join_op.left_projection_map) { - const auto col_type = join_op.types[col_idx]; - aggr_types.emplace_back(col_type); - - vector> aggr_children; - auto col_ref = make_uniq(col_type, col_idx); - aggr_children.push_back(std::move(col_ref)); - auto comp_expr = make_uniq(comp_types.back(), comp_types.size() - 1); - aggr_children.push_back(std::move(comp_expr)); - vector child_types; - for (const auto &child : aggr_children) { - child_types.emplace_back(child->return_type); - } - - auto &func = arg_min_max_entry; - ErrorData error; - auto best_function = function_binder.BindFunction(func.name, func.functions, child_types, error); - if (!best_function.IsValid()) { - return nullptr; - } - auto bound_function = func.functions.GetFunctionByOffset(best_function.GetIndex()); - auto aggr_expr = function_binder.BindAggregateFunction(bound_function, std::move(aggr_children), nullptr, - AggregateType::NON_DISTINCT); - D_ASSERT(col_type == aggr_expr->return_type); - aggregates.emplace_back(std::move(aggr_expr)); - } - - // Add a synthetic primary integer key to the probe relation using streaming windowing. - vector> window_select; - auto pk = make_uniq(ExpressionType::WINDOW_ROW_NUMBER, pk_type, nullptr, nullptr); - pk->start = WindowBoundary::UNBOUNDED_PRECEDING; - pk->end = WindowBoundary::CURRENT_ROW_ROWS; - pk->alias = "row_number"; - window_select.emplace_back(std::move(pk)); - - auto window_types = probe.GetTypes(); - window_types.emplace_back(pk_type); - - idx_t probe_cardinality = op.children[0]->EstimateCardinality(context); - auto &window = Make(window_types, std::move(window_select), probe_cardinality); - window.children.emplace_back(probe); - - auto &join = Make(join_op, build, window, std::move(join_op.conditions), join_op.join_type, - probe_cardinality); - - // Plan a projection of the compare column - auto &comp_proj = Make(std::move(comp_types), std::move(comp_list), probe_cardinality); - comp_proj.children.emplace_back(join); - - // Plan an aggregation on the output of the join, grouping by key; - // TODO: Can we make it perfect? - // Note that the NLJ produced all fields, but only the projected ones were aggregated - vector> groups; - auto pk_ref = make_uniq(pk_type, join_op.types.size() - 1); - groups.emplace_back(std::move(pk_ref)); - - auto &aggr = - Make(context, aggr_types, std::move(aggregates), std::move(groups), probe_cardinality); - aggr.children.emplace_back(comp_proj); - - // Project away primary/grouping key - // The aggregates were generated in the output order of the original ASOF, - // so we just have to shift away the pk - vector> project_list; - for (column_t i = 1; i < aggr.GetTypes().size(); ++i) { - auto col_ref = make_uniq(aggr.GetTypes()[i], i); - project_list.emplace_back(std::move(col_ref)); - } - - auto &proj = Make(op.types, std::move(project_list), probe_cardinality); - proj.children.emplace_back(aggr); - return proj; -} - -PhysicalOperator &PhysicalPlanGenerator::PlanAsOfJoin(LogicalComparisonJoin &op) { +unique_ptr PhysicalPlanGenerator::PlanAsOfJoin(LogicalComparisonJoin &op) { // now visit the children D_ASSERT(op.children.size() == 2); idx_t lhs_cardinality = op.children[0]->EstimateCardinality(context); idx_t rhs_cardinality = op.children[1]->EstimateCardinality(context); - auto &left = CreatePlan(*op.children[0]); - auto &right = CreatePlan(*op.children[1]); + auto left = CreatePlan(*op.children[0]); + auto right = CreatePlan(*op.children[1]); + D_ASSERT(left && right); // Validate vector equi_indexes; @@ -264,21 +42,14 @@ PhysicalOperator &PhysicalPlanGenerator::PlanAsOfJoin(LogicalComparisonJoin &op) } D_ASSERT(asof_idx < op.conditions.size()); - auto &config = ClientConfig::GetConfig(context); - if (!config.force_asof_iejoin) { - if (op.children[0]->has_estimated_cardinality && lhs_cardinality <= config.asof_loop_join_threshold) { - auto result = PlanAsOfLoopJoin(op, left, right); - if (result) { - return *result; - } - } - return Make(op, left, right); + if (!ClientConfig::GetConfig(context).force_asof_iejoin) { + return make_uniq(op, std::move(left), std::move(right)); } // Strip extra column from rhs projections auto &right_projection_map = op.right_projection_map; if (right_projection_map.empty()) { - const auto right_count = right.GetTypes().size(); + const auto right_count = right->types.size(); right_projection_map.reserve(right_count); for (column_t i = 0; i < right_count; ++i) { right_projection_map.emplace_back(i); @@ -321,8 +92,8 @@ PhysicalOperator &PhysicalPlanGenerator::PlanAsOfJoin(LogicalComparisonJoin &op) auto &window_types = op.children[1]->types; window_types.emplace_back(asof_type); - auto &window = Make(window_types, std::move(window_select), rhs_cardinality); - window.children.emplace_back(right); + auto window = make_uniq(window_types, std::move(window_select), rhs_cardinality); + window->children.emplace_back(std::move(right)); // IEJoin(left, window, conditions || asof_comp ~op asof_end) JoinCondition asof_upper; @@ -346,7 +117,9 @@ PhysicalOperator &PhysicalPlanGenerator::PlanAsOfJoin(LogicalComparisonJoin &op) } op.conditions.emplace_back(std::move(asof_upper)); - return Make(op, left, window, std::move(op.conditions), op.join_type, lhs_cardinality); + + return make_uniq(op, std::move(left), std::move(window), std::move(op.conditions), op.join_type, + lhs_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_column_data_get.cpp b/src/duckdb/src/execution/physical_plan/plan_column_data_get.cpp index 6712ab5a1..46305675b 100644 --- a/src/duckdb/src/execution/physical_plan/plan_column_data_get.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_column_data_get.cpp @@ -4,11 +4,12 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalColumnDataGet &op) { - D_ASSERT(op.children.empty()); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalColumnDataGet &op) { + D_ASSERT(op.children.size() == 0); D_ASSERT(op.collection); - return Make(op.types, PhysicalOperatorType::COLUMN_DATA_SCAN, op.estimated_cardinality, - std::move(op.collection)); + + return make_uniq(op.types, PhysicalOperatorType::COLUMN_DATA_SCAN, op.estimated_cardinality, + std::move(op.collection)); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp b/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp index a639ab696..e8d310519 100644 --- a/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp @@ -25,19 +25,20 @@ static void RewriteJoinCondition(Expression &expr, idx_t offset) { ExpressionIterator::EnumerateChildren(expr, [&](Expression &child) { RewriteJoinCondition(child, offset); }); } -PhysicalOperator &PhysicalPlanGenerator::PlanComparisonJoin(LogicalComparisonJoin &op) { +unique_ptr PhysicalPlanGenerator::PlanComparisonJoin(LogicalComparisonJoin &op) { // now visit the children D_ASSERT(op.children.size() == 2); idx_t lhs_cardinality = op.children[0]->EstimateCardinality(context); idx_t rhs_cardinality = op.children[1]->EstimateCardinality(context); - auto &left = CreatePlan(*op.children[0]); - auto &right = CreatePlan(*op.children[1]); - left.estimated_cardinality = lhs_cardinality; - right.estimated_cardinality = rhs_cardinality; + auto left = CreatePlan(*op.children[0]); + auto right = CreatePlan(*op.children[1]); + left->estimated_cardinality = lhs_cardinality; + right->estimated_cardinality = rhs_cardinality; + D_ASSERT(left && right); if (op.conditions.empty()) { // no conditions: insert a cross product - return Make(op.types, left, right, op.estimated_cardinality); + return make_uniq(op.types, std::move(left), std::move(right), op.estimated_cardinality); } idx_t has_range = 0; @@ -60,51 +61,52 @@ PhysicalOperator &PhysicalPlanGenerator::PlanComparisonJoin(LogicalComparisonJoi // TODO: Extend PWMJ to handle all comparisons and projection maps const auto prefer_range_joins = client_config.prefer_range_joins && can_iejoin; + + unique_ptr plan; if (has_equality && !prefer_range_joins) { // Equality join with small number of keys : possible perfect join optimization - auto &join = Make(op, left, right, std::move(op.conditions), op.join_type, - op.left_projection_map, op.right_projection_map, std::move(op.mark_types), - op.estimated_cardinality, std::move(op.filter_pushdown)); - join.Cast().join_stats = std::move(op.join_stats); - return join; - } - - D_ASSERT(op.left_projection_map.empty()); - if (left.estimated_cardinality <= client_config.nested_loop_join_threshold || - right.estimated_cardinality <= client_config.nested_loop_join_threshold) { - can_iejoin = false; - can_merge = false; - } - - if (can_merge && can_iejoin) { - if (left.estimated_cardinality <= client_config.merge_join_threshold || - right.estimated_cardinality <= client_config.merge_join_threshold) { + plan = make_uniq( + op, std::move(left), std::move(right), std::move(op.conditions), op.join_type, op.left_projection_map, + op.right_projection_map, std::move(op.mark_types), op.estimated_cardinality, std::move(op.filter_pushdown)); + plan->Cast().join_stats = std::move(op.join_stats); + } else { + D_ASSERT(op.left_projection_map.empty()); + if (left->estimated_cardinality <= client_config.nested_loop_join_threshold || + right->estimated_cardinality <= client_config.nested_loop_join_threshold) { can_iejoin = false; + can_merge = false; + } + if (can_merge && can_iejoin) { + if (left->estimated_cardinality <= client_config.merge_join_threshold || + right->estimated_cardinality <= client_config.merge_join_threshold) { + can_iejoin = false; + } + } + if (can_iejoin) { + plan = make_uniq(op, std::move(left), std::move(right), std::move(op.conditions), + op.join_type, op.estimated_cardinality); + } else if (can_merge) { + // range join: use piecewise merge join + plan = + make_uniq(op, std::move(left), std::move(right), std::move(op.conditions), + op.join_type, op.estimated_cardinality); + } else if (PhysicalNestedLoopJoin::IsSupported(op.conditions, op.join_type)) { + // inequality join: use nested loop + plan = make_uniq(op, std::move(left), std::move(right), std::move(op.conditions), + op.join_type, op.estimated_cardinality); + } else { + for (auto &cond : op.conditions) { + RewriteJoinCondition(*cond.right, left->types.size()); + } + auto condition = JoinCondition::CreateExpression(std::move(op.conditions)); + plan = make_uniq(op, std::move(left), std::move(right), std::move(condition), + op.join_type, op.estimated_cardinality); } } - - if (can_iejoin) { - return Make(op, left, right, std::move(op.conditions), op.join_type, op.estimated_cardinality); - } - if (can_merge) { - // range join: use piecewise merge join - return Make(op, left, right, std::move(op.conditions), op.join_type, - op.estimated_cardinality); - } - if (PhysicalNestedLoopJoin::IsSupported(op.conditions, op.join_type)) { - // inequality join: use nested loop - return Make(op, left, right, std::move(op.conditions), op.join_type, - op.estimated_cardinality); - } - - for (auto &cond : op.conditions) { - RewriteJoinCondition(*cond.right, left.types.size()); - } - auto condition = JoinCondition::CreateExpression(std::move(op.conditions)); - return Make(op, left, right, std::move(condition), op.join_type, op.estimated_cardinality); + return plan; } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalComparisonJoin &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalComparisonJoin &op) { switch (op.type) { case LogicalOperatorType::LOGICAL_ASOF_JOIN: return PlanAsOfJoin(op); diff --git a/src/duckdb/src/execution/physical_plan/plan_copy_database.cpp b/src/duckdb/src/execution/physical_plan/plan_copy_database.cpp index 35388987c..68eaf5619 100644 --- a/src/duckdb/src/execution/physical_plan/plan_copy_database.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_copy_database.cpp @@ -4,8 +4,9 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCopyDatabase &op) { - return Make(op.types, op.estimated_cardinality, std::move(op.info)); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCopyDatabase &op) { + auto node = make_uniq(op.types, op.estimated_cardinality, std::move(op.info)); + return std::move(node); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp b/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp index bc81a3ddf..a2981f61f 100644 --- a/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp @@ -5,14 +5,12 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCopyToFile &op) { - auto &plan = CreatePlan(*op.children[0]); - bool preserve_insertion_order = PhysicalPlanGenerator::PreserveInsertionOrder(context, plan); - bool supports_batch_index = PhysicalPlanGenerator::UseBatchIndex(context, plan); - +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCopyToFile &op) { + auto plan = CreatePlan(*op.children[0]); + bool preserve_insertion_order = PhysicalPlanGenerator::PreserveInsertionOrder(context, *plan); + bool supports_batch_index = PhysicalPlanGenerator::UseBatchIndex(context, *plan); auto &fs = FileSystem::GetFileSystem(context); op.file_path = fs.ExpandPath(op.file_path); - if (op.use_tmp_file) { auto path = StringUtil::GetFilePath(op.file_path); auto base = StringUtil::GetFileName(op.file_path); @@ -33,45 +31,37 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCopyToFile &op) { throw InternalException("BATCH_COPY_TO_FILE can only be used if batch indexes are supported"); } // batched copy to file - auto © = - Make(op.types, op.function, std::move(op.bind_data), op.estimated_cardinality); - - auto &cast_copy = copy.Cast(); - cast_copy.file_path = op.file_path; - cast_copy.use_tmp_file = op.use_tmp_file; - cast_copy.children.push_back(plan); - cast_copy.return_type = op.return_type; - cast_copy.write_empty_file = op.write_empty_file; - return copy; + auto copy = make_uniq(op.types, op.function, std::move(op.bind_data), + op.estimated_cardinality); + copy->file_path = op.file_path; + copy->use_tmp_file = op.use_tmp_file; + copy->children.push_back(std::move(plan)); + copy->return_type = op.return_type; + return std::move(copy); } // COPY from select statement to file - auto © = Make(op.types, op.function, std::move(op.bind_data), op.estimated_cardinality); - - auto &cast_copy = copy.Cast(); - cast_copy.file_path = op.file_path; - cast_copy.use_tmp_file = op.use_tmp_file; - cast_copy.overwrite_mode = op.overwrite_mode; - cast_copy.filename_pattern = op.filename_pattern; - cast_copy.file_extension = op.file_extension; - cast_copy.per_thread_output = op.per_thread_output; - + auto copy = make_uniq(op.types, op.function, std::move(op.bind_data), op.estimated_cardinality); + copy->file_path = op.file_path; + copy->use_tmp_file = op.use_tmp_file; + copy->overwrite_mode = op.overwrite_mode; + copy->filename_pattern = op.filename_pattern; + copy->file_extension = op.file_extension; + copy->per_thread_output = op.per_thread_output; if (op.file_size_bytes.IsValid()) { - cast_copy.file_size_bytes = op.file_size_bytes; + copy->file_size_bytes = op.file_size_bytes; } + copy->rotate = op.rotate; + copy->return_type = op.return_type; + copy->partition_output = op.partition_output; + copy->partition_columns = op.partition_columns; + copy->write_partition_columns = op.write_partition_columns; + copy->names = op.names; + copy->expected_types = op.expected_types; + copy->parallel = mode == CopyFunctionExecutionMode::PARALLEL_COPY_TO_FILE; - cast_copy.rotate = op.rotate; - cast_copy.return_type = op.return_type; - cast_copy.partition_output = op.partition_output; - cast_copy.partition_columns = op.partition_columns; - cast_copy.write_partition_columns = op.write_partition_columns; - cast_copy.names = op.names; - cast_copy.expected_types = op.expected_types; - cast_copy.parallel = mode == CopyFunctionExecutionMode::PARALLEL_COPY_TO_FILE; - cast_copy.write_empty_file = op.write_empty_file; - - cast_copy.children.push_back(plan); - return copy; + copy->children.push_back(std::move(plan)); + return std::move(copy); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_create.cpp b/src/duckdb/src/execution/physical_plan/plan_create.cpp index 4d6acc339..42a1652e6 100644 --- a/src/duckdb/src/execution/physical_plan/plan_create.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_create.cpp @@ -10,27 +10,27 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCreate &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCreate &op) { switch (op.type) { case LogicalOperatorType::LOGICAL_CREATE_SEQUENCE: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_CREATE_VIEW: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_CREATE_SCHEMA: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_CREATE_MACRO: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_CREATE_TYPE: { - auto &create = Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + unique_ptr create = make_uniq( + unique_ptr_cast(std::move(op.info)), op.estimated_cardinality); if (!op.children.empty()) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); - create.children.push_back(plan); + auto plan = CreatePlan(*op.children[0]); + create->children.push_back(std::move(plan)); } return create; } diff --git a/src/duckdb/src/execution/physical_plan/plan_create_index.cpp b/src/duckdb/src/execution/physical_plan/plan_create_index.cpp index be7d7159f..ef38c6971 100644 --- a/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_create_index.cpp @@ -10,7 +10,7 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCreateIndex &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCreateIndex &op) { // Early-out, if the index already exists. auto &schema = op.table.schema; auto entry = schema.GetEntry(schema.GetCatalogTransaction(context), CatalogType::INDEX_ENTRY, op.info->index_name); @@ -18,7 +18,7 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCreateIndex &op) { if (op.info->on_conflict != OnCreateConflict::IGNORE_ON_CONFLICT) { throw CatalogException("Index with name \"%s\" already exists!", op.info->index_name); } - return Make(op.types, op.estimated_cardinality); + return make_uniq(op.types, op.estimated_cardinality); } // Ensure that all expressions contain valid scalar functions. @@ -47,9 +47,9 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCreateIndex &op) { // Generate a physical plan for the parallel index creation. // TABLE SCAN - PROJECTION - (optional) NOT NULL FILTER - (optional) ORDER BY - CREATE INDEX D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); + auto table_scan = CreatePlan(*op.children[0]); - PlanIndexInput input(context, op, *this, plan); + PlanIndexInput input(context, op, table_scan); return index_type->create_plan(input); } diff --git a/src/duckdb/src/execution/physical_plan/plan_create_secret.cpp b/src/duckdb/src/execution/physical_plan/plan_create_secret.cpp index 94ebf53fb..b4818c809 100644 --- a/src/duckdb/src/execution/physical_plan/plan_create_secret.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_create_secret.cpp @@ -4,8 +4,8 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCreateSecret &op) { - return Make(op.secret_input, op.estimated_cardinality); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCreateSecret &op) { + return make_uniq(op.info, op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_create_table.cpp b/src/duckdb/src/execution/physical_plan/plan_create_table.cpp index c8688450d..06b728ee4 100644 --- a/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_create_table.cpp @@ -15,36 +15,37 @@ namespace duckdb { -PhysicalOperator &DuckCatalog::PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, - LogicalCreateTable &op, PhysicalOperator &plan) { - bool parallel_streaming_insert = !PhysicalPlanGenerator::PreserveInsertionOrder(context, plan); - bool use_batch_index = PhysicalPlanGenerator::UseBatchIndex(context, plan); +unique_ptr DuckCatalog::PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op, + unique_ptr plan) { + bool parallel_streaming_insert = !PhysicalPlanGenerator::PreserveInsertionOrder(context, *plan); + bool use_batch_index = PhysicalPlanGenerator::UseBatchIndex(context, *plan); auto num_threads = TaskScheduler::GetScheduler(context).NumberOfThreads(); + unique_ptr create; if (!parallel_streaming_insert && use_batch_index) { - auto &insert = planner.Make(op, op.schema, std::move(op.info), 0U); - D_ASSERT(op.children.size() == 1); - insert.children.push_back(plan); - return insert; + create = make_uniq(op, op.schema, std::move(op.info), 0U); + + } else { + create = make_uniq(op, op.schema, std::move(op.info), 0U, + parallel_streaming_insert && num_threads > 1); } - auto parallel = parallel_streaming_insert && num_threads > 1; - auto &insert = planner.Make(op, op.schema, std::move(op.info), 0U, parallel); D_ASSERT(op.children.size() == 1); - insert.children.push_back(plan); - return insert; + create->children.push_back(std::move(plan)); + return create; } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCreateTable &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCreateTable &op) { const auto &create_info = op.info->base->Cast(); auto &catalog = op.info->schema.catalog; - auto existing_entry = catalog.GetEntry(context, CatalogType::TABLE_ENTRY, create_info.schema, create_info.table, - OnEntryNotFound::RETURN_NULL); + auto existing_entry = catalog.GetEntry(context, create_info.schema, create_info.table, + OnEntryNotFound::RETURN_NULL); bool replace = op.info->Base().on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT; if ((!existing_entry || replace) && !op.children.empty()) { - auto &plan = CreatePlan(*op.children[0]); - return op.schema.catalog.PlanCreateTableAs(context, *this, op, plan); + auto plan = CreatePlan(*op.children[0]); + return op.schema.catalog.PlanCreateTableAs(context, op, std::move(plan)); + } else { + return make_uniq(op, op.schema, std::move(op.info), op.estimated_cardinality); } - return Make(op, op.schema, std::move(op.info), op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_cross_product.cpp b/src/duckdb/src/execution/physical_plan/plan_cross_product.cpp index e27b8f6d5..dac220706 100644 --- a/src/duckdb/src/execution/physical_plan/plan_cross_product.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_cross_product.cpp @@ -4,11 +4,12 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCrossProduct &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCrossProduct &op) { D_ASSERT(op.children.size() == 2); - auto &left = CreatePlan(*op.children[0]); - auto &right = CreatePlan(*op.children[1]); - return Make(op.types, left, right, op.estimated_cardinality); + + auto left = CreatePlan(*op.children[0]); + auto right = CreatePlan(*op.children[1]); + return make_uniq(op.types, std::move(left), std::move(right), op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_cte.cpp b/src/duckdb/src/execution/physical_plan/plan_cte.cpp index a1937f408..9c6596279 100644 --- a/src/duckdb/src/execution/physical_plan/plan_cte.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_cte.cpp @@ -8,7 +8,7 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalMaterializedCTE &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalMaterializedCTE &op) { D_ASSERT(op.children.size() == 2); // Create the working_table that the PhysicalCTE will use for evaluation. @@ -19,15 +19,17 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalMaterializedCTE &op) materialized_ctes[op.table_index] = vector>(); // Create the plan for the left side. This is the materialization. - auto &left = CreatePlan(*op.children[0]); + auto left = CreatePlan(*op.children[0]); // Initialize an empty vector to collect the scan operators. - auto &right = CreatePlan(*op.children[1]); + auto right = CreatePlan(*op.children[1]); - auto &cte = Make(op.ctename, op.table_index, right.types, left, right, op.estimated_cardinality); - auto &cast_cte = cte.Cast(); - cast_cte.working_table = working_table; - cast_cte.cte_scans = materialized_ctes[op.table_index]; - return cte; + unique_ptr cte; + cte = make_uniq(op.ctename, op.table_index, right->types, std::move(left), std::move(right), + op.estimated_cardinality); + cte->working_table = working_table; + cte->cte_scans = materialized_ctes[op.table_index]; + + return std::move(cte); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_delete.cpp b/src/duckdb/src/execution/physical_plan/plan_delete.cpp index 96a6f2dc1..d6afee808 100644 --- a/src/duckdb/src/execution/physical_plan/plan_delete.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_delete.cpp @@ -7,26 +7,26 @@ namespace duckdb { -PhysicalOperator &DuckCatalog::PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op, - PhysicalOperator &plan) { - // Get the row_id column index. +unique_ptr DuckCatalog::PlanDelete(ClientContext &context, LogicalDelete &op, + unique_ptr plan) { + // get the index of the row_id column auto &bound_ref = op.expressions[0]->Cast(); - auto &del = planner.Make(op.types, op.table, op.table.GetStorage(), std::move(op.bound_constraints), - bound_ref.index, op.estimated_cardinality, op.return_chunk); - del.children.push_back(plan); - return del; -} -PhysicalOperator &Catalog::PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op) { - auto &plan = planner.CreatePlan(*op.children[0]); - return PlanDelete(context, planner, op, plan); + auto del = make_uniq(op.types, op.table, op.table.GetStorage(), std::move(op.bound_constraints), + bound_ref.index, op.estimated_cardinality, op.return_chunk); + del->children.push_back(std::move(plan)); + return std::move(del); } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalDelete &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalDelete &op) { D_ASSERT(op.children.size() == 1); + D_ASSERT(op.expressions.size() == 1); + D_ASSERT(op.expressions[0]->GetExpressionType() == ExpressionType::BOUND_REF); + + auto plan = CreatePlan(*op.children[0]); dependencies.AddDependency(op.table); - return op.table.catalog.PlanDelete(context, *this, op); + return op.table.catalog.PlanDelete(context, op, std::move(plan)); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_delim_get.cpp b/src/duckdb/src/execution/physical_plan/plan_delim_get.cpp index 2e1d45109..1b45efe21 100644 --- a/src/duckdb/src/execution/physical_plan/plan_delim_get.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_delim_get.cpp @@ -4,11 +4,13 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalDelimGet &op) { - // Create a PhysicalChunkScan without an owned_collection. - // We'll add the collection later. +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalDelimGet &op) { D_ASSERT(op.children.empty()); - return Make(op.types, PhysicalOperatorType::DELIM_SCAN, op.estimated_cardinality, nullptr); + + // create a PhysicalChunkScan without an owned_collection, the collection will be added later + auto chunk_scan = make_uniq(op.types, PhysicalOperatorType::DELIM_SCAN, + op.estimated_cardinality, nullptr); + return std::move(chunk_scan); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp b/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp index 27a9de5e6..9755f8330 100644 --- a/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp @@ -19,20 +19,20 @@ static void GatherDelimScans(PhysicalOperator &op, vector PhysicalPlanGenerator::PlanDelimJoin(LogicalComparisonJoin &op) { // first create the underlying join - auto &plan = PlanComparisonJoin(op); + auto plan = PlanComparisonJoin(op); // this should create a join, not a cross product - D_ASSERT(plan.type != PhysicalOperatorType::CROSS_PRODUCT); + D_ASSERT(plan && plan->type != PhysicalOperatorType::CROSS_PRODUCT); // duplicate eliminated join // first gather the scans on the duplicate eliminated data set from the delim side const idx_t delim_idx = op.delim_flipped ? 0 : 1; vector> delim_scans; - GatherDelimScans(plan.children[delim_idx], delim_scans, ++this->delim_index); + GatherDelimScans(*plan->children[delim_idx], delim_scans, ++this->delim_index); if (delim_scans.empty()) { // no duplicate eliminated scans in the delim side! // in this case we don't need to create a delim join @@ -47,18 +47,20 @@ PhysicalOperator &PhysicalPlanGenerator::PlanDelimJoin(LogicalComparisonJoin &op delim_types.push_back(bound_ref.return_type); distinct_groups.push_back(make_uniq(bound_ref.return_type, bound_ref.index)); } - - // we still have to create the DISTINCT clause that is used to generate the duplicate eliminated chunk - auto &distinct = Make(context, delim_types, std::move(distinct_expressions), - std::move(distinct_groups), op.estimated_cardinality); - - // Create the duplicate eliminated join. + // now create the duplicate eliminated join + unique_ptr delim_join; if (op.delim_flipped) { - return Make(*this, op.types, plan, distinct, delim_scans, op.estimated_cardinality, - optional_idx(this->delim_index)); + delim_join = make_uniq(op.types, std::move(plan), delim_scans, op.estimated_cardinality, + optional_idx(this->delim_index)); + } else { + delim_join = make_uniq(op.types, std::move(plan), delim_scans, op.estimated_cardinality, + optional_idx(this->delim_index)); } - return Make(*this, op.types, plan, distinct, delim_scans, op.estimated_cardinality, - optional_idx(this->delim_index)); + // we still have to create the DISTINCT clause that is used to generate the duplicate eliminated chunk + delim_join->distinct = make_uniq(context, delim_types, std::move(distinct_expressions), + std::move(distinct_groups), op.estimated_cardinality); + + return std::move(delim_join); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_distinct.cpp b/src/duckdb/src/execution/physical_plan/plan_distinct.cpp index f1b8aec47..60fdb6584 100644 --- a/src/duckdb/src/execution/physical_plan/plan_distinct.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_distinct.cpp @@ -10,13 +10,14 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalDistinct &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalDistinct &op) { D_ASSERT(op.children.size() == 1); - reference child = CreatePlan(*op.children[0]); + auto child = CreatePlan(*op.children[0]); auto &distinct_targets = op.distinct_targets; + D_ASSERT(child); D_ASSERT(!distinct_targets.empty()); - auto &types = child.get().GetTypes(); + auto &types = child->GetTypes(); vector> groups, aggregates, projections; idx_t group_count = distinct_targets.size(); unordered_map group_by_references; @@ -81,20 +82,20 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalDistinct &op) { } } - child = ExtractAggregateExpressions(child, aggregates, groups); + child = ExtractAggregateExpressions(std::move(child), aggregates, groups); // we add a physical hash aggregation in the plan to select the distinct groups - auto &group_by = Make(context, aggregate_types, std::move(aggregates), std::move(groups), - child.get().estimated_cardinality); - group_by.children.push_back(child); + auto groupby = make_uniq(context, aggregate_types, std::move(aggregates), std::move(groups), + child->estimated_cardinality); + groupby->children.push_back(std::move(child)); if (!requires_projection) { - return group_by; + return std::move(groupby); } // we add a physical projection on top of the aggregation to project all members in the select list - auto &proj = Make(types, std::move(projections), group_by.estimated_cardinality); - proj.children.push_back(group_by); - return proj; + auto aggr_projection = make_uniq(types, std::move(projections), groupby->estimated_cardinality); + aggr_projection->children.push_back(std::move(groupby)); + return std::move(aggr_projection); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_dummy_scan.cpp b/src/duckdb/src/execution/physical_plan/plan_dummy_scan.cpp index e1305d574..ed561cf4e 100644 --- a/src/duckdb/src/execution/physical_plan/plan_dummy_scan.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_dummy_scan.cpp @@ -4,9 +4,9 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalDummyScan &op) { - D_ASSERT(op.children.empty()); - return Make(op.types, op.estimated_cardinality); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalDummyScan &op) { + D_ASSERT(op.children.size() == 0); + return make_uniq(op.types, op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_empty_result.cpp b/src/duckdb/src/execution/physical_plan/plan_empty_result.cpp index afbc13504..7313f034a 100644 --- a/src/duckdb/src/execution/physical_plan/plan_empty_result.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_empty_result.cpp @@ -4,9 +4,9 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalEmptyResult &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalEmptyResult &op) { D_ASSERT(op.children.size() == 0); - return Make(op.types, op.estimated_cardinality); + return make_uniq(op.types, op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_execute.cpp b/src/duckdb/src/execution/physical_plan/plan_execute.cpp index 66a0ca033..735cf9fc1 100644 --- a/src/duckdb/src/execution/physical_plan/plan_execute.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_execute.cpp @@ -4,18 +4,18 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalExecute &op) { - if (op.prepared->physical_plan) { - D_ASSERT(op.children.empty()); - return Make(op.prepared->physical_plan->Root()); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalExecute &op) { + if (!op.prepared->plan) { + D_ASSERT(op.children.size() == 1); + auto owned_plan = CreatePlan(*op.children[0]); + auto execute = make_uniq(*owned_plan); + execute->owned_plan = std::move(owned_plan); + execute->prepared = std::move(op.prepared); + return std::move(execute); + } else { + D_ASSERT(op.children.size() == 0); + return make_uniq(*op.prepared->plan); } - - D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); - auto &execute = Make(plan); - auto &cast_execute = execute.Cast(); - cast_execute.prepared = op.prepared; - return execute; } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_explain.cpp b/src/duckdb/src/execution/physical_plan/plan_explain.cpp index 2bb227077..3f9d2a4b4 100644 --- a/src/duckdb/src/execution/physical_plan/plan_explain.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_explain.cpp @@ -8,18 +8,18 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalExplain &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalExplain &op) { D_ASSERT(op.children.size() == 1); auto logical_plan_opt = op.children[0]->ToString(op.explain_format); - auto &plan = CreatePlan(*op.children[0]); + auto plan = CreatePlan(*op.children[0]); if (op.explain_type == ExplainType::EXPLAIN_ANALYZE) { - auto &explain = Make(op.types, op.explain_format); - explain.children.push_back(plan); - return explain; + auto result = make_uniq(op.types, op.explain_format); + result->children.push_back(std::move(plan)); + return std::move(result); } - // Format the plan and set the output of the EXPLAIN. - op.physical_plan = plan.ToString(op.explain_format); + op.physical_plan = plan->ToString(op.explain_format); + // the output of the explain vector keys, values; switch (ClientConfig::GetConfig(context).explain_output_type) { case ExplainOutputType::OPTIMIZED_ONLY: @@ -35,7 +35,7 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalExplain &op) { values = {op.logical_plan_unopt, logical_plan_opt, op.physical_plan}; } - // Create a ColumnDataCollection from the output. + // create a ColumnDataCollection from the output auto &allocator = Allocator::Get(context); vector plan_types {LogicalType::VARCHAR, LogicalType::VARCHAR}; auto collection = @@ -54,9 +54,10 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalExplain &op) { } collection->Append(chunk); - // Output the result via a chunk scan. - return Make(op.types, PhysicalOperatorType::COLUMN_DATA_SCAN, op.estimated_cardinality, - std::move(collection)); + // create a chunk scan to output the result + auto chunk_scan = make_uniq(op.types, PhysicalOperatorType::COLUMN_DATA_SCAN, + op.estimated_cardinality, std::move(collection)); + return std::move(chunk_scan); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_export.cpp b/src/duckdb/src/execution/physical_plan/plan_export.cpp index 7cdff2341..ff04115e3 100644 --- a/src/duckdb/src/execution/physical_plan/plan_export.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_export.cpp @@ -5,15 +5,15 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalExport &op) { - auto &export_op = Make(op.types, op.function, std::move(op.copy_info), op.estimated_cardinality, - std::move(op.exported_tables)); - // Plan the underlying copy statements, if any. +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalExport &op) { + auto export_node = make_uniq(op.types, op.function, std::move(op.copy_info), + op.estimated_cardinality, std::move(op.exported_tables)); + // plan the underlying copy statements, if any if (!op.children.empty()) { - auto &plan = CreatePlan(*op.children[0]); - export_op.children.push_back(plan); + auto plan = CreatePlan(*op.children[0]); + export_node->children.push_back(std::move(plan)); } - return export_op; + return std::move(export_node); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_expression_get.cpp b/src/duckdb/src/execution/physical_plan/plan_expression_get.cpp index 62aaacccd..b63726742 100644 --- a/src/duckdb/src/execution/physical_plan/plan_expression_get.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_expression_get.cpp @@ -6,37 +6,33 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalExpressionGet &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalExpressionGet &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); + auto plan = CreatePlan(*op.children[0]); - auto &expr_scan = Make(op.types, std::move(op.expressions), op.estimated_cardinality); - expr_scan.children.push_back(plan); - - auto &cast_expr_scan = expr_scan.Cast(); - if (!cast_expr_scan.IsFoldable()) { - return expr_scan; + auto expr_scan = make_uniq(op.types, std::move(op.expressions), op.estimated_cardinality); + expr_scan->children.push_back(std::move(plan)); + if (!expr_scan->IsFoldable()) { + return std::move(expr_scan); } - auto &allocator = Allocator::Get(context); // simple expression scan (i.e. no subqueries to evaluate and no prepared statement parameters) // we can evaluate all the expressions right now and turn this into a chunk collection scan - auto &chunk_scan = Make(op.types, PhysicalOperatorType::COLUMN_DATA_SCAN, - cast_expr_scan.expressions.size(), - make_uniq(context, op.types)); - auto &cast_chunk_scan = chunk_scan.Cast(); + auto chunk_scan = make_uniq(op.types, PhysicalOperatorType::COLUMN_DATA_SCAN, + expr_scan->expressions.size(), + make_uniq(context, op.types)); DataChunk chunk; chunk.Initialize(allocator, op.types); ColumnDataAppendState append_state; - cast_chunk_scan.collection->InitializeAppend(append_state); - for (idx_t expression_idx = 0; expression_idx < cast_expr_scan.expressions.size(); expression_idx++) { + chunk_scan->collection->InitializeAppend(append_state); + for (idx_t expression_idx = 0; expression_idx < expr_scan->expressions.size(); expression_idx++) { chunk.Reset(); - cast_expr_scan.EvaluateExpression(context, expression_idx, nullptr, chunk); - cast_chunk_scan.collection->Append(append_state, chunk); + expr_scan->EvaluateExpression(context, expression_idx, nullptr, chunk); + chunk_scan->collection->Append(append_state, chunk); } - return chunk_scan; + return std::move(chunk_scan); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_filter.cpp b/src/duckdb/src/execution/physical_plan/plan_filter.cpp index 292fe1bc8..50c1253d0 100644 --- a/src/duckdb/src/execution/physical_plan/plan_filter.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_filter.cpp @@ -10,15 +10,15 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalFilter &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalFilter &op) { D_ASSERT(op.children.size() == 1); - reference plan = CreatePlan(*op.children[0]); + unique_ptr plan = CreatePlan(*op.children[0]); if (!op.expressions.empty()) { - D_ASSERT(!plan.get().GetTypes().empty()); + D_ASSERT(plan->types.size() > 0); // create a filter if there is anything to filter - auto &filter = Make(plan.get().GetTypes(), std::move(op.expressions), op.estimated_cardinality); - filter.children.push_back(plan); - plan = filter; + auto filter = make_uniq(plan->types, std::move(op.expressions), op.estimated_cardinality); + filter->children.push_back(std::move(plan)); + plan = std::move(filter); } if (op.HasProjectionMap()) { // there is a projection map, generate a physical projection @@ -26,9 +26,9 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalFilter &op) { for (idx_t i = 0; i < op.projection_map.size(); i++) { select_list.push_back(make_uniq(op.types[i], op.projection_map[i])); } - auto &proj = Make(op.types, std::move(select_list), op.estimated_cardinality); - proj.children.push_back(plan); - plan = proj; + auto proj = make_uniq(op.types, std::move(select_list), op.estimated_cardinality); + proj->children.push_back(std::move(plan)); + plan = std::move(proj); } return plan; } diff --git a/src/duckdb/src/execution/physical_plan/plan_get.cpp b/src/duckdb/src/execution/physical_plan/plan_get.cpp index 342c43fb4..3b5d940eb 100644 --- a/src/duckdb/src/execution/physical_plan/plan_get.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_get.cpp @@ -34,28 +34,25 @@ unique_ptr CreateTableFilterSet(TableFilterSet &table_filters, c return table_filter_set; } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalGet &op) { auto column_ids = op.GetColumnIds(); if (!op.children.empty()) { - reference child = ResolveAndPlan(std::move(op.children[0])); - auto &child_types = child.get().types; - + auto child_node = CreatePlan(std::move(op.children[0])); // this is for table producing functions that consume subquery results // push a projection node with casts if required - if (child_types.size() < op.input_table_types.size()) { + if (child_node->types.size() < op.input_table_types.size()) { throw InternalException( "Mismatch between input table types and child node types - expected %llu but got %llu", - op.input_table_types.size(), child_types.size()); + op.input_table_types.size(), child_node->types.size()); } - vector return_types; vector> expressions; bool any_cast_required = false; - for (idx_t proj_idx = 0; proj_idx < child_types.size(); proj_idx++) { - auto ref = make_uniq(child_types[proj_idx], proj_idx); + for (idx_t proj_idx = 0; proj_idx < child_node->types.size(); proj_idx++) { + auto ref = make_uniq(child_node->types[proj_idx], proj_idx); auto &target_type = - proj_idx < op.input_table_types.size() ? op.input_table_types[proj_idx] : child_types[proj_idx]; - if (child_types[proj_idx] != target_type) { + proj_idx < op.input_table_types.size() ? op.input_table_types[proj_idx] : child_node->types[proj_idx]; + if (child_node->types[proj_idx] != target_type) { // cast is required - push a cast any_cast_required = true; auto cast = BoundCastExpression::AddCastToType(context, std::move(ref), target_type); @@ -65,21 +62,18 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) { } return_types.push_back(target_type); } - if (any_cast_required) { - auto &proj = Make(std::move(return_types), std::move(expressions), - child.get().estimated_cardinality); - proj.children.push_back(child); - child = proj; + auto proj = make_uniq(std::move(return_types), std::move(expressions), + child_node->estimated_cardinality); + proj->children.push_back(std::move(child_node)); + child_node = std::move(proj); } - auto &table_in_out = - Make(op.types, op.function, std::move(op.bind_data), column_ids, - op.estimated_cardinality, std::move(op.projected_input)); - table_in_out.children.push_back(child); - return table_in_out; + auto node = make_uniq(op.types, op.function, std::move(op.bind_data), column_ids, + op.estimated_cardinality, std::move(op.projected_input)); + node->children.push_back(std::move(child_node)); + return std::move(node); } - if (!op.projected_input.empty()) { throw InternalException("LogicalGet::project_input can only be set for table-in-out functions"); } @@ -92,8 +86,8 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) { if (op.function.dependency) { op.function.dependency(dependencies, op.bind_data.get()); } + unique_ptr filter; - optional_ptr filter; auto &projection_ids = op.projection_ids; if (table_filters && op.function.supports_pushdown_type) { @@ -132,17 +126,16 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) { auto column_id = column_ids[c].GetPrimaryIndex(); filter_types.push_back(op.returned_types[column_id]); } - filter = Make(filter_types, std::move(select_list), op.estimated_cardinality); + filter = make_uniq(filter_types, std::move(select_list), op.estimated_cardinality); } } op.ResolveOperatorTypes(); // create the table scan node if (!op.function.projection_pushdown) { // function does not support projection pushdown - auto &table_scan = Make(op.returned_types, op.function, std::move(op.bind_data), - op.returned_types, column_ids, vector(), op.names, - std::move(table_filters), op.estimated_cardinality, op.extra_info, - std::move(op.parameters), std::move(op.virtual_columns)); + auto node = make_uniq( + op.returned_types, op.function, std::move(op.bind_data), op.returned_types, column_ids, vector(), + op.names, std::move(table_filters), op.estimated_cardinality, op.extra_info, std::move(op.parameters)); // first check if an additional projection is necessary if (column_ids.size() == op.returned_types.size()) { bool projection_necessary = false; @@ -156,18 +149,20 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) { // a projection is not necessary if all columns have been requested in-order // in that case we just return the node if (filter) { - filter->children.push_back(table_scan); - return *filter; + filter->children.push_back(std::move(node)); + return std::move(filter); } - return table_scan; + return std::move(node); } } // push a projection on top that does the projection vector types; vector> expressions; for (auto &column_id : column_ids) { - if (column_id.IsVirtualColumn()) { - throw NotImplementedException("Virtual columns require projection pushdown"); + if (column_id.IsRowIdColumn()) { + types.emplace_back(op.GetRowIdType()); + // Now how to make that a constant expression. + expressions.push_back(make_uniq(Value(op.GetRowIdType()))); } else { auto col_id = column_id.GetPrimaryIndex(); auto type = op.returned_types[col_id]; @@ -175,27 +170,26 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalGet &op) { expressions.push_back(make_uniq(type, col_id)); } } - auto &proj = Make(std::move(types), std::move(expressions), op.estimated_cardinality); + unique_ptr projection = + make_uniq(std::move(types), std::move(expressions), op.estimated_cardinality); if (filter) { - filter->children.push_back(table_scan); - proj.children.push_back(*filter); - return proj; + filter->children.push_back(std::move(node)); + projection->children.push_back(std::move(filter)); + } else { + projection->children.push_back(std::move(node)); } - proj.children.push_back(table_scan); - return proj; - } - - auto &table_scan = - Make(op.types, op.function, std::move(op.bind_data), op.returned_types, column_ids, - op.projection_ids, op.names, std::move(table_filters), op.estimated_cardinality, - op.extra_info, std::move(op.parameters), std::move(op.virtual_columns)); - auto &cast_table_scan = table_scan.Cast(); - cast_table_scan.dynamic_filters = op.dynamic_filters; - if (filter) { - filter->children.push_back(table_scan); - return *filter; + return std::move(projection); + } else { + auto node = make_uniq(op.types, op.function, std::move(op.bind_data), op.returned_types, + column_ids, op.projection_ids, op.names, std::move(table_filters), + op.estimated_cardinality, op.extra_info, std::move(op.parameters)); + node->dynamic_filters = op.dynamic_filters; + if (filter) { + filter->children.push_back(std::move(node)); + return std::move(filter); + } + return std::move(node); } - return table_scan; } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_insert.cpp b/src/duckdb/src/execution/physical_plan/plan_insert.cpp index f726eb4ec..6e593c63b 100644 --- a/src/duckdb/src/execution/physical_plan/plan_insert.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_insert.cpp @@ -2,12 +2,11 @@ #include "duckdb/execution/operator/persistent/physical_insert.hpp" #include "duckdb/execution/physical_plan_generator.hpp" #include "duckdb/planner/operator/logical_insert.hpp" +#include "duckdb/storage/data_table.hpp" #include "duckdb/main/config.hpp" #include "duckdb/execution/operator/persistent/physical_batch_insert.hpp" -#include "duckdb/execution/operator/projection/physical_projection.hpp" #include "duckdb/parallel/task_scheduler.hpp" #include "duckdb/catalog/duck_catalog.hpp" -#include "duckdb/planner/expression/bound_reference_expression.hpp" namespace duckdb { @@ -22,7 +21,7 @@ OrderPreservationType PhysicalPlanGenerator::OrderPreservationRecursive(Physical if (op.type == PhysicalOperatorType::CTE && child_idx == 0) { continue; } - auto child_preservation = OrderPreservationRecursive(child); + auto child_preservation = OrderPreservationRecursive(*child); if (child_preservation != OrderPreservationType::INSERTION_ORDER) { return child_preservation; } @@ -73,33 +72,8 @@ bool PhysicalPlanGenerator::UseBatchIndex(PhysicalOperator &plan) { return UseBatchIndex(context, plan); } -PhysicalOperator &PhysicalPlanGenerator::ResolveDefaultsProjection(LogicalInsert &op, PhysicalOperator &child) { - if (op.column_index_map.empty()) { - throw InternalException("No defaults to push"); - } - // columns specified by the user, push a projection - vector types; - vector> select_list; - for (auto &col : op.table.GetColumns().Physical()) { - auto storage_idx = col.StorageOid(); - auto mapped_index = op.column_index_map[col.Physical()]; - if (mapped_index == DConstants::INVALID_INDEX) { - // push default value - select_list.push_back(std::move(op.bound_defaults[storage_idx])); - } else { - // push reference - select_list.push_back(make_uniq(col.Type(), mapped_index)); - } - types.push_back(col.Type()); - } - auto &proj = Make(std::move(types), std::move(select_list), child.estimated_cardinality); - proj.children.push_back(child); - return proj; -} - -PhysicalOperator &DuckCatalog::PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op, - optional_ptr plan) { - D_ASSERT(plan); +unique_ptr DuckCatalog::PlanInsert(ClientContext &context, LogicalInsert &op, + unique_ptr plan) { bool parallel_streaming_insert = !PhysicalPlanGenerator::PreserveInsertionOrder(context, *plan); bool use_batch_index = PhysicalPlanGenerator::UseBatchIndex(context, *plan); auto num_threads = TaskScheduler::GetScheduler(context).NumberOfThreads(); @@ -117,34 +91,31 @@ PhysicalOperator &DuckCatalog::PlanInsert(ClientContext &context, PhysicalPlanGe // that currently needs to be done for every chunk, which would add a huge bottleneck to parallelized insertion parallel_streaming_insert = false; } - if (!op.column_index_map.empty()) { - plan = planner.ResolveDefaultsProjection(op, *plan); - } + unique_ptr insert; if (use_batch_index && !parallel_streaming_insert) { - auto &insert = planner.Make(op.types, op.table, std::move(op.bound_constraints), - op.estimated_cardinality); - insert.children.push_back(*plan); - return insert; + insert = make_uniq(op.types, op.table, op.column_index_map, std::move(op.bound_defaults), + std::move(op.bound_constraints), op.estimated_cardinality); + } else { + insert = make_uniq( + op.types, op.table, op.column_index_map, std::move(op.bound_defaults), std::move(op.bound_constraints), + std::move(op.expressions), std::move(op.set_columns), std::move(op.set_types), op.estimated_cardinality, + op.return_chunk, parallel_streaming_insert && num_threads > 1, op.action_type, + std::move(op.on_conflict_condition), std::move(op.do_update_condition), std::move(op.on_conflict_filter), + std::move(op.columns_to_fetch), op.update_is_del_and_insert); } - - auto &insert = planner.Make( - op.types, op.table, std::move(op.bound_constraints), std::move(op.expressions), std::move(op.set_columns), - std::move(op.set_types), op.estimated_cardinality, op.return_chunk, - parallel_streaming_insert && num_threads > 1, op.action_type, std::move(op.on_conflict_condition), - std::move(op.do_update_condition), std::move(op.on_conflict_filter), std::move(op.columns_to_fetch), - op.update_is_del_and_insert); - insert.children.push_back(*plan); + D_ASSERT(plan); + insert->children.push_back(std::move(plan)); return insert; } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalInsert &op) { - optional_ptr plan; +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalInsert &op) { + unique_ptr plan; if (!op.children.empty()) { D_ASSERT(op.children.size() == 1); plan = CreatePlan(*op.children[0]); } dependencies.AddDependency(op.table); - return op.table.catalog.PlanInsert(context, *this, op, plan); + return op.table.catalog.PlanInsert(context, op, std::move(plan)); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_limit.cpp b/src/duckdb/src/execution/physical_plan/plan_limit.cpp index 4ad7fc945..508f1c889 100644 --- a/src/duckdb/src/execution/physical_plan/plan_limit.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_limit.cpp @@ -21,7 +21,7 @@ bool UseBatchLimit(PhysicalOperator &child_node, BoundLimitNode &limit_val, Boun case PhysicalOperatorType::TABLE_SCAN: return false; case PhysicalOperatorType::PROJECTION: - current_ref = current_op.children[0]; + current_ref = *current_op.children[0]; break; default: finished = true; @@ -46,43 +46,40 @@ bool UseBatchLimit(PhysicalOperator &child_node, BoundLimitNode &limit_val, Boun #endif } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalLimit &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalLimit &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); + auto plan = CreatePlan(*op.children[0]); + + unique_ptr limit; switch (op.limit_val.Type()) { case LimitNodeType::EXPRESSION_PERCENTAGE: - case LimitNodeType::CONSTANT_PERCENTAGE: { - auto &limit = Make(op.types, std::move(op.limit_val), std::move(op.offset_val), - op.estimated_cardinality); - limit.children.push_back(plan); - return limit; - } - default: { - if (!PreserveInsertionOrder(plan)) { + case LimitNodeType::CONSTANT_PERCENTAGE: + limit = make_uniq(op.types, std::move(op.limit_val), std::move(op.offset_val), + op.estimated_cardinality); + break; + default: + if (!PreserveInsertionOrder(*plan)) { // use parallel streaming limit if insertion order is not important - auto &limit = Make(op.types, std::move(op.limit_val), std::move(op.offset_val), - op.estimated_cardinality, true); - limit.children.push_back(plan); - return limit; - } - - // maintaining insertion order is important - if (UseBatchIndex(plan) && UseBatchLimit(plan, op.limit_val, op.offset_val)) { - // source supports batch index: use parallel batch limit - auto &limit = Make(op.types, std::move(op.limit_val), std::move(op.offset_val), - op.estimated_cardinality); - limit.children.push_back(plan); - return limit; + limit = make_uniq(op.types, std::move(op.limit_val), std::move(op.offset_val), + op.estimated_cardinality, true); + } else { + // maintaining insertion order is important + if (UseBatchIndex(*plan) && UseBatchLimit(*plan, op.limit_val, op.offset_val)) { + // source supports batch index: use parallel batch limit + limit = make_uniq(op.types, std::move(op.limit_val), std::move(op.offset_val), + op.estimated_cardinality); + } else { + // source does not support batch index: use a non-parallel streaming limit + limit = make_uniq(op.types, std::move(op.limit_val), std::move(op.offset_val), + op.estimated_cardinality, false); + } } - - // source does not support batch index: use a non-parallel streaming limit - auto &limit = Make(op.types, std::move(op.limit_val), std::move(op.offset_val), - op.estimated_cardinality, false); - limit.children.push_back(plan); - return limit; - } + break; } + + limit->children.push_back(std::move(plan)); + return limit; } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_order.cpp b/src/duckdb/src/execution/physical_plan/plan_order.cpp index 7281308fd..449e7ee81 100644 --- a/src/duckdb/src/execution/physical_plan/plan_order.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_order.cpp @@ -4,26 +4,25 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalOrder &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalOrder &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); - if (op.orders.empty()) { - return plan; - } - - vector projection_map; - if (op.HasProjectionMap()) { - projection_map = std::move(op.projection_map); - } else { - for (idx_t i = 0; i < plan.types.size(); i++) { - projection_map.push_back(i); + auto plan = CreatePlan(*op.children[0]); + if (!op.orders.empty()) { + vector projection_map; + if (op.HasProjectionMap()) { + projection_map = std::move(op.projection_map); + } else { + for (idx_t i = 0; i < plan->types.size(); i++) { + projection_map.push_back(i); + } } + auto order = make_uniq(op.types, std::move(op.orders), std::move(projection_map), + op.estimated_cardinality); + order->children.push_back(std::move(plan)); + plan = std::move(order); } - auto &order = - Make(op.types, std::move(op.orders), std::move(projection_map), op.estimated_cardinality); - order.children.push_back(plan); - return order; + return plan; } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_pivot.cpp b/src/duckdb/src/execution/physical_plan/plan_pivot.cpp index 590c42922..bca3bc909 100644 --- a/src/duckdb/src/execution/physical_plan/plan_pivot.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_pivot.cpp @@ -4,10 +4,11 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalPivot &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalPivot &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); - return Make(std::move(op.types), plan, std::move(op.bound_pivot)); + auto child_plan = CreatePlan(*op.children[0]); + auto pivot = make_uniq(std::move(op.types), std::move(child_plan), std::move(op.bound_pivot)); + return std::move(pivot); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_positional_join.cpp b/src/duckdb/src/execution/physical_plan/plan_positional_join.cpp index d972bf612..6fd20ed4e 100644 --- a/src/duckdb/src/execution/physical_plan/plan_positional_join.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_positional_join.cpp @@ -5,18 +5,18 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalPositionalJoin &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalPositionalJoin &op) { D_ASSERT(op.children.size() == 2); - auto &left = CreatePlan(*op.children[0]); - auto &right = CreatePlan(*op.children[1]); - switch (left.type) { + auto left = CreatePlan(*op.children[0]); + auto right = CreatePlan(*op.children[1]); + switch (left->type) { case PhysicalOperatorType::TABLE_SCAN: case PhysicalOperatorType::POSITIONAL_SCAN: - switch (right.type) { + switch (right->type) { case PhysicalOperatorType::TABLE_SCAN: case PhysicalOperatorType::POSITIONAL_SCAN: - return Make(op.types, left, right); + return make_uniq(op.types, std::move(left), std::move(right)); default: break; } @@ -24,7 +24,8 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalPositionalJoin &op) { default: break; } - return Make(op.types, left, right, op.estimated_cardinality); + + return make_uniq(op.types, std::move(left), std::move(right), op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_pragma.cpp b/src/duckdb/src/execution/physical_plan/plan_pragma.cpp index 360a6651e..c0303965f 100644 --- a/src/duckdb/src/execution/physical_plan/plan_pragma.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_pragma.cpp @@ -4,8 +4,8 @@ #include "duckdb/execution/operator/helper/physical_pragma.hpp" namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalPragma &op) { - return Make(std::move(op.info), op.estimated_cardinality); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalPragma &op) { + return make_uniq(std::move(op.info), op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_prepare.cpp b/src/duckdb/src/execution/physical_plan/plan_prepare.cpp index 1c24539ac..191377b1f 100644 --- a/src/duckdb/src/execution/physical_plan/plan_prepare.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_prepare.cpp @@ -5,16 +5,17 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalPrepare &op) { - // Generate the physical plan only if all parameters are bound. - // Otherwise, the physical plan is never used. +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalPrepare &op) { D_ASSERT(op.children.size() <= 1); + + // generate physical plan only when all parameters are bound (otherwise the physical plan won't be used anyway) if (op.prepared->properties.bound_all_parameters && !op.children.empty()) { - PhysicalPlanGenerator inner_planner(context); - op.prepared->physical_plan = inner_planner.PlanInternal(*op.children[0]); - op.prepared->types = op.prepared->physical_plan->Root().types; + auto plan = CreatePlan(*op.children[0]); + op.prepared->types = plan->types; + op.prepared->plan = std::move(plan); } - return Make(op.name, std::move(op.prepared), op.estimated_cardinality); + + return make_uniq(op.name, std::move(op.prepared), op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_projection.cpp b/src/duckdb/src/execution/physical_plan/plan_projection.cpp index a0b65a2c4..f5f262f55 100644 --- a/src/duckdb/src/execution/physical_plan/plan_projection.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_projection.cpp @@ -5,9 +5,9 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalProjection &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalProjection &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); + auto plan = CreatePlan(*op.children[0]); #ifdef DEBUG for (auto &expr : op.expressions) { @@ -15,7 +15,7 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalProjection &op) { D_ASSERT(!expr->IsAggregate()); } #endif - if (plan.GetTypes().size() == op.types.size()) { + if (plan->types.size() == op.types.size()) { // check if this projection can be omitted entirely // this happens if a projection simply emits the columns in the same order // e.g. PROJECTION(#0, #1, #2, #3, ...) @@ -36,9 +36,9 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalProjection &op) { } } - auto &proj = Make(op.types, std::move(op.expressions), op.estimated_cardinality); - proj.children.push_back(plan); - return proj; + auto projection = make_uniq(op.types, std::move(op.expressions), op.estimated_cardinality); + projection->children.push_back(std::move(plan)); + return std::move(projection); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp b/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp index 837c751b9..7933dd166 100644 --- a/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp @@ -5,14 +5,10 @@ #include "duckdb/planner/expression/bound_reference_expression.hpp" #include "duckdb/planner/operator/logical_cteref.hpp" #include "duckdb/planner/operator/logical_recursive_cte.hpp" -#include "duckdb/function/aggregate/distributive_function_utils.hpp" -#include "duckdb/function/function_binder.hpp" -#include "duckdb/execution/aggregate_hashtable.hpp" -#include "duckdb/execution/perfect_aggregate_hashtable.hpp" namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalRecursiveCTE &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalRecursiveCTE &op) { D_ASSERT(op.children.size() == 2); // Create the working_table that the PhysicalRecursiveCTE will use for evaluation. @@ -21,86 +17,17 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalRecursiveCTE &op) { // Add the ColumnDataCollection to the context of this PhysicalPlanGenerator recursive_cte_tables[op.table_index] = working_table; - auto &left = CreatePlan(*op.children[0]); - - // If the logical operator has no key targets or all columns are referenced, - // then we create a normal recursive CTE operator. - if (op.key_targets.empty()) { - auto &right = CreatePlan(*op.children[1]); - auto &cte = Make(op.ctename, op.table_index, op.types, op.union_all, left, right, - op.estimated_cardinality); - auto &cast_cte = cte.Cast(); - cast_cte.distinct_types = op.types; - cast_cte.working_table = working_table; - return cte; - } - - vector payload_types, distinct_types; - vector payload_idx, distinct_idx; - vector> payload_aggregates; - - // create a group for each target, these are the columns that should be grouped - unordered_map group_by_references; - for (idx_t i = 0; i < op.key_targets.size(); i++) { - auto &target = op.key_targets[i]; - D_ASSERT(target->type == ExpressionType::BOUND_REF); - auto &bound_ref = target->Cast(); - group_by_references[bound_ref.index] = i; - } + auto left = CreatePlan(*op.children[0]); + auto right = CreatePlan(*op.children[1]); - /* - * iterate over all types - * Differentiate the occurrence of the column in the key clause. - */ - auto &types = left.GetTypes(); - for (idx_t i = 0; i < types.size(); ++i) { - auto logical_type = types[i]; - // Check if we can directly refer to a group, or if we need to push an aggregate with LAST - auto entry = group_by_references.find(i); - if (entry != group_by_references.end()) { - // Column has a key, note the column index to make a distinction on it - distinct_idx.emplace_back(i); - distinct_types.push_back(logical_type); - } else { - // Column is not in the key clause, so we need to create an aggregate - auto bound = make_uniq(logical_type, 0U); - - vector> first_children; - first_children.push_back(std::move(bound)); - - FunctionBinder function_binder(context); - auto first_aggregate = - function_binder.BindAggregateFunction(LastFunctionGetter::GetFunction(logical_type), - std::move(first_children), nullptr, AggregateType::NON_DISTINCT); - first_aggregate->order_bys = nullptr; - - payload_types.push_back(logical_type); - payload_idx.emplace_back(i); - payload_aggregates.push_back(std::move(first_aggregate)); - } - } + auto cte = make_uniq(op.ctename, op.table_index, op.types, op.union_all, std::move(left), + std::move(right), op.estimated_cardinality); + cte->working_table = working_table; - // If the key variant has been used, a recurring table will be created. - auto recurring_table = make_shared_ptr(context, op.types); - recurring_cte_tables[op.table_index] = recurring_table; - - auto &right = CreatePlan(*op.children[1]); - auto &cte = Make(op.ctename, op.table_index, op.types, op.union_all, left, right, - op.estimated_cardinality); - auto &cast_cte = cte.Cast(); - cast_cte.using_key = true; - cast_cte.payload_aggregates = std::move(payload_aggregates); - cast_cte.distinct_idx = distinct_idx; - cast_cte.distinct_types = distinct_types; - cast_cte.payload_idx = payload_idx; - cast_cte.payload_types = payload_types; - cast_cte.ref_recurring = op.ref_recurring; - cast_cte.working_table = working_table; - cast_cte.recurring_table = recurring_table; - return cte; + return std::move(cte); } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCTERef &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalCTERef &op) { D_ASSERT(op.children.empty()); // Check if this LogicalCTERef is supposed to scan a materialized CTE. @@ -110,18 +37,17 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCTERef &op) { // If this check fails, this is a reference to a materialized recursive CTE. if (materialized_cte != materialized_ctes.end()) { - auto &chunk_scan = Make(op.chunk_types, PhysicalOperatorType::CTE_SCAN, - op.estimated_cardinality, op.cte_index); + auto chunk_scan = make_uniq(op.chunk_types, PhysicalOperatorType::CTE_SCAN, + op.estimated_cardinality, op.cte_index); auto cte = recursive_cte_tables.find(op.cte_index); if (cte == recursive_cte_tables.end()) { throw InvalidInputException("Referenced materialized CTE does not exist."); } + chunk_scan->collection = cte->second.get(); + materialized_cte->second.push_back(*chunk_scan.get()); - auto &cast_chunk_scan = chunk_scan.Cast(); - cast_chunk_scan.collection = cte->second.get(); - materialized_cte->second.push_back(cast_chunk_scan); - return chunk_scan; + return std::move(chunk_scan); } } @@ -131,21 +57,12 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalCTERef &op) { throw InvalidInputException("Referenced recursive CTE does not exist."); } - // If we found a recursive CTE and we want to scan the recurring table, we search for it, - if (op.is_recurring) { - cte = recurring_cte_tables.find(op.cte_index); - if (cte == recurring_cte_tables.end()) { - throw InvalidInputException("RECURRING can only be used with USING KEY in recursive CTE."); - } - } + auto chunk_scan = make_uniq( + cte->second.get()->Types(), PhysicalOperatorType::RECURSIVE_CTE_SCAN, op.estimated_cardinality, op.cte_index); + + chunk_scan->collection = cte->second.get(); - auto &types = cte->second.get()->Types(); - auto op_type = - op.is_recurring ? PhysicalOperatorType::RECURSIVE_RECURRING_CTE_SCAN : PhysicalOperatorType::RECURSIVE_CTE_SCAN; - auto &chunk_scan = Make(types, op_type, op.estimated_cardinality, op.cte_index); - auto &cast_chunk_scan = chunk_scan.Cast(); - cast_chunk_scan.collection = cte->second.get(); - return chunk_scan; + return std::move(chunk_scan); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_reset.cpp b/src/duckdb/src/execution/physical_plan/plan_reset.cpp index a7d8240c1..2f8aa3698 100644 --- a/src/duckdb/src/execution/physical_plan/plan_reset.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_reset.cpp @@ -4,8 +4,8 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalReset &op) { - return Make(op.name, op.scope, op.estimated_cardinality); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalReset &op) { + return make_uniq(op.name, op.scope, op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_sample.cpp b/src/duckdb/src/execution/physical_plan/plan_sample.cpp index c88d8c741..883c7055d 100644 --- a/src/duckdb/src/execution/physical_plan/plan_sample.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_sample.cpp @@ -7,35 +7,34 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalSample &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalSample &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); + auto plan = CreatePlan(*op.children[0]); + + unique_ptr sample; if (!op.sample_options->seed.IsValid()) { auto &random_engine = RandomEngine::Get(context); op.sample_options->SetSeed(random_engine.NextRandomInteger()); } - switch (op.sample_options->method) { - case SampleMethod::RESERVOIR_SAMPLE: { - auto &sample = Make(op.types, std::move(op.sample_options), op.estimated_cardinality); - sample.children.push_back(plan); - return sample; - } + case SampleMethod::RESERVOIR_SAMPLE: + sample = make_uniq(op.types, std::move(op.sample_options), op.estimated_cardinality); + break; case SampleMethod::SYSTEM_SAMPLE: - case SampleMethod::BERNOULLI_SAMPLE: { + case SampleMethod::BERNOULLI_SAMPLE: if (!op.sample_options->is_percentage) { throw ParserException("Sample method %s cannot be used with a discrete sample count, either switch to " "reservoir sampling or use a sample_size", EnumUtil::ToString(op.sample_options->method)); } - auto &sample = Make(op.types, std::move(op.sample_options), op.estimated_cardinality); - sample.children.push_back(plan); - return sample; - } + sample = make_uniq(op.types, std::move(op.sample_options), op.estimated_cardinality); + break; default: throw InternalException("Unimplemented sample method"); } + sample->children.push_back(std::move(plan)); + return sample; } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_set.cpp b/src/duckdb/src/execution/physical_plan/plan_set.cpp index 25df13222..fe09cb317 100644 --- a/src/duckdb/src/execution/physical_plan/plan_set.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_set.cpp @@ -5,17 +5,16 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalSet &op) { - // Set a config setting. - if (op.children.empty()) { - return Make(op.name, op.value, op.scope, op.estimated_cardinality); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalSet &op) { + if (!op.children.empty()) { + // set variable + auto child = CreatePlan(*op.children[0]); + auto set_variable = make_uniq(std::move(op.name), op.estimated_cardinality); + set_variable->children.push_back(std::move(child)); + return std::move(set_variable); } - - // Set a variable. - auto &plan = CreatePlan(*op.children[0]); - auto &set_variable = Make(std::move(op.name), op.estimated_cardinality); - set_variable.children.push_back(plan); - return set_variable; + // set config setting + return make_uniq(op.name, op.value, op.scope, op.estimated_cardinality); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_set_operation.cpp b/src/duckdb/src/execution/physical_plan/plan_set_operation.cpp index aa274f16d..dada24fcf 100644 --- a/src/duckdb/src/execution/physical_plan/plan_set_operation.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_set_operation.cpp @@ -31,25 +31,27 @@ static JoinCondition CreateNotDistinctComparison(const LogicalType &type, idx_t return cond; } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalSetOperation &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalSetOperation &op) { D_ASSERT(op.children.size() == 2); - reference left = CreatePlan(*op.children[0]); - reference right = CreatePlan(*op.children[1]); + unique_ptr result; - if (left.get().GetTypes() != right.get().GetTypes()) { + auto left = CreatePlan(*op.children[0]); + auto right = CreatePlan(*op.children[1]); + + if (left->GetTypes() != right->GetTypes()) { throw InvalidInputException("Type mismatch for SET OPERATION"); } - optional_ptr result; switch (op.type) { case LogicalOperatorType::LOGICAL_UNION: // UNION - result = Make(op.types, left, right, op.estimated_cardinality, op.allow_out_of_order); + result = make_uniq(op.types, std::move(left), std::move(right), op.estimated_cardinality, + op.allow_out_of_order); break; case LogicalOperatorType::LOGICAL_EXCEPT: case LogicalOperatorType::LOGICAL_INTERSECT: { - auto &types = left.get().GetTypes(); + auto &types = left->GetTypes(); vector conditions; // create equality condition for all columns for (idx_t i = 0; i < types.size(); i++) { @@ -61,17 +63,15 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalSetOperation &op) { vector window_types = types; window_types.push_back(LogicalType::BIGINT); - auto select_list = CreatePartitionedRowNumExpression(types); - auto &left_window = - Make(window_types, std::move(select_list), left.get().estimated_cardinality); - left_window.children.push_back(left); - left = left_window; + auto window_left = make_uniq(window_types, CreatePartitionedRowNumExpression(types), + left->estimated_cardinality); + window_left->children.push_back(std::move(left)); + left = std::move(window_left); - select_list = CreatePartitionedRowNumExpression(types); - auto &right_window = - Make(window_types, std::move(select_list), right.get().estimated_cardinality); - right_window.children.push_back(right); - right = right_window; + auto window_right = make_uniq(window_types, CreatePartitionedRowNumExpression(types), + right->estimated_cardinality); + window_right->children.push_back(std::move(right)); + right = std::move(window_right); // add window expression result to join condition conditions.push_back(CreateNotDistinctComparison(LogicalType::BIGINT, types.size())); @@ -83,17 +83,19 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalSetOperation &op) { // INTERSECT is SEMI join JoinType join_type = op.type == LogicalOperatorType::LOGICAL_EXCEPT ? JoinType::ANTI : JoinType::SEMI; - result = Make(op, left, right, std::move(conditions), join_type, op.estimated_cardinality); + result = make_uniq(op, std::move(left), std::move(right), std::move(conditions), join_type, + op.estimated_cardinality); // For EXCEPT ALL / INTERSECT ALL we need to remove the row number column again if (op.setop_all) { - vector> select_list; + vector> projection_select_list; for (idx_t i = 0; i < types.size(); i++) { - select_list.push_back(make_uniq(types[i], i)); + projection_select_list.push_back(make_uniq(types[i], i)); } - auto &proj = Make(types, std::move(select_list), op.estimated_cardinality); - proj.children.push_back(*result); - result = proj; + auto projection = + make_uniq(types, std::move(projection_select_list), op.estimated_cardinality); + projection->children.push_back(std::move(result)); + result = std::move(projection); } break; } @@ -108,14 +110,14 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalSetOperation &op) { for (idx_t i = 0; i < types.size(); i++) { groups.push_back(make_uniq(types[i], i)); } - auto &group_by = Make(context, op.types, std::move(aggregates), std::move(groups), - result->estimated_cardinality); - group_by.children.push_back(*result); - result = group_by; + auto groupby = make_uniq(context, op.types, std::move(aggregates), std::move(groups), + result->estimated_cardinality); + groupby->children.push_back(std::move(result)); + result = std::move(groupby); } D_ASSERT(result); - return *result; + return (result); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_simple.cpp b/src/duckdb/src/execution/physical_plan/plan_simple.cpp index 608df673a..7c03ff4f0 100644 --- a/src/duckdb/src/execution/physical_plan/plan_simple.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_simple.cpp @@ -14,26 +14,29 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalSimple &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalSimple &op) { switch (op.type) { case LogicalOperatorType::LOGICAL_ALTER: - return Make(unique_ptr_cast(std::move(op.info)), op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_DROP: - return Make(unique_ptr_cast(std::move(op.info)), op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_TRANSACTION: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_LOAD: - return Make(unique_ptr_cast(std::move(op.info)), op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_ATTACH: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_DETACH: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); case LogicalOperatorType::LOGICAL_UPDATE_EXTENSIONS: - return Make(unique_ptr_cast(std::move(op.info)), - op.estimated_cardinality); + return make_uniq(unique_ptr_cast(std::move(op.info)), + op.estimated_cardinality); default: throw NotImplementedException("Unimplemented type for logical simple operator"); } diff --git a/src/duckdb/src/execution/physical_plan/plan_top_n.cpp b/src/duckdb/src/execution/physical_plan/plan_top_n.cpp index a28d540a9..700021876 100644 --- a/src/duckdb/src/execution/physical_plan/plan_top_n.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_top_n.cpp @@ -4,14 +4,16 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalTopN &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalTopN &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); - auto &top_n = - Make(op.types, std::move(op.orders), NumericCast(op.limit), NumericCast(op.offset), - std::move(op.dynamic_filter), op.estimated_cardinality); - top_n.children.push_back(plan); - return top_n; + + auto plan = CreatePlan(*op.children[0]); + + auto top_n = + make_uniq(op.types, std::move(op.orders), NumericCast(op.limit), + NumericCast(op.offset), std::move(op.dynamic_filter), op.estimated_cardinality); + top_n->children.push_back(std::move(plan)); + return std::move(top_n); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_unnest.cpp b/src/duckdb/src/execution/physical_plan/plan_unnest.cpp index 448b668d6..992da4306 100644 --- a/src/duckdb/src/execution/physical_plan/plan_unnest.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_unnest.cpp @@ -4,12 +4,12 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalUnnest &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalUnnest &op) { D_ASSERT(op.children.size() == 1); - auto &plan = CreatePlan(*op.children[0]); - auto &unnest = Make(op.types, std::move(op.expressions), op.estimated_cardinality); - unnest.children.push_back(plan); - return unnest; + auto plan = CreatePlan(*op.children[0]); + auto unnest = make_uniq(op.types, std::move(op.expressions), op.estimated_cardinality); + unnest->children.push_back(std::move(plan)); + return std::move(unnest); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_update.cpp b/src/duckdb/src/execution/physical_plan/plan_update.cpp index 3b65d4f3e..b35914233 100644 --- a/src/duckdb/src/execution/physical_plan/plan_update.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_update.cpp @@ -6,26 +6,24 @@ namespace duckdb { -PhysicalOperator &DuckCatalog::PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op, - PhysicalOperator &plan) { - auto &update = planner.Make( - op.types, op.table, op.table.GetStorage(), op.columns, std::move(op.expressions), std::move(op.bound_defaults), - std::move(op.bound_constraints), op.estimated_cardinality, op.return_chunk); - auto &cast_update = update.Cast(); - cast_update.update_is_del_and_insert = op.update_is_del_and_insert; - cast_update.children.push_back(plan); - return update; -} +unique_ptr DuckCatalog::PlanUpdate(ClientContext &context, LogicalUpdate &op, + unique_ptr plan) { + auto update = make_uniq(op.types, op.table, op.table.GetStorage(), op.columns, + std::move(op.expressions), std::move(op.bound_defaults), + std::move(op.bound_constraints), op.estimated_cardinality, op.return_chunk); -PhysicalOperator &Catalog::PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op) { - auto &plan = planner.CreatePlan(*op.children[0]); - return PlanUpdate(context, planner, op, plan); + update->update_is_del_and_insert = op.update_is_del_and_insert; + update->children.push_back(std::move(plan)); + return std::move(update); } -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalUpdate &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalUpdate &op) { D_ASSERT(op.children.size() == 1); + + auto plan = CreatePlan(*op.children[0]); + dependencies.AddDependency(op.table); - return op.table.catalog.PlanUpdate(context, *this, op); + return op.table.catalog.PlanUpdate(context, op, std::move(plan)); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_vacuum.cpp b/src/duckdb/src/execution/physical_plan/plan_vacuum.cpp index db561ae3d..3f1f88b3d 100644 --- a/src/duckdb/src/execution/physical_plan/plan_vacuum.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_vacuum.cpp @@ -5,14 +5,14 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalVacuum &op) { - auto &vacuum = Make(unique_ptr_cast(std::move(op.info)), op.table, - std::move(op.column_id_map), op.estimated_cardinality); +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalVacuum &op) { + auto result = make_uniq(unique_ptr_cast(std::move(op.info)), op.table, + std::move(op.column_id_map), op.estimated_cardinality); if (!op.children.empty()) { - auto &plan = CreatePlan(*op.children[0]); - vacuum.children.push_back(plan); + auto child = CreatePlan(*op.children[0]); + result->children.push_back(std::move(child)); } - return vacuum; + return std::move(result); } } // namespace duckdb diff --git a/src/duckdb/src/execution/physical_plan/plan_window.cpp b/src/duckdb/src/execution/physical_plan/plan_window.cpp index c9cab9e8c..f294d9324 100644 --- a/src/duckdb/src/execution/physical_plan/plan_window.cpp +++ b/src/duckdb/src/execution/physical_plan/plan_window.cpp @@ -11,11 +11,10 @@ namespace duckdb { -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalWindow &op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalWindow &op) { D_ASSERT(op.children.size() == 1); - op.estimated_cardinality = op.EstimateCardinality(context); - reference plan = CreatePlan(*op.children[0]); + auto plan = CreatePlan(*op.children[0]); #ifdef DEBUG for (auto &expr : op.expressions) { D_ASSERT(expr->IsWindow()); @@ -122,15 +121,14 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalWindow &op) { } // Chain the new window operator on top of the plan + unique_ptr window; if (i < blocking_count) { - auto &window = Make(types, std::move(select_list), op.estimated_cardinality); - window.children.push_back(plan); - plan = window; + window = make_uniq(types, std::move(select_list), op.estimated_cardinality); } else { - auto &window = Make(types, std::move(select_list), op.estimated_cardinality); - window.children.push_back(plan); - plan = window; + window = make_uniq(types, std::move(select_list), op.estimated_cardinality); } + window->children.push_back(std::move(plan)); + plan = std::move(window); } // Put everything back into place if it moved @@ -144,9 +142,9 @@ PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalWindow &op) { for (const auto &p : projection_map) { select_list[p.first] = make_uniq(op.types[p.first], p.second); } - auto &proj = Make(op.types, std::move(select_list), op.estimated_cardinality); - proj.children.push_back(plan); - plan = proj; + auto proj = make_uniq(op.types, std::move(select_list), op.estimated_cardinality); + proj->children.push_back(std::move(plan)); + plan = std::move(proj); } return plan; diff --git a/src/duckdb/src/execution/physical_plan_generator.cpp b/src/duckdb/src/execution/physical_plan_generator.cpp index eb14ba813..1ac6f61b2 100644 --- a/src/duckdb/src/execution/physical_plan_generator.cpp +++ b/src/duckdb/src/execution/physical_plan_generator.cpp @@ -19,167 +19,203 @@ PhysicalPlanGenerator::PhysicalPlanGenerator(ClientContext &context) : context(c PhysicalPlanGenerator::~PhysicalPlanGenerator() { } -unique_ptr PhysicalPlanGenerator::Plan(unique_ptr op) { - auto &plan = ResolveAndPlan(std::move(op)); - plan.Verify(); - return std::move(physical_plan); -} - -PhysicalOperator &PhysicalPlanGenerator::ResolveAndPlan(unique_ptr op) { +unique_ptr PhysicalPlanGenerator::CreatePlan(unique_ptr op) { auto &profiler = QueryProfiler::Get(context); - // Resolve the column references. + // first resolve column references profiler.StartPhase(MetricsType::PHYSICAL_PLANNER_COLUMN_BINDING); ColumnBindingResolver resolver; resolver.VisitOperator(*op); profiler.EndPhase(); - // Resolve the types of each operator. + // now resolve types of all the operators profiler.StartPhase(MetricsType::PHYSICAL_PLANNER_RESOLVE_TYPES); op->ResolveOperatorTypes(); profiler.EndPhase(); - // Create the main physical plan. + // then create the main physical plan profiler.StartPhase(MetricsType::PHYSICAL_PLANNER_CREATE_PLAN); - physical_plan = PlanInternal(*op); + auto plan = CreatePlan(*op); profiler.EndPhase(); - // Return a reference to the root of this plan. - return physical_plan->Root(); + plan->Verify(); + return plan; } -unique_ptr PhysicalPlanGenerator::PlanInternal(LogicalOperator &op) { - if (!physical_plan) { - physical_plan = make_uniq(Allocator::Get(context)); - } +unique_ptr PhysicalPlanGenerator::CreatePlan(LogicalOperator &op) { op.estimated_cardinality = op.EstimateCardinality(context); - physical_plan->SetRoot(CreatePlan(op)); - physical_plan->Root().estimated_cardinality = op.estimated_cardinality; - - auto &config = DBConfig::GetConfig(context); - if (config.options.debug_verify_vector != DebugVectorVerification::NONE) { - if (config.options.debug_verify_vector != DebugVectorVerification::DICTIONARY_EXPRESSION) { - physical_plan->SetRoot( - Make(physical_plan->Root(), config.options.debug_verify_vector)); - } - } - return std::move(physical_plan); -} + unique_ptr plan = nullptr; -PhysicalOperator &PhysicalPlanGenerator::CreatePlan(LogicalOperator &op) { switch (op.type) { case LogicalOperatorType::LOGICAL_GET: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_PROJECTION: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_EMPTY_RESULT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_FILTER: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_AGGREGATE_AND_GROUP_BY: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_WINDOW: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_UNNEST: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_LIMIT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_SAMPLE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_ORDER_BY: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_TOP_N: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_COPY_TO_FILE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_DUMMY_SCAN: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_ANY_JOIN: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_ASOF_JOIN: case LogicalOperatorType::LOGICAL_DELIM_JOIN: case LogicalOperatorType::LOGICAL_COMPARISON_JOIN: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_CROSS_PRODUCT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_POSITIONAL_JOIN: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_UNION: case LogicalOperatorType::LOGICAL_EXCEPT: case LogicalOperatorType::LOGICAL_INTERSECT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_INSERT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_DELETE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_CHUNK_GET: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_DELIM_GET: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_EXPRESSION_GET: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_UPDATE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_CREATE_TABLE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_CREATE_INDEX: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_CREATE_SECRET: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_EXPLAIN: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_DISTINCT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_PREPARE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_EXECUTE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_CREATE_VIEW: case LogicalOperatorType::LOGICAL_CREATE_SEQUENCE: case LogicalOperatorType::LOGICAL_CREATE_SCHEMA: case LogicalOperatorType::LOGICAL_CREATE_MACRO: case LogicalOperatorType::LOGICAL_CREATE_TYPE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_PRAGMA: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_VACUUM: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_TRANSACTION: case LogicalOperatorType::LOGICAL_ALTER: case LogicalOperatorType::LOGICAL_DROP: case LogicalOperatorType::LOGICAL_LOAD: case LogicalOperatorType::LOGICAL_ATTACH: case LogicalOperatorType::LOGICAL_DETACH: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_RECURSIVE_CTE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_MATERIALIZED_CTE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_CTE_REF: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_EXPORT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_SET: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_RESET: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_PIVOT: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_COPY_DATABASE: - return CreatePlan(op.Cast()); + plan = CreatePlan(op.Cast()); + break; case LogicalOperatorType::LOGICAL_UPDATE_EXTENSIONS: - return CreatePlan(op.Cast()); - case LogicalOperatorType::LOGICAL_EXTENSION_OPERATOR: { - auto &extension_op = op.Cast(); - return extension_op.CreatePlan(context, *this); - } + plan = CreatePlan(op.Cast()); + break; + case LogicalOperatorType::LOGICAL_EXTENSION_OPERATOR: + plan = op.Cast().CreatePlan(context, *this); + + if (!plan) { + throw InternalException("Missing PhysicalOperator for Extension Operator"); + } + break; case LogicalOperatorType::LOGICAL_JOIN: case LogicalOperatorType::LOGICAL_DEPENDENT_JOIN: case LogicalOperatorType::LOGICAL_INVALID: { throw NotImplementedException("Unimplemented logical operator type!"); } } - throw InternalException("Physical plan generator - no plan generated"); + if (!plan) { + throw InternalException("Physical plan generator - no plan generated"); + } + + plan->estimated_cardinality = op.estimated_cardinality; +#ifdef DUCKDB_VERIFY_VECTOR_OPERATOR + auto verify = make_uniq(std::move(plan)); + plan = std::move(verify); +#endif + + return plan; } } // namespace duckdb diff --git a/src/duckdb/src/execution/radix_partitioned_hashtable.cpp b/src/duckdb/src/execution/radix_partitioned_hashtable.cpp index 40f4360cf..8ef1dd519 100644 --- a/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +++ b/src/duckdb/src/execution/radix_partitioned_hashtable.cpp @@ -33,10 +33,7 @@ RadixPartitionedHashTable::RadixPartitionedHashTable(GroupingSet &grouping_set_p auto group_types_copy = group_types; group_types_copy.emplace_back(LogicalType::HASH); - - auto layout = make_shared_ptr(); - layout->Initialize(std::move(group_types_copy), AggregateObject::CreateAggregateObjects(op.bindings)); - layout_ptr = std::move(layout); + layout.Initialize(std::move(group_types_copy), AggregateObject::CreateAggregateObjects(op.bindings)); } void RadixPartitionedHashTable::SetGroupingValues() { @@ -58,12 +55,8 @@ void RadixPartitionedHashTable::SetGroupingValues() { } } -shared_ptr RadixPartitionedHashTable::GetLayoutPtr() const { - return layout_ptr; -} - const TupleDataLayout &RadixPartitionedHashTable::GetLayout() const { - return *layout_ptr; + return layout; } unique_ptr RadixPartitionedHashTable::CreateHT(ClientContext &context, const idx_t capacity, @@ -428,11 +421,11 @@ void MaybeRepartition(ClientContext &context, RadixHTGlobalSinkState &gstate, Ra // We're approaching the memory limit, unpin the data if (!lstate.abandoned_data) { lstate.abandoned_data = make_uniq( - BufferManager::GetBufferManager(context), gstate.radix_ht.GetLayoutPtr(), config.GetRadixBits(), + BufferManager::GetBufferManager(context), gstate.radix_ht.GetLayout(), config.GetRadixBits(), gstate.radix_ht.GetLayout().ColumnCount() - 1); } ht.SetRadixBits(gstate.config.GetRadixBits()); - ht.AcquirePartitionedData()->Repartition(context, *lstate.abandoned_data); + ht.AcquirePartitionedData()->Repartition(*lstate.abandoned_data); } } @@ -677,7 +670,6 @@ class RadixHTLocalSourceState : public LocalSourceState { //! Allocator and layout for finalizing state TupleDataLayout layout; ArenaAllocator aggregate_allocator; - RowOperationsState row_state; //! State and chunk for scanning TupleDataScanState scan_state; @@ -732,8 +724,7 @@ SourceResultType RadixHTGlobalSourceState::AssignTask(RadixHTGlobalSinkState &si RadixHTLocalSourceState::RadixHTLocalSourceState(ExecutionContext &context, const RadixPartitionedHashTable &radix_ht) : task(RadixHTSourceTaskType::NO_TASK), task_idx(DConstants::INVALID_INDEX), scan_status(RadixHTScanStatus::DONE), - layout(radix_ht.GetLayout().Copy()), aggregate_allocator(BufferAllocator::Get(context.client)), - row_state(aggregate_allocator) { + layout(radix_ht.GetLayout().Copy()), aggregate_allocator(BufferAllocator::Get(context.client)) { auto &allocator = BufferAllocator::Get(context.client); auto scan_chunk_types = radix_ht.group_types; for (auto &aggr_type : radix_ht.op.aggregate_return_types) { @@ -788,7 +779,7 @@ void RadixHTLocalSourceState::Finalize(RadixHTGlobalSinkState &sink, RadixHTGlob // Move the combined data back to the partition partition.data = - make_uniq(BufferManager::GetBufferManager(gstate.context), sink.radix_ht.GetLayoutPtr()); + make_uniq(BufferManager::GetBufferManager(gstate.context), sink.radix_ht.GetLayout()); partition.data->Combine(*ht->AcquirePartitionedData()->GetPartitions()[0]); // Update thread-global state @@ -839,6 +830,7 @@ void RadixHTLocalSourceState::Scan(RadixHTGlobalSinkState &sink, RadixHTGlobalSo return; } + RowOperationsState row_state(aggregate_allocator); const auto group_cols = layout.ColumnCount() - 1; RowOperations::FinalizeStates(row_state, layout, scan_state.chunk_state.row_locations, scan_chunk, group_cols); diff --git a/src/duckdb/src/function/aggregate/distributive/first_last_any.cpp b/src/duckdb/src/function/aggregate/distributive/first_last_any.cpp index 5e053b194..4e7455efa 100644 --- a/src/duckdb/src/function/aggregate/distributive/first_last_any.cpp +++ b/src/duckdb/src/function/aggregate/distributive/first_last_any.cpp @@ -314,12 +314,6 @@ AggregateFunction FirstFunctionGetter::GetFunction(const LogicalType &type) { return fun; } -AggregateFunction LastFunctionGetter::GetFunction(const LogicalType &type) { - auto fun = GetFirstFunction(type); - fun.name = "last"; - return fun; -} - template unique_ptr BindDecimalFirst(ClientContext &context, AggregateFunction &function, vector> &arguments) { diff --git a/src/duckdb/src/function/aggregate/distributive/minmax.cpp b/src/duckdb/src/function/aggregate/distributive/minmax.cpp index 486f6bd93..b862bf6d9 100644 --- a/src/duckdb/src/function/aggregate/distributive/minmax.cpp +++ b/src/duckdb/src/function/aggregate/distributive/minmax.cpp @@ -337,8 +337,8 @@ unique_ptr BindMinMax(ClientContext &context, AggregateFunction &f // to make sure the result's correctness. string function_name = function.name == "min" ? "arg_min" : "arg_max"; QueryErrorContext error_context; - auto func = Catalog::GetEntry(context, "", "", function_name, - OnEntryNotFound::RETURN_NULL, error_context); + auto func = Catalog::GetEntry(context, CatalogType::AGGREGATE_FUNCTION_ENTRY, "", "", function_name, + OnEntryNotFound::RETURN_NULL, error_context); if (!func) { throw NotImplementedException( "Failure while binding function \"%s\" using collations - arg_min/arg_max do not exist in the " @@ -346,7 +346,7 @@ unique_ptr BindMinMax(ClientContext &context, AggregateFunction &f function.name); } - auto &func_entry = *func; + auto &func_entry = func->Cast(); FunctionBinder function_binder(context); vector types {arguments[0]->return_type, arguments[0]->return_type}; @@ -412,8 +412,8 @@ class MinMaxNState { UnaryAggregateHeap heap; bool is_initialized = false; - void Initialize(ArenaAllocator &allocator, idx_t nval) { - heap.Initialize(allocator, nval); + void Initialize(idx_t nval) { + heap.Initialize(nval); is_initialized = true; } @@ -432,7 +432,7 @@ static void MinMaxNUpdate(Vector inputs[], AggregateInputData &aggr_input, idx_t UnifiedVectorFormat val_format; UnifiedVectorFormat n_format; UnifiedVectorFormat state_format; - + ; auto val_extra_state = STATE::VAL_TYPE::CreateExtraState(val_vector, count); STATE::VAL_TYPE::PrepareData(val_vector, count, val_extra_state, val_format); @@ -464,7 +464,7 @@ static void MinMaxNUpdate(Vector inputs[], AggregateInputData &aggr_input, idx_t if (nval >= MAX_N) { throw InvalidInputException("Invalid input for MIN/MAX: n value must be < %d", MAX_N); } - state.Initialize(aggr_input.allocator, UnsafeNumericCast(nval)); + state.Initialize(UnsafeNumericCast(nval)); } // Now add the input to the heap diff --git a/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp b/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp index b6dbb7ece..f38e74970 100644 --- a/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +++ b/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp @@ -17,10 +17,10 @@ struct SortedAggregateBindData : public FunctionData { using BindInfoPtr = unique_ptr; using OrderBys = vector; - SortedAggregateBindData(ClientContext &context_p, Expressions &children, AggregateFunction &aggregate, + SortedAggregateBindData(ClientContext &context, Expressions &children, AggregateFunction &aggregate, BindInfoPtr &bind_info, OrderBys &order_bys) - : context(context_p), function(aggregate), bind_info(std::move(bind_info)), - threshold(ClientConfig::GetConfig(context).ordered_aggregate_threshold), + : buffer_manager(BufferManager::GetBufferManager(context)), function(aggregate), + bind_info(std::move(bind_info)), threshold(ClientConfig::GetConfig(context).ordered_aggregate_threshold), external(ClientConfig::GetConfig(context).force_external) { arg_types.reserve(children.size()); arg_funcs.reserve(children.size()); @@ -54,9 +54,9 @@ struct SortedAggregateBindData : public FunctionData { } SortedAggregateBindData(const SortedAggregateBindData &other) - : context(other.context), function(other.function), arg_types(other.arg_types), arg_funcs(other.arg_funcs), - sort_types(other.sort_types), sort_funcs(other.sort_funcs), sorted_on_args(other.sorted_on_args), - threshold(other.threshold), external(other.external) { + : buffer_manager(other.buffer_manager), function(other.function), arg_types(other.arg_types), + arg_funcs(other.arg_funcs), sort_types(other.sort_types), sort_funcs(other.sort_funcs), + sorted_on_args(other.sorted_on_args), threshold(other.threshold), external(other.external) { if (other.bind_info) { bind_info = other.bind_info->Copy(); } @@ -92,7 +92,7 @@ struct SortedAggregateBindData : public FunctionData { return true; } - ClientContext &context; + BufferManager &buffer_manager; AggregateFunction function; vector arg_types; unique_ptr bind_info; @@ -143,7 +143,7 @@ struct SortedAggregateState { void InitializeChunks(const SortedAggregateBindData &order_bind) { // Lazy instantiation of the buffer chunks - auto &allocator = BufferManager::GetBufferManager(order_bind.context).GetBufferAllocator(); + auto &allocator = order_bind.buffer_manager.GetBufferAllocator(); InitializeChunk(allocator, sort_chunk, order_bind.sort_types); if (!order_bind.sorted_on_args) { InitializeChunk(allocator, arg_chunk, order_bind.arg_types); @@ -167,12 +167,12 @@ struct SortedAggregateState { } void InitializeCollections(const SortedAggregateBindData &order_bind) { - ordering = make_uniq(order_bind.context, order_bind.sort_types); + ordering = make_uniq(order_bind.buffer_manager, order_bind.sort_types); ordering_append = make_uniq(); ordering->InitializeAppend(*ordering_append); if (!order_bind.sorted_on_args) { - arguments = make_uniq(order_bind.context, order_bind.arg_types); + arguments = make_uniq(order_bind.buffer_manager, order_bind.arg_types); arguments_append = make_uniq(); arguments->InitializeAppend(*arguments_append); } @@ -564,15 +564,13 @@ struct SortedAggregateFunction { static void Finalize(Vector &states, AggregateInputData &aggr_input_data, Vector &result, idx_t count, const idx_t offset) { auto &order_bind = aggr_input_data.bind_data->Cast(); - auto &context = order_bind.context; + auto &buffer_manager = order_bind.buffer_manager; RowLayout payload_layout; payload_layout.Initialize(order_bind.arg_types); - - auto &buffer_allocator = BufferManager::GetBufferManager(order_bind.context).GetBufferAllocator(); DataChunk chunk; - chunk.Initialize(buffer_allocator, order_bind.arg_types); + chunk.Initialize(order_bind.buffer_manager.GetBufferAllocator(), order_bind.arg_types); DataChunk sliced; - sliced.Initialize(buffer_allocator, order_bind.arg_types); + sliced.Initialize(order_bind.buffer_manager.GetBufferAllocator(), order_bind.arg_types); // Reusable inner state auto &aggr = order_bind.function; @@ -605,13 +603,13 @@ struct SortedAggregateFunction { orders.emplace_back(order.Copy()); } - auto global_sort = make_uniq(context, orders, payload_layout); + auto global_sort = make_uniq(buffer_manager, orders, payload_layout); global_sort->external = order_bind.external; auto local_sort = make_uniq(); local_sort->Initialize(*global_sort, global_sort->buffer_manager); DataChunk prefixed; - prefixed.Initialize(buffer_allocator, global_sort->sort_layout.logical_types); + prefixed.Initialize(order_bind.buffer_manager.GetBufferAllocator(), global_sort->sort_layout.logical_types); // Go through the states accumulating values to sort until we hit the sort threshold idx_t unsorted_count = 0; @@ -702,7 +700,7 @@ struct SortedAggregateFunction { // Create a new sort scanner.reset(); - global_sort = make_uniq(context, orders, payload_layout); + global_sort = make_uniq(buffer_manager, orders, payload_layout); global_sort->external = order_bind.external; local_sort = make_uniq(); local_sort->Initialize(*global_sort, global_sort->buffer_manager); diff --git a/src/duckdb/src/function/built_in_functions.cpp b/src/duckdb/src/function/built_in_functions.cpp index f13bfe677..00e7eac64 100644 --- a/src/duckdb/src/function/built_in_functions.cpp +++ b/src/duckdb/src/function/built_in_functions.cpp @@ -142,9 +142,9 @@ void BuiltinFunctions::RegisterExtensionOverloads() { vector arguments; auto splits = StringUtil::Split(entry.signature, ">"); auto return_type = DBConfig::ParseLogicalType(splits[1]); - auto parameters = Value(splits[0]).DefaultCastAs(LogicalType::LIST(LogicalType::VARCHAR)); - for (auto ¶m : ListValue::GetChildren(parameters)) { - arguments.push_back(DBConfig::ParseLogicalType(param.GetValue())); + auto argument_splits = StringUtil::Split(splits[0], ","); + for (auto ¶m : argument_splits) { + arguments.push_back(DBConfig::ParseLogicalType(param)); } if (entry.type != CatalogType::SCALAR_FUNCTION_ENTRY) { throw InternalException( diff --git a/src/duckdb/src/function/cast/list_casts.cpp b/src/duckdb/src/function/cast/list_casts.cpp index 156b43143..a2326f860 100644 --- a/src/duckdb/src/function/cast/list_casts.cpp +++ b/src/duckdb/src/function/cast/list_casts.cpp @@ -2,7 +2,6 @@ #include "duckdb/function/cast/cast_function_set.hpp" #include "duckdb/function/cast/bound_cast_data.hpp" #include "duckdb/common/operator/cast_operators.hpp" -#include "duckdb/function/cast/vector_cast_helpers.hpp" namespace duckdb { @@ -77,13 +76,6 @@ static bool ListToVarcharCast(Vector &source, Vector &result, idx_t count, CastP Vector varchar_list(LogicalType::LIST(LogicalType::VARCHAR), count); ListCast::ListToListCast(source, varchar_list, count, parameters); - auto &child_vec = ListVector::GetEntry(source); - auto child_is_nested = child_vec.GetType().IsNested(); - auto string_length_func = child_is_nested ? VectorCastHelpers::CalculateStringLength - : VectorCastHelpers::CalculateEscapedStringLength; - auto write_string_func = - child_is_nested ? VectorCastHelpers::WriteString : VectorCastHelpers::WriteEscapedString; - // now construct the actual varchar vector varchar_list.Flatten(count); auto &child = ListVector::GetEntry(varchar_list); @@ -97,9 +89,6 @@ static bool ListToVarcharCast(Vector &source, Vector &result, idx_t count, CastP auto result_data = FlatVector::GetData(result); static constexpr const idx_t SEP_LENGTH = 2; static constexpr const idx_t NULL_LENGTH = 4; - unsafe_unique_array needs_quotes; - idx_t needs_quotes_length; - for (idx_t i = 0; i < count; i++) { if (!validity.RowIsValid(i)) { FlatVector::SetNull(result, i, true); @@ -108,21 +97,13 @@ static bool ListToVarcharCast(Vector &source, Vector &result, idx_t count, CastP auto list = list_data[i]; // figure out how long the result needs to be idx_t list_length = 2; // "[" and "]" - if (!needs_quotes || list.length > needs_quotes_length) { - needs_quotes = make_unsafe_uniq_array_uninitialized(list.length); - needs_quotes_length = list.length; - } for (idx_t list_idx = 0; list_idx < list.length; list_idx++) { auto idx = list.offset + list_idx; if (list_idx > 0) { list_length += SEP_LENGTH; // ", " } // string length, or "NULL" - if (child_validity.RowIsValid(idx)) { - list_length += string_length_func(child_data[idx], needs_quotes[list_idx]); - } else { - list_length += NULL_LENGTH; - } + list_length += child_validity.RowIsValid(idx) ? child_data[idx].GetSize() : NULL_LENGTH; } result_data[i] = StringVector::EmptyString(result, list_length); auto dataptr = result_data[i].GetDataWriteable(); @@ -135,7 +116,9 @@ static bool ListToVarcharCast(Vector &source, Vector &result, idx_t count, CastP offset += SEP_LENGTH; } if (child_validity.RowIsValid(idx)) { - offset += write_string_func(dataptr + offset, child_data[idx], needs_quotes[list_idx]); + auto len = child_data[idx].GetSize(); + memcpy(dataptr + offset, child_data[idx].GetData(), len); + offset += len; } else { memcpy(dataptr + offset, "NULL", NULL_LENGTH); offset += NULL_LENGTH; diff --git a/src/duckdb/src/function/cast/map_cast.cpp b/src/duckdb/src/function/cast/map_cast.cpp index ee8a4b11a..20c14efa0 100644 --- a/src/duckdb/src/function/cast/map_cast.cpp +++ b/src/duckdb/src/function/cast/map_cast.cpp @@ -1,7 +1,6 @@ #include "duckdb/function/cast/default_casts.hpp" #include "duckdb/function/cast/cast_function_set.hpp" #include "duckdb/function/cast/bound_cast_data.hpp" -#include "duckdb/function/cast/vector_cast_helpers.hpp" namespace duckdb { @@ -40,103 +39,35 @@ static bool MapToVarcharCast(Vector &source, Vector &result, idx_t count, CastPa auto &val_validity = FlatVector::Validity(val_str); auto &struct_validity = FlatVector::Validity(ListVector::GetEntry(varchar_map)); - //! {key=value[, ]} - static constexpr const idx_t SEP_LENGTH = 2; - static constexpr const idx_t KEY_VALUE_SEP_LENGTH = 1; - static constexpr const idx_t NULL_LENGTH = 4; - static constexpr const idx_t INVALID_LENGTH = 7; - - auto &key_vec = MapVector::GetKeys(source); - auto &value_vec = MapVector::GetValues(source); - - auto key_is_nested = key_vec.GetType().IsNested(); - auto value_is_nested = value_vec.GetType().IsNested(); - - auto key_strlen_func = key_is_nested ? VectorCastHelpers::CalculateStringLength - : VectorCastHelpers::CalculateEscapedStringLength; - auto key_write_func = key_is_nested ? VectorCastHelpers::WriteString : VectorCastHelpers::WriteEscapedString; - - auto value_strlen_func = value_is_nested ? VectorCastHelpers::CalculateStringLength - : VectorCastHelpers::CalculateEscapedStringLength; - auto value_write_func = - value_is_nested ? VectorCastHelpers::WriteString : VectorCastHelpers::WriteEscapedString; - auto result_data = FlatVector::GetData(result); - unsafe_unique_array key_needs_quotes; - unsafe_unique_array value_needs_quotes; - idx_t needs_quotes_length; for (idx_t i = 0; i < count; i++) { if (!validity.RowIsValid(i)) { FlatVector::SetNull(result, i, true); continue; } - - idx_t string_length = 2; // {} auto list = list_data[i]; - - if (!key_needs_quotes || list.length > needs_quotes_length) { - key_needs_quotes = make_unsafe_uniq_array_uninitialized(list.length); - value_needs_quotes = make_unsafe_uniq_array_uninitialized(list.length); - needs_quotes_length = list.length; - } + string ret = "{"; for (idx_t list_idx = 0; list_idx < list.length; list_idx++) { if (list_idx > 0) { - string_length += SEP_LENGTH; + ret += ", "; } - auto idx = list.offset + list_idx; if (!struct_validity.RowIsValid(idx)) { - string_length += NULL_LENGTH; + ret += "NULL"; continue; } if (!key_validity.RowIsValid(idx)) { // throw InternalException("Error in map: key validity invalid?!"); - string_length += INVALID_LENGTH; + ret += "invalid"; continue; } - string_length += key_strlen_func(key_data[idx], key_needs_quotes[list_idx]); - string_length += KEY_VALUE_SEP_LENGTH; - if (val_validity.RowIsValid(idx)) { - string_length += value_strlen_func(val_data[idx], value_needs_quotes[list_idx]); - } else { - string_length += NULL_LENGTH; - } - } - result_data[i] = StringVector::EmptyString(result, string_length); - auto dataptr = result_data[i].GetDataWriteable(); - idx_t offset = 0; - - dataptr[offset++] = '{'; - for (idx_t list_idx = 0; list_idx < list.length; list_idx++) { - if (list_idx > 0) { - memcpy(dataptr + offset, ", ", SEP_LENGTH); - offset += SEP_LENGTH; - } - - auto idx = list.offset + list_idx; - if (!struct_validity.RowIsValid(idx)) { - memcpy(dataptr + offset, "NULL", NULL_LENGTH); - offset += NULL_LENGTH; - continue; - } - if (!key_validity.RowIsValid(idx)) { - // throw InternalException("Error in map: key validity invalid?!"); - memcpy(dataptr + offset, "invalid", INVALID_LENGTH); - offset += INVALID_LENGTH; - continue; - } - offset += key_write_func(dataptr + offset, key_data[idx], key_needs_quotes[list_idx]); - dataptr[offset++] = '='; - if (val_validity.RowIsValid(idx)) { - offset += value_write_func(dataptr + offset, val_data[idx], value_needs_quotes[list_idx]); - } else { - memcpy(dataptr + offset, "NULL", NULL_LENGTH); - offset += NULL_LENGTH; - } + ret += key_data[idx].GetString(); + ret += "="; + ret += val_validity.RowIsValid(idx) ? val_data[idx].GetString() : "NULL"; } - dataptr[offset++] = '}'; - result_data[i].Finalize(); + ret += "}"; + result_data[i] = StringVector::AddString(result, ret); } if (constant) { diff --git a/src/duckdb/src/function/cast/string_cast.cpp b/src/duckdb/src/function/cast/string_cast.cpp index 07375bf7b..f3a19c427 100644 --- a/src/duckdb/src/function/cast/string_cast.cpp +++ b/src/duckdb/src/function/cast/string_cast.cpp @@ -160,9 +160,9 @@ bool VectorStringToList::StringToNestedTypeCastLoop(const string_t *source_data, list_data[i].offset = total; if (!VectorStringToList::SplitStringList(source_data[idx], child_data, total, varchar_vector)) { - auto error = StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type %s", - source_data[idx].GetString(), result.GetType().ToString()); - HandleVectorCastError::Operation(error, result_mask, i, vector_cast_data); + string text = "Type VARCHAR with value '" + source_data[idx].GetString() + + "' can't be cast to the destination type LIST"; + HandleVectorCastError::Operation(text, result_mask, i, vector_cast_data); } list_data[i].length = total - list_data[i].offset; // length is the amount of parts coming from this string } @@ -233,13 +233,16 @@ bool VectorStringToStruct::StringToNestedTypeCastLoop(const string_t *source_dat result_mask.SetInvalid(i); continue; } + if (is_unnamed) { + throw ConversionException("Casting strings to unnamed structs is unsupported"); + } if (!VectorStringToStruct::SplitStruct(source_data[idx], child_vectors, i, child_names, child_masks)) { - auto error = StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type %s", - source_data[idx].GetString(), result.GetType().ToString()); + string text = "Type VARCHAR with value '" + source_data[idx].GetString() + + "' can't be cast to the destination type STRUCT"; for (auto &child_mask : child_masks) { child_mask.get().SetInvalid(i); // some values may have already been found and set valid } - HandleVectorCastError::Operation(error, result_mask, i, vector_cast_data); + HandleVectorCastError::Operation(text, result_mask, i, vector_cast_data); } } @@ -316,10 +319,10 @@ bool VectorStringToMap::StringToNestedTypeCastLoop(const string_t *source_data, list_data[i].offset = total; if (!VectorStringToMap::SplitStringMap(source_data[idx], child_key_data, child_val_data, total, varchar_key_vector, varchar_val_vector)) { - auto error = StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type %s", - source_data[idx].GetString(), result.GetType().ToString()); + string text = "Type VARCHAR with value '" + source_data[idx].GetString() + + "' can't be cast to the destination type MAP"; FlatVector::SetNull(result, i, true); - HandleVectorCastError::Operation(error, result_mask, i, vector_cast_data); + HandleVectorCastError::Operation(text, result_mask, i, vector_cast_data); } list_data[i].length = total - list_data[i].offset; } @@ -379,9 +382,10 @@ bool VectorStringToArray::StringToNestedTypeCastLoop(const string_t *source_data if (array_size != str_array_size) { if (all_lengths_match) { all_lengths_match = false; - auto msg = StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type %s" - ", the size of the array must match the destination type", - source_data[idx].GetString(), result.GetType().ToString()); + auto msg = + StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type ARRAY[%u]" + ", the size of the array must match the destination type", + source_data[idx].GetString(), array_size); if (parameters.strict) { throw ConversionException(msg); } @@ -417,9 +421,9 @@ bool VectorStringToArray::StringToNestedTypeCastLoop(const string_t *source_data } if (!VectorStringToList::SplitStringList(source_data[idx], child_data, total, varchar_vector)) { - auto error = StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type %s", - source_data[idx].GetString(), result.GetType().ToString()); - HandleVectorCastError::Operation(error, result_mask, i, vector_cast_data); + auto text = StringUtil::Format("Type VARCHAR with value '%s' can't be cast to the destination type ARRAY", + source_data[idx].GetString()); + HandleVectorCastError::Operation(text, result_mask, i, vector_cast_data); } } D_ASSERT(total == child_count); diff --git a/src/duckdb/src/function/cast/struct_cast.cpp b/src/duckdb/src/function/cast/struct_cast.cpp index a28e7a070..051581c54 100644 --- a/src/duckdb/src/function/cast/struct_cast.cpp +++ b/src/duckdb/src/function/cast/struct_cast.cpp @@ -2,7 +2,6 @@ #include "duckdb/function/cast/default_casts.hpp" #include "duckdb/function/cast/cast_function_set.hpp" #include "duckdb/function/cast/bound_cast_data.hpp" -#include "duckdb/function/cast/vector_cast_helpers.hpp" namespace duckdb { @@ -139,7 +138,6 @@ static bool StructToVarcharCast(Vector &source, Vector &result, idx_t count, Cas auto &cast_data = parameters.cast_data->Cast(); Vector varchar_struct(cast_data.target, count); StructToStructCast(source, varchar_struct, count, parameters); - auto &base_children = StructVector::GetEntries(source); // now construct the actual varchar vector varchar_struct.Flatten(count); @@ -149,47 +147,29 @@ static bool StructToVarcharCast(Vector &source, Vector &result, idx_t count, Cas auto &validity = FlatVector::Validity(varchar_struct); auto result_data = FlatVector::GetData(result); static constexpr const idx_t SEP_LENGTH = 2; - static constexpr const idx_t NAME_SEP_LENGTH = 2; + static constexpr const idx_t NAME_SEP_LENGTH = 4; static constexpr const idx_t NULL_LENGTH = 4; - auto key_needs_quotes = make_unsafe_uniq_array_uninitialized(children.size()); - auto value_needs_quotes = make_unsafe_uniq_array_uninitialized(children.size()); - for (idx_t i = 0; i < count; i++) { if (!validity.RowIsValid(i)) { FlatVector::SetNull(result, i, true); continue; } - - //! Calculate the total length of the row idx_t string_length = 2; // {} for (idx_t c = 0; c < children.size(); c++) { if (c > 0) { string_length += SEP_LENGTH; } - auto add_escapes = !base_children[c]->GetType().IsNested(); - auto string_length_func = add_escapes ? VectorCastHelpers::CalculateEscapedStringLength - : VectorCastHelpers::CalculateStringLength; - children[c]->Flatten(count); auto &child_validity = FlatVector::Validity(*children[c]); auto data = FlatVector::GetData(*children[c]); auto &name = child_types[c].first; if (!is_unnamed) { - string_length += VectorCastHelpers::CalculateEscapedStringLength(name, key_needs_quotes[c]); - string_length += NAME_SEP_LENGTH; // ": " - } - if (child_validity.RowIsValid(i)) { - //! Skip the `\`, not a special character outside quotes - string_length += string_length_func(data[i], value_needs_quotes[c]); - } else { - string_length += NULL_LENGTH; + string_length += name.size() + NAME_SEP_LENGTH; // "'{name}': " } + string_length += child_validity.RowIsValid(i) ? data[i].GetSize() : NULL_LENGTH; } - result_data[i] = StringVector::EmptyString(result, string_length); auto dataptr = result_data[i].GetDataWriteable(); - - //! Serialize the struct to the string idx_t offset = 0; dataptr[offset++] = is_unnamed ? '(' : '{'; for (idx_t c = 0; c < children.size(); c++) { @@ -197,23 +177,23 @@ static bool StructToVarcharCast(Vector &source, Vector &result, idx_t count, Cas memcpy(dataptr + offset, ", ", SEP_LENGTH); offset += SEP_LENGTH; } - auto add_escapes = !base_children[c]->GetType().IsNested(); - auto write_string_func = - add_escapes ? VectorCastHelpers::WriteEscapedString : VectorCastHelpers::WriteString; - auto &child_validity = FlatVector::Validity(*children[c]); auto data = FlatVector::GetData(*children[c]); if (!is_unnamed) { auto &name = child_types[c].first; - // "{: }" - offset += VectorCastHelpers::WriteEscapedString(dataptr + offset, name, key_needs_quotes[c]); + // "'{name}': " + dataptr[offset++] = '\''; + memcpy(dataptr + offset, name.c_str(), name.size()); + offset += name.size(); + dataptr[offset++] = '\''; dataptr[offset++] = ':'; dataptr[offset++] = ' '; } // value if (child_validity.RowIsValid(i)) { - //! Skip the `\`, not a special character outside quotes - offset += write_string_func(dataptr + offset, data[i], value_needs_quotes[c]); + auto len = data[i].GetSize(); + memcpy(dataptr + offset, data[i].GetData(), len); + offset += len; } else { memcpy(dataptr + offset, "NULL", NULL_LENGTH); offset += NULL_LENGTH; diff --git a/src/duckdb/src/function/cast/vector_cast_helpers.cpp b/src/duckdb/src/function/cast/vector_cast_helpers.cpp index 444c37c5e..c7aa523ea 100644 --- a/src/duckdb/src/function/cast/vector_cast_helpers.cpp +++ b/src/duckdb/src/function/cast/vector_cast_helpers.cpp @@ -1,107 +1,85 @@ #include "duckdb/function/cast/vector_cast_helpers.hpp" -#include "duckdb/common/stack.hpp" -#include "duckdb/common/typedefs.hpp" - -namespace { - -struct StringCastInputState { -public: - StringCastInputState(const char *buf, duckdb::idx_t &pos, duckdb::idx_t &len) : buf(buf), pos(pos), len(len) { - } - -public: - const char *buf; - duckdb::idx_t &pos; - duckdb::idx_t &len; - bool escaped = false; -}; - -} // namespace namespace duckdb { // ------- Helper functions for splitting string nested types ------- -static bool IsNull(const char *buf, idx_t pos, idx_t end_pos) { - if (pos + 4 != end_pos) { - return false; +static bool IsNull(const char *buf, idx_t start_pos, Vector &child, idx_t row_idx) { + if ((buf[start_pos] == 'N' || buf[start_pos] == 'n') && (buf[start_pos + 1] == 'U' || buf[start_pos + 1] == 'u') && + (buf[start_pos + 2] == 'L' || buf[start_pos + 2] == 'l') && + (buf[start_pos + 3] == 'L' || buf[start_pos + 3] == 'l')) { + FlatVector::SetNull(child, row_idx, true); + return true; } - return StringUtil::CIEquals(buf + pos, 4, "null", 4); + return false; } -inline static void SkipWhitespace(StringCastInputState &input_state) { - auto &buf = input_state.buf; - auto &pos = input_state.pos; - auto &len = input_state.len; +inline static void SkipWhitespace(const char *buf, idx_t &pos, idx_t len) { while (pos < len && StringUtil::CharacterIsSpace(buf[pos])) { pos++; - input_state.escaped = false; } } -static bool SkipToCloseQuotes(StringCastInputState &input_state) { - auto &buf = input_state.buf; - auto &pos = input_state.pos; - auto &len = input_state.len; - auto &escaped = input_state.escaped; - +static bool SkipToCloseQuotes(idx_t &pos, const char *buf, idx_t &len) { char quote = buf[pos]; pos++; + bool escaped = false; while (pos < len) { - bool set_escaped = false; if (buf[pos] == '\\') { - if (!escaped) { - set_escaped = true; - } + escaped = !escaped; } else { if (buf[pos] == quote && !escaped) { return true; } + escaped = false; } - escaped = set_escaped; pos++; } return false; } -static bool SkipToClose(StringCastInputState &input_state) { - auto &idx = input_state.pos; - auto &buf = input_state.buf; - auto &len = input_state.len; - - D_ASSERT(buf[idx] == '{' || buf[idx] == '[' || buf[idx] == '('); +static bool SkipToClose(idx_t &idx, const char *buf, idx_t &len, idx_t &lvl, char close_bracket) { + idx++; vector brackets; + brackets.push_back(close_bracket); while (idx < len) { - bool set_escaped = false; if (buf[idx] == '"' || buf[idx] == '\'') { - if (!input_state.escaped) { - if (!SkipToCloseQuotes(input_state)) { - return false; - } + if (!SkipToCloseQuotes(idx, buf, len)) { + return false; } } else if (buf[idx] == '{') { brackets.push_back('}'); - } else if (buf[idx] == '(') { - brackets.push_back(')'); } else if (buf[idx] == '[') { brackets.push_back(']'); + lvl++; } else if (buf[idx] == brackets.back()) { + if (buf[idx] == ']') { + lvl--; + } brackets.pop_back(); if (brackets.empty()) { return true; } - } else if (buf[idx] == '\\') { - //! Note that we don't treat `\\` special here, backslashes can't be escaped outside of quotes - //! backslashes within quotes will not be encountered in this function - set_escaped = true; } - input_state.escaped = set_escaped; idx++; } return false; } +static idx_t StringTrim(const char *buf, idx_t &start_pos, idx_t pos) { + idx_t trailing_whitespace = 0; + while (pos > start_pos && StringUtil::CharacterIsSpace(buf[pos - trailing_whitespace - 1])) { + trailing_whitespace++; + } + if ((buf[start_pos] == '"' && buf[pos - trailing_whitespace - 1] == '"') || + (buf[start_pos] == '\'' && buf[pos - trailing_whitespace - 1] == '\'')) { + start_pos++; + trailing_whitespace++; + } + return (pos - trailing_whitespace); +} + struct CountPartOperation { idx_t count = 0; @@ -114,200 +92,75 @@ struct CountPartOperation { } }; -template -static string_t HandleString(Vector &vec, const char *buf, idx_t start, idx_t end) { - D_ASSERT(start <= end); - auto length = end - start; - auto allocated_string = StringVector::EmptyString(vec, length); - auto string_data = allocated_string.GetDataWriteable(); - uint32_t copied_count = 0; - bool escaped = false; - - bool quoted = false; - char quote_char; - stack scopes; - for (idx_t i = 0; i < length; i++) { - auto current_char = buf[start + i]; - if (!escaped) { - if (scopes.empty() && current_char == '\\') { - if (quoted || (start + i + 1 < end && (buf[start + i + 1] == '\'' || buf[start + i + 1] == '"'))) { - //! Start of escape - escaped = true; - continue; - } - } - if (scopes.empty() && (current_char == '\'' || current_char == '"')) { - if (quoted && current_char == quote_char) { - quoted = false; - //! Skip the ending quote - continue; - } else if (!quoted) { - quoted = true; - quote_char = current_char; - //! Skip the starting quote - continue; - } - } - if (!quoted && !scopes.empty() && current_char == scopes.top()) { - //! Close scope - scopes.pop(); - } - if (!quoted && (current_char == '[' || current_char == '{' || current_char == '(')) { - if (RESPECT_SCOPES) { - //! 'RESPECT_SCOPES' is false in things like STRUCT keys, these are regular strings - //! New scope - char end_char; - if (current_char == '[') { - end_char = ']'; - } else if (current_char == '{') { - end_char = '}'; - } else { - D_ASSERT(current_char == '('); - end_char = ')'; - } - scopes.push(end_char); - } - } - //! Regular character - string_data[copied_count++] = current_char; - } else { - string_data[copied_count++] = current_char; - escaped = false; - } - } - return string_t((const char *)string_data, copied_count); // NOLINT -} - // ------- LIST SPLIT ------- struct SplitStringListOperation { -public: - SplitStringListOperation(string_t *child_data, idx_t &entry_count, Vector &child) - : child_data(child_data), entry_count(entry_count), child(child) { - } - -public: - void HandleValue(const char *buf, idx_t start, idx_t end) { - if (IsNull(buf, start, end)) { - FlatVector::SetNull(child, entry_count, true); - entry_count++; - return; - } - child_data[entry_count] = HandleString(child, buf, start, end); - entry_count++; + SplitStringListOperation(string_t *child_data, idx_t &child_start, Vector &child) + : child_data(child_data), child_start(child_start), child(child) { } -private: string_t *child_data; - idx_t &entry_count; + idx_t &child_start; Vector &child; -}; - -static inline bool ValueStateTransition(StringCastInputState &input_state, optional_idx &start_pos, idx_t &end_pos) { - auto &buf = input_state.buf; - auto &pos = input_state.pos; - bool set_escaped = false; - if (buf[pos] == '"' || buf[pos] == '\'') { - if (!start_pos.IsValid()) { - start_pos = pos; - } - if (!input_state.escaped) { - if (!SkipToCloseQuotes(input_state)) { - return false; - } - } - end_pos = pos; - } else if (buf[pos] == '{') { - if (!start_pos.IsValid()) { - start_pos = pos; - } - if (!SkipToClose(input_state)) { - return false; - } - end_pos = pos; - } else if (buf[pos] == '(') { - if (!start_pos.IsValid()) { - start_pos = pos; - } - if (!SkipToClose(input_state)) { - return false; - } - end_pos = pos; - } else if (buf[pos] == '[') { - if (!start_pos.IsValid()) { - start_pos = pos; - } - if (!SkipToClose(input_state)) { - return false; - } - end_pos = pos; - } else if (buf[pos] == '\\') { - if (!start_pos.IsValid()) { - start_pos = pos; + void HandleValue(const char *buf, idx_t start_pos, idx_t pos) { + if ((pos - start_pos) == 4 && IsNull(buf, start_pos, child, child_start)) { + child_start++; + return; } - set_escaped = true; - end_pos = pos; - } else if (!StringUtil::CharacterIsSpace(buf[pos])) { - if (!start_pos.IsValid()) { - start_pos = pos; + if (start_pos > pos) { + pos = start_pos; } - end_pos = pos; + child_data[child_start] = StringVector::AddString(child, buf + start_pos, pos - start_pos); + child_start++; } - input_state.escaped = set_escaped; - pos++; - - return true; -} +}; template static bool SplitStringListInternal(const string_t &input, OP &state) { const char *buf = input.GetData(); idx_t len = input.GetSize(); + idx_t lvl = 1; idx_t pos = 0; + bool seen_value = false; - StringCastInputState input_state(buf, pos, len); - - SkipWhitespace(input_state); + SkipWhitespace(buf, pos, len); if (pos == len || buf[pos] != '[') { - //! Does not have a valid list start return false; } - //! Skip the '[' - pos++; - SkipWhitespace(input_state); - bool seen_value = false; + SkipWhitespace(buf, ++pos, len); + idx_t start_pos = pos; while (pos < len) { - optional_idx start_pos; - idx_t end_pos; - - while (pos < len && (buf[pos] != ',' && buf[pos] != ']')) { - if (!ValueStateTransition(input_state, start_pos, end_pos)) { + if (buf[pos] == '[') { + if (!SkipToClose(pos, buf, len, ++lvl, ']')) { return false; } - } - if (pos == len) { - return false; - } - if (buf[pos] != ']' || start_pos.IsValid() || seen_value) { - if (!start_pos.IsValid()) { - state.HandleValue(buf, 0, 0); - } else { - auto start = start_pos.GetIndex(); - state.HandleValue(buf, start, end_pos + 1); + } else if ((buf[pos] == '"' || buf[pos] == '\'') && pos == start_pos) { + SkipToCloseQuotes(pos, buf, len); + } else if (buf[pos] == '{') { + idx_t struct_lvl = 0; + SkipToClose(pos, buf, len, struct_lvl, '}'); + } else if (buf[pos] == ',' || buf[pos] == ']') { + idx_t trailing_whitespace = 0; + while (StringUtil::CharacterIsSpace(buf[pos - trailing_whitespace - 1])) { + trailing_whitespace++; } - seen_value = true; - } - if (buf[pos] == ']') { - break; + if (buf[pos] != ']' || start_pos != pos || seen_value) { + state.HandleValue(buf, start_pos, pos - trailing_whitespace); + seen_value = true; + } + if (buf[pos] == ']') { + lvl--; + break; + } + SkipWhitespace(buf, ++pos, len); + start_pos = pos; + continue; } - pos++; - SkipWhitespace(input_state); } - pos++; - SkipWhitespace(input_state); - return (pos == len); + SkipWhitespace(buf, ++pos, len); + return (pos == len && lvl == 0); } bool VectorStringToList::SplitStringList(const string_t &input, string_t *child_data, idx_t &child_start, @@ -337,95 +190,78 @@ struct SplitStringMapOperation { Vector &varchar_val; bool HandleKey(const char *buf, idx_t start_pos, idx_t pos) { - if (IsNull(buf, start_pos, pos)) { + if ((pos - start_pos) == 4 && IsNull(buf, start_pos, varchar_key, child_start)) { FlatVector::SetNull(varchar_val, child_start, true); - FlatVector::SetNull(varchar_key, child_start, true); child_start++; return false; } - child_key_data[child_start] = HandleString(varchar_key, buf, start_pos, pos); + child_key_data[child_start] = StringVector::AddString(varchar_key, buf + start_pos, pos - start_pos); return true; } void HandleValue(const char *buf, idx_t start_pos, idx_t pos) { - if (IsNull(buf, start_pos, pos)) { - FlatVector::SetNull(varchar_val, child_start, true); + if ((pos - start_pos) == 4 && IsNull(buf, start_pos, varchar_val, child_start)) { child_start++; return; } - child_val_data[child_start] = HandleString(varchar_val, buf, start_pos, pos); + child_val_data[child_start] = StringVector::AddString(varchar_val, buf + start_pos, pos - start_pos); child_start++; } }; +template +static bool FindKeyOrValueMap(const char *buf, idx_t len, idx_t &pos, OP &state, bool key) { + auto start_pos = pos; + idx_t lvl = 0; + while (pos < len) { + if (buf[pos] == '"' || buf[pos] == '\'') { + SkipToCloseQuotes(pos, buf, len); + } else if (buf[pos] == '{') { + SkipToClose(pos, buf, len, lvl, '}'); + } else if (buf[pos] == '[') { + SkipToClose(pos, buf, len, lvl, ']'); + } else if (key && buf[pos] == '=') { + idx_t end_pos = StringTrim(buf, start_pos, pos); + return state.HandleKey(buf, start_pos, end_pos); // put string in KEY_child_vector + } else if (!key && (buf[pos] == ',' || buf[pos] == '}')) { + idx_t end_pos = StringTrim(buf, start_pos, pos); + state.HandleValue(buf, start_pos, end_pos); // put string in VALUE_child_vector + return true; + } + pos++; + } + return false; +} + template static bool SplitStringMapInternal(const string_t &input, OP &state) { const char *buf = input.GetData(); idx_t len = input.GetSize(); idx_t pos = 0; - StringCastInputState input_state(buf, pos, len); - SkipWhitespace(input_state); + SkipWhitespace(buf, pos, len); if (pos == len || buf[pos] != '{') { return false; } - pos++; - SkipWhitespace(input_state); + SkipWhitespace(buf, ++pos, len); if (pos == len) { return false; } if (buf[pos] == '}') { - pos++; - SkipWhitespace(input_state); - return pos == len; + SkipWhitespace(buf, ++pos, len); + return (pos == len); } - while (pos < len) { - optional_idx start_pos; - idx_t end_pos; - while (pos < len && buf[pos] != '=') { - if (!ValueStateTransition(input_state, start_pos, end_pos)) { - return false; - } - } - if (pos == len) { + if (!FindKeyOrValueMap(buf, len, pos, state, true)) { return false; } - if (!start_pos.IsValid()) { - start_pos = 0; - end_pos = 0; - } else { - end_pos++; - } - if (!state.HandleKey(buf, start_pos.GetIndex(), end_pos)) { + SkipWhitespace(buf, ++pos, len); + if (!FindKeyOrValueMap(buf, len, pos, state, false)) { return false; } - start_pos = optional_idx(); - pos++; - SkipWhitespace(input_state); - while (pos < len && (buf[pos] != ',' && buf[pos] != '}')) { - if (!ValueStateTransition(input_state, start_pos, end_pos)) { - return false; - } - } - if (pos == len) { - return false; - } - if (!start_pos.IsValid()) { - //! Value is empty - state.HandleValue(buf, 0, 0); - } else { - state.HandleValue(buf, start_pos.GetIndex(), end_pos + 1); - } - if (buf[pos] == '}') { - break; - } - pos++; - SkipWhitespace(input_state); + SkipWhitespace(buf, ++pos, len); } - pos++; - SkipWhitespace(input_state); - return (pos == len); + return true; } bool VectorStringToMap::SplitStringMap(const string_t &input, string_t *child_key_data, string_t *child_val_data, @@ -441,6 +277,42 @@ idx_t VectorStringToMap::CountPartsMap(const string_t &input) { } // ------- STRUCT SPLIT ------- +static bool FindKeyStruct(const char *buf, idx_t len, idx_t &pos) { + while (pos < len) { + if (buf[pos] == ':') { + return true; + } + pos++; + } + return false; +} + +static bool FindValueStruct(const char *buf, idx_t len, idx_t &pos, Vector &varchar_child, idx_t &row_idx, + ValidityMask &child_mask) { + auto start_pos = pos; + idx_t lvl = 0; + while (pos < len) { + if (buf[pos] == '"' || buf[pos] == '\'') { + SkipToCloseQuotes(pos, buf, len); + } else if (buf[pos] == '{') { + SkipToClose(pos, buf, len, lvl, '}'); + } else if (buf[pos] == '[') { + SkipToClose(pos, buf, len, lvl, ']'); + } else if (buf[pos] == ',' || buf[pos] == '}') { + idx_t end_pos = StringTrim(buf, start_pos, pos); + if ((end_pos - start_pos) == 4 && IsNull(buf, start_pos, varchar_child, row_idx)) { + return true; + } + FlatVector::GetData(varchar_child)[row_idx] = + StringVector::AddString(varchar_child, buf + start_pos, end_pos - start_pos); + child_mask.SetValid(row_idx); // any child not set to valid will remain invalid + return true; + } + pos++; + } + return false; +} + bool VectorStringToStruct::SplitStruct(const string_t &input, vector> &varchar_vectors, idx_t &row_idx, string_map_t &child_names, vector> &child_masks) { @@ -449,161 +321,39 @@ bool VectorStringToStruct::SplitStruct(const string_t &input, vector= key_end) { + // empty key name unsupported return false; } - idx_t key_start = start_pos.GetIndex(); - end_pos++; - if (IsNull(buf, key_start, end_pos)) { - //! Key can not be NULL - return false; - } - auto child_name = HandleString(temp_vec, buf, key_start, end_pos); - auto it = child_names.find(child_name); + string_t found_key(buf + key_start, UnsafeNumericCast(key_end - key_start)); + + auto it = child_names.find(found_key); if (it == child_names.end()) { return false; // false key } child_idx = it->second; - - start_pos = optional_idx(); - pos++; - SkipWhitespace(input_state); - while (pos < len && (buf[pos] != ',' && buf[pos] != '}')) { - if (!ValueStateTransition(input_state, start_pos, end_pos)) { - return false; - } - } - if (pos == len) { + SkipWhitespace(buf, ++pos, len); + if (!FindValueStruct(buf, len, pos, *varchar_vectors[child_idx], row_idx, child_masks[child_idx].get())) { return false; } - auto &child_vec = *varchar_vectors[child_idx]; - auto string_data = FlatVector::GetData(child_vec); - auto &child_mask = child_masks[child_idx].get(); - - if (!start_pos.IsValid()) { - start_pos = 0; - end_pos = 0; - } else { - end_pos++; - } - auto value_start = start_pos.GetIndex(); - if (IsNull(buf, value_start, end_pos)) { - child_mask.SetInvalid(row_idx); - } else { - string_data[row_idx] = HandleString(child_vec, buf, value_start, end_pos); - child_mask.SetValid(row_idx); - } - - if (buf[pos] == '}') { - break; - } - pos++; - SkipWhitespace(input_state); - } - } else { - //! This is an unnamed struct in the form of `(value, value_2, ...)` - D_ASSERT(end_char == ')'); - idx_t child_idx = 0; - while (pos < len) { - if (child_idx == child_masks.size()) { - return false; - } - - optional_idx start_pos; - idx_t end_pos; - while (pos < len && (buf[pos] != ',' && buf[pos] != ')')) { - if (!ValueStateTransition(input_state, start_pos, end_pos)) { - return false; - } - } - if (pos == len) { - return false; - } - auto &child_vec = *varchar_vectors[child_idx]; - auto string_data = FlatVector::GetData(child_vec); - auto &child_mask = child_masks[child_idx].get(); - - if (!start_pos.IsValid()) { - start_pos = 0; - end_pos = 0; - } else { - end_pos++; - } - auto value_start = start_pos.GetIndex(); - if (IsNull(buf, value_start, end_pos)) { - child_mask.SetInvalid(row_idx); - } else { - string_data[row_idx] = HandleString(child_vec, buf, value_start, end_pos); - child_mask.SetValid(row_idx); - } - - if (buf[pos] == ')') { - break; - } - child_idx++; - pos++; - SkipWhitespace(input_state); + SkipWhitespace(buf, ++pos, len); } - (void)child_idx; } - pos++; - SkipWhitespace(input_state); + SkipWhitespace(buf, pos, len); return (pos == len); } diff --git a/src/duckdb/src/function/copy_function.cpp b/src/duckdb/src/function/copy_function.cpp index d6395fbd1..ac2bc7545 100644 --- a/src/duckdb/src/function/copy_function.cpp +++ b/src/duckdb/src/function/copy_function.cpp @@ -8,8 +8,6 @@ vector GetCopyFunctionReturnNames(CopyFunctionReturnType return_type) { return {"Count"}; case CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST: return {"Count", "Files"}; - case CopyFunctionReturnType::WRITTEN_FILE_STATISTICS: - return {"filename", "count", "file_size_bytes", "footer_size_bytes", "column_statistics", "partition_keys"}; default: throw NotImplementedException("Unknown CopyFunctionReturnType"); } @@ -21,13 +19,6 @@ vector GetCopyFunctionReturnLogicalTypes(CopyFunctionReturnType ret return {LogicalType::BIGINT}; case CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST: return {LogicalType::BIGINT, LogicalType::LIST(LogicalType::VARCHAR)}; - case CopyFunctionReturnType::WRITTEN_FILE_STATISTICS: - return {LogicalType::VARCHAR, - LogicalType::UBIGINT, - LogicalType::UBIGINT, - LogicalType::UBIGINT, - LogicalType::MAP(LogicalType::VARCHAR, LogicalType::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR)), - LogicalType::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR)}; default: throw NotImplementedException("Unknown CopyFunctionReturnType"); } diff --git a/src/duckdb/src/function/function_binder.cpp b/src/duckdb/src/function/function_binder.cpp index bf8f95464..b0e3bbc73 100644 --- a/src/duckdb/src/function/function_binder.cpp +++ b/src/duckdb/src/function/function_binder.cpp @@ -301,9 +301,11 @@ unique_ptr FunctionBinder::BindScalarFunction(const string &schema, vector> children, ErrorData &error, bool is_operator, optional_ptr binder) { // bind the function - auto &function = Catalog::GetSystemCatalog(context).GetEntry(context, schema, name); + auto &function = + Catalog::GetSystemCatalog(context).GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, schema, name); D_ASSERT(function.type == CatalogType::SCALAR_FUNCTION_ENTRY); - return BindScalarFunction(function, std::move(children), error, is_operator, binder); + return BindScalarFunction(function.Cast(), std::move(children), error, is_operator, + binder); } unique_ptr FunctionBinder::BindScalarFunction(ScalarFunctionCatalogEntry &func, diff --git a/src/duckdb/src/function/function_list.cpp b/src/duckdb/src/function/function_list.cpp index 001849dc2..3950308e3 100644 --- a/src/duckdb/src/function/function_list.cpp +++ b/src/duckdb/src/function/function_list.cpp @@ -17,27 +17,27 @@ namespace duckdb { // Scalar Function -#define DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, _PARAM::GetFunction, nullptr, nullptr, nullptr } -#define DUCKDB_SCALAR_FUNCTION(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_SCALAR_FUNCTION_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::GetFunction, nullptr, nullptr, nullptr } +#define DUCKDB_SCALAR_FUNCTION(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_SCALAR_FUNCTION_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name) // Scalar Function Set -#define DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, nullptr, _PARAM::GetFunctions, nullptr, nullptr } -#define DUCKDB_SCALAR_FUNCTION_SET(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_SCALAR_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, nullptr, _PARAM::GetFunctions, nullptr, nullptr } +#define DUCKDB_SCALAR_FUNCTION_SET(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_SCALAR_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_SCALAR_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name) // Aggregate Function -#define DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, nullptr, nullptr, _PARAM::GetFunction, nullptr } -#define DUCKDB_AGGREGATE_FUNCTION(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_AGGREGATE_FUNCTION_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, nullptr, nullptr, _PARAM::GetFunction, nullptr } +#define DUCKDB_AGGREGATE_FUNCTION(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_AGGREGATE_FUNCTION_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_BASE(_PARAM::ALIAS, _PARAM::Name) // Aggregate Function Set -#define DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _NAME, _ALIAS_OF) \ - { _NAME, _ALIAS_OF, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, _PARAM::Categories, nullptr, nullptr, nullptr, _PARAM::GetFunctions } -#define DUCKDB_AGGREGATE_FUNCTION_SET(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _PARAM::Name, _PARAM::Name) -#define DUCKDB_AGGREGATE_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name, _PARAM::ALIAS::Name) +#define DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _NAME) \ + { _NAME, _PARAM::Parameters, _PARAM::Description, _PARAM::Example, nullptr, nullptr, nullptr, _PARAM::GetFunctions } +#define DUCKDB_AGGREGATE_FUNCTION_SET(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM, _PARAM::Name) +#define DUCKDB_AGGREGATE_FUNCTION_SET_ALIAS(_PARAM) DUCKDB_AGGREGATE_FUNCTION_SET_BASE(_PARAM::ALIAS, _PARAM::Name) #define FINAL_FUNCTION \ - { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } + { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr } // this list is generated by scripts/generate_functions.py static const StaticFunctionDefinition function[] = { @@ -83,8 +83,6 @@ static const StaticFunctionDefinition function[] = { DUCKDB_SCALAR_FUNCTION_ALIAS(ArrayWhereFun), DUCKDB_SCALAR_FUNCTION_ALIAS(ArrayZipFun), DUCKDB_SCALAR_FUNCTION_SET(BitLengthFun), - DUCKDB_SCALAR_FUNCTION_SET_ALIAS(CharLengthFun), - DUCKDB_SCALAR_FUNCTION_SET_ALIAS(CharacterLengthFun), DUCKDB_SCALAR_FUNCTION(CombineFun), DUCKDB_SCALAR_FUNCTION(ConcatFun), DUCKDB_SCALAR_FUNCTION(ConcatWsFun), @@ -93,9 +91,6 @@ static const StaticFunctionDefinition function[] = { DUCKDB_AGGREGATE_FUNCTION_SET(CountFun), DUCKDB_AGGREGATE_FUNCTION(CountStarFun), DUCKDB_SCALAR_FUNCTION(CreateSortKeyFun), - DUCKDB_SCALAR_FUNCTION(CurrentConnectionId), - DUCKDB_SCALAR_FUNCTION(CurrentQueryId), - DUCKDB_SCALAR_FUNCTION(CurrentTransactionId), DUCKDB_SCALAR_FUNCTION(CurrvalFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(DivideFun), DUCKDB_SCALAR_FUNCTION_ALIAS(EndsWithFun), @@ -143,7 +138,6 @@ static const StaticFunctionDefinition function[] = { DUCKDB_SCALAR_FUNCTION_SET(RegexpMatchesFun), DUCKDB_SCALAR_FUNCTION_SET(RegexpReplaceFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(RegexpSplitToArrayFun), - DUCKDB_SCALAR_FUNCTION(RemapStructFun), DUCKDB_SCALAR_FUNCTION(RowFun), DUCKDB_SCALAR_FUNCTION_SET(SHA1Fun), DUCKDB_SCALAR_FUNCTION_SET(SHA256Fun), @@ -159,7 +153,7 @@ static const StaticFunctionDefinition function[] = { DUCKDB_SCALAR_FUNCTION_SET(StrpTimeFun), DUCKDB_SCALAR_FUNCTION(StructConcatFun), DUCKDB_SCALAR_FUNCTION_SET(StructExtractFun), - DUCKDB_SCALAR_FUNCTION(StructExtractAtFun), + DUCKDB_SCALAR_FUNCTION_SET(StructExtractAtFun), DUCKDB_SCALAR_FUNCTION(StructPackFun), DUCKDB_SCALAR_FUNCTION_SET_ALIAS(SubstrFun), DUCKDB_SCALAR_FUNCTION_SET(SubstringFun), diff --git a/src/duckdb/src/function/pragma/pragma_functions.cpp b/src/duckdb/src/function/pragma/pragma_functions.cpp index 4378f16e1..635828066 100644 --- a/src/duckdb/src/function/pragma/pragma_functions.cpp +++ b/src/duckdb/src/function/pragma/pragma_functions.cpp @@ -94,10 +94,6 @@ static void PragmaForceCheckpoint(ClientContext &context, const FunctionParamete DBConfig::GetConfig(context).options.force_checkpoint = true; } -static void PragmaTruncateDuckDBLogs(ClientContext &context, const FunctionParameters ¶meters) { - context.db->GetLogManager().TruncateLogStorage(); -} - static void PragmaDisableForceParallelism(ClientContext &context, const FunctionParameters ¶meters) { ClientConfig::GetConfig(context).verify_parallelism = false; } @@ -116,14 +112,6 @@ static void PragmaDisableCheckpointOnShutdown(ClientContext &context, const Func DBConfig::GetConfig(context).options.checkpoint_on_shutdown = false; } -static void PragmaEnableLogging(ClientContext &context, const FunctionParameters ¶meters) { - context.db->GetLogManager().SetEnableLogging(true); -} - -static void PragmaDisableLogging(ClientContext &context, const FunctionParameters ¶meters) { - context.db->GetLogManager().SetEnableLogging(false); -} - static void PragmaEnableOptimizer(ClientContext &context, const FunctionParameters ¶meters) { ClientConfig::GetConfig(context).enable_optimizer = true; } @@ -156,16 +144,11 @@ void PragmaFunctions::RegisterFunction(BuiltinFunctions &set) { set.AddFunction(PragmaFunction::PragmaStatement("enable_object_cache", PragmaEnableObjectCache)); set.AddFunction(PragmaFunction::PragmaStatement("disable_object_cache", PragmaDisableObjectCache)); - set.AddFunction(PragmaFunction::PragmaStatement("enable_logging", PragmaEnableLogging)); - set.AddFunction(PragmaFunction::PragmaStatement("disable_logging", PragmaDisableLogging)); - set.AddFunction(PragmaFunction::PragmaStatement("enable_optimizer", PragmaEnableOptimizer)); set.AddFunction(PragmaFunction::PragmaStatement("disable_optimizer", PragmaDisableOptimizer)); set.AddFunction(PragmaFunction::PragmaStatement("force_checkpoint", PragmaForceCheckpoint)); - set.AddFunction(PragmaFunction::PragmaStatement("truncate_duckdb_logs", PragmaTruncateDuckDBLogs)); - set.AddFunction(PragmaFunction::PragmaStatement("enable_progress_bar", PragmaEnableProgressBar)); set.AddFunction(PragmaFunction::PragmaStatement("disable_progress_bar", PragmaDisableProgressBar)); diff --git a/src/duckdb/src/function/register_function_list.cpp b/src/duckdb/src/function/register_function_list.cpp index bc7cef655..1aeebbbbb 100644 --- a/src/duckdb/src/function/register_function_list.cpp +++ b/src/duckdb/src/function/register_function_list.cpp @@ -10,7 +10,6 @@ namespace duckdb { template static void FillExtraInfo(const StaticFunctionDefinition &function, T &info) { info.internal = true; - info.alias_of = function.alias_of; FillFunctionDescriptions(function, info); } diff --git a/src/duckdb/src/function/scalar/operator/arithmetic.cpp b/src/duckdb/src/function/scalar/operator/arithmetic.cpp index 858ecb384..a3c11ed63 100644 --- a/src/duckdb/src/function/scalar/operator/arithmetic.cpp +++ b/src/duckdb/src/function/scalar/operator/arithmetic.cpp @@ -3,19 +3,21 @@ #include "duckdb/common/operator/multiply.hpp" #include "duckdb/common/operator/numeric_binary_operators.hpp" #include "duckdb/common/operator/subtract.hpp" -#include "duckdb/common/serializer/deserializer.hpp" -#include "duckdb/common/serializer/serializer.hpp" #include "duckdb/common/types/date.hpp" #include "duckdb/common/types/decimal.hpp" +#include "duckdb/common/types/hugeint.hpp" #include "duckdb/common/types/interval.hpp" #include "duckdb/common/types/time.hpp" #include "duckdb/common/types/timestamp.hpp" +#include "duckdb/common/vector_operations/vector_operations.hpp" +#include "duckdb/function/scalar/nested_functions.hpp" #include "duckdb/function/scalar/operators.hpp" #include "duckdb/function/scalar/operator_functions.hpp" #include "duckdb/function/scalar/string_functions.hpp" -#include "duckdb/main/client_context.hpp" #include "duckdb/planner/expression/bound_function_expression.hpp" +#include + namespace duckdb { template @@ -80,7 +82,7 @@ static scalar_function_t GetScalarBinaryFunction(PhysicalType type) { //===--------------------------------------------------------------------===// struct AddPropagateStatistics { template - static bool Operation(const LogicalType &type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min, + static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min, Value &new_max) { T min, max; // new min is min+min @@ -99,7 +101,7 @@ struct AddPropagateStatistics { struct SubtractPropagateStatistics { template - static bool Operation(const LogicalType &type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min, + static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min, Value &new_max) { T min, max; if (!OP::Operation(NumericStats::GetMin(lstats), NumericStats::GetMax(rstats), min)) { @@ -125,7 +127,7 @@ struct DecimalArithmeticBindData : public FunctionData { } bool Equals(const FunctionData &other_p) const override { - const auto &other = other_p.Cast(); + auto other = other_p.Cast(); return other.check_overflow == check_overflow; } @@ -525,7 +527,7 @@ struct DecimalNegateBindData : public FunctionData { } bool Equals(const FunctionData &other_p) const override { - const auto &other = other_p.Cast(); + auto other = other_p.Cast(); return other.bound_type == bound_type; } @@ -557,7 +559,7 @@ unique_ptr DecimalNegateBind(ClientContext &context, ScalarFunctio struct NegatePropagateStatistics { template - static bool Operation(const LogicalType &type, BaseStatistics &istats, Value &new_min, Value &new_max) { + static bool Operation(LogicalType type, BaseStatistics &istats, Value &new_min, Value &new_max) { auto max_value = NumericStats::GetMax(istats); auto min_value = NumericStats::GetMin(istats); if (!NegateOperator::CanNegate(min_value) || !NegateOperator::CanNegate(max_value)) { @@ -756,7 +758,7 @@ ScalarFunctionSet OperatorSubtractFun::GetFunctions() { //===--------------------------------------------------------------------===// struct MultiplyPropagateStatistics { template - static bool Operation(const LogicalType &type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min, + static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min, Value &new_max) { // statistics propagation on the multiplication is slightly less straightforward because of negative numbers // the new min/max depend on the signs of the input types @@ -880,8 +882,8 @@ ScalarFunctionSet OperatorMultiplyFun::GetFunctions() { } } multiply.AddFunction( - ScalarFunction({LogicalType::INTERVAL, LogicalType::DOUBLE}, LogicalType::INTERVAL, - ScalarFunction::BinaryFunction)); + ScalarFunction({LogicalType::INTERVAL, LogicalType::BIGINT}, LogicalType::INTERVAL, + ScalarFunction::BinaryFunction)); multiply.AddFunction( ScalarFunction({LogicalType::BIGINT, LogicalType::INTERVAL}, LogicalType::INTERVAL, ScalarFunction::BinaryFunction)); @@ -916,13 +918,11 @@ hugeint_t DivideOperator::Operation(hugeint_t left, hugeint_t right) { } template <> -interval_t DivideOperator::Operation(interval_t left, double right) { - interval_t result; - if (!TryMultiplyOperator::Operation(left, 1.0 / right, result)) { - throw OutOfRangeException("Overflow in INTERVAL division"); - } - - return result; +interval_t DivideOperator::Operation(interval_t left, int64_t right) { + left.days = UnsafeNumericCast(left.days / right); + left.months = UnsafeNumericCast(left.months / right); + left.micros /= right; + return left; } struct BinaryNumericDivideWrapper { @@ -1033,8 +1033,8 @@ ScalarFunctionSet OperatorFloatDivideFun::GetFunctions() { fp_divide.AddFunction(ScalarFunction({LogicalType::DOUBLE, LogicalType::DOUBLE}, LogicalType::DOUBLE, nullptr, BindBinaryFloatingPoint)); fp_divide.AddFunction( - ScalarFunction({LogicalType::INTERVAL, LogicalType::DOUBLE}, LogicalType::INTERVAL, - BinaryScalarFunctionIgnoreZero)); + ScalarFunction({LogicalType::INTERVAL, LogicalType::BIGINT}, LogicalType::INTERVAL, + BinaryScalarFunctionIgnoreZero)); for (auto &func : fp_divide.functions) { ScalarFunction::SetReturnsError(func); } diff --git a/src/duckdb/src/function/scalar/operator/multiply.cpp b/src/duckdb/src/function/scalar/operator/multiply.cpp index a07594348..c2ae20767 100644 --- a/src/duckdb/src/function/scalar/operator/multiply.cpp +++ b/src/duckdb/src/function/scalar/operator/multiply.cpp @@ -4,8 +4,10 @@ #include "duckdb/common/operator/cast_operators.hpp" #include "duckdb/common/types/hugeint.hpp" #include "duckdb/common/types/uhugeint.hpp" +#include "duckdb/common/types/value.hpp" #include "duckdb/common/windows_undefs.hpp" +#include #include namespace duckdb { @@ -39,89 +41,6 @@ interval_t MultiplyOperator::Operation(int64_t left, interval_t right) { return MultiplyOperator::Operation(right, left); } -// TSROUND. -// Avoid std::rint because it can raise exceptions and we know that can't happen. -inline double PGTimestampRound(const double &j) { - return (std::nearbyint(((double)(j)) * Interval::MICROS_PER_SEC) / Interval::MICROS_PER_SEC); -} - -// Taken from Postgres src.backend/utils/adt/timestamp.c:interval_mul -template <> -bool TryMultiplyOperator::Operation(interval_t left, double right, interval_t &result) { - double d = left.months * right; - if (std::isnan(d) || d < NumericLimits::Minimum() || d > NumericLimits::Maximum()) { - return false; - } - result.months = LossyNumericCast(d); - - d = left.days * right; - if (std::isnan(d) || d < NumericLimits::Minimum() || d > NumericLimits::Maximum()) { - return false; - } - result.days = LossyNumericCast(d); - - /* - * The above correctly handles the whole-number part of the month and day - * products, but we have to do something with any fractional part - * resulting when the factor is non-integral. We cascade the fractions - * down to lower units using the conversion factors DAYS_PER_MONTH and - * SECS_PER_DAY. Note we do NOT cascade up, since we are not forced to do - * so by the representation. The user can choose to cascade up later, - * using justify_hours and/or justify_days. - */ - - /* - * Fractional months full days into days. - * - * Floating point calculation are inherently imprecise, so these - * calculations are crafted to produce the most reliable result possible. - * TSROUND() is needed to more accurately produce whole numbers where - * appropriate. - */ - double month_remainder = (left.months * right - result.months) * Interval::DAYS_PER_MONTH; - month_remainder = PGTimestampRound(month_remainder); - auto day_remainder = LossyNumericCast(month_remainder); - - double sec_remainder = (left.days * right - result.days + month_remainder - day_remainder) * Interval::SECS_PER_DAY; - sec_remainder = PGTimestampRound(sec_remainder); - - /* - * Might have 24:00:00 hours due to rounding, or >24 hours because of time - * cascade from months and days. It might still be >24 if the combination - * of cascade and the seconds factor operation itself. - */ - if (std::fabs(sec_remainder) >= Interval::SECS_PER_DAY) { - result.days += LossyNumericCast(sec_remainder / Interval::SECS_PER_DAY); - sec_remainder -= LossyNumericCast(sec_remainder / Interval::SECS_PER_DAY) * Interval::SECS_PER_DAY; - } - - /* cascade units down */ - result.days += day_remainder; - if (!TryCast::Operation(left.micros, d)) { - return false; - } - d = std::nearbyint(d * right + sec_remainder * Interval::MICROS_PER_SEC); - if (std::isnan(d) || !TryCast::Operation(d, result.micros)) { - return false; - } - - return true; -} - -template <> -interval_t MultiplyOperator::Operation(interval_t left, double right) { - interval_t result; - if (!TryMultiplyOperator::Operation(left, right, result)) { - throw OutOfRangeException("Overflow in multiplication of INTERVAL."); - } - return result; -} - -template <> -interval_t MultiplyOperator::Operation(double left, interval_t right) { - return MultiplyOperator::Operation(right, left); -} - //===--------------------------------------------------------------------===// // * [multiply] with overflow check //===--------------------------------------------------------------------===// diff --git a/src/duckdb/src/function/scalar/sequence/nextval.cpp b/src/duckdb/src/function/scalar/sequence/nextval.cpp index 5f50b259b..6738383dc 100644 --- a/src/duckdb/src/function/scalar/sequence/nextval.cpp +++ b/src/duckdb/src/function/scalar/sequence/nextval.cpp @@ -32,8 +32,9 @@ struct NextSequenceValueOperator { SequenceCatalogEntry &BindSequence(Binder &binder, string &catalog, string &schema, const string &name) { // fetch the sequence from the catalog Binder::BindSchemaOrCatalog(binder.context, catalog, schema); - EntryLookupInfo sequence_lookup(CatalogType::SEQUENCE_ENTRY, name); - return binder.EntryRetriever().GetEntry(catalog, schema, sequence_lookup)->Cast(); + return binder.EntryRetriever() + .GetEntry(CatalogType::SEQUENCE_ENTRY, catalog, schema, name) + ->Cast(); } SequenceCatalogEntry &BindSequenceFromContext(ClientContext &context, string &catalog, string &schema, diff --git a/src/duckdb/src/function/scalar/strftime_format.cpp b/src/duckdb/src/function/scalar/strftime_format.cpp index d46f72352..58ccd9959 100644 --- a/src/duckdb/src/function/scalar/strftime_format.cpp +++ b/src/duckdb/src/function/scalar/strftime_format.cpp @@ -48,14 +48,6 @@ idx_t StrfTimepecifierSize(StrTimeSpecifier specifier) { } } -void StrfTimeSplitOffset(int offset, int &hh, int &mm, int &ss) { - hh = offset / Interval::SECS_PER_HOUR; - offset = offset % Interval::SECS_PER_HOUR; - - mm = offset / Interval::SECS_PER_MINUTE; - ss = offset % Interval::SECS_PER_MINUTE; -} - void StrTimeFormat::AddLiteral(string literal) { constant_size += literal.size(); literals.push_back(std::move(literal)); @@ -101,12 +93,9 @@ idx_t StrfTimeFormat::GetSpecifierLength(StrTimeSpecifier specifier, date_t date len += month >= 10; return len; } - case StrTimeSpecifier::UTC_OFFSET: { - // ±HH or ±HH:MM or ±HH:MM:SS - int hh, mm, ss; - StrfTimeSplitOffset(data[7], hh, mm, ss); - return ss ? 9 : (mm ? 6 : 3); - } + case StrTimeSpecifier::UTC_OFFSET: + // ±HH or ±HH:MM + return (data[7] % 60) ? 6 : 3; case StrTimeSpecifier::TZ_NAME: if (tz_name) { return strlen(tz_name); @@ -306,7 +295,7 @@ char *StrfTimeFormat::WriteDateSpecifier(StrTimeSpecifier specifier, date_t date char *StrfTimeFormat::WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t data[], const char *tz_name, size_t tz_len, char *target) const { - // data contains [0] year, [1] month, [2] day, [3] hour, [4] minute, [5] second, [6] ns, [7] utc (secs) + // data contains [0] year, [1] month, [2] day, [3] hour, [4] minute, [5] second, [6] ns, [7] utc switch (specifier) { case StrTimeSpecifier::DAY_OF_MONTH_PADDED: target = WritePadded2(target, UnsafeNumericCast(data[2])); @@ -376,16 +365,12 @@ char *StrfTimeFormat::WriteStandardSpecifier(StrTimeSpecifier specifier, int32_t *target++ = (data[7] < 0) ? '-' : '+'; auto offset = abs(data[7]); - int hh, mm, ss; - StrfTimeSplitOffset(offset, hh, mm, ss); - target = WritePadded2(target, UnsafeNumericCast(hh)); - if (mm || ss) { + auto offset_hours = offset / Interval::MINS_PER_HOUR; + auto offset_minutes = offset % Interval::MINS_PER_HOUR; + target = WritePadded2(target, UnsafeNumericCast(offset_hours)); + if (offset_minutes) { *target++ = ':'; - target = WritePadded2(target, UnsafeNumericCast(mm)); - } - if (ss) { - *target++ = ':'; - target = WritePadded2(target, UnsafeNumericCast(ss)); + target = WritePadded2(target, UnsafeNumericCast(offset_minutes)); } break; } @@ -1033,6 +1018,7 @@ bool StrpTimeFormat::Parse(const char *data, size_t size, ParseResult &result, b error_message = "Incompatible ISO year offset specified"; error_position = start_pos; return false; + break; } if (number > 9999) { // %G only supports numbers between [0..9999] @@ -1137,17 +1123,15 @@ bool StrpTimeFormat::Parse(const char *data, size_t size, ParseResult &result, b weekday = number; break; case StrTimeSpecifier::WEEK_NUMBER_ISO: + // y/m/d overrides G/V/u but does not conflict switch (offset_specifier) { - case StrTimeSpecifier::YEAR_WITHOUT_CENTURY_PADDED: - case StrTimeSpecifier::YEAR_WITHOUT_CENTURY: - case StrTimeSpecifier::YEAR_DECIMAL: - error_message = "ISO week offsets are incompatible with non-ISO year specifiers. Use '%G' instead"; - error_position = start_pos; - return false; case StrTimeSpecifier::DAY_OF_MONTH_PADDED: case StrTimeSpecifier::DAY_OF_MONTH: case StrTimeSpecifier::MONTH_DECIMAL_PADDED: case StrTimeSpecifier::MONTH_DECIMAL: + case StrTimeSpecifier::YEAR_WITHOUT_CENTURY_PADDED: + case StrTimeSpecifier::YEAR_WITHOUT_CENTURY: + case StrTimeSpecifier::YEAR_DECIMAL: // Just validate, don't use break; case StrTimeSpecifier::WEEKDAY_DECIMAL: @@ -1286,13 +1270,13 @@ bool StrpTimeFormat::Parse(const char *data, size_t size, ParseResult &result, b break; } case StrTimeSpecifier::UTC_OFFSET: { - int hh, mm, ss; - if (!Timestamp::TryParseUTCOffset(data, pos, size, hh, mm, ss)) { - error_message = "Expected ±HH[MM] or -HH[:MM[:SS]]"; + int hour_offset, minute_offset; + if (!Timestamp::TryParseUTCOffset(data, pos, size, hour_offset, minute_offset)) { + error_message = "Expected +HH[MM] or -HH[MM]"; error_position = pos; return false; } - result_data[7] = (hh * Interval::MINS_PER_HOUR + mm) * Interval::SECS_PER_MINUTE + ss; + result_data[7] = hour_offset * Interval::MINS_PER_HOUR + minute_offset; break; } case StrTimeSpecifier::TZ_NAME: { @@ -1465,15 +1449,15 @@ int32_t StrpTimeFormat::ParseResult::GetMicros() const { } dtime_t StrpTimeFormat::ParseResult::ToTime() { - int hh, mm, ss; - StrfTimeSplitOffset(data[7], hh, mm, ss); - return Time::FromTime(data[3] - hh, data[4] - mm, data[5] - ss, GetMicros()); + const auto hour_offset = data[7] / Interval::MINS_PER_HOUR; + const auto mins_offset = data[7] % Interval::MINS_PER_HOUR; + return Time::FromTime(data[3] - hour_offset, data[4] - mins_offset, data[5], GetMicros()); } int64_t StrpTimeFormat::ParseResult::ToTimeNS() { - int hh, mm, ss; - StrfTimeSplitOffset(data[7], hh, mm, ss); - return Time::ToNanoTime(data[3] - hh, data[4] - mm, data[5] - ss, data[6]); + const int32_t hour_offset = data[7] / Interval::MINS_PER_HOUR; + const int32_t mins_offset = data[7] % Interval::MINS_PER_HOUR; + return Time::ToNanoTime(data[3] - hour_offset, data[4] - mins_offset, data[5], data[6]); } bool StrpTimeFormat::ParseResult::TryToTime(dtime_t &result) { diff --git a/src/duckdb/src/function/scalar/string/concat.cpp b/src/duckdb/src/function/scalar/string/concat.cpp index 0ee57a752..a6a495a95 100644 --- a/src/duckdb/src/function/scalar/string/concat.cpp +++ b/src/duckdb/src/function/scalar/string/concat.cpp @@ -335,9 +335,9 @@ static unique_ptr ListConcatStats(ClientContext &context, Functi ScalarFunction ListConcatFun::GetFunction() { // The arguments and return types are set in the binder function. - auto fun = ScalarFunction({}, LogicalType::LIST(LogicalType::ANY), ConcatFunction, BindConcatFunction, nullptr, + auto fun = ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::LIST(LogicalType::ANY)}, + LogicalType::LIST(LogicalType::ANY), ConcatFunction, BindConcatFunction, nullptr, ListConcatStats); - fun.varargs = LogicalType::LIST(LogicalType::ANY); fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING; return fun; } diff --git a/src/duckdb/src/function/scalar/string/contains.cpp b/src/duckdb/src/function/scalar/string/contains.cpp index 220000cfe..b34d62c78 100644 --- a/src/duckdb/src/function/scalar/string/contains.cpp +++ b/src/duckdb/src/function/scalar/string/contains.cpp @@ -8,57 +8,96 @@ namespace duckdb { -struct ContainsAligned { - template - static bool MatchRemainder(const unsigned char *haystack, const unsigned char *needle, idx_t needle_size) { - return true; +template +static idx_t ContainsUnaligned(const unsigned char *haystack, idx_t haystack_size, const unsigned char *needle, + idx_t base_offset) { + if (NEEDLE_SIZE > haystack_size) { + // needle is bigger than haystack: haystack cannot contain needle + return DConstants::INVALID_INDEX; } -}; + // contains for a small unaligned needle (3/5/6/7 bytes) + // we perform unsigned integer comparisons to check for equality of the entire needle in a single comparison + // this implementation is inspired by the memmem implementation of freebsd -struct ContainsUnaligned { - template - static bool MatchRemainder(const unsigned char *haystack, const unsigned char *needle, idx_t needle_size) { - idx_t matches = 0; - for (idx_t i = sizeof(UNSIGNED); i < needle_size; i++) { - matches += haystack[i] == needle[i]; + // first we set up the needle and the first NEEDLE_SIZE characters of the haystack as UNSIGNED integers + UNSIGNED needle_entry = 0; + UNSIGNED haystack_entry = 0; + const UNSIGNED start = (sizeof(UNSIGNED) * 8) - 8; + const UNSIGNED shift = (sizeof(UNSIGNED) - NEEDLE_SIZE) * 8; + for (idx_t i = 0; i < NEEDLE_SIZE; i++) { + needle_entry |= UNSIGNED(needle[i]) << UNSIGNED(start - i * 8); + haystack_entry |= UNSIGNED(haystack[i]) << UNSIGNED(start - i * 8); + } + // now we perform the actual search + for (idx_t offset = NEEDLE_SIZE; offset < haystack_size; offset++) { + // for this position we first compare the haystack with the needle + if (haystack_entry == needle_entry) { + return base_offset + offset - NEEDLE_SIZE; } - return matches == needle_size - sizeof(UNSIGNED); + // now we adjust the haystack entry by + // (1) removing the left-most character (shift by 8) + // (2) adding the next character (bitwise or, with potential shift) + // this shift is only necessary if the needle size is not aligned with the unsigned integer size + // (e.g. needle size 3, unsigned integer size 4, we need to shift by 1) + haystack_entry = (haystack_entry << 8) | ((UNSIGNED(haystack[offset])) << shift); } -}; - -struct ContainsGeneric { - template - static bool MatchRemainder(const unsigned char *haystack, const unsigned char *needle, idx_t needle_size) { - return memcmp(haystack + sizeof(UNSIGNED), needle + sizeof(UNSIGNED), needle_size - sizeof(UNSIGNED)) == 0; + if (haystack_entry == needle_entry) { + return base_offset + haystack_size - NEEDLE_SIZE; } -}; + return DConstants::INVALID_INDEX; +} -template -static idx_t Contains(const unsigned char *haystack, idx_t haystack_size, const unsigned char *needle, - idx_t needle_size, idx_t base_offset) { - if (needle_size > haystack_size) { +template +static idx_t ContainsAligned(const unsigned char *haystack, idx_t haystack_size, const unsigned char *needle, + idx_t base_offset) { + if (sizeof(UNSIGNED) > haystack_size) { // needle is bigger than haystack: haystack cannot contain needle return DConstants::INVALID_INDEX; } - haystack_size -= needle_size - 1; + // contains for a small needle aligned with unsigned integer (2/4/8) + // similar to ContainsUnaligned, but simpler because we only need to do a reinterpret cast auto needle_entry = Load(needle); - for (idx_t offset = 0; offset < haystack_size; offset++) { - // start off by performing a memchr to find the first character of the - auto location = - static_cast(memchr(haystack + offset, needle[0], haystack_size - offset)); - if (!location) { - return DConstants::INVALID_INDEX; - } + for (idx_t offset = 0; offset <= haystack_size - sizeof(UNSIGNED); offset++) { // for this position we first compare the haystack with the needle - offset = UnsafeNumericCast(location - haystack); - auto haystack_entry = Load(location); + auto haystack_entry = Load(haystack + offset); if (needle_entry == haystack_entry) { - if (OP::template MatchRemainder(location, needle, needle_size)) { + return base_offset + offset; + } + } + return DConstants::INVALID_INDEX; +} + +idx_t ContainsGeneric(const unsigned char *haystack, idx_t haystack_size, const unsigned char *needle, + idx_t needle_size, idx_t base_offset) { + if (needle_size > haystack_size) { + // needle is bigger than haystack: haystack cannot contain needle + return DConstants::INVALID_INDEX; + } + // this implementation is inspired by Raphael Javaux's faststrstr (https://github.com/RaphaelJ/fast_strstr) + // generic contains; note that we can't use strstr because we don't have null-terminated strings anymore + // we keep track of a shifting window sum of all characters with window size equal to needle_size + // this shifting sum is used to avoid calling into memcmp; + // we only need to call into memcmp when the window sum is equal to the needle sum + // when that happens, the characters are potentially the same and we call into memcmp to check if they are + uint32_t sums_diff = 0; + for (idx_t i = 0; i < needle_size; i++) { + sums_diff += haystack[i]; + sums_diff -= needle[i]; + } + idx_t offset = 0; + while (true) { + if (sums_diff == 0 && haystack[offset] == needle[0]) { + if (memcmp(haystack + offset, needle, needle_size) == 0) { return base_offset + offset; } } + if (offset >= haystack_size - needle_size) { + return DConstants::INVALID_INDEX; + } + sums_diff -= haystack[offset]; + sums_diff += haystack[offset + needle_size]; + offset++; } - return DConstants::INVALID_INDEX; } idx_t FindStrInStr(const unsigned char *haystack, idx_t haystack_size, const unsigned char *needle, idx_t needle_size) { @@ -76,21 +115,21 @@ idx_t FindStrInStr(const unsigned char *haystack, idx_t haystack_size, const uns case 1: return base_offset; case 2: - return Contains(haystack, haystack_size, needle, 2, base_offset); + return ContainsAligned(haystack, haystack_size, needle, base_offset); case 3: - return Contains(haystack, haystack_size, needle, 3, base_offset); + return ContainsUnaligned(haystack, haystack_size, needle, base_offset); case 4: - return Contains(haystack, haystack_size, needle, 4, base_offset); + return ContainsAligned(haystack, haystack_size, needle, base_offset); case 5: - return Contains(haystack, haystack_size, needle, 5, base_offset); + return ContainsUnaligned(haystack, haystack_size, needle, base_offset); case 6: - return Contains(haystack, haystack_size, needle, 6, base_offset); + return ContainsUnaligned(haystack, haystack_size, needle, base_offset); case 7: - return Contains(haystack, haystack_size, needle, 7, base_offset); + return ContainsUnaligned(haystack, haystack_size, needle, base_offset); case 8: - return Contains(haystack, haystack_size, needle, 8, base_offset); + return ContainsAligned(haystack, haystack_size, needle, base_offset); default: - return Contains(haystack, haystack_size, needle, needle_size, base_offset); + return ContainsGeneric(haystack, haystack_size, needle, needle_size, base_offset); } } diff --git a/src/duckdb/src/function/scalar/string/regexp.cpp b/src/duckdb/src/function/scalar/string/regexp.cpp index f91121a07..2383e3b57 100644 --- a/src/duckdb/src/function/scalar/string/regexp.cpp +++ b/src/duckdb/src/function/scalar/string/regexp.cpp @@ -186,9 +186,6 @@ static void RegexReplaceFunction(DataChunk &args, ExpressionState &state, Vector TernaryExecutor::Execute( strings, patterns, replaces, result, args.size(), [&](string_t input, string_t pattern, string_t replace) { RE2 re(CreateStringPiece(pattern), info.options); - if (!re.ok()) { - throw InvalidInputException(re.error()); - } std::string sstring = input.GetString(); if (info.global_replace) { RE2::GlobalReplace(&sstring, re, CreateStringPiece(replace)); diff --git a/src/duckdb/src/function/scalar/string/strip_accents.cpp b/src/duckdb/src/function/scalar/string/strip_accents.cpp index a28ccf914..2ab7ca497 100644 --- a/src/duckdb/src/function/scalar/string/strip_accents.cpp +++ b/src/duckdb/src/function/scalar/string/strip_accents.cpp @@ -6,19 +6,7 @@ namespace duckdb { bool IsAscii(const char *input, idx_t n) { - static constexpr uint64_t MASK = 0x8080808080808080U; - - // Check 8 bytes at a time - idx_t i = 0; - for (; i + sizeof(uint64_t) <= n; i += sizeof(uint64_t)) { - if ((Load(const_data_ptr_cast(input + i)) & MASK)) { - // non-ascii character in the next 8 bytes - return false; - } - } - - // Less than 8 bytes remain - for (; i < n; i++) { + for (idx_t i = 0; i < n; i++) { if (input[i] & 0x80) { // non-ascii character return false; diff --git a/src/duckdb/src/function/scalar/struct/struct_extract.cpp b/src/duckdb/src/function/scalar/struct/struct_extract.cpp index 23c5419cd..20cc74157 100644 --- a/src/duckdb/src/function/scalar/struct/struct_extract.cpp +++ b/src/duckdb/src/function/scalar/struct/struct_extract.cpp @@ -84,7 +84,7 @@ static unique_ptr StructExtractBind(ClientContext &context, Scalar } bound_function.return_type = std::move(return_type); - return StructExtractAtFun::GetBindData(key_index); + return GetBindData(key_index); } static unique_ptr StructExtractBindInternal(ClientContext &context, ScalarFunction &bound_function, @@ -121,7 +121,7 @@ static unique_ptr StructExtractBindInternal(ClientContext &context index, struct_children.size()); } bound_function.return_type = struct_children[NumericCast(index - 1)].second; - return StructExtractAtFun::GetBindData(NumericCast(index - 1)); + return GetBindData(NumericCast(index - 1)); } static unique_ptr StructExtractBindIndex(ClientContext &context, ScalarFunction &bound_function, @@ -143,7 +143,7 @@ static unique_ptr PropagateStructExtractStats(ClientContext &con return struct_child_stats[info.index].ToUnique(); } -unique_ptr StructExtractAtFun::GetBindData(idx_t index) { +unique_ptr GetBindData(idx_t index) { return make_uniq(index); } @@ -170,8 +170,10 @@ ScalarFunctionSet StructExtractFun::GetFunctions() { return struct_extract_set; } -ScalarFunction StructExtractAtFun::GetFunction() { - return GetExtractAtFunction(); +ScalarFunctionSet StructExtractAtFun::GetFunctions() { + ScalarFunctionSet struct_extractat_set("struct_extract_at"); + struct_extractat_set.AddFunction(GetExtractAtFunction()); + return struct_extractat_set; } } // namespace duckdb diff --git a/src/duckdb/src/function/scalar/system/aggregate_export.cpp b/src/duckdb/src/function/scalar/system/aggregate_export.cpp index 71c081f3a..64fee3e8c 100644 --- a/src/duckdb/src/function/scalar/system/aggregate_export.cpp +++ b/src/duckdb/src/function/scalar/system/aggregate_export.cpp @@ -208,8 +208,8 @@ static unique_ptr BindAggregateState(ClientContext &context, Scala auto state_type = AggregateStateType::GetStateType(arg_return_type); // now we can look up the function in the catalog again and bind it - auto &func = Catalog::GetSystemCatalog(context).GetEntry(context, DEFAULT_SCHEMA, - state_type.function_name); + auto &func = Catalog::GetSystemCatalog(context).GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, + DEFAULT_SCHEMA, state_type.function_name); if (func.type != CatalogType::AGGREGATE_FUNCTION_ENTRY) { throw InternalException("Could not find aggregate %s", state_type.function_name); } diff --git a/src/duckdb/src/function/table/copy_csv.cpp b/src/duckdb/src/function/table/copy_csv.cpp index 6e6f145dc..e4eeedb8f 100644 --- a/src/duckdb/src/function/table/copy_csv.cpp +++ b/src/duckdb/src/function/table/copy_csv.cpp @@ -1,6 +1,6 @@ #include "duckdb/common/bind_helpers.hpp" #include "duckdb/common/file_system.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/serializer/memory_stream.hpp" #include "duckdb/common/serializer/write_stream.hpp" #include "duckdb/common/string_util.hpp" @@ -8,7 +8,6 @@ #include "duckdb/common/types/string_type.hpp" #include "duckdb/common/vector_operations/vector_operations.hpp" #include "duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp" -#include "duckdb/execution/operator/csv_scanner/csv_multi_file_info.hpp" #include "duckdb/function/copy_function.hpp" #include "duckdb/function/scalar/string_functions.hpp" #include "duckdb/function/table/read_csv.hpp" @@ -18,7 +17,6 @@ #include "duckdb/parser/expression/function_expression.hpp" #include "duckdb/parser/parsed_data/copy_info.hpp" #include "duckdb/planner/expression/bound_reference_expression.hpp" -#include "duckdb/common/multi_file/multi_file_function.hpp" #include @@ -229,6 +227,54 @@ static unique_ptr WriteCSVBind(ClientContext &context, CopyFunctio return std::move(bind_data); } +static unique_ptr ReadCSVBind(ClientContext &context, CopyInfo &info, vector &expected_names, + vector &expected_types) { + auto bind_data = make_uniq(); + bind_data->csv_types = expected_types; + bind_data->csv_names = expected_names; + bind_data->return_types = expected_types; + bind_data->return_names = expected_names; + + auto multi_file_reader = MultiFileReader::CreateDefault("CSVCopy"); + bind_data->files = multi_file_reader->CreateFileList(context, Value(info.file_path))->GetAllFiles(); + + auto &options = bind_data->options; + + // check all the options in the copy info + for (auto &option : info.options) { + auto loption = StringUtil::Lower(option.first); + auto &set = option.second; + options.SetReadOption(loption, ConvertVectorToValue(set), expected_names); + } + // verify the parsed options + if (options.force_not_null.empty()) { + // no FORCE_QUOTE specified: initialize to false + options.force_not_null.resize(expected_types.size(), false); + } + + // Look for rejects table options last + named_parameter_map_t options_map; + for (auto &option : info.options) { + options_map[option.first] = ConvertVectorToValue(std::move(option.second)); + } + options.file_path = bind_data->files[0]; + options.name_list = expected_names; + options.sql_type_list = expected_types; + options.columns_set = true; + for (idx_t i = 0; i < expected_types.size(); i++) { + options.sql_types_per_column[expected_names[i]] = i; + } + + if (options.auto_detect) { + auto buffer_manager = make_shared_ptr(context, options, bind_data->files[0], 0); + CSVSniffer sniffer(options, buffer_manager, CSVStateMachineCache::Get(context)); + sniffer.SniffCSV(); + } + bind_data->FinalizeRead(context); + + return std::move(bind_data); +} + //===--------------------------------------------------------------------===// // Helper writing functions //===--------------------------------------------------------------------===// @@ -606,7 +652,7 @@ void CSVCopyFunction::RegisterFunction(BuiltinFunctions &set) { info.rotate_files = WriteCSVRotateFiles; info.rotate_next_file = WriteCSVRotateNextFile; - info.copy_from_bind = MultiFileFunction::MultiFileBindCopy; + info.copy_from_bind = ReadCSVBind; info.copy_from_function = ReadCSVTableFunction::GetFunction(); info.extension = "csv"; diff --git a/src/duckdb/src/function/table/glob.cpp b/src/duckdb/src/function/table/glob.cpp index 324d9e622..736c2778e 100644 --- a/src/duckdb/src/function/table/glob.cpp +++ b/src/duckdb/src/function/table/glob.cpp @@ -3,7 +3,7 @@ #include "duckdb/function/function_set.hpp" #include "duckdb/common/file_system.hpp" #include "duckdb/main/config.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" namespace duckdb { diff --git a/src/duckdb/src/function/table/range.cpp b/src/duckdb/src/function/table/range.cpp index 7fd16a34e..17bcda81d 100644 --- a/src/duckdb/src/function/table/range.cpp +++ b/src/duckdb/src/function/table/range.cpp @@ -73,8 +73,6 @@ struct RangeFunctionLocalState : public LocalTableFunctionState { hugeint_t start; hugeint_t end; hugeint_t increment; - - bool empty_range = false; }; static unique_ptr RangeFunctionLocalInit(ExecutionContext &context, @@ -106,10 +104,10 @@ static void GenerateRangeParameters(DataChunk &input, idx_t row_id, RangeFunctio throw BinderException("interval cannot be 0!"); } if (result.start > result.end && result.increment > 0) { - result.empty_range = true; + throw BinderException("start is bigger than end, but increment is positive: cannot generate infinite series"); } if (result.start < result.end && result.increment < 0) { - result.empty_range = true; + throw BinderException("start is smaller than end, but increment is negative: cannot generate infinite series"); } if (GENERATE_SERIES) { // generate_series has inclusive bounds on the RHS @@ -138,13 +136,6 @@ static OperatorResultType RangeFunction(ExecutionContext &context, TableFunction state.initialized_row = true; state.current_idx = 0; } - if (state.empty_range) { - // empty range - output.SetCardinality(0); - state.current_input_row++; - state.initialized_row = false; - return OperatorResultType::HAVE_MORE_OUTPUT; - } auto increment = state.increment; auto end = state.end; hugeint_t current_value = state.start + increment * UnsafeNumericCast(state.current_idx); @@ -210,8 +201,6 @@ struct RangeDateTimeLocalState : public LocalTableFunctionState { bool inclusive_bound; bool greater_than_check; - bool empty_range = false; - bool Finished(timestamp_t current_value) const { if (greater_than_check) { if (inclusive_bound) { @@ -263,12 +252,14 @@ static void GenerateRangeDateTimeParameters(DataChunk &input, idx_t row_id, Rang } result.greater_than_check = true; if (result.start > result.end) { - result.empty_range = true; + throw BinderException( + "start is bigger than end, but increment is positive: cannot generate infinite series"); } } else { result.greater_than_check = false; if (result.start < result.end) { - result.empty_range = true; + throw BinderException( + "start is smaller than end, but increment is negative: cannot generate infinite series"); } } result.inclusive_bound = GENERATE_SERIES; @@ -297,13 +288,6 @@ static OperatorResultType RangeDateTimeFunction(ExecutionContext &context, Table state.initialized_row = true; state.current_state = state.start; } - if (state.empty_range) { - // empty range - output.SetCardinality(0); - state.current_input_row++; - state.initialized_row = false; - return OperatorResultType::HAVE_MORE_OUTPUT; - } idx_t size = 0; auto data = FlatVector::GetData(output.data[0]); while (true) { diff --git a/src/duckdb/src/function/table/read_csv.cpp b/src/duckdb/src/function/table/read_csv.cpp index ed39baa0c..e5bce2264 100644 --- a/src/duckdb/src/function/table/read_csv.cpp +++ b/src/duckdb/src/function/table/read_csv.cpp @@ -1,11 +1,11 @@ #include "duckdb/function/table/read_csv.hpp" #include "duckdb/common/enum_util.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/serializer/deserializer.hpp" #include "duckdb/common/serializer/serializer.hpp" #include "duckdb/common/string_util.hpp" -#include "duckdb/common/multi_file/union_by_name.hpp" +#include "duckdb/common/union_by_name.hpp" #include "duckdb/execution/operator/csv_scanner/global_csv_state.hpp" #include "duckdb/execution/operator/csv_scanner/csv_error.hpp" #include "duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp" @@ -27,20 +27,9 @@ #include #include "duckdb/execution/operator/csv_scanner/csv_schema.hpp" -#include "duckdb/common/multi_file/multi_file_function.hpp" -#include "duckdb/execution/operator/csv_scanner/csv_multi_file_info.hpp" namespace duckdb { -SerializedCSVReaderOptions::SerializedCSVReaderOptions(CSVReaderOptions options_p, MultiFileOptions file_options_p) - : options(std::move(options_p)), file_options(std::move(file_options_p)) { -} - -SerializedCSVReaderOptions::SerializedCSVReaderOptions(CSVOption single_byte_delimiter, - const CSVOption &multi_byte_delimiter) - : options(single_byte_delimiter, multi_byte_delimiter) { -} - unique_ptr ReadCSV::OpenCSV(const string &file_path, const CSVReaderOptions &options, ClientContext &context) { auto &fs = FileSystem::GetFileSystem(context); @@ -56,6 +45,273 @@ void ReadCSVData::FinalizeRead(ClientContext &context) { BaseCSVData::Finalize(); } +//! Function to do schema discovery over one CSV file or a list/glob of CSV files +void SchemaDiscovery(ClientContext &context, ReadCSVData &result, CSVReaderOptions &options, + vector &return_types, vector &names, MultiFileList &multi_file_list) { + vector schemas; + const auto option_og = options; + + const auto file_paths = multi_file_list.GetAllFiles(); + + // Here what we want to do is to sniff a given number of lines, if we have many files, we might go through them + // to reach the number of lines. + const idx_t required_number_of_lines = options.sniff_size * options.sample_size_chunks; + + idx_t total_number_of_rows = 0; + idx_t current_file = 0; + options.file_path = file_paths[current_file]; + + result.buffer_manager = make_shared_ptr(context, options, options.file_path, 0, false); + idx_t only_header_or_empty_files = 0; + + { + CSVSniffer sniffer(options, result.buffer_manager, CSVStateMachineCache::Get(context)); + auto sniffer_result = sniffer.SniffCSV(); + idx_t rows_read = sniffer.LinesSniffed() - + (options.dialect_options.skip_rows.GetValue() + options.dialect_options.header.GetValue()); + + schemas.emplace_back(sniffer_result.names, sniffer_result.return_types, file_paths[0], rows_read, + result.buffer_manager->GetBuffer(0)->actual_size == 0); + total_number_of_rows += sniffer.LinesSniffed(); + current_file++; + if (sniffer.EmptyOrOnlyHeader()) { + only_header_or_empty_files++; + } + } + + // We do a copy of the options to not pollute the options of the first file. + constexpr idx_t max_files_to_sniff = 10; + idx_t files_to_sniff = file_paths.size() > max_files_to_sniff ? max_files_to_sniff : file_paths.size(); + while (total_number_of_rows < required_number_of_lines && current_file < files_to_sniff) { + auto option_copy = option_og; + option_copy.file_path = file_paths[current_file]; + auto buffer_manager = + make_shared_ptr(context, option_copy, option_copy.file_path, current_file, false); + // TODO: We could cache the sniffer to be reused during scanning. Currently that's an exercise left to the + // reader + CSVSniffer sniffer(option_copy, buffer_manager, CSVStateMachineCache::Get(context)); + auto sniffer_result = sniffer.SniffCSV(); + idx_t rows_read = sniffer.LinesSniffed() - (option_copy.dialect_options.skip_rows.GetValue() + + option_copy.dialect_options.header.GetValue()); + if (buffer_manager->GetBuffer(0)->actual_size == 0) { + schemas.emplace_back(true); + } else { + schemas.emplace_back(sniffer_result.names, sniffer_result.return_types, option_copy.file_path, rows_read); + } + total_number_of_rows += sniffer.LinesSniffed(); + if (sniffer.EmptyOrOnlyHeader()) { + only_header_or_empty_files++; + } + current_file++; + } + + // We might now have multiple schemas, we need to go through them to define the one true schema + CSVSchema best_schema; + for (auto &schema : schemas) { + if (best_schema.Empty()) { + // A schema is bettah than no schema + best_schema = schema; + } else if (best_schema.GetRowsRead() == 0) { + // If the best-schema has no data-rows, that's easy, we just take the new schema + best_schema = schema; + } else if (schema.GetRowsRead() != 0) { + // We might have conflicting-schemas, we must merge them + best_schema.MergeSchemas(schema, options.null_padding); + } + } + + if (names.empty()) { + names = best_schema.GetNames(); + return_types = best_schema.GetTypes(); + } + if (only_header_or_empty_files == current_file && !options.columns_set) { + for (auto &type : return_types) { + D_ASSERT(type.id() == LogicalTypeId::BOOLEAN); + // we default to varchar if all files are empty or only have a header after all the sniffing + type = LogicalType::VARCHAR; + } + } + result.csv_types = return_types; + result.csv_names = names; +} + +static unique_ptr ReadCSVBind(ClientContext &context, TableFunctionBindInput &input, + vector &return_types, vector &names) { + + auto result = make_uniq(); + auto &options = result->options; + const auto multi_file_reader = MultiFileReader::Create(input.table_function); + const auto multi_file_list = multi_file_reader->CreateFileList(context, input.inputs[0]); + if (multi_file_list->GetTotalFileCount() > 1) { + options.multi_file_reader = true; + } + options.FromNamedParameters(input.named_parameters, context); + + options.file_options.AutoDetectHivePartitioning(*multi_file_list, context); + options.Verify(); + if (!options.file_options.union_by_name) { + if (options.auto_detect) { + SchemaDiscovery(context, *result, options, return_types, names, *multi_file_list); + } else { + // If we are not running the sniffer, the columns must be set! + if (!options.columns_set) { + throw BinderException("read_csv requires columns to be specified through the 'columns' option. Use " + "read_csv_auto or set read_csv(..., " + "AUTO_DETECT=TRUE) to automatically guess columns."); + } + names = options.name_list; + return_types = options.sql_type_list; + } + D_ASSERT(return_types.size() == names.size()); + result->options.dialect_options.num_cols = names.size(); + + multi_file_reader->BindOptions(options.file_options, *multi_file_list, return_types, names, + result->reader_bind); + } else { + result->reader_bind = multi_file_reader->BindUnionReader(context, return_types, names, + *multi_file_list, *result, options); + if (result->union_readers.size() > 1) { + for (idx_t i = 0; i < result->union_readers.size(); i++) { + result->column_info.emplace_back(result->union_readers[i]->names, result->union_readers[i]->types); + } + } + if (!options.sql_types_per_column.empty()) { + const auto exception = CSVError::ColumnTypesError(options.sql_types_per_column, names); + if (!exception.error_message.empty()) { + throw BinderException(exception.error_message); + } + for (idx_t i = 0; i < names.size(); i++) { + auto it = options.sql_types_per_column.find(names[i]); + if (it != options.sql_types_per_column.end()) { + return_types[i] = options.sql_type_list[it->second]; + } + } + } + } + + result->csv_types = return_types; + result->csv_names = names; + result->return_types = return_types; + result->return_names = names; + if (!options.force_not_null_names.empty()) { + // Let's first check all column names match + duckdb::unordered_set column_names; + for (auto &name : names) { + column_names.insert(name); + } + for (auto &force_name : options.force_not_null_names) { + if (column_names.find(force_name) == column_names.end()) { + throw BinderException("\"force_not_null\" expected to find %s, but it was not found in the table", + force_name); + } + } + D_ASSERT(options.force_not_null.empty()); + for (idx_t i = 0; i < names.size(); i++) { + if (options.force_not_null_names.find(names[i]) != options.force_not_null_names.end()) { + options.force_not_null.push_back(true); + } else { + options.force_not_null.push_back(false); + } + } + } + + // TODO: make the CSV reader use MultiFileList throughout, instead of converting to vector + result->files = multi_file_list->GetAllFiles(); + result->Finalize(); + return std::move(result); +} + +//===--------------------------------------------------------------------===// +// Read CSV Local State +//===--------------------------------------------------------------------===// +struct CSVLocalState : public LocalTableFunctionState { +public: + explicit CSVLocalState(unique_ptr csv_reader_p) : csv_reader(std::move(csv_reader_p)) { + } + + //! The CSV reader + unique_ptr csv_reader; + bool done = false; +}; + +//===--------------------------------------------------------------------===// +// Read CSV Functions +//===--------------------------------------------------------------------===// +static unique_ptr ReadCSVInitGlobal(ClientContext &context, TableFunctionInitInput &input) { + auto &bind_data = input.bind_data->Cast(); + + // Create the temporary rejects table + if (bind_data.options.store_rejects.GetValue()) { + CSVRejectsTable::GetOrCreate(context, bind_data.options.rejects_scan_name.GetValue(), + bind_data.options.rejects_table_name.GetValue()) + ->InitializeTable(context, bind_data); + } + if (bind_data.files.empty()) { + // This can happen when a filename based filter pushdown has eliminated all possible files for this scan. + return nullptr; + } + return make_uniq(context, bind_data.buffer_manager, bind_data.options, + context.db->NumberOfThreads(), bind_data.files, input.column_indexes, bind_data); +} + +unique_ptr ReadCSVInitLocal(ExecutionContext &context, TableFunctionInitInput &input, + GlobalTableFunctionState *global_state_p) { + if (!global_state_p) { + return nullptr; + } + auto &global_state = global_state_p->Cast(); + if (global_state.IsDone()) { + // nothing to do + return nullptr; + } + auto csv_scanner = global_state.Next(nullptr); + if (!csv_scanner) { + global_state.DecrementThread(); + } + return make_uniq(std::move(csv_scanner)); +} + +static void ReadCSVFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) { + auto &bind_data = data_p.bind_data->Cast(); + if (!data_p.global_state) { + return; + } + auto &csv_global_state = data_p.global_state->Cast(); + if (!data_p.local_state) { + return; + } + auto &csv_local_state = data_p.local_state->Cast(); + + if (!csv_local_state.csv_reader) { + // no csv_reader was set, this can happen when a filename-based filter has filtered out all possible files + return; + } + do { + if (output.size() != 0) { + MultiFileReader().FinalizeChunk(context, bind_data.reader_bind, + csv_local_state.csv_reader->csv_file_scan->reader_data, output, nullptr); + break; + } + if (csv_local_state.csv_reader->FinishedIterator()) { + csv_local_state.csv_reader = csv_global_state.Next(csv_local_state.csv_reader.get()); + if (!csv_local_state.csv_reader) { + csv_global_state.DecrementThread(); + break; + } + } + csv_local_state.csv_reader->Flush(output); + + } while (true); +} + +static OperatorPartitionData CSVReaderGetPartitionData(ClientContext &context, TableFunctionGetPartitionInput &input) { + if (input.partition_info.RequiresPartitionColumns()) { + throw InternalException("CSVReader::GetPartitionData: partition columns not supported"); + } + auto &data = input.local_state->Cast(); + return OperatorPartitionData(data.csv_reader->scanner_idx); +} + void ReadCSVTableFunction::ReadCSVAddNamedParameters(TableFunction &table_function) { table_function.named_parameters["sep"] = LogicalType::VARCHAR; table_function.named_parameters["delim"] = LogicalType::VARCHAR; @@ -99,59 +355,85 @@ void ReadCSVTableFunction::ReadCSVAddNamedParameters(TableFunction &table_functi MultiFileReader::AddParameters(table_function); } +double CSVReaderProgress(ClientContext &context, const FunctionData *bind_data_p, + const GlobalTableFunctionState *global_state) { + if (!global_state) { + return 0; + } + auto &bind_data = bind_data_p->Cast(); + auto &data = global_state->Cast(); + return data.GetProgress(bind_data); +} + +void CSVComplexFilterPushdown(ClientContext &context, LogicalGet &get, FunctionData *bind_data_p, + vector> &filters) { + auto &data = bind_data_p->Cast(); + SimpleMultiFileList file_list(data.files); + MultiFilePushdownInfo info(get); + auto filtered_list = + MultiFileReader().ComplexFilterPushdown(context, file_list, data.options.file_options, info, filters); + if (filtered_list) { + data.files = filtered_list->GetAllFiles(); + SimpleMultiFileList simple_filtered_list(data.files); + MultiFileReader::PruneReaders(data, simple_filtered_list); + } else { + data.files = file_list.GetAllFiles(); + } +} + +unique_ptr CSVReaderCardinality(ClientContext &context, const FunctionData *bind_data_p) { + auto &bind_data = bind_data_p->Cast(); + // determined through the scientific method as the average amount of rows in a CSV file + idx_t per_file_cardinality = 42; + if (bind_data.buffer_manager && bind_data.buffer_manager->file_handle) { + auto estimated_row_width = (bind_data.csv_types.size() * 5); + per_file_cardinality = bind_data.buffer_manager->file_handle->FileSize() / estimated_row_width; + } + return make_uniq(bind_data.files.size() * per_file_cardinality); +} + static void CSVReaderSerialize(Serializer &serializer, const optional_ptr bind_data_p, const TableFunction &function) { - throw NotImplementedException("CSVReaderSerialize not implemented"); - // auto &bind_data = bind_data_p->Cast(); - // auto &csv_data = bind_data.bind_data->Cast(); - // serializer.WriteProperty(100, "extra_info", function.extra_info); - // // generate the serialized data - // SerializedReadCSVData serialized_data; - // serialized_data.return_types = serialized_data.csv_types = bind_data.types; - // serialized_data.return_names = serialized_data.csv_names = bind_data.names; - // serialized_data.files = bind_data.file_list->GetAllFiles(); - // serialized_data.filename_col_idx = csv_data.filename_col_idx; - // serialized_data.options.options = csv_data.options; - // serialized_data.options.file_options = bind_data.file_options; - // serialized_data.reader_bind = bind_data.reader_bind; - // serializer.WriteProperty(101, "csv_data", serialized_data); + auto &bind_data = bind_data_p->Cast(); + serializer.WriteProperty(100, "extra_info", function.extra_info); + serializer.WriteProperty(101, "csv_data", &bind_data); } static unique_ptr CSVReaderDeserialize(Deserializer &deserializer, TableFunction &function) { - throw NotImplementedException("CSVReaderDeserialize not implemented"); - // auto &context = deserializer.Get(); - // SerializedReadCSVData serialized_data; - // deserializer.ReadProperty(100, "extra_info", function.extra_info); - // deserializer.ReadProperty(101, "csv_data", serialized_data); - // - // vector file_path; - // for (auto &path : serialized_data.files) { - // file_path.emplace_back(path); - // } - // auto multi_file_reader = MultiFileReader::Create(function); - // auto file_list = multi_file_reader->CreateFileList(context, Value::LIST(LogicalType::VARCHAR, file_path), - // FileGlobOptions::ALLOW_EMPTY); - // auto csv_options = make_uniq(); - // csv_options->options = std::move(serialized_data.options.options); - // - // auto bind_data = MultiFileFunction::MultiFileBindInternal( - // context, std::move(multi_file_reader), std::move(file_list), serialized_data.return_types, - // serialized_data.return_names, std::move(serialized_data.options.file_options), std::move(csv_options)); - // return bind_data; + unique_ptr result; + deserializer.ReadProperty(100, "extra_info", function.extra_info); + deserializer.ReadProperty(101, "csv_data", result); + return std::move(result); +} + +void PushdownTypeToCSVScanner(ClientContext &context, optional_ptr bind_data, + const unordered_map &new_column_types) { + auto &csv_bind = bind_data->Cast(); + for (auto &type : new_column_types) { + csv_bind.csv_types[type.first] = type.second; + csv_bind.return_types[type.first] = type.second; + } } TableFunction ReadCSVTableFunction::GetFunction() { - MultiFileFunction read_csv("read_csv"); + TableFunction read_csv("read_csv", {LogicalType::VARCHAR}, ReadCSVFunction, ReadCSVBind, ReadCSVInitGlobal, + ReadCSVInitLocal); + read_csv.table_scan_progress = CSVReaderProgress; + read_csv.pushdown_complex_filter = CSVComplexFilterPushdown; read_csv.serialize = CSVReaderSerialize; read_csv.deserialize = CSVReaderDeserialize; - read_csv.type_pushdown = MultiFileFunction::PushdownType; + read_csv.get_partition_data = CSVReaderGetPartitionData; + read_csv.cardinality = CSVReaderCardinality; + read_csv.projection_pushdown = true; + read_csv.type_pushdown = PushdownTypeToCSVScanner; ReadCSVAddNamedParameters(read_csv); - return static_cast(read_csv); + return read_csv; } TableFunction ReadCSVTableFunction::GetAutoFunction() { auto read_csv_auto = ReadCSVTableFunction::GetFunction(); read_csv_auto.name = "read_csv_auto"; + read_csv_auto.bind = ReadCSVBind; return read_csv_auto; } diff --git a/src/duckdb/src/function/table/read_file.cpp b/src/duckdb/src/function/table/read_file.cpp index 02f48cc1e..158e89fd0 100644 --- a/src/duckdb/src/function/table/read_file.cpp +++ b/src/duckdb/src/function/table/read_file.cpp @@ -1,4 +1,4 @@ -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/function/function_set.hpp" #include "duckdb/main/client_context.hpp" diff --git a/src/duckdb/src/function/table/sniff_csv.cpp b/src/duckdb/src/function/table/sniff_csv.cpp index dd8540189..1e236a5c7 100644 --- a/src/duckdb/src/function/table/sniff_csv.cpp +++ b/src/duckdb/src/function/table/sniff_csv.cpp @@ -60,9 +60,8 @@ static unique_ptr CSVSniffBind(ClientContext &context, TableFuncti result->force_match = it->second.GetValue(); input.named_parameters.erase("force_match"); } - MultiFileOptions file_options; - result->options.FromNamedParameters(input.named_parameters, context, file_options); - result->options.Verify(file_options); + result->options.FromNamedParameters(input.named_parameters, context); + result->options.Verify(); // We want to return the whole CSV Configuration // 1. Delimiter @@ -151,8 +150,7 @@ static void CSVSniffFunction(ClientContext &context, TableFunctionInput &data_p, if (sniffer_options.sql_type_list.empty()) { sniffer_options.sql_type_list = data.return_types_csv; } - MultiFileOptions file_options; - CSVSniffer sniffer(sniffer_options, file_options, buffer_manager, CSVStateMachineCache::Get(context)); + CSVSniffer sniffer(sniffer_options, buffer_manager, CSVStateMachineCache::Get(context)); auto sniffer_result = sniffer.SniffCSV(data.force_match); if (sniffer.EmptyOrOnlyHeader()) { for (auto &type : sniffer_result.return_types) { @@ -167,19 +165,19 @@ static void CSVSniffFunction(ClientContext &context, TableFunctionInput &data_p, output.SetCardinality(1); // 1. Delimiter - str_opt = sniffer_options.dialect_options.state_machine_options.delimiter.FormatValue(); + str_opt = sniffer_options.dialect_options.state_machine_options.delimiter.GetValue(); output.SetValue(0, 0, str_opt); // 2. Quote - str_opt = sniffer_options.dialect_options.state_machine_options.quote.FormatValue(); + str_opt = sniffer_options.dialect_options.state_machine_options.quote.GetValue(); output.SetValue(1, 0, str_opt); // 3. Escape - str_opt = sniffer_options.dialect_options.state_machine_options.escape.FormatValue(); + str_opt = sniffer_options.dialect_options.state_machine_options.escape.GetValue(); output.SetValue(2, 0, str_opt); // 4. NewLine Delimiter auto new_line_identifier = sniffer_options.NewLineIdentifierToString(); output.SetValue(3, 0, new_line_identifier); // 5. Comment - str_opt = sniffer_options.dialect_options.state_machine_options.comment.FormatValue(); + str_opt = sniffer_options.dialect_options.state_machine_options.comment.GetValue(); output.SetValue(4, 0, str_opt); // 6. Skip Rows output.SetValue(5, 0, Value::UINTEGER(NumericCast(sniffer_options.dialect_options.skip_rows.GetValue()))); @@ -231,7 +229,7 @@ static void CSVSniffFunction(ClientContext &context, TableFunctionInput &data_p, if (data.options.user_defined_parameters.empty()) { output.SetValue(10, 0, Value()); } else { - output.SetValue(10, 0, Value(data.options.GetUserDefinedParameters())); + output.SetValue(10, 0, Value(data.options.user_defined_parameters)); } // 12. csv_read string @@ -311,7 +309,7 @@ static void CSVSniffFunction(ClientContext &context, TableFunctionInput &data_p, } // 11.11 User Arguments if (!data.options.user_defined_parameters.empty()) { - csv_read << separator << data.options.GetUserDefinedParameters(); + csv_read << separator << data.options.user_defined_parameters; } csv_read << ");"; output.SetValue(11, 0, csv_read.str()); diff --git a/src/duckdb/src/function/table/system/duckdb_extensions.cpp b/src/duckdb/src/function/table/system/duckdb_extensions.cpp index 8adeb356a..0edc2c2ff 100644 --- a/src/duckdb/src/function/table/system/duckdb_extensions.cpp +++ b/src/duckdb/src/function/table/system/duckdb_extensions.cpp @@ -84,7 +84,7 @@ unique_ptr DuckDBExtensionsInit(ClientContext &context info.loaded = false; info.file_path = extension.statically_loaded ? "(BUILT-IN)" : string(); info.install_mode = - extension.statically_loaded ? ExtensionInstallMode::STATICALLY_LINKED : ExtensionInstallMode::NOT_INSTALLED; + extension.statically_loaded ? ExtensionInstallMode::STATICALLY_LINKED : ExtensionInstallMode::UNKNOWN; info.description = extension.description; for (idx_t k = 0; k < alias_count; k++) { auto alias = ExtensionHelper::GetExtensionAlias(k); @@ -206,7 +206,7 @@ void DuckDBExtensionsFunction(ClientContext &context, TableFunctionInput &data_p // extension version LogicalType::LIST(LogicalType::VARCHAR) output.SetValue(6, count, Value(entry.extension_version)); // installed_mode LogicalType::VARCHAR - output.SetValue(7, count, EnumUtil::ToString(entry.install_mode)); + output.SetValue(7, count, entry.installed ? Value(EnumUtil::ToString(entry.install_mode)) : Value()); // installed_source LogicalType::VARCHAR output.SetValue(8, count, Value(entry.installed_from)); diff --git a/src/duckdb/src/function/table/system/duckdb_functions.cpp b/src/duckdb/src/function/table/system/duckdb_functions.cpp index 272e686e6..4ed87e524 100644 --- a/src/duckdb/src/function/table/system/duckdb_functions.cpp +++ b/src/duckdb/src/function/table/system/duckdb_functions.cpp @@ -41,9 +41,6 @@ static unique_ptr DuckDBFunctionsBind(ClientContext &context, Tabl names.emplace_back("function_name"); return_types.emplace_back(LogicalType::VARCHAR); - names.emplace_back("alias_of"); - return_types.emplace_back(LogicalType::VARCHAR); - names.emplace_back("function_type"); return_types.emplace_back(LogicalType::VARCHAR); @@ -86,9 +83,6 @@ static unique_ptr DuckDBFunctionsBind(ClientContext &context, Tabl names.emplace_back("stability"); return_types.emplace_back(LogicalType::VARCHAR); - names.emplace_back("categories"); - return_types.emplace_back(LogicalType::LIST(LogicalType::VARCHAR)); - return nullptr; } @@ -604,11 +598,6 @@ bool ExtractFunctionData(FunctionEntry &entry, idx_t function_idx, DataChunk &ou // function_name, LogicalType::VARCHAR output.SetValue(col++, output_offset, Value(function.name)); - // alias_of, LogicalType::VARCHAR - output.SetValue(col++, output_offset, - function.alias_of.empty() || function.alias_of == function.name ? Value() - : Value(function.alias_of)); - // function_type, LogicalType::VARCHAR output.SetValue(col++, output_offset, Value(OP::GetFunctionType())); @@ -654,10 +643,6 @@ bool ExtractFunctionData(FunctionEntry &entry, idx_t function_idx, DataChunk &ou // stability, LogicalType::VARCHAR output.SetValue(col++, output_offset, OP::ResultType(function, function_idx)); - // categories, LogicalType::LIST(LogicalType::VARCHAR) - output.SetValue(col++, output_offset, - Value::LIST(LogicalType::VARCHAR, ToValueVector(function_description.categories))); - return function_idx + 1 == OP::FunctionCount(function); } diff --git a/src/duckdb/src/function/table/system/duckdb_log_contexts.cpp b/src/duckdb/src/function/table/system/duckdb_log_contexts.cpp index fa227551f..d0c5c3b35 100644 --- a/src/duckdb/src/function/table/system/duckdb_log_contexts.cpp +++ b/src/duckdb/src/function/table/system/duckdb_log_contexts.cpp @@ -31,16 +31,13 @@ static unique_ptr DuckDBLogContextBind(ClientContext &context, Tab names.emplace_back("scope"); return_types.emplace_back(LogicalType::VARCHAR); - names.emplace_back("connection_id"); + names.emplace_back("client_context"); return_types.emplace_back(LogicalType::UBIGINT); names.emplace_back("transaction_id"); return_types.emplace_back(LogicalType::UBIGINT); - names.emplace_back("query_id"); - return_types.emplace_back(LogicalType::UBIGINT); - - names.emplace_back("thread_id"); + names.emplace_back("thread"); return_types.emplace_back(LogicalType::UBIGINT); return nullptr; diff --git a/src/duckdb/src/function/table/system/duckdb_which_secret.cpp b/src/duckdb/src/function/table/system/duckdb_which_secret.cpp index bab4c0db7..3314fee95 100644 --- a/src/duckdb/src/function/table/system/duckdb_which_secret.cpp +++ b/src/duckdb/src/function/table/system/duckdb_which_secret.cpp @@ -3,7 +3,7 @@ #include "duckdb/common/file_system.hpp" #include "duckdb/common/map.hpp" #include "duckdb/common/string_util.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/function/function_set.hpp" #include "duckdb/main/client_context.hpp" #include "duckdb/main/database.hpp" diff --git a/src/duckdb/src/function/table/system/pragma_table_sample.cpp b/src/duckdb/src/function/table/system/pragma_table_sample.cpp index ce083d92c..7f4122b92 100644 --- a/src/duckdb/src/function/table/system/pragma_table_sample.cpp +++ b/src/duckdb/src/function/table/system/pragma_table_sample.cpp @@ -37,7 +37,7 @@ static unique_ptr DuckDBTableSampleBind(ClientContext &context, Ta auto qname = QualifiedName::Parse(input.inputs[0].GetValue()); Binder::BindSchemaOrCatalog(context, qname.catalog, qname.schema); - auto &entry = Catalog::GetEntry(context, qname.catalog, qname.schema, qname.name); + auto &entry = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, qname.catalog, qname.schema, qname.name); if (entry.type != CatalogType::TABLE_ENTRY) { throw NotImplementedException("Invalid Catalog type passed to table_sample()"); } diff --git a/src/duckdb/src/function/table/system_functions.cpp b/src/duckdb/src/function/table/system_functions.cpp index fe639f1f1..972eb7e54 100644 --- a/src/duckdb/src/function/table/system_functions.cpp +++ b/src/duckdb/src/function/table/system_functions.cpp @@ -23,7 +23,6 @@ void BuiltinFunctions::RegisterSQLiteFunctions() { DuckDBDatabasesFun::RegisterFunction(*this); DuckDBFunctionsFun::RegisterFunction(*this); DuckDBKeywordsFun::RegisterFunction(*this); - DuckDBPreparedStatementsFun::RegisterFunction(*this); DuckDBLogFun::RegisterFunction(*this); DuckDBLogContextFun::RegisterFunction(*this); DuckDBIndexesFun::RegisterFunction(*this); diff --git a/src/duckdb/src/function/table/table_scan.cpp b/src/duckdb/src/function/table/table_scan.cpp index 58cb9274e..3e7224bde 100644 --- a/src/duckdb/src/function/table/table_scan.cpp +++ b/src/duckdb/src/function/table/table_scan.cpp @@ -140,7 +140,7 @@ class DuckIndexScanState : public TableScanGlobalState { for (const auto &col_idx : input.column_indexes) { l_state->column_ids.push_back(GetStorageIndex(bind_data.table, col_idx)); } - l_state->scan_state.Initialize(l_state->column_ids, context.client, input.filters.get()); + l_state->scan_state.Initialize(l_state->column_ids, input.filters.get()); local_storage.InitializeScan(storage, l_state->scan_state.local_state, input.filters); return std::move(l_state); } @@ -232,7 +232,7 @@ class DuckTableScanState : public TableScanGlobalState { storage_ids.push_back(GetStorageIndex(bind_data.table, col)); } - l_state->scan_state.Initialize(std::move(storage_ids), context.client, input.filters, input.sample_options); + l_state->scan_state.Initialize(std::move(storage_ids), input.filters.get(), input.sample_options.get()); auto &duck_table = bind_data.table.Cast(); auto &storage = duck_table.GetStorage(); @@ -712,11 +712,6 @@ static unique_ptr TableScanDeserialize(Deserializer &deserializer, return std::move(result); } -virtual_column_map_t TableScanGetVirtualColumns(ClientContext &context, optional_ptr bind_data_p) { - auto &bind_data = bind_data_p->Cast(); - return bind_data.table.GetVirtualColumns(); -} - TableFunction TableScanFunction::GetFunction() { TableFunction scan_function("seq_scan", {}, TableScanFunc); scan_function.init_local = TableScanInitLocal; @@ -734,10 +729,8 @@ TableFunction TableScanFunction::GetFunction() { scan_function.filter_pushdown = true; scan_function.filter_prune = true; scan_function.sampling_pushdown = true; - scan_function.late_materialization = true; scan_function.serialize = TableScanSerialize; scan_function.deserialize = TableScanDeserialize; - scan_function.get_virtual_columns = TableScanGetVirtualColumns; return scan_function; } diff --git a/src/duckdb/src/function/table/version/pragma_version.cpp b/src/duckdb/src/function/table/version/pragma_version.cpp index debdc5b75..9df101cb3 100644 --- a/src/duckdb/src/function/table/version/pragma_version.cpp +++ b/src/duckdb/src/function/table/version/pragma_version.cpp @@ -1,17 +1,17 @@ #ifndef DUCKDB_PATCH_VERSION -#define DUCKDB_PATCH_VERSION "0-dev2339" +#define DUCKDB_PATCH_VERSION "2" #endif #ifndef DUCKDB_MINOR_VERSION -#define DUCKDB_MINOR_VERSION 3 +#define DUCKDB_MINOR_VERSION 2 #endif #ifndef DUCKDB_MAJOR_VERSION #define DUCKDB_MAJOR_VERSION 1 #endif #ifndef DUCKDB_VERSION -#define DUCKDB_VERSION "v1.3.0-dev2339" +#define DUCKDB_VERSION "v1.2.2" #endif #ifndef DUCKDB_SOURCE_ID -#define DUCKDB_SOURCE_ID "e1dcf13ed5" +#define DUCKDB_SOURCE_ID "7c039464e4" #endif #include "duckdb/function/table/system_functions.hpp" #include "duckdb/main/database.hpp" diff --git a/src/duckdb/src/function/table_function.cpp b/src/duckdb/src/function/table_function.cpp index 1569f5223..6e9df8194 100644 --- a/src/duckdb/src/function/table_function.cpp +++ b/src/duckdb/src/function/table_function.cpp @@ -20,11 +20,10 @@ TableFunction::TableFunction(string name, vector arguments, table_f : SimpleNamedParameterFunction(std::move(name), std::move(arguments)), bind(bind), bind_replace(nullptr), init_global(init_global), init_local(init_local), function(function), in_out_function(nullptr), in_out_function_final(nullptr), statistics(nullptr), dependency(nullptr), cardinality(nullptr), - pushdown_complex_filter(nullptr), to_string(nullptr), dynamic_to_string(nullptr), table_scan_progress(nullptr), - get_partition_data(nullptr), get_bind_info(nullptr), type_pushdown(nullptr), get_multi_file_reader(nullptr), - supports_pushdown_type(nullptr), get_partition_info(nullptr), get_partition_stats(nullptr), - get_virtual_columns(nullptr), serialize(nullptr), deserialize(nullptr), projection_pushdown(false), - filter_pushdown(false), filter_prune(false), sampling_pushdown(false), late_materialization(false) { + pushdown_complex_filter(nullptr), to_string(nullptr), table_scan_progress(nullptr), get_partition_data(nullptr), + get_bind_info(nullptr), type_pushdown(nullptr), get_multi_file_reader(nullptr), supports_pushdown_type(nullptr), + get_partition_info(nullptr), get_partition_stats(nullptr), serialize(nullptr), deserialize(nullptr), + projection_pushdown(false), filter_pushdown(false), filter_prune(false), sampling_pushdown(false) { } TableFunction::TableFunction(const vector &arguments, table_function_t function, @@ -35,12 +34,11 @@ TableFunction::TableFunction(const vector &arguments, table_functio TableFunction::TableFunction() : SimpleNamedParameterFunction("", {}), bind(nullptr), bind_replace(nullptr), init_global(nullptr), init_local(nullptr), function(nullptr), in_out_function(nullptr), statistics(nullptr), dependency(nullptr), - cardinality(nullptr), pushdown_complex_filter(nullptr), to_string(nullptr), dynamic_to_string(nullptr), - table_scan_progress(nullptr), get_partition_data(nullptr), get_bind_info(nullptr), type_pushdown(nullptr), - get_multi_file_reader(nullptr), supports_pushdown_type(nullptr), get_partition_info(nullptr), - get_partition_stats(nullptr), get_virtual_columns(nullptr), serialize(nullptr), deserialize(nullptr), - projection_pushdown(false), filter_pushdown(false), filter_prune(false), sampling_pushdown(false), - late_materialization(false) { + cardinality(nullptr), pushdown_complex_filter(nullptr), to_string(nullptr), table_scan_progress(nullptr), + get_partition_data(nullptr), get_bind_info(nullptr), type_pushdown(nullptr), get_multi_file_reader(nullptr), + supports_pushdown_type(nullptr), get_partition_info(nullptr), get_partition_stats(nullptr), serialize(nullptr), + deserialize(nullptr), projection_pushdown(false), filter_pushdown(false), filter_prune(false), + sampling_pushdown(false) { } bool TableFunction::Equal(const TableFunction &rhs) const { diff --git a/src/duckdb/src/function/window/window_boundaries_state.cpp b/src/duckdb/src/function/window/window_boundaries_state.cpp index 2f5749189..a4b034441 100644 --- a/src/duckdb/src/function/window/window_boundaries_state.cpp +++ b/src/duckdb/src/function/window/window_boundaries_state.cpp @@ -205,10 +205,11 @@ static idx_t FindTypedRangeBound(WindowCursor &range_lo, WindowCursor &range_hi, } // Try to reuse the previous bounds to restrict the search. // This is only valid if the previous bounds were non-empty + // Only inject the comparisons if the previous bounds are a strict subset. WindowColumnIterator begin(range_lo, order_begin); WindowColumnIterator end(range_hi, order_end); if (prev.start < prev.end) { - if (order_begin <= prev.start && prev.start < order_end) { + if (order_begin < prev.start && prev.start < order_end) { const auto first = range_lo.GetCell(0, prev.start); if (FROM && !comp(val, first)) { // If prev.start == val and we are looking for a lower bound, then we are done @@ -506,12 +507,7 @@ void WindowBoundariesState::Bounds(DataChunk &bounds, idx_t row_idx, optional_pt bounds.Reset(); D_ASSERT(bounds.ColumnCount() == 8); - // Have we jumped from the previous position? const auto is_jump = (next_pos != row_idx); - if (is_jump) { - next_pos = row_idx; - } - if (required.count(PARTITION_BEGIN)) { PartitionBegin(bounds, row_idx, count, is_jump, partition_mask); } @@ -652,15 +648,11 @@ void WindowBoundariesState::PeerEnd(DataChunk &bounds, idx_t row_idx, const idx_ auto partition_end_data = FlatVector::GetData(bounds.data[PARTITION_END]); auto peer_begin_data = FlatVector::GetData(bounds.data[PEER_BEGIN]); auto peer_end_data = FlatVector::GetData(bounds.data[PEER_END]); - auto prev_end = peer_begin_data[0]; for (idx_t chunk_idx = 0; chunk_idx < count; ++chunk_idx, ++row_idx) { + idx_t n = 1; const auto peer_start = peer_begin_data[chunk_idx]; - if (peer_start >= prev_end) { - idx_t n = 1; - const auto partition_end = partition_end_data[chunk_idx]; - prev_end = FindNextStart(order_mask, peer_start + 1, partition_end, n); - } - peer_end_data[chunk_idx] = prev_end; + const auto partition_end = partition_end_data[chunk_idx]; + peer_end_data[chunk_idx] = FindNextStart(order_mask, peer_start + 1, partition_end, n); } } diff --git a/src/duckdb/src/function/window/window_distinct_aggregator.cpp b/src/duckdb/src/function/window/window_distinct_aggregator.cpp index 0f98160d4..1c935826f 100644 --- a/src/duckdb/src/function/window/window_distinct_aggregator.cpp +++ b/src/duckdb/src/function/window/window_distinct_aggregator.cpp @@ -142,7 +142,7 @@ WindowDistinctAggregatorGlobalState::WindowDistinctAggregatorGlobalState(ClientC RowLayout payload_layout; payload_layout.Initialize(payload_types); - global_sort = make_uniq(context, orders, payload_layout); + global_sort = make_uniq(BufferManager::GetBufferManager(context), orders, payload_layout); memory_per_thread = PhysicalOperator::GetMaxThreadMemory(context); diff --git a/src/duckdb/src/function/window/window_merge_sort_tree.cpp b/src/duckdb/src/function/window/window_merge_sort_tree.cpp index 812c945fc..ef22694c4 100644 --- a/src/duckdb/src/function/window/window_merge_sort_tree.cpp +++ b/src/duckdb/src/function/window/window_merge_sort_tree.cpp @@ -27,6 +27,7 @@ WindowMergeSortTree::WindowMergeSortTree(ClientContext &context, const vector unique_orders; for (const auto &order : orders) { @@ -36,9 +37,9 @@ WindowMergeSortTree::WindowMergeSortTree(ClientContext &context, const vector(context, unique_orders, payload_layout); + global_sort = make_uniq(buffer_manager, unique_orders, payload_layout); } else { - global_sort = make_uniq(context, orders, payload_layout); + global_sort = make_uniq(buffer_manager, orders, payload_layout); } global_sort->external = force_external; } diff --git a/src/duckdb/src/function/window/window_naive_aggregator.cpp b/src/duckdb/src/function/window/window_naive_aggregator.cpp index 5d7c74971..448639e77 100644 --- a/src/duckdb/src/function/window/window_naive_aggregator.cpp +++ b/src/duckdb/src/function/window/window_naive_aggregator.cpp @@ -230,7 +230,8 @@ void WindowNaiveState::Evaluate(const WindowAggregatorGlobalState &gsink, const if (arg_orderer) { auto &context = aggregator.executor.context; auto &orders = aggregator.wexpr.arg_orders; - GlobalSortState global_sort(context, orders, payload_layout); + auto &buffer_manager = BufferManager::GetBufferManager(context); + GlobalSortState global_sort(buffer_manager, orders, payload_layout); LocalSortState local_sort; local_sort.Initialize(global_sort, global_sort.buffer_manager); diff --git a/src/duckdb/src/include/duckdb.h b/src/duckdb/src/include/duckdb.h index d2b14d54f..3537ac5d6 100644 --- a/src/duckdb/src/include/duckdb.h +++ b/src/duckdb/src/include/duckdb.h @@ -186,7 +186,7 @@ typedef enum duckdb_statement_type { DUCKDB_STATEMENT_TYPE_DETACH = 26, DUCKDB_STATEMENT_TYPE_MULTI = 27, } duckdb_statement_type; -//! An enum over DuckDB's different error types. +//! An enum over DuckDB's different result types. typedef enum duckdb_error_type { DUCKDB_ERROR_INVALID = 0, DUCKDB_ERROR_OUT_OF_RANGE = 1, @@ -242,14 +242,11 @@ typedef enum duckdb_cast_mode { DUCKDB_CAST_NORMAL = 0, DUCKDB_CAST_TRY = 1 } du //! DuckDB's index type. typedef uint64_t idx_t; -//! Type used for the selection vector -typedef uint32_t sel_t; - //! The callback that will be called to destroy data, e.g., //! bind data (if any), init data (if any), extra data for replacement scans (if any) typedef void (*duckdb_delete_callback_t)(void *data); -//! Used for threading, contains a task state. Must be destroyed with `duckdb_destroy_task_state`. +//! Used for threading, contains a task state. Must be destroyed with `duckdb_destroy_state`. typedef void *duckdb_task_state; //===--------------------------------------------------------------------===// @@ -394,12 +391,6 @@ typedef struct _duckdb_vector { void *internal_ptr; } * duckdb_vector; -//! A selection vector is a possibly duplicative vector of indices, which refer to values in a vector. -//! The resulting vector is make up of the values at each index in the selection vector. -typedef struct _duckdb_selection_vector { - void *internal_ptr; -} * duckdb_selection_vector; - //===--------------------------------------------------------------------===// // Types (explicit freeing/destroying) //===--------------------------------------------------------------------===// @@ -887,7 +878,7 @@ query fails, otherwise the error stored within the result will not be freed corr DUCKDB_C_API duckdb_state duckdb_query(duckdb_connection connection, const char *query, duckdb_result *out_result); /*! -Closes the result and de-allocates all memory allocated for that result. +Closes the result and de-allocates all memory allocated for that connection. * @param result The result to destroy. */ @@ -1657,7 +1648,7 @@ DUCKDB_C_API duckdb_state duckdb_bind_hugeint(duckdb_prepared_statement prepared duckdb_hugeint val); /*! -Binds a duckdb_uhugeint value to the prepared statement at the specified index. +Binds an duckdb_uhugeint value to the prepared statement at the specified index. */ DUCKDB_C_API duckdb_state duckdb_bind_uhugeint(duckdb_prepared_statement prepared_statement, idx_t param_idx, duckdb_uhugeint val); @@ -1669,24 +1660,24 @@ DUCKDB_C_API duckdb_state duckdb_bind_decimal(duckdb_prepared_statement prepared duckdb_decimal val); /*! -Binds a uint8_t value to the prepared statement at the specified index. +Binds an uint8_t value to the prepared statement at the specified index. */ DUCKDB_C_API duckdb_state duckdb_bind_uint8(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint8_t val); /*! -Binds a uint16_t value to the prepared statement at the specified index. +Binds an uint16_t value to the prepared statement at the specified index. */ DUCKDB_C_API duckdb_state duckdb_bind_uint16(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint16_t val); /*! -Binds a uint32_t value to the prepared statement at the specified index. +Binds an uint32_t value to the prepared statement at the specified index. */ DUCKDB_C_API duckdb_state duckdb_bind_uint32(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint32_t val); /*! -Binds a uint64_t value to the prepared statement at the specified index. +Binds an uint64_t value to the prepared statement at the specified index. */ DUCKDB_C_API duckdb_state duckdb_bind_uint64(duckdb_prepared_statement prepared_statement, idx_t param_idx, uint64_t val); @@ -1987,7 +1978,7 @@ Creates a value from a boolean DUCKDB_C_API duckdb_value duckdb_create_bool(bool input); /*! -Creates a value from an int8_t (a tinyint) +Creates a value from a int8_t (a tinyint) * @param input The tinyint value * @return The value. This must be destroyed with `duckdb_destroy_value`. @@ -2003,7 +1994,7 @@ Creates a value from a uint8_t (a utinyint) DUCKDB_C_API duckdb_value duckdb_create_uint8(uint8_t input); /*! -Creates a value from an int16_t (a smallint) +Creates a value from a int16_t (a smallint) * @param input The smallint value * @return The value. This must be destroyed with `duckdb_destroy_value`. @@ -2019,7 +2010,7 @@ Creates a value from a uint16_t (a usmallint) DUCKDB_C_API duckdb_value duckdb_create_uint16(uint16_t input); /*! -Creates a value from an int32_t (an integer) +Creates a value from a int32_t (an integer) * @param input The integer value * @return The value. This must be destroyed with `duckdb_destroy_value`. @@ -2238,7 +2229,7 @@ DUCKDB_C_API uint16_t duckdb_get_uint16(duckdb_value val); /*! Returns the int32_t value of the given value. -* @param val A duckdb_value containing an integer +* @param val A duckdb_value containing a integer * @return A int32_t, or MinValue if the value cannot be converted */ DUCKDB_C_API int32_t duckdb_get_int32(duckdb_value val); @@ -2546,14 +2537,6 @@ Returns the STRUCT child at index as a duckdb_value. */ DUCKDB_C_API duckdb_value duckdb_get_struct_child(duckdb_value value, idx_t index); -/*! -Returns the SQL string representation of the given value. - -* @param value A duckdb_value. -* @return The SQL string representation as a null-terminated string. The result must be freed with `duckdb_free`. -*/ -DUCKDB_C_API char *duckdb_value_to_string(duckdb_value value); - //===--------------------------------------------------------------------===// // Logical Type Interface //===--------------------------------------------------------------------===// @@ -3037,7 +3020,7 @@ The resulting vector is valid as long as the parent vector is valid. DUCKDB_C_API duckdb_vector duckdb_struct_vector_get_child(duckdb_vector vector, idx_t index); /*! -Retrieves the child vector of an array vector. +Retrieves the child vector of a array vector. The resulting vector is valid as long as the parent vector is valid. The resulting vector has the size of the parent vector multiplied by the array size. @@ -3047,19 +3030,6 @@ The resulting vector has the size of the parent vector multiplied by the array s */ DUCKDB_C_API duckdb_vector duckdb_array_vector_get_child(duckdb_vector vector); -/*! -Slice a vector with a selection vector. - -The max value in the selection vector must be less than the length of the vector - -The resulting vector happens to be a dictionary vector. - -* @param vector The vector which is to become a dictionary -* @param selection The selection vector -* @param len The length of the selection vector -*/ -DUCKDB_C_API void duckdb_slice_vector(duckdb_vector vector, duckdb_selection_vector selection, idx_t len); - //===--------------------------------------------------------------------===// // Validity Mask Functions //===--------------------------------------------------------------------===// @@ -3144,7 +3114,8 @@ duckdb_scalar_function_add_parameter. DUCKDB_C_API void duckdb_scalar_function_set_varargs(duckdb_scalar_function scalar_function, duckdb_logical_type type); /*! -Sets the scalar function's null-handling behavior to special. +Sets the parameters of the given scalar function to varargs. Does not require adding parameters with +duckdb_scalar_function_add_parameter. * @param scalar_function The scalar function. */ @@ -3181,7 +3152,7 @@ Assigns extra information to the scalar function that can be fetched during bind * @param scalar_function The scalar function * @param extra_info The extra information -* @param destroy The callback that will be called to destroy the extra information (if any) +* @param destroy The callback that will be called to destroy the bind data (if any) */ DUCKDB_C_API void duckdb_scalar_function_set_extra_info(duckdb_scalar_function scalar_function, void *extra_info, duckdb_delete_callback_t destroy); @@ -3264,25 +3235,6 @@ If the set is incomplete or a function with this name already exists DuckDBError */ DUCKDB_C_API duckdb_state duckdb_register_scalar_function_set(duckdb_connection con, duckdb_scalar_function_set set); -//===--------------------------------------------------------------------===// -// Selection Vector Interface -//===--------------------------------------------------------------------===// - -/*! -Creates a new selection vector of size `size`. -*/ -DUCKDB_C_API duckdb_selection_vector duckdb_create_selection_vector(idx_t size); - -/*! -Destroys a selection vector. -*/ -DUCKDB_C_API void duckdb_destroy_selection_vector(duckdb_selection_vector vector); - -/*! -Access the data pointer of a selection vector. -*/ -DUCKDB_C_API sel_t *duckdb_selection_vector_get_data_ptr(duckdb_selection_vector vector); - //===--------------------------------------------------------------------===// // Aggregate Functions //===--------------------------------------------------------------------===// @@ -3379,7 +3331,7 @@ Assigns extra information to the scalar function that can be fetched during bind * @param aggregate_function The aggregate function * @param extra_info The extra information -* @param destroy The callback that will be called to destroy the extra information (if any) +* @param destroy The callback that will be called to destroy the bind data (if any) */ DUCKDB_C_API void duckdb_aggregate_function_set_extra_info(duckdb_aggregate_function aggregate_function, void *extra_info, duckdb_delete_callback_t destroy); @@ -3491,7 +3443,7 @@ Assigns extra information to the table function that can be fetched during bindi * @param table_function The table function * @param extra_info The extra information -* @param destroy The callback that will be called to destroy the extra information (if any) +* @param destroy The callback that will be called to destroy the bind data (if any) */ DUCKDB_C_API void duckdb_table_function_set_extra_info(duckdb_table_function table_function, void *extra_info, duckdb_delete_callback_t destroy); diff --git a/src/duckdb/src/include/duckdb/catalog/catalog.hpp b/src/duckdb/src/include/duckdb/catalog/catalog.hpp index c200512f1..96679f2a9 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog.hpp @@ -20,7 +20,6 @@ #include "duckdb/common/optional_ptr.hpp" #include "duckdb/common/reference_map.hpp" #include "duckdb/parser/query_error_context.hpp" -#include "duckdb/catalog/entry_lookup_info.hpp" #include @@ -66,7 +65,6 @@ struct SimilarCatalogEntry; class Binder; class LogicalOperator; class PhysicalOperator; -class PhysicalPlanGenerator; class LogicalCreateIndex; class LogicalCreateTable; class LogicalInsert; @@ -75,6 +73,17 @@ class LogicalUpdate; class CreateStatement; class CatalogEntryRetriever; +//! Return value of Catalog::LookupEntry +struct CatalogEntryLookup { + optional_ptr schema; + optional_ptr entry; + ErrorData error; + + DUCKDB_API bool Found() const { + return entry; + } +}; + //! The Catalog object represents the catalog of the database. class Catalog { public: @@ -108,7 +117,6 @@ class Catalog { return false; } virtual void Initialize(bool load_builtin) = 0; - virtual void Initialize(optional_ptr context, bool load_builtin); bool IsSystemCatalog() const; bool IsTemporaryCatalog() const; @@ -202,65 +210,63 @@ class Catalog { //! Drops an entry from the catalog DUCKDB_API void DropEntry(ClientContext &context, DropInfo &info); - DUCKDB_API virtual optional_ptr LookupSchema(CatalogTransaction transaction, - const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found) = 0; - //! Returns the schema object with the specified name, or throws an exception if it does not exist - DUCKDB_API SchemaCatalogEntry &GetSchema(ClientContext &context, const EntryLookupInfo &schema_lookup); - DUCKDB_API optional_ptr GetSchema(ClientContext &context, const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found); + DUCKDB_API SchemaCatalogEntry &GetSchema(ClientContext &context, const string &name, + QueryErrorContext error_context = QueryErrorContext()); + DUCKDB_API optional_ptr GetSchema(ClientContext &context, const string &name, + OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); //! Overloadable method for giving warnings on ambiguous naming id.tab due to a database and schema with name id - DUCKDB_API virtual bool CheckAmbiguousCatalogOrSchema(ClientContext &context, const string &schema); - - DUCKDB_API SchemaCatalogEntry &GetSchema(ClientContext &context, const string &schema); - DUCKDB_API SchemaCatalogEntry &GetSchema(CatalogTransaction transaction, const string &schema); - DUCKDB_API SchemaCatalogEntry &GetSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup); - DUCKDB_API static SchemaCatalogEntry &GetSchema(ClientContext &context, const string &catalog_name, - const EntryLookupInfo &schema_lookup); - DUCKDB_API optional_ptr GetSchema(ClientContext &context, const string &schema, - OnEntryNotFound if_not_found); - DUCKDB_API optional_ptr GetSchema(CatalogTransaction transaction, const string &schema, - OnEntryNotFound if_not_found); - DUCKDB_API static optional_ptr GetSchema(ClientContext &context, const string &catalog_name, - const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found); + DUCKDB_API virtual bool CheckAmbiguousCatalogOrSchema(ClientContext &context, const string &name) { + return !!GetSchema(context, name, OnEntryNotFound::RETURN_NULL); + } + DUCKDB_API SchemaCatalogEntry &GetSchema(CatalogTransaction transaction, const string &name, + QueryErrorContext error_context = QueryErrorContext()); + DUCKDB_API virtual optional_ptr + GetSchema(CatalogTransaction transaction, const string &schema_name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()) = 0; DUCKDB_API static SchemaCatalogEntry &GetSchema(ClientContext &context, const string &catalog_name, - const string &schema); + const string &schema_name, + QueryErrorContext error_context = QueryErrorContext()); DUCKDB_API static optional_ptr GetSchema(ClientContext &context, const string &catalog_name, - const string &schema, OnEntryNotFound if_not_found); + const string &schema_name, + OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); DUCKDB_API static optional_ptr GetSchema(CatalogEntryRetriever &retriever, - const string &catalog_name, - const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found); + const string &catalog_name, const string &schema_name, + OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); //! Scans all the schemas in the system one-by-one, invoking the callback for each entry DUCKDB_API virtual void ScanSchemas(ClientContext &context, std::function callback) = 0; //! Gets the "schema.name" entry of the specified type, if entry does not exist behavior depends on OnEntryNotFound - DUCKDB_API optional_ptr GetEntry(ClientContext &context, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found); - DUCKDB_API optional_ptr GetEntry(ClientContext &context, CatalogType catalog_type, + DUCKDB_API optional_ptr GetEntry(ClientContext &context, CatalogType type, const string &schema, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); + DUCKDB_API optional_ptr GetEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &schema, const string &name, - OnEntryNotFound if_not_found); - DUCKDB_API optional_ptr GetEntry(CatalogEntryRetriever &retriever, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found); - DUCKDB_API CatalogEntry &GetEntry(ClientContext &context, const string &schema, const EntryLookupInfo &lookup_info); + OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); + DUCKDB_API CatalogEntry &GetEntry(ClientContext &context, CatalogType type, const string &schema, + const string &name, QueryErrorContext error_context = QueryErrorContext()); //! Gets the "catalog.schema.name" entry of the specified type, if entry does not exist behavior depends on //! OnEntryNotFound - DUCKDB_API static optional_ptr GetEntry(ClientContext &context, const string &catalog, - const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound if_not_found); - DUCKDB_API static optional_ptr GetEntry(CatalogEntryRetriever &retriever, const string &catalog, - const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound if_not_found); - DUCKDB_API static CatalogEntry &GetEntry(ClientContext &context, const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info); + DUCKDB_API static optional_ptr GetEntry(ClientContext &context, CatalogType type, + const string &catalog, const string &schema, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); + DUCKDB_API static optional_ptr GetEntry(CatalogEntryRetriever &retriever, CatalogType type, + const string &catalog, const string &schema, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); + DUCKDB_API static CatalogEntry &GetEntry(ClientContext &context, CatalogType type, const string &catalog, + const string &schema, const string &name, + QueryErrorContext error_context = QueryErrorContext()); template optional_ptr GetEntry(ClientContext &context, const string &schema_name, const string &name, OnEntryNotFound if_not_found, QueryErrorContext error_context = QueryErrorContext()) { - EntryLookupInfo lookup_info(T::Type, name, error_context); - auto entry = GetEntry(context, schema_name, lookup_info, if_not_found); + auto entry = GetEntry(context, T::Type, schema_name, name, if_not_found, error_context); if (!entry) { return nullptr; } @@ -269,7 +275,6 @@ class Catalog { } return &entry->template Cast(); } - template T &GetEntry(ClientContext &context, const string &schema_name, const string &name, QueryErrorContext error_context = QueryErrorContext()) { @@ -277,11 +282,6 @@ class Catalog { return *entry; } - static CatalogEntry &GetEntry(ClientContext &context, CatalogType catalog_type, const string &catalog_name, - const string &schema_name, const string &name); - CatalogEntry &GetEntry(ClientContext &context, CatalogType catalog_type, const string &schema_name, - const string &name); - //! Append a scalar or aggregate function to the catalog DUCKDB_API optional_ptr AddFunction(ClientContext &context, CreateFunctionInfo &info); @@ -289,16 +289,14 @@ class Catalog { DUCKDB_API void Alter(CatalogTransaction transaction, AlterInfo &info); DUCKDB_API void Alter(ClientContext &context, AlterInfo &info); - virtual PhysicalOperator &PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, - LogicalCreateTable &op, PhysicalOperator &plan) = 0; - virtual PhysicalOperator &PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op, - optional_ptr plan) = 0; - virtual PhysicalOperator &PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op, - PhysicalOperator &plan) = 0; - virtual PhysicalOperator &PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op); - virtual PhysicalOperator &PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op, - PhysicalOperator &plan) = 0; - virtual PhysicalOperator &PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op); + virtual unique_ptr PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op, + unique_ptr plan) = 0; + virtual unique_ptr PlanInsert(ClientContext &context, LogicalInsert &op, + unique_ptr plan) = 0; + virtual unique_ptr PlanDelete(ClientContext &context, LogicalDelete &op, + unique_ptr plan) = 0; + virtual unique_ptr PlanUpdate(ClientContext &context, LogicalUpdate &op, + unique_ptr plan) = 0; virtual unique_ptr BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table, unique_ptr plan); virtual unique_ptr BindAlterAddIndex(Binder &binder, TableCatalogEntry &table_entry, @@ -311,9 +309,6 @@ class Catalog { virtual bool InMemory() = 0; virtual string GetDBPath() = 0; - virtual bool SupportsTimeTravel() const { - return false; - } //! Whether or not this catalog should search a specific type with the standard priority DUCKDB_API virtual CatalogLookupBehavior CatalogTypeLookupRule(CatalogType type) const { @@ -338,8 +333,7 @@ class Catalog { static optional_ptr GetEntry(ClientContext &context, const string &catalog_name, const string &schema_name, const string &name, OnEntryNotFound if_not_found, QueryErrorContext error_context = QueryErrorContext()) { - EntryLookupInfo lookup_info(T::Type, name, error_context); - auto entry = GetEntry(context, catalog_name, schema_name, lookup_info, if_not_found); + auto entry = GetEntry(context, T::Type, catalog_name, schema_name, name, if_not_found, error_context); if (!entry) { return nullptr; } @@ -383,36 +377,40 @@ class Catalog { public: //! Lookup an entry using TryLookupEntry, throws if entry not found and if_not_found == THROW_EXCEPTION - CatalogEntryLookup LookupEntry(CatalogEntryRetriever &retriever, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found); + CatalogEntryLookup LookupEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &schema, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); private: //! Lookup an entry in the schema, returning a lookup with the entry and schema if they exist - CatalogEntryLookup TryLookupEntryInternal(CatalogTransaction transaction, const string &schema, - const EntryLookupInfo &lookup_info); + CatalogEntryLookup TryLookupEntryInternal(CatalogTransaction transaction, CatalogType type, const string &schema, + const string &name); //! Calls LookupEntryInternal on the schema, trying other schemas if the schema is invalid. Sets //! CatalogEntryLookup->error depending on if_not_found when no entry is found - CatalogEntryLookup TryLookupEntry(CatalogEntryRetriever &retriever, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found); - static CatalogEntryLookup TryLookupEntry(CatalogEntryRetriever &retriever, const vector &lookups, - const EntryLookupInfo &lookup_info, OnEntryNotFound if_not_found); - static CatalogEntryLookup TryLookupEntry(CatalogEntryRetriever &retriever, const string &catalog, - const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound if_not_found); + CatalogEntryLookup TryLookupEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &schema, + const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); + static CatalogEntryLookup TryLookupEntry(CatalogEntryRetriever &retriever, vector &lookups, + CatalogType type, const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()); + static CatalogEntryLookup TryLookupEntry(CatalogEntryRetriever &retriever, CatalogType type, const string &catalog, + const string &schema, const string &name, OnEntryNotFound if_not_found, + QueryErrorContext error_context); //! Looks for a Catalog with a DefaultTable that matches the lookup - static CatalogEntryLookup TryLookupDefaultTable(CatalogEntryRetriever &retriever, const string &catalog, - const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound if_not_found); + static CatalogEntryLookup TryLookupDefaultTable(CatalogEntryRetriever &retriever, CatalogType type, + const string &catalog, const string &schema, const string &name, + OnEntryNotFound if_not_found, QueryErrorContext error_context); //! Return an exception with did-you-mean suggestion. - static CatalogException CreateMissingEntryException(CatalogEntryRetriever &retriever, - const EntryLookupInfo &lookup_info, - const reference_set_t &schemas); + static CatalogException CreateMissingEntryException(CatalogEntryRetriever &retriever, const string &entry_name, + CatalogType type, + const reference_set_t &schemas, + QueryErrorContext error_context); //! Return the close entry name, the distance and the belonging schema. - static vector SimilarEntriesInSchemas(ClientContext &context, - const EntryLookupInfo &lookup_info, + static vector SimilarEntriesInSchemas(ClientContext &context, const string &entry_name, + CatalogType type, const reference_set_t &schemas); virtual void DropSchema(ClientContext &context, DropInfo &info) = 0; diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp index 67837c8db..88c9706a1 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp @@ -70,7 +70,6 @@ class CatalogEntry { virtual unique_ptr AlterEntry(CatalogTransaction transaction, AlterInfo &info); virtual void UndoAlter(ClientContext &context, AlterInfo &info); virtual void Rollback(CatalogEntry &prev_entry); - virtual void OnDrop(); virtual unique_ptr Copy(ClientContext &context) const; diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp index 7936ad44f..188424015 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp @@ -61,10 +61,10 @@ class DuckSchemaEntry : public SchemaCatalogEntry { void Scan(ClientContext &context, CatalogType type, const std::function &callback) override; void Scan(CatalogType type, const std::function &callback) override; void DropEntry(ClientContext &context, DropInfo &info) override; - optional_ptr LookupEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) override; - CatalogSet::EntryLookup LookupEntryDetailed(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info) override; - SimilarCatalogEntry GetSimilarEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) override; + optional_ptr GetEntry(CatalogTransaction transaction, CatalogType type, const string &name) override; + CatalogSet::EntryLookup GetEntryDetailed(CatalogTransaction transaction, CatalogType type, + const string &name) override; + SimilarCatalogEntry GetSimilarEntry(CatalogTransaction transaction, CatalogType type, const string &name) override; unique_ptr Copy(ClientContext &context) const override; diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp index 14033cecd..fb9d5ae67 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp @@ -28,7 +28,6 @@ class DuckTableEntry : public TableCatalogEntry { unique_ptr AlterEntry(CatalogTransaction, AlterInfo &info) override; void UndoAlter(ClientContext &context, AlterInfo &info) override; void Rollback(CatalogEntry &prev_entry) override; - void OnDrop() override; //! Returns the underlying storage of the table DataTable &GetStorage() override; @@ -57,11 +56,8 @@ class DuckTableEntry : public TableCatalogEntry { private: unique_ptr RenameColumn(ClientContext &context, RenameColumnInfo &info); - unique_ptr RenameField(ClientContext &context, RenameFieldInfo &info); unique_ptr AddColumn(ClientContext &context, AddColumnInfo &info); - unique_ptr AddField(ClientContext &context, AddFieldInfo &info); unique_ptr RemoveColumn(ClientContext &context, RemoveColumnInfo &info); - unique_ptr RemoveField(ClientContext &context, RemoveFieldInfo &info); unique_ptr SetDefault(ClientContext &context, SetDefaultInfo &info); unique_ptr ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info); unique_ptr SetNotNull(ClientContext &context, SetNotNullInfo &info); diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry/function_entry.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry/function_entry.hpp index 590583f63..955e5cd87 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry/function_entry.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry/function_entry.hpp @@ -19,12 +19,10 @@ class FunctionEntry : public StandardEntry { FunctionEntry(CatalogType type, Catalog &catalog, SchemaCatalogEntry &schema, CreateFunctionInfo &info) : StandardEntry(type, schema, catalog, info.name) { descriptions = std::move(info.descriptions); - alias_of = std::move(info.alias_of); this->dependencies = info.dependencies; this->internal = info.internal; } - string alias_of; vector descriptions; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp index 12a4ee330..a82ea56cd 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp @@ -10,7 +10,7 @@ #include "duckdb/catalog/catalog_entry.hpp" #include "duckdb/catalog/catalog_set.hpp" -#include "duckdb/catalog/entry_lookup_info.hpp" +#include "duckdb/parser/query_error_context.hpp" namespace duckdb { class ClientContext; @@ -83,16 +83,12 @@ class SchemaCatalogEntry : public InCatalogEntry { //! Create a enum within the given schema virtual optional_ptr CreateType(CatalogTransaction transaction, CreateTypeInfo &info) = 0; - //! Lookup an entry in the schema - DUCKDB_API virtual optional_ptr LookupEntry(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info) = 0; - DUCKDB_API virtual CatalogSet::EntryLookup LookupEntryDetailed(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info); - DUCKDB_API virtual SimilarCatalogEntry GetSimilarEntry(CatalogTransaction transaction, - const EntryLookupInfo &lookup_info); - - DUCKDB_API optional_ptr GetEntry(CatalogTransaction transaction, CatalogType type, - const string &name); + DUCKDB_API virtual optional_ptr GetEntry(CatalogTransaction transaction, CatalogType type, + const string &name) = 0; + DUCKDB_API virtual CatalogSet::EntryLookup GetEntryDetailed(CatalogTransaction transaction, CatalogType type, + const string &name); + DUCKDB_API virtual SimilarCatalogEntry GetSimilarEntry(CatalogTransaction transaction, CatalogType type, + const string &name); //! Drops an entry from the schema virtual void DropEntry(ClientContext &context, DropInfo &info) = 0; diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp index 5cab72c59..398e49974 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp @@ -18,18 +18,14 @@ #include "duckdb/common/case_insensitive_map.hpp" #include "duckdb/catalog/catalog_entry/table_column_type.hpp" #include "duckdb/catalog/catalog_entry/column_dependency_manager.hpp" -#include "duckdb/common/table_column.hpp" namespace duckdb { class DataTable; struct RenameColumnInfo; -struct RenameFieldInfo; struct AddColumnInfo; -struct AddFieldInfo; struct RemoveColumnInfo; -struct RemoveFieldInfo; struct SetDefaultInfo; struct ChangeColumnTypeInfo; struct AlterForeignKeyInfo; @@ -41,7 +37,6 @@ struct BoundCreateTableInfo; class TableFunction; struct FunctionData; -struct EntryLookupInfo; class Binder; struct ColumnSegmentInfo; @@ -98,8 +93,6 @@ class TableCatalogEntry : public StandardEntry { //! Returns the scan function that can be used to scan the given table virtual TableFunction GetScanFunction(ClientContext &context, unique_ptr &bind_data) = 0; - virtual TableFunction GetScanFunction(ClientContext &context, unique_ptr &bind_data, - const EntryLookupInfo &lookup_info); virtual bool IsDuckTable() const { return false; @@ -124,10 +117,10 @@ class TableCatalogEntry : public StandardEntry { //! Returns true, if the table has a primary key, else false. bool HasPrimaryKey() const; - //! Returns the virtual columns for this table - virtual virtual_column_map_t GetVirtualColumns() const; - - virtual vector GetRowIdColumns() const; + //! Returns the rowid type of this table + virtual LogicalType GetRowIdType() const { + return LogicalType::ROW_TYPE; + } protected: //! A list of columns that are part of this table diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp index c64ffbf9e..d435fcec2 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp @@ -48,13 +48,6 @@ class ViewCatalogEntry : public StandardEntry { unique_ptr Copy(ClientContext &context) const override; - virtual const SelectStatement &GetQuery(); - - virtual bool HasTypes() const { - // Whether or not the view has types/names defined - return true; - } - string ToSQL() const override; private: diff --git a/src/duckdb/src/include/duckdb/catalog/catalog_entry_retriever.hpp b/src/duckdb/src/include/duckdb/catalog/catalog_entry_retriever.hpp index 6dda5cb6b..08425f00a 100644 --- a/src/duckdb/src/include/duckdb/catalog/catalog_entry_retriever.hpp +++ b/src/duckdb/src/include/duckdb/catalog/catalog_entry_retriever.hpp @@ -15,7 +15,6 @@ #include "duckdb/parser/query_error_context.hpp" #include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp" #include "duckdb/catalog/catalog_search_path.hpp" -#include "duckdb/catalog/entry_lookup_info.hpp" namespace duckdb { @@ -39,19 +38,23 @@ class CatalogEntryRetriever { return context; } - optional_ptr GetEntry(const string &catalog, const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound on_entry_not_found = OnEntryNotFound::THROW_EXCEPTION); + optional_ptr GetEntry(CatalogType type, const string &catalog, const string &schema, + const string &name, + OnEntryNotFound on_entry_not_found = OnEntryNotFound::THROW_EXCEPTION, + QueryErrorContext error_context = QueryErrorContext()); - optional_ptr GetEntry(Catalog &catalog, const string &schema, const EntryLookupInfo &lookup_info, - OnEntryNotFound on_entry_not_found = OnEntryNotFound::THROW_EXCEPTION); + optional_ptr GetEntry(CatalogType type, Catalog &catalog, const string &schema, const string &name, + OnEntryNotFound on_entry_not_found = OnEntryNotFound::THROW_EXCEPTION, + QueryErrorContext error_context = QueryErrorContext()); LogicalType GetType(const string &catalog, const string &schema, const string &name, OnEntryNotFound on_entry_not_found = OnEntryNotFound::RETURN_NULL); LogicalType GetType(Catalog &catalog, const string &schema, const string &name, OnEntryNotFound on_entry_not_found = OnEntryNotFound::RETURN_NULL); - optional_ptr GetSchema(const string &catalog, const EntryLookupInfo &schema_lookup, - OnEntryNotFound on_entry_not_found = OnEntryNotFound::THROW_EXCEPTION); + optional_ptr GetSchema(const string &catalog, const string &name, + OnEntryNotFound on_entry_not_found = OnEntryNotFound::THROW_EXCEPTION, + QueryErrorContext error_context = QueryErrorContext()); const CatalogSearchPath &GetSearchPath() const; void SetSearchPath(vector entries); @@ -59,9 +62,6 @@ class CatalogEntryRetriever { void SetCallback(catalog_entry_callback_t callback); catalog_entry_callback_t GetCallback(); - optional_ptr GetAtClause() const; - void SetAtClause(optional_ptr at_clause); - private: optional_ptr ReturnAndCallback(optional_ptr result); @@ -70,7 +70,6 @@ class CatalogEntryRetriever { catalog_entry_callback_t callback = nullptr; ClientContext &context; shared_ptr search_path; - optional_ptr at_clause; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp b/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp index 87b7747fa..54bcb40d6 100644 --- a/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +++ b/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp @@ -34,18 +34,18 @@ class DuckCatalog : public Catalog { DUCKDB_API void ScanSchemas(ClientContext &context, std::function callback) override; DUCKDB_API void ScanSchemas(std::function callback); - DUCKDB_API optional_ptr LookupSchema(CatalogTransaction transaction, - const EntryLookupInfo &schema_lookup, - OnEntryNotFound if_not_found) override; - - DUCKDB_API PhysicalOperator &PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, - LogicalCreateTable &op, PhysicalOperator &plan) override; - DUCKDB_API PhysicalOperator &PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op, - optional_ptr plan) override; - DUCKDB_API PhysicalOperator &PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op, - PhysicalOperator &plan) override; - DUCKDB_API PhysicalOperator &PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op, - PhysicalOperator &plan) override; + DUCKDB_API optional_ptr + GetSchema(CatalogTransaction transaction, const string &schema_name, OnEntryNotFound if_not_found, + QueryErrorContext error_context = QueryErrorContext()) override; + + DUCKDB_API unique_ptr PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op, + unique_ptr plan) override; + DUCKDB_API unique_ptr PlanInsert(ClientContext &context, LogicalInsert &op, + unique_ptr plan) override; + DUCKDB_API unique_ptr PlanDelete(ClientContext &context, LogicalDelete &op, + unique_ptr plan) override; + DUCKDB_API unique_ptr PlanUpdate(ClientContext &context, LogicalUpdate &op, + unique_ptr plan) override; DUCKDB_API unique_ptr BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table, unique_ptr plan) override; diff --git a/src/duckdb/src/include/duckdb/common/arrow/schema_metadata.hpp b/src/duckdb/src/include/duckdb/common/arrow/schema_metadata.hpp index 4b23fd385..1aff53718 100644 --- a/src/duckdb/src/include/duckdb/common/arrow/schema_metadata.hpp +++ b/src/duckdb/src/include/duckdb/common/arrow/schema_metadata.hpp @@ -12,7 +12,6 @@ #include "duckdb/common/arrow/arrow_wrapper.hpp" #include "duckdb/main/chunk_scan_state.hpp" #include "duckdb/common/arrow/arrow_type_extension.hpp" -#include "duckdb/common/complex_json.hpp" namespace duckdb { class ArrowSchemaMetadata { @@ -20,7 +19,7 @@ class ArrowSchemaMetadata { //! Constructor used to read a metadata schema, used when importing an arrow object explicit ArrowSchemaMetadata(const char *metadata); //! Constructor used to create a metadata schema, used when exporting an arrow object - ArrowSchemaMetadata(); + ArrowSchemaMetadata() {}; //! Adds an option to the metadata void AddOption(const string &key, const string &value); //! Gets an option from the metadata, returns an empty string if it does not exist. @@ -46,6 +45,6 @@ class ArrowSchemaMetadata { //! The unordered map that holds the metadata unordered_map schema_metadata_map; //! The extension metadata map, currently only used for internal types in arrow.opaque - unique_ptr extension_metadata_map; + unordered_map extension_metadata_map; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/cgroups.hpp b/src/duckdb/src/include/duckdb/common/cgroups.hpp index 7f2bc6e98..fcdbb730b 100644 --- a/src/duckdb/src/include/duckdb/common/cgroups.hpp +++ b/src/duckdb/src/include/duckdb/common/cgroups.hpp @@ -18,6 +18,13 @@ class CGroups { public: static optional_idx GetMemoryLimit(FileSystem &fs); static idx_t GetCPULimit(FileSystem &fs, idx_t physical_cores); + +private: + static optional_idx GetCGroupV2MemoryLimit(FileSystem &fs); + static optional_idx GetCGroupV1MemoryLimit(FileSystem &fs); + static string ReadCGroupPath(FileSystem &fs, const char *cgroup_file); + static string ReadMemoryCGroupPath(FileSystem &fs, const char *cgroup_file); + static optional_idx ReadCGroupValue(FileSystem &fs, const char *file_path); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/chrono.hpp b/src/duckdb/src/include/duckdb/common/chrono.hpp index 5b3733d37..c46e27b15 100644 --- a/src/duckdb/src/include/duckdb/common/chrono.hpp +++ b/src/duckdb/src/include/duckdb/common/chrono.hpp @@ -16,7 +16,6 @@ using std::chrono::duration_cast; using std::chrono::high_resolution_clock; using std::chrono::milliseconds; using std::chrono::nanoseconds; -using std::chrono::steady_clock; using std::chrono::system_clock; using std::chrono::time_point; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/column_index.hpp b/src/duckdb/src/include/duckdb/common/column_index.hpp index a563005f4..32d2e1828 100644 --- a/src/duckdb/src/include/duckdb/common/column_index.hpp +++ b/src/duckdb/src/include/duckdb/common/column_index.hpp @@ -61,9 +61,6 @@ struct ColumnIndex { bool IsRowIdColumn() const { return index == DConstants::INVALID_INDEX; } - bool IsVirtualColumn() const { - return index >= VIRTUAL_COLUMN_START; - } void Serialize(Serializer &serializer) const; static ColumnIndex Deserialize(Deserializer &deserializer); diff --git a/src/duckdb/src/include/duckdb/common/constants.hpp b/src/duckdb/src/include/duckdb/common/constants.hpp index e9f816a17..d4a0d7cda 100644 --- a/src/duckdb/src/include/duckdb/common/constants.hpp +++ b/src/duckdb/src/include/duckdb/common/constants.hpp @@ -40,11 +40,7 @@ DUCKDB_API bool IsInvalidCatalog(const string &str); //! Special value used to signify the ROW ID of a table DUCKDB_API extern const column_t COLUMN_IDENTIFIER_ROW_ID; -//! Special value used to signify an empty column (used for e.g. COUNT(*)) -DUCKDB_API extern const column_t COLUMN_IDENTIFIER_EMPTY; -DUCKDB_API extern const column_t VIRTUAL_COLUMN_START; DUCKDB_API bool IsRowIdColumnId(column_t column_id); -DUCKDB_API bool IsVirtualColumn(column_t column_id); //! The maximum row identifier used in tables extern const row_t MAX_ROW_ID; diff --git a/src/duckdb/src/include/duckdb/common/enum_util.hpp b/src/duckdb/src/include/duckdb/common/enum_util.hpp index 861cb2115..379a23969 100644 --- a/src/duckdb/src/include/duckdb/common/enum_util.hpp +++ b/src/duckdb/src/include/duckdb/common/enum_util.hpp @@ -34,10 +34,6 @@ struct EnumUtil { enum class ARTConflictType : uint8_t; -enum class ARTScanHandling : uint8_t; - -enum class ARTScanHandlingResult : uint8_t; - enum class AccessMode : uint8_t; enum class AggregateCombineType : uint8_t; @@ -124,8 +120,6 @@ enum class DatePartSpecifier : uint8_t; enum class DebugInitialize : uint8_t; -enum class DebugVectorVerification : uint8_t; - enum class DefaultOrderByNullType : uint8_t; enum class DependencyEntryType : uint8_t; @@ -232,9 +226,7 @@ enum class MetaPipelineType : uint8_t; enum class MetricsType : uint8_t; -enum class MultiFileColumnMappingMode : uint8_t; - -enum class MultiFileFileState : uint8_t; +enum class MultiFileReaderColumnMappingMode : uint8_t; enum class NType : uint8_t; @@ -336,8 +328,6 @@ enum class SinkResultType : uint8_t; enum class SourceResultType : uint8_t; -enum class StarExpressionType : uint8_t; - enum class StatementReturnType : uint8_t; enum class StatementType : uint8_t; @@ -404,12 +394,6 @@ enum class WindowExcludeMode : uint8_t; template<> const char* EnumUtil::ToChars(ARTConflictType value); -template<> -const char* EnumUtil::ToChars(ARTScanHandling value); - -template<> -const char* EnumUtil::ToChars(ARTScanHandlingResult value); - template<> const char* EnumUtil::ToChars(AccessMode value); @@ -539,9 +523,6 @@ const char* EnumUtil::ToChars(DatePartSpecifier value); template<> const char* EnumUtil::ToChars(DebugInitialize value); -template<> -const char* EnumUtil::ToChars(DebugVectorVerification value); - template<> const char* EnumUtil::ToChars(DefaultOrderByNullType value); @@ -702,10 +683,7 @@ template<> const char* EnumUtil::ToChars(MetricsType value); template<> -const char* EnumUtil::ToChars(MultiFileColumnMappingMode value); - -template<> -const char* EnumUtil::ToChars(MultiFileFileState value); +const char* EnumUtil::ToChars(MultiFileReaderColumnMappingMode value); template<> const char* EnumUtil::ToChars(NType value); @@ -857,9 +835,6 @@ const char* EnumUtil::ToChars(SinkResultType value); template<> const char* EnumUtil::ToChars(SourceResultType value); -template<> -const char* EnumUtil::ToChars(StarExpressionType value); - template<> const char* EnumUtil::ToChars(StatementReturnType value); @@ -957,12 +932,6 @@ const char* EnumUtil::ToChars(WindowExcludeMode value); template<> ARTConflictType EnumUtil::FromString(const char *value); -template<> -ARTScanHandling EnumUtil::FromString(const char *value); - -template<> -ARTScanHandlingResult EnumUtil::FromString(const char *value); - template<> AccessMode EnumUtil::FromString(const char *value); @@ -1092,9 +1061,6 @@ DatePartSpecifier EnumUtil::FromString(const char *value); template<> DebugInitialize EnumUtil::FromString(const char *value); -template<> -DebugVectorVerification EnumUtil::FromString(const char *value); - template<> DefaultOrderByNullType EnumUtil::FromString(const char *value); @@ -1255,10 +1221,7 @@ template<> MetricsType EnumUtil::FromString(const char *value); template<> -MultiFileColumnMappingMode EnumUtil::FromString(const char *value); - -template<> -MultiFileFileState EnumUtil::FromString(const char *value); +MultiFileReaderColumnMappingMode EnumUtil::FromString(const char *value); template<> NType EnumUtil::FromString(const char *value); @@ -1410,9 +1373,6 @@ SinkResultType EnumUtil::FromString(const char *value); template<> SourceResultType EnumUtil::FromString(const char *value); -template<> -StarExpressionType EnumUtil::FromString(const char *value); - template<> StatementReturnType EnumUtil::FromString(const char *value); diff --git a/src/duckdb/src/include/duckdb/common/enums/expression_type.hpp b/src/duckdb/src/include/duckdb/common/enums/expression_type.hpp index f517fb049..858781aa9 100644 --- a/src/duckdb/src/include/duckdb/common/enums/expression_type.hpp +++ b/src/duckdb/src/include/duckdb/common/enums/expression_type.hpp @@ -26,8 +26,6 @@ enum class ExpressionType : uint8_t { OPERATOR_IS_NULL = 14, // is not null operator OPERATOR_IS_NOT_NULL = 15, - // unpack operator - OPERATOR_UNPACK = 16, // ----------------------------- // Comparison Operators @@ -120,7 +118,6 @@ enum class ExpressionType : uint8_t { STRUCT_EXTRACT = 155, ARRAY_CONSTRUCTOR = 156, ARROW = 157, - OPERATOR_TRY = 158, // ----------------------------- // Subquery IN/EXISTS diff --git a/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp b/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp index 1a896333b..607588c11 100644 --- a/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +++ b/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp @@ -46,7 +46,6 @@ enum class PhysicalOperatorType : uint8_t { COLUMN_DATA_SCAN, CHUNK_SCAN, RECURSIVE_CTE_SCAN, - RECURSIVE_RECURRING_CTE_SCAN, CTE_SCAN, DELIM_SCAN, EXPRESSION_SCAN, @@ -69,7 +68,6 @@ enum class PhysicalOperatorType : uint8_t { // ----------------------------- UNION, RECURSIVE_CTE, - RECURSIVE_KEY_CTE, CTE, // ----------------------------- diff --git a/src/duckdb/src/include/duckdb/common/exception.hpp b/src/duckdb/src/include/duckdb/common/exception.hpp index ab6c73f75..71c4ff8b2 100644 --- a/src/duckdb/src/include/duckdb/common/exception.hpp +++ b/src/duckdb/src/include/duckdb/common/exception.hpp @@ -119,8 +119,6 @@ class Exception : public std::runtime_error { DUCKDB_API static unordered_map InitializeExtraInfo(const string &subtype, optional_idx error_location); - //! Whether this exception type can occur during execution of a query - DUCKDB_API static bool IsExecutionError(ExceptionType type); DUCKDB_API static string ToJSON(ExceptionType type, const string &message); DUCKDB_API static string ToJSON(ExceptionType type, const string &message, const unordered_map &extra_info); diff --git a/src/duckdb/src/include/duckdb/common/exception/catalog_exception.hpp b/src/duckdb/src/include/duckdb/common/exception/catalog_exception.hpp index 498fafd19..8b510d987 100644 --- a/src/duckdb/src/include/duckdb/common/exception/catalog_exception.hpp +++ b/src/duckdb/src/include/duckdb/common/exception/catalog_exception.hpp @@ -14,7 +14,6 @@ #include "duckdb/common/unordered_map.hpp" namespace duckdb { -struct EntryLookupInfo; class CatalogException : public Exception { public: @@ -29,7 +28,6 @@ class CatalogException : public Exception { : CatalogException(ConstructMessage(msg, params...), Exception::InitializeExtraInfo(error_context)) { } - static CatalogException MissingEntry(const EntryLookupInfo &lookup_info, const string &suggestion); static CatalogException MissingEntry(CatalogType type, const string &name, const string &suggestion, QueryErrorContext context = QueryErrorContext()); static CatalogException MissingEntry(const string &type, const string &name, const vector &suggestions, diff --git a/src/duckdb/src/include/duckdb/common/file_system.hpp b/src/duckdb/src/include/duckdb/common/file_system.hpp index bfe3cf76a..e3aac6e9b 100644 --- a/src/duckdb/src/include/duckdb/common/file_system.hpp +++ b/src/duckdb/src/include/duckdb/common/file_system.hpp @@ -57,12 +57,8 @@ struct FileHandle { FileHandle(const FileHandle &) = delete; DUCKDB_API virtual ~FileHandle(); - // Read at [nr_bytes] bytes into [buffer], and return the bytes actually read. - // File offset will be changed, which advances for number of bytes read. DUCKDB_API int64_t Read(void *buffer, idx_t nr_bytes); DUCKDB_API int64_t Write(void *buffer, idx_t nr_bytes); - // Read at [nr_bytes] bytes into [buffer]. - // File offset will not be changed. DUCKDB_API void Read(void *buffer, idx_t nr_bytes, idx_t location); DUCKDB_API void Write(void *buffer, idx_t nr_bytes, idx_t location); DUCKDB_API void Seek(idx_t location); @@ -140,9 +136,6 @@ class FileSystem { DUCKDB_API virtual int64_t GetFileSize(FileHandle &handle); //! Returns the file last modified time of a file handle, returns timespec with zero on all attributes on error DUCKDB_API virtual time_t GetLastModifiedTime(FileHandle &handle); - //! Returns a tag that uniquely identifies the version of the file, - //! used for checking cache invalidation for CachingFileSystem httpfs files - DUCKDB_API virtual string GetVersionTag(FileHandle &handle); //! Returns the file type of the attached handle DUCKDB_API virtual FileType GetFileType(FileHandle &handle); //! Truncate a file to a maximum size of new_size, new_size should be smaller than or equal to the current size of @@ -222,10 +215,6 @@ class FileSystem { //! Unregister a sub-filesystem by name DUCKDB_API virtual void UnregisterSubSystem(const string &name); - // !Extract a sub-filesystem by name, with ownership transfered, return nullptr if not registered or the subsystem - // has been disabled. - DUCKDB_API virtual unique_ptr ExtractSubSystem(const string &name); - //! List registered sub-filesystems, including builtin ones DUCKDB_API virtual vector ListSubSystems(); diff --git a/src/duckdb/src/include/duckdb/common/fsst.hpp b/src/duckdb/src/include/duckdb/common/fsst.hpp index 99bc2456e..47398d270 100644 --- a/src/duckdb/src/include/duckdb/common/fsst.hpp +++ b/src/duckdb/src/include/duckdb/common/fsst.hpp @@ -10,55 +10,16 @@ #include "duckdb/common/typedefs.hpp" #include "duckdb/common/vector.hpp" -#include "duckdb/storage/string_uncompressed.hpp" -#include "duckdb/common/types/value.hpp" -#include "duckdb/common/fsst.hpp" -#include "fsst.h" -#include "duckdb/common/types/vector_buffer.hpp" namespace duckdb { - class Value; class Vector; struct string_t; class FSSTPrimitives { -private: - // This allows us to decode FSST strings efficiently directly into a string_t (if inlined) - // The decode will overflow a bit into "extra_space", but "str" will contain the full string - struct StringWithExtraSpace { - string_t str; - uint64_t extra_space[string_t::INLINE_LENGTH]; - }; - public: - static string_t DecompressValue(void *duckdb_fsst_decoder, VectorStringBuffer &str_buffer, - const char *compressed_string, const idx_t compressed_string_len) { - const auto max_uncompressed_length = compressed_string_len * 8; - const auto fsst_decoder = static_cast(duckdb_fsst_decoder); - const auto compressed_string_ptr = (const unsigned char *)compressed_string; // NOLINT - const auto target_ptr = str_buffer.AllocateShrinkableBuffer(max_uncompressed_length); - const auto decompressed_string_size = duckdb_fsst_decompress( - fsst_decoder, compressed_string_len, compressed_string_ptr, max_uncompressed_length, target_ptr); - return str_buffer.FinalizeShrinkableBuffer(target_ptr, max_uncompressed_length, decompressed_string_size); - } - static string_t DecompressInlinedValue(void *duckdb_fsst_decoder, const char *compressed_string, - const idx_t compressed_string_len) { - const auto fsst_decoder = static_cast(duckdb_fsst_decoder); - const auto compressed_string_ptr = (const unsigned char *)compressed_string; // NOLINT - StringWithExtraSpace result; - const auto target_ptr = (unsigned char *)result.str.GetPrefixWriteable(); // NOLINT - const auto decompressed_string_size = - duckdb_fsst_decompress(fsst_decoder, compressed_string_len, compressed_string_ptr, - string_t::INLINE_LENGTH + sizeof(StringWithExtraSpace::extra_space), target_ptr); - if (decompressed_string_size > string_t::INLINE_LENGTH) { - throw IOException("Corrupt database file: decoded FSST string of >=%llu bytes (should be <=%llu bytes)", - decompressed_string_size, string_t::INLINE_LENGTH); - } - D_ASSERT(decompressed_string_size <= string_t::INLINE_LENGTH); - result.str.SetSizeAndFinalize(UnsafeNumericCast(decompressed_string_size)); - return result.str; - } + static string_t DecompressValue(void *duckdb_fsst_decoder, Vector &result, const char *compressed_string, + const idx_t compressed_string_len, vector &decompress_buffer); static string DecompressValue(void *duckdb_fsst_decoder, const char *compressed_string, const idx_t compressed_string_len, vector &decompress_buffer); }; diff --git a/src/duckdb/src/include/duckdb/common/multi_file_list.hpp b/src/duckdb/src/include/duckdb/common/multi_file_list.hpp new file mode 100644 index 000000000..5adc321cb --- /dev/null +++ b/src/duckdb/src/include/duckdb/common/multi_file_list.hpp @@ -0,0 +1,184 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// duckdb/common/multi_file_list.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "duckdb/common/common.hpp" +#include "duckdb/common/multi_file_reader_options.hpp" +#include "duckdb/common/extra_operator_info.hpp" + +namespace duckdb { +class MultiFileList; + +enum class FileExpandResult : uint8_t { NO_FILES, SINGLE_FILE, MULTIPLE_FILES }; + +struct MultiFileListScanData { + idx_t current_file_idx = DConstants::INVALID_INDEX; +}; + +class MultiFileListIterationHelper { +public: + DUCKDB_API explicit MultiFileListIterationHelper(MultiFileList &collection); + +private: + MultiFileList &file_list; + +private: + class MultiFileListIterator; + + class MultiFileListIterator { + public: + DUCKDB_API explicit MultiFileListIterator(MultiFileList *file_list); + + optional_ptr file_list; + MultiFileListScanData file_scan_data; + string current_file; + + public: + DUCKDB_API void Next(); + + DUCKDB_API MultiFileListIterator &operator++(); + DUCKDB_API bool operator!=(const MultiFileListIterator &other) const; + DUCKDB_API const string &operator*() const; + }; + +public: + MultiFileListIterator begin(); // NOLINT: match stl API + MultiFileListIterator end(); // NOLINT: match stl API +}; + +struct MultiFilePushdownInfo { + explicit MultiFilePushdownInfo(LogicalGet &get); + MultiFilePushdownInfo(idx_t table_index, const vector &column_names, const vector &column_ids, + ExtraOperatorInfo &extra_info); + + idx_t table_index; + const vector &column_names; + vector column_ids; + vector column_indexes; + ExtraOperatorInfo &extra_info; +}; + +//! Abstract class for lazily generated list of file paths/globs +//! NOTE: subclasses are responsible for ensuring thread-safety +class MultiFileList { +public: + explicit MultiFileList(vector paths, FileGlobOptions options); + virtual ~MultiFileList(); + + //! Returns the raw, unexpanded paths, pre-filter + const vector GetPaths() const; + + //! Get Iterator over the files for pretty for loops + MultiFileListIterationHelper Files(); + + //! Initialize a sequential scan over a file list + void InitializeScan(MultiFileListScanData &iterator); + //! Scan the next file into result_file, returns false when out of files + bool Scan(MultiFileListScanData &iterator, string &result_file); + + //! Returns the first file or an empty string if GetTotalFileCount() == 0 + string GetFirstFile(); + //! Syntactic sugar for GetExpandResult() == FileExpandResult::NO_FILES + bool IsEmpty(); + + //! Virtual functions for subclasses +public: + virtual unique_ptr ComplexFilterPushdown(ClientContext &context, + const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters); + virtual unique_ptr + DynamicFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, const vector &names, + const vector &types, const vector &column_ids, + TableFilterSet &filters) const; + + virtual vector GetAllFiles() = 0; + virtual FileExpandResult GetExpandResult() = 0; + virtual idx_t GetTotalFileCount() = 0; + + virtual unique_ptr GetCardinality(ClientContext &context); + +protected: + //! Get the i-th expanded file + virtual string GetFile(idx_t i) = 0; + +protected: + //! The unexpanded input paths + const vector paths; + //! Whether paths can expand to 0 files + const FileGlobOptions glob_options; +}; + +//! MultiFileList that takes a list of files and produces the same list of paths. Useful for quickly wrapping +//! existing vectors of paths in a MultiFileList without changing any code +class SimpleMultiFileList : public MultiFileList { +public: + //! Construct a SimpleMultiFileList from a list of already expanded files + explicit SimpleMultiFileList(vector paths); + //! Copy `paths` to `filtered_files` and apply the filters + unique_ptr ComplexFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters) override; + unique_ptr DynamicFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, + const vector &names, const vector &types, + const vector &column_ids, + TableFilterSet &filters) const override; + + //! Main MultiFileList API + vector GetAllFiles() override; + FileExpandResult GetExpandResult() override; + idx_t GetTotalFileCount() override; + +protected: + //! Main MultiFileList API + string GetFile(idx_t i) override; +}; + +//! MultiFileList that takes a list of paths and produces a list of files with all globs expanded +class GlobMultiFileList : public MultiFileList { +public: + GlobMultiFileList(ClientContext &context, vector paths, FileGlobOptions options); + //! Calls ExpandAll, then prunes the expanded_files using the hive/filename filters + unique_ptr ComplexFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters) override; + unique_ptr DynamicFilterPushdown(ClientContext &context, const MultiFileReaderOptions &options, + const vector &names, const vector &types, + const vector &column_ids, + TableFilterSet &filters) const override; + + //! Main MultiFileList API + vector GetAllFiles() override; + FileExpandResult GetExpandResult() override; + idx_t GetTotalFileCount() override; + +protected: + //! Main MultiFileList API + string GetFile(idx_t i) override; + + //! Get the i-th expanded file + string GetFileInternal(idx_t i); + //! Grabs the next path and expands it into Expanded paths: returns false if no more files to expand + bool ExpandNextPath(); + //! Grabs the next path and expands it into Expanded paths: returns false if no more files to expand + bool ExpandPathInternal(idx_t ¤t_path, vector &result) const; + //! Whether all files have been expanded + bool IsFullyExpanded() const; + + //! The ClientContext for globbing + ClientContext &context; + //! The current path to expand + idx_t current_path; + //! The expanded files + vector expanded_files; + + mutable mutex lock; +}; + +} // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/multi_file_reader.hpp b/src/duckdb/src/include/duckdb/common/multi_file_reader.hpp new file mode 100644 index 000000000..942f72c1e --- /dev/null +++ b/src/duckdb/src/include/duckdb/common/multi_file_reader.hpp @@ -0,0 +1,419 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// duckdb/common/multi_file_reader.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "duckdb/common/common.hpp" +#include "duckdb/common/enums/file_glob_options.hpp" +#include "duckdb/common/multi_file_reader_options.hpp" +#include "duckdb/common/multi_file_list.hpp" +#include "duckdb/common/optional_ptr.hpp" +#include "duckdb/common/types/value.hpp" +#include "duckdb/common/union_by_name.hpp" +#include "duckdb/parser/expression/constant_expression.hpp" + +namespace duckdb { +class TableFunction; +class TableFunctionSet; +class TableFilterSet; +class LogicalGet; +class Expression; +class ClientContext; +class DataChunk; + +struct HivePartitioningIndex { + HivePartitioningIndex(string value, idx_t index); + + string value; + idx_t index; + + DUCKDB_API void Serialize(Serializer &serializer) const; + DUCKDB_API static HivePartitioningIndex Deserialize(Deserializer &deserializer); +}; + +struct MultiFileReaderColumnDefinition { +public: + MultiFileReaderColumnDefinition(const string &name, const LogicalType &type) : name(name), type(type) { + } + + MultiFileReaderColumnDefinition(const MultiFileReaderColumnDefinition &other) + : name(other.name), type(other.type), children(other.children), + default_expression(other.default_expression ? other.default_expression->Copy() : nullptr), + identifier(other.identifier) { + } + + MultiFileReaderColumnDefinition &operator=(const MultiFileReaderColumnDefinition &other) { + if (this != &other) { + name = other.name; + type = other.type; + children = other.children; + default_expression = other.default_expression ? other.default_expression->Copy() : nullptr; + identifier = other.identifier; + } + return *this; + } + +public: + static vector ColumnsFromNamesAndTypes(const vector &names, + const vector &types) { + vector columns; + D_ASSERT(names.size() == types.size()); + for (idx_t i = 0; i < names.size(); i++) { + auto &name = names[i]; + auto &type = types[i]; + columns.emplace_back(name, type); + } + return columns; + } + + static void ExtractNamesAndTypes(const vector &columns, vector &names, + vector &types) { + D_ASSERT(names.empty()); + D_ASSERT(types.empty()); + for (auto &column : columns) { + names.push_back(column.name); + types.push_back(column.type); + } + } + + int32_t GetIdentifierFieldId() const { + D_ASSERT(!identifier.IsNull()); + D_ASSERT(identifier.type().id() == LogicalTypeId::INTEGER); + return identifier.GetValue(); + } + + string GetIdentifierName() const { + if (identifier.IsNull()) { + // No identifier was provided, assume the name as the identifier + return name; + } + D_ASSERT(identifier.type().id() == LogicalTypeId::VARCHAR); + return identifier.GetValue(); + } + + Value GetDefaultValue() const { + D_ASSERT(default_expression); + if (default_expression->type != ExpressionType::VALUE_CONSTANT) { + throw NotImplementedException("Default expression that isn't constant is not supported yet"); + } + auto &constant_expr = default_expression->Cast(); + return constant_expr.value; + } + +public: + string name; + LogicalType type; + vector children; + unique_ptr default_expression; + + //! Either the field_id or the name to map on + Value identifier; +}; + +//! The bind data for the multi-file reader, obtained through MultiFileReader::BindReader +struct MultiFileReaderBindData { + //! The index of the filename column (if any) + idx_t filename_idx = DConstants::INVALID_INDEX; + //! The set of hive partitioning indexes (if any) + vector hive_partitioning_indexes; + //! The index of the file_row_number column (if any) + idx_t file_row_number_idx = DConstants::INVALID_INDEX; + //! (optional) The schema set by the multi file reader + vector schema; + //! The method used to map local -> global columns + MultiFileReaderColumnMappingMode mapping = MultiFileReaderColumnMappingMode::BY_NAME; + + DUCKDB_API void Serialize(Serializer &serializer) const; + DUCKDB_API static MultiFileReaderBindData Deserialize(Deserializer &deserializer); +}; + +//! Global state for MultiFileReads +struct MultiFileReaderGlobalState { + MultiFileReaderGlobalState(vector extra_columns_p, optional_ptr file_list_p) + : extra_columns(std::move(extra_columns_p)), file_list(file_list_p) {}; + virtual ~MultiFileReaderGlobalState(); + + //! extra columns that will be produced during scanning + const vector extra_columns; + // the file list driving the current scan + const optional_ptr file_list; + + //! Indicates that the MultiFileReader has added columns to be scanned that are not in the projection + bool RequiresExtraColumns() { + return !extra_columns.empty(); + } + + template + TARGET &Cast() { + DynamicCastCheck(this); + return reinterpret_cast(*this); + } + template + const TARGET &Cast() const { + DynamicCastCheck(this); + return reinterpret_cast(*this); + } +}; + +struct MultiFileFilterEntry { + idx_t index = DConstants::INVALID_INDEX; + bool is_constant = false; +}; + +struct MultiFileConstantEntry { + MultiFileConstantEntry(idx_t column_id, Value value_p) : column_id(column_id), value(std::move(value_p)) { + } + //! The (global) column id to apply the constant value to + idx_t column_id; + //! The constant value + Value value; +}; + +struct MultiFileReaderData { + //! The column ids to read from the file + vector column_ids; + //! The column indexes to read from the file + vector column_indexes; + //! The mapping of column id -> result column id + //! The result chunk will be filled as follows: chunk.data[column_mapping[i]] = ReadColumn(column_ids[i]); + vector column_mapping; + //! Whether or not there are no columns to read. This can happen when a file only consists of constants + bool empty_columns = false; + //! Filters can point to either (1) local columns in the file, or (2) constant values in the `constant_map` + //! This map specifies where the to-be-filtered value can be found + vector filter_map; + //! The set of table filters + optional_ptr filters; + //! The constants that should be applied at the various positions + vector constant_map; + //! Map of column_id -> cast, used when reading multiple files when files have diverging types + //! for the same column + unordered_map cast_map; + //! (Optionally) The MultiFileReader-generated metadata corresponding to the currently read file + optional_idx file_list_idx; +}; + +//! The MultiFileReader class provides a set of helper methods to handle scanning from multiple files +struct MultiFileReader { + virtual ~MultiFileReader(); + + //! Create a MultiFileReader for a specific TableFunction, using its function name for errors + DUCKDB_API static unique_ptr Create(const TableFunction &table_function); + //! Create a default MultiFileReader, function_name is used for errors + DUCKDB_API static unique_ptr CreateDefault(const string &function_name = ""); + + //! Create a LIST Value from a vector of strings (list of file paths) + static Value CreateValueFromFileList(const vector &files); + + //! Add the parameters for multi-file readers (e.g. union_by_name, filename) to a table function + DUCKDB_API static void AddParameters(TableFunction &table_function); + //! Creates a table function set from a single reader function (including e.g. list parameters, etc) + DUCKDB_API static TableFunctionSet CreateFunctionSet(TableFunction table_function); + + //! Parse a Value containing 1 or more paths into a vector of paths. Note: no expansion is performed here + DUCKDB_API virtual vector ParsePaths(const Value &input); + //! Create a MultiFileList from a vector of paths. Any globs will be expanded using the default filesystem + DUCKDB_API virtual shared_ptr + CreateFileList(ClientContext &context, const vector &paths, + FileGlobOptions options = FileGlobOptions::DISALLOW_EMPTY); + //! Shorthand for ParsePaths + CreateFileList + DUCKDB_API shared_ptr CreateFileList(ClientContext &context, const Value &input, + FileGlobOptions options = FileGlobOptions::DISALLOW_EMPTY); + + //! Parse the named parameters of a multi-file reader + DUCKDB_API virtual bool ParseOption(const string &key, const Value &val, MultiFileReaderOptions &options, + ClientContext &context); + //! Perform filter pushdown into the MultiFileList. Returns a new MultiFileList if filters were pushed down + DUCKDB_API virtual unique_ptr ComplexFilterPushdown(ClientContext &context, MultiFileList &files, + const MultiFileReaderOptions &options, + MultiFilePushdownInfo &info, + vector> &filters); + DUCKDB_API virtual unique_ptr + DynamicFilterPushdown(ClientContext &context, const MultiFileList &files, const MultiFileReaderOptions &options, + const vector &names, const vector &types, + const vector &column_ids, TableFilterSet &filters); + //! Try to use the MultiFileReader for binding. Returns true if a bind could be made, returns false if the + //! MultiFileReader can not perform the bind and binding should be performed on 1 or more files in the MultiFileList + //! directly. + DUCKDB_API virtual bool Bind(MultiFileReaderOptions &options, MultiFileList &files, + vector &return_types, vector &names, + MultiFileReaderBindData &bind_data); + //! Bind the options of the multi-file reader, potentially emitting any extra columns that are required + DUCKDB_API virtual void BindOptions(MultiFileReaderOptions &options, MultiFileList &files, + vector &return_types, vector &names, + MultiFileReaderBindData &bind_data); + + //! Initialize global state used by the MultiFileReader + DUCKDB_API virtual unique_ptr + InitializeGlobalState(ClientContext &context, const MultiFileReaderOptions &file_options, + const MultiFileReaderBindData &bind_data, const MultiFileList &file_list, + const vector &global_columns, + const vector &global_column_ids); + + //! Finalize the bind phase of the multi-file reader after we know (1) the required (output) columns, and (2) the + //! pushed down table filters + DUCKDB_API virtual void FinalizeBind(const MultiFileReaderOptions &file_options, + const MultiFileReaderBindData &options, const string &filename, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, MultiFileReaderData &reader_data, + ClientContext &context, optional_ptr global_state); + + //! Create all required mappings from the global types/names to the file-local types/names + DUCKDB_API virtual void CreateMapping(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, + optional_ptr filters, MultiFileReaderData &reader_data, + const string &initial_file, const MultiFileReaderBindData &options, + optional_ptr global_state); + //! Populated the filter_map + DUCKDB_API virtual void CreateFilterMap(const vector &global_column_ids, + optional_ptr filters, MultiFileReaderData &reader_data, + optional_ptr global_state); + + //! Finalize the reading of a chunk - applying any constants that are required + DUCKDB_API virtual void FinalizeChunk(ClientContext &context, const MultiFileReaderBindData &bind_data, + const MultiFileReaderData &reader_data, DataChunk &chunk, + optional_ptr global_state); + + //! Fetch the partition data for the current chunk + DUCKDB_API virtual void GetPartitionData(ClientContext &context, const MultiFileReaderBindData &bind_data, + const MultiFileReaderData &reader_data, + optional_ptr global_state, + const OperatorPartitionInfo &partition_info, + OperatorPartitionData &partition_data); + + template + MultiFileReaderBindData BindUnionReader(ClientContext &context, vector &return_types, + vector &names, MultiFileList &files, RESULT_CLASS &result, + OPTIONS_CLASS &options) { + D_ASSERT(options.file_options.union_by_name); + vector union_col_names; + vector union_col_types; + + // obtain the set of union column names + types by unifying the types of all of the files + // note that this requires opening readers for each file and reading the metadata of each file + // note also that it requires fully expanding the MultiFileList + auto materialized_file_list = files.GetAllFiles(); + auto union_readers = UnionByName::UnionCols(context, materialized_file_list, union_col_types, + union_col_names, options); + + std::move(union_readers.begin(), union_readers.end(), std::back_inserter(result.union_readers)); + // perform the binding on the obtained set of names + types + MultiFileReaderBindData bind_data; + BindOptions(options.file_options, files, union_col_types, union_col_names, bind_data); + names = union_col_names; + return_types = union_col_types; + result.Initialize(context, result.union_readers[0]); + D_ASSERT(names.size() == return_types.size()); + return bind_data; + } + + template + MultiFileReaderBindData BindReader(ClientContext &context, vector &return_types, vector &names, + MultiFileList &files, RESULT_CLASS &result, OPTIONS_CLASS &options) { + if (options.file_options.union_by_name) { + return BindUnionReader(context, return_types, names, files, result, options); + } else { + shared_ptr reader; + reader = make_shared_ptr(context, files.GetFirstFile(), options); + auto &columns = reader->GetColumns(); + for (auto &column : columns) { + return_types.emplace_back(column.type); + names.emplace_back(column.name); + } + result.Initialize(std::move(reader)); + MultiFileReaderBindData bind_data; + BindOptions(options.file_options, files, return_types, names, bind_data); + return bind_data; + } + } + + template + void InitializeReader(READER_CLASS &reader, const MultiFileReaderOptions &options, + const MultiFileReaderBindData &bind_data, + const vector &global_columns, + const vector &global_column_ids, optional_ptr table_filters, + const string &initial_file, ClientContext &context, + optional_ptr global_state) { + FinalizeBind(options, bind_data, reader.GetFileName(), reader.GetColumns(), global_columns, global_column_ids, + reader.reader_data, context, global_state); + CreateMapping(reader.GetFileName(), reader.GetColumns(), global_columns, global_column_ids, table_filters, + reader.reader_data, initial_file, bind_data, global_state); + reader.reader_data.filters = table_filters; + } + + template + static void PruneReaders(BIND_DATA &data, MultiFileList &file_list) { + unordered_set file_set; + + // Avoid materializing the file list if there's nothing to prune + if (!data.initial_reader && data.union_readers.empty()) { + return; + } + + for (const auto &file : file_list.Files()) { + file_set.insert(file); + } + + if (data.initial_reader) { + // check if the initial reader should still be read + auto entry = file_set.find(data.initial_reader->GetFileName()); + if (entry == file_set.end()) { + data.initial_reader.reset(); + } + } + for (idx_t r = 0; r < data.union_readers.size(); r++) { + if (!data.union_readers[r]) { + data.union_readers.erase_at(r); + r--; + continue; + } + // check if the union reader should still be read or not + auto entry = file_set.find(data.union_readers[r]->GetFileName()); + if (entry == file_set.end()) { + data.union_readers.erase_at(r); + r--; + continue; + } + } + } + + //! Get partition info + DUCKDB_API virtual TablePartitionInfo GetPartitionInfo(ClientContext &context, + const MultiFileReaderBindData &bind_data, + TableFunctionPartitionInput &input); + +protected: + virtual void CreateColumnMapping(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, MultiFileReaderData &reader_data, + const MultiFileReaderBindData &bind_data, const string &initial_file, + optional_ptr global_state); + virtual void CreateColumnMappingByFieldId(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, + MultiFileReaderData &reader_data, + const MultiFileReaderBindData &bind_data, const string &initial_file, + optional_ptr global_state); + virtual void CreateColumnMappingByName(const string &file_name, + const vector &local_columns, + const vector &global_columns, + const vector &global_column_ids, + MultiFileReaderData &reader_data, const MultiFileReaderBindData &bind_data, + const string &initial_file, + optional_ptr global_state); + + //! Used in errors to report which function is using this MultiFileReader + string function_name; +}; + +} // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/multi_file_reader_options.hpp b/src/duckdb/src/include/duckdb/common/multi_file_reader_options.hpp new file mode 100644 index 000000000..32486cc8f --- /dev/null +++ b/src/duckdb/src/include/duckdb/common/multi_file_reader_options.hpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// duckdb/common/multi_file_reader_options.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "duckdb/common/case_insensitive_map.hpp" +#include "duckdb/common/hive_partitioning.hpp" +#include "duckdb/common/types.hpp" +#include "duckdb/main/client_context.hpp" + +namespace duckdb { +struct BindInfo; +class MultiFileList; + +enum class MultiFileReaderColumnMappingMode : uint8_t { BY_NAME, BY_FIELD_ID }; + +struct MultiFileReaderOptions { + bool filename = false; + bool hive_partitioning = false; + bool auto_detect_hive_partitioning = true; + bool union_by_name = false; + bool hive_types_autocast = true; + MultiFileReaderColumnMappingMode mapping = MultiFileReaderColumnMappingMode::BY_NAME; + + case_insensitive_map_t hive_types_schema; + + // Default/configurable name of the column containing the file names + static constexpr const char *DEFAULT_FILENAME_COLUMN = "filename"; + string filename_column = DEFAULT_FILENAME_COLUMN; + // These are used to pass options through custom multifilereaders + case_insensitive_map_t custom_options; + + DUCKDB_API void Serialize(Serializer &serializer) const; + DUCKDB_API static MultiFileReaderOptions Deserialize(Deserializer &source); + DUCKDB_API void AddBatchInfo(BindInfo &bind_info) const; + DUCKDB_API void AutoDetectHivePartitioning(MultiFileList &files, ClientContext &context); + DUCKDB_API static bool AutoDetectHivePartitioningInternal(MultiFileList &files, ClientContext &context); + DUCKDB_API void AutoDetectHiveTypesInternal(MultiFileList &files, ClientContext &context); + DUCKDB_API void VerifyHiveTypesArePartitions(const std::map &partitions) const; + DUCKDB_API LogicalType GetHiveLogicalType(const string &hive_partition_column) const; + DUCKDB_API Value GetHivePartitionValue(const string &base, const string &entry, ClientContext &context) const; + DUCKDB_API bool AnySet(); +}; + +} // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/operator/multiply.hpp b/src/duckdb/src/include/duckdb/common/operator/multiply.hpp index b333202bc..0fad42bd5 100644 --- a/src/duckdb/src/include/duckdb/common/operator/multiply.hpp +++ b/src/duckdb/src/include/duckdb/common/operator/multiply.hpp @@ -32,10 +32,6 @@ template <> interval_t MultiplyOperator::Operation(interval_t left, int64_t right); template <> interval_t MultiplyOperator::Operation(int64_t left, interval_t right); -template <> -interval_t MultiplyOperator::Operation(interval_t left, double right); -template <> -interval_t MultiplyOperator::Operation(double left, interval_t right); struct TryMultiplyOperator { template @@ -66,9 +62,6 @@ DUCKDB_API bool TryMultiplyOperator::Operation(hugeint_t left, hugeint_t right, template <> DUCKDB_API bool TryMultiplyOperator::Operation(uhugeint_t left, uhugeint_t right, uhugeint_t &result); -template <> -bool TryMultiplyOperator::Operation(interval_t left, double right, interval_t &result); - struct MultiplyOperatorOverflowCheck { template static inline TR Operation(TA left, TB right) { diff --git a/src/duckdb/src/include/duckdb/common/profiler.hpp b/src/duckdb/src/include/duckdb/common/profiler.hpp index 5fb65337a..397efad80 100644 --- a/src/duckdb/src/include/duckdb/common/profiler.hpp +++ b/src/duckdb/src/include/duckdb/common/profiler.hpp @@ -45,6 +45,6 @@ class BaseProfiler { bool finished = false; }; -using Profiler = BaseProfiler; +using Profiler = BaseProfiler; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp b/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp index fef1847bd..5c4a0e2a1 100644 --- a/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +++ b/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp @@ -107,7 +107,7 @@ class RadixPartitionedColumnData : public PartitionedColumnData { //! RadixPartitionedTupleData is a PartitionedTupleData that partitions input based on the radix of a hash class RadixPartitionedTupleData : public PartitionedTupleData { public: - RadixPartitionedTupleData(BufferManager &buffer_manager, shared_ptr layout_ptr, idx_t radix_bits_p, + RadixPartitionedTupleData(BufferManager &buffer_manager, const TupleDataLayout &layout, idx_t radix_bits_p, idx_t hash_col_idx_p); RadixPartitionedTupleData(const RadixPartitionedTupleData &other); ~RadixPartitionedTupleData() override; @@ -127,8 +127,7 @@ class RadixPartitionedTupleData : public PartitionedTupleData { TupleDataPinProperties properties) const override; void ComputePartitionIndices(PartitionedTupleDataAppendState &state, DataChunk &input, const SelectionVector &append_sel, const idx_t append_count) override; - void ComputePartitionIndices(Vector &row_locations, idx_t count, Vector &partition_indices, - unique_ptr &utility_vector) const override; + void ComputePartitionIndices(Vector &row_locations, idx_t count, Vector &partition_indices) const override; idx_t MaxPartitionIndex() const override { return RadixPartitioning::NumberOfPartitions(radix_bits) - 1; } diff --git a/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp b/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp index 70e4e3e86..06ae00f4e 100644 --- a/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp +++ b/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp @@ -10,7 +10,6 @@ #include "duckdb/common/enums/expression_type.hpp" #include "duckdb/common/types.hpp" -#include "duckdb/common/types/vector.hpp" namespace duckdb { @@ -23,6 +22,7 @@ class TupleDataLayout; class RowDataCollection; struct SelectionVector; class StringHeap; +class Vector; struct UnifiedVectorFormat; // The NestedValidity class help to set/get the validity from inside nested vectors @@ -46,7 +46,6 @@ struct RowOperationsState { } ArenaAllocator &allocator; - unique_ptr addresses; // Re-usable vector for row_aggregate.cpp }; // RowOperations contains a set of operations that operate on data using a RowLayout diff --git a/src/duckdb/src/include/duckdb/common/serializer/memory_stream.hpp b/src/duckdb/src/include/duckdb/common/serializer/memory_stream.hpp index f5cd1c153..a735ad1aa 100644 --- a/src/duckdb/src/include/duckdb/common/serializer/memory_stream.hpp +++ b/src/duckdb/src/include/duckdb/common/serializer/memory_stream.hpp @@ -25,20 +25,20 @@ class MemoryStream : public WriteStream, public ReadStream { public: static constexpr idx_t DEFAULT_INITIAL_CAPACITY = 512; - //! Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will - //! own the backing buffer, resize it when needed and free its memory when the stream is destroyed + // Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will + // own the backing buffer, resize it when needed and free its memory when the stream is destroyed explicit MemoryStream(Allocator &allocator, idx_t capacity = DEFAULT_INITIAL_CAPACITY); - //! Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will - //! own the backing buffer, resize it when needed and free its memory when the stream is destroyed + // Create a new owning MemoryStream with an internal backing buffer with the specified capacity. The stream will + // own the backing buffer, resize it when needed and free its memory when the stream is destroyed explicit MemoryStream(idx_t capacity = DEFAULT_INITIAL_CAPACITY); - //! Create a new non-owning MemoryStream over the specified external buffer and capacity. The stream will not take - //! ownership of the backing buffer, will not attempt to resize it and will not free the memory when the stream - //! is destroyed + // Create a new non-owning MemoryStream over the specified external buffer and capacity. The stream will not take + // ownership of the backing buffer, will not attempt to resize it and will not free the memory when the stream + // is destroyed explicit MemoryStream(data_ptr_t buffer, idx_t capacity); - //! Cant copy! + // Cant copy! MemoryStream(const MemoryStream &) = delete; MemoryStream &operator=(const MemoryStream &) = delete; @@ -47,33 +47,30 @@ class MemoryStream : public WriteStream, public ReadStream { ~MemoryStream() override; - //! Write data to the stream. - //! Throws if the write would exceed the capacity of the stream and the backing buffer is not owned by the stream + // Write data to the stream. + // Throws if the write would exceed the capacity of the stream and the backing buffer is not owned by the stream void WriteData(const_data_ptr_t buffer, idx_t write_size) override; - //! Read data from the stream. - //! Throws if the read would exceed the capacity of the stream + // Read data from the stream. + // Throws if the read would exceed the capacity of the stream void ReadData(data_ptr_t buffer, idx_t read_size) override; - //! Rewind the stream to the start, keeping the capacity and the backing buffer intact + // Rewind the stream to the start, keeping the capacity and the backing buffer intact void Rewind(); - //! Release ownership of the backing buffer and turn a owning stream into a non-owning one. - //! The stream will no longer be responsible for freeing the data. - //! The stream will also no longer attempt to automatically resize the buffer when the capacity is reached. + // Release ownership of the backing buffer and turn a owning stream into a non-owning one. + // The stream will no longer be responsible for freeing the data. + // The stream will also no longer attempt to automatically resize the buffer when the capacity is reached. void Release(); - //! Get a pointer to the underlying backing buffer + // Get a pointer to the underlying backing buffer data_ptr_t GetData() const; - //! Get the current position in the stream + // Get the current position in the stream idx_t GetPosition() const; - //! Get the capacity of the stream + // Get the capacity of the stream idx_t GetCapacity() const; - - //! Set the position in the stream - void SetPosition(idx_t position); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp b/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp index 8170875e8..d0ab3ed6a 100644 --- a/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp +++ b/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp @@ -9,6 +9,7 @@ #pragma once #include "duckdb/common/sort/sort.hpp" +#include "duckdb/common/types/column/partitioned_column_data.hpp" #include "duckdb/common/radix_partitioning.hpp" #include "duckdb/parallel/base_pipeline_event.hpp" @@ -21,7 +22,7 @@ class PartitionGlobalHashGroup { using Types = vector; using OrderMasks = unordered_map; - PartitionGlobalHashGroup(ClientContext &context, const Orders &partitions, const Orders &orders, + PartitionGlobalHashGroup(BufferManager &buffer_manager, const Orders &partitions, const Orders &orders, const Types &payload_types, bool external); inline int ComparePartitions(const SBIterator &left, const SBIterator &right) { @@ -81,7 +82,7 @@ class PartitionGlobalSinkState { // OVER(PARTITION BY...) (hash grouping) unique_ptr grouping_data; //! Payload plus hash column - shared_ptr grouping_types_ptr; + TupleDataLayout grouping_types; //! The number of radix bits if this partition is being synced with another idx_t fixed_bits; @@ -159,6 +160,7 @@ class PartitionGlobalMergeState { explicit PartitionGlobalMergeState(PartitionGlobalSinkState &sink); bool IsFinished() const { + lock_guard guard(lock); return stage == PartitionSortStage::FINISHED; } @@ -178,7 +180,7 @@ class PartitionGlobalMergeState { private: mutable mutex lock; - atomic stage; + PartitionSortStage stage; idx_t total_tasks; idx_t tasks_assigned; idx_t tasks_completed; diff --git a/src/duckdb/src/include/duckdb/common/sort/sort.hpp b/src/duckdb/src/include/duckdb/common/sort/sort.hpp index 188ea2127..c933da9f0 100644 --- a/src/duckdb/src/include/duckdb/common/sort/sort.hpp +++ b/src/duckdb/src/include/duckdb/common/sort/sort.hpp @@ -53,7 +53,7 @@ struct SortLayout { struct GlobalSortState { public: - GlobalSortState(ClientContext &context, const vector &orders, RowLayout &payload_layout); + GlobalSortState(BufferManager &buffer_manager, const vector &orders, RowLayout &payload_layout); //! Add local state sorted data to this global state void AddLocalState(LocalSortState &local_sort_state); @@ -68,8 +68,6 @@ struct GlobalSortState { void Print(); public: - //! The client context - ClientContext &context; //! The lock for updating the order global state mutex lock; //! The buffer manager diff --git a/src/duckdb/src/include/duckdb/common/string_util.hpp b/src/duckdb/src/include/duckdb/common/string_util.hpp index 8c0c19bef..7ccc80429 100644 --- a/src/duckdb/src/include/duckdb/common/string_util.hpp +++ b/src/duckdb/src/include/duckdb/common/string_util.hpp @@ -14,7 +14,7 @@ #include "duckdb/common/pair.hpp" #include "duckdb/common/set.hpp" #include "duckdb/common/vector.hpp" -#include "duckdb/common/complex_json.hpp" + #include namespace duckdb { @@ -165,9 +165,6 @@ class StringUtil { DUCKDB_API static void URLDecodeBuffer(const char *input, idx_t input_size, char *output, bool plus_to_space = false); - //! BOM skipping (https://en.wikipedia.org/wiki/Byte_order_mark) - DUCKDB_API static void SkipBOM(const char *buffer_ptr, const idx_t &buffer_size, idx_t &buffer_pos); - DUCKDB_API static idx_t ToUnsigned(const string &str); template @@ -221,9 +218,6 @@ class StringUtil { //! Case insensitive equals DUCKDB_API static bool CIEquals(const string &l1, const string &l2); - //! Case insensitive equals (null-terminated strings) - DUCKDB_API static bool CIEquals(const char *l1, idx_t l1_size, const char *l2, idx_t l2_size); - //! Case insensitive compare DUCKDB_API static bool CILessThan(const string &l1, const string &l2); @@ -301,22 +295,18 @@ class StringUtil { } //! JSON method that parses a { string: value } JSON blob + //! NOTE: this method ONLY parses a JSON {"key": "value"} object, it does not support ANYTHING else //! NOTE: this method is not efficient //! NOTE: this method is used in Exception construction - as such it does NOT throw on invalid JSON, instead an //! empty map is returned - //! Parses complex (i.e., nested) Json maps, it also parses invalid JSONs, as a pure string. - DUCKDB_API static unique_ptr ParseJSONMap(const string &json, bool ignore_errors = false); - + DUCKDB_API static unordered_map ParseJSONMap(const string &json); //! JSON method that constructs a { string: value } JSON map //! This is the inverse of ParseJSONMap //! NOTE: this method is not efficient DUCKDB_API static string ExceptionToJSONMap(ExceptionType type, const string &message, const unordered_map &map); - //! Transforms an unordered map to a JSON string DUCKDB_API static string ToJSONMap(const unordered_map &map); - //! Transforms an complex JSON to a JSON string - DUCKDB_API static string ToComplexJSONMap(const ComplexJSON &complex_json); DUCKDB_API static string GetFileName(const string &file_path); DUCKDB_API static string GetFileExtension(const string &file_name); diff --git a/src/duckdb/src/include/duckdb/common/typedefs.hpp b/src/duckdb/src/include/duckdb/common/typedefs.hpp index 2c0f3584d..a3bc4ac9a 100644 --- a/src/duckdb/src/include/duckdb/common/typedefs.hpp +++ b/src/duckdb/src/include/duckdb/common/typedefs.hpp @@ -31,9 +31,6 @@ typedef uint32_t sel_t; //! Type used for transaction timestamps typedef idx_t transaction_t; -//! Type used to identify connections -typedef idx_t connection_t; - //! Type used for column identifiers typedef idx_t column_t; //! Type used for storage (column) identifiers diff --git a/src/duckdb/src/include/duckdb/common/types.hpp b/src/duckdb/src/include/duckdb/common/types.hpp index 02f548ff2..1bc43811a 100644 --- a/src/duckdb/src/include/duckdb/common/types.hpp +++ b/src/duckdb/src/include/duckdb/common/types.hpp @@ -318,7 +318,6 @@ struct LogicalType { } DUCKDB_API string ToString() const; DUCKDB_API bool IsIntegral() const; - DUCKDB_API bool IsFloating() const; DUCKDB_API bool IsNumeric() const; DUCKDB_API bool IsTemporal() const; DUCKDB_API hash_t Hash() const; diff --git a/src/duckdb/src/include/duckdb/common/types/cast_helpers.hpp b/src/duckdb/src/include/duckdb/common/types/cast_helpers.hpp index 2d32e72fe..f0087ba30 100644 --- a/src/duckdb/src/include/duckdb/common/types/cast_helpers.hpp +++ b/src/duckdb/src/include/duckdb/common/types/cast_helpers.hpp @@ -192,66 +192,55 @@ struct UhugeintToStringCast { }; struct DateToStringCast { - static idx_t YearLength(int32_t &year, idx_t &year_length, bool &add_bc) { + static idx_t Length(int32_t date[], idx_t &year_length, bool &add_bc) { // format is YYYY-MM-DD with optional (BC) at the end // regular length is 10 idx_t length = 6; year_length = 4; add_bc = false; - if (year <= 0) { + if (date[0] <= 0) { // add (BC) suffix length += 5; - year = -year + 1; + date[0] = -date[0] + 1; add_bc = true; } // potentially add extra characters depending on length of year - year_length += year >= 10000; - year_length += year >= 100000; - year_length += year >= 1000000; - year_length += year >= 10000000; + year_length += date[0] >= 10000; + year_length += date[0] >= 100000; + year_length += date[0] >= 1000000; + year_length += date[0] >= 10000000; length += year_length; return length; } - static idx_t Length(int32_t date[], idx_t &year_length, bool &add_bc) { - return YearLength(date[0], year_length, add_bc); - } - - static void FormatComponent(char *&ptr, int32_t number) { - ptr[0] = '-'; - if (number < 10) { - ptr[1] = '0'; - ptr[2] = UnsafeNumericCast('0' + number); - } else { - auto index = UnsafeNumericCast(number * 2); - ptr[1] = duckdb_fmt::internal::data::digits[index]; - ptr[2] = duckdb_fmt::internal::data::digits[index + 1]; - } - ptr += 3; - } - - static void Format(char *data, int32_t year, int32_t month, int32_t day, idx_t year_length, bool add_bc) { + static void Format(char *data, int32_t date[], idx_t year_length, bool add_bc) { // now we write the string, first write the year auto endptr = data + year_length; - endptr = NumericHelper::FormatUnsigned(year, endptr); + endptr = NumericHelper::FormatUnsigned(date[0], endptr); // add optional leading zeros while (endptr > data) { *--endptr = '0'; } // now write the month and day auto ptr = data + year_length; - FormatComponent(ptr, month); - FormatComponent(ptr, day); + for (int i = 1; i <= 2; i++) { + ptr[0] = '-'; + if (date[i] < 10) { + ptr[1] = '0'; + ptr[2] = UnsafeNumericCast('0' + date[i]); + } else { + auto index = UnsafeNumericCast(date[i] * 2); + ptr[1] = duckdb_fmt::internal::data::digits[index]; + ptr[2] = duckdb_fmt::internal::data::digits[index + 1]; + } + ptr += 3; + } // optionally add BC to the end of the date if (add_bc) { memcpy(ptr, " (BC)", 5); // NOLINT } } - - static void Format(char *data, int32_t date[], idx_t year_length, bool add_bc) { - Format(data, date[0], date[1], date[2], year_length, add_bc); - } }; struct TimeToStringCast { @@ -272,11 +261,11 @@ struct TimeToStringCast { return UnsafeNumericCast(trailing_zeros); } - static idx_t MicrosLength(int32_t micros, char micro_buffer[]) { + static idx_t Length(int32_t time[], char micro_buffer[]) { // format is HH:MM:DD.MS // microseconds come after the time with a period separator idx_t length; - if (micros == 0) { + if (time[3] == 0) { // no microseconds // format is HH:MM:DD length = 8; @@ -287,15 +276,11 @@ struct TimeToStringCast { // we write backwards and pad with zeros to the left // now we figure out how many digits we need to include by looking backwards // and checking how many zeros we encounter - length -= NumericCast(FormatMicros(micros, micro_buffer)); + length -= NumericCast(FormatMicros(time[3], micro_buffer)); } return length; } - static idx_t Length(int32_t time[], char micro_buffer[]) { - return MicrosLength(time[3], micro_buffer); - } - static void FormatTwoDigits(char *ptr, int32_t value) { D_ASSERT(value >= 0 && value <= 99); if (value < 10) { @@ -308,24 +293,21 @@ struct TimeToStringCast { } } - static void Format(char *data, idx_t length, int32_t hour, int32_t minute, int32_t second, int32_t microsecond, - char micro_buffer[]) { + static void Format(char *data, idx_t length, int32_t time[], char micro_buffer[]) { // first write hour, month and day - FormatTwoDigits(data, hour); - data[2] = ':'; - FormatTwoDigits(data + 3, minute); - data[5] = ':'; - FormatTwoDigits(data + 6, second); + auto ptr = data; + ptr[2] = ':'; + ptr[5] = ':'; + for (int i = 0; i <= 2; i++) { + FormatTwoDigits(ptr, time[i]); + ptr += 3; + } if (length > 8) { // write the micro seconds at the end data[8] = '.'; memcpy(data + 9, micro_buffer, length - 9); } } - - static void Format(char *data, idx_t length, int32_t time[], char micro_buffer[]) { - Format(data, length, time[0], time[1], time[2], time[3], micro_buffer); - } }; struct IntervalToStringCast { diff --git a/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp b/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp index e63d03936..cb6ebcba5 100644 --- a/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp +++ b/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp @@ -143,7 +143,7 @@ class DataChunk { //! Vector to point back to the data owned by this DataChunk. DUCKDB_API void Reset(); - DUCKDB_API void Serialize(Serializer &serializer, bool compressed_serialization = true) const; + DUCKDB_API void Serialize(Serializer &serializer) const; DUCKDB_API void Deserialize(Deserializer &source); //! Hashes the DataChunk to the target vector diff --git a/src/duckdb/src/include/duckdb/common/types/datetime.hpp b/src/duckdb/src/include/duckdb/common/types/datetime.hpp index d52edd573..ccbb95524 100644 --- a/src/duckdb/src/include/duckdb/common/types/datetime.hpp +++ b/src/duckdb/src/include/duckdb/common/types/datetime.hpp @@ -1,11 +1,3 @@ -//===----------------------------------------------------------------------===// -// DuckDB -// -// duckdb/common/types/datetime.hpp -// -// -//===----------------------------------------------------------------------===// - #pragma once #include "duckdb/common/common.hpp" diff --git a/src/duckdb/src/include/duckdb/common/types/hash.hpp b/src/duckdb/src/include/duckdb/common/types/hash.hpp index 128ee634d..b213f249e 100644 --- a/src/duckdb/src/include/duckdb/common/types/hash.hpp +++ b/src/duckdb/src/include/duckdb/common/types/hash.hpp @@ -10,7 +10,6 @@ #include "duckdb/common/common.hpp" #include "duckdb/common/types.hpp" -#include "duckdb/common/types/datetime.hpp" namespace duckdb { @@ -64,8 +63,6 @@ template <> DUCKDB_API hash_t Hash(string_t val); template <> DUCKDB_API hash_t Hash(interval_t val); -template <> -DUCKDB_API hash_t Hash(dtime_tz_t val); DUCKDB_API hash_t Hash(const char *val, size_t size); DUCKDB_API hash_t Hash(uint8_t *val, size_t size); diff --git a/src/duckdb/src/include/duckdb/common/types/interval.hpp b/src/duckdb/src/include/duckdb/common/types/interval.hpp index 23c9b2052..825000d57 100644 --- a/src/duckdb/src/include/duckdb/common/types/interval.hpp +++ b/src/duckdb/src/include/duckdb/common/types/interval.hpp @@ -17,7 +17,6 @@ struct dtime_t; // NOLINT: literal casing struct date_t; // NOLINT: literal casing struct dtime_tz_t; // NOLINT: literal casing struct timestamp_t; // NOLINT: literal casing -struct TimestampComponents; class Serializer; class Deserializer; @@ -145,10 +144,8 @@ class Interval { //! Get Interval in Nanoseconds static int64_t GetNanoseconds(const interval_t &val); - //! Returns the age between two timestamps (including months) + //! Returns the age between two timestamps (including 30 day months) static interval_t GetAge(timestamp_t timestamp_1, timestamp_t timestamp_2); - //! Returns the age between two timestamp components - static interval_t GetAge(TimestampComponents ts1, TimestampComponents ts2, bool is_negative); //! Returns the exact difference between two timestamps (days and seconds) static interval_t GetDifference(timestamp_t timestamp_1, timestamp_t timestamp_2); diff --git a/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp b/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp index e3ba2a53a..878b1bfa0 100644 --- a/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp +++ b/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp @@ -31,12 +31,9 @@ struct PartitionedTupleDataAppendState { perfect_map_t partition_entries; fixed_size_map_t fixed_partition_entries; - unsafe_vector partition_pin_states; + unsafe_vector> partition_pin_states; TupleDataChunkState chunk_state; - //! Utility Vector for when repartitioning and copying rows straight from one collection to another - unique_ptr utility_vector; - public: template typename std::conditional, perfect_map_t>::type &GetMap() { @@ -74,6 +71,12 @@ enum class PartitionedTupleDataType : uint8_t { RADIX }; +//! Shared allocators for parallel partitioning +struct PartitionTupleDataAllocators { + mutex lock; + vector> allocators; +}; + //! PartitionedTupleData represents partitioned row data, which serves as an interface for different types of //! partitioning, e.g., radix, hive class PartitionedTupleData { @@ -82,7 +85,6 @@ class PartitionedTupleData { public: //! Get the layout of this PartitionedTupleData - shared_ptr GetLayoutPtr() const; const TupleDataLayout &GetLayout() const; //! Get the partitioning type of this PartitionedTupleData PartitionedTupleDataType GetType() const; @@ -107,7 +109,7 @@ class PartitionedTupleData { //! Resets this PartitionedTupleData void Reset(); //! Repartition this PartitionedTupleData into the new PartitionedTupleData - void Repartition(ClientContext &context, PartitionedTupleData &new_partitioned_data); + void Repartition(PartitionedTupleData &new_partitioned_data); //! Unpins the data void Unpin(); //! Get the partitions in this PartitionedTupleData @@ -143,8 +145,7 @@ class PartitionedTupleData { throw NotImplementedException("ComputePartitionIndices for this type of PartitionedTupleData"); } //! Compute partition indices from rows (similar to function above) - virtual void ComputePartitionIndices(Vector &row_locations, idx_t append_count, Vector &partition_indices, - unique_ptr &utility_vector) const { + virtual void ComputePartitionIndices(Vector &row_locations, idx_t append_count, Vector &partition_indices) const { throw NotImplementedException("ComputePartitionIndices for this type of PartitionedTupleData"); } //! Maximum partition index (optional) @@ -160,10 +161,11 @@ class PartitionedTupleData { protected: //! PartitionedTupleData can only be instantiated by derived classes - PartitionedTupleData(PartitionedTupleDataType type, BufferManager &buffer_manager, - shared_ptr &layout_ptr); + PartitionedTupleData(PartitionedTupleDataType type, BufferManager &buffer_manager, const TupleDataLayout &layout); PartitionedTupleData(const PartitionedTupleData &other); + //! Create a new shared allocator + void CreateAllocator(); //! Whether to use fixed size map or regular map bool UseFixedSizeMap() const; //! Builds a selection vector in the Append state for the partitions @@ -178,8 +180,12 @@ class PartitionedTupleData { template void BuildBufferSpace(PartitionedTupleDataAppendState &state); //! Create a collection for a specific a partition - unique_ptr CreatePartitionCollection(idx_t partition_index) { - return make_uniq(buffer_manager, layout_ptr); + unique_ptr CreatePartitionCollection(idx_t partition_index) const { + if (allocators) { + return make_uniq(allocators->allocators[partition_index]); + } else { + return make_uniq(buffer_manager, layout); + } } //! Verify count/data size of this PartitionedTupleData void Verify() const; @@ -187,12 +193,12 @@ class PartitionedTupleData { protected: PartitionedTupleDataType type; BufferManager &buffer_manager; - shared_ptr layout_ptr; - const TupleDataLayout &layout; + const TupleDataLayout layout; idx_t count; idx_t data_size; mutex lock; + shared_ptr allocators; unsafe_vector> partitions; public: diff --git a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_allocator.hpp b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_allocator.hpp index 0b98a1e9b..b68d3606b 100644 --- a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_allocator.hpp +++ b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_allocator.hpp @@ -16,7 +16,6 @@ namespace duckdb { struct TupleDataSegment; struct TupleDataChunk; struct TupleDataChunkPart; -class ContinuousIdSet; struct TupleDataBlock { public: @@ -53,7 +52,7 @@ struct TupleDataBlock { class TupleDataAllocator { public: - TupleDataAllocator(BufferManager &buffer_manager, shared_ptr &layout_ptr); + TupleDataAllocator(BufferManager &buffer_manager, const TupleDataLayout &layout); TupleDataAllocator(TupleDataAllocator &allocator); ~TupleDataAllocator(); @@ -63,7 +62,6 @@ class TupleDataAllocator { //! Get the buffer allocator Allocator &GetAllocator(); //! Get the layout - shared_ptr GetLayoutPtr() const; const TupleDataLayout &GetLayout() const; //! Number of row blocks idx_t RowBlockCount() const; @@ -101,7 +99,7 @@ class TupleDataAllocator { //! Internal function for ReleaseOrStoreHandles static void ReleaseOrStoreHandlesInternal(TupleDataSegment &segment, unsafe_vector &pinned_row_handles, - buffer_handle_map_t &handles, const ContinuousIdSet &block_ids, + perfect_map_t &handles, const perfect_set_t &block_ids, unsafe_vector &blocks, TupleDataPinProperties properties); //! Pins the given row block BufferHandle &PinRowBlock(TupleDataPinState &state, const TupleDataChunkPart &part); @@ -116,8 +114,7 @@ class TupleDataAllocator { //! The buffer manager BufferManager &buffer_manager; //! The layout of the data - shared_ptr layout_ptr; - const TupleDataLayout &layout; + const TupleDataLayout layout; //! Partition index (optional, if partitioned) optional_idx partition_index; //! Blocks storing the fixed-size rows diff --git a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp index 45efa5402..71b700922 100644 --- a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp +++ b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp @@ -49,7 +49,9 @@ class TupleDataCollection { public: //! Constructs a TupleDataCollection with the specified layout - TupleDataCollection(BufferManager &buffer_manager, shared_ptr layout_ptr); + TupleDataCollection(BufferManager &buffer_manager, const TupleDataLayout &layout); + //! Constructs a TupleDataCollection with the same (shared) allocator + explicit TupleDataCollection(shared_ptr allocator); ~TupleDataCollection(); @@ -239,8 +241,7 @@ class TupleDataCollection { private: //! The layout of the TupleDataCollection - shared_ptr layout_ptr; - const TupleDataLayout &layout; + const TupleDataLayout layout; //! The TupleDataAllocator shared_ptr allocator; //! The number of entries stored in the TupleDataCollection diff --git a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp index 77afad378..cf6ee2767 100644 --- a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp +++ b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp @@ -19,7 +19,6 @@ namespace duckdb { class TupleDataAllocator; class TupleDataLayout; -struct TupleDataSegment; struct TupleDataChunkPart { public: @@ -30,8 +29,8 @@ struct TupleDataChunkPart { TupleDataChunkPart &operator=(const TupleDataChunkPart &) = delete; //! Enable move constructors - TupleDataChunkPart(TupleDataChunkPart &&other) noexcept = default; - TupleDataChunkPart &operator=(TupleDataChunkPart &&) noexcept = default; + TupleDataChunkPart(TupleDataChunkPart &&other) noexcept; + TupleDataChunkPart &operator=(TupleDataChunkPart &&) noexcept; public: //! Mark heap as empty @@ -54,61 +53,7 @@ struct TupleDataChunkPart { private: //! Marker for empty heaps - static constexpr uint32_t INVALID_INDEX = static_cast(-1); -}; - -class ContinuousIdSet { -public: - ContinuousIdSet() : min_id(INVALID_INDEX), max_id(INVALID_INDEX) { - } - -public: - void Insert(const uint32_t &block_id) { - if (Empty()) { - min_id = block_id; - max_id = block_id; - } else { - min_id = MinValue(min_id, block_id); - max_id = MaxValue(max_id, block_id); - } - } - - bool Contains(const uint32_t &block_id) const { - if (Empty()) { - return false; - } - return block_id >= min_id && block_id <= max_id; - } - - bool Empty() const { - return min_id == INVALID_INDEX; - } - - uint32_t Start() const { - D_ASSERT(!Empty()); - return min_id; - } - - uint32_t End() const { - D_ASSERT(!Empty()); - return max_id + 1; - } - - uint32_t Size() const { - D_ASSERT(!Empty()); - return End() - Start(); - } - - void DecrementMax() { - D_ASSERT(!Empty()); - D_ASSERT(Size() > 1); - max_id--; - } - -private: - static constexpr uint32_t INVALID_INDEX = static_cast(-1); - uint32_t min_id; - uint32_t max_id; + static constexpr const uint32_t INVALID_INDEX = (uint32_t)-1; }; struct TupleDataChunk { @@ -124,20 +69,19 @@ struct TupleDataChunk { TupleDataChunk &operator=(TupleDataChunk &&) noexcept; //! Add a part to this chunk - TupleDataChunkPart &AddPart(TupleDataSegment &segment, TupleDataChunkPart &&part); + void AddPart(TupleDataChunkPart &&part, const TupleDataLayout &layout); //! Tries to merge the last chunk part into the second-to-last one - void MergeLastChunkPart(TupleDataSegment &segment); + void MergeLastChunkPart(const TupleDataLayout &layout); //! Verify counts of the parts in this chunk - void Verify(const TupleDataSegment &segment) const; + void Verify() const; public: //! The parts of this chunk - ContinuousIdSet part_ids; - + unsafe_vector parts; //! The row block ids referenced by the chunk - ContinuousIdSet row_block_ids; + perfect_set_t row_block_ids; //! The heap block ids referenced by the chunk - ContinuousIdSet heap_block_ids; + perfect_set_t heap_block_ids; //! Tuple count for this chunk idx_t count; //! Lock for recomputing heap pointers @@ -145,9 +89,6 @@ struct TupleDataChunk { }; struct TupleDataSegment { - friend struct TupleDataChunkPart; - friend struct TupleDataChunk; - public: explicit TupleDataSegment(shared_ptr allocator); @@ -176,11 +117,8 @@ struct TupleDataSegment { public: //! The allocator for this segment shared_ptr allocator; - reference layout; //! The chunks of this segment unsafe_vector chunks; - //! The chunk parts of this segment - unsafe_vector chunk_parts; //! The tuple count of this segment idx_t count; //! The data size of this segment diff --git a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp index 17b18cc82..e76ba83db 100644 --- a/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp +++ b/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp @@ -9,14 +9,13 @@ #pragma once #include "duckdb/common/mutex.hpp" +#include "duckdb/common/perfect_map_set.hpp" #include "duckdb/common/types.hpp" #include "duckdb/common/types/vector_cache.hpp" #include "duckdb/common/types/vector.hpp" namespace duckdb { -struct TupleDataChunkPart; - enum class TupleDataPinProperties : uint8_t { INVALID, //! Keeps all passed blocks pinned while scanning/iterating over the chunks (for both reading/writing) @@ -29,57 +28,9 @@ enum class TupleDataPinProperties : uint8_t { ALREADY_PINNED }; -//! Instead of an unordered_map from uint32 -> BufferHandle, we have a vector. -//! The lookup speed is OK since these maps should be very small. -//! The benefit of this is that we aren't doing any other heap allocations than the one vector. -//! For unordered_map, we would get a heap allocation for every inserted entry. -class buffer_handle_map_t { - using iterator = unsafe_vector>::iterator; - -public: - buffer_handle_map_t() { - } - -public: - pair emplace(const uint32_t &id, BufferHandle &&handle) { - D_ASSERT(find(id) == end()); // Should have been checked by the caller - handles.emplace_back(id, std::move(handle)); - return make_pair(--end(), true); - } - - iterator erase(const iterator &it) { - return handles.erase(it); - } - - iterator find(const uint32_t &id) { - auto it = handles.begin(); - for (; it != handles.end(); it++) { - if (it->first == id) { - break; - } - } - return it; - } - - iterator begin() { - return handles.begin(); - } - - iterator end() { - return handles.end(); - } - - void clear() { - handles.clear(); - } - -private: - unsafe_vector> handles; -}; - struct TupleDataPinState { - buffer_handle_map_t row_handles; - buffer_handle_map_t heap_handles; + perfect_map_t row_handles; + perfect_map_t heap_handles; TupleDataPinProperties properties = TupleDataPinProperties::INVALID; }; @@ -114,9 +65,6 @@ struct TupleDataChunkState { vector> cached_cast_vectors; vector> cached_cast_vector_cache; - - //! Cached vector (for InitializeChunkState) - unsafe_vector> parts; }; struct TupleDataAppendState { diff --git a/src/duckdb/src/include/duckdb/common/types/selection_vector.hpp b/src/duckdb/src/include/duckdb/common/types/selection_vector.hpp index 5aa104758..cd163aa2b 100644 --- a/src/duckdb/src/include/duckdb/common/types/selection_vector.hpp +++ b/src/duckdb/src/include/duckdb/common/types/selection_vector.hpp @@ -8,7 +8,6 @@ #pragma once -#include "duckdb/common/allocator.hpp" #include "duckdb/common/common.hpp" #include "duckdb/common/numeric_utils.hpp" #include "duckdb/common/types.hpp" @@ -20,7 +19,7 @@ class VectorBuffer; struct SelectionData { DUCKDB_API explicit SelectionData(idx_t count); - AllocatedData owned_data; + unsafe_unique_array owned_data; }; struct SelectionVector { @@ -73,11 +72,11 @@ struct SelectionVector { } void Initialize(idx_t count = STANDARD_VECTOR_SIZE) { selection_data = make_shared_ptr(count); - sel_vector = reinterpret_cast(selection_data->owned_data.get()); + sel_vector = selection_data->owned_data.get(); } void Initialize(buffer_ptr data) { selection_data = std::move(data); - sel_vector = reinterpret_cast(selection_data->owned_data.get()); + sel_vector = selection_data->owned_data.get(); } void Initialize(const SelectionVector &other) { selection_data = other.selection_data; diff --git a/src/duckdb/src/include/duckdb/common/types/string_heap.hpp b/src/duckdb/src/include/duckdb/common/types/string_heap.hpp index 73a84c5a5..2dac802ff 100644 --- a/src/duckdb/src/include/duckdb/common/types/string_heap.hpp +++ b/src/duckdb/src/include/duckdb/common/types/string_heap.hpp @@ -43,10 +43,6 @@ class StringHeap { //! Total allocation size (cached) DUCKDB_API idx_t AllocationSize() const; - DUCKDB_API ArenaAllocator &GetAllocator() { - return allocator; - } - private: ArenaAllocator allocator; }; diff --git a/src/duckdb/src/include/duckdb/common/types/string_type.hpp b/src/duckdb/src/include/duckdb/common/types/string_type.hpp index 1f69a53a7..0a88e3321 100644 --- a/src/duckdb/src/include/duckdb/common/types/string_type.hpp +++ b/src/duckdb/src/include/duckdb/common/types/string_type.hpp @@ -97,12 +97,6 @@ struct string_t { return value.inlined.length; } - void SetSizeAndFinalize(uint32_t size) { - value.inlined.length = size; - Finalize(); - VerifyCharacters(); - } - bool Empty() const { return value.inlined.length == 0; } diff --git a/src/duckdb/src/include/duckdb/common/types/timestamp.hpp b/src/duckdb/src/include/duckdb/common/types/timestamp.hpp index 57835db22..c56168251 100644 --- a/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +++ b/src/duckdb/src/include/duckdb/common/types/timestamp.hpp @@ -8,6 +8,7 @@ #pragma once +#include "duckdb/common/common.hpp" #include "duckdb/common/limits.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/common/types.hpp" @@ -111,24 +112,7 @@ struct timestamp_tz_t : public timestamp_t { // NOLINT } }; -enum class TimestampCastResult : uint8_t { - SUCCESS, - ERROR_INCORRECT_FORMAT, - ERROR_NON_UTC_TIMEZONE, - ERROR_RANGE, - STRICT_UTC -}; - -struct TimestampComponents { - int32_t year; - int32_t month; - int32_t day; - - int32_t hour; - int32_t minute; - int32_t second; - int32_t microsecond; -}; +enum class TimestampCastResult : uint8_t { SUCCESS, ERROR_INCORRECT_FORMAT, ERROR_NON_UTC_TIMEZONE, ERROR_RANGE }; //! The static Timestamp class holds helper functions for the timestamp types. class Timestamp { @@ -147,10 +131,8 @@ class Timestamp { DUCKDB_API static TimestampCastResult TryConvertTimestampTZ(const char *str, idx_t len, timestamp_t &result, bool &has_offset, string_t &tz, optional_ptr nanos = nullptr); - //! Strict Timestamp does not accept offsets. DUCKDB_API static TimestampCastResult TryConvertTimestamp(const char *str, idx_t len, timestamp_t &result, - optional_ptr nanos = nullptr, - bool strict = false); + optional_ptr nanos = nullptr); DUCKDB_API static TimestampCastResult TryConvertTimestamp(const char *str, idx_t len, timestamp_ns_t &result); DUCKDB_API static timestamp_t FromCString(const char *str, idx_t len, optional_ptr nanos = nullptr); //! Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss" @@ -216,10 +198,8 @@ class Timestamp { //! Convert a timestamp to a Julian Day DUCKDB_API static double GetJulianDay(timestamp_t timestamp); - //! Decompose a timestamp into its components - DUCKDB_API static TimestampComponents GetComponents(timestamp_t timestamp); - - DUCKDB_API static bool TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &hh, int &mm, int &ss); + DUCKDB_API static bool TryParseUTCOffset(const char *str, idx_t &pos, idx_t len, int &hour_offset, + int &minute_offset); DUCKDB_API static string FormatError(const string &str); DUCKDB_API static string FormatError(string_t str); diff --git a/src/duckdb/src/include/duckdb/common/types/uuid.hpp b/src/duckdb/src/include/duckdb/common/types/uuid.hpp index 16b1e082d..bf5ade17a 100644 --- a/src/duckdb/src/include/duckdb/common/types/uuid.hpp +++ b/src/duckdb/src/include/duckdb/common/types/uuid.hpp @@ -8,16 +8,15 @@ #pragma once -#include - #include "duckdb/common/types.hpp" #include "duckdb/common/types/string_type.hpp" namespace duckdb { +class ClientContext; class RandomEngine; -//! The BaseUUID class contains UUID related common and util functions. -class BaseUUID { +//! The UUID class contains static operations for the UUID type +class UUID { public: constexpr static const uint8_t STRING_SIZE = 36; //! Convert a uuid string to a hugeint object @@ -34,6 +33,10 @@ class BaseUUID { //! Convert a uuid value to a uhugeint_t object static uhugeint_t ToUHugeint(hugeint_t input); + //! Convert a hugeint object to a uuid style string + static hugeint_t GenerateRandomUUID(RandomEngine &engine); + static hugeint_t GenerateRandomUUID(); + //! Convert a hugeint object to a uuid style string static string ToString(hugeint_t input) { char buff[STRING_SIZE]; @@ -46,28 +49,6 @@ class BaseUUID { FromString(str, result); return result; } - -protected: - //! Util function, which converts uint8_t array to hugeint_t. - static hugeint_t Convert(const std::array &bytes); -}; - -//! The UUIDv4 class contains static operations for the UUIDv4 type -class UUID : public BaseUUID { -public: - //! Generate a random UUID v4 value. - static hugeint_t GenerateRandomUUID(RandomEngine &engine); - static hugeint_t GenerateRandomUUID(); -}; - -using UUIDv4 = UUID; - -//! The UUIDv7 class contains static operations for the UUIDv7 type. -class UUIDv7 : public BaseUUID { -public: - //! Generate a random UUID v7 value. - static hugeint_t GenerateRandomUUID(RandomEngine &engine); - static hugeint_t GenerateRandomUUID(); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp b/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp index 724703608..05583cddd 100644 --- a/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp +++ b/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp @@ -63,7 +63,7 @@ struct TemplatedValidityMask { public: static constexpr const idx_t BITS_PER_VALUE = ValidityBuffer::BITS_PER_VALUE; static constexpr const idx_t STANDARD_ENTRY_COUNT = (STANDARD_VECTOR_SIZE + (BITS_PER_VALUE - 1)) / BITS_PER_VALUE; - static constexpr const idx_t STANDARD_MASK_SIZE = STANDARD_ENTRY_COUNT * sizeof(V); + static constexpr const idx_t STANDARD_MASK_SIZE = STANDARD_ENTRY_COUNT * sizeof(validity_t); public: inline TemplatedValidityMask() : validity_mask(nullptr), capacity(STANDARD_VECTOR_SIZE) { @@ -112,11 +112,16 @@ struct TemplatedValidityMask { auto entry = GetValidityEntry(entry_idx++); // Handle ragged end (if not exactly multiple of BITS_PER_VALUE) if (entry_idx == entry_count && count % BITS_PER_VALUE != 0) { - const auto shift = BITS_PER_VALUE - (count % BITS_PER_VALUE); - const auto mask = ValidityBuffer::MAX_ENTRY >> shift; - entry &= mask; - } else if (AllValid(entry)) { - // Handle all set + idx_t idx_in_entry; + GetEntryIndex(count, entry_idx, idx_in_entry); + for (idx_t i = 0; i < idx_in_entry; ++i) { + valid += idx_t(RowIsValid(entry, i)); + } + break; + } + + // Handle all set + if (AllValid(entry)) { valid += BITS_PER_VALUE; continue; } @@ -183,7 +188,7 @@ struct TemplatedValidityMask { D_ASSERT(validity_mask); idx_t entry_idx, idx_in_entry; GetEntryIndex(row_idx, entry_idx, idx_in_entry); - auto entry = GetValidityEntryUnsafe(entry_idx); + auto entry = GetValidityEntry(entry_idx); return RowIsValid(entry, idx_in_entry); } diff --git a/src/duckdb/src/include/duckdb/common/types/value.hpp b/src/duckdb/src/include/duckdb/common/types/value.hpp index fa450abff..079541587 100644 --- a/src/duckdb/src/include/duckdb/common/types/value.hpp +++ b/src/duckdb/src/include/duckdb/common/types/value.hpp @@ -208,6 +208,9 @@ class Value { // type of the value. Only use this if you know what you are doing. template T GetValueUnsafe() const; + //! Returns a reference to the internal value. This can only be used for primitive types. + template + T &GetReferenceUnsafe(); //! Return a copy of this value Value Copy() const { diff --git a/src/duckdb/src/include/duckdb/common/types/vector.hpp b/src/duckdb/src/include/duckdb/common/types/vector.hpp index 5559cf4a6..61e0b714e 100644 --- a/src/duckdb/src/include/duckdb/common/types/vector.hpp +++ b/src/duckdb/src/include/duckdb/common/types/vector.hpp @@ -20,7 +20,6 @@ namespace duckdb { class VectorCache; -class VectorStringBuffer; class VectorStructBuffer; class VectorListBuffer; struct SelCache; @@ -207,7 +206,7 @@ class Vector { //! Returns a vector of ResizeInfo containing each (nested) vector to resize. DUCKDB_API void FindResizeInfos(vector &resize_infos, const idx_t multiplier); - DUCKDB_API void Serialize(Serializer &serializer, idx_t count, bool compressed_serialization = true); + DUCKDB_API void Serialize(Serializer &serializer, idx_t count); DUCKDB_API void Deserialize(Deserializer &deserializer, idx_t count); idx_t GetAllocationSize(idx_t cardinality) const; @@ -457,8 +456,6 @@ struct StringVector { //! Allocates an empty string of the specified size, and returns a writable pointer that can be used to store the //! result of an operation DUCKDB_API static string_t EmptyString(Vector &vector, idx_t len); - //! Returns a reference to the underlying VectorStringBuffer - throws an error if vector is not of type VARCHAR - DUCKDB_API static VectorStringBuffer &GetStringBuffer(Vector &vector); //! Adds a reference to a handle that stores strings of this vector DUCKDB_API static void AddHandle(Vector &vector, BufferHandle handle); //! Adds a reference to an unspecified vector buffer that stores strings of this vector diff --git a/src/duckdb/src/include/duckdb/common/types/vector_buffer.hpp b/src/duckdb/src/include/duckdb/common/types/vector_buffer.hpp index e44689a79..00ee20c2b 100644 --- a/src/duckdb/src/include/duckdb/common/types/vector_buffer.hpp +++ b/src/duckdb/src/include/duckdb/common/types/vector_buffer.hpp @@ -72,10 +72,10 @@ class VectorBuffer { } explicit VectorBuffer(idx_t data_size) : buffer_type(VectorBufferType::STANDARD_BUFFER) { if (data_size > 0) { - data = Allocator::DefaultAllocator().Allocate(data_size); + data = make_unsafe_uniq_array_uninitialized(data_size); } } - explicit VectorBuffer(AllocatedData &&data_p) + explicit VectorBuffer(unsafe_unique_array data_p) : buffer_type(VectorBufferType::STANDARD_BUFFER), data(std::move(data_p)) { } virtual ~VectorBuffer() { @@ -88,7 +88,7 @@ class VectorBuffer { return data.get(); } - void SetData(AllocatedData &&new_data) { + void SetData(unsafe_unique_array new_data) { data = std::move(new_data); } @@ -121,7 +121,7 @@ class VectorBuffer { protected: VectorBufferType buffer_type; unique_ptr aux_data; - AllocatedData data; + unsafe_unique_array data; public: template @@ -198,25 +198,6 @@ class VectorStringBuffer : public VectorBuffer { return heap.EmptyString(len); } - //! Allocate a buffer to store up to "len" bytes for a string - //! This can be turned into a proper string by using FinalizeBuffer afterwards - //! Note that alloc_len only has to be an upper bound, the final string may be smaller - data_ptr_t AllocateShrinkableBuffer(idx_t alloc_len) { - auto &allocator = heap.GetAllocator(); - return allocator.Allocate(alloc_len); - } - //! Finalize a buffer allocated with AllocateShrinkableBuffer into a string of size str_len - //! str_len must be <= alloc_len - string_t FinalizeShrinkableBuffer(data_ptr_t buffer, idx_t alloc_len, idx_t str_len) { - auto &allocator = heap.GetAllocator(); - D_ASSERT(str_len <= alloc_len); - D_ASSERT(buffer == allocator.GetHead()->data.get() + allocator.GetHead()->current_position - alloc_len); - bool is_not_inlined = str_len > string_t::INLINE_LENGTH; - idx_t shrink_count = alloc_len - (str_len * is_not_inlined); - allocator.ShrinkHead(shrink_count); - return string_t(const_char_ptr_cast(buffer), UnsafeNumericCast(str_len)); - } - void AddHeapReference(buffer_ptr heap) { references.push_back(std::move(heap)); } @@ -224,7 +205,7 @@ class VectorStringBuffer : public VectorBuffer { private: //! The string heap of this buffer StringHeap heap; - //! References to additional vector buffers referenced by this string buffer + // References to additional vector buffers referenced by this string buffer vector> references; }; diff --git a/src/duckdb/src/include/duckdb/common/union_by_name.hpp b/src/duckdb/src/include/duckdb/common/union_by_name.hpp new file mode 100644 index 000000000..2282424ad --- /dev/null +++ b/src/duckdb/src/include/duckdb/common/union_by_name.hpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// DuckDB +// +// duckdb/common/union_by_name.hpp +// +// +//===----------------------------------------------------------------------===// + +#pragma once + +#include "duckdb/common/types.hpp" +#include "duckdb/common/vector.hpp" +#include "duckdb/common/case_insensitive_map.hpp" +#include "duckdb/common/helper.hpp" +#include "duckdb/parallel/task_executor.hpp" + +namespace duckdb { + +template +class UnionByReaderTask : public BaseExecutorTask { +public: + UnionByReaderTask(TaskExecutor &executor, ClientContext &context, const string &file, idx_t file_idx, + vector &readers, OPTION_TYPE &options) + : BaseExecutorTask(executor), context(context), file_name(file), file_idx(file_idx), readers(readers), + options(options) { + } + + void ExecuteTask() override { + auto reader = make_uniq(context, file_name, options); + readers[file_idx] = READER_TYPE::StoreUnionReader(std::move(reader), file_idx); + } + +private: + ClientContext &context; + const string &file_name; + idx_t file_idx; + vector &readers; + OPTION_TYPE &options; +}; + +class UnionByName { +public: + static void CombineUnionTypes(const vector &new_names, const vector &new_types, + vector &union_col_types, vector &union_col_names, + case_insensitive_map_t &union_names_map); + + //! Union all files(readers) by their col names + template + static vector + UnionCols(ClientContext &context, const vector &files, vector &union_col_types, + vector &union_col_names, OPTION_TYPE &options) { + vector union_readers; + union_readers.resize(files.size()); + + TaskExecutor executor(context); + // schedule tasks for all files + for (idx_t file_idx = 0; file_idx < files.size(); ++file_idx) { + auto task = make_uniq>(executor, context, files[file_idx], + file_idx, union_readers, options); + executor.ScheduleTask(std::move(task)); + } + // complete all tasks + executor.WorkOnTasks(); + + // now combine the result schemas + case_insensitive_map_t union_names_map; + for (auto &reader : union_readers) { + auto &col_names = reader->names; + auto &sql_types = reader->types; + CombineUnionTypes(col_names, sql_types, union_col_types, union_col_names, union_names_map); + } + return union_readers; + } +}; + +} // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/common/virtual_file_system.hpp b/src/duckdb/src/include/duckdb/common/virtual_file_system.hpp index 13813cd0f..110ad0487 100644 --- a/src/duckdb/src/include/duckdb/common/virtual_file_system.hpp +++ b/src/duckdb/src/include/duckdb/common/virtual_file_system.hpp @@ -61,8 +61,6 @@ class VirtualFileSystem : public FileSystem { void RegisterSubSystem(FileCompressionType compression_type, unique_ptr fs) override; - unique_ptr ExtractSubSystem(const string &name) override; - vector ListSubSystems() override; std::string GetName() const override; diff --git a/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp b/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp index 0bb95ff9c..e44c90363 100644 --- a/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +++ b/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp @@ -13,11 +13,12 @@ #include "duckdb/execution/base_aggregate_hashtable.hpp" #include "duckdb/execution/ht_entry.hpp" #include "duckdb/storage/arena_allocator.hpp" -#include "duckdb/common/row_operations/row_operations.hpp" +#include "duckdb/storage/buffer/buffer_handle.hpp" namespace duckdb { class BlockHandle; +class BufferHandle; struct FlushMoveState; @@ -28,14 +29,6 @@ struct FlushMoveState; as input the set of groups and the types of the aggregates to compute and stores them in the HT. It uses linear probing for collision resolution. */ -struct AggregateHTScanState { -public: - AggregateHTScanState() { - } - - idx_t partition_idx = 0; - TupleDataScanState scan_states; -}; class GroupedAggregateHashTable : public BaseAggregateHashTable { public: @@ -53,7 +46,6 @@ class GroupedAggregateHashTable : public BaseAggregateHashTable { constexpr static double LOAD_FACTOR = 1.25; //! Get the layout of this HT - shared_ptr GetLayoutPtr(); const TupleDataLayout &GetLayout() const; //! Number of groups in the HT idx_t Count() const; @@ -80,9 +72,6 @@ class GroupedAggregateHashTable : public BaseAggregateHashTable { //! Fetch the aggregates for specific groups from the HT and place them in the result void FetchAggregates(DataChunk &groups, DataChunk &result); - void InitializeScan(AggregateHTScanState &scan_state); - bool Scan(AggregateHTScanState &scan_state, DataChunk &distinct_rows, DataChunk &payload_rows); - //! Finds or creates groups in the hashtable using the specified group keys. The addresses vector will be filled //! with pointers to the groups in the hash table, and the new_groups selection vector will point to the newly //! created groups. The return value is the amount of newly created groups. @@ -115,7 +104,6 @@ class GroupedAggregateHashTable : public BaseAggregateHashTable { void Combine(TupleDataCollection &other_data, optional_ptr> progress = nullptr); private: - ClientContext &context; //! Efficiently matches groups RowMatcher row_matcher; @@ -133,6 +121,25 @@ class GroupedAggregateHashTable : public BaseAggregateHashTable { idx_t capacity = 0; }; + //! Append state + struct AggregateHTAppendState { + AggregateHTAppendState(); + + PartitionedTupleDataAppendState partitioned_append_state; + PartitionedTupleDataAppendState unpartitioned_append_state; + + Vector ht_offsets; + Vector hash_salts; + SelectionVector group_compare_vector; + SelectionVector no_match_vector; + SelectionVector empty_vector; + SelectionVector new_groups; + Vector addresses; + unsafe_unique_array group_data; + DataChunk group_chunk; + AggregateDictionaryState dict_state; + } state; + //! If we have this many or more radix bits, we use the unpartitioned data collection too static constexpr idx_t UNPARTITIONED_RADIX_BITS_THRESHOLD = 3; //! The number of radix bits to partition by @@ -166,27 +173,6 @@ class GroupedAggregateHashTable : public BaseAggregateHashTable { //! Owning arena allocators that this HT has data from vector> stored_allocators; - //! Append state - struct AggregateHTAppendState { - explicit AggregateHTAppendState(ArenaAllocator &allocator); - - PartitionedTupleDataAppendState partitioned_append_state; - PartitionedTupleDataAppendState unpartitioned_append_state; - - Vector hashes; - Vector ht_offsets; - Vector hash_salts; - SelectionVector group_compare_vector; - SelectionVector no_match_vector; - SelectionVector empty_vector; - SelectionVector new_groups; - Vector addresses; - DataChunk group_chunk; - AggregateDictionaryState dict_state; - - RowOperationsState row_state; - } state; - private: //! Disabled the copy constructor GroupedAggregateHashTable(const GroupedAggregateHashTable &) = delete; diff --git a/src/duckdb/src/include/duckdb/execution/base_aggregate_hashtable.hpp b/src/duckdb/src/include/duckdb/execution/base_aggregate_hashtable.hpp index ce59051fa..df4f72882 100644 --- a/src/duckdb/src/include/duckdb/execution/base_aggregate_hashtable.hpp +++ b/src/duckdb/src/include/duckdb/execution/base_aggregate_hashtable.hpp @@ -27,7 +27,7 @@ class BaseAggregateHashTable { Allocator &allocator; BufferManager &buffer_manager; //! A helper for managing offsets into the data buffers - shared_ptr layout_ptr; + TupleDataLayout layout; //! The types of the payload columns stored in the hashtable vector payload_types; //! Intermediate structures and data for aggregate filters diff --git a/src/duckdb/src/include/duckdb/execution/expression_executor.hpp b/src/duckdb/src/include/duckdb/execution/expression_executor.hpp index 6d8fd4ac2..7aeb3c2da 100644 --- a/src/duckdb/src/include/duckdb/execution/expression_executor.hpp +++ b/src/duckdb/src/include/duckdb/execution/expression_executor.hpp @@ -13,7 +13,6 @@ #include "duckdb/planner/bound_tokens.hpp" #include "duckdb/planner/expression.hpp" #include "duckdb/main/client_context.hpp" -#include "duckdb/common/enums/debug_vector_verification.hpp" namespace duckdb { class Allocator; @@ -43,7 +42,6 @@ class ExpressionExecutor { //! Add an expression to the set of to-be-executed expressions of the executor DUCKDB_API void AddExpression(const Expression &expr); - void ClearExpressions(); //! Execute the set of expressions with the given input chunk and store the result in the output chunk DUCKDB_API void Execute(DataChunk *input, DataChunk &result); @@ -155,8 +153,6 @@ class ExpressionExecutor { optional_ptr context; //! The states of the expression executor; this holds any intermediates and temporary states of expressions vector> states; - //! The vector verification (debug setting) - DebugVectorVerification debug_vector_verification = DebugVectorVerification::NONE; private: // it is possible to create an expression executor without a ClientContext - but it should be avoided diff --git a/src/duckdb/src/include/duckdb/execution/index/art/art.hpp b/src/duckdb/src/include/duckdb/execution/index/art/art.hpp index 5f03b91da..ea638abf6 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/art.hpp @@ -53,7 +53,7 @@ class ART : public BoundIndex { } //! Plan index construction. - static PhysicalOperator &CreatePlan(PlanIndexInput &input); + static unique_ptr CreatePlan(PlanIndexInput &input); //! Root of the tree. Node tree = Node(); @@ -115,11 +115,9 @@ class ART : public BoundIndex { unsafe_vector &row_id_keys); //! Verifies the nodes and optionally returns a string of the ART. - string VerifyAndToString(IndexLock &l, const bool only_verify) override; + string VerifyAndToString(IndexLock &state, const bool only_verify) override; //! Verifies that the node allocations match the node counts. - void VerifyAllocations(IndexLock &l) override; - //! Verifies the index buffers. - void VerifyBuffers(IndexLock &l) override; + void VerifyAllocations(IndexLock &state) override; private: bool SearchEqual(ARTKey &key, idx_t max_count, unsafe_vector &row_ids); diff --git a/src/duckdb/src/include/duckdb/execution/index/art/node.hpp b/src/duckdb/src/include/duckdb/execution/index/art/node.hpp index d31e31c82..316ecc5f2 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/node.hpp @@ -112,8 +112,7 @@ class Node : public IndexPointer { void Vacuum(ART &art, const unordered_set &indexes); //! Transform the node storage to deprecated storage. - static void TransformToDeprecated(ART &art, Node &node, - unsafe_unique_ptr &deprecated_prefix_allocator); + static void TransformToDeprecated(ART &art, Node &node, unsafe_unique_ptr &allocator); //! Returns the node type. inline NType GetType() const { @@ -168,6 +167,16 @@ class Node : public IndexPointer { bool MergeInternal(ART &art, Node &other, const GateStatus status); private: + template + static void InitMergeInternal(ART &art, NODE &n, const unsafe_vector &upper_bounds) { + NODE::Iterator(n, [&](Node &child) { child.InitMerge(art, upper_bounds); }); + } + + template + static void VacuumInternal(ART &art, NODE &n, const unordered_set &indexes) { + NODE::Iterator(n, [&](Node &child) { child.Vacuum(art, indexes); }); + } + template static void TransformToDeprecatedInternal(ART &art, unsafe_optional_ptr ptr, unsafe_unique_ptr &allocator) { @@ -175,5 +184,10 @@ class Node : public IndexPointer { NODE::Iterator(*ptr, [&](Node &child) { Node::TransformToDeprecated(art, child, allocator); }); } } + + template + static void VerifyAllocationsInternal(ART &art, NODE &n, unordered_map &node_counts) { + NODE::Iterator(n, [&](const Node &child) { child.VerifyAllocations(art, node_counts); }); + } }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp b/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp index d856c5b2a..1afa0d993 100644 --- a/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp @@ -51,6 +51,9 @@ class Prefix { //! Free the prefix and its child. static void Free(ART &art, Node &node); + //! Initializes a merge by incrementing the buffer ID of the prefix and its child. + static void InitializeMerge(ART &art, Node &node, const unsafe_vector &upper_bounds); + //! Concatenates parent -> byte -> child. Special-handling, if //! 1. the byte was in a gate node. //! 2. the byte was in PREFIX_INLINED. @@ -87,6 +90,12 @@ class Prefix { //! Returns the string representation of the node, or only traverses and verifies the node and its subtree static string VerifyAndToString(ART &art, const Node &node, const bool only_verify); + //! Count the number of prefixes. + static void VerifyAllocations(ART &art, const Node &node, unordered_map &node_counts); + + //! Vacuum the child of the node. + static void Vacuum(ART &art, Node &node, const unordered_set &indexes); + //! Transform the child of the node. static void TransformToDeprecated(ART &art, Node &node, unsafe_unique_ptr &allocator); diff --git a/src/duckdb/src/include/duckdb/execution/index/bound_index.hpp b/src/duckdb/src/include/duckdb/execution/index/bound_index.hpp index ce2e5e400..4ac5d4b25 100644 --- a/src/duckdb/src/include/duckdb/execution/index/bound_index.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/bound_index.hpp @@ -114,10 +114,9 @@ class BoundIndex : public Index { //! Obtains a lock and calls MergeIndexes while holding that lock bool MergeIndexes(BoundIndex &other_index); - //! Performs a full traversal of the ART while vacuuming the qualifying nodes. - //! The lock obtained from InitializeLock must be held. - virtual void Vacuum(IndexLock &l) = 0; - //! Obtains a lock and calls Vacuum while holding that lock. + //! Traverses an ART and vacuums the qualifying nodes. The lock obtained from InitializeLock must be held + virtual void Vacuum(IndexLock &state) = 0; + //! Obtains a lock and calls Vacuum while holding that lock void Vacuum(); //! Returns the in-memory usage of the index. The lock obtained from InitializeLock must be held @@ -126,20 +125,15 @@ class BoundIndex : public Index { idx_t GetInMemorySize(); //! Returns the string representation of an index, or only traverses and verifies the index. - virtual string VerifyAndToString(IndexLock &l, const bool only_verify) = 0; + virtual string VerifyAndToString(IndexLock &state, const bool only_verify) = 0; //! Obtains a lock and calls VerifyAndToString. string VerifyAndToString(const bool only_verify); //! Ensures that the node allocation counts match the node counts. - virtual void VerifyAllocations(IndexLock &l) = 0; + virtual void VerifyAllocations(IndexLock &state) = 0; //! Obtains a lock and calls VerifyAllocations. void VerifyAllocations(); - //! Verify the index buffers. - virtual void VerifyBuffers(IndexLock &l); - //! Obtains a lock and calls VerifyBuffers. - void VerifyBuffers(); - //! Returns true if the index is affected by updates on the specified column IDs, and false otherwise bool IndexIsUpdated(const vector &column_ids) const; diff --git a/src/duckdb/src/include/duckdb/execution/index/fixed_size_allocator.hpp b/src/duckdb/src/include/duckdb/execution/index/fixed_size_allocator.hpp index 2bc8dd33d..3b2e4c287 100644 --- a/src/duckdb/src/include/duckdb/execution/index/fixed_size_allocator.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/fixed_size_allocator.hpp @@ -95,6 +95,10 @@ class FixedSizeAllocator { return total_segment_count; } + inline idx_t GetMaxSegmentsPerBuffer() const { + return available_segments_per_buffer; + } + //! Returns the upper bound of the available buffer IDs, i.e., upper_bound > max_buffer_id idx_t GetUpperBoundBufferId() const; //! Merge another FixedSizeAllocator into this allocator. Both must have the same segment size @@ -124,15 +128,12 @@ class FixedSizeAllocator { void Init(const FixedSizeAllocatorInfo &info); //! Deserializes all metadata of older storage files void Deserialize(MetadataManager &metadata_manager, const BlockPointer &block_pointer); - + //! Removes empty buffers. + void RemoveEmptyBuffers(); //! Returns true, if the allocator does not contain any segments. - inline bool Empty() { + inline bool IsEmpty() { return total_segment_count == 0; } - //! Removes empty buffers. - void RemoveEmptyBuffers(); - //! Verifies that the number of empty buffers does not exceed the empty buffer threshold. - void VerifyBuffers(); private: //! Allocation size of one segment in a buffer @@ -151,23 +152,16 @@ class FixedSizeAllocator { //! We can recalculate this by iterating over all buffers idx_t total_segment_count; - //! Buffers containing the segments. + //! Buffers containing the segments unordered_map> buffers; - //! Buffers with free space. + //! Buffers with free space unordered_set buffers_with_free_space; - //! Caches the next buffer to be filled up. - //! Unordered sets make no guarantee that begin() returns the same element. - //! By caching one of the buffers with free space, we get more consistency when filling buffers. - optional_idx buffer_with_free_space; - //! Buffers qualifying for a vacuum (helper field to allow for fast NeedsVacuum checks) unordered_set vacuum_buffers; private: //! Returns an available buffer id idx_t GetAvailableBufferId() const; - //! Caches the next buffer that we're going to fill. - void NextBufferWithFreeSpace(); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/index/fixed_size_buffer.hpp b/src/duckdb/src/include/duckdb/execution/index/fixed_size_buffer.hpp index 1ead2cb1b..edeb0ab17 100644 --- a/src/duckdb/src/include/duckdb/execution/index/fixed_size_buffer.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/fixed_size_buffer.hpp @@ -82,6 +82,9 @@ class FixedSizeBuffer { uint32_t GetOffset(const idx_t bitmask_count, const idx_t available_segments); //! Sets the allocation size, if dirty void SetAllocationSize(const idx_t available_segments, const idx_t segment_size, const idx_t bitmask_offset); + //! Sets all uninitialized regions of a buffer in the respective partial block allocation + void SetUninitializedRegions(PartialBlockForIndex &p_block_for_index, const idx_t segment_size, const idx_t offset, + const idx_t bitmask_offset, const idx_t available_segments); private: //! Block manager of the database instance diff --git a/src/duckdb/src/include/duckdb/execution/index/index_type.hpp b/src/duckdb/src/include/duckdb/execution/index/index_type.hpp index 62d335b84..52d779f3d 100644 --- a/src/duckdb/src/include/duckdb/execution/index/index_type.hpp +++ b/src/duckdb/src/include/duckdb/execution/index/index_type.hpp @@ -14,7 +14,6 @@ #include "duckdb/common/string.hpp" #include "duckdb/common/types/value.hpp" #include "duckdb/common/case_insensitive_map.hpp" -#include "duckdb/execution/physical_plan_generator.hpp" namespace duckdb { @@ -49,17 +48,15 @@ struct CreateIndexInput { struct PlanIndexInput { ClientContext &context; LogicalCreateIndex &op; - PhysicalPlanGenerator &planner; - PhysicalOperator &table_scan; + unique_ptr &table_scan; - PlanIndexInput(ClientContext &context_p, LogicalCreateIndex &op_p, PhysicalPlanGenerator &planner, - PhysicalOperator &table_scan_p) - : context(context_p), op(op_p), planner(planner), table_scan(table_scan_p) { + PlanIndexInput(ClientContext &context_p, LogicalCreateIndex &op_p, unique_ptr &table_scan_p) + : context(context_p), op(op_p), table_scan(table_scan_p) { } }; typedef unique_ptr (*index_create_function_t)(CreateIndexInput &input); -typedef PhysicalOperator &(*index_plan_function_t)(PlanIndexInput &input); +typedef unique_ptr (*index_plan_function_t)(PlanIndexInput &input); //! A index "type" class IndexType { diff --git a/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp b/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp index fc74fad44..441c3ecd8 100644 --- a/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp +++ b/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp @@ -177,10 +177,8 @@ class JoinHashTable { void Merge(JoinHashTable &other); //! Combines the partitions in sink_collection into data_collection, as if it were not partitioned void Unpartition(); - //! Allocate the pointer table for the probe - void AllocatePointerTable(); //! Initialize the pointer table for the probe - void InitializePointerTable(idx_t entry_idx_from, idx_t entry_idx_to); + void InitializePointerTable(); //! Finalize the build of the HT, constructing the actual hash table and making the HT ready for probing. //! Finalize must be called before any call to Probe, and after Finalize is called Build should no longer be //! ever called. @@ -212,7 +210,6 @@ class JoinHashTable { return null_values_are_equal[col_idx]; } - ClientContext &context; //! BufferManager BufferManager &buffer_manager; //! The join conditions @@ -235,7 +232,7 @@ class JoinHashTable { //! The column indices of the non-equality predicates to be used to compare the rows vector non_equality_predicate_columns; //! Data column layout - shared_ptr layout_ptr; + TupleDataLayout layout; //! Matches the equal condition rows during the build phase of the hash join to prevent //! duplicates in a list because of hash-collisions RowMatcher row_matcher_build; @@ -384,22 +381,13 @@ class JoinHashTable { return radix_bits; } - //! For a LOAD_FACTOR of 2.0, the HT is between 25% and 50% full - static constexpr double DEFAULT_LOAD_FACTOR = 2.0; - //! For a LOAD_FACTOR of 1.5, the HT is between 33% and 67% full - static constexpr double EXTERNAL_LOAD_FACTOR = 1.5; - - double load_factor = DEFAULT_LOAD_FACTOR; - //! Capacity of the pointer table given the ht count - idx_t PointerTableCapacity(idx_t count) const { - static constexpr idx_t MINIMUM_CAPACITY = 16384; - - const auto capacity = NextPowerOfTwo(LossyNumericCast(static_cast(count) * load_factor)); - return MaxValue(capacity, MINIMUM_CAPACITY); + //! (minimum of 1024 to prevent collision chance for small HT's) + static idx_t PointerTableCapacity(idx_t count) { + return MaxValue(NextPowerOfTwo(count * 2), 1 << 10); } //! Size of the pointer table (in bytes) - idx_t PointerTableSize(idx_t count) const { + static idx_t PointerTableSize(idx_t count) { return PointerTableCapacity(count) * sizeof(data_ptr_t); } diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/base_scanner.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/base_scanner.hpp index 9b355e271..1a68757d9 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/base_scanner.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/base_scanner.hpp @@ -201,11 +201,6 @@ class BaseScanner { void Process(T &result) { idx_t to_pos; const bool has_escaped_value = state_machine->dialect_options.state_machine_options.escape != '\0'; - const bool only_rn_newlines = - state_machine->state_machine_options.strict_mode.GetValue() && - state_machine->state_machine_options.strict_mode.IsSetByUser() && - state_machine->state_machine_options.new_line.GetValue() == NewLineIdentifier::CARRY_ON && - state_machine->state_machine_options.new_line.IsSetByUser(); const idx_t start_pos = iterator.pos.buffer_pos; if (iterator.IsBoundarySet()) { to_pos = iterator.GetEndPos(); @@ -269,7 +264,7 @@ class BaseScanner { lines_read++; return; } - } else if (!only_rn_newlines) { + } else { if (T::AddRow(result, iterator.pos.buffer_pos)) { iterator.pos.buffer_pos++; bytes_read = iterator.pos.buffer_pos - start_pos; diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer.hpp index 7ee7d60a3..d1894b5ee 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer.hpp @@ -19,10 +19,10 @@ namespace duckdb { class CSVBufferHandle { public: CSVBufferHandle(BufferHandle handle_p, idx_t actual_size_p, idx_t requested_size_p, const bool is_final_buffer_p, - idx_t buffer_index_p) + idx_t file_idx_p, idx_t buffer_index_p) : handle(std::move(handle_p)), actual_size(actual_size_p), requested_size(requested_size_p), - is_last_buffer(is_final_buffer_p), buffer_idx(buffer_index_p) {}; - CSVBufferHandle() : actual_size(0), requested_size(0), is_last_buffer(false), buffer_idx(0) {}; + is_last_buffer(is_final_buffer_p), file_idx(file_idx_p), buffer_idx(buffer_index_p) {}; + CSVBufferHandle() : actual_size(0), requested_size(0), is_last_buffer(false), file_idx(0), buffer_idx(0) {}; ~CSVBufferHandle() { } //! Handle created during allocation @@ -30,6 +30,7 @@ class CSVBufferHandle { const idx_t actual_size; const idx_t requested_size; const bool is_last_buffer; + const idx_t file_idx; const idx_t buffer_idx; inline char *Ptr() { return char_ptr_cast(handle.Ptr()); @@ -44,14 +45,15 @@ class CSVBuffer { public: //! Constructor for Initial Buffer CSVBuffer(ClientContext &context, idx_t buffer_size_p, CSVFileHandle &file_handle, - const idx_t &global_csv_current_position); + const idx_t &global_csv_current_position, idx_t file_number); //! Constructor for `Next()` Buffers CSVBuffer(CSVFileHandle &file_handle, ClientContext &context, idx_t buffer_size, idx_t global_csv_current_position, - idx_t buffer_idx); + idx_t file_number_p, idx_t buffer_idx); //! Creates a new buffer with the next part of the CSV File - shared_ptr Next(CSVFileHandle &file_handle, idx_t buffer_size, bool &has_seeked) const; + shared_ptr Next(CSVFileHandle &file_handle, idx_t buffer_size, idx_t file_number, + bool &has_seaked) const; //! Gets the buffer actual size idx_t GetBufferSize() const; @@ -88,6 +90,8 @@ class CSVBuffer { idx_t requested_size; //! Global position from the CSV File where this buffer starts idx_t global_csv_start = 0; + //! Number of the file that is in this buffer + idx_t file_number = 0; //! If we can seek in the file or not. bool can_seek; //! If this file is being fed by a pipe. diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer_manager.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer_manager.hpp index 1291a9a61..6c9674229 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer_manager.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer_manager.hpp @@ -22,7 +22,8 @@ class CSVStateMachine; class CSVBufferManager { public: CSVBufferManager(ClientContext &context, const CSVReaderOptions &options, const string &file_path, - bool per_file_single_threaded = false, unique_ptr file_handle = nullptr); + const idx_t file_idx, bool per_file_single_threaded = false, + unique_ptr file_handle = nullptr); //! Returns a buffer from a buffer id (starting from 0). If it's in the auto-detection then we cache new buffers //! Otherwise we remove them from the cache if they are already there, or just return them bypassing the cache. @@ -58,6 +59,8 @@ class CSVBufferManager { private: //! Reads next buffer in reference to cached_buffers.front() bool ReadNextAndCacheIt(); + //! The file index this Buffer Manager refers to + const idx_t file_idx; //! The file path this Buffer Manager refers to const string file_path; //! The cached buffers diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_error.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_error.hpp index 7d7ee88d6..c585576f2 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_error.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_error.hpp @@ -15,14 +15,12 @@ #include "duckdb/common/types/string_type.hpp" #include "duckdb/execution/operator/csv_scanner/csv_reader_options.hpp" #include "duckdb/execution/operator/csv_scanner/header_value.hpp" -#include "duckdb/execution/operator/csv_scanner/set_columns.hpp" namespace duckdb { class InternalAppender; class CSVFileScan; class CSVRejectsTable; struct ReadCSVData; -struct MultiFileBindData; //! Object that holds information on how many lines each csv batch read. class LinesPerBoundary { @@ -68,8 +66,7 @@ class CSVError { string &csv_row, idx_t row_byte_position, optional_idx byte_position, const string ¤t_path); //! Produces an error message for a dialect sniffing error. - static CSVError SniffingError(const CSVReaderOptions &options, const string &search_space, idx_t max_columns_found, - SetColumns &set_columns); + static CSVError SniffingError(const CSVReaderOptions &options, const string &search_space); //! Produces an error message for a header sniffing error. static CSVError HeaderSniffingError(const CSVReaderOptions &options, const vector &best_header_row, idx_t column_count, const string &delimiter); @@ -123,8 +120,6 @@ class CSVErrorHandler { void Error(const CSVError &csv_error, bool force_error = false); //! If we have a cached error, and we can now error, we error. void ErrorIfNeeded(); - //! Throw an error if there are any - void ErrorIfAny(); //! Throws an error if a given type exists void ErrorIfTypeExists(CSVErrorType error_type); //! Inserts a finished error info @@ -142,7 +137,7 @@ class CSVErrorHandler { idx_t GetSize(); void FillRejectsTable(InternalAppender &errors_appender, idx_t file_idx, idx_t scan_idx, const CSVFileScan &file, - CSVRejectsTable &rejects, const MultiFileBindData &bind_data, idx_t limit); + CSVRejectsTable &rejects, const ReadCSVData &bind_data, idx_t limit); private: //! Private methods should always be locked by parent method. diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_file_scanner.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_file_scanner.hpp index e9be2e3e0..016f0b908 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_file_scanner.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_file_scanner.hpp @@ -13,60 +13,81 @@ #include "duckdb/execution/operator/csv_scanner/csv_state_machine.hpp" #include "duckdb/execution/operator/csv_scanner/csv_error.hpp" #include "duckdb/execution/operator/csv_scanner/csv_schema.hpp" -#include "duckdb/execution/operator/csv_scanner/csv_validator.hpp" -#include "duckdb/common/multi_file/base_file_reader.hpp" namespace duckdb { struct ReadCSVData; class CSVFileScan; -struct CSVUnionData : public BaseUnionData { - explicit CSVUnionData(string file_name_p) : BaseUnionData(std::move(file_name_p)) { - } - ~CSVUnionData() override; +struct CSVUnionData { + ~CSVUnionData(); + string file_name; + vector names; + vector types; CSVReaderOptions options; + unique_ptr reader; + + const string &GetFileName() { + return file_name; + } }; //! Struct holding information over a CSV File we will scan -class CSVFileScan : public BaseFileReader { +class CSVFileScan { public: + using UNION_READER_DATA = unique_ptr; + +public: + //! Constructor for when a CSV File Scan is being constructed over information acquired during sniffing + //! This means the options are alreadu set, and the buffer manager is already up and runinng. + CSVFileScan(ClientContext &context, shared_ptr buffer_manager, + shared_ptr state_machine, const CSVReaderOptions &options, + const ReadCSVData &bind_data, const vector &column_ids, CSVSchema &file_schema); //! Constructor for new CSV Files, we must initialize the buffer manager and the state machine //! Path to this file - CSVFileScan(ClientContext &context, const string &file_path, CSVReaderOptions options, - const MultiFileOptions &file_options, const vector &names, const vector &types, - CSVSchema &file_schema, bool per_file_single_threaded, - shared_ptr buffer_manager = nullptr, bool fixed_schema = false); + CSVFileScan(ClientContext &context, const string &file_path, const CSVReaderOptions &options, idx_t file_idx, + const ReadCSVData &bind_data, const vector &column_ids, CSVSchema &file_schema, + bool per_file_single_threaded); - CSVFileScan(ClientContext &context, const string &file_name, const CSVReaderOptions &options, - const MultiFileOptions &file_options); + CSVFileScan(ClientContext &context, const string &file_name, const CSVReaderOptions &options); public: void SetStart(); void SetNamesAndTypes(const vector &names, const vector &types); public: - idx_t GetFileIndex() const { - return file_list_idx.GetIndex(); - } + const string &GetFileName() const; const vector &GetNames(); const vector &GetTypes(); + const vector &GetColumns(); void InitializeProjection(); void Finish(); - //! Initialize the actual names and types to be scanned from the file - void InitializeFileNamesTypes(); - - string GetReaderType() const override { - return "CSV"; + static unique_ptr StoreUnionReader(unique_ptr scan_p, idx_t file_idx) { + auto data = make_uniq(); + if (file_idx == 0) { + data->file_name = scan_p->file_path; + data->options = scan_p->options; + data->names = scan_p->names; + data->types = scan_p->types; + data->reader = std::move(scan_p); + } else { + data->file_name = scan_p->file_path; + data->options = std::move(scan_p->options); + data->names = std::move(scan_p->names); + data->types = std::move(scan_p->types); + } + data->options.auto_detect = false; + return data; } - bool UseCastMap() const override { - //! Whether or not to push casts into the cast map - return true; - } + //! Initialize the actual names and types to be scanned from the file + void InitializeFileNamesTypes(); public: + const string file_path; + //! File Index + idx_t file_idx; //! Buffer Manager for the CSV File shared_ptr buffer_manager; //! State Machine for this file @@ -80,6 +101,8 @@ class CSVFileScan : public BaseFileReader { //! Whether or not this is an on-disk file bool on_disk_file = true; + MultiFileReaderData reader_data; + vector file_types; //! Variables to handle projection pushdown @@ -91,16 +114,9 @@ class CSVFileScan : public BaseFileReader { CSVIterator start_iterator; - CSVValidator validator; - - //! The started tasks and finished tasks allow us to track if all reads of the CSV file have completed - //! Note that the "started_tasks" starts at one - this is so we can track when the scheduling of all tasks for this - //! file has completed When the scheduling is finished we increment `finished_tasks` by one as well - atomic started_tasks {1}; - atomic finished_tasks {0}; - private: vector names; vector types; + vector columns; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_option.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_option.hpp index 7e02f9ba5..ab4dbf2b0 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_option.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_option.hpp @@ -128,10 +128,6 @@ struct CSVOption { // NOLINT: work-around bug in clang-tidy std::string FormatValueInternal(const char &val) const { string char_val; - if (val == '\0') { - char_val = "(empty)"; - return char_val; - } char_val += val; return char_val; } diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_reader_options.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_reader_options.hpp index 3fe2dc613..4e0ee86fd 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_reader_options.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_reader_options.hpp @@ -16,8 +16,7 @@ #include "duckdb/common/types/value.hpp" #include "duckdb/common/case_insensitive_map.hpp" #include "duckdb/common/types.hpp" -#include "duckdb/common/multi_file/multi_file_options.hpp" -#include "duckdb/execution/operator/csv_scanner/set_columns.hpp" +#include "duckdb/common/multi_file_reader_options.hpp" namespace duckdb { @@ -36,8 +35,7 @@ struct DialectOptions { }; struct CSVReaderOptions { - CSVReaderOptions() { - } + CSVReaderOptions() {}; CSVReaderOptions(CSVOption single_byte_delimiter, const CSVOption &multi_byte_delimiter); //===--------------------------------------------------------------------===// // CommonCSVOptions @@ -77,10 +75,9 @@ struct CSVReaderOptions { //! If the names and types were set by the columns parameter bool columns_set = false; //! Types considered as candidates for auto-detection ordered by descending specificity (~ from high to low) - vector auto_type_candidates = { - LogicalType::VARCHAR, LogicalType::DOUBLE, LogicalType::BIGINT, - LogicalType::TIMESTAMP_TZ, LogicalType::TIMESTAMP, LogicalType::DATE, - LogicalType::TIME, LogicalType::BOOLEAN, LogicalType::SQLNULL}; + vector auto_type_candidates = {LogicalType::VARCHAR, LogicalType::DOUBLE, LogicalType::BIGINT, + LogicalType::TIMESTAMP, LogicalType::DATE, LogicalType::TIME, + LogicalType::BOOLEAN, LogicalType::SQLNULL}; //! In case the sniffer found a mismatch error from user defined types or dialect string sniffer_user_mismatch_error; //! In case the sniffer found a mismatch error from user defined types or dialect @@ -109,6 +106,8 @@ struct CSVReaderOptions { bool auto_detect = true; //! The file path of the CSV file to read string file_path; + //! Multi-file reader options + MultiFileReaderOptions file_options; //! Buffer Size (Parallel Scan) CSVOption buffer_size_option = CSVBuffer::ROWS_PER_BUFFER * max_line_size_default; //! Decimal separator when reading as numeric @@ -120,11 +119,8 @@ struct CSVReaderOptions { //! By default, our encoding is always UTF-8 string encoding = "utf-8"; - //! User defined parameters - map user_defined_parameters; - - //! Returns a list of user-defined parameters in string format - string GetUserDefinedParameters() const; + //! User defined parameters for the csv function concatenated on a string + string user_defined_parameters; //===--------------------------------------------------------------------===// // WriteCSVOptions @@ -143,6 +139,9 @@ struct CSVReaderOptions { //! If this reader is a multifile reader bool multi_file_reader = false; + void Serialize(Serializer &serializer) const; + static CSVReaderOptions Deserialize(Deserializer &deserializer); + void SetCompression(const string &compression); bool GetHeader() const; @@ -170,8 +169,8 @@ struct CSVReaderOptions { bool GetRFC4180() const; void SetRFC4180(bool rfc4180); - CSVOption GetSingleByteDelimiter() const; - CSVOption GetMultiByteDelimiter() const; + char GetSingleByteDelimiter() const; + string GetMultiByteDelimiter() const; //! Set an option that is supported by both reading and writing functions, called by //! the SetReadOption and SetWriteOption methods @@ -184,10 +183,9 @@ struct CSVReaderOptions { void SetWriteOption(const string &loption, const Value &value); void SetDateFormat(LogicalTypeId type, const string &format, bool read_format); void ToNamedParameters(named_parameter_map_t &out) const; - void FromNamedParameters(const named_parameter_map_t &in, ClientContext &context, MultiFileOptions &file_options); - void ParseOption(ClientContext &context, const string &key, const Value &val); + void FromNamedParameters(const named_parameter_map_t &in, ClientContext &context); //! Verify options are not conflicting - void Verify(MultiFileOptions &file_options); + void Verify(); string ToString(const string ¤t_file_path) const; //! If the type for column with idx i was manually set diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_validator.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_validator.hpp index 36f307e1a..20d031707 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_validator.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_validator.hpp @@ -42,17 +42,17 @@ struct ThreadLines { struct CSVValidator { CSVValidator() { } - //! Validate that all lines are good + //! Validate that all files are good void Verify() const; - //! Inserts line_info to a given thread index - void Insert(idx_t thread, ValidatorLine line_info); + //! Inserts line_info to a given thread index of a given file. + void Insert(idx_t file_idx, idx_t thread, ValidatorLine line_info); - string Print() const; + string Print(idx_t file_idx) const; private: - //! Thread lines for this file - ThreadLines thread_lines; + //! Per file thread lines. + vector per_file_thread_lines; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/global_csv_state.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/global_csv_state.hpp index ae33ffc96..5381071ab 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/global_csv_state.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/global_csv_state.hpp @@ -18,51 +18,69 @@ #include "duckdb/execution/operator/csv_scanner/csv_validator.hpp" namespace duckdb { -struct MultiFileBindData; //! CSV Global State is used in the CSV Reader Table Function, it controls what each thread struct CSVGlobalState : public GlobalTableFunctionState { -public: - CSVGlobalState(ClientContext &context_p, const CSVReaderOptions &options, idx_t total_file_count, - const MultiFileBindData &bind_data); + CSVGlobalState(ClientContext &context, const shared_ptr &buffer_manager_p, + const CSVReaderOptions &options, idx_t system_threads_p, const vector &files, + vector column_ids_p, const ReadCSVData &bind_data); ~CSVGlobalState() override { } //! Generates a CSV Scanner, with information regarding the piece of buffer it should be read. //! In case it returns a nullptr it means we are done reading these files. - void FinishScan(unique_ptr scanner); - unique_ptr Next(shared_ptr &file); - void FinishLaunchingTasks(CSVFileScan &scan); + unique_ptr Next(optional_ptr previous_scanner); - void FillRejectsTable(CSVFileScan &scan); - void FinishTask(CSVFileScan &scan); - void FinishFile(CSVFileScan &scan); + void FillRejectsTable() const; - //! Whether or not to read individual CSV files single-threaded - bool SingleThreadedRead() const { - return single_threaded; - } + void DecrementThread(); + + //! Returns Current Progress of this CSV Read + double GetProgress(const ReadCSVData &bind_data) const; + + //! Calculates the Max Threads that will be used by this CSV Reader + idx_t MaxThreads() const override; + + bool IsDone() const; private: //! Reference to the client context that created this scan ClientContext &context; - const MultiFileBindData &bind_data; + + vector> file_scans; + + //! Mutex to lock when getting next batch of bytes (Parallel Only) + mutable mutex main_mutex; + + //! Basically max number of threads in DuckDB + idx_t system_threads; + + //! Number of threads being used in this scanner + idx_t running_threads = 1; + //! The column ids to read + vector column_ids; string sniffer_mismatch_error; - bool initialized = false; + bool finished = false; + + const ReadCSVData &bind_data; + + CSVSchema file_schema; bool single_threaded = false; atomic scanner_idx; + atomic last_file_idx; shared_ptr current_buffer_in_use; + unordered_map threads_per_file; //! We hold information on the current scanner boundary CSVIterator current_boundary; - vector rejects_file_indexes; + CSVValidator validator; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner_boundary.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner_boundary.hpp index 93163c32f..da796d79e 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner_boundary.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner_boundary.hpp @@ -13,7 +13,7 @@ #include "duckdb/execution/operator/csv_scanner/csv_reader_options.hpp" #include "duckdb/execution/operator/csv_scanner/csv_state_machine.hpp" #include "duckdb/main/client_context.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/common/fast_mem.hpp" //! We all need boundaries every now and then, CSV Scans also need them diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp index 7d6d5b99f..ad77f6abc 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp @@ -54,6 +54,51 @@ struct DialectCandidates { unordered_map> escape_candidates_map; }; +//! This represents the data related to columns that have been set by the user +//! e.g., from a copy command +struct SetColumns { + SetColumns(const vector *types_p, const vector *names_p) : types(types_p), names(names_p) { + if (!types) { + D_ASSERT(!types && !names); + } else { + D_ASSERT(types->size() == names->size()); + } + } + SetColumns() {}; + //! Return Types that were detected + const vector *types = nullptr; + //! Column Names that were detected + const vector *names = nullptr; + //! If columns are set + bool IsSet() const; + //! How many columns + idx_t Size() const; + //! Helper function that checks if candidate is acceptable based on the number of columns it produces + inline bool IsCandidateUnacceptable(const idx_t num_cols, bool null_padding, bool ignore_errors, + bool last_value_always_empty) const { + if (!IsSet() || ignore_errors) { + // We can't say its unacceptable if it's not set or if we ignore errors + return false; + } + idx_t size = Size(); + // If the columns are set and there is a mismatch with the expected number of columns, with null_padding and + // ignore_errors not set, we don't have a suitable candidate. + // Note that we compare with max_columns_found + 1, because some broken files have the behaviour where two + // columns are represented as: | col 1 | col_2 | + if (num_cols == size || num_cols == size + last_value_always_empty) { + // Good Candidate + return false; + } + // if we detected more columns than we have set, it's all good because we can null-pad them + if (null_padding && num_cols > size) { + return false; + } + + // Unacceptable + return true; + } +}; + //! Struct used to know if we have a date or timestamp type already identified in this CSV File struct HasType { bool date = false; @@ -63,9 +108,8 @@ struct HasType { //! Sniffer that detects Header, Dialect and Types of CSV Files class CSVSniffer { public: - explicit CSVSniffer(CSVReaderOptions &options_p, const MultiFileOptions &file_options, - shared_ptr buffer_manager_p, CSVStateMachineCache &state_machine_cache, - bool default_null_to_varchar = true); + explicit CSVSniffer(CSVReaderOptions &options_p, shared_ptr buffer_manager_p, + CSVStateMachineCache &state_machine_cache, bool default_null_to_varchar = true); //! Main method that sniffs the CSV file, returns the types, names and options as a result //! CSV Sniffing consists of five steps: @@ -101,13 +145,10 @@ class CSVSniffer { CSVStateMachineCache &state_machine_cache; //! Highest number of columns found idx_t max_columns_found = 0; - idx_t max_columns_found_error = 0; //! Current Candidates being considered vector> candidates; //! Reference to original CSV Options, it will be modified as a result of the sniffer. CSVReaderOptions &options; - //! The multi-file reader options - const MultiFileOptions &file_options; //! Buffer being used on sniffer shared_ptr buffer_manager; //! Information regarding columns that were set by user/query @@ -195,8 +236,7 @@ class CSVSniffer { DetectHeaderInternal(ClientContext &context, vector &best_header_row, CSVStateMachine &state_machine, const SetColumns &set_columns, unordered_map> &best_sql_types_candidates_per_column_idx, - CSVReaderOptions &options, const MultiFileOptions &file_options, - CSVErrorHandler &error_handler); + CSVReaderOptions &options, CSVErrorHandler &error_handler); vector names; //! If the file only has a header bool single_row_file = false; diff --git a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/string_value_scanner.hpp b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/string_value_scanner.hpp index 123ece886..9e056a3dc 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/string_value_scanner.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/string_value_scanner.hpp @@ -195,8 +195,6 @@ class StringValueResult : public ScannerResult { bool projecting_columns = false; idx_t chunk_col_id = 0; - bool icu_loaded = false; - //! We must ensure that we keep the buffers alive until processing the query result unordered_map> buffer_handles; @@ -293,8 +291,7 @@ class StringValueScanner : public BaseScanner { void Flush(DataChunk &insert_chunk); //! Function that creates and returns a non-boundary CSV Scanner, can be used for internal csv reading. - static unique_ptr GetCSVScanner(ClientContext &context, CSVReaderOptions &options, - const MultiFileOptions &file_options); + static unique_ptr GetCSVScanner(ClientContext &context, CSVReaderOptions &options); bool FinishedIterator() const; diff --git a/src/duckdb/src/include/duckdb/execution/operator/helper/physical_create_secret.hpp b/src/duckdb/src/include/duckdb/execution/operator/helper/physical_create_secret.hpp index 8bc046fa6..0a303b2df 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/helper/physical_create_secret.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/helper/physical_create_secret.hpp @@ -9,7 +9,7 @@ #pragma once #include "duckdb/execution/physical_operator.hpp" -#include "duckdb/main/secret/secret.hpp" +#include "duckdb/parser/parsed_data/create_secret_info.hpp" namespace duckdb { @@ -19,12 +19,12 @@ class PhysicalCreateSecret : public PhysicalOperator { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::CREATE_SECRET; public: - PhysicalCreateSecret(CreateSecretInput input_p, idx_t estimated_cardinality) + PhysicalCreateSecret(CreateSecretInfo info_p, idx_t estimated_cardinality) : PhysicalOperator(PhysicalOperatorType::CREATE_SECRET, {LogicalType::BOOLEAN}, estimated_cardinality), - create_input(std::move(input_p)) { + info(std::move(info_p)) { } - CreateSecretInput create_input; + CreateSecretInfo info; public: // Source interface diff --git a/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp b/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp index 023b96a0f..46b1e38c2 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp @@ -21,6 +21,7 @@ class PhysicalExecute : public PhysicalOperator { explicit PhysicalExecute(PhysicalOperator &plan); PhysicalOperator &plan; + unique_ptr owned_plan; shared_ptr prepared; public: diff --git a/src/duckdb/src/include/duckdb/execution/operator/helper/physical_verify_vector.hpp b/src/duckdb/src/include/duckdb/execution/operator/helper/physical_verify_vector.hpp index 52deb9eb9..ce774c554 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/helper/physical_verify_vector.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/helper/physical_verify_vector.hpp @@ -10,7 +10,6 @@ #include "duckdb/execution/physical_operator.hpp" #include "duckdb/planner/expression.hpp" -#include "duckdb/common/enums/debug_vector_verification.hpp" namespace duckdb { @@ -37,9 +36,7 @@ class PhysicalVerifyVector : public PhysicalOperator { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::VERIFY_VECTOR; public: - explicit PhysicalVerifyVector(PhysicalOperator &child, DebugVectorVerification verification); - - DebugVectorVerification verification; + explicit PhysicalVerifyVector(unique_ptr child); public: unique_ptr GetOperatorState(ExecutionContext &context) const override; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_asof_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_asof_join.hpp index a304fd83e..467eafe6e 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_asof_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_asof_join.hpp @@ -19,7 +19,7 @@ class PhysicalAsOfJoin : public PhysicalComparisonJoin { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::ASOF_JOIN; public: - PhysicalAsOfJoin(LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right); + PhysicalAsOfJoin(LogicalComparisonJoin &op, unique_ptr left, unique_ptr right); vector join_key_types; vector null_sensitive; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_blockwise_nl_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_blockwise_nl_join.hpp index 9622ab8d0..e6ec48410 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_blockwise_nl_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_blockwise_nl_join.hpp @@ -20,7 +20,7 @@ class PhysicalBlockwiseNLJoin : public PhysicalJoin { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::BLOCKWISE_NL_JOIN; public: - PhysicalBlockwiseNLJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, + PhysicalBlockwiseNLJoin(LogicalOperator &op, unique_ptr left, unique_ptr right, unique_ptr condition, JoinType join_type, idx_t estimated_cardinality); unique_ptr condition; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp index b67628fbf..8091bb3c5 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp @@ -19,8 +19,8 @@ class PhysicalCrossProduct : public CachingPhysicalOperator { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::CROSS_PRODUCT; public: - PhysicalCrossProduct(vector types, PhysicalOperator &left, PhysicalOperator &right, - idx_t estimated_cardinality); + PhysicalCrossProduct(vector types, unique_ptr left, + unique_ptr right, idx_t estimated_cardinality); public: // Operator Interface diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_delim_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_delim_join.hpp index 56091ea73..f12fe76ec 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_delim_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_delim_join.hpp @@ -18,12 +18,12 @@ class PhysicalHashAggregate; //! PhysicalColumnDataScan in the other side. Implementations are PhysicalLeftDelimJoin and PhysicalRightDelimJoin class PhysicalDelimJoin : public PhysicalOperator { public: - PhysicalDelimJoin(PhysicalOperatorType type, vector types, PhysicalOperator &original_join, - PhysicalOperator &distinct, const vector> &delim_scans, - idx_t estimated_cardinality, optional_idx delim_idx); + PhysicalDelimJoin(PhysicalOperatorType type, vector types, unique_ptr original_join, + vector> delim_scans, idx_t estimated_cardinality, + optional_idx delim_idx); - PhysicalOperator &join; - PhysicalHashAggregate &distinct; + unique_ptr join; + unique_ptr distinct; vector> delim_scans; optional_idx delim_idx; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp index 893e8e383..849423a25 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp @@ -28,12 +28,12 @@ class PhysicalHashJoin : public PhysicalComparisonJoin { }; public: - PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, vector cond, - JoinType join_type, const vector &left_projection_map, + PhysicalHashJoin(LogicalOperator &op, unique_ptr left, unique_ptr right, + vector cond, JoinType join_type, const vector &left_projection_map, const vector &right_projection_map, vector delim_types, idx_t estimated_cardinality, unique_ptr pushdown_info); - PhysicalHashJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, vector cond, - JoinType join_type, idx_t estimated_cardinality); + PhysicalHashJoin(LogicalOperator &op, unique_ptr left, unique_ptr right, + vector cond, JoinType join_type, idx_t estimated_cardinality); //! Initialize HT for this operator unique_ptr InitializeHashTable(ClientContext &context) const; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_iejoin.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_iejoin.hpp index b2c2f7a4a..5c0183726 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_iejoin.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_iejoin.hpp @@ -20,7 +20,7 @@ class PhysicalIEJoin : public PhysicalRangeJoin { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::IE_JOIN; public: - PhysicalIEJoin(LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right, + PhysicalIEJoin(LogicalComparisonJoin &op, unique_ptr left, unique_ptr right, vector cond, JoinType join_type, idx_t estimated_cardinality); vector join_key_types; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_left_delim_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_left_delim_join.hpp index 1d0a7ecff..a051aa63e 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_left_delim_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_left_delim_join.hpp @@ -19,9 +19,9 @@ class PhysicalLeftDelimJoin : public PhysicalDelimJoin { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::LEFT_DELIM_JOIN; public: - PhysicalLeftDelimJoin(PhysicalPlanGenerator &planner, vector types, PhysicalOperator &original_join, - PhysicalOperator &distinct, const vector> &delim_scans, - idx_t estimated_cardinality, optional_idx delim_idx); + PhysicalLeftDelimJoin(vector types, unique_ptr original_join, + vector> delim_scans, idx_t estimated_cardinality, + optional_idx delim_idx); public: unique_ptr GetGlobalSinkState(ClientContext &context) const override; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_nested_loop_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_nested_loop_join.hpp index 00a1a9a29..85fef3ff0 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_nested_loop_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_nested_loop_join.hpp @@ -18,7 +18,7 @@ class PhysicalNestedLoopJoin : public PhysicalComparisonJoin { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::NESTED_LOOP_JOIN; public: - PhysicalNestedLoopJoin(LogicalOperator &op, PhysicalOperator &left, PhysicalOperator &right, + PhysicalNestedLoopJoin(LogicalOperator &op, unique_ptr left, unique_ptr right, vector cond, JoinType join_type, idx_t estimated_cardinality); public: diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_piecewise_merge_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_piecewise_merge_join.hpp index 05080e326..6164f83fe 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_piecewise_merge_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_piecewise_merge_join.hpp @@ -22,8 +22,9 @@ class PhysicalPiecewiseMergeJoin : public PhysicalRangeJoin { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::PIECEWISE_MERGE_JOIN; public: - PhysicalPiecewiseMergeJoin(LogicalComparisonJoin &op, PhysicalOperator &left, PhysicalOperator &right, - vector cond, JoinType join_type, idx_t estimated_cardinality); + PhysicalPiecewiseMergeJoin(LogicalComparisonJoin &op, unique_ptr left, + unique_ptr right, vector cond, JoinType join_type, + idx_t estimated_cardinality); vector join_key_types; vector lhs_orders; diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp index 6f5f13032..409229ef0 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp @@ -19,8 +19,8 @@ class PhysicalPositionalJoin : public PhysicalOperator { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::POSITIONAL_JOIN; public: - PhysicalPositionalJoin(vector types, PhysicalOperator &left, PhysicalOperator &right, - idx_t estimated_cardinality); + PhysicalPositionalJoin(vector types, unique_ptr left, + unique_ptr right, idx_t estimated_cardinality); public: // Operator Interface diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_range_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_range_join.hpp index 802863731..23b2084f5 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_range_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_range_join.hpp @@ -92,8 +92,8 @@ class PhysicalRangeJoin : public PhysicalComparisonJoin { }; public: - PhysicalRangeJoin(LogicalComparisonJoin &op, PhysicalOperatorType type, PhysicalOperator &left, - PhysicalOperator &right, vector cond, JoinType join_type, + PhysicalRangeJoin(LogicalComparisonJoin &op, PhysicalOperatorType type, unique_ptr left, + unique_ptr right, vector cond, JoinType join_type, idx_t estimated_cardinality); // Projection mappings diff --git a/src/duckdb/src/include/duckdb/execution/operator/join/physical_right_delim_join.hpp b/src/duckdb/src/include/duckdb/execution/operator/join/physical_right_delim_join.hpp index 3aeba3669..5393df4be 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/join/physical_right_delim_join.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/join/physical_right_delim_join.hpp @@ -19,9 +19,9 @@ class PhysicalRightDelimJoin : public PhysicalDelimJoin { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::RIGHT_DELIM_JOIN; public: - PhysicalRightDelimJoin(PhysicalPlanGenerator &planner, vector types, PhysicalOperator &original_join, - PhysicalOperator &distinct, const vector> &delim_scans, - idx_t estimated_cardinality, optional_idx delim_idx); + PhysicalRightDelimJoin(vector types, unique_ptr original_join, + vector> delim_scans, idx_t estimated_cardinality, + optional_idx delim_idx); public: unique_ptr GetGlobalSinkState(ClientContext &context) const override; diff --git a/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_rejects_table.hpp b/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_rejects_table.hpp index 2cae7e3ce..7b88e0de8 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_rejects_table.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_rejects_table.hpp @@ -1,11 +1,3 @@ -//===----------------------------------------------------------------------===// -// DuckDB -// -// duckdb/execution/operator/persistent/csv_rejects_table.hpp -// -// -//===----------------------------------------------------------------------===// - #pragma once #include "duckdb/storage/object_cache.hpp" diff --git a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_copy_to_file.hpp b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_copy_to_file.hpp index adb2f4722..56f8a43a5 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_copy_to_file.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_copy_to_file.hpp @@ -30,7 +30,6 @@ class PhysicalBatchCopyToFile : public PhysicalOperator { string file_path; bool use_tmp_file; CopyFunctionReturnType return_type; - bool write_empty_file; public: // Source interface diff --git a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp index 6e156fcc4..57c349280 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp @@ -19,21 +19,28 @@ class PhysicalBatchInsert : public PhysicalOperator { public: //! INSERT INTO PhysicalBatchInsert(vector types, TableCatalogEntry &table, + physical_index_vector_t column_index_map, vector> bound_defaults, vector> bound_constraints, idx_t estimated_cardinality); //! CREATE TABLE AS PhysicalBatchInsert(LogicalOperator &op, SchemaCatalogEntry &schema, unique_ptr info, idx_t estimated_cardinality); + //! The map from insert column index to table column index + physical_index_vector_t column_index_map; //! The table to insert into optional_ptr insert_table; //! The insert types vector insert_types; + //! The default expressions of the columns for which no value is provided + vector> bound_defaults; //! The bound constraints for the table vector> bound_constraints; //! Table schema, in case of CREATE TABLE AS optional_ptr schema; //! Create table info, in case of CREATE TABLE AS unique_ptr info; + // Which action to perform on conflict + OnConflictAction action_type; public: // Source interface diff --git a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp index ab5c71a6d..6201e671b 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp @@ -18,15 +18,6 @@ namespace duckdb { -struct CopyToFileInfo { - explicit CopyToFileInfo(string file_path_p) : file_path(std::move(file_path_p)) { - } - - string file_path; - unique_ptr file_stats; - Value partition_keys; -}; - //! Copy the contents of a query into a table class PhysicalCopyToFile : public PhysicalOperator { public: @@ -51,14 +42,12 @@ class PhysicalCopyToFile : public PhysicalOperator { bool partition_output; bool write_partition_columns; - bool write_empty_file; vector partition_columns; vector names; vector expected_types; public: // Source interface - unique_ptr GetGlobalSourceState(ClientContext &context) const override; SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override; bool IsSource() const override { @@ -71,7 +60,6 @@ class PhysicalCopyToFile : public PhysicalOperator { SinkCombineResultType Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const override; SinkFinalizeType Finalize(Pipeline &pipeline, Event &event, ClientContext &context, OperatorSinkFinalizeInput &input) const override; - SinkFinalizeType FinalizeInternal(ClientContext &context, GlobalSinkState &gstate) const; unique_ptr GetLocalSinkState(ExecutionContext &context) const override; unique_ptr GetGlobalSinkState(ClientContext &context) const override; @@ -87,18 +75,13 @@ class PhysicalCopyToFile : public PhysicalOperator { return per_thread_output || partition_output || parallel; } -public: static void MoveTmpFile(ClientContext &context, const string &tmp_file_path); static string GetNonTmpFile(ClientContext &context, const string &tmp_file_path); string GetTrimmedPath(ClientContext &context) const; - static void ReturnStatistics(DataChunk &chunk, idx_t row_idx, CopyToFileInfo &written_file_info); - private: unique_ptr CreateFileState(ClientContext &context, GlobalSinkState &sink, StorageLockKey &global_lock) const; - void WriteRotateInternal(ExecutionContext &context, GlobalSinkState &global_state, - const std::function &fun) const; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_export.hpp b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_export.hpp index 214487dac..fd7f4981f 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_export.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_export.hpp @@ -14,7 +14,6 @@ #include "duckdb/function/copy_function.hpp" #include "duckdb/parser/parsed_data/copy_info.hpp" #include "duckdb/parser/parsed_data/exported_table_data.hpp" -#include "duckdb/catalog/catalog_entry_map.hpp" namespace duckdb { diff --git a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp index 9a818de74..ccb113c4f 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp @@ -16,7 +16,6 @@ #include "duckdb/storage/table/append_state.hpp" #include "duckdb/catalog/catalog_entry/duck_table_entry.hpp" #include "duckdb/storage/table/delete_state.hpp" -#include "duckdb/storage/optimistic_data_writer.hpp" namespace duckdb { @@ -40,6 +39,7 @@ class InsertLocalState : public LocalSinkState { public: public: InsertLocalState(ClientContext &context, const vector &types, + const vector> &bound_defaults, const vector> &bound_constraints); public: @@ -47,12 +47,14 @@ class InsertLocalState : public LocalSinkState { TableDeleteState &GetDeleteState(DataTable &table, TableCatalogEntry &table_ref, ClientContext &context); public: + //! The chunk that ends up getting inserted + DataChunk insert_chunk; //! The chunk containing the tuples that become an update (if DO UPDATE) DataChunk update_chunk; + ExpressionExecutor default_executor; TableAppendState local_append_state; - //! An index to the optimistic row group collection vector of the local table storage for this transaction. - PhysicalIndex collection_index; - unique_ptr optimistic_writer; + unique_ptr local_collection; + optional_ptr writer; // Rows that have been updated by a DO UPDATE conflict unordered_set updated_rows; idx_t update_count = 0; @@ -71,8 +73,8 @@ class PhysicalInsert : public PhysicalOperator { public: //! INSERT INTO - PhysicalInsert(vector types, TableCatalogEntry &table, - vector> bound_constraints, + PhysicalInsert(vector types, TableCatalogEntry &table, physical_index_vector_t column_index_map, + vector> bound_defaults, vector> bound_constraints, vector> set_expressions, vector set_columns, vector set_types, idx_t estimated_cardinality, bool return_chunk, bool parallel, OnConflictAction action_type, unique_ptr on_conflict_condition, @@ -82,10 +84,14 @@ class PhysicalInsert : public PhysicalOperator { PhysicalInsert(LogicalOperator &op, SchemaCatalogEntry &schema, unique_ptr info, idx_t estimated_cardinality, bool parallel); + //! The map from insert column index to table column index + physical_index_vector_t column_index_map; //! The table to insert into optional_ptr insert_table; //! The insert types vector insert_types; + //! The default expressions of the columns for which no value is provided + vector> bound_defaults; //! The bound constraints for the table vector> bound_constraints; //! If the returning statement is present, return the whole chunk @@ -152,7 +158,11 @@ class PhysicalInsert : public PhysicalOperator { } public: - static void GetInsertInfo(const BoundCreateTableInfo &info, vector &insert_types); + static void GetInsertInfo(const BoundCreateTableInfo &info, vector &insert_types, + vector> &bound_defaults); + static void ResolveDefaults(const TableCatalogEntry &table, DataChunk &chunk, + const physical_index_vector_t &column_index_map, + ExpressionExecutor &defaults_executor, DataChunk &result); protected: void CombineExistingAndInsertTuples(DataChunk &result, DataChunk &scan_chunk, DataChunk &input_chunk, @@ -161,7 +171,7 @@ class PhysicalInsert : public PhysicalOperator { void CreateUpdateChunk(ExecutionContext &context, DataChunk &chunk, TableCatalogEntry &table, Vector &row_ids, DataChunk &result) const; idx_t OnConflictHandling(TableCatalogEntry &table, ExecutionContext &context, InsertGlobalState &gstate, - InsertLocalState &lstate, DataChunk &insert_chunk) const; + InsertLocalState &lstate) const; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/operator/projection/physical_pivot.hpp b/src/duckdb/src/include/duckdb/execution/operator/projection/physical_pivot.hpp index 037db52a1..badb073d8 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/projection/physical_pivot.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/projection/physical_pivot.hpp @@ -18,7 +18,7 @@ namespace duckdb { //! PhysicalPivot implements the physical PIVOT operation class PhysicalPivot : public PhysicalOperator { public: - PhysicalPivot(vector types, PhysicalOperator &child, BoundPivotInfo bound_pivot); + PhysicalPivot(vector types, unique_ptr child, BoundPivotInfo bound_pivot); BoundPivotInfo bound_pivot; //! The map for pivot value -> column index diff --git a/src/duckdb/src/include/duckdb/execution/operator/scan/physical_positional_scan.hpp b/src/duckdb/src/include/duckdb/execution/operator/scan/physical_positional_scan.hpp index c0aee1f95..2a39fb239 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/scan/physical_positional_scan.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/scan/physical_positional_scan.hpp @@ -22,10 +22,11 @@ class PhysicalPositionalScan : public PhysicalOperator { public: //! Regular Table Scan - PhysicalPositionalScan(vector types, PhysicalOperator &left, PhysicalOperator &right); + PhysicalPositionalScan(vector types, unique_ptr left, + unique_ptr right); //! The child table functions - vector> child_tables; + vector> child_tables; public: bool Equals(const PhysicalOperator &other) const override; diff --git a/src/duckdb/src/include/duckdb/execution/operator/scan/physical_table_scan.hpp b/src/duckdb/src/include/duckdb/execution/operator/scan/physical_table_scan.hpp index 88aa76c46..45ac1e34c 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/scan/physical_table_scan.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/scan/physical_table_scan.hpp @@ -27,7 +27,7 @@ class PhysicalTableScan : public PhysicalOperator { PhysicalTableScan(vector types, TableFunction function, unique_ptr bind_data, vector returned_types, vector column_ids, vector projection_ids, vector names, unique_ptr table_filters, idx_t estimated_cardinality, - ExtraOperatorInfo extra_info, vector parameters, virtual_column_map_t virtual_columns); + ExtraOperatorInfo extra_info, vector parameters); //! The table function TableFunction function; @@ -50,8 +50,6 @@ class PhysicalTableScan : public PhysicalOperator { vector parameters; //! Contains a reference to dynamically generated table filters (through e.g. a join up in the tree) shared_ptr dynamic_filters; - //! Virtual columns - virtual_column_map_t virtual_columns; public: string GetName() const override; @@ -76,9 +74,6 @@ class PhysicalTableScan : public PhysicalOperator { bool SupportsPartitioning(const OperatorPartitionInfo &partition_info) const override; ProgressData GetProgress(ClientContext &context, GlobalSourceState &gstate) const override; - - InsertionOrderPreservingMap ExtraSourceParams(GlobalSourceState &gstate, - LocalSourceState &lstate) const override; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/operator/set/physical_cte.hpp b/src/duckdb/src/include/duckdb/execution/operator/set/physical_cte.hpp index 1826b18c6..3ce30ce67 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/set/physical_cte.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/set/physical_cte.hpp @@ -20,8 +20,8 @@ class PhysicalCTE : public PhysicalOperator { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::CTE; public: - PhysicalCTE(string ctename, idx_t table_index, vector types, PhysicalOperator &top, - PhysicalOperator &bottom, idx_t estimated_cardinality); + PhysicalCTE(string ctename, idx_t table_index, vector types, unique_ptr top, + unique_ptr bottom, idx_t estimated_cardinality); ~PhysicalCTE() override; vector> cte_scans; diff --git a/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp b/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp index 6169d811b..37292df9d 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp @@ -10,7 +10,6 @@ #include "duckdb/common/types/column/column_data_collection.hpp" #include "duckdb/execution/physical_operator.hpp" -#include "duckdb/planner/expression/bound_aggregate_expression.hpp" namespace duckdb { @@ -22,30 +21,17 @@ class PhysicalRecursiveCTE : public PhysicalOperator { public: PhysicalRecursiveCTE(string ctename, idx_t table_index, vector types, bool union_all, - PhysicalOperator &top, PhysicalOperator &bottom, idx_t estimated_cardinality); + unique_ptr top, unique_ptr bottom, + idx_t estimated_cardinality); ~PhysicalRecursiveCTE() override; string ctename; idx_t table_index; - // Flag if recurring table is referenced, if not we do not copy ht into ColumnDataCollection - bool ref_recurring; + bool union_all; shared_ptr working_table; shared_ptr recursive_meta_pipeline; - //===--------------------------------------------------------------------===// - // Additionally required for using-key recursive CTE to normal CTE. - //===--------------------------------------------------------------------===// - bool using_key = false; - // Contains the result of the key variant - shared_ptr recurring_table; - // Contains the types of the payload and key columns. - vector payload_types, distinct_types; - // Contains the payload and key indices - vector payload_idx, distinct_idx; - // Contains the aggregates for the payload - vector> payload_aggregates; - public: // Source interface SourceResultType GetData(ExecutionContext &context, DataChunk &chunk, OperatorSourceInput &input) const override; diff --git a/src/duckdb/src/include/duckdb/execution/operator/set/physical_union.hpp b/src/duckdb/src/include/duckdb/execution/operator/set/physical_union.hpp index 54f1b81ca..ffb87d6cd 100644 --- a/src/duckdb/src/include/duckdb/execution/operator/set/physical_union.hpp +++ b/src/duckdb/src/include/duckdb/execution/operator/set/physical_union.hpp @@ -17,7 +17,7 @@ class PhysicalUnion : public PhysicalOperator { static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::UNION; public: - PhysicalUnion(vector types, PhysicalOperator &top, PhysicalOperator &bottom, + PhysicalUnion(vector types, unique_ptr top, unique_ptr bottom, idx_t estimated_cardinality, bool allow_out_of_order); bool allow_out_of_order; diff --git a/src/duckdb/src/include/duckdb/execution/physical_operator.hpp b/src/duckdb/src/include/duckdb/execution/physical_operator.hpp index 6067a0ccf..50529d594 100644 --- a/src/duckdb/src/include/duckdb/execution/physical_operator.hpp +++ b/src/duckdb/src/include/duckdb/execution/physical_operator.hpp @@ -45,14 +45,10 @@ class PhysicalOperator { virtual ~PhysicalOperator() { } - // Delete copy constructors. - PhysicalOperator(const PhysicalOperator &other) = delete; - PhysicalOperator &operator=(const PhysicalOperator &) = delete; - //! The physical operator type PhysicalOperatorType type; //! The set of children of the operator - vector> children; + vector> children; //! The types returned by this physical operator vector types; //! The estimated cardinality of this physical operator @@ -152,11 +148,6 @@ class PhysicalOperator { return source_progress; } - virtual InsertionOrderPreservingMap ExtraSourceParams(GlobalSourceState &gstate, - LocalSourceState &lstate) const { - return InsertionOrderPreservingMap(); - } - public: // Sink interface diff --git a/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp b/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp index 201f65ef7..e728012bf 100644 --- a/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp +++ b/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp @@ -21,46 +21,8 @@ namespace duckdb { class ClientContext; class ColumnDataCollection; -class PhysicalPlan { -public: - explicit PhysicalPlan(Allocator &allocator) : arena(allocator) {}; - - ~PhysicalPlan() { - // Call the destructor of each physical operator. - for (auto &op : ops) { - auto &op_ref = op.get(); - op_ref.~PhysicalOperator(); - } - } - -public: - template - PhysicalOperator &Make(ARGS &&... args) { - static_assert(std::is_base_of::value, "T must be a physical operator"); - auto mem = arena.AllocateAligned(sizeof(T)); - auto ptr = new (mem) T(std::forward(args)...); - ops.push_back(*ptr); - return *ptr; - } - - PhysicalOperator &Root() { - D_ASSERT(root); - return *root; - } - void SetRoot(PhysicalOperator &op) { - root = op; - } - -private: - //! The arena allocator storing the physical operator memory. - ArenaAllocator arena; - //! References to the physical operators. - vector> ops; - //! The root of the physical plan. - optional_ptr root; -}; - -//! The physical plan generator generates a physical execution plan from a logical query plan. +//! The physical plan generator generates a physical execution plan from a +//! logical query plan class PhysicalPlanGenerator { public: explicit PhysicalPlanGenerator(ClientContext &context); @@ -70,18 +32,13 @@ class PhysicalPlanGenerator { //! Recursive CTEs require at least one ChunkScan, referencing the working_table. //! This data structure is used to establish it. unordered_map> recursive_cte_tables; - //! Used to reference the recurring tables - unordered_map> recurring_cte_tables; //! Materialized CTE ids must be collected. unordered_map>> materialized_ctes; - //! The index for duplicate eliminated joins. - idx_t delim_index = 0; public: - //! Creates and returns the physical plan from the logical operator. - //! Performs a verification pass. - unique_ptr Plan(unique_ptr logical); - PhysicalOperator &CreatePlan(LogicalOperator &op); + //! Creates a plan from the logical operator. This involves resolving column bindings and generating physical + //! operator nodes. + unique_ptr CreatePlan(unique_ptr logical); //! Whether or not we can (or should) use a batch-index based operator for executing the given sink static bool UseBatchIndex(ClientContext &context, PhysicalOperator &plan); @@ -90,75 +47,68 @@ class PhysicalPlanGenerator { //! The order preservation type of the given operator decided by recursively looking at its children static OrderPreservationType OrderPreservationRecursive(PhysicalOperator &op); - template - PhysicalOperator &Make(ARGS &&... args) { - return physical_plan->Make(std::forward(args)...); - } - -public: - PhysicalOperator &ResolveDefaultsProjection(LogicalInsert &op, PhysicalOperator &child); - protected: - PhysicalOperator &CreatePlan(LogicalAggregate &op); - PhysicalOperator &CreatePlan(LogicalAnyJoin &op); - PhysicalOperator &CreatePlan(LogicalColumnDataGet &op); - PhysicalOperator &CreatePlan(LogicalComparisonJoin &op); - PhysicalOperator &CreatePlan(LogicalCopyDatabase &op); - PhysicalOperator &CreatePlan(LogicalCreate &op); - PhysicalOperator &CreatePlan(LogicalCreateTable &op); - PhysicalOperator &CreatePlan(LogicalCreateIndex &op); - PhysicalOperator &CreatePlan(LogicalCreateSecret &op); - PhysicalOperator &CreatePlan(LogicalCrossProduct &op); - PhysicalOperator &CreatePlan(LogicalDelete &op); - PhysicalOperator &CreatePlan(LogicalDelimGet &op); - PhysicalOperator &CreatePlan(LogicalDistinct &op); - PhysicalOperator &CreatePlan(LogicalDummyScan &expr); - PhysicalOperator &CreatePlan(LogicalEmptyResult &op); - PhysicalOperator &CreatePlan(LogicalExpressionGet &op); - PhysicalOperator &CreatePlan(LogicalExport &op); - PhysicalOperator &CreatePlan(LogicalFilter &op); - PhysicalOperator &CreatePlan(LogicalGet &op); - PhysicalOperator &CreatePlan(LogicalLimit &op); - PhysicalOperator &CreatePlan(LogicalOrder &op); - PhysicalOperator &CreatePlan(LogicalTopN &op); - PhysicalOperator &CreatePlan(LogicalPositionalJoin &op); - PhysicalOperator &CreatePlan(LogicalProjection &op); - PhysicalOperator &CreatePlan(LogicalInsert &op); - PhysicalOperator &CreatePlan(LogicalCopyToFile &op); - PhysicalOperator &CreatePlan(LogicalExplain &op); - PhysicalOperator &CreatePlan(LogicalSetOperation &op); - PhysicalOperator &CreatePlan(LogicalUpdate &op); - PhysicalOperator &CreatePlan(LogicalPrepare &expr); - PhysicalOperator &CreatePlan(LogicalWindow &expr); - PhysicalOperator &CreatePlan(LogicalExecute &op); - PhysicalOperator &CreatePlan(LogicalPragma &op); - PhysicalOperator &CreatePlan(LogicalSample &op); - PhysicalOperator &CreatePlan(LogicalSet &op); - PhysicalOperator &CreatePlan(LogicalReset &op); - PhysicalOperator &CreatePlan(LogicalSimple &op); - PhysicalOperator &CreatePlan(LogicalVacuum &op); - PhysicalOperator &CreatePlan(LogicalUnnest &op); - PhysicalOperator &CreatePlan(LogicalRecursiveCTE &op); - PhysicalOperator &CreatePlan(LogicalMaterializedCTE &op); - PhysicalOperator &CreatePlan(LogicalCTERef &op); - PhysicalOperator &CreatePlan(LogicalPivot &op); - - PhysicalOperator &PlanAsOfJoin(LogicalComparisonJoin &op); - PhysicalOperator &PlanComparisonJoin(LogicalComparisonJoin &op); - PhysicalOperator &PlanDelimJoin(LogicalComparisonJoin &op); - PhysicalOperator &ExtractAggregateExpressions(PhysicalOperator &child, vector> &expressions, - vector> &groups); - -private: - ClientContext &context; - unique_ptr physical_plan; + unique_ptr CreatePlan(LogicalOperator &op); + + unique_ptr CreatePlan(LogicalAggregate &op); + unique_ptr CreatePlan(LogicalAnyJoin &op); + unique_ptr CreatePlan(LogicalColumnDataGet &op); + unique_ptr CreatePlan(LogicalComparisonJoin &op); + unique_ptr CreatePlan(LogicalCopyDatabase &op); + unique_ptr CreatePlan(LogicalCreate &op); + unique_ptr CreatePlan(LogicalCreateTable &op); + unique_ptr CreatePlan(LogicalCreateIndex &op); + unique_ptr CreatePlan(LogicalCreateSecret &op); + unique_ptr CreatePlan(LogicalCrossProduct &op); + unique_ptr CreatePlan(LogicalDelete &op); + unique_ptr CreatePlan(LogicalDelimGet &op); + unique_ptr CreatePlan(LogicalDistinct &op); + unique_ptr CreatePlan(LogicalDummyScan &expr); + unique_ptr CreatePlan(LogicalEmptyResult &op); + unique_ptr CreatePlan(LogicalExpressionGet &op); + unique_ptr CreatePlan(LogicalExport &op); + unique_ptr CreatePlan(LogicalFilter &op); + unique_ptr CreatePlan(LogicalGet &op); + unique_ptr CreatePlan(LogicalLimit &op); + unique_ptr CreatePlan(LogicalOrder &op); + unique_ptr CreatePlan(LogicalTopN &op); + unique_ptr CreatePlan(LogicalPositionalJoin &op); + unique_ptr CreatePlan(LogicalProjection &op); + unique_ptr CreatePlan(LogicalInsert &op); + unique_ptr CreatePlan(LogicalCopyToFile &op); + unique_ptr CreatePlan(LogicalExplain &op); + unique_ptr CreatePlan(LogicalSetOperation &op); + unique_ptr CreatePlan(LogicalUpdate &op); + unique_ptr CreatePlan(LogicalPrepare &expr); + unique_ptr CreatePlan(LogicalWindow &expr); + unique_ptr CreatePlan(LogicalExecute &op); + unique_ptr CreatePlan(LogicalPragma &op); + unique_ptr CreatePlan(LogicalSample &op); + unique_ptr CreatePlan(LogicalSet &op); + unique_ptr CreatePlan(LogicalReset &op); + unique_ptr CreatePlan(LogicalSimple &op); + unique_ptr CreatePlan(LogicalVacuum &op); + unique_ptr CreatePlan(LogicalUnnest &op); + unique_ptr CreatePlan(LogicalRecursiveCTE &op); + unique_ptr CreatePlan(LogicalMaterializedCTE &op); + unique_ptr CreatePlan(LogicalCTERef &op); + unique_ptr CreatePlan(LogicalPivot &op); + + unique_ptr PlanAsOfJoin(LogicalComparisonJoin &op); + unique_ptr PlanComparisonJoin(LogicalComparisonJoin &op); + unique_ptr PlanDelimJoin(LogicalComparisonJoin &op); + unique_ptr ExtractAggregateExpressions(unique_ptr child, + vector> &expressions, + vector> &groups); private: - PhysicalOperator &ResolveAndPlan(unique_ptr logical); - unique_ptr PlanInternal(LogicalOperator &logical); bool PreserveInsertionOrder(PhysicalOperator &plan); bool UseBatchIndex(PhysicalOperator &plan); - optional_ptr PlanAsOfLoopJoin(LogicalComparisonJoin &op, PhysicalOperator &probe, - PhysicalOperator &build); + +public: + idx_t delim_index = 0; + +private: + ClientContext &context; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/radix_partitioned_hashtable.hpp b/src/duckdb/src/include/duckdb/execution/radix_partitioned_hashtable.hpp index 305c11d8d..b14ebb173 100644 --- a/src/duckdb/src/include/duckdb/execution/radix_partitioned_hashtable.hpp +++ b/src/duckdb/src/include/duckdb/execution/radix_partitioned_hashtable.hpp @@ -53,7 +53,6 @@ class RadixPartitionedHashTable { ProgressData GetProgress(ClientContext &context, GlobalSinkState &sink_p, GlobalSourceState &gstate) const; - shared_ptr GetLayoutPtr() const; const TupleDataLayout &GetLayout() const; idx_t MaxThreads(GlobalSinkState &sink) const; static void SetMultiScan(GlobalSinkState &sink); @@ -62,7 +61,7 @@ class RadixPartitionedHashTable { void SetGroupingValues(); void PopulateGroupChunk(DataChunk &group_chunk, DataChunk &input_chunk) const; - shared_ptr layout_ptr; + TupleDataLayout layout; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/execution/task_error_manager.hpp b/src/duckdb/src/include/duckdb/execution/task_error_manager.hpp index 115270ff2..4d7e64493 100644 --- a/src/duckdb/src/include/duckdb/execution/task_error_manager.hpp +++ b/src/duckdb/src/include/duckdb/execution/task_error_manager.hpp @@ -10,20 +10,15 @@ #include "duckdb/common/error_data.hpp" #include "duckdb/common/mutex.hpp" -#include "duckdb/common/atomic.hpp" #include "duckdb/common/vector.hpp" namespace duckdb { class TaskErrorManager { public: - TaskErrorManager() : has_error(false) { - } - void PushError(ErrorData error) { lock_guard elock(error_lock); this->exceptions.push_back(std::move(error)); - has_error = true; } ErrorData GetError() { @@ -38,7 +33,8 @@ class TaskErrorManager { } bool HasError() { - return has_error; + lock_guard elock(error_lock); + return !exceptions.empty(); } void ThrowException() { @@ -51,14 +47,11 @@ class TaskErrorManager { void Reset() { lock_guard elock(error_lock); exceptions.clear(); - has_error = false; } private: mutex error_lock; //! Exceptions that occurred during the execution of the current query vector exceptions; - //! Lock-free error flag - atomic has_error; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/function/aggregate/distributive_function_utils.hpp b/src/duckdb/src/include/duckdb/function/aggregate/distributive_function_utils.hpp index c42c34346..9f32d453f 100644 --- a/src/duckdb/src/include/duckdb/function/aggregate/distributive_function_utils.hpp +++ b/src/duckdb/src/include/duckdb/function/aggregate/distributive_function_utils.hpp @@ -20,10 +20,6 @@ struct FirstFunctionGetter { static AggregateFunction GetFunction(const LogicalType &type); }; -struct LastFunctionGetter { - static AggregateFunction GetFunction(const LogicalType &type); -}; - struct MinFunction { static AggregateFunction GetFunction(); }; diff --git a/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp b/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp index e3eb4dddb..7d6eb3274 100644 --- a/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp @@ -20,7 +20,6 @@ struct CountStarFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct CountFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the number of non-null values in arg."; static constexpr const char *Example = "count(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -40,7 +38,6 @@ struct FirstFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the first value (null or non-null) from arg. This function is affected by ordering."; static constexpr const char *Example = "first(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -56,7 +53,6 @@ struct LastFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the last value of a column. This function is affected by ordering."; static constexpr const char *Example = "last(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -66,7 +62,6 @@ struct AnyValueFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the first non-null value from arg. This function is affected by ordering."; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -76,7 +71,6 @@ struct MinFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the minimum value present in arg."; static constexpr const char *Example = "min(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; @@ -86,7 +80,6 @@ struct MaxFun { static constexpr const char *Parameters = "arg"; static constexpr const char *Description = "Returns the maximum value present in arg."; static constexpr const char *Example = "max(A)"; - static constexpr const char *Categories = ""; static AggregateFunctionSet GetFunctions(); }; diff --git a/src/duckdb/src/include/duckdb/function/aggregate/minmax_n_helpers.hpp b/src/duckdb/src/include/duckdb/function/aggregate/minmax_n_helpers.hpp index a26772819..9c59d11cb 100644 --- a/src/duckdb/src/include/duckdb/function/aggregate/minmax_n_helpers.hpp +++ b/src/duckdb/src/include/duckdb/function/aggregate/minmax_n_helpers.hpp @@ -102,23 +102,20 @@ class UnaryAggregateHeap { public: UnaryAggregateHeap() = default; - UnaryAggregateHeap(ArenaAllocator &allocator, idx_t capacity_p) { - Initialize(allocator, capacity_p); + explicit UnaryAggregateHeap(idx_t capacity_p) : capacity(capacity_p) { + heap.reserve(capacity); } - void Initialize(ArenaAllocator &allocator, const idx_t capacity_p) { + void Initialize(const idx_t capacity_p) { capacity = capacity_p; - auto ptr = allocator.AllocateAligned(capacity * sizeof(HeapEntry)); - memset(ptr, 0, capacity * sizeof(HeapEntry)); - heap = reinterpret_cast *>(ptr); - size = 0; + heap.reserve(capacity); } bool IsEmpty() const { - return size == 0; + return heap.empty(); } idx_t Size() const { - return size; + return heap.size(); } idx_t Capacity() const { return capacity; @@ -128,28 +125,29 @@ class UnaryAggregateHeap { D_ASSERT(capacity != 0); // must be initialized // If the heap is not full, insert the value into a new slot - if (size < capacity) { - heap[size++].Assign(allocator, value); - std::push_heap(heap, heap + size, Compare); + if (heap.size() < capacity) { + heap.emplace_back(); + heap.back().Assign(allocator, value); + std::push_heap(heap.begin(), heap.end(), Compare); } // If the heap is full, check if the value is greater than the smallest value in the heap // If it is, assign the new value to the slot and re-heapify - else if (T_COMPARATOR::Operation(value, heap[0].value)) { - std::pop_heap(heap, heap + size, Compare); - heap[size - 1].Assign(allocator, value); - std::push_heap(heap, heap + size, Compare); + else if (T_COMPARATOR::Operation(value, heap.front().value)) { + std::pop_heap(heap.begin(), heap.end(), Compare); + heap.back().Assign(allocator, value); + std::push_heap(heap.begin(), heap.end(), Compare); } - D_ASSERT(std::is_heap(heap, heap + size, Compare)); + D_ASSERT(std::is_heap(heap.begin(), heap.end(), Compare)); } void Insert(ArenaAllocator &allocator, const UnaryAggregateHeap &other) { - for (idx_t slot = 0; slot < other.Size(); slot++) { - Insert(allocator, other.heap[slot].value); + for (auto &slot : other.heap) { + Insert(allocator, slot.value); } } - HeapEntry *SortAndGetHeap() { - std::sort_heap(heap, heap + size, Compare); + vector> &SortAndGetHeap() { + std::sort_heap(heap.begin(), heap.end(), Compare); return heap; } @@ -162,9 +160,8 @@ class UnaryAggregateHeap { return T_COMPARATOR::Operation(left.value, right.value); } + vector> heap; idx_t capacity; - HeapEntry *heap; - idx_t size; }; template @@ -174,23 +171,20 @@ class BinaryAggregateHeap { public: BinaryAggregateHeap() = default; - BinaryAggregateHeap(ArenaAllocator &allocator, idx_t capacity_p) { - Initialize(allocator, capacity_p); + explicit BinaryAggregateHeap(idx_t capacity_p) : capacity(capacity_p) { + heap.reserve(capacity); } - void Initialize(ArenaAllocator &allocator, const idx_t capacity_p) { + void Initialize(const idx_t capacity_p) { capacity = capacity_p; - auto ptr = allocator.AllocateAligned(capacity * sizeof(STORAGE_TYPE)); - memset(ptr, 0, capacity * sizeof(STORAGE_TYPE)); - heap = reinterpret_cast(ptr); - size = 0; + heap.reserve(capacity); } bool IsEmpty() const { - return size == 0; + return heap.empty(); } idx_t Size() const { - return size; + return heap.size(); } idx_t Capacity() const { return capacity; @@ -200,31 +194,31 @@ class BinaryAggregateHeap { D_ASSERT(capacity != 0); // must be initialized // If the heap is not full, insert the value into a new slot - if (size < capacity) { - heap[size].first.Assign(allocator, key); - heap[size].second.Assign(allocator, value); - size++; - std::push_heap(heap, heap + size, Compare); + if (heap.size() < capacity) { + heap.emplace_back(); + heap.back().first.Assign(allocator, key); + heap.back().second.Assign(allocator, value); + std::push_heap(heap.begin(), heap.end(), Compare); } // If the heap is full, check if the value is greater than the smallest value in the heap // If it is, assign the new value to the slot and re-heapify - else if (K_COMPARATOR::Operation(key, heap[0].first.value)) { - std::pop_heap(heap, heap + size, Compare); - heap[size - 1].first.Assign(allocator, key); - heap[size - 1].second.Assign(allocator, value); - std::push_heap(heap, heap + size, Compare); + else if (K_COMPARATOR::Operation(key, heap.front().first.value)) { + std::pop_heap(heap.begin(), heap.end(), Compare); + heap.back().first.Assign(allocator, key); + heap.back().second.Assign(allocator, value); + std::push_heap(heap.begin(), heap.end(), Compare); } - D_ASSERT(std::is_heap(heap, heap + size, Compare)); + D_ASSERT(std::is_heap(heap.begin(), heap.end(), Compare)); } void Insert(ArenaAllocator &allocator, const BinaryAggregateHeap &other) { - for (idx_t slot = 0; slot < other.Size(); slot++) { - Insert(allocator, other.heap[slot].first.value, other.heap[slot].second.value); + for (auto &slot : other.heap) { + Insert(allocator, slot.first.value, slot.second.value); } } - STORAGE_TYPE *SortAndGetHeap() { - std::sort_heap(heap, heap + size, Compare); + vector &SortAndGetHeap() { + std::sort_heap(heap.begin(), heap.end(), Compare); return heap; } @@ -237,9 +231,8 @@ class BinaryAggregateHeap { return K_COMPARATOR::Operation(left.first.value, right.first.value); } + vector heap; idx_t capacity; - STORAGE_TYPE *heap; - idx_t size; }; //------------------------------------------------------------------------------ @@ -333,7 +326,7 @@ struct MinMaxNOperation { } if (!target.is_initialized) { - target.Initialize(aggr_input.allocator, source.heap.Capacity()); + target.Initialize(source.heap.Capacity()); } else if (source.heap.Capacity() != target.heap.Capacity()) { throw InvalidInputException("Mismatched n values in min/max/arg_min/arg_max"); } @@ -384,10 +377,10 @@ struct MinMaxNOperation { list_entry.length = state.heap.Size(); // Turn the heap into a sorted list, invalidating the heap property - auto heap = state.heap.SortAndGetHeap(); + auto &heap = state.heap.SortAndGetHeap(); - for (idx_t slot = 0; slot < state.heap.Size(); slot++) { - STATE::VAL_TYPE::Assign(child_data, current_offset++, state.heap.GetValue(heap[slot])); + for (const auto &slot : heap) { + STATE::VAL_TYPE::Assign(child_data, current_offset++, state.heap.GetValue(slot)); } } diff --git a/src/duckdb/src/include/duckdb/function/cast/vector_cast_helpers.hpp b/src/duckdb/src/include/duckdb/function/cast/vector_cast_helpers.hpp index 8c77b6ceb..9766df4e3 100644 --- a/src/duckdb/src/include/duckdb/function/cast/vector_cast_helpers.hpp +++ b/src/duckdb/src/include/duckdb/function/cast/vector_cast_helpers.hpp @@ -14,7 +14,6 @@ #include "duckdb/common/operator/decimal_cast_operators.hpp" #include "duckdb/common/likely.hpp" #include "duckdb/common/string_map_set.hpp" -#include "duckdb/function/cast/nested_to_varchar_cast.hpp" namespace duckdb { @@ -181,89 +180,6 @@ struct VectorCastHelpers { throw InternalException("Unimplemented internal type for decimal"); } } - - template - static idx_t CalculateEscapedStringLength(const string_t &string, bool &needs_quotes) { - auto base_length = string.GetSize(); - idx_t length = 0; - auto string_data = string.GetData(); - needs_quotes = false; - - if (base_length == 0) { - //! Empty quotes - needs_quotes = true; - return 2; - } - - if (STRUCT_KEY) { - needs_quotes = true; - } else if (isspace(string_data[0])) { - needs_quotes = true; - } else if (base_length >= 2 && isspace(string_data[base_length - 1])) { - needs_quotes = true; - } else if (StringUtil::CIEquals(string_data, base_length, "null", 4)) { - needs_quotes = true; - } else { - const bool *table = NestedToVarcharCast::LOOKUP_TABLE; - for (idx_t i = 0; i < base_length; i++) { - needs_quotes |= table[(uint8_t)string_data[i]]; - } - } - - if (!needs_quotes) { - return base_length; - } - - for (idx_t i = 0; i < base_length; i++) { - length += 1 + (string_data[i] == '\'' || string_data[i] == '\\'); - } - length += 2; - return length; - } - - static idx_t CalculateStringLength(const string_t &string, bool &needs_quotes) { - needs_quotes = false; - return string.GetSize(); - } - - template - static idx_t WriteEscapedString(void *dest, const string_t &string, bool needs_quotes) { - auto base_length = string.GetSize(); - if (base_length == 0) { - D_ASSERT(needs_quotes); - memcpy(dest, "''", 2); - return 2; - } - - auto string_start = string.GetData(); - auto string_data = string_start; - - auto destination = reinterpret_cast(dest); - if (!needs_quotes) { - memcpy(destination, string_data, base_length); - return base_length; - } - - idx_t offset = 0; - destination[offset++] = '\''; - - for (idx_t i = 0; i < base_length; i++) { - const bool needs_quote = string_data[i] == '\\' || string_data[i] == '\''; - destination[offset] = '\\'; - destination[offset + needs_quote] = string_data[i]; - offset += 1 + needs_quote; - } - - destination[offset++] = '\''; - return offset; - } - - static idx_t WriteString(void *dest, const string_t &string, bool needs_quotes) { - D_ASSERT(needs_quotes == false); - auto len = string.GetSize(); - memcpy(dest, string.GetData(), len); - return len; - } }; struct VectorStringToList { diff --git a/src/duckdb/src/include/duckdb/function/compression_function.hpp b/src/duckdb/src/include/duckdb/function/compression_function.hpp index 1e731d9a0..b0546a5a2 100644 --- a/src/duckdb/src/include/duckdb/function/compression_function.hpp +++ b/src/duckdb/src/include/duckdb/function/compression_function.hpp @@ -11,7 +11,6 @@ #include "duckdb/common/common.hpp" #include "duckdb/common/enums/compression_type.hpp" #include "duckdb/common/map.hpp" -#include "duckdb/common/insertion_order_preserving_map.hpp" #include "duckdb/common/mutex.hpp" #include "duckdb/function/function.hpp" #include "duckdb/storage/data_pointer.hpp" @@ -24,7 +23,6 @@ struct ColumnDataCheckpointData; class ColumnSegment; class SegmentStatistics; class TableFilter; -struct TableFilterState; struct ColumnSegmentState; struct ColumnFetchState; @@ -176,8 +174,7 @@ typedef void (*compression_select_t)(ColumnSegment &segment, ColumnScanState &st const SelectionVector &sel, idx_t sel_count); //! Function prototype used for applying a filter to a vector while scanning that vector typedef void (*compression_filter_t)(ColumnSegment &segment, ColumnScanState &state, idx_t vector_count, Vector &result, - SelectionVector &sel, idx_t &sel_count, const TableFilter &filter, - TableFilterState &filter_state); + SelectionVector &sel, idx_t &sel_count, const TableFilter &filter); //! Function prototype used for reading a single value typedef void (*compression_fetch_row_t)(ColumnSegment &segment, ColumnFetchState &state, row_t row_id, Vector &result, idx_t result_idx); @@ -206,12 +203,6 @@ typedef unique_ptr (*compression_deserialize_state_t)(Deseri //! Function prototype for cleaning up the segment state when the column data is dropped typedef void (*compression_cleanup_state_t)(ColumnSegment &segment); -//===--------------------------------------------------------------------===// -// GetSegmentInfo (optional) -//===--------------------------------------------------------------------===// -//! Function prototype for retrieving segment information straight from the column segment -typedef InsertionOrderPreservingMap (*compression_get_segment_info_t)(ColumnSegment &segment); - enum class CompressionValidity : uint8_t { REQUIRES_VALIDITY, NO_VALIDITY_REQUIRED }; class CompressionFunction { @@ -309,13 +300,6 @@ class CompressionFunction { //! Cleanup the segment state (optional) compression_cleanup_state_t cleanup_state; - // Get Segment Info - //! This is only necessary if you want to convey more information about the segment in the 'pragma_storage_info' - //! result - - //! Get stringified segment information directly from reading the column segment - compression_get_segment_info_t get_segment_info = nullptr; - //! Whether the validity mask should be separately compressed //! or this compression function can also be used to decompress the validity CompressionValidity validity = CompressionValidity::REQUIRES_VALIDITY; diff --git a/src/duckdb/src/include/duckdb/function/copy_function.hpp b/src/duckdb/src/include/duckdb/function/copy_function.hpp index 58842b506..00e4f4da4 100644 --- a/src/duckdb/src/include/duckdb/function/copy_function.hpp +++ b/src/duckdb/src/include/duckdb/function/copy_function.hpp @@ -15,9 +15,8 @@ namespace duckdb { -struct BoundStatement; -struct CopyFunctionFileStatistics; class Binder; +struct BoundStatement; class ColumnDataCollection; class ExecutionContext; @@ -118,36 +117,20 @@ typedef bool (*copy_rotate_files_t)(FunctionData &bind_data, const optional_idx typedef bool (*copy_rotate_next_file_t)(GlobalFunctionData &gstate, FunctionData &bind_data, const optional_idx &file_size_bytes); -typedef void (*copy_to_get_written_statistics_t)(ClientContext &context, FunctionData &bind_data, - GlobalFunctionData &gstate, CopyFunctionFileStatistics &statistics); - typedef vector> (*copy_to_select_t)(CopyToSelectInput &input); -enum class CopyFunctionReturnType : uint8_t { - CHANGED_ROWS = 0, - CHANGED_ROWS_AND_FILE_LIST = 1, - WRITTEN_FILE_STATISTICS = 2 -}; +enum class CopyFunctionReturnType : uint8_t { CHANGED_ROWS = 0, CHANGED_ROWS_AND_FILE_LIST = 1 }; vector GetCopyFunctionReturnNames(CopyFunctionReturnType return_type); vector GetCopyFunctionReturnLogicalTypes(CopyFunctionReturnType return_type); -struct CopyFunctionFileStatistics { - idx_t row_count = 0; - idx_t file_size_bytes = 0; - Value footer_size_bytes; - // map of column name -> statistics name -> statistics value - case_insensitive_map_t> column_statistics; -}; - class CopyFunction : public Function { // NOLINT: work-around bug in clang-tidy public: explicit CopyFunction(const string &name) : Function(name), plan(nullptr), copy_to_select(nullptr), copy_to_bind(nullptr), - copy_to_initialize_local(nullptr), copy_to_initialize_global(nullptr), - copy_to_get_written_statistics(nullptr), copy_to_sink(nullptr), copy_to_combine(nullptr), - copy_to_finalize(nullptr), execution_mode(nullptr), prepare_batch(nullptr), flush_batch(nullptr), - desired_batch_size(nullptr), rotate_files(nullptr), rotate_next_file(nullptr), serialize(nullptr), - deserialize(nullptr), copy_from_bind(nullptr) { + copy_to_initialize_local(nullptr), copy_to_initialize_global(nullptr), copy_to_sink(nullptr), + copy_to_combine(nullptr), copy_to_finalize(nullptr), execution_mode(nullptr), prepare_batch(nullptr), + flush_batch(nullptr), desired_batch_size(nullptr), rotate_files(nullptr), rotate_next_file(nullptr), + serialize(nullptr), deserialize(nullptr), copy_from_bind(nullptr) { } //! Plan rewrite copy function @@ -157,7 +140,6 @@ class CopyFunction : public Function { // NOLINT: work-around bug in clang-tidy copy_to_bind_t copy_to_bind; copy_to_initialize_local_t copy_to_initialize_local; copy_to_initialize_global_t copy_to_initialize_global; - copy_to_get_written_statistics_t copy_to_get_written_statistics; copy_to_sink_t copy_to_sink; copy_to_combine_t copy_to_combine; copy_to_finalize_t copy_to_finalize; diff --git a/src/duckdb/src/include/duckdb/function/function_list.hpp b/src/duckdb/src/include/duckdb/function/function_list.hpp index 01057fa8f..feccb823b 100644 --- a/src/duckdb/src/include/duckdb/function/function_list.hpp +++ b/src/duckdb/src/include/duckdb/function/function_list.hpp @@ -19,11 +19,9 @@ typedef AggregateFunctionSet (*get_aggregate_function_set_t)(); struct StaticFunctionDefinition { const char *name; - const char *alias_of; const char *parameters; const char *description; const char *example; - const char *categories; get_scalar_function_t get_function; get_scalar_function_set_t get_function_set; get_aggregate_function_t get_aggregate_function; diff --git a/src/duckdb/src/include/duckdb/function/function_serialization.hpp b/src/duckdb/src/include/duckdb/function/function_serialization.hpp index 678229b40..8f8ed65f2 100644 --- a/src/duckdb/src/include/duckdb/function/function_serialization.hpp +++ b/src/duckdb/src/include/duckdb/function/function_serialization.hpp @@ -35,8 +35,7 @@ class FunctionSerializer { template static FUNC DeserializeFunction(ClientContext &context, CatalogType catalog_type, const string &name, vector arguments, vector original_arguments) { - EntryLookupInfo lookup_info(catalog_type, name); - auto &func_catalog = Catalog::GetEntry(context, SYSTEM_CATALOG, DEFAULT_SCHEMA, lookup_info); + auto &func_catalog = Catalog::GetEntry(context, catalog_type, SYSTEM_CATALOG, DEFAULT_SCHEMA, name); if (func_catalog.type != catalog_type) { throw InternalException("DeserializeFunction - cant find catalog entry for function %s", name); } diff --git a/src/duckdb/src/include/duckdb/function/lambda_functions.hpp b/src/duckdb/src/include/duckdb/function/lambda_functions.hpp index 3eb04a673..802d96c5e 100644 --- a/src/duckdb/src/include/duckdb/function/lambda_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/lambda_functions.hpp @@ -19,10 +19,8 @@ namespace duckdb { struct ListLambdaBindData final : public FunctionData { public: - ListLambdaBindData(const LogicalType &return_type, unique_ptr lambda_expr, const bool has_index = false, - const bool has_initial = false) - : return_type(return_type), lambda_expr(std::move(lambda_expr)), has_index(has_index), - has_initial(has_initial) {}; + ListLambdaBindData(const LogicalType &return_type, unique_ptr lambda_expr, const bool has_index = false) + : return_type(return_type), lambda_expr(std::move(lambda_expr)), has_index(has_index) {}; //! Return type of the scalar function LogicalType return_type; @@ -30,18 +28,17 @@ struct ListLambdaBindData final : public FunctionData { unique_ptr lambda_expr; //! True, if the last parameter in a lambda parameter list represents the index of the current list element bool has_index; - bool has_initial; public: unique_ptr Copy() const override { auto lambda_expr_copy = lambda_expr ? lambda_expr->Copy() : nullptr; - return make_uniq(return_type, std::move(lambda_expr_copy), has_index, has_initial); + return make_uniq(return_type, std::move(lambda_expr_copy), has_index); } bool Equals(const FunctionData &other_p) const override { auto &other = other_p.Cast(); return Expression::Equals(lambda_expr, other.lambda_expr) && return_type == other.return_type && - has_index == other.has_index && has_initial == other.has_initial; + has_index == other.has_index; } //! Serializes a lambda function's bind data @@ -111,7 +108,6 @@ class LambdaFunctions { lambda_expr = bind_info.lambda_expr; is_volatile = lambda_expr->IsVolatile(); has_index = bind_info.has_index; - has_initial = bind_info.has_initial; // get the list column entries list_column.ToUnifiedFormat(row_count, list_column_format); @@ -132,7 +128,6 @@ class LambdaFunctions { const idx_t row_count; bool has_index; - bool has_initial; bool is_volatile; const bool is_all_constant; }; diff --git a/src/duckdb/src/include/duckdb/function/register_function_list_helper.hpp b/src/duckdb/src/include/duckdb/function/register_function_list_helper.hpp index 714001a96..fc389cff2 100644 --- a/src/duckdb/src/include/duckdb/function/register_function_list_helper.hpp +++ b/src/duckdb/src/include/duckdb/function/register_function_list_helper.hpp @@ -15,7 +15,7 @@ namespace duckdb { static void FillFunctionParameters(FunctionDescription &function_description, const char *function_name, - vector ¶meters, vector &descriptions) { + vector ¶meters, vector &descriptions, vector &examples) { for (string ¶meter : parameters) { vector parameter_name_type = StringUtil::Split(parameter, "::"); if (parameter_name_type.size() == 1) { @@ -35,7 +35,6 @@ static void FillFunctionDescriptions(const FunctionDefinition &function, T &info vector variants = StringUtil::Split(function.parameters, '\1'); vector descriptions = StringUtil::Split(function.description, '\1'); vector examples = StringUtil::Split(function.example, '\1'); - vector categories = StringUtil::Split(function.categories, '\1'); // add single variant for functions that take no arguments if (variants.empty()) { @@ -46,7 +45,7 @@ static void FillFunctionDescriptions(const FunctionDefinition &function, T &info FunctionDescription function_description; // parameter_names and parameter_types vector parameters = StringUtil::SplitWithParentheses(variants[variant_index], ','); - FillFunctionParameters(function_description, function.name, parameters, descriptions); + FillFunctionParameters(function_description, function.name, parameters, descriptions, examples); // description if (descriptions.size() == variants.size()) { function_description.description = descriptions[variant_index]; @@ -63,12 +62,6 @@ static void FillFunctionDescriptions(const FunctionDefinition &function, T &info } else if (!examples.empty()) { throw InternalException("Incorrect number of function examples for function '%s'", function.name); } - // categories - if (variant_index < categories.size()) { - function_description.categories = StringUtil::Split(categories[variant_index], ','); - } else if (categories.size() == 1) { - function_description.categories = StringUtil::Split(categories[0], ','); - } info.descriptions.push_back(std::move(function_description)); } } diff --git a/src/duckdb/src/include/duckdb/function/scalar/compressed_materialization_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/compressed_materialization_functions.hpp index 918888594..f9e4fe930 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/compressed_materialization_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/compressed_materialization_functions.hpp @@ -20,7 +20,6 @@ struct InternalCompressIntegralUtinyintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -30,7 +29,6 @@ struct InternalCompressIntegralUsmallintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -40,7 +38,6 @@ struct InternalCompressIntegralUintegerFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -50,7 +47,6 @@ struct InternalCompressIntegralUbigintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -60,7 +56,6 @@ struct InternalCompressStringUtinyintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -70,7 +65,6 @@ struct InternalCompressStringUsmallintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -80,7 +74,6 @@ struct InternalCompressStringUintegerFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -90,7 +83,6 @@ struct InternalCompressStringUbigintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -100,7 +92,6 @@ struct InternalCompressStringHugeintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -110,7 +101,6 @@ struct InternalDecompressIntegralSmallintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -120,7 +110,6 @@ struct InternalDecompressIntegralIntegerFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -130,7 +119,6 @@ struct InternalDecompressIntegralBigintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -140,7 +128,6 @@ struct InternalDecompressIntegralHugeintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -150,7 +137,6 @@ struct InternalDecompressIntegralUsmallintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -160,7 +146,6 @@ struct InternalDecompressIntegralUintegerFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -170,7 +155,6 @@ struct InternalDecompressIntegralUbigintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -180,7 +164,6 @@ struct InternalDecompressIntegralUhugeintFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -190,7 +173,6 @@ struct InternalDecompressStringFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/date_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/date_functions.hpp index 9454bb6fc..8aac94b28 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/date_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/date_functions.hpp @@ -20,7 +20,6 @@ struct StrfTimeFun { static constexpr const char *Parameters = "data,format"; static constexpr const char *Description = "Converts a date to a string according to the format string."; static constexpr const char *Example = "strftime(date '1992-01-01', '%a, %-d %B %Y')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -30,7 +29,6 @@ struct StrpTimeFun { static constexpr const char *Parameters = "text::VARCHAR,format::VARCHAR\1text::VARCHAR,format-list::VARCHAR[]"; static constexpr const char *Description = "Converts the string text to timestamp according to the format string. Throws an error on failure. To return NULL on failure, use try_strptime.\1Converts the string text to timestamp applying the format strings in the list until one succeeds. Throws an error on failure. To return NULL on failure, use try_strptime."; static constexpr const char *Example = "strptime('Wed, 1 January 1992 - 08:38:40 PM', '%a, %-d %B %Y - %I:%M:%S %p')\1strptime('4/15/2023 10:56:00', ['%d/%m/%Y %H:%M:%S', '%m/%d/%Y %H:%M:%S'])"; - static constexpr const char *Categories = "\1"; static ScalarFunctionSet GetFunctions(); }; @@ -40,7 +38,6 @@ struct TryStrpTimeFun { static constexpr const char *Parameters = "text,format"; static constexpr const char *Description = "Converts the string text to timestamp according to the format string. Returns NULL on failure."; static constexpr const char *Example = "try_strptime('Wed, 1 January 1992 - 08:38:40 PM', '%a, %-d %B %Y - %I:%M:%S %p')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/generic_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/generic_functions.hpp index f502b4e82..fd2865e6c 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/generic_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/generic_functions.hpp @@ -20,7 +20,6 @@ struct ConstantOrNullFun { static constexpr const char *Parameters = "arg1,arg2"; static constexpr const char *Description = "If arg2 is NULL, return NULL. Otherwise, return arg1."; static constexpr const char *Example = "constant_or_null(42, NULL)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct GetVariableFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -40,7 +38,6 @@ struct ErrorFun { static constexpr const char *Parameters = "message"; static constexpr const char *Description = "Throws the given error message"; static constexpr const char *Example = "error('access_mode')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -50,7 +47,6 @@ struct CreateSortKeyFun { static constexpr const char *Parameters = "parameters..."; static constexpr const char *Description = "Constructs a binary-comparable sort key based on a set of input parameters and sort qualifiers"; static constexpr const char *Example = "create_sort_key('A', 'DESC')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/list_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/list_functions.hpp index e02b808ad..577b643f6 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/list_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/list_functions.hpp @@ -20,7 +20,6 @@ struct ListSelectFun { static constexpr const char *Parameters = "value_list,index_list"; static constexpr const char *Description = "Returns a list based on the elements selected by the index_list."; static constexpr const char *Example = "list_select([10, 20, 30, 40], [1, 4])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -36,7 +35,6 @@ struct ListWhereFun { static constexpr const char *Parameters = "value_list,mask_list"; static constexpr const char *Description = "Returns a list with the BOOLEANs in mask_list applied as a mask to the value_list."; static constexpr const char *Example = "list_where([10, 20, 30, 40], [true, false, false, true])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -52,7 +50,6 @@ struct ListContainsFun { static constexpr const char *Parameters = "list,element"; static constexpr const char *Description = "Returns true if the list contains the element."; static constexpr const char *Example = "list_contains([1, 2, NULL], 1)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -80,7 +77,6 @@ struct ListPositionFun { static constexpr const char *Parameters = "list,element"; static constexpr const char *Description = "Returns the index of the element if the list contains the element. If the element is not found, it returns NULL."; static constexpr const char *Example = "list_position([1, 2, NULL], 2)"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -108,7 +104,6 @@ struct ListZipFun { static constexpr const char *Parameters = "list1,list2,..."; static constexpr const char *Description = "Zips k LISTs to a new LIST whose length will be that of the longest list. Its elements are structs of k elements from each list list_1, …, list_k, missing elements are replaced with NULL. If truncate is set, all lists are truncated to the smallest list length."; static constexpr const char *Example = "list_zip([1, 2], [3, 4], [5, 6])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -124,7 +119,6 @@ struct ListExtractFun { static constexpr const char *Parameters = "list,index"; static constexpr const char *Description = "Extract the indexth (1-based) value from the list."; static constexpr const char *Example = "list_extract([4, 5, 6], 3)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -140,7 +134,6 @@ struct ListResizeFun { static constexpr const char *Parameters = "list,size[,value]"; static constexpr const char *Description = "Resizes the list to contain size elements. Initializes new elements with value or NULL if value is not set."; static constexpr const char *Example = "list_resize([1, 2, 3], 5, 0)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -156,7 +149,6 @@ struct ArrayExtractFun { static constexpr const char *Parameters = "list,index"; static constexpr const char *Description = "Extract the indexth (1-based) value from the array."; static constexpr const char *Example = "array_extract('DuckDB', 2)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/map_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/map_functions.hpp index f802d5998..5814a00e3 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/map_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/map_functions.hpp @@ -20,7 +20,6 @@ struct MapContainsFun { static constexpr const char *Parameters = "map,key"; static constexpr const char *Description = "Checks if a map contains a given key."; static constexpr const char *Example = "map_contains(MAP {'key1': 10, 'key2': 20, 'key3': 30}, 'key2')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp index 35276d810..07b16a151 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp @@ -82,6 +82,7 @@ struct HistogramAggState { MAP_TYPE *hist; }; +unique_ptr GetBindData(idx_t index); ScalarFunction GetKeyExtractFunction(); ScalarFunction GetIndexExtractFunction(); ScalarFunction GetExtractAtFunction(); diff --git a/src/duckdb/src/include/duckdb/function/scalar/operator_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/operator_functions.hpp index 4b124a44f..dbb7a1461 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/operator_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/operator_functions.hpp @@ -20,7 +20,6 @@ struct OperatorAddFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -36,7 +35,6 @@ struct OperatorSubtractFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -52,7 +50,6 @@ struct OperatorMultiplyFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -68,7 +65,6 @@ struct OperatorFloatDivideFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -78,7 +74,6 @@ struct OperatorIntegerDivideFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -94,7 +89,6 @@ struct OperatorModuloFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp b/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp index 5ac80ab08..fa6a3e91f 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp @@ -140,9 +140,6 @@ struct RegexLocalState : public FunctionLocalState { explicit RegexLocalState(RegexpBaseBindData &info, bool extract_all = false) : constant_pattern(duckdb_re2::StringPiece(info.constant_string.c_str(), info.constant_string.size()), info.options) { - if (!constant_pattern.ok()) { - throw InvalidInputException(constant_pattern.error()); - } if (extract_all) { auto group_count_p = constant_pattern.NumberOfCapturingGroups(); if (group_count_p != -1) { diff --git a/src/duckdb/src/include/duckdb/function/scalar/sequence_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/sequence_functions.hpp index 99766a332..d7f6eb01a 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/sequence_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/sequence_functions.hpp @@ -20,7 +20,6 @@ struct CurrvalFun { static constexpr const char *Parameters = "'sequence_name'"; static constexpr const char *Description = "Return the current value of the sequence. Note that nextval must be called at least once prior to calling currval."; static constexpr const char *Example = "currval('my_sequence_name')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct NextvalFun { static constexpr const char *Parameters = "'sequence_name'"; static constexpr const char *Description = "Return the following value of the sequence."; static constexpr const char *Example = "nextval('my_sequence_name')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp index c69958f4c..ffca2c073 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp @@ -18,9 +18,8 @@ namespace duckdb { struct UpperFun { static constexpr const char *Name = "upper"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Converts `string` to upper case."; + static constexpr const char *Description = "Convert string to upper case."; static constexpr const char *Example = "upper('Hello')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -34,9 +33,8 @@ struct UcaseFun { struct LowerFun { static constexpr const char *Name = "lower"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Converts `string` to lower case"; + static constexpr const char *Description = "Convert string to lower case"; static constexpr const char *Example = "lower('Hello')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -50,9 +48,8 @@ struct LcaseFun { struct ConcatWsFun { static constexpr const char *Name = "concat_ws"; static constexpr const char *Parameters = "separator,string,..."; - static constexpr const char *Description = "Concatenates strings together separated by the specified separator."; + static constexpr const char *Description = "Concatenate strings together separated by the specified separator."; static constexpr const char *Example = "concat_ws(', ', 'Banana', 'Apple', 'Melon')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -60,9 +57,8 @@ struct ConcatWsFun { struct ConcatFun { static constexpr const char *Name = "concat"; static constexpr const char *Parameters = "string,..."; - static constexpr const char *Description = "Concatenates many strings together."; + static constexpr const char *Description = "Concatenate many strings together."; static constexpr const char *Example = "concat('Hello', ' ', 'World')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -72,7 +68,6 @@ struct ListConcatFun { static constexpr const char *Parameters = "list1,list2"; static constexpr const char *Description = "Concatenates two lists."; static constexpr const char *Example = "list_concat([2, 3], [4, 5, 6])"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -97,10 +92,9 @@ struct ArrayCatFun { struct ConcatOperatorFun { static constexpr const char *Name = "||"; - static constexpr const char *Parameters = "string,string"; - static constexpr const char *Description = "Concatenates two strings, lists, or blobs. Any `NULL` input results in `NULL`. See also `concat(string, ...)` and `list_concat(list1, list2)`"; - static constexpr const char *Example = "'Duck' || 'DB'\2[1, 2, 3] || [4, 5, 6]\2'\\xAA'::BLOB || '\\xBB'::BLOB"; - static constexpr const char *Categories = "string,list,blob"; + static constexpr const char *Parameters = "list1,list2"; + static constexpr const char *Description = "Concatenates two lists."; + static constexpr const char *Example = "list_concat([2, 3], [4, 5, 6])"; static ScalarFunction GetFunction(); }; @@ -110,7 +104,6 @@ struct PrefixFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -120,7 +113,6 @@ struct SuffixFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -134,9 +126,8 @@ struct EndsWithFun { struct ContainsFun { static constexpr const char *Name = "contains"; static constexpr const char *Parameters = "string::VARCHAR,search_string::VARCHAR\1list::ANY[],element::ANY\1map::MAP(ANY,ANY),key::ANY"; - static constexpr const char *Description = "Returns true if `search_string` is found within `string`.\1Returns true if the `list` contains the `element`.\1Checks if a `map` contains a given `key`."; + static constexpr const char *Description = "Returns true if search_string is found within string.\1Returns true if the list contains the element.\1Checks if a map contains a given key."; static constexpr const char *Example = "contains('abc', 'a')\1contains([1, 2, NULL], 1)\1contains(MAP {'key1': 10, 'key2': 20, 'key3': 30}, 'key2')"; - static constexpr const char *Categories = "\1\1"; static ScalarFunctionSet GetFunctions(); }; @@ -144,9 +135,8 @@ struct ContainsFun { struct StripAccentsFun { static constexpr const char *Name = "strip_accents"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Strips accents from `string`."; + static constexpr const char *Description = "Strips accents from string."; static constexpr const char *Example = "strip_accents('mühleisen')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -154,9 +144,8 @@ struct StripAccentsFun { struct NFCNormalizeFun { static constexpr const char *Name = "nfc_normalize"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Converts `string` to Unicode NFC normalized string. Useful for comparisons and ordering if text data is mixed between NFC normalized and not."; + static constexpr const char *Description = "Convert string to Unicode NFC normalized string. Useful for comparisons and ordering if text data is mixed between NFC normalized and not."; static constexpr const char *Example = "nfc_normalize('ardèch')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -164,9 +153,8 @@ struct NFCNormalizeFun { struct LengthFun { static constexpr const char *Name = "length"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Number of characters in `string`."; + static constexpr const char *Description = "Number of characters in string."; static constexpr const char *Example = "length('Hello🦆')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -177,24 +165,11 @@ struct LenFun { static constexpr const char *Name = "len"; }; -struct CharLengthFun { - using ALIAS = LengthFun; - - static constexpr const char *Name = "char_length"; -}; - -struct CharacterLengthFun { - using ALIAS = LengthFun; - - static constexpr const char *Name = "character_length"; -}; - struct StrlenFun { static constexpr const char *Name = "strlen"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Number of bytes in `string`."; + static constexpr const char *Description = "Number of bytes in string."; static constexpr const char *Example = "strlen('🦆')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -204,17 +179,15 @@ struct BitLengthFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; struct OctetLengthFun { static constexpr const char *Name = "octet_length"; - static constexpr const char *Parameters = "blob::BLOB\1bitstring::BIT"; - static constexpr const char *Description = "Number of bytes in `blob`.\1Returns the number of bytes in the `bitstring`."; - static constexpr const char *Example = "octet_length('\\xAA\\xBB'::BLOB)\1octet_length('1101011'::BITSTRING)"; - static constexpr const char *Categories = "blob\1bitstring"; + static constexpr const char *Parameters = "blob"; + static constexpr const char *Description = "Number of bytes in blob."; + static constexpr const char *Example = "octet_length('\\xAA\\xBB'::BLOB)"; static ScalarFunctionSet GetFunctions(); }; @@ -222,9 +195,8 @@ struct OctetLengthFun { struct LengthGraphemeFun { static constexpr const char *Name = "length_grapheme"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Number of grapheme clusters in `string`."; + static constexpr const char *Description = "Number of grapheme clusters in string."; static constexpr const char *Example = "length_grapheme('🤦🏼‍♂️🤦🏽‍♀️')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -232,9 +204,8 @@ struct LengthGraphemeFun { struct ArrayLengthFun { static constexpr const char *Name = "array_length"; static constexpr const char *Parameters = "list"; - static constexpr const char *Description = "Returns the length of the `list`."; + static constexpr const char *Description = "Returns the length of the list."; static constexpr const char *Example = "array_length([1,2,3])"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -242,9 +213,8 @@ struct ArrayLengthFun { struct SubstringFun { static constexpr const char *Name = "substring"; static constexpr const char *Parameters = "string,start,length"; - static constexpr const char *Description = "Extract substring of `length` characters starting from character `start`. Note that a start value of 1 refers to the first character of the `string`."; + static constexpr const char *Description = "Extract substring of length characters starting from character start. Note that a start value of 1 refers to the first character of the string."; static constexpr const char *Example = "substring('Hello', 2, 2)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -258,9 +228,8 @@ struct SubstrFun { struct SubstringGraphemeFun { static constexpr const char *Name = "substring_grapheme"; static constexpr const char *Parameters = "string,start,length"; - static constexpr const char *Description = "Extract substring of `length` grapheme clusters starting from character `start`. Note that a start value of 1 refers to the first character of the `string`."; + static constexpr const char *Description = "Extract substring of length grapheme clusters starting from character start. Note that a start value of 1 refers to the first character of the string."; static constexpr const char *Example = "substring_grapheme('🦆🤦🏼‍♂️🤦🏽‍♀️🦆', 3, 2)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -268,9 +237,8 @@ struct SubstringGraphemeFun { struct StringSplitFun { static constexpr const char *Name = "string_split"; static constexpr const char *Parameters = "string,separator"; - static constexpr const char *Description = "Splits the `string` along the `separator`"; + static constexpr const char *Description = "Splits the string along the separator"; static constexpr const char *Example = "string_split('hello-world', '-')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -295,10 +263,9 @@ struct SplitFun { struct StringSplitRegexFun { static constexpr const char *Name = "string_split_regex"; - static constexpr const char *Parameters = "string,regex"; - static constexpr const char *Description = "Splits the `string` along the `regex`"; - static constexpr const char *Example = "string_split_regex('hello world; 42', ';? ')"; - static constexpr const char *Categories = ""; + static constexpr const char *Parameters = "string,separator"; + static constexpr const char *Description = "Splits the string along the regex"; + static constexpr const char *Example = "string_split_regex('hello␣world; 42', ';?␣')"; static ScalarFunctionSet GetFunctions(); }; @@ -318,9 +285,8 @@ struct RegexpSplitToArrayFun { struct RegexpFun { static constexpr const char *Name = "regexp_full_match"; static constexpr const char *Parameters = "string,regex[,options]"; - static constexpr const char *Description = "Returns true if the entire `string` matches the `regex`. A set of optional `options` can be set."; + static constexpr const char *Description = "Returns true if the entire string matches the regex. A set of optional options can be set."; static constexpr const char *Example = "regexp_full_match('anabanana', '(an)*')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -328,9 +294,8 @@ struct RegexpFun { struct RegexpMatchesFun { static constexpr const char *Name = "regexp_matches"; static constexpr const char *Parameters = "string,pattern[,options]"; - static constexpr const char *Description = "Returns true if `string` contains the regexp `pattern`, false otherwise. A set of optional `options` can be set."; + static constexpr const char *Description = "Returns true if string contains the regexp pattern, false otherwise. A set of optional options can be set."; static constexpr const char *Example = "regexp_matches('anabanana', '(an)*')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -338,9 +303,8 @@ struct RegexpMatchesFun { struct RegexpReplaceFun { static constexpr const char *Name = "regexp_replace"; static constexpr const char *Parameters = "string,pattern,replacement[,options]"; - static constexpr const char *Description = "If `string` contains the regexp `pattern`, replaces the matching part with `replacement`. A set of optional `options` can be set."; + static constexpr const char *Description = "If string contains the regexp pattern, replaces the matching part with replacement. A set of optional options can be set."; static constexpr const char *Example = "regexp_replace('hello', '[lo]', '-')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -348,9 +312,8 @@ struct RegexpReplaceFun { struct RegexpExtractFun { static constexpr const char *Name = "regexp_extract"; static constexpr const char *Parameters = "string,pattern[,group = 0][,options]"; - static constexpr const char *Description = "If `string` contains the regexp `pattern`, returns the capturing group specified by optional parameter `group`. The group must be a constant value. If no group is given, it defaults to 0. A set of optional `options` can be set."; + static constexpr const char *Description = "If string contains the regexp pattern, returns the capturing group specified by optional parameter group. The group must be a constant value. If no group is given, it defaults to 0. A set of optional options can be set."; static constexpr const char *Example = "regexp_extract('abc', '([a-z])(b)', 1)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -358,9 +321,8 @@ struct RegexpExtractFun { struct RegexpExtractAllFun { static constexpr const char *Name = "regexp_extract_all"; static constexpr const char *Parameters = "string, regex[, group = 0][, options]"; - static constexpr const char *Description = "Splits the `string` along the `regex` and extract all occurrences of `group`. A set of optional `options` can be set."; + static constexpr const char *Description = "Split the string along the regex and extract all occurrences of group. A set of optional options can be set."; static constexpr const char *Example = "regexp_extract_all('hello_world', '([a-z ]+)_?', 1)"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -368,9 +330,8 @@ struct RegexpExtractAllFun { struct RegexpEscapeFun { static constexpr const char *Name = "regexp_escape"; static constexpr const char *Parameters = "string"; - static constexpr const char *Description = "Escapes special patterns to turn string into a regular expression similarly to Python's re.escape function."; + static constexpr const char *Description = "Escapes all potentially meaningful regexp characters in the input string"; static constexpr const char *Example = "regexp_escape('https://duckdb.org')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -380,7 +341,6 @@ struct LikeFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -390,7 +350,6 @@ struct NotLikeFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -400,7 +359,6 @@ struct GlobPatternFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -410,7 +368,6 @@ struct ILikeFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -420,7 +377,6 @@ struct NotILikeFun { static constexpr const char *Parameters = ""; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -428,9 +384,8 @@ struct NotILikeFun { struct LikeEscapeFun { static constexpr const char *Name = "like_escape"; static constexpr const char *Parameters = "string,like_specifier,escape_character"; - static constexpr const char *Description = "Returns true if the `string` matches the `like_specifier` (see Pattern Matching) using case-sensitive matching. `escape_character` is used to search for wildcard characters in the `string`."; + static constexpr const char *Description = "Returns true if the string matches the like_specifier (see Pattern Matching) using case-sensitive matching. escape_character is used to search for wildcard characters in the string."; static constexpr const char *Example = "like_escape('a%c', 'a$%c', '$')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -438,9 +393,8 @@ struct LikeEscapeFun { struct NotLikeEscapeFun { static constexpr const char *Name = "not_like_escape"; static constexpr const char *Parameters = "string,like_specifier,escape_character"; - static constexpr const char *Description = "Returns false if the `string` matches the `like_specifier` (see Pattern Matching) using case-sensitive matching. `escape_character` is used to search for wildcard characters in the `string`."; + static constexpr const char *Description = "Returns false if the string matches the like_specifier (see Pattern Matching) using case-sensitive matching. escape_character is used to search for wildcard characters in the string."; static constexpr const char *Example = "not_like_escape('a%c', 'a$%c', '$')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -448,9 +402,8 @@ struct NotLikeEscapeFun { struct IlikeEscapeFun { static constexpr const char *Name = "ilike_escape"; static constexpr const char *Parameters = "string,like_specifier,escape_character"; - static constexpr const char *Description = "Returns true if the `string` matches the `like_specifier` (see Pattern Matching) using case-insensitive matching. `escape_character` is used to search for wildcard characters in the `string`."; + static constexpr const char *Description = "Returns true if the string matches the like_specifier (see Pattern Matching) using case-insensitive matching. escape_character is used to search for wildcard characters in the string."; static constexpr const char *Example = "ilike_escape('A%c', 'a$%C', '$')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -458,9 +411,8 @@ struct IlikeEscapeFun { struct NotIlikeEscapeFun { static constexpr const char *Name = "not_ilike_escape"; static constexpr const char *Parameters = "string,like_specifier,escape_character"; - static constexpr const char *Description = "Returns false if the `string` matches the `like_specifier` (see Pattern Matching) using case-insensitive matching. `escape_character` is used to search for wildcard characters in the `string`."; + static constexpr const char *Description = "Returns false if the string matches the like_specifier (see Pattern Matching) using case-insensitive matching. escape_character is used to search for wildcard characters in the string."; static constexpr const char *Example = "not_ilike_escape('A%c', 'a$%C', '$')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -468,9 +420,8 @@ struct NotIlikeEscapeFun { struct MD5Fun { static constexpr const char *Name = "md5"; static constexpr const char *Parameters = "value"; - static constexpr const char *Description = "Returns the MD5 hash of the `value` as a string"; + static constexpr const char *Description = "Returns the MD5 hash of the value as a string"; static constexpr const char *Example = "md5('123')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -478,9 +429,8 @@ struct MD5Fun { struct MD5NumberFun { static constexpr const char *Name = "md5_number"; static constexpr const char *Parameters = "value"; - static constexpr const char *Description = "Returns the MD5 hash of the `value` as an INT128"; + static constexpr const char *Description = "Returns the MD5 hash of the value as an INT128"; static constexpr const char *Example = "md5_number('123')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -488,9 +438,8 @@ struct MD5NumberFun { struct SHA1Fun { static constexpr const char *Name = "sha1"; static constexpr const char *Parameters = "value"; - static constexpr const char *Description = "Returns the SHA1 hash of the `value`"; + static constexpr const char *Description = "Returns the SHA1 hash of the value"; static constexpr const char *Example = "sha1('hello')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -498,9 +447,8 @@ struct SHA1Fun { struct SHA256Fun { static constexpr const char *Name = "sha256"; static constexpr const char *Parameters = "value"; - static constexpr const char *Description = "Returns the SHA256 hash of the `value`"; + static constexpr const char *Description = "Returns the SHA256 hash of the value"; static constexpr const char *Example = "sha256('hello')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/struct_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/struct_functions.hpp index 8fb514026..fa11d636f 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/struct_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/struct_functions.hpp @@ -20,7 +20,6 @@ struct StructExtractFun { static constexpr const char *Parameters = "struct,'entry'"; static constexpr const char *Description = "Extract the named entry from the STRUCT."; static constexpr const char *Example = "struct_extract({'i': 3, 'v2': 3, 'v3': 0}, 'i')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; @@ -30,10 +29,8 @@ struct StructExtractAtFun { static constexpr const char *Parameters = "struct,'entry'"; static constexpr const char *Description = "Extract the entry from the STRUCT by position (starts at 1!)."; static constexpr const char *Example = "struct_extract_at({'i': 3, 'v2': 3, 'v3': 0}, 2)"; - static constexpr const char *Categories = ""; - static ScalarFunction GetFunction(); - static unique_ptr GetBindData(idx_t index); + static ScalarFunctionSet GetFunctions(); }; struct StructPackFun { @@ -41,7 +38,6 @@ struct StructPackFun { static constexpr const char *Parameters = "name:=any,..."; static constexpr const char *Description = "Create a STRUCT containing the argument values. The entry name will be the bound variable name."; static constexpr const char *Example = "struct_pack(i := 4, s := 'string')"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -51,17 +47,6 @@ struct RowFun { static constexpr const char *Parameters = "any,..."; static constexpr const char *Description = "Create an unnamed STRUCT (tuple) containing the argument values."; static constexpr const char *Example = "row(i, i % 4, i / 4)"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - -struct RemapStructFun { - static constexpr const char *Name = "remap_struct"; - static constexpr const char *Parameters = "input,target_type,mapping,defaults"; - static constexpr const char *Description = "Map a struct to another struct type, potentially re-ordering, renaming and casting members and filling in defaults for missing values"; - static constexpr const char *Example = "remap_struct({'i': 1, 'j': 2}, NULL::ROW(v1 INT, v2 INT, v3 INT), {'v1': 'j', 'v3': 'i'}, {'v2': NULL::INTEGER})"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -71,7 +56,6 @@ struct StructConcatFun { static constexpr const char *Parameters = "struct,struct,..."; static constexpr const char *Description = "Merge the multiple STRUCTs into a single STRUCT."; static constexpr const char *Example = "struct_concat(struct_pack(i := 4), struct_pack(s := 'string'))"; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; diff --git a/src/duckdb/src/include/duckdb/function/scalar/system_functions.hpp b/src/duckdb/src/include/duckdb/function/scalar/system_functions.hpp index a45f6dda7..fd82a230b 100644 --- a/src/duckdb/src/include/duckdb/function/scalar/system_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/scalar/system_functions.hpp @@ -20,7 +20,6 @@ struct FinalizeFun { static constexpr const char *Parameters = "col0"; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -30,7 +29,6 @@ struct CombineFun { static constexpr const char *Parameters = "col0,col1"; static constexpr const char *Description = ""; static constexpr const char *Example = ""; - static constexpr const char *Categories = ""; static ScalarFunction GetFunction(); }; @@ -40,39 +38,8 @@ struct WriteLogFun { static constexpr const char *Parameters = "string"; static constexpr const char *Description = "Writes to the logger"; static constexpr const char *Example = "write_log('Hello')"; - static constexpr const char *Categories = ""; static ScalarFunctionSet GetFunctions(); }; -struct CurrentConnectionId { - static constexpr const char *Name = "current_connection_id"; - static constexpr const char *Parameters = ""; - static constexpr const char *Description = "Get the current connection_id"; - static constexpr const char *Example = "current_connection_id()"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - -struct CurrentTransactionId { - static constexpr const char *Name = "current_transaction_id"; - static constexpr const char *Parameters = ""; - static constexpr const char *Description = "Get the current global transaction_id"; - static constexpr const char *Example = "current_transaction_id()"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - -struct CurrentQueryId { - static constexpr const char *Name = "current_query_id"; - static constexpr const char *Parameters = ""; - static constexpr const char *Description = "Get the current query_id"; - static constexpr const char *Example = "current_transaction_id('Hello')"; - static constexpr const char *Categories = ""; - - static ScalarFunction GetFunction(); -}; - } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/function/table/arrow.hpp b/src/duckdb/src/include/duckdb/function/table/arrow.hpp index 08756ebbc..106c485e5 100644 --- a/src/duckdb/src/include/duckdb/function/table/arrow.hpp +++ b/src/duckdb/src/include/duckdb/function/table/arrow.hpp @@ -133,6 +133,7 @@ struct ArrowScanLocalState : public LocalTableFunctionState { } public: + unique_ptr stream; shared_ptr chunk; idx_t chunk_offset = 0; idx_t batch_index = 0; diff --git a/src/duckdb/src/include/duckdb/function/table/read_csv.hpp b/src/duckdb/src/include/duckdb/function/table/read_csv.hpp index 22fcee9fa..67ab686b3 100644 --- a/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +++ b/src/duckdb/src/include/duckdb/function/table/read_csv.hpp @@ -8,7 +8,7 @@ #pragma once -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/execution/operator/csv_scanner/csv_buffer.hpp" #include "duckdb/execution/operator/csv_scanner/csv_buffer_manager.hpp" #include "duckdb/execution/operator/csv_scanner/csv_file_handle.hpp" @@ -30,6 +30,8 @@ class ReadCSV { }; struct BaseCSVData : public TableFunctionData { + //! The file path of the CSV file to read or write + vector files; //! The CSV reader options CSVReaderOptions options; //! Offsets for generated columns @@ -49,8 +51,6 @@ struct WriteCSVData : public BaseCSVData { } } - //! The file path of the CSV file to read or write - vector files; //! The SQL types to write vector sql_types; //! The newline string to write @@ -79,44 +79,38 @@ struct ColumnInfo { struct ReadCSVData : public BaseCSVData { ReadCSVData(); + //! The expected SQL types to read from the file + vector csv_types; + //! The expected SQL names to be read from the file + vector csv_names; //! If the sql types from the file were manually set vector manually_set; + //! The expected SQL types to be returned from the read - including added constants (e.g. filename, hive partitions) + vector return_types; + //! The expected SQL names to be returned from the read - including added constants (e.g. filename, hive partitions) + vector return_names; //! The buffer manager (if any): this is used when automatic detection is used during binding. //! In this case, some CSV buffers have already been read and can be reused. shared_ptr buffer_manager; - //! Column info (used for union reader serialization) + unique_ptr initial_reader; + //! The union readers are created (when csv union_by_name option is on) during binding + //! Those readers can be re-used during ReadCSVFunction + vector> union_readers; + //! Reader bind data + MultiFileReaderBindData reader_bind; + vector column_info; - //! The CSV schema, in case there is a unified schema that all files must read - CSVSchema csv_schema; + void Initialize(unique_ptr &reader) { + this->initial_reader = std::move(reader); + } + void Initialize(ClientContext &, unique_ptr &data) { + this->initial_reader = std::move(data->reader); + } void FinalizeRead(ClientContext &context); -}; - -struct SerializedCSVReaderOptions { - SerializedCSVReaderOptions() = default; - SerializedCSVReaderOptions(CSVReaderOptions options, MultiFileOptions file_options); - SerializedCSVReaderOptions(CSVOption single_byte_delimiter, const CSVOption &multi_byte_delimiter); - - CSVReaderOptions options; - MultiFileOptions file_options; - - void Serialize(Serializer &serializer) const; - static SerializedCSVReaderOptions Deserialize(Deserializer &deserializer); -}; - -struct SerializedReadCSVData { - vector files; - vector csv_types; - vector csv_names; - vector return_types; - vector return_names; - idx_t filename_col_idx; - SerializedCSVReaderOptions options; - MultiFileReaderBindData reader_bind; - vector column_info; void Serialize(Serializer &serializer) const; - static SerializedReadCSVData Deserialize(Deserializer &deserializer); + static unique_ptr Deserialize(Deserializer &deserializer); }; struct CSVCopyFunction { diff --git a/src/duckdb/src/include/duckdb/function/table/system_functions.hpp b/src/duckdb/src/include/duckdb/function/table/system_functions.hpp index 623ca7458..c339b386d 100644 --- a/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +++ b/src/duckdb/src/include/duckdb/function/table/system_functions.hpp @@ -75,10 +75,6 @@ struct DuckDBExtensionsFun { static void RegisterFunction(BuiltinFunctions &set); }; -struct DuckDBPreparedStatementsFun { - static void RegisterFunction(BuiltinFunctions &set); -}; - struct DuckDBFunctionsFun { static void RegisterFunction(BuiltinFunctions &set); }; diff --git a/src/duckdb/src/include/duckdb/function/table_function.hpp b/src/duckdb/src/include/duckdb/function/table_function.hpp index c9f9d7dae..6293100ef 100644 --- a/src/duckdb/src/include/duckdb/function/table_function.hpp +++ b/src/duckdb/src/include/duckdb/function/table_function.hpp @@ -12,12 +12,11 @@ #include "duckdb/common/optional_ptr.hpp" #include "duckdb/execution/execution_context.hpp" #include "duckdb/function/function.hpp" +#include "duckdb/planner/bind_context.hpp" #include "duckdb/planner/logical_operator.hpp" #include "duckdb/storage/statistics/node_statistics.hpp" #include "duckdb/common/column_index.hpp" -#include "duckdb/common/table_column.hpp" #include "duckdb/function/partition_stats.hpp" -#include "duckdb/common/exception/binder_exception.hpp" #include @@ -28,9 +27,7 @@ class LogicalDependencyList; class LogicalGet; class TableFunction; class TableFilterSet; -class TableFunctionRef; class TableCatalogEntry; -class SampleOptions; struct MultiFileReader; struct OperatorPartitionData; struct OperatorPartitionInfo; @@ -181,20 +178,6 @@ struct TableFunctionToStringInput { optional_ptr bind_data; }; -struct TableFunctionDynamicToStringInput { - TableFunctionDynamicToStringInput(const TableFunction &table_function_p, - optional_ptr bind_data_p, - optional_ptr local_state_p, - optional_ptr global_state_p) - : table_function(table_function_p), bind_data(bind_data_p), local_state(local_state_p), - global_state(global_state_p) { - } - const TableFunction &table_function; - optional_ptr bind_data; - optional_ptr local_state; - optional_ptr global_state; -}; - struct TableFunctionGetPartitionInput { public: TableFunctionGetPartitionInput(optional_ptr bind_data_p, @@ -296,8 +279,6 @@ typedef void (*table_function_pushdown_complex_filter_t)(ClientContext &context, FunctionData *bind_data, vector> &filters); typedef InsertionOrderPreservingMap (*table_function_to_string_t)(TableFunctionToStringInput &input); -typedef InsertionOrderPreservingMap (*table_function_dynamic_to_string_t)( - TableFunctionDynamicToStringInput &input); typedef void (*table_function_serialize_t)(Serializer &serializer, const optional_ptr bind_data, const TableFunction &function); @@ -311,9 +292,6 @@ typedef TablePartitionInfo (*table_function_get_partition_info_t)(ClientContext typedef vector (*table_function_get_partition_stats_t)(ClientContext &context, GetPartitionStatsInput &input); -typedef virtual_column_map_t (*table_function_get_virtual_columns_t)(ClientContext &context, - optional_ptr bind_data); - //! When to call init_global to initialize the table function enum class TableFunctionInitialization { INITIALIZE_ON_EXECUTE, INITIALIZE_ON_SCHEDULE }; @@ -364,10 +342,8 @@ class TableFunction : public SimpleNamedParameterFunction { // NOLINT: work-arou //! (Optional) pushdown a set of arbitrary filter expressions, rather than only simple comparisons with a constant //! Any functions remaining in the expression list will be pushed as a regular filter after the scan table_function_pushdown_complex_filter_t pushdown_complex_filter; - //! (Optional) function for rendering the operator to a string in explain/profiling output (invoked pre-execution) + //! (Optional) function for rendering the operator to a string in profiling output table_function_to_string_t to_string; - //! (Optional) function for rendering the operator to a string in profiling output (invoked post-execution) - table_function_dynamic_to_string_t dynamic_to_string; //! (Optional) return how much of the table we have scanned up to this point (% of the data) table_function_progress_t table_scan_progress; //! (Optional) returns the partition info of the current scan operator @@ -384,8 +360,6 @@ class TableFunction : public SimpleNamedParameterFunction { // NOLINT: work-arou table_function_get_partition_info_t get_partition_info; //! (Optional) get a list of all the partition stats of the table table_function_get_partition_stats_t get_partition_stats; - //! (Optional) returns a list of virtual columns emitted by the table function - table_function_get_virtual_columns_t get_virtual_columns; table_function_serialize_t serialize; table_function_deserialize_t deserialize; @@ -403,8 +377,6 @@ class TableFunction : public SimpleNamedParameterFunction { // NOLINT: work-arou //! Whether or not the table function supports sampling pushdown. If not supported a sample will be taken after the //! table function. bool sampling_pushdown; - //! Whether or not the table function supports late materialization - bool late_materialization; //! Additional function info, passed to the bind shared_ptr function_info; diff --git a/src/duckdb/src/include/duckdb/logging/log_manager.hpp b/src/duckdb/src/include/duckdb/logging/log_manager.hpp index 6f414d9ef..90c6384c3 100644 --- a/src/duckdb/src/include/duckdb/logging/log_manager.hpp +++ b/src/duckdb/src/include/duckdb/logging/log_manager.hpp @@ -54,8 +54,6 @@ class LogManager : public enable_shared_from_this { DUCKDB_API void SetDisabledLogTypes(unordered_set &disabled_log_types); DUCKDB_API void SetLogStorage(DatabaseInstance &db, const string &storage_name); - DUCKDB_API void TruncateLogStorage(); - DUCKDB_API LogConfig GetConfig(); protected: diff --git a/src/duckdb/src/include/duckdb/logging/log_storage.hpp b/src/duckdb/src/include/duckdb/logging/log_storage.hpp index d30d370a7..f99175b59 100644 --- a/src/duckdb/src/include/duckdb/logging/log_storage.hpp +++ b/src/duckdb/src/include/duckdb/logging/log_storage.hpp @@ -61,8 +61,6 @@ class LogStorage { DUCKDB_API virtual unique_ptr CreateScanContextsState() const; DUCKDB_API virtual bool ScanContexts(LogStorageScanState &state, DataChunk &result) const; DUCKDB_API virtual void InitializeScanContexts(LogStorageScanState &state) const; - - DUCKDB_API virtual void Truncate(); }; class StdOutLogStorage : public LogStorage { @@ -75,8 +73,6 @@ class StdOutLogStorage : public LogStorage { const RegisteredLoggingContext &context) override; void WriteLogEntries(DataChunk &chunk, const RegisteredLoggingContext &context) override; void Flush() override; - - void Truncate() override; }; class InMemoryLogStorageScanState : public LogStorageScanState { @@ -98,8 +94,6 @@ class InMemoryLogStorage : public LogStorage { void WriteLogEntries(DataChunk &chunk, const RegisteredLoggingContext &context) override; void Flush() override; - void Truncate() override; - //! LogStorage API: READING bool CanScan() override; @@ -112,7 +106,6 @@ class InMemoryLogStorage : public LogStorage { protected: void WriteLoggingContext(const RegisteredLoggingContext &context); - void ResetBuffers(); protected: mutable mutex lock; diff --git a/src/duckdb/src/include/duckdb/logging/logging.hpp b/src/duckdb/src/include/duckdb/logging/logging.hpp index 36cc7126f..6d6c4f2e8 100644 --- a/src/duckdb/src/include/duckdb/logging/logging.hpp +++ b/src/duckdb/src/include/duckdb/logging/logging.hpp @@ -68,10 +68,9 @@ struct LoggingContext { LogContextScope scope; - optional_idx thread_id; - optional_idx connection_id; + optional_idx thread; + optional_idx client_context; optional_idx transaction_id; - optional_idx query_id; }; struct RegisteredLoggingContext { diff --git a/src/duckdb/src/include/duckdb/main/attached_database.hpp b/src/duckdb/src/include/duckdb/main/attached_database.hpp index 2d5a59741..098edf9f7 100644 --- a/src/duckdb/src/include/duckdb/main/attached_database.hpp +++ b/src/duckdb/src/include/duckdb/main/attached_database.hpp @@ -64,7 +64,7 @@ class AttachedDatabase : public CatalogEntry { ~AttachedDatabase() override; //! Initializes the catalog and storage of the attached database. - void Initialize(optional_ptr context = nullptr, StorageOptions options = StorageOptions()); + void Initialize(StorageOptions options = StorageOptions()); void Close(); Catalog &ParentCatalog() override; diff --git a/src/duckdb/src/include/duckdb/main/capi/extension_api.hpp b/src/duckdb/src/include/duckdb/main/capi/extension_api.hpp index 7c298d4f9..71e6d18bc 100644 --- a/src/duckdb/src/include/duckdb/main/capi/extension_api.hpp +++ b/src/duckdb/src/include/duckdb/main/capi/extension_api.hpp @@ -471,15 +471,6 @@ typedef struct { duckdb_state (*duckdb_append_default_to_chunk)(duckdb_appender appender, duckdb_data_chunk chunk, idx_t col, idx_t row); - // New string functions that are added - - char *(*duckdb_value_to_string)(duckdb_value value); - // An API to create new vector types - - void (*duckdb_slice_vector)(duckdb_vector vector, duckdb_selection_vector selection, idx_t len); - duckdb_selection_vector (*duckdb_create_selection_vector)(idx_t size); - void (*duckdb_destroy_selection_vector)(duckdb_selection_vector vector); - sel_t *(*duckdb_selection_vector_get_data_ptr)(duckdb_selection_vector vector); } duckdb_ext_api_v1; //===--------------------------------------------------------------------===// @@ -895,11 +886,6 @@ inline duckdb_ext_api_v1 CreateAPIv1() { result.duckdb_get_or_create_from_cache = duckdb_get_or_create_from_cache; result.duckdb_destroy_instance_cache = duckdb_destroy_instance_cache; result.duckdb_append_default_to_chunk = duckdb_append_default_to_chunk; - result.duckdb_value_to_string = duckdb_value_to_string; - result.duckdb_slice_vector = duckdb_slice_vector; - result.duckdb_create_selection_vector = duckdb_create_selection_vector; - result.duckdb_destroy_selection_vector = duckdb_destroy_selection_vector; - result.duckdb_selection_vector_get_data_ptr = duckdb_selection_vector_get_data_ptr; return result; } diff --git a/src/duckdb/src/include/duckdb/main/client_config.hpp b/src/duckdb/src/include/duckdb/main/client_config.hpp index 4398a7885..9cedb4074 100644 --- a/src/duckdb/src/include/duckdb/main/client_config.hpp +++ b/src/duckdb/src/include/duckdb/main/client_config.hpp @@ -101,8 +101,6 @@ struct ClientConfig { idx_t nested_loop_join_threshold = 5; //! The number of rows we need on either table to choose a merge join over an IE join idx_t merge_join_threshold = 1000; - //! The maximum number of rows to use the nested loop join implementation - idx_t asof_loop_join_threshold = 64; //! The maximum amount of memory to keep buffered in a streaming query result. Default: 1mb. idx_t streaming_buffer_size = 1000000; diff --git a/src/duckdb/src/include/duckdb/main/client_context.hpp b/src/duckdb/src/include/duckdb/main/client_context.hpp index 490b30e00..ae0b93740 100644 --- a/src/duckdb/src/include/duckdb/main/client_context.hpp +++ b/src/duckdb/src/include/duckdb/main/client_context.hpp @@ -207,8 +207,6 @@ class ClientContext : public enable_shared_from_this { //! Returns the current query string (if any) const string &GetCurrentQuery(); - connection_t GetConnectionId() const; - //! Fetch a list of table names that are required for a given query DUCKDB_API unordered_set GetTableNames(const string &query); @@ -307,8 +305,6 @@ class ClientContext : public enable_shared_from_this { unique_ptr active_query; //! The current query progress QueryProgress query_progress; - //! The connection corresponding to this client context - connection_t connection_id; }; class ClientContextLock { diff --git a/src/duckdb/src/include/duckdb/main/config.hpp b/src/duckdb/src/include/duckdb/main/config.hpp index 1e447bdc5..064c794b6 100644 --- a/src/duckdb/src/include/duckdb/main/config.hpp +++ b/src/duckdb/src/include/duckdb/main/config.hpp @@ -37,7 +37,6 @@ #include "duckdb/storage/compression/bitpacking.hpp" #include "duckdb/function/encoding_function.hpp" #include "duckdb/logging/log_manager.hpp" -#include "duckdb/common/enums/debug_vector_verification.hpp" namespace duckdb { @@ -280,8 +279,6 @@ struct DBConfigOptions { idx_t catalog_error_max_schemas = 100; //! Whether or not to always write to the WAL file, even if this is not required bool debug_skip_checkpoint_on_commit = false; - //! Vector verification to enable (debug setting only) - DebugVectorVerification debug_verify_vector = DebugVectorVerification::NONE; //! The maximum amount of vacuum tasks to schedule during a checkpoint idx_t max_vacuum_tasks = 100; //! Paths that are explicitly allowed, even if enable_external_access is false @@ -290,12 +287,6 @@ struct DBConfigOptions { set allowed_directories; //! The log configuration LogConfig log_config = LogConfig(); - //! Partially process tasks before rescheduling - allows for more scheduler fairness between separate queries -#ifdef DUCKDB_ALTERNATIVE_VERIFY - bool scheduler_process_partial = true; -#else - bool scheduler_process_partial = false; -#endif bool operator==(const DBConfigOptions &other) const; }; diff --git a/src/duckdb/src/include/duckdb/main/connection.hpp b/src/duckdb/src/include/duckdb/main/connection.hpp index fc50cdc7a..f5b46717c 100644 --- a/src/duckdb/src/include/duckdb/main/connection.hpp +++ b/src/duckdb/src/include/duckdb/main/connection.hpp @@ -135,8 +135,6 @@ class Connection { //! Returns a relation that produces a table from this connection DUCKDB_API shared_ptr Table(const string &tname); DUCKDB_API shared_ptr Table(const string &schema_name, const string &table_name); - DUCKDB_API shared_ptr Table(const string &catalog_name, const string &schema_name, - const string &table_name); //! Returns a relation that produces a view from this connection DUCKDB_API shared_ptr View(const string &tname); DUCKDB_API shared_ptr View(const string &schema_name, const string &table_name); @@ -246,10 +244,6 @@ class Connection { } // NOLINTEND -protected: - //! Identified used to uniquely identify connections to the database. - connection_t connection_id; - private: unique_ptr QueryParamsRecursive(const string &query, vector &values); diff --git a/src/duckdb/src/include/duckdb/main/connection_manager.hpp b/src/duckdb/src/include/duckdb/main/connection_manager.hpp index 7fa5c66b5..45f2bd965 100644 --- a/src/duckdb/src/include/duckdb/main/connection_manager.hpp +++ b/src/duckdb/src/include/duckdb/main/connection_manager.hpp @@ -16,7 +16,6 @@ namespace duckdb { class ClientContext; class DatabaseInstance; -class Connection; class ConnectionManager { public: @@ -31,8 +30,6 @@ class ConnectionManager { } idx_t GetConnectionCount() const; - void AssignConnectionId(Connection &connection); - static ConnectionManager &Get(DatabaseInstance &db); static ConnectionManager &Get(ClientContext &context); @@ -40,8 +37,6 @@ class ConnectionManager { mutex connections_lock; reference_map_t> connections; atomic connection_count; - - atomic current_connection_id; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/main/database_manager.hpp b/src/duckdb/src/include/duckdb/main/database_manager.hpp index dec1c89f0..c193c979f 100644 --- a/src/duckdb/src/include/duckdb/main/database_manager.hpp +++ b/src/duckdb/src/include/duckdb/main/database_manager.hpp @@ -78,12 +78,6 @@ class DatabaseManager { transaction_t ActiveQueryNumber() const { return current_query_number; } - transaction_t GetNewTransactionNumber() { - return current_transaction_id++; - } - transaction_t ActiveTransactionNumber() const { - return current_transaction_id; - } idx_t NextOid() { return next_oid++; } @@ -107,8 +101,6 @@ class DatabaseManager { atomic next_oid; //! The current query number atomic current_query_number; - //! The current transaction number - atomic current_transaction_id; //! The current default database string default_database; diff --git a/src/duckdb/src/include/duckdb/main/extension_entries.hpp b/src/duckdb/src/include/duckdb/main/extension_entries.hpp index 9e906a2a0..89391bc42 100644 --- a/src/duckdb/src/include/duckdb/main/extension_entries.hpp +++ b/src/duckdb/src/include/duckdb/main/extension_entries.hpp @@ -512,6 +512,7 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = { {"rtree_index_dump", "spatial", CatalogType::TABLE_FUNCTION_ENTRY}, {"rtree_index_scan", "spatial", CatalogType::TABLE_FUNCTION_ENTRY}, {"rtrim", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, + {"scan_arrow_ipc", "arrow", CatalogType::TABLE_FUNCTION_ENTRY}, {"sem", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY}, {"set_bit", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, {"setseed", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, @@ -688,6 +689,7 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = { {"tanh", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, {"text", "excel", CatalogType::SCALAR_FUNCTION_ENTRY}, {"timetz_byte_comparable", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, + {"to_arrow_ipc", "arrow", CatalogType::TABLE_FUNCTION_ENTRY}, {"to_base", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, {"to_base64", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, {"to_binary", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, @@ -731,10 +733,6 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = { {"url_decode", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, {"url_encode", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, {"uuid", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, - {"uuid_extract_timestamp", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, - {"uuid_extract_version", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, - {"uuidv4", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, - {"uuidv7", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY}, {"var_pop", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY}, {"var_samp", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY}, {"variance", "core_functions", CatalogType::AGGREGATE_FUNCTION_ENTRY}, @@ -748,211 +746,211 @@ static constexpr ExtensionFunctionEntry EXTENSION_FUNCTIONS[] = { }; // END_OF_EXTENSION_FUNCTIONS static constexpr ExtensionFunctionOverloadEntry EXTENSION_FUNCTION_OVERLOADS[] = { - {"age", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>INTERVAL"}, - {"age", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP,TIMESTAMP]>INTERVAL"}, - {"age", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>INTERVAL"}, - {"age", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ,TIMESTAMPTZ]>INTERVAL"}, - {"century", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"century", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"century", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"century", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"date_diff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE,DATE]>BIGINT"}, - {"date_diff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIME,TIME]>BIGINT"}, - {"date_diff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP,TIMESTAMP]>BIGINT"}, - {"date_diff", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ]>BIGINT"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',DATE]>STRUCT()"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',INTERVAL]>STRUCT()"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIME]>STRUCT()"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIMESTAMP]>STRUCT()"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIMETZ]>STRUCT()"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE]>BIGINT"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,INTERVAL]>BIGINT"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIME]>BIGINT"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP]>BIGINT"}, - {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMETZ]>BIGINT"}, - {"date_part", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIMESTAMPTZ]>STRUCT()"}, - {"date_part", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ]>BIGINT"}, - {"date_sub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE,DATE]>BIGINT"}, - {"date_sub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIME,TIME]>BIGINT"}, - {"date_sub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP,TIMESTAMP]>BIGINT"}, - {"date_sub", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ]>BIGINT"}, - {"date_trunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE]>TIMESTAMP"}, - {"date_trunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,INTERVAL]>INTERVAL"}, - {"date_trunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP]>TIMESTAMP"}, - {"date_trunc", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ]>TIMESTAMPTZ"}, - {"datediff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE,DATE]>BIGINT"}, - {"datediff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIME,TIME]>BIGINT"}, - {"datediff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP,TIMESTAMP]>BIGINT"}, - {"datediff", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ]>BIGINT"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',DATE]>STRUCT()"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',INTERVAL]>STRUCT()"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIME]>STRUCT()"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIMESTAMP]>STRUCT()"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIMETZ]>STRUCT()"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE]>BIGINT"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,INTERVAL]>BIGINT"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIME]>BIGINT"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP]>BIGINT"}, - {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMETZ]>BIGINT"}, - {"datepart", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "['VARCHAR[]',TIMESTAMPTZ]>STRUCT()"}, - {"datepart", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ]>BIGINT"}, - {"datesub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE,DATE]>BIGINT"}, - {"datesub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIME,TIME]>BIGINT"}, - {"datesub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP,TIMESTAMP]>BIGINT"}, - {"datesub", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ]>BIGINT"}, - {"datetrunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,DATE]>TIMESTAMP"}, - {"datetrunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,INTERVAL]>INTERVAL"}, - {"datetrunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP]>TIMESTAMP"}, - {"datetrunc", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ]>TIMESTAMPTZ"}, - {"day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"day", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"dayname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>VARCHAR"}, - {"dayname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>VARCHAR"}, - {"dayname", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>VARCHAR"}, - {"dayofmonth", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"dayofmonth", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"dayofmonth", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"dayofmonth", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"dayofweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"dayofweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"dayofweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"dayofweek", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"dayofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"dayofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"dayofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"dayofyear", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"decade", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"decade", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"decade", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"decade", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>DOUBLE"}, - {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>DOUBLE"}, - {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIME]>DOUBLE"}, - {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>DOUBLE"}, - {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMETZ]>DOUBLE"}, - {"epoch", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>DOUBLE"}, - {"era", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"era", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"era", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"era", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"generate_series", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[BIGINT]>BIGINT[]"}, - {"generate_series", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[BIGINT,BIGINT]>BIGINT[]"}, - {"generate_series", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[BIGINT,BIGINT,BIGINT]>BIGINT[]"}, + {"age", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>INTERVAL"}, + {"age", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP,TIMESTAMP>INTERVAL"}, + {"age", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>INTERVAL"}, + {"age", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ,TIMESTAMPTZ>INTERVAL"}, + {"century", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"century", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"century", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"century", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"date_diff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE,DATE>BIGINT"}, + {"date_diff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIME,TIME>BIGINT"}, + {"date_diff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP,TIMESTAMP>BIGINT"}, + {"date_diff", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ>BIGINT"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE>BIGINT"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,INTERVAL>BIGINT"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIME>BIGINT"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP>BIGINT"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMETZ>BIGINT"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],DATE>STRUCT()"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],INTERVAL>STRUCT()"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIME>STRUCT()"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIMESTAMP>STRUCT()"}, + {"date_part", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIMETZ>STRUCT()"}, + {"date_part", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ>BIGINT"}, + {"date_part", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIMESTAMPTZ>STRUCT()"}, + {"date_sub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE,DATE>BIGINT"}, + {"date_sub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIME,TIME>BIGINT"}, + {"date_sub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP,TIMESTAMP>BIGINT"}, + {"date_sub", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ>BIGINT"}, + {"date_trunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE>TIMESTAMP"}, + {"date_trunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,INTERVAL>INTERVAL"}, + {"date_trunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP>TIMESTAMP"}, + {"date_trunc", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ>TIMESTAMPTZ"}, + {"datediff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE,DATE>BIGINT"}, + {"datediff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIME,TIME>BIGINT"}, + {"datediff", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP,TIMESTAMP>BIGINT"}, + {"datediff", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ>BIGINT"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE>BIGINT"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,INTERVAL>BIGINT"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIME>BIGINT"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP>BIGINT"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMETZ>BIGINT"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],DATE>STRUCT()"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],INTERVAL>STRUCT()"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIME>STRUCT()"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIMESTAMP>STRUCT()"}, + {"datepart", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIMETZ>STRUCT()"}, + {"datepart", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ>BIGINT"}, + {"datepart", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR[],TIMESTAMPTZ>STRUCT()"}, + {"datesub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE,DATE>BIGINT"}, + {"datesub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIME,TIME>BIGINT"}, + {"datesub", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP,TIMESTAMP>BIGINT"}, + {"datesub", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ,TIMESTAMPTZ>BIGINT"}, + {"datetrunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,DATE>TIMESTAMP"}, + {"datetrunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,INTERVAL>INTERVAL"}, + {"datetrunc", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP>TIMESTAMP"}, + {"datetrunc", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ>TIMESTAMPTZ"}, + {"day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"day", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"dayname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>VARCHAR"}, + {"dayname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>VARCHAR"}, + {"dayname", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>VARCHAR"}, + {"dayofmonth", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"dayofmonth", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"dayofmonth", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"dayofmonth", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"dayofweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"dayofweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"dayofweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"dayofweek", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"dayofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"dayofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"dayofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"dayofyear", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"decade", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"decade", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"decade", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"decade", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>DOUBLE"}, + {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>DOUBLE"}, + {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIME>DOUBLE"}, + {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>DOUBLE"}, + {"epoch", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMETZ>DOUBLE"}, + {"epoch", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>DOUBLE"}, + {"era", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"era", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"era", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"era", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"generate_series", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "BIGINT>BIGINT[]"}, + {"generate_series", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "BIGINT,BIGINT>BIGINT[]"}, + {"generate_series", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "BIGINT,BIGINT,BIGINT>BIGINT[]"}, {"generate_series", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, - "[TIMESTAMP,TIMESTAMP,INTERVAL]>TIMESTAMP[]"}, - {"generate_series", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ,TIMESTAMPTZ,INTERVAL]>TIMESTAMPTZ[]"}, - {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIME]>BIGINT"}, - {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMETZ]>BIGINT"}, - {"hour", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"isodow", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"isodow", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"isodow", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"isodow", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"isoyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"isoyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"isoyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"isoyear", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"julian", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>DOUBLE"}, - {"julian", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>DOUBLE"}, - {"julian", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>DOUBLE"}, - {"last_day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>DATE"}, - {"last_day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>DATE"}, - {"last_day", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>DATE"}, - {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIME]>BIGINT"}, - {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMETZ]>BIGINT"}, - {"microsecond", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"millennium", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"millennium", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"millennium", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"millennium", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIME]>BIGINT"}, - {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMETZ]>BIGINT"}, - {"millisecond", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIME]>BIGINT"}, - {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMETZ]>BIGINT"}, - {"minute", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"month", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"month", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"month", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"month", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"monthname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>VARCHAR"}, - {"monthname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>VARCHAR"}, - {"monthname", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>VARCHAR"}, - {"quarter", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"quarter", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"quarter", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"quarter", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[BIGINT]>BIGINT[]"}, - {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[BIGINT,BIGINT]>BIGINT[]"}, - {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[BIGINT,BIGINT,BIGINT]>BIGINT[]"}, - {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP,TIMESTAMP,INTERVAL]>TIMESTAMP[]"}, - {"range", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ,TIMESTAMPTZ,INTERVAL]>TIMESTAMPTZ[]"}, - {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIME]>BIGINT"}, - {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMETZ]>BIGINT"}, - {"second", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,DATE]>DATE"}, - {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,DATE,DATE]>DATE"}, - {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,DATE,INTERVAL]>DATE"}, - {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMESTAMP]>TIMESTAMP"}, - {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMESTAMP,INTERVAL]>TIMESTAMP"}, - {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMESTAMP,TIMESTAMP]>TIMESTAMP"}, - {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMESTAMPTZ]>TIMESTAMPTZ"}, - {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMESTAMPTZ,INTERVAL]>TIMESTAMPTZ"}, - {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMESTAMPTZ,TIMESTAMPTZ]>TIMESTAMPTZ"}, - {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMESTAMPTZ,VARCHAR]>TIMESTAMPTZ"}, - {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL,TIMETZ]>TIMETZ"}, - {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMP]>TIMESTAMPTZ"}, - {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMESTAMPTZ]>TIMESTAMP"}, - {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[VARCHAR,TIMETZ]>TIMETZ"}, - {"timezone_hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"timezone_hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"timezone_hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"timezone_hour", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"timezone_minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"timezone_minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"timezone_minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"timezone_minute", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"week", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"week", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"week", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"week", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"weekday", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"weekday", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"weekday", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"weekday", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"weekofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"weekofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"weekofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"weekofyear", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"year", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"year", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"year", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"year", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, - {"yearweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[DATE]>BIGINT"}, - {"yearweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[INTERVAL]>BIGINT"}, - {"yearweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMP]>BIGINT"}, - {"yearweek", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "[TIMESTAMPTZ]>BIGINT"}, + "TIMESTAMP,TIMESTAMP,INTERVAL>TIMESTAMP[]"}, + {"generate_series", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ,TIMESTAMPTZ,INTERVAL>TIMESTAMPTZ[]"}, + {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIME>BIGINT"}, + {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMETZ>BIGINT"}, + {"hour", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"isodow", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"isodow", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"isodow", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"isodow", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"isoyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"isoyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"isoyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"isoyear", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"julian", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>DOUBLE"}, + {"julian", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>DOUBLE"}, + {"julian", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>DOUBLE"}, + {"last_day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>DATE"}, + {"last_day", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>DATE"}, + {"last_day", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>DATE"}, + {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIME>BIGINT"}, + {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"microsecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMETZ>BIGINT"}, + {"microsecond", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"millennium", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"millennium", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"millennium", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"millennium", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIME>BIGINT"}, + {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"millisecond", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMETZ>BIGINT"}, + {"millisecond", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIME>BIGINT"}, + {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMETZ>BIGINT"}, + {"minute", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"month", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"month", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"month", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"month", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"monthname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>VARCHAR"}, + {"monthname", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>VARCHAR"}, + {"monthname", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>VARCHAR"}, + {"quarter", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"quarter", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"quarter", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"quarter", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "BIGINT>BIGINT[]"}, + {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "BIGINT,BIGINT>BIGINT[]"}, + {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "BIGINT,BIGINT,BIGINT>BIGINT[]"}, + {"range", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP,TIMESTAMP,INTERVAL>TIMESTAMP[]"}, + {"range", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ,TIMESTAMPTZ,INTERVAL>TIMESTAMPTZ[]"}, + {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIME>BIGINT"}, + {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"second", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMETZ>BIGINT"}, + {"second", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,DATE>DATE"}, + {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,DATE,DATE>DATE"}, + {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,DATE,INTERVAL>DATE"}, + {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMESTAMP>TIMESTAMP"}, + {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMESTAMP,INTERVAL>TIMESTAMP"}, + {"time_bucket", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMESTAMP,TIMESTAMP>TIMESTAMP"}, + {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMESTAMPTZ>TIMESTAMPTZ"}, + {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMESTAMPTZ,INTERVAL>TIMESTAMPTZ"}, + {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMESTAMPTZ,TIMESTAMPTZ>TIMESTAMPTZ"}, + {"time_bucket", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMESTAMPTZ,VARCHAR>TIMESTAMPTZ"}, + {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL,TIMETZ>TIMETZ"}, + {"timezone", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMP>TIMESTAMPTZ"}, + {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMESTAMPTZ>TIMESTAMP"}, + {"timezone", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "VARCHAR,TIMETZ>TIMETZ"}, + {"timezone_hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"timezone_hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"timezone_hour", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"timezone_hour", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"timezone_minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"timezone_minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"timezone_minute", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"timezone_minute", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"week", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"week", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"week", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"week", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"weekday", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"weekday", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"weekday", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"weekday", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"weekofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"weekofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"weekofyear", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"weekofyear", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"year", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"year", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"year", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"year", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, + {"yearweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "DATE>BIGINT"}, + {"yearweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "INTERVAL>BIGINT"}, + {"yearweek", "core_functions", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMP>BIGINT"}, + {"yearweek", "icu", CatalogType::SCALAR_FUNCTION_ENTRY, "TIMESTAMPTZ>BIGINT"}, }; // END_OF_EXTENSION_FUNCTION_OVERLOADS static constexpr ExtensionEntry EXTENSION_SETTINGS[] = { @@ -1001,6 +999,7 @@ static constexpr ExtensionEntry EXTENSION_SETTINGS[] = { {"prefetch_all_parquet_files", "parquet"}, {"s3_access_key_id", "httpfs"}, {"s3_endpoint", "httpfs"}, + {"s3_kms_key_id", "httpfs"}, {"s3_region", "httpfs"}, {"s3_secret_access_key", "httpfs"}, {"s3_session_token", "httpfs"}, diff --git a/src/duckdb/src/include/duckdb/main/prepared_statement_data.hpp b/src/duckdb/src/include/duckdb/main/prepared_statement_data.hpp index b40a9addb..40d741545 100644 --- a/src/duckdb/src/include/duckdb/main/prepared_statement_data.hpp +++ b/src/duckdb/src/include/duckdb/main/prepared_statement_data.hpp @@ -19,7 +19,7 @@ namespace duckdb { class CatalogEntry; class ClientContext; -class PhysicalPlan; +class PhysicalOperator; class SQLStatement; class PreparedStatementData { @@ -30,9 +30,8 @@ class PreparedStatementData { StatementType statement_type; //! The unbound SQL statement that was prepared unique_ptr unbound_statement; - - //! The physical plan. - unique_ptr physical_plan; + //! The fully prepared physical plan of the prepared statement + unique_ptr plan; //! The result names of the transaction vector names; diff --git a/src/duckdb/src/include/duckdb/main/query_profiler.hpp b/src/duckdb/src/include/duckdb/main/query_profiler.hpp index 7127e6d7d..7ac69cd33 100644 --- a/src/duckdb/src/include/duckdb/main/query_profiler.hpp +++ b/src/duckdb/src/include/duckdb/main/query_profiler.hpp @@ -71,13 +71,10 @@ class OperatorProfiler { public: DUCKDB_API void StartOperator(optional_ptr phys_op); DUCKDB_API void EndOperator(optional_ptr chunk); - DUCKDB_API void FinishSource(GlobalSourceState &gstate, LocalSourceState &lstate); //! Adds the timings in the OperatorProfiler (tree) to the QueryProfiler (tree). DUCKDB_API void Flush(const PhysicalOperator &phys_op); DUCKDB_API OperatorInformation &GetOperatorInfo(const PhysicalOperator &phys_op); - DUCKDB_API bool OperatorInfoIsInitialized(const PhysicalOperator &phys_op); - DUCKDB_API void AddExtraInfo(InsertionOrderPreservingMap extra_info); public: ClientContext &context; diff --git a/src/duckdb/src/include/duckdb/main/query_result.hpp b/src/duckdb/src/include/duckdb/main/query_result.hpp index f85629428..af9e3817c 100644 --- a/src/duckdb/src/include/duckdb/main/query_result.hpp +++ b/src/duckdb/src/include/duckdb/main/query_result.hpp @@ -135,9 +135,6 @@ class QueryResult : public BaseQueryResult { QueryResultIterator &iterator; idx_t row; - bool IsNull(idx_t col_idx) const { - return iterator.chunk->GetValue(col_idx, row).IsNull(); - } template T GetValue(idx_t col_idx) const { return iterator.chunk->GetValue(col_idx, row).GetValue(); diff --git a/src/duckdb/src/include/duckdb/main/relation/delete_relation.hpp b/src/duckdb/src/include/duckdb/main/relation/delete_relation.hpp index c07445ba4..d72a48bd4 100644 --- a/src/duckdb/src/include/duckdb/main/relation/delete_relation.hpp +++ b/src/duckdb/src/include/duckdb/main/relation/delete_relation.hpp @@ -16,11 +16,10 @@ namespace duckdb { class DeleteRelation : public Relation { public: DeleteRelation(shared_ptr &context, unique_ptr condition, - string catalog_name, string schema_name, string table_name); + string schema_name, string table_name); vector columns; unique_ptr condition; - string catalog_name; string schema_name; string table_name; diff --git a/src/duckdb/src/include/duckdb/main/relation/update_relation.hpp b/src/duckdb/src/include/duckdb/main/relation/update_relation.hpp index 58ad203b2..f46739dde 100644 --- a/src/duckdb/src/include/duckdb/main/relation/update_relation.hpp +++ b/src/duckdb/src/include/duckdb/main/relation/update_relation.hpp @@ -16,12 +16,11 @@ namespace duckdb { class UpdateRelation : public Relation { public: UpdateRelation(shared_ptr &context, unique_ptr condition, - string catalog_name, string schema_name, string table_name, vector update_columns, + string schema_name, string table_name, vector update_columns, vector> expressions); vector columns; unique_ptr condition; - string catalog_name; string schema_name; string table_name; vector update_columns; diff --git a/src/duckdb/src/include/duckdb/main/secret/secret.hpp b/src/duckdb/src/include/duckdb/main/secret/secret.hpp index 40a9dab64..7d71522cb 100644 --- a/src/duckdb/src/include/duckdb/main/secret/secret.hpp +++ b/src/duckdb/src/include/duckdb/main/secret/secret.hpp @@ -17,7 +17,6 @@ namespace duckdb { class BaseSecret; struct SecretEntry; struct FileOpenerInfo; -struct CreateSecretInfo; //! Whether a secret is persistent or temporary enum class SecretPersistType : uint8_t { DEFAULT, TEMPORARY, PERSISTENT }; @@ -36,10 +35,6 @@ struct CreateSecretInput { vector scope; //! (optional) named parameter map, each create secret function has defined it's own set of these case_insensitive_map_t options; - //! how to handle conflicts - OnCreateConflict on_conflict; - //! persistence of secret - SecretPersistType persist_type; }; typedef unique_ptr (*secret_deserializer_t)(Deserializer &deserializer, BaseSecret base_secret); diff --git a/src/duckdb/src/include/duckdb/main/secret/secret_manager.hpp b/src/duckdb/src/include/duckdb/main/secret/secret_manager.hpp index 644c45aeb..69f03a663 100644 --- a/src/duckdb/src/include/duckdb/main/secret/secret_manager.hpp +++ b/src/duckdb/src/include/duckdb/main/secret/secret_manager.hpp @@ -119,9 +119,9 @@ class SecretManager { unique_ptr secret, OnCreateConflict on_conflict, SecretPersistType persist_type, const string &storage = ""); //! Create a secret from a CreateSecretInfo - DUCKDB_API unique_ptr CreateSecret(ClientContext &context, const CreateSecretInput &info); + DUCKDB_API unique_ptr CreateSecret(ClientContext &context, const CreateSecretInfo &info); //! The Bind for create secret is done by the secret manager - DUCKDB_API BoundStatement BindCreateSecret(CatalogTransaction transaction, CreateSecretInput &info); + DUCKDB_API BoundStatement BindCreateSecret(CatalogTransaction transaction, CreateSecretInfo &info); //! Lookup the best matching secret by matching the secret scopes to the path DUCKDB_API SecretMatch LookupSecret(CatalogTransaction transaction, const string &path, const string &type); //! Get a secret by name, optionally from a specific storage diff --git a/src/duckdb/src/include/duckdb/main/settings.hpp b/src/duckdb/src/include/duckdb/main/settings.hpp index 9be9ef482..b9c979dca 100644 --- a/src/duckdb/src/include/duckdb/main/settings.hpp +++ b/src/duckdb/src/include/duckdb/main/settings.hpp @@ -218,17 +218,6 @@ struct ArrowOutputListViewSetting { static Value GetSetting(const ClientContext &context); }; -struct AsofLoopJoinThresholdSetting { - using RETURN_TYPE = idx_t; - static constexpr const char *Name = "asof_loop_join_threshold"; - static constexpr const char *Description = - "The maximum number of rows we need on the left side of an ASOF join to use a nested loop join"; - static constexpr const char *InputType = "UBIGINT"; - static void SetLocal(ClientContext &context, const Value ¶meter); - static void ResetLocal(ClientContext &context); - static Value GetSetting(const ClientContext &context); -}; - struct AutoinstallExtensionRepositorySetting { using RETURN_TYPE = string; static constexpr const char *Name = "autoinstall_extension_repository"; @@ -367,16 +356,6 @@ struct DebugSkipCheckpointOnCommitSetting { static Value GetSetting(const ClientContext &context); }; -struct DebugVerifyVectorSetting { - using RETURN_TYPE = DebugVectorVerification; - static constexpr const char *Name = "debug_verify_vector"; - static constexpr const char *Description = "DEBUG SETTING: enable vector verification"; - static constexpr const char *InputType = "VARCHAR"; - static void SetGlobal(DatabaseInstance *db, DBConfig &config, const Value ¶meter); - static void ResetGlobal(DatabaseInstance *db, DBConfig &config); - static Value GetSetting(const ClientContext &context); -}; - struct DebugWindowModeSetting { using RETURN_TYPE = WindowAggregationMode; static constexpr const char *Name = "debug_window_mode"; @@ -1122,17 +1101,6 @@ struct ScalarSubqueryErrorOnMultipleRowsSetting { static Value GetSetting(const ClientContext &context); }; -struct SchedulerProcessPartialSetting { - using RETURN_TYPE = bool; - static constexpr const char *Name = "scheduler_process_partial"; - static constexpr const char *Description = - "Partially process tasks before rescheduling - allows for more scheduler fairness between separate queries"; - static constexpr const char *InputType = "BOOLEAN"; - static void SetGlobal(DatabaseInstance *db, DBConfig &config, const Value ¶meter); - static void ResetGlobal(DatabaseInstance *db, DBConfig &config); - static Value GetSetting(const ClientContext &context); -}; - struct SchemaSetting { using RETURN_TYPE = string; static constexpr const char *Name = "schema"; diff --git a/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp b/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp index 49bb11e5b..12512a32f 100644 --- a/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp +++ b/src/duckdb/src/include/duckdb/optimizer/expression_heuristics.hpp @@ -12,8 +12,6 @@ #include "duckdb/common/unordered_map.hpp" namespace duckdb { -class TableFilterSet; -class TableFilter; class ExpressionHeuristics : public LogicalOperatorVisitor { public: @@ -29,23 +27,27 @@ class ExpressionHeuristics : public LogicalOperatorVisitor { //! Reorder the expressions of a filter void ReorderExpressions(vector> &expressions); //! Return the cost of an expression - static idx_t Cost(Expression &expr); - - static vector GetInitialOrder(const TableFilterSet &table_filters); + idx_t Cost(Expression &expr); unique_ptr VisitReplace(BoundConjunctionExpression &expr, unique_ptr *expr_ptr) override; //! Override this function to search for filter operators void VisitOperator(LogicalOperator &op) override; private: - static idx_t ExpressionCost(BoundBetweenExpression &expr); - static idx_t ExpressionCost(BoundCaseExpression &expr); - static idx_t ExpressionCost(BoundCastExpression &expr); - static idx_t ExpressionCost(BoundComparisonExpression &expr); - static idx_t ExpressionCost(BoundConjunctionExpression &expr); - static idx_t ExpressionCost(BoundFunctionExpression &expr); - static idx_t ExpressionCost(BoundOperatorExpression &expr, ExpressionType expr_type); - static idx_t ExpressionCost(PhysicalType return_type, idx_t multiplier); - static idx_t Cost(TableFilter &filter); + unordered_map function_costs = { + {"+", 5}, {"-", 5}, {"&", 5}, {"#", 5}, + {">>", 5}, {"<<", 5}, {"abs", 5}, {"*", 10}, + {"%", 10}, {"/", 15}, {"date_part", 20}, {"year", 20}, + {"round", 100}, {"~~", 200}, {"!~~", 200}, {"regexp_matches", 200}, + {"||", 200}}; + + idx_t ExpressionCost(BoundBetweenExpression &expr); + idx_t ExpressionCost(BoundCaseExpression &expr); + idx_t ExpressionCost(BoundCastExpression &expr); + idx_t ExpressionCost(BoundComparisonExpression &expr); + idx_t ExpressionCost(BoundConjunctionExpression &expr); + idx_t ExpressionCost(BoundFunctionExpression &expr); + idx_t ExpressionCost(BoundOperatorExpression &expr, ExpressionType expr_type); + idx_t ExpressionCost(PhysicalType return_type, idx_t multiplier); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/optimizer/filter_combiner.hpp b/src/duckdb/src/include/duckdb/optimizer/filter_combiner.hpp index ef304b32a..979c88693 100644 --- a/src/duckdb/src/include/duckdb/optimizer/filter_combiner.hpp +++ b/src/duckdb/src/include/duckdb/optimizer/filter_combiner.hpp @@ -24,7 +24,6 @@ class Optimizer; enum class ValueComparisonResult { PRUNE_LEFT, PRUNE_RIGHT, UNSATISFIABLE_CONDITION, PRUNE_NOTHING }; enum class FilterResult { UNSATISFIABLE, SUCCESS, UNSUPPORTED }; -enum class FilterPushdownResult { NO_PUSHDOWN, PUSHED_DOWN_PARTIALLY, PUSHED_DOWN_FULLY }; //! The FilterCombiner combines several filters and generates a logically equivalent set that is more efficient //! Amongst others: @@ -54,28 +53,50 @@ class FilterCombiner { void GenerateFilters(const std::function filter)> &callback); bool HasFilters(); TableFilterSet GenerateTableScanFilters(const vector &column_ids); + // vector> GenerateZonemapChecks(vector &column_ids, vector> + // &pushed_filters); private: FilterResult AddFilter(Expression &expr); FilterResult AddBoundComparisonFilter(Expression &expr); FilterResult AddTransitiveFilters(BoundComparisonExpression &comparison, bool is_root = true); unique_ptr FindTransitiveFilter(Expression &expr); + // unordered_map> + // FindZonemapChecks(vector &column_ids, unordered_set ¬_constants, Expression *filter); Expression &GetNode(Expression &expr); idx_t GetEquivalenceSet(Expression &expr); FilterResult AddConstantComparison(vector &info_list, ExpressionValueInformation info); - - FilterPushdownResult TryPushdownConstantFilter(TableFilterSet &table_filters, const vector &column_ids, - column_t column_id, vector &info_list); - FilterPushdownResult TryPushdownExpression(TableFilterSet &table_filters, const vector &column_ids, - Expression &expr); - FilterPushdownResult TryPushdownPrefixFilter(TableFilterSet &table_filters, const vector &column_ids, - Expression &expr); - FilterPushdownResult TryPushdownLikeFilter(TableFilterSet &table_filters, const vector &column_ids, - Expression &expr); - FilterPushdownResult TryPushdownInFilter(TableFilterSet &table_filters, const vector &column_ids, - Expression &expr); - FilterPushdownResult TryPushdownOrClause(TableFilterSet &table_filters, const vector &column_ids, - Expression &expr); + // + // //! Functions used to push and generate OR Filters + // void LookUpConjunctions(Expression *expr); + // bool BFSLookUpConjunctions(BoundConjunctionExpression *conjunction); + // void VerifyOrsToPush(Expression &expr); + // + // bool UpdateConjunctionFilter(BoundComparisonExpression *comparison_expr); + // bool UpdateFilterByColumn(BoundColumnRefExpression *column_ref, BoundComparisonExpression *comparison_expr); + // void GenerateORFilters(TableFilterSet &table_filter, vector &column_ids); + // + // template + // void GenerateConjunctionFilter(BoundConjunctionExpression *conjunction, ConjunctionFilter *last_conj_filter) { + // auto new_filter = NextConjunctionFilter(conjunction); + // auto conj_filter_ptr = (ConjunctionFilter *)new_filter.get(); + // last_conj_filter->child_filters.push_back(std::move(new_filter)); + // last_conj_filter = conj_filter_ptr; + // } + // + // template + // unique_ptr NextConjunctionFilter(BoundConjunctionExpression *conjunction) { + // unique_ptr conj_filter = make_uniq(); + // for (auto &expr : conjunction->children) { + // auto comp_expr = (BoundComparisonExpression *)expr.get(); + // auto &const_expr = + // (comp_expr->left->type == ExpressionType::VALUE_CONSTANT) ? *comp_expr->left : *comp_expr->right; + // auto const_value = ExpressionExecutor::EvaluateScalar(const_expr); + // auto const_filter = make_uniq(comp_expr->type, const_value); + // conj_filter->child_filters.push_back(std::move(const_filter)); + // } + // return std::move(conj_filter); + // } private: vector> remaining_filters; @@ -85,6 +106,26 @@ class FilterCombiner { map> constant_values; map>> equivalence_map; idx_t set_index = 0; + // + // //! Structures used for OR Filters + // + // struct ConjunctionsToPush { + // BoundConjunctionExpression *root_or; + // + // // only preserve AND if there is a single column in the expression + // bool preserve_and = true; + // + // // conjunction chain for this column + // vector> conjunctions; + // }; + // + // expression_map_t>> map_col_conjunctions; + // vector vec_colref_insertion_order; + // + // BoundConjunctionExpression *cur_root_or; + // BoundConjunctionExpression *cur_conjunction; + // + // BoundColumnRefExpression *cur_colref_to_push; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/optimizer/late_materialization.hpp b/src/duckdb/src/include/duckdb/optimizer/late_materialization.hpp index b21870243..7d720e13d 100644 --- a/src/duckdb/src/include/duckdb/optimizer/late_materialization.hpp +++ b/src/duckdb/src/include/duckdb/optimizer/late_materialization.hpp @@ -41,8 +41,6 @@ class LateMaterialization : public BaseColumnPruner { Optimizer &optimizer; //! The max row count for which we will consider late materialization idx_t max_row_count; - //! The type of the row id column - LogicalType row_id_type; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/optimizer/statistics_propagator.hpp b/src/duckdb/src/include/duckdb/optimizer/statistics_propagator.hpp index edcb9a6af..be98b7789 100644 --- a/src/duckdb/src/include/duckdb/optimizer/statistics_propagator.hpp +++ b/src/duckdb/src/include/duckdb/optimizer/statistics_propagator.hpp @@ -35,11 +35,6 @@ class StatisticsPropagator { return std::move(statistics_map); } - //! Whether or not we can propagate a cast between two types - static bool CanPropagateCast(const LogicalType &source, const LogicalType &target); - static unique_ptr TryPropagateCast(BaseStatistics &stats, const LogicalType &source, - const LogicalType &target); - private: //! Propagate statistics through an operator unique_ptr PropagateStatistics(LogicalOperator &node, unique_ptr &node_ptr); diff --git a/src/duckdb/src/include/duckdb/parallel/task.hpp b/src/duckdb/src/include/duckdb/parallel/task.hpp index a18b72e2f..2bcafeeaa 100644 --- a/src/duckdb/src/include/duckdb/parallel/task.hpp +++ b/src/duckdb/src/include/duckdb/parallel/task.hpp @@ -9,7 +9,6 @@ #pragma once #include "duckdb/common/common.hpp" -#include "duckdb/common/optional_ptr.hpp" namespace duckdb { class ClientContext; @@ -51,9 +50,6 @@ class Task : public enable_shared_from_this { virtual bool TaskBlockedOnResult() const { return false; } - -public: - optional_ptr token; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp b/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp index 0a2588c6a..80d7c8970 100644 --- a/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +++ b/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp @@ -17,7 +17,6 @@ class SelectStatement; struct CommonTableExpressionInfo { vector aliases; - vector> key_targets; unique_ptr query; CTEMaterialize materialized = CTEMaterialize::CTE_MATERIALIZE_DEFAULT; diff --git a/src/duckdb/src/include/duckdb/parser/expression/lambda_expression.hpp b/src/duckdb/src/include/duckdb/parser/expression/lambda_expression.hpp index 3f41659b1..f3b2c8cc6 100644 --- a/src/duckdb/src/include/duckdb/parser/expression/lambda_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/expression/lambda_expression.hpp @@ -30,8 +30,6 @@ class LambdaExpression : public ParsedExpression { unique_ptr lhs; //! The lambda or JSON expression (RHS) unique_ptr expr; - //! Band-aid for conflicts between lambda binding and JSON binding. - unique_ptr copied_expr; public: //! Returns a vector to the column references in the LHS expression, and fills the error message, diff --git a/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp b/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp index 3551e0982..3bcf38146 100644 --- a/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/expression/operator_expression.hpp @@ -61,12 +61,6 @@ class OperatorExpression : public ParsedExpression { child_list += ")"; return "(" + in_child + op_type + child_list + ")"; } - case ExpressionType::OPERATOR_UNPACK: { - return StringUtil::Format("UNPACK(%s)", entry.children[0]->ToString()); - } - case ExpressionType::OPERATOR_TRY: { - return StringUtil::Format("TRY(%s)", entry.children[0]->ToString()); - } case ExpressionType::OPERATOR_NOT: { string result = "("; result += ExpressionTypeToString(entry.GetExpressionType()); diff --git a/src/duckdb/src/include/duckdb/parser/expression/star_expression.hpp b/src/duckdb/src/include/duckdb/parser/expression/star_expression.hpp index dbe7c9cfc..c35ef2029 100644 --- a/src/duckdb/src/include/duckdb/parser/expression/star_expression.hpp +++ b/src/duckdb/src/include/duckdb/parser/expression/star_expression.hpp @@ -14,8 +14,6 @@ namespace duckdb { -enum class StarExpressionType : uint8_t { STAR, COLUMNS, UNPACKED, NONE }; - //! Represents a * expression in the SELECT clause class StarExpression : public ParsedExpression { public: @@ -36,6 +34,8 @@ class StarExpression : public ParsedExpression { unique_ptr expr; //! Whether or not this is a COLUMNS expression bool columns = false; + //! Whether the columns are unpacked + bool unpacked = false; public: string ToString() const override; @@ -47,12 +47,6 @@ class StarExpression : public ParsedExpression { unique_ptr Copy() const override; - static unique_ptr - DeserializeStarExpression(string &&relation_name, const case_insensitive_set_t &exclude_list, - case_insensitive_map_t> &&replace_list, bool columns, - unique_ptr expr, bool unpacked, - const qualified_column_set_t &qualified_exclude_list, - qualified_column_map_t &&rename_list); void Serialize(Serializer &serializer) const override; static unique_ptr Deserialize(Deserializer &deserializer); diff --git a/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp b/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp index 25864c3e8..9506b1519 100644 --- a/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +++ b/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp @@ -12,7 +12,6 @@ #include "duckdb/parser/column_definition.hpp" #include "duckdb/parser/constraint.hpp" #include "duckdb/parser/parsed_data/parse_info.hpp" -#include "duckdb/parser/result_modifier.hpp" namespace duckdb { @@ -80,12 +79,7 @@ enum class AlterTableType : uint8_t { SET_NOT_NULL = 8, DROP_NOT_NULL = 9, SET_COLUMN_COMMENT = 10, - ADD_CONSTRAINT = 11, - SET_PARTITIONED_BY = 12, - SET_SORTED_BY = 13, - ADD_FIELD = 14, - REMOVE_FIELD = 15, - RENAME_FIELD = 16 + ADD_CONSTRAINT = 11 }; struct AlterTableInfo : public AlterInfo { @@ -127,29 +121,6 @@ struct RenameColumnInfo : public AlterTableInfo { RenameColumnInfo(); }; -//===--------------------------------------------------------------------===// -// RenameFieldInfo -//===--------------------------------------------------------------------===// -struct RenameFieldInfo : public AlterTableInfo { - RenameFieldInfo(AlterEntryData data, vector column_path, string new_name_p); - ~RenameFieldInfo() override; - - //! Path to source field - vector column_path; - //! Column new name - string new_name; - -public: - unique_ptr Copy() const override; - string ToString() const override; - - void Serialize(Serializer &serializer) const override; - static unique_ptr Deserialize(Deserializer &deserializer); - -private: - RenameFieldInfo(); -}; - //===--------------------------------------------------------------------===// // RenameTableInfo //===--------------------------------------------------------------------===// @@ -194,31 +165,6 @@ struct AddColumnInfo : public AlterTableInfo { explicit AddColumnInfo(ColumnDefinition new_column); }; -//===--------------------------------------------------------------------===// -// AddFieldInfo -//===--------------------------------------------------------------------===// -struct AddFieldInfo : public AlterTableInfo { - AddFieldInfo(AlterEntryData data, vector column_path, ColumnDefinition new_field, bool if_field_not_exists); - ~AddFieldInfo() override; - - //! The path to the struct - vector column_path; - //! New field to add to the struct - ColumnDefinition new_field; - //! Whether or not an error should be thrown if the field exist - bool if_field_not_exists; - -public: - unique_ptr Copy() const override; - string ToString() const override; - - void Serialize(Serializer &serializer) const override; - static unique_ptr Deserialize(Deserializer &deserializer); - -private: - explicit AddFieldInfo(ColumnDefinition new_column); -}; - //===--------------------------------------------------------------------===// // RemoveColumnInfo //===--------------------------------------------------------------------===// @@ -246,29 +192,6 @@ struct RemoveColumnInfo : public AlterTableInfo { RemoveColumnInfo(); }; -//===--------------------------------------------------------------------===// -// RemoveFieldInfo -//===--------------------------------------------------------------------===// -struct RemoveFieldInfo : public AlterTableInfo { - RemoveFieldInfo(AlterEntryData data, vector column_path, bool if_column_exists, bool cascade); - ~RemoveFieldInfo() override; - - //! The path to the field to remove - vector column_path; - //! Whether or not an error should be thrown if the column does not exist - bool if_column_exists; - //! Whether or not the column should be removed if a dependency conflict arises (used by GENERATED columns) - bool cascade; - -public: - unique_ptr Copy() const override; - string ToString() const override; - void Serialize(Serializer &serializer) const override; - static unique_ptr Deserialize(Deserializer &deserializer); - -private: - RemoveFieldInfo(); -}; //===--------------------------------------------------------------------===// // ChangeColumnTypeInfo //===--------------------------------------------------------------------===// @@ -444,44 +367,4 @@ struct AddConstraintInfo : public AlterTableInfo { AddConstraintInfo(); }; -//===--------------------------------------------------------------------===// -// SetPartitionedByInfo -//===--------------------------------------------------------------------===// -struct SetPartitionedByInfo : public AlterTableInfo { - SetPartitionedByInfo(AlterEntryData data, vector> partition_keys); - ~SetPartitionedByInfo() override; - - //! The partition keys - vector> partition_keys; - -public: - unique_ptr Copy() const override; - string ToString() const override; - void Serialize(Serializer &serializer) const override; - static unique_ptr Deserialize(Deserializer &deserializer); - -private: - SetPartitionedByInfo(); -}; - -//===--------------------------------------------------------------------===// -// SetSortedByInfo -//===--------------------------------------------------------------------===// -struct SetSortedByInfo : public AlterTableInfo { - SetSortedByInfo(AlterEntryData data, vector orders); - ~SetSortedByInfo() override; - - //! The sort keys - vector orders; - -public: - unique_ptr Copy() const override; - string ToString() const override; - void Serialize(Serializer &serializer) const override; - static unique_ptr Deserialize(Deserializer &deserializer); - -private: - SetSortedByInfo(); -}; - } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/parser/parsed_data/create_function_info.hpp b/src/duckdb/src/include/duckdb/parser/parsed_data/create_function_info.hpp index fb6522cc7..355a11f7d 100644 --- a/src/duckdb/src/include/duckdb/parser/parsed_data/create_function_info.hpp +++ b/src/duckdb/src/include/duckdb/parser/parsed_data/create_function_info.hpp @@ -22,8 +22,6 @@ struct FunctionDescription { string description; //! Examples (if any) vector examples; - //! Categories (if any) - vector categories; }; struct CreateFunctionInfo : public CreateInfo { @@ -31,8 +29,6 @@ struct CreateFunctionInfo : public CreateInfo { //! Function name string name; - //! The function name of which this function is an alias - string alias_of; //! Function description vector descriptions; diff --git a/src/duckdb/src/include/duckdb/parser/parsed_data/create_secret_info.hpp b/src/duckdb/src/include/duckdb/parser/parsed_data/create_secret_info.hpp index 76c4353b6..dfe81249c 100644 --- a/src/duckdb/src/include/duckdb/parser/parsed_data/create_secret_info.hpp +++ b/src/duckdb/src/include/duckdb/parser/parsed_data/create_secret_info.hpp @@ -24,25 +24,24 @@ struct CreateSecretInfo : public CreateInfo { // NOLINT: work-around bug in clan public: explicit CreateSecretInfo(OnCreateConflict on_conflict, SecretPersistType persist_type); - ~CreateSecretInfo() override; - //! How to handle conflict OnCreateConflict on_conflict; //! Whether the secret can be persisted SecretPersistType persist_type; //! The type of secret - unique_ptr type; + string type; //! Which storage to use (empty for default) string storage_type; //! (optionally) the provider of the secret credentials - unique_ptr provider; + string provider; //! (optionally) the name of the secret string name; //! (optionally) the scope of the secret - unique_ptr scope; + vector scope; //! Named parameter list (if any) - case_insensitive_map_t> options; + case_insensitive_map_t options; unique_ptr Copy() const override; }; + } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/parser/query_error_context.hpp b/src/duckdb/src/include/duckdb/parser/query_error_context.hpp index f0de3fa11..cec72b142 100644 --- a/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +++ b/src/duckdb/src/include/duckdb/parser/query_error_context.hpp @@ -14,11 +14,9 @@ #include "duckdb/common/optional_idx.hpp" namespace duckdb { -class ParsedExpression; class QueryErrorContext { public: - QueryErrorContext(const ParsedExpression &expr); // NOLINT: allow implicit conversion from expression explicit QueryErrorContext(optional_idx query_location_p = optional_idx()) : query_location(query_location_p) { } diff --git a/src/duckdb/src/include/duckdb/parser/query_node/recursive_cte_node.hpp b/src/duckdb/src/include/duckdb/parser/query_node/recursive_cte_node.hpp index 6d73fda4a..a69bf0032 100644 --- a/src/duckdb/src/include/duckdb/parser/query_node/recursive_cte_node.hpp +++ b/src/duckdb/src/include/duckdb/parser/query_node/recursive_cte_node.hpp @@ -30,8 +30,6 @@ class RecursiveCTENode : public QueryNode { unique_ptr right; //! Aliases of the recursive CTE node vector aliases; - //! targets for key variants - vector> key_targets; const vector> &GetSelectList() const override { return left->GetSelectList(); diff --git a/src/duckdb/src/include/duckdb/parser/tableref.hpp b/src/duckdb/src/include/duckdb/parser/tableref.hpp index 1a0d81692..62890e3b3 100644 --- a/src/duckdb/src/include/duckdb/parser/tableref.hpp +++ b/src/duckdb/src/include/duckdb/parser/tableref.hpp @@ -41,6 +41,8 @@ class TableRef { public: //! Convert the object to a string virtual string ToString() const = 0; + string BaseToString(string result) const; + string BaseToString(string result, const vector &column_name_alias) const; void Print(); virtual bool Equals(const TableRef &other) const; @@ -70,11 +72,5 @@ class TableRef { } return reinterpret_cast(*this); } - -protected: - string BaseToString(string result) const; - string BaseToString(string result, const vector &column_name_alias) const; - string AliasToString(const vector &column_name_alias) const; - string SampleToString() const; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/parser/tableref/basetableref.hpp b/src/duckdb/src/include/duckdb/parser/tableref/basetableref.hpp index e5b2d6d2f..b841559ea 100644 --- a/src/duckdb/src/include/duckdb/parser/tableref/basetableref.hpp +++ b/src/duckdb/src/include/duckdb/parser/tableref/basetableref.hpp @@ -11,7 +11,6 @@ #include "duckdb/common/vector.hpp" #include "duckdb/main/table_description.hpp" #include "duckdb/parser/tableref.hpp" -#include "duckdb/parser/tableref/at_clause.hpp" namespace duckdb { @@ -35,8 +34,6 @@ class BaseTableRef : public TableRef { string schema_name; //! The table name. string table_name; - //! The timestamp/version at which to read this table entry (if any) - unique_ptr at_clause; public: string ToString() const override; diff --git a/src/duckdb/src/include/duckdb/parser/transformer.hpp b/src/duckdb/src/include/duckdb/parser/transformer.hpp index a03288034..00833a526 100644 --- a/src/duckdb/src/include/duckdb/parser/transformer.hpp +++ b/src/duckdb/src/include/duckdb/parser/transformer.hpp @@ -367,7 +367,6 @@ class Transformer { void ParseGenericOptionListEntry(case_insensitive_map_t> &result_options, string &name, duckdb_libpgquery::PGNode *arg); - vector TransformNameList(duckdb_libpgquery::PGList &list); public: static void SetQueryLocation(ParsedExpression &expr, int query_location); diff --git a/src/duckdb/src/include/duckdb/planner/bind_context.hpp b/src/duckdb/src/include/duckdb/planner/bind_context.hpp index 547bd5781..8234805e7 100644 --- a/src/duckdb/src/include/duckdb/planner/bind_context.hpp +++ b/src/duckdb/src/include/duckdb/planner/bind_context.hpp @@ -94,13 +94,13 @@ class BindContext { //! Adds a base table with the given alias to the BindContext. void AddBaseTable(idx_t index, const string &alias, const vector &names, const vector &types, - vector &bound_column_ids, TableCatalogEntry &entry, bool add_row_id = true); + vector &bound_column_ids, StandardEntry &entry, bool add_row_id = true); void AddBaseTable(idx_t index, const string &alias, const vector &names, const vector &types, vector &bound_column_ids, const string &table_name); //! Adds a call to a table function with the given alias to the BindContext. void AddTableFunction(idx_t index, const string &alias, const vector &names, const vector &types, vector &bound_column_ids, - optional_ptr entry, virtual_column_map_t virtual_columns); + optional_ptr entry); //! Adds a table view with a given alias to the BindContext. void AddView(idx_t index, const string &alias, SubqueryRef &ref, BoundQueryNode &subquery, ViewCatalogEntry &view); //! Adds a subquery with a given alias to the BindContext. @@ -116,8 +116,7 @@ class BindContext { //! Adds a base table with the given alias to the CTE BindContext. //! We need this to correctly bind recursive CTEs with multiple references. - void AddCTEBinding(idx_t index, const string &alias, const vector &names, const vector &types, - bool using_key = false); + void AddCTEBinding(idx_t index, const string &alias, const vector &names, const vector &types); //! Add an implicit join condition (e.g. USING (x)) void AddUsingBinding(const string &column_name, UsingColumnSet &set); diff --git a/src/duckdb/src/include/duckdb/planner/binder.hpp b/src/duckdb/src/include/duckdb/planner/binder.hpp index d0601ec79..6a1e8dcc3 100644 --- a/src/duckdb/src/include/duckdb/planner/binder.hpp +++ b/src/duckdb/src/include/duckdb/planner/binder.hpp @@ -23,17 +23,11 @@ #include "duckdb/planner/bound_statement.hpp" #include "duckdb/planner/bound_tokens.hpp" #include "duckdb/planner/expression/bound_columnref_expression.hpp" -#include "duckdb/parser/expression/star_expression.hpp" #include "duckdb/planner/joinside.hpp" #include "duckdb/planner/bound_constraint.hpp" #include "duckdb/planner/logical_operator.hpp" #include "duckdb/planner/tableref/bound_delimgetref.hpp" -//! fwd declare -namespace duckdb_re2 { -class RE2; -} // namespace duckdb_re2 - namespace duckdb { class BoundResultModifier; class BoundSelectNode; @@ -53,8 +47,6 @@ class ExternalDependency; class TableFunction; class TableStorageInfo; class BoundConstraint; -class AtClause; -class BoundAtClause; struct CreateInfo; struct BoundCreateTableInfo; @@ -62,7 +54,6 @@ struct CommonTableExpressionInfo; struct BoundParameterMap; struct BoundPragmaInfo; struct BoundLimitNode; -struct EntryLookupInfo; struct PivotColumnEntry; struct UnpivotEntry; @@ -166,8 +157,9 @@ class Binder : public enable_shared_from_this { //! Generates an unused index for a table idx_t GenerateTableIndex(); - optional_ptr GetCatalogEntry(const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound on_entry_not_found); + optional_ptr GetCatalogEntry(CatalogType type, const string &catalog, const string &schema, + const string &name, OnEntryNotFound on_entry_not_found, + QueryErrorContext &error_context); //! Add a common table expression to the binder void AddCTE(const string &name, CommonTableExpressionInfo &cte); @@ -229,9 +221,6 @@ class Binder : public enable_shared_from_this { void SetAlwaysRequireRebind(); StatementProperties &GetStatementProperties(); - static void ReplaceStarExpression(unique_ptr &expr, unique_ptr &replacement); - static string ReplaceColumnsAlias(const string &alias, const string &column_name, - optional_ptr regex); private: //! The parent binder (if any) @@ -360,8 +349,6 @@ class Binder : public enable_shared_from_this { void ExtractUnpivotEntries(Binder &child_binder, PivotColumnEntry &entry, vector &unpivot_entries); void ExtractUnpivotColumnName(ParsedExpression &expr, vector &result); - unique_ptr BindAtClause(optional_ptr at_clause); - bool BindTableFunctionParameters(TableFunctionCatalogEntry &table_function, vector> &expressions, vector &arguments, vector ¶meters, named_parameter_map_t &named_parameters, @@ -422,16 +409,14 @@ class Binder : public enable_shared_from_this { void ExpandStarExpressions(vector> &select_list, vector> &new_select_list); void ExpandStarExpression(unique_ptr expr, vector> &new_select_list); - StarExpressionType FindStarExpression(unique_ptr &expr, StarExpression **star, bool is_root, - bool in_columns); + bool FindStarExpression(unique_ptr &expr, StarExpression **star, bool is_root, bool in_columns); void ReplaceUnpackedStarExpression(unique_ptr &expr, - vector> &replacements, StarExpression &star, - optional_ptr regex); + vector> &replacements); + void ReplaceStarExpression(unique_ptr &expr, unique_ptr &replacement); void BindWhereStarExpression(unique_ptr &expr); //! If only a schema name is provided (e.g. "a.b") then figure out if "a" is a schema or a catalog name void BindSchemaOrCatalog(string &catalog_name, string &schema_name); - static void BindSchemaOrCatalog(CatalogEntryRetriever &retriever, string &catalog, string &schema); const string BindCatalog(string &catalog_name); SchemaCatalogEntry &BindCreateSchema(CreateInfo &info); diff --git a/src/duckdb/src/include/duckdb/planner/expression_binder.hpp b/src/duckdb/src/include/duckdb/planner/expression_binder.hpp index bb60e64de..c73ea546d 100644 --- a/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +++ b/src/duckdb/src/include/duckdb/planner/expression_binder.hpp @@ -211,8 +211,9 @@ class ExpressionBinder { virtual string UnsupportedAggregateMessage(); virtual string UnsupportedUnnestMessage(); - optional_ptr GetCatalogEntry(const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info, OnEntryNotFound on_entry_not_found); + optional_ptr GetCatalogEntry(CatalogType type, const string &catalog, const string &schema, + const string &name, OnEntryNotFound on_entry_not_found, + QueryErrorContext &error_context); Binder &binder; ClientContext &context; diff --git a/src/duckdb/src/include/duckdb/planner/filter/conjunction_filter.hpp b/src/duckdb/src/include/duckdb/planner/filter/conjunction_filter.hpp index 155b8c999..49fcf6e95 100644 --- a/src/duckdb/src/include/duckdb/planner/filter/conjunction_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/filter/conjunction_filter.hpp @@ -37,7 +37,7 @@ class ConjunctionOrFilter : public ConjunctionFilter { public: ConjunctionOrFilter(); FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; bool Equals(const TableFilter &other) const override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; @@ -54,7 +54,7 @@ class ConjunctionAndFilter : public ConjunctionFilter { public: FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; bool Equals(const TableFilter &other) const override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; diff --git a/src/duckdb/src/include/duckdb/planner/filter/constant_filter.hpp b/src/duckdb/src/include/duckdb/planner/filter/constant_filter.hpp index cea6ebd5f..25d516a5c 100644 --- a/src/duckdb/src/include/duckdb/planner/filter/constant_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/filter/constant_filter.hpp @@ -29,7 +29,7 @@ class ConstantFilter : public TableFilter { public: bool Compare(const Value &value) const; FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; bool Equals(const TableFilter &other) const override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; diff --git a/src/duckdb/src/include/duckdb/planner/filter/dynamic_filter.hpp b/src/duckdb/src/include/duckdb/planner/filter/dynamic_filter.hpp index 1c39ee58e..fbb32faff 100644 --- a/src/duckdb/src/include/duckdb/planner/filter/dynamic_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/filter/dynamic_filter.hpp @@ -12,13 +12,12 @@ #include "duckdb/planner/table_filter.hpp" #include "duckdb/common/types/value.hpp" #include "duckdb/common/enums/expression_type.hpp" -#include "duckdb/planner/filter/constant_filter.hpp" namespace duckdb { struct DynamicFilterData { mutex lock; - unique_ptr filter; + unique_ptr filter; bool initialized = false; void SetValue(Value val); @@ -38,7 +37,7 @@ class DynamicFilter : public TableFilter { public: FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; bool Equals(const TableFilter &other) const override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; diff --git a/src/duckdb/src/include/duckdb/planner/filter/in_filter.hpp b/src/duckdb/src/include/duckdb/planner/filter/in_filter.hpp index 757f735f3..c9028ed5e 100644 --- a/src/duckdb/src/include/duckdb/planner/filter/in_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/filter/in_filter.hpp @@ -24,7 +24,7 @@ class InFilter : public TableFilter { public: FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; bool Equals(const TableFilter &other) const override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; diff --git a/src/duckdb/src/include/duckdb/planner/filter/null_filter.hpp b/src/duckdb/src/include/duckdb/planner/filter/null_filter.hpp index 11297c73d..212ef3861 100644 --- a/src/duckdb/src/include/duckdb/planner/filter/null_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/filter/null_filter.hpp @@ -21,7 +21,7 @@ class IsNullFilter : public TableFilter { public: FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; void Serialize(Serializer &serializer) const override; @@ -37,7 +37,7 @@ class IsNotNullFilter : public TableFilter { public: FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; void Serialize(Serializer &serializer) const override; diff --git a/src/duckdb/src/include/duckdb/planner/filter/optional_filter.hpp b/src/duckdb/src/include/duckdb/planner/filter/optional_filter.hpp index 70f610b91..edbd060ae 100644 --- a/src/duckdb/src/include/duckdb/planner/filter/optional_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/filter/optional_filter.hpp @@ -24,7 +24,7 @@ class OptionalFilter : public TableFilter { unique_ptr child_filter; public: - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; diff --git a/src/duckdb/src/include/duckdb/planner/filter/struct_filter.hpp b/src/duckdb/src/include/duckdb/planner/filter/struct_filter.hpp index 52c5fdcfc..05e806d36 100644 --- a/src/duckdb/src/include/duckdb/planner/filter/struct_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/filter/struct_filter.hpp @@ -32,7 +32,7 @@ class StructFilter : public TableFilter { public: FilterPropagateResult CheckStatistics(BaseStatistics &stats) override; - string ToString(const string &column_name) const override; + string ToString(const string &column_name) override; bool Equals(const TableFilter &other) const override; unique_ptr Copy() const override; unique_ptr ToExpression(const Expression &column) const override; diff --git a/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp b/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp index 4e5502747..5ec454b0e 100644 --- a/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +++ b/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp @@ -42,7 +42,6 @@ class LogicalCopyToFile : public LogicalOperator { bool partition_output; bool write_partition_columns; - bool write_empty_file = true; vector partition_columns; vector names; vector expected_types; diff --git a/src/duckdb/src/include/duckdb/planner/operator/logical_create_secret.hpp b/src/duckdb/src/include/duckdb/planner/operator/logical_create_secret.hpp index 91c4d44ad..9a780bd28 100644 --- a/src/duckdb/src/include/duckdb/planner/operator/logical_create_secret.hpp +++ b/src/duckdb/src/include/duckdb/planner/operator/logical_create_secret.hpp @@ -19,11 +19,11 @@ class LogicalCreateSecret : public LogicalOperator { static constexpr const LogicalOperatorType TYPE = LogicalOperatorType::LOGICAL_CREATE_SECRET; public: - explicit LogicalCreateSecret(CreateSecretInput secret_input_p) - : LogicalOperator(LogicalOperatorType::LOGICAL_CREATE_SECRET), secret_input(std::move(secret_input_p)) { + explicit LogicalCreateSecret(CreateSecretInfo info_p) + : LogicalOperator(LogicalOperatorType::LOGICAL_CREATE_SECRET), info(std::move(info_p)) { } - CreateSecretInput secret_input; + CreateSecretInfo info; public: idx_t EstimateCardinality(ClientContext &context) override { diff --git a/src/duckdb/src/include/duckdb/planner/operator/logical_cteref.hpp b/src/duckdb/src/include/duckdb/planner/operator/logical_cteref.hpp index 377749b8d..32eaaeea3 100644 --- a/src/duckdb/src/include/duckdb/planner/operator/logical_cteref.hpp +++ b/src/duckdb/src/include/duckdb/planner/operator/logical_cteref.hpp @@ -20,9 +20,9 @@ class LogicalCTERef : public LogicalOperator { public: LogicalCTERef(idx_t table_index, idx_t cte_index, vector types, vector colnames, - CTEMaterialize materialized_cte, bool is_recurring = false) + CTEMaterialize materialized_cte) : LogicalOperator(LogicalOperatorType::LOGICAL_CTE_REF), table_index(table_index), cte_index(cte_index), - correlated_columns(0), materialized_cte(materialized_cte), is_recurring(is_recurring) { + correlated_columns(0), materialized_cte(materialized_cte) { D_ASSERT(types.size() > 0); chunk_types = std::move(types); bound_columns = std::move(colnames); @@ -39,8 +39,6 @@ class LogicalCTERef : public LogicalOperator { idx_t correlated_columns; //! Does this operator read a materialized CTE? CTEMaterialize materialized_cte; - //! Does this operator read the recurring CTE table - bool is_recurring = false; public: InsertionOrderPreservingMap ParamsToString() const override; diff --git a/src/duckdb/src/include/duckdb/planner/operator/logical_extension_operator.hpp b/src/duckdb/src/include/duckdb/planner/operator/logical_extension_operator.hpp index b0d4f72c6..a7d60ca3f 100644 --- a/src/duckdb/src/include/duckdb/planner/operator/logical_extension_operator.hpp +++ b/src/duckdb/src/include/duckdb/planner/operator/logical_extension_operator.hpp @@ -29,7 +29,7 @@ struct LogicalExtensionOperator : public LogicalOperator { void Serialize(Serializer &serializer) const override; static unique_ptr Deserialize(Deserializer &deserializer); - virtual PhysicalOperator &CreatePlan(ClientContext &context, PhysicalPlanGenerator &planner) = 0; + virtual unique_ptr CreatePlan(ClientContext &context, PhysicalPlanGenerator &generator) = 0; virtual void ResolveColumnBindings(ColumnBindingResolver &res, vector &bindings); virtual string GetExtensionName() const; diff --git a/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp b/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp index 395224bc8..81b93accb 100644 --- a/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +++ b/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp @@ -24,7 +24,7 @@ class LogicalGet : public LogicalOperator { public: LogicalGet(idx_t table_index, TableFunction function, unique_ptr bind_data, vector returned_types, vector returned_names, - virtual_column_map_t virtual_columns = virtual_column_map_t()); + LogicalType rowid_type = LogicalType(LogicalType::ROW_TYPE)); //! The table index in the current bind context idx_t table_index; @@ -36,8 +36,6 @@ class LogicalGet : public LogicalOperator { vector returned_types; //! The names of ALL columns that can be returned by the table function vector names; - //! A mapping of column index -> type/name for all virtual columns - virtual_column_map_t virtual_columns; //! Columns that are used outside the scan vector projection_ids; //! Filters pushed down for table scan @@ -63,12 +61,6 @@ class LogicalGet : public LogicalOperator { InsertionOrderPreservingMap ParamsToString() const override; //! Returns the underlying table that is being scanned, or nullptr if there is none optional_ptr GetTable() const; - //! Returns any column to query - preferably the cheapest column - //! This is used when we are running e.g. a COUNT(*) and don't care about the contents of any columns in the table - column_t GetAnyColumn() const; - - const LogicalType &GetColumnType(const ColumnIndex &column_index) const; - const string &GetColumnName(const ColumnIndex &column_index) const; public: void SetColumnIds(vector &&column_ids); @@ -88,6 +80,10 @@ class LogicalGet : public LogicalOperator { void Serialize(Serializer &serializer) const override; static unique_ptr Deserialize(Deserializer &deserializer); + const LogicalType &GetRowIdType() const { + return rowid_type; + } + protected: void ResolveTypes() override; @@ -97,5 +93,8 @@ class LogicalGet : public LogicalOperator { private: //! Bound column IDs vector column_ids; + + //! The type of the rowid column + LogicalType rowid_type = LogicalType(LogicalType::ROW_TYPE); }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/planner/operator/logical_recursive_cte.hpp b/src/duckdb/src/include/duckdb/planner/operator/logical_recursive_cte.hpp index 1184959ef..c118b41fe 100644 --- a/src/duckdb/src/include/duckdb/planner/operator/logical_recursive_cte.hpp +++ b/src/duckdb/src/include/duckdb/planner/operator/logical_recursive_cte.hpp @@ -22,24 +22,17 @@ class LogicalRecursiveCTE : public LogicalOperator { public: LogicalRecursiveCTE(string ctename_p, idx_t table_index, idx_t column_count, bool union_all, - vector> key_targets, unique_ptr top, - unique_ptr bottom) + unique_ptr top, unique_ptr bottom) : LogicalOperator(LogicalOperatorType::LOGICAL_RECURSIVE_CTE), union_all(union_all), - ctename(std::move(ctename_p)), table_index(table_index), column_count(column_count), - key_targets(std::move(key_targets)) { - + ctename(std::move(ctename_p)), table_index(table_index), column_count(column_count) { children.push_back(std::move(top)); children.push_back(std::move(bottom)); } bool union_all; - // Flag if recurring table is referenced, if not we do not copy ht into ColumnDataCollection - bool ref_recurring; string ctename; idx_t table_index; idx_t column_count; - - vector> key_targets; vector correlated_columns; public: diff --git a/src/duckdb/src/include/duckdb/planner/query_node/bound_recursive_cte_node.hpp b/src/duckdb/src/include/duckdb/planner/query_node/bound_recursive_cte_node.hpp index 3da295e2a..0e9b3dddf 100644 --- a/src/duckdb/src/include/duckdb/planner/query_node/bound_recursive_cte_node.hpp +++ b/src/duckdb/src/include/duckdb/planner/query_node/bound_recursive_cte_node.hpp @@ -30,8 +30,6 @@ class BoundRecursiveCTENode : public BoundQueryNode { unique_ptr left; //! The right side of the set operation unique_ptr right; - //! Target columns for the recursive key variant - vector> key_targets; //! Index used by the set operation idx_t setop_index; diff --git a/src/duckdb/src/include/duckdb/planner/table_binding.hpp b/src/duckdb/src/include/duckdb/planner/table_binding.hpp index 9aedc7e70..50631f57a 100644 --- a/src/duckdb/src/include/duckdb/planner/table_binding.hpp +++ b/src/duckdb/src/include/duckdb/planner/table_binding.hpp @@ -16,7 +16,6 @@ #include "duckdb/catalog/catalog_entry/table_column_type.hpp" #include "duckdb/planner/binding_alias.hpp" #include "duckdb/common/column_index.hpp" -#include "duckdb/common/table_column.hpp" namespace duckdb { class BindContext; @@ -34,7 +33,8 @@ enum class BindingType { BASE, TABLE, DUMMY, CATALOG_ENTRY }; //! A Binding represents a binding to a table, table-producing function or subquery with a specified table index. struct Binding { - Binding(BindingType binding_type, BindingAlias alias, vector types, vector names, idx_t index); + Binding(BindingType binding_type, BindingAlias alias, vector types, vector names, idx_t index, + LogicalType rowid_type = LogicalType(LogicalType::ROW_TYPE)); virtual ~Binding() = default; //! The type of Binding @@ -50,6 +50,8 @@ struct Binding { //! Name -> index for the names case_insensitive_map_t name_map; + LogicalType rowid_type; + public: bool TryGetBindingIndex(const string &column_name, column_t &column_index); column_t GetBindingIndex(const string &column_name); @@ -102,14 +104,12 @@ struct TableBinding : public Binding { public: TableBinding(const string &alias, vector types, vector names, vector &bound_column_ids, optional_ptr entry, idx_t index, - virtual_column_map_t virtual_columns); + bool add_row_id = false); //! A reference to the set of bound column ids vector &bound_column_ids; //! The underlying catalog entry (if any) optional_ptr entry; - //! Virtual columns - virtual_column_map_t virtual_columns; public: unique_ptr ExpandGeneratedColumn(const string &column_name); diff --git a/src/duckdb/src/include/duckdb/planner/table_filter.hpp b/src/duckdb/src/include/duckdb/planner/table_filter.hpp index 9e71a1391..290f789da 100644 --- a/src/duckdb/src/include/duckdb/planner/table_filter.hpp +++ b/src/duckdb/src/include/duckdb/planner/table_filter.hpp @@ -13,7 +13,7 @@ #include "duckdb/common/mutex.hpp" #include "duckdb/common/reference_map.hpp" #include "duckdb/common/types.hpp" -#include "duckdb/common/map.hpp" +#include "duckdb/common/unordered_map.hpp" #include "duckdb/planner/column_binding.hpp" #include "duckdb/common/column_index.hpp" @@ -48,8 +48,8 @@ class TableFilter { public: //! Returns true if the statistics indicate that the segment can contain values that satisfy that filter virtual FilterPropagateResult CheckStatistics(BaseStatistics &stats) = 0; - virtual string ToString(const string &column_name) const = 0; - string DebugToString() const; + virtual string ToString(const string &column_name) = 0; + string DebugToString(); virtual unique_ptr Copy() const = 0; virtual bool Equals(const TableFilter &other) const { return filter_type == other.filter_type; @@ -77,11 +77,9 @@ class TableFilter { } }; -//! The filters in here are non-composite (only need a single column to be evaluated) -//! Conditions like `A = 2 OR B = 4` are not pushed into a TableFilterSet. class TableFilterSet { public: - map> filters; + unordered_map> filters; public: void PushFilter(const ColumnIndex &col_idx, unique_ptr filter); @@ -111,14 +109,6 @@ class TableFilterSet { return left->Equals(*right); } - unique_ptr Copy() const { - auto copy = make_uniq(); - for (auto &it : filters) { - copy->filters.emplace(it.first, it.second->Copy()); - } - return copy; - } - void Serialize(Serializer &serializer) const; static TableFilterSet Deserialize(Deserializer &deserializer); }; diff --git a/src/duckdb/src/include/duckdb/planner/tableref/bound_cteref.hpp b/src/duckdb/src/include/duckdb/planner/tableref/bound_cteref.hpp index e79a35b64..8d300c722 100644 --- a/src/duckdb/src/include/duckdb/planner/tableref/bound_cteref.hpp +++ b/src/duckdb/src/include/duckdb/planner/tableref/bound_cteref.hpp @@ -23,10 +23,6 @@ class BoundCTERef : public BoundTableRef { materialized_cte(materialized_cte) { } - BoundCTERef(idx_t bind_index, idx_t cte_index, CTEMaterialize materialized_cte, bool is_recurring) - : BoundTableRef(TableReferenceType::CTE), bind_index(bind_index), cte_index(cte_index), - materialized_cte(materialized_cte), is_recurring(is_recurring) { - } //! The set of columns bound to this base table reference vector bound_columns; //! The types of the values list @@ -37,7 +33,5 @@ class BoundCTERef : public BoundTableRef { idx_t cte_index; //! Is this a reference to a materialized CTE? CTEMaterialize materialized_cte; - //! Is this a reference to the recurring table of a CTE - bool is_recurring = false; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/storage/arena_allocator.hpp b/src/duckdb/src/include/duckdb/storage/arena_allocator.hpp index ce6f5c514..d76aeccb6 100644 --- a/src/duckdb/src/include/duckdb/storage/arena_allocator.hpp +++ b/src/duckdb/src/include/duckdb/storage/arena_allocator.hpp @@ -33,16 +33,7 @@ class ArenaAllocator { DUCKDB_API explicit ArenaAllocator(Allocator &allocator, idx_t initial_capacity = ARENA_ALLOCATOR_INITIAL_CAPACITY); DUCKDB_API ~ArenaAllocator(); - data_ptr_t Allocate(idx_t len) { - D_ASSERT(!head || head->current_position <= head->maximum_size); - if (!head || head->current_position + len > head->maximum_size) { - AllocateNewBlock(len); - } - D_ASSERT(head->current_position + len <= head->maximum_size); - auto result = head->data.get() + head->current_position; - head->current_position += len; - return result; - } + DUCKDB_API data_ptr_t Allocate(idx_t size); DUCKDB_API data_ptr_t Reallocate(data_ptr_t pointer, idx_t old_size, idx_t size); DUCKDB_API data_ptr_t AllocateAligned(idx_t size); @@ -51,13 +42,6 @@ class ArenaAllocator { //! Increment the internal cursor (if required) so the next allocation is guaranteed to be aligned to 8 bytes DUCKDB_API void AlignNext(); - //! This shrinks the LAST allocation that was made using the allocator - //! Note that we can ONLY safely call this method if Allocate has been called previously with a size >= shrink_size - DUCKDB_API void ShrinkHead(idx_t shrink_size) const { - D_ASSERT(head && head->current_position >= shrink_size); - head->current_position -= shrink_size; - } - //! Resets the current head and destroys all previous arena chunks DUCKDB_API void Reset(); DUCKDB_API void Destroy(); @@ -77,9 +61,6 @@ class ArenaAllocator { return arena_allocator; } -private: - void AllocateNewBlock(idx_t min_size); - private: //! Internal allocator that is used by the arena allocator Allocator &allocator; diff --git a/src/duckdb/src/include/duckdb/storage/checkpoint/string_checkpoint_state.hpp b/src/duckdb/src/include/duckdb/storage/checkpoint/string_checkpoint_state.hpp index 5ff309563..2b49a4cbc 100644 --- a/src/duckdb/src/include/duckdb/storage/checkpoint/string_checkpoint_state.hpp +++ b/src/duckdb/src/include/duckdb/storage/checkpoint/string_checkpoint_state.hpp @@ -43,8 +43,6 @@ struct UncompressedStringSegmentState : public CompressedSegmentState { unordered_map> overflow_blocks; //! Overflow string writer (if any), if not set overflow strings will be written to memory blocks unique_ptr overflow_writer; - //! The block manager with which to write - optional_ptr block_manager; //! The set of overflow blocks written to disk (if any) vector on_disk_blocks; @@ -53,10 +51,18 @@ struct UncompressedStringSegmentState : public CompressedSegmentState { void RegisterBlock(BlockManager &manager, block_id_t block_id); - string GetSegmentInfo() const override; + string GetSegmentInfo() const override { + if (on_disk_blocks.empty()) { + return ""; + } + string result = StringUtil::Join(on_disk_blocks, on_disk_blocks.size(), ", ", + [&](block_id_t block) { return to_string(block); }); + return "Overflow String Block Ids: " + result; + } - vector GetAdditionalBlocks() const override; - void Cleanup(BlockManager &manager); + vector GetAdditionalBlocks() const override { + return on_disk_blocks; + } private: mutex block_lock; diff --git a/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp b/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp index 89480cbf4..90b5e7532 100644 --- a/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +++ b/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp @@ -8,7 +8,6 @@ #pragma once -#include "duckdb/parallel/task_executor.hpp" #include "duckdb/storage/checkpoint/row_group_writer.hpp" namespace duckdb { @@ -38,8 +37,9 @@ class TableDataWriter { virtual void AddRowGroup(RowGroupPointer &&row_group_pointer, unique_ptr writer); virtual CheckpointType GetCheckpointType() const = 0; + TaskScheduler &GetScheduler(); DatabaseInstance &GetDatabase(); - unique_ptr CreateTaskExecutor(); + optional_ptr GetClientContext(); protected: DuckTableEntry &table; diff --git a/src/duckdb/src/include/duckdb/storage/data_table.hpp b/src/duckdb/src/include/duckdb/storage/data_table.hpp index 9dab751c7..6a0b97727 100644 --- a/src/duckdb/src/include/duckdb/storage/data_table.hpp +++ b/src/duckdb/src/include/duckdb/storage/data_table.hpp @@ -29,6 +29,7 @@ class ColumnDataCollection; class ColumnDefinition; class DataTable; class DuckTransaction; +class OptimisticDataWriter; class RowGroup; class StorageManager; class TableCatalogEntry; @@ -43,14 +44,8 @@ struct ConstraintState; struct TableUpdateState; enum class VerifyExistenceType : uint8_t; -enum class DataTableVersion { - MAIN_TABLE, // this is the newest version of the table - it has not been altered or dropped - ALTERED, // this table has been altered - DROPPED // this table has been dropped -}; - //! DataTable represents a physical table on disk -class DataTable : public enable_shared_from_this { +class DataTable { public: //! Constructs a new data table from an (optional) set of persistent segments DataTable(AttachedDatabase &db, shared_ptr table_io_manager, const string &schema, @@ -79,8 +74,8 @@ class DataTable : public enable_shared_from_this { vector GetTypes(); const vector &Columns() const; - void InitializeScan(ClientContext &context, DuckTransaction &transaction, TableScanState &state, - const vector &column_ids, optional_ptr table_filters = nullptr); + void InitializeScan(DuckTransaction &transaction, TableScanState &state, const vector &column_ids, + TableFilterSet *table_filters = nullptr); //! Returns the maximum amount of threads that should be assigned to scan this data table idx_t MaxThreads(ClientContext &context) const; @@ -120,15 +115,9 @@ class DataTable : public enable_shared_from_this { optional_ptr> column_ids); //! Merge a row group collection into the transaction-local storage void LocalMerge(ClientContext &context, RowGroupCollection &collection); - //! Create an optimistic row group collection for this table. Used for optimistically writing parallel appends. - //! Returns the index into the optimistic_collections vector for newly created collection. - PhysicalIndex CreateOptimisticCollection(ClientContext &context, unique_ptr collection); - //! Returns the optimistic row group collection corresponding to the index. - RowGroupCollection &GetOptimisticCollection(ClientContext &context, const PhysicalIndex collection_index); - //! Resets the optimistic row group collection corresponding to the index. - void ResetOptimisticCollection(ClientContext &context, const PhysicalIndex collection_index); - //! Returns the optimistic writer of the corresponding local table. - OptimisticDataWriter &GetOptimisticWriter(ClientContext &context); + //! Creates an optimistic writer for this table - used for optimistically writing parallel appends + OptimisticDataWriter &CreateOptimisticWriter(ClientContext &context); + void FinalizeOptimisticWriter(ClientContext &context, OptimisticDataWriter &writer); unique_ptr InitializeDelete(TableCatalogEntry &table, ClientContext &context, const vector> &bound_constraints); @@ -189,21 +178,13 @@ class DataTable : public enable_shared_from_this { //! Remove the row identifiers from all the indexes of the table void RemoveFromIndexes(Vector &row_identifiers, idx_t count); - void SetAsMainTable() { - this->version = DataTableVersion::MAIN_TABLE; + void SetAsRoot() { + this->is_root = true; } - void SetAsDropped() { - this->version = DataTableVersion::DROPPED; - } - - bool IsMainTable() const { - return this->version == DataTableVersion::MAIN_TABLE; - } - bool IsRoot() const { - return IsMainTable(); + bool IsRoot() { + return this->is_root; } - string TableModification() const; //! Get statistics of a physical column within the table unique_ptr GetStatistics(ClientContext &context, column_t column_id); @@ -220,7 +201,7 @@ class DataTable : public enable_shared_from_this { //! Checkpoint the table to the specified table data writer void Checkpoint(TableDataWriter &writer, Serializer &serializer); void CommitDropTable(); - void CommitDropColumn(const idx_t column_index); + void CommitDropColumn(idx_t index); idx_t ColumnCount() const; idx_t GetTotalRows() const; @@ -248,7 +229,6 @@ class DataTable : public enable_shared_from_this { bool HasForeignKeyIndex(const vector &keys, ForeignKeyType type); void SetIndexStorageInfo(vector index_storage_info); void VacuumIndexes(); - void VerifyIndexBuffers(); void CleanupAppend(transaction_t lowest_transaction, idx_t start, idx_t count); string GetTableName() const; @@ -304,7 +284,8 @@ class DataTable : public enable_shared_from_this { mutex append_lock; //! The row groups of the table shared_ptr row_groups; - //! The version of the data table - atomic version; + //! Whether or not the data table is the root DataTable for this table; the root DataTable is the newest version + //! that can be appended to + atomic is_root; }; } // namespace duckdb diff --git a/src/duckdb/src/include/duckdb/storage/optimistic_data_writer.hpp b/src/duckdb/src/include/duckdb/storage/optimistic_data_writer.hpp index cdf96a038..802d51bad 100644 --- a/src/duckdb/src/include/duckdb/storage/optimistic_data_writer.hpp +++ b/src/duckdb/src/include/duckdb/storage/optimistic_data_writer.hpp @@ -39,7 +39,7 @@ class OptimisticDataWriter { private: //! The table DataTable &table; - //! The partial block manager, if any was created. + //! The partial block manager (if we created one yet) unique_ptr partial_manager; }; diff --git a/src/duckdb/src/include/duckdb/storage/partial_block_manager.hpp b/src/duckdb/src/include/duckdb/storage/partial_block_manager.hpp index c59869976..b46ea65ad 100644 --- a/src/duckdb/src/include/duckdb/storage/partial_block_manager.hpp +++ b/src/duckdb/src/include/duckdb/storage/partial_block_manager.hpp @@ -129,6 +129,9 @@ class PartialBlockManager { //! Returns a reference to the underlying block manager. BlockManager &GetBlockManager() const; + //! Registers a block as "written" by this partial block manager + void AddWrittenBlock(block_id_t block); + protected: BlockManager &block_manager; PartialBlockType partial_block_type; @@ -137,6 +140,8 @@ class PartialBlockManager { //! This is a multimap because there might be outstanding partial blocks with //! the same amount of left-over space multimap> partially_filled_blocks; + //! The set of written blocks + unordered_set written_blocks; //! The maximum size (in bytes) at which a partial block will be considered a partial block uint32_t max_partial_block_size; diff --git a/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp b/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp index 9b5ca0b39..6ae410bea 100644 --- a/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp +++ b/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp @@ -54,8 +54,6 @@ struct StringStats { //! Resets the max string length so HasMaxStringLength() is false DUCKDB_API static void ResetMaxStringLength(BaseStatistics &stats); - //! Sets the max string length - DUCKDB_API static void SetMaxStringLength(BaseStatistics &stats, uint32_t length); //! FIXME: make this part of Set on statistics DUCKDB_API static void SetContainsUnicode(BaseStatistics &stats); diff --git a/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp b/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp index b5342829c..9873b6761 100644 --- a/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +++ b/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp @@ -18,6 +18,7 @@ #include "duckdb/storage/buffer_manager.hpp" #include "duckdb/storage/checkpoint/string_checkpoint_state.hpp" #include "duckdb/storage/segment/uncompressed.hpp" +#include "duckdb/storage/string_uncompressed.hpp" #include "duckdb/storage/table/append_state.hpp" #include "duckdb/storage/table/column_segment.hpp" #include "duckdb/storage/table/scan_state.hpp" diff --git a/src/duckdb/src/include/duckdb/storage/table/array_column_data.hpp b/src/duckdb/src/include/duckdb/storage/table/array_column_data.hpp index 05d48e9c0..2a0ec1d07 100644 --- a/src/duckdb/src/include/duckdb/storage/table/array_column_data.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/array_column_data.hpp @@ -36,10 +36,8 @@ class ArrayColumnData : public ColumnData { idx_t scan_count) override; idx_t ScanCommitted(idx_t vector_index, ColumnScanState &state, Vector &result, bool allow_updates, idx_t scan_count) override; - idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset = 0) override; + idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count) override; - void Select(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, - SelectionVector &sel, idx_t sel_count) override; void Skip(ColumnScanState &state, idx_t count = STANDARD_VECTOR_SIZE) override; void InitializeAppend(ColumnAppendState &state) override; diff --git a/src/duckdb/src/include/duckdb/storage/table/column_data.hpp b/src/duckdb/src/include/duckdb/storage/table/column_data.hpp index a1e339450..aa85b66b8 100644 --- a/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/column_data.hpp @@ -120,11 +120,11 @@ class ColumnData { idx_t scan_count); virtual void ScanCommittedRange(idx_t row_group_start, idx_t offset_in_row_group, idx_t count, Vector &result); - virtual idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset = 0); + virtual idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count); //! Select virtual void Filter(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, - SelectionVector &sel, idx_t &count, const TableFilter &filter, TableFilterState &filter_state); + SelectionVector &sel, idx_t &count, const TableFilter &filter); virtual void Select(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, SelectionVector &sel, idx_t count); virtual void SelectCommitted(idx_t vector_index, ColumnScanState &state, Vector &result, SelectionVector &sel, @@ -196,8 +196,7 @@ class ColumnData { void BeginScanVectorInternal(ColumnScanState &state); //! Scans a base vector from the column - idx_t ScanVector(ColumnScanState &state, Vector &result, idx_t remaining, ScanVectorType scan_type, - idx_t result_offset = 0); + idx_t ScanVector(ColumnScanState &state, Vector &result, idx_t remaining, ScanVectorType scan_type); //! Scans a vector from the column merged with any potential updates idx_t ScanVector(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, idx_t target_scan, ScanVectorType scan_type, ScanVectorMode mode); @@ -206,7 +205,7 @@ class ColumnData { void SelectVector(ColumnScanState &state, Vector &result, idx_t target_count, const SelectionVector &sel, idx_t sel_count); void FilterVector(ColumnScanState &state, Vector &result, idx_t target_count, SelectionVector &sel, - idx_t &sel_count, const TableFilter &filter, TableFilterState &filter_state); + idx_t &sel_count, const TableFilter &filter); void ClearUpdates(); void FetchUpdates(TransactionData transaction, idx_t vector_index, Vector &result, idx_t scan_count, diff --git a/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp b/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp index 4015bcf70..45d2db0c0 100644 --- a/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp @@ -28,7 +28,6 @@ class Transaction; class BaseStatistics; class UpdateSegment; class TableFilter; -struct TableFilterState; struct ColumnFetchState; struct ColumnScanState; struct ColumnAppendState; @@ -69,13 +68,12 @@ class ColumnSegment : public SegmentBase { void Select(ColumnScanState &state, idx_t scan_count, Vector &result, const SelectionVector &sel, idx_t sel_count); //! Scan one vector while applying a filter to the vector, returning only the matching elements void Filter(ColumnScanState &state, idx_t scan_count, Vector &result, SelectionVector &sel, idx_t &sel_count, - const TableFilter &filter, TableFilterState &filter_state); + const TableFilter &filter); //! Fetch a value of the specific row id and append it to the result void FetchRow(ColumnFetchState &state, row_t row_id, Vector &result, idx_t result_idx); static idx_t FilterSelection(SelectionVector &sel, Vector &vector, UnifiedVectorFormat &vdata, - const TableFilter &filter, TableFilterState &filter_state, idx_t scan_count, - idx_t &approved_tuple_count); + const TableFilter &filter, idx_t scan_count, idx_t &approved_tuple_count); //! Skip a scan forward to the row_index specified in the scan state void Skip(ColumnScanState &state); diff --git a/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp b/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp index f80371f4f..c4ec56740 100644 --- a/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp @@ -36,7 +36,7 @@ class ListColumnData : public ColumnData { idx_t scan_count) override; idx_t ScanCommitted(idx_t vector_index, ColumnScanState &state, Vector &result, bool allow_updates, idx_t scan_count) override; - idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset = 0) override; + idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count) override; void Skip(ColumnScanState &state, idx_t count = STANDARD_VECTOR_SIZE) override; diff --git a/src/duckdb/src/include/duckdb/storage/table/row_group.hpp b/src/duckdb/src/include/duckdb/storage/table/row_group.hpp index 8ceea68a3..16a535a4e 100644 --- a/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/row_group.hpp @@ -102,7 +102,7 @@ class RowGroup : public SegmentBase { unique_ptr RemoveColumn(RowGroupCollection &collection, idx_t removed_column); void CommitDrop(); - void CommitDropColumn(const idx_t column_index); + void CommitDropColumn(idx_t index); void InitializeEmpty(const vector &types); diff --git a/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp b/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp index 53242b9af..19aa64520 100644 --- a/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp @@ -60,7 +60,7 @@ class RowGroupCollection { void Verify(); void InitializeScan(CollectionScanState &state, const vector &column_ids, - optional_ptr table_filters); + TableFilterSet *table_filters); void InitializeCreateIndexScan(CreateIndexScanState &state); void InitializeScanWithOffset(CollectionScanState &state, const vector &column_ids, idx_t start_row, idx_t end_row); @@ -108,7 +108,7 @@ class RowGroupCollection { bool schedule_vacuum); unique_ptr GetCheckpointTask(CollectionCheckpointState &checkpoint_state, idx_t segment_idx); - void CommitDropColumn(const idx_t column_index); + void CommitDropColumn(idx_t index); void CommitDropTable(); vector GetPartitionStats() const; diff --git a/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp b/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp index b8b54f889..e94381a65 100644 --- a/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp @@ -18,7 +18,6 @@ #include "duckdb/common/types/data_chunk.hpp" #include "duckdb/parser/parsed_data/sample_options.hpp" #include "duckdb/storage/storage_index.hpp" -#include "duckdb/planner/table_filter_state.hpp" namespace duckdb { class AdaptiveFilter; @@ -41,7 +40,6 @@ class TableFilter; struct AdaptiveFilterState; struct TableScanOptions; struct ScanSamplingInfo; -struct TableFilterState; struct SegmentScanState { virtual ~SegmentScanState() { @@ -130,7 +128,6 @@ struct ScanFilter { idx_t table_column_index; TableFilter &filter; bool always_true; - unique_ptr filter_state; bool IsAlwaysTrue() const { return always_true; @@ -141,7 +138,7 @@ class ScanFilterInfo { public: ~ScanFilterInfo(); - void Initialize(ClientContext &context, TableFilterSet &filters, const vector &column_ids); + void Initialize(TableFilterSet &filters, const vector &column_ids); const vector &GetFilterList() const { return filter_list; @@ -255,8 +252,7 @@ class TableScanState { ScanSamplingInfo sampling_info; public: - void Initialize(vector column_ids, optional_ptr context = nullptr, - optional_ptr table_filters = nullptr, + void Initialize(vector column_ids, optional_ptr table_filters = nullptr, optional_ptr table_sampling = nullptr); const vector &GetColumnIds(); diff --git a/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp b/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp index 9bad48ffa..97fbc889c 100644 --- a/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp @@ -34,10 +34,10 @@ class StandardColumnData : public ColumnData { idx_t target_count) override; idx_t ScanCommitted(idx_t vector_index, ColumnScanState &state, Vector &result, bool allow_updates, idx_t target_count) override; - idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset) override; + idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count) override; void Filter(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, - SelectionVector &sel, idx_t &count, const TableFilter &filter, TableFilterState &filter_state) override; + SelectionVector &sel, idx_t &count, const TableFilter &filter) override; void Select(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, SelectionVector &sel, idx_t sel_count) override; diff --git a/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp b/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp index b3fd8f4d0..0d5d79231 100644 --- a/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp @@ -36,7 +36,7 @@ class StructColumnData : public ColumnData { idx_t scan_count) override; idx_t ScanCommitted(idx_t vector_index, ColumnScanState &state, Vector &result, bool allow_updates, idx_t scan_count) override; - idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset = 0) override; + idx_t ScanCount(ColumnScanState &state, Vector &result, idx_t count) override; void Skip(ColumnScanState &state, idx_t count = STANDARD_VECTOR_SIZE) override; diff --git a/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp b/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp index 0b7993d73..a0e325c31 100644 --- a/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +++ b/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp @@ -67,10 +67,9 @@ class UpdateSegment { public: typedef void (*initialize_update_function_t)(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, - UnifiedVectorFormat &update, const SelectionVector &sel); + Vector &update, const SelectionVector &sel); typedef void (*merge_update_function_t)(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, - UnifiedVectorFormat &update, row_t *ids, idx_t count, - const SelectionVector &sel); + Vector &update, row_t *ids, idx_t count, const SelectionVector &sel); typedef void (*fetch_update_function_t)(transaction_t start_time, transaction_t transaction_id, UpdateInfo &info, Vector &result); typedef void (*fetch_committed_function_t)(UpdateInfo &info, Vector &result); @@ -79,8 +78,8 @@ class UpdateSegment { typedef void (*fetch_row_function_t)(transaction_t start_time, transaction_t transaction_id, UpdateInfo &info, idx_t row_idx, Vector &result, idx_t result_idx); typedef void (*rollback_update_function_t)(UpdateInfo &base_info, UpdateInfo &rollback_info); - typedef idx_t (*statistics_update_function_t)(UpdateSegment *segment, SegmentStatistics &stats, - UnifiedVectorFormat &update, idx_t count, SelectionVector &sel); + typedef idx_t (*statistics_update_function_t)(UpdateSegment *segment, SegmentStatistics &stats, Vector &update, + idx_t count, SelectionVector &sel); private: initialize_update_function_t initialize_update_function; diff --git a/src/duckdb/src/include/duckdb/storage/temporary_memory_manager.hpp b/src/duckdb/src/include/duckdb/storage/temporary_memory_manager.hpp index af9539f00..c0e0829d4 100644 --- a/src/duckdb/src/include/duckdb/storage/temporary_memory_manager.hpp +++ b/src/duckdb/src/include/duckdb/storage/temporary_memory_manager.hpp @@ -85,12 +85,9 @@ class TemporaryMemoryManager { static constexpr idx_t MINIMUM_RESERVATION_MEMORY_LIMIT_DIVISOR = 16ULL; //! The maximum ratio of the memory limit that we reserve using the TemporaryMemoryManager - static constexpr double MAXIMUM_MEMORY_LIMIT_RATIO = 0.9; + static constexpr double MAXIMUM_MEMORY_LIMIT_RATIO = 0.8; //! The maximum ratio of the remaining memory that we reserve per TemporaryMemoryState - static constexpr double MAXIMUM_FREE_MEMORY_RATIO = 0.9; - //! Or, we leave room for between this many minimum reservations (if it is less than MAXIMUM_FREE_MEMORY_RATIO) - static constexpr idx_t MINIMUM_REMAINING_STATE_RESERVATIONS = 8ULL; - static constexpr idx_t MAXIMUM_REMAINING_STATE_RESERVATIONS = 32ULL; + static constexpr double MAXIMUM_FREE_MEMORY_RATIO = 2.0 / 3.0; public: //! Get the TemporaryMemoryManager @@ -101,8 +98,6 @@ class TemporaryMemoryManager { private: //! Locks the TemporaryMemoryManager unique_lock Lock(); - //! Get the default minimum reservation - idx_t DefaultMinimumReservation() const; //! Unregister a TemporaryMemoryState (called by the destructor of TemporaryMemoryState) void Unregister(TemporaryMemoryState &temporary_memory_state); //! Update memory_limit, has_temporary_directory, and num_threads (must hold the lock) @@ -128,8 +123,6 @@ class TemporaryMemoryManager { bool has_temporary_directory = false; //! Number of threads idx_t num_threads = DConstants::INVALID_INDEX; - //! Number of active connections - idx_t num_connections = DConstants::INVALID_INDEX; //! Max memory per query idx_t query_max_memory = DConstants::INVALID_INDEX; diff --git a/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp b/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp index 933801001..e17c048be 100644 --- a/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp +++ b/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp @@ -81,11 +81,11 @@ class DuckTransaction : public Transaction { return write_lock.get(); } + void UpdateCollection(shared_ptr &collection); + //! Get a shared lock on a table shared_ptr SharedLockTable(DataTableInfo &info); - void ModifyTable(DataTable &tbl); - private: DuckTransactionManager &transaction_manager; //! The undo buffer is used to store old versions of rows that are updated @@ -99,8 +99,8 @@ class DuckTransaction : public Transaction { mutex sequence_lock; //! Map of all sequences that were used during the transaction and the value they had in this transaction reference_map_t> sequence_usage; - //! Tables that are modified by this transaction - reference_map_t> modified_tables; + //! Collections that are updated by this transaction + reference_map_t> updated_collections; //! Lock for the active_locks map mutex active_locks_lock; struct ActiveTableLock { diff --git a/src/duckdb/src/include/duckdb/transaction/local_storage.hpp b/src/duckdb/src/include/duckdb/transaction/local_storage.hpp index 4119e968d..4213fa0fa 100644 --- a/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +++ b/src/duckdb/src/include/duckdb/transaction/local_storage.hpp @@ -29,12 +29,11 @@ class LocalTableStorage : public enable_shared_from_this { public: // Create a new LocalTableStorage explicit LocalTableStorage(ClientContext &context, DataTable &table); - //! Create a LocalTableStorage from an ALTER TYPE. - LocalTableStorage(ClientContext &context, DataTable &new_data_table, LocalTableStorage &parent, - const idx_t alter_column_index, const LogicalType &target_type, - const vector &bound_columns, Expression &cast_expr); - //! Create a LocalTableStorage from a DROP COLUMN. - LocalTableStorage(DataTable &new_data_table, LocalTableStorage &parent, const idx_t drop_column_index); + // Create a LocalTableStorage from an ALTER TYPE + LocalTableStorage(ClientContext &context, DataTable &table, LocalTableStorage &parent, idx_t changed_idx, + const LogicalType &target_type, const vector &bound_columns, Expression &cast_expr); + // Create a LocalTableStorage from a DROP COLUMN + LocalTableStorage(DataTable &table, LocalTableStorage &parent, idx_t drop_idx); // Create a LocalTableStorage from an ADD COLUMN LocalTableStorage(ClientContext &context, DataTable &table, LocalTableStorage &parent, ColumnDefinition &new_column, ExpressionExecutor &default_executor); @@ -43,7 +42,7 @@ class LocalTableStorage : public enable_shared_from_this { reference table_ref; Allocator &allocator; - //! The main row group collection. + //! The main chunk collection holding the data shared_ptr row_groups; //! The set of unique append indexes. TableIndexList append_indexes; @@ -53,12 +52,10 @@ class LocalTableStorage : public enable_shared_from_this { IndexAppendMode index_append_mode = IndexAppendMode::DEFAULT; //! The number of deleted rows idx_t deleted_rows; - - //! The optimistic row group collections associated with this table. - vector> optimistic_collections; - //! The main optimistic data writer associated with this table. + //! The main optimistic data writer OptimisticDataWriter optimistic_writer; - + //! The set of all optimistic data writers associated with this table + vector> optimistic_writers; //! Whether or not storage was merged bool merged_storage = false; //! Whether or not the storage was dropped @@ -77,18 +74,9 @@ class LocalTableStorage : public enable_shared_from_this { const vector &table_types, row_t &start_row); void AppendToDeleteIndexes(Vector &row_ids, DataChunk &delete_chunk); - //! Create an optimistic row group collection for this table. - //! Returns the index into the optimistic_collections vector for newly created collection. - PhysicalIndex CreateOptimisticCollection(unique_ptr collection); - //! Returns the optimistic row group collection corresponding to the index. - RowGroupCollection &GetOptimisticCollection(const PhysicalIndex collection_index); - //! Resets the optimistic row group collection corresponding to the index. - void ResetOptimisticCollection(const PhysicalIndex collection_index); - //! Returns the optimistic writer. - OptimisticDataWriter &GetOptimisticWriter(); - -private: - mutex collections_lock; + //! Creates an optimistic writer for this table + OptimisticDataWriter &CreateOptimisticWriter(); + void FinalizeOptimisticWriter(OptimisticDataWriter &writer); }; class LocalTableManager { @@ -142,15 +130,9 @@ class LocalStorage { static void FinalizeAppend(LocalAppendState &state); //! Merge a row group collection into the transaction-local storage void LocalMerge(DataTable &table, RowGroupCollection &collection); - //! Create an optimistic row group collection for this table. - //! Returns the index into the optimistic_collections vector for newly created collection. - PhysicalIndex CreateOptimisticCollection(DataTable &table, unique_ptr collection); - //! Returns the optimistic row group collection corresponding to the index. - RowGroupCollection &GetOptimisticCollection(DataTable &table, const PhysicalIndex collection_index); - //! Resets the optimistic row group collection corresponding to the index. - void ResetOptimisticCollection(DataTable &table, const PhysicalIndex collection_index); - //! Returns the optimistic writer. - OptimisticDataWriter &GetOptimisticWriter(DataTable &table); + //! Create an optimistic writer for the specified table + OptimisticDataWriter &CreateOptimisticWriter(DataTable &table); + void FinalizeOptimisticWriter(DataTable &table, OptimisticDataWriter &writer); //! Delete a set of rows from the local storage idx_t Delete(DataTable &table, Vector &row_ids, idx_t count); @@ -173,7 +155,7 @@ class LocalStorage { void AddColumn(DataTable &old_dt, DataTable &new_dt, ColumnDefinition &new_column, ExpressionExecutor &default_executor); - void DropColumn(DataTable &old_dt, DataTable &new_dt, const idx_t drop_column_index); + void DropColumn(DataTable &old_dt, DataTable &new_dt, idx_t removed_column); void ChangeType(DataTable &old_dt, DataTable &new_dt, idx_t changed_idx, const LogicalType &target_type, const vector &bound_columns, Expression &cast_expr); @@ -190,7 +172,6 @@ class LocalStorage { DuckTransaction &transaction; LocalTableManager table_manager; -private: void Flush(DataTable &table, LocalTableStorage &storage, optional_ptr commit_state); }; diff --git a/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp b/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp index ca6b2c920..fbcca106e 100644 --- a/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +++ b/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp @@ -25,14 +25,11 @@ class Transaction; //! The MetaTransaction manages multiple transactions for different attached databases class MetaTransaction { public: - DUCKDB_API MetaTransaction(ClientContext &context, timestamp_t start_timestamp, - transaction_t global_transaction_id); + DUCKDB_API MetaTransaction(ClientContext &context, timestamp_t start_timestamp); ClientContext &context; //! The timestamp when the transaction started timestamp_t start_timestamp; - //! The global identifier of the transaction - transaction_t global_transaction_id; //! The validity checker of the transaction ValidChecker transaction_validity; //! The active query number diff --git a/src/duckdb/src/include/duckdb_extension.h b/src/duckdb/src/include/duckdb_extension.h index 8a05b1358..47c6a7f87 100644 --- a/src/duckdb/src/include/duckdb_extension.h +++ b/src/duckdb/src/include/duckdb_extension.h @@ -542,19 +542,6 @@ typedef struct { idx_t row); #endif -// New string functions that are added -#ifdef DUCKDB_EXTENSION_API_VERSION_UNSTABLE - char *(*duckdb_value_to_string)(duckdb_value value); -#endif - -// An API to create new vector types -#ifdef DUCKDB_EXTENSION_API_VERSION_UNSTABLE - void (*duckdb_slice_vector)(duckdb_vector vector, duckdb_selection_vector selection, idx_t len); - duckdb_selection_vector (*duckdb_create_selection_vector)(idx_t size); - void (*duckdb_destroy_selection_vector)(duckdb_selection_vector vector); - sel_t *(*duckdb_selection_vector_get_data_ptr)(duckdb_selection_vector vector); -#endif - } duckdb_ext_api_v1; //===--------------------------------------------------------------------===// @@ -977,15 +964,6 @@ typedef struct { // Version unstable_new_append_functions #define duckdb_append_default_to_chunk duckdb_ext_api.duckdb_append_default_to_chunk -// Version unstable_new_string_functions -#define duckdb_value_to_string duckdb_ext_api.duckdb_value_to_string - -// Version unstable_new_vector_types -#define duckdb_slice_vector duckdb_ext_api.duckdb_slice_vector -#define duckdb_create_selection_vector duckdb_ext_api.duckdb_create_selection_vector -#define duckdb_destroy_selection_vector duckdb_ext_api.duckdb_destroy_selection_vector -#define duckdb_selection_vector_get_data_ptr duckdb_ext_api.duckdb_selection_vector_get_data_ptr - //===--------------------------------------------------------------------===// // Struct Global Macros //===--------------------------------------------------------------------===// diff --git a/src/duckdb/src/logging/log_manager.cpp b/src/duckdb/src/logging/log_manager.cpp index f493e2ee5..c937b3fda 100644 --- a/src/duckdb/src/logging/log_manager.cpp +++ b/src/duckdb/src/logging/log_manager.cpp @@ -149,11 +149,6 @@ void LogManager::SetLogStorage(DatabaseInstance &db, const string &storage_name) config.storage = storage_name_to_lower; } -void LogManager::TruncateLogStorage() { - unique_lock lck(lock); - log_storage->Truncate(); -} - LogConfig LogManager::GetConfig() { unique_lock lck(lock); return config; diff --git a/src/duckdb/src/logging/log_storage.cpp b/src/duckdb/src/logging/log_storage.cpp index 625757490..909bddf75 100644 --- a/src/duckdb/src/logging/log_storage.cpp +++ b/src/duckdb/src/logging/log_storage.cpp @@ -25,9 +25,6 @@ bool LogStorage::ScanContexts(LogStorageScanState &state, DataChunk &result) con void LogStorage::InitializeScanContexts(LogStorageScanState &state) const { throw NotImplementedException("Not implemented for this LogStorage: InitializeScanContexts"); } -void LogStorage::Truncate() { - throw NotImplementedException("Not implemented for this LogStorage: TruncateLogStorage"); -} StdOutLogStorage::StdOutLogStorage() { } @@ -40,19 +37,15 @@ void StdOutLogStorage::WriteLogEntry(timestamp_t timestamp, LogLevel level, cons std::cout << StringUtil::Format( "[LOG] %s, %s, %s, %s, %s, %s, %s, %s\n", Value::TIMESTAMP(timestamp).ToString(), log_type, EnumUtil::ToString(level), log_message, EnumUtil::ToString(context.context.scope), - context.context.connection_id.IsValid() ? to_string(context.context.connection_id.GetIndex()) : "NULL", + context.context.client_context.IsValid() ? to_string(context.context.client_context.GetIndex()) : "NULL", context.context.transaction_id.IsValid() ? to_string(context.context.transaction_id.GetIndex()) : "NULL", - context.context.thread_id.IsValid() ? to_string(context.context.thread_id.GetIndex()) : "NULL"); + context.context.thread.IsValid() ? to_string(context.context.thread.GetIndex()) : "NULL"); } void StdOutLogStorage::WriteLogEntries(DataChunk &chunk, const RegisteredLoggingContext &context) { throw NotImplementedException("StdOutLogStorage::WriteLogEntries"); } -void StdOutLogStorage::Truncate() { - // NOP -} - void StdOutLogStorage::Flush() { // NOP } @@ -77,9 +70,8 @@ InMemoryLogStorage::InMemoryLogStorage(DatabaseInstance &db_p) vector log_context_schema = { LogicalType::UBIGINT, // context_id LogicalType::VARCHAR, // scope TODO: enumify - LogicalType::UBIGINT, // connection_id + LogicalType::UBIGINT, // client_context LogicalType::UBIGINT, // transaction_id - LogicalType::UBIGINT, // query_id LogicalType::UBIGINT, // thread }; @@ -90,16 +82,6 @@ InMemoryLogStorage::InMemoryLogStorage(DatabaseInstance &db_p) log_contexts = make_uniq(db_p.GetBufferManager(), log_context_schema); } -void InMemoryLogStorage::ResetBuffers() { - entry_buffer->Reset(); - log_context_buffer->Reset(); - - log_entries->Reset(); - log_contexts->Reset(); - - registered_contexts.clear(); -} - InMemoryLogStorage::~InMemoryLogStorage() { } @@ -140,11 +122,6 @@ void InMemoryLogStorage::Flush() { FlushInternal(); } -void InMemoryLogStorage::Truncate() { - unique_lock lck(lock); - ResetBuffers(); -} - void InMemoryLogStorage::FlushInternal() { if (entry_buffer->size() > 0) { log_entries->Append(*entry_buffer); @@ -169,9 +146,9 @@ void InMemoryLogStorage::WriteLoggingContext(const RegisteredLoggingContext &con context_scope_data[size] = StringVector::AddString(log_context_buffer->data[1], EnumUtil::ToString(context.context.scope)); - if (context.context.connection_id.IsValid()) { + if (context.context.client_context.IsValid()) { auto client_context_data = FlatVector::GetData(log_context_buffer->data[2]); - client_context_data[size] = context.context.connection_id.GetIndex(); + client_context_data[size] = context.context.client_context.GetIndex(); } else { FlatVector::Validity(log_context_buffer->data[2]).SetInvalid(size); } @@ -181,20 +158,13 @@ void InMemoryLogStorage::WriteLoggingContext(const RegisteredLoggingContext &con } else { FlatVector::Validity(log_context_buffer->data[3]).SetInvalid(size); } - if (context.context.query_id.IsValid()) { - auto client_context_data = FlatVector::GetData(log_context_buffer->data[4]); - client_context_data[size] = context.context.query_id.GetIndex(); + if (context.context.thread.IsValid()) { + auto thread_data = FlatVector::GetData(log_context_buffer->data[4]); + thread_data[size] = context.context.thread.GetIndex(); } else { FlatVector::Validity(log_context_buffer->data[4]).SetInvalid(size); } - if (context.context.thread_id.IsValid()) { - auto thread_data = FlatVector::GetData(log_context_buffer->data[5]); - thread_data[size] = context.context.thread_id.GetIndex(); - } else { - FlatVector::Validity(log_context_buffer->data[5]).SetInvalid(size); - } - log_context_buffer->SetCardinality(size + 1); if (size + 1 >= max_buffer_size) { diff --git a/src/duckdb/src/main/appender.cpp b/src/duckdb/src/main/appender.cpp index 83e41da36..11a5753a6 100644 --- a/src/duckdb/src/main/appender.cpp +++ b/src/duckdb/src/main/appender.cpp @@ -65,8 +65,7 @@ Appender::Appender(Connection &con, const string &database_name, const string &s description = con.TableInfo(database_name, schema_name, table_name); if (!description) { - throw CatalogException( - StringUtil::Format("Table \"%s.%s.%s\" could not be found", database_name, schema_name, table_name)); + throw CatalogException(StringUtil::Format("Table \"%s.%s\" could not be found", schema_name, table_name)); } if (description->readonly) { throw InvalidInputException("Cannot append to a readonly database."); diff --git a/src/duckdb/src/main/attached_database.cpp b/src/duckdb/src/main/attached_database.cpp index 31e4a719b..64c80df56 100644 --- a/src/duckdb/src/main/attached_database.cpp +++ b/src/duckdb/src/main/attached_database.cpp @@ -173,11 +173,11 @@ string AttachedDatabase::ExtractDatabaseName(const string &dbpath, FileSystem &f return name; } -void AttachedDatabase::Initialize(optional_ptr context, StorageOptions options) { +void AttachedDatabase::Initialize(StorageOptions options) { if (IsSystem()) { - catalog->Initialize(context, true); + catalog->Initialize(true); } else { - catalog->Initialize(context, false); + catalog->Initialize(false); } if (storage) { storage->Initialize(options); diff --git a/src/duckdb/src/main/capi/data_chunk-c.cpp b/src/duckdb/src/main/capi/data_chunk-c.cpp index cf0b16a21..b549e74df 100644 --- a/src/duckdb/src/main/capi/data_chunk-c.cpp +++ b/src/duckdb/src/main/capi/data_chunk-c.cpp @@ -208,21 +208,3 @@ void duckdb_validity_set_row_valid(uint64_t *validity, idx_t row) { idx_t idx_in_entry = row % 64; validity[entry_idx] |= (uint64_t)1 << idx_in_entry; } - -duckdb_selection_vector duckdb_create_selection_vector(idx_t size) { - return reinterpret_cast(new duckdb::SelectionVector(size)); -} - -void duckdb_destroy_selection_vector(duckdb_selection_vector vector) { - delete reinterpret_cast(vector); -} - -sel_t *duckdb_selection_vector_get_data_ptr(duckdb_selection_vector vector) { - return reinterpret_cast(vector)->data(); -} - -void duckdb_slice_vector(duckdb_vector dict, duckdb_selection_vector selection, idx_t len) { - auto ddict = reinterpret_cast(dict); - auto dselection = reinterpret_cast(selection); - ddict->Slice(*dselection, len); -} diff --git a/src/duckdb/src/main/capi/duckdb_value-c.cpp b/src/duckdb/src/main/capi/duckdb_value-c.cpp index 911148f3d..7f75691bc 100644 --- a/src/duckdb/src/main/capi/duckdb_value-c.cpp +++ b/src/duckdb/src/main/capi/duckdb_value-c.cpp @@ -537,17 +537,3 @@ duckdb_value duckdb_get_struct_child(duckdb_value value, idx_t index) { return WrapValue(new duckdb::Value(children[index])); } - -char *duckdb_value_to_string(duckdb_value val) { - if (!val) { - return nullptr; - } - - auto v = UnwrapValue(val); - auto str = v.ToSQLString(); - - auto result = reinterpret_cast(malloc(sizeof(char) * (str.size() + 1))); - memcpy(result, str.c_str(), str.size()); - result[str.size()] = '\0'; - return result; -} diff --git a/src/duckdb/src/main/client_context.cpp b/src/duckdb/src/main/client_context.cpp index 474317b33..473178dfe 100644 --- a/src/duckdb/src/main/client_context.cpp +++ b/src/duckdb/src/main/client_context.cpp @@ -138,12 +138,13 @@ struct DebugClientContextState : public ClientContextState { #endif ClientContext::ClientContext(shared_ptr database) - : db(std::move(database)), interrupted(false), transaction(*this), connection_id(DConstants::INVALID_INDEX) { + : db(std::move(database)), interrupted(false), transaction(*this) { registered_state = make_uniq(); #ifdef DEBUG registered_state->GetOrCreate("debug_client_context_state"); #endif LoggingContext context(LogContextScope::CONNECTION); + context.client_context = reinterpret_cast(this); logger = db->GetLogManager().CreateLogger(context, true); client_data = make_uniq(*this); } @@ -214,9 +215,8 @@ void ClientContext::BeginQueryInternal(ClientContextLock &lock, const string &qu // Refresh the logger to ensure we are in sync with global log settings LoggingContext context(LogContextScope::CONNECTION); - context.connection_id = connection_id; - context.transaction_id = transaction.ActiveTransaction().global_transaction_id; - context.query_id = transaction.GetActiveQuery(); + context.client_context = reinterpret_cast(this); + context.transaction_id = transaction.GetActiveQuery(); logger = db->GetLogManager().CreateLogger(context, true); DUCKDB_LOG_INFO(*this, "duckdb.ClientContext.BeginQuery", query); } @@ -260,7 +260,7 @@ ErrorData ClientContext::EndQueryInternal(ClientContextLock &lock, bool success, // Refresh the logger logger->Flush(); LoggingContext context(LogContextScope::CONNECTION); - context.connection_id = reinterpret_cast(this); + context.client_context = reinterpret_cast(this); logger = db->GetLogManager().CreateLogger(context, true); // Notify any registered state of query end @@ -316,10 +316,6 @@ const string &ClientContext::GetCurrentQuery() { return active_query->query; } -connection_t ClientContext::GetConnectionId() const { - return connection_id; -} - unique_ptr ClientContext::FetchResultInternal(ClientContextLock &lock, PendingQueryResult &pending) { D_ASSERT(active_query); D_ASSERT(active_query->IsOpenResult(pending)); @@ -360,48 +356,52 @@ ClientContext::CreatePreparedStatementInternal(ClientContextLock &lock, const st auto &profiler = QueryProfiler::Get(*this); profiler.StartQuery(query, IsExplainAnalyze(statement.get()), true); profiler.StartPhase(MetricsType::PLANNER); - Planner logical_planner(*this); + Planner planner(*this); if (values) { auto ¶meter_values = *values; for (auto &value : parameter_values) { - logical_planner.parameter_data.emplace(value.first, BoundParameterData(value.second)); + planner.parameter_data.emplace(value.first, BoundParameterData(value.second)); } } - logical_planner.CreatePlan(std::move(statement)); - D_ASSERT(logical_planner.plan || !logical_planner.properties.bound_all_parameters); + planner.CreatePlan(std::move(statement)); + D_ASSERT(planner.plan || !planner.properties.bound_all_parameters); profiler.EndPhase(); - auto logical_plan = std::move(logical_planner.plan); + auto plan = std::move(planner.plan); // extract the result column names from the plan - result->properties = logical_planner.properties; - result->names = logical_planner.names; - result->types = logical_planner.types; - result->value_map = std::move(logical_planner.value_map); - if (!logical_planner.properties.bound_all_parameters) { + result->properties = planner.properties; + result->names = planner.names; + result->types = planner.types; + result->value_map = std::move(planner.value_map); + if (!planner.properties.bound_all_parameters) { return result; } #ifdef DEBUG - logical_plan->Verify(*this); + plan->Verify(*this); #endif - if (config.enable_optimizer && logical_plan->RequireOptimizer()) { + if (config.enable_optimizer && plan->RequireOptimizer()) { profiler.StartPhase(MetricsType::ALL_OPTIMIZERS); - Optimizer optimizer(*logical_planner.binder, *this); - logical_plan = optimizer.Optimize(std::move(logical_plan)); - D_ASSERT(logical_plan); + Optimizer optimizer(*planner.binder, *this); + plan = optimizer.Optimize(std::move(plan)); + D_ASSERT(plan); profiler.EndPhase(); #ifdef DEBUG - logical_plan->Verify(*this); + plan->Verify(*this); #endif } - // Convert the logical query plan into a physical query plan. profiler.StartPhase(MetricsType::PHYSICAL_PLANNER); + // now convert logical query plan into a physical query plan PhysicalPlanGenerator physical_planner(*this); - result->physical_plan = physical_planner.Plan(std::move(logical_plan)); + auto physical_plan = physical_planner.CreatePlan(std::move(plan)); profiler.EndPhase(); - D_ASSERT(result->physical_plan); + +#ifdef DEBUG + D_ASSERT(!physical_plan->ToString().empty()); +#endif + result->plan = std::move(physical_plan); return result; } diff --git a/src/duckdb/src/main/config.cpp b/src/duckdb/src/main/config.cpp index 73b5172f7..d48181cd5 100644 --- a/src/duckdb/src/main/config.cpp +++ b/src/duckdb/src/main/config.cpp @@ -72,7 +72,6 @@ static const ConfigurationOption internal_options[] = { DUCKDB_GLOBAL(ArrowLargeBufferSizeSetting), DUCKDB_GLOBAL(ArrowLosslessConversionSetting), DUCKDB_GLOBAL(ArrowOutputListViewSetting), - DUCKDB_LOCAL(AsofLoopJoinThresholdSetting), DUCKDB_GLOBAL(AutoinstallExtensionRepositorySetting), DUCKDB_GLOBAL(AutoinstallKnownExtensionsSetting), DUCKDB_GLOBAL(AutoloadKnownExtensionsSetting), @@ -87,7 +86,6 @@ static const ConfigurationOption internal_options[] = { DUCKDB_LOCAL(DebugForceExternalSetting), DUCKDB_LOCAL(DebugForceNoCrossProductSetting), DUCKDB_GLOBAL(DebugSkipCheckpointOnCommitSetting), - DUCKDB_GLOBAL(DebugVerifyVectorSetting), DUCKDB_GLOBAL(DebugWindowModeSetting), DUCKDB_GLOBAL(DefaultBlockSizeSetting), DUCKDB_GLOBAL_LOCAL(DefaultCollationSetting), @@ -161,7 +159,6 @@ static const ConfigurationOption internal_options[] = { DUCKDB_LOCAL(ProfilingModeSetting), DUCKDB_LOCAL(ProgressBarTimeSetting), DUCKDB_LOCAL(ScalarSubqueryErrorOnMultipleRowsSetting), - DUCKDB_GLOBAL(SchedulerProcessPartialSetting), DUCKDB_LOCAL(SchemaSetting), DUCKDB_LOCAL(SearchPathSetting), DUCKDB_GLOBAL(SecretDirectorySetting), diff --git a/src/duckdb/src/main/connection.cpp b/src/duckdb/src/main/connection.cpp index ac984d134..a5742dbfd 100644 --- a/src/duckdb/src/main/connection.cpp +++ b/src/duckdb/src/main/connection.cpp @@ -20,10 +20,7 @@ namespace duckdb { Connection::Connection(DatabaseInstance &database) : context(make_shared_ptr(database.shared_from_this())), warning_cb(nullptr) { - auto &connection_manager = ConnectionManager::Get(database); - connection_manager.AddConnection(*context); - connection_manager.AssignConnectionId(*this); - + ConnectionManager::Get(database).AddConnection(*context); #ifdef DEBUG EnableProfiling(); context->config.emit_profiler_output = false; @@ -37,13 +34,11 @@ Connection::Connection(DuckDB &database) : Connection(*database.instance) { Connection::Connection(Connection &&other) noexcept : warning_cb(nullptr) { std::swap(context, other.context); std::swap(warning_cb, other.warning_cb); - std::swap(connection_id, other.connection_id); } Connection &Connection::operator=(Connection &&other) noexcept { std::swap(context, other.context); std::swap(warning_cb, other.warning_cb); - std::swap(connection_id, other.connection_id); return *this; } @@ -209,28 +204,7 @@ shared_ptr Connection::Table(const string &table_name) { shared_ptr Connection::Table(const string &schema_name, const string &table_name) { auto table_info = TableInfo(INVALID_CATALOG, schema_name, table_name); if (!table_info) { - throw CatalogException("Table %s does not exist!", ParseInfo::QualifierToString("", schema_name, table_name)); - } - return make_shared_ptr(context, std::move(table_info)); -} - -shared_ptr Connection::Table(const string &catalog_name, const string &schema_name, - const string &table_name) { - unique_ptr table_info; - do { - table_info = TableInfo(catalog_name, schema_name, table_name); - if (table_info) { - break; - } - - if (catalog_name.empty() && !schema_name.empty()) { - table_info = TableInfo(schema_name, DEFAULT_SCHEMA, table_name); - } - } while (false); - - if (!table_info) { - throw CatalogException("Table %s does not exist!", - ParseInfo::QualifierToString(catalog_name, schema_name, table_name)); + throw CatalogException("Table '%s' does not exist!", table_name); } return make_shared_ptr(context, std::move(table_info)); } diff --git a/src/duckdb/src/main/connection_manager.cpp b/src/duckdb/src/main/connection_manager.cpp index 436c89eff..39762cf43 100644 --- a/src/duckdb/src/main/connection_manager.cpp +++ b/src/duckdb/src/main/connection_manager.cpp @@ -1,12 +1,11 @@ #include "duckdb/main/connection_manager.hpp" #include "duckdb/common/exception/transaction_exception.hpp" -#include "duckdb/main/connection.hpp" #include "duckdb/main/config.hpp" #include "duckdb/planner/extension_callback.hpp" namespace duckdb { -ConnectionManager::ConnectionManager() : connection_count(0), current_connection_id(0) { +ConnectionManager::ConnectionManager() : connection_count(0) { } void ConnectionManager::AddConnection(ClientContext &context) { @@ -31,10 +30,6 @@ idx_t ConnectionManager::GetConnectionCount() const { return connection_count; } -void ConnectionManager::AssignConnectionId(Connection &connection) { - connection.context->connection_id = current_connection_id.fetch_add(1, std::memory_order_relaxed) + 1; -} - vector> ConnectionManager::GetConnectionList() { lock_guard lock(connections_lock); vector> result; diff --git a/src/duckdb/src/main/database.cpp b/src/duckdb/src/main/database.cpp index 26a84ed40..f51caaaee 100644 --- a/src/duckdb/src/main/database.cpp +++ b/src/duckdb/src/main/database.cpp @@ -201,14 +201,16 @@ void DatabaseInstance::CreateMainDatabase() { info.path = config.options.database_path; optional_ptr initial_database; - Connection con(*this); - con.BeginTransaction(); - AttachOptions options(config.options); - initial_database = db_manager->AttachDatabase(*con.context, info, options); + { + Connection con(*this); + con.BeginTransaction(); + AttachOptions options(config.options); + initial_database = db_manager->AttachDatabase(*con.context, info, options); + con.Commit(); + } initial_database->SetInitialDatabase(); - initial_database->Initialize(*con.context); - con.Commit(); + initial_database->Initialize(); } static void ThrowExtensionSetUnrecognizedOptions(const case_insensitive_map_t &unrecognized_options) { diff --git a/src/duckdb/src/main/database_manager.cpp b/src/duckdb/src/main/database_manager.cpp index 4ab3d55b3..8b836ebfa 100644 --- a/src/duckdb/src/main/database_manager.cpp +++ b/src/duckdb/src/main/database_manager.cpp @@ -11,8 +11,7 @@ namespace duckdb { -DatabaseManager::DatabaseManager(DatabaseInstance &db) - : next_oid(0), current_query_number(1), current_transaction_id(0) { +DatabaseManager::DatabaseManager(DatabaseInstance &db) : next_oid(0), current_query_number(1) { system = make_uniq(db); databases = make_uniq(system->GetCatalog()); } @@ -60,9 +59,6 @@ optional_ptr DatabaseManager::AttachDatabase(ClientContext &co } // and add it to the databases catalog set - if (info.on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { - DetachDatabase(context, name, OnEntryNotFound::RETURN_NULL); - } if (!databases->CreateEntry(context, name, std::move(attached_db), dependencies)) { throw BinderException("Failed to attach database: database with name \"%s\" already exists", name); } diff --git a/src/duckdb/src/main/extension/extension_helper.cpp b/src/duckdb/src/main/extension/extension_helper.cpp index 72fdf4766..cbf2cae8b 100644 --- a/src/duckdb/src/main/extension/extension_helper.cpp +++ b/src/duckdb/src/main/extension/extension_helper.cpp @@ -115,6 +115,7 @@ static const DefaultExtension internal_extensions[] = { {"inet", "Adds support for IP-related data types and functions", false}, {"spatial", "Geospatial extension that adds support for working with spatial data and functions", false}, {"aws", "Provides features that depend on the AWS SDK", false}, + {"arrow", "A zero-copy data integration between Apache Arrow and DuckDB", false}, {"azure", "Adds a filesystem abstraction for Azure blob storage to DuckDB", false}, {"iceberg", "Adds support for Apache Iceberg", false}, {"vss", "Adds indexing support to accelerate Vector Similarity Search", false}, diff --git a/src/duckdb/src/main/extension/extension_install.cpp b/src/duckdb/src/main/extension/extension_install.cpp index 601adaea1..477cb6fff 100644 --- a/src/duckdb/src/main/extension/extension_install.cpp +++ b/src/duckdb/src/main/extension/extension_install.cpp @@ -59,7 +59,7 @@ const vector ExtensionHelper::PathComponents() { string ExtensionHelper::ExtensionInstallDocumentationLink(const string &extension_name) { auto components = PathComponents(); - string link = "https://duckdb.org/docs/stable/extensions/troubleshooting"; + string link = "https://duckdb.org/docs/extensions/troubleshooting"; if (components.size() >= 2) { link += "/?version=" + components[0] + "&platform=" + components[1] + "&extension=" + extension_name; @@ -318,8 +318,7 @@ static unique_ptr DirectInstallExtension(DatabaseInstance // Throw error on failure if (!exists) { if (!fs.IsRemoteFile(file)) { - throw IOException("Failed to install local extension \"%s\", no access to the file at PATH \"%s\"\n", - extension_name, file); + throw IOException("Failed to copy local extension \"%s\" at PATH \"%s\"\n", extension_name, file); } if (StringUtil::StartsWith(file, "https://")) { throw IOException("Failed to install remote extension \"%s\" from url \"%s\"", extension_name, file); diff --git a/src/duckdb/src/main/prepared_statement_data.cpp b/src/duckdb/src/main/prepared_statement_data.cpp index 63069ceb1..c4cec4c55 100644 --- a/src/duckdb/src/main/prepared_statement_data.cpp +++ b/src/duckdb/src/main/prepared_statement_data.cpp @@ -1,4 +1,5 @@ #include "duckdb/main/prepared_statement_data.hpp" +#include "duckdb/execution/physical_operator.hpp" #include "duckdb/parser/sql_statement.hpp" #include "duckdb/catalog/catalog.hpp" #include "duckdb/common/exception/binder_exception.hpp" diff --git a/src/duckdb/src/main/profiling_info.cpp b/src/duckdb/src/main/profiling_info.cpp index f2b67df8a..4ce68b76d 100644 --- a/src/duckdb/src/main/profiling_info.cpp +++ b/src/duckdb/src/main/profiling_info.cpp @@ -98,7 +98,7 @@ void ProfilingInfo::ResetMetrics() { case MetricsType::EXTRA_INFO: break; default: - throw InternalException("MetricsType" + EnumUtil::ToString(metric) + "not implemented"); + throw Exception(ExceptionType::INTERNAL, "MetricsType" + EnumUtil::ToString(metric) + "not implemented"); } } } diff --git a/src/duckdb/src/main/query_profiler.cpp b/src/duckdb/src/main/query_profiler.cpp index 93edf2a99..03889af52 100644 --- a/src/duckdb/src/main/query_profiler.cpp +++ b/src/duckdb/src/main/query_profiler.cpp @@ -143,7 +143,6 @@ bool QueryProfiler::OperatorRequiresProfiling(PhysicalOperatorType op_type) { case PhysicalOperatorType::RIGHT_DELIM_JOIN: case PhysicalOperatorType::UNION: case PhysicalOperatorType::RECURSIVE_CTE: - case PhysicalOperatorType::RECURSIVE_KEY_CTE: case PhysicalOperatorType::EMPTY_RESULT: case PhysicalOperatorType::EXTENSION: return true; @@ -375,12 +374,9 @@ void OperatorProfiler::StartOperator(optional_ptr phys_o if (!settings.empty()) { if (ProfilingInfo::Enabled(settings, MetricsType::EXTRA_INFO)) { - if (!OperatorInfoIsInitialized(*active_operator)) { - // first time calling into this operator - fetch the info - auto &info = GetOperatorInfo(*active_operator); - auto params = active_operator->ParamsToString(); - info.extra_info = params; - } + auto &info = GetOperatorInfo(*active_operator); + auto params = active_operator->ParamsToString(); + info.extra_info = params; } // Start the timing of the current operator. @@ -395,7 +391,7 @@ void OperatorProfiler::EndOperator(optional_ptr chunk) { return; } if (!active_operator) { - throw InternalException("OperatorProfiler: Attempting to call EndOperator while no operator is active"); + throw InternalException("OperatorProfiler: Attempting to call EndOperator while another operator is active"); } if (!settings.empty()) { @@ -415,37 +411,6 @@ void OperatorProfiler::EndOperator(optional_ptr chunk) { active_operator = nullptr; } -void OperatorProfiler::FinishSource(GlobalSourceState &gstate, LocalSourceState &lstate) { - if (!enabled) { - return; - } - if (!active_operator) { - throw InternalException("OperatorProfiler: Attempting to call FinishSource while no operator is active"); - } - if (!settings.empty()) { - if (ProfilingInfo::Enabled(settings, MetricsType::EXTRA_INFO)) { - // we're emitting extra info - get the extra source info - auto &info = GetOperatorInfo(*active_operator); - auto extra_info = active_operator->ExtraSourceParams(gstate, lstate); - for (auto &new_info : extra_info) { - auto entry = info.extra_info.find(new_info.first); - if (entry != info.extra_info.end()) { - // entry exists - override - entry->second = std::move(new_info.second); - } else { - // entry does not exist yet - insert - info.extra_info.insert(std::move(new_info)); - } - } - } - } -} - -bool OperatorProfiler::OperatorInfoIsInitialized(const PhysicalOperator &phys_op) { - auto entry = operator_infos.find(phys_op); - return entry != operator_infos.end(); -} - OperatorInformation &OperatorProfiler::GetOperatorInfo(const PhysicalOperator &phys_op) { auto entry = operator_infos.find(phys_op); if (entry != operator_infos.end()) { diff --git a/src/duckdb/src/main/relation/delete_relation.cpp b/src/duckdb/src/main/relation/delete_relation.cpp index 64b3f231e..bbc0d58ef 100644 --- a/src/duckdb/src/main/relation/delete_relation.cpp +++ b/src/duckdb/src/main/relation/delete_relation.cpp @@ -7,16 +7,14 @@ namespace duckdb { DeleteRelation::DeleteRelation(shared_ptr &context, unique_ptr condition_p, - string catalog_name_p, string schema_name_p, string table_name_p) + string schema_name_p, string table_name_p) : Relation(context, RelationType::DELETE_RELATION), condition(std::move(condition_p)), - catalog_name(std::move(catalog_name_p)), schema_name(std::move(schema_name_p)), - table_name(std::move(table_name_p)) { + schema_name(std::move(schema_name_p)), table_name(std::move(table_name_p)) { TryBindRelation(columns); } BoundStatement DeleteRelation::Bind(Binder &binder) { auto basetable = make_uniq(); - basetable->catalog_name = catalog_name; basetable->schema_name = schema_name; basetable->table_name = table_name; @@ -31,8 +29,7 @@ const vector &DeleteRelation::Columns() { } string DeleteRelation::ToString(idx_t depth) { - string str = - RenderWhitespace(depth) + "DELETE FROM " + ParseInfo::QualifierToString(catalog_name, schema_name, table_name); + string str = RenderWhitespace(depth) + "DELETE FROM " + table_name; if (condition) { str += " WHERE " + condition->ToString(); } diff --git a/src/duckdb/src/main/relation/read_csv_relation.cpp b/src/duckdb/src/main/relation/read_csv_relation.cpp index b0c24e8e3..4720a8e52 100644 --- a/src/duckdb/src/main/relation/read_csv_relation.cpp +++ b/src/duckdb/src/main/relation/read_csv_relation.cpp @@ -8,15 +8,12 @@ #include "duckdb/parser/expression/function_expression.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/execution/operator/csv_scanner/csv_reader_options.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/parser/expression/star_expression.hpp" #include "duckdb/parser/query_node/select_node.hpp" #include "duckdb/parser/tableref/basetableref.hpp" #include "duckdb/parser/tableref/table_function_ref.hpp" #include "duckdb/function/table/read_csv.hpp" -#include "duckdb/common/multi_file/multi_file_function.hpp" -#include "duckdb/execution/operator/csv_scanner/csv_multi_file_info.hpp" - namespace duckdb { void ReadCSVRelation::InitializeAlias(const vector &input) { @@ -25,34 +22,42 @@ void ReadCSVRelation::InitializeAlias(const vector &input) { alias = StringUtil::Split(csv_file, ".")[0]; } -CSVReaderOptions ReadCSVRelationBind(const shared_ptr &context, const vector &input, - named_parameter_map_t &options, vector &columns, - MultiFileOptions &file_options) { +ReadCSVRelation::ReadCSVRelation(const shared_ptr &context, const vector &input, + named_parameter_map_t &&options, string alias_p) + : TableFunctionRelation(context, "read_csv_auto", {MultiFileReader::CreateValueFromFileList(input)}, nullptr, + false), + alias(std::move(alias_p)) { + + InitializeAlias(input); + auto file_list = MultiFileReader::CreateValueFromFileList(input); auto multi_file_reader = MultiFileReader::CreateDefault("ReadCSVRelation"); vector files; - files = multi_file_reader->CreateFileList(*context, file_list)->GetAllFiles(); - + context->RunFunctionInTransaction( + [&]() { files = multi_file_reader->CreateFileList(*context, file_list)->GetAllFiles(); }); D_ASSERT(!files.empty()); auto &file_name = files[0]; CSVReaderOptions csv_options; csv_options.file_path = file_name; vector empty; - csv_options.FromNamedParameters(options, *context, file_options); + csv_options.FromNamedParameters(options, *context); // Run the auto-detect, populating the options with the detected settings - if (file_options.union_by_name) { + if (csv_options.file_options.union_by_name) { SimpleMultiFileList multi_file_list(files); vector types; vector names; - auto result = make_uniq(); - auto csv_data = make_uniq(); + auto result = make_uniq(); - multi_file_reader->BindUnionReader(*context, types, names, multi_file_list, *result, - csv_options, file_options); + multi_file_reader->BindUnionReader(*context, types, names, multi_file_list, *result, csv_options); + if (result->union_readers.size() > 1) { + for (idx_t i = 0; i < result->union_readers.size(); i++) { + result->column_info.emplace_back(result->union_readers[i]->names, result->union_readers[i]->types); + } + } if (!csv_options.sql_types_per_column.empty()) { const auto exception = CSVError::ColumnTypesError(csv_options.sql_types_per_column, names); if (!exception.error_message.empty()) { @@ -72,14 +77,16 @@ CSVReaderOptions ReadCSVRelationBind(const shared_ptr &context, c } else { if (csv_options.auto_detect) { shared_ptr buffer_manager; - buffer_manager = make_shared_ptr(*context, csv_options, files[0], 0); - CSVSniffer sniffer(csv_options, file_options, buffer_manager, CSVStateMachineCache::Get(*context)); - auto sniffer_result = sniffer.SniffCSV(); - auto &types = sniffer_result.return_types; - auto &names = sniffer_result.names; - for (idx_t i = 0; i < types.size(); i++) { - columns.emplace_back(names[i], types[i]); - } + context->RunFunctionInTransaction([&]() { + buffer_manager = make_shared_ptr(*context, csv_options, files[0], 0); + CSVSniffer sniffer(csv_options, buffer_manager, CSVStateMachineCache::Get(*context)); + auto sniffer_result = sniffer.SniffCSV(); + auto &types = sniffer_result.return_types; + auto &names = sniffer_result.names; + for (idx_t i = 0; i < types.size(); i++) { + columns.emplace_back(names[i], types[i]); + } + }); } else { for (idx_t i = 0; i < csv_options.sql_type_list.size(); i++) { D_ASSERT(csv_options.name_list.size() == csv_options.sql_type_list.size()); @@ -94,20 +101,6 @@ CSVReaderOptions ReadCSVRelationBind(const shared_ptr &context, c csv_options.dialect_options.header.ChangeSetByUserTrue(); csv_options.dialect_options.skip_rows.ChangeSetByUserTrue(); } - return csv_options; -} - -ReadCSVRelation::ReadCSVRelation(const shared_ptr &context, const vector &input, - named_parameter_map_t &&options, string alias_p) - : TableFunctionRelation(context, "read_csv_auto", {MultiFileReader::CreateValueFromFileList(input)}, nullptr, - false), - alias(std::move(alias_p)) { - MultiFileOptions file_options; - - InitializeAlias(input); - CSVReaderOptions csv_options; - context->RunFunctionInTransaction( - [&]() { csv_options = ReadCSVRelationBind(context, input, options, columns, file_options); }); // Capture the options potentially set/altered by the auto-detection phase csv_options.ToNamedParameters(options); @@ -121,7 +114,7 @@ ReadCSVRelation::ReadCSVRelation(const shared_ptr &context, const column_names.push_back(make_pair(columns[i].Name(), Value(columns[i].Type().ToString()))); } - if (!file_options.union_by_name) { + if (!csv_options.file_options.union_by_name) { AddNamedParameter("columns", Value::STRUCT(std::move(column_names))); } RemoveNamedParameterIfExists("names"); diff --git a/src/duckdb/src/main/relation/read_json_relation.cpp b/src/duckdb/src/main/relation/read_json_relation.cpp index 2f849597d..6d80369d3 100644 --- a/src/duckdb/src/main/relation/read_json_relation.cpp +++ b/src/duckdb/src/main/relation/read_json_relation.cpp @@ -1,6 +1,6 @@ #include "duckdb/main/relation/read_json_relation.hpp" #include "duckdb/parser/column_definition.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader.hpp" namespace duckdb { diff --git a/src/duckdb/src/main/relation/table_relation.cpp b/src/duckdb/src/main/relation/table_relation.cpp index c82ace698..1b790a698 100644 --- a/src/duckdb/src/main/relation/table_relation.cpp +++ b/src/duckdb/src/main/relation/table_relation.cpp @@ -29,7 +29,6 @@ unique_ptr TableRelation::GetTableRef() { auto table_ref = make_uniq(); table_ref->schema_name = description->schema; table_ref->table_name = description->table; - table_ref->catalog_name = description->database; return std::move(table_ref); } @@ -42,8 +41,7 @@ const vector &TableRelation::Columns() { } string TableRelation::ToString(idx_t depth) { - return RenderWhitespace(depth) + "Scan Table [" + - ParseInfo::QualifierToString(description->database, description->schema, description->table) + "]"; + return RenderWhitespace(depth) + "Scan Table [" + description->table + "]"; } static unique_ptr ParseCondition(ClientContext &context, const string &condition) { @@ -64,8 +62,8 @@ void TableRelation::Update(vector names, vector> expressions = std::move(update); auto update_relation = - make_shared_ptr(context, std::move(condition), description->database, description->schema, - description->table, std::move(update_columns), std::move(expressions)); + make_shared_ptr(context, std::move(condition), description->schema, description->table, + std::move(update_columns), std::move(expressions)); update_relation->Execute(); } @@ -74,16 +72,14 @@ void TableRelation::Update(const string &update_list, const string &condition) { vector> expressions; auto cond = ParseCondition(*context->GetContext(), condition); Parser::ParseUpdateList(update_list, update_columns, expressions, context->GetContext()->GetParserOptions()); - auto update = - make_shared_ptr(context, std::move(cond), description->database, description->schema, - description->table, std::move(update_columns), std::move(expressions)); + auto update = make_shared_ptr(context, std::move(cond), description->schema, description->table, + std::move(update_columns), std::move(expressions)); update->Execute(); } void TableRelation::Delete(const string &condition) { auto cond = ParseCondition(*context->GetContext(), condition); - auto del = make_shared_ptr(context, std::move(cond), description->database, description->schema, - description->table); + auto del = make_shared_ptr(context, std::move(cond), description->schema, description->table); del->Execute(); } diff --git a/src/duckdb/src/main/relation/update_relation.cpp b/src/duckdb/src/main/relation/update_relation.cpp index 9176cf2f2..6dd34dfc5 100644 --- a/src/duckdb/src/main/relation/update_relation.cpp +++ b/src/duckdb/src/main/relation/update_relation.cpp @@ -7,19 +7,17 @@ namespace duckdb { UpdateRelation::UpdateRelation(shared_ptr &context, unique_ptr condition_p, - string catalog_name_p, string schema_name_p, string table_name_p, - vector update_columns_p, vector> expressions_p) + string schema_name_p, string table_name_p, vector update_columns_p, + vector> expressions_p) : Relation(context, RelationType::UPDATE_RELATION), condition(std::move(condition_p)), - catalog_name(std::move(catalog_name_p)), schema_name(std::move(schema_name_p)), - table_name(std::move(table_name_p)), update_columns(std::move(update_columns_p)), - expressions(std::move(expressions_p)) { + schema_name(std::move(schema_name_p)), table_name(std::move(table_name_p)), + update_columns(std::move(update_columns_p)), expressions(std::move(expressions_p)) { D_ASSERT(update_columns.size() == expressions.size()); TryBindRelation(columns); } BoundStatement UpdateRelation::Bind(Binder &binder) { auto basetable = make_uniq(); - basetable->catalog_name = catalog_name; basetable->schema_name = schema_name; basetable->table_name = table_name; @@ -40,8 +38,7 @@ const vector &UpdateRelation::Columns() { } string UpdateRelation::ToString(idx_t depth) { - string str = RenderWhitespace(depth) + "UPDATE " + - ParseInfo::QualifierToString(catalog_name, schema_name, table_name) + " SET\n"; + string str = RenderWhitespace(depth) + "UPDATE " + table_name + " SET\n"; for (idx_t i = 0; i < expressions.size(); i++) { str += update_columns[i] + " = " + expressions[i]->ToString() + "\n"; } diff --git a/src/duckdb/src/main/secret/secret_manager.cpp b/src/duckdb/src/main/secret/secret_manager.cpp index 67246be18..d49d56030 100644 --- a/src/duckdb/src/main/secret/secret_manager.cpp +++ b/src/duckdb/src/main/secret/secret_manager.cpp @@ -225,13 +225,13 @@ optional_ptr SecretManager::LookupFunctionInternal(const s return nullptr; } -unique_ptr SecretManager::CreateSecret(ClientContext &context, const CreateSecretInput &input) { +unique_ptr SecretManager::CreateSecret(ClientContext &context, const CreateSecretInfo &info) { // Note that a context is required for CreateSecret, as the CreateSecretFunction expects one auto transaction = CatalogTransaction::GetSystemCatalogTransaction(context); InitializeSecrets(transaction); // Make a copy to set the provider to default if necessary - auto function_input = input; + CreateSecretInput function_input {info.type, info.provider, info.storage_type, info.name, info.scope, info.options}; if (function_input.provider.empty()) { auto secret_type = LookupTypeInternal(function_input.type); function_input.provider = secret_type.default_provider; @@ -240,7 +240,7 @@ unique_ptr SecretManager::CreateSecret(ClientContext &context, cons // Lookup function auto function_lookup = LookupFunctionInternal(function_input.type, function_input.provider); if (!function_lookup) { - ThrowProviderNotFoundError(input.type, input.provider); + ThrowProviderNotFoundError(info.type, info.provider); } // Call the function @@ -248,15 +248,15 @@ unique_ptr SecretManager::CreateSecret(ClientContext &context, cons if (!secret) { throw InternalException("CreateSecretFunction for type: '%s' and provider: '%s' did not return a secret!", - input.type, input.provider); + info.type, info.provider); } // Register the secret at the secret_manager - return RegisterSecretInternal(transaction, std::move(secret), input.on_conflict, input.persist_type, - input.storage_type); + return RegisterSecretInternal(transaction, std::move(secret), info.on_conflict, info.persist_type, + info.storage_type); } -BoundStatement SecretManager::BindCreateSecret(CatalogTransaction transaction, CreateSecretInput &info) { +BoundStatement SecretManager::BindCreateSecret(CatalogTransaction transaction, CreateSecretInfo &info) { InitializeSecrets(transaction); auto type = info.type; diff --git a/src/duckdb/src/main/settings/autogenerated_settings.cpp b/src/duckdb/src/main/settings/autogenerated_settings.cpp index 6c462f57b..d007da71f 100644 --- a/src/duckdb/src/main/settings/autogenerated_settings.cpp +++ b/src/duckdb/src/main/settings/autogenerated_settings.cpp @@ -177,23 +177,6 @@ Value ArrowOutputListViewSetting::GetSetting(const ClientContext &context) { return Value::BOOLEAN(config.options.arrow_use_list_view); } -//===----------------------------------------------------------------------===// -// Asof Loop Join Threshold -//===----------------------------------------------------------------------===// -void AsofLoopJoinThresholdSetting::SetLocal(ClientContext &context, const Value &input) { - auto &config = ClientConfig::GetConfig(context); - config.asof_loop_join_threshold = input.GetValue(); -} - -void AsofLoopJoinThresholdSetting::ResetLocal(ClientContext &context) { - ClientConfig::GetConfig(context).asof_loop_join_threshold = ClientConfig().asof_loop_join_threshold; -} - -Value AsofLoopJoinThresholdSetting::GetSetting(const ClientContext &context) { - auto &config = ClientConfig::GetConfig(context); - return Value::UBIGINT(config.asof_loop_join_threshold); -} - //===----------------------------------------------------------------------===// // Autoinstall Extension Repository //===----------------------------------------------------------------------===// @@ -373,23 +356,6 @@ Value DebugSkipCheckpointOnCommitSetting::GetSetting(const ClientContext &contex return Value::BOOLEAN(config.options.debug_skip_checkpoint_on_commit); } -//===----------------------------------------------------------------------===// -// Debug Verify Vector -//===----------------------------------------------------------------------===// -void DebugVerifyVectorSetting::SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &input) { - auto str_input = StringUtil::Upper(input.GetValue()); - config.options.debug_verify_vector = EnumUtil::FromString(str_input); -} - -void DebugVerifyVectorSetting::ResetGlobal(DatabaseInstance *db, DBConfig &config) { - config.options.debug_verify_vector = DBConfig().options.debug_verify_vector; -} - -Value DebugVerifyVectorSetting::GetSetting(const ClientContext &context) { - auto &config = DBConfig::GetConfig(context); - return Value(StringUtil::Lower(EnumUtil::ToString(config.options.debug_verify_vector))); -} - //===----------------------------------------------------------------------===// // Debug Window Mode //===----------------------------------------------------------------------===// @@ -1117,22 +1083,6 @@ Value ScalarSubqueryErrorOnMultipleRowsSetting::GetSetting(const ClientContext & return Value::BOOLEAN(config.scalar_subquery_error_on_multiple_rows); } -//===----------------------------------------------------------------------===// -// Scheduler Process Partial -//===----------------------------------------------------------------------===// -void SchedulerProcessPartialSetting::SetGlobal(DatabaseInstance *db, DBConfig &config, const Value &input) { - config.options.scheduler_process_partial = input.GetValue(); -} - -void SchedulerProcessPartialSetting::ResetGlobal(DatabaseInstance *db, DBConfig &config) { - config.options.scheduler_process_partial = DBConfig().options.scheduler_process_partial; -} - -Value SchedulerProcessPartialSetting::GetSetting(const ClientContext &context) { - auto &config = DBConfig::GetConfig(context); - return Value::BOOLEAN(config.options.scheduler_process_partial); -} - //===----------------------------------------------------------------------===// // Zstd Min String Length //===----------------------------------------------------------------------===// diff --git a/src/duckdb/src/main/settings/custom_settings.cpp b/src/duckdb/src/main/settings/custom_settings.cpp index 177266472..4471021b4 100644 --- a/src/duckdb/src/main/settings/custom_settings.cpp +++ b/src/duckdb/src/main/settings/custom_settings.cpp @@ -332,7 +332,7 @@ void CustomProfilingSettingsSetting::SetLocal(ClientContext &context, const Valu // parse the file content unordered_map json; try { - json = StringUtil::ParseJSONMap(input.ToString())->Flatten(); + json = StringUtil::ParseJSONMap(input.ToString()); } catch (std::exception &ex) { throw IOException("Could not parse the custom profiler settings file due to incorrect JSON: \"%s\". Make sure " "all the keys and values start with a quote. ", diff --git a/src/duckdb/src/optimizer/build_probe_side_optimizer.cpp b/src/duckdb/src/optimizer/build_probe_side_optimizer.cpp index a71c94c64..384760594 100644 --- a/src/duckdb/src/optimizer/build_probe_side_optimizer.cpp +++ b/src/duckdb/src/optimizer/build_probe_side_optimizer.cpp @@ -3,7 +3,6 @@ #include "duckdb/common/enums/join_type.hpp" #include "duckdb/common/type_visitor.hpp" #include "duckdb/common/types/row/tuple_data_layout.hpp" -#include "duckdb/execution/ht_entry.hpp" #include "duckdb/planner/operator/logical_any_join.hpp" #include "duckdb/planner/operator/logical_comparison_join.hpp" #include "duckdb/planner/operator/logical_get.hpp" @@ -138,9 +137,9 @@ double BuildProbeSideOptimizer::GetBuildSize(vector types, const id }); } - // There is also a cost of NextPowerOfTwo(count * 2) * sizeof(ht_entry_t) per tuple in the hash table - // This is a not a smooth cost function, so instead we do the average, which is ~3 * sizeof(ht_entry_t) - row_width += 3 * sizeof(ht_entry_t); + // There is also a cost of NextPowerOfTwo(count * 2) * sizeof(data_ptr_t) per tuple in the hash table + // This is a not a smooth cost function, so instead we do the average, which is ~3 * sizeof(data_ptr_t) + row_width += 3 * sizeof(data_ptr_t); return static_cast(row_width * cardinality); } diff --git a/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp b/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp index cc34d2d53..ce49c6a9e 100644 --- a/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp +++ b/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp @@ -112,7 +112,6 @@ void ColumnLifetimeAnalyzer::VisitOperator(LogicalOperator &op) { case LogicalOperatorType::LOGICAL_UNION: case LogicalOperatorType::LOGICAL_EXCEPT: case LogicalOperatorType::LOGICAL_INTERSECT: - case LogicalOperatorType::LOGICAL_RECURSIVE_CTE: case LogicalOperatorType::LOGICAL_MATERIALIZED_CTE: { // for set operations/materialized CTEs we don't remove anything, just recursively visit the children // FIXME: for UNION we can remove unreferenced columns as long as everything_referenced is false (i.e. we diff --git a/src/duckdb/src/optimizer/compressed_materialization.cpp b/src/duckdb/src/optimizer/compressed_materialization.cpp index 0245110b5..5e6c30760 100644 --- a/src/duckdb/src/optimizer/compressed_materialization.cpp +++ b/src/duckdb/src/optimizer/compressed_materialization.cpp @@ -329,9 +329,6 @@ unique_ptr CompressedMaterialization::GetCompressExpression( static Value GetIntegralRangeValue(ClientContext &context, const LogicalType &type, const BaseStatistics &stats) { auto min = NumericStats::Min(stats); auto max = NumericStats::Max(stats); - if (max < min) { - return Value::HUGEINT(NumericLimits::Maximum()); - } vector> arguments; arguments.emplace_back(make_uniq(max)); diff --git a/src/duckdb/src/optimizer/cse_optimizer.cpp b/src/duckdb/src/optimizer/cse_optimizer.cpp index 096cd85eb..cde7aeb4c 100644 --- a/src/duckdb/src/optimizer/cse_optimizer.cpp +++ b/src/duckdb/src/optimizer/cse_optimizer.cpp @@ -2,6 +2,7 @@ #include "duckdb/planner/expression/bound_columnref_expression.hpp" #include "duckdb/planner/expression_iterator.hpp" +#include "duckdb/planner/operator/logical_filter.hpp" #include "duckdb/planner/operator/logical_projection.hpp" #include "duckdb/planner/column_binding_map.hpp" #include "duckdb/planner/binder.hpp" @@ -30,8 +31,6 @@ struct CSEReplacementState { vector> expressions; //! Cached expressions that are kept around so the expression_map always contains valid expressions vector> cached_expressions; - //! Short circuit argument tracking - bool short_circuited = false; }; void CommonSubExpressionOptimizer::VisitOperator(LogicalOperator &op) { @@ -52,6 +51,9 @@ void CommonSubExpressionOptimizer::CountExpressions(Expression &expr, CSEReplace case ExpressionClass::BOUND_COLUMN_REF: case ExpressionClass::BOUND_CONSTANT: case ExpressionClass::BOUND_PARAMETER: + // skip conjunctions and case, since short-circuiting might be incorrectly disabled otherwise + case ExpressionClass::BOUND_CONJUNCTION: + case ExpressionClass::BOUND_CASE: return; default: break; @@ -61,35 +63,14 @@ void CommonSubExpressionOptimizer::CountExpressions(Expression &expr, CSEReplace auto node = state.expression_count.find(expr); if (node == state.expression_count.end()) { // first time we encounter this expression, insert this node with [count = 1] - // but only if it is not an interior argument of a short circuit sensitive expression. - if (!state.short_circuited) { - state.expression_count[expr] = CSENode(); - } + state.expression_count[expr] = CSENode(); } else { // we encountered this expression before, increment the occurrence count node->second.count++; } } - - // If we have a function that uses short circuiting, then we can only extract CSEs from the leftmost - // side of the argument tree (child_no == 0) - switch (expr.GetExpressionClass()) { - case ExpressionClass::BOUND_CONJUNCTION: - case ExpressionClass::BOUND_CASE: { - // Save the short circuit reference - const auto save_short_circuit = state.short_circuited; - ExpressionIterator::EnumerateChildren(expr, [&](Expression &child) { - CountExpressions(child, state); - state.short_circuited = true; - }); - state.short_circuited = save_short_circuit; - break; - } - default: - // recursively count the children - ExpressionIterator::EnumerateChildren(expr, [&](Expression &child) { CountExpressions(child, state); }); - break; - } + // recursively count the children + ExpressionIterator::EnumerateChildren(expr, [&](Expression &child) { CountExpressions(child, state); }); } void CommonSubExpressionOptimizer::PerformCSEReplacement(unique_ptr &expr_ptr, CSEReplacementState &state) { @@ -112,7 +93,9 @@ void CommonSubExpressionOptimizer::PerformCSEReplacement(unique_ptr return; } // check if this child is eligible for CSE elimination - if (state.expression_count.find(expr) != state.expression_count.end()) { + bool can_cse = expr.GetExpressionClass() != ExpressionClass::BOUND_CONJUNCTION && + expr.GetExpressionClass() != ExpressionClass::BOUND_CASE; + if (can_cse && state.expression_count.find(expr) != state.expression_count.end()) { auto &node = state.expression_count[expr]; if (node.count > 1) { // this expression occurs more than once! push it into the projection diff --git a/src/duckdb/src/optimizer/expression_heuristics.cpp b/src/duckdb/src/optimizer/expression_heuristics.cpp index 766ac8d88..e6103b6d3 100644 --- a/src/duckdb/src/optimizer/expression_heuristics.cpp +++ b/src/duckdb/src/optimizer/expression_heuristics.cpp @@ -1,9 +1,6 @@ #include "duckdb/optimizer/expression_heuristics.hpp" #include "duckdb/planner/expression/list.hpp" -#include "duckdb/planner/filter/conjunction_filter.hpp" -#include "duckdb/planner/filter/constant_filter.hpp" -#include "duckdb/planner/filter/struct_filter.hpp" namespace duckdb { @@ -32,6 +29,7 @@ unique_ptr ExpressionHeuristics::VisitReplace(BoundConjunctionExpres } void ExpressionHeuristics::ReorderExpressions(vector> &expressions) { + struct ExpressionCosts { unique_ptr expr; idx_t cost; @@ -114,13 +112,6 @@ idx_t ExpressionHeuristics::ExpressionCost(BoundConjunctionExpression &expr) { } idx_t ExpressionHeuristics::ExpressionCost(BoundFunctionExpression &expr) { - unordered_map function_costs = { - {"+", 5}, {"-", 5}, {"&", 5}, {"#", 5}, - {">>", 5}, {"<<", 5}, {"abs", 5}, {"*", 10}, - {"%", 10}, {"/", 15}, {"date_part", 20}, {"year", 20}, - {"round", 100}, {"~~", 200}, {"!~~", 200}, {"regexp_matches", 200}, - {"||", 200}}; - idx_t cost_children = 0; for (auto &child : expr.children) { cost_children += Cost(*child); @@ -222,71 +213,4 @@ idx_t ExpressionHeuristics::Cost(Expression &expr) { return 1000; } -idx_t ExpressionHeuristics::Cost(TableFilter &filter) { - switch (filter.filter_type) { - case TableFilterType::DYNAMIC_FILTER: - case TableFilterType::OPTIONAL_FILTER: - return 0; - case TableFilterType::CONJUNCTION_OR: { - auto &conjunction_and = filter.Cast(); - idx_t cost = 5; - for (auto &child_filter : conjunction_and.child_filters) { - cost += Cost(*child_filter); - } - return cost; - } - case TableFilterType::CONJUNCTION_AND: { - auto &conjunction_and = filter.Cast(); - idx_t cost = 5; - for (auto &child_filter : conjunction_and.child_filters) { - cost += Cost(*child_filter); - } - return cost; - } - case TableFilterType::CONSTANT_COMPARISON: { - auto &constant_filter = filter.Cast(); - return ExpressionCost(constant_filter.constant.type().InternalType(), 1); - } - case TableFilterType::IS_NULL: - case TableFilterType::IS_NOT_NULL: - return 5; - case TableFilterType::STRUCT_EXTRACT: { - auto &struct_filter = filter.Cast(); - return Cost(*struct_filter.child_filter); - } - default: - return 1000; - } -} - -vector ExpressionHeuristics::GetInitialOrder(const TableFilterSet &table_filters) { - struct FilterCost { - idx_t index; - idx_t cost; - - bool operator==(const FilterCost &p) const { - return cost == p.cost; - } - bool operator<(const FilterCost &p) const { - return cost < p.cost; - } - }; - vector filter_costs; - idx_t filter_index = 0; - for (auto &entry : table_filters.filters) { - FilterCost cost; - cost.index = filter_index; - cost.cost = Cost(*entry.second); - filter_costs.push_back(cost); - filter_index++; - } - // sort by cost and put back in place - sort(filter_costs.begin(), filter_costs.end()); - vector initial_permutation; - for (idx_t i = 0; i < filter_costs.size(); i++) { - initial_permutation.push_back(filter_costs[i].index); - } - return initial_permutation; -} - } // namespace duckdb diff --git a/src/duckdb/src/optimizer/filter_combiner.cpp b/src/duckdb/src/optimizer/filter_combiner.cpp index 1752cb8ed..45d7c06a0 100644 --- a/src/duckdb/src/optimizer/filter_combiner.cpp +++ b/src/duckdb/src/optimizer/filter_combiner.cpp @@ -181,6 +181,225 @@ bool FilterCombiner::HasFilters() { return has_filters; } +// unordered_map> MergeAnd(unordered_map> &f_1, +// unordered_map> &f_2) { +// unordered_map> result; +// for (auto &f : f_1) { +// auto it = f_2.find(f.first); +// if (it == f_2.end()) { +// result[f.first] = f.second; +// } else { +// Value *min = nullptr, *max = nullptr; +// if (it->second.first && f.second.first) { +// if (*f.second.first > *it->second.first) { +// min = f.second.first; +// } else { +// min = it->second.first; +// } + +// } else if (it->second.first) { +// min = it->second.first; +// } else if (f.second.first) { +// min = f.second.first; +// } else { +// min = nullptr; +// } +// if (it->second.second && f.second.second) { +// if (*f.second.second < *it->second.second) { +// max = f.second.second; +// } else { +// max = it->second.second; +// } +// } else if (it->second.second) { +// max = it->second.second; +// } else if (f.second.second) { +// max = f.second.second; +// } else { +// max = nullptr; +// } +// result[f.first] = {min, max}; +// f_2.erase(f.first); +// } +// } +// for (auto &f : f_2) { +// result[f.first] = f.second; +// } +// return result; +// } + +// unordered_map> MergeOr(unordered_map> &f_1, +// unordered_map> &f_2) { +// unordered_map> result; +// for (auto &f : f_1) { +// auto it = f_2.find(f.first); +// if (it != f_2.end()) { +// Value *min = nullptr, *max = nullptr; +// if (it->second.first && f.second.first) { +// if (*f.second.first < *it->second.first) { +// min = f.second.first; +// } else { +// min = it->second.first; +// } +// } +// if (it->second.second && f.second.second) { +// if (*f.second.second > *it->second.second) { +// max = f.second.second; +// } else { +// max = it->second.second; +// } +// } +// result[f.first] = {min, max}; +// f_2.erase(f.first); +// } +// } +// return result; +// } + +// unordered_map> +// FilterCombiner::FindZonemapChecks(vector &column_ids, unordered_set ¬_constants, Expression *filter) +// { unordered_map> checks; switch (filter->type) { case +// ExpressionType::CONJUNCTION_OR: { +// //! For a filter to +// auto &or_exp = filter->Cast(); +// checks = FindZonemapChecks(column_ids, not_constants, or_exp.children[0].get()); +// for (size_t i = 1; i < or_exp.children.size(); ++i) { +// auto child_check = FindZonemapChecks(column_ids, not_constants, or_exp.children[i].get()); +// checks = MergeOr(checks, child_check); +// } +// return checks; +// } +// case ExpressionType::CONJUNCTION_AND: { +// auto &and_exp = filter->Cast(); +// checks = FindZonemapChecks(column_ids, not_constants, and_exp.children[0].get()); +// for (size_t i = 1; i < and_exp.children.size(); ++i) { +// auto child_check = FindZonemapChecks(column_ids, not_constants, and_exp.children[i].get()); +// checks = MergeAnd(checks, child_check); +// } +// return checks; +// } +// case ExpressionType::COMPARE_IN: { +// auto &comp_in_exp = filter->Cast(); +// if (comp_in_exp.children[0]->type == ExpressionType::BOUND_COLUMN_REF) { +// Value *min = nullptr, *max = nullptr; +// auto &column_ref = comp_in_exp.children[0]->Cast(); +// for (size_t i {1}; i < comp_in_exp.children.size(); i++) { +// if (comp_in_exp.children[i]->type != ExpressionType::VALUE_CONSTANT) { +// //! This indicates the column has a comparison that is not with a constant +// not_constants.insert(column_ids[column_ref.binding.column_index]); +// break; +// } else { +// auto &const_value_expr = comp_in_exp.children[i]->Cast(); +// if (const_value_expr.value.IsNull()) { +// return checks; +// } +// if (!min && !max) { +// min = &const_value_expr.value; +// max = min; +// } else { +// if (*min > const_value_expr.value) { +// min = &const_value_expr.value; +// } +// if (*max < const_value_expr.value) { +// max = &const_value_expr.value; +// } +// } +// } +// } +// checks[column_ids[column_ref.binding.column_index]] = {min, max}; +// } +// return checks; +// } +// case ExpressionType::COMPARE_EQUAL: { +// auto &comp_exp = filter->Cast(); +// if ((comp_exp.left->expression_class == ExpressionClass::BOUND_COLUMN_REF && +// comp_exp.right->expression_class == ExpressionClass::BOUND_CONSTANT)) { +// auto &column_ref = comp_exp.left->Cast(); +// auto &constant_value_expr = comp_exp.right->Cast(); +// checks[column_ids[column_ref.binding.column_index]] = {&constant_value_expr.value, +// &constant_value_expr.value}; +// } +// if ((comp_exp.left->expression_class == ExpressionClass::BOUND_CONSTANT && +// comp_exp.right->expression_class == ExpressionClass::BOUND_COLUMN_REF)) { +// auto &column_ref = comp_exp.right->Cast(); +// auto &constant_value_expr = comp_exp.left->Cast(); +// checks[column_ids[column_ref.binding.column_index]] = {&constant_value_expr.value, +// &constant_value_expr.value}; +// } +// return checks; +// } +// case ExpressionType::COMPARE_LESSTHAN: +// case ExpressionType::COMPARE_LESSTHANOREQUALTO: { +// auto &comp_exp = filter->Cast(); +// if ((comp_exp.left->expression_class == ExpressionClass::BOUND_COLUMN_REF && +// comp_exp.right->expression_class == ExpressionClass::BOUND_CONSTANT)) { +// auto &column_ref = comp_exp.left->Cast(); +// auto &constant_value_expr = comp_exp.right->Cast(); +// checks[column_ids[column_ref.binding.column_index]] = {nullptr, &constant_value_expr.value}; +// } +// if ((comp_exp.left->expression_class == ExpressionClass::BOUND_CONSTANT && +// comp_exp.right->expression_class == ExpressionClass::BOUND_COLUMN_REF)) { +// auto &column_ref = comp_exp.right->Cast(); +// auto &constant_value_expr = comp_exp.left->Cast(); +// checks[column_ids[column_ref.binding.column_index]] = {&constant_value_expr.value, nullptr}; +// } +// return checks; +// } +// case ExpressionType::COMPARE_GREATERTHANOREQUALTO: +// case ExpressionType::COMPARE_GREATERTHAN: { +// auto &comp_exp = filter->Cast(); +// if ((comp_exp.left->expression_class == ExpressionClass::BOUND_COLUMN_REF && +// comp_exp.right->expression_class == ExpressionClass::BOUND_CONSTANT)) { +// auto &column_ref = comp_exp.left->Cast(); +// auto &constant_value_expr = comp_exp.right->Cast(); +// checks[column_ids[column_ref.binding.column_index]] = {&constant_value_expr.value, nullptr}; +// } +// if ((comp_exp.left->expression_class == ExpressionClass::BOUND_CONSTANT && +// comp_exp.right->expression_class == ExpressionClass::BOUND_COLUMN_REF)) { +// auto &column_ref = comp_exp.right->Cast(); +// auto &constant_value_expr = comp_exp.left->Cast(); +// checks[column_ids[column_ref.binding.column_index]] = {nullptr, &constant_value_expr.value}; +// } +// return checks; +// } +// default: +// return checks; +// } +// } + +// vector FilterCombiner::GenerateZonemapChecks(vector &column_ids, +// vector &pushed_filters) { +// vector zonemap_checks; +// unordered_set not_constants; +// //! We go through the remaining filters and capture their min max +// if (remaining_filters.empty()) { +// return zonemap_checks; +// } + +// auto checks = FindZonemapChecks(column_ids, not_constants, remaining_filters[0].get()); +// for (size_t i = 1; i < remaining_filters.size(); ++i) { +// auto child_check = FindZonemapChecks(column_ids, not_constants, remaining_filters[i].get()); +// checks = MergeAnd(checks, child_check); +// } +// //! We construct the equivalent filters +// for (auto not_constant : not_constants) { +// checks.erase(not_constant); +// } +// for (const auto &pushed_filter : pushed_filters) { +// checks.erase(column_ids[pushed_filter.column_index]); +// } +// for (const auto &check : checks) { +// if (check.second.first) { +// zonemap_checks.emplace_back(check.second.first->Copy(), ExpressionType::COMPARE_GREATERTHANOREQUALTO, +// check.first); +// } +// if (check.second.second) { +// zonemap_checks.emplace_back(check.second.second->Copy(), ExpressionType::COMPARE_LESSTHANOREQUALTO, +// check.first); +// } +// } +// return zonemap_checks; +// } + // Try to extract a column index from a bound column ref expression, or a column ref recursively nested // inside of a struct_extract call. If the expression is not a column ref (or nested column ref), return false. static bool TryGetBoundColumnIndex(const vector &column_ids, const Expression &expr, ColumnIndex &result) { @@ -261,339 +480,261 @@ bool FilterCombiner::IsDenseRange(vector &in_list) { return true; } -static bool SupportedFilterComparison(ExpressionType expression_type) { - switch (expression_type) { - case ExpressionType::COMPARE_EQUAL: - case ExpressionType::COMPARE_GREATERTHAN: - case ExpressionType::COMPARE_GREATERTHANOREQUALTO: - case ExpressionType::COMPARE_LESSTHAN: - case ExpressionType::COMPARE_LESSTHANOREQUALTO: - case ExpressionType::COMPARE_NOTEQUAL: - return true; - default: - return false; - } -} - -bool TypeSupportsConstantFilter(const LogicalType &type) { - if (TypeIsNumeric(type.InternalType())) { - return true; - } - if (type.InternalType() == PhysicalType::VARCHAR || type.InternalType() == PhysicalType::BOOL) { - return true; - } - return false; -} - -FilterPushdownResult FilterCombiner::TryPushdownConstantFilter(TableFilterSet &table_filters, - const vector &column_ids, - column_t column_id, - vector &info_list) { - if (info_list.empty()) { - // no constants - already removed - return FilterPushdownResult::NO_PUSHDOWN; - } - auto filter_exp = equivalence_map.end(); - auto &constant_info = info_list[0]; - // check if the type is supported - if (!TypeSupportsConstantFilter(constant_info.constant.type())) { - // not supported - return FilterPushdownResult::NO_PUSHDOWN; - } - if (!SupportedFilterComparison(constant_info.comparison_type)) { - return FilterPushdownResult::NO_PUSHDOWN; - } - //! Here we check if these filters are column references - filter_exp = equivalence_map.find(column_id); - - if (filter_exp->second.size() != 1) { - return FilterPushdownResult::NO_PUSHDOWN; - } - - auto &expr = filter_exp->second[0]; - auto equiv_set = filter_exp->first; - - // Try to get the column index, either from bound column ref, or a column ref nested inside of a - // struct_extract call - ColumnIndex column_index; - if (!TryGetBoundColumnIndex(column_ids, expr, column_index)) { - return FilterPushdownResult::NO_PUSHDOWN; - } - - auto &constant_list = constant_values.find(equiv_set)->second; - for (auto &constant_cmp : constant_list) { - auto constant_filter = make_uniq(constant_cmp.comparison_type, constant_cmp.constant); - table_filters.PushFilter(column_index, PushDownFilterIntoExpr(expr, std::move(constant_filter))); - } - equivalence_map.erase(filter_exp); - return FilterPushdownResult::PUSHED_DOWN_FULLY; -} - -FilterPushdownResult FilterCombiner::TryPushdownPrefixFilter(TableFilterSet &table_filters, - const vector &column_ids, Expression &expr) { - if (expr.GetExpressionClass() != ExpressionClass::BOUND_FUNCTION) { - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &func = expr.Cast(); - if (func.function.name != "prefix") { - return FilterPushdownResult::NO_PUSHDOWN; - } - if (func.children[0]->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF || - func.children[1]->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { - // we need prefix(col, 'literal') in order to push this down - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &column_ref = func.children[0]->Cast(); - auto &constant_value_expr = func.children[1]->Cast(); - auto prefix_string = StringValue::Get(constant_value_expr.value); - if (prefix_string.empty()) { - // empty prefix - skip - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &column_index = column_ids[column_ref.binding.column_index]; - //! Replace prefix with a set of comparisons - auto lower_bound = make_uniq(ExpressionType::COMPARE_GREATERTHANOREQUALTO, Value(prefix_string)); - prefix_string[prefix_string.size() - 1]++; - auto upper_bound = make_uniq(ExpressionType::COMPARE_LESSTHAN, Value(prefix_string)); - table_filters.PushFilter(column_index, std::move(lower_bound)); - table_filters.PushFilter(column_index, std::move(upper_bound)); - return FilterPushdownResult::PUSHED_DOWN_FULLY; -} +TableFilterSet FilterCombiner::GenerateTableScanFilters(const vector &column_ids) { + TableFilterSet table_filters; + //! First, we figure the filters that have constant expressions that we can push down to the table scan + for (auto &constant_value : constant_values) { + if (!constant_value.second.empty()) { + auto filter_exp = equivalence_map.end(); + if ((constant_value.second[0].comparison_type == ExpressionType::COMPARE_EQUAL || + constant_value.second[0].comparison_type == ExpressionType::COMPARE_GREATERTHAN || + constant_value.second[0].comparison_type == ExpressionType::COMPARE_GREATERTHANOREQUALTO || + constant_value.second[0].comparison_type == ExpressionType::COMPARE_LESSTHAN || + constant_value.second[0].comparison_type == ExpressionType::COMPARE_LESSTHANOREQUALTO || + constant_value.second[0].comparison_type == ExpressionType::COMPARE_NOTEQUAL) && + (TypeIsNumeric(constant_value.second[0].constant.type().InternalType()) || + constant_value.second[0].constant.type().InternalType() == PhysicalType::VARCHAR || + constant_value.second[0].constant.type().InternalType() == PhysicalType::BOOL)) { + //! Here we check if these filters are column references + filter_exp = equivalence_map.find(constant_value.first); -FilterPushdownResult FilterCombiner::TryPushdownLikeFilter(TableFilterSet &table_filters, - const vector &column_ids, Expression &expr) { - if (expr.GetExpressionClass() != ExpressionClass::BOUND_FUNCTION) { - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &func = expr.Cast(); - if (func.function.name != "~~") { - return FilterPushdownResult::NO_PUSHDOWN; - } - if (func.children[0]->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF || - func.children[1]->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { - // we need col LIKE 'literal' in order to generate extra filters - return FilterPushdownResult::NO_PUSHDOWN; - } + if (filter_exp->second.size() != 1) { + continue; + } - //! This is a like function. - auto &column_ref = func.children[0]->Cast(); - auto &constant_value_expr = func.children[1]->Cast(); - auto &column_index = column_ids[column_ref.binding.column_index]; - // constant value expr can sometimes be null. if so, push is not null filter, which will - // make the filter unsatisfiable and return no results. - if (constant_value_expr.value.IsNull()) { - auto is_not_null = make_uniq(); - table_filters.PushFilter(column_index, std::move(is_not_null)); - return FilterPushdownResult::PUSHED_DOWN_FULLY; - } - auto &like_string = StringValue::Get(constant_value_expr.value); - if (like_string[0] == '%' || like_string[0] == '_') { - //! If the like starts with a special character we have no fixed prefix so nothing to pushdown - return FilterPushdownResult::NO_PUSHDOWN; - } - string prefix; - bool equality = true; - for (char const &c : like_string) { - if (c == '%' || c == '_') { - equality = false; - break; - } - prefix += c; - } - if (equality) { - //! If the LIKE has no special characters we can turn it into an equality and push that down - auto equal_filter = make_uniq(ExpressionType::COMPARE_EQUAL, Value(prefix)); - table_filters.PushFilter(column_index, std::move(equal_filter)); - return FilterPushdownResult::PUSHED_DOWN_FULLY; - } + auto &expr = filter_exp->second[0]; + auto equiv_set = filter_exp->first; - //! We have a prefix - we can push down the prefix using a bound (x >= PREFIX AND x <= prefix + 1) - // Note that we still need to execute the LIKE filter - auto lower_bound = make_uniq(ExpressionType::COMPARE_GREATERTHANOREQUALTO, Value(prefix)); - prefix[prefix.size() - 1]++; - auto upper_bound = make_uniq(ExpressionType::COMPARE_LESSTHAN, Value(prefix)); - table_filters.PushFilter(column_index, std::move(lower_bound)); - table_filters.PushFilter(column_index, std::move(upper_bound)); - return FilterPushdownResult::PUSHED_DOWN_PARTIALLY; -} + // Try to get the column index, either from bound column ref, or a column ref nested inside of a + // struct_extract call + ColumnIndex column_index; + if (!TryGetBoundColumnIndex(column_ids, expr, column_index)) { + continue; + } -FilterPushdownResult FilterCombiner::TryPushdownInFilter(TableFilterSet &table_filters, - const vector &column_ids, Expression &expr) { - if (expr.GetExpressionType() != ExpressionType::COMPARE_IN) { - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &func = expr.Cast(); - D_ASSERT(func.children.size() > 1); - if (func.children[0]->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF) { - // we need col IN (...) to be able to push this down - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &column_ref = func.children[0]->Cast(); - auto &column_index = column_ids[column_ref.binding.column_index]; - //! check if all children are const expr - bool children_constant = true; - for (size_t i {1}; i < func.children.size(); i++) { - if (func.children[i]->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { - children_constant = false; - break; - } - auto &const_value_expr = func.children[i]->Cast(); - if (const_value_expr.value.IsNull()) { - // cannot simplify NULL values - children_constant = false; - break; + auto &constant_list = constant_values.find(equiv_set)->second; + for (auto &constant_cmp : constant_list) { + auto constant_filter = + make_uniq(constant_cmp.comparison_type, constant_cmp.constant); + table_filters.PushFilter(column_index, PushDownFilterIntoExpr(expr, std::move(constant_filter))); + } + equivalence_map.erase(filter_exp); + } } } - if (!children_constant) { - // all children must be constant - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &fst_const_value_expr = func.children[1]->Cast(); - auto &type = fst_const_value_expr.value.type(); - - if (func.children.size() == 2 && TypeSupportsConstantFilter(type)) { - // col IN (literal) is equivalent to an equality comparison - push that down - auto bound_eq_comparison = make_uniq(ExpressionType::COMPARE_EQUAL, fst_const_value_expr.value); - table_filters.PushFilter(column_index, std::move(bound_eq_comparison)); - return FilterPushdownResult::PUSHED_DOWN_FULLY; - } - - //! Check if values are consecutive, if yes transform them to >= <= (only for integers) - // e.g. if we have x IN (1, 2, 3, 4, 5) we transform this into x >= 1 AND x <= 5 - vector in_list; - for (idx_t i = 1; i < func.children.size(); i++) { - auto &const_value_expr = func.children[i]->Cast(); - D_ASSERT(!const_value_expr.value.IsNull()); - in_list.push_back(const_value_expr.value); - } - if (type.IsIntegral() && IsDenseRange(in_list)) { - // dense range! turn this into x >= min AND x <= max - // IsDenseRange sorts in_list, so the front element is the min and the back element is the max - auto lower_bound = - make_uniq(ExpressionType::COMPARE_GREATERTHANOREQUALTO, std::move(in_list.front())); - auto upper_bound = - make_uniq(ExpressionType::COMPARE_LESSTHANOREQUALTO, std::move(in_list.back())); - table_filters.PushFilter(column_index, std::move(lower_bound)); - table_filters.PushFilter(column_index, std::move(upper_bound)); - return FilterPushdownResult::PUSHED_DOWN_FULLY; - } - // if this is not a dense range we can push an optional filter for zone-map pruning - auto optional_filter = make_uniq(); - auto in_filter = make_uniq(std::move(in_list)); - optional_filter->child_filter = std::move(in_filter); - table_filters.PushFilter(column_index, std::move(optional_filter)); - return FilterPushdownResult::PUSHED_DOWN_PARTIALLY; -} - -FilterPushdownResult FilterCombiner::TryPushdownOrClause(TableFilterSet &table_filters, - const vector &column_ids, Expression &expr) { - if (expr.GetExpressionClass() != ExpressionClass::BOUND_CONJUNCTION) { - return FilterPushdownResult::NO_PUSHDOWN; - } - auto &conj = expr.Cast(); - if (conj.GetExpressionType() != ExpressionType::CONJUNCTION_OR) { - return FilterPushdownResult::NO_PUSHDOWN; - } - auto conj_filter = make_uniq(); - if (conj.children.empty()) { - return FilterPushdownResult::NO_PUSHDOWN; - } - idx_t column_id = 0; - for (idx_t i = 0; i < conj.children.size(); i++) { - auto &child = conj.children[i]; - if (child->GetExpressionClass() != ExpressionClass::BOUND_COMPARISON) { - return FilterPushdownResult::NO_PUSHDOWN; - } - optional_ptr column_ref; - optional_ptr const_val; - auto &comp = child->Cast(); - bool invert = false; - if (comp.left->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && - comp.right->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) { - column_ref = comp.left->Cast(); - const_val = comp.right->Cast(); - } else if (comp.left->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT && - comp.right->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { - column_ref = comp.right->Cast(); - const_val = comp.left->Cast(); - invert = true; - } else { - // child of OR filter is not simple so we do not push the or filter down at all - return FilterPushdownResult::NO_PUSHDOWN; - } - - if (i == 0) { - auto &col_id = column_ids[column_ref->binding.column_index]; - column_id = col_id.GetPrimaryIndex(); - } else if (column_id != column_ids[column_ref->binding.column_index].GetPrimaryIndex()) { - return FilterPushdownResult::NO_PUSHDOWN; - } - - auto comparison_type = invert ? FlipComparisonExpression(comp.GetExpressionType()) : comp.GetExpressionType(); - if (const_val->value.IsNull()) { - switch (comparison_type) { - case ExpressionType::COMPARE_DISTINCT_FROM: { - auto null_filter = make_uniq(); - conj_filter->child_filters.push_back(std::move(null_filter)); - break; + //! Here we look for LIKE or IN filters + for (idx_t rem_fil_idx = 0; rem_fil_idx < remaining_filters.size(); rem_fil_idx++) { + auto &remaining_filter = remaining_filters[rem_fil_idx]; + if (remaining_filter->GetExpressionClass() == ExpressionClass::BOUND_FUNCTION) { + auto &func = remaining_filter->Cast(); + if (func.function.name == "prefix" && + func.children[0]->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && + func.children[1]->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { + //! This is a like function. + auto &column_ref = func.children[0]->Cast(); + auto &constant_value_expr = func.children[1]->Cast(); + auto like_string = StringValue::Get(constant_value_expr.value); + if (like_string.empty()) { + continue; + } + auto &column_index = column_ids[column_ref.binding.column_index]; + //! Here the like must be transformed to a BOUND COMPARISON geq le + auto lower_bound = + make_uniq(ExpressionType::COMPARE_GREATERTHANOREQUALTO, Value(like_string)); + like_string[like_string.size() - 1]++; + auto upper_bound = make_uniq(ExpressionType::COMPARE_LESSTHAN, Value(like_string)); + table_filters.PushFilter(column_index, std::move(lower_bound)); + table_filters.PushFilter(column_index, std::move(upper_bound)); } - case ExpressionType::COMPARE_NOT_DISTINCT_FROM: { - auto null_filter = make_uniq(); - conj_filter->child_filters.push_back(std::move(null_filter)); - break; + if (func.function.name == "~~" && + func.children[0]->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && + func.children[1]->GetExpressionType() == ExpressionType::VALUE_CONSTANT) { + //! This is a like function. + auto &column_ref = func.children[0]->Cast(); + auto &constant_value_expr = func.children[1]->Cast(); + auto &column_index = column_ids[column_ref.binding.column_index]; + // constant value expr can sometimes be null. if so, push is not null filter, which will + // make the filter unsatisfiable and return no results. + if (constant_value_expr.value.IsNull()) { + auto is_not_null = make_uniq(); + table_filters.PushFilter(column_index, std::move(is_not_null)); + continue; + } + auto &like_string = StringValue::Get(constant_value_expr.value); + if (like_string[0] == '%' || like_string[0] == '_') { + //! We have no prefix so nothing to pushdown + break; + } + string prefix; + bool equality = true; + for (char const &c : like_string) { + if (c == '%' || c == '_') { + equality = false; + break; + } + prefix += c; + } + if (equality) { + //! Here the like can be transformed to an equality query + auto equal_filter = make_uniq(ExpressionType::COMPARE_EQUAL, Value(prefix)); + table_filters.PushFilter(column_index, std::move(equal_filter)); + } else { + //! Here the like must be transformed to a BOUND COMPARISON geq le + auto lower_bound = + make_uniq(ExpressionType::COMPARE_GREATERTHANOREQUALTO, Value(prefix)); + prefix[prefix.size() - 1]++; + auto upper_bound = make_uniq(ExpressionType::COMPARE_LESSTHAN, Value(prefix)); + table_filters.PushFilter(column_index, std::move(lower_bound)); + table_filters.PushFilter(column_index, std::move(upper_bound)); + } + } + } else if (remaining_filter->GetExpressionType() == ExpressionType::COMPARE_IN) { + auto &func = remaining_filter->Cast(); + D_ASSERT(func.children.size() > 1); + if (func.children[0]->GetExpressionClass() != ExpressionClass::BOUND_COLUMN_REF) { + continue; } - default: - // if any other comparison type (i.e EQUAL, NOT_EQUAL) do not push a table filter - this is a nop - // since x = NULL is always falsey, and this is a chain of OR conditions, we can just ignore it + auto &column_ref = func.children[0]->Cast(); + auto &column_index = column_ids[column_ref.binding.column_index]; + if (column_index.IsRowIdColumn()) { break; } - } else { - auto const_filter = make_uniq(comparison_type, const_val->value); - conj_filter->child_filters.push_back(std::move(const_filter)); - } - } - auto optional_filter = make_uniq(); - optional_filter->child_filter = std::move(conj_filter); - table_filters.PushFilter(ColumnIndex(column_id), std::move(optional_filter)); - return FilterPushdownResult::PUSHED_DOWN_PARTIALLY; -} + //! check if all children are const expr + bool children_constant = true; + for (size_t i {1}; i < func.children.size(); i++) { + if (func.children[i]->GetExpressionType() != ExpressionType::VALUE_CONSTANT) { + children_constant = false; + break; + } + auto &const_value_expr = func.children[i]->Cast(); + if (const_value_expr.value.IsNull()) { + // cannot simplify NULL values + children_constant = false; + break; + } + } + if (!children_constant) { + continue; + } + auto &fst_const_value_expr = func.children[1]->Cast(); + auto &type = fst_const_value_expr.value.type(); -FilterPushdownResult FilterCombiner::TryPushdownExpression(TableFilterSet &table_filters, - const vector &column_ids, Expression &expr) { - auto pushdown_result = TryPushdownPrefixFilter(table_filters, column_ids, expr); - if (pushdown_result != FilterPushdownResult::NO_PUSHDOWN) { - return pushdown_result; - } - pushdown_result = TryPushdownLikeFilter(table_filters, column_ids, expr); - if (pushdown_result != FilterPushdownResult::NO_PUSHDOWN) { - return pushdown_result; - } - pushdown_result = TryPushdownInFilter(table_filters, column_ids, expr); - if (pushdown_result != FilterPushdownResult::NO_PUSHDOWN) { - return pushdown_result; - } - pushdown_result = TryPushdownOrClause(table_filters, column_ids, expr); - if (pushdown_result != FilterPushdownResult::NO_PUSHDOWN) { - return pushdown_result; - } - return FilterPushdownResult::NO_PUSHDOWN; -} + if ((type.IsNumeric() || type.id() == LogicalTypeId::VARCHAR || type.id() == LogicalTypeId::BOOLEAN) && + func.children.size() == 2) { + auto bound_eq_comparison = + make_uniq(ExpressionType::COMPARE_EQUAL, fst_const_value_expr.value); + table_filters.PushFilter(column_index, std::move(bound_eq_comparison)); + remaining_filters.erase_at(rem_fil_idx--); // decrement to stay on the same idx next iteration + continue; + } -TableFilterSet FilterCombiner::GenerateTableScanFilters(const vector &column_ids) { - TableFilterSet table_filters; - //! First, we figure the filters that have constant expressions that we can push down to the table scan - for (auto &constant_value : constant_values) { - TryPushdownConstantFilter(table_filters, column_ids, constant_value.first, constant_value.second); + //! Check if values are consecutive, if yes transform them to >= <= (only for integers) + // e.g. if we have x IN (1, 2, 3, 4, 5) we transform this into x >= 1 AND x <= 5 + vector in_list; + for (idx_t i = 1; i < func.children.size(); i++) { + auto &const_value_expr = func.children[i]->Cast(); + D_ASSERT(!const_value_expr.value.IsNull()); + in_list.push_back(const_value_expr.value); + } + if (type.IsIntegral() && IsDenseRange(in_list)) { + // dense range! turn this into x >= min AND x <= max + // IsDenseRange sorts in_list, so the front element is the min and the back element is the max + auto lower_bound = + make_uniq(ExpressionType::COMPARE_GREATERTHANOREQUALTO, std::move(in_list.front())); + auto upper_bound = + make_uniq(ExpressionType::COMPARE_LESSTHANOREQUALTO, std::move(in_list.back())); + table_filters.PushFilter(column_index, std::move(lower_bound)); + table_filters.PushFilter(column_index, std::move(upper_bound)); + + remaining_filters.erase_at(rem_fil_idx--); // decrement to stay on the same idx next iteration + } else { + // if this is not a dense range we can push a zone-map filter + auto optional_filter = make_uniq(); + auto in_filter = make_uniq(std::move(in_list)); + optional_filter->child_filter = std::move(in_filter); + table_filters.PushFilter(column_index, std::move(optional_filter)); + } + } } - //! Here we look for LIKE or IN filters + for (idx_t rem_fil_idx = 0; rem_fil_idx < remaining_filters.size(); rem_fil_idx++) { auto &remaining_filter = remaining_filters[rem_fil_idx]; - auto pushdown_result = TryPushdownExpression(table_filters, column_ids, *remaining_filter); - if (pushdown_result == FilterPushdownResult::PUSHED_DOWN_FULLY) { - // the filter has been pushed down entirely - we can prune it - remaining_filters.erase_at(rem_fil_idx--); + if (remaining_filter->GetExpressionClass() == ExpressionClass::BOUND_CONJUNCTION) { + auto &conj = remaining_filter->Cast(); + if (conj.GetExpressionType() == ExpressionType::CONJUNCTION_OR) { + optional_idx column_id; + auto optional_filter = make_uniq(); + auto conj_filter = make_uniq(); + for (auto &child : conj.children) { + if (child->GetExpressionClass() != ExpressionClass::BOUND_COMPARISON) { + column_id.SetInvalid(); + break; + } + optional_ptr column_ref; + optional_ptr const_val; + auto &comp = child->Cast(); + bool invert = false; + if (comp.left->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && + comp.right->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT) { + column_ref = comp.left->Cast(); + const_val = comp.right->Cast(); + } else if (comp.left->GetExpressionClass() == ExpressionClass::BOUND_CONSTANT && + comp.right->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { + column_ref = comp.right->Cast(); + const_val = comp.left->Cast(); + invert = true; + } else { + // child of OR filter is not simple so we do not push the or filter down at all + column_id.SetInvalid(); + break; + } + + if (!column_id.IsValid()) { + auto &col_id = column_ids[column_ref->binding.column_index]; + if (col_id.IsRowIdColumn()) { + break; + } + column_id = col_id.GetPrimaryIndex(); + } else if (column_id.GetIndex() != column_ids[column_ref->binding.column_index].GetPrimaryIndex()) { + column_id.SetInvalid(); + break; + } + + if (const_val->value.type().IsTemporal()) { + column_id.SetInvalid(); + break; + } + auto comparison_type = + invert ? FlipComparisonExpression(comp.GetExpressionType()) : comp.GetExpressionType(); + if (const_val->value.IsNull()) { + switch (comparison_type) { + case ExpressionType::COMPARE_DISTINCT_FROM: { + auto null_filter = make_uniq(); + conj_filter->child_filters.push_back(std::move(null_filter)); + break; + } + case ExpressionType::COMPARE_NOT_DISTINCT_FROM: { + auto null_filter = make_uniq(); + conj_filter->child_filters.push_back(std::move(null_filter)); + break; + } + // if any other comparison type (i.e EQUAL, NOT_EQUAL) do not push a table filter + default: + break; + } + } else { + auto const_filter = make_uniq(comparison_type, const_val->value); + conj_filter->child_filters.push_back(std::move(const_filter)); + } + } + if (column_id.IsValid()) { + optional_filter->child_filter = std::move(conj_filter); + table_filters.PushFilter(ColumnIndex(column_id.GetIndex()), std::move(optional_filter)); + } + } } } + return table_filters; } @@ -607,7 +748,12 @@ static bool IsLessThan(ExpressionType type) { FilterResult FilterCombiner::AddBoundComparisonFilter(Expression &expr) { auto &comparison = expr.Cast(); - if (!SupportedFilterComparison(comparison.GetExpressionType())) { + if (comparison.GetExpressionType() != ExpressionType::COMPARE_LESSTHAN && + comparison.GetExpressionType() != ExpressionType::COMPARE_LESSTHANOREQUALTO && + comparison.GetExpressionType() != ExpressionType::COMPARE_GREATERTHAN && + comparison.GetExpressionType() != ExpressionType::COMPARE_GREATERTHANOREQUALTO && + comparison.GetExpressionType() != ExpressionType::COMPARE_EQUAL && + comparison.GetExpressionType() != ExpressionType::COMPARE_NOTEQUAL) { // only support [>, >=, <, <=, ==, !=] expressions return FilterResult::UNSUPPORTED; } @@ -1100,5 +1246,175 @@ ValueComparisonResult CompareValueInformation(ExpressionValueInformation &left, return InvertValueComparisonResult(CompareValueInformation(right, left)); } } +// +// void FilterCombiner::LookUpConjunctions(Expression *expr) { +// if (expr->GetExpressionType() == ExpressionType::CONJUNCTION_OR) { +// auto root_or_expr = (BoundConjunctionExpression *)expr; +// for (const auto &entry : map_col_conjunctions) { +// for (const auto &conjs_to_push : entry.second) { +// if (conjs_to_push->root_or->Equals(root_or_expr)) { +// return; +// } +// } +// } +// +// cur_root_or = root_or_expr; +// cur_conjunction = root_or_expr; +// cur_colref_to_push = nullptr; +// if (!BFSLookUpConjunctions(cur_root_or)) { +// if (cur_colref_to_push) { +// auto entry = map_col_conjunctions.find(cur_colref_to_push); +// auto &vec_conjs_to_push = entry->second; +// if (vec_conjs_to_push.size() == 1) { +// map_col_conjunctions.erase(entry); +// return; +// } +// vec_conjs_to_push.pop_back(); +// } +// } +// return; +// } +// +// // Verify if the expression has a column already pushed down by other OR expression +// VerifyOrsToPush(*expr); +//} +// +// bool FilterCombiner::BFSLookUpConjunctions(BoundConjunctionExpression *conjunction) { +// vector conjunctions_to_visit; +// +// for (auto &child : conjunction->children) { +// switch (child->GetExpressionClass()) { +// case ExpressionClass::BOUND_CONJUNCTION: { +// auto child_conjunction = (BoundConjunctionExpression *)child.get(); +// conjunctions_to_visit.emplace_back(child_conjunction); +// break; +// } +// case ExpressionClass::BOUND_COMPARISON: { +// if (!UpdateConjunctionFilter((BoundComparisonExpression *)child.get())) { +// return false; +// } +// break; +// } +// default: { +// return false; +// } +// } +// } +// +// for (auto child_conjunction : conjunctions_to_visit) { +// cur_conjunction = child_conjunction; +// // traverse child conjunction +// if (!BFSLookUpConjunctions(child_conjunction)) { +// return false; +// } +// } +// return true; +//} +// +// void FilterCombiner::VerifyOrsToPush(Expression &expr) { +// if (expr.type == ExpressionType::BOUND_COLUMN_REF) { +// auto colref = (BoundColumnRefExpression *)&expr; +// auto entry = map_col_conjunctions.find(colref); +// if (entry == map_col_conjunctions.end()) { +// return; +// } +// map_col_conjunctions.erase(entry); +// } +// ExpressionIterator::EnumerateChildren(expr, [&](Expression &child) { VerifyOrsToPush(child); }); +//} +// +// bool FilterCombiner::UpdateConjunctionFilter(BoundComparisonExpression *comparison_expr) { +// bool left_is_scalar = comparison_expr->left->IsFoldable(); +// bool right_is_scalar = comparison_expr->right->IsFoldable(); +// +// Expression *non_scalar_expr; +// if (left_is_scalar || right_is_scalar) { +// // only support comparison with scalar +// non_scalar_expr = left_is_scalar ? comparison_expr->right.get() : comparison_expr->left.get(); +// +// if (non_scalar_expr->GetExpressionType() == ExpressionType::BOUND_COLUMN_REF) { +// return UpdateFilterByColumn((BoundColumnRefExpression *)non_scalar_expr, comparison_expr); +// } +// } +// +// return false; +//} +// +// bool FilterCombiner::UpdateFilterByColumn(BoundColumnRefExpression *column_ref, +// BoundComparisonExpression *comparison_expr) { +// if (cur_colref_to_push == nullptr) { +// cur_colref_to_push = column_ref; +// +// auto or_conjunction = make_uniq(ExpressionType::CONJUNCTION_OR); +// or_conjunction->children.emplace_back(comparison_expr->Copy()); +// +// unique_ptr conjs_to_push = make_uniq(); +// conjs_to_push->conjunctions.emplace_back(std::move(or_conjunction)); +// conjs_to_push->root_or = cur_root_or; +// +// auto &&vec_col_conjs = map_col_conjunctions[column_ref]; +// vec_col_conjs.emplace_back(std::move(conjs_to_push)); +// vec_colref_insertion_order.emplace_back(column_ref); +// return true; +// } +// +// auto entry = map_col_conjunctions.find(cur_colref_to_push); +// D_ASSERT(entry != map_col_conjunctions.end()); +// auto &conjunctions_to_push = entry->second.back(); +// +// if (!cur_colref_to_push->Equals(column_ref)) { +// // check for multiple colunms in the same root OR node +// if (cur_root_or == cur_conjunction) { +// return false; +// } +// // found an AND using a different column, we should stop the look up +// if (cur_conjunction->GetExpressionType() == ExpressionType::CONJUNCTION_AND) { +// return false; +// } +// +// // found a different column, AND conditions cannot be preserved anymore +// conjunctions_to_push->preserve_and = false; +// return true; +// } +// +// auto &last_conjunction = conjunctions_to_push->conjunctions.back(); +// if (cur_conjunction->GetExpressionType() == last_conjunction->GetExpressionType()) { +// last_conjunction->children.emplace_back(comparison_expr->Copy()); +// } else { +// auto new_conjunction = make_uniq(cur_conjunction->GetExpressionType()); +// new_conjunction->children.emplace_back(comparison_expr->Copy()); +// conjunctions_to_push->conjunctions.emplace_back(std::move(new_conjunction)); +// } +// return true; +//} +// +// void FilterCombiner::GenerateORFilters(TableFilterSet &table_filter, vector &column_ids) { +// for (const auto colref : vec_colref_insertion_order) { +// auto column_index = column_ids[colref->binding.column_index]; +// if (column_index == COLUMN_IDENTIFIER_ROW_ID) { +// break; +// } +// +// for (const auto &conjunctions_to_push : map_col_conjunctions[colref]) { +// // root OR filter to push into the TableFilter +// auto root_or_filter = make_uniq(); +// // variable to hold the last conjuntion filter pointer +// // the next filter will be added into it, i.e., we create a chain of conjunction filters +// ConjunctionFilter *last_conj_filter = root_or_filter.get(); +// +// for (auto &conjunction : conjunctions_to_push->conjunctions) { +// if (conjunction->GetExpressionType() == ExpressionType::CONJUNCTION_AND && +// conjunctions_to_push->preserve_and) { +// GenerateConjunctionFilter(conjunction.get(), last_conj_filter); +// } else { +// GenerateConjunctionFilter(conjunction.get(), last_conj_filter); +// } +// } +// table_filter.PushFilter(column_index, std::move(root_or_filter)); +// } +// } +// map_col_conjunctions.clear(); +// vec_colref_insertion_order.clear(); +//} } // namespace duckdb diff --git a/src/duckdb/src/optimizer/filter_pushdown.cpp b/src/duckdb/src/optimizer/filter_pushdown.cpp index 461d79767..883885178 100644 --- a/src/duckdb/src/optimizer/filter_pushdown.cpp +++ b/src/duckdb/src/optimizer/filter_pushdown.cpp @@ -149,60 +149,35 @@ unique_ptr FilterPushdown::PushdownJoin(unique_ptrtype == LogicalOperatorType::LOGICAL_ASOF_JOIN || op->type == LogicalOperatorType::LOGICAL_ANY_JOIN || op->type == LogicalOperatorType::LOGICAL_DELIM_JOIN); auto &join = op->Cast(); - - const auto restore_projection_maps = join.HasProjectionMap(); - auto left_projection_map = join.left_projection_map; - auto right_projection_map = join.right_projection_map; + if (join.HasProjectionMap()) { + // cannot push down further otherwise the projection maps won't be preserved + return FinishPushdown(std::move(op)); + } unordered_set left_bindings, right_bindings; LogicalJoin::GetTableReferences(*op->children[0], left_bindings); LogicalJoin::GetTableReferences(*op->children[1], right_bindings); - unique_ptr result; switch (join.join_type) { case JoinType::INNER: // AsOf joins can't push anything into the RHS, so treat it as a left join if (op->type == LogicalOperatorType::LOGICAL_ASOF_JOIN) { - result = PushdownLeftJoin(std::move(op), left_bindings, right_bindings); - break; + return PushdownLeftJoin(std::move(op), left_bindings, right_bindings); } - result = PushdownInnerJoin(std::move(op), left_bindings, right_bindings); - break; + return PushdownInnerJoin(std::move(op), left_bindings, right_bindings); case JoinType::LEFT: - result = PushdownLeftJoin(std::move(op), left_bindings, right_bindings); - break; + return PushdownLeftJoin(std::move(op), left_bindings, right_bindings); case JoinType::MARK: - result = PushdownMarkJoin(std::move(op), left_bindings, right_bindings); - break; + return PushdownMarkJoin(std::move(op), left_bindings, right_bindings); case JoinType::SINGLE: - result = PushdownSingleJoin(std::move(op), left_bindings, right_bindings); - break; + return PushdownSingleJoin(std::move(op), left_bindings, right_bindings); case JoinType::SEMI: case JoinType::ANTI: - result = PushdownSemiAntiJoin(std::move(op)); - break; + return PushdownSemiAntiJoin(std::move(op)); default: // unsupported join type: stop pushing down return FinishPushdown(std::move(op)); } - - if (restore_projection_maps) { - switch (result->type) { - case LogicalOperatorType::LOGICAL_COMPARISON_JOIN: - case LogicalOperatorType::LOGICAL_ASOF_JOIN: - case LogicalOperatorType::LOGICAL_ANY_JOIN: - case LogicalOperatorType::LOGICAL_DELIM_JOIN: { - // Pushing down filter through join didn't change operator type (e.g., LogicalEmptyResult), restore maps - auto &result_join = result->Cast(); - result_join.left_projection_map = std::move(left_projection_map); - result_join.right_projection_map = std::move(right_projection_map); - break; - } - default: - break; - } - } - return result; } void FilterPushdown::PushFilters() { for (auto &f : filters) { diff --git a/src/duckdb/src/optimizer/late_materialization.cpp b/src/duckdb/src/optimizer/late_materialization.cpp index acbcd5bbc..1c2b56f52 100644 --- a/src/duckdb/src/optimizer/late_materialization.cpp +++ b/src/duckdb/src/optimizer/late_materialization.cpp @@ -36,7 +36,7 @@ idx_t LateMaterialization::GetOrInsertRowId(LogicalGet &get) { get.projection_ids.push_back(column_ids.size() - 1); } if (!get.types.empty()) { - get.types.push_back(row_id_type); + get.types.push_back(get.GetRowIdType()); } return column_ids.size() - 1; } @@ -45,7 +45,7 @@ unique_ptr LateMaterialization::ConstructLHS(LogicalGet &get) { // we need to construct a new scan of the same table auto table_index = optimizer.binder.GenerateTableIndex(); auto new_get = make_uniq(table_index, get.function, get.bind_data->Copy(), get.returned_types, - get.names, get.virtual_columns); + get.names, get.GetRowIdType()); new_get->GetMutableColumnIds() = get.GetColumnIds(); new_get->projection_ids = get.projection_ids; return new_get; @@ -74,7 +74,8 @@ ColumnBinding LateMaterialization::ConstructRHS(unique_ptr &op) case LogicalOperatorType::LOGICAL_PROJECTION: { auto &proj = op.Cast(); // push a projection of the row-id column - proj.expressions.push_back(make_uniq("rowid", row_id_type, row_id_binding)); + proj.expressions.push_back( + make_uniq("rowid", get.GetRowIdType(), row_id_binding)); // modify the row-id-binding to push to the new projection row_id_binding = ColumnBinding(proj.table_index, proj.expressions.size() - 1); column_count = proj.expressions.size(); @@ -153,8 +154,9 @@ unique_ptr LateMaterialization::GetExpression(LogicalOperator &op, i case LogicalOperatorType::LOGICAL_GET: { auto &get = op.Cast(); auto &column_id = get.GetColumnIds()[column_index]; - auto column_name = get.GetColumnName(column_id); - auto &column_type = get.GetColumnType(column_id); + auto is_row_id = column_id.IsRowIdColumn(); + auto column_name = is_row_id ? "rowid" : get.names[column_id.GetPrimaryIndex()]; + auto &column_type = is_row_id ? get.GetRowIdType() : get.returned_types[column_id.GetPrimaryIndex()]; auto expr = make_uniq(column_name, column_type, ColumnBinding(get.table_index, column_index)); return std::move(expr); @@ -234,20 +236,16 @@ bool LateMaterialization::TryLateMaterialization(unique_ptr &op } } auto &get = child.get().Cast(); + auto table = get.GetTable(); + if (!table || !table->IsDuckTable()) { + // we can only do the late-materialization optimization for DuckDB tables currently + return false; + } if (column_references.size() >= get.GetColumnIds().size()) { // we do not benefit from late materialization // we need all of the columns to compute the root node anyway (Top-N/Limit/etc) return false; } - if (!get.function.late_materialization) { - // this function does not support late materialization - return false; - } - auto entry = get.virtual_columns.find(COLUMN_IDENTIFIER_ROW_ID); - if (entry == get.virtual_columns.end()) { - throw InternalException("Table function supports late materialization but does not expose a rowid column"); - } - row_id_type = entry->second.type; // we benefit from late materialization // we need to transform this plan into a semi-join with the row-id // we need to ensure the operator returns exactly the same column bindings as before @@ -261,6 +259,8 @@ bool LateMaterialization::TryLateMaterialization(unique_ptr &op auto lhs_row_idx = GetOrInsertRowId(lhs_get); ColumnBinding lhs_binding(lhs_index, lhs_row_idx); + auto &row_id_type = get.GetRowIdType(); + // after constructing the LHS but before constructing the RHS we construct the final projections/orders // - we do this before constructing the RHS because that alter the original plan vector> final_proj_list; diff --git a/src/duckdb/src/optimizer/optimizer.cpp b/src/duckdb/src/optimizer/optimizer.cpp index 8c16e83a6..dc1ddfa59 100644 --- a/src/duckdb/src/optimizer/optimizer.cpp +++ b/src/duckdb/src/optimizer/optimizer.cpp @@ -118,7 +118,7 @@ void Optimizer::RunBuiltInOptimizers() { // this does not change the logical plan structure, but only simplifies the expression trees RunOptimizer(OptimizerType::EXPRESSION_REWRITER, [&]() { rewriter.VisitOperator(*plan); }); - // Rewrites SUM(x + C) into SUM(x) + C * COUNT(x) + // transform ORDER BY + LIMIT to TopN RunOptimizer(OptimizerType::SUM_REWRITER, [&]() { SumRewriterOptimizer optimizer(*this); optimizer.Optimize(plan); diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp index 002bb2540..814adadc0 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp @@ -1,30 +1,12 @@ -#include "duckdb/common/assert.hpp" -#include "duckdb/common/enums/join_type.hpp" -#include "duckdb/common/helper.hpp" -#include "duckdb/common/typedefs.hpp" -#include "duckdb/common/types.hpp" -#include "duckdb/common/types/value.hpp" -#include "duckdb/common/unique_ptr.hpp" -#include "duckdb/common/unordered_map.hpp" -#include "duckdb/common/vector.hpp" #include "duckdb/execution/expression_executor.hpp" #include "duckdb/optimizer/filter_pushdown.hpp" #include "duckdb/optimizer/optimizer.hpp" -#include "duckdb/planner/binder.hpp" -#include "duckdb/planner/column_binding.hpp" #include "duckdb/planner/expression/bound_columnref_expression.hpp" #include "duckdb/planner/expression/bound_comparison_expression.hpp" #include "duckdb/planner/expression/bound_constant_expression.hpp" #include "duckdb/planner/expression_iterator.hpp" -#include "duckdb/planner/joinside.hpp" -#include "duckdb/planner/logical_operator.hpp" -#include "duckdb/planner/operator/logical_any_join.hpp" #include "duckdb/planner/operator/logical_comparison_join.hpp" -#include "duckdb/planner/operator/logical_cross_product.hpp" -#include "duckdb/planner/operator/logical_dummy_scan.hpp" #include "duckdb/planner/operator/logical_filter.hpp" -#include "duckdb/planner/operator/logical_projection.hpp" -#include namespace duckdb { @@ -97,7 +79,6 @@ unique_ptr FilterPushdown::PushdownLeftJoin(unique_ptr> remaining_filters; for (idx_t i = 0; i < filters.size(); i++) { auto side = JoinSide::GetJoinSide(filters[i]->bindings, left_bindings, right_bindings); if (side == JoinSide::LEFT) { @@ -130,12 +111,6 @@ unique_ptr FilterPushdown::PushdownLeftJoin(unique_ptr FilterPushdown::PushdownLeftJoin(unique_ptrchildren[0] = left_pushdown.Rewrite(std::move(op->children[0])); - - bool rewrite_right = true; - if (op->type == LogicalOperatorType::LOGICAL_ANY_JOIN) { - auto &any_join = join.Cast(); - if (AddFilter(any_join.condition->Copy()) == FilterResult::UNSATISFIABLE) { - // filter statically evaluates to false, turns it to the cross product join with 1 row NULLs - if (any_join.join_type == JoinType::LEFT) { - unordered_map>> projections_groups; - auto column_bindings = op->children[1]->GetColumnBindings(); - op->children[1]->ResolveOperatorTypes(); - auto &types = op->children[1]->types; - for (idx_t i = 0; i < column_bindings.size(); i++) { - projections_groups[column_bindings[i].table_index].emplace_back( - make_uniq(Value(types[i]))); - } - - auto create_proj_dummy_scan = [&](idx_t table_index) { - auto dummy_scan = make_uniq(optimizer.binder.GenerateTableIndex()); - auto proj = make_uniq(table_index, std::move(projections_groups[table_index])); - proj->AddChild(std::move(dummy_scan)); - return proj; - }; - // make cross products on the RHS first - auto begin = projections_groups.begin(); - D_ASSERT(begin != projections_groups.end()); - unique_ptr left = create_proj_dummy_scan(begin->first); - projections_groups.erase(begin); - for (auto &group : projections_groups) { - auto proj = create_proj_dummy_scan(group.first); - auto op = LogicalCrossProduct::Create(std::move(left), std::move(proj)); - left = std::move(op); - } - // then make cross product with the LHS - op = LogicalCrossProduct::Create(std::move(op->children[0]), std::move(left)); - rewrite_right = false; - } - } - } - - if (rewrite_right) { - op->children[1] = right_pushdown.Rewrite(std::move(op->children[1])); - } - - for (auto &filter : remaining_filters) { - filters.push_back(std::move(filter)); - } - + op->children[1] = right_pushdown.Rewrite(std::move(op->children[1])); return PushFinalFilters(std::move(op)); } diff --git a/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp b/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp index 4646b894e..b10b60ae4 100644 --- a/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp +++ b/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp @@ -32,11 +32,7 @@ static unique_ptr ReplaceProjectionBindings(LogicalProjection &proj, D_ASSERT(colref.binding.column_index < proj.expressions.size()); D_ASSERT(colref.depth == 0); // replace the binding with a copy to the expression at the referenced index - auto copy = proj.expressions[colref.binding.column_index]->Copy(); - if (!colref.alias.empty()) { - copy->alias = colref.alias; - } - return copy; + return proj.expressions[colref.binding.column_index]->Copy(); } ExpressionIterator::EnumerateChildren( *expr, [&](unique_ptr &child) { child = ReplaceProjectionBindings(proj, std::move(child)); }); diff --git a/src/duckdb/src/optimizer/remove_unused_columns.cpp b/src/duckdb/src/optimizer/remove_unused_columns.cpp index e6543c06f..48ea7cbff 100644 --- a/src/duckdb/src/optimizer/remove_unused_columns.cpp +++ b/src/duckdb/src/optimizer/remove_unused_columns.cpp @@ -87,13 +87,10 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { // for inner joins with equality predicates in the form of (X=Y) // we can replace any references to the RHS (Y) to references to the LHS (X) // this reduces the amount of columns we need to extract from the join hash table - // (except in the case of floating point numbers which have +0 and -0, equal but different). for (auto &cond : comp_join.conditions) { if (cond.comparison == ExpressionType::COMPARE_EQUAL) { if (cond.left->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && - cond.right->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF && - !(cond.left->Cast().return_type.IsFloating() && - cond.right->Cast().return_type.IsFloating())) { + cond.right->GetExpressionClass() == ExpressionClass::BOUND_COLUMN_REF) { // comparison join between two bound column refs // we can replace any reference to the RHS (build-side) with a reference to the LHS (probe-side) auto &lhs_col = cond.left->Cast(); @@ -243,7 +240,8 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { throw InternalException("Could not find column index for table filter"); } - auto column_type = get.GetColumnType(ColumnIndex(filter.first)); + auto column_type = + filter.first == COLUMN_IDENTIFIER_ROW_ID ? LogicalType::ROW_TYPE : get.returned_types[filter.first]; ColumnBinding filter_binding(get.table_index, index.GetIndex()); auto column_ref = make_uniq(std::move(column_type), filter_binding); @@ -270,7 +268,7 @@ void RemoveUnusedColumns::VisitOperator(LogicalOperator &op) { // this generally means we are only interested in whether or not anything exists in the table (e.g. // EXISTS(SELECT * FROM tbl)) in this case, we just scan the row identifier column as it means we do not // need to read any of the columns - column_ids.emplace_back(get.GetAnyColumn()); + column_ids.emplace_back(COLUMN_IDENTIFIER_ROW_ID); } get.SetColumnIds(std::move(column_ids)); diff --git a/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp b/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp index 823b7e7d0..b5fcc8ced 100644 --- a/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp +++ b/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp @@ -21,46 +21,17 @@ static unique_ptr StatisticsOperationsNumericNumericCast(const B return result.ToUnique(); } -bool StatisticsPropagator::CanPropagateCast(const LogicalType &source, const LogicalType &target) { - if (source == target) { - return true; - } - // we can only propagate numeric -> numeric - switch (source.InternalType()) { - case PhysicalType::INT8: - case PhysicalType::INT16: - case PhysicalType::INT32: - case PhysicalType::INT64: - case PhysicalType::INT128: - case PhysicalType::FLOAT: - case PhysicalType::DOUBLE: - break; - default: - return false; - } - switch (target.InternalType()) { - case PhysicalType::INT8: - case PhysicalType::INT16: - case PhysicalType::INT32: - case PhysicalType::INT64: - case PhysicalType::INT128: - case PhysicalType::FLOAT: - case PhysicalType::DOUBLE: - break; - default: - return false; - } - // for time/timestamps/dates - there are various limitations on what we can propagate +static unique_ptr StatisticsNumericCastSwitch(const BaseStatistics &input, const LogicalType &target) { // Downcasting timestamps to times is not a truncation operation switch (target.id()) { case LogicalTypeId::TIME: { - switch (source.id()) { + switch (input.GetType().id()) { case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIMESTAMP_SEC: case LogicalTypeId::TIMESTAMP_MS: case LogicalTypeId::TIMESTAMP_NS: case LogicalTypeId::TIMESTAMP_TZ: - return false; + return nullptr; default: break; } @@ -72,22 +43,22 @@ bool StatisticsPropagator::CanPropagateCast(const LogicalType &source, const Log const bool to_timestamp = target.id() == LogicalTypeId::TIMESTAMP; const bool to_timestamp_tz = target.id() == LogicalTypeId::TIMESTAMP_TZ; // Casting to timestamp[_tz] (us) from a different unit can not re-use stats - switch (source.id()) { + switch (input.GetType().id()) { case LogicalTypeId::TIMESTAMP_NS: case LogicalTypeId::TIMESTAMP_MS: case LogicalTypeId::TIMESTAMP_SEC: - return false; + return nullptr; case LogicalTypeId::TIMESTAMP: { if (to_timestamp_tz) { // Both use INT64 physical type, but should not be treated equal - return false; + return nullptr; } break; } case LogicalTypeId::TIMESTAMP_TZ: { if (to_timestamp) { // Both use INT64 physical type, but should not be treated equal - return false; + return nullptr; } break; } @@ -98,12 +69,12 @@ bool StatisticsPropagator::CanPropagateCast(const LogicalType &source, const Log } case LogicalTypeId::TIMESTAMP_NS: { // Same as above ^ - switch (source.id()) { + switch (input.GetType().id()) { case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIMESTAMP_TZ: case LogicalTypeId::TIMESTAMP_MS: case LogicalTypeId::TIMESTAMP_SEC: - return false; + return nullptr; default: break; } @@ -111,12 +82,12 @@ bool StatisticsPropagator::CanPropagateCast(const LogicalType &source, const Log } case LogicalTypeId::TIMESTAMP_MS: { // Same as above ^ - switch (source.id()) { + switch (input.GetType().id()) { case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIMESTAMP_TZ: case LogicalTypeId::TIMESTAMP_NS: case LogicalTypeId::TIMESTAMP_SEC: - return false; + return nullptr; default: break; } @@ -124,12 +95,12 @@ bool StatisticsPropagator::CanPropagateCast(const LogicalType &source, const Log } case LogicalTypeId::TIMESTAMP_SEC: { // Same as above ^ - switch (source.id()) { + switch (input.GetType().id()) { case LogicalTypeId::TIMESTAMP: case LogicalTypeId::TIMESTAMP_TZ: case LogicalTypeId::TIMESTAMP_NS: case LogicalTypeId::TIMESTAMP_MS: - return false; + return nullptr; default: break; } @@ -138,16 +109,19 @@ bool StatisticsPropagator::CanPropagateCast(const LogicalType &source, const Log default: break; } - // we can propagate! - return true; -} -unique_ptr StatisticsPropagator::TryPropagateCast(BaseStatistics &stats, const LogicalType &source, - const LogicalType &target) { - if (!CanPropagateCast(source, target)) { + switch (target.InternalType()) { + case PhysicalType::INT8: + case PhysicalType::INT16: + case PhysicalType::INT32: + case PhysicalType::INT64: + case PhysicalType::INT128: + case PhysicalType::FLOAT: + case PhysicalType::DOUBLE: + return StatisticsOperationsNumericNumericCast(input, target); + default: return nullptr; } - return StatisticsOperationsNumericNumericCast(stats, target); } unique_ptr StatisticsPropagator::PropagateExpression(BoundCastExpression &cast, @@ -156,7 +130,20 @@ unique_ptr StatisticsPropagator::PropagateExpression(BoundCastEx if (!child_stats) { return nullptr; } - auto result_stats = TryPropagateCast(*child_stats, cast.child->return_type, cast.return_type); + unique_ptr result_stats; + switch (cast.child->return_type.InternalType()) { + case PhysicalType::INT8: + case PhysicalType::INT16: + case PhysicalType::INT32: + case PhysicalType::INT64: + case PhysicalType::INT128: + case PhysicalType::FLOAT: + case PhysicalType::DOUBLE: + result_stats = StatisticsNumericCastSwitch(*child_stats, cast.return_type); + break; + default: + return nullptr; + } if (cast.try_cast && result_stats) { result_stats->Set(StatsInfo::CAN_HAVE_NULL_VALUES); } diff --git a/src/duckdb/src/parallel/pipeline_executor.cpp b/src/duckdb/src/parallel/pipeline_executor.cpp index 71979e374..4b32c99d9 100644 --- a/src/duckdb/src/parallel/pipeline_executor.cpp +++ b/src/duckdb/src/parallel/pipeline_executor.cpp @@ -527,12 +527,9 @@ SourceResultType PipelineExecutor::FetchFromSource(DataChunk &result) { OperatorSourceInput source_input = {*pipeline.source_state, *local_source_state, interrupt_state}; auto res = GetData(result, source_input); - // Ensures sources only return empty results when Blocking or Finished + // Ensures Sinks only return empty results when Blocking or Finished D_ASSERT(res != SourceResultType::BLOCKED || result.size() == 0); - if (res == SourceResultType::FINISHED) { - // final call into the source - finish source execution - context.thread.profiler.FinishSource(*pipeline.source_state, *local_source_state); - } + EndOperator(*pipeline.source, &result); return res; diff --git a/src/duckdb/src/parallel/task_executor.cpp b/src/duckdb/src/parallel/task_executor.cpp index fa2c0087c..10c4a9e92 100644 --- a/src/duckdb/src/parallel/task_executor.cpp +++ b/src/duckdb/src/parallel/task_executor.cpp @@ -63,6 +63,8 @@ BaseExecutorTask::BaseExecutorTask(TaskExecutor &executor) : executor(executor) } TaskExecutionResult BaseExecutorTask::Execute(TaskExecutionMode mode) { + (void)mode; + D_ASSERT(mode == TaskExecutionMode::PROCESS_ALL); if (executor.HasError()) { // another task encountered an error - bailout executor.FinishTask(); diff --git a/src/duckdb/src/parallel/task_scheduler.cpp b/src/duckdb/src/parallel/task_scheduler.cpp index 34e84be72..22bba36a0 100644 --- a/src/duckdb/src/parallel/task_scheduler.cpp +++ b/src/duckdb/src/parallel/task_scheduler.cpp @@ -55,7 +55,6 @@ struct QueueProducerToken { void ConcurrentQueue::Enqueue(ProducerToken &token, shared_ptr task) { lock_guard producer_lock(token.producer_lock); - task->token = token; if (q.enqueue(token.token->queue_token, std::move(task))) { semaphore.signal(); } else { @@ -79,7 +78,6 @@ struct ConcurrentQueue { void ConcurrentQueue::Enqueue(ProducerToken &token, shared_ptr task) { lock_guard lock(qlock); - task->token = token; q[std::ref(*token.token)].push(std::move(task)); } @@ -163,7 +161,6 @@ void TaskScheduler::ExecuteForever(atomic *marker) { #ifndef DUCKDB_NO_THREADS static constexpr const int64_t INITIAL_FLUSH_WAIT = 500000; // initial wait time of 0.5s (in mus) before flushing - auto &config = DBConfig::GetConfig(db); shared_ptr task; // loop until the marker is set to false while (*marker) { @@ -189,21 +186,15 @@ void TaskScheduler::ExecuteForever(atomic *marker) { } } if (queue->q.try_dequeue(task)) { - auto process_mode = config.options.scheduler_process_partial ? TaskExecutionMode::PROCESS_PARTIAL - : TaskExecutionMode::PROCESS_ALL; - auto execute_result = task->Execute(process_mode); + auto execute_result = task->Execute(TaskExecutionMode::PROCESS_ALL); switch (execute_result) { case TaskExecutionResult::TASK_FINISHED: case TaskExecutionResult::TASK_ERROR: task.reset(); break; - case TaskExecutionResult::TASK_NOT_FINISHED: { - // task is not finished - reschedule immediately - auto &token = *task->token; - queue->Enqueue(token, std::move(task)); - break; - } + case TaskExecutionResult::TASK_NOT_FINISHED: + throw InternalException("Task should not return TASK_NOT_FINISHED in PROCESS_ALL mode"); case TaskExecutionResult::TASK_BLOCKED: task->Deschedule(); task.reset(); diff --git a/src/duckdb/src/parallel/thread_context.cpp b/src/duckdb/src/parallel/thread_context.cpp index 15ed6a64c..43a10af00 100644 --- a/src/duckdb/src/parallel/thread_context.cpp +++ b/src/duckdb/src/parallel/thread_context.cpp @@ -7,14 +7,8 @@ namespace duckdb { ThreadContext::ThreadContext(ClientContext &context) : profiler(context) { LoggingContext log_context(LogContextScope::THREAD); - - log_context.connection_id = context.GetConnectionId(); - if (context.transaction.HasActiveTransaction()) { - log_context.transaction_id = context.transaction.ActiveTransaction().global_transaction_id; - log_context.query_id = context.transaction.GetActiveQuery(); - } - - log_context.thread_id = TaskScheduler::GetEstimatedCPUId(); + log_context.client_context = reinterpret_cast(&context); + log_context.thread = TaskScheduler::GetEstimatedCPUId(); if (context.transaction.HasActiveTransaction()) { log_context.transaction_id = context.transaction.GetActiveQuery(); } diff --git a/src/duckdb/src/parser/expression/star_expression.cpp b/src/duckdb/src/parser/expression/star_expression.cpp index f18aee0a9..22279f121 100644 --- a/src/duckdb/src/parser/expression/star_expression.cpp +++ b/src/duckdb/src/parser/expression/star_expression.cpp @@ -1,5 +1,4 @@ #include "duckdb/parser/expression/star_expression.hpp" -#include "duckdb/parser/expression/operator_expression.hpp" #include "duckdb/common/exception.hpp" @@ -14,6 +13,10 @@ StarExpression::StarExpression(string relation_name_p) string StarExpression::ToString() const { string result; + if (unpacked) { + D_ASSERT(columns); + result += "*"; + } if (expr) { D_ASSERT(columns); result += "COLUMNS(" + expr->ToString() + ")"; @@ -76,6 +79,9 @@ bool StarExpression::Equal(const StarExpression &a, const StarExpression &b) { if (a.columns != b.columns) { return false; } + if (a.unpacked != b.unpacked) { + return false; + } if (a.replace_list.size() != b.replace_list.size()) { return false; } @@ -107,36 +113,15 @@ bool StarExpression::IsColumns(const ParsedExpression &a) { return false; } auto &star = a.Cast(); - return star.columns == true; + return star.columns == true && star.unpacked == false; } bool StarExpression::IsColumnsUnpacked(const ParsedExpression &a) { - if (a.GetExpressionType() != ExpressionType::OPERATOR_UNPACK) { + if (a.GetExpressionClass() != ExpressionClass::STAR) { return false; } - return true; -} - -unique_ptr -StarExpression::DeserializeStarExpression(string &&relation_name, const case_insensitive_set_t &exclude_list, - case_insensitive_map_t> &&replace_list, - bool columns, unique_ptr expr, bool unpacked, - const qualified_column_set_t &qualified_exclude_list, - qualified_column_map_t &&rename_list) { - auto result = duckdb::unique_ptr(new StarExpression(exclude_list, qualified_exclude_list)); - result->relation_name = std::move(relation_name); - result->replace_list = std::move(replace_list); - result->columns = columns; - result->expr = std::move(expr); - result->rename_list = std::move(rename_list); - if (unpacked) { - //! This was previously a member of StarExpression, but not anymore - //! We wrap it into an OPERATOR_UNPACK instead - vector> unpack_children; - unpack_children.push_back(std::move(result)); - return make_uniq(ExpressionType::OPERATOR_UNPACK, std::move(unpack_children)); - } - return std::move(result); + auto &star = a.Cast(); + return star.columns == true && star.unpacked == true; } unique_ptr StarExpression::Copy() const { @@ -149,6 +134,7 @@ unique_ptr StarExpression::Copy() const { copy->columns = columns; copy->expr = expr ? expr->Copy() : nullptr; copy->CopyProperties(*this); + copy->unpacked = unpacked; return std::move(copy); } diff --git a/src/duckdb/src/parser/parsed_data/alter_table_info.cpp b/src/duckdb/src/parser/parsed_data/alter_table_info.cpp index 01bdc4da9..ddf7db07d 100644 --- a/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +++ b/src/duckdb/src/parser/parsed_data/alter_table_info.cpp @@ -131,44 +131,6 @@ string RenameColumnInfo::ToString() const { return result; } -//===--------------------------------------------------------------------===// -// RenameFieldInfo -//===--------------------------------------------------------------------===// -RenameFieldInfo::RenameFieldInfo(AlterEntryData data, vector column_path_p, string new_name_p) - : AlterTableInfo(AlterTableType::RENAME_FIELD, std::move(data)), column_path(std::move(column_path_p)), - new_name(std::move(new_name_p)) { -} - -RenameFieldInfo::RenameFieldInfo() : AlterTableInfo(AlterTableType::RENAME_FIELD) { -} - -RenameFieldInfo::~RenameFieldInfo() { -} - -unique_ptr RenameFieldInfo::Copy() const { - return make_uniq_base(GetAlterEntryData(), column_path, new_name); -} - -string RenameFieldInfo::ToString() const { - string result = ""; - result += "ALTER TABLE "; - if (if_not_found == OnEntryNotFound::RETURN_NULL) { - result += " IF EXISTS"; - } - result += QualifierToString(catalog, schema, name); - result += " RENAME COLUMN "; - for (idx_t i = 0; i < column_path.size(); i++) { - if (i > 0) { - result += "."; - } - result += KeywordHelper::WriteOptionallyQuoted(column_path[i]); - } - result += " TO "; - result += KeywordHelper::WriteOptionallyQuoted(new_name); - result += ";"; - return result; -} - //===--------------------------------------------------------------------===// // RenameTableInfo //===--------------------------------------------------------------------===// @@ -229,48 +191,7 @@ string AddColumnInfo::ToString() const { if (if_column_not_exists) { result += " IF NOT EXISTS"; } - throw NotImplementedException("FIXME: column definition to string"); - result += ";"; - return result; -} - -//===--------------------------------------------------------------------===// -// AddFieldInfo -//===--------------------------------------------------------------------===// -AddFieldInfo::AddFieldInfo(ColumnDefinition new_field_p) - : AlterTableInfo(AlterTableType::ADD_FIELD), new_field(std::move(new_field_p)) { -} - -AddFieldInfo::AddFieldInfo(AlterEntryData data, vector column_path_p, ColumnDefinition new_field_p, - bool if_field_not_exists) - : AlterTableInfo(AlterTableType::ADD_FIELD, std::move(data)), column_path(std::move(column_path_p)), - new_field(std::move(new_field_p)), if_field_not_exists(if_field_not_exists) { -} - -AddFieldInfo::~AddFieldInfo() { -} - -unique_ptr AddFieldInfo::Copy() const { - return make_uniq_base(GetAlterEntryData(), column_path, new_field.Copy(), - if_field_not_exists); -} - -string AddFieldInfo::ToString() const { - string result = ""; - result += "ALTER TABLE "; - if (if_not_found == OnEntryNotFound::RETURN_NULL) { - result += " IF EXISTS"; - } - result += QualifierToString(catalog, schema, name); - result += " ADD COLUMN"; - if (if_field_not_exists) { - result += " IF NOT EXISTS"; - } - for (auto &path : column_path) { - result += KeywordHelper::WriteOptionallyQuoted(path); - result += "."; - } - throw NotImplementedException("FIXME: column definition to string"); + throw NotImplementedException("COLUMN SERIALIZATION"); result += ";"; return result; } @@ -311,47 +232,6 @@ string RemoveColumnInfo::ToString() const { return result; } -//===--------------------------------------------------------------------===// -// RemoveFieldInfo -//===--------------------------------------------------------------------===// -RemoveFieldInfo::RemoveFieldInfo() : AlterTableInfo(AlterTableType::REMOVE_FIELD) { -} - -RemoveFieldInfo::RemoveFieldInfo(AlterEntryData data, vector column_path_p, bool if_column_exists, bool cascade) - : AlterTableInfo(AlterTableType::REMOVE_FIELD, std::move(data)), column_path(std::move(column_path_p)), - if_column_exists(if_column_exists), cascade(cascade) { -} -RemoveFieldInfo::~RemoveFieldInfo() { -} - -unique_ptr RemoveFieldInfo::Copy() const { - return make_uniq_base(GetAlterEntryData(), column_path, if_column_exists, cascade); -} - -string RemoveFieldInfo::ToString() const { - string result = ""; - result += "ALTER TABLE "; - if (if_not_found == OnEntryNotFound::RETURN_NULL) { - result += " IF EXISTS"; - } - result += QualifierToString(catalog, schema, name); - result += " DROP COLUMN "; - if (if_column_exists) { - result += "IF EXISTS "; - } - for (idx_t i = 0; i < column_path.size(); i++) { - if (i > 0) { - result += "."; - } - result += KeywordHelper::WriteOptionallyQuoted(column_path[i]); - } - if (cascade) { - result += " CASCADE"; - } - result += ";"; - return result; -} - //===--------------------------------------------------------------------===// // ChangeColumnTypeInfo //===--------------------------------------------------------------------===// @@ -593,82 +473,4 @@ string AddConstraintInfo::ToString() const { return result; } -//===--------------------------------------------------------------------===// -// SetPartitionedByInfo -//===--------------------------------------------------------------------===// -SetPartitionedByInfo::SetPartitionedByInfo() : AlterTableInfo(AlterTableType::SET_PARTITIONED_BY) { -} - -SetPartitionedByInfo::SetPartitionedByInfo(AlterEntryData data, vector> partition_keys_p) - : AlterTableInfo(AlterTableType::SET_PARTITIONED_BY, std::move(data)), partition_keys(std::move(partition_keys_p)) { -} - -SetPartitionedByInfo::~SetPartitionedByInfo() { -} - -unique_ptr SetPartitionedByInfo::Copy() const { - vector> copied_partition_keys; - for (auto &partition_key : partition_keys) { - copied_partition_keys.push_back(partition_key->Copy()); - } - return make_uniq_base(GetAlterEntryData(), std::move(copied_partition_keys)); -} - -string SetPartitionedByInfo::ToString() const { - string result = "ALTER TABLE "; - result += QualifierToString(catalog, schema, name); - if (partition_keys.empty()) { - result += " RESET PARTITIONED BY"; - } else { - result += " SET PARTITIONED BY ("; - for (idx_t i = 0; i < partition_keys.size(); i++) { - if (i > 0) { - result += ", "; - } - result += partition_keys[i]->ToString(); - } - result += ")"; - } - return result; -} - -//===--------------------------------------------------------------------===// -// SetSortedByInfo -//===--------------------------------------------------------------------===// -SetSortedByInfo::SetSortedByInfo() : AlterTableInfo(AlterTableType::SET_SORTED_BY) { -} - -SetSortedByInfo::SetSortedByInfo(AlterEntryData data, vector orders_p) - : AlterTableInfo(AlterTableType::SET_SORTED_BY, std::move(data)), orders(std::move(orders_p)) { -} - -SetSortedByInfo::~SetSortedByInfo() { -} - -unique_ptr SetSortedByInfo::Copy() const { - vector copied_orders; - for (auto &order_key : orders) { - copied_orders.emplace_back(order_key.type, order_key.null_order, order_key.expression->Copy()); - } - return make_uniq_base(GetAlterEntryData(), std::move(copied_orders)); -} - -string SetSortedByInfo::ToString() const { - string result = "ALTER TABLE "; - result += QualifierToString(catalog, schema, name); - if (orders.empty()) { - result += " RESET SORTED BY"; - } else { - result += " SET SORTED BY ("; - for (idx_t i = 0; i < orders.size(); i++) { - if (i > 0) { - result += ", "; - } - result += orders[i].ToString(); - } - result += ")"; - } - return result; -} - } // namespace duckdb diff --git a/src/duckdb/src/parser/parsed_data/attach_info.cpp b/src/duckdb/src/parser/parsed_data/attach_info.cpp index 76bd2eefb..99dc347e2 100644 --- a/src/duckdb/src/parser/parsed_data/attach_info.cpp +++ b/src/duckdb/src/parser/parsed_data/attach_info.cpp @@ -38,8 +38,6 @@ string AttachInfo::ToString() const { result += "ATTACH"; if (on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT) { result += " IF NOT EXISTS"; - } else if (on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) { - result += " OR REPLACE"; } result += " DATABASE"; result += KeywordHelper::WriteQuoted(path, '\''); diff --git a/src/duckdb/src/parser/parsed_data/comment_on_column_info.cpp b/src/duckdb/src/parser/parsed_data/comment_on_column_info.cpp index d16b3cf45..4bc332482 100644 --- a/src/duckdb/src/parser/parsed_data/comment_on_column_info.cpp +++ b/src/duckdb/src/parser/parsed_data/comment_on_column_info.cpp @@ -35,8 +35,7 @@ string SetColumnCommentInfo::ToString() const { } optional_ptr SetColumnCommentInfo::TryResolveCatalogEntry(CatalogEntryRetriever &retriever) { - EntryLookupInfo lookup_info(CatalogType::TABLE_ENTRY, name); - auto entry = retriever.GetEntry(catalog, schema, lookup_info, if_not_found); + auto entry = retriever.GetEntry(CatalogType::TABLE_ENTRY, catalog, schema, name, if_not_found); if (entry) { catalog_entry_type = entry->type; diff --git a/src/duckdb/src/parser/parsed_data/create_function_info.cpp b/src/duckdb/src/parser/parsed_data/create_function_info.cpp index bcdd3bd5e..2c3dde835 100644 --- a/src/duckdb/src/parser/parsed_data/create_function_info.cpp +++ b/src/duckdb/src/parser/parsed_data/create_function_info.cpp @@ -11,7 +11,6 @@ CreateFunctionInfo::CreateFunctionInfo(CatalogType type, string schema) : Create void CreateFunctionInfo::CopyFunctionProperties(CreateFunctionInfo &other) const { CopyProperties(other); other.name = name; - other.alias_of = alias_of; other.descriptions = descriptions; } diff --git a/src/duckdb/src/parser/parsed_data/create_secret_info.cpp b/src/duckdb/src/parser/parsed_data/create_secret_info.cpp index afa50cf60..55f8bd020 100644 --- a/src/duckdb/src/parser/parsed_data/create_secret_info.cpp +++ b/src/duckdb/src/parser/parsed_data/create_secret_info.cpp @@ -1,5 +1,5 @@ #include "duckdb/parser/parsed_data/create_secret_info.hpp" -#include "duckdb/parser/parsed_expression.hpp" + #include "duckdb/parser/parsed_data/create_info.hpp" namespace duckdb { @@ -8,29 +8,14 @@ CreateSecretInfo::CreateSecretInfo(OnCreateConflict on_conflict, SecretPersistTy : CreateInfo(CatalogType::SECRET_ENTRY), on_conflict(on_conflict), persist_type(persist_type), options() { } -CreateSecretInfo::~CreateSecretInfo() { -} - unique_ptr CreateSecretInfo::Copy() const { auto result = make_uniq(on_conflict, persist_type); - + result->type = type; result->storage_type = storage_type; + result->provider = provider; result->name = name; - - if (type) { - result->type = type->Copy(); - } - if (provider) { - result->provider = provider->Copy(); - } - if (scope) { - result->scope = scope->Copy(); - } - - for (const auto &option : options) { - result->options.insert(make_pair(option.first, option.second->Copy())); - } - + result->scope = scope; + result->options = options; return std::move(result); } diff --git a/src/duckdb/src/parser/parsed_data/exported_table_data.cpp b/src/duckdb/src/parser/parsed_data/exported_table_data.cpp index a4b66578d..d3573bc0a 100644 --- a/src/duckdb/src/parser/parsed_data/exported_table_data.cpp +++ b/src/duckdb/src/parser/parsed_data/exported_table_data.cpp @@ -1,6 +1,5 @@ #include "duckdb/parser/parsed_data/exported_table_data.hpp" #include "duckdb/catalog/catalog.hpp" -#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" namespace duckdb { @@ -15,8 +14,9 @@ ExportedTableInfo::ExportedTableInfo(ClientContext &context, ExportedTableData t } TableCatalogEntry &ExportedTableInfo::GetEntry(ClientContext &context, const ExportedTableData &table_data) { - return Catalog::GetEntry(context, table_data.database_name, table_data.schema_name, - table_data.table_name); + return Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, table_data.database_name, table_data.schema_name, + table_data.table_name) + .Cast(); } } // namespace duckdb diff --git a/src/duckdb/src/parser/parser.cpp b/src/duckdb/src/parser/parser.cpp index c9c9b0a6e..77ad899f1 100644 --- a/src/duckdb/src/parser/parser.cpp +++ b/src/duckdb/src/parser/parser.cpp @@ -296,12 +296,10 @@ void Parser::ParseQuery(const string &query) { auto &last_statement = statements.back(); last_statement->stmt_length = query.size() - last_statement->stmt_location; for (auto &statement : statements) { - statement->query = query.substr(statement->stmt_location, statement->stmt_length); - statement->stmt_location = 0; - statement->stmt_length = statement->query.size(); + statement->query = query; if (statement->type == StatementType::CREATE_STATEMENT) { auto &create = statement->Cast(); - create.info->sql = statement->query; + create.info->sql = query.substr(statement->stmt_location, statement->stmt_length); } } } diff --git a/src/duckdb/src/parser/query_error_context.cpp b/src/duckdb/src/parser/query_error_context.cpp index 44defbce0..f8545714e 100644 --- a/src/duckdb/src/parser/query_error_context.cpp +++ b/src/duckdb/src/parser/query_error_context.cpp @@ -2,14 +2,11 @@ #include "duckdb/parser/sql_statement.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/common/to_string.hpp" -#include "duckdb/parser/parsed_expression.hpp" + #include "utf8proc_wrapper.hpp" namespace duckdb { -QueryErrorContext::QueryErrorContext(const ParsedExpression &expr) : query_location(expr.query_location) { -} - string QueryErrorContext::Format(const string &query, const string &error_message, optional_idx error_loc, bool add_line_indicator) { static constexpr idx_t MAX_LINE_RENDER_WIDTH = 120; diff --git a/src/duckdb/src/parser/query_node.cpp b/src/duckdb/src/parser/query_node.cpp index d68e1169d..7b084c5c8 100644 --- a/src/duckdb/src/parser/query_node.cpp +++ b/src/duckdb/src/parser/query_node.cpp @@ -20,9 +20,6 @@ CommonTableExpressionMap CommonTableExpressionMap::Copy() const { for (auto &al : kv.second->aliases) { kv_info->aliases.push_back(al); } - for (auto &al : kv.second->key_targets) { - kv_info->key_targets.push_back(al->Copy()); - } kv_info->query = unique_ptr_cast(kv.second->query->Copy()); kv_info->materialized = kv.second->materialized; res.map[kv.first] = std::move(kv_info); @@ -65,16 +62,6 @@ string CommonTableExpressionMap::ToString() const { } result += ")"; } - if (!cte.key_targets.empty()) { - result += " USING KEY ("; - for (idx_t k = 0; k < cte.key_targets.size(); k++) { - if (k > 0) { - result += ", "; - } - result += cte.key_targets[k]->ToString(); - } - result += ") "; - } if (kv.second->materialized == CTEMaterialize::CTE_MATERIALIZE_ALWAYS) { result += " AS MATERIALIZED ("; } else if (kv.second->materialized == CTEMaterialize::CTE_MATERIALIZE_NEVER) { @@ -156,9 +143,6 @@ bool QueryNode::Equals(const QueryNode *other) const { if (entry.second->aliases != other->cte_map.map.at(entry.first)->aliases) { return false; } - if (!ParsedExpression::ListEquals(entry.second->key_targets, other_entry->second->key_targets)) { - return false; - } if (!entry.second->query->Equals(*other->cte_map.map.at(entry.first)->query)) { return false; } @@ -175,9 +159,6 @@ void QueryNode::CopyProperties(QueryNode &other) const { for (auto &al : kv.second->aliases) { kv_info->aliases.push_back(al); } - for (auto &key : kv.second->key_targets) { - kv_info->key_targets.push_back(key->Copy()); - } kv_info->query = unique_ptr_cast(kv.second->query->Copy()); kv_info->materialized = kv.second->materialized; other.cte_map.map[kv.first] = std::move(kv_info); diff --git a/src/duckdb/src/parser/query_node/recursive_cte_node.cpp b/src/duckdb/src/parser/query_node/recursive_cte_node.cpp index 993c38f6b..120547e6c 100644 --- a/src/duckdb/src/parser/query_node/recursive_cte_node.cpp +++ b/src/duckdb/src/parser/query_node/recursive_cte_node.cpp @@ -28,11 +28,6 @@ bool RecursiveCTENode::Equals(const QueryNode *other_p) const { if (other.union_all != union_all) { return false; } - - if (!ParsedExpression::ListEquals(key_targets, other.key_targets)) { - return false; - } - if (!left->Equals(other.left.get())) { return false; } @@ -49,11 +44,6 @@ unique_ptr RecursiveCTENode::Copy() const { result->left = left->Copy(); result->right = right->Copy(); result->aliases = aliases; - - for (auto &key : key_targets) { - result->key_targets.push_back(key->Copy()); - } - this->CopyProperties(*result); return std::move(result); } diff --git a/src/duckdb/src/parser/tableref.cpp b/src/duckdb/src/parser/tableref.cpp index b97f7ecb4..9ce290237 100644 --- a/src/duckdb/src/parser/tableref.cpp +++ b/src/duckdb/src/parser/tableref.cpp @@ -13,8 +13,7 @@ string TableRef::BaseToString(string result) const { return BaseToString(std::move(result), column_name_alias); } -string TableRef::AliasToString(const vector &column_name_alias) const { - string result; +string TableRef::BaseToString(string result, const vector &column_name_alias) const { if (!alias.empty()) { result += StringUtil::Format(" AS %s", SQLIdentifier(alias)); } @@ -29,11 +28,6 @@ string TableRef::AliasToString(const vector &column_name_alias) const { } result += ")"; } - return result; -} - -string TableRef::SampleToString() const { - string result; if (sample) { result += " TABLESAMPLE " + EnumUtil::ToString(sample->method); result += "(" + sample->sample_size.ToString() + " " + string(sample->is_percentage ? "PERCENT" : "ROWS") + ")"; @@ -41,12 +35,7 @@ string TableRef::SampleToString() const { result += "REPEATABLE (" + to_string(sample->seed.GetIndex()) + ")"; } } - return result; -} -string TableRef::BaseToString(string result, const vector &column_name_alias) const { - result += AliasToString(column_name_alias); - result += SampleToString(); return result; } diff --git a/src/duckdb/src/parser/tableref/basetableref.cpp b/src/duckdb/src/parser/tableref/basetableref.cpp index 205cd13f6..a39c07ec7 100644 --- a/src/duckdb/src/parser/tableref/basetableref.cpp +++ b/src/duckdb/src/parser/tableref/basetableref.cpp @@ -11,12 +11,7 @@ string BaseTableRef::ToString() const { result += catalog_name.empty() ? "" : (KeywordHelper::WriteOptionallyQuoted(catalog_name) + "."); result += schema_name.empty() ? "" : (KeywordHelper::WriteOptionallyQuoted(schema_name) + "."); result += KeywordHelper::WriteOptionallyQuoted(table_name); - result += AliasToString(column_name_alias); - if (at_clause) { - result += " " + at_clause->ToString(); - } - result += SampleToString(); - return result; + return BaseToString(result, column_name_alias); } bool BaseTableRef::Equals(const TableRef &other_p) const { @@ -25,7 +20,7 @@ bool BaseTableRef::Equals(const TableRef &other_p) const { } auto &other = other_p.Cast(); return other.catalog_name == catalog_name && other.schema_name == schema_name && other.table_name == table_name && - column_name_alias == other.column_name_alias && AtClause::Equals(at_clause.get(), other.at_clause.get()); + column_name_alias == other.column_name_alias; } unique_ptr BaseTableRef::Copy() { @@ -35,7 +30,6 @@ unique_ptr BaseTableRef::Copy() { copy->schema_name = schema_name; copy->table_name = table_name; copy->column_name_alias = column_name_alias; - copy->at_clause = at_clause ? at_clause->Copy() : nullptr; CopyProperties(*copy); return std::move(copy); diff --git a/src/duckdb/src/parser/transform/expression/transform_columnref.cpp b/src/duckdb/src/parser/transform/expression/transform_columnref.cpp index 21ec022b7..dfbbc6f12 100644 --- a/src/duckdb/src/parser/transform/expression/transform_columnref.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_columnref.cpp @@ -107,6 +107,7 @@ unique_ptr Transformer::TransformStarExpression(duckdb_libpgqu } } result->columns = star.columns; + result->unpacked = star.unpacked; SetQueryLocation(*result, star.location); return std::move(result); } diff --git a/src/duckdb/src/parser/transform/expression/transform_function.cpp b/src/duckdb/src/parser/transform/expression/transform_function.cpp index 45e41dde9..6684d489e 100644 --- a/src/duckdb/src/parser/transform/expression/transform_function.cpp +++ b/src/duckdb/src/parser/transform/expression/transform_function.cpp @@ -1,9 +1,9 @@ #include "duckdb/common/enum_util.hpp" #include "duckdb/common/string_util.hpp" #include "duckdb/parser/expression/case_expression.hpp" -#include "duckdb/parser/expression/cast_expression.hpp" #include "duckdb/parser/expression/constant_expression.hpp" #include "duckdb/parser/expression/function_expression.hpp" + #include "duckdb/parser/expression/operator_expression.hpp" #include "duckdb/parser/expression/star_expression.hpp" #include "duckdb/parser/expression/window_expression.hpp" @@ -365,20 +365,6 @@ unique_ptr Transformer::TransformFuncCall(duckdb_libpgquery::P expr->case_checks.push_back(std::move(check)); expr->else_expr = std::move(children[2]); return std::move(expr); - } else if (lowercase_name == "unpack") { - if (children.size() != 1) { - throw ParserException("Wrong number of arguments to the UNPACK operator"); - } - auto expr = make_uniq(ExpressionType::OPERATOR_UNPACK); - expr->children = std::move(children); - return std::move(expr); - } else if (lowercase_name == "try") { - if (children.size() != 1) { - throw ParserException("Wrong number of arguments provided to TRY expression"); - } - auto try_expression = make_uniq(ExpressionType::OPERATOR_TRY); - try_expression->children = std::move(children); - return std::move(try_expression); } else if (lowercase_name == "construct_array") { auto construct_array = make_uniq(ExpressionType::ARRAY_CONSTRUCTOR); construct_array->children = std::move(children); @@ -423,11 +409,6 @@ unique_ptr Transformer::TransformFuncCall(duckdb_libpgquery::P children.emplace_back(std::move(sense)); children.emplace_back(std::move(nulls)); } - } else if (lowercase_name == "date") { - if (children.size() != 1) { - throw ParserException("Wrong number of arguments provided to DATE function"); - } - return std::move(make_uniq(LogicalType::DATE, std::move(children[0]))); } auto function = make_uniq(std::move(catalog), std::move(schema), lowercase_name.c_str(), diff --git a/src/duckdb/src/parser/transform/helpers/transform_cte.cpp b/src/duckdb/src/parser/transform/helpers/transform_cte.cpp index 7f1e43dfe..a344d730e 100644 --- a/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +++ b/src/duckdb/src/parser/transform/helpers/transform_cte.cpp @@ -11,11 +11,6 @@ unique_ptr CommonTableExpressionInfo::Copy() { auto result = make_uniq(); result->aliases = aliases; result->query = unique_ptr_cast(query->Copy()); - - for (auto &key : result->key_targets) { - result->key_targets.push_back(key->Copy()); - } - result->materialized = materialized; return result; } @@ -45,12 +40,6 @@ void Transformer::TransformCTE(duckdb_libpgquery::PGWithClause &de_with_clause, auto info = make_uniq(); auto &cte = *PGPointerCast(cte_ele->data.ptr_value); - - auto key_target = PGPointerCast(cte.recursive_keys->head->data.ptr_value); - if (key_target) { - TransformExpressionList(*cte.recursive_keys, info->key_targets); - } - if (cte.aliascolnames) { for (auto node = cte.aliascolnames->head; node != nullptr; node = node->next) { auto value = PGPointerCast(node->data.ptr_value); @@ -127,9 +116,6 @@ unique_ptr Transformer::TransformRecursiveCTE(duckdb_libpgquery result.left = TransformSelectNode(*stmt.larg); result.right = TransformSelectNode(*stmt.rarg); result.aliases = info.aliases; - for (auto &key : info.key_targets) { - result.key_targets.emplace_back(key->Copy()); - } break; } case duckdb_libpgquery::PG_SETOP_EXCEPT: diff --git a/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp b/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp index 7fb15a90d..2537daaec 100644 --- a/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp @@ -10,14 +10,6 @@ OnEntryNotFound Transformer::TransformOnEntryNotFound(bool missing_ok) { return missing_ok ? OnEntryNotFound::RETURN_NULL : OnEntryNotFound::THROW_EXCEPTION; } -vector Transformer::TransformNameList(duckdb_libpgquery::PGList &list) { - vector result; - for (auto c = list.head; c != nullptr; c = c->next) { - result.emplace_back(static_cast(c->data.ptr_value)); - } - return result; -} - unique_ptr Transformer::TransformAlter(duckdb_libpgquery::PGAlterTableStmt &stmt) { D_ASSERT(stmt.relation); @@ -37,14 +29,14 @@ unique_ptr Transformer::TransformAlter(duckdb_libpgquery::PGAlte switch (command->subtype) { case duckdb_libpgquery::PG_AT_AddColumn: { - auto column_name_list = PGPointerCast(command->def_list->head->data.ptr_value); - auto column_def = PGPointerCast(command->def_list->tail->data.ptr_value); + auto column_def = PGPointerCast(command->def); if (stmt.relkind != duckdb_libpgquery::PG_OBJECT_TABLE) { throw ParserException("Adding columns is only supported for tables"); } if (column_def->category == duckdb_libpgquery::COL_GENERATED) { throw ParserException("Adding generated columns after table creation is not supported yet"); } + auto column_entry = TransformColumnDefinition(*column_def); if (column_def->constraints) { for (auto cell = column_def->constraints->head; cell != nullptr; cell = cell->next) { @@ -56,20 +48,7 @@ unique_ptr Transformer::TransformAlter(duckdb_libpgquery::PGAlte throw ParserException("Adding columns with constraints not yet supported"); } } - auto column_names = TransformNameList(*column_name_list); - if (column_names.empty()) { - throw InternalException("Expected a name"); - } - column_entry.SetName(column_names.back()); - if (column_names.size() == 1) { - // ADD COLUMN - result->info = make_uniq(std::move(data), std::move(column_entry), command->missing_ok); - } else { - // ADD FIELD - column_names.pop_back(); - result->info = make_uniq(std::move(data), std::move(column_names), - std::move(column_entry), command->missing_ok); - } + result->info = make_uniq(std::move(data), std::move(column_entry), command->missing_ok); break; } case duckdb_libpgquery::PG_AT_DropColumn: { @@ -77,17 +56,7 @@ unique_ptr Transformer::TransformAlter(duckdb_libpgquery::PGAlte if (stmt.relkind != duckdb_libpgquery::PG_OBJECT_TABLE) { throw ParserException("Dropping columns is only supported for tables"); } - auto column_names = TransformNameList(*command->def_list); - if (column_names.empty()) { - throw InternalException("Expected a name"); - } - if (column_names.size() == 1) { - result->info = - make_uniq(std::move(data), column_names[0], command->missing_ok, cascade); - } else { - result->info = - make_uniq(std::move(data), std::move(column_names), command->missing_ok, cascade); - } + result->info = make_uniq(std::move(data), command->name, command->missing_ok, cascade); break; } case duckdb_libpgquery::PG_AT_ColumnDefault: { @@ -139,22 +108,6 @@ unique_ptr Transformer::TransformAlter(duckdb_libpgquery::PGAlte result->info = make_uniq(std::move(data), std::move(constraint)); break; } - case duckdb_libpgquery::PG_AT_SetPartitionedBy: { - vector> partition_keys; - if (command->def_list) { - TransformExpressionList(*command->def_list, partition_keys); - } - result->info = make_uniq(std::move(data), std::move(partition_keys)); - break; - } - case duckdb_libpgquery::PG_AT_SetSortedBy: { - vector orders; - if (command->def_list) { - TransformOrderBy(command->def_list, orders); - } - result->info = make_uniq(std::move(data), std::move(orders)); - break; - } default: throw NotImplementedException("No support for that ALTER TABLE option yet!"); } diff --git a/src/duckdb/src/parser/transform/statement/transform_create_table_as.cpp b/src/duckdb/src/parser/transform/statement/transform_create_table_as.cpp index e8a9d83ec..3770194a7 100644 --- a/src/duckdb/src/parser/transform/statement/transform_create_table_as.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_create_table_as.cpp @@ -1,8 +1,5 @@ #include "duckdb/parser/statement/create_statement.hpp" -#include "duckdb/parser/expression/constant_expression.hpp" #include "duckdb/parser/parsed_data/create_table_info.hpp" -#include "duckdb/parser/query_node/select_node.hpp" -#include "duckdb/parser/tableref/subqueryref.hpp" #include "duckdb/parser/transformer.hpp" namespace duckdb { @@ -23,19 +20,6 @@ unique_ptr Transformer::TransformCreateTableAs(duckdb_libpgquer auto qname = TransformQualifiedName(*stmt.into->rel); auto query = TransformSelectStmt(*stmt.query, false); - // push a LIMIT 0 if 'WITH NO DATA' is specified - if (stmt.into->skipData) { - auto limit_modifier = make_uniq(); - limit_modifier->limit = make_uniq(Value::BIGINT(0)); - auto limit_node = make_uniq(); - limit_node->modifiers.push_back(std::move(limit_modifier)); - limit_node->from_table = make_uniq(std::move(query)); - limit_node->select_list.push_back(make_uniq()); - auto limit_stmt = make_uniq(); - limit_stmt->node = std::move(limit_node); - query = std::move(limit_stmt); - } - if (stmt.into->colNames) { auto cols = TransformStringList(stmt.into->colNames); for (idx_t i = 0; i < cols.size(); i++) { diff --git a/src/duckdb/src/parser/transform/statement/transform_rename.cpp b/src/duckdb/src/parser/transform/statement/transform_rename.cpp index 3526205e7..25b72d85a 100644 --- a/src/duckdb/src/parser/transform/statement/transform_rename.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_rename.cpp @@ -23,13 +23,9 @@ unique_ptr Transformer::TransformRename(duckdb_libpgquery::PGRen // change column name // get the old name and the new name - auto names = TransformNameList(*stmt.name_list); + string old_name = stmt.subname; string new_name = stmt.newname; - if (names.size() == 1) { - info = make_uniq(std::move(data), std::move(names[0]), std::move(new_name)); - } else { - info = make_uniq(std::move(data), std::move(names), std::move(new_name)); - } + info = make_uniq(std::move(data), old_name, new_name); break; } case duckdb_libpgquery::PG_OBJECT_TABLE: { diff --git a/src/duckdb/src/parser/transform/statement/transform_secret.cpp b/src/duckdb/src/parser/transform/statement/transform_secret.cpp index bde6c38f7..f9f13b088 100644 --- a/src/duckdb/src/parser/transform/statement/transform_secret.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_secret.cpp @@ -6,16 +6,6 @@ namespace duckdb { -static Value GetConstantExpressionValue(ParsedExpression &expr) { - if (expr.type == ExpressionType::VALUE_CONSTANT) { - return expr.Cast().value; - } - if (expr.type == ExpressionType::COLUMN_REF) { - return expr.Cast().GetName(); - } - return Value(); -} - void Transformer::TransformCreateSecretOptions(CreateSecretInfo &info, optional_ptr options) { if (!options) { @@ -23,42 +13,59 @@ void Transformer::TransformCreateSecretOptions(CreateSecretInfo &info, } duckdb_libpgquery::PGListCell *cell; - // iterate over each option for_each_cell(cell, options->head) { auto def_elem = PGPointerCast(cell->data.ptr_value); auto lower_name = StringUtil::Lower(def_elem->defname); if (lower_name == "scope") { - info.scope = TransformExpression(def_elem->arg); + // format specifier: interpret this option + auto scope_val = PGPointerCast(def_elem->arg); + if (!scope_val) { + throw ParserException("Unsupported parameter type for SCOPE"); + } else if (scope_val->type == duckdb_libpgquery::T_PGString) { + info.scope.push_back(scope_val->val.str); + continue; + } else if (scope_val->type != duckdb_libpgquery::T_PGList) { + throw ParserException("%s has to be a string, or a list of strings", lower_name); + } + + auto list = PGPointerCast(def_elem->arg); + for (auto scope_cell = list->head; scope_cell != nullptr; scope_cell = lnext(scope_cell)) { + auto scope_val_entry = PGPointerCast(scope_cell->data.ptr_value); + info.scope.push_back(scope_val_entry->val.str); + } continue; - } - if (lower_name == "type") { - info.type = TransformExpression(def_elem->arg); - if (info.type->type == ExpressionType::COLUMN_REF) { - info.type = make_uniq(GetConstantExpressionValue(*info.type)); + } else if (lower_name == "type") { + auto type_val = PGPointerCast(def_elem->arg); + if (type_val->type != duckdb_libpgquery::T_PGString) { + throw ParserException("%s has to be a string", lower_name); } + info.type = StringUtil::Lower(type_val->val.str); continue; - } - if (lower_name == "provider") { - info.provider = TransformExpression(def_elem->arg); - if (info.provider->type == ExpressionType::COLUMN_REF) { - info.provider = make_uniq(GetConstantExpressionValue(*info.provider)); + } else if (lower_name == "provider") { + auto provider_val = PGPointerCast(def_elem->arg); + if (provider_val->type != duckdb_libpgquery::T_PGString) { + throw ParserException("%s has to be a string", lower_name); } + info.provider = StringUtil::Lower(provider_val->val.str); continue; } // All the other options end up in the generic - case_insensitive_map_t> vector_options; + case_insensitive_map_t> vector_options; + ParseGenericOptionListEntry(vector_options, lower_name, def_elem->arg); - if (info.options.find(lower_name) != info.options.end()) { - throw BinderException("Duplicate query param found while parsing create secret: '%s'", lower_name); - } + for (const auto &entry : vector_options) { + if (entry.second.size() != 1) { + throw ParserException("Invalid parameter passed to option '%s'", entry.first); + } - auto expr = TransformExpression(def_elem->arg); - if (expr->type == ExpressionType::COLUMN_REF) { - expr = make_uniq(GetConstantExpressionValue(*expr)); + if (info.options.find(entry.first) != info.options.end()) { + throw BinderException("Duplicate query param found while parsing create secret: '%s'", entry.first); + } + + info.options[entry.first] = entry.second.at(0); } - info.options[lower_name] = std::move(expr); } } @@ -81,17 +88,11 @@ unique_ptr Transformer::TransformSecret(duckdb_libpgquery::PGCr TransformCreateSecretOptions(*create_secret_info, stmt.options); } - if (!create_secret_info->type) { + if (create_secret_info->type.empty()) { throw ParserException("Failed to create secret - secret must have a type defined"); } if (create_secret_info->name.empty()) { - auto value = GetConstantExpressionValue(*create_secret_info->type); - if (value.IsNull()) { - throw InvalidInputException( - "Can not combine a non-constant expression for the secret type with a default-named secret. Either " - "provide an explicit secret name or use a constant expression for the secret type."); - } - create_secret_info->name = "__default_" + StringUtil::Lower(value.ToString()); + create_secret_info->name = "__default_" + create_secret_info->type; } result->info = std::move(create_secret_info); diff --git a/src/duckdb/src/parser/transform/statement/transform_select_node.cpp b/src/duckdb/src/parser/transform/statement/transform_select_node.cpp index 56ef6c71c..ab206fdb8 100644 --- a/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +++ b/src/duckdb/src/parser/transform/statement/transform_select_node.cpp @@ -31,20 +31,11 @@ void Transformer::TransformModifiers(duckdb_libpgquery::PGSelectStmt &stmt, Quer node.modifiers.push_back(std::move(limit_percent_modifier)); } else { auto limit_modifier = make_uniq(); - if (stmt.offset_first) { - if (stmt.limitOffset) { - limit_modifier->offset = TransformExpression(stmt.limitOffset); - } - if (stmt.limitCount) { - limit_modifier->limit = TransformExpression(stmt.limitCount); - } - } else { - if (stmt.limitCount) { - limit_modifier->limit = TransformExpression(stmt.limitCount); - } - if (stmt.limitOffset) { - limit_modifier->offset = TransformExpression(stmt.limitOffset); - } + if (stmt.limitCount) { + limit_modifier->limit = TransformExpression(stmt.limitCount); + } + if (stmt.limitOffset) { + limit_modifier->offset = TransformExpression(stmt.limitOffset); } node.modifiers.push_back(std::move(limit_modifier)); } diff --git a/src/duckdb/src/parser/transform/tableref/transform_base_tableref.cpp b/src/duckdb/src/parser/transform/tableref/transform_base_tableref.cpp index 14205959a..d0e64a452 100644 --- a/src/duckdb/src/parser/transform/tableref/transform_base_tableref.cpp +++ b/src/duckdb/src/parser/transform/tableref/transform_base_tableref.cpp @@ -16,11 +16,6 @@ unique_ptr Transformer::TransformRangeVar(duckdb_libpgquery::PGRangeVa if (root.schemaname) { result->schema_name = root.schemaname; } - if (root.at_clause) { - auto &at_clause = PGCast(*root.at_clause); - auto at_expr = TransformExpression(*at_clause.expr); - result->at_clause = make_uniq(at_clause.unit, std::move(at_expr)); - } if (root.sample) { result->sample = TransformSampleOptions(root.sample); } diff --git a/src/duckdb/src/planner/bind_context.cpp b/src/duckdb/src/planner/bind_context.cpp index 1005db332..d135ed2ae 100644 --- a/src/duckdb/src/planner/bind_context.cpp +++ b/src/duckdb/src/planner/bind_context.cpp @@ -570,15 +570,10 @@ void BindContext::GenerateAllColumnExpressions(StarExpression &expr, } } } - if (binder.GetBindingMode() == BindingMode::EXTRACT_NAMES) { - //! We only care about extracting the names of the referenced columns - //! remove the exclude + replace lists expr.exclude_list.clear(); expr.replace_list.clear(); } - - //! Verify correctness of the exclude list for (auto &excluded : expr.exclude_list) { if (exclusion_info.excluded_qualified_columns.find(excluded) == exclusion_info.excluded_qualified_columns.end()) { @@ -586,8 +581,6 @@ void BindContext::GenerateAllColumnExpressions(StarExpression &expr, expr.relation_name.empty() ? "FROM clause" : expr.relation_name.c_str()); } } - - //! Verify correctness of the replace list for (auto &entry : expr.replace_list) { if (exclusion_info.excluded_columns.find(entry.first) == exclusion_info.excluded_columns.end()) { throw BinderException("Column \"%s\" in REPLACE list not found in %s", entry.first, @@ -613,28 +606,21 @@ void BindContext::AddBinding(unique_ptr binding) { void BindContext::AddBaseTable(idx_t index, const string &alias, const vector &names, const vector &types, vector &bound_column_ids, - TableCatalogEntry &entry, bool add_virtual_columns) { - virtual_column_map_t virtual_columns; - if (add_virtual_columns) { - virtual_columns = entry.GetVirtualColumns(); - } - AddBinding( - make_uniq(alias, types, names, bound_column_ids, &entry, index, std::move(virtual_columns))); + StandardEntry &entry, bool add_row_id) { + AddBinding(make_uniq(alias, types, names, bound_column_ids, &entry, index, add_row_id)); } void BindContext::AddBaseTable(idx_t index, const string &alias, const vector &names, const vector &types, vector &bound_column_ids, const string &table_name) { - virtual_column_map_t virtual_columns; AddBinding(make_uniq(alias.empty() ? table_name : alias, types, names, bound_column_ids, nullptr, - index, std::move(virtual_columns))); + index, true)); } void BindContext::AddTableFunction(idx_t index, const string &alias, const vector &names, const vector &types, vector &bound_column_ids, - optional_ptr entry, virtual_column_map_t virtual_columns) { - AddBinding( - make_uniq(alias, types, names, bound_column_ids, entry, index, std::move(virtual_columns))); + optional_ptr entry) { + AddBinding(make_uniq(alias, types, names, bound_column_ids, entry, index)); } static string AddColumnNameToBinding(const string &base_name, case_insensitive_set_t ¤t_names) { @@ -693,7 +679,7 @@ void BindContext::AddGenericBinding(idx_t index, const string &alias, const vect } void BindContext::AddCTEBinding(idx_t index, const string &alias, const vector &names, - const vector &types, bool using_key) { + const vector &types) { auto binding = make_shared_ptr(BindingType::BASE, BindingAlias(alias), types, names, index); if (cte_bindings.find(alias) != cte_bindings.end()) { @@ -701,13 +687,6 @@ void BindContext::AddCTEBinding(idx_t index, const string &alias, const vector(0); - - if (using_key) { - auto recurring_alias = "recurring." + alias; - cte_bindings[recurring_alias] = - make_shared_ptr(BindingType::BASE, BindingAlias(recurring_alias), types, names, index); - cte_references[recurring_alias] = make_shared_ptr(0); - } } void BindContext::AddContext(BindContext other) { diff --git a/src/duckdb/src/planner/binder.cpp b/src/duckdb/src/planner/binder.cpp index 9dc11a810..7333ac393 100644 --- a/src/duckdb/src/planner/binder.cpp +++ b/src/duckdb/src/planner/binder.cpp @@ -238,10 +238,8 @@ static bool ParsedExpressionIsAggregate(Binder &binder, const ParsedExpression & if (expr.GetExpressionClass() == ExpressionClass::FUNCTION) { auto &function = expr.Cast(); QueryErrorContext error_context; - - EntryLookupInfo lookup_info(CatalogType::AGGREGATE_FUNCTION_ENTRY, function.function_name, error_context); - auto entry = - binder.GetCatalogEntry(function.catalog, function.schema, lookup_info, OnEntryNotFound::RETURN_NULL); + auto entry = binder.GetCatalogEntry(CatalogType::AGGREGATE_FUNCTION_ENTRY, function.catalog, function.schema, + function.function_name, OnEntryNotFound::RETURN_NULL, error_context); if (entry && entry->type == CatalogType::AGGREGATE_FUNCTION_ENTRY) { return true; } @@ -726,10 +724,10 @@ BoundStatement Binder::BindReturning(vector> return return result; } -optional_ptr Binder::GetCatalogEntry(const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info, - OnEntryNotFound on_entry_not_found) { - return entry_retriever.GetEntry(catalog, schema, lookup_info, on_entry_not_found); +optional_ptr Binder::GetCatalogEntry(CatalogType type, const string &catalog, const string &schema, + const string &name, OnEntryNotFound on_entry_not_found, + QueryErrorContext &error_context) { + return entry_retriever.GetEntry(type, catalog, schema, name, on_entry_not_found, error_context); } } // namespace duckdb diff --git a/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp index 4e59c4828..b2a44072c 100644 --- a/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp @@ -39,14 +39,12 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t // lookup the function in the catalog QueryErrorContext error_context(function.GetQueryLocation()); binder.BindSchemaOrCatalog(function.catalog, function.schema); - - EntryLookupInfo function_lookup(CatalogType::SCALAR_FUNCTION_ENTRY, function.function_name, error_context); - auto func = GetCatalogEntry(function.catalog, function.schema, function_lookup, OnEntryNotFound::RETURN_NULL); + auto func = GetCatalogEntry(CatalogType::SCALAR_FUNCTION_ENTRY, function.catalog, function.schema, + function.function_name, OnEntryNotFound::RETURN_NULL, error_context); if (!func) { // function was not found - check if we this is a table function - EntryLookupInfo table_function_lookup(CatalogType::TABLE_FUNCTION_ENTRY, function.function_name, error_context); - auto table_func = - GetCatalogEntry(function.catalog, function.schema, table_function_lookup, OnEntryNotFound::RETURN_NULL); + auto table_func = GetCatalogEntry(CatalogType::TABLE_FUNCTION_ENTRY, function.catalog, function.schema, + function.function_name, OnEntryNotFound::RETURN_NULL, error_context); if (table_func) { throw BinderException(function, "Function \"%s\" is a table function but it was used as a scalar function. This " @@ -76,7 +74,8 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t } } // rebind the function - func = GetCatalogEntry(function.catalog, function.schema, function_lookup, OnEntryNotFound::THROW_EXCEPTION); + func = GetCatalogEntry(CatalogType::SCALAR_FUNCTION_ENTRY, function.catalog, function.schema, + function.function_name, OnEntryNotFound::THROW_EXCEPTION, error_context); } if (func->type != CatalogType::AGGREGATE_FUNCTION_ENTRY && @@ -144,6 +143,11 @@ BindResult ExpressionBinder::BindFunction(FunctionExpression &function, ScalarFu BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, ScalarFunctionCatalogEntry &func, idx_t depth) { + // scalar functions with lambdas can never be overloaded + if (func.functions.functions.size() != 1) { + return BindResult("This scalar function does not support lambdas!"); + } + // get the callback function for the lambda parameter types auto &scalar_function = func.functions.functions.front(); auto &bind_lambda_function = scalar_function.bind_lambda; @@ -151,29 +155,20 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc return BindResult("This scalar function does not support lambdas!"); } - // the first child is the list, the second child is the lambda expression - const idx_t list_idx = 0; - const idx_t lambda_expr_idx = 1; - D_ASSERT(function.children[lambda_expr_idx]->GetExpressionClass() == ExpressionClass::LAMBDA); + if (function.children.size() != 2) { + return BindResult("Invalid number of function arguments!"); + } + D_ASSERT(function.children[1]->GetExpressionClass() == ExpressionClass::LAMBDA); - // bind the list + // bind the list parameter ErrorData error; - for (idx_t i = 0; i < function.children.size(); i++) { - if (i != lambda_expr_idx) { - if (function.children[i]->GetExpressionClass() == ExpressionClass::LAMBDA) { - return BindResult("No function matches the given name and argument types: '" + function.ToString() + - "'. You might need to add explicit type casts."); - } - - BindChild(function.children[i], depth, error); - if (error.HasError()) { - return BindResult(std::move(error)); - } - } + BindChild(function.children[0], depth, error); + if (error.HasError()) { + return BindResult(std::move(error)); } // get the logical type of the children of the list - auto &list_child = BoundExpression::GetExpression(*function.children[list_idx]); + auto &list_child = BoundExpression::GetExpression(*function.children[0]); if (list_child->return_type.id() != LogicalTypeId::LIST && list_child->return_type.id() != LogicalTypeId::ARRAY && list_child->return_type.id() != LogicalTypeId::SQLNULL && list_child->return_type.id() != LogicalTypeId::UNKNOWN) { @@ -192,7 +187,7 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc } // bind the lambda parameter - auto &lambda_expr = function.children[lambda_expr_idx]->Cast(); + auto &lambda_expr = function.children[1]->Cast(); BindResult bind_lambda_result = BindExpression(lambda_expr, depth, list_child_type, &bind_lambda_function); if (bind_lambda_result.HasError()) { @@ -200,12 +195,12 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc } // successfully bound: replace the node with a BoundExpression - auto alias = function.children[lambda_expr_idx]->GetAlias(); + auto alias = function.children[1]->GetAlias(); bind_lambda_result.expression->SetAlias(alias); if (!alias.empty()) { bind_lambda_result.expression->SetAlias(alias); } - function.children[lambda_expr_idx] = make_uniq(std::move(bind_lambda_result.expression)); + function.children[1] = make_uniq(std::move(bind_lambda_result.expression)); if (binder.GetBindingMode() == BindingMode::EXTRACT_NAMES) { return BindResult(make_uniq(Value(LogicalType::SQLNULL))); @@ -220,7 +215,7 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc } // capture the (lambda) columns - auto &bound_lambda_expr = children[lambda_expr_idx]->Cast(); + auto &bound_lambda_expr = children.back()->Cast(); CaptureLambdaColumns(bound_lambda_expr, bound_lambda_expr.lambda_expr, &bind_lambda_function, list_child_type); FunctionBinder function_binder(binder); @@ -232,10 +227,11 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, Sc } auto &bound_function_expr = result->Cast(); + D_ASSERT(bound_function_expr.children.size() == 2); // remove the lambda expression from the children - auto lambda = std::move(bound_function_expr.children[lambda_expr_idx]); - bound_function_expr.children.erase_at(lambda_expr_idx); + auto lambda = std::move(bound_function_expr.children.back()); + bound_function_expr.children.pop_back(); auto &bound_lambda = lambda->Cast(); // push back (in reverse order) any nested lambda parameters so that we can later use them in the lambda @@ -285,10 +281,11 @@ string ExpressionBinder::UnsupportedUnnestMessage() { return "UNNEST not supported here"; } -optional_ptr ExpressionBinder::GetCatalogEntry(const string &catalog, const string &schema, - const EntryLookupInfo &lookup_info, - OnEntryNotFound on_entry_not_found) { - return binder.GetCatalogEntry(catalog, schema, lookup_info, on_entry_not_found); +optional_ptr ExpressionBinder::GetCatalogEntry(CatalogType type, const string &catalog, + const string &schema, const string &name, + OnEntryNotFound on_entry_not_found, + QueryErrorContext &error_context) { + return binder.GetCatalogEntry(type, catalog, schema, name, on_entry_not_found, error_context); } } // namespace duckdb diff --git a/src/duckdb/src/planner/binder/expression/bind_lambda.cpp b/src/duckdb/src/planner/binder/expression/bind_lambda.cpp index 83e9e84ae..acc68ed0b 100644 --- a/src/duckdb/src/planner/binder/expression/bind_lambda.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_lambda.cpp @@ -65,17 +65,12 @@ void ExtractParameters(LambdaExpression &expr, vector &column_names, vec BindResult ExpressionBinder::BindExpression(LambdaExpression &expr, idx_t depth, const LogicalType &list_child_type, optional_ptr bind_lambda_function) { + // This is not a lambda expression, but the JSON arrow operator. if (!bind_lambda_function) { - // This is not a lambda expression, but the JSON arrow operator. - // Remember the original expression in case of a binding error. - if (!expr.copied_expr) { - expr.copied_expr = expr.expr->Copy(); - } OperatorExpression arrow_expr(ExpressionType::ARROW, std::move(expr.lhs), std::move(expr.expr)); auto bind_result = BindExpression(arrow_expr, depth); - // The arrow_expr now might contain bound nodes. - // Restore the original expression. + // The arrow_expr now contains bound nodes. We move these into the original expression. if (bind_result.HasError()) { D_ASSERT(arrow_expr.children.size() == 2); expr.lhs = std::move(arrow_expr.children[0]); @@ -107,9 +102,6 @@ BindResult ExpressionBinder::BindExpression(LambdaExpression &expr, idx_t depth, DummyBinding new_lambda_binding(column_types, column_names, table_alias); lambda_bindings->push_back(new_lambda_binding); - if (expr.copied_expr) { - expr.expr = std::move(expr.copied_expr); - } auto result = BindExpression(expr.expr, depth, false); lambda_bindings->pop_back(); diff --git a/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp index 7a2421107..d1d0df606 100644 --- a/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp @@ -8,8 +8,6 @@ #include "duckdb/planner/expression/bound_operator_expression.hpp" #include "duckdb/planner/expression/bound_parameter_expression.hpp" #include "duckdb/planner/expression_binder.hpp" -#include "duckdb/planner/expression/bound_function_expression.hpp" -#include "duckdb/planner/expression_iterator.hpp" namespace duckdb { @@ -77,8 +75,6 @@ LogicalType ExpressionBinder::ResolveOperatorType(OperatorExpression &op, vector case ExpressionType::OPERATOR_COALESCE: { return ResolveCoalesceType(op, children); } - case ExpressionType::OPERATOR_TRY: - return ExpressionBinder::GetExpressionReturnType(*children[0]); case ExpressionType::OPERATOR_NOT: return ResolveNotType(op, children); default: @@ -108,8 +104,6 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth) // all children bound successfully string function_name; switch (op.GetExpressionType()) { - case ExpressionType::OPERATOR_UNPACK: - return BindResult("UNPACK not allowed here, should have been resolved earlier"); case ExpressionType::ARRAY_EXTRACT: { D_ASSERT(op.children[0]->GetExpressionClass() == ExpressionClass::BOUND_EXPRESSION); auto &b_exp = BoundExpression::GetExpression(*op.children[0]); @@ -177,16 +171,6 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth) case ExpressionType::ARROW: function_name = "json_extract"; break; - case ExpressionType::OPERATOR_TRY: { - auto &expr = BoundExpression::GetExpression(*op.children[0]); - if (expr->HasSubquery()) { - throw BinderException("TRY can not be used in combination with a scalar subquery"); - } - if (expr->IsVolatile()) { - throw BinderException("TRY can not be used in combination with a volatile function"); - } - break; - } default: break; } diff --git a/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp index 876f8336f..fa9f004ee 100644 --- a/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp @@ -20,18 +20,9 @@ string GetColumnsStringValue(ParsedExpression &expr) { } } -StarExpressionType Binder::FindStarExpression(unique_ptr &expr, StarExpression **star, bool is_root, - bool in_columns) { - StarExpressionType has_star = StarExpressionType::NONE; - if (expr->GetExpressionType() == ExpressionType::OPERATOR_UNPACK) { - auto &operator_expr = expr->Cast(); - auto res = FindStarExpression(operator_expr.children[0], star, is_root, in_columns); - if (res != StarExpressionType::STAR && res != StarExpressionType::COLUMNS) { - throw BinderException( - "UNPACK can only be used in combination with a STAR (*) expression or COLUMNS expression"); - } - return StarExpressionType::UNPACKED; - } +bool Binder::FindStarExpression(unique_ptr &expr, StarExpression **star, bool is_root, + bool in_columns) { + bool has_star = false; if (expr->GetExpressionClass() == ExpressionClass::STAR) { auto ¤t_star = expr->Cast(); if (StarExpression::IsStar(*expr)) { @@ -39,7 +30,7 @@ StarExpressionType Binder::FindStarExpression(unique_ptr &expr D_ASSERT(!in_columns); // At the root level *star = ¤t_star; - return StarExpressionType::STAR; + return true; } if (!in_columns) { @@ -70,7 +61,7 @@ StarExpressionType Binder::FindStarExpression(unique_ptr &expr } D_ASSERT(!values.empty()); expr = make_uniq(Value::LIST(LogicalType::VARCHAR, values)); - return StarExpressionType::STAR; + return true; } if (in_columns) { throw BinderException("COLUMNS expression is not allowed inside another COLUMNS expression"); @@ -83,15 +74,14 @@ StarExpressionType Binder::FindStarExpression(unique_ptr &expr throw BinderException(*expr, "Multiple different STAR/COLUMNS in the same expression are not supported"); } - return StarExpressionType::STAR; + return true; } *star = ¤t_star; - has_star = StarExpressionType::STAR; + has_star = true; } ParsedExpressionIterator::EnumerateChildren(*expr, [&](unique_ptr &child_expr) { - auto res = FindStarExpression(child_expr, star, false, in_columns); - if (res != StarExpressionType::NONE) { - has_star = res; + if (FindStarExpression(child_expr, star, false, in_columns)) { + has_star = true; } }); return has_star; @@ -112,8 +102,7 @@ void Binder::ReplaceStarExpression(unique_ptr &expr, unique_pt *expr, [&](unique_ptr &child_expr) { ReplaceStarExpression(child_expr, replacement); }); } -string Binder::ReplaceColumnsAlias(const string &alias, const string &column_name, - optional_ptr regex) { +static string ReplaceColumnsAlias(const string &alias, const string &column_name, optional_ptr regex) { string result; result.reserve(alias.size()); for (idx_t c = 0; c < alias.size(); c++) { @@ -243,11 +232,7 @@ void Binder::ExpandStarExpression(unique_ptr expr, TryTransformStarLike(expr); StarExpression *star = nullptr; - - //! Check the current 'expr' to find out if it contains a star-expression - //! that needs to be expanded - auto star_type = FindStarExpression(expr, &star, true, false); - if (star_type == StarExpressionType::NONE) { + if (!FindStarExpression(expr, &star, true, false)) { // no star expression: add it as-is D_ASSERT(!star); new_select_list.push_back(std::move(expr)); @@ -255,7 +240,7 @@ void Binder::ExpandStarExpression(unique_ptr expr, } D_ASSERT(star); vector> star_list; - //! Expand the star that we found into a new list of expressions + // we have star expressions! expand the list of star expressions bind_context.GenerateAllColumnExpressions(*star, star_list); unique_ptr regex; @@ -288,8 +273,8 @@ void Binder::ExpandStarExpression(unique_ptr expr, throw BinderException(*star, err); } vector> new_list; - for (auto &expanded_expr : star_list) { - auto child_expr = GetResolvedColumnExpression(*expanded_expr); + for (idx_t i = 0; i < star_list.size(); i++) { + auto child_expr = GetResolvedColumnExpression(*star_list[i]); if (!child_expr) { continue; } @@ -297,7 +282,7 @@ void Binder::ExpandStarExpression(unique_ptr expr, if (!RE2::PartialMatch(colref.GetColumnName(), *regex)) { continue; } - new_list.push_back(std::move(expanded_expr)); + new_list.push_back(std::move(star_list[i])); } if (new_list.empty()) { auto err = StringUtil::Format("No matching columns found that match regex \"%s\"", regex_str); @@ -344,25 +329,20 @@ void Binder::ExpandStarExpression(unique_ptr expr, *star, "COLUMNS expects either a VARCHAR argument (regex) or a LIST of VARCHAR (list of columns)"); } } - //! We make a copy because we will be replacing the original star - //! If we have identical stars that also need to be replaced - //! This causes a heap-use-after-free or other corruption if we don't make a copy to reference instead. - auto copied_star_p = star->Copy(); - auto &copied_star = copied_star_p->Cast(); // now perform the replacement - if (star_type == StarExpressionType::UNPACKED) { + if (StarExpression::IsColumnsUnpacked(*star)) { if (StarExpression::IsColumnsUnpacked(*expr)) { throw BinderException("*COLUMNS not allowed at the root level, use COLUMNS instead"); } - ReplaceUnpackedStarExpression(expr, star_list, copied_star, regex.get()); + ReplaceUnpackedStarExpression(expr, star_list); new_select_list.push_back(std::move(expr)); return; } for (idx_t i = 0; i < star_list.size(); i++) { auto new_expr = expr->Copy(); ReplaceStarExpression(new_expr, star_list[i]); - if (StarExpression::IsColumns(copied_star)) { + if (StarExpression::IsColumns(*star)) { auto expr = GetResolvedColumnExpression(*star_list[i]); if (expr) { auto &colref = expr->Cast(); diff --git a/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp index 03d3c1ca9..ba9c0715b 100644 --- a/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp @@ -149,8 +149,7 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth, b case LogicalTypeId::SQLNULL: break; default: - return BindResult(BinderException(function, "UNNEST() can only be applied to lists, structs and NULL, not %s", - child_type.ToString())); + return BindResult(BinderException(function, "UNNEST() can only be applied to lists, structs and NULL")); } idx_t list_unnests; diff --git a/src/duckdb/src/planner/binder/expression/bind_unpacked_star_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_unpacked_star_expression.cpp index b570f8289..24e708129 100644 --- a/src/duckdb/src/planner/binder/expression/bind_unpacked_star_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_unpacked_star_expression.cpp @@ -9,45 +9,25 @@ namespace duckdb { using expression_list_t = vector>; static void AddChild(unique_ptr &child, expression_list_t &new_children, - expression_list_t &replacements, StarExpression &star, optional_ptr regex) { + expression_list_t &replacements) { if (!StarExpression::IsColumnsUnpacked(*child)) { // Just add the child directly new_children.push_back(std::move(child)); return; } - auto &unpack = child->Cast(); - D_ASSERT(unpack.type == ExpressionType::OPERATOR_UNPACK); - D_ASSERT(unpack.children.size() == 1); - auto &unpack_child = unpack.children[0]; - // Replace the child with the replacement expression(s) for (auto &replacement : replacements) { - auto new_expr = unpack_child->Copy(); - Binder::ReplaceStarExpression(new_expr, replacement); - if (StarExpression::IsColumns(star)) { - auto expr = Binder::GetResolvedColumnExpression(*replacement); - if (expr) { - auto &colref = expr->Cast(); - if (new_expr->GetAlias().empty()) { - new_expr->SetAlias(colref.GetColumnName()); - } else { - new_expr->SetAlias( - Binder::ReplaceColumnsAlias(new_expr->GetAlias(), colref.GetColumnName(), regex)); - } - } - } - new_children.push_back(std::move(new_expr)); + new_children.push_back(replacement->Copy()); } } -static void ReplaceInFunction(unique_ptr &expr, expression_list_t &star_list, StarExpression &star, - optional_ptr regex) { +static void ReplaceInFunction(unique_ptr &expr, expression_list_t &star_list) { auto &function_expr = expr->Cast(); // Replace children expression_list_t new_children; for (auto &child : function_expr.children) { - AddChild(child, new_children, star_list, star, regex); + AddChild(child, new_children, star_list); } function_expr.children = std::move(new_children); @@ -55,7 +35,7 @@ static void ReplaceInFunction(unique_ptr &expr, expression_lis if (function_expr.order_bys) { expression_list_t new_orders; for (auto &order : function_expr.order_bys->orders) { - AddChild(order.expression, new_orders, star_list, star, regex); + AddChild(order.expression, new_orders, star_list); } if (new_orders.size() != function_expr.order_bys->orders.size()) { throw NotImplementedException("*COLUMNS(...) is not supported in the order expression"); @@ -67,50 +47,35 @@ static void ReplaceInFunction(unique_ptr &expr, expression_lis } } -static void ReplaceInOperator(unique_ptr &expr, expression_list_t &star_list, StarExpression &star, - optional_ptr regex) { +static void ReplaceInOperator(unique_ptr &expr, expression_list_t &star_list) { auto &operator_expr = expr->Cast(); - vector allowed_types({ - ExpressionType::OPERATOR_COALESCE, - ExpressionType::COMPARE_IN, - ExpressionType::COMPARE_NOT_IN, - }); - bool allowed = false; - for (idx_t i = 0; i < allowed_types.size() && !allowed; i++) { - auto &type = allowed_types[i]; - if (operator_expr.type == type) { - allowed = true; - } - } - if (!allowed) { - throw BinderException("*COLUMNS() can not be used together with the '%s' operator", - EnumUtil::ToString(operator_expr.type)); - } - // Replace children expression_list_t new_children; for (auto &child : operator_expr.children) { - AddChild(child, new_children, star_list, star, regex); + AddChild(child, new_children, star_list); } operator_expr.children = std::move(new_children); } -void Binder::ReplaceUnpackedStarExpression(unique_ptr &expr, expression_list_t &star_list, - StarExpression &star, optional_ptr regex) { +void Binder::ReplaceUnpackedStarExpression(unique_ptr &expr, expression_list_t &star_list) { D_ASSERT(expr); auto expression_class = expr->GetExpressionClass(); // Replace *COLUMNS(...) in the supported places switch (expression_class) { + case ExpressionClass::STAR: { + if (!StarExpression::IsColumnsUnpacked(*expr)) { + break; + } + // Deal with any *COLUMNS that was not replaced + throw BinderException("*COLUMNS() can not be used in this place"); + } case ExpressionClass::FUNCTION: { - ReplaceInFunction(expr, star_list, star, regex); + ReplaceInFunction(expr, star_list); break; } case ExpressionClass::OPERATOR: { - if (StarExpression::IsColumnsUnpacked(*expr)) { - throw BinderException("*COLUMNS() can not be used in this place"); - } - ReplaceInOperator(expr, star_list, star, regex); + ReplaceInOperator(expr, star_list); break; } default: { @@ -119,9 +84,8 @@ void Binder::ReplaceUnpackedStarExpression(unique_ptr &expr, e } // Visit the children of this expression, collecting the unpacked expressions - ParsedExpressionIterator::EnumerateChildren(*expr, [&](unique_ptr &child_expr) { - ReplaceUnpackedStarExpression(child_expr, star_list, star, regex); - }); + ParsedExpressionIterator::EnumerateChildren( + *expr, [&](unique_ptr &child_expr) { ReplaceUnpackedStarExpression(child_expr, star_list); }); } } // namespace duckdb diff --git a/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp b/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp index c99ae49de..72a6c4be2 100644 --- a/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +++ b/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp @@ -144,9 +144,8 @@ static LogicalType BindRangeExpression(ClientContext &context, const string &nam BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) { QueryErrorContext error_context(window.GetQueryLocation()); // Check for macros pretending to be aggregates - - EntryLookupInfo function_lookup(CatalogType::SCALAR_FUNCTION_ENTRY, window.function_name, error_context); - auto entry = GetCatalogEntry(window.catalog, window.schema, function_lookup, OnEntryNotFound::RETURN_NULL); + auto entry = GetCatalogEntry(CatalogType::SCALAR_FUNCTION_ENTRY, window.catalog, window.schema, + window.function_name, OnEntryNotFound::RETURN_NULL, error_context); if (window.GetExpressionType() == ExpressionType::WINDOW_AGGREGATE && entry && entry->type == CatalogType::MACRO_ENTRY) { auto macro = make_uniq(window.catalog, window.schema, window.function_name, diff --git a/src/duckdb/src/planner/binder/query_node/bind_recursive_cte_node.cpp b/src/duckdb/src/planner/binder/query_node/bind_recursive_cte_node.cpp index 003f13458..1c5e34261 100644 --- a/src/duckdb/src/planner/binder/query_node/bind_recursive_cte_node.cpp +++ b/src/duckdb/src/planner/binder/query_node/bind_recursive_cte_node.cpp @@ -15,9 +15,6 @@ unique_ptr Binder::BindNode(RecursiveCTENode &statement) { // the left side is visited first and is added to the BindContext of the right side D_ASSERT(statement.left); D_ASSERT(statement.right); - if (statement.union_all && !statement.key_targets.empty()) { - throw BinderException("UNION ALL cannot be used with USING KEY in recursive CTE."); - } result->ctename = statement.ctename; result->union_all = statement.union_all; @@ -41,8 +38,7 @@ unique_ptr Binder::BindNode(RecursiveCTENode &statement) { // Add bindings of left side to temporary CTE bindings context result->right_binder->bind_context.AddCTEBinding(result->setop_index, statement.ctename, result->names, - result->types, !statement.key_targets.empty()); - + result->types); result->right = result->right_binder->BindNode(*statement.right); for (auto &c : result->left_binder->correlated_columns) { result->right_binder->AddCorrelatedColumn(c); @@ -52,14 +48,6 @@ unique_ptr Binder::BindNode(RecursiveCTENode &statement) { MoveCorrelatedExpressions(*result->left_binder); MoveCorrelatedExpressions(*result->right_binder); - // bind specified keys to the referenced column - auto expression_binder = ExpressionBinder(*this, context); - for (unique_ptr &expr : statement.key_targets) { - auto bound_expr = expression_binder.Bind(expr); - D_ASSERT(bound_expr->type == ExpressionType::BOUND_COLUMN_REF); - result->key_targets.push_back(std::move(bound_expr)); - } - // now both sides have been bound we can resolve types if (result->left->types.size() != result->right->types.size()) { throw BinderException("Set operations can only apply to expressions with the " diff --git a/src/duckdb/src/planner/binder/query_node/plan_recursive_cte_node.cpp b/src/duckdb/src/planner/binder/query_node/plan_recursive_cte_node.cpp index 5863db90d..7f2eafefd 100644 --- a/src/duckdb/src/planner/binder/query_node/plan_recursive_cte_node.cpp +++ b/src/duckdb/src/planner/binder/query_node/plan_recursive_cte_node.cpp @@ -24,26 +24,15 @@ unique_ptr Binder::CreatePlan(BoundRecursiveCTENode &node) { left_node = CastLogicalOperatorToTypes(node.left->types, node.types, std::move(left_node)); right_node = CastLogicalOperatorToTypes(node.right->types, node.types, std::move(right_node)); - bool ref_recurring = node.right_binder->bind_context.cte_references["recurring." + node.ctename] && - *node.right_binder->bind_context.cte_references["recurring." + node.ctename] != 0; - - if (node.key_targets.empty() && ref_recurring) { - throw InvalidInputException("RECURRING can only be used with USING KEY in recursive CTE."); - } - - // Check if there is a reference to the recursive or recurring table, if not create a set operator. - if ((!node.right_binder->bind_context.cte_references[node.ctename] || - *node.right_binder->bind_context.cte_references[node.ctename] == 0) && - !ref_recurring) { + if (!node.right_binder->bind_context.cte_references[node.ctename] || + *node.right_binder->bind_context.cte_references[node.ctename] == 0) { auto root = make_uniq(node.setop_index, node.types.size(), std::move(left_node), std::move(right_node), LogicalOperatorType::LOGICAL_UNION, true); return VisitQueryNode(node, std::move(root)); } + auto root = make_uniq(node.ctename, node.setop_index, node.types.size(), node.union_all, + std::move(left_node), std::move(right_node)); - auto root = - make_uniq(node.ctename, node.setop_index, node.types.size(), node.union_all, - std::move(node.key_targets), std::move(left_node), std::move(right_node)); - root->ref_recurring = ref_recurring; return VisitQueryNode(node, std::move(root)); } diff --git a/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp b/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp index f4c98bcfc..b938f1f65 100644 --- a/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp +++ b/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp @@ -393,20 +393,17 @@ void RecursiveDependentJoinPlanner::VisitOperator(LogicalOperator &op) { auto &rec_cte = op.Cast(); binder.recursive_ctes[rec_cte.table_index] = &op; } - for (idx_t i = 0; i < op.children.size(); i++) { - root = std::move(op.children[i]); - D_ASSERT(root); - if (root->type == LogicalOperatorType::LOGICAL_DEPENDENT_JOIN) { - // Found a dependent join, flatten it - auto &new_root = root->Cast(); - root = binder.PlanLateralJoin(std::move(new_root.children[0]), std::move(new_root.children[1]), - new_root.correlated_columns, new_root.join_type, - std::move(new_root.join_condition)); - } - VisitOperatorExpressions(op); - op.children[i] = std::move(root); + root = std::move(op.children[0]); + D_ASSERT(root); + if (root->type == LogicalOperatorType::LOGICAL_DEPENDENT_JOIN) { + // Found a dependent join, flatten it + auto &new_root = root->Cast(); + root = binder.PlanLateralJoin(std::move(new_root.children[0]), std::move(new_root.children[1]), + new_root.correlated_columns, new_root.join_type, + std::move(new_root.join_condition)); } - + VisitOperatorExpressions(op); + op.children[0] = std::move(root); for (idx_t i = 0; i < op.children.size(); i++) { D_ASSERT(op.children[i]); VisitOperator(*op.children[i]); diff --git a/src/duckdb/src/planner/binder/statement/bind_copy.cpp b/src/duckdb/src/planner/binder/statement/bind_copy.cpp index 0278ab8b0..ce2f93ad8 100644 --- a/src/duckdb/src/planner/binder/statement/bind_copy.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_copy.cpp @@ -56,7 +56,6 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt, CopyToType copy_to_type) bool seen_overwrite_mode = false; bool seen_filepattern = false; bool write_partition_columns = false; - bool write_empty_file = true; CopyFunctionReturnType return_type = CopyFunctionReturnType::CHANGED_ROWS; CopyFunctionBindInput bind_input(*stmt.info); @@ -122,14 +121,8 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt, CopyToType copy_to_type) if (GetBooleanArg(context, option.second)) { return_type = CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST; } - } else if (loption == "return_stats") { - if (GetBooleanArg(context, option.second)) { - return_type = CopyFunctionReturnType::WRITTEN_FILE_STATISTICS; - } } else if (loption == "write_partition_columns") { write_partition_columns = GetBooleanArg(context, option.second); - } else if (loption == "write_empty_file") { - write_empty_file = GetBooleanArg(context, option.second); } else { stmt.info->options[option.first] = option.second; } @@ -229,22 +222,6 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt, CopyToType copy_to_type) "Can't combine file rotation (e.g., ROW_GROUPS_PER_FILE) and PARTITION_BY for COPY"); } } - if (!write_empty_file) { - if (rotate) { - throw NotImplementedException( - "Can't combine WRITE_EMPTY_FILE false with file rotation (e.g., ROW_GROUPS_PER_FILE)"); - } - if (per_thread_output) { - throw NotImplementedException("Can't combine WRITE_EMPTY_FILE false with PER_THREAD_OUTPUT"); - } - if (!partition_cols.empty()) { - throw NotImplementedException("Can't combine WRITE_EMPTY_FILE false with PARTITION_BY"); - } - } - if (return_type == CopyFunctionReturnType::WRITTEN_FILE_STATISTICS && - !copy_function.function.copy_to_get_written_statistics) { - throw NotImplementedException("RETURN_STATS is not supported for the \"%s\" copy format", stmt.info->format); - } // now create the copy information auto copy = make_uniq(copy_function.function, std::move(function_data), std::move(stmt.info)); @@ -261,7 +238,6 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt, CopyToType copy_to_type) copy->partition_output = !partition_cols.empty(); copy->write_partition_columns = write_partition_columns; copy->partition_columns = std::move(partition_cols); - copy->write_empty_file = write_empty_file; copy->return_type = return_type; copy->names = unique_column_names; @@ -275,7 +251,6 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt, CopyToType copy_to_type) properties.return_type = StatementReturnType::CHANGED_ROWS; break; case CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST: - case CopyFunctionReturnType::WRITTEN_FILE_STATISTICS: properties.return_type = StatementReturnType::QUERY_RESULT; break; default: diff --git a/src/duckdb/src/planner/binder/statement/bind_create.cpp b/src/duckdb/src/planner/binder/statement/bind_create.cpp index c44eb0992..67408ca91 100644 --- a/src/duckdb/src/planner/binder/statement/bind_create.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_create.cpp @@ -30,7 +30,6 @@ #include "duckdb/planner/bound_query_node.hpp" #include "duckdb/planner/expression/bound_cast_expression.hpp" #include "duckdb/planner/expression/bound_columnref_expression.hpp" -#include "duckdb/planner/expression_binder/constant_binder.hpp" #include "duckdb/planner/expression_binder/index_binder.hpp" #include "duckdb/planner/expression_binder/select_binder.hpp" #include "duckdb/planner/operator/logical_create.hpp" @@ -46,8 +45,8 @@ namespace duckdb { -void Binder::BindSchemaOrCatalog(CatalogEntryRetriever &retriever, string &catalog, string &schema) { - auto &context = retriever.GetContext(); +void Binder::BindSchemaOrCatalog(ClientContext &context, string &catalog, string &schema) { + CatalogEntryRetriever retriever(context); if (catalog.empty() && !schema.empty()) { // schema is specified - but catalog is not // try searching for the catalog instead @@ -56,17 +55,18 @@ void Binder::BindSchemaOrCatalog(CatalogEntryRetriever &retriever, string &catal if (database) { // we have a database with this name // check if there is a schema - auto &search_path = retriever.GetSearchPath(); + auto &search_path = *context.client_data->catalog_search_path; auto catalog_names = search_path.GetCatalogsForSchema(schema); if (catalog_names.empty()) { catalog_names.push_back(DatabaseManager::GetDefaultDatabase(context)); } for (auto &catalog_name : catalog_names) { - auto catalog_ptr = Catalog::GetCatalogEntry(retriever, catalog_name); - if (!catalog_ptr) { + auto catalog = Catalog::GetCatalogEntry(retriever, catalog_name); + if (!catalog) { continue; } - if (catalog_ptr->CheckAmbiguousCatalogOrSchema(context, schema)) { + if (catalog->CheckAmbiguousCatalogOrSchema(context, schema)) { + throw BinderException( "Ambiguous reference to catalog or schema \"%s\" - use a fully qualified path like \"%s.%s\"", schema, catalog_name, schema); @@ -78,11 +78,6 @@ void Binder::BindSchemaOrCatalog(CatalogEntryRetriever &retriever, string &catal } } -void Binder::BindSchemaOrCatalog(ClientContext &context, string &catalog, string &schema) { - CatalogEntryRetriever retriever(context); - BindSchemaOrCatalog(retriever, catalog, schema); -} - void Binder::BindSchemaOrCatalog(string &catalog, string &schema) { BindSchemaOrCatalog(context, catalog, schema); } @@ -327,7 +322,6 @@ LogicalType Binder::BindLogicalTypeInternal(const LogicalType &type, optional_pt bind_logical_type_function_t user_bind_modifiers_func = nullptr; LogicalType result; - EntryLookupInfo type_lookup(CatalogType::TYPE_ENTRY, user_type_name); if (catalog) { // The search order is: // 1) In the explicitly set schema (my_schema.my_type) @@ -337,16 +331,19 @@ LogicalType Binder::BindLogicalTypeInternal(const LogicalType &type, optional_pt optional_ptr entry = nullptr; if (!user_type_schema.empty()) { - entry = entry_retriever.GetEntry(*catalog, user_type_schema, type_lookup, OnEntryNotFound::RETURN_NULL); + entry = entry_retriever.GetEntry(CatalogType::TYPE_ENTRY, *catalog, user_type_schema, user_type_name, + OnEntryNotFound::RETURN_NULL); } if (!IsValidUserType(entry)) { - entry = entry_retriever.GetEntry(*catalog, schema, type_lookup, OnEntryNotFound::RETURN_NULL); + entry = entry_retriever.GetEntry(CatalogType::TYPE_ENTRY, *catalog, schema, user_type_name, + OnEntryNotFound::RETURN_NULL); } if (!IsValidUserType(entry)) { - entry = entry_retriever.GetEntry(*catalog, INVALID_SCHEMA, type_lookup, OnEntryNotFound::RETURN_NULL); + entry = entry_retriever.GetEntry(CatalogType::TYPE_ENTRY, *catalog, INVALID_SCHEMA, user_type_name, + OnEntryNotFound::RETURN_NULL); } if (!IsValidUserType(entry)) { - entry = entry_retriever.GetEntry(INVALID_CATALOG, INVALID_SCHEMA, type_lookup, + entry = entry_retriever.GetEntry(CatalogType::TYPE_ENTRY, INVALID_CATALOG, INVALID_SCHEMA, user_type_name, OnEntryNotFound::THROW_EXCEPTION); } auto &type_entry = entry->Cast(); @@ -357,7 +354,7 @@ LogicalType Binder::BindLogicalTypeInternal(const LogicalType &type, optional_pt string type_schema = UserType::GetSchema(type); BindSchemaOrCatalog(context, type_catalog, type_schema); - auto entry = entry_retriever.GetEntry(type_catalog, type_schema, type_lookup); + auto entry = entry_retriever.GetEntry(CatalogType::TYPE_ENTRY, type_catalog, type_schema, user_type_name); auto &type_entry = entry->Cast(); result = type_entry.user_type; user_bind_modifiers_func = type_entry.bind_function; @@ -525,9 +522,8 @@ BoundStatement Binder::Bind(CreateStatement &stmt) { // 2: create a type alias with a custom type. // eg. CREATE TYPE a AS INT; CREATE TYPE b AS a; // We set b to be an alias for the underlying type of a - - EntryLookupInfo type_lookup(CatalogType::TYPE_ENTRY, UserType::GetTypeName(create_type_info.type)); - auto type_entry_p = entry_retriever.GetEntry(schema.catalog.GetName(), schema.name, type_lookup); + auto type_entry_p = entry_retriever.GetEntry(CatalogType::TYPE_ENTRY, schema.catalog.GetName(), schema.name, + UserType::GetTypeName(create_type_info.type)); D_ASSERT(type_entry_p); auto &type_entry = type_entry_p->Cast(); create_type_info.type = type_entry.user_type; @@ -544,73 +540,7 @@ BoundStatement Binder::Bind(CreateStatement &stmt) { case CatalogType::SECRET_ENTRY: { CatalogTransaction transaction = CatalogTransaction(Catalog::GetSystemCatalog(context), context); properties.return_type = StatementReturnType::QUERY_RESULT; - - auto &info = stmt.info->Cast(); - - // We need to execute all expressions in the CreateSecretInfo to construct a CreateSecretInput - ConstantBinder default_binder(*this, context, "Secret Parameter"); - - string provider_string, type_string; - vector scope_strings; - - if (info.provider) { - auto bound_provider = default_binder.Bind(info.provider); - if (bound_provider->HasParameter()) { - throw InvalidInputException("Create Secret expressions can not have parameters!"); - } - provider_string = - StringUtil::Lower(ExpressionExecutor::EvaluateScalar(context, *bound_provider, true).ToString()); - } - if (info.type) { - auto bound_type = default_binder.Bind(info.type); - if (bound_type->HasParameter()) { - throw InvalidInputException("Create Secret expressions can not have parameters!"); - } - type_string = StringUtil::Lower(ExpressionExecutor::EvaluateScalar(context, *bound_type, true).ToString()); - } - if (info.scope) { - auto bound_scope = default_binder.Bind(info.scope); - if (bound_scope->HasParameter()) { - throw InvalidInputException("Create Secret expressions can not have parameters!"); - } - // Execute all scope expressions - Value scope = ExpressionExecutor::EvaluateScalar(context, *bound_scope, true); - if (scope.type() == LogicalType::VARCHAR) { - scope_strings.push_back(scope.ToString()); - } else if (scope.type() == LogicalType::LIST(LogicalType::VARCHAR)) { - for (const auto &item : ListValue::GetChildren(scope)) { - scope_strings.push_back(item.GetValue()); - } - } else if (scope.type().InternalType() == PhysicalType::STRUCT) { - // struct expression with empty keys is also allowed for backwards compatibility to when the create - // secret statement would be parsed differently: this allows CREATE SECRET (TYPE x, SCOPE ('bla', - // 'bloe')) - for (const auto &child : StructValue::GetChildren(scope)) { - if (child.type() != LogicalType::VARCHAR) { - throw InvalidInputException( - "Invalid input to scope parameter of create secret: only struct of VARCHARs is allowed"); - } - scope_strings.push_back(child.GetValue()); - } - } else { - throw InvalidInputException("Create Secret scope must be of type VARCHAR or LIST(VARCHAR)"); - } - } - - // Execute all options expressions - case_insensitive_map_t bound_options; - for (auto &option : info.options) { - auto bound_value = default_binder.Bind(option.second); - if (bound_value->HasParameter()) { - throw InvalidInputException("Create Secret expressions can not have parameters!"); - } - bound_options.insert({option.first, ExpressionExecutor::EvaluateScalar(context, *bound_value, true)}); - } - - CreateSecretInput create_secret_input {type_string, provider_string, info.storage_type, info.name, - scope_strings, bound_options, info.on_conflict, info.persist_type}; - - return SecretManager::Get(context).BindCreateSecret(transaction, create_secret_input); + return SecretManager::Get(context).BindCreateSecret(transaction, stmt.info->Cast()); } default: throw InternalException("Unrecognized type!"); diff --git a/src/duckdb/src/planner/binder/statement/bind_create_table.cpp b/src/duckdb/src/planner/binder/statement/bind_create_table.cpp index 9a9c16f05..4a6eccf80 100644 --- a/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_create_table.cpp @@ -518,8 +518,8 @@ static void BindCreateTableConstraints(CreateTableInfo &create_info, CatalogEntr } // Resolve the table reference. - EntryLookupInfo table_lookup(CatalogType::TABLE_ENTRY, fk.info.table); - auto table_entry = entry_retriever.GetEntry(INVALID_CATALOG, fk.info.schema, table_lookup); + auto table_entry = + entry_retriever.GetEntry(CatalogType::TABLE_ENTRY, INVALID_CATALOG, fk.info.schema, fk.info.table); if (table_entry->type == CatalogType::VIEW_ENTRY) { throw BinderException("cannot reference a VIEW with a FOREIGN KEY"); } diff --git a/src/duckdb/src/planner/binder/statement/bind_delete.cpp b/src/duckdb/src/planner/binder/statement/bind_delete.cpp index f37b3f7ba..822f487ed 100644 --- a/src/duckdb/src/planner/binder/statement/bind_delete.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_delete.cpp @@ -73,20 +73,11 @@ BoundStatement Binder::Bind(DeleteStatement &stmt) { del->bound_constraints = BindConstraints(table); del->AddChild(std::move(root)); - auto row_id_columns = table.GetRowIdColumns(); - auto virtual_columns = table.GetVirtualColumns(); + // set up the delete expression auto &column_ids = get.GetColumnIds(); - for (auto &row_id_column : row_id_columns) { - auto row_id_entry = virtual_columns.find(row_id_column); - if (row_id_entry == virtual_columns.end()) { - throw InternalException( - "BindDelete could not find the row id column in the virtual columns list of the table"); - } - // set up the delete expression - del->expressions.push_back(make_uniq( - row_id_entry->second.type, ColumnBinding(get.table_index, column_ids.size()))); - get.AddColumnId(row_id_column); - } + del->expressions.push_back( + make_uniq(table.GetRowIdType(), ColumnBinding(get.table_index, column_ids.size()))); + get.AddColumnId(COLUMN_IDENTIFIER_ROW_ID); if (!stmt.returning_list.empty()) { del->return_chunk = true; diff --git a/src/duckdb/src/planner/binder/statement/bind_drop.cpp b/src/duckdb/src/planner/binder/statement/bind_drop.cpp index 3e181eb73..e17287bed 100644 --- a/src/duckdb/src/planner/binder/statement/bind_drop.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_drop.cpp @@ -40,9 +40,8 @@ BoundStatement Binder::Bind(DropStatement &stmt) { // mark catalog as accessed properties.RegisterDBRead(*catalog, context); } - EntryLookupInfo entry_lookup(stmt.info->type, stmt.info->name); - auto entry = Catalog::GetEntry(context, stmt.info->catalog, stmt.info->schema, entry_lookup, - OnEntryNotFound::RETURN_NULL); + auto entry = Catalog::GetEntry(context, stmt.info->type, stmt.info->catalog, stmt.info->schema, stmt.info->name, + stmt.info->if_not_found); if (!entry) { break; } diff --git a/src/duckdb/src/planner/binder/statement/bind_simple.cpp b/src/duckdb/src/planner/binder/statement/bind_simple.cpp index 583c9e992..d4d862843 100644 --- a/src/duckdb/src/planner/binder/statement/bind_simple.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_simple.cpp @@ -87,8 +87,8 @@ BoundStatement Binder::Bind(AlterStatement &stmt) { } else { // For any other ALTER, we retrieve the catalog entry directly. - EntryLookupInfo lookup_info(stmt.info->GetCatalogType(), stmt.info->name); - entry = entry_retriever.GetEntry(stmt.info->catalog, stmt.info->schema, lookup_info, stmt.info->if_not_found); + entry = entry_retriever.GetEntry(stmt.info->GetCatalogType(), stmt.info->catalog, stmt.info->schema, + stmt.info->name, stmt.info->if_not_found); } auto &properties = GetStatementProperties(); diff --git a/src/duckdb/src/planner/binder/statement/bind_summarize.cpp b/src/duckdb/src/planner/binder/statement/bind_summarize.cpp index 45b2b2f25..b5c87e1ad 100644 --- a/src/duckdb/src/planner/binder/statement/bind_summarize.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_summarize.cpp @@ -120,14 +120,11 @@ unique_ptr Binder::BindSummarize(ShowRef &ref) { max_children.push_back(SummarizeCreateAggregate("max", plan.names[i])); unique_children.push_back(make_uniq( LogicalType::BIGINT, SummarizeCreateAggregate("approx_count_distinct", plan.names[i]))); - if (plan.types[i].IsNumeric() || plan.types[i].IsTemporal()) { - avg_children.push_back(SummarizeCreateAggregate("avg", plan.names[i])); - } else { - avg_children.push_back(make_uniq(Value())); - } if (plan.types[i].IsNumeric()) { + avg_children.push_back(SummarizeCreateAggregate("avg", plan.names[i])); std_children.push_back(SummarizeCreateAggregate("stddev", plan.names[i])); } else { + avg_children.push_back(make_uniq(Value())); std_children.push_back(make_uniq(Value())); } if (plan.types[i].IsNumeric() || plan.types[i].IsTemporal()) { diff --git a/src/duckdb/src/planner/binder/statement/bind_update.cpp b/src/duckdb/src/planner/binder/statement/bind_update.cpp index 4bd8ae57c..75dd39074 100644 --- a/src/duckdb/src/planner/binder/statement/bind_update.cpp +++ b/src/duckdb/src/planner/binder/statement/bind_update.cpp @@ -133,19 +133,10 @@ BoundStatement Binder::Bind(UpdateStatement &stmt) { table.BindUpdateConstraints(*this, *get, *proj, *update, context); // finally add the row id column to the projection list - auto row_id_columns = table.GetRowIdColumns(); - auto virtual_columns = table.GetVirtualColumns(); auto &column_ids = get->GetColumnIds(); - for (auto &row_id_column : row_id_columns) { - auto row_id_entry = virtual_columns.find(row_id_column); - if (row_id_entry == virtual_columns.end()) { - throw InternalException( - "BindUpdate could not find the row id column in the virtual columns list of the table"); - } - proj->expressions.push_back(make_uniq( - row_id_entry->second.type, ColumnBinding(get->table_index, column_ids.size()))); - get->AddColumnId(row_id_column); - } + proj->expressions.push_back( + make_uniq(table.GetRowIdType(), ColumnBinding(get->table_index, column_ids.size()))); + get->AddColumnId(COLUMN_IDENTIFIER_ROW_ID); // set the projection as child of the update node and finalize the result update->AddChild(std::move(proj)); diff --git a/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp b/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp index 01147a3f5..a8cf487f4 100644 --- a/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +++ b/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp @@ -15,10 +15,7 @@ #include "duckdb/planner/tableref/bound_cteref.hpp" #include "duckdb/planner/tableref/bound_dummytableref.hpp" #include "duckdb/planner/tableref/bound_subqueryref.hpp" -#include "duckdb/planner/expression_binder/constant_binder.hpp" #include "duckdb/catalog/catalog_search_path.hpp" -#include "duckdb/planner/tableref/bound_at_clause.hpp" -#include "duckdb/execution/expression_executor.hpp" namespace duckdb { @@ -82,16 +79,6 @@ unique_ptr Binder::BindWithReplacementScan(ClientContext &context return nullptr; } -unique_ptr Binder::BindAtClause(optional_ptr at_clause) { - if (!at_clause) { - return nullptr; - } - ConstantBinder binder(*this, context, "AT clause"); - auto expr = binder.Bind(at_clause->ExpressionMutable()); - auto val = ExpressionExecutor::EvaluateScalar(context, *expr); - return make_uniq(at_clause->Unit(), std::move(val)); -} - vector Binder::GetSearchPath(Catalog &catalog, const string &schema_name) { vector view_search_path; auto &catalog_name = catalog.GetName(); @@ -121,9 +108,8 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { // check if the table name refers to a CTE // CTE name should never be qualified (i.e. schema_name should be empty) - // unless we want to refer to the recurring table of "using key". vector> found_ctes; - if (ref.schema_name.empty() || ref.schema_name == "recurring") { + if (ref.schema_name.empty()) { found_ctes = FindCTE(ref.table_name, ref.table_name == alias); } @@ -147,29 +133,13 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { materialized = CTEMaterialize::CTE_MATERIALIZE_NEVER; #endif } - - if (ref.schema_name == "recurring" && cte.key_targets.empty()) { - throw InvalidInputException("RECURRING can only be used with USING KEY in recursive CTE."); - } - - auto result = - make_uniq(index, ctebinding->index, materialized, ref.schema_name == "recurring"); + auto result = make_uniq(index, ctebinding->index, materialized); auto alias = ref.alias.empty() ? ref.table_name : ref.alias; auto names = BindContext::AliasColumnNames(alias, ctebinding->names, ref.column_name_alias); bind_context.AddGenericBinding(index, alias, names, ctebinding->types); - - auto cte_reference = ref.schema_name.empty() ? ref.table_name : ref.schema_name + "." + ref.table_name; - // Update references to CTE - auto cteref = bind_context.cte_references[cte_reference]; - - if (cteref == nullptr && ref.schema_name == "recurring") { - throw BinderException("There is a WITH item named \"%s\", but the recurring table cannot be " - "referenced from this part of the query.", - ref.table_name); - } - + auto cteref = bind_context.cte_references[ref.table_name]; (*cteref)++; result->types = ctebinding->types; @@ -191,12 +161,6 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { ref.table_name); } - if (ref.schema_name == "recurring") { - throw BinderException("There is a WITH item named \"%s\", but the recurring table cannot be " - "referenced from this part of the query.", - ref.table_name); - } - // Move CTE to subquery and bind recursively SubqueryRef subquery(unique_ptr_cast(cte.query->Copy())); subquery.alias = ref.alias.empty() ? ref.table_name : ref.alias; @@ -227,12 +191,9 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { } // not a CTE // extract a table or view from the catalog - auto at_clause = BindAtClause(ref.at_clause); - auto entry_at_clause = at_clause ? at_clause.get() : entry_retriever.GetAtClause(); - EntryLookupInfo table_lookup(CatalogType::TABLE_ENTRY, ref.table_name, entry_at_clause, error_context); - BindSchemaOrCatalog(entry_retriever, ref.catalog_name, ref.schema_name); - auto table_or_view = - entry_retriever.GetEntry(ref.catalog_name, ref.schema_name, table_lookup, OnEntryNotFound::RETURN_NULL); + BindSchemaOrCatalog(ref.catalog_name, ref.schema_name); + auto table_or_view = entry_retriever.GetEntry(CatalogType::TABLE_ENTRY, ref.catalog_name, ref.schema_name, + ref.table_name, OnEntryNotFound::RETURN_NULL, error_context); // we still didn't find the table if (GetBindingMode() == BindingMode::EXTRACT_NAMES) { if (!table_or_view || table_or_view->type == CatalogType::TABLE_ENTRY) { @@ -278,8 +239,8 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { } // could not find an alternative: bind again to get the error - (void)entry_retriever.GetEntry(ref.catalog_name, ref.schema_name, table_lookup, - OnEntryNotFound::THROW_EXCEPTION); + (void)entry_retriever.GetEntry(CatalogType::TABLE_ENTRY, ref.catalog_name, ref.schema_name, ref.table_name, + OnEntryNotFound::THROW_EXCEPTION, error_context); throw InternalException("Catalog::GetEntry should have thrown an exception above"); } @@ -293,7 +254,7 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { properties.RegisterDBRead(table.ParentCatalog(), context); unique_ptr bind_data; - auto scan_function = table.GetScanFunction(context, bind_data, table_lookup); + auto scan_function = table.GetScanFunction(context, bind_data); // TODO: bundle the type and name vector in a struct (e.g PackedColumnMetadata) vector table_types; vector table_names; @@ -309,15 +270,9 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { } table_names = BindContext::AliasColumnNames(ref.table_name, table_names, ref.column_name_alias); - virtual_column_map_t virtual_columns; - if (scan_function.get_virtual_columns) { - virtual_columns = scan_function.get_virtual_columns(context, bind_data.get()); - } else { - virtual_columns = table.GetVirtualColumns(); - } auto logical_get = make_uniq(table_index, scan_function, std::move(bind_data), std::move(return_types), - std::move(return_names), std::move(virtual_columns)); + std::move(return_names), table.GetRowIdType()); auto table_entry = logical_get->GetTable(); auto &col_ids = logical_get->GetMutableColumnIds(); if (!table_entry) { @@ -335,7 +290,7 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { // for the view and for the current query auto view_binder = Binder::CreateBinder(context, this, BinderType::VIEW_BINDER); view_binder->can_contain_nulls = true; - SubqueryRef subquery(unique_ptr_cast(view_catalog_entry.GetQuery().Copy())); + SubqueryRef subquery(unique_ptr_cast(view_catalog_entry.query->Copy())); subquery.alias = ref.alias; // construct view names by first (1) taking the view aliases, (2) adding the view names, then (3) applying // subquery aliases @@ -349,9 +304,6 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { auto view_search_path = GetSearchPath(view_catalog_entry.ParentCatalog(), view_catalog_entry.ParentSchema().name); view_binder->entry_retriever.SetSearchPath(std::move(view_search_path)); - // propagate the AT clause through the view - view_binder->entry_retriever.SetAtClause(entry_at_clause); - // bind the child subquery view_binder->AddBoundView(view_catalog_entry); auto bound_child = view_binder->Bind(subquery); @@ -360,9 +312,9 @@ unique_ptr Binder::Bind(BaseTableRef &ref) { } D_ASSERT(bound_child->type == TableReferenceType::SUBQUERY); - // verify that the types and names match up with the expected types and names if the view has type info defined + // verify that the types and names match up with the expected types and names auto &bound_subquery = bound_child->Cast(); - if (GetBindingMode() != BindingMode::EXTRACT_NAMES && view_catalog_entry.HasTypes()) { + if (GetBindingMode() != BindingMode::EXTRACT_NAMES) { // we bind the view subquery and the original view with different "can_contain_nulls", // but we don't want to throw an error when SQLNULL does not match up with INTEGER, // so we exchange all SQLNULL with INTEGER here before comparing diff --git a/src/duckdb/src/planner/binder/tableref/bind_named_parameters.cpp b/src/duckdb/src/planner/binder/tableref/bind_named_parameters.cpp index 80afc9f33..e2a6537d1 100644 --- a/src/duckdb/src/planner/binder/tableref/bind_named_parameters.cpp +++ b/src/duckdb/src/planner/binder/tableref/bind_named_parameters.cpp @@ -2,24 +2,18 @@ namespace duckdb { -template -map order_case_insensitive_map(const case_insensitive_map_t &input_map) { - return map(input_map.begin(), input_map.end()); -} - void Binder::BindNamedParameters(named_parameter_type_map_t &types, named_parameter_map_t &values, QueryErrorContext &error_context, string &func_name) { for (auto &kv : values) { auto entry = types.find(kv.first); if (entry == types.end()) { - auto ordered_params = order_case_insensitive_map(types); // create a list of named parameters for the error string named_params; - for (auto &kv_ordered_params : ordered_params) { + for (auto &kv : types) { named_params += " "; - named_params += kv_ordered_params.first; + named_params += kv.first; named_params += " "; - named_params += kv_ordered_params.second.ToString(); + named_params += kv.second.ToString(); named_params += "\n"; } string error_msg; diff --git a/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp b/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp index 05def578b..3899ecdd6 100644 --- a/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +++ b/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp @@ -61,7 +61,7 @@ static void ExtractPivotExpressions(ParsedExpression &expr, case_insensitive_set if (expr.GetExpressionType() == ExpressionType::COLUMN_REF) { auto &child_colref = expr.Cast(); if (child_colref.IsQualified()) { - throw BinderException(expr, "PIVOT expression cannot contain qualified columns"); + throw BinderException("PIVOT expression cannot contain qualified columns"); } handled_columns.insert(child_colref.GetColumnName()); } @@ -75,8 +75,8 @@ void ExtractPivotAggregateExpression(ClientContext &context, ParsedExpression &e auto &aggr_function = expr.Cast(); // check if this is an aggregate to ensure it is an aggregate and not a scalar function - EntryLookupInfo lookup_info(CatalogType::AGGREGATE_FUNCTION_ENTRY, aggr_function.function_name, expr); - auto &entry = Catalog::GetEntry(context, aggr_function.catalog, aggr_function.schema, lookup_info); + auto &entry = Catalog::GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, aggr_function.catalog, + aggr_function.schema, aggr_function.function_name); if (entry.type == CatalogType::AGGREGATE_FUNCTION_ENTRY) { // aggregate aggregates.push_back(aggr_function); @@ -606,7 +606,6 @@ unique_ptr Binder::BindUnpivot(Binder &child_binder, PivotRef &ref, } } - vector select_names; for (auto &col_expr : all_columns) { if (col_expr->GetExpressionType() != ExpressionType::COLUMN_REF) { throw InternalException("Unexpected child of pivot source - not a ColumnRef"); @@ -616,7 +615,6 @@ unique_ptr Binder::BindUnpivot(Binder &child_binder, PivotRef &ref, auto entry = handled_columns.find(column_name); if (entry == handled_columns.end()) { // not handled - add to the set of regularly selected columns - select_names.push_back(col_expr->GetName()); select_node->select_list.push_back(std::move(col_expr)); } else { name_map[column_name] = column_name; @@ -664,70 +662,28 @@ unique_ptr Binder::BindUnpivot(Binder &child_binder, PivotRef &ref, unpivot_expressions.push_back(std::move(expressions)); } - idx_t column_count = select_names.size(); - idx_t unnest_count = unpivot_expressions.size(); - // add the names for the generated unpivot lists - select_names.push_back("unpivot_names"); - for (idx_t i = 0; i < unpivot_expressions.size(); i++) { - if (i > 0) { - select_names.push_back("unpivot_list_" + std::to_string(i + 1)); - } else { - select_names.push_back("unpivot_list"); - } - } - - // now de-duplicate the names - QueryResult::DeduplicateColumns(select_names); - // construct the UNNEST expression for the set of names (constant) auto unpivot_list = Value::LIST(LogicalType::VARCHAR, std::move(unpivot_names)); auto unpivot_name_expr = make_uniq(std::move(unpivot_list)); - unpivot_name_expr->alias = select_names[column_count]; - select_node->select_list.push_back(std::move(unpivot_name_expr)); + vector> unnest_name_children; + unnest_name_children.push_back(std::move(unpivot_name_expr)); + auto unnest_name_expr = make_uniq("unnest", std::move(unnest_name_children)); + unnest_name_expr->SetAlias(unpivot.unpivot_names[0]); + select_node->select_list.push_back(std::move(unnest_name_expr)); - // construct the unpivot lists for the set of unpivoted columns + // construct the UNNEST expression for the set of unpivoted columns if (ref.unpivot_names.size() != unpivot_expressions.size()) { throw BinderException(ref, "UNPIVOT name count mismatch - got %d names but %d expressions", ref.unpivot_names.size(), unpivot_expressions.size()); } for (idx_t i = 0; i < unpivot_expressions.size(); i++) { auto list_expr = make_uniq("unpivot_list", std::move(unpivot_expressions[i])); - list_expr->alias = select_names[column_count + 1 + i]; - select_node->select_list.push_back(std::move(list_expr)); - } - - // move the unpivot lists into a subquery - auto result_node = make_uniq(); - auto sub_select = make_uniq(); - sub_select->node = std::move(select_node); - auto subquery = make_uniq(std::move(sub_select)); - subquery->alias = "unpivot"; - - result_node->from_table = std::move(subquery); - - // construct the final UNNEST calls which generate the final unpivot result - for (idx_t i = 0; i < column_count; i++) { - auto select_col = make_uniq(std::move(select_names[i])); - result_node->select_list.push_back(std::move(select_col)); - } - - auto unpivot_name_list = make_uniq(std::move(select_names[column_count])); - vector> unnest_name_children; - unnest_name_children.push_back(std::move(unpivot_name_list)); - auto unnest_name_expr = make_uniq("unnest", std::move(unnest_name_children)); - unnest_name_expr->SetAlias(unpivot.unpivot_names[0]); - result_node->select_list.push_back(std::move(unnest_name_expr)); - - for (idx_t i = 0; i < unnest_count; i++) { - auto unpivot_internal_name = std::move(select_names[column_count + 1 + i]); - - auto unpivot_list_ref = make_uniq(std::move(unpivot_internal_name)); vector> unnest_val_children; - unnest_val_children.push_back(std::move(unpivot_list_ref)); + unnest_val_children.push_back(std::move(list_expr)); auto unnest_val_expr = make_uniq("unnest", std::move(unnest_val_children)); auto unnest_name = i < ref.column_name_alias.size() ? ref.column_name_alias[i] : ref.unpivot_names[i]; unnest_val_expr->SetAlias(unnest_name); - result_node->select_list.push_back(std::move(unnest_val_expr)); + select_node->select_list.push_back(std::move(unnest_val_expr)); if (!ref.include_nulls) { // if we are running with EXCLUDE NULLS we need to add an IS NOT NULL filter auto colref = make_uniq(unnest_name); @@ -740,7 +696,7 @@ unique_ptr Binder::BindUnpivot(Binder &child_binder, PivotRef &ref, } } } - return result_node; + return select_node; } unique_ptr Binder::Bind(PivotRef &ref) { diff --git a/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp b/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp index 01fb95000..ace96207b 100644 --- a/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +++ b/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp @@ -236,13 +236,8 @@ unique_ptr Binder::BindTableFunctionInternal(TableFunction &tab return_names[i] = "C" + to_string(i); } } - virtual_column_map_t virtual_columns; - if (table_function.get_virtual_columns) { - virtual_columns = table_function.get_virtual_columns(context, bind_data.get()); - } - auto get = make_uniq(bind_index, table_function, std::move(bind_data), return_types, return_names, - virtual_columns); + auto get = make_uniq(bind_index, table_function, std::move(bind_data), return_types, return_names); get->parameters = parameters; get->named_parameters = named_parameters; get->input_table_types = input_table_types; @@ -254,7 +249,7 @@ unique_ptr Binder::BindTableFunctionInternal(TableFunction &tab } // now add the table function to the bind context so its columns can be bound bind_context.AddTableFunction(bind_index, function_name, return_names, return_types, get->GetMutableColumnIds(), - get->GetTable().get(), std::move(virtual_columns)); + get->GetTable().get()); return std::move(get); } @@ -281,9 +276,8 @@ unique_ptr Binder::Bind(TableFunctionRef &ref) { Binder::BindSchemaOrCatalog(context, catalog, schema); // fetch the function from the catalog - - EntryLookupInfo table_function_lookup(CatalogType::TABLE_FUNCTION_ENTRY, fexpr.function_name, error_context); - auto &func_catalog = *GetCatalogEntry(catalog, schema, table_function_lookup, OnEntryNotFound::THROW_EXCEPTION); + auto &func_catalog = *GetCatalogEntry(CatalogType::TABLE_FUNCTION_ENTRY, catalog, schema, fexpr.function_name, + OnEntryNotFound::THROW_EXCEPTION, error_context); if (func_catalog.type == CatalogType::TABLE_MACRO_ENTRY) { auto ¯o_func = func_catalog.Cast(); diff --git a/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp b/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp index 8bf1934fc..1f0fcb6b8 100644 --- a/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp +++ b/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp @@ -5,8 +5,7 @@ namespace duckdb { unique_ptr Binder::CreatePlan(BoundCTERef &ref) { - return make_uniq(ref.bind_index, ref.cte_index, ref.types, ref.bound_columns, ref.materialized_cte, - ref.is_recurring); + return make_uniq(ref.bind_index, ref.cte_index, ref.types, ref.bound_columns, ref.materialized_cte); } } // namespace duckdb diff --git a/src/duckdb/src/planner/expression/bound_reference_expression.cpp b/src/duckdb/src/planner/expression/bound_reference_expression.cpp index d96221e9b..fe3912402 100644 --- a/src/duckdb/src/planner/expression/bound_reference_expression.cpp +++ b/src/duckdb/src/planner/expression/bound_reference_expression.cpp @@ -10,7 +10,7 @@ BoundReferenceExpression::BoundReferenceExpression(string alias, LogicalType typ : Expression(ExpressionType::BOUND_REF, ExpressionClass::BOUND_REF, std::move(type)), index(index) { this->alias = std::move(alias); } -BoundReferenceExpression::BoundReferenceExpression(LogicalType type, storage_t index) +BoundReferenceExpression::BoundReferenceExpression(LogicalType type, idx_t index) : BoundReferenceExpression(string(), std::move(type), index) { } diff --git a/src/duckdb/src/planner/expression_binder/table_function_binder.cpp b/src/duckdb/src/planner/expression_binder/table_function_binder.cpp index 71ccdefe4..fca04a10b 100644 --- a/src/duckdb/src/planner/expression_binder/table_function_binder.cpp +++ b/src/duckdb/src/planner/expression_binder/table_function_binder.cpp @@ -49,11 +49,6 @@ BindResult TableFunctionBinder::BindColumnReference(unique_ptr if (value_function) { return BindExpression(value_function, depth, root_expression); } - if (table_function_name.empty()) { - throw BinderException(query_location, - "Failed to bind \"%s\" - COLUMNS expression can only contain lambda parameters", - result_name); - } return BindResult(make_uniq(Value(result_name))); } diff --git a/src/duckdb/src/planner/filter/conjunction_filter.cpp b/src/duckdb/src/planner/filter/conjunction_filter.cpp index 62f3dbc9f..aa11de721 100644 --- a/src/duckdb/src/planner/filter/conjunction_filter.cpp +++ b/src/duckdb/src/planner/filter/conjunction_filter.cpp @@ -21,7 +21,7 @@ FilterPropagateResult ConjunctionOrFilter::CheckStatistics(BaseStatistics &stats return FilterPropagateResult::FILTER_ALWAYS_FALSE; } -string ConjunctionOrFilter::ToString(const string &column_name) const { +string ConjunctionOrFilter::ToString(const string &column_name) { string result; for (idx_t i = 0; i < child_filters.size(); i++) { if (i > 0) { @@ -82,7 +82,7 @@ FilterPropagateResult ConjunctionAndFilter::CheckStatistics(BaseStatistics &stat return result; } -string ConjunctionAndFilter::ToString(const string &column_name) const { +string ConjunctionAndFilter::ToString(const string &column_name) { string result; for (idx_t i = 0; i < child_filters.size(); i++) { if (i > 0) { diff --git a/src/duckdb/src/planner/filter/constant_filter.cpp b/src/duckdb/src/planner/filter/constant_filter.cpp index 7a1c770d0..99dc10a4e 100644 --- a/src/duckdb/src/planner/filter/constant_filter.cpp +++ b/src/duckdb/src/planner/filter/constant_filter.cpp @@ -72,7 +72,7 @@ FilterPropagateResult ConstantFilter::CheckStatistics(BaseStatistics &stats) { return result; } -string ConstantFilter::ToString(const string &column_name) const { +string ConstantFilter::ToString(const string &column_name) { return column_name + ExpressionTypeToOperator(comparison_type) + constant.ToSQLString(); } diff --git a/src/duckdb/src/planner/filter/dynamic_filter.cpp b/src/duckdb/src/planner/filter/dynamic_filter.cpp index ec764e5e4..23de4bf42 100644 --- a/src/duckdb/src/planner/filter/dynamic_filter.cpp +++ b/src/duckdb/src/planner/filter/dynamic_filter.cpp @@ -22,7 +22,7 @@ FilterPropagateResult DynamicFilter::CheckStatistics(BaseStatistics &stats) { return filter_data->filter->CheckStatistics(stats); } -string DynamicFilter::ToString(const string &column_name) const { +string DynamicFilter::ToString(const string &column_name) { if (filter_data) { return "Dynamic Filter (" + column_name + ")"; } else { diff --git a/src/duckdb/src/planner/filter/in_filter.cpp b/src/duckdb/src/planner/filter/in_filter.cpp index e65e0579c..22c7f83cf 100644 --- a/src/duckdb/src/planner/filter/in_filter.cpp +++ b/src/duckdb/src/planner/filter/in_filter.cpp @@ -46,7 +46,7 @@ FilterPropagateResult InFilter::CheckStatistics(BaseStatistics &stats) { } } -string InFilter::ToString(const string &column_name) const { +string InFilter::ToString(const string &column_name) { string in_list; for (auto &val : values) { if (!in_list.empty()) { diff --git a/src/duckdb/src/planner/filter/null_filter.cpp b/src/duckdb/src/planner/filter/null_filter.cpp index b7ec69a8a..6848191e9 100644 --- a/src/duckdb/src/planner/filter/null_filter.cpp +++ b/src/duckdb/src/planner/filter/null_filter.cpp @@ -19,7 +19,7 @@ FilterPropagateResult IsNullFilter::CheckStatistics(BaseStatistics &stats) { return FilterPropagateResult::NO_PRUNING_POSSIBLE; } -string IsNullFilter::ToString(const string &column_name) const { +string IsNullFilter::ToString(const string &column_name) { return column_name + " IS NULL"; } @@ -48,7 +48,7 @@ FilterPropagateResult IsNotNullFilter::CheckStatistics(BaseStatistics &stats) { return FilterPropagateResult::NO_PRUNING_POSSIBLE; } -string IsNotNullFilter::ToString(const string &column_name) const { +string IsNotNullFilter::ToString(const string &column_name) { return column_name + " IS NOT NULL"; } diff --git a/src/duckdb/src/planner/filter/optional_filter.cpp b/src/duckdb/src/planner/filter/optional_filter.cpp index 0f054c3d2..891e9014d 100644 --- a/src/duckdb/src/planner/filter/optional_filter.cpp +++ b/src/duckdb/src/planner/filter/optional_filter.cpp @@ -12,7 +12,7 @@ FilterPropagateResult OptionalFilter::CheckStatistics(BaseStatistics &stats) { return child_filter->CheckStatistics(stats); } -string OptionalFilter::ToString(const string &column_name) const { +string OptionalFilter::ToString(const string &column_name) { return string("optional: ") + child_filter->ToString(column_name); } diff --git a/src/duckdb/src/planner/filter/struct_filter.cpp b/src/duckdb/src/planner/filter/struct_filter.cpp index 6a7c011cd..91d3b323d 100644 --- a/src/duckdb/src/planner/filter/struct_filter.cpp +++ b/src/duckdb/src/planner/filter/struct_filter.cpp @@ -5,7 +5,6 @@ #include "duckdb/planner/expression/bound_constant_expression.hpp" #include "duckdb/planner/expression/bound_function_expression.hpp" #include "duckdb/function/scalar/nested_functions.hpp" -#include "duckdb/function/scalar/struct_functions.hpp" namespace duckdb { @@ -21,7 +20,7 @@ FilterPropagateResult StructFilter::CheckStatistics(BaseStatistics &stats) { return child_filter->CheckStatistics(child_stats); } -string StructFilter::ToString(const string &column_name) const { +string StructFilter::ToString(const string &column_name) { if (!child_name.empty()) { return child_filter->ToString(column_name + "." + child_name); } @@ -49,7 +48,7 @@ unique_ptr StructFilter::ToExpression(const Expression &column) cons arguments.push_back(column.Copy()); arguments.push_back(make_uniq(Value::BIGINT(NumericCast(child_idx + 1)))); auto child = make_uniq(child_type, GetExtractAtFunction(), std::move(arguments), - StructExtractAtFun::GetBindData(child_idx)); + GetBindData(child_idx)); return child_filter->ToExpression(*child); } } // namespace duckdb diff --git a/src/duckdb/src/planner/logical_operator_visitor.cpp b/src/duckdb/src/planner/logical_operator_visitor.cpp index a3c20767c..7ebf3151e 100644 --- a/src/duckdb/src/planner/logical_operator_visitor.cpp +++ b/src/duckdb/src/planner/logical_operator_visitor.cpp @@ -122,14 +122,6 @@ void LogicalOperatorVisitor::EnumerateExpressions(LogicalOperator &op, } break; } - case LogicalOperatorType::LOGICAL_RECURSIVE_CTE: { - auto &rec = op.Cast(); - - for (auto &target : rec.key_targets) { - callback(&target); - } - break; - } case LogicalOperatorType::LOGICAL_INSERT: { auto &insert = op.Cast(); if (insert.on_conflict_condition) { diff --git a/src/duckdb/src/planner/operator/logical_copy_to_file.cpp b/src/duckdb/src/planner/operator/logical_copy_to_file.cpp index 763c9f54e..1b4f88f65 100644 --- a/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +++ b/src/duckdb/src/planner/operator/logical_copy_to_file.cpp @@ -66,7 +66,6 @@ void LogicalCopyToFile::Serialize(Serializer &serializer) const { serializer.WriteProperty(214, "rotate", rotate); serializer.WriteProperty(215, "return_type", return_type); serializer.WritePropertyWithDefault(216, "write_partition_columns", write_partition_columns, true); - serializer.WritePropertyWithDefault(217, "write_empty_file", write_empty_file, true); } unique_ptr LogicalCopyToFile::Deserialize(Deserializer &deserializer) { @@ -87,7 +86,7 @@ unique_ptr LogicalCopyToFile::Deserialize(Deserializer &deseria auto name = deserializer.ReadProperty(210, "function_name"); auto &func_catalog_entry = - Catalog::GetEntry(context, SYSTEM_CATALOG, DEFAULT_SCHEMA, name); + Catalog::GetEntry(context, CatalogType::COPY_FUNCTION_ENTRY, SYSTEM_CATALOG, DEFAULT_SCHEMA, name); if (func_catalog_entry.type != CatalogType::COPY_FUNCTION_ENTRY) { throw InternalException("DeserializeFunction - cant find catalog entry for function %s", name); } @@ -111,7 +110,6 @@ unique_ptr LogicalCopyToFile::Deserialize(Deserializer &deseria auto return_type = deserializer.ReadPropertyWithExplicitDefault(215, "return_type", CopyFunctionReturnType::CHANGED_ROWS); auto write_partition_columns = deserializer.ReadPropertyWithExplicitDefault(216, "write_partition_columns", true); - auto write_empty_file = deserializer.ReadPropertyWithExplicitDefault(217, "write_empty_file", true); if (!has_serialize) { // If not serialized, re-bind with the copy info @@ -139,18 +137,19 @@ unique_ptr LogicalCopyToFile::Deserialize(Deserializer &deseria result->rotate = rotate; result->return_type = return_type; result->write_partition_columns = write_partition_columns; - result->write_empty_file = write_empty_file; return std::move(result); } vector LogicalCopyToFile::GetColumnBindings() { - idx_t return_column_count = GetCopyFunctionReturnLogicalTypes(return_type).size(); - vector result; - for (idx_t i = 0; i < return_column_count; i++) { - result.emplace_back(0, i); + switch (return_type) { + case CopyFunctionReturnType::CHANGED_ROWS: + return {ColumnBinding(0, 0)}; + case CopyFunctionReturnType::CHANGED_ROWS_AND_FILE_LIST: + return {ColumnBinding(0, 0), ColumnBinding(0, 1)}; + default: + throw NotImplementedException("Unknown CopyFunctionReturnType"); } - return result; } idx_t LogicalCopyToFile::EstimateCardinality(ClientContext &context) { diff --git a/src/duckdb/src/planner/operator/logical_get.cpp b/src/duckdb/src/planner/operator/logical_get.cpp index e894cd8fa..be7b5aa5d 100644 --- a/src/duckdb/src/planner/operator/logical_get.cpp +++ b/src/duckdb/src/planner/operator/logical_get.cpp @@ -17,11 +17,10 @@ LogicalGet::LogicalGet() : LogicalOperator(LogicalOperatorType::LOGICAL_GET) { } LogicalGet::LogicalGet(idx_t table_index, TableFunction function, unique_ptr bind_data, - vector returned_types, vector returned_names, - virtual_column_map_t virtual_columns_p) + vector returned_types, vector returned_names, LogicalType rowid_type) : LogicalOperator(LogicalOperatorType::LOGICAL_GET), table_index(table_index), function(std::move(function)), bind_data(std::move(bind_data)), returned_types(std::move(returned_types)), names(std::move(returned_names)), - virtual_columns(std::move(virtual_columns_p)), extra_info() { + extra_info(), rowid_type(std::move(rowid_type)) { } optional_ptr LogicalGet::GetTable() const { @@ -119,57 +118,27 @@ vector LogicalGet::GetColumnBindings() { return result; } -const LogicalType &LogicalGet::GetColumnType(const ColumnIndex &index) const { - if (index.IsVirtualColumn()) { - auto entry = virtual_columns.find(index.GetPrimaryIndex()); - if (entry == virtual_columns.end()) { - throw InternalException("Failed to find referenced virtual column %d", index.GetPrimaryIndex()); - } - return entry->second.type; - } - return returned_types[index.GetPrimaryIndex()]; -} - -const string &LogicalGet::GetColumnName(const ColumnIndex &index) const { - if (index.IsVirtualColumn()) { - auto entry = virtual_columns.find(index.GetPrimaryIndex()); - if (entry == virtual_columns.end()) { - throw InternalException("Failed to find referenced virtual column %d", index.GetPrimaryIndex()); - } - return entry->second.name; - } - return names[index.GetPrimaryIndex()]; -} - -column_t LogicalGet::GetAnyColumn() const { - auto entry = virtual_columns.find(COLUMN_IDENTIFIER_EMPTY); - if (entry != virtual_columns.end()) { - // return the empty column if the projection supports it - return COLUMN_IDENTIFIER_EMPTY; - } - entry = virtual_columns.find(COLUMN_IDENTIFIER_ROW_ID); - if (entry != virtual_columns.end()) { - // return the rowid column if the projection supports it - return COLUMN_IDENTIFIER_ROW_ID; - } - // otherwise return the first column - return 0; -} - void LogicalGet::ResolveTypes() { if (column_ids.empty()) { - // no projection - we need to push a column - column_ids.emplace_back(GetAnyColumn()); + column_ids.emplace_back(COLUMN_IDENTIFIER_ROW_ID); } types.clear(); if (projection_ids.empty()) { for (auto &index : column_ids) { - types.push_back(GetColumnType(index)); + if (index.IsRowIdColumn()) { + types.emplace_back(LogicalType(rowid_type)); + } else { + types.push_back(returned_types[index.GetPrimaryIndex()]); + } } } else { for (auto &proj_index : projection_ids) { auto &index = column_ids[proj_index]; - types.push_back(GetColumnType(index)); + if (index.IsRowIdColumn()) { + types.emplace_back(LogicalType(rowid_type)); + } else { + types.push_back(returned_types[index.GetPrimaryIndex()]); + } } } if (!projected_input.empty()) { @@ -256,8 +225,6 @@ unique_ptr LogicalGet::Deserialize(Deserializer &deserializer) result->column_ids.emplace_back(col_id); } } - auto &context = deserializer.Get(); - virtual_column_map_t virtual_columns; if (!has_serialize) { TableFunctionRef empty_ref; TableFunctionBindInput input(result->parameters, result->named_parameters, result->input_table_types, @@ -269,44 +236,24 @@ unique_ptr LogicalGet::Deserialize(Deserializer &deserializer) if (!function.bind) { throw InternalException("Table function \"%s\" has neither bind nor (de)serialize", function.name); } - bind_data = function.bind(context, input, bind_return_types, bind_names); - if (function.get_virtual_columns) { - virtual_columns = function.get_virtual_columns(context, bind_data.get()); - } + bind_data = function.bind(deserializer.Get(), input, bind_return_types, bind_names); for (auto &col_id : result->column_ids) { - if (col_id.IsVirtualColumn()) { - auto idx = col_id.GetPrimaryIndex(); - auto ventry = virtual_columns.find(idx); - if (ventry == virtual_columns.end()) { - throw SerializationException( - "Table function deserialization failure - could not find virtual column with id %d", idx); - } - auto &ret_type = ventry->second.type; - auto &col_name = ventry->second.name; - if (bind_return_types[idx] != ret_type) { - throw SerializationException( - "Table function deserialization failure in function \"%s\" - virtual column with " - "name %s was serialized with type %s, but now has type %s", - function.name, col_name, ret_type, bind_return_types[idx]); - } - } else { - auto idx = col_id.GetPrimaryIndex(); - auto &ret_type = result->returned_types[idx]; - auto &col_name = result->names[idx]; - if (bind_return_types[idx] != ret_type) { - throw SerializationException( - "Table function deserialization failure in function \"%s\" - column with " - "name %s was serialized with type %s, but now has type %s", - function.name, col_name, ret_type, bind_return_types[idx]); - } + if (col_id.IsRowIdColumn()) { + // rowid + continue; + } + auto idx = col_id.GetPrimaryIndex(); + auto &ret_type = result->returned_types[idx]; + auto &col_name = result->names[idx]; + if (bind_return_types[idx] != ret_type) { + throw SerializationException("Table function deserialization failure in function \"%s\" - column with " + "name %s was serialized with type %s, but now has type %s", + function.name, col_name, ret_type, bind_return_types[idx]); } } result->returned_types = std::move(bind_return_types); - } else if (function.get_virtual_columns) { - virtual_columns = function.get_virtual_columns(context, bind_data.get()); } - result->virtual_columns = std::move(virtual_columns); result->bind_data = std::move(bind_data); return std::move(result); } diff --git a/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp b/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp index 9781f349f..bb5db60a9 100644 --- a/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp +++ b/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp @@ -730,17 +730,6 @@ unique_ptr FlattenDependentJoins::PushDownDependentJoinInternal base_binding.column_index = setop.column_count; table_index = setop.table_index; setop.correlated_columns = correlated_columns; - - if (!setop.key_targets.empty()) { - for (idx_t i = 0; i < correlated_columns.size(); i++) { - auto corr = correlated_columns[i]; - auto colref = make_uniq( - correlated_columns[i].type, - ColumnBinding(base_binding.table_index, base_binding.column_index + i)); - setop.key_targets.push_back(std::move(colref)); - } - } - } else if (plan->type == LogicalOperatorType::LOGICAL_MATERIALIZED_CTE) { auto &setop = plan->Cast(); base_binding.table_index = setop.table_index; diff --git a/src/duckdb/src/planner/table_binding.cpp b/src/duckdb/src/planner/table_binding.cpp index e18d899d6..455834a4b 100644 --- a/src/duckdb/src/planner/table_binding.cpp +++ b/src/duckdb/src/planner/table_binding.cpp @@ -16,9 +16,9 @@ namespace duckdb { Binding::Binding(BindingType binding_type, BindingAlias alias_p, vector coltypes, vector colnames, - idx_t index) + idx_t index, LogicalType rowid_type) : binding_type(binding_type), alias(std::move(alias_p)), index(index), types(std::move(coltypes)), - names(std::move(colnames)) { + names(std::move(colnames)), rowid_type(std::move(rowid_type)) { D_ASSERT(types.size() == names.size()); for (idx_t i = 0; i < names.size(); i++) { auto &name = names[i]; @@ -114,23 +114,13 @@ optional_ptr EntryBinding::GetStandardEntry() { TableBinding::TableBinding(const string &alias, vector types_p, vector names_p, vector &bound_column_ids, optional_ptr entry, idx_t index, - virtual_column_map_t virtual_columns_p) - : Binding(BindingType::TABLE, GetAlias(alias, entry), std::move(types_p), std::move(names_p), index), - bound_column_ids(bound_column_ids), entry(entry), virtual_columns(std::move(virtual_columns_p)) { - for (auto &ventry : virtual_columns) { - auto idx = ventry.first; - auto &name = ventry.second.name; - if (idx < VIRTUAL_COLUMN_START) { - throw BinderException( - "Virtual column index must be larger than VIRTUAL_COLUMN_START - found %d for column \"%s\"", idx, - name); - } - if (idx == COLUMN_IDENTIFIER_EMPTY) { - // the empty column cannot be queried by the user - continue; - } - if (name_map.find(name) == name_map.end()) { - name_map[name] = idx; + bool add_row_id) + : Binding(BindingType::TABLE, GetAlias(alias, entry), std::move(types_p), std::move(names_p), index, + (add_row_id && entry) ? entry->Cast().GetRowIdType() : LogicalType::ROW_TYPE), + bound_column_ids(bound_column_ids), entry(entry) { + if (add_row_id) { + if (name_map.find("rowid") == name_map.end()) { + name_map["rowid"] = COLUMN_IDENTIFIER_ROW_ID; } } } @@ -248,10 +238,8 @@ BindResult TableBinding::Bind(ColumnRefExpression &colref, idx_t depth) { } // fetch the type of the column LogicalType col_type; - auto ventry = virtual_columns.find(column_index); - if (ventry != virtual_columns.end()) { - // virtual column - fetch type from there - col_type = ventry->second.type; + if (column_index == COLUMN_IDENTIFIER_ROW_ID) { + col_type = LogicalType(rowid_type); } else { // normal column: fetch type from base column col_type = types[column_index]; diff --git a/src/duckdb/src/planner/table_filter.cpp b/src/duckdb/src/planner/table_filter.cpp index ee6a20ac0..f8544102d 100644 --- a/src/duckdb/src/planner/table_filter.cpp +++ b/src/duckdb/src/planner/table_filter.cpp @@ -27,7 +27,7 @@ void TableFilterSet::PushFilter(const ColumnIndex &col_idx, unique_ptrmaximum_size; - } - // capacity of the previous block can be bigger than the max capacity if we allocate len > max capacity - // for new blocks - try to set it back to the max capacity - if (capacity > ARENA_ALLOCATOR_MAX_CAPACITY) { - capacity = ARENA_ALLOCATOR_MAX_CAPACITY; - } - // if we are below the max capacity - double the size of the block - if (capacity < ARENA_ALLOCATOR_MAX_CAPACITY) { - capacity *= 2; - } - // we double the size until we can fit `len` - // this is generally only relevant if len is very large - while (capacity < min_size) { - capacity *= 2; - } - auto new_chunk = make_unsafe_uniq(allocator, capacity); - if (head) { - head->prev = new_chunk.get(); - new_chunk->next = std::move(head); - } else { - tail = new_chunk.get(); +data_ptr_t ArenaAllocator::Allocate(idx_t len) { + D_ASSERT(!head || head->current_position <= head->maximum_size); + if (!head || head->current_position + len > head->maximum_size) { + idx_t capacity; + // start off with either (1) initial capacity (if we have no block) or (2) capacity of the previous block + if (!head) { + capacity = initial_capacity; + } else { + capacity = head->maximum_size; + } + // capacity of the previous block can be bigger than the max capacity if we allocate len > max capacity + // for new blocks - try to set it back to the max capacity + if (capacity > ARENA_ALLOCATOR_MAX_CAPACITY) { + capacity = ARENA_ALLOCATOR_MAX_CAPACITY; + } + // if we are below the max capacity - double the size of the block + if (capacity < ARENA_ALLOCATOR_MAX_CAPACITY) { + capacity *= 2; + } + // we double the size until we can fit `len` + // this is generally only relevant if len is very large + while (capacity < len) { + capacity *= 2; + } + auto new_chunk = make_unsafe_uniq(allocator, capacity); + if (head) { + head->prev = new_chunk.get(); + new_chunk->next = std::move(head); + } else { + tail = new_chunk.get(); + } + head = std::move(new_chunk); + allocated_size += capacity; } - head = std::move(new_chunk); - allocated_size += capacity; + D_ASSERT(head->current_position + len <= head->maximum_size); + auto result = head->data.get() + head->current_position; + head->current_position += len; + return result; } data_ptr_t ArenaAllocator::Reallocate(data_ptr_t pointer, idx_t old_size, idx_t size) { diff --git a/src/duckdb/src/storage/buffer/block_handle.cpp b/src/duckdb/src/storage/buffer/block_handle.cpp index e0c2ab834..1d1c333b3 100644 --- a/src/duckdb/src/storage/buffer/block_handle.cpp +++ b/src/duckdb/src/storage/buffer/block_handle.cpp @@ -51,10 +51,8 @@ BlockHandle::~BlockHandle() { // NOLINT: allow internal exceptions } else { D_ASSERT(memory_charge.size == 0); } - try { - block_manager.UnregisterBlock(*this); - } catch (...) { - } + + block_manager.UnregisterBlock(*this); } unique_ptr AllocateBlock(BlockManager &block_manager, unique_ptr reusable_buffer, diff --git a/src/duckdb/src/storage/checkpoint/table_data_writer.cpp b/src/duckdb/src/storage/checkpoint/table_data_writer.cpp index ea1a63458..d60ac7fa1 100644 --- a/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +++ b/src/duckdb/src/storage/checkpoint/table_data_writer.cpp @@ -31,15 +31,12 @@ void TableDataWriter::AddRowGroup(RowGroupPointer &&row_group_pointer, unique_pt row_group_pointers.push_back(std::move(row_group_pointer)); } -DatabaseInstance &TableDataWriter::GetDatabase() { - return table.ParentCatalog().GetDatabase(); +TaskScheduler &TableDataWriter::GetScheduler() { + return TaskScheduler::GetScheduler(GetDatabase()); } -unique_ptr TableDataWriter::CreateTaskExecutor() { - if (client_context) { - return make_uniq(*client_context); - } - return make_uniq(TaskScheduler::GetScheduler(GetDatabase())); +DatabaseInstance &TableDataWriter::GetDatabase() { + return table.ParentCatalog().GetDatabase(); } SingleFileTableDataWriter::SingleFileTableDataWriter(SingleFileCheckpointWriter &checkpoint_manager, diff --git a/src/duckdb/src/storage/checkpoint/write_overflow_strings_to_disk.cpp b/src/duckdb/src/storage/checkpoint/write_overflow_strings_to_disk.cpp index bae38218b..c58be3102 100644 --- a/src/duckdb/src/storage/checkpoint/write_overflow_strings_to_disk.cpp +++ b/src/duckdb/src/storage/checkpoint/write_overflow_strings_to_disk.cpp @@ -14,52 +14,29 @@ WriteOverflowStringsToDisk::~WriteOverflowStringsToDisk() { D_ASSERT(Exception::UncaughtException() || offset == 0); } -shared_ptr UncompressedStringSegmentState::GetHandle(BlockManager &manager_p, block_id_t block_id) { +shared_ptr UncompressedStringSegmentState::GetHandle(BlockManager &manager, block_id_t block_id) { lock_guard lock(block_lock); auto entry = handles.find(block_id); if (entry != handles.end()) { return entry->second; } - auto &manager = block_manager ? *block_manager : manager_p; auto result = manager.RegisterBlock(block_id); handles.insert(make_pair(block_id, result)); return result; } -void UncompressedStringSegmentState::RegisterBlock(BlockManager &manager_p, block_id_t block_id) { +void UncompressedStringSegmentState::RegisterBlock(BlockManager &manager, block_id_t block_id) { lock_guard lock(block_lock); auto entry = handles.find(block_id); if (entry != handles.end()) { throw InternalException("UncompressedStringSegmentState::RegisterBlock - block id %llu already exists", block_id); } - auto &manager = block_manager ? *block_manager : manager_p; auto result = manager.RegisterBlock(block_id); handles.insert(make_pair(block_id, std::move(result))); on_disk_blocks.push_back(block_id); } -string UncompressedStringSegmentState::GetSegmentInfo() const { - if (on_disk_blocks.empty()) { - return ""; - } - string result = StringUtil::Join(on_disk_blocks, on_disk_blocks.size(), ", ", - [&](block_id_t block) { return to_string(block); }); - return "Overflow String Block Ids: " + result; -} - -vector UncompressedStringSegmentState::GetAdditionalBlocks() const { - return on_disk_blocks; -} - -void UncompressedStringSegmentState::Cleanup(BlockManager &manager_p) { - auto &manager = block_manager ? *block_manager : manager_p; - for (auto &block_id : on_disk_blocks) { - manager.MarkBlockAsModified(block_id); - } - on_disk_blocks.clear(); -} - void WriteOverflowStringsToDisk::WriteString(UncompressedStringSegmentState &state, string_t string, block_id_t &result_block, int32_t &result_offset) { auto &block_manager = partial_block_manager.GetBlockManager(); @@ -110,6 +87,9 @@ void WriteOverflowStringsToDisk::Flush() { // write to disk auto &block_manager = partial_block_manager.GetBlockManager(); block_manager.Write(handle.GetFileBuffer(), block_id); + + auto lock = partial_block_manager.GetLock(); + partial_block_manager.AddWrittenBlock(block_id); } block_id = INVALID_BLOCK; offset = 0; diff --git a/src/duckdb/src/storage/compression/bitpacking.cpp b/src/duckdb/src/storage/compression/bitpacking.cpp index b03b48b13..af2e35c2d 100644 --- a/src/duckdb/src/storage/compression/bitpacking.cpp +++ b/src/duckdb/src/storage/compression/bitpacking.cpp @@ -375,9 +375,9 @@ idx_t BitpackingFinalAnalyze(AnalyzeState &state) { // Compress //===--------------------------------------------------------------------===// template ::type> -struct BitpackingCompressionState : public CompressionState { +struct BitpackingCompressState : public CompressionState { public: - explicit BitpackingCompressionState(ColumnDataCheckpointData &checkpoint_data, const CompressionInfo &info) + explicit BitpackingCompressState(ColumnDataCheckpointData &checkpoint_data, const CompressionInfo &info) : CompressionState(info), checkpoint_data(checkpoint_data), function(checkpoint_data.GetCompressionFunction(CompressionType::COMPRESSION_BITPACKING)) { CreateEmptySegment(checkpoint_data.GetRowGroup().start); @@ -403,7 +403,7 @@ struct BitpackingCompressionState : public CompressionState { public: struct BitpackingWriter { static void WriteConstant(T constant, idx_t count, void *data_ptr, bool all_invalid) { - auto state = reinterpret_cast *>(data_ptr); + auto state = reinterpret_cast *>(data_ptr); ReserveSpace(state, sizeof(T)); WriteMetaData(state, BitpackingMode::CONSTANT); @@ -414,7 +414,7 @@ struct BitpackingCompressionState : public CompressionState { static void WriteConstantDelta(T_S constant, T frame_of_reference, idx_t count, T *values, bool *validity, void *data_ptr) { - auto state = reinterpret_cast *>(data_ptr); + auto state = reinterpret_cast *>(data_ptr); ReserveSpace(state, 2 * sizeof(T)); WriteMetaData(state, BitpackingMode::CONSTANT_DELTA); @@ -425,7 +425,7 @@ struct BitpackingCompressionState : public CompressionState { } static void WriteDeltaFor(T *values, bool *validity, bitpacking_width_t width, T frame_of_reference, T_S delta_offset, T *original_values, idx_t count, void *data_ptr) { - auto state = reinterpret_cast *>(data_ptr); + auto state = reinterpret_cast *>(data_ptr); auto bp_size = BitpackingPrimitives::GetRequiredSize(count, width); ReserveSpace(state, bp_size + 3 * sizeof(T)); @@ -443,7 +443,7 @@ struct BitpackingCompressionState : public CompressionState { static void WriteFor(T *values, bool *validity, bitpacking_width_t width, T frame_of_reference, idx_t count, void *data_ptr) { - auto state = reinterpret_cast *>(data_ptr); + auto state = reinterpret_cast *>(data_ptr); auto bp_size = BitpackingPrimitives::GetRequiredSize(count, width); ReserveSpace(state, bp_size + 2 * sizeof(T)); @@ -464,19 +464,19 @@ struct BitpackingCompressionState : public CompressionState { ptr += sizeof(T_OUT); } - static void WriteMetaData(BitpackingCompressionState *state, BitpackingMode mode) { + static void WriteMetaData(BitpackingCompressState *state, BitpackingMode mode) { bitpacking_metadata_t metadata {mode, (uint32_t)(state->data_ptr - state->handle.Ptr())}; state->metadata_ptr -= sizeof(bitpacking_metadata_encoded_t); Store(EncodeMeta(metadata), state->metadata_ptr); } - static void ReserveSpace(BitpackingCompressionState *state, idx_t data_bytes) { + static void ReserveSpace(BitpackingCompressState *state, idx_t data_bytes) { idx_t meta_bytes = sizeof(bitpacking_metadata_encoded_t); state->FlushAndCreateSegmentIfFull(data_bytes, meta_bytes); D_ASSERT(state->CanStore(data_bytes, meta_bytes)); } - static void UpdateStats(BitpackingCompressionState *state, idx_t count) { + static void UpdateStats(BitpackingCompressState *state, idx_t count) { state->current_segment->count += count; if (WRITE_STATISTICS && !state->state.all_invalid) { @@ -514,7 +514,7 @@ struct BitpackingCompressionState : public CompressionState { for (idx_t i = 0; i < count; i++) { idx_t idx = vdata.sel->get_index(i); - state.template Update::BitpackingWriter>( + state.template Update::BitpackingWriter>( data[idx], vdata.validity.RowIsValid(idx)); } } @@ -556,7 +556,7 @@ struct BitpackingCompressionState : public CompressionState { } void Finalize() { - state.template Flush::BitpackingWriter>(); + state.template Flush::BitpackingWriter>(); FlushSegment(); current_segment.reset(); } @@ -565,12 +565,12 @@ struct BitpackingCompressionState : public CompressionState { template unique_ptr BitpackingInitCompression(ColumnDataCheckpointData &checkpoint_data, unique_ptr state) { - return make_uniq>(checkpoint_data, state->info); + return make_uniq>(checkpoint_data, state->info); } template void BitpackingCompress(CompressionState &state_p, Vector &scan_vector, idx_t count) { - auto &state = state_p.Cast>(); + auto &state = state_p.Cast>(); UnifiedVectorFormat vdata; scan_vector.ToUnifiedFormat(count, vdata); state.Append(vdata, count); @@ -578,7 +578,7 @@ void BitpackingCompress(CompressionState &state_p, Vector &scan_vector, idx_t co template void BitpackingFinalizeCompress(CompressionState &state_p) { - auto &state = state_p.Cast>(); + auto &state = state_p.Cast>(); state.Finalize(); } @@ -949,42 +949,16 @@ void BitpackingSkip(ColumnSegment &segment, ColumnScanState &state, idx_t skip_c scan_state.Skip(segment, skip_count); } -//===--------------------------------------------------------------------===// -// GetSegmentInfo -//===--------------------------------------------------------------------===// -template -InsertionOrderPreservingMap BitpackingGetSegmentInfo(ColumnSegment &segment) { - map counts; - auto tuple_count = segment.count.load(); - BitpackingScanState scan_state(segment); - for (idx_t i = 0; i < tuple_count; i += BITPACKING_METADATA_GROUP_SIZE) { - if (i) { - scan_state.LoadNextGroup(); - } - counts[scan_state.current_group.mode]++; - } - - InsertionOrderPreservingMap result; - for (auto &it : counts) { - auto &mode = it.first; - auto &count = it.second; - result[EnumUtil::ToString(mode)] = StringUtil::Format("%d", count); - } - return result; -} - //===--------------------------------------------------------------------===// // Get Function //===--------------------------------------------------------------------===// template CompressionFunction GetBitpackingFunction(PhysicalType data_type) { - auto bitpacking = CompressionFunction( - CompressionType::COMPRESSION_BITPACKING, data_type, BitpackingInitAnalyze, BitpackingAnalyze, - BitpackingFinalAnalyze, BitpackingInitCompression, - BitpackingCompress, BitpackingFinalizeCompress, BitpackingInitScan, - BitpackingScan, BitpackingScanPartial, BitpackingFetchRow, BitpackingSkip); - bitpacking.get_segment_info = BitpackingGetSegmentInfo; - return bitpacking; + return CompressionFunction(CompressionType::COMPRESSION_BITPACKING, data_type, BitpackingInitAnalyze, + BitpackingAnalyze, BitpackingFinalAnalyze, + BitpackingInitCompression, BitpackingCompress, + BitpackingFinalizeCompress, BitpackingInitScan, + BitpackingScan, BitpackingScanPartial, BitpackingFetchRow, BitpackingSkip); } CompressionFunction BitpackingFun::GetFunction(PhysicalType type) { diff --git a/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp b/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp index 00aec39da..3215f1b8f 100644 --- a/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +++ b/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp @@ -72,9 +72,8 @@ void UncompressedCompressState::CreateEmptySegment(idx_t row_start) { ColumnSegment::CreateTransientSegment(db, function, type, row_start, info.GetBlockSize(), info.GetBlockSize()); if (type.InternalType() == PhysicalType::VARCHAR) { auto &state = compressed_segment->GetSegmentState()->Cast(); - auto &partial_block_manager = checkpoint_data.GetCheckpointState().GetPartialBlockManager(); - state.block_manager = partial_block_manager.GetBlockManager(); - state.overflow_writer = make_uniq(partial_block_manager); + state.overflow_writer = + make_uniq(checkpoint_data.GetCheckpointState().GetPartialBlockManager()); } current_segment = std::move(compressed_segment); current_segment->InitializeAppend(append_state); diff --git a/src/duckdb/src/storage/compression/fsst.cpp b/src/duckdb/src/storage/compression/fsst.cpp index 0f1dc0d2e..209bf8a5a 100644 --- a/src/duckdb/src/storage/compression/fsst.cpp +++ b/src/duckdb/src/storage/compression/fsst.cpp @@ -513,8 +513,6 @@ struct FSSTScanState : public StringScanState { } buffer_ptr duckdb_fsst_decoder; - void *duckdb_fsst_decoder_ptr = nullptr; - vector decompress_buffer; bitpacking_width_t current_width; @@ -527,8 +525,6 @@ struct FSSTScanState : public StringScanState { unsafe_unique_array delta_decode_buffer; idx_t delta_decode_capacity = 0; - bool all_values_inlined = false; - void StoreLastDelta(uint32_t value, int64_t row) { last_known_index = value; last_known_row = row; @@ -538,8 +534,7 @@ struct FSSTScanState : public StringScanState { last_known_row = -1; } inline string_t DecompressString(StringDictionaryContainer dict, data_ptr_t baseptr, - const bp_delta_offsets_t &offsets, idx_t index, - VectorStringBuffer &str_buffer) const { + const bp_delta_offsets_t &offsets, idx_t index, Vector &result) { uint32_t str_len = bitunpack_buffer[offsets.scan_offset + index]; auto str_ptr = FSSTStorage::FetchStringPointer( dict, baseptr, @@ -548,11 +543,7 @@ struct FSSTScanState : public StringScanState { if (str_len == 0) { return string_t(nullptr, 0); } - if (all_values_inlined) { - return FSSTPrimitives::DecompressInlinedValue(duckdb_fsst_decoder_ptr, str_ptr, str_len); - } else { - return FSSTPrimitives::DecompressValue(duckdb_fsst_decoder_ptr, str_buffer, str_ptr, str_len); - } + return FSSTPrimitives::DecompressValue(duckdb_fsst_decoder.get(), result, str_ptr, str_len, decompress_buffer); } }; @@ -569,11 +560,6 @@ unique_ptr FSSTStorage::StringInitScan(ColumnSegment &segment) if (!retval) { state->duckdb_fsst_decoder = nullptr; } - state->duckdb_fsst_decoder_ptr = state->duckdb_fsst_decoder.get(); - - if (StringStats::HasMaxStringLength(segment.stats.statistics)) { - state->all_values_inlined = StringStats::MaxStringLength(segment.stats.statistics) <= string_t::INLINE_LENGTH; - } return std::move(state); } @@ -679,9 +665,8 @@ void FSSTStorage::StringScanPartial(ColumnSegment &segment, ColumnScanState &sta } } else { // Just decompress - auto &str_buffer = StringVector::GetStringBuffer(result); for (idx_t i = 0; i < scan_count; i++) { - result_data[i + result_offset] = scan_state.DecompressString(dict, baseptr, offsets, i, str_buffer); + result_data[i + result_offset] = scan_state.DecompressString(dict, baseptr, offsets, i, result); } } EndScan(scan_state, offsets, start, scan_count); @@ -705,13 +690,11 @@ void FSSTStorage::Select(ColumnSegment &segment, ColumnScanState &state, idx_t v D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR); - auto &str_buffer = StringVector::GetStringBuffer(result); auto offsets = StartScan(scan_state, base_data, start, vector_count); auto result_data = FlatVector::GetData(result); - for (idx_t i = 0; i < sel_count; i++) { idx_t index = sel.get_index(i); - result_data[i] = scan_state.DecompressString(dict, baseptr, offsets, index, str_buffer); + result_data[i] = scan_state.DecompressString(dict, baseptr, offsets, index, result); } EndScan(scan_state, offsets, start, vector_count); } @@ -756,9 +739,11 @@ void FSSTStorage::StringFetchRow(ColumnSegment &segment, ColumnFetchState &state segment, dict.end, result, base_ptr, UnsafeNumericCast(delta_decode_buffer[offsets.unused_delta_decoded_values]), string_length); - auto &str_buffer = StringVector::GetStringBuffer(result); - result_data[result_idx] = FSSTPrimitives::DecompressValue((void *)&decoder, str_buffer, compressed_string.GetData(), - compressed_string.GetSize()); + vector uncompress_buffer; + auto string_block_limit = StringUncompressed::GetStringBlockLimit(segment.GetBlockManager().GetBlockSize()); + uncompress_buffer.resize(string_block_limit + 1); + result_data[result_idx] = FSSTPrimitives::DecompressValue((void *)&decoder, result, compressed_string.GetData(), + compressed_string.GetSize(), uncompress_buffer); } //===--------------------------------------------------------------------===// diff --git a/src/duckdb/src/storage/compression/numeric_constant.cpp b/src/duckdb/src/storage/compression/numeric_constant.cpp index 34d905b5c..097ab9068 100644 --- a/src/duckdb/src/storage/compression/numeric_constant.cpp +++ b/src/duckdb/src/storage/compression/numeric_constant.cpp @@ -150,7 +150,7 @@ void FiltersNullValues(const TableFilter &filter, bool &filters_nulls, bool &fil } void ConstantFilterValidity(ColumnSegment &segment, ColumnScanState &state, idx_t vector_count, Vector &result, - SelectionVector &sel, idx_t &sel_count, const TableFilter &filter, TableFilterState &) { + SelectionVector &sel, idx_t &sel_count, const TableFilter &filter) { // check what effect the filter has on NULL values bool filters_nulls, filters_valid_values; FiltersNullValues(filter, filters_nulls, filters_valid_values); diff --git a/src/duckdb/src/storage/compression/rle.cpp b/src/duckdb/src/storage/compression/rle.cpp index ffedbbbeb..125ded8f2 100644 --- a/src/duckdb/src/storage/compression/rle.cpp +++ b/src/duckdb/src/storage/compression/rle.cpp @@ -442,7 +442,7 @@ void RLESelect(ColumnSegment &segment, ColumnScanState &state, idx_t vector_coun //===--------------------------------------------------------------------===// template void RLEFilter(ColumnSegment &segment, ColumnScanState &state, idx_t vector_count, Vector &result, SelectionVector &sel, - idx_t &sel_count, const TableFilter &filter, TableFilterState &filter_state) { + idx_t &sel_count, const TableFilter &filter) { auto &scan_state = state.scan_state->Cast>(); auto data = scan_state.handle.Ptr() + segment.GetBlockOffset(); @@ -466,7 +466,7 @@ void RLEFilter(ColumnSegment &segment, ColumnScanState &state, idx_t vector_coun SelectionVector run_matches; scan_state.matching_run_count = total_run_count; - ColumnSegment::FilterSelection(run_matches, run_vector, run_format, filter, filter_state, total_run_count, + ColumnSegment::FilterSelection(run_matches, run_vector, run_format, filter, total_run_count, scan_state.matching_run_count); // for any runs that pass the filter - set the matches to true diff --git a/src/duckdb/src/storage/compression/string_uncompressed.cpp b/src/duckdb/src/storage/compression/string_uncompressed.cpp index 67b7efc4b..9e013f835 100644 --- a/src/duckdb/src/storage/compression/string_uncompressed.cpp +++ b/src/duckdb/src/storage/compression/string_uncompressed.cpp @@ -260,7 +260,9 @@ unique_ptr UncompressedStringStorage::DeserializeState(Deser void UncompressedStringStorage::CleanupState(ColumnSegment &segment) { auto &state = segment.GetSegmentState()->Cast(); auto &block_manager = segment.GetBlockManager(); - state.Cleanup(block_manager); + for (auto &block_id : state.on_disk_blocks) { + block_manager.MarkBlockAsModified(block_id); + } } //===--------------------------------------------------------------------===// diff --git a/src/duckdb/src/storage/compression/zstd.cpp b/src/duckdb/src/storage/compression/zstd.cpp index b3cac8107..fca90c180 100644 --- a/src/duckdb/src/storage/compression/zstd.cpp +++ b/src/duckdb/src/storage/compression/zstd.cpp @@ -474,6 +474,10 @@ class ZSTDCompressionState : public CompressionState { // Write the current page to disk auto &block_manager = partial_block_manager.GetBlockManager(); block_manager.Write(buffer.GetFileBuffer(), block_id); + { + auto lock = partial_block_manager.GetLock(); + partial_block_manager.AddWrittenBlock(block_id); + } } void FlushVector() { diff --git a/src/duckdb/src/storage/data_table.cpp b/src/duckdb/src/storage/data_table.cpp index 620736204..fb9baddf9 100644 --- a/src/duckdb/src/storage/data_table.cpp +++ b/src/duckdb/src/storage/data_table.cpp @@ -49,7 +49,7 @@ DataTable::DataTable(AttachedDatabase &db, shared_ptr table_io_m const string &table, vector column_definitions_p, unique_ptr data) : db(db), info(make_shared_ptr(db, std::move(table_io_manager_p), schema, table)), - column_definitions(std::move(column_definitions_p)), version(DataTableVersion::MAIN_TABLE) { + column_definitions(std::move(column_definitions_p)), is_root(true) { // initialize the table with the existing data from disk, if any auto types = GetTypes(); auto &io_manager = TableIOManager::Get(*this); @@ -64,7 +64,7 @@ DataTable::DataTable(AttachedDatabase &db, shared_ptr table_io_m } DataTable::DataTable(ClientContext &context, DataTable &parent, ColumnDefinition &new_column, Expression &default_value) - : db(parent.db), info(parent.info), version(DataTableVersion::MAIN_TABLE) { + : db(parent.db), info(parent.info), is_root(true) { // add the column definitions from this DataTable for (auto &column_def : parent.column_definitions) { column_definitions.emplace_back(column_def.Copy()); @@ -85,11 +85,11 @@ DataTable::DataTable(ClientContext &context, DataTable &parent, ColumnDefinition local_storage.AddColumn(parent, *this, new_column, default_executor); // this table replaces the previous table, hence the parent is no longer the root DataTable - parent.version = DataTableVersion::ALTERED; + parent.is_root = false; } DataTable::DataTable(ClientContext &context, DataTable &parent, idx_t removed_column) - : db(parent.db), info(parent.info), version(DataTableVersion::MAIN_TABLE) { + : db(parent.db), info(parent.info), is_root(true) { // prevent any new tuples from being added to the parent auto &local_storage = LocalStorage::Get(context, db); lock_guard parent_lock(parent.append_lock); @@ -133,11 +133,11 @@ DataTable::DataTable(ClientContext &context, DataTable &parent, idx_t removed_co local_storage.DropColumn(parent, *this, removed_column); // this table replaces the previous table, hence the parent is no longer the root DataTable - parent.version = DataTableVersion::ALTERED; + parent.is_root = false; } DataTable::DataTable(ClientContext &context, DataTable &parent, BoundConstraint &constraint) - : db(parent.db), info(parent.info), row_groups(parent.row_groups), version(DataTableVersion::MAIN_TABLE) { + : db(parent.db), info(parent.info), row_groups(parent.row_groups), is_root(true) { // ALTER COLUMN to add a new constraint. @@ -157,12 +157,12 @@ DataTable::DataTable(ClientContext &context, DataTable &parent, BoundConstraint VerifyNewConstraint(local_storage, parent, constraint); } local_storage.MoveStorage(parent, *this); - parent.version = DataTableVersion::ALTERED; + parent.is_root = false; } DataTable::DataTable(ClientContext &context, DataTable &parent, idx_t changed_idx, const LogicalType &target_type, const vector &bound_columns, Expression &cast_expr) - : db(parent.db), info(parent.info), version(DataTableVersion::MAIN_TABLE) { + : db(parent.db), info(parent.info), is_root(true) { auto &local_storage = LocalStorage::Get(context, db); // prevent any tuples from being added to the parent lock_guard lock(append_lock); @@ -193,7 +193,7 @@ DataTable::DataTable(ClientContext &context, DataTable &parent, idx_t changed_id local_storage.ChangeType(parent, *this, changed_idx, target_type, bound_columns, cast_expr); // this table replaces the previous table, hence the parent is no longer the root DataTable - parent.version = DataTableVersion::ALTERED; + parent.is_root = false; } vector DataTable::GetTypes() { @@ -228,11 +228,11 @@ TableIOManager &TableIOManager::Get(DataTable &table) { //===--------------------------------------------------------------------===// // Scan //===--------------------------------------------------------------------===// -void DataTable::InitializeScan(ClientContext &context, DuckTransaction &transaction, TableScanState &state, - const vector &column_ids, optional_ptr table_filters) { +void DataTable::InitializeScan(DuckTransaction &transaction, TableScanState &state, + const vector &column_ids, TableFilterSet *table_filters) { state.checkpoint_lock = transaction.SharedLockTable(*info); auto &local_storage = LocalStorage::Get(transaction); - state.Initialize(column_ids, context, table_filters); + state.Initialize(column_ids, table_filters); row_groups->InitializeScan(state.table_state, column_ids, table_filters); local_storage.InitializeScan(*this, state.local_state, table_filters); } @@ -356,15 +356,6 @@ void DataTable::VacuumIndexes() { }); } -void DataTable::VerifyIndexBuffers() { - info->indexes.Scan([&](Index &index) { - if (index.IsBound()) { - index.Cast().VerifyBuffers(); - } - return false; - }); -} - void DataTable::CleanupAppend(transaction_t lowest_transaction, idx_t start, idx_t count) { row_groups->CleanupAppend(lowest_transaction, start, count); } @@ -818,25 +809,10 @@ DataTable::InitializeConstraintState(TableCatalogEntry &table, return make_uniq(table, bound_constraints); } -string DataTable::TableModification() const { - switch (version.load()) { - case DataTableVersion::MAIN_TABLE: - return "no changes"; - case DataTableVersion::ALTERED: - return "altered"; - case DataTableVersion::DROPPED: - return "dropped"; - default: - throw InternalException("Unrecognized table version"); - } -} - void DataTable::InitializeLocalAppend(LocalAppendState &state, TableCatalogEntry &table, ClientContext &context, const vector> &bound_constraints) { - if (!IsMainTable()) { - throw TransactionException("Transaction conflict: attempting to insert into table \"%s\" but it has been %s by " - "a different transaction", - GetTableName(), TableModification()); + if (!is_root) { + throw TransactionException("Transaction conflict: adding entries to a table that has been altered!"); } auto &local_storage = LocalStorage::Get(context, db); local_storage.InitializeAppend(state, *this); @@ -845,10 +821,8 @@ void DataTable::InitializeLocalAppend(LocalAppendState &state, TableCatalogEntry void DataTable::InitializeLocalStorage(LocalAppendState &state, TableCatalogEntry &table, ClientContext &context, const vector> &bound_constraints) { - if (!IsMainTable()) { - throw TransactionException("Transaction conflict: attempting to insert into table \"%s\" but it has been %s by " - "a different transaction", - GetTableName(), TableModification()); + if (!is_root) { + throw TransactionException("Transaction conflict: adding entries to a table that has been altered!"); } auto &local_storage = LocalStorage::Get(context, db); @@ -860,10 +834,8 @@ void DataTable::LocalAppend(LocalAppendState &state, ClientContext &context, Dat if (chunk.size() == 0) { return; } - if (!IsMainTable()) { - throw TransactionException("Transaction conflict: attempting to insert into table \"%s\" but it has been %s by " - "a different transaction", - GetTableName(), TableModification()); + if (!is_root) { + throw TransactionException("write conflict: adding entries to a table that has been altered"); } chunk.Verify(); @@ -882,24 +854,14 @@ void DataTable::FinalizeLocalAppend(LocalAppendState &state) { LocalStorage::FinalizeAppend(state); } -PhysicalIndex DataTable::CreateOptimisticCollection(ClientContext &context, unique_ptr collection) { +OptimisticDataWriter &DataTable::CreateOptimisticWriter(ClientContext &context) { auto &local_storage = LocalStorage::Get(context, db); - return local_storage.CreateOptimisticCollection(*this, std::move(collection)); + return local_storage.CreateOptimisticWriter(*this); } -RowGroupCollection &DataTable::GetOptimisticCollection(ClientContext &context, const PhysicalIndex collection_index) { +void DataTable::FinalizeOptimisticWriter(ClientContext &context, OptimisticDataWriter &writer) { auto &local_storage = LocalStorage::Get(context, db); - return local_storage.GetOptimisticCollection(*this, collection_index); -} - -void DataTable::ResetOptimisticCollection(ClientContext &context, const PhysicalIndex collection_index) { - auto &local_storage = LocalStorage::Get(context, db); - local_storage.ResetOptimisticCollection(*this, collection_index); -} - -OptimisticDataWriter &DataTable::GetOptimisticWriter(ClientContext &context) { - auto &local_storage = LocalStorage::Get(context, db); - return local_storage.GetOptimisticWriter(*this); + local_storage.FinalizeOptimisticWriter(*this, writer); } void DataTable::LocalMerge(ClientContext &context, RowGroupCollection &collection) { @@ -991,10 +953,8 @@ void DataTable::LocalAppend(TableCatalogEntry &table, ClientContext &context, Co void DataTable::AppendLock(TableAppendState &state) { state.append_lock = unique_lock(append_lock); - if (!IsMainTable()) { - throw TransactionException("Transaction conflict: attempting to insert into table \"%s\" but it has been %s by " - "a different transaction", - GetTableName(), TableModification()); + if (!is_root) { + throw TransactionException("Transaction conflict: adding entries to a table that has been altered!"); } state.row_start = NumericCast(row_groups->GetTotalRows()); state.current_row = state.row_start; @@ -1009,7 +969,7 @@ void DataTable::InitializeAppend(DuckTransaction &transaction, TableAppendState } void DataTable::Append(DataChunk &chunk, TableAppendState &state) { - D_ASSERT(IsMainTable()); + D_ASSERT(is_root); row_groups->Append(chunk, state); } @@ -1109,7 +1069,7 @@ void DataTable::CommitAppend(transaction_t commit_id, idx_t row_start, idx_t cou } void DataTable::RevertAppendInternal(idx_t start_row) { - D_ASSERT(IsMainTable()); + D_ASSERT(is_root); // revert appends made to row_groups row_groups->RevertAppendInternal(start_row); } @@ -1138,15 +1098,15 @@ void DataTable::RevertAppend(DuckTransaction &transaction, idx_t start_row, idx_ }); } -#ifdef DEBUG - // Verify that our index memory is stable. + // we need to vacuum the indexes to remove any buffers that are now empty + // due to reverting the appends info->indexes.Scan([&](Index &index) { + // We cant add to unbound indexes anyway, so there is no need to vacuum them if (index.IsBound()) { - index.Cast().VerifyBuffers(); + index.Cast().Vacuum(); } return false; }); -#endif // revert the data table append RevertAppendInternal(start_row); @@ -1210,12 +1170,12 @@ ErrorData DataTable::AppendToIndexes(TableIndexList &indexes, optional_ptr delete_indexes, DataChunk &chunk, row_t row_start, const IndexAppendMode index_append_mode) { - D_ASSERT(IsMainTable()); + D_ASSERT(is_root); return AppendToIndexes(info->indexes, delete_indexes, chunk, row_start, index_append_mode); } void DataTable::RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, row_t row_start) { - D_ASSERT(IsMainTable()); + D_ASSERT(is_root); if (info->indexes.Empty()) { return; } @@ -1228,7 +1188,7 @@ void DataTable::RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, row } void DataTable::RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, Vector &row_identifiers) { - D_ASSERT(IsMainTable()); + D_ASSERT(is_root); info->indexes.Scan([&](Index &index) { if (!index.IsBound()) { throw InternalException("Unbound index found in DataTable::RemoveFromIndexes"); @@ -1240,7 +1200,7 @@ void DataTable::RemoveFromIndexes(TableAppendState &state, DataChunk &chunk, Vec } void DataTable::RemoveFromIndexes(Vector &row_identifiers, idx_t count) { - D_ASSERT(IsMainTable()); + D_ASSERT(is_root); row_groups->RemoveFromIndexes(info->indexes, row_identifiers, count); } @@ -1475,10 +1435,8 @@ void DataTable::Update(TableUpdateState &state, ClientContext &context, Vector & return; } - if (!IsMainTable()) { - throw TransactionException( - "Transaction conflict: attempting to update table \"%s\" but it has been %s by a different transaction", - GetTableName(), TableModification()); + if (!is_root) { + throw TransactionException("Transaction conflict: cannot update a table that has been altered!"); } // first verify that no constraints are violated @@ -1508,12 +1466,12 @@ void DataTable::Update(TableUpdateState &state, ClientContext &context, Vector & // otherwise global storage if (n_global_update > 0) { auto &transaction = DuckTransaction::Get(context, db); - transaction.ModifyTable(*this); updates_slice.Slice(updates, sel_global_update, n_global_update); updates_slice.Flatten(); row_ids_slice.Slice(row_ids, sel_global_update, n_global_update); row_ids_slice.Flatten(n_global_update); + transaction.UpdateCollection(row_groups); row_groups->Update(transaction, FlatVector::GetData(row_ids_slice), column_ids, updates_slice); } } @@ -1527,10 +1485,8 @@ void DataTable::UpdateColumn(TableCatalogEntry &table, ClientContext &context, V return; } - if (!IsMainTable()) { - throw TransactionException( - "Transaction conflict: attempting to update table \"%s\" but it has been %s by a different transaction", - GetTableName(), TableModification()); + if (!is_root) { + throw TransactionException("Transaction conflict: cannot update a table that has been altered!"); } // now perform the actual update @@ -1585,8 +1541,8 @@ void DataTable::Checkpoint(TableDataWriter &writer, Serializer &serializer) { writer.FinalizeTable(global_stats, info.get(), serializer); } -void DataTable::CommitDropColumn(const idx_t column_index) { - row_groups->CommitDropColumn(column_index); +void DataTable::CommitDropColumn(idx_t index) { + row_groups->CommitDropColumn(index); } idx_t DataTable::ColumnCount() const { @@ -1622,10 +1578,8 @@ vector DataTable::GetColumnSegmentInfo() { //===--------------------------------------------------------------------===// void DataTable::AddIndex(const ColumnList &columns, const vector &column_indexes, const IndexConstraintType type, const IndexStorageInfo &index_info) { - if (!IsMainTable()) { - throw TransactionException("Transaction conflict: attempting to add an index to table \"%s\" but it has been " - "%s by a different transaction", - GetTableName(), TableModification()); + if (!IsRoot()) { + throw TransactionException("cannot add an index to a table that has been altered!"); } // Fetch the column types and create bound column reference expressions. diff --git a/src/duckdb/src/storage/local_storage.cpp b/src/duckdb/src/storage/local_storage.cpp index 20497c55e..93dccfcba 100644 --- a/src/duckdb/src/storage/local_storage.cpp +++ b/src/duckdb/src/storage/local_storage.cpp @@ -50,41 +50,31 @@ LocalTableStorage::LocalTableStorage(ClientContext &context, DataTable &table) }); } -LocalTableStorage::LocalTableStorage(ClientContext &context, DataTable &new_data_table, LocalTableStorage &parent, - const idx_t alter_column_index, const LogicalType &target_type, +LocalTableStorage::LocalTableStorage(ClientContext &context, DataTable &new_dt, LocalTableStorage &parent, + idx_t changed_idx, const LogicalType &target_type, const vector &bound_columns, Expression &cast_expr) - : table_ref(new_data_table), allocator(Allocator::Get(new_data_table.db)), deleted_rows(parent.deleted_rows), - optimistic_collections(std::move(parent.optimistic_collections)), - optimistic_writer(new_data_table, parent.optimistic_writer), merged_storage(parent.merged_storage) { - - // Alter the column type. - row_groups = parent.row_groups->AlterType(context, alter_column_index, target_type, bound_columns, cast_expr); - parent.row_groups->CommitDropColumn(alter_column_index); + : table_ref(new_dt), allocator(Allocator::Get(new_dt.db)), deleted_rows(parent.deleted_rows), + optimistic_writer(new_dt, parent.optimistic_writer), optimistic_writers(std::move(parent.optimistic_writers)), + merged_storage(parent.merged_storage) { + row_groups = parent.row_groups->AlterType(context, changed_idx, target_type, bound_columns, cast_expr); parent.row_groups.reset(); - append_indexes.Move(parent.append_indexes); } -LocalTableStorage::LocalTableStorage(DataTable &new_data_table, LocalTableStorage &parent, - const idx_t drop_column_index) - : table_ref(new_data_table), allocator(Allocator::Get(new_data_table.db)), deleted_rows(parent.deleted_rows), - optimistic_collections(std::move(parent.optimistic_collections)), - optimistic_writer(new_data_table, parent.optimistic_writer), merged_storage(parent.merged_storage) { - - // Remove the column from the previous table storage. - row_groups = parent.row_groups->RemoveColumn(drop_column_index); - parent.row_groups->CommitDropColumn(drop_column_index); +LocalTableStorage::LocalTableStorage(DataTable &new_dt, LocalTableStorage &parent, idx_t drop_idx) + : table_ref(new_dt), allocator(Allocator::Get(new_dt.db)), deleted_rows(parent.deleted_rows), + optimistic_writer(new_dt, parent.optimistic_writer), optimistic_writers(std::move(parent.optimistic_writers)), + merged_storage(parent.merged_storage) { + row_groups = parent.row_groups->RemoveColumn(drop_idx); parent.row_groups.reset(); - append_indexes.Move(parent.append_indexes); } LocalTableStorage::LocalTableStorage(ClientContext &context, DataTable &new_dt, LocalTableStorage &parent, ColumnDefinition &new_column, ExpressionExecutor &default_executor) : table_ref(new_dt), allocator(Allocator::Get(new_dt.db)), deleted_rows(parent.deleted_rows), - optimistic_collections(std::move(parent.optimistic_collections)), - optimistic_writer(new_dt, parent.optimistic_writer), merged_storage(parent.merged_storage) { - + optimistic_writer(new_dt, parent.optimistic_writer), optimistic_writers(std::move(parent.optimistic_writers)), + merged_storage(parent.merged_storage) { row_groups = parent.row_groups->AddColumn(context, new_column, default_executor); parent.row_groups.reset(); append_indexes.Move(parent.append_indexes); @@ -219,10 +209,10 @@ void LocalTableStorage::AppendToIndexes(DuckTransaction &transaction, TableAppen if (append_to_table) { table.RevertAppendInternal(NumericCast(append_state.row_start)); } -#ifdef DEBUG - // Verify that our index memory is stable. - table.VerifyIndexBuffers(); -#endif + + // we need to vacuum the indexes to remove any buffers that are now empty + // due to reverting the appends + table.VacuumIndexes(); error.Throw(); } if (append_to_table) { @@ -230,38 +220,34 @@ void LocalTableStorage::AppendToIndexes(DuckTransaction &transaction, TableAppen } } -PhysicalIndex LocalTableStorage::CreateOptimisticCollection(unique_ptr collection) { - lock_guard l(collections_lock); - optimistic_collections.push_back(std::move(collection)); - return PhysicalIndex(optimistic_collections.size() - 1); -} - -RowGroupCollection &LocalTableStorage::GetOptimisticCollection(const PhysicalIndex collection_index) { - lock_guard l(collections_lock); - auto &collection = optimistic_collections[collection_index.index]; - return *collection; +OptimisticDataWriter &LocalTableStorage::CreateOptimisticWriter() { + auto writer = make_uniq(table_ref.get()); + optimistic_writers.push_back(std::move(writer)); + return *optimistic_writers.back(); } -void LocalTableStorage::ResetOptimisticCollection(const PhysicalIndex collection_index) { - lock_guard l(collections_lock); - optimistic_collections[collection_index.index].reset(); -} - -OptimisticDataWriter &LocalTableStorage::GetOptimisticWriter() { - return optimistic_writer; +void LocalTableStorage::FinalizeOptimisticWriter(OptimisticDataWriter &writer) { + // remove the writer from the set of optimistic writers + unique_ptr owned_writer; + for (idx_t i = 0; i < optimistic_writers.size(); i++) { + if (optimistic_writers[i].get() == &writer) { + owned_writer = std::move(optimistic_writers[i]); + optimistic_writers.erase_at(i); + break; + } + } + if (!owned_writer) { + throw InternalException("Error in FinalizeOptimisticWriter - could not find writer"); + } + optimistic_writer.Merge(*owned_writer); } void LocalTableStorage::Rollback() { - optimistic_writer.Rollback(); - - for (auto &collection : optimistic_collections) { - if (!collection) { - continue; - } - collection->CommitDropTable(); + for (auto &writer : optimistic_writers) { + writer->Rollback(); } - optimistic_collections.clear(); - row_groups->CommitDropTable(); + optimistic_writers.clear(); + optimistic_writer.Rollback(); } //===--------------------------------------------------------------------===// @@ -449,24 +435,14 @@ void LocalStorage::LocalMerge(DataTable &table, RowGroupCollection &collection) storage.merged_storage = true; } -PhysicalIndex LocalStorage::CreateOptimisticCollection(DataTable &table, unique_ptr collection) { +OptimisticDataWriter &LocalStorage::CreateOptimisticWriter(DataTable &table) { auto &storage = table_manager.GetOrCreateStorage(context, table); - return storage.CreateOptimisticCollection(std::move(collection)); + return storage.CreateOptimisticWriter(); } -RowGroupCollection &LocalStorage::GetOptimisticCollection(DataTable &table, const PhysicalIndex collection_index) { +void LocalStorage::FinalizeOptimisticWriter(DataTable &table, OptimisticDataWriter &writer) { auto &storage = table_manager.GetOrCreateStorage(context, table); - return storage.GetOptimisticCollection(collection_index); -} - -void LocalStorage::ResetOptimisticCollection(DataTable &table, const PhysicalIndex collection_index) { - auto &storage = table_manager.GetOrCreateStorage(context, table); - storage.ResetOptimisticCollection(collection_index); -} - -OptimisticDataWriter &LocalStorage::GetOptimisticWriter(DataTable &table) { - auto &storage = table_manager.GetOrCreateStorage(context, table); - return storage.GetOptimisticWriter(); + storage.FinalizeOptimisticWriter(writer); } bool LocalStorage::ChangesMade() noexcept { @@ -546,10 +522,8 @@ void LocalStorage::Flush(DataTable &table, LocalTableStorage &storage, optional_ storage.AppendToIndexes(transaction, append_state, true); } -#ifdef DEBUG - // Verify that our index memory is stable. - table.VerifyIndexBuffers(); -#endif + // possibly vacuum any excess index data + table.VacuumIndexes(); } void LocalStorage::Commit(optional_ptr commit_state) { @@ -575,6 +549,7 @@ void LocalStorage::Rollback() { continue; } storage->Rollback(); + entry.second.reset(); } } @@ -625,13 +600,13 @@ void LocalStorage::AddColumn(DataTable &old_dt, DataTable &new_dt, ColumnDefinit table_manager.InsertEntry(new_dt, std::move(new_storage)); } -void LocalStorage::DropColumn(DataTable &old_dt, DataTable &new_dt, const idx_t drop_column_index) { +void LocalStorage::DropColumn(DataTable &old_dt, DataTable &new_dt, idx_t removed_column) { // check if there are any pending appends for the old version of the table auto storage = table_manager.MoveEntry(old_dt); if (!storage) { return; } - auto new_storage = make_shared_ptr(new_dt, *storage, drop_column_index); + auto new_storage = make_shared_ptr(new_dt, *storage, removed_column); table_manager.InsertEntry(new_dt, std::move(new_storage)); } diff --git a/src/duckdb/src/storage/partial_block_manager.cpp b/src/duckdb/src/storage/partial_block_manager.cpp index 7c23df3da..3dbf89760 100644 --- a/src/duckdb/src/storage/partial_block_manager.cpp +++ b/src/duckdb/src/storage/partial_block_manager.cpp @@ -46,7 +46,6 @@ PartialBlockManager::PartialBlockManager(BlockManager &block_manager, PartialBlo // Use the default maximum partial block size with a ratio of 20% free and 80% utilization. max_partial_block_size = NumericCast(block_manager.GetBlockSize() / 5 * 4); } - PartialBlockManager::~PartialBlockManager() { } @@ -133,6 +132,7 @@ void PartialBlockManager::RegisterPartialBlock(PartialBlockAllocation allocation // Flush any block that we're not going to reuse. if (block_to_free) { block_to_free->Flush(free_space); + AddWrittenBlock(block_to_free->state.block_id); } } @@ -161,9 +161,21 @@ void PartialBlockManager::Merge(PartialBlockManager &other) { partially_filled_blocks.insert(make_pair(e.first, std::move(e.second))); } } + // copy over the written blocks + for (auto &block_id : other.written_blocks) { + AddWrittenBlock(block_id); + } + other.written_blocks.clear(); other.partially_filled_blocks.clear(); } +void PartialBlockManager::AddWrittenBlock(block_id_t block) { + auto entry = written_blocks.insert(block); + if (!entry.second) { + throw InternalException("Written block already exists"); + } +} + void PartialBlockManager::ClearBlocks() { for (auto &e : partially_filled_blocks) { e.second->Clear(); @@ -184,6 +196,9 @@ BlockManager &PartialBlockManager::GetBlockManager() const { void PartialBlockManager::Rollback() { ClearBlocks(); + for (auto &block_id : written_blocks) { + block_manager.MarkBlockAsFree(block_id); + } } } // namespace duckdb diff --git a/src/duckdb/src/storage/serialization/serialize_logical_operator.cpp b/src/duckdb/src/storage/serialization/serialize_logical_operator.cpp index c5e81db40..9288cec21 100644 --- a/src/duckdb/src/storage/serialization/serialize_logical_operator.cpp +++ b/src/duckdb/src/storage/serialization/serialize_logical_operator.cpp @@ -252,7 +252,6 @@ void LogicalCTERef::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault>(202, "chunk_types", chunk_types); serializer.WritePropertyWithDefault>(203, "bound_columns", bound_columns); serializer.WriteProperty(204, "materialized_cte", materialized_cte); - serializer.WritePropertyWithDefault(205, "is_recurring", is_recurring); } unique_ptr LogicalCTERef::Deserialize(Deserializer &deserializer) { @@ -262,7 +261,6 @@ unique_ptr LogicalCTERef::Deserialize(Deserializer &deserialize auto bound_columns = deserializer.ReadPropertyWithDefault>(203, "bound_columns"); auto materialized_cte = deserializer.ReadProperty(204, "materialized_cte"); auto result = duckdb::unique_ptr(new LogicalCTERef(table_index, cte_index, std::move(chunk_types), std::move(bound_columns), materialized_cte)); - deserializer.ReadPropertyWithDefault(205, "is_recurring", result->is_recurring); return std::move(result); } @@ -619,8 +617,6 @@ void LogicalRecursiveCTE::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault(201, "ctename", ctename); serializer.WritePropertyWithDefault(202, "table_index", table_index); serializer.WritePropertyWithDefault(203, "column_count", column_count); - serializer.WritePropertyWithDefault>>(204, "key_targets", key_targets); - serializer.WritePropertyWithDefault(205, "ref_recurring", ref_recurring); } unique_ptr LogicalRecursiveCTE::Deserialize(Deserializer &deserializer) { @@ -629,8 +625,6 @@ unique_ptr LogicalRecursiveCTE::Deserialize(Deserializer &deser deserializer.ReadPropertyWithDefault(201, "ctename", result->ctename); deserializer.ReadPropertyWithDefault(202, "table_index", result->table_index); deserializer.ReadPropertyWithDefault(203, "column_count", result->column_count); - deserializer.ReadPropertyWithDefault>>(204, "key_targets", result->key_targets); - deserializer.ReadPropertyWithDefault(205, "ref_recurring", result->ref_recurring); return std::move(result); } diff --git a/src/duckdb/src/storage/serialization/serialize_nodes.cpp b/src/duckdb/src/storage/serialization/serialize_nodes.cpp index 0b0f696a4..10fe3f949 100644 --- a/src/duckdb/src/storage/serialization/serialize_nodes.cpp +++ b/src/duckdb/src/storage/serialization/serialize_nodes.cpp @@ -25,11 +25,12 @@ #include "duckdb/planner/joinside.hpp" #include "duckdb/parser/parsed_data/vacuum_info.hpp" #include "duckdb/planner/table_filter.hpp" -#include "duckdb/common/multi_file/multi_file_options.hpp" -#include "duckdb/common/multi_file/multi_file_reader.hpp" +#include "duckdb/common/multi_file_reader_options.hpp" +#include "duckdb/common/multi_file_reader.hpp" #include "duckdb/execution/operator/csv_scanner/csv_option.hpp" -#include "duckdb/function/table/read_csv.hpp" +#include "duckdb/execution/operator/csv_scanner/csv_reader_options.hpp" #include "duckdb/function/scalar/strftime_format.hpp" +#include "duckdb/function/table/read_csv.hpp" #include "duckdb/common/types/interval.hpp" #include "duckdb/parser/qualified_name.hpp" #include "duckdb/parser/parsed_data/exported_table_data.hpp" @@ -167,6 +168,139 @@ CSVOption CSVOption::Deserialize(Deserializer &deserializer) { return result; } +void CSVReaderOptions::Serialize(Serializer &serializer) const { + serializer.WritePropertyWithDefault(100, "ignore_errors", ignore_errors, false); + serializer.WritePropertyWithDefault(101, "buffer_sample_size", buffer_sample_size); + serializer.WritePropertyWithDefault>(102, "null_str", null_str); + serializer.WriteProperty(103, "compression", compression); + serializer.WritePropertyWithDefault(104, "allow_quoted_nulls", allow_quoted_nulls); + serializer.WriteProperty>(105, "maximum_line_size", maximum_line_size); + serializer.WritePropertyWithDefault(106, "normalize_names", normalize_names); + serializer.WritePropertyWithDefault>(107, "force_not_null", force_not_null); + serializer.WritePropertyWithDefault(108, "all_varchar", all_varchar); + serializer.WritePropertyWithDefault(109, "sample_size_chunks", sample_size_chunks); + serializer.WritePropertyWithDefault(110, "auto_detect", auto_detect); + serializer.WritePropertyWithDefault(111, "file_path", file_path); + serializer.WritePropertyWithDefault(112, "decimal_separator", decimal_separator); + serializer.WritePropertyWithDefault(113, "null_padding", null_padding); + /* [Deleted] (idx_t) "buffer_size" */ + serializer.WriteProperty(115, "file_options", file_options); + serializer.WritePropertyWithDefault>(116, "force_quote", force_quote); + serializer.WritePropertyWithDefault(117, "rejects_table_name", rejects_table_name, "reject_errors"); + serializer.WritePropertyWithDefault(118, "rejects_limit", rejects_limit); + /* [Deleted] (vector) "rejects_recovery_columns" */ + /* [Deleted] (vector) "rejects_recovery_column_ids" */ + serializer.WriteProperty>(121, "delimiter", GetSingleByteDelimiter()); + serializer.WriteProperty>(122, "quote", dialect_options.state_machine_options.quote); + serializer.WriteProperty>(123, "escape", dialect_options.state_machine_options.escape); + serializer.WriteProperty>(124, "header", dialect_options.header); + serializer.WritePropertyWithDefault(125, "num_cols", dialect_options.num_cols); + serializer.WriteProperty>(126, "new_line", dialect_options.state_machine_options.new_line); + serializer.WriteProperty>(127, "skip_rows", dialect_options.skip_rows); + serializer.WriteProperty>>(128, "date_format", dialect_options.date_format); + serializer.WritePropertyWithDefault(129, "sniffer_user_mismatch_error", sniffer_user_mismatch_error); + serializer.WritePropertyWithDefault(130, "parallel", parallel); + serializer.WritePropertyWithDefault>(131, "was_type_manually_set", was_type_manually_set); + serializer.WritePropertyWithDefault>(132, "rejects_scan_name", rejects_scan_name, {"reject_scans"}); + serializer.WritePropertyWithDefault>(133, "name_list", name_list); + serializer.WritePropertyWithDefault>(134, "sql_type_list", sql_type_list); + serializer.WritePropertyWithDefault>(135, "sql_types_per_column", sql_types_per_column); + serializer.WritePropertyWithDefault(136, "columns_set", columns_set, false); + serializer.WritePropertyWithDefault>(137, "comment", dialect_options.state_machine_options.comment, CSVOption('\0')); + serializer.WritePropertyWithDefault(138, "rows_until_header", dialect_options.rows_until_header); + serializer.WritePropertyWithDefault(139, "encoding", encoding); + serializer.WriteProperty>(140, "strict_mode", dialect_options.state_machine_options.strict_mode); + serializer.WriteProperty>(141, "multi_byte_delimiter", GetMultiByteDelimiter()); + serializer.WritePropertyWithDefault(142, "multi_file_reader", multi_file_reader); + serializer.WriteProperty>(143, "buffer_size_option", buffer_size_option); +} + +CSVReaderOptions CSVReaderOptions::Deserialize(Deserializer &deserializer) { + auto ignore_errors = deserializer.ReadPropertyWithExplicitDefault(100, "ignore_errors", false); + auto buffer_sample_size = deserializer.ReadPropertyWithDefault(101, "buffer_sample_size"); + auto null_str = deserializer.ReadPropertyWithDefault>(102, "null_str"); + auto compression = deserializer.ReadProperty(103, "compression"); + auto allow_quoted_nulls = deserializer.ReadPropertyWithDefault(104, "allow_quoted_nulls"); + auto maximum_line_size = deserializer.ReadProperty>(105, "maximum_line_size"); + auto normalize_names = deserializer.ReadPropertyWithDefault(106, "normalize_names"); + auto force_not_null = deserializer.ReadPropertyWithDefault>(107, "force_not_null"); + auto all_varchar = deserializer.ReadPropertyWithDefault(108, "all_varchar"); + auto sample_size_chunks = deserializer.ReadPropertyWithDefault(109, "sample_size_chunks"); + auto auto_detect = deserializer.ReadPropertyWithDefault(110, "auto_detect"); + auto file_path = deserializer.ReadPropertyWithDefault(111, "file_path"); + auto decimal_separator = deserializer.ReadPropertyWithDefault(112, "decimal_separator"); + auto null_padding = deserializer.ReadPropertyWithDefault(113, "null_padding"); + deserializer.ReadDeletedProperty(114, "buffer_size"); + auto file_options = deserializer.ReadProperty(115, "file_options"); + auto force_quote = deserializer.ReadPropertyWithDefault>(116, "force_quote"); + auto rejects_table_name = deserializer.ReadPropertyWithExplicitDefault(117, "rejects_table_name", "reject_errors"); + auto rejects_limit = deserializer.ReadPropertyWithDefault(118, "rejects_limit"); + deserializer.ReadDeletedProperty>(119, "rejects_recovery_columns"); + deserializer.ReadDeletedProperty>(120, "rejects_recovery_column_ids"); + auto dialect_options_state_machine_options_delimiter = deserializer.ReadProperty>(121, "delimiter"); + auto dialect_options_state_machine_options_quote = deserializer.ReadProperty>(122, "quote"); + auto dialect_options_state_machine_options_escape = deserializer.ReadProperty>(123, "escape"); + auto dialect_options_header = deserializer.ReadProperty>(124, "header"); + auto dialect_options_num_cols = deserializer.ReadPropertyWithDefault(125, "num_cols"); + auto dialect_options_state_machine_options_new_line = deserializer.ReadProperty>(126, "new_line"); + auto dialect_options_skip_rows = deserializer.ReadProperty>(127, "skip_rows"); + auto dialect_options_date_format = deserializer.ReadProperty>>(128, "date_format"); + auto sniffer_user_mismatch_error = deserializer.ReadPropertyWithDefault(129, "sniffer_user_mismatch_error"); + auto parallel = deserializer.ReadPropertyWithDefault(130, "parallel"); + auto was_type_manually_set = deserializer.ReadPropertyWithDefault>(131, "was_type_manually_set"); + auto rejects_scan_name = deserializer.ReadPropertyWithExplicitDefault>(132, "rejects_scan_name", {"reject_scans"}); + auto name_list = deserializer.ReadPropertyWithDefault>(133, "name_list"); + auto sql_type_list = deserializer.ReadPropertyWithDefault>(134, "sql_type_list"); + auto sql_types_per_column = deserializer.ReadPropertyWithDefault>(135, "sql_types_per_column"); + auto columns_set = deserializer.ReadPropertyWithExplicitDefault(136, "columns_set", false); + auto dialect_options_state_machine_options_comment = deserializer.ReadPropertyWithExplicitDefault>(137, "comment", CSVOption('\0')); + auto dialect_options_rows_until_header = deserializer.ReadPropertyWithDefault(138, "rows_until_header"); + auto encoding = deserializer.ReadPropertyWithDefault(139, "encoding"); + auto dialect_options_state_machine_options_strict_mode = deserializer.ReadProperty>(140, "strict_mode"); + auto multi_byte_delimiter = deserializer.ReadProperty>(141, "multi_byte_delimiter"); + CSVReaderOptions result(dialect_options_state_machine_options_delimiter, multi_byte_delimiter); + result.ignore_errors = ignore_errors; + result.buffer_sample_size = buffer_sample_size; + result.null_str = std::move(null_str); + result.compression = compression; + result.allow_quoted_nulls = allow_quoted_nulls; + result.maximum_line_size = maximum_line_size; + result.normalize_names = normalize_names; + result.force_not_null = std::move(force_not_null); + result.all_varchar = all_varchar; + result.sample_size_chunks = sample_size_chunks; + result.auto_detect = auto_detect; + result.file_path = std::move(file_path); + result.decimal_separator = std::move(decimal_separator); + result.null_padding = null_padding; + result.file_options = file_options; + result.force_quote = std::move(force_quote); + result.rejects_table_name = std::move(rejects_table_name); + result.rejects_limit = rejects_limit; + result.dialect_options.state_machine_options.quote = dialect_options_state_machine_options_quote; + result.dialect_options.state_machine_options.escape = dialect_options_state_machine_options_escape; + result.dialect_options.header = dialect_options_header; + result.dialect_options.num_cols = dialect_options_num_cols; + result.dialect_options.state_machine_options.new_line = dialect_options_state_machine_options_new_line; + result.dialect_options.skip_rows = dialect_options_skip_rows; + result.dialect_options.date_format = dialect_options_date_format; + result.sniffer_user_mismatch_error = std::move(sniffer_user_mismatch_error); + result.parallel = parallel; + result.was_type_manually_set = std::move(was_type_manually_set); + result.rejects_scan_name = rejects_scan_name; + result.name_list = std::move(name_list); + result.sql_type_list = std::move(sql_type_list); + result.sql_types_per_column = std::move(sql_types_per_column); + result.columns_set = columns_set; + result.dialect_options.state_machine_options.comment = dialect_options_state_machine_options_comment; + result.dialect_options.rows_until_header = dialect_options_rows_until_header; + result.encoding = std::move(encoding); + result.dialect_options.state_machine_options.strict_mode = dialect_options_state_machine_options_strict_mode; + deserializer.ReadPropertyWithDefault(142, "multi_file_reader", result.multi_file_reader); + deserializer.ReadProperty>(143, "buffer_size_option", result.buffer_size_option); + return result; +} + void CaseCheck::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault>(100, "when_expr", when_expr); serializer.WritePropertyWithDefault>(101, "then_expr", then_expr); @@ -251,7 +385,6 @@ void CommonTableExpressionInfo::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault>(100, "aliases", aliases); serializer.WritePropertyWithDefault>(101, "query", query); serializer.WriteProperty(102, "materialized", materialized); - serializer.WritePropertyWithDefault>>(103, "key_targets", key_targets); } unique_ptr CommonTableExpressionInfo::Deserialize(Deserializer &deserializer) { @@ -259,7 +392,6 @@ unique_ptr CommonTableExpressionInfo::Deserialize(Des deserializer.ReadPropertyWithDefault>(100, "aliases", result->aliases); deserializer.ReadPropertyWithDefault>(101, "query", result->query); deserializer.ReadProperty(102, "materialized", result->materialized); - deserializer.ReadPropertyWithDefault>>(103, "key_targets", result->key_targets); return result; } @@ -339,37 +471,37 @@ LogicalType LogicalType::Deserialize(Deserializer &deserializer) { return result; } -void MultiFileOptions::Serialize(Serializer &serializer) const { +void MultiFileReaderBindData::Serialize(Serializer &serializer) const { + serializer.WritePropertyWithDefault(100, "filename_idx", filename_idx); + serializer.WritePropertyWithDefault>(101, "hive_partitioning_indexes", hive_partitioning_indexes); +} + +MultiFileReaderBindData MultiFileReaderBindData::Deserialize(Deserializer &deserializer) { + MultiFileReaderBindData result; + deserializer.ReadPropertyWithDefault(100, "filename_idx", result.filename_idx); + deserializer.ReadPropertyWithDefault>(101, "hive_partitioning_indexes", result.hive_partitioning_indexes); + return result; +} + +void MultiFileReaderOptions::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault(100, "filename", filename); serializer.WritePropertyWithDefault(101, "hive_partitioning", hive_partitioning); serializer.WritePropertyWithDefault(102, "auto_detect_hive_partitioning", auto_detect_hive_partitioning); serializer.WritePropertyWithDefault(103, "union_by_name", union_by_name); serializer.WritePropertyWithDefault(104, "hive_types_autocast", hive_types_autocast); serializer.WritePropertyWithDefault>(105, "hive_types_schema", hive_types_schema); - serializer.WritePropertyWithDefault(106, "filename_column", filename_column, MultiFileOptions::DEFAULT_FILENAME_COLUMN); + serializer.WritePropertyWithDefault(106, "filename_column", filename_column, MultiFileReaderOptions::DEFAULT_FILENAME_COLUMN); } -MultiFileOptions MultiFileOptions::Deserialize(Deserializer &deserializer) { - MultiFileOptions result; +MultiFileReaderOptions MultiFileReaderOptions::Deserialize(Deserializer &deserializer) { + MultiFileReaderOptions result; deserializer.ReadPropertyWithDefault(100, "filename", result.filename); deserializer.ReadPropertyWithDefault(101, "hive_partitioning", result.hive_partitioning); deserializer.ReadPropertyWithDefault(102, "auto_detect_hive_partitioning", result.auto_detect_hive_partitioning); deserializer.ReadPropertyWithDefault(103, "union_by_name", result.union_by_name); deserializer.ReadPropertyWithDefault(104, "hive_types_autocast", result.hive_types_autocast); deserializer.ReadPropertyWithDefault>(105, "hive_types_schema", result.hive_types_schema); - deserializer.ReadPropertyWithExplicitDefault(106, "filename_column", result.filename_column, MultiFileOptions::DEFAULT_FILENAME_COLUMN); - return result; -} - -void MultiFileReaderBindData::Serialize(Serializer &serializer) const { - serializer.WriteProperty(100, "filename_idx", filename_idx); - serializer.WritePropertyWithDefault>(101, "hive_partitioning_indexes", hive_partitioning_indexes); -} - -MultiFileReaderBindData MultiFileReaderBindData::Deserialize(Deserializer &deserializer) { - MultiFileReaderBindData result; - deserializer.ReadProperty(100, "filename_idx", result.filename_idx); - deserializer.ReadPropertyWithDefault>(101, "hive_partitioning_indexes", result.hive_partitioning_indexes); + deserializer.ReadPropertyWithExplicitDefault(106, "filename_column", result.filename_column, MultiFileReaderOptions::DEFAULT_FILENAME_COLUMN); return result; } @@ -433,6 +565,32 @@ QualifiedColumnName QualifiedColumnName::Deserialize(Deserializer &deserializer) return result; } +void ReadCSVData::Serialize(Serializer &serializer) const { + serializer.WritePropertyWithDefault>(100, "files", files); + serializer.WritePropertyWithDefault>(101, "csv_types", csv_types); + serializer.WritePropertyWithDefault>(102, "csv_names", csv_names); + serializer.WritePropertyWithDefault>(103, "return_types", return_types); + serializer.WritePropertyWithDefault>(104, "return_names", return_names); + serializer.WritePropertyWithDefault(105, "filename_col_idx", filename_col_idx); + serializer.WriteProperty(106, "options", options); + serializer.WriteProperty(107, "reader_bind", reader_bind); + serializer.WritePropertyWithDefault>(108, "column_info", column_info); +} + +unique_ptr ReadCSVData::Deserialize(Deserializer &deserializer) { + auto result = duckdb::unique_ptr(new ReadCSVData()); + deserializer.ReadPropertyWithDefault>(100, "files", result->files); + deserializer.ReadPropertyWithDefault>(101, "csv_types", result->csv_types); + deserializer.ReadPropertyWithDefault>(102, "csv_names", result->csv_names); + deserializer.ReadPropertyWithDefault>(103, "return_types", result->return_types); + deserializer.ReadPropertyWithDefault>(104, "return_names", result->return_names); + deserializer.ReadPropertyWithDefault(105, "filename_col_idx", result->filename_col_idx); + deserializer.ReadProperty(106, "options", result->options); + deserializer.ReadProperty(107, "reader_bind", result->reader_bind); + deserializer.ReadPropertyWithDefault>(108, "column_info", result->column_info); + return result; +} + void ReservoirSample::Serialize(Serializer &serializer) const { BlockingSample::Serialize(serializer); serializer.WritePropertyWithDefault(200, "sample_count", sample_count); @@ -478,165 +636,6 @@ unique_ptr SampleOptions::Deserialize(Deserializer &deserializer) return result; } -void SerializedCSVReaderOptions::Serialize(Serializer &serializer) const { - serializer.WritePropertyWithDefault(100, "ignore_errors", options.ignore_errors, false); - serializer.WritePropertyWithDefault(101, "buffer_sample_size", options.buffer_sample_size); - serializer.WritePropertyWithDefault>(102, "null_str", options.null_str); - serializer.WriteProperty(103, "compression", options.compression); - serializer.WritePropertyWithDefault(104, "allow_quoted_nulls", options.allow_quoted_nulls); - serializer.WriteProperty>(105, "maximum_line_size", options.maximum_line_size); - serializer.WritePropertyWithDefault(106, "normalize_names", options.normalize_names); - serializer.WritePropertyWithDefault>(107, "force_not_null", options.force_not_null); - serializer.WritePropertyWithDefault(108, "all_varchar", options.all_varchar); - serializer.WritePropertyWithDefault(109, "sample_size_chunks", options.sample_size_chunks); - serializer.WritePropertyWithDefault(110, "auto_detect", options.auto_detect); - serializer.WritePropertyWithDefault(111, "file_path", options.file_path); - serializer.WritePropertyWithDefault(112, "decimal_separator", options.decimal_separator); - serializer.WritePropertyWithDefault(113, "null_padding", options.null_padding); - /* [Deleted] (idx_t) "buffer_size" */ - serializer.WriteProperty(115, "file_options", file_options); - serializer.WritePropertyWithDefault>(116, "force_quote", options.force_quote); - serializer.WritePropertyWithDefault(117, "rejects_table_name", options.rejects_table_name, "reject_errors"); - serializer.WritePropertyWithDefault(118, "rejects_limit", options.rejects_limit); - /* [Deleted] (vector) "rejects_recovery_columns" */ - /* [Deleted] (vector) "rejects_recovery_column_ids" */ - serializer.WriteProperty>(121, "delimiter", options.GetSingleByteDelimiter()); - serializer.WriteProperty>(122, "quote", options.dialect_options.state_machine_options.quote); - serializer.WriteProperty>(123, "escape", options.dialect_options.state_machine_options.escape); - serializer.WriteProperty>(124, "header", options.dialect_options.header); - serializer.WritePropertyWithDefault(125, "num_cols", options.dialect_options.num_cols); - serializer.WriteProperty>(126, "new_line", options.dialect_options.state_machine_options.new_line); - serializer.WriteProperty>(127, "skip_rows", options.dialect_options.skip_rows); - serializer.WriteProperty>>(128, "date_format", options.dialect_options.date_format); - serializer.WritePropertyWithDefault(129, "sniffer_user_mismatch_error", options.sniffer_user_mismatch_error); - serializer.WritePropertyWithDefault(130, "parallel", options.parallel); - serializer.WritePropertyWithDefault>(131, "was_type_manually_set", options.was_type_manually_set); - serializer.WritePropertyWithDefault>(132, "rejects_scan_name", options.rejects_scan_name, {"reject_scans"}); - serializer.WritePropertyWithDefault>(133, "name_list", options.name_list); - serializer.WritePropertyWithDefault>(134, "sql_type_list", options.sql_type_list); - serializer.WritePropertyWithDefault>(135, "sql_types_per_column", options.sql_types_per_column); - serializer.WritePropertyWithDefault(136, "columns_set", options.columns_set, false); - serializer.WritePropertyWithDefault>(137, "comment", options.dialect_options.state_machine_options.comment, CSVOption('\0')); - serializer.WritePropertyWithDefault(138, "rows_until_header", options.dialect_options.rows_until_header); - serializer.WritePropertyWithDefault(139, "encoding", options.encoding); - serializer.WriteProperty>(140, "strict_mode", options.dialect_options.state_machine_options.strict_mode); - serializer.WriteProperty>(141, "multi_byte_delimiter", options.GetMultiByteDelimiter()); - serializer.WritePropertyWithDefault(142, "multi_file_reader", options.multi_file_reader); - serializer.WriteProperty>(143, "buffer_size_option", options.buffer_size_option); -} - -SerializedCSVReaderOptions SerializedCSVReaderOptions::Deserialize(Deserializer &deserializer) { - auto options_ignore_errors = deserializer.ReadPropertyWithExplicitDefault(100, "ignore_errors", false); - auto options_buffer_sample_size = deserializer.ReadPropertyWithDefault(101, "buffer_sample_size"); - auto options_null_str = deserializer.ReadPropertyWithDefault>(102, "null_str"); - auto options_compression = deserializer.ReadProperty(103, "compression"); - auto options_allow_quoted_nulls = deserializer.ReadPropertyWithDefault(104, "allow_quoted_nulls"); - auto options_maximum_line_size = deserializer.ReadProperty>(105, "maximum_line_size"); - auto options_normalize_names = deserializer.ReadPropertyWithDefault(106, "normalize_names"); - auto options_force_not_null = deserializer.ReadPropertyWithDefault>(107, "force_not_null"); - auto options_all_varchar = deserializer.ReadPropertyWithDefault(108, "all_varchar"); - auto options_sample_size_chunks = deserializer.ReadPropertyWithDefault(109, "sample_size_chunks"); - auto options_auto_detect = deserializer.ReadPropertyWithDefault(110, "auto_detect"); - auto options_file_path = deserializer.ReadPropertyWithDefault(111, "file_path"); - auto options_decimal_separator = deserializer.ReadPropertyWithDefault(112, "decimal_separator"); - auto options_null_padding = deserializer.ReadPropertyWithDefault(113, "null_padding"); - deserializer.ReadDeletedProperty(114, "buffer_size"); - auto file_options = deserializer.ReadProperty(115, "file_options"); - auto options_force_quote = deserializer.ReadPropertyWithDefault>(116, "force_quote"); - auto options_rejects_table_name = deserializer.ReadPropertyWithExplicitDefault(117, "rejects_table_name", "reject_errors"); - auto options_rejects_limit = deserializer.ReadPropertyWithDefault(118, "rejects_limit"); - deserializer.ReadDeletedProperty>(119, "rejects_recovery_columns"); - deserializer.ReadDeletedProperty>(120, "rejects_recovery_column_ids"); - auto options_dialect_options_state_machine_options_delimiter = deserializer.ReadProperty>(121, "delimiter"); - auto options_dialect_options_state_machine_options_quote = deserializer.ReadProperty>(122, "quote"); - auto options_dialect_options_state_machine_options_escape = deserializer.ReadProperty>(123, "escape"); - auto options_dialect_options_header = deserializer.ReadProperty>(124, "header"); - auto options_dialect_options_num_cols = deserializer.ReadPropertyWithDefault(125, "num_cols"); - auto options_dialect_options_state_machine_options_new_line = deserializer.ReadProperty>(126, "new_line"); - auto options_dialect_options_skip_rows = deserializer.ReadProperty>(127, "skip_rows"); - auto options_dialect_options_date_format = deserializer.ReadProperty>>(128, "date_format"); - auto options_sniffer_user_mismatch_error = deserializer.ReadPropertyWithDefault(129, "sniffer_user_mismatch_error"); - auto options_parallel = deserializer.ReadPropertyWithDefault(130, "parallel"); - auto options_was_type_manually_set = deserializer.ReadPropertyWithDefault>(131, "was_type_manually_set"); - auto options_rejects_scan_name = deserializer.ReadPropertyWithExplicitDefault>(132, "rejects_scan_name", {"reject_scans"}); - auto options_name_list = deserializer.ReadPropertyWithDefault>(133, "name_list"); - auto options_sql_type_list = deserializer.ReadPropertyWithDefault>(134, "sql_type_list"); - auto options_sql_types_per_column = deserializer.ReadPropertyWithDefault>(135, "sql_types_per_column"); - auto options_columns_set = deserializer.ReadPropertyWithExplicitDefault(136, "columns_set", false); - auto options_dialect_options_state_machine_options_comment = deserializer.ReadPropertyWithExplicitDefault>(137, "comment", CSVOption('\0')); - auto options_dialect_options_rows_until_header = deserializer.ReadPropertyWithDefault(138, "rows_until_header"); - auto options_encoding = deserializer.ReadPropertyWithDefault(139, "encoding"); - auto options_dialect_options_state_machine_options_strict_mode = deserializer.ReadProperty>(140, "strict_mode"); - auto options_multi_byte_delimiter = deserializer.ReadProperty>(141, "multi_byte_delimiter"); - SerializedCSVReaderOptions result(options_dialect_options_state_machine_options_delimiter, options_multi_byte_delimiter); - result.options.ignore_errors = options_ignore_errors; - result.options.buffer_sample_size = options_buffer_sample_size; - result.options.null_str = std::move(options_null_str); - result.options.compression = options_compression; - result.options.allow_quoted_nulls = options_allow_quoted_nulls; - result.options.maximum_line_size = options_maximum_line_size; - result.options.normalize_names = options_normalize_names; - result.options.force_not_null = std::move(options_force_not_null); - result.options.all_varchar = options_all_varchar; - result.options.sample_size_chunks = options_sample_size_chunks; - result.options.auto_detect = options_auto_detect; - result.options.file_path = std::move(options_file_path); - result.options.decimal_separator = std::move(options_decimal_separator); - result.options.null_padding = options_null_padding; - result.file_options = file_options; - result.options.force_quote = std::move(options_force_quote); - result.options.rejects_table_name = std::move(options_rejects_table_name); - result.options.rejects_limit = options_rejects_limit; - result.options.dialect_options.state_machine_options.quote = options_dialect_options_state_machine_options_quote; - result.options.dialect_options.state_machine_options.escape = options_dialect_options_state_machine_options_escape; - result.options.dialect_options.header = options_dialect_options_header; - result.options.dialect_options.num_cols = options_dialect_options_num_cols; - result.options.dialect_options.state_machine_options.new_line = options_dialect_options_state_machine_options_new_line; - result.options.dialect_options.skip_rows = options_dialect_options_skip_rows; - result.options.dialect_options.date_format = options_dialect_options_date_format; - result.options.sniffer_user_mismatch_error = std::move(options_sniffer_user_mismatch_error); - result.options.parallel = options_parallel; - result.options.was_type_manually_set = std::move(options_was_type_manually_set); - result.options.rejects_scan_name = options_rejects_scan_name; - result.options.name_list = std::move(options_name_list); - result.options.sql_type_list = std::move(options_sql_type_list); - result.options.sql_types_per_column = std::move(options_sql_types_per_column); - result.options.columns_set = options_columns_set; - result.options.dialect_options.state_machine_options.comment = options_dialect_options_state_machine_options_comment; - result.options.dialect_options.rows_until_header = options_dialect_options_rows_until_header; - result.options.encoding = std::move(options_encoding); - result.options.dialect_options.state_machine_options.strict_mode = options_dialect_options_state_machine_options_strict_mode; - deserializer.ReadPropertyWithDefault(142, "multi_file_reader", result.options.multi_file_reader); - deserializer.ReadProperty>(143, "buffer_size_option", result.options.buffer_size_option); - return result; -} - -void SerializedReadCSVData::Serialize(Serializer &serializer) const { - serializer.WritePropertyWithDefault>(100, "files", files); - serializer.WritePropertyWithDefault>(101, "csv_types", csv_types); - serializer.WritePropertyWithDefault>(102, "csv_names", csv_names); - serializer.WritePropertyWithDefault>(103, "return_types", return_types); - serializer.WritePropertyWithDefault>(104, "return_names", return_names); - serializer.WritePropertyWithDefault(105, "filename_col_idx", filename_col_idx); - serializer.WriteProperty(106, "options", options); - serializer.WriteProperty(107, "reader_bind", reader_bind); - serializer.WritePropertyWithDefault>(108, "column_info", column_info); -} - -SerializedReadCSVData SerializedReadCSVData::Deserialize(Deserializer &deserializer) { - SerializedReadCSVData result; - deserializer.ReadPropertyWithDefault>(100, "files", result.files); - deserializer.ReadPropertyWithDefault>(101, "csv_types", result.csv_types); - deserializer.ReadPropertyWithDefault>(102, "csv_names", result.csv_names); - deserializer.ReadPropertyWithDefault>(103, "return_types", result.return_types); - deserializer.ReadPropertyWithDefault>(104, "return_names", result.return_names); - deserializer.ReadPropertyWithDefault(105, "filename_col_idx", result.filename_col_idx); - deserializer.ReadProperty(106, "options", result.options); - deserializer.ReadProperty(107, "reader_bind", result.reader_bind); - deserializer.ReadPropertyWithDefault>(108, "column_info", result.column_info); - return result; -} - void StrpTimeFormat::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault(100, "format_specifier", format_specifier); } @@ -648,12 +647,12 @@ StrpTimeFormat StrpTimeFormat::Deserialize(Deserializer &deserializer) { } void TableFilterSet::Serialize(Serializer &serializer) const { - serializer.WritePropertyWithDefault>>(100, "filters", filters); + serializer.WritePropertyWithDefault>>(100, "filters", filters); } TableFilterSet TableFilterSet::Deserialize(Deserializer &deserializer) { TableFilterSet result; - deserializer.ReadPropertyWithDefault>>(100, "filters", result.filters); + deserializer.ReadPropertyWithDefault>>(100, "filters", result.filters); return result; } diff --git a/src/duckdb/src/storage/serialization/serialize_parse_info.cpp b/src/duckdb/src/storage/serialization/serialize_parse_info.cpp index 7a9d7b3f9..ccf98a0ce 100644 --- a/src/duckdb/src/storage/serialization/serialize_parse_info.cpp +++ b/src/duckdb/src/storage/serialization/serialize_parse_info.cpp @@ -133,9 +133,6 @@ unique_ptr AlterTableInfo::Deserialize(Deserializer &deserializer) { case AlterTableType::ADD_CONSTRAINT: result = AddConstraintInfo::Deserialize(deserializer); break; - case AlterTableType::ADD_FIELD: - result = AddFieldInfo::Deserialize(deserializer); - break; case AlterTableType::ALTER_COLUMN_TYPE: result = ChangeColumnTypeInfo::Deserialize(deserializer); break; @@ -148,15 +145,9 @@ unique_ptr AlterTableInfo::Deserialize(Deserializer &deserializer) { case AlterTableType::REMOVE_COLUMN: result = RemoveColumnInfo::Deserialize(deserializer); break; - case AlterTableType::REMOVE_FIELD: - result = RemoveFieldInfo::Deserialize(deserializer); - break; case AlterTableType::RENAME_COLUMN: result = RenameColumnInfo::Deserialize(deserializer); break; - case AlterTableType::RENAME_FIELD: - result = RenameFieldInfo::Deserialize(deserializer); - break; case AlterTableType::RENAME_TABLE: result = RenameTableInfo::Deserialize(deserializer); break; @@ -166,12 +157,6 @@ unique_ptr AlterTableInfo::Deserialize(Deserializer &deserializer) { case AlterTableType::SET_NOT_NULL: result = SetNotNullInfo::Deserialize(deserializer); break; - case AlterTableType::SET_PARTITIONED_BY: - result = SetPartitionedByInfo::Deserialize(deserializer); - break; - case AlterTableType::SET_SORTED_BY: - result = SetSortedByInfo::Deserialize(deserializer); - break; default: throw SerializationException("Unsupported type for deserialization of AlterTableInfo!"); } @@ -220,21 +205,6 @@ unique_ptr AddConstraintInfo::Deserialize(Deserializer &deserial return std::move(result); } -void AddFieldInfo::Serialize(Serializer &serializer) const { - AlterTableInfo::Serialize(serializer); - serializer.WriteProperty(400, "new_field", new_field); - serializer.WritePropertyWithDefault(401, "if_field_not_exists", if_field_not_exists); - serializer.WritePropertyWithDefault>(402, "column_path", column_path); -} - -unique_ptr AddFieldInfo::Deserialize(Deserializer &deserializer) { - auto new_field = deserializer.ReadProperty(400, "new_field"); - auto result = duckdb::unique_ptr(new AddFieldInfo(std::move(new_field))); - deserializer.ReadPropertyWithDefault(401, "if_field_not_exists", result->if_field_not_exists); - deserializer.ReadPropertyWithDefault>(402, "column_path", result->column_path); - return std::move(result); -} - void AlterForeignKeyInfo::Serialize(Serializer &serializer) const { AlterTableInfo::Serialize(serializer); serializer.WritePropertyWithDefault(400, "fk_table", fk_table); @@ -452,21 +422,6 @@ unique_ptr RemoveColumnInfo::Deserialize(Deserializer &deseriali return std::move(result); } -void RemoveFieldInfo::Serialize(Serializer &serializer) const { - AlterTableInfo::Serialize(serializer); - serializer.WritePropertyWithDefault>(400, "column_path", column_path); - serializer.WritePropertyWithDefault(401, "if_column_exists", if_column_exists); - serializer.WritePropertyWithDefault(402, "cascade", cascade); -} - -unique_ptr RemoveFieldInfo::Deserialize(Deserializer &deserializer) { - auto result = duckdb::unique_ptr(new RemoveFieldInfo()); - deserializer.ReadPropertyWithDefault>(400, "column_path", result->column_path); - deserializer.ReadPropertyWithDefault(401, "if_column_exists", result->if_column_exists); - deserializer.ReadPropertyWithDefault(402, "cascade", result->cascade); - return std::move(result); -} - void RenameColumnInfo::Serialize(Serializer &serializer) const { AlterTableInfo::Serialize(serializer); serializer.WritePropertyWithDefault(400, "old_name", old_name); @@ -480,19 +435,6 @@ unique_ptr RenameColumnInfo::Deserialize(Deserializer &deseriali return std::move(result); } -void RenameFieldInfo::Serialize(Serializer &serializer) const { - AlterTableInfo::Serialize(serializer); - serializer.WritePropertyWithDefault>(400, "column_path", column_path); - serializer.WritePropertyWithDefault(401, "new_name", new_name); -} - -unique_ptr RenameFieldInfo::Deserialize(Deserializer &deserializer) { - auto result = duckdb::unique_ptr(new RenameFieldInfo()); - deserializer.ReadPropertyWithDefault>(400, "column_path", result->column_path); - deserializer.ReadPropertyWithDefault(401, "new_name", result->new_name); - return std::move(result); -} - void RenameTableInfo::Serialize(Serializer &serializer) const { AlterTableInfo::Serialize(serializer); serializer.WritePropertyWithDefault(400, "new_table_name", new_table_name); @@ -567,28 +509,6 @@ unique_ptr SetNotNullInfo::Deserialize(Deserializer &deserialize return std::move(result); } -void SetPartitionedByInfo::Serialize(Serializer &serializer) const { - AlterTableInfo::Serialize(serializer); - serializer.WritePropertyWithDefault>>(400, "partition_keys", partition_keys); -} - -unique_ptr SetPartitionedByInfo::Deserialize(Deserializer &deserializer) { - auto result = duckdb::unique_ptr(new SetPartitionedByInfo()); - deserializer.ReadPropertyWithDefault>>(400, "partition_keys", result->partition_keys); - return std::move(result); -} - -void SetSortedByInfo::Serialize(Serializer &serializer) const { - AlterTableInfo::Serialize(serializer); - serializer.WritePropertyWithDefault>(400, "orders", orders); -} - -unique_ptr SetSortedByInfo::Deserialize(Deserializer &deserializer) { - auto result = duckdb::unique_ptr(new SetSortedByInfo()); - deserializer.ReadPropertyWithDefault>(400, "orders", result->orders); - return std::move(result); -} - void TransactionInfo::Serialize(Serializer &serializer) const { ParseInfo::Serialize(serializer); serializer.WriteProperty(200, "type", type); diff --git a/src/duckdb/src/storage/serialization/serialize_parsed_expression.cpp b/src/duckdb/src/storage/serialization/serialize_parsed_expression.cpp index 94777d97e..a5c79b3d9 100644 --- a/src/duckdb/src/storage/serialization/serialize_parsed_expression.cpp +++ b/src/duckdb/src/storage/serialization/serialize_parsed_expression.cpp @@ -292,7 +292,7 @@ void StarExpression::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault>>(202, "replace_list", replace_list); serializer.WritePropertyWithDefault(203, "columns", columns); serializer.WritePropertyWithDefault>(204, "expr", expr); - /* [Deleted] (bool) "unpacked" */ + serializer.WritePropertyWithDefault(205, "unpacked", unpacked, false); serializer.WritePropertyWithDefault(206, "qualified_exclude_list", SerializedQualifiedExcludeList(), qualified_column_set_t()); serializer.WritePropertyWithDefault>(207, "rename_list", rename_list, qualified_column_map_t()); } @@ -305,9 +305,14 @@ unique_ptr StarExpression::Deserialize(Deserializer &deseriali auto expr = deserializer.ReadPropertyWithDefault>(204, "expr"); auto unpacked = deserializer.ReadPropertyWithExplicitDefault(205, "unpacked", false); auto qualified_exclude_list = deserializer.ReadPropertyWithExplicitDefault(206, "qualified_exclude_list", qualified_column_set_t()); - auto rename_list = deserializer.ReadPropertyWithExplicitDefault>(207, "rename_list", qualified_column_map_t()); - auto result = StarExpression::DeserializeStarExpression(std::move(relation_name), exclude_list, std::move(replace_list), columns, std::move(expr), unpacked, qualified_exclude_list, std::move(rename_list)); - return result; + auto result = duckdb::unique_ptr(new StarExpression(exclude_list, qualified_exclude_list)); + result->relation_name = std::move(relation_name); + result->replace_list = std::move(replace_list); + result->columns = columns; + result->expr = std::move(expr); + result->unpacked = unpacked; + deserializer.ReadPropertyWithExplicitDefault>(207, "rename_list", result->rename_list, qualified_column_map_t()); + return std::move(result); } void SubqueryExpression::Serialize(Serializer &serializer) const { diff --git a/src/duckdb/src/storage/serialization/serialize_query_node.cpp b/src/duckdb/src/storage/serialization/serialize_query_node.cpp index 20b05401d..4aa4ebb77 100644 --- a/src/duckdb/src/storage/serialization/serialize_query_node.cpp +++ b/src/duckdb/src/storage/serialization/serialize_query_node.cpp @@ -65,7 +65,6 @@ void RecursiveCTENode::Serialize(Serializer &serializer) const { serializer.WritePropertyWithDefault>(202, "left", left); serializer.WritePropertyWithDefault>(203, "right", right); serializer.WritePropertyWithDefault>(204, "aliases", aliases); - serializer.WritePropertyWithDefault>>(205, "key_targets", key_targets); } unique_ptr RecursiveCTENode::Deserialize(Deserializer &deserializer) { @@ -75,7 +74,6 @@ unique_ptr RecursiveCTENode::Deserialize(Deserializer &deserializer) deserializer.ReadPropertyWithDefault>(202, "left", result->left); deserializer.ReadPropertyWithDefault>(203, "right", result->right); deserializer.ReadPropertyWithDefault>(204, "aliases", result->aliases); - deserializer.ReadPropertyWithDefault>>(205, "key_targets", result->key_targets); return std::move(result); } diff --git a/src/duckdb/src/storage/serialization/serialize_tableref.cpp b/src/duckdb/src/storage/serialization/serialize_tableref.cpp index 97e5c3fda..0283418fc 100644 --- a/src/duckdb/src/storage/serialization/serialize_tableref.cpp +++ b/src/duckdb/src/storage/serialization/serialize_tableref.cpp @@ -6,7 +6,6 @@ #include "duckdb/common/serializer/serializer.hpp" #include "duckdb/common/serializer/deserializer.hpp" #include "duckdb/parser/tableref/list.hpp" -#include "duckdb/parser/tableref/at_clause.hpp" namespace duckdb { @@ -60,25 +59,12 @@ unique_ptr TableRef::Deserialize(Deserializer &deserializer) { return result; } -void AtClause::Serialize(Serializer &serializer) const { - serializer.WritePropertyWithDefault(1, "unit", unit); - serializer.WritePropertyWithDefault>(2, "expr", expr); -} - -unique_ptr AtClause::Deserialize(Deserializer &deserializer) { - auto unit = deserializer.ReadPropertyWithDefault(1, "unit"); - auto expr = deserializer.ReadPropertyWithDefault>(2, "expr"); - auto result = duckdb::unique_ptr(new AtClause(std::move(unit), std::move(expr))); - return result; -} - void BaseTableRef::Serialize(Serializer &serializer) const { TableRef::Serialize(serializer); serializer.WritePropertyWithDefault(200, "schema_name", schema_name); serializer.WritePropertyWithDefault(201, "table_name", table_name); serializer.WritePropertyWithDefault>(202, "column_name_alias", column_name_alias); serializer.WritePropertyWithDefault(203, "catalog_name", catalog_name); - serializer.WritePropertyWithDefault>(204, "at_clause", at_clause); } unique_ptr BaseTableRef::Deserialize(Deserializer &deserializer) { @@ -87,7 +73,6 @@ unique_ptr BaseTableRef::Deserialize(Deserializer &deserializer) { deserializer.ReadPropertyWithDefault(201, "table_name", result->table_name); deserializer.ReadPropertyWithDefault>(202, "column_name_alias", result->column_name_alias); deserializer.ReadPropertyWithDefault(203, "catalog_name", result->catalog_name); - deserializer.ReadPropertyWithDefault>(204, "at_clause", result->at_clause); return std::move(result); } diff --git a/src/duckdb/src/storage/statistics/string_stats.cpp b/src/duckdb/src/storage/statistics/string_stats.cpp index 230944ab1..ae6a1e5fe 100644 --- a/src/duckdb/src/storage/statistics/string_stats.cpp +++ b/src/duckdb/src/storage/statistics/string_stats.cpp @@ -91,12 +91,6 @@ void StringStats::ResetMaxStringLength(BaseStatistics &stats) { StringStats::GetDataUnsafe(stats).has_max_string_length = false; } -void StringStats::SetMaxStringLength(BaseStatistics &stats, uint32_t length) { - auto &data = StringStats::GetDataUnsafe(stats); - data.has_max_string_length = true; - data.max_string_length = length; -} - void StringStats::SetContainsUnicode(BaseStatistics &stats) { StringStats::GetDataUnsafe(stats).has_unicode = true; } diff --git a/src/duckdb/src/storage/storage_info.cpp b/src/duckdb/src/storage/storage_info.cpp index bc10c812e..c7bbb4425 100644 --- a/src/duckdb/src/storage/storage_info.cpp +++ b/src/duckdb/src/storage/storage_info.cpp @@ -7,7 +7,7 @@ namespace duckdb { const uint64_t VERSION_NUMBER = 64; const uint64_t VERSION_NUMBER_LOWER = 64; -const uint64_t VERSION_NUMBER_UPPER = 66; +const uint64_t VERSION_NUMBER_UPPER = 65; static_assert(VERSION_NUMBER_LOWER <= VERSION_NUMBER, "Check on VERSION_NUMBER lower bound"); static_assert(VERSION_NUMBER <= VERSION_NUMBER_UPPER, "Check on VERSION_NUMBER upper bound"); @@ -79,14 +79,13 @@ static const StorageVersionInfo storage_version_info[] = { {"v1.2.0", 65}, {"v1.2.1", 65}, {"v1.2.2", 65}, - {"v1.3.0", 66}, {nullptr, 0} }; // END OF STORAGE VERSION INFO static_assert(DEFAULT_STORAGE_VERSION_INFO == VERSION_NUMBER, "Check on VERSION_INFO"); // START OF SERIALIZATION VERSION INFO -const uint64_t LATEST_SERIALIZATION_VERSION_INFO = 5; +const uint64_t LATEST_SERIALIZATION_VERSION_INFO = 4; const uint64_t DEFAULT_SERIALIZATION_VERSION_INFO = 1; static const SerializationVersionInfo serialization_version_info[] = { {"v0.10.0", 1}, @@ -101,8 +100,7 @@ static const SerializationVersionInfo serialization_version_info[] = { {"v1.2.0", 4}, {"v1.2.1", 4}, {"v1.2.2", 4}, - {"v1.3.0", 5}, - {"latest", 5}, + {"latest", 4}, {nullptr, 0} }; // END OF SERIALIZATION VERSION INFO @@ -114,9 +112,10 @@ static_assert(DEFAULT_SERIALIZATION_VERSION_INFO <= LATEST_SERIALIZATION_VERSION string GetStorageVersionName(idx_t serialization_version) { if (serialization_version < 4) { // special handling for lower serialization versions - return "v1.0.0+"; + return "v1.0.0 - v1.1.3"; } optional_idx min_idx; + optional_idx max_idx; for (idx_t i = 0; serialization_version_info[i].version_name; i++) { if (strcmp(serialization_version_info[i].version_name, "latest") == 0) { continue; @@ -126,6 +125,8 @@ string GetStorageVersionName(idx_t serialization_version) { } if (!min_idx.IsValid()) { min_idx = i; + } else { + max_idx = i; } } if (!min_idx.IsValid()) { @@ -133,7 +134,11 @@ string GetStorageVersionName(idx_t serialization_version) { return "--UNKNOWN--"; } auto min_name = serialization_version_info[min_idx.GetIndex()].version_name; - return string(min_name) + "+"; + if (!max_idx.IsValid()) { + return min_name; + } + auto max_name = serialization_version_info[max_idx.GetIndex()].version_name; + return string(min_name) + " - " + string(max_name); } optional_idx GetStorageVersion(const char *version_string) { diff --git a/src/duckdb/src/storage/table/array_column_data.cpp b/src/duckdb/src/storage/table/array_column_data.cpp index c4c556984..148f3fd84 100644 --- a/src/duckdb/src/storage/table/array_column_data.cpp +++ b/src/duckdb/src/storage/table/array_column_data.cpp @@ -85,95 +85,16 @@ idx_t ArrayColumnData::ScanCommitted(idx_t vector_index, ColumnScanState &state, return ScanCount(state, result, scan_count); } -idx_t ArrayColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset) { +idx_t ArrayColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count) { // Scan validity - auto scan_count = validity.ScanCount(state.child_states[0], result, count, result_offset); + auto scan_count = validity.ScanCount(state.child_states[0], result, count); auto array_size = ArrayType::GetSize(type); // Scan child column auto &child_vec = ArrayVector::GetEntry(result); - child_column->ScanCount(state.child_states[1], child_vec, count * array_size, result_offset * array_size); + child_column->ScanCount(state.child_states[1], child_vec, count * array_size); return scan_count; } -void ArrayColumnData::Select(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, - SelectionVector &sel, idx_t sel_count) { - bool is_supported = !child_column->type.IsNested(); - if (!is_supported) { - ColumnData::Select(transaction, vector_index, state, result, sel, sel_count); - return; - } - // the below specialized Select implementation selects only the required arrays, and skips over non-required data - // note that this implementation is not necessarily faster than the naive implementation of scanning + slicing - // this optimization is better: - // (1) the fewer consecutive ranges we are scanning - // (2) the larger the arrays are - // below we try to select the optimal variant - - // first count the number of consecutive requests we must make - idx_t consecutive_ranges = 0; - for (idx_t i = 0; i < sel_count; i++) { - idx_t start_idx = sel.get_index(i); - idx_t end_idx = start_idx + 1; - for (; i + 1 < sel_count; i++) { - auto next_idx = sel.get_index(i + 1); - if (next_idx > end_idx) { - // not consecutive - break - break; - } - end_idx = next_idx; - } - consecutive_ranges++; - } - - auto target_count = GetVectorCount(vector_index); - - // experimentally, we want to allow around one consecutive range every ~2 array size - // for array size = 10, we allow 5 consecutive ranges - // for array size = 100, we allow 50 consecutive ranges - auto array_size = ArrayType::GetSize(type); - auto allowed_ranges = array_size / 2; - if (allowed_ranges < consecutive_ranges) { - // fallback to select + filter - ColumnData::Select(transaction, vector_index, state, result, sel, sel_count); - return; - } - - idx_t current_offset = 0; - idx_t current_position = 0; - auto &child_vec = ArrayVector::GetEntry(result); - for (idx_t i = 0; i < sel_count; i++) { - idx_t start_idx = sel.get_index(i); - idx_t end_idx = start_idx + 1; - for (; i + 1 < sel_count; i++) { - auto next_idx = sel.get_index(i + 1); - if (next_idx > end_idx) { - // not consecutive - break - break; - } - end_idx = next_idx + 1; - } - if (start_idx > current_position) { - // skip forward - idx_t skip_amount = start_idx - current_position; - validity.Skip(state.child_states[0], skip_amount); - child_column->Skip(state.child_states[1], skip_amount * array_size); - } - // scan into the result array - idx_t scan_count = end_idx - start_idx; - validity.ScanCount(state.child_states[0], result, scan_count, current_offset); - child_column->ScanCount(state.child_states[1], child_vec, scan_count * array_size, current_offset * array_size); - // move the current position forward - current_offset += scan_count; - current_position = end_idx; - } - // if there is any remaining at the end - skip any trailing rows - if (current_position < target_count) { - idx_t skip_amount = target_count - current_position; - validity.Skip(state.child_states[0], skip_amount); - child_column->Skip(state.child_states[1], skip_amount * array_size); - } -} - void ArrayColumnData::Skip(ColumnScanState &state, idx_t count) { // Skip validity validity.Skip(state.child_states[0], count); diff --git a/src/duckdb/src/storage/table/column_checkpoint_state.cpp b/src/duckdb/src/storage/table/column_checkpoint_state.cpp index d2fce922a..a67daa060 100644 --- a/src/duckdb/src/storage/table/column_checkpoint_state.cpp +++ b/src/duckdb/src/storage/table/column_checkpoint_state.cpp @@ -71,6 +71,7 @@ void PartialBlockForCheckpoint::Flush(const idx_t free_space_left) { } } } + Clear(); } diff --git a/src/duckdb/src/storage/table/column_data.cpp b/src/duckdb/src/storage/table/column_data.cpp index e55d33c03..eadc5152b 100644 --- a/src/duckdb/src/storage/table/column_data.cpp +++ b/src/duckdb/src/storage/table/column_data.cpp @@ -166,8 +166,7 @@ void ColumnData::BeginScanVectorInternal(ColumnScanState &state) { D_ASSERT(state.current->type == type); } -idx_t ColumnData::ScanVector(ColumnScanState &state, Vector &result, idx_t remaining, ScanVectorType scan_type, - idx_t base_result_offset) { +idx_t ColumnData::ScanVector(ColumnScanState &state, Vector &result, idx_t remaining, ScanVectorType scan_type) { if (scan_type == ScanVectorType::SCAN_FLAT_VECTOR && result.GetVectorType() != VectorType::FLAT_VECTOR) { throw InternalException("ScanVector called with SCAN_FLAT_VECTOR but result is not a flat vector"); } @@ -177,7 +176,7 @@ idx_t ColumnData::ScanVector(ColumnScanState &state, Vector &result, idx_t remai D_ASSERT(state.row_index >= state.current->start && state.row_index <= state.current->start + state.current->count); idx_t scan_count = MinValue(remaining, state.current->start + state.current->count - state.row_index); - idx_t result_offset = base_result_offset + initial_remaining - remaining; + idx_t result_offset = initial_remaining - remaining; if (scan_count > 0) { if (state.scan_options && state.scan_options->force_fetch_row) { for (idx_t i = 0; i < scan_count; i++) { @@ -230,12 +229,12 @@ void ColumnData::SelectVector(ColumnScanState &state, Vector &result, idx_t targ } void ColumnData::FilterVector(ColumnScanState &state, Vector &result, idx_t target_count, SelectionVector &sel, - idx_t &sel_count, const TableFilter &filter, TableFilterState &filter_state) { + idx_t &sel_count, const TableFilter &filter) { BeginScanVectorInternal(state); if (state.current->start + state.current->count - state.row_index < target_count) { throw InternalException("ColumnData::Filter should be able to fetch everything from one segment"); } - state.current->Filter(state, target_count, result, sel, sel_count, filter, filter_state); + state.current->Filter(state, target_count, result, sel, sel_count, filter); state.row_index += target_count; state.internal_index = state.row_index; } @@ -336,23 +335,22 @@ void ColumnData::ScanCommittedRange(idx_t row_group_start, idx_t offset_in_row_g } } -idx_t ColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t scan_count, idx_t result_offset) { +idx_t ColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t scan_count) { if (scan_count == 0) { return 0; } // ScanCount can only be used if there are no updates D_ASSERT(!HasUpdates()); - return ScanVector(state, result, scan_count, ScanVectorType::SCAN_FLAT_VECTOR, result_offset); + return ScanVector(state, result, scan_count, ScanVectorType::SCAN_FLAT_VECTOR); } void ColumnData::Filter(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, - SelectionVector &sel, idx_t &s_count, const TableFilter &filter, - TableFilterState &filter_state) { + SelectionVector &sel, idx_t &s_count, const TableFilter &filter) { idx_t scan_count = Scan(transaction, vector_index, state, result); UnifiedVectorFormat vdata; result.ToUnifiedFormat(scan_count, vdata); - ColumnSegment::FilterSelection(sel, result, vdata, filter, filter_state, scan_count, s_count); + ColumnSegment::FilterSelection(sel, result, vdata, filter, scan_count, s_count); } void ColumnData::Select(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, @@ -897,22 +895,11 @@ void ColumnData::GetColumnSegmentInfo(idx_t row_group_index, vector col_p } else { column_info.persistent = false; } - auto &compression_function = segment->GetCompressionFunction(); auto segment_state = segment->GetSegmentState(); if (segment_state) { column_info.segment_info = segment_state->GetSegmentInfo(); column_info.additional_blocks = segment_state->GetAdditionalBlocks(); } - if (compression_function.get_segment_info) { - auto segment_info = compression_function.get_segment_info(*segment); - vector sinfo; - for (auto &item : segment_info) { - auto &mode = item.first; - auto &count = item.second; - sinfo.push_back(StringUtil::Format("%s: %s", mode, count)); - } - column_info.segment_info = StringUtil::Join(sinfo, ", "); - } result.emplace_back(column_info); segment_idx++; diff --git a/src/duckdb/src/storage/table/column_segment.cpp b/src/duckdb/src/storage/table/column_segment.cpp index fcd28a03c..207c663fa 100644 --- a/src/duckdb/src/storage/table/column_segment.cpp +++ b/src/duckdb/src/storage/table/column_segment.cpp @@ -13,7 +13,6 @@ #include "duckdb/storage/table/append_state.hpp" #include "duckdb/storage/table/scan_state.hpp" #include "duckdb/storage/table/update_segment.hpp" -#include "duckdb/planner/table_filter_state.hpp" #include @@ -133,11 +132,11 @@ void ColumnSegment::Select(ColumnScanState &state, idx_t scan_count, Vector &res } void ColumnSegment::Filter(ColumnScanState &state, idx_t scan_count, Vector &result, SelectionVector &sel, - idx_t &sel_count, const TableFilter &filter, TableFilterState &filter_state) { + idx_t &sel_count, const TableFilter &filter) { if (!function.get().filter) { throw InternalException("ColumnSegment::Filter not implemented for this compression method"); } - function.get().filter(*this, state, scan_count, result, sel, sel_count, filter, filter_state); + function.get().filter(*this, state, scan_count, result, sel, sel_count, filter); } void ColumnSegment::Skip(ColumnScanState &state) { @@ -275,6 +274,10 @@ DataPointer ColumnSegment::GetDataPointer() { // Drop Segment //===--------------------------------------------------------------------===// void ColumnSegment::CommitDropSegment() { + if (segment_type != ColumnSegmentType::PERSISTENT) { + // not persistent + return; + } if (block_id != INVALID_BLOCK) { GetBlockManager().MarkBlockAsModified(block_id); } @@ -404,25 +407,21 @@ static idx_t TemplatedNullSelection(UnifiedVectorFormat &vdata, SelectionVector } idx_t ColumnSegment::FilterSelection(SelectionVector &sel, Vector &vector, UnifiedVectorFormat &vdata, - const TableFilter &filter, TableFilterState &filter_state, idx_t scan_count, - idx_t &approved_tuple_count) { + const TableFilter &filter, idx_t scan_count, idx_t &approved_tuple_count) { switch (filter.filter_type) { case TableFilterType::OPTIONAL_FILTER: { return scan_count; } case TableFilterType::CONJUNCTION_OR: { // similar to the CONJUNCTION_AND, but we need to take care of the SelectionVectors (OR all of them) - auto &state = filter_state.Cast(); idx_t count_total = 0; SelectionVector result_sel(approved_tuple_count); auto &conjunction_or = filter.Cast(); - for (idx_t child_idx = 0; child_idx < conjunction_or.child_filters.size(); child_idx++) { - auto &child_filter = *conjunction_or.child_filters[child_idx]; + for (auto &child_filter : conjunction_or.child_filters) { SelectionVector temp_sel; temp_sel.Initialize(sel); idx_t temp_tuple_count = approved_tuple_count; - idx_t temp_count = FilterSelection(temp_sel, vector, vdata, child_filter, *state.child_states[child_idx], - scan_count, temp_tuple_count); + idx_t temp_count = FilterSelection(temp_sel, vector, vdata, *child_filter, scan_count, temp_tuple_count); // tuples passed, move them into the actual result vector for (idx_t i = 0; i < temp_count; i++) { auto new_idx = temp_sel.get_index(i); @@ -444,11 +443,8 @@ idx_t ColumnSegment::FilterSelection(SelectionVector &sel, Vector &vector, Unifi } case TableFilterType::CONJUNCTION_AND: { auto &conjunction_and = filter.Cast(); - auto &state = filter_state.Cast(); - for (idx_t child_idx = 0; child_idx < conjunction_and.child_filters.size(); child_idx++) { - auto &child_filter = *conjunction_and.child_filters[child_idx]; - FilterSelection(sel, vector, vdata, child_filter, *state.child_states[child_idx], scan_count, - approved_tuple_count); + for (auto &child_filter : conjunction_and.child_filters) { + FilterSelection(sel, vector, vdata, *child_filter, scan_count, approved_tuple_count); } return approved_tuple_count; } @@ -540,19 +536,17 @@ idx_t ColumnSegment::FilterSelection(SelectionVector &sel, Vector &vector, Unifi } return approved_tuple_count; } - case TableFilterType::IS_NULL: { + case TableFilterType::IS_NULL: return TemplatedNullSelection(vdata, sel, approved_tuple_count); - } - case TableFilterType::IS_NOT_NULL: { + case TableFilterType::IS_NOT_NULL: return TemplatedNullSelection(vdata, sel, approved_tuple_count); - } case TableFilterType::STRUCT_EXTRACT: { auto &struct_filter = filter.Cast(); // Apply the filter on the child vector auto &child_vec = StructVector::GetEntries(vector)[struct_filter.child_idx]; UnifiedVectorFormat child_data; child_vec->ToUnifiedFormat(scan_count, child_data); - return FilterSelection(sel, *child_vec, child_data, *struct_filter.child_filter, filter_state, scan_count, + return FilterSelection(sel, *child_vec, child_data, *struct_filter.child_filter, scan_count, approved_tuple_count); } default: diff --git a/src/duckdb/src/storage/table/list_column_data.cpp b/src/duckdb/src/storage/table/list_column_data.cpp index 76c0defe8..03d8de085 100644 --- a/src/duckdb/src/storage/table/list_column_data.cpp +++ b/src/duckdb/src/storage/table/list_column_data.cpp @@ -94,10 +94,7 @@ idx_t ListColumnData::ScanCommitted(idx_t vector_index, ColumnScanState &state, return ScanCount(state, result, scan_count); } -idx_t ListColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset) { - if (result_offset > 0) { - throw InternalException("ListColumnData::ScanCount not supported with result_offset > 0"); - } +idx_t ListColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count) { if (count == 0) { return 0; } diff --git a/src/duckdb/src/storage/table/row_group.cpp b/src/duckdb/src/storage/table/row_group.cpp index 65675a138..55c6e064f 100644 --- a/src/duckdb/src/storage/table/row_group.cpp +++ b/src/duckdb/src/storage/table/row_group.cpp @@ -385,9 +385,8 @@ void RowGroup::CommitDrop() { } } -void RowGroup::CommitDropColumn(const idx_t column_index) { - auto &column = GetColumn(column_index); - column.CommitDropColumn(); +void RowGroup::CommitDropColumn(idx_t column_idx) { + GetColumn(column_idx).CommitDropColumn(); } void RowGroup::NextVector(CollectionScanState &state) { @@ -606,7 +605,6 @@ void RowGroup::TemplatedScan(TransactionData transaction, CollectionScanState &s // this filter is always true - skip it continue; } - auto &table_filter_state = *filter.filter_state; const auto scan_idx = filter.scan_column_index; const auto column_idx = filter.table_column_index; @@ -641,13 +639,13 @@ void RowGroup::TemplatedScan(TransactionData transaction, CollectionScanState &s // Now apply the filter UnifiedVectorFormat vdata; result_vector.ToUnifiedFormat(approved_tuple_count, vdata); - ColumnSegment::FilterSelection(sel, result_vector, vdata, filter.filter, table_filter_state, - approved_tuple_count, approved_tuple_count); + ColumnSegment::FilterSelection(sel, result_vector, vdata, filter.filter, approved_tuple_count, + approved_tuple_count); } else { auto &col_data = GetColumn(filter.table_column_index); col_data.Filter(transaction, state.vector_index, state.column_scans[scan_idx], result_vector, - sel, approved_tuple_count, filter.filter, table_filter_state); + sel, approved_tuple_count, filter.filter); } } for (auto &table_filter : filter_list) { diff --git a/src/duckdb/src/storage/table/row_group_collection.cpp b/src/duckdb/src/storage/table/row_group_collection.cpp index bdd6fe486..dc0a7eb47 100644 --- a/src/duckdb/src/storage/table/row_group_collection.cpp +++ b/src/duckdb/src/storage/table/row_group_collection.cpp @@ -141,7 +141,7 @@ void RowGroupCollection::Verify() { // Scan //===--------------------------------------------------------------------===// void RowGroupCollection::InitializeScan(CollectionScanState &state, const vector &column_ids, - optional_ptr table_filters) { + TableFilterSet *table_filters) { auto row_group = row_groups->GetRootSegment(); D_ASSERT(row_group); state.row_groups = row_groups.get(); @@ -748,7 +748,7 @@ void RowGroupCollection::UpdateColumn(TransactionData transaction, Vector &row_i struct CollectionCheckpointState { CollectionCheckpointState(RowGroupCollection &collection, TableDataWriter &writer, vector> &segments, TableStatistics &global_stats) - : collection(collection), writer(writer), executor(writer.CreateTaskExecutor()), segments(segments), + : collection(collection), writer(writer), executor(writer.GetScheduler()), segments(segments), global_stats(global_stats) { writers.resize(segments.size()); write_data.resize(segments.size()); @@ -756,7 +756,7 @@ struct CollectionCheckpointState { RowGroupCollection &collection; TableDataWriter &writer; - unique_ptr executor; + TaskExecutor executor; vector> &segments; vector> writers; vector write_data; @@ -767,7 +767,7 @@ struct CollectionCheckpointState { class BaseCheckpointTask : public BaseExecutorTask { public: explicit BaseCheckpointTask(CollectionCheckpointState &checkpoint_state) - : BaseExecutorTask(*checkpoint_state.executor), checkpoint_state(checkpoint_state) { + : BaseExecutorTask(checkpoint_state.executor), checkpoint_state(checkpoint_state) { } protected: @@ -1000,7 +1000,7 @@ bool RowGroupCollection::ScheduleVacuumTasks(CollectionCheckpointState &checkpoi // schedule the vacuum task auto vacuum_task = make_uniq(checkpoint_state, state, segment_idx, merge_count, target_count, merge_rows, state.row_start); - checkpoint_state.executor->ScheduleTask(std::move(vacuum_task)); + checkpoint_state.executor.ScheduleTask(std::move(vacuum_task)); // skip vacuuming by the row groups we have merged state.next_vacuum_idx = next_idx; state.row_start += merge_rows; @@ -1045,17 +1045,17 @@ void RowGroupCollection::Checkpoint(TableDataWriter &writer, TableStatistics &gl // schedule a checkpoint task for this row group entry.node->MoveToCollection(*this, vacuum_state.row_start); auto checkpoint_task = GetCheckpointTask(checkpoint_state, segment_idx); - checkpoint_state.executor->ScheduleTask(std::move(checkpoint_task)); + checkpoint_state.executor.ScheduleTask(std::move(checkpoint_task)); vacuum_state.row_start += entry.node->count; } } catch (const std::exception &e) { ErrorData error(e); - checkpoint_state.executor->PushError(std::move(error)); - checkpoint_state.executor->WorkOnTasks(); // ensure all tasks have completed first before rethrowing + checkpoint_state.executor.PushError(std::move(error)); + checkpoint_state.executor.WorkOnTasks(); // ensure all tasks have completed first before rethrowing throw; } // all tasks have been successfully scheduled - execute tasks until we are done - checkpoint_state.executor->WorkOnTasks(); + checkpoint_state.executor.WorkOnTasks(); // no errors - finalize the row groups idx_t new_total_rows = 0; @@ -1082,9 +1082,9 @@ void RowGroupCollection::Checkpoint(TableDataWriter &writer, TableStatistics &gl //===--------------------------------------------------------------------===// // CommitDrop //===--------------------------------------------------------------------===// -void RowGroupCollection::CommitDropColumn(const idx_t column_index) { +void RowGroupCollection::CommitDropColumn(idx_t index) { for (auto &row_group : row_groups->Segments()) { - row_group.CommitDropColumn(column_index); + row_group.CommitDropColumn(index); } } diff --git a/src/duckdb/src/storage/table/scan_state.cpp b/src/duckdb/src/storage/table/scan_state.cpp index 76a642728..4868e5dcf 100644 --- a/src/duckdb/src/storage/table/scan_state.cpp +++ b/src/duckdb/src/storage/table/scan_state.cpp @@ -16,12 +16,11 @@ TableScanState::TableScanState() : table_state(*this), local_state(*this) { TableScanState::~TableScanState() { } -void TableScanState::Initialize(vector column_ids_p, optional_ptr context, - optional_ptr table_filters, +void TableScanState::Initialize(vector column_ids_p, optional_ptr table_filters, optional_ptr table_sampling) { this->column_ids = std::move(column_ids_p); if (table_filters) { - filters.Initialize(*context, *table_filters, column_ids); + filters.Initialize(*table_filters, column_ids); } if (table_sampling) { sampling_info.do_system_sample = table_sampling->method == SampleMethod::SYSTEM_SAMPLE; @@ -51,11 +50,9 @@ ScanSamplingInfo &TableScanState::GetSamplingInfo() { ScanFilter::ScanFilter(idx_t index, const vector &column_ids, TableFilter &filter) : scan_column_index(index), table_column_index(column_ids[index].GetPrimaryIndex()), filter(filter), always_true(false) { - filter_state = TableFilterState::Initialize(filter); } -void ScanFilterInfo::Initialize(ClientContext &context, TableFilterSet &filters, - const vector &column_ids) { +void ScanFilterInfo::Initialize(TableFilterSet &filters, const vector &column_ids) { D_ASSERT(!filters.filters.empty()); table_filters = &filters; adaptive_filter = make_uniq(filters); diff --git a/src/duckdb/src/storage/table/standard_column_data.cpp b/src/duckdb/src/storage/table/standard_column_data.cpp index c8cf79c27..6b6311c3d 100644 --- a/src/duckdb/src/storage/table/standard_column_data.cpp +++ b/src/duckdb/src/storage/table/standard_column_data.cpp @@ -73,15 +73,14 @@ idx_t StandardColumnData::ScanCommitted(idx_t vector_index, ColumnScanState &sta return scan_count; } -idx_t StandardColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset) { - auto scan_count = ColumnData::ScanCount(state, result, count, result_offset); - validity.ScanCount(state.child_states[0], result, count, result_offset); +idx_t StandardColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count) { + auto scan_count = ColumnData::ScanCount(state, result, count); + validity.ScanCount(state.child_states[0], result, count); return scan_count; } void StandardColumnData::Filter(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, - SelectionVector &sel, idx_t &count, const TableFilter &filter, - TableFilterState &filter_state) { + SelectionVector &sel, idx_t &count, const TableFilter &filter) { // check if we can do a specialized select // the compression functions need to support this auto compression = GetCompressionFunction(); @@ -94,11 +93,11 @@ void StandardColumnData::Filter(TransactionData transaction, idx_t vector_index, bool verify_fetch_row = state.scan_options && state.scan_options->force_fetch_row; if (!has_filter || !validity_has_filter || !scan_entire_vector || verify_fetch_row) { // we are not scanning an entire vector - this can have several causes (updates, etc) - ColumnData::Filter(transaction, vector_index, state, result, sel, count, filter, filter_state); + ColumnData::Filter(transaction, vector_index, state, result, sel, count, filter); return; } - FilterVector(state, result, target_count, sel, count, filter, filter_state); - validity.FilterVector(state.child_states[0], result, target_count, sel, count, filter, filter_state); + FilterVector(state, result, target_count, sel, count, filter); + validity.FilterVector(state.child_states[0], result, target_count, sel, count, filter); } void StandardColumnData::Select(TransactionData transaction, idx_t vector_index, ColumnScanState &state, Vector &result, diff --git a/src/duckdb/src/storage/table/struct_column_data.cpp b/src/duckdb/src/storage/table/struct_column_data.cpp index 2e8f94954..5d1506b5c 100644 --- a/src/duckdb/src/storage/table/struct_column_data.cpp +++ b/src/duckdb/src/storage/table/struct_column_data.cpp @@ -119,7 +119,7 @@ idx_t StructColumnData::ScanCommitted(idx_t vector_index, ColumnScanState &state return scan_count; } -idx_t StructColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count, idx_t result_offset) { +idx_t StructColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t count) { auto scan_count = validity.ScanCount(state.child_states[0], result, count); auto &child_entries = StructVector::GetEntries(result); for (idx_t i = 0; i < sub_columns.size(); i++) { @@ -130,7 +130,7 @@ idx_t StructColumnData::ScanCount(ColumnScanState &state, Vector &result, idx_t ConstantVector::SetNull(target_vector, true); continue; } - sub_columns[i]->ScanCount(state.child_states[i + 1], target_vector, count, result_offset); + sub_columns[i]->ScanCount(state.child_states[i + 1], target_vector, count); } return scan_count; } diff --git a/src/duckdb/src/storage/table/update_segment.cpp b/src/duckdb/src/storage/table/update_segment.cpp index 114a9106e..ddee92ceb 100644 --- a/src/duckdb/src/storage/table/update_segment.cpp +++ b/src/duckdb/src/storage/table/update_segment.cpp @@ -652,14 +652,14 @@ void UpdateSegment::InitializeUpdateInfo(UpdateInfo &info, row_t *ids, const Sel }; } -static void InitializeUpdateValidity(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, - UnifiedVectorFormat &update, const SelectionVector &sel) { - auto &update_mask = update.validity; +static void InitializeUpdateValidity(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, Vector &update, + const SelectionVector &sel) { + auto &update_mask = FlatVector::Validity(update); auto tuple_data = update_info.GetData(); if (!update_mask.AllValid()) { for (idx_t i = 0; i < update_info.N; i++) { - auto idx = update.sel->get_index(sel.get_index(i)); + auto idx = sel.get_index(i); tuple_data[i] = update_mask.RowIsValidUnsafe(idx); } } else { @@ -695,13 +695,13 @@ string_t UpdateSelectElement::Operation(UpdateSegment &segment, string_t element } template -static void InitializeUpdateData(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, - UnifiedVectorFormat &update, const SelectionVector &sel) { - auto update_data = update.GetData(update); +static void InitializeUpdateData(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, Vector &update, + const SelectionVector &sel) { + auto update_data = FlatVector::GetData(update); auto tuple_data = update_info.GetData(); for (idx_t i = 0; i < update_info.N; i++) { - auto idx = update.sel->get_index(sel.get_index(i)); + auto idx = sel.get_index(i); tuple_data[i] = update_data[idx]; } @@ -797,22 +797,21 @@ static idx_t MergeLoop(row_t a[], sel_t b[], idx_t acount, idx_t bcount, idx_t a struct ExtractStandardEntry { template - static T Extract(const V *data, idx_t entry) { + static T Extract(V *data, idx_t entry) { return data[entry]; } }; struct ExtractValidityEntry { template - static T Extract(const V *data, idx_t entry) { + static T Extract(V *data, idx_t entry) { return data->RowIsValid(entry); } }; template static void MergeUpdateLoopInternal(UpdateInfo &base_info, V *base_table_data, UpdateInfo &update_info, - const SelectionVector &update_vector_sel, const V *update_vector_data, row_t *ids, - idx_t count, const SelectionVector &sel) { + V *update_vector_data, row_t *ids, idx_t count, const SelectionVector &sel) { auto base_id = base_info.segment->column_data.start + base_info.vector_index * STANDARD_VECTOR_SIZE; #ifdef DEBUG // all of these should be sorted, otherwise the below algorithm does not work @@ -894,8 +893,7 @@ static void MergeUpdateLoopInternal(UpdateInfo &base_info, V *base_table_data, U // now we merge the new values into the base_info result_offset = 0; auto pick_new = [&](idx_t id, idx_t aidx, idx_t count) { - result_values[result_offset] = - OP::template Extract(update_vector_data, update_vector_sel.get_index(aidx)); + result_values[result_offset] = OP::template Extract(update_vector_data, aidx); result_ids[result_offset] = UnsafeNumericCast(id); result_offset++; }; @@ -915,21 +913,20 @@ static void MergeUpdateLoopInternal(UpdateInfo &base_info, V *base_table_data, U memcpy(base_tuples, result_ids, result_offset * sizeof(sel_t)); } -static void MergeValidityLoop(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, - UnifiedVectorFormat &update, row_t *ids, idx_t count, const SelectionVector &sel) { +static void MergeValidityLoop(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, Vector &update, + row_t *ids, idx_t count, const SelectionVector &sel) { auto &base_validity = FlatVector::Validity(base_data); - auto &update_validity = update.validity; + auto &update_validity = FlatVector::Validity(update); MergeUpdateLoopInternal(base_info, &base_validity, update_info, - *update.sel, &update_validity, ids, count, sel); + &update_validity, ids, count, sel); } template -static void MergeUpdateLoop(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, - UnifiedVectorFormat &update, row_t *ids, idx_t count, const SelectionVector &sel) { +static void MergeUpdateLoop(UpdateInfo &base_info, Vector &base_data, UpdateInfo &update_info, Vector &update, + row_t *ids, idx_t count, const SelectionVector &sel) { auto base_table_data = FlatVector::GetData(base_data); - auto update_vector_data = update.GetData(update); - MergeUpdateLoopInternal(base_info, base_table_data, update_info, *update.sel, update_vector_data, ids, count, - sel); + auto update_vector_data = FlatVector::GetData(update); + MergeUpdateLoopInternal(base_info, base_table_data, update_info, update_vector_data, ids, count, sel); } static UpdateSegment::merge_update_function_t GetMergeUpdateFunction(PhysicalType type) { @@ -978,14 +975,13 @@ unique_ptr UpdateSegment::GetStatistics() { return stats.statistics.ToUnique(); } -idx_t UpdateValidityStatistics(UpdateSegment *segment, SegmentStatistics &stats, UnifiedVectorFormat &update, - idx_t count, SelectionVector &sel) { - auto &mask = update.validity; +idx_t UpdateValidityStatistics(UpdateSegment *segment, SegmentStatistics &stats, Vector &update, idx_t count, + SelectionVector &sel) { + auto &mask = FlatVector::Validity(update); auto &validity = stats.statistics; if (!mask.AllValid() && !validity.CanHaveNull()) { for (idx_t i = 0; i < count; i++) { - auto idx = update.sel->get_index(i); - if (!mask.RowIsValid(idx)) { + if (!mask.RowIsValid(i)) { validity.SetHasNullFast(); break; } @@ -996,15 +992,14 @@ idx_t UpdateValidityStatistics(UpdateSegment *segment, SegmentStatistics &stats, } template -idx_t TemplatedUpdateNumericStatistics(UpdateSegment *segment, SegmentStatistics &stats, UnifiedVectorFormat &update, - idx_t count, SelectionVector &sel) { - auto update_data = update.GetData(update); - auto &mask = update.validity; +idx_t TemplatedUpdateNumericStatistics(UpdateSegment *segment, SegmentStatistics &stats, Vector &update, idx_t count, + SelectionVector &sel) { + auto update_data = FlatVector::GetData(update); + auto &mask = FlatVector::Validity(update); if (mask.AllValid()) { for (idx_t i = 0; i < count; i++) { - auto idx = update.sel->get_index(i); - stats.statistics.UpdateNumericStats(update_data[idx]); + stats.statistics.UpdateNumericStats(update_data[i]); } sel.Initialize(nullptr); return count; @@ -1012,27 +1007,24 @@ idx_t TemplatedUpdateNumericStatistics(UpdateSegment *segment, SegmentStatistics idx_t not_null_count = 0; sel.Initialize(STANDARD_VECTOR_SIZE); for (idx_t i = 0; i < count; i++) { - auto idx = update.sel->get_index(i); - if (mask.RowIsValid(idx)) { + if (mask.RowIsValid(i)) { sel.set_index(not_null_count++, i); - stats.statistics.UpdateNumericStats(update_data[idx]); + stats.statistics.UpdateNumericStats(update_data[i]); } } return not_null_count; } } -idx_t UpdateStringStatistics(UpdateSegment *segment, SegmentStatistics &stats, UnifiedVectorFormat &update, idx_t count, +idx_t UpdateStringStatistics(UpdateSegment *segment, SegmentStatistics &stats, Vector &update, idx_t count, SelectionVector &sel) { - auto update_data = update.GetDataNoConst(update); - auto &mask = update.validity; + auto update_data = FlatVector::GetData(update); + auto &mask = FlatVector::Validity(update); if (mask.AllValid()) { for (idx_t i = 0; i < count; i++) { - auto idx = update.sel->get_index(i); - auto &str = update_data[idx]; - StringStats::Update(stats.statistics, str); - if (!str.IsInlined()) { - update_data[idx] = segment->GetStringHeap().AddBlob(str); + StringStats::Update(stats.statistics, update_data[i]); + if (!update_data[i].IsInlined()) { + update_data[i] = segment->GetStringHeap().AddBlob(update_data[i]); } } sel.Initialize(nullptr); @@ -1041,13 +1033,11 @@ idx_t UpdateStringStatistics(UpdateSegment *segment, SegmentStatistics &stats, U idx_t not_null_count = 0; sel.Initialize(STANDARD_VECTOR_SIZE); for (idx_t i = 0; i < count; i++) { - auto idx = update.sel->get_index(i); - if (mask.RowIsValid(idx)) { + if (mask.RowIsValid(i)) { sel.set_index(not_null_count++, i); - auto &str = update_data[idx]; - StringStats::Update(stats.statistics, str); - if (!str.IsInlined()) { - update_data[idx] = segment->GetStringHeap().AddBlob(str); + StringStats::Update(stats.statistics, update_data[i]); + if (!update_data[i].IsInlined()) { + update_data[i] = segment->GetStringHeap().AddBlob(update_data[i]); } } } @@ -1163,19 +1153,18 @@ void UpdateSegment::InitializeUpdateInfo(idx_t vector_idx) { } } -void UpdateSegment::Update(TransactionData transaction, idx_t column_index, Vector &update_p, row_t *ids, idx_t count, +void UpdateSegment::Update(TransactionData transaction, idx_t column_index, Vector &update, row_t *ids, idx_t count, Vector &base_data) { // obtain an exclusive lock auto write_lock = lock.GetExclusiveLock(); - UnifiedVectorFormat update_format; - update_p.ToUnifiedFormat(count, update_format); + update.Flatten(count); // update statistics SelectionVector sel; { lock_guard stats_guard(stats_lock); - count = statistics_update_function(this, stats, update_format, count, sel); + count = statistics_update_function(this, stats, update, count, sel); } if (count == 0) { return; @@ -1242,7 +1231,7 @@ void UpdateSegment::Update(TransactionData transaction, idx_t column_index, Vect node->Verify(); // now we are going to perform the merge - merge_update_function(base_info, base_data, *node, update_format, ids, count, sel); + merge_update_function(base_info, base_data, *node, update, ids, count, sel); base_info.Verify(); node->Verify(); @@ -1271,7 +1260,7 @@ void UpdateSegment::Update(TransactionData transaction, idx_t column_index, Vect InitializeUpdateInfo(*transaction_node, ids, sel, count, vector_index, vector_offset); // we write the updates in the update node data, and write the updates in the info - initialize_update_function(*transaction_node, base_data, update_info, update_format, sel); + initialize_update_function(*transaction_node, base_data, update_info, update, sel); update_info.next = transaction.transaction ? node_ref.GetBufferPointer() : UndoBufferPointer(); update_info.prev = UndoBufferPointer(); diff --git a/src/duckdb/src/storage/table_index_list.cpp b/src/duckdb/src/storage/table_index_list.cpp index 3390755e0..abcb9a7d1 100644 --- a/src/duckdb/src/storage/table_index_list.cpp +++ b/src/duckdb/src/storage/table_index_list.cpp @@ -83,7 +83,7 @@ void TableIndexList::InitializeIndexes(ClientContext &context, DataTableInfo &ta auto &catalog = table_info.GetDB().GetCatalog(); auto schema = table_info.GetSchemaName(); auto table_name = table_info.GetTableName(); - auto &table_entry = catalog.GetEntry(context, schema, table_name); + auto &table_entry = catalog.GetEntry(context, CatalogType::TABLE_ENTRY, schema, table_name); auto &table = table_entry.Cast(); vector column_types; diff --git a/src/duckdb/src/storage/temporary_memory_manager.cpp b/src/duckdb/src/storage/temporary_memory_manager.cpp index b66cea0c4..a2bf67bc5 100644 --- a/src/duckdb/src/storage/temporary_memory_manager.cpp +++ b/src/duckdb/src/storage/temporary_memory_manager.cpp @@ -1,7 +1,6 @@ #include "duckdb/storage/temporary_memory_manager.hpp" #include "duckdb/main/client_context.hpp" -#include "duckdb/main/connection_manager.hpp" #include "duckdb/parallel/task_scheduler.hpp" #include "duckdb/storage/buffer_manager.hpp" @@ -74,11 +73,6 @@ unique_lock TemporaryMemoryManager::Lock() { return unique_lock(lock); } -idx_t TemporaryMemoryManager::DefaultMinimumReservation() const { - return MinValue(num_threads * MINIMUM_RESERVATION_PER_STATE_PER_THREAD, - memory_limit / MINIMUM_RESERVATION_MEMORY_LIMIT_DIVISOR); -} - void TemporaryMemoryManager::Unregister(TemporaryMemoryState &temporary_memory_state) { auto guard = Lock(); @@ -97,7 +91,6 @@ void TemporaryMemoryManager::UpdateConfiguration(ClientContext &context) { LossyNumericCast(MAXIMUM_MEMORY_LIMIT_RATIO * static_cast(buffer_manager.GetMaxMemory())); has_temporary_directory = buffer_manager.HasTemporaryDirectory(); num_threads = NumericCast(task_scheduler.NumberOfThreads()); - num_connections = ConnectionManager::Get(context).GetConnectionCount(); query_max_memory = buffer_manager.GetQueryMaxMemory(); } @@ -109,7 +102,9 @@ unique_ptr TemporaryMemoryManager::Register(ClientContext auto guard = Lock(); UpdateConfiguration(context); - auto result = unique_ptr(new TemporaryMemoryState(*this, DefaultMinimumReservation())); + auto minimum_reservation = MinValue(num_threads * MINIMUM_RESERVATION_PER_STATE_PER_THREAD, + memory_limit / MINIMUM_RESERVATION_MEMORY_LIMIT_DIVISOR); + auto result = unique_ptr(new TemporaryMemoryState(*this, minimum_reservation)); SetRemainingSize(*result, result->GetMinimumReservation()); SetReservation(*result, result->GetMinimumReservation()); active_states.insert(*result); @@ -282,12 +277,6 @@ idx_t TemporaryMemoryManager::ComputeReservation(const TemporaryMemoryState &tem // Update counts res[min_idx] += delta; remaining_memory -= delta; - - // If we aren't able to assign the remaining memory to the lowest-derivative state in the last iteration, - // we'll exit this loop without assigning all free memory. This adds another iteration - if (opt_idx == optimization_iterations - 1 && delta < iter_memory) { - opt_idx--; - } } D_ASSERT(remaining_memory == 0); @@ -313,13 +302,8 @@ idx_t TemporaryMemoryManager::ComputeReservation(const TemporaryMemoryState &tem auto &state = states[idx].get(); D_ASSERT(res[idx] <= state.GetRemainingSize()); const auto initial_state_reservation = ComputeInitialReservation(state); - // Bound by the ratio - const auto state_remaining = initial_state_reservation + remaining_memory; - auto upper_bound = LossyNumericCast(MAXIMUM_FREE_MEMORY_RATIO * static_cast(state_remaining)); - // Or bound by leaving a number of minimum reservations for other states - auto num_other_states = MinValue(MAXIMUM_REMAINING_STATE_RESERVATIONS, num_connections); - num_other_states = MaxValue(num_other_states, MINIMUM_REMAINING_STATE_RESERVATIONS); - upper_bound = MinValue(upper_bound, num_other_states * DefaultMinimumReservation()); + const auto upper_bound = LossyNumericCast( + MAXIMUM_FREE_MEMORY_RATIO * static_cast(initial_state_reservation + remaining_memory)); auto state_reservation = MinValue(res[idx], upper_bound); // But make sure it's never less than the initial reservation state_reservation = MaxValue(state_reservation, initial_state_reservation); diff --git a/src/duckdb/src/storage/wal_replay.cpp b/src/duckdb/src/storage/wal_replay.cpp index 861db230a..ac2a1bb57 100644 --- a/src/duckdb/src/storage/wal_replay.cpp +++ b/src/duckdb/src/storage/wal_replay.cpp @@ -658,6 +658,7 @@ void WriteAheadLogDeserializer::ReplayCreateIndex() { if (DeserializeOnly()) { return; } + auto &info = create_info->Cast(); // Ensure that the index type exists. @@ -665,16 +666,41 @@ void WriteAheadLogDeserializer::ReplayCreateIndex() { info.index_type = ART::TYPE_NAME; } - auto &table = catalog.GetEntry(context, create_info->schema, info.table).Cast(); - auto &storage = table.GetStorage(); - auto &io_manager = TableIOManager::Get(storage); + auto index_type = context.db->config.GetIndexTypes().FindByName(info.index_type); + if (!index_type) { + throw InternalException("Index type \"%s\" not recognized", info.index_type); + } // Create the index in the catalog. - table.schema.CreateIndex(context, info, table); + auto &table = catalog.GetEntry(context, create_info->schema, info.table).Cast(); + auto &index = table.schema.CreateIndex(context, info, table)->Cast(); + + // Add the table to the bind context to bind the parsed expressions. + auto binder = Binder::CreateBinder(context); + vector column_types; + vector column_names; + for (auto &col : table.GetColumns().Logical()) { + column_types.push_back(col.Type()); + column_names.push_back(col.Name()); + } + + // create a binder to bind the parsed expressions + vector column_ids; + binder->bind_context.AddBaseTable(0, string(), column_names, column_types, column_ids, table); + IndexBinder idx_binder(*binder, context); - // add the index to the storage - auto unbound_index = make_uniq(std::move(create_info), std::move(index_info), io_manager, db); - storage.AddIndex(std::move(unbound_index)); + // Bind the parsed expressions to create unbound expressions. + vector> unbound_expressions; + for (auto &expr : index.parsed_expressions) { + auto copy = expr->Copy(); + unbound_expressions.push_back(idx_binder.Bind(copy)); + } + + auto &storage = table.GetStorage(); + CreateIndexInput input(TableIOManager::Get(storage), storage.db, info.constraint_type, info.index_name, + info.column_ids, unbound_expressions, index_info, info.options); + auto index_instance = index_type->create_instance(input); + storage.AddIndex(std::move(index_instance)); } void WriteAheadLogDeserializer::ReplayDropIndex() { diff --git a/src/duckdb/src/transaction/duck_transaction.cpp b/src/duckdb/src/transaction/duck_transaction.cpp index 478fcf0dc..1aa62c20c 100644 --- a/src/duckdb/src/transaction/duck_transaction.cpp +++ b/src/duckdb/src/transaction/duck_transaction.cpp @@ -78,7 +78,6 @@ void DuckTransaction::PushCatalogEntry(CatalogEntry &entry, data_ptr_t extra_dat void DuckTransaction::PushDelete(DataTable &table, RowVersionManager &info, idx_t vector_idx, row_t rows[], idx_t count, idx_t base_row) { - ModifyTable(table); bool is_consecutive = true; // check if the rows are consecutive for (idx_t i = 0; i < count; i++) { @@ -144,14 +143,14 @@ void DuckTransaction::PushSequenceUsage(SequenceCatalogEntry &sequence, const Se } } -void DuckTransaction::ModifyTable(DataTable &tbl) { - auto table_ref = reference(tbl); - auto entry = modified_tables.find(table_ref); - if (entry != modified_tables.end()) { +void DuckTransaction::UpdateCollection(shared_ptr &collection) { + auto collection_ref = reference(*collection); + auto entry = updated_collections.find(collection_ref); + if (entry != updated_collections.end()) { // already exists return; } - modified_tables.insert(make_pair(table_ref, tbl.shared_from_this())); + updated_collections.insert(make_pair(collection_ref, collection)); } bool DuckTransaction::ChangesMade() { @@ -235,14 +234,6 @@ ErrorData DuckTransaction::Commit(AttachedDatabase &db, transaction_t new_commit // no need to flush anything if we made no changes return ErrorData(); } - for (auto &entry : modified_tables) { - auto &tbl = entry.first.get(); - if (!tbl.IsMainTable()) { - return ErrorData( - TransactionException("Attempting to modify table %s but another transaction has %s this table", - tbl.GetTableName(), tbl.TableModification())); - } - } D_ASSERT(db.IsSystem() || db.IsTemporary() || !IsReadOnly()); UndoBuffer::IteratorState iterator_state; diff --git a/src/duckdb/src/transaction/meta_transaction.cpp b/src/duckdb/src/transaction/meta_transaction.cpp index c64015d55..319f81875 100644 --- a/src/duckdb/src/transaction/meta_transaction.cpp +++ b/src/duckdb/src/transaction/meta_transaction.cpp @@ -7,10 +7,9 @@ namespace duckdb { -MetaTransaction::MetaTransaction(ClientContext &context_p, timestamp_t start_timestamp_p, - transaction_t transaction_id_p) - : context(context_p), start_timestamp(start_timestamp_p), global_transaction_id(transaction_id_p), - active_query(MAXIMUM_QUERY_ID), modified_database(nullptr), is_read_only(false) { +MetaTransaction::MetaTransaction(ClientContext &context_p, timestamp_t start_timestamp_p) + : context(context_p), start_timestamp(start_timestamp_p), active_query(MAXIMUM_QUERY_ID), + modified_database(nullptr), is_read_only(false) { } MetaTransaction &MetaTransaction::Get(ClientContext &context) { diff --git a/src/duckdb/src/transaction/transaction_context.cpp b/src/duckdb/src/transaction/transaction_context.cpp index 596921f68..67f8cfec4 100644 --- a/src/duckdb/src/transaction/transaction_context.cpp +++ b/src/duckdb/src/transaction/transaction_context.cpp @@ -5,7 +5,6 @@ #include "duckdb/main/client_context.hpp" #include "duckdb/main/client_context_state.hpp" #include "duckdb/main/config.hpp" -#include "duckdb/main/database.hpp" #include "duckdb/main/database_manager.hpp" #include "duckdb/transaction/meta_transaction.hpp" #include "duckdb/transaction/transaction_manager.hpp" @@ -30,8 +29,7 @@ void TransactionContext::BeginTransaction() { throw TransactionException("cannot start a transaction within a transaction"); } auto start_timestamp = Timestamp::GetCurrentTimestamp(); - auto global_transaction_id = context.db->GetDatabaseManager().GetNewTransactionNumber(); - current_transaction = make_uniq(context, start_timestamp, global_transaction_id); + current_transaction = make_uniq(context, start_timestamp); // Notify any registered state of transaction begin for (auto &state : context.registered_state->States()) { diff --git a/src/duckdb/src/transaction/undo_buffer.cpp b/src/duckdb/src/transaction/undo_buffer.cpp index 4a6ca3a32..e352ff473 100644 --- a/src/duckdb/src/transaction/undo_buffer.cpp +++ b/src/duckdb/src/transaction/undo_buffer.cpp @@ -179,12 +179,10 @@ void UndoBuffer::Cleanup(transaction_t lowest_active_transaction) { UndoBuffer::IteratorState iterator_state; IterateEntries(iterator_state, [&](UndoFlags type, data_ptr_t data) { state.CleanupEntry(type, data); }); -#ifdef DEBUG - // Verify that our index memory is stable. + // possibly vacuum indexes for (auto &table : state.indexed_tables) { - table.second->VerifyIndexBuffers(); + table.second->VacuumIndexes(); } -#endif } void UndoBuffer::WriteToWAL(WriteAheadLog &wal, optional_ptr commit_state) { diff --git a/src/duckdb/third_party/fsst/fsst.h b/src/duckdb/third_party/fsst/fsst.h index 86909be5b..46e94e7cf 100644 --- a/src/duckdb/third_party/fsst/fsst.h +++ b/src/duckdb/third_party/fsst/fsst.h @@ -163,7 +163,7 @@ inline size_t /* OUT: bytesize of the decompressed string. If > size, the decode duckdb_fsst_decompress( duckdb_fsst_decoder_t *decoder, /* IN: use this symbol table for compression. */ size_t lenIn, /* IN: byte-length of compressed string. */ - const unsigned char *strIn, /* IN: compressed string. */ + unsigned char *strIn, /* IN: compressed string. */ size_t size, /* IN: byte-length of output buffer. */ unsigned char *output /* OUT: memory buffer to put the decompressed string in. */ ) { diff --git a/src/duckdb/third_party/httplib/httplib.hpp b/src/duckdb/third_party/httplib/httplib.hpp index 63b979fc4..f06db896a 100644 --- a/src/duckdb/third_party/httplib/httplib.hpp +++ b/src/duckdb/third_party/httplib/httplib.hpp @@ -2543,7 +2543,7 @@ inline void read_file(const std::string &path, std::string &out) { inline std::string file_extension(const std::string &path) { Match m; - auto re = Regex("\\.([a-zA-Z0-9]+)$"); + static auto re = Regex("\\.([a-zA-Z0-9]+)$"); if (duckdb_re2::RegexSearch(path, m, re)) { return m[1].str(); } return std::string(); } @@ -4196,7 +4196,7 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider, } } - const std::string done_marker("0\r\n"); + static const std::string done_marker("0\r\n"); if (!write_data(strm, done_marker.data(), done_marker.size())) { ok = false; } @@ -4211,7 +4211,7 @@ write_content_chunked(Stream &strm, const ContentProvider &content_provider, } } - const std::string crlf("\r\n"); + static const std::string crlf("\r\n"); if (!write_data(strm, crlf.data(), crlf.size())) { ok = false; } }; @@ -4349,7 +4349,7 @@ inline bool parse_range_header(const std::string &s, Ranges &ranges) { #else inline bool parse_range_header(const std::string &s, Ranges &ranges) try { #endif - auto re_first_range = Regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))"); + static auto re_first_range = Regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))"); Match m; if (RegexMatch(s, m, re_first_range)) { auto pos = static_cast(m.position(1)); @@ -4357,7 +4357,7 @@ inline bool parse_range_header(const std::string &s, Ranges &ranges) try { auto all_valid_ranges = true; split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) { if (!all_valid_ranges) { return; } - auto re_another_range = Regex(R"(\s*(\d*)-(\d*))"); + static auto re_another_range = Regex(R"(\s*(\d*)-(\d*))"); Match cm; if (RegexMatch(b, e, cm, re_another_range)) { ssize_t first = -1; @@ -4441,13 +4441,13 @@ class MultipartFormDataParser { return false; } - const std::string header_content_type = "Content-Type:"; + static const std::string header_content_type = "Content-Type:"; if (start_with_case_ignore(header, header_content_type)) { file_.content_type = trim_copy(header.substr(header_content_type.size())); } else { - const Regex re_content_disposition( + static const Regex re_content_disposition( R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~", duckdb_re2::RegexOptions::CASE_INSENSITIVE); @@ -4470,7 +4470,7 @@ class MultipartFormDataParser { it = params.find("filename*"); if (it != params.end()) { // Only allow UTF-8 enconnding... - const Regex re_rfc5987_encoding( + static const Regex re_rfc5987_encoding( R"~(^UTF-8''(.+?)$)~", duckdb_re2::RegexOptions::CASE_INSENSITIVE); Match m2; @@ -5098,7 +5098,7 @@ inline bool parse_www_authenticate(const Response &res, bool is_proxy) { auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate"; if (res.has_header(auth_key)) { - auto re = Regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~"); + static auto re = Regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~"); auto s = res.get_header_value(auth_key); auto pos = s.find(' '); if (pos != std::string::npos) { @@ -5196,7 +5196,7 @@ inline void hosted_at(const std::string &hostname, inline std::string append_query_params(const std::string &path, const Params ¶ms) { std::string path_with_query = path; - const Regex re("[^?]+\\?.*"); + const static Regex re("[^?]+\\?.*"); auto delm = RegexMatch(path, re) ? '&' : '?'; path_with_query += delm + detail::params_to_query_str(params); return path_with_query; @@ -5872,10 +5872,6 @@ inline void Server::stop() { } } -static const std::set SERVER_METHODS{ - "GET", "HEAD", "POST", "PUT", "DELETE", - "CONNECT", "OPTIONS", "TRACE", "PATCH", "PRI"}; - inline bool Server::parse_request_line(const char *s, Request &req) const { auto len = strlen(s); if (len < 2 || s[len - 2] != '\r' || s[len - 1] != '\n') { return false; } @@ -5897,7 +5893,11 @@ inline bool Server::parse_request_line(const char *s, Request &req) const { if (count != 3) { return false; } } - if (SERVER_METHODS.find(req.method) == SERVER_METHODS.end()) { return false; } + static const std::set methods{ + "GET", "HEAD", "POST", "PUT", "DELETE", + "CONNECT", "OPTIONS", "TRACE", "PATCH", "PRI"}; + + if (methods.find(req.method) == methods.end()) { return false; } if (req.version != "HTTP/1.1" && req.version != "HTTP/1.0") { return false; } @@ -6848,9 +6848,9 @@ inline bool ClientImpl::read_response_line(Stream &strm, const Request &req, if (!line_reader.getline()) { return false; } #ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR - const Regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n"); + const static Regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n"); #else - const Regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n"); + const static Regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n"); #endif Match m; @@ -7072,7 +7072,7 @@ inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) { auto location = res.get_header_value("location"); if (location.empty()) { return false; } - const Regex re( + const static Regex re( R"((?:(https?):)?(?://(?:\[([\d:]+)\]|([^:/?#]+))(?::(\d+))?)?([^?#]*)(\?[^#]*)?(?:#.*)?)"); Match m; @@ -8878,7 +8878,7 @@ inline Client::Client(const std::string &scheme_host_port) inline Client::Client(const std::string &scheme_host_port, const std::string &client_cert_path, const std::string &client_key_path) { - const Regex re( + const static Regex re( R"((?:([a-z]+):\/\/)?(?:\[([\d:]+)\]|([^:/?#]+))(?::(\d+))?)"); Match m; diff --git a/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp b/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp index 35c95e627..d12e34c2e 100644 --- a/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +++ b/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp @@ -197,7 +197,6 @@ typedef enum PGNodeTag { T_PGPivotExpr, T_PGPivot, T_PGPivotStmt, - T_PGAtClause, /* * TAGS FOR EXPRESSION STATE NODES (execnodes.h) diff --git a/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp b/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp index 982617928..2fbf2cf75 100644 --- a/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +++ b/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp @@ -319,6 +319,7 @@ typedef struct PGAStar { PGList *replace_list; /* optional: REPLACE list */ PGList *rename_list; /* optional: RENAME list */ bool columns; /* whether or not this is a columns list */ + bool unpacked; /* whether or not the columns list is unpacked */ int location; } PGAStar; @@ -1095,7 +1096,6 @@ typedef struct PGCommonTableExpr { int location; /* token location, or -1 if unknown */ /* These fields are set during parse analysis: */ bool cterecursive; /* is this CTE actually recursive? */ - PGList *recursive_keys; int cterefcount; /* number of RTEs referencing this CTE * (excluding internal self-references) */ PGList *ctecolnames; /* list of output column names */ @@ -1289,7 +1289,6 @@ typedef struct PGSelectStmt { PGSetOperation op; /* type of set op */ bool all; /* ALL specified? */ bool from_first; /* FROM first or SELECT first */ - bool offset_first; /* OFFSET first or LIMIT first */ struct PGNode *larg; /* left child */ struct PGNode *rarg; /* right child */ /* Eventually add fields for CORRESPONDING spec here */ @@ -1487,9 +1486,7 @@ typedef enum PGAlterTableType { PG_AT_DetachPartition, /* DETACH PARTITION */ PG_AT_AddIdentity, /* ADD IDENTITY */ PG_AT_SetIdentity, /* SET identity column options */ - AT_DropIdentity, /* DROP IDENTITY */ - PG_AT_SetPartitionedBy, /* SET PARTITIONED BY */ - PG_AT_SetSortedBy /* SET SORTED BY */ + AT_DropIdentity /* DROP IDENTITY */ } PGAlterTableType; typedef struct PGAlterTableCmd /* one subcommand of an ALTER TABLE */ @@ -1498,8 +1495,8 @@ typedef struct PGAlterTableCmd /* one subcommand of an ALTER TABLE */ PGAlterTableType subtype; /* Type of table alteration to apply */ char *name; /* column, constraint, or trigger to act on, * or tablespace */ - PGNode *def; /* definition of new column, index, * constraint, or parent table */ - PGList *def_list; /* e.g. expression list for partitioned by */ + PGNode *def; /* definition of new column, index, + * constraint, or parent table */ PGDropBehavior behavior; /* RESTRICT or CASCADE for DROP cases */ bool missing_ok; /* skip error if missing? */ } PGAlterTableCmd; @@ -1834,7 +1831,6 @@ typedef struct PGRenameStmt { PGNode *object; /* in case it's some other object */ char *subname; /* name of contained object (column, rule, * trigger, etc) */ - PGList *name_list; /* names of contained object (e.g. qualified column) */ char *newname; /* the new name */ PGDropBehavior behavior; /* RESTRICT or CASCADE behavior */ bool missing_ok; /* skip error if missing? */ diff --git a/src/duckdb/third_party/libpg_query/include/nodes/primnodes.hpp b/src/duckdb/third_party/libpg_query/include/nodes/primnodes.hpp index cf7928f6e..890c9304e 100644 --- a/src/duckdb/third_party/libpg_query/include/nodes/primnodes.hpp +++ b/src/duckdb/third_party/libpg_query/include/nodes/primnodes.hpp @@ -76,7 +76,6 @@ typedef struct PGRangeVar { bool inh; /* expand rel by inheritance? recursively act * on children? */ char relpersistence; /* see RELPERSISTENCE_* in pg_class.h */ - PGNode *at_clause; /* version of the table to read */ PGAlias *alias; /* table alias & optional column aliases */ int location; /* token location, or -1 if unknown */ PGNode *sample; /* sample, if any */ @@ -1399,14 +1398,4 @@ typedef struct PGOnConflictExpr { PGList *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */ } PGOnConflictExpr; - -/* - * PGAtClause - AT clause in FROM tables - e.g. "AT (TIMESTAMP => NOW()) - */ -typedef struct PGAtClause { - PGNodeTag type; - const char *unit; /* the unit (e.g. TIMESTAMP/VERSION) */ - PGNode *expr; /* the expression */ -} PGAtClause; - } diff --git a/src/duckdb/third_party/libpg_query/include/parser/gram.hpp b/src/duckdb/third_party/libpg_query/include/parser/gram.hpp index c4e15b31c..b4e16ccca 100644 --- a/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +++ b/src/duckdb/third_party/libpg_query/include/parser/gram.hpp @@ -347,205 +347,202 @@ PARSER = 563, PARTIAL = 564, PARTITION = 565, - PARTITIONED = 566, - PASSING = 567, - PASSWORD = 568, - PERCENT = 569, - PERSISTENT = 570, - PIVOT = 571, - PIVOT_LONGER = 572, - PIVOT_WIDER = 573, - PLACING = 574, - PLANS = 575, - POLICY = 576, - POSITION = 577, - POSITIONAL = 578, - PRAGMA_P = 579, - PRECEDING = 580, - PRECISION = 581, - PREPARE = 582, - PREPARED = 583, - PRESERVE = 584, - PRIMARY = 585, - PRIOR = 586, - PRIVILEGES = 587, - PROCEDURAL = 588, - PROCEDURE = 589, - PROGRAM = 590, - PUBLICATION = 591, - QUALIFY = 592, - QUARTER_P = 593, - QUARTERS_P = 594, - QUOTE = 595, - RANGE = 596, - READ_P = 597, - REAL = 598, - REASSIGN = 599, - RECHECK = 600, - RECURSIVE = 601, - REF = 602, - REFERENCES = 603, - REFERENCING = 604, - REFRESH = 605, - REINDEX = 606, - RELATIVE_P = 607, - RELEASE = 608, - RENAME = 609, - REPEATABLE = 610, - REPLACE = 611, - REPLICA = 612, - RESET = 613, - RESPECT_P = 614, - RESTART = 615, - RESTRICT = 616, - RETURNING = 617, - RETURNS = 618, - REVOKE = 619, - RIGHT = 620, - ROLE = 621, - ROLLBACK = 622, - ROLLUP = 623, - ROW = 624, - ROWS = 625, - RULE = 626, - SAMPLE = 627, - SAVEPOINT = 628, - SCHEMA = 629, - SCHEMAS = 630, - SCOPE = 631, - SCROLL = 632, - SEARCH = 633, - SECOND_P = 634, - SECONDS_P = 635, - SECRET = 636, - SECURITY = 637, - SELECT = 638, - SEMI = 639, - SEQUENCE = 640, - SEQUENCES = 641, - SERIALIZABLE = 642, - SERVER = 643, - SESSION = 644, - SET = 645, - SETOF = 646, - SETS = 647, - SHARE = 648, - SHOW = 649, - SIMILAR = 650, - SIMPLE = 651, - SKIP = 652, - SMALLINT = 653, - SNAPSHOT = 654, - SOME = 655, - SORTED = 656, - SQL_P = 657, - STABLE = 658, - STANDALONE_P = 659, - START = 660, - STATEMENT = 661, - STATISTICS = 662, - STDIN = 663, - STDOUT = 664, - STORAGE = 665, - STORED = 666, - STRICT_P = 667, - STRIP_P = 668, - STRUCT = 669, - SUBSCRIPTION = 670, - SUBSTRING = 671, - SUMMARIZE = 672, - SYMMETRIC = 673, - SYSID = 674, - SYSTEM_P = 675, - TABLE = 676, - TABLES = 677, - TABLESAMPLE = 678, - TABLESPACE = 679, - TEMP = 680, - TEMPLATE = 681, - TEMPORARY = 682, - TEXT_P = 683, - THEN = 684, - TIES = 685, - TIME = 686, - TIMESTAMP = 687, - TO = 688, - TRAILING = 689, - TRANSACTION = 690, - TRANSFORM = 691, - TREAT = 692, - TRIGGER = 693, - TRIM = 694, - TRUE_P = 695, - TRUNCATE = 696, - TRUSTED = 697, - TRY_CAST = 698, - TYPE_P = 699, - TYPES_P = 700, - UNBOUNDED = 701, - UNCOMMITTED = 702, - UNENCRYPTED = 703, - UNION = 704, - UNIQUE = 705, - UNKNOWN = 706, - UNLISTEN = 707, - UNLOGGED = 708, - UNPACK = 709, - UNPIVOT = 710, - UNTIL = 711, - UPDATE = 712, - USE_P = 713, - USER = 714, - USING = 715, - VACUUM = 716, - VALID = 717, - VALIDATE = 718, - VALIDATOR = 719, - VALUE_P = 720, - VALUES = 721, - VARCHAR = 722, - VARIABLE_P = 723, - VARIADIC = 724, - VARYING = 725, - VERBOSE = 726, - VERSION_P = 727, - VIEW = 728, - VIEWS = 729, - VIRTUAL = 730, - VOLATILE = 731, - WEEK_P = 732, - WEEKS_P = 733, - WHEN = 734, - WHERE = 735, - WHITESPACE_P = 736, - WINDOW = 737, - WITH = 738, - WITHIN = 739, - WITHOUT = 740, - WORK = 741, - WRAPPER = 742, - WRITE_P = 743, - XML_P = 744, - XMLATTRIBUTES = 745, - XMLCONCAT = 746, - XMLELEMENT = 747, - XMLEXISTS = 748, - XMLFOREST = 749, - XMLNAMESPACES = 750, - XMLPARSE = 751, - XMLPI = 752, - XMLROOT = 753, - XMLSERIALIZE = 754, - XMLTABLE = 755, - YEAR_P = 756, - YEARS_P = 757, - YES_P = 758, - ZONE = 759, - NOT_LA = 760, - NULLS_LA = 761, - WITH_LA = 762, - POSTFIXOP = 763, - UMINUS = 764 + PASSING = 566, + PASSWORD = 567, + PERCENT = 568, + PERSISTENT = 569, + PIVOT = 570, + PIVOT_LONGER = 571, + PIVOT_WIDER = 572, + PLACING = 573, + PLANS = 574, + POLICY = 575, + POSITION = 576, + POSITIONAL = 577, + PRAGMA_P = 578, + PRECEDING = 579, + PRECISION = 580, + PREPARE = 581, + PREPARED = 582, + PRESERVE = 583, + PRIMARY = 584, + PRIOR = 585, + PRIVILEGES = 586, + PROCEDURAL = 587, + PROCEDURE = 588, + PROGRAM = 589, + PUBLICATION = 590, + QUALIFY = 591, + QUARTER_P = 592, + QUARTERS_P = 593, + QUOTE = 594, + RANGE = 595, + READ_P = 596, + REAL = 597, + REASSIGN = 598, + RECHECK = 599, + RECURSIVE = 600, + REF = 601, + REFERENCES = 602, + REFERENCING = 603, + REFRESH = 604, + REINDEX = 605, + RELATIVE_P = 606, + RELEASE = 607, + RENAME = 608, + REPEATABLE = 609, + REPLACE = 610, + REPLICA = 611, + RESET = 612, + RESPECT_P = 613, + RESTART = 614, + RESTRICT = 615, + RETURNING = 616, + RETURNS = 617, + REVOKE = 618, + RIGHT = 619, + ROLE = 620, + ROLLBACK = 621, + ROLLUP = 622, + ROW = 623, + ROWS = 624, + RULE = 625, + SAMPLE = 626, + SAVEPOINT = 627, + SCHEMA = 628, + SCHEMAS = 629, + SCOPE = 630, + SCROLL = 631, + SEARCH = 632, + SECOND_P = 633, + SECONDS_P = 634, + SECRET = 635, + SECURITY = 636, + SELECT = 637, + SEMI = 638, + SEQUENCE = 639, + SEQUENCES = 640, + SERIALIZABLE = 641, + SERVER = 642, + SESSION = 643, + SET = 644, + SETOF = 645, + SETS = 646, + SHARE = 647, + SHOW = 648, + SIMILAR = 649, + SIMPLE = 650, + SKIP = 651, + SMALLINT = 652, + SNAPSHOT = 653, + SOME = 654, + SQL_P = 655, + STABLE = 656, + STANDALONE_P = 657, + START = 658, + STATEMENT = 659, + STATISTICS = 660, + STDIN = 661, + STDOUT = 662, + STORAGE = 663, + STORED = 664, + STRICT_P = 665, + STRIP_P = 666, + STRUCT = 667, + SUBSCRIPTION = 668, + SUBSTRING = 669, + SUMMARIZE = 670, + SYMMETRIC = 671, + SYSID = 672, + SYSTEM_P = 673, + TABLE = 674, + TABLES = 675, + TABLESAMPLE = 676, + TABLESPACE = 677, + TEMP = 678, + TEMPLATE = 679, + TEMPORARY = 680, + TEXT_P = 681, + THEN = 682, + TIES = 683, + TIME = 684, + TIMESTAMP = 685, + TO = 686, + TRAILING = 687, + TRANSACTION = 688, + TRANSFORM = 689, + TREAT = 690, + TRIGGER = 691, + TRIM = 692, + TRUE_P = 693, + TRUNCATE = 694, + TRUSTED = 695, + TRY_CAST = 696, + TYPE_P = 697, + TYPES_P = 698, + UNBOUNDED = 699, + UNCOMMITTED = 700, + UNENCRYPTED = 701, + UNION = 702, + UNIQUE = 703, + UNKNOWN = 704, + UNLISTEN = 705, + UNLOGGED = 706, + UNPIVOT = 707, + UNTIL = 708, + UPDATE = 709, + USE_P = 710, + USER = 711, + USING = 712, + VACUUM = 713, + VALID = 714, + VALIDATE = 715, + VALIDATOR = 716, + VALUE_P = 717, + VALUES = 718, + VARCHAR = 719, + VARIABLE_P = 720, + VARIADIC = 721, + VARYING = 722, + VERBOSE = 723, + VERSION_P = 724, + VIEW = 725, + VIEWS = 726, + VIRTUAL = 727, + VOLATILE = 728, + WEEK_P = 729, + WEEKS_P = 730, + WHEN = 731, + WHERE = 732, + WHITESPACE_P = 733, + WINDOW = 734, + WITH = 735, + WITHIN = 736, + WITHOUT = 737, + WORK = 738, + WRAPPER = 739, + WRITE_P = 740, + XML_P = 741, + XMLATTRIBUTES = 742, + XMLCONCAT = 743, + XMLELEMENT = 744, + XMLEXISTS = 745, + XMLFOREST = 746, + XMLNAMESPACES = 747, + XMLPARSE = 748, + XMLPI = 749, + XMLROOT = 750, + XMLSERIALIZE = 751, + XMLTABLE = 752, + YEAR_P = 753, + YEARS_P = 754, + YES_P = 755, + ZONE = 756, + NOT_LA = 757, + NULLS_LA = 758, + WITH_LA = 759, + POSTFIXOP = 760, + UMINUS = 761 }; #endif /* Tokens. */ @@ -857,205 +854,202 @@ #define PARSER 563 #define PARTIAL 564 #define PARTITION 565 -#define PARTITIONED 566 -#define PASSING 567 -#define PASSWORD 568 -#define PERCENT 569 -#define PERSISTENT 570 -#define PIVOT 571 -#define PIVOT_LONGER 572 -#define PIVOT_WIDER 573 -#define PLACING 574 -#define PLANS 575 -#define POLICY 576 -#define POSITION 577 -#define POSITIONAL 578 -#define PRAGMA_P 579 -#define PRECEDING 580 -#define PRECISION 581 -#define PREPARE 582 -#define PREPARED 583 -#define PRESERVE 584 -#define PRIMARY 585 -#define PRIOR 586 -#define PRIVILEGES 587 -#define PROCEDURAL 588 -#define PROCEDURE 589 -#define PROGRAM 590 -#define PUBLICATION 591 -#define QUALIFY 592 -#define QUARTER_P 593 -#define QUARTERS_P 594 -#define QUOTE 595 -#define RANGE 596 -#define READ_P 597 -#define REAL 598 -#define REASSIGN 599 -#define RECHECK 600 -#define RECURSIVE 601 -#define REF 602 -#define REFERENCES 603 -#define REFERENCING 604 -#define REFRESH 605 -#define REINDEX 606 -#define RELATIVE_P 607 -#define RELEASE 608 -#define RENAME 609 -#define REPEATABLE 610 -#define REPLACE 611 -#define REPLICA 612 -#define RESET 613 -#define RESPECT_P 614 -#define RESTART 615 -#define RESTRICT 616 -#define RETURNING 617 -#define RETURNS 618 -#define REVOKE 619 -#define RIGHT 620 -#define ROLE 621 -#define ROLLBACK 622 -#define ROLLUP 623 -#define ROW 624 -#define ROWS 625 -#define RULE 626 -#define SAMPLE 627 -#define SAVEPOINT 628 -#define SCHEMA 629 -#define SCHEMAS 630 -#define SCOPE 631 -#define SCROLL 632 -#define SEARCH 633 -#define SECOND_P 634 -#define SECONDS_P 635 -#define SECRET 636 -#define SECURITY 637 -#define SELECT 638 -#define SEMI 639 -#define SEQUENCE 640 -#define SEQUENCES 641 -#define SERIALIZABLE 642 -#define SERVER 643 -#define SESSION 644 -#define SET 645 -#define SETOF 646 -#define SETS 647 -#define SHARE 648 -#define SHOW 649 -#define SIMILAR 650 -#define SIMPLE 651 -#define SKIP 652 -#define SMALLINT 653 -#define SNAPSHOT 654 -#define SOME 655 -#define SORTED 656 -#define SQL_P 657 -#define STABLE 658 -#define STANDALONE_P 659 -#define START 660 -#define STATEMENT 661 -#define STATISTICS 662 -#define STDIN 663 -#define STDOUT 664 -#define STORAGE 665 -#define STORED 666 -#define STRICT_P 667 -#define STRIP_P 668 -#define STRUCT 669 -#define SUBSCRIPTION 670 -#define SUBSTRING 671 -#define SUMMARIZE 672 -#define SYMMETRIC 673 -#define SYSID 674 -#define SYSTEM_P 675 -#define TABLE 676 -#define TABLES 677 -#define TABLESAMPLE 678 -#define TABLESPACE 679 -#define TEMP 680 -#define TEMPLATE 681 -#define TEMPORARY 682 -#define TEXT_P 683 -#define THEN 684 -#define TIES 685 -#define TIME 686 -#define TIMESTAMP 687 -#define TO 688 -#define TRAILING 689 -#define TRANSACTION 690 -#define TRANSFORM 691 -#define TREAT 692 -#define TRIGGER 693 -#define TRIM 694 -#define TRUE_P 695 -#define TRUNCATE 696 -#define TRUSTED 697 -#define TRY_CAST 698 -#define TYPE_P 699 -#define TYPES_P 700 -#define UNBOUNDED 701 -#define UNCOMMITTED 702 -#define UNENCRYPTED 703 -#define UNION 704 -#define UNIQUE 705 -#define UNKNOWN 706 -#define UNLISTEN 707 -#define UNLOGGED 708 -#define UNPACK 709 -#define UNPIVOT 710 -#define UNTIL 711 -#define UPDATE 712 -#define USE_P 713 -#define USER 714 -#define USING 715 -#define VACUUM 716 -#define VALID 717 -#define VALIDATE 718 -#define VALIDATOR 719 -#define VALUE_P 720 -#define VALUES 721 -#define VARCHAR 722 -#define VARIABLE_P 723 -#define VARIADIC 724 -#define VARYING 725 -#define VERBOSE 726 -#define VERSION_P 727 -#define VIEW 728 -#define VIEWS 729 -#define VIRTUAL 730 -#define VOLATILE 731 -#define WEEK_P 732 -#define WEEKS_P 733 -#define WHEN 734 -#define WHERE 735 -#define WHITESPACE_P 736 -#define WINDOW 737 -#define WITH 738 -#define WITHIN 739 -#define WITHOUT 740 -#define WORK 741 -#define WRAPPER 742 -#define WRITE_P 743 -#define XML_P 744 -#define XMLATTRIBUTES 745 -#define XMLCONCAT 746 -#define XMLELEMENT 747 -#define XMLEXISTS 748 -#define XMLFOREST 749 -#define XMLNAMESPACES 750 -#define XMLPARSE 751 -#define XMLPI 752 -#define XMLROOT 753 -#define XMLSERIALIZE 754 -#define XMLTABLE 755 -#define YEAR_P 756 -#define YEARS_P 757 -#define YES_P 758 -#define ZONE 759 -#define NOT_LA 760 -#define NULLS_LA 761 -#define WITH_LA 762 -#define POSTFIXOP 763 -#define UMINUS 764 +#define PASSING 566 +#define PASSWORD 567 +#define PERCENT 568 +#define PERSISTENT 569 +#define PIVOT 570 +#define PIVOT_LONGER 571 +#define PIVOT_WIDER 572 +#define PLACING 573 +#define PLANS 574 +#define POLICY 575 +#define POSITION 576 +#define POSITIONAL 577 +#define PRAGMA_P 578 +#define PRECEDING 579 +#define PRECISION 580 +#define PREPARE 581 +#define PREPARED 582 +#define PRESERVE 583 +#define PRIMARY 584 +#define PRIOR 585 +#define PRIVILEGES 586 +#define PROCEDURAL 587 +#define PROCEDURE 588 +#define PROGRAM 589 +#define PUBLICATION 590 +#define QUALIFY 591 +#define QUARTER_P 592 +#define QUARTERS_P 593 +#define QUOTE 594 +#define RANGE 595 +#define READ_P 596 +#define REAL 597 +#define REASSIGN 598 +#define RECHECK 599 +#define RECURSIVE 600 +#define REF 601 +#define REFERENCES 602 +#define REFERENCING 603 +#define REFRESH 604 +#define REINDEX 605 +#define RELATIVE_P 606 +#define RELEASE 607 +#define RENAME 608 +#define REPEATABLE 609 +#define REPLACE 610 +#define REPLICA 611 +#define RESET 612 +#define RESPECT_P 613 +#define RESTART 614 +#define RESTRICT 615 +#define RETURNING 616 +#define RETURNS 617 +#define REVOKE 618 +#define RIGHT 619 +#define ROLE 620 +#define ROLLBACK 621 +#define ROLLUP 622 +#define ROW 623 +#define ROWS 624 +#define RULE 625 +#define SAMPLE 626 +#define SAVEPOINT 627 +#define SCHEMA 628 +#define SCHEMAS 629 +#define SCOPE 630 +#define SCROLL 631 +#define SEARCH 632 +#define SECOND_P 633 +#define SECONDS_P 634 +#define SECRET 635 +#define SECURITY 636 +#define SELECT 637 +#define SEMI 638 +#define SEQUENCE 639 +#define SEQUENCES 640 +#define SERIALIZABLE 641 +#define SERVER 642 +#define SESSION 643 +#define SET 644 +#define SETOF 645 +#define SETS 646 +#define SHARE 647 +#define SHOW 648 +#define SIMILAR 649 +#define SIMPLE 650 +#define SKIP 651 +#define SMALLINT 652 +#define SNAPSHOT 653 +#define SOME 654 +#define SQL_P 655 +#define STABLE 656 +#define STANDALONE_P 657 +#define START 658 +#define STATEMENT 659 +#define STATISTICS 660 +#define STDIN 661 +#define STDOUT 662 +#define STORAGE 663 +#define STORED 664 +#define STRICT_P 665 +#define STRIP_P 666 +#define STRUCT 667 +#define SUBSCRIPTION 668 +#define SUBSTRING 669 +#define SUMMARIZE 670 +#define SYMMETRIC 671 +#define SYSID 672 +#define SYSTEM_P 673 +#define TABLE 674 +#define TABLES 675 +#define TABLESAMPLE 676 +#define TABLESPACE 677 +#define TEMP 678 +#define TEMPLATE 679 +#define TEMPORARY 680 +#define TEXT_P 681 +#define THEN 682 +#define TIES 683 +#define TIME 684 +#define TIMESTAMP 685 +#define TO 686 +#define TRAILING 687 +#define TRANSACTION 688 +#define TRANSFORM 689 +#define TREAT 690 +#define TRIGGER 691 +#define TRIM 692 +#define TRUE_P 693 +#define TRUNCATE 694 +#define TRUSTED 695 +#define TRY_CAST 696 +#define TYPE_P 697 +#define TYPES_P 698 +#define UNBOUNDED 699 +#define UNCOMMITTED 700 +#define UNENCRYPTED 701 +#define UNION 702 +#define UNIQUE 703 +#define UNKNOWN 704 +#define UNLISTEN 705 +#define UNLOGGED 706 +#define UNPIVOT 707 +#define UNTIL 708 +#define UPDATE 709 +#define USE_P 710 +#define USER 711 +#define USING 712 +#define VACUUM 713 +#define VALID 714 +#define VALIDATE 715 +#define VALIDATOR 716 +#define VALUE_P 717 +#define VALUES 718 +#define VARCHAR 719 +#define VARIABLE_P 720 +#define VARIADIC 721 +#define VARYING 722 +#define VERBOSE 723 +#define VERSION_P 724 +#define VIEW 725 +#define VIEWS 726 +#define VIRTUAL 727 +#define VOLATILE 728 +#define WEEK_P 729 +#define WEEKS_P 730 +#define WHEN 731 +#define WHERE 732 +#define WHITESPACE_P 733 +#define WINDOW 734 +#define WITH 735 +#define WITHIN 736 +#define WITHOUT 737 +#define WORK 738 +#define WRAPPER 739 +#define WRITE_P 740 +#define XML_P 741 +#define XMLATTRIBUTES 742 +#define XMLCONCAT 743 +#define XMLELEMENT 744 +#define XMLEXISTS 745 +#define XMLFOREST 746 +#define XMLNAMESPACES 747 +#define XMLPARSE 748 +#define XMLPI 749 +#define XMLROOT 750 +#define XMLSERIALIZE 751 +#define XMLTABLE 752 +#define YEAR_P 753 +#define YEARS_P 754 +#define YES_P 755 +#define ZONE 756 +#define NOT_LA 757 +#define NULLS_LA 758 +#define WITH_LA 759 +#define POSTFIXOP 760 +#define UMINUS 761 @@ -1114,7 +1108,7 @@ typedef union YYSTYPE PGTransactionStmtType transactiontype; } /* Line 1529 of yacc.c. */ -#line 1118 "third_party/libpg_query/grammar/grammar_out.hpp" +#line 1112 "third_party/libpg_query/grammar/grammar_out.hpp" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 diff --git a/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp b/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp index 57fb14889..9d54b6f2d 100644 --- a/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +++ b/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp @@ -27,7 +27,7 @@ PG_KEYWORD("asof", ASOF, TYPE_FUNC_NAME_KEYWORD) PG_KEYWORD("assertion", ASSERTION, UNRESERVED_KEYWORD) PG_KEYWORD("assignment", ASSIGNMENT, UNRESERVED_KEYWORD) PG_KEYWORD("asymmetric", ASYMMETRIC, RESERVED_KEYWORD) -PG_KEYWORD("at", AT, TYPE_FUNC_NAME_KEYWORD) +PG_KEYWORD("at", AT, UNRESERVED_KEYWORD) PG_KEYWORD("attach", ATTACH, UNRESERVED_KEYWORD) PG_KEYWORD("attribute", ATTRIBUTE, UNRESERVED_KEYWORD) PG_KEYWORD("authorization", AUTHORIZATION, TYPE_FUNC_NAME_KEYWORD) @@ -160,7 +160,7 @@ PG_KEYWORD("functions", FUNCTIONS, UNRESERVED_KEYWORD) PG_KEYWORD("generated", GENERATED, TYPE_FUNC_NAME_KEYWORD) PG_KEYWORD("glob", GLOB, TYPE_FUNC_NAME_KEYWORD) PG_KEYWORD("global", GLOBAL, UNRESERVED_KEYWORD) -PG_KEYWORD("grant", GRANT, UNRESERVED_KEYWORD) +PG_KEYWORD("grant", GRANT, RESERVED_KEYWORD) PG_KEYWORD("granted", GRANTED, UNRESERVED_KEYWORD) PG_KEYWORD("group", GROUP_P, RESERVED_KEYWORD) PG_KEYWORD("grouping", GROUPING, COL_NAME_KEYWORD) @@ -292,7 +292,6 @@ PG_KEYWORD("parallel", PARALLEL, UNRESERVED_KEYWORD) PG_KEYWORD("parser", PARSER, UNRESERVED_KEYWORD) PG_KEYWORD("partial", PARTIAL, UNRESERVED_KEYWORD) PG_KEYWORD("partition", PARTITION, UNRESERVED_KEYWORD) -PG_KEYWORD("partitioned", PARTITIONED, UNRESERVED_KEYWORD) PG_KEYWORD("passing", PASSING, UNRESERVED_KEYWORD) PG_KEYWORD("password", PASSWORD, UNRESERVED_KEYWORD) PG_KEYWORD("percent", PERCENT, UNRESERVED_KEYWORD) @@ -382,7 +381,6 @@ PG_KEYWORD("skip", SKIP, UNRESERVED_KEYWORD) PG_KEYWORD("smallint", SMALLINT, COL_NAME_KEYWORD) PG_KEYWORD("snapshot", SNAPSHOT, UNRESERVED_KEYWORD) PG_KEYWORD("some", SOME, RESERVED_KEYWORD) -PG_KEYWORD("sorted", SORTED, UNRESERVED_KEYWORD) PG_KEYWORD("sql", SQL_P, UNRESERVED_KEYWORD) PG_KEYWORD("stable", STABLE, UNRESERVED_KEYWORD) PG_KEYWORD("standalone", STANDALONE_P, UNRESERVED_KEYWORD) @@ -435,7 +433,6 @@ PG_KEYWORD("unique", UNIQUE, RESERVED_KEYWORD) PG_KEYWORD("unknown", UNKNOWN, UNRESERVED_KEYWORD) PG_KEYWORD("unlisten", UNLISTEN, UNRESERVED_KEYWORD) PG_KEYWORD("unlogged", UNLOGGED, UNRESERVED_KEYWORD) -PG_KEYWORD("unpack", UNPACK, TYPE_FUNC_NAME_KEYWORD) PG_KEYWORD("unpivot", UNPIVOT, RESERVED_KEYWORD) PG_KEYWORD("until", UNTIL, UNRESERVED_KEYWORD) PG_KEYWORD("update", UPDATE, UNRESERVED_KEYWORD) diff --git a/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp b/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp index 8d8881ce6..71ed8b023 100644 --- a/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +++ b/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp @@ -382,205 +382,202 @@ PARSER = 563, PARTIAL = 564, PARTITION = 565, - PARTITIONED = 566, - PASSING = 567, - PASSWORD = 568, - PERCENT = 569, - PERSISTENT = 570, - PIVOT = 571, - PIVOT_LONGER = 572, - PIVOT_WIDER = 573, - PLACING = 574, - PLANS = 575, - POLICY = 576, - POSITION = 577, - POSITIONAL = 578, - PRAGMA_P = 579, - PRECEDING = 580, - PRECISION = 581, - PREPARE = 582, - PREPARED = 583, - PRESERVE = 584, - PRIMARY = 585, - PRIOR = 586, - PRIVILEGES = 587, - PROCEDURAL = 588, - PROCEDURE = 589, - PROGRAM = 590, - PUBLICATION = 591, - QUALIFY = 592, - QUARTER_P = 593, - QUARTERS_P = 594, - QUOTE = 595, - RANGE = 596, - READ_P = 597, - REAL = 598, - REASSIGN = 599, - RECHECK = 600, - RECURSIVE = 601, - REF = 602, - REFERENCES = 603, - REFERENCING = 604, - REFRESH = 605, - REINDEX = 606, - RELATIVE_P = 607, - RELEASE = 608, - RENAME = 609, - REPEATABLE = 610, - REPLACE = 611, - REPLICA = 612, - RESET = 613, - RESPECT_P = 614, - RESTART = 615, - RESTRICT = 616, - RETURNING = 617, - RETURNS = 618, - REVOKE = 619, - RIGHT = 620, - ROLE = 621, - ROLLBACK = 622, - ROLLUP = 623, - ROW = 624, - ROWS = 625, - RULE = 626, - SAMPLE = 627, - SAVEPOINT = 628, - SCHEMA = 629, - SCHEMAS = 630, - SCOPE = 631, - SCROLL = 632, - SEARCH = 633, - SECOND_P = 634, - SECONDS_P = 635, - SECRET = 636, - SECURITY = 637, - SELECT = 638, - SEMI = 639, - SEQUENCE = 640, - SEQUENCES = 641, - SERIALIZABLE = 642, - SERVER = 643, - SESSION = 644, - SET = 645, - SETOF = 646, - SETS = 647, - SHARE = 648, - SHOW = 649, - SIMILAR = 650, - SIMPLE = 651, - SKIP = 652, - SMALLINT = 653, - SNAPSHOT = 654, - SOME = 655, - SORTED = 656, - SQL_P = 657, - STABLE = 658, - STANDALONE_P = 659, - START = 660, - STATEMENT = 661, - STATISTICS = 662, - STDIN = 663, - STDOUT = 664, - STORAGE = 665, - STORED = 666, - STRICT_P = 667, - STRIP_P = 668, - STRUCT = 669, - SUBSCRIPTION = 670, - SUBSTRING = 671, - SUMMARIZE = 672, - SYMMETRIC = 673, - SYSID = 674, - SYSTEM_P = 675, - TABLE = 676, - TABLES = 677, - TABLESAMPLE = 678, - TABLESPACE = 679, - TEMP = 680, - TEMPLATE = 681, - TEMPORARY = 682, - TEXT_P = 683, - THEN = 684, - TIES = 685, - TIME = 686, - TIMESTAMP = 687, - TO = 688, - TRAILING = 689, - TRANSACTION = 690, - TRANSFORM = 691, - TREAT = 692, - TRIGGER = 693, - TRIM = 694, - TRUE_P = 695, - TRUNCATE = 696, - TRUSTED = 697, - TRY_CAST = 698, - TYPE_P = 699, - TYPES_P = 700, - UNBOUNDED = 701, - UNCOMMITTED = 702, - UNENCRYPTED = 703, - UNION = 704, - UNIQUE = 705, - UNKNOWN = 706, - UNLISTEN = 707, - UNLOGGED = 708, - UNPACK = 709, - UNPIVOT = 710, - UNTIL = 711, - UPDATE = 712, - USE_P = 713, - USER = 714, - USING = 715, - VACUUM = 716, - VALID = 717, - VALIDATE = 718, - VALIDATOR = 719, - VALUE_P = 720, - VALUES = 721, - VARCHAR = 722, - VARIABLE_P = 723, - VARIADIC = 724, - VARYING = 725, - VERBOSE = 726, - VERSION_P = 727, - VIEW = 728, - VIEWS = 729, - VIRTUAL = 730, - VOLATILE = 731, - WEEK_P = 732, - WEEKS_P = 733, - WHEN = 734, - WHERE = 735, - WHITESPACE_P = 736, - WINDOW = 737, - WITH = 738, - WITHIN = 739, - WITHOUT = 740, - WORK = 741, - WRAPPER = 742, - WRITE_P = 743, - XML_P = 744, - XMLATTRIBUTES = 745, - XMLCONCAT = 746, - XMLELEMENT = 747, - XMLEXISTS = 748, - XMLFOREST = 749, - XMLNAMESPACES = 750, - XMLPARSE = 751, - XMLPI = 752, - XMLROOT = 753, - XMLSERIALIZE = 754, - XMLTABLE = 755, - YEAR_P = 756, - YEARS_P = 757, - YES_P = 758, - ZONE = 759, - NOT_LA = 760, - NULLS_LA = 761, - WITH_LA = 762, - POSTFIXOP = 763, - UMINUS = 764 + PASSING = 566, + PASSWORD = 567, + PERCENT = 568, + PERSISTENT = 569, + PIVOT = 570, + PIVOT_LONGER = 571, + PIVOT_WIDER = 572, + PLACING = 573, + PLANS = 574, + POLICY = 575, + POSITION = 576, + POSITIONAL = 577, + PRAGMA_P = 578, + PRECEDING = 579, + PRECISION = 580, + PREPARE = 581, + PREPARED = 582, + PRESERVE = 583, + PRIMARY = 584, + PRIOR = 585, + PRIVILEGES = 586, + PROCEDURAL = 587, + PROCEDURE = 588, + PROGRAM = 589, + PUBLICATION = 590, + QUALIFY = 591, + QUARTER_P = 592, + QUARTERS_P = 593, + QUOTE = 594, + RANGE = 595, + READ_P = 596, + REAL = 597, + REASSIGN = 598, + RECHECK = 599, + RECURSIVE = 600, + REF = 601, + REFERENCES = 602, + REFERENCING = 603, + REFRESH = 604, + REINDEX = 605, + RELATIVE_P = 606, + RELEASE = 607, + RENAME = 608, + REPEATABLE = 609, + REPLACE = 610, + REPLICA = 611, + RESET = 612, + RESPECT_P = 613, + RESTART = 614, + RESTRICT = 615, + RETURNING = 616, + RETURNS = 617, + REVOKE = 618, + RIGHT = 619, + ROLE = 620, + ROLLBACK = 621, + ROLLUP = 622, + ROW = 623, + ROWS = 624, + RULE = 625, + SAMPLE = 626, + SAVEPOINT = 627, + SCHEMA = 628, + SCHEMAS = 629, + SCOPE = 630, + SCROLL = 631, + SEARCH = 632, + SECOND_P = 633, + SECONDS_P = 634, + SECRET = 635, + SECURITY = 636, + SELECT = 637, + SEMI = 638, + SEQUENCE = 639, + SEQUENCES = 640, + SERIALIZABLE = 641, + SERVER = 642, + SESSION = 643, + SET = 644, + SETOF = 645, + SETS = 646, + SHARE = 647, + SHOW = 648, + SIMILAR = 649, + SIMPLE = 650, + SKIP = 651, + SMALLINT = 652, + SNAPSHOT = 653, + SOME = 654, + SQL_P = 655, + STABLE = 656, + STANDALONE_P = 657, + START = 658, + STATEMENT = 659, + STATISTICS = 660, + STDIN = 661, + STDOUT = 662, + STORAGE = 663, + STORED = 664, + STRICT_P = 665, + STRIP_P = 666, + STRUCT = 667, + SUBSCRIPTION = 668, + SUBSTRING = 669, + SUMMARIZE = 670, + SYMMETRIC = 671, + SYSID = 672, + SYSTEM_P = 673, + TABLE = 674, + TABLES = 675, + TABLESAMPLE = 676, + TABLESPACE = 677, + TEMP = 678, + TEMPLATE = 679, + TEMPORARY = 680, + TEXT_P = 681, + THEN = 682, + TIES = 683, + TIME = 684, + TIMESTAMP = 685, + TO = 686, + TRAILING = 687, + TRANSACTION = 688, + TRANSFORM = 689, + TREAT = 690, + TRIGGER = 691, + TRIM = 692, + TRUE_P = 693, + TRUNCATE = 694, + TRUSTED = 695, + TRY_CAST = 696, + TYPE_P = 697, + TYPES_P = 698, + UNBOUNDED = 699, + UNCOMMITTED = 700, + UNENCRYPTED = 701, + UNION = 702, + UNIQUE = 703, + UNKNOWN = 704, + UNLISTEN = 705, + UNLOGGED = 706, + UNPIVOT = 707, + UNTIL = 708, + UPDATE = 709, + USE_P = 710, + USER = 711, + USING = 712, + VACUUM = 713, + VALID = 714, + VALIDATE = 715, + VALIDATOR = 716, + VALUE_P = 717, + VALUES = 718, + VARCHAR = 719, + VARIABLE_P = 720, + VARIADIC = 721, + VARYING = 722, + VERBOSE = 723, + VERSION_P = 724, + VIEW = 725, + VIEWS = 726, + VIRTUAL = 727, + VOLATILE = 728, + WEEK_P = 729, + WEEKS_P = 730, + WHEN = 731, + WHERE = 732, + WHITESPACE_P = 733, + WINDOW = 734, + WITH = 735, + WITHIN = 736, + WITHOUT = 737, + WORK = 738, + WRAPPER = 739, + WRITE_P = 740, + XML_P = 741, + XMLATTRIBUTES = 742, + XMLCONCAT = 743, + XMLELEMENT = 744, + XMLEXISTS = 745, + XMLFOREST = 746, + XMLNAMESPACES = 747, + XMLPARSE = 748, + XMLPI = 749, + XMLROOT = 750, + XMLSERIALIZE = 751, + XMLTABLE = 752, + YEAR_P = 753, + YEARS_P = 754, + YES_P = 755, + ZONE = 756, + NOT_LA = 757, + NULLS_LA = 758, + WITH_LA = 759, + POSTFIXOP = 760, + UMINUS = 761 }; #endif /* Tokens. */ @@ -892,205 +889,202 @@ #define PARSER 563 #define PARTIAL 564 #define PARTITION 565 -#define PARTITIONED 566 -#define PASSING 567 -#define PASSWORD 568 -#define PERCENT 569 -#define PERSISTENT 570 -#define PIVOT 571 -#define PIVOT_LONGER 572 -#define PIVOT_WIDER 573 -#define PLACING 574 -#define PLANS 575 -#define POLICY 576 -#define POSITION 577 -#define POSITIONAL 578 -#define PRAGMA_P 579 -#define PRECEDING 580 -#define PRECISION 581 -#define PREPARE 582 -#define PREPARED 583 -#define PRESERVE 584 -#define PRIMARY 585 -#define PRIOR 586 -#define PRIVILEGES 587 -#define PROCEDURAL 588 -#define PROCEDURE 589 -#define PROGRAM 590 -#define PUBLICATION 591 -#define QUALIFY 592 -#define QUARTER_P 593 -#define QUARTERS_P 594 -#define QUOTE 595 -#define RANGE 596 -#define READ_P 597 -#define REAL 598 -#define REASSIGN 599 -#define RECHECK 600 -#define RECURSIVE 601 -#define REF 602 -#define REFERENCES 603 -#define REFERENCING 604 -#define REFRESH 605 -#define REINDEX 606 -#define RELATIVE_P 607 -#define RELEASE 608 -#define RENAME 609 -#define REPEATABLE 610 -#define REPLACE 611 -#define REPLICA 612 -#define RESET 613 -#define RESPECT_P 614 -#define RESTART 615 -#define RESTRICT 616 -#define RETURNING 617 -#define RETURNS 618 -#define REVOKE 619 -#define RIGHT 620 -#define ROLE 621 -#define ROLLBACK 622 -#define ROLLUP 623 -#define ROW 624 -#define ROWS 625 -#define RULE 626 -#define SAMPLE 627 -#define SAVEPOINT 628 -#define SCHEMA 629 -#define SCHEMAS 630 -#define SCOPE 631 -#define SCROLL 632 -#define SEARCH 633 -#define SECOND_P 634 -#define SECONDS_P 635 -#define SECRET 636 -#define SECURITY 637 -#define SELECT 638 -#define SEMI 639 -#define SEQUENCE 640 -#define SEQUENCES 641 -#define SERIALIZABLE 642 -#define SERVER 643 -#define SESSION 644 -#define SET 645 -#define SETOF 646 -#define SETS 647 -#define SHARE 648 -#define SHOW 649 -#define SIMILAR 650 -#define SIMPLE 651 -#define SKIP 652 -#define SMALLINT 653 -#define SNAPSHOT 654 -#define SOME 655 -#define SORTED 656 -#define SQL_P 657 -#define STABLE 658 -#define STANDALONE_P 659 -#define START 660 -#define STATEMENT 661 -#define STATISTICS 662 -#define STDIN 663 -#define STDOUT 664 -#define STORAGE 665 -#define STORED 666 -#define STRICT_P 667 -#define STRIP_P 668 -#define STRUCT 669 -#define SUBSCRIPTION 670 -#define SUBSTRING 671 -#define SUMMARIZE 672 -#define SYMMETRIC 673 -#define SYSID 674 -#define SYSTEM_P 675 -#define TABLE 676 -#define TABLES 677 -#define TABLESAMPLE 678 -#define TABLESPACE 679 -#define TEMP 680 -#define TEMPLATE 681 -#define TEMPORARY 682 -#define TEXT_P 683 -#define THEN 684 -#define TIES 685 -#define TIME 686 -#define TIMESTAMP 687 -#define TO 688 -#define TRAILING 689 -#define TRANSACTION 690 -#define TRANSFORM 691 -#define TREAT 692 -#define TRIGGER 693 -#define TRIM 694 -#define TRUE_P 695 -#define TRUNCATE 696 -#define TRUSTED 697 -#define TRY_CAST 698 -#define TYPE_P 699 -#define TYPES_P 700 -#define UNBOUNDED 701 -#define UNCOMMITTED 702 -#define UNENCRYPTED 703 -#define UNION 704 -#define UNIQUE 705 -#define UNKNOWN 706 -#define UNLISTEN 707 -#define UNLOGGED 708 -#define UNPACK 709 -#define UNPIVOT 710 -#define UNTIL 711 -#define UPDATE 712 -#define USE_P 713 -#define USER 714 -#define USING 715 -#define VACUUM 716 -#define VALID 717 -#define VALIDATE 718 -#define VALIDATOR 719 -#define VALUE_P 720 -#define VALUES 721 -#define VARCHAR 722 -#define VARIABLE_P 723 -#define VARIADIC 724 -#define VARYING 725 -#define VERBOSE 726 -#define VERSION_P 727 -#define VIEW 728 -#define VIEWS 729 -#define VIRTUAL 730 -#define VOLATILE 731 -#define WEEK_P 732 -#define WEEKS_P 733 -#define WHEN 734 -#define WHERE 735 -#define WHITESPACE_P 736 -#define WINDOW 737 -#define WITH 738 -#define WITHIN 739 -#define WITHOUT 740 -#define WORK 741 -#define WRAPPER 742 -#define WRITE_P 743 -#define XML_P 744 -#define XMLATTRIBUTES 745 -#define XMLCONCAT 746 -#define XMLELEMENT 747 -#define XMLEXISTS 748 -#define XMLFOREST 749 -#define XMLNAMESPACES 750 -#define XMLPARSE 751 -#define XMLPI 752 -#define XMLROOT 753 -#define XMLSERIALIZE 754 -#define XMLTABLE 755 -#define YEAR_P 756 -#define YEARS_P 757 -#define YES_P 758 -#define ZONE 759 -#define NOT_LA 760 -#define NULLS_LA 761 -#define WITH_LA 762 -#define POSTFIXOP 763 -#define UMINUS 764 +#define PASSING 566 +#define PASSWORD 567 +#define PERCENT 568 +#define PERSISTENT 569 +#define PIVOT 570 +#define PIVOT_LONGER 571 +#define PIVOT_WIDER 572 +#define PLACING 573 +#define PLANS 574 +#define POLICY 575 +#define POSITION 576 +#define POSITIONAL 577 +#define PRAGMA_P 578 +#define PRECEDING 579 +#define PRECISION 580 +#define PREPARE 581 +#define PREPARED 582 +#define PRESERVE 583 +#define PRIMARY 584 +#define PRIOR 585 +#define PRIVILEGES 586 +#define PROCEDURAL 587 +#define PROCEDURE 588 +#define PROGRAM 589 +#define PUBLICATION 590 +#define QUALIFY 591 +#define QUARTER_P 592 +#define QUARTERS_P 593 +#define QUOTE 594 +#define RANGE 595 +#define READ_P 596 +#define REAL 597 +#define REASSIGN 598 +#define RECHECK 599 +#define RECURSIVE 600 +#define REF 601 +#define REFERENCES 602 +#define REFERENCING 603 +#define REFRESH 604 +#define REINDEX 605 +#define RELATIVE_P 606 +#define RELEASE 607 +#define RENAME 608 +#define REPEATABLE 609 +#define REPLACE 610 +#define REPLICA 611 +#define RESET 612 +#define RESPECT_P 613 +#define RESTART 614 +#define RESTRICT 615 +#define RETURNING 616 +#define RETURNS 617 +#define REVOKE 618 +#define RIGHT 619 +#define ROLE 620 +#define ROLLBACK 621 +#define ROLLUP 622 +#define ROW 623 +#define ROWS 624 +#define RULE 625 +#define SAMPLE 626 +#define SAVEPOINT 627 +#define SCHEMA 628 +#define SCHEMAS 629 +#define SCOPE 630 +#define SCROLL 631 +#define SEARCH 632 +#define SECOND_P 633 +#define SECONDS_P 634 +#define SECRET 635 +#define SECURITY 636 +#define SELECT 637 +#define SEMI 638 +#define SEQUENCE 639 +#define SEQUENCES 640 +#define SERIALIZABLE 641 +#define SERVER 642 +#define SESSION 643 +#define SET 644 +#define SETOF 645 +#define SETS 646 +#define SHARE 647 +#define SHOW 648 +#define SIMILAR 649 +#define SIMPLE 650 +#define SKIP 651 +#define SMALLINT 652 +#define SNAPSHOT 653 +#define SOME 654 +#define SQL_P 655 +#define STABLE 656 +#define STANDALONE_P 657 +#define START 658 +#define STATEMENT 659 +#define STATISTICS 660 +#define STDIN 661 +#define STDOUT 662 +#define STORAGE 663 +#define STORED 664 +#define STRICT_P 665 +#define STRIP_P 666 +#define STRUCT 667 +#define SUBSCRIPTION 668 +#define SUBSTRING 669 +#define SUMMARIZE 670 +#define SYMMETRIC 671 +#define SYSID 672 +#define SYSTEM_P 673 +#define TABLE 674 +#define TABLES 675 +#define TABLESAMPLE 676 +#define TABLESPACE 677 +#define TEMP 678 +#define TEMPLATE 679 +#define TEMPORARY 680 +#define TEXT_P 681 +#define THEN 682 +#define TIES 683 +#define TIME 684 +#define TIMESTAMP 685 +#define TO 686 +#define TRAILING 687 +#define TRANSACTION 688 +#define TRANSFORM 689 +#define TREAT 690 +#define TRIGGER 691 +#define TRIM 692 +#define TRUE_P 693 +#define TRUNCATE 694 +#define TRUSTED 695 +#define TRY_CAST 696 +#define TYPE_P 697 +#define TYPES_P 698 +#define UNBOUNDED 699 +#define UNCOMMITTED 700 +#define UNENCRYPTED 701 +#define UNION 702 +#define UNIQUE 703 +#define UNKNOWN 704 +#define UNLISTEN 705 +#define UNLOGGED 706 +#define UNPIVOT 707 +#define UNTIL 708 +#define UPDATE 709 +#define USE_P 710 +#define USER 711 +#define USING 712 +#define VACUUM 713 +#define VALID 714 +#define VALIDATE 715 +#define VALIDATOR 716 +#define VALUE_P 717 +#define VALUES 718 +#define VARCHAR 719 +#define VARIABLE_P 720 +#define VARIADIC 721 +#define VARYING 722 +#define VERBOSE 723 +#define VERSION_P 724 +#define VIEW 725 +#define VIEWS 726 +#define VIRTUAL 727 +#define VOLATILE 728 +#define WEEK_P 729 +#define WEEKS_P 730 +#define WHEN 731 +#define WHERE 732 +#define WHITESPACE_P 733 +#define WINDOW 734 +#define WITH 735 +#define WITHIN 736 +#define WITHOUT 737 +#define WORK 738 +#define WRAPPER 739 +#define WRITE_P 740 +#define XML_P 741 +#define XMLATTRIBUTES 742 +#define XMLCONCAT 743 +#define XMLELEMENT 744 +#define XMLEXISTS 745 +#define XMLFOREST 746 +#define XMLNAMESPACES 747 +#define XMLPARSE 748 +#define XMLPI 749 +#define XMLROOT 750 +#define XMLSERIALIZE 751 +#define XMLTABLE 752 +#define YEAR_P 753 +#define YEARS_P 754 +#define YES_P 755 +#define ZONE 756 +#define NOT_LA 757 +#define NULLS_LA 758 +#define WITH_LA 759 +#define POSTFIXOP 760 +#define UMINUS 761 @@ -1298,7 +1292,7 @@ static PGList *check_func_name(PGList *names, core_yyscan_t yyscanner); static PGList *check_indirection(PGList *indirection, core_yyscan_t yyscanner); static void insertSelectOptions(PGSelectStmt *stmt, PGList *sortClause, PGList *lockingClause, - PGNode *limitOffset, PGNode *limitCount, PGNode *isLimitOffsetFirst, + PGNode *limitOffset, PGNode *limitCount, PGWithClause *withClause, core_yyscan_t yyscanner); static PGNode *makeSetOp(PGSetOperation op, bool all, PGNode *larg, PGNode *rarg); @@ -1390,7 +1384,7 @@ typedef union YYSTYPE PGTransactionStmtType transactiontype; } /* Line 193 of yacc.c. */ -#line 1394 "third_party/libpg_query/grammar/grammar_out.cpp" +#line 1388 "third_party/libpg_query/grammar/grammar_out.cpp" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 @@ -1415,7 +1409,7 @@ typedef struct YYLTYPE /* Line 216 of yacc.c. */ -#line 1419 "third_party/libpg_query/grammar/grammar_out.cpp" +#line 1413 "third_party/libpg_query/grammar/grammar_out.cpp" #ifdef short # undef short @@ -1630,22 +1624,22 @@ union yyalloc #endif /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 879 +#define YYFINAL 874 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 75275 +#define YYLAST 74510 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 532 +#define YYNTOKENS 529 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 498 +#define YYNNTS 483 /* YYNRULES -- Number of rules. */ -#define YYNRULES 2214 +#define YYNRULES 2176 /* YYNRULES -- Number of states. */ -#define YYNSTATES 3689 +#define YYNSTATES 3617 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 -#define YYMAXUTOK 764 +#define YYMAXUTOK 761 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) @@ -1656,16 +1650,16 @@ static const yytype_uint16 yytranslate[] = 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 529, 528, 516, 2, 2, - 521, 522, 514, 512, 525, 513, 523, 515, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 526, 524, - 508, 510, 509, 527, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 526, 525, 513, 2, 2, + 518, 519, 511, 509, 522, 510, 520, 512, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 523, 521, + 505, 507, 506, 524, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 519, 2, 520, 517, 2, 2, 2, 2, 2, + 2, 516, 2, 517, 514, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 530, 2, 531, 2, 2, 2, 2, + 2, 2, 2, 527, 2, 528, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -1729,7 +1723,7 @@ static const yytype_uint16 yytranslate[] = 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 505, 506, 507, 511, 518 + 508, 515 }; #if YYDEBUG @@ -1743,1053 +1737,1034 @@ static const yytype_uint16 yyprhs[] = 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 94, 99, 106, 111, 118, 123, 130, 135, 142, 144, 147, 151, 154, - 156, 160, 163, 167, 169, 173, 175, 178, 181, 183, - 186, 189, 192, 195, 201, 205, 212, 219, 223, 230, - 234, 239, 246, 253, 260, 266, 272, 279, 289, 294, - 300, 308, 315, 320, 329, 334, 337, 342, 346, 353, - 358, 361, 364, 367, 370, 372, 375, 376, 378, 381, - 384, 387, 389, 393, 398, 401, 403, 404, 407, 411, - 414, 418, 420, 423, 425, 427, 429, 431, 433, 435, - 437, 440, 443, 445, 447, 449, 451, 453, 460, 467, - 476, 483, 492, 499, 508, 515, 524, 533, 544, 553, - 564, 566, 567, 577, 579, 584, 589, 597, 600, 602, - 606, 609, 612, 613, 618, 622, 623, 625, 626, 629, - 633, 639, 642, 645, 646, 655, 661, 662, 668, 674, - 682, 685, 686, 688, 690, 692, 696, 699, 700, 702, - 703, 705, 709, 711, 715, 717, 720, 722, 726, 729, - 736, 745, 751, 753, 754, 756, 760, 763, 768, 774, - 780, 789, 797, 799, 800, 809, 821, 832, 833, 835, - 836, 838, 840, 841, 844, 846, 849, 851, 855, 860, - 864, 874, 887, 889, 893, 895, 899, 903, 904, 909, - 916, 918, 921, 923, 925, 926, 928, 931, 934, 936, - 939, 942, 944, 947, 951, 954, 957, 960, 963, 967, - 971, 975, 977, 981, 983, 984, 986, 989, 992, 998, - 1006, 1007, 1010, 1013, 1017, 1021, 1024, 1027, 1030, 1032, - 1034, 1035, 1038, 1041, 1042, 1045, 1055, 1068, 1080, 1081, - 1084, 1086, 1088, 1090, 1092, 1094, 1096, 1100, 1101, 1103, - 1106, 1108, 1110, 1113, 1116, 1120, 1122, 1124, 1127, 1130, - 1132, 1135, 1139, 1145, 1149, 1152, 1158, 1160, 1162, 1164, - 1165, 1171, 1179, 1185, 1188, 1192, 1194, 1196, 1199, 1202, - 1203, 1207, 1212, 1217, 1218, 1222, 1225, 1226, 1230, 1232, - 1234, 1236, 1238, 1240, 1242, 1244, 1246, 1248, 1250, 1254, - 1258, 1260, 1263, 1266, 1269, 1272, 1275, 1278, 1279, 1283, - 1287, 1291, 1292, 1294, 1297, 1299, 1302, 1305, 1308, 1311, - 1314, 1318, 1321, 1324, 1326, 1330, 1332, 1334, 1336, 1338, - 1342, 1344, 1347, 1348, 1350, 1353, 1354, 1356, 1360, 1361, - 1364, 1365, 1369, 1373, 1375, 1381, 1385, 1387, 1391, 1393, - 1396, 1398, 1403, 1409, 1415, 1422, 1426, 1434, 1439, 1451, - 1453, 1457, 1460, 1463, 1466, 1467, 1471, 1473, 1475, 1478, - 1481, 1484, 1487, 1489, 1490, 1492, 1495, 1502, 1507, 1514, - 1519, 1526, 1535, 1537, 1539, 1541, 1543, 1546, 1548, 1551, - 1553, 1556, 1558, 1560, 1562, 1564, 1568, 1572, 1576, 1580, - 1582, 1585, 1588, 1590, 1594, 1596, 1598, 1600, 1604, 1606, - 1608, 1609, 1611, 1613, 1615, 1621, 1630, 1638, 1644, 1653, - 1661, 1666, 1671, 1673, 1677, 1679, 1681, 1685, 1687, 1691, - 1693, 1695, 1698, 1702, 1711, 1723, 1733, 1741, 1742, 1746, - 1750, 1752, 1754, 1758, 1759, 1761, 1765, 1767, 1768, 1770, - 1771, 1773, 1774, 1776, 1780, 1782, 1784, 1786, 1788, 1792, - 1794, 1796, 1797, 1800, 1803, 1804, 1807, 1808, 1810, 1811, - 1813, 1815, 1817, 1821, 1825, 1827, 1829, 1833, 1837, 1841, - 1845, 1849, 1853, 1858, 1862, 1865, 1867, 1869, 1871, 1873, - 1877, 1879, 1881, 1885, 1887, 1889, 1893, 1897, 1901, 1903, - 1906, 1911, 1916, 1919, 1923, 1929, 1935, 1937, 1939, 1943, - 1944, 1956, 1968, 1979, 1992, 1994, 1997, 2003, 2008, 2013, - 2018, 2023, 2031, 2037, 2042, 2050, 2057, 2067, 2077, 2082, - 2084, 2086, 2088, 2090, 2092, 2094, 2096, 2102, 2104, 2106, - 2110, 2112, 2115, 2118, 2121, 2125, 2127, 2131, 2140, 2146, - 2147, 2149, 2152, 2154, 2158, 2160, 2163, 2164, 2167, 2168, - 2172, 2176, 2181, 2186, 2191, 2196, 2200, 2203, 2205, 2207, - 2208, 2210, 2212, 2213, 2216, 2218, 2224, 2226, 2227, 2230, - 2233, 2234, 2236, 2237, 2241, 2247, 2249, 2253, 2258, 2262, - 2264, 2266, 2267, 2270, 2273, 2274, 2277, 2280, 2282, 2284, - 2286, 2287, 2290, 2295, 2301, 2306, 2309, 2313, 2315, 2317, - 2319, 2322, 2325, 2327, 2330, 2334, 2335, 2337, 2338, 2344, - 2346, 2351, 2358, 2361, 2363, 2364, 2369, 2370, 2372, 2374, - 2378, 2383, 2384, 2386, 2388, 2391, 2394, 2397, 2399, 2401, - 2404, 2407, 2409, 2411, 2413, 2415, 2417, 2419, 2423, 2427, - 2428, 2430, 2434, 2436, 2439, 2441, 2443, 2445, 2447, 2449, - 2452, 2457, 2462, 2468, 2470, 2472, 2475, 2476, 2479, 2480, - 2482, 2486, 2488, 2489, 2491, 2494, 2498, 2501, 2506, 2509, - 2513, 2516, 2517, 2519, 2522, 2523, 2528, 2534, 2536, 2539, - 2542, 2543, 2545, 2549, 2551, 2554, 2557, 2562, 2567, 2571, - 2575, 2579, 2583, 2587, 2591, 2595, 2597, 2602, 2607, 2617, - 2627, 2631, 2632, 2635, 2638, 2639, 2645, 2649, 2651, 2653, - 2657, 2663, 2667, 2669, 2672, 2674, 2678, 2684, 2686, 2689, - 2693, 2698, 2704, 2709, 2715, 2720, 2727, 2733, 2738, 2744, - 2750, 2756, 2759, 2764, 2766, 2768, 2769, 2771, 2776, 2782, - 2787, 2788, 2791, 2794, 2797, 2799, 2801, 2803, 2805, 2806, - 2811, 2814, 2816, 2819, 2822, 2827, 2830, 2837, 2840, 2842, - 2846, 2851, 2852, 2855, 2856, 2859, 2860, 2862, 2866, 2870, - 2873, 2874, 2877, 2882, 2884, 2886, 2888, 2889, 2892, 2896, - 2902, 2909, 2912, 2916, 2918, 2924, 2930, 2936, 2940, 2944, - 2948, 2953, 2954, 2956, 2958, 2960, 2962, 2964, 2967, 2972, - 2974, 2976, 2978, 2980, 2983, 2987, 2988, 2990, 2992, 2994, - 2996, 2998, 3001, 3004, 3007, 3010, 3013, 3015, 3019, 3020, - 3022, 3024, 3026, 3028, 3034, 3037, 3039, 3041, 3043, 3045, - 3050, 3052, 3055, 3058, 3060, 3064, 3068, 3071, 3073, 3074, - 3080, 3083, 3089, 3092, 3094, 3098, 3102, 3103, 3105, 3107, - 3109, 3111, 3113, 3115, 3117, 3119, 3121, 3123, 3125, 3127, - 3129, 3131, 3133, 3135, 3137, 3139, 3141, 3143, 3145, 3147, - 3149, 3151, 3153, 3155, 3157, 3159, 3161, 3163, 3165, 3167, - 3169, 3171, 3173, 3175, 3177, 3179, 3181, 3185, 3189, 3193, - 3197, 3201, 3205, 3209, 3210, 3212, 3216, 3220, 3226, 3229, - 3232, 3236, 3240, 3244, 3248, 3252, 3256, 3260, 3264, 3268, - 3272, 3276, 3280, 3284, 3288, 3292, 3295, 3298, 3302, 3306, - 3309, 3312, 3316, 3320, 3326, 3331, 3338, 3342, 3348, 3353, - 3360, 3365, 3372, 3378, 3386, 3390, 3393, 3398, 3402, 3405, - 3409, 3413, 3417, 3421, 3426, 3430, 3435, 3439, 3444, 3450, - 3457, 3464, 3472, 3479, 3487, 3494, 3502, 3506, 3511, 3516, - 3523, 3525, 3530, 3535, 3541, 3546, 3553, 3555, 3559, 3562, - 3565, 3569, 3573, 3577, 3581, 3585, 3589, 3593, 3597, 3601, - 3605, 3609, 3613, 3617, 3621, 3625, 3628, 3631, 3637, 3644, - 3651, 3659, 3661, 3664, 3666, 3668, 3670, 3673, 3676, 3681, - 3685, 3687, 3689, 3691, 3693, 3696, 3698, 3700, 3702, 3704, - 3706, 3708, 3710, 3713, 3718, 3721, 3725, 3729, 3734, 3738, - 3744, 3751, 3759, 3769, 3777, 3785, 3791, 3793, 3795, 3797, - 3803, 3810, 3817, 3822, 3827, 3832, 3837, 3844, 3850, 3856, - 3862, 3867, 3874, 3879, 3881, 3889, 3899, 3905, 3906, 3912, - 3917, 3918, 3920, 3921, 3924, 3925, 3927, 3931, 3935, 3938, - 3941, 3942, 3949, 3951, 3952, 3956, 3957, 3961, 3965, 3969, - 3970, 3972, 3977, 3980, 3983, 3986, 3989, 3992, 3996, 3999, - 4002, 4006, 4007, 4012, 4016, 4018, 4024, 4028, 4030, 4034, - 4036, 4039, 4043, 4045, 4049, 4051, 4054, 4056, 4057, 4059, - 4061, 4063, 4065, 4067, 4069, 4071, 4073, 4075, 4077, 4079, - 4081, 4083, 4085, 4087, 4089, 4091, 4093, 4095, 4097, 4102, - 4104, 4109, 4111, 4116, 4118, 4121, 4123, 4126, 4128, 4131, - 4133, 4137, 4139, 4143, 4145, 4148, 4150, 4154, 4156, 4159, - 4161, 4162, 4164, 4168, 4170, 4174, 4178, 4180, 4184, 4188, - 4189, 4191, 4193, 4195, 4197, 4199, 4201, 4203, 4205, 4207, - 4209, 4211, 4213, 4215, 4217, 4219, 4224, 4228, 4231, 4235, - 4236, 4240, 4244, 4247, 4250, 4252, 4253, 4256, 4259, 4263, - 4266, 4268, 4270, 4274, 4276, 4278, 4284, 4286, 4289, 4294, - 4297, 4298, 4300, 4301, 4303, 4307, 4309, 4311, 4314, 4318, - 4324, 4332, 4340, 4342, 4343, 4344, 4347, 4348, 4351, 4355, - 4359, 4363, 4369, 4377, 4385, 4386, 4389, 4391, 4392, 4394, - 4395, 4397, 4401, 4403, 4406, 4410, 4413, 4415, 4419, 4424, - 4427, 4429, 4433, 4435, 4439, 4441, 4444, 4446, 4447, 4451, - 4453, 4457, 4459, 4462, 4467, 4470, 4471, 4475, 4477, 4481, - 4483, 4486, 4491, 4494, 4495, 4497, 4501, 4503, 4507, 4509, - 4512, 4514, 4518, 4520, 4522, 4525, 4527, 4529, 4532, 4534, - 4536, 4539, 4547, 4550, 4556, 4560, 4564, 4566, 4568, 4570, - 4572, 4574, 4576, 4578, 4580, 4582, 4584, 4586, 4588, 4590, - 4592, 4595, 4598, 4602, 4606, 4607, 4609, 4611, 4613, 4619, - 4623, 4624, 4626, 4628, 4630, 4632, 4634, 4636, 4641, 4649, - 4656, 4659, 4660, 4662, 4664, 4666, 4668, 4682, 4699, 4701, - 4704, 4705, 4707, 4708, 4710, 4711, 4714, 4715, 4717, 4718, - 4725, 4734, 4741, 4750, 4757, 4766, 4770, 4773, 4775, 4776, - 4783, 4790, 4792, 4794, 4796, 4798, 4800, 4802, 4805, 4807, - 4809, 4811, 4813, 4815, 4820, 4827, 4831, 4834, 4839, 4843, - 4849, 4851, 4852, 4854, 4856, 4857, 4859, 4861, 4863, 4865, - 4867, 4869, 4871, 4873, 4875, 4877, 4879, 4881, 4883, 4885, - 4887, 4889, 4891, 4893, 4895, 4897, 4899, 4901, 4903, 4905, - 4907, 4909, 4911, 4913, 4915, 4917, 4919, 4921, 4923, 4925, - 4927, 4929, 4931, 4935, 4937, 4939, 4941, 4943, 4945, 4947, - 4950, 4952, 4954, 4957, 4961, 4965, 4969, 4973, 4975, 4979, - 4983, 4986, 4990, 4994, 4996, 4998, 5000, 5004, 5010, 5012, - 5014, 5016, 5018, 5022, 5025, 5030, 5037, 5044, 5045, 5047, - 5049, 5051, 5052, 5055, 5058, 5063, 5070, 5076, 5081, 5088, - 5090, 5092, 5094, 5096, 5098, 5100, 5101, 5103, 5107, 5109, - 5110, 5118, 5122, 5124, 5127, 5131, 5134, 5135, 5138, 5139, - 5142, 5147, 5153, 5162, 5170, 5173, 5177, 5183, 5185, 5186, - 5189, 5190, 5193, 5197, 5201, 5205, 5209, 5211, 5213, 5215, - 5218, 5222, 5225, 5228, 5231, 5234, 5238, 5243, 5247, 5249, - 5251, 5253, 5255, 5257, 5259, 5260, 5262, 5266, 5269, 5279, - 5292, 5304, 5317, 5332, 5336, 5341, 5346, 5347, 5355, 5366, - 5376, 5379, 5383, 5384, 5389, 5391, 5393, 5395, 5397, 5399, - 5401, 5403, 5405, 5407, 5409, 5411, 5413, 5415, 5417, 5419, - 5421, 5423, 5425, 5427, 5429, 5431, 5433, 5435, 5437, 5439, - 5441, 5443, 5445, 5447, 5449, 5451, 5453, 5455, 5457, 5459, - 5461, 5463, 5465, 5467, 5469, 5471, 5473, 5475, 5477, 5479, - 5481, 5483, 5485, 5487, 5489, 5491, 5493, 5495, 5497, 5499, - 5501, 5503, 5505, 5507, 5509, 5511, 5513, 5515, 5517, 5519, - 5521, 5523, 5525, 5527, 5529, 5531, 5533, 5535, 5537, 5539, - 5541, 5543, 5545, 5547, 5549, 5551, 5553, 5555, 5557, 5559, - 5561, 5563, 5565, 5567, 5569, 5571, 5573, 5575, 5577, 5579, - 5581, 5583, 5585, 5587, 5589, 5591, 5593, 5595, 5597, 5599, - 5601, 5603, 5605, 5607, 5609, 5611, 5613, 5615, 5617, 5619, - 5621, 5623, 5625, 5627, 5629, 5631, 5633, 5635, 5637, 5639, - 5641, 5643, 5645, 5647, 5649, 5651, 5653, 5655, 5657, 5659, - 5661, 5663, 5665, 5667, 5669, 5671, 5673, 5675, 5677, 5679, - 5681, 5683, 5685, 5687, 5689, 5691, 5693, 5695, 5697, 5699, - 5701, 5703, 5705, 5707, 5709, 5711, 5713, 5715, 5717, 5719, - 5721, 5723, 5725, 5727, 5729, 5731, 5733, 5735, 5737, 5739, - 5741, 5743, 5745, 5747, 5749, 5751, 5753, 5755, 5757, 5759, - 5761, 5763, 5765, 5767, 5769, 5771, 5773, 5775, 5777, 5779, - 5781, 5783, 5785, 5787, 5789, 5791, 5793, 5795, 5797, 5799, - 5801, 5803, 5805, 5807, 5809, 5811, 5813, 5815, 5817, 5819, - 5821, 5823, 5825, 5827, 5829, 5831, 5833, 5835, 5837, 5839, - 5841, 5843, 5845, 5847, 5849, 5851, 5853, 5855, 5857, 5859, - 5861, 5863, 5865, 5867, 5869, 5871, 5873, 5875, 5877, 5879, - 5881, 5883, 5885, 5887, 5889, 5891, 5893, 5895, 5897, 5899, - 5901, 5903, 5905, 5907, 5909, 5911, 5913, 5915, 5917, 5919, - 5921, 5923, 5925, 5927, 5929, 5931, 5933, 5935, 5937, 5939, - 5941, 5943, 5945, 5947, 5949, 5951, 5953, 5955, 5957, 5959, - 5961, 5963, 5965, 5967, 5969, 5971, 5973, 5975, 5977, 5979, - 5981, 5983, 5985, 5987, 5989, 5991, 5993, 5995, 5997, 5999, - 6001, 6003, 6005, 6007, 6009, 6011, 6013, 6015, 6017, 6019, - 6021, 6023, 6025, 6027, 6029, 6031, 6033, 6035, 6037, 6039, - 6041, 6043, 6045, 6047, 6049, 6051, 6053, 6055, 6057, 6059, - 6061, 6063, 6065, 6067, 6069, 6071, 6073, 6075, 6077, 6079, - 6081, 6083, 6085, 6087, 6089, 6091, 6093, 6095, 6097, 6099, - 6101, 6103, 6105, 6107, 6109, 6111, 6113, 6115, 6117, 6119, - 6121, 6123, 6125, 6127, 6129, 6131, 6133, 6135, 6137, 6139, - 6141, 6143, 6145, 6147, 6149, 6151, 6153, 6155, 6157, 6159, - 6161, 6163, 6165, 6167, 6169, 6171, 6173, 6175, 6177, 6179, - 6181, 6183, 6185, 6187, 6189, 6191, 6193, 6195, 6197, 6199, - 6201, 6203, 6205, 6207, 6209, 6211, 6213, 6215, 6217, 6219, - 6221, 6223, 6225, 6227, 6229, 6231, 6233, 6235, 6237, 6239, - 6241, 6243, 6245, 6247, 6249, 6251, 6253, 6255, 6257, 6259, - 6261, 6263, 6265, 6267, 6269, 6271, 6273, 6275, 6277, 6279, - 6281, 6283, 6285, 6287, 6289, 6291, 6293, 6295, 6297, 6299, - 6301, 6303, 6305, 6307, 6309, 6311, 6313, 6315, 6317, 6319, - 6321, 6323, 6325, 6327, 6329, 6331, 6333, 6335, 6337, 6339, - 6341, 6343, 6345, 6347, 6349, 6351, 6353, 6355, 6357, 6359, - 6361, 6363, 6365, 6367, 6369, 6371, 6373, 6375, 6377, 6379, - 6381, 6383, 6385, 6387, 6389, 6391, 6393, 6395, 6397, 6399, - 6401, 6403, 6405, 6407, 6409, 6411, 6413, 6415, 6417, 6419, - 6421, 6423, 6425, 6427, 6429, 6431, 6433, 6435, 6437, 6439, - 6441, 6443, 6445, 6447, 6449, 6451, 6453, 6455, 6457, 6459, - 6461, 6463, 6465, 6467, 6469, 6471, 6473, 6475, 6477, 6479, - 6481, 6483, 6485, 6487, 6489, 6491, 6493, 6495, 6497, 6499, - 6501, 6503, 6505, 6507, 6509, 6511, 6513, 6515, 6517, 6519, - 6521, 6523, 6525, 6527, 6529, 6531, 6533, 6535, 6537, 6539, - 6541, 6543, 6545, 6547, 6549, 6551, 6553, 6555, 6557, 6559, - 6561, 6563, 6565, 6567, 6569, 6571, 6573, 6575, 6577, 6579, - 6581, 6583, 6585, 6587, 6589, 6591, 6593, 6595, 6597, 6599, - 6601, 6603, 6605, 6607, 6609, 6611, 6613, 6615, 6617, 6619, - 6621, 6623, 6625, 6627, 6629, 6631, 6633, 6635, 6637, 6639, - 6641, 6643, 6645, 6647, 6649 + 156, 160, 163, 167, 169, 173, 176, 182, 186, 193, + 198, 205, 212, 219, 225, 231, 238, 248, 253, 259, + 267, 274, 279, 288, 293, 296, 301, 305, 312, 317, + 320, 323, 326, 329, 331, 334, 335, 337, 340, 343, + 346, 348, 352, 357, 360, 362, 363, 366, 370, 373, + 377, 379, 382, 384, 386, 388, 390, 392, 394, 396, + 399, 402, 404, 406, 408, 410, 412, 419, 426, 435, + 442, 451, 458, 467, 474, 483, 492, 503, 512, 523, + 525, 526, 536, 538, 543, 548, 556, 559, 561, 565, + 568, 571, 572, 577, 581, 582, 584, 585, 588, 592, + 598, 601, 604, 605, 614, 620, 621, 627, 633, 641, + 644, 645, 647, 649, 651, 655, 658, 659, 661, 662, + 664, 668, 670, 674, 676, 679, 681, 685, 688, 695, + 704, 710, 712, 713, 715, 719, 722, 727, 733, 739, + 748, 756, 758, 759, 768, 780, 791, 792, 794, 795, + 797, 799, 800, 803, 808, 812, 822, 835, 837, 841, + 843, 847, 851, 852, 857, 864, 866, 869, 871, 873, + 874, 876, 879, 882, 884, 887, 890, 892, 895, 899, + 902, 905, 908, 911, 915, 919, 923, 925, 929, 931, + 932, 934, 937, 940, 946, 954, 955, 958, 961, 965, + 969, 972, 975, 978, 980, 982, 983, 986, 989, 990, + 993, 1003, 1016, 1028, 1029, 1032, 1034, 1036, 1038, 1040, + 1042, 1044, 1048, 1049, 1051, 1054, 1056, 1058, 1061, 1064, + 1068, 1070, 1072, 1075, 1078, 1080, 1083, 1087, 1093, 1097, + 1100, 1106, 1108, 1110, 1112, 1113, 1119, 1127, 1133, 1136, + 1140, 1142, 1144, 1147, 1150, 1151, 1155, 1160, 1165, 1166, + 1170, 1173, 1174, 1178, 1180, 1182, 1184, 1186, 1188, 1190, + 1192, 1194, 1196, 1198, 1202, 1206, 1208, 1211, 1214, 1217, + 1220, 1223, 1226, 1227, 1231, 1235, 1239, 1240, 1242, 1245, + 1247, 1250, 1253, 1256, 1259, 1263, 1268, 1270, 1274, 1276, + 1278, 1280, 1282, 1286, 1288, 1291, 1292, 1294, 1297, 1298, + 1300, 1304, 1305, 1308, 1309, 1313, 1317, 1319, 1325, 1329, + 1331, 1335, 1337, 1340, 1342, 1347, 1353, 1359, 1366, 1370, + 1378, 1383, 1395, 1397, 1401, 1404, 1407, 1410, 1411, 1415, + 1417, 1419, 1422, 1425, 1428, 1431, 1433, 1434, 1436, 1439, + 1446, 1451, 1458, 1463, 1470, 1479, 1481, 1483, 1485, 1487, + 1490, 1492, 1495, 1497, 1500, 1502, 1504, 1506, 1508, 1512, + 1516, 1520, 1524, 1526, 1529, 1532, 1534, 1538, 1540, 1542, + 1544, 1548, 1550, 1552, 1553, 1555, 1557, 1559, 1565, 1574, + 1582, 1588, 1597, 1605, 1610, 1615, 1617, 1621, 1623, 1625, + 1629, 1631, 1635, 1637, 1639, 1642, 1646, 1655, 1667, 1677, + 1685, 1686, 1690, 1694, 1696, 1698, 1702, 1703, 1705, 1709, + 1711, 1712, 1714, 1715, 1717, 1718, 1720, 1724, 1726, 1728, + 1730, 1732, 1736, 1738, 1740, 1741, 1744, 1747, 1748, 1751, + 1752, 1754, 1755, 1757, 1759, 1761, 1765, 1769, 1771, 1773, + 1777, 1781, 1785, 1789, 1793, 1797, 1802, 1806, 1809, 1811, + 1813, 1815, 1817, 1821, 1823, 1825, 1829, 1831, 1833, 1837, + 1841, 1845, 1847, 1850, 1855, 1860, 1863, 1867, 1873, 1879, + 1881, 1883, 1887, 1888, 1900, 1912, 1923, 1936, 1938, 1941, + 1947, 1952, 1957, 1962, 1967, 1975, 1981, 1986, 1994, 2001, + 2011, 2021, 2026, 2028, 2030, 2032, 2034, 2036, 2038, 2040, + 2046, 2048, 2050, 2054, 2056, 2059, 2062, 2065, 2069, 2071, + 2075, 2083, 2085, 2088, 2089, 2092, 2093, 2097, 2101, 2106, + 2111, 2116, 2121, 2125, 2128, 2130, 2132, 2133, 2135, 2137, + 2138, 2141, 2143, 2149, 2151, 2152, 2155, 2158, 2159, 2161, + 2162, 2166, 2172, 2174, 2178, 2183, 2187, 2189, 2191, 2192, + 2195, 2198, 2199, 2202, 2205, 2207, 2209, 2211, 2212, 2215, + 2220, 2226, 2231, 2234, 2238, 2240, 2242, 2244, 2247, 2250, + 2252, 2255, 2259, 2260, 2262, 2263, 2269, 2271, 2276, 2283, + 2286, 2288, 2289, 2294, 2295, 2297, 2299, 2302, 2305, 2308, + 2310, 2312, 2315, 2318, 2320, 2322, 2324, 2326, 2328, 2330, + 2334, 2338, 2339, 2341, 2345, 2347, 2350, 2352, 2354, 2356, + 2358, 2360, 2363, 2368, 2373, 2379, 2381, 2383, 2386, 2387, + 2390, 2391, 2393, 2397, 2399, 2400, 2402, 2405, 2409, 2412, + 2417, 2420, 2424, 2427, 2428, 2430, 2433, 2434, 2439, 2445, + 2447, 2450, 2453, 2454, 2456, 2460, 2462, 2465, 2468, 2472, + 2476, 2480, 2484, 2488, 2492, 2496, 2500, 2504, 2506, 2511, + 2516, 2526, 2536, 2540, 2541, 2544, 2547, 2548, 2554, 2558, + 2560, 2562, 2566, 2572, 2576, 2578, 2581, 2583, 2587, 2593, + 2595, 2598, 2602, 2607, 2613, 2618, 2624, 2629, 2636, 2642, + 2647, 2653, 2659, 2665, 2668, 2673, 2675, 2677, 2678, 2680, + 2685, 2691, 2696, 2697, 2700, 2703, 2706, 2708, 2710, 2712, + 2714, 2715, 2720, 2723, 2725, 2728, 2731, 2736, 2739, 2746, + 2749, 2751, 2755, 2760, 2761, 2764, 2765, 2768, 2769, 2771, + 2775, 2779, 2782, 2783, 2786, 2791, 2793, 2795, 2797, 2798, + 2801, 2805, 2811, 2818, 2821, 2825, 2827, 2833, 2839, 2845, + 2849, 2853, 2857, 2862, 2863, 2865, 2867, 2869, 2871, 2873, + 2876, 2881, 2883, 2885, 2887, 2889, 2892, 2896, 2897, 2899, + 2901, 2903, 2905, 2907, 2910, 2913, 2916, 2919, 2922, 2924, + 2928, 2929, 2931, 2933, 2935, 2937, 2943, 2946, 2948, 2950, + 2952, 2954, 2959, 2961, 2964, 2967, 2969, 2973, 2977, 2980, + 2982, 2983, 2989, 2992, 2998, 3001, 3003, 3007, 3011, 3012, + 3014, 3016, 3018, 3020, 3022, 3024, 3026, 3028, 3030, 3032, + 3034, 3036, 3038, 3040, 3042, 3044, 3046, 3048, 3050, 3052, + 3054, 3056, 3058, 3060, 3062, 3064, 3066, 3068, 3070, 3072, + 3074, 3076, 3078, 3080, 3082, 3084, 3086, 3088, 3090, 3094, + 3098, 3102, 3106, 3110, 3114, 3118, 3119, 3121, 3125, 3129, + 3135, 3138, 3141, 3145, 3149, 3153, 3157, 3161, 3165, 3169, + 3173, 3177, 3181, 3185, 3189, 3193, 3197, 3201, 3204, 3207, + 3211, 3215, 3218, 3221, 3225, 3229, 3235, 3240, 3247, 3251, + 3257, 3262, 3269, 3274, 3281, 3287, 3295, 3299, 3302, 3307, + 3311, 3314, 3318, 3322, 3326, 3330, 3335, 3339, 3344, 3348, + 3353, 3359, 3366, 3373, 3381, 3388, 3396, 3403, 3411, 3415, + 3420, 3425, 3432, 3434, 3440, 3445, 3450, 3457, 3459, 3463, + 3466, 3469, 3473, 3477, 3481, 3485, 3489, 3493, 3497, 3501, + 3505, 3509, 3513, 3517, 3521, 3525, 3529, 3532, 3535, 3541, + 3548, 3555, 3563, 3565, 3568, 3570, 3572, 3574, 3577, 3580, + 3585, 3589, 3591, 3593, 3595, 3597, 3600, 3602, 3604, 3606, + 3608, 3610, 3612, 3614, 3617, 3622, 3625, 3629, 3633, 3638, + 3642, 3648, 3655, 3663, 3673, 3681, 3689, 3695, 3697, 3699, + 3701, 3707, 3714, 3721, 3726, 3731, 3736, 3741, 3748, 3754, + 3760, 3766, 3771, 3778, 3783, 3785, 3793, 3803, 3809, 3810, + 3816, 3821, 3822, 3824, 3825, 3828, 3829, 3831, 3835, 3839, + 3842, 3845, 3846, 3853, 3855, 3856, 3860, 3861, 3865, 3869, + 3873, 3874, 3876, 3881, 3884, 3887, 3890, 3893, 3896, 3900, + 3903, 3906, 3910, 3911, 3916, 3920, 3922, 3928, 3932, 3934, + 3938, 3940, 3943, 3947, 3949, 3953, 3955, 3958, 3960, 3961, + 3963, 3965, 3967, 3969, 3971, 3973, 3975, 3977, 3979, 3981, + 3983, 3985, 3987, 3989, 3991, 3993, 3995, 3997, 3999, 4001, + 4006, 4008, 4013, 4015, 4020, 4022, 4025, 4027, 4030, 4032, + 4035, 4037, 4041, 4043, 4047, 4049, 4052, 4054, 4058, 4060, + 4063, 4065, 4066, 4068, 4072, 4074, 4078, 4082, 4084, 4088, + 4092, 4093, 4095, 4097, 4099, 4101, 4103, 4105, 4107, 4109, + 4111, 4113, 4115, 4117, 4119, 4121, 4123, 4128, 4132, 4135, + 4139, 4140, 4144, 4148, 4151, 4154, 4156, 4157, 4160, 4163, + 4167, 4170, 4172, 4174, 4178, 4180, 4182, 4188, 4190, 4193, + 4198, 4201, 4202, 4204, 4205, 4207, 4211, 4213, 4215, 4218, + 4222, 4228, 4236, 4244, 4246, 4247, 4248, 4251, 4252, 4255, + 4259, 4263, 4267, 4273, 4281, 4289, 4290, 4293, 4295, 4296, + 4298, 4299, 4301, 4305, 4307, 4310, 4314, 4317, 4319, 4323, + 4328, 4331, 4333, 4337, 4339, 4343, 4345, 4348, 4350, 4351, + 4355, 4357, 4361, 4363, 4366, 4371, 4374, 4375, 4379, 4381, + 4385, 4387, 4390, 4395, 4398, 4399, 4401, 4405, 4407, 4411, + 4413, 4416, 4418, 4422, 4424, 4426, 4429, 4431, 4433, 4436, + 4438, 4440, 4443, 4451, 4454, 4460, 4464, 4468, 4470, 4472, + 4474, 4476, 4478, 4480, 4482, 4484, 4486, 4488, 4490, 4492, + 4494, 4496, 4499, 4502, 4506, 4510, 4511, 4513, 4515, 4517, + 4523, 4527, 4528, 4530, 4532, 4534, 4536, 4538, 4540, 4545, + 4553, 4560, 4563, 4564, 4566, 4568, 4570, 4572, 4586, 4603, + 4605, 4608, 4609, 4611, 4612, 4614, 4615, 4618, 4619, 4621, + 4622, 4629, 4638, 4645, 4654, 4661, 4670, 4674, 4677, 4679, + 4680, 4687, 4694, 4696, 4698, 4700, 4702, 4704, 4706, 4709, + 4711, 4713, 4715, 4717, 4719, 4724, 4731, 4735, 4738, 4743, + 4747, 4753, 4755, 4756, 4758, 4760, 4761, 4763, 4765, 4767, + 4769, 4771, 4773, 4775, 4777, 4779, 4781, 4783, 4785, 4787, + 4789, 4791, 4793, 4795, 4797, 4799, 4801, 4803, 4805, 4807, + 4809, 4811, 4813, 4815, 4817, 4819, 4821, 4823, 4825, 4827, + 4829, 4831, 4833, 4835, 4839, 4841, 4843, 4845, 4847, 4849, + 4851, 4854, 4856, 4858, 4861, 4865, 4869, 4873, 4877, 4879, + 4883, 4887, 4890, 4894, 4898, 4900, 4902, 4904, 4908, 4914, + 4916, 4918, 4920, 4922, 4926, 4929, 4934, 4941, 4948, 4949, + 4951, 4953, 4955, 4956, 4959, 4962, 4967, 4974, 4980, 4985, + 4992, 4994, 4996, 4998, 5000, 5002, 5004, 5005, 5007, 5011, + 5013, 5014, 5022, 5026, 5028, 5031, 5035, 5038, 5039, 5042, + 5043, 5046, 5051, 5057, 5066, 5069, 5073, 5079, 5081, 5082, + 5085, 5086, 5089, 5093, 5097, 5101, 5105, 5107, 5109, 5111, + 5114, 5118, 5121, 5124, 5127, 5130, 5134, 5139, 5143, 5145, + 5147, 5149, 5151, 5153, 5155, 5156, 5158, 5162, 5165, 5175, + 5188, 5200, 5213, 5228, 5232, 5237, 5242, 5243, 5251, 5262, + 5272, 5275, 5279, 5280, 5285, 5287, 5289, 5291, 5293, 5295, + 5297, 5299, 5301, 5303, 5305, 5307, 5309, 5311, 5313, 5315, + 5317, 5319, 5321, 5323, 5325, 5327, 5329, 5331, 5333, 5335, + 5337, 5339, 5341, 5343, 5345, 5347, 5349, 5351, 5353, 5355, + 5357, 5359, 5361, 5363, 5365, 5367, 5369, 5371, 5373, 5375, + 5377, 5379, 5381, 5383, 5385, 5387, 5389, 5391, 5393, 5395, + 5397, 5399, 5401, 5403, 5405, 5407, 5409, 5411, 5413, 5415, + 5417, 5419, 5421, 5423, 5425, 5427, 5429, 5431, 5433, 5435, + 5437, 5439, 5441, 5443, 5445, 5447, 5449, 5451, 5453, 5455, + 5457, 5459, 5461, 5463, 5465, 5467, 5469, 5471, 5473, 5475, + 5477, 5479, 5481, 5483, 5485, 5487, 5489, 5491, 5493, 5495, + 5497, 5499, 5501, 5503, 5505, 5507, 5509, 5511, 5513, 5515, + 5517, 5519, 5521, 5523, 5525, 5527, 5529, 5531, 5533, 5535, + 5537, 5539, 5541, 5543, 5545, 5547, 5549, 5551, 5553, 5555, + 5557, 5559, 5561, 5563, 5565, 5567, 5569, 5571, 5573, 5575, + 5577, 5579, 5581, 5583, 5585, 5587, 5589, 5591, 5593, 5595, + 5597, 5599, 5601, 5603, 5605, 5607, 5609, 5611, 5613, 5615, + 5617, 5619, 5621, 5623, 5625, 5627, 5629, 5631, 5633, 5635, + 5637, 5639, 5641, 5643, 5645, 5647, 5649, 5651, 5653, 5655, + 5657, 5659, 5661, 5663, 5665, 5667, 5669, 5671, 5673, 5675, + 5677, 5679, 5681, 5683, 5685, 5687, 5689, 5691, 5693, 5695, + 5697, 5699, 5701, 5703, 5705, 5707, 5709, 5711, 5713, 5715, + 5717, 5719, 5721, 5723, 5725, 5727, 5729, 5731, 5733, 5735, + 5737, 5739, 5741, 5743, 5745, 5747, 5749, 5751, 5753, 5755, + 5757, 5759, 5761, 5763, 5765, 5767, 5769, 5771, 5773, 5775, + 5777, 5779, 5781, 5783, 5785, 5787, 5789, 5791, 5793, 5795, + 5797, 5799, 5801, 5803, 5805, 5807, 5809, 5811, 5813, 5815, + 5817, 5819, 5821, 5823, 5825, 5827, 5829, 5831, 5833, 5835, + 5837, 5839, 5841, 5843, 5845, 5847, 5849, 5851, 5853, 5855, + 5857, 5859, 5861, 5863, 5865, 5867, 5869, 5871, 5873, 5875, + 5877, 5879, 5881, 5883, 5885, 5887, 5889, 5891, 5893, 5895, + 5897, 5899, 5901, 5903, 5905, 5907, 5909, 5911, 5913, 5915, + 5917, 5919, 5921, 5923, 5925, 5927, 5929, 5931, 5933, 5935, + 5937, 5939, 5941, 5943, 5945, 5947, 5949, 5951, 5953, 5955, + 5957, 5959, 5961, 5963, 5965, 5967, 5969, 5971, 5973, 5975, + 5977, 5979, 5981, 5983, 5985, 5987, 5989, 5991, 5993, 5995, + 5997, 5999, 6001, 6003, 6005, 6007, 6009, 6011, 6013, 6015, + 6017, 6019, 6021, 6023, 6025, 6027, 6029, 6031, 6033, 6035, + 6037, 6039, 6041, 6043, 6045, 6047, 6049, 6051, 6053, 6055, + 6057, 6059, 6061, 6063, 6065, 6067, 6069, 6071, 6073, 6075, + 6077, 6079, 6081, 6083, 6085, 6087, 6089, 6091, 6093, 6095, + 6097, 6099, 6101, 6103, 6105, 6107, 6109, 6111, 6113, 6115, + 6117, 6119, 6121, 6123, 6125, 6127, 6129, 6131, 6133, 6135, + 6137, 6139, 6141, 6143, 6145, 6147, 6149, 6151, 6153, 6155, + 6157, 6159, 6161, 6163, 6165, 6167, 6169, 6171, 6173, 6175, + 6177, 6179, 6181, 6183, 6185, 6187, 6189, 6191, 6193, 6195, + 6197, 6199, 6201, 6203, 6205, 6207, 6209, 6211, 6213, 6215, + 6217, 6219, 6221, 6223, 6225, 6227, 6229, 6231, 6233, 6235, + 6237, 6239, 6241, 6243, 6245, 6247, 6249, 6251, 6253, 6255, + 6257, 6259, 6261, 6263, 6265, 6267, 6269, 6271, 6273, 6275, + 6277, 6279, 6281, 6283, 6285, 6287, 6289, 6291, 6293, 6295, + 6297, 6299, 6301, 6303, 6305, 6307, 6309, 6311, 6313, 6315, + 6317, 6319, 6321, 6323, 6325, 6327, 6329, 6331, 6333, 6335, + 6337, 6339, 6341, 6343, 6345, 6347, 6349, 6351, 6353, 6355, + 6357, 6359, 6361, 6363, 6365, 6367, 6369, 6371, 6373, 6375, + 6377, 6379, 6381, 6383, 6385, 6387, 6389, 6391, 6393, 6395, + 6397, 6399, 6401, 6403, 6405, 6407, 6409, 6411, 6413, 6415, + 6417, 6419, 6421, 6423, 6425, 6427, 6429, 6431, 6433, 6435, + 6437, 6439, 6441, 6443, 6445, 6447, 6449, 6451, 6453, 6455, + 6457, 6459, 6461, 6463, 6465, 6467, 6469, 6471, 6473, 6475, + 6477, 6479, 6481, 6483, 6485, 6487, 6489, 6491, 6493, 6495, + 6497, 6499, 6501, 6503, 6505, 6507, 6509, 6511, 6513, 6515, + 6517, 6519, 6521, 6523, 6525, 6527, 6529 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int16 yyrhs[] = { - 533, 0, -1, 534, -1, 534, 524, 535, -1, 535, - -1, 966, -1, 601, -1, 536, -1, 1004, -1, 1005, - -1, 1017, -1, 967, -1, 969, -1, 680, -1, 1020, - -1, 670, -1, 956, -1, 589, -1, 587, -1, 614, - -1, 583, -1, 551, -1, 1000, -1, 1006, -1, 608, - -1, 664, -1, 597, -1, 974, -1, 972, -1, 973, - -1, 959, -1, 562, -1, 991, -1, 586, -1, 953, - -1, 560, -1, 698, -1, 610, -1, 596, -1, 679, - -1, 613, -1, 995, -1, 1009, -1, 985, -1, 1012, - -1, 1018, -1, -1, 32, 421, 793, 548, -1, 32, - 421, 192, 152, 793, 548, -1, 32, 203, 552, 548, - -1, 32, 203, 192, 152, 552, 548, -1, 32, 385, - 552, 548, -1, 32, 385, 192, 152, 552, 548, -1, - 32, 473, 552, 548, -1, 32, 473, 192, 152, 552, - 548, -1, 539, -1, 537, 539, -1, 390, 117, 842, - -1, 137, 117, -1, 360, -1, 360, 603, 604, -1, - 390, 605, -1, 390, 176, 663, -1, 547, -1, 540, - 525, 547, -1, 542, -1, 541, 542, -1, 523, 558, - -1, 553, -1, 553, 541, -1, 543, 641, -1, 543, - 642, -1, 26, 544, -1, 26, 192, 275, 152, 544, - -1, 26, 82, 544, -1, 26, 82, 192, 275, 152, - 544, -1, 390, 311, 59, 521, 891, 522, -1, 358, - 311, 59, -1, 390, 401, 59, 521, 727, 522, -1, - 358, 401, 59, -1, 32, 561, 553, 538, -1, 32, - 561, 553, 137, 275, 280, -1, 32, 561, 553, 390, - 275, 280, -1, 32, 561, 553, 390, 407, 607, -1, - 32, 561, 553, 390, 629, -1, 32, 561, 553, 358, - 629, -1, 32, 561, 553, 390, 410, 553, -1, 32, - 561, 553, 26, 176, 663, 40, 191, 617, -1, 32, - 561, 553, 537, -1, 32, 561, 553, 137, 191, -1, - 32, 561, 553, 137, 191, 192, 152, -1, 137, 561, - 192, 152, 543, 668, -1, 137, 561, 543, 668, -1, - 32, 561, 553, 550, 444, 805, 802, 546, -1, 32, - 561, 553, 549, -1, 26, 631, -1, 32, 93, 941, - 615, -1, 463, 93, 941, -1, 137, 93, 192, 152, - 941, 668, -1, 137, 93, 941, 668, -1, 390, 245, - -1, 390, 453, -1, 390, 629, -1, 358, 629, -1, - 549, -1, 460, 842, -1, -1, 625, -1, 390, 625, - -1, 26, 625, -1, 137, 639, -1, 545, -1, 548, - 525, 545, -1, 294, 521, 540, 522, -1, 390, 107, - -1, 390, -1, -1, 111, 941, -1, 111, 327, 941, - -1, 111, 30, -1, 111, 327, 30, -1, 554, -1, - 553, 556, -1, 3, -1, 1023, -1, 1024, -1, 553, - -1, 5, -1, 5, -1, 557, -1, 556, 557, -1, - 523, 558, -1, 559, -1, 3, -1, 1027, -1, 1023, - -1, 1029, -1, 32, 374, 941, 354, 433, 941, -1, - 32, 421, 793, 354, 433, 941, -1, 32, 421, 192, - 152, 793, 354, 433, 941, -1, 32, 385, 552, 354, - 433, 941, -1, 32, 385, 192, 152, 552, 354, 433, - 941, -1, 32, 473, 552, 354, 433, 941, -1, 32, - 473, 192, 152, 552, 354, 433, 941, -1, 32, 203, - 552, 354, 433, 941, -1, 32, 203, 192, 152, 552, - 354, 433, 941, -1, 32, 421, 793, 354, 561, 543, - 433, 941, -1, 32, 421, 192, 152, 793, 354, 561, - 543, 433, 941, -1, 32, 421, 793, 354, 93, 941, - 433, 941, -1, 32, 421, 192, 152, 793, 354, 93, - 941, 433, 941, -1, 82, -1, -1, 567, 213, 570, - 220, 564, 565, 563, 571, 573, -1, 698, -1, 304, - 574, 465, 698, -1, 521, 578, 522, 698, -1, 521, - 578, 522, 304, 574, 465, 698, -1, 117, 466, -1, - 552, -1, 552, 40, 553, -1, 59, 266, -1, 59, - 322, -1, -1, 521, 581, 522, 799, -1, 290, 93, - 941, -1, -1, 710, -1, -1, 553, 915, -1, 582, - 510, 842, -1, 521, 575, 522, 510, 842, -1, 295, - 356, -1, 295, 193, -1, -1, 290, 91, 566, 133, - 457, 390, 580, 799, -1, 290, 91, 566, 133, 276, - -1, -1, 553, 576, 577, 729, 730, -1, 854, 576, - 577, 729, 730, -1, 521, 842, 522, 576, 577, 729, - 730, -1, 362, 921, -1, -1, 459, -1, 420, -1, - 582, -1, 575, 525, 582, -1, 80, 948, -1, -1, - 948, -1, -1, 568, -1, 578, 525, 568, -1, 569, - -1, 579, 525, 569, -1, 579, -1, 579, 525, -1, - 572, -1, 581, 525, 572, -1, 553, 915, -1, 100, - 444, 552, 40, 144, 699, -1, 100, 444, 552, 40, - 144, 521, 584, 522, -1, 100, 444, 552, 40, 806, - -1, 585, -1, -1, 555, -1, 585, 525, 555, -1, - 324, 553, -1, 324, 553, 510, 990, -1, 324, 553, - 521, 893, 522, -1, 100, 662, 385, 552, 588, -1, - 100, 662, 385, 192, 275, 152, 552, 588, -1, 100, - 295, 356, 662, 385, 552, 588, -1, 602, -1, -1, - 100, 591, 381, 590, 592, 521, 595, 522, -1, 100, - 591, 381, 192, 275, 152, 590, 592, 521, 595, 522, - -1, 100, 295, 356, 591, 381, 590, 592, 521, 595, - 522, -1, -1, 553, -1, -1, 427, -1, 315, -1, - -1, 199, 3, -1, 842, -1, 559, 593, -1, 594, - -1, 595, 525, 594, -1, 567, 457, 157, 651, -1, - 151, 941, 600, -1, 100, 662, 421, 1022, 40, 151, - 941, 600, 1021, -1, 100, 662, 421, 192, 275, 152, - 1022, 40, 151, 941, 600, 1021, -1, 842, -1, 951, - 13, 842, -1, 598, -1, 599, 525, 598, -1, 521, - 599, 522, -1, -1, 32, 385, 552, 602, -1, 32, - 385, 192, 152, 552, 602, -1, 605, -1, 602, 605, - -1, 483, -1, 507, -1, -1, 4, -1, 512, 4, - -1, 513, 4, -1, 607, -1, 40, 809, -1, 60, - 604, -1, 106, -1, 273, 106, -1, 202, 606, 604, - -1, 251, 604, -1, 261, 604, -1, 273, 251, -1, - 273, 261, -1, 305, 59, 948, -1, 385, 266, 948, - -1, 405, 603, 604, -1, 360, -1, 360, 603, 604, - -1, 59, -1, -1, 944, -1, 512, 944, -1, 513, - 944, -1, 137, 591, 381, 553, 609, -1, 137, 591, - 381, 192, 152, 553, 609, -1, -1, 172, 3, -1, - 22, 611, -1, 52, 611, 612, -1, 405, 611, 612, - -1, 86, 611, -1, 143, 611, -1, 367, 611, -1, - 486, -1, 435, -1, -1, 342, 291, -1, 342, 488, - -1, -1, 458, 552, -1, 100, 662, 421, 552, 521, - 649, 522, 636, 628, -1, 100, 662, 421, 192, 275, - 152, 552, 521, 649, 522, 636, 628, -1, 100, 295, - 356, 662, 421, 552, 521, 649, 522, 636, 628, -1, - -1, 615, 640, -1, 657, -1, 1029, -1, 885, -1, - 604, -1, 555, -1, 274, -1, 521, 602, 522, -1, - -1, 555, -1, 273, 25, -1, 361, -1, 63, -1, - 390, 280, -1, 390, 117, -1, 93, 941, 621, -1, - 621, -1, 635, -1, 80, 948, -1, 275, 280, -1, - 280, -1, 450, 648, -1, 330, 227, 648, -1, 74, - 521, 842, 522, 630, -1, 460, 88, 941, -1, 117, - 843, -1, 348, 552, 651, 660, 627, -1, 475, -1, - 411, -1, 622, -1, -1, 176, 663, 40, 191, 617, - -1, 176, 663, 40, 521, 842, 522, 623, -1, 40, - 521, 842, 522, 623, -1, 639, 618, -1, 290, 457, - 619, -1, 626, -1, 653, -1, 626, 653, -1, 653, - 626, -1, -1, 290, 86, 137, -1, 290, 86, 122, - 370, -1, 290, 86, 329, 370, -1, -1, 521, 633, - 522, -1, 273, 205, -1, -1, 93, 941, 658, -1, - 658, -1, 85, -1, 94, -1, 118, -1, 191, -1, - 204, -1, 407, -1, 410, -1, 30, -1, 654, -1, - 633, 525, 654, -1, 460, 203, 645, -1, 119, -1, - 275, 119, -1, 207, 120, -1, 207, 195, -1, 483, - 629, -1, 483, 288, -1, 485, 288, -1, -1, 521, - 644, 522, -1, 638, 201, 632, -1, 638, 149, 632, - -1, -1, 559, -1, 275, 119, -1, 119, -1, 207, - 195, -1, 207, 120, -1, 275, 462, -1, 273, 205, - -1, 806, 652, -1, 805, 624, 652, -1, 553, 641, - -1, 553, 642, -1, 647, -1, 644, 525, 647, -1, - 553, -1, 643, -1, 661, -1, 631, -1, 559, 510, - 616, -1, 559, -1, 483, 637, -1, -1, 659, -1, - 659, 525, -1, -1, 553, -1, 521, 655, 522, -1, - -1, 652, 620, -1, -1, 290, 122, 619, -1, 559, - 510, 616, -1, 559, -1, 559, 523, 559, 510, 616, - -1, 559, 523, 559, -1, 650, -1, 655, 525, 650, - -1, 655, -1, 655, 525, -1, 806, -1, 945, 949, - 516, 444, -1, 391, 945, 949, 516, 444, -1, 74, - 521, 842, 522, 615, -1, 450, 521, 656, 522, 648, - 615, -1, 450, 634, 615, -1, 330, 227, 521, 656, - 522, 648, 615, -1, 330, 227, 634, 615, -1, 169, - 227, 521, 656, 522, 348, 552, 651, 660, 627, 615, - -1, 646, -1, 659, 525, 646, -1, 249, 173, -1, - 249, 309, -1, 249, 396, -1, -1, 237, 552, 638, - -1, 427, -1, 425, -1, 241, 427, -1, 241, 425, - -1, 178, 427, -1, 178, 425, -1, 453, -1, -1, - 33, -1, 59, 117, -1, 137, 665, 192, 152, 667, - 668, -1, 137, 665, 667, 668, -1, 137, 666, 192, - 152, 938, 668, -1, 137, 666, 938, 668, -1, 137, - 669, 941, 290, 948, 668, -1, 137, 669, 192, 152, - 941, 290, 948, 668, -1, 421, -1, 385, -1, 174, - -1, 246, -1, 246, 421, -1, 473, -1, 250, 473, - -1, 203, -1, 169, 421, -1, 81, -1, 97, -1, - 374, -1, 407, -1, 428, 378, 308, -1, 428, 378, - 129, -1, 428, 378, 426, -1, 428, 378, 90, -1, - 444, -1, 24, 252, -1, 146, 438, -1, 156, -1, - 169, 107, 487, -1, 336, -1, 388, -1, 948, -1, - 667, 525, 948, -1, 63, -1, 361, -1, -1, 321, - -1, 371, -1, 438, -1, 100, 662, 677, 552, 674, - -1, 100, 662, 677, 192, 275, 152, 552, 674, -1, - 100, 295, 356, 662, 677, 552, 674, -1, 100, 662, - 677, 552, 676, -1, 100, 662, 677, 192, 275, 152, - 552, 676, -1, 100, 295, 356, 662, 677, 552, 676, - -1, 678, 40, 421, 700, -1, 678, 40, 421, 699, - -1, 672, -1, 673, 525, 672, -1, 671, -1, 673, - -1, 678, 40, 842, -1, 675, -1, 676, 525, 675, - -1, 174, -1, 246, -1, 521, 522, -1, 521, 893, - 522, -1, 567, 457, 1001, 390, 580, 772, 1002, 573, - -1, 98, 693, 552, 651, 691, 682, 687, 696, 683, - 603, 688, -1, 98, 521, 698, 522, 433, 687, 696, - 603, 688, -1, 98, 172, 108, 553, 433, 553, 681, - -1, -1, 521, 374, 522, -1, 521, 107, 522, -1, - 172, -1, 433, -1, 685, 124, 555, -1, -1, 695, - -1, 684, 525, 695, -1, 460, -1, -1, 40, -1, - -1, 335, -1, -1, 692, -1, 521, 697, 522, -1, - 982, -1, 604, -1, 849, -1, 514, -1, 521, 684, - 522, -1, 850, -1, 851, -1, -1, 559, 689, -1, - 483, 288, -1, -1, 692, 694, -1, -1, 55, -1, - -1, 55, -1, 288, -1, 171, -1, 123, 686, 555, - -1, 280, 686, 555, -1, 102, -1, 187, -1, 340, - 686, 555, -1, 145, 686, 555, -1, 168, 340, 655, - -1, 168, 340, 514, -1, 310, 59, 655, -1, 310, - 59, 514, -1, 168, 275, 280, 655, -1, 168, 280, - 655, -1, 141, 555, -1, 982, -1, 555, -1, 408, - -1, 409, -1, 3, 523, 553, -1, 3, -1, 690, - -1, 697, 525, 690, -1, 700, -1, 699, -1, 521, - 700, 522, -1, 521, 699, 522, -1, 521, 1012, 522, - -1, 703, -1, 701, 726, -1, 701, 725, 763, 732, - -1, 701, 725, 731, 764, -1, 710, 701, -1, 710, - 701, 726, -1, 710, 701, 725, 763, 732, -1, 710, - 701, 725, 731, 764, -1, 703, -1, 699, -1, 383, - 723, 920, -1, -1, 383, 723, 920, 717, 772, 799, - 752, 761, 861, 762, 737, -1, 383, 722, 922, 717, - 772, 799, 752, 761, 861, 762, 737, -1, 172, 773, - 702, 717, 799, 752, 761, 861, 762, 737, -1, 172, - 773, 383, 722, 922, 717, 799, 752, 761, 861, 762, - 737, -1, 771, -1, 421, 793, -1, 701, 449, 720, - 721, 701, -1, 701, 449, 720, 701, -1, 701, 218, - 720, 701, -1, 701, 147, 720, 701, -1, 705, 776, - 460, 922, -1, 705, 776, 460, 922, 181, 59, 940, - -1, 705, 776, 181, 59, 940, -1, 705, 776, 290, - 709, -1, 705, 776, 290, 709, 181, 59, 940, -1, - 705, 776, 290, 709, 460, 922, -1, 705, 776, 290, - 709, 460, 922, 181, 59, 940, -1, 706, 776, 290, - 922, 220, 266, 941, 704, 940, -1, 706, 776, 290, - 922, -1, 465, -1, 466, -1, 316, -1, 318, -1, - 455, -1, 317, -1, 843, -1, 843, 199, 521, 700, - 522, -1, 779, -1, 707, -1, 708, 525, 707, -1, - 708, -1, 708, 525, -1, 483, 711, -1, 507, 711, - -1, 483, 346, 711, -1, 712, -1, 711, 525, 712, - -1, 941, 950, 713, 40, 716, 521, 955, 522, -1, - 460, 227, 521, 714, 522, -1, -1, 715, -1, 715, - 525, -1, 912, -1, 715, 525, 912, -1, 250, -1, - 275, 250, -1, -1, 220, 718, -1, -1, 427, 719, - 552, -1, 425, 719, 552, -1, 241, 427, 719, 552, - -1, 241, 425, 719, 552, -1, 178, 427, 719, 552, - -1, 178, 425, 719, 552, -1, 453, 719, 552, -1, - 421, 552, -1, 552, -1, 421, -1, -1, 30, -1, - 132, -1, -1, 59, 266, -1, 132, -1, 132, 290, - 521, 891, 522, -1, 30, -1, -1, 193, 282, -1, - 359, 282, -1, -1, 726, -1, -1, 296, 59, 727, - -1, 296, 59, 30, 729, 730, -1, 728, -1, 727, - 525, 728, -1, 842, 460, 885, 730, -1, 842, 729, - 730, -1, 41, -1, 126, -1, -1, 506, 164, -1, - 506, 231, -1, -1, 733, 734, -1, 734, 733, -1, - 733, -1, 734, -1, 731, -1, -1, 238, 746, -1, - 238, 746, 525, 747, -1, 162, 751, 748, 750, 291, - -1, 162, 751, 750, 291, -1, 287, 747, -1, 287, - 748, 750, -1, 4, -1, 9, -1, 847, -1, 735, - 516, -1, 735, 314, -1, 735, -1, 735, 370, -1, - 460, 372, 739, -1, -1, 553, -1, -1, 738, 521, - 736, 522, 742, -1, 736, -1, 736, 521, 553, 522, - -1, 736, 521, 553, 525, 9, 522, -1, 423, 739, - -1, 740, -1, -1, 355, 521, 9, 522, -1, -1, - 432, -1, 472, -1, 743, 14, 842, -1, 46, 521, - 744, 522, -1, -1, 842, -1, 30, -1, 842, 516, - -1, 4, 314, -1, 9, 314, -1, 842, -1, 844, - -1, 512, 749, -1, 513, 749, -1, 944, -1, 4, - -1, 369, -1, 370, -1, 164, -1, 272, -1, 181, - 59, 754, -1, 181, 59, 30, -1, -1, 755, -1, - 753, 525, 755, -1, 753, -1, 753, 525, -1, 842, - -1, 756, -1, 758, -1, 757, -1, 759, -1, 521, - 522, -1, 368, 521, 891, 522, -1, 103, 521, 891, - 522, -1, 182, 392, 521, 754, 522, -1, 182, -1, - 183, -1, 186, 842, -1, -1, 337, 842, -1, -1, - 765, -1, 167, 342, 291, -1, 763, -1, -1, 766, - -1, 765, 766, -1, 767, 768, 769, -1, 167, 457, - -1, 167, 273, 227, 457, -1, 167, 393, -1, 167, - 227, 393, -1, 285, 937, -1, -1, 279, -1, 397, - 244, -1, -1, 466, 521, 891, 522, -1, 770, 525, - 521, 891, 522, -1, 770, -1, 770, 525, -1, 172, - 774, -1, -1, 776, -1, 773, 525, 776, -1, 773, - -1, 773, 525, -1, 554, 526, -1, 793, 788, 745, - 741, -1, 775, 793, 745, 741, -1, 794, 789, 741, - -1, 775, 794, 741, -1, 771, 787, 741, -1, 232, - 794, 789, -1, 699, 788, 741, -1, 775, 699, 741, - -1, 232, 699, 788, -1, 786, -1, 521, 786, 522, - 787, -1, 775, 521, 786, 522, -1, 776, 316, 521, - 922, 167, 782, 777, 522, 788, -1, 776, 455, 778, - 521, 783, 167, 785, 522, 788, -1, 181, 59, 939, - -1, -1, 200, 282, -1, 148, 282, -1, -1, 843, - 199, 521, 922, 522, -1, 843, 199, 554, -1, 845, - -1, 848, -1, 521, 889, 522, -1, 780, 199, 521, - 922, 522, -1, 780, 199, 554, -1, 781, -1, 782, - 781, -1, 554, -1, 521, 939, 522, -1, 783, 199, - 521, 922, 522, -1, 784, -1, 785, 784, -1, 521, - 786, 522, -1, 776, 101, 225, 776, -1, 776, 790, - 225, 776, 792, -1, 776, 225, 776, 792, -1, 776, - 269, 790, 225, 776, -1, 776, 269, 225, 776, -1, - 776, 42, 790, 225, 776, 792, -1, 776, 42, 225, - 776, 792, -1, 776, 323, 225, 776, -1, 776, 37, - 225, 776, 792, -1, 776, 384, 225, 776, 792, -1, - 40, 554, 521, 939, 522, -1, 40, 554, -1, 553, - 521, 939, 522, -1, 553, -1, 787, -1, -1, 787, - -1, 40, 521, 800, 522, -1, 40, 554, 521, 800, - 522, -1, 553, 521, 800, 522, -1, -1, 173, 791, - -1, 235, 791, -1, 365, 791, -1, 384, -1, 37, - -1, 209, -1, 300, -1, -1, 460, 521, 939, 522, - -1, 290, 842, -1, 552, -1, 552, 514, -1, 291, - 552, -1, 291, 521, 552, 522, -1, 854, 798, -1, - 370, 172, 521, 796, 522, 798, -1, 854, 797, -1, - 795, -1, 796, 525, 795, -1, 40, 521, 800, 522, - -1, -1, 507, 297, -1, -1, 480, 842, -1, -1, - 801, -1, 800, 525, 801, -1, 554, 806, 802, -1, - 80, 948, -1, -1, 553, 806, -1, 803, 525, 553, - 806, -1, 369, -1, 414, -1, 806, -1, -1, 809, - 808, -1, 391, 809, 808, -1, 809, 39, 519, 944, - 520, -1, 391, 809, 39, 519, 944, 520, -1, 809, - 39, -1, 391, 809, 39, -1, 807, -1, 804, 521, - 803, 522, 808, -1, 247, 521, 895, 522, 808, -1, - 449, 521, 803, 522, 808, -1, 3, 523, 3, -1, - 807, 523, 3, -1, 808, 519, 520, -1, 808, 519, - 944, 520, -1, -1, 811, -1, 813, -1, 815, -1, - 819, -1, 825, -1, 826, 841, -1, 826, 521, 944, - 522, -1, 813, -1, 816, -1, 820, -1, 825, -1, - 947, 812, -1, 521, 892, 522, -1, -1, 216, -1, - 217, -1, 398, -1, 54, -1, 343, -1, 165, 814, - -1, 136, 326, -1, 115, 812, -1, 112, 812, -1, - 283, 812, -1, 57, -1, 521, 944, 522, -1, -1, - 817, -1, 818, -1, 817, -1, 818, -1, 56, 824, - 521, 891, 522, -1, 56, 824, -1, 821, -1, 822, - -1, 821, -1, 822, -1, 823, 521, 944, 522, -1, - 823, -1, 72, 824, -1, 71, 824, -1, 467, -1, - 268, 72, 824, -1, 268, 71, 824, -1, 270, 824, - -1, 470, -1, -1, 432, 521, 944, 522, 827, -1, - 432, 827, -1, 431, 521, 944, 522, 827, -1, 431, - 827, -1, 219, -1, 507, 431, 504, -1, 485, 431, - 504, -1, -1, 501, -1, 502, -1, 263, -1, 264, - -1, 109, -1, 110, -1, 189, -1, 190, -1, 259, - -1, 260, -1, 379, -1, 380, -1, 257, -1, 258, - -1, 253, -1, 254, -1, 477, -1, 478, -1, 338, - -1, 339, -1, 113, -1, 114, -1, 69, -1, 68, - -1, 256, -1, 255, -1, 828, -1, 829, -1, 830, - -1, 831, -1, 832, -1, 833, -1, 834, -1, 835, - -1, 836, -1, 837, -1, 838, -1, 839, -1, 840, - -1, 828, 433, 829, -1, 830, 433, 831, -1, 830, - 433, 832, -1, 830, 433, 833, -1, 831, 433, 832, - -1, 831, 433, 833, -1, 832, 433, 833, -1, -1, - 844, -1, 842, 11, 806, -1, 842, 80, 948, -1, - 842, 46, 431, 504, 842, -1, 512, 842, -1, 513, - 842, -1, 842, 512, 842, -1, 842, 513, 842, -1, - 842, 514, 842, -1, 842, 515, 842, -1, 842, 15, - 842, -1, 842, 516, 842, -1, 842, 517, 842, -1, - 842, 16, 842, -1, 842, 508, 842, -1, 842, 509, - 842, -1, 842, 510, 842, -1, 842, 19, 842, -1, - 842, 20, 842, -1, 842, 21, 842, -1, 842, 884, - 842, -1, 884, 842, -1, 842, 884, -1, 842, 36, - 842, -1, 842, 295, 842, -1, 275, 842, -1, 505, - 842, -1, 842, 177, 842, -1, 842, 237, 842, -1, - 842, 237, 842, 145, 842, -1, 842, 505, 237, 842, - -1, 842, 505, 237, 842, 145, 842, -1, 842, 194, - 842, -1, 842, 194, 842, 145, 842, -1, 842, 505, - 194, 842, -1, 842, 505, 194, 842, 145, 842, -1, - 842, 395, 433, 842, -1, 842, 395, 433, 842, 145, - 842, -1, 842, 505, 395, 433, 842, -1, 842, 505, - 395, 433, 842, 145, 842, -1, 842, 222, 280, -1, - 842, 223, -1, 842, 222, 275, 280, -1, 842, 275, - 280, -1, 842, 278, -1, 842, 17, 842, -1, 842, - 18, 842, -1, 873, 302, 873, -1, 842, 222, 440, - -1, 842, 222, 275, 440, -1, 842, 222, 160, -1, - 842, 222, 275, 160, -1, 842, 222, 451, -1, 842, - 222, 275, 451, -1, 842, 222, 132, 172, 842, -1, - 842, 222, 275, 132, 172, 842, -1, 842, 222, 285, - 521, 895, 522, -1, 842, 222, 275, 285, 521, 895, - 522, -1, 842, 53, 919, 843, 36, 842, -1, 842, - 505, 53, 919, 843, 36, 842, -1, 842, 53, 418, - 843, 36, 842, -1, 842, 505, 53, 418, 843, 36, - 842, -1, 842, 199, 905, -1, 842, 505, 199, 905, - -1, 842, 886, 881, 699, -1, 842, 886, 881, 521, - 842, 522, -1, 117, -1, 83, 521, 842, 522, -1, - 454, 521, 842, 522, -1, 514, 83, 521, 842, 522, - -1, 514, 928, 932, 936, -1, 553, 523, 514, 928, - 932, 936, -1, 844, -1, 843, 11, 806, -1, 512, - 843, -1, 513, 843, -1, 843, 512, 843, -1, 843, - 513, 843, -1, 843, 514, 843, -1, 843, 515, 843, - -1, 843, 15, 843, -1, 843, 516, 843, -1, 843, - 517, 843, -1, 843, 16, 843, -1, 843, 508, 843, - -1, 843, 509, 843, -1, 843, 510, 843, -1, 843, - 19, 843, -1, 843, 20, 843, -1, 843, 21, 843, - -1, 843, 884, 843, -1, 884, 843, -1, 843, 884, - -1, 843, 222, 132, 172, 843, -1, 843, 222, 275, - 132, 172, 843, -1, 843, 222, 285, 521, 895, 522, - -1, 843, 222, 275, 285, 521, 895, 522, -1, 845, - -1, 846, 918, -1, 913, -1, 943, -1, 699, -1, - 699, 556, -1, 152, 699, -1, 760, 521, 891, 522, - -1, 521, 842, 522, -1, 848, -1, 873, -1, 527, - -1, 10, -1, 528, 559, -1, 847, -1, 850, -1, - 851, -1, 853, -1, 906, -1, 849, -1, 857, -1, - 39, 699, -1, 39, 519, 892, 520, -1, 529, 9, - -1, 519, 892, 520, -1, 530, 876, 531, -1, 247, - 530, 880, 531, -1, 942, 521, 522, -1, 942, 521, - 726, 724, 522, -1, 942, 521, 893, 725, 724, 522, - -1, 942, 521, 469, 894, 725, 724, 522, -1, 942, - 521, 893, 525, 469, 894, 725, 724, 522, -1, 942, - 521, 30, 893, 725, 724, 522, -1, 942, 521, 132, - 893, 725, 724, 522, -1, 852, 858, 859, 860, 864, - -1, 855, -1, 852, -1, 855, -1, 81, 167, 521, - 842, 522, -1, 66, 521, 842, 40, 806, 522, -1, - 443, 521, 842, 40, 806, 522, -1, 159, 521, 896, - 522, -1, 303, 521, 898, 522, -1, 322, 521, 900, - 522, -1, 416, 521, 901, 522, -1, 437, 521, 842, - 40, 806, 522, -1, 439, 521, 58, 904, 522, -1, - 439, 521, 233, 904, 522, -1, 439, 521, 434, 904, - 522, -1, 439, 521, 904, 522, -1, 281, 521, 842, - 525, 842, 522, -1, 79, 521, 891, 522, -1, 911, - -1, 519, 842, 167, 856, 199, 842, 520, -1, 519, - 842, 167, 856, 199, 844, 192, 842, 520, -1, 484, - 181, 521, 726, 522, -1, -1, 163, 521, 480, 842, - 522, -1, 163, 521, 842, 522, -1, -1, 155, -1, - -1, 482, 862, -1, -1, 863, -1, 862, 525, 863, - -1, 553, 40, 865, -1, 301, 865, -1, 301, 553, - -1, -1, 521, 866, 867, 725, 868, 522, -1, 553, - -1, -1, 310, 59, 890, -1, -1, 341, 869, 871, - -1, 370, 869, 871, -1, 184, 869, 871, -1, -1, - 870, -1, 53, 870, 36, 870, -1, 446, 325, -1, - 446, 166, -1, 104, 369, -1, 842, 325, -1, 842, - 166, -1, 148, 104, 369, -1, 148, 181, -1, 148, - 430, -1, 148, 273, 298, -1, -1, 369, 521, 891, - 522, -1, 369, 521, 522, -1, 872, -1, 521, 890, - 525, 842, 522, -1, 554, 526, 842, -1, 874, -1, - 875, 525, 874, -1, 875, -1, 875, 525, -1, 842, - 526, 842, -1, 877, -1, 878, 525, 877, -1, 878, - -1, 878, 525, -1, 879, -1, -1, 38, -1, 400, - -1, 30, -1, 8, -1, 883, -1, 512, -1, 513, - -1, 514, -1, 515, -1, 15, -1, 516, -1, 517, - -1, 16, -1, 508, -1, 509, -1, 510, -1, 19, - -1, 20, -1, 21, -1, 8, -1, 292, 521, 887, - 522, -1, 882, -1, 292, 521, 887, 522, -1, 882, - -1, 292, 521, 887, 522, -1, 237, -1, 505, 237, - -1, 177, -1, 505, 177, -1, 194, -1, 505, 194, - -1, 882, -1, 553, 523, 887, -1, 844, -1, 888, - 525, 844, -1, 888, -1, 888, 525, -1, 842, -1, - 890, 525, 842, -1, 890, -1, 890, 525, -1, 891, - -1, -1, 894, -1, 893, 525, 894, -1, 842, -1, - 951, 13, 842, -1, 951, 14, 842, -1, 806, -1, - 895, 525, 806, -1, 897, 172, 842, -1, -1, 3, - -1, 828, -1, 829, -1, 830, -1, 831, -1, 832, - -1, 833, -1, 834, -1, 835, -1, 836, -1, 837, - -1, 838, -1, 839, -1, 840, -1, 555, -1, 842, - 899, 902, 903, -1, 842, 899, 902, -1, 319, 842, - -1, 843, 199, 843, -1, -1, 842, 902, 903, -1, - 842, 903, 902, -1, 842, 902, -1, 842, 903, -1, - 890, -1, -1, 172, 842, -1, 167, 842, -1, 842, - 172, 891, -1, 172, 891, -1, 891, -1, 699, -1, - 521, 891, 522, -1, 913, -1, 848, -1, 65, 910, - 907, 909, 143, -1, 908, -1, 907, 908, -1, 479, - 842, 429, 842, -1, 139, 842, -1, -1, 842, -1, - -1, 912, -1, 911, 525, 912, -1, 553, -1, 553, - -1, 553, 556, -1, 519, 842, 520, -1, 519, 914, - 526, 914, 520, -1, 519, 914, 526, 914, 526, 914, - 520, -1, 519, 914, 526, 513, 526, 914, 520, -1, - 842, -1, -1, -1, 915, 557, -1, -1, 521, 522, - -1, 521, 893, 522, -1, 523, 558, 916, -1, 519, - 842, 520, -1, 519, 914, 526, 914, 520, -1, 519, - 914, 526, 914, 526, 914, 520, -1, 519, 914, 526, - 513, 526, 914, 520, -1, -1, 918, 917, -1, 45, - -1, -1, 922, -1, -1, 923, -1, 921, 525, 923, - -1, 921, -1, 921, 525, -1, 842, 40, 952, -1, - 842, 3, -1, 842, -1, 553, 526, 842, -1, 148, - 521, 927, 522, -1, 148, 925, -1, 554, -1, 925, - 523, 554, -1, 925, -1, 926, 525, 925, -1, 926, - -1, 926, 525, -1, 924, -1, -1, 842, 40, 553, - -1, 929, -1, 930, 525, 929, -1, 930, -1, 930, - 525, -1, 356, 521, 931, 522, -1, 356, 929, -1, - -1, 925, 40, 553, -1, 933, -1, 934, 525, 933, - -1, 934, -1, 934, 525, -1, 354, 521, 935, 522, - -1, 354, 933, -1, -1, 552, -1, 937, 525, 552, - -1, 941, -1, 938, 525, 941, -1, 938, -1, 938, - 525, -1, 939, -1, 521, 939, 522, -1, 554, -1, - 946, -1, 553, 556, -1, 944, -1, 4, -1, 555, - 915, -1, 6, -1, 7, -1, 942, 555, -1, 942, - 521, 893, 725, 724, 522, 555, -1, 810, 555, -1, - 826, 521, 842, 522, 841, -1, 826, 944, 841, -1, - 826, 555, 841, -1, 440, -1, 160, -1, 280, -1, - 9, -1, 3, -1, 1023, -1, 1028, -1, 3, -1, - 1023, -1, 1025, -1, 3, -1, 1023, -1, 1026, -1, - 553, -1, 553, 949, -1, 523, 558, -1, 949, 523, - 558, -1, 521, 939, 522, -1, -1, 945, -1, 559, - -1, 5, -1, 327, 941, 954, 40, 955, -1, 521, - 895, 522, -1, -1, 698, -1, 562, -1, 679, -1, - 680, -1, 1000, -1, 1012, -1, 100, 374, 552, 957, - -1, 100, 374, 192, 275, 152, 552, 957, -1, 100, - 295, 356, 374, 552, 957, -1, 957, 958, -1, -1, - 614, -1, 959, -1, 587, -1, 1018, -1, 100, 965, - 203, 962, 963, 290, 552, 961, 521, 581, 522, 964, - 799, -1, 100, 965, 203, 962, 192, 275, 152, 645, - 290, 552, 961, 521, 581, 522, 964, 799, -1, 553, - -1, 460, 960, -1, -1, 89, -1, -1, 645, -1, - -1, 483, 629, -1, -1, 450, -1, -1, 32, 421, - 793, 390, 374, 941, -1, 32, 421, 192, 152, 793, - 390, 374, 941, -1, 32, 385, 552, 390, 374, 941, - -1, 32, 385, 192, 152, 552, 390, 374, 941, -1, - 32, 473, 552, 390, 374, 941, -1, 32, 473, 192, - 152, 552, 390, 374, 941, -1, 168, 75, 968, -1, - 75, 968, -1, 553, -1, -1, 84, 290, 971, 552, - 222, 970, -1, 84, 290, 82, 842, 222, 970, -1, - 555, -1, 280, -1, 421, -1, 385, -1, 174, -1, - 246, -1, 246, 421, -1, 473, -1, 108, -1, 203, - -1, 374, -1, 444, -1, 154, 108, 555, 688, -1, - 154, 108, 553, 433, 555, 688, -1, 198, 108, 555, - -1, 153, 977, -1, 153, 981, 975, 977, -1, 153, - 471, 977, -1, 153, 521, 980, 522, 977, -1, 471, - -1, -1, 982, -1, 604, -1, -1, 966, -1, 601, - -1, 536, -1, 1017, -1, 967, -1, 680, -1, 1020, - -1, 670, -1, 956, -1, 587, -1, 614, -1, 583, - -1, 551, -1, 1000, -1, 664, -1, 597, -1, 959, - -1, 562, -1, 991, -1, 586, -1, 953, -1, 560, - -1, 698, -1, 610, -1, 679, -1, 596, -1, 995, - -1, 1009, -1, 985, -1, 1012, -1, 1018, -1, 3, - -1, 1023, -1, 1027, -1, 978, -1, 555, -1, 983, - -1, 980, 525, 983, -1, 35, -1, 34, -1, 440, - -1, 160, -1, 290, -1, 979, -1, 984, 976, -1, - 978, -1, 981, -1, 390, 986, -1, 390, 241, 986, - -1, 390, 389, 986, -1, 390, 178, 986, -1, 390, - 468, 986, -1, 987, -1, 1016, 172, 104, -1, 431, - 504, 989, -1, 374, 555, -1, 1016, 433, 990, -1, - 1016, 510, 990, -1, 842, -1, 555, -1, 3, -1, - 826, 555, 841, -1, 826, 521, 944, 522, 555, -1, - 604, -1, 117, -1, 241, -1, 988, -1, 990, 525, - 988, -1, 240, 993, -1, 992, 214, 993, 994, -1, - 992, 214, 993, 172, 553, 994, -1, 992, 214, 993, - 172, 555, 994, -1, -1, 168, -1, 555, -1, 553, - -1, -1, 472, 555, -1, 472, 553, -1, 461, 997, - 999, 975, -1, 461, 997, 999, 975, 552, 950, -1, - 461, 997, 999, 975, 1004, -1, 461, 521, 998, 522, - -1, 461, 521, 998, 522, 552, 950, -1, 981, -1, - 471, -1, 171, -1, 173, -1, 3, -1, 173, -1, - -1, 996, -1, 998, 525, 996, -1, 171, -1, -1, - 567, 122, 172, 1001, 1003, 1002, 573, -1, 441, 719, - 1001, -1, 793, -1, 793, 553, -1, 793, 40, 553, - -1, 480, 842, -1, -1, 460, 774, -1, -1, 981, - 975, -1, 981, 975, 552, 950, -1, 47, 1007, 555, - 1008, 688, -1, 47, 192, 275, 152, 1007, 555, 1008, - 688, -1, 47, 295, 356, 1007, 555, 1008, 688, -1, - 128, 559, -1, 128, 108, 559, -1, 128, 108, 192, - 152, 559, -1, 108, -1, -1, 40, 553, -1, -1, - 358, 1011, -1, 358, 241, 1011, -1, 358, 389, 1011, - -1, 358, 178, 1011, -1, 358, 468, 1011, -1, 1016, - -1, 30, -1, 1010, -1, 431, 504, -1, 435, 224, - 236, -1, 1014, 698, -1, 417, 698, -1, 417, 552, - -1, 1014, 552, -1, 1014, 431, 504, -1, 1014, 435, - 224, 236, -1, 1014, 30, 1015, -1, 1014, -1, 127, - -1, 126, -1, 394, -1, 1013, -1, 422, -1, -1, - 553, -1, 1016, 523, 553, -1, 61, 852, -1, 100, - 662, 473, 552, 651, 964, 40, 698, 1019, -1, 100, - 662, 473, 192, 275, 152, 552, 651, 964, 40, 698, - 1019, -1, 100, 295, 356, 662, 473, 552, 651, 964, - 40, 698, 1019, -1, 100, 662, 346, 473, 552, 521, - 655, 522, 964, 40, 698, 1019, -1, 100, 295, 356, - 662, 346, 473, 552, 521, 655, 522, 964, 40, 698, - 1019, -1, 483, 74, 293, -1, 483, 64, 74, 293, - -1, 483, 241, 74, 293, -1, -1, 100, 662, 421, - 1022, 40, 698, 1021, -1, 100, 662, 421, 192, 275, - 152, 1022, 40, 698, 1021, -1, 100, 295, 356, 662, - 421, 1022, 40, 698, 1021, -1, 483, 107, -1, 483, - 273, 107, -1, -1, 552, 651, 636, 628, -1, 22, - -1, 23, -1, 24, -1, 25, -1, 26, -1, 27, - -1, 28, -1, 29, -1, 31, -1, 32, -1, 33, - -1, 43, -1, 44, -1, 47, -1, 48, -1, 50, - -1, 51, -1, 52, -1, 59, -1, 60, -1, 61, - -1, 62, -1, 63, -1, 64, -1, 67, -1, 68, - -1, 69, -1, 70, -1, 73, -1, 75, -1, 76, - -1, 77, -1, 78, -1, 84, -1, 85, -1, 86, - -1, 87, -1, 88, -1, 90, -1, 91, -1, 92, - -1, 94, -1, 95, -1, 96, -1, 97, -1, 98, - -1, 99, -1, 102, -1, 103, -1, 104, -1, 105, - -1, 106, -1, 107, -1, 108, -1, 109, -1, 110, - -1, 111, -1, 113, -1, 114, -1, 116, -1, 118, - -1, 120, -1, 121, -1, 122, -1, 123, -1, 124, - -1, 125, -1, 128, -1, 129, -1, 130, -1, 131, - -1, 134, -1, 135, -1, 136, -1, 137, -1, 138, - -1, 140, -1, 141, -1, 142, -1, 144, -1, 145, - -1, 146, -1, 148, -1, 149, -1, 150, -1, 151, - -1, 153, -1, 154, -1, 155, -1, 156, -1, 157, - -1, 158, -1, 161, -1, 163, -1, 164, -1, 166, - -1, 168, -1, 170, -1, 174, -1, 175, -1, 178, - -1, 179, -1, 180, -1, 184, -1, 185, -1, 187, - -1, 188, -1, 189, -1, 190, -1, 191, -1, 192, - -1, 193, -1, 195, -1, 196, -1, 197, -1, 198, - -1, 200, -1, 201, -1, 202, -1, 203, -1, 204, - -1, 205, -1, 206, -1, 208, -1, 211, -1, 212, - -1, 213, -1, 214, -1, 215, -1, 221, -1, 224, - -1, 226, -1, 227, -1, 228, -1, 229, -1, 230, - -1, 231, -1, 234, -1, 236, -1, 239, -1, 240, - -1, 241, -1, 242, -1, 243, -1, 244, -1, 245, - -1, 246, -1, 248, -1, 249, -1, 250, -1, 251, - -1, 252, -1, 253, -1, 254, -1, 255, -1, 256, - -1, 257, -1, 258, -1, 259, -1, 260, -1, 261, - -1, 262, -1, 263, -1, 264, -1, 265, -1, 266, - -1, 267, -1, 271, -1, 272, -1, 273, -1, 276, - -1, 277, -1, 279, -1, 282, -1, 284, -1, 285, - -1, 286, -1, 288, -1, 289, -1, 292, -1, 293, - -1, 294, -1, 297, -1, 298, -1, 301, -1, 304, - -1, 305, -1, 306, -1, 307, -1, 308, -1, 309, - -1, 310, -1, 311, -1, 312, -1, 313, -1, 314, - -1, 315, -1, 320, -1, 321, -1, 324, -1, 325, - -1, 327, -1, 328, -1, 329, -1, 331, -1, 332, - -1, 333, -1, 334, -1, 335, -1, 336, -1, 338, - -1, 339, -1, 340, -1, 341, -1, 342, -1, 344, - -1, 345, -1, 346, -1, 347, -1, 349, -1, 350, - -1, 351, -1, 352, -1, 353, -1, 354, -1, 355, - -1, 356, -1, 357, -1, 358, -1, 359, -1, 360, - -1, 361, -1, 363, -1, 364, -1, 366, -1, 367, - -1, 368, -1, 370, -1, 371, -1, 372, -1, 373, - -1, 374, -1, 375, -1, 376, -1, 377, -1, 378, - -1, 379, -1, 380, -1, 381, -1, 382, -1, 385, - -1, 386, -1, 387, -1, 388, -1, 389, -1, 390, - -1, 392, -1, 393, -1, 396, -1, 397, -1, 399, - -1, 401, -1, 402, -1, 403, -1, 404, -1, 405, - -1, 406, -1, 407, -1, 408, -1, 409, -1, 410, - -1, 411, -1, 412, -1, 413, -1, 415, -1, 419, - -1, 420, -1, 422, -1, 424, -1, 425, -1, 426, - -1, 427, -1, 428, -1, 430, -1, 435, -1, 436, - -1, 438, -1, 441, -1, 442, -1, 444, -1, 445, - -1, 446, -1, 447, -1, 448, -1, 451, -1, 452, - -1, 453, -1, 456, -1, 457, -1, 458, -1, 459, - -1, 461, -1, 462, -1, 463, -1, 464, -1, 465, - -1, 468, -1, 470, -1, 472, -1, 473, -1, 474, - -1, 475, -1, 476, -1, 477, -1, 478, -1, 481, - -1, 484, -1, 485, -1, 486, -1, 487, -1, 488, - -1, 489, -1, 501, -1, 502, -1, 503, -1, 504, - -1, 53, -1, 54, -1, 56, -1, 57, -1, 71, - -1, 72, -1, 79, -1, 83, -1, 112, -1, 115, - -1, 152, -1, 159, -1, 165, -1, 176, -1, 182, - -1, 183, -1, 210, -1, 216, -1, 217, -1, 219, - -1, 247, -1, 268, -1, 270, -1, 274, -1, 281, - -1, 283, -1, 299, -1, 303, -1, 322, -1, 326, - -1, 343, -1, 369, -1, 391, -1, 398, -1, 414, - -1, 416, -1, 431, -1, 432, -1, 437, -1, 439, - -1, 443, -1, 466, -1, 467, -1, 490, -1, 491, - -1, 492, -1, 493, -1, 494, -1, 495, -1, 496, - -1, 497, -1, 498, -1, 499, -1, 500, -1, 42, - -1, 46, -1, 49, -1, 55, -1, 81, -1, 89, + 530, 0, -1, 531, -1, 531, 521, 532, -1, 532, + -1, 948, -1, 591, -1, 533, -1, 986, -1, 987, + -1, 999, -1, 949, -1, 951, -1, 668, -1, 1002, + -1, 658, -1, 938, -1, 582, -1, 580, -1, 604, + -1, 576, -1, 544, -1, 982, -1, 988, -1, 598, + -1, 652, -1, 587, -1, 956, -1, 954, -1, 955, + -1, 941, -1, 555, -1, 973, -1, 579, -1, 935, + -1, 553, -1, 686, -1, 600, -1, 586, -1, 667, + -1, 603, -1, 977, -1, 991, -1, 967, -1, 994, + -1, 1000, -1, -1, 32, 419, 775, 541, -1, 32, + 419, 192, 152, 775, 541, -1, 32, 203, 545, 541, + -1, 32, 203, 192, 152, 545, 541, -1, 32, 384, + 545, 541, -1, 32, 384, 192, 152, 545, 541, -1, + 32, 470, 545, 541, -1, 32, 470, 192, 152, 545, + 541, -1, 536, -1, 534, 536, -1, 389, 117, 824, + -1, 137, 117, -1, 359, -1, 359, 593, 594, -1, + 389, 595, -1, 389, 176, 651, -1, 540, -1, 537, + 522, 540, -1, 26, 631, -1, 26, 192, 275, 152, + 631, -1, 26, 82, 631, -1, 26, 82, 192, 275, + 152, 631, -1, 32, 554, 546, 535, -1, 32, 554, + 546, 137, 275, 280, -1, 32, 554, 546, 389, 275, + 280, -1, 32, 554, 546, 389, 405, 597, -1, 32, + 554, 546, 389, 619, -1, 32, 554, 546, 357, 619, + -1, 32, 554, 546, 389, 408, 546, -1, 32, 554, + 546, 26, 176, 651, 40, 191, 607, -1, 32, 554, + 546, 534, -1, 32, 554, 546, 137, 191, -1, 32, + 554, 546, 137, 191, 192, 152, -1, 137, 554, 192, + 152, 546, 656, -1, 137, 554, 546, 656, -1, 32, + 554, 546, 543, 442, 787, 784, 539, -1, 32, 554, + 546, 542, -1, 26, 621, -1, 32, 93, 923, 605, + -1, 460, 93, 923, -1, 137, 93, 192, 152, 923, + 656, -1, 137, 93, 923, 656, -1, 389, 245, -1, + 389, 451, -1, 389, 619, -1, 357, 619, -1, 542, + -1, 457, 824, -1, -1, 615, -1, 389, 615, -1, + 26, 615, -1, 137, 629, -1, 538, -1, 541, 522, + 538, -1, 294, 518, 537, 519, -1, 389, 107, -1, + 389, -1, -1, 111, 923, -1, 111, 326, 923, -1, + 111, 30, -1, 111, 326, 30, -1, 547, -1, 546, + 549, -1, 3, -1, 1005, -1, 1006, -1, 546, -1, + 5, -1, 5, -1, 550, -1, 549, 550, -1, 520, + 551, -1, 552, -1, 3, -1, 1009, -1, 1005, -1, + 1011, -1, 32, 373, 923, 353, 431, 923, -1, 32, + 419, 775, 353, 431, 923, -1, 32, 419, 192, 152, + 775, 353, 431, 923, -1, 32, 384, 545, 353, 431, + 923, -1, 32, 384, 192, 152, 545, 353, 431, 923, + -1, 32, 470, 545, 353, 431, 923, -1, 32, 470, + 192, 152, 545, 353, 431, 923, -1, 32, 203, 545, + 353, 431, 923, -1, 32, 203, 192, 152, 545, 353, + 431, 923, -1, 32, 419, 775, 353, 554, 923, 431, + 923, -1, 32, 419, 192, 152, 775, 353, 554, 923, + 431, 923, -1, 32, 419, 775, 353, 93, 923, 431, + 923, -1, 32, 419, 192, 152, 775, 353, 93, 923, + 431, 923, -1, 82, -1, -1, 560, 213, 563, 220, + 557, 558, 556, 564, 566, -1, 686, -1, 304, 567, + 462, 686, -1, 518, 571, 519, 686, -1, 518, 571, + 519, 304, 567, 462, 686, -1, 117, 463, -1, 545, + -1, 545, 40, 546, -1, 59, 266, -1, 59, 321, + -1, -1, 518, 574, 519, 781, -1, 290, 93, 923, + -1, -1, 698, -1, -1, 546, 897, -1, 575, 507, + 824, -1, 518, 568, 519, 507, 824, -1, 295, 355, + -1, 295, 193, -1, -1, 290, 91, 559, 133, 454, + 389, 573, 781, -1, 290, 91, 559, 133, 276, -1, + -1, 546, 569, 570, 714, 715, -1, 836, 569, 570, + 714, 715, -1, 518, 824, 519, 569, 570, 714, 715, + -1, 361, 903, -1, -1, 456, -1, 418, -1, 575, + -1, 568, 522, 575, -1, 80, 930, -1, -1, 930, + -1, -1, 561, -1, 571, 522, 561, -1, 562, -1, + 572, 522, 562, -1, 572, -1, 572, 522, -1, 565, + -1, 574, 522, 565, -1, 546, 897, -1, 100, 442, + 545, 40, 144, 687, -1, 100, 442, 545, 40, 144, + 518, 577, 519, -1, 100, 442, 545, 40, 788, -1, + 578, -1, -1, 548, -1, 578, 522, 548, -1, 323, + 546, -1, 323, 546, 507, 972, -1, 323, 546, 518, + 875, 519, -1, 100, 650, 384, 545, 581, -1, 100, + 650, 384, 192, 275, 152, 545, 581, -1, 100, 295, + 355, 650, 384, 545, 581, -1, 592, -1, -1, 100, + 584, 380, 583, 585, 518, 685, 519, -1, 100, 584, + 380, 192, 275, 152, 583, 585, 518, 685, 519, -1, + 100, 295, 355, 584, 380, 583, 585, 518, 685, 519, + -1, -1, 546, -1, -1, 425, -1, 314, -1, -1, + 199, 3, -1, 560, 454, 157, 639, -1, 151, 923, + 590, -1, 100, 650, 419, 1004, 40, 151, 923, 590, + 1003, -1, 100, 650, 419, 192, 275, 152, 1004, 40, + 151, 923, 590, 1003, -1, 824, -1, 933, 13, 824, + -1, 588, -1, 589, 522, 588, -1, 518, 589, 519, + -1, -1, 32, 384, 545, 592, -1, 32, 384, 192, + 152, 545, 592, -1, 595, -1, 592, 595, -1, 480, + -1, 504, -1, -1, 4, -1, 509, 4, -1, 510, + 4, -1, 597, -1, 40, 791, -1, 60, 594, -1, + 106, -1, 273, 106, -1, 202, 596, 594, -1, 251, + 594, -1, 261, 594, -1, 273, 251, -1, 273, 261, + -1, 305, 59, 930, -1, 384, 266, 930, -1, 403, + 593, 594, -1, 359, -1, 359, 593, 594, -1, 59, + -1, -1, 926, -1, 509, 926, -1, 510, 926, -1, + 137, 584, 380, 546, 599, -1, 137, 584, 380, 192, + 152, 546, 599, -1, -1, 172, 3, -1, 22, 601, + -1, 52, 601, 602, -1, 403, 601, 602, -1, 86, + 601, -1, 143, 601, -1, 366, 601, -1, 483, -1, + 433, -1, -1, 341, 291, -1, 341, 485, -1, -1, + 455, 545, -1, 100, 650, 419, 545, 518, 637, 519, + 626, 618, -1, 100, 650, 419, 192, 275, 152, 545, + 518, 637, 519, 626, 618, -1, 100, 295, 355, 650, + 419, 545, 518, 637, 519, 626, 618, -1, -1, 605, + 630, -1, 645, -1, 1011, -1, 867, -1, 594, -1, + 548, -1, 274, -1, 518, 592, 519, -1, -1, 548, + -1, 273, 25, -1, 360, -1, 63, -1, 389, 280, + -1, 389, 117, -1, 93, 923, 611, -1, 611, -1, + 625, -1, 80, 930, -1, 275, 280, -1, 280, -1, + 448, 636, -1, 329, 227, 636, -1, 74, 518, 824, + 519, 620, -1, 457, 88, 923, -1, 117, 825, -1, + 347, 545, 639, 648, 617, -1, 472, -1, 409, -1, + 612, -1, -1, 176, 651, 40, 191, 607, -1, 176, + 651, 40, 518, 824, 519, 613, -1, 40, 518, 824, + 519, 613, -1, 629, 608, -1, 290, 454, 609, -1, + 616, -1, 641, -1, 616, 641, -1, 641, 616, -1, + -1, 290, 86, 137, -1, 290, 86, 122, 369, -1, + 290, 86, 328, 369, -1, -1, 518, 623, 519, -1, + 273, 205, -1, -1, 93, 923, 646, -1, 646, -1, + 85, -1, 94, -1, 118, -1, 191, -1, 204, -1, + 405, -1, 408, -1, 30, -1, 642, -1, 623, 522, + 642, -1, 457, 203, 633, -1, 119, -1, 275, 119, + -1, 207, 120, -1, 207, 195, -1, 480, 619, -1, + 480, 288, -1, 482, 288, -1, -1, 518, 632, 519, + -1, 628, 201, 622, -1, 628, 149, 622, -1, -1, + 552, -1, 275, 119, -1, 119, -1, 207, 195, -1, + 207, 120, -1, 275, 459, -1, 273, 205, -1, 546, + 788, 640, -1, 546, 787, 614, 640, -1, 635, -1, + 632, 522, 635, -1, 546, -1, 631, -1, 649, -1, + 621, -1, 552, 507, 606, -1, 552, -1, 480, 627, + -1, -1, 647, -1, 647, 522, -1, -1, 546, -1, + 518, 643, 519, -1, -1, 640, 610, -1, -1, 290, + 122, 609, -1, 552, 507, 606, -1, 552, -1, 552, + 520, 552, 507, 606, -1, 552, 520, 552, -1, 638, + -1, 643, 522, 638, -1, 643, -1, 643, 522, -1, + 788, -1, 927, 931, 513, 442, -1, 390, 927, 931, + 513, 442, -1, 74, 518, 824, 519, 605, -1, 448, + 518, 644, 519, 636, 605, -1, 448, 624, 605, -1, + 329, 227, 518, 644, 519, 636, 605, -1, 329, 227, + 624, 605, -1, 169, 227, 518, 644, 519, 347, 545, + 639, 648, 617, 605, -1, 634, -1, 647, 522, 634, + -1, 249, 173, -1, 249, 309, -1, 249, 395, -1, + -1, 237, 545, 628, -1, 425, -1, 423, -1, 241, + 425, -1, 241, 423, -1, 178, 425, -1, 178, 423, + -1, 451, -1, -1, 33, -1, 59, 117, -1, 137, + 653, 192, 152, 655, 656, -1, 137, 653, 655, 656, + -1, 137, 654, 192, 152, 920, 656, -1, 137, 654, + 920, 656, -1, 137, 657, 923, 290, 930, 656, -1, + 137, 657, 192, 152, 923, 290, 930, 656, -1, 419, + -1, 384, -1, 174, -1, 246, -1, 246, 419, -1, + 470, -1, 250, 470, -1, 203, -1, 169, 419, -1, + 81, -1, 97, -1, 373, -1, 405, -1, 426, 377, + 308, -1, 426, 377, 129, -1, 426, 377, 424, -1, + 426, 377, 90, -1, 442, -1, 24, 252, -1, 146, + 436, -1, 156, -1, 169, 107, 484, -1, 335, -1, + 387, -1, 930, -1, 655, 522, 930, -1, 63, -1, + 360, -1, -1, 320, -1, 370, -1, 436, -1, 100, + 650, 665, 545, 662, -1, 100, 650, 665, 192, 275, + 152, 545, 662, -1, 100, 295, 355, 650, 665, 545, + 662, -1, 100, 650, 665, 545, 664, -1, 100, 650, + 665, 192, 275, 152, 545, 664, -1, 100, 295, 355, + 650, 665, 545, 664, -1, 666, 40, 419, 688, -1, + 666, 40, 419, 687, -1, 660, -1, 661, 522, 660, + -1, 659, -1, 661, -1, 666, 40, 824, -1, 663, + -1, 664, 522, 663, -1, 174, -1, 246, -1, 518, + 519, -1, 518, 875, 519, -1, 560, 454, 983, 389, + 573, 754, 984, 566, -1, 98, 681, 545, 639, 679, + 670, 675, 684, 671, 593, 676, -1, 98, 518, 686, + 519, 431, 675, 684, 593, 676, -1, 98, 172, 108, + 546, 431, 546, 669, -1, -1, 518, 373, 519, -1, + 518, 107, 519, -1, 172, -1, 431, -1, 673, 124, + 548, -1, -1, 683, -1, 672, 522, 683, -1, 457, + -1, -1, 40, -1, -1, 334, -1, -1, 680, -1, + 518, 685, 519, -1, 964, -1, 594, -1, 831, -1, + 511, -1, 518, 672, 519, -1, 832, -1, 833, -1, + -1, 552, 677, -1, 480, 288, -1, -1, 680, 682, + -1, -1, 55, -1, -1, 55, -1, 288, -1, 171, + -1, 123, 674, 548, -1, 280, 674, 548, -1, 102, + -1, 187, -1, 339, 674, 548, -1, 145, 674, 548, + -1, 168, 339, 643, -1, 168, 339, 511, -1, 310, + 59, 643, -1, 310, 59, 511, -1, 168, 275, 280, + 643, -1, 168, 280, 643, -1, 141, 548, -1, 964, + -1, 548, -1, 406, -1, 407, -1, 3, 520, 546, + -1, 3, -1, 678, -1, 685, 522, 678, -1, 688, + -1, 687, -1, 518, 688, 519, -1, 518, 687, 519, + -1, 518, 994, 519, -1, 691, -1, 689, 711, -1, + 689, 710, 745, 717, -1, 689, 710, 716, 746, -1, + 698, 689, -1, 698, 689, 711, -1, 698, 689, 710, + 745, 717, -1, 698, 689, 710, 716, 746, -1, 691, + -1, 687, -1, 382, 708, 902, -1, -1, 382, 708, + 902, 702, 754, 781, 734, 743, 843, 744, 722, -1, + 382, 707, 904, 702, 754, 781, 734, 743, 843, 744, + 722, -1, 172, 755, 690, 702, 781, 734, 743, 843, + 744, 722, -1, 172, 755, 382, 707, 904, 702, 781, + 734, 743, 843, 744, 722, -1, 753, -1, 419, 775, + -1, 689, 447, 705, 706, 689, -1, 689, 447, 705, + 689, -1, 689, 218, 705, 689, -1, 689, 147, 705, + 689, -1, 693, 758, 457, 904, -1, 693, 758, 457, + 904, 181, 59, 922, -1, 693, 758, 181, 59, 922, + -1, 693, 758, 290, 697, -1, 693, 758, 290, 697, + 181, 59, 922, -1, 693, 758, 290, 697, 457, 904, + -1, 693, 758, 290, 697, 457, 904, 181, 59, 922, + -1, 694, 758, 290, 904, 220, 266, 923, 692, 922, + -1, 694, 758, 290, 904, -1, 462, -1, 463, -1, + 315, -1, 317, -1, 452, -1, 316, -1, 825, -1, + 825, 199, 518, 688, 519, -1, 761, -1, 695, -1, + 696, 522, 695, -1, 696, -1, 696, 522, -1, 480, + 699, -1, 504, 699, -1, 480, 345, 699, -1, 700, + -1, 699, 522, 700, -1, 923, 932, 40, 701, 518, + 937, 519, -1, 250, -1, 275, 250, -1, -1, 220, + 703, -1, -1, 425, 704, 545, -1, 423, 704, 545, + -1, 241, 425, 704, 545, -1, 241, 423, 704, 545, + -1, 178, 425, 704, 545, -1, 178, 423, 704, 545, + -1, 451, 704, 545, -1, 419, 545, -1, 545, -1, + 419, -1, -1, 30, -1, 132, -1, -1, 59, 266, + -1, 132, -1, 132, 290, 518, 873, 519, -1, 30, + -1, -1, 193, 282, -1, 358, 282, -1, -1, 711, + -1, -1, 296, 59, 712, -1, 296, 59, 30, 714, + 715, -1, 713, -1, 712, 522, 713, -1, 824, 457, + 867, 715, -1, 824, 714, 715, -1, 41, -1, 126, + -1, -1, 503, 164, -1, 503, 231, -1, -1, 718, + 719, -1, 719, 718, -1, 718, -1, 719, -1, 716, + -1, -1, 238, 728, -1, 238, 728, 522, 729, -1, + 162, 733, 730, 732, 291, -1, 162, 733, 732, 291, + -1, 287, 729, -1, 287, 730, 732, -1, 4, -1, + 9, -1, 829, -1, 720, 513, -1, 720, 313, -1, + 720, -1, 720, 369, -1, 457, 371, 724, -1, -1, + 546, -1, -1, 723, 518, 721, 519, 727, -1, 721, + -1, 721, 518, 546, 519, -1, 721, 518, 546, 522, + 9, 519, -1, 421, 724, -1, 725, -1, -1, 354, + 518, 9, 519, -1, -1, 824, -1, 30, -1, 824, + 513, -1, 4, 313, -1, 9, 313, -1, 824, -1, + 826, -1, 509, 731, -1, 510, 731, -1, 926, -1, + 4, -1, 368, -1, 369, -1, 164, -1, 272, -1, + 181, 59, 736, -1, 181, 59, 30, -1, -1, 737, + -1, 735, 522, 737, -1, 735, -1, 735, 522, -1, + 824, -1, 738, -1, 740, -1, 739, -1, 741, -1, + 518, 519, -1, 367, 518, 873, 519, -1, 103, 518, + 873, 519, -1, 182, 391, 518, 736, 519, -1, 182, + -1, 183, -1, 186, 824, -1, -1, 336, 824, -1, + -1, 747, -1, 167, 341, 291, -1, 745, -1, -1, + 748, -1, 747, 748, -1, 749, 750, 751, -1, 167, + 454, -1, 167, 273, 227, 454, -1, 167, 392, -1, + 167, 227, 392, -1, 285, 919, -1, -1, 279, -1, + 396, 244, -1, -1, 463, 518, 873, 519, -1, 752, + 522, 518, 873, 519, -1, 752, -1, 752, 522, -1, + 172, 756, -1, -1, 758, -1, 755, 522, 758, -1, + 755, -1, 755, 522, -1, 547, 523, -1, 775, 770, + 726, -1, 757, 775, 726, -1, 776, 771, 726, -1, + 757, 776, 726, -1, 753, 769, 726, -1, 232, 776, + 771, -1, 687, 770, 726, -1, 757, 687, 726, -1, + 232, 687, 770, -1, 768, -1, 518, 768, 519, 769, + -1, 757, 518, 768, 519, -1, 758, 315, 518, 904, + 167, 764, 759, 519, 770, -1, 758, 452, 760, 518, + 765, 167, 767, 519, 770, -1, 181, 59, 921, -1, + -1, 200, 282, -1, 148, 282, -1, -1, 825, 199, + 518, 904, 519, -1, 825, 199, 547, -1, 827, -1, + 830, -1, 518, 871, 519, -1, 762, 199, 518, 904, + 519, -1, 762, 199, 547, -1, 763, -1, 764, 763, + -1, 547, -1, 518, 921, 519, -1, 765, 199, 518, + 904, 519, -1, 766, -1, 767, 766, -1, 518, 768, + 519, -1, 758, 101, 225, 758, -1, 758, 772, 225, + 758, 774, -1, 758, 225, 758, 774, -1, 758, 269, + 772, 225, 758, -1, 758, 269, 225, 758, -1, 758, + 42, 772, 225, 758, 774, -1, 758, 42, 225, 758, + 774, -1, 758, 322, 225, 758, -1, 758, 37, 225, + 758, 774, -1, 758, 383, 225, 758, 774, -1, 40, + 547, 518, 921, 519, -1, 40, 547, -1, 546, 518, + 921, 519, -1, 546, -1, 769, -1, -1, 769, -1, + 40, 518, 782, 519, -1, 40, 547, 518, 782, 519, + -1, 546, 518, 782, 519, -1, -1, 173, 773, -1, + 235, 773, -1, 364, 773, -1, 383, -1, 37, -1, + 209, -1, 300, -1, -1, 457, 518, 921, 519, -1, + 290, 824, -1, 545, -1, 545, 511, -1, 291, 545, + -1, 291, 518, 545, 519, -1, 836, 780, -1, 369, + 172, 518, 778, 519, 780, -1, 836, 779, -1, 777, + -1, 778, 522, 777, -1, 40, 518, 782, 519, -1, + -1, 504, 297, -1, -1, 477, 824, -1, -1, 783, + -1, 782, 522, 783, -1, 547, 788, 784, -1, 80, + 930, -1, -1, 546, 788, -1, 785, 522, 546, 788, + -1, 368, -1, 412, -1, 788, -1, -1, 791, 790, + -1, 390, 791, 790, -1, 791, 39, 516, 926, 517, + -1, 390, 791, 39, 516, 926, 517, -1, 791, 39, + -1, 390, 791, 39, -1, 789, -1, 786, 518, 785, + 519, 790, -1, 247, 518, 877, 519, 790, -1, 447, + 518, 785, 519, 790, -1, 3, 520, 3, -1, 789, + 520, 3, -1, 790, 516, 517, -1, 790, 516, 926, + 517, -1, -1, 793, -1, 795, -1, 797, -1, 801, + -1, 807, -1, 808, 823, -1, 808, 518, 926, 519, + -1, 795, -1, 798, -1, 802, -1, 807, -1, 929, + 794, -1, 518, 874, 519, -1, -1, 216, -1, 217, + -1, 397, -1, 54, -1, 342, -1, 165, 796, -1, + 136, 325, -1, 115, 794, -1, 112, 794, -1, 283, + 794, -1, 57, -1, 518, 926, 519, -1, -1, 799, + -1, 800, -1, 799, -1, 800, -1, 56, 806, 518, + 873, 519, -1, 56, 806, -1, 803, -1, 804, -1, + 803, -1, 804, -1, 805, 518, 926, 519, -1, 805, + -1, 72, 806, -1, 71, 806, -1, 464, -1, 268, + 72, 806, -1, 268, 71, 806, -1, 270, 806, -1, + 467, -1, -1, 430, 518, 926, 519, 809, -1, 430, + 809, -1, 429, 518, 926, 519, 809, -1, 429, 809, + -1, 219, -1, 504, 429, 501, -1, 482, 429, 501, + -1, -1, 498, -1, 499, -1, 263, -1, 264, -1, + 109, -1, 110, -1, 189, -1, 190, -1, 259, -1, + 260, -1, 378, -1, 379, -1, 257, -1, 258, -1, + 253, -1, 254, -1, 474, -1, 475, -1, 337, -1, + 338, -1, 113, -1, 114, -1, 69, -1, 68, -1, + 256, -1, 255, -1, 810, -1, 811, -1, 812, -1, + 813, -1, 814, -1, 815, -1, 816, -1, 817, -1, + 818, -1, 819, -1, 820, -1, 821, -1, 822, -1, + 810, 431, 811, -1, 812, 431, 813, -1, 812, 431, + 814, -1, 812, 431, 815, -1, 813, 431, 814, -1, + 813, 431, 815, -1, 814, 431, 815, -1, -1, 826, + -1, 824, 11, 788, -1, 824, 80, 930, -1, 824, + 46, 429, 501, 824, -1, 509, 824, -1, 510, 824, + -1, 824, 509, 824, -1, 824, 510, 824, -1, 824, + 511, 824, -1, 824, 512, 824, -1, 824, 15, 824, + -1, 824, 513, 824, -1, 824, 514, 824, -1, 824, + 16, 824, -1, 824, 505, 824, -1, 824, 506, 824, + -1, 824, 507, 824, -1, 824, 19, 824, -1, 824, + 20, 824, -1, 824, 21, 824, -1, 824, 866, 824, + -1, 866, 824, -1, 824, 866, -1, 824, 36, 824, + -1, 824, 295, 824, -1, 275, 824, -1, 502, 824, + -1, 824, 177, 824, -1, 824, 237, 824, -1, 824, + 237, 824, 145, 824, -1, 824, 502, 237, 824, -1, + 824, 502, 237, 824, 145, 824, -1, 824, 194, 824, + -1, 824, 194, 824, 145, 824, -1, 824, 502, 194, + 824, -1, 824, 502, 194, 824, 145, 824, -1, 824, + 394, 431, 824, -1, 824, 394, 431, 824, 145, 824, + -1, 824, 502, 394, 431, 824, -1, 824, 502, 394, + 431, 824, 145, 824, -1, 824, 222, 280, -1, 824, + 223, -1, 824, 222, 275, 280, -1, 824, 275, 280, + -1, 824, 278, -1, 824, 17, 824, -1, 824, 18, + 824, -1, 855, 302, 855, -1, 824, 222, 438, -1, + 824, 222, 275, 438, -1, 824, 222, 160, -1, 824, + 222, 275, 160, -1, 824, 222, 449, -1, 824, 222, + 275, 449, -1, 824, 222, 132, 172, 824, -1, 824, + 222, 275, 132, 172, 824, -1, 824, 222, 285, 518, + 877, 519, -1, 824, 222, 275, 285, 518, 877, 519, + -1, 824, 53, 901, 825, 36, 824, -1, 824, 502, + 53, 901, 825, 36, 824, -1, 824, 53, 416, 825, + 36, 824, -1, 824, 502, 53, 416, 825, 36, 824, + -1, 824, 199, 887, -1, 824, 502, 199, 887, -1, + 824, 868, 863, 687, -1, 824, 868, 863, 518, 824, + 519, -1, 117, -1, 511, 83, 518, 824, 519, -1, + 83, 518, 824, 519, -1, 511, 910, 914, 918, -1, + 546, 520, 511, 910, 914, 918, -1, 826, -1, 825, + 11, 788, -1, 509, 825, -1, 510, 825, -1, 825, + 509, 825, -1, 825, 510, 825, -1, 825, 511, 825, + -1, 825, 512, 825, -1, 825, 15, 825, -1, 825, + 513, 825, -1, 825, 514, 825, -1, 825, 16, 825, + -1, 825, 505, 825, -1, 825, 506, 825, -1, 825, + 507, 825, -1, 825, 19, 825, -1, 825, 20, 825, + -1, 825, 21, 825, -1, 825, 866, 825, -1, 866, + 825, -1, 825, 866, -1, 825, 222, 132, 172, 825, + -1, 825, 222, 275, 132, 172, 825, -1, 825, 222, + 285, 518, 877, 519, -1, 825, 222, 275, 285, 518, + 877, 519, -1, 827, -1, 828, 900, -1, 895, -1, + 925, -1, 687, -1, 687, 549, -1, 152, 687, -1, + 742, 518, 873, 519, -1, 518, 824, 519, -1, 830, + -1, 855, -1, 524, -1, 10, -1, 525, 552, -1, + 829, -1, 832, -1, 833, -1, 835, -1, 888, -1, + 831, -1, 839, -1, 39, 687, -1, 39, 516, 874, + 517, -1, 526, 9, -1, 516, 874, 517, -1, 527, + 858, 528, -1, 247, 527, 862, 528, -1, 924, 518, + 519, -1, 924, 518, 711, 709, 519, -1, 924, 518, + 875, 710, 709, 519, -1, 924, 518, 466, 876, 710, + 709, 519, -1, 924, 518, 875, 522, 466, 876, 710, + 709, 519, -1, 924, 518, 30, 875, 710, 709, 519, + -1, 924, 518, 132, 875, 710, 709, 519, -1, 834, + 840, 841, 842, 846, -1, 837, -1, 834, -1, 837, + -1, 81, 167, 518, 824, 519, -1, 66, 518, 824, + 40, 788, 519, -1, 441, 518, 824, 40, 788, 519, + -1, 159, 518, 878, 519, -1, 303, 518, 880, 519, + -1, 321, 518, 882, 519, -1, 414, 518, 883, 519, + -1, 435, 518, 824, 40, 788, 519, -1, 437, 518, + 58, 886, 519, -1, 437, 518, 233, 886, 519, -1, + 437, 518, 432, 886, 519, -1, 437, 518, 886, 519, + -1, 281, 518, 824, 522, 824, 519, -1, 79, 518, + 873, 519, -1, 893, -1, 516, 824, 167, 838, 199, + 824, 517, -1, 516, 824, 167, 838, 199, 826, 192, + 824, 517, -1, 481, 181, 518, 711, 519, -1, -1, + 163, 518, 477, 824, 519, -1, 163, 518, 824, 519, + -1, -1, 155, -1, -1, 479, 844, -1, -1, 845, + -1, 844, 522, 845, -1, 546, 40, 847, -1, 301, + 847, -1, 301, 546, -1, -1, 518, 848, 849, 710, + 850, 519, -1, 546, -1, -1, 310, 59, 872, -1, + -1, 340, 851, 853, -1, 369, 851, 853, -1, 184, + 851, 853, -1, -1, 852, -1, 53, 852, 36, 852, + -1, 444, 324, -1, 444, 166, -1, 104, 368, -1, + 824, 324, -1, 824, 166, -1, 148, 104, 368, -1, + 148, 181, -1, 148, 428, -1, 148, 273, 298, -1, + -1, 368, 518, 873, 519, -1, 368, 518, 519, -1, + 854, -1, 518, 872, 522, 824, 519, -1, 547, 523, + 824, -1, 856, -1, 857, 522, 856, -1, 857, -1, + 857, 522, -1, 824, 523, 824, -1, 859, -1, 860, + 522, 859, -1, 860, -1, 860, 522, -1, 861, -1, + -1, 38, -1, 399, -1, 30, -1, 8, -1, 865, + -1, 509, -1, 510, -1, 511, -1, 512, -1, 15, + -1, 513, -1, 514, -1, 16, -1, 505, -1, 506, + -1, 507, -1, 19, -1, 20, -1, 21, -1, 8, + -1, 292, 518, 869, 519, -1, 864, -1, 292, 518, + 869, 519, -1, 864, -1, 292, 518, 869, 519, -1, + 237, -1, 502, 237, -1, 177, -1, 502, 177, -1, + 194, -1, 502, 194, -1, 864, -1, 546, 520, 869, + -1, 826, -1, 870, 522, 826, -1, 870, -1, 870, + 522, -1, 824, -1, 872, 522, 824, -1, 872, -1, + 872, 522, -1, 873, -1, -1, 876, -1, 875, 522, + 876, -1, 824, -1, 933, 13, 824, -1, 933, 14, + 824, -1, 788, -1, 877, 522, 788, -1, 879, 172, + 824, -1, -1, 3, -1, 810, -1, 811, -1, 812, + -1, 813, -1, 814, -1, 815, -1, 816, -1, 817, + -1, 818, -1, 819, -1, 820, -1, 821, -1, 822, + -1, 548, -1, 824, 881, 884, 885, -1, 824, 881, + 884, -1, 318, 824, -1, 825, 199, 825, -1, -1, + 824, 884, 885, -1, 824, 885, 884, -1, 824, 884, + -1, 824, 885, -1, 872, -1, -1, 172, 824, -1, + 167, 824, -1, 824, 172, 873, -1, 172, 873, -1, + 873, -1, 687, -1, 518, 873, 519, -1, 895, -1, + 830, -1, 65, 892, 889, 891, 143, -1, 890, -1, + 889, 890, -1, 476, 824, 427, 824, -1, 139, 824, + -1, -1, 824, -1, -1, 894, -1, 893, 522, 894, + -1, 546, -1, 546, -1, 546, 549, -1, 516, 824, + 517, -1, 516, 896, 523, 896, 517, -1, 516, 896, + 523, 896, 523, 896, 517, -1, 516, 896, 523, 510, + 523, 896, 517, -1, 824, -1, -1, -1, 897, 550, + -1, -1, 518, 519, -1, 518, 875, 519, -1, 520, + 551, 898, -1, 516, 824, 517, -1, 516, 896, 523, + 896, 517, -1, 516, 896, 523, 896, 523, 896, 517, + -1, 516, 896, 523, 510, 523, 896, 517, -1, -1, + 900, 899, -1, 45, -1, -1, 904, -1, -1, 905, + -1, 903, 522, 905, -1, 903, -1, 903, 522, -1, + 824, 40, 934, -1, 824, 3, -1, 824, -1, 546, + 523, 824, -1, 148, 518, 909, 519, -1, 148, 907, + -1, 547, -1, 907, 520, 547, -1, 907, -1, 908, + 522, 907, -1, 908, -1, 908, 522, -1, 906, -1, + -1, 824, 40, 546, -1, 911, -1, 912, 522, 911, + -1, 912, -1, 912, 522, -1, 355, 518, 913, 519, + -1, 355, 911, -1, -1, 907, 40, 546, -1, 915, + -1, 916, 522, 915, -1, 916, -1, 916, 522, -1, + 353, 518, 917, 519, -1, 353, 915, -1, -1, 545, + -1, 919, 522, 545, -1, 923, -1, 920, 522, 923, + -1, 920, -1, 920, 522, -1, 921, -1, 518, 921, + 519, -1, 547, -1, 928, -1, 546, 549, -1, 926, + -1, 4, -1, 548, 897, -1, 6, -1, 7, -1, + 924, 548, -1, 924, 518, 875, 710, 709, 519, 548, + -1, 792, 548, -1, 808, 518, 824, 519, 823, -1, + 808, 926, 823, -1, 808, 548, 823, -1, 438, -1, + 160, -1, 280, -1, 9, -1, 3, -1, 1005, -1, + 1010, -1, 3, -1, 1005, -1, 1007, -1, 3, -1, + 1005, -1, 1008, -1, 546, -1, 546, 931, -1, 520, + 551, -1, 931, 520, 551, -1, 518, 921, 519, -1, + -1, 927, -1, 552, -1, 5, -1, 326, 923, 936, + 40, 937, -1, 518, 877, 519, -1, -1, 686, -1, + 555, -1, 667, -1, 668, -1, 982, -1, 994, -1, + 100, 373, 545, 939, -1, 100, 373, 192, 275, 152, + 545, 939, -1, 100, 295, 355, 373, 545, 939, -1, + 939, 940, -1, -1, 604, -1, 941, -1, 580, -1, + 1000, -1, 100, 947, 203, 944, 945, 290, 545, 943, + 518, 574, 519, 946, 781, -1, 100, 947, 203, 944, + 192, 275, 152, 633, 290, 545, 943, 518, 574, 519, + 946, 781, -1, 546, -1, 457, 942, -1, -1, 89, + -1, -1, 633, -1, -1, 480, 619, -1, -1, 448, + -1, -1, 32, 419, 775, 389, 373, 923, -1, 32, + 419, 192, 152, 775, 389, 373, 923, -1, 32, 384, + 545, 389, 373, 923, -1, 32, 384, 192, 152, 545, + 389, 373, 923, -1, 32, 470, 545, 389, 373, 923, + -1, 32, 470, 192, 152, 545, 389, 373, 923, -1, + 168, 75, 950, -1, 75, 950, -1, 546, -1, -1, + 84, 290, 953, 545, 222, 952, -1, 84, 290, 82, + 824, 222, 952, -1, 548, -1, 280, -1, 419, -1, + 384, -1, 174, -1, 246, -1, 246, 419, -1, 470, + -1, 108, -1, 203, -1, 373, -1, 442, -1, 154, + 108, 548, 676, -1, 154, 108, 546, 431, 548, 676, + -1, 198, 108, 548, -1, 153, 959, -1, 153, 963, + 957, 959, -1, 153, 468, 959, -1, 153, 518, 962, + 519, 959, -1, 468, -1, -1, 964, -1, 594, -1, + -1, 948, -1, 591, -1, 533, -1, 999, -1, 949, + -1, 668, -1, 1002, -1, 658, -1, 938, -1, 580, + -1, 604, -1, 576, -1, 544, -1, 982, -1, 652, + -1, 587, -1, 941, -1, 555, -1, 973, -1, 579, + -1, 935, -1, 553, -1, 686, -1, 600, -1, 667, + -1, 586, -1, 977, -1, 991, -1, 967, -1, 994, + -1, 1000, -1, 3, -1, 1005, -1, 1009, -1, 960, + -1, 548, -1, 965, -1, 962, 522, 965, -1, 35, + -1, 34, -1, 438, -1, 160, -1, 290, -1, 961, + -1, 966, 958, -1, 960, -1, 963, -1, 389, 968, + -1, 389, 241, 968, -1, 389, 388, 968, -1, 389, + 178, 968, -1, 389, 465, 968, -1, 969, -1, 998, + 172, 104, -1, 429, 501, 971, -1, 373, 548, -1, + 998, 431, 972, -1, 998, 507, 972, -1, 824, -1, + 548, -1, 3, -1, 808, 548, 823, -1, 808, 518, + 926, 519, 548, -1, 594, -1, 117, -1, 241, -1, + 970, -1, 972, 522, 970, -1, 240, 975, -1, 974, + 214, 975, 976, -1, 974, 214, 975, 172, 546, 976, + -1, 974, 214, 975, 172, 548, 976, -1, -1, 168, + -1, 548, -1, 546, -1, -1, 469, 548, -1, 469, + 546, -1, 458, 979, 981, 957, -1, 458, 979, 981, + 957, 545, 932, -1, 458, 979, 981, 957, 986, -1, + 458, 518, 980, 519, -1, 458, 518, 980, 519, 545, + 932, -1, 963, -1, 468, -1, 171, -1, 173, -1, + 3, -1, 173, -1, -1, 978, -1, 980, 522, 978, + -1, 171, -1, -1, 560, 122, 172, 983, 985, 984, + 566, -1, 439, 704, 983, -1, 775, -1, 775, 546, + -1, 775, 40, 546, -1, 477, 824, -1, -1, 457, + 756, -1, -1, 963, 957, -1, 963, 957, 545, 932, + -1, 47, 989, 548, 990, 676, -1, 47, 192, 275, + 152, 989, 548, 990, 676, -1, 128, 552, -1, 128, + 108, 552, -1, 128, 108, 192, 152, 552, -1, 108, + -1, -1, 40, 546, -1, -1, 357, 993, -1, 357, + 241, 993, -1, 357, 388, 993, -1, 357, 178, 993, + -1, 357, 465, 993, -1, 998, -1, 30, -1, 992, + -1, 429, 501, -1, 433, 224, 236, -1, 996, 686, + -1, 415, 686, -1, 415, 545, -1, 996, 545, -1, + 996, 429, 501, -1, 996, 433, 224, 236, -1, 996, + 30, 997, -1, 996, -1, 127, -1, 126, -1, 393, + -1, 995, -1, 420, -1, -1, 546, -1, 998, 520, + 546, -1, 61, 834, -1, 100, 650, 470, 545, 639, + 946, 40, 686, 1001, -1, 100, 650, 470, 192, 275, + 152, 545, 639, 946, 40, 686, 1001, -1, 100, 295, + 355, 650, 470, 545, 639, 946, 40, 686, 1001, -1, + 100, 650, 345, 470, 545, 518, 643, 519, 946, 40, + 686, 1001, -1, 100, 295, 355, 650, 345, 470, 545, + 518, 643, 519, 946, 40, 686, 1001, -1, 480, 74, + 293, -1, 480, 64, 74, 293, -1, 480, 241, 74, + 293, -1, -1, 100, 650, 419, 1004, 40, 686, 1003, + -1, 100, 650, 419, 192, 275, 152, 1004, 40, 686, + 1003, -1, 100, 295, 355, 650, 419, 1004, 40, 686, + 1003, -1, 480, 107, -1, 480, 273, 107, -1, -1, + 545, 639, 626, 618, -1, 22, -1, 23, -1, 24, + -1, 25, -1, 26, -1, 27, -1, 28, -1, 29, + -1, 31, -1, 32, -1, 33, -1, 43, -1, 44, + -1, 46, -1, 47, -1, 48, -1, 50, -1, 51, + -1, 52, -1, 59, -1, 60, -1, 61, -1, 62, + -1, 63, -1, 64, -1, 67, -1, 68, -1, 69, + -1, 70, -1, 73, -1, 75, -1, 76, -1, 77, + -1, 78, -1, 84, -1, 85, -1, 86, -1, 87, + -1, 88, -1, 90, -1, 91, -1, 92, -1, 94, + -1, 95, -1, 96, -1, 97, -1, 98, -1, 99, + -1, 102, -1, 103, -1, 104, -1, 105, -1, 106, + -1, 107, -1, 108, -1, 109, -1, 110, -1, 111, + -1, 113, -1, 114, -1, 116, -1, 118, -1, 120, + -1, 121, -1, 122, -1, 123, -1, 124, -1, 125, + -1, 128, -1, 129, -1, 130, -1, 131, -1, 134, + -1, 135, -1, 136, -1, 137, -1, 138, -1, 140, + -1, 141, -1, 142, -1, 144, -1, 145, -1, 146, + -1, 148, -1, 149, -1, 150, -1, 151, -1, 153, + -1, 154, -1, 155, -1, 156, -1, 157, -1, 158, + -1, 161, -1, 163, -1, 164, -1, 166, -1, 168, + -1, 170, -1, 174, -1, 175, -1, 178, -1, 180, + -1, 184, -1, 185, -1, 187, -1, 188, -1, 189, + -1, 190, -1, 191, -1, 192, -1, 193, -1, 195, + -1, 196, -1, 197, -1, 198, -1, 200, -1, 201, + -1, 202, -1, 203, -1, 204, -1, 205, -1, 206, + -1, 208, -1, 211, -1, 212, -1, 213, -1, 214, + -1, 215, -1, 221, -1, 224, -1, 226, -1, 227, + -1, 228, -1, 229, -1, 230, -1, 231, -1, 234, + -1, 236, -1, 239, -1, 240, -1, 241, -1, 242, + -1, 243, -1, 244, -1, 245, -1, 246, -1, 248, + -1, 249, -1, 250, -1, 251, -1, 252, -1, 253, + -1, 254, -1, 255, -1, 256, -1, 257, -1, 258, + -1, 259, -1, 260, -1, 261, -1, 262, -1, 263, + -1, 264, -1, 265, -1, 266, -1, 267, -1, 271, + -1, 272, -1, 273, -1, 276, -1, 277, -1, 279, + -1, 282, -1, 284, -1, 285, -1, 286, -1, 288, + -1, 289, -1, 292, -1, 293, -1, 294, -1, 297, + -1, 298, -1, 301, -1, 304, -1, 305, -1, 306, + -1, 307, -1, 308, -1, 309, -1, 310, -1, 311, + -1, 312, -1, 313, -1, 314, -1, 319, -1, 320, + -1, 323, -1, 324, -1, 326, -1, 327, -1, 328, + -1, 330, -1, 331, -1, 332, -1, 333, -1, 334, + -1, 335, -1, 337, -1, 338, -1, 339, -1, 340, + -1, 341, -1, 343, -1, 344, -1, 345, -1, 346, + -1, 348, -1, 349, -1, 350, -1, 351, -1, 352, + -1, 353, -1, 354, -1, 355, -1, 356, -1, 357, + -1, 358, -1, 359, -1, 360, -1, 362, -1, 363, + -1, 365, -1, 366, -1, 367, -1, 369, -1, 370, + -1, 371, -1, 372, -1, 373, -1, 374, -1, 375, + -1, 376, -1, 377, -1, 378, -1, 379, -1, 380, + -1, 381, -1, 384, -1, 385, -1, 386, -1, 387, + -1, 388, -1, 389, -1, 391, -1, 392, -1, 395, + -1, 396, -1, 398, -1, 400, -1, 401, -1, 402, + -1, 403, -1, 404, -1, 405, -1, 406, -1, 407, + -1, 408, -1, 409, -1, 410, -1, 411, -1, 413, + -1, 417, -1, 418, -1, 420, -1, 422, -1, 423, + -1, 424, -1, 425, -1, 426, -1, 428, -1, 433, + -1, 434, -1, 436, -1, 439, -1, 440, -1, 442, + -1, 443, -1, 444, -1, 445, -1, 446, -1, 449, + -1, 450, -1, 451, -1, 453, -1, 454, -1, 455, + -1, 456, -1, 458, -1, 459, -1, 460, -1, 461, + -1, 462, -1, 465, -1, 467, -1, 469, -1, 470, + -1, 471, -1, 472, -1, 473, -1, 474, -1, 475, + -1, 478, -1, 481, -1, 482, -1, 483, -1, 484, + -1, 485, -1, 486, -1, 498, -1, 499, -1, 500, + -1, 501, -1, 53, -1, 54, -1, 56, -1, 57, + -1, 71, -1, 72, -1, 79, -1, 83, -1, 112, + -1, 115, -1, 152, -1, 159, -1, 165, -1, 176, + -1, 182, -1, 183, -1, 210, -1, 216, -1, 217, + -1, 219, -1, 247, -1, 268, -1, 270, -1, 274, + -1, 281, -1, 283, -1, 299, -1, 303, -1, 321, + -1, 325, -1, 342, -1, 368, -1, 390, -1, 397, + -1, 412, -1, 414, -1, 429, -1, 430, -1, 435, + -1, 437, -1, 441, -1, 463, -1, 464, -1, 487, + -1, 488, -1, 489, -1, 490, -1, 491, -1, 492, + -1, 493, -1, 494, -1, 495, -1, 496, -1, 497, + -1, 42, -1, 49, -1, 55, -1, 81, -1, 89, -1, 101, -1, 171, -1, 173, -1, 176, -1, 177, -1, 194, -1, 209, -1, 222, -1, 223, -1, 225, -1, 235, -1, 237, -1, 247, -1, 269, -1, 278, - -1, 300, -1, 302, -1, 323, -1, 365, -1, 395, - -1, 414, -1, 423, -1, 471, -1, 37, -1, 42, - -1, 46, -1, 49, -1, 55, -1, 81, -1, 83, - -1, 89, -1, 101, -1, 171, -1, 173, -1, 177, - -1, 194, -1, 209, -1, 222, -1, 223, -1, 225, - -1, 235, -1, 237, -1, 269, -1, 278, -1, 300, - -1, 302, -1, 323, -1, 365, -1, 384, -1, 395, - -1, 423, -1, 443, -1, 454, -1, 471, -1, 37, - -1, 42, -1, 46, -1, 49, -1, 53, -1, 54, - -1, 55, -1, 56, -1, 57, -1, 72, -1, 71, - -1, 79, -1, 81, -1, 83, -1, 89, -1, 101, - -1, 112, -1, 115, -1, 152, -1, 159, -1, 165, - -1, 171, -1, 173, -1, 176, -1, 177, -1, 182, - -1, 183, -1, 194, -1, 209, -1, 210, -1, 217, - -1, 219, -1, 216, -1, 222, -1, 223, -1, 225, - -1, 235, -1, 237, -1, 247, -1, 268, -1, 269, - -1, 270, -1, 274, -1, 278, -1, 281, -1, 283, - -1, 300, -1, 299, -1, 302, -1, 303, -1, 322, - -1, 323, -1, 326, -1, 343, -1, 365, -1, 369, - -1, 384, -1, 391, -1, 395, -1, 398, -1, 414, - -1, 416, -1, 423, -1, 431, -1, 432, -1, 437, - -1, 439, -1, 443, -1, 454, -1, 466, -1, 467, - -1, 471, -1, 490, -1, 491, -1, 492, -1, 493, - -1, 494, -1, 495, -1, 496, -1, 497, -1, 498, - -1, 499, -1, 500, -1, 37, -1, 42, -1, 46, + -1, 300, -1, 302, -1, 322, -1, 364, -1, 394, + -1, 412, -1, 421, -1, 468, -1, 37, -1, 42, + -1, 49, -1, 55, -1, 81, -1, 83, -1, 89, + -1, 101, -1, 171, -1, 173, -1, 177, -1, 194, + -1, 209, -1, 222, -1, 223, -1, 225, -1, 235, + -1, 237, -1, 269, -1, 278, -1, 300, -1, 302, + -1, 322, -1, 364, -1, 383, -1, 394, -1, 421, + -1, 441, -1, 468, -1, 37, -1, 42, -1, 49, + -1, 53, -1, 54, -1, 55, -1, 56, -1, 57, + -1, 72, -1, 71, -1, 79, -1, 81, -1, 83, + -1, 89, -1, 101, -1, 112, -1, 115, -1, 152, + -1, 159, -1, 165, -1, 171, -1, 173, -1, 176, + -1, 177, -1, 182, -1, 183, -1, 194, -1, 209, + -1, 210, -1, 217, -1, 219, -1, 216, -1, 222, + -1, 223, -1, 225, -1, 235, -1, 237, -1, 247, + -1, 268, -1, 269, -1, 270, -1, 274, -1, 278, + -1, 281, -1, 283, -1, 300, -1, 299, -1, 302, + -1, 303, -1, 321, -1, 322, -1, 325, -1, 342, + -1, 364, -1, 368, -1, 383, -1, 390, -1, 394, + -1, 397, -1, 412, -1, 414, -1, 421, -1, 429, + -1, 430, -1, 435, -1, 437, -1, 441, -1, 463, + -1, 464, -1, 468, -1, 487, -1, 488, -1, 489, + -1, 490, -1, 491, -1, 492, -1, 493, -1, 494, + -1, 495, -1, 496, -1, 497, -1, 37, -1, 42, -1, 49, -1, 55, -1, 81, -1, 83, -1, 89, -1, 101, -1, 171, -1, 173, -1, 176, -1, 177, -1, 194, -1, 209, -1, 222, -1, 223, -1, 225, -1, 235, -1, 237, -1, 247, -1, 269, -1, 278, - -1, 300, -1, 302, -1, 323, -1, 365, -1, 384, - -1, 395, -1, 414, -1, 423, -1, 443, -1, 454, - -1, 471, -1, 30, -1, 34, -1, 35, -1, 36, - -1, 38, -1, 39, -1, 40, -1, 41, -1, 45, - -1, 58, -1, 65, -1, 66, -1, 74, -1, 80, - -1, 82, -1, 93, -1, 100, -1, 117, -1, 119, - -1, 126, -1, 127, -1, 132, -1, 133, -1, 139, - -1, 143, -1, 147, -1, 160, -1, 162, -1, 167, - -1, 169, -1, 172, -1, 181, -1, 186, -1, 199, + -1, 300, -1, 302, -1, 322, -1, 364, -1, 383, + -1, 394, -1, 412, -1, 421, -1, 441, -1, 468, + -1, 30, -1, 34, -1, 35, -1, 36, -1, 38, + -1, 39, -1, 40, -1, 41, -1, 45, -1, 58, + -1, 65, -1, 66, -1, 74, -1, 80, -1, 82, + -1, 93, -1, 100, -1, 117, -1, 119, -1, 126, + -1, 127, -1, 132, -1, 133, -1, 139, -1, 143, + -1, 147, -1, 160, -1, 162, -1, 167, -1, 169, + -1, 172, -1, 179, -1, 181, -1, 186, -1, 199, -1, 207, -1, 218, -1, 220, -1, 232, -1, 233, -1, 238, -1, 275, -1, 280, -1, 287, -1, 290, - -1, 291, -1, 295, -1, 296, -1, 316, -1, 317, - -1, 318, -1, 319, -1, 330, -1, 337, -1, 348, - -1, 362, -1, 383, -1, 394, -1, 400, -1, 417, - -1, 418, -1, 421, -1, 429, -1, 433, -1, 434, - -1, 440, -1, 449, -1, 450, -1, 455, -1, 460, - -1, 469, -1, 479, -1, 480, -1, 482, -1, 483, + -1, 291, -1, 295, -1, 296, -1, 315, -1, 316, + -1, 317, -1, 318, -1, 329, -1, 336, -1, 347, + -1, 361, -1, 382, -1, 393, -1, 399, -1, 415, + -1, 416, -1, 419, -1, 427, -1, 431, -1, 432, + -1, 438, -1, 447, -1, 448, -1, 452, -1, 457, + -1, 466, -1, 476, -1, 477, -1, 479, -1, 480, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 513, 513, 529, 541, 550, 551, 552, 553, 554, - 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, - 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, - 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, - 585, 586, 587, 588, 589, 590, 592, 9, 18, 27, + 0, 509, 509, 525, 537, 546, 547, 548, 549, 550, + 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, + 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, + 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, + 581, 582, 583, 584, 585, 586, 588, 9, 18, 27, 36, 45, 54, 63, 72, 85, 87, 93, 94, 99, - 103, 107, 118, 126, 130, 138, 139, 143, 150, 151, - 156, 163, 173, 182, 191, 200, 209, 217, 225, 233, - 241, 250, 258, 266, 275, 284, 293, 302, 319, 328, - 337, 346, 356, 369, 384, 393, 401, 416, 424, 434, - 444, 451, 458, 466, 473, 484, 485, 490, 494, 499, - 504, 512, 513, 518, 522, 523, 524, 7, 13, 19, - 25, 9, 13, 44, 45, 46, 50, 51, 55, 59, - 60, 64, 70, 75, 76, 77, 78, 6, 15, 25, - 35, 45, 55, 65, 75, 85, 95, 106, 117, 127, - 140, 141, 9, 23, 29, 36, 42, 49, 59, 63, - 71, 72, 73, 77, 86, 95, 102, 103, 108, 120, - 125, 150, 155, 160, 166, 176, 186, 192, 203, 214, - 229, 230, 236, 237, 242, 243, 249, 250, 254, 255, - 260, 262, 268, 269, 273, 274, 277, 278, 283, 7, - 16, 25, 46, 47, 50, 54, 7, 14, 22, 9, - 19, 29, 42, 43, 7, 17, 27, 40, 41, 45, - 46, 47, 51, 52, 57, 61, 68, 72, 7, 7, - 14, 31, 51, 55, 65, 69, 75, 76, 9, 17, - 29, 30, 34, 35, 36, 41, 42, 43, 48, 52, - 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, - 97, 101, 105, 112, 113, 117, 118, 119, 7, 16, - 28, 29, 2, 10, 17, 24, 32, 40, 51, 52, - 53, 57, 58, 59, 2, 7, 21, 36, 56, 57, - 84, 85, 86, 87, 88, 89, 93, 94, 99, 104, - 105, 106, 107, 108, 113, 120, 121, 122, 139, 146, - 153, 163, 173, 185, 193, 202, 220, 221, 225, 226, - 230, 239, 262, 276, 283, 288, 290, 292, 294, 297, - 300, 301, 302, 303, 308, 312, 313, 318, 325, 330, - 331, 332, 333, 334, 335, 336, 337, 343, 344, 348, - 353, 360, 367, 374, 386, 387, 388, 389, 393, 398, - 399, 400, 405, 410, 411, 412, 413, 414, 415, 420, - 440, 466, 474, 484, 485, 489, 493, 494, 495, 499, - 503, 511, 512, 517, 518, 519, 523, 531, 532, 537, - 538, 542, 547, 551, 555, 560, 568, 569, 573, 574, - 578, 579, 585, 596, 609, 623, 637, 651, 665, 688, - 692, 699, 703, 711, 716, 723, 733, 734, 735, 736, - 737, 744, 751, 752, 757, 758, 9, 19, 29, 39, - 49, 59, 73, 74, 75, 76, 77, 78, 79, 80, - 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, - 95, 96, 97, 98, 99, 100, 105, 106, 111, 112, - 113, 118, 119, 120, 8, 18, 29, 39, 49, 59, - 71, 81, 91, 95, 102, 106, 110, 119, 123, 130, - 131, 135, 139, 7, 1, 30, 49, 61, 62, 63, - 67, 68, 73, 77, 82, 86, 94, 95, 99, 100, - 105, 106, 110, 111, 116, 117, 118, 119, 120, 121, - 122, 123, 128, 136, 140, 145, 146, 151, 155, 160, - 164, 168, 172, 176, 180, 184, 188, 192, 196, 200, - 204, 208, 212, 216, 220, 228, 233, 234, 235, 236, - 237, 243, 247, 47, 48, 52, 53, 54, 72, 73, - 80, 88, 96, 104, 112, 120, 131, 132, 159, 164, - 172, 188, 205, 223, 241, 242, 261, 265, 269, 273, - 277, 287, 298, 308, 317, 328, 339, 351, 366, 384, - 384, 388, 388, 392, 392, 396, 402, 409, 413, 414, - 418, 419, 433, 440, 447, 457, 458, 461, 475, 476, - 480, 481, 485, 486, 490, 491, 492, 496, 507, 515, - 520, 525, 530, 535, 543, 551, 556, 561, 568, 569, - 573, 574, 575, 579, 586, 587, 591, 592, 596, 597, - 598, 602, 603, 607, 608, 624, 625, 628, 637, 648, - 649, 650, 653, 654, 655, 659, 660, 661, 662, 666, - 667, 671, 673, 689, 691, 696, 699, 704, 708, 712, - 719, 723, 727, 731, 738, 743, 750, 751, 755, 760, - 764, 768, 776, 783, 784, 789, 790, 795, 796, 800, - 810, 811, 816, 817, 822, 824, 826, 831, 851, 852, - 854, 859, 860, 864, 865, 868, 869, 894, 895, 900, - 904, 905, 909, 910, 914, 915, 916, 917, 918, 922, - 935, 942, 949, 956, 957, 961, 962, 966, 967, 971, - 972, 976, 977, 981, 982, 986, 997, 998, 999, 1000, - 1004, 1005, 1010, 1011, 1012, 1021, 1027, 1036, 1037, 1050, - 1051, 1055, 1056, 1060, 1061, 1065, 1076, 1083, 1090, 1098, - 1106, 1116, 1124, 1133, 1142, 1151, 1155, 1160, 1165, 1176, - 1190, 1191, 1194, 1195, 1196, 1199, 1207, 1217, 1218, 1219, - 1222, 1230, 1239, 1243, 1250, 1251, 1255, 1264, 1268, 1293, - 1297, 1310, 1324, 1339, 1351, 1364, 1378, 1392, 1405, 1420, - 1439, 1445, 1450, 1456, 1463, 1464, 1472, 1476, 1480, 1486, - 1493, 1498, 1499, 1500, 1501, 1502, 1503, 1507, 1508, 1520, - 1521, 1526, 1533, 1540, 1547, 1579, 1590, 1603, 1608, 1609, - 1612, 1613, 1616, 1617, 1622, 1623, 1628, 1632, 1638, 1659, - 1667, 1681, 1684, 1688, 1688, 1691, 1692, 1694, 1699, 1706, - 1711, 1717, 1722, 1728, 1732, 1739, 1746, 1756, 1757, 1761, - 1763, 1766, 1770, 1771, 1772, 1773, 1774, 1775, 1780, 1800, - 1801, 1802, 1803, 1814, 1828, 1829, 1835, 1840, 1845, 1850, - 1855, 1860, 1865, 1870, 1876, 1882, 1888, 1895, 1917, 1926, - 1930, 1938, 1942, 1950, 1962, 1983, 1987, 1993, 1997, 2010, - 2018, 2028, 2030, 2032, 2034, 2036, 2038, 2043, 2044, 2051, - 2060, 2068, 2077, 2088, 2096, 2097, 2098, 2102, 2102, 2105, - 2105, 2108, 2108, 2111, 2111, 2114, 2114, 2117, 2117, 2120, - 2120, 2123, 2123, 2126, 2126, 2129, 2129, 2132, 2132, 2135, - 2135, 2138, 2138, 2141, 2143, 2145, 2147, 2149, 2151, 2153, - 2155, 2157, 2159, 2161, 2163, 2165, 2167, 2172, 2177, 2183, - 2190, 2195, 2201, 2207, 2238, 2240, 2242, 2250, 2265, 2267, - 2269, 2271, 2273, 2275, 2277, 2279, 2281, 2283, 2285, 2287, - 2289, 2291, 2293, 2295, 2298, 2300, 2302, 2305, 2307, 2309, - 2311, 2313, 2318, 2323, 2330, 2335, 2342, 2347, 2354, 2359, - 2367, 2375, 2383, 2391, 2409, 2417, 2425, 2433, 2441, 2449, - 2457, 2461, 2477, 2485, 2493, 2501, 2509, 2517, 2525, 2529, - 2533, 2537, 2541, 2549, 2557, 2565, 2573, 2593, 2615, 2626, - 2633, 2647, 2655, 2660, 2670, 2679, 2700, 2702, 2704, 2706, - 2708, 2710, 2712, 2714, 2716, 2718, 2720, 2722, 2724, 2726, - 2728, 2730, 2732, 2734, 2736, 2738, 2740, 2742, 2746, 2750, - 2754, 2768, 2769, 2783, 2784, 2785, 2796, 2820, 2831, 2841, - 2845, 2849, 2856, 2860, 2867, 2874, 2875, 2876, 2877, 2878, - 2879, 2880, 2881, 2892, 2897, 2906, 2912, 2919, 2939, 2943, - 2950, 2957, 2965, 2973, 2984, 3004, 3040, 3051, 3052, 3059, - 3065, 3067, 3069, 3073, 3082, 3087, 3094, 3109, 3116, 3120, - 3124, 3128, 3132, 3142, 3150, 3159, 3181, 3182, 3186, 3187, - 3188, 3192, 3193, 3200, 3201, 3205, 3206, 3211, 3219, 3221, - 3235, 3238, 3265, 3266, 3269, 3270, 3278, 3286, 3294, 3303, - 3313, 3331, 3377, 3386, 3395, 3404, 3413, 3425, 3426, 3427, - 3428, 3429, 3443, 3444, 3447, 3448, 3452, 3462, 3463, 3467, - 3468, 3472, 3479, 3480, 3485, 3486, 3491, 3492, 3495, 3496, - 3497, 3500, 3501, 3504, 3505, 3506, 3507, 3508, 3509, 3510, - 3511, 3512, 3513, 3514, 3515, 3516, 3517, 3520, 3522, 3527, - 3529, 3534, 3536, 3538, 3540, 3542, 3544, 3546, 3548, 3562, - 3564, 3569, 3573, 3580, 3585, 3591, 3595, 3602, 3607, 3614, - 3619, 3627, 3631, 3637, 3641, 3650, 3661, 3662, 3666, 3670, - 3677, 3678, 3679, 3680, 3681, 3682, 3683, 3684, 3685, 3686, - 3687, 3688, 3689, 3690, 3691, 3701, 3705, 3712, 3719, 3720, - 3736, 3740, 3745, 3749, 3764, 3769, 3773, 3776, 3779, 3780, - 3781, 3784, 3791, 3792, 3793, 3803, 3817, 3818, 3822, 3833, - 3834, 3837, 3838, 3842, 3843, 3846, 3852, 3856, 3863, 3871, - 3879, 3887, 3897, 3898, 3903, 3904, 3908, 3909, 3910, 3914, - 3923, 3931, 3939, 3948, 3963, 3964, 3969, 3970, 3980, 3981, - 3985, 3986, 3990, 3991, 3994, 4010, 4018, 4026, 4036, 4037, - 4041, 4045, 4051, 4053, 4058, 4059, 4063, 4064, 4067, 4071, - 4072, 4076, 4077, 4080, 4081, 4082, 4085, 4089, 4090, 4094, - 4095, 4097, 4098, 4099, 4109, 4110, 4114, 4116, 4122, 4123, - 4127, 4128, 4131, 4142, 4145, 4156, 4160, 4164, 4176, 4180, - 4189, 4196, 4234, 4238, 4242, 4246, 4250, 4254, 4258, 4264, - 4281, 4282, 4283, 4286, 4287, 4288, 4291, 4292, 4293, 4296, - 4297, 4300, 4302, 4307, 4308, 4311, 4315, 4316, 7, 18, - 19, 23, 24, 25, 26, 27, 28, 7, 26, 50, - 73, 80, 85, 86, 87, 88, 8, 33, 62, 66, - 67, 72, 73, 78, 79, 83, 84, 89, 90, 7, - 16, 25, 34, 43, 52, 5, 12, 22, 23, 7, - 15, 26, 27, 30, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 7, 19, 33, 9, 16, 26, 33, - 44, 45, 50, 51, 52, 57, 58, 59, 60, 61, - 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 91, 92, 93, 98, - 99, 104, 108, 116, 117, 122, 123, 124, 130, 135, - 143, 144, 10, 16, 22, 28, 34, 44, 45, 53, - 64, 76, 84, 95, 101, 105, 109, 124, 131, 132, - 133, 137, 138, 7, 17, 26, 35, 46, 47, 49, - 50, 53, 54, 55, 8, 22, 36, 48, 56, 70, - 71, 72, 73, 74, 87, 88, 93, 94, 98, 99, - 7, 18, 31, 35, 42, 53, 54, 60, 61, 9, - 19, 7, 16, 25, 37, 44, 51, 60, 61, 65, - 66, 2, 7, 12, 17, 22, 31, 38, 48, 49, + 103, 107, 118, 126, 130, 139, 148, 157, 166, 175, + 184, 192, 200, 209, 218, 227, 236, 253, 262, 271, + 280, 290, 303, 318, 327, 335, 350, 358, 368, 378, + 385, 392, 400, 407, 418, 419, 424, 428, 433, 438, + 446, 447, 452, 456, 457, 458, 7, 13, 19, 25, + 9, 13, 44, 45, 46, 50, 51, 55, 59, 60, + 64, 70, 75, 76, 77, 78, 6, 15, 25, 35, + 45, 55, 65, 75, 85, 95, 106, 117, 127, 140, + 141, 9, 23, 29, 36, 42, 49, 59, 63, 71, + 72, 73, 77, 86, 95, 102, 103, 108, 120, 125, + 150, 155, 160, 166, 176, 186, 192, 203, 214, 229, + 230, 236, 237, 242, 243, 249, 250, 254, 255, 260, + 262, 268, 269, 273, 274, 277, 278, 283, 7, 16, + 25, 46, 47, 50, 54, 7, 14, 22, 9, 19, + 29, 42, 43, 7, 17, 27, 40, 41, 45, 46, + 47, 51, 52, 7, 7, 14, 31, 51, 55, 65, + 69, 75, 76, 9, 17, 29, 30, 34, 35, 36, + 41, 42, 43, 48, 52, 56, 60, 64, 68, 72, + 76, 80, 84, 88, 92, 97, 101, 105, 112, 113, + 117, 118, 119, 7, 16, 28, 29, 2, 10, 17, + 24, 32, 40, 51, 52, 53, 57, 58, 59, 2, + 7, 21, 36, 56, 57, 84, 85, 86, 87, 88, + 89, 93, 94, 99, 104, 105, 106, 107, 108, 113, + 120, 121, 122, 139, 146, 153, 163, 173, 185, 193, + 202, 220, 221, 225, 226, 230, 239, 262, 276, 283, + 288, 290, 292, 294, 297, 300, 301, 302, 303, 308, + 312, 313, 318, 325, 330, 331, 332, 333, 334, 335, + 336, 337, 343, 344, 348, 353, 360, 367, 374, 386, + 387, 388, 389, 393, 398, 399, 400, 405, 410, 411, + 412, 413, 414, 415, 420, 440, 469, 470, 474, 478, + 479, 480, 484, 488, 496, 497, 502, 503, 504, 508, + 516, 517, 522, 523, 527, 532, 536, 540, 545, 553, + 554, 558, 559, 563, 564, 570, 581, 594, 608, 622, + 636, 650, 673, 677, 684, 688, 696, 701, 708, 718, + 719, 720, 721, 722, 729, 736, 737, 742, 743, 9, + 19, 29, 39, 49, 59, 73, 74, 75, 76, 77, + 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 95, 96, 97, 98, 99, 100, 105, + 106, 111, 112, 113, 118, 119, 120, 8, 18, 29, + 39, 49, 59, 71, 81, 91, 95, 102, 106, 110, + 119, 123, 130, 131, 135, 139, 7, 1, 30, 49, + 61, 62, 63, 67, 68, 73, 77, 82, 86, 94, + 95, 99, 100, 105, 106, 110, 111, 116, 117, 118, + 119, 120, 121, 122, 123, 128, 136, 140, 145, 146, + 151, 155, 160, 164, 168, 172, 176, 180, 184, 188, + 192, 196, 200, 204, 208, 212, 216, 220, 228, 233, + 234, 235, 236, 237, 243, 247, 47, 48, 52, 53, + 54, 72, 73, 80, 88, 96, 104, 112, 120, 131, + 132, 159, 164, 172, 188, 205, 223, 241, 242, 261, + 265, 269, 273, 277, 287, 298, 308, 317, 328, 339, + 351, 366, 384, 384, 388, 388, 392, 392, 396, 402, + 409, 413, 414, 418, 419, 433, 440, 447, 457, 458, + 461, 474, 475, 476, 480, 491, 499, 504, 509, 514, + 519, 527, 535, 540, 545, 552, 553, 557, 558, 559, + 563, 570, 571, 575, 576, 580, 581, 582, 586, 587, + 591, 592, 608, 609, 612, 621, 632, 633, 634, 637, + 638, 639, 643, 644, 645, 646, 650, 651, 655, 657, + 673, 675, 680, 683, 688, 692, 696, 703, 707, 711, + 715, 722, 727, 734, 735, 739, 744, 748, 752, 760, + 767, 768, 773, 774, 778, 779, 784, 786, 788, 793, + 813, 814, 816, 821, 822, 826, 827, 830, 831, 856, + 857, 862, 866, 867, 871, 872, 876, 877, 878, 879, + 880, 884, 897, 904, 911, 918, 919, 923, 924, 928, + 929, 933, 934, 938, 939, 943, 944, 948, 959, 960, + 961, 962, 966, 967, 972, 973, 974, 983, 989, 998, + 999, 1012, 1013, 1017, 1018, 1022, 1023, 1027, 1038, 1044, + 1050, 1058, 1066, 1076, 1084, 1093, 1102, 1111, 1115, 1120, + 1125, 1136, 1150, 1151, 1154, 1155, 1156, 1159, 1167, 1177, + 1178, 1179, 1182, 1190, 1199, 1203, 1210, 1211, 1215, 1224, + 1228, 1253, 1257, 1270, 1284, 1299, 1311, 1324, 1338, 1352, + 1365, 1380, 1399, 1405, 1410, 1416, 1423, 1424, 1432, 1436, + 1440, 1446, 1453, 1458, 1459, 1460, 1461, 1462, 1463, 1467, + 1468, 1480, 1481, 1486, 1493, 1500, 1507, 1539, 1550, 1563, + 1568, 1569, 1572, 1573, 1576, 1577, 1582, 1583, 1588, 1592, + 1598, 1619, 1627, 1641, 1644, 1648, 1648, 1651, 1652, 1654, + 1659, 1666, 1671, 1677, 1682, 1688, 1692, 1699, 1706, 1716, + 1717, 1721, 1723, 1726, 1730, 1731, 1732, 1733, 1734, 1735, + 1740, 1760, 1761, 1762, 1763, 1774, 1788, 1789, 1795, 1800, + 1805, 1810, 1815, 1820, 1825, 1830, 1836, 1842, 1848, 1855, + 1877, 1886, 1890, 1898, 1902, 1910, 1922, 1943, 1947, 1953, + 1957, 1970, 1978, 1988, 1990, 1992, 1994, 1996, 1998, 2003, + 2004, 2011, 2020, 2028, 2037, 2048, 2056, 2057, 2058, 2062, + 2062, 2065, 2065, 2068, 2068, 2071, 2071, 2074, 2074, 2077, + 2077, 2080, 2080, 2083, 2083, 2086, 2086, 2089, 2089, 2092, + 2092, 2095, 2095, 2098, 2098, 2101, 2103, 2105, 2107, 2109, + 2111, 2113, 2115, 2117, 2119, 2121, 2123, 2125, 2127, 2132, + 2137, 2143, 2150, 2155, 2161, 2167, 2198, 2200, 2202, 2210, + 2225, 2227, 2229, 2231, 2233, 2235, 2237, 2239, 2241, 2243, + 2245, 2247, 2249, 2251, 2253, 2255, 2258, 2260, 2262, 2265, + 2267, 2269, 2271, 2273, 2278, 2283, 2290, 2295, 2302, 2307, + 2314, 2319, 2327, 2335, 2343, 2351, 2369, 2377, 2385, 2393, + 2401, 2409, 2417, 2421, 2437, 2445, 2453, 2461, 2469, 2477, + 2485, 2489, 2493, 2497, 2501, 2509, 2517, 2525, 2533, 2553, + 2575, 2586, 2593, 2607, 2616, 2624, 2633, 2654, 2656, 2658, + 2660, 2662, 2664, 2666, 2668, 2670, 2672, 2674, 2676, 2678, + 2680, 2682, 2684, 2686, 2688, 2690, 2692, 2694, 2696, 2700, + 2704, 2708, 2722, 2723, 2737, 2738, 2739, 2750, 2774, 2785, + 2795, 2799, 2803, 2810, 2814, 2821, 2828, 2829, 2830, 2831, + 2832, 2833, 2834, 2835, 2846, 2851, 2860, 2866, 2873, 2893, + 2897, 2904, 2911, 2919, 2927, 2938, 2958, 2994, 3005, 3006, + 3013, 3019, 3021, 3023, 3027, 3036, 3041, 3048, 3063, 3070, + 3074, 3078, 3082, 3086, 3096, 3104, 3113, 3135, 3136, 3140, + 3141, 3142, 3146, 3147, 3154, 3155, 3159, 3160, 3165, 3173, + 3175, 3189, 3192, 3219, 3220, 3223, 3224, 3232, 3240, 3248, + 3257, 3267, 3285, 3331, 3340, 3349, 3358, 3367, 3379, 3380, + 3381, 3382, 3383, 3397, 3398, 3401, 3402, 3406, 3416, 3417, + 3421, 3422, 3426, 3433, 3434, 3439, 3440, 3445, 3446, 3449, + 3450, 3451, 3454, 3455, 3458, 3459, 3460, 3461, 3462, 3463, + 3464, 3465, 3466, 3467, 3468, 3469, 3470, 3471, 3474, 3476, + 3481, 3483, 3488, 3490, 3492, 3494, 3496, 3498, 3500, 3502, + 3516, 3518, 3523, 3527, 3534, 3539, 3545, 3549, 3556, 3561, + 3568, 3573, 3581, 3585, 3591, 3595, 3604, 3615, 3616, 3620, + 3624, 3631, 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, + 3640, 3641, 3642, 3643, 3644, 3645, 3655, 3659, 3666, 3673, + 3674, 3690, 3694, 3699, 3703, 3718, 3723, 3727, 3730, 3733, + 3734, 3735, 3738, 3745, 3746, 3747, 3757, 3771, 3772, 3776, + 3787, 3788, 3791, 3792, 3796, 3797, 3800, 3806, 3810, 3817, + 3825, 3833, 3841, 3851, 3852, 3857, 3858, 3862, 3863, 3864, + 3868, 3877, 3885, 3893, 3902, 3917, 3918, 3923, 3924, 3934, + 3935, 3939, 3940, 3944, 3945, 3948, 3964, 3972, 3980, 3990, + 3991, 3995, 3999, 4005, 4007, 4012, 4013, 4017, 4018, 4021, + 4025, 4026, 4030, 4031, 4034, 4035, 4036, 4039, 4043, 4044, + 4048, 4049, 4051, 4052, 4053, 4063, 4064, 4068, 4070, 4076, + 4077, 4081, 4082, 4085, 4096, 4099, 4110, 4114, 4118, 4130, + 4134, 4143, 4150, 4188, 4192, 4196, 4200, 4204, 4208, 4212, + 4218, 4235, 4236, 4237, 4240, 4241, 4242, 4245, 4246, 4247, + 4250, 4251, 4254, 4256, 4261, 4262, 4265, 4269, 4270, 7, + 18, 19, 23, 24, 25, 26, 27, 28, 7, 26, + 50, 73, 80, 85, 86, 87, 88, 8, 33, 62, + 66, 67, 72, 73, 78, 79, 83, 84, 89, 90, + 7, 16, 25, 34, 43, 52, 5, 12, 22, 23, + 7, 15, 26, 27, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 7, 19, 33, 9, 16, 26, + 33, 44, 45, 50, 51, 52, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 91, 92, 93, + 98, 99, 104, 108, 116, 117, 122, 123, 124, 130, + 135, 143, 144, 10, 16, 22, 28, 34, 44, 45, + 53, 64, 76, 84, 95, 101, 105, 109, 124, 131, + 132, 133, 137, 138, 7, 17, 26, 35, 46, 47, + 49, 50, 53, 54, 55, 8, 22, 36, 48, 56, + 70, 71, 72, 73, 74, 87, 88, 93, 94, 98, + 99, 7, 18, 31, 35, 42, 53, 54, 60, 61, + 9, 19, 7, 16, 28, 35, 42, 51, 52, 56, + 57, 2, 7, 12, 17, 22, 31, 38, 48, 49, 56, 3, 10, 17, 24, 31, 38, 45, 52, 61, 61, 63, 63, 65, 65, 67, 68, 6, 8, 21, 34, 47, 65, 87, 88, 89, 90, 11, 24, 37, @@ -2825,19 +2800,19 @@ static const yytype_uint16 yyrline[] = 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, - 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, + 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, - 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, + 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, - 76, 76, 76, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, @@ -2845,18 +2820,17 @@ static const yytype_uint16 yyrline[] = 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, - 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80 + 80, 80, 80, 80, 80, 80, 80 }; #endif @@ -2913,8 +2887,8 @@ static const char *const yytname[] = "OBJECT_P", "OF", "OFF", "OFFSET", "OIDS", "OLD", "ON", "ONLY", "OPERATOR", "OPTION", "OPTIONS", "OR", "ORDER", "ORDINALITY", "OTHERS", "OUT_P", "OUTER_P", "OVER", "OVERLAPS", "OVERLAY", "OVERRIDING", "OWNED", - "OWNER", "PARALLEL", "PARSER", "PARTIAL", "PARTITION", "PARTITIONED", - "PASSING", "PASSWORD", "PERCENT", "PERSISTENT", "PIVOT", "PIVOT_LONGER", + "OWNER", "PARALLEL", "PARSER", "PARTIAL", "PARTITION", "PASSING", + "PASSWORD", "PERCENT", "PERSISTENT", "PIVOT", "PIVOT_LONGER", "PIVOT_WIDER", "PLACING", "PLANS", "POLICY", "POSITION", "POSITIONAL", "PRAGMA_P", "PRECEDING", "PRECISION", "PREPARE", "PREPARED", "PRESERVE", "PRIMARY", "PRIOR", "PRIVILEGES", "PROCEDURAL", "PROCEDURE", "PROGRAM", @@ -2928,45 +2902,42 @@ static const char *const yytname[] = "SECOND_P", "SECONDS_P", "SECRET", "SECURITY", "SELECT", "SEMI", "SEQUENCE", "SEQUENCES", "SERIALIZABLE", "SERVER", "SESSION", "SET", "SETOF", "SETS", "SHARE", "SHOW", "SIMILAR", "SIMPLE", "SKIP", - "SMALLINT", "SNAPSHOT", "SOME", "SORTED", "SQL_P", "STABLE", - "STANDALONE_P", "START", "STATEMENT", "STATISTICS", "STDIN", "STDOUT", - "STORAGE", "STORED", "STRICT_P", "STRIP_P", "STRUCT", "SUBSCRIPTION", - "SUBSTRING", "SUMMARIZE", "SYMMETRIC", "SYSID", "SYSTEM_P", "TABLE", - "TABLES", "TABLESAMPLE", "TABLESPACE", "TEMP", "TEMPLATE", "TEMPORARY", - "TEXT_P", "THEN", "TIES", "TIME", "TIMESTAMP", "TO", "TRAILING", - "TRANSACTION", "TRANSFORM", "TREAT", "TRIGGER", "TRIM", "TRUE_P", - "TRUNCATE", "TRUSTED", "TRY_CAST", "TYPE_P", "TYPES_P", "UNBOUNDED", - "UNCOMMITTED", "UNENCRYPTED", "UNION", "UNIQUE", "UNKNOWN", "UNLISTEN", - "UNLOGGED", "UNPACK", "UNPIVOT", "UNTIL", "UPDATE", "USE_P", "USER", - "USING", "VACUUM", "VALID", "VALIDATE", "VALIDATOR", "VALUE_P", "VALUES", - "VARCHAR", "VARIABLE_P", "VARIADIC", "VARYING", "VERBOSE", "VERSION_P", - "VIEW", "VIEWS", "VIRTUAL", "VOLATILE", "WEEK_P", "WEEKS_P", "WHEN", - "WHERE", "WHITESPACE_P", "WINDOW", "WITH", "WITHIN", "WITHOUT", "WORK", - "WRAPPER", "WRITE_P", "XML_P", "XMLATTRIBUTES", "XMLCONCAT", - "XMLELEMENT", "XMLEXISTS", "XMLFOREST", "XMLNAMESPACES", "XMLPARSE", - "XMLPI", "XMLROOT", "XMLSERIALIZE", "XMLTABLE", "YEAR_P", "YEARS_P", - "YES_P", "ZONE", "NOT_LA", "NULLS_LA", "WITH_LA", "'<'", "'>'", "'='", + "SMALLINT", "SNAPSHOT", "SOME", "SQL_P", "STABLE", "STANDALONE_P", + "START", "STATEMENT", "STATISTICS", "STDIN", "STDOUT", "STORAGE", + "STORED", "STRICT_P", "STRIP_P", "STRUCT", "SUBSCRIPTION", "SUBSTRING", + "SUMMARIZE", "SYMMETRIC", "SYSID", "SYSTEM_P", "TABLE", "TABLES", + "TABLESAMPLE", "TABLESPACE", "TEMP", "TEMPLATE", "TEMPORARY", "TEXT_P", + "THEN", "TIES", "TIME", "TIMESTAMP", "TO", "TRAILING", "TRANSACTION", + "TRANSFORM", "TREAT", "TRIGGER", "TRIM", "TRUE_P", "TRUNCATE", "TRUSTED", + "TRY_CAST", "TYPE_P", "TYPES_P", "UNBOUNDED", "UNCOMMITTED", + "UNENCRYPTED", "UNION", "UNIQUE", "UNKNOWN", "UNLISTEN", "UNLOGGED", + "UNPIVOT", "UNTIL", "UPDATE", "USE_P", "USER", "USING", "VACUUM", + "VALID", "VALIDATE", "VALIDATOR", "VALUE_P", "VALUES", "VARCHAR", + "VARIABLE_P", "VARIADIC", "VARYING", "VERBOSE", "VERSION_P", "VIEW", + "VIEWS", "VIRTUAL", "VOLATILE", "WEEK_P", "WEEKS_P", "WHEN", "WHERE", + "WHITESPACE_P", "WINDOW", "WITH", "WITHIN", "WITHOUT", "WORK", "WRAPPER", + "WRITE_P", "XML_P", "XMLATTRIBUTES", "XMLCONCAT", "XMLELEMENT", + "XMLEXISTS", "XMLFOREST", "XMLNAMESPACES", "XMLPARSE", "XMLPI", + "XMLROOT", "XMLSERIALIZE", "XMLTABLE", "YEAR_P", "YEARS_P", "YES_P", + "ZONE", "NOT_LA", "NULLS_LA", "WITH_LA", "'<'", "'>'", "'='", "POSTFIXOP", "'+'", "'-'", "'*'", "'/'", "'%'", "'^'", "UMINUS", "'['", "']'", "'('", "')'", "'.'", "';'", "','", "':'", "'?'", "'$'", "'#'", "'{'", "'}'", "$accept", "stmtblock", "stmtmulti", "stmt", "AlterTableStmt", "alter_identity_column_option_list", "alter_column_default", "alter_identity_column_option", - "alter_generic_option_list", "qualify_list", "qualify_el", - "qualified_column", "qualifiedColumnDef", "alter_table_cmd", - "alter_using", "alter_generic_option_elem", "alter_table_cmds", - "alter_generic_options", "opt_set_data", "DeallocateStmt", - "qualified_name", "ColId", "ColIdOrString", "Sconst", "indirection", - "indirection_el", "attr_name", "ColLabel", "RenameStmt", "opt_column", - "InsertStmt", "insert_rest", "insert_target", "opt_by_name_or_position", - "opt_conf_expr", "opt_with_clause", "insert_column_item", "set_clause", - "opt_or_action", "opt_on_conflict", "index_elem", "returning_clause", - "override_kind", "set_target_list", "opt_collate", "opt_class", - "insert_column_list", "set_clause_list", "set_clause_list_opt_comma", - "index_params", "set_target", "CreateTypeStmt", "opt_enum_val_list", - "enum_val_list", "PragmaStmt", "CreateSeqStmt", "OptSeqOptList", - "CreateSecretStmt", "opt_secret_name", "opt_persist", - "opt_storage_specifier", "create_secret_generic_opt_arg", - "create_secret_generic_opt_elem", "create_secret_generic_opt_list", + "alter_generic_option_list", "alter_table_cmd", "alter_using", + "alter_generic_option_elem", "alter_table_cmds", "alter_generic_options", + "opt_set_data", "DeallocateStmt", "qualified_name", "ColId", + "ColIdOrString", "Sconst", "indirection", "indirection_el", "attr_name", + "ColLabel", "RenameStmt", "opt_column", "InsertStmt", "insert_rest", + "insert_target", "opt_by_name_or_position", "opt_conf_expr", + "opt_with_clause", "insert_column_item", "set_clause", "opt_or_action", + "opt_on_conflict", "index_elem", "returning_clause", "override_kind", + "set_target_list", "opt_collate", "opt_class", "insert_column_list", + "set_clause_list", "set_clause_list_opt_comma", "index_params", + "set_target", "CreateTypeStmt", "opt_enum_val_list", "enum_val_list", + "PragmaStmt", "CreateSeqStmt", "OptSeqOptList", "CreateSecretStmt", + "opt_secret_name", "opt_persist", "opt_storage_specifier", "UpdateExtensionsStmt", "ExecuteStmt", "execute_param_expr", "execute_param_list", "execute_param_clause", "AlterSeqStmt", "SeqOptList", "opt_with", "NumericOnly", "SeqOptElem", "opt_by", @@ -2980,19 +2951,18 @@ static const char *const yytname[] = "reloptions", "opt_no_inherit", "TableConstraint", "TableLikeOption", "reloption_list", "ExistingIndex", "ConstraintAttr", "OptWith", "definition", "TableLikeOptionList", "generic_option_name", - "ConstraintAttributeElem", "regularColumnDef", "generatedColumnDef", - "columnDef", "def_list", "index_name", "TableElement", "def_elem", - "opt_definition", "OptTableElementList", "columnElem", "opt_column_list", - "ColQualList", "key_delete", "reloption_elem", "columnList", - "columnList_opt_comma", "func_type", "ConstraintElem", - "TableElementList", "key_match", "TableLikeClause", "OptTemp", - "generated_when", "DropStmt", "drop_type_any_name", "drop_type_name", - "any_name_list", "opt_drop_behavior", "drop_type_name_on_any_name", - "CreateFunctionStmt", "table_macro_definition", - "table_macro_definition_parens", "table_macro_list_internal", - "table_macro_list", "macro_definition", "macro_definition_list", - "macro_alias", "param_list", "UpdateStmt", "CopyStmt", - "copy_database_flag", "copy_from", "copy_delimiter", + "ConstraintAttributeElem", "columnDef", "def_list", "index_name", + "TableElement", "def_elem", "opt_definition", "OptTableElementList", + "columnElem", "opt_column_list", "ColQualList", "key_delete", + "reloption_elem", "columnList", "columnList_opt_comma", "func_type", + "ConstraintElem", "TableElementList", "key_match", "TableLikeClause", + "OptTemp", "generated_when", "DropStmt", "drop_type_any_name", + "drop_type_name", "any_name_list", "opt_drop_behavior", + "drop_type_name_on_any_name", "CreateFunctionStmt", + "table_macro_definition", "table_macro_definition_parens", + "table_macro_list_internal", "table_macro_list", "macro_definition", + "macro_definition_list", "macro_alias", "param_list", "UpdateStmt", + "CopyStmt", "copy_database_flag", "copy_from", "copy_delimiter", "copy_generic_opt_arg_list", "opt_using", "opt_as", "opt_program", "copy_options", "copy_generic_opt_arg", "copy_generic_opt_elem", "opt_oids", "copy_opt_list", "opt_binary", "copy_opt_item", @@ -3001,8 +2971,7 @@ static const char *const yytname[] = "select_no_parens", "select_clause", "opt_select", "simple_select", "value_or_values", "pivot_keyword", "unpivot_keyword", "pivot_column_entry", "pivot_column_list_internal", "pivot_column_list", - "with_clause", "cte_list", "common_table_expr", "opt_on_key", - "column_ref_list_opt_comma", "column_ref_list", "opt_materialized", + "with_clause", "cte_list", "common_table_expr", "opt_materialized", "into_clause", "OptTempTableName", "opt_table", "all_or_distinct", "by_name", "distinct_clause", "opt_all_clause", "opt_ignore_nulls", "opt_sort_clause", "sort_clause", "sortby_list", "sortby", @@ -3010,23 +2979,22 @@ static const char *const yytname[] = "limit_clause", "offset_clause", "sample_value", "sample_count", "sample_clause", "opt_sample_func", "tablesample_entry", "tablesample_clause", "opt_tablesample_clause", "opt_repeatable_clause", - "at_unit", "at_specifier", "opt_at_clause", "select_limit_value", - "select_offset_value", "select_fetch_first_value", "I_or_F_const", - "row_or_rows", "first_or_next", "group_clause", "group_by_list", - "group_by_list_opt_comma", "group_by_item", "empty_grouping_set", - "rollup_clause", "cube_clause", "grouping_sets_clause", - "grouping_or_grouping_id", "having_clause", "qualify_clause", - "for_locking_clause", "opt_for_locking_clause", "for_locking_items", - "for_locking_item", "for_locking_strength", "locked_rels_list", - "opt_nowait_or_skip", "values_clause", "values_clause_opt_comma", - "from_clause", "from_list", "from_list_opt_comma", - "alias_prefix_colon_clause", "table_ref", "opt_pivot_group_by", - "opt_include_nulls", "single_pivot_value", "pivot_header", "pivot_value", - "pivot_value_list", "unpivot_header", "unpivot_value", - "unpivot_value_list", "joined_table", "alias_clause", "opt_alias_clause", - "func_alias_clause", "join_type", "join_outer", "join_qual", - "relation_expr", "func_table", "rowsfrom_item", "rowsfrom_list", - "opt_col_def_list", "opt_ordinality", "where_clause", + "select_limit_value", "select_offset_value", "select_fetch_first_value", + "I_or_F_const", "row_or_rows", "first_or_next", "group_clause", + "group_by_list", "group_by_list_opt_comma", "group_by_item", + "empty_grouping_set", "rollup_clause", "cube_clause", + "grouping_sets_clause", "grouping_or_grouping_id", "having_clause", + "qualify_clause", "for_locking_clause", "opt_for_locking_clause", + "for_locking_items", "for_locking_item", "for_locking_strength", + "locked_rels_list", "opt_nowait_or_skip", "values_clause", + "values_clause_opt_comma", "from_clause", "from_list", + "from_list_opt_comma", "alias_prefix_colon_clause", "table_ref", + "opt_pivot_group_by", "opt_include_nulls", "single_pivot_value", + "pivot_header", "pivot_value", "pivot_value_list", "unpivot_header", + "unpivot_value", "unpivot_value_list", "joined_table", "alias_clause", + "opt_alias_clause", "func_alias_clause", "join_type", "join_outer", + "join_qual", "relation_expr", "func_table", "rowsfrom_item", + "rowsfrom_list", "opt_col_def_list", "opt_ordinality", "where_clause", "TableFuncElementList", "TableFuncElement", "opt_collate_clause", "colid_type_list", "RowOrStruct", "opt_Typename", "Typename", "qualified_typename", "opt_array_bounds", "SimpleTypename", @@ -3150,238 +3118,233 @@ static const yytype_uint16 yytoknum[] = 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, - 755, 756, 757, 758, 759, 760, 761, 762, 60, 62, - 61, 763, 43, 45, 42, 47, 37, 94, 764, 91, - 93, 40, 41, 46, 59, 44, 58, 63, 36, 35, - 123, 125 + 755, 756, 757, 758, 759, 60, 62, 61, 760, 43, + 45, 42, 47, 37, 94, 761, 91, 93, 40, 41, + 46, 59, 44, 58, 63, 36, 35, 123, 125 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint16 yyr1[] = { - 0, 532, 533, 534, 534, 535, 535, 535, 535, 535, - 535, 535, 535, 535, 535, 535, 535, 535, 535, 535, - 535, 535, 535, 535, 535, 535, 535, 535, 535, 535, - 535, 535, 535, 535, 535, 535, 535, 535, 535, 535, - 535, 535, 535, 535, 535, 535, 535, 536, 536, 536, - 536, 536, 536, 536, 536, 537, 537, 538, 538, 539, - 539, 539, 539, 540, 540, 541, 541, 542, 543, 543, - 544, 544, 545, 545, 545, 545, 545, 545, 545, 545, - 545, 545, 545, 545, 545, 545, 545, 545, 545, 545, - 545, 545, 545, 545, 545, 545, 545, 545, 545, 545, - 545, 545, 545, 545, 545, 546, 546, 547, 547, 547, - 547, 548, 548, 549, 550, 550, 550, 551, 551, 551, - 551, 552, 552, 553, 553, 553, 554, 554, 555, 556, - 556, 557, 558, 559, 559, 559, 559, 560, 560, 560, - 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, - 561, 561, 562, 563, 563, 563, 563, 563, 564, 564, - 565, 565, 565, 566, 566, 566, 567, 567, 568, 569, - 569, 570, 570, 570, 571, 571, 571, 572, 572, 572, - 573, 573, 574, 574, 575, 575, 576, 576, 577, 577, - 578, 578, 579, 579, 580, 580, 581, 581, 582, 583, - 583, 583, 584, 584, 585, 585, 586, 586, 586, 587, - 587, 587, 588, 588, 589, 589, 589, 590, 590, 591, - 591, 591, 592, 592, 593, 594, 595, 595, 596, 597, - 597, 597, 598, 598, 599, 599, 600, 600, 601, 601, - 602, 602, 603, 603, 603, 604, 604, 604, 604, 605, - 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, - 605, 605, 605, 606, 606, 607, 607, 607, 608, 608, - 609, 609, 610, 610, 610, 610, 610, 610, 611, 611, - 611, 612, 612, 612, 613, 614, 614, 614, 615, 615, - 616, 616, 616, 616, 616, 616, 617, 617, 618, 619, - 619, 619, 619, 619, 620, 620, 620, 620, 621, 621, - 621, 621, 621, 621, 621, 621, 622, 622, 623, 623, - 624, 624, 624, 625, 626, 627, 627, 627, 627, 627, - 628, 628, 628, 628, 629, 630, 630, 631, 631, 632, - 632, 632, 632, 632, 632, 632, 632, 633, 633, 634, - 635, 635, 635, 635, 636, 636, 636, 636, 637, 638, - 638, 638, 639, 640, 640, 640, 640, 640, 640, 641, - 642, 643, 643, 644, 644, 645, 646, 646, 646, 647, - 647, 648, 648, 649, 649, 649, 650, 651, 651, 652, - 652, 653, 654, 654, 654, 654, 655, 655, 656, 656, - 657, 657, 657, 658, 658, 658, 658, 658, 658, 659, - 659, 660, 660, 660, 660, 661, 662, 662, 662, 662, - 662, 662, 662, 662, 663, 663, 664, 664, 664, 664, - 664, 664, 665, 665, 665, 665, 665, 665, 665, 665, - 665, 665, 665, 665, 665, 665, 665, 665, 665, 665, - 666, 666, 666, 666, 666, 666, 667, 667, 668, 668, - 668, 669, 669, 669, 670, 670, 670, 670, 670, 670, - 671, 672, 673, 673, 674, 674, 675, 676, 676, 677, - 677, 678, 678, 679, 680, 680, 680, 681, 681, 681, - 682, 682, 683, 683, 684, 684, 685, 685, 686, 686, - 687, 687, 688, 688, 689, 689, 689, 689, 689, 689, - 689, 689, 690, 691, 691, 692, 692, 693, 693, 694, - 694, 694, 694, 694, 694, 694, 694, 694, 694, 694, - 694, 694, 694, 694, 694, 695, 696, 696, 696, 696, - 696, 697, 697, 698, 698, 699, 699, 699, 700, 700, - 700, 700, 700, 700, 700, 700, 701, 701, 702, 702, - 703, 703, 703, 703, 703, 703, 703, 703, 703, 703, - 703, 703, 703, 703, 703, 703, 703, 703, 703, 704, - 704, 705, 705, 706, 706, 707, 707, 707, 708, 708, - 709, 709, 710, 710, 710, 711, 711, 712, 713, 713, - 714, 714, 715, 715, 716, 716, 716, 717, 717, 718, - 718, 718, 718, 718, 718, 718, 718, 718, 719, 719, - 720, 720, 720, 721, 722, 722, 723, 723, 724, 724, - 724, 725, 725, 726, 726, 727, 727, 728, 728, 729, - 729, 729, 730, 730, 730, 731, 731, 731, 731, 732, - 732, 733, 733, 733, 733, 734, 734, 735, 735, 735, - 736, 736, 736, 736, 737, 737, 738, 738, 739, 739, - 739, 739, 740, 741, 741, 742, 742, 743, 743, 744, - 745, 745, 746, 746, 746, 746, 746, 747, 748, 748, - 748, 749, 749, 750, 750, 751, 751, 752, 752, 752, - 753, 753, 754, 754, 755, 755, 755, 755, 755, 756, - 757, 758, 759, 760, 760, 761, 761, 762, 762, 763, - 763, 764, 764, 765, 765, 766, 767, 767, 767, 767, - 768, 768, 769, 769, 769, 770, 770, 771, 771, 772, - 772, 773, 773, 774, 774, 775, 776, 776, 776, 776, - 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, - 777, 777, 778, 778, 778, 779, 779, 780, 780, 780, - 781, 781, 782, 782, 783, 783, 784, 785, 785, 786, - 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, - 787, 787, 787, 787, 788, 788, 789, 789, 789, 789, - 789, 790, 790, 790, 790, 790, 790, 791, 791, 792, - 792, 793, 793, 793, 793, 794, 794, 795, 796, 796, - 797, 797, 798, 798, 799, 799, 800, 800, 801, 802, - 802, 803, 803, 804, 804, 805, 805, 806, 806, 806, - 806, 806, 806, 806, 806, 806, 806, 807, 807, 808, - 808, 808, 809, 809, 809, 809, 809, 809, 809, 810, - 810, 810, 810, 811, 812, 812, 813, 813, 813, 813, - 813, 813, 813, 813, 813, 813, 813, 814, 814, 815, - 815, 816, 816, 817, 818, 819, 819, 820, 820, 821, - 822, 823, 823, 823, 823, 823, 823, 824, 824, 825, - 825, 825, 825, 826, 827, 827, 827, 828, 828, 829, - 829, 830, 830, 831, 831, 832, 832, 833, 833, 834, - 834, 835, 835, 836, 836, 837, 837, 838, 838, 839, - 839, 840, 840, 841, 841, 841, 841, 841, 841, 841, - 841, 841, 841, 841, 841, 841, 841, 841, 841, 841, - 841, 841, 841, 841, 842, 842, 842, 842, 842, 842, - 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - 842, 842, 842, 842, 842, 842, 843, 843, 843, 843, - 843, 843, 843, 843, 843, 843, 843, 843, 843, 843, - 843, 843, 843, 843, 843, 843, 843, 843, 843, 843, - 843, 844, 844, 845, 845, 845, 845, 845, 845, 846, - 846, 846, 847, 847, 847, 848, 848, 848, 848, 848, - 848, 848, 848, 848, 848, 849, 850, 851, 852, 852, - 852, 852, 852, 852, 852, 853, 853, 854, 854, 855, - 855, 855, 855, 855, 855, 855, 855, 855, 855, 855, - 855, 855, 855, 856, 857, 857, 858, 858, 859, 859, - 859, 860, 860, 861, 861, 862, 862, 863, 864, 864, - 864, 865, 866, 866, 867, 867, 868, 868, 868, 868, - 869, 869, 870, 870, 870, 870, 870, 871, 871, 871, - 871, 871, 872, 872, 873, 873, 874, 875, 875, 876, - 876, 877, 878, 878, 879, 879, 880, 880, 881, 881, - 881, 882, 882, 883, 883, 883, 883, 883, 883, 883, - 883, 883, 883, 883, 883, 883, 883, 884, 884, 885, - 885, 886, 886, 886, 886, 886, 886, 886, 886, 887, - 887, 888, 888, 889, 889, 890, 890, 891, 891, 892, - 892, 893, 893, 894, 894, 894, 895, 895, 896, 896, - 897, 897, 897, 897, 897, 897, 897, 897, 897, 897, - 897, 897, 897, 897, 897, 898, 898, 899, 900, 900, - 901, 901, 901, 901, 901, 901, 902, 903, 904, 904, - 904, 905, 905, 905, 905, 906, 907, 907, 908, 909, - 909, 910, 910, 911, 911, 912, 913, 913, 557, 557, - 557, 557, 914, 914, 915, 915, 916, 916, 916, 917, - 917, 917, 917, 917, 918, 918, 919, 919, 920, 920, - 921, 921, 922, 922, 923, 923, 923, 923, 924, 924, - 925, 925, 926, 926, 927, 927, 928, 928, 929, 930, - 930, 931, 931, 932, 932, 932, 933, 934, 934, 935, - 935, 936, 936, 936, 937, 937, 938, 938, 939, 939, - 940, 940, 941, 942, 942, 943, 943, 943, 943, 943, - 943, 943, 943, 943, 943, 943, 943, 943, 943, 944, - 945, 945, 945, 946, 946, 946, 947, 947, 947, 948, - 948, 949, 949, 950, 950, 951, 952, 952, 953, 954, - 954, 955, 955, 955, 955, 955, 955, 956, 956, 956, - 957, 957, 958, 958, 958, 958, 959, 959, 960, 961, - 961, 962, 962, 963, 963, 964, 964, 965, 965, 966, - 966, 966, 966, 966, 966, 967, 967, 968, 968, 969, - 969, 970, 970, 971, 971, 971, 971, 971, 971, 971, - 971, 971, 971, 972, 972, 973, 974, 974, 974, 974, + 0, 529, 530, 531, 531, 532, 532, 532, 532, 532, + 532, 532, 532, 532, 532, 532, 532, 532, 532, 532, + 532, 532, 532, 532, 532, 532, 532, 532, 532, 532, + 532, 532, 532, 532, 532, 532, 532, 532, 532, 532, + 532, 532, 532, 532, 532, 532, 532, 533, 533, 533, + 533, 533, 533, 533, 533, 534, 534, 535, 535, 536, + 536, 536, 536, 537, 537, 538, 538, 538, 538, 538, + 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, + 538, 538, 538, 538, 538, 538, 538, 538, 538, 538, + 538, 538, 538, 538, 539, 539, 540, 540, 540, 540, + 541, 541, 542, 543, 543, 543, 544, 544, 544, 544, + 545, 545, 546, 546, 546, 547, 547, 548, 549, 549, + 550, 551, 552, 552, 552, 552, 553, 553, 553, 553, + 553, 553, 553, 553, 553, 553, 553, 553, 553, 554, + 554, 555, 556, 556, 556, 556, 556, 557, 557, 558, + 558, 558, 559, 559, 559, 560, 560, 561, 562, 562, + 563, 563, 563, 564, 564, 564, 565, 565, 565, 566, + 566, 567, 567, 568, 568, 569, 569, 570, 570, 571, + 571, 572, 572, 573, 573, 574, 574, 575, 576, 576, + 576, 577, 577, 578, 578, 579, 579, 579, 580, 580, + 580, 581, 581, 582, 582, 582, 583, 583, 584, 584, + 584, 585, 585, 586, 587, 587, 587, 588, 588, 589, + 589, 590, 590, 591, 591, 592, 592, 593, 593, 593, + 594, 594, 594, 594, 595, 595, 595, 595, 595, 595, + 595, 595, 595, 595, 595, 595, 595, 595, 596, 596, + 597, 597, 597, 598, 598, 599, 599, 600, 600, 600, + 600, 600, 600, 601, 601, 601, 602, 602, 602, 603, + 604, 604, 604, 605, 605, 606, 606, 606, 606, 606, + 606, 607, 607, 608, 609, 609, 609, 609, 609, 610, + 610, 610, 610, 611, 611, 611, 611, 611, 611, 611, + 611, 612, 612, 613, 613, 614, 614, 614, 615, 616, + 617, 617, 617, 617, 617, 618, 618, 618, 618, 619, + 620, 620, 621, 621, 622, 622, 622, 622, 622, 622, + 622, 622, 623, 623, 624, 625, 625, 625, 625, 626, + 626, 626, 626, 627, 628, 628, 628, 629, 630, 630, + 630, 630, 630, 630, 631, 631, 632, 632, 633, 634, + 634, 634, 635, 635, 636, 636, 637, 637, 637, 638, + 639, 639, 640, 640, 641, 642, 642, 642, 642, 643, + 643, 644, 644, 645, 645, 645, 646, 646, 646, 646, + 646, 646, 647, 647, 648, 648, 648, 648, 649, 650, + 650, 650, 650, 650, 650, 650, 650, 651, 651, 652, + 652, 652, 652, 652, 652, 653, 653, 653, 653, 653, + 653, 653, 653, 653, 653, 653, 653, 653, 653, 653, + 653, 653, 653, 654, 654, 654, 654, 654, 654, 655, + 655, 656, 656, 656, 657, 657, 657, 658, 658, 658, + 658, 658, 658, 659, 660, 661, 661, 662, 662, 663, + 664, 664, 665, 665, 666, 666, 667, 668, 668, 668, + 669, 669, 669, 670, 670, 671, 671, 672, 672, 673, + 673, 674, 674, 675, 675, 676, 676, 677, 677, 677, + 677, 677, 677, 677, 677, 678, 679, 679, 680, 680, + 681, 681, 682, 682, 682, 682, 682, 682, 682, 682, + 682, 682, 682, 682, 682, 682, 682, 682, 683, 684, + 684, 684, 684, 684, 685, 685, 686, 686, 687, 687, + 687, 688, 688, 688, 688, 688, 688, 688, 688, 689, + 689, 690, 690, 691, 691, 691, 691, 691, 691, 691, + 691, 691, 691, 691, 691, 691, 691, 691, 691, 691, + 691, 691, 692, 692, 693, 693, 694, 694, 695, 695, + 695, 696, 696, 697, 697, 698, 698, 698, 699, 699, + 700, 701, 701, 701, 702, 702, 703, 703, 703, 703, + 703, 703, 703, 703, 703, 704, 704, 705, 705, 705, + 706, 707, 707, 708, 708, 709, 709, 709, 710, 710, + 711, 711, 712, 712, 713, 713, 714, 714, 714, 715, + 715, 715, 716, 716, 716, 716, 717, 717, 718, 718, + 718, 718, 719, 719, 720, 720, 720, 721, 721, 721, + 721, 722, 722, 723, 723, 724, 724, 724, 724, 725, + 726, 726, 727, 727, 728, 728, 728, 728, 728, 729, + 730, 730, 730, 731, 731, 732, 732, 733, 733, 734, + 734, 734, 735, 735, 736, 736, 737, 737, 737, 737, + 737, 738, 739, 740, 741, 742, 742, 743, 743, 744, + 744, 745, 745, 746, 746, 747, 747, 748, 749, 749, + 749, 749, 750, 750, 751, 751, 751, 752, 752, 753, + 753, 754, 754, 755, 755, 756, 756, 757, 758, 758, + 758, 758, 758, 758, 758, 758, 758, 758, 758, 758, + 758, 758, 759, 759, 760, 760, 760, 761, 761, 762, + 762, 762, 763, 763, 764, 764, 765, 765, 766, 767, + 767, 768, 768, 768, 768, 768, 768, 768, 768, 768, + 768, 768, 769, 769, 769, 769, 770, 770, 771, 771, + 771, 771, 771, 772, 772, 772, 772, 772, 772, 773, + 773, 774, 774, 775, 775, 775, 775, 776, 776, 777, + 778, 778, 779, 779, 780, 780, 781, 781, 782, 782, + 783, 784, 784, 785, 785, 786, 786, 787, 787, 788, + 788, 788, 788, 788, 788, 788, 788, 788, 788, 789, + 789, 790, 790, 790, 791, 791, 791, 791, 791, 791, + 791, 792, 792, 792, 792, 793, 794, 794, 795, 795, + 795, 795, 795, 795, 795, 795, 795, 795, 795, 796, + 796, 797, 797, 798, 798, 799, 800, 801, 801, 802, + 802, 803, 804, 805, 805, 805, 805, 805, 805, 806, + 806, 807, 807, 807, 807, 808, 809, 809, 809, 810, + 810, 811, 811, 812, 812, 813, 813, 814, 814, 815, + 815, 816, 816, 817, 817, 818, 818, 819, 819, 820, + 820, 821, 821, 822, 822, 823, 823, 823, 823, 823, + 823, 823, 823, 823, 823, 823, 823, 823, 823, 823, + 823, 823, 823, 823, 823, 823, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 824, 824, 825, 825, 825, + 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, + 825, 825, 825, 825, 825, 825, 825, 825, 825, 825, + 825, 825, 826, 826, 827, 827, 827, 827, 827, 827, + 828, 828, 828, 829, 829, 829, 830, 830, 830, 830, + 830, 830, 830, 830, 830, 830, 831, 832, 833, 834, + 834, 834, 834, 834, 834, 834, 835, 835, 836, 836, + 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, + 837, 837, 837, 837, 838, 839, 839, 840, 840, 841, + 841, 841, 842, 842, 843, 843, 844, 844, 845, 846, + 846, 846, 847, 848, 848, 849, 849, 850, 850, 850, + 850, 851, 851, 852, 852, 852, 852, 852, 853, 853, + 853, 853, 853, 854, 854, 855, 855, 856, 857, 857, + 858, 858, 859, 860, 860, 861, 861, 862, 862, 863, + 863, 863, 864, 864, 865, 865, 865, 865, 865, 865, + 865, 865, 865, 865, 865, 865, 865, 865, 866, 866, + 867, 867, 868, 868, 868, 868, 868, 868, 868, 868, + 869, 869, 870, 870, 871, 871, 872, 872, 873, 873, + 874, 874, 875, 875, 876, 876, 876, 877, 877, 878, + 878, 879, 879, 879, 879, 879, 879, 879, 879, 879, + 879, 879, 879, 879, 879, 879, 880, 880, 881, 882, + 882, 883, 883, 883, 883, 883, 883, 884, 885, 886, + 886, 886, 887, 887, 887, 887, 888, 889, 889, 890, + 891, 891, 892, 892, 893, 893, 894, 895, 895, 550, + 550, 550, 550, 896, 896, 897, 897, 898, 898, 898, + 899, 899, 899, 899, 899, 900, 900, 901, 901, 902, + 902, 903, 903, 904, 904, 905, 905, 905, 905, 906, + 906, 907, 907, 908, 908, 909, 909, 910, 910, 911, + 912, 912, 913, 913, 914, 914, 914, 915, 916, 916, + 917, 917, 918, 918, 918, 919, 919, 920, 920, 921, + 921, 922, 922, 923, 924, 924, 925, 925, 925, 925, + 925, 925, 925, 925, 925, 925, 925, 925, 925, 925, + 926, 927, 927, 927, 928, 928, 928, 929, 929, 929, + 930, 930, 931, 931, 932, 932, 933, 934, 934, 935, + 936, 936, 937, 937, 937, 937, 937, 937, 938, 938, + 938, 939, 939, 940, 940, 940, 940, 941, 941, 942, + 943, 943, 944, 944, 945, 945, 946, 946, 947, 947, + 948, 948, 948, 948, 948, 948, 949, 949, 950, 950, + 951, 951, 952, 952, 953, 953, 953, 953, 953, 953, + 953, 953, 953, 953, 954, 954, 955, 956, 956, 956, + 956, 957, 957, 958, 958, 958, 959, 959, 959, 959, + 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, + 959, 959, 959, 959, 959, 959, 959, 959, 959, 959, + 959, 959, 959, 959, 959, 959, 959, 960, 960, 960, + 961, 961, 962, 962, 963, 963, 964, 964, 964, 964, + 965, 966, 966, 967, 967, 967, 967, 967, 968, 968, + 968, 968, 969, 969, 970, 971, 971, 971, 971, 971, + 971, 971, 972, 972, 973, 973, 973, 973, 974, 974, 975, 975, 976, 976, 976, 977, 977, 977, 977, 977, - 977, 977, 977, 977, 977, 977, 977, 977, 977, 977, - 977, 977, 977, 977, 977, 977, 977, 977, 977, 977, - 977, 977, 977, 977, 977, 977, 978, 978, 978, 979, - 979, 980, 980, 981, 981, 982, 982, 982, 982, 983, - 984, 984, 985, 985, 985, 985, 985, 986, 986, 986, - 986, 987, 987, 988, 989, 989, 989, 989, 989, 989, - 989, 990, 990, 991, 991, 991, 991, 992, 992, 993, - 993, 994, 994, 994, 995, 995, 995, 995, 995, 996, - 996, 996, 996, 996, 997, 997, 998, 998, 999, 999, - 1000, 1000, 1001, 1001, 1001, 1002, 1002, 1003, 1003, 1004, - 1004, 1005, 1005, 1005, 1006, 1006, 1006, 1007, 1007, 1008, - 1008, 1009, 1009, 1009, 1009, 1009, 1010, 1010, 1011, 1011, - 1011, 1012, 1012, 1012, 1012, 1012, 1012, 1012, 1012, 1013, - 1013, 1014, 1014, 1015, 1015, 1016, 1016, 1017, 1018, 1018, - 1018, 1018, 1018, 1019, 1019, 1019, 1019, 1020, 1020, 1020, - 1021, 1021, 1021, 1022, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, - 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, - 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, - 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, - 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, - 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, 1024, - 1024, 1024, 1024, 1024, 1025, 1025, 1025, 1025, 1025, 1025, - 1025, 1025, 1025, 1025, 1025, 1025, 1025, 1025, 1025, 1025, - 1025, 1025, 1025, 1025, 1025, 1025, 1025, 1025, 1025, 1025, - 1025, 1025, 1025, 1026, 1026, 1026, 1026, 1026, 1026, 1026, - 1026, 1026, 1026, 1026, 1026, 1026, 1026, 1026, 1026, 1026, - 1026, 1026, 1026, 1026, 1026, 1026, 1026, 1026, 1026, 1026, - 1026, 1026, 1026, 1026, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1027, - 1027, 1027, 1027, 1027, 1027, 1027, 1027, 1028, 1028, 1028, - 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, - 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, - 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, 1028, - 1028, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, - 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, - 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, - 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, - 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, - 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, - 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, 1029, - 1029, 1029, 1029, 1029, 1029 + 978, 978, 978, 978, 978, 979, 979, 980, 980, 981, + 981, 982, 982, 983, 983, 983, 984, 984, 985, 985, + 986, 986, 987, 987, 988, 988, 988, 989, 989, 990, + 990, 991, 991, 991, 991, 991, 992, 992, 993, 993, + 993, 994, 994, 994, 994, 994, 994, 994, 994, 995, + 995, 996, 996, 997, 997, 998, 998, 999, 1000, 1000, + 1000, 1000, 1000, 1001, 1001, 1001, 1001, 1002, 1002, 1002, + 1003, 1003, 1003, 1004, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, + 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1005, 1006, 1006, + 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, + 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, + 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, + 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, + 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, 1006, + 1006, 1006, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, + 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, + 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, 1007, + 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, + 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, + 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, 1009, + 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, + 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, + 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, 1010, + 1010, 1010, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, + 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, + 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, + 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, + 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, + 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, + 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1011, + 1011, 1011, 1011, 1011, 1011, 1011, 1011 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ @@ -3393,154 +3356,151 @@ static const yytype_uint8 yyr2[] = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 4, 6, 4, 6, 4, 6, 4, 6, 1, 2, 3, 2, 1, - 3, 2, 3, 1, 3, 1, 2, 2, 1, 2, - 2, 2, 2, 5, 3, 6, 6, 3, 6, 3, - 4, 6, 6, 6, 5, 5, 6, 9, 4, 5, - 7, 6, 4, 8, 4, 2, 4, 3, 6, 4, - 2, 2, 2, 2, 1, 2, 0, 1, 2, 2, - 2, 1, 3, 4, 2, 1, 0, 2, 3, 2, - 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 1, 1, 1, 1, 1, 6, 6, 8, - 6, 8, 6, 8, 6, 8, 8, 10, 8, 10, - 1, 0, 9, 1, 4, 4, 7, 2, 1, 3, - 2, 2, 0, 4, 3, 0, 1, 0, 2, 3, - 5, 2, 2, 0, 8, 5, 0, 5, 5, 7, - 2, 0, 1, 1, 1, 3, 2, 0, 1, 0, - 1, 3, 1, 3, 1, 2, 1, 3, 2, 6, - 8, 5, 1, 0, 1, 3, 2, 4, 5, 5, - 8, 7, 1, 0, 8, 11, 10, 0, 1, 0, - 1, 1, 0, 2, 1, 2, 1, 3, 4, 3, - 9, 12, 1, 3, 1, 3, 3, 0, 4, 6, - 1, 2, 1, 1, 0, 1, 2, 2, 1, 2, - 2, 1, 2, 3, 2, 2, 2, 2, 3, 3, - 3, 1, 3, 1, 0, 1, 2, 2, 5, 7, - 0, 2, 2, 3, 3, 2, 2, 2, 1, 1, - 0, 2, 2, 0, 2, 9, 12, 11, 0, 2, - 1, 1, 1, 1, 1, 1, 3, 0, 1, 2, - 1, 1, 2, 2, 3, 1, 1, 2, 2, 1, - 2, 3, 5, 3, 2, 5, 1, 1, 1, 0, - 5, 7, 5, 2, 3, 1, 1, 2, 2, 0, - 3, 4, 4, 0, 3, 2, 0, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, - 1, 2, 2, 2, 2, 2, 2, 0, 3, 3, - 3, 0, 1, 2, 1, 2, 2, 2, 2, 2, - 3, 2, 2, 1, 3, 1, 1, 1, 1, 3, - 1, 2, 0, 1, 2, 0, 1, 3, 0, 2, - 0, 3, 3, 1, 5, 3, 1, 3, 1, 2, - 1, 4, 5, 5, 6, 3, 7, 4, 11, 1, - 3, 2, 2, 2, 0, 3, 1, 1, 2, 2, - 2, 2, 1, 0, 1, 2, 6, 4, 6, 4, - 6, 8, 1, 1, 1, 1, 2, 1, 2, 1, - 2, 1, 1, 1, 1, 3, 3, 3, 3, 1, - 2, 2, 1, 3, 1, 1, 1, 3, 1, 1, - 0, 1, 1, 1, 5, 8, 7, 5, 8, 7, - 4, 4, 1, 3, 1, 1, 3, 1, 3, 1, - 1, 2, 3, 8, 11, 9, 7, 0, 3, 3, - 1, 1, 3, 0, 1, 3, 1, 0, 1, 0, - 1, 0, 1, 3, 1, 1, 1, 1, 3, 1, - 1, 0, 2, 2, 0, 2, 0, 1, 0, 1, - 1, 1, 3, 3, 1, 1, 3, 3, 3, 3, - 3, 3, 4, 3, 2, 1, 1, 1, 1, 3, - 1, 1, 3, 1, 1, 3, 3, 3, 1, 2, - 4, 4, 2, 3, 5, 5, 1, 1, 3, 0, - 11, 11, 10, 12, 1, 2, 5, 4, 4, 4, - 4, 7, 5, 4, 7, 6, 9, 9, 4, 1, - 1, 1, 1, 1, 1, 1, 5, 1, 1, 3, - 1, 2, 2, 2, 3, 1, 3, 8, 5, 0, - 1, 2, 1, 3, 1, 2, 0, 2, 0, 3, - 3, 4, 4, 4, 4, 3, 2, 1, 1, 0, - 1, 1, 0, 2, 1, 5, 1, 0, 2, 2, - 0, 1, 0, 3, 5, 1, 3, 4, 3, 1, - 1, 0, 2, 2, 0, 2, 2, 1, 1, 1, - 0, 2, 4, 5, 4, 2, 3, 1, 1, 1, - 2, 2, 1, 2, 3, 0, 1, 0, 5, 1, - 4, 6, 2, 1, 0, 4, 0, 1, 1, 3, - 4, 0, 1, 1, 2, 2, 2, 1, 1, 2, - 2, 1, 1, 1, 1, 1, 1, 3, 3, 0, - 1, 3, 1, 2, 1, 1, 1, 1, 1, 2, - 4, 4, 5, 1, 1, 2, 0, 2, 0, 1, - 3, 1, 0, 1, 2, 3, 2, 4, 2, 3, - 2, 0, 1, 2, 0, 4, 5, 1, 2, 2, - 0, 1, 3, 1, 2, 2, 4, 4, 3, 3, - 3, 3, 3, 3, 3, 1, 4, 4, 9, 9, - 3, 0, 2, 2, 0, 5, 3, 1, 1, 3, - 5, 3, 1, 2, 1, 3, 5, 1, 2, 3, - 4, 5, 4, 5, 4, 6, 5, 4, 5, 5, - 5, 2, 4, 1, 1, 0, 1, 4, 5, 4, - 0, 2, 2, 2, 1, 1, 1, 1, 0, 4, - 2, 1, 2, 2, 4, 2, 6, 2, 1, 3, - 4, 0, 2, 0, 2, 0, 1, 3, 3, 2, - 0, 2, 4, 1, 1, 1, 0, 2, 3, 5, - 6, 2, 3, 1, 5, 5, 5, 3, 3, 3, - 4, 0, 1, 1, 1, 1, 1, 2, 4, 1, - 1, 1, 1, 2, 3, 0, 1, 1, 1, 1, - 1, 2, 2, 2, 2, 2, 1, 3, 0, 1, - 1, 1, 1, 5, 2, 1, 1, 1, 1, 4, - 1, 2, 2, 1, 3, 3, 2, 1, 0, 5, - 2, 5, 2, 1, 3, 3, 0, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 3, 2, 3, 1, 3, 2, 5, 3, 6, 4, + 6, 6, 6, 5, 5, 6, 9, 4, 5, 7, + 6, 4, 8, 4, 2, 4, 3, 6, 4, 2, + 2, 2, 2, 1, 2, 0, 1, 2, 2, 2, + 1, 3, 4, 2, 1, 0, 2, 3, 2, 3, + 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, + 2, 1, 1, 1, 1, 1, 6, 6, 8, 6, + 8, 6, 8, 6, 8, 8, 10, 8, 10, 1, + 0, 9, 1, 4, 4, 7, 2, 1, 3, 2, + 2, 0, 4, 3, 0, 1, 0, 2, 3, 5, + 2, 2, 0, 8, 5, 0, 5, 5, 7, 2, + 0, 1, 1, 1, 3, 2, 0, 1, 0, 1, + 3, 1, 3, 1, 2, 1, 3, 2, 6, 8, + 5, 1, 0, 1, 3, 2, 4, 5, 5, 8, + 7, 1, 0, 8, 11, 10, 0, 1, 0, 1, + 1, 0, 2, 4, 3, 9, 12, 1, 3, 1, + 3, 3, 0, 4, 6, 1, 2, 1, 1, 0, + 1, 2, 2, 1, 2, 2, 1, 2, 3, 2, + 2, 2, 2, 3, 3, 3, 1, 3, 1, 0, + 1, 2, 2, 5, 7, 0, 2, 2, 3, 3, + 2, 2, 2, 1, 1, 0, 2, 2, 0, 2, + 9, 12, 11, 0, 2, 1, 1, 1, 1, 1, + 1, 3, 0, 1, 2, 1, 1, 2, 2, 3, + 1, 1, 2, 2, 1, 2, 3, 5, 3, 2, + 5, 1, 1, 1, 0, 5, 7, 5, 2, 3, + 1, 1, 2, 2, 0, 3, 4, 4, 0, 3, + 2, 0, 3, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 3, 3, 1, 2, 2, 2, 2, + 2, 2, 0, 3, 3, 3, 0, 1, 2, 1, + 2, 2, 2, 2, 3, 4, 1, 3, 1, 1, + 1, 1, 3, 1, 2, 0, 1, 2, 0, 1, + 3, 0, 2, 0, 3, 3, 1, 5, 3, 1, + 3, 1, 2, 1, 4, 5, 5, 6, 3, 7, + 4, 11, 1, 3, 2, 2, 2, 0, 3, 1, + 1, 2, 2, 2, 2, 1, 0, 1, 2, 6, + 4, 6, 4, 6, 8, 1, 1, 1, 1, 2, + 1, 2, 1, 2, 1, 1, 1, 1, 3, 3, + 3, 3, 1, 2, 2, 1, 3, 1, 1, 1, + 3, 1, 1, 0, 1, 1, 1, 5, 8, 7, + 5, 8, 7, 4, 4, 1, 3, 1, 1, 3, + 1, 3, 1, 1, 2, 3, 8, 11, 9, 7, + 0, 3, 3, 1, 1, 3, 0, 1, 3, 1, + 0, 1, 0, 1, 0, 1, 3, 1, 1, 1, + 1, 3, 1, 1, 0, 2, 2, 0, 2, 0, + 1, 0, 1, 1, 1, 3, 3, 1, 1, 3, + 3, 3, 3, 3, 3, 4, 3, 2, 1, 1, + 1, 1, 3, 1, 1, 3, 1, 1, 3, 3, + 3, 1, 2, 4, 4, 2, 3, 5, 5, 1, + 1, 3, 0, 11, 11, 10, 12, 1, 2, 5, + 4, 4, 4, 4, 7, 5, 4, 7, 6, 9, + 9, 4, 1, 1, 1, 1, 1, 1, 1, 5, + 1, 1, 3, 1, 2, 2, 2, 3, 1, 3, + 7, 1, 2, 0, 2, 0, 3, 3, 4, 4, + 4, 4, 3, 2, 1, 1, 0, 1, 1, 0, + 2, 1, 5, 1, 0, 2, 2, 0, 1, 0, + 3, 5, 1, 3, 4, 3, 1, 1, 0, 2, + 2, 0, 2, 2, 1, 1, 1, 0, 2, 4, + 5, 4, 2, 3, 1, 1, 1, 2, 2, 1, + 2, 3, 0, 1, 0, 5, 1, 4, 6, 2, + 1, 0, 4, 0, 1, 1, 2, 2, 2, 1, + 1, 2, 2, 1, 1, 1, 1, 1, 1, 3, + 3, 0, 1, 3, 1, 2, 1, 1, 1, 1, + 1, 2, 4, 4, 5, 1, 1, 2, 0, 2, + 0, 1, 3, 1, 0, 1, 2, 3, 2, 4, + 2, 3, 2, 0, 1, 2, 0, 4, 5, 1, + 2, 2, 0, 1, 3, 1, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 1, 4, 4, + 9, 9, 3, 0, 2, 2, 0, 5, 3, 1, + 1, 3, 5, 3, 1, 2, 1, 3, 5, 1, + 2, 3, 4, 5, 4, 5, 4, 6, 5, 4, + 5, 5, 5, 2, 4, 1, 1, 0, 1, 4, + 5, 4, 0, 2, 2, 2, 1, 1, 1, 1, + 0, 4, 2, 1, 2, 2, 4, 2, 6, 2, + 1, 3, 4, 0, 2, 0, 2, 0, 1, 3, + 3, 2, 0, 2, 4, 1, 1, 1, 0, 2, + 3, 5, 6, 2, 3, 1, 5, 5, 5, 3, + 3, 3, 4, 0, 1, 1, 1, 1, 1, 2, + 4, 1, 1, 1, 1, 2, 3, 0, 1, 1, + 1, 1, 1, 2, 2, 2, 2, 2, 1, 3, + 0, 1, 1, 1, 1, 5, 2, 1, 1, 1, + 1, 4, 1, 2, 2, 1, 3, 3, 2, 1, + 0, 5, 2, 5, 2, 1, 3, 3, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, - 3, 3, 3, 0, 1, 3, 3, 5, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 2, 2, 3, 3, 2, - 2, 3, 3, 5, 4, 6, 3, 5, 4, 6, - 4, 6, 5, 7, 3, 2, 4, 3, 2, 3, - 3, 3, 3, 4, 3, 4, 3, 4, 5, 6, - 6, 7, 6, 7, 6, 7, 3, 4, 4, 6, - 1, 4, 4, 5, 4, 6, 1, 3, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 2, 2, 5, 6, 6, - 7, 1, 2, 1, 1, 1, 2, 2, 4, 3, - 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, - 1, 1, 2, 4, 2, 3, 3, 4, 3, 5, - 6, 7, 9, 7, 7, 5, 1, 1, 1, 5, - 6, 6, 4, 4, 4, 4, 6, 5, 5, 5, - 4, 6, 4, 1, 7, 9, 5, 0, 5, 4, - 0, 1, 0, 2, 0, 1, 3, 3, 2, 2, - 0, 6, 1, 0, 3, 0, 3, 3, 3, 0, - 1, 4, 2, 2, 2, 2, 2, 3, 2, 2, - 3, 0, 4, 3, 1, 5, 3, 1, 3, 1, - 2, 3, 1, 3, 1, 2, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, - 4, 1, 4, 1, 2, 1, 2, 1, 2, 1, - 3, 1, 3, 1, 2, 1, 3, 1, 2, 1, - 0, 1, 3, 1, 3, 3, 1, 3, 3, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, + 3, 3, 3, 3, 3, 0, 1, 3, 3, 5, + 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 2, 2, 3, + 3, 2, 2, 3, 3, 5, 4, 6, 3, 5, + 4, 6, 4, 6, 5, 7, 3, 2, 4, 3, + 2, 3, 3, 3, 3, 4, 3, 4, 3, 4, + 5, 6, 6, 7, 6, 7, 6, 7, 3, 4, + 4, 6, 1, 5, 4, 4, 6, 1, 3, 2, + 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 2, 2, 5, 6, + 6, 7, 1, 2, 1, 1, 1, 2, 2, 4, + 3, 1, 1, 1, 1, 2, 1, 1, 1, 1, + 1, 1, 1, 2, 4, 2, 3, 3, 4, 3, + 5, 6, 7, 9, 7, 7, 5, 1, 1, 1, + 5, 6, 6, 4, 4, 4, 4, 6, 5, 5, + 5, 4, 6, 4, 1, 7, 9, 5, 0, 5, + 4, 0, 1, 0, 2, 0, 1, 3, 3, 2, + 2, 0, 6, 1, 0, 3, 0, 3, 3, 3, + 0, 1, 4, 2, 2, 2, 2, 2, 3, 2, + 2, 3, 0, 4, 3, 1, 5, 3, 1, 3, + 1, 2, 3, 1, 3, 1, 2, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 4, 3, 2, 3, 0, - 3, 3, 2, 2, 1, 0, 2, 2, 3, 2, - 1, 1, 3, 1, 1, 5, 1, 2, 4, 2, - 0, 1, 0, 1, 3, 1, 1, 2, 3, 5, - 7, 7, 1, 0, 0, 2, 0, 2, 3, 3, - 3, 5, 7, 7, 0, 2, 1, 0, 1, 0, - 1, 3, 1, 2, 3, 2, 1, 3, 4, 2, - 1, 3, 1, 3, 1, 2, 1, 0, 3, 1, - 3, 1, 2, 4, 2, 0, 3, 1, 3, 1, - 2, 4, 2, 0, 1, 3, 1, 3, 1, 2, - 1, 3, 1, 1, 2, 1, 1, 2, 1, 1, - 2, 7, 2, 5, 3, 3, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, + 1, 4, 1, 4, 1, 2, 1, 2, 1, 2, + 1, 3, 1, 3, 1, 2, 1, 3, 1, 2, + 1, 0, 1, 3, 1, 3, 3, 1, 3, 3, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 4, 3, 2, 3, + 0, 3, 3, 2, 2, 1, 0, 2, 2, 3, + 2, 1, 1, 3, 1, 1, 5, 1, 2, 4, + 2, 0, 1, 0, 1, 3, 1, 1, 2, 3, + 5, 7, 7, 1, 0, 0, 2, 0, 2, 3, + 3, 3, 5, 7, 7, 0, 2, 1, 0, 1, + 0, 1, 3, 1, 2, 3, 2, 1, 3, 4, + 2, 1, 3, 1, 3, 1, 2, 1, 0, 3, + 1, 3, 1, 2, 4, 2, 0, 3, 1, 3, + 1, 2, 4, 2, 0, 1, 3, 1, 3, 1, + 2, 1, 3, 1, 1, 2, 1, 1, 2, 1, + 1, 2, 7, 2, 5, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 3, 3, 0, 1, 1, 1, 5, 3, - 0, 1, 1, 1, 1, 1, 1, 4, 7, 6, - 2, 0, 1, 1, 1, 1, 13, 16, 1, 2, - 0, 1, 0, 1, 0, 2, 0, 1, 0, 6, - 8, 6, 8, 6, 8, 3, 2, 1, 0, 6, - 6, 1, 1, 1, 1, 1, 1, 2, 1, 1, - 1, 1, 1, 4, 6, 3, 2, 4, 3, 5, - 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, + 1, 2, 2, 3, 3, 0, 1, 1, 1, 5, + 3, 0, 1, 1, 1, 1, 1, 1, 4, 7, + 6, 2, 0, 1, 1, 1, 1, 13, 16, 1, + 2, 0, 1, 0, 1, 0, 2, 0, 1, 0, + 6, 8, 6, 8, 6, 8, 3, 2, 1, 0, + 6, 6, 1, 1, 1, 1, 1, 1, 2, 1, + 1, 1, 1, 1, 4, 6, 3, 2, 4, 3, + 5, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 3, 1, 1, 1, 1, 1, 1, 2, - 1, 1, 2, 3, 3, 3, 3, 1, 3, 3, - 2, 3, 3, 1, 1, 1, 3, 5, 1, 1, - 1, 1, 3, 2, 4, 6, 6, 0, 1, 1, - 1, 0, 2, 2, 4, 6, 5, 4, 6, 1, - 1, 1, 1, 1, 1, 0, 1, 3, 1, 0, - 7, 3, 1, 2, 3, 2, 0, 2, 0, 2, - 4, 5, 8, 7, 2, 3, 5, 1, 0, 2, + 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, + 2, 1, 1, 2, 3, 3, 3, 3, 1, 3, + 3, 2, 3, 3, 1, 1, 1, 3, 5, 1, + 1, 1, 1, 3, 2, 4, 6, 6, 0, 1, + 1, 1, 0, 2, 2, 4, 6, 5, 4, 6, + 1, 1, 1, 1, 1, 1, 0, 1, 3, 1, + 0, 7, 3, 1, 2, 3, 2, 0, 2, 0, + 2, 4, 5, 8, 2, 3, 5, 1, 0, 2, 0, 2, 3, 3, 3, 3, 1, 1, 1, 2, 3, 2, 2, 2, 2, 3, 4, 3, 1, 1, 1, 1, 1, 1, 0, 1, 3, 2, 9, 12, @@ -3607,8 +3567,7 @@ static const yytype_uint8 yyr2[] = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1, 1, 1 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state @@ -3616,9360 +3575,9287 @@ static const yytype_uint8 yyr2[] = means the default is an error. */ static const yytype_uint16 yydefact[] = { - 167, 280, 0, 1464, 1463, 1538, 280, 0, 1398, 0, - 280, 518, 423, 0, 1560, 1559, 0, 219, 280, 0, - 167, 0, 1498, 0, 0, 0, 581, 584, 582, 0, - 0, 0, 280, 627, 0, 1561, 280, 0, 0, 619, - 583, 0, 1515, 0, 0, 0, 0, 0, 2, 4, + 156, 265, 0, 1435, 1434, 1508, 265, 0, 1369, 0, + 265, 501, 406, 0, 1530, 1529, 0, 208, 265, 0, + 156, 0, 1469, 0, 0, 0, 564, 567, 565, 0, + 0, 0, 265, 604, 0, 1531, 265, 0, 0, 596, + 566, 0, 1486, 0, 0, 0, 0, 0, 2, 4, 7, 21, 35, 31, 0, 20, 33, 18, 17, 38, 26, 6, 24, 37, 40, 19, 25, 15, 39, 13, - 36, 557, 543, 632, 556, 0, 0, 166, 737, 564, - 34, 16, 30, 5, 11, 12, 28, 29, 27, 1421, + 36, 540, 526, 609, 539, 0, 0, 155, 709, 547, + 34, 16, 30, 5, 11, 12, 28, 29, 27, 1392, 43, 32, 0, 41, 22, 8, 9, 23, 42, 44, - 1562, 1558, 10, 45, 14, 279, 278, 272, 0, 0, - 0, 0, 0, 1537, 0, 0, 0, 283, 123, 1584, - 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, - 1964, 1595, 1596, 1965, 1597, 1598, 1966, 1599, 1600, 1601, - 1910, 1911, 1967, 1912, 1913, 1602, 1603, 1604, 1605, 1606, - 1607, 1608, 1609, 1610, 1611, 1914, 1915, 1612, 1613, 1614, - 1615, 1616, 1916, 1968, 1917, 1617, 1618, 1619, 1620, 1621, - 1969, 1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629, 1630, - 1970, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, - 1640, 1918, 1641, 1642, 1919, 1643, 1644, 1645, 1646, 1647, - 1648, 1649, 1650, 1651, 1652, 1653, 1654, 1655, 1656, 1657, - 1658, 1659, 1660, 1661, 1662, 1663, 1664, 1665, 1666, 1667, - 1668, 1669, 1920, 1670, 1671, 1672, 1673, 1674, 1675, 1921, - 1676, 1677, 1678, 1922, 1679, 1680, 1681, 1971, 1972, 1682, - 1683, 1923, 1974, 1684, 1685, 1686, 1924, 1925, 1687, 1688, - 1689, 1690, 1691, 1692, 1693, 1694, 1695, 1975, 1696, 1697, - 1698, 1699, 1700, 1701, 1702, 1703, 1704, 1705, 1706, 1707, - 1976, 1926, 1708, 1709, 1710, 1711, 1712, 1927, 1928, 1929, - 1713, 1977, 1978, 1714, 1979, 1715, 1716, 1717, 1718, 1719, - 1720, 1721, 1980, 1722, 1981, 1723, 1724, 1725, 1726, 1727, - 1728, 1729, 1730, 1930, 1731, 1732, 1733, 1734, 1735, 1736, - 1737, 1738, 1739, 1740, 1741, 1742, 1743, 1744, 1745, 1746, - 1747, 1748, 1749, 1750, 1931, 1983, 1932, 1751, 1752, 1753, - 1933, 1754, 1755, 1984, 1756, 1934, 1757, 1935, 1758, 1759, - 1760, 1761, 1762, 1763, 1764, 1765, 1766, 1767, 1936, 1985, - 1768, 1986, 1937, 1769, 1770, 1771, 1772, 1773, 1774, 1775, - 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1938, 1987, 1783, - 1784, 1939, 1785, 1786, 1787, 1788, 1789, 1790, 1791, 1792, - 1793, 1794, 1795, 1796, 1797, 1798, 1940, 1799, 1800, 1801, - 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1810, 1811, - 1812, 1813, 1814, 1815, 1816, 1817, 1988, 1818, 1819, 1820, - 1941, 1821, 1822, 1823, 1824, 1825, 1826, 1827, 1828, 1829, - 1830, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, - 1942, 1840, 1841, 1989, 1842, 1843, 1943, 1844, 1845, 1846, - 1847, 1848, 1849, 1850, 1851, 1852, 1853, 1854, 1855, 1856, - 1857, 1944, 1858, 1945, 1859, 1860, 1861, 1991, 1862, 1863, - 1864, 1865, 1866, 1867, 1946, 1947, 1868, 1869, 1948, 1870, - 1949, 1871, 1872, 1950, 1873, 1874, 1875, 1876, 1877, 1878, - 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, - 1889, 1951, 1952, 1890, 1891, 1992, 1892, 1893, 1894, 1895, - 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, - 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, - 1963, 1906, 1907, 1908, 1909, 0, 1567, 0, 1323, 124, - 125, 1345, 123, 1923, 1930, 1944, 1397, 1396, 124, 0, - 275, 517, 0, 0, 0, 0, 0, 0, 221, 0, - 417, 416, 0, 1387, 422, 0, 0, 0, 127, 119, - 1785, 126, 1322, 117, 133, 2141, 2142, 2143, 2144, 2024, - 2145, 2146, 2147, 2148, 2025, 2149, 2026, 2027, 2028, 2029, - 2030, 2031, 2032, 2150, 2151, 2152, 2034, 2033, 2153, 2035, - 2154, 2036, 2155, 2037, 2038, 2156, 2157, 2039, 1637, 2040, - 2041, 2158, 2159, 2160, 2161, 2162, 2163, 2164, 2165, 2166, - 2042, 2043, 2167, 2168, 2044, 2169, 2170, 2045, 2171, 2046, - 2047, 2048, 2172, 2049, 2050, 2173, 2051, 2174, 2175, 2052, - 2053, 2056, 2054, 2176, 2055, 2177, 2057, 2058, 2059, 2178, - 2179, 2060, 2061, 2180, 2062, 2063, 2064, 2065, 2066, 2181, - 2067, 2182, 2068, 2069, 2183, 2184, 2185, 2186, 2187, 2071, - 2070, 2072, 2073, 2188, 2189, 2190, 2191, 2074, 2075, 2076, - 2192, 2193, 2077, 2194, 2195, 2078, 2079, 2196, 2080, 2081, - 2197, 2082, 2083, 2198, 2084, 2085, 2199, 2200, 2201, 2086, - 2202, 2087, 2088, 2203, 2204, 2089, 2090, 2205, 2091, 2206, - 2207, 2092, 2208, 2209, 2093, 2094, 2210, 2095, 2211, 2212, - 2213, 2214, 2096, 2097, 2098, 2099, 2100, 2101, 2102, 2103, - 2104, 2105, 2106, 1534, 135, 134, 136, 0, 441, 442, - 0, 452, 0, 434, 439, 435, 0, 461, 454, 462, - 443, 433, 455, 444, 432, 220, 0, 463, 449, 437, - 0, 0, 0, 0, 276, 237, 423, 0, 167, 0, - 1427, 1437, 1446, 1442, 1436, 1444, 1434, 1450, 1440, 1426, - 1448, 1435, 1439, 1432, 1449, 1430, 1447, 1445, 1433, 1441, - 1425, 1429, 1416, 1421, 1453, 1443, 1451, 1438, 1452, 1454, - 1428, 1455, 1431, 0, 1398, 0, 1916, 1968, 1921, 0, - 1934, 0, 1937, 1938, 1821, 1945, 1948, 1949, 1950, 1951, - 0, 811, 126, 121, 795, 0, 559, 0, 741, 755, - 795, 800, 1087, 823, 1088, 0, 128, 1500, 1499, 1493, - 206, 1360, 1547, 1684, 1725, 1838, 1946, 1868, 1890, 1565, - 1548, 1541, 1546, 277, 626, 624, 0, 1279, 1684, 1725, - 1825, 1838, 1946, 1890, 1472, 1477, 0, 283, 1553, 126, - 121, 1552, 0, 565, 618, 0, 284, 1514, 0, 1519, - 0, 1801, 592, 595, 1354, 593, 557, 0, 0, 1, - 167, 0, 173, 0, 622, 622, 0, 622, 0, 549, - 0, 0, 557, 552, 556, 738, 1420, 1529, 0, 1564, - 1946, 1868, 1554, 1551, 1694, 0, 0, 1694, 0, 1694, - 0, 1694, 0, 0, 1538, 1540, 0, 273, 1263, 0, - 1324, 129, 0, 0, 1409, 1405, 1410, 1406, 1411, 1404, - 1403, 1412, 1408, 0, 0, 0, 388, 421, 420, 419, - 418, 423, 1694, 1371, 0, 217, 479, 480, 0, 0, - 0, 0, 0, 1382, 120, 118, 1694, 1535, 450, 451, - 0, 440, 436, 438, 0, 0, 1694, 1349, 460, 456, - 1694, 460, 1316, 1694, 0, 0, 229, 0, 416, 1418, - 1456, 2093, 1470, 0, 1471, 1461, 1424, 1457, 1458, 167, - 0, 516, 1395, 0, 0, 0, 1209, 795, 800, 0, - 0, 813, 0, 1229, 0, 1235, 0, 0, 0, 795, - 564, 0, 755, 812, 122, 745, 0, 793, 794, 674, - 674, 627, 0, 608, 0, 674, 681, 674, 805, 0, - 0, 808, 806, 0, 808, 0, 0, 0, 808, 804, - 764, 0, 681, 0, 793, 796, 674, 0, 815, 1415, - 0, 0, 0, 0, 1544, 1542, 1543, 1549, 0, 1545, - 0, 0, 1326, 1328, 1329, 1177, 1339, 1063, 0, 1911, - 1912, 1913, 1252, 1914, 1915, 1917, 1918, 1919, 1020, 1657, - 1920, 1337, 1922, 1924, 1925, 1927, 1928, 1929, 1930, 1931, - 1932, 0, 1338, 1935, 1763, 1940, 1941, 1943, 1946, 1947, - 1336, 0, 1952, 0, 0, 0, 1297, 1200, 0, 1062, - 0, 0, 0, 1256, 1264, 1055, 0, 0, 859, 860, - 881, 882, 861, 887, 888, 890, 862, 0, 1286, 954, - 1051, 1274, 1065, 1060, 1070, 1066, 1067, 1107, 1068, 1086, - 1071, 1144, 1061, 0, 1069, 1053, 1282, 608, 1280, 0, - 1054, 1325, 608, 1278, 1475, 1473, 1480, 1474, 0, 1476, - 0, 0, 0, 274, 122, 1522, 1521, 1513, 1511, 1512, - 1510, 1509, 1516, 0, 1518, 1421, 1256, 1195, 1197, 0, - 594, 0, 0, 599, 546, 545, 547, 3, 0, 0, - 0, 1674, 0, 620, 621, 0, 0, 0, 0, 0, - 0, 0, 0, 722, 647, 648, 650, 719, 723, 731, - 0, 0, 0, 0, 0, 553, 0, 1354, 1501, 1563, - 1557, 1555, 0, 0, 0, 151, 151, 0, 0, 0, - 0, 0, 111, 49, 104, 0, 0, 0, 0, 251, - 264, 0, 0, 0, 0, 0, 261, 0, 0, 244, - 51, 238, 240, 0, 151, 0, 47, 0, 0, 0, - 53, 1538, 0, 0, 516, 281, 282, 1262, 0, 131, - 132, 130, 123, 0, 2107, 1964, 1965, 1966, 1967, 1968, - 1917, 1969, 1970, 0, 1971, 1972, 1923, 1974, 1975, 1976, - 1977, 1978, 1979, 1980, 1981, 1930, 1983, 1984, 1985, 1986, - 1987, 1988, 2134, 1989, 1944, 1991, 1950, 2139, 0, 1992, - 1078, 630, 1203, 632, 1201, 1355, 0, 124, 1342, 0, - 1407, 0, 0, 0, 0, 514, 0, 0, 0, 0, - 1367, 0, 1694, 218, 222, 0, 1694, 213, 1694, 388, - 0, 1694, 388, 1694, 0, 1381, 1384, 0, 453, 448, - 446, 445, 447, 1694, 270, 0, 0, 1350, 458, 459, - 0, 427, 0, 0, 429, 0, 0, 234, 0, 232, - 0, 423, 167, 0, 245, 1466, 1467, 1465, 0, 0, - 1460, 1423, 248, 265, 1469, 1459, 1468, 1422, 1417, 0, - 0, 1413, 502, 0, 0, 0, 1210, 930, 929, 911, - 912, 927, 928, 913, 914, 921, 922, 932, 931, 919, - 920, 915, 916, 909, 910, 925, 926, 917, 918, 923, - 924, 907, 908, 1224, 1211, 1212, 1213, 1214, 1215, 1216, - 1217, 1218, 1219, 1220, 1221, 1222, 1223, 0, 0, 754, - 751, 0, 0, 0, 0, 0, 0, 1256, 0, 1026, - 1061, 0, 0, 0, 1195, 1234, 0, 0, 0, 0, - 0, 0, 1195, 1240, 0, 0, 779, 791, 0, 667, - 673, 752, 750, 0, 1279, 742, 0, 825, 755, 753, - 0, 674, 749, 0, 805, 0, 804, 0, 0, 807, - 801, 0, 802, 0, 0, 0, 0, 803, 0, 0, - 0, 0, 0, 674, 0, 791, 0, 748, 822, 1483, - 1491, 207, 0, 1346, 1993, 1994, 1995, 1996, 869, 1997, - 898, 876, 898, 898, 1998, 1999, 2000, 2001, 865, 865, - 878, 2002, 2003, 2004, 2005, 2006, 866, 867, 903, 2007, - 2008, 2009, 2010, 2011, 0, 0, 2012, 898, 2013, 865, - 2014, 2015, 2016, 870, 2017, 833, 2018, 0, 2019, 868, - 834, 2020, 906, 906, 2021, 0, 2022, 893, 2023, 0, - 1206, 843, 851, 852, 853, 854, 879, 880, 855, 885, - 886, 856, 953, 0, 865, 1347, 1348, 167, 1550, 1566, - 0, 1200, 1072, 897, 884, 1251, 0, 892, 891, 0, - 1200, 874, 873, 872, 1057, 0, 871, 1157, 898, 898, - 896, 979, 875, 0, 0, 0, 0, 0, 902, 0, - 900, 0, 980, 958, 959, 0, 0, 1296, 1305, 1195, - 1199, 0, 1055, 1195, 0, 1064, 1074, 0, 1147, 1149, - 0, 0, 0, 1257, 1327, 1056, 0, 1332, 0, 0, - 953, 953, 1285, 1177, 0, 1167, 1170, 0, 0, 1174, - 1175, 1176, 0, 0, 0, 1277, 0, 1185, 1187, 0, - 0, 995, 1183, 0, 998, 0, 0, 0, 0, 1171, - 1172, 1173, 1163, 1164, 1165, 1166, 1168, 1169, 1181, 1162, - 976, 0, 1052, 0, 1110, 0, 975, 1283, 740, 0, - 1330, 740, 1485, 1489, 1490, 1484, 1488, 0, 1479, 1478, - 1481, 1482, 0, 1523, 1507, 0, 1504, 1198, 735, 596, - 1318, 0, 0, 0, 1528, 172, 171, 0, 228, 0, - 569, 568, 641, 633, 635, 641, 0, 567, 0, 695, - 696, 0, 0, 0, 0, 728, 726, 1326, 1339, 683, - 651, 682, 0, 0, 655, 0, 687, 954, 721, 551, - 645, 646, 649, 550, 0, 724, 0, 734, 0, 588, - 590, 573, 587, 585, 570, 578, 722, 650, 0, 1530, - 0, 0, 1494, 1556, 0, 0, 0, 0, 0, 1694, - 0, 0, 836, 72, 68, 95, 338, 150, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 103, 100, 0, - 0, 101, 102, 0, 0, 0, 0, 1346, 249, 250, - 263, 0, 254, 255, 252, 256, 257, 0, 0, 242, - 243, 0, 0, 0, 0, 241, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1540, 1539, 1531, 1258, 1263, - 632, 632, 632, 0, 0, 0, 0, 630, 631, 0, - 0, 0, 0, 0, 501, 386, 396, 0, 0, 0, - 1371, 217, 0, 0, 0, 0, 0, 0, 423, 1374, - 1372, 1370, 1373, 1375, 1663, 201, 0, 0, 0, 0, - 0, 209, 212, 0, 385, 357, 0, 0, 1386, 0, - 0, 474, 472, 475, 464, 477, 467, 0, 1694, 375, - 1383, 0, 1536, 0, 0, 268, 460, 1351, 0, 457, - 460, 1317, 0, 460, 236, 0, 0, 1419, 1462, 246, - 266, 247, 267, 516, 511, 541, 0, 519, 524, 499, - 0, 499, 0, 521, 525, 499, 520, 0, 499, 515, - 0, 1102, 0, 1092, 0, 0, 814, 0, 0, 1093, - 1028, 1029, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1046, 1045, 1094, 818, 0, 821, 0, 0, 1232, 1233, - 0, 1095, 0, 0, 1239, 0, 0, 0, 1100, 0, - 756, 0, 0, 657, 658, 666, 662, 669, 0, 672, - 659, 608, 558, 1684, 1725, 0, 619, 619, 619, 617, - 607, 0, 699, 757, 0, 747, 0, 0, 0, 780, - 0, 0, 782, 784, 0, 0, 787, 0, 763, 762, - 0, 0, 746, 0, 0, 826, 0, 1322, 0, 0, - 208, 0, 0, 0, 851, 0, 0, 0, 841, 837, - 0, 933, 934, 935, 936, 937, 938, 939, 940, 941, - 942, 943, 944, 945, 857, 1359, 0, 863, 1362, 0, - 1363, 1364, 1361, 1358, 1365, 1366, 0, 0, 0, 0, - 1250, 1246, 0, 0, 0, 0, 1152, 1154, 1156, 0, - 895, 894, 1161, 1167, 1170, 1174, 1175, 1176, 1171, 1172, - 1173, 1163, 1164, 1165, 1166, 1168, 1169, 0, 1189, 0, - 1143, 0, 0, 0, 0, 0, 0, 0, 0, 1290, - 1289, 0, 1313, 0, 1075, 1059, 0, 0, 1150, 1076, - 1297, 1287, 1265, 0, 0, 0, 1335, 1334, 955, 964, - 967, 999, 1000, 971, 972, 973, 977, 1357, 1356, 1284, - 0, 1276, 0, 0, 956, 981, 986, 0, 1241, 1244, - 1016, 1243, 0, 1004, 0, 994, 0, 1002, 1006, 982, - 997, 0, 978, 0, 1277, 1186, 1188, 0, 1184, 0, - 968, 969, 970, 960, 961, 962, 963, 965, 966, 974, - 1160, 1158, 1159, 0, 1263, 0, 1275, 0, 0, 1112, - 0, 0, 1001, 1281, 0, 825, 632, 825, 0, 953, - 1524, 1354, 1517, 1354, 1506, 1196, 1319, 1353, 0, 606, - 0, 1526, 158, 162, 0, 1264, 192, 194, 740, 0, - 639, 640, 644, 0, 0, 644, 623, 566, 1941, 1821, - 0, 0, 0, 0, 688, 729, 0, 720, 685, 686, - 0, 684, 1326, 689, 1325, 690, 693, 694, 656, 1314, - 730, 732, 0, 725, 0, 1320, 572, 591, 0, 0, - 0, 0, 0, 555, 554, 736, 1501, 1501, 1503, 1502, - 0, 50, 0, 1694, 74, 0, 0, 0, 0, 0, - 0, 288, 70, 71, 0, 390, 0, 69, 65, 288, - 116, 1694, 460, 1694, 460, 1588, 1658, 1839, 0, 63, - 362, 107, 0, 144, 77, 79, 393, 0, 347, 0, - 0, 97, 112, 137, 0, 0, 52, 239, 253, 258, - 140, 262, 259, 1391, 260, 151, 0, 48, 0, 138, - 0, 1389, 0, 0, 54, 142, 1393, 1540, 516, 0, - 1262, 0, 630, 630, 630, 628, 629, 1079, 0, 1202, - 0, 1204, 1205, 994, 1401, 1400, 1402, 1399, 487, 500, - 0, 387, 0, 513, 490, 491, 501, 1369, 222, 0, - 213, 388, 0, 388, 0, 1371, 0, 0, 203, 199, - 217, 223, 0, 0, 0, 0, 0, 386, 378, 376, - 409, 0, 383, 377, 0, 0, 333, 0, 1582, 0, - 0, 0, 0, 481, 0, 0, 0, 0, 0, 0, - 270, 271, 426, 1352, 428, 0, 430, 235, 233, 1414, - 2062, 507, 1200, 0, 505, 512, 506, 509, 510, 504, - 503, 0, 498, 0, 534, 0, 0, 0, 0, 0, - 0, 0, 0, 1089, 1208, 0, 1227, 1226, 1027, 1034, - 1037, 1041, 1042, 1043, 1228, 0, 0, 0, 1038, 1039, - 1040, 1030, 1031, 1032, 1033, 1035, 1036, 1044, 823, 0, - 0, 817, 1237, 1236, 1230, 1231, 0, 1097, 1098, 1099, - 1238, 0, 0, 792, 661, 663, 660, 0, 0, 825, - 619, 619, 619, 619, 616, 0, 0, 0, 824, 0, - 716, 677, 678, 0, 0, 788, 786, 0, 810, 0, - 783, 0, 789, 0, 774, 0, 781, 830, 797, 0, - 0, 799, 1492, 847, 0, 842, 838, 0, 0, 0, - 848, 0, 0, 0, 0, 0, 0, 0, 1207, 0, - 625, 1073, 0, 0, 0, 1247, 0, 1021, 864, 877, - 0, 1155, 1077, 0, 1178, 1142, 905, 904, 906, 906, - 1022, 0, 1292, 1294, 0, 0, 0, 0, 1304, 0, - 1024, 1255, 0, 1103, 1253, 1196, 1146, 1148, 1305, 1058, - 889, 953, 0, 0, 0, 0, 0, 0, 0, 1005, - 996, 0, 1003, 1007, 0, 0, 0, 990, 0, 0, - 988, 1017, 984, 0, 0, 1018, 1262, 0, 1266, 0, - 0, 1111, 1120, 743, 739, 699, 630, 699, 0, 1486, - 1508, 1505, 0, 604, 0, 0, 1527, 0, 181, 0, - 0, 0, 0, 184, 198, 195, 1526, 0, 0, 634, - 636, 0, 1179, 644, 638, 692, 691, 0, 654, 727, - 652, 0, 733, 0, 589, 0, 575, 0, 766, 0, - 0, 1495, 1496, 0, 0, 0, 337, 0, 0, 0, - 288, 0, 398, 0, 405, 0, 0, 390, 369, 67, - 66, 96, 0, 0, 0, 59, 115, 88, 80, 55, - 94, 0, 0, 99, 0, 92, 109, 110, 108, 113, - 0, 298, 323, 0, 0, 334, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 516, - 1533, 1263, 1259, 1263, 0, 0, 0, 632, 1080, 0, - 486, 540, 537, 538, 536, 244, 397, 0, 0, 0, - 211, 385, 0, 1386, 466, 469, 1368, 423, 0, 204, - 0, 202, 222, 0, 226, 0, 0, 213, 388, 0, - 361, 371, 372, 357, 384, 355, 354, 356, 0, 1583, - 237, 0, 1577, 388, 1385, 0, 0, 482, 473, 0, - 478, 0, 0, 476, 0, 1380, 269, 460, 0, 494, - 535, 542, 522, 527, 0, 533, 529, 528, 523, 531, - 530, 526, 1090, 1101, 1225, 0, 0, 0, 0, 816, - 819, 0, 1096, 1091, 790, 0, 0, 699, 0, 0, - 0, 0, 610, 609, 615, 0, 0, 1114, 0, 680, - 785, 0, 0, 0, 772, 761, 767, 768, 0, 0, - 0, 828, 827, 798, 851, 0, 831, 851, 0, 851, - 0, 849, 0, 858, 946, 947, 948, 949, 950, 951, - 952, 883, 0, 1249, 1245, 1151, 1153, 1190, 901, 899, - 1023, 1295, 1288, 1291, 1195, 1299, 1301, 0, 0, 0, - 0, 1312, 0, 0, 1145, 1313, 1333, 957, 0, 0, - 987, 1242, 1008, 0, 0, 0, 983, 1178, 0, 0, - 0, 0, 0, 992, 0, 1270, 1263, 0, 1269, 0, - 0, 0, 0, 1085, 744, 716, 0, 716, 0, 0, - 600, 602, 605, 167, 1525, 0, 1520, 159, 160, 161, - 0, 0, 0, 176, 153, 0, 0, 193, 181, 169, - 642, 643, 0, 637, 653, 1315, 1321, 574, 0, 1055, - 0, 0, 571, 0, 145, 288, 0, 0, 73, 0, - 407, 349, 399, 382, 364, 0, 0, 0, 289, 0, - 424, 0, 0, 370, 0, 0, 0, 0, 350, 0, - 0, 309, 0, 0, 382, 0, 389, 305, 306, 0, - 58, 89, 0, 85, 0, 114, 0, 0, 0, 0, - 0, 61, 84, 0, 56, 836, 460, 460, 64, 1346, - 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, - 2003, 2118, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, - 2127, 2012, 295, 2013, 1763, 2014, 2015, 2016, 2017, 2018, - 0, 2019, 834, 2020, 2021, 2206, 2022, 2023, 1163, 1164, - 294, 293, 392, 290, 400, 292, 0, 1347, 291, 395, - 348, 0, 0, 141, 1392, 0, 139, 0, 1390, 148, - 146, 143, 1394, 1532, 0, 0, 1083, 1084, 1081, 630, - 0, 0, 0, 516, 493, 0, 0, 0, 1582, 0, - 0, 1694, 0, 200, 0, 0, 225, 224, 214, 0, - 1386, 210, 385, 0, 415, 333, 836, 410, 0, 1582, - 1580, 0, 1386, 1576, 465, 468, 0, 0, 557, 470, - 0, 0, 0, 431, 508, 0, 532, 1047, 0, 0, - 0, 0, 670, 0, 676, 716, 614, 613, 612, 611, - 698, 1632, 1924, 1820, 0, 702, 697, 700, 705, 707, - 706, 708, 704, 715, 0, 718, 679, 809, 1191, 1193, - 0, 0, 0, 0, 773, 775, 0, 777, 0, 829, - 845, 0, 846, 0, 844, 839, 850, 1248, 1293, 1302, - 1303, 1298, 1307, 1309, 0, 0, 0, 954, 1254, 1025, - 1014, 1012, 1009, 0, 1010, 991, 0, 0, 989, 985, - 0, 1019, 0, 0, 1267, 0, 1106, 0, 1109, 1123, - 1119, 1118, 1114, 1080, 1114, 1487, 598, 601, 0, 180, - 157, 183, 182, 0, 1264, 190, 0, 0, 181, 0, - 185, 483, 0, 0, 586, 765, 579, 580, 0, 403, - 75, 0, 382, 0, 288, 366, 365, 368, 363, 367, - 0, 425, 0, 0, 307, 0, 314, 352, 353, 351, - 308, 382, 388, 310, 0, 0, 0, 81, 60, 57, - 62, 82, 0, 0, 83, 86, 830, 835, 98, 91, - 1346, 2127, 2136, 0, 0, 0, 76, 78, 0, 0, - 1261, 1260, 0, 489, 488, 539, 485, 496, 244, 0, - 0, 0, 357, 1579, 0, 0, 0, 385, 205, 0, - 227, 0, 0, 0, 1582, 0, 0, 285, 0, 330, - 0, 230, 1581, 0, 0, 1568, 0, 0, 1378, 1379, - 0, 495, 1048, 0, 1049, 820, 0, 0, 668, 1114, - 0, 0, 0, 709, 703, 0, 1113, 1115, 0, 665, - 1194, 769, 0, 771, 0, 795, 0, 795, 778, 840, - 832, 1300, 1310, 1311, 1306, 1104, 0, 1011, 1015, 1013, - 993, 1263, 1271, 1263, 1268, 1108, 1122, 1125, 718, 1331, - 718, 603, 597, 0, 0, 168, 0, 0, 165, 152, - 170, 1180, 576, 577, 0, 288, 0, 381, 404, 319, - 297, 0, 0, 0, 304, 311, 414, 313, 0, 90, - 106, 0, 0, 394, 149, 147, 1082, 516, 0, 216, - 1386, 333, 1576, 0, 0, 0, 0, 357, 237, 1578, - 346, 339, 340, 341, 342, 343, 344, 345, 360, 359, - 331, 332, 0, 0, 0, 0, 471, 1380, 0, 187, - 196, 0, 187, 1050, 671, 0, 718, 0, 0, 0, - 701, 0, 0, 717, 0, 562, 1192, 0, 760, 758, - 0, 759, 1308, 0, 0, 0, 0, 632, 665, 665, - 154, 0, 155, 191, 0, 0, 0, 388, 406, 380, - 0, 373, 317, 316, 318, 322, 0, 320, 0, 336, - 0, 329, 297, 0, 93, 0, 401, 484, 492, 0, - 287, 1570, 385, 0, 215, 1576, 333, 1582, 1576, 0, - 1573, 0, 0, 0, 0, 189, 1386, 0, 189, 0, - 665, 711, 0, 710, 1117, 1116, 667, 770, 0, 1105, - 1273, 1272, 0, 1129, 561, 560, 0, 0, 0, 0, - 414, 0, 358, 0, 0, 319, 0, 312, 411, 412, - 413, 0, 325, 315, 326, 87, 105, 402, 0, 385, - 1571, 286, 231, 1569, 1574, 1575, 0, 187, 186, 641, - 188, 825, 197, 641, 675, 563, 712, 664, 776, 1124, - 0, 0, 0, 0, 0, 164, 825, 175, 0, 329, - 379, 374, 296, 321, 335, 0, 0, 0, 327, 0, - 328, 1576, 0, 189, 644, 1376, 644, 1910, 1633, 1875, - 0, 1141, 1130, 1141, 1141, 1121, 156, 163, 0, 288, - 301, 0, 300, 0, 391, 324, 1572, 1386, 641, 177, - 178, 0, 1134, 1133, 1132, 1136, 1135, 0, 1128, 1126, - 1127, 825, 408, 299, 303, 302, 825, 644, 0, 0, - 1138, 0, 1139, 174, 1377, 179, 1131, 1137, 1140 + 1532, 1528, 10, 45, 14, 264, 263, 257, 0, 0, + 0, 0, 0, 1507, 0, 0, 268, 112, 1554, 1555, + 1556, 1557, 1558, 1559, 1560, 1561, 1562, 1563, 1564, 1932, + 1565, 1566, 1567, 1568, 1569, 1933, 1570, 1571, 1572, 1878, + 1879, 1934, 1880, 1881, 1573, 1574, 1575, 1576, 1577, 1578, + 1579, 1580, 1581, 1582, 1882, 1883, 1583, 1584, 1585, 1586, + 1587, 1884, 1935, 1885, 1588, 1589, 1590, 1591, 1592, 1936, + 1593, 1594, 1595, 1596, 1597, 1598, 1599, 1600, 1601, 1937, + 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, + 1886, 1612, 1613, 1887, 1614, 1615, 1616, 1617, 1618, 1619, + 1620, 1621, 1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629, + 1630, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, + 1640, 1888, 1641, 1642, 1643, 1644, 1645, 1646, 1889, 1647, + 1648, 1649, 1890, 1650, 1651, 1652, 1938, 1939, 1653, 1654, + 1891, 1941, 1655, 1656, 1892, 1893, 1657, 1658, 1659, 1660, + 1661, 1662, 1663, 1664, 1665, 1942, 1666, 1667, 1668, 1669, + 1670, 1671, 1672, 1673, 1674, 1675, 1676, 1677, 1943, 1894, + 1678, 1679, 1680, 1681, 1682, 1895, 1896, 1897, 1683, 1944, + 1945, 1684, 1946, 1685, 1686, 1687, 1688, 1689, 1690, 1691, + 1947, 1692, 1948, 1693, 1694, 1695, 1696, 1697, 1698, 1699, + 1700, 1898, 1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708, + 1709, 1710, 1711, 1712, 1713, 1714, 1715, 1716, 1717, 1718, + 1719, 1720, 1899, 1950, 1900, 1721, 1722, 1723, 1901, 1724, + 1725, 1951, 1726, 1902, 1727, 1903, 1728, 1729, 1730, 1731, + 1732, 1733, 1734, 1735, 1736, 1737, 1904, 1952, 1738, 1953, + 1905, 1739, 1740, 1741, 1742, 1743, 1744, 1745, 1746, 1747, + 1748, 1749, 1750, 1751, 1906, 1954, 1752, 1753, 1907, 1754, + 1755, 1756, 1757, 1758, 1759, 1760, 1761, 1762, 1763, 1764, + 1765, 1766, 1767, 1908, 1768, 1769, 1770, 1771, 1772, 1773, + 1774, 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, + 1784, 1785, 1786, 1955, 1787, 1788, 1789, 1909, 1790, 1791, + 1792, 1793, 1794, 1795, 1796, 1797, 1798, 1799, 1800, 1801, + 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1910, 1809, 1810, + 1956, 1811, 1812, 1911, 1813, 1814, 1815, 1816, 1817, 1818, + 1819, 1820, 1821, 1822, 1823, 1824, 1825, 1912, 1826, 1913, + 1827, 1828, 1829, 1958, 1830, 1831, 1832, 1833, 1834, 1835, + 1914, 1915, 1836, 1837, 1916, 1838, 1917, 1839, 1840, 1918, + 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, + 1851, 1852, 1853, 1854, 1855, 1856, 1857, 1919, 1920, 1858, + 1859, 1959, 1860, 1861, 1862, 1863, 1864, 1865, 1866, 1867, + 1868, 1869, 1870, 1871, 1872, 1873, 1921, 1922, 1923, 1924, + 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1874, 1875, 1876, + 1877, 0, 1537, 0, 1294, 113, 114, 1316, 112, 1891, + 1898, 1912, 1368, 1367, 113, 0, 260, 500, 0, 0, + 0, 0, 0, 0, 210, 0, 400, 399, 0, 1358, + 405, 0, 0, 0, 116, 108, 1754, 115, 1293, 106, + 122, 2102, 2103, 2104, 2105, 1989, 2106, 2107, 2108, 2109, + 1990, 2110, 1991, 1992, 1993, 1994, 1995, 1996, 2111, 2112, + 2113, 1998, 1997, 2114, 1999, 2115, 2000, 2116, 2001, 2002, + 2117, 2118, 2003, 1608, 2004, 2005, 2119, 2120, 2121, 2122, + 2123, 2124, 2125, 2126, 2127, 2006, 2007, 2128, 2129, 2008, + 2130, 2131, 2009, 2132, 2010, 2011, 2012, 2133, 2134, 2013, + 2014, 2135, 2015, 2136, 2137, 2016, 2017, 2020, 2018, 2138, + 2019, 2139, 2021, 2022, 2023, 2140, 2141, 2024, 2025, 2142, + 2026, 2027, 2028, 2029, 2030, 2143, 2031, 2144, 2032, 2033, + 2145, 2146, 2147, 2148, 2149, 2035, 2034, 2036, 2037, 2150, + 2151, 2152, 2153, 2038, 2039, 2040, 2154, 2155, 2041, 2156, + 2157, 2042, 2043, 2158, 2044, 2045, 2159, 2046, 2047, 2160, + 2048, 2049, 2161, 2162, 2163, 2050, 2164, 2051, 2052, 2165, + 2166, 2053, 2054, 2167, 2055, 2168, 2169, 2170, 2171, 2056, + 2057, 2172, 2058, 2173, 2174, 2175, 2176, 2059, 2060, 2061, + 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 1504, 124, + 123, 125, 0, 424, 425, 0, 435, 0, 417, 422, + 418, 0, 444, 437, 445, 426, 416, 438, 427, 415, + 209, 0, 446, 432, 420, 0, 0, 0, 0, 261, + 222, 406, 0, 156, 0, 1398, 1408, 1417, 1413, 1407, + 1415, 1405, 1421, 1411, 1397, 1419, 1406, 1410, 1403, 1420, + 1401, 1418, 1416, 1404, 1412, 1396, 1400, 1387, 1392, 1424, + 1414, 1422, 1409, 1423, 1425, 1399, 1426, 1402, 0, 1369, + 0, 1884, 1935, 1889, 0, 1902, 0, 1905, 1906, 1790, + 1913, 1916, 1917, 1918, 1919, 0, 783, 115, 110, 767, + 0, 542, 0, 713, 727, 767, 772, 1058, 795, 1059, + 0, 117, 1471, 1470, 1464, 195, 1331, 1517, 1655, 1695, + 1807, 1914, 1836, 1858, 1535, 1518, 1511, 1516, 262, 603, + 601, 0, 1250, 1655, 1695, 1794, 1807, 1914, 1858, 1443, + 1448, 0, 268, 1523, 115, 110, 1522, 0, 548, 595, + 0, 269, 1485, 0, 1490, 0, 1770, 575, 578, 1325, + 576, 540, 0, 0, 1, 156, 0, 162, 0, 599, + 599, 0, 599, 0, 532, 0, 0, 540, 535, 539, + 710, 1391, 1500, 0, 1534, 1914, 1836, 1524, 1521, 1664, + 0, 0, 1664, 0, 1664, 0, 1664, 0, 0, 1510, + 0, 258, 1234, 0, 1295, 118, 0, 0, 1380, 1376, + 1381, 1377, 1382, 1375, 1374, 1383, 1379, 0, 0, 0, + 371, 404, 403, 402, 401, 406, 1664, 1342, 0, 206, + 462, 463, 0, 0, 0, 0, 0, 1353, 109, 107, + 1664, 1505, 433, 434, 0, 423, 419, 421, 0, 0, + 1664, 1320, 443, 439, 1664, 443, 1287, 1664, 0, 0, + 214, 0, 399, 1389, 1427, 2056, 1441, 0, 1442, 1432, + 1395, 1428, 1429, 156, 0, 499, 1366, 0, 0, 0, + 1180, 767, 772, 0, 0, 785, 0, 1200, 0, 1206, + 0, 0, 0, 767, 547, 0, 727, 784, 111, 717, + 0, 765, 766, 651, 651, 604, 0, 585, 0, 651, + 651, 651, 777, 0, 0, 780, 778, 0, 780, 0, + 0, 0, 780, 776, 736, 0, 651, 0, 765, 768, + 651, 0, 787, 1386, 0, 0, 0, 0, 1514, 1512, + 1513, 1519, 0, 1515, 0, 0, 1297, 1299, 1300, 1148, + 1310, 1034, 0, 1879, 1880, 1881, 1223, 1882, 1883, 1885, + 1886, 1887, 992, 1628, 1888, 1308, 1890, 1892, 1893, 1895, + 1896, 1897, 1898, 1899, 1900, 0, 1309, 1903, 1733, 1908, + 1909, 1911, 1914, 1915, 1307, 1920, 0, 0, 0, 1268, + 1171, 0, 1033, 0, 0, 0, 1227, 1235, 1026, 0, + 0, 831, 832, 853, 854, 833, 859, 860, 862, 834, + 0, 1257, 926, 1022, 1245, 1036, 1031, 1041, 1037, 1038, + 1078, 1039, 1057, 1042, 1115, 1032, 0, 1040, 1024, 1253, + 585, 1251, 0, 1025, 1296, 585, 1249, 1446, 1444, 1451, + 1445, 0, 1447, 0, 0, 0, 259, 111, 1493, 1492, + 1484, 1482, 1483, 1481, 1480, 1487, 0, 1489, 1392, 1227, + 1166, 1168, 0, 577, 0, 0, 0, 529, 528, 530, + 3, 0, 0, 0, 1645, 0, 597, 598, 0, 0, + 0, 0, 0, 0, 0, 0, 694, 624, 625, 627, + 691, 695, 703, 0, 0, 0, 0, 0, 536, 0, + 1325, 1472, 1533, 1527, 1525, 0, 0, 0, 140, 140, + 0, 0, 0, 0, 0, 100, 49, 93, 0, 0, + 0, 0, 236, 249, 0, 0, 0, 0, 0, 246, + 0, 0, 229, 51, 223, 225, 0, 140, 0, 47, + 0, 0, 0, 53, 1508, 0, 499, 266, 267, 1233, + 0, 120, 121, 119, 112, 0, 2070, 1932, 1933, 1934, + 1935, 1885, 1936, 1937, 0, 1938, 1939, 1891, 1941, 1942, + 1943, 1944, 1945, 1946, 1947, 1948, 1898, 1950, 1951, 1952, + 1953, 1954, 1955, 2096, 1956, 1912, 1958, 1918, 0, 1959, + 1049, 607, 1174, 609, 1172, 1326, 0, 113, 1313, 0, + 1378, 0, 0, 0, 0, 497, 0, 0, 0, 0, + 1338, 0, 1664, 207, 211, 0, 1664, 202, 1664, 371, + 0, 1664, 371, 1664, 0, 1352, 1355, 0, 436, 431, + 429, 428, 430, 1664, 255, 0, 0, 1321, 441, 442, + 0, 410, 0, 0, 412, 0, 0, 219, 0, 217, + 0, 406, 156, 0, 230, 1437, 1438, 1436, 0, 0, + 1431, 1394, 233, 250, 1440, 1430, 1439, 1393, 1388, 0, + 0, 1384, 485, 0, 0, 0, 1181, 902, 901, 883, + 884, 899, 900, 885, 886, 893, 894, 904, 903, 891, + 892, 887, 888, 881, 882, 897, 898, 889, 890, 895, + 896, 879, 880, 1195, 1182, 1183, 1184, 1185, 1186, 1187, + 1188, 1189, 1190, 1191, 1192, 1193, 1194, 0, 0, 726, + 723, 0, 0, 0, 0, 0, 0, 1227, 0, 997, + 1032, 0, 0, 0, 1166, 1205, 0, 0, 0, 0, + 0, 0, 1166, 1211, 0, 0, 751, 763, 0, 644, + 650, 724, 722, 0, 1250, 714, 0, 797, 727, 725, + 719, 721, 0, 777, 0, 776, 0, 0, 779, 773, + 0, 774, 0, 0, 0, 0, 775, 0, 0, 0, + 0, 0, 718, 0, 763, 0, 720, 794, 1454, 1462, + 196, 0, 1317, 1960, 1961, 1962, 841, 1963, 870, 848, + 870, 870, 1964, 1965, 1966, 1967, 837, 837, 850, 1968, + 1969, 1970, 1971, 1972, 838, 839, 875, 1973, 1974, 1975, + 1976, 1977, 0, 0, 1978, 870, 1979, 837, 1980, 1981, + 1982, 842, 1983, 805, 1984, 0, 1985, 840, 806, 1986, + 878, 878, 1987, 0, 865, 1988, 0, 1177, 815, 823, + 824, 825, 826, 851, 852, 827, 857, 858, 828, 925, + 0, 837, 1318, 1319, 156, 1520, 1536, 0, 1171, 1043, + 869, 856, 1222, 0, 864, 863, 0, 1171, 846, 845, + 844, 1028, 0, 843, 1128, 870, 870, 868, 951, 847, + 0, 0, 0, 0, 0, 874, 0, 872, 952, 930, + 931, 0, 0, 1267, 1276, 1166, 1170, 0, 1026, 1166, + 0, 1035, 1045, 0, 1118, 1120, 0, 0, 0, 1228, + 1298, 1027, 0, 1303, 0, 0, 925, 925, 1256, 1148, + 0, 1138, 1141, 0, 0, 1145, 1146, 1147, 0, 0, + 0, 1248, 0, 1156, 1158, 0, 0, 967, 1154, 0, + 970, 0, 0, 0, 0, 1142, 1143, 1144, 1134, 1135, + 1136, 1137, 1139, 1140, 1152, 1133, 948, 0, 1023, 0, + 1081, 0, 947, 1254, 712, 0, 1301, 712, 1456, 1460, + 1461, 1455, 1459, 0, 1450, 1449, 1452, 1453, 0, 1494, + 1478, 0, 1475, 1169, 707, 579, 1289, 0, 583, 1499, + 161, 160, 0, 213, 0, 552, 551, 618, 610, 612, + 618, 0, 550, 0, 667, 668, 0, 0, 0, 0, + 700, 698, 1297, 1310, 655, 628, 654, 0, 0, 632, + 0, 659, 926, 693, 534, 622, 623, 626, 533, 0, + 696, 0, 706, 0, 571, 573, 556, 570, 568, 553, + 561, 694, 627, 0, 1501, 0, 0, 1465, 1526, 0, + 0, 0, 0, 0, 1664, 0, 0, 808, 84, 65, + 323, 139, 0, 0, 0, 0, 0, 0, 0, 92, + 89, 90, 91, 0, 0, 0, 0, 1317, 234, 235, + 248, 0, 239, 240, 237, 241, 242, 0, 0, 227, + 228, 0, 0, 0, 0, 226, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1509, 1502, 1229, 1234, 609, + 609, 609, 0, 0, 0, 0, 607, 608, 0, 0, + 0, 0, 0, 484, 369, 379, 0, 0, 0, 1342, + 206, 0, 0, 0, 0, 0, 0, 406, 1345, 1343, + 1341, 1344, 1346, 1634, 190, 0, 0, 0, 0, 0, + 198, 201, 0, 368, 342, 0, 0, 1357, 0, 0, + 457, 455, 458, 447, 460, 450, 0, 1664, 358, 1354, + 0, 1506, 0, 0, 253, 443, 1322, 0, 440, 443, + 1288, 0, 443, 221, 0, 0, 1390, 1433, 231, 251, + 232, 252, 499, 494, 524, 0, 502, 507, 482, 0, + 482, 0, 504, 508, 482, 503, 0, 482, 498, 0, + 1073, 0, 1063, 0, 0, 786, 0, 0, 1064, 999, + 1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1017, + 1016, 1065, 790, 0, 793, 0, 0, 1203, 1204, 0, + 1066, 0, 0, 1210, 0, 0, 0, 1071, 0, 728, + 0, 0, 634, 635, 643, 639, 646, 0, 649, 636, + 585, 541, 1655, 1695, 0, 596, 596, 596, 594, 584, + 0, 671, 729, 0, 0, 0, 752, 0, 0, 754, + 756, 0, 0, 759, 0, 735, 734, 0, 0, 0, + 0, 798, 0, 1293, 0, 0, 197, 0, 0, 0, + 823, 0, 0, 0, 813, 809, 0, 905, 906, 907, + 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, + 829, 1330, 0, 835, 1333, 0, 1334, 1335, 1332, 1329, + 1336, 1337, 0, 0, 0, 0, 1221, 1217, 0, 0, + 0, 0, 1123, 1125, 1127, 0, 867, 866, 1132, 1138, + 1141, 1145, 1146, 1147, 1142, 1143, 1144, 1134, 1135, 1136, + 1137, 1139, 1140, 0, 1160, 0, 1114, 0, 0, 0, + 0, 0, 0, 0, 1261, 1260, 0, 1284, 0, 1046, + 1030, 0, 0, 1121, 1047, 1268, 1258, 1236, 0, 0, + 0, 1306, 1305, 927, 936, 939, 971, 972, 943, 944, + 945, 949, 1328, 1327, 1255, 0, 1247, 0, 0, 928, + 953, 958, 0, 1212, 1215, 988, 1214, 0, 976, 0, + 966, 0, 974, 978, 954, 969, 0, 950, 0, 1248, + 1157, 1159, 0, 1155, 0, 940, 941, 942, 932, 933, + 934, 935, 937, 938, 946, 1131, 1129, 1130, 0, 1234, + 0, 1246, 0, 0, 1083, 0, 0, 973, 1252, 0, + 797, 609, 797, 0, 925, 1495, 1325, 1488, 1325, 1477, + 1167, 1290, 1324, 581, 0, 0, 0, 1497, 147, 151, + 0, 1235, 181, 183, 712, 0, 616, 617, 621, 0, + 0, 621, 600, 549, 1909, 1790, 0, 0, 0, 0, + 660, 701, 0, 692, 657, 658, 0, 656, 1297, 661, + 1296, 662, 665, 666, 633, 1285, 702, 704, 0, 697, + 0, 1291, 555, 574, 0, 0, 0, 0, 0, 538, + 537, 708, 1472, 1472, 1474, 1473, 0, 50, 0, 1664, + 67, 0, 0, 0, 0, 0, 0, 273, 0, 373, + 273, 105, 1664, 443, 1664, 443, 1558, 1629, 1808, 0, + 63, 347, 96, 0, 133, 376, 0, 332, 86, 101, + 126, 0, 0, 52, 224, 238, 243, 129, 247, 244, + 1362, 245, 140, 0, 48, 0, 127, 0, 1360, 0, + 0, 54, 131, 1364, 1510, 0, 1233, 0, 607, 607, + 607, 605, 606, 1050, 0, 1173, 0, 1175, 1176, 966, + 1372, 1371, 1373, 1370, 470, 483, 0, 370, 0, 496, + 473, 474, 484, 1340, 211, 0, 202, 371, 0, 371, + 0, 1342, 0, 0, 192, 188, 206, 212, 0, 0, + 0, 0, 0, 369, 361, 359, 392, 0, 366, 360, + 0, 0, 318, 0, 1552, 0, 0, 0, 0, 464, + 0, 0, 0, 0, 0, 0, 255, 256, 409, 1323, + 411, 0, 413, 220, 218, 1385, 2026, 490, 1171, 0, + 488, 495, 489, 492, 493, 487, 486, 0, 481, 0, + 517, 0, 0, 0, 0, 0, 0, 0, 0, 1060, + 1179, 0, 1198, 1197, 998, 1005, 1008, 1012, 1013, 1014, + 1199, 0, 0, 0, 1009, 1010, 1011, 1001, 1002, 1003, + 1004, 1006, 1007, 1015, 795, 0, 0, 789, 1208, 1207, + 1201, 1202, 0, 1068, 1069, 1070, 1209, 0, 0, 764, + 638, 640, 637, 0, 0, 797, 596, 596, 596, 596, + 593, 0, 0, 0, 796, 0, 688, 760, 758, 0, + 782, 0, 755, 0, 761, 0, 746, 0, 753, 802, + 769, 0, 0, 771, 1463, 819, 0, 814, 810, 0, + 0, 0, 820, 0, 0, 0, 0, 0, 0, 0, + 1178, 0, 602, 1044, 0, 0, 0, 1218, 0, 994, + 836, 849, 0, 1126, 1048, 0, 1149, 1113, 877, 876, + 878, 878, 0, 1263, 1265, 0, 0, 0, 0, 1275, + 0, 995, 1226, 0, 1074, 1224, 1167, 1117, 1119, 1276, + 1029, 861, 925, 0, 0, 0, 0, 0, 0, 0, + 977, 968, 0, 975, 979, 0, 0, 0, 962, 0, + 0, 960, 989, 956, 0, 0, 990, 1233, 0, 1237, + 0, 0, 1082, 1091, 715, 711, 671, 607, 671, 0, + 1457, 1479, 1476, 582, 156, 1498, 0, 170, 0, 0, + 0, 0, 173, 187, 184, 1497, 0, 0, 611, 613, + 0, 1150, 621, 615, 664, 663, 0, 631, 699, 629, + 0, 705, 0, 572, 0, 558, 0, 738, 0, 0, + 1466, 1467, 0, 0, 0, 322, 0, 0, 0, 273, + 0, 381, 0, 388, 0, 0, 373, 354, 85, 0, + 0, 0, 59, 104, 77, 69, 55, 83, 0, 0, + 88, 0, 81, 98, 99, 97, 102, 0, 283, 308, + 0, 0, 319, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 499, 1234, 1230, 1234, 0, 0, + 0, 609, 1051, 0, 469, 523, 520, 521, 519, 229, + 380, 0, 0, 0, 200, 368, 0, 1357, 449, 452, + 1339, 406, 0, 193, 0, 191, 211, 0, 0, 202, + 371, 0, 346, 342, 367, 340, 339, 341, 0, 1553, + 222, 0, 1547, 371, 1356, 0, 0, 465, 456, 0, + 461, 0, 0, 459, 0, 1351, 254, 443, 0, 477, + 518, 525, 505, 510, 0, 516, 512, 511, 506, 514, + 513, 509, 1061, 1072, 1196, 0, 0, 0, 0, 788, + 791, 0, 1067, 1062, 762, 0, 0, 671, 0, 0, + 0, 0, 587, 586, 592, 0, 0, 1085, 757, 0, + 0, 0, 744, 733, 739, 740, 0, 0, 0, 800, + 799, 770, 823, 0, 803, 823, 0, 823, 0, 821, + 0, 830, 918, 919, 920, 921, 922, 923, 924, 855, + 0, 1220, 1216, 1122, 1124, 1161, 873, 871, 993, 1266, + 1259, 1262, 1166, 1270, 1272, 0, 0, 0, 0, 1283, + 0, 0, 1116, 1284, 1304, 929, 0, 0, 959, 1213, + 980, 0, 0, 0, 955, 1149, 0, 0, 0, 0, + 0, 964, 0, 1241, 1234, 0, 1240, 0, 0, 0, + 0, 1056, 716, 688, 0, 688, 0, 0, 1496, 0, + 1491, 148, 149, 150, 0, 0, 0, 165, 142, 0, + 0, 182, 170, 158, 619, 620, 0, 614, 630, 1286, + 1292, 557, 0, 1026, 0, 0, 554, 0, 134, 273, + 0, 0, 66, 0, 390, 334, 382, 365, 349, 0, + 0, 0, 274, 0, 407, 0, 0, 355, 0, 0, + 0, 0, 335, 0, 0, 294, 0, 0, 365, 0, + 372, 290, 291, 0, 58, 78, 0, 74, 0, 103, + 0, 0, 0, 0, 0, 61, 73, 0, 56, 808, + 443, 443, 64, 1317, 1960, 1961, 1962, 1963, 1964, 1965, + 1966, 1967, 1968, 1969, 2080, 1970, 1971, 1972, 1973, 1974, + 1975, 1976, 1977, 2089, 1978, 280, 1979, 1733, 1980, 1981, + 1982, 1983, 1984, 0, 1985, 806, 1986, 1987, 2168, 1988, + 1134, 1135, 279, 278, 375, 275, 383, 277, 0, 1318, + 276, 378, 333, 130, 1363, 0, 128, 0, 1361, 137, + 135, 132, 1365, 1503, 0, 0, 1054, 1055, 1052, 607, + 0, 0, 0, 499, 476, 0, 0, 0, 1552, 0, + 0, 1664, 0, 189, 0, 0, 203, 1357, 199, 368, + 0, 398, 318, 393, 0, 1552, 1550, 0, 1357, 1546, + 448, 451, 0, 0, 540, 453, 0, 0, 0, 414, + 491, 0, 515, 1018, 0, 0, 0, 0, 647, 0, + 653, 688, 591, 590, 589, 588, 670, 1603, 1892, 1789, + 0, 674, 669, 672, 677, 679, 678, 680, 676, 687, + 0, 690, 781, 1162, 1164, 0, 0, 0, 0, 745, + 747, 0, 749, 0, 801, 817, 0, 818, 0, 816, + 811, 822, 1219, 1264, 1273, 1274, 1269, 1278, 1280, 0, + 0, 0, 926, 1225, 996, 986, 984, 981, 0, 982, + 963, 0, 0, 961, 957, 0, 991, 0, 0, 1238, + 0, 1077, 0, 1080, 1094, 1090, 1089, 1085, 1051, 1085, + 1458, 580, 169, 146, 172, 171, 0, 1235, 179, 0, + 0, 170, 0, 174, 466, 0, 0, 569, 737, 562, + 563, 0, 386, 68, 0, 365, 0, 273, 351, 350, + 353, 348, 352, 0, 408, 0, 0, 292, 0, 299, + 337, 338, 336, 293, 365, 371, 295, 0, 0, 0, + 70, 60, 57, 62, 71, 0, 0, 72, 75, 802, + 807, 87, 80, 1317, 2089, 2098, 0, 0, 0, 0, + 0, 1232, 1231, 0, 472, 471, 522, 468, 479, 229, + 0, 0, 0, 342, 1549, 0, 0, 0, 368, 194, + 0, 0, 0, 0, 1552, 0, 0, 270, 0, 315, + 0, 215, 1551, 0, 0, 1538, 0, 0, 1349, 1350, + 0, 478, 1019, 0, 1020, 792, 0, 0, 645, 1085, + 0, 0, 0, 681, 675, 0, 1084, 1086, 0, 642, + 1165, 741, 0, 743, 0, 767, 0, 767, 750, 812, + 804, 1271, 1281, 1282, 1277, 1075, 0, 983, 987, 985, + 965, 1234, 1242, 1234, 1239, 1079, 1093, 1096, 690, 1302, + 690, 0, 0, 157, 0, 0, 154, 141, 159, 1151, + 559, 560, 0, 273, 0, 364, 387, 304, 282, 0, + 0, 0, 289, 296, 397, 298, 0, 79, 95, 0, + 0, 377, 138, 136, 1053, 499, 0, 205, 1357, 318, + 1546, 0, 0, 0, 0, 342, 222, 1548, 331, 324, + 325, 326, 327, 328, 329, 330, 345, 344, 316, 317, + 0, 0, 0, 0, 454, 1351, 0, 176, 185, 0, + 176, 1021, 648, 0, 690, 0, 0, 0, 673, 0, + 0, 689, 0, 545, 1163, 0, 732, 730, 0, 731, + 1279, 0, 0, 0, 0, 609, 642, 642, 143, 0, + 144, 180, 0, 0, 0, 371, 389, 363, 0, 356, + 302, 301, 303, 307, 0, 305, 0, 321, 0, 314, + 282, 0, 82, 0, 384, 467, 475, 0, 272, 1540, + 368, 0, 204, 1546, 318, 1552, 1546, 0, 1543, 0, + 0, 0, 0, 178, 1357, 0, 178, 0, 642, 683, + 0, 682, 1088, 1087, 644, 742, 0, 1076, 1244, 1243, + 0, 1100, 544, 543, 0, 0, 0, 0, 397, 0, + 343, 0, 0, 304, 0, 297, 394, 395, 396, 0, + 310, 300, 311, 76, 94, 385, 0, 368, 1541, 271, + 216, 1539, 1544, 1545, 0, 176, 175, 618, 177, 797, + 186, 618, 652, 546, 684, 641, 748, 1095, 0, 0, + 0, 0, 0, 153, 797, 164, 0, 314, 362, 357, + 281, 306, 320, 0, 0, 0, 312, 0, 313, 1546, + 0, 178, 621, 1347, 621, 1878, 1604, 1843, 0, 1112, + 1101, 1112, 1112, 1092, 145, 152, 0, 273, 286, 0, + 285, 0, 374, 309, 1542, 1357, 618, 166, 167, 0, + 1105, 1104, 1103, 1107, 1106, 0, 1099, 1097, 1098, 797, + 391, 284, 288, 287, 797, 621, 0, 0, 1109, 0, + 1110, 163, 1348, 168, 1102, 1108, 1111 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { - -1, 47, 48, 49, 760, 2707, 2708, 2709, 2318, 2307, - 2308, 1792, 1793, 1232, 3524, 2319, 1233, 1234, 2711, 761, - 811, 1176, 860, 1114, 1643, 921, 1269, 1270, 762, 1799, - 763, 2953, 2233, 2651, 3506, 54, 3245, 2236, 1190, 3248, - 3470, 2946, 3243, 2652, 3545, 3599, 3246, 2237, 2238, 3471, - 2239, 764, 2770, 2771, 765, 766, 1891, 58, 1334, 555, - 1888, 3116, 2774, 2775, 767, 768, 1367, 1368, 976, 769, - 1892, 1831, 3071, 1252, 1821, 1382, 62, 1915, 770, 107, - 917, 64, 771, 2694, 3072, 3517, 2722, 3654, 3006, 3007, - 3514, 3515, 2697, 2321, 3582, 3583, 2789, 1812, 3577, 2408, - 3458, 2327, 2301, 3008, 2416, 3417, 3124, 2322, 2988, 2781, - 2782, 2409, 3510, 1910, 2410, 3511, 3264, 2411, 1866, 1895, - 2698, 3584, 2328, 1867, 2693, 3073, 1796, 2412, 3521, 2413, - 556, 2992, 772, 751, 752, 968, 1361, 753, 773, 1901, - 1902, 1903, 1904, 1905, 1906, 952, 1907, 774, 775, 2750, - 2386, 3318, 2808, 3319, 2453, 2380, 1391, 2445, 1935, 1869, - 1392, 544, 1949, 2809, 2755, 1936, 776, 1115, 72, 73, - 1023, 74, 3258, 75, 76, 1769, 1770, 1771, 862, 872, - 873, 1723, 2939, 2940, 2645, 1477, 2020, 865, 1195, 1738, - 846, 847, 1855, 888, 1858, 1733, 1734, 2242, 2659, 1762, - 1763, 1204, 1205, 2006, 2007, 3485, 2008, 2009, 1470, 1471, - 3358, 2523, 2524, 1481, 1750, 1754, 1755, 2263, 2253, 1741, - 2520, 3165, 3166, 3167, 3168, 3169, 3170, 3171, 1116, 2847, - 3369, 1758, 1759, 1207, 1208, 1209, 1767, 2273, 78, 79, - 2215, 2633, 2634, 817, 818, 3183, 1501, 1772, 2853, 2854, - 2855, 3186, 3187, 3188, 819, 1018, 1019, 1046, 1041, 1490, - 2032, 820, 821, 1983, 1984, 2491, 1048, 2022, 2044, 2045, - 2861, 2548, 1569, 2304, 1570, 1571, 2059, 1572, 1117, 1573, - 1601, 1118, 1606, 1575, 1119, 1120, 1121, 1578, 1122, 1123, - 1124, 1125, 1594, 1126, 1127, 1618, 2061, 2062, 2063, 2064, - 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, - 1177, 1773, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, - 1137, 1138, 823, 1139, 2592, 1140, 1694, 2209, 2632, 3175, - 3366, 3367, 2933, 3231, 3397, 3497, 3613, 3641, 3642, 3668, - 1141, 1142, 1638, 1639, 1640, 2096, 2097, 2098, 2099, 2203, - 1688, 1689, 1143, 3075, 1691, 2119, 3179, 3180, 1178, 1463, - 1631, 1313, 1314, 1583, 1437, 1438, 1444, 1958, 1452, 1456, - 1988, 1989, 1464, 2170, 1144, 2090, 2091, 2566, 1596, 2593, - 2594, 1145, 1268, 1644, 2928, 2206, 1692, 2163, 1152, 1146, - 1153, 1148, 1627, 2900, 2583, 2584, 1628, 2588, 2896, 2897, - 2132, 2901, 3203, 3204, 2590, 2270, 1720, 2275, 2276, 972, - 1149, 1150, 1151, 1315, 528, 1584, 3600, 1357, 1183, 1316, - 2159, 777, 1053, 2083, 778, 1330, 1881, 779, 3349, 3142, - 1346, 1911, 2421, 557, 780, 781, 537, 85, 2375, 933, - 86, 87, 88, 897, 1384, 782, 1385, 1386, 983, 89, - 2810, 985, 986, 784, 854, 855, 1510, 1708, 1511, 785, - 92, 829, 1782, 786, 1172, 869, 1173, 1175, 787, 1192, - 2648, 2231, 95, 96, 97, 116, 1264, 788, 840, 841, - 878, 100, 101, 1220, 842, 790, 791, 3345, 792, 2792, - 1340, 538, 530, 531, 1586, 725, 1318, 726 + -1, 47, 48, 49, 755, 2664, 2665, 2666, 2289, 1225, + 3452, 2290, 1226, 1227, 2668, 756, 806, 1169, 855, 1107, + 1629, 915, 1261, 1262, 757, 1783, 758, 2897, 2209, 2610, + 3434, 54, 3178, 2212, 1183, 3181, 3398, 2890, 3176, 2611, + 3473, 3527, 3179, 2213, 2214, 3399, 2215, 759, 2724, 2725, + 760, 761, 1870, 58, 1324, 551, 1867, 762, 763, 1357, + 1358, 970, 764, 1871, 1811, 3013, 1245, 1801, 1372, 62, + 1894, 765, 107, 911, 64, 766, 2653, 3014, 3445, 2679, + 3582, 2950, 2951, 3442, 3443, 2656, 2292, 3510, 3511, 2739, + 1792, 3505, 2374, 3386, 2296, 2277, 2952, 2382, 3345, 3061, + 2293, 2932, 2375, 3438, 1889, 2376, 3439, 3197, 2377, 1845, + 1874, 2657, 3512, 2297, 1846, 2652, 3015, 1780, 2378, 3449, + 2379, 552, 2936, 767, 746, 747, 962, 1351, 748, 768, + 1880, 1881, 1882, 1883, 1884, 1885, 946, 1886, 769, 770, + 2704, 2352, 3249, 2758, 3250, 2419, 2346, 1381, 2411, 1914, + 1848, 1382, 540, 1928, 2759, 2709, 1915, 771, 1108, 72, + 73, 1017, 74, 3191, 75, 76, 1754, 1755, 1756, 857, + 867, 868, 2205, 1467, 1999, 860, 1188, 1723, 841, 842, + 1834, 883, 1837, 1718, 1719, 2218, 2618, 1747, 1748, 1197, + 1198, 1985, 1986, 3413, 1987, 1988, 1460, 1461, 3288, 1735, + 1739, 1740, 2239, 2229, 1726, 2486, 3101, 3102, 3103, 3104, + 3105, 3106, 3107, 1109, 2797, 3299, 1743, 1744, 1200, 1201, + 1202, 1752, 2249, 78, 79, 2190, 2594, 2595, 812, 813, + 3118, 1490, 1757, 2801, 2802, 2803, 3121, 3122, 3123, 814, + 1012, 1013, 1040, 1035, 1479, 2009, 815, 816, 1962, 1963, + 2457, 1042, 2001, 2020, 2021, 2809, 2510, 1556, 2278, 1557, + 1558, 2035, 1559, 1110, 1560, 1588, 1111, 1593, 1562, 1112, + 1113, 1114, 1565, 1115, 1116, 1117, 1118, 1581, 1119, 1120, + 1605, 2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, + 2046, 2047, 2048, 2049, 2050, 1170, 1758, 1122, 1123, 1124, + 1125, 1126, 1127, 1128, 1129, 1130, 1131, 818, 1132, 2553, + 1133, 1680, 2184, 2593, 3111, 3296, 3297, 2881, 3166, 3327, + 3425, 3541, 3569, 3570, 3596, 1134, 1135, 1624, 1625, 1626, + 2072, 2073, 2074, 2075, 2178, 1674, 1675, 1136, 3017, 1677, + 2095, 3114, 3115, 1171, 1453, 1617, 1303, 1304, 1570, 1427, + 1428, 1434, 1937, 1442, 1446, 1967, 1968, 1454, 2145, 1137, + 2066, 2067, 2528, 1583, 2554, 2555, 1138, 1260, 1630, 2876, + 2181, 1678, 2138, 1145, 1139, 1146, 1141, 1613, 2848, 2544, + 2545, 1614, 2549, 2844, 2845, 2107, 2849, 3138, 3139, 2551, + 2246, 1706, 2251, 2252, 966, 1142, 1143, 1144, 1305, 524, + 1571, 3528, 1347, 1176, 1306, 2134, 772, 1047, 2059, 773, + 1320, 1860, 774, 3279, 3078, 1336, 1890, 2387, 553, 775, + 776, 533, 85, 2341, 927, 86, 87, 88, 892, 1374, + 777, 1375, 1376, 977, 89, 2760, 979, 980, 779, 849, + 850, 1499, 1694, 1500, 780, 92, 824, 1767, 781, 1165, + 864, 1166, 1168, 782, 1185, 2607, 2207, 95, 96, 97, + 115, 1256, 783, 835, 836, 873, 100, 101, 1213, 837, + 785, 786, 3275, 787, 2742, 1330, 534, 526, 527, 1573, + 720, 1308, 721 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -3183 +#define YYPACT_NINF -3162 static const int yypact[] = { - 7498, 376, 90, -3183, -3183, 223, 376, 52258, 68277, 157, - 376, 115, 3126, 54753, -3183, -3183, 48744, 43787, 376, 57765, - 74754, 430, 581, 32562, 563, 58267, -3183, -3183, -3183, 68277, - 57765, 58769, 376, 355, 68779, -3183, 376, 35576, 55255, 325, - -3183, 57765, 52, 300, 59271, 57765, 2175, 734, 350, -3183, - -3183, -3183, -3183, -3183, 108, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, 169, -3183, 338, 191, 32562, 32562, 1684, 324, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, 437, - -3183, -3183, 535, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, 35073, -3183, -3183, -3183, -3183, -3183, -3183, 59773, 57765, - 60275, 55757, 60777, -3183, 657, 602, 943, 671, 180, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, 182, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, 537, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, 202, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, 596, -3183, 551, -3183, 208, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, 1613, - -3183, -3183, 914, 1688, 57765, 459, 539, 797, -3183, 61279, - -3183, 788, 57765, -3183, -3183, 799, 996, 1005, -3183, -3183, - 56259, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, 49246, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, 947, -3183, -3183, - 790, -3183, 174, -3183, -3183, 813, 766, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, 872, -3183, -3183, -3183, - 882, 69281, 61781, 62283, -3183, 733, 2594, 8874, 43633, 31556, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, 437, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, 58267, 68277, 748, 754, 1112, 763, 33566, - 776, 36079, 787, 796, 1151, 837, 839, 858, 876, 300, - 32059, 890, 596, 892, 62785, 62785, -28, 33064, 4145, -3183, - 62785, 63287, -3183, 913, -3183, 943, -3183, -3183, -3183, -3183, - 262, 919, -3183, 63789, 63789, 63789, 927, 1219, 63789, -3183, - -3183, -3183, 924, -3183, -3183, 1159, 20059, 20059, 69783, 69783, - 943, 69783, 951, 69783, -3183, -3183, 69, 671, -3183, 596, - -3183, -3183, 1684, -3183, -3183, 55255, -3183, -3183, 170, 1297, - 20059, 57765, 935, -3183, 952, 935, 960, 983, 991, -3183, - 7498, 1348, 1235, 56761, 359, 359, 1485, 359, 623, 1106, - 2816, 3725, -3183, 984, -3183, 1025, -3183, 57765, 58267, 1126, - 1063, 1331, -3183, -3183, 1417, 944, 1221, 1444, 5140, 1480, - 1107, 1484, 1116, 1518, 1495, 1649, 36, -3183, 20059, 49748, - 596, -3183, 11083, 20059, -3183, -3183, -3183, 1270, -3183, -3183, - -3183, -3183, -3183, 57765, 68277, 1177, 1187, -3183, -3183, -3183, - -3183, 1916, 1438, -3183, 1679, 70285, -3183, -3183, 1249, 64291, - 64793, 65295, 65797, 1641, -3183, -3183, 1583, -3183, -3183, -3183, - 1257, -3183, -3183, -3183, 219, 70787, 1595, 1227, 165, -3183, - 1603, 205, -3183, 1605, 1472, 14779, -3183, 1409, -3183, -3183, - -3183, 300, -3183, 256, -3183, -3183, 45814, -3183, -3183, 43633, - 1337, 1258, -3183, 20059, 20059, 1260, 7589, 62785, 63287, 20059, - 57765, -3183, 20059, 25339, 1273, 20059, 20059, 12139, 20059, 30552, - 62785, 4145, 1276, -3183, 605, -3183, 57765, 1281, -3183, 1383, - 1383, 355, 32562, 1588, 32059, 1383, 1765, 1383, -3183, 1024, - 1596, 1517, -3183, 32562, 1517, 1645, 1305, 1609, 1517, -3183, - 290, 1618, 1765, 36581, 1317, -3183, 1383, 1550, -3183, -3183, - 20059, 14779, 66299, 1811, -3183, -3183, -3183, -3183, 1619, -3183, - 68277, 1343, -3183, -3183, -3183, -3183, -3183, -3183, 521, 1866, - 177, 1868, 20059, 177, 177, 1354, 211, 211, -3183, 1552, - 1365, -3183, 212, 1373, 1377, 1887, 1897, 190, 146, 1022, - 177, 20059, -3183, 211, 1387, 1905, 1393, 1912, 181, 214, - -3183, 1399, 215, 20059, 20059, 20059, 319, 20059, 10027, -3183, - 49748, 1922, 57765, 410, -3183, 596, 1414, 943, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, 1418, -3183, 203, 8279, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, 1457, -3183, -3183, - -3183, -3183, 1642, 20059, -3183, -3183, 1421, 1588, -3183, 216, - -3183, -3183, 1588, -3183, -3183, -3183, -3183, -3183, 235, -3183, - 1845, 20059, 20059, -3183, 596, 71289, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, 660, -3183, 437, 615, 47518, 1426, 1430, - 935, 57765, 57765, 1493, -3183, -3183, -3183, -3183, 55255, 257, - 1742, 168, 1573, -3183, -3183, 1684, 1684, 15307, 895, 236, - 72, 15835, 20587, 1807, 1689, 271, 577, 1808, -3183, 1692, - 1919, 25339, 20059, 20059, 623, 1106, 20059, 952, 133, -3183, - -3183, -3183, 1745, 57765, 52760, 783, 786, 1461, 1551, 4, - 1592, 1893, -3183, 1464, -3183, 1558, 57765, 73784, 228, -3183, - 1935, 228, 228, 714, 1936, 1563, 288, 1733, 21, 321, - 1464, 1991, -3183, 55255, 179, 847, 1464, 57765, 1564, 873, - 1464, 1495, 943, 68277, 1258, -3183, -3183, 8587, 1486, -3183, - -3183, -3183, 176, 14779, -3183, 905, 1149, 1178, 1248, 347, - 210, 1315, 1351, 14779, 1371, 1413, 187, 1497, 1525, 1599, - 1674, 1715, 1719, 1739, 1747, 134, 1755, 1760, 1763, 1770, - 1775, 1779, -3183, 1787, 189, 1791, 229, 1399, 14779, 1817, - -3183, 160, 47518, 22, -3183, -3183, 1819, 201, -3183, 47606, - -3183, 1789, 1580, 1582, 68277, 1533, 57765, 1636, 1451, 1867, - 1920, 66786, 1749, -3183, 1823, 57765, 1750, 1991, 1757, 1514, - 1990, 1758, 1187, 1762, 1520, -3183, 71791, 49748, -3183, -3183, - -3183, -3183, -3183, 1895, 1876, 68277, 49748, 1516, -3183, -3183, - 68277, -3183, 57765, 57765, -3183, 57765, 68277, -3183, 702, 47518, - 2036, 1767, 43633, 51254, -3183, -3183, -3183, -3183, 409, 938, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, 943, - 49748, -3183, 4107, 46440, 1528, 20059, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, 1530, 1881, -3183, - -3183, 8146, 1532, 46480, 1536, 25339, 25339, 596, 1804, -3183, - -3183, 25339, 1538, 51756, 46352, 1537, 1539, 46834, 16363, 20059, - 16363, 16363, 46922, -3183, 1542, 46999, 62785, 1534, 57765, 30045, - -3183, -3183, -3183, 20059, 20059, 4145, 57263, 1586, 1546, -3183, - 1549, 1383, -3183, 32562, -3183, 32562, -3183, 1849, 32562, -3183, - -3183, 2879, -3183, 32562, 1850, 20059, 32562, -3183, 32562, 1796, - 1797, 1559, 32562, 1383, 57765, 1566, 57765, -3183, -3183, 47518, - -3183, 1560, 718, 1561, -3183, -3183, -3183, -3183, -3183, -3183, - 1621, -3183, 1621, 1621, -3183, -3183, -3183, -3183, 1567, 1567, - 1569, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, 1571, 1022, -3183, 1621, -3183, 1567, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, 73784, -3183, -3183, - -3183, -3183, 362, 569, -3183, 1572, -3183, -3183, -3183, 1578, - -3183, 1577, 2062, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, 7880, 774, 1567, -3183, -3183, 4373, -3183, -3183, - 20059, 20059, -3183, -3183, 1581, 47518, 1624, -3183, -3183, 20059, - 20059, -3183, -3183, -3183, -3183, 2097, -3183, 20059, 1621, 1621, - -3183, 6844, -3183, 41603, 16891, 1676, 1685, 2097, -3183, 2097, - -3183, 20059, 6844, 2099, 2099, 1594, 37083, -3183, 1766, 47087, - -3183, 1601, 985, 8724, 1600, -3183, -3183, 1593, -3183, 1606, - 1602, 44308, 20059, 158, 596, 596, 20059, -3183, 2097, 20059, - 8008, 8008, -3183, 196, 66299, 20059, 20059, 20059, 20059, 20059, - 20059, 20059, 20059, 48242, 1695, 164, 68277, 20059, 20059, 29532, - 676, -3183, 20059, 1852, -3183, 1616, 20059, 1701, 207, 20059, - 20059, 20059, 20059, 20059, 20059, 20059, 20059, 20059, -3183, -3183, - 28507, 221, 621, 1957, 1977, 13, 534, 20059, 1970, 11083, - -3183, 1970, -3183, -3183, -3183, -3183, -3183, 217, -3183, -3183, - 1560, 1560, 68277, -3183, 57765, 170, 53764, 20059, -3183, -3183, - 1622, 1627, 1917, 2112, 1698, -3183, -3183, 57765, -3183, 40095, - 1943, -3183, 346, 1637, -3183, 46313, 1898, 1943, 1684, -3183, - -3183, 25867, 1772, 1939, 1877, -3183, -3183, 1861, 1863, -3183, - 1653, 47746, 21115, 21115, -3183, 1289, 47518, 1492, -3183, -3183, - -3183, -3183, -3183, -3183, 852, -3183, 57765, 98, 37585, -3183, - 1657, 114, -3183, 2195, 2002, 1966, 1807, 577, 1665, -3183, - 58267, 58267, -3183, -3183, 1200, 1667, 72293, 57765, 1963, 1921, - 1964, -52, 66299, -3183, 1678, -3183, -3183, -3183, 57765, 68277, - 67273, 72795, 50250, 57765, 2143, 2153, 49748, -3183, -3183, 2154, - 2160, -3183, -3183, 57765, 820, 57765, 5451, -3183, -3183, -3183, - -3183, 228, -3183, -3183, -3183, -3183, -3183, 68277, 57765, -3183, - -3183, 228, 68277, 57765, 228, -3183, 1327, 57765, 57765, 68277, - 57765, 1424, 57765, 57765, 943, 1649, -3183, -3183, -3183, 21643, - 27, 27, 1903, 1940, 1942, 1706, 12667, 160, -3183, 20059, - 20059, 1047, 278, 68277, 1894, -3183, -3183, 789, 1944, 247, - -3183, 68277, 1764, 57765, 57765, 57765, 57765, 57765, 888, -3183, - -3183, -3183, -3183, -3183, 1712, -3183, 2091, 2245, 1729, 1730, - 2103, -3183, 1991, 2104, 53262, 574, 1856, 2105, 1776, 2106, - 13195, -3183, -3183, 1735, -3183, -3183, 1737, 2225, 1992, -3183, - -3183, 1976, -3183, 68277, 2265, -3183, 165, -3183, 49748, -3183, - 205, -3183, 1979, 239, -3183, 14779, 20059, -3183, -3183, -3183, - -3183, -3183, -3183, 1258, 29020, -3183, 811, -3183, -3183, 2231, - 943, 2231, 516, -3183, -3183, 2231, -3183, 2214, 2231, -3183, - 66299, -3183, 8895, -3183, 20059, 20059, -3183, 20059, 2102, -3183, - 2267, 2267, 66299, 25339, 25339, 25339, 25339, 25339, 25339, 575, - 1387, 25339, 25339, 25339, 25339, 25339, 25339, 25339, 25339, 25339, - 26395, 592, -3183, -3183, 830, 2240, 20059, 20059, 2114, 2102, - 20059, -3183, 66299, 1761, -3183, 1769, 1771, 20059, -3183, 66299, - -3183, 57765, 1773, -3183, -3183, -3183, -6, 1768, 1777, -3183, - -3183, 1588, -3183, 710, 773, 57765, 4193, 5403, 6185, -3183, - -3183, 20059, 2101, -3183, -20, -3183, 2879, 2879, 32562, -3183, - 20059, 1782, -3183, -3183, 32562, 2119, -3183, 2879, -3183, -3183, - 38087, 2879, -3183, 66299, 832, -3183, 57765, 66299, 870, 20059, - -3183, 14779, 2284, 66299, 2249, 68277, 68277, 2289, 1781, 1785, - 2097, 1872, -3183, 1873, 1874, 1882, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, 66299, -3183, -3183, 153, - -3183, -3183, -3183, -3183, -3183, -3183, 1801, 1774, 20059, 20059, - 44, -3183, 8969, 1802, 1805, 7217, -3183, 1806, -3183, 1795, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, 1825, -3183, 1812, - -3183, 1818, 1826, 1838, 1824, 1828, 42113, 20059, 57765, -3183, - 1834, 22171, 2005, 68277, -3183, -3183, 20059, 20059, 57765, -3183, - 2216, 47518, -3183, 1840, 1844, 42152, -3183, -3183, -3183, 234, - 400, 4034, 534, 2551, 2551, 2551, 6844, -3183, -3183, -3183, - 1869, -3183, 25339, 25339, -3183, 2997, 3613, 10027, -3183, -3183, - -3183, -3183, 2198, -3183, 266, -3183, 1846, -3183, -3183, 4268, - -3183, 41603, 6804, 20059, 186, -3183, 20059, 29532, 20059, 1938, - 2551, 2551, 2551, 388, 388, 234, 234, 234, 400, 534, - -3183, -3183, -3183, 1851, 20059, 49748, -3183, 1853, 1854, 2223, - 1393, 20059, -3183, -3183, 32562, 1586, 22, 1586, 2097, 8008, - -3183, 952, -3183, 952, -3183, 47518, 57765, -3183, 1858, 595, - 32562, 1901, 2342, 2324, 68277, -3183, -3183, 1859, 1970, 1875, - -3183, -3183, 1880, 20059, 778, 1880, -3183, 1943, 19, 2096, - 1065, 1065, 1289, 2098, -3183, -3183, 1933, -3183, -3183, -3183, - 20059, 13723, 1499, -3183, 1512, -3183, -3183, -3183, -3183, -3183, - 1878, -3183, 2147, -3183, 57765, -3183, -3183, 25339, 2334, 20059, - 38589, 2338, 2132, -3183, -3183, -3183, 1927, 1927, -3183, -3183, - 1968, 1464, 20059, 2127, -3183, 110, 1885, 2256, -51, 2206, - 68277, -3183, -3183, -3183, 307, 322, 49748, 1678, -3183, -3183, - 270, 2258, 239, 2260, 239, 49748, 49748, 49748, 880, -3183, - -3183, -3183, 943, -3183, -3183, -3183, 390, 887, -3183, 1892, - 1900, -3183, -3183, -3183, 1981, 1319, 1464, 1991, -3183, -3183, - -3183, -3183, -3183, -3183, -3183, 183, 1412, 1464, 1982, -3183, - 1983, -3183, 1985, 1535, 1464, -3183, -3183, 1649, 1258, 17419, - 47518, 249, 160, 160, 160, -3183, -3183, -3183, 14779, -3183, - 1902, 47518, 47518, 144, -3183, -3183, -3183, -3183, 1904, -3183, - 224, -3183, 68277, -3183, -3183, -3183, 1894, 1920, 1823, 57765, - 1991, 1907, 2379, 1187, 1520, -3183, 2066, 40, 2339, -3183, - 68277, -3183, 49748, 68277, 57765, 57765, 57765, 54266, -3183, -3183, - -3183, 1908, 1906, -3183, 16, 2135, 2136, 57765, 1946, 57765, - 1911, 2397, 57765, -3183, 889, 1520, 1520, 17947, 2286, 57765, - 1876, -3183, -3183, -3183, -3183, 68277, -3183, -3183, 47518, -3183, - 1910, -3183, 20059, 50752, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, 49748, -3183, 943, -3183, 943, 2162, 68277, 44810, 943, - 45312, 943, 1926, -3183, 47518, 42191, 47518, 2114, -3183, 238, - 2267, 3706, 3706, 3706, 3330, 2278, 204, 1931, 3706, 3706, - 3706, 572, 572, 238, 238, 238, 2267, 592, 913, 51756, - 1937, -3183, 47518, 47518, -3183, -3183, 1932, -3183, -3183, -3183, - -3183, 1950, 1951, -3183, -3183, -3183, -3183, 68277, 167, 1586, - 325, 325, 325, 325, -3183, 57765, 57765, 57765, 47518, 2400, - 2275, -3183, -3183, 2448, 1953, -3183, -3183, 2879, 47518, 57765, - -3183, 27451, -3183, 57765, -3183, 2301, -3183, 2396, -3183, 57765, - 897, -3183, -3183, -3183, 910, 1958, 1785, 66299, 920, 937, - -3183, 2097, 163, 1956, 1620, 998, 137, 1509, -3183, 55255, - -3183, -3183, 1959, 47191, 20059, -3183, 2336, -3183, -3183, -3183, - 20059, 20059, -3183, 41603, -3183, -3183, -3183, -3183, -75, -75, - -3183, 42238, 1834, 1960, 1961, 57765, 10027, 47438, -3183, 39091, - -3183, -3183, 2285, 1969, -3183, 42277, 47518, -3183, 1766, -3183, - -3183, 8008, 20059, 2317, 3513, 20059, 1967, 20059, 2314, -3183, - -3183, 1974, -3183, -3183, 66299, 20059, 1975, 4945, 25339, 25339, - 5766, -3183, 6361, 20059, 10027, -3183, 43366, 1962, 1986, 1903, - 18475, -3183, 2197, 1971, -3183, 2101, 160, 2101, 1984, -3183, - -3183, -3183, 68277, -3183, 2253, 1987, -3183, 20059, 2142, 68277, - 501, 1408, 950, -3183, 596, 40095, 1901, 20059, 495, -3183, - -3183, 1988, -3183, 1880, -3183, -3183, -3183, 2219, -3183, -3183, - -3183, 57765, -3183, 1993, -3183, 37585, 2333, 10555, -3183, 37585, - 57765, -3183, -3183, 57765, 42634, 2364, -3183, 68277, 68277, 68277, - -3183, 68277, 1994, 1995, 1070, 1997, 397, -3183, 2807, -3183, - -3183, 1070, 2345, 225, 1911, 288, 3372, 76, -3183, -3183, - -3183, 2078, 57765, -3183, 68277, -3183, -3183, -3183, -3183, -3183, - 50250, -3183, -3183, 41100, 49748, -3183, 49748, 20059, 20059, 57765, - 57765, 57765, 57765, 68277, 57765, 57765, 57765, 57765, 57765, 1258, - -3183, 20059, -3183, 20059, 2004, 2006, 2007, 1903, -3183, 251, - -3183, 2008, -3183, -3183, -3183, 321, -3183, 224, 2011, 2012, - -3183, 53262, 1688, 1776, -3183, 1737, 1920, 988, 67775, -3183, - 2019, 2017, 1823, 20059, -3183, 955, 968, 1991, 2022, 2504, - -3183, -3183, -3183, 574, 53262, -3183, -3183, -3183, 2459, -3183, - 733, 226, -3183, 1187, -3183, 1688, 1520, -3183, -3183, 2508, - -3183, 2509, 1688, 47518, 68277, 2090, -3183, 239, 974, -3183, - -3183, -3183, -3183, -3183, 68277, 2026, -3183, 2026, -3183, -3183, - 2026, -3183, -3183, -3183, -3183, 25339, 2380, 2032, 66299, -3183, - -3183, 57765, -3183, -3183, -3183, 987, 2033, 2101, 57765, 57765, - 57765, 57765, -3183, -3183, -3183, 19003, 20059, 2072, 20059, -3183, - -3183, 2034, 11611, 2361, -3183, 26923, -3183, -3183, 2039, 38087, - 68277, -3183, -3183, -3183, -3183, 2097, -3183, -3183, 68277, -3183, - 2045, -3183, 2048, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, 20059, 47518, -3183, 47518, -3183, -3183, -3183, -3183, - -3183, 57765, -3183, -3183, 8667, -3183, 2050, 2051, 68277, 57765, - 106, -3183, 20059, 68277, -3183, 2005, -3183, 380, 20059, 20059, - 2997, -3183, 6951, 20059, 66299, 1006, 2997, 248, 20059, 4557, - 5364, 20059, 20059, 7009, 42720, -3183, 22699, 14251, -3183, 2055, - 20059, 42759, 40597, -3183, 32562, 2275, 2056, 2275, 943, 2058, - 2057, -3183, -3183, 4373, 47518, 20059, -3183, -3183, -3183, -3183, - 2115, 407, 34570, 2293, -3183, 2075, 68277, -3183, 2142, 47518, - -3183, -3183, 41603, -3183, -3183, -3183, -3183, -3183, 2527, 1589, - 2067, 2068, -3183, 1431, -3183, -3183, 68277, 2077, -3183, 2079, - 1070, -3183, 68277, 2108, -3183, 297, 2383, 79, -3183, 20059, - -3183, 2477, 2562, 2807, 2082, 68277, 57765, 25339, -3183, 309, - 232, -3183, 2378, 57765, 2108, 2518, -3183, -3183, -3183, 397, - -3183, 2418, 2335, -3183, 228, -3183, 20059, 397, 2348, 246, - 68277, -3183, -3183, 1443, -3183, 66299, 239, 239, -3183, 1561, - 2109, 2110, 2111, 2113, 2116, 2120, 2122, 2123, 2124, 2126, - 2128, -3183, 2129, 2131, 2137, 2138, 2146, 2158, 2161, 2163, - 1571, 2164, -3183, 2165, 1988, 2166, 2167, 2168, 2169, 2170, - 73297, 2171, 2172, 2174, 2176, 1572, 2178, 2183, 409, 938, - -3183, -3183, -3183, -3183, -3183, -3183, 1227, 2191, -3183, 2125, - -3183, 2100, 1018, -3183, -3183, 2180, -3183, 2196, -3183, -3183, - -3183, -3183, -3183, -3183, 2139, 2204, -3183, -3183, -3183, 160, - 2193, 2203, 68277, 1258, 149, 49748, 68277, 2207, 1946, 2602, - 918, 2369, 2177, -3183, 943, 2209, -3183, 47518, -3183, 49748, - 1776, -3183, 53262, 2302, 241, 2136, 66299, -3183, 298, 1946, - -3183, 2576, 1776, 2235, -3183, 1737, 2310, 20059, 162, -3183, - 2442, 68277, 2217, -3183, -3183, 50752, 2026, 3476, 25339, 66299, - 1031, 1035, -3183, 2726, 2382, 2275, -3183, -3183, -3183, -3183, - -3183, 2218, -35, 2220, 9499, 2215, -3183, -3183, -3183, -3183, - -3183, -3183, 47518, 47518, 68277, 2405, 47518, -3183, -3183, 2221, - 2222, 39593, 2684, 2226, -3183, -3183, 2548, -3183, 31054, -3183, - 1785, 2229, 1785, 66299, 1785, -3183, -3183, 47518, 1834, 20059, - -3183, -3183, -3183, 2227, 2232, 68277, 43405, 2559, -3183, -3183, - 2997, 2997, 6951, 1040, -3183, 2997, 20059, 20059, 2997, 2997, - 20059, -3183, 19531, 394, -3183, 1041, -3183, 42798, -3183, 74271, - -3183, -3183, 2072, 943, 2072, -3183, -3183, 68277, 2233, 2228, - -3183, -3183, -3183, 2296, -3183, -3183, 1046, 2667, 2142, 20059, - -3183, -3183, 2242, 37585, -3183, -3183, -3183, -3183, 37585, 1070, - -3183, 2421, 2108, 2254, -3183, -3183, -3183, -3183, -3183, -3183, - 42884, -3183, 94, 20059, -3183, 1076, 3330, -3183, -3183, -3183, - -3183, 2108, 1187, -3183, 57765, 2734, 2625, -3183, -3183, 47518, - -3183, -3183, 2097, 2097, -3183, -3183, 2396, -3183, -3183, -3183, - 2257, -3183, -3183, 1227, 415, 41100, -3183, -3183, 57765, 57765, - -3183, -3183, 2259, -3183, -3183, -3183, -3183, -3183, 321, 2655, - 1051, 1064, 574, -3183, 1688, 57765, 2630, 53262, -3183, 49748, - -3183, 2746, 2269, 57765, 1946, 1171, 1171, -3183, 2417, -3183, - 2419, -3183, -3183, 2752, 314, -3183, 1365, 57765, -3183, -3183, - 34068, -3183, 3476, 1102, -3183, -3183, 2271, 2277, -3183, 2072, - 20059, 2279, 20059, -3183, 23227, 2759, 2276, -3183, 20059, 2343, - 27979, -3183, 20059, -3183, 57765, 62785, 2281, 62785, -3183, -3183, - -3183, -3183, 57765, -3183, -3183, -3183, 20059, -3183, 2997, 2997, - 2997, 20059, -3183, 20059, -3183, -3183, -3183, 2494, 2405, -3183, - 2405, -3183, -3183, 20059, 1688, 596, 2624, 68277, 54, -3183, - 47518, -3183, -3183, -3183, 57765, -3183, 49748, -3183, 1070, 60, - 2290, 20059, 43241, 2530, -3183, -3183, 2564, -3183, 2623, -3183, - 2355, 540, 2372, -3183, -3183, -3183, -3183, 1258, 943, -3183, - 1776, 2136, 2235, 2298, 57765, 1104, 1688, 574, 733, -3183, - -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, -3183, - -3183, -3183, 1688, 2743, 2531, 2754, -3183, 2090, 20059, 245, - -3183, 1119, 2740, -3183, -3183, 2827, 2405, 2315, 23227, 2318, - -3183, 2321, 68277, 47518, 2472, -3183, -3183, 2325, -3183, -3183, - 20059, -3183, -3183, 43809, 2329, 2330, 2792, 1903, 2343, 2343, - -3183, 407, -3183, -3183, 2761, 34068, 2719, 1187, 1070, 2346, - 1121, -3183, -3183, -3183, -3183, -3183, 1991, -3183, 43280, 2582, - 641, 2567, 2290, 20059, -3183, 2415, -3183, -3183, -3183, 2821, - -3183, -3183, 53262, 2344, -3183, 2235, 2136, 1946, 2235, 2571, - -3183, 2573, 2347, 43327, 68277, 68277, 1776, 34068, 68277, 2349, - 2343, -3183, 2350, -3183, -3183, -3183, 30045, -3183, 2351, -3183, - -3183, -3183, 20059, 166, -3183, -3183, 2402, 57765, 1142, 46, - 2564, 41100, -3183, 49748, 2909, 60, 2664, -3183, -3183, -3183, - -3183, 197, 2580, -3183, 2584, -3183, 47518, -3183, 1688, 53262, - -3183, -3183, -3183, -3183, -3183, -3183, 34068, 2740, -3183, 346, - -3183, 1586, -3183, 346, -3183, -3183, -3183, -3183, -3183, 1537, - 23755, 23755, 23755, 2354, 1688, -3183, 1586, -3183, 2487, 2567, - -3183, -3183, -3183, -3183, -3183, 200, 200, 2756, -3183, 2422, - -3183, 2235, 1146, 68277, 1880, -3183, 1880, 24811, 2513, 313, - 46391, 2735, -3183, 2735, 2735, -3183, -3183, -3183, 40095, -3183, - -3183, 2859, -3183, 242, -3183, -3183, -3183, 1776, 346, -3183, - -3183, 2849, -3183, -3183, -3183, -3183, -3183, 148, -3183, -3183, - -3183, 1586, 1070, -3183, -3183, -3183, 1586, 1880, 24283, 2519, - -3183, 2592, -3183, -3183, -3183, -3183, -3183, -3183, -3183 + 6054, 348, 823, -3162, -3162, 279, 348, 51623, 66578, 339, + 348, 118, 2095, 53619, -3162, -3162, 48130, 8709, 348, 56613, + 73974, 548, 689, 32620, 719, 57112, -3162, -3162, -3162, 66578, + 56613, 57611, 348, 359, 67077, -3162, 348, 35616, 54118, 453, + -3162, 56613, 47, 383, 58110, 56613, 3130, 946, 431, -3162, + -3162, -3162, -3162, -3162, 128, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, 159, -3162, 98, 174, 32620, 32620, 2484, 438, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, 498, + -3162, -3162, 807, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, 35116, -3162, -3162, -3162, -3162, -3162, -3162, 58609, 56613, + 59108, 54617, 59607, -3162, 727, 1020, 705, 152, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + 170, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, 512, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, 182, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, 399, -3162, 535, -3162, 188, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, 1886, -3162, -3162, 961, 2952, + 56613, 715, 753, 724, -3162, 60106, -3162, 712, 56613, -3162, + -3162, 729, 1039, 901, -3162, -3162, 55116, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, 48629, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, 868, -3162, -3162, 688, -3162, 124, -3162, -3162, + 709, 686, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, 791, -3162, -3162, -3162, 805, 67576, 60605, 61104, -3162, + 674, 2617, 9200, 73992, 31620, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, 498, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, 57112, 66578, + 720, 731, 1013, 736, 33618, 771, 36116, 776, 802, 1032, + 810, 814, 824, 841, 383, 32120, 699, 399, 704, 61603, + 61603, -22, 33119, 3628, -3162, 61603, 62102, -3162, 798, -3162, + 1020, -3162, -3162, -3162, -3162, -99, 845, -3162, 62601, 62601, + 62601, 836, 1087, 62601, -3162, -3162, -3162, 878, -3162, -3162, + 1097, 20189, 20189, 68075, 68075, 1020, 68075, 916, 68075, -3162, + -3162, 76, 705, -3162, 399, -3162, -3162, 2484, -3162, -3162, + 54118, -3162, -3162, 270, 1250, 20189, 56613, 926, -3162, 920, + 926, 936, 949, 977, -3162, 6054, 1328, 1209, 55615, 369, + 369, 1467, 369, 662, 701, 2582, 2099, -3162, 1234, -3162, + 1015, -3162, 56613, 57112, 1116, 1042, 1323, -3162, -3162, 1400, + 786, 1204, 1423, 1991, 1431, 788, 1434, 1240, 1440, 1532, + 31, -3162, 20189, 49128, 399, -3162, 11264, 20189, -3162, -3162, + -3162, 1176, -3162, -3162, -3162, -3162, -3162, 56613, 66578, 1108, + 1132, -3162, -3162, -3162, -3162, 1530, 1377, -3162, 1614, 68574, + -3162, -3162, 1197, 63100, 63599, 64098, 64597, 1585, -3162, -3162, + 1525, -3162, -3162, -3162, 1199, -3162, -3162, -3162, 168, 69073, + 1534, 1168, 105, -3162, 1547, 119, -3162, 1562, 1426, 14939, + -3162, 1363, -3162, -3162, -3162, 383, -3162, 377, -3162, -3162, + 45231, -3162, -3162, 73992, 1293, 1210, -3162, 20189, 20189, 1214, + 6413, 61603, 62102, 20189, 56613, -3162, 20189, 24914, 1218, 20189, + 20189, 12314, 20189, 30622, 61603, 3628, 1207, -3162, 567, -3162, + 56613, 1225, -3162, 1324, 1324, 359, 32620, 1546, 32120, 1324, + 1324, 1324, -3162, 1035, 1539, 1452, -3162, 32620, 1452, 1502, + 1254, 1572, 1452, -3162, 261, 1579, 1324, 36615, 1262, -3162, + 1324, 1512, -3162, -3162, 20189, 14939, 71568, 1784, -3162, -3162, + -3162, -3162, 1591, -3162, 66578, 1318, -3162, -3162, -3162, -3162, + -3162, -3162, 772, 1845, 165, 1851, 20189, 165, 165, 1339, + 190, 190, -3162, 1538, 1341, -3162, 198, 1347, 1349, 1863, + 1864, 167, 147, 1028, 165, 20189, -3162, 190, 1352, 1866, + 1356, 1868, 197, 207, -3162, 201, 20189, 20189, 20189, 305, + 20189, 10214, -3162, 49128, 1867, 56613, 590, -3162, 399, 1359, + 1020, -3162, -3162, -3162, -3162, -3162, -3162, -3162, 1360, -3162, + 185, 7096, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + 1394, -3162, -3162, -3162, -3162, 1577, 20189, -3162, -3162, 1358, + 1546, -3162, 205, -3162, -3162, 1546, -3162, -3162, -3162, -3162, + -3162, 218, -3162, 1779, 20189, 20189, -3162, 399, 69572, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, 536, -3162, 498, 515, + 46949, 1362, 1367, 926, 56613, 56613, 1847, -3162, -3162, -3162, + -3162, 54118, 144, 1668, 169, 1504, -3162, -3162, 2484, 2484, + 15464, 1290, 222, 549, 15989, 20714, 1724, 1607, 213, 600, + 1729, -3162, 1615, 1840, 24914, 20189, 20189, 662, 701, 20189, + 920, 122, -3162, -3162, -3162, 1665, 56613, 52122, 334, 778, + 1387, 1476, 1390, 91, 1816, -3162, 1389, -3162, 1482, 56613, + 73519, 226, -3162, 1856, 226, 226, 245, 1857, 1486, 233, + 1652, 67, -83, 1389, 4318, -3162, 54118, 150, 738, 1389, + 56613, 1488, 822, 1389, 1812, 66578, 1210, -3162, -3162, 42797, + 1398, -3162, -3162, -3162, 186, 14939, -3162, 971, 1202, 1208, + 367, 212, 1248, 1263, 14939, 1269, 1355, 200, 1361, 1380, + 1450, 1505, 1554, 1596, 1602, 1618, 134, 1643, 1666, 1680, + 1693, 1699, 1721, -3162, 1725, 202, 1727, 215, 14939, 1755, + -3162, 146, 46949, -1, -3162, -3162, 1761, 204, -3162, 47049, + -3162, 1701, 1493, 1494, 66578, 1448, 56613, 1550, 1422, 1780, + 1831, 72052, 1658, -3162, 1757, 56613, 1679, 4318, 1682, 1442, + 1921, 1688, 1132, 1691, 1449, -3162, 70071, 49128, -3162, -3162, + -3162, -3162, -3162, 1818, 1802, 66578, 49128, 1455, -3162, -3162, + 66578, -3162, 56613, 56613, -3162, 56613, 66578, -3162, 542, 46949, + 1963, 1022, 73992, 50625, -3162, -3162, -3162, -3162, 933, 939, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, 1020, + 49128, -3162, 3393, 45852, 1458, 20189, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, 1461, 1811, -3162, + -3162, 6931, 1465, 46147, 1468, 24914, 24914, 399, 2469, -3162, + -3162, 24914, 1469, 51124, 45766, 1464, 1470, 46332, 16514, 20189, + 16514, 16514, 46398, -3162, 1471, 46487, 61603, 1473, 56613, 30118, + -3162, -3162, -3162, 20189, 20189, 3628, 56114, 1515, 1477, -3162, + -3162, -3162, 32620, -3162, 32620, -3162, 1770, 32620, -3162, -3162, + 3794, -3162, 32620, 1772, 20189, 32620, -3162, 32620, 1717, 1719, + 1485, 32620, -3162, 56613, 1487, 56613, -3162, -3162, 46949, -3162, + 1484, 586, 1489, -3162, -3162, -3162, -3162, -3162, 1541, -3162, + 1541, 1541, -3162, -3162, -3162, -3162, 1492, 1492, 1495, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, 1496, 1028, -3162, 1541, -3162, 1492, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, 73519, -3162, -3162, -3162, -3162, + -92, -79, -3162, 1497, -3162, -3162, 1501, -3162, 1506, 1985, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, 8118, + 687, 1492, -3162, -3162, 4489, -3162, -3162, 20189, 20189, -3162, + -3162, 1507, 46949, 1552, -3162, -3162, 20189, 20189, -3162, -3162, + -3162, -3162, 2020, -3162, 20189, 1541, 1541, -3162, 6264, -3162, + 41607, 17039, 1601, 1604, 2020, -3162, 2020, -3162, 6264, 2021, + 2021, 1517, 37114, -3162, 1681, 46696, -3162, 1523, 1555, 7666, + 1520, -3162, -3162, 1524, -3162, 1526, 1518, 43734, 20189, 178, + 399, 399, 20189, -3162, 2020, 20189, 9122, 9122, -3162, 224, + 71568, 20189, 20189, 20189, 20189, 20189, 20189, 20189, 20189, 47631, + 1621, 136, 66578, 20189, 20189, 29608, 984, -3162, 20189, 1782, + -3162, 1548, 20189, 1628, 253, 20189, 20189, 20189, 20189, 20189, + 20189, 20189, 20189, 20189, -3162, -3162, 28589, 308, 520, 1871, + 1901, -10, 538, 20189, 1893, 11264, -3162, 1893, -3162, -3162, + -3162, -3162, -3162, 206, -3162, -3162, 1484, 1484, 66578, -3162, + 56613, 270, 53120, 20189, -3162, -3162, 1545, 1549, 599, 1612, + -3162, -3162, 56613, -3162, 40108, 1852, -3162, 332, 1558, -3162, + 45727, 1806, 1852, 2484, -3162, -3162, 25964, 1684, 1854, 1791, + -3162, -3162, 1771, 1774, -3162, 1561, 47138, 21239, 21239, -3162, + 1409, 46949, 1414, -3162, -3162, -3162, -3162, -3162, -3162, 671, + -3162, 56613, 99, 37613, -3162, 1563, 164, -3162, 2765, 1909, + 1872, 1724, 600, 1574, -3162, 57112, 57112, -3162, -3162, 1255, + 1573, 70570, 56613, 1869, 1819, 1873, -64, 71568, -3162, -3162, + -3162, -3162, 56613, 66578, 65096, 71069, 49627, 56613, 49128, -3162, + -3162, -3162, -3162, 56613, 890, 56613, 3834, -3162, -3162, -3162, + -3162, 226, -3162, -3162, -3162, -3162, -3162, 66578, 56613, -3162, + -3162, 226, 66578, 56613, 226, -3162, 1260, 56613, 56613, 56613, + 56613, 1332, 56613, 56613, 1020, -3162, -3162, -3162, 21764, 37, + 37, 1805, 1821, 1824, 1588, 12839, 146, -3162, 20189, 20189, + 325, 295, 66578, 1777, -3162, -3162, 692, 1832, 109, -3162, + 66578, 1649, 56613, 56613, 56613, 56613, 56613, 2508, -3162, -3162, + -3162, -3162, -3162, 1605, -3162, 1969, 2119, 1606, 1609, 1977, + -3162, 4318, 1981, 52621, 866, 3367, 1982, 1659, 1986, 13364, + -3162, -3162, 1622, -3162, -3162, 1624, 2107, 1874, -3162, -3162, + 1862, -3162, 66578, 2150, -3162, 105, -3162, 49128, -3162, 119, + -3162, 1870, 214, -3162, 14939, 20189, -3162, -3162, -3162, -3162, + -3162, -3162, 1210, 29099, -3162, 713, -3162, -3162, 2118, 1020, + 2118, 497, -3162, -3162, 2118, -3162, 2102, 2118, -3162, 71568, + -3162, 8056, -3162, 20189, 20189, -3162, 20189, 1990, -3162, 2152, + 2152, 71568, 24914, 24914, 24914, 24914, 24914, 24914, 199, 1352, + 24914, 24914, 24914, 24914, 24914, 24914, 24914, 24914, 24914, 26489, + 622, -3162, -3162, 749, 2125, 20189, 20189, 1999, 1990, 20189, + -3162, 71568, 1650, -3162, 1655, 1657, 20189, -3162, 71568, -3162, + 56613, 1661, -3162, -3162, -3162, 48, 1653, 1663, -3162, -3162, + 1546, -3162, 1060, 1064, 56613, 1978, 3821, 4733, -3162, -3162, + 20189, 1987, -3162, 3794, 3794, 32620, -3162, 20189, 1667, -3162, + -3162, 32620, 2010, -3162, 3794, -3162, -3162, 38112, 3794, 71568, + 756, -3162, 56613, 71568, 777, 20189, -3162, 14939, 2180, 71568, + 2145, 66578, 66578, 2184, 1672, 1673, 2020, 1759, -3162, 1763, + 1764, 1767, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, 71568, -3162, -3162, 158, -3162, -3162, -3162, -3162, + -3162, -3162, 1683, 1675, 20189, 20189, 62, -3162, 8203, 1687, + 1690, 6565, -3162, 1685, -3162, 1686, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, -3162, 1697, -3162, 1694, -3162, 1700, 1702, 1709, + 1704, 1705, 20189, 56613, -3162, 1698, 22289, 1848, 66578, -3162, + -3162, 20189, 20189, 56613, -3162, 2072, 46949, -3162, 1706, 1707, + 8647, -3162, -3162, -3162, 252, 737, 6322, 538, 3743, 3743, + 3743, 6264, -3162, -3162, -3162, 1731, -3162, 24914, 24914, -3162, + 4673, 3933, 10214, -3162, -3162, -3162, -3162, 2056, -3162, 665, + -3162, 1716, -3162, -3162, 4655, -3162, 41607, 7006, 20189, 163, + -3162, 20189, 29608, 20189, 1804, 3743, 3743, 3743, 333, 333, + 252, 252, 252, 737, 538, -3162, -3162, -3162, 1718, 20189, + 49128, -3162, 1720, 1722, 2082, 1356, 20189, -3162, -3162, 32620, + 1515, -1, 1515, 2020, 9122, -3162, 920, -3162, 920, -3162, + 46949, 56613, -3162, -3162, 1993, 1723, 32620, 1768, 2207, 2190, + 66578, -3162, -3162, 1728, 1893, 1744, -3162, -3162, 1750, 20189, + 3187, 1750, -3162, 1852, 19, 1964, 1014, 1014, 1409, 1966, + -3162, -3162, 1800, -3162, -3162, -3162, 20189, 13889, 1416, -3162, + 1420, -3162, -3162, -3162, -3162, -3162, 1736, -3162, 2016, -3162, + 56613, -3162, -3162, 24914, 2203, 20189, 38611, 2204, 2000, -3162, + -3162, -3162, 1798, 1798, -3162, -3162, 1838, 1389, 20189, 1996, + -3162, 115, 1758, 2123, 298, 2079, 66578, -3162, 316, 329, + -3162, 166, 2131, 214, 2132, 214, 49128, 49128, 49128, 779, + -3162, -3162, -3162, 1020, -3162, 12, 784, -3162, -3162, -3162, + -3162, 1858, 892, 1389, 4318, -3162, -3162, -3162, -3162, -3162, + -3162, -3162, 156, 956, 1389, 1859, -3162, 1875, -3162, 1878, + 958, 1389, -3162, -3162, 1532, 17564, 46949, 394, 146, 146, + 146, -3162, -3162, -3162, 14939, -3162, 1775, 46949, 46949, 151, + -3162, -3162, -3162, -3162, 1769, -3162, 352, -3162, 66578, -3162, + -3162, -3162, 1777, 1831, 1757, 56613, 4318, 1781, 2253, 1132, + 1449, -3162, 1940, 23, 902, -3162, 66578, -3162, 49128, 66578, + 56613, 56613, 56613, 65595, -3162, -3162, -3162, 1778, 1793, -3162, + -6, 2013, 2014, 56613, 1823, 56613, 1390, 2273, 56613, -3162, + 793, 1449, 1449, 18089, 2164, 56613, 1802, -3162, -3162, -3162, + -3162, 66578, -3162, -3162, 46949, -3162, 1790, -3162, 20189, 50126, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, 49128, -3162, 1020, + -3162, 1020, 2039, 66578, 44233, 1020, 44732, 1020, 1803, -3162, + 46949, 8811, 46949, 1999, -3162, 230, 2152, 1603, 1603, 1603, + 1289, 2149, 528, 1807, 1603, 1603, 1603, 277, 277, 230, + 230, 230, 2152, 622, 798, 51124, 1808, -3162, 46949, 46949, + -3162, -3162, 1813, -3162, -3162, -3162, -3162, 1814, 1826, -3162, + -3162, -3162, -3162, 66578, 157, 1515, 453, 453, 453, 453, + -3162, 56613, 56613, 56613, 46949, 2264, 2144, -3162, -3162, 3794, + 46949, 56613, -3162, 27539, -3162, 56613, -3162, 2168, -3162, 2257, + -3162, 56613, 800, -3162, -3162, -3162, 819, 1822, 1673, 71568, + 833, 861, -3162, 2020, 145, 1830, 1527, 992, 1075, 1435, + -3162, 54118, -3162, -3162, 1834, 46753, 20189, -3162, 2197, -3162, + -3162, -3162, 20189, 20189, -3162, 41607, -3162, -3162, -3162, -3162, + 131, 131, 8900, 1698, 1820, 1844, 56613, 10214, 46840, -3162, + 39110, -3162, -3162, 2166, 1829, -3162, 8978, 46949, -3162, 1681, + -3162, -3162, 9122, 20189, 2794, 5118, 20189, 1850, 20189, 2198, + -3162, -3162, 1853, -3162, -3162, 71568, 20189, 1855, 5420, 24914, + 24914, 5942, -3162, 6836, 20189, 10214, -3162, 42884, 1865, 1877, + 1805, 18614, -3162, 2084, 1876, -3162, 1987, 146, 1987, 1881, + -3162, -3162, -3162, -3162, 4489, -3162, 20189, 2026, 66578, 505, + 2525, 867, -3162, 399, 40108, 1768, 20189, 553, -3162, -3162, + 1885, -3162, 1750, -3162, -3162, -3162, 2100, -3162, -3162, -3162, + 56613, -3162, 1887, -3162, 37613, 2215, 10739, -3162, 37613, 56613, + -3162, -3162, 56613, 42114, 2252, -3162, 66578, 66578, 66578, -3162, + 66578, 1883, 1888, 266, 1894, 721, -3162, 2619, 266, 2235, + 275, 1390, 233, 2821, 61, -3162, -3162, -3162, 1971, 56613, + -3162, 66578, -3162, -3162, -3162, -3162, -3162, 49627, -3162, -3162, + 41107, 49128, -3162, 49128, 56613, 56613, 56613, 56613, 56613, 56613, + 56613, 56613, 56613, 56613, 1210, 20189, -3162, 20189, 1896, 1898, + 1900, 1805, -3162, 221, -3162, 1903, -3162, -3162, -3162, -83, + -3162, 352, 1902, 1906, -3162, 52621, 2952, 1659, -3162, 1624, + 1831, 379, 66079, -3162, 1907, 1905, 1757, 881, 883, 4318, + 1910, 2390, -3162, 866, 52621, -3162, -3162, -3162, 2345, -3162, + 674, 194, -3162, 1132, -3162, 2952, 1449, -3162, -3162, 2393, + -3162, 2394, 2952, 46949, 66578, 1979, -3162, 214, 889, -3162, + -3162, -3162, -3162, -3162, 66578, 1915, -3162, 1915, -3162, -3162, + 1915, -3162, -3162, -3162, -3162, 24914, 2266, 1924, 71568, -3162, + -3162, 56613, -3162, -3162, -3162, 893, 1926, 1987, 56613, 56613, + 56613, 56613, -3162, -3162, -3162, 19139, 20189, 1967, -3162, 1928, + 11789, 2251, -3162, 27014, -3162, -3162, 1933, 38112, 66578, -3162, + -3162, -3162, -3162, 2020, -3162, -3162, 66578, -3162, 1936, -3162, + 1937, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + 20189, 46949, -3162, 46949, -3162, -3162, -3162, -3162, -3162, 56613, + -3162, -3162, 7517, -3162, 1934, 1941, 66578, 56613, 231, -3162, + 20189, 66578, -3162, 1848, -3162, 390, 20189, 20189, 4673, -3162, + 43162, 20189, 71568, 897, 4673, 353, 20189, 5250, 5349, 20189, + 20189, 7468, 42153, -3162, 22814, 14414, -3162, 1942, 20189, 42192, + 40607, -3162, 32620, 2144, 1943, 2144, 1020, 1945, 46949, 20189, + -3162, -3162, -3162, -3162, 2002, 452, 34616, 2169, -3162, 1959, + 66578, -3162, 2026, 46949, -3162, -3162, 41607, -3162, -3162, -3162, + -3162, -3162, 2408, 2615, 1950, 1951, -3162, 1357, -3162, -3162, + 66578, 1953, -3162, 1955, 266, -3162, 66578, 1998, -3162, 286, + 2274, 117, -3162, 20189, -3162, 2370, 2451, 2619, 1974, 66578, + 56613, 24914, -3162, 302, 223, -3162, 2268, 56613, 1998, 2412, + -3162, -3162, -3162, 721, -3162, 2304, 2221, -3162, 226, -3162, + 20189, 721, 2224, 149, 66578, -3162, -3162, 2171, -3162, 71568, + 214, 214, -3162, 1489, 1988, 1994, 1995, 1997, 2001, 2003, + 2004, 2008, 2009, 2011, -3162, 2012, 2018, 2019, 2022, 2024, + 2025, 2027, 2028, 1496, 2029, -3162, 2032, 1885, 2033, 2034, + 2037, 2038, 2042, 72536, 2043, 2044, 2045, 2046, 1497, 2047, + 933, 939, -3162, -3162, -3162, -3162, -3162, -3162, 1168, 2050, + -3162, 2006, -3162, -3162, -3162, 2074, -3162, 2075, -3162, -3162, + -3162, -3162, -3162, -3162, 2005, 2017, -3162, -3162, -3162, 146, + 1992, 2052, 66578, 1210, 154, 49128, 66578, 2057, 1823, 2493, + 458, 2261, 2062, -3162, 1020, 2064, -3162, 1659, -3162, 52621, + 3754, 636, 2014, -3162, 273, 1823, -3162, 2468, 1659, 2103, + -3162, 1624, 2167, 20189, 155, -3162, 2295, 66578, 2069, -3162, + -3162, 50126, 1915, 5813, 24914, 71568, 908, 913, -3162, 2579, + 2237, 2144, -3162, -3162, -3162, -3162, -3162, 2076, -29, 2080, + 9689, 2078, -3162, -3162, -3162, -3162, -3162, -3162, 46949, 46949, + 66578, 2267, -3162, -3162, 2083, 2085, 39609, 2538, 2087, -3162, + -3162, 2403, -3162, 31121, -3162, 1673, 2091, 1673, 71568, 1673, + -3162, -3162, 46949, 1698, 20189, -3162, -3162, -3162, 2088, 2092, + 66578, 43181, 2421, -3162, -3162, 4673, 4673, 43162, 918, -3162, + 4673, 20189, 20189, 4673, 4673, 20189, -3162, 19664, 413, -3162, + 927, -3162, 42240, -3162, 73020, -3162, -3162, 1967, 1020, 1967, + -3162, -3162, 2098, -3162, -3162, -3162, 2163, -3162, -3162, 960, + 2535, 2026, 20189, -3162, -3162, 2108, 37613, -3162, -3162, -3162, + -3162, 37613, 266, -3162, 2286, 1998, 2117, -3162, -3162, -3162, + -3162, -3162, -3162, 42279, -3162, 79, 20189, -3162, 1038, 1289, + -3162, -3162, -3162, -3162, 1998, 1132, -3162, 56613, 2596, 2489, + -3162, -3162, 46949, -3162, -3162, 2020, 2020, -3162, -3162, 2257, + -3162, -3162, -3162, 2124, -3162, -3162, 1168, 95, 41107, 56613, + 56613, -3162, -3162, 2126, -3162, -3162, -3162, -3162, -3162, -83, + 2524, 983, 994, 866, -3162, 2952, 56613, 2497, 52621, -3162, + 49128, 2611, 2133, 56613, 1823, 1156, 1156, -3162, 2288, -3162, + 2289, -3162, -3162, 2620, 290, -3162, 1341, 56613, -3162, -3162, + 34117, -3162, 5813, 995, -3162, -3162, 2136, 2141, -3162, 1967, + 20189, 2143, 20189, -3162, 23339, 2622, 2142, -3162, 20189, 2206, + 28064, -3162, 20189, -3162, 56613, 61603, 2148, 61603, -3162, -3162, + -3162, -3162, 56613, -3162, -3162, -3162, 20189, -3162, 4673, 4673, + 4673, 20189, -3162, 20189, -3162, -3162, -3162, 2357, 2267, -3162, + 2267, 20189, 2952, 399, 4497, 66578, 18, -3162, 46949, -3162, + -3162, -3162, 56613, -3162, 49128, -3162, 266, -4, 2151, 20189, + 42632, 2392, -3162, -3162, 2429, -3162, 2488, -3162, 2223, 344, + 2240, -3162, -3162, -3162, -3162, 1210, 1020, -3162, 1659, 2014, + 2103, 2174, 56613, 1009, 2952, 866, 674, -3162, -3162, -3162, + -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, -3162, + 2952, 2613, 2396, 2621, -3162, 1979, 20189, 108, -3162, 1029, + 2614, -3162, -3162, 2687, 2267, 2179, 23339, 2183, -3162, 2185, + 66578, 46949, 2335, -3162, -3162, 2194, -3162, -3162, 20189, -3162, + -3162, 43238, 2192, 2199, 2655, 1805, 2206, 2206, -3162, 452, + -3162, -3162, 2629, 34117, 2590, 1132, 266, 2208, 1041, -3162, + -3162, -3162, -3162, -3162, 4318, -3162, 42719, 2455, 129, 2439, + 2151, 20189, -3162, 2290, -3162, -3162, -3162, 2690, -3162, -3162, + 52621, 2213, -3162, 2103, 2014, 1823, 2103, 2440, -3162, 2441, + 2217, 42758, 66578, 66578, 1659, 34117, 66578, 2218, 2206, -3162, + 2220, -3162, -3162, -3162, 30118, -3162, 2225, -3162, -3162, -3162, + 20189, 140, -3162, -3162, 2278, 56613, 1043, 74, 2429, 41107, + -3162, 49128, 1783, -4, 2537, -3162, -3162, -3162, -3162, 102, + 2456, -3162, 2457, -3162, 46949, -3162, 2952, 52621, -3162, -3162, + -3162, -3162, -3162, -3162, 34117, 2614, -3162, 332, -3162, 1515, + -3162, 332, -3162, -3162, -3162, -3162, -3162, 1464, 23864, 23864, + 23864, 2229, 2952, -3162, 1515, -3162, 2361, 2439, -3162, -3162, + -3162, -3162, -3162, 209, 209, 2630, -3162, 2297, -3162, 2103, + 1047, 66578, 1750, -3162, 1750, 25439, 2386, 193, 45805, 2610, + -3162, 2610, 2610, -3162, -3162, -3162, 40108, -3162, -3162, 2732, + -3162, 203, -3162, -3162, -3162, 1659, 332, -3162, -3162, 2723, + -3162, -3162, -3162, -3162, -3162, 162, -3162, -3162, -3162, 1515, + 266, -3162, -3162, -3162, 1515, 1750, 24389, 2397, -3162, 2466, + -3162, -3162, -3162, -3162, -3162, -3162, -3162 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -3183, -3183, -3183, 2014, 75, -3183, -3183, 185, -3183, -3183, - 589, -1723, -1721, 1083, -3183, 178, -822, 593, -3183, 83, - 3800, 2426, 3721, 946, -522, -900, -1279, 39, 92, -1159, - 7, -3183, -3183, -3183, -3183, -1544, -508, 250, -3183, -3183, - -643, -2705, -593, -3183, -3109, -3156, -3183, -3183, -735, -3112, - -2134, 93, -3183, -3183, 97, 1, -2210, -3183, -1739, 65, - -2200, -3183, -209, -2785, 103, 105, 993, -3183, -2672, 109, - -895, -1220, -925, -1214, -3183, -97, -3183, 500, 113, 1731, - 2074, -3183, 5, -2259, -3023, -597, -3183, -694, -3183, -342, - -3183, -641, -3183, -1172, -649, -683, -2947, -1189, -3183, 1713, - -397, -3183, 645, -3183, -2673, -3183, -3183, 628, -3183, 1156, - 1160, -3183, -3183, -2322, 175, -613, -2742, -2659, -2262, -914, - 264, -620, 237, -2157, -1470, -3183, 669, -3183, -603, -3183, - -909, -2137, 122, -3183, -3183, 1611, -891, -3183, 123, -3183, - 546, -3183, -2220, 547, -2219, 1646, -525, 10, 12, -3183, - -3183, -3183, -3183, -3183, -846, 590, -1237, -3183, 526, -3183, - -3183, -3183, -3183, -166, 227, -3183, 11, 742, -40, -31, - -3183, -24, -3183, -3183, -3183, 704, -3183, -3183, 8, 53, - 1810, -3183, -3183, -3183, -3183, -1058, -3183, -1678, 419, -3183, - 1972, 1973, -1794, -870, -15, 259, 745, -1704, -2206, -594, - 1208, 1790, 1788, -3183, 488, -2692, -3183, -558, -3183, -652, - -3183, -3183, -3183, 1978, -3183, 739, 1259, -1608, -1602, -3183, - -2309, -3183, -477, -362, -3183, -3183, -3183, -3183, -3183, -2554, - -2961, -590, 1228, -3183, 1799, -3183, -3183, -3183, -3183, 49, - -1580, 2980, 780, -3183, 89, -3183, -3183, -3183, -3183, 161, - -3183, 977, -164, -3183, -503, -686, -801, 2024, -92, 143, - -1770, -12, 58, 538, -3183, -3183, 541, -2153, -1449, 487, - -268, 975, -3183, 9, -1287, -3183, -1923, -1203, -3183, -3183, - -747, 2069, -3183, -3183, -3183, 2094, 2121, -3183, -3183, 2929, - 3534, -3183, -924, 3695, -680, -1057, 2037, -937, 2040, -949, - -940, -947, 2041, 2043, 2044, 2046, 2052, 2053, 2059, -1577, - 5090, 700, 4061, -2296, -3183, -1428, -1603, 1096, 1098, 1101, - 135, -3183, -1429, 213, -3183, -3183, -3183, -3183, -3183, -2858, - -3183, -436, -3183, -427, -3183, -3183, -3183, -1707, -3182, -1731, - -3183, 4415, 932, -3183, -3183, 486, -3183, -3183, -3183, -3183, - -1562, -3183, 5933, 814, -3183, -2080, -3183, -3183, -975, -837, - -775, -999, -1238, -1974, -3183, -3183, -3183, -3183, -3183, -3183, - -1531, -1821, -140, 875, -3183, -3183, 981, -3183, -3183, -3183, - -2523, -1517, -1753, -2159, -3183, -3183, -3183, 891, 1598, 129, - -842, -1661, -3183, -1566, -3183, -3183, 933, -2471, -3183, -3183, - 478, -2738, -3183, -3183, 173, -3183, -635, -1157, -2549, 2140, - 31, -3183, -793, -2636, -3183, -3183, -749, -2770, -1146, -894, - -3183, 127, -3183, 150, 128, -1733, -3183, 17, -3183, -387, - -3183, -3183, -2679, -3183, 136, 138, 2287, -3183, 1222, -3183, - -3183, -3183, -3183, -604, -3183, -654, -648, -3183, -3183, 25, - -901, 1710, -3183, 140, 367, -3183, 1037, -3183, 761, 141, - -3183, 2194, -361, 154, 1374, -3183, -3183, -3183, 14, -607, - 435, -3183, 1378, -3183, -3183, -667, -1685, 155, -3183, 536, - 15, -3183, -3183, -3183, 74, 156, 18, -2228, 159, -2911, - -1740, -7, -3183, -3183, -3183, -738, -3183, -2632 + -3162, -3162, -3162, 1891, 78, -3162, -3162, 103, -3162, 975, + -3162, 106, -797, 489, -3162, 82, 3221, 2609, 4184, 1298, + -520, -890, -1248, 24, 84, -1138, 3, -3162, -3162, -3162, + -3162, -1516, -560, 173, -3162, -3162, -697, -2619, -650, -3162, + -3037, -3092, -3162, -3162, -786, -3061, -2089, 86, -3162, -3162, + 90, 4, -2178, -3162, -1700, 63, -2168, 93, 94, 888, + -3162, -2620, 96, -884, -1212, -917, -1202, -3162, -169, -3162, + 401, 100, 1828, 1946, -3162, 5, -2220, -2969, -646, -3162, + -748, -3162, -400, -3162, -692, -3162, -730, -700, -729, -2891, + -1155, -3162, 1599, -447, -3162, 547, -3162, -2602, -3162, -3162, + 537, -3162, -1176, -3162, -2268, 88, -676, -2435, -2604, -2212, + -908, 171, -682, 148, -2171, -1048, -3162, 561, -3162, -664, + -3162, -899, -2099, 101, -3162, -3162, 1490, -932, -3162, 104, + -3162, 445, -3162, -2176, 446, -2175, 1519, -562, 8, 10, + -3162, -3162, -3162, -3162, -3162, -691, 487, -1228, -3162, 427, + -3162, -3162, -3162, -3162, -236, 135, -2296, 27, 3629, -44, + -18, -3162, 2, -3162, -3162, -3162, 594, -3162, -3162, 14, + 58, 1674, -3162, -1043, -3162, -1670, 763, -3162, 1841, 1842, + -1782, -875, -55, -3162, 641, -1682, -2174, -639, 1102, 1671, + 1676, -3162, 396, -2574, -3162, -610, -3162, 797, -3162, -3162, + 640, 1152, -1582, -1578, -3162, -2277, -3162, -527, -414, -3162, + -3162, -3162, -3162, -3162, -2576, -2932, -627, 1122, -3162, 1689, + -3162, -3162, -3162, -3162, 50, -1547, 2861, 679, -3162, 68, + -3162, -3162, -3162, -3162, 87, -3162, 870, -232, -3162, -492, + -681, -795, 1904, -496, 13, -1739, -12, -380, 437, -3162, + -3162, 441, -2105, -1445, 400, -329, 873, -3162, -63, -1266, + -3162, -1877, -1198, -3162, -3162, -772, 652, -3162, -3162, -3162, + 1544, 2347, -3162, -3162, 2552, 2561, -3162, -904, 2808, -799, + -1049, 1918, -938, 1919, -941, -928, -915, 1920, 1923, 1925, + 1927, 1929, 1931, 1932, -1548, 5255, -196, 1160, -2204, -3162, + -1430, -1598, 1001, 1003, 1005, 38, -3162, -1422, 210, -3162, + -3162, -3162, -3162, -3162, -2802, -3162, -487, -3162, -484, -3162, + -3162, -3162, -1692, -3161, -1732, -3162, -793, 816, -3162, -3162, + 397, -3162, -3162, -3162, -3162, -1534, -3162, 6195, 717, -3162, + -2037, -3162, -3162, -974, -809, -711, -1014, -1233, -1959, -3162, + -3162, -3162, -3162, -3162, -3162, -1522, -1807, -655, 773, -3162, + -3162, 874, -3162, -3162, -3162, 92, -1436, -1777, -2135, -3162, + -3162, -3162, 780, 1481, 52, -829, -1640, -3162, -1559, -3162, + -3162, 834, -2413, -3162, -3162, 392, -2682, -3162, -3162, 110, + -3162, -623, -1129, -2489, 559, 16, -3162, 1773, -2585, -3162, + -3162, -731, -2722, -1136, -898, -3162, 107, -3162, 350, 112, + -1652, -3162, 6, -3162, -443, -3162, -3162, -2634, -3162, 116, + 130, 2172, -3162, 1114, -3162, -3162, -3162, -3162, -601, -3162, + -630, -632, -3162, -3162, 28, -903, 1594, -3162, 132, 227, + -3162, 935, -3162, 698, 133, -3162, 2065, -408, 137, 1266, + -3162, -3162, -3162, 11, -621, 354, -3162, 1268, -3162, -3162, + 1714, 647, 138, -3162, 289, 17, -3162, -3162, -3162, 83, + 141, 7, -3030, 142, -2808, -1707, -7, -3162, -3162, -3162, + -719, -3162, -2565 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -2141 +#define YYTABLE_NINF -2102 static const yytype_int16 yytable[] = { - 529, 57, 969, 920, 1147, 65, 877, 53, 77, 724, - 68, 70, 69, 1251, 94, 99, 529, 82, 103, 1042, - 1271, 988, 1325, 1214, 1985, 1721, 863, 1847, 77, 1834, - 1455, 2245, 1328, 1179, 1818, 789, 2213, 1835, 527, 2664, - 1807, 2010, 1620, 2079, 1885, 783, 893, 1427, 861, 1429, - 2701, 2118, 1512, 894, 527, 723, 1428, 2048, 889, 1425, - 2130, 1381, 2635, 2370, 2637, 2294, 2169, 1801, 529, 529, - 1852, 1779, 815, 2146, 2147, 50, 2654, 1917, 2314, 2544, - 1364, 1370, 750, 51, 3109, 1387, 1250, 3076, 1256, 1698, - 1260, 3078, 52, 55, 1701, 1839, 2361, 56, 875, 910, - 2653, 2616, 3107, 59, 979, 60, 527, 527, 856, 61, - 3125, 982, 903, 63, 1271, 2895, 2350, 971, 3129, 2941, - 2756, 2217, 66, 67, 815, 815, 2967, 80, 81, 1020, - 2972, 2546, 2388, 1634, 2392, 1045, 83, 2387, 84, -1982, - 90, 91, 526, 2692, -1402, 2265, 3205, -2127, -2127, 1597, - 1598, -1982, 2171, 2268, 93, 98, 102, 1394, 822, 104, - 2358, 3202, -471, -1324, 890, 891, 1610, 2494, -388, -544, - 541, 2003, 1066, 1167, 2764, 2765, 2004, 1067, 3337, 989, - 2760, -1343, -898, 2564, 1785, -1343, -906, -1973, 2758, -1340, - -1340, -548, -1973, 1383, -1990, -903, 1439, 3323, 3268, -903, - -2118, -2118, -2136, -2136, 3, 4, -1344, -1990, 826, 2161, - 822, 822, 1066, -1344, -1341, -1341, -865, -878, 3341, -906, - -893, 826, 826, -2113, -2113, 867, -1161, 2751, 1358, 826, - 881, 2161, 1374, 1706, -1161, 2856, 824, 1066, 1702, 1374, - 826, 1160, -2138, -2138, 1066, 1654, 2776, 1262, 988, 1962, - 1656, 2200, 3679, 3251, 1964, 1066, 2525, 2526, 1166, 2201, - 2184, 1797, 3283, 3650, 1271, 1797, 1808, 2532, 1358, -544, - 1630, 2536, 1837, -497, 1850, 881, 2731, 1728, -1182, 1788, - 1664, 960, 3433, 826, 1851, 3420, -1182, 542, 824, 824, - 1014, -548, -244, 108, 1203, 2278, 2702, -244, 1206, 1742, - 2815, 2817, 1358, 2820, 2785, 1780, 3304, 1012, 2504, 1349, - -693, 2002, 1045, 1819, 1666, 1804, 1822, 1823, 886, 3625, - 3320, 882, 3617, 886, 1020, 3544, 2935, 1265, 2937, 3680, - 1602, 113, 1809, 3130, 1651, 1388, 2826, 1164, 2515, 2516, - 2517, 1168, 3010, 1169, 3504, 1743, 1612, 2695, 1350, 2002, - 3610, 3279, 1703, 1853, 2054, 1021, 2837, 3361, 3100, 3674, - -2112, -2112, -835, 3548, 2505, 1383, 882, 2148, 1472, 2981, - 1774, 1775, 1582, 1479, 3398, 1482, 3400, 2271, 3463, 1778, - 3208, 3232, 2210, 3234, 2185, 844, 948, 2240, 3464, 1193, - 3335, 1654, 3603, 3568, 1507, 1833, 1411, 1412, 2608, 1654, - 1739, 2186, 1625, 1655, 1656, 1805, 2187, 2703, 2299, 2299, - 1615, 1654, 2521, 1929, 1744, 114, 3011, 3265, 1066, 2384, - 3338, 3681, 1810, 3449, 3303, 949, 2609, 2467, 1898, 3277, - 2990, 2980, 1616, 1199, 1664, 3339, 2705, 3498, 1499, 3499, - 1790, 3331, 3336, 1857, 2188, 1383, 1664, 539, 1383, 1383, - 1725, 2627, 2522, 3343, 1538, 3661, 2991, 2963, 2495, -544, - 1666, 2768, 1328, 3332, 109, 1745, 3023, 1626, 1666, 2300, - 2689, 3512, 2241, 3651, 1811, 110, 1704, 3658, 1707, 3663, - 1666, -548, 3140, 2696, 3632, 884, -713, 845, 3633, 2827, - 1500, 1194, 3266, 2887, 3530, 2272, 3686, 1022, -835, 3131, - 3012, 3476, 1161, 3618, 3278, 2305, 1620, 3611, 1740, 1201, - 2506, 111, 3280, 951, 995, 3550, 1417, 1418, 115, 1854, - 3415, 1478, 3675, 2089, 1266, 1806, 1359, 1351, 3155, 1746, - 2692, -544, 2692, 3431, 2211, 3513, 3612, 1806, 793, 3425, - 1614, 3269, 1806, 3409, 3445, 1654, 2610, 1856, 3620, 1655, - 1656, 2611, 2051, -548, 935, 3465, 885, 1582, 2376, 2856, - 1791, 3652, 2582, 112, 1227, 883, 1359, 3121, 2744, 2745, - 2746, 1716, 3115, 868, 2279, 3505, 3134, 3135, 3682, 1162, - 1664, 1724, 2162, 1962, 2169, 1930, 1932, 1963, 1964, 3591, - 3653, 724, 1060, 1645, 1844, 961, -1161, 2540, 1597, 1598, - 1359, 3359, 2189, 1962, 2618, 1781, 969, 1963, 1964, 3317, - 2559, 1919, 1838, 1726, 1666, 3421, 2732, 1923, 2369, 2118, - 1776, 2202, 1994, 1610, 1777, 3101, 3592, 3340, 2704, 2585, - 2705, 2011, 2752, 2753, 886, 988, 543, 957, 3664, 2433, - 2915, 1170, 2639, 2265, 3492, 1352, 2824, 1593, -1182, 3441, - 2667, 1582, -544, 2035, 3626, -1982, 794, 3146, 2656, 2960, - 2706, 2772, 2766, 2462, 1607, 2779, 1615, -1982, -1402, 3076, - 2171, 825, 2739, 3078, -548, 2468, 1607, 918, 1835, -1324, - 2385, 919, 2662, 2871, 2100, 2101, -471, -471, 1616, 1324, - 1360, -544, -388, -544, 1109, 1110, 2439, -1343, -898, 1615, - 2216, -1343, 1617, -1973, 3412, 2496, 2612, 2475, -1973, 3413, - -1990, -903, 2501, -548, 3401, -548, 3259, 2613, 1927, 877, - 2756, 1616, -1344, -1990, 1649, 982, 2961, 1920, 3381, -1344, - 1363, 1599, 1600, 1605, 879, 1619, -893, 1699, 2218, 1199, - 1378, 1379, 71, 1271, 2142, 1271, 864, 1378, 1379, 898, - 1008, 1687, 987, 2086, 1630, 1979, 2537, 2850, 3292, 3293, - 2537, 3529, 71, 1630, 918, 814, 77, 2948, 919, 2742, - 877, 1829, 1050, 789, 3536, 2743, 3537, 2121, 1372, 71, - 2000, 1373, 1602, 1051, 984, 1199, 2102, 887, 876, 2558, - 1200, 2456, 529, 2103, 2104, 1830, 2457, 2105, 2106, 2107, - -244, -244, 1612, 529, 1829, 1026, 3564, 3565, 2172, 2143, - 529, 105, 2094, 2369, 3578, 1201, 2087, 814, 814, 892, - 1824, 870, 3250, 2949, 2124, 2093, 2125, 3241, 1830, 2025, - 527, 893, 2838, 2839, 2840, 2841, 2173, 2077, 894, 529, - 529, 527, 2936, 71, 2502, 2643, 1224, 1615, 527, 895, - 2476, 2042, 1225, 1165, 3150, 2144, 2458, 998, 3605, 1010, - 2477, 1201, 106, 529, 1202, 1797, 3242, 3601, 1797, 1616, - 2644, 1165, 3285, 3107, 880, 1027, 1798, 1582, 1215, 1800, - 3290, 57, 3252, 1617, 937, 65, 938, 53, 77, 2502, - 68, 70, 69, 1171, 94, 99, 2338, 82, 103, 1011, - 2723, 2424, 1684, 1685, 1686, 1687, 2341, 1311, 896, 2344, - 1202, 529, 724, 2724, 3392, 1317, 529, 2164, -2108, -2108, - 3393, 2337, 856, 856, 1180, 856, 2628, 856, 2857, 918, - 3332, 3432, 913, 1641, 822, 3076, 1642, 1487, 1918, 3078, - 3213, 3190, 1931, 1494, 3192, 822, 3194, 1066, 826, 3321, - 3579, 2174, 822, 2509, 1736, 50, 2175, 1226, 914, 2264, - 2264, 2176, 2291, 51, 939, 1825, 940, 2978, 1317, 2397, - 1224, 828, 52, 55, 1582, 1826, 1225, 56, 3676, 987, - 2362, 2363, 2364, 59, 877, 60, 529, 529, 3094, 61, - 3095, 3027, 529, 63, 2336, 529, 529, 77, 529, 529, - 529, 529, 66, 67, 789, 3418, 1327, 80, 81, 2444, - 3087, 2118, 824, 916, 2347, 529, 83, 529, 84, 2354, - 90, 91, 934, 824, 2906, 2432, 529, 2699, 1383, 2434, - 824, 1370, 2436, 2449, 93, 98, 102, 3580, 1383, 104, - 1591, 1383, 46, 529, 1317, 1585, 1682, 1683, 1684, 1685, - 1686, 1687, 826, 527, 1615, 527, 3525, 2414, -1982, 2415, - 1985, 1484, 915, 1918, 527, 529, 545, 23, 877, 2665, - 2661, 815, 922, 1010, 1066, 2640, 1616, 2641, 2339, 1742, - 2010, 1226, 815, 2342, 529, 3405, 1976, 1977, 1978, 1979, - 1619, -1388, 1808, 1608, 1609, 2455, 529, 529, 529, 2459, - 529, 529, 2461, 724, 1974, 1975, 1976, 1977, 1978, 1979, - 1645, 1475, 1582, 1011, 1227, 918, 2177, 2673, 1808, 919, - 2305, 2740, 1491, 1835, 918, 1743, -1324, 2178, 919, 546, - 2747, 884, -557, 1224, 918, 2510, 529, 2511, 1641, 1225, - 2204, 1383, 1224, 2716, 2205, 2718, -632, -557, 1225, 1635, - 2994, -632, -557, 941, 529, 529, 3508, 822, 1809, 822, - 2500, 2662, -2109, -2109, 1730, 1731, 545, 1737, 822, -220, - 946, 894, 894, 3223, 894, 3353, 1165, 1492, 1229, 2172, - 945, 1497, 1714, 2396, 1809, 1715, 2733, 1403, 1404, 2984, - 529, -2110, -2110, 2997, 529, 529, 988, 1031, 2512, 958, - 2513, 3450, 885, -557, 529, 529, 529, 2173, 953, 529, - 1230, 26, 27, 28, 3531, 1154, 1155, 2977, 1157, 2979, - 1159, 1840, -632, -557, 1924, 2786, 1224, 1925, 959, 546, - 1585, 2794, 1225, 1032, 962, 824, 1634, 824, 1227, 963, - 2050, 1836, 947, 2051, 1226, 1745, 824, 1843, 1810, 1485, - 964, 2562, 2857, 1226, 975, 3260, 3451, 1411, 1412, 1034, - 2866, -2111, -2111, 965, 1872, 3452, 1317, 2553, -631, 993, - 1582, -632, -557, -631, 1810, 994, 1317, 2985, 33, 995, - 886, -557, 1582, 1231, 996, 71, 2108, 2109, 2110, 3453, - 2111, 2112, 2113, 2114, 2115, 2116, 2075, 999, 1228, 2076, - 1811, 1317, 1229, 1873, 1196, 3312, 1198, 3590, 1002, 1746, - 3593, 2381, 1582, 550, 2382, 978, 38, 1003, 1993, 1582, - 1995, 1996, 2174, 1004, 1585, 3198, 1811, 2373, -2114, -2114, - 2606, 1879, 2176, 2450, 1230, 1880, 2451, 1226, 553, 3325, - 724, 554, 948, 2986, -631, 2987, 2636, 1882, 1883, 724, - 40, 3423, 2488, 1224, 2538, 2489, 3001, 2539, 1005, 1225, - 1006, 43, 3454, 1582, -2115, -2115, 987, 1582, 1806, 1054, - 1055, 1056, 2851, 1582, 1059, 3455, 2858, 1417, 1418, 1007, - 77, 949, 3151, 724, -2116, -2116, 1912, 789, 529, 1038, - 3672, 1875, 2541, -631, 1806, 2539, 1582, 1008, 984, 2079, - 2118, 1227, 2719, 3656, 1013, 2720, 3002, 1231, 1486, 2725, - 1227, 2797, 2726, 550, 2051, 978, 46, 950, 1015, 2863, - 1047, 2713, 2539, 2715, 3003, 2638, -2117, -2117, 3659, 1934, - 3660, 1057, 2864, 887, -557, 2076, 3074, 2676, 529, 529, - 1052, 554, 2867, 1058, 529, 2868, 529, 1060, 3635, 1061, - 1224, 529, 529, 529, 529, 1158, 1225, 2666, 2666, 2869, - 1181, 1254, 2868, 3647, 1226, 1229, 529, 529, 1174, 951, - 1258, 3685, 2955, 1182, 1229, 2956, 529, 3118, 529, 2763, - 3119, 529, 1184, 1237, 527, 3014, 529, 2177, 529, 529, - 3120, 529, 3021, 2382, 1227, 529, 3144, 1255, 2178, 3145, - 71, 876, 3093, 1238, 918, 1185, 1259, 1184, 919, 3152, - -2119, -2119, 3153, 1186, 527, 3013, 527, 3022, 3683, 527, - 1188, 2888, 2889, 3684, 527, 2950, 3004, 527, 3214, 527, - 1189, 2076, 815, 527, 815, 3103, 3005, 815, -2120, -2120, - 3307, 997, 815, 2243, 1197, 815, 1216, 815, 1219, 1239, - 1585, 815, 1009, 3354, 2290, 1222, 2076, 3355, 1229, 1025, - 2539, 1226, 3387, 3394, 1808, 2076, 2051, 1221, 3406, 1223, - 1231, 3407, 2026, 3439, 2027, 1235, 3119, 2029, 3456, 1231, - 23, 3457, 2033, 529, 529, 2036, 3440, 2037, 822, 2382, - 1230, 2041, 529, 529, 2078, 77, 1236, 2080, 2082, 2081, - 529, 2084, 2085, 113, 892, 1630, 2875, 529, 2877, 2879, - 2880, 1634, -2121, -2121, 529, 2876, 2878, 2874, 822, 3017, - 822, 1227, 71, 822, 3473, 946, 3534, 2076, 822, 3119, - 1809, 822, 1253, 822, 724, 529, 1257, 822, 3494, 529, - 3495, 3546, 529, 3572, 3547, 1240, 3573, 1585, 529, 529, - 529, 529, 529, 529, 529, 529, 724, 1808, 2266, 2267, - 529, 529, 529, 1231, 3616, 529, 824, 3547, 3657, 529, - 1261, 3547, 529, 529, 529, 529, 529, 529, 529, 529, - 529, 2345, 1484, 529, 1311, 1229, 2807, -2122, -2122, 1263, - 529, 1320, 1317, 2730, 1241, 923, 824, 947, 824, 1323, - 527, 824, 2158, 1448, 1242, 988, 824, 2247, 1324, 824, - 529, 824, 2951, 1329, 894, 824, 1243, 2346, 1227, 1331, - 1810, 924, 1335, 1809, 26, 27, 28, 1582, -2123, -2123, - 1345, 71, -2124, -2124, 529, 1347, -557, 117, 3297, 991, - 1171, 540, 2213, 2662, 1348, 529, 529, 1355, 1244, 754, - 1356, -557, -2125, -2125, 2142, 1362, -557, 1365, 2870, 2872, - -2126, -2126, 1366, 843, 814, 1371, 1009, 857, -2128, -2128, - 1389, 1049, 1811, -2129, -2129, 814, -2130, -2130, 2352, 1390, - 1808, 1395, 1229, -2131, -2131, 1585, 2734, 925, -2132, -2132, - 1231, 33, -2133, -2133, 1453, 724, 1156, 1872, 1466, 724, - -2135, -2135, 1468, 1246, -2137, -2137, 1469, -557, 1476, 3021, - 1592, 1480, 1065, 1810, 2353, 1962, 926, 1489, 1031, 1963, - 1964, 1488, 1604, 1965, 1966, 1967, 1495, -557, 1247, 38, - -2140, -2140, 1859, 1860, 1496, 2971, 1873, 1808, 1506, 2305, - 1806, 2320, 529, 1502, 828, 2326, 1809, 1508, 1249, 1317, - 1632, 1587, 529, 529, 1032, 1588, 23, 2054, 3110, 927, - 23, -688, -688, 40, 1590, 1811, 3316, 1582, -692, -692, - 1493, -869, 1874, -876, 43, 1599, -557, 3099, 1603, 3132, - 1034, -691, -691, 1413, 1414, -557, 46, 1231, 1417, 1418, - 3081, 44, -866, 1317, -713, 3634, 3256, 3257, -714, 3636, - 2799, 2801, -867, 1809, 3643, 3644, 3380, 2418, 1613, 2738, - -870, 724, 3669, 3670, 1614, 45, 3143, -868, 1317, 529, - 1621, 3472, 1710, 1711, 1875, 2681, 2682, 987, 3225, 2952, - 1383, 1636, 1380, 1806, 1582, 1646, 1810, 892, 892, 1648, - 892, 1693, 1423, 1585, 1695, 545, 1697, 529, 529, 1709, - 529, 1717, 1718, 1722, 3677, 1585, 529, 529, 529, 529, - 529, 529, 1727, 1729, 529, 529, 529, 529, 529, 529, - 529, 529, 529, 529, 1200, 1764, 1202, 1766, 1768, 529, - 529, 1783, 1802, 529, 1803, 1585, 1813, 928, 1811, 1814, - 529, 1815, 1585, 1810, 1820, 1827, 1828, 1842, 929, 1832, - 26, 27, 28, 1968, 26, 27, 28, 2417, 546, 2662, - 1038, 1862, 1849, 1863, 529, 1864, 1868, 1871, 3074, 1877, - 1878, 529, 1887, 529, 1886, 1890, 1969, 529, 23, 1486, - 1896, 1237, 1893, 1897, 930, 1894, 1585, 1899, -557, 1918, - 1585, 1900, 529, 1582, 1317, 1811, 1585, 1913, 1914, 1926, - 1951, 1238, 1953, 1954, 1956, 2001, 1806, 931, 1959, 527, - 1982, 1991, 1990, 1647, 1998, 527, 2021, 33, 2023, 1585, - 2024, 33, 3191, 1650, 2028, 2034, 3472, 815, 2038, 2039, - 2040, 529, 529, 815, 2052, 2049, 932, 2046, 1600, 3288, - 1605, 1593, 2053, 2055, 545, 1700, 1970, 1239, 3437, 2056, - 2057, 2058, 2088, 2089, 1705, 38, 1066, 2122, 918, 38, - 1654, 3189, 919, 1806, 71, 2127, 2123, 2527, 3472, 2137, - 529, 2134, 2131, 2530, 529, 2136, 2160, 877, 2010, 529, - 529, 2138, 2180, 2139, 2183, 3298, 3299, 2181, 2207, 40, - 2208, 1326, 2214, 40, 2228, 1960, 1961, 2226, 1582, 2227, - 43, 1981, 2229, 563, 43, 529, 529, 546, 2230, 755, - 529, 885, 2243, 822, 2246, 2255, 2256, 3472, 2257, 822, - 831, 44, 26, 27, 28, 2258, 529, 2259, 2260, 529, - 529, 529, 2277, 2281, 874, 874, 2282, 2285, 2292, 1634, - 2296, 2298, 550, 1240, 978, 45, 2297, 529, 724, 886, - 3527, 2306, 2324, 1065, 529, 46, 1962, 529, 1845, 46, - 1963, 1964, 2325, 2329, 1965, 1966, 1967, 3488, 527, 2330, - 554, 1383, 2365, 529, 2366, 814, 1383, 814, 2367, 2379, - 814, 548, 2383, 2398, 1582, 814, 529, 2389, 814, 33, - 814, 824, 1241, 2400, 814, 527, 3274, 824, 2401, 906, - 2402, 2403, 1242, 529, 529, 2404, 2405, 2419, 2422, 2420, - 2425, 527, 2426, 815, 1243, 2427, 2429, 2428, 2431, 2435, - 529, 2452, 529, 2460, 1987, 1930, 1932, 38, 1962, 815, - 2490, 1986, 2519, 2497, 3074, 529, 2531, 2543, 2545, 2507, - 1326, 2498, 2550, 2499, 2561, 2503, 1244, -219, 2508, 724, - 2551, 14, 15, 2529, 2552, 2554, 2555, 2556, 724, 724, - 724, 40, 1971, 1972, 1973, 2557, 1974, 1975, 1976, 1977, - 1978, 1979, 43, 2560, 2568, 1065, 2572, 2569, 1962, 71, - 2576, 2571, 1963, 1964, 2574, 1933, 1965, 1966, 1967, 44, - 2575, 550, 2577, 551, 826, 1582, 2578, 23, 2573, 822, - 2579, 1246, 529, 2908, 2320, 2320, 2320, 2585, 877, 2589, - 1835, 1317, 2599, 45, 1626, 822, 2600, 2614, 3426, 554, - 2607, 2623, 2624, 2602, 2629, 2630, 1247, 46, 2631, 2642, - 1582, 2647, 2649, 2650, 2655, 2657, 2658, -694, 1879, 2668, - 2669, 2672, 1880, 2675, 2280, 724, 1249, 2679, 2680, 1781, - 1585, 2683, 2685, 2671, 1882, 1883, 2687, 988, 2688, 2691, - 2712, 2168, 2714, 2727, 2729, 2735, 2736, 1969, 2737, 2762, - 529, 2728, 2767, 2787, 2748, 2749, 2788, 824, 2761, 2791, - 2783, 2784, 1806, 525, 536, 529, 987, 2795, 2804, 561, - 1607, 2773, 2814, 824, 724, 561, 1582, 1645, 2822, 812, - 2825, 827, 2828, 3333, 2832, 830, 561, 839, 2831, 2845, - 839, 2846, 2848, 859, 859, 14, 15, 859, 2859, 1582, - 561, 561, 2833, 2834, 23, 2849, 2860, 2865, 2873, 2884, - 892, 2881, 529, 2892, 2902, 2891, 2913, 1970, 2926, 2911, - 1934, 26, 27, 28, 2903, 2914, 2934, 2917, 2932, 1930, - 1932, 812, 812, 2942, 2945, 2142, 2938, 2927, 2943, 2962, - 2964, 23, 1383, 1582, 2968, 2966, 2976, 2983, 2989, 2982, - 527, 3009, 3025, 3477, 529, 3479, 3096, 859, 3097, 3098, - 3487, 3102, 3105, 3106, 859, 561, 859, 859, 859, 1969, - 1585, 3113, 3114, 3122, 3123, 3128, 877, 1165, 3136, 3137, - 3141, 2382, 3148, 3149, 3174, 3154, 3177, 529, 33, 1653, - 3181, 3185, 1654, 529, 529, 3195, 1655, 1656, 3196, 35, - -2141, -2141, -2141, 3200, 3489, 3199, 3491, 3226, 3233, 529, - 3236, 3240, 3237, 3247, 877, 3249, 3253, 3609, 3267, 3254, - 3255, 3263, 37, 3570, 3271, 529, 38, 1664, 529, 3261, - 529, 3262, 3272, 3273, 1665, 3281, 3284, 1585, 529, 1970, - 3286, 529, 529, 3308, 2929, 3287, 529, 529, 26, 27, - 28, 3574, 3306, 529, 822, 1582, 2399, 3563, 3291, 3309, - 40, 1666, -2107, -2108, -2109, 3305, -2110, 2970, 71, -2111, - 529, 43, 3324, -2112, 3326, -2113, -2114, -2115, 3558, -2116, - 529, -2117, -2119, 2219, -2120, 26, 27, 28, 44, 3310, - -2121, -2122, 2954, 2469, 2470, 2471, 2472, 2473, 2474, -2123, - 529, 2478, 2479, 2480, 2481, 2482, 2483, 2484, 2485, 2486, - 2487, -2124, 45, 3342, -2125, 33, -2126, -2128, -2129, -2130, - -2131, -2132, -2133, -2134, -2135, -2136, 46, -2137, 3327, -2138, - 955, -2139, 824, 1971, 1972, 1973, -2140, 1974, 1975, 1976, - 1977, 1978, 1979, 724, -1341, 3313, 3077, 724, 3344, 724, - 529, 529, 33, 38, 3311, 3314, 2287, 2289, 1667, 3322, - 3329, 3346, 3347, 35, 529, 3356, 529, 3357, 3350, 3360, - 3364, 3362, 3368, 3374, 3371, 1668, 3370, 3376, 3375, 3379, - 1669, 3386, 3382, 3403, 3383, 3402, 37, 40, 3408, 2320, - 38, 3404, 3139, 3079, 3411, 2326, 529, 1879, 43, 3414, - 814, 1880, 545, 3108, 3428, 3416, 814, 3429, 1383, 3438, - -1340, 3436, 3444, 1882, 1883, 44, 3446, 3460, 1672, 3461, - 2357, 3447, 3462, 3474, 40, 3598, 23, -1388, 3475, 3481, - 3478, 3482, 3490, 3484, 3496, 43, 3133, 2374, 2374, 45, - 3280, 3516, 877, 3520, 3522, 3523, 3526, 3539, 529, 3532, - 3544, 1585, 44, 46, 3540, 1971, 1972, 1973, 3541, 1974, - 1975, 1976, 1977, 1978, 1979, 546, 3549, 3551, 529, 529, - 3553, 529, 3229, 1675, 3556, 529, 45, 3557, 529, 3560, - 3561, 3562, 3569, 1028, 3567, 3576, 3571, 3581, 1029, 3587, - 46, 3588, 2603, 2604, 3594, 3589, 3595, 3614, 3596, 3624, - 3627, 3604, 3606, 3608, 3629, 529, 3645, 3648, 3625, 3626, - 1380, 2994, 3662, 3667, 3673, 3678, 2454, 2995, 3687, 977, - 3688, 1582, 3024, 974, 1187, 529, 2700, 2332, 3028, 3503, - 2996, 529, 529, 2710, 3602, 2957, 529, 1585, 3566, 1632, - 3330, 529, 877, 3671, 529, 529, 1028, 1030, 2437, 529, - 1317, 1029, 3294, 529, 2997, 3585, 2998, 529, 3501, 2168, - 2806, 1163, 3655, 3424, 3623, 3630, 3649, 1795, 529, 3459, - 26, 27, 28, 2690, 2717, 2625, 1677, 920, 2302, 1237, - 2078, 77, 2303, 2080, 2082, 2081, 814, 2084, 2085, 3127, - 3621, 2993, 3628, 3080, 2686, 527, 1916, 3619, 549, 1238, - 859, 2798, 814, 2800, 1876, 859, 2757, 2811, 859, 3351, - 1030, 2674, 529, 815, 3104, 2284, 561, 3082, 2660, 1031, - 529, 1719, 1760, 1473, 1474, 1761, 2836, 1210, 3607, 2670, - 2252, 3552, 3480, 816, 2283, 1653, 1765, 33, 1654, 529, - 2646, 874, 1655, 1656, 2999, 1239, 3184, 2535, 1585, 550, - 1503, 978, 1440, 1475, 3378, 1032, 2862, 2830, 3430, 2829, - 2446, 2549, 2447, 1424, 3296, 2448, 1426, 1430, 552, 1431, - 1432, 1033, 1433, 1664, 553, 38, 3555, 554, 1434, 1435, - -2141, 1034, 1031, 3077, 3554, 1436, 1678, 2886, 2663, -2141, - -2141, -2141, 2621, 1682, 1683, 1684, 1685, 1686, 1687, 822, - 2597, 2565, 2012, 2598, 3239, 2619, 2905, 1666, 3209, 40, - 3542, 992, 3000, 1928, 2377, 1035, 2542, 3001, 1032, 2222, - 43, 2958, 1218, 3238, 2224, 0, 0, 0, 724, 0, - 0, 0, 0, 0, 1033, 0, 1211, 44, 0, 0, - 0, 1240, 724, 0, 1034, 0, 0, 0, 0, 1585, - 0, 1574, 0, 0, 877, 0, 0, 0, 0, 0, - 529, 45, 1036, 0, 3334, 0, 0, 3002, 987, 1037, - 876, 529, 1585, 0, 2773, 46, 1576, 824, 1035, 0, - 0, 0, 0, 0, 0, 3003, 0, 529, 2773, 0, - 1241, 0, 0, 0, 0, 0, 0, 0, 0, 2030, - 1242, 0, 0, 1577, -2141, 0, 0, 967, 561, 561, - 0, 1038, 1243, 0, 0, 0, 1585, 0, 0, 0, - 0, -2141, 529, 0, 0, 1036, -2141, 0, 0, 0, - 1039, 0, 1037, 0, 0, 0, 0, 0, 0, 529, - 529, 0, 0, 529, 1244, 529, 0, 0, 0, 990, - 536, 0, 0, 0, 0, 525, 0, 859, 0, 0, - 0, 0, 0, 0, -2141, 0, 812, 0, 0, 0, - 1017, 1017, 529, 812, 1038, 0, 1017, 1044, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 3004, 0, 839, - 839, 839, 0, 1039, 839, 0, 529, 3005, 2721, 1246, - 0, 1040, 1113, 1113, 839, 839, 1212, 839, 0, 839, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1675, - 0, 859, 0, 0, 1247, 0, 0, 561, 3077, 0, - 0, 0, 0, 0, 545, 0, 1574, 0, 0, 859, - 0, 0, 0, 0, 1249, 0, 0, 0, 2919, 2920, - 0, 874, 724, 859, 827, 0, 2754, 0, 1632, -1388, - 0, 1576, 0, 0, 1040, 3442, 0, 0, 1065, 2031, - 0, 1962, 0, 529, 2769, 1963, 1964, 0, 0, 1965, - 1966, 1967, 0, 529, 0, 529, 0, 529, 1577, 859, - 1322, 529, 0, 529, 0, 529, 1632, 546, 2773, 0, - 0, 1333, 0, 0, 0, 859, 859, 859, 859, 529, - 0, 527, 0, 0, 529, 0, 529, 0, 0, 1380, - 0, 1354, -2141, 71, 0, 0, 529, 0, 0, 2812, - 1574, 2813, 0, 0, 0, 2818, 0, 2821, 0, 724, - 0, 0, 1237, 0, 529, 3500, 0, 3502, 0, 2969, - 0, 547, 0, 1017, 1044, 1576, 859, 0, 0, 1447, - 0, 3622, 1238, 0, 0, 1017, 1017, 0, 0, 0, - 0, 548, 561, 0, 0, 0, 0, 0, 812, 0, - 812, 0, 1577, 0, 0, 3509, 0, 3535, 0, 812, - 0, 529, 0, 0, 0, 0, 0, 0, 0, 561, - 0, 529, 0, 3538, 0, 0, 0, 0, 1239, 3015, - 0, 0, 0, 529, 1065, 822, 1589, 1962, 0, 3016, - 0, 1963, 1964, 0, 0, 1965, 1966, 1967, 529, 0, - 549, 0, -2141, 1921, 71, 1922, 0, -219, 0, 1682, - 1683, 1684, 1685, 1686, 1687, 0, 529, 0, 0, 0, - 0, 1065, 0, 0, 1962, 3147, 0, 0, 1963, 1964, - 0, 0, 1965, 1966, 1967, 0, 527, 71, 561, 0, - 529, 0, 0, 0, 3138, 0, 0, 0, 3017, 2909, - 0, 550, 1969, 551, 0, 529, 0, 0, 0, 0, - 0, 0, 0, 824, 3077, 0, 724, 0, 0, 0, - 552, 0, 0, 0, 1240, 0, 553, 0, 527, 554, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 529, - 0, 1713, 0, 0, 1632, 0, 0, 0, 0, 3631, - 0, 0, 0, 529, 529, 529, 0, 561, 561, 0, - 0, 0, 3509, 0, 859, 0, 0, 0, 0, 0, - 0, 1653, 1970, 1241, 1654, 3646, 1574, 527, 1655, 1656, - 529, 0, 0, 1242, 0, 0, 0, 1447, 1113, 1113, - 822, 0, 0, 0, 0, 1243, 0, 3018, 0, 859, - 1794, 1576, 0, 0, 0, 0, 0, 0, 0, 1664, - 0, 0, 859, 0, 0, 0, -2141, 0, 0, 3070, - 0, 529, 0, 0, 0, 0, 814, 1244, 1577, 859, - 0, 0, 822, 859, 0, 71, 0, 0, 0, 1846, - 0, 0, 0, 1666, 876, 0, 0, 3276, -2141, 0, - 0, 0, 0, 2754, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1065, 0, 0, 1962, 824, 0, - 0, 1963, 1964, 1574, 0, -2141, -2141, -2141, 0, 0, - 0, 822, 1246, 0, 562, 1969, 0, 0, 0, 0, - 562, 0, 0, 0, 813, 0, 0, 0, 1576, 0, - 1865, 562, 859, 0, 0, 0, 0, 1247, 2605, 0, - 824, 859, 1028, 0, 0, 562, 562, 1029, 1970, 0, - 0, 0, 1909, 0, 0, 1577, 0, 1249, 0, 3019, - 0, 967, 3020, 0, 0, 0, 967, 0, 561, 561, - -2141, 561, 967, 0, 0, 0, 813, 813, 0, 0, - 0, 0, 0, 0, 0, 1970, 0, -2141, 0, 824, - 0, 0, -2141, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1030, 0, 0, 0, - 562, 0, 0, 0, 0, 0, 0, 858, 1971, 1972, - 1973, 866, 1974, 1975, 1976, 1977, 1978, 1979, 3352, 0, - -2141, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1574, 0, 0, 0, 71, 0, 0, 0, 0, - 0, 1447, 1447, 0, 0, 0, 0, 1447, 0, 525, - 0, 0, 0, 0, 3235, 0, 1576, 0, 0, 0, - 0, 0, 1017, 1806, 561, 2005, 0, 0, 1031, 1113, - 1113, 902, 859, 0, 0, 1675, 1632, 0, 905, 812, - 908, 812, 912, 1577, 812, 0, 0, 0, 0, 812, - 0, 1113, 812, 0, 812, 0, 0, 2295, 812, 0, - 561, 0, 561, 0, 1032, 0, 0, 0, 2309, 0, - 2312, 0, 0, 2323, 0, 0, 0, 0, 0, 0, - 1033, 0, 0, 2331, 0, 2333, 0, 0, 0, 0, - 1034, 0, 0, 0, 0, 0, 0, 0, 2340, 0, - 0, 0, 0, 2343, 0, 0, 0, 2348, 2349, 0, - 2351, 1579, 2355, 2356, 1971, 1972, 1973, 0, 1974, 1975, - 1976, 1977, 1978, 1979, 1035, 0, 0, 0, 1970, 0, - 0, 0, 0, 0, 0, 0, 0, 0, -2141, 0, - 0, 0, 0, 0, 0, 1213, 0, 0, 0, 1574, - 0, 1971, 1972, 1973, 0, 1974, 1975, 1976, 1977, 1978, - 1979, 1574, 0, 0, 0, 0, 0, 0, 0, 2117, - 0, 1036, 1653, 0, 1576, 1654, 0, 0, 1037, 1655, - 1656, 0, 561, 1659, 1660, 1661, 1576, 0, 0, 0, - 3328, 1574, 0, 0, 0, 0, 71, 0, 1574, 0, - 1662, 1577, 0, 0, 0, 0, 0, 0, 0, 0, - 1664, 0, 0, 1577, 0, 0, 1576, 1665, 3466, 0, - 1038, 1380, 967, 1576, 0, 1447, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1039, - 0, 0, 1574, 1577, 1666, 0, 1574, 0, -2141, 0, - 1577, 0, 1574, 1113, 0, 1682, 1683, 1684, 1685, 1686, - 1687, 0, 0, 0, 0, 0, 0, 1576, 2220, 0, - 859, 1576, 859, 0, 0, 1574, 71, 1576, 71, 0, - 0, 0, 0, 859, 0, 2235, 0, 0, 0, 0, - 0, 0, 1937, 0, 1577, 0, 1579, 1447, 1577, 0, - 1576, 0, 0, 0, 1577, 0, 0, 0, 0, 3399, - 1040, 0, 1028, 0, 0, 0, 0, 1029, 71, 0, - 0, 0, 859, -1863, 561, 0, 0, 1577, 0, 0, - 0, 0, 0, 0, 71, 0, 2286, 2288, 0, 1938, - 0, 1667, 1794, 561, -2141, -2141, -2141, 0, 1974, 1975, - 1976, 1977, 1978, 1979, 561, 2310, 561, 1794, 1668, 561, - 1939, 0, 0, 1669, 0, 0, 0, 0, 0, 561, - 0, 561, 0, 0, 0, 0, 1030, 0, 1940, 0, - 0, 3070, 1941, 967, 561, 0, 1670, 1671, 967, 561, - 1579, 0, 0, 561, 561, 1794, 561, 0, 561, 561, - 0, 1672, 0, 0, 0, 1942, 1653, 0, 1943, 1654, - 0, 562, 0, 1655, 1656, 0, 0, 0, 0, 2378, - 0, 0, 0, -1863, 1944, 0, 0, 1333, 0, 859, - 859, 859, 859, 859, 0, 0, 0, 0, 0, 1673, - 0, 0, 1674, 0, 1664, 0, 0, 0, 1031, 0, - 2407, -2141, 0, 0, 0, 0, 1675, 0, 0, 1676, - 71, 0, 0, 0, 0, 0, 0, 0, 0, 2430, - -1863, 0, 0, 0, 936, 0, 0, 0, 1666, 943, - 0, 0, 944, 0, 1032, -1863, 71, 0, 0, 0, - -1863, 0, 0, 0, 0, -1863, 1921, 0, 0, 0, - 1033, 0, 0, 0, -1863, 0, 0, 0, 0, -1863, - 1034, 0, 0, 0, 3528, 0, 0, 1945, 0, 1447, - 1447, 1447, 1447, 1447, 1447, 1946, 0, 1447, 1447, 1447, - 1447, 1447, 1447, 1447, 1447, 1447, 1447, 0, 0, 0, - 0, -1863, 0, 2615, 1035, 0, 0, 1947, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 561, 0, 1677, - 0, -1863, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 859, 0, 0, 0, -2141, 0, 1948, 0, 0, - 0, 0, 0, 0, 812, 0, 0, 0, 0, 0, - 812, 1036, -2141, 0, 0, 0, 561, -2141, 1037, 0, - 0, 11, 561, 562, 562, 0, 1574, 0, 0, 0, - -1863, 2547, 2547, -1863, 0, 0, 1579, 0, 0, -1863, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, - 15, 1576, 0, 0, 0, -2141, 0, 0, 0, 0, - 1038, 0, 0, 0, 0, 0, 0, 3070, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1577, 1039, - -1863, 813, 0, 0, 0, 0, 0, 0, 0, 1678, - 0, 0, 1679, 1680, 1681, 23, 1682, 1683, 1684, 1685, - 1686, 1687, 0, 0, 561, -1863, 0, 2790, 0, 2591, - 1675, 0, 0, 0, 561, 1065, 0, 0, 1962, 0, - 0, 0, 1963, 1964, 0, 0, 1965, 1966, 1967, 0, - 0, 0, 0, 1579, 0, 0, 1580, 0, 1447, 1447, - 0, 0, 562, 3216, 0, 0, 0, 0, 0, 0, - 1040, 1001, 0, 0, 0, 0, 0, 2117, 0, 0, - 0, 0, 0, 1447, 864, 0, 1574, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 812, 1576, -1863, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 561, -1863, 0, 0, 812, 0, 0, 0, - 2235, 0, 0, -2141, 0, 0, 0, 0, 1577, 0, - 0, 0, 0, -1863, 0, -1863, -1863, 0, 0, 0, - 0, 0, 0, 1574, 0, 0, 0, 0, 0, 26, - 27, 28, 0, 0, 0, 0, 0, 1217, 0, 0, - 561, 0, 0, 1447, 0, 1113, 561, 0, 1576, 0, - 0, 0, -1863, 0, 0, -1863, -1863, -1863, 0, 0, - 0, 1579, 0, 0, 0, 0, 1865, 0, 0, 0, - 0, 0, 0, 1321, 0, 1577, 0, 1467, 0, 0, - 0, 0, 0, 813, 0, 813, 0, 1581, 0, 1337, - 1339, 1342, 1344, 0, 813, 0, 33, 0, 0, 0, - 0, 0, 0, 0, 1505, 0, 0, 35, 0, 0, - 0, 1580, 0, -2141, 0, 0, 0, 0, 0, 1969, - 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, 0, 0, - 37, 0, 1574, 0, 38, 0, 0, 0, 0, 0, - 1442, 0, 0, 0, 0, 0, 0, 0, 1865, 0, - 0, 0, 0, 0, 39, 859, 0, 1576, 0, 0, - 2973, 0, 0, 2974, 0, 0, 1333, 0, 40, 1865, - 859, 859, 859, 1637, 0, 0, 0, 0, 0, 43, - 0, 0, 0, 561, 1577, 859, 0, 0, 859, 1970, - 0, 0, 3026, 0, 0, 859, 44, 0, 0, 0, - 0, 967, 0, 0, 0, 1580, 0, 0, 0, 3083, - 3084, 3085, 3086, 0, 3088, 3089, 3090, 3091, 3092, 1579, - 45, 0, 0, 1865, 1865, 0, 1865, 0, 0, 0, - 0, 1579, 0, 0, 46, 0, 0, 1574, 0, 0, - 0, 0, 562, 562, 0, 0, 0, 0, 0, 0, + 525, 914, 872, 53, 57, 65, 82, 103, 68, 719, + 69, 94, 1140, 1207, 77, 963, 525, 99, 884, 1244, + 1036, 1964, 1315, 523, 1263, 1445, 858, 70, 1826, 1989, + 1814, 1501, 1798, 1354, 77, 982, 1318, 784, 2221, 523, + 718, 1779, 1815, 2188, 1607, 522, 1707, 2623, 778, 1417, + 2024, 2327, 1415, 2105, 2336, 1864, 1172, 2144, 2055, 888, + 2658, 817, 1418, 1371, 856, 1831, 2094, 1789, 525, 525, + 2506, 1360, 2727, 810, 1764, 1419, 2613, 1377, 50, 889, + 745, 1785, 51, 3049, 52, 2596, 55, 2598, 2121, 2122, + 56, 523, 523, 59, 60, 3018, 61, 1684, 1896, 905, + 63, 66, 1687, 870, 67, 2651, 1243, 80, 1249, 1819, + 1253, 3047, 81, 817, 817, 3020, 83, 851, 1263, 2577, + 3065, 2612, 976, 973, 965, 810, 810, 1620, 898, 1014, + 84, 3062, 90, 91, 2843, 1039, 2710, 93, 98, -1949, + 2192, 102, 104, 885, 886, 2911, 2358, -2089, -2089, 2916, + 2354, -1373, -1949, 2508, 1060, -454, 2241, -1314, 1060, -527, + 2460, 1982, 2244, 1584, 1585, 3137, 1983, 1061, 1348, -371, + -870, 3267, -875, 537, -531, -1940, -875, 983, 2714, 1384, + 1597, 2136, 1348, -1295, 2718, 2719, 2712, -1957, 3472, 1770, + 821, -1314, 2659, -1315, 1060, -837, 1429, 2353, 2728, -1311, + -1311, 2526, -878, -850, 1440, -1940, -865, -1957, 2136, -1315, + 821, 821, -878, -2080, -2080, -2098, -2098, -1312, -1312, 2146, + 862, 1688, 1364, 821, 3553, -2075, -2075, 1060, -2100, -2100, + 1364, 954, 1781, 819, 1692, 1060, 3201, -229, 1781, 1159, + 3254, 1941, -229, 1817, 1196, 879, 1943, 1569, 1153, 2686, + 876, 1829, 2765, 2767, -1132, 2770, 1199, 3271, 1339, -527, + 1830, 982, -1132, 1640, 2487, 2488, 3607, 1263, 1642, 3361, + 3348, 3140, 3578, 1160, -531, 2494, 1713, 1348, -480, 2498, + 876, 2350, 2735, 3184, 1773, 819, 819, 1008, 1941, 2804, + 538, 1616, 1942, 1943, 1765, 881, 3237, 1340, 1650, 1589, + 821, 3066, 3506, 2660, 3, 4, 2159, 3167, 3432, 3169, + -665, 1039, 1790, 1006, 1799, 1599, 880, 1802, 1803, 2883, + 3602, 2885, 1257, 1014, 3538, 2481, 2482, 2483, 3040, 1981, + 821, 2441, 1652, 881, 1157, 1689, 1790, 1710, 2175, 1832, + 3459, 877, 3212, 3608, 1640, 2254, 2176, 2030, 1641, 1642, + 3545, 1804, 1693, 1378, 3391, 2705, 2654, 821, 2185, 3591, + 1015, 2470, 3291, 3476, 3392, 3328, 1981, 3330, 942, -807, + 2787, 877, 3496, 2216, 2123, 1192, 1759, 1760, 2247, 1650, + -2074, -2074, 2925, -1153, 3531, 2928, 1724, 113, 1611, 839, + 1602, -1153, 2954, 2275, 881, 3268, 3426, 1809, 3427, 1186, + 1763, 1640, 2588, 1602, 3589, 3440, 3198, 943, 1044, 1488, + 3269, 1440, 1603, 1652, 992, 2433, 1781, 2471, 3236, 1045, + 2662, 1810, 3210, 3261, 1877, 1603, 1604, 1782, 1836, 2924, + 2160, 1569, 1021, 3518, 3273, 3609, 3521, 1526, 3507, 1606, + 1813, 1161, 2722, 1162, 1775, 3614, 2461, 2161, 2907, -527, + 2967, 1194, 2162, 1612, 2276, 3262, 3377, 2147, 2217, 1690, + 1220, 1489, 1318, 3560, -531, 1349, 2955, 3067, 3441, 3586, + 1652, 114, 3478, 2929, 2442, 2651, 1341, 2651, 3458, 1349, + 3539, 3199, 3579, 3603, 2443, 2148, 3076, 3404, 3561, -685, + 2163, 840, 2655, 945, 1725, 2248, 1805, 3211, 2835, 1711, + 1016, 1187, 1607, 3213, 1833, -807, 1806, 1154, 2186, 3540, + 3091, 2279, 1788, 3216, 3359, 3289, 1258, 3592, 1791, 2680, + -527, 1835, 1569, 2661, 3508, 2662, 1468, 1476, 3546, 3584, + 3548, 3393, 2681, 1483, 989, -531, 3433, 1601, 2065, 2930, + 2351, 2931, 1791, 955, 2543, 882, 2698, 2699, 2700, 1640, + 2956, 3058, 2137, 1641, 1642, 2663, 3554, 541, 3055, 2027, + 1709, 2472, 3337, 1776, 2144, 863, 929, 1702, 1761, 3580, + 3070, 3071, 559, 3519, 1349, 2342, 3202, 2502, 750, 2579, + 1762, 1818, 878, 1155, 1650, 1788, 719, 2687, 1631, 826, + 3610, 1766, 1342, 3082, 3041, 2270, 1054, 3349, 3581, 2804, + 2149, 3270, 2335, 869, 869, 2339, 1584, 1585, 3360, 1788, + 2151, 3248, 2521, 1602, 963, 1897, 2863, 951, 1652, 1898, + 542, 2255, 2094, -1132, 912, 1902, 2774, 1350, 913, 535, + 3420, 1597, 1580, 1941, 1990, 1603, 539, 1942, 1943, -527, + 1973, 1353, 1440, 1440, 982, 2241, 2600, 2164, 1440, 2399, + 2626, 3369, -1949, 3018, -531, 2012, 788, 3520, 3225, 3226, + 2776, 1594, 2819, 2428, 2731, -1949, 2726, 2615, 901, 1815, + -1314, 2191, -1373, 3020, 1594, 2434, -454, -454, -527, 1602, + -527, 1102, 1103, -870, 2405, -875, 2621, 1314, -1940, 1602, + -371, 2076, 2077, -531, 912, -531, -1295, 3340, 913, 3192, + -1957, 1603, 3341, 1635, -1314, 2462, -1315, 2177, 1587, 2720, + 872, 1603, 2467, 1809, 2710, 1604, 1592, 2904, -1940, -865, + -1957, 3311, -1315, 1685, 2193, 1606, 2146, 1368, 1369, 1899, + 1586, 976, 1906, 1002, 3457, 1368, 1369, 1810, 1163, 1263, + 2117, 1263, -229, -229, 1958, 1589, 1569, 981, 1640, 3251, + 2798, 2546, -1153, 2499, 2934, 2275, 3465, 2499, 2706, 2707, + 3343, 872, 1192, 2152, 789, 1599, 1673, 77, 2062, 1616, + 784, 2892, 2422, 3464, 2153, 1979, 1727, 2423, 1616, 3353, + 2935, 105, 978, 1650, 2905, 3265, 2520, 525, 1955, 1956, + 1957, 1958, 2097, 1972, 2335, 1974, 1975, 2569, 525, 2053, + 1020, 1438, 546, 1851, 972, 525, 2788, 2789, 2790, 2791, + 523, 3183, 1217, 2777, 1217, 2884, 2648, 1652, 1218, 3086, + 1218, 523, 1728, 2118, 1192, 2570, 2893, 820, 523, 1193, + 550, 106, 817, 1208, 525, 525, 2424, 3266, 1194, 888, + 3529, 1569, 1852, 817, 1670, 1671, 1672, 1673, 1158, 2203, + 817, 2468, 3492, 3493, 3218, 1004, 3047, 3453, 525, 889, + 1781, 1301, 3223, -608, 1897, 2390, 1158, 2063, -608, 3185, + 3174, 1784, 859, 1005, 2204, 3252, 2069, 3256, 53, 57, + 65, 82, 103, 68, 2305, 69, 94, 1195, 2187, 77, + 1729, 1164, 99, 2468, 2308, 2805, 1362, 2311, 1727, 1363, + 1194, 865, 70, 3148, 3533, 525, 719, 821, 3175, 1307, + 525, 2696, 2304, 3262, 3018, 912, 1217, 2697, 3034, 913, + 3035, 2139, 1218, 1219, 1173, 1219, 851, 851, 1854, 851, + 3322, 851, 2589, 1440, 3020, 3125, 3323, 1908, 3127, -608, + 3129, 1730, 1060, 1910, 1728, 2571, 874, 2475, 1060, 1195, + 2572, 3604, 875, 50, 2328, 2329, 2330, 51, 2363, 52, + 890, 55, 1307, 2398, 3373, 56, 891, 2400, 59, 60, + 2402, 61, 2267, 981, 872, 63, 66, 3346, 1569, 67, + 525, 525, 80, 1790, -2071, -2071, 525, 81, -608, 525, + 525, 83, 525, 525, 525, 525, 2410, 77, 1317, 2303, + 784, 2094, 908, 1731, 819, 84, 1360, 90, 91, 525, + 2415, 525, 93, 98, 2854, 819, 102, 104, 2624, 2314, + 525, 893, 819, 1060, 2321, 821, 108, 1219, 14, 15, + -1949, 912, 523, 1964, 523, 1627, 2179, 525, 1307, 1572, + 2180, 1481, 3333, 523, 1989, 1486, 910, 1668, 1669, 1670, + 1671, 1672, 1673, 916, 817, 1700, 817, 872, 1701, 525, + 2601, 1903, 2602, 1730, 1904, 817, 810, 1790, 1004, 928, + 1147, 1148, 1473, 1150, 23, 1152, 2306, 810, 525, 935, + 1220, 2309, 1220, 912, 1465, -1295, 1005, 913, 2055, 525, + 525, 525, -209, 525, 525, 1480, 719, 3158, 1631, 1595, + 1596, 2701, 1815, 2573, 947, 2026, 912, 2279, 2027, 939, + 1627, 1820, 2938, 1628, 2574, 949, 2147, 1048, 1049, 1050, + 952, 2632, 1053, 3436, 953, 1731, 3283, 1621, 956, 525, + 1569, 1953, 1954, 1955, 1956, 1957, 1958, 1790, 931, 1221, + 932, 1247, 1569, 1222, 2148, 1222, 2621, 525, 525, 1440, + 1440, 1440, 1440, 1440, 1440, 2941, 957, 1440, 1440, 1440, + 1440, 1440, 1440, 1440, 1440, 1440, 1440, 2466, 958, 1158, + 1715, 1716, 1569, 1722, 2688, 1223, 933, 1248, 934, 1569, + 989, 1393, 1394, 525, 1220, 959, 3378, 525, 525, 1791, + 889, 889, 969, 889, 982, 1823, 109, 525, 525, 525, + 541, 1790, 525, 1790, 998, 2805, 2051, 110, 1025, 2052, + 1007, 2347, 1620, 940, 2348, -2072, -2072, 26, 27, 28, + 1569, -2073, -2073, 1572, 1569, 2736, 819, 1009, 819, 2421, + 1569, 2744, 2416, 2425, 1816, 2417, 2427, 819, 987, 1939, + 1940, 3379, 111, 2814, 1026, 1960, 1224, 1222, 1224, 988, + 3380, 1401, 1402, 1569, 990, 2524, 1788, 3243, 1307, 2149, + 1474, -2076, -2076, 542, 2150, 2685, 1217, 1307, 2454, 2151, + 1028, 2455, 1218, 1791, 3381, 2500, -2077, -2077, 2501, 1223, + 3133, 1217, -2078, -2078, 33, 941, 1217, 1218, 1578, 993, + 46, 1307, 1218, 112, 996, 35, 2503, 1059, 2676, 2501, + 1941, 2677, 1041, 2682, 1942, 1943, 2683, 968, 1944, 1945, + 1946, 1052, 2747, 3351, 1572, 2027, 2597, 37, 2945, 2811, + 997, 38, 2501, 823, 1858, 1859, 1861, 1862, 999, 2689, + 719, 2693, 1000, 2567, 1401, 1402, 3087, 1051, 2812, 719, + 1788, 2052, 1001, 1791, 1440, 1440, 2380, 3382, 2381, 1721, + 1224, 2670, 2815, 2672, 40, 2816, 981, 3600, 1217, 1002, + 3383, 1891, 2799, 1046, 1218, 43, 2806, 2946, -2079, -2079, + 1407, 1408, 2094, 719, -2081, -2081, 77, 1219, 525, 784, + 2817, 879, 44, 2816, 942, 2947, 2899, 1055, 3587, 2900, + 3588, 978, 1219, -2082, -2082, 1316, -609, 1219, 1054, 1032, + 3056, -609, 3057, 2417, 1913, 2348, 45, 1791, 3080, 1791, + 1788, 3081, 3088, 909, 3016, 3089, 3149, 1151, 1475, 2052, + 46, 1167, 2152, 943, 3563, 869, 2635, 3284, 525, 525, + 2052, 3613, 3285, 2153, 525, 2501, 525, 3317, 1175, 3575, + 2052, 525, 525, 525, 525, 546, 3324, 972, 1174, 2027, + 2958, 2717, 880, 1407, 1408, 1177, 525, 525, 944, 523, + 1440, 2965, 23, -2083, -2083, 525, 3033, 525, 1178, 1219, + 525, 2922, -609, 550, 1788, 525, 1788, 525, 525, 3334, + 525, 817, 3335, 2476, 525, 2477, 2948, 2478, 523, 2479, + 523, 2836, 2837, 523, 3611, 2949, 1179, 3043, 523, 3612, + 1181, 523, 3367, 523, 1182, 2417, 2957, 523, 2966, 945, + 817, 1948, 817, 3368, 3401, 817, 2348, 2052, -2084, -2084, + 817, -609, 810, 817, 810, 817, 1190, 810, 3462, 817, + 881, 2417, 810, 1209, 1220, 810, 1212, 810, 1572, 1473, + 2003, 810, 2004, 1214, 3422, 2006, 3423, 1215, 3474, 1220, + 2010, 3475, 1216, 2013, 1220, 2014, 2673, 1228, 2675, 2018, + 3500, 3384, 3544, 3501, 3385, 3475, 3585, -2085, -2085, 3475, + 525, 525, 1255, 1620, 1569, 1229, 2823, 2054, 2822, 525, + 525, 1949, 2056, 1246, 2057, 2060, 1250, 525, 77, 2824, + 2826, 2061, 1254, 1251, 525, 1310, 940, 1222, 2921, 1616, + 2923, 2058, 2825, 2827, 2828, 26, 27, 28, 2266, -2086, + -2086, 1059, 1222, 2312, 1941, -2087, -2087, 1222, 1942, 1943, + 719, 525, -2102, -2102, -2102, 525, 1220, 1313, 525, 1252, + 1301, -2088, -2088, 1572, 525, 525, 525, 525, 525, 525, + 525, 525, 719, 1189, 1223, 1191, 525, 525, 525, 2313, + 1314, 525, 1319, 819, 1321, 525, -2090, -2090, 525, 525, + 525, 525, 525, 525, 525, 525, 525, 1325, 941, 525, + 2757, 523, 33, 2133, 1335, 1025, 525, 1337, 1307, -2091, + -2091, 882, 819, 1338, 819, 2319, 1345, 819, 1346, 1222, + 982, 2188, 819, -2092, -2092, 819, 525, 819, 1561, 1352, + 1224, 819, -540, 3230, 2621, 2223, -2093, -2093, 541, 38, + 1569, 1026, -2094, -2094, 1355, 1224, 1356, -540, 1361, 525, + 1224, 2320, -540, 2117, 1379, 889, 1456, 1482, 1380, 1164, + 525, 525, 1385, 869, -2095, -2095, 1443, 1028, -2097, -2097, + -2099, -2099, 40, 1458, 3193, 1459, 2435, 2436, 2437, 2438, + 2439, 2440, 1478, 43, 2444, 2445, 2446, 2447, 2448, 2449, + 2450, 2451, 2452, 2453, 1477, 2965, 1466, 1851, -2101, -2101, + 1572, 542, 1484, -540, 1838, 1839, 1569, 2242, 2243, 719, + 1495, 719, -660, -660, -664, -664, 1440, 1440, -663, -663, + 1403, 1404, 1224, -540, 1950, 1951, 1952, 1485, 1953, 1954, + 1955, 1956, 1957, 1958, 1491, 2030, 1852, 2915, 46, 1497, + 2291, 1462, 2295, 1407, 1408, 3247, 1469, 1470, 1471, 3189, + 3190, 525, 3050, 1230, 1574, 3079, 3039, 1575, 1307, 2749, + 2751, 525, 525, 1492, 116, 3068, 1577, 1496, 536, 3597, + 3598, 1853, -540, 1231, 544, 3562, 749, 3571, 3572, 3564, + -841, -540, 1696, 1697, 2640, 2641, -848, 1586, 3400, 46, + 838, 3160, 3310, 1590, 852, -685, 1032, -686, -838, -839, + 1600, -842, 1307, -840, 1601, 1679, 1622, 1632, 1634, 1681, + 1683, 1569, 1561, 1695, 1703, 1475, 1704, 1708, 1712, 1232, + 719, 1193, 1854, 1714, 1195, 1949, 1749, 1307, 525, 1753, + 1751, 1768, 2384, 1316, 3605, 1786, 981, 1787, 1788, 1793, + -208, 1794, 1900, 1795, 1901, 1800, 1807, 1808, 1812, 1822, + 113, 1828, 1572, 1841, 1842, 1843, 525, 525, 1847, 525, + 1850, 1857, 1856, 1865, 1572, 525, 525, 525, 525, 525, + 525, 2564, 2565, 525, 525, 525, 525, 525, 525, 525, + 525, 525, 525, 546, 1869, 547, 1866, 1872, 525, 525, + 1873, 1875, 525, 1876, 1572, 2621, 1878, 1879, 917, 525, + 1892, 1572, 3016, 1561, 1893, 1897, 1905, 1930, -1831, 1569, + 1932, 550, 1440, 1933, 1935, 1233, 1969, 1938, 1961, 1970, + 1977, 1980, 2000, 525, 918, 2005, 2002, 2011, 525, 2015, + 525, 2016, -540, 2017, 525, 2022, 2025, 1440, 1580, 2028, + 1587, 3400, 1572, 1592, 2029, 2031, 1572, 1217, 525, 2032, + 1307, 523, 1572, 1218, 2034, 2064, 2033, 523, 2065, 1060, + 2098, 1230, 1640, 2099, 1234, 2102, 2106, 3365, 3231, 3232, + 2109, 3221, 2111, 817, 1235, 1572, 2114, 2112, 2113, 817, + 2135, 1231, 2182, 3400, 1989, 810, 1236, 525, 525, 2158, + 919, 810, 2155, 1569, 2183, 2189, 2156, 2201, 2202, 2206, + 880, 912, 2222, 2489, 1177, 913, 2231, 3124, -1831, 2492, + 2219, 2232, 2233, 2236, 2234, 2253, 985, 2235, 1237, 920, + 2257, 2268, 2258, 2261, 2273, 525, 2272, 1232, 872, 525, + 2274, 881, 3400, 2331, 525, 525, 2332, 2333, -2102, -2102, + -2102, 2345, 1953, 1954, 1955, 1956, 1957, 1958, 1043, 2355, + 2349, 2366, 2367, 2364, 2368, -1831, 1620, 2369, 1219, 2370, + 525, 525, 921, 2371, 2385, 525, 1022, 3455, 2388, 2386, + -1831, 1023, 1239, 1149, 2391, -1831, 2392, 2393, 1440, 2394, + -1831, 525, 2395, 2397, 525, 525, 525, 1439, 2418, -1831, + 2401, 2426, 1966, 1941, -1831, 2456, 1965, 1240, 2485, 2463, + 1569, 2473, 525, 719, 2464, 3416, 2465, 2493, 523, 525, + 2469, 2474, 525, 2505, 2507, 2491, 1242, 2512, 2513, 2514, + 2516, 823, 2523, 1233, 2517, 2518, -1831, 1561, 2519, 525, + 1024, 2550, 2522, 2538, 1569, 523, 2530, 2533, 3207, 2531, + 2539, 1230, 525, 2536, 2534, 819, -1831, 2535, 2546, 2537, + 1612, 819, 523, 2540, 2541, 2560, 2561, 817, 2568, 525, + 525, 1231, 2563, 3016, 2575, 2584, 2585, 2592, 2590, 810, + 2591, 2604, 1234, 2603, 817, 2606, 525, 2608, 525, 2609, + 2614, 2616, 1235, 2617, 2628, -666, 810, 2627, 2630, 922, + 2631, 525, 2634, 2638, 1236, -1831, 2639, 1766, -1831, 2642, + 923, 2644, 1025, 541, -1831, 2647, 2646, 1232, 1370, 719, + 719, 719, 2650, 2669, 2671, 1220, 1569, 2703, 1413, 2684, + 2690, 1440, 1561, 2716, 2702, 2721, 1237, 2733, -1359, 2715, + 1815, 2737, 3550, 2741, 2738, 924, 2691, 3354, 1026, 2692, + 2291, 2291, 2291, 2745, -1831, 2734, 2754, 1594, 525, 2764, + 872, 2775, 2772, 2795, 1027, 2778, 2781, 1307, 925, 1569, + 2796, 2271, 2782, 2783, 1028, 2807, 542, 2808, 2813, -1831, + 2832, 2280, 2839, 2283, 1238, 2784, 2294, 2961, 1222, 2821, + 1239, 2851, 2298, 2829, 2300, 1742, 926, 1858, 1859, 1861, + 1862, 719, 982, 2840, 1439, 2850, 1572, 2307, 1029, 2859, + 2861, 2862, 2310, 1233, 2865, 1240, 2315, 2316, 2317, 2318, + 1241, 2322, 2323, 2867, 2868, 2880, 525, 2889, 2874, 1206, + 543, 2908, 1913, 1631, 1242, 2875, 2912, 859, 2882, 819, + 2886, 525, 981, 2906, 2920, 2926, 2910, 2927, 1633, 544, + 719, 2953, 2933, 2969, 1030, 3036, 819, 3037, 1636, 3038, + 3045, 1031, 1234, 3042, 3046, -1831, 3053, 3054, 3059, 1561, + 3060, 3064, 1235, 3072, 3073, -1831, 3077, 2348, 3084, 1569, + 1686, 1913, 3085, 2117, 1236, 3090, 3110, 3112, 525, 1691, + 3116, 1224, 3120, 3130, 3131, -1831, 3134, -1831, -1831, 3180, + 3135, 3161, 3168, 1032, 3171, 3173, 3182, 3186, 545, 3187, + 3188, 523, 3194, 3415, 3195, -208, 1237, 1059, 3196, 3200, + 1941, 3405, 1033, 3407, 1942, 1943, 525, 3204, 1944, 1945, + 1946, 3205, 3206, 817, -1831, 3214, 3219, -1831, -1831, -1831, + 3217, 3220, 1572, 872, 3224, 3239, 3240, 1440, -2070, 1158, + 3417, 3244, 3419, 3238, -2071, -2072, 3537, -2073, 546, 525, + 547, -2074, 3241, -2075, -2076, 525, 525, 3498, -2077, -2078, + 1239, -2079, -2081, 3255, 3242, 2877, 3257, 548, -2082, -2083, + 525, 872, -2084, 549, -2085, -2086, 550, -2087, -2088, -2090, + 3491, 1034, -2091, -2092, -2093, 1240, 525, -2094, -2095, 525, + 3502, 525, -2096, -2097, -2098, -2099, -2100, -2101, 1572, 525, + -1312, 3245, 525, 525, 1242, 3272, 3253, 525, 525, 3083, + 3258, 1561, 3260, 3274, 525, 3277, 3276, 3280, 3286, 3486, + 1563, 3287, 2914, 1561, 3290, 1439, 1439, 3304, 3292, 525, + 3294, 1439, 3306, 3298, 3301, 3300, 3305, 2054, 3309, 525, + 3312, 3313, 2056, 3316, 2057, 2060, 521, 532, 77, 1022, + 3331, 2061, 557, 1561, 1023, 3332, 3336, 3339, 557, 525, + 1561, 2058, 807, 3342, 822, 3344, 3356, 2898, 825, 557, + 834, 3357, 2894, 834, -1311, 3364, 854, 854, 3366, 3372, + 854, 3374, 3375, 557, 557, 3402, 23, 3388, 3389, 3403, + 3390, 3406, 3409, 3412, 3410, 819, 3418, 3424, 1947, 3444, + 719, 1561, 3213, 3019, 719, 1561, 719, 1912, 3448, 3450, + 3451, 1561, 3454, 1024, 807, 807, 541, 3467, 525, 3468, + 525, 1948, 3460, 2938, 3472, 3469, 3477, 23, 3479, 2939, + 1569, 2291, 3481, 3164, 1561, 3021, 3484, 2295, 3075, 3488, + 854, -1359, 2940, 3485, 3490, 3499, 3489, 854, 557, 854, + 854, 854, 3495, 3497, 1858, 1859, 1861, 1862, 3504, 3509, + 3516, 3517, 3515, 3522, 3523, 3524, 2941, 3532, 2942, 3534, + 3542, 3526, 3552, 3048, 3536, 3209, 3555, 3557, 3573, 542, + 3576, 3554, 3553, 1373, 3590, 1025, 872, 3601, 3595, 3606, + 1900, 1949, -540, 1203, 3616, 3615, 1180, 2968, 525, 2299, + 2667, 1572, 3069, 1059, 1563, 3431, 1941, -540, 3530, 3494, + 1942, 1943, -540, 2972, 1944, 1945, 1946, 2901, 525, 525, + 3599, 1026, 2403, 525, 3227, 541, 525, 2756, 1156, 26, + 27, 28, 1059, 2362, 3513, 1941, 3583, 1027, 3352, 1942, + 1943, 3551, 3558, 1944, 1945, 1946, 1778, 1028, 3577, 3387, + -1359, 2649, 3063, 525, 2674, 3549, 2943, 2937, 3556, 2895, + 2856, 3022, 2645, -540, 3547, 1895, 2748, 1855, 2750, 2711, + 26, 27, 28, 525, 2761, 3281, 3044, 2633, 1705, 525, + 525, 1029, 872, -540, 525, 1572, 1463, 1464, 542, 525, + 2619, 1230, 525, 525, 2260, 1563, 33, 525, 1307, 1746, + 2786, 525, 1204, 1745, 3535, 525, 2629, 914, 2228, 3480, + 3408, 1231, 525, 2259, 811, 2605, 2230, 2497, 3282, 1750, + 3119, 3308, 2780, 1637, 2944, 2779, 1430, 1030, 523, 2945, + 3358, 2810, -540, 38, 1031, 2511, 3229, 33, 1414, 1416, + 1420, -540, 971, 1421, 2412, 1422, 2413, 1423, 2414, 1424, + 817, 1425, 1426, 3483, 1373, 3482, 525, 1232, 2959, 2558, + 2834, 546, 810, 972, 525, 2582, 40, 2622, 2960, 2580, + 2527, 3172, 2740, 3143, 38, 1991, 1032, 43, 2946, 2559, + 1465, 2853, 3470, 525, 2887, 2343, 549, 1907, 1211, 550, + 2504, 986, 1572, 3144, 2256, 1033, 2947, 2197, 1824, 2902, + 2199, 2694, 0, 0, 1950, 1951, 1952, 40, 1953, 1954, + 1955, 1956, 1957, 1958, 0, 0, 0, 1948, 43, 0, + 545, 2194, 0, 0, 0, 0, 3019, 2961, 0, 0, + 0, 0, 46, 0, 1373, 44, 0, 1373, 1373, 0, + 0, 0, 0, 0, 0, 0, 1948, 0, 0, 0, + 0, 0, 0, 1233, 0, 1561, 0, 0, 0, 45, + 0, 0, 0, 0, 1034, 0, 0, 0, 719, 1205, + 546, 0, 972, 2896, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 872, 1949, 0, 548, + 0, 0, -540, 2263, 2265, 549, 525, 2948, 550, 1913, + 0, 0, 1234, 0, 981, 0, 2949, 525, 1572, 0, + 0, 0, 1235, 0, 0, 0, 1949, 3264, 0, 1563, + 0, 0, 819, 525, 1236, 0, 2962, 0, 0, 0, + 0, 0, 1439, 1439, 1439, 1439, 1439, 1439, 0, 0, + 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1439, 1439, + 0, 1572, 2324, 0, 23, 0, 1237, 525, 0, 0, + 0, 912, 0, 0, 0, 913, 0, 0, 2340, 2340, + 0, 1909, 1911, 0, 525, 525, 0, 0, 525, 854, + 525, 0, 0, 0, 854, 0, 0, 854, 0, 0, + 0, 1561, 0, 0, 0, 557, 0, 0, 0, 0, 0, 0, 0, 0, 0, 525, 0, 0, 0, 0, - 0, 1579, 1576, 0, 0, 0, 0, 0, 1579, 0, - 0, 0, 1581, 2835, 0, 0, 0, 0, 0, 0, - 0, 859, 859, 859, 0, 0, 0, 0, 0, 1577, - 0, 0, 0, 1653, 0, 561, 1654, 1447, 0, 561, - 1655, 1656, 0, 0, 0, 561, 0, 0, 0, 0, - 0, 0, 1579, 0, 0, 0, 1579, 0, 0, 0, - 0, 0, 1579, 1574, 0, 859, 0, 0, 0, 0, - 0, 1664, 0, 0, 0, 0, 0, 0, -2141, 2117, - 0, 0, 0, 0, 0, 1579, 0, 0, 1576, 0, - 0, 561, 0, 0, 0, 561, 0, 0, 0, 0, - 0, 0, 0, 1784, 0, 1666, 1581, 0, 0, 0, - 0, 0, 0, 0, 0, 1577, 1816, 0, 0, 0, - 0, 0, 0, 0, 1447, 1447, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1841, 0, 0, - 0, 0, 0, 0, 1449, 1971, 1972, 1973, 2591, 1974, - 1975, 1976, 1977, 1978, 1979, 2947, 0, 0, 0, 0, - 0, 2235, 0, 562, 562, 0, 562, 0, 0, 0, - 2918, 1580, 0, 0, 1574, 0, 0, 859, 0, 0, - 0, 561, 0, 1113, 0, 561, 561, 0, 0, 561, - 0, 0, 0, 1865, 1794, 1865, 0, 1909, 0, 1576, - 0, 0, -2141, 0, 0, 0, 1870, 0, 0, 1574, - 0, 0, 0, 0, 0, 1889, 3275, 0, 561, -2141, - 1794, 0, 0, 0, -2141, 0, 1577, 0, 0, 0, - 0, 0, 0, 0, 1576, 561, 561, 561, 561, 1794, - 561, 561, 561, 561, 561, 0, 1224, 0, 0, 0, - 0, 0, 1225, 0, 0, 0, 0, 0, 0, 0, - 1237, 1577, -2141, 0, 0, 0, 0, 2407, 1580, 562, - 0, 0, 0, 0, 859, 1574, 0, 0, 0, 0, - 1238, 0, 0, 0, 813, 0, 813, 0, 0, 813, - 3126, 0, 0, 0, 813, 0, 0, 813, 1574, 813, - 1576, 0, 0, 813, 0, 2043, 0, 2047, 0, 0, - 1909, 0, 0, 0, 0, 0, 0, 1675, 0, 0, - 1865, 0, 0, 1576, 0, 0, 1239, 1577, 0, 0, - 0, 1447, 1581, 0, 0, 0, 0, 561, 0, 0, - 0, 0, 1574, 1757, 859, 859, 859, 859, 0, 0, - 1577, 0, 1449, 0, 0, 0, 2019, 1226, 1447, 0, - 0, 1447, 0, 0, 0, 561, 967, 1576, 0, 0, - 0, 0, 0, 0, 3193, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1577, 0, 0, 561, 0, 0, - 0, 0, 0, 0, 3201, 561, 1580, 0, 0, 2591, - 0, 0, 0, 0, 0, 0, 1579, 0, 0, 0, - -2141, 0, 1240, 0, 0, 0, 0, 2129, 0, 1581, - 0, 0, 0, 0, 0, 0, 0, 0, 3230, 0, - 812, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1113, 1065, 0, 1574, 1962, 0, 0, 3244, 1963, - 1964, 0, 2235, 1965, 1966, 1967, 0, 0, 2117, 0, - 0, 1241, 0, 0, 0, 0, 0, 0, 0, 1576, - 3217, 1242, 1794, -1865, 0, 0, 0, 0, 1865, 0, - 0, 0, 0, 1243, 0, 0, 0, 0, 1450, 0, - 0, 967, 561, 1447, 3427, 0, 1577, 0, 0, 859, - 0, 0, 0, 0, 1227, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1244, 3295, 0, 3434, 3435, - -2141, 0, 0, 0, 0, 0, 0, 1682, 1683, 1684, - 1685, 1686, 1687, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 3448, 0, 0, 1579, 1224, 0, 0, - 0, 0, 0, 1225, 1580, 0, 0, 1581, 0, 562, - 0, 1237, 0, 0, 1245, 0, 1580, 0, 1229, 0, - 1246, 0, 0, -1865, 0, 0, 1449, 1449, 562, 0, - 0, 1238, 1449, 0, 2221, 0, 2223, 0, 0, 562, - 0, 562, 0, 0, 562, 1247, 1580, 2232, 3315, 0, - 1248, 0, 1865, 1580, 562, 0, 562, 0, 0, 0, - 0, 0, 0, 1579, 0, 1249, 0, 0, 2407, 562, - -1865, 0, 0, 0, 562, 0, 0, 1239, 562, 562, - 0, 562, 0, 562, 562, -1865, 2269, 3348, 0, 0, - -1865, 0, 0, 0, 1447, -1865, 0, 1580, 0, 0, - 0, 1580, 0, 0, -1865, 0, 1969, 1580, 1226, -1865, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 3365, 0, 0, 1231, 0, 0, 0, 561, 0, 0, - 1580, 0, 0, 0, 561, 0, 0, 0, 0, 0, - 0, -1865, 0, 0, 0, 0, 1450, 0, 0, 0, - 0, 3384, 0, 0, 0, 0, 0, 0, 0, 0, - 1574, -1865, 0, 0, 0, 1581, 0, 0, 0, 0, - 0, 0, 1579, 1240, 0, 3396, 1970, 1581, 0, 0, - 0, 0, 0, 2591, 0, 1576, 0, 0, 0, 0, - 0, 0, 0, 2390, 2391, 2393, 2394, 2395, 0, 561, - 0, 0, 0, 0, 561, 0, 0, 1581, 0, 0, - -1865, 0, 1577, -1865, 1581, 0, 0, 0, 0, -1865, - 0, 0, 1241, 0, 0, 0, 0, 3615, 0, 0, - 561, 0, 1242, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 562, 0, 1243, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 561, 561, 0, 0, 1581, 0, - -1865, 0, 1581, 0, 0, 1227, 0, 0, 1581, 813, - 0, 859, 0, 3126, 0, 813, 1244, 1579, 0, 561, - 0, 2534, 0, 0, 0, -1865, 0, 2047, 0, 0, - 0, 1581, 0, 859, 1653, 0, 3469, 1654, 0, 0, - 0, 1655, 1656, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1447, 0, 1113, 0, - 561, 1017, 2254, 1017, 0, 2334, 0, 0, 561, 1229, - 0, 1246, 1664, 0, 0, 2514, 0, 0, 0, -2141, - 0, 0, 0, 0, 864, 0, 0, 0, 0, 1113, - 0, 0, 0, 3244, 0, 0, 1247, 0, 0, 0, - 859, 2335, 0, 1579, 0, 0, 1666, 0, 0, 2129, - 0, 0, -1865, 0, 0, 0, 1249, 0, 0, 1637, - 1450, 1450, 0, -1865, 0, 0, 1450, 0, 0, 0, - 859, 0, 1971, 1972, 1973, 0, 1974, 1975, 1976, 1977, - 1978, 1979, 0, -1865, 0, -1865, -1865, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 3365, 0, - 0, 2921, 0, 0, 1231, 0, 1113, 0, 0, 0, - 0, 0, -1865, 0, 0, -1865, -1865, -1865, 0, 0, - 0, 3469, 0, 0, 0, 813, 1128, 1128, 0, 0, - 0, 1580, 0, -2141, 0, 0, 0, 562, 0, 0, - 0, 813, 0, 0, 1579, 0, 0, 0, 3126, 0, - -2141, 0, 0, 0, 0, -2141, 0, 0, 0, 0, - 967, 967, 0, 3469, 967, 0, 0, 0, 0, 0, - 0, 0, 2005, 0, 0, 0, 0, 0, 0, 1579, - 0, 0, 0, 561, 0, 562, 0, 0, 0, 0, - 0, 2678, 0, -2141, 0, 0, 0, 0, 1267, 0, - 0, 0, 1312, 1319, 0, 3126, 0, 0, 0, 0, - 0, 0, 3469, 0, 1449, 1449, 1449, 1449, 1449, 1449, - 0, 0, 1449, 1449, 1449, 1449, 1449, 1449, 1449, 1449, - 1449, 1449, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1579, 0, 0, 1675, 967, - 0, 0, 0, 0, 0, 1369, 0, 0, 0, 0, - 0, 0, 0, 0, 2235, 0, 0, 0, 1579, 0, - 0, 1580, 0, 1393, 0, 0, 0, 0, 0, 1441, - 0, 0, 1443, 0, 0, 1454, 1457, 1462, 1465, 0, - 0, 0, 1581, 0, 0, 0, 0, 0, 0, 0, - 2212, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1579, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 562, 0, - 1509, 1312, 0, 0, 0, 0, 0, 0, 1580, 0, - 0, 0, 0, 0, 0, 0, 1450, 0, 0, 0, - 0, -2141, 1595, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1611, 0, 0, 0, -1880, 0, 0, 0, 2759, - 0, 0, 0, 1622, 1623, 1624, 0, 1629, 1633, 0, - 0, 0, 0, 0, 2777, 2778, 2780, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 2793, - 0, 0, 2796, 1449, 1449, 0, 0, 0, 0, 2805, - 0, 0, 0, 1696, 1579, 0, 0, 0, 0, 0, - 0, 0, 1581, 0, 0, 0, 0, 0, 0, 0, - 562, 1509, 1509, 0, 562, 0, 0, 1580, 0, 0, - 2043, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, -2141, 0, 0, 0, 0, 0, 0, 1682, 1683, - 1684, 1685, 1686, 1687, 0, -1880, 0, 1735, 0, 0, - 0, 1751, 1756, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1128, 1128, 0, 0, 2893, 0, 0, 1581, - 2129, 0, 0, 0, 0, 2842, 2843, 2844, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1880, 0, 0, 0, 0, 0, 1449, 0, - 0, 0, 0, 0, 0, 0, 0, -1880, 0, 0, - 0, 0, -1880, 0, 0, 0, 0, -1880, 0, 0, - 0, 0, 1580, 1312, 0, 0, -1880, 0, 0, 1653, - 0, -1880, 1654, 1312, 0, 0, 1655, 1656, 1450, 1450, - 1450, 1450, 1450, 1450, 0, 0, 1450, 1450, 1450, 1450, - 1450, 1450, 1450, 1450, 1450, 1450, 562, 0, 1312, 0, - 562, 562, 0, -1880, 562, 0, 0, 1664, 0, 0, - 0, 0, 0, 0, -2141, 0, 0, 0, 1581, 0, - 0, 0, 0, -1880, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 562, 0, 0, 0, 0, 0, 0, - 0, 1666, 0, 0, 0, 0, 0, 0, 1580, 0, - 562, 562, 562, 562, 0, 562, 562, 562, 562, 562, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2965, -1880, 0, 0, -1880, 0, 0, 0, 0, - 0, -1880, 0, 0, 0, 1952, 0, 0, 0, 0, + 1239, 0, 0, 0, 1563, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2078, 0, 0, 2917, 525, + 0, 2918, 2079, 2080, 0, 1240, 2081, 2082, 2083, 0, + 0, 1370, 0, 0, 0, 0, 0, 2420, 0, 0, + 0, 0, 0, 0, 1242, 0, 2963, 1561, 2970, 2964, + 0, 3019, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 3023, 3024, 3025, 3026, 3027, 3028, 3029, + 3030, 3031, 3032, 719, 0, 0, 14, 15, 853, 0, + 0, 0, 861, 0, 0, 0, 0, 26, 27, 28, + 1950, 1951, 1952, 525, 1953, 1954, 1955, 1956, 1957, 1958, + 0, 0, 3370, 525, 1913, 525, 0, 525, 0, 0, + 0, 525, 0, 525, 0, 525, 523, 1439, 1439, 1950, + 1951, 1952, 23, 1953, 1954, 1955, 1956, 1957, 1958, 525, + 0, 0, 0, 0, 525, 0, 525, 0, 817, 0, + 0, 1563, 897, 0, 525, 0, 0, 0, 0, 900, + 0, 903, 1561, 907, 33, 0, 0, 719, 0, 1788, + 0, 0, 525, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 961, 557, 557, 0, 3428, + 0, 3430, 0, 0, 0, 2070, 0, 0, 3437, 0, + 0, 38, 0, 0, 0, 0, 0, 2100, 0, 2101, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 525, + 0, 0, 0, 1564, 0, 0, 0, 984, 532, 525, + 0, 3463, 0, 521, 40, 854, 0, 2119, 0, 0, + 0, 525, 0, 1439, 807, 43, 0, 3466, 1011, 1011, + 0, 807, 0, 0, 1011, 1038, 525, 0, 0, 0, + 1561, 0, 44, 0, 0, 0, 0, 834, 834, 834, + 0, 0, 834, 0, 525, 26, 27, 28, 1916, 523, + 1106, 1106, 834, 834, 0, 834, 45, 834, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 525, 854, + 46, 817, 0, 1563, 0, 557, 0, 0, 0, 2620, + 0, 0, 0, 525, 0, 1563, 0, 854, 0, 0, + 819, 523, 3019, 0, 719, 1917, 0, 0, 0, 3208, + 0, 854, 822, 0, 0, 0, 0, 0, 0, 0, + 2240, 2240, 33, 817, 1561, 1563, 1918, 525, 2383, 0, + 0, 0, 1563, 35, 0, 3437, 0, 0, 0, 0, + 0, 525, 525, 525, 1919, 0, 854, 1312, 1920, 23, + 523, 0, 0, 3559, 0, 37, 0, 0, 1323, 38, + 0, 0, 854, 854, 854, 854, 0, 0, 525, 0, + 0, 1921, 817, 1563, 1922, 0, 0, 1563, 1344, 3574, + 0, 0, 0, 1563, 1373, 0, 0, 1564, 0, 0, + 1923, 0, 40, 0, 1373, 0, 0, 1373, 0, 0, + 0, 2678, 0, 43, 0, 0, 1563, 0, 1566, 525, + 1011, 1038, 0, 854, 0, 0, 1437, 1567, 0, 0, + 44, 0, 1011, 1011, 0, 0, 0, 0, 0, 557, + 0, 1561, 0, 0, 0, 807, 0, 807, 0, 71, + 0, 0, 0, 0, 45, 0, 807, 0, 0, 0, + 0, 0, 0, 819, 2708, 0, 557, 0, 46, 71, + 0, 0, 809, 0, 0, 1561, 0, 0, 0, 0, + 0, 0, 2723, 1576, 0, 1022, 71, 0, 1564, 0, + 1023, 0, 0, 1924, 0, 871, 0, 0, 0, 0, + 0, 1925, 26, 27, 28, 819, 1373, 0, 0, 0, + 0, 0, 2084, 2085, 2086, 0, 2087, 2088, 2089, 2090, + 2091, 2092, 0, 1926, 809, 809, 887, 1370, 0, 0, + 0, 0, 0, 0, 557, 0, 0, 2762, 0, 2763, + 0, 0, 0, 2768, 0, 2771, 0, 0, 0, 1024, + 71, 0, 1927, 0, 819, 0, 0, 1561, 0, 1439, + 1439, 0, 0, 0, 0, 0, 0, 0, 0, 33, + 0, 1639, 0, 0, 1640, 0, 0, 0, 1641, 1642, + 0, 930, -2102, -2102, -2102, 0, 937, 1699, 0, 938, + 0, 0, 0, 0, 0, 0, 3355, 0, 0, 0, + 1561, 0, 1566, 557, 557, 0, 38, 0, 0, 1650, + 854, 1567, 0, 0, 0, 0, 1651, 0, 3362, 3363, + 0, 1025, 0, 0, 0, 0, 0, 0, 0, 2515, + 0, 0, 0, 1437, 1106, 1106, 0, 0, 0, 40, + 0, -1833, 3376, 1652, 0, 854, 1777, 0, 0, 0, + 43, 1022, 0, 0, 0, 0, 1023, 1026, 854, 0, + 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, + 0, 0, 0, 1027, 1568, 854, 0, 0, 0, 854, + 1217, 0, 0, 1028, 1825, 0, 1218, 0, 0, 0, + 0, 45, 0, 1566, 1230, 0, 0, 0, 0, 0, + 0, 0, 1567, 0, 0, 46, 0, 0, 0, 0, + 1561, 0, 1564, 0, 1231, 1024, 0, 1029, 0, 0, + 0, 0, 0, 0, 0, 3263, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1563, 0, 0, + 1653, -1833, 0, 1844, 0, 854, 23, 0, 0, 0, + 0, 0, 0, 0, 854, 1439, 0, 1654, 0, 0, + 1232, 1639, 1655, 1030, 1640, 1888, 0, 0, 1641, 1642, + 1031, 0, 0, 0, 961, 0, 0, 0, 0, 961, + 3113, 557, 557, 0, 557, 961, 2599, 1025, -1833, 0, + 0, 1219, 0, 0, 0, 0, 0, 0, 3012, 1650, + 1658, 0, 0, -1833, 0, 0, -2102, 1564, -1833, 0, + 0, 0, 1032, -1833, 0, 0, 0, 0, 0, 2625, + 2625, 0, -1833, 1026, 0, 0, 0, -1833, 0, 2708, + 3142, 1033, 0, 1652, 0, 0, 0, 995, 0, 1027, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1028, + 0, 0, 0, 0, 0, 1661, 1233, 0, 1568, -1833, + 0, 0, 0, 0, 1437, 1437, 0, 0, 0, 0, + 1437, 0, 521, 1563, 3543, 0, 0, 0, 0, -1833, + 0, 0, 0, 1029, 0, 1011, 0, 557, 1984, 26, + 27, 28, 1106, 1106, 0, 854, 0, 0, 2566, 0, + 1034, 807, 0, 807, 2007, 1234, 807, 0, 0, 0, + 0, 807, 0, 1106, 807, 1235, 807, 1566, 0, 0, + 807, 1439, 557, 0, 557, 0, 1567, 1236, -1833, 1030, + -2102, -1833, 0, 1210, 0, 0, 1031, -1833, 0, 1563, + 0, 0, 0, 0, 1564, 0, 0, -2102, 1220, 1568, + 0, 0, -2102, 0, 0, 0, 33, 1663, 0, 1237, + 0, 0, 0, 0, 0, 0, 0, 0, 1311, 0, + 0, 1561, 0, 0, 0, 0, 0, -1833, 1032, 0, + 0, 0, 0, 0, 1327, 1329, 1332, 1334, 71, 0, + -2102, 0, 0, 38, 0, 0, 0, 1033, 0, 0, + 0, 0, -1833, 0, 3170, 0, 0, 2301, 0, 0, + 0, 1222, 1566, 1239, 0, 0, 0, 558, 0, 0, + 0, 1567, 0, 558, 0, 0, 40, 808, 0, 2093, + 0, 0, 0, 0, 558, 1432, 0, 43, 1240, 0, + 0, 557, 0, 2302, 1563, 1661, 0, 0, 558, 558, + 0, 0, 0, 0, 44, 0, 0, 1242, 0, 0, + 859, 0, 0, 0, 1439, 1664, 1034, 0, -2102, -2102, + -2102, 2008, 1668, 1669, 1670, 1671, 1672, 1673, 45, 808, + 808, 961, 0, 0, 1437, 0, 0, 0, -1833, 0, + 0, 0, 46, 0, 0, 0, 1564, 0, -1833, 0, + 0, 0, 0, 0, 0, 0, 2818, 2820, 1564, 0, + 0, 0, 1106, 558, 1224, 0, 0, 0, -1833, 0, + -1833, -1833, 0, 0, 0, 0, 0, 2195, 0, 854, + 0, 854, 0, 0, 0, 0, 0, 0, 1564, 0, + 0, 854, 1563, 2211, 0, 1564, 0, -2102, 0, 1566, + 0, 0, 0, 0, 0, 1437, 0, -1833, 1567, 0, + -1833, -1833, -1833, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 3259, 1568, 0, 0, 0, 0, 1230, 0, + 854, 0, 557, 0, 0, 0, 1564, 0, 0, 0, + 1564, 0, 0, 0, 2262, 2264, 1564, 0, 1231, 1370, + 1777, 557, 71, 871, 0, 0, 0, 0, 0, 0, + 0, 557, 2281, 557, 2285, 0, 557, 0, 0, 1564, + 0, 0, 557, 0, 557, 0, 1563, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 961, 557, 0, 0, + 0, 961, 557, 991, 1232, 0, 557, 557, 557, 557, + 0, 557, 557, 0, 1003, -2102, 0, 1769, 0, 0, + 0, 1019, 1668, 1669, 1670, 1671, 1672, 1673, 1568, 0, + 1796, 2344, 0, 1373, 0, 0, 0, 0, 0, 1323, + 3414, 854, 854, 854, 854, 854, 3329, 0, 0, 0, + 0, 1821, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1566, 2373, 0, 0, 0, 887, 0, 0, 0, + 1567, 0, 0, 1566, 0, 0, 0, 0, 0, 0, + 0, 2396, 1567, 0, 71, 0, 0, 0, 0, 0, + 0, 0, 0, 1563, 0, 0, 0, 0, 0, 0, + 1233, 0, 0, 1566, 0, 0, 0, 0, 0, 0, + 1566, 0, 1567, 0, 0, 0, 3012, 1849, 0, 1567, + 0, 0, 0, 0, 0, 0, 1868, 1563, 0, 0, + 0, 1437, 1437, 1437, 1437, 1437, 1437, 0, 0, 1437, + 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1437, 1234, + 0, 1566, 0, 0, 0, 1566, 0, 0, 0, 1235, + 1567, 1566, 0, 0, 1567, 1568, 3126, 11, 0, 557, + 1567, 1236, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 854, 1566, 0, 0, 0, 0, 0, + 0, 0, 71, 1567, 807, 14, 15, 0, 0, 0, + 807, 0, 0, 1237, 0, 0, 557, 0, 0, 1563, + 0, 557, 0, 0, 0, 0, 0, 0, 0, 0, + 2509, 2509, 0, 0, 0, 809, 0, 1003, 0, 0, + 0, 0, 0, 0, 0, 0, 809, 0, 0, 0, + 0, 23, 0, 1639, 3456, 0, 1640, 0, 0, 23, + 1641, 1642, 1563, 0, 0, 0, 0, 1239, 0, 0, + 0, 1639, 0, 0, 1640, 0, 0, 1998, 1641, 1642, + 0, 1579, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1650, 1240, 1591, 0, 0, 0, 0, -2102, 0, + 0, 0, 557, 0, 0, 0, 0, 2552, 0, 1650, + 1564, 1242, 557, 0, 0, 0, -2102, 0, 0, 0, + 1618, 1373, 0, -1848, 0, 1652, 1373, 1568, 0, 0, + 558, 0, 0, 0, 0, 0, 1437, 1437, 0, 1568, + 0, 0, 0, 1652, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2093, 0, 0, 0, 0, + 0, 1437, 0, 0, 0, 0, 0, 0, 0, 1568, + 0, 0, 1563, 1909, 1911, 0, 1568, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 3012, 807, 0, + 2576, 3429, 0, 0, 26, 27, 28, 0, 0, 0, + 557, 0, 26, 27, 28, 807, 0, 887, 887, 2211, + 887, 0, 0, 0, 0, 0, 0, 1568, 0, 0, + 0, 1568, -2102, -1848, 0, 0, 0, 1568, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, -2102, + -2102, 0, 0, 0, -2102, 0, 1564, 0, 0, 557, + 1568, 0, 1437, 0, 1106, 557, 0, -2102, 0, 0, + 0, 33, -2102, 0, 0, 0, 0, 0, 0, 33, + -1848, 0, 35, 0, 0, 1844, 0, 0, 0, 0, + 0, 0, -2102, 0, 0, -1848, 0, 0, 0, 0, + -1848, 0, 0, 0, 37, -1848, 0, 0, 38, 0, + -2102, 0, 0, 0, -1848, 0, 38, 0, 0, -1848, + 0, 2196, 1564, 2198, 0, 1566, 0, 0, 39, 0, + 0, 558, 558, 2208, 1567, 0, 0, 0, 0, 0, + 0, 40, 0, 0, 0, 0, 0, 1661, 0, 40, + 0, -1848, 43, 0, 0, 0, 0, 1844, 0, 0, + 43, 0, 0, 0, 854, 1661, 0, 0, 0, 44, + 0, -1848, 2245, 0, 0, 1323, 0, 44, 1844, 854, + 854, 854, 0, 0, 0, 0, 0, 0, 0, 808, + 0, 71, 557, 45, 854, 0, 0, 854, 1909, 1911, + 0, 45, 0, 0, 854, 0, 0, 46, 0, 0, + 961, 1373, 0, 0, 0, 46, 0, 0, 0, 0, + -1848, 0, 0, -1848, 0, 0, 0, 1564, 0, -1848, + 0, 0, 1844, 1844, 0, 1844, 0, 0, 0, 0, + 0, 0, 0, 1563, 0, 0, 0, 0, 0, -2102, + 558, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1566, 0, 0, 521, 0, 0, -2102, 0, -1848, + 1567, 0, 0, 2356, 2357, 2359, 2360, 2361, 0, 0, + 0, 0, 2785, 0, 0, 0, 0, 0, 0, 0, + 854, 854, 854, 0, -1848, 0, 0, 0, 0, 0, + 557, 809, 1437, 809, 557, 0, 809, 0, 0, 0, + 557, 809, 0, 0, 809, 0, 809, 0, 0, 0, + 809, 0, 0, 0, 0, 1564, 1059, 1566, 0, 1941, + 854, 0, 0, 1942, 1943, 0, 1567, 1944, 1945, 1946, + 0, 0, 0, 0, 2093, 0, 0, 0, 0, 0, + 0, 0, 859, 0, 2857, 557, 0, -2102, 0, 557, + 0, 0, 0, 0, 1668, 1669, 1670, 1671, 1672, 1673, + 0, 0, 0, 0, 0, -2102, 0, 0, 0, 0, + -1848, 1568, 1668, 1669, 1670, 1671, 1672, 1673, 1437, 1437, + -1848, 0, 0, 0, 1457, 0, 0, 0, 0, 0, + 808, 0, 808, 71, 0, 0, 0, 0, 0, 1564, + -1848, 808, -1848, -1848, 0, 2480, 0, 2891, 0, 0, + 0, 1494, 0, 2211, 0, 0, 0, 0, 0, 0, + 0, 0, 1566, 0, 0, 0, 0, 0, 0, 854, + 0, 1567, 0, 557, 0, 1106, 0, 557, 557, -1848, + 0, 557, -1848, -1848, -1848, 1844, 1777, 1844, 1059, 1888, + 0, 1941, 0, 0, 0, 1942, 1943, 0, 0, 1944, + 1945, 1946, 1373, 0, 0, 0, 0, 0, 557, 0, + 2971, 0, 0, 0, 2143, 0, 3151, 0, 0, 1623, + 0, 0, 0, 557, 557, 557, 557, 557, 557, 557, + 557, 557, 557, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1564, 1568, 0, 0, + 0, 0, 0, 0, 2373, 0, 0, 0, 0, 0, + 1566, 854, 0, 0, 0, 0, 0, 0, 0, 1567, + 1948, 0, 0, 1777, 0, 0, 0, 0, 0, 0, + 1564, 0, 887, 0, 0, 0, 0, 1059, 558, 558, + 1941, 0, 0, 1888, 1942, 1943, 0, 0, 1944, 1945, + 1946, 0, 0, 1844, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1568, 1437, 3152, 0, 0, 0, 0, + 557, 0, 0, 0, 0, 0, 0, 854, 854, 854, + 854, 0, 0, 0, 0, 0, 0, 0, 0, 1437, + 1949, 0, 1437, 0, 1566, 0, 557, 961, 0, 0, + 0, 0, 0, 1567, 0, 3128, 0, 0, 1639, 0, + 0, 1640, 1564, 0, 0, 1641, 1642, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 557, 0, + 0, 0, 0, 0, 0, 3136, 557, 0, 0, 0, + 2552, 0, 0, 0, 0, 0, 1650, 0, 0, 0, + 0, 0, 1948, -2102, 0, 1564, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1568, 3165, + 0, 807, 2365, 0, 0, 0, 0, 0, 1106, 0, + 1652, 0, 0, 0, 71, 3177, 0, 0, 0, 2211, + 0, 0, 0, 0, 0, 2093, 0, 0, 0, 0, + 0, 1566, 0, 0, 0, 0, 0, 0, 0, 1777, + 1567, 0, 0, 0, 0, 1844, 558, 558, 0, 558, + 0, 0, 1949, 0, 0, 0, 0, 0, 961, 557, + 1437, 0, 0, 0, 0, 1566, 854, 0, 0, 0, + 0, 0, 0, 0, 1567, 2866, 0, 0, 0, 0, + 0, 1948, 0, 3228, 0, 0, 2713, 0, 0, 0, + 0, 0, 0, 0, 0, 1564, 1568, 0, 0, 0, + 0, 2729, 2730, 2732, 0, 0, 0, -2102, 0, 0, + 0, 0, 0, 0, 0, 0, 2743, 0, 0, 2746, + 0, 0, 0, 0, -2102, 0, 2755, 0, 0, -2102, + 0, 0, 0, 1950, 1951, 1952, 0, 1953, 1954, 1955, + 1956, 1957, 1958, 0, 809, 0, 0, 1566, 0, 0, + 809, 1949, 558, 0, 0, 0, 1567, 0, 0, 0, + 0, 3246, 0, 0, 0, 1844, 808, -2102, 808, 0, + 0, 808, 0, 0, 0, 0, 808, 0, 2373, 808, + 1568, 808, 0, 0, 0, 808, 0, 2019, 0, 2023, + 1566, 0, 0, 0, 0, 0, 3278, 0, 0, 1567, + 0, 0, 0, 1437, 0, 0, 0, 0, 0, 0, + 0, 0, 2792, 2793, 2794, 0, 0, 0, 0, 0, + 0, 0, 1661, 0, 0, 0, 0, 0, 0, 3295, + 0, 0, 0, 0, 0, 557, 0, 0, 0, 0, + 0, 0, 557, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 3314, + 0, 0, 0, 0, 0, 1950, 1951, 1952, 0, 1953, + 1954, 1955, 1956, 1957, 1958, 0, 0, 0, 0, 0, + 0, 1618, 0, 3326, 0, 0, 0, 1568, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1579, 0, 0, 0, 0, 0, 2922, 0, 0, 0, + 1566, 2143, 0, 0, 0, 557, 2104, 0, 0, 1567, + 557, 0, 0, 0, 0, 0, 0, 2586, 0, 0, + 0, 1568, 0, 0, -2102, 0, 0, 0, 809, 0, + 0, 1059, 0, 0, 1941, 0, 557, 0, 1942, 1943, + 0, 0, 1944, 1945, 1946, 809, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1564, 0, 557, 557, + 0, 2909, 0, 0, 1950, 1951, 1952, 0, 1953, 1954, + 1955, 1956, 1957, 1958, 0, 854, 0, 1777, 0, 0, + 0, 0, 557, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 854, 0, 0, 3397, + 0, 0, 0, 1568, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1437, + 0, 1106, 0, 557, 1011, 0, 1011, 0, 0, 0, + 0, 557, -2102, 0, 0, 0, 0, 0, 0, 1668, + 1669, 1670, 1671, 1672, 1673, 0, 1568, 558, 0, 0, + 1106, 0, 0, 3052, 3177, 0, 0, 0, 0, 0, + 1639, 854, 0, 1640, 0, 0, 558, 1641, 1642, 0, + 0, 0, 0, 0, 0, 0, 558, 0, 558, 0, + 0, 558, 0, 0, 0, 0, 0, 558, 0, 558, + 0, 854, 0, 0, 0, 0, 0, 0, 1650, 0, + 0, 0, 558, 871, 0, -2102, 0, 558, 0, 0, + 0, 558, 558, 558, 558, 0, 558, 558, 0, 3092, + 3093, 3094, 3095, 0, 0, 0, 0, 0, 0, 3295, + 0, 0, 1652, 0, 0, 0, 0, 1106, 0, 0, + 0, 0, 0, 0, 0, -2102, 0, 0, 0, 0, + 0, 0, 3397, 0, 0, 0, 1568, 0, 0, 0, + 0, 1566, 0, 0, -46, 0, 0, 0, 0, 0, + 1567, 0, 0, 0, 0, 0, 0, 0, 0, 1777, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, + 0, 961, 961, 0, 3397, 961, 2, 2869, 3, 4, + 0, 0, 0, 1984, 0, 0, 1121, 1121, 0, 0, + 0, 5, 0, 0, 557, 1949, 6, 0, 0, 0, + 0, 0, 0, 0, 0, 7, 0, 0, 0, -2102, + 0, 0, 0, 0, 0, 0, 1777, 0, 0, 8, + 0, 0, 0, 3397, 0, 0, -2102, 0, 9, 0, + 10, -2102, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 11, 0, 12, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 558, 13, 0, 1259, 3215, 0, + 961, 1302, 1309, 0, 0, 0, 1618, 0, 0, -2102, + 14, 15, 16, 0, 0, 2211, 0, 0, 0, 808, + 0, 17, 0, 0, 0, 808, 0, 18, 0, 0, + 0, 2496, 0, 0, 0, 19, 2023, 20, 21, 0, + 0, 0, 0, 0, 1618, 0, 0, 0, 0, 0, + 0, 0, 22, 0, 1359, 0, 23, 0, 0, 0, + 0, 0, 0, 71, 1661, 0, 0, 0, 0, 71, + 0, 0, 1383, 0, 0, 0, 0, 0, 1431, 0, + 0, 1433, 24, 0, 1444, 1447, 1452, 1455, 0, 0, + 0, 0, 0, 0, 0, 2913, 0, 0, -1468, 0, + 0, 0, 1639, 0, 0, 1640, 0, 0, 0, 1641, + 1642, 0, 0, 1645, 1646, 1647, 0, 2104, 0, 0, + 0, 0, 0, 0, 25, 0, 0, 1623, 0, 1498, + 1302, 0, 0, 0, 0, 0, 0, 1568, 0, 0, + 1650, 0, 0, 0, 0, 0, 0, 1651, 1950, 1951, + 1952, 1582, 1953, 1954, 1955, 1956, 1957, 1958, 0, 0, + 1639, 0, 0, 1640, 0, 0, -2102, 1641, 1642, 0, + 1598, 1645, 1646, 1647, 1652, 71, 0, 0, 0, 0, + 0, 1608, 1609, 1610, 0, 1615, 1619, 0, 1648, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1650, 26, + 27, 28, 0, 808, 71, 1651, 0, 29, 0, 0, + 30, 3074, 0, 0, 0, 558, 0, 0, 0, 0, + 808, 1682, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1652, 0, 0, 0, 0, 0, 0, 1498, + 1498, 31, 0, 0, 0, 0, 1386, 0, 821, 0, + 32, 0, 0, 0, 0, 0, 0, 0, 0, 1618, + 0, 0, 0, 0, 558, 0, 33, 0, 0, 0, + 2637, 1653, 0, 34, -2102, 1720, 0, 35, 0, 1736, + 1741, 1668, 1669, 1670, 1671, 1672, 1673, 36, 1654, 0, + 1121, 1121, 0, 1655, 0, 0, 0, 0, 0, 37, + 0, 0, 0, 38, 0, 0, 0, 3371, 0, 0, + 0, 1387, 1388, 0, 0, 0, 1656, 1657, 0, 0, + 0, 0, 0, 39, 0, 0, 0, 0, 3395, 1653, + 0, 1658, 0, 0, 0, 0, 40, 0, 0, 41, + 0, 809, 42, 0, 0, 0, 1654, 43, 0, 0, + 1302, 1655, 1389, 1390, 0, 871, 1391, 1392, 0, 1302, + 0, 0, 0, 0, 44, 0, 0, 0, 0, 1659, + 0, 0, 1660, 0, 1656, 1657, 0, 0, 0, 0, + 0, 0, 0, 1302, 0, 0, 1661, 0, 45, 1658, + 0, 0, 0, 3435, 0, 0, 0, 558, 0, 0, + 0, 0, 46, 1639, 0, -46, 1640, 0, 0, 0, + 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, 0, + 0, 0, 0, 3461, 0, 0, 0, 1659, 0, 0, + 1660, 1648, 1393, 1394, 0, 0, 0, 0, 0, 0, + 0, 1650, 0, 0, 1661, 0, 0, 1662, 1651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -1880, 1581, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, -2141, 0, - 0, 0, 0, 0, 0, 0, 0, -1880, 1462, 0, - 1462, 1462, 2043, 0, 0, -2141, 0, 0, 0, 1580, - -2141, 0, 0, 1128, 1128, 0, 0, 0, 3112, 0, - 0, 0, 0, 0, 0, 0, 0, 1450, 1450, 0, - 2534, 0, 0, 0, 0, 1128, 0, 0, 0, 0, - 0, 0, 0, 0, 1580, 0, 0, 0, -2141, 0, - 0, 0, 0, 0, 0, 0, 864, 0, 0, 1581, - 0, 0, 2129, 0, 0, 0, 0, 0, 0, 0, - 2129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, -1880, 0, 0, 0, 3156, 3157, - 3158, 3159, 0, 0, 0, -1880, 0, 0, 0, 0, - 0, 0, 0, 1675, 0, 813, 0, 0, 0, 0, - 1580, 0, 0, 0, 0, -1880, 0, -1880, -1880, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1449, - 1449, 0, 0, 1580, 0, 0, 0, 0, 0, 2092, - 0, 0, 1450, 0, 0, 0, 0, 2095, 0, 0, - 0, 0, 0, 0, -1880, 0, 0, -1880, -1880, -1880, - 0, 2126, 0, 0, 0, 0, 0, 562, 0, 0, - 1581, 0, 0, 0, 0, 0, 0, 1580, 0, 0, - 0, 0, 2141, 0, 0, 0, 0, 0, 0, 2145, - 0, 0, 0, 0, 0, 2149, 2150, 2151, 2152, 2153, - 2154, 2155, 2156, 0, 0, 1581, -2141, 2165, 2166, 0, - 0, 0, 2179, 0, 0, 0, 2182, 0, 0, 2190, - 2191, 2192, 2193, 2194, 2195, 2196, 2197, 2198, 0, 0, - 2199, 0, 0, 0, 0, 0, 0, 1128, 0, 1312, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 3282, 0, 0, 0, 2225, 0, 0, - 0, 0, 1653, 0, 0, 1654, 0, 0, 0, 1655, - 1656, 1581, 0, 1659, 1660, 1661, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1580, - 1662, 0, 1623, 1624, 1581, 0, 0, 0, 0, 0, - 1664, 0, 1653, 0, 0, 1654, 0, 1665, 0, 1655, - 1656, 0, 0, 1659, 1660, 1661, -2141, 0, 0, 0, - 0, 0, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, - 0, 0, 0, 0, 1666, 0, 1449, 0, 1581, 0, - 1664, 0, 0, 0, 0, 0, 0, 1665, 0, 0, - 0, 0, 3373, 0, 0, 0, 0, 0, 0, 2534, - 0, 0, 0, 3178, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1666, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1451, 0, 0, 2360, - 0, 0, 0, 0, 0, 0, 1312, 0, 0, 2371, - 2372, 0, 0, 0, 0, 0, 0, 0, 0, 1653, - 0, 0, 1654, 3207, 0, 0, 1655, 1656, 0, 0, - 1659, 1660, 1661, 0, 562, 0, 0, 0, 0, 562, - 0, 1667, 0, 0, 0, 0, 0, 0, 0, 0, - 1312, 0, 0, 0, 0, 0, 0, 1664, 1668, 0, - 1581, 0, 0, 1669, 1665, 562, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1369, 2438, 1653, 0, 0, - 1654, 1667, 0, 0, 1655, 1656, 1670, 1671, 0, 562, - 562, 1666, 0, 1450, 1450, 0, 0, 0, 1668, 0, - 0, 1672, 0, 1669, 2464, 2465, 0, 2466, 0, 0, - 0, 0, 0, 0, 562, 1664, 0, 0, 1449, 0, - 0, 1690, -2141, 0, 0, 0, 1670, 1671, 0, 0, - 0, 0, 0, 0, 0, 0, 2492, 2493, 0, 1673, - 2225, 1672, 1674, 0, 0, 0, 0, 0, 0, 1666, - 0, 0, 0, 0, 0, 562, 1675, 0, 0, 0, - 0, 0, 0, 2129, 0, 1580, 0, 0, 0, 0, - 1690, 2518, 0, 0, 0, 0, 0, 0, 0, 1673, - 2528, 0, 1674, 0, 0, 3443, 0, 0, 1667, 0, - 0, 0, 0, 0, 0, 0, 1675, 0, 0, 1509, - 0, 1312, 0, 0, 1451, 1668, 0, 3467, 0, 0, - 1669, 0, 0, 0, 3220, 0, 0, 0, 0, 0, + 1931, 0, 0, 0, 0, 1652, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1663, 0, + 0, 0, 0, 0, 0, 0, 1395, 1396, 1397, 1398, + 1399, 1400, 1401, 1402, 0, 558, 1403, 1404, 0, 558, + 0, 0, 0, 0, 0, 2019, 0, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, -2141, -2141, 0, 0, 0, 0, 2563, - 0, 0, 0, 0, 0, 0, -2141, 0, 1672, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1677, - 1690, 0, 0, -2141, 0, 0, 0, 0, -2141, 1449, - 0, 0, 0, 0, 3507, 0, 0, 2581, 0, 0, - 0, 2587, 0, 0, 0, 1653, 2595, 2596, 1654, -2141, - 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 1677, - 1450, 0, 0, 1675, 3533, 1690, -2141, 0, 0, 0, - 0, 0, 1690, 1662, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1664, 0, 0, 1581, 1450, 0, 0, - 1665, 0, 0, 2617, 0, 0, 2620, 0, 2622, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 562, 0, - 0, 0, 0, 0, 2626, 0, 0, 1666, 0, 0, - 0, 1675, 1690, 0, 0, 0, 0, 0, 0, 1678, - 0, 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, - 1686, 1687, 0, 0, 0, 0, 1690, 0, 0, 0, - 0, 0, 0, 1735, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1677, 0, 0, 1678, - 1756, 2197, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, - 1686, 1687, 0, 0, 0, 0, 0, 0, 0, 1128, - 0, 0, 0, 0, 1690, 0, 1690, 0, 1451, 1451, - 0, 1980, 2684, 0, 1451, 0, 0, 1690, 0, 0, - 1690, 0, 0, 0, 1667, 1690, 0, 0, 1690, 0, - 0, 0, 0, 0, -2141, 0, 0, 0, 0, 0, - 0, 1668, 1450, 0, 0, 0, 1669, 0, 0, 0, + 0, 0, 0, 1452, 0, 1452, 1452, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1663, 0, 1121, 1121, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1618, + 2841, 0, 0, 0, 2104, 0, 0, 0, 0, 1121, + 0, 0, 1653, 0, 0, 0, 0, 0, 0, 0, + 1405, 1406, 0, 0, 0, 0, 0, 0, 0, 1654, + 0, 0, 0, 0, 1655, 0, 1664, 0, 0, 1665, + 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, + 0, 0, 0, 0, 0, 0, 0, 1656, 1657, 0, + 0, 1407, 1408, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1658, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 558, 0, + 0, 0, 558, 558, 1664, 0, 558, 1665, 1666, 1667, + 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 0, 0, + 1659, 2068, 0, 1660, 1639, 0, 0, 1640, 0, 2071, + 0, 1641, 1642, 558, 0, 0, 0, 1661, 0, 0, + 1662, 0, 0, 0, 0, 0, 0, 0, 558, 558, + 558, 558, 558, 558, 558, 558, 558, 558, 0, 0, + 0, 0, 1650, 2116, 71, 0, 0, 1409, 1410, -2102, + 2120, 0, 0, 0, 0, 0, 2124, 2125, 2126, 2127, + 2128, 2129, 2130, 2131, 0, 3394, 0, 0, 2140, 2141, + 0, 1411, 1412, 2154, 0, 0, 1652, 2157, 0, 0, + 2165, 2166, 2167, 2168, 2169, 2170, 2171, 2172, 2173, 0, + 0, 2174, 0, 0, 0, 0, 0, 0, 1121, 1639, + 1302, 0, 1640, 0, 0, 0, 1641, 1642, 1643, 1644, + 1645, 1646, 1647, 0, 0, 0, 0, 0, 2200, 1663, + 0, 71, 0, 71, 0, 2019, 0, 1648, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1650, 0, 0, + 0, 2870, 0, 0, 1651, 0, 0, 0, 0, 0, + 0, 2496, 1609, 1610, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 71, 0, 0, 0, 0, 0, 0, + 0, 1652, 0, -2102, 1639, 0, 0, 1640, 0, 71, + 0, 1641, 1642, 2104, 0, 1645, 1646, 1647, 0, 0, + -2102, 2104, 0, 0, 0, -2102, 0, 0, 0, 0, + 0, 0, 1648, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1650, 0, 0, 0, 0, 0, 0, 1651, + 0, 0, 0, 0, 0, 0, 808, 1664, 0, 0, + 1665, 1666, 1667, -2102, 1668, 1669, 1670, 1671, 1672, 1673, + 0, 0, 0, 2326, 0, 0, 1652, 0, 2532, 0, + 1302, 0, 0, 2337, 2338, 0, 0, 0, 0, 1638, + 0, 0, 0, 0, 1639, 0, 0, 1640, 1653, 0, + 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, + 0, 0, 0, 0, 558, 1654, 0, 0, 1661, 0, + 1655, 0, 1648, 0, 1302, 0, 1649, 0, 0, 0, + 0, 0, 1650, 0, 0, 71, 0, 0, 0, 1651, + 0, 0, 0, 1656, 1657, 0, 0, 0, 0, 1359, + 2404, 0, 0, 0, 0, 0, 0, 0, 1658, 0, + 0, 71, 0, 0, 0, 0, 1652, 0, 0, 0, + 0, 0, 0, 1653, 0, 0, 0, 0, 2430, 2431, + 0, 2432, 1441, 0, 0, 0, 0, 0, 0, 0, + 1654, 0, 0, 0, 0, 1655, 1659, 0, 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3486, 0, 0, 0, 0, 0, 0, 0, 1670, - 1671, 0, 1690, 0, 0, 0, 0, 0, 0, 1624, - 0, 0, 0, 0, 1672, 0, 1678, 0, 1312, 1679, - 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, + 2458, 2459, 0, 1661, 2200, 0, 1662, 0, 1656, 1657, + -2102, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1658, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 2484, 0, 0, 0, 0, + 0, 0, 2490, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1653, 0, 0, 0, 0, 0, 0, + 1498, 1659, 1302, 0, 1660, 0, 0, 0, 0, 0, + 1654, 0, 0, 0, 0, 1655, 0, 0, 1661, 0, + 3303, 0, 0, 0, 0, 0, 0, 2496, 0, 0, + 0, 0, 0, 0, 0, 0, 1676, 0, 1656, 1657, + 2525, 0, 0, 0, 0, 1663, 0, 0, 0, 0, + 0, 0, 0, 1658, 0, 0, 0, 0, -2102, 0, + 0, 0, 0, 0, 0, 1668, 1669, 1670, 1671, 1672, + 1673, 0, 0, 0, 0, 0, 0, 2542, 0, 0, + 0, 2548, 0, 0, 0, 1676, 2556, 2557, 0, 0, + 558, 1659, 0, 0, 1660, 558, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1661, 0, + 0, 1662, 0, 0, 0, 0, 0, 0, 0, 1441, + 1663, 558, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2578, 0, 0, 2581, 0, 2583, 0, + 0, 0, 0, 558, 558, 0, 0, 0, 0, 0, + 0, 0, 0, 1664, 2587, 0, 1665, 1666, 1667, 0, + 1668, 1669, 1670, 1671, 1672, 1673, 0, 558, 0, 0, + 0, 0, 0, 1934, 1676, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1720, 0, 1639, 0, 0, 1640, + 0, 0, 0, 1641, 1642, 0, 0, 0, 558, 0, + 1663, 1741, 2172, 0, 0, 0, 2104, 1676, 0, 0, + 0, 0, 0, 0, 1676, 0, 0, 0, 1664, 0, + 1121, 1665, 1666, 1667, 1650, 1668, 1669, 1670, 1671, 1672, + 1673, -2102, 0, 2643, 0, 1639, 0, 0, 1640, 0, + 0, 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1652, 0, + 0, 0, 0, 1648, 1676, 0, 0, 2846, 0, 0, + 0, 0, 0, 1650, 0, 0, 0, 0, 0, 0, + 1651, 0, 0, 0, 0, 0, 0, 0, 1676, 0, + 1610, 0, 0, 0, 0, 0, 0, 0, 0, 1302, + 0, 0, 0, 0, 0, 0, 0, 1652, 1664, 0, + 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, + 1673, 0, 0, 3155, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1676, 0, 1676, 0, + 1441, 1441, 0, 1959, 0, 0, 1441, 0, 0, 1676, + 0, 0, 1676, 0, 0, -2102, 0, 1676, 2753, 0, + 1676, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, -2102, 0, 0, 0, 0, -2102, 0, 0, + 0, 0, 0, 0, 1639, 0, 0, 1640, 0, 558, + 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, + 0, 0, 0, 1676, 1653, 0, 0, 0, 0, 0, + 0, 0, 1648, 0, 0, -2102, 0, 0, 0, 0, + 0, 1654, 1650, 0, 0, 0, 1655, 0, 0, 1651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1673, 0, 0, 1674, 0, 0, -46, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1675, - 0, 0, 1676, 0, -2141, 0, 0, 2803, 0, 0, - 1, 1682, 1683, 1684, 1685, 1686, 1687, 0, 1690, 0, - 2, 0, 3, 4, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1690, 5, 0, 0, 0, 0, - 6, 0, 0, 0, 0, 1690, 1690, 1690, 0, 7, - 0, 0, 1690, 1450, 0, 0, 1690, 0, 0, 0, - 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, - 0, 0, 9, 0, 10, 0, 0, 0, 0, 0, - 0, 0, 1396, 0, 826, 0, 11, 0, 12, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, - 0, 0, 1677, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 14, 15, 16, 0, 0, 1690, - 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, - 0, 18, 0, 0, 0, 0, 0, 0, 0, 19, - 0, 20, 21, 0, 2883, 0, 0, 1397, 1398, 0, - 2885, 2095, 0, 0, 0, 0, 22, 0, 1690, 0, - 23, 0, 0, 0, 0, 0, 2894, 0, 0, 0, - 0, 0, 0, 0, 1690, 0, 0, 0, 0, 1690, - 0, 0, 2907, 0, 0, 2910, 24, 2912, 1399, 1400, - 0, 0, 1401, 1402, 0, 2916, 1980, 0, 0, 0, - 0, 0, -1497, 2923, 2924, 0, 0, 0, 0, 0, - 2931, 0, 1678, 0, 0, 1679, 1680, 1681, 0, 1682, - 1683, 1684, 1685, 1686, 1687, 0, 0, 2944, 25, 0, - 0, 0, 0, 2570, 0, 0, 0, 2959, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1656, + 1657, 0, 0, 0, 0, 0, 1652, 0, 0, 0, + 0, 0, 0, 0, 1658, 0, 0, 0, 0, 0, + 1661, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1676, 0, 0, + 0, 2831, 0, 0, 0, 0, 0, 2833, 2071, 0, + 0, 0, 1659, 1676, 0, 1660, 0, 0, 0, 0, + 0, 0, 2842, 1676, 1676, 1676, 0, 0, 0, 1661, + 1676, 0, 1662, 0, 1676, 0, 0, 0, 2855, 0, + 0, 2858, 0, 2860, 0, 0, 0, 0, 0, 0, + 0, 2864, 0, 0, 0, 0, 0, 0, 0, 2871, + 2872, 0, 0, 1653, 0, 0, 2879, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1128, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1403, 1404, - 0, 0, 0, 0, 0, 1450, 0, 0, 0, 0, + 1654, 2888, -2102, 0, 0, 1655, 0, 0, 0, 0, + 0, 2903, 0, 0, 0, 0, 0, 1676, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1656, 1657, + 0, 1121, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1658, 0, 0, 0, 0, 0, 0, + 0, 1663, 0, 0, 0, 1676, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1676, 0, 0, 0, 0, 1676, 0, 0, 0, + 0, 1659, 0, 0, 1660, 0, 0, 0, 0, 0, + 2326, 0, 2326, 1959, 0, 0, 0, 0, 1661, 0, + 0, 1662, 0, 0, 0, 0, 0, 0, 0, 0, + -2102, 0, 0, 0, 0, 0, 0, 1668, 1669, 1670, + 1671, 1672, 1673, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 26, 27, 28, 0, 1735, 0, - 0, 0, 29, 0, 0, 30, 0, 0, 0, 0, - 0, 2360, 0, 2360, 0, 0, 0, 0, 0, 0, - 0, 0, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, - 0, 0, 1413, 1414, 0, 0, 31, 0, 0, 0, - 0, 0, 0, 3117, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 33, 0, 0, 0, 1690, 0, 0, 34, 0, - 0, 0, 35, 1980, 1980, 0, 1451, 1451, 1451, 1451, - 1451, 1451, 0, 36, 1451, 1451, 1451, 1451, 1451, 1451, - 1451, 1451, 1451, 1451, 1980, 37, 0, 0, 0, 38, - 0, 0, 0, 0, 0, 0, 0, 1415, 1416, 0, - 0, 0, 0, 0, 0, 3172, 3173, 0, 3176, 39, - 0, 0, 0, 0, 0, 0, 0, 0, 1397, 1398, - 0, 0, 0, 40, 0, 0, 41, 0, 0, 42, - 0, 0, 0, 0, 43, 0, 0, 0, 1417, 1418, - 0, 0, 3197, 0, 0, 0, 0, 0, 0, 0, - 0, 44, 0, 0, 0, 0, 0, 0, 0, 1399, - 1400, 0, 3206, 1401, 1402, 0, 0, 0, 3210, 3211, - 0, 0, 0, 3212, 0, 45, 0, 0, 3215, 0, - 0, 3218, 3219, 0, 0, 0, 2360, 1312, 0, 46, - 3227, 0, -46, 0, 0, 1690, 0, 0, 1690, 0, - 0, 0, 0, 0, 0, 1128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1664, + 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, + 1672, 1673, 0, 0, 0, 0, 2110, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1690, - 0, 0, 0, 0, 0, 0, 1419, 1420, 0, 1403, - 1404, 0, 0, 0, 1690, 0, 1397, 1398, 1690, 3270, - 0, 0, 1690, 1690, 1690, 1690, 1690, 1690, 1690, 1690, - 1421, 1422, 0, 0, 0, 1451, 1451, 0, 1690, 1690, - 0, 0, 0, 0, 0, 0, 3289, 0, 0, 0, - 0, 0, 1690, 0, 0, 1690, 0, 1399, 1400, 0, - 0, 1401, 1402, 1690, 1690, 1690, 1690, 1690, 1690, 1690, - 1690, 1690, 1690, 1405, 1406, 1407, 1408, 1409, 1410, 1411, - 1412, 0, 0, 1413, 1414, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1653, 0, 0, 1654, 1690, 0, - 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, 0, + 3108, 3109, 0, 0, 0, 0, 0, 0, 0, 0, + 1663, 0, 0, 0, 1639, 0, 0, 1640, 0, 0, + 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, + 0, 0, 0, 0, 0, 3132, 0, 0, 0, 0, + 0, 0, 1648, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1650, 0, 0, 3141, 0, 0, 0, 1651, + 0, 3145, 3146, 0, 0, 0, 3147, 0, 0, 0, + 0, 3150, 0, 0, 3153, 3154, 1676, 0, 0, 2326, + 1302, 0, 0, 3162, 1959, 1959, 1652, 1441, 1441, 1441, + 1441, 1441, 1441, 0, 1121, 1441, 1441, 1441, 1441, 1441, + 1441, 1441, 1441, 1441, 1441, 1959, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1664, 0, + 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, + 1673, 0, 0, 0, 0, 2110, 1387, 1388, 3203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1662, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1664, 0, 0, 0, 0, 1403, 1404, 1665, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1451, 0, 0, 0, 0, 0, 0, 0, 1415, 1416, - 0, 0, 0, 0, 0, 0, 1666, 2803, 0, 0, + 0, 1639, 0, 0, 1640, 3222, 0, 0, 1641, 1642, + 1643, 1644, 1645, 1646, 1647, 0, 0, 1389, 1390, 0, + 0, 1391, 1392, 1653, 0, 0, 0, 0, 0, 1648, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1650, + 1654, 0, 0, 0, 0, 1655, 1651, 0, 0, 0, + 0, 0, 0, 1676, 0, 0, 1676, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1656, 1657, + 0, 0, 0, 1652, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1658, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1393, 1394, 0, + 0, 1676, 0, 0, 0, 1676, 0, 0, 0, 1676, + 1676, 1676, 1676, 1676, 1676, 1676, 1676, 0, 2753, 0, + 0, 1659, 1441, 1441, 1660, 1676, 1676, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1661, 1676, + 0, 1662, 1676, 0, 0, 1619, 0, 0, 0, 0, + 1676, 1676, 1676, 1676, 1676, 1676, 1676, 1676, 1676, 1676, + 0, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 0, + 1653, 1403, 1404, 0, 0, 0, 0, 0, 0, 2548, + 0, 0, 0, 0, 0, 1676, 0, 1654, 0, 0, + 0, 0, 1655, 0, 0, 0, 3318, 3319, 0, 0, + 3320, 0, 1610, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1656, 1657, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 3338, 0, 0, + 1658, 0, 0, 0, 0, 0, 0, 0, 1441, 0, + 1663, 0, 0, 0, 0, 1405, 1406, 0, 0, 0, + 0, 3350, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1659, 0, + 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1661, 1407, 1408, 1662, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1633, 0, 0, 0, 0, 1417, - 1418, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 0, - 0, 1413, 1414, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1652, 0, 0, 0, 0, 1653, 0, 2587, - 1654, 0, 0, 1690, 1655, 1656, 1657, 1658, 1659, 1660, - 1661, 0, 0, 0, 1690, 1690, 3388, 3389, 0, 0, - 3390, 0, 1624, 0, 0, 1662, 0, 0, 0, 1663, - 0, 0, 0, 1667, 0, 1664, 0, 0, 0, 0, - 0, 0, 1665, 0, 0, 0, 0, 0, 0, 3410, - 1668, 0, 0, 0, 0, 1669, 1415, 1416, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1419, 1420, 1666, - 0, 0, 0, 3422, 0, 0, 0, 0, 1670, 1671, - 0, 1690, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1421, 1422, 1672, 0, 0, 0, 1417, 1418, 0, - 0, 0, 0, 0, 0, 0, 0, 1690, 1690, 1690, - 0, 2060, 1980, 1980, 1980, 1980, 1980, 1980, 0, 0, - 0, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, - 1980, 1673, 0, 0, 1674, 1690, 1690, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1675, 0, 0, 1676, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1690, 0, 0, 3172, 0, 1667, 0, 3483, 0, - 0, 1690, 1128, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1668, 0, 0, 3493, 0, 1669, 0, - 0, 2360, 0, 2360, 0, 1419, 1420, 0, 0, 0, - 0, 0, 0, 1128, 0, 0, 1690, 0, 0, 0, - 0, 1670, 1671, 0, 0, 0, 0, 0, 0, 1421, - 1422, 3518, 0, 0, 1690, 0, 1672, 0, 0, 0, - 1690, 0, 0, 0, 0, 0, 0, 0, 1690, 1690, - 0, 0, 0, 0, 0, 0, 1980, 1980, 0, 0, - 0, 1677, 0, 0, 0, 0, 0, 0, 0, 0, - 1690, 1451, 1451, 1690, 1673, 1690, 0, 1674, 3543, 1690, - 0, 0, 0, 0, 0, 0, 0, 0, 3172, 0, - 0, 1675, 0, 0, 1676, 0, 0, 0, 0, 0, - 1128, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1653, 0, 0, 1654, 0, - 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, - 0, 0, 0, 3586, 0, 0, 0, 1690, 0, 0, - 0, 0, 0, 1662, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1664, 0, 0, 0, 0, 0, 0, - 1665, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1678, 0, 0, 1679, 1680, 1681, 0, 1682, 1683, - 1684, 1685, 1686, 1687, 0, 0, 0, 1666, 0, 0, - 0, 1955, 0, 0, 1677, 1653, 0, 0, 1654, 0, - 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, + 0, 0, 1676, 1676, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 3108, + 0, 0, 0, 3411, 0, 0, 0, 1121, 1664, 0, + 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, + 1673, 3421, 0, 0, 0, 2429, 2326, 0, 2326, 0, + 0, 0, 0, 0, 0, 0, 1121, 0, 0, 0, + 0, 0, 1409, 1410, 0, 0, 0, 1663, 0, 1676, + 0, 0, 0, 0, 3446, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1411, 1412, 0, 0, + 0, 0, 0, 0, 0, 1676, 1676, 1676, 0, 0, + 1959, 1959, 1959, 1959, 1959, 1959, 2036, 0, 0, 1959, + 1959, 1959, 1959, 1959, 1959, 1959, 1959, 1959, 1959, 0, + 0, 3471, 0, 1676, 1676, 1639, 0, 0, 1640, 0, + 0, 3108, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, + 0, 0, 0, 1121, 0, 0, 0, 0, 0, 1676, + 0, 0, 0, 1648, 0, 1676, 0, 0, 0, 0, + 0, 0, 0, 1650, 0, 0, 0, 0, 0, 0, + 1651, 0, 0, 0, 0, 1664, 3514, 0, 1665, 1666, + 1667, 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 0, + 1676, 0, 2529, 0, 0, 0, 0, 1652, 0, 0, + 0, 0, 0, 722, 0, 0, 0, 1676, 0, 0, + 0, 0, 0, 1676, 0, 0, 0, 0, 0, 0, + 0, 1676, 1676, 0, 0, 0, 0, 0, 0, 1959, + 1959, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1676, 1441, 1441, 1676, 0, 1676, 0, + 0, 0, 1676, 0, 0, 0, 0, 0, 0, 0, + 723, 0, 0, 3568, 3568, 3568, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 724, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1639, + 3568, 0, 1640, 0, 1653, 0, 1641, 1642, 1643, 1644, + 1645, 1646, 1647, 0, 0, 0, 0, 0, 1676, 0, + 0, 1654, 0, 0, 0, 0, 1655, 1648, 0, 0, + 0, 0, 0, 0, 0, 725, 0, 1650, 0, 0, + 0, 3568, 0, 0, 1651, 726, 0, 0, 0, 1656, + 1657, 0, 0, 0, 0, 0, 0, 0, 727, 0, + 0, 0, 0, 728, 1658, 0, 0, 0, 0, 0, + 0, 1652, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1639, 0, + 0, 1640, 729, 0, 0, 1641, 1642, 1643, 1644, 1645, + 1646, 1647, 1659, 0, 0, 1660, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1648, 0, 0, 1661, + 0, 0, 1662, 0, 0, 0, 1650, 0, 1676, 0, + 0, 0, 0, 1651, 0, 730, 0, 0, 0, 731, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 3640, 3640, 3640, 1662, 0, 0, 0, 2898, 0, 0, - 0, 0, 0, 1664, 0, 0, 0, 0, 0, 0, - 1665, 0, 0, 0, 0, 0, 0, 3640, 0, 0, - 0, 0, 1653, 0, 0, 1654, 1690, 0, 0, 1655, - 1656, 1657, 1658, 1659, 1660, 1661, 0, 1666, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1451, 0, - 1662, 0, 0, 0, 1667, 0, 0, 0, 3640, 0, - 1664, 0, 0, 0, 0, 0, 0, 1665, 0, 0, - 0, 1668, 0, 0, 1678, 0, 1669, 1679, 1680, 1681, - 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, 0, - 0, 0, 0, 0, 1666, 0, 0, 0, 0, 1670, - 1671, 0, 0, 0, 0, 0, 1690, 0, 1690, 0, - 0, 0, 0, 0, 1672, 0, 0, 1690, 0, 0, + 1441, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1652, 0, 0, 0, 0, 0, 1639, 0, 1653, 1640, + 0, 0, 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, + 0, 0, 0, 0, 0, 1654, 0, 0, 0, 0, + 1655, 0, 0, 0, 1648, 0, 0, 0, 0, 0, + 0, 0, 0, 544, 1650, 0, 1676, 0, 1676, 732, + 0, 1651, 0, 1656, 1657, 0, 0, 1676, 0, 0, + 0, 1663, 0, 0, 733, 0, 0, 0, 1658, 0, + 1676, 0, 0, 1676, 0, 1676, 0, 0, 1652, 1676, + 0, 0, 1959, 1959, 0, 0, 1676, 1676, 0, 0, + 0, 0, 0, 0, 1676, 0, 0, 1653, 0, 734, + 0, 0, 735, 1676, 0, 0, 1659, 0, 0, 1660, + 0, 0, 0, 736, 1654, 0, 737, 0, 1676, 1655, + 0, 0, 0, 1661, 0, 0, 1662, 0, 0, 0, + 0, 0, 0, 0, 738, 0, 0, 0, 0, 0, + 0, 0, 1656, 1657, 0, 0, 0, 0, 739, 0, + 0, 0, 0, 0, 740, 741, 1441, 1658, 0, 0, + 0, 0, 0, 0, 0, 742, 0, 0, 0, 1664, + 0, 743, 1665, 1666, 1667, 1653, 1668, 1669, 1670, 1671, + 1672, 1673, 0, 0, 0, 0, 2562, 0, 0, 0, + 0, 0, 1654, 0, 0, 1659, 0, 1655, 1660, 744, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1690, 0, 0, 1690, 1667, 1690, 0, 0, 0, 1690, - 0, 0, 1980, 1980, 0, 0, 1690, 1690, 0, 0, - 0, 1668, 1673, 0, 1690, 1674, 1669, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1690, 0, 1675, - 0, 0, 1676, 0, 0, 0, 0, 0, 0, 1670, - 1671, 0, 1690, 0, 0, 0, 0, 0, 727, 0, - 0, 1667, 0, 1653, 1672, 0, 1654, 0, 0, 0, - 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, 1668, 0, - 0, 0, 0, 1669, 0, 0, 0, 0, 0, 0, - 1451, 1662, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1664, 1673, 0, 0, 1674, 1670, 1671, 1665, 0, - 0, 0, 0, 0, 0, 728, 0, 0, 0, 1675, - 0, 1672, 1676, 0, 0, 0, 0, 0, 0, 0, - 0, 729, 0, 0, 0, 1666, 0, 1653, 0, 0, - 1654, 0, 1677, 0, 1655, 1656, 1657, 1658, 1659, 1660, - 1661, 0, 0, 0, 0, 0, 0, 0, 0, 1673, - 0, 0, 1674, 0, 0, 1662, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1664, 1675, 0, 0, 1676, - 730, 0, 1665, 0, 0, 0, 0, 0, 0, 0, - 731, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 732, 0, 0, 0, 0, 733, 1666, - 1690, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1677, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1667, 0, 0, 0, 0, 734, 0, 0, - 1980, 1451, 0, 0, 0, 0, 0, 0, 0, 1668, - 0, 0, 1678, 0, 1669, 1679, 1680, 1681, 0, 1682, - 1683, 1684, 1685, 1686, 1687, 1690, 1690, 1848, 0, 1690, - 0, 0, 0, 0, 0, 0, 0, 1670, 1671, 1677, - 735, 0, 0, 0, 736, 0, 0, 0, 0, 0, - 1690, 0, 1672, 0, 0, 0, 0, 0, 0, 1690, - 0, 0, 0, 1690, 1690, 1690, 1667, 0, 1690, 0, - 0, 1690, 1690, 0, 0, 0, 0, 0, 0, 0, - 1690, 0, 0, 1668, 0, 0, 0, 0, 1669, 0, - 1673, 0, 1678, 1674, 0, 1679, 1680, 1681, 0, 1682, - 1683, 1684, 1685, 1686, 1687, 0, 0, 1675, 0, 2135, - 1676, 1670, 1671, 0, 0, 737, 0, 0, 0, 0, - 0, 0, 0, 1690, 0, 0, 1672, 0, 0, 1980, - 738, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1690, 0, 0, 0, 0, 0, 0, 1678, - 0, 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, - 1686, 1687, 0, 0, 1673, 739, 2135, 1674, 740, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 741, - 0, 1675, 742, 0, 1676, 0, 0, 0, 0, 0, + 1387, 1388, 1661, 0, 0, 1662, 0, 0, 0, 0, + 1656, 1657, 0, 0, 0, 1663, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1658, 0, 0, 0, 0, + 0, 0, 0, 0, 722, 0, 0, 0, 0, 0, + 0, 1389, 1390, 0, 0, 1391, 1392, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 743, 0, 0, 0, 1980, 0, 0, 0, 0, - 1677, 0, 0, 0, 0, 744, 0, 0, 0, 0, - 0, 0, 746, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 747, 0, 0, 0, 0, 0, 748, 0, - 0, 1690, 1690, 1690, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1659, 0, 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1690, 0, 0, 0, 749, 0, 0, - 0, 0, 0, 0, 0, 1690, 0, 0, 0, 0, - 0, 0, 0, 0, 1677, 0, 0, 0, 0, 0, + 1661, 0, 0, 1662, 0, 0, 0, 0, 1959, 1441, + 0, 723, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1663, 0, 0, 724, 0, 0, + 0, 0, 0, 1676, 1676, 0, 0, 0, 0, 0, + 0, 1393, 1394, 1664, 0, 0, 1665, 1666, 1667, 0, + 1668, 1669, 1670, 1671, 1672, 1673, 0, 1676, 0, 0, + 2773, 0, 0, 0, 0, 0, 1676, 0, 0, 0, + 1676, 1676, 1676, 0, 0, 1676, 725, 0, 1676, 1676, + 0, 0, 0, 0, 0, 0, 726, 1676, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 727, + 0, 0, 1663, 0, 728, 1395, 1396, 1397, 1398, 1399, + 1400, 1401, 1402, 0, 0, 1403, 1404, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1676, 0, + 0, 0, 1664, 729, 1959, 1665, 1666, 1667, 0, 1668, + 1669, 1670, 1671, 1672, 1673, 0, 0, 1676, 0, 2838, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 730, 0, 0, 0, + 731, 0, 0, 0, 0, 0, 0, 0, 0, 1405, + 1406, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1959, 0, 0, + 1664, 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, + 1671, 1672, 1673, 0, 0, 0, 0, 2852, 0, 0, + 1407, 1408, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1676, 1676, 1676, 0, 0, 0, 0, + 732, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1676, 0, 733, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1676, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1678, 0, 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, - 1685, 1686, 1687, 0, 0, 0, 1690, 2463, 0, 0, - 0, 0, 0, 0, 0, 0, 1690, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 734, 0, 0, 735, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 736, 0, 0, 737, 0, 0, + 0, 0, 0, 0, 0, 0, 1409, 1410, 0, 0, + 0, 0, 0, 0, 0, 738, 1676, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1676, 0, 0, 739, + 1411, 1412, 0, 0, 0, 0, 741, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 742, 0, 0, 0, + 0, 1676, 743, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1690, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1676, 0, 0, 0, + 744, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1678, 0, 1690, 1679, 1680, 1681, - 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, 0, - 0, 2567, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1690, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 1068, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 1069, 142, 1070, 1071, 0, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 1690, 158, 159, 160, 161, 796, 0, - 797, 0, 1075, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 1078, 196, 0, 197, - 198, 199, 200, 201, 202, 14, 15, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 237, 23, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 292, 293, 294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1088, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 325, 1090, - 327, 328, 329, 330, 1091, 331, 332, 333, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 1094, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 26, 27, 28, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 33, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 35, 433, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 37, 0, 454, 455, - 38, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 0, 466, 467, 806, 469, 807, 1100, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 1101, 40, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 809, 1102, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 44, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 1103, 0, 45, 0, 0, 0, - 0, 1104, 1105, 1106, 0, 0, 0, 0, 1107, 0, - 1108, 3363, 0, 0, 0, 0, 1109, 1110, 1111, 1112, - 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 1068, 0, 0, 130, - 131, 132, 0, 133, 134, 135, 136, 137, 138, 139, - 140, 1069, 142, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 797, 0, - 1075, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 1078, 196, 0, 197, 198, 199, - 200, 201, 202, 14, 15, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 237, 23, - 238, 239, 240, 241, 242, 243, 244, 245, 0, 1083, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 270, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 292, 293, 294, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1088, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 325, 1090, 327, 328, - 329, 330, 1091, 331, 332, 333, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 1094, - 344, 345, 0, 0, 346, 347, 348, 349, 350, 351, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 26, 27, 28, 0, 365, 366, 803, - 368, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 406, 407, 408, 409, 1096, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 33, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 35, 433, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 805, 37, 0, 454, 455, 38, 456, - 457, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 808, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 1101, 40, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 809, 1102, 493, 0, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 44, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 1103, 0, 45, 0, 0, 0, 0, 1104, - 1105, 1106, 0, 0, 0, 0, 1107, 0, 1108, 0, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 118, 1062, - 826, 1063, 1064, 1065, 1066, 1067, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 1068, 0, 0, 130, 131, 132, - 0, 133, 134, 135, 136, 137, 138, 139, 140, 1069, - 142, 1070, 1071, 0, 145, 146, 147, 148, 149, 150, - 1072, 795, 151, 152, 153, 154, 1073, 1074, 157, 0, - 158, 159, 160, 161, 796, 0, 797, 0, 1075, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 1076, 192, 193, - 1077, 195, 1078, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 1079, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 1080, 223, 224, - 225, 226, 227, 228, 798, 1081, 230, 0, 231, 232, - 1082, 234, 0, 235, 0, 236, 237, 23, 238, 239, - 240, 241, 242, 243, 244, 245, 0, 1083, 1084, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 270, 271, 272, 273, 274, 275, - 276, 1085, 1086, 0, 1087, 0, 280, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 292, 293, 294, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 1088, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 1089, 325, 1090, 327, 328, 329, 330, - 1091, 331, 332, 333, 334, 1092, 800, 336, 1093, 338, - 339, 340, 0, 341, 342, 0, 0, 1094, 344, 345, - 0, 0, 346, 347, 348, 349, 350, 351, 802, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 26, 27, 28, 0, 365, 366, 803, 368, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 1095, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 406, 407, 408, 409, 1096, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 33, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 433, 434, 435, 1097, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 805, 0, 0, 454, 455, 38, 456, 457, 458, - 459, 460, 461, 462, 0, 463, 1098, 1099, 0, 0, - 466, 467, 806, 469, 807, 1100, 471, 472, 808, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 1101, - 40, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 809, 1102, 493, 0, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 44, 504, + 0, 0, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1676, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 1676, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 14, 15, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 23, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 26, 27, 28, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 33, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 35, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 37, 0, 450, 451, 38, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 40, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 804, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 44, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 45, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 3293, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 14, 15, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 23, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 26, + 27, 28, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 33, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 35, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 37, + 0, 450, 451, 38, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 40, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 804, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 44, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 1103, 0, 45, 0, 0, 0, 0, 1104, 1105, 1106, - 0, 0, 0, 0, 1107, 0, 1108, 0, 0, 0, - 0, 0, 1109, 1110, 1111, 1112, 1272, 1062, 826, 1063, - 1064, 1065, 1066, 1067, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 1273, 127, 128, 129, 0, 0, 0, - 1274, 0, 1068, 0, 0, 1275, 131, 132, 0, 1276, - 134, 135, 1277, 137, 138, 139, 140, 1069, 1278, 1070, - 1071, 0, 145, 146, 147, 148, 149, 150, 1072, 795, - 151, 152, 153, 154, 1073, 1074, 157, 0, 158, 159, - 160, 161, 796, 0, 1279, 0, 1280, 165, 166, 167, - 168, 169, 1281, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 1282, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 1076, 192, 193, 1077, 195, - 1078, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 1283, 0, 207, 208, 1079, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 1080, 223, 224, 225, 226, - 227, 228, 798, 1081, 230, 0, 231, 232, 1082, 234, - 0, 235, 0, 236, 1284, 0, 1285, 239, 240, 1286, - 1287, 243, 244, 245, 0, 1083, 1084, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 1288, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 1289, 271, 272, 273, 274, 275, 276, 1085, - 1086, 0, 1087, 0, 280, 1290, 1291, 283, 1292, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 1293, 293, - 1294, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 1295, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 1089, 1296, 1090, 327, 328, 329, 330, 1091, 331, - 332, 1297, 334, 1092, 800, 336, 1093, 338, 339, 340, - 0, 341, 342, 0, 0, 1094, 344, 345, 0, 886, - 346, 347, 348, 1298, 350, 1299, 802, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 803, 1300, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 1095, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 1301, 407, - 408, 409, 1096, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 1302, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 1303, 434, - 435, 1097, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 1304, 452, 805, - 0, 0, 454, 455, 0, 456, 1305, 458, 459, 460, - 461, 462, 0, 463, 1098, 1099, 0, 0, 466, 467, - 806, 469, 807, 1100, 471, 472, 1306, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 1307, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 1102, 493, 1308, 494, 1309, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 1103, 0, - 0, 0, 0, 0, 0, 1104, 1105, 1106, 0, 0, - 0, 0, 1107, 0, 1108, 1310, 0, 0, 0, 0, - 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, 1064, 0, - 1066, 1067, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 1068, 0, 0, 130, 131, 132, 0, 133, 134, 135, - 136, 137, 138, 139, 140, 1069, 142, 1070, 1071, 0, - 145, 146, 147, 148, 149, 150, 1072, 795, 151, 152, - 153, 154, 1073, 1074, 157, 0, 158, 159, 160, 161, - 796, 0, 797, 0, 164, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 180, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 1076, 192, 193, 1077, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 14, 15, 203, - 204, 205, 206, 0, 0, 207, 208, 1079, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 1080, 223, 224, 225, 226, 227, 228, - 798, 1081, 230, 0, 231, 232, 1082, 234, 0, 235, - 0, 236, 237, 23, 238, 239, 240, 241, 242, 243, - 244, 245, 0, 1083, 1084, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 270, 271, 272, 273, 274, 275, 276, 1085, 1086, 0, - 1087, 0, 280, 281, 282, 283, 284, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 292, 293, 294, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 1088, 304, + 515, 516, 517, 518, 519, 520, 1096, 0, 45, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 23, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 1089, - 325, 1090, 327, 328, 329, 330, 0, 331, 332, 333, - 334, 1092, 800, 336, 1093, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 349, 350, 351, 802, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 26, 27, 28, - 0, 365, 366, 803, 368, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 1095, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 26, 27, 28, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 406, 407, 408, 409, - 1096, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 33, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 35, 433, 434, 435, 1097, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 451, 452, 805, 37, 0, - 454, 455, 38, 456, 457, 458, 459, 460, 461, 462, - 0, 463, 1098, 1099, 0, 0, 466, 467, 806, 469, - 807, 1100, 471, 472, 808, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 40, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 809, 1102, 493, - 0, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 44, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 0, 0, 45, 0, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 33, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 38, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 40, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 804, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 44, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 45, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 1264, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 1265, 126, 127, 128, 0, 0, + 0, 1266, 0, 1062, 0, 0, 1267, 130, 131, 0, + 132, 133, 134, 1268, 136, 137, 138, 139, 1063, 1269, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 1270, 0, 1271, 164, 165, + 166, 167, 168, 1272, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 1273, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 1274, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 1275, 0, 1276, 238, 239, + 1277, 1278, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 1279, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 1280, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 1281, 1282, 281, 1283, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 1284, + 291, 1285, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1286, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 1287, 1084, 325, 326, 327, 328, 1085, + 329, 330, 1288, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 881, 344, 345, 346, 1289, 348, 1290, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 1291, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 1292, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 1293, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 1294, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 1295, 448, 800, 0, + 0, 450, 451, 0, 452, 1296, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 1297, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 1298, 490, 1299, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 1300, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 0, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1107, 0, 1108, 0, 0, 0, 0, 0, 1109, 1110, - 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 163, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 14, 15, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 23, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 0, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 26, 27, 28, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 33, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 35, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 37, 0, 450, 451, 38, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 40, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 804, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 44, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 0, 0, 45, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 1448, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 1449, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 1450, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 1451, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 1264, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 1068, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 1069, 142, 1070, 1071, 1458, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 0, 158, 159, 160, 161, 796, 0, - 797, 0, 1075, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 1078, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 237, 1459, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 0, 1460, 291, 292, 293, 294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1088, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 325, 1090, - 327, 328, 329, 330, 1091, 331, 332, 333, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 1094, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 433, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 0, 0, 454, 455, - 0, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 1461, 466, 467, 806, 469, 807, 1100, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 1101, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 1102, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 1103, 0, 0, 0, 0, 0, - 0, 1104, 1105, 1106, 0, 0, 0, 0, 1107, 0, - 1108, 0, 0, 0, 0, 0, 1109, 1110, 1111, 1112, - 1272, 1062, 826, 1063, 1064, 1065, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 1274, 0, 1068, 0, 0, 1275, - 131, 132, 0, 1276, 134, 135, 1277, 137, 138, 139, - 140, 1069, 1278, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 1279, 0, - 1280, 165, 166, 167, 168, 169, 1281, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 1282, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 1078, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 1284, 0, - 1285, 239, 240, 1286, 1287, 243, 244, 245, 0, 1083, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 1288, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 1289, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 1290, - 1291, 283, 1292, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 1293, 293, 1294, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1295, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 1296, 1090, 327, 328, - 329, 330, 1091, 331, 332, 1297, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 1094, - 344, 345, 0, 0, 346, 347, 348, 1298, 350, 1299, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 803, - 1300, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 1301, 407, 408, 409, 1096, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 1302, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 1303, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 1304, 452, 805, 0, 0, 454, 455, 0, 456, - 1305, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 1306, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 1307, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 1102, 493, 2368, 494, 1309, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 1103, 0, 0, 0, 0, 0, 0, 1104, - 1105, 1106, 0, 0, 0, 0, 1107, 0, 1108, 0, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 1272, 1062, - 826, 1063, 1064, 1065, 1066, 1067, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 1274, 0, 1068, 0, 0, 1275, 131, 132, - 0, 1276, 134, 135, 1277, 137, 138, 139, 140, 1069, - 1278, 1070, 1071, 0, 145, 146, 147, 148, 149, 150, - 1072, 795, 151, 152, 153, 154, 1073, 1074, 157, 0, - 158, 159, 160, 161, 796, 0, 1279, 0, 1280, 165, - 166, 167, 168, 169, 1281, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 1282, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 1076, 192, 193, - 1077, 195, 1078, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 1079, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 1080, 223, 224, - 225, 226, 227, 228, 798, 1081, 230, 0, 231, 232, - 1082, 234, 0, 235, 0, 236, 1284, 0, 1285, 239, - 240, 1286, 1287, 243, 244, 245, 0, 1083, 1084, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 1288, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 1289, 271, 272, 273, 274, 275, - 276, 1085, 1086, 0, 1087, 0, 280, 1290, 1291, 283, - 1292, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 1293, 293, 1294, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 1295, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 1089, 1296, 1090, 327, 328, 329, 330, - 1091, 331, 332, 1297, 334, 1092, 800, 336, 1093, 338, - 339, 340, 0, 341, 342, 0, 0, 1094, 344, 345, - 0, 0, 346, 347, 348, 1298, 350, 1299, 802, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 803, 1300, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 1095, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 1301, 407, 408, 409, 1096, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 1302, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 1303, 434, 435, 1097, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 1304, - 452, 805, 0, 0, 454, 455, 0, 456, 1305, 458, - 459, 460, 461, 462, 0, 463, 1098, 1099, 0, 0, - 466, 467, 806, 469, 807, 1100, 471, 472, 1306, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 1307, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 1102, 493, 0, 494, 1309, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 1266, 0, 1062, 0, + 0, 1267, 130, 131, 0, 132, 133, 134, 1268, 136, + 137, 138, 139, 1063, 1269, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 1270, 0, 1271, 164, 165, 166, 167, 168, 1272, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 1273, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 1275, 0, 1276, 238, 239, 1277, 1278, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 1279, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 1280, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 1281, 1282, 281, 1283, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 1284, 291, 1285, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1286, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 1287, 1084, + 325, 326, 327, 328, 1085, 329, 330, 1288, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 1289, + 348, 1290, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 1291, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 1292, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 1293, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 1294, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 1295, 448, 800, 0, 0, 450, 451, 0, 452, + 1296, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 1297, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 2334, 490, 1299, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 1264, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 1266, 0, 1062, 0, 0, 1267, 130, 131, 0, + 132, 133, 134, 1268, 136, 137, 138, 139, 1063, 1269, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 1270, 0, 1271, 164, 165, + 166, 167, 168, 1272, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 1273, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 1275, 0, 1276, 238, 239, + 1277, 1278, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 1279, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 1280, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 1281, 1282, 281, 1283, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 1284, + 291, 1285, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1286, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 1287, 1084, 325, 326, 327, 328, 1085, + 329, 330, 1288, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 1289, 348, 1290, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 1291, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 1292, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 1293, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 1294, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 1295, 448, 800, 0, + 0, 450, 451, 0, 452, 1296, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 1297, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 1299, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 1103, 0, 0, 0, 0, 0, 0, 1104, 1105, 1106, - 0, 0, 0, 0, 1107, 0, 1108, 2423, 0, 0, - 0, 0, 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, - 1064, 1065, 1066, 1067, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, -1168, 127, 128, 129, 0, 0, 0, - 0, -1168, 1068, 0, 0, 130, 131, 132, 0, 133, - 134, 135, 136, 137, 138, 139, 140, 1069, 142, 1070, - 1071, 0, 145, 146, 147, 148, 149, 150, 1072, 795, - 151, 152, 153, 154, 1073, 1074, 157, 0, 158, 159, - 160, 161, 796, 0, 797, 0, 1075, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 1076, 192, 193, 1077, 195, - 1078, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 1079, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 1080, 223, 224, 225, 226, - 227, 228, 798, 1081, 230, 0, 231, 232, 1082, 234, - 0, 235, 0, 236, 237, 0, 238, 239, 240, 241, - 242, 243, 244, 245, 0, 1083, 1084, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 270, 271, 272, 273, 274, 275, 276, 1085, - 1086, 0, 1087, 0, 280, 281, 282, 283, 284, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 292, 293, - 294, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 1088, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 1089, 325, 1090, 327, 328, 329, 330, 1091, 331, - 332, 333, 334, 1092, 800, 336, 1093, 338, 339, 340, - 0, 341, 342, 0, 0, 1094, 344, 345, 0, 0, - 346, 347, 348, 349, 350, 351, 802, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 803, 368, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 1095, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 406, 407, - 408, 409, 1096, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 433, 434, - 435, 1097, 437, -1168, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 451, 452, 805, - 0, 0, 454, 455, 0, 456, 457, 458, 459, 460, - 461, 462, 0, 463, 1098, 1099, 0, 0, 466, 467, - 806, 469, 807, 1100, 471, 472, 808, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 1101, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 1102, 493, 0, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 1103, 0, - 0, 0, 0, 0, 0, 1104, 1105, 1106, 0, 0, - 0, 0, 1107, 0, 1108, 0, 0, 0, 0, 0, - 1109, 1110, 1111, 1112, 1272, 1062, 826, 1063, 1064, 1065, - 1066, 1067, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 1274, 0, - 1068, 0, 0, 1275, 131, 132, 0, 1276, 134, 135, - 1277, 137, 138, 139, 140, 1069, 1278, 1070, 1071, 0, - 145, 146, 147, 148, 149, 150, 1072, 795, 151, 152, - 153, 154, 1073, 1074, 157, 0, 158, 159, 160, 161, - 796, 0, 1279, 0, 1280, 165, 166, 167, 168, 169, - 1281, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 1282, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 1076, 192, 193, 1077, 195, 1078, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 1079, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 1080, 223, 224, 225, 226, 227, 228, - 798, 1081, 230, 0, 231, 232, 1082, 234, 0, 235, - 0, 236, 1284, 0, 1285, 239, 240, 1286, 1287, 243, - 244, 245, 0, 1083, 1084, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 1288, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 1289, 271, 272, 273, 274, 275, 276, 1085, 1086, 0, - 1087, 0, 280, 1290, 1291, 283, 1292, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 1293, 293, 1294, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 1295, 304, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 2389, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, -1139, + 126, 127, 128, 0, 0, 0, 0, -1139, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 1089, - 1296, 1090, 327, 328, 329, 330, 1091, 331, 332, 1297, - 334, 1092, 800, 336, 1093, 338, 339, 340, 0, 341, - 342, 0, 0, 1094, 344, 345, 0, 0, 346, 347, - 348, 1298, 350, 1299, 802, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 803, 1300, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 1095, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 1301, 407, 408, 409, - 1096, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 1302, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 1303, 434, 435, 1097, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 1304, 452, 805, 0, 0, - 454, 455, 0, 456, 1305, 458, 459, 460, 461, 462, - 0, 463, 1098, 1099, 0, 0, 466, 467, 806, 469, - 807, 1100, 471, 472, 1306, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 1307, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 1102, 493, - 0, 494, 1309, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 1103, 0, 0, 0, - 0, 0, 0, 1104, 1105, 1106, 0, 0, 0, 0, - 1107, 0, 1108, 3224, 0, 0, 0, 0, 1109, 1110, - 1111, 1112, 1272, 1062, 826, 1063, 1064, 1065, 1066, 1067, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, -1139, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 1264, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 1266, 0, 1062, 0, 0, 1267, 130, 131, 0, + 132, 133, 134, 1268, 136, 137, 138, 139, 1063, 1269, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 1270, 0, 1271, 164, 165, + 166, 167, 168, 1272, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 1273, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 1275, 0, 1276, 238, 239, + 1277, 1278, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 1279, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 1280, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 1281, 1282, 281, 1283, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 1284, + 291, 1285, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1286, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 1287, 1084, 325, 326, 327, 328, 1085, + 329, 330, 1288, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 1289, 348, 1290, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 1291, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 1292, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 1293, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 1294, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 1295, 448, 800, 0, + 0, 450, 451, 0, 452, 1296, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 1297, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 1299, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 3159, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 1264, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 1274, 0, 1068, 0, - 0, 1275, 131, 132, 0, 1276, 134, 135, 1277, 137, - 138, 139, 140, 1069, 1278, 1070, 1071, 0, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 0, 158, 159, 160, 161, 796, 0, - 1279, 0, 1280, 165, 166, 167, 168, 169, 1281, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 1282, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 1078, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 1284, 0, 1285, 239, 240, 1286, 1287, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 1288, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 1289, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 1290, 1291, 283, 1292, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 1293, 293, 1294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1295, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 1296, 1090, - 327, 328, 329, 330, 1091, 331, 332, 1297, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 1094, 344, 345, 0, 0, 346, 347, 348, 1298, - 350, 1299, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 803, 1300, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 1301, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 1302, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 1303, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 1304, 452, 805, 0, 0, 454, 455, - 0, 456, 1305, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 0, 466, 467, 806, 469, 807, 1100, - 471, 472, 1306, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 1307, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 1102, 493, 0, 494, - 1309, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 1103, 0, 0, 0, 0, 0, - 0, 1104, 1105, 1106, 0, 0, 0, 0, 1107, 0, - 1108, 0, 0, 0, 0, 0, 1109, 1110, 1111, 1112, - 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 1732, 127, 128, - 129, 0, 0, 0, 0, 0, 1068, 0, 0, 130, - 131, 132, 0, 133, 134, 135, 136, 137, 138, 139, - 140, 1069, 142, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 797, 0, - 1075, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 1078, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 237, 0, - 238, 239, 240, 241, 242, 243, 244, 245, 0, 1083, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 270, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 292, 293, 294, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1088, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 325, 1090, 327, 328, - 329, 330, 1091, 331, 332, 333, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 1094, - 344, 345, 0, 0, 346, 347, 348, 349, 350, 351, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 803, - 368, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 406, 407, 408, 409, 1096, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 433, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 805, 0, 0, 454, 455, 0, 456, - 457, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 808, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 1101, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 1102, 493, 0, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 1103, 0, 0, 0, 0, 0, 0, 1104, - 1105, 1106, 0, 0, 0, 0, 1107, 0, 1108, 0, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 118, 1747, - 826, 1063, 1064, 1065, 1748, 1067, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 1749, 127, 128, 129, 0, - 0, 0, 0, 0, 1068, 0, 0, 130, 131, 132, - 0, 133, 134, 135, 136, 137, 138, 139, 140, 1069, - 142, 1070, 1071, 0, 145, 146, 147, 148, 149, 150, - 1072, 795, 151, 152, 153, 154, 1073, 1074, 157, 0, - 158, 159, 160, 161, 796, 0, 797, 0, 1075, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 1076, 192, 193, - 1077, 195, 1078, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 1079, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 1080, 223, 224, - 225, 226, 227, 228, 798, 1081, 230, 0, 231, 232, - 1082, 234, 0, 235, 0, 236, 237, 0, 238, 239, - 240, 241, 242, 243, 244, 245, 0, 1083, 1084, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 270, 271, 272, 273, 274, 275, - 276, 1085, 1086, 0, 1087, 0, 280, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 292, 293, 294, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 1088, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 1089, 325, 1090, 327, 328, 329, 330, - 1091, 331, 332, 333, 334, 1092, 800, 336, 1093, 338, - 339, 340, 0, 341, 342, 0, 0, 1094, 344, 345, - 0, 0, 346, 347, 348, 349, 350, 351, 802, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 803, 368, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 1095, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 406, 407, 408, 409, 1096, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 433, 434, 435, 1097, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 805, 0, 0, 454, 455, 0, 456, 457, 458, - 459, 460, 461, 462, 0, 463, 1098, 1099, 0, 0, - 466, 467, 806, 469, 807, 1100, 471, 472, 808, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 1101, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 1102, 493, 0, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 1266, 0, 1062, 0, + 0, 1267, 130, 131, 0, 132, 133, 134, 1268, 136, + 137, 138, 139, 1063, 1269, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 1270, 0, 1271, 164, 165, 166, 167, 168, 1272, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 1273, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 1275, 0, 1276, 238, 239, 1277, 1278, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 1279, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 1280, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 1281, 1282, 281, 1283, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 1284, 291, 1285, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1286, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 1287, 1084, + 325, 326, 327, 328, 1085, 329, 330, 1288, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 1289, + 348, 1290, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 1291, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 1292, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 1293, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 1294, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 1295, 448, 800, 0, 0, 450, 451, 0, 452, + 1296, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 1297, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 1299, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 1717, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 1103, 0, 0, 0, 0, 0, 0, 1104, 1105, 1106, - 0, 0, 0, 0, 1107, 0, 1108, 0, 0, 0, - 0, 0, 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, - 1064, 1065, 1066, 1067, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 1068, 0, 0, 130, 131, 132, 0, 133, - 134, 135, 136, 137, 138, 139, 140, 1069, 142, 1070, - 1071, 0, 145, 146, 147, 148, 149, 150, 1072, 795, - 151, 152, 153, 154, 1073, 1074, 157, 0, 158, 159, - 160, 161, 796, 0, 797, 0, 1075, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 1076, 192, 193, 1077, 195, - 1078, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 1079, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 1080, 223, 224, 225, 226, - 227, 228, 798, 1081, 230, 0, 231, 232, 1082, 234, - 0, 235, 0, 236, 237, 1459, 238, 239, 240, 241, - 242, 243, 244, 245, 0, 1083, 1084, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 270, 271, 272, 273, 274, 275, 276, 1085, - 1086, 0, 1087, 0, 280, 281, 282, 283, 284, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 292, 293, - 294, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 1088, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 1089, 325, 1090, 327, 328, 329, 330, 1091, 331, - 332, 333, 334, 1092, 800, 336, 1093, 338, 339, 340, - 0, 341, 342, 0, 0, 1094, 344, 345, 0, 0, - 346, 347, 348, 349, 350, 351, 802, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 803, 368, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 1095, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 406, 407, - 408, 409, 1096, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 433, 434, - 435, 1097, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 451, 452, 805, - 0, 0, 454, 455, 0, 456, 457, 458, 459, 460, - 461, 462, 0, 463, 1098, 1099, 0, 0, 466, 467, - 806, 469, 807, 1100, 471, 472, 808, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 1101, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 1102, 493, 0, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 1103, 0, - 0, 0, 0, 0, 0, 1104, 1105, 1106, 0, 0, - 0, 0, 1107, 0, 1108, 0, 0, 0, 0, 0, - 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, - 1066, 1067, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 1068, 0, 0, 130, 131, 132, 0, 133, 134, 135, - 136, 137, 138, 139, 140, 1069, 142, 1070, 1071, 0, - 145, 146, 147, 148, 149, 150, 1072, 795, 151, 152, - 153, 154, 1073, 1074, 157, 0, 158, 159, 160, 161, - 796, 0, 797, 0, 1075, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 180, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 1076, 192, 193, 1077, 195, 1078, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 1079, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 1080, 223, 224, 225, 226, 227, 228, - 798, 1081, 230, 0, 231, 232, 1082, 234, 0, 235, - 0, 236, 237, 0, 238, 239, 240, 241, 242, 243, - 244, 245, 0, 1083, 1084, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 270, 271, 272, 273, 274, 275, 276, 1085, 1086, 0, - 1087, 0, 280, 281, 282, 283, 284, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 292, 293, 294, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 1088, 304, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1732, 821, 1057, 1058, 1059, 1733, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 1734, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 1089, - 325, 1090, 327, 328, 329, 330, 1091, 331, 332, 333, - 334, 1092, 800, 336, 1093, 338, 339, 340, 0, 341, - 342, 0, 0, 1094, 344, 345, 0, 0, 346, 347, - 348, 349, 350, 351, 802, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 803, 368, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 1095, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 406, 407, 408, 409, - 1096, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 433, 434, 435, 1097, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 451, 452, 805, 0, 0, - 454, 455, 0, 456, 457, 458, 459, 460, 461, 462, - 0, 463, 1098, 1099, 0, 0, 466, 467, 806, 469, - 807, 1100, 471, 472, 808, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 1101, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 1102, 493, - 0, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 1103, 0, 0, 0, - 0, 0, 0, 1104, 1105, 1106, 0, 0, 0, 0, - 1107, 0, 1108, 2120, 0, 0, 0, 0, 1109, 1110, - 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 1449, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 1068, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 1069, 142, 1070, 1071, 0, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 0, 158, 159, 160, 161, 796, 0, - 797, 0, 1075, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 1078, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 237, 0, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 292, 293, 294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1088, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 325, 1090, - 327, 328, 329, 330, 1091, 331, 332, 333, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 1094, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 433, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 0, 0, 454, 455, - 0, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 0, 466, 467, 806, 469, 807, 1100, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 1101, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 1102, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 1103, 0, 0, 0, 0, 0, - 0, 1104, 1105, 1106, 0, 0, 0, 0, 1107, 0, - 1108, 0, 0, 0, 0, 2741, 1109, 1110, 1111, 1112, - 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 1068, 0, 0, 130, - 131, 132, 0, 133, 134, 135, 136, 137, 138, 139, - 140, 1069, 142, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 797, 0, - 1075, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 1078, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 237, 0, - 238, 239, 240, 241, 242, 243, 244, 245, 0, 1083, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 270, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 292, 293, 294, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1088, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 325, 1090, 327, 328, - 329, 330, 1091, 331, 332, 333, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 1094, - 344, 345, 0, 0, 346, 347, 348, 349, 350, 351, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 803, - 368, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 406, 407, 408, 409, 1096, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 433, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 805, 0, 0, 454, 455, 2802, 456, - 457, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 808, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 1101, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 1102, 493, 0, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 1103, 0, 0, 0, 0, 0, 0, 1104, - 1105, 1106, 0, 0, 0, 0, 1107, 0, 1108, 0, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 118, 1062, - 826, 1063, 1064, 1065, 1066, 1067, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 1068, 0, 0, 130, 131, 132, - 0, 133, 134, 135, 136, 137, 138, 139, 140, 1069, - 142, 1070, 1071, 0, 145, 146, 147, 148, 149, 150, - 1072, 795, 151, 152, 153, 154, 1073, 1074, 157, 0, - 158, 159, 160, 161, 796, 0, 797, 0, 1075, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 1076, 192, 193, - 1077, 195, 1078, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 1079, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 1080, 223, 224, - 225, 226, 227, 228, 798, 1081, 230, 0, 231, 232, - 1082, 234, 0, 235, 0, 236, 237, 0, 238, 239, - 240, 241, 242, 243, 244, 245, 0, 1083, 1084, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 270, 271, 272, 273, 274, 275, - 276, 1085, 1086, 0, 1087, 0, 280, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 292, 293, 294, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 1088, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 1089, 325, 1090, 327, 328, 329, 330, - 1091, 331, 332, 333, 334, 1092, 800, 336, 1093, 338, - 339, 340, 0, 341, 342, 0, 0, 1094, 344, 345, - 0, 0, 346, 347, 348, 349, 350, 351, 802, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 803, 368, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 1095, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 406, 407, 408, 409, 1096, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 433, 434, 435, 1097, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 805, 0, 0, 454, 455, 0, 456, 457, 458, - 459, 460, 461, 462, 0, 463, 1098, 1099, 0, 0, - 466, 467, 806, 469, 807, 1100, 471, 472, 808, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 1101, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 1102, 493, 0, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 0, 2930, 503, 0, 0, 504, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 2096, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 1103, 0, 0, 0, 0, 0, 0, 1104, 1105, 1106, - 0, 0, 0, 0, 1107, 0, 1108, 0, 0, 0, - 0, 0, 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, - 1064, 1065, 1066, 1067, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 3160, 127, 128, 129, 0, 0, 0, - 0, 0, 1068, 0, 0, 130, 131, 132, 0, 133, - 134, 135, 136, 137, 138, 139, 140, 1069, 142, 1070, - 1071, 0, 145, 146, 147, 148, 149, 150, 1072, 795, - 151, 152, 153, 154, 1073, 1074, 157, 0, 158, 159, - 160, 161, 796, 0, 797, 0, 1075, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 180, 181, 3161, 183, 184, 185, - 186, 187, 188, 189, 190, 1076, 192, 193, 1077, 195, - 1078, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 1079, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 1080, 223, 224, 225, 226, - 227, 228, 798, 1081, 230, 0, 231, 232, 1082, 234, - 0, 235, 0, 236, 237, 0, 238, 239, 240, 241, - 242, 243, 244, 245, 0, 3162, 1084, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 270, 271, 272, 273, 274, 275, 276, 1085, - 1086, 0, 1087, 0, 280, 281, 282, 283, 284, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 292, 293, - 294, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 1088, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 1089, 325, 1090, 327, 328, 329, 330, 1091, 331, - 332, 333, 334, 1092, 800, 336, 1093, 338, 339, 340, - 0, 341, 342, 0, 0, 1094, 344, 345, 0, 0, - 346, 347, 348, 349, 350, 351, 802, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 803, 368, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 1095, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 406, 407, - 408, 3163, 1096, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 433, 434, - 435, 1097, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 451, 452, 805, - 0, 0, 454, 455, 0, 456, 457, 458, 459, 460, - 461, 462, 0, 463, 1098, 1099, 0, 0, 466, 467, - 806, 469, 807, 1100, 471, 472, 808, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 1101, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 1102, 493, 0, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 1103, 0, - 0, 0, 0, 0, 0, 1104, 1105, 1106, 0, 0, - 0, 0, 1107, 0, 3164, 0, 0, 0, 0, 0, - 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, - 1066, 1067, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 1068, 0, 0, 130, 131, 132, 0, 133, 134, 135, - 136, 137, 138, 139, 140, 1069, 142, 1070, 1071, 0, - 145, 146, 147, 148, 149, 150, 1072, 795, 151, 152, - 153, 154, 1073, 1074, 157, 0, 158, 159, 160, 161, - 796, 0, 797, 0, 1075, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 180, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 1076, 192, 193, 1077, 195, 1078, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 1079, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 1080, 223, 224, 225, 226, 227, 228, - 798, 1081, 230, 0, 231, 232, 1082, 234, 0, 235, - 0, 236, 237, 0, 238, 239, 240, 241, 242, 243, - 244, 245, 0, 1083, 1084, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 270, 271, 272, 273, 274, 275, 276, 1085, 1086, 0, - 1087, 0, 280, 281, 282, 283, 284, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 292, 293, 294, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 1088, 304, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 2695, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 1089, - 325, 1090, 327, 328, 329, 330, 1091, 331, 332, 333, - 334, 1092, 800, 336, 1093, 338, 339, 340, 0, 341, - 342, 0, 0, 1094, 344, 345, 0, 0, 346, 347, - 348, 349, 350, 351, 802, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 803, 368, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 1095, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 406, 407, 408, 409, - 1096, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 433, 434, 435, 1097, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 451, 452, 805, 0, 0, - 454, 455, 0, 456, 457, 458, 459, 460, 461, 462, - 0, 463, 1098, 1099, 0, 0, 466, 467, 806, 469, - 807, 1100, 471, 472, 808, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 1101, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 1102, 493, - 0, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 1103, 0, 0, 0, - 0, 0, 0, 1104, 1105, 1106, 0, 0, 0, 0, - 1107, 0, 1108, 0, 0, 0, 0, 3391, 1109, 1110, - 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 2752, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 2878, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 1068, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 1069, 142, 1070, 1071, 0, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 0, 158, 159, 160, 161, 796, 0, - 797, 0, 1075, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 1078, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 237, 0, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 292, 293, 294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1088, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 325, 1090, - 327, 328, 329, 330, 1091, 331, 332, 333, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 1094, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 433, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 0, 0, 454, 455, - 0, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 0, 466, 467, 806, 469, 807, 1100, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 1101, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 1102, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 1103, 0, 0, 0, 0, 0, - 0, 1104, 1105, 1106, 0, 0, 0, 0, 1107, 0, - 1108, 0, 0, 0, 0, 0, 1109, 1110, 1111, 1112, - 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 1068, 0, 0, 130, - 131, 132, 0, 133, 134, 135, 136, 137, 138, 139, - 140, 1069, 142, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 797, 0, - 1075, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 1078, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 237, 0, - 238, 239, 240, 241, 242, 243, 244, 245, 0, 1083, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 270, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 292, 293, 294, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1088, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 325, 1090, 327, 328, - 329, 330, 1091, 331, 332, 333, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 1094, - 344, 345, 0, 0, 346, 347, 348, 349, 350, 351, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 803, - 368, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 406, 407, 408, 409, 1096, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 433, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 805, 0, 0, 454, 455, 0, 456, - 457, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 808, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 1101, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 1102, 493, 0, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 1103, 0, 0, 0, 0, 0, 0, 1752, - 1753, 1106, 0, 0, 0, 0, 1107, 0, 1108, 0, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 118, 2262, - 826, 1063, 1064, 1065, 1066, 1067, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 1068, 0, 0, 130, 131, 132, - 0, 133, 134, 135, 136, 137, 138, 139, 140, 1069, - 142, 1070, 1071, 0, 145, 146, 147, 148, 149, 150, - 1072, 795, 151, 152, 153, 154, 1073, 1074, 157, 0, - 158, 159, 160, 161, 796, 0, 797, 0, 1075, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 1076, 192, 193, - 1077, 195, 1078, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 1079, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 1080, 223, 224, - 225, 226, 227, 228, 798, 1081, 230, 0, 231, 232, - 1082, 234, 0, 235, 0, 236, 237, 0, 238, 239, - 240, 241, 242, 243, 244, 245, 0, 1083, 1084, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 270, 271, 272, 273, 274, 275, - 276, 1085, 1086, 0, 1087, 0, 280, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 292, 293, 294, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 1088, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 1089, 325, 1090, 327, 328, 329, 330, - 1091, 331, 332, 333, 334, 1092, 800, 336, 1093, 338, - 339, 340, 0, 341, 342, 0, 0, 1094, 344, 345, - 0, 0, 346, 347, 348, 349, 350, 351, 802, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 803, 368, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 1095, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 406, 407, 408, 409, 1096, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 433, 434, 435, 1097, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 805, 0, 0, 454, 455, 0, 456, 457, 458, - 459, 460, 461, 462, 0, 463, 1098, 1099, 0, 0, - 466, 467, 806, 469, 807, 1100, 471, 472, 808, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 1101, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 1102, 493, 0, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 3096, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 3097, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 3098, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 3099, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 3100, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 1103, 0, 0, 0, 0, 0, 0, 1104, 1105, 1106, - 0, 0, 0, 0, 1107, 0, 1108, 0, 0, 0, - 0, 0, 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, - 1064, 1065, 1066, 1067, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 1068, 0, 0, 130, 131, 132, 0, 133, - 134, 135, 136, 137, 138, 139, 140, 1069, 142, 1070, - 1071, 0, 145, 146, 147, 148, 149, 150, 1072, 795, - 151, 152, 153, 154, 1073, 1074, 157, 0, 158, 159, - 160, 161, 796, 0, 797, 0, 1075, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 1076, 192, 193, 1077, 195, - 1078, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 1079, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 1080, 223, 224, 225, 226, - 227, 228, 798, 1081, 230, 0, 231, 232, 1082, 234, - 0, 235, 0, 236, 237, 0, 238, 239, 240, 241, - 242, 243, 244, 245, 0, 1083, 1084, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 270, 271, 272, 273, 274, 275, 276, 1085, - 1086, 0, 1087, 0, 280, 281, 282, 283, 284, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 292, 293, - 294, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 1088, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 1089, 325, 1090, 327, 328, 329, 330, 1091, 331, - 332, 333, 334, 1092, 800, 336, 1093, 338, 339, 340, - 0, 341, 342, 0, 0, 1094, 344, 345, 0, 0, - 346, 347, 348, 349, 350, 351, 802, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 803, 368, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 1095, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 406, 407, - 408, 409, 1096, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 433, 434, - 435, 1097, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 451, 452, 805, - 0, 0, 454, 455, 0, 456, 457, 458, 459, 460, - 461, 462, 0, 463, 1098, 1099, 0, 0, 466, 467, - 806, 469, 807, 1100, 471, 472, 808, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 1101, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 1102, 493, 0, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 1103, 0, - 0, 0, 0, 0, 0, 1104, 2359, 1106, 0, 0, - 0, 0, 1107, 0, 1108, 0, 0, 0, 0, 0, - 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, - 1066, 1067, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 1068, 0, 0, 130, 131, 132, 0, 133, 134, 135, - 136, 137, 138, 139, 140, 1069, 142, 1070, 1071, 0, - 145, 146, 147, 148, 149, 150, 1072, 795, 151, 152, - 153, 154, 1073, 1074, 157, 0, 158, 159, 160, 161, - 796, 0, 797, 0, 1075, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 180, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 1076, 192, 193, 1077, 195, 1078, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 1079, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 1080, 223, 224, 225, 226, 227, 228, - 798, 1081, 230, 0, 231, 232, 1082, 234, 0, 235, - 0, 236, 237, 0, 238, 239, 240, 241, 242, 243, - 244, 245, 0, 1083, 1084, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 270, 271, 272, 273, 274, 275, 276, 1085, 1086, 0, - 1087, 0, 280, 281, 282, 283, 284, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 292, 293, 294, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 1088, 304, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 3321, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 1089, - 325, 1090, 327, 328, 329, 330, 1091, 331, 332, 333, - 334, 1092, 800, 336, 1093, 338, 339, 340, 0, 341, - 342, 0, 0, 1094, 344, 345, 0, 0, 346, 347, - 348, 349, 350, 351, 802, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 803, 368, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 1095, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 406, 407, 408, 409, - 1096, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 433, 434, 435, 1097, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 451, 452, 805, 0, 0, - 454, 455, 0, 456, 457, 458, 459, 460, 461, 462, - 0, 463, 1098, 1099, 0, 0, 466, 467, 806, 469, - 807, 1100, 471, 472, 808, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 1101, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 1102, 493, - 0, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 1103, 0, 0, 0, - 0, 0, 0, 1104, 1105, 1106, 0, 0, 0, 0, - 1107, 0, 2586, 0, 0, 0, 0, 0, 1109, 1110, - 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1737, 1738, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 2238, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 1068, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 1069, 142, 1070, 1071, 0, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 0, 158, 159, 160, 161, 796, 0, - 797, 0, 1075, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 1078, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 237, 0, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 292, 293, 294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1088, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 325, 1090, - 327, 328, 329, 330, 1091, 331, 332, 333, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 1094, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 433, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 0, 0, 454, 455, - 0, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 0, 466, 467, 806, 469, 807, 1100, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 1101, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 1102, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 1103, 0, 0, 0, 0, 0, - 0, 1104, 3222, 1106, 0, 0, 0, 0, 1107, 0, - 1108, 0, 0, 0, 0, 0, 1109, 1110, 1111, 1112, - 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 1068, 0, 0, 130, - 131, 132, 0, 133, 134, 135, 136, 137, 138, 139, - 140, 1069, 142, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 797, 0, - 1075, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 180, 181, - 3161, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 1078, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 237, 0, - 238, 239, 240, 241, 242, 243, 244, 245, 0, 3162, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 270, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 292, 293, 294, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1088, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 325, 1090, 327, 328, - 329, 330, 1091, 331, 332, 333, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 1094, - 344, 345, 0, 0, 346, 347, 348, 349, 350, 351, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 803, - 368, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 406, 407, 408, 3163, 1096, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 433, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 805, 0, 0, 454, 455, 0, 456, - 457, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 808, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 1101, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 1102, 493, 0, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 1103, 0, 0, 0, 0, 0, 0, 1104, - 1105, 1106, 0, 0, 0, 0, 1107, 0, 3164, 0, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 118, 1062, - 826, 1063, 1064, 1065, 1066, 1067, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 1068, 0, 0, 130, 131, 132, - 0, 133, 134, 135, 136, 137, 138, 139, 3637, 1069, - 142, 1070, 1071, 0, 145, 146, 147, 148, 149, 150, - 1072, 795, 151, 152, 153, 154, 1073, 1074, 157, 0, - 158, 159, 160, 161, 796, 0, 797, 0, 1075, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 180, 181, 182, 3638, - 184, 185, 186, 187, 188, 189, 190, 1076, 192, 193, - 1077, 195, 1078, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 1079, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 1080, 223, 224, - 225, 226, 227, 228, 798, 1081, 230, 0, 231, 232, - 1082, 234, 0, 235, 0, 236, 237, 0, 238, 239, - 240, 241, 242, 243, 244, 245, 0, 1083, 1084, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 270, 271, 272, 273, 274, 275, - 276, 1085, 1086, 0, 1087, 0, 280, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 292, 293, 294, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 1088, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 1089, 325, 1090, 327, 328, 329, 330, - 1091, 331, 332, 333, 334, 1092, 800, 336, 1093, 338, - 339, 340, 0, 341, 342, 0, 0, 1094, 344, 345, - 0, 0, 346, 347, 348, 349, 350, 351, 802, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 803, 368, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 1095, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 406, 407, 408, 409, 1096, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 433, 434, 435, 1097, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 805, 0, 0, 454, 455, 0, 456, 457, 458, - 459, 460, 461, 462, 0, 463, 1098, 1099, 0, 0, - 466, 467, 806, 469, 807, 1100, 471, 472, 808, 474, - 475, 3639, 477, 478, 0, 0, 479, 480, 481, 1101, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 1102, 493, 0, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 1103, 0, 0, 0, 0, 0, 0, 1104, 1105, 1106, - 0, 0, 0, 0, 1107, 0, 1108, 0, 0, 0, - 0, 0, 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, - 1064, 1065, 1066, 1067, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 1068, 0, 0, 130, 131, 132, 0, 133, - 134, 135, 136, 137, 138, 139, 140, 1069, 142, 1070, - 1071, 0, 145, 146, 147, 148, 149, 150, 1072, 795, - 151, 152, 153, 154, 1073, 1074, 157, 0, 158, 159, - 160, 161, 796, 0, 797, 0, 1075, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 180, 181, 182, 3638, 184, 185, - 186, 187, 188, 189, 190, 1076, 192, 193, 1077, 195, - 1078, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 1079, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 1080, 223, 224, 225, 226, - 227, 228, 798, 1081, 230, 0, 231, 232, 1082, 234, - 0, 235, 0, 236, 237, 0, 238, 239, 240, 241, - 242, 243, 244, 245, 0, 1083, 1084, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 270, 271, 272, 273, 274, 275, 276, 1085, - 1086, 0, 1087, 0, 280, 281, 282, 283, 284, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 292, 293, - 294, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 1088, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 1089, 325, 1090, 327, 328, 329, 330, 1091, 331, - 332, 333, 334, 1092, 800, 336, 1093, 338, 339, 340, - 0, 341, 342, 0, 0, 1094, 344, 345, 0, 0, - 346, 347, 348, 349, 350, 351, 802, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 803, 368, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 1095, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 406, 407, - 408, 409, 1096, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 433, 434, - 435, 1097, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 451, 452, 805, - 0, 0, 454, 455, 0, 456, 457, 458, 459, 460, - 461, 462, 0, 463, 1098, 1099, 0, 0, 466, 467, - 806, 469, 807, 1100, 471, 472, 808, 474, 475, 3639, - 477, 478, 0, 0, 479, 480, 481, 1101, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 1102, 493, 0, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 1103, 0, - 0, 0, 0, 0, 0, 1104, 1105, 1106, 0, 0, - 0, 0, 1107, 0, 1108, 0, 0, 0, 0, 0, - 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, - 1066, 1067, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 1068, 0, 0, 130, 131, 132, 0, 133, 134, 135, - 136, 137, 138, 139, -2141, 1069, 142, 1070, 1071, 0, - 145, 146, 147, 148, 149, 150, 1072, 795, 151, 152, - 153, 154, 1073, 1074, 157, 0, 158, 159, 160, 161, - 796, 0, 797, 0, 1075, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 180, 181, 182, 3638, 184, 185, 186, 187, - 188, 189, 190, 1076, 192, 193, 1077, 195, 1078, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 1079, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 1080, 223, 224, 225, 226, 227, 228, - 798, 1081, 230, 0, 231, 232, 1082, 234, 0, 235, - 0, 236, 237, 0, 238, 239, 240, 241, -2141, 243, - 244, 245, 0, 1083, 1084, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, -2141, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 270, 271, 272, 273, 274, 275, 276, 1085, 1086, 0, - 1087, 0, 280, 0, 0, 283, 284, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 292, 293, -2141, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 1088, 304, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 2325, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 1089, - 325, 1090, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 1092, 800, 336, 1093, 338, 339, 340, 0, 341, - 342, 0, 0, 1094, 344, 345, 0, 0, 346, 347, - 348, 349, 350, 351, 802, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 803, 368, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 1095, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 406, 407, 408, 409, - 1096, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, -2141, 434, 435, 1097, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 451, 452, 805, 0, 0, - 454, 455, 0, 456, 457, 458, 459, 460, 461, 462, - 0, 463, 1098, 1099, 0, 0, 466, 467, 806, 469, - 807, 1100, 471, 472, 808, 474, 475, 3639, 477, 478, - 0, 0, 479, 480, 481, 1101, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 1102, 493, - 0, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, -2141, 0, 0, 0, - 0, 0, 0, 1104, 1105, 1106, 0, 0, 0, 0, - 1107, 0, 1108, 0, 0, 0, 0, 0, 1109, 1110, - 1111, 1112, 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 2547, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 3157, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 1068, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 1069, 142, 1070, 1071, 0, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 0, 158, 159, 160, 161, 796, 0, - 797, 0, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 237, 0, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 292, 293, 294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1088, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 325, 1090, - 327, 328, 329, 330, 0, 331, 332, 333, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 1094, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 433, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 0, 0, 454, 455, - 0, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 0, 466, 467, 806, 469, 807, 1100, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 1102, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 0, 0, 0, 0, 0, 0, - 0, 1445, 1446, 0, 0, 0, 0, 0, 1107, 0, - 1108, 0, 0, 0, 0, 0, 1109, 1110, 1111, 1112, - 118, 1062, 826, 1063, 1064, 0, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 1068, 0, 0, 130, - 131, 132, 0, 133, 134, 135, 136, 137, 138, 139, - 140, 1069, 142, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 797, 0, - 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 237, 0, - 238, 239, 240, 241, 242, 243, 244, 245, 0, 1083, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 270, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 292, 293, 294, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1088, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 325, 1090, 327, 328, - 329, 330, 0, 331, 332, 333, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 349, 350, 351, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 803, - 368, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 406, 407, 408, 409, 2248, 2249, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 433, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 805, 0, 0, 454, 455, 0, 456, - 457, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 808, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 1102, 493, 0, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 0, 0, 0, 0, 0, 0, 0, 2250, - 2251, 0, 0, 0, 0, 0, 1107, 0, 1108, 0, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 118, 1062, - 826, 1063, 1064, 1065, 1066, 1067, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 1068, 0, 0, 130, 131, 132, - 0, 133, 134, 135, 136, 137, 138, 139, 140, 1069, - 142, 1070, 1071, 0, 145, 146, 147, 148, 149, 150, - 1072, 795, 151, 152, 153, 154, 1073, 1074, 157, 0, - 158, 159, 160, 161, 796, 0, 797, 0, 164, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 1076, 192, 193, - 1077, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 1079, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 1080, 223, 224, - 225, 226, 227, 228, 798, 1081, 230, 0, 231, 232, - 1082, 234, 0, 235, 0, 236, 237, 0, 238, 239, - 240, 241, 242, 243, 244, 245, 0, 1083, 1084, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 270, 271, 272, 273, 274, 275, - 276, 1085, 1086, 0, 1087, 0, 280, 0, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 292, 293, 294, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 1088, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 1089, 325, 1090, 327, 328, 329, 330, - 0, 331, 332, 333, 334, 1092, 800, 336, 1093, 338, - 339, 340, 0, 341, 342, 0, 0, 1094, 344, 345, - 0, 0, 346, 347, 348, 349, 350, 351, 802, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 803, 368, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 1095, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 406, 407, 408, 409, 1096, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 433, 434, 435, 1097, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 805, 0, 0, 454, 455, 0, 456, 457, 458, - 459, 460, 461, 462, 0, 463, 1098, 1099, 0, 0, - 466, 467, 806, 469, 807, 1100, 471, 472, 808, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 1102, 493, 0, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 3097, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 3098, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 3099, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 3100, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 3565, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 1069, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 3566, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 1072, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 1085, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 3567, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 0, 0, 0, 0, 0, 0, 0, 1445, 1446, 0, - 0, 0, 0, 0, 1107, 0, 1108, 0, 0, 0, - 0, 0, 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, - 1064, 0, 1066, 1067, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 1068, 0, 0, 130, 131, 132, 0, 133, - 134, 135, 136, 137, 138, 139, 140, 1069, 142, 1070, - 1071, 0, 145, 146, 147, 148, 149, 150, 1072, 795, - 151, 152, 153, 154, 1073, 1074, 157, 0, 158, 159, - 160, 161, 796, 0, 797, 0, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 1076, 192, 193, 1077, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 1079, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 1080, 223, 224, 225, 226, - 227, 228, 798, 1081, 230, 0, 231, 232, 1082, 234, - 0, 235, 0, 236, 237, 0, 238, 239, 240, 241, - 242, 243, 244, 245, 3182, 1083, 1084, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 270, 271, 272, 273, 274, 275, 276, 1085, - 1086, 0, 1087, 0, 280, 281, 282, 283, 284, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 292, 293, - 294, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 1088, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 1089, 325, 1090, 327, 328, 329, 330, 0, 331, - 332, 333, 334, 1092, 800, 336, 1093, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 349, 350, 351, 802, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 803, 368, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 1095, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 433, 434, - 435, 1097, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 451, 452, 805, - 0, 0, 454, 455, 0, 456, 457, 458, 459, 460, - 461, 462, 0, 463, 1098, 1099, 0, 0, 466, 467, - 806, 469, 807, 1100, 471, 472, 808, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 1102, 493, 0, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 0, 0, + 515, 516, 517, 518, 519, 520, 1096, 0, 0, 0, + 0, 0, 0, 1097, 1098, 1099, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1107, 0, 2852, 0, 0, 0, 0, 0, - 1109, 1110, 1111, 1112, 118, 1062, 826, 1063, 1064, 0, - 1066, 1067, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 1068, 0, 0, 130, 131, 132, 0, 133, 134, 135, - 136, 137, 138, 139, 140, 1069, 142, 1070, 1071, 0, - 145, 146, 147, 148, 149, 150, 1072, 795, 151, 152, - 153, 154, 1073, 1074, 157, 0, 158, 159, 160, 161, - 796, 0, 797, 0, 164, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 180, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 1076, 192, 193, 1077, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 1079, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 1080, 223, 224, 225, 226, 227, 228, - 798, 1081, 230, 0, 231, 232, 1082, 234, 0, 235, - 0, 236, 237, 0, 238, 239, 240, 241, 242, 243, - 244, 245, 0, 1083, 1084, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 270, 271, 272, 273, 274, 275, 276, 1085, 1086, 0, - 1087, 0, 280, 281, 282, 283, 284, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 292, 293, 294, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 1088, 304, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 3566, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 1089, - 325, 1090, 327, 328, 329, 330, 0, 331, 332, 333, - 334, 1092, 800, 336, 1093, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 349, 350, 351, 802, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 803, 368, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 1095, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 1085, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 406, 407, 408, 409, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 433, 434, 435, 1097, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 451, 452, 805, 0, 0, - 454, 455, 0, 456, 457, 458, 459, 460, 461, 462, - 0, 463, 1098, 1099, 0, 0, 466, 467, 806, 469, - 807, 1100, 471, 472, 808, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 1102, 493, - 0, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 0, 0, 0, 0, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 3567, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1096, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 0, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 1088, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 0, 0, 0, 0, + 0, 0, 0, 1435, 1436, 0, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1107, 0, 2852, 0, 0, 0, 0, 0, 1109, 1110, - 1111, 1112, 118, 1062, 826, 1063, 1064, 0, 1066, 1067, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, -2102, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 3566, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, -2102, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, -2102, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 0, 0, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, -2102, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, -2102, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 3567, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, -2102, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 0, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 0, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 2224, 2225, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 0, 0, 0, 0, + 0, 0, 0, 2226, 2227, 0, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 1068, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 1069, 142, 1070, 1071, 0, 145, 146, - 147, 148, 149, 150, 1072, 795, 151, 152, 153, 154, - 1073, 1074, 157, 0, 158, 159, 160, 161, 796, 0, - 797, 0, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1076, 192, 193, 1077, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 1080, 223, 224, 225, 226, 227, 228, 798, 1081, - 230, 0, 231, 232, 1082, 234, 0, 235, 0, 236, - 237, 0, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 1083, 1084, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 1085, 1086, 0, 1087, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 292, 293, 294, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1088, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1089, 325, 1090, - 327, 328, 329, 330, 0, 331, 332, 333, 334, 1092, - 800, 336, 1093, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1095, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 1096, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 433, 434, 435, 1097, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 0, 0, 454, 455, - 0, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 1098, 1099, 0, 0, 466, 467, 806, 469, 807, 1100, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 1102, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 163, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 0, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 0, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 0, 0, 0, 0, 0, 0, 0, 1435, 1436, + 0, 0, 0, 0, 0, 1100, 0, 1101, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 0, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 3117, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 0, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1100, 0, 2800, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 0, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 163, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 0, 329, 330, 331, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1100, 0, 2800, 0, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 117, 1056, 821, + 1057, 1058, 0, 1060, 1061, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 1062, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 1063, 141, + 1064, 1065, 0, 144, 145, 146, 147, 148, 149, 1066, + 790, 150, 151, 152, 153, 1067, 1068, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 1070, 191, 192, 1071, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 1073, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 1074, 222, 223, 224, + 225, 226, 227, 793, 1075, 229, 0, 230, 231, 1076, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 1077, 1078, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 1079, 1080, 0, 1081, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 1082, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 1083, 323, 1084, 325, 326, 327, 328, 0, + 329, 330, 331, 332, 1086, 795, 334, 1087, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 1089, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 1090, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 1091, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 1092, 1093, 0, 0, 462, 463, 801, + 465, 802, 1094, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 1095, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1100, 0, 1101, 0, 0, 0, 0, 0, 1102, 1103, + 1104, 1105, 117, 1056, 821, 1057, 1058, 1059, 1060, 1061, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 1062, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 0, 1063, 141, 1064, 1065, 0, 144, 145, + 146, 147, 148, 149, 1066, 790, 150, 151, 152, 153, + 1067, 1068, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 1069, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1070, 191, 192, 1071, 194, 1072, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 0, 216, 0, 217, 218, 219, + 220, 1074, 222, 223, 224, 225, 226, 227, 793, 1075, + 229, 0, 230, 231, 1076, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 0, 242, 0, 243, + 0, 1077, 1078, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 0, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 1079, 1080, 0, 1081, 0, + 278, 0, 0, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 0, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 1082, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1083, 323, 1084, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 1086, + 795, 334, 1087, 336, 337, 338, 0, 339, 340, 0, + 0, 1088, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1089, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 1090, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 0, 431, 432, 1091, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 1092, 1093, + 0, 0, 462, 463, 801, 465, 802, 1094, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 1095, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 0, 0, 0, 0, 0, 0, 0, 1097, 1098, + 1099, 0, 974, 1364, 821, 1100, 0, 1101, 1060, 0, + 0, 0, 0, 1102, 1103, 1104, 1105, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 565, 0, 0, 0, + 0, 570, 130, 131, 0, 132, 133, 134, 572, 136, + 137, 138, 573, 574, 575, 576, 577, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 581, 582, 156, 0, 157, 158, 159, 160, 584, 0, + 586, 0, 588, 164, 165, 166, 167, 168, 589, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 592, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 594, 191, 192, 595, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 605, 222, 223, 224, 225, 226, 227, 606, 1365, + 229, 0, 230, 231, 609, 233, 0, 234, 0, 235, + 612, 0, 614, 238, 239, 615, 616, 242, 0, 243, + 0, 619, 620, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 622, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 625, 626, + 270, 271, 272, 273, 274, 627, 628, 0, 630, 0, + 278, 632, 633, 281, 634, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 637, 291, 638, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 2406, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 641, 642, 643, + 325, 326, 327, 644, 0, 329, 330, 646, 332, 0, + 648, 334, 649, 336, 337, 338, 0, 339, 340, 1366, + 0, 341, 342, 343, 0, 0, 344, 345, 655, 656, + 348, 657, 658, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 663, 664, 366, 367, 665, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 668, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 671, 404, 405, 406, 672, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 674, 421, 422, 423, 424, 425, 426, 675, + 428, 429, 0, 677, 431, 432, 678, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 680, 448, 681, 0, 0, 450, 451, 0, 452, + 685, 454, 455, 456, 457, 458, 0, 459, 687, 688, + 0, 0, 462, 463, 691, 465, 692, 1367, 467, 468, + 694, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 699, 700, 489, 0, 490, 702, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 707, 708, 709, 710, + 711, 712, 713, 714, 715, 716, 717, 517, 518, 519, + 520, 0, 0, 0, 0, 0, 0, 0, 1368, 1369, + 2407, 117, 0, 0, 0, 2408, 0, 2409, 1061, 0, + 0, 0, 0, 0, 0, 0, 1105, 0, 0, 0, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 1062, 0, 0, + 129, 130, 131, 0, 132, 133, 134, 135, 136, 137, + 138, 139, 140, 141, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 1066, 790, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 791, 0, 792, + 0, 163, 164, 165, 166, 167, 168, 169, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 179, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 793, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 236, + 0, 237, 238, 239, 240, 241, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 290, 291, 292, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 1082, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, 0, 329, 330, 331, 332, 0, 795, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 346, 347, 348, + 349, 797, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 798, + 365, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 430, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 447, 448, 800, 0, 0, 450, 451, 0, 452, 453, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 801, 465, 802, 0, 467, 468, 803, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 491, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1107, 0, - 1108, 0, 0, 0, 0, 0, 1109, 1110, 1111, 1112, - 118, 1062, 826, 1063, 1064, 1065, 1066, 1067, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 1068, 0, 0, 130, - 131, 132, 0, 133, 134, 135, 136, 137, 138, 139, - 0, 1069, 142, 1070, 1071, 0, 145, 146, 147, 148, - 149, 150, 1072, 795, 151, 152, 153, 154, 1073, 1074, - 157, 0, 158, 159, 160, 161, 796, 0, 797, 0, - 1075, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1076, - 192, 193, 1077, 195, 1078, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 0, 217, 0, 218, 219, 220, 221, 1080, - 223, 224, 225, 226, 227, 228, 798, 1081, 230, 0, - 231, 232, 1082, 234, 0, 235, 0, 236, 237, 0, - 238, 239, 240, 241, 0, 243, 244, 245, 0, 1083, - 1084, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 270, 271, 272, 273, - 274, 275, 276, 1085, 1086, 0, 1087, 0, 280, 0, - 0, 283, 284, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 292, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 1088, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1089, 325, 1090, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 1092, 800, 336, - 1093, 338, 339, 340, 0, 341, 342, 0, 0, 1094, - 344, 345, 0, 0, 346, 347, 348, 349, 350, 351, - 802, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 803, - 368, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1095, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 406, 407, 408, 409, 1096, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 1097, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 805, 0, 0, 454, 455, 0, 456, - 457, 458, 459, 460, 461, 462, 0, 463, 1098, 1099, - 0, 0, 466, 467, 806, 469, 807, 1100, 471, 472, - 808, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 1101, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 1102, 493, 0, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 0, 0, 0, 0, 0, 0, 0, 1104, - 1105, 1106, 0, 980, 1374, 826, 1107, 0, 1108, 1066, - 0, 0, 0, 0, 1109, 1110, 1111, 1112, 0, 0, - 0, 0, 119, 120, 121, 122, 123, 124, 125, 126, - 0, 127, 128, 129, 0, 0, 0, 569, 0, 0, - 0, 0, 574, 131, 132, 0, 576, 134, 135, 577, - 137, 138, 139, 578, 579, 580, 581, 582, 0, 145, - 146, 147, 148, 149, 150, 0, 0, 151, 152, 153, - 154, 586, 587, 157, 0, 158, 159, 160, 161, 589, - 0, 591, 0, 593, 165, 166, 167, 168, 169, 594, - 171, 172, 173, 0, 174, 175, 176, 177, 178, 179, - 0, 597, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 599, 192, 193, 600, 195, 0, 196, 0, - 197, 198, 199, 200, 201, 202, 0, 0, 203, 204, - 205, 206, 0, 0, 207, 208, 209, 210, 211, 0, - 212, 213, 214, 0, 215, 216, 217, 0, 218, 219, - 220, 221, 610, 223, 224, 225, 226, 227, 228, 611, - 1375, 230, 0, 231, 232, 614, 234, 0, 235, 0, - 236, 617, 0, 619, 239, 240, 620, 621, 243, 244, - 245, 0, 623, 624, 248, 249, 0, 250, 251, 252, - 253, 254, 255, 256, 626, 258, 259, 260, 261, 0, - 262, 263, 264, 265, 266, 267, 268, 0, 269, 629, - 630, 272, 273, 274, 275, 276, 631, 632, 0, 634, - 0, 280, 636, 637, 283, 638, 285, 286, 287, 288, - 289, 290, 0, 0, 291, 641, 293, 642, 0, 295, - 296, 297, 298, 299, 300, 301, 302, 2440, 304, 305, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 528, 1982, 0, 1100, 0, 2142, 1983, 1061, 0, + 0, 0, 1102, 1103, 1104, 1105, 0, 0, 0, 0, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 130, 131, 0, 132, 133, 134, 0, 136, 137, + 138, 139, 140, 0, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 0, 0, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 161, 0, 0, + 0, 163, 164, 165, 166, 167, 168, 0, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 0, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 228, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 0, + 0, 0, 238, 239, 529, 0, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 253, 254, 0, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 0, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 0, 0, 281, 0, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 0, 291, 0, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 322, 323, 645, 646, - 647, 327, 328, 329, 648, 0, 331, 332, 650, 334, - 0, 652, 336, 653, 338, 339, 340, 0, 341, 342, - 1376, 0, 343, 344, 345, 0, 0, 346, 347, 659, - 660, 350, 661, 662, 353, 354, 355, 356, 357, 358, - 359, 360, 361, 362, 363, 364, 0, 0, 0, 0, - 365, 366, 667, 668, 369, 370, 669, 372, 373, 374, - 0, 375, 376, 377, 378, 379, 380, 0, 381, 382, - 383, 384, 385, 672, 387, 388, 389, 390, 0, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 0, 404, 405, 675, 407, 408, 409, 676, + 316, 317, 318, 319, 320, 321, 322, 0, 324, 325, + 326, 327, 328, 0, 329, 330, 0, 332, 0, 333, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 346, 0, 348, + 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 364, + 0, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, - 421, 422, 423, 0, 678, 424, 425, 426, 427, 428, - 429, 679, 431, 432, 0, 681, 434, 435, 682, 437, - 0, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, 449, 450, 684, 452, 685, 0, 0, 454, - 455, 0, 456, 689, 458, 459, 460, 461, 462, 0, - 463, 691, 692, 0, 0, 466, 467, 695, 469, 696, - 1377, 471, 472, 698, 474, 475, 476, 477, 478, 0, - 0, 479, 480, 481, 701, 0, 482, 483, 484, 485, - 0, 486, 487, 488, 489, 490, 704, 705, 493, 0, - 494, 707, 496, 497, 498, 499, 500, 501, 502, 0, - 0, 503, 0, 0, 504, 505, 506, 507, 508, 509, - 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, - 722, 521, 522, 523, 524, 0, 0, 0, 0, 0, - 0, 0, 1378, 1379, 2441, 118, 0, 0, 0, 2442, - 0, 2443, 1067, 0, 0, 0, 0, 0, 0, 0, - 1112, 0, 0, 0, 119, 120, 121, 122, 123, 124, - 125, 126, 0, 127, 128, 129, 0, 0, 0, 0, - 0, 1068, 0, 0, 130, 131, 132, 0, 133, 134, - 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, - 0, 145, 146, 147, 148, 149, 150, 1072, 795, 151, - 152, 153, 154, 155, 156, 157, 0, 158, 159, 160, - 161, 796, 0, 797, 0, 164, 165, 166, 167, 168, - 169, 170, 171, 172, 173, 0, 174, 175, 176, 177, - 178, 179, 0, 180, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 0, - 196, 0, 197, 198, 199, 200, 201, 202, 0, 0, - 203, 204, 205, 206, 0, 0, 207, 208, 209, 210, - 211, 0, 212, 213, 214, 0, 215, 216, 217, 0, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 0, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 531, 448, 449, 0, 0, 450, 451, 0, 452, 0, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 464, 465, 466, 0, 467, 468, 469, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 0, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, + 0, 0, 0, 0, 0, 528, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1102, 1103, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, + 0, 0, 1010, 0, 0, 130, 131, 0, 132, 133, + 134, 0, 136, 137, 138, 139, 140, 0, 142, 143, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 154, 155, 156, 0, 157, 158, 159, + 160, 161, 0, 0, 0, 163, 164, 165, 166, 167, + 168, 0, 170, 171, 172, 0, 173, 174, 175, 176, + 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 208, 209, + 210, 0, 211, 212, 213, 0, 214, 215, 216, -540, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 0, 229, -540, 230, 231, 232, 233, -540, + 234, 0, 235, 0, 0, 0, 238, 239, 529, 0, + 242, 0, 243, 0, 244, 245, 246, 247, 0, 248, + 249, 250, 251, 252, 253, 254, 0, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 0, 269, 270, 271, 272, 273, 274, 275, 276, + -540, 277, 0, 278, 0, 0, 281, 0, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 0, 291, 0, + -540, 293, 294, 295, 296, 297, 298, 299, 300, 530, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, + 322, 0, 324, 325, 326, 327, 328, 0, 329, 330, + 0, 332, 0, 333, 334, 335, 336, 337, 338, -540, + 339, 340, 0, 0, 341, 342, 343, 0, -540, 344, + 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 364, 0, 366, 367, 368, 369, 370, + 371, 0, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 0, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, + 417, 418, 419, 420, 0, 0, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 0, 0, 431, 432, 433, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 531, 448, 449, 0, 0, 450, + 451, 0, 452, 0, 454, 455, 456, 457, 458, 0, + 459, 460, 461, 0, 0, 462, 463, 464, 465, 466, + 0, 467, 468, 469, 470, 471, 472, 473, 474, -540, + 0, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 487, 488, 489, 0, 490, + 0, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, + 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, + 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1177, 0, 118, 119, 120, 121, 122, 123, 124, + 125, 0, 126, 127, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 130, 131, 0, 132, 133, 134, + 0, 136, 137, 138, 139, 140, 0, 142, 143, 0, + 144, 145, 146, 147, 148, 149, 0, 0, 150, 151, + 152, 153, 154, 155, 156, 0, 157, 158, 159, 160, + 161, 0, 0, 0, 163, 164, 165, 166, 167, 168, + 0, 170, 171, 172, 0, 173, 174, 175, 176, 177, + 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 0, 195, + 0, 196, 197, 198, 199, 200, 201, 0, 0, 202, + 203, 204, 205, 0, 0, 206, 207, 208, 209, 210, + 0, 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 798, 0, 230, 0, 231, 232, 233, 234, 0, - 235, 0, 236, 237, 0, 238, 239, 240, 241, 242, - 243, 244, 245, 0, 246, 247, 248, 249, 0, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 0, 262, 263, 264, 265, 266, 267, 268, 0, - 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, - 0, 279, 0, 280, 281, 282, 283, 284, 285, 286, - 287, 288, 289, 290, 0, 0, 291, 292, 293, 294, - 0, 295, 296, 297, 298, 299, 300, 301, 302, 1088, + 228, 0, 229, 0, 230, 231, 232, 233, 0, 234, + 0, 235, 0, 0, 0, 238, 239, 529, 0, 242, + 0, 243, 0, 244, 245, 246, 247, 0, 248, 249, + 250, 251, 252, 253, 254, 0, 256, 257, 258, 259, + 0, 260, 261, 262, 263, 264, 265, 266, 0, 267, + 0, 269, 270, 271, 272, 273, 274, 275, 276, 0, + 277, 0, 278, 0, 0, 281, 0, 283, 284, 285, + 286, 287, 288, 0, 0, 289, 0, 291, 0, 0, + 293, 294, 295, 296, 297, 298, 299, 300, 530, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, + 0, 324, 325, 326, 327, 328, 0, 329, 330, 0, + 332, 0, 333, 334, 335, 336, 337, 338, 0, 339, + 340, 0, 0, 341, 342, 343, 0, 0, 344, 345, + 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 0, 0, 0, 0, + 362, 363, 364, 0, 366, 367, 368, 369, 370, 371, + 0, 372, 373, 374, 375, 376, 377, 0, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 0, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 0, 401, 402, 0, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, + 418, 419, 420, 0, 0, 421, 422, 423, 424, 425, + 426, 427, 428, 429, 0, 0, 431, 432, 433, 434, + 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 531, 448, 449, 0, 0, 450, 451, + 0, 452, 0, 454, 455, 456, 457, 458, 0, 459, + 460, 461, 0, 0, 462, 463, 464, 465, 466, 0, + 467, 468, 469, 470, 471, 472, 473, 474, 0, 0, + 475, 476, 477, 0, 478, 479, 480, 481, 0, 482, + 483, 484, 485, 486, 487, 488, 489, 0, 490, 0, + 492, 493, 494, 495, 496, 497, 498, 0, 0, 499, + 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, + 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, + 518, 519, 520, 974, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 2495, + 3307, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 3, 4, 0, 565, 0, 0, + 0, 0, 570, 130, 131, 0, 132, 133, 134, 572, + 136, 137, 138, 573, 574, 575, 576, 577, 0, 144, + 145, 146, 147, 148, 149, 0, 0, 150, 151, 152, + 153, 581, 582, 156, 0, 157, 158, 159, 160, 584, + 0, 586, 0, 588, 164, 165, 166, 167, 168, 589, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 592, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 594, 191, 192, 595, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 14, 15, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, + 219, 220, 605, 222, 223, 224, 225, 226, 227, 606, + 0, 229, 0, 230, 231, 609, 233, 0, 234, 0, + 235, 612, 23, 614, 238, 239, 615, 616, 242, 0, + 243, 0, 619, 620, 246, 247, 0, 248, 249, 250, + 251, 252, 253, 254, 622, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 625, + 626, 270, 271, 272, 273, 274, 627, 628, 0, 630, + 0, 278, 632, 633, 281, 634, 283, 284, 285, 286, + 287, 288, 0, 0, 289, 637, 291, 638, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 640, 302, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, 318, 319, 320, 321, 641, 642, + 643, 325, 326, 327, 644, 0, 329, 330, 646, 332, + 0, 648, 334, 649, 336, 337, 338, 0, 339, 340, + 0, 0, 341, 342, 343, 0, 0, 344, 345, 655, + 656, 348, 657, 658, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 26, 27, 28, 0, 362, + 363, 663, 664, 366, 367, 665, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 668, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 671, 404, 405, 406, 672, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 33, 674, 421, 422, 423, 424, 425, 426, + 675, 428, 429, 35, 677, 431, 432, 678, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 680, 448, 681, 37, 0, 450, 451, 38, + 452, 685, 454, 455, 456, 457, 458, 0, 459, 687, + 688, 0, 0, 462, 463, 691, 465, 692, 0, 467, + 468, 694, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 40, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 975, 700, 489, 0, 490, 702, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 44, 500, 501, 502, 503, 504, 505, 707, 708, 709, + 710, 711, 712, 713, 714, 715, 716, 717, 517, 518, + 519, 520, 0, 117, 45, 554, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 46, 0, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 129, 130, 131, 0, 132, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 790, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 791, + 0, 792, 0, 163, 164, 165, 166, 167, 168, 169, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 179, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 14, 15, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, + 219, 220, 221, 222, 223, 224, 225, 226, 227, 793, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 236, 23, 237, 238, 239, 240, 241, 242, 0, + 243, 0, 244, 245, 246, 247, 0, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 268, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 279, 280, 281, 282, 283, 284, 285, 286, + 287, 288, 794, 0, 289, 290, 291, 292, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 324, 325, 326, 327, 328, 329, 330, 0, 331, 332, - 333, 334, 0, 800, 336, 337, 338, 339, 340, 0, - 341, 342, 0, 0, 343, 344, 345, 0, 0, 346, - 347, 348, 349, 350, 351, 802, 353, 354, 355, 356, - 357, 358, 359, 360, 361, 362, 363, 364, 0, 0, - 0, 0, 365, 366, 803, 368, 369, 370, 371, 372, - 373, 374, 0, 375, 376, 377, 378, 379, 380, 0, - 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, - 0, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 0, 404, 405, 406, 407, 408, + 324, 325, 326, 327, 328, 0, 329, 330, 331, 332, + 0, 795, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 796, 341, 342, 343, 0, 0, 344, 345, 346, + 347, 348, 349, 797, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 26, 27, 28, 0, 362, + 363, 798, 365, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 383, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 403, 404, 405, 406, 407, 799, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, - 419, 420, 421, 422, 423, 0, 0, 424, 425, 426, - 427, 428, 429, 430, 431, 432, 0, 433, 434, 435, - 436, 437, 0, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, 449, 450, 451, 452, 805, 0, - 0, 454, 455, 0, 456, 457, 458, 459, 460, 461, - 462, 0, 463, 464, 465, 0, 0, 466, 467, 806, - 469, 807, 0, 471, 472, 808, 474, 475, 476, 477, - 478, 0, 0, 479, 480, 481, 0, 0, 482, 483, - 484, 485, 0, 486, 487, 488, 489, 490, 491, 492, - 493, 0, 494, 495, 496, 497, 498, 499, 500, 501, - 502, 0, 0, 503, 0, 0, 504, 505, 506, 507, - 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, - 518, 519, 520, 521, 522, 523, 524, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 532, 2003, - 0, 1107, 0, 2167, 2004, 1067, 0, 0, 0, 1109, - 1110, 1111, 1112, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 0, 0, 0, 0, 0, 532, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1109, 1110, 119, 120, 121, 122, 123, 124, - 125, 126, 0, 127, 128, 129, 0, 0, 0, 0, - 0, 0, 1016, 0, 0, 131, 132, 0, 0, 134, - 135, 0, 137, 138, 139, 140, 141, 0, 143, 144, - 0, 145, 146, 147, 148, 149, 150, 0, 0, 151, - 152, 153, 154, 155, 156, 157, 0, 158, 159, 160, - 161, 162, 0, 0, 0, 164, 165, 166, 167, 168, - 169, 0, 171, 172, 173, 0, 174, 175, 176, 177, - 178, 179, 0, 0, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 0, - 196, 0, 197, 198, 199, 200, 201, 202, 0, 0, - 203, 204, 205, 206, 0, 0, 207, 208, 209, 210, - 211, 0, 212, 213, 214, 0, 215, 216, 217, -557, - 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 0, 230, -557, 231, 232, 233, 234, -557, - 235, 0, 236, 0, 0, 0, 239, 240, 533, 0, - 243, 244, 245, 0, 246, 247, 248, 249, 0, 250, - 251, 252, 253, 254, 255, 256, 0, 258, 259, 260, - 261, 0, 262, 263, 264, 265, 266, 267, 268, 0, - 269, 0, 271, 272, 273, 274, 275, 276, 277, 278, - -557, 279, 0, 280, 0, 0, 283, 0, 285, 286, - 287, 288, 289, 290, 0, 0, 291, 0, 293, 0, - -557, 295, 296, 297, 298, 299, 300, 301, 302, 534, + 419, 420, 33, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 35, 430, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 447, 448, 800, 37, 0, 450, 451, 38, + 452, 453, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 801, 465, 802, 0, 467, + 468, 803, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 40, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 804, 488, 489, 0, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 44, 500, 501, 502, 503, 504, 505, 506, 507, 508, + 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, + 519, 520, 0, 117, 45, 554, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 805, 0, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 129, 130, 131, 0, 132, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 790, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 791, + 0, 792, 0, 163, 164, 165, 166, 167, 168, 169, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 179, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 0, 0, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, + 219, 220, 221, 222, 223, 224, 225, 226, 227, 793, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 236, 0, 237, 238, 239, 240, 241, 242, 0, + 243, 0, 244, 245, 246, 247, 0, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 268, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 279, 280, 281, 282, 283, 284, 285, 286, + 287, 288, 794, 0, 289, 290, 291, 292, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 324, 0, 326, 327, 328, 329, 330, 0, 331, 332, - 0, 334, 0, 335, 336, 337, 338, 339, 340, -557, - 341, 342, 0, 0, 343, 344, 345, 0, -557, 346, - 347, 348, 0, 350, 0, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, 362, 363, 364, 0, 0, - 0, 0, 365, 366, 367, 0, 369, 370, 371, 372, - 373, 374, 0, 375, 376, 377, 378, 379, 380, 0, - 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, - 0, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 0, 404, 405, 0, 407, 408, + 324, 325, 326, 327, 328, 0, 329, 330, 331, 332, + 0, 795, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 796, 341, 342, 343, 0, 0, 344, 345, 346, + 347, 348, 349, 797, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 0, 0, 0, 0, 362, + 363, 798, 365, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 383, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 403, 404, 405, 406, 407, 799, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, - 419, 420, 421, 422, 423, 0, 0, 424, 425, 426, - 427, 428, 429, 430, 431, 432, 0, 0, 434, 435, - 436, 437, 0, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, 449, 450, 535, 452, 453, 0, - 0, 454, 455, 0, 456, 0, 458, 459, 460, 461, - 462, 0, 463, 464, 465, 0, 0, 466, 467, 468, - 469, 470, 0, 471, 472, 473, 474, 475, 476, 477, - 478, -557, 0, 479, 480, 481, 0, 0, 482, 483, - 484, 485, 0, 486, 487, 488, 489, 490, 491, 492, - 493, 0, 494, 0, 496, 497, 498, 499, 500, 501, - 502, 0, 0, 503, 0, 0, 504, 505, 506, 507, - 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, - 518, 519, 520, 521, 522, 523, 524, 532, 0, 558, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1184, 0, 119, 120, 121, 122, - 123, 124, 125, 126, 0, 127, 128, 129, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 131, 132, 0, - 0, 134, 135, 0, 137, 138, 139, 140, 141, 0, - 143, 144, 0, 145, 146, 147, 148, 149, 150, 0, - 0, 151, 152, 153, 154, 155, 156, 157, 0, 158, - 159, 160, 161, 162, 0, 0, 0, 164, 165, 166, - 167, 168, 169, 0, 171, 172, 173, 0, 174, 175, - 176, 177, 178, 179, 0, 0, 181, 182, 183, 184, - 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 0, 196, 0, 197, 198, 199, 200, 201, 202, - 0, 0, 203, 204, 205, 206, 0, 0, 207, 208, - 209, 210, 211, 0, 212, 213, 214, 0, 215, 216, - 217, 0, 218, 219, 220, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 0, 230, 0, 231, 232, 233, - 234, 0, 235, 0, 236, 0, 0, 0, 239, 240, - 533, 0, 243, 244, 245, 0, 246, 247, 248, 249, - 0, 250, 251, 252, 253, 254, 255, 256, 0, 258, - 259, 260, 261, 0, 262, 263, 264, 265, 266, 267, - 268, 0, 269, 0, 271, 272, 273, 274, 275, 276, - 277, 278, 0, 279, 0, 280, 0, 0, 283, 0, - 285, 286, 287, 288, 289, 290, 0, 0, 291, 0, - 293, 0, 0, 295, 296, 297, 298, 299, 300, 301, - 302, 534, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 324, 0, 326, 327, 328, 329, 330, 0, - 331, 332, 0, 334, 0, 335, 336, 337, 338, 339, - 340, 0, 341, 342, 0, 0, 343, 344, 345, 0, - 0, 346, 347, 348, 0, 350, 0, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 0, 0, 0, 0, 365, 366, 367, 0, 369, 370, - 371, 372, 373, 374, 0, 375, 376, 377, 378, 379, - 380, 0, 381, 382, 383, 384, 385, 386, 387, 388, - 389, 390, 0, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 0, 404, 405, 0, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 0, 0, 424, - 425, 426, 427, 428, 429, 430, 431, 432, 0, 0, - 434, 435, 436, 437, 0, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 535, 452, - 453, 0, 0, 454, 455, 0, 456, 0, 458, 459, - 460, 461, 462, 0, 463, 464, 465, 0, 0, 466, - 467, 468, 469, 470, 0, 471, 472, 473, 474, 475, - 476, 477, 478, 0, 0, 479, 480, 481, 0, 0, - 482, 483, 484, 485, 0, 486, 487, 488, 489, 490, - 491, 492, 493, 0, 494, 0, 496, 497, 498, 499, - 500, 501, 502, 0, 0, 503, 0, 0, 504, 505, - 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, - 516, 517, 518, 519, 520, 521, 522, 523, 524, 980, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 2533, 3377, 0, 119, 120, - 121, 122, 123, 124, 125, 126, 0, 127, 128, 129, - 3, 4, 0, 569, 0, 0, 0, 0, 574, 131, - 132, 0, 576, 134, 135, 577, 137, 138, 139, 578, - 579, 580, 581, 582, 0, 145, 146, 147, 148, 149, - 150, 0, 0, 151, 152, 153, 154, 586, 587, 157, - 0, 158, 159, 160, 161, 589, 0, 591, 0, 593, - 165, 166, 167, 168, 169, 594, 171, 172, 173, 0, - 174, 175, 176, 177, 178, 179, 0, 597, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 599, 192, - 193, 600, 195, 0, 196, 0, 197, 198, 199, 200, - 201, 202, 14, 15, 203, 204, 205, 206, 0, 0, - 207, 208, 209, 210, 211, 0, 212, 213, 214, 0, - 215, 216, 217, 0, 218, 219, 220, 221, 610, 223, - 224, 225, 226, 227, 228, 611, 0, 230, 0, 231, - 232, 614, 234, 0, 235, 0, 236, 617, 23, 619, - 239, 240, 620, 621, 243, 244, 245, 0, 623, 624, - 248, 249, 0, 250, 251, 252, 253, 254, 255, 256, - 626, 258, 259, 260, 261, 0, 262, 263, 264, 265, - 266, 267, 268, 0, 269, 629, 630, 272, 273, 274, - 275, 276, 631, 632, 0, 634, 0, 280, 636, 637, - 283, 638, 285, 286, 287, 288, 289, 290, 0, 0, - 291, 641, 293, 642, 0, 295, 296, 297, 298, 299, - 300, 301, 302, 644, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 645, 646, 647, 327, 328, 329, - 648, 0, 331, 332, 650, 334, 0, 652, 336, 653, - 338, 339, 340, 0, 341, 342, 0, 0, 343, 344, - 345, 0, 0, 346, 347, 659, 660, 350, 661, 662, - 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, - 363, 364, 26, 27, 28, 0, 365, 366, 667, 668, - 369, 370, 669, 372, 373, 374, 0, 375, 376, 377, - 378, 379, 380, 0, 381, 382, 383, 384, 385, 672, - 387, 388, 389, 390, 0, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 0, 404, - 405, 675, 407, 408, 409, 676, 411, 412, 413, 414, - 415, 416, 417, 418, 419, 420, 421, 422, 423, 33, - 678, 424, 425, 426, 427, 428, 429, 679, 431, 432, - 35, 681, 434, 435, 682, 437, 0, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, - 684, 452, 685, 37, 0, 454, 455, 38, 456, 689, - 458, 459, 460, 461, 462, 0, 463, 691, 692, 0, - 0, 466, 467, 695, 469, 696, 0, 471, 472, 698, - 474, 475, 476, 477, 478, 0, 0, 479, 480, 481, - 701, 40, 482, 483, 484, 485, 0, 486, 487, 488, - 489, 490, 981, 705, 493, 0, 494, 707, 496, 497, - 498, 499, 500, 501, 502, 0, 0, 503, 0, 44, - 504, 505, 506, 507, 508, 509, 712, 713, 714, 715, - 716, 717, 718, 719, 720, 721, 722, 521, 522, 523, - 524, 0, 118, 45, 558, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 46, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 130, 131, 132, 0, 133, 134, 135, 136, 137, - 138, 139, 140, 141, 142, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 795, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 796, 0, - 797, 0, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, + 419, 420, 0, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 0, 430, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 447, 448, 800, 0, 0, 450, 451, 0, + 452, 453, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 801, 465, 802, 0, 467, + 468, 803, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 0, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 804, 488, 489, 0, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, + 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, + 519, 520, 117, 0, 554, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 805, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 129, 130, 131, 0, 132, 133, 134, 135, 136, + 137, 138, 139, 140, 141, 142, 143, 0, 144, 145, + 146, 147, 148, 149, 0, 790, 150, 151, 152, 153, + 154, 155, 156, 0, 157, 158, 159, 160, 791, 0, + 792, 0, 163, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 793, 0, + 229, 0, 230, 231, 232, 233, 0, 234, 0, 235, + 236, 0, 237, 238, 239, 240, 241, 242, 0, 243, + 0, 244, 245, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 268, 269, + 270, 271, 272, 273, 274, 275, 276, 0, 277, 0, + 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 290, 291, 292, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, 0, 329, 330, 331, 332, 0, + 795, 334, 335, 336, 337, 338, 0, 339, 340, 0, + 796, 341, 342, 343, 0, 0, 344, 345, 346, 347, + 348, 349, 797, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 798, 365, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 403, 404, 405, 406, 407, 799, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 430, 431, 432, 433, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 800, 0, 0, 450, 451, 0, 452, + 453, 454, 455, 456, 457, 458, 0, 459, 460, 461, + 0, 0, 462, 463, 801, 465, 802, 0, 467, 468, + 803, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 488, 489, 0, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 117, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1018, 0, 0, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, + 129, 130, 131, 0, 132, 133, 134, 135, 136, 137, + 138, 139, 140, 141, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 0, 790, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 791, 0, 792, + 0, 163, 164, 165, 166, 167, 168, 169, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 14, 15, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 798, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 237, 23, 238, 239, 240, 241, 242, 243, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 270, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 799, 0, 291, 292, 293, 294, 0, 295, 296, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 793, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 236, + 0, 237, 238, 239, 240, 241, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 290, 291, 292, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, 0, 329, 330, 331, 332, 0, 795, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 346, 347, 348, + 349, 797, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 798, + 365, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 403, 404, 405, 406, 407, 799, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 430, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 447, 448, 800, 0, 0, 450, 451, 0, 452, 453, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 801, 465, 802, 0, 467, 468, 803, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 491, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, + 117, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 46, 0, 0, 118, + 119, 120, 121, 122, 123, 124, 125, 0, 126, 127, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 129, + 130, 131, 0, 132, 133, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 0, 144, 145, 146, 147, + 148, 149, 0, 790, 150, 151, 152, 153, 154, 155, + 156, 0, 157, 158, 159, 160, 791, 0, 792, 0, + 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, + 0, 173, 174, 175, 176, 177, 178, 0, 179, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 0, 195, 0, 196, 197, 198, + 199, 200, 201, 0, 0, 202, 203, 204, 205, 0, + 0, 206, 207, 208, 209, 210, 0, 211, 212, 213, + 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 793, 0, 229, 0, + 230, 231, 232, 233, 0, 234, 0, 235, 236, 0, + 237, 238, 239, 240, 241, 242, 0, 243, 0, 244, + 245, 246, 247, 0, 248, 249, 250, 251, 252, 253, + 254, 255, 256, 257, 258, 259, 0, 260, 261, 262, + 263, 264, 265, 266, 0, 267, 268, 269, 270, 271, + 272, 273, 274, 275, 276, 0, 277, 0, 278, 279, + 280, 281, 282, 283, 284, 285, 286, 287, 288, 0, + 0, 289, 290, 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, 330, 0, 331, 332, 333, 334, 0, - 800, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 801, 343, 344, 345, 0, 0, 346, 347, 348, 349, - 350, 351, 802, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 26, 27, 28, 0, 365, - 366, 803, 368, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 406, 407, 408, 409, 410, 804, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 33, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 35, 433, 434, 435, 436, 437, 0, + 327, 328, 0, 329, 330, 331, 332, 0, 795, 334, + 335, 336, 337, 338, 0, 339, 340, 0, 0, 341, + 342, 343, 0, 0, 344, 345, 346, 347, 348, 349, + 797, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 0, 0, 0, 0, 362, 363, 798, 365, + 366, 367, 368, 369, 370, 371, 0, 372, 373, 374, + 375, 376, 377, 0, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 0, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 0, + 0, 421, 422, 423, 424, 425, 426, 427, 428, 429, + 0, 430, 431, 432, 433, 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 805, 37, 0, 454, 455, - 38, 456, 457, 458, 459, 460, 461, 462, 0, 463, - 464, 465, 0, 0, 466, 467, 806, 469, 807, 0, - 471, 472, 808, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 40, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 809, 492, 493, 0, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 44, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 0, 118, 45, 558, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 810, 0, 0, 0, 119, 120, 121, 122, 123, 124, - 125, 126, 0, 127, 128, 129, 0, 0, 0, 0, - 0, 0, 0, 0, 130, 131, 132, 0, 133, 134, - 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, - 0, 145, 146, 147, 148, 149, 150, 0, 795, 151, - 152, 153, 154, 155, 156, 157, 0, 158, 159, 160, - 161, 796, 0, 797, 0, 164, 165, 166, 167, 168, - 169, 170, 171, 172, 173, 0, 174, 175, 176, 177, - 178, 179, 0, 180, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 0, - 196, 0, 197, 198, 199, 200, 201, 202, 0, 0, - 203, 204, 205, 206, 0, 0, 207, 208, 209, 210, - 211, 0, 212, 213, 214, 0, 215, 216, 217, 0, - 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 798, 0, 230, 0, 231, 232, 233, 234, 0, - 235, 0, 236, 237, 0, 238, 239, 240, 241, 242, - 243, 244, 245, 0, 246, 247, 248, 249, 0, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 0, 262, 263, 264, 265, 266, 267, 268, 0, - 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, - 0, 279, 0, 280, 281, 282, 283, 284, 285, 286, - 287, 288, 289, 290, 799, 0, 291, 292, 293, 294, - 0, 295, 296, 297, 298, 299, 300, 301, 302, 303, - 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 324, 325, 326, 327, 328, 329, 330, 0, 331, 332, - 333, 334, 0, 800, 336, 337, 338, 339, 340, 0, - 341, 342, 0, 801, 343, 344, 345, 0, 0, 346, - 347, 348, 349, 350, 351, 802, 353, 354, 355, 356, - 357, 358, 359, 360, 361, 362, 363, 364, 0, 0, - 0, 0, 365, 366, 803, 368, 369, 370, 371, 372, - 373, 374, 0, 375, 376, 377, 378, 379, 380, 0, - 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, - 0, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 0, 404, 405, 406, 407, 408, - 409, 410, 804, 412, 413, 414, 415, 416, 417, 418, - 419, 420, 421, 422, 423, 0, 0, 424, 425, 426, - 427, 428, 429, 430, 431, 432, 0, 433, 434, 435, - 436, 437, 0, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, 449, 450, 451, 452, 805, 0, - 0, 454, 455, 0, 456, 457, 458, 459, 460, 461, - 462, 0, 463, 464, 465, 0, 0, 466, 467, 806, - 469, 807, 0, 471, 472, 808, 474, 475, 476, 477, - 478, 0, 0, 479, 480, 481, 0, 0, 482, 483, - 484, 485, 0, 486, 487, 488, 489, 490, 809, 492, - 493, 0, 494, 495, 496, 497, 498, 499, 500, 501, - 502, 0, 0, 503, 0, 0, 504, 505, 506, 507, - 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, - 518, 519, 520, 521, 522, 523, 524, 118, 0, 558, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 810, 0, 0, 119, 120, 121, 122, - 123, 124, 125, 126, 0, 127, 128, 129, 0, 0, - 0, 0, 0, 0, 0, 0, 130, 131, 132, 0, - 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, - 143, 144, 0, 145, 146, 147, 148, 149, 150, 0, - 795, 151, 152, 153, 154, 155, 156, 157, 0, 158, - 159, 160, 161, 796, 0, 797, 0, 164, 165, 166, - 167, 168, 169, 170, 171, 172, 173, 0, 174, 175, - 176, 177, 178, 179, 0, 180, 181, 182, 183, 184, - 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 0, 196, 0, 197, 198, 199, 200, 201, 202, - 0, 0, 203, 204, 205, 206, 0, 0, 207, 208, - 209, 210, 211, 0, 212, 213, 214, 0, 215, 216, - 217, 0, 218, 219, 220, 221, 222, 223, 224, 225, - 226, 227, 228, 798, 0, 230, 0, 231, 232, 233, - 234, 0, 235, 0, 236, 237, 0, 238, 239, 240, - 241, 242, 243, 244, 245, 0, 246, 247, 248, 249, - 0, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 0, 262, 263, 264, 265, 266, 267, - 268, 0, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 0, 279, 0, 280, 281, 282, 283, 284, - 285, 286, 287, 288, 289, 290, 0, 0, 291, 292, - 293, 294, 0, 295, 296, 297, 298, 299, 300, 301, - 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 324, 325, 326, 327, 328, 329, 330, 0, - 331, 332, 333, 334, 0, 800, 336, 337, 338, 339, - 340, 0, 341, 342, 0, 801, 343, 344, 345, 0, - 0, 346, 347, 348, 349, 350, 351, 802, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 0, 0, 0, 0, 365, 366, 803, 368, 369, 370, - 371, 372, 373, 374, 0, 375, 376, 377, 378, 379, - 380, 0, 381, 382, 383, 384, 385, 386, 387, 388, - 389, 390, 0, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 0, 404, 405, 406, - 407, 408, 409, 410, 804, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 0, 0, 424, - 425, 426, 427, 428, 429, 430, 431, 432, 0, 433, - 434, 435, 436, 437, 0, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, - 805, 0, 0, 454, 455, 0, 456, 457, 458, 459, - 460, 461, 462, 0, 463, 464, 465, 0, 0, 466, - 467, 806, 469, 807, 0, 471, 472, 808, 474, 475, - 476, 477, 478, 0, 0, 479, 480, 481, 0, 0, - 482, 483, 484, 485, 0, 486, 487, 488, 489, 490, - 491, 492, 493, 0, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 0, 0, 503, 0, 0, 504, 505, - 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, - 516, 517, 518, 519, 520, 521, 522, 523, 524, 118, + 448, 800, 0, 0, 450, 451, 0, 452, 453, 454, + 455, 456, 457, 458, 0, 459, 460, 461, 0, 0, + 462, 463, 801, 465, 802, 0, 467, 468, 803, 470, + 471, 472, 473, 474, 0, 0, 475, 476, 477, 0, + 478, 479, 480, 481, 0, 482, 483, 484, 485, 486, + 487, 488, 489, 0, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 0, 0, 499, 0, 0, 500, 501, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1024, 0, 0, 119, 120, - 121, 122, 123, 124, 125, 126, 0, 127, 128, 129, + 0, 0, 0, 0, 0, 3396, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 14, 15, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 23, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 253, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 26, 27, 28, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 33, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 35, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 37, 0, 450, 451, 38, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 460, 461, 0, 0, 462, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 40, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 804, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 44, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 0, 528, + 45, 554, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 46, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 894, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 23, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 253, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 26, 27, 28, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 33, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 0, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 0, 0, 450, 451, 38, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 895, 461, 0, 0, 896, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 40, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 804, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 44, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 0, 528, + 45, 554, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 46, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 23, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 253, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 26, 27, 28, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 33, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 0, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 0, 0, 450, 451, 38, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 460, 461, 0, 0, 462, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 40, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 804, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 44, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 0, 528, + 45, 554, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 46, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 0, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 253, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 0, 0, 0, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 0, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 0, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 0, 0, 450, 451, 0, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 460, 461, 0, 0, 462, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 0, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 487, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 0, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 528, 0, + 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 994, 0, 0, 118, 119, 120, + 121, 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, 131, - 132, 0, 133, 134, 135, 136, 137, 138, 139, 140, - 141, 142, 143, 144, 0, 145, 146, 147, 148, 149, - 150, 0, 795, 151, 152, 153, 154, 155, 156, 157, - 0, 158, 159, 160, 161, 796, 0, 797, 0, 164, - 165, 166, 167, 168, 169, 170, 171, 172, 173, 0, - 174, 175, 176, 177, 178, 179, 0, 180, 181, 182, + 0, 132, 133, 134, 0, 136, 137, 138, 139, 140, + 0, 142, 143, 0, 144, 145, 146, 147, 148, 149, + 0, 0, 150, 151, 152, 153, 154, 155, 156, 0, + 157, 158, 159, 160, 161, 0, 0, 0, 163, 164, + 165, 166, 167, 168, 0, 170, 171, 172, 0, 173, + 174, 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 0, 196, 0, 197, 198, 199, 200, - 201, 202, 0, 0, 203, 204, 205, 206, 0, 0, - 207, 208, 209, 210, 211, 0, 212, 213, 214, 0, - 215, 216, 217, 0, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 798, 0, 230, 0, 231, - 232, 233, 234, 0, 235, 0, 236, 237, 0, 238, - 239, 240, 241, 242, 243, 244, 245, 0, 246, 247, - 248, 249, 0, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 0, 262, 263, 264, 265, - 266, 267, 268, 0, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 0, 279, 0, 280, 281, 282, - 283, 284, 285, 286, 287, 288, 289, 290, 0, 0, - 291, 292, 293, 294, 0, 295, 296, 297, 298, 299, - 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, - 330, 0, 331, 332, 333, 334, 0, 800, 336, 337, - 338, 339, 340, 0, 341, 342, 0, 0, 343, 344, - 345, 0, 0, 346, 347, 348, 349, 350, 351, 802, - 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, - 363, 364, 0, 0, 0, 0, 365, 366, 803, 368, - 369, 370, 371, 372, 373, 374, 0, 375, 376, 377, - 378, 379, 380, 0, 381, 382, 383, 384, 385, 386, - 387, 388, 389, 390, 0, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 0, 404, - 405, 406, 407, 408, 409, 410, 804, 412, 413, 414, - 415, 416, 417, 418, 419, 420, 421, 422, 423, 0, - 0, 424, 425, 426, 427, 428, 429, 430, 431, 432, - 0, 433, 434, 435, 436, 437, 0, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, - 451, 452, 805, 0, 0, 454, 455, 0, 456, 457, - 458, 459, 460, 461, 462, 0, 463, 464, 465, 0, - 0, 466, 467, 806, 469, 807, 0, 471, 472, 808, - 474, 475, 476, 477, 478, 0, 0, 479, 480, 481, - 0, 0, 482, 483, 484, 485, 0, 486, 487, 488, - 489, 490, 491, 492, 493, 0, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 0, 0, 503, 0, 0, + 193, 194, 0, 195, 0, 196, 197, 198, 199, 200, + 201, 0, 0, 202, 203, 204, 205, 0, 0, 206, + 207, 208, 209, 210, 0, 211, 212, 213, 0, 214, + 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 0, 229, 0, 230, 231, + 232, 233, 0, 234, 0, 235, 0, 0, 0, 238, + 239, 529, 0, 242, 0, 243, 0, 244, 245, 246, + 247, 0, 248, 249, 250, 251, 252, 253, 254, 0, + 256, 257, 258, 259, 0, 260, 261, 262, 263, 264, + 265, 266, 0, 267, 0, 269, 270, 271, 272, 273, + 274, 275, 276, 0, 277, 0, 278, 0, 0, 281, + 0, 283, 284, 285, 286, 287, 288, 0, 0, 289, + 0, 291, 0, 0, 293, 294, 295, 296, 297, 298, + 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, + 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, + 319, 320, 321, 322, 0, 324, 325, 326, 327, 328, + 0, 329, 330, 0, 332, 0, 333, 334, 335, 336, + 337, 338, 0, 339, 340, 0, 0, 341, 342, 343, + 0, 0, 344, 345, 346, 0, 348, 0, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, + 0, 0, 0, 0, 362, 363, 364, 0, 366, 367, + 368, 369, 370, 371, 0, 372, 373, 374, 375, 376, + 377, 0, 378, 379, 380, 381, 382, 383, 384, 385, + 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 0, 401, 402, 0, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, 415, 416, 417, 418, 419, 420, 0, 0, 421, + 422, 423, 424, 425, 426, 427, 428, 429, 0, 0, + 431, 432, 433, 434, 0, 435, 436, 437, 438, 439, + 440, 441, 442, 443, 444, 445, 446, 531, 448, 449, + 0, 0, 450, 451, 0, 452, 0, 454, 455, 456, + 457, 458, 0, 459, 460, 461, 0, 0, 462, 463, + 464, 465, 466, 0, 467, 468, 469, 470, 471, 472, + 473, 474, 0, 0, 475, 476, 477, 0, 478, 479, + 480, 481, 0, 482, 483, 484, 485, 486, 487, 488, + 489, 0, 490, 0, 492, 493, 494, 495, 496, 497, + 498, 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, - 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, - 524, 118, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 46, 0, 0, - 119, 120, 121, 122, 123, 124, 125, 126, 0, 127, - 128, 129, 0, 0, 0, 0, 0, 0, 0, 0, - 130, 131, 132, 0, 133, 134, 135, 136, 137, 138, - 139, 140, 141, 142, 143, 144, 0, 145, 146, 147, - 148, 149, 150, 0, 795, 151, 152, 153, 154, 155, - 156, 157, 0, 158, 159, 160, 161, 796, 0, 797, - 0, 164, 165, 166, 167, 168, 169, 170, 171, 172, - 173, 0, 174, 175, 176, 177, 178, 179, 0, 180, - 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, - 191, 192, 193, 194, 195, 0, 196, 0, 197, 198, - 199, 200, 201, 202, 0, 0, 203, 204, 205, 206, - 0, 0, 207, 208, 209, 210, 211, 0, 212, 213, - 214, 0, 215, 216, 217, 0, 218, 219, 220, 221, - 222, 223, 224, 225, 226, 227, 228, 798, 0, 230, - 0, 231, 232, 233, 234, 0, 235, 0, 236, 237, - 0, 238, 239, 240, 241, 242, 243, 244, 245, 0, - 246, 247, 248, 249, 0, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 0, 262, 263, - 264, 265, 266, 267, 268, 0, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 0, 279, 0, 280, - 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, - 0, 0, 291, 292, 293, 294, 0, 295, 296, 297, - 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, - 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, - 328, 329, 330, 0, 331, 332, 333, 334, 0, 800, - 336, 337, 338, 339, 340, 0, 341, 342, 0, 0, - 343, 344, 345, 0, 0, 346, 347, 348, 349, 350, - 351, 802, 353, 354, 355, 356, 357, 358, 359, 360, - 361, 362, 363, 364, 0, 0, 0, 0, 365, 366, - 803, 368, 369, 370, 371, 372, 373, 374, 0, 375, - 376, 377, 378, 379, 380, 0, 381, 382, 383, 384, - 385, 386, 387, 388, 389, 390, 0, 391, 392, 393, - 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, - 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, - 423, 0, 0, 424, 425, 426, 427, 428, 429, 430, - 431, 432, 0, 433, 434, 435, 436, 437, 0, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - 449, 450, 451, 452, 805, 0, 0, 454, 455, 0, - 456, 457, 458, 459, 460, 461, 462, 0, 463, 464, - 465, 0, 0, 466, 467, 806, 469, 807, 0, 471, - 472, 808, 474, 475, 476, 477, 478, 0, 0, 479, - 480, 481, 0, 0, 482, 483, 484, 485, 0, 486, - 487, 488, 489, 490, 491, 492, 493, 0, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 0, 0, 503, - 0, 0, 504, 505, 506, 507, 508, 509, 510, 511, - 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, - 522, 523, 524, 532, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 3468, - 0, 0, 119, 120, 121, 122, 123, 124, 125, 126, - 0, 127, 128, 129, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 131, 132, 0, 0, 134, 135, 0, - 137, 138, 139, 140, 141, 0, 143, 144, 0, 145, - 146, 147, 148, 149, 150, 0, 0, 151, 152, 153, - 154, 155, 156, 157, 0, 158, 159, 160, 161, 162, - 0, 0, 0, 164, 165, 166, 167, 168, 169, 0, - 171, 172, 173, 0, 174, 175, 176, 177, 178, 179, - 0, 0, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 0, 196, 0, - 197, 198, 199, 200, 201, 202, 14, 15, 203, 204, - 205, 206, 0, 0, 207, 208, 209, 210, 211, 0, - 212, 213, 214, 0, 215, 216, 217, 0, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, - 0, 230, 0, 231, 232, 233, 234, 0, 235, 0, - 236, 0, 23, 0, 239, 240, 533, 0, 243, 244, - 245, 0, 246, 247, 248, 249, 0, 250, 251, 252, - 253, 254, 255, 256, 0, 258, 259, 260, 261, 0, - 262, 263, 264, 265, 266, 267, 268, 0, 269, 0, - 271, 272, 273, 274, 275, 276, 277, 278, 0, 279, - 0, 280, 0, 0, 283, 0, 285, 286, 287, 288, - 289, 290, 0, 0, 291, 0, 293, 0, 0, 295, - 296, 297, 298, 299, 300, 301, 302, 534, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 322, 323, 324, 0, - 326, 327, 328, 329, 330, 0, 331, 332, 0, 334, - 0, 335, 336, 337, 338, 339, 340, 0, 341, 342, - 0, 0, 343, 344, 345, 0, 0, 346, 347, 348, - 0, 350, 0, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, 362, 363, 364, 26, 27, 28, 0, - 365, 366, 367, 0, 369, 370, 371, 372, 373, 374, - 0, 375, 376, 377, 378, 379, 380, 0, 381, 382, - 383, 384, 385, 386, 387, 388, 389, 390, 0, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 0, 404, 405, 0, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, - 421, 422, 423, 33, 0, 424, 425, 426, 427, 428, - 429, 430, 431, 432, 35, 0, 434, 435, 436, 437, - 0, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, 449, 450, 535, 452, 453, 37, 0, 454, - 455, 38, 456, 0, 458, 459, 460, 461, 462, 0, - 463, 464, 465, 0, 0, 466, 467, 468, 469, 470, - 0, 471, 472, 473, 474, 475, 476, 477, 478, 0, - 0, 479, 480, 481, 0, 40, 482, 483, 484, 485, - 0, 486, 487, 488, 489, 490, 809, 492, 493, 0, - 494, 0, 496, 497, 498, 499, 500, 501, 502, 0, - 0, 503, 0, 44, 504, 505, 506, 507, 508, 509, - 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, - 520, 521, 522, 523, 524, 0, 532, 45, 558, 0, + 514, 515, 516, 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 46, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 899, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 23, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 26, - 27, 28, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 33, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 38, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 900, 465, 0, 0, 901, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 40, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 809, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 44, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 0, 532, - 45, 558, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 46, 0, 0, 0, 119, 120, - 121, 122, 123, 124, 125, 126, 0, 127, 128, 129, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 131, - 132, 0, 0, 134, 135, 0, 137, 138, 139, 140, - 141, 0, 143, 144, 0, 145, 146, 147, 148, 149, - 150, 0, 0, 151, 152, 153, 154, 155, 156, 157, - 0, 158, 159, 160, 161, 162, 0, 0, 0, 164, - 165, 166, 167, 168, 169, 0, 171, 172, 173, 0, - 174, 175, 176, 177, 178, 179, 0, 0, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 0, 196, 0, 197, 198, 199, 200, - 201, 202, 0, 0, 203, 204, 205, 206, 0, 0, - 207, 208, 209, 210, 211, 0, 212, 213, 214, 0, - 215, 216, 217, 0, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 0, 230, 0, 231, - 232, 233, 234, 0, 235, 0, 236, 0, 23, 0, - 239, 240, 533, 0, 243, 244, 245, 0, 246, 247, - 248, 249, 0, 250, 251, 252, 253, 254, 255, 256, - 0, 258, 259, 260, 261, 0, 262, 263, 264, 265, - 266, 267, 268, 0, 269, 0, 271, 272, 273, 274, - 275, 276, 277, 278, 0, 279, 0, 280, 0, 0, - 283, 0, 285, 286, 287, 288, 289, 290, 0, 0, - 291, 0, 293, 0, 0, 295, 296, 297, 298, 299, - 300, 301, 302, 534, 304, 305, 306, 307, 308, 309, + 0, 0, 0, 1493, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 130, 131, 0, + 132, 133, 134, 0, 136, 137, 138, 139, 140, 0, + 142, 143, 0, 144, 145, 146, 147, 148, 149, 0, + 0, 150, 151, 152, 153, 154, 155, 156, 0, 157, + 158, 159, 160, 161, 0, 0, 0, 163, 164, 165, + 166, 167, 168, 0, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 208, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 0, 229, 0, 230, 231, 232, + 233, 0, 234, 0, 235, 0, 0, 0, 238, 239, + 529, 0, 242, 0, 243, 0, 244, 245, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 0, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 0, 269, 270, 271, 272, 273, 274, + 275, 276, 0, 277, 0, 278, 0, 0, 281, 0, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 0, + 291, 0, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 324, 0, 326, 327, 328, 329, - 330, 0, 331, 332, 0, 334, 0, 335, 336, 337, - 338, 339, 340, 0, 341, 342, 0, 0, 343, 344, - 345, 0, 0, 346, 347, 348, 0, 350, 0, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, - 363, 364, 26, 27, 28, 0, 365, 366, 367, 0, - 369, 370, 371, 372, 373, 374, 0, 375, 376, 377, - 378, 379, 380, 0, 381, 382, 383, 384, 385, 386, - 387, 388, 389, 390, 0, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 0, 404, - 405, 0, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, 417, 418, 419, 420, 421, 422, 423, 33, - 0, 424, 425, 426, 427, 428, 429, 430, 431, 432, - 0, 0, 434, 435, 436, 437, 0, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, - 535, 452, 453, 0, 0, 454, 455, 38, 456, 0, - 458, 459, 460, 461, 462, 0, 463, 464, 465, 0, - 0, 466, 467, 468, 469, 470, 0, 471, 472, 473, - 474, 475, 476, 477, 478, 0, 0, 479, 480, 481, - 0, 40, 482, 483, 484, 485, 0, 486, 487, 488, - 489, 490, 809, 492, 493, 0, 494, 0, 496, 497, - 498, 499, 500, 501, 502, 0, 0, 503, 0, 44, - 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, - 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, - 524, 0, 532, 45, 558, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 46, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 243, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 464, 465, 0, 0, 466, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 493, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 558, 0, 0, 0, + 320, 321, 322, 0, 324, 325, 326, 327, 328, 0, + 329, 330, 0, 332, 0, 333, 334, 335, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 0, 348, 0, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 364, 0, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 383, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 0, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 0, 431, + 432, 433, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 531, 448, 449, 0, + 0, 450, 451, 0, 452, 0, 454, 455, 456, 457, + 458, 0, 459, 460, 461, 0, 0, 462, 463, 464, + 465, 466, 0, 467, 468, 469, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 488, 489, + 0, 490, 0, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1000, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 0, - 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 558, 0, + 0, 0, 2103, 0, 0, 118, 119, 120, 121, 122, + 123, 124, 125, 0, 126, 127, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 130, 131, 0, 132, + 133, 134, 0, 136, 137, 138, 139, 140, 0, 142, + 143, 0, 144, 145, 146, 147, 148, 149, 0, 0, + 150, 151, 152, 153, 154, 155, 156, 0, 157, 158, + 159, 160, 161, 0, 0, 0, 163, 164, 165, 166, + 167, 168, 0, 170, 171, 172, 0, 173, 174, 175, + 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 0, 195, 0, 196, 197, 198, 199, 200, 201, 0, + 0, 202, 203, 204, 205, 0, 0, 206, 207, 208, + 209, 210, 0, 211, 212, 213, 0, 214, 215, 216, + 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, + 226, 227, 228, 0, 229, 0, 230, 231, 232, 233, + 0, 234, 0, 235, 0, 0, 0, 238, 239, 529, + 0, 242, 0, 243, 0, 244, 245, 246, 247, 0, + 248, 249, 250, 251, 252, 253, 254, 0, 256, 257, + 258, 259, 0, 260, 261, 262, 263, 264, 265, 266, + 0, 267, 0, 269, 270, 271, 272, 273, 274, 275, + 276, 0, 277, 0, 278, 0, 0, 281, 0, 283, + 284, 285, 286, 287, 288, 0, 0, 289, 0, 291, + 0, 0, 293, 294, 295, 296, 297, 298, 299, 300, + 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, + 321, 322, 0, 324, 325, 326, 327, 328, 0, 329, + 330, 0, 332, 0, 333, 334, 335, 336, 337, 338, + 0, 339, 340, 0, 0, 341, 342, 343, 0, 0, + 344, 345, 346, 0, 348, 0, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, 361, 0, 0, + 0, 0, 362, 363, 364, 0, 366, 367, 368, 369, + 370, 371, 0, 372, 373, 374, 375, 376, 377, 0, + 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, + 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, + 397, 398, 399, 400, 0, 401, 402, 0, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + 416, 417, 418, 419, 420, 0, 0, 421, 422, 423, + 424, 425, 426, 427, 428, 429, 0, 0, 431, 432, + 433, 434, 0, 435, 436, 437, 438, 439, 440, 441, + 442, 443, 444, 445, 446, 531, 448, 449, 0, 0, + 450, 451, 0, 452, 0, 454, 455, 456, 457, 458, + 0, 459, 460, 461, 0, 0, 462, 463, 464, 465, + 466, 0, 467, 468, 469, 470, 471, 472, 473, 474, + 0, 0, 475, 476, 477, 0, 478, 479, 480, 481, + 0, 482, 483, 484, 485, 486, 487, 488, 489, 0, + 490, 0, 492, 493, 494, 495, 496, 497, 498, 0, + 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, + 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, + 516, 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1504, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, + 0, 2250, 0, 0, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 130, 131, 0, 132, 133, + 134, 0, 136, 137, 138, 139, 140, 0, 142, 143, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 154, 155, 156, 0, 157, 158, 159, + 160, 161, 0, 0, 0, 163, 164, 165, 166, 167, + 168, 0, 170, 171, 172, 0, 173, 174, 175, 176, + 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 208, 209, + 210, 0, 211, 212, 213, 0, 214, 215, 216, 0, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 0, 229, 0, 230, 231, 232, 233, 0, + 234, 0, 235, 0, 0, 0, 238, 239, 529, 0, + 242, 0, 243, 0, 244, 245, 246, 247, 0, 248, + 249, 250, 251, 252, 253, 254, 0, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 0, 269, 270, 271, 272, 273, 274, 275, 276, + 0, 277, 0, 278, 0, 0, 281, 0, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 0, 291, 0, + 0, 293, 294, 295, 296, 297, 298, 299, 300, 530, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, + 322, 0, 324, 325, 326, 327, 328, 0, 329, 330, + 0, 332, 0, 333, 334, 335, 336, 337, 338, 0, + 339, 340, 0, 0, 341, 342, 343, 0, 0, 344, + 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 364, 0, 366, 367, 368, 369, 370, + 371, 0, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 0, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, + 417, 418, 419, 420, 0, 0, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 0, 0, 431, 432, 433, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 531, 448, 449, 0, 0, 450, + 451, 0, 452, 0, 454, 455, 456, 457, 458, 0, + 459, 460, 461, 0, 0, 462, 463, 464, 465, 466, + 0, 467, 468, 469, 470, 471, 472, 473, 474, 0, + 0, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 487, 488, 489, 0, 490, + 0, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 558, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 2128, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 558, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 2274, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 532, 0, 558, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 2533, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 243, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 464, 465, 0, 0, 466, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 493, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 558, 0, 0, 0, + 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2677, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, + 2495, 0, 0, 118, 119, 120, 121, 122, 123, 124, + 125, 0, 126, 127, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 130, 131, 0, 132, 133, 134, + 0, 136, 137, 138, 139, 140, 0, 142, 143, 0, + 144, 145, 146, 147, 148, 149, 0, 0, 150, 151, + 152, 153, 154, 155, 156, 0, 157, 158, 159, 160, + 161, 0, 0, 0, 163, 164, 165, 166, 167, 168, + 0, 170, 171, 172, 0, 173, 174, 175, 176, 177, + 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 0, 195, + 0, 196, 197, 198, 199, 200, 201, 0, 0, 202, + 203, 204, 205, 0, 0, 206, 207, 208, 209, 210, + 0, 211, 212, 213, 0, 214, 215, 216, 0, 217, + 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, + 228, 0, 229, 0, 230, 231, 232, 233, 0, 234, + 0, 235, 0, 0, 0, 238, 239, 529, 0, 242, + 0, 243, 0, 244, 245, 246, 247, 0, 248, 249, + 250, 251, 252, 253, 254, 0, 256, 257, 258, 259, + 0, 260, 261, 262, 263, 264, 265, 266, 0, 267, + 0, 269, 270, 271, 272, 273, 274, 275, 276, 0, + 277, 0, 278, 0, 0, 281, 0, 283, 284, 285, + 286, 287, 288, 0, 0, 289, 0, 291, 0, 0, + 293, 294, 295, 296, 297, 298, 299, 300, 530, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, + 0, 324, 325, 326, 327, 328, 0, 329, 330, 0, + 332, 0, 333, 334, 335, 336, 337, 338, 0, 339, + 340, 0, 0, 341, 342, 343, 0, 0, 344, 345, + 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 0, 0, 0, 0, + 362, 363, 364, 0, 366, 367, 368, 369, 370, 371, + 0, 372, 373, 374, 375, 376, 377, 0, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 0, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 0, 401, 402, 0, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, + 418, 419, 420, 0, 0, 421, 422, 423, 424, 425, + 426, 427, 428, 429, 0, 0, 431, 432, 433, 434, + 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 531, 448, 449, 0, 0, 450, 451, + 0, 452, 0, 454, 455, 456, 457, 458, 0, 459, + 460, 461, 0, 0, 462, 463, 464, 465, 466, 0, + 467, 468, 469, 470, 471, 472, 473, 474, 0, 0, + 475, 476, 477, 0, 478, 479, 480, 481, 0, 482, + 483, 484, 485, 486, 487, 488, 489, 0, 490, 0, + 492, 493, 494, 495, 496, 497, 498, 0, 0, 499, + 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, + 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, + 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 2636, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 130, 131, 0, 132, 133, 134, 0, + 136, 137, 138, 139, 140, 0, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 0, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 161, + 0, 0, 0, 163, 164, 165, 166, 167, 168, 0, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 0, 0, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 0, 0, 0, 238, 239, 529, 0, 242, 0, + 243, 0, 244, 245, 246, 247, 0, 248, 249, 250, + 251, 252, 253, 254, 0, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 0, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 0, 0, 281, 0, 283, 284, 285, 286, + 287, 288, 0, 0, 289, 0, 291, 0, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 530, 302, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, 318, 319, 320, 321, 322, 0, + 324, 325, 326, 327, 328, 0, 329, 330, 0, 332, + 0, 333, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 0, 341, 342, 343, 0, 0, 344, 345, 346, + 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 0, 0, 0, 0, 362, + 363, 364, 0, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 383, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 0, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 0, 0, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 531, 448, 449, 0, 0, 450, 451, 0, + 452, 0, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 464, 465, 466, 0, 467, + 468, 469, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 0, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 487, 488, 489, 0, 490, 0, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, + 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, + 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 2847, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 130, 131, 0, 132, 133, 134, 0, 136, + 137, 138, 139, 140, 0, 142, 143, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 154, 155, 156, 0, 157, 158, 159, 160, 161, 0, + 0, 0, 163, 164, 165, 166, 167, 168, 0, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 0, + 229, 0, 230, 231, 232, 233, 0, 234, 0, 235, + 0, 0, 0, 238, 239, 529, 0, 242, 0, 243, + 0, 244, 245, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 0, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 0, 269, + 270, 271, 272, 273, 274, 275, 276, 0, 277, 0, + 278, 0, 0, 281, 0, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 0, 291, 0, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 322, 0, 324, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 0, + 333, 334, 335, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 0, + 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 364, 0, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, + 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 558, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 2899, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 3372, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 2234, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 0, 3029, 1374, 826, 0, 0, 2102, 1066, - 0, 0, 0, 0, 0, 2103, 2104, 0, 3229, 2105, - 2106, 2107, 119, 120, 121, 122, 123, 124, 125, 126, - 565, 127, 128, 129, 566, 567, 568, 3030, 570, 571, - 572, 573, 3031, 131, 132, 575, 3032, 134, 135, 3033, - 137, 138, 139, 0, 1518, 3034, 1520, 1521, 583, 145, - 146, 147, 148, 149, 150, 584, 585, 151, 152, 153, - 154, 1522, 1523, 157, 588, 158, 159, 160, 161, 0, - 590, 3035, 592, 3036, 165, 166, 167, 168, 169, 3037, - 171, 172, 173, 595, 174, 175, 176, 177, 178, 179, - 596, 3038, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 1528, 192, 193, 1529, 195, 601, 196, 602, - 197, 198, 199, 200, 201, 202, 603, 604, 203, 204, - 205, 206, 605, 606, 207, 208, 1079, 210, 211, 607, - 212, 213, 214, 608, 215, 216, 217, 609, 218, 219, - 220, 221, 0, 223, 224, 225, 226, 227, 228, 0, - 612, 230, 613, 231, 232, 1530, 234, 615, 235, 616, - 236, 3039, 618, 3040, 239, 240, 3041, 3042, 243, 244, - 245, 622, 0, 0, 248, 249, 625, 250, 251, 252, - 253, 254, 255, 256, 3043, 258, 259, 260, 261, 627, - 262, 263, 264, 265, 266, 267, 268, 628, 269, 3044, - 0, 272, 273, 274, 275, 276, 1536, 1537, 633, 1538, - 635, 280, 3045, 3046, 283, 3047, 285, 286, 287, 288, - 289, 290, 639, 640, 291, 3048, 293, 3049, 643, 295, - 296, 297, 298, 299, 300, 301, 302, 3050, 304, 305, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 0, 431, 432, 433, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 531, 448, 449, 0, 0, 450, 451, 0, 452, + 0, 454, 455, 456, 457, 458, 0, 459, 460, 461, + 0, 0, 462, 463, 464, 465, 466, 0, 467, 468, + 469, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 488, 489, 0, 490, 0, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 3302, 0, 0, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 130, 131, 0, 132, 133, 134, 0, 136, 137, + 138, 139, 140, 0, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 0, 0, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 161, 0, 0, + 0, 163, 164, 165, 166, 167, 168, 0, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 0, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 228, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 0, + 0, 0, 238, 239, 529, 0, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 253, 254, 0, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 0, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 0, 0, 281, 0, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 0, 291, 0, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 322, 323, 1545, 3051, - 1547, 327, 328, 329, 3052, 649, 331, 332, 3053, 334, - 651, 0, 336, 1549, 338, 339, 340, 654, 341, 342, - 655, 656, 3054, 344, 345, 657, 658, 346, 347, 0, - 3055, 350, 3056, 0, 353, 354, 355, 356, 357, 358, - 359, 360, 361, 362, 363, 364, 663, 664, 665, 666, - 365, 366, 0, 3057, 369, 370, 0, 372, 373, 374, - 670, 375, 376, 377, 378, 379, 380, 671, 381, 382, - 383, 384, 385, 1553, 387, 388, 389, 390, 673, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 674, 404, 405, 3058, 407, 408, 409, 1555, + 316, 317, 318, 319, 320, 321, 322, 0, 324, 325, + 326, 327, 328, 0, 329, 330, 0, 332, 0, 333, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 346, 0, 348, + 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 364, + 0, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, - 421, 422, 423, 677, 3059, 424, 425, 426, 427, 428, - 429, 3060, 431, 432, 680, 3061, 434, 435, 1559, 437, - 683, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, 449, 450, 3062, 452, 0, 686, 687, 454, - 455, 688, 456, 3063, 458, 459, 460, 461, 462, 690, - 463, 1562, 1563, 693, 694, 466, 467, 0, 469, 0, - 697, 471, 472, 3064, 474, 475, 476, 477, 478, 3065, - 700, 479, 480, 481, 3066, 702, 482, 483, 484, 485, - 703, 486, 487, 488, 489, 490, 0, 1567, 493, 706, - 494, 3067, 496, 497, 498, 499, 500, 501, 502, 708, - 709, 503, 710, 711, 504, 505, 506, 507, 508, 509, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 0, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 531, 448, 449, 0, 0, 450, 451, 0, 452, 0, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 464, 465, 466, 0, 467, 468, 469, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 0, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, + 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 2210, 0, 0, 118, + 119, 120, 121, 122, 123, 124, 125, 0, 126, 127, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 130, 131, 0, 132, 133, 134, 0, 136, 137, 138, + 139, 140, 0, 142, 143, 0, 144, 145, 146, 147, + 148, 149, 0, 0, 150, 151, 152, 153, 154, 155, + 156, 0, 157, 158, 159, 160, 161, 0, 0, 0, + 163, 164, 165, 166, 167, 168, 0, 170, 171, 172, + 0, 173, 174, 175, 176, 177, 178, 0, 0, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 0, 195, 0, 196, 197, 198, + 199, 200, 201, 0, 0, 202, 203, 204, 205, 0, + 0, 206, 207, 208, 209, 210, 0, 211, 212, 213, + 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 0, 229, 0, + 230, 231, 232, 233, 0, 234, 0, 235, 0, 0, + 0, 238, 239, 529, 0, 242, 0, 243, 0, 244, + 245, 246, 247, 0, 248, 249, 250, 251, 252, 253, + 254, 0, 256, 257, 258, 259, 0, 260, 261, 262, + 263, 264, 265, 266, 0, 267, 0, 269, 270, 271, + 272, 273, 274, 275, 276, 0, 277, 0, 278, 0, + 0, 281, 0, 283, 284, 285, 286, 287, 288, 0, + 0, 289, 0, 291, 0, 0, 293, 294, 295, 296, + 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 322, 0, 324, 325, 326, + 327, 328, 0, 329, 330, 0, 332, 0, 333, 334, + 335, 336, 337, 338, 0, 339, 340, 0, 0, 341, + 342, 343, 0, 0, 344, 345, 346, 0, 348, 0, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 0, 0, 0, 0, 362, 363, 364, 0, + 366, 367, 368, 369, 370, 371, 0, 372, 373, 374, + 375, 376, 377, 0, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 0, 401, + 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 0, + 0, 421, 422, 423, 424, 425, 426, 427, 428, 429, + 0, 0, 431, 432, 433, 434, 0, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 531, + 448, 449, 0, 0, 450, 451, 0, 452, 0, 454, + 455, 456, 457, 458, 0, 459, 460, 461, 0, 0, + 462, 463, 464, 465, 466, 0, 467, 468, 469, 470, + 471, 472, 473, 474, 0, 0, 475, 476, 477, 0, + 478, 479, 480, 481, 0, 482, 483, 484, 485, 486, + 487, 488, 489, 0, 490, 0, 492, 493, 494, 495, + 496, 497, 498, 0, 0, 499, 0, 0, 500, 501, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 0, + 2973, 1364, 821, 0, 0, 2078, 1060, 0, 0, 0, + 0, 0, 2079, 2080, 0, 3164, 2081, 2082, 2083, 118, + 119, 120, 121, 122, 123, 124, 125, 561, 126, 127, + 128, 562, 563, 564, 2974, 566, 567, 568, 569, 2975, + 130, 131, 571, 132, 133, 134, 2976, 136, 137, 138, + 0, 1506, 2977, 1508, 1509, 578, 144, 145, 146, 147, + 148, 149, 579, 580, 150, 151, 152, 153, 1510, 1511, + 156, 583, 157, 158, 159, 160, 0, 585, 2978, 587, + 2979, 164, 165, 166, 167, 168, 2980, 170, 171, 172, + 590, 173, 174, 175, 176, 177, 178, 591, 2981, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 1516, + 191, 192, 1517, 194, 596, 195, 597, 196, 197, 198, + 199, 200, 201, 598, 599, 202, 203, 204, 205, 600, + 601, 206, 207, 1073, 209, 210, 602, 211, 212, 213, + 603, 214, 215, 216, 604, 217, 218, 219, 220, 0, + 222, 223, 224, 225, 226, 227, 0, 607, 229, 608, + 230, 231, 1518, 233, 610, 234, 611, 235, 2982, 613, + 2983, 238, 239, 2984, 2985, 242, 617, 243, 618, 0, + 0, 246, 247, 621, 248, 249, 250, 251, 252, 253, + 254, 2986, 256, 257, 258, 259, 623, 260, 261, 262, + 263, 264, 265, 266, 624, 267, 2987, 0, 270, 271, + 272, 273, 274, 1524, 1525, 629, 1526, 631, 278, 2988, + 2989, 281, 2990, 283, 284, 285, 286, 287, 288, 635, + 636, 289, 2991, 291, 2992, 639, 293, 294, 295, 296, + 297, 298, 299, 300, 2993, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 1533, 2994, 1535, 325, 326, + 327, 2995, 645, 329, 330, 2996, 332, 647, 0, 334, + 1537, 336, 337, 338, 650, 339, 340, 651, 652, 2997, + 342, 343, 653, 654, 344, 345, 0, 2998, 348, 2999, + 0, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 659, 660, 661, 662, 362, 363, 0, 3000, + 366, 367, 0, 369, 370, 371, 666, 372, 373, 374, + 375, 376, 377, 667, 378, 379, 380, 381, 382, 1541, + 384, 385, 386, 387, 669, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 670, 401, + 402, 3001, 404, 405, 406, 1543, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 673, + 3002, 421, 422, 423, 424, 425, 426, 3003, 428, 429, + 676, 3004, 431, 432, 1547, 434, 679, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 3005, + 448, 0, 682, 683, 450, 451, 684, 452, 3006, 454, + 455, 456, 457, 458, 686, 459, 1550, 1551, 689, 690, + 462, 463, 0, 465, 0, 693, 467, 468, 3007, 470, + 471, 472, 473, 474, 3008, 696, 475, 476, 477, 697, + 478, 479, 480, 481, 698, 482, 483, 484, 485, 486, + 0, 1554, 489, 701, 490, 3009, 492, 493, 494, 495, + 496, 497, 498, 703, 704, 499, 705, 706, 500, 501, + 502, 503, 504, 505, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 517, 518, 519, 520, 0, + 528, 0, 2084, 2085, 2086, 2078, 3010, 3011, 2089, 2090, + 2091, 2092, 2079, 2080, 0, 0, 2081, 2082, 2083, 118, + 119, 120, 121, 122, 123, 124, 125, 0, 126, 127, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 130, 131, 0, 132, 133, 134, 0, 136, 137, 138, + 139, 140, 0, 142, 143, 0, 144, 145, 146, 147, + 148, 149, 0, 0, 150, 151, 152, 153, 154, 155, + 156, 0, 157, 158, 159, 160, 161, 0, 0, 0, + 163, 164, 165, 166, 167, 168, 0, 170, 171, 172, + 0, 173, 174, 175, 176, 177, 178, 0, 0, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 0, 195, 0, 196, 197, 198, + 199, 200, 201, 0, 0, 202, 203, 204, 205, 0, + 0, 206, 207, 208, 209, 210, 0, 211, 212, 213, + 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 0, 229, 0, + 230, 231, 232, 233, 0, 234, 0, 235, 0, 0, + 0, 238, 239, 529, 0, 242, 0, 243, 0, 244, + 245, 246, 247, 0, 248, 249, 250, 251, 252, 253, + 254, 0, 256, 257, 258, 259, 0, 260, 261, 262, + 263, 264, 265, 266, 0, 267, 0, 269, 270, 271, + 272, 273, 274, 275, 276, 0, 277, 0, 278, 0, + 0, 281, 0, 283, 284, 285, 286, 287, 288, 0, + 0, 289, 0, 291, 0, 0, 293, 294, 295, 296, + 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 322, 0, 324, 325, 326, + 327, 328, 0, 329, 330, 0, 332, 0, 333, 334, + 335, 336, 337, 338, 0, 339, 340, 0, 0, 341, + 342, 343, 0, 0, 344, 345, 346, 0, 348, 0, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 0, 0, 0, 0, 362, 363, 364, 0, + 366, 367, 368, 369, 370, 371, 0, 372, 373, 374, + 375, 376, 377, 0, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 0, 401, + 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 0, + 0, 421, 422, 423, 424, 425, 426, 427, 428, 429, + 0, 0, 431, 432, 433, 434, 0, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 531, + 448, 449, 0, 0, 450, 451, 0, 452, 0, 454, + 455, 456, 457, 458, 0, 459, 460, 461, 0, 0, + 462, 463, 464, 465, 466, 0, 467, 468, 469, 470, + 471, 472, 473, 474, 0, 0, 475, 476, 477, 0, + 478, 479, 480, 481, 0, 482, 483, 484, 485, 486, + 487, 488, 489, 0, 490, 0, 492, 493, 494, 495, + 496, 497, 498, 0, 0, 499, 0, 0, 500, 501, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 0, + 0, 0, 2084, 2085, 2086, 0, 2087, 2088, 2089, 2090, + 2091, 2092, 1639, 0, 0, 1640, 0, 0, 0, 1641, + 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 521, 522, 523, 524, 0, 532, 0, 2108, 2109, - 2110, 2102, 3068, 3069, 2113, 2114, 2115, 2116, 2103, 2104, - 0, 0, 2105, 2106, 2107, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 0, 0, - 0, 2108, 2109, 2110, 0, 2111, 2112, 2113, 2114, 2115, - 2116, 1653, 0, 0, 1654, 0, 0, 0, 1655, 1656, - 1657, 1658, 1659, 1660, 1661, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1662, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1664, - 1653, 0, 0, 1654, 0, 0, 1665, 1655, 1656, 1657, - 1658, 1659, 1660, 1661, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1662, 0, - 0, 0, 0, 1666, 0, 0, 0, 0, 1664, 1653, - 0, 0, 1654, 0, 0, 1665, 1655, 1656, 1657, 1658, - 1659, 1660, 1661, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1662, 0, 0, - 0, 0, 1666, 0, 0, 0, 0, 1664, 0, 0, - 0, 0, 0, 0, 1665, 0, 1653, 0, 0, 1654, - 0, 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, + 1648, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1650, 1639, 0, 0, 1640, 0, 0, 1651, 1641, 1642, + 1643, 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1648, + 0, 0, 0, 0, 1652, 0, 0, 0, 0, 1650, + 1639, 0, 0, 1640, 0, 0, 1651, 1641, 1642, 1643, + 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1648, 0, + 0, 0, 0, 1652, 0, 0, 0, 0, 1650, 0, + 0, 0, 0, 0, 0, 1651, 0, 0, 1639, 0, + 0, 1640, 0, 0, 0, 1641, 1642, 1643, 1644, 1645, + 1646, 1647, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1652, 0, 0, 0, 1648, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1650, 1639, 0, 0, + 1640, 1653, 0, 1651, 1641, 1642, 1643, 1644, 1645, 1646, + 1647, 0, 0, 0, 0, 0, 0, 0, 1654, 0, + 0, 0, 0, 1655, 0, 1648, 0, 0, 0, 0, + 1652, 0, 0, 0, 0, 1650, 0, 0, 0, 0, + 1653, 0, 1651, 0, 0, 0, 1656, 1657, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1654, 0, 0, + 0, 1658, 1655, 0, 0, 0, 0, 0, 0, 1652, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1653, + 0, 0, 0, 0, 0, 1656, 1657, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1654, 0, 0, 1659, + 1658, 1655, 1660, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1661, 0, 0, 1662, + 0, 0, 0, 0, 1656, 1657, 0, 1653, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1659, 1658, + 0, 1660, 0, 0, 1654, 0, 0, 0, 0, 1655, + 0, 0, 0, 0, 0, 1661, 0, 0, 1662, 0, + 0, 0, 0, 0, 0, 0, 1653, 0, 0, 0, + 0, 0, 1656, 1657, 0, 0, 0, 1659, 0, 0, + 1660, 0, 0, 1654, 0, 0, 0, 1658, 1655, 0, + 0, 0, 0, 0, 1661, 0, 0, 1662, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1666, 0, 0, 1662, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1664, 1653, 0, 0, 1654, 0, - 1667, 1665, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, - 0, 0, 0, 0, 0, 0, 0, 1668, 0, 0, - 0, 0, 1669, 1662, 0, 0, 0, 0, 1666, 0, - 0, 0, 0, 1664, 0, 0, 0, 0, 0, 1667, - 1665, 0, 0, 0, 0, 1670, 1671, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1668, 0, 0, 0, - 1672, 1669, 0, 0, 0, 0, 0, 1666, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1667, 0, - 0, 0, 0, 0, 1670, 1671, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1668, 0, 0, 1673, 1672, - 1669, 1674, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1675, 0, 0, 1676, 0, - 0, 0, 0, 1670, 1671, 1667, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1673, 1672, 0, - 1674, 0, 1668, 0, 0, 0, 0, 1669, 0, 0, - 0, 0, 0, 0, 1675, 0, 0, 1676, 0, 0, - 0, 0, 0, 0, 1667, 0, 0, 0, 0, 0, - 1670, 1671, 0, 0, 0, 0, 1673, 0, 0, 1674, - 0, 1668, 0, 0, 0, 1672, 1669, 0, 0, 0, - 0, 0, 0, 1675, 0, 0, 1676, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1670, - 1671, 0, 0, 0, 0, 0, 0, 0, 1677, 0, - 0, 0, 0, 1673, 1672, 0, 1674, 0, 0, 0, + 0, 1656, 1657, 0, 0, 0, 0, 0, 1663, 0, + 0, 0, 0, 0, 0, 1659, 1658, 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1675, 0, 0, 1676, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1677, 0, 0, - 0, 0, 1673, 0, 0, 1674, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1675, - 0, 0, 1676, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1677, 0, 0, 0, + 0, 0, 1661, 0, 0, 1662, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1663, 0, 0, + 0, 0, 0, 0, 1659, 0, 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1661, 0, 0, 1662, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1663, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1678, 0, - 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, - 1687, 0, 0, 1677, 0, 2580, 0, 0, 0, 0, - 0, 0, 1653, 0, 0, 1654, 0, 0, 0, 1655, - 1656, 1657, 1658, 1659, 1660, 1661, 0, 1678, 0, 0, - 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, - 1662, 0, 1677, 0, 2601, 0, 0, 0, 0, 0, - 1664, 0, 0, 0, 0, 0, 0, 1665, 0, 0, - 0, 0, 0, 0, 0, 0, 1678, 0, 0, 1679, - 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, - 0, 0, 0, 2823, 1666, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1653, 0, - 0, 1654, 0, 0, 0, 1655, 1656, 1657, 1658, 1659, - 1660, 1661, 0, 1678, 0, 0, 1679, 1680, 1681, 0, - 1682, 1683, 1684, 1685, 1686, 1687, 1662, 0, 0, 0, - 2890, 0, 0, 0, 0, 0, 1664, 1653, 0, 0, - 1654, 0, 0, 1665, 1655, 1656, 1657, 1658, 1659, 1660, - 1661, 0, 1678, 0, 0, 1679, 1680, 1681, 0, 1682, - 1683, 1684, 1685, 1686, 1687, 1662, 0, 0, 0, 2904, - 1666, 0, 0, 0, 0, 1664, 1653, 0, 0, 1654, - 0, 1667, 1665, 1655, 1656, 1657, 1658, 1659, 1660, 1661, - 0, 0, 0, 0, 0, 0, 0, 0, 1668, 0, - 0, 0, 0, 1669, 1662, 0, 0, 0, 0, 1666, - 0, 0, 0, 0, 1664, 0, 0, 0, 0, 0, - 0, 1665, 0, 0, 0, 0, 1670, 1671, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1672, 0, 0, 0, 0, 0, 0, 1666, 0, + 0, 0, 0, 0, 0, 0, 1664, 0, 0, 1665, + 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, + 0, 0, 0, 2919, 1663, 0, 0, 0, 0, 0, + 1639, 0, 0, 1640, 0, 0, 0, 1641, 1642, 1643, + 1644, 1645, 1646, 1647, 0, 1664, 0, 0, 1665, 1666, + 1667, 0, 1668, 1669, 1670, 1671, 1672, 1673, 1648, 0, + 0, 0, 3156, 1663, 0, 0, 0, 0, 1650, 0, + 0, 0, 0, 0, 0, 1651, 0, 0, 0, 0, + 0, 0, 0, 0, 1664, 0, 0, 1665, 1666, 1667, + 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 0, 0, + 0, 3163, 1652, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1639, 0, 0, + 1640, 0, 0, 0, 1641, 1642, 1643, 1644, 1645, 1646, + 1647, 0, 1664, 0, 0, 1665, 1666, 1667, 0, 1668, + 1669, 1670, 1671, 1672, 1673, 1648, 0, 0, 0, 3325, + 0, 0, 0, 0, 0, 1650, 1639, 0, 0, 1640, + 0, 0, 1651, 1641, 1642, 1643, 1644, 1645, 1646, 1647, + 0, 1664, 0, 0, 1665, 1666, 1667, 0, 1668, 1669, + 1670, 1671, 1672, 1673, 1648, 0, 0, 0, 3347, 1652, + 0, 0, 0, 0, 1650, 1639, 0, 0, 1640, 1653, + 0, 1651, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, + 0, 0, 0, 0, 0, 0, 1654, 0, 0, 0, + 0, 1655, 0, 1648, 0, 0, 0, 0, 1652, 0, + 0, 0, 0, 1650, 0, 0, 0, 0, 0, 0, + 1651, 0, 0, 0, 1656, 1657, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1658, + 0, 0, 0, 0, 0, 0, 0, 1652, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1653, 0, 0, 1654, 0, 1667, 0, 1655, - 1656, 1657, 1658, 1659, 1660, 1661, 0, 0, 0, 1673, - 0, 0, 1674, 0, 1668, 0, 0, 0, 0, 1669, - 1662, 0, 0, 0, 0, 0, 1675, 0, 0, 1676, - 1664, 0, 0, 0, 0, 0, 1667, 1665, 0, 0, - 0, 0, 1670, 1671, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1668, 0, 0, 0, 1672, 1669, 0, - 0, 0, 0, 0, 1666, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1667, 0, 0, 0, 0, - 0, 1670, 1671, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1668, 0, 0, 1673, 1672, 1669, 1674, 0, + 0, 0, 1639, 0, 0, 1640, 1653, 0, 0, 1641, + 1642, 1643, 1644, 1645, 1646, 1647, 0, 1659, 0, 0, + 1660, 0, 0, 1654, 0, 0, 0, 0, 1655, 0, + 1648, 0, 0, 0, 1661, 0, 0, 1662, 0, 0, + 1650, 0, 0, 0, 0, 1653, 0, 1651, 0, 0, + 0, 1656, 1657, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1654, 0, 0, 0, 1658, 1655, 0, 0, + 0, 0, 0, 0, 1652, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1653, 0, 0, 0, 0, 0, + 1656, 1657, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1654, 0, 0, 1659, 1658, 1655, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1675, 0, 0, 1676, 0, 0, 0, 0, - 1670, 1671, 0, 0, 0, 0, 0, 0, 0, 1677, - 0, 0, 0, 0, 1673, 1672, 0, 1674, 0, 0, + 0, 1661, 0, 0, 1662, 0, 0, 0, 0, 1656, + 1657, 0, 0, 0, 0, 0, 1663, 0, 0, 0, + 0, 0, 0, 1659, 1658, 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1675, 0, 0, 1676, 0, 0, 0, 0, 0, - 0, 1667, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1673, 0, 0, 1674, 0, 1668, 0, - 0, 0, 0, 1669, 0, 0, 0, 0, 0, 0, - 1675, 0, 0, 1676, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1670, 1671, 0, 0, - 0, 0, 0, 0, 0, 1677, 0, 0, 0, 0, - 0, 1672, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1678, - 0, 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, - 1686, 1687, 0, 0, 1677, 0, 2975, 0, 0, 1673, - 0, 0, 1674, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1675, 0, 0, 1676, + 1661, 0, 0, 1662, 0, 0, 0, 0, 0, 0, + 0, 1653, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1659, 0, 0, 1660, 0, 0, 1654, 0, + 0, 0, 0, 1655, 0, 0, 0, 0, 0, 1661, + 0, 0, 1662, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1656, 1657, 0, 0, + 0, 0, 0, 1663, 0, 0, 0, 0, 0, 0, + 0, 1658, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1664, 0, 0, 1665, 1666, 1667, + 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 0, 0, + 0, 3447, 1663, 0, 0, 0, 0, 0, 0, 1659, + 0, 0, 1660, 0, 0, 0, 0, 0, 0, 0, + 1639, 0, 0, 1640, 0, 0, 1661, 1641, 1642, 1662, + 0, 1645, 1646, 1647, 0, 0, 0, 0, 0, 1639, + 0, 1663, 1640, 0, 0, 0, 1641, 1642, 1643, 1644, + 1645, 1646, 1647, 0, 0, 0, 0, 0, 1650, 0, + 0, 0, 0, 0, 0, 1651, 0, 1648, 0, 0, + 0, 1664, 0, 0, 1665, 1666, 1667, 1650, 1668, 1669, + 1670, 1671, 1672, 1673, 1651, 0, 0, 0, 3503, 0, + 0, 0, 1652, 0, 0, 0, 1639, 0, 0, 1640, + 0, 0, 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, + 1664, 1652, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, + 1671, 1672, 1673, 0, 1648, 0, 0, 3525, 1663, 0, + 0, 0, 0, 0, 1650, 0, 0, 0, 0, 0, + 0, 1651, 0, 0, 0, 0, 0, 0, 0, 1664, + 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, + 1672, 1673, 0, 0, 1827, 0, 0, 0, 1652, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1677, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1653, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1654, 0, 1653, 0, + 0, 1655, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1654, 0, 0, 0, 0, + 1655, 0, 0, 0, -2102, -2102, 1664, 0, 0, 1665, + 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, 1673, 1658, + 0, 2873, 0, 1656, 1657, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1653, 0, 0, 1658, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1678, 0, 0, 1679, 1680, - 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, - 0, 0, 3221, 0, 0, 0, 0, 0, 0, 1653, - 0, 0, 1654, 0, 0, 0, 1655, 1656, 1657, 1658, - 1659, 1660, 1661, 0, 1678, 0, 0, 1679, 1680, 1681, - 0, 1682, 1683, 1684, 1685, 1686, 1687, 1662, 0, 1677, - 0, 3228, 0, 0, 0, 0, 0, 1664, 1653, 0, - 0, 1654, 0, 0, 1665, 1655, 1656, 1657, 1658, 1659, - 1660, 1661, 0, 1678, 0, 0, 1679, 1680, 1681, 0, - 1682, 1683, 1684, 1685, 1686, 1687, 1662, 0, 0, 0, - 3395, 1666, 0, 0, 0, 0, 1664, 0, 0, 0, - 0, 0, 0, 1665, 0, 1653, 0, 0, 1654, 0, - 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, + 0, 0, 1654, 0, 0, 0, 0, 1655, 0, 0, + -2102, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1661, 0, 1659, 0, 0, 1660, + 1656, 1657, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1661, 0, 1658, 1662, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1666, 0, 0, 1662, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1664, 1653, 0, 0, 1654, 0, 0, - 1665, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, 1678, - 0, 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, - 1686, 1687, 1662, 0, 0, 0, 3419, 1666, 0, 0, - 0, 0, 1664, 1653, 0, 0, 1654, 0, 1667, 1665, - 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, 0, 0, - 0, 0, 0, 0, 0, 1668, 0, 0, 0, 0, - 1669, 1662, 0, 0, 0, 0, 1666, 0, 0, 0, - 0, 1664, 0, 0, 0, 0, 0, 1667, 1665, 0, - 0, 0, 0, 1670, 1671, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1668, 0, 0, 0, 1672, 1669, - 0, 0, 0, 0, 0, 1666, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1670, 1671, 1667, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1673, 1672, 0, 1674, - 0, 1668, 0, 0, 0, 0, 1669, 0, 0, 0, - 0, 0, 0, 1675, 0, 0, 1676, 0, 0, 0, - 0, 0, 0, 1667, 0, 0, 0, 0, 0, 1670, - 1671, 0, 0, 0, 0, 1673, 0, 0, 1674, 0, - 1668, 0, 0, 0, 1672, 1669, 0, 0, 0, 0, - 0, 0, 1675, 0, 0, 1676, 0, 0, 0, 0, - 0, 0, 1667, 0, 0, 0, 0, 0, 1670, 1671, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1668, - 0, 0, 1673, 1672, 1669, 1674, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1675, - 0, 0, 1676, 0, 0, 0, 0, 1670, 1671, 0, - 0, 0, 0, 0, 0, 0, 1677, 0, 0, 0, - 0, 1673, 1672, 0, 1674, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 1675, 0, - 0, 1676, 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1677, 0, 0, 0, 0, - 1673, 0, 0, 1674, 0, 6, 0, 0, 0, 0, - 0, 0, 0, 0, 7, 0, 0, 1675, 0, 0, - 1676, 0, 0, 0, 0, 0, 0, 0, 8, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, - 0, 0, 1677, 0, 0, 0, 0, 0, 0, 0, - 0, 11, 0, 756, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 13, 0, 1678, 0, 0, 1679, - 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 14, - 15, 1677, 0, 3519, 0, 0, 0, 0, 0, 0, - 757, 0, 0, 0, 0, 0, 18, 0, 0, 0, - 0, 0, 0, 0, 19, 1678, 0, 0, 1679, 1680, - 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, - 1677, 22, 3575, 0, 0, 23, 0, 0, 0, 0, - 0, 727, 0, 0, 0, 0, 0, 1653, 0, 0, - 1654, 0, 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, - 1661, 0, 1678, 0, 0, 1679, 1680, 1681, 0, 1682, - 1683, 1684, 1685, 1686, 1687, 1662, 0, -1497, 0, 3597, - 0, 0, 0, 0, 0, 1664, 0, 0, 0, 0, - 0, 0, 1665, 0, 0, 0, 0, 0, 728, 0, - 0, 1678, 0, 25, 1679, 1680, 1681, 0, 1682, 1683, - 1684, 1685, 1686, 1687, 729, 0, 2925, 0, 0, 1666, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1659, 0, 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1678, 0, 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, - 1685, 1686, 1687, 0, 0, 3385, 0, 0, 0, 0, - 0, 0, 0, 730, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 731, 0, 0, 0, 0, 0, 26, - 27, 28, 0, 0, 0, 0, 732, 29, 0, 0, - 30, 733, 0, 0, 0, 0, 0, 0, 0, 0, + 1661, 0, 0, 1662, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1667, 0, 0, 0, - 734, 31, 0, 0, 0, 0, 0, 0, 0, 0, - 32, 0, 0, 1668, 0, 0, 0, 0, 1669, 0, - 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, - 0, 0, 0, 34, 0, 0, 0, 35, 0, 0, - 0, 1670, 1671, 735, 0, 0, 0, 736, 36, 0, - 0, 0, 0, 0, 0, 0, 1672, 0, 0, 0, - 37, 0, 0, 0, 38, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1663, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1673, 0, 0, 1674, 40, 0, - 0, 0, 0, 0, 42, 0, 0, 0, 0, 43, - 0, 1675, 548, 0, 1676, 0, 0, 0, 737, 0, - 0, 0, 0, 0, 0, 0, 44, 0, 0, 0, - 0, 0, 0, 738, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1663, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 46, 0, 0, 0, 739, 0, - 0, 740, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 741, 0, 0, 742, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 743, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1677, 0, 0, 0, 744, 0, - 0, 0, 0, 0, 745, 746, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 747, 0, 0, 0, 0, - 0, 748, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 749, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1663, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1664, 0, 0, 1665, 1666, 1667, + 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 0, 0, + 0, 0, 0, 1664, 0, 0, 1665, 1666, 1667, 0, + 1668, 1669, 1670, 1671, 1672, 1673, 0, 0, 3315, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 564, 0, 0, 1678, 0, 0, 1679, 1680, 1681, - 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, 3559, - 119, 120, 121, 122, 123, 124, 125, 126, 565, 127, - 128, 129, 566, 567, 568, 569, 570, 571, 572, 573, - 574, 131, 132, 575, 576, 134, 135, 577, 137, 138, - 139, 578, 579, 580, 581, 582, 583, 145, 146, 147, - 148, 149, 150, 584, 585, 151, 152, 153, 154, 586, - 587, 157, 588, 158, 159, 160, 161, 589, 590, 591, - 592, 593, 165, 166, 167, 168, 169, 594, 171, 172, - 173, 595, 174, 175, 176, 177, 178, 179, 596, 597, - 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, - 599, 192, 193, 600, 195, 601, 196, 602, 197, 198, - 199, 200, 201, 202, 603, 604, 203, 204, 205, 206, - 605, 606, 207, 208, 209, 210, 211, 607, 212, 213, - 214, 608, 215, 216, 217, 609, 218, 219, 220, 221, - 610, 223, 224, 225, 226, 227, 228, 611, 612, 230, - 613, 231, 232, 614, 234, 615, 235, 616, 236, 617, - 618, 619, 239, 240, 620, 621, 243, 244, 245, 622, - 623, 624, 248, 249, 625, 250, 251, 252, 253, 254, - 255, 256, 626, 258, 259, 260, 261, 627, 262, 263, - 264, 265, 266, 267, 268, 628, 269, 629, 630, 272, - 273, 274, 275, 276, 631, 632, 633, 634, 635, 280, - 636, 637, 283, 638, 285, 286, 287, 288, 289, 290, - 639, 640, 291, 641, 293, 642, 643, 295, 296, 297, - 298, 299, 300, 301, 302, 644, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, - 318, 319, 320, 321, 322, 323, 645, 646, 647, 327, - 328, 329, 648, 649, 331, 332, 650, 334, 651, 652, - 336, 653, 338, 339, 340, 654, 341, 342, 655, 656, - 343, 344, 345, 657, 658, 346, 347, 659, 660, 350, - 661, 662, 353, 354, 355, 356, 357, 358, 359, 360, - 361, 362, 363, 364, 663, 664, 665, 666, 365, 366, - 667, 668, 369, 370, 669, 372, 373, 374, 670, 375, - 376, 377, 378, 379, 380, 671, 381, 382, 383, 384, - 385, 672, 387, 388, 389, 390, 673, 391, 392, 393, - 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, - 674, 404, 405, 675, 407, 408, 409, 676, 411, 412, - 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, - 423, 677, 678, 424, 425, 426, 427, 428, 429, 679, - 431, 432, 680, 681, 434, 435, 682, 437, 683, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - 449, 450, 684, 452, 685, 686, 687, 454, 455, 688, - 456, 689, 458, 459, 460, 461, 462, 690, 463, 691, - 692, 693, 694, 466, 467, 695, 469, 696, 697, 471, - 472, 698, 474, 475, 476, 477, 478, 699, 700, 479, - 480, 481, 701, 702, 482, 483, 484, 485, 703, 486, - 487, 488, 489, 490, 704, 705, 493, 706, 494, 707, - 496, 497, 498, 499, 500, 501, 502, 708, 709, 503, - 710, 711, 504, 505, 506, 507, 508, 509, 712, 713, - 714, 715, 716, 717, 718, 719, 720, 721, 722, 521, - 522, 523, 524, 532, 0, 0, 0, 0, 0, 0, - 0, 0, 2140, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 119, 120, 121, 122, 123, 124, 125, 126, - 0, 127, 128, 129, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 131, 132, 0, 0, 134, 135, 0, - 137, 138, 139, 140, 141, 0, 143, 144, 0, 145, - 146, 147, 148, 149, 150, 0, 0, 151, 152, 153, - 154, 155, 156, 157, 0, 158, 159, 160, 161, 162, - 0, 0, 0, 164, 165, 166, 167, 168, 169, 0, - 171, 172, 173, 0, 174, 175, 176, 177, 178, 179, - 0, 0, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 0, 196, 0, - 197, 198, 199, 200, 201, 202, 0, 0, 203, 204, - 205, 206, 0, 0, 207, 208, 209, 210, 211, 0, - 212, 213, 214, 0, 215, 216, 217, 0, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, - 0, 230, 0, 231, 232, 233, 234, 0, 235, 0, - 236, 0, 0, 0, 239, 240, 533, 0, 243, 244, - 245, 0, 246, 247, 248, 249, 0, 250, 251, 252, - 253, 254, 255, 256, 0, 258, 259, 260, 261, 0, - 262, 263, 264, 265, 266, 267, 268, 0, 269, 0, - 271, 272, 273, 274, 275, 276, 277, 278, 0, 279, - 0, 280, 0, 0, 283, 0, 285, 286, 287, 288, - 289, 290, 0, 0, 291, 0, 293, 0, 0, 295, - 296, 297, 298, 299, 300, 301, 302, 534, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 322, 323, 324, 0, - 326, 327, 328, 329, 330, 0, 331, 332, 0, 334, - 0, 335, 336, 337, 338, 339, 340, 0, 341, 342, - 0, 0, 343, 344, 345, 0, 0, 346, 347, 348, - 0, 350, 0, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, 362, 363, 364, 0, 0, 0, 0, - 365, 366, 367, 0, 369, 370, 371, 372, 373, 374, - 0, 375, 376, 377, 378, 379, 380, 0, 381, 382, - 383, 384, 385, 386, 387, 388, 389, 390, 0, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 0, 404, 405, 0, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, - 421, 422, 423, 0, 0, 424, 425, 426, 427, 428, - 429, 430, 431, 432, 0, 0, 434, 435, 436, 437, - 0, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, 449, 450, 535, 452, 453, 0, 0, 454, - 455, 0, 456, 0, 458, 459, 460, 461, 462, 0, - 463, 464, 465, 0, 0, 466, 467, 468, 469, 470, - 0, 471, 472, 473, 474, 475, 476, 477, 478, 0, - 0, 479, 480, 481, 0, 0, 482, 483, 484, 485, - 0, 486, 487, 488, 489, 490, 491, 492, 493, 0, - 494, 0, 496, 497, 498, 499, 500, 501, 502, 0, - 0, 503, 0, 0, 504, 505, 506, 507, 508, 509, - 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, - 520, 521, 522, 523, 524, 532, 0, 0, 0, 0, - 0, 0, 0, 0, 2816, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 119, 120, 121, 122, 123, 124, - 125, 126, 0, 127, 128, 129, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 131, 132, 0, 0, 134, - 135, 0, 137, 138, 139, 140, 141, 0, 143, 144, - 0, 145, 146, 147, 148, 149, 150, 0, 0, 151, - 152, 153, 154, 155, 156, 157, 0, 158, 159, 160, - 161, 162, 0, 0, 0, 164, 165, 166, 167, 168, - 169, 0, 171, 172, 173, 0, 174, 175, 176, 177, - 178, 179, 0, 0, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 0, - 196, 0, 197, 198, 199, 200, 201, 202, 0, 0, - 203, 204, 205, 206, 0, 0, 207, 208, 209, 210, - 211, 0, 212, 213, 214, 0, 215, 216, 217, 0, - 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 0, 230, 0, 231, 232, 233, 234, 0, - 235, 0, 236, 0, 0, 0, 239, 240, 533, 0, - 243, 244, 245, 0, 246, 247, 248, 249, 0, 250, - 251, 252, 253, 254, 255, 256, 0, 258, 259, 260, - 261, 0, 262, 263, 264, 265, 266, 267, 268, 0, - 269, 0, 271, 272, 273, 274, 275, 276, 277, 278, - 0, 279, 0, 280, 0, 0, 283, 0, 285, 286, - 287, 288, 289, 290, 0, 0, 291, 0, 293, 0, - 0, 295, 296, 297, 298, 299, 300, 301, 302, 534, - 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 324, 0, 326, 327, 328, 329, 330, 0, 331, 332, - 0, 334, 0, 335, 336, 337, 338, 339, 340, 0, - 341, 342, 0, 0, 343, 344, 345, 0, 0, 346, - 347, 348, 0, 350, 0, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, 362, 363, 364, 0, 0, - 0, 0, 365, 366, 367, 0, 369, 370, 371, 372, - 373, 374, 0, 375, 376, 377, 378, 379, 380, 0, - 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, - 0, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 0, 404, 405, 0, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, - 419, 420, 421, 422, 423, 0, 0, 424, 425, 426, - 427, 428, 429, 430, 431, 432, 0, 0, 434, 435, - 436, 437, 0, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, 449, 450, 535, 452, 453, 0, - 0, 454, 455, 0, 456, 0, 458, 459, 460, 461, - 462, 0, 463, 464, 465, 0, 0, 466, 467, 468, - 469, 470, 0, 471, 472, 473, 474, 475, 476, 477, - 478, 0, 0, 479, 480, 481, 0, 0, 482, 483, - 484, 485, 0, 486, 487, 488, 489, 490, 491, 492, - 493, 0, 494, 0, 496, 497, 498, 499, 500, 501, - 502, 0, 0, 503, 0, 0, 504, 505, 506, 507, - 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, - 518, 519, 520, 521, 522, 523, 524, 980, 1374, 826, - 0, 0, 0, 1066, 0, 0, 2819, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 119, 120, 121, 122, - 123, 124, 125, 126, 0, 127, 128, 129, 0, 0, - 0, 569, 0, 0, 0, 0, 574, 131, 132, 0, - 576, 134, 135, 577, 137, 138, 139, 578, 579, 580, - 581, 582, 0, 145, 146, 147, 148, 149, 150, 0, - 0, 151, 152, 153, 154, 586, 587, 157, 0, 158, - 159, 160, 161, 589, 0, 591, 0, 593, 165, 166, - 167, 168, 169, 594, 171, 172, 173, 0, 174, 175, - 176, 177, 178, 179, 0, 597, 181, 182, 183, 184, - 185, 186, 187, 188, 189, 190, 599, 192, 193, 600, - 195, 0, 196, 0, 197, 198, 199, 200, 201, 202, - 0, 0, 203, 204, 205, 206, 0, 0, 207, 208, - 209, 210, 211, 0, 212, 213, 214, 0, 215, 216, - 217, 0, 218, 219, 220, 221, 610, 223, 224, 225, - 226, 227, 228, 611, 1375, 230, 0, 231, 232, 614, - 234, 0, 235, 0, 236, 617, 0, 619, 239, 240, - 620, 621, 243, 244, 245, 0, 623, 624, 248, 249, - 0, 250, 251, 252, 253, 254, 255, 256, 626, 258, - 259, 260, 261, 0, 262, 263, 264, 265, 266, 267, - 268, 0, 269, 629, 630, 272, 273, 274, 275, 276, - 631, 632, 0, 634, 0, 280, 636, 637, 283, 638, - 285, 286, 287, 288, 289, 290, 0, 0, 291, 641, - 293, 642, 0, 295, 296, 297, 298, 299, 300, 301, - 302, 644, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 645, 646, 647, 327, 328, 329, 648, 0, - 331, 332, 650, 334, 0, 652, 336, 653, 338, 339, - 340, 0, 341, 342, 1376, 0, 343, 344, 345, 0, - 0, 346, 347, 659, 660, 350, 661, 662, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 0, 0, 0, 0, 365, 366, 667, 668, 369, 370, - 669, 372, 373, 374, 0, 375, 376, 377, 378, 379, - 380, 0, 381, 382, 383, 384, 385, 672, 387, 388, - 389, 390, 0, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 0, 404, 405, 675, - 407, 408, 409, 676, 411, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 0, 678, 424, - 425, 426, 427, 428, 429, 679, 431, 432, 0, 681, - 434, 435, 682, 437, 0, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 684, 452, - 685, 0, 0, 454, 455, 0, 456, 689, 458, 459, - 460, 461, 462, 0, 463, 691, 692, 0, 0, 466, - 467, 695, 469, 696, 1377, 471, 472, 698, 474, 475, - 476, 477, 478, 0, 0, 479, 480, 481, 701, 0, - 482, 483, 484, 485, 0, 486, 487, 488, 489, 490, - 704, 705, 493, 0, 494, 707, 496, 497, 498, 499, - 500, 501, 502, 0, 0, 503, 0, 0, 504, 505, - 506, 507, 508, 509, 712, 713, 714, 715, 716, 717, - 718, 719, 720, 721, 722, 521, 522, 523, 524, 0, - 0, 1653, 0, 0, 1654, 0, 1378, 1379, 1655, 1656, - 1657, 1658, 1659, 1660, 1661, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1662, - 0, 0, 0, 0, 2240, 0, 0, 0, 0, 1664, - 1653, 0, 0, 1654, 0, 0, 1665, 1655, 1656, 1657, - 1658, 1659, 1660, 1661, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1662, 0, - 0, 0, 0, 1666, 0, 0, 0, 0, 1664, 1653, - 0, 0, 1654, 0, 0, 1665, 1655, 1656, 1657, 1658, - 1659, 1660, 1661, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1662, 0, 0, - 0, 0, 1666, 0, 0, 0, 0, 1664, 0, 2241, - 0, 0, 0, 0, 1665, 0, 0, 0, 1653, 0, - 0, 1654, 0, 0, 0, 1655, 1656, 1657, 1658, 1659, - 1660, 1661, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1666, 0, 0, 0, 0, 1662, 0, 0, 0, - 1950, 0, 0, 0, 0, 0, 1664, 0, 1653, 0, - 1667, 1654, 0, 1665, 0, 1655, 1656, 1657, 1658, 1659, - 1660, 1661, 0, 0, 0, 0, 0, 1668, 0, 0, - 0, 0, 1669, 0, 0, 0, 1662, 0, 0, 1986, - 1666, 0, 0, 0, 1987, 0, 1664, 0, 0, 1667, - 0, 0, 0, 1665, 0, 1670, 1671, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1668, 0, 0, 0, - 1672, 1669, 0, 0, 0, 0, 0, 3665, 0, 0, - 1666, 0, 0, 0, 0, 0, 0, 0, 1667, 0, - 0, 0, 0, 0, 1670, 1671, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1668, 0, 0, 1673, 1672, - 1669, 1674, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1675, 0, 0, 1676, 0, - 0, 0, 0, 1670, 1671, 0, 0, 1667, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1673, 1672, 0, - 1674, 0, 0, 0, 1668, 0, 0, 0, 0, 1669, - 0, 0, 0, 0, 1675, 0, 0, 1676, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1667, 0, 0, - 0, 0, 1670, 1671, 0, 0, 1673, 0, 0, 1674, - 0, 0, 0, 0, 1668, 0, 0, 1672, 0, 1669, - 0, 0, 0, 1675, 0, 0, 1676, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1670, 1671, 0, 0, 0, 0, 1677, 0, - 0, 0, 0, 0, 0, 1673, 3666, 1672, 1674, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1675, 0, 0, 1676, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1677, 0, 0, - 0, 0, 0, 0, 0, 1673, 0, 0, 1674, 0, + 0, 0, 0, 0, 0, 0, 0, 560, 0, 0, + 1664, 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, + 1671, 1672, 1673, 0, 0, 3487, 118, 119, 120, 121, + 122, 123, 124, 125, 561, 126, 127, 128, 562, 563, + 564, 565, 566, 567, 568, 569, 570, 130, 131, 571, + 132, 133, 134, 572, 136, 137, 138, 573, 574, 575, + 576, 577, 578, 144, 145, 146, 147, 148, 149, 579, + 580, 150, 151, 152, 153, 581, 582, 156, 583, 157, + 158, 159, 160, 584, 585, 586, 587, 588, 164, 165, + 166, 167, 168, 589, 170, 171, 172, 590, 173, 174, + 175, 176, 177, 178, 591, 592, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 594, 191, 192, 595, + 194, 596, 195, 597, 196, 197, 198, 199, 200, 201, + 598, 599, 202, 203, 204, 205, 600, 601, 206, 207, + 208, 209, 210, 602, 211, 212, 213, 603, 214, 215, + 216, 604, 217, 218, 219, 220, 605, 222, 223, 224, + 225, 226, 227, 606, 607, 229, 608, 230, 231, 609, + 233, 610, 234, 611, 235, 612, 613, 614, 238, 239, + 615, 616, 242, 617, 243, 618, 619, 620, 246, 247, + 621, 248, 249, 250, 251, 252, 253, 254, 622, 256, + 257, 258, 259, 623, 260, 261, 262, 263, 264, 265, + 266, 624, 267, 625, 626, 270, 271, 272, 273, 274, + 627, 628, 629, 630, 631, 278, 632, 633, 281, 634, + 283, 284, 285, 286, 287, 288, 635, 636, 289, 637, + 291, 638, 639, 293, 294, 295, 296, 297, 298, 299, + 300, 640, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 641, 642, 643, 325, 326, 327, 644, 645, + 329, 330, 646, 332, 647, 648, 334, 649, 336, 337, + 338, 650, 339, 340, 651, 652, 341, 342, 343, 653, + 654, 344, 345, 655, 656, 348, 657, 658, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 659, + 660, 661, 662, 362, 363, 663, 664, 366, 367, 665, + 369, 370, 371, 666, 372, 373, 374, 375, 376, 377, + 667, 378, 379, 380, 381, 382, 668, 384, 385, 386, + 387, 669, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 670, 401, 402, 671, 404, + 405, 406, 672, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 673, 674, 421, 422, + 423, 424, 425, 426, 675, 428, 429, 676, 677, 431, + 432, 678, 434, 679, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 680, 448, 681, 682, + 683, 450, 451, 684, 452, 685, 454, 455, 456, 457, + 458, 686, 459, 687, 688, 689, 690, 462, 463, 691, + 465, 692, 693, 467, 468, 694, 470, 471, 472, 473, + 474, 695, 696, 475, 476, 477, 697, 478, 479, 480, + 481, 698, 482, 483, 484, 485, 486, 699, 700, 489, + 701, 490, 702, 492, 493, 494, 495, 496, 497, 498, + 703, 704, 499, 705, 706, 500, 501, 502, 503, 504, + 505, 707, 708, 709, 710, 711, 712, 713, 714, 715, + 716, 717, 517, 518, 519, 520, 528, 0, 0, 0, + 0, 0, 0, 0, 0, 2115, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 118, 119, 120, 121, 122, + 123, 124, 125, 0, 126, 127, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 130, 131, 0, 132, + 133, 134, 0, 136, 137, 138, 139, 140, 0, 142, + 143, 0, 144, 145, 146, 147, 148, 149, 0, 0, + 150, 151, 152, 153, 154, 155, 156, 0, 157, 158, + 159, 160, 161, 0, 0, 0, 163, 164, 165, 166, + 167, 168, 0, 170, 171, 172, 0, 173, 174, 175, + 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 0, 195, 0, 196, 197, 198, 199, 200, 201, 0, + 0, 202, 203, 204, 205, 0, 0, 206, 207, 208, + 209, 210, 0, 211, 212, 213, 0, 214, 215, 216, + 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, + 226, 227, 228, 0, 229, 0, 230, 231, 232, 233, + 0, 234, 0, 235, 0, 0, 0, 238, 239, 529, + 0, 242, 0, 243, 0, 244, 245, 246, 247, 0, + 248, 249, 250, 251, 252, 253, 254, 0, 256, 257, + 258, 259, 0, 260, 261, 262, 263, 264, 265, 266, + 0, 267, 0, 269, 270, 271, 272, 273, 274, 275, + 276, 0, 277, 0, 278, 0, 0, 281, 0, 283, + 284, 285, 286, 287, 288, 0, 0, 289, 0, 291, + 0, 0, 293, 294, 295, 296, 297, 298, 299, 300, + 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, + 321, 322, 0, 324, 325, 326, 327, 328, 0, 329, + 330, 0, 332, 0, 333, 334, 335, 336, 337, 338, + 0, 339, 340, 0, 0, 341, 342, 343, 0, 0, + 344, 345, 346, 0, 348, 0, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, 361, 0, 0, + 0, 0, 362, 363, 364, 0, 366, 367, 368, 369, + 370, 371, 0, 372, 373, 374, 375, 376, 377, 0, + 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, + 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, + 397, 398, 399, 400, 0, 401, 402, 0, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + 416, 417, 418, 419, 420, 0, 0, 421, 422, 423, + 424, 425, 426, 427, 428, 429, 0, 0, 431, 432, + 433, 434, 0, 435, 436, 437, 438, 439, 440, 441, + 442, 443, 444, 445, 446, 531, 448, 449, 0, 0, + 450, 451, 0, 452, 0, 454, 455, 456, 457, 458, + 0, 459, 460, 461, 0, 0, 462, 463, 464, 465, + 466, 0, 467, 468, 469, 470, 471, 472, 473, 474, + 0, 0, 475, 476, 477, 0, 478, 479, 480, 481, + 0, 482, 483, 484, 485, 486, 487, 488, 489, 0, + 490, 0, 492, 493, 494, 495, 496, 497, 498, 0, + 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, + 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, + 516, 517, 518, 519, 520, 528, 0, 0, 0, 0, + 0, 0, 0, 0, 2766, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 130, 131, 0, 132, 133, + 134, 0, 136, 137, 138, 139, 140, 0, 142, 143, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 154, 155, 156, 0, 157, 158, 159, + 160, 161, 0, 0, 0, 163, 164, 165, 166, 167, + 168, 0, 170, 171, 172, 0, 173, 174, 175, 176, + 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 208, 209, + 210, 0, 211, 212, 213, 0, 214, 215, 216, 0, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 0, 229, 0, 230, 231, 232, 233, 0, + 234, 0, 235, 0, 0, 0, 238, 239, 529, 0, + 242, 0, 243, 0, 244, 245, 246, 247, 0, 248, + 249, 250, 251, 252, 253, 254, 0, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 0, 269, 270, 271, 272, 273, 274, 275, 276, + 0, 277, 0, 278, 0, 0, 281, 0, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 0, 291, 0, + 0, 293, 294, 295, 296, 297, 298, 299, 300, 530, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, + 322, 0, 324, 325, 326, 327, 328, 0, 329, 330, + 0, 332, 0, 333, 334, 335, 336, 337, 338, 0, + 339, 340, 0, 0, 341, 342, 343, 0, 0, 344, + 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 364, 0, 366, 367, 368, 369, 370, + 371, 0, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 0, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, + 417, 418, 419, 420, 0, 0, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 0, 0, 431, 432, 433, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 531, 448, 449, 0, 0, 450, + 451, 0, 452, 0, 454, 455, 456, 457, 458, 0, + 459, 460, 461, 0, 0, 462, 463, 464, 465, 466, + 0, 467, 468, 469, 470, 471, 472, 473, 474, 0, + 0, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 487, 488, 489, 0, 490, + 0, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, + 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, + 517, 518, 519, 520, 974, 1364, 821, 0, 0, 0, + 1060, 0, 0, 2769, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 118, 119, 120, 121, 122, 123, 124, + 125, 0, 126, 127, 128, 0, 0, 0, 565, 0, + 0, 0, 0, 570, 130, 131, 0, 132, 133, 134, + 572, 136, 137, 138, 573, 574, 575, 576, 577, 0, + 144, 145, 146, 147, 148, 149, 0, 0, 150, 151, + 152, 153, 581, 582, 156, 0, 157, 158, 159, 160, + 584, 0, 586, 0, 588, 164, 165, 166, 167, 168, + 589, 170, 171, 172, 0, 173, 174, 175, 176, 177, + 178, 0, 592, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 594, 191, 192, 595, 194, 0, 195, + 0, 196, 197, 198, 199, 200, 201, 0, 0, 202, + 203, 204, 205, 0, 0, 206, 207, 208, 209, 210, + 0, 211, 212, 213, 0, 214, 215, 216, 0, 217, + 218, 219, 220, 605, 222, 223, 224, 225, 226, 227, + 606, 1365, 229, 0, 230, 231, 609, 233, 0, 234, + 0, 235, 612, 0, 614, 238, 239, 615, 616, 242, + 0, 243, 0, 619, 620, 246, 247, 0, 248, 249, + 250, 251, 252, 253, 254, 622, 256, 257, 258, 259, + 0, 260, 261, 262, 263, 264, 265, 266, 0, 267, + 625, 626, 270, 271, 272, 273, 274, 627, 628, 0, + 630, 0, 278, 632, 633, 281, 634, 283, 284, 285, + 286, 287, 288, 0, 0, 289, 637, 291, 638, 0, + 293, 294, 295, 296, 297, 298, 299, 300, 640, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, 321, 641, + 642, 643, 325, 326, 327, 644, 0, 329, 330, 646, + 332, 0, 648, 334, 649, 336, 337, 338, 0, 339, + 340, 1366, 0, 341, 342, 343, 0, 0, 344, 345, + 655, 656, 348, 657, 658, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 0, 0, 0, 0, + 362, 363, 663, 664, 366, 367, 665, 369, 370, 371, + 0, 372, 373, 374, 375, 376, 377, 0, 378, 379, + 380, 381, 382, 668, 384, 385, 386, 387, 0, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 0, 401, 402, 671, 404, 405, 406, 672, + 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, + 418, 419, 420, 0, 674, 421, 422, 423, 424, 425, + 426, 675, 428, 429, 0, 677, 431, 432, 678, 434, + 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 680, 448, 681, 0, 0, 450, 451, + 0, 452, 685, 454, 455, 456, 457, 458, 0, 459, + 687, 688, 0, 0, 462, 463, 691, 465, 692, 1367, + 467, 468, 694, 470, 471, 472, 473, 474, 0, 0, + 475, 476, 477, 0, 478, 479, 480, 481, 0, 482, + 483, 484, 485, 486, 699, 700, 489, 0, 490, 702, + 492, 493, 494, 495, 496, 497, 498, 0, 0, 499, + 0, 0, 500, 501, 502, 503, 504, 505, 707, 708, + 709, 710, 711, 712, 713, 714, 715, 716, 717, 517, + 518, 519, 520, 0, 0, 1639, 0, 0, 1640, 0, + 1368, 1369, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1648, 0, 0, 0, 0, 2216, 0, + 0, 0, 0, 1650, 1639, 0, 0, 1640, 0, 0, + 1651, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1675, 2244, 0, 1676, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1677, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1957, + 0, 0, 1648, 0, 0, 0, 0, 1652, 0, 0, + 0, 0, 1650, 1639, 0, 0, 1640, 0, 0, 1651, + 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1678, 0, - 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, - 1687, 0, 0, 0, 0, 1677, 0, 0, 0, 0, - 0, 0, 1653, 0, 0, 1654, 0, 0, 0, 1655, - 1656, 1657, 1658, 1659, 1660, 1661, 0, 1678, 0, 0, - 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, - 1662, 0, 0, 0, 1992, 1677, 0, 0, 0, 0, - 1664, 0, 0, 0, 0, 0, 0, 1665, 0, 0, - 0, 0, 0, 0, 0, 0, 1678, 0, 0, 1679, - 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, - 0, 0, 0, 0, 1666, 0, 0, 0, 0, 0, + 0, 1648, 0, 0, 0, 0, 1652, 0, 0, 0, + 0, 1650, 0, 2217, 0, 0, 0, 0, 1651, 0, + 1639, 0, 0, 1640, 0, 0, 0, 1641, 1642, 1643, + 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1652, 0, 0, 1648, 0, + 0, 0, 1929, 0, 0, 0, 0, 0, 1650, 0, + 0, 0, 0, 0, 1653, 1651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1653, 0, 0, 1654, 0, 0, 0, 1655, 1656, 1657, - 1658, 1659, 1660, 1661, 0, 1678, 0, 0, 1679, 1680, - 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 1662, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1664, 0, - 0, 0, 0, 0, 0, 1665, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1678, 0, 0, 1679, 1680, - 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, - 0, 0, 1666, 0, 0, 0, 0, 1653, 0, 0, - 1654, 1667, 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, - 1661, 0, 0, 0, 0, 0, 0, 0, 1668, 0, - 0, 0, 0, 1669, 0, 1662, 0, 0, 0, 1999, - 0, 0, 0, 0, 0, 1664, 0, 0, 0, 0, - 0, 0, 1665, 0, 0, 0, 1670, 1671, 0, 0, + 0, 1654, 0, 0, 0, 0, 1655, 0, 0, 0, + 0, 0, 1652, 1965, 0, 0, 0, 0, 1966, 0, + 0, 0, 0, 1653, 0, 0, 0, 0, 0, 1656, + 1657, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1654, 0, 0, 0, 1658, 1655, 0, 0, 0, 0, + 0, 3593, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1653, 0, 0, 0, 0, 0, 1656, 1657, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1654, + 0, 0, 1659, 1658, 1655, 1660, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1661, + 0, 0, 1662, 0, 0, 0, 0, 1656, 1657, 1653, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1672, 0, 0, 0, 0, 0, 0, 0, 1666, + 0, 1659, 1658, 0, 1660, 0, 1654, 0, 0, 0, + 0, 1655, 0, 0, 0, 0, 0, 0, 1661, 0, + 0, 1662, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1656, 1657, 0, 0, 0, 0, + 1659, 0, 0, 1660, 0, 0, 0, 0, 0, 1658, + 0, 0, 0, 0, 0, 0, 0, 1661, 0, 0, + 1662, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1997, 1653, 0, 0, 1654, 1667, - 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 1673, - 0, 0, 1674, 0, 0, 0, 1668, 0, 0, 0, - 0, 1669, 0, 1662, 0, 0, 1675, 0, 0, 1676, - 0, 0, 0, 1664, 0, 0, 0, 0, 0, 0, - 1665, 0, 0, 0, 1670, 1671, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1672, - 0, 0, 0, 0, 0, 0, 0, 1666, 0, 0, - 0, 0, 0, 0, 0, 0, 1667, 0, 0, 0, + 0, 1663, 0, 0, 0, 0, 0, 1659, 0, 3594, + 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1661, 0, 0, 1662, 0, 0, + 0, 0, 0, 0, 0, 1639, 0, 0, 1640, 0, + 1663, 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1668, 0, 0, 0, 1673, 1669, 1653, - 1674, 0, 1654, 0, 0, 0, 1655, 1656, 1657, 1658, - 1659, 1660, 1661, 0, 1675, 0, 0, 1676, 0, 0, - 0, 1670, 1671, 0, 0, 0, 0, 1662, 0, 1677, - 0, 0, 0, 0, 0, 0, 1672, 1664, 0, 0, - 0, 0, 0, 0, 1665, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 2133, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1667, 0, 0, 0, 0, 0, - 0, 1666, 0, 0, 1673, 0, 0, 1674, 0, 0, - 0, 1668, 0, 0, 0, 0, 1669, 0, 0, 0, - 0, 1675, 0, 0, 1676, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1670, - 1671, 0, 0, 0, 0, 0, 0, 1677, 0, 0, - 0, 0, 0, 0, 1672, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1678, - 0, 0, 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, - 1686, 1687, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1673, 0, 0, 1674, 0, 0, 1667, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1675, - 0, 0, 1676, 0, 0, 1668, 0, 0, 0, 0, - 1669, 0, 0, 0, 1677, 0, 0, 0, 0, 0, + 0, 0, 0, 1648, 2220, 0, 0, 0, 0, 0, + 0, 0, 0, 1650, 0, 0, 0, 0, 0, 1663, + 1651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1670, 1671, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1678, 1672, 0, - 1679, 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, - 0, 0, 0, 0, 0, 0, 1653, 0, 0, 1654, - 0, 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, - 0, 0, 0, 0, 0, 0, 1673, 0, 0, 1674, - 0, 0, 0, 0, 1662, 0, 0, 0, 2898, 0, - 0, 0, 1677, 1675, 1664, 0, 1676, 0, 0, 0, - 0, 1665, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1678, 0, 0, 1679, 1680, 1681, - 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, 1666, 0, - 0, 0, 0, 0, 0, 0, 1653, 0, 0, 1654, - 0, 0, 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, + 0, 0, 0, 0, 0, 0, 0, 1652, 0, 1664, + 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, + 1672, 1673, 0, 0, 0, 0, 1663, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1662, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1664, 0, 0, 0, 0, 0, - 0, 1665, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1677, 0, 0, 0, - 0, 0, 1678, 0, 0, 1679, 1680, 1681, 1666, 1682, - 1683, 1684, 1685, 1686, 1687, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1653, 1667, 0, 1654, 0, 0, - 2882, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, 0, - 0, 0, 1668, 0, 0, 0, 0, 1669, 0, 0, - 0, 0, 1662, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1664, 0, 0, 0, 0, 0, 0, 1665, - 1670, 1671, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1672, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1666, 0, 0, 0, - 0, 0, 0, 0, 0, 1667, 1678, 0, 0, 1679, - 1680, 1681, 0, 1682, 1683, 1684, 1685, 1686, 1687, 0, - 0, 0, 1668, 1673, 0, 0, 1674, 1669, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1664, 0, + 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, + 1673, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1675, 0, 0, 1676, 0, 0, 0, 0, 0, 0, - 1670, 1671, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1653, 1672, 0, 1654, 0, 0, - 0, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1664, 0, 0, + 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, 1673, + 0, 0, 0, 0, 1653, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1662, 1667, 0, 0, 0, 0, 0, 0, - 0, 0, 1664, 1673, 0, 0, 1674, 0, 0, 1665, - 1668, 0, 0, 0, 0, 1669, 0, 0, 0, 0, - 1675, 0, 0, 1676, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1666, 0, 1861, 1671, - 0, 0, 0, 1677, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1672, 0, 0, 0, 0, 0, 0, + 1639, 1654, 0, 1640, 0, 0, 1655, 1641, 1642, 1643, + 1644, 1645, 1646, 1647, 1664, 0, 0, 1665, 1666, 1667, + 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 1648, 1656, + 1657, 0, 1971, 0, 0, 0, 0, 0, 1650, 0, + 0, 0, 0, 0, 1658, 1651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1639, 0, 0, 1640, + 0, 0, 1652, 1641, 1642, 1643, 1644, 1645, 1646, 1647, + 0, 0, 1659, 0, 0, 1660, 0, 0, 0, 0, + 0, 0, 0, 0, 1648, 0, 0, 0, 0, 1661, + 0, 0, 1662, 0, 1650, 0, 0, 0, 0, 0, + 0, 1651, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1936, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1652, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1639, 0, 0, 1640, 0, + 0, 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1653, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1673, 0, 0, 1674, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1675, 0, - 0, 1676, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1677, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1667, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1648, 0, 0, 1654, 1978, 0, 0, + 0, 1655, 0, 1650, 0, 0, 0, 0, 0, 0, + 1651, 1663, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1656, 1657, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1652, 0, 1658, + 1976, 0, 0, 0, 0, 1653, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1668, 0, 0, 1678, 0, 1669, 1679, 1680, 1681, 0, - 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1670, 1671, + 0, 0, 1654, 0, 0, 0, 0, 1655, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1659, 0, 0, + 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1656, 1657, 0, 0, 1661, 0, 0, 1662, 0, 0, + 0, 0, 0, 0, 0, 1658, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1664, + 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, + 1672, 1673, 0, 0, 1653, 0, 0, 0, 0, 0, + 0, 0, 0, 1659, 0, 0, 1660, 0, 0, 0, + 0, 1654, 0, 0, 0, 0, 1655, 0, 0, 0, + 1661, 0, 0, 1662, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1639, 0, 0, 1640, 0, 1656, + 1657, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, + 0, 0, 0, 0, 1658, 0, 1663, 0, 0, 0, + 0, 0, 1648, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1650, 0, 0, 0, 0, 0, 0, 1651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1672, 0, 0, 0, 0, 0, 0, + 0, 1639, 1659, 0, 1640, 1660, 0, 0, 1641, 1642, + 1643, 1644, 1645, 1646, 1647, 0, 1652, 0, 0, 1661, + 0, 0, 1662, 0, 0, 0, 0, 0, 0, 1648, + 0, 0, 1663, 0, 0, 0, 0, 0, 0, 1650, + 0, 0, 0, 0, 0, 0, 1651, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1677, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1673, 0, 1678, 1674, 0, 1679, 1680, 1681, 0, - 1682, 1683, 1684, 1685, 1686, 1687, 0, 0, 1675, 0, - 0, 1676, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1652, 1664, 0, 0, 1665, 1666, 1667, + 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 1639, 0, + 0, 1640, 0, 0, 0, 1641, 1642, 1643, 1644, 1645, + 1646, 1647, 0, 2108, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1653, 0, 0, 1648, 0, 0, 0, + 2846, 1663, 0, 0, 0, 0, 1650, 0, 0, 0, + 1654, 0, 0, 1651, 0, 1655, 0, 0, 0, 0, + 1664, 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, + 1671, 1672, 1673, 0, 0, 0, 0, 0, 1656, 1657, + 1652, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1653, 0, 0, 1658, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1654, 0, 0, + 0, 0, 1655, 0, 0, 0, 0, 1639, 0, 0, + 1640, 0, 0, 0, 1641, 1642, 1643, 1644, 1645, 1646, + 1647, 1659, 0, 0, 1660, 1656, 1657, 0, 0, 0, + 0, 0, 0, 0, 0, 1648, 0, 0, 1661, 1664, + 1658, 1662, 1665, 1666, 1667, 1650, 1668, 1669, 1670, 1671, + 1672, 1673, 1651, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1653, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1659, 1652, + 0, 1660, 0, 0, 1654, 0, 0, 0, 0, 1655, + 0, 0, 0, 0, 0, 1661, 0, 0, 1662, 0, + 0, 0, 0, 0, 0, 0, 0, 1639, 0, 0, + 1640, 0, 1656, 1657, 1641, 1642, 1643, 1644, 1645, 1646, + 1647, 0, 0, 0, 0, 0, 0, 1658, 0, 0, + 0, 0, 0, 0, 0, 1648, 0, 0, 0, 0, + 1663, 0, 0, 0, 0, 1650, 0, 0, 0, 0, + 0, 0, 1651, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1659, 0, 0, 1660, 0, + 0, 0, 0, 0, 0, 0, 1653, 0, 0, 1652, + 0, 0, 1661, 0, 0, 1662, 0, 0, 0, 0, + 0, 0, 0, 1654, 0, 0, 1639, 1663, 1655, 1640, + 0, 0, 0, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1656, 1657, 0, 1648, 0, 0, 0, 0, 0, + 2830, 0, 0, 0, 1650, 0, 1658, 0, 0, 0, + 0, 1651, 0, 0, 0, 0, 0, 0, 1664, 0, + 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, 1671, 1672, + 1673, 0, 0, 0, 0, 0, 0, 0, 1652, 0, + 0, 0, 0, 0, 1659, 0, 1653, 1660, 0, 0, + 0, 0, 0, 0, 1663, 0, 0, 0, 0, 0, + 0, 1661, 0, 1654, 1662, 0, 0, 0, 1655, 0, + 0, 0, 0, 0, 0, 1664, 0, 0, 1665, 1666, + 1667, 0, 1668, 1669, 1670, 1671, 1672, 1673, 0, 0, + 0, 1840, 1657, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1658, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1653, 0, 0, 0, 0, + 0, 0, 0, 0, 1659, 0, 0, 1660, 0, 0, + 0, 0, 1654, 0, 0, 0, 0, 1655, 0, 0, + 0, 1661, 1664, 1663, 1662, 1665, 1666, 1667, 0, 1668, + 1669, 1670, 1671, 1672, 1673, 0, 0, 0, 0, 0, + 1656, 1657, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1658, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1678, 0, 0, 1679, 1680, 1681, 0, 1682, 1683, - 1684, 1685, 1686, 1687, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1659, 0, 0, 1660, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1677, 0, 0, 0, 0, 0, 0, 0, 0, + 1661, 0, 0, 1662, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1663, 0, 0, 0, 0, 0, 0, + 0, 1664, 0, 0, 1665, 1666, 1667, 0, 1668, 1669, + 1670, 1671, 1672, 1673, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1663, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1664, 0, 0, 1665, 1666, 1667, 0, 1668, 1669, + 1670, 1671, 1672, 1673, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 564, 0, 2157, 0, 0, - 0, 1678, 0, 0, 1679, 1680, 1681, 0, 1682, 1683, - 1684, 1685, 2261, 1687, 119, 120, 121, 122, 123, 124, - 125, 126, 565, 127, 128, 129, 566, 567, 568, 569, - 570, 571, 572, 573, 574, 131, 132, 575, 576, 134, - 135, 577, 137, 138, 139, 578, 579, 580, 581, 582, - 583, 145, 146, 147, 148, 149, 150, 584, 585, 151, - 152, 153, 154, 586, 587, 157, 588, 158, 159, 160, - 161, 589, 590, 591, 592, 593, 165, 166, 167, 168, - 169, 594, 171, 172, 173, 595, 174, 175, 176, 177, - 178, 179, 596, 597, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 599, 192, 193, 600, 195, 601, - 196, 602, 197, 198, 199, 200, 201, 202, 603, 604, - 203, 204, 205, 206, 605, 606, 207, 208, 209, 210, - 211, 607, 212, 213, 214, 608, 215, 216, 217, 609, - 218, 219, 220, 221, 610, 223, 224, 225, 226, 227, - 228, 611, 612, 230, 613, 231, 232, 614, 234, 615, - 235, 616, 236, 617, 618, 619, 239, 240, 620, 621, - 243, 244, 245, 622, 623, 624, 248, 249, 625, 250, - 251, 252, 253, 254, 255, 256, 626, 258, 259, 260, - 261, 627, 262, 263, 264, 265, 266, 267, 268, 628, - 269, 629, 630, 272, 273, 274, 275, 276, 631, 632, - 633, 634, 635, 280, 636, 637, 283, 638, 285, 286, - 287, 288, 289, 290, 639, 640, 291, 641, 293, 642, - 643, 295, 296, 297, 298, 299, 300, 301, 302, 644, - 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 645, 646, 647, 327, 328, 329, 648, 649, 331, 332, - 650, 334, 651, 652, 336, 653, 338, 339, 340, 654, - 341, 342, 655, 656, 343, 344, 345, 657, 658, 346, - 347, 659, 660, 350, 661, 662, 353, 354, 355, 356, - 357, 358, 359, 360, 361, 362, 363, 364, 663, 664, - 665, 666, 365, 366, 667, 668, 369, 370, 669, 372, - 373, 374, 670, 375, 376, 377, 378, 379, 380, 671, - 381, 382, 383, 384, 385, 672, 387, 388, 389, 390, - 673, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 674, 404, 405, 675, 407, 408, - 409, 676, 411, 412, 413, 414, 415, 416, 417, 418, - 419, 420, 421, 422, 423, 677, 678, 424, 425, 426, - 427, 428, 429, 679, 431, 432, 680, 681, 434, 435, - 682, 437, 683, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, 449, 450, 684, 452, 685, 686, - 687, 454, 455, 688, 456, 689, 458, 459, 460, 461, - 462, 690, 463, 691, 692, 693, 694, 466, 467, 695, - 469, 696, 697, 471, 472, 698, 474, 475, 476, 477, - 478, 699, 700, 479, 480, 481, 701, 702, 482, 483, - 484, 485, 703, 486, 487, 488, 489, 490, 704, 705, - 493, 706, 494, 707, 496, 497, 498, 499, 500, 501, - 502, 708, 709, 503, 710, 711, 504, 505, 506, 507, - 508, 509, 712, 713, 714, 715, 716, 717, 718, 719, - 720, 721, 722, 521, 522, 523, 524, 564, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 119, 120, 121, 122, - 123, 124, 125, 126, 565, 127, 128, 129, 566, 567, - 568, 569, 570, 571, 572, 573, 574, 131, 132, 575, - 576, 134, 135, 577, 137, 138, 139, 578, 579, 580, - 581, 582, 583, 145, 146, 147, 148, 149, 150, 584, - 585, 151, 152, 153, 154, 586, 587, 157, 588, 158, - 159, 160, 161, 589, 590, 591, 592, 593, 165, 166, - 167, 168, 169, 594, 171, 172, 173, 595, 174, 175, - 176, 177, 178, 179, 596, 597, 181, 182, 183, 184, - 185, 186, 598, 188, 189, 190, 599, 192, 193, 600, - 195, 601, 196, 602, 197, 198, 199, 200, 201, 202, - 603, 604, 203, 204, 205, 206, 605, 606, 207, 208, - 209, 210, 211, 607, 212, 213, 214, 608, 215, 216, - 217, 609, 218, 219, 220, 221, 610, 223, 224, 225, - 226, 227, 228, 611, 612, 230, 613, 231, 232, 614, - 234, 615, 235, 616, 236, 617, 618, 619, 239, 240, - 620, 621, 243, 244, 245, 622, 623, 624, 248, 249, - 625, 250, 251, 252, 253, 254, 255, 256, 626, 258, - 259, 260, 261, 627, 262, 263, 264, 265, 266, 267, - 268, 628, 269, 629, 630, 272, 273, 274, 275, 276, - 631, 632, 633, 634, 635, 280, 636, 637, 283, 638, - 285, 286, 287, 288, 289, 290, 639, 640, 291, 641, - 293, 642, 643, 295, 296, 297, 298, 299, 300, 301, - 302, 644, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 645, 646, 647, 327, 328, 329, 648, 649, - 331, 332, 650, 334, 651, 652, 336, 653, 338, 339, - 340, 654, 341, 342, 655, 656, 343, 344, 345, 657, - 658, 346, 347, 659, 660, 350, 661, 662, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 663, 664, 665, 666, 365, 366, 667, 668, 369, 370, - 669, 372, 373, 374, 670, 375, 376, 377, 378, 379, - 380, 671, 381, 382, 383, 384, 385, 672, 387, 388, - 389, 390, 673, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 674, 404, 405, 675, - 407, 408, 409, 676, 411, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 677, 678, 424, - 425, 426, 427, 428, 429, 679, 431, 432, 680, 681, - 434, 435, 682, 437, 683, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 684, 452, - 685, 686, 687, 454, 455, 688, 456, 689, 458, 459, - 460, 461, 462, 690, 463, 691, 692, 693, 694, 466, - 467, 695, 469, 696, 697, 471, 472, 698, 474, 475, - 476, 477, 478, 699, 700, 479, 480, 481, 701, 702, - 482, 483, 484, 485, 703, 486, 487, 488, 489, 490, - 704, 705, 493, 706, 494, 707, 496, 497, 498, 499, - 500, 501, 502, 708, 709, 503, 710, 711, 504, 505, - 506, 507, 508, 509, 712, 713, 714, 715, 716, 717, - 718, 719, 720, 721, 722, 521, 522, 523, 524, 564, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 119, 120, - 121, 122, 123, 124, 125, 126, 565, 127, 128, 129, - 566, 567, 568, 569, 570, 571, 572, 573, 574, 131, - 132, 575, 576, 134, 135, 577, 137, 138, 139, 578, - 579, 580, 581, 582, 583, 145, 146, 147, 148, 149, - 150, 584, 585, 151, 152, 153, 154, 586, 587, 157, - 588, 158, 159, 160, 161, 589, 590, 591, 592, 593, - 165, 166, 167, 168, 169, 594, 171, 172, 173, 595, - 174, 175, 176, 177, 178, 179, 596, 597, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 599, 192, - 193, 600, 195, 601, 196, 602, 197, 198, 199, 200, - 201, 202, 603, 604, 203, 204, 205, 206, 605, 606, - 207, 208, 209, 210, 211, 607, 212, 213, 214, 608, - 215, 216, 217, 609, 218, 219, 220, 221, 610, 223, - 224, 225, 226, 227, 228, 611, 612, 230, 613, 231, - 232, 614, 234, 615, 235, 616, 236, 617, 618, 619, - 239, 240, 620, 621, 243, 244, 245, 622, 623, 624, - 248, 249, 625, 250, 251, 252, 253, 254, 956, 256, - 626, 258, 259, 260, 261, 627, 262, 263, 264, 265, - 266, 267, 268, 628, 269, 629, 630, 272, 273, 274, - 275, 276, 631, 632, 633, 634, 635, 280, 636, 637, - 283, 638, 285, 286, 287, 288, 289, 290, 639, 640, - 291, 641, 293, 642, 643, 295, 296, 297, 298, 299, - 300, 301, 302, 644, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 645, 646, 647, 327, 328, 329, - 648, 649, 331, 332, 650, 334, 651, 652, 336, 653, - 338, 339, 340, 654, 341, 342, 655, 656, 343, 344, - 345, 657, 658, 346, 347, 659, 660, 350, 661, 662, - 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, - 363, 364, 663, 664, 665, 666, 365, 366, 667, 668, - 369, 370, 669, 372, 373, 374, 670, 375, 376, 377, - 378, 379, 380, 671, 381, 382, 383, 384, 385, 672, - 387, 388, 389, 390, 673, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 674, 404, - 405, 675, 407, 408, 409, 676, 411, 412, 413, 414, - 415, 416, 417, 418, 419, 420, 421, 422, 423, 677, - 678, 424, 425, 426, 427, 428, 429, 679, 431, 432, - 680, 681, 434, 435, 682, 437, 683, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, - 684, 452, 685, 686, 687, 454, 455, 688, 456, 689, - 458, 459, 460, 461, 462, 690, 463, 691, 692, 693, - 694, 466, 467, 695, 469, 696, 697, 471, 472, 698, - 474, 475, 476, 477, 478, 699, 700, 479, 480, 481, - 701, 702, 482, 483, 484, 485, 703, 486, 487, 488, - 489, 490, 704, 705, 493, 706, 494, 707, 496, 497, - 498, 499, 500, 501, 502, 708, 709, 503, 710, 711, - 504, 505, 506, 507, 508, 509, 712, 713, 714, 715, - 716, 717, 718, 719, 720, 721, 722, 521, 522, 523, - 524, 564, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 119, 120, 121, 122, 123, 124, 125, 126, 565, 127, - 128, 129, 566, 567, 568, 569, 570, 571, 572, 573, - 574, 131, 132, 575, 576, 134, 135, 577, 137, 138, - 139, 578, 579, 580, 581, 582, 583, 145, 146, 147, - 148, 149, 150, 584, 585, 151, 152, 153, 154, 586, - 587, 157, 588, 158, 159, 160, 161, 589, 590, 591, - 592, 593, 165, 166, 167, 168, 169, 594, 171, 172, - 173, 595, 174, 175, 176, 177, 178, 179, 596, 597, - 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, - 599, 192, 193, 600, 195, 601, 196, 602, 197, 198, - 199, 200, 201, 202, 603, 604, 203, 204, 205, 206, - 605, 606, 207, 208, 209, 210, 211, 607, 212, 213, - 214, 608, 215, 216, 217, 609, 218, 219, 220, 221, - 610, 223, 224, 225, 226, 227, 228, 611, 612, 230, - 613, 231, 232, 614, 234, 615, 235, 616, 236, 617, - 618, 619, 239, 240, 620, 621, 243, 244, 245, 622, - 623, 624, 248, 249, 625, 250, 251, 252, 253, 254, - 255, 256, 626, 258, 259, 260, 261, 627, 262, 263, - 264, 265, 266, 267, 268, 628, 269, 629, 630, 272, - 273, 274, 275, 276, 631, 632, 633, 634, 635, 280, - 636, 637, 283, 638, 285, 286, 287, 288, 289, 290, - 639, 640, 291, 641, 293, 642, 643, 295, 296, 297, - 298, 299, 300, 301, 302, 644, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, - 318, 319, 320, 321, 322, 323, 645, 646, 647, 327, - 328, 329, 648, 649, 331, 332, 650, 334, 651, 652, - 336, 653, 338, 339, 340, 654, 341, 342, 655, 656, - 343, 344, 345, 657, 658, 346, 347, 659, 660, 350, - 661, 662, 353, 354, 355, 356, 357, 358, 359, 360, - 361, 362, 363, 364, 663, 664, 665, 666, 365, 366, - 667, 668, 369, 370, 669, 372, 373, 374, 670, 375, - 376, 377, 378, 379, 380, 671, 381, 382, 383, 384, - 385, 672, 387, 388, 389, 390, 673, 391, 392, 393, - 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, - 674, 404, 405, 675, 407, 408, 409, 676, 411, 412, - 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, - 423, 677, 678, 424, 425, 426, 427, 428, 429, 679, - 431, 432, 680, 681, 434, 435, 682, 437, 683, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - 449, 450, 684, 452, 685, 686, 687, 454, 455, 688, - 456, 689, 458, 459, 460, 461, 462, 690, 463, 691, - 692, 693, 694, 466, 467, 695, 469, 696, 697, 471, - 472, 698, 474, 475, 476, 477, 478, 699, 700, 479, - 480, 481, 701, 702, 482, 483, 484, 485, 703, 486, - 487, 488, 489, 490, 704, 705, 493, 706, 494, 707, - 496, 497, 498, 499, 500, 501, 502, 708, 709, 503, - 710, 711, 504, 505, 506, 507, 508, 509, 712, 713, - 714, 715, 716, 717, 718, 719, 720, 721, 722, 521, - 522, 523, 524, 564, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 119, 120, 121, 122, 2315, 124, 125, 126, - 565, 127, 128, 129, 566, 567, 568, 569, 570, 571, - 572, 573, 574, 131, 132, 575, 576, 134, 135, 577, - 137, 138, 139, 578, 579, 580, 581, 582, 583, 145, - 146, 147, 148, 149, 150, 584, 585, 151, 152, 153, - 154, 586, 587, 157, 588, 158, 159, 160, 161, 589, - 590, 591, 592, 593, 165, 166, 167, 168, 169, 594, - 171, 172, 173, 595, 174, 175, 176, 177, 178, 179, - 596, 597, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 599, 192, 193, 600, 195, 601, 196, 602, - 197, 198, 199, 200, 201, 202, 603, 604, 203, 204, - 205, 206, 605, 606, 207, 208, 209, 2316, 211, 607, - 212, 213, 214, 608, 215, 216, 217, 609, 218, 219, - 220, 221, 610, 223, 224, 225, 226, 227, 228, 611, - 612, 230, 613, 231, 232, 614, 234, 615, 235, 616, - 236, 617, 618, 619, 239, 240, 620, 621, 243, 244, - 245, 622, 623, 624, 248, 249, 625, 250, 251, 252, - 253, 254, 255, 256, 626, 258, 259, 260, 261, 627, - 262, 263, 264, 265, 266, 267, 268, 628, 269, 629, - 630, 272, 273, 274, 275, 276, 631, 632, 633, 634, - 635, 280, 636, 637, 283, 638, 285, 286, 287, 288, - 289, 290, 639, 640, 291, 641, 293, 642, 643, 295, - 296, 297, 298, 299, 300, 301, 302, 644, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 322, 323, 645, 646, - 647, 327, 328, 329, 648, 649, 331, 332, 650, 334, - 651, 652, 336, 653, 338, 339, 340, 654, 341, 342, - 655, 656, 343, 344, 345, 657, 658, 346, 347, 659, - 660, 350, 661, 662, 353, 354, 355, 356, 357, 358, - 359, 360, 361, 362, 363, 364, 663, 664, 665, 666, - 365, 366, 667, 668, 369, 370, 669, 372, 373, 374, - 670, 375, 376, 377, 378, 379, 380, 671, 381, 382, - 383, 384, 385, 672, 387, 388, 389, 390, 673, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 674, 404, 405, 675, 407, 408, 409, 676, - 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, - 421, 422, 423, 677, 678, 424, 425, 426, 427, 428, - 2317, 679, 431, 432, 680, 681, 434, 435, 682, 437, - 683, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, 449, 450, 684, 452, 685, 686, 687, 454, - 455, 688, 456, 689, 458, 459, 460, 461, 462, 690, - 463, 691, 692, 693, 694, 466, 467, 695, 469, 696, - 697, 471, 472, 698, 474, 475, 476, 477, 478, 699, - 700, 479, 480, 481, 701, 702, 482, 483, 484, 485, - 703, 486, 487, 488, 489, 490, 704, 705, 493, 706, - 494, 707, 496, 497, 498, 499, 500, 501, 502, 708, - 709, 503, 710, 711, 504, 505, 506, 507, 508, 509, - 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, - 722, 521, 522, 523, 524, 980, 0, 826, 0, 0, + 0, 0, 0, 0, 560, 0, 2132, 0, 0, 0, + 1664, 0, 0, 1665, 1666, 1667, 0, 1668, 1669, 1670, + 1671, 2237, 1673, 118, 119, 120, 121, 122, 123, 124, + 125, 561, 126, 127, 128, 562, 563, 564, 565, 566, + 567, 568, 569, 570, 130, 131, 571, 132, 133, 134, + 572, 136, 137, 138, 573, 574, 575, 576, 577, 578, + 144, 145, 146, 147, 148, 149, 579, 580, 150, 151, + 152, 153, 581, 582, 156, 583, 157, 158, 159, 160, + 584, 585, 586, 587, 588, 164, 165, 166, 167, 168, + 589, 170, 171, 172, 590, 173, 174, 175, 176, 177, + 178, 591, 592, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 594, 191, 192, 595, 194, 596, 195, + 597, 196, 197, 198, 199, 200, 201, 598, 599, 202, + 203, 204, 205, 600, 601, 206, 207, 208, 209, 210, + 602, 211, 212, 213, 603, 214, 215, 216, 604, 217, + 218, 219, 220, 605, 222, 223, 224, 225, 226, 227, + 606, 607, 229, 608, 230, 231, 609, 233, 610, 234, + 611, 235, 612, 613, 614, 238, 239, 615, 616, 242, + 617, 243, 618, 619, 620, 246, 247, 621, 248, 249, + 250, 251, 252, 253, 254, 622, 256, 257, 258, 259, + 623, 260, 261, 262, 263, 264, 265, 266, 624, 267, + 625, 626, 270, 271, 272, 273, 274, 627, 628, 629, + 630, 631, 278, 632, 633, 281, 634, 283, 284, 285, + 286, 287, 288, 635, 636, 289, 637, 291, 638, 639, + 293, 294, 295, 296, 297, 298, 299, 300, 640, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, 321, 641, + 642, 643, 325, 326, 327, 644, 645, 329, 330, 646, + 332, 647, 648, 334, 649, 336, 337, 338, 650, 339, + 340, 651, 652, 341, 342, 343, 653, 654, 344, 345, + 655, 656, 348, 657, 658, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 659, 660, 661, 662, + 362, 363, 663, 664, 366, 367, 665, 369, 370, 371, + 666, 372, 373, 374, 375, 376, 377, 667, 378, 379, + 380, 381, 382, 668, 384, 385, 386, 387, 669, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 670, 401, 402, 671, 404, 405, 406, 672, + 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, + 418, 419, 420, 673, 674, 421, 422, 423, 424, 425, + 426, 675, 428, 429, 676, 677, 431, 432, 678, 434, + 679, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 680, 448, 681, 682, 683, 450, 451, + 684, 452, 685, 454, 455, 456, 457, 458, 686, 459, + 687, 688, 689, 690, 462, 463, 691, 465, 692, 693, + 467, 468, 694, 470, 471, 472, 473, 474, 695, 696, + 475, 476, 477, 697, 478, 479, 480, 481, 698, 482, + 483, 484, 485, 486, 699, 700, 489, 701, 490, 702, + 492, 493, 494, 495, 496, 497, 498, 703, 704, 499, + 705, 706, 500, 501, 502, 503, 504, 505, 707, 708, + 709, 710, 711, 712, 713, 714, 715, 716, 717, 517, + 518, 519, 520, 560, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 119, 120, 121, 122, 123, 124, - 125, 126, 0, 127, 128, 129, 0, 0, 0, 569, - 0, 0, 0, 0, 574, 131, 132, 0, 576, 134, - 135, 577, 137, 138, 139, 578, 579, 580, 581, 582, - 0, 145, 146, 147, 148, 149, 150, 0, 0, 151, - 152, 153, 154, 586, 587, 157, 0, 158, 159, 160, - 161, 589, 0, 591, 0, 593, 165, 166, 167, 168, - 169, 594, 171, 172, 173, 0, 174, 175, 176, 177, - 178, 179, 0, 597, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 599, 192, 193, 600, 195, 0, - 196, 0, 197, 198, 199, 200, 201, 202, 0, 0, - 203, 204, 205, 206, 0, 0, 207, 208, 209, 210, - 211, 0, 212, 213, 214, 0, 215, 216, 217, 0, - 218, 219, 220, 221, 610, 223, 224, 225, 226, 227, - 228, 611, 1375, 230, 0, 231, 232, 614, 234, 0, - 235, 0, 236, 617, 0, 619, 239, 240, 620, 621, - 243, 244, 245, 0, 623, 624, 248, 249, 0, 250, - 251, 252, 253, 254, 255, 256, 626, 258, 259, 260, - 261, 0, 262, 263, 264, 265, 266, 267, 268, 0, - 269, 629, 630, 272, 273, 274, 275, 276, 631, 632, - 0, 634, 0, 280, 636, 637, 283, 638, 285, 286, - 287, 288, 289, 290, 0, 0, 291, 641, 293, 642, - 0, 295, 296, 297, 298, 299, 300, 301, 302, 644, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 561, 126, 127, 128, 562, 563, 564, 565, 566, 567, + 568, 569, 570, 130, 131, 571, 132, 133, 134, 572, + 136, 137, 138, 573, 574, 575, 576, 577, 578, 144, + 145, 146, 147, 148, 149, 579, 580, 150, 151, 152, + 153, 581, 582, 156, 583, 157, 158, 159, 160, 584, + 585, 586, 587, 588, 164, 165, 166, 167, 168, 589, + 170, 171, 172, 590, 173, 174, 175, 176, 177, 178, + 591, 592, 180, 181, 182, 183, 184, 185, 593, 187, + 188, 189, 594, 191, 192, 595, 194, 596, 195, 597, + 196, 197, 198, 199, 200, 201, 598, 599, 202, 203, + 204, 205, 600, 601, 206, 207, 208, 209, 210, 602, + 211, 212, 213, 603, 214, 215, 216, 604, 217, 218, + 219, 220, 605, 222, 223, 224, 225, 226, 227, 606, + 607, 229, 608, 230, 231, 609, 233, 610, 234, 611, + 235, 612, 613, 614, 238, 239, 615, 616, 242, 617, + 243, 618, 619, 620, 246, 247, 621, 248, 249, 250, + 251, 252, 253, 254, 622, 256, 257, 258, 259, 623, + 260, 261, 262, 263, 264, 265, 266, 624, 267, 625, + 626, 270, 271, 272, 273, 274, 627, 628, 629, 630, + 631, 278, 632, 633, 281, 634, 283, 284, 285, 286, + 287, 288, 635, 636, 289, 637, 291, 638, 639, 293, + 294, 295, 296, 297, 298, 299, 300, 640, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 645, 646, 647, 327, 328, 329, 648, 0, 331, 332, - 650, 334, 0, 652, 336, 653, 338, 339, 340, 0, - 341, 342, 1376, 0, 343, 344, 345, 0, 0, 346, - 347, 659, 660, 350, 661, 662, 353, 354, 355, 356, - 357, 358, 359, 360, 361, 362, 363, 364, 0, 0, - 0, 0, 365, 366, 667, 668, 369, 370, 669, 372, - 373, 374, 0, 375, 376, 377, 378, 379, 380, 0, - 381, 382, 383, 384, 385, 672, 387, 388, 389, 390, - 0, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 0, 404, 405, 675, 407, 408, - 409, 676, 411, 412, 413, 414, 415, 416, 417, 418, - 419, 420, 421, 422, 423, 0, 678, 424, 425, 426, - 427, 428, 429, 679, 431, 432, 0, 681, 434, 435, - 682, 437, 0, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, 449, 450, 684, 452, 685, 0, - 0, 454, 455, 0, 456, 689, 458, 459, 460, 461, - 462, 0, 463, 691, 692, 0, 0, 466, 467, 695, - 469, 696, 1377, 471, 472, 698, 474, 475, 476, 477, - 478, 0, 0, 479, 480, 481, 701, 0, 482, 483, - 484, 485, 0, 486, 487, 488, 489, 490, 704, 705, - 493, 0, 494, 707, 496, 497, 498, 499, 500, 501, - 502, 0, 0, 503, 0, 0, 504, 505, 506, 507, - 508, 509, 712, 713, 714, 715, 716, 717, 718, 719, - 720, 721, 722, 521, 522, 523, 524, 980, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 119, 120, 121, 122, - 123, 124, 125, 126, 0, 127, 128, 129, 3, 4, - 0, 569, 0, 0, 0, 0, 574, 131, 132, 0, - 576, 134, 135, 577, 137, 138, 139, 578, 579, 580, - 581, 582, 0, 145, 146, 147, 148, 149, 150, 0, - 0, 151, 152, 153, 154, 586, 587, 157, 0, 158, - 159, 160, 161, 589, 0, 591, 0, 593, 165, 166, - 167, 168, 169, 594, 171, 172, 173, 0, 174, 175, - 176, 177, 178, 179, 0, 597, 181, 182, 183, 184, - 185, 186, 187, 188, 189, 190, 599, 192, 193, 600, - 195, 0, 196, 0, 197, 198, 199, 200, 201, 202, - 0, 0, 203, 204, 205, 206, 0, 0, 207, 208, - 209, 210, 211, 0, 212, 213, 214, 0, 215, 216, - 217, 0, 218, 219, 220, 221, 610, 223, 224, 225, - 226, 227, 228, 611, 0, 230, 0, 231, 232, 614, - 234, 0, 235, 0, 236, 617, 0, 619, 239, 240, - 620, 621, 243, 244, 245, 0, 623, 624, 248, 249, - 0, 250, 251, 252, 253, 254, 255, 256, 626, 258, - 259, 260, 261, 0, 262, 263, 264, 265, 266, 267, - 268, 0, 269, 629, 630, 272, 273, 274, 275, 276, - 631, 632, 0, 634, 0, 280, 636, 637, 283, 638, - 285, 286, 287, 288, 289, 290, 0, 0, 291, 641, - 293, 642, 0, 295, 296, 297, 298, 299, 300, 301, - 302, 644, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 645, 646, 647, 327, 328, 329, 648, 0, - 331, 332, 650, 334, 0, 652, 336, 653, 338, 339, - 340, 0, 341, 342, 0, 0, 343, 344, 345, 0, - 0, 346, 347, 659, 660, 350, 661, 662, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 0, 0, 0, 0, 365, 366, 667, 668, 369, 370, - 669, 372, 373, 374, 0, 375, 376, 377, 378, 379, - 380, 0, 381, 382, 383, 384, 385, 672, 387, 388, - 389, 390, 0, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 0, 404, 405, 675, - 407, 408, 409, 676, 411, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 0, 678, 424, - 425, 426, 427, 428, 429, 679, 431, 432, 0, 681, - 434, 435, 682, 437, 0, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 684, 452, - 685, 0, 0, 454, 455, 0, 456, 689, 458, 459, - 460, 461, 462, 0, 463, 691, 692, 0, 0, 466, - 467, 695, 469, 696, 0, 471, 472, 698, 474, 475, - 476, 477, 478, 0, 0, 479, 480, 481, 701, 0, - 482, 483, 484, 485, 0, 486, 487, 488, 489, 490, - 704, 705, 493, 0, 494, 707, 496, 497, 498, 499, - 500, 501, 502, 0, 0, 503, 0, 0, 504, 505, - 506, 507, 508, 509, 712, 713, 714, 715, 716, 717, - 718, 719, 720, 721, 722, 521, 522, 523, 524, 118, + 314, 315, 316, 317, 318, 319, 320, 321, 641, 642, + 643, 325, 326, 327, 644, 645, 329, 330, 646, 332, + 647, 648, 334, 649, 336, 337, 338, 650, 339, 340, + 651, 652, 341, 342, 343, 653, 654, 344, 345, 655, + 656, 348, 657, 658, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 659, 660, 661, 662, 362, + 363, 663, 664, 366, 367, 665, 369, 370, 371, 666, + 372, 373, 374, 375, 376, 377, 667, 378, 379, 380, + 381, 382, 668, 384, 385, 386, 387, 669, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 670, 401, 402, 671, 404, 405, 406, 672, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 673, 674, 421, 422, 423, 424, 425, 426, + 675, 428, 429, 676, 677, 431, 432, 678, 434, 679, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 680, 448, 681, 682, 683, 450, 451, 684, + 452, 685, 454, 455, 456, 457, 458, 686, 459, 687, + 688, 689, 690, 462, 463, 691, 465, 692, 693, 467, + 468, 694, 470, 471, 472, 473, 474, 695, 696, 475, + 476, 477, 697, 478, 479, 480, 481, 698, 482, 483, + 484, 485, 486, 699, 700, 489, 701, 490, 702, 492, + 493, 494, 495, 496, 497, 498, 703, 704, 499, 705, + 706, 500, 501, 502, 503, 504, 505, 707, 708, 709, + 710, 711, 712, 713, 714, 715, 716, 717, 517, 518, + 519, 520, 560, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 119, 120, - 121, 122, 123, 124, 125, 126, 0, 127, 128, 129, - 0, 0, 0, 0, 0, 0, 0, 0, 130, 131, - 132, 0, 133, 134, 135, 136, 137, 138, 139, 140, - 141, 142, 143, 144, 0, 145, 146, 147, 148, 149, - 150, 0, 795, 151, 152, 153, 154, 155, 156, 157, - 0, 158, 159, 160, 161, 796, 0, 797, 0, 164, - 165, 166, 167, 168, 169, 170, 171, 172, 173, 0, - 174, 175, 176, 177, 178, 179, 0, 180, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 0, 196, 0, 197, 198, 199, 200, - 201, 202, 0, 0, 203, 204, 205, 206, 0, 0, - 207, 208, 209, 210, 211, 0, 212, 213, 214, 0, - 215, 216, 217, 0, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 798, 0, 230, 0, 231, - 232, 233, 234, 0, 235, 0, 236, 237, 0, 238, - 239, 240, 241, 242, 243, 244, 245, 0, 246, 247, - 248, 249, 0, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 0, 262, 263, 264, 265, - 266, 267, 268, 0, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 0, 279, 0, 280, 281, 282, - 283, 284, 285, 286, 287, 288, 289, 290, 0, 0, - 291, 292, 293, 294, 0, 295, 296, 297, 298, 299, - 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, - 330, 0, 331, 332, 333, 334, 0, 800, 336, 337, - 338, 339, 340, 0, 341, 342, 0, 0, 343, 344, - 345, 0, 0, 346, 347, 348, 349, 350, 351, 802, - 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, - 363, 364, 0, 0, 0, 0, 365, 366, 803, 368, - 369, 370, 371, 372, 373, 374, 0, 375, 376, 377, - 378, 379, 380, 0, 381, 382, 383, 384, 385, 386, - 387, 388, 389, 390, 0, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 0, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, 417, 418, 419, 420, 421, 422, 423, 0, - 0, 424, 425, 426, 427, 428, 429, 430, 431, 432, - 0, 433, 434, 435, 436, 437, 0, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, - 451, 452, 805, 0, 0, 454, 455, 0, 456, 457, - 458, 459, 460, 461, 462, 0, 463, 464, 465, 0, - 0, 466, 467, 806, 469, 807, 0, 471, 472, 808, - 474, 475, 476, 477, 478, 0, 0, 479, 480, 481, - 0, 0, 482, 483, 484, 485, 0, 486, 487, 488, - 489, 490, 491, 492, 493, 0, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 0, 0, 503, 0, 0, - 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, - 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, - 524, 118, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 561, + 126, 127, 128, 562, 563, 564, 565, 566, 567, 568, + 569, 570, 130, 131, 571, 132, 133, 134, 572, 136, + 137, 138, 573, 574, 575, 576, 577, 578, 144, 145, + 146, 147, 148, 149, 579, 580, 150, 151, 152, 153, + 581, 582, 156, 583, 157, 158, 159, 160, 584, 585, + 586, 587, 588, 164, 165, 166, 167, 168, 589, 170, + 171, 172, 590, 173, 174, 175, 176, 177, 178, 591, + 592, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 594, 191, 192, 595, 194, 596, 195, 597, 196, + 197, 198, 199, 200, 201, 598, 599, 202, 203, 204, + 205, 600, 601, 206, 207, 208, 209, 210, 602, 211, + 212, 213, 603, 214, 215, 216, 604, 217, 218, 219, + 220, 605, 222, 223, 224, 225, 226, 227, 606, 607, + 229, 608, 230, 231, 609, 233, 610, 234, 611, 235, + 612, 613, 614, 238, 239, 615, 616, 242, 617, 243, + 618, 619, 620, 246, 247, 621, 248, 249, 250, 251, + 252, 950, 254, 622, 256, 257, 258, 259, 623, 260, + 261, 262, 263, 264, 265, 266, 624, 267, 625, 626, + 270, 271, 272, 273, 274, 627, 628, 629, 630, 631, + 278, 632, 633, 281, 634, 283, 284, 285, 286, 287, + 288, 635, 636, 289, 637, 291, 638, 639, 293, 294, + 295, 296, 297, 298, 299, 300, 640, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 641, 642, 643, + 325, 326, 327, 644, 645, 329, 330, 646, 332, 647, + 648, 334, 649, 336, 337, 338, 650, 339, 340, 651, + 652, 341, 342, 343, 653, 654, 344, 345, 655, 656, + 348, 657, 658, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 659, 660, 661, 662, 362, 363, + 663, 664, 366, 367, 665, 369, 370, 371, 666, 372, + 373, 374, 375, 376, 377, 667, 378, 379, 380, 381, + 382, 668, 384, 385, 386, 387, 669, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 670, 401, 402, 671, 404, 405, 406, 672, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 673, 674, 421, 422, 423, 424, 425, 426, 675, + 428, 429, 676, 677, 431, 432, 678, 434, 679, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 680, 448, 681, 682, 683, 450, 451, 684, 452, + 685, 454, 455, 456, 457, 458, 686, 459, 687, 688, + 689, 690, 462, 463, 691, 465, 692, 693, 467, 468, + 694, 470, 471, 472, 473, 474, 695, 696, 475, 476, + 477, 697, 478, 479, 480, 481, 698, 482, 483, 484, + 485, 486, 699, 700, 489, 701, 490, 702, 492, 493, + 494, 495, 496, 497, 498, 703, 704, 499, 705, 706, + 500, 501, 502, 503, 504, 505, 707, 708, 709, 710, + 711, 712, 713, 714, 715, 716, 717, 517, 518, 519, + 520, 560, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 119, 120, 121, 122, 123, 124, 125, 126, 0, 127, - 128, 129, 0, 0, 0, 0, 0, 0, 0, 0, - 130, 131, 132, 0, 133, 134, 135, 136, 137, 138, - 139, 140, 141, 142, 143, 144, 0, 145, 146, 147, - 148, 149, 150, 0, 0, 151, 152, 153, 154, 155, - 156, 157, 0, 158, 159, 160, 161, 162, 0, 163, - 0, 164, 165, 166, 167, 168, 169, 170, 171, 172, - 173, 0, 174, 175, 176, 177, 178, 179, 0, 180, - 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, - 191, 192, 193, 194, 195, 0, 196, 0, 197, 198, - 199, 200, 201, 202, 0, 0, 203, 204, 205, 206, - 0, 0, 207, 208, 209, 210, 211, 0, 212, 213, - 214, 0, 215, 216, 217, 0, 218, 219, 220, 221, - 222, 223, 224, 225, 226, 227, 228, 229, 0, 230, - 0, 231, 232, 233, 234, 0, 235, 0, 236, 237, - 0, 238, 239, 240, 241, 242, 243, 244, 245, 0, - 246, 247, 248, 249, 0, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 0, 262, 263, - 264, 265, 266, 267, 268, 0, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 0, 279, 0, 280, - 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, - 0, 0, 291, 292, 293, 294, 0, 295, 296, 297, - 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, + 118, 119, 120, 121, 122, 123, 124, 125, 561, 126, + 127, 128, 562, 563, 564, 565, 566, 567, 568, 569, + 570, 130, 131, 571, 132, 133, 134, 572, 136, 137, + 138, 573, 574, 575, 576, 577, 578, 144, 145, 146, + 147, 148, 149, 579, 580, 150, 151, 152, 153, 581, + 582, 156, 583, 157, 158, 159, 160, 584, 585, 586, + 587, 588, 164, 165, 166, 167, 168, 589, 170, 171, + 172, 590, 173, 174, 175, 176, 177, 178, 591, 592, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 594, 191, 192, 595, 194, 596, 195, 597, 196, 197, + 198, 199, 200, 201, 598, 599, 202, 203, 204, 205, + 600, 601, 206, 207, 208, 209, 210, 602, 211, 212, + 213, 603, 214, 215, 216, 604, 217, 218, 219, 220, + 605, 222, 223, 224, 225, 226, 227, 606, 607, 229, + 608, 230, 231, 609, 233, 610, 234, 611, 235, 612, + 613, 614, 238, 239, 615, 616, 242, 617, 243, 618, + 619, 620, 246, 247, 621, 248, 249, 250, 251, 252, + 253, 254, 622, 256, 257, 258, 259, 623, 260, 261, + 262, 263, 264, 265, 266, 624, 267, 625, 626, 270, + 271, 272, 273, 274, 627, 628, 629, 630, 631, 278, + 632, 633, 281, 634, 283, 284, 285, 286, 287, 288, + 635, 636, 289, 637, 291, 638, 639, 293, 294, 295, + 296, 297, 298, 299, 300, 640, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 641, 642, 643, 325, + 326, 327, 644, 645, 329, 330, 646, 332, 647, 648, + 334, 649, 336, 337, 338, 650, 339, 340, 651, 652, + 341, 342, 343, 653, 654, 344, 345, 655, 656, 348, + 657, 658, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 659, 660, 661, 662, 362, 363, 663, + 664, 366, 367, 665, 369, 370, 371, 666, 372, 373, + 374, 375, 376, 377, 667, 378, 379, 380, 381, 382, + 668, 384, 385, 386, 387, 669, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 670, + 401, 402, 671, 404, 405, 406, 672, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 673, 674, 421, 422, 423, 424, 425, 426, 675, 428, + 429, 676, 677, 431, 432, 678, 434, 679, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 680, 448, 681, 682, 683, 450, 451, 684, 452, 685, + 454, 455, 456, 457, 458, 686, 459, 687, 688, 689, + 690, 462, 463, 691, 465, 692, 693, 467, 468, 694, + 470, 471, 472, 473, 474, 695, 696, 475, 476, 477, + 697, 478, 479, 480, 481, 698, 482, 483, 484, 485, + 486, 699, 700, 489, 701, 490, 702, 492, 493, 494, + 495, 496, 497, 498, 703, 704, 499, 705, 706, 500, + 501, 502, 503, 504, 505, 707, 708, 709, 710, 711, + 712, 713, 714, 715, 716, 717, 517, 518, 519, 520, + 560, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, + 119, 120, 121, 2286, 123, 124, 125, 561, 126, 127, + 128, 562, 563, 564, 565, 566, 567, 568, 569, 570, + 130, 131, 571, 132, 133, 134, 572, 136, 137, 138, + 573, 574, 575, 576, 577, 578, 144, 145, 146, 147, + 148, 149, 579, 580, 150, 151, 152, 153, 581, 582, + 156, 583, 157, 158, 159, 160, 584, 585, 586, 587, + 588, 164, 165, 166, 167, 168, 589, 170, 171, 172, + 590, 173, 174, 175, 176, 177, 178, 591, 592, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 594, + 191, 192, 595, 194, 596, 195, 597, 196, 197, 198, + 199, 200, 201, 598, 599, 202, 203, 204, 205, 600, + 601, 206, 207, 208, 2287, 210, 602, 211, 212, 213, + 603, 214, 215, 216, 604, 217, 218, 219, 220, 605, + 222, 223, 224, 225, 226, 227, 606, 607, 229, 608, + 230, 231, 609, 233, 610, 234, 611, 235, 612, 613, + 614, 238, 239, 615, 616, 242, 617, 243, 618, 619, + 620, 246, 247, 621, 248, 249, 250, 251, 252, 253, + 254, 622, 256, 257, 258, 259, 623, 260, 261, 262, + 263, 264, 265, 266, 624, 267, 625, 626, 270, 271, + 272, 273, 274, 627, 628, 629, 630, 631, 278, 632, + 633, 281, 634, 283, 284, 285, 286, 287, 288, 635, + 636, 289, 637, 291, 638, 639, 293, 294, 295, 296, + 297, 298, 299, 300, 640, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 641, 642, 643, 325, 326, + 327, 644, 645, 329, 330, 646, 332, 647, 648, 334, + 649, 336, 337, 338, 650, 339, 340, 651, 652, 341, + 342, 343, 653, 654, 344, 345, 655, 656, 348, 657, + 658, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 659, 660, 661, 662, 362, 363, 663, 664, + 366, 367, 665, 369, 370, 371, 666, 372, 373, 374, + 375, 376, 377, 667, 378, 379, 380, 381, 382, 668, + 384, 385, 386, 387, 669, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 670, 401, + 402, 671, 404, 405, 406, 672, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 673, + 674, 421, 422, 423, 424, 425, 2288, 675, 428, 429, + 676, 677, 431, 432, 678, 434, 679, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 680, + 448, 681, 682, 683, 450, 451, 684, 452, 685, 454, + 455, 456, 457, 458, 686, 459, 687, 688, 689, 690, + 462, 463, 691, 465, 692, 693, 467, 468, 694, 470, + 471, 472, 473, 474, 695, 696, 475, 476, 477, 697, + 478, 479, 480, 481, 698, 482, 483, 484, 485, 486, + 699, 700, 489, 701, 490, 702, 492, 493, 494, 495, + 496, 497, 498, 703, 704, 499, 705, 706, 500, 501, + 502, 503, 504, 505, 707, 708, 709, 710, 711, 712, + 713, 714, 715, 716, 717, 517, 518, 519, 520, 974, + 0, 821, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 565, 0, 0, 0, 0, 570, 130, + 131, 0, 132, 133, 134, 572, 136, 137, 138, 573, + 574, 575, 576, 577, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 581, 582, 156, + 0, 157, 158, 159, 160, 584, 0, 586, 0, 588, + 164, 165, 166, 167, 168, 589, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 592, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 594, 191, + 192, 595, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 605, 222, + 223, 224, 225, 226, 227, 606, 1365, 229, 0, 230, + 231, 609, 233, 0, 234, 0, 235, 612, 0, 614, + 238, 239, 615, 616, 242, 0, 243, 0, 619, 620, + 246, 247, 0, 248, 249, 250, 251, 252, 253, 254, + 622, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 625, 626, 270, 271, 272, + 273, 274, 627, 628, 0, 630, 0, 278, 632, 633, + 281, 634, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 637, 291, 638, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 640, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, - 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, - 328, 329, 330, 0, 331, 332, 333, 334, 0, 335, - 336, 337, 338, 339, 340, 0, 341, 342, 0, 0, - 343, 344, 345, 0, 0, 346, 347, 348, 349, 350, + 318, 319, 320, 321, 641, 642, 643, 325, 326, 327, + 644, 0, 329, 330, 646, 332, 0, 648, 334, 649, + 336, 337, 338, 0, 339, 340, 1366, 0, 341, 342, + 343, 0, 0, 344, 345, 655, 656, 348, 657, 658, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, 362, 363, 364, 0, 0, 0, 0, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 0, 375, - 376, 377, 378, 379, 380, 0, 381, 382, 383, 384, - 385, 386, 387, 388, 389, 390, 0, 391, 392, 393, - 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, - 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, - 423, 0, 0, 424, 425, 426, 427, 428, 429, 430, - 431, 432, 0, 433, 434, 435, 436, 437, 0, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - 449, 450, 451, 452, 453, 0, 0, 454, 455, 0, - 456, 457, 458, 459, 460, 461, 462, 0, 463, 464, - 465, 0, 0, 466, 467, 468, 469, 470, 0, 471, - 472, 473, 474, 475, 476, 477, 478, 0, 0, 479, - 480, 481, 0, 0, 482, 483, 484, 485, 0, 486, - 487, 488, 489, 490, 491, 492, 493, 0, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 0, 0, 503, - 0, 0, 504, 505, 506, 507, 508, 509, 510, 511, - 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, - 522, 523, 524, 532, 0, 0, 0, 0, 0, 0, + 361, 0, 0, 0, 0, 362, 363, 663, 664, 366, + 367, 665, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 668, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 671, 404, 405, 406, 672, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 0, 674, + 421, 422, 423, 424, 425, 426, 675, 428, 429, 0, + 677, 431, 432, 678, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 680, 448, + 681, 0, 0, 450, 451, 0, 452, 685, 454, 455, + 456, 457, 458, 0, 459, 687, 688, 0, 0, 462, + 463, 691, 465, 692, 1367, 467, 468, 694, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 0, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 699, + 700, 489, 0, 490, 702, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 0, 500, 501, 502, + 503, 504, 505, 707, 708, 709, 710, 711, 712, 713, + 714, 715, 716, 717, 517, 518, 519, 520, 974, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 119, 120, 121, 122, 123, 124, 125, 126, - 0, 127, 128, 129, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 131, 132, 0, 0, 134, 135, 0, - 137, 138, 139, 140, 141, 0, 143, 144, 0, 145, - 146, 147, 148, 149, 150, 0, 0, 151, 152, 153, - 154, 155, 156, 157, 1785, 158, 159, 160, 161, 162, - 0, 0, 1786, 164, 165, 166, 167, 168, 169, 0, - 171, 172, 173, 1787, 174, 175, 176, 177, 178, 179, - 0, 0, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 0, 196, 0, - 197, 198, 199, 200, 201, 202, 0, 0, 203, 204, - 205, 206, 0, 0, 207, 208, 209, 210, 211, 0, - 212, 213, 214, 0, 215, 216, 217, 0, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, - 0, 230, 0, 231, 232, 233, 234, 0, 235, 1788, - 236, 0, 0, 0, 239, 240, 533, 0, 243, 244, - 245, 0, 246, 247, 248, 249, 0, 250, 251, 252, - 253, 254, 1789, 256, 0, 258, 259, 260, 261, 0, - 262, 263, 264, 265, 266, 267, 268, 0, 269, 0, - 271, 272, 273, 274, 275, 276, 277, 278, 0, 279, - 0, 280, 0, 0, 283, 0, 285, 286, 287, 288, - 289, 290, 0, 0, 291, 0, 293, 0, 0, 295, - 296, 297, 298, 299, 300, 301, 302, 534, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 322, 323, 324, 0, - 326, 327, 328, 329, 330, 0, 331, 332, 0, 334, - 0, 335, 336, 337, 338, 339, 340, 0, 341, 342, - 0, 0, 343, 344, 345, 0, 0, 346, 347, 348, - 0, 350, 0, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, 362, 363, 364, 0, 0, 0, 0, - 365, 366, 367, 0, 369, 370, 371, 372, 373, 374, - 1790, 375, 376, 377, 378, 379, 380, 0, 381, 382, - 383, 384, 385, 386, 387, 388, 389, 390, 0, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 0, 404, 405, 0, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, - 421, 422, 423, 0, 0, 424, 425, 426, 427, 428, - 429, 430, 431, 432, 0, 0, 434, 435, 436, 437, - 0, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, 449, 450, 535, 452, 453, 0, 0, 454, - 455, 0, 456, 0, 458, 459, 460, 461, 462, 0, - 463, 464, 465, 0, 0, 466, 467, 468, 469, 470, - 0, 471, 472, 473, 474, 475, 476, 477, 478, 0, - 1791, 479, 480, 481, 0, 0, 482, 483, 484, 485, - 0, 486, 487, 488, 489, 490, 491, 492, 493, 0, - 494, 0, 496, 497, 498, 499, 500, 501, 502, 0, - 0, 503, 0, 0, 504, 505, 506, 507, 508, 509, - 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, - 520, 521, 522, 523, 524, 532, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 118, 119, 120, + 121, 122, 123, 124, 125, 0, 126, 127, 128, 3, + 4, 0, 565, 0, 0, 0, 0, 570, 130, 131, + 0, 132, 133, 134, 572, 136, 137, 138, 573, 574, + 575, 576, 577, 0, 144, 145, 146, 147, 148, 149, + 0, 0, 150, 151, 152, 153, 581, 582, 156, 0, + 157, 158, 159, 160, 584, 0, 586, 0, 588, 164, + 165, 166, 167, 168, 589, 170, 171, 172, 0, 173, + 174, 175, 176, 177, 178, 0, 592, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 594, 191, 192, + 595, 194, 0, 195, 0, 196, 197, 198, 199, 200, + 201, 0, 0, 202, 203, 204, 205, 0, 0, 206, + 207, 208, 209, 210, 0, 211, 212, 213, 0, 214, + 215, 216, 0, 217, 218, 219, 220, 605, 222, 223, + 224, 225, 226, 227, 606, 0, 229, 0, 230, 231, + 609, 233, 0, 234, 0, 235, 612, 0, 614, 238, + 239, 615, 616, 242, 0, 243, 0, 619, 620, 246, + 247, 0, 248, 249, 250, 251, 252, 253, 254, 622, + 256, 257, 258, 259, 0, 260, 261, 262, 263, 264, + 265, 266, 0, 267, 625, 626, 270, 271, 272, 273, + 274, 627, 628, 0, 630, 0, 278, 632, 633, 281, + 634, 283, 284, 285, 286, 287, 288, 0, 0, 289, + 637, 291, 638, 0, 293, 294, 295, 296, 297, 298, + 299, 300, 640, 302, 303, 304, 305, 306, 307, 308, + 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, + 319, 320, 321, 641, 642, 643, 325, 326, 327, 644, + 0, 329, 330, 646, 332, 0, 648, 334, 649, 336, + 337, 338, 0, 339, 340, 0, 0, 341, 342, 343, + 0, 0, 344, 345, 655, 656, 348, 657, 658, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, + 0, 0, 0, 0, 362, 363, 663, 664, 366, 367, + 665, 369, 370, 371, 0, 372, 373, 374, 375, 376, + 377, 0, 378, 379, 380, 381, 382, 668, 384, 385, + 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 0, 401, 402, 671, + 404, 405, 406, 672, 408, 409, 410, 411, 412, 413, + 414, 415, 416, 417, 418, 419, 420, 0, 674, 421, + 422, 423, 424, 425, 426, 675, 428, 429, 0, 677, + 431, 432, 678, 434, 0, 435, 436, 437, 438, 439, + 440, 441, 442, 443, 444, 445, 446, 680, 448, 681, + 0, 0, 450, 451, 0, 452, 685, 454, 455, 456, + 457, 458, 0, 459, 687, 688, 0, 0, 462, 463, + 691, 465, 692, 0, 467, 468, 694, 470, 471, 472, + 473, 474, 0, 0, 475, 476, 477, 0, 478, 479, + 480, 481, 0, 482, 483, 484, 485, 486, 699, 700, + 489, 0, 490, 702, 492, 493, 494, 495, 496, 497, + 498, 0, 0, 499, 0, 0, 500, 501, 502, 503, + 504, 505, 707, 708, 709, 710, 711, 712, 713, 714, + 715, 716, 717, 517, 518, 519, 520, 117, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 119, 120, 121, 122, 123, 124, - 125, 126, 0, 127, 128, 129, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 131, 132, 0, 0, 134, - 135, 0, 137, 138, 139, 140, 141, 0, 143, 144, - 0, 145, 146, 147, 148, 149, 150, 0, 0, 151, - 152, 153, 154, 155, 156, 157, 1785, 158, 159, 160, - 161, 162, 0, 0, 0, 164, 165, 166, 167, 168, - 169, 0, 171, 172, 173, 1787, 174, 175, 176, 177, - 178, 179, 0, 0, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 0, - 196, 0, 197, 198, 199, 200, 201, 202, 0, 0, - 203, 204, 205, 206, 0, 0, 207, 208, 209, 210, - 211, 0, 212, 213, 214, 0, 215, 216, 217, 0, - 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 0, 230, 0, 231, 232, 233, 234, 0, - 235, 1788, 236, 0, 0, 0, 239, 240, 533, 0, - 243, 244, 245, 0, 246, 247, 248, 249, 0, 250, - 251, 252, 253, 254, 255, 256, 0, 258, 259, 260, - 261, 0, 262, 263, 264, 265, 266, 267, 268, 0, - 269, 0, 271, 272, 273, 274, 275, 276, 277, 278, - 0, 279, 0, 280, 0, 0, 283, 0, 285, 286, - 287, 288, 289, 290, 0, 0, 291, 0, 293, 2406, - 0, 295, 296, 297, 298, 299, 300, 301, 302, 534, - 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 324, 0, 326, 327, 328, 329, 330, 0, 331, 332, - 0, 334, 0, 335, 336, 337, 338, 339, 340, 0, - 341, 342, 0, 0, 343, 344, 345, 0, 0, 346, - 347, 348, 0, 350, 0, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, 362, 363, 364, 0, 0, - 0, 0, 365, 366, 367, 0, 369, 370, 371, 372, - 373, 374, 1790, 375, 376, 377, 378, 379, 380, 0, - 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, - 0, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 0, 404, 405, 0, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, - 419, 420, 421, 422, 423, 0, 0, 424, 425, 426, - 427, 428, 429, 430, 431, 432, 0, 0, 434, 435, - 436, 437, 0, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, 449, 450, 535, 452, 453, 0, - 0, 454, 455, 0, 456, 0, 458, 459, 460, 461, - 462, 0, 463, 464, 465, 0, 0, 466, 467, 468, - 469, 470, 0, 471, 472, 473, 474, 475, 476, 477, - 478, 0, 1791, 479, 480, 481, 0, 0, 482, 483, - 484, 485, 0, 486, 487, 488, 489, 490, 491, 492, - 493, 0, 494, 0, 496, 497, 498, 499, 500, 501, - 502, 0, 0, 503, 0, 0, 504, 505, 506, 507, - 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, - 518, 519, 520, 521, 522, 523, 524, 532, 0, 558, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 0, 0, 0, 129, 130, 131, 0, + 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, + 142, 143, 0, 144, 145, 146, 147, 148, 149, 0, + 790, 150, 151, 152, 153, 154, 155, 156, 0, 157, + 158, 159, 160, 791, 0, 792, 0, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 208, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 793, 0, 229, 0, 230, 231, 232, + 233, 0, 234, 0, 235, 236, 0, 237, 238, 239, + 240, 241, 242, 0, 243, 0, 244, 245, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 0, 277, 0, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 290, + 291, 292, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 322, 323, 324, 325, 326, 327, 328, 0, + 329, 330, 331, 332, 0, 795, 334, 335, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 347, 348, 349, 797, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 798, 365, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 383, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 430, 431, + 432, 433, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 800, 0, + 0, 450, 451, 0, 452, 453, 454, 455, 456, 457, + 458, 0, 459, 460, 461, 0, 0, 462, 463, 801, + 465, 802, 0, 467, 468, 803, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 488, 489, + 0, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, + 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 117, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 119, 120, 121, 122, - 123, 124, 125, 126, 0, 127, 128, 129, 3, 4, - 0, 0, 0, 0, 0, 0, 0, 131, 132, 0, - 0, 134, 135, 0, 137, 138, 139, 140, 141, 0, - 143, 144, 0, 145, 146, 147, 148, 149, 150, 0, - 0, 151, 152, 153, 154, 155, 156, 157, 0, 158, - 159, 160, 161, 162, 0, 0, 0, 164, 165, 166, - 167, 168, 169, 0, 171, 172, 173, 0, 174, 175, - 176, 177, 178, 179, 0, 0, 181, 182, 183, 184, + 0, 0, 0, 0, 0, 118, 119, 120, 121, 122, + 123, 124, 125, 0, 126, 127, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 129, 130, 131, 0, 132, + 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, + 143, 0, 144, 145, 146, 147, 148, 149, 0, 0, + 150, 151, 152, 153, 154, 155, 156, 0, 157, 158, + 159, 160, 161, 0, 162, 0, 163, 164, 165, 166, + 167, 168, 169, 170, 171, 172, 0, 173, 174, 175, + 176, 177, 178, 0, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 0, 196, 0, 197, 198, 199, 200, 201, 202, - 0, 0, 203, 204, 205, 206, 0, 0, 207, 208, - 209, 210, 211, 0, 212, 213, 214, 0, 215, 216, - 217, 0, 218, 219, 220, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 0, 230, 0, 231, 232, 233, - 234, 0, 235, 0, 236, 0, 0, 0, 239, 240, - 533, 0, 243, 244, 245, 0, 246, 247, 248, 249, - 0, 250, 251, 252, 253, 254, 255, 256, 0, 258, - 259, 260, 261, 0, 262, 263, 264, 265, 266, 267, - 268, 0, 269, 0, 271, 272, 273, 274, 275, 276, - 277, 278, 0, 279, 0, 280, 0, 0, 283, 0, - 285, 286, 287, 288, 289, 290, 0, 0, 291, 0, - 293, 0, 0, 295, 296, 297, 298, 299, 300, 301, - 302, 534, 304, 305, 306, 307, 308, 309, 310, 311, + 0, 195, 0, 196, 197, 198, 199, 200, 201, 0, + 0, 202, 203, 204, 205, 0, 0, 206, 207, 208, + 209, 210, 0, 211, 212, 213, 0, 214, 215, 216, + 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, + 226, 227, 228, 0, 229, 0, 230, 231, 232, 233, + 0, 234, 0, 235, 236, 0, 237, 238, 239, 240, + 241, 242, 0, 243, 0, 244, 245, 246, 247, 0, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 0, 260, 261, 262, 263, 264, 265, 266, + 0, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 0, 277, 0, 278, 279, 280, 281, 282, 283, + 284, 285, 286, 287, 288, 0, 0, 289, 290, 291, + 292, 0, 293, 294, 295, 296, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, 0, 329, + 330, 331, 332, 0, 333, 334, 335, 336, 337, 338, + 0, 339, 340, 0, 0, 341, 342, 343, 0, 0, + 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, 361, 0, 0, + 0, 0, 362, 363, 364, 365, 366, 367, 368, 369, + 370, 371, 0, 372, 373, 374, 375, 376, 377, 0, + 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, + 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, + 397, 398, 399, 400, 0, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + 416, 417, 418, 419, 420, 0, 0, 421, 422, 423, + 424, 425, 426, 427, 428, 429, 0, 430, 431, 432, + 433, 434, 0, 435, 436, 437, 438, 439, 440, 441, + 442, 443, 444, 445, 446, 447, 448, 449, 0, 0, + 450, 451, 0, 452, 453, 454, 455, 456, 457, 458, + 0, 459, 460, 461, 0, 0, 462, 463, 464, 465, + 466, 0, 467, 468, 469, 470, 471, 472, 473, 474, + 0, 0, 475, 476, 477, 0, 478, 479, 480, 481, + 0, 482, 483, 484, 485, 486, 487, 488, 489, 0, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 0, + 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, + 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, + 516, 517, 518, 519, 520, 528, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 130, 131, 0, 132, 133, + 134, 0, 136, 137, 138, 139, 140, 0, 142, 143, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 154, 155, 156, 1770, 157, 158, 159, + 160, 161, 0, 0, 1771, 163, 164, 165, 166, 167, + 168, 0, 170, 171, 172, 1772, 173, 174, 175, 176, + 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 208, 209, + 210, 0, 211, 212, 213, 0, 214, 215, 216, 0, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 0, 229, 0, 230, 231, 232, 233, 0, + 234, 1773, 235, 0, 0, 0, 238, 239, 529, 0, + 242, 0, 243, 0, 244, 245, 246, 247, 0, 248, + 249, 250, 251, 252, 1774, 254, 0, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 0, 269, 270, 271, 272, 273, 274, 275, 276, + 0, 277, 0, 278, 0, 0, 281, 0, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 0, 291, 0, + 0, 293, 294, 295, 296, 297, 298, 299, 300, 530, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 324, 0, 326, 327, 328, 329, 330, 0, - 331, 332, 0, 334, 0, 335, 336, 337, 338, 339, - 340, 0, 341, 342, 0, 0, 343, 344, 345, 0, - 0, 346, 347, 348, 0, 350, 0, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 0, 0, 0, 0, 365, 366, 367, 0, 369, 370, - 371, 372, 373, 374, 0, 375, 376, 377, 378, 379, - 380, 0, 381, 382, 383, 384, 385, 386, 387, 388, - 389, 390, 0, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 0, 404, 405, 0, + 322, 0, 324, 325, 326, 327, 328, 0, 329, 330, + 0, 332, 0, 333, 334, 335, 336, 337, 338, 0, + 339, 340, 0, 0, 341, 342, 343, 0, 0, 344, + 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 364, 0, 366, 367, 368, 369, 370, + 371, 1775, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 0, 0, 424, - 425, 426, 427, 428, 429, 430, 431, 432, 0, 0, - 434, 435, 436, 437, 0, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 535, 452, - 453, 0, 0, 454, 455, 0, 456, 0, 458, 459, - 460, 461, 462, 0, 463, 464, 465, 0, 0, 466, - 467, 468, 469, 470, 0, 471, 472, 473, 474, 475, - 476, 477, 478, 0, 0, 479, 480, 481, 0, 0, - 482, 483, 484, 485, 0, 486, 487, 488, 489, 490, - 491, 492, 493, 0, 494, 0, 496, 497, 498, 499, - 500, 501, 502, 0, 0, 503, 0, 0, 504, 505, - 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, - 516, 517, 518, 519, 520, 521, 522, 523, 524, 1513, + 417, 418, 419, 420, 0, 0, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 0, 0, 431, 432, 433, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 531, 448, 449, 0, 0, 450, + 451, 0, 452, 0, 454, 455, 456, 457, 458, 0, + 459, 460, 461, 0, 0, 462, 463, 464, 465, 466, + 0, 467, 468, 469, 470, 471, 472, 473, 474, 0, + 1776, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 487, 488, 489, 0, 490, + 0, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, + 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, + 517, 518, 519, 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 119, 120, - 121, 122, 123, 124, 125, 126, 0, 127, 128, 129, - 0, 0, 0, 1514, 0, 0, -836, 0, 1515, 131, - 132, 0, 1516, 134, 135, 1517, 137, 138, 139, 0, - 1518, 1519, 1520, 1521, 0, 145, 146, 147, 148, 149, - 150, 0, 0, 151, 152, 153, 154, 1522, 1523, 157, - 0, 158, 159, 160, 161, 0, 0, 1524, 0, 1525, - 165, 166, 167, 168, 169, 1526, 171, 172, 173, 0, - 174, 175, 176, 177, 178, 179, 0, 1527, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 1528, 192, - 193, 1529, 195, 0, 196, 0, 197, 198, 199, 200, - 201, 202, 0, 0, 203, 204, 205, 206, 0, 0, - 207, 208, 1079, 210, 211, 0, 212, 213, 214, 0, - 215, 216, 217, 0, 218, 219, 220, 221, 0, 223, - 224, 225, 226, 227, 228, 0, 0, 230, 0, 231, - 232, 1530, 234, 0, 235, 0, 236, 1531, 0, 1532, - 239, 240, -836, 1533, 243, 244, 245, 0, 0, 0, - 248, 249, 0, 250, 251, 252, 253, 254, 255, 256, - 1534, 258, 259, 260, 261, 0, 262, 263, 264, 265, - 266, 267, 268, 0, 269, 1535, 0, 272, 273, 274, - 275, 276, 1536, 1537, 0, 1538, 0, 280, 1539, 1540, - 283, 1541, 285, 286, 287, 288, 289, 290, 0, 0, - 291, 1542, 293, 1543, 0, 295, 296, 297, 298, 299, - 300, 301, 302, 1544, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 1545, 1546, 1547, 327, 328, 329, - 0, 0, 331, 332, 1548, 334, 0, 0, 336, 1549, - 338, 339, 340, 0, 341, 342, 0, 0, 343, 344, - 345, 0, 0, 346, 347, 0, 1550, 350, 1551, 0, - 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, - 363, 364, 0, 0, 0, 0, 365, 366, 0, 1552, - 369, 370, 0, 372, 373, 374, 0, 375, 376, 377, - 378, 379, 380, 0, 381, 382, 383, 384, 385, 1553, - 387, 388, 389, 390, 0, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 0, 404, - 405, 1554, 407, 408, 409, 1555, 411, 412, 413, 414, - 415, 416, 417, 418, 419, 420, 421, 422, 423, 0, - 1556, 424, 425, 426, 427, 428, 429, 1557, 431, 432, - 0, 1558, 434, 435, 1559, 437, 0, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, - 1560, 452, 0, 0, 0, 454, 455, 0, 456, 1561, - 458, 459, 460, 461, 462, 0, 463, 1562, 1563, 0, - 0, 466, 467, 0, 469, 0, 0, 471, 472, 1564, - 474, 475, 476, 477, 478, 1565, 0, 479, 480, 481, - 1566, 0, 482, 483, 484, 485, 0, 486, 487, 488, - 489, 490, 0, 1567, 493, 0, 494, 1568, 496, 497, - 498, 499, 500, 501, 502, 0, 0, 503, 0, 0, - 504, 505, 506, 507, 508, 509, 532, 0, 558, 0, - 0, 0, 0, 0, 0, 0, 0, 521, 522, 523, - 524, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 559, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 0, 0, 0, 118, 119, 120, 121, 122, 123, 124, + 125, 0, 126, 127, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 130, 131, 0, 132, 133, 134, + 0, 136, 137, 138, 139, 140, 0, 142, 143, 0, + 144, 145, 146, 147, 148, 149, 0, 0, 150, 151, + 152, 153, 154, 155, 156, 1770, 157, 158, 159, 160, + 161, 0, 0, 0, 163, 164, 165, 166, 167, 168, + 0, 170, 171, 172, 1772, 173, 174, 175, 176, 177, + 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 0, 195, + 0, 196, 197, 198, 199, 200, 201, 0, 0, 202, + 203, 204, 205, 0, 0, 206, 207, 208, 209, 210, + 0, 211, 212, 213, 0, 214, 215, 216, 0, 217, + 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, + 228, 0, 229, 0, 230, 231, 232, 233, 0, 234, + 1773, 235, 0, 0, 0, 238, 239, 529, 0, 242, + 0, 243, 0, 244, 245, 246, 247, 0, 248, 249, + 250, 251, 252, 253, 254, 0, 256, 257, 258, 259, + 0, 260, 261, 262, 263, 264, 265, 266, 0, 267, + 0, 269, 270, 271, 272, 273, 274, 275, 276, 0, + 277, 0, 278, 0, 0, 281, 0, 283, 284, 285, + 286, 287, 288, 0, 0, 289, 0, 291, 2372, 0, + 293, 294, 295, 296, 297, 298, 299, 300, 530, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 560, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, + 0, 324, 325, 326, 327, 328, 0, 329, 330, 0, + 332, 0, 333, 334, 335, 336, 337, 338, 0, 339, + 340, 0, 0, 341, 342, 343, 0, 0, 344, 345, + 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 0, 0, 0, 0, + 362, 363, 364, 0, 366, 367, 368, 369, 370, 371, + 1775, 372, 373, 374, 375, 376, 377, 0, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 0, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 558, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 801, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 558, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 909, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 801, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 532, 0, 558, 0, 0, 0, 0, 0, + 418, 419, 420, 0, 0, 421, 422, 423, 424, 425, + 426, 427, 428, 429, 0, 0, 431, 432, 433, 434, + 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 531, 448, 449, 0, 0, 450, 451, + 0, 452, 0, 454, 455, 456, 457, 458, 0, 459, + 460, 461, 0, 0, 462, 463, 464, 465, 466, 0, + 467, 468, 469, 470, 471, 472, 473, 474, 0, 1776, + 475, 476, 477, 0, 478, 479, 480, 481, 0, 482, + 483, 484, 485, 486, 487, 488, 489, 0, 490, 0, + 492, 493, 494, 495, 496, 497, 498, 0, 0, 499, + 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, + 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, + 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 954, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 243, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 464, 465, 0, 0, 466, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 493, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 558, 0, 0, 0, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 3, 4, 0, 0, 0, 0, + 0, 0, 0, 130, 131, 0, 132, 133, 134, 0, + 136, 137, 138, 139, 140, 0, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 0, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 161, + 0, 0, 0, 163, 164, 165, 166, 167, 168, 0, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 0, 0, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, + 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 0, 0, 0, 238, 239, 529, 0, 242, 0, + 243, 0, 244, 245, 246, 247, 0, 248, 249, 250, + 251, 252, 253, 254, 0, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 0, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 0, 0, 281, 0, 283, 284, 285, 286, + 287, 288, 0, 0, 289, 0, 291, 0, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 530, 302, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, 318, 319, 320, 321, 322, 0, + 324, 325, 326, 327, 328, 0, 329, 330, 0, 332, + 0, 333, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 0, 341, 342, 343, 0, 0, 344, 345, 346, + 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 0, 0, 0, 0, 362, + 363, 364, 0, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 383, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 0, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 0, 0, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 531, 448, 449, 0, 0, 450, 451, 0, + 452, 0, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 464, 465, 466, 0, 467, + 468, 469, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 0, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 487, 488, 489, 0, 490, 0, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, + 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, + 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 222, 223, 224, 225, 226, 1191, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 555, + 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 130, 131, 0, 132, 133, 134, 0, 136, + 137, 138, 139, 140, 0, 142, 143, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 154, 155, 156, 0, 157, 158, 159, 160, 161, 0, + 0, 0, 163, 164, 165, 166, 167, 168, 0, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 0, + 229, 0, 230, 231, 232, 233, 0, 234, 0, 235, + 0, 0, 0, 238, 239, 529, 0, 242, 0, 243, + 0, 244, 245, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 0, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 0, 269, + 270, 271, 272, 273, 274, 275, 276, 0, 277, 0, + 278, 0, 0, 281, 0, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 0, 291, 0, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 801, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 322, 0, 324, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 0, + 333, 334, 335, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 0, + 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 364, 0, 366, 367, 368, 556, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, + 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 558, 0, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 0, 431, 432, 433, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 531, 448, 449, 0, 0, 450, 451, 0, 452, + 0, 454, 455, 456, 457, 458, 0, 459, 460, 461, + 0, 0, 462, 463, 464, 465, 466, 0, 467, 468, + 469, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 488, 489, 0, 490, 0, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 2013, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 2014, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 2015, 456, 0, 458, 2016, 460, - 2017, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 2018, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 558, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 826, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 130, 131, 0, 132, 133, 134, 0, 136, 137, + 138, 139, 140, 0, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 0, 0, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 161, 0, 0, + 0, 163, 164, 165, 166, 167, 168, 0, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 0, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 228, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 0, + 0, 0, 238, 239, 529, 0, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 253, 254, 0, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 0, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 0, 0, 281, 0, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 0, 291, 0, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 322, 0, 324, 325, + 326, 327, 328, 0, 329, 330, 0, 332, 0, 333, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 796, + 341, 342, 343, 0, 0, 344, 345, 346, 0, 348, + 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 364, + 0, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 0, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 531, 448, 449, 0, 0, 450, 451, 0, 452, 0, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 464, 465, 466, 0, 467, 468, 469, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 0, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, + 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, + 119, 120, 121, 122, 123, 124, 125, 0, 126, 127, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 130, 131, 0, 132, 133, 134, 0, 136, 137, 138, + 139, 140, 0, 142, 143, 0, 144, 145, 146, 147, + 148, 149, 0, 0, 150, 151, 152, 153, 154, 155, + 156, 0, 157, 158, 159, 160, 161, 0, 0, 0, + 163, 164, 165, 166, 167, 168, 0, 170, 171, 172, + 0, 173, 174, 175, 176, 177, 178, 0, 0, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 0, 195, 0, 196, 197, 198, + 199, 200, 201, 0, 0, 202, 203, 204, 205, 0, + 0, 206, 207, 208, 209, 210, 0, 211, 212, 213, + 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 0, 229, 0, + 230, 231, 232, 233, 0, 234, 0, 235, 0, 0, + 0, 238, 239, 529, 0, 242, 0, 243, 0, 244, + 245, 246, 247, 0, 248, 249, 250, 251, 252, 904, + 254, 0, 256, 257, 258, 259, 0, 260, 261, 262, + 263, 264, 265, 266, 0, 267, 0, 269, 270, 271, + 272, 273, 274, 275, 276, 0, 277, 0, 278, 0, + 0, 281, 0, 283, 284, 285, 286, 287, 288, 0, + 0, 289, 0, 291, 0, 0, 293, 294, 295, 296, + 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 322, 0, 324, 325, 326, + 327, 328, 0, 329, 330, 0, 332, 0, 333, 334, + 335, 336, 337, 338, 0, 339, 340, 0, 796, 341, + 342, 343, 0, 0, 344, 345, 346, 0, 348, 0, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 0, 0, 0, 0, 362, 363, 364, 0, + 366, 367, 368, 369, 370, 371, 0, 372, 373, 374, + 375, 376, 377, 0, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 0, 401, + 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 0, + 0, 421, 422, 423, 424, 425, 426, 427, 428, 429, + 0, 0, 431, 432, 433, 434, 0, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 531, + 448, 449, 0, 0, 450, 451, 0, 452, 0, 454, + 455, 456, 457, 458, 0, 459, 460, 461, 0, 0, + 462, 463, 464, 465, 466, 0, 467, 468, 469, 470, + 471, 472, 473, 474, 0, 0, 475, 476, 477, 0, + 478, 479, 480, 481, 0, 482, 483, 484, 485, 486, + 487, 488, 489, 0, 490, 0, 492, 493, 494, 495, + 496, 497, 498, 0, 0, 499, 0, 0, 500, 501, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 528, + 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 948, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 0, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 253, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 0, 0, 0, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 0, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 0, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 0, 0, 450, 451, 0, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 460, 461, 0, 0, 462, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 0, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 487, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 0, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 528, 0, + 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 118, 119, 120, + 121, 122, 123, 124, 125, 0, 126, 127, 128, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 130, 131, + 0, 132, 133, 134, 0, 136, 137, 138, 139, 140, + 0, 142, 143, 0, 144, 145, 146, 147, 148, 149, + 0, 0, 150, 151, 152, 153, 154, 155, 156, 0, + 157, 158, 159, 160, 161, 0, 0, 0, 163, 164, + 165, 166, 167, 168, 0, 170, 171, 172, 0, 173, + 174, 175, 176, 177, 178, 0, 0, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, + 193, 194, 0, 195, 0, 196, 197, 198, 199, 200, + 201, 0, 0, 202, 203, 204, 205, 0, 0, 206, + 207, 208, 209, 210, 0, 211, 212, 213, 0, 214, + 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 1184, 227, 228, 0, 229, 0, 230, 231, + 232, 233, 0, 234, 0, 235, 0, 0, 0, 238, + 239, 529, 0, 242, 0, 243, 0, 244, 245, 246, + 247, 0, 248, 249, 250, 251, 252, 253, 254, 0, + 256, 257, 258, 259, 0, 260, 261, 262, 263, 264, + 265, 266, 0, 267, 0, 269, 270, 271, 272, 273, + 274, 275, 276, 0, 277, 0, 278, 0, 0, 281, + 0, 283, 284, 285, 286, 287, 288, 0, 0, 289, + 0, 291, 0, 0, 293, 294, 295, 296, 297, 298, + 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, + 319, 320, 321, 322, 0, 324, 325, 326, 327, 328, + 0, 329, 330, 0, 332, 0, 333, 334, 335, 336, + 337, 338, 0, 339, 340, 0, 796, 341, 342, 343, + 0, 0, 344, 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 532, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 832, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 833, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 834, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 835, 429, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 836, 465, 0, 0, 837, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 838, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 558, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 871, 390, 0, - 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 558, 0, + 0, 0, 0, 0, 362, 363, 364, 0, 366, 367, + 368, 369, 370, 371, 0, 372, 373, 374, 375, 376, + 377, 0, 378, 379, 380, 381, 382, 383, 384, 385, + 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 0, 401, 402, 0, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, 415, 416, 417, 418, 419, 420, 0, 0, 421, + 422, 423, 424, 425, 426, 427, 428, 429, 0, 0, + 431, 432, 433, 434, 0, 435, 436, 437, 438, 439, + 440, 441, 442, 443, 444, 445, 446, 531, 448, 449, + 0, 0, 450, 451, 0, 452, 0, 454, 455, 456, + 457, 458, 0, 459, 460, 461, 0, 0, 462, 463, + 464, 465, 466, 0, 467, 468, 469, 470, 471, 472, + 473, 474, 0, 0, 475, 476, 477, 0, 478, 479, + 480, 481, 0, 482, 483, 484, 485, 486, 487, 488, + 489, 0, 490, 0, 492, 493, 494, 495, 496, 497, + 498, 0, 0, 499, 0, 0, 500, 501, 502, 503, + 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, + 514, 515, 516, 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 904, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 558, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 130, 131, 0, + 132, 133, 134, 0, 136, 137, 138, 139, 140, 0, + 142, 143, 0, 144, 145, 146, 147, 148, 149, 0, + 0, 150, 151, 152, 153, 154, 155, 156, 0, 157, + 158, 159, 160, 161, 0, 0, 0, 163, 164, 165, + 166, 167, 168, 0, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 907, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 208, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 0, 229, 0, 230, 231, 232, + 233, 0, 234, 0, 235, 0, 0, 0, 238, 239, + 529, 0, 1992, 0, 243, 0, 244, 245, 246, 247, + 0, 248, 249, 250, 251, 252, 253, 254, 0, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 0, 269, 270, 271, 272, 273, 274, + 275, 276, 0, 277, 0, 278, 0, 0, 281, 0, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 0, + 291, 0, 0, 293, 294, 1993, 296, 297, 298, 299, + 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 322, 0, 324, 325, 326, 327, 328, 0, + 329, 330, 0, 332, 0, 333, 334, 335, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 0, 348, 0, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 364, 0, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 383, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 0, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 0, 431, + 432, 433, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 531, 448, 449, 0, + 0, 450, 451, 1994, 452, 0, 454, 1995, 456, 1996, + 458, 0, 459, 460, 461, 0, 0, 462, 463, 464, + 465, 466, 0, 467, 468, 469, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 1997, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 488, 489, + 0, 490, 0, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 558, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 911, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 532, 0, 558, 0, 0, 0, 0, 0, + 515, 516, 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 243, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 942, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 464, 465, 0, 0, 466, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 493, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 558, 0, 0, 0, + 0, 0, 0, 0, 0, 118, 119, 120, 121, 122, + 123, 124, 125, 0, 126, 127, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 130, 131, 0, 132, + 133, 134, 0, 136, 137, 138, 139, 140, 0, 142, + 143, 0, 144, 145, 146, 147, 148, 149, 0, 0, + 150, 151, 152, 153, 154, 155, 156, 0, 157, 158, + 159, 160, 161, 0, 0, 0, 163, 164, 165, 166, + 167, 168, 0, 170, 171, 172, 0, 173, 174, 175, + 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 0, 195, 0, 196, 197, 198, 199, 200, 201, 0, + 0, 202, 203, 204, 205, 0, 0, 206, 207, 208, + 209, 210, 0, 211, 212, 213, 0, 214, 215, 216, + 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, + 226, 227, 228, 0, 229, 0, 230, 231, 232, 233, + 0, 234, 0, 235, 0, 0, 0, 238, 239, 529, + 0, 242, 0, 243, 0, 244, 245, 246, 247, 0, + 248, 249, 250, 251, 252, 253, 254, 0, 256, 257, + 258, 259, 0, 260, 261, 262, 263, 264, 265, 266, + 0, 267, 0, 269, 270, 271, 272, 273, 274, 275, + 276, 0, 277, 0, 278, 0, 0, 281, 0, 283, + 284, 285, 286, 287, 288, 0, 0, 289, 0, 291, + 0, 0, 293, 294, 295, 296, 297, 298, 299, 300, + 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, + 321, 322, 0, 324, 325, 326, 327, 328, 0, 329, + 330, 0, 332, 0, 333, 334, 335, 336, 337, 338, + 0, 339, 340, 0, 0, 341, 342, 343, 0, 0, + 344, 345, 346, 0, 348, 0, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, 361, 0, 0, + 0, 0, 362, 363, 364, 0, 366, 367, 368, 369, + 370, 371, 0, 372, 373, 374, 375, 376, 377, 0, + 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, + 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, + 397, 398, 399, 400, 0, 401, 402, 0, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + 416, 417, 418, 419, 420, 0, 0, 421, 422, 423, + 424, 425, 426, 427, 428, 429, 0, 0, 431, 432, + 433, 434, 0, 435, 436, 437, 438, 439, 440, 441, + 442, 443, 444, 445, 446, 531, 448, 449, 0, 0, + 450, 451, 0, 452, 0, 454, 455, 456, 457, 458, + 0, 459, 460, 461, 0, 0, 462, 463, 464, 465, + 466, 0, 467, 468, 469, 470, 471, 472, 473, 474, + 0, 0, 475, 476, 477, 0, 478, 479, 480, 481, + 0, 482, 483, 484, 485, 486, 487, 488, 489, 0, + 490, 0, 492, 493, 494, 495, 496, 497, 498, 0, + 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, + 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, + 516, 517, 518, 519, 520, 528, 0, 821, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 970, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 0, - 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 558, 0, + 0, 0, 0, 0, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 130, 131, 0, 132, 133, + 134, 0, 136, 137, 138, 139, 140, 0, 142, 143, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 154, 155, 156, 0, 157, 158, 159, + 160, 161, 0, 0, 0, 163, 164, 165, 166, 167, + 168, 0, 170, 171, 172, 0, 173, 174, 175, 176, + 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 208, 209, + 210, 0, 211, 212, 213, 0, 214, 215, 216, 0, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 0, 229, 0, 230, 231, 232, 233, 0, + 234, 0, 235, 0, 0, 0, 238, 239, 529, 0, + 242, 0, 243, 0, 244, 245, 246, 247, 0, 248, + 249, 250, 251, 252, 253, 254, 0, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 0, 269, 270, 271, 272, 273, 274, 275, 276, + 0, 277, 0, 278, 0, 0, 281, 0, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 0, 291, 0, + 0, 293, 294, 295, 296, 297, 298, 299, 300, 530, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, + 322, 0, 324, 325, 326, 327, 328, 0, 329, 330, + 0, 332, 0, 333, 334, 335, 336, 337, 338, 0, + 339, 340, 0, 0, 341, 342, 343, 0, 0, 344, + 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 364, 0, 366, 367, 368, 369, 370, + 371, 0, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 0, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, + 417, 418, 419, 420, 0, 0, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 0, 0, 431, 432, 433, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 531, 448, 449, 0, 0, 450, + 451, 0, 452, 0, 454, 455, 456, 457, 458, 0, + 459, 460, 461, 0, 0, 462, 463, 464, 465, 466, + 0, 467, 468, 469, 470, 471, 472, 473, 474, 0, + 0, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 487, 488, 489, 0, 490, + 0, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, + 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, + 517, 518, 519, 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 973, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 0, 0, 0, 118, 119, 120, 121, 122, 123, 124, + 125, 827, 126, 127, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 130, 131, 0, 132, 133, 134, + 0, 136, 137, 138, 139, 140, 0, 142, 143, 0, + 144, 145, 146, 147, 148, 149, 0, 0, 150, 151, + 152, 153, 154, 155, 156, 0, 157, 158, 159, 160, + 161, 0, 0, 0, 163, 164, 165, 166, 167, 168, + 0, 170, 171, 172, 0, 173, 174, 175, 176, 177, + 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 0, 195, + 0, 196, 197, 198, 199, 200, 201, 0, 0, 202, + 203, 204, 205, 0, 0, 206, 207, 208, 209, 210, + 0, 211, 212, 213, 0, 214, 215, 216, 0, 217, + 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, + 228, 0, 229, 0, 230, 231, 232, 233, 0, 234, + 0, 235, 0, 0, 0, 238, 239, 529, 0, 828, + 0, 243, 0, 244, 245, 246, 247, 0, 248, 249, + 250, 251, 252, 253, 254, 0, 256, 257, 258, 259, + 0, 260, 261, 262, 263, 264, 265, 266, 0, 267, + 0, 269, 270, 271, 272, 273, 274, 275, 276, 0, + 277, 0, 278, 0, 0, 281, 0, 283, 284, 285, + 286, 287, 288, 0, 0, 289, 0, 291, 0, 0, + 293, 294, 829, 296, 297, 298, 299, 300, 530, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, + 0, 324, 325, 326, 327, 328, 0, 329, 330, 0, + 332, 0, 333, 334, 335, 336, 337, 338, 0, 339, + 340, 0, 0, 341, 342, 343, 0, 0, 344, 345, + 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 0, 0, 0, 0, + 362, 363, 364, 0, 366, 367, 368, 369, 370, 371, + 0, 372, 373, 374, 375, 376, 377, 0, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 0, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 1016, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 255, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 1043, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 532, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 832, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 243, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 836, 465, 0, 0, 837, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 493, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 558, 0, 0, 0, + 418, 419, 420, 0, 0, 421, 422, 423, 424, 830, + 426, 427, 428, 429, 0, 0, 431, 432, 433, 434, + 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 531, 448, 449, 0, 0, 450, 451, + 0, 452, 0, 454, 455, 456, 457, 458, 0, 459, + 831, 461, 0, 0, 832, 463, 464, 465, 466, 0, + 467, 468, 469, 470, 471, 472, 473, 474, 0, 0, + 475, 476, 477, 0, 478, 479, 480, 481, 0, 482, + 483, 484, 485, 486, 487, 488, 833, 0, 490, 0, + 492, 493, 494, 495, 496, 497, 498, 0, 0, 499, + 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, + 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, + 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 130, 131, 0, 132, 133, 134, 0, + 136, 137, 138, 139, 140, 0, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 0, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 161, + 0, 0, 0, 163, 164, 165, 166, 167, 168, 0, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 0, 0, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 1336, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 0, 0, 0, 238, 239, 529, 0, 242, 0, + 243, 0, 244, 245, 246, 247, 0, 248, 249, 250, + 251, 252, 253, 254, 0, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 0, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 0, 0, 281, 0, 283, 284, 285, 286, + 287, 288, 0, 0, 289, 0, 291, 0, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 530, 302, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, 318, 319, 320, 321, 322, 0, + 324, 325, 326, 327, 328, 0, 329, 330, 0, 332, + 0, 333, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 0, 341, 342, 343, 0, 0, 344, 345, 346, + 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 0, 0, 0, 0, 362, + 363, 364, 0, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 383, 384, 385, 866, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 0, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 0, 0, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 531, 448, 449, 0, 0, 450, 451, 0, + 452, 0, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 464, 465, 466, 0, 467, + 468, 469, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 0, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 487, 488, 489, 0, 490, 0, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, + 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, + 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 130, 131, 0, 132, 133, 134, 0, 136, + 137, 138, 139, 140, 0, 142, 143, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 154, 155, 156, 0, 157, 158, 159, 160, 161, 0, + 0, 0, 163, 164, 165, 166, 167, 168, 0, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 0, + 229, 0, 230, 231, 232, 233, 0, 234, 0, 235, + 0, 0, 0, 238, 239, 529, 0, 242, 0, 243, + 0, 244, 245, 246, 247, 0, 248, 249, 250, 251, + 252, 899, 254, 0, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 0, 269, + 270, 271, 272, 273, 274, 275, 276, 0, 277, 0, + 278, 0, 0, 281, 0, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 0, 291, 0, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 322, 0, 324, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 0, + 333, 334, 335, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 0, + 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 364, 0, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, + 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 558, 0, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 0, 431, 432, 433, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 531, 448, 449, 0, 0, 450, 451, 0, 452, + 0, 454, 455, 456, 457, 458, 0, 459, 460, 461, + 0, 0, 462, 463, 464, 465, 466, 0, 467, 468, + 469, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 488, 489, 0, 490, 0, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 1338, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 558, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 1341, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 558, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 130, 131, 0, 132, 133, 134, 0, 136, 137, + 138, 139, 140, 0, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 0, 0, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 161, 0, 0, + 0, 163, 164, 165, 166, 167, 168, 0, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 0, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 228, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 0, + 0, 0, 238, 239, 529, 0, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 902, 254, 0, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 0, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 0, 0, 281, 0, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 0, 291, 0, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 322, 0, 324, 325, + 326, 327, 328, 0, 329, 330, 0, 332, 0, 333, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 346, 0, 348, + 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 364, + 0, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 0, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 531, 448, 449, 0, 0, 450, 451, 0, 452, 0, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 464, 465, 466, 0, 467, 468, 469, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 0, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, + 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, + 119, 120, 121, 122, 123, 124, 125, 0, 126, 127, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 130, 131, 0, 132, 133, 134, 0, 136, 137, 138, + 139, 140, 0, 142, 143, 0, 144, 145, 146, 147, + 148, 149, 0, 0, 150, 151, 152, 153, 154, 155, + 156, 0, 157, 158, 159, 160, 161, 0, 0, 0, + 163, 164, 165, 166, 167, 168, 0, 170, 171, 172, + 0, 173, 174, 175, 176, 177, 178, 0, 0, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 0, 195, 0, 196, 197, 198, + 199, 200, 201, 0, 0, 202, 203, 204, 205, 0, + 0, 206, 207, 208, 209, 210, 0, 211, 212, 213, + 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 0, 229, 0, + 230, 231, 232, 233, 0, 234, 0, 235, 0, 0, + 0, 238, 239, 529, 0, 242, 0, 243, 0, 244, + 245, 246, 247, 0, 248, 249, 250, 251, 252, 906, + 254, 0, 256, 257, 258, 259, 0, 260, 261, 262, + 263, 264, 265, 266, 0, 267, 0, 269, 270, 271, + 272, 273, 274, 275, 276, 0, 277, 0, 278, 0, + 0, 281, 0, 283, 284, 285, 286, 287, 288, 0, + 0, 289, 0, 291, 0, 0, 293, 294, 295, 296, + 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 322, 0, 324, 325, 326, + 327, 328, 0, 329, 330, 0, 332, 0, 333, 334, + 335, 336, 337, 338, 0, 339, 340, 0, 0, 341, + 342, 343, 0, 0, 344, 345, 346, 0, 348, 0, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 0, 0, 0, 0, 362, 363, 364, 0, + 366, 367, 368, 369, 370, 371, 0, 372, 373, 374, + 375, 376, 377, 0, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 0, 401, + 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 0, + 0, 421, 422, 423, 424, 425, 426, 427, 428, 429, + 0, 0, 431, 432, 433, 434, 0, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 531, + 448, 449, 0, 0, 450, 451, 0, 452, 0, 454, + 455, 456, 457, 458, 0, 459, 460, 461, 0, 0, + 462, 463, 464, 465, 466, 0, 467, 468, 469, 470, + 471, 472, 473, 474, 0, 0, 475, 476, 477, 0, + 478, 479, 480, 481, 0, 482, 483, 484, 485, 486, + 487, 488, 489, 0, 490, 0, 492, 493, 494, 495, + 496, 497, 498, 0, 0, 499, 0, 0, 500, 501, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 528, + 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 1343, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 0, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 936, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 0, 0, 0, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 0, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 0, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 0, 0, 450, 451, 0, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 460, 461, 0, 0, 462, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 0, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 487, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 0, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 528, 0, + 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 118, 119, 120, + 121, 122, 123, 124, 125, 0, 126, 127, 128, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 130, 131, + 0, 132, 133, 134, 0, 136, 137, 138, 139, 140, + 0, 142, 143, 0, 144, 145, 146, 147, 148, 149, + 0, 0, 150, 151, 152, 153, 154, 155, 156, 0, + 157, 158, 159, 160, 161, 0, 0, 0, 163, 164, + 165, 166, 167, 168, 0, 170, 171, 172, 0, 173, + 174, 175, 176, 177, 178, 0, 0, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, + 193, 194, 0, 195, 0, 196, 197, 198, 199, 200, + 201, 0, 0, 202, 203, 204, 205, 0, 0, 206, + 207, 208, 209, 210, 0, 211, 212, 213, 0, 214, + 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 0, 229, 0, 230, 231, + 232, 233, 0, 234, 0, 235, 0, 0, 0, 238, + 239, 529, 0, 242, 0, 243, 0, 244, 245, 246, + 247, 0, 248, 249, 250, 251, 252, 964, 254, 0, + 256, 257, 258, 259, 0, 260, 261, 262, 263, 264, + 265, 266, 0, 267, 0, 269, 270, 271, 272, 273, + 274, 275, 276, 0, 277, 0, 278, 0, 0, 281, + 0, 283, 284, 285, 286, 287, 288, 0, 0, 289, + 0, 291, 0, 0, 293, 294, 295, 296, 297, 298, + 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, + 319, 320, 321, 322, 0, 324, 325, 326, 327, 328, + 0, 329, 330, 0, 332, 0, 333, 334, 335, 336, + 337, 338, 0, 339, 340, 0, 0, 341, 342, 343, + 0, 0, 344, 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 1513, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 1514, 0, 0, 0, - 0, 1515, 131, 132, 0, 1516, 134, 135, 1517, 137, - 138, 139, 0, 1518, 1519, 1520, 1521, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 1522, 1523, 157, 0, 158, 159, 160, 161, 0, 0, - 1524, 0, 1525, 165, 166, 167, 168, 169, 1526, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 1527, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 1528, 192, 193, 1529, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 1079, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 0, 223, 224, 225, 226, 227, 228, 0, 0, - 230, 0, 231, 232, 1530, 234, 0, 235, 0, 236, - 1531, 0, 1532, 239, 240, 0, 1533, 243, 244, 245, - 0, 0, 0, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 1534, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 1535, 0, - 272, 273, 274, 275, 276, 1536, 1537, 0, 1538, 0, - 280, 1539, 1540, 283, 1541, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 1542, 293, 1543, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 1544, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 1545, 1546, 1547, - 327, 328, 329, 0, 0, 331, 332, 1548, 334, 0, - 0, 336, 1549, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 0, 1550, - 350, 1551, 0, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 0, 1552, 369, 370, 0, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 1553, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 1554, 407, 408, 409, 1555, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 1556, 424, 425, 426, 427, 428, 429, - 1557, 431, 432, 0, 1558, 434, 435, 1559, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 1560, 452, 0, 0, 0, 454, 455, - 0, 456, 1561, 458, 459, 460, 461, 462, 0, 463, - 1562, 1563, 0, 0, 466, 467, 0, 469, 0, 0, - 471, 472, 1564, 474, 475, 476, 477, 478, 1565, 0, - 479, 480, 481, 1566, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 0, 1567, 493, 0, 494, - 1568, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 1513, + 0, 0, 0, 0, 362, 363, 364, 0, 366, 367, + 368, 369, 370, 371, 0, 372, 373, 374, 375, 376, + 377, 0, 378, 379, 380, 381, 382, 383, 384, 385, + 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 0, 401, 402, 0, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, 415, 416, 417, 418, 419, 420, 0, 0, 421, + 422, 423, 424, 425, 426, 427, 428, 429, 0, 0, + 431, 432, 433, 434, 0, 435, 436, 437, 438, 439, + 440, 441, 442, 443, 444, 445, 446, 531, 448, 449, + 0, 0, 450, 451, 0, 452, 0, 454, 455, 456, + 457, 458, 0, 459, 460, 461, 0, 0, 462, 463, + 464, 465, 466, 0, 467, 468, 469, 470, 471, 472, + 473, 474, 0, 0, 475, 476, 477, 0, 478, 479, + 480, 481, 0, 482, 483, 484, 485, 486, 487, 488, + 489, 0, 490, 0, 492, 493, 494, 495, 496, 497, + 498, 0, 0, 499, 0, 0, 500, 501, 502, 503, + 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, + 514, 515, 516, 517, 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 521, 522, 523, 524, 0, 0, 0, 0, 119, 120, - 121, 122, 123, 124, 125, 126, 0, 127, 128, 129, - 0, 0, 0, 1514, 0, 0, 0, 0, 1515, 131, - 132, 0, 1516, 134, 135, 1517, 137, 138, 139, 0, - 1518, 1519, 1520, 1521, 0, 145, 146, 147, 148, 149, - 150, 0, 0, 151, 152, 153, 154, 1522, 1523, 157, - 0, 158, 159, 160, 161, 0, 0, 1524, 0, 1525, - 165, 166, 167, 168, 169, 1526, 171, 172, 173, 0, - 174, 175, 176, 177, 178, 179, 0, 1527, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 1528, 192, - 193, 1529, 195, 0, 196, 0, 197, 198, 199, 200, - 201, 202, 0, 0, 203, 204, 205, 206, 0, 0, - 207, 208, 1079, 210, 211, 0, 212, 213, 214, 0, - 1884, 216, 217, 0, 218, 219, 220, 221, 0, 223, - 224, 225, 226, 227, 228, 0, 0, 230, 0, 231, - 232, 1530, 234, 0, 235, 0, 236, 1531, 0, 1532, - 239, 240, 0, 1533, 243, 244, 245, 0, 0, 0, - 248, 249, 0, 250, 251, 252, 253, 254, 255, 256, - 1534, 258, 259, 260, 261, 0, 262, 263, 264, 265, - 266, 267, 268, 0, 269, 1535, 0, 272, 273, 274, - 275, 276, 1536, 1537, 0, 1538, 0, 280, 1539, 1540, - 283, 1541, 285, 286, 287, 288, 289, 290, 0, 0, - 291, 1542, 293, 1543, 0, 295, 296, 297, 298, 299, - 300, 301, 302, 1544, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 1545, 1546, 1547, 327, 328, 329, - 0, 0, 331, 332, 1548, 334, 0, 0, 336, 1549, - 338, 339, 340, 0, 341, 342, 0, 0, 343, 344, - 345, 0, 0, 346, 347, 0, 1550, 350, 1551, 0, - 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, - 363, 364, 0, 0, 0, 0, 365, 366, 0, 1552, - 369, 370, 0, 372, 373, 374, 0, 375, 376, 377, - 378, 379, 380, 0, 381, 382, 383, 384, 385, 1553, - 387, 388, 389, 390, 0, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 0, 404, - 405, 1554, 407, 408, 409, 1555, 411, 412, 413, 414, - 415, 416, 417, 418, 419, 420, 421, 422, 423, 0, - 1556, 424, 425, 426, 427, 428, 429, 1557, 431, 432, - 0, 1558, 434, 435, 1559, 437, 0, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, - 1560, 452, 0, 0, 0, 454, 455, 0, 456, 1561, - 458, 459, 460, 461, 462, 0, 463, 1562, 1563, 0, - 0, 466, 467, 0, 469, 0, 0, 471, 472, 1564, - 474, 475, 476, 477, 478, 1565, 0, 479, 480, 481, - 1566, 0, 482, 483, 484, 485, 0, 486, 487, 488, - 489, 490, 0, 1567, 493, 0, 494, 1568, 496, 497, - 498, 499, 500, 501, 502, 0, 0, 503, 0, 0, - 504, 505, 506, 507, 508, 509, 532, 0, 558, 0, - 0, 0, 0, 0, 0, 0, 0, 521, 522, 523, - 524, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 2311, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, - 558, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 130, 131, 0, + 132, 133, 134, 0, 136, 137, 138, 139, 140, 0, + 142, 143, 0, 144, 145, 146, 147, 148, 149, 0, + 0, 150, 151, 152, 153, 154, 155, 156, 0, 157, + 158, 159, 160, 161, 0, 0, 0, 163, 164, 165, + 166, 167, 168, 0, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 3111, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 208, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 0, 229, 0, 230, 231, 232, + 233, 0, 234, 0, 235, 0, 0, 0, 238, 239, + 529, 0, 242, 0, 243, 0, 244, 245, 246, 247, + 0, 248, 249, 250, 251, 252, 967, 254, 0, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 0, 269, 270, 271, 272, 273, 274, + 275, 276, 0, 277, 0, 278, 0, 0, 281, 0, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 0, + 291, 0, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 322, 0, 324, 325, 326, 327, 328, 0, + 329, 330, 0, 332, 0, 333, 334, 335, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 0, 348, 0, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 364, 0, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 383, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 0, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 0, 431, + 432, 433, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 531, 448, 449, 0, + 0, 450, 451, 0, 452, 0, 454, 455, 456, 457, + 458, 0, 459, 460, 461, 0, 0, 462, 463, 464, + 465, 466, 0, 467, 468, 469, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 488, 489, + 0, 490, 0, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 532, 0, 0, 0, 0, 0, 0, 0, + 515, 516, 517, 518, 519, 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 848, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 849, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 850, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 851, 429, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 852, 465, 0, 0, 466, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 853, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 118, 119, 120, 121, 122, + 123, 124, 125, 0, 126, 127, 128, 0, 0, 0, + 0, 0, 0, 1010, 0, 0, 130, 131, 0, 132, + 133, 134, 0, 136, 137, 138, 139, 140, 0, 142, + 143, 0, 144, 145, 146, 147, 148, 149, 0, 0, + 150, 151, 152, 153, 154, 155, 156, 0, 157, 158, + 159, 160, 161, 0, 0, 0, 163, 164, 165, 166, + 167, 168, 0, 170, 171, 172, 0, 173, 174, 175, + 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 0, 195, 0, 196, 197, 198, 199, 200, 201, 0, + 0, 202, 203, 204, 205, 0, 0, 206, 207, 208, + 209, 210, 0, 211, 212, 213, 0, 214, 215, 216, + 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, + 226, 227, 228, 0, 229, 0, 230, 231, 232, 233, + 0, 234, 0, 235, 0, 0, 0, 238, 239, 529, + 0, 242, 0, 243, 0, 244, 245, 246, 247, 0, + 248, 249, 250, 251, 252, 253, 254, 0, 256, 257, + 258, 259, 0, 260, 261, 262, 263, 264, 265, 266, + 0, 267, 0, 269, 270, 271, 272, 273, 274, 275, + 276, 0, 277, 0, 278, 0, 0, 281, 0, 283, + 284, 285, 286, 287, 288, 0, 0, 289, 0, 291, + 0, 0, 293, 294, 295, 296, 297, 298, 299, 300, + 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, + 321, 322, 0, 324, 325, 326, 327, 328, 0, 329, + 330, 0, 332, 0, 333, 334, 335, 336, 337, 338, + 0, 339, 340, 0, 0, 341, 342, 343, 0, 0, + 344, 345, 346, 0, 348, 0, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, 361, 0, 0, + 0, 0, 362, 363, 364, 0, 366, 367, 368, 369, + 370, 371, 0, 372, 373, 374, 375, 376, 377, 0, + 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, + 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, + 397, 398, 399, 400, 0, 401, 402, 0, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + 416, 417, 418, 419, 420, 0, 0, 421, 422, 423, + 424, 425, 426, 427, 428, 429, 0, 0, 431, 432, + 433, 434, 0, 435, 436, 437, 438, 439, 440, 441, + 442, 443, 444, 445, 446, 531, 448, 449, 0, 0, + 450, 451, 0, 452, 0, 454, 455, 456, 457, 458, + 0, 459, 460, 461, 0, 0, 462, 463, 464, 465, + 466, 0, 467, 468, 469, 470, 471, 472, 473, 474, + 0, 0, 475, 476, 477, 0, 478, 479, 480, 481, + 0, 482, 483, 484, 485, 486, 487, 488, 489, 0, + 490, 0, 492, 493, 494, 495, 496, 497, 498, 0, + 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, + 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, + 516, 517, 518, 519, 520, 528, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, + 0, 0, 1037, 0, 0, 130, 131, 0, 132, 133, + 134, 0, 136, 137, 138, 139, 140, 0, 142, 143, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 154, 155, 156, 0, 157, 158, 159, + 160, 161, 0, 0, 0, 163, 164, 165, 166, 167, + 168, 0, 170, 171, 172, 0, 173, 174, 175, 176, + 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 208, 209, + 210, 0, 211, 212, 213, 0, 214, 215, 216, 0, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 0, 229, 0, 230, 231, 232, 233, 0, + 234, 0, 235, 0, 0, 0, 238, 239, 529, 0, + 242, 0, 243, 0, 244, 245, 246, 247, 0, 248, + 249, 250, 251, 252, 253, 254, 0, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 0, 269, 270, 271, 272, 273, 274, 275, 276, + 0, 277, 0, 278, 0, 0, 281, 0, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 0, 291, 0, + 0, 293, 294, 295, 296, 297, 298, 299, 300, 530, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, + 322, 0, 324, 325, 326, 327, 328, 0, 329, 330, + 0, 332, 0, 333, 334, 335, 336, 337, 338, 0, + 339, 340, 0, 0, 341, 342, 343, 0, 0, 344, + 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 364, 0, 366, 367, 368, 369, 370, + 371, 0, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 0, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, + 417, 418, 419, 420, 0, 0, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 0, 0, 431, 432, 433, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 531, 448, 449, 0, 0, 450, + 451, 0, 452, 0, 454, 455, 456, 457, 458, 0, + 459, 460, 461, 0, 0, 462, 463, 464, 465, 466, + 0, 467, 468, 469, 470, 471, 472, 473, 474, 0, + 0, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 487, 488, 489, 0, 490, + 0, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, + 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, + 517, 518, 519, 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, + 0, 0, 0, 118, 119, 120, 121, 122, 123, 124, + 125, 827, 126, 127, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 130, 131, 0, 132, 133, 134, + 0, 136, 137, 138, 139, 140, 0, 142, 143, 0, + 144, 145, 146, 147, 148, 149, 0, 0, 150, 151, + 152, 153, 154, 155, 156, 0, 157, 158, 159, 160, + 161, 0, 0, 0, 163, 164, 165, 166, 167, 168, + 0, 170, 171, 172, 0, 173, 174, 175, 176, 177, + 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 0, 195, + 0, 196, 197, 198, 199, 200, 201, 0, 0, 202, + 203, 204, 205, 0, 0, 206, 207, 208, 209, 210, + 0, 211, 212, 213, 0, 214, 215, 216, 0, 217, + 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, + 228, 0, 229, 0, 230, 231, 232, 233, 0, 234, + 0, 235, 0, 0, 0, 238, 239, 529, 0, 242, + 0, 243, 0, 244, 245, 246, 247, 0, 248, 249, + 250, 251, 252, 253, 254, 0, 256, 257, 258, 259, + 0, 260, 261, 262, 263, 264, 265, 266, 0, 267, + 0, 269, 270, 271, 272, 273, 274, 275, 276, 0, + 277, 0, 278, 0, 0, 281, 0, 283, 284, 285, + 286, 287, 288, 0, 0, 289, 0, 291, 0, 0, + 293, 294, 295, 296, 297, 298, 299, 300, 530, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, + 0, 324, 325, 326, 327, 328, 0, 329, 330, 0, + 332, 0, 333, 334, 335, 336, 337, 338, 0, 339, + 340, 0, 0, 341, 342, 343, 0, 0, 344, 345, + 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 0, 0, 0, 0, + 362, 363, 364, 0, 366, 367, 368, 369, 370, 371, + 0, 372, 373, 374, 375, 376, 377, 0, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 0, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 0, 401, 402, 0, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, + 418, 419, 420, 0, 0, 421, 422, 423, 424, 425, + 426, 427, 428, 429, 0, 0, 431, 432, 433, 434, + 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 531, 448, 449, 0, 0, 450, 451, + 0, 452, 0, 454, 455, 456, 457, 458, 0, 459, + 831, 461, 0, 0, 832, 463, 464, 465, 466, 0, + 467, 468, 469, 470, 471, 472, 473, 474, 0, 0, + 475, 476, 477, 0, 478, 479, 480, 481, 0, 482, + 483, 484, 485, 486, 487, 488, 489, 0, 490, 0, + 492, 493, 494, 495, 496, 497, 498, 0, 0, 499, + 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, + 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, + 518, 519, 520, 528, 0, 554, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 130, 131, 0, 132, 133, 134, 0, + 136, 137, 138, 139, 140, 0, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 0, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 161, + 0, 0, 0, 163, 164, 165, 166, 167, 168, 0, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 0, 0, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 966, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 0, 0, 0, 238, 239, 529, 0, 242, 0, + 243, 0, 244, 245, 246, 247, 0, 248, 249, 250, + 251, 252, 1326, 254, 0, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 0, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 0, 0, 281, 0, 283, 284, 285, 286, + 287, 288, 0, 0, 289, 0, 291, 0, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 530, 302, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, 318, 319, 320, 321, 322, 0, + 324, 325, 326, 327, 328, 0, 329, 330, 0, 332, + 0, 333, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 0, 341, 342, 343, 0, 0, 344, 345, 346, + 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 0, 0, 0, 0, 362, + 363, 364, 0, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 383, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 0, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 0, 0, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 531, 448, 449, 0, 0, 450, 451, 0, + 452, 0, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 464, 465, 466, 0, 467, + 468, 469, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 0, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 487, 488, 489, 0, 490, 0, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, + 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, + 519, 520, 528, 0, 554, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 130, 131, 0, 132, 133, 134, 0, 136, + 137, 138, 139, 140, 0, 142, 143, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 154, 155, 156, 0, 157, 158, 159, 160, 161, 0, + 0, 0, 163, 164, 165, 166, 167, 168, 0, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 0, + 229, 0, 230, 231, 232, 233, 0, 234, 0, 235, + 0, 0, 0, 238, 239, 529, 0, 242, 0, 243, + 0, 244, 245, 246, 247, 0, 248, 249, 250, 251, + 252, 1328, 254, 0, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 0, 269, + 270, 271, 272, 273, 274, 275, 276, 0, 277, 0, + 278, 0, 0, 281, 0, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 0, 291, 0, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 322, 0, 324, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 0, + 333, 334, 335, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 0, + 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 364, 0, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, + 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 255, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 850, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 852, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 0, 431, 432, 433, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 531, 448, 449, 0, 0, 450, 451, 0, 452, + 0, 454, 455, 456, 457, 458, 0, 459, 460, 461, + 0, 0, 462, 463, 464, 465, 466, 0, 467, 468, + 469, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 488, 489, 0, 490, 0, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 1332, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, - 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 532, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 131, 132, 0, 0, 134, 135, 0, 137, 138, 139, - 140, 141, 0, 143, 144, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 155, 156, - 157, 0, 158, 159, 160, 161, 162, 0, 0, 0, - 164, 165, 166, 167, 168, 169, 0, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 0, 181, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 130, 131, 0, 132, 133, 134, 0, 136, 137, + 138, 139, 140, 0, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 0, 0, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 161, 0, 0, + 0, 163, 164, 165, 166, 167, 168, 0, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 0, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 228, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 0, + 0, 0, 238, 239, 529, 0, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 1331, 254, 0, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 0, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 0, 0, 281, 0, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 0, 291, 0, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 322, 0, 324, 325, + 326, 327, 328, 0, 329, 330, 0, 332, 0, 333, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 346, 0, 348, + 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 364, + 0, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 0, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 531, 448, 449, 0, 0, 450, 451, 0, 452, 0, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 464, 465, 466, 0, 467, 468, 469, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 0, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, + 528, 0, 554, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, + 119, 120, 121, 122, 123, 124, 125, 0, 126, 127, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 130, 131, 0, 132, 133, 134, 0, 136, 137, 138, + 139, 140, 0, 142, 143, 0, 144, 145, 146, 147, + 148, 149, 0, 0, 150, 151, 152, 153, 154, 155, + 156, 0, 157, 158, 159, 160, 161, 0, 0, 0, + 163, 164, 165, 166, 167, 168, 0, 170, 171, 172, + 0, 173, 174, 175, 176, 177, 178, 0, 0, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 0, 195, 0, 196, 197, 198, + 199, 200, 201, 0, 0, 202, 203, 204, 205, 0, + 0, 206, 207, 208, 209, 210, 0, 211, 212, 213, + 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 0, 229, 0, + 230, 231, 232, 233, 0, 234, 0, 235, 0, 0, + 0, 238, 239, 529, 0, 242, 0, 243, 0, 244, + 245, 246, 247, 0, 248, 249, 250, 251, 252, 1333, + 254, 0, 256, 257, 258, 259, 0, 260, 261, 262, + 263, 264, 265, 266, 0, 267, 0, 269, 270, 271, + 272, 273, 274, 275, 276, 0, 277, 0, 278, 0, + 0, 281, 0, 283, 284, 285, 286, 287, 288, 0, + 0, 289, 0, 291, 0, 0, 293, 294, 295, 296, + 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 322, 0, 324, 325, 326, + 327, 328, 0, 329, 330, 0, 332, 0, 333, 334, + 335, 336, 337, 338, 0, 339, 340, 0, 0, 341, + 342, 343, 0, 0, 344, 345, 346, 0, 348, 0, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 0, 0, 0, 0, 362, 363, 364, 0, + 366, 367, 368, 369, 370, 371, 0, 372, 373, 374, + 375, 376, 377, 0, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 0, 401, + 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 0, + 0, 421, 422, 423, 424, 425, 426, 427, 428, 429, + 0, 0, 431, 432, 433, 434, 0, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 531, + 448, 449, 0, 0, 450, 451, 0, 452, 0, 454, + 455, 456, 457, 458, 0, 459, 460, 461, 0, 0, + 462, 463, 464, 465, 466, 0, 467, 468, 469, 470, + 471, 472, 473, 474, 0, 0, 475, 476, 477, 0, + 478, 479, 480, 481, 0, 482, 483, 484, 485, 486, + 487, 488, 489, 0, 490, 0, 492, 493, 494, 495, + 496, 497, 498, 0, 0, 499, 0, 0, 500, 501, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 528, + 0, 554, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 209, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 0, 230, 0, - 231, 232, 233, 234, 0, 235, 0, 236, 0, 0, - 0, 239, 240, 533, 0, 243, 244, 245, 0, 246, - 247, 248, 249, 0, 250, 251, 252, 253, 254, 1353, - 256, 0, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 0, 271, 272, 273, - 274, 275, 276, 277, 278, 0, 279, 0, 280, 0, - 0, 283, 0, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 0, 293, 0, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 534, 304, 305, 306, 307, 308, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 0, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 2282, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 0, 0, 0, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 0, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 0, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 0, 0, 450, 451, 0, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 460, 461, 0, 0, 462, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 0, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 487, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 0, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 1502, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 118, 119, 120, + 121, 122, 123, 124, 125, 0, 126, 127, 128, 0, + 0, 0, 1503, 0, 0, -808, 0, 1504, 130, 131, + 0, 132, 133, 134, 1505, 136, 137, 138, 0, 1506, + 1507, 1508, 1509, 0, 144, 145, 146, 147, 148, 149, + 0, 0, 150, 151, 152, 153, 1510, 1511, 156, 0, + 157, 158, 159, 160, 0, 0, 1512, 0, 1513, 164, + 165, 166, 167, 168, 1514, 170, 171, 172, 0, 173, + 174, 175, 176, 177, 178, 0, 1515, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 1516, 191, 192, + 1517, 194, 0, 195, 0, 196, 197, 198, 199, 200, + 201, 0, 0, 202, 203, 204, 205, 0, 0, 206, + 207, 1073, 209, 210, 0, 211, 212, 213, 0, 214, + 215, 216, 0, 217, 218, 219, 220, 0, 222, 223, + 224, 225, 226, 227, 0, 0, 229, 0, 230, 231, + 1518, 233, 0, 234, 0, 235, 1519, 0, 1520, 238, + 239, -808, 1521, 242, 0, 243, 0, 0, 0, 246, + 247, 0, 248, 249, 250, 251, 252, 253, 254, 1522, + 256, 257, 258, 259, 0, 260, 261, 262, 263, 264, + 265, 266, 0, 267, 1523, 0, 270, 271, 272, 273, + 274, 1524, 1525, 0, 1526, 0, 278, 1527, 1528, 281, + 1529, 283, 284, 285, 286, 287, 288, 0, 0, 289, + 1530, 291, 1531, 0, 293, 294, 295, 296, 297, 298, + 299, 300, 1532, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 324, 0, 326, 327, 328, - 329, 330, 0, 331, 332, 0, 334, 0, 335, 336, - 337, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 348, 0, 350, 0, + 319, 320, 321, 1533, 1534, 1535, 325, 326, 327, 0, + 0, 329, 330, 1536, 332, 0, 0, 334, 1537, 336, + 337, 338, 0, 339, 340, 0, 0, 341, 342, 343, + 0, 0, 344, 345, 0, 1538, 348, 1539, 0, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 367, - 0, 369, 370, 371, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 0, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 0, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 0, 0, 434, 435, 436, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 535, 452, 453, 0, 0, 454, 455, 0, 456, - 0, 458, 459, 460, 461, 462, 0, 463, 464, 465, - 0, 0, 466, 467, 468, 469, 470, 0, 471, 472, - 473, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 0, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 491, 492, 493, 0, 494, 0, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 510, 511, 512, - 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, - 523, 524, 532, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 119, 120, 121, 122, 123, 124, 125, 126, 0, - 127, 128, 129, 0, 0, 0, 0, 0, 0, 1712, - 0, 0, 131, 132, 0, 0, 134, 135, 0, 137, - 138, 139, 140, 141, 0, 143, 144, 0, 145, 146, - 147, 148, 149, 150, 0, 0, 151, 152, 153, 154, - 155, 156, 157, 0, 158, 159, 160, 161, 162, 0, - 0, 0, 164, 165, 166, 167, 168, 169, 0, 171, - 172, 173, 0, 174, 175, 176, 177, 178, 179, 0, - 0, 181, 182, 183, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 0, 196, 0, 197, - 198, 199, 200, 201, 202, 0, 0, 203, 204, 205, - 206, 0, 0, 207, 208, 209, 210, 211, 0, 212, - 213, 214, 0, 215, 216, 217, 0, 218, 219, 220, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 0, - 230, 0, 231, 232, 233, 234, 0, 235, 0, 236, - 0, 0, 0, 239, 240, 533, 0, 243, 244, 245, - 0, 246, 247, 248, 249, 0, 250, 251, 252, 253, - 254, 255, 256, 0, 258, 259, 260, 261, 0, 262, - 263, 264, 265, 266, 267, 268, 0, 269, 0, 271, - 272, 273, 274, 275, 276, 277, 278, 0, 279, 0, - 280, 0, 0, 283, 0, 285, 286, 287, 288, 289, - 290, 0, 0, 291, 0, 293, 0, 0, 295, 296, - 297, 298, 299, 300, 301, 302, 534, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, 319, 320, 321, 322, 323, 324, 0, 326, - 327, 328, 329, 330, 0, 331, 332, 0, 334, 0, - 335, 336, 337, 338, 339, 340, 0, 341, 342, 0, - 0, 343, 344, 345, 0, 0, 346, 347, 348, 0, - 350, 0, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 0, 0, 0, 0, 365, - 366, 367, 0, 369, 370, 371, 372, 373, 374, 0, - 375, 376, 377, 378, 379, 380, 0, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 0, 391, 392, - 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, - 403, 0, 404, 405, 0, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 0, 0, 424, 425, 426, 427, 428, 0, - 430, 431, 432, 0, 0, 434, 435, 436, 437, 0, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 535, 452, 453, 0, 0, 454, 455, - 0, 456, 0, 458, 459, 460, 461, 462, 0, 463, - 464, 465, 0, 0, 466, 467, 468, 469, 470, 0, - 471, 472, 473, 474, 475, 476, 477, 478, 0, 0, - 479, 480, 481, 0, 0, 482, 483, 484, 485, 0, - 486, 487, 488, 489, 490, 491, 492, 493, 0, 494, - 0, 496, 497, 498, 499, 500, 501, 502, 0, 0, - 503, 0, 0, 504, 505, 506, 507, 508, 509, 510, - 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, - 521, 522, 523, 524, 532, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, - 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 248, 249, 0, 250, 251, - 252, 253, 254, 1908, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, + 0, 0, 0, 0, 362, 363, 0, 1540, 366, 367, + 0, 369, 370, 371, 0, 372, 373, 374, 375, 376, + 377, 0, 378, 379, 380, 381, 382, 1541, 384, 385, + 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 0, 401, 402, 1542, + 404, 405, 406, 1543, 408, 409, 410, 411, 412, 413, + 414, 415, 416, 417, 418, 419, 420, 0, 1544, 421, + 422, 423, 424, 425, 426, 1545, 428, 429, 0, 1546, + 431, 432, 1547, 434, 0, 435, 436, 437, 438, 439, + 440, 441, 442, 443, 444, 445, 446, 1548, 448, 0, + 0, 0, 450, 451, 0, 452, 1549, 454, 455, 456, + 457, 458, 0, 459, 1550, 1551, 0, 0, 462, 463, + 0, 465, 0, 0, 467, 468, 1552, 470, 471, 472, + 473, 474, 1553, 0, 475, 476, 477, 0, 478, 479, + 480, 481, 0, 482, 483, 484, 485, 486, 0, 1554, + 489, 0, 490, 1555, 492, 493, 494, 495, 496, 497, + 498, 0, 0, 499, 0, 0, 500, 501, 502, 503, + 504, 505, 528, 0, 554, 0, 0, 0, 0, 0, + 0, 0, 0, 517, 518, 519, 520, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 130, 131, 0, 132, 133, 134, 0, 136, + 137, 138, 139, 140, 0, 142, 143, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 154, 155, 156, 0, 157, 158, 159, 160, 161, 0, + 0, 0, 163, 164, 165, 166, 167, 168, 0, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 0, + 229, 0, 230, 231, 232, 233, 0, 234, 0, 235, + 0, 0, 0, 238, 239, 529, 0, 242, 0, 243, + 0, 244, 245, 246, 247, 0, 248, 249, 250, 251, + 252, 3051, 254, 0, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 0, 269, + 270, 271, 272, 273, 274, 275, 276, 0, 277, 0, + 278, 0, 0, 281, 0, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 0, 291, 0, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 322, 0, 324, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 0, + 333, 334, 335, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 0, + 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 364, 0, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, + 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, - 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 532, 0, 0, 0, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 0, 431, 432, 433, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 531, 448, 449, 0, 0, 450, 451, 0, 452, + 0, 454, 455, 456, 457, 458, 0, 459, 460, 461, + 0, 0, 462, 463, 464, 465, 466, 0, 467, 468, + 469, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 488, 489, 0, 490, 0, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, - 124, 125, 126, 0, 127, 128, 129, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 131, 132, 0, 0, - 134, 135, 0, 137, 138, 139, 140, 141, 0, 143, - 144, 0, 145, 146, 147, 148, 149, 150, 0, 0, - 151, 152, 153, 154, 155, 156, 157, 0, 158, 159, - 160, 161, 162, 0, 0, 0, 164, 165, 166, 167, - 168, 169, 0, 171, 172, 173, 0, 174, 175, 176, - 177, 178, 179, 0, 0, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 0, 196, 0, 197, 198, 199, 200, 201, 202, 0, - 0, 203, 204, 205, 206, 0, 0, 207, 208, 209, - 210, 211, 0, 212, 213, 214, 0, 215, 216, 217, - 0, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 0, 230, 0, 231, 232, 233, 234, - 0, 235, 0, 236, 0, 0, 0, 239, 240, 533, - 0, 243, 244, 245, 0, 246, 247, 248, 249, 0, - 250, 251, 252, 253, 254, 2293, 256, 0, 258, 259, - 260, 261, 0, 262, 263, 264, 265, 266, 267, 268, - 0, 269, 0, 271, 272, 273, 274, 275, 276, 277, - 278, 0, 279, 0, 280, 0, 0, 283, 0, 285, - 286, 287, 288, 289, 290, 0, 0, 291, 0, 293, - 0, 0, 295, 296, 297, 298, 299, 300, 301, 302, - 534, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, - 323, 324, 0, 326, 327, 328, 329, 330, 0, 331, - 332, 0, 334, 0, 335, 336, 337, 338, 339, 340, - 0, 341, 342, 0, 0, 343, 344, 345, 0, 0, - 346, 347, 348, 0, 350, 0, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 0, - 0, 0, 0, 365, 366, 367, 0, 369, 370, 371, - 372, 373, 374, 0, 375, 376, 377, 378, 379, 380, - 0, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 0, 391, 392, 393, 394, 395, 396, 397, 398, - 399, 400, 401, 402, 403, 0, 404, 405, 0, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 0, 0, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 0, 0, 434, - 435, 436, 437, 0, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 535, 452, 453, - 0, 0, 454, 455, 0, 456, 0, 458, 459, 460, - 461, 462, 0, 463, 464, 465, 0, 0, 466, 467, - 468, 469, 470, 0, 471, 472, 473, 474, 475, 476, - 477, 478, 0, 0, 479, 480, 481, 0, 0, 482, - 483, 484, 485, 0, 486, 487, 488, 489, 490, 491, - 492, 493, 0, 494, 0, 496, 497, 498, 499, 500, - 501, 502, 0, 0, 503, 0, 0, 504, 505, 506, - 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, - 517, 518, 519, 520, 521, 522, 523, 524, 532, 0, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 130, 131, 0, 132, 133, 134, 0, 136, 137, + 138, 139, 140, 0, 142, 143, 0, 144, 145, 146, + 147, 148, 149, 0, 0, 150, 151, 152, 153, 154, + 155, 156, 0, 157, 158, 159, 160, 161, 0, 0, + 0, 163, 164, 165, 166, 167, 168, 0, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 0, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 208, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 228, 0, 229, + 0, 230, 231, 232, 233, 0, 234, 0, 235, 0, + 0, 0, 238, 239, 529, 0, 242, 0, 243, 0, + 244, 245, 246, 247, 0, 248, 249, 250, 251, 252, + 253, 254, 0, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 0, 269, 270, + 271, 272, 273, 274, 275, 276, 0, 277, 0, 278, + 0, 0, 281, 0, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 0, 291, 0, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 322, 0, 324, 325, + 326, 327, 328, 0, 329, 330, 0, 332, 0, 333, + 334, 335, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 346, 0, 348, + 0, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 364, + 0, 366, 367, 368, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 0, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 0, 0, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 0, 0, 431, 432, 433, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 531, 448, 449, 0, 0, 450, 451, 0, 452, 0, + 454, 455, 456, 457, 458, 0, 459, 460, 461, 0, + 0, 462, 463, 464, 465, 466, 0, 467, 468, 469, + 470, 471, 472, 473, 474, 0, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 487, 488, 489, 0, 490, 0, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, + 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, + 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 118, + 119, 120, 121, 122, 123, 124, 125, 0, 126, 127, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 130, 131, 0, 132, 133, 134, 0, 136, 137, 138, + 139, 140, 0, 142, 143, 0, 144, 145, 146, 147, + 148, 149, 0, 0, 150, 151, 152, 153, 154, 155, + 156, 0, 157, 158, 159, 160, 161, 0, 0, 0, + 163, 164, 165, 166, 167, 168, 0, 170, 171, 172, + 0, 173, 174, 175, 176, 177, 178, 0, 0, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 0, 195, 0, 196, 197, 198, + 199, 200, 201, 0, 0, 202, 203, 204, 205, 0, + 0, 206, 207, 208, 209, 210, 0, 211, 212, 213, + 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 0, 229, 0, + 230, 231, 232, 233, 0, 234, 0, 235, 0, 0, + 0, 238, 239, 529, 0, 843, 0, 243, 0, 244, + 245, 246, 247, 0, 248, 249, 250, 251, 252, 253, + 254, 0, 256, 257, 258, 259, 0, 260, 261, 262, + 263, 264, 265, 266, 0, 267, 0, 269, 270, 271, + 272, 273, 274, 275, 276, 0, 277, 0, 278, 0, + 0, 281, 0, 283, 284, 285, 286, 287, 288, 0, + 0, 289, 0, 291, 0, 0, 293, 294, 844, 296, + 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, + 317, 318, 319, 320, 321, 322, 0, 324, 325, 326, + 327, 328, 0, 329, 330, 0, 332, 0, 333, 334, + 335, 336, 337, 338, 0, 339, 340, 0, 0, 341, + 342, 343, 0, 0, 344, 345, 346, 0, 348, 0, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 361, 0, 0, 0, 0, 362, 363, 364, 0, + 366, 367, 368, 369, 370, 371, 0, 372, 373, 374, + 375, 376, 377, 0, 378, 379, 380, 381, 382, 383, + 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 0, 401, + 402, 0, 404, 405, 406, 407, 408, 409, 410, 411, + 845, 413, 414, 415, 416, 417, 418, 419, 420, 0, + 0, 421, 422, 423, 424, 846, 426, 427, 428, 429, + 0, 0, 431, 432, 433, 434, 0, 435, 436, 437, + 438, 439, 440, 441, 442, 443, 444, 445, 446, 531, + 448, 449, 0, 0, 450, 451, 0, 452, 0, 454, + 455, 456, 457, 458, 0, 459, 847, 461, 0, 0, + 462, 463, 464, 465, 466, 0, 467, 468, 469, 470, + 471, 472, 473, 474, 0, 0, 475, 476, 477, 0, + 478, 479, 480, 481, 0, 482, 483, 484, 485, 486, + 487, 488, 848, 0, 490, 0, 492, 493, 494, 495, + 496, 497, 498, 0, 0, 499, 0, 0, 500, 501, + 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, + 512, 513, 514, 515, 516, 517, 518, 519, 520, 528, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 130, + 131, 0, 132, 133, 134, 0, 136, 137, 138, 139, + 140, 0, 142, 143, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 154, 155, 156, + 0, 157, 158, 159, 160, 161, 0, 0, 0, 163, + 164, 165, 166, 167, 168, 0, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 0, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 208, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 0, 229, 0, 230, + 231, 232, 233, 0, 234, 0, 235, 0, 0, 0, + 238, 239, 529, 0, 242, 0, 243, 0, 244, 245, + 246, 247, 0, 248, 249, 250, 251, 252, 960, 254, + 0, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 0, 269, 270, 271, 272, + 273, 274, 275, 276, 0, 277, 0, 278, 0, 0, + 281, 0, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 0, 291, 0, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 322, 0, 324, 325, 326, 327, + 328, 0, 329, 330, 0, 332, 0, 333, 334, 335, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 346, 0, 348, 0, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 0, 0, 0, 0, 362, 363, 364, 0, 366, + 367, 368, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 383, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 0, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 0, 0, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 0, + 0, 431, 432, 433, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 531, 448, + 449, 0, 0, 450, 451, 0, 452, 0, 454, 455, + 456, 457, 458, 0, 459, 460, 461, 0, 0, 462, + 463, 464, 465, 466, 0, 467, 468, 469, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 0, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 487, + 488, 489, 0, 490, 0, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 0, 500, 501, 502, + 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, + 513, 514, 515, 516, 517, 518, 519, 520, 528, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 118, 119, 120, + 121, 122, 123, 124, 125, 0, 126, 127, 128, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 130, 131, + 0, 132, 133, 134, 0, 136, 137, 138, 139, 140, + 0, 142, 143, 0, 144, 145, 146, 147, 148, 149, + 0, 0, 150, 151, 152, 153, 154, 155, 156, 0, + 157, 158, 159, 160, 161, 0, 0, 0, 163, 164, + 165, 166, 167, 168, 0, 170, 171, 172, 0, 173, + 174, 175, 176, 177, 178, 0, 0, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, + 193, 194, 0, 195, 0, 196, 197, 198, 199, 200, + 201, 0, 0, 202, 203, 204, 205, 0, 0, 206, + 207, 208, 209, 210, 0, 211, 212, 213, 0, 214, + 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 0, 229, 0, 230, 231, + 232, 233, 0, 234, 0, 235, 0, 0, 0, 238, + 239, 529, 0, 242, 0, 243, 0, 244, 245, 246, + 247, 0, 248, 249, 250, 251, 252, 253, 254, 0, + 256, 257, 258, 259, 0, 260, 261, 262, 263, 264, + 265, 266, 0, 267, 0, 269, 270, 271, 272, 273, + 274, 275, 276, 0, 277, 0, 278, 0, 0, 281, + 0, 283, 284, 285, 286, 287, 288, 0, 0, 289, + 0, 291, 0, 0, 293, 294, 295, 296, 297, 298, + 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, + 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, + 319, 320, 321, 322, 0, 324, 325, 326, 327, 328, + 0, 329, 330, 0, 332, 0, 333, 334, 335, 336, + 337, 338, 0, 339, 340, 0, 0, 341, 342, 343, + 0, 0, 344, 345, 346, 0, 348, 0, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, + 0, 0, 0, 0, 362, 363, 364, 0, 366, 367, + 368, 369, 370, 371, 0, 372, 373, 374, 375, 376, + 377, 0, 378, 379, 380, 381, 382, 383, 384, 385, + 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 0, 401, 402, 0, + 404, 405, 406, 407, 408, 409, 410, 411, 845, 413, + 414, 415, 416, 417, 418, 419, 420, 0, 0, 421, + 422, 423, 424, 425, 426, 427, 428, 429, 0, 0, + 431, 432, 433, 434, 0, 435, 436, 437, 438, 439, + 440, 441, 442, 443, 444, 445, 446, 531, 448, 449, + 0, 0, 450, 451, 0, 452, 0, 454, 455, 456, + 457, 458, 0, 459, 847, 461, 0, 0, 462, 463, + 464, 465, 466, 0, 467, 468, 469, 470, 471, 472, + 473, 474, 0, 0, 475, 476, 477, 0, 478, 479, + 480, 481, 0, 482, 483, 484, 485, 486, 487, 488, + 489, 0, 490, 0, 492, 493, 494, 495, 496, 497, + 498, 0, 0, 499, 0, 0, 500, 501, 502, 503, + 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, + 514, 515, 516, 517, 518, 519, 520, 528, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, - 122, 123, 124, 125, 126, 0, 127, 128, 129, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 131, 132, - 0, 0, 134, 135, 0, 137, 138, 139, 140, 141, - 0, 143, 144, 0, 145, 146, 147, 148, 149, 150, - 0, 0, 151, 152, 153, 154, 155, 156, 157, 0, - 158, 159, 160, 161, 162, 0, 0, 0, 164, 165, - 166, 167, 168, 169, 0, 171, 172, 173, 0, 174, - 175, 176, 177, 178, 179, 0, 0, 181, 182, 183, + 0, 0, 0, 0, 0, 0, 118, 119, 120, 121, + 122, 123, 124, 125, 0, 126, 127, 128, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 130, 131, 0, + 132, 133, 134, 0, 136, 137, 138, 139, 140, 0, + 142, 143, 0, 144, 145, 146, 147, 148, 149, 0, + 0, 150, 151, 152, 153, 154, 155, 156, 0, 157, + 158, 159, 160, 161, 0, 0, 0, 163, 164, 165, + 166, 167, 168, 0, 170, 171, 172, 0, 173, 174, + 175, 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 0, 196, 0, 197, 198, 199, 200, 201, - 202, 0, 0, 203, 204, 205, 206, 0, 0, 207, - 208, 209, 210, 211, 0, 212, 213, 214, 0, 215, - 216, 217, 0, 218, 219, 220, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 0, 230, 0, 231, 232, - 233, 234, 0, 235, 0, 236, 0, 0, 0, 239, - 240, 533, 0, 243, 244, 245, 0, 246, 247, 248, - 249, 0, 250, 251, 252, 253, 254, 2313, 256, 0, - 258, 259, 260, 261, 0, 262, 263, 264, 265, 266, - 267, 268, 0, 269, 0, 271, 272, 273, 274, 275, - 276, 277, 278, 0, 279, 0, 280, 0, 0, 283, - 0, 285, 286, 287, 288, 289, 290, 0, 0, 291, - 0, 293, 0, 0, 295, 296, 297, 298, 299, 300, - 301, 302, 534, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, - 321, 322, 323, 324, 0, 326, 327, 328, 329, 330, - 0, 331, 332, 0, 334, 0, 335, 336, 337, 338, - 339, 340, 0, 341, 342, 0, 0, 343, 344, 345, - 0, 0, 346, 347, 348, 0, 350, 0, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 0, 0, 0, 0, 365, 366, 367, 0, 369, - 370, 371, 372, 373, 374, 0, 375, 376, 377, 378, - 379, 380, 0, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 0, 391, 392, 393, 394, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 0, 404, 405, - 0, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 0, 0, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 0, - 0, 434, 435, 436, 437, 0, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 535, - 452, 453, 0, 0, 454, 455, 0, 456, 0, 458, - 459, 460, 461, 462, 0, 463, 464, 465, 0, 0, - 466, 467, 468, 469, 470, 0, 471, 472, 473, 474, - 475, 476, 477, 478, 0, 0, 479, 480, 481, 0, - 0, 482, 483, 484, 485, 0, 486, 487, 488, 489, - 490, 491, 492, 493, 0, 494, 0, 496, 497, 498, - 499, 500, 501, 502, 0, 0, 503, 0, 0, 504, + 194, 0, 195, 0, 196, 197, 198, 199, 200, 201, + 0, 0, 202, 203, 204, 205, 0, 0, 206, 207, + 208, 209, 210, 0, 211, 212, 213, 0, 214, 215, + 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, + 225, 226, 227, 228, 0, 229, 0, 230, 231, 232, + 233, 0, 234, 0, 235, 0, 0, 0, 238, 239, + 529, 0, 242, 0, 243, 0, 244, 245, 246, 247, + 0, 248, 249, 250, 251, 252, 1322, 254, 0, 256, + 257, 258, 259, 0, 260, 261, 262, 263, 264, 265, + 266, 0, 267, 0, 269, 270, 271, 272, 273, 274, + 275, 276, 0, 277, 0, 278, 0, 0, 281, 0, + 283, 284, 285, 286, 287, 288, 0, 0, 289, 0, + 291, 0, 0, 293, 294, 295, 296, 297, 298, 299, + 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 322, 0, 324, 325, 326, 327, 328, 0, + 329, 330, 0, 332, 0, 333, 334, 335, 336, 337, + 338, 0, 339, 340, 0, 0, 341, 342, 343, 0, + 0, 344, 345, 346, 0, 348, 0, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 0, + 0, 0, 0, 362, 363, 364, 0, 366, 367, 368, + 369, 370, 371, 0, 372, 373, 374, 375, 376, 377, + 0, 378, 379, 380, 381, 382, 383, 384, 385, 386, + 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 0, 401, 402, 0, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 415, 416, 417, 418, 419, 420, 0, 0, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 0, 0, 431, + 432, 433, 434, 0, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 531, 448, 449, 0, + 0, 450, 451, 0, 452, 0, 454, 455, 456, 457, + 458, 0, 459, 460, 461, 0, 0, 462, 463, 464, + 465, 466, 0, 467, 468, 469, 470, 471, 472, 473, + 474, 0, 0, 475, 476, 477, 0, 478, 479, 480, + 481, 0, 482, 483, 484, 485, 486, 487, 488, 489, + 0, 490, 0, 492, 493, 494, 495, 496, 497, 498, + 0, 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, - 3300, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, - 120, 121, 122, 123, 124, 125, 126, 0, 127, 128, - 129, 0, 0, 0, 3030, 0, 0, 0, 0, 3031, - 131, 132, 0, 3032, 134, 135, 3033, 137, 138, 139, - 0, 1518, 3034, 1520, 1521, 0, 145, 146, 147, 148, - 149, 150, 0, 0, 151, 152, 153, 154, 1522, 1523, - 157, 0, 158, 159, 160, 161, 0, 0, 3035, 0, - 3036, 165, 166, 167, 168, 169, 3037, 171, 172, 173, - 0, 174, 175, 176, 177, 178, 179, 0, 3038, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 1528, - 192, 193, 1529, 195, 0, 196, 0, 197, 198, 199, - 200, 201, 202, 0, 0, 203, 204, 205, 206, 0, - 0, 207, 208, 1079, 210, 211, 0, 212, 213, 214, - 0, 215, 216, 217, 0, 218, 219, 220, 221, 0, - 223, 224, 225, 226, 227, 228, 0, 0, 230, 0, - 231, 232, 1530, 234, 0, 235, 0, 236, 3039, 0, - 3040, 239, 240, 3041, 3042, 243, 244, 245, 0, 0, - 0, 248, 249, 0, 250, 251, 252, 253, 254, 255, - 256, 3043, 258, 259, 260, 261, 0, 262, 263, 264, - 265, 266, 267, 268, 0, 269, 3044, 0, 272, 273, - 274, 275, 276, 1536, 1537, 0, 1538, 0, 280, 3045, - 3046, 283, 3047, 285, 286, 287, 288, 289, 290, 0, - 0, 291, 3048, 293, 3049, 0, 295, 296, 297, 298, - 299, 300, 301, 302, 3301, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - 319, 320, 321, 322, 323, 1545, 3051, 1547, 327, 328, - 329, 0, 0, 331, 332, 3053, 334, 0, 0, 336, - 1549, 338, 339, 340, 0, 341, 342, 0, 0, 343, - 344, 345, 0, 0, 346, 347, 0, 3055, 350, 3056, - 0, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 0, 0, 0, 0, 365, 366, 0, - 3057, 369, 370, 0, 372, 373, 374, 0, 375, 376, - 377, 378, 379, 380, 0, 381, 382, 383, 384, 385, - 1553, 387, 388, 389, 390, 0, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 0, - 404, 405, 3058, 407, 408, 409, 0, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 0, 3059, 424, 425, 426, 427, 428, 429, 0, 431, - 432, 0, 3061, 434, 435, 1559, 437, 0, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 3302, 452, 0, 0, 0, 454, 455, 0, 456, - 3063, 458, 459, 460, 461, 462, 0, 463, 1562, 1563, - 0, 0, 466, 467, 0, 469, 0, 0, 471, 472, - 3064, 474, 475, 476, 477, 478, 0, 0, 479, 480, - 481, 3066, 0, 482, 483, 484, 485, 0, 486, 487, - 488, 489, 490, 0, 1567, 493, 0, 494, 3067, 496, - 497, 498, 499, 500, 501, 502, 0, 0, 503, 0, - 0, 504, 505, 506, 507, 508, 509, 1817, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 521, 522, - 523, 524, 0, 0, 0, 0, 119, 120, 121, 122, - 123, 124, 125, 126, 0, 127, 128, 129, 0, 0, - 0, 1514, 0, 0, 0, 0, 1515, 131, 132, 0, - 1516, 134, 135, 1517, 137, 138, 139, 0, 1518, 1519, - 1520, 1521, 0, 145, 146, 147, 148, 149, 150, 0, - 0, 151, 152, 153, 154, 1522, 1523, 157, 0, 158, - 159, 160, 161, 0, 0, 1524, 0, 1525, 165, 166, - 167, 168, 169, 1526, 171, 172, 173, 0, 174, 175, - 176, 177, 178, 179, 0, 1527, 181, 182, 183, 184, - 185, 186, 187, 188, 189, 190, 1528, 192, 193, 1529, - 195, 0, 196, 0, 197, 198, 199, 200, 201, 202, - 0, 0, 203, 204, 205, 206, 0, 0, 207, 208, - 1079, 210, 211, 0, 212, 213, 214, 0, 215, 216, - 217, 0, 218, 219, 220, 221, 0, 223, 224, 225, - 226, 227, 228, 0, 0, 230, 0, 231, 232, 1530, - 234, 0, 235, 0, 236, 1531, 0, 1532, 239, 240, - 0, 1533, 243, 244, 245, 0, 0, 0, 248, 249, - 0, 250, 251, 252, 253, 254, 255, 256, 1534, 258, - 259, 260, 261, 0, 262, 263, 264, 265, 266, 267, - 268, 0, 269, 1535, 0, 272, 273, 274, 275, 276, - 1536, 1537, 0, 1538, 0, 280, 1539, 1540, 283, 1541, - 285, 286, 287, 288, 289, 290, 0, 0, 291, 1542, - 293, 1543, 0, 295, 296, 297, 298, 299, 300, 301, - 302, 0, 304, 305, 306, 307, 308, 309, 310, 311, + 515, 516, 517, 518, 519, 520, 528, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 118, 119, 120, 121, 122, + 123, 124, 125, 0, 126, 127, 128, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 130, 131, 0, 132, + 133, 134, 0, 136, 137, 138, 139, 140, 0, 142, + 143, 0, 144, 145, 146, 147, 148, 149, 0, 0, + 150, 151, 152, 153, 154, 155, 156, 0, 157, 158, + 159, 160, 161, 0, 0, 0, 163, 164, 165, 166, + 167, 168, 0, 170, 171, 172, 0, 173, 174, 175, + 176, 177, 178, 0, 0, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, + 0, 195, 0, 196, 197, 198, 199, 200, 201, 0, + 0, 202, 203, 204, 205, 0, 0, 206, 207, 208, + 209, 210, 0, 211, 212, 213, 0, 214, 215, 216, + 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, + 226, 227, 228, 0, 229, 0, 230, 231, 232, 233, + 0, 234, 0, 235, 0, 0, 0, 238, 239, 529, + 0, 242, 0, 243, 0, 244, 245, 246, 247, 0, + 248, 249, 250, 251, 252, 1343, 254, 0, 256, 257, + 258, 259, 0, 260, 261, 262, 263, 264, 265, 266, + 0, 267, 0, 269, 270, 271, 272, 273, 274, 275, + 276, 0, 277, 0, 278, 0, 0, 281, 0, 283, + 284, 285, 286, 287, 288, 0, 0, 289, 0, 291, + 0, 0, 293, 294, 295, 296, 297, 298, 299, 300, + 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, + 321, 322, 0, 324, 325, 326, 327, 328, 0, 329, + 330, 0, 332, 0, 333, 334, 335, 336, 337, 338, + 0, 339, 340, 0, 0, 341, 342, 343, 0, 0, + 344, 345, 346, 0, 348, 0, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, 361, 0, 0, + 0, 0, 362, 363, 364, 0, 366, 367, 368, 369, + 370, 371, 0, 372, 373, 374, 375, 376, 377, 0, + 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, + 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, + 397, 398, 399, 400, 0, 401, 402, 0, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + 416, 417, 418, 419, 420, 0, 0, 421, 422, 423, + 424, 425, 426, 427, 428, 429, 0, 0, 431, 432, + 433, 434, 0, 435, 436, 437, 438, 439, 440, 441, + 442, 443, 444, 445, 446, 531, 448, 449, 0, 0, + 450, 451, 0, 452, 0, 454, 455, 456, 457, 458, + 0, 459, 460, 461, 0, 0, 462, 463, 464, 465, + 466, 0, 467, 468, 469, 470, 471, 472, 473, 474, + 0, 0, 475, 476, 477, 0, 478, 479, 480, 481, + 0, 482, 483, 484, 485, 486, 487, 488, 489, 0, + 490, 0, 492, 493, 494, 495, 496, 497, 498, 0, + 0, 499, 0, 0, 500, 501, 502, 503, 504, 505, + 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, + 516, 517, 518, 519, 520, 528, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 0, + 0, 0, 1698, 0, 0, 130, 131, 0, 132, 133, + 134, 0, 136, 137, 138, 139, 140, 0, 142, 143, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 154, 155, 156, 0, 157, 158, 159, + 160, 161, 0, 0, 0, 163, 164, 165, 166, 167, + 168, 0, 170, 171, 172, 0, 173, 174, 175, 176, + 177, 178, 0, 0, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 208, 209, + 210, 0, 211, 212, 213, 0, 214, 215, 216, 0, + 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 0, 229, 0, 230, 231, 232, 233, 0, + 234, 0, 235, 0, 0, 0, 238, 239, 529, 0, + 242, 0, 243, 0, 244, 245, 246, 247, 0, 248, + 249, 250, 251, 252, 253, 254, 0, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 0, 269, 270, 271, 272, 273, 274, 275, 276, + 0, 277, 0, 278, 0, 0, 281, 0, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 0, 291, 0, + 0, 293, 294, 295, 296, 297, 298, 299, 300, 530, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 1545, 1546, 1547, 327, 328, 329, 0, 0, - 331, 332, 1548, 334, 0, 0, 336, 1549, 338, 339, - 340, 0, 341, 342, 0, 0, 343, 344, 345, 0, - 0, 346, 347, 0, 1550, 350, 1551, 0, 353, 354, - 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 0, 0, 0, 0, 365, 366, 0, 1552, 369, 370, - 0, 372, 373, 374, 0, 375, 376, 377, 378, 379, - 380, 0, 381, 382, 383, 384, 385, 1553, 387, 388, - 389, 390, 0, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 0, 404, 405, 1554, - 407, 408, 409, 0, 411, 412, 413, 414, 415, 416, - 417, 418, 419, 420, 421, 422, 423, 0, 1556, 424, - 425, 426, 427, 428, 429, 0, 431, 432, 0, 1558, - 434, 435, 1559, 437, 0, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, 449, 450, 0, 452, - 0, 0, 0, 454, 455, 0, 456, 1561, 458, 459, - 460, 461, 462, 0, 463, 1562, 1563, 0, 0, 466, - 467, 0, 469, 0, 0, 471, 472, 1564, 474, 475, - 476, 477, 478, 0, 0, 479, 480, 481, 1566, 0, - 482, 483, 484, 485, 0, 486, 487, 488, 489, 490, - 0, 1567, 493, 0, 494, 1568, 496, 497, 498, 499, - 500, 501, 502, 0, 0, 503, 0, 0, 504, 505, - 506, 507, 508, 509, 532, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 521, 522, 523, 524, 0, - 0, 0, 0, 119, 120, 121, 122, 123, 124, 125, - 126, 0, 127, 128, 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 131, 132, 0, 0, 134, 135, - 0, 137, 138, 139, 140, 141, 0, 143, 144, 0, - 145, 146, 147, 148, 149, 150, 0, 0, 151, 152, - 153, 154, 155, 156, 157, 0, 158, 159, 160, 161, - 162, 0, 0, 0, 164, 165, 166, 167, 168, 169, - 0, 171, 172, 173, 0, 174, 175, 176, 177, 178, - 179, 0, 0, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 0, 196, - 0, 197, 198, 199, 200, 201, 202, 0, 0, 203, - 204, 205, 206, 0, 0, 207, 208, 209, 210, 211, - 0, 212, 213, 214, 0, 215, 216, 217, 0, 218, + 322, 0, 324, 325, 326, 327, 328, 0, 329, 330, + 0, 332, 0, 333, 334, 335, 336, 337, 338, 0, + 339, 340, 0, 0, 341, 342, 343, 0, 0, 344, + 345, 346, 0, 348, 0, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 364, 0, 366, 367, 368, 369, 370, + 371, 0, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 0, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, + 417, 418, 419, 420, 0, 0, 421, 422, 423, 424, + 425, 0, 427, 428, 429, 0, 0, 431, 432, 433, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 531, 448, 449, 0, 0, 450, + 451, 0, 452, 0, 454, 455, 456, 457, 458, 0, + 459, 460, 461, 0, 0, 462, 463, 464, 465, 466, + 0, 467, 468, 469, 470, 471, 472, 473, 474, 0, + 0, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 487, 488, 489, 0, 490, + 0, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 506, + 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, + 517, 518, 519, 520, 528, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 118, 119, 120, 121, 122, 123, 124, + 125, 0, 126, 127, 128, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 130, 131, 0, 132, 133, 134, + 0, 136, 137, 138, 139, 140, 0, 142, 143, 0, + 144, 145, 146, 147, 148, 149, 0, 0, 150, 151, + 152, 153, 154, 155, 156, 0, 157, 158, 159, 160, + 161, 0, 0, 0, 163, 164, 165, 166, 167, 168, + 0, 170, 171, 172, 0, 173, 174, 175, 176, 177, + 178, 0, 0, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 0, 195, + 0, 196, 197, 198, 199, 200, 201, 0, 0, 202, + 203, 204, 205, 0, 0, 206, 207, 208, 209, 210, + 0, 211, 212, 213, 0, 214, 215, 216, 0, 217, + 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, + 228, 0, 229, 0, 230, 231, 232, 233, 0, 234, + 0, 235, 0, 0, 0, 238, 239, 529, 0, 242, + 0, 243, 0, 244, 245, 246, 247, 0, 248, 249, + 250, 251, 252, 1887, 254, 0, 256, 257, 258, 259, + 0, 260, 261, 262, 263, 264, 265, 266, 0, 267, + 0, 269, 270, 271, 272, 273, 274, 275, 276, 0, + 277, 0, 278, 0, 0, 281, 0, 283, 284, 285, + 286, 287, 288, 0, 0, 289, 0, 291, 0, 0, + 293, 294, 295, 296, 297, 298, 299, 300, 530, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, + 0, 324, 325, 326, 327, 328, 0, 329, 330, 0, + 332, 0, 333, 334, 335, 336, 337, 338, 0, 339, + 340, 0, 0, 341, 342, 343, 0, 0, 344, 345, + 346, 0, 348, 0, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 0, 0, 0, 0, + 362, 363, 364, 0, 366, 367, 368, 369, 370, 371, + 0, 372, 373, 374, 375, 376, 377, 0, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 0, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 0, 401, 402, 0, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, + 418, 419, 420, 0, 0, 421, 422, 423, 424, 425, + 426, 427, 428, 429, 0, 0, 431, 432, 433, 434, + 0, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, 531, 448, 449, 0, 0, 450, 451, + 0, 452, 0, 454, 455, 456, 457, 458, 0, 459, + 460, 461, 0, 0, 462, 463, 464, 465, 466, 0, + 467, 468, 469, 470, 471, 472, 473, 474, 0, 0, + 475, 476, 477, 0, 478, 479, 480, 481, 0, 482, + 483, 484, 485, 486, 487, 488, 489, 0, 490, 0, + 492, 493, 494, 495, 496, 497, 498, 0, 0, 499, + 0, 0, 500, 501, 502, 503, 504, 505, 506, 507, + 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, + 518, 519, 520, 528, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 130, 131, 0, 132, 133, 134, 0, + 136, 137, 138, 139, 140, 0, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 0, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 161, + 0, 0, 0, 163, 164, 165, 166, 167, 168, 0, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 0, 0, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 0, 231, 232, 233, 234, 0, 235, - 0, 236, 0, 0, 0, 239, 240, 533, 0, 243, - 244, 245, 0, 246, 247, 0, 249, 0, 250, 251, - 252, 253, 254, 255, 256, 0, 258, 259, 260, 261, - 0, 262, 263, 264, 265, 266, 267, 268, 0, 269, - 0, 271, 272, 273, 274, 275, 276, 277, 278, 0, - 279, 0, 280, 0, 0, 283, 0, 285, 286, 287, - 288, 289, 290, 0, 0, 291, 0, 293, 0, 0, - 295, 296, 297, 298, 299, 300, 301, 302, 534, 304, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 0, 0, 0, 238, 239, 529, 0, 242, 0, + 243, 0, 244, 245, 246, 247, 0, 248, 249, 250, + 251, 252, 2269, 254, 0, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 0, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 0, 0, 281, 0, 283, 284, 285, 286, + 287, 288, 0, 0, 289, 0, 291, 0, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 530, 302, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, 318, 319, 320, 321, 322, 0, + 324, 325, 326, 327, 328, 0, 329, 330, 0, 332, + 0, 333, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 0, 341, 342, 343, 0, 0, 344, 345, 346, + 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, 361, 0, 0, 0, 0, 362, + 363, 364, 0, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 381, 382, 383, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 0, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 0, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 0, 0, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 531, 448, 449, 0, 0, 450, 451, 0, + 452, 0, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 464, 465, 466, 0, 467, + 468, 469, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 0, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 487, 488, 489, 0, 490, 0, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, + 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, + 519, 520, 528, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 130, 131, 0, 132, 133, 134, 0, 136, + 137, 138, 139, 140, 0, 142, 143, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 154, 155, 156, 0, 157, 158, 159, 160, 161, 0, + 0, 0, 163, 164, 165, 166, 167, 168, 0, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 0, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 208, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 0, + 229, 0, 230, 231, 232, 233, 0, 234, 0, 235, + 0, 0, 0, 238, 239, 529, 0, 242, 0, 243, + 0, 244, 245, 246, 247, 0, 248, 249, 250, 251, + 252, 2284, 254, 0, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 0, 269, + 270, 271, 272, 273, 274, 275, 276, 0, 277, 0, + 278, 0, 0, 281, 0, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 0, 291, 0, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 530, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, - 0, 326, 327, 328, 329, 330, 0, 331, 332, 0, - 334, 0, 335, 336, 337, 338, 339, 340, 0, 341, - 342, 0, 0, 343, 344, 345, 0, 0, 346, 347, - 348, 0, 350, 0, 352, 353, 354, 355, 356, 357, - 358, 0, 360, 361, 362, 363, 364, 0, 0, 0, - 0, 365, 366, 367, 0, 369, 370, 371, 372, 373, - 374, 0, 375, 376, 377, 378, 379, 380, 0, 381, - 382, 383, 0, 385, 386, 387, 388, 389, 390, 0, + 315, 316, 317, 318, 319, 320, 321, 322, 0, 324, + 325, 326, 327, 328, 0, 329, 330, 0, 332, 0, + 333, 334, 335, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 346, 0, + 348, 0, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 364, 0, 366, 367, 368, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, - 401, 402, 403, 0, 404, 405, 0, 407, 408, 409, - 410, 0, 412, 413, 414, 415, 416, 417, 418, 419, - 420, 421, 422, 423, 0, 0, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 0, 0, 434, 435, 436, - 437, 0, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 535, 452, 453, 0, 0, - 454, 455, 0, 456, 0, 458, 459, 460, 461, 462, - 0, 463, 464, 465, 0, 0, 466, 467, 468, 469, - 470, 0, 471, 472, 473, 474, 475, 476, 477, 478, - 0, 0, 479, 480, 481, 0, 0, 482, 483, 484, - 485, 0, 486, 487, 488, 489, 490, 491, 492, 493, - 0, 494, 0, 496, 497, 498, 499, 500, 501, 502, - 0, 0, 503, 0, 0, 504, 505, 506, 507, 508, + 0, 401, 402, 0, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 0, 421, 422, 423, 424, 425, 426, 427, + 428, 429, 0, 0, 431, 432, 433, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 531, 448, 449, 0, 0, 450, 451, 0, 452, + 0, 454, 455, 456, 457, 458, 0, 459, 460, 461, + 0, 0, 462, 463, 464, 465, 466, 0, 467, 468, + 469, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 487, 488, 489, 0, 490, 0, 492, 493, + 494, 495, 496, 497, 498, 0, 0, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, + 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, + 520, 1502, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 118, 119, 120, 121, 122, 123, 124, 125, 0, 126, + 127, 128, 0, 0, 0, 1503, 0, 0, 0, 0, + 1504, 130, 131, 0, 132, 133, 134, 1505, 136, 137, + 138, 0, 1506, 1507, 1508, 1509, 0, 144, 145, 146, + 147, 148, 149, 0, 0, 150, 151, 152, 153, 1510, + 1511, 156, 0, 157, 158, 159, 160, 0, 0, 1512, + 0, 1513, 164, 165, 166, 167, 168, 1514, 170, 171, + 172, 0, 173, 174, 175, 176, 177, 178, 0, 1515, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 1516, 191, 192, 1517, 194, 0, 195, 0, 196, 197, + 198, 199, 200, 201, 0, 0, 202, 203, 204, 205, + 0, 0, 206, 207, 1073, 209, 210, 0, 211, 212, + 213, 0, 214, 215, 216, 0, 217, 218, 219, 220, + 0, 222, 223, 224, 225, 226, 227, 0, 0, 229, + 0, 230, 231, 1518, 233, 0, 234, 0, 235, 1519, + 0, 1520, 238, 239, 0, 1521, 242, 0, 243, 0, + 0, 0, 246, 247, 0, 248, 249, 250, 251, 252, + 253, 254, 1522, 256, 257, 258, 259, 0, 260, 261, + 262, 263, 264, 265, 266, 0, 267, 1523, 0, 270, + 271, 272, 273, 274, 1524, 1525, 0, 1526, 0, 278, + 1527, 1528, 281, 1529, 283, 284, 285, 286, 287, 288, + 0, 0, 289, 1530, 291, 1531, 0, 293, 294, 295, + 296, 297, 298, 299, 300, 1532, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 1533, 1534, 1535, 325, + 326, 327, 0, 0, 329, 330, 1536, 332, 0, 0, + 334, 1537, 336, 337, 338, 0, 339, 340, 0, 0, + 341, 342, 343, 0, 0, 344, 345, 0, 1538, 348, + 1539, 0, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 0, 0, 0, 0, 362, 363, 0, + 1540, 366, 367, 0, 369, 370, 371, 0, 372, 373, + 374, 375, 376, 377, 0, 378, 379, 380, 381, 382, + 1541, 384, 385, 386, 387, 0, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 0, + 401, 402, 1542, 404, 405, 406, 1543, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 0, 1544, 421, 422, 423, 424, 425, 426, 1545, 428, + 429, 0, 1546, 431, 432, 1547, 434, 0, 435, 436, + 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, + 1548, 448, 0, 0, 0, 450, 451, 0, 452, 1549, + 454, 455, 456, 457, 458, 0, 459, 1550, 1551, 0, + 0, 462, 463, 0, 465, 0, 0, 467, 468, 1552, + 470, 471, 472, 473, 474, 1553, 0, 475, 476, 477, + 0, 478, 479, 480, 481, 0, 482, 483, 484, 485, + 486, 0, 1554, 489, 0, 490, 1555, 492, 493, 494, + 495, 496, 497, 498, 0, 0, 499, 0, 0, 500, + 501, 502, 503, 504, 505, 1502, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 517, 518, 519, 520, + 0, 0, 0, 0, 118, 119, 120, 121, 122, 123, + 124, 125, 0, 126, 127, 128, 0, 0, 0, 1503, + 0, 0, 0, 0, 1504, 130, 131, 0, 132, 133, + 134, 1505, 136, 137, 138, 0, 1506, 1507, 1508, 1509, + 0, 144, 145, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 1510, 1511, 156, 0, 157, 158, 159, + 160, 0, 0, 1512, 0, 1513, 164, 165, 166, 167, + 168, 1514, 170, 171, 172, 0, 173, 174, 175, 176, + 177, 178, 0, 1515, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 1516, 191, 192, 1517, 194, 0, + 195, 0, 196, 197, 198, 199, 200, 201, 0, 0, + 202, 203, 204, 205, 0, 0, 206, 207, 1073, 209, + 210, 0, 211, 212, 213, 0, 1863, 215, 216, 0, + 217, 218, 219, 220, 0, 222, 223, 224, 225, 226, + 227, 0, 0, 229, 0, 230, 231, 1518, 233, 0, + 234, 0, 235, 1519, 0, 1520, 238, 239, 0, 1521, + 242, 0, 243, 0, 0, 0, 246, 247, 0, 248, + 249, 250, 251, 252, 253, 254, 1522, 256, 257, 258, + 259, 0, 260, 261, 262, 263, 264, 265, 266, 0, + 267, 1523, 0, 270, 271, 272, 273, 274, 1524, 1525, + 0, 1526, 0, 278, 1527, 1528, 281, 1529, 283, 284, + 285, 286, 287, 288, 0, 0, 289, 1530, 291, 1531, + 0, 293, 294, 295, 296, 297, 298, 299, 300, 1532, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, + 1533, 1534, 1535, 325, 326, 327, 0, 0, 329, 330, + 1536, 332, 0, 0, 334, 1537, 336, 337, 338, 0, + 339, 340, 0, 0, 341, 342, 343, 0, 0, 344, + 345, 0, 1538, 348, 1539, 0, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, 361, 0, 0, 0, + 0, 362, 363, 0, 1540, 366, 367, 0, 369, 370, + 371, 0, 372, 373, 374, 375, 376, 377, 0, 378, + 379, 380, 381, 382, 1541, 384, 385, 386, 387, 0, + 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, + 398, 399, 400, 0, 401, 402, 1542, 404, 405, 406, + 1543, 408, 409, 410, 411, 412, 413, 414, 415, 416, + 417, 418, 419, 420, 0, 1544, 421, 422, 423, 424, + 425, 426, 1545, 428, 429, 0, 1546, 431, 432, 1547, + 434, 0, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 1548, 448, 0, 0, 0, 450, + 451, 0, 452, 1549, 454, 455, 456, 457, 458, 0, + 459, 1550, 1551, 0, 0, 462, 463, 0, 465, 0, + 0, 467, 468, 1552, 470, 471, 472, 473, 474, 1553, + 0, 475, 476, 477, 0, 478, 479, 480, 481, 0, + 482, 483, 484, 485, 486, 0, 1554, 489, 0, 490, + 1555, 492, 493, 494, 495, 496, 497, 498, 0, 0, + 499, 0, 0, 500, 501, 502, 503, 504, 505, 3233, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 517, 518, 519, 520, 0, 0, 0, 0, 118, 119, + 120, 121, 122, 123, 124, 125, 0, 126, 127, 128, + 0, 0, 0, 2974, 0, 0, 0, 0, 2975, 130, + 131, 0, 132, 133, 134, 2976, 136, 137, 138, 0, + 1506, 2977, 1508, 1509, 0, 144, 145, 146, 147, 148, + 149, 0, 0, 150, 151, 152, 153, 1510, 1511, 156, + 0, 157, 158, 159, 160, 0, 0, 2978, 0, 2979, + 164, 165, 166, 167, 168, 2980, 170, 171, 172, 0, + 173, 174, 175, 176, 177, 178, 0, 2981, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 1516, 191, + 192, 1517, 194, 0, 195, 0, 196, 197, 198, 199, + 200, 201, 0, 0, 202, 203, 204, 205, 0, 0, + 206, 207, 1073, 209, 210, 0, 211, 212, 213, 0, + 214, 215, 216, 0, 217, 218, 219, 220, 0, 222, + 223, 224, 225, 226, 227, 0, 0, 229, 0, 230, + 231, 1518, 233, 0, 234, 0, 235, 2982, 0, 2983, + 238, 239, 2984, 2985, 242, 0, 243, 0, 0, 0, + 246, 247, 0, 248, 249, 250, 251, 252, 253, 254, + 2986, 256, 257, 258, 259, 0, 260, 261, 262, 263, + 264, 265, 266, 0, 267, 2987, 0, 270, 271, 272, + 273, 274, 1524, 1525, 0, 1526, 0, 278, 2988, 2989, + 281, 2990, 283, 284, 285, 286, 287, 288, 0, 0, + 289, 2991, 291, 2992, 0, 293, 294, 295, 296, 297, + 298, 299, 300, 3234, 302, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, + 318, 319, 320, 321, 1533, 2994, 1535, 325, 326, 327, + 0, 0, 329, 330, 2996, 332, 0, 0, 334, 1537, + 336, 337, 338, 0, 339, 340, 0, 0, 341, 342, + 343, 0, 0, 344, 345, 0, 2998, 348, 2999, 0, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 0, 0, 0, 0, 362, 363, 0, 3000, 366, + 367, 0, 369, 370, 371, 0, 372, 373, 374, 375, + 376, 377, 0, 378, 379, 380, 381, 382, 1541, 384, + 385, 386, 387, 0, 388, 389, 390, 391, 392, 393, + 394, 395, 396, 397, 398, 399, 400, 0, 401, 402, + 3001, 404, 405, 406, 0, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 0, 3002, + 421, 422, 423, 424, 425, 426, 0, 428, 429, 0, + 3004, 431, 432, 1547, 434, 0, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 3235, 448, + 0, 0, 0, 450, 451, 0, 452, 3006, 454, 455, + 456, 457, 458, 0, 459, 1550, 1551, 0, 0, 462, + 463, 0, 465, 0, 0, 467, 468, 3007, 470, 471, + 472, 473, 474, 0, 0, 475, 476, 477, 0, 478, + 479, 480, 481, 0, 482, 483, 484, 485, 486, 0, + 1554, 489, 0, 490, 3009, 492, 493, 494, 495, 496, + 497, 498, 0, 0, 499, 0, 0, 500, 501, 502, + 503, 504, 505, 528, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 517, 518, 519, 520, 0, 0, + 0, 0, 118, 119, 120, 121, 122, 123, 124, 125, + 0, 126, 127, 128, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 130, 131, 0, 132, 133, 134, 0, + 136, 137, 138, 139, 140, 0, 142, 143, 0, 144, + 145, 146, 147, 148, 149, 0, 0, 150, 151, 152, + 153, 154, 155, 156, 0, 157, 158, 159, 160, 161, + 0, 0, 0, 163, 164, 165, 166, 167, 168, 0, + 170, 171, 172, 0, 173, 174, 175, 176, 177, 178, + 0, 0, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 0, 195, 0, + 196, 197, 198, 199, 200, 201, 0, 0, 202, 203, + 204, 205, 0, 0, 206, 207, 208, 209, 210, 0, + 211, 212, 213, 0, 214, 215, 216, 0, 217, 218, + 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, + 0, 229, 0, 230, 231, 232, 233, 0, 234, 0, + 235, 0, 0, 0, 238, 239, 529, 0, 242, 0, + 243, 0, 244, 245, 0, 247, 0, 248, 249, 250, + 251, 252, 253, 254, 0, 256, 257, 258, 259, 0, + 260, 261, 262, 263, 264, 265, 266, 0, 267, 0, + 269, 270, 271, 272, 273, 274, 275, 276, 0, 277, + 0, 278, 0, 0, 281, 0, 283, 284, 285, 286, + 287, 288, 0, 0, 289, 0, 291, 0, 0, 293, + 294, 295, 296, 297, 298, 299, 300, 530, 302, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, 318, 319, 320, 321, 322, 0, + 324, 325, 326, 327, 328, 0, 329, 330, 0, 332, + 0, 333, 334, 335, 336, 337, 338, 0, 339, 340, + 0, 0, 341, 342, 343, 0, 0, 344, 345, 346, + 0, 348, 0, 350, 351, 352, 353, 354, 355, 356, + 0, 358, 359, 360, 361, 0, 0, 0, 0, 362, + 363, 364, 0, 366, 367, 368, 369, 370, 371, 0, + 372, 373, 374, 375, 376, 377, 0, 378, 379, 380, + 0, 382, 383, 384, 385, 386, 387, 0, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, + 400, 0, 401, 402, 0, 404, 405, 406, 407, 0, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 0, 0, 421, 422, 423, 424, 425, 426, + 427, 428, 429, 0, 0, 431, 432, 433, 434, 0, + 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, + 445, 446, 531, 448, 449, 0, 0, 450, 451, 0, + 452, 0, 454, 455, 456, 457, 458, 0, 459, 460, + 461, 0, 0, 462, 463, 464, 465, 466, 0, 467, + 468, 469, 470, 471, 472, 473, 474, 0, 0, 475, + 476, 477, 0, 478, 479, 480, 481, 0, 482, 483, + 484, 485, 486, 487, 488, 489, 0, 490, 0, 492, + 493, 494, 495, 496, 497, 498, 0, 0, 499, 0, + 0, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, - 519, 520, 521, 522, 523, 524, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 2, 0, 3, 4, + 519, 520, 1797, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, + 0, 118, 119, 120, 121, 122, 123, 124, 125, 0, + 126, 127, 128, 0, 0, 0, 1503, 0, 0, 0, + 0, 1504, 130, 131, 0, 132, 133, 134, 1505, 136, + 137, 138, 0, 1506, 1507, 1508, 1509, 0, 144, 145, + 146, 147, 148, 149, 0, 0, 150, 151, 152, 153, + 1510, 1511, 156, 0, 157, 158, 159, 160, 0, 0, + 1512, 0, 1513, 164, 165, 166, 167, 168, 1514, 170, + 171, 172, 0, 173, 174, 175, 176, 177, 178, 0, + 1515, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 1516, 191, 192, 1517, 194, 0, 195, 0, 196, + 197, 198, 199, 200, 201, 0, 0, 202, 203, 204, + 205, 0, 0, 206, 207, 1073, 209, 210, 0, 211, + 212, 213, 0, 214, 215, 216, 0, 217, 218, 219, + 220, 0, 222, 223, 224, 225, 226, 227, 0, 0, + 229, 0, 230, 231, 1518, 233, 0, 234, 0, 235, + 1519, 0, 1520, 238, 239, 0, 1521, 242, 0, 243, + 0, 0, 0, 246, 247, 0, 248, 249, 250, 251, + 252, 253, 254, 1522, 256, 257, 258, 259, 0, 260, + 261, 262, 263, 264, 265, 266, 0, 267, 1523, 0, + 270, 271, 272, 273, 274, 1524, 1525, 0, 1526, 0, + 278, 1527, 1528, 281, 1529, 283, 284, 285, 286, 287, + 288, 0, 0, 289, 1530, 291, 1531, 0, 293, 294, + 295, 296, 297, 298, 299, 300, 0, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + 315, 316, 317, 318, 319, 320, 321, 1533, 1534, 1535, + 325, 326, 327, 0, 0, 329, 330, 1536, 332, 0, + 0, 334, 1537, 336, 337, 338, 0, 339, 340, 0, + 0, 341, 342, 343, 0, 0, 344, 345, 0, 1538, + 348, 1539, 0, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, 361, 0, 0, 0, 0, 362, 363, + 0, 1540, 366, 367, 0, 369, 370, 371, 0, 372, + 373, 374, 375, 376, 377, 0, 378, 379, 380, 381, + 382, 1541, 384, 385, 386, 387, 0, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 0, 401, 402, 1542, 404, 405, 406, 0, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, + 420, 0, 1544, 421, 422, 423, 424, 425, 426, 0, + 428, 429, 0, 1546, 431, 432, 1547, 434, 0, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 0, 448, 0, 0, 0, 450, 451, 0, 452, + 1549, 454, 455, 456, 457, 458, 0, 459, 1550, 1551, + 0, 0, 462, 463, 0, 465, 0, 0, 467, 468, + 1552, 470, 471, 472, 473, 474, 0, 0, 475, 476, + 477, 0, 478, 479, 480, 481, 0, 482, 483, 484, + 485, 486, 0, 1554, 489, 0, 490, 1555, 492, 493, + 494, 495, 496, 497, 498, 0, 1, 499, 0, 0, + 500, 501, 502, 503, 504, 505, 2, 0, 3, 4, + 0, 0, 0, 0, 1, 0, 0, 517, 518, 519, + 520, 0, 0, 0, 2, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 11, 0, 756, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 6, 0, 0, 0, 0, 8, + 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, + 10, 0, 0, 0, 0, 0, 0, 8, 0, 0, + 0, 0, 11, 0, 751, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, + 11, 0, 751, 0, 0, 0, 0, 0, 0, 0, + 14, 15, 0, 13, 0, 0, 0, 0, 0, 0, + 0, 752, 0, 0, 0, 0, 0, 18, 14, 15, + 0, 0, 0, 0, 0, 19, 0, 0, 0, 752, + 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, + 0, 0, 22, 19, 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 757, 0, 0, 0, 0, 0, 18, 0, 0, - 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 22, 0, 0, 0, 23, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, -1497, 0, + 22, 0, 0, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, -1468, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, -1468, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, + 27, 28, 0, 0, 0, 0, 0, 29, 0, 0, + 30, 0, 0, 0, 0, 0, 0, 26, 27, 28, + 0, 0, 0, 0, 0, 29, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 31, 0, 0, 0, 0, 0, 0, 0, 0, + 32, 0, 0, 0, 0, 0, 0, 0, 0, 31, + 0, 0, 0, 0, 0, 0, 33, 0, 32, 0, + 0, 0, 0, 34, 0, 0, 0, 35, 0, 0, + 0, 0, 0, 0, 33, 0, 0, 36, 0, 0, + 0, 34, 0, 0, 0, 35, 0, 0, 0, 37, + 0, 0, 0, 38, 0, 36, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 37, 0, 0, + 0, 38, 0, 39, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 40, 0, 0, 0, + 0, 39, 42, 0, 0, 0, 0, 43, 0, 0, + 0, 0, 753, 0, 40, 0, 0, 0, 0, 0, + 42, 0, 0, 0, 44, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 26, 27, 28, 0, 0, 0, 0, 0, 29, 0, - 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, - 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, - 0, 0, 0, 0, 34, 0, 0, 0, 35, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 37, 0, 0, 0, 38, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 40, - 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, - 43, 0, 0, 0, 0, 758, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, + 0, 0, 44, 0, 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 754, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 759 + 46 }; static const yytype_int16 yycheck[] = { - 7, 0, 751, 525, 846, 0, 46, 0, 0, 16, - 0, 0, 0, 908, 0, 0, 23, 0, 0, 820, - 920, 759, 936, 893, 1453, 1182, 38, 1264, 20, 1249, - 1005, 1735, 941, 870, 1237, 20, 1697, 1251, 7, 2245, - 1229, 1469, 1099, 1587, 1331, 20, 77, 996, 37, 996, - 2309, 1613, 1051, 77, 23, 16, 996, 1506, 73, 996, - 1626, 986, 2215, 1857, 2217, 1786, 1669, 1226, 75, 76, - 1308, 1217, 23, 1650, 1651, 0, 2235, 1356, 1801, 2053, - 971, 975, 17, 0, 2763, 986, 908, 2723, 910, 1147, - 912, 2723, 0, 0, 1152, 1254, 1849, 0, 45, 111, - 2234, 2181, 2761, 0, 758, 0, 75, 76, 34, 0, - 2783, 759, 101, 0, 1014, 2586, 1839, 752, 2790, 2642, - 2382, 1701, 0, 0, 75, 76, 2675, 0, 0, 815, - 2679, 2054, 1871, 1108, 1874, 821, 0, 1870, 0, 5, - 0, 0, 7, 2300, 0, 1753, 40, 13, 14, 1073, - 1074, 5, 1669, 1755, 0, 0, 0, 994, 23, 0, - 1845, 2899, 0, 5, 75, 76, 1090, 1988, 0, 0, - 55, 4, 9, 3, 2394, 2394, 9, 10, 3125, 783, - 2390, 5, 5, 139, 74, 5, 5, 5, 2388, 13, - 14, 0, 5, 986, 5, 5, 997, 3108, 119, 9, - 13, 14, 13, 14, 34, 35, 5, 5, 5, 45, - 75, 76, 9, 5, 13, 14, 5, 5, 3129, 5, - 5, 5, 5, 13, 14, 173, 30, 3, 63, 5, - 122, 45, 4, 1158, 38, 2531, 23, 9, 3, 4, - 5, 172, 13, 14, 9, 11, 2403, 914, 986, 11, - 16, 30, 104, 2958, 16, 9, 2026, 2027, 865, 38, - 53, 82, 3004, 63, 1164, 82, 245, 2037, 63, 100, - 1107, 2041, 93, 124, 1273, 122, 93, 1191, 30, 169, - 46, 107, 3305, 5, 1283, 191, 38, 172, 75, 76, - 812, 100, 4, 203, 888, 181, 26, 9, 888, 227, - 2457, 2458, 63, 2460, 288, 172, 3076, 810, 314, 90, - 291, 1468, 998, 1238, 80, 311, 1241, 1242, 296, 122, - 3105, 213, 276, 296, 1010, 80, 2635, 291, 2637, 181, - 1077, 108, 311, 107, 1127, 989, 132, 859, 2016, 2017, - 2018, 171, 117, 173, 290, 273, 1093, 40, 129, 1506, - 184, 119, 117, 193, 1557, 383, 2509, 392, 107, 117, - 13, 14, 40, 3472, 370, 1158, 213, 1654, 1020, 2691, - 1212, 1213, 1052, 1025, 3232, 1027, 3234, 279, 64, 1216, - 2903, 2935, 369, 2937, 177, 30, 346, 41, 74, 30, - 149, 11, 3548, 3505, 1046, 374, 259, 260, 132, 11, - 164, 194, 83, 15, 16, 401, 199, 137, 460, 460, - 485, 11, 432, 4, 342, 192, 191, 120, 9, 172, - 122, 273, 401, 3334, 3060, 385, 160, 1958, 1342, 120, - 33, 2690, 507, 162, 46, 137, 360, 3398, 148, 3400, - 330, 3120, 201, 1313, 237, 1238, 46, 290, 1241, 1242, - 193, 2204, 472, 3132, 219, 3637, 59, 2663, 1989, 290, - 80, 421, 1371, 3122, 374, 393, 390, 148, 80, 521, - 521, 411, 126, 273, 453, 385, 241, 3633, 1158, 166, - 80, 290, 2804, 176, 3596, 147, 521, 132, 3597, 285, - 200, 132, 195, 2573, 3441, 397, 3678, 525, 176, 273, - 275, 3359, 433, 457, 195, 1792, 1563, 341, 272, 238, - 516, 421, 280, 473, 167, 3476, 379, 380, 295, 359, - 3262, 1024, 280, 479, 488, 521, 361, 308, 2837, 457, - 2687, 362, 2689, 3303, 521, 475, 370, 521, 108, 3281, - 521, 462, 521, 3248, 3329, 11, 280, 525, 3571, 15, - 16, 285, 525, 362, 543, 241, 218, 1237, 280, 2855, - 450, 361, 2128, 473, 294, 457, 361, 2777, 2362, 2363, - 2364, 1175, 2772, 521, 460, 521, 2796, 2796, 430, 510, - 46, 1188, 418, 11, 2187, 1378, 1379, 15, 16, 3536, - 390, 598, 523, 1115, 1261, 421, 400, 2046, 1522, 1523, - 361, 3155, 395, 11, 418, 472, 1355, 15, 16, 460, - 457, 1360, 433, 356, 80, 521, 433, 1366, 1856, 2181, - 1214, 400, 1459, 1547, 1214, 374, 3537, 329, 358, 523, - 360, 1473, 408, 409, 296, 1373, 521, 598, 325, 1918, - 2614, 471, 2219, 2251, 3382, 426, 2467, 470, 400, 3322, - 2252, 1331, 483, 1495, 457, 521, 75, 2814, 2238, 164, - 390, 2400, 2395, 1950, 530, 2405, 485, 521, 524, 3305, - 2187, 108, 2357, 3305, 483, 1962, 530, 519, 1892, 521, - 433, 523, 2244, 520, 1608, 1609, 524, 525, 507, 521, - 525, 522, 524, 524, 527, 528, 1933, 521, 521, 485, - 1699, 521, 521, 521, 3253, 1992, 440, 132, 521, 3258, - 521, 521, 1999, 522, 3237, 524, 2975, 451, 1372, 759, - 2982, 507, 521, 521, 521, 1373, 231, 1362, 3199, 521, - 525, 521, 521, 521, 0, 521, 521, 521, 521, 162, - 512, 513, 0, 1643, 1644, 1645, 421, 512, 513, 214, - 521, 517, 759, 1590, 1591, 517, 2043, 2527, 512, 513, - 2047, 3440, 20, 1600, 519, 23, 758, 266, 523, 520, - 810, 483, 510, 758, 3447, 526, 3448, 1614, 522, 37, - 1466, 525, 1529, 521, 759, 162, 8, 449, 46, 2076, - 167, 275, 799, 15, 16, 507, 280, 19, 20, 21, - 512, 513, 1549, 810, 483, 817, 3498, 3499, 132, 1646, - 817, 435, 1605, 2051, 173, 238, 1591, 75, 76, 77, - 106, 521, 2956, 322, 1617, 1600, 1619, 420, 507, 1481, - 799, 862, 2510, 2511, 2512, 2513, 160, 1584, 862, 846, - 847, 810, 2636, 101, 2001, 250, 26, 485, 817, 525, - 275, 1503, 32, 865, 2828, 1648, 340, 799, 3550, 810, - 285, 238, 486, 870, 287, 82, 459, 3546, 82, 507, - 275, 883, 3009, 3532, 524, 817, 93, 1557, 893, 93, - 3017, 880, 2962, 521, 425, 880, 427, 880, 880, 2046, - 880, 880, 880, 868, 880, 880, 1821, 880, 880, 810, - 510, 1900, 514, 515, 516, 517, 1831, 922, 471, 1834, - 287, 918, 919, 523, 520, 922, 923, 1666, 13, 14, - 526, 1816, 848, 849, 871, 851, 2205, 853, 2531, 519, - 3589, 516, 275, 523, 799, 3571, 526, 1029, 523, 3571, - 2914, 2864, 4, 1035, 2867, 810, 2869, 9, 5, 3106, - 309, 275, 817, 2011, 59, 880, 280, 137, 356, 1752, - 1753, 285, 1784, 880, 425, 251, 427, 2688, 975, 1878, - 26, 25, 880, 880, 1654, 261, 32, 880, 3657, 986, - 1850, 1851, 1852, 880, 1024, 880, 993, 994, 2741, 880, - 2743, 2714, 999, 880, 1816, 1002, 1003, 989, 1005, 1006, - 1007, 1008, 880, 880, 989, 3264, 941, 880, 880, 1934, - 2733, 2573, 799, 342, 1836, 1022, 880, 1024, 880, 1841, - 880, 880, 108, 810, 2601, 1916, 1033, 2306, 1821, 1920, - 817, 1925, 1923, 1934, 880, 880, 880, 396, 1831, 880, - 519, 1834, 521, 1050, 1051, 1052, 512, 513, 514, 515, - 516, 517, 5, 1022, 485, 1024, 516, 483, 521, 485, - 2489, 37, 116, 523, 1033, 1072, 178, 172, 1108, 4, - 292, 1022, 521, 1024, 9, 2221, 507, 2223, 1827, 227, - 2508, 137, 1033, 1832, 1091, 3244, 514, 515, 516, 517, - 521, 203, 245, 71, 72, 1941, 1103, 1104, 1105, 1945, - 1107, 1108, 1948, 1110, 512, 513, 514, 515, 516, 517, - 1632, 1022, 1792, 1024, 294, 519, 440, 2274, 245, 523, - 2407, 2358, 1033, 2337, 519, 273, 521, 451, 523, 241, - 2368, 147, 147, 26, 519, 425, 1143, 427, 523, 32, - 519, 1934, 26, 2315, 523, 2317, 162, 162, 32, 1110, - 74, 167, 167, 356, 1161, 1162, 3415, 1022, 311, 1024, - 1997, 2723, 13, 14, 1195, 1196, 178, 1198, 1033, 381, - 174, 1195, 1196, 2926, 1198, 3149, 1188, 1034, 358, 132, - 381, 1038, 522, 295, 311, 525, 2345, 189, 190, 119, - 1197, 13, 14, 117, 1201, 1202, 1934, 173, 425, 252, - 427, 30, 218, 218, 1211, 1212, 1213, 160, 203, 1216, - 390, 316, 317, 318, 3442, 848, 849, 2687, 851, 2689, - 853, 374, 238, 238, 522, 2414, 26, 525, 438, 241, - 1237, 2420, 32, 209, 421, 1022, 2211, 1024, 294, 473, - 522, 1253, 246, 525, 137, 393, 1033, 374, 401, 225, - 378, 2088, 2855, 137, 521, 2976, 85, 259, 260, 235, - 2547, 13, 14, 381, 346, 94, 1273, 2060, 162, 521, - 1950, 287, 287, 167, 401, 521, 1283, 207, 383, 167, - 296, 296, 1962, 463, 521, 543, 508, 509, 510, 118, - 512, 513, 514, 515, 516, 517, 522, 521, 354, 525, - 453, 1308, 358, 385, 885, 3099, 887, 3535, 521, 457, - 3538, 522, 1992, 425, 525, 427, 421, 521, 1458, 1999, - 1460, 1461, 275, 172, 1331, 2891, 453, 280, 13, 14, - 2167, 1330, 285, 522, 390, 1330, 525, 137, 450, 421, - 1347, 453, 346, 273, 238, 275, 2216, 1330, 1330, 1356, - 455, 275, 522, 26, 522, 525, 280, 525, 521, 32, - 521, 466, 191, 2043, 13, 14, 1373, 2047, 521, 833, - 834, 835, 2529, 2053, 838, 204, 2533, 379, 380, 521, - 1372, 385, 2831, 1390, 13, 14, 1347, 1372, 1395, 365, - 3649, 473, 522, 287, 521, 525, 2076, 521, 1373, 2943, - 2962, 294, 522, 3631, 514, 525, 330, 463, 384, 522, - 294, 522, 525, 425, 525, 427, 521, 421, 526, 522, - 507, 2312, 525, 2314, 348, 2218, 13, 14, 3634, 1390, - 3636, 504, 522, 449, 449, 525, 2723, 2279, 1445, 1446, - 521, 453, 522, 224, 1451, 525, 1453, 523, 3601, 290, - 26, 1458, 1459, 1460, 1461, 504, 32, 2250, 2251, 522, - 525, 354, 525, 3616, 137, 358, 1473, 1474, 171, 473, - 354, 3677, 522, 521, 358, 525, 1483, 522, 1485, 2393, - 525, 1488, 522, 40, 1453, 2705, 1493, 440, 1495, 1496, - 522, 1498, 2706, 525, 294, 1502, 522, 390, 451, 525, - 758, 759, 2739, 60, 519, 522, 390, 522, 523, 522, - 13, 14, 525, 522, 1483, 2704, 1485, 2706, 3671, 1488, - 172, 2578, 2579, 3676, 1493, 117, 450, 1496, 522, 1498, - 295, 525, 1483, 1502, 1485, 2755, 460, 1488, 13, 14, - 522, 799, 1493, 525, 59, 1496, 521, 1498, 422, 106, - 1557, 1502, 810, 522, 354, 224, 525, 522, 358, 817, - 525, 137, 522, 522, 245, 525, 525, 504, 522, 152, - 463, 525, 1483, 522, 1485, 354, 525, 1488, 407, 463, - 172, 410, 1493, 1590, 1591, 1496, 522, 1498, 1453, 525, - 390, 1502, 1599, 1600, 1587, 1587, 152, 1587, 1587, 1587, - 1607, 1587, 1587, 108, 862, 2442, 2555, 1614, 2555, 2556, - 2557, 2586, 13, 14, 1621, 2555, 2556, 2554, 1483, 176, - 1485, 294, 880, 1488, 522, 174, 522, 525, 1493, 525, - 311, 1496, 152, 1498, 1641, 1642, 152, 1502, 3391, 1646, - 3393, 522, 1649, 522, 525, 202, 525, 1654, 1655, 1656, - 1657, 1658, 1659, 1660, 1661, 1662, 1663, 245, 369, 370, - 1667, 1668, 1669, 463, 522, 1672, 1453, 525, 522, 1676, - 152, 525, 1679, 1680, 1681, 1682, 1683, 1684, 1685, 1686, - 1687, 354, 37, 1690, 1699, 358, 2435, 13, 14, 40, - 1697, 421, 1699, 374, 251, 82, 1483, 246, 1485, 522, - 1669, 1488, 1663, 1003, 261, 2443, 1493, 1738, 521, 1496, - 1717, 1498, 304, 275, 1738, 1502, 273, 390, 294, 40, - 401, 108, 473, 311, 316, 317, 318, 2407, 13, 14, - 89, 989, 13, 14, 1741, 152, 147, 6, 3025, 793, - 1715, 10, 3403, 3305, 487, 1752, 1753, 152, 305, 18, - 523, 162, 13, 14, 2654, 152, 167, 152, 2551, 2552, - 13, 14, 290, 32, 1022, 356, 1024, 36, 13, 14, - 433, 825, 453, 13, 14, 1033, 13, 14, 354, 521, - 245, 521, 358, 13, 14, 1792, 374, 174, 13, 14, - 463, 383, 13, 14, 521, 1802, 850, 346, 522, 1806, - 13, 14, 521, 360, 13, 14, 423, 218, 220, 3023, - 1068, 46, 8, 401, 390, 11, 203, 300, 173, 15, - 16, 225, 1080, 19, 20, 21, 521, 238, 385, 421, - 13, 14, 13, 14, 225, 2677, 385, 245, 521, 3126, - 521, 1802, 1849, 225, 898, 1806, 311, 297, 405, 1856, - 1108, 40, 1859, 1860, 209, 236, 172, 3060, 2767, 246, - 172, 369, 370, 455, 521, 453, 3103, 2547, 369, 370, - 225, 5, 421, 5, 466, 521, 287, 2747, 326, 2793, - 235, 369, 370, 263, 264, 296, 521, 463, 379, 380, - 2727, 483, 5, 1900, 521, 3599, 465, 466, 521, 3603, - 2425, 2426, 5, 311, 3611, 3612, 3193, 1896, 521, 374, - 5, 1918, 3643, 3644, 521, 507, 2807, 5, 1925, 1926, - 521, 3350, 1161, 1162, 473, 2286, 2287, 1934, 2927, 521, - 2723, 9, 986, 521, 2614, 521, 401, 1195, 1196, 521, - 1198, 484, 996, 1950, 302, 178, 525, 1954, 1955, 104, - 1957, 525, 522, 460, 3658, 1962, 1963, 1964, 1965, 1966, - 1967, 1968, 220, 390, 1971, 1972, 1973, 1974, 1975, 1976, - 1977, 1978, 1979, 1980, 167, 167, 287, 285, 59, 1986, - 1987, 236, 521, 1990, 433, 1992, 93, 374, 453, 525, - 1997, 433, 1999, 401, 59, 59, 433, 433, 385, 266, - 316, 317, 318, 199, 316, 317, 318, 151, 241, 3571, - 365, 222, 526, 433, 2021, 433, 483, 381, 3305, 152, - 100, 2028, 199, 2030, 275, 275, 222, 2034, 172, 384, - 40, 40, 275, 275, 421, 521, 2043, 275, 449, 523, - 2047, 521, 2049, 2723, 2051, 453, 2053, 152, 172, 13, - 522, 60, 522, 172, 522, 521, 521, 444, 522, 2028, - 522, 522, 525, 1117, 522, 2034, 480, 383, 522, 2076, - 521, 383, 2865, 1127, 225, 225, 3505, 2028, 282, 282, - 521, 2088, 2089, 2034, 523, 525, 473, 521, 521, 3014, - 521, 470, 521, 521, 178, 1149, 292, 106, 3318, 521, - 523, 39, 521, 479, 1158, 421, 9, 431, 519, 421, - 11, 2860, 523, 521, 1372, 521, 431, 2028, 3547, 526, - 2127, 520, 356, 2034, 2131, 525, 431, 2167, 3556, 2136, - 2137, 525, 280, 531, 433, 3026, 3027, 521, 181, 455, - 163, 374, 172, 455, 227, 1445, 1446, 525, 2828, 522, - 466, 1451, 40, 13, 466, 2162, 2163, 241, 460, 19, - 2167, 218, 525, 2028, 266, 393, 227, 3596, 291, 2034, - 30, 483, 316, 317, 318, 314, 2183, 314, 525, 2186, - 2187, 2188, 525, 181, 44, 45, 220, 522, 521, 3164, - 227, 227, 425, 202, 427, 507, 275, 2204, 2205, 296, - 3437, 523, 59, 8, 2211, 521, 11, 2214, 1262, 521, - 15, 16, 59, 59, 19, 20, 21, 3374, 2187, 59, - 453, 3014, 282, 2230, 282, 1483, 3019, 1485, 522, 335, - 1488, 315, 288, 521, 2914, 1493, 2243, 473, 1496, 383, - 1498, 2028, 251, 152, 1502, 2214, 2995, 2034, 3, 109, - 521, 521, 261, 2260, 2261, 152, 152, 152, 152, 483, - 525, 2230, 525, 2214, 273, 40, 290, 275, 3, 290, - 2277, 40, 2279, 59, 172, 3068, 3069, 421, 11, 2230, - 40, 167, 181, 522, 3571, 2292, 167, 3, 39, 521, - 374, 522, 3, 522, 520, 522, 305, 381, 521, 2306, - 519, 126, 127, 521, 519, 433, 433, 433, 2315, 2316, - 2317, 455, 508, 509, 510, 433, 512, 513, 514, 515, - 516, 517, 466, 522, 522, 8, 531, 522, 11, 1587, - 504, 525, 15, 16, 522, 1389, 19, 20, 21, 483, - 522, 425, 504, 427, 5, 3025, 522, 172, 523, 2214, - 522, 360, 2359, 36, 2315, 2316, 2317, 523, 2398, 354, - 3574, 2368, 522, 507, 148, 2230, 522, 521, 3282, 453, - 172, 433, 521, 504, 521, 521, 385, 521, 155, 521, - 3060, 480, 40, 59, 525, 510, 506, 291, 2387, 291, - 457, 244, 2387, 59, 199, 2402, 405, 59, 266, 472, - 2407, 433, 275, 525, 2387, 2387, 521, 3145, 152, 203, - 152, 1669, 152, 521, 433, 433, 433, 222, 433, 40, - 2427, 521, 356, 288, 522, 521, 290, 2214, 521, 483, - 522, 525, 521, 7, 8, 2442, 2443, 40, 152, 13, - 530, 2402, 280, 2230, 2451, 19, 3126, 2969, 522, 23, - 172, 25, 521, 151, 522, 29, 30, 31, 521, 59, - 34, 186, 14, 37, 38, 126, 127, 41, 167, 3149, - 44, 45, 522, 522, 172, 522, 80, 519, 522, 143, - 1738, 522, 2489, 522, 199, 525, 172, 292, 526, 522, - 2451, 316, 317, 318, 525, 521, 525, 522, 301, 3292, - 3293, 75, 76, 250, 362, 3405, 522, 521, 521, 521, - 291, 172, 3305, 3193, 181, 522, 152, 522, 521, 525, - 2489, 176, 444, 3360, 2531, 3362, 522, 101, 522, 522, - 3372, 523, 521, 521, 108, 109, 110, 111, 112, 222, - 2547, 522, 525, 521, 40, 86, 2586, 2559, 40, 40, - 460, 525, 172, 521, 482, 522, 522, 2564, 383, 8, - 199, 522, 11, 2570, 2571, 520, 15, 16, 520, 394, - 19, 20, 21, 522, 3375, 525, 3377, 522, 522, 2586, - 522, 466, 525, 290, 2624, 510, 59, 3562, 205, 522, - 522, 483, 417, 3507, 117, 2602, 421, 46, 2605, 522, - 2607, 522, 40, 521, 53, 227, 88, 2614, 2615, 292, - 192, 2618, 2619, 433, 2629, 280, 2623, 2624, 316, 317, - 318, 3516, 522, 2630, 2489, 3305, 1884, 3497, 280, 433, - 455, 80, 523, 523, 523, 510, 523, 2677, 1896, 523, - 2647, 466, 40, 523, 275, 523, 523, 523, 3490, 523, - 2657, 523, 523, 1707, 523, 316, 317, 318, 483, 520, - 523, 523, 2651, 1963, 1964, 1965, 1966, 1967, 1968, 523, - 2677, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, - 1980, 523, 507, 107, 523, 383, 523, 523, 523, 523, - 523, 523, 523, 523, 523, 523, 521, 523, 521, 523, - 560, 523, 2489, 508, 509, 510, 523, 512, 513, 514, - 515, 516, 517, 2720, 523, 522, 2723, 2724, 483, 2726, - 2727, 2728, 383, 421, 520, 522, 1780, 1781, 177, 522, - 521, 421, 290, 394, 2741, 9, 2743, 355, 521, 521, - 525, 521, 337, 59, 522, 194, 525, 199, 522, 520, - 199, 192, 525, 525, 522, 522, 417, 455, 91, 2720, - 421, 465, 2802, 2724, 522, 2726, 2773, 2766, 466, 348, - 2028, 2766, 178, 2762, 40, 521, 2034, 152, 3571, 124, - 523, 522, 152, 2766, 2766, 483, 40, 370, 237, 370, - 1844, 522, 40, 522, 455, 3544, 172, 203, 521, 40, - 521, 525, 521, 460, 310, 466, 2795, 1861, 1862, 507, - 280, 521, 2852, 249, 191, 460, 444, 74, 2825, 521, - 80, 2828, 483, 521, 293, 508, 509, 510, 74, 512, - 513, 514, 515, 516, 517, 241, 9, 522, 2845, 2846, - 522, 2848, 521, 292, 372, 2852, 507, 522, 2855, 520, - 520, 59, 133, 37, 93, 273, 510, 290, 42, 444, - 521, 40, 2162, 2163, 293, 521, 293, 465, 521, 205, - 290, 522, 522, 522, 290, 2882, 522, 390, 122, 457, - 1934, 74, 369, 148, 25, 36, 1940, 80, 369, 295, - 298, 3571, 2707, 753, 880, 2902, 2307, 1814, 2720, 3407, - 93, 2908, 2909, 2310, 3547, 2655, 2913, 2914, 3501, 2167, - 3119, 2918, 2952, 3648, 2921, 2922, 37, 101, 1925, 2926, - 2927, 42, 3019, 2930, 117, 3522, 119, 2934, 304, 2187, - 2430, 857, 3626, 3275, 3575, 3584, 3619, 1224, 2945, 3336, - 316, 317, 318, 2298, 2316, 2203, 395, 3469, 1792, 40, - 2943, 2943, 1792, 2943, 2943, 2943, 2214, 2943, 2943, 2784, - 3573, 2697, 3582, 2726, 2295, 2934, 1355, 3570, 374, 60, - 544, 2425, 2230, 2426, 1328, 549, 2386, 2451, 552, 3145, - 101, 2277, 2989, 2934, 2757, 1777, 560, 2728, 2243, 173, - 2997, 1181, 1204, 1021, 1021, 1205, 2508, 181, 3556, 2260, - 1741, 3478, 3364, 23, 1776, 8, 1207, 383, 11, 3016, - 2230, 871, 15, 16, 207, 106, 2855, 2040, 3025, 425, - 1042, 427, 998, 2934, 3188, 209, 2539, 2489, 3296, 2488, - 1934, 2056, 1934, 996, 3025, 1934, 996, 996, 444, 996, - 996, 225, 996, 46, 450, 421, 3482, 453, 996, 996, - 53, 235, 173, 3060, 3481, 996, 505, 2571, 2244, 508, - 509, 510, 2187, 512, 513, 514, 515, 516, 517, 2934, - 2138, 2090, 1474, 2140, 2945, 2184, 2598, 80, 2905, 455, - 3467, 794, 275, 1373, 1862, 269, 2049, 280, 209, 1715, - 466, 2656, 898, 2943, 1716, -1, -1, -1, 3105, -1, - -1, -1, -1, -1, 225, -1, 290, 483, -1, -1, - -1, 202, 3119, -1, 235, -1, -1, -1, -1, 3126, - -1, 1052, -1, -1, 3164, -1, -1, -1, -1, -1, - 3137, 507, 316, -1, 3123, -1, -1, 330, 3145, 323, - 2398, 3148, 3149, -1, 3105, 521, 1052, 2934, 269, -1, - -1, -1, -1, -1, -1, 348, -1, 3164, 3119, -1, - 251, -1, -1, -1, -1, -1, -1, -1, -1, 290, - 261, -1, -1, 1052, 177, -1, -1, 751, 752, 753, - -1, 365, 273, -1, -1, -1, 3193, -1, -1, -1, - -1, 194, 3199, -1, -1, 316, 199, -1, -1, -1, - 384, -1, 323, -1, -1, -1, -1, -1, -1, 3216, - 3217, -1, -1, 3220, 305, 3222, -1, -1, -1, 793, - 794, -1, -1, -1, -1, 799, -1, 801, -1, -1, - -1, -1, -1, -1, 237, -1, 810, -1, -1, -1, - 814, 815, 3249, 817, 365, -1, 820, 821, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 450, -1, 833, - 834, 835, -1, 384, 838, -1, 3273, 460, 2322, 360, - -1, 455, 846, 847, 848, 849, 460, 851, -1, 853, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, - -1, 865, -1, -1, 385, -1, -1, 871, 3305, -1, - -1, -1, -1, -1, 178, -1, 1237, -1, -1, 883, - -1, -1, -1, -1, 405, -1, -1, -1, 2618, 2619, - -1, 1181, 3329, 897, 898, -1, 2380, -1, 2586, 203, - -1, 1237, -1, -1, 455, 3324, -1, -1, 8, 460, - -1, 11, -1, 3350, 2398, 15, 16, -1, -1, 19, - 20, 21, -1, 3360, -1, 3362, -1, 3364, 1237, 933, - 934, 3368, -1, 3370, -1, 3372, 2624, 241, 3329, -1, - -1, 945, -1, -1, -1, 949, 950, 951, 952, 3386, - -1, 3350, -1, -1, 3391, -1, 3393, -1, -1, 2443, - -1, 965, 395, 2651, -1, -1, 3403, -1, -1, 2453, - 1331, 2455, -1, -1, -1, 2459, -1, 2461, -1, 3416, - -1, -1, 40, -1, 3421, 3404, -1, 3406, -1, 2677, - -1, 295, -1, 997, 998, 1331, 1000, -1, -1, 1003, - -1, 522, 60, -1, -1, 1009, 1010, -1, -1, -1, - -1, 315, 1016, -1, -1, -1, -1, -1, 1022, -1, - 1024, -1, 1331, -1, -1, 3416, -1, 3446, -1, 1033, - -1, 3468, -1, -1, -1, -1, -1, -1, -1, 1043, - -1, 3478, -1, 3462, -1, -1, -1, -1, 106, 107, - -1, -1, -1, 3490, 8, 3350, 1060, 11, -1, 117, - -1, 15, 16, -1, -1, 19, 20, 21, 3505, -1, - 374, -1, 505, 1363, 2762, 1365, -1, 381, -1, 512, - 513, 514, 515, 516, 517, -1, 3523, -1, -1, -1, - -1, 8, -1, -1, 11, 2825, -1, -1, 15, 16, - -1, -1, 19, 20, 21, -1, 3505, 2795, 1112, -1, - 3547, -1, -1, -1, 2802, -1, -1, -1, 176, 36, - -1, 425, 222, 427, -1, 3562, -1, -1, -1, -1, - -1, -1, -1, 3350, 3571, -1, 3573, -1, -1, -1, - 444, -1, -1, -1, 202, -1, 450, -1, 3547, 453, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 3596, - -1, 1165, -1, -1, 2852, -1, -1, -1, -1, 3588, - -1, -1, -1, 3610, 3611, 3612, -1, 1181, 1182, -1, - -1, -1, 3573, -1, 1188, -1, -1, -1, -1, -1, - -1, 8, 292, 251, 11, 3614, 1557, 3596, 15, 16, - 3637, -1, -1, 261, -1, -1, -1, 1211, 1212, 1213, - 3505, -1, -1, -1, -1, 273, -1, 275, -1, 1223, - 1224, 1557, -1, -1, -1, -1, -1, -1, -1, 46, - -1, -1, 1236, -1, -1, -1, 53, -1, -1, 2723, - -1, 3678, -1, -1, -1, -1, 2934, 305, 1557, 1253, - -1, -1, 3547, 1257, -1, 2943, -1, -1, -1, 1263, - -1, -1, -1, 80, 2952, -1, -1, 2997, 222, -1, - -1, -1, -1, 2757, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 8, -1, -1, 11, 3505, -1, - -1, 15, 16, 1654, -1, 19, 20, 21, -1, -1, - -1, 3596, 360, -1, 13, 222, -1, -1, -1, -1, - 19, -1, -1, -1, 23, -1, -1, -1, 1654, -1, - 1324, 30, 1326, -1, -1, -1, -1, 385, 145, -1, - 3547, 1335, 37, -1, -1, 44, 45, 42, 292, -1, - -1, -1, 1346, -1, -1, 1654, -1, 405, -1, 407, - -1, 1355, 410, -1, -1, -1, 1360, -1, 1362, 1363, - 177, 1365, 1366, -1, -1, -1, 75, 76, -1, -1, - -1, -1, -1, -1, -1, 292, -1, 194, -1, 3596, - -1, -1, 199, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 101, -1, -1, -1, - 109, -1, -1, -1, -1, -1, -1, 37, 508, 509, - 510, 41, 512, 513, 514, 515, 516, 517, 3148, -1, - 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 1792, -1, -1, -1, 3123, -1, -1, -1, -1, - -1, 1445, 1446, -1, -1, -1, -1, 1451, -1, 1453, - -1, -1, -1, -1, 2938, -1, 1792, -1, -1, -1, - -1, -1, 1466, 521, 1468, 1469, -1, -1, 173, 1473, - 1474, 101, 1476, -1, -1, 292, 3164, -1, 108, 1483, - 110, 1485, 112, 1792, 1488, -1, -1, -1, -1, 1493, - -1, 1495, 1496, -1, 1498, -1, -1, 1787, 1502, -1, - 1504, -1, 1506, -1, 209, -1, -1, -1, 1798, -1, - 1800, -1, -1, 1803, -1, -1, -1, -1, -1, -1, - 225, -1, -1, 1813, -1, 1815, -1, -1, -1, -1, - 235, -1, -1, -1, -1, -1, -1, -1, 1828, -1, - -1, -1, -1, 1833, -1, -1, -1, 1837, 1838, -1, - 1840, 1052, 1842, 1843, 508, 509, 510, -1, 512, 513, - 514, 515, 516, 517, 269, -1, -1, -1, 292, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 395, -1, - -1, -1, -1, -1, -1, 290, -1, -1, -1, 1950, - -1, 508, 509, 510, -1, 512, 513, 514, 515, 516, - 517, 1962, -1, -1, -1, -1, -1, -1, -1, 1613, - -1, 316, 8, -1, 1950, 11, -1, -1, 323, 15, - 16, -1, 1626, 19, 20, 21, 1962, -1, -1, -1, - 3114, 1992, -1, -1, -1, -1, 3324, -1, 1999, -1, - 36, 1950, -1, -1, -1, -1, -1, -1, -1, -1, - 46, -1, -1, 1962, -1, -1, 1992, 53, 3346, -1, - 365, 3145, 1666, 1999, -1, 1669, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 384, - -1, -1, 2043, 1992, 80, -1, 2047, -1, 505, -1, - 1999, -1, 2053, 1697, -1, 512, 513, 514, 515, 516, - 517, -1, -1, -1, -1, -1, -1, 2043, 1712, -1, - 1714, 2047, 1716, -1, -1, 2076, 3404, 2053, 3406, -1, - -1, -1, -1, 1727, -1, 1729, -1, -1, -1, -1, - -1, -1, 55, -1, 2043, -1, 1237, 1741, 2047, -1, - 2076, -1, -1, -1, 2053, -1, -1, -1, -1, 3233, - 455, -1, 37, -1, -1, -1, -1, 42, 3446, -1, - -1, -1, 1766, 0, 1768, -1, -1, 2076, -1, -1, - -1, -1, -1, -1, 3462, -1, 1780, 1781, -1, 102, - -1, 177, 1786, 1787, 508, 509, 510, -1, 512, 513, - 514, 515, 516, 517, 1798, 1799, 1800, 1801, 194, 1803, - 123, -1, -1, 199, -1, -1, -1, -1, -1, 1813, - -1, 1815, -1, -1, -1, -1, 101, -1, 141, -1, - -1, 3305, 145, 1827, 1828, -1, 222, 223, 1832, 1833, - 1331, -1, -1, 1837, 1838, 1839, 1840, -1, 1842, 1843, - -1, 237, -1, -1, -1, 168, 8, -1, 171, 11, - -1, 560, -1, 15, 16, -1, -1, -1, -1, 1863, - -1, -1, -1, 100, 187, -1, -1, 1871, -1, 1873, - 1874, 1875, 1876, 1877, -1, -1, -1, -1, -1, 275, - -1, -1, 278, -1, 46, -1, -1, -1, 173, -1, - 1894, 53, -1, -1, -1, -1, 292, -1, -1, 295, - 3588, -1, -1, -1, -1, -1, -1, -1, -1, 1913, - 147, -1, -1, -1, 544, -1, -1, -1, 80, 549, - -1, -1, 552, -1, 209, 162, 3614, -1, -1, -1, - 167, -1, -1, -1, -1, 172, 2226, -1, -1, -1, - 225, -1, -1, -1, 181, -1, -1, -1, -1, 186, - 235, -1, -1, -1, 3438, -1, -1, 280, -1, 1963, - 1964, 1965, 1966, 1967, 1968, 288, -1, 1971, 1972, 1973, - 1974, 1975, 1976, 1977, 1978, 1979, 1980, -1, -1, -1, - -1, 218, -1, 145, 269, -1, -1, 310, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 2001, -1, 395, - -1, 238, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 2015, -1, -1, -1, 177, -1, 340, -1, -1, - -1, -1, -1, -1, 2028, -1, -1, -1, -1, -1, - 2034, 316, 194, -1, -1, -1, 2040, 199, 323, -1, - -1, 98, 2046, 752, 753, -1, 2407, -1, -1, -1, - 287, 2055, 2056, 290, -1, -1, 1557, -1, -1, 296, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 126, - 127, 2407, -1, -1, -1, 237, -1, -1, -1, -1, - 365, -1, -1, -1, -1, -1, -1, 3571, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 2407, 384, - 337, 810, -1, -1, -1, -1, -1, -1, -1, 505, - -1, -1, 508, 509, 510, 172, 512, 513, 514, 515, - 516, 517, -1, -1, 2128, 362, -1, 2417, -1, 2133, - 292, -1, -1, -1, 2138, 8, -1, -1, 11, -1, - -1, -1, 15, 16, -1, -1, 19, 20, 21, -1, - -1, -1, -1, 1654, -1, -1, 1052, -1, 2162, 2163, - -1, -1, 871, 36, -1, -1, -1, -1, -1, -1, - 455, 801, -1, -1, -1, -1, -1, 2181, -1, -1, - -1, -1, -1, 2187, 421, -1, 2547, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 2214, 2547, 449, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 2226, 460, -1, -1, 2230, -1, -1, -1, - 2234, -1, -1, 395, -1, -1, -1, -1, 2547, -1, - -1, -1, -1, 480, -1, 482, 483, -1, -1, -1, - -1, -1, -1, 2614, -1, -1, -1, -1, -1, 316, - 317, 318, -1, -1, -1, -1, -1, 897, -1, -1, - 2274, -1, -1, 2277, -1, 2279, 2280, -1, 2614, -1, - -1, -1, 519, -1, -1, 522, 523, 524, -1, -1, - -1, 1792, -1, -1, -1, -1, 2300, -1, -1, -1, - -1, -1, -1, 933, -1, 2614, -1, 1016, -1, -1, - -1, -1, -1, 1022, -1, 1024, -1, 1052, -1, 949, - 950, 951, 952, -1, 1033, -1, 383, -1, -1, -1, - -1, -1, -1, -1, 1043, -1, -1, 394, -1, -1, - -1, 1237, -1, 505, -1, -1, -1, -1, -1, 222, - 512, 513, 514, 515, 516, 517, -1, -1, -1, -1, - 417, -1, 2723, -1, 421, -1, -1, -1, -1, -1, - 1000, -1, -1, -1, -1, -1, -1, -1, 2382, -1, - -1, -1, -1, -1, 441, 2389, -1, 2723, -1, -1, - 2680, -1, -1, 2683, -1, -1, 2400, -1, 455, 2403, - 2404, 2405, 2406, 1112, -1, -1, -1, -1, -1, 466, - -1, -1, -1, 2417, 2723, 2419, -1, -1, 2422, 292, - -1, -1, 2712, -1, -1, 2429, 483, -1, -1, -1, - -1, 2435, -1, -1, -1, 1331, -1, -1, -1, 2729, - 2730, 2731, 2732, -1, 2734, 2735, 2736, 2737, 2738, 1950, - 507, -1, -1, 2457, 2458, -1, 2460, -1, -1, -1, - -1, 1962, -1, -1, 521, -1, -1, 2828, -1, -1, - -1, -1, 1181, 1182, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 2489, -1, -1, -1, -1, - -1, 1992, 2828, -1, -1, -1, -1, -1, 1999, -1, - -1, -1, 1237, 2507, -1, -1, -1, -1, -1, -1, - -1, 2515, 2516, 2517, -1, -1, -1, -1, -1, 2828, - -1, -1, -1, 8, -1, 2529, 11, 2531, -1, 2533, - 15, 16, -1, -1, -1, 2539, -1, -1, -1, -1, - -1, -1, 2043, -1, -1, -1, 2047, -1, -1, -1, - -1, -1, 2053, 2914, -1, 2559, -1, -1, -1, -1, - -1, 46, -1, -1, -1, -1, -1, -1, 53, 2573, - -1, -1, -1, -1, -1, 2076, -1, -1, 2914, -1, - -1, 2585, -1, -1, -1, 2589, -1, -1, -1, -1, - -1, -1, -1, 1223, -1, 80, 1331, -1, -1, -1, - -1, -1, -1, -1, -1, 2914, 1236, -1, -1, -1, - -1, -1, -1, -1, 2618, 2619, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 1257, -1, -1, - -1, -1, -1, -1, 1003, 508, 509, 510, 2642, 512, - 513, 514, 515, 516, 517, 2649, -1, -1, -1, -1, - -1, 2655, -1, 1362, 1363, -1, 1365, -1, -1, -1, - 145, 1557, -1, -1, 3025, -1, -1, 2671, -1, -1, - -1, 2675, -1, 2677, -1, 2679, 2680, -1, -1, 2683, - -1, -1, -1, 2687, 2688, 2689, -1, 2691, -1, 3025, - -1, -1, 177, -1, -1, -1, 1326, -1, -1, 3060, - -1, -1, -1, -1, -1, 1335, 2996, -1, 2712, 194, - 2714, -1, -1, -1, 199, -1, 3025, -1, -1, -1, - -1, -1, -1, -1, 3060, 2729, 2730, 2731, 2732, 2733, - 2734, 2735, 2736, 2737, 2738, -1, 26, -1, -1, -1, - -1, -1, 32, -1, -1, -1, -1, -1, -1, -1, - 40, 3060, 237, -1, -1, -1, -1, 2761, 1654, 1468, - -1, -1, -1, -1, 2768, 3126, -1, -1, -1, -1, - 60, -1, -1, -1, 1483, -1, 1485, -1, -1, 1488, - 2784, -1, -1, -1, 1493, -1, -1, 1496, 3149, 1498, - 3126, -1, -1, 1502, -1, 1504, -1, 1506, -1, -1, - 2804, -1, -1, -1, -1, -1, -1, 292, -1, -1, - 2814, -1, -1, 3149, -1, -1, 106, 3126, -1, -1, - -1, 2825, 1557, -1, -1, -1, -1, 2831, -1, -1, - -1, -1, 3193, 1202, 2838, 2839, 2840, 2841, -1, -1, - 3149, -1, 1211, -1, -1, -1, 1476, 137, 2852, -1, - -1, 2855, -1, -1, -1, 2859, 2860, 3193, -1, -1, - -1, -1, -1, -1, 2868, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 3193, -1, -1, 2891, -1, -1, - -1, -1, -1, -1, 2898, 2899, 1792, -1, -1, 2903, - -1, -1, -1, -1, -1, -1, 2407, -1, -1, -1, - 395, -1, 202, -1, -1, -1, -1, 1626, -1, 1654, - -1, -1, -1, -1, -1, -1, -1, -1, 2932, -1, - 2934, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 2945, 8, -1, 3305, 11, -1, -1, 2952, 15, - 16, -1, 2956, 19, 20, 21, -1, -1, 2962, -1, - -1, 251, -1, -1, -1, -1, -1, -1, -1, 3305, - 36, 261, 2976, 0, -1, -1, -1, -1, 2982, -1, - -1, -1, -1, 273, -1, -1, -1, -1, 1003, -1, - -1, 2995, 2996, 2997, 3284, -1, 3305, -1, -1, 3003, - -1, -1, -1, -1, 294, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 305, 3020, -1, 3308, 3309, - 505, -1, -1, -1, -1, -1, -1, 512, 513, 514, - 515, 516, 517, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 3333, -1, -1, 2547, 26, -1, -1, - -1, -1, -1, 32, 1950, -1, -1, 1792, -1, 1768, - -1, 40, -1, -1, 354, -1, 1962, -1, 358, -1, - 360, -1, -1, 100, -1, -1, 1445, 1446, 1787, -1, - -1, 60, 1451, -1, 1714, -1, 1716, -1, -1, 1798, - -1, 1800, -1, -1, 1803, 385, 1992, 1727, 3102, -1, - 390, -1, 3106, 1999, 1813, -1, 1815, -1, -1, -1, - -1, -1, -1, 2614, -1, 405, -1, -1, 3122, 1828, - 147, -1, -1, -1, 1833, -1, -1, 106, 1837, 1838, - -1, 1840, -1, 1842, 1843, 162, 1766, 3141, -1, -1, - 167, -1, -1, -1, 3148, 172, -1, 2043, -1, -1, - -1, 2047, -1, -1, 181, -1, 222, 2053, 137, 186, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 3174, -1, -1, 463, -1, -1, -1, 3181, -1, -1, - 2076, -1, -1, -1, 3188, -1, -1, -1, -1, -1, - -1, 218, -1, -1, -1, -1, 1211, -1, -1, -1, - -1, 3205, -1, -1, -1, -1, -1, -1, -1, -1, - 3571, 238, -1, -1, -1, 1950, -1, -1, -1, -1, - -1, -1, 2723, 202, -1, 3229, 292, 1962, -1, -1, - -1, -1, -1, 3237, -1, 3571, -1, -1, -1, -1, - -1, -1, -1, 1873, 1874, 1875, 1876, 1877, -1, 3253, - -1, -1, -1, -1, 3258, -1, -1, 1992, -1, -1, - 287, -1, 3571, 290, 1999, -1, -1, -1, -1, 296, - -1, -1, 251, -1, -1, -1, -1, 3567, -1, -1, - 3284, -1, 261, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 2001, -1, 273, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 3308, 3309, -1, -1, 2043, -1, - 337, -1, 2047, -1, -1, 294, -1, -1, 2053, 2028, - -1, 3325, -1, 3327, -1, 2034, 305, 2828, -1, 3333, - -1, 2040, -1, -1, -1, 362, -1, 2046, -1, -1, - -1, 2076, -1, 3347, 8, -1, 3350, 11, -1, -1, - -1, 15, 16, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 3370, -1, 3372, -1, - 3374, 3375, 1741, 3377, -1, 354, -1, -1, 3382, 358, - -1, 360, 46, -1, -1, 2015, -1, -1, -1, 53, - -1, -1, -1, -1, 421, -1, -1, -1, -1, 3403, - -1, -1, -1, 3407, -1, -1, 385, -1, -1, -1, - 3414, 390, -1, 2914, -1, -1, 80, -1, -1, 2128, - -1, -1, 449, -1, -1, -1, 405, -1, -1, 2138, - 1445, 1446, -1, 460, -1, -1, 1451, -1, -1, -1, - 3444, -1, 508, 509, 510, -1, 512, 513, 514, 515, - 516, 517, -1, 480, -1, 482, 483, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 3482, -1, - -1, 145, -1, -1, 463, -1, 3490, -1, -1, -1, - -1, -1, 519, -1, -1, 522, 523, 524, -1, -1, - -1, 3505, -1, -1, -1, 2214, 846, 847, -1, -1, - -1, 2407, -1, 177, -1, -1, -1, 2226, -1, -1, - -1, 2230, -1, -1, 3025, -1, -1, -1, 3532, -1, - 194, -1, -1, -1, -1, 199, -1, -1, -1, -1, - 3544, 3545, -1, 3547, 3548, -1, -1, -1, -1, -1, - -1, -1, 3556, -1, -1, -1, -1, -1, -1, 3060, - -1, -1, -1, 3567, -1, 2274, -1, -1, -1, -1, - -1, 2280, -1, 237, -1, -1, -1, -1, 918, -1, - -1, -1, 922, 923, -1, 3589, -1, -1, -1, -1, - -1, -1, 3596, -1, 1963, 1964, 1965, 1966, 1967, 1968, - -1, -1, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, - 1979, 1980, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 3126, -1, -1, 292, 3633, - -1, -1, -1, -1, -1, 975, -1, -1, -1, -1, - -1, -1, -1, -1, 3648, -1, -1, -1, 3149, -1, - -1, 2547, -1, 993, -1, -1, -1, -1, -1, 999, - -1, -1, 1002, -1, -1, 1005, 1006, 1007, 1008, -1, - -1, -1, 2407, -1, -1, -1, -1, -1, -1, -1, - 1695, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 3193, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 2417, -1, - 1050, 1051, -1, -1, -1, -1, -1, -1, 2614, -1, - -1, -1, -1, -1, -1, -1, 1741, -1, -1, -1, - -1, 395, 1072, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 1091, -1, -1, -1, 0, -1, -1, -1, 2389, - -1, -1, -1, 1103, 1104, 1105, -1, 1107, 1108, -1, - -1, -1, -1, -1, 2404, 2405, 2406, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 2419, - -1, -1, 2422, 2162, 2163, -1, -1, -1, -1, 2429, - -1, -1, -1, 1143, 3305, -1, -1, -1, -1, -1, - -1, -1, 2547, -1, -1, -1, -1, -1, -1, -1, - 2529, 1161, 1162, -1, 2533, -1, -1, 2723, -1, -1, - 2539, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 505, -1, -1, -1, -1, -1, -1, 512, 513, - 514, 515, 516, 517, -1, 100, -1, 1197, -1, -1, - -1, 1201, 1202, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 1212, 1213, -1, -1, 2585, -1, -1, 2614, - 2589, -1, -1, -1, -1, 2515, 2516, 2517, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 147, -1, -1, -1, -1, -1, 2277, -1, - -1, -1, -1, -1, -1, -1, -1, 162, -1, -1, - -1, -1, 167, -1, -1, -1, -1, 172, -1, -1, - -1, -1, 2828, 1273, -1, -1, 181, -1, -1, 8, - -1, 186, 11, 1283, -1, -1, 15, 16, 1963, 1964, - 1965, 1966, 1967, 1968, -1, -1, 1971, 1972, 1973, 1974, - 1975, 1976, 1977, 1978, 1979, 1980, 2675, -1, 1308, -1, - 2679, 2680, -1, 218, 2683, -1, -1, 46, -1, -1, - -1, -1, -1, -1, 53, -1, -1, -1, 2723, -1, - -1, -1, -1, 238, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 2712, -1, -1, -1, -1, -1, -1, - -1, 80, -1, -1, -1, -1, -1, -1, 2914, -1, - 2729, 2730, 2731, 2732, -1, 2734, 2735, 2736, 2737, 2738, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 2671, 287, -1, -1, 290, -1, -1, -1, -1, - -1, 296, -1, -1, -1, 1395, -1, -1, -1, -1, + 7, 521, 46, 0, 0, 0, 0, 0, 0, 16, + 0, 0, 841, 888, 0, 746, 23, 0, 73, 903, + 815, 1443, 930, 7, 914, 999, 38, 0, 1256, 1459, + 1242, 1045, 1230, 965, 20, 754, 935, 20, 1720, 23, + 16, 1217, 1244, 1683, 1093, 7, 1175, 2221, 20, 990, + 1495, 1828, 990, 1612, 1836, 1321, 865, 1655, 1574, 77, + 2280, 23, 990, 980, 37, 1298, 1600, 1222, 75, 76, + 2029, 969, 2368, 23, 1210, 990, 2211, 980, 0, 77, + 17, 1219, 0, 2717, 0, 2190, 0, 2192, 1636, 1637, + 0, 75, 76, 0, 0, 2680, 0, 1140, 1346, 111, + 0, 0, 1145, 45, 0, 2276, 903, 0, 905, 1247, + 907, 2715, 0, 75, 76, 2680, 0, 34, 1008, 2156, + 2740, 2210, 754, 753, 747, 75, 76, 1101, 101, 810, + 0, 2733, 0, 0, 2547, 816, 2348, 0, 0, 5, + 1687, 0, 0, 75, 76, 2634, 1853, 13, 14, 2638, + 1850, 0, 5, 2030, 9, 0, 1738, 5, 9, 0, + 1967, 4, 1740, 1067, 1068, 2847, 9, 10, 63, 0, + 5, 3062, 5, 55, 0, 5, 9, 778, 2356, 988, + 1084, 45, 63, 5, 2360, 2360, 2354, 5, 80, 74, + 5, 5, 26, 5, 9, 5, 991, 1849, 2369, 13, + 14, 139, 5, 5, 997, 5, 5, 5, 45, 5, + 5, 5, 5, 13, 14, 13, 14, 13, 14, 1655, + 173, 3, 4, 5, 122, 13, 14, 9, 13, 14, + 4, 107, 82, 23, 1151, 9, 119, 4, 82, 860, + 3048, 11, 9, 93, 883, 147, 16, 1046, 172, 93, + 122, 1265, 2423, 2424, 30, 2426, 883, 3065, 90, 100, + 1274, 980, 38, 11, 2003, 2004, 104, 1157, 16, 3238, + 191, 40, 63, 3, 100, 2014, 1184, 63, 124, 2018, + 122, 172, 288, 2902, 169, 75, 76, 807, 11, 2493, + 172, 1100, 15, 16, 172, 296, 3018, 129, 46, 1071, + 5, 107, 173, 137, 34, 35, 53, 2883, 290, 2885, + 291, 992, 245, 805, 1231, 1087, 218, 1234, 1235, 2596, + 117, 2598, 291, 1004, 184, 1995, 1996, 1997, 107, 1458, + 5, 132, 80, 296, 854, 117, 245, 193, 30, 193, + 3370, 213, 119, 181, 11, 181, 38, 1545, 15, 16, + 276, 106, 1151, 983, 64, 3, 40, 5, 368, 166, + 382, 313, 391, 3400, 74, 3167, 1495, 3169, 345, 40, + 2475, 213, 3433, 41, 1640, 162, 1205, 1206, 279, 46, + 13, 14, 2650, 30, 3476, 119, 164, 108, 83, 30, + 482, 38, 117, 457, 296, 122, 3328, 480, 3330, 30, + 1209, 11, 2179, 482, 3565, 409, 120, 384, 507, 148, + 137, 1204, 504, 80, 794, 1937, 82, 369, 3003, 518, + 359, 504, 120, 3057, 1332, 504, 518, 93, 1303, 2649, + 177, 1230, 812, 3463, 3068, 273, 3466, 219, 309, 518, + 373, 171, 419, 173, 329, 3606, 1968, 194, 2622, 290, + 389, 238, 199, 148, 518, 3059, 3264, 132, 126, 241, + 294, 200, 1361, 3524, 290, 360, 191, 273, 472, 3561, + 80, 192, 3404, 207, 275, 2646, 308, 2648, 3369, 360, + 340, 195, 273, 280, 285, 160, 2754, 3289, 3525, 518, + 237, 132, 176, 470, 272, 396, 251, 195, 2535, 355, + 522, 132, 1551, 280, 358, 176, 261, 431, 518, 369, + 2787, 1777, 518, 2948, 3236, 3091, 485, 324, 451, 507, + 361, 522, 1321, 357, 395, 359, 1018, 1023, 454, 3559, + 3499, 241, 520, 1029, 167, 361, 518, 518, 476, 273, + 431, 275, 451, 419, 2103, 447, 2328, 2329, 2330, 11, + 275, 2729, 416, 15, 16, 389, 454, 178, 2726, 522, + 1181, 513, 3181, 448, 2162, 518, 539, 1168, 1207, 360, + 2746, 2746, 13, 3464, 360, 280, 459, 2022, 19, 416, + 1207, 431, 454, 507, 46, 518, 593, 431, 1108, 30, + 428, 469, 424, 2764, 373, 1771, 520, 518, 389, 2803, + 275, 328, 1835, 44, 45, 280, 1510, 1511, 513, 518, + 285, 457, 454, 482, 1345, 520, 2575, 593, 80, 1350, + 241, 457, 2156, 399, 516, 1356, 2433, 522, 520, 290, + 3312, 1535, 467, 11, 1463, 504, 518, 15, 16, 480, + 1449, 522, 1435, 1436, 1363, 2227, 2194, 394, 1441, 1897, + 2228, 3253, 518, 3238, 480, 1484, 108, 3465, 509, 510, + 132, 527, 517, 1929, 2371, 518, 2366, 2214, 109, 1871, + 518, 1685, 521, 3238, 527, 1941, 521, 522, 519, 482, + 521, 524, 525, 518, 1912, 518, 2220, 518, 518, 482, + 521, 1595, 1596, 519, 516, 521, 518, 3186, 520, 2919, + 518, 504, 3191, 518, 518, 1971, 518, 399, 518, 2361, + 754, 504, 1978, 480, 2926, 518, 518, 164, 518, 518, + 518, 3134, 518, 518, 518, 518, 2162, 509, 510, 1352, + 518, 1363, 1362, 518, 3368, 509, 510, 504, 468, 1629, + 1630, 1631, 509, 510, 514, 1517, 1545, 754, 11, 3045, + 2489, 520, 399, 2019, 33, 457, 3376, 2023, 406, 407, + 3195, 805, 162, 438, 75, 1537, 514, 753, 1577, 1578, + 753, 266, 275, 3375, 449, 1456, 227, 280, 1587, 3214, + 59, 433, 754, 46, 231, 149, 2052, 794, 511, 512, + 513, 514, 1601, 1448, 2027, 1450, 1451, 132, 805, 1571, + 812, 997, 423, 345, 425, 812, 2476, 2477, 2478, 2479, + 794, 2900, 26, 285, 26, 2597, 518, 80, 32, 2778, + 32, 805, 273, 1632, 162, 160, 321, 108, 812, 167, + 451, 483, 794, 888, 841, 842, 339, 201, 238, 857, + 3474, 1640, 384, 805, 511, 512, 513, 514, 860, 250, + 812, 1980, 3426, 3427, 2953, 805, 3460, 513, 865, 857, + 82, 916, 2961, 162, 520, 1879, 878, 1578, 167, 2906, + 418, 93, 419, 805, 275, 3046, 1587, 419, 875, 875, + 875, 875, 875, 875, 1801, 875, 875, 287, 1681, 875, + 341, 863, 875, 2022, 1811, 2493, 519, 1814, 227, 522, + 238, 518, 875, 2862, 3478, 912, 913, 5, 456, 916, + 917, 517, 1796, 3517, 3499, 516, 26, 523, 2695, 520, + 2697, 1652, 32, 137, 866, 137, 843, 844, 470, 846, + 517, 848, 2180, 1726, 3499, 2812, 523, 4, 2815, 238, + 2817, 392, 9, 4, 273, 280, 0, 1990, 9, 287, + 285, 3585, 521, 875, 1829, 1830, 1831, 875, 1857, 875, + 522, 875, 969, 1895, 3260, 875, 468, 1899, 875, 875, + 1902, 875, 1769, 980, 1018, 875, 875, 3197, 1777, 875, + 987, 988, 875, 245, 13, 14, 993, 875, 287, 996, + 997, 875, 999, 1000, 1001, 1002, 1913, 983, 935, 1796, + 983, 2535, 275, 454, 794, 875, 1904, 875, 875, 1016, + 1913, 1018, 875, 875, 2562, 805, 875, 875, 4, 1816, + 1027, 214, 812, 9, 1821, 5, 203, 137, 126, 127, + 518, 516, 1016, 2455, 1018, 520, 516, 1044, 1045, 1046, + 520, 1028, 3177, 1027, 2474, 1032, 341, 509, 510, 511, + 512, 513, 514, 518, 1016, 519, 1018, 1101, 522, 1066, + 2196, 519, 2198, 392, 522, 1027, 1016, 245, 1018, 108, + 843, 844, 37, 846, 172, 848, 1807, 1027, 1085, 355, + 294, 1812, 294, 516, 1016, 518, 1018, 520, 2604, 1096, + 1097, 1098, 380, 1100, 1101, 1027, 1103, 2874, 1618, 71, + 72, 2334, 2304, 438, 203, 519, 516, 2373, 522, 380, + 520, 373, 74, 523, 449, 556, 132, 828, 829, 830, + 252, 2250, 833, 3343, 436, 454, 3085, 1103, 419, 1136, + 1929, 509, 510, 511, 512, 513, 514, 245, 423, 353, + 425, 353, 1941, 357, 160, 357, 2680, 1154, 1155, 1942, + 1943, 1944, 1945, 1946, 1947, 117, 470, 1950, 1951, 1952, + 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1976, 377, 1181, + 1188, 1189, 1971, 1191, 2312, 389, 423, 389, 425, 1978, + 167, 189, 190, 1190, 294, 380, 30, 1194, 1195, 451, + 1188, 1189, 518, 1191, 1913, 373, 373, 1204, 1205, 1206, + 178, 245, 1209, 245, 172, 2803, 519, 384, 173, 522, + 511, 519, 2186, 174, 522, 13, 14, 315, 316, 317, + 2019, 13, 14, 1230, 2023, 2380, 1016, 523, 1018, 1920, + 2029, 2386, 519, 1924, 1246, 522, 1927, 1027, 518, 1435, + 1436, 85, 419, 2509, 209, 1441, 460, 357, 460, 518, + 94, 259, 260, 2052, 518, 2064, 518, 3039, 1265, 275, + 225, 13, 14, 241, 280, 373, 26, 1274, 519, 285, + 235, 522, 32, 451, 118, 519, 13, 14, 522, 389, + 2839, 26, 13, 14, 382, 246, 26, 32, 516, 518, + 518, 1298, 32, 470, 518, 393, 519, 8, 519, 522, + 11, 522, 504, 519, 15, 16, 522, 748, 19, 20, + 21, 224, 519, 275, 1321, 522, 2191, 415, 280, 519, + 518, 419, 522, 25, 1320, 1320, 1320, 1320, 518, 373, + 1337, 373, 518, 2142, 259, 260, 2781, 501, 519, 1346, + 518, 522, 518, 451, 2137, 2138, 480, 191, 482, 59, + 460, 2283, 519, 2285, 452, 522, 1363, 3577, 26, 518, + 204, 1337, 2491, 518, 32, 463, 2495, 329, 13, 14, + 378, 379, 2906, 1380, 13, 14, 1362, 137, 1385, 1362, + 519, 147, 480, 522, 345, 347, 519, 290, 3562, 522, + 3564, 1363, 137, 13, 14, 373, 162, 137, 520, 364, + 519, 167, 519, 522, 1380, 522, 504, 451, 519, 451, + 518, 522, 519, 115, 2680, 522, 519, 501, 383, 522, + 518, 171, 438, 384, 3529, 866, 2255, 519, 1435, 1436, + 522, 3605, 519, 449, 1441, 522, 1443, 519, 518, 3544, + 522, 1448, 1449, 1450, 1451, 423, 519, 425, 522, 522, + 2662, 2359, 218, 378, 379, 519, 1463, 1464, 419, 1443, + 2253, 2663, 172, 13, 14, 1472, 2694, 1474, 519, 137, + 1477, 2647, 238, 451, 518, 1482, 518, 1484, 1485, 519, + 1487, 1443, 522, 423, 1491, 425, 448, 423, 1472, 425, + 1474, 2540, 2541, 1477, 3599, 457, 519, 2709, 1482, 3604, + 172, 1485, 519, 1487, 295, 522, 2661, 1491, 2663, 470, + 1472, 222, 1474, 519, 519, 1477, 522, 522, 13, 14, + 1482, 287, 1472, 1485, 1474, 1487, 59, 1477, 519, 1491, + 296, 522, 1482, 518, 294, 1485, 420, 1487, 1545, 37, + 1472, 1491, 1474, 501, 3321, 1477, 3323, 224, 519, 294, + 1482, 522, 152, 1485, 294, 1487, 2286, 353, 2288, 1491, + 519, 405, 519, 522, 408, 522, 519, 13, 14, 522, + 1577, 1578, 40, 2547, 2373, 152, 2517, 1574, 2516, 1586, + 1587, 292, 1574, 152, 1574, 1574, 152, 1594, 1574, 2517, + 2518, 1574, 152, 353, 1601, 419, 174, 357, 2646, 2408, + 2648, 1574, 2517, 2518, 2519, 315, 316, 317, 353, 13, + 14, 8, 357, 353, 11, 13, 14, 357, 15, 16, + 1627, 1628, 19, 20, 21, 1632, 294, 519, 1635, 389, + 1685, 13, 14, 1640, 1641, 1642, 1643, 1644, 1645, 1646, + 1647, 1648, 1649, 880, 389, 882, 1653, 1654, 1655, 389, + 518, 1658, 275, 1443, 40, 1662, 13, 14, 1665, 1666, + 1667, 1668, 1669, 1670, 1671, 1672, 1673, 470, 246, 1676, + 2401, 1655, 382, 1649, 89, 173, 1683, 152, 1685, 13, + 14, 447, 1472, 484, 1474, 353, 152, 1477, 520, 357, + 2409, 3331, 1482, 13, 14, 1485, 1703, 1487, 1046, 152, + 460, 1491, 147, 2969, 3238, 1723, 13, 14, 178, 419, + 2509, 209, 13, 14, 152, 460, 290, 162, 355, 1726, + 460, 389, 167, 2613, 431, 1723, 519, 225, 518, 1701, + 1737, 1738, 518, 1174, 13, 14, 518, 235, 13, 14, + 13, 14, 452, 518, 2920, 421, 1942, 1943, 1944, 1945, + 1946, 1947, 300, 463, 1950, 1951, 1952, 1953, 1954, 1955, + 1956, 1957, 1958, 1959, 225, 2967, 220, 345, 13, 14, + 1777, 241, 518, 218, 13, 14, 2575, 368, 369, 1786, + 518, 1788, 368, 369, 368, 369, 2579, 2580, 368, 369, + 263, 264, 460, 238, 505, 506, 507, 225, 509, 510, + 511, 512, 513, 514, 225, 3003, 384, 2636, 518, 297, + 1786, 1014, 1788, 378, 379, 3043, 1019, 1020, 1021, 462, + 463, 1828, 2721, 40, 40, 2757, 2701, 236, 1835, 2391, + 2392, 1838, 1839, 1036, 6, 2743, 518, 1040, 10, 3571, + 3572, 419, 287, 60, 314, 3527, 18, 3539, 3540, 3531, + 5, 296, 1154, 1155, 2262, 2263, 5, 518, 3280, 518, + 32, 2875, 3128, 325, 36, 518, 364, 518, 5, 5, + 518, 5, 1879, 5, 518, 481, 9, 518, 518, 302, + 522, 2680, 1230, 104, 522, 383, 519, 40, 220, 106, + 1897, 167, 470, 389, 287, 292, 167, 1904, 1905, 59, + 285, 236, 1875, 373, 3586, 518, 1913, 431, 518, 93, + 380, 522, 1353, 431, 1355, 59, 59, 431, 266, 431, + 108, 523, 1929, 222, 431, 431, 1933, 1934, 480, 1936, + 380, 100, 152, 275, 1941, 1942, 1943, 1944, 1945, 1946, + 1947, 2137, 2138, 1950, 1951, 1952, 1953, 1954, 1955, 1956, + 1957, 1958, 1959, 423, 275, 425, 199, 275, 1965, 1966, + 518, 40, 1969, 275, 1971, 3499, 275, 518, 82, 1976, + 152, 1978, 3238, 1321, 172, 520, 13, 519, 0, 2778, + 519, 451, 2775, 172, 519, 202, 522, 519, 519, 519, + 519, 518, 477, 2000, 108, 225, 519, 225, 2005, 282, + 2007, 282, 447, 518, 2011, 518, 522, 2800, 467, 520, + 518, 3433, 2019, 518, 518, 518, 2023, 26, 2025, 518, + 2027, 2005, 2029, 32, 39, 518, 520, 2011, 476, 9, + 429, 40, 11, 429, 251, 518, 355, 3249, 2970, 2971, + 517, 2958, 522, 2005, 261, 2052, 528, 523, 522, 2011, + 429, 60, 181, 3475, 3484, 2005, 273, 2064, 2065, 431, + 174, 2011, 280, 2862, 163, 172, 518, 522, 519, 457, + 218, 516, 266, 2005, 519, 520, 392, 2808, 100, 2011, + 522, 227, 291, 522, 313, 522, 788, 313, 305, 203, + 181, 518, 220, 519, 275, 2102, 227, 106, 2142, 2106, + 227, 296, 3524, 282, 2111, 2112, 282, 519, 505, 506, + 507, 334, 509, 510, 511, 512, 513, 514, 820, 470, + 288, 152, 3, 518, 518, 147, 3100, 518, 137, 152, + 2137, 2138, 246, 152, 152, 2142, 37, 3365, 152, 480, + 162, 42, 359, 845, 522, 167, 522, 40, 2941, 275, + 172, 2158, 290, 3, 2161, 2162, 2163, 997, 40, 181, + 290, 59, 172, 11, 186, 40, 167, 384, 181, 519, + 2969, 518, 2179, 2180, 519, 3304, 519, 167, 2162, 2186, + 519, 518, 2189, 3, 39, 518, 403, 3, 516, 516, + 431, 893, 517, 202, 431, 431, 218, 1545, 431, 2206, + 101, 353, 519, 501, 3003, 2189, 519, 522, 2939, 519, + 501, 40, 2219, 519, 528, 2005, 238, 520, 520, 519, + 148, 2011, 2206, 519, 519, 519, 519, 2189, 172, 2236, + 2237, 60, 501, 3499, 518, 431, 518, 155, 518, 2189, + 518, 518, 251, 250, 2206, 477, 2253, 40, 2255, 59, + 522, 507, 261, 503, 454, 291, 2206, 291, 522, 373, + 244, 2268, 59, 59, 273, 287, 266, 469, 290, 431, + 384, 275, 173, 178, 296, 152, 518, 106, 980, 2286, + 2287, 2288, 203, 152, 152, 294, 3085, 518, 990, 431, + 431, 3084, 1640, 40, 519, 355, 305, 519, 203, 518, + 3502, 288, 519, 480, 290, 419, 431, 3215, 209, 431, + 2286, 2287, 2288, 40, 336, 522, 152, 527, 2325, 280, + 2364, 172, 519, 59, 225, 518, 518, 2334, 442, 3128, + 186, 1772, 519, 519, 235, 167, 241, 80, 516, 361, + 143, 1782, 522, 1784, 353, 519, 1787, 176, 357, 519, + 359, 522, 1793, 519, 1795, 1195, 470, 2353, 2353, 2353, + 2353, 2368, 3081, 519, 1204, 199, 2373, 1808, 269, 519, + 172, 518, 1813, 202, 519, 384, 1817, 1818, 1819, 1820, + 389, 1822, 1823, 2579, 2580, 301, 2393, 361, 523, 290, + 295, 291, 2368, 2913, 403, 518, 181, 419, 522, 2189, + 519, 2408, 2409, 518, 152, 522, 519, 519, 1110, 314, + 2417, 176, 518, 442, 315, 519, 2206, 519, 1120, 519, + 518, 322, 251, 520, 518, 447, 519, 522, 518, 1777, + 40, 86, 261, 40, 40, 457, 457, 522, 172, 3238, + 1142, 2417, 518, 3333, 273, 519, 479, 519, 2455, 1151, + 199, 460, 519, 517, 517, 477, 522, 479, 480, 290, + 519, 519, 519, 364, 519, 463, 507, 59, 373, 519, + 519, 2455, 519, 3302, 519, 380, 305, 8, 480, 205, + 11, 3290, 383, 3292, 15, 16, 2493, 117, 19, 20, + 21, 40, 518, 2455, 516, 227, 192, 519, 520, 521, + 88, 280, 2509, 2547, 280, 431, 431, 3300, 520, 2521, + 3305, 519, 3307, 507, 520, 520, 3490, 520, 423, 2526, + 425, 520, 517, 520, 520, 2532, 2533, 3435, 520, 520, + 359, 520, 520, 40, 517, 2590, 275, 442, 520, 520, + 2547, 2585, 520, 448, 520, 520, 451, 520, 520, 520, + 3425, 452, 520, 520, 520, 384, 2563, 520, 520, 2566, + 3444, 2568, 520, 520, 520, 520, 520, 520, 2575, 2576, + 520, 519, 2579, 2580, 403, 107, 519, 2584, 2585, 2775, + 518, 1929, 518, 480, 2591, 290, 419, 518, 9, 3418, + 1046, 354, 2636, 1941, 518, 1435, 1436, 59, 518, 2606, + 522, 1441, 199, 336, 519, 522, 519, 2604, 517, 2616, + 522, 519, 2604, 192, 2604, 2604, 7, 8, 2604, 37, + 522, 2604, 13, 1971, 42, 462, 91, 519, 19, 2636, + 1978, 2604, 23, 347, 25, 518, 40, 2610, 29, 30, + 31, 152, 117, 34, 520, 519, 37, 38, 124, 152, + 41, 40, 519, 44, 45, 519, 172, 369, 369, 518, + 40, 518, 40, 457, 522, 2455, 518, 310, 199, 518, + 2677, 2019, 280, 2680, 2681, 2023, 2683, 1379, 249, 191, + 457, 2029, 442, 101, 75, 76, 178, 74, 2695, 293, + 2697, 222, 518, 74, 80, 74, 9, 172, 519, 80, + 3499, 2677, 519, 518, 2052, 2681, 371, 2683, 2752, 517, + 101, 203, 93, 519, 59, 507, 517, 108, 109, 110, + 111, 112, 93, 133, 2720, 2720, 2720, 2720, 273, 290, + 40, 518, 442, 293, 293, 518, 117, 519, 119, 519, + 462, 3472, 205, 2716, 519, 2941, 290, 290, 519, 241, + 389, 454, 122, 980, 368, 173, 2800, 25, 148, 36, + 2201, 292, 147, 181, 298, 368, 875, 2664, 2775, 1794, + 2281, 2778, 2745, 8, 1230, 3335, 11, 162, 3475, 3429, + 15, 16, 167, 2677, 19, 20, 21, 2614, 2795, 2796, + 3576, 209, 1904, 2800, 2963, 178, 2803, 2396, 852, 315, + 316, 317, 8, 295, 3450, 11, 3554, 225, 3208, 15, + 16, 3503, 3512, 19, 20, 21, 1217, 235, 3547, 3266, + 203, 2274, 2734, 2830, 2287, 3501, 207, 2656, 3510, 304, + 36, 2683, 2271, 218, 3498, 1345, 2391, 1318, 2392, 2352, + 315, 316, 317, 2850, 2417, 3081, 2711, 2253, 1174, 2856, + 2857, 269, 2896, 238, 2861, 2862, 1015, 1015, 241, 2866, + 2219, 40, 2869, 2870, 1762, 1321, 382, 2874, 2875, 1198, + 2474, 2878, 290, 1197, 3484, 2882, 2236, 3397, 1726, 3406, + 3294, 60, 2889, 1761, 23, 2206, 1726, 2017, 3084, 1200, + 2803, 3123, 2455, 1120, 275, 2454, 992, 315, 2882, 280, + 3229, 2501, 287, 419, 322, 2032, 2969, 382, 990, 990, + 990, 296, 295, 990, 1913, 990, 1913, 990, 1913, 990, + 2882, 990, 990, 3410, 1151, 3409, 2933, 106, 107, 2113, + 2533, 423, 2882, 425, 2941, 2162, 452, 2220, 117, 2159, + 2066, 2889, 2383, 2851, 419, 1464, 364, 463, 329, 2115, + 2882, 2559, 3395, 2960, 2604, 1841, 448, 1363, 893, 451, + 2025, 789, 2969, 2853, 199, 383, 347, 1701, 1254, 2615, + 1702, 2324, -1, -1, 505, 506, 507, 452, 509, 510, + 511, 512, 513, 514, -1, -1, -1, 222, 463, -1, + 373, 1693, -1, -1, -1, -1, 3003, 176, -1, -1, + -1, -1, 518, -1, 1231, 480, -1, 1234, 1235, -1, + -1, -1, -1, -1, -1, -1, 222, -1, -1, -1, + -1, -1, -1, 202, -1, 2373, -1, -1, -1, 504, + -1, -1, -1, -1, 452, -1, -1, -1, 3045, 457, + 423, -1, 425, 518, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 3100, 292, -1, 442, + -1, -1, 447, 1765, 1766, 448, 3073, 448, 451, 3045, + -1, -1, 251, -1, 3081, -1, 457, 3084, 3085, -1, + -1, -1, 261, -1, -1, -1, 292, 3060, -1, 1545, + -1, -1, 2882, 3100, 273, -1, 275, -1, -1, -1, + -1, -1, 1942, 1943, 1944, 1945, 1946, 1947, -1, -1, + 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, + -1, 3128, 1824, -1, 172, -1, 305, 3134, -1, -1, + -1, 516, -1, -1, -1, 520, -1, -1, 1840, 1841, + -1, 1368, 1369, -1, 3151, 3152, -1, -1, 3155, 540, + 3157, -1, -1, -1, 545, -1, -1, 548, -1, -1, + -1, 2509, -1, -1, -1, 556, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 3182, -1, -1, -1, -1, + 359, -1, -1, -1, 1640, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 8, -1, -1, 2639, 3206, + -1, 2642, 15, 16, -1, 384, 19, 20, 21, -1, + -1, 1913, -1, -1, -1, -1, -1, 1919, -1, -1, + -1, -1, -1, -1, 403, -1, 405, 2575, 2669, 408, + -1, 3238, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 2684, 2685, 2686, 2687, 2688, 2689, 2690, + 2691, 2692, 2693, 3260, -1, -1, 126, 127, 37, -1, + -1, -1, 41, -1, -1, -1, -1, 315, 316, 317, + 505, 506, 507, 3280, 509, 510, 511, 512, 513, 514, + -1, -1, 3255, 3290, 3260, 3292, -1, 3294, -1, -1, + -1, 3298, -1, 3300, -1, 3302, 3280, 2137, 2138, 505, + 506, 507, 172, 509, 510, 511, 512, 513, 514, 3316, + -1, -1, -1, -1, 3321, -1, 3323, -1, 3280, -1, + -1, 1777, 101, -1, 3331, -1, -1, -1, -1, 108, + -1, 110, 2680, 112, 382, -1, -1, 3344, -1, 518, + -1, -1, 3349, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 746, 747, 748, -1, 3332, + -1, 3334, -1, -1, -1, 1592, -1, -1, 3344, -1, + -1, 419, -1, -1, -1, -1, -1, 1604, -1, 1606, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 3396, + -1, -1, -1, 1046, -1, -1, -1, 788, 789, 3406, + -1, 3374, -1, 794, 452, 796, -1, 1634, -1, -1, + -1, 3418, -1, 2253, 805, 463, -1, 3390, 809, 810, + -1, 812, -1, -1, 815, 816, 3433, -1, -1, -1, + 2778, -1, 480, -1, -1, -1, -1, 828, 829, 830, + -1, -1, 833, -1, 3451, 315, 316, 317, 55, 3433, + 841, 842, 843, 844, -1, 846, 504, 848, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 3475, 860, + 518, 3433, -1, 1929, -1, 866, -1, -1, -1, 292, + -1, -1, -1, 3490, -1, 1941, -1, 878, -1, -1, + 3280, 3475, 3499, -1, 3501, 102, -1, -1, -1, 2940, + -1, 892, 893, -1, -1, -1, -1, -1, -1, -1, + 1737, 1738, 382, 3475, 2862, 1971, 123, 3524, 151, -1, + -1, -1, 1978, 393, -1, 3501, -1, -1, -1, -1, + -1, 3538, 3539, 3540, 141, -1, 927, 928, 145, 172, + 3524, -1, -1, 3516, -1, 415, -1, -1, 939, 419, + -1, -1, 943, 944, 945, 946, -1, -1, 3565, -1, + -1, 168, 3524, 2019, 171, -1, -1, 2023, 959, 3542, + -1, -1, -1, 2029, 1801, -1, -1, 1230, -1, -1, + 187, -1, 452, -1, 1811, -1, -1, 1814, -1, -1, + -1, 2293, -1, 463, -1, -1, 2052, -1, 1046, 3606, + 991, 992, -1, 994, -1, -1, 997, 1046, -1, -1, + 480, -1, 1003, 1004, -1, -1, -1, -1, -1, 1010, + -1, 2969, -1, -1, -1, 1016, -1, 1018, -1, 0, + -1, -1, -1, -1, 504, -1, 1027, -1, -1, -1, + -1, -1, -1, 3433, 2346, -1, 1037, -1, 518, 20, + -1, -1, 23, -1, -1, 3003, -1, -1, -1, -1, + -1, -1, 2364, 1054, -1, 37, 37, -1, 1321, -1, + 42, -1, -1, 280, -1, 46, -1, -1, -1, -1, + -1, 288, 315, 316, 317, 3475, 1913, -1, -1, -1, + -1, -1, 505, 506, 507, -1, 509, 510, 511, 512, + 513, 514, -1, 310, 75, 76, 77, 2409, -1, -1, + -1, -1, -1, -1, 1105, -1, -1, 2419, -1, 2421, + -1, -1, -1, 2425, -1, 2427, -1, -1, -1, 101, + 101, -1, 339, -1, 3524, -1, -1, 3085, -1, 2579, + 2580, -1, -1, -1, -1, -1, -1, -1, -1, 382, + -1, 8, -1, -1, 11, -1, -1, -1, 15, 16, + -1, 540, 19, 20, 21, -1, 545, 1158, -1, 548, + -1, -1, -1, -1, -1, -1, 3217, -1, -1, -1, + 3128, -1, 1230, 1174, 1175, -1, 419, -1, -1, 46, + 1181, 1230, -1, -1, -1, -1, 53, -1, 3239, 3240, + -1, 173, -1, -1, -1, -1, -1, -1, -1, 2036, + -1, -1, -1, 1204, 1205, 1206, -1, -1, -1, 452, + -1, 0, 3263, 80, -1, 1216, 1217, -1, -1, -1, + 463, 37, -1, -1, -1, -1, 42, 209, 1229, -1, + -1, -1, -1, -1, -1, -1, -1, 480, -1, -1, + -1, -1, -1, 225, 1046, 1246, -1, -1, -1, 1250, + 26, -1, -1, 235, 1255, -1, 32, -1, -1, -1, + -1, 504, -1, 1321, 40, -1, -1, -1, -1, -1, + -1, -1, 1321, -1, -1, 518, -1, -1, -1, -1, + 3238, -1, 1545, -1, 60, 101, -1, 269, -1, -1, + -1, -1, -1, -1, -1, 151, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 2373, -1, -1, + 177, 100, -1, 1314, -1, 1316, 172, -1, -1, -1, + -1, -1, -1, -1, 1325, 2775, -1, 194, -1, -1, + 106, 8, 199, 315, 11, 1336, -1, -1, 15, 16, + 322, -1, -1, -1, 1345, -1, -1, -1, -1, 1350, + 2800, 1352, 1353, -1, 1355, 1356, 2193, 173, 147, -1, + -1, 137, -1, -1, -1, -1, -1, -1, 2680, 46, + 237, -1, -1, 162, -1, -1, 53, 1640, 167, -1, + -1, -1, 364, 172, -1, -1, -1, -1, -1, 2226, + 2227, -1, 181, 209, -1, -1, -1, 186, -1, 2711, + 2850, 383, -1, 80, -1, -1, -1, 796, -1, 225, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 235, + -1, -1, -1, -1, -1, 292, 202, -1, 1230, 218, + -1, -1, -1, -1, 1435, 1436, -1, -1, -1, -1, + 1441, -1, 1443, 2509, 3495, -1, -1, -1, -1, 238, + -1, -1, -1, 269, -1, 1456, -1, 1458, 1459, 315, + 316, 317, 1463, 1464, -1, 1466, -1, -1, 145, -1, + 452, 1472, -1, 1474, 290, 251, 1477, -1, -1, -1, + -1, 1482, -1, 1484, 1485, 261, 1487, 1545, -1, -1, + 1491, 2941, 1493, -1, 1495, -1, 1545, 273, 287, 315, + 177, 290, -1, 892, -1, -1, 322, 296, -1, 2575, + -1, -1, -1, -1, 1777, -1, -1, 194, 294, 1321, + -1, -1, 199, -1, -1, -1, 382, 394, -1, 305, + -1, -1, -1, -1, -1, -1, -1, -1, 927, -1, + -1, 3499, -1, -1, -1, -1, -1, 336, 364, -1, + -1, -1, -1, -1, 943, 944, 945, 946, 539, -1, + 237, -1, -1, 419, -1, -1, -1, 383, -1, -1, + -1, -1, 361, -1, 2886, -1, -1, 353, -1, -1, + -1, 357, 1640, 359, -1, -1, -1, 13, -1, -1, + -1, 1640, -1, 19, -1, -1, 452, 23, -1, 1600, + -1, -1, -1, -1, 30, 994, -1, 463, 384, -1, + -1, 1612, -1, 389, 2680, 292, -1, -1, 44, 45, + -1, -1, -1, -1, 480, -1, -1, 403, -1, -1, + 419, -1, -1, -1, 3084, 502, 452, -1, 505, 506, + 507, 457, 509, 510, 511, 512, 513, 514, 504, 75, + 76, 1652, -1, -1, 1655, -1, -1, -1, 447, -1, + -1, -1, 518, -1, -1, -1, 1929, -1, 457, -1, + -1, -1, -1, -1, -1, -1, 2513, 2514, 1941, -1, + -1, -1, 1683, 109, 460, -1, -1, -1, 477, -1, + 479, 480, -1, -1, -1, -1, -1, 1698, -1, 1700, + -1, 1702, -1, -1, -1, -1, -1, -1, 1971, -1, + -1, 1712, 2778, 1714, -1, 1978, -1, 394, -1, 1777, + -1, -1, -1, -1, -1, 1726, -1, 516, 1777, -1, + 519, 520, 521, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 3054, 1545, -1, -1, -1, -1, 40, -1, + 1751, -1, 1753, -1, -1, -1, 2019, -1, -1, -1, + 2023, -1, -1, -1, 1765, 1766, 2029, -1, 60, 3081, + 1771, 1772, 753, 754, -1, -1, -1, -1, -1, -1, + -1, 1782, 1783, 1784, 1785, -1, 1787, -1, -1, 2052, + -1, -1, 1793, -1, 1795, -1, 2862, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 1807, 1808, -1, -1, + -1, 1812, 1813, 794, 106, -1, 1817, 1818, 1819, 1820, + -1, 1822, 1823, -1, 805, 502, -1, 1216, -1, -1, + -1, 812, 509, 510, 511, 512, 513, 514, 1640, -1, + 1229, 1842, -1, 2680, -1, -1, -1, -1, -1, 1850, + 3300, 1852, 1853, 1854, 1855, 1856, 3168, -1, -1, -1, + -1, 1250, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 1929, 1873, -1, -1, -1, 857, -1, -1, -1, + 1929, -1, -1, 1941, -1, -1, -1, -1, -1, -1, + -1, 1892, 1941, -1, 875, -1, -1, -1, -1, -1, + -1, -1, -1, 2969, -1, -1, -1, -1, -1, -1, + 202, -1, -1, 1971, -1, -1, -1, -1, -1, -1, + 1978, -1, 1971, -1, -1, -1, 3238, 1316, -1, 1978, + -1, -1, -1, -1, -1, -1, 1325, 3003, -1, -1, + -1, 1942, 1943, 1944, 1945, 1946, 1947, -1, -1, 1950, + 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 251, + -1, 2019, -1, -1, -1, 2023, -1, -1, -1, 261, + 2019, 2029, -1, -1, 2023, 1777, 2813, 98, -1, 1980, + 2029, 273, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 1994, 2052, -1, -1, -1, -1, -1, + -1, -1, 983, 2052, 2005, 126, 127, -1, -1, -1, + 2011, -1, -1, 305, -1, -1, 2017, -1, -1, 3085, + -1, 2022, -1, -1, -1, -1, -1, -1, -1, -1, + 2031, 2032, -1, -1, -1, 1016, -1, 1018, -1, -1, + -1, -1, -1, -1, -1, -1, 1027, -1, -1, -1, + -1, 172, -1, 8, 3366, -1, 11, -1, -1, 172, + 15, 16, 3128, -1, -1, -1, -1, 359, -1, -1, + -1, 8, -1, -1, 11, -1, -1, 1466, 15, 16, + -1, 1062, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 46, 384, 1074, -1, -1, -1, -1, 53, -1, + -1, -1, 2103, -1, -1, -1, -1, 2108, -1, 46, + 2373, 403, 2113, -1, -1, -1, 53, -1, -1, -1, + 1101, 2958, -1, 0, -1, 80, 2963, 1929, -1, -1, + 556, -1, -1, -1, -1, -1, 2137, 2138, -1, 1941, + -1, -1, -1, 80, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 2156, -1, -1, -1, -1, + -1, 2162, -1, -1, -1, -1, -1, -1, -1, 1971, + -1, -1, 3238, 3010, 3011, -1, 1978, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 3499, 2189, -1, + 145, 304, -1, -1, 315, 316, 317, -1, -1, -1, + 2201, -1, 315, 316, 317, 2206, -1, 1188, 1189, 2210, + 1191, -1, -1, -1, -1, -1, -1, 2019, -1, -1, + -1, 2023, 177, 100, -1, -1, -1, 2029, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 194, + 177, -1, -1, -1, 199, -1, 2509, -1, -1, 2250, + 2052, -1, 2253, -1, 2255, 2256, -1, 194, -1, -1, + -1, 382, 199, -1, -1, -1, -1, -1, -1, 382, + 147, -1, 393, -1, -1, 2276, -1, -1, -1, -1, + -1, -1, 237, -1, -1, 162, -1, -1, -1, -1, + 167, -1, -1, -1, 415, 172, -1, -1, 419, -1, + 237, -1, -1, -1, 181, -1, 419, -1, -1, 186, + -1, 1700, 2575, 1702, -1, 2373, -1, -1, 439, -1, + -1, 747, 748, 1712, 2373, -1, -1, -1, -1, -1, + -1, 452, -1, -1, -1, -1, -1, 292, -1, 452, + -1, 218, 463, -1, -1, -1, -1, 2348, -1, -1, + 463, -1, -1, -1, 2355, 292, -1, -1, -1, 480, + -1, 238, 1751, -1, -1, 2366, -1, 480, 2369, 2370, + 2371, 2372, -1, -1, -1, -1, -1, -1, -1, 805, + -1, 1362, 2383, 504, 2385, -1, -1, 2388, 3225, 3226, + -1, 504, -1, -1, 2395, -1, -1, 518, -1, -1, + 2401, 3238, -1, -1, -1, 518, -1, -1, -1, -1, + 287, -1, -1, 290, -1, -1, -1, 2680, -1, 296, + -1, -1, 2423, 2424, -1, 2426, -1, -1, -1, -1, + -1, -1, -1, 3499, -1, -1, -1, -1, -1, 394, + 866, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 2509, -1, -1, 2455, -1, -1, 394, -1, 336, + 2509, -1, -1, 1852, 1853, 1854, 1855, 1856, -1, -1, + -1, -1, 2473, -1, -1, -1, -1, -1, -1, -1, + 2481, 2482, 2483, -1, 361, -1, -1, -1, -1, -1, + 2491, 1472, 2493, 1474, 2495, -1, 1477, -1, -1, -1, + 2501, 1482, -1, -1, 1485, -1, 1487, -1, -1, -1, + 1491, -1, -1, -1, -1, 2778, 8, 2575, -1, 11, + 2521, -1, -1, 15, 16, -1, 2575, 19, 20, 21, + -1, -1, -1, -1, 2535, -1, -1, -1, -1, -1, + -1, -1, 419, -1, 36, 2546, -1, 502, -1, 2550, + -1, -1, -1, -1, 509, 510, 511, 512, 513, 514, + -1, -1, -1, -1, -1, 502, -1, -1, -1, -1, + 447, 2373, 509, 510, 511, 512, 513, 514, 2579, 2580, + 457, -1, -1, -1, 1010, -1, -1, -1, -1, -1, + 1016, -1, 1018, 1574, -1, -1, -1, -1, -1, 2862, + 477, 1027, 479, 480, -1, 1994, -1, 2608, -1, -1, + -1, 1037, -1, 2614, -1, -1, -1, -1, -1, -1, + -1, -1, 2680, -1, -1, -1, -1, -1, -1, 2630, + -1, 2680, -1, 2634, -1, 2636, -1, 2638, 2639, 516, + -1, 2642, 519, 520, 521, 2646, 2647, 2648, 8, 2650, + -1, 11, -1, -1, -1, 15, 16, -1, -1, 19, + 20, 21, 3499, -1, -1, -1, -1, -1, 2669, -1, + 2671, -1, -1, -1, 1655, -1, 36, -1, -1, 1105, + -1, -1, -1, 2684, 2685, 2686, 2687, 2688, 2689, 2690, + 2691, 2692, 2693, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 2969, 2509, -1, -1, + -1, -1, -1, -1, 2715, -1, -1, -1, -1, -1, + 2778, 2722, -1, -1, -1, -1, -1, -1, -1, 2778, + 222, -1, -1, 2734, -1, -1, -1, -1, -1, -1, + 3003, -1, 1723, -1, -1, -1, -1, 8, 1174, 1175, + 11, -1, -1, 2754, 15, 16, -1, -1, 19, 20, + 21, -1, -1, 2764, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 2575, 2775, 36, -1, -1, -1, -1, + 2781, -1, -1, -1, -1, -1, -1, 2788, 2789, 2790, + 2791, -1, -1, -1, -1, -1, -1, -1, -1, 2800, + 292, -1, 2803, -1, 2862, -1, 2807, 2808, -1, -1, + -1, -1, -1, 2862, -1, 2816, -1, -1, 8, -1, + -1, 11, 3085, -1, -1, 15, 16, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 2839, -1, + -1, -1, -1, -1, -1, 2846, 2847, -1, -1, -1, + 2851, -1, -1, -1, -1, -1, 46, -1, -1, -1, + -1, -1, 222, 53, -1, 3128, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 2680, 2880, + -1, 2882, 1863, -1, -1, -1, -1, -1, 2889, -1, + 80, -1, -1, -1, 1875, 2896, -1, -1, -1, 2900, + -1, -1, -1, -1, -1, 2906, -1, -1, -1, -1, + -1, 2969, -1, -1, -1, -1, -1, -1, -1, 2920, + 2969, -1, -1, -1, -1, 2926, 1352, 1353, -1, 1355, + -1, -1, 292, -1, -1, -1, -1, -1, 2939, 2940, + 2941, -1, -1, -1, -1, 3003, 2947, -1, -1, -1, + -1, -1, -1, -1, 3003, 145, -1, -1, -1, -1, + -1, 222, -1, 2964, -1, -1, 2355, -1, -1, -1, + -1, -1, -1, -1, -1, 3238, 2778, -1, -1, -1, + -1, 2370, 2371, 2372, -1, -1, -1, 177, -1, -1, + -1, -1, -1, -1, -1, -1, 2385, -1, -1, 2388, + -1, -1, -1, -1, 194, -1, 2395, -1, -1, 199, + -1, -1, -1, 505, 506, 507, -1, 509, 510, 511, + 512, 513, 514, -1, 2005, -1, -1, 3085, -1, -1, + 2011, 292, 1458, -1, -1, -1, 3085, -1, -1, -1, + -1, 3042, -1, -1, -1, 3046, 1472, 237, 1474, -1, + -1, 1477, -1, -1, -1, -1, 1482, -1, 3059, 1485, + 2862, 1487, -1, -1, -1, 1491, -1, 1493, -1, 1495, + 3128, -1, -1, -1, -1, -1, 3077, -1, -1, 3128, + -1, -1, -1, 3084, -1, -1, -1, -1, -1, -1, + -1, -1, 2481, 2482, 2483, -1, -1, -1, -1, -1, + -1, -1, 292, -1, -1, -1, -1, -1, -1, 3110, + -1, -1, -1, -1, -1, 3116, -1, -1, -1, -1, + -1, -1, 3123, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 3140, + -1, -1, -1, -1, -1, 505, 506, 507, -1, 509, + 510, 511, 512, 513, 514, -1, -1, -1, -1, -1, + -1, 2142, -1, 3164, -1, -1, -1, 2969, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 3571, -1, -1, -1, -1, -1, 145, -1, -1, -1, + 3238, 2162, -1, -1, -1, 3186, 1612, -1, -1, 3238, + 3191, -1, -1, -1, -1, -1, -1, 2178, -1, -1, + -1, 3003, -1, -1, 394, -1, -1, -1, 2189, -1, + -1, 8, -1, -1, 11, -1, 3217, -1, 15, 16, + -1, -1, 19, 20, 21, 2206, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 3499, -1, 3239, 3240, + -1, 2630, -1, -1, 505, 506, 507, -1, 509, 510, + 511, 512, 513, 514, -1, 3256, -1, 3258, -1, -1, + -1, -1, 3263, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 3277, -1, -1, 3280, + -1, -1, -1, 3085, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 3300, + -1, 3302, -1, 3304, 3305, -1, 3307, -1, -1, -1, + -1, 3312, 502, -1, -1, -1, -1, -1, -1, 509, + 510, 511, 512, 513, 514, -1, 3128, 1753, -1, -1, + 3331, -1, -1, 2722, 3335, -1, -1, -1, -1, -1, + 8, 3342, -1, 11, -1, -1, 1772, 15, 16, -1, + -1, -1, -1, -1, -1, -1, 1782, -1, 1784, -1, + -1, 1787, -1, -1, -1, -1, -1, 1793, -1, 1795, + -1, 3372, -1, -1, -1, -1, -1, -1, 46, -1, + -1, -1, 1808, 2364, -1, 53, -1, 1813, -1, -1, + -1, 1817, 1818, 1819, 1820, -1, 1822, 1823, -1, 2788, + 2789, 2790, 2791, -1, -1, -1, -1, -1, -1, 3410, + -1, -1, 80, -1, -1, -1, -1, 3418, -1, -1, + -1, -1, -1, -1, -1, 222, -1, -1, -1, -1, + -1, -1, 3433, -1, -1, -1, 3238, -1, -1, -1, + -1, 3499, -1, -1, 0, -1, -1, -1, -1, -1, + 3499, -1, -1, -1, -1, -1, -1, -1, -1, 3460, + -1, -1, -1, -1, -1, -1, 22, -1, -1, -1, + -1, 3472, 3473, -1, 3475, 3476, 32, 145, 34, 35, + -1, -1, -1, 3484, -1, -1, 841, 842, -1, -1, + -1, 47, -1, -1, 3495, 292, 52, -1, -1, -1, + -1, -1, -1, -1, -1, 61, -1, -1, -1, 177, + -1, -1, -1, -1, -1, -1, 3517, -1, -1, 75, + -1, -1, -1, 3524, -1, -1, 194, -1, 84, -1, + 86, 199, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 98, -1, 100, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 1980, 111, -1, 912, 2947, -1, + 3561, 916, 917, -1, -1, -1, 2547, -1, -1, 237, + 126, 127, 128, -1, -1, 3576, -1, -1, -1, 2005, + -1, 137, -1, -1, -1, 2011, -1, 143, -1, -1, + -1, 2017, -1, -1, -1, 151, 2022, 153, 154, -1, + -1, -1, -1, -1, 2585, -1, -1, -1, -1, -1, + -1, -1, 168, -1, 969, -1, 172, -1, -1, -1, + -1, -1, -1, 2604, 292, -1, -1, -1, -1, 2610, + -1, -1, 987, -1, -1, -1, -1, -1, 993, -1, + -1, 996, 198, -1, 999, 1000, 1001, 1002, -1, -1, + -1, -1, -1, -1, -1, 2636, -1, -1, 214, -1, + -1, -1, 8, -1, -1, 11, -1, -1, -1, 15, + 16, -1, -1, 19, 20, 21, -1, 2103, -1, -1, + -1, -1, -1, -1, 240, -1, -1, 2113, -1, 1044, + 1045, -1, -1, -1, -1, -1, -1, 3499, -1, -1, + 46, -1, -1, -1, -1, -1, -1, 53, 505, 506, + 507, 1066, 509, 510, 511, 512, 513, 514, -1, -1, + 8, -1, -1, 11, -1, -1, 394, 15, 16, -1, + 1085, 19, 20, 21, 80, 2716, -1, -1, -1, -1, + -1, 1096, 1097, 1098, -1, 1100, 1101, -1, 36, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 46, 315, + 316, 317, -1, 2189, 2745, 53, -1, 323, -1, -1, + 326, 2752, -1, -1, -1, 2201, -1, -1, -1, -1, + 2206, 1136, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 80, -1, -1, -1, -1, -1, -1, 1154, + 1155, 357, -1, -1, -1, -1, 3, -1, 5, -1, + 366, -1, -1, -1, -1, -1, -1, -1, -1, 2800, + -1, -1, -1, -1, 2250, -1, 382, -1, -1, -1, + 2256, 177, -1, 389, 502, 1190, -1, 393, -1, 1194, + 1195, 509, 510, 511, 512, 513, 514, 403, 194, -1, + 1205, 1206, -1, 199, -1, -1, -1, -1, -1, 415, + -1, -1, -1, 419, -1, -1, -1, 3256, -1, -1, + -1, 68, 69, -1, -1, -1, 222, 223, -1, -1, + -1, -1, -1, 439, -1, -1, -1, -1, 3277, 177, + -1, 237, -1, -1, -1, -1, 452, -1, -1, 455, + -1, 2882, 458, -1, -1, -1, 194, 463, -1, -1, + 1265, 199, 109, 110, -1, 2896, 113, 114, -1, 1274, + -1, -1, -1, -1, 480, -1, -1, -1, -1, 275, + -1, -1, 278, -1, 222, 223, -1, -1, -1, -1, + -1, -1, -1, 1298, -1, -1, 292, -1, 504, 237, + -1, -1, -1, 3342, -1, -1, -1, 2383, -1, -1, + -1, -1, 518, 8, -1, 521, 11, -1, -1, -1, + 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, + -1, -1, -1, 3372, -1, -1, -1, 275, -1, -1, + 278, 36, 189, 190, -1, -1, -1, -1, -1, -1, + -1, 46, -1, -1, 292, -1, -1, 295, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 337, 2828, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 177, -1, - -1, -1, -1, -1, -1, -1, -1, 362, 1458, -1, - 1460, 1461, 2831, -1, -1, 194, -1, -1, -1, 3025, - 199, -1, -1, 1473, 1474, -1, -1, -1, 2768, -1, - -1, -1, -1, -1, -1, -1, -1, 2162, 2163, -1, - 2859, -1, -1, -1, -1, 1495, -1, -1, -1, -1, - -1, -1, -1, -1, 3060, -1, -1, -1, 237, -1, - -1, -1, -1, -1, -1, -1, 421, -1, -1, 2914, - -1, -1, 2891, -1, -1, -1, -1, -1, -1, -1, - 2899, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 449, -1, -1, -1, 2838, 2839, - 2840, 2841, -1, -1, -1, 460, -1, -1, -1, -1, - -1, -1, -1, 292, -1, 2934, -1, -1, -1, -1, - 3126, -1, -1, -1, -1, 480, -1, 482, 483, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 2618, - 2619, -1, -1, 3149, -1, -1, -1, -1, -1, 1599, - -1, -1, 2277, -1, -1, -1, -1, 1607, -1, -1, - -1, -1, -1, -1, 519, -1, -1, 522, 523, 524, - -1, 1621, -1, -1, -1, -1, -1, 2996, -1, -1, - 3025, -1, -1, -1, -1, -1, -1, 3193, -1, -1, - -1, -1, 1642, -1, -1, -1, -1, -1, -1, 1649, - -1, -1, -1, -1, -1, 1655, 1656, 1657, 1658, 1659, - 1660, 1661, 1662, -1, -1, 3060, 395, 1667, 1668, -1, - -1, -1, 1672, -1, -1, -1, 1676, -1, -1, 1679, - 1680, 1681, 1682, 1683, 1684, 1685, 1686, 1687, -1, -1, - 1690, -1, -1, -1, -1, -1, -1, 1697, -1, 1699, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 3003, -1, -1, -1, 1717, -1, -1, - -1, -1, 8, -1, -1, 11, -1, -1, -1, 15, - 16, 3126, -1, 19, 20, 21, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 3305, - 36, -1, 1752, 1753, 3149, -1, -1, -1, -1, -1, - 46, -1, 8, -1, -1, 11, -1, 53, -1, 15, - 16, -1, -1, 19, 20, 21, 505, -1, -1, -1, - -1, -1, -1, 512, 513, 514, 515, 516, 517, -1, - -1, -1, -1, -1, 80, -1, 2825, -1, 3193, -1, - 46, -1, -1, -1, -1, -1, -1, 53, -1, -1, - -1, -1, 3181, -1, -1, -1, -1, -1, -1, 3188, - -1, -1, -1, 2852, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 80, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 1003, -1, -1, 1849, - -1, -1, -1, -1, -1, -1, 1856, -1, -1, 1859, - 1860, -1, -1, -1, -1, -1, -1, -1, -1, 8, - -1, -1, 11, 2902, -1, -1, 15, 16, -1, -1, - 19, 20, 21, -1, 3253, -1, -1, -1, -1, 3258, - -1, 177, -1, -1, -1, -1, -1, -1, -1, -1, - 1900, -1, -1, -1, -1, -1, -1, 46, 194, -1, - 3305, -1, -1, 199, 53, 3284, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 1925, 1926, 8, -1, -1, - 11, 177, -1, -1, 15, 16, 222, 223, -1, 3308, - 3309, 80, -1, 2618, 2619, -1, -1, -1, 194, -1, - -1, 237, -1, 199, 1954, 1955, -1, 1957, -1, -1, - -1, -1, -1, -1, 3333, 46, -1, -1, 2997, -1, - -1, 1128, 53, -1, -1, -1, 222, 223, -1, -1, - -1, -1, -1, -1, -1, -1, 1986, 1987, -1, 275, - 1990, 237, 278, -1, -1, -1, -1, -1, -1, 80, - -1, -1, -1, -1, -1, 3374, 292, -1, -1, -1, - -1, -1, -1, 3382, -1, 3571, -1, -1, -1, -1, - 1177, 2021, -1, -1, -1, -1, -1, -1, -1, 275, - 2030, -1, 278, -1, -1, 3325, -1, -1, 177, -1, - -1, -1, -1, -1, -1, -1, 292, -1, -1, 2049, - -1, 2051, -1, -1, 1211, 194, -1, 3347, -1, -1, - 199, -1, -1, -1, 145, -1, -1, -1, -1, -1, + 1385, -1, -1, -1, -1, 80, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 394, -1, + -1, -1, -1, -1, -1, -1, 253, 254, 255, 256, + 257, 258, 259, 260, -1, 2491, 263, 264, -1, 2495, + -1, -1, -1, -1, -1, 2501, -1, -1, -1, 3060, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 222, 223, -1, -1, -1, -1, 2089, - -1, -1, -1, -1, -1, -1, 177, -1, 237, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 395, - 1267, -1, -1, 194, -1, -1, -1, -1, 199, 3148, - -1, -1, -1, -1, 3414, -1, -1, 2127, -1, -1, - -1, 2131, -1, -1, -1, 8, 2136, 2137, 11, 278, - -1, -1, 15, 16, 17, 18, 19, 20, 21, 395, - 2825, -1, -1, 292, 3444, 1312, 237, -1, -1, -1, - -1, -1, 1319, 36, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 46, -1, -1, 3571, 2852, -1, -1, - 53, -1, -1, 2183, -1, -1, 2186, -1, 2188, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 3567, -1, - -1, -1, -1, -1, 2204, -1, -1, 80, -1, -1, - -1, 292, 1369, -1, -1, -1, -1, -1, -1, 505, - -1, -1, 508, 509, 510, -1, 512, 513, 514, 515, - 516, 517, -1, -1, -1, -1, 1393, -1, -1, -1, - -1, -1, -1, 2243, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 395, -1, -1, 505, - 2260, 2261, 508, 509, 510, -1, 512, 513, 514, 515, - 516, 517, -1, -1, -1, -1, -1, -1, -1, 2279, - -1, -1, -1, -1, 1441, -1, 1443, -1, 1445, 1446, - -1, 1448, 2292, -1, 1451, -1, -1, 1454, -1, -1, - 1457, -1, -1, -1, 177, 1462, -1, -1, 1465, -1, - -1, -1, -1, -1, 395, -1, -1, -1, -1, -1, - -1, 194, 2997, -1, -1, -1, 199, -1, -1, -1, + -1, -1, -1, 1448, -1, 1450, 1451, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 394, -1, 1463, 1464, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 3100, + 2546, -1, -1, -1, 2550, -1, -1, -1, -1, 1484, + -1, -1, 177, -1, -1, -1, -1, -1, -1, -1, + 337, 338, -1, -1, -1, -1, -1, -1, -1, 194, + -1, -1, -1, -1, 199, -1, 502, -1, -1, 505, + 506, 507, -1, 509, 510, 511, 512, 513, 514, -1, + -1, -1, -1, -1, -1, -1, -1, 222, 223, -1, + -1, 378, 379, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 237, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 2634, -1, + -1, -1, 2638, 2639, 502, -1, 2642, 505, 506, 507, + -1, 509, 510, 511, 512, 513, 514, -1, -1, -1, + 275, 1586, -1, 278, 8, -1, -1, 11, -1, 1594, + -1, 15, 16, 2669, -1, -1, -1, 292, -1, -1, + 295, -1, -1, -1, -1, -1, -1, -1, 2684, 2685, + 2686, 2687, 2688, 2689, 2690, 2691, 2692, 2693, -1, -1, + -1, -1, 46, 1628, 3255, -1, -1, 474, 475, 53, + 1635, -1, -1, -1, -1, -1, 1641, 1642, 1643, 1644, + 1645, 1646, 1647, 1648, -1, 3276, -1, -1, 1653, 1654, + -1, 498, 499, 1658, -1, -1, 80, 1662, -1, -1, + 1665, 1666, 1667, 1668, 1669, 1670, 1671, 1672, 1673, -1, + -1, 1676, -1, -1, -1, -1, -1, -1, 1683, 8, + 1685, -1, 11, -1, -1, -1, 15, 16, 17, 18, + 19, 20, 21, -1, -1, -1, -1, -1, 1703, 394, + -1, 3332, -1, 3334, -1, 2781, -1, 36, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 46, -1, -1, + -1, 145, -1, -1, 53, -1, -1, -1, -1, -1, + -1, 2807, 1737, 1738, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 3374, -1, -1, -1, -1, -1, -1, + -1, 80, -1, 177, 8, -1, -1, 11, -1, 3390, + -1, 15, 16, 2839, -1, 19, 20, 21, -1, -1, + 194, 2847, -1, -1, -1, 199, -1, -1, -1, -1, + -1, -1, 36, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 46, -1, -1, -1, -1, -1, -1, 53, + -1, -1, -1, -1, -1, -1, 2882, 502, -1, -1, + 505, 506, 507, 237, 509, 510, 511, 512, 513, 514, + -1, -1, -1, 1828, -1, -1, 80, -1, 523, -1, + 1835, -1, -1, 1838, 1839, -1, -1, -1, -1, 3, + -1, -1, -1, -1, 8, -1, -1, 11, 177, -1, + -1, 15, 16, 17, 18, 19, 20, 21, -1, -1, + -1, -1, -1, -1, 2940, 194, -1, -1, 292, -1, + 199, -1, 36, -1, 1879, -1, 40, -1, -1, -1, + -1, -1, 46, -1, -1, 3516, -1, -1, -1, 53, + -1, -1, -1, 222, 223, -1, -1, -1, -1, 1904, + 1905, -1, -1, -1, -1, -1, -1, -1, 237, -1, + -1, 3542, -1, -1, -1, -1, 80, -1, -1, -1, + -1, -1, -1, 177, -1, -1, -1, -1, 1933, 1934, + -1, 1936, 997, -1, -1, -1, -1, -1, -1, -1, + 194, -1, -1, -1, -1, 199, 275, -1, -1, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 3370, -1, -1, -1, -1, -1, -1, -1, 222, - 223, -1, 1509, -1, -1, -1, -1, -1, -1, 2359, - -1, -1, -1, -1, 237, -1, 505, -1, 2368, 508, - 509, 510, -1, 512, 513, 514, 515, 516, 517, -1, + 1965, 1966, -1, 292, 1969, -1, 295, -1, 222, 223, + 394, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 237, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 2000, -1, -1, -1, -1, + -1, -1, 2007, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 177, -1, -1, -1, -1, -1, -1, + 2025, 275, 2027, -1, 278, -1, -1, -1, -1, -1, + 194, -1, -1, -1, -1, 199, -1, -1, 292, -1, + 3116, -1, -1, -1, -1, -1, -1, 3123, -1, -1, + -1, -1, -1, -1, -1, -1, 1121, -1, 222, 223, + 2065, -1, -1, -1, -1, 394, -1, -1, -1, -1, + -1, -1, -1, 237, -1, -1, -1, -1, 502, -1, + -1, -1, -1, -1, -1, 509, 510, 511, 512, 513, + 514, -1, -1, -1, -1, -1, -1, 2102, -1, -1, + -1, 2106, -1, -1, -1, 1170, 2111, 2112, -1, -1, + 3186, 275, -1, -1, 278, 3191, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 292, -1, + -1, 295, -1, -1, -1, -1, -1, -1, -1, 1204, + 394, 3217, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 2158, -1, -1, 2161, -1, 2163, -1, + -1, -1, -1, 3239, 3240, -1, -1, -1, -1, -1, + -1, -1, -1, 502, 2179, -1, 505, 506, 507, -1, + 509, 510, 511, 512, 513, 514, -1, 3263, -1, -1, + -1, -1, -1, 522, 1259, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 2219, -1, 8, -1, -1, 11, + -1, -1, -1, 15, 16, -1, -1, -1, 3304, -1, + 394, 2236, 2237, -1, -1, -1, 3312, 1302, -1, -1, + -1, -1, -1, -1, 1309, -1, -1, -1, 502, -1, + 2255, 505, 506, 507, 46, 509, 510, 511, 512, 513, + 514, 53, -1, 2268, -1, 8, -1, -1, 11, -1, + -1, -1, 15, 16, 17, 18, 19, 20, 21, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 80, -1, + -1, -1, -1, 36, 1359, -1, -1, 40, -1, -1, + -1, -1, -1, 46, -1, -1, -1, -1, -1, -1, + 53, -1, -1, -1, -1, -1, -1, -1, 1383, -1, + 2325, -1, -1, -1, -1, -1, -1, -1, -1, 2334, + -1, -1, -1, -1, -1, -1, -1, 80, 502, -1, + -1, 505, 506, 507, -1, 509, 510, 511, 512, 513, + 514, -1, -1, 145, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 1431, -1, 1433, -1, + 1435, 1436, -1, 1438, -1, -1, 1441, -1, -1, 1444, + -1, -1, 1447, -1, -1, 177, -1, 1452, 2393, -1, + 1455, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 194, -1, -1, -1, -1, 199, -1, -1, + -1, -1, -1, -1, 8, -1, -1, 11, -1, 3495, + -1, 15, 16, 17, 18, 19, 20, 21, -1, -1, + -1, -1, -1, 1498, 177, -1, -1, -1, -1, -1, + -1, -1, 36, -1, -1, 237, -1, -1, -1, -1, + -1, 194, 46, -1, -1, -1, 199, -1, -1, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 275, -1, -1, 278, -1, -1, 0, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, - -1, -1, 295, -1, 505, -1, -1, 2427, -1, -1, - 22, 512, 513, 514, 515, 516, 517, -1, 1595, -1, - 32, -1, 34, 35, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 1611, 47, -1, -1, -1, -1, - 52, -1, -1, -1, -1, 1622, 1623, 1624, -1, 61, - -1, -1, 1629, 3148, -1, -1, 1633, -1, -1, -1, - -1, -1, -1, 75, -1, -1, -1, -1, -1, -1, - -1, -1, 84, -1, 86, -1, -1, -1, -1, -1, - -1, -1, 3, -1, 5, -1, 98, -1, 100, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 111, - -1, -1, 395, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 126, 127, 128, -1, -1, 1696, - -1, -1, -1, -1, -1, 137, -1, -1, -1, -1, - -1, 143, -1, -1, -1, -1, -1, -1, -1, 151, - -1, 153, 154, -1, 2564, -1, -1, 68, 69, -1, - 2570, 2571, -1, -1, -1, -1, 168, -1, 1735, -1, - 172, -1, -1, -1, -1, -1, 2586, -1, -1, -1, - -1, -1, -1, -1, 1751, -1, -1, -1, -1, 1756, - -1, -1, 2602, -1, -1, 2605, 198, 2607, 109, 110, - -1, -1, 113, 114, -1, 2615, 1773, -1, -1, -1, - -1, -1, 214, 2623, 2624, -1, -1, -1, -1, -1, - 2630, -1, 505, -1, -1, 508, 509, 510, -1, 512, - 513, 514, 515, 516, 517, -1, -1, 2647, 240, -1, - -1, -1, -1, 526, -1, -1, -1, 2657, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 222, + 223, -1, -1, -1, -1, -1, 80, -1, -1, -1, + -1, -1, -1, -1, 237, -1, -1, -1, -1, -1, + 292, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 1582, -1, -1, + -1, 2526, -1, -1, -1, -1, -1, 2532, 2533, -1, + -1, -1, 275, 1598, -1, 278, -1, -1, -1, -1, + -1, -1, 2547, 1608, 1609, 1610, -1, -1, -1, 292, + 1615, -1, 295, -1, 1619, -1, -1, -1, 2563, -1, + -1, 2566, -1, 2568, -1, -1, -1, -1, -1, -1, + -1, 2576, -1, -1, -1, -1, -1, -1, -1, 2584, + 2585, -1, -1, 177, -1, -1, 2591, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 2677, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 189, 190, - -1, -1, -1, -1, -1, 3370, -1, -1, -1, -1, + 194, 2606, 394, -1, -1, 199, -1, -1, -1, -1, + -1, 2616, -1, -1, -1, -1, -1, 1682, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 222, 223, + -1, 2636, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 237, -1, -1, -1, -1, -1, -1, + -1, 394, -1, -1, -1, 1720, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 1736, -1, -1, -1, -1, 1741, -1, -1, -1, + -1, 275, -1, -1, 278, -1, -1, -1, -1, -1, + 2695, -1, 2697, 1758, -1, -1, -1, -1, 292, -1, + -1, 295, -1, -1, -1, -1, -1, -1, -1, -1, + 502, -1, -1, -1, -1, -1, -1, 509, 510, 511, + 512, 513, 514, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 316, 317, 318, -1, 2728, -1, - -1, -1, 324, -1, -1, 327, -1, -1, -1, -1, - -1, 2741, -1, 2743, -1, -1, -1, -1, -1, -1, - -1, -1, 253, 254, 255, 256, 257, 258, 259, 260, - -1, -1, 263, 264, -1, -1, 358, -1, -1, -1, - -1, -1, -1, 2773, -1, 367, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 383, -1, -1, -1, 1952, -1, -1, 390, -1, - -1, -1, 394, 1960, 1961, -1, 1963, 1964, 1965, 1966, - 1967, 1968, -1, 405, 1971, 1972, 1973, 1974, 1975, 1976, - 1977, 1978, 1979, 1980, 1981, 417, -1, -1, -1, 421, - -1, -1, -1, -1, -1, -1, -1, 338, 339, -1, - -1, -1, -1, -1, -1, 2845, 2846, -1, 2848, 441, - -1, -1, -1, -1, -1, -1, -1, -1, 68, 69, - -1, -1, -1, 455, -1, -1, 458, -1, -1, 461, - -1, -1, -1, -1, 466, -1, -1, -1, 379, 380, - -1, -1, 2882, -1, -1, -1, -1, -1, -1, -1, - -1, 483, -1, -1, -1, -1, -1, -1, -1, 109, - 110, -1, 2902, 113, 114, -1, -1, -1, 2908, 2909, - -1, -1, -1, 2913, -1, 507, -1, -1, 2918, -1, - -1, 2921, 2922, -1, -1, -1, 2926, 2927, -1, 521, - 2930, -1, 524, -1, -1, 2092, -1, -1, 2095, -1, - -1, -1, -1, -1, -1, 2945, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 502, + -1, -1, 505, 506, 507, -1, 509, 510, 511, 512, + 513, 514, -1, -1, -1, -1, 519, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 2126, - -1, -1, -1, -1, -1, -1, 477, 478, -1, 189, - 190, -1, -1, -1, 2141, -1, 68, 69, 2145, 2989, - -1, -1, 2149, 2150, 2151, 2152, 2153, 2154, 2155, 2156, - 501, 502, -1, -1, -1, 2162, 2163, -1, 2165, 2166, - -1, -1, -1, -1, -1, -1, 3016, -1, -1, -1, - -1, -1, 2179, -1, -1, 2182, -1, 109, 110, -1, - -1, 113, 114, 2190, 2191, 2192, 2193, 2194, 2195, 2196, - 2197, 2198, 2199, 253, 254, 255, 256, 257, 258, 259, - 260, -1, -1, 263, 264, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 8, -1, -1, 11, 2225, -1, + 2795, 2796, -1, -1, -1, -1, -1, -1, -1, -1, + 394, -1, -1, -1, 8, -1, -1, 11, -1, -1, -1, 15, 16, 17, 18, 19, 20, 21, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 2830, -1, -1, -1, -1, -1, -1, 36, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 46, -1, -1, -1, -1, 189, 190, 53, + -1, -1, 46, -1, -1, 2850, -1, -1, -1, 53, + -1, 2856, 2857, -1, -1, -1, 2861, -1, -1, -1, + -1, 2866, -1, -1, 2869, 2870, 1931, -1, -1, 2874, + 2875, -1, -1, 2878, 1939, 1940, 80, 1942, 1943, 1944, + 1945, 1946, 1947, -1, 2889, 1950, 1951, 1952, 1953, 1954, + 1955, 1956, 1957, 1958, 1959, 1960, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 502, -1, + -1, 505, 506, 507, -1, 509, 510, 511, 512, 513, + 514, -1, -1, -1, -1, 519, 68, 69, 2933, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 2277, -1, -1, -1, -1, -1, -1, -1, 338, 339, - -1, -1, -1, -1, -1, -1, 80, 3137, -1, -1, + -1, 8, -1, -1, 11, 2960, -1, -1, 15, 16, + 17, 18, 19, 20, 21, -1, -1, 109, 110, -1, + -1, 113, 114, 177, -1, -1, -1, -1, -1, 36, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, + 194, -1, -1, -1, -1, 199, 53, -1, -1, -1, + -1, -1, -1, 2068, -1, -1, 2071, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 222, 223, + -1, -1, -1, 80, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 237, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 189, 190, -1, + -1, 2116, -1, -1, -1, 2120, -1, -1, -1, 2124, + 2125, 2126, 2127, 2128, 2129, 2130, 2131, -1, 3073, -1, + -1, 275, 2137, 2138, 278, 2140, 2141, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 292, 2154, + -1, 295, 2157, -1, -1, 3100, -1, -1, -1, -1, + 2165, 2166, 2167, 2168, 2169, 2170, 2171, 2172, 2173, 2174, + -1, 253, 254, 255, 256, 257, 258, 259, 260, -1, + 177, 263, 264, -1, -1, -1, -1, -1, -1, 3134, + -1, -1, -1, -1, -1, 2200, -1, 194, -1, -1, + -1, -1, 199, -1, -1, -1, 3151, 3152, -1, -1, + 3155, -1, 3157, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 222, 223, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 3182, -1, -1, + 237, -1, -1, -1, -1, -1, -1, -1, 2253, -1, + 394, -1, -1, -1, -1, 337, 338, -1, -1, -1, + -1, 3206, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 275, -1, + -1, 278, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 292, 378, 379, 295, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 3164, -1, -1, -1, -1, 379, - 380, 253, 254, 255, 256, 257, 258, 259, 260, -1, - -1, 263, 264, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 3, -1, -1, -1, -1, 8, -1, 3199, - 11, -1, -1, 2360, 15, 16, 17, 18, 19, 20, - 21, -1, -1, -1, 2371, 2372, 3216, 3217, -1, -1, - 3220, -1, 3222, -1, -1, 36, -1, -1, -1, 40, - -1, -1, -1, 177, -1, 46, -1, -1, -1, -1, - -1, -1, 53, -1, -1, -1, -1, -1, -1, 3249, - 194, -1, -1, -1, -1, 199, 338, 339, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 477, 478, 80, - -1, -1, -1, 3273, -1, -1, -1, -1, 222, 223, - -1, 2438, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 501, 502, 237, -1, -1, -1, 379, 380, -1, - -1, -1, -1, -1, -1, -1, -1, 2464, 2465, 2466, - -1, 521, 2469, 2470, 2471, 2472, 2473, 2474, -1, -1, - -1, 2478, 2479, 2480, 2481, 2482, 2483, 2484, 2485, 2486, - 2487, 275, -1, -1, 278, 2492, 2493, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 292, -1, - -1, 295, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 2518, -1, -1, 3364, -1, 177, -1, 3368, -1, - -1, 2528, 3372, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 194, -1, -1, 3386, -1, 199, -1, - -1, 3391, -1, 3393, -1, 477, 478, -1, -1, -1, - -1, -1, -1, 3403, -1, -1, 2563, -1, -1, -1, - -1, 222, 223, -1, -1, -1, -1, -1, -1, 501, - 502, 3421, -1, -1, 2581, -1, 237, -1, -1, -1, - 2587, -1, -1, -1, -1, -1, -1, -1, 2595, 2596, - -1, -1, -1, -1, -1, -1, 2603, 2604, -1, -1, - -1, 395, -1, -1, -1, -1, -1, -1, -1, -1, - 2617, 2618, 2619, 2620, 275, 2622, -1, 278, 3468, 2626, - -1, -1, -1, -1, -1, -1, -1, -1, 3478, -1, - -1, 292, -1, -1, 295, -1, -1, -1, -1, -1, - 3490, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 8, -1, -1, 11, -1, - -1, -1, 15, 16, 17, 18, 19, 20, 21, -1, - -1, -1, -1, 3523, -1, -1, -1, 2684, -1, -1, - -1, -1, -1, 36, -1, -1, -1, -1, -1, -1, + -1, 2326, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 2337, 2338, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 3294, + -1, -1, -1, 3298, -1, -1, -1, 3302, 502, -1, + -1, 505, 506, 507, -1, 509, 510, 511, 512, 513, + 514, 3316, -1, -1, -1, 519, 3321, -1, 3323, -1, + -1, -1, -1, -1, -1, -1, 3331, -1, -1, -1, + -1, -1, 474, 475, -1, -1, -1, 394, -1, 2404, + -1, -1, -1, -1, 3349, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 498, 499, -1, -1, + -1, -1, -1, -1, -1, 2430, 2431, 2432, -1, -1, + 2435, 2436, 2437, 2438, 2439, 2440, 518, -1, -1, 2444, + 2445, 2446, 2447, 2448, 2449, 2450, 2451, 2452, 2453, -1, + -1, 3396, -1, 2458, 2459, 8, -1, -1, 11, -1, + -1, 3406, 15, 16, 17, 18, 19, 20, 21, -1, + -1, -1, -1, 3418, -1, -1, -1, -1, -1, 2484, + -1, -1, -1, 36, -1, 2490, -1, -1, -1, -1, -1, -1, -1, 46, -1, -1, -1, -1, -1, -1, - 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 505, -1, -1, 508, 509, 510, -1, 512, 513, - 514, 515, 516, 517, -1, -1, -1, 80, -1, -1, - -1, 525, -1, -1, 395, 8, -1, -1, 11, -1, - -1, -1, 15, 16, 17, 18, 19, 20, 21, -1, + 53, -1, -1, -1, -1, 502, 3451, -1, 505, 506, + 507, -1, 509, 510, 511, 512, 513, 514, -1, -1, + 2525, -1, 519, -1, -1, -1, -1, 80, -1, -1, + -1, -1, -1, 24, -1, -1, -1, 2542, -1, -1, + -1, -1, -1, 2548, -1, -1, -1, -1, -1, -1, + -1, 2556, 2557, -1, -1, -1, -1, -1, -1, 2564, + 2565, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 2578, 2579, 2580, 2581, -1, 2583, -1, + -1, -1, 2587, -1, -1, -1, -1, -1, -1, -1, + 81, -1, -1, 3538, 3539, 3540, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 97, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 8, + 3565, -1, 11, -1, 177, -1, 15, 16, 17, 18, + 19, 20, 21, -1, -1, -1, -1, -1, 2643, -1, + -1, 194, -1, -1, -1, -1, 199, 36, -1, -1, + -1, -1, -1, -1, -1, 146, -1, 46, -1, -1, + -1, 3606, -1, -1, 53, 156, -1, -1, -1, 222, + 223, -1, -1, -1, -1, -1, -1, -1, 169, -1, + -1, -1, -1, 174, 237, -1, -1, -1, -1, -1, + -1, 80, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 8, -1, + -1, 11, 203, -1, -1, 15, 16, 17, 18, 19, + 20, 21, 275, -1, -1, 278, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 36, -1, -1, 292, + -1, -1, 295, -1, -1, -1, 46, -1, 2753, -1, + -1, -1, -1, 53, -1, 246, -1, -1, -1, 250, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 3610, 3611, 3612, 36, -1, -1, -1, 40, -1, -1, - -1, -1, -1, 46, -1, -1, -1, -1, -1, -1, - 53, -1, -1, -1, -1, -1, -1, 3637, -1, -1, - -1, -1, 8, -1, -1, 11, 2803, -1, -1, 15, - 16, 17, 18, 19, 20, 21, -1, 80, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 2825, -1, - 36, -1, -1, -1, 177, -1, -1, -1, 3678, -1, - 46, -1, -1, -1, -1, -1, -1, 53, -1, -1, - -1, 194, -1, -1, 505, -1, 199, 508, 509, 510, - -1, 512, 513, 514, 515, 516, 517, -1, -1, -1, - -1, -1, -1, -1, 80, -1, -1, -1, -1, 222, - 223, -1, -1, -1, -1, -1, 2883, -1, 2885, -1, - -1, -1, -1, -1, 237, -1, -1, 2894, -1, -1, + 2775, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 80, -1, -1, -1, -1, -1, 8, -1, 177, 11, + -1, -1, -1, 15, 16, 17, 18, 19, 20, 21, + -1, -1, -1, -1, -1, 194, -1, -1, -1, -1, + 199, -1, -1, -1, 36, -1, -1, -1, -1, -1, + -1, -1, -1, 314, 46, -1, 2831, -1, 2833, 320, + -1, 53, -1, 222, 223, -1, -1, 2842, -1, -1, + -1, 394, -1, -1, 335, -1, -1, -1, 237, -1, + 2855, -1, -1, 2858, -1, 2860, -1, -1, 80, 2864, + -1, -1, 2867, 2868, -1, -1, 2871, 2872, -1, -1, + -1, -1, -1, -1, 2879, -1, -1, 177, -1, 370, + -1, -1, 373, 2888, -1, -1, 275, -1, -1, 278, + -1, -1, -1, 384, 194, -1, 387, -1, 2903, 199, + -1, -1, -1, 292, -1, -1, 295, -1, -1, -1, + -1, -1, -1, -1, 405, -1, -1, -1, -1, -1, + -1, -1, 222, 223, -1, -1, -1, -1, 419, -1, + -1, -1, -1, -1, 425, 426, 2941, 237, -1, -1, + -1, -1, -1, -1, -1, 436, -1, -1, -1, 502, + -1, 442, 505, 506, 507, 177, 509, 510, 511, 512, + 513, 514, -1, -1, -1, -1, 519, -1, -1, -1, + -1, -1, 194, -1, -1, 275, -1, 199, 278, 470, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 2907, -1, -1, 2910, 177, 2912, -1, -1, -1, 2916, - -1, -1, 2919, 2920, -1, -1, 2923, 2924, -1, -1, - -1, 194, 275, -1, 2931, 278, 199, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 2944, -1, 292, - -1, -1, 295, -1, -1, -1, -1, -1, -1, 222, - 223, -1, 2959, -1, -1, -1, -1, -1, 24, -1, - -1, 177, -1, 8, 237, -1, 11, -1, -1, -1, - 15, 16, 17, 18, 19, 20, 21, -1, 194, -1, - -1, -1, -1, 199, -1, -1, -1, -1, -1, -1, - 2997, 36, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 46, 275, -1, -1, 278, 222, 223, 53, -1, - -1, -1, -1, -1, -1, 81, -1, -1, -1, 292, - -1, 237, 295, -1, -1, -1, -1, -1, -1, -1, - -1, 97, -1, -1, -1, 80, -1, 8, -1, -1, - 11, -1, 395, -1, 15, 16, 17, 18, 19, 20, - 21, -1, -1, -1, -1, -1, -1, -1, -1, 275, - -1, -1, 278, -1, -1, 36, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 46, 292, -1, -1, 295, - 146, -1, 53, -1, -1, -1, -1, -1, -1, -1, - 156, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 169, -1, -1, -1, -1, 174, 80, - 3117, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 395, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 177, -1, -1, -1, -1, 203, -1, -1, - 3147, 3148, -1, -1, -1, -1, -1, -1, -1, 194, - -1, -1, 505, -1, 199, 508, 509, 510, -1, 512, - 513, 514, 515, 516, 517, 3172, 3173, 520, -1, 3176, - -1, -1, -1, -1, -1, -1, -1, 222, 223, 395, - 246, -1, -1, -1, 250, -1, -1, -1, -1, -1, - 3197, -1, 237, -1, -1, -1, -1, -1, -1, 3206, - -1, -1, -1, 3210, 3211, 3212, 177, -1, 3215, -1, - -1, 3218, 3219, -1, -1, -1, -1, -1, -1, -1, - 3227, -1, -1, 194, -1, -1, -1, -1, 199, -1, - 275, -1, 505, 278, -1, 508, 509, 510, -1, 512, - 513, 514, 515, 516, 517, -1, -1, 292, -1, 522, - 295, 222, 223, -1, -1, 321, -1, -1, -1, -1, - -1, -1, -1, 3270, -1, -1, 237, -1, -1, 3276, - 336, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 3289, -1, -1, -1, -1, -1, -1, 505, - -1, -1, 508, 509, 510, -1, 512, 513, 514, 515, - 516, 517, -1, -1, 275, 371, 522, 278, 374, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 385, - -1, 292, 388, -1, 295, -1, -1, -1, -1, -1, + 68, 69, 292, -1, -1, 295, -1, -1, -1, -1, + 222, 223, -1, -1, -1, 394, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 237, -1, -1, -1, -1, + -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, + -1, 109, 110, -1, -1, 113, 114, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 407, -1, -1, -1, 3352, -1, -1, -1, -1, - 395, -1, -1, -1, -1, 421, -1, -1, -1, -1, - -1, -1, 428, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 438, -1, -1, -1, -1, -1, 444, -1, - -1, 3388, 3389, 3390, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 275, -1, -1, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 3410, -1, -1, -1, 473, -1, -1, - -1, -1, -1, -1, -1, 3422, -1, -1, -1, -1, - -1, -1, -1, -1, 395, -1, -1, -1, -1, -1, + 292, -1, -1, 295, -1, -1, -1, -1, 3083, 3084, + -1, 81, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 394, -1, -1, 97, -1, -1, + -1, -1, -1, 3108, 3109, -1, -1, -1, -1, -1, + -1, 189, 190, 502, -1, -1, 505, 506, 507, -1, + 509, 510, 511, 512, 513, 514, -1, 3132, -1, -1, + 519, -1, -1, -1, -1, -1, 3141, -1, -1, -1, + 3145, 3146, 3147, -1, -1, 3150, 146, -1, 3153, 3154, + -1, -1, -1, -1, -1, -1, 156, 3162, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 169, + -1, -1, 394, -1, 174, 253, 254, 255, 256, 257, + 258, 259, 260, -1, -1, 263, 264, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 3203, -1, + -1, -1, 502, 203, 3209, 505, 506, 507, -1, 509, + 510, 511, 512, 513, 514, -1, -1, 3222, -1, 519, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 246, -1, -1, -1, + 250, -1, -1, -1, -1, -1, -1, -1, -1, 337, + 338, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 3282, -1, -1, + 502, -1, -1, 505, 506, 507, -1, 509, 510, 511, + 512, 513, 514, -1, -1, -1, -1, 519, -1, -1, + 378, 379, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 3318, 3319, 3320, -1, -1, -1, -1, + 320, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 3338, -1, 335, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 3350, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 505, -1, -1, 508, 509, 510, -1, 512, 513, 514, - 515, 516, 517, -1, -1, -1, 3483, 522, -1, -1, - -1, -1, -1, -1, -1, -1, 3493, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 370, -1, -1, 373, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 384, -1, -1, 387, -1, -1, + -1, -1, -1, -1, -1, -1, 474, 475, -1, -1, + -1, -1, -1, -1, -1, 405, 3411, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 3421, -1, -1, 419, + 498, 499, -1, -1, -1, -1, 426, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 436, -1, -1, -1, + -1, 3446, 442, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 3518, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 3471, -1, -1, -1, + 470, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 505, -1, 3543, 508, 509, 510, - -1, 512, 513, 514, 515, 516, 517, -1, -1, -1, - -1, 522, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 4, 5, 6, 7, 8, 9, 10, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 3586, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 3514, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 3640, 75, 76, 77, 78, 79, -1, + 71, 72, 73, 3568, 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, @@ -12979,7 +12865,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, + 171, 172, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, @@ -12993,245 +12879,296 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, 315, 316, 317, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, 383, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, 394, 395, 396, 397, 398, 399, -1, + 381, 382, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, 417, -1, 419, 420, - 421, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, 454, 455, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, 483, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, 415, -1, 417, 418, 419, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, 452, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, 480, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 505, -1, 507, -1, -1, -1, - -1, 512, 513, 514, -1, -1, -1, -1, 519, -1, - 521, 522, -1, -1, -1, -1, 527, 528, 529, 530, - 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, 120, 121, 122, - 123, 124, 125, 126, 127, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, 172, - 173, 174, 175, 176, 177, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, 316, 317, 318, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - 383, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, 394, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, 417, -1, 419, 420, 421, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, 455, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 505, -1, 507, -1, -1, -1, -1, 512, - 513, 514, -1, -1, -1, -1, 519, -1, 521, -1, - -1, -1, -1, -1, 527, 528, 529, 530, 3, 4, - 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, - -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, 171, 172, 173, 174, - 175, 176, 177, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, - 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, 316, 317, 318, -1, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, 383, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - 395, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, 421, 422, 423, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, 454, - 455, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, 471, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, 483, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 505, -1, 507, -1, -1, -1, -1, 512, 513, 514, - -1, -1, -1, -1, 519, -1, 521, -1, -1, -1, - -1, -1, 527, 528, 529, 530, 3, 4, 5, 6, - 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, -1, -1, - 37, -1, 39, -1, -1, 42, 43, 44, -1, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - 117, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, 132, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, 171, -1, 173, 174, 175, 176, - 177, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, - 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, 296, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, 384, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, 395, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, 423, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, 454, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 505, -1, - -1, -1, -1, -1, -1, 512, 513, 514, -1, -1, - -1, -1, 519, -1, 521, 522, -1, -1, -1, -1, - 527, 528, 529, 530, 3, 4, 5, 6, 7, -1, - 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, - -1, 120, 121, 122, 123, 124, 125, 126, 127, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, 171, 172, 173, 174, 175, 176, 177, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, -1, 276, 277, 278, - 279, 280, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, - -1, 320, 321, 322, 323, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, 383, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, 417, -1, - 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, 455, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, 471, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, 483, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, -1, -1, 507, -1, + 501, 502, -1, 504, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, 519, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + 126, 127, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, 172, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, 382, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + -1, 417, 418, 419, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, 452, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, 480, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, 504, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 519, -1, 521, -1, -1, -1, -1, -1, 527, 528, - 529, 530, 3, 4, 5, 6, 7, 8, 9, 10, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, 172, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, 382, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, 419, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, 452, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, 480, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, 504, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, -1, -1, + -1, 37, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, 132, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, 383, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, 519, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, -1, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, + 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, 172, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, -1, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, 382, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, 415, -1, 417, 418, 419, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, 452, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, 480, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, -1, -1, 504, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, 172, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, 233, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, 432, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, 37, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, @@ -13243,13 +13180,13 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, - 231, -1, 233, 234, 235, 236, 237, -1, 239, 240, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, @@ -13257,243 +13194,399 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, + 381, -1, 383, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, 434, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, 454, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 505, -1, -1, -1, -1, -1, - -1, 512, 513, 514, -1, -1, -1, -1, 519, -1, - 521, -1, -1, -1, -1, -1, 527, 528, 529, 530, - 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, 37, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, 177, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 505, -1, -1, -1, -1, -1, -1, 512, - 513, 514, -1, -1, -1, -1, 519, -1, 521, -1, - -1, -1, -1, -1, 527, 528, 529, 530, 3, 4, - 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, 37, -1, 39, -1, -1, 42, 43, 44, - -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, - 175, 176, 177, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, - 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, 384, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - 395, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, 423, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, 454, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, 471, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 505, -1, -1, -1, -1, -1, -1, 512, 513, 514, - -1, -1, -1, -1, 519, -1, 521, 522, -1, -1, - -1, -1, 527, 528, 529, 530, 3, 4, 5, 6, - 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, -1, -1, - -1, 38, 39, -1, -1, 42, 43, 44, -1, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - 117, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, 171, -1, 173, 174, 175, 176, - 177, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, - 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, 395, 396, - 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, 423, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, 454, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, 471, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 505, -1, - -1, -1, -1, -1, -1, 512, 513, 514, -1, -1, - -1, -1, 519, -1, 521, -1, -1, -1, -1, -1, - 527, 528, 529, 530, 3, 4, 5, 6, 7, 8, - 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, 37, -1, - 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, 171, -1, 173, 174, 175, 176, 177, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, - 279, 280, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, 323, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, 384, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, 395, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, 423, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, 454, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, 471, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 505, -1, -1, -1, - -1, -1, -1, 512, 513, 514, -1, -1, -1, -1, - 519, -1, 521, 522, -1, -1, -1, -1, 527, 528, - 529, 530, 3, 4, 5, 6, 7, 8, 9, 10, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, 37, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, 383, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, 519, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, -1, -1, -1, -1, 38, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, 399, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, 37, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, 383, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, 519, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, 37, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, 383, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, 172, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, - 31, 32, 33, -1, -1, -1, 37, -1, 39, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, @@ -13507,7 +13600,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, -1, 173, 174, 175, 176, 177, 178, 179, 180, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, @@ -13521,240 +13614,291 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, 384, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, 454, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 505, -1, -1, -1, -1, -1, - -1, 512, 513, 514, -1, -1, -1, -1, 519, -1, - 521, -1, -1, -1, -1, -1, 527, 528, 529, 530, - 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, 177, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 505, -1, -1, -1, -1, -1, -1, 512, - 513, 514, -1, -1, -1, -1, 519, -1, 521, -1, - -1, -1, -1, -1, 527, 528, 529, 530, 3, 4, - 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, -1, - -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, - -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, - 175, 176, 177, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, - 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - 395, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, 423, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, 454, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, 471, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 505, -1, -1, -1, -1, -1, -1, 512, 513, 514, - -1, -1, -1, -1, 519, -1, 521, -1, -1, -1, - -1, -1, 527, 528, 529, 530, 3, 4, 5, 6, - 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - 117, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, 171, 172, 173, 174, 175, 176, - 177, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, - 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, 395, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, 423, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, 454, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, 471, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 505, -1, - -1, -1, -1, -1, -1, 512, 513, 514, -1, -1, - -1, -1, 519, -1, 521, -1, -1, -1, -1, -1, - 527, 528, 529, 530, 3, 4, 5, 6, 7, 8, - 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, 171, -1, 173, 174, 175, 176, 177, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, - 279, 280, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, 323, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, 395, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, 423, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, 454, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, 471, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 505, -1, -1, -1, - -1, -1, -1, 512, 513, 514, -1, -1, -1, -1, - 519, -1, 521, 522, -1, -1, -1, -1, 527, 528, - 529, 530, 3, 4, 5, 6, 7, 8, 9, 10, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, 519, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, 523, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, 419, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, 477, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, 523, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, @@ -13771,7 +13915,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, -1, 173, 174, 175, 176, 177, 178, 179, 180, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, @@ -13785,240 +13929,186 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, 454, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 505, -1, -1, -1, -1, -1, - -1, 512, 513, 514, -1, -1, -1, -1, 519, -1, - 521, -1, -1, -1, -1, 526, 527, 528, 529, 530, - 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, 177, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, 421, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 505, -1, -1, -1, -1, -1, -1, 512, - 513, 514, -1, -1, -1, -1, 519, -1, 521, -1, - -1, -1, -1, -1, 527, 528, 529, 530, 3, 4, - 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, - -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, - 175, 176, 177, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, - 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - 395, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, 423, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, 454, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, 471, 472, 473, 474, - 475, 476, 477, 478, -1, 480, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 505, -1, -1, -1, -1, -1, -1, 512, 513, 514, - -1, -1, -1, -1, 519, -1, 521, -1, -1, -1, - -1, -1, 527, 528, 529, 530, 3, 4, 5, 6, - 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, -1, -1, - -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - 117, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, 171, -1, 173, 174, 175, 176, - 177, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, - 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, 395, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, 423, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, 454, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, 471, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 505, -1, - -1, -1, -1, -1, -1, 512, 513, 514, -1, -1, - -1, -1, 519, -1, 521, -1, -1, -1, -1, -1, - 527, 528, 529, 530, 3, 4, 5, 6, 7, 8, - 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, 171, -1, 173, 174, 175, 176, 177, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, - 279, 280, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, 323, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, 395, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, 423, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, 454, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, 471, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 505, -1, -1, -1, - -1, -1, -1, 512, 513, 514, -1, -1, -1, -1, - 519, -1, 521, -1, -1, -1, -1, 526, 527, 528, - 529, 530, 3, 4, 5, 6, 7, 8, 9, 10, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, @@ -14035,7 +14125,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, -1, 173, 174, 175, 176, 177, 178, 179, 180, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, @@ -14049,240 +14139,186 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, 454, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 505, -1, -1, -1, -1, -1, - -1, 512, 513, 514, -1, -1, -1, -1, 519, -1, - 521, -1, -1, -1, -1, -1, 527, 528, 529, 530, - 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, 177, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 505, -1, -1, -1, -1, -1, -1, 512, - 513, 514, -1, -1, -1, -1, 519, -1, 521, -1, - -1, -1, -1, -1, 527, 528, 529, 530, 3, 4, - 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, - -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, - 175, 176, 177, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, - 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - 395, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, 423, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, 454, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, 471, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 505, -1, -1, -1, -1, -1, -1, 512, 513, 514, - -1, -1, -1, -1, 519, -1, 521, -1, -1, -1, - -1, -1, 527, 528, 529, 530, 3, 4, 5, 6, - 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - 117, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, 171, -1, 173, 174, 175, 176, - 177, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, - 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, 395, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, 423, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, 454, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, 471, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 505, -1, - -1, -1, -1, -1, -1, 512, 513, 514, -1, -1, - -1, -1, 519, -1, 521, -1, -1, -1, -1, -1, - 527, 528, 529, 530, 3, 4, 5, 6, 7, 8, - 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, 171, -1, 173, 174, 175, 176, 177, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, - 279, 280, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, 323, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, 395, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, 423, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, 454, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, 471, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 505, -1, -1, -1, - -1, -1, -1, 512, 513, 514, -1, -1, -1, -1, - 519, -1, 521, -1, -1, -1, -1, -1, 527, 528, - 529, 530, 3, 4, 5, 6, 7, 8, 9, 10, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 502, -1, -1, -1, + -1, -1, -1, 509, 510, 511, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, @@ -14299,7 +14335,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, -1, 173, 174, 175, 176, 177, 178, 179, 180, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, @@ -14313,240 +14349,291 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, 454, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 505, -1, -1, -1, -1, -1, - -1, 512, 513, 514, -1, -1, -1, -1, 519, -1, - 521, -1, -1, -1, -1, -1, 527, 528, 529, 530, - 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, 177, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 505, -1, -1, -1, -1, -1, -1, 512, - 513, 514, -1, -1, -1, -1, 519, -1, 521, -1, - -1, -1, -1, -1, 527, 528, 529, 530, 3, 4, - 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, - -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, 117, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, - 175, 176, 177, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, - 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, - 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - 395, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, 423, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, 454, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, 471, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 505, -1, -1, -1, -1, -1, -1, 512, 513, 514, - -1, -1, -1, -1, 519, -1, 521, -1, -1, -1, - -1, -1, 527, 528, 529, 530, 3, 4, 5, 6, - 7, 8, 9, 10, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - 117, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, 171, -1, 173, 174, 175, 176, - 177, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, - 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, 395, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, 423, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, 454, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, 471, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 505, -1, - -1, -1, -1, -1, -1, 512, 513, 514, -1, -1, - -1, -1, 519, -1, 521, -1, -1, -1, -1, -1, - 527, 528, 529, 530, 3, 4, 5, 6, 7, 8, - 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, 171, -1, 173, 174, 175, 176, 177, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, -1, -1, 224, 225, 226, 227, 228, - 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, -1, 276, 277, -1, - 279, 280, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, 323, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, 395, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, 423, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, 454, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, 471, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 505, -1, -1, -1, - -1, -1, -1, 512, 513, 514, -1, -1, -1, -1, - 519, -1, 521, -1, -1, -1, -1, -1, 527, 528, - 529, 530, 3, 4, 5, 6, 7, 8, 9, 10, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, 8, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, -1, -1, -1, -1, + -1, -1, -1, 509, 510, -1, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, -1, -1, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, -1, 276, 277, -1, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 502, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, -1, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, -1, -1, -1, -1, + -1, -1, -1, 509, 510, -1, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, -1, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, -1, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, -1, -1, -1, -1, -1, -1, -1, 509, 510, + -1, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, -1, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, 181, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, -1, 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, @@ -14563,7 +14650,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, -1, 173, 174, 175, 176, 177, 178, 179, 180, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, @@ -14577,347 +14664,387 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, -1, -1, -1, -1, -1, -1, - -1, 512, 513, -1, -1, -1, -1, -1, 519, -1, - 521, -1, -1, -1, -1, -1, 527, 528, 529, 530, - 3, 4, 5, 6, 7, -1, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, 177, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, -1, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, -1, -1, -1, -1, -1, -1, -1, 512, - 513, -1, -1, -1, -1, -1, 519, -1, 521, -1, - -1, -1, -1, -1, 527, 528, 529, 530, 3, 4, - 5, 6, 7, 8, 9, 10, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, 39, -1, -1, 42, 43, 44, - -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, - 65, 66, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, - 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, - 175, 176, 177, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, 223, 224, - 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, - 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - -1, 276, 277, 278, 279, 280, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - 395, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, 423, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, 471, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - -1, -1, -1, -1, -1, -1, -1, 512, 513, -1, - -1, -1, -1, -1, 519, -1, 521, -1, -1, -1, - -1, -1, 527, 528, 529, 530, 3, 4, 5, 6, - 7, -1, 9, 10, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, 39, -1, -1, 42, 43, 44, -1, 46, - 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, -1, 59, 60, 61, 62, 63, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, - 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, 171, -1, 173, 174, 175, 176, - 177, 178, 179, 180, 181, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, - 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, -1, 276, - 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, 323, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, 365, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, 395, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, 423, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, 471, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, -1, -1, + 501, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 516, -1, 518, -1, -1, + -1, -1, -1, 524, 525, 526, 527, 3, 4, 5, + 6, 7, -1, 9, 10, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, 39, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, -1, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 516, -1, 518, -1, -1, -1, -1, -1, 524, 525, + 526, 527, 3, 4, 5, 6, 7, 8, 9, 10, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, -1, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, -1, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, -1, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, -1, -1, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, -1, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, -1, 276, 277, -1, 279, 280, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, -1, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, -1, -1, -1, -1, -1, -1, -1, 509, 510, + 511, -1, 3, 4, 5, 516, -1, 518, 9, -1, + -1, -1, -1, 524, 525, 526, 527, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, 37, -1, -1, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, -1, 276, 277, 278, 279, -1, + 281, 282, 283, 284, 285, 286, -1, 288, 289, 290, + -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, 383, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, -1, -1, -1, -1, -1, -1, -1, 509, 510, + 511, 3, -1, -1, -1, 516, -1, 518, 10, -1, + -1, -1, -1, -1, -1, -1, 527, -1, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, 39, -1, -1, + 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, 81, + -1, 83, 84, 85, 86, 87, 88, 89, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, 171, + -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, 209, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + -1, -1, 234, 235, 236, 237, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, + 272, 273, 274, -1, 276, 277, 278, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + 322, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, 421, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, 468, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 3, 4, -1, 516, -1, 518, 9, 10, -1, + -1, -1, 524, 525, 526, 527, -1, -1, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, + 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, + -1, 83, 84, 85, 86, 87, 88, -1, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, -1, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, + -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + -1, -1, 224, -1, 226, 227, 228, 229, 230, 231, + -1, -1, 234, -1, 236, -1, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, + 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, + -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + -1, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, -1, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, -1, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, + -1, -1, -1, -1, -1, 3, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 524, 525, 22, 23, 24, 25, 26, 27, + 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, + -1, -1, 40, -1, -1, 43, 44, -1, 46, 47, + 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, + -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, + 88, -1, 90, 91, 92, -1, 94, 95, 96, 97, + 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, + 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, + 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, + 138, -1, 140, 141, 142, -1, 144, 145, 146, 147, + 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, -1, 161, 162, 163, 164, 165, 166, 167, + 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, + 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, + 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, + 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, + 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, + 218, 219, -1, 221, -1, -1, 224, -1, 226, 227, + 228, 229, 230, 231, -1, -1, 234, -1, 236, -1, + 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, + -1, 279, -1, 281, 282, 283, 284, 285, 286, 287, + 288, 289, -1, -1, 292, 293, 294, -1, 296, 297, + 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, 321, -1, 323, 324, 325, 326, 327, + 328, -1, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, + 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 380, 381, -1, -1, 384, 385, 386, 387, + 388, 389, 390, 391, 392, -1, -1, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, -1, -1, 417, + 418, -1, 420, -1, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, 435, 436, 437, + -1, 439, 440, 441, 442, 443, 444, 445, 446, 447, + -1, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, 463, 464, 465, -1, 467, + -1, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, + 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, + 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 519, -1, 521, -1, -1, -1, -1, -1, - 527, 528, 529, 530, 3, 4, 5, 6, 7, -1, - 9, 10, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, + -1, 519, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - 39, -1, -1, 42, 43, 44, -1, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, - 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, + -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, + 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, + 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, + -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, + 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, 171, -1, 173, 174, 175, 176, 177, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, + 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, + -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, + -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, + 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, + -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, + 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, + 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 269, 270, 271, 272, 273, 274, -1, 276, 277, 278, - 279, 280, 281, 282, 283, 284, 285, 286, -1, 288, + -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, + 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, 323, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, + 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, + 309, 310, 311, 312, 313, 314, -1, -1, -1, -1, + 319, 320, 321, -1, 323, 324, 325, 326, 327, 328, + -1, 330, 331, 332, 333, 334, 335, -1, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, 365, 366, 367, 368, + 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, 395, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, 423, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, 471, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, + 379, 380, 381, -1, -1, 384, 385, 386, 387, 388, + 389, 390, 391, 392, -1, -1, 395, 396, 397, 398, + -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, -1, -1, 417, 418, + -1, 420, -1, 422, 423, 424, 425, 426, -1, 428, + 429, 430, -1, -1, 433, 434, 435, 436, 437, -1, + 439, 440, 441, 442, 443, 444, 445, 446, -1, -1, + 449, 450, 451, -1, 453, 454, 455, 456, -1, 458, + 459, 460, 461, 462, 463, 464, 465, -1, 467, -1, + 469, 470, 471, 472, 473, 474, 475, -1, -1, 478, + -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 519, -1, 521, -1, -1, -1, -1, -1, 527, 528, - 529, 530, 3, 4, 5, 6, 7, -1, 9, 10, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, - 31, 32, 33, -1, -1, -1, -1, -1, 39, -1, - -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, - 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, - 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, - 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, - 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, - 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, - 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, - 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, - 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, - 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, -1, 173, 174, 175, 176, 177, 178, 179, 180, - -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, - 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, - 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, - 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, - 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, - 271, 272, 273, 274, -1, 276, 277, 278, 279, 280, - 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, - -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, - 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, - 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, - 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, - 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, 440, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, - 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 519, -1, - 521, -1, -1, -1, -1, -1, 527, 528, 529, 530, - 3, 4, 5, 6, 7, 8, 9, 10, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, 39, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - -1, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, 117, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, -1, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, 160, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, -1, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, - -1, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, -1, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, 274, -1, 276, 277, -1, 279, 280, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - 323, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, 440, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, -1, -1, -1, -1, -1, -1, -1, 512, - 513, 514, -1, 3, 4, 5, 519, -1, 521, 9, - -1, -1, -1, -1, 527, 528, 529, 530, -1, -1, - -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, - -1, 31, 32, 33, -1, -1, -1, 37, -1, -1, + 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 518, + 519, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, 34, 35, -1, 37, -1, -1, -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, @@ -14926,12 +15053,12 @@ static const yytype_int16 yycheck[] = 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, - 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, - 170, 171, -1, 173, 174, 175, 176, 177, 178, 179, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, 171, 172, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, @@ -14942,284 +15069,130 @@ static const yytype_int16 yycheck[] = 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, 276, 277, 278, 279, - -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, - 290, -1, 292, 293, 294, -1, -1, 297, 298, 299, - 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, -1, -1, -1, -1, - 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, - -1, 331, 332, 333, 334, 335, 336, -1, 338, 339, - 340, 341, 342, 343, 344, 345, 346, 347, -1, 349, - 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, -1, 363, 364, 365, 366, 367, 368, 369, - 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, -1, 384, 385, 386, 387, 388, 389, - 390, 391, 392, 393, -1, 395, 396, 397, 398, 399, - -1, 401, 402, 403, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, -1, -1, 419, - 420, -1, 422, 423, 424, 425, 426, 427, 428, -1, - 430, 431, 432, -1, -1, 435, 436, 437, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, -1, - -1, 451, 452, 453, 454, -1, 456, 457, 458, 459, - -1, 461, 462, 463, 464, 465, 466, 467, 468, -1, - 470, 471, 472, 473, 474, 475, 476, 477, 478, -1, - -1, 481, -1, -1, 484, 485, 486, 487, 488, 489, - 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 503, 504, -1, -1, -1, -1, -1, - -1, -1, 512, 513, 514, 3, -1, -1, -1, 519, - -1, 521, 10, -1, -1, -1, -1, -1, -1, -1, - 530, -1, -1, -1, 22, 23, 24, 25, 26, 27, - 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, - -1, 39, -1, -1, 42, 43, 44, -1, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - -1, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, - 78, 79, -1, 81, -1, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, -1, 94, 95, 96, 97, - 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, - 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, - 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, - 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, - 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, - 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, - 168, -1, 170, 171, -1, 173, 174, 175, 176, 177, - 178, 179, 180, -1, 182, 183, 184, 185, -1, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, - 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, - 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, - -1, 219, -1, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 230, 231, -1, -1, 234, 235, 236, 237, - -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, 269, 270, 271, 272, 273, 274, -1, 276, 277, - 278, 279, -1, 281, 282, 283, 284, 285, 286, -1, - 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, - 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, -1, -1, - -1, -1, 320, 321, 322, 323, 324, 325, 326, 327, - 328, 329, -1, 331, 332, 333, 334, 335, 336, -1, - 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - -1, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, -1, 363, 364, 365, 366, 367, - 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, - 378, 379, 380, 381, 382, -1, -1, 385, 386, 387, - 388, 389, 390, 391, 392, 393, -1, 395, 396, 397, - 398, 399, -1, 401, 402, 403, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, -1, - -1, 419, 420, -1, 422, 423, 424, 425, 426, 427, - 428, -1, 430, 431, 432, -1, -1, 435, 436, 437, - 438, 439, -1, 441, 442, 443, 444, 445, 446, 447, - 448, -1, -1, 451, 452, 453, -1, -1, 456, 457, - 458, 459, -1, 461, 462, 463, 464, 465, 466, 467, - 468, -1, 470, 471, 472, 473, 474, 475, 476, 477, - 478, -1, -1, 481, -1, -1, 484, 485, 486, 487, - 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 503, 504, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 3, 4, - -1, 519, -1, 521, 9, 10, -1, -1, -1, 527, - 528, 529, 530, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - -1, -1, -1, -1, -1, 3, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 527, 528, 22, 23, 24, 25, 26, 27, - 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, - -1, -1, 40, -1, -1, 43, 44, -1, -1, 47, - 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, - -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, - 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, - 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, - 88, -1, 90, 91, 92, -1, 94, 95, 96, 97, - 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, - 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, - 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, - 138, -1, 140, 141, 142, -1, 144, 145, 146, 147, - 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, - 158, 159, -1, 161, 162, 163, 164, 165, 166, 167, - 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, - 178, 179, 180, -1, 182, 183, 184, 185, -1, 187, - 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, - 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, - 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, - 218, 219, -1, 221, -1, -1, 224, -1, 226, 227, - 228, 229, 230, 231, -1, -1, 234, -1, 236, -1, - 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, - -1, 279, -1, 281, 282, 283, 284, 285, 286, 287, - 288, 289, -1, -1, 292, 293, 294, -1, 296, 297, - 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, -1, -1, - -1, -1, 320, 321, 322, -1, 324, 325, 326, 327, - 328, 329, -1, 331, 332, 333, 334, 335, 336, -1, - 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - -1, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, -1, 363, 364, -1, 366, 367, - 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, - 378, 379, 380, 381, 382, -1, -1, 385, 386, 387, - 388, 389, 390, 391, 392, 393, -1, -1, 396, 397, - 398, 399, -1, 401, 402, 403, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, -1, - -1, 419, 420, -1, 422, -1, 424, 425, 426, 427, - 428, -1, 430, 431, 432, -1, -1, 435, 436, 437, - 438, 439, -1, 441, 442, 443, 444, 445, 446, 447, - 448, 449, -1, 451, 452, 453, -1, -1, 456, 457, - 458, 459, -1, 461, 462, 463, 464, 465, 466, 467, - 468, -1, 470, -1, 472, 473, 474, 475, 476, 477, - 478, -1, -1, 481, -1, -1, 484, 485, 486, 487, - 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 503, 504, 3, -1, 5, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 522, -1, 22, 23, 24, 25, - 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 43, 44, -1, - -1, 47, 48, -1, 50, 51, 52, 53, 54, -1, - 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, - -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, - 76, 77, 78, 79, -1, -1, -1, 83, 84, 85, - 86, 87, 88, -1, 90, 91, 92, -1, 94, 95, - 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, - 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, - -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, - 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, - 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, - 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, - 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, - 176, -1, 178, 179, 180, -1, 182, 183, 184, 185, - -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, - 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, - 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, - 216, 217, -1, 219, -1, 221, -1, -1, 224, -1, - 226, 227, 228, 229, 230, 231, -1, -1, 234, -1, - 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, - 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, - 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, - -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - -1, -1, -1, -1, 320, 321, 322, -1, 324, 325, - 326, 327, 328, 329, -1, 331, 332, 333, 334, 335, - 336, -1, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, -1, 349, 350, 351, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, -1, 363, 364, -1, - 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, - 376, 377, 378, 379, 380, 381, 382, -1, -1, 385, - 386, 387, 388, 389, 390, 391, 392, 393, -1, -1, - 396, 397, 398, 399, -1, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, -1, -1, 419, 420, -1, 422, -1, 424, 425, - 426, 427, 428, -1, 430, 431, 432, -1, -1, 435, - 436, 437, 438, 439, -1, 441, 442, 443, 444, 445, - 446, 447, 448, -1, -1, 451, 452, 453, -1, -1, - 456, 457, 458, 459, -1, 461, 462, 463, 464, 465, - 466, 467, 468, -1, 470, -1, 472, 473, 474, 475, - 476, 477, 478, -1, -1, 481, -1, -1, 484, 485, - 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 503, 504, 3, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 521, 522, -1, 22, 23, - 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, - 34, 35, -1, 37, -1, -1, -1, -1, 42, 43, - 44, -1, 46, 47, 48, 49, 50, 51, 52, 53, - 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, - 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, - -1, 75, 76, 77, 78, 79, -1, 81, -1, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, -1, - 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, - 124, 125, 126, 127, 128, 129, 130, 131, -1, -1, - 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, - 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, - 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, - 164, 165, 166, -1, 168, -1, 170, 171, 172, 173, - 174, 175, 176, 177, 178, 179, 180, -1, 182, 183, - 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, - 204, 205, 206, -1, 208, 209, 210, 211, 212, 213, - 214, 215, 216, 217, -1, 219, -1, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, -1, -1, - 234, 235, 236, 237, -1, 239, 240, 241, 242, 243, - 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, - 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, - 274, -1, 276, 277, 278, 279, -1, 281, 282, 283, - 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, - 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, - 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, -1, 320, 321, 322, 323, - 324, 325, 326, 327, 328, 329, -1, 331, 332, 333, - 334, 335, 336, -1, 338, 339, 340, 341, 342, 343, - 344, 345, 346, 347, -1, 349, 350, 351, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, -1, 363, - 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, - 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, - 394, 395, 396, 397, 398, 399, -1, 401, 402, 403, - 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, -1, 419, 420, 421, 422, 423, - 424, 425, 426, 427, 428, -1, 430, 431, 432, -1, - -1, 435, 436, 437, 438, 439, -1, 441, 442, 443, - 444, 445, 446, 447, 448, -1, -1, 451, 452, 453, - 454, 455, 456, 457, 458, 459, -1, 461, 462, 463, - 464, 465, 466, 467, 468, -1, 470, 471, 472, 473, - 474, 475, 476, 477, 478, -1, -1, 481, -1, 483, - 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, - 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, - 504, -1, 3, 507, 5, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 521, -1, -1, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, + 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, -1, 319, + 320, 321, 322, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, 364, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, 415, -1, 417, 418, 419, + 420, 421, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, 452, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, 468, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, -1, 3, 504, 5, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 518, -1, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, + -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, 66, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, 81, -1, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, 171, 172, 173, 174, 175, 176, 177, 178, -1, + 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, + 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, 222, 223, 224, 225, 226, 227, 228, 229, + 230, 231, 232, -1, 234, 235, 236, 237, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, + 270, 271, 272, 273, 274, -1, 276, 277, 278, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, 291, 292, 293, 294, -1, -1, 297, 298, 299, + 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, 315, 316, 317, -1, 319, + 320, 321, 322, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, 364, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, 382, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, 393, 394, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, 415, -1, 417, 418, 419, + 420, 421, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, 452, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, 468, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, -1, 3, 504, 5, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 518, -1, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, + -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, 66, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, 81, -1, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, 171, -1, 173, 174, 175, 176, 177, 178, -1, + 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, + 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, 222, 223, 224, 225, 226, 227, 228, 229, + 230, 231, 232, -1, 234, 235, 236, 237, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, + 270, 271, 272, 273, 274, -1, 276, 277, 278, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, 291, 292, 293, 294, -1, -1, 297, 298, 299, + 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, -1, -1, -1, -1, 319, + 320, 321, 322, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, 364, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, -1, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, -1, 394, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, -1, -1, 417, 418, -1, + 420, 421, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, -1, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, 468, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 518, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, @@ -15230,18 +15203,18 @@ static const yytype_int16 yycheck[] = 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, - 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, + 171, -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, - 231, 232, -1, 234, 235, 236, 237, -1, 239, 240, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, @@ -15249,332 +15222,280 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, 291, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, -1, 320, - 321, 322, 323, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, + -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, 383, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, 394, 395, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, 417, -1, 419, 420, - 421, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, 455, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, 483, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, -1, 3, 507, 5, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 521, -1, -1, -1, 22, 23, 24, 25, 26, 27, - 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, - -1, -1, -1, -1, 42, 43, 44, -1, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - -1, 59, 60, 61, 62, 63, 64, -1, 66, 67, - 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, - 78, 79, -1, 81, -1, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, -1, 94, 95, 96, 97, - 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, - 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, - 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, - 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, - 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, - 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, - 168, -1, 170, 171, -1, 173, 174, 175, 176, 177, - 178, 179, 180, -1, 182, 183, 184, 185, -1, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, - 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, - 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, - -1, 219, -1, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 230, 231, 232, -1, 234, 235, 236, 237, - -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, 269, 270, 271, 272, 273, 274, -1, 276, 277, - 278, 279, -1, 281, 282, 283, 284, 285, 286, -1, - 288, 289, -1, 291, 292, 293, 294, -1, -1, 297, - 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, -1, -1, - -1, -1, 320, 321, 322, 323, 324, 325, 326, 327, - 328, 329, -1, 331, 332, 333, 334, 335, 336, -1, - 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - -1, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, -1, 363, 364, 365, 366, 367, - 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, - 378, 379, 380, 381, 382, -1, -1, 385, 386, 387, - 388, 389, 390, 391, 392, 393, -1, 395, 396, 397, - 398, 399, -1, 401, 402, 403, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, -1, - -1, 419, 420, -1, 422, 423, 424, 425, 426, 427, - 428, -1, 430, 431, 432, -1, -1, 435, 436, 437, - 438, 439, -1, 441, 442, 443, 444, 445, 446, 447, - 448, -1, -1, 451, 452, 453, -1, -1, 456, 457, - 458, 459, -1, 461, 462, 463, 464, 465, 466, 467, - 468, -1, 470, 471, 472, 473, 474, 475, 476, 477, - 478, -1, -1, 481, -1, -1, 484, 485, 486, 487, - 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 503, 504, 3, -1, 5, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 521, -1, -1, 22, 23, 24, 25, - 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, - -1, -1, -1, -1, -1, -1, 42, 43, 44, -1, - 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, - 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, - 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, - 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, - 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, - -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, - 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, - 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, - 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, - 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, - 176, 177, 178, 179, 180, -1, 182, 183, 184, 185, - -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, - 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, - 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, - 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, - 276, 277, 278, 279, -1, 281, 282, 283, 284, 285, - 286, -1, 288, 289, -1, 291, 292, 293, 294, -1, - -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - -1, -1, -1, -1, 320, 321, 322, 323, 324, 325, - 326, 327, 328, 329, -1, 331, 332, 333, 334, 335, - 336, -1, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, -1, 349, 350, 351, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, -1, 363, 364, 365, - 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, - 376, 377, 378, 379, 380, 381, 382, -1, -1, 385, - 386, 387, 388, 389, 390, 391, 392, 393, -1, 395, - 396, 397, 398, 399, -1, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, -1, -1, 419, 420, -1, 422, 423, 424, 425, - 426, 427, 428, -1, 430, 431, 432, -1, -1, 435, - 436, 437, 438, 439, -1, 441, 442, 443, 444, 445, - 446, 447, 448, -1, -1, 451, 452, 453, -1, -1, - 456, 457, 458, 459, -1, 461, 462, 463, 464, 465, - 466, 467, 468, -1, 470, 471, 472, 473, 474, 475, - 476, 477, 478, -1, -1, 481, -1, -1, 484, 485, - 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 503, 504, 3, + 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 518, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, + 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, 66, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, 81, + -1, 83, 84, 85, 86, 87, 88, 89, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, 171, + -1, 173, 174, 175, 176, 177, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, 209, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + -1, -1, 234, 235, 236, 237, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, + 272, 273, 274, -1, 276, 277, 278, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + 322, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, 421, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, 468, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, + 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 518, -1, -1, 22, + 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, + 33, -1, -1, -1, -1, -1, -1, -1, -1, 42, + 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, + 63, 64, -1, 66, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, + 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, + -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, + 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, + -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, + -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, + 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, + 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, + 173, 174, 175, 176, 177, 178, -1, 180, -1, 182, + 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, + 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, + 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, + 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, + 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, + -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, + 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, + 273, 274, -1, 276, 277, 278, 279, -1, 281, 282, + 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, + 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, -1, -1, -1, -1, 319, 320, 321, 322, + 323, 324, 325, 326, 327, 328, -1, 330, 331, 332, + 333, 334, 335, -1, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, -1, 362, + 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, -1, + -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, + -1, 394, 395, 396, 397, 398, -1, 400, 401, 402, + 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, -1, -1, 417, 418, -1, 420, 421, 422, + 423, 424, 425, 426, -1, 428, 429, 430, -1, -1, + 433, 434, 435, 436, 437, -1, 439, 440, 441, 442, + 443, 444, 445, 446, -1, -1, 449, 450, 451, -1, + 453, 454, 455, 456, -1, 458, 459, 460, 461, 462, + 463, 464, 465, -1, 467, 468, 469, 470, 471, 472, + 473, 474, 475, -1, -1, 478, -1, -1, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 521, -1, -1, 22, 23, + -1, -1, -1, -1, -1, 518, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, - -1, -1, -1, -1, -1, -1, -1, -1, 42, 43, - 44, -1, 46, 47, 48, 49, 50, 51, 52, 53, - 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, - 64, -1, 66, 67, 68, 69, 70, 71, 72, 73, - -1, 75, 76, 77, 78, 79, -1, 81, -1, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, -1, - 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, + 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, + 84, 85, 86, 87, 88, -1, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, + 124, 125, 126, 127, 128, 129, 130, 131, -1, -1, + 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, + 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, + 164, 165, 166, -1, 168, -1, 170, -1, 172, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, + 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, + -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, + 224, -1, 226, 227, 228, 229, 230, 231, -1, -1, + 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, + 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, + 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, + 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, + 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, + 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, + 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, 382, -1, + 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, 415, -1, 417, 418, 419, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, 452, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, 480, 481, 482, 483, + 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 499, 500, 501, -1, 3, + 504, 5, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 518, -1, -1, -1, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, + 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, + 84, 85, 86, 87, 88, -1, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, + 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, + 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, + 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, + 164, 165, 166, -1, 168, -1, 170, -1, 172, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, + 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, + -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, + 224, -1, 226, 227, 228, 229, 230, 231, -1, -1, + 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, + 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, + 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, + 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, + 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, + 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, + 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, 315, 316, 317, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, 382, -1, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, -1, -1, 417, 418, 419, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, 452, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, 480, 481, 482, 483, + 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 499, 500, 501, -1, 3, + 504, 5, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 518, -1, -1, -1, 22, 23, + 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, + 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, + 84, 85, 86, 87, 88, -1, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, - 164, 165, 166, -1, 168, -1, 170, 171, -1, 173, - 174, 175, 176, 177, 178, 179, 180, -1, 182, 183, + 164, 165, 166, -1, 168, -1, 170, -1, 172, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, - 204, 205, 206, -1, 208, 209, 210, 211, 212, 213, - 214, 215, 216, 217, -1, 219, -1, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, -1, -1, - 234, 235, 236, 237, -1, 239, 240, 241, 242, 243, + -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, + 224, -1, 226, 227, 228, 229, 230, 231, -1, -1, + 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, - 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, - 274, -1, 276, 277, 278, 279, -1, 281, 282, 283, + 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, + 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, - 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, + 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, -1, -1, -1, -1, 320, 321, 322, 323, - 324, 325, 326, 327, 328, 329, -1, 331, 332, 333, - 334, 335, 336, -1, 338, 339, 340, 341, 342, 343, - 344, 345, 346, 347, -1, 349, 350, 351, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, -1, 363, - 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 314, 315, 316, 317, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, -1, - -1, 385, 386, 387, 388, 389, 390, 391, 392, 393, - -1, 395, 396, 397, 398, 399, -1, 401, 402, 403, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, -1, -1, 419, 420, -1, 422, 423, - 424, 425, 426, 427, 428, -1, 430, 431, 432, -1, - -1, 435, 436, 437, 438, 439, -1, 441, 442, 443, - 444, 445, 446, 447, 448, -1, -1, 451, 452, 453, - -1, -1, 456, 457, 458, 459, -1, 461, 462, 463, - 464, 465, 466, 467, 468, -1, 470, 471, 472, 473, - 474, 475, 476, 477, 478, -1, -1, 481, -1, -1, + 414, -1, -1, 417, 418, 419, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, 452, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, - 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, - 504, 3, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 521, -1, -1, - 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, - 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, - 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, - 62, 63, 64, -1, 66, 67, 68, 69, 70, 71, - 72, 73, -1, 75, 76, 77, 78, 79, -1, 81, - -1, 83, 84, 85, 86, 87, 88, 89, 90, 91, - 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, - 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, - 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, - -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, - 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, - 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, - -1, 163, 164, 165, 166, -1, 168, -1, 170, 171, - -1, 173, 174, 175, 176, 177, 178, 179, 180, -1, - 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, - 202, 203, 204, 205, 206, -1, 208, 209, 210, 211, - 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, - 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, - -1, -1, 234, 235, 236, 237, -1, 239, 240, 241, - 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, - 272, 273, 274, -1, 276, 277, 278, 279, -1, 281, - 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, - 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, - 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, -1, -1, -1, -1, 320, 321, - 322, 323, 324, 325, 326, 327, 328, 329, -1, 331, - 332, 333, 334, 335, 336, -1, 338, 339, 340, 341, - 342, 343, 344, 345, 346, 347, -1, 349, 350, 351, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - -1, 363, 364, 365, 366, 367, 368, 369, 370, 371, - 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, - 382, -1, -1, 385, 386, 387, 388, 389, 390, 391, - 392, 393, -1, 395, 396, 397, 398, 399, -1, 401, - 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, -1, -1, 419, 420, -1, - 422, 423, 424, 425, 426, 427, 428, -1, 430, 431, - 432, -1, -1, 435, 436, 437, 438, 439, -1, 441, - 442, 443, 444, 445, 446, 447, 448, -1, -1, 451, - 452, 453, -1, -1, 456, 457, 458, 459, -1, 461, - 462, 463, 464, 465, 466, 467, 468, -1, 470, 471, - 472, 473, 474, 475, 476, 477, 478, -1, -1, 481, - -1, -1, 484, 485, 486, 487, 488, 489, 490, 491, - 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, - 502, 503, 504, 3, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 521, - -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, - -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 43, 44, -1, -1, 47, 48, -1, - 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, - 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, - 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, - -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, - 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, - -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, - 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, - 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, - 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, - 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, - 170, -1, 172, -1, 174, 175, 176, -1, 178, 179, - 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, - 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, - 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, - 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, - -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, - 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, - 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, - 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, - -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, - -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, - -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, -1, - 320, 321, 322, -1, 324, 325, 326, 327, 328, 329, - -1, 331, 332, 333, 334, 335, 336, -1, 338, 339, - 340, 341, 342, 343, 344, 345, 346, 347, -1, 349, - 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, -1, 363, 364, -1, 366, 367, 368, 369, - 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, 383, -1, 385, 386, 387, 388, 389, - 390, 391, 392, 393, 394, -1, 396, 397, 398, 399, - -1, 401, 402, 403, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, 417, -1, 419, - 420, 421, 422, -1, 424, 425, 426, 427, 428, -1, - 430, 431, 432, -1, -1, 435, 436, 437, 438, 439, - -1, 441, 442, 443, 444, 445, 446, 447, 448, -1, - -1, 451, 452, 453, -1, 455, 456, 457, 458, 459, - -1, 461, 462, 463, 464, 465, 466, 467, 468, -1, - 470, -1, 472, 473, 474, 475, 476, 477, 478, -1, - -1, 481, -1, 483, 484, 485, 486, 487, 488, 489, - 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 503, 504, -1, 3, 507, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 521, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, 172, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, - 317, 318, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, 383, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, 421, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, 455, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, 483, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, -1, 3, - 507, 5, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 521, -1, -1, -1, 22, 23, + 494, 495, 496, 497, 498, 499, 500, 501, -1, 3, + 504, 5, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 518, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, - 44, -1, -1, 47, 48, -1, 50, 51, 52, 53, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, @@ -15586,8 +15507,8 @@ static const yytype_int16 yycheck[] = 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, - 164, 165, 166, -1, 168, -1, 170, -1, 172, -1, - 174, 175, 176, -1, 178, 179, 180, -1, 182, 183, + 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, @@ -15601,80 +15522,229 @@ static const yytype_int16 yycheck[] = 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, -1, 320, 321, 322, -1, - 324, 325, 326, 327, 328, 329, -1, 331, 332, 333, - 334, 335, 336, -1, 338, 339, 340, 341, 342, 343, - 344, 345, 346, 347, -1, 349, 350, 351, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, -1, 363, - 364, -1, 366, 367, 368, 369, 370, 371, 372, 373, - 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, - -1, 385, 386, 387, 388, 389, 390, 391, 392, 393, - -1, -1, 396, 397, 398, 399, -1, 401, 402, 403, + 314, -1, -1, -1, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, -1, -1, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, -1, -1, 419, 420, 421, 422, -1, - 424, 425, 426, 427, 428, -1, 430, 431, 432, -1, - -1, 435, 436, 437, 438, 439, -1, 441, 442, 443, - 444, 445, 446, 447, 448, -1, -1, 451, 452, 453, - -1, 455, 456, 457, 458, 459, -1, 461, 462, 463, - 464, 465, 466, 467, 468, -1, 470, -1, 472, 473, - 474, 475, 476, 477, 478, -1, -1, 481, -1, 483, + 414, -1, -1, 417, 418, -1, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, -1, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, - 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, - 504, -1, 3, 507, 5, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 521, -1, -1, - -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, - 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, - 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, - 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, - 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, - -1, -1, 83, 84, 85, 86, 87, 88, -1, 90, - 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, - -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, - 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, - 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, - 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, - 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, - 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, - -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, - 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, - 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, - 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, - 221, -1, -1, 224, -1, 226, 227, 228, 229, 230, - 231, -1, -1, 234, -1, 236, -1, -1, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, - 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, - 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, - -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, - 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, - 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, - 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, - 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, - 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, 5, -1, -1, -1, + 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, + 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 518, -1, -1, 22, 23, 24, + 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, + -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, + -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, + -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, + 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, + 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, + 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, + 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, + 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, + 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, + 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, + 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, + 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, + 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, + 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, + -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, + -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, + -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, + 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, + -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + -1, -1, -1, -1, 319, 320, 321, -1, 323, 324, + 325, 326, 327, 328, -1, 330, 331, 332, 333, 334, + 335, -1, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, -1, 362, 363, -1, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, -1, -1, 384, + 385, 386, 387, 388, 389, 390, 391, 392, -1, -1, + 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + -1, -1, 417, 418, -1, 420, -1, 422, 423, 424, + 425, 426, -1, 428, 429, 430, -1, -1, 433, 434, + 435, 436, 437, -1, 439, 440, 441, 442, 443, 444, + 445, 446, -1, -1, 449, 450, 451, -1, 453, 454, + 455, 456, -1, 458, 459, 460, 461, 462, 463, 464, + 465, -1, 467, -1, 469, 470, 471, 472, 473, 474, + 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, + 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, + 495, 496, 497, 498, 499, 500, 501, 3, -1, 5, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 518, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 43, 44, -1, + 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, + 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, + -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, -1, -1, 83, 84, 85, + 86, 87, 88, -1, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, + 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, -1, -1, 224, -1, + 226, 227, 228, 229, 230, 231, -1, -1, 234, -1, + 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, + 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, -1, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, -1, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, -1, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, -1, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, -1, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, -1, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 3, -1, 5, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 518, -1, -1, 22, 23, 24, 25, 26, + 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 43, 44, -1, 46, + 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, + 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, + 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, + 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, + 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, + 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, + -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, + -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, + 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, + -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, + 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, + -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, + -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, + 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, + 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, + -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, + 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, + 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, + -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, + 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, + 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, + -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, + 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, -1, -1, + -1, -1, 319, 320, 321, -1, 323, 324, 325, 326, + 327, 328, -1, 330, 331, 332, 333, 334, 335, -1, + 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, + -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, -1, 362, 363, -1, 365, 366, + 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, + 377, 378, 379, 380, 381, -1, -1, 384, 385, 386, + 387, 388, 389, 390, 391, 392, -1, -1, 395, 396, + 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, -1, -1, + 417, 418, -1, 420, -1, 422, 423, 424, 425, 426, + -1, 428, 429, 430, -1, -1, 433, 434, 435, 436, + 437, -1, 439, 440, 441, 442, 443, 444, 445, 446, + -1, -1, 449, 450, 451, -1, 453, 454, 455, 456, + -1, 458, 459, 460, 461, 462, 463, 464, 465, -1, + 467, -1, 469, 470, 471, 472, 473, 474, 475, -1, + -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, + 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, + 497, 498, 499, 500, 501, 3, -1, 5, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 518, -1, -1, 22, 23, 24, 25, 26, 27, + 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 43, 44, -1, 46, 47, + 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, + -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, + 88, -1, 90, 91, 92, -1, 94, 95, 96, 97, + 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, + 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, + 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, + 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, + 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, + 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, + 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, + 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, + 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, + 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, + -1, 219, -1, 221, -1, -1, 224, -1, 226, 227, + 228, 229, 230, 231, -1, -1, 234, -1, 236, -1, + -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, + -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, + 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, + 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, 321, -1, 323, 324, 325, 326, 327, + 328, -1, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, + 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 380, 381, -1, -1, 384, 385, 386, 387, + 388, 389, 390, 391, 392, -1, -1, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, -1, -1, 417, + 418, -1, 420, -1, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, 435, 436, 437, + -1, 439, 440, 441, 442, 443, 444, 445, 446, -1, + -1, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, 463, 464, 465, -1, 467, + -1, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, + 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, + 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 521, -1, -1, 22, 23, 24, 25, 26, 27, 28, + 518, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, + -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, @@ -15688,7 +15758,7 @@ static const yytype_int16 yycheck[] = 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, + -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, @@ -15701,181 +15771,80 @@ static const yytype_int16 yycheck[] = 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, + 309, 310, 311, 312, 313, 314, -1, -1, -1, -1, + 319, 320, 321, -1, 323, 324, 325, 326, 327, 328, + -1, 330, 331, 332, 333, 334, 335, -1, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, + 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, + 379, 380, 381, -1, -1, 384, 385, 386, 387, 388, + 389, 390, 391, 392, -1, -1, 395, 396, 397, 398, + -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, -1, -1, 417, 418, + -1, 420, -1, 422, 423, 424, 425, 426, -1, 428, + 429, 430, -1, -1, 433, 434, 435, 436, 437, -1, + 439, 440, 441, 442, 443, 444, 445, 446, -1, -1, + 449, 450, 451, -1, 453, 454, 455, 456, -1, 458, + 459, 460, 461, 462, 463, 464, 465, -1, 467, -1, + 469, 470, 471, 472, 473, 474, 475, -1, -1, 478, + -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 521, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, - 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 521, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 521, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, - 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, - 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, - 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, - -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, - -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, - 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, 5, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 521, -1, + 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 518, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, + 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, -1, -1, -1, 174, 175, 176, -1, 178, -1, + 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, + 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, + 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, + 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, + -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, -1, -1, -1, -1, 319, + 320, 321, -1, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, -1, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, -1, -1, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, -1, -1, 417, 418, -1, + 420, -1, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, -1, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, -1, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 518, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, + -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, @@ -15888,7 +15857,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, + -1, -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, @@ -15902,181 +15871,180 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, -1, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, + -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + -1, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, -1, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, 5, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 521, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, - -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, - 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, - -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, - 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, - 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, 5, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 521, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 521, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, + 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 518, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, + 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, + -1, 83, 84, 85, 86, 87, 88, -1, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, -1, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, + -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + -1, -1, 224, -1, 226, 227, 228, 229, 230, 231, + -1, -1, 234, -1, 236, -1, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, + 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, + -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + -1, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, -1, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, -1, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 521, -1, -1, 22, + -1, -1, -1, -1, -1, -1, 518, -1, -1, 22, + 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, + 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, + 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, + 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, + 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, + -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, + 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, + -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, + -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, + 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, + 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, + -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, + 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, + 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, + 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, + 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, + -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, + -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, + 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, + 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, + 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, + 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, -1, -1, -1, -1, 319, 320, 321, -1, + 323, 324, 325, 326, 327, 328, -1, 330, 331, 332, + 333, 334, 335, -1, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, -1, 362, + 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, -1, + -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, + -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, + 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, -1, -1, 417, 418, -1, 420, -1, 422, + 423, 424, 425, 426, -1, 428, 429, 430, -1, -1, + 433, 434, 435, 436, 437, -1, 439, 440, 441, 442, + 443, 444, 445, 446, -1, -1, 449, 450, 451, -1, + 453, 454, 455, 456, -1, 458, 459, 460, 461, 462, + 463, 464, 465, -1, 467, -1, 469, 470, 471, 472, + 473, 474, 475, -1, -1, 478, -1, -1, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, -1, + 3, 4, 5, -1, -1, 8, 9, -1, -1, -1, + -1, -1, 15, 16, -1, 518, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + -1, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, -1, 80, 81, 82, + 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, + 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, + 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, -1, + 153, 154, 155, 156, 157, 158, -1, 160, 161, 162, + 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, + 173, 174, 175, 176, 177, 178, 179, 180, 181, -1, + -1, 184, 185, 186, 187, 188, 189, 190, 191, 192, + 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, + 203, 204, 205, 206, 207, 208, 209, -1, 211, 212, + 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, + 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, + 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, + 273, 274, 275, 276, 277, 278, 279, 280, -1, 282, + 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, + 293, 294, 295, 296, 297, 298, -1, 300, 301, 302, + -1, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, -1, 322, + 323, 324, -1, 326, 327, 328, 329, 330, 331, 332, + 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, + 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, + 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, -1, 415, 416, 417, 418, 419, 420, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, + 433, 434, -1, 436, -1, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, + 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, + -1, 464, 465, 466, 467, 468, 469, 470, 471, 472, + 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, + 483, 484, 485, 486, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 498, 499, 500, 501, -1, + 3, -1, 505, 506, 507, 8, 509, 510, 511, 512, + 513, 514, 15, 16, -1, -1, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, + 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, @@ -16089,7 +16057,7 @@ static const yytype_int16 yycheck[] = -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, + -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, @@ -16103,451 +16071,292 @@ static const yytype_int16 yycheck[] = 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, + 313, 314, -1, -1, -1, -1, 319, 320, 321, -1, + 323, 324, 325, 326, 327, 328, -1, 330, 331, 332, + 333, 334, 335, -1, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, -1, 362, + 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, -1, + -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, + -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, -1, 3, 4, 5, -1, -1, 8, 9, - -1, -1, -1, -1, -1, 15, 16, -1, 521, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, - 50, 51, 52, -1, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, -1, - 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, - 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, - 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, - 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, - 150, 151, -1, 153, 154, 155, 156, 157, 158, -1, - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, - 180, 181, -1, -1, 184, 185, 186, 187, 188, 189, - 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, - 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, - -1, 211, 212, 213, 214, 215, 216, 217, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, - 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, - 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, - 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, - 280, -1, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 291, 292, 293, 294, 295, 296, 297, 298, -1, - 300, 301, 302, -1, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, -1, 323, 324, 325, -1, 327, 328, 329, - 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, - 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, - 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, - 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, - 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, - 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, -1, 417, 418, 419, - 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, - 430, 431, 432, 433, 434, 435, 436, -1, 438, -1, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, - 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, - 460, 461, 462, 463, 464, 465, -1, 467, 468, 469, - 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, - 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 413, 414, -1, -1, 417, 418, -1, 420, -1, 422, + 423, 424, 425, 426, -1, 428, 429, 430, -1, -1, + 433, 434, 435, 436, 437, -1, 439, 440, 441, 442, + 443, 444, 445, 446, -1, -1, 449, 450, 451, -1, + 453, 454, 455, 456, -1, 458, 459, 460, 461, 462, + 463, 464, 465, -1, 467, -1, 469, 470, 471, 472, + 473, 474, 475, -1, -1, 478, -1, -1, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, -1, + -1, -1, 505, 506, 507, -1, 509, 510, 511, 512, + 513, 514, 8, -1, -1, 11, -1, -1, -1, 15, + 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 501, 502, 503, 504, -1, 3, -1, 508, 509, - 510, 8, 512, 513, 514, 515, 516, 517, 15, 16, - -1, -1, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, -1, -1, - -1, 508, 509, 510, -1, 512, 513, 514, 515, 516, - 517, 8, -1, -1, 11, -1, -1, -1, 15, 16, + 36, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 46, 8, -1, -1, 11, -1, -1, 53, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 36, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 46, + -1, -1, -1, -1, 80, -1, -1, -1, -1, 46, 8, -1, -1, 11, -1, -1, 53, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 36, -1, - -1, -1, -1, 80, -1, -1, -1, -1, 46, 8, - -1, -1, 11, -1, -1, 53, 15, 16, 17, 18, - 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 36, -1, -1, - -1, -1, 80, -1, -1, -1, -1, 46, -1, -1, - -1, -1, -1, -1, 53, -1, 8, -1, -1, 11, - -1, -1, -1, 15, 16, 17, 18, 19, 20, 21, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 80, -1, -1, 36, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 46, 8, -1, -1, 11, -1, - 177, 53, 15, 16, 17, 18, 19, 20, 21, -1, + -1, -1, -1, 80, -1, -1, -1, -1, 46, -1, + -1, -1, -1, -1, -1, 53, -1, -1, 8, -1, + -1, 11, -1, -1, -1, 15, 16, 17, 18, 19, + 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 80, -1, -1, -1, 36, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 46, 8, -1, -1, + 11, 177, -1, 53, 15, 16, 17, 18, 19, 20, + 21, -1, -1, -1, -1, -1, -1, -1, 194, -1, + -1, -1, -1, 199, -1, 36, -1, -1, -1, -1, + 80, -1, -1, -1, -1, 46, -1, -1, -1, -1, + 177, -1, 53, -1, -1, -1, 222, 223, -1, -1, -1, -1, -1, -1, -1, -1, -1, 194, -1, -1, - -1, -1, 199, 36, -1, -1, -1, -1, 80, -1, - -1, -1, -1, 46, -1, -1, -1, -1, -1, 177, - 53, -1, -1, -1, -1, 222, 223, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 194, -1, -1, -1, - 237, 199, -1, -1, -1, -1, -1, 80, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 177, -1, - -1, -1, -1, -1, 222, 223, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 194, -1, -1, 275, 237, - 199, 278, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 237, 199, -1, -1, -1, -1, -1, -1, 80, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 177, + -1, -1, -1, -1, -1, 222, 223, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 194, -1, -1, 275, + 237, 199, 278, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 292, -1, -1, 295, + -1, -1, -1, -1, 222, 223, -1, 177, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 275, 237, + -1, 278, -1, -1, 194, -1, -1, -1, -1, 199, -1, -1, -1, -1, -1, 292, -1, -1, 295, -1, - -1, -1, -1, 222, 223, 177, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 275, 237, -1, - 278, -1, 194, -1, -1, -1, -1, 199, -1, -1, + -1, -1, -1, -1, -1, -1, 177, -1, -1, -1, + -1, -1, 222, 223, -1, -1, -1, 275, -1, -1, + 278, -1, -1, 194, -1, -1, -1, 237, 199, -1, -1, -1, -1, -1, 292, -1, -1, 295, -1, -1, - -1, -1, -1, -1, 177, -1, -1, -1, -1, -1, - 222, 223, -1, -1, -1, -1, 275, -1, -1, 278, - -1, 194, -1, -1, -1, 237, 199, -1, -1, -1, - -1, -1, -1, 292, -1, -1, 295, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 222, - 223, -1, -1, -1, -1, -1, -1, -1, 395, -1, - -1, -1, -1, 275, 237, -1, 278, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 292, -1, -1, 295, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 395, -1, -1, - -1, -1, 275, -1, -1, 278, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, - -1, -1, 295, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 395, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 505, -1, - -1, 508, 509, 510, -1, 512, 513, 514, 515, 516, - 517, -1, -1, 395, -1, 522, -1, -1, -1, -1, - -1, -1, 8, -1, -1, 11, -1, -1, -1, 15, - 16, 17, 18, 19, 20, 21, -1, 505, -1, -1, - 508, 509, 510, -1, 512, 513, 514, 515, 516, 517, - 36, -1, 395, -1, 522, -1, -1, -1, -1, -1, - 46, -1, -1, -1, -1, -1, -1, 53, -1, -1, - -1, -1, -1, -1, -1, -1, 505, -1, -1, 508, - 509, 510, -1, 512, 513, 514, 515, 516, 517, -1, - -1, -1, -1, 522, 80, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 8, -1, - -1, 11, -1, -1, -1, 15, 16, 17, 18, 19, - 20, 21, -1, 505, -1, -1, 508, 509, 510, -1, - 512, 513, 514, 515, 516, 517, 36, -1, -1, -1, - 522, -1, -1, -1, -1, -1, 46, 8, -1, -1, - 11, -1, -1, 53, 15, 16, 17, 18, 19, 20, - 21, -1, 505, -1, -1, 508, 509, 510, -1, 512, - 513, 514, 515, 516, 517, 36, -1, -1, -1, 522, - 80, -1, -1, -1, -1, 46, 8, -1, -1, 11, - -1, 177, 53, 15, 16, 17, 18, 19, 20, 21, - -1, -1, -1, -1, -1, -1, -1, -1, 194, -1, - -1, -1, -1, 199, 36, -1, -1, -1, -1, 80, - -1, -1, -1, -1, 46, -1, -1, -1, -1, -1, - -1, 53, -1, -1, -1, -1, 222, 223, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 237, -1, -1, -1, -1, -1, -1, 80, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 8, -1, -1, 11, -1, 177, -1, 15, - 16, 17, 18, 19, 20, 21, -1, -1, -1, 275, - -1, -1, 278, -1, 194, -1, -1, -1, -1, 199, - 36, -1, -1, -1, -1, -1, 292, -1, -1, 295, - 46, -1, -1, -1, -1, -1, 177, 53, -1, -1, - -1, -1, 222, 223, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 194, -1, -1, -1, 237, 199, -1, - -1, -1, -1, -1, 80, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 177, -1, -1, -1, -1, - -1, 222, 223, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 194, -1, -1, 275, 237, 199, 278, -1, + -1, 222, 223, -1, -1, -1, -1, -1, 394, -1, + -1, -1, -1, -1, -1, 275, 237, -1, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, -1, -1, 295, -1, -1, -1, -1, - 222, 223, -1, -1, -1, -1, -1, -1, -1, 395, - -1, -1, -1, -1, 275, 237, -1, 278, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 394, -1, -1, + -1, -1, -1, -1, 275, -1, -1, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, -1, -1, 295, -1, -1, -1, -1, -1, - -1, 177, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 275, -1, -1, 278, -1, 194, -1, - -1, -1, -1, 199, -1, -1, -1, -1, -1, -1, - 292, -1, -1, 295, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 222, 223, -1, -1, - -1, -1, -1, -1, -1, 395, -1, -1, -1, -1, - -1, 237, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 505, - -1, -1, 508, 509, 510, -1, 512, 513, 514, 515, - 516, 517, -1, -1, 395, -1, 522, -1, -1, 275, - -1, -1, 278, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 292, -1, -1, 295, + -1, -1, -1, -1, -1, -1, 394, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 395, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 505, -1, -1, 508, 509, - 510, -1, 512, 513, 514, 515, 516, 517, -1, -1, - -1, -1, 522, -1, -1, -1, -1, -1, -1, 8, - -1, -1, 11, -1, -1, -1, 15, 16, 17, 18, - 19, 20, 21, -1, 505, -1, -1, 508, 509, 510, - -1, 512, 513, 514, 515, 516, 517, 36, -1, 395, - -1, 522, -1, -1, -1, -1, -1, 46, 8, -1, - -1, 11, -1, -1, 53, 15, 16, 17, 18, 19, - 20, 21, -1, 505, -1, -1, 508, 509, 510, -1, - 512, 513, 514, 515, 516, 517, 36, -1, -1, -1, - 522, 80, -1, -1, -1, -1, 46, -1, -1, -1, - -1, -1, -1, 53, -1, 8, -1, -1, 11, -1, - -1, -1, 15, 16, 17, 18, 19, 20, 21, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 80, -1, -1, 36, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 46, 8, -1, -1, 11, -1, -1, - 53, 15, 16, 17, 18, 19, 20, 21, -1, 505, - -1, -1, 508, 509, 510, -1, 512, 513, 514, 515, - 516, 517, 36, -1, -1, -1, 522, 80, -1, -1, - -1, -1, 46, 8, -1, -1, 11, -1, 177, 53, - 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, - -1, -1, -1, -1, -1, 194, -1, -1, -1, -1, - 199, 36, -1, -1, -1, -1, 80, -1, -1, -1, - -1, 46, -1, -1, -1, -1, -1, 177, 53, -1, - -1, -1, -1, 222, 223, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 194, -1, -1, -1, 237, 199, - -1, -1, -1, -1, -1, 80, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 222, 223, 177, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 275, 237, -1, 278, - -1, 194, -1, -1, -1, -1, 199, -1, -1, -1, - -1, -1, -1, 292, -1, -1, 295, -1, -1, -1, - -1, -1, -1, 177, -1, -1, -1, -1, -1, 222, - 223, -1, -1, -1, -1, 275, -1, -1, 278, -1, - 194, -1, -1, -1, 237, 199, -1, -1, -1, -1, - -1, -1, 292, -1, -1, 295, -1, -1, -1, -1, - -1, -1, 177, -1, -1, -1, -1, -1, 222, 223, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 194, - -1, -1, 275, 237, 199, 278, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, - -1, -1, 295, -1, -1, -1, -1, 222, 223, -1, - -1, -1, -1, -1, -1, -1, 395, -1, -1, -1, - -1, 275, 237, -1, 278, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, -1, -1, 292, -1, - -1, 295, -1, -1, -1, 32, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 395, -1, -1, -1, -1, - 275, -1, -1, 278, -1, 52, -1, -1, -1, -1, - -1, -1, -1, -1, 61, -1, -1, 292, -1, -1, - 295, -1, -1, -1, -1, -1, -1, -1, 75, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 86, - -1, -1, 395, -1, -1, -1, -1, -1, -1, -1, - -1, 98, -1, 100, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 111, -1, 505, -1, -1, 508, - 509, 510, -1, 512, 513, 514, 515, 516, 517, 126, - 127, 395, -1, 522, -1, -1, -1, -1, -1, -1, - 137, -1, -1, -1, -1, -1, 143, -1, -1, -1, - -1, -1, -1, -1, 151, 505, -1, -1, 508, 509, - 510, -1, 512, 513, 514, 515, 516, 517, -1, -1, - 395, 168, 522, -1, -1, 172, -1, -1, -1, -1, - -1, 24, -1, -1, -1, -1, -1, 8, -1, -1, + -1, -1, -1, -1, -1, -1, 502, -1, -1, 505, + 506, 507, -1, 509, 510, 511, 512, 513, 514, -1, + -1, -1, -1, 519, 394, -1, -1, -1, -1, -1, + 8, -1, -1, 11, -1, -1, -1, 15, 16, 17, + 18, 19, 20, 21, -1, 502, -1, -1, 505, 506, + 507, -1, 509, 510, 511, 512, 513, 514, 36, -1, + -1, -1, 519, 394, -1, -1, -1, -1, 46, -1, + -1, -1, -1, -1, -1, 53, -1, -1, -1, -1, + -1, -1, -1, -1, 502, -1, -1, 505, 506, 507, + -1, 509, 510, 511, 512, 513, 514, -1, -1, -1, + -1, 519, 80, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 8, -1, -1, 11, -1, -1, -1, 15, 16, 17, 18, 19, 20, - 21, -1, 505, -1, -1, 508, 509, 510, -1, 512, - 513, 514, 515, 516, 517, 36, -1, 214, -1, 522, - -1, -1, -1, -1, -1, 46, -1, -1, -1, -1, - -1, -1, 53, -1, -1, -1, -1, -1, 81, -1, - -1, 505, -1, 240, 508, 509, 510, -1, 512, 513, - 514, 515, 516, 517, 97, -1, 520, -1, -1, 80, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 505, -1, -1, 508, 509, 510, -1, 512, 513, 514, - 515, 516, 517, -1, -1, 520, -1, -1, -1, -1, - -1, -1, -1, 146, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 156, -1, -1, -1, -1, -1, 316, - 317, 318, -1, -1, -1, -1, 169, 324, -1, -1, - 327, 174, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 177, -1, -1, -1, - 203, 358, -1, -1, -1, -1, -1, -1, -1, -1, - 367, -1, -1, 194, -1, -1, -1, -1, 199, -1, - -1, -1, -1, -1, -1, -1, 383, -1, -1, -1, - -1, -1, -1, 390, -1, -1, -1, 394, -1, -1, - -1, 222, 223, 246, -1, -1, -1, 250, 405, -1, - -1, -1, -1, -1, -1, -1, 237, -1, -1, -1, - 417, -1, -1, -1, 421, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 441, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 275, -1, -1, 278, 455, -1, - -1, -1, -1, -1, 461, -1, -1, -1, -1, 466, - -1, 292, 315, -1, 295, -1, -1, -1, 321, -1, - -1, -1, -1, -1, -1, -1, 483, -1, -1, -1, - -1, -1, -1, 336, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 507, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 521, -1, -1, -1, 371, -1, - -1, 374, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 385, -1, -1, 388, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 407, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 395, -1, -1, -1, 421, -1, - -1, -1, -1, -1, 427, 428, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 438, -1, -1, -1, -1, - -1, 444, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 473, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 21, -1, 502, -1, -1, 505, 506, 507, -1, 509, + 510, 511, 512, 513, 514, 36, -1, -1, -1, 519, + -1, -1, -1, -1, -1, 46, 8, -1, -1, 11, + -1, -1, 53, 15, 16, 17, 18, 19, 20, 21, + -1, 502, -1, -1, 505, 506, 507, -1, 509, 510, + 511, 512, 513, 514, 36, -1, -1, -1, 519, 80, + -1, -1, -1, -1, 46, 8, -1, -1, 11, 177, + -1, 53, 15, 16, 17, 18, 19, 20, 21, -1, + -1, -1, -1, -1, -1, -1, 194, -1, -1, -1, + -1, 199, -1, 36, -1, -1, -1, -1, 80, -1, + -1, -1, -1, 46, -1, -1, -1, -1, -1, -1, + 53, -1, -1, -1, 222, 223, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 237, + -1, -1, -1, -1, -1, -1, -1, 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 8, -1, -1, 11, 177, -1, -1, 15, + 16, 17, 18, 19, 20, 21, -1, 275, -1, -1, + 278, -1, -1, 194, -1, -1, -1, -1, 199, -1, + 36, -1, -1, -1, 292, -1, -1, 295, -1, -1, + 46, -1, -1, -1, -1, 177, -1, 53, -1, -1, + -1, 222, 223, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 194, -1, -1, -1, 237, 199, -1, -1, + -1, -1, -1, -1, 80, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 177, -1, -1, -1, -1, -1, + 222, 223, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 194, -1, -1, 275, 237, 199, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 292, -1, -1, 295, -1, -1, -1, -1, 222, + 223, -1, -1, -1, -1, -1, 394, -1, -1, -1, + -1, -1, -1, 275, 237, -1, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 3, -1, -1, 505, -1, -1, 508, 509, 510, - -1, 512, 513, 514, 515, 516, 517, -1, -1, 520, - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, - 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, - 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, - 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, - 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, - 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, - 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, - 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, - 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, - 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, - 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, - 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, - 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, - 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, - 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, - 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, - 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, - 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, - 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, - 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, - 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, - 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, - 502, 503, 504, 3, -1, -1, -1, -1, -1, -1, - -1, -1, 514, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, - -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 43, 44, -1, -1, 47, 48, -1, - 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, - 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, - 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, - -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, - 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, - -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, - 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, - 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, - 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, - 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, - 170, -1, -1, -1, 174, 175, 176, -1, 178, 179, - 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, - 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, - 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, - 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, - -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, - 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, - 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, - 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, - -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, - -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, - -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, -1, -1, -1, -1, - 320, 321, 322, -1, 324, 325, 326, 327, 328, 329, - -1, 331, 332, 333, 334, 335, 336, -1, 338, 339, - 340, 341, 342, 343, 344, 345, 346, 347, -1, 349, - 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, -1, 363, 364, -1, 366, 367, 368, 369, - 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, -1, -1, 385, 386, 387, 388, 389, - 390, 391, 392, 393, -1, -1, 396, 397, 398, 399, - -1, 401, 402, 403, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, -1, -1, 419, - 420, -1, 422, -1, 424, 425, 426, 427, 428, -1, - 430, 431, 432, -1, -1, 435, 436, 437, 438, 439, - -1, 441, 442, 443, 444, 445, 446, 447, 448, -1, - -1, 451, 452, 453, -1, -1, 456, 457, 458, 459, - -1, 461, 462, 463, 464, 465, 466, 467, 468, -1, - 470, -1, 472, 473, 474, 475, 476, 477, 478, -1, - -1, 481, -1, -1, 484, 485, 486, 487, 488, 489, - 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 503, 504, 3, -1, -1, -1, -1, - -1, -1, -1, -1, 514, -1, -1, -1, -1, -1, + 292, -1, -1, 295, -1, -1, -1, -1, -1, -1, + -1, 177, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 275, -1, -1, 278, -1, -1, 194, -1, + -1, -1, -1, 199, -1, -1, -1, -1, -1, 292, + -1, -1, 295, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 222, 223, -1, -1, + -1, -1, -1, 394, -1, -1, -1, -1, -1, -1, + -1, 237, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 502, -1, -1, 505, 506, 507, + -1, 509, 510, 511, 512, 513, 514, -1, -1, -1, + -1, 519, 394, -1, -1, -1, -1, -1, -1, 275, + -1, -1, 278, -1, -1, -1, -1, -1, -1, -1, + 8, -1, -1, 11, -1, -1, 292, 15, 16, 295, + -1, 19, 20, 21, -1, -1, -1, -1, -1, 8, + -1, 394, 11, -1, -1, -1, 15, 16, 17, 18, + 19, 20, 21, -1, -1, -1, -1, -1, 46, -1, + -1, -1, -1, -1, -1, 53, -1, 36, -1, -1, + -1, 502, -1, -1, 505, 506, 507, 46, 509, 510, + 511, 512, 513, 514, 53, -1, -1, -1, 519, -1, + -1, -1, 80, -1, -1, -1, 8, -1, -1, 11, + -1, -1, -1, 15, 16, 17, 18, 19, 20, 21, + 502, 80, -1, 505, 506, 507, -1, 509, 510, 511, + 512, 513, 514, -1, 36, -1, -1, 519, 394, -1, + -1, -1, -1, -1, 46, -1, -1, -1, -1, -1, + -1, 53, -1, -1, -1, -1, -1, -1, -1, 502, + -1, -1, 505, 506, 507, -1, 509, 510, 511, 512, + 513, 514, -1, -1, 517, -1, -1, -1, 80, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 177, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 194, -1, 177, -1, + -1, 199, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 194, -1, -1, -1, -1, + 199, -1, -1, -1, 222, 223, 502, -1, -1, 505, + 506, 507, -1, 509, 510, 511, 512, 513, 514, 237, + -1, 517, -1, 222, 223, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 177, -1, -1, 237, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 194, -1, -1, -1, -1, 199, -1, -1, + 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 292, -1, 275, -1, -1, 278, + 222, 223, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 292, -1, 237, 295, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 275, -1, -1, 278, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 292, -1, -1, 295, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 394, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 394, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 394, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 502, -1, -1, 505, 506, 507, + -1, 509, 510, 511, 512, 513, 514, -1, -1, -1, + -1, -1, -1, 502, -1, -1, 505, 506, 507, -1, + 509, 510, 511, 512, 513, 514, -1, -1, 517, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 3, -1, -1, + 502, -1, -1, 505, 506, 507, -1, 509, 510, 511, + 512, 513, 514, -1, -1, 517, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, + 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, + 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, + 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, + 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, + 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, + 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, + 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, + 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, + 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, + 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, + 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, + 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, + 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, + 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, + 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, + 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, + 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, + -1, -1, -1, -1, -1, 511, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, + 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 43, 44, -1, 46, + 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, + 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, + 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, + 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, + 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, + 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, + -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, + -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, + 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, + -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, + 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, + -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, + -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, + 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, + 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, + -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, + 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, + 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, + -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, + 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, + 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, + -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, + 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, -1, -1, + -1, -1, 319, 320, 321, -1, 323, 324, 325, 326, + 327, 328, -1, 330, 331, 332, 333, 334, 335, -1, + 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, + -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, -1, 362, 363, -1, 365, 366, + 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, + 377, 378, 379, 380, 381, -1, -1, 384, 385, 386, + 387, 388, 389, 390, 391, 392, -1, -1, 395, 396, + 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, -1, -1, + 417, 418, -1, 420, -1, 422, 423, 424, 425, 426, + -1, 428, 429, 430, -1, -1, 433, 434, 435, 436, + 437, -1, 439, 440, 441, 442, 443, 444, 445, 446, + -1, -1, 449, 450, 451, -1, 453, 454, 455, 456, + -1, 458, 459, 460, 461, 462, 463, 464, 465, -1, + 467, -1, 469, 470, 471, 472, 473, 474, 475, -1, + -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, + 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, + 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, + -1, -1, -1, -1, 511, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 43, 44, -1, -1, 47, + -1, -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, @@ -16561,7 +16370,7 @@ static const yytype_int16 yycheck[] = 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, - 178, 179, 180, -1, 182, 183, 184, 185, -1, 187, + 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, @@ -16574,470 +16383,316 @@ static const yytype_int16 yycheck[] = -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, -1, -1, - -1, -1, 320, 321, 322, -1, 324, 325, 326, 327, - 328, 329, -1, 331, 332, 333, 334, 335, 336, -1, - 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - -1, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, -1, 363, 364, -1, 366, 367, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, 321, -1, 323, 324, 325, 326, 327, + 328, -1, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, - 378, 379, 380, 381, 382, -1, -1, 385, 386, 387, - 388, 389, 390, 391, 392, 393, -1, -1, 396, 397, - 398, 399, -1, 401, 402, 403, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, -1, - -1, 419, 420, -1, 422, -1, 424, 425, 426, 427, - 428, -1, 430, 431, 432, -1, -1, 435, 436, 437, - 438, 439, -1, 441, 442, 443, 444, 445, 446, 447, - 448, -1, -1, 451, 452, 453, -1, -1, 456, 457, - 458, 459, -1, 461, 462, 463, 464, 465, 466, 467, - 468, -1, 470, -1, 472, 473, 474, 475, 476, 477, - 478, -1, -1, 481, -1, -1, 484, 485, 486, 487, + 378, 379, 380, 381, -1, -1, 384, 385, 386, 387, + 388, 389, 390, 391, 392, -1, -1, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, -1, -1, 417, + 418, -1, 420, -1, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, 435, 436, 437, + -1, 439, 440, 441, 442, 443, 444, 445, 446, -1, + -1, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, 463, 464, 465, -1, 467, + -1, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 503, 504, 3, 4, 5, - -1, -1, -1, 9, -1, -1, 514, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, - 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, - -1, 37, -1, -1, -1, -1, 42, 43, 44, -1, - 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, - -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, - 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, - 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, - 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, - -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, - 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, - 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, - 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, - 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, - 176, 177, 178, 179, 180, -1, 182, 183, 184, 185, - -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, - 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, - 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, - 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, - 276, 277, 278, 279, -1, 281, 282, 283, 284, 285, - 286, -1, 288, 289, 290, -1, 292, 293, 294, -1, - -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - -1, -1, -1, -1, 320, 321, 322, 323, 324, 325, - 326, 327, 328, 329, -1, 331, 332, 333, 334, 335, - 336, -1, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, -1, 349, 350, 351, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, -1, 363, 364, 365, - 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, - 376, 377, 378, 379, 380, 381, 382, -1, 384, 385, - 386, 387, 388, 389, 390, 391, 392, 393, -1, 395, - 396, 397, 398, 399, -1, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, -1, -1, 419, 420, -1, 422, 423, 424, 425, - 426, 427, 428, -1, 430, 431, 432, -1, -1, 435, - 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, -1, -1, 451, 452, 453, 454, -1, - 456, 457, 458, 459, -1, 461, 462, 463, 464, 465, - 466, 467, 468, -1, 470, 471, 472, 473, 474, 475, - 476, 477, 478, -1, -1, 481, -1, -1, 484, 485, - 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 503, 504, -1, - -1, 8, -1, -1, 11, -1, 512, 513, 15, 16, - 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 36, - -1, -1, -1, -1, 41, -1, -1, -1, -1, 46, - 8, -1, -1, 11, -1, -1, 53, 15, 16, 17, - 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 36, -1, - -1, -1, -1, 80, -1, -1, -1, -1, 46, 8, - -1, -1, 11, -1, -1, 53, 15, 16, 17, 18, - 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 36, -1, -1, - -1, -1, 80, -1, -1, -1, -1, 46, -1, 126, - -1, -1, -1, -1, 53, -1, -1, -1, 8, -1, - -1, 11, -1, -1, -1, 15, 16, 17, 18, 19, - 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 80, -1, -1, -1, -1, 36, -1, -1, -1, - 40, -1, -1, -1, -1, -1, 46, -1, 8, -1, - 177, 11, -1, 53, -1, 15, 16, 17, 18, 19, - 20, 21, -1, -1, -1, -1, -1, 194, -1, -1, - -1, -1, 199, -1, -1, -1, 36, -1, -1, 167, - 80, -1, -1, -1, 172, -1, 46, -1, -1, 177, - -1, -1, -1, 53, -1, 222, 223, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 194, -1, -1, -1, - 237, 199, -1, -1, -1, -1, -1, 166, -1, -1, - 80, -1, -1, -1, -1, -1, -1, -1, 177, -1, - -1, -1, -1, -1, 222, 223, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 194, -1, -1, 275, 237, - 199, 278, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 292, -1, -1, 295, -1, - -1, -1, -1, 222, 223, -1, -1, 177, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 275, 237, -1, - 278, -1, -1, -1, 194, -1, -1, -1, -1, 199, - -1, -1, -1, -1, 292, -1, -1, 295, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 177, -1, -1, - -1, -1, 222, 223, -1, -1, 275, -1, -1, 278, - -1, -1, -1, -1, 194, -1, -1, 237, -1, 199, - -1, -1, -1, 292, -1, -1, 295, -1, -1, -1, + 498, 499, 500, 501, 3, 4, 5, -1, -1, -1, + 9, -1, -1, 511, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, + 29, -1, 31, 32, 33, -1, -1, -1, 37, -1, + -1, -1, -1, 42, 43, 44, -1, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, + 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, + 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, + 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, + 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, + -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, + 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, + -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, + 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, + 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, + -1, 170, 171, -1, 173, 174, 175, 176, 177, 178, + -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, + 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, + -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, + 209, 210, 211, 212, 213, 214, 215, 216, 217, -1, + 219, -1, 221, 222, 223, 224, 225, 226, 227, 228, + 229, 230, 231, -1, -1, 234, 235, 236, 237, -1, + 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, + 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, + 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, + 269, 270, 271, 272, 273, 274, -1, 276, 277, 278, + 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, + 289, 290, -1, 292, 293, 294, -1, -1, 297, 298, + 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, + 309, 310, 311, 312, 313, 314, -1, -1, -1, -1, + 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, + -1, 330, 331, 332, 333, 334, 335, -1, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, -1, 348, + 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, -1, 362, 363, 364, 365, 366, 367, 368, + 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, + 379, 380, 381, -1, 383, 384, 385, 386, 387, 388, + 389, 390, 391, 392, -1, 394, 395, 396, 397, 398, + -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, -1, -1, 417, 418, + -1, 420, 421, 422, 423, 424, 425, 426, -1, 428, + 429, 430, -1, -1, 433, 434, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, -1, -1, + 449, 450, 451, -1, 453, 454, 455, 456, -1, 458, + 459, 460, 461, 462, 463, 464, 465, -1, 467, 468, + 469, 470, 471, 472, 473, 474, 475, -1, -1, 478, + -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, + 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 499, 500, 501, -1, -1, 8, -1, -1, 11, -1, + 509, 510, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 222, 223, -1, -1, -1, -1, 395, -1, - -1, -1, -1, -1, -1, 275, 325, 237, 278, -1, + -1, -1, -1, 36, -1, -1, -1, -1, 41, -1, + -1, -1, -1, 46, 8, -1, -1, 11, -1, -1, + 53, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 292, -1, -1, 295, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 395, -1, -1, - -1, -1, -1, -1, -1, 275, -1, -1, 278, -1, + -1, -1, 36, -1, -1, -1, -1, 80, -1, -1, + -1, -1, 46, 8, -1, -1, 11, -1, -1, 53, + 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 292, 460, -1, 295, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 395, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 319, + -1, 36, -1, -1, -1, -1, 80, -1, -1, -1, + -1, 46, -1, 126, -1, -1, -1, -1, 53, -1, + 8, -1, -1, 11, -1, -1, -1, 15, 16, 17, + 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 80, -1, -1, 36, -1, + -1, -1, 40, -1, -1, -1, -1, -1, 46, -1, + -1, -1, -1, -1, 177, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 505, -1, - -1, 508, 509, 510, -1, 512, 513, 514, 515, 516, - 517, -1, -1, -1, -1, 395, -1, -1, -1, -1, - -1, -1, 8, -1, -1, 11, -1, -1, -1, 15, - 16, 17, 18, 19, 20, 21, -1, 505, -1, -1, - 508, 509, 510, -1, 512, 513, 514, 515, 516, 517, - 36, -1, -1, -1, 40, 395, -1, -1, -1, -1, - 46, -1, -1, -1, -1, -1, -1, 53, -1, -1, - -1, -1, -1, -1, -1, -1, 505, -1, -1, 508, - 509, 510, -1, 512, 513, 514, 515, 516, 517, -1, - -1, -1, -1, -1, 80, -1, -1, -1, -1, -1, + -1, 194, -1, -1, -1, -1, 199, -1, -1, -1, + -1, -1, 80, 167, -1, -1, -1, -1, 172, -1, + -1, -1, -1, 177, -1, -1, -1, -1, -1, 222, + 223, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 194, -1, -1, -1, 237, 199, -1, -1, -1, -1, + -1, 166, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 177, -1, -1, -1, -1, -1, 222, 223, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 194, + -1, -1, 275, 237, 199, 278, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, + -1, -1, 295, -1, -1, -1, -1, 222, 223, 177, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 8, -1, -1, 11, -1, -1, -1, 15, 16, 17, - 18, 19, 20, 21, -1, 505, -1, -1, 508, 509, - 510, -1, 512, 513, 514, 515, 516, 517, 36, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 46, -1, - -1, -1, -1, -1, -1, 53, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 505, -1, -1, 508, 509, - 510, -1, 512, 513, 514, 515, 516, 517, -1, -1, - -1, -1, 80, -1, -1, -1, -1, 8, -1, -1, - 11, 177, -1, -1, 15, 16, 17, 18, 19, 20, - 21, -1, -1, -1, -1, -1, -1, -1, 194, -1, - -1, -1, -1, 199, -1, 36, -1, -1, -1, 40, - -1, -1, -1, -1, -1, 46, -1, -1, -1, -1, - -1, -1, 53, -1, -1, -1, 222, 223, -1, -1, + -1, 275, 237, -1, 278, -1, 194, -1, -1, -1, + -1, 199, -1, -1, -1, -1, -1, -1, 292, -1, + -1, 295, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 222, 223, -1, -1, -1, -1, + 275, -1, -1, 278, -1, -1, -1, -1, -1, 237, + -1, -1, -1, -1, -1, -1, -1, 292, -1, -1, + 295, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 394, -1, -1, -1, -1, -1, 275, -1, 324, + 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 292, -1, -1, 295, -1, -1, + -1, -1, -1, -1, -1, 8, -1, -1, 11, -1, + 394, -1, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 237, -1, -1, -1, -1, -1, -1, -1, 80, + -1, -1, -1, 36, 457, -1, -1, -1, -1, -1, + -1, -1, -1, 46, -1, -1, -1, -1, -1, 394, + 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 172, 8, -1, -1, 11, 177, - -1, -1, 15, 16, 17, 18, 19, 20, 21, 275, - -1, -1, 278, -1, -1, -1, 194, -1, -1, -1, - -1, 199, -1, 36, -1, -1, 292, -1, -1, 295, - -1, -1, -1, 46, -1, -1, -1, -1, -1, -1, - 53, -1, -1, -1, 222, 223, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 237, - -1, -1, -1, -1, -1, -1, -1, 80, -1, -1, - -1, -1, -1, -1, -1, -1, 177, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 80, -1, 502, + -1, -1, 505, 506, 507, -1, 509, 510, 511, 512, + 513, 514, -1, -1, -1, -1, 394, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 194, -1, -1, -1, 275, 199, 8, - 278, -1, 11, -1, -1, -1, 15, 16, 17, 18, - 19, 20, 21, -1, 292, -1, -1, 295, -1, -1, - -1, 222, 223, -1, -1, -1, -1, 36, -1, 395, - -1, -1, -1, -1, -1, -1, 237, 46, -1, -1, - -1, -1, -1, -1, 53, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 167, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 502, -1, + -1, 505, 506, 507, -1, 509, 510, 511, 512, 513, + 514, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 502, -1, -1, + 505, 506, 507, -1, 509, 510, 511, 512, 513, 514, -1, -1, -1, -1, 177, -1, -1, -1, -1, -1, - -1, 80, -1, -1, 275, -1, -1, 278, -1, -1, - -1, 194, -1, -1, -1, -1, 199, -1, -1, -1, - -1, 292, -1, -1, 295, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 222, - 223, -1, -1, -1, -1, -1, -1, 395, -1, -1, - -1, -1, -1, -1, 237, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 505, - -1, -1, 508, 509, 510, -1, 512, 513, 514, 515, - 516, 517, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 275, -1, -1, 278, -1, -1, 177, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 292, - -1, -1, 295, -1, -1, 194, -1, -1, -1, -1, - 199, -1, -1, -1, 395, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 222, 223, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 505, 237, -1, - 508, 509, 510, -1, 512, 513, 514, 515, 516, 517, + 8, 194, -1, 11, -1, -1, 199, 15, 16, 17, + 18, 19, 20, 21, 502, -1, -1, 505, 506, 507, + -1, 509, 510, 511, 512, 513, 514, -1, 36, 222, + 223, -1, 40, -1, -1, -1, -1, -1, 46, -1, + -1, -1, -1, -1, 237, 53, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 8, -1, -1, 11, - -1, -1, -1, 15, 16, 17, 18, 19, 20, 21, - -1, -1, -1, -1, -1, -1, 275, -1, -1, 278, - -1, -1, -1, -1, 36, -1, -1, -1, 40, -1, - -1, -1, 395, 292, 46, -1, 295, -1, -1, -1, + -1, -1, 80, 15, 16, 17, 18, 19, 20, 21, + -1, -1, 275, -1, -1, 278, -1, -1, -1, -1, + -1, -1, -1, -1, 36, -1, -1, -1, -1, 292, + -1, -1, 295, -1, 46, -1, -1, -1, -1, -1, -1, 53, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 505, -1, -1, 508, 509, 510, - -1, 512, 513, 514, 515, 516, 517, -1, 80, -1, - -1, -1, -1, -1, -1, -1, 8, -1, -1, 11, - -1, -1, -1, 15, 16, 17, 18, 19, 20, 21, + -1, -1, -1, -1, -1, 318, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 36, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 46, -1, -1, -1, -1, -1, - -1, 53, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 395, -1, -1, -1, - -1, -1, 505, -1, -1, 508, 509, 510, 80, 512, - 513, 514, 515, 516, 517, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 8, 177, -1, 11, -1, -1, - 429, 15, 16, 17, 18, 19, 20, 21, -1, -1, - -1, -1, 194, -1, -1, -1, -1, 199, -1, -1, - -1, -1, 36, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 46, -1, -1, -1, -1, -1, -1, 53, - 222, 223, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 237, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 80, -1, -1, -1, - -1, -1, -1, -1, -1, 177, 505, -1, -1, 508, - 509, 510, -1, 512, 513, 514, 515, 516, 517, -1, - -1, -1, 194, 275, -1, -1, 278, 199, -1, -1, + -1, -1, -1, -1, -1, 8, -1, -1, 11, -1, + -1, -1, 15, 16, 17, 18, 19, 20, 21, 177, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 292, -1, -1, 295, -1, -1, -1, -1, -1, -1, - 222, 223, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 8, 237, -1, 11, -1, -1, - -1, 15, 16, 17, 18, 19, 20, 21, -1, -1, + -1, -1, -1, 36, -1, -1, 194, 40, -1, -1, + -1, 199, -1, 46, -1, -1, -1, -1, -1, -1, + 53, 394, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 222, 223, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 80, -1, 237, + 172, -1, -1, -1, -1, 177, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 36, 177, -1, -1, -1, -1, -1, -1, - -1, -1, 46, 275, -1, -1, 278, -1, -1, 53, - 194, -1, -1, -1, -1, 199, -1, -1, -1, -1, + -1, -1, 194, -1, -1, -1, -1, 199, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 275, -1, -1, + 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 222, 223, -1, -1, 292, -1, -1, 295, -1, -1, + -1, -1, -1, -1, -1, 237, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 502, + -1, -1, 505, 506, 507, -1, 509, 510, 511, 512, + 513, 514, -1, -1, 177, -1, -1, -1, -1, -1, + -1, -1, -1, 275, -1, -1, 278, -1, -1, -1, + -1, 194, -1, -1, -1, -1, 199, -1, -1, -1, 292, -1, -1, 295, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 80, -1, 222, 223, - -1, -1, -1, 395, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 237, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 275, -1, -1, 278, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 292, -1, - -1, 295, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 395, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 177, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 8, -1, -1, 11, -1, 222, + 223, 15, 16, 17, 18, 19, 20, 21, -1, -1, + -1, -1, -1, -1, 237, -1, 394, -1, -1, -1, + -1, -1, 36, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 46, -1, -1, -1, -1, -1, -1, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 194, -1, -1, 505, -1, 199, 508, 509, 510, -1, - 512, 513, 514, 515, 516, 517, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 222, 223, + -1, 8, 275, -1, 11, 278, -1, -1, 15, 16, + 17, 18, 19, 20, 21, -1, 80, -1, -1, 292, + -1, -1, 295, -1, -1, -1, -1, -1, -1, 36, + -1, -1, 394, -1, -1, -1, -1, -1, -1, 46, + -1, -1, -1, -1, -1, -1, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 395, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 80, 502, -1, -1, 505, 506, 507, + -1, 509, 510, 511, 512, 513, 514, -1, 8, -1, + -1, 11, -1, -1, -1, 15, 16, 17, 18, 19, + 20, 21, -1, 167, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 177, -1, -1, 36, -1, -1, -1, + 40, 394, -1, -1, -1, -1, 46, -1, -1, -1, + 194, -1, -1, 53, -1, 199, -1, -1, -1, -1, + 502, -1, -1, 505, 506, 507, -1, 509, 510, 511, + 512, 513, 514, -1, -1, -1, -1, -1, 222, 223, + 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 177, -1, -1, 237, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 194, -1, -1, + -1, -1, 199, -1, -1, -1, -1, 8, -1, -1, + 11, -1, -1, -1, 15, 16, 17, 18, 19, 20, + 21, 275, -1, -1, 278, 222, 223, -1, -1, -1, + -1, -1, -1, -1, -1, 36, -1, -1, 292, 502, + 237, 295, 505, 506, 507, 46, 509, 510, 511, 512, + 513, 514, 53, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 177, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 275, 80, + -1, 278, -1, -1, 194, -1, -1, -1, -1, 199, + -1, -1, -1, -1, -1, 292, -1, -1, 295, -1, + -1, -1, -1, -1, -1, -1, -1, 8, -1, -1, + 11, -1, 222, 223, 15, 16, 17, 18, 19, 20, + 21, -1, -1, -1, -1, -1, -1, 237, -1, -1, + -1, -1, -1, -1, -1, 36, -1, -1, -1, -1, + 394, -1, -1, -1, -1, 46, -1, -1, -1, -1, + -1, -1, 53, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 275, -1, -1, 278, -1, + -1, -1, -1, -1, -1, -1, 177, -1, -1, 80, + -1, -1, 292, -1, -1, 295, -1, -1, -1, -1, + -1, -1, -1, 194, -1, -1, 8, 394, 199, 11, + -1, -1, -1, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 275, -1, 505, 278, -1, 508, 509, 510, -1, - 512, 513, 514, 515, 516, 517, -1, -1, 292, -1, - -1, 295, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 222, 223, -1, 36, -1, -1, -1, -1, -1, + 427, -1, -1, -1, 46, -1, 237, -1, -1, -1, + -1, 53, -1, -1, -1, -1, -1, -1, 502, -1, + -1, 505, 506, 507, -1, 509, 510, 511, 512, 513, + 514, -1, -1, -1, -1, -1, -1, -1, 80, -1, + -1, -1, -1, -1, 275, -1, 177, 278, -1, -1, + -1, -1, -1, -1, 394, -1, -1, -1, -1, -1, + -1, 292, -1, 194, 295, -1, -1, -1, 199, -1, + -1, -1, -1, -1, -1, 502, -1, -1, 505, 506, + 507, -1, 509, 510, 511, 512, 513, 514, -1, -1, + -1, 222, 223, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 177, -1, -1, -1, -1, + -1, -1, -1, -1, 275, -1, -1, 278, -1, -1, + -1, -1, 194, -1, -1, -1, -1, 199, -1, -1, + -1, 292, 502, 394, 295, 505, 506, 507, -1, 509, + 510, 511, 512, 513, 514, -1, -1, -1, -1, -1, + 222, 223, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 275, -1, -1, 278, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 505, -1, -1, 508, 509, 510, -1, 512, 513, - 514, 515, 516, 517, -1, -1, -1, -1, -1, -1, + 292, -1, -1, 295, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 394, -1, -1, -1, -1, -1, -1, + -1, 502, -1, -1, 505, 506, 507, -1, 509, 510, + 511, 512, 513, 514, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 395, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 394, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 502, -1, -1, 505, 506, 507, -1, 509, 510, + 511, 512, 513, 514, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 3, -1, 5, -1, -1, - -1, 505, -1, -1, 508, 509, 510, -1, 512, 513, - 514, 515, 516, 517, 22, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, - 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, - 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, - 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, - 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, - 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, - 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, - 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, - 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, - 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, - 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, - 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, - 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, - 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, - 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, - 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, - 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, - 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, - 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, - 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, - 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, - 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, - 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, - 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, - 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, - 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, - 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, - 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, - 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 503, 504, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, - 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, - 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, - 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, - 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, - 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, - 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, - 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, - 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, - 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, - 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, - 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, - 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, - 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, - 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, - 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, - 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, - 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, - 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, - 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, - 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, - 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, - 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, - 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, - 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, - 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, - 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, - 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, - 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, - 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, - 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, - 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, - 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, - 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, - 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, - 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, - 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, - 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, - 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, - 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, - 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, - 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, - 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, - 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, - 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, - 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, - 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, - 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, - 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, - 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, - 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, - 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, - 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, - 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, - 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, - 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, - 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, - 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, - 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, - 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, - 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, - 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, - 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, - 504, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, - 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, - 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, - 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, - 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, - 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, - 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, - 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, - 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, - 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, - 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, - 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, - 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, - 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, - 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, - 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, - 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, - 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, - 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, - 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, - 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, - 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, - 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, - 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, - 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, - 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, - 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, - 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, - 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, - 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, - 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, - 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, - 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, - 502, 503, 504, 3, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 3, -1, 5, -1, -1, -1, + 502, -1, -1, 505, 506, 507, -1, 509, 510, 511, + 512, 513, 514, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, + 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, + 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, + 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, + 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, + 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, + 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, + 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, + 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, + 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, + 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, + 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, + 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, + 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, + 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, + 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, + 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, + 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, + 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, + 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, + 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, + 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, + 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, + 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, + 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, + 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, + 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, + 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, + 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, + 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, + 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, + 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, + 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, @@ -17087,114 +16742,163 @@ static const yytype_int16 yycheck[] = 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 503, 504, 3, -1, 5, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, - 28, 29, -1, 31, 32, 33, -1, -1, -1, 37, - -1, -1, -1, -1, 42, 43, 44, -1, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, - 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, - 78, 79, -1, 81, -1, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, -1, 94, 95, 96, 97, - 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, - 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, - 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, - 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, - 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, - 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, - 168, -1, 170, 171, -1, 173, 174, 175, 176, 177, - 178, 179, 180, -1, 182, 183, 184, 185, -1, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, - 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, - 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, - -1, 219, -1, 221, 222, 223, 224, 225, 226, 227, - 228, 229, 230, 231, -1, -1, 234, 235, 236, 237, - -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, 269, 270, 271, 272, 273, 274, -1, 276, 277, - 278, 279, -1, 281, 282, 283, 284, 285, 286, -1, - 288, 289, 290, -1, 292, 293, 294, -1, -1, 297, - 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, -1, -1, - -1, -1, 320, 321, 322, 323, 324, 325, 326, 327, - 328, 329, -1, 331, 332, 333, 334, 335, 336, -1, - 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - -1, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, -1, 363, 364, 365, 366, 367, - 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, - 378, 379, 380, 381, 382, -1, 384, 385, 386, 387, - 388, 389, 390, 391, 392, 393, -1, 395, 396, 397, - 398, 399, -1, 401, 402, 403, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, -1, - -1, 419, 420, -1, 422, 423, 424, 425, 426, 427, - 428, -1, 430, 431, 432, -1, -1, 435, 436, 437, - 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, - 448, -1, -1, 451, 452, 453, 454, -1, 456, 457, - 458, 459, -1, 461, 462, 463, 464, 465, 466, 467, - 468, -1, 470, 471, 472, 473, 474, 475, 476, 477, - 478, -1, -1, 481, -1, -1, 484, 485, 486, 487, - 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 503, 504, 3, -1, -1, + 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, - 26, 27, 28, 29, -1, 31, 32, 33, 34, 35, - -1, 37, -1, -1, -1, -1, 42, 43, 44, -1, - 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, - -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, - 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, - 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, - 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, - -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, - 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, - 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, - 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, - 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, - 176, 177, 178, 179, 180, -1, 182, 183, 184, 185, - -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, - 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, - 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, - 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, - 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, - 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, - 276, 277, 278, 279, -1, 281, 282, 283, 284, 285, - 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, - -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - -1, -1, -1, -1, 320, 321, 322, 323, 324, 325, - 326, 327, 328, 329, -1, 331, 332, 333, 334, 335, - 336, -1, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, -1, 349, 350, 351, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, -1, 363, 364, 365, - 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, - 376, 377, 378, 379, 380, 381, 382, -1, 384, 385, - 386, 387, 388, 389, 390, 391, 392, 393, -1, 395, - 396, 397, 398, 399, -1, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, -1, -1, 419, 420, -1, 422, 423, 424, 425, - 426, 427, 428, -1, 430, 431, 432, -1, -1, 435, - 436, 437, 438, 439, -1, 441, 442, 443, 444, 445, - 446, 447, 448, -1, -1, 451, 452, 453, 454, -1, - 456, 457, 458, 459, -1, 461, 462, 463, 464, 465, - 466, 467, 468, -1, 470, 471, 472, 473, 474, 475, - 476, 477, 478, -1, -1, 481, -1, -1, 484, 485, - 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 503, 504, 3, + -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, + 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, + 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, + 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, + 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, + 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, + 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, + 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, + 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, + 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, + 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, + 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, + 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, + 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, + 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, + 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, + 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, + 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, + 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, + 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, + 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, + 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, + 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, + 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, + 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, + 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, + 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, + 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, + 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, + 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, + 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, + 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, + 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, + 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, + 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, + 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, + 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, + 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, + 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, + 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, + 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, + 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, + 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, + 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, + 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, + 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, + 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, + 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, + 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, + 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, + 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, + 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, + 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, + 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, + 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, + 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, + 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, + 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, + 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, + 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, + 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, + 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, + 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, + 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, + 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, + 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, + -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, - -1, -1, -1, -1, -1, -1, -1, -1, 42, 43, + -1, -1, -1, 37, -1, -1, -1, -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, - 64, -1, 66, 67, 68, 69, 70, 71, 72, 73, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, @@ -17203,9 +16907,9 @@ static const yytype_int16 yycheck[] = 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, - 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, + 154, 155, 156, 157, 158, 159, 160, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, 173, - 174, 175, 176, 177, 178, 179, 180, -1, 182, 183, + 174, 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, 209, 210, 211, 212, 213, @@ -17216,488 +16920,237 @@ static const yytype_int16 yycheck[] = 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, 276, 277, 278, 279, -1, 281, 282, 283, - 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, + 284, 285, 286, -1, 288, 289, 290, -1, 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, -1, -1, -1, -1, 320, 321, 322, 323, - 324, 325, 326, 327, 328, 329, -1, 331, 332, 333, - 334, 335, 336, -1, 338, 339, 340, 341, 342, 343, - 344, 345, 346, 347, -1, 349, 350, 351, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, -1, 363, + 314, -1, -1, -1, -1, 319, 320, 321, 322, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, - 374, 375, 376, 377, 378, 379, 380, 381, 382, -1, - -1, 385, 386, 387, 388, 389, 390, 391, 392, 393, - -1, 395, 396, 397, 398, 399, -1, 401, 402, 403, + 374, 375, 376, 377, 378, 379, 380, 381, -1, 383, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - 414, 415, 416, -1, -1, 419, 420, -1, 422, 423, - 424, 425, 426, 427, 428, -1, 430, 431, 432, -1, - -1, 435, 436, 437, 438, 439, -1, 441, 442, 443, - 444, 445, 446, 447, 448, -1, -1, 451, 452, 453, - -1, -1, 456, 457, 458, 459, -1, 461, 462, 463, - 464, 465, 466, 467, 468, -1, 470, 471, 472, 473, - 474, 475, 476, 477, 478, -1, -1, 481, -1, -1, + 414, -1, -1, 417, 418, -1, 420, 421, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, -1, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, 468, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, - 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, - 504, 3, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, - 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, - 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, - 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, - 72, 73, -1, 75, 76, 77, 78, 79, -1, 81, - -1, 83, 84, 85, 86, 87, 88, 89, 90, 91, - 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, - 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, - 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, - -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, - 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, - 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, - -1, 163, 164, 165, 166, -1, 168, -1, 170, 171, - -1, 173, 174, 175, 176, 177, 178, 179, 180, -1, - 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, - 202, 203, 204, 205, 206, -1, 208, 209, 210, 211, - 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, - 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, - -1, -1, 234, 235, 236, 237, -1, 239, 240, 241, - 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, - 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, - 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, - 272, 273, 274, -1, 276, 277, 278, 279, -1, 281, - 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, - 292, 293, 294, -1, -1, 297, 298, 299, 300, 301, - 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, - 312, 313, 314, 315, -1, -1, -1, -1, 320, 321, - 322, 323, 324, 325, 326, 327, 328, 329, -1, 331, - 332, 333, 334, 335, 336, -1, 338, 339, 340, 341, - 342, 343, 344, 345, 346, 347, -1, 349, 350, 351, - 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, - -1, 363, 364, 365, 366, 367, 368, 369, 370, 371, - 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, - 382, -1, -1, 385, 386, 387, 388, 389, 390, 391, - 392, 393, -1, 395, 396, 397, 398, 399, -1, 401, - 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, - 412, 413, 414, 415, 416, -1, -1, 419, 420, -1, - 422, 423, 424, 425, 426, 427, 428, -1, 430, 431, - 432, -1, -1, 435, 436, 437, 438, 439, -1, 441, - 442, 443, 444, 445, 446, 447, 448, -1, -1, 451, - 452, 453, -1, -1, 456, 457, 458, 459, -1, 461, - 462, 463, 464, 465, 466, 467, 468, -1, 470, 471, - 472, 473, 474, 475, 476, 477, 478, -1, -1, 481, - -1, -1, 484, 485, 486, 487, 488, 489, 490, 491, - 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, - 502, 503, 504, 3, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, - -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 43, 44, -1, -1, 47, 48, -1, - 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, - 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, - 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, - -1, -1, 82, 83, 84, 85, 86, 87, 88, -1, - 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, - -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, - 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, - 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, - 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, - 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - -1, 161, -1, 163, 164, 165, 166, -1, 168, 169, - 170, -1, -1, -1, 174, 175, 176, -1, 178, 179, - 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, - 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, - 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, - 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, - -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, - 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, - 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, - 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, - 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, - -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, - -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, - -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, - 310, 311, 312, 313, 314, 315, -1, -1, -1, -1, - 320, 321, 322, -1, 324, 325, 326, 327, 328, 329, - 330, 331, 332, 333, 334, 335, 336, -1, 338, 339, - 340, 341, 342, 343, 344, 345, 346, 347, -1, 349, - 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, - 360, 361, -1, 363, 364, -1, 366, 367, 368, 369, - 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, -1, -1, 385, 386, 387, 388, 389, - 390, 391, 392, 393, -1, -1, 396, 397, 398, 399, - -1, 401, 402, 403, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, -1, -1, 419, - 420, -1, 422, -1, 424, 425, 426, 427, 428, -1, - 430, 431, 432, -1, -1, 435, 436, 437, 438, 439, - -1, 441, 442, 443, 444, 445, 446, 447, 448, -1, - 450, 451, 452, 453, -1, -1, 456, 457, 458, 459, - -1, 461, 462, 463, 464, 465, 466, 467, 468, -1, - 470, -1, 472, 473, 474, 475, 476, 477, 478, -1, - -1, 481, -1, -1, 484, 485, 486, 487, 488, 489, - 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 503, 504, 3, -1, -1, -1, -1, + 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, - 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 43, 44, -1, -1, 47, - 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, - -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, - 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, - 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, - 88, -1, 90, 91, 92, 93, 94, 95, 96, 97, - 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, - 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, - 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, - 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, - 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, - 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, - 168, 169, 170, -1, -1, -1, 174, 175, 176, -1, - 178, 179, 180, -1, 182, 183, 184, 185, -1, 187, - 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, - 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, - 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, - -1, 219, -1, 221, -1, -1, 224, -1, 226, 227, - 228, 229, 230, 231, -1, -1, 234, -1, 236, 237, - -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, - 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, - -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, - 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, - 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, - 308, 309, 310, 311, 312, 313, 314, 315, -1, -1, - -1, -1, 320, 321, 322, -1, 324, 325, 326, 327, - 328, 329, 330, 331, 332, 333, 334, 335, 336, -1, - 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, - -1, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, -1, 363, 364, -1, 366, 367, - 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, - 378, 379, 380, 381, 382, -1, -1, 385, 386, 387, - 388, 389, 390, 391, 392, 393, -1, -1, 396, 397, - 398, 399, -1, 401, 402, 403, 404, 405, 406, 407, - 408, 409, 410, 411, 412, 413, 414, 415, 416, -1, - -1, 419, 420, -1, 422, -1, 424, 425, 426, 427, - 428, -1, 430, 431, 432, -1, -1, 435, 436, 437, - 438, 439, -1, 441, 442, 443, 444, 445, 446, 447, - 448, -1, 450, 451, 452, 453, -1, -1, 456, 457, - 458, 459, -1, 461, 462, 463, 464, 465, 466, 467, - 468, -1, 470, -1, 472, 473, 474, 475, 476, 477, - 478, -1, -1, 481, -1, -1, 484, 485, 486, 487, - 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 501, 502, 503, 504, 3, -1, 5, + -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, + 25, 26, 27, 28, 29, -1, 31, 32, 33, 34, + 35, -1, 37, -1, -1, -1, -1, 42, 43, 44, + -1, 46, 47, 48, 49, 50, 51, 52, 53, 54, + 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, + -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, 79, -1, 81, -1, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, + 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, + 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, + 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, + 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, + 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, + 175, 176, 177, 178, -1, 180, -1, 182, 183, 184, + 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, + 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, + 205, 206, -1, 208, 209, 210, 211, 212, 213, 214, + 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, + 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, + 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + -1, 276, 277, 278, 279, -1, 281, 282, 283, 284, + 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, + -1, -1, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + -1, -1, -1, -1, 319, 320, 321, 322, 323, 324, + 325, 326, 327, 328, -1, 330, 331, 332, 333, 334, + 335, -1, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, -1, 362, 363, 364, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, -1, 383, 384, + 385, 386, 387, 388, 389, 390, 391, 392, -1, 394, + 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + -1, -1, 417, 418, -1, 420, 421, 422, 423, 424, + 425, 426, -1, 428, 429, 430, -1, -1, 433, 434, + 435, 436, 437, -1, 439, 440, 441, 442, 443, 444, + 445, 446, -1, -1, 449, 450, 451, -1, 453, 454, + 455, 456, -1, 458, 459, 460, 461, 462, 463, 464, + 465, -1, 467, 468, 469, 470, 471, 472, 473, 474, + 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, + 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, + 495, 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, - 26, 27, 28, 29, -1, 31, 32, 33, 34, 35, - -1, -1, -1, -1, -1, -1, -1, 43, 44, -1, - -1, 47, 48, -1, 50, 51, 52, 53, 54, -1, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, -1, -1, -1, 42, 43, 44, -1, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, - -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, - 76, 77, 78, 79, -1, -1, -1, 83, 84, 85, - 86, 87, 88, -1, 90, 91, 92, -1, 94, 95, - 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, + 66, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, 81, -1, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, - 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, - 176, -1, 178, 179, 180, -1, 182, 183, 184, 185, - -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, + 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, + 176, 177, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, - 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, - 216, 217, -1, 219, -1, 221, -1, -1, 224, -1, - 226, 227, 228, 229, 230, 231, -1, -1, 234, -1, - 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, + 206, -1, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, + 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, + 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, - 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, + 266, 267, 268, 269, 270, 271, 272, 273, 274, -1, + 276, 277, 278, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, - -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - -1, -1, -1, -1, 320, 321, 322, -1, 324, 325, - 326, 327, 328, 329, -1, 331, 332, 333, 334, 335, - 336, -1, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, -1, 349, 350, 351, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, -1, 363, 364, -1, + -1, 297, 298, 299, 300, 301, 302, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, 322, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, - 376, 377, 378, 379, 380, 381, 382, -1, -1, 385, - 386, 387, 388, 389, 390, 391, 392, 393, -1, -1, - 396, 397, 398, 399, -1, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, - 416, -1, -1, 419, 420, -1, 422, -1, 424, 425, - 426, 427, 428, -1, 430, 431, 432, -1, -1, 435, - 436, 437, 438, 439, -1, 441, 442, 443, 444, 445, - 446, 447, 448, -1, -1, 451, 452, 453, -1, -1, - 456, 457, 458, 459, -1, 461, 462, 463, 464, 465, - 466, 467, 468, -1, 470, -1, 472, 473, 474, 475, - 476, 477, 478, -1, -1, 481, -1, -1, 484, 485, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, 394, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, 421, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, -1, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, 468, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, - 496, 497, 498, 499, 500, 501, 502, 503, 504, 3, + 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, - 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, - -1, -1, -1, 37, -1, -1, 40, -1, 42, 43, - 44, -1, 46, 47, 48, 49, 50, 51, 52, -1, - 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, - 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, - -1, 75, 76, 77, 78, -1, -1, 81, -1, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, -1, - 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, - 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, - 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, - 144, 145, 146, -1, 148, 149, 150, 151, -1, 153, - 154, 155, 156, 157, 158, -1, -1, 161, -1, 163, - 164, 165, 166, -1, 168, -1, 170, 171, -1, 173, - 174, 175, 176, 177, 178, 179, 180, -1, -1, -1, - 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, - 204, 205, 206, -1, 208, 209, -1, 211, 212, 213, - 214, 215, 216, 217, -1, 219, -1, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, -1, -1, - 234, 235, 236, 237, -1, 239, 240, 241, 242, 243, - 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, - 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, - -1, -1, 276, 277, 278, 279, -1, -1, 282, 283, - 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, - 294, -1, -1, 297, 298, -1, 300, 301, 302, -1, - 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, -1, -1, -1, -1, 320, 321, -1, 323, - 324, 325, -1, 327, 328, 329, -1, 331, 332, 333, - 334, 335, 336, -1, 338, 339, 340, 341, 342, 343, - 344, 345, 346, 347, -1, 349, 350, 351, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, -1, 363, - 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, - 374, 375, 376, 377, 378, 379, 380, 381, 382, -1, - 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, - -1, 395, 396, 397, 398, 399, -1, 401, 402, 403, - 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - 414, 415, -1, -1, -1, 419, 420, -1, 422, 423, - 424, 425, 426, 427, 428, -1, 430, 431, 432, -1, - -1, 435, 436, -1, 438, -1, -1, 441, 442, 443, - 444, 445, 446, 447, 448, 449, -1, 451, 452, 453, - 454, -1, 456, 457, 458, 459, -1, 461, 462, 463, - 464, 465, -1, 467, 468, -1, 470, 471, 472, 473, - 474, 475, 476, 477, 478, -1, -1, 481, -1, -1, - 484, 485, 486, 487, 488, 489, 3, -1, 5, -1, - -1, -1, -1, -1, -1, -1, -1, 501, 502, 503, - 504, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, + -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, + 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, + -1, -1, -1, -1, -1, 42, 43, 44, -1, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, + 77, 78, 79, -1, 81, -1, 83, 84, 85, 86, + 87, 88, 89, 90, 91, 92, -1, 94, 95, 96, + 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, + -1, 168, -1, 170, 171, -1, 173, 174, 175, 176, + 177, 178, -1, 180, -1, 182, 183, 184, 185, -1, + 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, + -1, 208, 209, 210, 211, 212, 213, 214, 215, 216, + 217, -1, 219, -1, 221, 222, 223, 224, 225, 226, + 227, 228, 229, 230, 231, -1, -1, 234, 235, 236, + 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, + 267, 268, 269, 270, 271, 272, 273, 274, -1, 276, + 277, 278, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, + 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, -1, -1, + -1, -1, 319, 320, 321, 322, 323, 324, 325, 326, + 327, 328, -1, 330, 331, 332, 333, 334, 335, -1, + 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, + -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, -1, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, + 377, 378, 379, 380, 381, -1, -1, 384, 385, 386, + 387, 388, 389, 390, 391, 392, -1, 394, 395, 396, + 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, -1, -1, + 417, 418, -1, 420, 421, 422, 423, 424, 425, 426, + -1, 428, 429, 430, -1, -1, 433, 434, 435, 436, + 437, -1, 439, 440, 441, 442, 443, 444, 445, 446, + -1, -1, 449, 450, 451, -1, 453, 454, 455, 456, + -1, 458, 459, 460, 461, 462, 463, 464, 465, -1, + 467, 468, 469, 470, 471, 472, 473, 474, 475, -1, + -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, - 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, 291, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, - 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, - 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, - 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, - -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, - -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, - 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, 291, 292, - 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, 5, -1, -1, -1, -1, -1, + 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, - 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, - 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, - 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, - -1, -1, 83, 84, 85, 86, 87, 88, -1, 90, - 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, - -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, - 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, - 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, - 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, - 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, - 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, - -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, - 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, - 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, - 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, - 221, -1, -1, 224, -1, 226, 227, 228, 229, 230, - 231, -1, -1, 234, -1, 236, -1, -1, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, - 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, - 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, - -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, - 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, - 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, - 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, - 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, - 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, 5, -1, -1, -1, + -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, + 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 43, 44, -1, 46, 47, + 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, + -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, + 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, + 78, 79, -1, -1, 82, 83, 84, 85, 86, 87, + 88, -1, 90, 91, 92, 93, 94, 95, 96, 97, + 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, + 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, + 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, + 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, + 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, + 168, 169, 170, -1, -1, -1, 174, 175, 176, -1, + 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, + 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, + 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, + 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, + -1, 219, -1, 221, -1, -1, 224, -1, 226, 227, + 228, 229, 230, 231, -1, -1, 234, -1, 236, -1, + -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, + -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, + 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, + 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, 321, -1, 323, 324, 325, 326, 327, + 328, 329, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, + 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 380, 381, -1, -1, 384, 385, 386, 387, + 388, 389, 390, 391, 392, -1, -1, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, -1, -1, 417, + 418, -1, 420, -1, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, 435, 436, 437, + -1, 439, 440, 441, 442, 443, 444, 445, 446, -1, + 448, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, 463, 464, 465, -1, 467, + -1, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, + 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, + 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, + -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, + 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, - -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, + -1, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, @@ -17705,195 +17158,94 @@ static const yytype_int16 yycheck[] = -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, + 169, 170, -1, -1, -1, 174, 175, 176, -1, 178, + -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, - 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, + 229, 230, 231, -1, -1, 234, -1, 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, 291, 292, 293, 294, -1, -1, 297, 298, + 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, + 309, 310, 311, 312, 313, 314, -1, -1, -1, -1, + 319, 320, 321, -1, 323, 324, 325, 326, 327, 328, + 329, 330, 331, 332, 333, 334, 335, -1, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, + 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, + 379, 380, 381, -1, -1, 384, 385, 386, 387, 388, + 389, 390, 391, 392, -1, -1, 395, 396, 397, 398, + -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, -1, -1, 417, 418, + -1, 420, -1, 422, 423, 424, 425, 426, -1, 428, + 429, 430, -1, -1, 433, 434, 435, 436, 437, -1, + 439, 440, 441, 442, 443, 444, 445, 446, -1, 448, + 449, 450, 451, -1, 453, 454, 455, 456, -1, 458, + 459, 460, 461, 462, 463, 464, 465, -1, 467, -1, + 469, 470, 471, 472, 473, 474, 475, -1, -1, 478, + -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, 5, -1, + 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, 421, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, - 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, - 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, - 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, - 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, - -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, - -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, - 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, 34, 35, -1, -1, -1, -1, + -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, + 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, -1, -1, -1, 174, 175, 176, -1, 178, -1, + 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, + 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, + 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, + 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, + -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, -1, -1, -1, -1, 319, + 320, 321, -1, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, -1, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, -1, -1, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, -1, -1, 417, 418, -1, + 420, -1, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, -1, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, -1, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, + -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, @@ -17906,7 +17258,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, + -1, -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, @@ -17920,131 +17272,180 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, -1, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, + -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + -1, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, -1, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, 5, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, - -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, - 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, - -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, - 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, - 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, 5, -1, + 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, + 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, + -1, 83, 84, 85, 86, 87, 88, -1, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, -1, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, + -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + -1, -1, 224, -1, 226, 227, 228, 229, 230, 231, + -1, -1, 234, -1, 236, -1, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, + 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, 291, + 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, + -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + -1, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, -1, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, -1, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, + 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, + 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, + 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, + 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, + 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, + 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, + -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, + 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, + -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, + -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, + 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, + 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, + -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, + 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, + 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, + 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, + 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, + -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, + -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, + 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, + 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, + 283, 284, 285, 286, -1, 288, 289, -1, 291, 292, + 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, -1, -1, -1, -1, 319, 320, 321, -1, + 323, 324, 325, 326, 327, 328, -1, 330, 331, 332, + 333, 334, 335, -1, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, -1, 362, + 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, -1, + -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, + -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, + 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, -1, -1, 417, 418, -1, 420, -1, 422, + 423, 424, 425, 426, -1, 428, 429, 430, -1, -1, + 433, 434, 435, 436, 437, -1, 439, 440, 441, 442, + 443, 444, 445, 446, -1, -1, 449, 450, 451, -1, + 453, 454, 455, 456, -1, 458, 459, 460, 461, 462, + 463, 464, 465, -1, 467, -1, 469, 470, 471, 472, + 473, 474, 475, -1, -1, 478, -1, -1, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, + -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, + 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, + 84, 85, 86, 87, 88, -1, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, + 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, + 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, + 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, + 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, + 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, + -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, + 224, -1, 226, 227, 228, 229, 230, 231, -1, -1, + 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, + 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, + 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, + 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, + 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, + 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, + 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, -1, -1, -1, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, -1, -1, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, -1, -1, 417, 418, -1, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, -1, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, -1, 481, 482, 483, + 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, + -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, @@ -18057,7 +17458,7 @@ static const yytype_int16 yycheck[] = 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, + 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, @@ -18068,183 +17469,82 @@ static const yytype_int16 yycheck[] = 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, + 285, 286, -1, 288, 289, -1, 291, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, + -1, -1, -1, -1, 319, 320, 321, -1, 323, 324, + 325, 326, 327, 328, -1, 330, 331, 332, 333, 334, + 335, -1, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, -1, 362, 363, -1, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, -1, -1, 384, + 385, 386, 387, 388, 389, 390, 391, 392, -1, -1, + 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, + -1, -1, 417, 418, -1, 420, -1, 422, 423, 424, + 425, 426, -1, 428, 429, 430, -1, -1, 433, 434, + 435, 436, 437, -1, 439, 440, 441, 442, 443, 444, + 445, 446, -1, -1, 449, 450, 451, -1, 453, 454, + 455, 456, -1, 458, 459, 460, 461, 462, 463, 464, + 465, -1, 467, -1, 469, 470, 471, 472, 473, 474, + 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, - 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, - 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, - 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, - -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, - -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, - 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, 5, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, - 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, - 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, - 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, - 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, - -1, -1, 83, 84, 85, 86, 87, 88, -1, 90, - 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, - -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, - 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, - 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, - 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, - 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, - 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, - -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, - 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, - 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, - 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, - 221, -1, -1, 224, -1, 226, 227, 228, 229, 230, - 231, -1, -1, 234, -1, 236, -1, -1, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, - 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, - 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, - -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, - 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, - 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, - 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, - 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, - 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, 5, -1, -1, -1, + 495, 496, 497, 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, - -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, - 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, - -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, - 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, - 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, 5, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 43, 44, -1, + 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, + 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, + -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, -1, -1, 83, 84, 85, + 86, 87, 88, -1, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, + 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, -1, -1, 224, -1, + 226, 227, 228, 229, 230, 231, -1, -1, 234, -1, + 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, + 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, -1, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, -1, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, -1, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, 419, 420, -1, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, -1, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, -1, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, + -1, -1, -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, @@ -18258,7 +17558,7 @@ static const yytype_int16 yycheck[] = -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, + -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, @@ -18271,181 +17571,80 @@ static const yytype_int16 yycheck[] = 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, + 307, 308, 309, 310, 311, 312, 313, 314, -1, -1, + -1, -1, 319, 320, 321, -1, 323, 324, 325, 326, + 327, 328, -1, 330, 331, 332, 333, 334, 335, -1, + 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, + -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, + 377, 378, 379, 380, 381, -1, -1, 384, 385, 386, + 387, 388, 389, 390, 391, 392, -1, -1, 395, 396, + 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, -1, -1, + 417, 418, -1, 420, -1, 422, 423, 424, 425, 426, + -1, 428, 429, 430, -1, -1, 433, 434, 435, 436, + 437, -1, 439, 440, 441, 442, 443, 444, 445, 446, + -1, -1, 449, 450, 451, -1, 453, 454, 455, 456, + -1, 458, 459, 460, 461, 462, 463, 464, 465, -1, + 467, -1, 469, 470, 471, 472, 473, 474, 475, -1, + -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, 40, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, -1, 40, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, - 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, - 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, - 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, - -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, - -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, - 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, -1, -1, -1, -1, -1, -1, + 497, 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 22, 23, 24, 25, 26, 27, 28, 29, 30, - 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, - 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, - 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, - 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, - -1, -1, 83, 84, 85, 86, 87, 88, -1, 90, - 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, - -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, - 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, - 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, - 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, - 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, - 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, - -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, - 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, - 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, - 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, - 221, -1, -1, 224, -1, 226, 227, 228, 229, 230, - 231, -1, -1, 234, -1, 236, -1, -1, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, - 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, - 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, - -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, - 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, - 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, - 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, - 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, - 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, 5, -1, -1, -1, + -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, + 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 43, 44, -1, 46, 47, + 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, + -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, + 88, -1, 90, 91, 92, -1, 94, 95, 96, 97, + 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, + 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, + 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, + 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, + 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, + 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, + 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, + 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, + 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, + 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, + -1, 219, -1, 221, -1, -1, 224, -1, 226, 227, + 228, 229, 230, 231, -1, -1, 234, -1, 236, -1, + -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, + -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, + 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, + 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, 321, -1, 323, 324, 325, 326, 327, + 328, -1, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, + 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 380, 381, -1, -1, 384, 385, 386, 387, + 388, 389, 390, 391, 392, -1, -1, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, -1, -1, 417, + 418, -1, 420, -1, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, 435, 436, 437, + -1, 439, 440, 441, 442, 443, 444, 445, 446, -1, + -1, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, 463, 464, 465, -1, 467, + -1, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, + 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, + 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, + 29, 30, 31, 32, 33, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, @@ -18459,7 +17658,7 @@ static const yytype_int16 yycheck[] = 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, + -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, @@ -18472,131 +17671,180 @@ static const yytype_int16 yycheck[] = 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, + 309, 310, 311, 312, 313, 314, -1, -1, -1, -1, + 319, 320, 321, -1, 323, 324, 325, 326, 327, 328, + -1, 330, 331, 332, 333, 334, 335, -1, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, + 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, + 379, 380, 381, -1, -1, 384, 385, 386, 387, 388, + 389, 390, 391, 392, -1, -1, 395, 396, 397, 398, + -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, -1, -1, 417, 418, + -1, 420, -1, 422, 423, 424, 425, 426, -1, 428, + 429, 430, -1, -1, 433, 434, 435, 436, 437, -1, + 439, 440, 441, 442, 443, 444, 445, 446, -1, -1, + 449, 450, 451, -1, 453, 454, 455, 456, -1, 458, + 459, 460, 461, 462, 463, 464, 465, -1, 467, -1, + 469, 470, 471, 472, 473, 474, 475, -1, -1, 478, + -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, 5, -1, + 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, - 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, + 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, -1, -1, -1, 174, 175, 176, -1, 178, -1, + 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, + 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, + 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, + 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, + -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, -1, -1, -1, -1, 319, + 320, 321, -1, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, -1, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, -1, -1, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, -1, -1, 417, 418, -1, + 420, -1, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, -1, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, -1, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, + 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, + 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + -1, -1, 83, 84, 85, 86, 87, 88, -1, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + -1, -1, -1, 174, 175, 176, -1, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, -1, -1, 224, -1, 226, 227, 228, 229, 230, + 231, -1, -1, 234, -1, 236, -1, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, + 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, + 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, -1, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, -1, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + -1, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, -1, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, + 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, + -1, 83, 84, 85, 86, 87, 88, -1, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, -1, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, + -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + -1, -1, 224, -1, 226, 227, 228, 229, 230, 231, + -1, -1, 234, -1, 236, -1, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, + 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, + -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + -1, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, -1, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, -1, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, + 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, @@ -18609,7 +17857,7 @@ static const yytype_int16 yycheck[] = -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, + -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, @@ -18623,178 +17871,80 @@ static const yytype_int16 yycheck[] = 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, + 313, 314, -1, -1, -1, -1, 319, 320, 321, -1, + 323, 324, 325, 326, 327, 328, -1, 330, 331, 332, + 333, 334, 335, -1, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, -1, 362, + 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, -1, + -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, + -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, - 31, 32, 33, -1, -1, -1, 37, -1, -1, -1, - -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, - 51, 52, -1, 54, 55, 56, 57, -1, 59, 60, - 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, - 71, 72, 73, -1, 75, 76, 77, 78, -1, -1, - 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, - 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, - 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, - 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, - 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, - 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, - 151, -1, 153, 154, 155, 156, 157, 158, -1, -1, - 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - 171, -1, 173, 174, 175, -1, 177, 178, 179, 180, - -1, -1, -1, 184, 185, -1, 187, 188, 189, 190, - 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, - 201, 202, 203, 204, 205, 206, -1, 208, 209, -1, - 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, - 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, - 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, - 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, - 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, - 271, 272, 273, -1, -1, 276, 277, 278, 279, -1, - -1, 282, 283, 284, 285, 286, -1, 288, 289, -1, - -1, 292, 293, 294, -1, -1, 297, 298, -1, 300, - 301, 302, -1, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, -1, 323, 324, 325, -1, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, - 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, 365, 366, 367, 368, 369, 370, - 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, 384, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, 395, 396, 397, 398, 399, -1, - 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, -1, -1, -1, 419, 420, - -1, 422, 423, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, -1, 438, -1, -1, - 441, 442, 443, 444, 445, 446, 447, 448, 449, -1, - 451, 452, 453, 454, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, -1, 467, 468, -1, 470, - 471, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 3, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 501, 502, 503, 504, -1, -1, -1, -1, 22, 23, + 413, 414, -1, -1, 417, 418, -1, 420, -1, 422, + 423, 424, 425, 426, -1, 428, 429, 430, -1, -1, + 433, 434, 435, 436, 437, -1, 439, 440, 441, 442, + 443, 444, 445, 446, -1, -1, 449, 450, 451, -1, + 453, 454, 455, 456, -1, 458, 459, 460, 461, 462, + 463, 464, 465, -1, 467, -1, 469, 470, 471, 472, + 473, 474, 475, -1, -1, 478, -1, -1, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, + -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, - -1, -1, -1, 37, -1, -1, -1, -1, 42, 43, - 44, -1, 46, 47, 48, 49, 50, 51, 52, -1, - 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, + 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, - -1, 75, 76, 77, 78, -1, -1, 81, -1, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, -1, - 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, + -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, + 84, 85, 86, 87, 88, -1, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, - 144, 145, 146, -1, 148, 149, 150, 151, -1, 153, - 154, 155, 156, 157, 158, -1, -1, 161, -1, 163, - 164, 165, 166, -1, 168, -1, 170, 171, -1, 173, - 174, 175, -1, 177, 178, 179, 180, -1, -1, -1, + 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, + 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, - 204, 205, 206, -1, 208, 209, -1, 211, 212, 213, - 214, 215, 216, 217, -1, 219, -1, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, -1, -1, - 234, 235, 236, 237, -1, 239, 240, 241, 242, 243, + -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, + 224, -1, 226, 227, 228, 229, 230, 231, -1, -1, + 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, - 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, - -1, -1, 276, 277, 278, 279, -1, -1, 282, 283, + 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, + 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, - 294, -1, -1, 297, 298, -1, 300, 301, 302, -1, + 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, - 314, 315, -1, -1, -1, -1, 320, 321, -1, 323, - 324, 325, -1, 327, 328, 329, -1, 331, 332, 333, - 334, 335, 336, -1, 338, 339, 340, 341, 342, 343, - 344, 345, 346, 347, -1, 349, 350, 351, 352, 353, - 354, 355, 356, 357, 358, 359, 360, 361, -1, 363, - 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, - 374, 375, 376, 377, 378, 379, 380, 381, 382, -1, - 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, - -1, 395, 396, 397, 398, 399, -1, 401, 402, 403, + 314, -1, -1, -1, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, -1, -1, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - 414, 415, -1, -1, -1, 419, 420, -1, 422, 423, - 424, 425, 426, 427, 428, -1, 430, 431, 432, -1, - -1, 435, 436, -1, 438, -1, -1, 441, 442, 443, - 444, 445, 446, 447, 448, 449, -1, 451, 452, 453, - 454, -1, 456, 457, 458, 459, -1, 461, 462, 463, - 464, 465, -1, 467, 468, -1, 470, 471, 472, 473, - 474, 475, 476, 477, 478, -1, -1, 481, -1, -1, - 484, 485, 486, 487, 488, 489, 3, -1, 5, -1, - -1, -1, -1, -1, -1, -1, -1, 501, 502, 503, - 504, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, + 414, -1, -1, 417, 418, -1, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, -1, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, -1, 481, 482, 483, + 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, + -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, @@ -18807,7 +17957,7 @@ static const yytype_int16 yycheck[] = 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, + 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, @@ -18821,80 +17971,279 @@ static const yytype_int16 yycheck[] = 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, + -1, -1, -1, -1, 319, 320, 321, -1, 323, 324, + 325, 326, 327, 328, -1, 330, 331, 332, 333, 334, + 335, -1, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, -1, 362, 363, -1, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, -1, -1, 384, + 385, 386, 387, 388, 389, 390, 391, 392, -1, -1, + 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, + -1, -1, 417, 418, -1, 420, -1, 422, 423, 424, + 425, 426, -1, 428, 429, 430, -1, -1, 433, 434, + 435, 436, 437, -1, 439, 440, 441, 442, 443, 444, + 445, 446, -1, -1, 449, 450, 451, -1, 453, 454, + 455, 456, -1, 458, 459, 460, 461, 462, 463, 464, + 465, -1, 467, -1, 469, 470, 471, 472, 473, 474, + 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, - 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, - 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, - 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, - 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, - 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, - -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, - -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, - 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, - 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, -1, -1, -1, -1, -1, -1, + 495, 496, 497, 498, 499, 500, 501, 3, -1, 5, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, + 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 43, 44, -1, + 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, + 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, + -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, + 76, 77, 78, 79, -1, -1, -1, 83, 84, 85, + 86, 87, 88, -1, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, + -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, + 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, + 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, + 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, + 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, -1, -1, 224, -1, + 226, 227, 228, 229, 230, 231, -1, -1, 234, -1, + 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, + 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, + 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, + -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, -1, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, -1, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, -1, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, -1, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, -1, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, -1, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, + 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, + -1, -1, -1, 40, -1, -1, 43, 44, -1, 46, + 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, + 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, + 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, + 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, + 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, + 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, + -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, + -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, + 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, + -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, + 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, + -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, + -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, + 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, + 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, + -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, + 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, + 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, + -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, + 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, + 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, + -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, + 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, -1, -1, + -1, -1, 319, 320, 321, -1, 323, 324, 325, 326, + 327, 328, -1, 330, 331, 332, 333, 334, 335, -1, + 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, + -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, -1, 362, 363, -1, 365, 366, + 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, + 377, 378, 379, 380, 381, -1, -1, 384, 385, 386, + 387, 388, 389, 390, 391, 392, -1, -1, 395, 396, + 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, -1, -1, + 417, 418, -1, 420, -1, 422, 423, 424, 425, 426, + -1, 428, 429, 430, -1, -1, 433, 434, 435, 436, + 437, -1, 439, 440, 441, 442, 443, 444, 445, 446, + -1, -1, 449, 450, 451, -1, 453, 454, 455, 456, + -1, 458, 459, 460, 461, 462, 463, 464, 465, -1, + 467, -1, 469, 470, 471, 472, 473, 474, 475, -1, + -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, + 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, + 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, + 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, + -1, -1, 40, -1, -1, 43, 44, -1, 46, 47, + 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, + -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, + 88, -1, 90, 91, 92, -1, 94, 95, 96, 97, + 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, + 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, + 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, + 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, + 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, + 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, + 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, + 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, + 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, + 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, + -1, 219, -1, 221, -1, -1, 224, -1, 226, 227, + 228, 229, 230, 231, -1, -1, 234, -1, 236, -1, + -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, + -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, + 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, + 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, 321, -1, 323, 324, 325, 326, 327, + 328, -1, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, + 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 380, 381, -1, -1, 384, 385, 386, 387, + 388, 389, 390, 391, 392, -1, -1, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, -1, -1, 417, + 418, -1, 420, -1, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, 435, 436, 437, + -1, 439, 440, 441, 442, 443, 444, 445, 446, -1, + -1, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, 463, 464, 465, -1, 467, + -1, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, + 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, + 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, + -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, + 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, + 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, + 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, + -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, + 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, + -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, + 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, + -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, + 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, + 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, + -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, + -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, + 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, + -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, + -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, + 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, + 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, + 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, + 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, + 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, + -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, + 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, + 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, + 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, + 309, 310, 311, 312, 313, 314, -1, -1, -1, -1, + 319, 320, 321, -1, 323, 324, 325, 326, 327, 328, + -1, 330, 331, 332, 333, 334, 335, -1, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, -1, 348, + 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, + 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, + 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, + 379, 380, 381, -1, -1, 384, 385, 386, 387, 388, + 389, 390, 391, 392, -1, -1, 395, 396, 397, 398, + -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, -1, -1, 417, 418, + -1, 420, -1, 422, 423, 424, 425, 426, -1, 428, + 429, 430, -1, -1, 433, 434, 435, 436, 437, -1, + 439, 440, 441, 442, 443, 444, 445, 446, -1, -1, + 449, 450, 451, -1, 453, 454, 455, 456, -1, 458, + 459, 460, 461, 462, 463, 464, 465, -1, 467, -1, + 469, 470, 471, 472, 473, 474, 475, -1, -1, 478, + -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, + 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, + 499, 500, 501, 3, -1, 5, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, + 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, -1, -1, -1, 174, 175, 176, -1, 178, -1, + 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, + 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, + 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, + 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, + -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, -1, -1, -1, -1, 319, + 320, 321, -1, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, -1, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, -1, -1, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, -1, -1, 417, 418, -1, + 420, -1, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, -1, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, -1, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, + -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, @@ -18907,7 +18256,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, + -1, -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, @@ -18921,181 +18270,80 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, -1, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, + -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, 390, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + -1, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, -1, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, - -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, - 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, - -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, - 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, - 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, + 501, 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, - 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, - -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, - -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, - 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, - 85, 86, 87, 88, -1, 90, 91, 92, -1, 94, - 95, 96, 97, 98, 99, -1, -1, 102, 103, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, - 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, - 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, - 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, - 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, - 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, - 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, - 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, - 215, 216, 217, -1, 219, -1, 221, -1, -1, 224, - -1, 226, 227, 228, 229, 230, 231, -1, -1, 234, - -1, 236, -1, -1, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, - 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, -1, 270, 271, 272, 273, 274, - -1, 276, 277, -1, 279, -1, 281, 282, 283, 284, - 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, - -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, - 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, + 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, + -1, 83, 84, 85, 86, 87, 88, -1, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, -1, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, + -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + -1, -1, 224, -1, 226, 227, 228, 229, 230, 231, + -1, -1, 234, -1, 236, -1, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, + 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, + -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + -1, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, -1, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, -1, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, + 3, -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 43, 44, -1, -1, 47, 48, -1, 50, 51, 52, + 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, @@ -19108,7 +18356,7 @@ static const yytype_int16 yycheck[] = -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, - -1, 174, 175, 176, -1, 178, 179, 180, -1, 182, + -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, @@ -19122,30 +18370,128 @@ static const yytype_int16 yycheck[] = 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, 322, - -1, 324, 325, 326, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, -1, 366, 367, 368, 369, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, -1, 385, 386, 387, 388, 389, 390, 391, 392, - 393, -1, -1, 396, 397, 398, 399, -1, 401, 402, + 313, 314, -1, -1, -1, -1, 319, 320, 321, -1, + 323, 324, 325, 326, 327, 328, -1, 330, 331, 332, + 333, 334, 335, -1, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, -1, 362, + 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, -1, + -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, + -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, -1, -1, 419, 420, -1, 422, - -1, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, 437, 438, 439, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, -1, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, 466, 467, 468, -1, 470, -1, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 490, 491, 492, - 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, - 503, 504, 3, -1, -1, -1, -1, -1, -1, -1, + 413, 414, -1, -1, 417, 418, -1, 420, -1, 422, + 423, 424, 425, 426, -1, 428, 429, 430, -1, -1, + 433, 434, 435, 436, 437, -1, 439, 440, 441, 442, + 443, 444, 445, 446, -1, -1, 449, 450, 451, -1, + 453, 454, 455, 456, -1, 458, 459, 460, 461, 462, + 463, 464, 465, -1, 467, -1, 469, 470, 471, 472, + 473, 474, 475, -1, -1, 478, -1, -1, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, + -1, 5, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, + 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, + 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, + 84, 85, 86, 87, 88, -1, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, + 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, + 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, + 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, + 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, + 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, + -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, + 224, -1, 226, 227, 228, 229, 230, 231, -1, -1, + 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, + 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, + 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, + 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, + 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, + 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, + 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, -1, -1, -1, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, -1, -1, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, -1, -1, 417, 418, -1, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, -1, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, -1, 481, 482, 483, + 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, + 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, + -1, -1, 37, -1, -1, 40, -1, 42, 43, 44, + -1, 46, 47, 48, 49, 50, 51, 52, -1, 54, + 55, 56, 57, -1, 59, 60, 61, 62, 63, 64, + -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, + 75, 76, 77, 78, -1, -1, 81, -1, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, -1, 94, + 95, 96, 97, 98, 99, -1, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, + 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, + 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, + 145, 146, -1, 148, 149, 150, 151, -1, 153, 154, + 155, 156, 157, 158, -1, -1, 161, -1, 163, 164, + 165, 166, -1, 168, -1, 170, 171, -1, 173, 174, + 175, 176, 177, 178, -1, 180, -1, -1, -1, 184, + 185, -1, 187, 188, 189, 190, 191, 192, 193, 194, + 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, + 205, 206, -1, 208, 209, -1, 211, 212, 213, 214, + 215, 216, 217, -1, 219, -1, 221, 222, 223, 224, + 225, 226, 227, 228, 229, 230, 231, -1, -1, 234, + 235, 236, 237, -1, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, + 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, -1, + -1, 276, 277, 278, 279, -1, -1, 282, 283, 284, + 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, + -1, -1, 297, 298, -1, 300, 301, 302, -1, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, + -1, -1, -1, -1, 319, 320, -1, 322, 323, 324, + -1, 326, 327, 328, -1, 330, 331, 332, 333, 334, + 335, -1, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, -1, 362, 363, 364, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, -1, 383, 384, + 385, 386, 387, 388, 389, 390, 391, 392, -1, 394, + 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, -1, + -1, -1, 417, 418, -1, 420, 421, 422, 423, 424, + 425, 426, -1, 428, 429, 430, -1, -1, 433, 434, + -1, 436, -1, -1, 439, 440, 441, 442, 443, 444, + 445, 446, 447, -1, 449, 450, 451, -1, 453, 454, + 455, 456, -1, 458, 459, 460, 461, 462, -1, 464, + 465, -1, 467, 468, 469, 470, 471, 472, 473, 474, + 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, + 485, 486, 3, -1, 5, -1, -1, -1, -1, -1, + -1, -1, -1, 498, 499, 500, 501, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, - 31, 32, 33, -1, -1, -1, -1, -1, -1, 40, - -1, -1, 43, 44, -1, -1, 47, 48, -1, 50, + 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, @@ -19158,7 +18504,7 @@ static const yytype_int16 yycheck[] = 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, - -1, -1, -1, 174, 175, 176, -1, 178, 179, 180, + -1, -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, @@ -19172,131 +18518,180 @@ static const yytype_int16 yycheck[] = 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, -1, -1, -1, -1, 320, - 321, 322, -1, 324, 325, 326, 327, 328, 329, -1, - 331, 332, 333, 334, 335, 336, -1, 338, 339, 340, - 341, 342, 343, 344, 345, 346, 347, -1, 349, 350, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, -1, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, - 361, -1, 363, 364, -1, 366, 367, 368, 369, 370, + -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, - 381, 382, -1, -1, 385, 386, 387, 388, 389, -1, - 391, 392, 393, -1, -1, 396, 397, 398, 399, -1, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, - 411, 412, 413, 414, 415, 416, -1, -1, 419, 420, - -1, 422, -1, 424, 425, 426, 427, 428, -1, 430, - 431, 432, -1, -1, 435, 436, 437, 438, 439, -1, - 441, 442, 443, 444, 445, 446, 447, 448, -1, -1, - 451, 452, 453, -1, -1, 456, 457, 458, 459, -1, - 461, 462, 463, 464, 465, 466, 467, 468, -1, 470, - -1, 472, 473, 474, 475, 476, 477, 478, -1, -1, - 481, -1, -1, 484, 485, 486, 487, 488, 489, 490, - 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, - 501, 502, 503, 504, 3, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, - 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, - -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, - 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, - 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, - 79, -1, -1, -1, 83, 84, 85, 86, 87, 88, - -1, 90, 91, 92, -1, 94, 95, 96, 97, 98, - 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, - -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, - 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, - -1, 140, 141, 142, -1, 144, 145, 146, -1, 148, - 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, - 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, - -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, 184, 185, -1, 187, 188, - 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, - -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, - -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, - 219, -1, 221, -1, -1, 224, -1, 226, 227, 228, - 229, 230, 231, -1, -1, 234, -1, 236, -1, -1, - 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, - 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, - -1, 270, 271, 272, 273, 274, -1, 276, 277, -1, - 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, - 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, - 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, 310, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, 341, 342, 343, 344, 345, 346, 347, -1, - 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, - 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 3, -1, -1, -1, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + -1, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, -1, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, - 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 43, 44, -1, -1, - 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, - 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, - 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, - 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, - 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, - 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, - 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, - -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, - -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, - 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, - -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, - 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, - -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, - -1, 178, 179, 180, -1, 182, 183, 184, 185, -1, - 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, - 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, - -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, - 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, - 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, - -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, - 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, - 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, - 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, - -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, - 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, - 307, 308, 309, 310, 311, 312, 313, 314, 315, -1, - -1, -1, -1, 320, 321, 322, -1, 324, 325, 326, - 327, 328, 329, -1, 331, 332, 333, 334, 335, 336, - -1, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, -1, 349, 350, 351, 352, 353, 354, 355, 356, - 357, 358, 359, 360, 361, -1, 363, 364, -1, 366, - 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, - 377, 378, 379, 380, 381, 382, -1, -1, 385, 386, - 387, 388, 389, 390, 391, 392, 393, -1, -1, 396, - 397, 398, 399, -1, 401, 402, 403, 404, 405, 406, - 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, - -1, -1, 419, 420, -1, 422, -1, 424, 425, 426, - 427, 428, -1, 430, 431, 432, -1, -1, 435, 436, - 437, 438, 439, -1, 441, 442, 443, 444, 445, 446, - 447, 448, -1, -1, 451, 452, 453, -1, -1, 456, - 457, 458, 459, -1, 461, 462, 463, 464, 465, 466, - 467, 468, -1, 470, -1, 472, 473, 474, 475, 476, - 477, 478, -1, -1, 481, -1, -1, 484, 485, 486, - 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, - 497, 498, 499, 500, 501, 502, 503, 504, 3, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, + 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, + -1, 83, 84, 85, 86, 87, 88, -1, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, -1, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, + -1, -1, 174, 175, 176, -1, 178, -1, 180, -1, + 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + -1, -1, 224, -1, 226, 227, 228, 229, 230, 231, + -1, -1, 234, -1, 236, -1, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, -1, 270, 271, + 272, 273, 274, -1, 276, 277, -1, 279, -1, 281, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, + -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, 321, + -1, 323, 324, 325, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, -1, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, -1, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, -1, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, 414, -1, -1, 417, 418, -1, 420, -1, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, 435, 436, 437, -1, 439, 440, 441, + 442, 443, 444, 445, 446, -1, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, 463, 464, 465, -1, 467, -1, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, + 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, + 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, + 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, + 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, + 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, + 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, + 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, + 83, 84, 85, 86, 87, 88, -1, 90, 91, 92, + -1, 94, 95, 96, 97, 98, 99, -1, -1, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, + 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, + -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, + -1, 144, 145, 146, -1, 148, 149, 150, 151, 152, + 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, + 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, + -1, 174, 175, 176, -1, 178, -1, 180, -1, 182, + 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, + 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, + 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, + 213, 214, 215, 216, 217, -1, 219, -1, 221, -1, + -1, 224, -1, 226, 227, 228, 229, 230, 231, -1, + -1, 234, -1, 236, -1, -1, 239, 240, 241, 242, + 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, + 263, 264, 265, 266, 267, 268, -1, 270, 271, 272, + 273, 274, -1, 276, 277, -1, 279, -1, 281, 282, + 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, + 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, -1, -1, -1, -1, 319, 320, 321, -1, + 323, 324, 325, 326, 327, 328, -1, 330, 331, 332, + 333, 334, 335, -1, 337, 338, 339, 340, 341, 342, + 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, + 353, 354, 355, 356, 357, 358, 359, 360, -1, 362, + 363, -1, 365, 366, 367, 368, 369, 370, 371, 372, + 373, 374, 375, 376, 377, 378, 379, 380, 381, -1, + -1, 384, 385, 386, 387, 388, 389, 390, 391, 392, + -1, -1, 395, 396, 397, 398, -1, 400, 401, 402, + 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, + 413, 414, -1, -1, 417, 418, -1, 420, -1, 422, + 423, 424, 425, 426, -1, 428, 429, 430, -1, -1, + 433, 434, 435, 436, 437, -1, 439, 440, 441, 442, + 443, 444, 445, 446, -1, -1, 449, 450, 451, -1, + 453, 454, 455, 456, -1, 458, 459, 460, 461, 462, + 463, 464, 465, -1, 467, -1, 469, 470, 471, 472, + 473, 474, 475, -1, -1, 478, -1, -1, 481, 482, + 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, + 493, 494, 495, 496, 497, 498, 499, 500, 501, 3, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, + 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, + 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, + 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, + 84, 85, 86, 87, 88, -1, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, -1, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, + 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, + 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, + 144, 145, 146, -1, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, + 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, + 174, 175, 176, -1, 178, -1, 180, -1, 182, 183, + 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, + -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, -1, -1, + 224, -1, 226, 227, 228, 229, 230, 231, -1, -1, + 234, -1, 236, -1, -1, 239, 240, 241, 242, 243, + 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, + 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, + 264, 265, 266, 267, 268, -1, 270, 271, 272, 273, + 274, -1, 276, 277, -1, 279, -1, 281, 282, 283, + 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, + 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, -1, -1, -1, -1, 319, 320, 321, -1, 323, + 324, 325, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + -1, 365, 366, 367, 368, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, -1, -1, + 384, 385, 386, 387, 388, 389, 390, 391, 392, -1, + -1, 395, 396, 397, 398, -1, 400, 401, 402, 403, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + 414, -1, -1, 417, 418, -1, 420, -1, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, 435, 436, 437, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, -1, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, 463, + 464, 465, -1, 467, -1, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, -1, 481, 482, 483, + 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, + 494, 495, 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, 43, 44, - -1, -1, 47, 48, -1, 50, 51, 52, 53, 54, + -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, -1, -1, 83, 84, @@ -19309,7 +18704,7 @@ static const yytype_int16 yycheck[] = 145, 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, - 175, 176, -1, 178, 179, 180, -1, 182, 183, 184, + 175, 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, @@ -19323,127 +18718,179 @@ static const yytype_int16 yycheck[] = 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 315, -1, -1, -1, -1, 320, 321, 322, -1, 324, - 325, 326, 327, 328, 329, -1, 331, 332, 333, 334, - 335, 336, -1, 338, 339, 340, 341, 342, 343, 344, - 345, 346, 347, -1, 349, 350, 351, 352, 353, 354, - 355, 356, 357, 358, 359, 360, 361, -1, 363, 364, - -1, 366, 367, 368, 369, 370, 371, 372, 373, 374, - 375, 376, 377, 378, 379, 380, 381, 382, -1, -1, - 385, 386, 387, 388, 389, 390, 391, 392, 393, -1, - -1, 396, 397, 398, 399, -1, 401, 402, 403, 404, + -1, -1, -1, -1, 319, 320, 321, -1, 323, 324, + 325, 326, 327, 328, -1, 330, 331, 332, 333, 334, + 335, -1, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, 358, 359, 360, -1, 362, 363, -1, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, + 375, 376, 377, 378, 379, 380, 381, -1, -1, 384, + 385, 386, 387, 388, 389, 390, 391, 392, -1, -1, + 395, 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, - 415, 416, -1, -1, 419, 420, -1, 422, -1, 424, - 425, 426, 427, 428, -1, 430, 431, 432, -1, -1, - 435, 436, 437, 438, 439, -1, 441, 442, 443, 444, - 445, 446, 447, 448, -1, -1, 451, 452, 453, -1, - -1, 456, 457, 458, 459, -1, 461, 462, 463, 464, - 465, 466, 467, 468, -1, 470, -1, 472, 473, 474, - 475, 476, 477, 478, -1, -1, 481, -1, -1, 484, + -1, -1, 417, 418, -1, 420, -1, 422, 423, 424, + 425, 426, -1, 428, 429, 430, -1, -1, 433, 434, + 435, 436, 437, -1, 439, 440, 441, 442, 443, 444, + 445, 446, -1, -1, 449, 450, 451, -1, 453, 454, + 455, 456, -1, 458, 459, 460, 461, 462, 463, 464, + 465, -1, 467, -1, 469, 470, 471, 472, 473, 474, + 475, -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, - 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, - 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, - 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, - 33, -1, -1, -1, 37, -1, -1, -1, -1, 42, - 43, 44, -1, 46, 47, 48, 49, 50, 51, 52, - -1, 54, 55, 56, 57, -1, 59, 60, 61, 62, - 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, - 73, -1, 75, 76, 77, 78, -1, -1, 81, -1, - 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - -1, 94, 95, 96, 97, 98, 99, -1, 101, 102, - 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, - 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, - -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, - -1, 144, 145, 146, -1, 148, 149, 150, 151, -1, - 153, 154, 155, 156, 157, 158, -1, -1, 161, -1, - 163, 164, 165, 166, -1, 168, -1, 170, 171, -1, - 173, 174, 175, 176, 177, 178, 179, 180, -1, -1, - -1, 184, 185, -1, 187, 188, 189, 190, 191, 192, - 193, 194, 195, 196, 197, 198, -1, 200, 201, 202, - 203, 204, 205, 206, -1, 208, 209, -1, 211, 212, - 213, 214, 215, 216, 217, -1, 219, -1, 221, 222, - 223, 224, 225, 226, 227, 228, 229, 230, 231, -1, - -1, 234, 235, 236, 237, -1, 239, 240, 241, 242, - 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, - 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, - 273, -1, -1, 276, 277, 278, 279, -1, -1, 282, - 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, - 293, 294, -1, -1, 297, 298, -1, 300, 301, 302, - -1, 304, 305, 306, 307, 308, 309, 310, 311, 312, - 313, 314, 315, -1, -1, -1, -1, 320, 321, -1, - 323, 324, 325, -1, 327, 328, 329, -1, 331, 332, - 333, 334, 335, 336, -1, 338, 339, 340, 341, 342, - 343, 344, 345, 346, 347, -1, 349, 350, 351, 352, - 353, 354, 355, 356, 357, 358, 359, 360, 361, -1, - 363, 364, 365, 366, 367, 368, -1, 370, 371, 372, - 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, - -1, 384, 385, 386, 387, 388, 389, 390, -1, 392, - 393, -1, 395, 396, 397, 398, 399, -1, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, -1, -1, -1, 419, 420, -1, 422, - 423, 424, 425, 426, 427, 428, -1, 430, 431, 432, - -1, -1, 435, 436, -1, 438, -1, -1, 441, 442, - 443, 444, 445, 446, 447, 448, -1, -1, 451, 452, - 453, 454, -1, 456, 457, 458, 459, -1, 461, 462, - 463, 464, 465, -1, 467, 468, -1, 470, 471, 472, - 473, 474, 475, 476, 477, 478, -1, -1, 481, -1, - -1, 484, 485, 486, 487, 488, 489, 3, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 501, 502, - 503, 504, -1, -1, -1, -1, 22, 23, 24, 25, + 495, 496, 497, 498, 499, 500, 501, 3, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, - -1, 37, -1, -1, -1, -1, 42, 43, 44, -1, - 46, 47, 48, 49, 50, 51, 52, -1, 54, 55, + -1, -1, -1, -1, -1, -1, -1, 43, 44, -1, + 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, - 76, 77, 78, -1, -1, 81, -1, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, -1, 94, 95, - 96, 97, 98, 99, -1, 101, 102, 103, 104, 105, + 76, 77, 78, 79, -1, -1, -1, 83, 84, 85, + 86, 87, 88, -1, 90, 91, 92, -1, 94, 95, + 96, 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, 144, 145, - 146, -1, 148, 149, 150, 151, -1, 153, 154, 155, - 156, 157, 158, -1, -1, 161, -1, 163, 164, 165, - 166, -1, 168, -1, 170, 171, -1, 173, 174, 175, - -1, 177, 178, 179, 180, -1, -1, -1, 184, 185, - -1, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 146, -1, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, + 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, + 176, -1, 178, -1, 180, -1, 182, 183, 184, 185, + -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, - 206, -1, 208, 209, -1, 211, 212, 213, 214, 215, - 216, 217, -1, 219, -1, 221, 222, 223, 224, 225, - 226, 227, 228, 229, 230, 231, -1, -1, 234, 235, - 236, 237, -1, 239, 240, 241, 242, 243, 244, 245, - 246, -1, 248, 249, 250, 251, 252, 253, 254, 255, + 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, + 216, 217, -1, 219, -1, 221, -1, -1, 224, -1, + 226, 227, 228, 229, 230, 231, -1, -1, 234, -1, + 236, -1, -1, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, 269, 270, 271, 272, 273, -1, -1, - 276, 277, 278, 279, -1, -1, 282, 283, 284, 285, + 266, 267, 268, -1, 270, 271, 272, 273, 274, -1, + 276, 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, - -1, 297, 298, -1, 300, 301, 302, -1, 304, 305, - 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, - -1, -1, -1, -1, 320, 321, -1, 323, 324, 325, - -1, 327, 328, 329, -1, 331, 332, 333, 334, 335, - 336, -1, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, -1, 349, 350, 351, 352, 353, 354, 355, - 356, 357, 358, 359, 360, 361, -1, 363, 364, 365, - 366, 367, 368, -1, 370, 371, 372, 373, 374, 375, - 376, 377, 378, 379, 380, 381, 382, -1, 384, 385, - 386, 387, 388, 389, 390, -1, 392, 393, -1, 395, - 396, 397, 398, 399, -1, 401, 402, 403, 404, 405, - 406, 407, 408, 409, 410, 411, 412, 413, -1, 415, - -1, -1, -1, 419, 420, -1, 422, 423, 424, 425, - 426, 427, 428, -1, 430, 431, 432, -1, -1, 435, - 436, -1, 438, -1, -1, 441, 442, 443, 444, 445, - 446, 447, 448, -1, -1, 451, 452, 453, 454, -1, - 456, 457, 458, 459, -1, 461, 462, 463, 464, 465, - -1, 467, 468, -1, 470, 471, 472, 473, 474, 475, - 476, 477, 478, -1, -1, 481, -1, -1, 484, 485, - 486, 487, 488, 489, 3, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 501, 502, 503, 504, -1, + -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, + 306, 307, 308, 309, 310, 311, 312, 313, 314, -1, + -1, -1, -1, 319, 320, 321, -1, 323, 324, 325, + 326, 327, 328, -1, 330, 331, 332, 333, 334, 335, + -1, 337, 338, 339, 340, 341, 342, 343, 344, 345, + 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, + 356, 357, 358, 359, 360, -1, 362, 363, -1, 365, + 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, + 376, 377, 378, 379, 380, 381, -1, -1, 384, 385, + 386, 387, 388, 389, 390, 391, 392, -1, -1, 395, + 396, 397, 398, -1, 400, 401, 402, 403, 404, 405, + 406, 407, 408, 409, 410, 411, 412, 413, 414, -1, + -1, 417, 418, -1, 420, -1, 422, 423, 424, 425, + 426, -1, 428, 429, 430, -1, -1, 433, 434, 435, + 436, 437, -1, 439, 440, 441, 442, 443, 444, 445, + 446, -1, -1, 449, 450, 451, -1, 453, 454, 455, + 456, -1, 458, 459, 460, 461, 462, 463, 464, 465, + -1, 467, -1, 469, 470, 471, 472, 473, 474, 475, + -1, -1, 478, -1, -1, 481, 482, 483, 484, 485, + 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, + 496, 497, 498, 499, 500, 501, 3, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, + 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 43, 44, -1, 46, + 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, + 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, + 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, + 77, 78, 79, -1, -1, -1, 83, 84, 85, 86, + 87, 88, -1, 90, 91, 92, -1, 94, 95, 96, + 97, 98, 99, -1, -1, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, + -1, 118, -1, 120, 121, 122, 123, 124, 125, -1, + -1, 128, 129, 130, 131, -1, -1, 134, 135, 136, + 137, 138, -1, 140, 141, 142, -1, 144, 145, 146, + -1, 148, 149, 150, 151, 152, 153, 154, 155, 156, + 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, + -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, + -1, 178, -1, 180, -1, 182, 183, 184, 185, -1, + 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, + 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, + -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, + 217, -1, 219, -1, 221, -1, -1, 224, -1, 226, + 227, 228, 229, 230, 231, -1, -1, 234, -1, 236, + -1, -1, 239, 240, 241, 242, 243, 244, 245, 246, + 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, + 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, -1, 270, 271, 272, 273, 274, -1, 276, + 277, -1, 279, -1, 281, 282, 283, 284, 285, 286, + -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, + 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, + 307, 308, 309, 310, 311, 312, 313, 314, -1, -1, + -1, -1, 319, 320, 321, -1, 323, 324, 325, 326, + 327, 328, -1, 330, 331, 332, 333, 334, 335, -1, + 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, + -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, + 357, 358, 359, 360, -1, 362, 363, -1, 365, 366, + 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, + 377, 378, 379, 380, 381, -1, -1, 384, 385, 386, + 387, 388, 389, 390, 391, 392, -1, -1, 395, 396, + 397, 398, -1, 400, 401, 402, 403, 404, 405, 406, + 407, 408, 409, 410, 411, 412, 413, 414, -1, -1, + 417, 418, -1, 420, -1, 422, 423, 424, 425, 426, + -1, 428, 429, 430, -1, -1, 433, 434, 435, 436, + 437, -1, 439, 440, 441, 442, 443, 444, 445, 446, + -1, -1, 449, 450, 451, -1, 453, 454, 455, 456, + -1, 458, 459, 460, 461, 462, 463, 464, 465, -1, + 467, -1, 469, 470, 471, 472, 473, 474, 475, -1, + -1, 478, -1, -1, 481, 482, 483, 484, 485, 486, + 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, + 497, 498, 499, 500, 501, 3, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, + 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, + -1, -1, 40, -1, -1, 43, 44, -1, 46, 47, + 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, + -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, 79, -1, -1, -1, 83, 84, 85, 86, 87, + 88, -1, 90, 91, 92, -1, 94, 95, 96, 97, + 98, 99, -1, -1, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, + 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, + 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, + 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, + 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, + 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, + 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, + 178, -1, 180, -1, 182, 183, 184, 185, -1, 187, + 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, + 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, + 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, + -1, 219, -1, 221, -1, -1, 224, -1, 226, 227, + 228, 229, 230, 231, -1, -1, 234, -1, 236, -1, + -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, -1, 270, 271, 272, 273, 274, -1, 276, 277, + -1, 279, -1, 281, 282, 283, 284, 285, 286, -1, + 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, + 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, 321, -1, 323, 324, 325, 326, 327, + 328, -1, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, -1, 365, 366, 367, + 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 380, 381, -1, -1, 384, 385, 386, 387, + 388, -1, 390, 391, 392, -1, -1, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, 414, -1, -1, 417, + 418, -1, 420, -1, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, 435, 436, 437, + -1, 439, 440, 441, 442, 443, 444, 445, 446, -1, + -1, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, 463, 464, 465, -1, 467, + -1, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 487, + 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, + 498, 499, 500, 501, 3, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 43, 44, -1, -1, 47, 48, + -1, -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, 78, @@ -19457,7 +18904,7 @@ static const yytype_int16 yycheck[] = 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, -1, -1, -1, 174, 175, 176, -1, 178, - 179, 180, -1, 182, 183, -1, 185, -1, 187, 188, + -1, 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, 211, 212, 213, 214, 215, 216, 217, -1, @@ -19470,76 +18917,420 @@ static const yytype_int16 yycheck[] = 279, -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, 301, -1, 303, 304, 305, 306, 307, 308, - 309, -1, 311, 312, 313, 314, 315, -1, -1, -1, - -1, 320, 321, 322, -1, 324, 325, 326, 327, 328, - 329, -1, 331, 332, 333, 334, 335, 336, -1, 338, - 339, 340, -1, 342, 343, 344, 345, 346, 347, -1, + 309, 310, 311, 312, 313, 314, -1, -1, -1, -1, + 319, 320, 321, -1, 323, 324, 325, 326, 327, 328, + -1, 330, 331, 332, 333, 334, 335, -1, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, - 359, 360, 361, -1, 363, 364, -1, 366, 367, 368, - 369, -1, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, -1, -1, 385, 386, 387, 388, - 389, 390, 391, 392, 393, -1, -1, 396, 397, 398, - 399, -1, 401, 402, 403, 404, 405, 406, 407, 408, - 409, 410, 411, 412, 413, 414, 415, 416, -1, -1, - 419, 420, -1, 422, -1, 424, 425, 426, 427, 428, - -1, 430, 431, 432, -1, -1, 435, 436, 437, 438, - 439, -1, 441, 442, 443, 444, 445, 446, 447, 448, - -1, -1, 451, 452, 453, -1, -1, 456, 457, 458, - 459, -1, 461, 462, 463, 464, 465, 466, 467, 468, - -1, 470, -1, 472, 473, 474, 475, 476, 477, 478, - -1, -1, 481, -1, -1, 484, 485, 486, 487, 488, + 359, 360, -1, 362, 363, -1, 365, 366, 367, 368, + 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, + 379, 380, 381, -1, -1, 384, 385, 386, 387, 388, + 389, 390, 391, 392, -1, -1, 395, 396, 397, 398, + -1, 400, 401, 402, 403, 404, 405, 406, 407, 408, + 409, 410, 411, 412, 413, 414, -1, -1, 417, 418, + -1, 420, -1, 422, 423, 424, 425, 426, -1, 428, + 429, 430, -1, -1, 433, 434, 435, 436, 437, -1, + 439, 440, 441, 442, 443, 444, 445, 446, -1, -1, + 449, 450, 451, -1, 453, 454, 455, 456, -1, 458, + 459, 460, 461, 462, 463, 464, 465, -1, 467, -1, + 469, 470, 471, 472, 473, 474, 475, -1, -1, 478, + -1, -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, - 499, 500, 501, 502, 503, 504, 22, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 32, -1, 34, 35, + 499, 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 52, -1, -1, -1, - -1, -1, -1, -1, -1, 61, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 75, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, + 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, -1, -1, -1, 174, 175, 176, -1, 178, -1, + 180, -1, 182, 183, 184, 185, -1, 187, 188, 189, + 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, + 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, + 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, + -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, + 310, 311, 312, 313, 314, -1, -1, -1, -1, 319, + 320, 321, -1, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + 340, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, -1, 365, 366, 367, 368, 369, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, -1, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, -1, -1, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, -1, -1, 417, 418, -1, + 420, -1, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, -1, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, -1, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 86, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 98, -1, 100, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 111, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 43, 44, -1, 46, 47, 48, -1, 50, + 51, 52, 53, 54, -1, 56, 57, -1, 59, 60, + 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, 79, -1, + -1, -1, 83, 84, 85, 86, 87, 88, -1, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + -1, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, -1, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + -1, -1, -1, 174, 175, 176, -1, 178, -1, 180, + -1, 182, 183, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, -1, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, -1, 210, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, -1, -1, 224, -1, 226, 227, 228, 229, 230, + 231, -1, -1, 234, -1, 236, -1, -1, 239, 240, + 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, -1, 270, + 271, 272, 273, 274, -1, 276, 277, -1, 279, -1, + 281, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, 299, -1, + 301, -1, 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + 321, -1, 323, 324, 325, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, -1, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, -1, 384, 385, 386, 387, 388, 389, 390, + 391, 392, -1, -1, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, 412, 413, 414, -1, -1, 417, 418, -1, 420, + -1, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, 435, 436, 437, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, 463, 464, 465, -1, 467, -1, 469, 470, + 471, 472, 473, 474, 475, -1, -1, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 126, 127, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 137, -1, -1, -1, -1, -1, 143, -1, -1, - -1, -1, -1, -1, -1, 151, -1, -1, -1, -1, + 22, 23, 24, 25, 26, 27, 28, 29, -1, 31, + 32, 33, -1, -1, -1, 37, -1, -1, -1, -1, + 42, 43, 44, -1, 46, 47, 48, 49, 50, 51, + 52, -1, 54, 55, 56, 57, -1, 59, 60, 61, + 62, 63, 64, -1, -1, 67, 68, 69, 70, 71, + 72, 73, -1, 75, 76, 77, 78, -1, -1, 81, + -1, 83, 84, 85, 86, 87, 88, 89, 90, 91, + 92, -1, 94, 95, 96, 97, 98, 99, -1, 101, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 118, -1, 120, 121, + 122, 123, 124, 125, -1, -1, 128, 129, 130, 131, + -1, -1, 134, 135, 136, 137, 138, -1, 140, 141, + 142, -1, 144, 145, 146, -1, 148, 149, 150, 151, + -1, 153, 154, 155, 156, 157, 158, -1, -1, 161, + -1, 163, 164, 165, 166, -1, 168, -1, 170, 171, + -1, 173, 174, 175, -1, 177, 178, -1, 180, -1, + -1, -1, 184, 185, -1, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, -1, 200, 201, + 202, 203, 204, 205, 206, -1, 208, 209, -1, 211, + 212, 213, 214, 215, 216, 217, -1, 219, -1, 221, + 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + -1, -1, 234, 235, 236, 237, -1, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, + 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, + 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, + 272, 273, -1, -1, 276, 277, 278, 279, -1, -1, + 282, 283, 284, 285, 286, -1, 288, 289, -1, -1, + 292, 293, 294, -1, -1, 297, 298, -1, 300, 301, + 302, -1, 304, 305, 306, 307, 308, 309, 310, 311, + 312, 313, 314, -1, -1, -1, -1, 319, 320, -1, + 322, 323, 324, -1, 326, 327, 328, -1, 330, 331, + 332, 333, 334, 335, -1, 337, 338, 339, 340, 341, + 342, 343, 344, 345, 346, -1, 348, 349, 350, 351, + 352, 353, 354, 355, 356, 357, 358, 359, 360, -1, + 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, + 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, + -1, 383, 384, 385, 386, 387, 388, 389, 390, 391, + 392, -1, 394, 395, 396, 397, 398, -1, 400, 401, + 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, + 412, 413, -1, -1, -1, 417, 418, -1, 420, 421, + 422, 423, 424, 425, 426, -1, 428, 429, 430, -1, + -1, 433, 434, -1, 436, -1, -1, 439, 440, 441, + 442, 443, 444, 445, 446, 447, -1, 449, 450, 451, + -1, 453, 454, 455, 456, -1, 458, 459, 460, 461, + 462, -1, 464, 465, -1, 467, 468, 469, 470, 471, + 472, 473, 474, 475, -1, -1, 478, -1, -1, 481, + 482, 483, 484, 485, 486, 3, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 498, 499, 500, 501, + -1, -1, -1, -1, 22, 23, 24, 25, 26, 27, + 28, 29, -1, 31, 32, 33, -1, -1, -1, 37, + -1, -1, -1, -1, 42, 43, 44, -1, 46, 47, + 48, 49, 50, 51, 52, -1, 54, 55, 56, 57, + -1, 59, 60, 61, 62, 63, 64, -1, -1, 67, + 68, 69, 70, 71, 72, 73, -1, 75, 76, 77, + 78, -1, -1, 81, -1, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, -1, 94, 95, 96, 97, + 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, + 118, -1, 120, 121, 122, 123, 124, 125, -1, -1, + 128, 129, 130, 131, -1, -1, 134, 135, 136, 137, + 138, -1, 140, 141, 142, -1, 144, 145, 146, -1, + 148, 149, 150, 151, -1, 153, 154, 155, 156, 157, + 158, -1, -1, 161, -1, 163, 164, 165, 166, -1, + 168, -1, 170, 171, -1, 173, 174, 175, -1, 177, + 178, -1, 180, -1, -1, -1, 184, 185, -1, 187, + 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, + 198, -1, 200, 201, 202, 203, 204, 205, 206, -1, + 208, 209, -1, 211, 212, 213, 214, 215, 216, 217, + -1, 219, -1, 221, 222, 223, 224, 225, 226, 227, + 228, 229, 230, 231, -1, -1, 234, 235, 236, 237, + -1, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, + 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, 269, 270, 271, 272, 273, -1, -1, 276, 277, + 278, 279, -1, -1, 282, 283, 284, 285, 286, -1, + 288, 289, -1, -1, 292, 293, 294, -1, -1, 297, + 298, -1, 300, 301, 302, -1, 304, 305, 306, 307, + 308, 309, 310, 311, 312, 313, 314, -1, -1, -1, + -1, 319, 320, -1, 322, 323, 324, -1, 326, 327, + 328, -1, 330, 331, 332, 333, 334, 335, -1, 337, + 338, 339, 340, 341, 342, 343, 344, 345, 346, -1, + 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, + 358, 359, 360, -1, 362, 363, 364, 365, 366, 367, + 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, + 378, 379, 380, 381, -1, 383, 384, 385, 386, 387, + 388, 389, 390, 391, 392, -1, 394, 395, 396, 397, + 398, -1, 400, 401, 402, 403, 404, 405, 406, 407, + 408, 409, 410, 411, 412, 413, -1, -1, -1, 417, + 418, -1, 420, 421, 422, 423, 424, 425, 426, -1, + 428, 429, 430, -1, -1, 433, 434, -1, 436, -1, + -1, 439, 440, 441, 442, 443, 444, 445, 446, 447, + -1, 449, 450, 451, -1, 453, 454, 455, 456, -1, + 458, 459, 460, 461, 462, -1, 464, 465, -1, 467, + 468, 469, 470, 471, 472, 473, 474, 475, -1, -1, + 478, -1, -1, 481, 482, 483, 484, 485, 486, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 168, -1, -1, -1, 172, -1, -1, -1, + 498, 499, 500, 501, -1, -1, -1, -1, 22, 23, + 24, 25, 26, 27, 28, 29, -1, 31, 32, 33, + -1, -1, -1, 37, -1, -1, -1, -1, 42, 43, + 44, -1, 46, 47, 48, 49, 50, 51, 52, -1, + 54, 55, 56, 57, -1, 59, 60, 61, 62, 63, + 64, -1, -1, 67, 68, 69, 70, 71, 72, 73, + -1, 75, 76, 77, 78, -1, -1, 81, -1, 83, + 84, 85, 86, 87, 88, 89, 90, 91, 92, -1, + 94, 95, 96, 97, 98, 99, -1, 101, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, -1, 118, -1, 120, 121, 122, 123, + 124, 125, -1, -1, 128, 129, 130, 131, -1, -1, + 134, 135, 136, 137, 138, -1, 140, 141, 142, -1, + 144, 145, 146, -1, 148, 149, 150, 151, -1, 153, + 154, 155, 156, 157, 158, -1, -1, 161, -1, 163, + 164, 165, 166, -1, 168, -1, 170, 171, -1, 173, + 174, 175, 176, 177, 178, -1, 180, -1, -1, -1, + 184, 185, -1, 187, 188, 189, 190, 191, 192, 193, + 194, 195, 196, 197, 198, -1, 200, 201, 202, 203, + 204, 205, 206, -1, 208, 209, -1, 211, 212, 213, + 214, 215, 216, 217, -1, 219, -1, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, -1, -1, + 234, 235, 236, 237, -1, 239, 240, 241, 242, 243, + 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, + 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, + 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, + -1, -1, 276, 277, 278, 279, -1, -1, 282, 283, + 284, 285, 286, -1, 288, 289, -1, -1, 292, 293, + 294, -1, -1, 297, 298, -1, 300, 301, 302, -1, + 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, + 314, -1, -1, -1, -1, 319, 320, -1, 322, 323, + 324, -1, 326, 327, 328, -1, 330, 331, 332, 333, + 334, 335, -1, 337, 338, 339, 340, 341, 342, 343, + 344, 345, 346, -1, 348, 349, 350, 351, 352, 353, + 354, 355, 356, 357, 358, 359, 360, -1, 362, 363, + 364, 365, 366, 367, -1, 369, 370, 371, 372, 373, + 374, 375, 376, 377, 378, 379, 380, 381, -1, 383, + 384, 385, 386, 387, 388, 389, -1, 391, 392, -1, + 394, 395, 396, 397, 398, -1, 400, 401, 402, 403, + 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, + -1, -1, -1, 417, 418, -1, 420, 421, 422, 423, + 424, 425, 426, -1, 428, 429, 430, -1, -1, 433, + 434, -1, 436, -1, -1, 439, 440, 441, 442, 443, + 444, 445, 446, -1, -1, 449, 450, 451, -1, 453, + 454, 455, 456, -1, 458, 459, 460, 461, 462, -1, + 464, 465, -1, 467, 468, 469, 470, 471, 472, 473, + 474, 475, -1, -1, 478, -1, -1, 481, 482, 483, + 484, 485, 486, 3, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 498, 499, 500, 501, -1, -1, + -1, -1, 22, 23, 24, 25, 26, 27, 28, 29, + -1, 31, 32, 33, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 43, 44, -1, 46, 47, 48, -1, + 50, 51, 52, 53, 54, -1, 56, 57, -1, 59, + 60, 61, 62, 63, 64, -1, -1, 67, 68, 69, + 70, 71, 72, 73, -1, 75, 76, 77, 78, 79, + -1, -1, -1, 83, 84, 85, 86, 87, 88, -1, + 90, 91, 92, -1, 94, 95, 96, 97, 98, 99, + -1, -1, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, -1, 118, -1, + 120, 121, 122, 123, 124, 125, -1, -1, 128, 129, + 130, 131, -1, -1, 134, 135, 136, 137, 138, -1, + 140, 141, 142, -1, 144, 145, 146, -1, 148, 149, + 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + -1, 161, -1, 163, 164, 165, 166, -1, 168, -1, + 170, -1, -1, -1, 174, 175, 176, -1, 178, -1, + 180, -1, 182, 183, -1, 185, -1, 187, 188, 189, + 190, 191, 192, 193, -1, 195, 196, 197, 198, -1, + 200, 201, 202, 203, 204, 205, 206, -1, 208, -1, + 210, 211, 212, 213, 214, 215, 216, 217, -1, 219, + -1, 221, -1, -1, 224, -1, 226, 227, 228, 229, + 230, 231, -1, -1, 234, -1, 236, -1, -1, 239, + 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, -1, + 270, 271, 272, 273, 274, -1, 276, 277, -1, 279, + -1, 281, 282, 283, 284, 285, 286, -1, 288, 289, + -1, -1, 292, 293, 294, -1, -1, 297, 298, 299, + -1, 301, -1, 303, 304, 305, 306, 307, 308, 309, + -1, 311, 312, 313, 314, -1, -1, -1, -1, 319, + 320, 321, -1, 323, 324, 325, 326, 327, 328, -1, + 330, 331, 332, 333, 334, 335, -1, 337, 338, 339, + -1, 341, 342, 343, 344, 345, 346, -1, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, -1, 362, 363, -1, 365, 366, 367, 368, -1, + 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, -1, -1, 384, 385, 386, 387, 388, 389, + 390, 391, 392, -1, -1, 395, 396, 397, 398, -1, + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, -1, -1, 417, 418, -1, + 420, -1, 422, 423, 424, 425, 426, -1, 428, 429, + 430, -1, -1, 433, 434, 435, 436, 437, -1, 439, + 440, 441, 442, 443, 444, 445, 446, -1, -1, 449, + 450, 451, -1, 453, 454, 455, 456, -1, 458, 459, + 460, 461, 462, 463, 464, 465, -1, 467, -1, 469, + 470, 471, 472, 473, 474, 475, -1, -1, 478, -1, + -1, 481, 482, 483, 484, 485, 486, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 22, 23, 24, 25, 26, 27, 28, 29, -1, + 31, 32, 33, -1, -1, -1, 37, -1, -1, -1, + -1, 42, 43, 44, -1, 46, 47, 48, 49, 50, + 51, 52, -1, 54, 55, 56, 57, -1, 59, 60, + 61, 62, 63, 64, -1, -1, 67, 68, 69, 70, + 71, 72, 73, -1, 75, 76, 77, 78, -1, -1, + 81, -1, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, -1, 94, 95, 96, 97, 98, 99, -1, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, -1, 118, -1, 120, + 121, 122, 123, 124, 125, -1, -1, 128, 129, 130, + 131, -1, -1, 134, 135, 136, 137, 138, -1, 140, + 141, 142, -1, 144, 145, 146, -1, 148, 149, 150, + 151, -1, 153, 154, 155, 156, 157, 158, -1, -1, + 161, -1, 163, 164, 165, 166, -1, 168, -1, 170, + 171, -1, 173, 174, 175, -1, 177, 178, -1, 180, + -1, -1, -1, 184, 185, -1, 187, 188, 189, 190, + 191, 192, 193, 194, 195, 196, 197, 198, -1, 200, + 201, 202, 203, 204, 205, 206, -1, 208, 209, -1, + 211, 212, 213, 214, 215, 216, 217, -1, 219, -1, + 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, -1, -1, 234, 235, 236, 237, -1, 239, 240, + 241, 242, 243, 244, 245, 246, -1, 248, 249, 250, + 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, -1, -1, 276, 277, 278, 279, -1, + -1, 282, 283, 284, 285, 286, -1, 288, 289, -1, + -1, 292, 293, 294, -1, -1, 297, 298, -1, 300, + 301, 302, -1, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, -1, -1, -1, -1, 319, 320, + -1, 322, 323, 324, -1, 326, 327, 328, -1, 330, + 331, 332, 333, 334, 335, -1, 337, 338, 339, 340, + 341, 342, 343, 344, 345, 346, -1, 348, 349, 350, + 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + -1, 362, 363, 364, 365, 366, 367, -1, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, -1, 383, 384, 385, 386, 387, 388, 389, -1, + 391, 392, -1, 394, 395, 396, 397, 398, -1, 400, + 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, + 411, -1, 413, -1, -1, -1, 417, 418, -1, 420, + 421, 422, 423, 424, 425, 426, -1, 428, 429, 430, + -1, -1, 433, 434, -1, 436, -1, -1, 439, 440, + 441, 442, 443, 444, 445, 446, -1, -1, 449, 450, + 451, -1, 453, 454, 455, 456, -1, 458, 459, 460, + 461, 462, -1, 464, 465, -1, 467, 468, 469, 470, + 471, 472, 473, 474, 475, -1, 22, 478, -1, -1, + 481, 482, 483, 484, 485, 486, 32, -1, 34, 35, + -1, -1, -1, -1, 22, -1, -1, 498, 499, 500, + 501, -1, -1, -1, 32, -1, 52, -1, -1, -1, + -1, -1, -1, -1, -1, 61, -1, -1, -1, -1, + -1, -1, -1, -1, 52, -1, -1, -1, -1, 75, + -1, -1, -1, 61, -1, -1, -1, -1, -1, -1, + 86, -1, -1, -1, -1, -1, -1, 75, -1, -1, + -1, -1, 98, -1, 100, -1, -1, -1, 86, -1, + -1, -1, -1, -1, -1, 111, -1, -1, -1, -1, + 98, -1, 100, -1, -1, -1, -1, -1, -1, -1, + 126, 127, -1, 111, -1, -1, -1, -1, -1, -1, + -1, 137, -1, -1, -1, -1, -1, 143, 126, 127, + -1, -1, -1, -1, -1, 151, -1, -1, -1, 137, + -1, -1, -1, -1, -1, 143, -1, -1, -1, -1, + -1, -1, 168, 151, -1, -1, 172, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 168, -1, -1, -1, 172, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 214, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 214, -1, -1, -1, -1, -1, -1, -1, 240, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, 240, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 315, + 316, 317, -1, -1, -1, -1, -1, 323, -1, -1, + 326, -1, -1, -1, -1, -1, -1, 315, 316, 317, + -1, -1, -1, -1, -1, 323, -1, -1, 326, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 357, -1, -1, -1, -1, -1, -1, -1, -1, + 366, -1, -1, -1, -1, -1, -1, -1, -1, 357, + -1, -1, -1, -1, -1, -1, 382, -1, 366, -1, + -1, -1, -1, 389, -1, -1, -1, 393, -1, -1, + -1, -1, -1, -1, 382, -1, -1, 403, -1, -1, + -1, 389, -1, -1, -1, 393, -1, -1, -1, 415, + -1, -1, -1, 419, -1, 403, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 415, -1, -1, + -1, 419, -1, 439, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, 452, -1, -1, -1, + -1, 439, 458, -1, -1, -1, -1, 463, -1, -1, + -1, -1, 468, -1, 452, -1, -1, -1, -1, -1, + 458, -1, -1, -1, 480, 463, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 316, 317, 318, -1, -1, -1, -1, -1, 324, -1, - -1, 327, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, 358, -1, -1, -1, -1, -1, -1, -1, - -1, 367, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 383, -1, -1, - -1, -1, -1, -1, 390, -1, -1, -1, 394, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 405, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 417, -1, -1, -1, 421, -1, -1, -1, -1, + -1, -1, 480, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 441, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, 455, - -1, -1, -1, -1, -1, 461, -1, -1, -1, -1, - 466, -1, -1, -1, -1, 471, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 483, -1, -1, + -1, -1, 518, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 507, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 521 + 518 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing @@ -19548,373 +19339,366 @@ static const yytype_uint16 yystos[] = { 0, 22, 32, 34, 35, 47, 52, 61, 75, 84, 86, 98, 100, 111, 126, 127, 128, 137, 143, 151, - 153, 154, 168, 172, 198, 240, 316, 317, 318, 324, - 327, 358, 367, 383, 390, 394, 405, 417, 421, 441, - 455, 458, 461, 466, 483, 507, 521, 533, 534, 535, - 536, 551, 560, 562, 567, 583, 586, 587, 589, 596, - 597, 601, 608, 610, 613, 614, 664, 670, 679, 680, - 698, 699, 700, 701, 703, 705, 706, 710, 770, 771, - 953, 956, 959, 966, 967, 969, 972, 973, 974, 981, - 985, 991, 992, 995, 1000, 1004, 1005, 1006, 1009, 1012, - 1013, 1014, 1017, 1018, 1020, 435, 486, 611, 203, 374, - 385, 421, 473, 108, 192, 295, 1007, 611, 3, 22, - 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, - 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 59, 60, 61, 62, 63, - 64, 67, 68, 69, 70, 71, 72, 73, 75, 76, - 77, 78, 79, 81, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, 94, 95, 96, 97, 98, 99, - 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, 118, 120, 121, 122, - 123, 124, 125, 128, 129, 130, 131, 134, 135, 136, - 137, 138, 140, 141, 142, 144, 145, 146, 148, 149, - 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 161, 163, 164, 165, 166, 168, 170, 171, 173, 174, - 175, 176, 177, 178, 179, 180, 182, 183, 184, 185, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, - 197, 198, 200, 201, 202, 203, 204, 205, 206, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, 219, - 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, - 231, 234, 235, 236, 237, 239, 240, 241, 242, 243, - 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, - 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, - 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, - 274, 276, 277, 278, 279, 281, 282, 283, 284, 285, - 286, 288, 289, 292, 293, 294, 297, 298, 299, 300, - 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 320, 321, 322, 323, 324, - 325, 326, 327, 328, 329, 331, 332, 333, 334, 335, - 336, 338, 339, 340, 341, 342, 343, 344, 345, 346, - 347, 349, 350, 351, 352, 353, 354, 355, 356, 357, - 358, 359, 360, 361, 363, 364, 365, 366, 367, 368, - 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, - 379, 380, 381, 382, 385, 386, 387, 388, 389, 390, - 391, 392, 393, 395, 396, 397, 398, 399, 401, 402, - 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, - 413, 414, 415, 416, 419, 420, 422, 423, 424, 425, - 426, 427, 428, 430, 431, 432, 435, 436, 437, 438, - 439, 441, 442, 443, 444, 445, 446, 447, 448, 451, - 452, 453, 456, 457, 458, 459, 461, 462, 463, 464, - 465, 466, 467, 468, 470, 471, 472, 473, 474, 475, - 476, 477, 478, 481, 484, 485, 486, 487, 488, 489, - 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 503, 504, 553, 852, 942, 946, 1023, - 1024, 1025, 3, 176, 247, 414, 553, 968, 1023, 290, - 611, 55, 172, 521, 693, 178, 241, 295, 315, 374, - 425, 427, 444, 450, 453, 591, 662, 965, 5, 30, - 327, 553, 554, 941, 3, 30, 34, 35, 36, 37, - 38, 39, 40, 41, 42, 45, 46, 49, 53, 54, - 55, 56, 57, 58, 65, 66, 71, 72, 74, 79, - 80, 81, 82, 83, 89, 93, 100, 101, 108, 112, - 115, 117, 119, 126, 127, 132, 133, 139, 143, 147, - 152, 159, 160, 162, 165, 167, 169, 171, 172, 173, - 176, 177, 181, 182, 183, 186, 194, 199, 207, 209, - 210, 216, 217, 218, 219, 220, 222, 223, 225, 232, - 233, 235, 237, 238, 247, 268, 269, 270, 274, 275, - 278, 280, 281, 283, 287, 290, 291, 295, 296, 299, - 300, 302, 303, 316, 317, 318, 319, 322, 323, 326, - 330, 337, 343, 348, 362, 365, 369, 383, 384, 391, - 394, 395, 398, 400, 414, 416, 417, 418, 421, 423, - 429, 431, 432, 433, 434, 437, 439, 440, 443, 449, - 450, 454, 455, 460, 466, 467, 469, 471, 479, 480, - 482, 483, 490, 491, 492, 493, 494, 495, 496, 497, - 498, 499, 500, 559, 1023, 1027, 1029, 24, 81, 97, - 146, 156, 169, 174, 203, 246, 250, 321, 336, 371, - 374, 385, 388, 407, 421, 427, 428, 438, 444, 473, - 591, 665, 666, 669, 611, 941, 100, 137, 471, 521, - 536, 551, 560, 562, 583, 586, 587, 596, 597, 601, - 610, 614, 664, 670, 679, 680, 698, 953, 956, 959, - 966, 967, 977, 981, 985, 991, 995, 1000, 1009, 1012, - 1017, 1018, 1020, 108, 75, 66, 79, 81, 159, 232, - 281, 291, 303, 322, 370, 416, 437, 439, 443, 466, - 521, 552, 553, 554, 699, 771, 773, 775, 776, 786, - 793, 794, 852, 854, 855, 108, 5, 553, 555, 993, - 553, 941, 30, 178, 241, 389, 431, 435, 468, 553, - 1010, 1011, 1016, 611, 30, 132, 722, 723, 178, 241, - 374, 389, 431, 468, 986, 987, 1016, 611, 552, 553, - 554, 698, 710, 793, 421, 719, 552, 173, 521, 997, - 521, 346, 711, 712, 941, 711, 699, 700, 1012, 0, - 524, 122, 213, 457, 147, 218, 296, 449, 725, 726, - 776, 776, 699, 701, 703, 525, 471, 975, 214, 30, - 431, 435, 552, 698, 192, 552, 941, 192, 552, 192, - 793, 192, 552, 275, 356, 555, 342, 612, 519, 523, - 556, 557, 521, 82, 108, 174, 203, 246, 374, 385, - 421, 444, 473, 971, 108, 698, 552, 425, 427, 425, - 427, 356, 192, 552, 552, 381, 174, 246, 346, 385, - 421, 473, 677, 203, 30, 941, 192, 559, 252, 438, - 107, 421, 421, 473, 378, 381, 192, 553, 667, 948, - 192, 938, 941, 192, 941, 521, 600, 295, 427, 977, - 3, 466, 978, 980, 981, 983, 984, 1023, 1027, 975, - 553, 555, 968, 521, 521, 167, 521, 699, 794, 521, - 521, 552, 521, 521, 172, 521, 521, 521, 521, 699, - 771, 776, 786, 514, 556, 526, 40, 553, 787, 788, - 787, 383, 525, 702, 521, 699, 793, 794, 37, 42, - 101, 173, 209, 225, 235, 269, 316, 323, 365, 384, - 455, 790, 788, 40, 553, 787, 789, 507, 798, 555, - 510, 521, 521, 954, 1011, 1011, 1011, 504, 224, 1011, - 523, 290, 4, 6, 7, 8, 9, 10, 39, 54, - 56, 57, 65, 71, 72, 83, 112, 115, 117, 136, - 152, 160, 165, 182, 183, 216, 217, 219, 247, 268, - 270, 275, 280, 283, 292, 343, 369, 398, 431, 432, - 440, 454, 467, 505, 512, 513, 514, 519, 521, 527, - 528, 529, 530, 553, 555, 699, 760, 810, 813, 816, - 817, 818, 820, 821, 822, 823, 825, 826, 842, 844, - 845, 846, 847, 848, 849, 850, 851, 852, 853, 855, - 857, 872, 873, 884, 906, 913, 921, 922, 923, 942, - 943, 944, 920, 922, 986, 986, 555, 986, 504, 986, - 172, 433, 510, 612, 556, 793, 1001, 3, 171, 173, - 471, 981, 996, 998, 171, 999, 553, 842, 890, 891, - 711, 525, 521, 950, 522, 522, 522, 535, 172, 295, - 570, 157, 1001, 30, 132, 720, 720, 59, 720, 162, - 167, 238, 287, 731, 733, 734, 763, 765, 766, 767, - 181, 290, 460, 290, 725, 726, 521, 552, 993, 422, - 1015, 504, 224, 152, 26, 32, 137, 294, 354, 358, - 390, 463, 545, 548, 549, 354, 152, 40, 60, 106, - 202, 251, 261, 273, 305, 354, 360, 385, 390, 405, - 548, 602, 605, 152, 354, 390, 548, 152, 354, 390, - 548, 152, 1007, 40, 1008, 291, 488, 842, 914, 558, - 559, 557, 3, 30, 37, 42, 46, 49, 55, 81, - 83, 89, 101, 132, 171, 173, 176, 177, 194, 209, - 222, 223, 225, 235, 237, 247, 269, 278, 300, 302, - 323, 365, 384, 395, 414, 423, 443, 454, 469, 471, - 522, 726, 842, 893, 894, 945, 951, 1023, 1028, 842, - 421, 552, 553, 522, 521, 651, 374, 591, 662, 275, - 957, 40, 192, 553, 590, 473, 192, 552, 192, 552, - 1022, 192, 552, 192, 552, 89, 962, 152, 487, 90, - 129, 308, 426, 192, 553, 152, 523, 949, 63, 361, - 525, 668, 152, 525, 668, 152, 290, 598, 599, 842, - 951, 356, 522, 525, 4, 160, 290, 440, 512, 513, - 555, 604, 607, 944, 976, 978, 979, 982, 977, 433, - 521, 688, 692, 842, 891, 521, 3, 68, 69, 109, + 153, 154, 168, 172, 198, 240, 315, 316, 317, 323, + 326, 357, 366, 382, 389, 393, 403, 415, 419, 439, + 452, 455, 458, 463, 480, 504, 518, 530, 531, 532, + 533, 544, 553, 555, 560, 576, 579, 580, 582, 586, + 587, 591, 598, 600, 603, 604, 652, 658, 667, 668, + 686, 687, 688, 689, 691, 693, 694, 698, 752, 753, + 935, 938, 941, 948, 949, 951, 954, 955, 956, 963, + 967, 973, 974, 977, 982, 986, 987, 988, 991, 994, + 995, 996, 999, 1000, 1002, 433, 483, 601, 203, 373, + 384, 419, 470, 108, 192, 989, 601, 3, 22, 23, + 24, 25, 26, 27, 28, 29, 31, 32, 33, 42, + 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 57, 59, 60, 61, 62, 63, 64, + 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, + 78, 79, 81, 83, 84, 85, 86, 87, 88, 89, + 90, 91, 92, 94, 95, 96, 97, 98, 99, 101, + 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 118, 120, 121, 122, 123, + 124, 125, 128, 129, 130, 131, 134, 135, 136, 137, + 138, 140, 141, 142, 144, 145, 146, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 161, + 163, 164, 165, 166, 168, 170, 171, 173, 174, 175, + 176, 177, 178, 180, 182, 183, 184, 185, 187, 188, + 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, + 200, 201, 202, 203, 204, 205, 206, 208, 209, 210, + 211, 212, 213, 214, 215, 216, 217, 219, 221, 222, + 223, 224, 225, 226, 227, 228, 229, 230, 231, 234, + 235, 236, 237, 239, 240, 241, 242, 243, 244, 245, + 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, + 266, 267, 268, 269, 270, 271, 272, 273, 274, 276, + 277, 278, 279, 281, 282, 283, 284, 285, 286, 288, + 289, 292, 293, 294, 297, 298, 299, 300, 301, 302, + 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, + 313, 314, 319, 320, 321, 322, 323, 324, 325, 326, + 327, 328, 330, 331, 332, 333, 334, 335, 337, 338, + 339, 340, 341, 342, 343, 344, 345, 346, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, + 360, 362, 363, 364, 365, 366, 367, 368, 369, 370, + 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, + 381, 384, 385, 386, 387, 388, 389, 390, 391, 392, + 394, 395, 396, 397, 398, 400, 401, 402, 403, 404, + 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, + 417, 418, 420, 421, 422, 423, 424, 425, 426, 428, + 429, 430, 433, 434, 435, 436, 437, 439, 440, 441, + 442, 443, 444, 445, 446, 449, 450, 451, 453, 454, + 455, 456, 458, 459, 460, 461, 462, 463, 464, 465, + 467, 468, 469, 470, 471, 472, 473, 474, 475, 478, + 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, + 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, + 501, 546, 834, 924, 928, 1005, 1006, 1007, 3, 176, + 247, 412, 546, 950, 1005, 290, 601, 55, 172, 518, + 681, 178, 241, 295, 314, 373, 423, 425, 442, 448, + 451, 584, 650, 947, 5, 30, 326, 546, 547, 923, + 3, 30, 34, 35, 36, 37, 38, 39, 40, 41, + 42, 45, 49, 53, 54, 55, 56, 57, 58, 65, + 66, 71, 72, 74, 79, 80, 81, 82, 83, 89, + 93, 100, 101, 108, 112, 115, 117, 119, 126, 127, + 132, 133, 139, 143, 147, 152, 159, 160, 162, 165, + 167, 169, 171, 172, 173, 176, 177, 179, 181, 182, + 183, 186, 194, 199, 207, 209, 210, 216, 217, 218, + 219, 220, 222, 223, 225, 232, 233, 235, 237, 238, + 247, 268, 269, 270, 274, 275, 278, 280, 281, 283, + 287, 290, 291, 295, 296, 299, 300, 302, 303, 315, + 316, 317, 318, 321, 322, 325, 329, 336, 342, 347, + 361, 364, 368, 382, 383, 390, 393, 394, 397, 399, + 412, 414, 415, 416, 419, 421, 427, 429, 430, 431, + 432, 435, 437, 438, 441, 447, 448, 452, 457, 463, + 464, 466, 468, 476, 477, 479, 480, 487, 488, 489, + 490, 491, 492, 493, 494, 495, 496, 497, 552, 1005, + 1009, 1011, 24, 81, 97, 146, 156, 169, 174, 203, + 246, 250, 320, 335, 370, 373, 384, 387, 405, 419, + 425, 426, 436, 442, 470, 584, 653, 654, 657, 601, + 923, 100, 137, 468, 518, 533, 544, 553, 555, 576, + 579, 580, 586, 587, 591, 600, 604, 652, 658, 667, + 668, 686, 935, 938, 941, 948, 949, 959, 963, 967, + 973, 977, 982, 991, 994, 999, 1000, 1002, 108, 75, + 66, 79, 81, 159, 232, 281, 291, 303, 321, 369, + 414, 435, 437, 441, 463, 518, 545, 546, 547, 687, + 753, 755, 757, 758, 768, 775, 776, 834, 836, 837, + 108, 5, 546, 548, 975, 546, 923, 30, 178, 241, + 388, 429, 433, 465, 546, 992, 993, 998, 601, 30, + 132, 707, 708, 178, 241, 373, 388, 429, 465, 968, + 969, 998, 601, 545, 546, 547, 686, 698, 775, 419, + 704, 545, 173, 518, 979, 518, 345, 699, 700, 923, + 699, 687, 688, 994, 0, 521, 122, 213, 454, 147, + 218, 296, 447, 710, 711, 758, 758, 687, 689, 691, + 522, 468, 957, 214, 30, 429, 433, 545, 686, 192, + 545, 923, 192, 545, 192, 775, 192, 545, 275, 548, + 341, 602, 516, 520, 549, 550, 518, 82, 108, 174, + 203, 246, 373, 384, 419, 442, 470, 953, 108, 686, + 545, 423, 425, 423, 425, 355, 192, 545, 545, 380, + 174, 246, 345, 384, 419, 470, 665, 203, 30, 923, + 192, 552, 252, 436, 107, 419, 419, 470, 377, 380, + 192, 546, 655, 930, 192, 920, 923, 192, 923, 518, + 590, 295, 425, 959, 3, 463, 960, 962, 963, 965, + 966, 1005, 1009, 957, 546, 548, 950, 518, 518, 167, + 518, 687, 776, 518, 518, 545, 518, 518, 172, 518, + 518, 518, 518, 687, 753, 758, 768, 511, 549, 523, + 40, 546, 769, 770, 769, 382, 522, 690, 518, 687, + 775, 776, 37, 42, 101, 173, 209, 225, 235, 269, + 315, 322, 364, 383, 452, 772, 770, 40, 546, 769, + 771, 504, 780, 548, 507, 518, 518, 936, 993, 993, + 993, 501, 224, 993, 520, 290, 4, 6, 7, 8, + 9, 10, 39, 54, 56, 57, 65, 71, 72, 83, + 112, 115, 117, 136, 152, 160, 165, 182, 183, 216, + 217, 219, 247, 268, 270, 275, 280, 283, 292, 342, + 368, 397, 429, 430, 438, 464, 502, 509, 510, 511, + 516, 518, 524, 525, 526, 527, 546, 548, 687, 742, + 792, 795, 798, 799, 800, 802, 803, 804, 805, 807, + 808, 824, 826, 827, 828, 829, 830, 831, 832, 833, + 834, 835, 837, 839, 854, 855, 866, 888, 895, 903, + 904, 905, 924, 925, 926, 902, 904, 968, 968, 548, + 968, 501, 968, 172, 431, 507, 602, 549, 775, 983, + 3, 171, 173, 468, 963, 978, 980, 171, 981, 546, + 824, 872, 873, 699, 522, 518, 932, 519, 519, 519, + 532, 172, 295, 563, 157, 983, 30, 132, 705, 705, + 59, 705, 162, 167, 238, 287, 716, 718, 719, 745, + 747, 748, 749, 181, 290, 457, 290, 710, 711, 518, + 545, 975, 420, 997, 501, 224, 152, 26, 32, 137, + 294, 353, 357, 389, 460, 538, 541, 542, 353, 152, + 40, 60, 106, 202, 251, 261, 273, 305, 353, 359, + 384, 389, 403, 541, 592, 595, 152, 353, 389, 541, + 152, 353, 389, 541, 152, 40, 990, 291, 485, 824, + 896, 551, 552, 550, 3, 30, 37, 42, 49, 55, + 81, 83, 89, 101, 132, 171, 173, 176, 177, 194, + 209, 222, 223, 225, 235, 237, 247, 269, 278, 300, + 302, 322, 364, 383, 394, 412, 421, 441, 466, 468, + 519, 711, 824, 875, 876, 927, 933, 1005, 1010, 824, + 419, 545, 546, 519, 518, 639, 373, 584, 650, 275, + 939, 40, 192, 546, 583, 470, 192, 545, 192, 545, + 1004, 192, 545, 192, 545, 89, 944, 152, 484, 90, + 129, 308, 424, 192, 546, 152, 520, 931, 63, 360, + 522, 656, 152, 522, 656, 152, 290, 588, 589, 824, + 933, 355, 519, 522, 4, 160, 290, 438, 509, 510, + 548, 594, 597, 926, 958, 960, 961, 964, 959, 431, + 518, 676, 680, 824, 873, 518, 3, 68, 69, 109, 110, 113, 114, 189, 190, 253, 254, 255, 256, 257, - 258, 259, 260, 263, 264, 338, 339, 379, 380, 477, - 478, 501, 502, 555, 828, 829, 830, 831, 832, 833, - 834, 835, 836, 837, 838, 839, 840, 896, 897, 788, - 789, 842, 552, 842, 898, 512, 513, 553, 843, 844, - 873, 884, 900, 521, 842, 890, 901, 842, 58, 172, - 233, 434, 842, 891, 904, 842, 522, 554, 521, 423, - 740, 741, 741, 722, 723, 776, 220, 717, 786, 741, - 46, 745, 741, 225, 37, 225, 384, 790, 225, 300, - 791, 776, 791, 225, 790, 521, 225, 791, 225, 148, - 200, 778, 225, 745, 521, 554, 521, 741, 297, 842, - 988, 990, 893, 3, 37, 42, 46, 49, 54, 55, - 56, 57, 71, 72, 81, 83, 89, 101, 112, 115, - 165, 171, 173, 177, 194, 209, 216, 217, 219, 222, - 223, 225, 235, 237, 247, 268, 269, 270, 278, 283, - 300, 302, 323, 343, 365, 369, 384, 391, 395, 398, - 414, 423, 431, 432, 443, 449, 454, 467, 471, 804, - 806, 807, 809, 811, 813, 815, 817, 818, 819, 821, - 822, 825, 826, 895, 947, 1023, 1026, 40, 236, 553, - 521, 519, 699, 470, 824, 842, 910, 824, 824, 521, - 521, 812, 812, 326, 699, 521, 814, 530, 71, 72, - 824, 842, 812, 521, 521, 485, 507, 521, 827, 521, - 827, 521, 842, 842, 842, 83, 148, 924, 928, 842, - 891, 892, 699, 842, 890, 559, 9, 554, 874, 875, - 876, 523, 526, 556, 915, 556, 521, 555, 521, 521, - 555, 944, 3, 8, 11, 15, 16, 17, 18, 19, - 20, 21, 36, 40, 46, 53, 80, 177, 194, 199, - 222, 223, 237, 275, 278, 292, 295, 395, 505, 508, - 509, 510, 512, 513, 514, 515, 516, 517, 882, 883, - 884, 886, 918, 484, 858, 302, 842, 525, 717, 521, - 555, 717, 3, 117, 241, 555, 604, 826, 989, 104, - 990, 990, 40, 553, 522, 525, 975, 525, 522, 712, - 938, 939, 460, 713, 1001, 193, 356, 220, 651, 390, - 701, 701, 30, 727, 728, 842, 59, 701, 721, 164, - 272, 751, 227, 273, 342, 393, 457, 4, 9, 30, - 746, 842, 512, 513, 747, 748, 842, 844, 763, 764, - 734, 733, 731, 732, 167, 766, 285, 768, 59, 707, - 708, 709, 779, 843, 922, 922, 731, 763, 891, 950, - 172, 472, 994, 236, 552, 74, 82, 93, 169, 192, - 330, 450, 543, 544, 553, 631, 658, 82, 93, 561, - 93, 561, 521, 433, 311, 401, 521, 629, 245, 311, - 401, 453, 629, 93, 525, 433, 552, 3, 809, 604, - 59, 606, 604, 604, 106, 251, 261, 59, 433, 483, - 507, 603, 266, 374, 603, 605, 793, 93, 433, 561, - 374, 552, 433, 374, 1007, 555, 553, 688, 520, 526, - 893, 893, 894, 193, 359, 724, 525, 725, 726, 13, - 14, 222, 222, 433, 433, 553, 650, 655, 483, 691, - 552, 381, 346, 385, 421, 473, 677, 152, 100, 587, - 614, 958, 959, 1018, 144, 806, 275, 199, 592, 552, - 275, 588, 602, 275, 521, 651, 40, 275, 651, 275, - 521, 671, 672, 673, 674, 675, 676, 678, 192, 553, - 645, 963, 559, 152, 172, 609, 667, 558, 523, 948, - 938, 941, 941, 948, 522, 525, 13, 977, 983, 4, - 944, 4, 944, 555, 559, 690, 697, 55, 102, 123, - 141, 145, 168, 171, 187, 280, 288, 310, 340, 694, - 40, 522, 842, 522, 172, 525, 522, 319, 899, 522, - 843, 843, 11, 15, 16, 19, 20, 21, 199, 222, - 292, 508, 509, 510, 512, 513, 514, 515, 516, 517, - 884, 843, 522, 795, 796, 854, 167, 172, 902, 903, - 525, 522, 40, 904, 891, 904, 904, 172, 522, 40, - 787, 521, 939, 4, 9, 553, 735, 736, 738, 739, - 847, 922, 920, 178, 241, 421, 425, 427, 453, 552, - 718, 480, 799, 522, 521, 741, 776, 776, 225, 776, - 290, 460, 792, 776, 225, 922, 776, 776, 282, 282, - 521, 776, 741, 554, 800, 801, 521, 554, 800, 525, - 522, 525, 523, 521, 809, 521, 521, 523, 39, 808, - 521, 828, 829, 830, 831, 832, 833, 834, 835, 836, - 837, 838, 839, 840, 841, 522, 525, 812, 562, 567, - 679, 680, 698, 955, 1000, 1012, 891, 892, 521, 479, - 907, 908, 842, 892, 944, 842, 877, 878, 879, 880, - 824, 824, 8, 15, 16, 19, 20, 21, 508, 509, - 510, 512, 513, 514, 515, 516, 517, 553, 882, 887, - 522, 891, 431, 431, 944, 944, 842, 521, 521, 554, - 925, 356, 932, 167, 520, 522, 525, 526, 525, 531, - 514, 842, 557, 891, 944, 842, 841, 841, 806, 842, - 842, 842, 842, 842, 842, 842, 842, 5, 559, 952, - 431, 45, 418, 919, 948, 842, 842, 521, 699, 848, - 905, 913, 132, 160, 275, 280, 285, 440, 451, 842, - 280, 521, 842, 433, 53, 177, 194, 199, 237, 395, - 842, 842, 842, 842, 842, 842, 842, 842, 842, 842, - 30, 38, 400, 881, 519, 523, 917, 181, 163, 859, - 369, 521, 873, 923, 172, 772, 893, 772, 521, 555, - 553, 552, 996, 552, 1004, 842, 525, 522, 227, 40, - 460, 1003, 552, 564, 521, 553, 569, 579, 580, 582, - 41, 126, 729, 525, 460, 729, 266, 701, 369, 370, - 512, 513, 748, 750, 844, 393, 227, 291, 314, 314, - 525, 516, 4, 749, 944, 749, 369, 370, 750, 552, - 937, 279, 397, 769, 521, 939, 940, 525, 181, 460, - 199, 181, 220, 764, 732, 522, 553, 555, 553, 555, - 354, 548, 521, 192, 544, 941, 227, 275, 227, 460, - 521, 634, 641, 642, 805, 806, 523, 541, 542, 941, - 553, 192, 941, 192, 543, 26, 137, 390, 540, 547, - 559, 625, 639, 941, 59, 59, 559, 633, 654, 59, - 59, 941, 545, 941, 354, 390, 548, 602, 604, 948, - 941, 604, 948, 941, 604, 354, 390, 548, 941, 941, - 543, 941, 354, 390, 548, 941, 941, 555, 1008, 513, - 842, 914, 725, 725, 725, 282, 282, 522, 469, 894, - 724, 842, 842, 280, 555, 970, 280, 970, 553, 335, - 687, 522, 525, 288, 172, 433, 682, 957, 590, 473, - 552, 552, 1022, 552, 552, 552, 295, 662, 521, 699, - 152, 3, 521, 521, 152, 152, 237, 553, 631, 643, - 646, 649, 659, 661, 483, 485, 636, 151, 698, 152, - 483, 964, 152, 522, 893, 525, 525, 40, 275, 290, - 553, 3, 668, 558, 668, 290, 668, 598, 842, 688, - 247, 514, 519, 521, 604, 689, 849, 850, 851, 982, - 522, 525, 40, 686, 555, 686, 275, 280, 340, 686, - 59, 686, 806, 522, 842, 842, 842, 902, 806, 843, - 843, 843, 843, 843, 843, 132, 275, 285, 843, 843, - 843, 843, 843, 843, 843, 843, 843, 843, 522, 525, - 40, 797, 842, 842, 903, 902, 806, 522, 522, 522, - 891, 806, 939, 522, 314, 370, 516, 521, 521, 717, - 425, 427, 425, 427, 552, 719, 719, 719, 842, 181, - 752, 432, 472, 743, 744, 792, 792, 776, 842, 521, - 776, 167, 792, 521, 554, 783, 792, 806, 522, 525, - 800, 522, 988, 3, 895, 39, 808, 553, 803, 803, - 3, 519, 519, 944, 433, 433, 433, 433, 806, 457, - 522, 520, 891, 842, 139, 908, 909, 522, 522, 522, - 526, 525, 531, 523, 522, 522, 504, 504, 522, 522, - 522, 842, 925, 926, 927, 523, 521, 842, 929, 354, - 936, 553, 856, 911, 912, 842, 842, 874, 928, 522, - 522, 522, 504, 843, 843, 145, 891, 172, 132, 160, - 280, 285, 440, 451, 521, 145, 887, 842, 418, 919, - 842, 905, 842, 433, 521, 699, 842, 914, 558, 521, - 521, 155, 860, 773, 774, 799, 725, 799, 944, 841, - 950, 950, 521, 250, 275, 716, 774, 480, 1002, 40, - 59, 565, 575, 582, 915, 525, 772, 510, 506, 730, - 728, 292, 882, 885, 730, 4, 944, 750, 291, 457, - 747, 525, 244, 939, 707, 59, 922, 521, 554, 59, - 266, 994, 994, 433, 842, 275, 658, 521, 152, 521, - 634, 203, 655, 656, 615, 40, 176, 624, 652, 558, - 542, 615, 26, 137, 358, 360, 390, 537, 538, 539, - 549, 550, 152, 668, 152, 668, 625, 639, 625, 522, - 525, 555, 618, 510, 523, 522, 525, 521, 521, 433, - 374, 93, 433, 561, 374, 433, 433, 433, 374, 1008, - 688, 526, 520, 526, 724, 724, 724, 894, 522, 521, - 681, 3, 408, 409, 555, 696, 650, 687, 592, 552, - 588, 521, 40, 651, 674, 676, 957, 356, 421, 555, - 584, 585, 590, 559, 594, 595, 655, 552, 552, 1022, - 552, 641, 642, 522, 525, 288, 629, 288, 290, 628, - 941, 483, 1021, 552, 629, 40, 552, 522, 672, 678, - 675, 678, 421, 842, 152, 552, 609, 948, 684, 695, - 982, 690, 555, 555, 280, 655, 514, 655, 555, 514, - 655, 555, 522, 522, 903, 172, 132, 285, 521, 798, - 795, 521, 522, 522, 522, 553, 736, 799, 719, 719, - 719, 719, 552, 552, 552, 59, 186, 761, 14, 522, - 792, 939, 521, 780, 781, 782, 845, 848, 939, 167, - 80, 802, 801, 522, 522, 519, 806, 522, 525, 522, - 944, 520, 944, 522, 829, 831, 832, 833, 832, 833, - 833, 522, 429, 842, 143, 842, 877, 887, 827, 827, - 522, 525, 522, 554, 842, 929, 930, 931, 40, 521, - 925, 933, 199, 525, 522, 932, 841, 842, 36, 36, - 842, 522, 842, 172, 521, 895, 842, 522, 145, 843, - 843, 145, 145, 842, 842, 520, 526, 521, 916, 726, - 480, 842, 301, 864, 525, 752, 724, 752, 522, 714, - 715, 912, 250, 521, 842, 362, 573, 553, 266, 322, - 117, 304, 521, 563, 698, 522, 525, 569, 1002, 842, - 164, 231, 521, 730, 291, 552, 522, 940, 181, 699, - 700, 922, 940, 941, 941, 522, 152, 656, 544, 656, - 615, 645, 525, 522, 119, 207, 273, 275, 640, 521, - 33, 59, 663, 652, 74, 80, 93, 117, 119, 207, - 275, 280, 330, 348, 450, 460, 620, 621, 635, 176, - 117, 191, 275, 629, 603, 107, 117, 176, 275, 407, - 410, 605, 629, 390, 539, 444, 941, 543, 547, 3, - 37, 42, 46, 49, 55, 81, 83, 89, 101, 171, - 173, 176, 177, 194, 209, 222, 223, 225, 235, 237, - 247, 269, 274, 278, 292, 300, 302, 323, 365, 384, - 391, 395, 414, 423, 443, 449, 454, 471, 512, 513, - 555, 604, 616, 657, 806, 885, 945, 1023, 1029, 559, - 654, 891, 727, 941, 941, 941, 941, 543, 941, 941, - 941, 941, 941, 688, 914, 914, 522, 522, 522, 725, - 107, 374, 523, 603, 696, 521, 521, 649, 698, 964, - 662, 192, 552, 522, 525, 592, 593, 842, 522, 525, - 522, 588, 521, 40, 638, 636, 553, 646, 86, 600, - 107, 273, 651, 698, 674, 676, 40, 40, 699, 700, - 645, 460, 961, 668, 522, 525, 655, 843, 172, 521, - 895, 800, 522, 525, 522, 752, 552, 552, 552, 552, - 30, 103, 182, 368, 521, 753, 754, 755, 756, 757, - 758, 759, 842, 842, 482, 861, 842, 522, 844, 888, - 889, 199, 181, 777, 781, 522, 783, 784, 785, 948, - 808, 944, 808, 553, 808, 520, 520, 842, 925, 525, - 522, 553, 933, 934, 935, 40, 842, 844, 912, 936, - 842, 842, 842, 895, 522, 842, 36, 36, 842, 842, - 145, 522, 513, 914, 522, 893, 522, 842, 522, 521, - 553, 865, 761, 522, 761, 555, 522, 525, 955, 921, - 466, 420, 459, 574, 553, 568, 578, 290, 571, 510, - 582, 573, 887, 59, 522, 522, 465, 466, 704, 615, - 544, 522, 522, 483, 648, 120, 195, 205, 119, 462, - 842, 117, 40, 521, 948, 941, 843, 120, 195, 119, - 280, 227, 552, 648, 88, 663, 192, 280, 604, 842, - 663, 280, 512, 513, 607, 553, 805, 806, 668, 668, - 3, 247, 414, 945, 949, 510, 522, 522, 433, 433, - 520, 520, 724, 522, 522, 553, 688, 460, 683, 685, - 595, 655, 522, 1021, 40, 421, 275, 521, 555, 521, - 594, 964, 649, 151, 698, 149, 201, 628, 122, 137, - 329, 1021, 107, 964, 483, 1019, 421, 290, 553, 960, - 521, 695, 843, 895, 522, 522, 9, 355, 742, 761, - 521, 392, 521, 522, 525, 553, 862, 863, 337, 762, - 525, 522, 521, 554, 59, 522, 199, 522, 784, 520, - 806, 929, 525, 522, 553, 520, 192, 522, 842, 842, - 842, 526, 520, 526, 522, 522, 553, 866, 861, 555, - 861, 912, 522, 525, 465, 915, 522, 525, 91, 573, - 842, 522, 940, 940, 348, 648, 521, 637, 615, 522, - 191, 521, 842, 275, 621, 648, 651, 941, 40, 152, - 802, 949, 516, 616, 941, 941, 522, 603, 124, 522, - 522, 636, 698, 552, 152, 595, 40, 522, 941, 1021, - 30, 85, 94, 118, 191, 204, 407, 410, 632, 632, - 370, 370, 40, 64, 74, 241, 699, 552, 521, 553, - 572, 581, 854, 522, 522, 521, 861, 891, 521, 891, - 755, 40, 525, 842, 460, 737, 844, 922, 939, 788, - 521, 788, 933, 842, 914, 914, 310, 867, 762, 762, - 698, 304, 698, 568, 290, 521, 566, 552, 615, 559, - 644, 647, 411, 475, 622, 623, 521, 617, 842, 522, - 249, 660, 191, 460, 546, 516, 444, 688, 555, 964, - 628, 1019, 521, 552, 522, 698, 636, 600, 698, 74, - 293, 74, 961, 842, 80, 576, 522, 525, 576, 9, - 762, 522, 754, 522, 865, 863, 372, 522, 922, 520, - 520, 520, 59, 725, 737, 737, 574, 93, 581, 133, - 651, 510, 522, 525, 602, 522, 273, 630, 173, 309, - 396, 290, 626, 627, 653, 617, 842, 444, 40, 521, - 1019, 628, 1021, 1019, 293, 293, 521, 522, 948, 577, - 948, 964, 572, 577, 522, 737, 522, 739, 522, 890, - 184, 341, 370, 868, 465, 941, 522, 276, 457, 660, - 616, 647, 522, 623, 205, 122, 457, 290, 653, 290, - 626, 698, 581, 576, 729, 799, 729, 53, 104, 446, - 842, 869, 870, 869, 869, 522, 698, 799, 390, 627, - 63, 273, 361, 390, 619, 619, 1019, 522, 577, 730, - 730, 870, 369, 166, 325, 166, 325, 148, 871, 871, - 871, 580, 615, 25, 117, 280, 964, 729, 36, 104, - 181, 273, 430, 799, 799, 730, 870, 369, 298 + 258, 259, 260, 263, 264, 337, 338, 378, 379, 474, + 475, 498, 499, 548, 810, 811, 812, 813, 814, 815, + 816, 817, 818, 819, 820, 821, 822, 878, 879, 770, + 771, 824, 545, 824, 880, 509, 510, 546, 825, 826, + 855, 866, 882, 518, 824, 872, 883, 824, 58, 172, + 233, 432, 824, 873, 886, 824, 519, 547, 518, 421, + 725, 726, 726, 707, 708, 758, 220, 702, 768, 726, + 726, 726, 225, 37, 225, 383, 772, 225, 300, 773, + 758, 773, 225, 772, 518, 225, 773, 225, 148, 200, + 760, 225, 726, 518, 547, 518, 726, 297, 824, 970, + 972, 875, 3, 37, 42, 49, 54, 55, 56, 57, + 71, 72, 81, 83, 89, 101, 112, 115, 165, 171, + 173, 177, 194, 209, 216, 217, 219, 222, 223, 225, + 235, 237, 247, 268, 269, 270, 278, 283, 300, 302, + 322, 342, 364, 368, 383, 390, 394, 397, 412, 421, + 429, 430, 441, 447, 464, 468, 786, 788, 789, 791, + 793, 795, 797, 799, 800, 801, 803, 804, 807, 808, + 877, 929, 1005, 1008, 40, 236, 546, 518, 516, 687, + 467, 806, 824, 892, 806, 806, 518, 518, 794, 794, + 325, 687, 518, 796, 527, 71, 72, 806, 824, 794, + 518, 518, 482, 504, 518, 809, 518, 809, 824, 824, + 824, 83, 148, 906, 910, 824, 873, 874, 687, 824, + 872, 552, 9, 547, 856, 857, 858, 520, 523, 549, + 897, 549, 518, 548, 518, 518, 548, 926, 3, 8, + 11, 15, 16, 17, 18, 19, 20, 21, 36, 40, + 46, 53, 80, 177, 194, 199, 222, 223, 237, 275, + 278, 292, 295, 394, 502, 505, 506, 507, 509, 510, + 511, 512, 513, 514, 864, 865, 866, 868, 900, 481, + 840, 302, 824, 522, 702, 518, 548, 702, 3, 117, + 241, 548, 594, 808, 971, 104, 972, 972, 40, 546, + 519, 522, 957, 522, 519, 700, 920, 921, 40, 983, + 193, 355, 220, 639, 389, 689, 689, 30, 712, 713, + 824, 59, 689, 706, 164, 272, 733, 227, 273, 341, + 392, 454, 4, 9, 30, 728, 824, 509, 510, 729, + 730, 824, 826, 745, 746, 719, 718, 716, 717, 167, + 748, 285, 750, 59, 695, 696, 697, 761, 825, 904, + 904, 716, 745, 873, 932, 172, 469, 976, 236, 545, + 74, 82, 93, 169, 192, 329, 448, 546, 621, 631, + 646, 82, 93, 554, 93, 554, 518, 431, 518, 619, + 245, 451, 619, 93, 522, 431, 545, 3, 791, 594, + 59, 596, 594, 594, 106, 251, 261, 59, 431, 480, + 504, 593, 266, 373, 593, 595, 775, 93, 431, 554, + 373, 545, 431, 373, 989, 546, 676, 517, 523, 875, + 875, 876, 193, 358, 709, 522, 710, 711, 13, 14, + 222, 222, 431, 431, 546, 638, 643, 480, 679, 545, + 380, 345, 384, 419, 470, 665, 152, 100, 580, 604, + 940, 941, 1000, 144, 788, 275, 199, 585, 545, 275, + 581, 592, 275, 518, 639, 40, 275, 639, 275, 518, + 659, 660, 661, 662, 663, 664, 666, 192, 546, 633, + 945, 552, 152, 172, 599, 655, 551, 520, 930, 920, + 923, 923, 930, 519, 522, 13, 959, 965, 4, 926, + 4, 926, 548, 552, 678, 685, 55, 102, 123, 141, + 145, 168, 171, 187, 280, 288, 310, 339, 682, 40, + 519, 824, 519, 172, 522, 519, 318, 881, 519, 825, + 825, 11, 15, 16, 19, 20, 21, 199, 222, 292, + 505, 506, 507, 509, 510, 511, 512, 513, 514, 866, + 825, 519, 777, 778, 836, 167, 172, 884, 885, 522, + 519, 40, 886, 873, 886, 886, 172, 519, 40, 769, + 518, 921, 4, 9, 546, 720, 721, 723, 724, 829, + 904, 902, 178, 241, 419, 423, 425, 451, 545, 703, + 477, 781, 519, 758, 758, 225, 758, 290, 457, 774, + 758, 225, 904, 758, 758, 282, 282, 518, 758, 547, + 782, 783, 518, 547, 782, 522, 519, 522, 520, 518, + 791, 518, 518, 520, 39, 790, 518, 810, 811, 812, + 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, + 823, 519, 522, 794, 555, 560, 667, 668, 686, 937, + 982, 994, 873, 874, 518, 476, 889, 890, 824, 874, + 926, 824, 859, 860, 861, 862, 806, 806, 8, 15, + 16, 19, 20, 21, 505, 506, 507, 509, 510, 511, + 512, 513, 514, 546, 864, 869, 519, 873, 429, 429, + 926, 926, 518, 518, 547, 907, 355, 914, 167, 517, + 519, 522, 523, 522, 528, 511, 824, 550, 873, 926, + 824, 823, 823, 788, 824, 824, 824, 824, 824, 824, + 824, 824, 5, 552, 934, 429, 45, 416, 901, 930, + 824, 824, 518, 687, 830, 887, 895, 132, 160, 275, + 280, 285, 438, 449, 824, 280, 518, 824, 431, 53, + 177, 194, 199, 237, 394, 824, 824, 824, 824, 824, + 824, 824, 824, 824, 824, 30, 38, 399, 863, 516, + 520, 899, 181, 163, 841, 368, 518, 855, 905, 172, + 754, 875, 754, 518, 548, 546, 545, 978, 545, 986, + 824, 522, 519, 250, 275, 701, 457, 985, 545, 557, + 518, 546, 562, 572, 573, 575, 41, 126, 714, 522, + 457, 714, 266, 689, 368, 369, 509, 510, 730, 732, + 826, 392, 227, 291, 313, 313, 522, 513, 4, 731, + 926, 731, 368, 369, 732, 545, 919, 279, 396, 751, + 518, 921, 922, 522, 181, 457, 199, 181, 220, 746, + 717, 519, 546, 548, 546, 548, 353, 541, 518, 192, + 631, 923, 227, 275, 227, 457, 518, 624, 787, 788, + 923, 546, 192, 923, 192, 546, 26, 137, 389, 537, + 540, 552, 615, 629, 923, 552, 623, 642, 923, 538, + 923, 353, 389, 541, 592, 594, 930, 923, 594, 930, + 923, 594, 353, 389, 541, 923, 923, 923, 923, 353, + 389, 541, 923, 923, 548, 510, 824, 896, 710, 710, + 710, 282, 282, 519, 466, 876, 709, 824, 824, 280, + 548, 952, 280, 952, 546, 334, 675, 519, 522, 288, + 172, 431, 670, 939, 583, 470, 545, 545, 1004, 545, + 545, 545, 295, 650, 518, 687, 152, 3, 518, 518, + 152, 152, 237, 546, 621, 631, 634, 637, 647, 649, + 480, 482, 626, 151, 686, 152, 480, 946, 152, 519, + 875, 522, 522, 40, 275, 290, 546, 3, 656, 551, + 656, 290, 656, 588, 824, 676, 247, 511, 516, 518, + 594, 677, 831, 832, 833, 964, 519, 522, 40, 674, + 548, 674, 275, 280, 339, 674, 59, 674, 788, 519, + 824, 824, 824, 884, 788, 825, 825, 825, 825, 825, + 825, 132, 275, 285, 825, 825, 825, 825, 825, 825, + 825, 825, 825, 825, 519, 522, 40, 779, 824, 824, + 885, 884, 788, 519, 519, 519, 873, 788, 921, 519, + 313, 369, 513, 518, 518, 702, 423, 425, 423, 425, + 545, 704, 704, 704, 824, 181, 734, 774, 774, 758, + 824, 518, 758, 167, 774, 518, 547, 765, 774, 788, + 519, 522, 782, 519, 970, 3, 877, 39, 790, 546, + 785, 785, 3, 516, 516, 926, 431, 431, 431, 431, + 788, 454, 519, 517, 873, 824, 139, 890, 891, 519, + 519, 519, 523, 522, 528, 520, 519, 519, 501, 501, + 519, 519, 824, 907, 908, 909, 520, 518, 824, 911, + 353, 918, 546, 838, 893, 894, 824, 824, 856, 910, + 519, 519, 519, 501, 825, 825, 145, 873, 172, 132, + 160, 280, 285, 438, 449, 518, 145, 869, 824, 416, + 901, 824, 887, 824, 431, 518, 687, 824, 896, 551, + 518, 518, 155, 842, 755, 756, 781, 710, 781, 926, + 823, 932, 932, 250, 518, 756, 477, 984, 40, 59, + 558, 568, 575, 897, 522, 754, 507, 503, 715, 713, + 292, 864, 867, 715, 4, 926, 732, 291, 454, 729, + 522, 244, 921, 695, 59, 904, 518, 547, 59, 266, + 976, 976, 431, 824, 275, 646, 518, 152, 518, 624, + 203, 643, 644, 605, 40, 176, 614, 640, 605, 26, + 137, 357, 359, 389, 534, 535, 536, 542, 543, 152, + 656, 152, 656, 615, 629, 615, 519, 522, 548, 608, + 507, 520, 519, 522, 431, 373, 93, 431, 554, 373, + 431, 431, 431, 373, 990, 523, 517, 523, 709, 709, + 709, 876, 519, 518, 669, 3, 406, 407, 548, 684, + 638, 675, 585, 545, 581, 518, 40, 639, 662, 664, + 939, 355, 419, 548, 577, 578, 583, 685, 643, 545, + 545, 1004, 545, 519, 522, 288, 619, 288, 290, 618, + 923, 480, 1003, 545, 619, 40, 545, 519, 660, 666, + 663, 666, 419, 824, 152, 545, 599, 930, 672, 683, + 964, 678, 548, 548, 280, 643, 511, 643, 548, 511, + 643, 548, 519, 519, 885, 172, 132, 285, 518, 780, + 777, 518, 519, 519, 519, 546, 721, 781, 704, 704, + 704, 704, 545, 545, 545, 59, 186, 743, 774, 921, + 518, 762, 763, 764, 827, 830, 921, 167, 80, 784, + 783, 519, 519, 516, 788, 519, 522, 519, 926, 517, + 926, 519, 811, 813, 814, 815, 814, 815, 815, 519, + 427, 824, 143, 824, 859, 869, 809, 809, 519, 522, + 519, 547, 824, 911, 912, 913, 40, 518, 907, 915, + 199, 522, 519, 914, 823, 824, 36, 36, 824, 519, + 824, 172, 518, 877, 824, 519, 145, 825, 825, 145, + 145, 824, 824, 517, 523, 518, 898, 711, 477, 824, + 301, 846, 522, 734, 709, 734, 519, 937, 824, 361, + 566, 546, 266, 321, 117, 304, 518, 556, 686, 519, + 522, 562, 984, 824, 164, 231, 518, 715, 291, 545, + 519, 922, 181, 687, 688, 904, 922, 923, 923, 519, + 152, 644, 631, 644, 605, 633, 522, 519, 119, 207, + 273, 275, 630, 518, 33, 59, 651, 640, 74, 80, + 93, 117, 119, 207, 275, 280, 329, 347, 448, 457, + 610, 611, 625, 176, 117, 191, 275, 619, 593, 107, + 117, 176, 275, 405, 408, 595, 619, 389, 536, 442, + 923, 546, 540, 3, 37, 42, 49, 55, 81, 83, + 89, 101, 171, 173, 176, 177, 194, 209, 222, 223, + 225, 235, 237, 247, 269, 274, 278, 292, 300, 302, + 322, 364, 383, 390, 394, 412, 421, 441, 447, 468, + 509, 510, 548, 594, 606, 645, 788, 867, 927, 1005, + 1011, 552, 642, 923, 923, 923, 923, 923, 923, 923, + 923, 923, 923, 676, 896, 896, 519, 519, 519, 710, + 107, 373, 520, 593, 684, 518, 518, 637, 686, 946, + 650, 192, 545, 519, 522, 585, 519, 519, 581, 518, + 40, 628, 626, 634, 86, 590, 107, 273, 639, 686, + 662, 664, 40, 40, 687, 688, 633, 457, 943, 656, + 519, 522, 643, 825, 172, 518, 877, 782, 519, 522, + 519, 734, 545, 545, 545, 545, 30, 103, 182, 367, + 518, 735, 736, 737, 738, 739, 740, 741, 824, 824, + 479, 843, 519, 826, 870, 871, 199, 181, 759, 763, + 519, 765, 766, 767, 930, 790, 926, 790, 546, 790, + 517, 517, 824, 907, 522, 519, 546, 915, 916, 917, + 40, 824, 826, 894, 918, 824, 824, 824, 877, 519, + 824, 36, 36, 824, 824, 145, 519, 510, 896, 519, + 875, 519, 824, 519, 518, 546, 847, 743, 519, 743, + 548, 519, 903, 463, 418, 456, 567, 546, 561, 571, + 290, 564, 507, 575, 566, 869, 59, 519, 519, 462, + 463, 692, 605, 631, 519, 519, 480, 636, 120, 195, + 205, 119, 459, 824, 117, 40, 518, 930, 923, 825, + 120, 195, 119, 280, 227, 545, 636, 88, 651, 192, + 280, 594, 824, 651, 280, 509, 510, 597, 546, 787, + 788, 656, 656, 3, 247, 412, 927, 931, 507, 431, + 431, 517, 517, 709, 519, 519, 546, 676, 457, 671, + 673, 685, 643, 519, 1003, 40, 419, 275, 518, 548, + 518, 946, 637, 151, 686, 149, 201, 618, 122, 137, + 328, 1003, 107, 946, 480, 1001, 419, 290, 546, 942, + 518, 683, 825, 877, 519, 519, 9, 354, 727, 743, + 518, 391, 518, 519, 522, 546, 844, 845, 336, 744, + 522, 519, 518, 547, 59, 519, 199, 519, 766, 517, + 788, 911, 522, 519, 546, 517, 192, 519, 824, 824, + 824, 523, 517, 523, 519, 519, 546, 848, 843, 548, + 843, 522, 462, 897, 519, 522, 91, 566, 824, 519, + 922, 922, 347, 636, 518, 627, 605, 519, 191, 518, + 824, 275, 611, 636, 639, 923, 40, 152, 784, 931, + 513, 606, 923, 923, 519, 593, 124, 519, 519, 626, + 686, 545, 152, 685, 40, 519, 923, 1003, 30, 85, + 94, 118, 191, 204, 405, 408, 622, 622, 369, 369, + 40, 64, 74, 241, 687, 545, 518, 546, 565, 574, + 836, 519, 519, 518, 843, 873, 518, 873, 737, 40, + 522, 824, 457, 722, 826, 904, 921, 770, 518, 770, + 915, 824, 896, 896, 310, 849, 744, 744, 686, 304, + 686, 561, 290, 518, 559, 545, 605, 552, 632, 635, + 409, 472, 612, 613, 518, 607, 824, 519, 249, 648, + 191, 457, 539, 513, 442, 676, 548, 946, 618, 1001, + 518, 545, 519, 686, 626, 590, 686, 74, 293, 74, + 943, 824, 80, 569, 519, 522, 569, 9, 744, 519, + 736, 519, 847, 845, 371, 519, 904, 517, 517, 517, + 59, 710, 722, 722, 567, 93, 574, 133, 639, 507, + 519, 522, 592, 519, 273, 620, 173, 309, 395, 290, + 616, 617, 641, 607, 824, 442, 40, 518, 1001, 618, + 1003, 1001, 293, 293, 518, 519, 930, 570, 930, 946, + 565, 570, 519, 722, 519, 724, 519, 872, 184, 340, + 369, 850, 462, 923, 519, 276, 454, 648, 606, 635, + 519, 613, 205, 122, 454, 290, 641, 290, 616, 686, + 574, 569, 714, 781, 714, 53, 104, 444, 824, 851, + 852, 851, 851, 519, 686, 781, 389, 617, 63, 273, + 360, 389, 609, 609, 1001, 519, 570, 715, 715, 852, + 368, 166, 324, 166, 324, 148, 853, 853, 853, 573, + 605, 25, 117, 280, 946, 714, 36, 104, 181, 273, + 428, 781, 781, 715, 852, 368, 298 }; #define yyerrok (yyerrstatus = 0) @@ -20757,14 +20541,14 @@ YYLTYPE yylloc; switch (yyn) { case 2: -#line 514 "third_party/libpg_query/grammar/grammar.y" +#line 510 "third_party/libpg_query/grammar/grammar.y" { pg_yyget_extra(yyscanner)->parsetree = (yyvsp[(1) - (1)].list); ;} break; case 3: -#line 530 "third_party/libpg_query/grammar/grammar.y" +#line 526 "third_party/libpg_query/grammar/grammar.y" { if ((yyvsp[(1) - (3)].list) != NIL) { @@ -20779,7 +20563,7 @@ YYLTYPE yylloc; break; case 4: -#line 542 "third_party/libpg_query/grammar/grammar.y" +#line 538 "third_party/libpg_query/grammar/grammar.y" { if ((yyvsp[(1) - (1)].node) != NULL) (yyval.list) = list_make1(makeRawStmt((yyvsp[(1) - (1)].node), 0)); @@ -20789,7 +20573,7 @@ YYLTYPE yylloc; break; case 46: -#line 592 "third_party/libpg_query/grammar/grammar.y" +#line 588 "third_party/libpg_query/grammar/grammar.y" { (yyval.node) = NULL; ;} break; @@ -20937,158 +20721,73 @@ YYLTYPE yylloc; ;} break; - case 62: -#line 119 "third_party/libpg_query/grammar/statements/alter_table.y" - { - (yyval.defelt) = makeDefElem("generated", (PGNode *) makeInteger((yyvsp[(3) - (3)].ival)), (yylsp[(1) - (3)])); - ;} - break; - - case 63: -#line 127 "third_party/libpg_query/grammar/statements/alter_table.y" - { - (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); - ;} - break; - - case 64: -#line 131 "third_party/libpg_query/grammar/statements/alter_table.y" - { - (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].defelt)); - ;} - break; - - case 65: -#line 138 "third_party/libpg_query/grammar/statements/alter_table.y" - { (yyval.list) = list_make1((yyvsp[(1) - (1)].str)); ;} - break; - - case 66: -#line 139 "third_party/libpg_query/grammar/statements/alter_table.y" - { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].str)); ;} - break; - - case 67: -#line 144 "third_party/libpg_query/grammar/statements/alter_table.y" - { - (yyval.str) = (yyvsp[(2) - (2)].str); - ;} - break; - - case 68: -#line 150 "third_party/libpg_query/grammar/statements/alter_table.y" - { (yyval.list) = list_make1((yyvsp[(1) - (1)].str)); ;} - break; - - case 69: -#line 151 "third_party/libpg_query/grammar/statements/alter_table.y" - { (yyval.list) = list_concat(list_make1((yyvsp[(1) - (2)].str)), (yyvsp[(2) - (2)].list)); ;} - break; - - case 70: -#line 157 "third_party/libpg_query/grammar/statements/alter_table.y" - { - PGColumnDef *n = (PGColumnDef *) (yyvsp[(2) - (2)].node); - n->location = (yylsp[(1) - (2)]); - (yyval.list) = list_make2((yyvsp[(1) - (2)].list), n); - ;} - break; - - case 71: -#line 164 "third_party/libpg_query/grammar/statements/alter_table.y" - { - PGColumnDef *n = (PGColumnDef *) (yyvsp[(2) - (2)].node); - n->location = (yylsp[(1) - (2)]); - (yyval.list) = list_make2((yyvsp[(1) - (2)].list), n); - ;} - break; - - case 72: -#line 174 "third_party/libpg_query/grammar/statements/alter_table.y" - { - PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_AddColumn; - n->def_list = (yyvsp[(2) - (2)].list); - n->missing_ok = false; - (yyval.node) = (PGNode *)n; - ;} - break; - - case 73: -#line 183 "third_party/libpg_query/grammar/statements/alter_table.y" + case 62: +#line 119 "third_party/libpg_query/grammar/statements/alter_table.y" { - PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_AddColumn; - n->def_list = (yyvsp[(5) - (5)].list); - n->missing_ok = true; - (yyval.node) = (PGNode *)n; + (yyval.defelt) = makeDefElem("generated", (PGNode *) makeInteger((yyvsp[(3) - (3)].ival)), (yylsp[(1) - (3)])); ;} break; - case 74: -#line 192 "third_party/libpg_query/grammar/statements/alter_table.y" + case 63: +#line 127 "third_party/libpg_query/grammar/statements/alter_table.y" { - PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_AddColumn; - n->def_list = (yyvsp[(3) - (3)].list); - n->missing_ok = false; - (yyval.node) = (PGNode *)n; + (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); ;} break; - case 75: -#line 201 "third_party/libpg_query/grammar/statements/alter_table.y" + case 64: +#line 131 "third_party/libpg_query/grammar/statements/alter_table.y" { - PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_AddColumn; - n->def_list = (yyvsp[(6) - (6)].list); - n->missing_ok = true; - (yyval.node) = (PGNode *)n; + (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].defelt)); ;} break; - case 76: -#line 210 "third_party/libpg_query/grammar/statements/alter_table.y" + case 65: +#line 140 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_SetPartitionedBy; - n->def_list = (yyvsp[(5) - (6)].list); + n->subtype = PG_AT_AddColumn; + n->def = (yyvsp[(2) - (2)].node); + n->missing_ok = false; (yyval.node) = (PGNode *)n; ;} break; - case 77: -#line 218 "third_party/libpg_query/grammar/statements/alter_table.y" + case 66: +#line 149 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_SetPartitionedBy; - n->def_list = NULL; + n->subtype = PG_AT_AddColumn; + n->def = (yyvsp[(5) - (5)].node); + n->missing_ok = true; (yyval.node) = (PGNode *)n; ;} break; - case 78: -#line 226 "third_party/libpg_query/grammar/statements/alter_table.y" + case 67: +#line 158 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_SetSortedBy; - n->def_list = (yyvsp[(5) - (6)].list); + n->subtype = PG_AT_AddColumn; + n->def = (yyvsp[(3) - (3)].node); + n->missing_ok = false; (yyval.node) = (PGNode *)n; ;} break; - case 79: -#line 234 "third_party/libpg_query/grammar/statements/alter_table.y" + case 68: +#line 167 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); - n->subtype = PG_AT_SetSortedBy; - n->def_list = NULL; + n->subtype = PG_AT_AddColumn; + n->def = (yyvsp[(6) - (6)].node); + n->missing_ok = true; (yyval.node) = (PGNode *)n; ;} break; - case 80: -#line 242 "third_party/libpg_query/grammar/statements/alter_table.y" + case 69: +#line 176 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_ColumnDefault; @@ -21098,8 +20797,8 @@ YYLTYPE yylloc; ;} break; - case 81: -#line 251 "third_party/libpg_query/grammar/statements/alter_table.y" + case 70: +#line 185 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_DropNotNull; @@ -21108,8 +20807,8 @@ YYLTYPE yylloc; ;} break; - case 82: -#line 259 "third_party/libpg_query/grammar/statements/alter_table.y" + case 71: +#line 193 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetNotNull; @@ -21118,8 +20817,8 @@ YYLTYPE yylloc; ;} break; - case 83: -#line 267 "third_party/libpg_query/grammar/statements/alter_table.y" + case 72: +#line 201 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetStatistics; @@ -21129,8 +20828,8 @@ YYLTYPE yylloc; ;} break; - case 84: -#line 276 "third_party/libpg_query/grammar/statements/alter_table.y" + case 73: +#line 210 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetOptions; @@ -21140,8 +20839,8 @@ YYLTYPE yylloc; ;} break; - case 85: -#line 285 "third_party/libpg_query/grammar/statements/alter_table.y" + case 74: +#line 219 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_ResetOptions; @@ -21151,8 +20850,8 @@ YYLTYPE yylloc; ;} break; - case 86: -#line 294 "third_party/libpg_query/grammar/statements/alter_table.y" + case 75: +#line 228 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetStorage; @@ -21162,8 +20861,8 @@ YYLTYPE yylloc; ;} break; - case 87: -#line 303 "third_party/libpg_query/grammar/statements/alter_table.y" + case 76: +#line 237 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); PGConstraint *c = makeNode(PGConstraint); @@ -21181,8 +20880,8 @@ YYLTYPE yylloc; ;} break; - case 88: -#line 320 "third_party/libpg_query/grammar/statements/alter_table.y" + case 77: +#line 254 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetIdentity; @@ -21192,8 +20891,8 @@ YYLTYPE yylloc; ;} break; - case 89: -#line 329 "third_party/libpg_query/grammar/statements/alter_table.y" + case 78: +#line 263 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = AT_DropIdentity; @@ -21203,8 +20902,8 @@ YYLTYPE yylloc; ;} break; - case 90: -#line 338 "third_party/libpg_query/grammar/statements/alter_table.y" + case 79: +#line 272 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = AT_DropIdentity; @@ -21214,32 +20913,32 @@ YYLTYPE yylloc; ;} break; - case 91: -#line 347 "third_party/libpg_query/grammar/statements/alter_table.y" + case 80: +#line 281 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_DropColumn; - n->def_list = (yyvsp[(5) - (6)].list); + n->name = (yyvsp[(5) - (6)].str); n->behavior = (yyvsp[(6) - (6)].dbehavior); n->missing_ok = true; (yyval.node) = (PGNode *)n; ;} break; - case 92: -#line 357 "third_party/libpg_query/grammar/statements/alter_table.y" + case 81: +#line 291 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_DropColumn; - n->def_list = (yyvsp[(3) - (4)].list); + n->name = (yyvsp[(3) - (4)].str); n->behavior = (yyvsp[(4) - (4)].dbehavior); n->missing_ok = false; (yyval.node) = (PGNode *)n; ;} break; - case 93: -#line 370 "third_party/libpg_query/grammar/statements/alter_table.y" + case 82: +#line 304 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); PGColumnDef *def = makeNode(PGColumnDef); @@ -21255,8 +20954,8 @@ YYLTYPE yylloc; ;} break; - case 94: -#line 385 "third_party/libpg_query/grammar/statements/alter_table.y" + case 83: +#line 319 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_AlterColumnGenericOptions; @@ -21266,8 +20965,8 @@ YYLTYPE yylloc; ;} break; - case 95: -#line 394 "third_party/libpg_query/grammar/statements/alter_table.y" + case 84: +#line 328 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_AddConstraint; @@ -21276,8 +20975,8 @@ YYLTYPE yylloc; ;} break; - case 96: -#line 402 "third_party/libpg_query/grammar/statements/alter_table.y" + case 85: +#line 336 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); PGConstraint *c = makeNode(PGConstraint); @@ -21293,8 +20992,8 @@ YYLTYPE yylloc; ;} break; - case 97: -#line 417 "third_party/libpg_query/grammar/statements/alter_table.y" + case 86: +#line 351 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_ValidateConstraint; @@ -21303,8 +21002,8 @@ YYLTYPE yylloc; ;} break; - case 98: -#line 425 "third_party/libpg_query/grammar/statements/alter_table.y" + case 87: +#line 359 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_DropConstraint; @@ -21315,8 +21014,8 @@ YYLTYPE yylloc; ;} break; - case 99: -#line 435 "third_party/libpg_query/grammar/statements/alter_table.y" + case 88: +#line 369 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_DropConstraint; @@ -21327,8 +21026,8 @@ YYLTYPE yylloc; ;} break; - case 100: -#line 445 "third_party/libpg_query/grammar/statements/alter_table.y" + case 89: +#line 379 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetLogged; @@ -21336,8 +21035,8 @@ YYLTYPE yylloc; ;} break; - case 101: -#line 452 "third_party/libpg_query/grammar/statements/alter_table.y" + case 90: +#line 386 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetUnLogged; @@ -21345,8 +21044,8 @@ YYLTYPE yylloc; ;} break; - case 102: -#line 459 "third_party/libpg_query/grammar/statements/alter_table.y" + case 91: +#line 393 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_SetRelOptions; @@ -21355,8 +21054,8 @@ YYLTYPE yylloc; ;} break; - case 103: -#line 467 "third_party/libpg_query/grammar/statements/alter_table.y" + case 92: +#line 401 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_ResetRelOptions; @@ -21365,8 +21064,8 @@ YYLTYPE yylloc; ;} break; - case 104: -#line 474 "third_party/libpg_query/grammar/statements/alter_table.y" + case 93: +#line 408 "third_party/libpg_query/grammar/statements/alter_table.y" { PGAlterTableCmd *n = makeNode(PGAlterTableCmd); n->subtype = PG_AT_GenericOptions; @@ -21375,77 +21074,77 @@ YYLTYPE yylloc; ;} break; - case 105: -#line 484 "third_party/libpg_query/grammar/statements/alter_table.y" + case 94: +#line 418 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 106: -#line 485 "third_party/libpg_query/grammar/statements/alter_table.y" + case 95: +#line 419 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.node) = NULL; ;} break; - case 107: -#line 491 "third_party/libpg_query/grammar/statements/alter_table.y" + case 96: +#line 425 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.defelt) = (yyvsp[(1) - (1)].defelt); ;} break; - case 108: -#line 495 "third_party/libpg_query/grammar/statements/alter_table.y" + case 97: +#line 429 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.defelt) = (yyvsp[(2) - (2)].defelt); (yyval.defelt)->defaction = PG_DEFELEM_SET; ;} break; - case 109: -#line 500 "third_party/libpg_query/grammar/statements/alter_table.y" + case 98: +#line 434 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.defelt) = (yyvsp[(2) - (2)].defelt); (yyval.defelt)->defaction = PG_DEFELEM_ADD; ;} break; - case 110: -#line 505 "third_party/libpg_query/grammar/statements/alter_table.y" + case 99: +#line 439 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.defelt) = makeDefElemExtended(NULL, (yyvsp[(2) - (2)].str), NULL, DEFELEM_DROP, (yylsp[(2) - (2)])); ;} break; - case 111: -#line 512 "third_party/libpg_query/grammar/statements/alter_table.y" + case 100: +#line 446 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 112: -#line 513 "third_party/libpg_query/grammar/statements/alter_table.y" + case 101: +#line 447 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 113: -#line 518 "third_party/libpg_query/grammar/statements/alter_table.y" + case 102: +#line 452 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 114: -#line 522 "third_party/libpg_query/grammar/statements/alter_table.y" + case 103: +#line 456 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.ival) = 1; ;} break; - case 115: -#line 523 "third_party/libpg_query/grammar/statements/alter_table.y" + case 104: +#line 457 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.ival) = 0; ;} break; - case 116: -#line 524 "third_party/libpg_query/grammar/statements/alter_table.y" + case 105: +#line 458 "third_party/libpg_query/grammar/statements/alter_table.y" { (yyval.ival) = 0; ;} break; - case 117: + case 106: #line 8 "third_party/libpg_query/grammar/statements/deallocate.y" { PGDeallocateStmt *n = makeNode(PGDeallocateStmt); @@ -21454,7 +21153,7 @@ YYLTYPE yylloc; ;} break; - case 118: + case 107: #line 14 "third_party/libpg_query/grammar/statements/deallocate.y" { PGDeallocateStmt *n = makeNode(PGDeallocateStmt); @@ -21463,7 +21162,7 @@ YYLTYPE yylloc; ;} break; - case 119: + case 108: #line 20 "third_party/libpg_query/grammar/statements/deallocate.y" { PGDeallocateStmt *n = makeNode(PGDeallocateStmt); @@ -21472,7 +21171,7 @@ YYLTYPE yylloc; ;} break; - case 120: + case 109: #line 26 "third_party/libpg_query/grammar/statements/deallocate.y" { PGDeallocateStmt *n = makeNode(PGDeallocateStmt); @@ -21481,14 +21180,14 @@ YYLTYPE yylloc; ;} break; - case 121: + case 110: #line 10 "third_party/libpg_query/grammar/statements/common.y" { (yyval.range) = makeRangeVar(NULL, (yyvsp[(1) - (1)].str), (yylsp[(1) - (1)])); ;} break; - case 122: + case 111: #line 14 "third_party/libpg_query/grammar/statements/common.y" { check_qualified_name((yyvsp[(2) - (2)].list), yyscanner); @@ -21517,79 +21216,79 @@ YYLTYPE yylloc; ;} break; - case 123: + case 112: #line 44 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 124: + case 113: #line 45 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 125: + case 114: #line 46 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 126: + case 115: #line 50 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 127: + case 116: #line 51 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 128: + case 117: #line 55 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 129: + case 118: #line 59 "third_party/libpg_query/grammar/statements/common.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 130: + case 119: #line 60 "third_party/libpg_query/grammar/statements/common.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 131: + case 120: #line 65 "third_party/libpg_query/grammar/statements/common.y" { (yyval.node) = (PGNode *) makeString((yyvsp[(2) - (2)].str)); ;} break; - case 132: + case 121: #line 70 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 133: + case 122: #line 75 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 134: + case 123: #line 76 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 135: + case 124: #line 77 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 136: + case 125: #line 78 "third_party/libpg_query/grammar/statements/common.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 137: + case 126: #line 7 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21601,7 +21300,7 @@ YYLTYPE yylloc; ;} break; - case 138: + case 127: #line 16 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21614,7 +21313,7 @@ YYLTYPE yylloc; ;} break; - case 139: + case 128: #line 26 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21627,7 +21326,7 @@ YYLTYPE yylloc; ;} break; - case 140: + case 129: #line 36 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21640,7 +21339,7 @@ YYLTYPE yylloc; ;} break; - case 141: + case 130: #line 46 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21653,7 +21352,7 @@ YYLTYPE yylloc; ;} break; - case 142: + case 131: #line 56 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21666,7 +21365,7 @@ YYLTYPE yylloc; ;} break; - case 143: + case 132: #line 66 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21679,7 +21378,7 @@ YYLTYPE yylloc; ;} break; - case 144: + case 133: #line 76 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21692,7 +21391,7 @@ YYLTYPE yylloc; ;} break; - case 145: + case 134: #line 86 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21705,35 +21404,35 @@ YYLTYPE yylloc; ;} break; - case 146: + case 135: #line 96 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); n->renameType = PG_OBJECT_COLUMN; n->relationType = PG_OBJECT_TABLE; n->relation = (yyvsp[(3) - (8)].range); - n->name_list = (yyvsp[(6) - (8)].list); + n->subname = (yyvsp[(6) - (8)].str); n->newname = (yyvsp[(8) - (8)].str); n->missing_ok = false; (yyval.node) = (PGNode *)n; ;} break; - case 147: + case 136: #line 107 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); n->renameType = PG_OBJECT_COLUMN; n->relationType = PG_OBJECT_TABLE; n->relation = (yyvsp[(5) - (10)].range); - n->name_list = (yyvsp[(8) - (10)].list); + n->subname = (yyvsp[(8) - (10)].str); n->newname = (yyvsp[(10) - (10)].str); n->missing_ok = true; (yyval.node) = (PGNode *)n; ;} break; - case 148: + case 137: #line 118 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21746,7 +21445,7 @@ YYLTYPE yylloc; ;} break; - case 149: + case 138: #line 128 "third_party/libpg_query/grammar/statements/rename.y" { PGRenameStmt *n = makeNode(PGRenameStmt); @@ -21759,17 +21458,17 @@ YYLTYPE yylloc; ;} break; - case 150: + case 139: #line 140 "third_party/libpg_query/grammar/statements/rename.y" { (yyval.ival) = COLUMN; ;} break; - case 151: + case 140: #line 141 "third_party/libpg_query/grammar/statements/rename.y" { (yyval.ival) = 0; ;} break; - case 152: + case 141: #line 11 "third_party/libpg_query/grammar/statements/insert.y" { (yyvsp[(7) - (9)].istmt)->relation = (yyvsp[(5) - (9)].range); @@ -21782,7 +21481,7 @@ YYLTYPE yylloc; ;} break; - case 153: + case 142: #line 24 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.istmt) = makeNode(PGInsertStmt); @@ -21791,7 +21490,7 @@ YYLTYPE yylloc; ;} break; - case 154: + case 143: #line 30 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.istmt) = makeNode(PGInsertStmt); @@ -21801,7 +21500,7 @@ YYLTYPE yylloc; ;} break; - case 155: + case 144: #line 37 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.istmt) = makeNode(PGInsertStmt); @@ -21810,7 +21509,7 @@ YYLTYPE yylloc; ;} break; - case 156: + case 145: #line 43 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.istmt) = makeNode(PGInsertStmt); @@ -21820,7 +21519,7 @@ YYLTYPE yylloc; ;} break; - case 157: + case 146: #line 50 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.istmt) = makeNode(PGInsertStmt); @@ -21829,14 +21528,14 @@ YYLTYPE yylloc; ;} break; - case 158: + case 147: #line 60 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.range) = (yyvsp[(1) - (1)].range); ;} break; - case 159: + case 148: #line 64 "third_party/libpg_query/grammar/statements/insert.y" { (yyvsp[(1) - (3)].range)->alias = makeAlias((yyvsp[(3) - (3)].str), NIL); @@ -21844,22 +21543,22 @@ YYLTYPE yylloc; ;} break; - case 160: + case 149: #line 71 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.bynameorposition) = PG_INSERT_BY_NAME; ;} break; - case 161: + case 150: #line 72 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.bynameorposition) = PG_INSERT_BY_POSITION; ;} break; - case 162: + case 151: #line 73 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.bynameorposition) = PG_INSERT_BY_POSITION; ;} break; - case 163: + case 152: #line 78 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.infer) = makeNode(PGInferClause); @@ -21870,7 +21569,7 @@ YYLTYPE yylloc; ;} break; - case 164: + case 153: #line 87 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.infer) = makeNode(PGInferClause); @@ -21881,24 +21580,24 @@ YYLTYPE yylloc; ;} break; - case 165: + case 154: #line 95 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.infer) = NULL; ;} break; - case 166: + case 155: #line 102 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.with) = (yyvsp[(1) - (1)].with); ;} break; - case 167: + case 156: #line 103 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.with) = NULL; ;} break; - case 168: + case 157: #line 109 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.target) = makeNode(PGResTarget); @@ -21909,7 +21608,7 @@ YYLTYPE yylloc; ;} break; - case 169: + case 158: #line 121 "third_party/libpg_query/grammar/statements/insert.y" { (yyvsp[(1) - (3)].target)->val = (PGNode *) (yyvsp[(3) - (3)].node); @@ -21917,7 +21616,7 @@ YYLTYPE yylloc; ;} break; - case 170: + case 159: #line 126 "third_party/libpg_query/grammar/statements/insert.y" { int ncolumns = list_length((yyvsp[(2) - (5)].list)); @@ -21941,28 +21640,28 @@ YYLTYPE yylloc; ;} break; - case 171: + case 160: #line 151 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.onconflictshorthand) = PG_ONCONFLICT_ALIAS_REPLACE; ;} break; - case 172: + case 161: #line 156 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.onconflictshorthand) = PG_ONCONFLICT_ALIAS_IGNORE; ;} break; - case 173: + case 162: #line 160 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.onconflictshorthand) = PG_ONCONFLICT_ALIAS_NONE; ;} break; - case 174: + case 163: #line 167 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.onconflict) = makeNode(PGOnConflictClause); @@ -21974,7 +21673,7 @@ YYLTYPE yylloc; ;} break; - case 175: + case 164: #line 177 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.onconflict) = makeNode(PGOnConflictClause); @@ -21986,14 +21685,14 @@ YYLTYPE yylloc; ;} break; - case 176: + case 165: #line 186 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.onconflict) = NULL; ;} break; - case 177: + case 166: #line 193 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.ielem) = makeNode(PGIndexElem); @@ -22007,7 +21706,7 @@ YYLTYPE yylloc; ;} break; - case 178: + case 167: #line 204 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.ielem) = makeNode(PGIndexElem); @@ -22021,7 +21720,7 @@ YYLTYPE yylloc; ;} break; - case 179: + case 168: #line 215 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.ielem) = makeNode(PGIndexElem); @@ -22035,97 +21734,97 @@ YYLTYPE yylloc; ;} break; - case 180: + case 169: #line 229 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 181: + case 170: #line 230 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = NIL; ;} break; - case 182: + case 171: #line 236 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.override) = PG_OVERRIDING_USER_VALUE; ;} break; - case 183: + case 172: #line 237 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.override) = OVERRIDING_SYSTEM_VALUE; ;} break; - case 184: + case 173: #line 242 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].target)); ;} break; - case 185: + case 174: #line 243 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list),(yyvsp[(3) - (3)].target)); ;} break; - case 186: + case 175: #line 249 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 187: + case 176: #line 250 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = NIL; ;} break; - case 188: + case 177: #line 254 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 189: + case 178: #line 255 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = NIL; ;} break; - case 190: + case 179: #line 261 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].target)); ;} break; - case 191: + case 180: #line 263 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].target)); ;} break; - case 192: + case 181: #line 268 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 193: + case 182: #line 269 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = list_concat((yyvsp[(1) - (3)].list),(yyvsp[(3) - (3)].list)); ;} break; - case 194: + case 183: #line 273 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 195: + case 184: #line 274 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 196: + case 185: #line 277 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].ielem)); ;} break; - case 197: + case 186: #line 278 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].ielem)); ;} break; - case 198: + case 187: #line 284 "third_party/libpg_query/grammar/statements/insert.y" { (yyval.target) = makeNode(PGResTarget); @@ -22136,7 +21835,7 @@ YYLTYPE yylloc; ;} break; - case 199: + case 188: #line 8 "third_party/libpg_query/grammar/statements/create_type.y" { PGCreateTypeStmt *n = makeNode(PGCreateTypeStmt); @@ -22148,7 +21847,7 @@ YYLTYPE yylloc; ;} break; - case 200: + case 189: #line 17 "third_party/libpg_query/grammar/statements/create_type.y" { PGCreateTypeStmt *n = makeNode(PGCreateTypeStmt); @@ -22160,7 +21859,7 @@ YYLTYPE yylloc; ;} break; - case 201: + case 190: #line 26 "third_party/libpg_query/grammar/statements/create_type.y" { PGCreateTypeStmt *n = makeNode(PGCreateTypeStmt); @@ -22178,31 +21877,31 @@ YYLTYPE yylloc; ;} break; - case 202: + case 191: #line 46 "third_party/libpg_query/grammar/statements/create_type.y" { (yyval.list) = (yyvsp[(1) - (1)].list);;} break; - case 203: + case 192: #line 47 "third_party/libpg_query/grammar/statements/create_type.y" {(yyval.list) = NIL;;} break; - case 204: + case 193: #line 51 "third_party/libpg_query/grammar/statements/create_type.y" { (yyval.list) = list_make1(makeStringConst((yyvsp[(1) - (1)].str), (yylsp[(1) - (1)]))); ;} break; - case 205: + case 194: #line 55 "third_party/libpg_query/grammar/statements/create_type.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), makeStringConst((yyvsp[(3) - (3)].str), (yylsp[(3) - (3)]))); ;} break; - case 206: + case 195: #line 8 "third_party/libpg_query/grammar/statements/pragma.y" { PGPragmaStmt *n = makeNode(PGPragmaStmt); @@ -22212,7 +21911,7 @@ YYLTYPE yylloc; ;} break; - case 207: + case 196: #line 15 "third_party/libpg_query/grammar/statements/pragma.y" { PGPragmaStmt *n = makeNode(PGPragmaStmt); @@ -22223,7 +21922,7 @@ YYLTYPE yylloc; ;} break; - case 208: + case 197: #line 23 "third_party/libpg_query/grammar/statements/pragma.y" { PGPragmaStmt *n = makeNode(PGPragmaStmt); @@ -22234,7 +21933,7 @@ YYLTYPE yylloc; ;} break; - case 209: + case 198: #line 10 "third_party/libpg_query/grammar/statements/create_sequence.y" { PGCreateSeqStmt *n = makeNode(PGCreateSeqStmt); @@ -22247,7 +21946,7 @@ YYLTYPE yylloc; ;} break; - case 210: + case 199: #line 20 "third_party/libpg_query/grammar/statements/create_sequence.y" { PGCreateSeqStmt *n = makeNode(PGCreateSeqStmt); @@ -22260,7 +21959,7 @@ YYLTYPE yylloc; ;} break; - case 211: + case 200: #line 30 "third_party/libpg_query/grammar/statements/create_sequence.y" { PGCreateSeqStmt *n = makeNode(PGCreateSeqStmt); @@ -22273,17 +21972,17 @@ YYLTYPE yylloc; ;} break; - case 212: + case 201: #line 42 "third_party/libpg_query/grammar/statements/create_sequence.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 213: + case 202: #line 43 "third_party/libpg_query/grammar/statements/create_sequence.y" { (yyval.list) = NIL; ;} break; - case 214: + case 203: #line 8 "third_party/libpg_query/grammar/statements/create_secret.y" { PGCreateSecretStmt *n = makeNode(PGCreateSecretStmt); @@ -22296,7 +21995,7 @@ YYLTYPE yylloc; ;} break; - case 215: + case 204: #line 18 "third_party/libpg_query/grammar/statements/create_secret.y" { PGCreateSecretStmt *n = makeNode(PGCreateSecretStmt); @@ -22309,7 +22008,7 @@ YYLTYPE yylloc; ;} break; - case 216: + case 205: #line 28 "third_party/libpg_query/grammar/statements/create_secret.y" { PGCreateSecretStmt *n = makeNode(PGCreateSecretStmt); @@ -22322,68 +22021,42 @@ YYLTYPE yylloc; ;} break; - case 217: + case 206: #line 40 "third_party/libpg_query/grammar/statements/create_secret.y" { (yyval.str) = NULL; ;} break; - case 218: + case 207: #line 41 "third_party/libpg_query/grammar/statements/create_secret.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 219: + case 208: #line 45 "third_party/libpg_query/grammar/statements/create_secret.y" { (yyval.str) = pstrdup("default"); ;} break; - case 220: + case 209: #line 46 "third_party/libpg_query/grammar/statements/create_secret.y" { (yyval.str) = pstrdup("temporary"); ;} break; - case 221: + case 210: #line 47 "third_party/libpg_query/grammar/statements/create_secret.y" { (yyval.str) = pstrdup("persistent"); ;} break; - case 222: + case 211: #line 51 "third_party/libpg_query/grammar/statements/create_secret.y" { (yyval.str) = pstrdup(""); ;} break; - case 223: + case 212: #line 52 "third_party/libpg_query/grammar/statements/create_secret.y" { (yyval.str) = (yyvsp[(2) - (2)].str); ;} break; - case 224: -#line 57 "third_party/libpg_query/grammar/statements/create_secret.y" - { (yyval.node) = (PGNode *) (yyvsp[(1) - (1)].node); ;} - break; - - case 225: -#line 62 "third_party/libpg_query/grammar/statements/create_secret.y" - { - (yyval.defelt) = makeDefElem((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); - ;} - break; - - case 226: -#line 69 "third_party/libpg_query/grammar/statements/create_secret.y" - { - (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); - ;} - break; - - case 227: -#line 73 "third_party/libpg_query/grammar/statements/create_secret.y" - { - (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].defelt)); - ;} - break; - - case 228: + case 213: #line 8 "third_party/libpg_query/grammar/statements/update_extensions.y" { PGUpdateExtensionsStmt *n = makeNode(PGUpdateExtensionsStmt); @@ -22401,7 +22074,7 @@ YYLTYPE yylloc; ;} break; - case 229: + case 214: #line 8 "third_party/libpg_query/grammar/statements/execute.y" { PGExecuteStmt *n = makeNode(PGExecuteStmt); @@ -22411,7 +22084,7 @@ YYLTYPE yylloc; ;} break; - case 230: + case 215: #line 16 "third_party/libpg_query/grammar/statements/execute.y" { PGCreateTableAsStmt *ctas = makeNode(PGCreateTableAsStmt); @@ -22430,7 +22103,7 @@ YYLTYPE yylloc; ;} break; - case 231: + case 216: #line 33 "third_party/libpg_query/grammar/statements/execute.y" { PGCreateTableAsStmt *ctas = makeNode(PGCreateTableAsStmt); @@ -22449,14 +22122,14 @@ YYLTYPE yylloc; ;} break; - case 232: + case 217: #line 52 "third_party/libpg_query/grammar/statements/execute.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 233: + case 218: #line 56 "third_party/libpg_query/grammar/statements/execute.y" { PGNamedArgExpr *na = makeNode(PGNamedArgExpr); @@ -22468,31 +22141,31 @@ YYLTYPE yylloc; ;} break; - case 234: + case 219: #line 66 "third_party/libpg_query/grammar/statements/execute.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 235: + case 220: #line 70 "third_party/libpg_query/grammar/statements/execute.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 236: + case 221: #line 75 "third_party/libpg_query/grammar/statements/execute.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 237: + case 222: #line 76 "third_party/libpg_query/grammar/statements/execute.y" { (yyval.list) = NIL; ;} break; - case 238: + case 223: #line 10 "third_party/libpg_query/grammar/statements/alter_sequence.y" { PGAlterSeqStmt *n = makeNode(PGAlterSeqStmt); @@ -22503,7 +22176,7 @@ YYLTYPE yylloc; ;} break; - case 239: + case 224: #line 18 "third_party/libpg_query/grammar/statements/alter_sequence.y" { PGAlterSeqStmt *n = makeNode(PGAlterSeqStmt); @@ -22514,42 +22187,42 @@ YYLTYPE yylloc; ;} break; - case 240: + case 225: #line 29 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); ;} break; - case 241: + case 226: #line 30 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].defelt)); ;} break; - case 242: + case 227: #line 34 "third_party/libpg_query/grammar/statements/alter_sequence.y" {;} break; - case 243: + case 228: #line 35 "third_party/libpg_query/grammar/statements/alter_sequence.y" {;} break; - case 244: + case 229: #line 36 "third_party/libpg_query/grammar/statements/alter_sequence.y" {;} break; - case 245: + case 230: #line 41 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.value) = makeFloat((yyvsp[(1) - (1)].str)); ;} break; - case 246: + case 231: #line 42 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.value) = makeFloat((yyvsp[(2) - (2)].str)); ;} break; - case 247: + case 232: #line 44 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.value) = makeFloat((yyvsp[(2) - (2)].str)); @@ -22557,82 +22230,82 @@ YYLTYPE yylloc; ;} break; - case 248: + case 233: #line 48 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.value) = makeInteger((yyvsp[(1) - (1)].ival)); ;} break; - case 249: + case 234: #line 53 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("as", (PGNode *)(yyvsp[(2) - (2)].typnam), (yylsp[(1) - (2)])); ;} break; - case 250: + case 235: #line 57 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("cache", (PGNode *)(yyvsp[(2) - (2)].value), (yylsp[(1) - (2)])); ;} break; - case 251: + case 236: #line 61 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("cycle", (PGNode *)makeInteger(true), (yylsp[(1) - (1)])); ;} break; - case 252: + case 237: #line 65 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("cycle", (PGNode *)makeInteger(false), (yylsp[(1) - (2)])); ;} break; - case 253: + case 238: #line 69 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("increment", (PGNode *)(yyvsp[(3) - (3)].value), (yylsp[(1) - (3)])); ;} break; - case 254: + case 239: #line 73 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("maxvalue", (PGNode *)(yyvsp[(2) - (2)].value), (yylsp[(1) - (2)])); ;} break; - case 255: + case 240: #line 77 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("minvalue", (PGNode *)(yyvsp[(2) - (2)].value), (yylsp[(1) - (2)])); ;} break; - case 256: + case 241: #line 81 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("maxvalue", NULL, (yylsp[(1) - (2)])); ;} break; - case 257: + case 242: #line 85 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("minvalue", NULL, (yylsp[(1) - (2)])); ;} break; - case 258: + case 243: #line 89 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("owned_by", (PGNode *)(yyvsp[(3) - (3)].list), (yylsp[(1) - (3)])); ;} break; - case 259: + case 244: #line 93 "third_party/libpg_query/grammar/statements/alter_sequence.y" { /* not documented, only used by pg_dump */ @@ -22640,53 +22313,53 @@ YYLTYPE yylloc; ;} break; - case 260: + case 245: #line 98 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("start", (PGNode *)(yyvsp[(3) - (3)].value), (yylsp[(1) - (3)])); ;} break; - case 261: + case 246: #line 102 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("restart", NULL, (yylsp[(1) - (1)])); ;} break; - case 262: + case 247: #line 106 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.defelt) = makeDefElem("restart", (PGNode *)(yyvsp[(3) - (3)].value), (yylsp[(1) - (3)])); ;} break; - case 263: + case 248: #line 112 "third_party/libpg_query/grammar/statements/alter_sequence.y" {;} break; - case 264: + case 249: #line 113 "third_party/libpg_query/grammar/statements/alter_sequence.y" {;} break; - case 265: + case 250: #line 117 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.ival) = (yyvsp[(1) - (1)].ival); ;} break; - case 266: + case 251: #line 118 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.ival) = + (yyvsp[(2) - (2)].ival); ;} break; - case 267: + case 252: #line 119 "third_party/libpg_query/grammar/statements/alter_sequence.y" { (yyval.ival) = - (yyvsp[(2) - (2)].ival); ;} break; - case 268: + case 253: #line 8 "third_party/libpg_query/grammar/statements/drop_secret.y" { PGDropSecretStmt *n = makeNode(PGDropSecretStmt); @@ -22698,7 +22371,7 @@ YYLTYPE yylloc; ;} break; - case 269: + case 254: #line 17 "third_party/libpg_query/grammar/statements/drop_secret.y" { PGDropSecretStmt *n = makeNode(PGDropSecretStmt); @@ -22710,17 +22383,17 @@ YYLTYPE yylloc; ;} break; - case 270: + case 255: #line 28 "third_party/libpg_query/grammar/statements/drop_secret.y" { (yyval.str) = pstrdup(""); ;} break; - case 271: + case 256: #line 29 "third_party/libpg_query/grammar/statements/drop_secret.y" { (yyval.str) = (yyvsp[(2) - (2)].str); ;} break; - case 272: + case 257: #line 3 "third_party/libpg_query/grammar/statements/transaction.y" { PGTransactionStmt *n = makeNode(PGTransactionStmt); @@ -22731,7 +22404,7 @@ YYLTYPE yylloc; ;} break; - case 273: + case 258: #line 11 "third_party/libpg_query/grammar/statements/transaction.y" { PGTransactionStmt *n = makeNode(PGTransactionStmt); @@ -22741,7 +22414,7 @@ YYLTYPE yylloc; ;} break; - case 274: + case 259: #line 18 "third_party/libpg_query/grammar/statements/transaction.y" { PGTransactionStmt *n = makeNode(PGTransactionStmt); @@ -22751,7 +22424,7 @@ YYLTYPE yylloc; ;} break; - case 275: + case 260: #line 25 "third_party/libpg_query/grammar/statements/transaction.y" { PGTransactionStmt *n = makeNode(PGTransactionStmt); @@ -22762,7 +22435,7 @@ YYLTYPE yylloc; ;} break; - case 276: + case 261: #line 33 "third_party/libpg_query/grammar/statements/transaction.y" { PGTransactionStmt *n = makeNode(PGTransactionStmt); @@ -22773,7 +22446,7 @@ YYLTYPE yylloc; ;} break; - case 277: + case 262: #line 41 "third_party/libpg_query/grammar/statements/transaction.y" { PGTransactionStmt *n = makeNode(PGTransactionStmt); @@ -22784,37 +22457,37 @@ YYLTYPE yylloc; ;} break; - case 278: + case 263: #line 51 "third_party/libpg_query/grammar/statements/transaction.y" {;} break; - case 279: + case 264: #line 52 "third_party/libpg_query/grammar/statements/transaction.y" {;} break; - case 280: + case 265: #line 53 "third_party/libpg_query/grammar/statements/transaction.y" {;} break; - case 281: + case 266: #line 57 "third_party/libpg_query/grammar/statements/transaction.y" { (yyval.transactiontype) = PG_TRANS_TYPE_READ_ONLY; ;} break; - case 282: + case 267: #line 58 "third_party/libpg_query/grammar/statements/transaction.y" { (yyval.transactiontype) = PG_TRANS_TYPE_READ_WRITE; ;} break; - case 283: + case 268: #line 59 "third_party/libpg_query/grammar/statements/transaction.y" { (yyval.transactiontype) = PG_TRANS_TYPE_DEFAULT; ;} break; - case 284: + case 269: #line 3 "third_party/libpg_query/grammar/statements/use.y" { PGUseStmt *n = makeNode(PGUseStmt); @@ -22823,7 +22496,7 @@ YYLTYPE yylloc; ;} break; - case 285: + case 270: #line 9 "third_party/libpg_query/grammar/statements/create.y" { PGCreateStmt *n = makeNode(PGCreateStmt); @@ -22839,7 +22512,7 @@ YYLTYPE yylloc; ;} break; - case 286: + case 271: #line 24 "third_party/libpg_query/grammar/statements/create.y" { PGCreateStmt *n = makeNode(PGCreateStmt); @@ -22855,7 +22528,7 @@ YYLTYPE yylloc; ;} break; - case 287: + case 272: #line 39 "third_party/libpg_query/grammar/statements/create.y" { PGCreateStmt *n = makeNode(PGCreateStmt); @@ -22871,12 +22544,12 @@ YYLTYPE yylloc; ;} break; - case 288: + case 273: #line 56 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = 0; ;} break; - case 289: + case 274: #line 58 "third_party/libpg_query/grammar/statements/create.y" { /* @@ -22903,77 +22576,77 @@ YYLTYPE yylloc; ;} break; - case 290: + case 275: #line 84 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *)(yyvsp[(1) - (1)].typnam); ;} break; - case 291: + case 276: #line 85 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *)makeString(pstrdup((yyvsp[(1) - (1)].keyword))); ;} break; - case 292: + case 277: #line 86 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *)(yyvsp[(1) - (1)].list); ;} break; - case 293: + case 278: #line 87 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *)(yyvsp[(1) - (1)].value); ;} break; - case 294: + case 279: #line 88 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *)makeString((yyvsp[(1) - (1)].str)); ;} break; - case 295: + case 280: #line 89 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *)makeString(pstrdup((yyvsp[(1) - (1)].keyword))); ;} break; - case 296: + case 281: #line 93 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 297: + case 282: #line 94 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = NIL; ;} break; - case 298: + case 283: #line 99 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *) makeString((yyvsp[(1) - (1)].str)); ;} break; - case 299: + case 284: #line 104 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_ACTION_NOACTION; ;} break; - case 300: + case 285: #line 105 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_ACTION_RESTRICT; ;} break; - case 301: + case 286: #line 106 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_ACTION_CASCADE; ;} break; - case 302: + case 287: #line 107 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_ACTION_SETNULL; ;} break; - case 303: + case 288: #line 108 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_ACTION_SETDEFAULT; ;} break; - case 304: + case 289: #line 114 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = castNode(PGConstraint, (yyvsp[(3) - (3)].node)); @@ -22983,17 +22656,17 @@ YYLTYPE yylloc; ;} break; - case 305: + case 290: #line 120 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 306: + case 291: #line 121 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 307: + case 292: #line 123 "third_party/libpg_query/grammar/statements/create.y" { /* @@ -23009,7 +22682,7 @@ YYLTYPE yylloc; ;} break; - case 308: + case 293: #line 140 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23019,7 +22692,7 @@ YYLTYPE yylloc; ;} break; - case 309: + case 294: #line 147 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23029,7 +22702,7 @@ YYLTYPE yylloc; ;} break; - case 310: + case 295: #line 154 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23042,7 +22715,7 @@ YYLTYPE yylloc; ;} break; - case 311: + case 296: #line 164 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23055,7 +22728,7 @@ YYLTYPE yylloc; ;} break; - case 312: + case 297: #line 174 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23070,7 +22743,7 @@ YYLTYPE yylloc; ;} break; - case 313: + case 298: #line 186 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23081,7 +22754,7 @@ YYLTYPE yylloc; ;} break; - case 314: + case 299: #line 194 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23093,7 +22766,7 @@ YYLTYPE yylloc; ;} break; - case 315: + case 300: #line 203 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23111,27 +22784,27 @@ YYLTYPE yylloc; ;} break; - case 316: + case 301: #line 220 "third_party/libpg_query/grammar/statements/create.y" { (yyval.constr) = PG_CONSTR_GENERATED_VIRTUAL; ;} break; - case 317: + case 302: #line 221 "third_party/libpg_query/grammar/statements/create.y" { (yyval.constr) = PG_CONSTR_GENERATED_STORED; ;} break; - case 318: + case 303: #line 225 "third_party/libpg_query/grammar/statements/create.y" { (yyval.constr) = (yyvsp[(1) - (1)].constr); ;} break; - case 319: + case 304: #line 226 "third_party/libpg_query/grammar/statements/create.y" { (yyval.constr) = PG_CONSTR_GENERATED_VIRTUAL; ;} break; - case 320: + case 305: #line 231 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23143,7 +22816,7 @@ YYLTYPE yylloc; ;} break; - case 321: + case 306: #line 240 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23169,7 +22842,7 @@ YYLTYPE yylloc; ;} break; - case 322: + case 307: #line 263 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23182,79 +22855,79 @@ YYLTYPE yylloc; ;} break; - case 323: + case 308: #line 277 "third_party/libpg_query/grammar/statements/create.y" { (yyval.defelt) = makeDefElem((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 324: + case 309: #line 283 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = (yyvsp[(3) - (3)].ival); ;} break; - case 325: + case 310: #line 289 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = ((yyvsp[(1) - (1)].ival) << 8) | (PG_FKCONSTR_ACTION_NOACTION & 0xFF); ;} break; - case 326: + case 311: #line 291 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = (PG_FKCONSTR_ACTION_NOACTION << 8) | ((yyvsp[(1) - (1)].ival) & 0xFF); ;} break; - case 327: + case 312: #line 293 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = ((yyvsp[(1) - (2)].ival) << 8) | ((yyvsp[(2) - (2)].ival) & 0xFF); ;} break; - case 328: + case 313: #line 295 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = ((yyvsp[(2) - (2)].ival) << 8) | ((yyvsp[(1) - (2)].ival) & 0xFF); ;} break; - case 329: + case 314: #line 297 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = (PG_FKCONSTR_ACTION_NOACTION << 8) | (PG_FKCONSTR_ACTION_NOACTION & 0xFF); ;} break; - case 330: + case 315: #line 300 "third_party/libpg_query/grammar/statements/create.y" { (yyval.oncommit) = ONCOMMIT_DROP; ;} break; - case 331: + case 316: #line 301 "third_party/libpg_query/grammar/statements/create.y" { (yyval.oncommit) = PG_ONCOMMIT_DELETE_ROWS; ;} break; - case 332: + case 317: #line 302 "third_party/libpg_query/grammar/statements/create.y" { (yyval.oncommit) = PG_ONCOMMIT_PRESERVE_ROWS; ;} break; - case 333: + case 318: #line 303 "third_party/libpg_query/grammar/statements/create.y" { (yyval.oncommit) = PG_ONCOMMIT_NOOP; ;} break; - case 334: + case 319: #line 308 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 335: + case 320: #line 312 "third_party/libpg_query/grammar/statements/create.y" { (yyval.boolean) = true; ;} break; - case 336: + case 321: #line 313 "third_party/libpg_query/grammar/statements/create.y" { (yyval.boolean) = false; ;} break; - case 337: + case 322: #line 319 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = castNode(PGConstraint, (yyvsp[(3) - (3)].node)); @@ -23264,67 +22937,67 @@ YYLTYPE yylloc; ;} break; - case 338: + case 323: #line 325 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 339: + case 324: #line 330 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_COMMENTS; ;} break; - case 340: + case 325: #line 331 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_CONSTRAINTS; ;} break; - case 341: + case 326: #line 332 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_DEFAULTS; ;} break; - case 342: + case 327: #line 333 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_IDENTITY; ;} break; - case 343: + case 328: #line 334 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_INDEXES; ;} break; - case 344: + case 329: #line 335 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_STATISTICS; ;} break; - case 345: + case 330: #line 336 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_STORAGE; ;} break; - case 346: + case 331: #line 337 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_CREATE_TABLE_LIKE_ALL; ;} break; - case 347: + case 332: #line 343 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); ;} break; - case 348: + case 333: #line 344 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].defelt)); ;} break; - case 349: + case 334: #line 348 "third_party/libpg_query/grammar/statements/create.y" { (yyval.str) = (yyvsp[(3) - (3)].str); ;} break; - case 350: + case 335: #line 354 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23334,7 +23007,7 @@ YYLTYPE yylloc; ;} break; - case 351: + case 336: #line 361 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23344,7 +23017,7 @@ YYLTYPE yylloc; ;} break; - case 352: + case 337: #line 368 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23354,7 +23027,7 @@ YYLTYPE yylloc; ;} break; - case 353: + case 338: #line 375 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); @@ -23364,305 +23037,289 @@ YYLTYPE yylloc; ;} break; - case 354: + case 339: #line 386 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 355: + case 340: #line 387 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = list_make1(makeDefElem("oids", (PGNode *) makeInteger(true), (yylsp[(1) - (2)]))); ;} break; - case 356: + case 341: #line 388 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = list_make1(makeDefElem("oids", (PGNode *) makeInteger(false), (yylsp[(1) - (2)]))); ;} break; - case 357: + case 342: #line 389 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = NIL; ;} break; - case 358: + case 343: #line 393 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 359: + case 344: #line 398 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = (yyvsp[(1) - (3)].ival) | (yyvsp[(3) - (3)].ival); ;} break; - case 360: + case 345: #line 399 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = (yyvsp[(1) - (3)].ival) & ~(yyvsp[(3) - (3)].ival); ;} break; - case 361: + case 346: #line 400 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = 0; ;} break; - case 362: + case 347: #line 405 "third_party/libpg_query/grammar/statements/create.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 363: + case 348: #line 410 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = CAS_NOT_DEFERRABLE; ;} break; - case 364: + case 349: #line 411 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = CAS_DEFERRABLE; ;} break; - case 365: + case 350: #line 412 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = CAS_INITIALLY_IMMEDIATE; ;} break; - case 366: + case 351: #line 413 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = CAS_INITIALLY_DEFERRED; ;} break; - case 367: + case 352: #line 414 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = CAS_NOT_VALID; ;} break; - case 368: + case 353: #line 415 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = CAS_NO_INHERIT; ;} break; - case 369: + case 354: #line 421 "third_party/libpg_query/grammar/statements/create.y" { - PGColumnDef *n = makeNode(PGColumnDef); - n->category = COL_STANDARD; - n->typeName = (yyvsp[(1) - (2)].typnam); - n->inhcount = 0; - n->is_local = true; - n->is_not_null = false; - n->is_from_type = false; - n->storage = 0; - n->raw_default = NULL; - n->cooked_default = NULL; - n->collOid = InvalidOid; - SplitColQualList((yyvsp[(2) - (2)].list), &n->constraints, &n->collClause, - yyscanner); - (yyval.node) = (PGNode *) n; - ;} - break; - - case 370: -#line 441 "third_party/libpg_query/grammar/statements/create.y" - { - PGColumnDef *n = makeNode(PGColumnDef); - n->category = COL_GENERATED; - n->typeName = (yyvsp[(1) - (3)].typnam); - n->inhcount = 0; - n->is_local = true; - n->is_not_null = false; - n->is_from_type = false; - n->storage = 0; - n->raw_default = NULL; - n->cooked_default = NULL; - n->collOid = InvalidOid; - // merge the constraints with the generated column constraint - auto constraints = (yyvsp[(3) - (3)].list); - if (constraints) { - constraints = lappend(constraints, (yyvsp[(2) - (3)].node)); - } else { - constraints = list_make1((yyvsp[(2) - (3)].node)); - } - SplitColQualList(constraints, &n->constraints, &n->collClause, - yyscanner); - (yyval.node) = (PGNode *)n; - ;} - break; - - case 371: -#line 467 "third_party/libpg_query/grammar/statements/create.y" - { - PGColumnDef *n = (PGColumnDef *) (yyvsp[(2) - (2)].node); - n->colname = (yyvsp[(1) - (2)].str); - n->location = (yylsp[(1) - (2)]); + PGColumnDef *n = makeNode(PGColumnDef); + n->category = COL_STANDARD; + n->colname = (yyvsp[(1) - (3)].str); + n->typeName = (yyvsp[(2) - (3)].typnam); + n->inhcount = 0; + n->is_local = true; + n->is_not_null = false; + n->is_from_type = false; + n->storage = 0; + n->raw_default = NULL; + n->cooked_default = NULL; + n->collOid = InvalidOid; + SplitColQualList((yyvsp[(3) - (3)].list), &n->constraints, &n->collClause, + yyscanner); + n->location = (yylsp[(1) - (3)]); (yyval.node) = (PGNode *)n; ;} break; - case 372: -#line 475 "third_party/libpg_query/grammar/statements/create.y" + case 355: +#line 441 "third_party/libpg_query/grammar/statements/create.y" { - PGColumnDef *n = (PGColumnDef *) (yyvsp[(2) - (2)].node); - n->colname = (yyvsp[(1) - (2)].str); - n->location = (yylsp[(1) - (2)]); + PGColumnDef *n = makeNode(PGColumnDef); + n->category = COL_GENERATED; + n->colname = (yyvsp[(1) - (4)].str); + n->typeName = (yyvsp[(2) - (4)].typnam); + n->inhcount = 0; + n->is_local = true; + n->is_not_null = false; + n->is_from_type = false; + n->storage = 0; + n->raw_default = NULL; + n->cooked_default = NULL; + n->collOid = InvalidOid; + // merge the constraints with the generated column constraint + auto constraints = (yyvsp[(4) - (4)].list); + if (constraints) { + constraints = lappend(constraints, (yyvsp[(3) - (4)].node)); + } else { + constraints = list_make1((yyvsp[(3) - (4)].node)); + } + SplitColQualList(constraints, &n->constraints, &n->collClause, + yyscanner); + n->location = (yylsp[(1) - (4)]); (yyval.node) = (PGNode *)n; ;} break; - case 373: -#line 484 "third_party/libpg_query/grammar/statements/create.y" + case 356: +#line 469 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); ;} break; - case 374: -#line 485 "third_party/libpg_query/grammar/statements/create.y" + case 357: +#line 470 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].defelt)); ;} break; - case 375: -#line 489 "third_party/libpg_query/grammar/statements/create.y" + case 358: +#line 474 "third_party/libpg_query/grammar/statements/create.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 376: -#line 493 "third_party/libpg_query/grammar/statements/create.y" + case 359: +#line 478 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 377: -#line 494 "third_party/libpg_query/grammar/statements/create.y" + case 360: +#line 479 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 378: -#line 495 "third_party/libpg_query/grammar/statements/create.y" + case 361: +#line 480 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 379: -#line 500 "third_party/libpg_query/grammar/statements/create.y" + case 362: +#line 485 "third_party/libpg_query/grammar/statements/create.y" { (yyval.defelt) = makeDefElem((yyvsp[(1) - (3)].str), (PGNode *) (yyvsp[(3) - (3)].node), (yylsp[(1) - (3)])); ;} break; - case 380: -#line 504 "third_party/libpg_query/grammar/statements/create.y" + case 363: +#line 489 "third_party/libpg_query/grammar/statements/create.y" { (yyval.defelt) = makeDefElem((yyvsp[(1) - (1)].str), NULL, (yylsp[(1) - (1)])); ;} break; - case 381: -#line 511 "third_party/libpg_query/grammar/statements/create.y" + case 364: +#line 496 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 382: -#line 512 "third_party/libpg_query/grammar/statements/create.y" + case 365: +#line 497 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = NIL; ;} break; - case 383: -#line 517 "third_party/libpg_query/grammar/statements/create.y" + case 366: +#line 502 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 384: -#line 518 "third_party/libpg_query/grammar/statements/create.y" + case 367: +#line 503 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 385: -#line 519 "third_party/libpg_query/grammar/statements/create.y" + case 368: +#line 504 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = NIL; ;} break; - case 386: -#line 524 "third_party/libpg_query/grammar/statements/create.y" + case 369: +#line 509 "third_party/libpg_query/grammar/statements/create.y" { (yyval.node) = (PGNode *) makeString((yyvsp[(1) - (1)].str)); ;} break; - case 387: -#line 531 "third_party/libpg_query/grammar/statements/create.y" + case 370: +#line 516 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 388: -#line 532 "third_party/libpg_query/grammar/statements/create.y" + case 371: +#line 517 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = NIL; ;} break; - case 389: -#line 537 "third_party/libpg_query/grammar/statements/create.y" + case 372: +#line 522 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 390: -#line 538 "third_party/libpg_query/grammar/statements/create.y" + case 373: +#line 523 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = NIL; ;} break; - case 391: -#line 542 "third_party/libpg_query/grammar/statements/create.y" + case 374: +#line 527 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = (yyvsp[(3) - (3)].ival); ;} break; - case 392: -#line 548 "third_party/libpg_query/grammar/statements/create.y" + case 375: +#line 533 "third_party/libpg_query/grammar/statements/create.y" { (yyval.defelt) = makeDefElem((yyvsp[(1) - (3)].str), (PGNode *) (yyvsp[(3) - (3)].node), (yylsp[(1) - (3)])); ;} break; - case 393: -#line 552 "third_party/libpg_query/grammar/statements/create.y" + case 376: +#line 537 "third_party/libpg_query/grammar/statements/create.y" { (yyval.defelt) = makeDefElem((yyvsp[(1) - (1)].str), NULL, (yylsp[(1) - (1)])); ;} break; - case 394: -#line 556 "third_party/libpg_query/grammar/statements/create.y" + case 377: +#line 541 "third_party/libpg_query/grammar/statements/create.y" { (yyval.defelt) = makeDefElemExtended((yyvsp[(1) - (5)].str), (yyvsp[(3) - (5)].str), (PGNode *) (yyvsp[(5) - (5)].node), PG_DEFELEM_UNSPEC, (yylsp[(1) - (5)])); ;} break; - case 395: -#line 561 "third_party/libpg_query/grammar/statements/create.y" + case 378: +#line 546 "third_party/libpg_query/grammar/statements/create.y" { (yyval.defelt) = makeDefElemExtended((yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str), NULL, PG_DEFELEM_UNSPEC, (yylsp[(1) - (3)])); ;} break; - case 396: -#line 568 "third_party/libpg_query/grammar/statements/create.y" + case 379: +#line 553 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 397: -#line 569 "third_party/libpg_query/grammar/statements/create.y" + case 380: +#line 554 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 398: -#line 573 "third_party/libpg_query/grammar/statements/create.y" + case 381: +#line 558 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 399: -#line 574 "third_party/libpg_query/grammar/statements/create.y" + case 382: +#line 559 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 400: -#line 578 "third_party/libpg_query/grammar/statements/create.y" + case 383: +#line 563 "third_party/libpg_query/grammar/statements/create.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 401: -#line 580 "third_party/libpg_query/grammar/statements/create.y" + case 384: +#line 565 "third_party/libpg_query/grammar/statements/create.y" { (yyval.typnam) = makeTypeNameFromNameList(lcons(makeString((yyvsp[(1) - (4)].str)), (yyvsp[(2) - (4)].list))); (yyval.typnam)->pct_type = true; @@ -23670,8 +23327,8 @@ YYLTYPE yylloc; ;} break; - case 402: -#line 586 "third_party/libpg_query/grammar/statements/create.y" + case 385: +#line 571 "third_party/libpg_query/grammar/statements/create.y" { (yyval.typnam) = makeTypeNameFromNameList(lcons(makeString((yyvsp[(2) - (5)].str)), (yyvsp[(3) - (5)].list))); (yyval.typnam)->pct_type = true; @@ -23680,8 +23337,8 @@ YYLTYPE yylloc; ;} break; - case 403: -#line 597 "third_party/libpg_query/grammar/statements/create.y" + case 386: +#line 582 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); n->contype = PG_CONSTR_CHECK; @@ -23696,8 +23353,8 @@ YYLTYPE yylloc; ;} break; - case 404: -#line 611 "third_party/libpg_query/grammar/statements/create.y" + case 387: +#line 596 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); n->contype = PG_CONSTR_UNIQUE; @@ -23712,8 +23369,8 @@ YYLTYPE yylloc; ;} break; - case 405: -#line 624 "third_party/libpg_query/grammar/statements/create.y" + case 388: +#line 609 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); n->contype = PG_CONSTR_UNIQUE; @@ -23729,8 +23386,8 @@ YYLTYPE yylloc; ;} break; - case 406: -#line 639 "third_party/libpg_query/grammar/statements/create.y" + case 389: +#line 624 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); n->contype = PG_CONSTR_PRIMARY; @@ -23745,8 +23402,8 @@ YYLTYPE yylloc; ;} break; - case 407: -#line 652 "third_party/libpg_query/grammar/statements/create.y" + case 390: +#line 637 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); n->contype = PG_CONSTR_PRIMARY; @@ -23762,8 +23419,8 @@ YYLTYPE yylloc; ;} break; - case 408: -#line 667 "third_party/libpg_query/grammar/statements/create.y" + case 391: +#line 652 "third_party/libpg_query/grammar/statements/create.y" { PGConstraint *n = makeNode(PGConstraint); n->contype = PG_CONSTR_FOREIGN; @@ -23783,29 +23440,29 @@ YYLTYPE yylloc; ;} break; - case 409: -#line 689 "third_party/libpg_query/grammar/statements/create.y" + case 392: +#line 674 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 410: -#line 693 "third_party/libpg_query/grammar/statements/create.y" + case 393: +#line 678 "third_party/libpg_query/grammar/statements/create.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 411: -#line 700 "third_party/libpg_query/grammar/statements/create.y" + case 394: +#line 685 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_MATCH_FULL; ;} break; - case 412: -#line 704 "third_party/libpg_query/grammar/statements/create.y" + case 395: +#line 689 "third_party/libpg_query/grammar/statements/create.y" { ereport(ERROR, (errcode(PG_ERRCODE_FEATURE_NOT_SUPPORTED), @@ -23815,22 +23472,22 @@ YYLTYPE yylloc; ;} break; - case 413: -#line 712 "third_party/libpg_query/grammar/statements/create.y" + case 396: +#line 697 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_MATCH_SIMPLE; ;} break; - case 414: -#line 716 "third_party/libpg_query/grammar/statements/create.y" + case 397: +#line 701 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_FKCONSTR_MATCH_SIMPLE; ;} break; - case 415: -#line 724 "third_party/libpg_query/grammar/statements/create.y" + case 398: +#line 709 "third_party/libpg_query/grammar/statements/create.y" { PGTableLikeClause *n = makeNode(PGTableLikeClause); n->relation = (yyvsp[(2) - (3)].range); @@ -23839,28 +23496,28 @@ YYLTYPE yylloc; ;} break; - case 416: -#line 733 "third_party/libpg_query/grammar/statements/create.y" + case 399: +#line 718 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_RELPERSISTENCE_TEMP; ;} break; - case 417: -#line 734 "third_party/libpg_query/grammar/statements/create.y" + case 400: +#line 719 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_RELPERSISTENCE_TEMP; ;} break; - case 418: -#line 735 "third_party/libpg_query/grammar/statements/create.y" + case 401: +#line 720 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_RELPERSISTENCE_TEMP; ;} break; - case 419: -#line 736 "third_party/libpg_query/grammar/statements/create.y" + case 402: +#line 721 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_RELPERSISTENCE_TEMP; ;} break; - case 420: -#line 738 "third_party/libpg_query/grammar/statements/create.y" + case 403: +#line 723 "third_party/libpg_query/grammar/statements/create.y" { ereport(PGWARNING, (errmsg("GLOBAL is deprecated in temporary table creation"), @@ -23869,8 +23526,8 @@ YYLTYPE yylloc; ;} break; - case 421: -#line 745 "third_party/libpg_query/grammar/statements/create.y" + case 404: +#line 730 "third_party/libpg_query/grammar/statements/create.y" { ereport(PGWARNING, (errmsg("GLOBAL is deprecated in temporary table creation"), @@ -23879,27 +23536,27 @@ YYLTYPE yylloc; ;} break; - case 422: -#line 751 "third_party/libpg_query/grammar/statements/create.y" + case 405: +#line 736 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_RELPERSISTENCE_UNLOGGED; ;} break; - case 423: -#line 752 "third_party/libpg_query/grammar/statements/create.y" + case 406: +#line 737 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = RELPERSISTENCE_PERMANENT; ;} break; - case 424: -#line 757 "third_party/libpg_query/grammar/statements/create.y" + case 407: +#line 742 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = PG_ATTRIBUTE_IDENTITY_ALWAYS; ;} break; - case 425: -#line 758 "third_party/libpg_query/grammar/statements/create.y" + case 408: +#line 743 "third_party/libpg_query/grammar/statements/create.y" { (yyval.ival) = ATTRIBUTE_IDENTITY_BY_DEFAULT; ;} break; - case 426: + case 409: #line 10 "third_party/libpg_query/grammar/statements/drop.y" { PGDropStmt *n = makeNode(PGDropStmt); @@ -23912,7 +23569,7 @@ YYLTYPE yylloc; ;} break; - case 427: + case 410: #line 20 "third_party/libpg_query/grammar/statements/drop.y" { PGDropStmt *n = makeNode(PGDropStmt); @@ -23925,7 +23582,7 @@ YYLTYPE yylloc; ;} break; - case 428: + case 411: #line 30 "third_party/libpg_query/grammar/statements/drop.y" { PGDropStmt *n = makeNode(PGDropStmt); @@ -23938,7 +23595,7 @@ YYLTYPE yylloc; ;} break; - case 429: + case 412: #line 40 "third_party/libpg_query/grammar/statements/drop.y" { PGDropStmt *n = makeNode(PGDropStmt); @@ -23951,7 +23608,7 @@ YYLTYPE yylloc; ;} break; - case 430: + case 413: #line 50 "third_party/libpg_query/grammar/statements/drop.y" { PGDropStmt *n = makeNode(PGDropStmt); @@ -23964,7 +23621,7 @@ YYLTYPE yylloc; ;} break; - case 431: + case 414: #line 60 "third_party/libpg_query/grammar/statements/drop.y" { PGDropStmt *n = makeNode(PGDropStmt); @@ -23977,167 +23634,167 @@ YYLTYPE yylloc; ;} break; - case 432: + case 415: #line 73 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TABLE; ;} break; - case 433: + case 416: #line 74 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_SEQUENCE; ;} break; - case 434: + case 417: #line 75 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_FUNCTION; ;} break; - case 435: + case 418: #line 76 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_FUNCTION; ;} break; - case 436: + case 419: #line 77 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TABLE_MACRO; ;} break; - case 437: + case 420: #line 78 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_VIEW; ;} break; - case 438: + case 421: #line 79 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_MATVIEW; ;} break; - case 439: + case 422: #line 80 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_INDEX; ;} break; - case 440: + case 423: #line 81 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_FOREIGN_TABLE; ;} break; - case 441: + case 424: #line 82 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_COLLATION; ;} break; - case 442: + case 425: #line 83 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_CONVERSION; ;} break; - case 443: + case 426: #line 84 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_SCHEMA; ;} break; - case 444: + case 427: #line 85 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_STATISTIC_EXT; ;} break; - case 445: + case 428: #line 86 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TSPARSER; ;} break; - case 446: + case 429: #line 87 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TSDICTIONARY; ;} break; - case 447: + case 430: #line 88 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TSTEMPLATE; ;} break; - case 448: + case 431: #line 89 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TSCONFIGURATION; ;} break; - case 449: + case 432: #line 90 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TYPE; ;} break; - case 450: + case 433: #line 95 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_ACCESS_METHOD; ;} break; - case 451: + case 434: #line 96 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_EVENT_TRIGGER; ;} break; - case 452: + case 435: #line 97 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_EXTENSION; ;} break; - case 453: + case 436: #line 98 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_FDW; ;} break; - case 454: + case 437: #line 99 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_PUBLICATION; ;} break; - case 455: + case 438: #line 100 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_FOREIGN_SERVER; ;} break; - case 456: + case 439: #line 105 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].list)); ;} break; - case 457: + case 440: #line 106 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].list)); ;} break; - case 458: + case 441: #line 111 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.dbehavior) = PG_DROP_CASCADE; ;} break; - case 459: + case 442: #line 112 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.dbehavior) = PG_DROP_RESTRICT; ;} break; - case 460: + case 443: #line 113 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.dbehavior) = PG_DROP_RESTRICT; /* default */ ;} break; - case 461: + case 444: #line 118 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_POLICY; ;} break; - case 462: + case 445: #line 119 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_RULE; ;} break; - case 463: + case 446: #line 120 "third_party/libpg_query/grammar/statements/drop.y" { (yyval.objtype) = PG_OBJECT_TRIGGER; ;} break; - case 464: + case 447: #line 9 "third_party/libpg_query/grammar/statements/create_function.y" { PGCreateFunctionStmt *n = makeNode(PGCreateFunctionStmt); @@ -24149,7 +23806,7 @@ YYLTYPE yylloc; ;} break; - case 465: + case 448: #line 19 "third_party/libpg_query/grammar/statements/create_function.y" { PGCreateFunctionStmt *n = makeNode(PGCreateFunctionStmt); @@ -24162,7 +23819,7 @@ YYLTYPE yylloc; ;} break; - case 466: + case 449: #line 30 "third_party/libpg_query/grammar/statements/create_function.y" { PGCreateFunctionStmt *n = makeNode(PGCreateFunctionStmt); @@ -24174,7 +23831,7 @@ YYLTYPE yylloc; ;} break; - case 467: + case 450: #line 40 "third_party/libpg_query/grammar/statements/create_function.y" { PGCreateFunctionStmt *n = makeNode(PGCreateFunctionStmt); @@ -24186,7 +23843,7 @@ YYLTYPE yylloc; ;} break; - case 468: + case 451: #line 50 "third_party/libpg_query/grammar/statements/create_function.y" { PGCreateFunctionStmt *n = makeNode(PGCreateFunctionStmt); @@ -24198,7 +23855,7 @@ YYLTYPE yylloc; ;} break; - case 469: + case 452: #line 60 "third_party/libpg_query/grammar/statements/create_function.y" { PGCreateFunctionStmt *n = makeNode(PGCreateFunctionStmt); @@ -24210,7 +23867,7 @@ YYLTYPE yylloc; ;} break; - case 470: + case 453: #line 72 "third_party/libpg_query/grammar/statements/create_function.y" { PGFunctionDefinition *n = makeNode(PGFunctionDefinition); @@ -24220,7 +23877,7 @@ YYLTYPE yylloc; ;} break; - case 471: + case 454: #line 82 "third_party/libpg_query/grammar/statements/create_function.y" { PGFunctionDefinition *n = makeNode(PGFunctionDefinition); @@ -24230,28 +23887,28 @@ YYLTYPE yylloc; ;} break; - case 472: + case 455: #line 92 "third_party/libpg_query/grammar/statements/create_function.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 473: + case 456: #line 96 "third_party/libpg_query/grammar/statements/create_function.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 474: + case 457: #line 103 "third_party/libpg_query/grammar/statements/create_function.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 476: + case 459: #line 111 "third_party/libpg_query/grammar/statements/create_function.y" { PGFunctionDefinition *n = makeNode(PGFunctionDefinition); @@ -24261,35 +23918,35 @@ YYLTYPE yylloc; ;} break; - case 477: + case 460: #line 120 "third_party/libpg_query/grammar/statements/create_function.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 478: + case 461: #line 124 "third_party/libpg_query/grammar/statements/create_function.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 481: + case 464: #line 136 "third_party/libpg_query/grammar/statements/create_function.y" { (yyval.list) = NIL; ;} break; - case 482: + case 465: #line 140 "third_party/libpg_query/grammar/statements/create_function.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 483: + case 466: #line 12 "third_party/libpg_query/grammar/statements/update.y" { PGUpdateStmt *n = makeNode(PGUpdateStmt); @@ -24303,7 +23960,7 @@ YYLTYPE yylloc; ;} break; - case 484: + case 467: #line 3 "third_party/libpg_query/grammar/statements/copy.y" { PGCopyStmt *n = makeNode(PGCopyStmt); @@ -24334,7 +23991,7 @@ YYLTYPE yylloc; ;} break; - case 485: + case 468: #line 31 "third_party/libpg_query/grammar/statements/copy.y" { PGCopyStmt *n = makeNode(PGCopyStmt); @@ -24356,7 +24013,7 @@ YYLTYPE yylloc; ;} break; - case 486: + case 469: #line 50 "third_party/libpg_query/grammar/statements/copy.y" { PGCopyDatabaseStmt *n = makeNode(PGCopyDatabaseStmt); @@ -24367,450 +24024,450 @@ YYLTYPE yylloc; ;} break; - case 487: + case 470: #line 61 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.conststr) = NULL; ;} break; - case 488: + case 471: #line 62 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.conststr) = "schema"; ;} break; - case 489: + case 472: #line 63 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.conststr) = "data"; ;} break; - case 490: + case 473: #line 67 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.boolean) = true; ;} break; - case 491: + case 474: #line 68 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.boolean) = false; ;} break; - case 492: + case 475: #line 74 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("delimiter", (PGNode *)makeString((yyvsp[(3) - (3)].str)), (yylsp[(2) - (3)])); ;} break; - case 493: + case 476: #line 77 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = NULL; ;} break; - case 494: + case 477: #line 83 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 495: + case 478: #line 87 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 496: + case 479: #line 94 "third_party/libpg_query/grammar/statements/copy.y" {;} break; - case 497: + case 480: #line 95 "third_party/libpg_query/grammar/statements/copy.y" {;} break; - case 498: + case 481: #line 99 "third_party/libpg_query/grammar/statements/copy.y" {;} break; - case 499: + case 482: #line 100 "third_party/libpg_query/grammar/statements/copy.y" {;} break; - case 500: + case 483: #line 105 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.boolean) = true; ;} break; - case 501: + case 484: #line 106 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.boolean) = false; ;} break; - case 502: + case 485: #line 110 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 503: + case 486: #line 111 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 504: + case 487: #line 116 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) makeString((yyvsp[(1) - (1)].str)); ;} break; - case 505: + case 488: #line 117 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) (yyvsp[(1) - (1)].value); ;} break; - case 506: + case 489: #line 118 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) (yyvsp[(1) - (1)].node); ;} break; - case 507: + case 490: #line 119 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) makeNode(PGAStar); ;} break; - case 508: + case 491: #line 120 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) (yyvsp[(2) - (3)].list); ;} break; - case 509: + case 492: #line 121 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) (yyvsp[(1) - (1)].node); ;} break; - case 510: + case 493: #line 122 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) (yyvsp[(1) - (1)].node); ;} break; - case 511: + case 494: #line 123 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = NULL; ;} break; - case 512: + case 495: #line 129 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 513: + case 496: #line 137 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("oids", (PGNode *)makeInteger(true), (yylsp[(1) - (2)])); ;} break; - case 514: + case 497: #line 140 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = NULL; ;} break; - case 515: + case 498: #line 145 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].defelt)); ;} break; - case 516: + case 499: #line 146 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = NIL; ;} break; - case 517: + case 500: #line 152 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("format", (PGNode *)makeString("binary"), (yylsp[(1) - (1)])); ;} break; - case 518: + case 501: #line 155 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = NULL; ;} break; - case 519: + case 502: #line 161 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("format", (PGNode *)makeString("binary"), (yylsp[(1) - (1)])); ;} break; - case 520: + case 503: #line 165 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("oids", (PGNode *)makeInteger(true), (yylsp[(1) - (1)])); ;} break; - case 521: + case 504: #line 169 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("freeze", (PGNode *)makeInteger(true), (yylsp[(1) - (1)])); ;} break; - case 522: + case 505: #line 173 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("delimiter", (PGNode *)makeString((yyvsp[(3) - (3)].str)), (yylsp[(1) - (3)])); ;} break; - case 523: + case 506: #line 177 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("null", (PGNode *)makeString((yyvsp[(3) - (3)].str)), (yylsp[(1) - (3)])); ;} break; - case 524: + case 507: #line 181 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("format", (PGNode *)makeString("csv"), (yylsp[(1) - (1)])); ;} break; - case 525: + case 508: #line 185 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("header", (PGNode *)makeInteger(true), (yylsp[(1) - (1)])); ;} break; - case 526: + case 509: #line 189 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("quote", (PGNode *)makeString((yyvsp[(3) - (3)].str)), (yylsp[(1) - (3)])); ;} break; - case 527: + case 510: #line 193 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("escape", (PGNode *)makeString((yyvsp[(3) - (3)].str)), (yylsp[(1) - (3)])); ;} break; - case 528: + case 511: #line 197 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("force_quote", (PGNode *)(yyvsp[(3) - (3)].list), (yylsp[(1) - (3)])); ;} break; - case 529: + case 512: #line 201 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("force_quote", (PGNode *)makeNode(PGAStar), (yylsp[(1) - (3)])); ;} break; - case 530: + case 513: #line 205 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("partition_by", (PGNode *)(yyvsp[(3) - (3)].list), (yylsp[(1) - (3)])); ;} break; - case 531: + case 514: #line 209 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("partition_by", (PGNode *)makeNode(PGAStar), (yylsp[(1) - (3)])); ;} break; - case 532: + case 515: #line 213 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("force_not_null", (PGNode *)(yyvsp[(4) - (4)].list), (yylsp[(1) - (4)])); ;} break; - case 533: + case 516: #line 217 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("force_null", (PGNode *)(yyvsp[(3) - (3)].list), (yylsp[(1) - (3)])); ;} break; - case 534: + case 517: #line 221 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.defelt) = makeDefElem("encoding", (PGNode *)makeString((yyvsp[(2) - (2)].str)), (yylsp[(1) - (2)])); ;} break; - case 535: + case 518: #line 228 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.node) = (PGNode *) makeString((yyvsp[(1) - (1)].str)); ;} break; - case 536: + case 519: #line 233 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 537: + case 520: #line 234 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.str) = NULL; ;} break; - case 538: + case 521: #line 235 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.str) = NULL; ;} break; - case 539: + case 522: #line 236 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.str) = psprintf("%s.%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)); ;} break; - case 540: + case 523: #line 237 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 541: + case 524: #line 244 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); ;} break; - case 542: + case 525: #line 248 "third_party/libpg_query/grammar/statements/copy.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].defelt)); ;} break; - case 545: + case 528: #line 52 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (3)].node); ;} break; - case 546: + case 529: #line 53 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (3)].node); ;} break; - case 547: + case 530: #line 55 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (3)].node); ;} break; - case 548: + case 531: #line 72 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 549: + case 532: #line 74 "third_party/libpg_query/grammar/statements/select.y" { insertSelectOptions((PGSelectStmt *) (yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].list), NIL, - NULL, NULL, NULL, NULL, + NULL, NULL, NULL, yyscanner); (yyval.node) = (yyvsp[(1) - (2)].node); ;} break; - case 550: + case 533: #line 81 "third_party/libpg_query/grammar/statements/select.y" { insertSelectOptions((PGSelectStmt *) (yyvsp[(1) - (4)].node), (yyvsp[(2) - (4)].list), (yyvsp[(3) - (4)].list), - (PGNode*) list_nth((yyvsp[(4) - (4)].list), 0), (PGNode*) list_nth((yyvsp[(4) - (4)].list), 1), (PGNode*) list_nth((yyvsp[(4) - (4)].list), 2), + (PGNode*) list_nth((yyvsp[(4) - (4)].list), 0), (PGNode*) list_nth((yyvsp[(4) - (4)].list), 1), NULL, yyscanner); (yyval.node) = (yyvsp[(1) - (4)].node); ;} break; - case 551: + case 534: #line 89 "third_party/libpg_query/grammar/statements/select.y" { insertSelectOptions((PGSelectStmt *) (yyvsp[(1) - (4)].node), (yyvsp[(2) - (4)].list), (yyvsp[(4) - (4)].list), - (PGNode*) list_nth((yyvsp[(3) - (4)].list), 0), (PGNode*) list_nth((yyvsp[(3) - (4)].list), 1), (PGNode*) list_nth((yyvsp[(3) - (4)].list), 2), + (PGNode*) list_nth((yyvsp[(3) - (4)].list), 0), (PGNode*) list_nth((yyvsp[(3) - (4)].list), 1), NULL, yyscanner); (yyval.node) = (yyvsp[(1) - (4)].node); ;} break; - case 552: + case 535: #line 97 "third_party/libpg_query/grammar/statements/select.y" { insertSelectOptions((PGSelectStmt *) (yyvsp[(2) - (2)].node), NULL, NIL, - NULL, NULL, NULL, + NULL, NULL, (yyvsp[(1) - (2)].with), yyscanner); (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 553: + case 536: #line 105 "third_party/libpg_query/grammar/statements/select.y" { insertSelectOptions((PGSelectStmt *) (yyvsp[(2) - (3)].node), (yyvsp[(3) - (3)].list), NIL, - NULL, NULL, NULL, + NULL, NULL, (yyvsp[(1) - (3)].with), yyscanner); (yyval.node) = (yyvsp[(2) - (3)].node); ;} break; - case 554: + case 537: #line 113 "third_party/libpg_query/grammar/statements/select.y" { insertSelectOptions((PGSelectStmt *) (yyvsp[(2) - (5)].node), (yyvsp[(3) - (5)].list), (yyvsp[(4) - (5)].list), - (PGNode*) list_nth((yyvsp[(5) - (5)].list), 0), (PGNode*) list_nth((yyvsp[(5) - (5)].list), 1), (PGNode*) list_nth((yyvsp[(5) - (5)].list), 2), + (PGNode*) list_nth((yyvsp[(5) - (5)].list), 0), (PGNode*) list_nth((yyvsp[(5) - (5)].list), 1), (yyvsp[(1) - (5)].with), yyscanner); (yyval.node) = (yyvsp[(2) - (5)].node); ;} break; - case 555: + case 538: #line 121 "third_party/libpg_query/grammar/statements/select.y" { insertSelectOptions((PGSelectStmt *) (yyvsp[(2) - (5)].node), (yyvsp[(3) - (5)].list), (yyvsp[(5) - (5)].list), - (PGNode*) list_nth((yyvsp[(4) - (5)].list), 0), (PGNode*) list_nth((yyvsp[(4) - (5)].list), 1), (PGNode*) list_nth((yyvsp[(4) - (5)].list), 2), + (PGNode*) list_nth((yyvsp[(4) - (5)].list), 0), (PGNode*) list_nth((yyvsp[(4) - (5)].list), 1), (yyvsp[(1) - (5)].with), yyscanner); (yyval.node) = (yyvsp[(2) - (5)].node); ;} break; - case 556: + case 539: #line 131 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 557: + case 540: #line 132 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 558: + case 541: #line 160 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (3)].list); ;} break; - case 559: + case 542: #line 164 "third_party/libpg_query/grammar/statements/select.y" { PGAStar *star = makeNode(PGAStar); @@ -24818,7 +24475,7 @@ YYLTYPE yylloc; ;} break; - case 560: + case 543: #line 175 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *n = makeNode(PGSelectStmt); @@ -24835,7 +24492,7 @@ YYLTYPE yylloc; ;} break; - case 561: + case 544: #line 191 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *n = makeNode(PGSelectStmt); @@ -24853,7 +24510,7 @@ YYLTYPE yylloc; ;} break; - case 562: + case 545: #line 208 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *n = makeNode(PGSelectStmt); @@ -24871,7 +24528,7 @@ YYLTYPE yylloc; ;} break; - case 563: + case 546: #line 226 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *n = makeNode(PGSelectStmt); @@ -24890,12 +24547,12 @@ YYLTYPE yylloc; ;} break; - case 564: + case 547: #line 241 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 565: + case 548: #line 243 "third_party/libpg_query/grammar/statements/select.y" { /* same as SELECT * FROM relation_expr */ @@ -24917,35 +24574,35 @@ YYLTYPE yylloc; ;} break; - case 566: + case 549: #line 262 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSetOp(PG_SETOP_UNION_BY_NAME, (yyvsp[(3) - (5)].boolean), (yyvsp[(1) - (5)].node), (yyvsp[(5) - (5)].node)); ;} break; - case 567: + case 550: #line 266 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSetOp(PG_SETOP_UNION, (yyvsp[(3) - (4)].boolean), (yyvsp[(1) - (4)].node), (yyvsp[(4) - (4)].node)); ;} break; - case 568: + case 551: #line 270 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSetOp(PG_SETOP_INTERSECT, (yyvsp[(3) - (4)].boolean), (yyvsp[(1) - (4)].node), (yyvsp[(4) - (4)].node)); ;} break; - case 569: + case 552: #line 274 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSetOp(PG_SETOP_EXCEPT, (yyvsp[(3) - (4)].boolean), (yyvsp[(1) - (4)].node), (yyvsp[(4) - (4)].node)); ;} break; - case 570: + case 553: #line 278 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -24958,7 +24615,7 @@ YYLTYPE yylloc; ;} break; - case 571: + case 554: #line 288 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -24972,7 +24629,7 @@ YYLTYPE yylloc; ;} break; - case 572: + case 555: #line 299 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -24985,7 +24642,7 @@ YYLTYPE yylloc; ;} break; - case 573: + case 556: #line 309 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -24997,7 +24654,7 @@ YYLTYPE yylloc; ;} break; - case 574: + case 557: #line 318 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -25011,7 +24668,7 @@ YYLTYPE yylloc; ;} break; - case 575: + case 558: #line 329 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -25025,7 +24682,7 @@ YYLTYPE yylloc; ;} break; - case 576: + case 559: #line 340 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -25040,7 +24697,7 @@ YYLTYPE yylloc; ;} break; - case 577: + case 560: #line 352 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -25058,7 +24715,7 @@ YYLTYPE yylloc; ;} break; - case 578: + case 561: #line 367 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *res = makeNode(PGSelectStmt); @@ -25076,7 +24733,7 @@ YYLTYPE yylloc; ;} break; - case 585: + case 568: #line 397 "third_party/libpg_query/grammar/statements/select.y" { PGPivot *n = makeNode(PGPivot); @@ -25085,7 +24742,7 @@ YYLTYPE yylloc; ;} break; - case 586: + case 569: #line 403 "third_party/libpg_query/grammar/statements/select.y" { PGPivot *n = makeNode(PGPivot); @@ -25095,32 +24752,32 @@ YYLTYPE yylloc; ;} break; - case 587: + case 570: #line 409 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 588: + case 571: #line 413 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 589: + case 572: #line 414 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 590: + case 573: #line 418 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 591: + case 574: #line 419 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 592: + case 575: #line 434 "third_party/libpg_query/grammar/statements/select.y" { (yyval.with) = makeNode(PGWithClause); @@ -25130,7 +24787,7 @@ YYLTYPE yylloc; ;} break; - case 593: + case 576: #line 441 "third_party/libpg_query/grammar/statements/select.y" { (yyval.with) = makeNode(PGWithClause); @@ -25140,7 +24797,7 @@ YYLTYPE yylloc; ;} break; - case 594: + case 577: #line 448 "third_party/libpg_query/grammar/statements/select.y" { (yyval.with) = makeNode(PGWithClause); @@ -25150,77 +24807,46 @@ YYLTYPE yylloc; ;} break; - case 595: + case 578: #line 457 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 596: + case 579: #line 458 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 597: + case 580: #line 462 "third_party/libpg_query/grammar/statements/select.y" { PGCommonTableExpr *n = makeNode(PGCommonTableExpr); - n->ctename = (yyvsp[(1) - (8)].str); - n->aliascolnames = (yyvsp[(2) - (8)].list); - n->recursive_keys = (yyvsp[(3) - (8)].list); - n->ctematerialized = (yyvsp[(5) - (8)].ctematerialize); - n->ctequery = (yyvsp[(7) - (8)].node); - n->location = (yylsp[(1) - (8)]); + n->ctename = (yyvsp[(1) - (7)].str); + n->aliascolnames = (yyvsp[(2) - (7)].list); + n->ctematerialized = (yyvsp[(4) - (7)].ctematerialize); + n->ctequery = (yyvsp[(6) - (7)].node); + n->location = (yylsp[(1) - (7)]); (yyval.node) = (PGNode *) n; ;} break; - case 598: -#line 475 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = (yyvsp[(4) - (5)].list); ;} - break; - - case 599: -#line 476 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = list_make1(NIL); ;} - break; - - case 600: -#line 480 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = (yyvsp[(1) - (1)].list); ;} - break; - - case 601: -#line 481 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = (yyvsp[(1) - (2)].list); ;} - break; - - case 602: -#line 485 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} - break; - - case 603: -#line 486 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} - break; - - case 604: -#line 490 "third_party/libpg_query/grammar/statements/select.y" + case 581: +#line 474 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ctematerialize) = PGCTEMaterializeAlways; ;} break; - case 605: -#line 491 "third_party/libpg_query/grammar/statements/select.y" + case 582: +#line 475 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ctematerialize) = PGCTEMaterializeNever; ;} break; - case 606: -#line 492 "third_party/libpg_query/grammar/statements/select.y" + case 583: +#line 476 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ctematerialize) = PGCTEMaterializeDefault; ;} break; - case 607: -#line 497 "third_party/libpg_query/grammar/statements/select.y" + case 584: +#line 481 "third_party/libpg_query/grammar/statements/select.y" { (yyval.into) = makeNode(PGIntoClause); (yyval.into)->rel = (yyvsp[(2) - (2)].range); @@ -25232,45 +24858,45 @@ YYLTYPE yylloc; ;} break; - case 608: -#line 507 "third_party/libpg_query/grammar/statements/select.y" + case 585: +#line 491 "third_party/libpg_query/grammar/statements/select.y" { (yyval.into) = NULL; ;} break; - case 609: -#line 516 "third_party/libpg_query/grammar/statements/select.y" + case 586: +#line 500 "third_party/libpg_query/grammar/statements/select.y" { (yyval.range) = (yyvsp[(3) - (3)].range); (yyval.range)->relpersistence = PG_RELPERSISTENCE_TEMP; ;} break; - case 610: -#line 521 "third_party/libpg_query/grammar/statements/select.y" + case 587: +#line 505 "third_party/libpg_query/grammar/statements/select.y" { (yyval.range) = (yyvsp[(3) - (3)].range); (yyval.range)->relpersistence = PG_RELPERSISTENCE_TEMP; ;} break; - case 611: -#line 526 "third_party/libpg_query/grammar/statements/select.y" + case 588: +#line 510 "third_party/libpg_query/grammar/statements/select.y" { (yyval.range) = (yyvsp[(4) - (4)].range); (yyval.range)->relpersistence = PG_RELPERSISTENCE_TEMP; ;} break; - case 612: -#line 531 "third_party/libpg_query/grammar/statements/select.y" + case 589: +#line 515 "third_party/libpg_query/grammar/statements/select.y" { (yyval.range) = (yyvsp[(4) - (4)].range); (yyval.range)->relpersistence = PG_RELPERSISTENCE_TEMP; ;} break; - case 613: -#line 536 "third_party/libpg_query/grammar/statements/select.y" + case 590: +#line 520 "third_party/libpg_query/grammar/statements/select.y" { ereport(PGWARNING, (errmsg("GLOBAL is deprecated in temporary table creation"), @@ -25280,8 +24906,8 @@ YYLTYPE yylloc; ;} break; - case 614: -#line 544 "third_party/libpg_query/grammar/statements/select.y" + case 591: +#line 528 "third_party/libpg_query/grammar/statements/select.y" { ereport(PGWARNING, (errmsg("GLOBAL is deprecated in temporary table creation"), @@ -25291,112 +24917,112 @@ YYLTYPE yylloc; ;} break; - case 615: -#line 552 "third_party/libpg_query/grammar/statements/select.y" + case 592: +#line 536 "third_party/libpg_query/grammar/statements/select.y" { (yyval.range) = (yyvsp[(3) - (3)].range); (yyval.range)->relpersistence = PG_RELPERSISTENCE_UNLOGGED; ;} break; - case 616: -#line 557 "third_party/libpg_query/grammar/statements/select.y" + case 593: +#line 541 "third_party/libpg_query/grammar/statements/select.y" { (yyval.range) = (yyvsp[(2) - (2)].range); (yyval.range)->relpersistence = RELPERSISTENCE_PERMANENT; ;} break; - case 617: -#line 562 "third_party/libpg_query/grammar/statements/select.y" + case 594: +#line 546 "third_party/libpg_query/grammar/statements/select.y" { (yyval.range) = (yyvsp[(1) - (1)].range); (yyval.range)->relpersistence = RELPERSISTENCE_PERMANENT; ;} break; - case 618: -#line 568 "third_party/libpg_query/grammar/statements/select.y" + case 595: +#line 552 "third_party/libpg_query/grammar/statements/select.y" {;} break; - case 619: -#line 569 "third_party/libpg_query/grammar/statements/select.y" + case 596: +#line 553 "third_party/libpg_query/grammar/statements/select.y" {;} break; - case 620: -#line 573 "third_party/libpg_query/grammar/statements/select.y" + case 597: +#line 557 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = true; ;} break; - case 621: -#line 574 "third_party/libpg_query/grammar/statements/select.y" + case 598: +#line 558 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 622: -#line 575 "third_party/libpg_query/grammar/statements/select.y" + case 599: +#line 559 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 623: -#line 579 "third_party/libpg_query/grammar/statements/select.y" + case 600: +#line 563 "third_party/libpg_query/grammar/statements/select.y" { ;} break; - case 624: -#line 586 "third_party/libpg_query/grammar/statements/select.y" + case 601: +#line 570 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(NIL); ;} break; - case 625: -#line 587 "third_party/libpg_query/grammar/statements/select.y" + case 602: +#line 571 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(4) - (5)].list); ;} break; - case 626: -#line 591 "third_party/libpg_query/grammar/statements/select.y" + case 603: +#line 575 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL;;} break; - case 627: -#line 592 "third_party/libpg_query/grammar/statements/select.y" + case 604: +#line 576 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 628: -#line 596 "third_party/libpg_query/grammar/statements/select.y" + case 605: +#line 580 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ignorenulls) = PG_IGNORE_NULLS;;} break; - case 629: -#line 597 "third_party/libpg_query/grammar/statements/select.y" + case 606: +#line 581 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ignorenulls) = PG_RESPECT_NULLS;;} break; - case 630: -#line 598 "third_party/libpg_query/grammar/statements/select.y" + case 607: +#line 582 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ignorenulls) = PG_DEFAULT_NULLS; ;} break; - case 631: -#line 602 "third_party/libpg_query/grammar/statements/select.y" + case 608: +#line 586 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list);;} break; - case 632: -#line 603 "third_party/libpg_query/grammar/statements/select.y" + case 609: +#line 587 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 633: -#line 607 "third_party/libpg_query/grammar/statements/select.y" + case 610: +#line 591 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (3)].list); ;} break; - case 634: -#line 609 "third_party/libpg_query/grammar/statements/select.y" + case 611: +#line 593 "third_party/libpg_query/grammar/statements/select.y" { PGSortBy *sort = makeNode(PGSortBy); PGAStar *star = makeNode(PGAStar); @@ -25411,18 +25037,18 @@ YYLTYPE yylloc; ;} break; - case 635: -#line 624 "third_party/libpg_query/grammar/statements/select.y" + case 612: +#line 608 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].sortby)); ;} break; - case 636: -#line 625 "third_party/libpg_query/grammar/statements/select.y" + case 613: +#line 609 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].sortby)); ;} break; - case 637: -#line 629 "third_party/libpg_query/grammar/statements/select.y" + case 614: +#line 613 "third_party/libpg_query/grammar/statements/select.y" { (yyval.sortby) = makeNode(PGSortBy); (yyval.sortby)->node = (yyvsp[(1) - (4)].node); @@ -25433,8 +25059,8 @@ YYLTYPE yylloc; ;} break; - case 638: -#line 638 "third_party/libpg_query/grammar/statements/select.y" + case 615: +#line 622 "third_party/libpg_query/grammar/statements/select.y" { (yyval.sortby) = makeNode(PGSortBy); (yyval.sortby)->node = (yyvsp[(1) - (3)].node); @@ -25445,73 +25071,73 @@ YYLTYPE yylloc; ;} break; - case 639: -#line 648 "third_party/libpg_query/grammar/statements/select.y" + case 616: +#line 632 "third_party/libpg_query/grammar/statements/select.y" { (yyval.sortorder) = PG_SORTBY_ASC; ;} break; - case 640: -#line 649 "third_party/libpg_query/grammar/statements/select.y" + case 617: +#line 633 "third_party/libpg_query/grammar/statements/select.y" { (yyval.sortorder) = PG_SORTBY_DESC; ;} break; - case 641: -#line 650 "third_party/libpg_query/grammar/statements/select.y" + case 618: +#line 634 "third_party/libpg_query/grammar/statements/select.y" { (yyval.sortorder) = PG_SORTBY_DEFAULT; ;} break; - case 642: -#line 653 "third_party/libpg_query/grammar/statements/select.y" + case 619: +#line 637 "third_party/libpg_query/grammar/statements/select.y" { (yyval.nullorder) = PG_SORTBY_NULLS_FIRST; ;} break; - case 643: -#line 654 "third_party/libpg_query/grammar/statements/select.y" + case 620: +#line 638 "third_party/libpg_query/grammar/statements/select.y" { (yyval.nullorder) = PG_SORTBY_NULLS_LAST; ;} break; - case 644: -#line 655 "third_party/libpg_query/grammar/statements/select.y" + case 621: +#line 639 "third_party/libpg_query/grammar/statements/select.y" { (yyval.nullorder) = PG_SORTBY_NULLS_DEFAULT; ;} break; - case 645: -#line 659 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = list_make3((yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].node), NULL); ;} + case 622: +#line 643 "third_party/libpg_query/grammar/statements/select.y" + { (yyval.list) = list_make2((yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].node)); ;} break; - case 646: -#line 660 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = list_make3((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].node), (yyvsp[(1) - (2)].node)); ;} + case 623: +#line 644 "third_party/libpg_query/grammar/statements/select.y" + { (yyval.list) = list_make2((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].node)); ;} break; - case 647: -#line 661 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = list_make3(NULL, (yyvsp[(1) - (1)].node), NULL); ;} + case 624: +#line 645 "third_party/libpg_query/grammar/statements/select.y" + { (yyval.list) = list_make2(NULL, (yyvsp[(1) - (1)].node)); ;} break; - case 648: -#line 662 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = list_make3((yyvsp[(1) - (1)].node), NULL, (yyvsp[(1) - (1)].node)); ;} + case 625: +#line 646 "third_party/libpg_query/grammar/statements/select.y" + { (yyval.list) = list_make2((yyvsp[(1) - (1)].node), NULL); ;} break; - case 649: -#line 666 "third_party/libpg_query/grammar/statements/select.y" + case 626: +#line 650 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 650: -#line 667 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.list) = list_make3(NULL,NULL,NULL); ;} + case 627: +#line 651 "third_party/libpg_query/grammar/statements/select.y" + { (yyval.list) = list_make2(NULL,NULL); ;} break; - case 651: -#line 672 "third_party/libpg_query/grammar/statements/select.y" + case 628: +#line 656 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 652: -#line 674 "third_party/libpg_query/grammar/statements/select.y" + case 629: +#line 658 "third_party/libpg_query/grammar/statements/select.y" { /* Disabled because it was too confusing, bjm 2002-02-18 */ ereport(ERROR, @@ -25522,408 +25148,378 @@ YYLTYPE yylloc; ;} break; - case 653: -#line 690 "third_party/libpg_query/grammar/statements/select.y" + case 630: +#line 674 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(3) - (5)].node); ;} break; - case 654: -#line 692 "third_party/libpg_query/grammar/statements/select.y" + case 631: +#line 676 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeIntConst(1, -1); ;} break; - case 655: -#line 697 "third_party/libpg_query/grammar/statements/select.y" + case 632: +#line 681 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 656: -#line 700 "third_party/libpg_query/grammar/statements/select.y" + case 633: +#line 684 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (3)].node); ;} break; - case 657: -#line 705 "third_party/libpg_query/grammar/statements/select.y" + case 634: +#line 689 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeFloatConst((yyvsp[(1) - (1)].str), (yylsp[(1) - (1)])); ;} break; - case 658: -#line 709 "third_party/libpg_query/grammar/statements/select.y" + case 635: +#line 693 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeIntConst((yyvsp[(1) - (1)].ival), (yylsp[(1) - (1)])); ;} break; - case 660: -#line 720 "third_party/libpg_query/grammar/statements/select.y" + case 637: +#line 704 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSampleSize((yyvsp[(1) - (2)].node), true); ;} break; - case 661: -#line 724 "third_party/libpg_query/grammar/statements/select.y" + case 638: +#line 708 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSampleSize((yyvsp[(1) - (2)].node), true); ;} break; - case 662: -#line 728 "third_party/libpg_query/grammar/statements/select.y" + case 639: +#line 712 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSampleSize((yyvsp[(1) - (1)].node), false); ;} break; - case 663: -#line 732 "third_party/libpg_query/grammar/statements/select.y" + case 640: +#line 716 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSampleSize((yyvsp[(1) - (2)].node), false); ;} break; - case 664: -#line 739 "third_party/libpg_query/grammar/statements/select.y" + case 641: +#line 723 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(3) - (3)].node); ;} break; - case 665: -#line 743 "third_party/libpg_query/grammar/statements/select.y" + case 642: +#line 727 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 666: -#line 750 "third_party/libpg_query/grammar/statements/select.y" + case 643: +#line 734 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 667: -#line 751 "third_party/libpg_query/grammar/statements/select.y" + case 644: +#line 735 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = NULL; ;} break; - case 668: -#line 756 "third_party/libpg_query/grammar/statements/select.y" + case 645: +#line 740 "third_party/libpg_query/grammar/statements/select.y" { int seed = (yyvsp[(5) - (5)].ival); (yyval.node) = makeSampleOptions((yyvsp[(3) - (5)].node), (yyvsp[(1) - (5)].str), &seed, (yylsp[(1) - (5)])); ;} break; - case 669: -#line 761 "third_party/libpg_query/grammar/statements/select.y" + case 646: +#line 745 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSampleOptions((yyvsp[(1) - (1)].node), NULL, NULL, (yylsp[(1) - (1)])); ;} break; - case 670: -#line 765 "third_party/libpg_query/grammar/statements/select.y" + case 647: +#line 749 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeSampleOptions((yyvsp[(1) - (4)].node), (yyvsp[(3) - (4)].str), NULL, (yylsp[(1) - (4)])); ;} break; - case 671: -#line 769 "third_party/libpg_query/grammar/statements/select.y" + case 648: +#line 753 "third_party/libpg_query/grammar/statements/select.y" { int seed = (yyvsp[(5) - (6)].ival); (yyval.node) = makeSampleOptions((yyvsp[(1) - (6)].node), (yyvsp[(3) - (6)].str), &seed, (yylsp[(1) - (6)])); ;} break; - case 672: -#line 777 "third_party/libpg_query/grammar/statements/select.y" + case 649: +#line 761 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 673: -#line 783 "third_party/libpg_query/grammar/statements/select.y" + case 650: +#line 767 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 674: -#line 784 "third_party/libpg_query/grammar/statements/select.y" + case 651: +#line 768 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 675: -#line 789 "third_party/libpg_query/grammar/statements/select.y" + case 652: +#line 773 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = (yyvsp[(3) - (4)].ival); ;} break; - case 676: -#line 790 "third_party/libpg_query/grammar/statements/select.y" + case 653: +#line 774 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = -1; ;} break; - case 677: -#line 795 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.str) = (char*) "TIMESTAMP"; ;} - break; - - case 678: -#line 796 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.str) = (char*) "VERSION"; ;} - break; - - case 679: -#line 801 "third_party/libpg_query/grammar/statements/select.y" - { - PGAtClause *n = makeNode(PGAtClause); - n->unit = (yyvsp[(1) - (3)].str); - n->expr = (yyvsp[(3) - (3)].node); - (yyval.node) = (PGNode *) n; - ;} - break; - - case 680: -#line 810 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.node) = (yyvsp[(3) - (4)].node); ;} - break; - - case 681: -#line 811 "third_party/libpg_query/grammar/statements/select.y" - { (yyval.node) = NULL; ;} - break; - - case 682: -#line 816 "third_party/libpg_query/grammar/statements/select.y" + case 654: +#line 778 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 683: -#line 818 "third_party/libpg_query/grammar/statements/select.y" + case 655: +#line 780 "third_party/libpg_query/grammar/statements/select.y" { /* LIMIT ALL is represented as a NULL constant */ (yyval.node) = makeNullAConst((yylsp[(1) - (1)])); ;} break; - case 684: -#line 823 "third_party/libpg_query/grammar/statements/select.y" + case 656: +#line 785 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeLimitPercent((yyvsp[(1) - (2)].node)); ;} break; - case 685: -#line 825 "third_party/libpg_query/grammar/statements/select.y" + case 657: +#line 787 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeLimitPercent(makeFloatConst((yyvsp[(1) - (2)].str),(yylsp[(1) - (2)]))); ;} break; - case 686: -#line 827 "third_party/libpg_query/grammar/statements/select.y" + case 658: +#line 789 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeLimitPercent(makeIntConst((yyvsp[(1) - (2)].ival),(yylsp[(1) - (2)]))); ;} break; - case 687: -#line 831 "third_party/libpg_query/grammar/statements/select.y" + case 659: +#line 793 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 688: -#line 851 "third_party/libpg_query/grammar/statements/select.y" + case 660: +#line 813 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 689: -#line 853 "third_party/libpg_query/grammar/statements/select.y" + case 661: +#line 815 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "+", NULL, (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 690: -#line 855 "third_party/libpg_query/grammar/statements/select.y" + case 662: +#line 817 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = doNegate((yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 691: -#line 859 "third_party/libpg_query/grammar/statements/select.y" + case 663: +#line 821 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeIntConst((yyvsp[(1) - (1)].ival),(yylsp[(1) - (1)])); ;} break; - case 692: -#line 860 "third_party/libpg_query/grammar/statements/select.y" + case 664: +#line 822 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeFloatConst((yyvsp[(1) - (1)].str),(yylsp[(1) - (1)])); ;} break; - case 693: -#line 864 "third_party/libpg_query/grammar/statements/select.y" + case 665: +#line 826 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = 0; ;} break; - case 694: -#line 865 "third_party/libpg_query/grammar/statements/select.y" + case 666: +#line 827 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = 0; ;} break; - case 695: -#line 868 "third_party/libpg_query/grammar/statements/select.y" + case 667: +#line 830 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = 0; ;} break; - case 696: -#line 869 "third_party/libpg_query/grammar/statements/select.y" + case 668: +#line 831 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = 0; ;} break; - case 697: -#line 894 "third_party/libpg_query/grammar/statements/select.y" + case 669: +#line 856 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (3)].list); ;} break; - case 698: -#line 896 "third_party/libpg_query/grammar/statements/select.y" + case 670: +#line 858 "third_party/libpg_query/grammar/statements/select.y" { PGNode *node = (PGNode *) makeGroupingSet(GROUPING_SET_ALL, NIL, (yylsp[(3) - (3)])); (yyval.list) = list_make1(node); ;} break; - case 699: -#line 900 "third_party/libpg_query/grammar/statements/select.y" + case 671: +#line 862 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 700: -#line 904 "third_party/libpg_query/grammar/statements/select.y" + case 672: +#line 866 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 701: -#line 905 "third_party/libpg_query/grammar/statements/select.y" + case 673: +#line 867 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list),(yyvsp[(3) - (3)].node)); ;} break; - case 702: -#line 909 "third_party/libpg_query/grammar/statements/select.y" + case 674: +#line 871 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 703: -#line 910 "third_party/libpg_query/grammar/statements/select.y" + case 675: +#line 872 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 704: -#line 914 "third_party/libpg_query/grammar/statements/select.y" + case 676: +#line 876 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 705: -#line 915 "third_party/libpg_query/grammar/statements/select.y" + case 677: +#line 877 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 706: -#line 916 "third_party/libpg_query/grammar/statements/select.y" + case 678: +#line 878 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 707: -#line 917 "third_party/libpg_query/grammar/statements/select.y" + case 679: +#line 879 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 708: -#line 918 "third_party/libpg_query/grammar/statements/select.y" + case 680: +#line 880 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 709: -#line 923 "third_party/libpg_query/grammar/statements/select.y" + case 681: +#line 885 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, (yylsp[(1) - (2)])); ;} break; - case 710: -#line 936 "third_party/libpg_query/grammar/statements/select.y" + case 682: +#line 898 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeGroupingSet(GROUPING_SET_ROLLUP, (yyvsp[(3) - (4)].list), (yylsp[(1) - (4)])); ;} break; - case 711: -#line 943 "third_party/libpg_query/grammar/statements/select.y" + case 683: +#line 905 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeGroupingSet(GROUPING_SET_CUBE, (yyvsp[(3) - (4)].list), (yylsp[(1) - (4)])); ;} break; - case 712: -#line 950 "third_party/libpg_query/grammar/statements/select.y" + case 684: +#line 912 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeGroupingSet(GROUPING_SET_SETS, (yyvsp[(4) - (5)].list), (yylsp[(1) - (5)])); ;} break; - case 713: -#line 956 "third_party/libpg_query/grammar/statements/select.y" + case 685: +#line 918 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 714: -#line 957 "third_party/libpg_query/grammar/statements/select.y" + case 686: +#line 919 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 715: -#line 961 "third_party/libpg_query/grammar/statements/select.y" + case 687: +#line 923 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 716: -#line 962 "third_party/libpg_query/grammar/statements/select.y" + case 688: +#line 924 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 717: -#line 966 "third_party/libpg_query/grammar/statements/select.y" + case 689: +#line 928 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 718: -#line 967 "third_party/libpg_query/grammar/statements/select.y" + case 690: +#line 929 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 719: -#line 971 "third_party/libpg_query/grammar/statements/select.y" + case 691: +#line 933 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 720: -#line 972 "third_party/libpg_query/grammar/statements/select.y" + case 692: +#line 934 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 721: -#line 976 "third_party/libpg_query/grammar/statements/select.y" + case 693: +#line 938 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 722: -#line 977 "third_party/libpg_query/grammar/statements/select.y" + case 694: +#line 939 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 723: -#line 981 "third_party/libpg_query/grammar/statements/select.y" + case 695: +#line 943 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 724: -#line 982 "third_party/libpg_query/grammar/statements/select.y" + case 696: +#line 944 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 725: -#line 987 "third_party/libpg_query/grammar/statements/select.y" + case 697: +#line 949 "third_party/libpg_query/grammar/statements/select.y" { PGLockingClause *n = makeNode(PGLockingClause); n->lockedRels = (yyvsp[(2) - (3)].list); @@ -25933,53 +25529,53 @@ YYLTYPE yylloc; ;} break; - case 726: -#line 997 "third_party/libpg_query/grammar/statements/select.y" + case 698: +#line 959 "third_party/libpg_query/grammar/statements/select.y" { (yyval.lockstrength) = LCS_FORUPDATE; ;} break; - case 727: -#line 998 "third_party/libpg_query/grammar/statements/select.y" + case 699: +#line 960 "third_party/libpg_query/grammar/statements/select.y" { (yyval.lockstrength) = PG_LCS_FORNOKEYUPDATE; ;} break; - case 728: -#line 999 "third_party/libpg_query/grammar/statements/select.y" + case 700: +#line 961 "third_party/libpg_query/grammar/statements/select.y" { (yyval.lockstrength) = PG_LCS_FORSHARE; ;} break; - case 729: -#line 1000 "third_party/libpg_query/grammar/statements/select.y" + case 701: +#line 962 "third_party/libpg_query/grammar/statements/select.y" { (yyval.lockstrength) = PG_LCS_FORKEYSHARE; ;} break; - case 730: -#line 1004 "third_party/libpg_query/grammar/statements/select.y" + case 702: +#line 966 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 731: -#line 1005 "third_party/libpg_query/grammar/statements/select.y" + case 703: +#line 967 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 732: -#line 1010 "third_party/libpg_query/grammar/statements/select.y" + case 704: +#line 972 "third_party/libpg_query/grammar/statements/select.y" { (yyval.lockwaitpolicy) = LockWaitError; ;} break; - case 733: -#line 1011 "third_party/libpg_query/grammar/statements/select.y" + case 705: +#line 973 "third_party/libpg_query/grammar/statements/select.y" { (yyval.lockwaitpolicy) = PGLockWaitSkip; ;} break; - case 734: -#line 1012 "third_party/libpg_query/grammar/statements/select.y" + case 706: +#line 974 "third_party/libpg_query/grammar/statements/select.y" { (yyval.lockwaitpolicy) = PGLockWaitBlock; ;} break; - case 735: -#line 1022 "third_party/libpg_query/grammar/statements/select.y" + case 707: +#line 984 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *n = makeNode(PGSelectStmt); n->valuesLists = list_make1((yyvsp[(3) - (4)].list)); @@ -25987,8 +25583,8 @@ YYLTYPE yylloc; ;} break; - case 736: -#line 1028 "third_party/libpg_query/grammar/statements/select.y" + case 708: +#line 990 "third_party/libpg_query/grammar/statements/select.y" { PGSelectStmt *n = (PGSelectStmt *) (yyvsp[(1) - (5)].node); n->valuesLists = lappend(n->valuesLists, (yyvsp[(4) - (5)].list)); @@ -25996,76 +25592,74 @@ YYLTYPE yylloc; ;} break; - case 737: -#line 1036 "third_party/libpg_query/grammar/statements/select.y" + case 709: +#line 998 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 738: -#line 1037 "third_party/libpg_query/grammar/statements/select.y" + case 710: +#line 999 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (2)].node); ;} break; - case 739: -#line 1050 "third_party/libpg_query/grammar/statements/select.y" + case 711: +#line 1012 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 740: -#line 1051 "third_party/libpg_query/grammar/statements/select.y" + case 712: +#line 1013 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 741: -#line 1055 "third_party/libpg_query/grammar/statements/select.y" + case 713: +#line 1017 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 742: -#line 1056 "third_party/libpg_query/grammar/statements/select.y" + case 714: +#line 1018 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 743: -#line 1060 "third_party/libpg_query/grammar/statements/select.y" + case 715: +#line 1022 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 744: -#line 1061 "third_party/libpg_query/grammar/statements/select.y" + case 716: +#line 1023 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 745: -#line 1066 "third_party/libpg_query/grammar/statements/select.y" + case 717: +#line 1028 "third_party/libpg_query/grammar/statements/select.y" { (yyval.alias) = makeNode(PGAlias); (yyval.alias)->aliasname = (yyvsp[(1) - (2)].str); ;} break; - case 746: -#line 1077 "third_party/libpg_query/grammar/statements/select.y" + case 718: +#line 1039 "third_party/libpg_query/grammar/statements/select.y" { - (yyvsp[(1) - (4)].range)->at_clause = (yyvsp[(3) - (4)].node); - (yyvsp[(1) - (4)].range)->alias = (yyvsp[(2) - (4)].alias); - (yyvsp[(1) - (4)].range)->sample = (yyvsp[(4) - (4)].node); - (yyval.node) = (PGNode *) (yyvsp[(1) - (4)].range); + (yyvsp[(1) - (3)].range)->alias = (yyvsp[(2) - (3)].alias); + (yyvsp[(1) - (3)].range)->sample = (yyvsp[(3) - (3)].node); + (yyval.node) = (PGNode *) (yyvsp[(1) - (3)].range); ;} break; - case 747: -#line 1084 "third_party/libpg_query/grammar/statements/select.y" + case 719: +#line 1045 "third_party/libpg_query/grammar/statements/select.y" { - (yyvsp[(2) - (4)].range)->at_clause = (yyvsp[(3) - (4)].node); - (yyvsp[(2) - (4)].range)->alias = (yyvsp[(1) - (4)].alias); - (yyvsp[(2) - (4)].range)->sample = (yyvsp[(4) - (4)].node); - (yyval.node) = (PGNode *) (yyvsp[(2) - (4)].range); + (yyvsp[(2) - (3)].range)->alias = (yyvsp[(1) - (3)].alias); + (yyvsp[(2) - (3)].range)->sample = (yyvsp[(3) - (3)].node); + (yyval.node) = (PGNode *) (yyvsp[(2) - (3)].range); ;} break; - case 748: -#line 1091 "third_party/libpg_query/grammar/statements/select.y" + case 720: +#line 1051 "third_party/libpg_query/grammar/statements/select.y" { PGRangeFunction *n = (PGRangeFunction *) (yyvsp[(1) - (3)].node); n->alias = (PGAlias*) linitial((yyvsp[(2) - (3)].list)); @@ -26075,8 +25669,8 @@ YYLTYPE yylloc; ;} break; - case 749: -#line 1099 "third_party/libpg_query/grammar/statements/select.y" + case 721: +#line 1059 "third_party/libpg_query/grammar/statements/select.y" { PGRangeFunction *n = (PGRangeFunction *) (yyvsp[(2) - (3)].node); n->alias = (yyvsp[(1) - (3)].alias); @@ -26085,8 +25679,8 @@ YYLTYPE yylloc; ;} break; - case 750: -#line 1107 "third_party/libpg_query/grammar/statements/select.y" + case 722: +#line 1067 "third_party/libpg_query/grammar/statements/select.y" { PGRangeSubselect *n = makeNode(PGRangeSubselect); n->lateral = false; @@ -26097,8 +25691,8 @@ YYLTYPE yylloc; ;} break; - case 751: -#line 1117 "third_party/libpg_query/grammar/statements/select.y" + case 723: +#line 1077 "third_party/libpg_query/grammar/statements/select.y" { PGRangeFunction *n = (PGRangeFunction *) (yyvsp[(2) - (3)].node); n->lateral = true; @@ -26108,8 +25702,8 @@ YYLTYPE yylloc; ;} break; - case 752: -#line 1125 "third_party/libpg_query/grammar/statements/select.y" + case 724: +#line 1085 "third_party/libpg_query/grammar/statements/select.y" { PGRangeSubselect *n = makeNode(PGRangeSubselect); n->lateral = false; @@ -26120,8 +25714,8 @@ YYLTYPE yylloc; ;} break; - case 753: -#line 1134 "third_party/libpg_query/grammar/statements/select.y" + case 725: +#line 1094 "third_party/libpg_query/grammar/statements/select.y" { PGRangeSubselect *n = makeNode(PGRangeSubselect); n->lateral = false; @@ -26132,8 +25726,8 @@ YYLTYPE yylloc; ;} break; - case 754: -#line 1143 "third_party/libpg_query/grammar/statements/select.y" + case 726: +#line 1103 "third_party/libpg_query/grammar/statements/select.y" { PGRangeSubselect *n = makeNode(PGRangeSubselect); n->lateral = true; @@ -26144,31 +25738,31 @@ YYLTYPE yylloc; ;} break; - case 755: -#line 1152 "third_party/libpg_query/grammar/statements/select.y" + case 727: +#line 1112 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) (yyvsp[(1) - (1)].jexpr); ;} break; - case 756: -#line 1156 "third_party/libpg_query/grammar/statements/select.y" + case 728: +#line 1116 "third_party/libpg_query/grammar/statements/select.y" { (yyvsp[(2) - (4)].jexpr)->alias = (yyvsp[(4) - (4)].alias); (yyval.node) = (PGNode *) (yyvsp[(2) - (4)].jexpr); ;} break; - case 757: -#line 1161 "third_party/libpg_query/grammar/statements/select.y" + case 729: +#line 1121 "third_party/libpg_query/grammar/statements/select.y" { (yyvsp[(3) - (4)].jexpr)->alias = (yyvsp[(1) - (4)].alias); (yyval.node) = (PGNode *) (yyvsp[(3) - (4)].jexpr); ;} break; - case 758: -#line 1166 "third_party/libpg_query/grammar/statements/select.y" + case 730: +#line 1126 "third_party/libpg_query/grammar/statements/select.y" { PGPivotExpr *n = makeNode(PGPivotExpr); n->source = (yyvsp[(1) - (9)].node); @@ -26181,8 +25775,8 @@ YYLTYPE yylloc; ;} break; - case 759: -#line 1177 "third_party/libpg_query/grammar/statements/select.y" + case 731: +#line 1137 "third_party/libpg_query/grammar/statements/select.y" { PGPivotExpr *n = makeNode(PGPivotExpr); n->source = (yyvsp[(1) - (9)].node); @@ -26195,33 +25789,33 @@ YYLTYPE yylloc; ;} break; - case 760: -#line 1190 "third_party/libpg_query/grammar/statements/select.y" + case 732: +#line 1150 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (3)].list); ;} break; - case 761: -#line 1191 "third_party/libpg_query/grammar/statements/select.y" + case 733: +#line 1151 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NULL; ;} break; - case 762: -#line 1194 "third_party/libpg_query/grammar/statements/select.y" + case 734: +#line 1154 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = true; ;} break; - case 763: -#line 1195 "third_party/libpg_query/grammar/statements/select.y" + case 735: +#line 1155 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 764: -#line 1196 "third_party/libpg_query/grammar/statements/select.y" + case 736: +#line 1156 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 765: -#line 1200 "third_party/libpg_query/grammar/statements/select.y" + case 737: +#line 1160 "third_party/libpg_query/grammar/statements/select.y" { PGPivot *n = makeNode(PGPivot); n->pivot_columns = list_make1((yyvsp[(1) - (5)].node)); @@ -26230,8 +25824,8 @@ YYLTYPE yylloc; ;} break; - case 766: -#line 1208 "third_party/libpg_query/grammar/statements/select.y" + case 738: +#line 1168 "third_party/libpg_query/grammar/statements/select.y" { PGPivot *n = makeNode(PGPivot); n->pivot_columns = list_make1((yyvsp[(1) - (3)].node)); @@ -26240,23 +25834,23 @@ YYLTYPE yylloc; ;} break; - case 767: -#line 1217 "third_party/libpg_query/grammar/statements/select.y" + case 739: +#line 1177 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 768: -#line 1218 "third_party/libpg_query/grammar/statements/select.y" + case 740: +#line 1178 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 769: -#line 1219 "third_party/libpg_query/grammar/statements/select.y" + case 741: +#line 1179 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 770: -#line 1223 "third_party/libpg_query/grammar/statements/select.y" + case 742: +#line 1183 "third_party/libpg_query/grammar/statements/select.y" { PGPivot *n = makeNode(PGPivot); n->pivot_columns = (yyvsp[(1) - (5)].list); @@ -26265,8 +25859,8 @@ YYLTYPE yylloc; ;} break; - case 771: -#line 1231 "third_party/libpg_query/grammar/statements/select.y" + case 743: +#line 1191 "third_party/libpg_query/grammar/statements/select.y" { PGPivot *n = makeNode(PGPivot); n->pivot_columns = (yyvsp[(1) - (3)].list); @@ -26275,32 +25869,32 @@ YYLTYPE yylloc; ;} break; - case 772: -#line 1240 "third_party/libpg_query/grammar/statements/select.y" + case 744: +#line 1200 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 773: -#line 1244 "third_party/libpg_query/grammar/statements/select.y" + case 745: +#line 1204 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 774: -#line 1250 "third_party/libpg_query/grammar/statements/select.y" + case 746: +#line 1210 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 775: -#line 1251 "third_party/libpg_query/grammar/statements/select.y" + case 747: +#line 1211 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 776: -#line 1256 "third_party/libpg_query/grammar/statements/select.y" + case 748: +#line 1216 "third_party/libpg_query/grammar/statements/select.y" { PGPivot *n = makeNode(PGPivot); n->unpivot_columns = (yyvsp[(1) - (5)].list); @@ -26309,29 +25903,29 @@ YYLTYPE yylloc; ;} break; - case 777: -#line 1265 "third_party/libpg_query/grammar/statements/select.y" + case 749: +#line 1225 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 778: -#line 1269 "third_party/libpg_query/grammar/statements/select.y" + case 750: +#line 1229 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 779: -#line 1294 "third_party/libpg_query/grammar/statements/select.y" + case 751: +#line 1254 "third_party/libpg_query/grammar/statements/select.y" { (yyval.jexpr) = (yyvsp[(2) - (3)].jexpr); ;} break; - case 780: -#line 1298 "third_party/libpg_query/grammar/statements/select.y" + case 752: +#line 1258 "third_party/libpg_query/grammar/statements/select.y" { /* CROSS JOIN is same as unqualified inner join */ PGJoinExpr *n = makeNode(PGJoinExpr); @@ -26346,8 +25940,8 @@ YYLTYPE yylloc; ;} break; - case 781: -#line 1311 "third_party/libpg_query/grammar/statements/select.y" + case 753: +#line 1271 "third_party/libpg_query/grammar/statements/select.y" { PGJoinExpr *n = makeNode(PGJoinExpr); n->jointype = (yyvsp[(2) - (5)].jtype); @@ -26363,8 +25957,8 @@ YYLTYPE yylloc; ;} break; - case 782: -#line 1325 "third_party/libpg_query/grammar/statements/select.y" + case 754: +#line 1285 "third_party/libpg_query/grammar/statements/select.y" { /* letting join_type reduce to empty doesn't work */ PGJoinExpr *n = makeNode(PGJoinExpr); @@ -26381,8 +25975,8 @@ YYLTYPE yylloc; ;} break; - case 783: -#line 1340 "third_party/libpg_query/grammar/statements/select.y" + case 755: +#line 1300 "third_party/libpg_query/grammar/statements/select.y" { PGJoinExpr *n = makeNode(PGJoinExpr); n->jointype = (yyvsp[(3) - (5)].jtype); @@ -26396,8 +25990,8 @@ YYLTYPE yylloc; ;} break; - case 784: -#line 1352 "third_party/libpg_query/grammar/statements/select.y" + case 756: +#line 1312 "third_party/libpg_query/grammar/statements/select.y" { /* letting join_type reduce to empty doesn't work */ PGJoinExpr *n = makeNode(PGJoinExpr); @@ -26412,8 +26006,8 @@ YYLTYPE yylloc; ;} break; - case 785: -#line 1365 "third_party/libpg_query/grammar/statements/select.y" + case 757: +#line 1325 "third_party/libpg_query/grammar/statements/select.y" { PGJoinExpr *n = makeNode(PGJoinExpr); n->jointype = (yyvsp[(3) - (6)].jtype); @@ -26429,8 +26023,8 @@ YYLTYPE yylloc; ;} break; - case 786: -#line 1379 "third_party/libpg_query/grammar/statements/select.y" + case 758: +#line 1339 "third_party/libpg_query/grammar/statements/select.y" { PGJoinExpr *n = makeNode(PGJoinExpr); n->jointype = PG_JOIN_INNER; @@ -26446,8 +26040,8 @@ YYLTYPE yylloc; ;} break; - case 787: -#line 1393 "third_party/libpg_query/grammar/statements/select.y" + case 759: +#line 1353 "third_party/libpg_query/grammar/statements/select.y" { /* POSITIONAL JOIN is a coordinated scan */ PGJoinExpr *n = makeNode(PGJoinExpr); @@ -26462,8 +26056,8 @@ YYLTYPE yylloc; ;} break; - case 788: -#line 1406 "third_party/libpg_query/grammar/statements/select.y" + case 760: +#line 1366 "third_party/libpg_query/grammar/statements/select.y" { /* ANTI JOIN is a filter */ PGJoinExpr *n = makeNode(PGJoinExpr); @@ -26480,8 +26074,8 @@ YYLTYPE yylloc; ;} break; - case 789: -#line 1421 "third_party/libpg_query/grammar/statements/select.y" + case 761: +#line 1381 "third_party/libpg_query/grammar/statements/select.y" { /* SEMI JOIN is also a filter */ PGJoinExpr *n = makeNode(PGJoinExpr); @@ -26499,8 +26093,8 @@ YYLTYPE yylloc; ;} break; - case 790: -#line 1440 "third_party/libpg_query/grammar/statements/select.y" + case 762: +#line 1400 "third_party/libpg_query/grammar/statements/select.y" { (yyval.alias) = makeNode(PGAlias); (yyval.alias)->aliasname = (yyvsp[(2) - (5)].str); @@ -26508,16 +26102,16 @@ YYLTYPE yylloc; ;} break; - case 791: -#line 1446 "third_party/libpg_query/grammar/statements/select.y" + case 763: +#line 1406 "third_party/libpg_query/grammar/statements/select.y" { (yyval.alias) = makeNode(PGAlias); (yyval.alias)->aliasname = (yyvsp[(2) - (2)].str); ;} break; - case 792: -#line 1451 "third_party/libpg_query/grammar/statements/select.y" + case 764: +#line 1411 "third_party/libpg_query/grammar/statements/select.y" { (yyval.alias) = makeNode(PGAlias); (yyval.alias)->aliasname = (yyvsp[(1) - (4)].str); @@ -26525,40 +26119,40 @@ YYLTYPE yylloc; ;} break; - case 793: -#line 1457 "third_party/libpg_query/grammar/statements/select.y" + case 765: +#line 1417 "third_party/libpg_query/grammar/statements/select.y" { (yyval.alias) = makeNode(PGAlias); (yyval.alias)->aliasname = (yyvsp[(1) - (1)].str); ;} break; - case 794: -#line 1463 "third_party/libpg_query/grammar/statements/select.y" + case 766: +#line 1423 "third_party/libpg_query/grammar/statements/select.y" { (yyval.alias) = (yyvsp[(1) - (1)].alias); ;} break; - case 795: -#line 1464 "third_party/libpg_query/grammar/statements/select.y" + case 767: +#line 1424 "third_party/libpg_query/grammar/statements/select.y" { (yyval.alias) = NULL; ;} break; - case 796: -#line 1473 "third_party/libpg_query/grammar/statements/select.y" + case 768: +#line 1433 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2((yyvsp[(1) - (1)].alias), NIL); ;} break; - case 797: -#line 1477 "third_party/libpg_query/grammar/statements/select.y" + case 769: +#line 1437 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2(NULL, (yyvsp[(3) - (4)].list)); ;} break; - case 798: -#line 1481 "third_party/libpg_query/grammar/statements/select.y" + case 770: +#line 1441 "third_party/libpg_query/grammar/statements/select.y" { PGAlias *a = makeNode(PGAlias); a->aliasname = (yyvsp[(2) - (5)].str); @@ -26566,8 +26160,8 @@ YYLTYPE yylloc; ;} break; - case 799: -#line 1487 "third_party/libpg_query/grammar/statements/select.y" + case 771: +#line 1447 "third_party/libpg_query/grammar/statements/select.y" { PGAlias *a = makeNode(PGAlias); a->aliasname = (yyvsp[(1) - (4)].str); @@ -26575,65 +26169,65 @@ YYLTYPE yylloc; ;} break; - case 800: -#line 1493 "third_party/libpg_query/grammar/statements/select.y" + case 772: +#line 1453 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2(NULL, NIL); ;} break; - case 801: -#line 1498 "third_party/libpg_query/grammar/statements/select.y" + case 773: +#line 1458 "third_party/libpg_query/grammar/statements/select.y" { (yyval.jtype) = PG_JOIN_FULL; ;} break; - case 802: -#line 1499 "third_party/libpg_query/grammar/statements/select.y" + case 774: +#line 1459 "third_party/libpg_query/grammar/statements/select.y" { (yyval.jtype) = PG_JOIN_LEFT; ;} break; - case 803: -#line 1500 "third_party/libpg_query/grammar/statements/select.y" + case 775: +#line 1460 "third_party/libpg_query/grammar/statements/select.y" { (yyval.jtype) = PG_JOIN_RIGHT; ;} break; - case 804: -#line 1501 "third_party/libpg_query/grammar/statements/select.y" + case 776: +#line 1461 "third_party/libpg_query/grammar/statements/select.y" { (yyval.jtype) = PG_JOIN_SEMI; ;} break; - case 805: -#line 1502 "third_party/libpg_query/grammar/statements/select.y" + case 777: +#line 1462 "third_party/libpg_query/grammar/statements/select.y" { (yyval.jtype) = PG_JOIN_ANTI; ;} break; - case 806: -#line 1503 "third_party/libpg_query/grammar/statements/select.y" + case 778: +#line 1463 "third_party/libpg_query/grammar/statements/select.y" { (yyval.jtype) = PG_JOIN_INNER; ;} break; - case 807: -#line 1507 "third_party/libpg_query/grammar/statements/select.y" + case 779: +#line 1467 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 808: -#line 1508 "third_party/libpg_query/grammar/statements/select.y" + case 780: +#line 1468 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 809: -#line 1520 "third_party/libpg_query/grammar/statements/select.y" + case 781: +#line 1480 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) (yyvsp[(3) - (4)].list); ;} break; - case 810: -#line 1521 "third_party/libpg_query/grammar/statements/select.y" + case 782: +#line 1481 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 811: -#line 1527 "third_party/libpg_query/grammar/statements/select.y" + case 783: +#line 1487 "third_party/libpg_query/grammar/statements/select.y" { /* inheritance query, implicitly */ (yyval.range) = (yyvsp[(1) - (1)].range); @@ -26642,8 +26236,8 @@ YYLTYPE yylloc; ;} break; - case 812: -#line 1534 "third_party/libpg_query/grammar/statements/select.y" + case 784: +#line 1494 "third_party/libpg_query/grammar/statements/select.y" { /* inheritance query, explicitly */ (yyval.range) = (yyvsp[(1) - (2)].range); @@ -26652,8 +26246,8 @@ YYLTYPE yylloc; ;} break; - case 813: -#line 1541 "third_party/libpg_query/grammar/statements/select.y" + case 785: +#line 1501 "third_party/libpg_query/grammar/statements/select.y" { /* no inheritance */ (yyval.range) = (yyvsp[(2) - (2)].range); @@ -26662,8 +26256,8 @@ YYLTYPE yylloc; ;} break; - case 814: -#line 1548 "third_party/libpg_query/grammar/statements/select.y" + case 786: +#line 1508 "third_party/libpg_query/grammar/statements/select.y" { /* no inheritance, SQL99-style syntax */ (yyval.range) = (yyvsp[(3) - (4)].range); @@ -26672,8 +26266,8 @@ YYLTYPE yylloc; ;} break; - case 815: -#line 1580 "third_party/libpg_query/grammar/statements/select.y" + case 787: +#line 1540 "third_party/libpg_query/grammar/statements/select.y" { PGRangeFunction *n = makeNode(PGRangeFunction); n->lateral = false; @@ -26686,8 +26280,8 @@ YYLTYPE yylloc; ;} break; - case 816: -#line 1591 "third_party/libpg_query/grammar/statements/select.y" + case 788: +#line 1551 "third_party/libpg_query/grammar/statements/select.y" { PGRangeFunction *n = makeNode(PGRangeFunction); n->lateral = false; @@ -26700,67 +26294,67 @@ YYLTYPE yylloc; ;} break; - case 817: -#line 1604 "third_party/libpg_query/grammar/statements/select.y" + case 789: +#line 1564 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].list)); ;} break; - case 818: -#line 1608 "third_party/libpg_query/grammar/statements/select.y" + case 790: +#line 1568 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].list)); ;} break; - case 819: -#line 1609 "third_party/libpg_query/grammar/statements/select.y" + case 791: +#line 1569 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].list)); ;} break; - case 820: -#line 1612 "third_party/libpg_query/grammar/statements/select.y" + case 792: +#line 1572 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 821: -#line 1613 "third_party/libpg_query/grammar/statements/select.y" + case 793: +#line 1573 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 822: -#line 1616 "third_party/libpg_query/grammar/statements/select.y" + case 794: +#line 1576 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = true; ;} break; - case 823: -#line 1617 "third_party/libpg_query/grammar/statements/select.y" + case 795: +#line 1577 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 824: -#line 1622 "third_party/libpg_query/grammar/statements/select.y" + case 796: +#line 1582 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 825: -#line 1623 "third_party/libpg_query/grammar/statements/select.y" + case 797: +#line 1583 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 826: -#line 1629 "third_party/libpg_query/grammar/statements/select.y" + case 798: +#line 1589 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 827: -#line 1633 "third_party/libpg_query/grammar/statements/select.y" + case 799: +#line 1593 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 828: -#line 1639 "third_party/libpg_query/grammar/statements/select.y" + case 800: +#line 1599 "third_party/libpg_query/grammar/statements/select.y" { PGColumnDef *n = makeNode(PGColumnDef); n->colname = (yyvsp[(1) - (3)].str); @@ -26780,8 +26374,8 @@ YYLTYPE yylloc; ;} break; - case 829: -#line 1660 "third_party/libpg_query/grammar/statements/select.y" + case 801: +#line 1620 "third_party/libpg_query/grammar/statements/select.y" { PGCollateClause *n = makeNode(PGCollateClause); n->arg = NULL; @@ -26791,45 +26385,45 @@ YYLTYPE yylloc; ;} break; - case 830: -#line 1667 "third_party/libpg_query/grammar/statements/select.y" + case 802: +#line 1627 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 831: -#line 1681 "third_party/libpg_query/grammar/statements/select.y" + case 803: +#line 1641 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(list_make2(makeString((yyvsp[(1) - (2)].str)), (yyvsp[(2) - (2)].typnam))); ;} break; - case 832: -#line 1684 "third_party/libpg_query/grammar/statements/select.y" + case 804: +#line 1644 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (4)].list), list_make2(makeString((yyvsp[(3) - (4)].str)), (yyvsp[(4) - (4)].typnam))); ;} break; - case 835: -#line 1691 "third_party/libpg_query/grammar/statements/select.y" + case 807: +#line 1651 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 836: -#line 1692 "third_party/libpg_query/grammar/statements/select.y" + case 808: +#line 1652 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = NULL; ;} break; - case 837: -#line 1695 "third_party/libpg_query/grammar/statements/select.y" + case 809: +#line 1655 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (2)].typnam); (yyval.typnam)->arrayBounds = (yyvsp[(2) - (2)].list); ;} break; - case 838: -#line 1700 "third_party/libpg_query/grammar/statements/select.y" + case 810: +#line 1660 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(2) - (3)].typnam); (yyval.typnam)->arrayBounds = (yyvsp[(3) - (3)].list); @@ -26837,16 +26431,16 @@ YYLTYPE yylloc; ;} break; - case 839: -#line 1707 "third_party/libpg_query/grammar/statements/select.y" + case 811: +#line 1667 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (5)].typnam); (yyval.typnam)->arrayBounds = list_make1(makeInteger((yyvsp[(4) - (5)].ival))); ;} break; - case 840: -#line 1712 "third_party/libpg_query/grammar/statements/select.y" + case 812: +#line 1672 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(2) - (6)].typnam); (yyval.typnam)->arrayBounds = list_make1(makeInteger((yyvsp[(5) - (6)].ival))); @@ -26854,16 +26448,16 @@ YYLTYPE yylloc; ;} break; - case 841: -#line 1718 "third_party/libpg_query/grammar/statements/select.y" + case 813: +#line 1678 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (2)].typnam); (yyval.typnam)->arrayBounds = list_make1(makeInteger(-1)); ;} break; - case 842: -#line 1723 "third_party/libpg_query/grammar/statements/select.y" + case 814: +#line 1683 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(2) - (3)].typnam); (yyval.typnam)->arrayBounds = list_make1(makeInteger(-1)); @@ -26871,15 +26465,15 @@ YYLTYPE yylloc; ;} break; - case 843: -#line 1729 "third_party/libpg_query/grammar/statements/select.y" + case 815: +#line 1689 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = makeTypeNameFromNameList((yyvsp[(1) - (1)].list)); ;} break; - case 844: -#line 1733 "third_party/libpg_query/grammar/statements/select.y" + case 816: +#line 1693 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("struct"); (yyval.typnam)->arrayBounds = (yyvsp[(5) - (5)].list); @@ -26888,8 +26482,8 @@ YYLTYPE yylloc; ;} break; - case 845: -#line 1740 "third_party/libpg_query/grammar/statements/select.y" + case 817: +#line 1700 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("map"); (yyval.typnam)->arrayBounds = (yyvsp[(5) - (5)].list); @@ -26898,8 +26492,8 @@ YYLTYPE yylloc; ;} break; - case 846: -#line 1747 "third_party/libpg_query/grammar/statements/select.y" + case 818: +#line 1707 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("union"); (yyval.typnam)->arrayBounds = (yyvsp[(5) - (5)].list); @@ -26908,66 +26502,66 @@ YYLTYPE yylloc; ;} break; - case 847: -#line 1756 "third_party/libpg_query/grammar/statements/select.y" + case 819: +#line 1716 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2(makeString((yyvsp[(1) - (3)].str)), makeString((yyvsp[(3) - (3)].str))); ;} break; - case 848: -#line 1757 "third_party/libpg_query/grammar/statements/select.y" + case 820: +#line 1717 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), makeString((yyvsp[(3) - (3)].str))); ;} break; - case 849: -#line 1762 "third_party/libpg_query/grammar/statements/select.y" + case 821: +#line 1722 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), makeInteger(-1)); ;} break; - case 850: -#line 1764 "third_party/libpg_query/grammar/statements/select.y" + case 822: +#line 1724 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (4)].list), makeInteger((yyvsp[(3) - (4)].ival))); ;} break; - case 851: -#line 1766 "third_party/libpg_query/grammar/statements/select.y" + case 823: +#line 1726 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 852: -#line 1770 "third_party/libpg_query/grammar/statements/select.y" + case 824: +#line 1730 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 853: -#line 1771 "third_party/libpg_query/grammar/statements/select.y" + case 825: +#line 1731 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 854: -#line 1772 "third_party/libpg_query/grammar/statements/select.y" + case 826: +#line 1732 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 855: -#line 1773 "third_party/libpg_query/grammar/statements/select.y" + case 827: +#line 1733 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 856: -#line 1774 "third_party/libpg_query/grammar/statements/select.y" + case 828: +#line 1734 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 857: -#line 1776 "third_party/libpg_query/grammar/statements/select.y" + case 829: +#line 1736 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (2)].typnam); (yyval.typnam)->typmods = (yyvsp[(2) - (2)].list); ;} break; - case 858: -#line 1781 "third_party/libpg_query/grammar/statements/select.y" + case 830: +#line 1741 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (4)].typnam); (yyval.typnam)->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1), @@ -26975,28 +26569,28 @@ YYLTYPE yylloc; ;} break; - case 859: -#line 1800 "third_party/libpg_query/grammar/statements/select.y" + case 831: +#line 1760 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 860: -#line 1801 "third_party/libpg_query/grammar/statements/select.y" + case 832: +#line 1761 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 861: -#line 1802 "third_party/libpg_query/grammar/statements/select.y" + case 833: +#line 1762 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 862: -#line 1803 "third_party/libpg_query/grammar/statements/select.y" + case 834: +#line 1763 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 863: -#line 1815 "third_party/libpg_query/grammar/statements/select.y" + case 835: +#line 1775 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = makeTypeName((yyvsp[(1) - (2)].str)); (yyval.typnam)->typmods = (yyvsp[(2) - (2)].list); @@ -27004,74 +26598,74 @@ YYLTYPE yylloc; ;} break; - case 864: -#line 1828 "third_party/libpg_query/grammar/statements/select.y" + case 836: +#line 1788 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 865: -#line 1829 "third_party/libpg_query/grammar/statements/select.y" + case 837: +#line 1789 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 866: -#line 1836 "third_party/libpg_query/grammar/statements/select.y" + case 838: +#line 1796 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("int4"); (yyval.typnam)->location = (yylsp[(1) - (1)]); ;} break; - case 867: -#line 1841 "third_party/libpg_query/grammar/statements/select.y" + case 839: +#line 1801 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("int4"); (yyval.typnam)->location = (yylsp[(1) - (1)]); ;} break; - case 868: -#line 1846 "third_party/libpg_query/grammar/statements/select.y" + case 840: +#line 1806 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("int2"); (yyval.typnam)->location = (yylsp[(1) - (1)]); ;} break; - case 869: -#line 1851 "third_party/libpg_query/grammar/statements/select.y" + case 841: +#line 1811 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("int8"); (yyval.typnam)->location = (yylsp[(1) - (1)]); ;} break; - case 870: -#line 1856 "third_party/libpg_query/grammar/statements/select.y" + case 842: +#line 1816 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("float4"); (yyval.typnam)->location = (yylsp[(1) - (1)]); ;} break; - case 871: -#line 1861 "third_party/libpg_query/grammar/statements/select.y" + case 843: +#line 1821 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(2) - (2)].typnam); (yyval.typnam)->location = (yylsp[(1) - (2)]); ;} break; - case 872: -#line 1866 "third_party/libpg_query/grammar/statements/select.y" + case 844: +#line 1826 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("float8"); (yyval.typnam)->location = (yylsp[(1) - (2)]); ;} break; - case 873: -#line 1871 "third_party/libpg_query/grammar/statements/select.y" + case 845: +#line 1831 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("numeric"); (yyval.typnam)->typmods = (yyvsp[(2) - (2)].list); @@ -27079,8 +26673,8 @@ YYLTYPE yylloc; ;} break; - case 874: -#line 1877 "third_party/libpg_query/grammar/statements/select.y" + case 846: +#line 1837 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("numeric"); (yyval.typnam)->typmods = (yyvsp[(2) - (2)].list); @@ -27088,8 +26682,8 @@ YYLTYPE yylloc; ;} break; - case 875: -#line 1883 "third_party/libpg_query/grammar/statements/select.y" + case 847: +#line 1843 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("numeric"); (yyval.typnam)->typmods = (yyvsp[(2) - (2)].list); @@ -27097,16 +26691,16 @@ YYLTYPE yylloc; ;} break; - case 876: -#line 1889 "third_party/libpg_query/grammar/statements/select.y" + case 848: +#line 1849 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("bool"); (yyval.typnam)->location = (yylsp[(1) - (1)]); ;} break; - case 877: -#line 1896 "third_party/libpg_query/grammar/statements/select.y" + case 849: +#line 1856 "third_party/libpg_query/grammar/statements/select.y" { /* * Check FLOAT() precision limits assuming IEEE floating @@ -27129,44 +26723,44 @@ YYLTYPE yylloc; ;} break; - case 878: -#line 1917 "third_party/libpg_query/grammar/statements/select.y" + case 850: +#line 1877 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("float4"); ;} break; - case 879: -#line 1927 "third_party/libpg_query/grammar/statements/select.y" + case 851: +#line 1887 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 880: -#line 1931 "third_party/libpg_query/grammar/statements/select.y" + case 852: +#line 1891 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 881: -#line 1939 "third_party/libpg_query/grammar/statements/select.y" + case 853: +#line 1899 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 882: -#line 1943 "third_party/libpg_query/grammar/statements/select.y" + case 854: +#line 1903 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); (yyval.typnam)->typmods = NIL; ;} break; - case 883: -#line 1951 "third_party/libpg_query/grammar/statements/select.y" + case 855: +#line 1911 "third_party/libpg_query/grammar/statements/select.y" { const char *typname; @@ -27177,8 +26771,8 @@ YYLTYPE yylloc; ;} break; - case 884: -#line 1963 "third_party/libpg_query/grammar/statements/select.y" + case 856: +#line 1923 "third_party/libpg_query/grammar/statements/select.y" { /* bit defaults to bit(1), varbit to no limit */ if ((yyvsp[(2) - (2)].boolean)) @@ -27194,29 +26788,29 @@ YYLTYPE yylloc; ;} break; - case 885: -#line 1984 "third_party/libpg_query/grammar/statements/select.y" + case 857: +#line 1944 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 886: -#line 1988 "third_party/libpg_query/grammar/statements/select.y" + case 858: +#line 1948 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 887: -#line 1994 "third_party/libpg_query/grammar/statements/select.y" + case 859: +#line 1954 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = (yyvsp[(1) - (1)].typnam); ;} break; - case 888: -#line 1998 "third_party/libpg_query/grammar/statements/select.y" + case 860: +#line 1958 "third_party/libpg_query/grammar/statements/select.y" { /* Length was not specified so allow to be unrestricted. * This handles problems with fixed-length (bpchar) strings @@ -27229,8 +26823,8 @@ YYLTYPE yylloc; ;} break; - case 889: -#line 2011 "third_party/libpg_query/grammar/statements/select.y" + case 861: +#line 1971 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName((yyvsp[(1) - (4)].conststr)); (yyval.typnam)->typmods = list_make1(makeIntConst((yyvsp[(3) - (4)].ival), (yylsp[(3) - (4)]))); @@ -27238,8 +26832,8 @@ YYLTYPE yylloc; ;} break; - case 890: -#line 2019 "third_party/libpg_query/grammar/statements/select.y" + case 862: +#line 1979 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName((yyvsp[(1) - (1)].conststr)); /* char defaults to char(1), varchar to no limit */ @@ -27249,48 +26843,48 @@ YYLTYPE yylloc; ;} break; - case 891: -#line 2029 "third_party/libpg_query/grammar/statements/select.y" + case 863: +#line 1989 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = (yyvsp[(2) - (2)].boolean) ? "varchar": "bpchar"; ;} break; - case 892: -#line 2031 "third_party/libpg_query/grammar/statements/select.y" + case 864: +#line 1991 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = (yyvsp[(2) - (2)].boolean) ? "varchar": "bpchar"; ;} break; - case 893: -#line 2033 "third_party/libpg_query/grammar/statements/select.y" + case 865: +#line 1993 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "varchar"; ;} break; - case 894: -#line 2035 "third_party/libpg_query/grammar/statements/select.y" + case 866: +#line 1995 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = (yyvsp[(3) - (3)].boolean) ? "varchar": "bpchar"; ;} break; - case 895: -#line 2037 "third_party/libpg_query/grammar/statements/select.y" + case 867: +#line 1997 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = (yyvsp[(3) - (3)].boolean) ? "varchar": "bpchar"; ;} break; - case 896: -#line 2039 "third_party/libpg_query/grammar/statements/select.y" + case 868: +#line 1999 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = (yyvsp[(2) - (2)].boolean) ? "varchar": "bpchar"; ;} break; - case 897: -#line 2043 "third_party/libpg_query/grammar/statements/select.y" + case 869: +#line 2003 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = true; ;} break; - case 898: -#line 2044 "third_party/libpg_query/grammar/statements/select.y" + case 870: +#line 2004 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 899: -#line 2052 "third_party/libpg_query/grammar/statements/select.y" + case 871: +#line 2012 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(5) - (5)].boolean)) (yyval.typnam) = SystemTypeName("timestamptz"); @@ -27301,8 +26895,8 @@ YYLTYPE yylloc; ;} break; - case 900: -#line 2061 "third_party/libpg_query/grammar/statements/select.y" + case 872: +#line 2021 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(2) - (2)].boolean)) (yyval.typnam) = SystemTypeName("timestamptz"); @@ -27312,8 +26906,8 @@ YYLTYPE yylloc; ;} break; - case 901: -#line 2069 "third_party/libpg_query/grammar/statements/select.y" + case 873: +#line 2029 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(5) - (5)].boolean)) (yyval.typnam) = SystemTypeName("timetz"); @@ -27324,8 +26918,8 @@ YYLTYPE yylloc; ;} break; - case 902: -#line 2078 "third_party/libpg_query/grammar/statements/select.y" + case 874: +#line 2038 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(2) - (2)].boolean)) (yyval.typnam) = SystemTypeName("timetz"); @@ -27335,112 +26929,112 @@ YYLTYPE yylloc; ;} break; - case 903: -#line 2089 "third_party/libpg_query/grammar/statements/select.y" + case 875: +#line 2049 "third_party/libpg_query/grammar/statements/select.y" { (yyval.typnam) = SystemTypeName("interval"); (yyval.typnam)->location = (yylsp[(1) - (1)]); ;} break; - case 904: -#line 2096 "third_party/libpg_query/grammar/statements/select.y" + case 876: +#line 2056 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = true; ;} break; - case 905: -#line 2097 "third_party/libpg_query/grammar/statements/select.y" + case 877: +#line 2057 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 906: -#line 2098 "third_party/libpg_query/grammar/statements/select.y" + case 878: +#line 2058 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 933: -#line 2142 "third_party/libpg_query/grammar/statements/select.y" + case 905: +#line 2102 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(YEAR), (yylsp[(1) - (1)]))); ;} break; - case 934: -#line 2144 "third_party/libpg_query/grammar/statements/select.y" + case 906: +#line 2104 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(MONTH), (yylsp[(1) - (1)]))); ;} break; - case 935: -#line 2146 "third_party/libpg_query/grammar/statements/select.y" + case 907: +#line 2106 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(DAY), (yylsp[(1) - (1)]))); ;} break; - case 936: -#line 2148 "third_party/libpg_query/grammar/statements/select.y" + case 908: +#line 2108 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(HOUR), (yylsp[(1) - (1)]))); ;} break; - case 937: -#line 2150 "third_party/libpg_query/grammar/statements/select.y" + case 909: +#line 2110 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), (yylsp[(1) - (1)]))); ;} break; - case 938: -#line 2152 "third_party/libpg_query/grammar/statements/select.y" + case 910: +#line 2112 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(SECOND), (yylsp[(1) - (1)]))); ;} break; - case 939: -#line 2154 "third_party/libpg_query/grammar/statements/select.y" + case 911: +#line 2114 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(MILLISECOND), (yylsp[(1) - (1)]))); ;} break; - case 940: -#line 2156 "third_party/libpg_query/grammar/statements/select.y" + case 912: +#line 2116 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(MICROSECOND), (yylsp[(1) - (1)]))); ;} break; - case 941: -#line 2158 "third_party/libpg_query/grammar/statements/select.y" + case 913: +#line 2118 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(WEEK), (yylsp[(1) - (1)]))); ;} break; - case 942: -#line 2160 "third_party/libpg_query/grammar/statements/select.y" + case 914: +#line 2120 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(QUARTER), (yylsp[(1) - (1)]))); ;} break; - case 943: -#line 2162 "third_party/libpg_query/grammar/statements/select.y" + case 915: +#line 2122 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(DECADE), (yylsp[(1) - (1)]))); ;} break; - case 944: -#line 2164 "third_party/libpg_query/grammar/statements/select.y" + case 916: +#line 2124 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(CENTURY), (yylsp[(1) - (1)]))); ;} break; - case 945: -#line 2166 "third_party/libpg_query/grammar/statements/select.y" + case 917: +#line 2126 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(MILLENNIUM), (yylsp[(1) - (1)]))); ;} break; - case 946: -#line 2168 "third_party/libpg_query/grammar/statements/select.y" + case 918: +#line 2128 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(YEAR) | INTERVAL_MASK(MONTH), (yylsp[(1) - (3)]))); ;} break; - case 947: -#line 2173 "third_party/libpg_query/grammar/statements/select.y" + case 919: +#line 2133 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(DAY) | INTERVAL_MASK(HOUR), (yylsp[(1) - (3)]))); ;} break; - case 948: -#line 2178 "third_party/libpg_query/grammar/statements/select.y" + case 920: +#line 2138 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(DAY) | INTERVAL_MASK(HOUR) | @@ -27448,8 +27042,8 @@ YYLTYPE yylloc; ;} break; - case 949: -#line 2184 "third_party/libpg_query/grammar/statements/select.y" + case 921: +#line 2144 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(DAY) | INTERVAL_MASK(HOUR) | @@ -27458,16 +27052,16 @@ YYLTYPE yylloc; ;} break; - case 950: -#line 2191 "third_party/libpg_query/grammar/statements/select.y" + case 922: +#line 2151 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE), (yylsp[(1) - (3)]))); ;} break; - case 951: -#line 2196 "third_party/libpg_query/grammar/statements/select.y" + case 923: +#line 2156 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE) | @@ -27475,31 +27069,31 @@ YYLTYPE yylloc; ;} break; - case 952: -#line 2202 "third_party/libpg_query/grammar/statements/select.y" + case 924: +#line 2162 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeIntConst(INTERVAL_MASK(MINUTE) | INTERVAL_MASK(SECOND), (yylsp[(1) - (3)]))); ;} break; - case 953: -#line 2207 "third_party/libpg_query/grammar/statements/select.y" + case 925: +#line 2167 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 954: -#line 2238 "third_party/libpg_query/grammar/statements/select.y" + case 926: +#line 2198 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 955: -#line 2241 "third_party/libpg_query/grammar/statements/select.y" + case 927: +#line 2201 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeTypeCast((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].typnam), 0, (yylsp[(2) - (3)])); ;} break; - case 956: -#line 2243 "third_party/libpg_query/grammar/statements/select.y" + case 928: +#line 2203 "third_party/libpg_query/grammar/statements/select.y" { PGCollateClause *n = makeNode(PGCollateClause); n->arg = (yyvsp[(1) - (3)].node); @@ -27509,8 +27103,8 @@ YYLTYPE yylloc; ;} break; - case 957: -#line 2251 "third_party/libpg_query/grammar/statements/select.y" + case 929: +#line 2211 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeFuncCall(SystemFuncName("timezone"), list_make2((yyvsp[(5) - (5)].node), (yyvsp[(1) - (5)].node)), @@ -27518,139 +27112,139 @@ YYLTYPE yylloc; ;} break; - case 958: -#line 2266 "third_party/libpg_query/grammar/statements/select.y" + case 930: +#line 2226 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "+", NULL, (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 959: -#line 2268 "third_party/libpg_query/grammar/statements/select.y" + case 931: +#line 2228 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = doNegate((yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 960: -#line 2270 "third_party/libpg_query/grammar/statements/select.y" + case 932: +#line 2230 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "+", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 961: -#line 2272 "third_party/libpg_query/grammar/statements/select.y" + case 933: +#line 2232 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "-", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 962: -#line 2274 "third_party/libpg_query/grammar/statements/select.y" + case 934: +#line 2234 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "*", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 963: -#line 2276 "third_party/libpg_query/grammar/statements/select.y" + case 935: +#line 2236 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "/", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 964: -#line 2278 "third_party/libpg_query/grammar/statements/select.y" + case 936: +#line 2238 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "//", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 965: -#line 2280 "third_party/libpg_query/grammar/statements/select.y" + case 937: +#line 2240 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "%", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 966: -#line 2282 "third_party/libpg_query/grammar/statements/select.y" + case 938: +#line 2242 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "^", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 967: -#line 2284 "third_party/libpg_query/grammar/statements/select.y" + case 939: +#line 2244 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "**", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 968: -#line 2286 "third_party/libpg_query/grammar/statements/select.y" + case 940: +#line 2246 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "<", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 969: -#line 2288 "third_party/libpg_query/grammar/statements/select.y" + case 941: +#line 2248 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, ">", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 970: -#line 2290 "third_party/libpg_query/grammar/statements/select.y" + case 942: +#line 2250 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "=", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 971: -#line 2292 "third_party/libpg_query/grammar/statements/select.y" + case 943: +#line 2252 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "<=", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 972: -#line 2294 "third_party/libpg_query/grammar/statements/select.y" + case 944: +#line 2254 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, ">=", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 973: -#line 2296 "third_party/libpg_query/grammar/statements/select.y" + case 945: +#line 2256 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "<>", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 974: -#line 2299 "third_party/libpg_query/grammar/statements/select.y" + case 946: +#line 2259 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeAExpr(PG_AEXPR_OP, (yyvsp[(2) - (3)].list), (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 975: -#line 2301 "third_party/libpg_query/grammar/statements/select.y" + case 947: +#line 2261 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeAExpr(PG_AEXPR_OP, (yyvsp[(1) - (2)].list), NULL, (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 976: -#line 2303 "third_party/libpg_query/grammar/statements/select.y" + case 948: +#line 2263 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeAExpr(PG_AEXPR_OP, (yyvsp[(2) - (2)].list), (yyvsp[(1) - (2)].node), NULL, (yylsp[(2) - (2)])); ;} break; - case 977: -#line 2306 "third_party/libpg_query/grammar/statements/select.y" + case 949: +#line 2266 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeAndExpr((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 978: -#line 2308 "third_party/libpg_query/grammar/statements/select.y" + case 950: +#line 2268 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeOrExpr((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 979: -#line 2310 "third_party/libpg_query/grammar/statements/select.y" + case 951: +#line 2270 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeNotExpr((yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 980: -#line 2312 "third_party/libpg_query/grammar/statements/select.y" + case 952: +#line 2272 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeNotExpr((yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 981: -#line 2314 "third_party/libpg_query/grammar/statements/select.y" + case 953: +#line 2274 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_GLOB, "~~~", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 982: -#line 2319 "third_party/libpg_query/grammar/statements/select.y" + case 954: +#line 2279 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_LIKE, "~~", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 983: -#line 2324 "third_party/libpg_query/grammar/statements/select.y" + case 955: +#line 2284 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("like_escape"), list_make3((yyvsp[(1) - (5)].node), (yyvsp[(3) - (5)].node), (yyvsp[(5) - (5)].node)), @@ -27659,16 +27253,16 @@ YYLTYPE yylloc; ;} break; - case 984: -#line 2331 "third_party/libpg_query/grammar/statements/select.y" + case 956: +#line 2291 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_LIKE, "!~~", (yyvsp[(1) - (4)].node), (yyvsp[(4) - (4)].node), (yylsp[(2) - (4)])); ;} break; - case 985: -#line 2336 "third_party/libpg_query/grammar/statements/select.y" + case 957: +#line 2296 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("not_like_escape"), list_make3((yyvsp[(1) - (6)].node), (yyvsp[(4) - (6)].node), (yyvsp[(6) - (6)].node)), @@ -27677,16 +27271,16 @@ YYLTYPE yylloc; ;} break; - case 986: -#line 2343 "third_party/libpg_query/grammar/statements/select.y" + case 958: +#line 2303 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_ILIKE, "~~*", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 987: -#line 2348 "third_party/libpg_query/grammar/statements/select.y" + case 959: +#line 2308 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("ilike_escape"), list_make3((yyvsp[(1) - (5)].node), (yyvsp[(3) - (5)].node), (yyvsp[(5) - (5)].node)), @@ -27695,16 +27289,16 @@ YYLTYPE yylloc; ;} break; - case 988: -#line 2355 "third_party/libpg_query/grammar/statements/select.y" + case 960: +#line 2315 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_ILIKE, "!~~*", (yyvsp[(1) - (4)].node), (yyvsp[(4) - (4)].node), (yylsp[(2) - (4)])); ;} break; - case 989: -#line 2360 "third_party/libpg_query/grammar/statements/select.y" + case 961: +#line 2320 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("not_ilike_escape"), list_make3((yyvsp[(1) - (6)].node), (yyvsp[(4) - (6)].node), (yyvsp[(6) - (6)].node)), @@ -27713,8 +27307,8 @@ YYLTYPE yylloc; ;} break; - case 990: -#line 2368 "third_party/libpg_query/grammar/statements/select.y" + case 962: +#line 2328 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("similar_escape"), list_make2((yyvsp[(4) - (4)].node), makeNullAConst(-1)), @@ -27724,8 +27318,8 @@ YYLTYPE yylloc; ;} break; - case 991: -#line 2376 "third_party/libpg_query/grammar/statements/select.y" + case 963: +#line 2336 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("similar_escape"), list_make2((yyvsp[(4) - (6)].node), (yyvsp[(6) - (6)].node)), @@ -27735,8 +27329,8 @@ YYLTYPE yylloc; ;} break; - case 992: -#line 2384 "third_party/libpg_query/grammar/statements/select.y" + case 964: +#line 2344 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("similar_escape"), list_make2((yyvsp[(5) - (5)].node), makeNullAConst(-1)), @@ -27746,8 +27340,8 @@ YYLTYPE yylloc; ;} break; - case 993: -#line 2392 "third_party/libpg_query/grammar/statements/select.y" + case 965: +#line 2352 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("similar_escape"), list_make2((yyvsp[(5) - (7)].node), (yyvsp[(7) - (7)].node)), @@ -27757,8 +27351,8 @@ YYLTYPE yylloc; ;} break; - case 994: -#line 2410 "third_party/libpg_query/grammar/statements/select.y" + case 966: +#line 2370 "third_party/libpg_query/grammar/statements/select.y" { PGNullTest *n = makeNode(PGNullTest); n->arg = (PGExpr *) (yyvsp[(1) - (3)].node); @@ -27768,8 +27362,8 @@ YYLTYPE yylloc; ;} break; - case 995: -#line 2418 "third_party/libpg_query/grammar/statements/select.y" + case 967: +#line 2378 "third_party/libpg_query/grammar/statements/select.y" { PGNullTest *n = makeNode(PGNullTest); n->arg = (PGExpr *) (yyvsp[(1) - (2)].node); @@ -27779,8 +27373,8 @@ YYLTYPE yylloc; ;} break; - case 996: -#line 2426 "third_party/libpg_query/grammar/statements/select.y" + case 968: +#line 2386 "third_party/libpg_query/grammar/statements/select.y" { PGNullTest *n = makeNode(PGNullTest); n->arg = (PGExpr *) (yyvsp[(1) - (4)].node); @@ -27790,8 +27384,8 @@ YYLTYPE yylloc; ;} break; - case 997: -#line 2434 "third_party/libpg_query/grammar/statements/select.y" + case 969: +#line 2394 "third_party/libpg_query/grammar/statements/select.y" { PGNullTest *n = makeNode(PGNullTest); n->arg = (PGExpr *) (yyvsp[(1) - (3)].node); @@ -27801,8 +27395,8 @@ YYLTYPE yylloc; ;} break; - case 998: -#line 2442 "third_party/libpg_query/grammar/statements/select.y" + case 970: +#line 2402 "third_party/libpg_query/grammar/statements/select.y" { PGNullTest *n = makeNode(PGNullTest); n->arg = (PGExpr *) (yyvsp[(1) - (2)].node); @@ -27812,8 +27406,8 @@ YYLTYPE yylloc; ;} break; - case 999: -#line 2450 "third_party/libpg_query/grammar/statements/select.y" + case 971: +#line 2410 "third_party/libpg_query/grammar/statements/select.y" { PGLambdaFunction *n = makeNode(PGLambdaFunction); n->lhs = (yyvsp[(1) - (3)].node); @@ -27823,15 +27417,15 @@ YYLTYPE yylloc; ;} break; - case 1000: -#line 2458 "third_party/libpg_query/grammar/statements/select.y" + case 972: +#line 2418 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "->>", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1001: -#line 2462 "third_party/libpg_query/grammar/statements/select.y" + case 973: +#line 2422 "third_party/libpg_query/grammar/statements/select.y" { if (list_length((yyvsp[(1) - (3)].list)) != 2) ereport(ERROR, @@ -27849,8 +27443,8 @@ YYLTYPE yylloc; ;} break; - case 1002: -#line 2478 "third_party/libpg_query/grammar/statements/select.y" + case 974: +#line 2438 "third_party/libpg_query/grammar/statements/select.y" { PGBooleanTest *b = makeNode(PGBooleanTest); b->arg = (PGExpr *) (yyvsp[(1) - (3)].node); @@ -27860,8 +27454,8 @@ YYLTYPE yylloc; ;} break; - case 1003: -#line 2486 "third_party/libpg_query/grammar/statements/select.y" + case 975: +#line 2446 "third_party/libpg_query/grammar/statements/select.y" { PGBooleanTest *b = makeNode(PGBooleanTest); b->arg = (PGExpr *) (yyvsp[(1) - (4)].node); @@ -27871,8 +27465,8 @@ YYLTYPE yylloc; ;} break; - case 1004: -#line 2494 "third_party/libpg_query/grammar/statements/select.y" + case 976: +#line 2454 "third_party/libpg_query/grammar/statements/select.y" { PGBooleanTest *b = makeNode(PGBooleanTest); b->arg = (PGExpr *) (yyvsp[(1) - (3)].node); @@ -27882,8 +27476,8 @@ YYLTYPE yylloc; ;} break; - case 1005: -#line 2502 "third_party/libpg_query/grammar/statements/select.y" + case 977: +#line 2462 "third_party/libpg_query/grammar/statements/select.y" { PGBooleanTest *b = makeNode(PGBooleanTest); b->arg = (PGExpr *) (yyvsp[(1) - (4)].node); @@ -27893,8 +27487,8 @@ YYLTYPE yylloc; ;} break; - case 1006: -#line 2510 "third_party/libpg_query/grammar/statements/select.y" + case 978: +#line 2470 "third_party/libpg_query/grammar/statements/select.y" { PGBooleanTest *b = makeNode(PGBooleanTest); b->arg = (PGExpr *) (yyvsp[(1) - (3)].node); @@ -27904,8 +27498,8 @@ YYLTYPE yylloc; ;} break; - case 1007: -#line 2518 "third_party/libpg_query/grammar/statements/select.y" + case 979: +#line 2478 "third_party/libpg_query/grammar/statements/select.y" { PGBooleanTest *b = makeNode(PGBooleanTest); b->arg = (PGExpr *) (yyvsp[(1) - (4)].node); @@ -27915,36 +27509,36 @@ YYLTYPE yylloc; ;} break; - case 1008: -#line 2526 "third_party/libpg_query/grammar/statements/select.y" + case 980: +#line 2486 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_DISTINCT, "=", (yyvsp[(1) - (5)].node), (yyvsp[(5) - (5)].node), (yylsp[(2) - (5)])); ;} break; - case 1009: -#line 2530 "third_party/libpg_query/grammar/statements/select.y" + case 981: +#line 2490 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_NOT_DISTINCT, "=", (yyvsp[(1) - (6)].node), (yyvsp[(6) - (6)].node), (yylsp[(2) - (6)])); ;} break; - case 1010: -#line 2534 "third_party/libpg_query/grammar/statements/select.y" + case 982: +#line 2494 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OF, "=", (yyvsp[(1) - (6)].node), (PGNode *) (yyvsp[(5) - (6)].list), (yylsp[(2) - (6)])); ;} break; - case 1011: -#line 2538 "third_party/libpg_query/grammar/statements/select.y" + case 983: +#line 2498 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OF, "<>", (yyvsp[(1) - (7)].node), (PGNode *) (yyvsp[(6) - (7)].list), (yylsp[(2) - (7)])); ;} break; - case 1012: -#line 2542 "third_party/libpg_query/grammar/statements/select.y" + case 984: +#line 2502 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_BETWEEN, "BETWEEN", @@ -27954,8 +27548,8 @@ YYLTYPE yylloc; ;} break; - case 1013: -#line 2550 "third_party/libpg_query/grammar/statements/select.y" + case 985: +#line 2510 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_NOT_BETWEEN, "NOT BETWEEN", @@ -27965,8 +27559,8 @@ YYLTYPE yylloc; ;} break; - case 1014: -#line 2558 "third_party/libpg_query/grammar/statements/select.y" + case 986: +#line 2518 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_BETWEEN_SYM, "BETWEEN SYMMETRIC", @@ -27976,8 +27570,8 @@ YYLTYPE yylloc; ;} break; - case 1015: -#line 2566 "third_party/libpg_query/grammar/statements/select.y" + case 987: +#line 2526 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_NOT_BETWEEN_SYM, "NOT BETWEEN SYMMETRIC", @@ -27987,8 +27581,8 @@ YYLTYPE yylloc; ;} break; - case 1016: -#line 2574 "third_party/libpg_query/grammar/statements/select.y" + case 988: +#line 2534 "third_party/libpg_query/grammar/statements/select.y" { /* in_expr returns a PGSubLink or a list of a_exprs */ if (IsA((yyvsp[(3) - (3)].node), PGSubLink)) @@ -28010,8 +27604,8 @@ YYLTYPE yylloc; ;} break; - case 1017: -#line 2594 "third_party/libpg_query/grammar/statements/select.y" + case 989: +#line 2554 "third_party/libpg_query/grammar/statements/select.y" { /* in_expr returns a PGSubLink or a list of a_exprs */ if (IsA((yyvsp[(4) - (4)].node), PGSubLink)) @@ -28035,8 +27629,8 @@ YYLTYPE yylloc; ;} break; - case 1018: -#line 2616 "third_party/libpg_query/grammar/statements/select.y" + case 990: +#line 2576 "third_party/libpg_query/grammar/statements/select.y" { PGSubLink *n = makeNode(PGSubLink); n->subLinkType = (yyvsp[(3) - (4)].subquerytype); @@ -28049,8 +27643,8 @@ YYLTYPE yylloc; ;} break; - case 1019: -#line 2627 "third_party/libpg_query/grammar/statements/select.y" + case 991: +#line 2587 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(3) - (6)].subquerytype) == PG_ANY_SUBLINK) (yyval.node) = (PGNode *) makeAExpr(PG_AEXPR_OP_ANY, (yyvsp[(2) - (6)].list), (yyvsp[(1) - (6)].node), (yyvsp[(5) - (6)].node), (yylsp[(2) - (6)])); @@ -28059,8 +27653,8 @@ YYLTYPE yylloc; ;} break; - case 1020: -#line 2634 "third_party/libpg_query/grammar/statements/select.y" + case 992: +#line 2594 "third_party/libpg_query/grammar/statements/select.y" { /* * The SQL spec only allows DEFAULT in "contextually typed @@ -28072,44 +27666,35 @@ YYLTYPE yylloc; PGSetToDefault *n = makeNode(PGSetToDefault); /* parse analysis will fill in the rest */ n->location = (yylsp[(1) - (1)]); - (yyval.node) = (PGNode *)n; - ;} - break; - - case 1021: -#line 2648 "third_party/libpg_query/grammar/statements/select.y" - { - PGAStar *star = makeNode(PGAStar); - star->expr = (yyvsp[(3) - (4)].node); - star->columns = true; - star->location = (yylsp[(1) - (4)]); - (yyval.node) = (PGNode *) star; - ;} - break; - - case 1022: -#line 2656 "third_party/libpg_query/grammar/statements/select.y" - { - PGFuncCall *n = makeFuncCall(SystemFuncName("unpack"), list_make1((yyvsp[(3) - (4)].node)), (yylsp[(1) - (4)])); - (yyval.node) = (PGNode *) n; + (yyval.node) = (PGNode *)n; ;} break; - case 1023: -#line 2661 "third_party/libpg_query/grammar/statements/select.y" + case 993: +#line 2608 "third_party/libpg_query/grammar/statements/select.y" { PGAStar *star = makeNode(PGAStar); star->expr = (yyvsp[(4) - (5)].node); star->columns = true; + star->unpacked = true; star->location = (yylsp[(1) - (5)]); + (yyval.node) = (PGNode *) star; + ;} + break; - PGFuncCall *n = makeFuncCall(SystemFuncName("unpack"), list_make1((PGNode *)star), (yylsp[(1) - (5)])); - (yyval.node) = (PGNode *) n; + case 994: +#line 2617 "third_party/libpg_query/grammar/statements/select.y" + { + PGAStar *star = makeNode(PGAStar); + star->expr = (yyvsp[(3) - (4)].node); + star->columns = true; + star->location = (yylsp[(1) - (4)]); + (yyval.node) = (PGNode *) star; ;} break; - case 1024: -#line 2671 "third_party/libpg_query/grammar/statements/select.y" + case 995: +#line 2625 "third_party/libpg_query/grammar/statements/select.y" { PGAStar *star = makeNode(PGAStar); star->except_list = (yyvsp[(2) - (4)].list); @@ -28120,8 +27705,8 @@ YYLTYPE yylloc; ;} break; - case 1025: -#line 2680 "third_party/libpg_query/grammar/statements/select.y" + case 996: +#line 2634 "third_party/libpg_query/grammar/statements/select.y" { PGAStar *star = makeNode(PGAStar); star->relation = (yyvsp[(1) - (6)].str); @@ -28133,141 +27718,141 @@ YYLTYPE yylloc; ;} break; - case 1026: -#line 2701 "third_party/libpg_query/grammar/statements/select.y" + case 997: +#line 2655 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1027: -#line 2703 "third_party/libpg_query/grammar/statements/select.y" + case 998: +#line 2657 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeTypeCast((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].typnam), 0, (yylsp[(2) - (3)])); ;} break; - case 1028: -#line 2705 "third_party/libpg_query/grammar/statements/select.y" + case 999: +#line 2659 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "+", NULL, (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 1029: -#line 2707 "third_party/libpg_query/grammar/statements/select.y" + case 1000: +#line 2661 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = doNegate((yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 1030: -#line 2709 "third_party/libpg_query/grammar/statements/select.y" + case 1001: +#line 2663 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "+", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1031: -#line 2711 "third_party/libpg_query/grammar/statements/select.y" + case 1002: +#line 2665 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "-", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1032: -#line 2713 "third_party/libpg_query/grammar/statements/select.y" + case 1003: +#line 2667 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "*", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1033: -#line 2715 "third_party/libpg_query/grammar/statements/select.y" + case 1004: +#line 2669 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "/", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1034: -#line 2717 "third_party/libpg_query/grammar/statements/select.y" + case 1005: +#line 2671 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "//", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1035: -#line 2719 "third_party/libpg_query/grammar/statements/select.y" + case 1006: +#line 2673 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "%", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1036: -#line 2721 "third_party/libpg_query/grammar/statements/select.y" + case 1007: +#line 2675 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "^", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1037: -#line 2723 "third_party/libpg_query/grammar/statements/select.y" + case 1008: +#line 2677 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "**", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1038: -#line 2725 "third_party/libpg_query/grammar/statements/select.y" + case 1009: +#line 2679 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "<", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1039: -#line 2727 "third_party/libpg_query/grammar/statements/select.y" + case 1010: +#line 2681 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, ">", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1040: -#line 2729 "third_party/libpg_query/grammar/statements/select.y" + case 1011: +#line 2683 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "=", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1041: -#line 2731 "third_party/libpg_query/grammar/statements/select.y" + case 1012: +#line 2685 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "<=", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1042: -#line 2733 "third_party/libpg_query/grammar/statements/select.y" + case 1013: +#line 2687 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, ">=", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1043: -#line 2735 "third_party/libpg_query/grammar/statements/select.y" + case 1014: +#line 2689 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OP, "<>", (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1044: -#line 2737 "third_party/libpg_query/grammar/statements/select.y" + case 1015: +#line 2691 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeAExpr(PG_AEXPR_OP, (yyvsp[(2) - (3)].list), (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yylsp[(2) - (3)])); ;} break; - case 1045: -#line 2739 "third_party/libpg_query/grammar/statements/select.y" + case 1016: +#line 2693 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeAExpr(PG_AEXPR_OP, (yyvsp[(1) - (2)].list), NULL, (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 1046: -#line 2741 "third_party/libpg_query/grammar/statements/select.y" + case 1017: +#line 2695 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeAExpr(PG_AEXPR_OP, (yyvsp[(2) - (2)].list), (yyvsp[(1) - (2)].node), NULL, (yylsp[(2) - (2)])); ;} break; - case 1047: -#line 2743 "third_party/libpg_query/grammar/statements/select.y" + case 1018: +#line 2697 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_DISTINCT, "=", (yyvsp[(1) - (5)].node), (yyvsp[(5) - (5)].node), (yylsp[(2) - (5)])); ;} break; - case 1048: -#line 2747 "third_party/libpg_query/grammar/statements/select.y" + case 1019: +#line 2701 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_NOT_DISTINCT, "=", (yyvsp[(1) - (6)].node), (yyvsp[(6) - (6)].node), (yylsp[(2) - (6)])); ;} break; - case 1049: -#line 2751 "third_party/libpg_query/grammar/statements/select.y" + case 1020: +#line 2705 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OF, "=", (yyvsp[(1) - (6)].node), (PGNode *) (yyvsp[(5) - (6)].list), (yylsp[(2) - (6)])); ;} break; - case 1050: -#line 2755 "third_party/libpg_query/grammar/statements/select.y" + case 1021: +#line 2709 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_OF, "<>", (yyvsp[(1) - (7)].node), (PGNode *) (yyvsp[(6) - (7)].list), (yylsp[(2) - (7)])); ;} break; - case 1052: -#line 2770 "third_party/libpg_query/grammar/statements/select.y" + case 1023: +#line 2724 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(2) - (2)].list)) { @@ -28281,18 +27866,18 @@ YYLTYPE yylloc; ;} break; - case 1053: -#line 2783 "third_party/libpg_query/grammar/statements/select.y" + case 1024: +#line 2737 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1054: -#line 2784 "third_party/libpg_query/grammar/statements/select.y" + case 1025: +#line 2738 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1055: -#line 2786 "third_party/libpg_query/grammar/statements/select.y" + case 1026: +#line 2740 "third_party/libpg_query/grammar/statements/select.y" { PGSubLink *n = makeNode(PGSubLink); n->subLinkType = PG_EXPR_SUBLINK; @@ -28305,8 +27890,8 @@ YYLTYPE yylloc; ;} break; - case 1056: -#line 2797 "third_party/libpg_query/grammar/statements/select.y" + case 1027: +#line 2751 "third_party/libpg_query/grammar/statements/select.y" { /* * Because the select_with_parens nonterminal is designed @@ -28332,8 +27917,8 @@ YYLTYPE yylloc; ;} break; - case 1057: -#line 2821 "third_party/libpg_query/grammar/statements/select.y" + case 1028: +#line 2775 "third_party/libpg_query/grammar/statements/select.y" { PGSubLink *n = makeNode(PGSubLink); n->subLinkType = PG_EXISTS_SUBLINK; @@ -28346,8 +27931,8 @@ YYLTYPE yylloc; ;} break; - case 1058: -#line 2832 "third_party/libpg_query/grammar/statements/select.y" + case 1029: +#line 2786 "third_party/libpg_query/grammar/statements/select.y" { PGGroupingFunc *g = makeNode(PGGroupingFunc); g->args = (yyvsp[(3) - (4)].list); @@ -28356,37 +27941,37 @@ YYLTYPE yylloc; ;} break; - case 1059: -#line 2842 "third_party/libpg_query/grammar/statements/select.y" + case 1030: +#line 2796 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (3)].node); ;} break; - case 1060: -#line 2846 "third_party/libpg_query/grammar/statements/select.y" + case 1031: +#line 2800 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1061: -#line 2849 "third_party/libpg_query/grammar/statements/select.y" + case 1032: +#line 2803 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("row"), (yyvsp[(1) - (1)].list), (yylsp[(1) - (1)])); (yyval.node) = (PGNode *) n; ;} break; - case 1062: -#line 2857 "third_party/libpg_query/grammar/statements/select.y" + case 1033: +#line 2811 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeParamRef(0, (yylsp[(1) - (1)])); ;} break; - case 1063: -#line 2861 "third_party/libpg_query/grammar/statements/select.y" + case 1034: +#line 2815 "third_party/libpg_query/grammar/statements/select.y" { PGParamRef *p = makeNode(PGParamRef); p->number = (yyvsp[(1) - (1)].ival); @@ -28395,15 +27980,15 @@ YYLTYPE yylloc; ;} break; - case 1064: -#line 2868 "third_party/libpg_query/grammar/statements/select.y" + case 1035: +#line 2822 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeNamedParamRef((yyvsp[(2) - (2)].str), (yylsp[(1) - (2)])); ;} break; - case 1072: -#line 2882 "third_party/libpg_query/grammar/statements/select.y" + case 1043: +#line 2836 "third_party/libpg_query/grammar/statements/select.y" { PGSubLink *n = makeNode(PGSubLink); n->subLinkType = PG_ARRAY_SUBLINK; @@ -28416,8 +28001,8 @@ YYLTYPE yylloc; ;} break; - case 1073: -#line 2892 "third_party/libpg_query/grammar/statements/select.y" + case 1044: +#line 2846 "third_party/libpg_query/grammar/statements/select.y" { PGList *func_name = list_make1(makeString("construct_array")); PGFuncCall *n = makeFuncCall(func_name, (yyvsp[(3) - (4)].list), (yylsp[(1) - (4)])); @@ -28425,8 +28010,8 @@ YYLTYPE yylloc; ;} break; - case 1074: -#line 2898 "third_party/libpg_query/grammar/statements/select.y" + case 1045: +#line 2852 "third_party/libpg_query/grammar/statements/select.y" { PGPositionalReference *n = makeNode(PGPositionalReference); n->position = (yyvsp[(2) - (2)].ival); @@ -28435,24 +28020,24 @@ YYLTYPE yylloc; ;} break; - case 1075: -#line 2906 "third_party/libpg_query/grammar/statements/select.y" + case 1046: +#line 2860 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("list_value"), (yyvsp[(2) - (3)].list), (yylsp[(2) - (3)])); (yyval.node) = (PGNode *) n; ;} break; - case 1076: -#line 2913 "third_party/libpg_query/grammar/statements/select.y" + case 1047: +#line 2867 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *f = makeFuncCall(SystemFuncName("struct_pack"), (yyvsp[(2) - (3)].list), (yylsp[(2) - (3)])); (yyval.node) = (PGNode *) f; ;} break; - case 1077: -#line 2920 "third_party/libpg_query/grammar/statements/select.y" + case 1048: +#line 2874 "third_party/libpg_query/grammar/statements/select.y" { PGList *key_list = NULL; PGList *value_list = NULL; @@ -28471,15 +28056,15 @@ YYLTYPE yylloc; ;} break; - case 1078: -#line 2940 "third_party/libpg_query/grammar/statements/select.y" + case 1049: +#line 2894 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeFuncCall((yyvsp[(1) - (3)].list), NIL, (yylsp[(1) - (3)])); ;} break; - case 1079: -#line 2944 "third_party/libpg_query/grammar/statements/select.y" + case 1050: +#line 2898 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall((yyvsp[(1) - (5)].list), NIL, (yylsp[(1) - (5)])); n->agg_order = (yyvsp[(3) - (5)].list); @@ -28488,8 +28073,8 @@ YYLTYPE yylloc; ;} break; - case 1080: -#line 2951 "third_party/libpg_query/grammar/statements/select.y" + case 1051: +#line 2905 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall((yyvsp[(1) - (6)].list), (yyvsp[(3) - (6)].list), (yylsp[(1) - (6)])); n->agg_order = (yyvsp[(4) - (6)].list); @@ -28498,8 +28083,8 @@ YYLTYPE yylloc; ;} break; - case 1081: -#line 2958 "third_party/libpg_query/grammar/statements/select.y" + case 1052: +#line 2912 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall((yyvsp[(1) - (7)].list), list_make1((yyvsp[(4) - (7)].node)), (yylsp[(1) - (7)])); n->func_variadic = true; @@ -28509,8 +28094,8 @@ YYLTYPE yylloc; ;} break; - case 1082: -#line 2966 "third_party/libpg_query/grammar/statements/select.y" + case 1053: +#line 2920 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall((yyvsp[(1) - (9)].list), lappend((yyvsp[(3) - (9)].list), (yyvsp[(6) - (9)].node)), (yylsp[(1) - (9)])); n->func_variadic = true; @@ -28520,8 +28105,8 @@ YYLTYPE yylloc; ;} break; - case 1083: -#line 2974 "third_party/libpg_query/grammar/statements/select.y" + case 1054: +#line 2928 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall((yyvsp[(1) - (7)].list), (yyvsp[(4) - (7)].list), (yylsp[(1) - (7)])); n->agg_order = (yyvsp[(5) - (7)].list); @@ -28534,8 +28119,8 @@ YYLTYPE yylloc; ;} break; - case 1084: -#line 2985 "third_party/libpg_query/grammar/statements/select.y" + case 1055: +#line 2939 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall((yyvsp[(1) - (7)].list), (yyvsp[(4) - (7)].list), (yylsp[(1) - (7)])); n->agg_order = (yyvsp[(5) - (7)].list); @@ -28545,8 +28130,8 @@ YYLTYPE yylloc; ;} break; - case 1085: -#line 3005 "third_party/libpg_query/grammar/statements/select.y" + case 1056: +#line 2959 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = (PGFuncCall *) (yyvsp[(1) - (5)].node); /* @@ -28584,23 +28169,23 @@ YYLTYPE yylloc; ;} break; - case 1086: -#line 3041 "third_party/libpg_query/grammar/statements/select.y" + case 1057: +#line 2995 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1087: -#line 3051 "third_party/libpg_query/grammar/statements/select.y" + case 1058: +#line 3005 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1088: -#line 3052 "third_party/libpg_query/grammar/statements/select.y" + case 1059: +#line 3006 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1089: -#line 3060 "third_party/libpg_query/grammar/statements/select.y" + case 1060: +#line 3014 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeFuncCall(SystemFuncName("pg_collation_for"), list_make1((yyvsp[(4) - (5)].node)), @@ -28608,25 +28193,25 @@ YYLTYPE yylloc; ;} break; - case 1090: -#line 3066 "third_party/libpg_query/grammar/statements/select.y" + case 1061: +#line 3020 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeTypeCast((yyvsp[(3) - (6)].node), (yyvsp[(5) - (6)].typnam), 0, (yylsp[(1) - (6)])); ;} break; - case 1091: -#line 3068 "third_party/libpg_query/grammar/statements/select.y" + case 1062: +#line 3022 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeTypeCast((yyvsp[(3) - (6)].node), (yyvsp[(5) - (6)].typnam), 1, (yylsp[(1) - (6)])); ;} break; - case 1092: -#line 3070 "third_party/libpg_query/grammar/statements/select.y" + case 1063: +#line 3024 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeFuncCall(SystemFuncName("date_part"), (yyvsp[(3) - (4)].list), (yylsp[(1) - (4)])); ;} break; - case 1093: -#line 3074 "third_party/libpg_query/grammar/statements/select.y" + case 1064: +#line 3028 "third_party/libpg_query/grammar/statements/select.y" { /* overlay(A PLACING B FROM C FOR D) is converted to * overlay(A, B, C, D) @@ -28637,16 +28222,16 @@ YYLTYPE yylloc; ;} break; - case 1094: -#line 3083 "third_party/libpg_query/grammar/statements/select.y" + case 1065: +#line 3037 "third_party/libpg_query/grammar/statements/select.y" { /* position(A in B) is converted to position_inverse(A, B) */ (yyval.node) = (PGNode *) makeFuncCall(SystemFuncName("__internal_position_operator"), (yyvsp[(3) - (4)].list), (yylsp[(1) - (4)])); ;} break; - case 1095: -#line 3088 "third_party/libpg_query/grammar/statements/select.y" + case 1066: +#line 3042 "third_party/libpg_query/grammar/statements/select.y" { /* substring(A from B for C) is converted to * substring(A, B, C) - thomas 2000-11-28 @@ -28655,8 +28240,8 @@ YYLTYPE yylloc; ;} break; - case 1096: -#line 3095 "third_party/libpg_query/grammar/statements/select.y" + case 1067: +#line 3049 "third_party/libpg_query/grammar/statements/select.y" { /* TREAT(expr AS target) converts expr of a particular type to target, * which is defined to be a subtype of the original expression. @@ -28673,8 +28258,8 @@ YYLTYPE yylloc; ;} break; - case 1097: -#line 3110 "third_party/libpg_query/grammar/statements/select.y" + case 1068: +#line 3064 "third_party/libpg_query/grammar/statements/select.y" { /* various trim expressions are defined in SQL * - thomas 1997-07-19 @@ -28683,36 +28268,36 @@ YYLTYPE yylloc; ;} break; - case 1098: -#line 3117 "third_party/libpg_query/grammar/statements/select.y" + case 1069: +#line 3071 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeFuncCall(SystemFuncName("ltrim"), (yyvsp[(4) - (5)].list), (yylsp[(1) - (5)])); ;} break; - case 1099: -#line 3121 "third_party/libpg_query/grammar/statements/select.y" + case 1070: +#line 3075 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeFuncCall(SystemFuncName("rtrim"), (yyvsp[(4) - (5)].list), (yylsp[(1) - (5)])); ;} break; - case 1100: -#line 3125 "third_party/libpg_query/grammar/statements/select.y" + case 1071: +#line 3079 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeFuncCall(SystemFuncName("trim"), (yyvsp[(3) - (4)].list), (yylsp[(1) - (4)])); ;} break; - case 1101: -#line 3129 "third_party/libpg_query/grammar/statements/select.y" + case 1072: +#line 3083 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *) makeSimpleAExpr(PG_AEXPR_NULLIF, "=", (yyvsp[(3) - (6)].node), (yyvsp[(5) - (6)].node), (yylsp[(1) - (6)])); ;} break; - case 1102: -#line 3133 "third_party/libpg_query/grammar/statements/select.y" + case 1073: +#line 3087 "third_party/libpg_query/grammar/statements/select.y" { PGCoalesceExpr *c = makeNode(PGCoalesceExpr); c->args = (yyvsp[(3) - (4)].list); @@ -28721,16 +28306,16 @@ YYLTYPE yylloc; ;} break; - case 1103: -#line 3143 "third_party/libpg_query/grammar/statements/select.y" + case 1074: +#line 3097 "third_party/libpg_query/grammar/statements/select.y" { PGFuncCall *n = makeFuncCall(SystemFuncName("row"), (yyvsp[(1) - (1)].list), (yylsp[(1) - (1)])); (yyval.node) = (PGNode *) n; ;} break; - case 1104: -#line 3151 "third_party/libpg_query/grammar/statements/select.y" + case 1075: +#line 3105 "third_party/libpg_query/grammar/statements/select.y" { PGLambdaFunction *lambda = makeNode(PGLambdaFunction); lambda->lhs = (yyvsp[(4) - (7)].node); @@ -28741,8 +28326,8 @@ YYLTYPE yylloc; ;} break; - case 1105: -#line 3160 "third_party/libpg_query/grammar/statements/select.y" + case 1076: +#line 3114 "third_party/libpg_query/grammar/statements/select.y" { PGLambdaFunction *lambda = makeNode(PGLambdaFunction); lambda->lhs = (yyvsp[(4) - (9)].node); @@ -28759,63 +28344,63 @@ YYLTYPE yylloc; ;} break; - case 1106: -#line 3181 "third_party/libpg_query/grammar/statements/select.y" + case 1077: +#line 3135 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(4) - (5)].list); ;} break; - case 1107: -#line 3182 "third_party/libpg_query/grammar/statements/select.y" + case 1078: +#line 3136 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1108: -#line 3186 "third_party/libpg_query/grammar/statements/select.y" + case 1079: +#line 3140 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(4) - (5)].node); ;} break; - case 1109: -#line 3187 "third_party/libpg_query/grammar/statements/select.y" + case 1080: +#line 3141 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(3) - (4)].node); ;} break; - case 1110: -#line 3188 "third_party/libpg_query/grammar/statements/select.y" + case 1081: +#line 3142 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 1111: -#line 3192 "third_party/libpg_query/grammar/statements/select.y" + case 1082: +#line 3146 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = true; ;} break; - case 1112: -#line 3193 "third_party/libpg_query/grammar/statements/select.y" + case 1083: +#line 3147 "third_party/libpg_query/grammar/statements/select.y" { (yyval.boolean) = false; ;} break; - case 1113: -#line 3200 "third_party/libpg_query/grammar/statements/select.y" + case 1084: +#line 3154 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 1114: -#line 3201 "third_party/libpg_query/grammar/statements/select.y" + case 1085: +#line 3155 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1115: -#line 3205 "third_party/libpg_query/grammar/statements/select.y" + case 1086: +#line 3159 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].windef)); ;} break; - case 1116: -#line 3207 "third_party/libpg_query/grammar/statements/select.y" + case 1087: +#line 3161 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].windef)); ;} break; - case 1117: -#line 3212 "third_party/libpg_query/grammar/statements/select.y" + case 1088: +#line 3166 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = (yyvsp[(3) - (3)].windef); n->name = (yyvsp[(1) - (3)].str); @@ -28823,13 +28408,13 @@ YYLTYPE yylloc; ;} break; - case 1118: -#line 3220 "third_party/libpg_query/grammar/statements/select.y" + case 1089: +#line 3174 "third_party/libpg_query/grammar/statements/select.y" { (yyval.windef) = (yyvsp[(2) - (2)].windef); ;} break; - case 1119: -#line 3222 "third_party/libpg_query/grammar/statements/select.y" + case 1090: +#line 3176 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); n->name = (yyvsp[(2) - (2)].str); @@ -28844,13 +28429,13 @@ YYLTYPE yylloc; ;} break; - case 1120: -#line 3235 "third_party/libpg_query/grammar/statements/select.y" + case 1091: +#line 3189 "third_party/libpg_query/grammar/statements/select.y" { (yyval.windef) = NULL; ;} break; - case 1121: -#line 3240 "third_party/libpg_query/grammar/statements/select.y" + case 1092: +#line 3194 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); n->name = NULL; @@ -28866,28 +28451,28 @@ YYLTYPE yylloc; ;} break; - case 1122: -#line 3265 "third_party/libpg_query/grammar/statements/select.y" + case 1093: +#line 3219 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1123: -#line 3266 "third_party/libpg_query/grammar/statements/select.y" + case 1094: +#line 3220 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = NULL; ;} break; - case 1124: -#line 3269 "third_party/libpg_query/grammar/statements/select.y" + case 1095: +#line 3223 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (3)].list); ;} break; - case 1125: -#line 3270 "third_party/libpg_query/grammar/statements/select.y" + case 1096: +#line 3224 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1126: -#line 3279 "third_party/libpg_query/grammar/statements/select.y" + case 1097: +#line 3233 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = (yyvsp[(2) - (3)].windef); @@ -28897,8 +28482,8 @@ YYLTYPE yylloc; ;} break; - case 1127: -#line 3287 "third_party/libpg_query/grammar/statements/select.y" + case 1098: +#line 3241 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = (yyvsp[(2) - (3)].windef); @@ -28908,8 +28493,8 @@ YYLTYPE yylloc; ;} break; - case 1128: -#line 3295 "third_party/libpg_query/grammar/statements/select.y" + case 1099: +#line 3249 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = (yyvsp[(2) - (3)].windef); @@ -28919,8 +28504,8 @@ YYLTYPE yylloc; ;} break; - case 1129: -#line 3303 "third_party/libpg_query/grammar/statements/select.y" + case 1100: +#line 3257 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); @@ -28931,8 +28516,8 @@ YYLTYPE yylloc; ;} break; - case 1130: -#line 3314 "third_party/libpg_query/grammar/statements/select.y" + case 1101: +#line 3268 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = (yyvsp[(1) - (1)].windef); @@ -28952,8 +28537,8 @@ YYLTYPE yylloc; ;} break; - case 1131: -#line 3332 "third_party/libpg_query/grammar/statements/select.y" + case 1102: +#line 3286 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n1 = (yyvsp[(2) - (4)].windef); PGWindowDef *n2 = (yyvsp[(4) - (4)].windef); @@ -28993,8 +28578,8 @@ YYLTYPE yylloc; ;} break; - case 1132: -#line 3378 "third_party/libpg_query/grammar/statements/select.y" + case 1103: +#line 3332 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); @@ -29005,8 +28590,8 @@ YYLTYPE yylloc; ;} break; - case 1133: -#line 3387 "third_party/libpg_query/grammar/statements/select.y" + case 1104: +#line 3341 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); @@ -29017,8 +28602,8 @@ YYLTYPE yylloc; ;} break; - case 1134: -#line 3396 "third_party/libpg_query/grammar/statements/select.y" + case 1105: +#line 3350 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); @@ -29029,8 +28614,8 @@ YYLTYPE yylloc; ;} break; - case 1135: -#line 3405 "third_party/libpg_query/grammar/statements/select.y" + case 1106: +#line 3359 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); @@ -29041,8 +28626,8 @@ YYLTYPE yylloc; ;} break; - case 1136: -#line 3414 "third_party/libpg_query/grammar/statements/select.y" + case 1107: +#line 3368 "third_party/libpg_query/grammar/statements/select.y" { PGWindowDef *n = makeNode(PGWindowDef); @@ -29053,53 +28638,53 @@ YYLTYPE yylloc; ;} break; - case 1137: -#line 3425 "third_party/libpg_query/grammar/statements/select.y" + case 1108: +#line 3379 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = FRAMEOPTION_EXCLUDE_CURRENT_ROW; ;} break; - case 1138: -#line 3426 "third_party/libpg_query/grammar/statements/select.y" + case 1109: +#line 3380 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = FRAMEOPTION_EXCLUDE_GROUP; ;} break; - case 1139: -#line 3427 "third_party/libpg_query/grammar/statements/select.y" + case 1110: +#line 3381 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = FRAMEOPTION_EXCLUDE_TIES; ;} break; - case 1140: -#line 3428 "third_party/libpg_query/grammar/statements/select.y" + case 1111: +#line 3382 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = 0; ;} break; - case 1141: -#line 3429 "third_party/libpg_query/grammar/statements/select.y" + case 1112: +#line 3383 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = 0; ;} break; - case 1142: -#line 3443 "third_party/libpg_query/grammar/statements/select.y" + case 1113: +#line 3397 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 1143: -#line 3444 "third_party/libpg_query/grammar/statements/select.y" + case 1114: +#line 3398 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1144: -#line 3447 "third_party/libpg_query/grammar/statements/select.y" + case 1115: +#line 3401 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list);;} break; - case 1145: -#line 3448 "third_party/libpg_query/grammar/statements/select.y" + case 1116: +#line 3402 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(2) - (5)].list), (yyvsp[(4) - (5)].node)); ;} break; - case 1146: -#line 3452 "third_party/libpg_query/grammar/statements/select.y" + case 1117: +#line 3406 "third_party/libpg_query/grammar/statements/select.y" { PGNamedArgExpr *na = makeNode(PGNamedArgExpr); na->name = (yyvsp[(1) - (3)].str); @@ -29110,321 +28695,321 @@ YYLTYPE yylloc; ;} break; - case 1147: -#line 3462 "third_party/libpg_query/grammar/statements/select.y" + case 1118: +#line 3416 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 1148: -#line 3463 "third_party/libpg_query/grammar/statements/select.y" + case 1119: +#line 3417 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 1149: -#line 3467 "third_party/libpg_query/grammar/statements/select.y" + case 1120: +#line 3421 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1150: -#line 3468 "third_party/libpg_query/grammar/statements/select.y" + case 1121: +#line 3422 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1151: -#line 3473 "third_party/libpg_query/grammar/statements/select.y" + case 1122: +#line 3427 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); ;} break; - case 1152: -#line 3479 "third_party/libpg_query/grammar/statements/select.y" + case 1123: +#line 3433 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].list)); ;} break; - case 1153: -#line 3480 "third_party/libpg_query/grammar/statements/select.y" + case 1124: +#line 3434 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].list)); ;} break; - case 1154: -#line 3485 "third_party/libpg_query/grammar/statements/select.y" + case 1125: +#line 3439 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1155: -#line 3486 "third_party/libpg_query/grammar/statements/select.y" + case 1126: +#line 3440 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1156: -#line 3491 "third_party/libpg_query/grammar/statements/select.y" + case 1127: +#line 3445 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1157: -#line 3492 "third_party/libpg_query/grammar/statements/select.y" + case 1128: +#line 3446 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NULL; ;} break; - case 1158: -#line 3495 "third_party/libpg_query/grammar/statements/select.y" + case 1129: +#line 3449 "third_party/libpg_query/grammar/statements/select.y" { (yyval.subquerytype) = PG_ANY_SUBLINK; ;} break; - case 1159: -#line 3496 "third_party/libpg_query/grammar/statements/select.y" + case 1130: +#line 3450 "third_party/libpg_query/grammar/statements/select.y" { (yyval.subquerytype) = PG_ANY_SUBLINK; ;} break; - case 1160: -#line 3497 "third_party/libpg_query/grammar/statements/select.y" + case 1131: +#line 3451 "third_party/libpg_query/grammar/statements/select.y" { (yyval.subquerytype) = PG_ALL_SUBLINK; ;} break; - case 1161: -#line 3500 "third_party/libpg_query/grammar/statements/select.y" + case 1132: +#line 3454 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1162: -#line 3501 "third_party/libpg_query/grammar/statements/select.y" + case 1133: +#line 3455 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) (yyvsp[(1) - (1)].conststr); ;} break; - case 1163: -#line 3504 "third_party/libpg_query/grammar/statements/select.y" + case 1134: +#line 3458 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "+"; ;} break; - case 1164: -#line 3505 "third_party/libpg_query/grammar/statements/select.y" + case 1135: +#line 3459 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "-"; ;} break; - case 1165: -#line 3506 "third_party/libpg_query/grammar/statements/select.y" + case 1136: +#line 3460 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "*"; ;} break; - case 1166: -#line 3507 "third_party/libpg_query/grammar/statements/select.y" + case 1137: +#line 3461 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "/"; ;} break; - case 1167: -#line 3508 "third_party/libpg_query/grammar/statements/select.y" + case 1138: +#line 3462 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "//"; ;} break; - case 1168: -#line 3509 "third_party/libpg_query/grammar/statements/select.y" + case 1139: +#line 3463 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "%"; ;} break; - case 1169: -#line 3510 "third_party/libpg_query/grammar/statements/select.y" + case 1140: +#line 3464 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "^"; ;} break; - case 1170: -#line 3511 "third_party/libpg_query/grammar/statements/select.y" + case 1141: +#line 3465 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "**"; ;} break; - case 1171: -#line 3512 "third_party/libpg_query/grammar/statements/select.y" + case 1142: +#line 3466 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "<"; ;} break; - case 1172: -#line 3513 "third_party/libpg_query/grammar/statements/select.y" + case 1143: +#line 3467 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = ">"; ;} break; - case 1173: -#line 3514 "third_party/libpg_query/grammar/statements/select.y" + case 1144: +#line 3468 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "="; ;} break; - case 1174: -#line 3515 "third_party/libpg_query/grammar/statements/select.y" + case 1145: +#line 3469 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "<="; ;} break; - case 1175: -#line 3516 "third_party/libpg_query/grammar/statements/select.y" + case 1146: +#line 3470 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = ">="; ;} break; - case 1176: -#line 3517 "third_party/libpg_query/grammar/statements/select.y" + case 1147: +#line 3471 "third_party/libpg_query/grammar/statements/select.y" { (yyval.conststr) = "<>"; ;} break; - case 1177: -#line 3521 "third_party/libpg_query/grammar/statements/select.y" + case 1148: +#line 3475 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 1178: -#line 3523 "third_party/libpg_query/grammar/statements/select.y" + case 1149: +#line 3477 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 1179: -#line 3528 "third_party/libpg_query/grammar/statements/select.y" + case 1150: +#line 3482 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 1180: -#line 3530 "third_party/libpg_query/grammar/statements/select.y" + case 1151: +#line 3484 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 1181: -#line 3535 "third_party/libpg_query/grammar/statements/select.y" + case 1152: +#line 3489 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 1182: -#line 3537 "third_party/libpg_query/grammar/statements/select.y" + case 1153: +#line 3491 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 1183: -#line 3539 "third_party/libpg_query/grammar/statements/select.y" + case 1154: +#line 3493 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString("~~")); ;} break; - case 1184: -#line 3541 "third_party/libpg_query/grammar/statements/select.y" + case 1155: +#line 3495 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString("!~~")); ;} break; - case 1185: -#line 3543 "third_party/libpg_query/grammar/statements/select.y" + case 1156: +#line 3497 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString("~~~")); ;} break; - case 1186: -#line 3545 "third_party/libpg_query/grammar/statements/select.y" + case 1157: +#line 3499 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString("!~~~")); ;} break; - case 1187: -#line 3547 "third_party/libpg_query/grammar/statements/select.y" + case 1158: +#line 3501 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString("~~*")); ;} break; - case 1188: -#line 3549 "third_party/libpg_query/grammar/statements/select.y" + case 1159: +#line 3503 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString("!~~*")); ;} break; - case 1189: -#line 3563 "third_party/libpg_query/grammar/statements/select.y" + case 1160: +#line 3517 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 1190: -#line 3565 "third_party/libpg_query/grammar/statements/select.y" + case 1161: +#line 3519 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lcons(makeString((yyvsp[(1) - (3)].str)), (yyvsp[(3) - (3)].list)); ;} break; - case 1191: -#line 3570 "third_party/libpg_query/grammar/statements/select.y" + case 1162: +#line 3524 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 1192: -#line 3574 "third_party/libpg_query/grammar/statements/select.y" + case 1163: +#line 3528 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 1193: -#line 3581 "third_party/libpg_query/grammar/statements/select.y" + case 1164: +#line 3535 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1194: -#line 3586 "third_party/libpg_query/grammar/statements/select.y" + case 1165: +#line 3540 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1195: -#line 3592 "third_party/libpg_query/grammar/statements/select.y" + case 1166: +#line 3546 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 1196: -#line 3596 "third_party/libpg_query/grammar/statements/select.y" + case 1167: +#line 3550 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 1197: -#line 3603 "third_party/libpg_query/grammar/statements/select.y" + case 1168: +#line 3557 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1198: -#line 3608 "third_party/libpg_query/grammar/statements/select.y" + case 1169: +#line 3562 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1199: -#line 3615 "third_party/libpg_query/grammar/statements/select.y" + case 1170: +#line 3569 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1200: -#line 3619 "third_party/libpg_query/grammar/statements/select.y" + case 1171: +#line 3573 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NULL; ;} break; - case 1201: -#line 3628 "third_party/libpg_query/grammar/statements/select.y" + case 1172: +#line 3582 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 1202: -#line 3632 "third_party/libpg_query/grammar/statements/select.y" + case 1173: +#line 3586 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 1203: -#line 3638 "third_party/libpg_query/grammar/statements/select.y" + case 1174: +#line 3592 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1204: -#line 3642 "third_party/libpg_query/grammar/statements/select.y" + case 1175: +#line 3596 "third_party/libpg_query/grammar/statements/select.y" { PGNamedArgExpr *na = makeNode(PGNamedArgExpr); na->name = (yyvsp[(1) - (3)].str); @@ -29435,8 +29020,8 @@ YYLTYPE yylloc; ;} break; - case 1205: -#line 3651 "third_party/libpg_query/grammar/statements/select.y" + case 1176: +#line 3605 "third_party/libpg_query/grammar/statements/select.y" { PGNamedArgExpr *na = makeNode(PGNamedArgExpr); na->name = (yyvsp[(1) - (3)].str); @@ -29447,156 +29032,156 @@ YYLTYPE yylloc; ;} break; - case 1206: -#line 3661 "third_party/libpg_query/grammar/statements/select.y" + case 1177: +#line 3615 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].typnam)); ;} break; - case 1207: -#line 3662 "third_party/libpg_query/grammar/statements/select.y" + case 1178: +#line 3616 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].typnam)); ;} break; - case 1208: -#line 3667 "third_party/libpg_query/grammar/statements/select.y" + case 1179: +#line 3621 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2(makeStringConst((yyvsp[(1) - (3)].str), (yylsp[(1) - (3)])), (yyvsp[(3) - (3)].node)); ;} break; - case 1209: -#line 3670 "third_party/libpg_query/grammar/statements/select.y" + case 1180: +#line 3624 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1210: -#line 3677 "third_party/libpg_query/grammar/statements/select.y" + case 1181: +#line 3631 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1211: -#line 3678 "third_party/libpg_query/grammar/statements/select.y" + case 1182: +#line 3632 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "year"; ;} break; - case 1212: -#line 3679 "third_party/libpg_query/grammar/statements/select.y" + case 1183: +#line 3633 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "month"; ;} break; - case 1213: -#line 3680 "third_party/libpg_query/grammar/statements/select.y" + case 1184: +#line 3634 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "day"; ;} break; - case 1214: -#line 3681 "third_party/libpg_query/grammar/statements/select.y" + case 1185: +#line 3635 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "hour"; ;} break; - case 1215: -#line 3682 "third_party/libpg_query/grammar/statements/select.y" + case 1186: +#line 3636 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "minute"; ;} break; - case 1216: -#line 3683 "third_party/libpg_query/grammar/statements/select.y" + case 1187: +#line 3637 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "second"; ;} break; - case 1217: -#line 3684 "third_party/libpg_query/grammar/statements/select.y" + case 1188: +#line 3638 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "millisecond"; ;} break; - case 1218: -#line 3685 "third_party/libpg_query/grammar/statements/select.y" + case 1189: +#line 3639 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "microsecond"; ;} break; - case 1219: -#line 3686 "third_party/libpg_query/grammar/statements/select.y" + case 1190: +#line 3640 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "week"; ;} break; - case 1220: -#line 3687 "third_party/libpg_query/grammar/statements/select.y" + case 1191: +#line 3641 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "quarter"; ;} break; - case 1221: -#line 3688 "third_party/libpg_query/grammar/statements/select.y" + case 1192: +#line 3642 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "decade"; ;} break; - case 1222: -#line 3689 "third_party/libpg_query/grammar/statements/select.y" + case 1193: +#line 3643 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "century"; ;} break; - case 1223: -#line 3690 "third_party/libpg_query/grammar/statements/select.y" + case 1194: +#line 3644 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (char*) "millennium"; ;} break; - case 1224: -#line 3691 "third_party/libpg_query/grammar/statements/select.y" + case 1195: +#line 3645 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1225: -#line 3702 "third_party/libpg_query/grammar/statements/select.y" + case 1196: +#line 3656 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make4((yyvsp[(1) - (4)].node), (yyvsp[(2) - (4)].node), (yyvsp[(3) - (4)].node), (yyvsp[(4) - (4)].node)); ;} break; - case 1226: -#line 3706 "third_party/libpg_query/grammar/statements/select.y" + case 1197: +#line 3660 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make3((yyvsp[(1) - (3)].node), (yyvsp[(2) - (3)].node), (yyvsp[(3) - (3)].node)); ;} break; - case 1227: -#line 3713 "third_party/libpg_query/grammar/statements/select.y" + case 1198: +#line 3667 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 1228: -#line 3719 "third_party/libpg_query/grammar/statements/select.y" + case 1199: +#line 3673 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); ;} break; - case 1229: -#line 3720 "third_party/libpg_query/grammar/statements/select.y" + case 1200: +#line 3674 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1230: -#line 3737 "third_party/libpg_query/grammar/statements/select.y" + case 1201: +#line 3691 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make3((yyvsp[(1) - (3)].node), (yyvsp[(2) - (3)].node), (yyvsp[(3) - (3)].node)); ;} break; - case 1231: -#line 3741 "third_party/libpg_query/grammar/statements/select.y" + case 1202: +#line 3695 "third_party/libpg_query/grammar/statements/select.y" { /* not legal per SQL99, but might as well allow it */ (yyval.list) = list_make3((yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node), (yyvsp[(2) - (3)].node)); ;} break; - case 1232: -#line 3746 "third_party/libpg_query/grammar/statements/select.y" + case 1203: +#line 3700 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2((yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].node)); ;} break; - case 1233: -#line 3750 "third_party/libpg_query/grammar/statements/select.y" + case 1204: +#line 3704 "third_party/libpg_query/grammar/statements/select.y" { /* * Since there are no cases where this syntax allows @@ -29613,45 +29198,45 @@ YYLTYPE yylloc; ;} break; - case 1234: -#line 3765 "third_party/libpg_query/grammar/statements/select.y" + case 1205: +#line 3719 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1235: -#line 3769 "third_party/libpg_query/grammar/statements/select.y" + case 1206: +#line 3723 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1236: -#line 3773 "third_party/libpg_query/grammar/statements/select.y" + case 1207: +#line 3727 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 1237: -#line 3776 "third_party/libpg_query/grammar/statements/select.y" + case 1208: +#line 3730 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 1238: -#line 3779 "third_party/libpg_query/grammar/statements/select.y" + case 1209: +#line 3733 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(3) - (3)].list), (yyvsp[(1) - (3)].node)); ;} break; - case 1239: -#line 3780 "third_party/libpg_query/grammar/statements/select.y" + case 1210: +#line 3734 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 1240: -#line 3781 "third_party/libpg_query/grammar/statements/select.y" + case 1211: +#line 3735 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1241: -#line 3785 "third_party/libpg_query/grammar/statements/select.y" + case 1212: +#line 3739 "third_party/libpg_query/grammar/statements/select.y" { PGSubLink *n = makeNode(PGSubLink); n->subselect = (yyvsp[(1) - (1)].node); @@ -29660,18 +29245,18 @@ YYLTYPE yylloc; ;} break; - case 1242: -#line 3791 "third_party/libpg_query/grammar/statements/select.y" + case 1213: +#line 3745 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *)(yyvsp[(2) - (3)].list); ;} break; - case 1244: -#line 3793 "third_party/libpg_query/grammar/statements/select.y" + case 1215: +#line 3747 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (PGNode *)(yyvsp[(1) - (1)].node); ;} break; - case 1245: -#line 3804 "third_party/libpg_query/grammar/statements/select.y" + case 1216: +#line 3758 "third_party/libpg_query/grammar/statements/select.y" { PGCaseExpr *c = makeNode(PGCaseExpr); c->casetype = InvalidOid; /* not analyzed yet */ @@ -29683,18 +29268,18 @@ YYLTYPE yylloc; ;} break; - case 1246: -#line 3817 "third_party/libpg_query/grammar/statements/select.y" + case 1217: +#line 3771 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 1247: -#line 3818 "third_party/libpg_query/grammar/statements/select.y" + case 1218: +#line 3772 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 1248: -#line 3823 "third_party/libpg_query/grammar/statements/select.y" + case 1219: +#line 3777 "third_party/libpg_query/grammar/statements/select.y" { PGCaseWhen *w = makeNode(PGCaseWhen); w->expr = (PGExpr *) (yyvsp[(2) - (4)].node); @@ -29704,59 +29289,59 @@ YYLTYPE yylloc; ;} break; - case 1249: -#line 3833 "third_party/libpg_query/grammar/statements/select.y" + case 1220: +#line 3787 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 1250: -#line 3834 "third_party/libpg_query/grammar/statements/select.y" + case 1221: +#line 3788 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 1251: -#line 3837 "third_party/libpg_query/grammar/statements/select.y" + case 1222: +#line 3791 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1252: -#line 3838 "third_party/libpg_query/grammar/statements/select.y" + case 1223: +#line 3792 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 1253: -#line 3842 "third_party/libpg_query/grammar/statements/select.y" + case 1224: +#line 3796 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 1254: -#line 3843 "third_party/libpg_query/grammar/statements/select.y" + case 1225: +#line 3797 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 1255: -#line 3847 "third_party/libpg_query/grammar/statements/select.y" + case 1226: +#line 3801 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeColumnRef((yyvsp[(1) - (1)].str), NIL, (yylsp[(1) - (1)]), yyscanner); ;} break; - case 1256: -#line 3853 "third_party/libpg_query/grammar/statements/select.y" + case 1227: +#line 3807 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeColumnRef((yyvsp[(1) - (1)].str), NIL, (yylsp[(1) - (1)]), yyscanner); ;} break; - case 1257: -#line 3857 "third_party/libpg_query/grammar/statements/select.y" + case 1228: +#line 3811 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeColumnRef((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].list), (yylsp[(1) - (2)]), yyscanner); ;} break; - case 1258: -#line 3864 "third_party/libpg_query/grammar/statements/select.y" + case 1229: +#line 3818 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = false; @@ -29766,8 +29351,8 @@ YYLTYPE yylloc; ;} break; - case 1259: -#line 3872 "third_party/libpg_query/grammar/statements/select.y" + case 1230: +#line 3826 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = true; @@ -29777,8 +29362,8 @@ YYLTYPE yylloc; ;} break; - case 1260: -#line 3879 "third_party/libpg_query/grammar/statements/select.y" + case 1231: +#line 3833 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = true; @@ -29789,8 +29374,8 @@ YYLTYPE yylloc; ;} break; - case 1261: -#line 3887 "third_party/libpg_query/grammar/statements/select.y" + case 1232: +#line 3841 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = true; @@ -29800,43 +29385,43 @@ YYLTYPE yylloc; ;} break; - case 1262: -#line 3897 "third_party/libpg_query/grammar/statements/select.y" + case 1233: +#line 3851 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1263: -#line 3898 "third_party/libpg_query/grammar/statements/select.y" + case 1234: +#line 3852 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = NULL; ;} break; - case 1264: -#line 3903 "third_party/libpg_query/grammar/statements/select.y" + case 1235: +#line 3857 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1265: -#line 3904 "third_party/libpg_query/grammar/statements/select.y" + case 1236: +#line 3858 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 1266: -#line 3908 "third_party/libpg_query/grammar/statements/select.y" + case 1237: +#line 3862 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NULL; ;} break; - case 1267: -#line 3909 "third_party/libpg_query/grammar/statements/select.y" + case 1238: +#line 3863 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(NULL); ;} break; - case 1268: -#line 3910 "third_party/libpg_query/grammar/statements/select.y" + case 1239: +#line 3864 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 1269: -#line 3915 "third_party/libpg_query/grammar/statements/select.y" + case 1240: +#line 3869 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(3) - (3)].list)) { PGFuncCall *n = makeFuncCall(list_make1(makeString((yyvsp[(2) - (3)].str))), (yyvsp[(3) - (3)].list)->head->data.ptr_value ? (yyvsp[(3) - (3)].list) : NULL, (yylsp[(2) - (3)])); @@ -29847,8 +29432,8 @@ YYLTYPE yylloc; ;} break; - case 1270: -#line 3924 "third_party/libpg_query/grammar/statements/select.y" + case 1241: +#line 3878 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = false; @@ -29858,8 +29443,8 @@ YYLTYPE yylloc; ;} break; - case 1271: -#line 3932 "third_party/libpg_query/grammar/statements/select.y" + case 1242: +#line 3886 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = true; @@ -29869,8 +29454,8 @@ YYLTYPE yylloc; ;} break; - case 1272: -#line 3939 "third_party/libpg_query/grammar/statements/select.y" + case 1243: +#line 3893 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = true; @@ -29881,8 +29466,8 @@ YYLTYPE yylloc; ;} break; - case 1273: -#line 3948 "third_party/libpg_query/grammar/statements/select.y" + case 1244: +#line 3902 "third_party/libpg_query/grammar/statements/select.y" { PGAIndices *ai = makeNode(PGAIndices); ai->is_slice = true; @@ -29892,48 +29477,48 @@ YYLTYPE yylloc; ;} break; - case 1274: -#line 3963 "third_party/libpg_query/grammar/statements/select.y" + case 1245: +#line 3917 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1275: -#line 3964 "third_party/libpg_query/grammar/statements/select.y" + case 1246: +#line 3918 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (2)].list), (yyvsp[(2) - (2)].node)); ;} break; - case 1278: -#line 3980 "third_party/libpg_query/grammar/statements/select.y" + case 1249: +#line 3934 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1279: -#line 3981 "third_party/libpg_query/grammar/statements/select.y" + case 1250: +#line 3935 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1280: -#line 3985 "third_party/libpg_query/grammar/statements/select.y" + case 1251: +#line 3939 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].target)); ;} break; - case 1281: -#line 3986 "third_party/libpg_query/grammar/statements/select.y" + case 1252: +#line 3940 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].target)); ;} break; - case 1282: -#line 3990 "third_party/libpg_query/grammar/statements/select.y" + case 1253: +#line 3944 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1283: -#line 3991 "third_party/libpg_query/grammar/statements/select.y" + case 1254: +#line 3945 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1284: -#line 3995 "third_party/libpg_query/grammar/statements/select.y" + case 1255: +#line 3949 "third_party/libpg_query/grammar/statements/select.y" { (yyval.target) = makeNode(PGResTarget); (yyval.target)->name = (yyvsp[(3) - (3)].str); @@ -29943,8 +29528,8 @@ YYLTYPE yylloc; ;} break; - case 1285: -#line 4011 "third_party/libpg_query/grammar/statements/select.y" + case 1256: +#line 3965 "third_party/libpg_query/grammar/statements/select.y" { (yyval.target) = makeNode(PGResTarget); (yyval.target)->name = (yyvsp[(2) - (2)].str); @@ -29954,8 +29539,8 @@ YYLTYPE yylloc; ;} break; - case 1286: -#line 4019 "third_party/libpg_query/grammar/statements/select.y" + case 1257: +#line 3973 "third_party/libpg_query/grammar/statements/select.y" { (yyval.target) = makeNode(PGResTarget); (yyval.target)->name = NULL; @@ -29965,8 +29550,8 @@ YYLTYPE yylloc; ;} break; - case 1287: -#line 4027 "third_party/libpg_query/grammar/statements/select.y" + case 1258: +#line 3981 "third_party/libpg_query/grammar/statements/select.y" { (yyval.target) = makeNode(PGResTarget); (yyval.target)->name = (yyvsp[(1) - (3)].str); @@ -29976,214 +29561,214 @@ YYLTYPE yylloc; ;} break; - case 1288: -#line 4036 "third_party/libpg_query/grammar/statements/select.y" + case 1259: +#line 3990 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 1289: -#line 4037 "third_party/libpg_query/grammar/statements/select.y" + case 1260: +#line 3991 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(2) - (2)].list)); ;} break; - case 1290: -#line 4042 "third_party/libpg_query/grammar/statements/select.y" + case 1261: +#line 3996 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].str)); ;} break; - case 1291: -#line 4046 "third_party/libpg_query/grammar/statements/select.y" + case 1262: +#line 4000 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].str)); ;} break; - case 1292: -#line 4052 "third_party/libpg_query/grammar/statements/select.y" + case 1263: +#line 4006 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].list)); ;} break; - case 1293: -#line 4054 "third_party/libpg_query/grammar/statements/select.y" + case 1264: +#line 4008 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].list)); ;} break; - case 1294: -#line 4058 "third_party/libpg_query/grammar/statements/select.y" + case 1265: +#line 4012 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1295: -#line 4059 "third_party/libpg_query/grammar/statements/select.y" + case 1266: +#line 4013 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1296: -#line 4063 "third_party/libpg_query/grammar/statements/select.y" + case 1267: +#line 4017 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1297: -#line 4064 "third_party/libpg_query/grammar/statements/select.y" + case 1268: +#line 4018 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NULL; ;} break; - case 1298: -#line 4067 "third_party/libpg_query/grammar/statements/select.y" + case 1269: +#line 4021 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2((yyvsp[(1) - (3)].node), makeString((yyvsp[(3) - (3)].str))); ;} break; - case 1299: -#line 4071 "third_party/libpg_query/grammar/statements/select.y" + case 1270: +#line 4025 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].list)); ;} break; - case 1300: -#line 4072 "third_party/libpg_query/grammar/statements/select.y" + case 1271: +#line 4026 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].list)); ;} break; - case 1301: -#line 4076 "third_party/libpg_query/grammar/statements/select.y" + case 1272: +#line 4030 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1302: -#line 4077 "third_party/libpg_query/grammar/statements/select.y" + case 1273: +#line 4031 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1303: -#line 4080 "third_party/libpg_query/grammar/statements/select.y" + case 1274: +#line 4034 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 1304: -#line 4081 "third_party/libpg_query/grammar/statements/select.y" + case 1275: +#line 4035 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(2) - (2)].list)); ;} break; - case 1305: -#line 4082 "third_party/libpg_query/grammar/statements/select.y" + case 1276: +#line 4036 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NULL; ;} break; - case 1306: -#line 4085 "third_party/libpg_query/grammar/statements/select.y" + case 1277: +#line 4039 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make2((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].str)); ;} break; - case 1307: -#line 4089 "third_party/libpg_query/grammar/statements/select.y" + case 1278: +#line 4043 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].list)); ;} break; - case 1308: -#line 4090 "third_party/libpg_query/grammar/statements/select.y" + case 1279: +#line 4044 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].list)); ;} break; - case 1309: -#line 4094 "third_party/libpg_query/grammar/statements/select.y" + case 1280: +#line 4048 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1310: -#line 4095 "third_party/libpg_query/grammar/statements/select.y" + case 1281: +#line 4049 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1311: -#line 4097 "third_party/libpg_query/grammar/statements/select.y" + case 1282: +#line 4051 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(3) - (4)].list); ;} break; - case 1312: -#line 4098 "third_party/libpg_query/grammar/statements/select.y" + case 1283: +#line 4052 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(2) - (2)].list)); ;} break; - case 1313: -#line 4099 "third_party/libpg_query/grammar/statements/select.y" + case 1284: +#line 4053 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NULL; ;} break; - case 1314: -#line 4109 "third_party/libpg_query/grammar/statements/select.y" + case 1285: +#line 4063 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].range)); ;} break; - case 1315: -#line 4110 "third_party/libpg_query/grammar/statements/select.y" + case 1286: +#line 4064 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].range)); ;} break; - case 1316: -#line 4115 "third_party/libpg_query/grammar/statements/select.y" + case 1287: +#line 4069 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 1317: -#line 4117 "third_party/libpg_query/grammar/statements/select.y" + case 1288: +#line 4071 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), makeString((yyvsp[(3) - (3)].str))); ;} break; - case 1318: -#line 4122 "third_party/libpg_query/grammar/statements/select.y" + case 1289: +#line 4076 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1319: -#line 4123 "third_party/libpg_query/grammar/statements/select.y" + case 1290: +#line 4077 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (2)].list); ;} break; - case 1320: -#line 4127 "third_party/libpg_query/grammar/statements/select.y" + case 1291: +#line 4081 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(1) - (1)].list); ;} break; - case 1321: -#line 4128 "third_party/libpg_query/grammar/statements/select.y" + case 1292: +#line 4082 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 1322: -#line 4131 "third_party/libpg_query/grammar/statements/select.y" + case 1293: +#line 4085 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1323: -#line 4143 "third_party/libpg_query/grammar/statements/select.y" + case 1294: +#line 4097 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 1324: -#line 4146 "third_party/libpg_query/grammar/statements/select.y" + case 1295: +#line 4100 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = check_func_name(lcons(makeString((yyvsp[(1) - (2)].str)), (yyvsp[(2) - (2)].list)), yyscanner); ;} break; - case 1325: -#line 4157 "third_party/libpg_query/grammar/statements/select.y" + case 1296: +#line 4111 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeIntConst((yyvsp[(1) - (1)].ival), (yylsp[(1) - (1)])); ;} break; - case 1326: -#line 4161 "third_party/libpg_query/grammar/statements/select.y" + case 1297: +#line 4115 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeFloatConst((yyvsp[(1) - (1)].str), (yylsp[(1) - (1)])); ;} break; - case 1327: -#line 4165 "third_party/libpg_query/grammar/statements/select.y" + case 1298: +#line 4119 "third_party/libpg_query/grammar/statements/select.y" { if ((yyvsp[(2) - (2)].list)) { @@ -30197,15 +29782,15 @@ YYLTYPE yylloc; ;} break; - case 1328: -#line 4177 "third_party/libpg_query/grammar/statements/select.y" + case 1299: +#line 4131 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeBitStringConst((yyvsp[(1) - (1)].str), (yylsp[(1) - (1)])); ;} break; - case 1329: -#line 4181 "third_party/libpg_query/grammar/statements/select.y" + case 1300: +#line 4135 "third_party/libpg_query/grammar/statements/select.y" { /* This is a bit constant per SQL99: * Without Feature F511, "BIT data type", @@ -30216,8 +29801,8 @@ YYLTYPE yylloc; ;} break; - case 1330: -#line 4190 "third_party/libpg_query/grammar/statements/select.y" + case 1301: +#line 4144 "third_party/libpg_query/grammar/statements/select.y" { /* generic type 'literal' syntax */ PGTypeName *t = makeTypeNameFromNameList((yyvsp[(1) - (2)].list)); @@ -30226,8 +29811,8 @@ YYLTYPE yylloc; ;} break; - case 1331: -#line 4197 "third_party/libpg_query/grammar/statements/select.y" + case 1302: +#line 4151 "third_party/libpg_query/grammar/statements/select.y" { /* generic syntax with a type modifier */ PGTypeName *t = makeTypeNameFromNameList((yyvsp[(1) - (7)].list)); @@ -30267,146 +29852,146 @@ YYLTYPE yylloc; ;} break; - case 1332: -#line 4235 "third_party/libpg_query/grammar/statements/select.y" + case 1303: +#line 4189 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeStringConstCast((yyvsp[(2) - (2)].str), (yylsp[(2) - (2)]), (yyvsp[(1) - (2)].typnam)); ;} break; - case 1333: -#line 4239 "third_party/libpg_query/grammar/statements/select.y" + case 1304: +#line 4193 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeIntervalNode((yyvsp[(3) - (5)].node), (yylsp[(3) - (5)]), (yyvsp[(5) - (5)].list)); ;} break; - case 1334: -#line 4243 "third_party/libpg_query/grammar/statements/select.y" + case 1305: +#line 4197 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeIntervalNode((yyvsp[(2) - (3)].ival), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].list)); ;} break; - case 1335: -#line 4247 "third_party/libpg_query/grammar/statements/select.y" + case 1306: +#line 4201 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeIntervalNode((yyvsp[(2) - (3)].str), (yylsp[(2) - (3)]), (yyvsp[(3) - (3)].list)); ;} break; - case 1336: -#line 4251 "third_party/libpg_query/grammar/statements/select.y" + case 1307: +#line 4205 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeBoolAConst(true, (yylsp[(1) - (1)])); ;} break; - case 1337: -#line 4255 "third_party/libpg_query/grammar/statements/select.y" + case 1308: +#line 4209 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeBoolAConst(false, (yylsp[(1) - (1)])); ;} break; - case 1338: -#line 4259 "third_party/libpg_query/grammar/statements/select.y" + case 1309: +#line 4213 "third_party/libpg_query/grammar/statements/select.y" { (yyval.node) = makeNullAConst((yylsp[(1) - (1)])); ;} break; - case 1339: -#line 4264 "third_party/libpg_query/grammar/statements/select.y" + case 1310: +#line 4218 "third_party/libpg_query/grammar/statements/select.y" { (yyval.ival) = (yyvsp[(1) - (1)].ival); ;} break; - case 1340: -#line 4281 "third_party/libpg_query/grammar/statements/select.y" + case 1311: +#line 4235 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1341: -#line 4282 "third_party/libpg_query/grammar/statements/select.y" + case 1312: +#line 4236 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1342: -#line 4283 "third_party/libpg_query/grammar/statements/select.y" + case 1313: +#line 4237 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1343: -#line 4286 "third_party/libpg_query/grammar/statements/select.y" + case 1314: +#line 4240 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1344: -#line 4287 "third_party/libpg_query/grammar/statements/select.y" + case 1315: +#line 4241 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1345: -#line 4288 "third_party/libpg_query/grammar/statements/select.y" + case 1316: +#line 4242 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1346: -#line 4291 "third_party/libpg_query/grammar/statements/select.y" + case 1317: +#line 4245 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1347: -#line 4292 "third_party/libpg_query/grammar/statements/select.y" + case 1318: +#line 4246 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1348: -#line 4293 "third_party/libpg_query/grammar/statements/select.y" + case 1319: +#line 4247 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1349: -#line 4296 "third_party/libpg_query/grammar/statements/select.y" + case 1320: +#line 4250 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(1) - (1)].str))); ;} break; - case 1350: -#line 4297 "third_party/libpg_query/grammar/statements/select.y" + case 1321: +#line 4251 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lcons(makeString((yyvsp[(1) - (2)].str)), (yyvsp[(2) - (2)].list)); ;} break; - case 1351: -#line 4301 "third_party/libpg_query/grammar/statements/select.y" + case 1322: +#line 4255 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = list_make1(makeString((yyvsp[(2) - (2)].str))); ;} break; - case 1352: -#line 4303 "third_party/libpg_query/grammar/statements/select.y" + case 1323: +#line 4257 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), makeString((yyvsp[(3) - (3)].str))); ;} break; - case 1353: -#line 4307 "third_party/libpg_query/grammar/statements/select.y" + case 1324: +#line 4261 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 1354: -#line 4308 "third_party/libpg_query/grammar/statements/select.y" + case 1325: +#line 4262 "third_party/libpg_query/grammar/statements/select.y" { (yyval.list) = NIL; ;} break; - case 1356: -#line 4315 "third_party/libpg_query/grammar/statements/select.y" + case 1327: +#line 4269 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1357: -#line 4316 "third_party/libpg_query/grammar/statements/select.y" + case 1328: +#line 4270 "third_party/libpg_query/grammar/statements/select.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1358: + case 1329: #line 8 "third_party/libpg_query/grammar/statements/prepare.y" { PGPrepareStmt *n = makeNode(PGPrepareStmt); @@ -30417,17 +30002,17 @@ YYLTYPE yylloc; ;} break; - case 1359: + case 1330: #line 18 "third_party/libpg_query/grammar/statements/prepare.y" { (yyval.list) = (yyvsp[(2) - (3)].list); ;} break; - case 1360: + case 1331: #line 19 "third_party/libpg_query/grammar/statements/prepare.y" { (yyval.list) = NIL; ;} break; - case 1367: + case 1338: #line 8 "third_party/libpg_query/grammar/statements/create_schema.y" { PGCreateSchemaStmt *n = makeNode(PGCreateSchemaStmt); @@ -30449,7 +30034,7 @@ YYLTYPE yylloc; ;} break; - case 1368: + case 1339: #line 27 "third_party/libpg_query/grammar/statements/create_schema.y" { PGCreateSchemaStmt *n = makeNode(PGCreateSchemaStmt); @@ -30476,7 +30061,7 @@ YYLTYPE yylloc; ;} break; - case 1369: + case 1340: #line 51 "third_party/libpg_query/grammar/statements/create_schema.y" { PGCreateSchemaStmt *n = makeNode(PGCreateSchemaStmt); @@ -30498,7 +30083,7 @@ YYLTYPE yylloc; ;} break; - case 1370: + case 1341: #line 74 "third_party/libpg_query/grammar/statements/create_schema.y" { if ((yyloc) < 0) /* see comments for YYLLOC_DEFAULT */ @@ -30507,12 +30092,12 @@ YYLTYPE yylloc; ;} break; - case 1371: + case 1342: #line 80 "third_party/libpg_query/grammar/statements/create_schema.y" { (yyval.list) = NIL; ;} break; - case 1376: + case 1347: #line 11 "third_party/libpg_query/grammar/statements/index.y" { PGIndexStmt *n = makeNode(PGIndexStmt); @@ -30538,7 +30123,7 @@ YYLTYPE yylloc; ;} break; - case 1377: + case 1348: #line 36 "third_party/libpg_query/grammar/statements/index.y" { PGIndexStmt *n = makeNode(PGIndexStmt); @@ -30564,62 +30149,62 @@ YYLTYPE yylloc; ;} break; - case 1378: + case 1349: #line 62 "third_party/libpg_query/grammar/statements/index.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1379: + case 1350: #line 66 "third_party/libpg_query/grammar/statements/index.y" { (yyval.str) = (yyvsp[(2) - (2)].str); ;} break; - case 1380: + case 1351: #line 67 "third_party/libpg_query/grammar/statements/index.y" { (yyval.str) = (char*) DEFAULT_INDEX_TYPE; ;} break; - case 1381: + case 1352: #line 72 "third_party/libpg_query/grammar/statements/index.y" { (yyval.boolean) = true; ;} break; - case 1382: + case 1353: #line 73 "third_party/libpg_query/grammar/statements/index.y" { (yyval.boolean) = false; ;} break; - case 1383: + case 1354: #line 78 "third_party/libpg_query/grammar/statements/index.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1384: + case 1355: #line 79 "third_party/libpg_query/grammar/statements/index.y" { (yyval.str) = NULL; ;} break; - case 1385: + case 1356: #line 83 "third_party/libpg_query/grammar/statements/index.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 1386: + case 1357: #line 84 "third_party/libpg_query/grammar/statements/index.y" { (yyval.list) = NIL; ;} break; - case 1387: + case 1358: #line 89 "third_party/libpg_query/grammar/statements/index.y" { (yyval.boolean) = true; ;} break; - case 1388: + case 1359: #line 90 "third_party/libpg_query/grammar/statements/index.y" { (yyval.boolean) = false; ;} break; - case 1389: + case 1360: #line 8 "third_party/libpg_query/grammar/statements/alter_schema.y" { PGAlterObjectSchemaStmt *n = makeNode(PGAlterObjectSchemaStmt); @@ -30631,7 +30216,7 @@ YYLTYPE yylloc; ;} break; - case 1390: + case 1361: #line 17 "third_party/libpg_query/grammar/statements/alter_schema.y" { PGAlterObjectSchemaStmt *n = makeNode(PGAlterObjectSchemaStmt); @@ -30643,7 +30228,7 @@ YYLTYPE yylloc; ;} break; - case 1391: + case 1362: #line 26 "third_party/libpg_query/grammar/statements/alter_schema.y" { PGAlterObjectSchemaStmt *n = makeNode(PGAlterObjectSchemaStmt); @@ -30655,7 +30240,7 @@ YYLTYPE yylloc; ;} break; - case 1392: + case 1363: #line 35 "third_party/libpg_query/grammar/statements/alter_schema.y" { PGAlterObjectSchemaStmt *n = makeNode(PGAlterObjectSchemaStmt); @@ -30667,7 +30252,7 @@ YYLTYPE yylloc; ;} break; - case 1393: + case 1364: #line 44 "third_party/libpg_query/grammar/statements/alter_schema.y" { PGAlterObjectSchemaStmt *n = makeNode(PGAlterObjectSchemaStmt); @@ -30679,7 +30264,7 @@ YYLTYPE yylloc; ;} break; - case 1394: + case 1365: #line 53 "third_party/libpg_query/grammar/statements/alter_schema.y" { PGAlterObjectSchemaStmt *n = makeNode(PGAlterObjectSchemaStmt); @@ -30691,7 +30276,7 @@ YYLTYPE yylloc; ;} break; - case 1395: + case 1366: #line 6 "third_party/libpg_query/grammar/statements/checkpoint.y" { PGCheckPointStmt *n = makeNode(PGCheckPointStmt); @@ -30701,7 +30286,7 @@ YYLTYPE yylloc; ;} break; - case 1396: + case 1367: #line 13 "third_party/libpg_query/grammar/statements/checkpoint.y" { PGCheckPointStmt *n = makeNode(PGCheckPointStmt); @@ -30711,17 +30296,17 @@ YYLTYPE yylloc; ;} break; - case 1397: + case 1368: #line 22 "third_party/libpg_query/grammar/statements/checkpoint.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1398: + case 1369: #line 23 "third_party/libpg_query/grammar/statements/checkpoint.y" { (yyval.str) = NULL; ;} break; - case 1399: + case 1370: #line 8 "third_party/libpg_query/grammar/statements/comment_on.y" { PGCommentOnStmt *n = makeNode(PGCommentOnStmt); @@ -30732,7 +30317,7 @@ YYLTYPE yylloc; ;} break; - case 1400: + case 1371: #line 16 "third_party/libpg_query/grammar/statements/comment_on.y" { PGCommentOnStmt *n = makeNode(PGCommentOnStmt); @@ -30743,67 +30328,67 @@ YYLTYPE yylloc; ;} break; - case 1401: + case 1372: #line 26 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.node) = makeStringConst((yyvsp[(1) - (1)].str), (yylsp[(1) - (1)])); ;} break; - case 1402: + case 1373: #line 27 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.node) = makeNullAConst((yylsp[(1) - (1)])); ;} break; - case 1403: + case 1374: #line 30 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_TABLE; ;} break; - case 1404: + case 1375: #line 31 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_SEQUENCE; ;} break; - case 1405: + case 1376: #line 32 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_FUNCTION; ;} break; - case 1406: + case 1377: #line 33 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_FUNCTION; ;} break; - case 1407: + case 1378: #line 34 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_TABLE_MACRO; ;} break; - case 1408: + case 1379: #line 35 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_VIEW; ;} break; - case 1409: + case 1380: #line 36 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_DATABASE; ;} break; - case 1410: + case 1381: #line 37 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_INDEX; ;} break; - case 1411: + case 1382: #line 38 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_SCHEMA; ;} break; - case 1412: + case 1383: #line 39 "third_party/libpg_query/grammar/statements/comment_on.y" { (yyval.objtype) = PG_OBJECT_TYPE; ;} break; - case 1413: + case 1384: #line 8 "third_party/libpg_query/grammar/statements/export.y" { PGExportStmt *n = makeNode(PGExportStmt); @@ -30817,7 +30402,7 @@ YYLTYPE yylloc; ;} break; - case 1414: + case 1385: #line 20 "third_party/libpg_query/grammar/statements/export.y" { PGExportStmt *n = makeNode(PGExportStmt); @@ -30831,7 +30416,7 @@ YYLTYPE yylloc; ;} break; - case 1415: + case 1386: #line 34 "third_party/libpg_query/grammar/statements/export.y" { PGImportStmt *n = makeNode(PGImportStmt); @@ -30840,7 +30425,7 @@ YYLTYPE yylloc; ;} break; - case 1416: + case 1387: #line 10 "third_party/libpg_query/grammar/statements/explain.y" { PGExplainStmt *n = makeNode(PGExplainStmt); @@ -30850,7 +30435,7 @@ YYLTYPE yylloc; ;} break; - case 1417: + case 1388: #line 17 "third_party/libpg_query/grammar/statements/explain.y" { PGExplainStmt *n = makeNode(PGExplainStmt); @@ -30863,7 +30448,7 @@ YYLTYPE yylloc; ;} break; - case 1418: + case 1389: #line 27 "third_party/libpg_query/grammar/statements/explain.y" { PGExplainStmt *n = makeNode(PGExplainStmt); @@ -30873,7 +30458,7 @@ YYLTYPE yylloc; ;} break; - case 1419: + case 1390: #line 34 "third_party/libpg_query/grammar/statements/explain.y" { PGExplainStmt *n = makeNode(PGExplainStmt); @@ -30883,118 +30468,118 @@ YYLTYPE yylloc; ;} break; - case 1420: + case 1391: #line 44 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.boolean) = true; ;} break; - case 1421: + case 1392: #line 45 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.boolean) = false; ;} break; - case 1422: + case 1393: #line 50 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.node) = (PGNode *) makeString((yyvsp[(1) - (1)].str)); ;} break; - case 1423: + case 1394: #line 51 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.node) = (PGNode *) (yyvsp[(1) - (1)].value); ;} break; - case 1424: + case 1395: #line 52 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.node) = NULL; ;} break; - case 1456: + case 1427: #line 91 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1457: + case 1428: #line 92 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1458: + case 1429: #line 93 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = pstrdup((yyvsp[(1) - (1)].keyword)); ;} break; - case 1459: + case 1430: #line 98 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1460: + case 1431: #line 99 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1461: + case 1432: #line 105 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].defelt)); ;} break; - case 1462: + case 1433: #line 109 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].defelt)); ;} break; - case 1463: + case 1434: #line 116 "third_party/libpg_query/grammar/statements/explain.y" {;} break; - case 1464: + case 1435: #line 117 "third_party/libpg_query/grammar/statements/explain.y" {;} break; - case 1465: + case 1436: #line 122 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (char*) "true"; ;} break; - case 1466: + case 1437: #line 123 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (char*) "false"; ;} break; - case 1467: + case 1438: #line 124 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (char*) "on"; ;} break; - case 1468: + case 1439: #line 130 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1469: + case 1440: #line 136 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.defelt) = makeDefElem((yyvsp[(1) - (2)].str), (yyvsp[(2) - (2)].node), (yylsp[(1) - (2)])); ;} break; - case 1470: + case 1441: #line 143 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1471: + case 1442: #line 144 "third_party/libpg_query/grammar/statements/explain.y" { (yyval.str) = (char*) "analyze"; ;} break; - case 1472: + case 1443: #line 11 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = (yyvsp[(2) - (2)].vsetstmt); @@ -31003,7 +30588,7 @@ YYLTYPE yylloc; ;} break; - case 1473: + case 1444: #line 17 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = (yyvsp[(3) - (3)].vsetstmt); @@ -31012,7 +30597,7 @@ YYLTYPE yylloc; ;} break; - case 1474: + case 1445: #line 23 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = (yyvsp[(3) - (3)].vsetstmt); @@ -31021,7 +30606,7 @@ YYLTYPE yylloc; ;} break; - case 1475: + case 1446: #line 29 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = (yyvsp[(3) - (3)].vsetstmt); @@ -31030,7 +30615,7 @@ YYLTYPE yylloc; ;} break; - case 1476: + case 1447: #line 35 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = (yyvsp[(3) - (3)].vsetstmt); @@ -31039,12 +30624,12 @@ YYLTYPE yylloc; ;} break; - case 1477: + case 1448: #line 44 "third_party/libpg_query/grammar/statements/variable_set.y" {(yyval.vsetstmt) = (yyvsp[(1) - (1)].vsetstmt);;} break; - case 1478: + case 1449: #line 46 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31054,7 +30639,7 @@ YYLTYPE yylloc; ;} break; - case 1479: + case 1450: #line 54 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31068,7 +30653,7 @@ YYLTYPE yylloc; ;} break; - case 1480: + case 1451: #line 65 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31079,7 +30664,7 @@ YYLTYPE yylloc; ;} break; - case 1481: + case 1452: #line 77 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31090,7 +30675,7 @@ YYLTYPE yylloc; ;} break; - case 1482: + case 1453: #line 85 "third_party/libpg_query/grammar/statements/variable_set.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31101,26 +30686,26 @@ YYLTYPE yylloc; ;} break; - case 1483: + case 1454: #line 96 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.node) = (yyvsp[(1) - (1)].node); ;} break; - case 1484: + case 1455: #line 102 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.node) = makeStringConst((yyvsp[(1) - (1)].str), (yylsp[(1) - (1)])); ;} break; - case 1485: + case 1456: #line 106 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.node) = makeStringConst((yyvsp[(1) - (1)].str), (yylsp[(1) - (1)])); ;} break; - case 1486: + case 1457: #line 110 "third_party/libpg_query/grammar/statements/variable_set.y" { PGTypeName *t = (yyvsp[(1) - (3)].typnam); @@ -31138,7 +30723,7 @@ YYLTYPE yylloc; ;} break; - case 1487: + case 1458: #line 125 "third_party/libpg_query/grammar/statements/variable_set.y" { PGTypeName *t = (yyvsp[(1) - (5)].typnam); @@ -31148,32 +30733,32 @@ YYLTYPE yylloc; ;} break; - case 1488: + case 1459: #line 131 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.node) = makeAConst((yyvsp[(1) - (1)].value), (yylsp[(1) - (1)])); ;} break; - case 1489: + case 1460: #line 132 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.node) = NULL; ;} break; - case 1490: + case 1461: #line 133 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.node) = NULL; ;} break; - case 1491: + case 1462: #line 137 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.list) = list_make1((yyvsp[(1) - (1)].node)); ;} break; - case 1492: + case 1463: #line 138 "third_party/libpg_query/grammar/statements/variable_set.y" { (yyval.list) = lappend((yyvsp[(1) - (3)].list), (yyvsp[(3) - (3)].node)); ;} break; - case 1493: + case 1464: #line 8 "third_party/libpg_query/grammar/statements/load.y" { PGLoadStmt *n = makeNode(PGLoadStmt); @@ -31186,7 +30771,7 @@ YYLTYPE yylloc; ;} break; - case 1494: + case 1465: #line 17 "third_party/libpg_query/grammar/statements/load.y" { PGLoadStmt *n = makeNode(PGLoadStmt); @@ -31199,7 +30784,7 @@ YYLTYPE yylloc; ;} break; - case 1495: + case 1466: #line 26 "third_party/libpg_query/grammar/statements/load.y" { PGLoadStmt *n = makeNode(PGLoadStmt); @@ -31212,7 +30797,7 @@ YYLTYPE yylloc; ;} break; - case 1496: + case 1467: #line 35 "third_party/libpg_query/grammar/statements/load.y" { PGLoadStmt *n = makeNode(PGLoadStmt); @@ -31225,42 +30810,42 @@ YYLTYPE yylloc; ;} break; - case 1497: + case 1468: #line 46 "third_party/libpg_query/grammar/statements/load.y" { (yyval.loadinstalltype) = PG_LOAD_TYPE_INSTALL; ;} break; - case 1498: + case 1469: #line 47 "third_party/libpg_query/grammar/statements/load.y" { (yyval.loadinstalltype) = PG_LOAD_TYPE_FORCE_INSTALL; ;} break; - case 1499: + case 1470: #line 49 "third_party/libpg_query/grammar/statements/load.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1500: + case 1471: #line 50 "third_party/libpg_query/grammar/statements/load.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1501: + case 1472: #line 53 "third_party/libpg_query/grammar/statements/load.y" { (yyval.str) = NULL; ;} break; - case 1502: + case 1473: #line 54 "third_party/libpg_query/grammar/statements/load.y" { (yyval.str) = (yyvsp[(2) - (2)].str); ;} break; - case 1503: + case 1474: #line 55 "third_party/libpg_query/grammar/statements/load.y" { (yyval.str) = (yyvsp[(2) - (2)].str); ;} break; - case 1504: + case 1475: #line 9 "third_party/libpg_query/grammar/statements/vacuum.y" { PGVacuumStmt *n = makeNode(PGVacuumStmt); @@ -31277,7 +30862,7 @@ YYLTYPE yylloc; ;} break; - case 1505: + case 1476: #line 23 "third_party/libpg_query/grammar/statements/vacuum.y" { PGVacuumStmt *n = makeNode(PGVacuumStmt); @@ -31294,7 +30879,7 @@ YYLTYPE yylloc; ;} break; - case 1506: + case 1477: #line 37 "third_party/libpg_query/grammar/statements/vacuum.y" { PGVacuumStmt *n = (PGVacuumStmt *) (yyvsp[(5) - (5)].node); @@ -31309,7 +30894,7 @@ YYLTYPE yylloc; ;} break; - case 1507: + case 1478: #line 49 "third_party/libpg_query/grammar/statements/vacuum.y" { PGVacuumStmt *n = makeNode(PGVacuumStmt); @@ -31320,7 +30905,7 @@ YYLTYPE yylloc; ;} break; - case 1508: + case 1479: #line 57 "third_party/libpg_query/grammar/statements/vacuum.y" { PGVacuumStmt *n = makeNode(PGVacuumStmt); @@ -31333,27 +30918,27 @@ YYLTYPE yylloc; ;} break; - case 1509: + case 1480: #line 70 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.ival) = PG_VACOPT_ANALYZE; ;} break; - case 1510: + case 1481: #line 71 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.ival) = PG_VACOPT_VERBOSE; ;} break; - case 1511: + case 1482: #line 72 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.ival) = PG_VACOPT_FREEZE; ;} break; - case 1512: + case 1483: #line 73 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.ival) = PG_VACOPT_FULL; ;} break; - case 1513: + case 1484: #line 75 "third_party/libpg_query/grammar/statements/vacuum.y" { if (strcmp((yyvsp[(1) - (1)].str), "disable_page_skipping") == 0) @@ -31366,37 +30951,37 @@ YYLTYPE yylloc; ;} break; - case 1514: + case 1485: #line 87 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.boolean) = true; ;} break; - case 1515: + case 1486: #line 88 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.boolean) = false; ;} break; - case 1516: + case 1487: #line 93 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.ival) = (yyvsp[(1) - (1)].ival); ;} break; - case 1517: + case 1488: #line 94 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.ival) = (yyvsp[(1) - (3)].ival) | (yyvsp[(3) - (3)].ival); ;} break; - case 1518: + case 1489: #line 98 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.boolean) = true; ;} break; - case 1519: + case 1490: #line 99 "third_party/libpg_query/grammar/statements/vacuum.y" { (yyval.boolean) = false; ;} break; - case 1520: + case 1491: #line 9 "third_party/libpg_query/grammar/statements/delete.y" { PGDeleteStmt *n = makeNode(PGDeleteStmt); @@ -31409,7 +30994,7 @@ YYLTYPE yylloc; ;} break; - case 1521: + case 1492: #line 19 "third_party/libpg_query/grammar/statements/delete.y" { PGDeleteStmt *n = makeNode(PGDeleteStmt); @@ -31422,14 +31007,14 @@ YYLTYPE yylloc; ;} break; - case 1522: + case 1493: #line 32 "third_party/libpg_query/grammar/statements/delete.y" { (yyval.range) = (yyvsp[(1) - (1)].range); ;} break; - case 1523: + case 1494: #line 36 "third_party/libpg_query/grammar/statements/delete.y" { PGAlias *alias = makeNode(PGAlias); @@ -31439,7 +31024,7 @@ YYLTYPE yylloc; ;} break; - case 1524: + case 1495: #line 43 "third_party/libpg_query/grammar/statements/delete.y" { PGAlias *alias = makeNode(PGAlias); @@ -31449,27 +31034,27 @@ YYLTYPE yylloc; ;} break; - case 1525: + case 1496: #line 53 "third_party/libpg_query/grammar/statements/delete.y" { (yyval.node) = (yyvsp[(2) - (2)].node); ;} break; - case 1526: + case 1497: #line 54 "third_party/libpg_query/grammar/statements/delete.y" { (yyval.node) = NULL; ;} break; - case 1527: + case 1498: #line 60 "third_party/libpg_query/grammar/statements/delete.y" { (yyval.list) = (yyvsp[(2) - (2)].list); ;} break; - case 1528: + case 1499: #line 61 "third_party/libpg_query/grammar/statements/delete.y" { (yyval.list) = NIL; ;} break; - case 1529: + case 1500: #line 10 "third_party/libpg_query/grammar/statements/analyze.y" { PGVacuumStmt *n = makeNode(PGVacuumStmt); @@ -31482,7 +31067,7 @@ YYLTYPE yylloc; ;} break; - case 1530: + case 1501: #line 20 "third_party/libpg_query/grammar/statements/analyze.y" { PGVacuumStmt *n = makeNode(PGVacuumStmt); @@ -31495,7 +31080,7 @@ YYLTYPE yylloc; ;} break; - case 1531: + case 1502: #line 8 "third_party/libpg_query/grammar/statements/attach.y" { PGAttachStmt *n = makeNode(PGAttachStmt); @@ -31507,7 +31092,7 @@ YYLTYPE yylloc; ;} break; - case 1532: + case 1503: #line 17 "third_party/libpg_query/grammar/statements/attach.y" { PGAttachStmt *n = makeNode(PGAttachStmt); @@ -31519,20 +31104,8 @@ YYLTYPE yylloc; ;} break; - case 1533: -#line 26 "third_party/libpg_query/grammar/statements/attach.y" - { - PGAttachStmt *n = makeNode(PGAttachStmt); - n->path = (yyvsp[(5) - (7)].str); - n->name = (yyvsp[(6) - (7)].str); - n->options = (yyvsp[(7) - (7)].list); - n->onconflict = PG_REPLACE_ON_CONFLICT; - (yyval.node) = (PGNode *)n; - ;} - break; - - case 1534: -#line 38 "third_party/libpg_query/grammar/statements/attach.y" + case 1504: +#line 29 "third_party/libpg_query/grammar/statements/attach.y" { PGDetachStmt *n = makeNode(PGDetachStmt); n->missing_ok = false; @@ -31541,8 +31114,8 @@ YYLTYPE yylloc; ;} break; - case 1535: -#line 45 "third_party/libpg_query/grammar/statements/attach.y" + case 1505: +#line 36 "third_party/libpg_query/grammar/statements/attach.y" { PGDetachStmt *n = makeNode(PGDetachStmt); n->missing_ok = false; @@ -31551,8 +31124,8 @@ YYLTYPE yylloc; ;} break; - case 1536: -#line 52 "third_party/libpg_query/grammar/statements/attach.y" + case 1506: +#line 43 "third_party/libpg_query/grammar/statements/attach.y" { PGDetachStmt *n = makeNode(PGDetachStmt); n->missing_ok = true; @@ -31561,27 +31134,27 @@ YYLTYPE yylloc; ;} break; - case 1537: -#line 60 "third_party/libpg_query/grammar/statements/attach.y" + case 1507: +#line 51 "third_party/libpg_query/grammar/statements/attach.y" {;} break; - case 1538: -#line 61 "third_party/libpg_query/grammar/statements/attach.y" + case 1508: +#line 52 "third_party/libpg_query/grammar/statements/attach.y" {;} break; - case 1539: -#line 65 "third_party/libpg_query/grammar/statements/attach.y" + case 1509: +#line 56 "third_party/libpg_query/grammar/statements/attach.y" { (yyval.str) = (yyvsp[(2) - (2)].str); ;} break; - case 1540: -#line 66 "third_party/libpg_query/grammar/statements/attach.y" + case 1510: +#line 57 "third_party/libpg_query/grammar/statements/attach.y" { (yyval.str) = NULL; ;} break; - case 1541: + case 1511: #line 3 "third_party/libpg_query/grammar/statements/variable_reset.y" { (yyvsp[(2) - (2)].vsetstmt)->scope = VAR_SET_SCOPE_DEFAULT; @@ -31589,7 +31162,7 @@ YYLTYPE yylloc; ;} break; - case 1542: + case 1512: #line 8 "third_party/libpg_query/grammar/statements/variable_reset.y" { (yyvsp[(3) - (3)].vsetstmt)->scope = VAR_SET_SCOPE_LOCAL; @@ -31597,7 +31170,7 @@ YYLTYPE yylloc; ;} break; - case 1543: + case 1513: #line 13 "third_party/libpg_query/grammar/statements/variable_reset.y" { (yyvsp[(3) - (3)].vsetstmt)->scope = VAR_SET_SCOPE_SESSION; @@ -31605,7 +31178,7 @@ YYLTYPE yylloc; ;} break; - case 1544: + case 1514: #line 18 "third_party/libpg_query/grammar/statements/variable_reset.y" { (yyvsp[(3) - (3)].vsetstmt)->scope = VAR_SET_SCOPE_GLOBAL; @@ -31613,7 +31186,7 @@ YYLTYPE yylloc; ;} break; - case 1545: + case 1515: #line 23 "third_party/libpg_query/grammar/statements/variable_reset.y" { (yyvsp[(3) - (3)].vsetstmt)->scope = VAR_SET_SCOPE_VARIABLE; @@ -31621,7 +31194,7 @@ YYLTYPE yylloc; ;} break; - case 1546: + case 1516: #line 32 "third_party/libpg_query/grammar/statements/variable_reset.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31631,7 +31204,7 @@ YYLTYPE yylloc; ;} break; - case 1547: + case 1517: #line 39 "third_party/libpg_query/grammar/statements/variable_reset.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31640,12 +31213,12 @@ YYLTYPE yylloc; ;} break; - case 1548: + case 1518: #line 48 "third_party/libpg_query/grammar/statements/variable_reset.y" { (yyval.vsetstmt) = (yyvsp[(1) - (1)].vsetstmt); ;} break; - case 1549: + case 1519: #line 50 "third_party/libpg_query/grammar/statements/variable_reset.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31655,7 +31228,7 @@ YYLTYPE yylloc; ;} break; - case 1550: + case 1520: #line 57 "third_party/libpg_query/grammar/statements/variable_reset.y" { PGVariableSetStmt *n = makeNode(PGVariableSetStmt); @@ -31665,7 +31238,7 @@ YYLTYPE yylloc; ;} break; - case 1551: + case 1521: #line 3 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowSelectStmt *n = makeNode(PGVariableShowSelectStmt); @@ -31676,7 +31249,7 @@ YYLTYPE yylloc; ;} break; - case 1552: + case 1522: #line 10 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowSelectStmt *n = makeNode(PGVariableShowSelectStmt); @@ -31687,7 +31260,7 @@ YYLTYPE yylloc; ;} break; - case 1553: + case 1523: #line 18 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowStmt *n = makeNode(PGVariableShowStmt); @@ -31697,7 +31270,7 @@ YYLTYPE yylloc; ;} break; - case 1554: + case 1524: #line 25 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowStmt *n = makeNode(PGVariableShowStmt); @@ -31707,7 +31280,7 @@ YYLTYPE yylloc; ;} break; - case 1555: + case 1525: #line 32 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowStmt *n = makeNode(PGVariableShowStmt); @@ -31717,7 +31290,7 @@ YYLTYPE yylloc; ;} break; - case 1556: + case 1526: #line 39 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowStmt *n = makeNode(PGVariableShowStmt); @@ -31727,7 +31300,7 @@ YYLTYPE yylloc; ;} break; - case 1557: + case 1527: #line 46 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowStmt *n = makeNode(PGVariableShowStmt); @@ -31737,7 +31310,7 @@ YYLTYPE yylloc; ;} break; - case 1558: + case 1528: #line 53 "third_party/libpg_query/grammar/statements/variable_show.y" { PGVariableShowStmt *n = makeNode(PGVariableShowStmt); @@ -31747,17 +31320,17 @@ YYLTYPE yylloc; ;} break; - case 1565: + case 1535: #line 67 "third_party/libpg_query/grammar/statements/variable_show.y" { (yyval.str) = (yyvsp[(1) - (1)].str); ;} break; - case 1566: + case 1536: #line 69 "third_party/libpg_query/grammar/statements/variable_show.y" { (yyval.str) = psprintf("%s.%s", (yyvsp[(1) - (3)].str), (yyvsp[(3) - (3)].str)); ;} break; - case 1567: + case 1537: #line 7 "third_party/libpg_query/grammar/statements/call.y" { PGCallStmt *n = makeNode(PGCallStmt); @@ -31766,7 +31339,7 @@ YYLTYPE yylloc; ;} break; - case 1568: + case 1538: #line 10 "third_party/libpg_query/grammar/statements/view.y" { PGViewStmt *n = makeNode(PGViewStmt); @@ -31781,7 +31354,7 @@ YYLTYPE yylloc; ;} break; - case 1569: + case 1539: #line 23 "third_party/libpg_query/grammar/statements/view.y" { PGViewStmt *n = makeNode(PGViewStmt); @@ -31796,7 +31369,7 @@ YYLTYPE yylloc; ;} break; - case 1570: + case 1540: #line 36 "third_party/libpg_query/grammar/statements/view.y" { PGViewStmt *n = makeNode(PGViewStmt); @@ -31811,7 +31384,7 @@ YYLTYPE yylloc; ;} break; - case 1571: + case 1541: #line 49 "third_party/libpg_query/grammar/statements/view.y" { PGViewStmt *n = makeNode(PGViewStmt); @@ -31831,7 +31404,7 @@ YYLTYPE yylloc; ;} break; - case 1572: + case 1542: #line 67 "third_party/libpg_query/grammar/statements/view.y" { PGViewStmt *n = makeNode(PGViewStmt); @@ -31851,27 +31424,27 @@ YYLTYPE yylloc; ;} break; - case 1573: + case 1543: #line 87 "third_party/libpg_query/grammar/statements/view.y" { (yyval.viewcheckoption) = CASCADED_CHECK_OPTION; ;} break; - case 1574: + case 1544: #line 88 "third_party/libpg_query/grammar/statements/view.y" { (yyval.viewcheckoption) = CASCADED_CHECK_OPTION; ;} break; - case 1575: + case 1545: #line 89 "third_party/libpg_query/grammar/statements/view.y" { (yyval.viewcheckoption) = PG_LOCAL_CHECK_OPTION; ;} break; - case 1576: + case 1546: #line 90 "third_party/libpg_query/grammar/statements/view.y" { (yyval.viewcheckoption) = PG_NO_CHECK_OPTION; ;} break; - case 1577: + case 1547: #line 12 "third_party/libpg_query/grammar/statements/create_as.y" { PGCreateTableAsStmt *ctas = makeNode(PGCreateTableAsStmt); @@ -31887,7 +31460,7 @@ YYLTYPE yylloc; ;} break; - case 1578: + case 1548: #line 25 "third_party/libpg_query/grammar/statements/create_as.y" { PGCreateTableAsStmt *ctas = makeNode(PGCreateTableAsStmt); @@ -31903,7 +31476,7 @@ YYLTYPE yylloc; ;} break; - case 1579: + case 1549: #line 38 "third_party/libpg_query/grammar/statements/create_as.y" { PGCreateTableAsStmt *ctas = makeNode(PGCreateTableAsStmt); @@ -31919,22 +31492,22 @@ YYLTYPE yylloc; ;} break; - case 1580: + case 1550: #line 54 "third_party/libpg_query/grammar/statements/create_as.y" { (yyval.boolean) = true; ;} break; - case 1581: + case 1551: #line 55 "third_party/libpg_query/grammar/statements/create_as.y" { (yyval.boolean) = false; ;} break; - case 1582: + case 1552: #line 56 "third_party/libpg_query/grammar/statements/create_as.y" { (yyval.boolean) = true; ;} break; - case 1583: + case 1553: #line 62 "third_party/libpg_query/grammar/statements/create_as.y" { (yyval.into) = makeNode(PGIntoClause); @@ -31949,7 +31522,7 @@ YYLTYPE yylloc; /* Line 1267 of yacc.c. */ -#line 31953 "third_party/libpg_query/grammar/grammar_out.cpp" +#line 31526 "third_party/libpg_query/grammar/grammar_out.cpp" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -32541,7 +32114,7 @@ static PGNode* makeNamedParamRef(char *name, int location) static void insertSelectOptions(PGSelectStmt *stmt, PGList *sortClause, PGList *lockingClause, - PGNode *limitOffset, PGNode *limitCount, PGNode *isLimitOffsetFirst, + PGNode *limitOffset, PGNode *limitCount, PGWithClause *withClause, core_yyscan_t yyscanner) { @@ -32586,9 +32159,6 @@ insertSelectOptions(PGSelectStmt *stmt, parser_errposition(exprLocation(limitCount)))); stmt->limitCount = limitCount; } - if (limitOffset == isLimitOffsetFirst) { - stmt->offset_first = true; - } if (withClause) { if (stmt->withClause) diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/aes.h b/src/duckdb/third_party/mbedtls/include/mbedtls/aes.h index d5eb1fd5c..63d7edb48 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/aes.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/aes.h @@ -1,29 +1,41 @@ /** - * \file aes.h - * - * \brief This file contains AES definitions and functions. - * - * The Advanced Encryption Standard (AES) specifies a FIPS-approved - * cryptographic algorithm that can be used to protect electronic - * data. - * - * The AES algorithm is a symmetric block cipher that can - * encrypt and decrypt information. For more information, see - * FIPS Publication 197: Advanced Encryption Standard and - * ISO/IEC 18033-2:2006: Information technology -- Security - * techniques -- Encryption algorithms -- Part 2: Asymmetric - * ciphers. - * - * The AES-XTS block mode is standardized by NIST SP 800-38E - * - * and described in detail by IEEE P1619 - * . - */ +* \file aes.h +* +* \brief This file contains AES definitions and functions. +* +* The Advanced Encryption Standard (AES) specifies a FIPS-approved +* cryptographic algorithm that can be used to protect electronic +* data. +* +* The AES algorithm is a symmetric block cipher that can +* encrypt and decrypt information. For more information, see +* FIPS Publication 197: Advanced Encryption Standard and +* ISO/IEC 18033-2:2006: Information technology -- Security +* techniques -- Encryption algorithms -- Part 2: Asymmetric +* ciphers. +* +* The AES-XTS block mode is standardized by NIST SP 800-38E +* +* and described in detail by IEEE P1619 +* . +*/ /* - * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ +* Copyright The Mbed TLS Contributors +* SPDX-License-Identifier: Apache-2.0 +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ #ifndef MBEDTLS_AES_H #define MBEDTLS_AES_H @@ -49,6 +61,11 @@ /** Invalid input data. */ #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) +#define inline __inline +#endif + #ifdef __cplusplus extern "C" { #endif @@ -58,569 +75,561 @@ extern "C" { // /** - * \brief The AES context-type definition. - */ -typedef struct mbedtls_aes_context { - int MBEDTLS_PRIVATE(nr); /*!< The number of rounds. */ - size_t MBEDTLS_PRIVATE(rk_offset); /*!< The offset in array elements to AES - round keys in the buffer. */ -#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C) - uint32_t MBEDTLS_PRIVATE(buf)[44]; /*!< Aligned data buffer to hold - 10 round keys for 128-bit case. */ -#else - uint32_t MBEDTLS_PRIVATE(buf)[68]; /*!< Unaligned data buffer. This buffer can - hold 32 extra Bytes, which can be used for - one of the following purposes: -
  • Alignment if VIA padlock is - used.
  • -
  • Simplifying key expansion in the 256-bit - case by generating an extra round key. -
*/ -#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH && !MBEDTLS_PADLOCK_C */ +* \brief The AES context-type definition. +*/ +typedef struct mbedtls_aes_context +{ + int MBEDTLS_PRIVATE(nr); /*!< The number of rounds. */ + uint32_t *MBEDTLS_PRIVATE(rk); /*!< AES round keys. */ + uint32_t MBEDTLS_PRIVATE(buf)[68]; /*!< Unaligned data buffer. This buffer can + hold 32 extra Bytes, which can be used for + one of the following purposes: +
  • Alignment if VIA padlock is + used.
  • +
  • Simplifying key expansion in the 256-bit + case by generating an extra round key. +
*/ } mbedtls_aes_context; #if defined(MBEDTLS_CIPHER_MODE_XTS) /** - * \brief The AES XTS context-type definition. - */ -typedef struct mbedtls_aes_xts_context { - mbedtls_aes_context MBEDTLS_PRIVATE(crypt); /*!< The AES context to use for AES block - encryption or decryption. */ - mbedtls_aes_context MBEDTLS_PRIVATE(tweak); /*!< The AES context used for tweak - computation. */ +* \brief The AES XTS context-type definition. +*/ +typedef struct mbedtls_aes_xts_context +{ + mbedtls_aes_context MBEDTLS_PRIVATE(crypt); /*!< The AES context to use for AES block + encryption or decryption. */ + mbedtls_aes_context MBEDTLS_PRIVATE(tweak); /*!< The AES context used for tweak + computation. */ } mbedtls_aes_xts_context; #endif /* MBEDTLS_CIPHER_MODE_XTS */ #else /* MBEDTLS_AES_ALT */ -#include "aes_alt.h" +#include "mbedtls/aes_alt.h" #endif /* MBEDTLS_AES_ALT */ /** - * \brief This function initializes the specified AES context. - * - * It must be the first API called before using - * the context. - * - * \param ctx The AES context to initialize. This must not be \c NULL. - */ -void mbedtls_aes_init(mbedtls_aes_context *ctx); +* \brief This function initializes the specified AES context. +* +* It must be the first API called before using +* the context. +* +* \param ctx The AES context to initialize. This must not be \c NULL. +*/ +void mbedtls_aes_init( mbedtls_aes_context *ctx ); /** - * \brief This function releases and clears the specified AES context. - * - * \param ctx The AES context to clear. - * If this is \c NULL, this function does nothing. - * Otherwise, the context must have been at least initialized. - */ -void mbedtls_aes_free(mbedtls_aes_context *ctx); +* \brief This function releases and clears the specified AES context. +* +* \param ctx The AES context to clear. +* If this is \c NULL, this function does nothing. +* Otherwise, the context must have been at least initialized. +*/ +void mbedtls_aes_free( mbedtls_aes_context *ctx ); #if defined(MBEDTLS_CIPHER_MODE_XTS) /** - * \brief This function initializes the specified AES XTS context. - * - * It must be the first API called before using - * the context. - * - * \param ctx The AES XTS context to initialize. This must not be \c NULL. - */ -void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx); +* \brief This function initializes the specified AES XTS context. +* +* It must be the first API called before using +* the context. +* +* \param ctx The AES XTS context to initialize. This must not be \c NULL. +*/ +void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ); /** - * \brief This function releases and clears the specified AES XTS context. - * - * \param ctx The AES XTS context to clear. - * If this is \c NULL, this function does nothing. - * Otherwise, the context must have been at least initialized. - */ -void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx); +* \brief This function releases and clears the specified AES XTS context. +* +* \param ctx The AES XTS context to clear. +* If this is \c NULL, this function does nothing. +* Otherwise, the context must have been at least initialized. +*/ +void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ); #endif /* MBEDTLS_CIPHER_MODE_XTS */ /** - * \brief This function sets the encryption key. - * - * \param ctx The AES context to which the key should be bound. - * It must be initialized. - * \param key The encryption key. - * This must be a readable buffer of size \p keybits bits. - * \param keybits The size of data passed in bits. Valid options are: - *
  • 128 bits
  • - *
  • 192 bits
  • - *
  • 256 bits
- * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. - */ +* \brief This function sets the encryption key. +* +* \param ctx The AES context to which the key should be bound. +* It must be initialized. +* \param key The encryption key. +* This must be a readable buffer of size \p keybits bits. +* \param keybits The size of data passed in bits. Valid options are: +*
  • 128 bits
  • +*
  • 192 bits
  • +*
  • 256 bits
+* +* \return \c 0 on success. +* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits); +int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, + unsigned int keybits ); -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) /** - * \brief This function sets the decryption key. - * - * \param ctx The AES context to which the key should be bound. - * It must be initialized. - * \param key The decryption key. - * This must be a readable buffer of size \p keybits bits. - * \param keybits The size of data passed. Valid options are: - *
  • 128 bits
  • - *
  • 192 bits
  • - *
  • 256 bits
- * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. - */ +* \brief This function sets the decryption key. +* +* \param ctx The AES context to which the key should be bound. +* It must be initialized. +* \param key The decryption key. +* This must be a readable buffer of size \p keybits bits. +* \param keybits The size of data passed. Valid options are: +*
  • 128 bits
  • +*
  • 192 bits
  • +*
  • 256 bits
+* +* \return \c 0 on success. +* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits); -#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */ +int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, + unsigned int keybits ); #if defined(MBEDTLS_CIPHER_MODE_XTS) /** - * \brief This function prepares an XTS context for encryption and - * sets the encryption key. - * - * \param ctx The AES XTS context to which the key should be bound. - * It must be initialized. - * \param key The encryption key. This is comprised of the XTS key1 - * concatenated with the XTS key2. - * This must be a readable buffer of size \p keybits bits. - * \param keybits The size of \p key passed in bits. Valid options are: - *
  • 256 bits (each of key1 and key2 is a 128-bit key)
  • - *
  • 512 bits (each of key1 and key2 is a 256-bit key)
- * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. - */ +* \brief This function prepares an XTS context for encryption and +* sets the encryption key. +* +* \param ctx The AES XTS context to which the key should be bound. +* It must be initialized. +* \param key The encryption key. This is comprised of the XTS key1 +* concatenated with the XTS key2. +* This must be a readable buffer of size \p keybits bits. +* \param keybits The size of \p key passed in bits. Valid options are: +*
  • 256 bits (each of key1 and key2 is a 128-bit key)
  • +*
  • 512 bits (each of key1 and key2 is a 256-bit key)
+* +* \return \c 0 on success. +* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx, - const unsigned char *key, - unsigned int keybits); +int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits ); /** - * \brief This function prepares an XTS context for decryption and - * sets the decryption key. - * - * \param ctx The AES XTS context to which the key should be bound. - * It must be initialized. - * \param key The decryption key. This is comprised of the XTS key1 - * concatenated with the XTS key2. - * This must be a readable buffer of size \p keybits bits. - * \param keybits The size of \p key passed in bits. Valid options are: - *
  • 256 bits (each of key1 and key2 is a 128-bit key)
  • - *
  • 512 bits (each of key1 and key2 is a 256-bit key)
- * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. - */ +* \brief This function prepares an XTS context for decryption and +* sets the decryption key. +* +* \param ctx The AES XTS context to which the key should be bound. +* It must be initialized. +* \param key The decryption key. This is comprised of the XTS key1 +* concatenated with the XTS key2. +* This must be a readable buffer of size \p keybits bits. +* \param keybits The size of \p key passed in bits. Valid options are: +*
  • 256 bits (each of key1 and key2 is a 128-bit key)
  • +*
  • 512 bits (each of key1 and key2 is a 256-bit key)
+* +* \return \c 0 on success. +* \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx, - const unsigned char *key, - unsigned int keybits); +int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits ); #endif /* MBEDTLS_CIPHER_MODE_XTS */ /** - * \brief This function performs an AES single-block encryption or - * decryption operation. - * - * It performs the operation defined in the \p mode parameter - * (encrypt or decrypt), on the input data buffer defined in - * the \p input parameter. - * - * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or - * mbedtls_aes_setkey_dec() must be called before the first - * call to this API with the same context. - * - * \param ctx The AES context to use for encryption or decryption. - * It must be initialized and bound to a key. - * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or - * #MBEDTLS_AES_DECRYPT. - * \param input The buffer holding the input data. - * It must be readable and at least \c 16 Bytes long. - * \param output The buffer where the output data will be written. - * It must be writeable and at least \c 16 Bytes long. - - * \return \c 0 on success. - */ +* \brief This function performs an AES single-block encryption or +* decryption operation. +* +* It performs the operation defined in the \p mode parameter +* (encrypt or decrypt), on the input data buffer defined in +* the \p input parameter. +* +* mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or +* mbedtls_aes_setkey_dec() must be called before the first +* call to this API with the same context. +* +* \param ctx The AES context to use for encryption or decryption. +* It must be initialized and bound to a key. +* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or +* #MBEDTLS_AES_DECRYPT. +* \param input The buffer holding the input data. +* It must be readable and at least \c 16 Bytes long. +* \param output The buffer where the output data will be written. +* It must be writeable and at least \c 16 Bytes long. + +* \return \c 0 on success. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16]); +int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, + int mode, + const unsigned char input[16], + unsigned char output[16] ); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** - * \brief This function performs an AES-CBC encryption or decryption operation - * on full blocks. - * - * It performs the operation defined in the \p mode - * parameter (encrypt/decrypt), on the input data buffer defined in - * the \p input parameter. - * - * It can be called as many times as needed, until all the input - * data is processed. mbedtls_aes_init(), and either - * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called - * before the first call to this API with the same context. - * - * \note This function operates on full blocks, that is, the input size - * must be a multiple of the AES block size of \c 16 Bytes. - * - * \note Upon exit, the content of the IV is updated so that you can - * call the same function again on the next - * block(s) of data and get the same result as if it was - * encrypted in one call. This allows a "streaming" usage. - * If you need to retain the contents of the IV, you should - * either save it manually or use the cipher module instead. - * - * - * \param ctx The AES context to use for encryption or decryption. - * It must be initialized and bound to a key. - * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or - * #MBEDTLS_AES_DECRYPT. - * \param length The length of the input data in Bytes. This must be a - * multiple of the block size (\c 16 Bytes). - * \param iv Initialization vector (updated after use). - * It must be a readable and writeable buffer of \c 16 Bytes. - * \param input The buffer holding the input data. - * It must be readable and of size \p length Bytes. - * \param output The buffer holding the output data. - * It must be writeable and of size \p length Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH - * on failure. - */ +* \brief This function performs an AES-CBC encryption or decryption operation +* on full blocks. +* +* It performs the operation defined in the \p mode +* parameter (encrypt/decrypt), on the input data buffer defined in +* the \p input parameter. +* +* It can be called as many times as needed, until all the input +* data is processed. mbedtls_aes_init(), and either +* mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called +* before the first call to this API with the same context. +* +* \note This function operates on full blocks, that is, the input size +* must be a multiple of the AES block size of \c 16 Bytes. +* +* \note Upon exit, the content of the IV is updated so that you can +* call the same function again on the next +* block(s) of data and get the same result as if it was +* encrypted in one call. This allows a "streaming" usage. +* If you need to retain the contents of the IV, you should +* either save it manually or use the cipher module instead. +* +* +* \param ctx The AES context to use for encryption or decryption. +* It must be initialized and bound to a key. +* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or +* #MBEDTLS_AES_DECRYPT. +* \param length The length of the input data in Bytes. This must be a +* multiple of the block size (\c 16 Bytes). +* \param iv Initialization vector (updated after use). +* It must be a readable and writeable buffer of \c 16 Bytes. +* \param input The buffer holding the input data. +* It must be readable and of size \p length Bytes. +* \param output The buffer holding the output data. +* It must be writeable and of size \p length Bytes. +* +* \return \c 0 on success. +* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH +* on failure. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); +int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_XTS) /** - * \brief This function performs an AES-XTS encryption or decryption - * operation for an entire XTS data unit. - * - * AES-XTS encrypts or decrypts blocks based on their location as - * defined by a data unit number. The data unit number must be - * provided by \p data_unit. - * - * NIST SP 800-38E limits the maximum size of a data unit to 2^20 - * AES blocks. If the data unit is larger than this, this function - * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH. - * - * \param ctx The AES XTS context to use for AES XTS operations. - * It must be initialized and bound to a key. - * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or - * #MBEDTLS_AES_DECRYPT. - * \param length The length of a data unit in Bytes. This can be any - * length between 16 bytes and 2^24 bytes inclusive - * (between 1 and 2^20 block cipher blocks). - * \param data_unit The address of the data unit encoded as an array of 16 - * bytes in little-endian format. For disk encryption, this - * is typically the index of the block device sector that - * contains the data. - * \param input The buffer holding the input data (which is an entire - * data unit). This function reads \p length Bytes from \p - * input. - * \param output The buffer holding the output data (which is an entire - * data unit). This function writes \p length Bytes to \p - * output. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is - * smaller than an AES block in size (16 Bytes) or if \p - * length is larger than 2^20 blocks (16 MiB). - */ +* \brief This function performs an AES-XTS encryption or decryption +* operation for an entire XTS data unit. +* +* AES-XTS encrypts or decrypts blocks based on their location as +* defined by a data unit number. The data unit number must be +* provided by \p data_unit. +* +* NIST SP 800-38E limits the maximum size of a data unit to 2^20 +* AES blocks. If the data unit is larger than this, this function +* returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH. +* +* \param ctx The AES XTS context to use for AES XTS operations. +* It must be initialized and bound to a key. +* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or +* #MBEDTLS_AES_DECRYPT. +* \param length The length of a data unit in Bytes. This can be any +* length between 16 bytes and 2^24 bytes inclusive +* (between 1 and 2^20 block cipher blocks). +* \param data_unit The address of the data unit encoded as an array of 16 +* bytes in little-endian format. For disk encryption, this +* is typically the index of the block device sector that +* contains the data. +* \param input The buffer holding the input data (which is an entire +* data unit). This function reads \p length Bytes from \p +* input. +* \param output The buffer holding the output data (which is an entire +* data unit). This function writes \p length Bytes to \p +* output. +* +* \return \c 0 on success. +* \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is +* smaller than an AES block in size (16 Bytes) or if \p +* length is larger than 2^20 blocks (16 MiB). +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx, - int mode, - size_t length, - const unsigned char data_unit[16], - const unsigned char *input, - unsigned char *output); +int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, + int mode, + size_t length, + const unsigned char data_unit[16], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_XTS */ #if defined(MBEDTLS_CIPHER_MODE_CFB) /** - * \brief This function performs an AES-CFB128 encryption or decryption - * operation. - * - * It performs the operation defined in the \p mode - * parameter (encrypt or decrypt), on the input data buffer - * defined in the \p input parameter. - * - * For CFB, you must set up the context with mbedtls_aes_setkey_enc(), - * regardless of whether you are performing an encryption or decryption - * operation, that is, regardless of the \p mode parameter. This is - * because CFB mode uses the same key schedule for encryption and - * decryption. - * - * \note Upon exit, the content of the IV is updated so that you can - * call the same function again on the next - * block(s) of data and get the same result as if it was - * encrypted in one call. This allows a "streaming" usage. - * If you need to retain the contents of the - * IV, you must either save it manually or use the cipher - * module instead. - * - * - * \param ctx The AES context to use for encryption or decryption. - * It must be initialized and bound to a key. - * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or - * #MBEDTLS_AES_DECRYPT. - * \param length The length of the input data in Bytes. - * \param iv_off The offset in IV (updated after use). - * It must point to a valid \c size_t. - * \param iv The initialization vector (updated after use). - * It must be a readable and writeable buffer of \c 16 Bytes. - * \param input The buffer holding the input data. - * It must be readable and of size \p length Bytes. - * \param output The buffer holding the output data. - * It must be writeable and of size \p length Bytes. - * - * \return \c 0 on success. - */ +* \brief This function performs an AES-CFB128 encryption or decryption +* operation. +* +* It performs the operation defined in the \p mode +* parameter (encrypt or decrypt), on the input data buffer +* defined in the \p input parameter. +* +* For CFB, you must set up the context with mbedtls_aes_setkey_enc(), +* regardless of whether you are performing an encryption or decryption +* operation, that is, regardless of the \p mode parameter. This is +* because CFB mode uses the same key schedule for encryption and +* decryption. +* +* \note Upon exit, the content of the IV is updated so that you can +* call the same function again on the next +* block(s) of data and get the same result as if it was +* encrypted in one call. This allows a "streaming" usage. +* If you need to retain the contents of the +* IV, you must either save it manually or use the cipher +* module instead. +* +* +* \param ctx The AES context to use for encryption or decryption. +* It must be initialized and bound to a key. +* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or +* #MBEDTLS_AES_DECRYPT. +* \param length The length of the input data in Bytes. +* \param iv_off The offset in IV (updated after use). +* It must point to a valid \c size_t. +* \param iv The initialization vector (updated after use). +* It must be a readable and writeable buffer of \c 16 Bytes. +* \param input The buffer holding the input data. +* It must be readable and of size \p length Bytes. +* \param output The buffer holding the output data. +* It must be writeable and of size \p length Bytes. +* +* \return \c 0 on success. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx, - int mode, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); +int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); /** - * \brief This function performs an AES-CFB8 encryption or decryption - * operation. - * - * It performs the operation defined in the \p mode - * parameter (encrypt/decrypt), on the input data buffer defined - * in the \p input parameter. - * - * Due to the nature of CFB, you must use the same key schedule for - * both encryption and decryption operations. Therefore, you must - * use the context initialized with mbedtls_aes_setkey_enc() for - * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT. - * - * \note Upon exit, the content of the IV is updated so that you can - * call the same function again on the next - * block(s) of data and get the same result as if it was - * encrypted in one call. This allows a "streaming" usage. - * If you need to retain the contents of the - * IV, you should either save it manually or use the cipher - * module instead. - * - * - * \param ctx The AES context to use for encryption or decryption. - * It must be initialized and bound to a key. - * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or - * #MBEDTLS_AES_DECRYPT - * \param length The length of the input data. - * \param iv The initialization vector (updated after use). - * It must be a readable and writeable buffer of \c 16 Bytes. - * \param input The buffer holding the input data. - * It must be readable and of size \p length Bytes. - * \param output The buffer holding the output data. - * It must be writeable and of size \p length Bytes. - * - * \return \c 0 on success. - */ +* \brief This function performs an AES-CFB8 encryption or decryption +* operation. +* +* It performs the operation defined in the \p mode +* parameter (encrypt/decrypt), on the input data buffer defined +* in the \p input parameter. +* +* Due to the nature of CFB, you must use the same key schedule for +* both encryption and decryption operations. Therefore, you must +* use the context initialized with mbedtls_aes_setkey_enc() for +* both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT. +* +* \note Upon exit, the content of the IV is updated so that you can +* call the same function again on the next +* block(s) of data and get the same result as if it was +* encrypted in one call. This allows a "streaming" usage. +* If you need to retain the contents of the +* IV, you should either save it manually or use the cipher +* module instead. +* +* +* \param ctx The AES context to use for encryption or decryption. +* It must be initialized and bound to a key. +* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or +* #MBEDTLS_AES_DECRYPT +* \param length The length of the input data. +* \param iv The initialization vector (updated after use). +* It must be a readable and writeable buffer of \c 16 Bytes. +* \param input The buffer holding the input data. +* It must be readable and of size \p length Bytes. +* \param output The buffer holding the output data. +* It must be writeable and of size \p length Bytes. +* +* \return \c 0 on success. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); +int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); #endif /*MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) /** - * \brief This function performs an AES-OFB (Output Feedback Mode) - * encryption or decryption operation. - * - * For OFB, you must set up the context with - * mbedtls_aes_setkey_enc(), regardless of whether you are - * performing an encryption or decryption operation. This is - * because OFB mode uses the same key schedule for encryption and - * decryption. - * - * The OFB operation is identical for encryption or decryption, - * therefore no operation mode needs to be specified. - * - * \note Upon exit, the content of iv, the Initialisation Vector, is - * updated so that you can call the same function again on the next - * block(s) of data and get the same result as if it was encrypted - * in one call. This allows a "streaming" usage, by initialising - * iv_off to 0 before the first call, and preserving its value - * between calls. - * - * For non-streaming use, the iv should be initialised on each call - * to a unique value, and iv_off set to 0 on each call. - * - * If you need to retain the contents of the initialisation vector, - * you must either save it manually or use the cipher module - * instead. - * - * \warning For the OFB mode, the initialisation vector must be unique - * every encryption operation. Reuse of an initialisation vector - * will compromise security. - * - * \param ctx The AES context to use for encryption or decryption. - * It must be initialized and bound to a key. - * \param length The length of the input data. - * \param iv_off The offset in IV (updated after use). - * It must point to a valid \c size_t. - * \param iv The initialization vector (updated after use). - * It must be a readable and writeable buffer of \c 16 Bytes. - * \param input The buffer holding the input data. - * It must be readable and of size \p length Bytes. - * \param output The buffer holding the output data. - * It must be writeable and of size \p length Bytes. - * - * \return \c 0 on success. - */ +* \brief This function performs an AES-OFB (Output Feedback Mode) +* encryption or decryption operation. +* +* For OFB, you must set up the context with +* mbedtls_aes_setkey_enc(), regardless of whether you are +* performing an encryption or decryption operation. This is +* because OFB mode uses the same key schedule for encryption and +* decryption. +* +* The OFB operation is identical for encryption or decryption, +* therefore no operation mode needs to be specified. +* +* \note Upon exit, the content of iv, the Initialisation Vector, is +* updated so that you can call the same function again on the next +* block(s) of data and get the same result as if it was encrypted +* in one call. This allows a "streaming" usage, by initialising +* iv_off to 0 before the first call, and preserving its value +* between calls. +* +* For non-streaming use, the iv should be initialised on each call +* to a unique value, and iv_off set to 0 on each call. +* +* If you need to retain the contents of the initialisation vector, +* you must either save it manually or use the cipher module +* instead. +* +* \warning For the OFB mode, the initialisation vector must be unique +* every encryption operation. Reuse of an initialisation vector +* will compromise security. +* +* \param ctx The AES context to use for encryption or decryption. +* It must be initialized and bound to a key. +* \param length The length of the input data. +* \param iv_off The offset in IV (updated after use). +* It must point to a valid \c size_t. +* \param iv The initialization vector (updated after use). +* It must be a readable and writeable buffer of \c 16 Bytes. +* \param input The buffer holding the input data. +* It must be readable and of size \p length Bytes. +* \param output The buffer holding the output data. +* It must be writeable and of size \p length Bytes. +* +* \return \c 0 on success. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); +int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) /** - * \brief This function performs an AES-CTR encryption or decryption - * operation. - * - * Due to the nature of CTR, you must use the same key schedule - * for both encryption and decryption operations. Therefore, you - * must use the context initialized with mbedtls_aes_setkey_enc() - * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT. - * - * \warning You must never reuse a nonce value with the same key. Doing so - * would void the encryption for the two messages encrypted with - * the same nonce and key. - * - * There are two common strategies for managing nonces with CTR: - * - * 1. You can handle everything as a single message processed over - * successive calls to this function. In that case, you want to - * set \p nonce_counter and \p nc_off to 0 for the first call, and - * then preserve the values of \p nonce_counter, \p nc_off and \p - * stream_block across calls to this function as they will be - * updated by this function. - * - * With this strategy, you must not encrypt more than 2**128 - * blocks of data with the same key. - * - * 2. You can encrypt separate messages by dividing the \p - * nonce_counter buffer in two areas: the first one used for a - * per-message nonce, handled by yourself, and the second one - * updated by this function internally. - * - * For example, you might reserve the first 12 bytes for the - * per-message nonce, and the last 4 bytes for internal use. In that - * case, before calling this function on a new message you need to - * set the first 12 bytes of \p nonce_counter to your chosen nonce - * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p - * stream_block to be ignored). That way, you can encrypt at most - * 2**96 messages of up to 2**32 blocks each with the same key. - * - * The per-message nonce (or information sufficient to reconstruct - * it) needs to be communicated with the ciphertext and must be unique. - * The recommended way to ensure uniqueness is to use a message - * counter. An alternative is to generate random nonces, but this - * limits the number of messages that can be securely encrypted: - * for example, with 96-bit random nonces, you should not encrypt - * more than 2**32 messages with the same key. - * - * Note that for both strategies, sizes are measured in blocks and - * that an AES block is 16 bytes. - * - * \warning Upon return, \p stream_block contains sensitive data. Its - * content must not be written to insecure storage and should be - * securely discarded as soon as it's no longer needed. - * - * \param ctx The AES context to use for encryption or decryption. - * It must be initialized and bound to a key. - * \param length The length of the input data. - * \param nc_off The offset in the current \p stream_block, for - * resuming within the current cipher stream. The - * offset pointer should be 0 at the start of a stream. - * It must point to a valid \c size_t. - * \param nonce_counter The 128-bit nonce and counter. - * It must be a readable-writeable buffer of \c 16 Bytes. - * \param stream_block The saved stream block for resuming. This is - * overwritten by the function. - * It must be a readable-writeable buffer of \c 16 Bytes. - * \param input The buffer holding the input data. - * It must be readable and of size \p length Bytes. - * \param output The buffer holding the output data. - * It must be writeable and of size \p length Bytes. - * - * \return \c 0 on success. - */ +* \brief This function performs an AES-CTR encryption or decryption +* operation. +* +* Due to the nature of CTR, you must use the same key schedule +* for both encryption and decryption operations. Therefore, you +* must use the context initialized with mbedtls_aes_setkey_enc() +* for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT. +* +* \warning You must never reuse a nonce value with the same key. Doing so +* would void the encryption for the two messages encrypted with +* the same nonce and key. +* +* There are two common strategies for managing nonces with CTR: +* +* 1. You can handle everything as a single message processed over +* successive calls to this function. In that case, you want to +* set \p nonce_counter and \p nc_off to 0 for the first call, and +* then preserve the values of \p nonce_counter, \p nc_off and \p +* stream_block across calls to this function as they will be +* updated by this function. +* +* With this strategy, you must not encrypt more than 2**128 +* blocks of data with the same key. +* +* 2. You can encrypt separate messages by dividing the \p +* nonce_counter buffer in two areas: the first one used for a +* per-message nonce, handled by yourself, and the second one +* updated by this function internally. +* +* For example, you might reserve the first 12 bytes for the +* per-message nonce, and the last 4 bytes for internal use. In that +* case, before calling this function on a new message you need to +* set the first 12 bytes of \p nonce_counter to your chosen nonce +* value, the last 4 to 0, and \p nc_off to 0 (which will cause \p +* stream_block to be ignored). That way, you can encrypt at most +* 2**96 messages of up to 2**32 blocks each with the same key. +* +* The per-message nonce (or information sufficient to reconstruct +* it) needs to be communicated with the ciphertext and must be unique. +* The recommended way to ensure uniqueness is to use a message +* counter. An alternative is to generate random nonces, but this +* limits the number of messages that can be securely encrypted: +* for example, with 96-bit random nonces, you should not encrypt +* more than 2**32 messages with the same key. +* +* Note that for both stategies, sizes are measured in blocks and +* that an AES block is 16 bytes. +* +* \warning Upon return, \p stream_block contains sensitive data. Its +* content must not be written to insecure storage and should be +* securely discarded as soon as it's no longer needed. +* +* \param ctx The AES context to use for encryption or decryption. +* It must be initialized and bound to a key. +* \param length The length of the input data. +* \param nc_off The offset in the current \p stream_block, for +* resuming within the current cipher stream. The +* offset pointer should be 0 at the start of a stream. +* It must point to a valid \c size_t. +* \param nonce_counter The 128-bit nonce and counter. +* It must be a readable-writeable buffer of \c 16 Bytes. +* \param stream_block The saved stream block for resuming. This is +* overwritten by the function. +* It must be a readable-writeable buffer of \c 16 Bytes. +* \param input The buffer holding the input data. +* It must be readable and of size \p length Bytes. +* \param output The buffer holding the output data. +* It must be writeable and of size \p length Bytes. +* +* \return \c 0 on success. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx, - size_t length, - size_t *nc_off, - unsigned char nonce_counter[16], - unsigned char stream_block[16], - const unsigned char *input, - unsigned char *output); +int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CTR */ /** - * \brief Internal AES block encryption function. This is only - * exposed to allow overriding it using - * \c MBEDTLS_AES_ENCRYPT_ALT. - * - * \param ctx The AES context to use for encryption. - * \param input The plaintext block. - * \param output The output (ciphertext) block. - * - * \return \c 0 on success. - */ +* \brief Internal AES block encryption function. This is only +* exposed to allow overriding it using +* \c MBEDTLS_AES_ENCRYPT_ALT. +* +* \param ctx The AES context to use for encryption. +* \param input The plaintext block. +* \param output The output (ciphertext) block. +* +* \return \c 0 on success. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16]); +int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ); -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) /** - * \brief Internal AES block decryption function. This is only - * exposed to allow overriding it using see - * \c MBEDTLS_AES_DECRYPT_ALT. - * - * \param ctx The AES context to use for decryption. - * \param input The ciphertext block. - * \param output The output (plaintext) block. - * - * \return \c 0 on success. - */ +* \brief Internal AES block decryption function. This is only +* exposed to allow overriding it using see +* \c MBEDTLS_AES_DECRYPT_ALT. +* +* \param ctx The AES context to use for decryption. +* \param input The ciphertext block. +* \param output The output (plaintext) block. +* +* \return \c 0 on success. +*/ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16]); -#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */ +int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ); #if defined(MBEDTLS_SELF_TEST) /** - * \brief Checkup routine. - * - * \return \c 0 on success. - * \return \c 1 on failure. - */ +* \brief Checkup routine. +* +* \return \c 0 on success. +* \return \c 1 on failure. +*/ MBEDTLS_CHECK_RETURN_CRITICAL -int mbedtls_aes_self_test(int verbose); +int mbedtls_aes_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/aria.h b/src/duckdb/third_party/mbedtls/include/mbedtls/aria.h index 456385123..4a2634fa8 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/aria.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/aria.h @@ -1 +1,358 @@ -// dummy \ No newline at end of file +/** + * \file aria.h + * + * \brief ARIA block cipher + * + * The ARIA algorithm is a symmetric block cipher that can encrypt and + * decrypt information. It is defined by the Korean Agency for + * Technology and Standards (KATS) in KS X 1213:2004 (in + * Korean, but see http://210.104.33.10/ARIA/index-e.html in English) + * and also described by the IETF in RFC 5794. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MBEDTLS_ARIA_H +#define MBEDTLS_ARIA_H +#include "mbedtls/private_access.h" + +#include "mbedtls/build_info.h" + +#include +#include + +#include "mbedtls/platform_util.h" + +#define MBEDTLS_ARIA_ENCRYPT 1 /**< ARIA encryption. */ +#define MBEDTLS_ARIA_DECRYPT 0 /**< ARIA decryption. */ + +#define MBEDTLS_ARIA_BLOCKSIZE 16 /**< ARIA block size in bytes. */ +#define MBEDTLS_ARIA_MAX_ROUNDS 16 /**< Maxiumum number of rounds in ARIA. */ +#define MBEDTLS_ARIA_MAX_KEYSIZE 32 /**< Maximum size of an ARIA key in bytes. */ + +/** Bad input data. */ +#define MBEDTLS_ERR_ARIA_BAD_INPUT_DATA -0x005C + +/** Invalid data input length. */ +#define MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH -0x005E + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(MBEDTLS_ARIA_ALT) +// Regular implementation +// + +/** + * \brief The ARIA context-type definition. + */ +typedef struct mbedtls_aria_context +{ + unsigned char MBEDTLS_PRIVATE(nr); /*!< The number of rounds (12, 14 or 16) */ + /*! The ARIA round keys. */ + uint32_t MBEDTLS_PRIVATE(rk)[MBEDTLS_ARIA_MAX_ROUNDS + 1][MBEDTLS_ARIA_BLOCKSIZE / 4]; +} +mbedtls_aria_context; + +#else /* MBEDTLS_ARIA_ALT */ +#include "mbedtls/aria_alt.h" +#endif /* MBEDTLS_ARIA_ALT */ + +/** + * \brief This function initializes the specified ARIA context. + * + * It must be the first API called before using + * the context. + * + * \param ctx The ARIA context to initialize. This must not be \c NULL. + */ +void mbedtls_aria_init( mbedtls_aria_context *ctx ); + +/** + * \brief This function releases and clears the specified ARIA context. + * + * \param ctx The ARIA context to clear. This may be \c NULL, in which + * case this function returns immediately. If it is not \c NULL, + * it must point to an initialized ARIA context. + */ +void mbedtls_aria_free( mbedtls_aria_context *ctx ); + +/** + * \brief This function sets the encryption key. + * + * \param ctx The ARIA context to which the key should be bound. + * This must be initialized. + * \param key The encryption key. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The size of \p key in Bits. Valid options are: + *
  • 128 bits
  • + *
  • 192 bits
  • + *
  • 256 bits
+ * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx, + const unsigned char *key, + unsigned int keybits ); + +/** + * \brief This function sets the decryption key. + * + * \param ctx The ARIA context to which the key should be bound. + * This must be initialized. + * \param key The decryption key. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The size of data passed. Valid options are: + *
  • 128 bits
  • + *
  • 192 bits
  • + *
  • 256 bits
+ * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx, + const unsigned char *key, + unsigned int keybits ); + +/** + * \brief This function performs an ARIA single-block encryption or + * decryption operation. + * + * It performs encryption or decryption (depending on whether + * the key was set for encryption on decryption) on the input + * data buffer defined in the \p input parameter. + * + * mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or + * mbedtls_aria_setkey_dec() must be called before the first + * call to this API with the same context. + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param input The 16-Byte buffer holding the input data. + * \param output The 16-Byte buffer holding the output data. + + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx, + const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE], + unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] ); + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +/** + * \brief This function performs an ARIA-CBC encryption or decryption operation + * on full blocks. + * + * It performs the operation defined in the \p mode + * parameter (encrypt/decrypt), on the input data buffer defined in + * the \p input parameter. + * + * It can be called as many times as needed, until all the input + * data is processed. mbedtls_aria_init(), and either + * mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called + * before the first call to this API with the same context. + * + * \note This function operates on aligned blocks, that is, the input size + * must be a multiple of the ARIA block size of 16 Bytes. + * + * \note Upon exit, the content of the IV is updated so that you can + * call the same function again on the next + * block(s) of data and get the same result as if it was + * encrypted in one call. This allows a "streaming" usage. + * If you need to retain the contents of the IV, you should + * either save it manually or use the cipher module instead. + * + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_ARIA_ENCRYPT for encryption, or + * #MBEDTLS_ARIA_DECRYPT for decryption. + * \param length The length of the input data in Bytes. This must be a + * multiple of the block size (16 Bytes). + * \param iv Initialization vector (updated after use). + * This must be a readable buffer of size 16 Bytes. + * \param input The buffer holding the input data. This must + * be a readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must + * be a writable buffer of length \p length Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx, + int mode, + size_t length, + unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CFB) +/** + * \brief This function performs an ARIA-CFB128 encryption or decryption + * operation. + * + * It performs the operation defined in the \p mode + * parameter (encrypt or decrypt), on the input data buffer + * defined in the \p input parameter. + * + * For CFB, you must set up the context with mbedtls_aria_setkey_enc(), + * regardless of whether you are performing an encryption or decryption + * operation, that is, regardless of the \p mode parameter. This is + * because CFB mode uses the same key schedule for encryption and + * decryption. + * + * \note Upon exit, the content of the IV is updated so that you can + * call the same function again on the next + * block(s) of data and get the same result as if it was + * encrypted in one call. This allows a "streaming" usage. + * If you need to retain the contents of the + * IV, you must either save it manually or use the cipher + * module instead. + * + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_ARIA_ENCRYPT for encryption, or + * #MBEDTLS_ARIA_DECRYPT for decryption. + * \param length The length of the input data \p input in Bytes. + * \param iv_off The offset in IV (updated after use). + * This must not be larger than 15. + * \param iv The initialization vector (updated after use). + * This must be a readable buffer of size 16 Bytes. + * \param input The buffer holding the input data. This must + * be a readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must + * be a writable buffer of length \p length Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +/** + * \brief This function performs an ARIA-CTR encryption or decryption + * operation. + * + * This function performs the operation defined in the \p mode + * parameter (encrypt/decrypt), on the input data buffer + * defined in the \p input parameter. + * + * Due to the nature of CTR, you must use the same key schedule + * for both encryption and decryption operations. Therefore, you + * must use the context initialized with mbedtls_aria_setkey_enc() + * for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT. + * + * \warning You must never reuse a nonce value with the same key. Doing so + * would void the encryption for the two messages encrypted with + * the same nonce and key. + * + * There are two common strategies for managing nonces with CTR: + * + * 1. You can handle everything as a single message processed over + * successive calls to this function. In that case, you want to + * set \p nonce_counter and \p nc_off to 0 for the first call, and + * then preserve the values of \p nonce_counter, \p nc_off and \p + * stream_block across calls to this function as they will be + * updated by this function. + * + * With this strategy, you must not encrypt more than 2**128 + * blocks of data with the same key. + * + * 2. You can encrypt separate messages by dividing the \p + * nonce_counter buffer in two areas: the first one used for a + * per-message nonce, handled by yourself, and the second one + * updated by this function internally. + * + * For example, you might reserve the first 12 bytes for the + * per-message nonce, and the last 4 bytes for internal use. In that + * case, before calling this function on a new message you need to + * set the first 12 bytes of \p nonce_counter to your chosen nonce + * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p + * stream_block to be ignored). That way, you can encrypt at most + * 2**96 messages of up to 2**32 blocks each with the same key. + * + * The per-message nonce (or information sufficient to reconstruct + * it) needs to be communicated with the ciphertext and must be unique. + * The recommended way to ensure uniqueness is to use a message + * counter. An alternative is to generate random nonces, but this + * limits the number of messages that can be securely encrypted: + * for example, with 96-bit random nonces, you should not encrypt + * more than 2**32 messages with the same key. + * + * Note that for both stategies, sizes are measured in blocks and + * that an ARIA block is 16 bytes. + * + * \warning Upon return, \p stream_block contains sensitive data. Its + * content must not be written to insecure storage and should be + * securely discarded as soon as it's no longer needed. + * + * \param ctx The ARIA context to use for encryption or decryption. + * This must be initialized and bound to a key. + * \param length The length of the input data \p input in Bytes. + * \param nc_off The offset in Bytes in the current \p stream_block, + * for resuming within the current cipher stream. The + * offset pointer should be \c 0 at the start of a + * stream. This must not be larger than \c 15 Bytes. + * \param nonce_counter The 128-bit nonce and counter. This must point to + * a read/write buffer of length \c 16 bytes. + * \param stream_block The saved stream block for resuming. This must + * point to a read/write buffer of length \c 16 bytes. + * This is overwritten by the function. + * \param input The buffer holding the input data. This must + * be a readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must + * be a writable buffer of length \p length Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE], + unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CTR */ + +#if defined(MBEDTLS_SELF_TEST) +/** + * \brief Checkup routine. + * + * \return \c 0 on success, or \c 1 on failure. + */ +int mbedtls_aria_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* aria.h */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/asn1.h b/src/duckdb/third_party/mbedtls/include/mbedtls/asn1.h index ff019f432..4746c1cb4 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/asn1.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/asn1.h @@ -5,14 +5,25 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_ASN1_H #define MBEDTLS_ASN1_H #include "mbedtls/private_access.h" #include "mbedtls/build_info.h" -#include "mbedtls/platform_util.h" #include @@ -27,9 +38,8 @@ /** * \name ASN1 Error codes - * These error codes are combined with other error codes for + * These error codes are OR'ed to X509 error codes for * higher error granularity. - * e.g. X.509 and PKCS #7 error codes * ASN1 is a standard to specify data structures. * \{ */ @@ -48,7 +58,7 @@ /** Buffer too small when writing ASN.1 data structure. */ #define MBEDTLS_ERR_ASN1_BUF_TOO_SMALL -0x006C -/** \} name ASN1 Error codes */ +/* \} name */ /** * \name DER constants @@ -84,14 +94,15 @@ /* Slightly smaller way to check if tag is a string tag * compared to canonical implementation. */ -#define MBEDTLS_ASN1_IS_STRING_TAG(tag) \ - ((unsigned int) (tag) < 32u && ( \ - ((1u << (tag)) & ((1u << MBEDTLS_ASN1_BMP_STRING) | \ - (1u << MBEDTLS_ASN1_UTF8_STRING) | \ - (1u << MBEDTLS_ASN1_T61_STRING) | \ - (1u << MBEDTLS_ASN1_IA5_STRING) | \ - (1u << MBEDTLS_ASN1_UNIVERSAL_STRING) | \ - (1u << MBEDTLS_ASN1_PRINTABLE_STRING))) != 0)) +#define MBEDTLS_ASN1_IS_STRING_TAG( tag ) \ + ( ( tag ) < 32u && ( \ + ( ( 1u << ( tag ) ) & ( ( 1u << MBEDTLS_ASN1_BMP_STRING ) | \ + ( 1u << MBEDTLS_ASN1_UTF8_STRING ) | \ + ( 1u << MBEDTLS_ASN1_T61_STRING ) | \ + ( 1u << MBEDTLS_ASN1_IA5_STRING ) | \ + ( 1u << MBEDTLS_ASN1_UNIVERSAL_STRING ) | \ + ( 1u << MBEDTLS_ASN1_PRINTABLE_STRING ) | \ + ( 1u << MBEDTLS_ASN1_BIT_STRING ) ) ) != 0 ) ) /* * Bit masks for each of the components of an ASN.1 tag as specified in @@ -107,7 +118,8 @@ #define MBEDTLS_ASN1_TAG_PC_MASK 0x20 #define MBEDTLS_ASN1_TAG_VALUE_MASK 0x1F -/** \} name DER constants */ +/* \} name */ +/* \} addtogroup asn1_module */ /** Returns the size of the binary string, without the trailing \\0 */ #define MBEDTLS_OID_SIZE(x) (sizeof(x) - 1) @@ -119,12 +131,12 @@ * 'unsigned char *oid' here! */ #define MBEDTLS_OID_CMP(oid_str, oid_buf) \ - ((MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len) || \ - memcmp((oid_str), (oid_buf)->p, (oid_buf)->len) != 0) + ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf)->len ) || \ + memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) != 0 ) #define MBEDTLS_OID_CMP_RAW(oid_str, oid_buf, oid_buf_len) \ - ((MBEDTLS_OID_SIZE(oid_str) != (oid_buf_len)) || \ - memcmp((oid_str), (oid_buf), (oid_buf_len)) != 0) + ( ( MBEDTLS_OID_SIZE(oid_str) != (oid_buf_len) ) || \ + memcmp( (oid_str), (oid_buf), (oid_buf_len) ) != 0 ) #ifdef __cplusplus extern "C" { @@ -138,7 +150,8 @@ extern "C" { /** * Type-length-value structure that allows for ASN1 using DER. */ -typedef struct mbedtls_asn1_buf { +typedef struct mbedtls_asn1_buf +{ int tag; /**< ASN1 type, e.g. MBEDTLS_ASN1_UTF8_STRING. */ size_t len; /**< ASN1 length, in octets. */ unsigned char *p; /**< ASN1 data, e.g. in ASCII. */ @@ -148,7 +161,8 @@ mbedtls_asn1_buf; /** * Container for ASN1 bit strings. */ -typedef struct mbedtls_asn1_bitstring { +typedef struct mbedtls_asn1_bitstring +{ size_t len; /**< ASN1 length, in octets. */ unsigned char unused_bits; /**< Number of unused bits at the end of the string */ unsigned char *p; /**< Raw ASN1 data for the bit string */ @@ -158,7 +172,8 @@ mbedtls_asn1_bitstring; /** * Container for a sequence of ASN.1 items */ -typedef struct mbedtls_asn1_sequence { +typedef struct mbedtls_asn1_sequence +{ mbedtls_asn1_buf buf; /**< Buffer containing the given ASN.1 item. */ /** The next entry in the sequence. @@ -175,7 +190,8 @@ mbedtls_asn1_sequence; /** * Container for a sequence or list of 'named' ASN.1 data items */ -typedef struct mbedtls_asn1_named_data { +typedef struct mbedtls_asn1_named_data +{ mbedtls_asn1_buf oid; /**< The object identifier. */ mbedtls_asn1_buf val; /**< The named value. */ @@ -197,8 +213,6 @@ typedef struct mbedtls_asn1_named_data { } mbedtls_asn1_named_data; -#if defined(MBEDTLS_ASN1_PARSE_C) || defined(MBEDTLS_X509_CREATE_C) || \ - defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA) /** * \brief Get the length of an ASN.1 element. * Updates the pointer to immediately behind the length. @@ -215,11 +229,11 @@ mbedtls_asn1_named_data; * \return 0 if successful. * \return #MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element * would end beyond \p end. - * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparsable. + * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable. */ -int mbedtls_asn1_get_len(unsigned char **p, - const unsigned char *end, - size_t *len); +int mbedtls_asn1_get_len( unsigned char **p, + const unsigned char *end, + size_t *len ); /** * \brief Get the tag and length of the element. @@ -240,14 +254,12 @@ int mbedtls_asn1_get_len(unsigned char **p, * with the requested tag. * \return #MBEDTLS_ERR_ASN1_OUT_OF_DATA if the ASN.1 element * would end beyond \p end. - * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparsable. + * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the length is unparseable. */ -int mbedtls_asn1_get_tag(unsigned char **p, - const unsigned char *end, - size_t *len, int tag); -#endif /* MBEDTLS_ASN1_PARSE_C || MBEDTLS_X509_CREATE_C || MBEDTLS_PSA_UTIL_HAVE_ECDSA */ +int mbedtls_asn1_get_tag( unsigned char **p, + const unsigned char *end, + size_t *len, int tag ); -#if defined(MBEDTLS_ASN1_PARSE_C) /** * \brief Retrieve a boolean ASN.1 tag and its value. * Updates the pointer to immediately behind the full tag. @@ -263,9 +275,9 @@ int mbedtls_asn1_get_tag(unsigned char **p, * \return An ASN.1 error code if the input does not start with * a valid ASN.1 BOOLEAN. */ -int mbedtls_asn1_get_bool(unsigned char **p, - const unsigned char *end, - int *val); +int mbedtls_asn1_get_bool( unsigned char **p, + const unsigned char *end, + int *val ); /** * \brief Retrieve an integer ASN.1 tag and its value. @@ -284,9 +296,9 @@ int mbedtls_asn1_get_bool(unsigned char **p, * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does * not fit in an \c int. */ -int mbedtls_asn1_get_int(unsigned char **p, - const unsigned char *end, - int *val); +int mbedtls_asn1_get_int( unsigned char **p, + const unsigned char *end, + int *val ); /** * \brief Retrieve an enumerated ASN.1 tag and its value. @@ -305,9 +317,9 @@ int mbedtls_asn1_get_int(unsigned char **p, * \return #MBEDTLS_ERR_ASN1_INVALID_LENGTH if the parsed value does * not fit in an \c int. */ -int mbedtls_asn1_get_enum(unsigned char **p, - const unsigned char *end, - int *val); +int mbedtls_asn1_get_enum( unsigned char **p, + const unsigned char *end, + int *val ); /** * \brief Retrieve a bitstring ASN.1 tag and its value. @@ -326,8 +338,8 @@ int mbedtls_asn1_get_enum(unsigned char **p, * \return An ASN.1 error code if the input does not start with * a valid ASN.1 BIT STRING. */ -int mbedtls_asn1_get_bitstring(unsigned char **p, const unsigned char *end, - mbedtls_asn1_bitstring *bs); +int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end, + mbedtls_asn1_bitstring *bs ); /** * \brief Retrieve a bitstring ASN.1 tag without unused bits and its @@ -347,9 +359,9 @@ int mbedtls_asn1_get_bitstring(unsigned char **p, const unsigned char *end, * \return An ASN.1 error code if the input does not start with * a valid ASN.1 BIT STRING. */ -int mbedtls_asn1_get_bitstring_null(unsigned char **p, - const unsigned char *end, - size_t *len); +int mbedtls_asn1_get_bitstring_null( unsigned char **p, + const unsigned char *end, + size_t *len ); /** * \brief Parses and splits an ASN.1 "SEQUENCE OF ". @@ -398,10 +410,10 @@ int mbedtls_asn1_get_bitstring_null(unsigned char **p, * \return An ASN.1 error code if the input does not start with * a valid ASN.1 SEQUENCE. */ -int mbedtls_asn1_get_sequence_of(unsigned char **p, - const unsigned char *end, - mbedtls_asn1_sequence *cur, - int tag); +int mbedtls_asn1_get_sequence_of( unsigned char **p, + const unsigned char *end, + mbedtls_asn1_sequence *cur, + int tag ); /** * \brief Free a heap-allocated linked list presentation of * an ASN.1 sequence, including the first element. @@ -423,7 +435,7 @@ int mbedtls_asn1_get_sequence_of(unsigned char **p, * be \c NULL, in which case this functions returns * immediately. */ -void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq); +void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq ); /** * \brief Traverse an ASN.1 SEQUENCE container and @@ -465,7 +477,7 @@ void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq); * on a successful invocation. * \param end The end of the ASN.1 SEQUENCE container. * \param tag_must_mask A mask to be applied to the ASN.1 tags found within - * the SEQUENCE before comparing to \p tag_must_val. + * the SEQUENCE before comparing to \p tag_must_value. * \param tag_must_val The required value of each ASN.1 tag found in the * SEQUENCE, after masking with \p tag_must_mask. * Mismatching tags lead to an error. @@ -474,7 +486,7 @@ void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq); * while a value of \c 0xFF for \p tag_must_mask means * that \p tag_must_val is the only allowed tag. * \param tag_may_mask A mask to be applied to the ASN.1 tags found within - * the SEQUENCE before comparing to \p tag_may_val. + * the SEQUENCE before comparing to \p tag_may_value. * \param tag_may_val The desired value of each ASN.1 tag found in the * SEQUENCE, after masking with \p tag_may_mask. * Mismatching tags will be silently ignored. @@ -515,9 +527,9 @@ int mbedtls_asn1_traverse_sequence_of( const unsigned char *end, unsigned char tag_must_mask, unsigned char tag_must_val, unsigned char tag_may_mask, unsigned char tag_may_val, - int (*cb)(void *ctx, int tag, - unsigned char *start, size_t len), - void *ctx); + int (*cb)( void *ctx, int tag, + unsigned char* start, size_t len ), + void *ctx ); #if defined(MBEDTLS_BIGNUM_C) /** @@ -538,9 +550,9 @@ int mbedtls_asn1_traverse_sequence_of( * not fit in an \c int. * \return An MPI error code if the parsed value is too large. */ -int mbedtls_asn1_get_mpi(unsigned char **p, - const unsigned char *end, - mbedtls_mpi *X); +int mbedtls_asn1_get_mpi( unsigned char **p, + const unsigned char *end, + mbedtls_mpi *X ); #endif /* MBEDTLS_BIGNUM_C */ /** @@ -559,9 +571,9 @@ int mbedtls_asn1_get_mpi(unsigned char **p, * * \return 0 if successful or a specific ASN.1 or MPI error code. */ -int mbedtls_asn1_get_alg(unsigned char **p, - const unsigned char *end, - mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params); +int mbedtls_asn1_get_alg( unsigned char **p, + const unsigned char *end, + mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params ); /** * \brief Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no @@ -578,9 +590,9 @@ int mbedtls_asn1_get_alg(unsigned char **p, * * \return 0 if successful or a specific ASN.1 or MPI error code. */ -int mbedtls_asn1_get_alg_null(unsigned char **p, - const unsigned char *end, - mbedtls_asn1_buf *alg); +int mbedtls_asn1_get_alg_null( unsigned char **p, + const unsigned char *end, + mbedtls_asn1_buf *alg ); /** * \brief Find a specific named_data entry in a sequence or list based on @@ -592,48 +604,27 @@ int mbedtls_asn1_get_alg_null(unsigned char **p, * * \return NULL if not found, or a pointer to the existing entry. */ -const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data(const mbedtls_asn1_named_data *list, - const char *oid, size_t len); +const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( const mbedtls_asn1_named_data *list, + const char *oid, size_t len ); -#if !defined(MBEDTLS_DEPRECATED_REMOVED) /** * \brief Free a mbedtls_asn1_named_data entry * - * \deprecated This function is deprecated and will be removed in a - * future version of the library. - * Please use mbedtls_asn1_free_named_data_list() - * or mbedtls_asn1_free_named_data_list_shallow(). - * * \param entry The named data entry to free. * This function calls mbedtls_free() on * `entry->oid.p` and `entry->val.p`. */ -void MBEDTLS_DEPRECATED mbedtls_asn1_free_named_data(mbedtls_asn1_named_data *entry); -#endif /* MBEDTLS_DEPRECATED_REMOVED */ +void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *entry ); /** * \brief Free all entries in a mbedtls_asn1_named_data list. * * \param head Pointer to the head of the list of named data entries to free. - * This function calls mbedtls_free() on - * `entry->oid.p` and `entry->val.p` and then on `entry` - * for each list entry, and sets \c *head to \c NULL. - */ -void mbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data **head); - -/** - * \brief Free all shallow entries in a mbedtls_asn1_named_data list, - * but do not free internal pointer targets. - * - * \param name Head of the list of named data entries to free. - * This function calls mbedtls_free() on each list element. + * This function calls mbedtls_asn1_free_named_data() and + * mbedtls_free() on each list element and + * sets \c *head to \c NULL. */ -void mbedtls_asn1_free_named_data_list_shallow(mbedtls_asn1_named_data *name); - -/** \} name Functions to parse ASN.1 data structures */ -/** \} addtogroup asn1_module */ - -#endif /* MBEDTLS_ASN1_PARSE_C */ +void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head ); #ifdef __cplusplus } diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/asn1write.h b/src/duckdb/third_party/mbedtls/include/mbedtls/asn1write.h index 0c5a85ac2..6b63dc037 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/asn1write.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/asn1write.h @@ -1,390 +1 @@ -/** - * \file asn1write.h - * - * \brief ASN.1 buffer writing functionality - */ -/* - * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ -#ifndef MBEDTLS_ASN1_WRITE_H -#define MBEDTLS_ASN1_WRITE_H - -#include "mbedtls/build_info.h" - -#include "mbedtls/asn1.h" - -#define MBEDTLS_ASN1_CHK_ADD(g, f) \ - do \ - { \ - if ((ret = (f)) < 0) \ - return ret; \ - else \ - (g) += ret; \ - } while (0) - -#define MBEDTLS_ASN1_CHK_CLEANUP_ADD(g, f) \ - do \ - { \ - if ((ret = (f)) < 0) \ - goto cleanup; \ - else \ - (g) += ret; \ - } while (0) - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(MBEDTLS_ASN1_WRITE_C) || defined(MBEDTLS_X509_USE_C) || \ - defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA) -/** - * \brief Write a length field in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param len The length value to write. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_len(unsigned char **p, const unsigned char *start, - size_t len); -/** - * \brief Write an ASN.1 tag in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param tag The tag to write. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_tag(unsigned char **p, const unsigned char *start, - unsigned char tag); -#endif /* MBEDTLS_ASN1_WRITE_C || MBEDTLS_X509_USE_C || MBEDTLS_PSA_UTIL_HAVE_ECDSA*/ - -#if defined(MBEDTLS_ASN1_WRITE_C) -/** - * \brief Write raw buffer data. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param buf The data buffer to write. - * \param size The length of the data buffer. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start, - const unsigned char *buf, size_t size); - -#if defined(MBEDTLS_BIGNUM_C) -/** - * \brief Write an arbitrary-precision number (#MBEDTLS_ASN1_INTEGER) - * in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param X The MPI to write. - * It must be non-negative. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_mpi(unsigned char **p, const unsigned char *start, - const mbedtls_mpi *X); -#endif /* MBEDTLS_BIGNUM_C */ - -/** - * \brief Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data - * in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_null(unsigned char **p, const unsigned char *start); - -/** - * \brief Write an OID tag (#MBEDTLS_ASN1_OID) and data - * in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param oid The OID to write. - * \param oid_len The length of the OID. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_oid(unsigned char **p, const unsigned char *start, - const char *oid, size_t oid_len); - -/** - * \brief Write an AlgorithmIdentifier sequence in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param oid The OID of the algorithm to write. - * \param oid_len The length of the algorithm's OID. - * \param par_len The length of the parameters, which must be already written. - * If 0, NULL parameters are added - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_algorithm_identifier(unsigned char **p, - const unsigned char *start, - const char *oid, size_t oid_len, - size_t par_len); - -/** - * \brief Write an AlgorithmIdentifier sequence in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param oid The OID of the algorithm to write. - * \param oid_len The length of the algorithm's OID. - * \param par_len The length of the parameters, which must be already written. - * \param has_par If there are any parameters. If 0, par_len must be 0. If 1 - * and \p par_len is 0, NULL parameters are added. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_algorithm_identifier_ext(unsigned char **p, - const unsigned char *start, - const char *oid, size_t oid_len, - size_t par_len, int has_par); - -/** - * \brief Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value - * in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param boolean The boolean value to write, either \c 0 or \c 1. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_bool(unsigned char **p, const unsigned char *start, - int boolean); - -/** - * \brief Write an int tag (#MBEDTLS_ASN1_INTEGER) and value - * in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param val The integer value to write. - * It must be non-negative. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_int(unsigned char **p, const unsigned char *start, int val); - -/** - * \brief Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value - * in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param val The integer value to write. - * - * \return The number of bytes written to \p p on success. - * \return A negative \c MBEDTLS_ERR_ASN1_XXX error code on failure. - */ -int mbedtls_asn1_write_enum(unsigned char **p, const unsigned char *start, int val); - -/** - * \brief Write a string in ASN.1 format using a specific - * string encoding tag. - - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param tag The string encoding tag to write, e.g. - * #MBEDTLS_ASN1_UTF8_STRING. - * \param text The string to write. - * \param text_len The length of \p text in bytes (which might - * be strictly larger than the number of characters). - * - * \return The number of bytes written to \p p on success. - * \return A negative error code on failure. - */ -int mbedtls_asn1_write_tagged_string(unsigned char **p, const unsigned char *start, - int tag, const char *text, - size_t text_len); - -/** - * \brief Write a string in ASN.1 format using the PrintableString - * string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING). - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param text The string to write. - * \param text_len The length of \p text in bytes (which might - * be strictly larger than the number of characters). - * - * \return The number of bytes written to \p p on success. - * \return A negative error code on failure. - */ -int mbedtls_asn1_write_printable_string(unsigned char **p, - const unsigned char *start, - const char *text, size_t text_len); - -/** - * \brief Write a UTF8 string in ASN.1 format using the UTF8String - * string encoding tag (#MBEDTLS_ASN1_UTF8_STRING). - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param text The string to write. - * \param text_len The length of \p text in bytes (which might - * be strictly larger than the number of characters). - * - * \return The number of bytes written to \p p on success. - * \return A negative error code on failure. - */ -int mbedtls_asn1_write_utf8_string(unsigned char **p, const unsigned char *start, - const char *text, size_t text_len); - -/** - * \brief Write a string in ASN.1 format using the IA5String - * string encoding tag (#MBEDTLS_ASN1_IA5_STRING). - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param text The string to write. - * \param text_len The length of \p text in bytes (which might - * be strictly larger than the number of characters). - * - * \return The number of bytes written to \p p on success. - * \return A negative error code on failure. - */ -int mbedtls_asn1_write_ia5_string(unsigned char **p, const unsigned char *start, - const char *text, size_t text_len); - -/** - * \brief Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and - * value in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param buf The bitstring to write. - * \param bits The total number of bits in the bitstring. - * - * \return The number of bytes written to \p p on success. - * \return A negative error code on failure. - */ -int mbedtls_asn1_write_bitstring(unsigned char **p, const unsigned char *start, - const unsigned char *buf, size_t bits); - -/** - * \brief This function writes a named bitstring tag - * (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format. - * - * As stated in RFC 5280 Appendix B, trailing zeroes are - * omitted when encoding named bitstrings in DER. - * - * \note This function works backwards within the data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer which is used for bounds-checking. - * \param buf The bitstring to write. - * \param bits The total number of bits in the bitstring. - * - * \return The number of bytes written to \p p on success. - * \return A negative error code on failure. - */ -int mbedtls_asn1_write_named_bitstring(unsigned char **p, - const unsigned char *start, - const unsigned char *buf, - size_t bits); - -/** - * \brief Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING) - * and value in ASN.1 format. - * - * \note This function works backwards in data buffer. - * - * \param p The reference to the current position pointer. - * \param start The start of the buffer, for bounds-checking. - * \param buf The buffer holding the data to write. - * \param size The length of the data buffer \p buf. - * - * \return The number of bytes written to \p p on success. - * \return A negative error code on failure. - */ -int mbedtls_asn1_write_octet_string(unsigned char **p, const unsigned char *start, - const unsigned char *buf, size_t size); - -/** - * \brief Create or find a specific named_data entry for writing in a - * sequence or list based on the OID. If not already in there, - * a new entry is added to the head of the list. - * Warning: Destructive behaviour for the val data! - * - * \param list The pointer to the location of the head of the list to seek - * through (will be updated in case of a new entry). - * \param oid The OID to look for. - * \param oid_len The size of the OID. - * \param val The associated data to store. If this is \c NULL, - * no data is copied to the new or existing buffer. - * \param val_len The minimum length of the data buffer needed. - * If this is 0, do not allocate a buffer for the associated - * data. - * If the OID was already present, enlarge, shrink or free - * the existing buffer to fit \p val_len. - * - * \return A pointer to the new / existing entry on success. - * \return \c NULL if there was a memory allocation error. - */ -mbedtls_asn1_named_data *mbedtls_asn1_store_named_data(mbedtls_asn1_named_data **list, - const char *oid, size_t oid_len, - const unsigned char *val, - size_t val_len); - -#ifdef __cplusplus -} -#endif - -#endif /* MBEDTLS_ASN1_WRITE_C */ - -#endif /* MBEDTLS_ASN1_WRITE_H */ +// dummy file to make amalgamantion happy diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/base64.h b/src/duckdb/third_party/mbedtls/include/mbedtls/base64.h index 8f459b74c..8378589f3 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/base64.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/base64.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_BASE64_H #define MBEDTLS_BASE64_H @@ -42,8 +54,8 @@ extern "C" { * \note Call this function with dlen = 0 to obtain the * required buffer size in *olen */ -int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen, - const unsigned char *src, size_t slen); +int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, + const unsigned char *src, size_t slen ); /** * \brief Decode a base64-formatted buffer @@ -62,8 +74,8 @@ int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen, * \note Call this function with *dst = NULL or dlen = 0 to obtain * the required buffer size in *olen */ -int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen, - const unsigned char *src, size_t slen); +int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, + const unsigned char *src, size_t slen ); #if defined(MBEDTLS_SELF_TEST) /** @@ -71,7 +83,7 @@ int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen, * * \return 0 if successful, or 1 if the test failed */ -int mbedtls_base64_self_test(int verbose); +int mbedtls_base64_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/bignum.h b/src/duckdb/third_party/mbedtls/include/mbedtls/bignum.h index 8367cd34e..45d311991 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/bignum.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/bignum.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_BIGNUM_H #define MBEDTLS_BIGNUM_H @@ -40,9 +52,9 @@ #define MBEDTLS_MPI_CHK(f) \ do \ { \ - if ((ret = (f)) != 0) \ - goto cleanup; \ - } while (0) + if( ( ret = (f) ) != 0 ) \ + goto cleanup; \ + } while( 0 ) /* * Maximum size MPIs are allowed to grow to in number of limbs. @@ -51,15 +63,15 @@ #if !defined(MBEDTLS_MPI_WINDOW_SIZE) /* - * Maximum window size used for modular exponentiation. Default: 3 + * Maximum window size used for modular exponentiation. Default: 6 * Minimum value: 1. Maximum value: 6. * * Result is an array of ( 2 ** MBEDTLS_MPI_WINDOW_SIZE ) MPIs used - * for the sliding window calculation. (So 8 by default) + * for the sliding window calculation. (So 64 by default) * * Reduction in size, reduces speed. */ -#define MBEDTLS_MPI_WINDOW_SIZE 3 /**< Maximum window size used. */ +#define MBEDTLS_MPI_WINDOW_SIZE 6 /**< Maximum window size used. */ #endif /* !MBEDTLS_MPI_WINDOW_SIZE */ #if !defined(MBEDTLS_MPI_MAX_SIZE) @@ -73,7 +85,7 @@ #define MBEDTLS_MPI_MAX_SIZE 1024 /**< Maximum number of bytes for usable MPIs. */ #endif /* !MBEDTLS_MPI_MAX_SIZE */ -#define MBEDTLS_MPI_MAX_BITS (8 * MBEDTLS_MPI_MAX_SIZE) /**< Maximum number of bits for usable MPIs. */ +#define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) /**< Maximum number of bits for usable MPIs. */ /* * When reading from files with mbedtls_mpi_read_file() and writing to files with @@ -93,11 +105,9 @@ * MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) + * LabelSize + 6 */ -#define MBEDTLS_MPI_MAX_BITS_SCALE100 (100 * MBEDTLS_MPI_MAX_BITS) +#define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS ) #define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332 -#define MBEDTLS_MPI_RW_BUFFER_SIZE (((MBEDTLS_MPI_MAX_BITS_SCALE100 + \ - MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / \ - MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6) +#define MBEDTLS_MPI_RW_BUFFER_SIZE ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6 ) /* * Define the base integer type, architecture-wise. @@ -111,92 +121,64 @@ */ #if !defined(MBEDTLS_HAVE_INT32) #if defined(_MSC_VER) && defined(_M_AMD64) -/* Always choose 64-bit when using MSC */ + /* Always choose 64-bit when using MSC */ #if !defined(MBEDTLS_HAVE_INT64) #define MBEDTLS_HAVE_INT64 #endif /* !MBEDTLS_HAVE_INT64 */ -typedef int64_t mbedtls_mpi_sint; -typedef uint64_t mbedtls_mpi_uint; -#define MBEDTLS_MPI_UINT_MAX UINT64_MAX + typedef int64_t mbedtls_mpi_sint; + typedef uint64_t mbedtls_mpi_uint; #elif defined(__GNUC__) && ( \ - defined(__amd64__) || defined(__x86_64__) || \ - defined(__ppc64__) || defined(__powerpc64__) || \ - defined(__ia64__) || defined(__alpha__) || \ - (defined(__sparc__) && defined(__arch64__)) || \ - defined(__s390x__) || defined(__mips64) || \ - defined(__aarch64__)) + defined(__amd64__) || defined(__x86_64__) || \ + defined(__ppc64__) || defined(__powerpc64__) || \ + defined(__ia64__) || defined(__alpha__) || \ + ( defined(__sparc__) && defined(__arch64__) ) || \ + defined(__s390x__) || defined(__mips64) || \ + defined(__aarch64__) ) #if !defined(MBEDTLS_HAVE_INT64) #define MBEDTLS_HAVE_INT64 #endif /* MBEDTLS_HAVE_INT64 */ -typedef int64_t mbedtls_mpi_sint; -typedef uint64_t mbedtls_mpi_uint; -#define MBEDTLS_MPI_UINT_MAX UINT64_MAX + typedef int64_t mbedtls_mpi_sint; + typedef uint64_t mbedtls_mpi_uint; #if !defined(MBEDTLS_NO_UDBL_DIVISION) -/* mbedtls_t_udbl defined as 128-bit unsigned int */ -typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI))); + /* mbedtls_t_udbl defined as 128-bit unsigned int */ + typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI))); #define MBEDTLS_HAVE_UDBL #endif /* !MBEDTLS_NO_UDBL_DIVISION */ #elif defined(__ARMCC_VERSION) && defined(__aarch64__) -/* - * __ARMCC_VERSION is defined for both armcc and armclang and - * __aarch64__ is only defined by armclang when compiling 64-bit code - */ + /* + * __ARMCC_VERSION is defined for both armcc and armclang and + * __aarch64__ is only defined by armclang when compiling 64-bit code + */ #if !defined(MBEDTLS_HAVE_INT64) #define MBEDTLS_HAVE_INT64 #endif /* !MBEDTLS_HAVE_INT64 */ -typedef int64_t mbedtls_mpi_sint; -typedef uint64_t mbedtls_mpi_uint; -#define MBEDTLS_MPI_UINT_MAX UINT64_MAX + typedef int64_t mbedtls_mpi_sint; + typedef uint64_t mbedtls_mpi_uint; #if !defined(MBEDTLS_NO_UDBL_DIVISION) -/* mbedtls_t_udbl defined as 128-bit unsigned int */ -typedef __uint128_t mbedtls_t_udbl; + /* mbedtls_t_udbl defined as 128-bit unsigned int */ + typedef __uint128_t mbedtls_t_udbl; #define MBEDTLS_HAVE_UDBL #endif /* !MBEDTLS_NO_UDBL_DIVISION */ #elif defined(MBEDTLS_HAVE_INT64) -/* Force 64-bit integers with unknown compiler */ -typedef int64_t mbedtls_mpi_sint; -typedef uint64_t mbedtls_mpi_uint; -#define MBEDTLS_MPI_UINT_MAX UINT64_MAX + /* Force 64-bit integers with unknown compiler */ + typedef int64_t mbedtls_mpi_sint; + typedef uint64_t mbedtls_mpi_uint; #endif #endif /* !MBEDTLS_HAVE_INT32 */ #if !defined(MBEDTLS_HAVE_INT64) -/* Default to 32-bit compilation */ + /* Default to 32-bit compilation */ #if !defined(MBEDTLS_HAVE_INT32) #define MBEDTLS_HAVE_INT32 #endif /* !MBEDTLS_HAVE_INT32 */ -typedef int32_t mbedtls_mpi_sint; -typedef uint32_t mbedtls_mpi_uint; -#define MBEDTLS_MPI_UINT_MAX UINT32_MAX + typedef int32_t mbedtls_mpi_sint; + typedef uint32_t mbedtls_mpi_uint; #if !defined(MBEDTLS_NO_UDBL_DIVISION) -typedef uint64_t mbedtls_t_udbl; + typedef uint64_t mbedtls_t_udbl; #define MBEDTLS_HAVE_UDBL #endif /* !MBEDTLS_NO_UDBL_DIVISION */ #endif /* !MBEDTLS_HAVE_INT64 */ -/* - * Sanity check that exactly one of MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64 is defined, - * so that code elsewhere doesn't have to check. - */ -#if (!(defined(MBEDTLS_HAVE_INT32) || defined(MBEDTLS_HAVE_INT64))) || \ - (defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64)) -#error "Only 32-bit or 64-bit limbs are supported in bignum" -#endif - -/** \typedef mbedtls_mpi_uint - * \brief The type of machine digits in a bignum, called _limbs_. - * - * This is always an unsigned integer type with no padding bits. The size - * is platform-dependent. - */ - -/** \typedef mbedtls_mpi_sint - * \brief The signed type corresponding to #mbedtls_mpi_uint. - * - * This is always an signed integer type with no padding bits. The size - * is platform-dependent. - */ - #ifdef __cplusplus extern "C" { #endif @@ -204,37 +186,11 @@ extern "C" { /** * \brief MPI structure */ -typedef struct mbedtls_mpi { - /** Pointer to limbs. - * - * This may be \c NULL if \c n is 0. - */ - mbedtls_mpi_uint *MBEDTLS_PRIVATE(p); - - /** Sign: -1 if the mpi is negative, 1 otherwise. - * - * The number 0 must be represented with `s = +1`. Although many library - * functions treat all-limbs-zero as equivalent to a valid representation - * of 0 regardless of the sign bit, there are exceptions, so bignum - * functions and external callers must always set \c s to +1 for the - * number zero. - * - * Note that this implies that calloc() or `... = {0}` does not create - * a valid MPI representation. You must call mbedtls_mpi_init(). - */ - signed short MBEDTLS_PRIVATE(s); - - /** Total number of limbs in \c p. */ - unsigned short MBEDTLS_PRIVATE(n); - /* Make sure that MBEDTLS_MPI_MAX_LIMBS fits in n. - * Use the same limit value on all platforms so that we don't have to - * think about different behavior on the rare platforms where - * unsigned short can store values larger than the minimum required by - * the C language, which is 65535. - */ -#if MBEDTLS_MPI_MAX_LIMBS > 65535 -#error "MBEDTLS_MPI_MAX_LIMBS > 65535 is not supported" -#endif +typedef struct mbedtls_mpi +{ + int MBEDTLS_PRIVATE(s); /*!< Sign: -1 if the mpi is negative, 1 otherwise */ + size_t MBEDTLS_PRIVATE(n); /*!< total # of limbs */ + mbedtls_mpi_uint *MBEDTLS_PRIVATE(p); /*!< pointer to limbs */ } mbedtls_mpi; @@ -246,7 +202,7 @@ mbedtls_mpi; * * \param X The MPI context to initialize. This must not be \c NULL. */ -void mbedtls_mpi_init(mbedtls_mpi *X); +void mbedtls_mpi_init( mbedtls_mpi *X ); /** * \brief This function frees the components of an MPI context. @@ -255,7 +211,7 @@ void mbedtls_mpi_init(mbedtls_mpi *X); * in which case this function is a no-op. If it is * not \c NULL, it must point to an initialized MPI. */ -void mbedtls_mpi_free(mbedtls_mpi *X); +void mbedtls_mpi_free( mbedtls_mpi *X ); /** * \brief Enlarge an MPI to the specified number of limbs. @@ -270,7 +226,7 @@ void mbedtls_mpi_free(mbedtls_mpi *X); * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs); +int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs ); /** * \brief This function resizes an MPI downwards, keeping at least the @@ -287,7 +243,7 @@ int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs); * (this can only happen when resizing up). * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs); +int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ); /** * \brief Make a copy of an MPI. @@ -302,7 +258,7 @@ int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs); * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y); +int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y ); /** * \brief Swap the contents of two MPIs. @@ -310,7 +266,7 @@ int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y); * \param X The first MPI. It must be initialized. * \param Y The second MPI. It must be initialized. */ -void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y); +void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y ); /** * \brief Perform a safe conditional copy of MPI which doesn't @@ -321,7 +277,7 @@ void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y); * \param Y The MPI to be assigned from. This must point to an * initialized MPI. * \param assign The condition deciding whether to perform the - * assignment or not. Must be either 0 or 1: + * assignment or not. Possible values: * * \c 1: Perform the assignment `X = Y`. * * \c 0: Keep the original value of \p X. * @@ -332,15 +288,11 @@ void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y); * information through branch prediction and/or memory access * patterns analysis). * - * \warning If \p assign is neither 0 nor 1, the result of this function - * is indeterminate, and the resulting value in \p X might be - * neither its original value nor the value in \p Y. - * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign); +int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign ); /** * \brief Perform a safe conditional swap which doesn't @@ -348,28 +300,24 @@ int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned * * \param X The first MPI. This must be initialized. * \param Y The second MPI. This must be initialized. - * \param swap The condition deciding whether to perform - * the swap or not. Must be either 0 or 1: + * \param assign The condition deciding whether to perform + * the swap or not. Possible values: * * \c 1: Swap the values of \p X and \p Y. * * \c 0: Keep the original values of \p X and \p Y. * * \note This function is equivalent to - * if( swap ) mbedtls_mpi_swap( X, Y ); + * if( assign ) mbedtls_mpi_swap( X, Y ); * except that it avoids leaking any information about whether - * the swap was done or not (the above code may leak + * the assignment was done or not (the above code may leak * information through branch prediction and/or memory access * patterns analysis). * - * \warning If \p swap is neither 0 nor 1, the result of this function - * is indeterminate, and both \p X and \p Y might end up with - * values different to either of the original ones. - * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on other kinds of failure. * */ -int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char swap); +int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign ); /** * \brief Store integer value in MPI. @@ -381,7 +329,7 @@ int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char swa * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z); +int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z ); /** * \brief Get a specific bit from an MPI. @@ -393,7 +341,7 @@ int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z); * of \c X is unset or set. * \return A negative error code on failure. */ -int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos); +int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos ); /** * \brief Modify a specific bit in an MPI. @@ -410,7 +358,7 @@ int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos); * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val); +int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val ); /** * \brief Return the number of bits of value \c 0 before the @@ -424,7 +372,7 @@ int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val); * \return The number of bits of value \c 0 before the least significant * bit of value \c 1 in \p X. */ -size_t mbedtls_mpi_lsb(const mbedtls_mpi *X); +size_t mbedtls_mpi_lsb( const mbedtls_mpi *X ); /** * \brief Return the number of bits up to and including the most @@ -438,7 +386,7 @@ size_t mbedtls_mpi_lsb(const mbedtls_mpi *X); * \return The number of bits up to and including the most * significant bit of value \c 1. */ -size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X); +size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X ); /** * \brief Return the total size of an MPI value in bytes. @@ -453,7 +401,7 @@ size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X); * \return The least number of bytes capable of storing * the absolute value of \p X. */ -size_t mbedtls_mpi_size(const mbedtls_mpi *X); +size_t mbedtls_mpi_size( const mbedtls_mpi *X ); /** * \brief Import an MPI from an ASCII string. @@ -465,7 +413,7 @@ size_t mbedtls_mpi_size(const mbedtls_mpi *X); * \return \c 0 if successful. * \return A negative error code on failure. */ -int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s); +int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ); /** * \brief Export an MPI to an ASCII string. @@ -489,8 +437,8 @@ int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s); * size of \p buf required for a successful call. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix, - char *buf, size_t buflen, size_t *olen); +int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, + char *buf, size_t buflen, size_t *olen ); #if defined(MBEDTLS_FS_IO) /** @@ -514,7 +462,7 @@ int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix, * is too small. * \return Another negative error code on failure. */ -int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin); +int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin ); /** * \brief Export an MPI into an opened file. @@ -531,8 +479,8 @@ int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin); * \return \c 0 if successful. * \return A negative error code on failure. */ -int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, - int radix, FILE *fout); +int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, + int radix, FILE *fout ); #endif /* MBEDTLS_FS_IO */ /** @@ -541,14 +489,14 @@ int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, * \param X The destination MPI. This must point to an initialized MPI. * \param buf The input buffer. This must be a readable buffer of length * \p buflen Bytes. - * \param buflen The length of the input buffer \p buf in Bytes. + * \param buflen The length of the input buffer \p p in Bytes. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, - size_t buflen); +int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, + size_t buflen ); /** * \brief Import X from unsigned binary data, little endian @@ -556,14 +504,14 @@ int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, * \param X The destination MPI. This must point to an initialized MPI. * \param buf The input buffer. This must be a readable buffer of length * \p buflen Bytes. - * \param buflen The length of the input buffer \p buf in Bytes. + * \param buflen The length of the input buffer \p p in Bytes. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_read_binary_le(mbedtls_mpi *X, - const unsigned char *buf, size_t buflen); +int mbedtls_mpi_read_binary_le( mbedtls_mpi *X, + const unsigned char *buf, size_t buflen ); /** * \brief Export X into unsigned binary data, big endian. @@ -580,8 +528,8 @@ int mbedtls_mpi_read_binary_le(mbedtls_mpi *X, * large enough to hold the value of \p X. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_write_binary(const mbedtls_mpi *X, unsigned char *buf, - size_t buflen); +int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf, + size_t buflen ); /** * \brief Export X into unsigned binary data, little endian. @@ -598,22 +546,20 @@ int mbedtls_mpi_write_binary(const mbedtls_mpi *X, unsigned char *buf, * large enough to hold the value of \p X. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_write_binary_le(const mbedtls_mpi *X, - unsigned char *buf, size_t buflen); +int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X, + unsigned char *buf, size_t buflen ); /** * \brief Perform a left-shift on an MPI: X <<= count * * \param X The MPI to shift. This must point to an initialized MPI. - * The MPI pointed by \p X may be resized to fit - * the resulting number. * \param count The number of bits to shift by. * * \return \c 0 if successful. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count); +int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count ); /** * \brief Perform a right-shift on an MPI: X >>= count @@ -625,7 +571,7 @@ int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count); * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count); +int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count ); /** * \brief Compare the absolute values of two MPIs. @@ -637,7 +583,7 @@ int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count); * \return \c -1 if `|X|` is lesser than `|Y|`. * \return \c 0 if `|X|` is equal to `|Y|`. */ -int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y); +int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y ); /** * \brief Compare two MPIs. @@ -649,7 +595,7 @@ int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y); * \return \c -1 if \p X is lesser than \p Y. * \return \c 0 if \p X is equal to \p Y. */ -int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y); +int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y ); /** * \brief Check if an MPI is less than the other in constant time. @@ -666,8 +612,8 @@ int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y); * \return MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the allocated length of * the two input MPIs is not the same. */ -int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X, const mbedtls_mpi *Y, - unsigned *ret); +int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, const mbedtls_mpi *Y, + unsigned *ret ); /** * \brief Compare an MPI with an integer. @@ -679,7 +625,7 @@ int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X, const mbedtls_mpi *Y, * \return \c -1 if \p X is lesser than \p z. * \return \c 0 if \p X is equal to \p z. */ -int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z); +int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z ); /** * \brief Perform an unsigned addition of MPIs: X = |A| + |B| @@ -692,8 +638,8 @@ int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z); * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Perform an unsigned subtraction of MPIs: X = |A| - |B| @@ -707,8 +653,8 @@ int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A, * \return Another negative error code on different kinds of failure. * */ -int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Perform a signed addition of MPIs: X = A + B @@ -721,8 +667,8 @@ int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Perform a signed subtraction of MPIs: X = A - B @@ -735,8 +681,8 @@ int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Perform a signed addition of an MPI and an integer: X = A + b @@ -749,8 +695,8 @@ int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, - mbedtls_mpi_sint b); +int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** * \brief Perform a signed subtraction of an MPI and an integer: @@ -764,8 +710,8 @@ int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, - mbedtls_mpi_sint b); +int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** * \brief Perform a multiplication of two MPIs: X = A * B @@ -779,8 +725,8 @@ int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, * \return Another negative error code on different kinds of failure. * */ -int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Perform a multiplication of an MPI with an unsigned integer: @@ -795,8 +741,8 @@ int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, * \return Another negative error code on different kinds of failure. * */ -int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, - mbedtls_mpi_uint b); +int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, + mbedtls_mpi_uint b ); /** * \brief Perform a division with remainder of two MPIs: @@ -804,11 +750,11 @@ int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, * * \param Q The destination MPI for the quotient. * This may be \c NULL if the value of the - * quotient is not needed. This must not alias A or B. + * quotient is not needed. * \param R The destination MPI for the remainder value. * This may be \c NULL if the value of the - * remainder is not needed. This must not alias A or B. - * \param A The dividend. This must point to an initialized MPI. + * remainder is not needed. + * \param A The dividend. This must point to an initialized MPi. * \param B The divisor. This must point to an initialized MPI. * * \return \c 0 if successful. @@ -816,8 +762,8 @@ int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p B equals zero. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Perform a division with remainder of an MPI by an integer: @@ -825,10 +771,10 @@ int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, * * \param Q The destination MPI for the quotient. * This may be \c NULL if the value of the - * quotient is not needed. This must not alias A. + * quotient is not needed. * \param R The destination MPI for the remainder value. * This may be \c NULL if the value of the - * remainder is not needed. This must not alias A. + * remainder is not needed. * \param A The dividend. This must point to an initialized MPi. * \param b The divisor. * @@ -837,8 +783,8 @@ int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if \p b equals zero. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, - mbedtls_mpi_sint b); +int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** * \brief Perform a modular reduction. R = A mod B @@ -857,8 +803,8 @@ int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, * \return Another negative error code on different kinds of failure. * */ -int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Perform a modular reduction with respect to an integer. @@ -876,14 +822,13 @@ int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_NEGATIVE_VALUE if \p b is negative. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, - mbedtls_mpi_sint b); +int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, + mbedtls_mpi_sint b ); /** - * \brief Perform a modular exponentiation: X = A^E mod N + * \brief Perform a sliding-window exponentiation: X = A^E mod N * * \param X The destination MPI. This must point to an initialized MPI. - * This must not alias E or N. * \param A The base of the exponentiation. * This must point to an initialized MPI. * \param E The exponent MPI. This must point to an initialized MPI. @@ -906,9 +851,9 @@ int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, * \return Another negative error code on different kinds of failures. * */ -int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *E, const mbedtls_mpi *N, - mbedtls_mpi *prec_RR); +int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *E, const mbedtls_mpi *N, + mbedtls_mpi *prec_RR ); /** * \brief Fill an MPI with a number of random bytes. @@ -927,9 +872,9 @@ int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A, * as a big-endian representation of an MPI; this can * be relevant in applications like deterministic ECDSA. */ -int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); +int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** Generate a random number uniformly in a range. * @@ -963,11 +908,11 @@ int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size, * for all usual cryptographic applications. * \return Another negative error code on failure. */ -int mbedtls_mpi_random(mbedtls_mpi *X, - mbedtls_mpi_sint min, - const mbedtls_mpi *N, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); +int mbedtls_mpi_random( mbedtls_mpi *X, + mbedtls_mpi_sint min, + const mbedtls_mpi *N, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** * \brief Compute the greatest common divisor: G = gcd(A, B) @@ -980,8 +925,8 @@ int mbedtls_mpi_random(mbedtls_mpi *X, * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return Another negative error code on different kinds of failure. */ -int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, - const mbedtls_mpi *B); +int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, + const mbedtls_mpi *B ); /** * \brief Compute the modular inverse: X = A^-1 mod N @@ -996,11 +941,11 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed. * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p N is less than * or equal to one. - * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p A has no modular - * inverse with respect to \p N. + * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p has no modular inverse + * with respect to \p N. */ -int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *N); +int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *N ); /** * \brief Miller-Rabin primality test. @@ -1010,7 +955,7 @@ int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, * generate yourself and that are supposed to be prime, then * \p rounds should be at least the half of the security * strength of the cryptographic algorithm. On the other hand, - * if \p X is chosen uniformly or non-adversarially (as is the + * if \p X is chosen uniformly or non-adversially (as is the * case when mbedtls_mpi_gen_prime calls this function), then * \p rounds can be much lower. * @@ -1018,7 +963,7 @@ int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, * This must point to an initialized MPI. * \param rounds The number of bases to perform the Miller-Rabin primality * test for. The probability of returning 0 on a composite is - * at most 2-2*\p rounds . + * at most 2-2*\p rounds. * \param f_rng The RNG function to use. This must not be \c NULL. * \param p_rng The RNG parameter to be passed to \p f_rng. * This may be \c NULL if \p f_rng doesn't use @@ -1029,9 +974,9 @@ int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, * \return #MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if \p X is not prime. * \return Another negative error code on other kinds of failure. */ -int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); +int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** * \brief Flags for mbedtls_mpi_gen_prime() * @@ -1062,9 +1007,9 @@ typedef enum { * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `nbits` is not between * \c 3 and #MBEDTLS_MPI_MAX_BITS. */ -int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); +int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); #if defined(MBEDTLS_SELF_TEST) @@ -1073,7 +1018,7 @@ int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags, * * \return 0 if successful, or 1 if the test failed */ -int mbedtls_mpi_self_test(int verbose); +int mbedtls_mpi_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/build_info.h b/src/duckdb/third_party/mbedtls/include/mbedtls/build_info.h index d91d2964b..cef6566c3 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/build_info.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/build_info.h @@ -1,15 +1,27 @@ /** - * \file mbedtls/build_info.h + * \file build_info.h * * \brief Build-time configuration info * * Include this file if you need to depend on the * configuration options defined in mbedtls_config.h or MBEDTLS_CONFIG_FILE */ -/* - * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ + /* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef MBEDTLS_BUILD_INFO_H #define MBEDTLS_BUILD_INFO_H @@ -25,90 +37,22 @@ * Major, Minor, Patchlevel */ #define MBEDTLS_VERSION_MAJOR 3 -#define MBEDTLS_VERSION_MINOR 6 -#define MBEDTLS_VERSION_PATCH 2 +#define MBEDTLS_VERSION_MINOR 1 +#define MBEDTLS_VERSION_PATCH 0 /** * The single version number has the following structure: * MMNNPP00 * Major version | Minor version | Patch version */ -#define MBEDTLS_VERSION_NUMBER 0x03060200 -#define MBEDTLS_VERSION_STRING "3.6.2" -#define MBEDTLS_VERSION_STRING_FULL "Mbed TLS 3.6.2" - -/* Macros for build-time platform detection */ - -#if !defined(MBEDTLS_ARCH_IS_ARM64) && \ - (defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)) -#define MBEDTLS_ARCH_IS_ARM64 -#endif - -#if !defined(MBEDTLS_ARCH_IS_ARM32) && \ - (defined(__arm__) || defined(_M_ARM) || \ - defined(_M_ARMT) || defined(__thumb__) || defined(__thumb2__)) -#define MBEDTLS_ARCH_IS_ARM32 -#endif - -#if !defined(MBEDTLS_ARCH_IS_X64) && \ - (defined(__amd64__) || defined(__x86_64__) || \ - ((defined(_M_X64) || defined(_M_AMD64)) && !defined(_M_ARM64EC))) -#define MBEDTLS_ARCH_IS_X64 -#endif - -#if !defined(MBEDTLS_ARCH_IS_X86) && \ - (defined(__i386__) || defined(_X86_) || \ - (defined(_M_IX86) && !defined(_M_I86))) -#define MBEDTLS_ARCH_IS_X86 -#endif - -#if !defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) && \ - (defined(_M_ARM64) || defined(_M_ARM64EC)) -#define MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64 -#endif - -/* This is defined if the architecture is Armv8-A, or higher */ -#if !defined(MBEDTLS_ARCH_IS_ARMV8_A) -#if defined(__ARM_ARCH) && defined(__ARM_ARCH_PROFILE) -#if (__ARM_ARCH >= 8) && (__ARM_ARCH_PROFILE == 'A') -/* GCC, clang, armclang and IAR */ -#define MBEDTLS_ARCH_IS_ARMV8_A -#endif -#elif defined(__ARM_ARCH_8A) -/* Alternative defined by clang */ -#define MBEDTLS_ARCH_IS_ARMV8_A -#elif defined(_M_ARM64) || defined(_M_ARM64EC) -/* MSVC ARM64 is at least Armv8.0-A */ -#define MBEDTLS_ARCH_IS_ARMV8_A -#endif -#endif - -#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && !defined(__clang__) \ - && !defined(__llvm__) && !defined(__INTEL_COMPILER) -/* Defined if the compiler really is gcc and not clang, etc */ -#define MBEDTLS_COMPILER_IS_GCC -#define MBEDTLS_GCC_VERSION \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -#endif +#define MBEDTLS_VERSION_NUMBER 0x03010000 +#define MBEDTLS_VERSION_STRING "3.1.0" +#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 3.1.0" #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) #define _CRT_SECURE_NO_DEPRECATE 1 #endif -/* Define `inline` on some non-C99-compliant compilers. */ -#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \ - !defined(inline) && !defined(__cplusplus) -#define inline __inline -#endif - -#if defined(MBEDTLS_CONFIG_FILES_READ) -#error "Something went wrong: MBEDTLS_CONFIG_FILES_READ defined before reading the config files!" -#endif -#if defined(MBEDTLS_CONFIG_IS_FINALIZED) -#error "Something went wrong: MBEDTLS_CONFIG_IS_FINALIZED defined before reading the config files!" -#endif - -/* X.509, TLS and non-PSA crypto configuration */ #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/mbedtls_config.h" #else @@ -117,7 +61,7 @@ #if defined(MBEDTLS_CONFIG_VERSION) && ( \ MBEDTLS_CONFIG_VERSION < 0x03000000 || \ - MBEDTLS_CONFIG_VERSION > MBEDTLS_VERSION_NUMBER) + MBEDTLS_CONFIG_VERSION > MBEDTLS_VERSION_NUMBER ) #error "Invalid config version, defined value of MBEDTLS_CONFIG_VERSION is unsupported" #endif @@ -130,65 +74,10 @@ #include MBEDTLS_USER_CONFIG_FILE #endif -/* PSA crypto configuration */ #if defined(MBEDTLS_PSA_CRYPTO_CONFIG) -#if defined(MBEDTLS_PSA_CRYPTO_CONFIG_FILE) -#include MBEDTLS_PSA_CRYPTO_CONFIG_FILE -#else -#include "psa/crypto_config.h" -#endif -#if defined(MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE) -#include MBEDTLS_PSA_CRYPTO_USER_CONFIG_FILE -#endif -#endif /* defined(MBEDTLS_PSA_CRYPTO_CONFIG) */ - -/* Indicate that all configuration files have been read. - * It is now time to adjust the configuration (follow through on dependencies, - * make PSA and legacy crypto consistent, etc.). - */ -#define MBEDTLS_CONFIG_FILES_READ - -/* Auto-enable MBEDTLS_CTR_DRBG_USE_128_BIT_KEY if - * MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH and MBEDTLS_CTR_DRBG_C defined - * to ensure a 128-bit key size in CTR_DRBG. - */ -#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && defined(MBEDTLS_CTR_DRBG_C) -#define MBEDTLS_CTR_DRBG_USE_128_BIT_KEY -#endif - -/* Auto-enable MBEDTLS_MD_C if needed by a module that didn't require it - * in a previous release, to ensure backwards compatibility. - */ -#if defined(MBEDTLS_PKCS5_C) -#define MBEDTLS_MD_C -#endif - -/* PSA crypto specific configuration options - * - If config_psa.h reads a configuration option in preprocessor directive, - * this symbol should be set before its inclusion. (e.g. MBEDTLS_MD_C) - * - If config_psa.h writes a configuration option in conditional directive, - * this symbol should be consulted after its inclusion. - * (e.g. MBEDTLS_MD_LIGHT) - */ -#if defined(MBEDTLS_PSA_CRYPTO_CONFIG) /* PSA_WANT_xxx influences MBEDTLS_xxx */ || \ - defined(MBEDTLS_PSA_CRYPTO_C) /* MBEDTLS_xxx influences PSA_WANT_xxx */ || \ - defined(MBEDTLS_PSA_CRYPTO_CLIENT) /* The same as the previous, but with separation only */ #include "mbedtls/config_psa.h" #endif -#include "mbedtls/config_adjust_legacy_crypto.h" - -#include "mbedtls/config_adjust_x509.h" - -#include "mbedtls/config_adjust_ssl.h" - -/* Indicate that all configuration symbols are set, - * even the ones that are calculated programmatically. - * It is now safe to query the configuration (to check it, to size buffers, - * etc.). - */ -#define MBEDTLS_CONFIG_IS_FINALIZED - #include "mbedtls/check_config.h" #endif /* MBEDTLS_BUILD_INFO_H */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/camellia.h b/src/duckdb/third_party/mbedtls/include/mbedtls/camellia.h index 456385123..c74193171 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/camellia.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/camellia.h @@ -1 +1,316 @@ -// dummy \ No newline at end of file +/** + * \file camellia.h + * + * \brief Camellia block cipher + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBEDTLS_CAMELLIA_H +#define MBEDTLS_CAMELLIA_H +#include "mbedtls/private_access.h" + +#include "mbedtls/build_info.h" + +#include +#include + +#include "mbedtls/platform_util.h" + +#define MBEDTLS_CAMELLIA_ENCRYPT 1 +#define MBEDTLS_CAMELLIA_DECRYPT 0 + +/** Bad input data. */ +#define MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA -0x0024 + +/** Invalid data input length. */ +#define MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(MBEDTLS_CAMELLIA_ALT) +// Regular implementation +// + +/** + * \brief CAMELLIA context structure + */ +typedef struct mbedtls_camellia_context +{ + int MBEDTLS_PRIVATE(nr); /*!< number of rounds */ + uint32_t MBEDTLS_PRIVATE(rk)[68]; /*!< CAMELLIA round keys */ +} +mbedtls_camellia_context; + +#else /* MBEDTLS_CAMELLIA_ALT */ +#include "mbedtls/camellia_alt.h" +#endif /* MBEDTLS_CAMELLIA_ALT */ + +/** + * \brief Initialize a CAMELLIA context. + * + * \param ctx The CAMELLIA context to be initialized. + * This must not be \c NULL. + */ +void mbedtls_camellia_init( mbedtls_camellia_context *ctx ); + +/** + * \brief Clear a CAMELLIA context. + * + * \param ctx The CAMELLIA context to be cleared. This may be \c NULL, + * in which case this function returns immediately. If it is not + * \c NULL, it must be initialized. + */ +void mbedtls_camellia_free( mbedtls_camellia_context *ctx ); + +/** + * \brief Perform a CAMELLIA key schedule operation for encryption. + * + * \param ctx The CAMELLIA context to use. This must be initialized. + * \param key The encryption key to use. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The length of \p key in Bits. This must be either \c 128, + * \c 192 or \c 256. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, + const unsigned char *key, + unsigned int keybits ); + +/** + * \brief Perform a CAMELLIA key schedule operation for decryption. + * + * \param ctx The CAMELLIA context to use. This must be initialized. + * \param key The decryption key. This must be a readable buffer + * of size \p keybits Bits. + * \param keybits The length of \p key in Bits. This must be either \c 128, + * \c 192 or \c 256. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, + const unsigned char *key, + unsigned int keybits ); + +/** + * \brief Perform a CAMELLIA-ECB block encryption/decryption operation. + * + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * \param input The input block. This must be a readable buffer + * of size \c 16 Bytes. + * \param output The output block. This must be a writable buffer + * of size \c 16 Bytes. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, + int mode, + const unsigned char input[16], + unsigned char output[16] ); + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +/** + * \brief Perform a CAMELLIA-CBC buffer encryption/decryption operation. + * + * \note Upon exit, the content of the IV is updated so that you can + * call the function same function again on the following + * block(s) of data and get the same result as if it was + * encrypted in one call. This allows a "streaming" usage. + * If on the other hand you need to retain the contents of the + * IV, you should either save it manually or use the cipher + * module instead. + * + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * \param length The length in Bytes of the input data \p input. + * This must be a multiple of \c 16 Bytes. + * \param iv The initialization vector. This must be a read/write buffer + * of length \c 16 Bytes. It is updated to allow streaming + * use as explained above. + * \param input The buffer holding the input data. This must point to a + * readable buffer of length \p length Bytes. + * \param output The buffer holding the output data. This must point to a + * writable buffer of length \p length Bytes. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CFB) +/** + * \brief Perform a CAMELLIA-CFB128 buffer encryption/decryption + * operation. + * + * \note Due to the nature of CFB mode, you should use the same + * key for both encryption and decryption. In particular, calls + * to this function should be preceded by a key-schedule via + * mbedtls_camellia_setkey_enc() regardless of whether \p mode + * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * + * \note Upon exit, the content of the IV is updated so that you can + * call the function same function again on the following + * block(s) of data and get the same result as if it was + * encrypted in one call. This allows a "streaming" usage. + * If on the other hand you need to retain the contents of the + * IV, you should either save it manually or use the cipher + * module instead. + * + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param mode The mode of operation. This must be either + * #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * \param length The length of the input data \p input. Any value is allowed. + * \param iv_off The current offset in the IV. This must be smaller + * than \c 16 Bytes. It is updated after this call to allow + * the aforementioned streaming usage. + * \param iv The initialization vector. This must be a read/write buffer + * of length \c 16 Bytes. It is updated after this call to + * allow the aforementioned streaming usage. + * \param input The buffer holding the input data. This must be a readable + * buffer of size \p length Bytes. + * \param output The buffer to hold the output data. This must be a writable + * buffer of length \p length Bytes. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +/** + * \brief Perform a CAMELLIA-CTR buffer encryption/decryption operation. + * + * *note Due to the nature of CTR mode, you should use the same + * key for both encryption and decryption. In particular, calls + * to this function should be preceded by a key-schedule via + * mbedtls_camellia_setkey_enc() regardless of whether \p mode + * is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. + * + * \warning You must never reuse a nonce value with the same key. Doing so + * would void the encryption for the two messages encrypted with + * the same nonce and key. + * + * There are two common strategies for managing nonces with CTR: + * + * 1. You can handle everything as a single message processed over + * successive calls to this function. In that case, you want to + * set \p nonce_counter and \p nc_off to 0 for the first call, and + * then preserve the values of \p nonce_counter, \p nc_off and \p + * stream_block across calls to this function as they will be + * updated by this function. + * + * With this strategy, you must not encrypt more than 2**128 + * blocks of data with the same key. + * + * 2. You can encrypt separate messages by dividing the \p + * nonce_counter buffer in two areas: the first one used for a + * per-message nonce, handled by yourself, and the second one + * updated by this function internally. + * + * For example, you might reserve the first \c 12 Bytes for the + * per-message nonce, and the last \c 4 Bytes for internal use. + * In that case, before calling this function on a new message you + * need to set the first \c 12 Bytes of \p nonce_counter to your + * chosen nonce value, the last four to \c 0, and \p nc_off to \c 0 + * (which will cause \p stream_block to be ignored). That way, you + * can encrypt at most \c 2**96 messages of up to \c 2**32 blocks + * each with the same key. + * + * The per-message nonce (or information sufficient to reconstruct + * it) needs to be communicated with the ciphertext and must be + * unique. The recommended way to ensure uniqueness is to use a + * message counter. An alternative is to generate random nonces, + * but this limits the number of messages that can be securely + * encrypted: for example, with 96-bit random nonces, you should + * not encrypt more than 2**32 messages with the same key. + * + * Note that for both stategies, sizes are measured in blocks and + * that a CAMELLIA block is \c 16 Bytes. + * + * \warning Upon return, \p stream_block contains sensitive data. Its + * content must not be written to insecure storage and should be + * securely discarded as soon as it's no longer needed. + * + * \param ctx The CAMELLIA context to use. This must be initialized + * and bound to a key. + * \param length The length of the input data \p input in Bytes. + * Any value is allowed. + * \param nc_off The offset in the current \p stream_block (for resuming + * within current cipher stream). The offset pointer to + * should be \c 0 at the start of a stream. It is updated + * at the end of this call. + * \param nonce_counter The 128-bit nonce and counter. This must be a read/write + * buffer of length \c 16 Bytes. + * \param stream_block The saved stream-block for resuming. This must be a + * read/write buffer of length \c 16 Bytes. + * \param input The input data stream. This must be a readable buffer of + * size \p length Bytes. + * \param output The output data stream. This must be a writable buffer + * of size \p length Bytes. + * + * \return \c 0 if successful. + * \return A negative error code on failure. + */ +int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char *input, + unsigned char *output ); +#endif /* MBEDTLS_CIPHER_MODE_CTR */ + +#if defined(MBEDTLS_SELF_TEST) + +/** + * \brief Checkup routine + * + * \return 0 if successful, or 1 if the test failed + */ +int mbedtls_camellia_self_test( int verbose ); + +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* camellia.h */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/ccm.h b/src/duckdb/third_party/mbedtls/include/mbedtls/ccm.h index 1da57c921..20245d938 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/ccm.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/ccm.h @@ -29,7 +29,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_CCM_H @@ -40,10 +52,6 @@ #include "mbedtls/cipher.h" -#if defined(MBEDTLS_BLOCK_CIPHER_C) -#include "mbedtls/block_cipher.h" -#endif - #define MBEDTLS_CCM_DECRYPT 0 #define MBEDTLS_CCM_ENCRYPT 1 #define MBEDTLS_CCM_STAR_DECRYPT 2 @@ -66,9 +74,11 @@ extern "C" { * \brief The CCM context-type definition. The CCM context is passed * to the APIs called. */ -typedef struct mbedtls_ccm_context { +typedef struct mbedtls_ccm_context +{ unsigned char MBEDTLS_PRIVATE(y)[16]; /*!< The Y working buffer */ unsigned char MBEDTLS_PRIVATE(ctr)[16]; /*!< The counter buffer */ + mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */ size_t MBEDTLS_PRIVATE(plaintext_len); /*!< Total plaintext length */ size_t MBEDTLS_PRIVATE(add_len); /*!< Total authentication data length */ size_t MBEDTLS_PRIVATE(tag_len); /*!< Total tag length */ @@ -78,24 +88,20 @@ typedef struct mbedtls_ccm_context { and plaintext/ciphertext. This variable is set to zero after auth data input is finished. */ - unsigned int MBEDTLS_PRIVATE(q); /*!< The Q working value */ - unsigned int MBEDTLS_PRIVATE(mode); /*!< The operation to perform: - #MBEDTLS_CCM_ENCRYPT or - #MBEDTLS_CCM_DECRYPT or - #MBEDTLS_CCM_STAR_ENCRYPT or - #MBEDTLS_CCM_STAR_DECRYPT. */ -#if defined(MBEDTLS_BLOCK_CIPHER_C) - mbedtls_block_cipher_context_t MBEDTLS_PRIVATE(block_cipher_ctx); /*!< The cipher context used. */ -#else - mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */ -#endif + unsigned char MBEDTLS_PRIVATE(q); /*!< The Q working value */ + unsigned char MBEDTLS_PRIVATE(mode); /*!< The operation to perform: + #MBEDTLS_CCM_ENCRYPT or + #MBEDTLS_CCM_DECRYPT or + #MBEDTLS_CCM_STAR_ENCRYPT or + #MBEDTLS_CCM_STAR_DECRYPT. */ int MBEDTLS_PRIVATE(state); /*!< Working value holding context's - state. Used for chunked data input */ + state. Used for chunked data + input */ } mbedtls_ccm_context; #else /* MBEDTLS_CCM_ALT */ -#include "ccm_alt.h" +#include "mbedtls/ccm_alt.h" #endif /* MBEDTLS_CCM_ALT */ /** @@ -105,7 +111,7 @@ mbedtls_ccm_context; * * \param ctx The CCM context to initialize. This must not be \c NULL. */ -void mbedtls_ccm_init(mbedtls_ccm_context *ctx); +void mbedtls_ccm_init( mbedtls_ccm_context *ctx ); /** * \brief This function initializes the CCM context set in the @@ -120,10 +126,10 @@ void mbedtls_ccm_init(mbedtls_ccm_context *ctx); * \return \c 0 on success. * \return A CCM or cipher-specific error code on failure. */ -int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, - mbedtls_cipher_id_t cipher, - const unsigned char *key, - unsigned int keybits); +int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, + mbedtls_cipher_id_t cipher, + const unsigned char *key, + unsigned int keybits ); /** * \brief This function releases and clears the specified CCM context @@ -132,7 +138,7 @@ int mbedtls_ccm_setkey(mbedtls_ccm_context *ctx, * \param ctx The CCM context to clear. If this is \c NULL, the function * has no effect. Otherwise, this must be initialized. */ -void mbedtls_ccm_free(mbedtls_ccm_context *ctx); +void mbedtls_ccm_free( mbedtls_ccm_context *ctx ); /** * \brief This function encrypts a buffer using CCM. @@ -170,11 +176,11 @@ void mbedtls_ccm_free(mbedtls_ccm_context *ctx); * \return \c 0 on success. * \return A CCM or cipher-specific error code on failure. */ -int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, unsigned char *output, - unsigned char *tag, size_t tag_len); +int mbedtls_ccm_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, unsigned char *output, + unsigned char *tag, size_t tag_len ); /** * \brief This function encrypts a buffer using CCM*. @@ -219,11 +225,11 @@ int mbedtls_ccm_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, * \return \c 0 on success. * \return A CCM or cipher-specific error code on failure. */ -int mbedtls_ccm_star_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, unsigned char *output, - unsigned char *tag, size_t tag_len); +int mbedtls_ccm_star_encrypt_and_tag( mbedtls_ccm_context *ctx, size_t length, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, unsigned char *output, + unsigned char *tag, size_t tag_len ); /** * \brief This function performs a CCM authenticated decryption of a @@ -256,11 +262,11 @@ int mbedtls_ccm_star_encrypt_and_tag(mbedtls_ccm_context *ctx, size_t length, * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. * \return A cipher-specific error code on calculation failure. */ -int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, unsigned char *output, - const unsigned char *tag, size_t tag_len); +int mbedtls_ccm_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, unsigned char *output, + const unsigned char *tag, size_t tag_len ); /** * \brief This function performs a CCM* authenticated decryption of a @@ -302,11 +308,11 @@ int mbedtls_ccm_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, * \return #MBEDTLS_ERR_CCM_AUTH_FAILED if the tag does not match. * \return A cipher-specific error code on calculation failure. */ -int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, unsigned char *output, - const unsigned char *tag, size_t tag_len); +int mbedtls_ccm_star_auth_decrypt( mbedtls_ccm_context *ctx, size_t length, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, unsigned char *output, + const unsigned char *tag, size_t tag_len ); /** * \brief This function starts a CCM encryption or decryption @@ -336,10 +342,10 @@ int mbedtls_ccm_star_auth_decrypt(mbedtls_ccm_context *ctx, size_t length, * \p iv_len is invalid (lower than \c 7 or greater than * \c 13). */ -int mbedtls_ccm_starts(mbedtls_ccm_context *ctx, - int mode, - const unsigned char *iv, - size_t iv_len); +int mbedtls_ccm_starts( mbedtls_ccm_context *ctx, + int mode, + const unsigned char *iv, + size_t iv_len ); /** * \brief This function declares the lengths of the message @@ -368,10 +374,10 @@ int mbedtls_ccm_starts(mbedtls_ccm_context *ctx, * \p ctx is in an invalid state, * \p total_ad_len is greater than \c 0xFF00. */ -int mbedtls_ccm_set_lengths(mbedtls_ccm_context *ctx, - size_t total_ad_len, - size_t plaintext_len, - size_t tag_len); +int mbedtls_ccm_set_lengths( mbedtls_ccm_context *ctx, + size_t total_ad_len, + size_t plaintext_len, + size_t tag_len ); /** * \brief This function feeds an input buffer as associated data @@ -403,9 +409,9 @@ int mbedtls_ccm_set_lengths(mbedtls_ccm_context *ctx, * \p ctx is in an invalid state, * total input length too long. */ -int mbedtls_ccm_update_ad(mbedtls_ccm_context *ctx, - const unsigned char *ad, - size_t ad_len); +int mbedtls_ccm_update_ad( mbedtls_ccm_context *ctx, + const unsigned char *ad, + size_t ad_len ); /** * \brief This function feeds an input buffer into an ongoing CCM @@ -470,10 +476,10 @@ int mbedtls_ccm_update_ad(mbedtls_ccm_context *ctx, * total input length too long, * or \p output_size too small. */ -int mbedtls_ccm_update(mbedtls_ccm_context *ctx, - const unsigned char *input, size_t input_len, - unsigned char *output, size_t output_size, - size_t *output_len); +int mbedtls_ccm_update( mbedtls_ccm_context *ctx, + const unsigned char *input, size_t input_len, + unsigned char *output, size_t output_size, + size_t *output_len ); /** * \brief This function finishes the CCM operation and generates @@ -506,17 +512,17 @@ int mbedtls_ccm_update(mbedtls_ccm_context *ctx, * mbedtls_ccm_update() was lower than the plaintext length * \c plaintext_len passed to mbedtls_ccm_set_lengths(). */ -int mbedtls_ccm_finish(mbedtls_ccm_context *ctx, - unsigned char *tag, size_t tag_len); +int mbedtls_ccm_finish( mbedtls_ccm_context *ctx, + unsigned char *tag, size_t tag_len ); -#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_CCM_GCM_CAN_AES) +#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) /** * \brief The CCM checkup routine. * * \return \c 0 on success. * \return \c 1 on failure. */ -int mbedtls_ccm_self_test(int verbose); +int mbedtls_ccm_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ #ifdef __cplusplus diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/check_config.h b/src/duckdb/third_party/mbedtls/include/mbedtls/check_config.h index 67a05f83b..ce97f6a35 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/check_config.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/check_config.h @@ -2,48 +2,53 @@ * \file check_config.h * * \brief Consistency checks for configuration options - * - * This is an internal header. Do not include it directly. - * - * This header is included automatically by all public Mbed TLS headers - * (via mbedtls/build_info.h). Do not include it directly in a configuration - * file such as mbedtls/mbedtls_config.h or #MBEDTLS_USER_CONFIG_FILE! - * It would run at the wrong time due to missing derived symbols. */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_CHECK_CONFIG_H #define MBEDTLS_CHECK_CONFIG_H -/* *INDENT-OFF* */ - -#if !defined(MBEDTLS_CONFIG_IS_FINALIZED) -#warning "Do not include mbedtls/check_config.h manually! " \ - "This may cause spurious errors. " \ - "It is included automatically at the right point since Mbed TLS 3.0." -#endif /* !MBEDTLS_CONFIG_IS_FINALIZED */ - /* * We assume CHAR_BIT is 8 in many places. In practice, this is true on our * target platforms, so not an issue, but let's just be extra sure. */ #include #if CHAR_BIT != 8 -#error "Mbed TLS requires a platform with 8-bit chars" +#error "mbed TLS requires a platform with 8-bit chars" #endif -#include - -#if defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER <= 1900) +#if defined(_WIN32) #if !defined(MBEDTLS_PLATFORM_C) #error "MBEDTLS_PLATFORM_C is required on Windows" #endif -/* See auto-enabling SNPRINTF_ALT and VSNPRINTF_ALT - * in * config_adjust_legacy_crypto.h */ -#endif /* _MINGW32__ || (_MSC_VER && (_MSC_VER <= 1900)) */ + +/* Fix the config here. Not convenient to put an #ifdef _WIN32 in mbedtls_config.h as + * it would confuse config.py. */ +#if !defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) && \ + !defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) +#define MBEDTLS_PLATFORM_SNPRINTF_ALT +#endif + +#if !defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) && \ + !defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) +#define MBEDTLS_PLATFORM_VSNPRINTF_ALT +#endif +#endif /* _WIN32 */ #if defined(TARGET_LIKE_MBED) && defined(MBEDTLS_NET_C) #error "The NET module is not available for mbed OS - please use the network functions provided by Mbed OS" @@ -58,49 +63,11 @@ #error "MBEDTLS_HAVE_TIME_DATE without MBEDTLS_HAVE_TIME does not make sense" #endif -/* Limitations on ECC key types acceleration: if we have any of `PUBLIC_KEY`, - * `KEY_PAIR_BASIC`, `KEY_PAIR_IMPORT`, `KEY_PAIR_EXPORT` then we must have - * all 4 of them. - */ -#if defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) || \ - defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC) || \ - defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT) || \ - defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT) -#if !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) || \ - !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_BASIC) || \ - !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_IMPORT) || \ - !defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR_EXPORT) -#error "Unsupported partial support for ECC key type acceleration, see docs/driver-only-builds.md" -#endif /* not all of public, basic, import, export */ -#endif /* one of public, basic, import, export */ - -/* Limitations on ECC curves acceleration: partial curve acceleration is only - * supported with crypto excluding PK, X.509 or TLS. - * Note: no need to check X.509 as it depends on PK. */ -#if defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_256) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_384) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_BRAINPOOL_P_R1_512) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_255) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_MONTGOMERY_448) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_192) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_224) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_K1_256) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_192) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_224) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_256) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_384) || \ - defined(MBEDTLS_PSA_ACCEL_ECC_SECP_R1_521) -#if defined(MBEDTLS_PSA_ECC_ACCEL_INCOMPLETE_CURVES) -#if defined(MBEDTLS_PK_C) || \ - defined(MBEDTLS_SSL_TLS_C) -#error "Unsupported partial support for ECC curves acceleration, see docs/driver-only-builds.md" -#endif /* modules beyond what's supported */ -#endif /* not all curves accelerated */ -#endif /* some curve accelerated */ - -#if defined(MBEDTLS_CTR_DRBG_C) && !(defined(MBEDTLS_AES_C) || \ - (defined(MBEDTLS_PSA_CRYPTO_CLIENT) && defined(PSA_WANT_KEY_TYPE_AES) && \ - defined(PSA_WANT_ALG_ECB_NO_PADDING))) +#if defined(MBEDTLS_AESNI_C) && !defined(MBEDTLS_HAVE_ASM) +#error "MBEDTLS_AESNI_C defined, but not all prerequisites" +#endif + +#if defined(MBEDTLS_CTR_DRBG_C) && !defined(MBEDTLS_AES_C) #error "MBEDTLS_CTR_DRBG_C defined, but not all prerequisites" #endif @@ -109,7 +76,7 @@ #endif #if defined(MBEDTLS_CMAC_C) && \ - ( !defined(MBEDTLS_CIPHER_C ) || ( !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C) ) ) + !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_DES_C) #error "MBEDTLS_CMAC_C defined, but not all prerequisites" #endif @@ -118,36 +85,6 @@ #error "MBEDTLS_NIST_KW_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) && defined(MBEDTLS_PSA_CRYPTO_CONFIG) -#if defined(PSA_WANT_ALG_CBC_NO_PADDING) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_ALG_CBC_NO_PADDING cannot be defined simultaneously" -#endif -#if defined(PSA_WANT_ALG_CBC_PKCS7) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_ALG_CBC_PKCS7 cannot be defined simultaneously" -#endif -#if defined(PSA_WANT_ALG_ECB_NO_PADDING) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_ALG_ECB_NO_PADDING cannot be defined simultaneously" -#endif -#if defined(PSA_WANT_KEY_TYPE_DES) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and PSA_WANT_KEY_TYPE_DES cannot be defined simultaneously" -#endif -#endif - -#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -#if defined(MBEDTLS_CIPHER_MODE_CBC) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_CIPHER_MODE_CBC cannot be defined simultaneously" -#endif -#if defined(MBEDTLS_CIPHER_MODE_XTS) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_CIPHER_MODE_XTS cannot be defined simultaneously" -#endif -#if defined(MBEDTLS_DES_C) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_DES_C cannot be defined simultaneously" -#endif -#if defined(MBEDTLS_NIST_KW_C) -#error "MBEDTLS_BLOCK_CIPHER_NO_DECRYPT and MBEDTLS_NIST_KW_C cannot be defined simultaneously" -#endif -#endif - #if defined(MBEDTLS_ECDH_C) && !defined(MBEDTLS_ECP_C) #error "MBEDTLS_ECDH_C defined, but not all prerequisites" #endif @@ -170,41 +107,28 @@ #error "MBEDTLS_ECDSA_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PK_C) && defined(MBEDTLS_USE_PSA_CRYPTO) -#if defined(MBEDTLS_PK_CAN_ECDSA_SIGN) && !defined(MBEDTLS_ASN1_WRITE_C) -#error "MBEDTLS_PK_C with MBEDTLS_USE_PSA_CRYPTO needs MBEDTLS_ASN1_WRITE_C for ECDSA signature" -#endif -#if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) && !defined(MBEDTLS_ASN1_PARSE_C) -#error "MBEDTLS_PK_C with MBEDTLS_USE_PSA_CRYPTO needs MBEDTLS_ASN1_PARSE_C for ECDSA verification" -#endif -#endif /* MBEDTLS_PK_C && MBEDTLS_USE_PSA_CRYPTO */ - -#if defined(MBEDTLS_ECJPAKE_C) && \ - !defined(MBEDTLS_ECP_C) +#if defined(MBEDTLS_ECJPAKE_C) && \ + ( !defined(MBEDTLS_ECP_C) || !defined(MBEDTLS_MD_C) ) #error "MBEDTLS_ECJPAKE_C defined, but not all prerequisites" #endif #if defined(MBEDTLS_ECP_RESTARTABLE) && \ - ( defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) || \ + defined(MBEDTLS_ECDH_COMPUTE_SHARED_ALT) || \ defined(MBEDTLS_ECDH_GEN_PUBLIC_ALT) || \ defined(MBEDTLS_ECDSA_SIGN_ALT) || \ defined(MBEDTLS_ECDSA_VERIFY_ALT) || \ defined(MBEDTLS_ECDSA_GENKEY_ALT) || \ defined(MBEDTLS_ECP_INTERNAL_ALT) || \ defined(MBEDTLS_ECP_ALT) ) -#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative ECP implementation" -#endif - -#if defined(MBEDTLS_ECP_RESTARTABLE) && \ - !defined(MBEDTLS_ECP_C) -#error "MBEDTLS_ECP_RESTARTABLE defined, but not all prerequisites" +#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative or PSA-based ECP implementation" #endif #if defined(MBEDTLS_ECDSA_DETERMINISTIC) && !defined(MBEDTLS_HMAC_DRBG_C) #error "MBEDTLS_ECDSA_DETERMINISTIC defined, but not all prerequisites" #endif -#if defined(MBEDTLS_ECP_LIGHT) && ( !defined(MBEDTLS_BIGNUM_C) || ( \ +#if defined(MBEDTLS_ECP_C) && ( !defined(MBEDTLS_BIGNUM_C) || ( \ !defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) && \ !defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) && \ !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) && \ @@ -218,57 +142,46 @@ !defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) && \ !defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) && \ !defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) ) ) -#error "MBEDTLS_ECP_C defined (or a subset enabled), but not all prerequisites" +#error "MBEDTLS_ECP_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_ENTROPY_C) && \ - !(defined(MBEDTLS_MD_CAN_SHA512) || defined(MBEDTLS_MD_CAN_SHA256)) +#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_ASN1_PARSE_C) +#error "MBEDTLS_PK_PARSE_C defined, but not all prerequesites" +#endif + +#if defined(MBEDTLS_ENTROPY_C) && (!defined(MBEDTLS_SHA512_C) && \ + !defined(MBEDTLS_SHA256_C)) #error "MBEDTLS_ENTROPY_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_ENTROPY_C) && \ +#if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_SHA512_C) && \ defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 64) #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high" #endif #if defined(MBEDTLS_ENTROPY_C) && \ - (defined(MBEDTLS_ENTROPY_FORCE_SHA256) || !defined(MBEDTLS_MD_CAN_SHA512)) \ + ( !defined(MBEDTLS_SHA512_C) || defined(MBEDTLS_ENTROPY_FORCE_SHA256) ) \ && defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) && (MBEDTLS_CTR_DRBG_ENTROPY_LEN > 32) #error "MBEDTLS_CTR_DRBG_ENTROPY_LEN value too high" #endif #if defined(MBEDTLS_ENTROPY_C) && \ - defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_MD_CAN_SHA256) + defined(MBEDTLS_ENTROPY_FORCE_SHA256) && !defined(MBEDTLS_SHA256_C) #error "MBEDTLS_ENTROPY_FORCE_SHA256 defined, but not all prerequisites" #endif #if defined(__has_feature) #if __has_feature(memory_sanitizer) -#define MBEDTLS_HAS_MEMSAN // #undef at the end of this paragraph +#define MBEDTLS_HAS_MEMSAN #endif #endif #if defined(MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN) && !defined(MBEDTLS_HAS_MEMSAN) #error "MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN requires building with MemorySanitizer" #endif -#undef MBEDTLS_HAS_MEMSAN // temporary macro defined above - -#if defined(MBEDTLS_CCM_C) && \ - !(defined(MBEDTLS_CCM_GCM_CAN_AES) || defined(MBEDTLS_CCM_GCM_CAN_ARIA) || \ - defined(MBEDTLS_CCM_GCM_CAN_CAMELLIA)) -#error "MBEDTLS_CCM_C defined, but not all prerequisites" -#endif +#undef MBEDTLS_HAS_MEMSAN -#if defined(MBEDTLS_GCM_C) && \ - !(defined(MBEDTLS_CCM_GCM_CAN_AES) || defined(MBEDTLS_CCM_GCM_CAN_ARIA) || \ - defined(MBEDTLS_CCM_GCM_CAN_CAMELLIA)) +#if defined(MBEDTLS_GCM_C) && ( \ + !defined(MBEDTLS_AES_C) && !defined(MBEDTLS_CAMELLIA_C) && !defined(MBEDTLS_ARIA_C) ) #error "MBEDTLS_GCM_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_CHACHAPOLY_C) && !defined(MBEDTLS_CHACHA20_C) -#error "MBEDTLS_CHACHAPOLY_C defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_CHACHAPOLY_C) && !defined(MBEDTLS_POLY1305_C) -#error "MBEDTLS_CHACHAPOLY_C defined, but not all prerequisites" -#endif - #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT) #error "MBEDTLS_ECP_RANDOMIZE_JAC_ALT defined, but not all prerequisites" #endif @@ -314,14 +227,13 @@ #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) && \ - ( !defined(MBEDTLS_CAN_ECDH) || \ - !defined(MBEDTLS_PK_CAN_ECDSA_SIGN) || \ + ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \ !defined(MBEDTLS_X509_CRT_PARSE_C) ) #error "MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED defined, but not all prerequisites" #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \ - ( !defined(MBEDTLS_CAN_ECDH) || !defined(MBEDTLS_RSA_C) || \ + ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \ !defined(MBEDTLS_X509_CRT_PARSE_C) ) #error "MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED defined, but not all prerequisites" #endif @@ -331,7 +243,7 @@ #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED) && \ - !defined(MBEDTLS_CAN_ECDH) + !defined(MBEDTLS_ECDH_C) #error "MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED defined, but not all prerequisites" #endif @@ -342,14 +254,13 @@ #endif #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \ - ( !defined(MBEDTLS_CAN_ECDH) || !defined(MBEDTLS_RSA_C) || \ + ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_RSA_C) || \ !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_PKCS1_V15) ) #error "MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED defined, but not all prerequisites" #endif -#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \ - ( !defined(MBEDTLS_CAN_ECDH) || \ - !defined(MBEDTLS_PK_CAN_ECDSA_SIGN) || \ +#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) && \ + ( !defined(MBEDTLS_ECDH_C) || !defined(MBEDTLS_ECDSA_C) || \ !defined(MBEDTLS_X509_CRT_PARSE_C) ) #error "MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED defined, but not all prerequisites" #endif @@ -366,58 +277,18 @@ #error "MBEDTLS_KEY_EXCHANGE_RSA_ENABLED defined, but not all prerequisites" #endif -#if defined(MBEDTLS_USE_PSA_CRYPTO) -#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \ - ( !defined(PSA_WANT_ALG_JPAKE) || \ - !defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC) || \ - !defined(PSA_WANT_ECC_SECP_R1_256) ) -#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites" -#endif -#else /* MBEDTLS_USE_PSA_CRYPTO */ -#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \ - ( !defined(MBEDTLS_ECJPAKE_C) || \ - !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) ) -#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites" -#endif -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - -/* Use of EC J-PAKE in TLS requires SHA-256. */ #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \ - !defined(MBEDTLS_MD_CAN_SHA256) + ( !defined(MBEDTLS_ECJPAKE_C) || !defined(MBEDTLS_SHA256_C) || \ + !defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) ) #error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites" #endif #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \ - !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) && \ - !defined(MBEDTLS_MD_CAN_SHA256) && \ - !defined(MBEDTLS_MD_CAN_SHA512) && \ - !defined(MBEDTLS_MD_CAN_SHA1) -#error "!MBEDTLS_SSL_KEEP_PEER_CERTIFICATE requires SHA-512, SHA-256 or SHA-1". -#endif - -#if defined(MBEDTLS_MD_C) && \ - !defined(MBEDTLS_MD_CAN_MD5) && \ - !defined(MBEDTLS_MD_CAN_RIPEMD160) && \ - !defined(MBEDTLS_MD_CAN_SHA1) && \ - !defined(MBEDTLS_MD_CAN_SHA224) && \ - !defined(MBEDTLS_MD_CAN_SHA256) && \ - !defined(MBEDTLS_MD_CAN_SHA384) && \ - !defined(MBEDTLS_MD_CAN_SHA512) && \ - !defined(MBEDTLS_MD_CAN_SHA3_224) && \ - !defined(MBEDTLS_MD_CAN_SHA3_256) && \ - !defined(MBEDTLS_MD_CAN_SHA3_384) && \ - !defined(MBEDTLS_MD_CAN_SHA3_512) -#error "MBEDTLS_MD_C defined, but no hash algorithm" -#endif - -#if defined(MBEDTLS_LMS_C) && \ - ! ( defined(MBEDTLS_PSA_CRYPTO_CLIENT) && defined(PSA_WANT_ALG_SHA_256) ) -#error "MBEDTLS_LMS_C requires MBEDTLS_PSA_CRYPTO_C and PSA_WANT_ALG_SHA_256" -#endif - -#if defined(MBEDTLS_LMS_PRIVATE) && \ - ( !defined(MBEDTLS_LMS_C) ) -#error "MBEDTLS_LMS_PRIVATE requires MBEDTLS_LMS_C" + !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) && \ + ( !defined(MBEDTLS_SHA256_C) && \ + !defined(MBEDTLS_SHA512_C) && \ + !defined(MBEDTLS_SHA1_C) ) +#error "!MBEDTLS_SSL_KEEP_PEER_CERTIFICATE requires MBEDTLS_SHA512_C, MBEDTLS_SHA256_C or MBEDTLS_SHA1_C" #endif #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \ @@ -426,11 +297,15 @@ #endif #if defined(MBEDTLS_MEMORY_BACKTRACE) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) -#error "MBEDTLS_MEMORY_BACKTRACE defined, but not all prerequisites" +#error "MBEDTLS_MEMORY_BACKTRACE defined, but not all prerequesites" #endif #if defined(MBEDTLS_MEMORY_DEBUG) && !defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) -#error "MBEDTLS_MEMORY_DEBUG defined, but not all prerequisites" +#error "MBEDTLS_MEMORY_DEBUG defined, but not all prerequesites" +#endif + +#if defined(MBEDTLS_PADLOCK_C) && !defined(MBEDTLS_HAVE_ASM) +#error "MBEDTLS_PADLOCK_C defined, but not all prerequisites" #endif #if defined(MBEDTLS_PEM_PARSE_C) && !defined(MBEDTLS_BASE64_C) @@ -442,21 +317,15 @@ #endif #if defined(MBEDTLS_PK_C) && \ - !defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_PK_HAVE_ECC_KEYS) + ( !defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_ECP_C) ) #error "MBEDTLS_PK_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PK_PARSE_C) && \ - (!defined(MBEDTLS_ASN1_PARSE_C) || \ - !defined(MBEDTLS_OID_C) || \ - !defined(MBEDTLS_PK_C)) +#if defined(MBEDTLS_PK_PARSE_C) && !defined(MBEDTLS_PK_C) #error "MBEDTLS_PK_PARSE_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PK_WRITE_C) && \ - (!defined(MBEDTLS_ASN1_WRITE_C) || \ - !defined(MBEDTLS_OID_C) || \ - !defined(MBEDTLS_PK_C)) +#if defined(MBEDTLS_PK_WRITE_C) && !defined(MBEDTLS_PK_C) #error "MBEDTLS_PK_WRITE_C defined, but not all prerequisites" #endif @@ -474,20 +343,6 @@ #error "MBEDTLS_PLATFORM_EXIT_MACRO and MBEDTLS_PLATFORM_STD_EXIT/MBEDTLS_PLATFORM_EXIT_ALT cannot be defined simultaneously" #endif -#if defined(MBEDTLS_PLATFORM_SETBUF_ALT) && !defined(MBEDTLS_PLATFORM_C) -#error "MBEDTLS_PLATFORM_SETBUF_ALT defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_PLATFORM_SETBUF_MACRO) && !defined(MBEDTLS_PLATFORM_C) -#error "MBEDTLS_PLATFORM_SETBUF_MACRO defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_PLATFORM_SETBUF_MACRO) &&\ - ( defined(MBEDTLS_PLATFORM_STD_SETBUF) ||\ - defined(MBEDTLS_PLATFORM_SETBUF_ALT) ) -#error "MBEDTLS_PLATFORM_SETBUF_MACRO and MBEDTLS_PLATFORM_STD_SETBUF/MBEDTLS_PLATFORM_SETBUF_ALT cannot be defined simultaneously" -#endif - #if defined(MBEDTLS_PLATFORM_TIME_ALT) &&\ ( !defined(MBEDTLS_PLATFORM_C) ||\ !defined(MBEDTLS_HAVE_TIME) ) @@ -500,16 +355,6 @@ #error "MBEDTLS_PLATFORM_TIME_MACRO defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO) &&\ - ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_HAVE_TIME) ) -#error "MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_PLATFORM_MS_TIME_ALT) && \ - ( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_HAVE_TIME) ) -#error "MBEDTLS_PLATFORM_MS_TIME_ALT defined, but not all prerequisites" -#endif - #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO) &&\ ( !defined(MBEDTLS_PLATFORM_C) ||\ !defined(MBEDTLS_HAVE_TIME) ) @@ -602,20 +447,6 @@ #error "MBEDTLS_PLATFORM_SNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_SNPRINTF/MBEDTLS_PLATFORM_SNPRINTF_ALT cannot be defined simultaneously" #endif -#if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) && !defined(MBEDTLS_PLATFORM_C) -#error "MBEDTLS_PLATFORM_VSNPRINTF_ALT defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) && !defined(MBEDTLS_PLATFORM_C) -#error "MBEDTLS_PLATFORM_VSNPRINTF_MACRO defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) &&\ - ( defined(MBEDTLS_PLATFORM_STD_VSNPRINTF) ||\ - defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) ) -#error "MBEDTLS_PLATFORM_VSNPRINTF_MACRO and MBEDTLS_PLATFORM_STD_VSNPRINTF/MBEDTLS_PLATFORM_VSNPRINTF_ALT cannot be defined simultaneously" -#endif - #if defined(MBEDTLS_PLATFORM_STD_MEM_HDR) &&\ !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) #error "MBEDTLS_PLATFORM_STD_MEM_HDR defined, but not all prerequisites" @@ -694,11 +525,6 @@ #error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites (missing RNG)" #endif -#if defined(MBEDTLS_PSA_CRYPTO_C) && defined(PSA_HAVE_SOFT_BLOCK_MODE) && \ - defined(PSA_HAVE_SOFT_BLOCK_CIPHER) && !defined(MBEDTLS_CIPHER_C) -#error "MBEDTLS_PSA_CRYPTO_C defined, but not all prerequisites" -#endif - #if defined(MBEDTLS_PSA_CRYPTO_SPM) && !defined(MBEDTLS_PSA_CRYPTO_C) #error "MBEDTLS_PSA_CRYPTO_SPM defined, but not all prerequisites" #endif @@ -709,14 +535,6 @@ #error "MBEDTLS_PSA_CRYPTO_SE_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_PSA_CRYPTO_SE_C) -#if defined(MBEDTLS_DEPRECATED_REMOVED) -#error "MBEDTLS_PSA_CRYPTO_SE_C is deprecated and will be removed in a future version of Mbed TLS" -#elif defined(MBEDTLS_DEPRECATED_WARNING) -#warning "MBEDTLS_PSA_CRYPTO_SE_C is deprecated and will be removed in a future version of Mbed TLS" -#endif -#endif /* MBEDTLS_PSA_CRYPTO_SE_C */ - #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) && \ ! defined(MBEDTLS_PSA_CRYPTO_C) #error "MBEDTLS_PSA_CRYPTO_STORAGE_C defined, but not all prerequisites" @@ -743,6 +561,11 @@ #error "MBEDTLS_PSA_ITS_FILE_C defined, but not all prerequisites" #endif +#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER) && \ + defined(MBEDTLS_USE_PSA_CRYPTO) +#error "MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER defined, but it cannot coexist with MBEDTLS_USE_PSA_CRYPTO." +#endif + #if defined(MBEDTLS_RSA_C) && ( !defined(MBEDTLS_BIGNUM_C) || \ !defined(MBEDTLS_OID_C) ) #error "MBEDTLS_RSA_C defined, but not all prerequisites" @@ -758,79 +581,33 @@ #error "MBEDTLS_X509_RSASSA_PSS_SUPPORT defined, but not all prerequisites" #endif -#if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) && \ - defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY) -#error "Must only define one of MBEDTLS_SHA512_USE_A64_CRYPTO_*" +#if defined(MBEDTLS_SHA384_C) && !defined(MBEDTLS_SHA512_C) +#error "MBEDTLS_SHA384_C defined without MBEDTLS_SHA512_C" #endif -#if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT) || \ - defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY) -#if !defined(MBEDTLS_SHA512_C) -#error "MBEDTLS_SHA512_USE_A64_CRYPTO_* defined without MBEDTLS_SHA512_C" -#endif -#if defined(MBEDTLS_SHA512_ALT) || defined(MBEDTLS_SHA512_PROCESS_ALT) -#error "MBEDTLS_SHA512_*ALT can't be used with MBEDTLS_SHA512_USE_A64_CRYPTO_*" -#endif - -#endif /* MBEDTLS_SHA512_USE_A64_CRYPTO_IF_PRESENT || MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY */ - -#if defined(MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY) && !defined(__aarch64__) -#error "MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY defined on non-Aarch64 system" +#if defined(MBEDTLS_SHA224_C) && !defined(MBEDTLS_SHA256_C) +#error "MBEDTLS_SHA224_C defined without MBEDTLS_SHA256_C" #endif -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) && \ - defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) -#error "Must only define one of MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*" +#if defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA224_C) +#error "MBEDTLS_SHA256_C defined without MBEDTLS_SHA224_C" #endif -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \ - defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) -#if !defined(MBEDTLS_SHA256_C) -#error "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_* defined without MBEDTLS_SHA256_C" -#endif -#if defined(MBEDTLS_SHA256_ALT) || defined(MBEDTLS_SHA256_PROCESS_ALT) -#error "MBEDTLS_SHA256_*ALT can't be used with MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*" -#endif - -#endif - -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) && !defined(MBEDTLS_ARCH_IS_ARMV8_A) -#error "MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY defined on non-Armv8-A system" -#endif - -/* TLS 1.3 requires separate HKDF parts from PSA, - * and at least one ciphersuite, so at least SHA-256 or SHA-384 - * from PSA to use with HKDF. - * - * Note: for dependencies common with TLS 1.2 (running handshake hash), - * see MBEDTLS_SSL_TLS_C. */ -#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && \ - !(defined(MBEDTLS_PSA_CRYPTO_CLIENT) && \ - defined(PSA_WANT_ALG_HKDF_EXTRACT) && \ - defined(PSA_WANT_ALG_HKDF_EXPAND) && \ - (defined(PSA_WANT_ALG_SHA_256) || defined(PSA_WANT_ALG_SHA_384))) -#error "MBEDTLS_SSL_PROTO_TLS1_3 defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED) -#if !( (defined(PSA_WANT_ALG_ECDH) || defined(PSA_WANT_ALG_FFDH)) && \ - defined(MBEDTLS_X509_CRT_PARSE_C) && \ - ( defined(MBEDTLS_PK_CAN_ECDSA_SIGN) || defined(MBEDTLS_PKCS1_V21) ) ) -#error "MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED defined, but not all prerequisites" -#endif -#endif - -#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED) -#if !( defined(PSA_WANT_ALG_ECDH) || defined(PSA_WANT_ALG_FFDH) ) -#error "MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED defined, but not all prerequisites" -#endif +#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && ( !defined(MBEDTLS_SHA1_C) && \ + !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA512_C) ) +#error "MBEDTLS_SSL_PROTO_TLS1_2 defined, but not all prerequisites" #endif /* - * The current implementation of TLS 1.3 requires MBEDTLS_SSL_KEEP_PEER_CERTIFICATE. + * HKDF is mandatory for TLS 1.3. + * Otherwise support for at least one ciphersuite mandates either SHA_256 or + * SHA_384. */ -#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) -#error "MBEDTLS_SSL_PROTO_TLS1_3 defined without MBEDTLS_SSL_KEEP_PEER_CERTIFICATE" +#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && \ + ( ( !defined(MBEDTLS_HKDF_C) ) || \ + ( !defined(MBEDTLS_SHA256_C) && !defined(MBEDTLS_SHA384_C) ) || \ + ( !defined(MBEDTLS_PSA_CRYPTO_C) ) ) +#error "MBEDTLS_SSL_PROTO_TLS1_3 defined, but not all prerequisites" #endif #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ @@ -849,20 +626,6 @@ "but no key exchange methods defined with MBEDTLS_KEY_EXCHANGE_xxxx" #endif -#if defined(MBEDTLS_SSL_EARLY_DATA) && \ - ( !defined(MBEDTLS_SSL_SESSION_TICKETS) || \ - ( !defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ENABLED) && \ - !defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED) ) ) -#error "MBEDTLS_SSL_EARLY_DATA defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_SRV_C) && \ - defined(MBEDTLS_SSL_MAX_EARLY_DATA_SIZE) && \ - ((MBEDTLS_SSL_MAX_EARLY_DATA_SIZE < 0) || \ - (MBEDTLS_SSL_MAX_EARLY_DATA_SIZE > UINT32_MAX)) -#error "MBEDTLS_SSL_MAX_EARLY_DATA_SIZE must be in the range(0..UINT32_MAX)" -#endif - #if defined(MBEDTLS_SSL_PROTO_DTLS) && \ !defined(MBEDTLS_SSL_PROTO_TLS1_2) #error "MBEDTLS_SSL_PROTO_DTLS defined, but not all prerequisites" @@ -872,35 +635,16 @@ #error "MBEDTLS_SSL_CLI_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_SSL_ASYNC_PRIVATE) && !defined(MBEDTLS_X509_CRT_PARSE_C) -#error "MBEDTLS_SSL_ASYNC_PRIVATE defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_SSL_TLS_C) && !(defined(MBEDTLS_CIPHER_C) || \ - defined(MBEDTLS_USE_PSA_CRYPTO)) +#if defined(MBEDTLS_SSL_TLS_C) && ( !defined(MBEDTLS_CIPHER_C) || \ + !defined(MBEDTLS_MD_C) ) #error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites" #endif -/* TLS 1.2 and 1.3 require SHA-256 or SHA-384 (running handshake hash) */ -#if defined(MBEDTLS_SSL_TLS_C) -#if defined(MBEDTLS_USE_PSA_CRYPTO) -#if !(defined(PSA_WANT_ALG_SHA_256) || defined(PSA_WANT_ALG_SHA_384)) -#error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites" -#endif -#else /* MBEDTLS_USE_PSA_CRYPTO */ -#if !defined(MBEDTLS_MD_C) || \ - !(defined(MBEDTLS_MD_CAN_SHA256) || defined(MBEDTLS_MD_CAN_SHA384)) -#error "MBEDTLS_SSL_TLS_C defined, but not all prerequisites" -#endif -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#endif /* MBEDTLS_SSL_TLS_C */ - #if defined(MBEDTLS_SSL_SRV_C) && !defined(MBEDTLS_SSL_TLS_C) #error "MBEDTLS_SSL_SRV_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_SSL_TLS_C) && \ - !( defined(MBEDTLS_SSL_PROTO_TLS1_2) || defined(MBEDTLS_SSL_PROTO_TLS1_3) ) +#if defined(MBEDTLS_SSL_TLS_C) && !defined(MBEDTLS_SSL_PROTO_TLS1_2) #error "MBEDTLS_SSL_TLS_C defined, but no protocols are active" #endif @@ -935,50 +679,20 @@ #error "MBEDTLS_SSL_CID_OUT_LEN_MAX too large (max 255)" #endif -#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT) && \ - !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) -#error "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT) && MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT != 0 -#if defined(MBEDTLS_DEPRECATED_REMOVED) -#error "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT is deprecated and will be removed in a future version of Mbed TLS" -#elif defined(MBEDTLS_DEPRECATED_WARNING) -#warning "MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT is deprecated and will be removed in a future version of Mbed TLS" -#endif -#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT && MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT != 0 */ - #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \ !defined(MBEDTLS_SSL_PROTO_TLS1_2) -#error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequisites" +#error "MBEDTLS_SSL_ENCRYPT_THEN_MAC defined, but not all prerequsites" #endif #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET) && \ !defined(MBEDTLS_SSL_PROTO_TLS1_2) -#error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequisites" +#error "MBEDTLS_SSL_EXTENDED_MASTER_SECRET defined, but not all prerequsites" #endif -#if defined(MBEDTLS_SSL_RENEGOTIATION) && \ - !defined(MBEDTLS_SSL_PROTO_TLS1_2) -#error "MBEDTLS_SSL_RENEGOTIATION defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_SSL_TICKET_C) && ( !defined(MBEDTLS_CIPHER_C) && \ - !defined(MBEDTLS_USE_PSA_CRYPTO) ) -#error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites" -#endif - -#if defined(MBEDTLS_SSL_TICKET_C) && \ - !( defined(MBEDTLS_SSL_HAVE_CCM) || defined(MBEDTLS_SSL_HAVE_GCM) || \ - defined(MBEDTLS_SSL_HAVE_CHACHAPOLY) ) +#if defined(MBEDTLS_SSL_TICKET_C) && !defined(MBEDTLS_CIPHER_C) #error "MBEDTLS_SSL_TICKET_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH) && \ - MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH >= 256 -#error "MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH must be less than 256" -#endif - #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \ !defined(MBEDTLS_X509_CRT_PARSE_C) #error "MBEDTLS_SSL_SERVER_NAME_INDICATION defined, but not all prerequisites" @@ -988,20 +702,22 @@ #if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL) #error "MBEDTLS_THREADING_PTHREAD defined, but not all prerequisites" #endif -#define MBEDTLS_THREADING_IMPL // undef at the end of this paragraph +#define MBEDTLS_THREADING_IMPL #endif + #if defined(MBEDTLS_THREADING_ALT) #if !defined(MBEDTLS_THREADING_C) || defined(MBEDTLS_THREADING_IMPL) #error "MBEDTLS_THREADING_ALT defined, but not all prerequisites" #endif -#define MBEDTLS_THREADING_IMPL // undef at the end of this paragraph +#define MBEDTLS_THREADING_IMPL #endif + #if defined(MBEDTLS_THREADING_C) && !defined(MBEDTLS_THREADING_IMPL) #error "MBEDTLS_THREADING_C defined, single threading implementation required" #endif -#undef MBEDTLS_THREADING_IMPL // temporary macro defined above +#undef MBEDTLS_THREADING_IMPL -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_PSA_CRYPTO_CLIENT) +#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_PSA_CRYPTO_C) #error "MBEDTLS_USE_PSA_CRYPTO defined, but not all prerequisites" #endif @@ -1009,17 +725,15 @@ #error "MBEDTLS_VERSION_FEATURES defined, but not all prerequisites" #endif -#if defined(MBEDTLS_X509_USE_C) && \ - (!defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \ - !defined(MBEDTLS_PK_PARSE_C) || \ - ( !defined(MBEDTLS_MD_C) && !defined(MBEDTLS_USE_PSA_CRYPTO) ) ) +#if defined(MBEDTLS_X509_USE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \ + !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_PARSE_C) || \ + !defined(MBEDTLS_PK_PARSE_C) ) #error "MBEDTLS_X509_USE_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_X509_CREATE_C) && \ - (!defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || \ - !defined(MBEDTLS_PK_PARSE_C) || \ - ( !defined(MBEDTLS_MD_C) && !defined(MBEDTLS_USE_PSA_CRYPTO) ) ) +#if defined(MBEDTLS_X509_CREATE_C) && ( !defined(MBEDTLS_BIGNUM_C) || \ + !defined(MBEDTLS_OID_C) || !defined(MBEDTLS_ASN1_WRITE_C) || \ + !defined(MBEDTLS_PK_WRITE_C) ) #error "MBEDTLS_X509_CREATE_C defined, but not all prerequisites" #endif @@ -1043,11 +757,6 @@ #error "MBEDTLS_X509_CSR_WRITE_C defined, but not all prerequisites" #endif -#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) && \ - ( !defined(MBEDTLS_X509_CRT_PARSE_C) ) -#error "MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK defined, but not all prerequisites" -#endif - #if defined(MBEDTLS_HAVE_INT32) && defined(MBEDTLS_HAVE_INT64) #error "MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 cannot be defined simultaneously" #endif /* MBEDTLS_HAVE_INT32 && MBEDTLS_HAVE_INT64 */ @@ -1065,37 +774,29 @@ #error "MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH defined, but not all prerequisites" #endif -#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) && ( !defined(MBEDTLS_SSL_PROTO_TLS1_3) ) -#error "MBEDTLS_SSL_RECORD_SIZE_LIMIT defined, but not all prerequisites" -#endif -#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) && \ - !( defined(MBEDTLS_SSL_HAVE_CCM) || defined(MBEDTLS_SSL_HAVE_GCM) || \ - defined(MBEDTLS_SSL_HAVE_CHACHAPOLY) ) -#error "MBEDTLS_SSL_CONTEXT_SERIALIZATION defined, but not all prerequisites" -#endif /* Reject attempts to enable options that have been removed and that could * cause a build to succeed but with features removed. */ #if defined(MBEDTLS_HAVEGE_C) //no-check-names -#error "MBEDTLS_HAVEGE_C was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/2599" +#error "MBEDTLS_HAVEGE_C was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/2599" #endif #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL) //no-check-names -#error "MBEDTLS_SSL_HW_RECORD_ACCEL was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4031" +#error "MBEDTLS_SSL_HW_RECORD_ACCEL was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4031" #endif #if defined(MBEDTLS_SSL_PROTO_SSL3) //no-check-names -#error "MBEDTLS_SSL_PROTO_SSL3 (SSL v3.0 support) was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4031" +#error "MBEDTLS_SSL_PROTO_SSL3 (SSL v3.0 support) was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4031" #endif #if defined(MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO) //no-check-names -#error "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO (SSL v2 ClientHello support) was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4031" +#error "MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO (SSL v2 ClientHello support) was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4031" #endif #if defined(MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT) //no-check-names -#error "MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT (compatibility with the buggy implementation of truncated HMAC in Mbed TLS up to 2.7) was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4031" +#error "MBEDTLS_SSL_TRUNCATED_HMAC_COMPAT (compatibility with the buggy implementation of truncated HMAC in Mbed TLS up to 2.7) was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4031" #endif #if defined(MBEDTLS_TLS_DEFAULT_ALLOW_SHA1_IN_CERTIFICATES) //no-check-names @@ -1103,31 +804,23 @@ #endif #if defined(MBEDTLS_ZLIB_SUPPORT) //no-check-names -#error "MBEDTLS_ZLIB_SUPPORT was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4031" +#error "MBEDTLS_ZLIB_SUPPORT was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4031" #endif #if defined(MBEDTLS_CHECK_PARAMS) //no-check-names -#error "MBEDTLS_CHECK_PARAMS was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4313" +#error "MBEDTLS_CHECK_PARAMS was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4313" #endif #if defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY) //no-check-names -#error "MBEDTLS_SSL_CID_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4335" +#error "MBEDTLS_SSL_CID_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4335" #endif #if defined(MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY) //no-check-names -#error "MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4335" +#error "MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4335" #endif #if defined(MBEDTLS_SSL_TRUNCATED_HMAC) //no-check-names -#error "MBEDTLS_SSL_TRUNCATED_HMAC was removed in Mbed TLS 3.0. See https://github.com/Mbed-TLS/mbedtls/issues/4341" -#endif - -#if defined(MBEDTLS_PKCS7_C) && ( ( !defined(MBEDTLS_ASN1_PARSE_C) ) || \ - ( !defined(MBEDTLS_OID_C) ) || ( !defined(MBEDTLS_PK_PARSE_C) ) || \ - ( !defined(MBEDTLS_X509_CRT_PARSE_C) ) || \ - ( !defined(MBEDTLS_X509_CRL_PARSE_C) ) || \ - ( !defined(MBEDTLS_MD_C) ) ) -#error "MBEDTLS_PKCS7_C is defined, but not all prerequisites" +#error "MBEDTLS_SSL_TRUNCATED_HMAC was removed in Mbed TLS 3.0. See https://github.com/ARMmbed/mbedtls/issues/4341" #endif /* @@ -1137,5 +830,4 @@ */ typedef int mbedtls_iso_c_forbids_empty_translation_units; -/* *INDENT-ON* */ #endif /* MBEDTLS_CHECK_CONFIG_H */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/cipher.h b/src/duckdb/third_party/mbedtls/include/mbedtls/cipher.h index 7bf86149f..b02ab76c0 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/cipher.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/cipher.h @@ -9,7 +9,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_CIPHER_H @@ -34,6 +46,11 @@ #define MBEDTLS_CIPHER_MODE_STREAM #endif +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) +#define inline __inline +#endif + /** The selected feature is not available. */ #define MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE -0x6080 /** Bad input parameters. */ @@ -59,16 +76,16 @@ extern "C" { /** * \brief Supported cipher types. * - * \warning DES/3DES are considered weak ciphers and their use - * constitutes a security risk. We recommend considering stronger + * \warning DES is considered weak cipher and its use + * constitutes a security risk. Arm recommends considering stronger * ciphers instead. */ typedef enum { MBEDTLS_CIPHER_ID_NONE = 0, /**< Placeholder to mark the end of cipher ID lists. */ MBEDTLS_CIPHER_ID_NULL, /**< The identity cipher, treated as a stream cipher. */ MBEDTLS_CIPHER_ID_AES, /**< The AES cipher. */ - MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. \warning DES is considered weak. */ - MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. \warning 3DES is considered weak. */ + MBEDTLS_CIPHER_ID_DES, /**< The DES cipher. */ + MBEDTLS_CIPHER_ID_3DES, /**< The Triple DES cipher. */ MBEDTLS_CIPHER_ID_CAMELLIA, /**< The Camellia cipher. */ MBEDTLS_CIPHER_ID_ARIA, /**< The Aria cipher. */ MBEDTLS_CIPHER_ID_CHACHA20, /**< The ChaCha20 cipher. */ @@ -77,8 +94,8 @@ typedef enum { /** * \brief Supported {cipher type, cipher mode} pairs. * - * \warning DES/3DES are considered weak ciphers and their use - * constitutes a security risk. We recommend considering stronger + * \warning DES is considered weak cipher and its use + * constitutes a security risk. Arm recommends considering stronger * ciphers instead. */ typedef enum { @@ -114,12 +131,12 @@ typedef enum { MBEDTLS_CIPHER_CAMELLIA_128_GCM, /**< Camellia cipher with 128-bit GCM mode. */ MBEDTLS_CIPHER_CAMELLIA_192_GCM, /**< Camellia cipher with 192-bit GCM mode. */ MBEDTLS_CIPHER_CAMELLIA_256_GCM, /**< Camellia cipher with 256-bit GCM mode. */ - MBEDTLS_CIPHER_DES_ECB, /**< DES cipher with ECB mode. \warning DES is considered weak. */ - MBEDTLS_CIPHER_DES_CBC, /**< DES cipher with CBC mode. \warning DES is considered weak. */ - MBEDTLS_CIPHER_DES_EDE_ECB, /**< DES cipher with EDE ECB mode. \warning 3DES is considered weak. */ - MBEDTLS_CIPHER_DES_EDE_CBC, /**< DES cipher with EDE CBC mode. \warning 3DES is considered weak. */ - MBEDTLS_CIPHER_DES_EDE3_ECB, /**< DES cipher with EDE3 ECB mode. \warning 3DES is considered weak. */ - MBEDTLS_CIPHER_DES_EDE3_CBC, /**< DES cipher with EDE3 CBC mode. \warning 3DES is considered weak. */ + MBEDTLS_CIPHER_DES_ECB, /**< DES cipher with ECB mode. */ + MBEDTLS_CIPHER_DES_CBC, /**< DES cipher with CBC mode. */ + MBEDTLS_CIPHER_DES_EDE_ECB, /**< DES cipher with EDE ECB mode. */ + MBEDTLS_CIPHER_DES_EDE_CBC, /**< DES cipher with EDE CBC mode. */ + MBEDTLS_CIPHER_DES_EDE3_ECB, /**< DES cipher with EDE3 ECB mode. */ + MBEDTLS_CIPHER_DES_EDE3_CBC, /**< DES cipher with EDE3 CBC mode. */ MBEDTLS_CIPHER_AES_128_CCM, /**< AES cipher with 128-bit CCM mode. */ MBEDTLS_CIPHER_AES_192_CCM, /**< AES cipher with 192-bit CCM mode. */ MBEDTLS_CIPHER_AES_256_CCM, /**< AES cipher with 256-bit CCM mode. */ @@ -205,11 +222,11 @@ typedef enum { enum { /** Undefined key length. */ MBEDTLS_KEY_LENGTH_NONE = 0, - /** Key length, in bits (including parity), for DES keys. \warning DES is considered weak. */ + /** Key length, in bits (including parity), for DES keys. */ MBEDTLS_KEY_LENGTH_DES = 64, - /** Key length in bits, including parity, for DES in two-key EDE. \warning 3DES is considered weak. */ + /** Key length in bits, including parity, for DES in two-key EDE. */ MBEDTLS_KEY_LENGTH_DES_EDE = 128, - /** Key length in bits, including parity, for DES in three-key EDE. \warning 3DES is considered weak. */ + /** Key length in bits, including parity, for DES in three-key EDE. */ MBEDTLS_KEY_LENGTH_DES_EDE3 = 192, }; @@ -258,62 +275,51 @@ typedef struct mbedtls_cmac_context_t mbedtls_cmac_context_t; * mbedtls_cipher_info_from_type(), * mbedtls_cipher_info_from_values(), * mbedtls_cipher_info_from_psa(). - * - * \note Some fields store a value that has been right-shifted to save - * code-size, so should not be used directly. The accessor - * functions adjust for this and return the "natural" value. */ -typedef struct mbedtls_cipher_info_t { - /** Name of the cipher. */ - const char *MBEDTLS_PRIVATE(name); - - /** The block size, in bytes. */ - unsigned int MBEDTLS_PRIVATE(block_size) : 5; - - /** IV or nonce size, in bytes (right shifted by #MBEDTLS_IV_SIZE_SHIFT). - * For ciphers that accept variable IV sizes, - * this is the recommended size. +typedef struct mbedtls_cipher_info_t +{ + /** Full cipher identifier. For example, + * MBEDTLS_CIPHER_AES_256_CBC. */ - unsigned int MBEDTLS_PRIVATE(iv_size) : 3; + mbedtls_cipher_type_t MBEDTLS_PRIVATE(type); + + /** The cipher mode. For example, MBEDTLS_MODE_CBC. */ + mbedtls_cipher_mode_t MBEDTLS_PRIVATE(mode); - /** The cipher key length, in bits (right shifted by #MBEDTLS_KEY_BITLEN_SHIFT). - * This is the default length for variable sized ciphers. + /** The cipher key length, in bits. This is the + * default length for variable sized ciphers. * Includes parity bits for ciphers like DES. */ - unsigned int MBEDTLS_PRIVATE(key_bitlen) : 4; + unsigned int MBEDTLS_PRIVATE(key_bitlen); - /** The cipher mode (as per mbedtls_cipher_mode_t). - * For example, MBEDTLS_MODE_CBC. - */ - unsigned int MBEDTLS_PRIVATE(mode) : 4; + /** Name of the cipher. */ + const char * MBEDTLS_PRIVATE(name); - /** Full cipher identifier (as per mbedtls_cipher_type_t). - * For example, MBEDTLS_CIPHER_AES_256_CBC. - * - * This could be 7 bits, but 8 bits retains byte alignment for the - * next field, which reduces code size to access that field. + /** IV or nonce size, in Bytes. + * For ciphers that accept variable IV sizes, + * this is the recommended size. */ - unsigned int MBEDTLS_PRIVATE(type) : 8; + unsigned int MBEDTLS_PRIVATE(iv_size); /** Bitflag comprised of MBEDTLS_CIPHER_VARIABLE_IV_LEN and * MBEDTLS_CIPHER_VARIABLE_KEY_LEN indicating whether the * cipher supports variable IV or variable key sizes, respectively. */ - unsigned int MBEDTLS_PRIVATE(flags) : 2; + int MBEDTLS_PRIVATE(flags); - /** Index to LUT for base cipher information and functions. */ - unsigned int MBEDTLS_PRIVATE(base_idx) : 5; + /** The block size, in Bytes. */ + unsigned int MBEDTLS_PRIVATE(block_size); + + /** Struct for base cipher information and functions. */ + const mbedtls_cipher_base_t *MBEDTLS_PRIVATE(base); } mbedtls_cipher_info_t; -/* For internal use only. - * These are used to more compactly represent the fields above. */ -#define MBEDTLS_KEY_BITLEN_SHIFT 6 -#define MBEDTLS_IV_SIZE_SHIFT 2 /** * Generic cipher context. */ -typedef struct mbedtls_cipher_context_t { +typedef struct mbedtls_cipher_context_t +{ /** Information about the associated cipher. */ const mbedtls_cipher_info_t *MBEDTLS_PRIVATE(cipher_info); @@ -329,8 +335,8 @@ typedef struct mbedtls_cipher_context_t { /** Padding functions to use, if relevant for * the specific cipher mode. */ - void(*MBEDTLS_PRIVATE(add_padding))(unsigned char *output, size_t olen, size_t data_len); - int(*MBEDTLS_PRIVATE(get_padding))(unsigned char *input, size_t ilen, size_t *data_len); + void (*MBEDTLS_PRIVATE(add_padding))( unsigned char *output, size_t olen, size_t data_len ); + int (*MBEDTLS_PRIVATE(get_padding))( unsigned char *input, size_t ilen, size_t *data_len ); #endif /** Buffer for input that has not been processed yet. */ @@ -354,7 +360,7 @@ typedef struct mbedtls_cipher_context_t { mbedtls_cmac_context_t *MBEDTLS_PRIVATE(cmac_ctx); #endif -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_USE_PSA_CRYPTO) /** Indicates whether the cipher operations should be performed * by Mbed TLS' own crypto library or an external implementation * of the PSA Crypto API. @@ -363,7 +369,7 @@ typedef struct mbedtls_cipher_context_t { * mbedtls_cipher_setup_psa(). */ unsigned char MBEDTLS_PRIVATE(psa_enabled); -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ } mbedtls_cipher_context_t; @@ -380,7 +386,7 @@ typedef struct mbedtls_cipher_context_t { * \return A statically-allocated array of cipher identifiers * of type cipher_type_t. The last entry is zero. */ -const int *mbedtls_cipher_list(void); +const int *mbedtls_cipher_list( void ); /** * \brief This function retrieves the cipher-information @@ -393,7 +399,7 @@ const int *mbedtls_cipher_list(void); * given \p cipher_name. * \return \c NULL if the associated cipher information is not found. */ -const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string(const char *cipher_name); +const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( const char *cipher_name ); /** * \brief This function retrieves the cipher-information @@ -405,7 +411,7 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string(const char *cipher_ * given \p cipher_type. * \return \c NULL if the associated cipher information is not found. */ -const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type(const mbedtls_cipher_type_t cipher_type); +const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( const mbedtls_cipher_type_t cipher_type ); /** * \brief This function retrieves the cipher-information @@ -421,9 +427,9 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type(const mbedtls_cipher_ * given \p cipher_id. * \return \c NULL if the associated cipher information is not found. */ -const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values(const mbedtls_cipher_id_t cipher_id, - int key_bitlen, - const mbedtls_cipher_mode_t mode); +const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id, + int key_bitlen, + const mbedtls_cipher_mode_t mode ); /** * \brief Retrieve the identifier for a cipher info structure. @@ -434,15 +440,14 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values(const mbedtls_ciphe * \return The full cipher identifier (\c MBEDTLS_CIPHER_xxx). * \return #MBEDTLS_CIPHER_NONE if \p info is \c NULL. */ -inline mbedtls_cipher_type_t mbedtls_cipher_info_get_type( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return MBEDTLS_CIPHER_NONE; - } else { - return (mbedtls_cipher_type_t) info->MBEDTLS_PRIVATE(type); - } -} +//static inline mbedtls_cipher_type_t mbedtls_cipher_info_get_type( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( MBEDTLS_CIPHER_NONE ); +// else +// return( info->MBEDTLS_PRIVATE(type) ); +//} /** * \brief Retrieve the operation mode for a cipher info structure. @@ -453,15 +458,14 @@ inline mbedtls_cipher_type_t mbedtls_cipher_info_get_type( * \return The cipher mode (\c MBEDTLS_MODE_xxx). * \return #MBEDTLS_MODE_NONE if \p info is \c NULL. */ -inline mbedtls_cipher_mode_t mbedtls_cipher_info_get_mode( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return MBEDTLS_MODE_NONE; - } else { - return (mbedtls_cipher_mode_t) info->MBEDTLS_PRIVATE(mode); - } -} +//static inline mbedtls_cipher_mode_t mbedtls_cipher_info_get_mode( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( MBEDTLS_MODE_NONE ); +// else +// return( info->MBEDTLS_PRIVATE(mode) ); +//} /** * \brief Retrieve the key size for a cipher info structure. @@ -474,15 +478,14 @@ inline mbedtls_cipher_mode_t mbedtls_cipher_info_get_mode( * For DES, this includes the parity bits. * \return \c 0 if \p info is \c NULL. */ -inline size_t mbedtls_cipher_info_get_key_bitlen( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return 0; - } else { - return ((size_t) info->MBEDTLS_PRIVATE(key_bitlen)) << MBEDTLS_KEY_BITLEN_SHIFT; - } -} +//static inline size_t mbedtls_cipher_info_get_key_bitlen( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( 0 ); +// else +// return( info->MBEDTLS_PRIVATE(key_bitlen) ); +//} /** * \brief Retrieve the human-readable name for a @@ -493,17 +496,16 @@ inline size_t mbedtls_cipher_info_get_key_bitlen( * * \return The cipher name, which is a human readable string, * with static storage duration. - * \return \c NULL if \p info is \c NULL. + * \return \c NULL if \c info is \p NULL. */ -inline const char *mbedtls_cipher_info_get_name( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return NULL; - } else { - return info->MBEDTLS_PRIVATE(name); - } -} +//static inline const char *mbedtls_cipher_info_get_name( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( NULL ); +// else +// return( info->MBEDTLS_PRIVATE(name) ); +//} /** * \brief This function returns the size of the IV or nonce @@ -515,15 +517,14 @@ inline const char *mbedtls_cipher_info_get_name( * \return \c 0 for ciphers not using an IV or a nonce. * \return \c 0 if \p info is \c NULL. */ -inline size_t mbedtls_cipher_info_get_iv_size( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return 0; - } - - return ((size_t) info->MBEDTLS_PRIVATE(iv_size)) << MBEDTLS_IV_SIZE_SHIFT; -} +//static inline size_t mbedtls_cipher_info_get_iv_size( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( 0 ); +// +// return( (size_t) info->MBEDTLS_PRIVATE(iv_size) ); +//} /** * \brief This function returns the block size of the given @@ -535,15 +536,14 @@ inline size_t mbedtls_cipher_info_get_iv_size( * \return \c 1 if the cipher is a stream cipher. * \return \c 0 if \p info is \c NULL. */ -inline size_t mbedtls_cipher_info_get_block_size( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return 0; - } - - return (size_t) (info->MBEDTLS_PRIVATE(block_size)); -} +//static inline size_t mbedtls_cipher_info_get_block_size( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( 0 ); +// +// return( (size_t) info->MBEDTLS_PRIVATE(block_size) ); +//} /** * \brief This function returns a non-zero value if the key length for @@ -554,15 +554,14 @@ inline size_t mbedtls_cipher_info_get_block_size( * \return Non-zero if the key length is variable, \c 0 otherwise. * \return \c 0 if the given pointer is \c NULL. */ -inline int mbedtls_cipher_info_has_variable_key_bitlen( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return 0; - } - - return info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_KEY_LEN; -} +//static inline int mbedtls_cipher_info_has_variable_key_bitlen( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( 0 ); +// +// return( info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ); +//} /** * \brief This function returns a non-zero value if the IV size for @@ -573,22 +572,21 @@ inline int mbedtls_cipher_info_has_variable_key_bitlen( * \return Non-zero if the IV size is variable, \c 0 otherwise. * \return \c 0 if the given pointer is \c NULL. */ -inline int mbedtls_cipher_info_has_variable_iv_size( - const mbedtls_cipher_info_t *info) -{ - if (info == NULL) { - return 0; - } - - return info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_IV_LEN; -} +//static inline int mbedtls_cipher_info_has_variable_iv_size( +// const mbedtls_cipher_info_t *info ) +//{ +// if( info == NULL ) +// return( 0 ); +// +// return( info->MBEDTLS_PRIVATE(flags) & MBEDTLS_CIPHER_VARIABLE_IV_LEN ); +//} /** - * \brief This function initializes a \p ctx as NONE. + * \brief This function initializes a \p cipher_context as NONE. * * \param ctx The context to be initialized. This must not be \c NULL. */ -void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx); +void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx ); /** * \brief This function frees and clears the cipher-specific @@ -599,7 +597,7 @@ void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx); * function has no effect, otherwise this must point to an * initialized context. */ -void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx); +void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ); /** @@ -628,20 +626,14 @@ void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx); * \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the * cipher-specific context fails. */ -int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx, - const mbedtls_cipher_info_t *cipher_info); +int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info ); #if defined(MBEDTLS_USE_PSA_CRYPTO) -#if !defined(MBEDTLS_DEPRECATED_REMOVED) /** * \brief This function initializes a cipher context for * PSA-based use with the given cipher primitive. * - * \deprecated This function is deprecated and will be removed in a - * future version of the library. - * Please use psa_aead_xxx() / psa_cipher_xxx() directly - * instead. - * * \note See #MBEDTLS_USE_PSA_CRYPTO for information on PSA. * * \param ctx The context to initialize. May not be \c NULL. @@ -659,10 +651,9 @@ int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx, * \return #MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the * cipher-specific context fails. */ -int MBEDTLS_DEPRECATED mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx, - const mbedtls_cipher_info_t *cipher_info, - size_t taglen); -#endif /* MBEDTLS_DEPRECATED_REMOVED */ +int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info, + size_t taglen ); #endif /* MBEDTLS_USE_PSA_CRYPTO */ /** @@ -675,14 +666,14 @@ int MBEDTLS_DEPRECATED mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx, * \return \c 1 if the cipher is a stream cipher. * \return \c 0 if \p ctx has not been initialized. */ -inline unsigned int mbedtls_cipher_get_block_size( - const mbedtls_cipher_context_t *ctx) +static inline unsigned int mbedtls_cipher_get_block_size( + const mbedtls_cipher_context_t *ctx ) { - if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) { + MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 ); + if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL ) return 0; - } - return (unsigned int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(block_size); + return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(block_size); } /** @@ -694,15 +685,15 @@ inline unsigned int mbedtls_cipher_get_block_size( * \return The mode of operation. * \return #MBEDTLS_MODE_NONE if \p ctx has not been initialized. */ -inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( - const mbedtls_cipher_context_t *ctx) -{ - if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) { - return MBEDTLS_MODE_NONE; - } - - return (mbedtls_cipher_mode_t) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(mode); -} +//static inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( +// const mbedtls_cipher_context_t *ctx ) +//{ +// MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, MBEDTLS_MODE_NONE ); +// if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL ) +// return MBEDTLS_MODE_NONE; +// +// return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(mode); +//} /** * \brief This function returns the size of the IV or nonce @@ -714,20 +705,18 @@ inline mbedtls_cipher_mode_t mbedtls_cipher_get_cipher_mode( * \return \c 0 for ciphers not using an IV or a nonce. * \return The actual size if an IV has been set. */ -inline int mbedtls_cipher_get_iv_size( - const mbedtls_cipher_context_t *ctx) -{ - if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) { - return 0; - } - - if (ctx->MBEDTLS_PRIVATE(iv_size) != 0) { - return (int) ctx->MBEDTLS_PRIVATE(iv_size); - } - - return (int) (((int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(iv_size)) << - MBEDTLS_IV_SIZE_SHIFT); -} +//static inline int mbedtls_cipher_get_iv_size( +// const mbedtls_cipher_context_t *ctx ) +//{ +// MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 ); +// if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL ) +// return 0; +// +// if( ctx->MBEDTLS_PRIVATE(iv_size) != 0 ) +// return (int) ctx->MBEDTLS_PRIVATE(iv_size); +// +// return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(iv_size); +//} /** * \brief This function returns the type of the given cipher. @@ -737,15 +726,16 @@ inline int mbedtls_cipher_get_iv_size( * \return The type of the cipher. * \return #MBEDTLS_CIPHER_NONE if \p ctx has not been initialized. */ -inline mbedtls_cipher_type_t mbedtls_cipher_get_type( - const mbedtls_cipher_context_t *ctx) -{ - if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) { - return MBEDTLS_CIPHER_NONE; - } - - return (mbedtls_cipher_type_t) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(type); -} +//static inline mbedtls_cipher_type_t mbedtls_cipher_get_type( +// const mbedtls_cipher_context_t *ctx ) +//{ +// MBEDTLS_INTERNAL_VALIDATE_RET( +// ctx != NULL, MBEDTLS_CIPHER_NONE ); +// if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL ) +// return MBEDTLS_CIPHER_NONE; +// +// return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(type); +//} /** * \brief This function returns the name of the given cipher @@ -756,15 +746,15 @@ inline mbedtls_cipher_type_t mbedtls_cipher_get_type( * \return The name of the cipher. * \return NULL if \p ctx has not been not initialized. */ -inline const char *mbedtls_cipher_get_name( - const mbedtls_cipher_context_t *ctx) -{ - if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) { - return 0; - } - - return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(name); -} +//static inline const char *mbedtls_cipher_get_name( +// const mbedtls_cipher_context_t *ctx ) +//{ +// MBEDTLS_INTERNAL_VALIDATE_RET( ctx != NULL, 0 ); +// if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL ) +// return 0; +// +// return ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(name); +//} /** * \brief This function returns the key length of the cipher. @@ -772,19 +762,19 @@ inline const char *mbedtls_cipher_get_name( * \param ctx The context of the cipher. This must be initialized. * * \return The key length of the cipher in bits. - * \return #MBEDTLS_KEY_LENGTH_NONE if \p ctx has not been + * \return #MBEDTLS_KEY_LENGTH_NONE if ctx \p has not been * initialized. */ -inline int mbedtls_cipher_get_key_bitlen( - const mbedtls_cipher_context_t *ctx) -{ - if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) { - return MBEDTLS_KEY_LENGTH_NONE; - } - - return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(key_bitlen) << - MBEDTLS_KEY_BITLEN_SHIFT; -} +//static inline int mbedtls_cipher_get_key_bitlen( +// const mbedtls_cipher_context_t *ctx ) +//{ +// MBEDTLS_INTERNAL_VALIDATE_RET( +// ctx != NULL, MBEDTLS_KEY_LENGTH_NONE ); +// if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL ) +// return MBEDTLS_KEY_LENGTH_NONE; +// +// return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(key_bitlen); +//} /** * \brief This function returns the operation of the given cipher. @@ -794,15 +784,16 @@ inline int mbedtls_cipher_get_key_bitlen( * \return The type of operation: #MBEDTLS_ENCRYPT or #MBEDTLS_DECRYPT. * \return #MBEDTLS_OPERATION_NONE if \p ctx has not been initialized. */ -inline mbedtls_operation_t mbedtls_cipher_get_operation( - const mbedtls_cipher_context_t *ctx) -{ - if (ctx->MBEDTLS_PRIVATE(cipher_info) == NULL) { - return MBEDTLS_OPERATION_NONE; - } - - return ctx->MBEDTLS_PRIVATE(operation); -} +//static inline mbedtls_operation_t mbedtls_cipher_get_operation( +// const mbedtls_cipher_context_t *ctx ) +//{ +// MBEDTLS_INTERNAL_VALIDATE_RET( +// ctx != NULL, MBEDTLS_OPERATION_NONE ); +// if( ctx->MBEDTLS_PRIVATE(cipher_info) == NULL ) +// return MBEDTLS_OPERATION_NONE; +// +// return ctx->MBEDTLS_PRIVATE(operation); +//} /** * \brief This function sets the key to use with the given context. @@ -820,16 +811,17 @@ inline mbedtls_operation_t mbedtls_cipher_get_operation( * parameter-verification failure. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, - const unsigned char *key, - int key_bitlen, - const mbedtls_operation_t operation); +int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, + const unsigned char *key, + int key_bitlen, + const mbedtls_operation_t operation ); #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) /** * \brief This function sets the padding mode, for cipher modes * that use padding. * + * The default passing mode is PKCS7 padding. * * \param ctx The generic cipher context. This must be initialized and * bound to a cipher information structure. @@ -841,8 +833,8 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA if the cipher mode * does not support padding. */ -int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx, - mbedtls_cipher_padding_t mode); +int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, + mbedtls_cipher_padding_t mode ); #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ /** @@ -852,12 +844,6 @@ int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx, * \note Some ciphers do not use IVs nor nonce. For these * ciphers, this function has no effect. * - * \note For #MBEDTLS_CIPHER_CHACHA20, the nonce length must - * be 12, and the initial counter value is 0. - * - * \note For #MBEDTLS_CIPHER_CHACHA20_POLY1305, the nonce length - * must be 12. - * * \param ctx The generic cipher context. This must be initialized and * bound to a cipher information structure. * \param iv The IV to use, or NONCE_COUNTER for CTR-mode ciphers. This @@ -869,9 +855,9 @@ int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx, * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on * parameter-verification failure. */ -int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, - size_t iv_len); +int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, + size_t iv_len ); /** * \brief This function resets the cipher state. @@ -905,7 +891,7 @@ int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx, * \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on * parameter-verification failure. */ -int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx); +int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx ); #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) /** @@ -920,8 +906,8 @@ int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx); * \return \c 0 on success. * \return A specific error code on failure. */ -int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx, - const unsigned char *ad, size_t ad_len); +int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, + const unsigned char *ad, size_t ad_len ); #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ /** @@ -953,10 +939,10 @@ int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx, * unsupported mode for a cipher. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, - const unsigned char *input, - size_t ilen, unsigned char *output, - size_t *olen); +int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, + const unsigned char *input, + size_t ilen, unsigned char *output, + size_t *olen ); /** * \brief The generic cipher finalization function. If data still @@ -967,7 +953,7 @@ int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, * \param ctx The generic cipher context. This must be initialized and * bound to a key. * \param output The buffer to write data to. This needs to be a writable - * buffer of at least block_size Bytes. + * buffer of at least \p block_size Bytes. * \param olen The length of the data written to the \p output buffer. * This may not be \c NULL. * @@ -980,8 +966,8 @@ int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, * while decrypting. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, - unsigned char *output, size_t *olen); +int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, + unsigned char *output, size_t *olen ); #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) /** @@ -1000,8 +986,8 @@ int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, * \return \c 0 on success. * \return A specific error code on failure. */ -int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx, - unsigned char *tag, size_t tag_len); +int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx, + unsigned char *tag, size_t tag_len ); /** * \brief This function checks the tag for AEAD ciphers. @@ -1016,8 +1002,8 @@ int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx, * \return \c 0 on success. * \return A specific error code on failure. */ -int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, - const unsigned char *tag, size_t tag_len); +int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, + const unsigned char *tag, size_t tag_len ); #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ /** @@ -1053,10 +1039,10 @@ int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, * while decrypting. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen); +int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen ); #if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C) /** @@ -1103,12 +1089,12 @@ int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, * parameter-verification failure. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_auth_encrypt_ext(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t output_len, - size_t *olen, size_t tag_len); +int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t output_len, + size_t *olen, size_t tag_len ); /** * \brief The authenticated encryption (AEAD/NIST_KW) function. @@ -1159,12 +1145,12 @@ int mbedtls_cipher_auth_encrypt_ext(mbedtls_cipher_context_t *ctx, * \return #MBEDTLS_ERR_CIPHER_AUTH_FAILED if data is not authentic. * \return A cipher-specific error code on failure. */ -int mbedtls_cipher_auth_decrypt_ext(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t output_len, - size_t *olen, size_t tag_len); +int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t output_len, + size_t *olen, size_t tag_len ); #endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */ #ifdef __cplusplus } diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/constant_time.h b/src/duckdb/third_party/mbedtls/include/mbedtls/constant_time.h index d31bff677..c5de57a01 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/constant_time.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/constant_time.h @@ -1,9 +1,20 @@ /** * Constant-time functions - */ -/* + * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_CONSTANT_TIME_H @@ -11,26 +22,24 @@ #include + /** Constant-time buffer comparison without branches. * * This is equivalent to the standard memcmp function, but is likely to be - * compiled to code using bitwise operations rather than a branch, such that - * the time taken is constant w.r.t. the data pointed to by \p a and \p b, - * and w.r.t. whether \p a and \p b are equal or not. It is not constant-time - * w.r.t. \p n . + * compiled to code using bitwise operation rather than a branch. * * This function can be used to write constant-time code by replacing branches * with bit operations using masks. * - * \param a Pointer to the first buffer, containing at least \p n bytes. May not be NULL. - * \param b Pointer to the second buffer, containing at least \p n bytes. May not be NULL. - * \param n The number of bytes to compare. + * \param a Pointer to the first buffer. + * \param b Pointer to the second buffer. + * \param n The number of bytes to compare in the buffer. * - * \return Zero if the contents of the two buffers are the same, + * \return Zero if the content of the two buffer is the same, * otherwise non-zero. */ -int mbedtls_ct_memcmp(const void *a, - const void *b, - size_t n); +int mbedtls_ct_memcmp( const void *a, + const void *b, + size_t n ); #endif /* MBEDTLS_CONSTANT_TIME_H */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/des.h b/src/duckdb/third_party/mbedtls/include/mbedtls/des.h index 2b097a13d..be74cb111 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/des.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/des.h @@ -3,13 +3,25 @@ * * \brief DES block cipher * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * */ #ifndef MBEDTLS_DES_H @@ -41,23 +53,21 @@ extern "C" { /** * \brief DES context structure * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ -typedef struct mbedtls_des_context { +typedef struct mbedtls_des_context +{ uint32_t MBEDTLS_PRIVATE(sk)[32]; /*!< DES subkeys */ } mbedtls_des_context; /** * \brief Triple-DES context structure - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ -typedef struct mbedtls_des3_context { +typedef struct mbedtls_des3_context +{ uint32_t MBEDTLS_PRIVATE(sk)[96]; /*!< 3DES subkeys */ } mbedtls_des3_context; @@ -71,44 +81,36 @@ mbedtls_des3_context; * * \param ctx DES context to be initialized * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ -void mbedtls_des_init(mbedtls_des_context *ctx); +void mbedtls_des_init( mbedtls_des_context *ctx ); /** * \brief Clear DES context * * \param ctx DES context to be cleared * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ -void mbedtls_des_free(mbedtls_des_context *ctx); +void mbedtls_des_free( mbedtls_des_context *ctx ); /** * \brief Initialize Triple-DES context * * \param ctx DES3 context to be initialized - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ -void mbedtls_des3_init(mbedtls_des3_context *ctx); +void mbedtls_des3_init( mbedtls_des3_context *ctx ); /** * \brief Clear Triple-DES context * * \param ctx DES3 context to be cleared - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ -void mbedtls_des3_free(mbedtls_des3_context *ctx); +void mbedtls_des3_free( mbedtls_des3_context *ctx ); /** * \brief Set key parity on the given key to odd. @@ -118,11 +120,11 @@ void mbedtls_des3_free(mbedtls_des3_context *ctx); * * \param key 8-byte secret key * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ -void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]); +void mbedtls_des_key_set_parity( unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** * \brief Check that key parity on the given key is odd. @@ -134,12 +136,12 @@ void mbedtls_des_key_set_parity(unsigned char key[MBEDTLS_DES_KEY_SIZE]); * * \return 0 is parity was ok, 1 if parity was not correct. * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZE]); +int mbedtls_des_key_check_key_parity( const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** * \brief Check that key is not a weak or semi-weak DES key @@ -148,12 +150,12 @@ int mbedtls_des_key_check_key_parity(const unsigned char key[MBEDTLS_DES_KEY_SIZ * * \return 0 if no weak key was found, 1 if a weak key was identified. * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]); +int mbedtls_des_key_check_weak( const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** * \brief DES key schedule (56-bit, encryption) @@ -163,12 +165,12 @@ int mbedtls_des_key_check_weak(const unsigned char key[MBEDTLS_DES_KEY_SIZE]); * * \return 0 * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]); +int mbedtls_des_setkey_enc( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** * \brief DES key schedule (56-bit, decryption) @@ -178,12 +180,12 @@ int mbedtls_des_setkey_enc(mbedtls_des_context *ctx, const unsigned char key[MBE * * \return 0 * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE]); +int mbedtls_des_setkey_dec( mbedtls_des_context *ctx, const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); /** * \brief Triple-DES key schedule (112-bit, encryption) @@ -192,14 +194,10 @@ int mbedtls_des_setkey_dec(mbedtls_des_context *ctx, const unsigned char key[MBE * \param key 16-byte secret key * * \return 0 - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx, - const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]); +int mbedtls_des3_set2key_enc( mbedtls_des3_context *ctx, + const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] ); /** * \brief Triple-DES key schedule (112-bit, decryption) @@ -208,14 +206,10 @@ int mbedtls_des3_set2key_enc(mbedtls_des3_context *ctx, * \param key 16-byte secret key * * \return 0 - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx, - const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2]); +int mbedtls_des3_set2key_dec( mbedtls_des3_context *ctx, + const unsigned char key[MBEDTLS_DES_KEY_SIZE * 2] ); /** * \brief Triple-DES key schedule (168-bit, encryption) @@ -224,14 +218,10 @@ int mbedtls_des3_set2key_dec(mbedtls_des3_context *ctx, * \param key 24-byte secret key * * \return 0 - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx, - const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]); +int mbedtls_des3_set3key_enc( mbedtls_des3_context *ctx, + const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ); /** * \brief Triple-DES key schedule (168-bit, decryption) @@ -240,14 +230,10 @@ int mbedtls_des3_set3key_enc(mbedtls_des3_context *ctx, * \param key 24-byte secret key * * \return 0 - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx, - const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3]); +int mbedtls_des3_set3key_dec( mbedtls_des3_context *ctx, + const unsigned char key[MBEDTLS_DES_KEY_SIZE * 3] ); /** * \brief DES-ECB block encryption/decryption @@ -258,14 +244,14 @@ int mbedtls_des3_set3key_dec(mbedtls_des3_context *ctx, * * \return 0 if successful * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx, - const unsigned char input[8], - unsigned char output[8]); +int mbedtls_des_crypt_ecb( mbedtls_des_context *ctx, + const unsigned char input[8], + unsigned char output[8] ); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** @@ -286,17 +272,17 @@ int mbedtls_des_crypt_ecb(mbedtls_des_context *ctx, * \param input buffer holding the input data * \param output buffer holding the output data * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char *input, - unsigned char *output); +int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx, + int mode, + size_t length, + unsigned char iv[8], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CBC */ /** @@ -307,15 +293,11 @@ int mbedtls_des_crypt_cbc(mbedtls_des_context *ctx, * \param output 64-bit output block * * \return 0 if successful - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx, - const unsigned char input[8], - unsigned char output[8]); +int mbedtls_des3_crypt_ecb( mbedtls_des3_context *ctx, + const unsigned char input[8], + unsigned char output[8] ); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** @@ -337,18 +319,14 @@ int mbedtls_des3_crypt_ecb(mbedtls_des3_context *ctx, * \param output buffer holding the output data * * \return 0 if successful, or MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH - * - * \warning DES/3DES are considered weak ciphers and their use constitutes a - * security risk. We recommend considering stronger ciphers - * instead. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx, - int mode, - size_t length, - unsigned char iv[8], - const unsigned char *input, - unsigned char *output); +int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx, + int mode, + size_t length, + unsigned char iv[8], + const unsigned char *input, + unsigned char *output ); #endif /* MBEDTLS_CIPHER_MODE_CBC */ /** @@ -359,12 +337,12 @@ int mbedtls_des3_crypt_cbc(mbedtls_des3_context *ctx, * \param SK Round keys * \param key Base key * - * \warning DES/3DES are considered weak ciphers and their use constitutes a + * \warning DES is considered a weak cipher and its use constitutes a * security risk. We recommend considering stronger ciphers * instead. */ -void mbedtls_des_setkey(uint32_t SK[32], - const unsigned char key[MBEDTLS_DES_KEY_SIZE]); +void mbedtls_des_setkey( uint32_t SK[32], + const unsigned char key[MBEDTLS_DES_KEY_SIZE] ); #if defined(MBEDTLS_SELF_TEST) @@ -374,7 +352,7 @@ void mbedtls_des_setkey(uint32_t SK[32], * \return 0 if successful, or 1 if the test failed */ MBEDTLS_CHECK_RETURN_CRITICAL -int mbedtls_des_self_test(int verbose); +int mbedtls_des_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/ecp.h b/src/duckdb/third_party/mbedtls/include/mbedtls/ecp.h index b49368f9f..6b63dc037 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/ecp.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/ecp.h @@ -1,1528 +1 @@ -/** - * \file ecp.h - * - * \brief This file provides an API for Elliptic Curves over GF(P) (ECP). - * - * The use of ECP in cryptography and TLS is defined in - * Standards for Efficient Cryptography Group (SECG): SEC1 - * Elliptic Curve Cryptography and - * RFC-4492: Elliptic Curve Cryptography (ECC) Cipher Suites - * for Transport Layer Security (TLS). - * - * RFC-2409: The Internet Key Exchange (IKE) defines ECP - * group types. - * - */ - -/* - * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ - -#ifndef MBEDTLS_ECP_H -#define MBEDTLS_ECP_H -#include "mbedtls/private_access.h" - -#include "mbedtls/build_info.h" -#include "mbedtls/platform_util.h" - -#include "mbedtls/bignum.h" - -/* - * ECP error codes - */ -/** Bad input parameters to function. */ -#define MBEDTLS_ERR_ECP_BAD_INPUT_DATA -0x4F80 -/** The buffer is too small to write to. */ -#define MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL -0x4F00 -/** The requested feature is not available, for example, the requested curve is not supported. */ -#define MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE -0x4E80 -/** The signature is not valid. */ -#define MBEDTLS_ERR_ECP_VERIFY_FAILED -0x4E00 -/** Memory allocation failed. */ -#define MBEDTLS_ERR_ECP_ALLOC_FAILED -0x4D80 -/** Generation of random value, such as ephemeral key, failed. */ -#define MBEDTLS_ERR_ECP_RANDOM_FAILED -0x4D00 -/** Invalid private or public key. */ -#define MBEDTLS_ERR_ECP_INVALID_KEY -0x4C80 -/** The buffer contains a valid signature followed by more data. */ -#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 -/** Operation in progress, call again with the same parameters to continue. */ -#define MBEDTLS_ERR_ECP_IN_PROGRESS -0x4B00 - -/* Flags indicating whether to include code that is specific to certain - * types of curves. These flags are for internal library use only. */ -#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) || \ - defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) -#define MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED -#endif -#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || \ - defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) -#define MBEDTLS_ECP_MONTGOMERY_ENABLED -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Domain-parameter identifiers: curve, subgroup, and generator. - * - * \note Only curves over prime fields are supported. - * - * \warning This library does not support validation of arbitrary domain - * parameters. Therefore, only standardized domain parameters from trusted - * sources should be used. See mbedtls_ecp_group_load(). - */ -/* Note: when adding a new curve: - * - Add it at the end of this enum, otherwise you'll break the ABI by - * changing the numerical value for existing curves. - * - Increment MBEDTLS_ECP_DP_MAX below if needed. - * - Update the calculation of MBEDTLS_ECP_MAX_BITS below. - * - Add the corresponding MBEDTLS_ECP_DP_xxx_ENABLED macro definition to - * mbedtls_config.h. - * - List the curve as a dependency of MBEDTLS_ECP_C and - * MBEDTLS_ECDSA_C if supported in check_config.h. - * - Add the curve to the appropriate curve type macro - * MBEDTLS_ECP_yyy_ENABLED above. - * - Add the necessary definitions to ecp_curves.c. - * - Add the curve to the ecp_supported_curves array in ecp.c. - * - Add the curve to applicable profiles in x509_crt.c. - * - Add the curve to applicable presets in ssl_tls.c. - */ -typedef enum { - MBEDTLS_ECP_DP_NONE = 0, /*!< Curve not defined. */ - MBEDTLS_ECP_DP_SECP192R1, /*!< Domain parameters for the 192-bit curve defined by FIPS 186-4 and SEC1. */ - MBEDTLS_ECP_DP_SECP224R1, /*!< Domain parameters for the 224-bit curve defined by FIPS 186-4 and SEC1. */ - MBEDTLS_ECP_DP_SECP256R1, /*!< Domain parameters for the 256-bit curve defined by FIPS 186-4 and SEC1. */ - MBEDTLS_ECP_DP_SECP384R1, /*!< Domain parameters for the 384-bit curve defined by FIPS 186-4 and SEC1. */ - MBEDTLS_ECP_DP_SECP521R1, /*!< Domain parameters for the 521-bit curve defined by FIPS 186-4 and SEC1. */ - MBEDTLS_ECP_DP_BP256R1, /*!< Domain parameters for 256-bit Brainpool curve. */ - MBEDTLS_ECP_DP_BP384R1, /*!< Domain parameters for 384-bit Brainpool curve. */ - MBEDTLS_ECP_DP_BP512R1, /*!< Domain parameters for 512-bit Brainpool curve. */ - MBEDTLS_ECP_DP_CURVE25519, /*!< Domain parameters for Curve25519. */ - MBEDTLS_ECP_DP_SECP192K1, /*!< Domain parameters for 192-bit "Koblitz" curve. */ - MBEDTLS_ECP_DP_SECP224K1, /*!< Domain parameters for 224-bit "Koblitz" curve. */ - MBEDTLS_ECP_DP_SECP256K1, /*!< Domain parameters for 256-bit "Koblitz" curve. */ - MBEDTLS_ECP_DP_CURVE448, /*!< Domain parameters for Curve448. */ -} mbedtls_ecp_group_id; - -/** - * The number of supported curves, plus one for #MBEDTLS_ECP_DP_NONE. - */ -#define MBEDTLS_ECP_DP_MAX 14 - -/* - * Curve types - */ -typedef enum { - MBEDTLS_ECP_TYPE_NONE = 0, - MBEDTLS_ECP_TYPE_SHORT_WEIERSTRASS, /* y^2 = x^3 + a x + b */ - MBEDTLS_ECP_TYPE_MONTGOMERY, /* y^2 = x^3 + a x^2 + x */ -} mbedtls_ecp_curve_type; - -/** - * Curve information, for use by other modules. - * - * The fields of this structure are part of the public API and can be - * accessed directly by applications. Future versions of the library may - * add extra fields or reorder existing fields. - */ -typedef struct mbedtls_ecp_curve_info { - mbedtls_ecp_group_id grp_id; /*!< An internal identifier. */ - uint16_t tls_id; /*!< The TLS NamedCurve identifier. */ - uint16_t bit_size; /*!< The curve size in bits. */ - const char *name; /*!< A human-friendly name. */ -} mbedtls_ecp_curve_info; - -/** - * \brief The ECP point structure, in Jacobian coordinates. - * - * \note All functions expect and return points satisfying - * the following condition: Z == 0 or - * Z == 1. Other values of \p Z are - * used only by internal functions. - * The point is zero, or "at infinity", if Z == 0. - * Otherwise, \p X and \p Y are its standard (affine) - * coordinates. - */ -typedef struct mbedtls_ecp_point { - mbedtls_mpi MBEDTLS_PRIVATE(X); /*!< The X coordinate of the ECP point. */ - mbedtls_mpi MBEDTLS_PRIVATE(Y); /*!< The Y coordinate of the ECP point. */ - mbedtls_mpi MBEDTLS_PRIVATE(Z); /*!< The Z coordinate of the ECP point. */ -} -mbedtls_ecp_point; - -#if !defined(MBEDTLS_ECP_ALT) -/* - * default Mbed TLS elliptic curve arithmetic implementation - * - * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an - * alternative implementation for the whole module and it will replace this - * one.) - */ - -/** - * \brief The ECP group structure. - * - * We consider two types of curve equations: - *
  • Short Weierstrass: y^2 = x^3 + A x + B mod P - * (SEC1 + RFC-4492)
  • - *
  • Montgomery: y^2 = x^3 + A x^2 + x mod P (Curve25519, - * Curve448)
- * In both cases, the generator (\p G) for a prime-order subgroup is fixed. - * - * For Short Weierstrass, this subgroup is the whole curve, and its - * cardinality is denoted by \p N. Our code requires that \p N is an - * odd prime as mbedtls_ecp_mul() requires an odd number, and - * mbedtls_ecdsa_sign() requires that it is prime for blinding purposes. - * - * The default implementation only initializes \p A without setting it to the - * authentic value for curves with A = -3(SECP256R1, etc), in which - * case you need to load \p A by yourself when using domain parameters directly, - * for example: - * \code - * mbedtls_mpi_init(&A); - * mbedtls_ecp_group_init(&grp); - * CHECK_RETURN(mbedtls_ecp_group_load(&grp, grp_id)); - * if (mbedtls_ecp_group_a_is_minus_3(&grp)) { - * CHECK_RETURN(mbedtls_mpi_sub_int(&A, &grp.P, 3)); - * } else { - * CHECK_RETURN(mbedtls_mpi_copy(&A, &grp.A)); - * } - * - * do_something_with_a(&A); - * - * cleanup: - * mbedtls_mpi_free(&A); - * mbedtls_ecp_group_free(&grp); - * \endcode - * - * For Montgomery curves, we do not store \p A, but (A + 2) / 4, - * which is the quantity used in the formulas. Additionally, \p nbits is - * not the size of \p N but the required size for private keys. - * - * If \p modp is NULL, reduction modulo \p P is done using a generic algorithm. - * Otherwise, \p modp must point to a function that takes an \p mbedtls_mpi in the - * range of 0..2^(2*pbits)-1, and transforms it in-place to an integer - * which is congruent mod \p P to the given MPI, and is close enough to \p pbits - * in size, so that it may be efficiently brought in the 0..P-1 range by a few - * additions or subtractions. Therefore, it is only an approximate modular - * reduction. It must return 0 on success and non-zero on failure. - * - * \note Alternative implementations of the ECP module must obey the - * following constraints. - * * Group IDs must be distinct: if two group structures have - * the same ID, then they must be identical. - * * The fields \c id, \c P, \c A, \c B, \c G, \c N, - * \c pbits and \c nbits must have the same type and semantics - * as in the built-in implementation. - * They must be available for reading, but direct modification - * of these fields does not need to be supported. - * They do not need to be at the same offset in the structure. - */ -typedef struct mbedtls_ecp_group { - mbedtls_ecp_group_id id; /*!< An internal group identifier. */ - mbedtls_mpi P; /*!< The prime modulus of the base field. */ - mbedtls_mpi A; /*!< For Short Weierstrass: \p A in the equation. Note that - \p A is not set to the authentic value in some cases. - Refer to detailed description of ::mbedtls_ecp_group if - using domain parameters in the structure. - For Montgomery curves: (A + 2) / 4. */ - mbedtls_mpi B; /*!< For Short Weierstrass: \p B in the equation. - For Montgomery curves: unused. */ - mbedtls_ecp_point G; /*!< The generator of the subgroup used. */ - mbedtls_mpi N; /*!< The order of \p G. */ - size_t pbits; /*!< The number of bits in \p P.*/ - size_t nbits; /*!< For Short Weierstrass: The number of bits in \p P. - For Montgomery curves: the number of bits in the - private keys. */ - /* End of public fields */ - - unsigned int MBEDTLS_PRIVATE(h); /*!< \internal 1 if the constants are static. */ - int(*MBEDTLS_PRIVATE(modp))(mbedtls_mpi *); /*!< The function for fast pseudo-reduction - mod \p P (see above).*/ - int(*MBEDTLS_PRIVATE(t_pre))(mbedtls_ecp_point *, void *); /*!< Unused. */ - int(*MBEDTLS_PRIVATE(t_post))(mbedtls_ecp_point *, void *); /*!< Unused. */ - void *MBEDTLS_PRIVATE(t_data); /*!< Unused. */ - mbedtls_ecp_point *MBEDTLS_PRIVATE(T); /*!< Pre-computed points for ecp_mul_comb(). */ - size_t MBEDTLS_PRIVATE(T_size); /*!< The number of dynamic allocated pre-computed points. */ -} -mbedtls_ecp_group; - -/** - * \name SECTION: Module settings - * - * The configuration options you can set for this module are in this section. - * Either change them in mbedtls_config.h, or define them using the compiler command line. - * \{ - */ - -#if !defined(MBEDTLS_ECP_WINDOW_SIZE) -/* - * Maximum "window" size used for point multiplication. - * Default: a point where higher memory usage yields diminishing performance - * returns. - * Minimum value: 2. Maximum value: 7. - * - * Result is an array of at most ( 1 << ( MBEDTLS_ECP_WINDOW_SIZE - 1 ) ) - * points used for point multiplication. This value is directly tied to EC - * peak memory usage, so decreasing it by one should roughly cut memory usage - * by two (if large curves are in use). - * - * Reduction in size may reduce speed, but larger curves are impacted first. - * Sample performances (in ECDHE handshakes/s, with FIXED_POINT_OPTIM = 1): - * w-size: 6 5 4 3 2 - * 521 145 141 135 120 97 - * 384 214 209 198 177 146 - * 256 320 320 303 262 226 - * 224 475 475 453 398 342 - * 192 640 640 633 587 476 - */ -#define MBEDTLS_ECP_WINDOW_SIZE 4 /**< The maximum window size used. */ -#endif /* MBEDTLS_ECP_WINDOW_SIZE */ - -#if !defined(MBEDTLS_ECP_FIXED_POINT_OPTIM) -/* - * Trade code size for speed on fixed-point multiplication. - * - * This speeds up repeated multiplication of the generator (that is, the - * multiplication in ECDSA signatures, and half of the multiplications in - * ECDSA verification and ECDHE) by a factor roughly 3 to 4. - * - * For each n-bit Short Weierstrass curve that is enabled, this adds 4n bytes - * of code size if n < 384 and 8n otherwise. - * - * Change this value to 0 to reduce code size. - */ -#define MBEDTLS_ECP_FIXED_POINT_OPTIM 1 /**< Enable fixed-point speed-up. */ -#endif /* MBEDTLS_ECP_FIXED_POINT_OPTIM */ - -/** \} name SECTION: Module settings */ - -#else /* MBEDTLS_ECP_ALT */ -#include "ecp_alt.h" -#endif /* MBEDTLS_ECP_ALT */ - -/** - * The maximum size of the groups, that is, of \c N and \c P. - */ -#if !defined(MBEDTLS_ECP_LIGHT) -/* Dummy definition to help code that has optional ECP support and - * defines an MBEDTLS_ECP_MAX_BYTES-sized array unconditionally. */ -#define MBEDTLS_ECP_MAX_BITS 1 -/* Note: the curves must be listed in DECREASING size! */ -#elif defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 521 -#elif defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 512 -#elif defined(MBEDTLS_ECP_DP_CURVE448_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 448 -#elif defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 384 -#elif defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 384 -#elif defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 256 -#elif defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 256 -#elif defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 256 -#elif defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 255 -#elif defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 225 // n is slightly above 2^224 -#elif defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 224 -#elif defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 192 -#elif defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) -#define MBEDTLS_ECP_MAX_BITS 192 -#else /* !MBEDTLS_ECP_LIGHT */ -#error "Missing definition of MBEDTLS_ECP_MAX_BITS" -#endif /* !MBEDTLS_ECP_LIGHT */ - -#define MBEDTLS_ECP_MAX_BYTES ((MBEDTLS_ECP_MAX_BITS + 7) / 8) -#define MBEDTLS_ECP_MAX_PT_LEN (2 * MBEDTLS_ECP_MAX_BYTES + 1) - -#if defined(MBEDTLS_ECP_RESTARTABLE) - -/** - * \brief Internal restart context for multiplication - * - * \note Opaque struct - */ -typedef struct mbedtls_ecp_restart_mul mbedtls_ecp_restart_mul_ctx; - -/** - * \brief Internal restart context for ecp_muladd() - * - * \note Opaque struct - */ -typedef struct mbedtls_ecp_restart_muladd mbedtls_ecp_restart_muladd_ctx; - -/** - * \brief General context for resuming ECC operations - */ -typedef struct { - unsigned MBEDTLS_PRIVATE(ops_done); /*!< current ops count */ - unsigned MBEDTLS_PRIVATE(depth); /*!< call depth (0 = top-level) */ - mbedtls_ecp_restart_mul_ctx *MBEDTLS_PRIVATE(rsm); /*!< ecp_mul_comb() sub-context */ - mbedtls_ecp_restart_muladd_ctx *MBEDTLS_PRIVATE(ma); /*!< ecp_muladd() sub-context */ -} mbedtls_ecp_restart_ctx; - -/* - * Operation counts for restartable functions - */ -#define MBEDTLS_ECP_OPS_CHK 3 /*!< basic ops count for ecp_check_pubkey() */ -#define MBEDTLS_ECP_OPS_DBL 8 /*!< basic ops count for ecp_double_jac() */ -#define MBEDTLS_ECP_OPS_ADD 11 /*!< basic ops count for see ecp_add_mixed() */ -#define MBEDTLS_ECP_OPS_INV 120 /*!< empirical equivalent for mpi_mod_inv() */ - -/** - * \brief Internal; for restartable functions in other modules. - * Check and update basic ops budget. - * - * \param grp Group structure - * \param rs_ctx Restart context - * \param ops Number of basic ops to do - * - * \return \c 0 if doing \p ops basic ops is still allowed, - * \return #MBEDTLS_ERR_ECP_IN_PROGRESS otherwise. - */ -int mbedtls_ecp_check_budget(const mbedtls_ecp_group *grp, - mbedtls_ecp_restart_ctx *rs_ctx, - unsigned ops); - -/* Utility macro for checking and updating ops budget */ -#define MBEDTLS_ECP_BUDGET(ops) \ - MBEDTLS_MPI_CHK(mbedtls_ecp_check_budget(grp, rs_ctx, \ - (unsigned) (ops))); - -#else /* MBEDTLS_ECP_RESTARTABLE */ - -#define MBEDTLS_ECP_BUDGET(ops) /* no-op; for compatibility */ - -/* We want to declare restartable versions of existing functions anyway */ -typedef void mbedtls_ecp_restart_ctx; - -#endif /* MBEDTLS_ECP_RESTARTABLE */ - -/** - * \brief The ECP key-pair structure. - * - * A generic key-pair that may be used for ECDSA and fixed ECDH, for example. - * - * \note Members are deliberately in the same order as in the - * ::mbedtls_ecdsa_context structure. - */ -typedef struct mbedtls_ecp_keypair { - mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /*!< Elliptic curve and base point */ - mbedtls_mpi MBEDTLS_PRIVATE(d); /*!< our secret value */ - mbedtls_ecp_point MBEDTLS_PRIVATE(Q); /*!< our public value */ -} -mbedtls_ecp_keypair; - -/** - * The uncompressed point format for Short Weierstrass curves - * (MBEDTLS_ECP_DP_SECP_XXX and MBEDTLS_ECP_DP_BP_XXX). - */ -#define MBEDTLS_ECP_PF_UNCOMPRESSED 0 -/** - * The compressed point format for Short Weierstrass curves - * (MBEDTLS_ECP_DP_SECP_XXX and MBEDTLS_ECP_DP_BP_XXX). - * - * \warning While this format is supported for all concerned curves for - * writing, when it comes to parsing, it is not supported for all - * curves. Specifically, parsing compressed points on - * MBEDTLS_ECP_DP_SECP224R1 and MBEDTLS_ECP_DP_SECP224K1 is not - * supported. - */ -#define MBEDTLS_ECP_PF_COMPRESSED 1 - -/* - * Some other constants from RFC 4492 - */ -#define MBEDTLS_ECP_TLS_NAMED_CURVE 3 /**< The named_curve of ECCurveType. */ - -#if defined(MBEDTLS_ECP_RESTARTABLE) -/** - * \brief Set the maximum number of basic operations done in a row. - * - * If more operations are needed to complete a computation, - * #MBEDTLS_ERR_ECP_IN_PROGRESS will be returned by the - * function performing the computation. It is then the - * caller's responsibility to either call again with the same - * parameters until it returns 0 or an error code; or to free - * the restart context if the operation is to be aborted. - * - * It is strictly required that all input parameters and the - * restart context be the same on successive calls for the - * same operation, but output parameters need not be the - * same; they must not be used until the function finally - * returns 0. - * - * This only applies to functions whose documentation - * mentions they may return #MBEDTLS_ERR_ECP_IN_PROGRESS (or - * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS for functions in the - * SSL module). For functions that accept a "restart context" - * argument, passing NULL disables restart and makes the - * function equivalent to the function with the same name - * with \c _restartable removed. For functions in the ECDH - * module, restart is disabled unless the function accepts - * an "ECDH context" argument and - * mbedtls_ecdh_enable_restart() was previously called on - * that context. For function in the SSL module, restart is - * only enabled for specific sides and key exchanges - * (currently only for clients and ECDHE-ECDSA). - * - * \warning Using the PSA interruptible interfaces with keys in local - * storage and no accelerator driver will also call this - * function to set the values specified via those interfaces, - * overwriting values previously set. Care should be taken if - * mixing these two interfaces. - * - * \param max_ops Maximum number of basic operations done in a row. - * Default: 0 (unlimited). - * Lower (non-zero) values mean ECC functions will block for - * a lesser maximum amount of time. - * - * \note A "basic operation" is defined as a rough equivalent of a - * multiplication in GF(p) for the NIST P-256 curve. - * As an indication, with default settings, a scalar - * multiplication (full run of \c mbedtls_ecp_mul()) is: - * - about 3300 basic operations for P-256 - * - about 9400 basic operations for P-384 - * - * \note Very low values are not always respected: sometimes - * functions need to block for a minimum number of - * operations, and will do so even if max_ops is set to a - * lower value. That minimum depends on the curve size, and - * can be made lower by decreasing the value of - * \c MBEDTLS_ECP_WINDOW_SIZE. As an indication, here is the - * lowest effective value for various curves and values of - * that parameter (w for short): - * w=6 w=5 w=4 w=3 w=2 - * P-256 208 208 160 136 124 - * P-384 682 416 320 272 248 - * P-521 1364 832 640 544 496 - * - * \note This setting is currently ignored by Curve25519. - */ -void mbedtls_ecp_set_max_ops(unsigned max_ops); - -/** - * \brief Check if restart is enabled (max_ops != 0) - * - * \return \c 0 if \c max_ops == 0 (restart disabled) - * \return \c 1 otherwise (restart enabled) - */ -int mbedtls_ecp_restart_is_enabled(void); -#endif /* MBEDTLS_ECP_RESTARTABLE */ - -/* - * Get the type of a curve - */ -mbedtls_ecp_curve_type mbedtls_ecp_get_type(const mbedtls_ecp_group *grp); - -/** - * \brief This function retrieves the information defined in - * mbedtls_ecp_curve_info() for all supported curves. - * - * \note This function returns information about all curves - * supported by the library. Some curves may not be - * supported for all algorithms. Call mbedtls_ecdh_can_do() - * or mbedtls_ecdsa_can_do() to check if a curve is - * supported for ECDH or ECDSA. - * - * \return A statically allocated array. The last entry is 0. - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_list(void); - -/** - * \brief This function retrieves the list of internal group - * identifiers of all supported curves in the order of - * preference. - * - * \note This function returns information about all curves - * supported by the library. Some curves may not be - * supported for all algorithms. Call mbedtls_ecdh_can_do() - * or mbedtls_ecdsa_can_do() to check if a curve is - * supported for ECDH or ECDSA. - * - * \return A statically allocated array, - * terminated with MBEDTLS_ECP_DP_NONE. - */ -const mbedtls_ecp_group_id *mbedtls_ecp_grp_id_list(void); - -/** - * \brief This function retrieves curve information from an internal - * group identifier. - * - * \param grp_id An \c MBEDTLS_ECP_DP_XXX value. - * - * \return The associated curve information on success. - * \return NULL on failure. - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_grp_id(mbedtls_ecp_group_id grp_id); - -/** - * \brief This function retrieves curve information from a TLS - * NamedCurve value. - * - * \param tls_id An \c MBEDTLS_ECP_DP_XXX value. - * - * \return The associated curve information on success. - * \return NULL on failure. - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_tls_id(uint16_t tls_id); - -/** - * \brief This function retrieves curve information from a - * human-readable name. - * - * \param name The human-readable name. - * - * \return The associated curve information on success. - * \return NULL on failure. - */ -const mbedtls_ecp_curve_info *mbedtls_ecp_curve_info_from_name(const char *name); - -/** - * \brief This function initializes a point as zero. - * - * \param pt The point to initialize. - */ -void mbedtls_ecp_point_init(mbedtls_ecp_point *pt); - -/** - * \brief This function initializes an ECP group context - * without loading any domain parameters. - * - * \note After this function is called, domain parameters - * for various ECP groups can be loaded through the - * mbedtls_ecp_group_load() or mbedtls_ecp_tls_read_group() - * functions. - */ -void mbedtls_ecp_group_init(mbedtls_ecp_group *grp); - -/** - * \brief This function initializes a key pair as an invalid one. - * - * \param key The key pair to initialize. - */ -void mbedtls_ecp_keypair_init(mbedtls_ecp_keypair *key); - -/** - * \brief This function frees the components of a point. - * - * \param pt The point to free. - */ -void mbedtls_ecp_point_free(mbedtls_ecp_point *pt); - -/** - * \brief This function frees the components of an ECP group. - * - * \param grp The group to free. This may be \c NULL, in which - * case this function returns immediately. If it is not - * \c NULL, it must point to an initialized ECP group. - */ -void mbedtls_ecp_group_free(mbedtls_ecp_group *grp); - -/** - * \brief This function frees the components of a key pair. - * - * \param key The key pair to free. This may be \c NULL, in which - * case this function returns immediately. If it is not - * \c NULL, it must point to an initialized ECP key pair. - */ -void mbedtls_ecp_keypair_free(mbedtls_ecp_keypair *key); - -#if defined(MBEDTLS_ECP_RESTARTABLE) -/** - * \brief Initialize a restart context. - * - * \param ctx The restart context to initialize. This must - * not be \c NULL. - */ -void mbedtls_ecp_restart_init(mbedtls_ecp_restart_ctx *ctx); - -/** - * \brief Free the components of a restart context. - * - * \param ctx The restart context to free. This may be \c NULL, in which - * case this function returns immediately. If it is not - * \c NULL, it must point to an initialized restart context. - */ -void mbedtls_ecp_restart_free(mbedtls_ecp_restart_ctx *ctx); -#endif /* MBEDTLS_ECP_RESTARTABLE */ - -/** - * \brief This function copies the contents of point \p Q into - * point \p P. - * - * \param P The destination point. This must be initialized. - * \param Q The source point. This must be initialized. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return Another negative error code for other kinds of failure. - */ -int mbedtls_ecp_copy(mbedtls_ecp_point *P, const mbedtls_ecp_point *Q); - -/** - * \brief This function copies the contents of group \p src into - * group \p dst. - * - * \param dst The destination group. This must be initialized. - * \param src The source group. This must be initialized. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_group_copy(mbedtls_ecp_group *dst, - const mbedtls_ecp_group *src); - -/** - * \brief This function sets a point to the point at infinity. - * - * \param pt The point to set. This must be initialized. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_set_zero(mbedtls_ecp_point *pt); - -/** - * \brief This function checks if a point is the point at infinity. - * - * \param pt The point to test. This must be initialized. - * - * \return \c 1 if the point is zero. - * \return \c 0 if the point is non-zero. - * \return A negative error code on failure. - */ -int mbedtls_ecp_is_zero(mbedtls_ecp_point *pt); - -/** - * \brief This function compares two points. - * - * \note This assumes that the points are normalized. Otherwise, - * they may compare as "not equal" even if they are. - * - * \param P The first point to compare. This must be initialized. - * \param Q The second point to compare. This must be initialized. - * - * \return \c 0 if the points are equal. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the points are not equal. - */ -int mbedtls_ecp_point_cmp(const mbedtls_ecp_point *P, - const mbedtls_ecp_point *Q); - -/** - * \brief This function imports a non-zero point from two ASCII - * strings. - * - * \param P The destination point. This must be initialized. - * \param radix The numeric base of the input. - * \param x The first affine coordinate, as a null-terminated string. - * \param y The second affine coordinate, as a null-terminated string. - * - * \return \c 0 on success. - * \return An \c MBEDTLS_ERR_MPI_XXX error code on failure. - */ -int mbedtls_ecp_point_read_string(mbedtls_ecp_point *P, int radix, - const char *x, const char *y); - -/** - * \brief This function exports a point into unsigned binary data. - * - * \param grp The group to which the point should belong. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param P The point to export. This must be initialized. - * \param format The point format. This must be either - * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED. - * (For groups without these formats, this parameter is - * ignored. But it still has to be either of the above - * values.) - * \param olen The address at which to store the length of - * the output in Bytes. This must not be \c NULL. - * \param buf The output buffer. This must be a writable buffer - * of length \p buflen Bytes. - * \param buflen The length of the output buffer \p buf in Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer - * is too small to hold the point. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format - * or the export for the given group is not implemented. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_point_write_binary(const mbedtls_ecp_group *grp, - const mbedtls_ecp_point *P, - int format, size_t *olen, - unsigned char *buf, size_t buflen); - -/** - * \brief This function imports a point from unsigned binary data. - * - * \note This function does not check that the point actually - * belongs to the given group, see mbedtls_ecp_check_pubkey() - * for that. - * - * \note For compressed points, see #MBEDTLS_ECP_PF_COMPRESSED for - * limitations. - * - * \param grp The group to which the point should belong. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param P The destination context to import the point to. - * This must be initialized. - * \param buf The input buffer. This must be a readable buffer - * of length \p ilen Bytes. - * \param ilen The length of the input buffer \p buf in Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the import for the - * given group is not implemented. - */ -int mbedtls_ecp_point_read_binary(const mbedtls_ecp_group *grp, - mbedtls_ecp_point *P, - const unsigned char *buf, size_t ilen); - -/** - * \brief This function imports a point from a TLS ECPoint record. - * - * \note On function return, \p *buf is updated to point immediately - * after the ECPoint record. - * - * \param grp The ECP group to use. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param pt The destination point. - * \param buf The address of the pointer to the start of the input buffer. - * \param len The length of the buffer. - * - * \return \c 0 on success. - * \return An \c MBEDTLS_ERR_MPI_XXX error code on initialization - * failure. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid. - */ -int mbedtls_ecp_tls_read_point(const mbedtls_ecp_group *grp, - mbedtls_ecp_point *pt, - const unsigned char **buf, size_t len); - -/** - * \brief This function exports a point as a TLS ECPoint record - * defined in RFC 4492, Section 5.4. - * - * \param grp The ECP group to use. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param pt The point to be exported. This must be initialized. - * \param format The point format to use. This must be either - * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED. - * \param olen The address at which to store the length in Bytes - * of the data written. - * \param buf The target buffer. This must be a writable buffer of - * length \p blen Bytes. - * \param blen The length of the target buffer \p buf in Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the input is invalid. - * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the target buffer - * is too small to hold the exported point. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_tls_write_point(const mbedtls_ecp_group *grp, - const mbedtls_ecp_point *pt, - int format, size_t *olen, - unsigned char *buf, size_t blen); - -/** - * \brief This function sets up an ECP group context - * from a standardized set of domain parameters. - * - * \note The index should be a value of the NamedCurve enum, - * as defined in RFC-4492: Elliptic Curve Cryptography - * (ECC) Cipher Suites for Transport Layer Security (TLS), - * usually in the form of an \c MBEDTLS_ECP_DP_XXX macro. - * - * \param grp The group context to setup. This must be initialized. - * \param id The identifier of the domain parameter set to load. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p id doesn't - * correspond to a known group. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_group_load(mbedtls_ecp_group *grp, mbedtls_ecp_group_id id); - -/** - * \brief This function sets up an ECP group context from a TLS - * ECParameters record as defined in RFC 4492, Section 5.4. - * - * \note The read pointer \p buf is updated to point right after - * the ECParameters record on exit. - * - * \param grp The group context to setup. This must be initialized. - * \param buf The address of the pointer to the start of the input buffer. - * \param len The length of the input buffer \c *buf in Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not - * recognized. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_tls_read_group(mbedtls_ecp_group *grp, - const unsigned char **buf, size_t len); - -/** - * \brief This function extracts an elliptic curve group ID from a - * TLS ECParameters record as defined in RFC 4492, Section 5.4. - * - * \note The read pointer \p buf is updated to point right after - * the ECParameters record on exit. - * - * \param grp The address at which to store the group id. - * This must not be \c NULL. - * \param buf The address of the pointer to the start of the input buffer. - * \param len The length of the input buffer \c *buf in Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if input is invalid. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the group is not - * recognized. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_tls_read_group_id(mbedtls_ecp_group_id *grp, - const unsigned char **buf, - size_t len); -/** - * \brief This function exports an elliptic curve as a TLS - * ECParameters record as defined in RFC 4492, Section 5.4. - * - * \param grp The ECP group to be exported. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param olen The address at which to store the number of Bytes written. - * This must not be \c NULL. - * \param buf The buffer to write to. This must be a writable buffer - * of length \p blen Bytes. - * \param blen The length of the output buffer \p buf in Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output - * buffer is too small to hold the exported group. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_tls_write_group(const mbedtls_ecp_group *grp, - size_t *olen, - unsigned char *buf, size_t blen); - -/** - * \brief This function performs a scalar multiplication of a point - * by an integer: \p R = \p m * \p P. - * - * It is not thread-safe to use same group in multiple threads. - * - * \note To prevent timing attacks, this function - * executes the exact same sequence of base-field - * operations for any valid \p m. It avoids any if-branch or - * array index depending on the value of \p m. It also uses - * \p f_rng to randomize some intermediate results. - * - * \param grp The ECP group to use. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param R The point in which to store the result of the calculation. - * This must be initialized. - * \param m The integer by which to multiply. This must be initialized. - * \param P The point to multiply. This must be initialized. - * \param f_rng The RNG function. This must not be \c NULL. - * \param p_rng The RNG context to be passed to \p f_rng. This may be \c - * NULL if \p f_rng doesn't need a context. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private - * key, or \p P is not a valid public key. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_mul(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, - const mbedtls_mpi *m, const mbedtls_ecp_point *P, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); - -/** - * \brief This function performs multiplication of a point by - * an integer: \p R = \p m * \p P in a restartable way. - * - * \see mbedtls_ecp_mul() - * - * \note This function does the same as \c mbedtls_ecp_mul(), but - * it can return early and restart according to the limit set - * with \c mbedtls_ecp_set_max_ops() to reduce blocking. - * - * \param grp The ECP group to use. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param R The point in which to store the result of the calculation. - * This must be initialized. - * \param m The integer by which to multiply. This must be initialized. - * \param P The point to multiply. This must be initialized. - * \param f_rng The RNG function. This must not be \c NULL. - * \param p_rng The RNG context to be passed to \p f_rng. This may be \c - * NULL if \p f_rng doesn't need a context. - * \param rs_ctx The restart context (NULL disables restart). - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m is not a valid private - * key, or \p P is not a valid public key. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of - * operations was reached: see \c mbedtls_ecp_set_max_ops(). - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_mul_restartable(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, - const mbedtls_mpi *m, const mbedtls_ecp_point *P, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, - mbedtls_ecp_restart_ctx *rs_ctx); - -#if defined(MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED) -/** - * \brief This function checks if domain parameter A of the curve is - * \c -3. - * - * \note This function is only defined for short Weierstrass curves. - * It may not be included in builds without any short - * Weierstrass curve. - * - * \param grp The ECP group to use. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * - * \return \c 1 if A = -3. - * \return \c 0 Otherwise. - */ -inline int mbedtls_ecp_group_a_is_minus_3(const mbedtls_ecp_group *grp) -{ - return grp->A.MBEDTLS_PRIVATE(p) == NULL; -} - -/** - * \brief This function performs multiplication and addition of two - * points by integers: \p R = \p m * \p P + \p n * \p Q - * - * It is not thread-safe to use same group in multiple threads. - * - * \note In contrast to mbedtls_ecp_mul(), this function does not - * guarantee a constant execution flow and timing. - * - * \note This function is only defined for short Weierstrass curves. - * It may not be included in builds without any short - * Weierstrass curve. - * - * \param grp The ECP group to use. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param R The point in which to store the result of the calculation. - * This must be initialized. - * \param m The integer by which to multiply \p P. - * This must be initialized. - * \param P The point to multiply by \p m. This must be initialized. - * \param n The integer by which to multiply \p Q. - * This must be initialized. - * \param Q The point to be multiplied by \p n. - * This must be initialized. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not - * valid private keys, or \p P or \p Q are not valid public - * keys. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not - * designate a short Weierstrass curve. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_muladd(mbedtls_ecp_group *grp, mbedtls_ecp_point *R, - const mbedtls_mpi *m, const mbedtls_ecp_point *P, - const mbedtls_mpi *n, const mbedtls_ecp_point *Q); - -/** - * \brief This function performs multiplication and addition of two - * points by integers: \p R = \p m * \p P + \p n * \p Q in a - * restartable way. - * - * \see \c mbedtls_ecp_muladd() - * - * \note This function works the same as \c mbedtls_ecp_muladd(), - * but it can return early and restart according to the limit - * set with \c mbedtls_ecp_set_max_ops() to reduce blocking. - * - * \note This function is only defined for short Weierstrass curves. - * It may not be included in builds without any short - * Weierstrass curve. - * - * \param grp The ECP group to use. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param R The point in which to store the result of the calculation. - * This must be initialized. - * \param m The integer by which to multiply \p P. - * This must be initialized. - * \param P The point to multiply by \p m. This must be initialized. - * \param n The integer by which to multiply \p Q. - * This must be initialized. - * \param Q The point to be multiplied by \p n. - * This must be initialized. - * \param rs_ctx The restart context (NULL disables restart). - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_INVALID_KEY if \p m or \p n are not - * valid private keys, or \p P or \p Q are not valid public - * keys. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if \p grp does not - * designate a short Weierstrass curve. - * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of - * operations was reached: see \c mbedtls_ecp_set_max_ops(). - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_muladd_restartable( - mbedtls_ecp_group *grp, mbedtls_ecp_point *R, - const mbedtls_mpi *m, const mbedtls_ecp_point *P, - const mbedtls_mpi *n, const mbedtls_ecp_point *Q, - mbedtls_ecp_restart_ctx *rs_ctx); -#endif /* MBEDTLS_ECP_SHORT_WEIERSTRASS_ENABLED */ - -/** - * \brief This function checks that a point is a valid public key - * on this curve. - * - * It only checks that the point is non-zero, has - * valid coordinates and lies on the curve. It does not verify - * that it is indeed a multiple of \c G. This additional - * check is computationally more expensive, is not required - * by standards, and should not be necessary if the group - * used has a small cofactor. In particular, it is useless for - * the NIST groups which all have a cofactor of 1. - * - * \note This function uses bare components rather than an - * ::mbedtls_ecp_keypair structure, to ease use with other - * structures, such as ::mbedtls_ecdh_context or - * ::mbedtls_ecdsa_context. - * - * \param grp The ECP group the point should belong to. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param pt The point to check. This must be initialized. - * - * \return \c 0 if the point is a valid public key. - * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not - * a valid public key for the given curve. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_check_pubkey(const mbedtls_ecp_group *grp, - const mbedtls_ecp_point *pt); - -/** - * \brief This function checks that an \c mbedtls_mpi is a - * valid private key for this curve. - * - * \note This function uses bare components rather than an - * ::mbedtls_ecp_keypair structure to ease use with other - * structures, such as ::mbedtls_ecdh_context or - * ::mbedtls_ecdsa_context. - * - * \param grp The ECP group the private key should belong to. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param d The integer to check. This must be initialized. - * - * \return \c 0 if the point is a valid private key. - * \return #MBEDTLS_ERR_ECP_INVALID_KEY if the point is not a valid - * private key for the given curve. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_check_privkey(const mbedtls_ecp_group *grp, - const mbedtls_mpi *d); - -/** - * \brief This function generates a private key. - * - * \param grp The ECP group to generate a private key for. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param d The destination MPI (secret part). This must be initialized. - * \param f_rng The RNG function. This must not be \c NULL. - * \param p_rng The RNG parameter to be passed to \p f_rng. This may be - * \c NULL if \p f_rng doesn't need a context argument. - * - * \return \c 0 on success. - * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code - * on failure. - */ -int mbedtls_ecp_gen_privkey(const mbedtls_ecp_group *grp, - mbedtls_mpi *d, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief This function generates a keypair with a configurable base - * point. - * - * \note This function uses bare components rather than an - * ::mbedtls_ecp_keypair structure to ease use with other - * structures, such as ::mbedtls_ecdh_context or - * ::mbedtls_ecdsa_context. - * - * \param grp The ECP group to generate a key pair for. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param G The base point to use. This must be initialized - * and belong to \p grp. It replaces the default base - * point \c grp->G used by mbedtls_ecp_gen_keypair(). - * \param d The destination MPI (secret part). - * This must be initialized. - * \param Q The destination point (public part). - * This must be initialized. - * \param f_rng The RNG function. This must not be \c NULL. - * \param p_rng The RNG context to be passed to \p f_rng. This may - * be \c NULL if \p f_rng doesn't need a context argument. - * - * \return \c 0 on success. - * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code - * on failure. - */ -int mbedtls_ecp_gen_keypair_base(mbedtls_ecp_group *grp, - const mbedtls_ecp_point *G, - mbedtls_mpi *d, mbedtls_ecp_point *Q, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief This function generates an ECP keypair. - * - * \note This function uses bare components rather than an - * ::mbedtls_ecp_keypair structure to ease use with other - * structures, such as ::mbedtls_ecdh_context or - * ::mbedtls_ecdsa_context. - * - * \param grp The ECP group to generate a key pair for. - * This must be initialized and have group parameters - * set, for example through mbedtls_ecp_group_load(). - * \param d The destination MPI (secret part). - * This must be initialized. - * \param Q The destination point (public part). - * This must be initialized. - * \param f_rng The RNG function. This must not be \c NULL. - * \param p_rng The RNG context to be passed to \p f_rng. This may - * be \c NULL if \p f_rng doesn't need a context argument. - * - * \return \c 0 on success. - * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code - * on failure. - */ -int mbedtls_ecp_gen_keypair(mbedtls_ecp_group *grp, mbedtls_mpi *d, - mbedtls_ecp_point *Q, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** - * \brief This function generates an ECP key. - * - * \param grp_id The ECP group identifier. - * \param key The destination key. This must be initialized. - * \param f_rng The RNG function to use. This must not be \c NULL. - * \param p_rng The RNG context to be passed to \p f_rng. This may - * be \c NULL if \p f_rng doesn't need a context argument. - * - * \return \c 0 on success. - * \return An \c MBEDTLS_ERR_ECP_XXX or \c MBEDTLS_MPI_XXX error code - * on failure. - */ -int mbedtls_ecp_gen_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); - -/** \brief Set the public key in a key pair object. - * - * \note This function does not check that the point actually - * belongs to the given group. Call mbedtls_ecp_check_pubkey() - * on \p Q before calling this function to check that. - * - * \note This function does not check that the public key matches - * the private key that is already in \p key, if any. - * To check the consistency of the resulting key pair object, - * call mbedtls_ecp_check_pub_priv() after setting both - * the public key and the private key. - * - * \param grp_id The ECP group identifier. - * \param key The key pair object. It must be initialized. - * If its group has already been set, it must match \p grp_id. - * If its group has not been set, it will be set to \p grp_id. - * If the public key has already been set, it is overwritten. - * \param Q The public key to copy. This must be a point on the - * curve indicated by \p grp_id. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p key does not - * match \p grp_id. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for - * the group is not implemented. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_set_public_key(mbedtls_ecp_group_id grp_id, - mbedtls_ecp_keypair *key, - const mbedtls_ecp_point *Q); - -/** - * \brief This function reads an elliptic curve private key. - * - * \note This function does not set the public key in the - * key pair object. Without a public key, the key pair object - * cannot be used with operations that require the public key. - * Call mbedtls_ecp_keypair_calc_public() to set the public - * key from the private key. Alternatively, you can call - * mbedtls_ecp_set_public_key() to set the public key part, - * and then optionally mbedtls_ecp_check_pub_priv() to check - * that the private and public parts are consistent. - * - * \note If a public key has already been set in the key pair - * object, this function does not check that it is consistent - * with the private key. Call mbedtls_ecp_check_pub_priv() - * after setting both the public key and the private key - * to make that check. - * - * \param grp_id The ECP group identifier. - * \param key The destination key. - * \param buf The buffer containing the binary representation of the - * key. (Big endian integer for Weierstrass curves, byte - * string for Montgomery curves.) - * \param buflen The length of the buffer in bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_INVALID_KEY error if the key is - * invalid. - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the operation for - * the group is not implemented. - * \return Another negative error code on different kinds of failure. - */ -int mbedtls_ecp_read_key(mbedtls_ecp_group_id grp_id, mbedtls_ecp_keypair *key, - const unsigned char *buf, size_t buflen); - -#if !defined(MBEDTLS_DEPRECATED_REMOVED) -/** - * \brief This function exports an elliptic curve private key. - * - * \deprecated Note that although this function accepts an output - * buffer that is smaller or larger than the key, most key - * import interfaces require the output to have exactly - * key's nominal length. It is generally simplest to - * pass the key's nominal length as \c buflen, after - * checking that the output buffer is large enough. - * See the description of the \p buflen parameter for - * how to calculate the nominal length. - * To avoid this difficulty, use mbedtls_ecp_write_key_ext() - * instead. - * mbedtls_ecp_write_key() is deprecated and will be - * removed in a future version of the library. - * - * \note If the private key was not set in \p key, - * the output is unspecified. Future versions - * may return an error in that case. - * - * \param key The private key. - * \param buf The output buffer for containing the binary representation - * of the key. - * For Weierstrass curves, this is the big-endian - * representation, padded with null bytes at the beginning - * to reach \p buflen bytes. - * For Montgomery curves, this is the standard byte string - * representation (which is little-endian), padded with - * null bytes at the end to reach \p buflen bytes. - * \param buflen The total length of the buffer in bytes. - * The length of the output is - * (`grp->nbits` + 7) / 8 bytes - * where `grp->nbits` is the private key size in bits. - * For Weierstrass keys, if the output buffer is smaller, - * leading zeros are trimmed to fit if possible. For - * Montgomery keys, the output buffer must always be large - * enough for the nominal length. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL or - * #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the \p key - * representation is larger than the available space in \p buf. - * \return Another negative error code on different kinds of failure. - */ -int MBEDTLS_DEPRECATED mbedtls_ecp_write_key(mbedtls_ecp_keypair *key, - unsigned char *buf, size_t buflen); -#endif /* MBEDTLS_DEPRECATED_REMOVED */ - -/** - * \brief This function exports an elliptic curve private key. - * - * \param key The private key. - * \param olen On success, the length of the private key. - * This is always (`grp->nbits` + 7) / 8 bytes - * where `grp->nbits` is the private key size in bits. - * \param buf The output buffer for containing the binary representation - * of the key. - * \param buflen The total length of the buffer in bytes. - * #MBEDTLS_ECP_MAX_BYTES is always sufficient. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the \p key - * representation is larger than the available space in \p buf. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if no private key is - * set in \p key. - * \return Another negative error code on different kinds of failure. - */ -int mbedtls_ecp_write_key_ext(const mbedtls_ecp_keypair *key, - size_t *olen, unsigned char *buf, size_t buflen); - -/** - * \brief This function exports an elliptic curve public key. - * - * \note If the public key was not set in \p key, - * the output is unspecified. Future versions - * may return an error in that case. - * - * \param key The public key. - * \param format The point format. This must be either - * #MBEDTLS_ECP_PF_COMPRESSED or #MBEDTLS_ECP_PF_UNCOMPRESSED. - * (For groups without these formats, this parameter is - * ignored. But it still has to be either of the above - * values.) - * \param olen The address at which to store the length of - * the output in Bytes. This must not be \c NULL. - * \param buf The output buffer. This must be a writable buffer - * of length \p buflen Bytes. - * \param buflen The length of the output buffer \p buf in Bytes. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL if the output buffer - * is too small to hold the point. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if the point format - * or the export for the given group is not implemented. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_write_public_key(const mbedtls_ecp_keypair *key, - int format, size_t *olen, - unsigned char *buf, size_t buflen); - -/** - * \brief This function checks that the keypair objects - * \p pub and \p prv have the same group and the - * same public point, and that the private key in - * \p prv is consistent with the public key. - * - * \param pub The keypair structure holding the public key. This - * must be initialized. If it contains a private key, that - * part is ignored. - * \param prv The keypair structure holding the full keypair. - * This must be initialized. - * \param f_rng The RNG function. This must not be \c NULL. - * \param p_rng The RNG context to be passed to \p f_rng. This may be \c - * NULL if \p f_rng doesn't need a context. - * - * \return \c 0 on success, meaning that the keys are valid and match. - * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if the keys are invalid or do not match. - * \return An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX - * error code on calculation failure. - */ -int mbedtls_ecp_check_pub_priv( - const mbedtls_ecp_keypair *pub, const mbedtls_ecp_keypair *prv, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); - -/** \brief Calculate the public key from a private key in a key pair. - * - * \param key A keypair structure. It must have a private key set. - * If the public key is set, it will be overwritten. - * \param f_rng The RNG function. This must not be \c NULL. - * \param p_rng The RNG context to be passed to \p f_rng. This may be \c - * NULL if \p f_rng doesn't need a context. - * - * \return \c 0 on success. The key pair object can be used for - * operations that require the public key. - * \return An \c MBEDTLS_ERR_ECP_XXX or an \c MBEDTLS_ERR_MPI_XXX - * error code on calculation failure. - */ -int mbedtls_ecp_keypair_calc_public( - mbedtls_ecp_keypair *key, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); - -/** \brief Query the group that a key pair belongs to. - * - * \param key The key pair to query. - * - * \return The group ID for the group registered in the key pair - * object. - * This is \c MBEDTLS_ECP_DP_NONE if no group has been set - * in the key pair object. - */ -mbedtls_ecp_group_id mbedtls_ecp_keypair_get_group_id( - const mbedtls_ecp_keypair *key); - -/** - * \brief This function exports generic key-pair parameters. - * - * Each of the output parameters can be a null pointer - * if you do not need that parameter. - * - * \note If the private key or the public key was not set in \p key, - * the corresponding output is unspecified. Future versions - * may return an error in that case. - * - * \param key The key pair to export from. - * \param grp Slot for exported ECP group. - * It must either be null or point to an initialized ECP group. - * \param d Slot for the exported secret value. - * It must either be null or point to an initialized mpi. - * \param Q Slot for the exported public value. - * It must either be null or point to an initialized ECP point. - * - * \return \c 0 on success, - * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory-allocation failure. - * \return #MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE if key id doesn't - * correspond to a known group. - * \return Another negative error code on other kinds of failure. - */ -int mbedtls_ecp_export(const mbedtls_ecp_keypair *key, mbedtls_ecp_group *grp, - mbedtls_mpi *d, mbedtls_ecp_point *Q); - -#if defined(MBEDTLS_SELF_TEST) - -/** - * \brief The ECP checkup routine. - * - * \return \c 0 on success. - * \return \c 1 on failure. - */ -int mbedtls_ecp_self_test(int verbose); - -#endif /* MBEDTLS_SELF_TEST */ - -#ifdef __cplusplus -} -#endif - -#endif /* ecp.h */ +// dummy file to make amalgamantion happy diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/entropy.h b/src/duckdb/third_party/mbedtls/include/mbedtls/entropy.h index ab0c01417..fede05ffa 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/entropy.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/entropy.h @@ -1 +1,293 @@ -// \ No newline at end of file +/** + * \file entropy.h + * + * \brief Entropy accumulator implementation + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBEDTLS_ENTROPY_H +#define MBEDTLS_ENTROPY_H +#include "mbedtls/private_access.h" + +#include "mbedtls/build_info.h" + +#include + +#if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) +#include "mbedtls/sha512.h" +#define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR +#else +#if defined(MBEDTLS_SHA256_C) +#define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR +#include "mbedtls/sha256.h" +#endif +#endif + +#if defined(MBEDTLS_THREADING_C) +#include "mbedtls/threading.h" +#endif + + +/** Critical entropy source failure. */ +#define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED -0x003C +/** No more sources can be added. */ +#define MBEDTLS_ERR_ENTROPY_MAX_SOURCES -0x003E +/** No sources have been added to poll. */ +#define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040 +/** No strong sources have been added to poll. */ +#define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE -0x003D +/** Read/write error in file. */ +#define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR -0x003F + +/** + * \name SECTION: Module settings + * + * The configuration options you can set for this module are in this section. + * Either change them in mbedtls_config.h or define them on the compiler command line. + * \{ + */ + +#if !defined(MBEDTLS_ENTROPY_MAX_SOURCES) +#define MBEDTLS_ENTROPY_MAX_SOURCES 20 /**< Maximum number of sources supported */ +#endif + +#if !defined(MBEDTLS_ENTROPY_MAX_GATHER) +#define MBEDTLS_ENTROPY_MAX_GATHER 128 /**< Maximum amount requested from entropy sources */ +#endif + +/* \} name SECTION: Module settings */ + +#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) +#define MBEDTLS_ENTROPY_BLOCK_SIZE 64 /**< Block size of entropy accumulator (SHA-512) */ +#else +#define MBEDTLS_ENTROPY_BLOCK_SIZE 32 /**< Block size of entropy accumulator (SHA-256) */ +#endif + +#define MBEDTLS_ENTROPY_MAX_SEED_SIZE 1024 /**< Maximum size of seed we read from seed file */ +#define MBEDTLS_ENTROPY_SOURCE_MANUAL MBEDTLS_ENTROPY_MAX_SOURCES + +#define MBEDTLS_ENTROPY_SOURCE_STRONG 1 /**< Entropy source is strong */ +#define MBEDTLS_ENTROPY_SOURCE_WEAK 0 /**< Entropy source is weak */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \brief Entropy poll callback pointer + * + * \param data Callback-specific data pointer + * \param output Data to fill + * \param len Maximum size to provide + * \param olen The actual amount of bytes put into the buffer (Can be 0) + * + * \return 0 if no critical failures occurred, + * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED otherwise + */ +typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len, + size_t *olen); + +/** + * \brief Entropy source state + */ +typedef struct mbedtls_entropy_source_state +{ + mbedtls_entropy_f_source_ptr MBEDTLS_PRIVATE(f_source); /**< The entropy source callback */ + void * MBEDTLS_PRIVATE(p_source); /**< The callback data pointer */ + size_t MBEDTLS_PRIVATE(size); /**< Amount received in bytes */ + size_t MBEDTLS_PRIVATE(threshold); /**< Minimum bytes required before release */ + int MBEDTLS_PRIVATE(strong); /**< Is the source strong? */ +} +mbedtls_entropy_source_state; + +/** + * \brief Entropy context structure + */ +typedef struct mbedtls_entropy_context +{ + int MBEDTLS_PRIVATE(accumulator_started); /* 0 after init. + * 1 after the first update. + * -1 after free. */ +#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) + mbedtls_sha512_context MBEDTLS_PRIVATE(accumulator); +#elif defined(MBEDTLS_ENTROPY_SHA256_ACCUMULATOR) + mbedtls_sha256_context MBEDTLS_PRIVATE(accumulator); +#endif + int MBEDTLS_PRIVATE(source_count); /* Number of entries used in source. */ + mbedtls_entropy_source_state MBEDTLS_PRIVATE(source)[MBEDTLS_ENTROPY_MAX_SOURCES]; +#if defined(MBEDTLS_THREADING_C) + mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); /*!< mutex */ +#endif +#if defined(MBEDTLS_ENTROPY_NV_SEED) + int MBEDTLS_PRIVATE(initial_entropy_run); +#endif +} +mbedtls_entropy_context; + +#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) +/** + * \brief Platform-specific entropy poll callback + */ +int mbedtls_platform_entropy_poll( void *data, + unsigned char *output, size_t len, size_t *olen ); +#endif + +/** + * \brief Initialize the context + * + * \param ctx Entropy context to initialize + */ +void mbedtls_entropy_init( mbedtls_entropy_context *ctx ); + +/** + * \brief Free the data in the context + * + * \param ctx Entropy context to free + */ +void mbedtls_entropy_free( mbedtls_entropy_context *ctx ); + +/** + * \brief Adds an entropy source to poll + * (Thread-safe if MBEDTLS_THREADING_C is enabled) + * + * \param ctx Entropy context + * \param f_source Entropy function + * \param p_source Function data + * \param threshold Minimum required from source before entropy is released + * ( with mbedtls_entropy_func() ) (in bytes) + * \param strong MBEDTLS_ENTROPY_SOURCE_STRONG or + * MBEDTLS_ENTROPY_SOURCE_WEAK. + * At least one strong source needs to be added. + * Weaker sources (such as the cycle counter) can be used as + * a complement. + * + * \return 0 if successful or MBEDTLS_ERR_ENTROPY_MAX_SOURCES + */ +int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx, + mbedtls_entropy_f_source_ptr f_source, void *p_source, + size_t threshold, int strong ); + +/** + * \brief Trigger an extra gather poll for the accumulator + * (Thread-safe if MBEDTLS_THREADING_C is enabled) + * + * \param ctx Entropy context + * + * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED + */ +int mbedtls_entropy_gather( mbedtls_entropy_context *ctx ); + +/** + * \brief Retrieve entropy from the accumulator + * (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE) + * (Thread-safe if MBEDTLS_THREADING_C is enabled) + * + * \param data Entropy context + * \param output Buffer to fill + * \param len Number of bytes desired, must be at most MBEDTLS_ENTROPY_BLOCK_SIZE + * + * \return 0 if successful, or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED + */ +int mbedtls_entropy_func( void *data, unsigned char *output, size_t len ); + +/** + * \brief Add data to the accumulator manually + * (Thread-safe if MBEDTLS_THREADING_C is enabled) + * + * \param ctx Entropy context + * \param data Data to add + * \param len Length of data + * + * \return 0 if successful + */ +int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx, + const unsigned char *data, size_t len ); + +#if defined(MBEDTLS_ENTROPY_NV_SEED) +/** + * \brief Trigger an update of the seed file in NV by using the + * current entropy pool. + * + * \param ctx Entropy context + * + * \return 0 if successful + */ +int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx ); +#endif /* MBEDTLS_ENTROPY_NV_SEED */ + +#if defined(MBEDTLS_FS_IO) +/** + * \brief Write a seed file + * + * \param ctx Entropy context + * \param path Name of the file + * + * \return 0 if successful, + * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error, or + * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED + */ +int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path ); + +/** + * \brief Read and update a seed file. Seed is added to this + * instance. No more than MBEDTLS_ENTROPY_MAX_SEED_SIZE bytes are + * read from the seed file. The rest is ignored. + * + * \param ctx Entropy context + * \param path Name of the file + * + * \return 0 if successful, + * MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR on file error, + * MBEDTLS_ERR_ENTROPY_SOURCE_FAILED + */ +int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path ); +#endif /* MBEDTLS_FS_IO */ + +#if defined(MBEDTLS_SELF_TEST) +/** + * \brief Checkup routine + * + * This module self-test also calls the entropy self-test, + * mbedtls_entropy_source_self_test(); + * + * \return 0 if successful, or 1 if a test failed + */ +int mbedtls_entropy_self_test( int verbose ); + +#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) +/** + * \brief Checkup routine + * + * Verifies the integrity of the hardware entropy source + * provided by the function 'mbedtls_hardware_poll()'. + * + * Note this is the only hardware entropy source that is known + * at link time, and other entropy sources configured + * dynamically at runtime by the function + * mbedtls_entropy_add_source() will not be tested. + * + * \return 0 if successful, or 1 if a test failed + */ +int mbedtls_entropy_source_self_test( int verbose ); +#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */ +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* entropy.h */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/error.h b/src/duckdb/third_party/mbedtls/include/mbedtls/error.h index d0c7c1e94..8b2b9ea58 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/error.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/error.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_ERROR_H #define MBEDTLS_ERROR_H @@ -14,6 +26,11 @@ #include +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) +#define inline __inline +#endif + /** * Error code layout. * @@ -61,12 +78,10 @@ * SHA1 1 0x0035-0x0035 0x0073-0x0073 * SHA256 1 0x0037-0x0037 0x0074-0x0074 * SHA512 1 0x0039-0x0039 0x0075-0x0075 - * SHA-3 1 0x0076-0x0076 * CHACHA20 3 0x0051-0x0055 * POLY1305 3 0x0057-0x005B * CHACHAPOLY 2 0x0054-0x0056 * PLATFORM 2 0x0070-0x0072 - * LMS 5 0x0011-0x0019 * * High-level module nr (3 bits - 0x0...-0x7...) * Name ID Nr of Errors @@ -80,7 +95,6 @@ * ECP 4 10 (Started from top) * MD 5 5 * HKDF 5 1 (Started from top) - * PKCS7 5 12 (Started from 0x5300) * SSL 5 2 (Started from 0x5F00) * CIPHER 6 8 (Started from 0x6080) * SSL 6 22 (Started from top, plus 0x6000) @@ -110,15 +124,15 @@ extern "C" { * Wrapper macro for mbedtls_error_add(). See that function for * more details. */ -#define MBEDTLS_ERROR_ADD(high, low) \ - mbedtls_error_add(high, low, __FILE__, __LINE__) +#define MBEDTLS_ERROR_ADD( high, low ) \ + mbedtls_error_add( high, low, __FILE__, __LINE__ ) #if defined(MBEDTLS_TEST_HOOKS) /** * \brief Testing hook called before adding/combining two error codes together. * Only used when invasive testing is enabled via MBEDTLS_TEST_HOOKS. */ -extern void (*mbedtls_test_hook_error_add)(int, int, const char *, int); +extern void (*mbedtls_test_hook_error_add)( int, int, const char *, int ); #endif /** @@ -139,30 +153,29 @@ extern void (*mbedtls_test_hook_error_add)(int, int, const char *, int); * \param file file where this error code addition occurred. * \param line line where this error code addition occurred. */ -inline int mbedtls_error_add(int high, int low, - const char *file, int line) +static inline int mbedtls_error_add( int high, int low, + const char *file, int line ) { #if defined(MBEDTLS_TEST_HOOKS) - if (*mbedtls_test_hook_error_add != NULL) { - (*mbedtls_test_hook_error_add)(high, low, file, line); - } + if( *mbedtls_test_hook_error_add != NULL ) + ( *mbedtls_test_hook_error_add )( high, low, file, line ); #endif - (void) file; - (void) line; + (void)file; + (void)line; - return high + low; + return( high + low ); } /** - * \brief Translate an Mbed TLS error code into a string representation. - * The result is truncated if necessary and always includes a - * terminating null byte. + * \brief Translate a mbed TLS error code into a string representation, + * Result is truncated if necessary and always includes a terminating + * null byte. * * \param errnum error code * \param buffer buffer to place representation in * \param buflen length of the buffer */ -void mbedtls_strerror(int errnum, char *buffer, size_t buflen); +void mbedtls_strerror( int errnum, char *buffer, size_t buflen ); /** * \brief Translate the high-level part of an Mbed TLS error code into a string @@ -177,7 +190,7 @@ void mbedtls_strerror(int errnum, char *buffer, size_t buflen); * \return The string representation of the error code, or \c NULL if the error * code is unknown. */ -const char *mbedtls_high_level_strerr(int error_code); +const char * mbedtls_high_level_strerr( int error_code ); /** * \brief Translate the low-level part of an Mbed TLS error code into a string @@ -192,7 +205,7 @@ const char *mbedtls_high_level_strerr(int error_code); * \return The string representation of the error code, or \c NULL if the error * code is unknown. */ -const char *mbedtls_low_level_strerr(int error_code); +const char * mbedtls_low_level_strerr( int error_code ); #ifdef __cplusplus } diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/gcm.h b/src/duckdb/third_party/mbedtls/include/mbedtls/gcm.h index 98faa4361..500b1ee6e 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/gcm.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/gcm.h @@ -13,7 +13,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_GCM_H @@ -24,10 +36,6 @@ #include "mbedtls/cipher.h" -#if defined(MBEDTLS_BLOCK_CIPHER_C) -#include "mbedtls/block_cipher.h" -#endif - #include #define MBEDTLS_GCM_ENCRYPT 1 @@ -46,36 +54,27 @@ extern "C" { #if !defined(MBEDTLS_GCM_ALT) -#if defined(MBEDTLS_GCM_LARGE_TABLE) -#define MBEDTLS_GCM_HTABLE_SIZE 256 -#else -#define MBEDTLS_GCM_HTABLE_SIZE 16 -#endif - /** * \brief The GCM context structure. */ -typedef struct mbedtls_gcm_context { -#if defined(MBEDTLS_BLOCK_CIPHER_C) - mbedtls_block_cipher_context_t MBEDTLS_PRIVATE(block_cipher_ctx); /*!< The cipher context used. */ -#else - mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */ -#endif - uint64_t MBEDTLS_PRIVATE(H)[MBEDTLS_GCM_HTABLE_SIZE][2]; /*!< Precalculated HTable. */ - uint64_t MBEDTLS_PRIVATE(len); /*!< The total length of the encrypted data. */ - uint64_t MBEDTLS_PRIVATE(add_len); /*!< The total length of the additional data. */ - unsigned char MBEDTLS_PRIVATE(base_ectr)[16]; /*!< The first ECTR for tag. */ - unsigned char MBEDTLS_PRIVATE(y)[16]; /*!< The Y working value. */ - unsigned char MBEDTLS_PRIVATE(buf)[16]; /*!< The buf working value. */ - unsigned char MBEDTLS_PRIVATE(mode); /*!< The operation to perform: - #MBEDTLS_GCM_ENCRYPT or - #MBEDTLS_GCM_DECRYPT. */ - unsigned char MBEDTLS_PRIVATE(acceleration); /*!< The acceleration to use. */ +typedef struct mbedtls_gcm_context +{ + mbedtls_cipher_context_t MBEDTLS_PRIVATE(cipher_ctx); /*!< The cipher context used. */ + uint64_t MBEDTLS_PRIVATE(HL)[16]; /*!< Precalculated HTable low. */ + uint64_t MBEDTLS_PRIVATE(HH)[16]; /*!< Precalculated HTable high. */ + uint64_t MBEDTLS_PRIVATE(len); /*!< The total length of the encrypted data. */ + uint64_t MBEDTLS_PRIVATE(add_len); /*!< The total length of the additional data. */ + unsigned char MBEDTLS_PRIVATE(base_ectr)[16]; /*!< The first ECTR for tag. */ + unsigned char MBEDTLS_PRIVATE(y)[16]; /*!< The Y working value. */ + unsigned char MBEDTLS_PRIVATE(buf)[16]; /*!< The buf working value. */ + int MBEDTLS_PRIVATE(mode); /*!< The operation to perform: + #MBEDTLS_GCM_ENCRYPT or + #MBEDTLS_GCM_DECRYPT. */ } mbedtls_gcm_context; #else /* !MBEDTLS_GCM_ALT */ -#include "gcm_alt.h" +#include "mbedtls/gcm_alt.h" #endif /* !MBEDTLS_GCM_ALT */ /** @@ -89,7 +88,7 @@ mbedtls_gcm_context; * * \param ctx The GCM context to initialize. This must not be \c NULL. */ -void mbedtls_gcm_init(mbedtls_gcm_context *ctx); +void mbedtls_gcm_init( mbedtls_gcm_context *ctx ); /** * \brief This function associates a GCM context with a @@ -107,10 +106,10 @@ void mbedtls_gcm_init(mbedtls_gcm_context *ctx); * \return \c 0 on success. * \return A cipher-specific error code on failure. */ -int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx, - mbedtls_cipher_id_t cipher, - const unsigned char *key, - unsigned int keybits); +int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, + mbedtls_cipher_id_t cipher, + const unsigned char *key, + unsigned int keybits ); /** * \brief This function performs GCM encryption or decryption of a buffer. @@ -163,17 +162,17 @@ int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx, * not valid or a cipher-specific error code if the encryption * or decryption failed. */ -int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx, - int mode, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *input, - unsigned char *output, - size_t tag_len, - unsigned char *tag); +int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, + int mode, + size_t length, + const unsigned char *iv, + size_t iv_len, + const unsigned char *add, + size_t add_len, + const unsigned char *input, + unsigned char *output, + size_t tag_len, + unsigned char *tag ); /** * \brief This function performs a GCM authenticated decryption of a @@ -208,16 +207,16 @@ int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx, * not valid or a cipher-specific error code if the decryption * failed. */ -int mbedtls_gcm_auth_decrypt(mbedtls_gcm_context *ctx, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *tag, - size_t tag_len, - const unsigned char *input, - unsigned char *output); +int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, + size_t length, + const unsigned char *iv, + size_t iv_len, + const unsigned char *add, + size_t add_len, + const unsigned char *tag, + size_t tag_len, + const unsigned char *input, + unsigned char *output ); /** * \brief This function starts a GCM encryption or decryption @@ -232,10 +231,10 @@ int mbedtls_gcm_auth_decrypt(mbedtls_gcm_context *ctx, * * \return \c 0 on success. */ -int mbedtls_gcm_starts(mbedtls_gcm_context *ctx, - int mode, - const unsigned char *iv, - size_t iv_len); +int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, + int mode, + const unsigned char *iv, + size_t iv_len ); /** * \brief This function feeds an input buffer as associated data @@ -257,9 +256,9 @@ int mbedtls_gcm_starts(mbedtls_gcm_context *ctx, * * \return \c 0 on success. */ -int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx, - const unsigned char *add, - size_t add_len); +int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx, + const unsigned char *add, + size_t add_len ); /** * \brief This function feeds an input buffer into an ongoing GCM @@ -312,10 +311,10 @@ int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx, * unsupported input/output buffer overlap detected, * or \p output_size too small. */ -int mbedtls_gcm_update(mbedtls_gcm_context *ctx, - const unsigned char *input, size_t input_length, - unsigned char *output, size_t output_size, - size_t *output_length); +int mbedtls_gcm_update( mbedtls_gcm_context *ctx, + const unsigned char *input, size_t input_length, + unsigned char *output, size_t output_size, + size_t *output_length ); /** * \brief This function finishes the GCM operation and generates @@ -350,10 +349,10 @@ int mbedtls_gcm_update(mbedtls_gcm_context *ctx, * invalid value of \p tag_len, * or \p output_size too small. */ -int mbedtls_gcm_finish(mbedtls_gcm_context *ctx, - unsigned char *output, size_t output_size, - size_t *output_length, - unsigned char *tag, size_t tag_len); +int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, + unsigned char *output, size_t output_size, + size_t *output_length, + unsigned char *tag, size_t tag_len ); /** * \brief This function clears a GCM context and the underlying @@ -362,7 +361,7 @@ int mbedtls_gcm_finish(mbedtls_gcm_context *ctx, * \param ctx The GCM context to clear. If this is \c NULL, the call has * no effect. Otherwise, this must be initialized. */ -void mbedtls_gcm_free(mbedtls_gcm_context *ctx); +void mbedtls_gcm_free( mbedtls_gcm_context *ctx ); #if defined(MBEDTLS_SELF_TEST) @@ -372,7 +371,7 @@ void mbedtls_gcm_free(mbedtls_gcm_context *ctx); * \return \c 0 on success. * \return \c 1 on failure. */ -int mbedtls_gcm_self_test(int verbose); +int mbedtls_gcm_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/mbedtls_config.h b/src/duckdb/third_party/mbedtls/include/mbedtls/mbedtls_config.h index 33d55af9a..6487c7123 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/mbedtls_config.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/mbedtls_config.h @@ -1,25 +1,20 @@ -// HM: beware of changes here -// there are patches in mbedtls_cipher_base_index & mbedtls_cipher_base_lookup_table -// that break if mbedtls features are changed - -#define MBEDTLS_AES_C -#define MBEDTLS_ASN1_PARSE_C -#define MBEDTLS_ASN1_WRITE_C -#define MBEDTLS_BASE64_C +#define MBEDTLS_SHA1_C +#define MBEDTLS_SHA256_C +#define MBEDTLS_SHA224_C +#define MBEDTLS_RSA_C +#define MBEDTLS_PKCS1_V15 #define MBEDTLS_BIGNUM_C -#define MBEDTLS_CCM_GCM_CAN_AES -#define MBEDTLS_CIPHER_C -#define MBEDTLS_DEPRECATED_REMOVED -#define MBEDTLS_GCM_C -#define MBEDTLS_MD_C -#define MBEDTLS_MD_CAN_SHA256 -#define MBEDTLS_MD_LIGHT #define MBEDTLS_OID_C -#define MBEDTLS_PEM_PARSE_C -#define MBEDTLS_PKCS1_V15 -#define MBEDTLS_PK_C +#define MBEDTLS_MD_C +#define MBEDTLS_BASE64_C #define MBEDTLS_PK_PARSE_C +#define MBEDTLS_ASN1_PARSE_C +#define MBEDTLS_PK_C +#define MBEDTLS_PEM_PARSE_C #define MBEDTLS_PLATFORM_C -#define MBEDTLS_RSA_C -#define MBEDTLS_SHA1_C -#define MBEDTLS_SHA256_C \ No newline at end of file +#define MBEDTLS_AES_C +#define MBEDTLS_CIPHER_C +#define MBEDTLS_CAMELLIA_C +#define MBEDTLS_ARIA_C +#define MBEDTLS_GCM_C +#define MBEDTLS_ENTROPY_C diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/md.h b/src/duckdb/third_party/mbedtls/include/mbedtls/md.h index 17c88d683..2b668f55e 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/md.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/md.h @@ -1,14 +1,25 @@ -/** + /** * \file md.h * - * \brief This file contains the generic functions for message-digest - * (hashing) and HMAC. + * \brief This file contains the generic message-digest wrapper. * * \author Adriaan de Jong */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_MD_H @@ -41,55 +52,25 @@ extern "C" { * stronger message digests instead. * */ -/* Note: these are aligned with the definitions of PSA_ALG_ macros for hashes, - * in order to enable an efficient implementation of conversion functions. - * This is tested by md_to_from_psa() in test_suite_md. */ typedef enum { MBEDTLS_MD_NONE=0, /**< None. */ - MBEDTLS_MD_MD5=0x03, /**< The MD5 message digest. */ - MBEDTLS_MD_RIPEMD160=0x04, /**< The RIPEMD-160 message digest. */ - MBEDTLS_MD_SHA1=0x05, /**< The SHA-1 message digest. */ - MBEDTLS_MD_SHA224=0x08, /**< The SHA-224 message digest. */ - MBEDTLS_MD_SHA256=0x09, /**< The SHA-256 message digest. */ - MBEDTLS_MD_SHA384=0x0a, /**< The SHA-384 message digest. */ - MBEDTLS_MD_SHA512=0x0b, /**< The SHA-512 message digest. */ - MBEDTLS_MD_SHA3_224=0x10, /**< The SHA3-224 message digest. */ - MBEDTLS_MD_SHA3_256=0x11, /**< The SHA3-256 message digest. */ - MBEDTLS_MD_SHA3_384=0x12, /**< The SHA3-384 message digest. */ - MBEDTLS_MD_SHA3_512=0x13, /**< The SHA3-512 message digest. */ + MBEDTLS_MD_MD5, /**< The MD5 message digest. */ + MBEDTLS_MD_SHA1, /**< The SHA-1 message digest. */ + MBEDTLS_MD_SHA224, /**< The SHA-224 message digest. */ + MBEDTLS_MD_SHA256, /**< The SHA-256 message digest. */ + MBEDTLS_MD_SHA384, /**< The SHA-384 message digest. */ + MBEDTLS_MD_SHA512, /**< The SHA-512 message digest. */ + MBEDTLS_MD_RIPEMD160, /**< The RIPEMD-160 message digest. */ } mbedtls_md_type_t; -/* Note: this should always be >= PSA_HASH_MAX_SIZE - * in all builds with both CRYPTO_C and MD_LIGHT. - * - * This is to make things easier for modules such as TLS that may define a - * buffer size using MD_MAX_SIZE in a part of the code that's common to PSA - * and legacy, then assume the buffer's size is PSA_HASH_MAX_SIZE in another - * part of the code based on PSA. - */ -#if defined(MBEDTLS_MD_CAN_SHA512) || defined(MBEDTLS_MD_CAN_SHA3_512) +#if defined(MBEDTLS_SHA512_C) #define MBEDTLS_MD_MAX_SIZE 64 /* longest known is SHA512 */ -#elif defined(MBEDTLS_MD_CAN_SHA384) || defined(MBEDTLS_MD_CAN_SHA3_384) -#define MBEDTLS_MD_MAX_SIZE 48 /* longest known is SHA384 */ -#elif defined(MBEDTLS_MD_CAN_SHA256) || defined(MBEDTLS_MD_CAN_SHA3_256) -#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 */ -#elif defined(MBEDTLS_MD_CAN_SHA224) || defined(MBEDTLS_MD_CAN_SHA3_224) -#define MBEDTLS_MD_MAX_SIZE 28 /* longest known is SHA224 */ #else -#define MBEDTLS_MD_MAX_SIZE 20 /* longest known is SHA1 or RIPE MD-160 - or smaller (MD5 and earlier) */ +#define MBEDTLS_MD_MAX_SIZE 32 /* longest known is SHA256 or less */ #endif -#if defined(MBEDTLS_MD_CAN_SHA3_224) -#define MBEDTLS_MD_MAX_BLOCK_SIZE 144 /* the longest known is SHA3-224 */ -#elif defined(MBEDTLS_MD_CAN_SHA3_256) -#define MBEDTLS_MD_MAX_BLOCK_SIZE 136 -#elif defined(MBEDTLS_MD_CAN_SHA512) || defined(MBEDTLS_MD_CAN_SHA384) +#if defined(MBEDTLS_SHA512_C) #define MBEDTLS_MD_MAX_BLOCK_SIZE 128 -#elif defined(MBEDTLS_MD_CAN_SHA3_384) -#define MBEDTLS_MD_MAX_BLOCK_SIZE 104 -#elif defined(MBEDTLS_MD_CAN_SHA3_512) -#define MBEDTLS_MD_MAX_BLOCK_SIZE 72 #else #define MBEDTLS_MD_MAX_BLOCK_SIZE 64 #endif @@ -106,37 +87,45 @@ typedef enum { /* Defined internally in library/md_wrap.h. */ typedef struct mbedtls_md_info_t mbedtls_md_info_t; -/** - * Used internally to indicate whether a context uses legacy or PSA. - * - * Internal use only. - */ -typedef enum { - MBEDTLS_MD_ENGINE_LEGACY = 0, - MBEDTLS_MD_ENGINE_PSA, -} mbedtls_md_engine_t; - /** * The generic message-digest context. */ -typedef struct mbedtls_md_context_t { +typedef struct mbedtls_md_context_t +{ /** Information about the associated message digest. */ const mbedtls_md_info_t *MBEDTLS_PRIVATE(md_info); -#if defined(MBEDTLS_MD_SOME_PSA) - /** Are hash operations dispatched to PSA or legacy? */ - mbedtls_md_engine_t MBEDTLS_PRIVATE(engine); -#endif - - /** The digest-specific context (legacy) or the PSA operation. */ + /** The digest-specific context. */ void *MBEDTLS_PRIVATE(md_ctx); -#if defined(MBEDTLS_MD_C) /** The HMAC part of the context. */ void *MBEDTLS_PRIVATE(hmac_ctx); -#endif } mbedtls_md_context_t; +/** + * \brief This function returns the list of digests supported by the + * generic digest module. + * + * \note The list starts with the strongest available hashes. + * + * \return A statically allocated array of digests. Each element + * in the returned list is an integer belonging to the + * message-digest enumeration #mbedtls_md_type_t. + * The last entry is 0. + */ +const int *mbedtls_md_list( void ); + +/** + * \brief This function returns the message-digest information + * associated with the given digest name. + * + * \param md_name The name of the digest to search for. + * + * \return The message-digest information associated with \p md_name. + * \return NULL if the associated message-digest information is not found. + */ +const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ); + /** * \brief This function returns the message-digest information * associated with the given digest type. @@ -146,7 +135,7 @@ typedef struct mbedtls_md_context_t { * \return The message-digest information associated with \p md_type. * \return NULL if the associated message-digest information is not found. */ -const mbedtls_md_info_t *mbedtls_md_info_from_type(mbedtls_md_type_t md_type); +const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type ); /** * \brief This function initializes a message-digest context without @@ -156,7 +145,7 @@ const mbedtls_md_info_t *mbedtls_md_info_from_type(mbedtls_md_type_t md_type); * context for mbedtls_md_setup() for binding it to a * message-digest algorithm. */ -void mbedtls_md_init(mbedtls_md_context_t *ctx); +void mbedtls_md_init( mbedtls_md_context_t *ctx ); /** * \brief This function clears the internal structure of \p ctx and @@ -171,7 +160,7 @@ void mbedtls_md_init(mbedtls_md_context_t *ctx); * You must not call this function if you have not called * mbedtls_md_init(). */ -void mbedtls_md_free(mbedtls_md_context_t *ctx); +void mbedtls_md_free( mbedtls_md_context_t *ctx ); /** @@ -194,10 +183,10 @@ void mbedtls_md_free(mbedtls_md_context_t *ctx); * \return #MBEDTLS_ERR_MD_ALLOC_FAILED on memory-allocation failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac); +int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ); /** - * \brief This function clones the state of a message-digest + * \brief This function clones the state of an message-digest * context. * * \note You must call mbedtls_md_setup() on \c dst before calling @@ -214,14 +203,10 @@ int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info * * \return \c 0 on success. * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA on parameter-verification failure. - * \return #MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE if both contexts are - * not using the same engine. This can be avoided by moving - * the call to psa_crypto_init() before the first call to - * mbedtls_md_setup(). */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_clone(mbedtls_md_context_t *dst, - const mbedtls_md_context_t *src); +int mbedtls_md_clone( mbedtls_md_context_t *dst, + const mbedtls_md_context_t *src ); /** * \brief This function extracts the message-digest size from the @@ -232,32 +217,29 @@ int mbedtls_md_clone(mbedtls_md_context_t *dst, * * \return The size of the message-digest output in Bytes. */ -unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info); +unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info ); /** - * \brief This function gives the message-digest size associated to - * message-digest type. + * \brief This function extracts the message-digest type from the + * message-digest information structure. * - * \param md_type The message-digest type. + * \param md_info The information structure of the message-digest algorithm + * to use. * - * \return The size of the message-digest output in Bytes, - * or 0 if the message-digest type is not known. + * \return The type of the message digest. */ -inline unsigned char mbedtls_md_get_size_from_type(mbedtls_md_type_t md_type) -{ - return mbedtls_md_get_size(mbedtls_md_info_from_type(md_type)); -} +mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info ); /** - * \brief This function extracts the message-digest type from the + * \brief This function extracts the message-digest name from the * message-digest information structure. * * \param md_info The information structure of the message-digest algorithm * to use. * - * \return The type of the message digest. + * \return The name of the message digest. */ -mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info); +const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info ); /** * \brief This function starts a message-digest computation. @@ -273,7 +255,7 @@ mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info); * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_starts(mbedtls_md_context_t *ctx); +int mbedtls_md_starts( mbedtls_md_context_t *ctx ); /** * \brief This function feeds an input buffer into an ongoing @@ -292,7 +274,7 @@ int mbedtls_md_starts(mbedtls_md_context_t *ctx); * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen); +int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ); /** * \brief This function finishes the digest operation, @@ -313,7 +295,7 @@ int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, siz * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output); +int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ); /** * \brief This function calculates the message-digest of a buffer, @@ -334,56 +316,8 @@ int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output); * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, - unsigned char *output); - -/** - * \brief This function returns the list of digests supported by the - * generic digest module. - * - * \note The list starts with the strongest available hashes. - * - * \return A statically allocated array of digests. Each element - * in the returned list is an integer belonging to the - * message-digest enumeration #mbedtls_md_type_t. - * The last entry is 0. - */ -const int *mbedtls_md_list(void); - -/** - * \brief This function returns the message-digest information - * associated with the given digest name. - * - * \param md_name The name of the digest to search for. - * - * \return The message-digest information associated with \p md_name. - * \return NULL if the associated message-digest information is not found. - */ -const mbedtls_md_info_t *mbedtls_md_info_from_string(const char *md_name); - -/** - * \brief This function returns the name of the message digest for - * the message-digest information structure given. - * - * \param md_info The information structure of the message-digest algorithm - * to use. - * - * \return The name of the message digest. - */ -const char *mbedtls_md_get_name(const mbedtls_md_info_t *md_info); - -/** - * \brief This function returns the message-digest information - * from the given context. - * - * \param ctx The context from which to extract the information. - * This must be initialized (or \c NULL). - * - * \return The message-digest information associated with \p ctx. - * \return \c NULL if \p ctx is \c NULL. - */ -const mbedtls_md_info_t *mbedtls_md_info_from_ctx( - const mbedtls_md_context_t *ctx); +int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, + unsigned char *output ); #if defined(MBEDTLS_FS_IO) /** @@ -404,8 +338,8 @@ const mbedtls_md_info_t *mbedtls_md_info_from_ctx( * \return #MBEDTLS_ERR_MD_BAD_INPUT_DATA if \p md_info was NULL. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path, - unsigned char *output); +int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, + unsigned char *output ); #endif /* MBEDTLS_FS_IO */ /** @@ -427,8 +361,8 @@ int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path, * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, - size_t keylen); +int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, + size_t keylen ); /** * \brief This function feeds an input buffer into an ongoing HMAC @@ -450,8 +384,8 @@ int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input, - size_t ilen); +int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, + size_t ilen ); /** * \brief This function finishes the HMAC operation, and writes @@ -472,7 +406,7 @@ int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output); +int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output); /** * \brief This function prepares to authenticate a new message with @@ -490,7 +424,7 @@ int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output); * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx); +int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ); /** * \brief This function calculates the full generic HMAC @@ -515,9 +449,13 @@ int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx); * failure. */ MBEDTLS_CHECK_RETURN_TYPICAL -int mbedtls_md_hmac(const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen, - const unsigned char *input, size_t ilen, - unsigned char *output); +int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, const unsigned char *key, size_t keylen, + const unsigned char *input, size_t ilen, + unsigned char *output ); + +/* Internal use */ +MBEDTLS_CHECK_RETURN_TYPICAL +int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data ); #ifdef __cplusplus } diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/memory_buffer_alloc.h b/src/duckdb/third_party/mbedtls/include/mbedtls/memory_buffer_alloc.h index b527d9b66..d4737f5c4 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/memory_buffer_alloc.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/memory_buffer_alloc.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_MEMORY_BUFFER_ALLOC_H #define MBEDTLS_MEMORY_BUFFER_ALLOC_H @@ -26,13 +38,12 @@ #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ #endif -/** \} name SECTION: Module settings */ +/* \} name SECTION: Module settings */ #define MBEDTLS_MEMORY_VERIFY_NONE 0 #define MBEDTLS_MEMORY_VERIFY_ALLOC (1 << 0) #define MBEDTLS_MEMORY_VERIFY_FREE (1 << 1) -#define MBEDTLS_MEMORY_VERIFY_ALWAYS (MBEDTLS_MEMORY_VERIFY_ALLOC | \ - MBEDTLS_MEMORY_VERIFY_FREE) +#define MBEDTLS_MEMORY_VERIFY_ALWAYS (MBEDTLS_MEMORY_VERIFY_ALLOC | MBEDTLS_MEMORY_VERIFY_FREE) #ifdef __cplusplus extern "C" { @@ -53,12 +64,12 @@ extern "C" { * \param buf buffer to use as heap * \param len size of the buffer */ -void mbedtls_memory_buffer_alloc_init(unsigned char *buf, size_t len); +void mbedtls_memory_buffer_alloc_init( unsigned char *buf, size_t len ); /** * \brief Free the mutex for thread-safety and clear remaining memory */ -void mbedtls_memory_buffer_alloc_free(void); +void mbedtls_memory_buffer_alloc_free( void ); /** * \brief Determine when the allocator should automatically verify the state @@ -68,7 +79,7 @@ void mbedtls_memory_buffer_alloc_free(void); * \param verify One of MBEDTLS_MEMORY_VERIFY_NONE, MBEDTLS_MEMORY_VERIFY_ALLOC, * MBEDTLS_MEMORY_VERIFY_FREE or MBEDTLS_MEMORY_VERIFY_ALWAYS */ -void mbedtls_memory_buffer_set_verify(int verify); +void mbedtls_memory_buffer_set_verify( int verify ); #if defined(MBEDTLS_MEMORY_DEBUG) /** @@ -77,15 +88,7 @@ void mbedtls_memory_buffer_set_verify(int verify); * Prints out a list of 'still allocated' blocks and their stack * trace if MBEDTLS_MEMORY_BACKTRACE is defined. */ -void mbedtls_memory_buffer_alloc_status(void); - -/** - * \brief Get the number of alloc/free so far. - * - * \param alloc_count Number of allocations. - * \param free_count Number of frees. - */ -void mbedtls_memory_buffer_alloc_count_get(size_t *alloc_count, size_t *free_count); +void mbedtls_memory_buffer_alloc_status( void ); /** * \brief Get the peak heap usage so far @@ -95,12 +98,12 @@ void mbedtls_memory_buffer_alloc_count_get(size_t *alloc_count, size_t *free_cou * into smaller blocks but larger than the requested size. * \param max_blocks Peak number of blocks in use, including free and used */ -void mbedtls_memory_buffer_alloc_max_get(size_t *max_used, size_t *max_blocks); +void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks ); /** * \brief Reset peak statistics */ -void mbedtls_memory_buffer_alloc_max_reset(void); +void mbedtls_memory_buffer_alloc_max_reset( void ); /** * \brief Get the current heap usage @@ -110,7 +113,7 @@ void mbedtls_memory_buffer_alloc_max_reset(void); * into smaller blocks but larger than the requested size. * \param cur_blocks Current number of blocks in use, including free and used */ -void mbedtls_memory_buffer_alloc_cur_get(size_t *cur_used, size_t *cur_blocks); +void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks ); #endif /* MBEDTLS_MEMORY_DEBUG */ /** @@ -124,7 +127,7 @@ void mbedtls_memory_buffer_alloc_cur_get(size_t *cur_used, size_t *cur_blocks); * * \return 0 if verified, 1 otherwise */ -int mbedtls_memory_buffer_alloc_verify(void); +int mbedtls_memory_buffer_alloc_verify( void ); #if defined(MBEDTLS_SELF_TEST) /** @@ -132,7 +135,7 @@ int mbedtls_memory_buffer_alloc_verify(void); * * \return 0 if successful, or 1 if a test failed */ -int mbedtls_memory_buffer_alloc_self_test(int verbose); +int mbedtls_memory_buffer_alloc_self_test( int verbose ); #endif #ifdef __cplusplus diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/oid.h b/src/duckdb/third_party/mbedtls/include/mbedtls/oid.h index fdc25ebf8..836e455b3 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/oid.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/oid.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_OID_H #define MBEDTLS_OID_H @@ -22,7 +34,9 @@ #include "mbedtls/cipher.h" #endif +#if defined(MBEDTLS_MD_C) #include "mbedtls/md.h" +#endif /** OID is not found. */ #define MBEDTLS_ERR_OID_NOT_FOUND -0x002E @@ -51,11 +65,6 @@ #define MBEDTLS_OID_X509_EXT_FRESHEST_CRL (1 << 14) #define MBEDTLS_OID_X509_EXT_NS_CERT_TYPE (1 << 16) -/* - * Maximum number of OID components allowed - */ -#define MBEDTLS_OID_MAX_COMPONENTS 128 - /* * Top level OID tuples */ @@ -70,10 +79,10 @@ #define MBEDTLS_OID_COUNTRY_US "\x86\x48" /* {us(840)} */ #define MBEDTLS_OID_ORG_RSA_DATA_SECURITY "\x86\xf7\x0d" /* {rsadsi(113549)} */ #define MBEDTLS_OID_RSA_COMPANY MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \ - MBEDTLS_OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) rsadsi(113549)} */ + MBEDTLS_OID_ORG_RSA_DATA_SECURITY /* {iso(1) member-body(2) us(840) rsadsi(113549)} */ #define MBEDTLS_OID_ORG_ANSI_X9_62 "\xce\x3d" /* ansi-X9-62(10045) */ #define MBEDTLS_OID_ANSI_X9_62 MBEDTLS_OID_ISO_MEMBER_BODIES MBEDTLS_OID_COUNTRY_US \ - MBEDTLS_OID_ORG_ANSI_X9_62 + MBEDTLS_OID_ORG_ANSI_X9_62 /* * ISO Identified organization OID parts @@ -83,22 +92,16 @@ #define MBEDTLS_OID_OIW_SECSIG MBEDTLS_OID_ORG_OIW "\x03" #define MBEDTLS_OID_OIW_SECSIG_ALG MBEDTLS_OID_OIW_SECSIG "\x02" #define MBEDTLS_OID_OIW_SECSIG_SHA1 MBEDTLS_OID_OIW_SECSIG_ALG "\x1a" -#define MBEDTLS_OID_ORG_THAWTE "\x65" /* thawte(101) */ -#define MBEDTLS_OID_THAWTE MBEDTLS_OID_ISO_IDENTIFIED_ORG \ - MBEDTLS_OID_ORG_THAWTE #define MBEDTLS_OID_ORG_CERTICOM "\x81\x04" /* certicom(132) */ -#define MBEDTLS_OID_CERTICOM MBEDTLS_OID_ISO_IDENTIFIED_ORG \ - MBEDTLS_OID_ORG_CERTICOM +#define MBEDTLS_OID_CERTICOM MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_CERTICOM #define MBEDTLS_OID_ORG_TELETRUST "\x24" /* teletrust(36) */ -#define MBEDTLS_OID_TELETRUST MBEDTLS_OID_ISO_IDENTIFIED_ORG \ - MBEDTLS_OID_ORG_TELETRUST +#define MBEDTLS_OID_TELETRUST MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_TELETRUST /* * ISO ITU OID parts */ #define MBEDTLS_OID_ORGANIZATION "\x01" /* {organization(1)} */ -#define MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ISO_ITU_COUNTRY MBEDTLS_OID_COUNTRY_US \ - MBEDTLS_OID_ORGANIZATION /* {joint-iso-itu-t(2) country(16) us(840) organization(1)} */ +#define MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ISO_ITU_COUNTRY MBEDTLS_OID_COUNTRY_US MBEDTLS_OID_ORGANIZATION /* {joint-iso-itu-t(2) country(16) us(840) organization(1)} */ #define MBEDTLS_OID_ORG_GOV "\x65" /* {gov(101)} */ #define MBEDTLS_OID_GOV MBEDTLS_OID_ISO_ITU_US_ORG MBEDTLS_OID_ORG_GOV /* {joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101)} */ @@ -116,8 +119,7 @@ * { iso(1) identified-organization(3) dod(6) internet(1) * security(5) mechanisms(5) pkix(7) } */ -#define MBEDTLS_OID_INTERNET MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD \ - "\x01" +#define MBEDTLS_OID_INTERNET MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_ORG_DOD "\x01" #define MBEDTLS_OID_PKIX MBEDTLS_OID_INTERNET "\x05\x05\x07" /* @@ -138,7 +140,7 @@ #define MBEDTLS_OID_AT_GIVEN_NAME MBEDTLS_OID_AT "\x2A" /**< id-at-givenName AttributeType:= {id-at 42} */ #define MBEDTLS_OID_AT_INITIALS MBEDTLS_OID_AT "\x2B" /**< id-at-initials AttributeType:= {id-at 43} */ #define MBEDTLS_OID_AT_GENERATION_QUALIFIER MBEDTLS_OID_AT "\x2C" /**< id-at-generationQualifier AttributeType:= {id-at 44} */ -#define MBEDTLS_OID_AT_UNIQUE_IDENTIFIER MBEDTLS_OID_AT "\x2D" /**< id-at-uniqueIdentifier AttributeType:= {id-at 45} */ +#define MBEDTLS_OID_AT_UNIQUE_IDENTIFIER MBEDTLS_OID_AT "\x2D" /**< id-at-uniqueIdentifier AttributType:= {id-at 45} */ #define MBEDTLS_OID_AT_DN_QUALIFIER MBEDTLS_OID_AT "\x2E" /**< id-at-dnQualifier AttributeType:= {id-at 46} */ #define MBEDTLS_OID_AT_PSEUDONYM MBEDTLS_OID_AT "\x41" /**< id-at-pseudonym AttributeType:= {id-at 65} */ @@ -220,7 +222,6 @@ #define MBEDTLS_OID_PKCS MBEDTLS_OID_RSA_COMPANY "\x01" /**< pkcs OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) 1 } */ #define MBEDTLS_OID_PKCS1 MBEDTLS_OID_PKCS "\x01" /**< pkcs-1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 1 } */ #define MBEDTLS_OID_PKCS5 MBEDTLS_OID_PKCS "\x05" /**< pkcs-5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 5 } */ -#define MBEDTLS_OID_PKCS7 MBEDTLS_OID_PKCS "\x07" /**< pkcs-7 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 7 } */ #define MBEDTLS_OID_PKCS9 MBEDTLS_OID_PKCS "\x09" /**< pkcs-9 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 9 } */ #define MBEDTLS_OID_PKCS12 MBEDTLS_OID_PKCS "\x0c" /**< pkcs-12 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) 12 } */ @@ -247,8 +248,7 @@ * Digest algorithms */ #define MBEDTLS_OID_DIGEST_ALG_MD5 MBEDTLS_OID_RSA_COMPANY "\x02\x05" /**< id-mbedtls_md5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 5 } */ -#define MBEDTLS_OID_DIGEST_ALG_SHA1 MBEDTLS_OID_ISO_IDENTIFIED_ORG \ - MBEDTLS_OID_OIW_SECSIG_SHA1 /**< id-mbedtls_sha1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 26 } */ +#define MBEDTLS_OID_DIGEST_ALG_SHA1 MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_SHA1 /**< id-mbedtls_sha1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 26 } */ #define MBEDTLS_OID_DIGEST_ALG_SHA224 MBEDTLS_OID_NIST_ALG "\x02\x04" /**< id-sha224 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 4 } */ #define MBEDTLS_OID_DIGEST_ALG_SHA256 MBEDTLS_OID_NIST_ALG "\x02\x01" /**< id-mbedtls_sha256 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistalgorithm(4) hashalgs(2) 1 } */ @@ -258,15 +258,6 @@ #define MBEDTLS_OID_DIGEST_ALG_RIPEMD160 MBEDTLS_OID_TELETRUST "\x03\x02\x01" /**< id-ripemd160 OBJECT IDENTIFIER :: { iso(1) identified-organization(3) teletrust(36) algorithm(3) hashAlgorithm(2) ripemd160(1) } */ -#define MBEDTLS_OID_DIGEST_ALG_SHA3_224 MBEDTLS_OID_NIST_ALG "\x02\x07" /**< id-sha3-224 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) sha3-224(7) } */ - -#define MBEDTLS_OID_DIGEST_ALG_SHA3_256 MBEDTLS_OID_NIST_ALG "\x02\x08" /**< id-sha3-256 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) sha3-256(8) } */ - -#define MBEDTLS_OID_DIGEST_ALG_SHA3_384 MBEDTLS_OID_NIST_ALG "\x02\x09" /**< id-sha3-384 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) sha3-384(9) } */ - -#define MBEDTLS_OID_DIGEST_ALG_SHA3_512 MBEDTLS_OID_NIST_ALG "\x02\x0a" /**< id-sha3-512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) sha3-512(10) } */ - - #define MBEDTLS_OID_HMAC_SHA1 MBEDTLS_OID_RSA_COMPANY "\x02\x07" /**< id-hmacWithSHA1 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 7 } */ #define MBEDTLS_OID_HMAC_SHA224 MBEDTLS_OID_RSA_COMPANY "\x02\x08" /**< id-hmacWithSHA224 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 8 } */ @@ -277,28 +268,12 @@ #define MBEDTLS_OID_HMAC_SHA512 MBEDTLS_OID_RSA_COMPANY "\x02\x0B" /**< id-hmacWithSHA512 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2) 11 } */ -#define MBEDTLS_OID_HMAC_SHA3_224 MBEDTLS_OID_NIST_ALG "\x02\x0d" /**< id-hmacWithSHA3-512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) hmacWithSHA3-224(13) } */ - -#define MBEDTLS_OID_HMAC_SHA3_256 MBEDTLS_OID_NIST_ALG "\x02\x0e" /**< id-hmacWithSHA3-512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) hmacWithSHA3-256(14) } */ - -#define MBEDTLS_OID_HMAC_SHA3_384 MBEDTLS_OID_NIST_ALG "\x02\x0f" /**< id-hmacWithSHA3-512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) hmacWithSHA3-384(15) } */ - -#define MBEDTLS_OID_HMAC_SHA3_512 MBEDTLS_OID_NIST_ALG "\x02\x10" /**< id-hmacWithSHA3-512 OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) hashalgs(2) hmacWithSHA3-512(16) } */ - -#define MBEDTLS_OID_HMAC_RIPEMD160 MBEDTLS_OID_INTERNET "\x05\x05\x08\x01\x04" /**< id-hmacWithSHA1 OBJECT IDENTIFIER ::= {iso(1) iso-identified-organization(3) dod(6) internet(1) security(5) mechanisms(5) ipsec(8) isakmpOakley(1) hmacRIPEMD160(4)} */ - /* - * Encryption algorithms, - * the following standardized object identifiers are specified at - * https://datatracker.ietf.org/doc/html/rfc8018#appendix-C. + * Encryption algorithms */ -#define MBEDTLS_OID_DES_CBC MBEDTLS_OID_ISO_IDENTIFIED_ORG \ - MBEDTLS_OID_OIW_SECSIG_ALG "\x07" /**< desCBC OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 7 } */ +#define MBEDTLS_OID_DES_CBC MBEDTLS_OID_ISO_IDENTIFIED_ORG MBEDTLS_OID_OIW_SECSIG_ALG "\x07" /**< desCBC OBJECT IDENTIFIER ::= { iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2) 7 } */ #define MBEDTLS_OID_DES_EDE3_CBC MBEDTLS_OID_RSA_COMPANY "\x03\x07" /**< des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) -- us(840) rsadsi(113549) encryptionAlgorithm(3) 7 } */ #define MBEDTLS_OID_AES MBEDTLS_OID_NIST_ALG "\x01" /** aes OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithm(4) 1 } */ -#define MBEDTLS_OID_AES_128_CBC MBEDTLS_OID_AES "\x02" /** aes128-cbc-pad OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) aes(1) aes128-CBC-PAD(2) } */ -#define MBEDTLS_OID_AES_192_CBC MBEDTLS_OID_AES "\x16" /** aes192-cbc-pad OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) aes(1) aes192-CBC-PAD(22) } */ -#define MBEDTLS_OID_AES_256_CBC MBEDTLS_OID_AES "\x2a" /** aes256-cbc-pad OBJECT IDENTIFIER ::= { joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithms(4) aes(1) aes256-CBC-PAD(42) } */ /* * Key Wrapping algorithms @@ -327,16 +302,6 @@ #define MBEDTLS_OID_PKCS5_PBE_SHA1_DES_CBC MBEDTLS_OID_PKCS5 "\x0a" /**< pbeWithSHA1AndDES-CBC OBJECT IDENTIFIER ::= {pkcs-5 10} */ #define MBEDTLS_OID_PKCS5_PBE_SHA1_RC2_CBC MBEDTLS_OID_PKCS5 "\x0b" /**< pbeWithSHA1AndRC2-CBC OBJECT IDENTIFIER ::= {pkcs-5 11} */ -/* - * PKCS#7 OIDs - */ -#define MBEDTLS_OID_PKCS7_DATA MBEDTLS_OID_PKCS7 "\x01" /**< Content type is Data OBJECT IDENTIFIER ::= {pkcs-7 1} */ -#define MBEDTLS_OID_PKCS7_SIGNED_DATA MBEDTLS_OID_PKCS7 "\x02" /**< Content type is Signed Data OBJECT IDENTIFIER ::= {pkcs-7 2} */ -#define MBEDTLS_OID_PKCS7_ENVELOPED_DATA MBEDTLS_OID_PKCS7 "\x03" /**< Content type is Enveloped Data OBJECT IDENTIFIER ::= {pkcs-7 3} */ -#define MBEDTLS_OID_PKCS7_SIGNED_AND_ENVELOPED_DATA MBEDTLS_OID_PKCS7 "\x04" /**< Content type is Signed and Enveloped Data OBJECT IDENTIFIER ::= {pkcs-7 4} */ -#define MBEDTLS_OID_PKCS7_DIGESTED_DATA MBEDTLS_OID_PKCS7 "\x05" /**< Content type is Digested Data OBJECT IDENTIFIER ::= {pkcs-7 5} */ -#define MBEDTLS_OID_PKCS7_ENCRYPTED_DATA MBEDTLS_OID_PKCS7 "\x06" /**< Content type is Encrypted Data OBJECT IDENTIFIER ::= {pkcs-7 6} */ - /* * PKCS#8 OIDs */ @@ -457,15 +422,6 @@ * ecdsa-with-SHA2(3) 4 } */ #define MBEDTLS_OID_ECDSA_SHA512 MBEDTLS_OID_ANSI_X9_62_SIG_SHA2 "\x04" -/* - * EC key algorithms from RFC 8410 - */ - -#define MBEDTLS_OID_X25519 MBEDTLS_OID_THAWTE "\x6e" /**< id-X25519 OBJECT IDENTIFIER ::= { 1 3 101 110 } */ -#define MBEDTLS_OID_X448 MBEDTLS_OID_THAWTE "\x6f" /**< id-X448 OBJECT IDENTIFIER ::= { 1 3 101 111 } */ -#define MBEDTLS_OID_ED25519 MBEDTLS_OID_THAWTE "\x70" /**< id-Ed25519 OBJECT IDENTIFIER ::= { 1 3 101 112 } */ -#define MBEDTLS_OID_ED448 MBEDTLS_OID_THAWTE "\x71" /**< id-Ed448 OBJECT IDENTIFIER ::= { 1 3 101 113 } */ - #ifdef __cplusplus extern "C" { #endif @@ -473,7 +429,8 @@ extern "C" { /** * \brief Base OID descriptor structure */ -typedef struct mbedtls_oid_descriptor_t { +typedef struct mbedtls_oid_descriptor_t +{ const char *MBEDTLS_PRIVATE(asn1); /*!< OID ASN.1 representation */ size_t MBEDTLS_PRIVATE(asn1_len); /*!< length of asn1 */ #if !defined(MBEDTLS_X509_REMOVE_INFO) @@ -493,26 +450,7 @@ typedef struct mbedtls_oid_descriptor_t { * \return Length of the string written (excluding final NULL) or * MBEDTLS_ERR_OID_BUF_TOO_SMALL in case of error */ -int mbedtls_oid_get_numeric_string(char *buf, size_t size, const mbedtls_asn1_buf *oid); - -/** - * \brief Translate a string containing a dotted-decimal - * representation of an ASN.1 OID into its encoded form - * (e.g. "1.2.840.113549" into "\x2A\x86\x48\x86\xF7\x0D"). - * On success, this function allocates oid->buf from the - * heap. It must be freed by the caller using mbedtls_free(). - * - * \param oid #mbedtls_asn1_buf to populate with the DER-encoded OID - * \param oid_str string representation of the OID to parse - * \param size length of the OID string, not including any null terminator - * - * \return 0 if successful - * \return #MBEDTLS_ERR_ASN1_INVALID_DATA if \p oid_str does not - * represent a valid OID - * \return #MBEDTLS_ERR_ASN1_ALLOC_FAILED if the function fails to - * allocate oid->buf - */ -int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, const char *oid_str, size_t size); +int mbedtls_oid_get_numeric_string( char *buf, size_t size, const mbedtls_asn1_buf *oid ); /** * \brief Translate an X.509 extension OID into local values @@ -522,7 +460,7 @@ int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, const char *oid_str, * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_x509_ext_type(const mbedtls_asn1_buf *oid, int *ext_type); +int mbedtls_oid_get_x509_ext_type( const mbedtls_asn1_buf *oid, int *ext_type ); /** * \brief Translate an X.509 attribute type OID into the short name @@ -533,7 +471,7 @@ int mbedtls_oid_get_x509_ext_type(const mbedtls_asn1_buf *oid, int *ext_type); * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_attr_short_name(const mbedtls_asn1_buf *oid, const char **short_name); +int mbedtls_oid_get_attr_short_name( const mbedtls_asn1_buf *oid, const char **short_name ); /** * \brief Translate PublicKeyAlgorithm OID into pk_type @@ -543,7 +481,7 @@ int mbedtls_oid_get_attr_short_name(const mbedtls_asn1_buf *oid, const char **sh * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_pk_alg(const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_alg); +int mbedtls_oid_get_pk_alg( const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_alg ); /** * \brief Translate pk_type into PublicKeyAlgorithm OID @@ -554,10 +492,10 @@ int mbedtls_oid_get_pk_alg(const mbedtls_asn1_buf *oid, mbedtls_pk_type_t *pk_al * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_oid_by_pk_alg(mbedtls_pk_type_t pk_alg, - const char **oid, size_t *olen); +int mbedtls_oid_get_oid_by_pk_alg( mbedtls_pk_type_t pk_alg, + const char **oid, size_t *olen ); -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_ECP_C) /** * \brief Translate NamedCurve OID into an EC group identifier * @@ -566,7 +504,7 @@ int mbedtls_oid_get_oid_by_pk_alg(mbedtls_pk_type_t pk_alg, * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_ec_grp(const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id); +int mbedtls_oid_get_ec_grp( const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id ); /** * \brief Translate EC group identifier into NamedCurve OID @@ -577,34 +515,11 @@ int mbedtls_oid_get_ec_grp(const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *gr * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_oid_by_ec_grp(mbedtls_ecp_group_id grp_id, - const char **oid, size_t *olen); - -/** - * \brief Translate AlgorithmIdentifier OID into an EC group identifier, - * for curves that are directly encoded at this level - * - * \param oid OID to use - * \param grp_id place to store group id - * - * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND - */ -int mbedtls_oid_get_ec_grp_algid(const mbedtls_asn1_buf *oid, mbedtls_ecp_group_id *grp_id); - -/** - * \brief Translate EC group identifier into AlgorithmIdentifier OID, - * for curves that are directly encoded at this level - * - * \param grp_id EC group identifier - * \param oid place to store ASN.1 OID string pointer - * \param olen length of the OID - * - * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND - */ -int mbedtls_oid_get_oid_by_ec_grp_algid(mbedtls_ecp_group_id grp_id, - const char **oid, size_t *olen); -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ +int mbedtls_oid_get_oid_by_ec_grp( mbedtls_ecp_group_id grp_id, + const char **oid, size_t *olen ); +#endif /* MBEDTLS_ECP_C */ +#if defined(MBEDTLS_MD_C) /** * \brief Translate SignatureAlgorithm OID into md_type and pk_type * @@ -614,8 +529,8 @@ int mbedtls_oid_get_oid_by_ec_grp_algid(mbedtls_ecp_group_id grp_id, * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_sig_alg(const mbedtls_asn1_buf *oid, - mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg); +int mbedtls_oid_get_sig_alg( const mbedtls_asn1_buf *oid, + mbedtls_md_type_t *md_alg, mbedtls_pk_type_t *pk_alg ); /** * \brief Translate SignatureAlgorithm OID into description @@ -625,7 +540,7 @@ int mbedtls_oid_get_sig_alg(const mbedtls_asn1_buf *oid, * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_sig_alg_desc(const mbedtls_asn1_buf *oid, const char **desc); +int mbedtls_oid_get_sig_alg_desc( const mbedtls_asn1_buf *oid, const char **desc ); /** * \brief Translate md_type and pk_type into SignatureAlgorithm OID @@ -637,28 +552,29 @@ int mbedtls_oid_get_sig_alg_desc(const mbedtls_asn1_buf *oid, const char **desc) * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_oid_by_sig_alg(mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, - const char **oid, size_t *olen); +int mbedtls_oid_get_oid_by_sig_alg( mbedtls_pk_type_t pk_alg, mbedtls_md_type_t md_alg, + const char **oid, size_t *olen ); /** - * \brief Translate hmac algorithm OID into md_type + * \brief Translate hash algorithm OID into md_type * * \param oid OID to use - * \param md_hmac place to store message hmac algorithm + * \param md_alg place to store message digest algorithm * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_md_hmac(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac); +int mbedtls_oid_get_md_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg ); /** - * \brief Translate hash algorithm OID into md_type + * \brief Translate hmac algorithm OID into md_type * * \param oid OID to use - * \param md_alg place to store message digest algorithm + * \param md_hmac place to store message hmac algorithm * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_md_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg); +int mbedtls_oid_get_md_hmac( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_hmac ); +#endif /* MBEDTLS_MD_C */ #if !defined(MBEDTLS_X509_REMOVE_INFO) /** @@ -669,7 +585,7 @@ int mbedtls_oid_get_md_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_al * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_extended_key_usage(const mbedtls_asn1_buf *oid, const char **desc); +int mbedtls_oid_get_extended_key_usage( const mbedtls_asn1_buf *oid, const char **desc ); #endif /** @@ -680,7 +596,7 @@ int mbedtls_oid_get_extended_key_usage(const mbedtls_asn1_buf *oid, const char * * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_certificate_policies(const mbedtls_asn1_buf *oid, const char **desc); +int mbedtls_oid_get_certificate_policies( const mbedtls_asn1_buf *oid, const char **desc ); /** * \brief Translate md_type into hash algorithm OID @@ -691,7 +607,7 @@ int mbedtls_oid_get_certificate_policies(const mbedtls_asn1_buf *oid, const char * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_oid_by_md(mbedtls_md_type_t md_alg, const char **oid, size_t *olen); +int mbedtls_oid_get_oid_by_md( mbedtls_md_type_t md_alg, const char **oid, size_t *olen ); #if defined(MBEDTLS_CIPHER_C) /** @@ -702,7 +618,8 @@ int mbedtls_oid_get_oid_by_md(mbedtls_md_type_t md_alg, const char **oid, size_t * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_cipher_alg(const mbedtls_asn1_buf *oid, mbedtls_cipher_type_t *cipher_alg); +int mbedtls_oid_get_cipher_alg( const mbedtls_asn1_buf *oid, mbedtls_cipher_type_t *cipher_alg ); +#endif /* MBEDTLS_CIPHER_C */ #if defined(MBEDTLS_PKCS12_C) /** @@ -715,10 +632,9 @@ int mbedtls_oid_get_cipher_alg(const mbedtls_asn1_buf *oid, mbedtls_cipher_type_ * * \return 0 if successful, or MBEDTLS_ERR_OID_NOT_FOUND */ -int mbedtls_oid_get_pkcs12_pbe_alg(const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg, - mbedtls_cipher_type_t *cipher_alg); +int mbedtls_oid_get_pkcs12_pbe_alg( const mbedtls_asn1_buf *oid, mbedtls_md_type_t *md_alg, + mbedtls_cipher_type_t *cipher_alg ); #endif /* MBEDTLS_PKCS12_C */ -#endif /* MBEDTLS_CIPHER_C */ #ifdef __cplusplus } diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/pem.h b/src/duckdb/third_party/mbedtls/include/mbedtls/pem.h index 0b5cca0dc..baceb0762 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/pem.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/pem.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_PEM_H #define MBEDTLS_PEM_H @@ -39,7 +51,7 @@ #define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /** Bad input parameters to function. */ #define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 -/** \} name PEM Error codes */ +/* \} name */ #ifdef __cplusplus extern "C" { @@ -49,7 +61,8 @@ extern "C" { /** * \brief PEM context structure */ -typedef struct mbedtls_pem_context { +typedef struct mbedtls_pem_context +{ unsigned char *MBEDTLS_PRIVATE(buf); /*!< buffer for decoded data */ size_t MBEDTLS_PRIVATE(buflen); /*!< length of the buffer */ unsigned char *MBEDTLS_PRIVATE(info); /*!< buffer for extra header information */ @@ -61,7 +74,7 @@ mbedtls_pem_context; * * \param ctx context to be initialized */ -void mbedtls_pem_init(mbedtls_pem_context *ctx); +void mbedtls_pem_init( mbedtls_pem_context *ctx ); /** * \brief Read a buffer for PEM information and store the resulting @@ -73,52 +86,29 @@ void mbedtls_pem_init(mbedtls_pem_context *ctx); * \param data source data to look in (must be nul-terminated) * \param pwd password for decryption (can be NULL) * \param pwdlen length of password - * \param use_len destination for total length used from data buffer. It is - * set after header is correctly read, so unless you get + * \param use_len destination for total length used (set after header is + * correctly read, so unless you get * MBEDTLS_ERR_PEM_BAD_INPUT_DATA or * MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is - * the length to skip. + * the length to skip) * * \note Attempts to check password correctness by verifying if * the decrypted text starts with an ASN.1 sequence of * appropriate length * - * \note \c mbedtls_pem_free must be called on PEM context before - * the PEM context can be reused in another call to - * \c mbedtls_pem_read_buffer - * * \return 0 on success, or a specific PEM error code */ -int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const char *footer, - const unsigned char *data, - const unsigned char *pwd, - size_t pwdlen, size_t *use_len); - -/** - * \brief Get the pointer to the decoded binary data in a PEM context. - * - * \param ctx PEM context to access. - * \param buflen On success, this will contain the length of the binary data. - * This must be a valid (non-null) pointer. - * - * \return A pointer to the decoded binary data. - * - * \note The returned pointer remains valid only until \p ctx is - modified or freed. - */ -inline const unsigned char *mbedtls_pem_get_buffer(mbedtls_pem_context *ctx, size_t *buflen) -{ - *buflen = ctx->MBEDTLS_PRIVATE(buflen); - return ctx->MBEDTLS_PRIVATE(buf); -} - +int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer, + const unsigned char *data, + const unsigned char *pwd, + size_t pwdlen, size_t *use_len ); /** * \brief PEM context memory freeing * * \param ctx context to be freed */ -void mbedtls_pem_free(mbedtls_pem_context *ctx); +void mbedtls_pem_free( mbedtls_pem_context *ctx ); #endif /* MBEDTLS_PEM_PARSE_C */ #if defined(MBEDTLS_PEM_WRITE_C) @@ -148,9 +138,9 @@ void mbedtls_pem_free(mbedtls_pem_context *ctx); * the required minimum size of \p buf. * \return Another PEM or BASE64 error code on other kinds of failure. */ -int mbedtls_pem_write_buffer(const char *header, const char *footer, - const unsigned char *der_data, size_t der_len, - unsigned char *buf, size_t buf_len, size_t *olen); +int mbedtls_pem_write_buffer( const char *header, const char *footer, + const unsigned char *der_data, size_t der_len, + unsigned char *buf, size_t buf_len, size_t *olen ); #endif /* MBEDTLS_PEM_WRITE_C */ #ifdef __cplusplus diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/pk.h b/src/duckdb/third_party/mbedtls/include/mbedtls/pk.h index af05fde6e..33c83f5e3 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/pk.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/pk.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_PK_H @@ -28,10 +40,15 @@ #include "mbedtls/ecdsa.h" #endif -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) +#if defined(MBEDTLS_USE_PSA_CRYPTO) #include "psa/crypto.h" #endif +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) +#define inline __inline +#endif + /** Memory allocation failed. */ #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80 /** Type mismatch, eg attempt to encrypt with an ECDSA key */ @@ -85,25 +102,10 @@ typedef enum { * \brief Options for RSASSA-PSS signature verification. * See \c mbedtls_rsa_rsassa_pss_verify_ext() */ -typedef struct mbedtls_pk_rsassa_pss_options { - /** The digest to use for MGF1 in PSS. - * - * \note When #MBEDTLS_USE_PSA_CRYPTO is enabled and #MBEDTLS_RSA_C is - * disabled, this must be equal to the \c md_alg argument passed - * to mbedtls_pk_verify_ext(). In a future version of the library, - * this constraint may apply whenever #MBEDTLS_USE_PSA_CRYPTO is - * enabled regardless of the status of #MBEDTLS_RSA_C. - */ - mbedtls_md_type_t mgf1_hash_id; - - /** The expected length of the salt, in bytes. This may be - * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length. - * - * \note When #MBEDTLS_USE_PSA_CRYPTO is enabled, only - * #MBEDTLS_RSA_SALT_LEN_ANY is valid. Any other value may be - * ignored (allowing any salt length). - */ - int expected_salt_len; +typedef struct mbedtls_pk_rsassa_pss_options +{ + mbedtls_md_type_t MBEDTLS_PRIVATE(mgf1_hash_id); + int MBEDTLS_PRIVATE(expected_salt_len); } mbedtls_pk_rsassa_pss_options; @@ -121,7 +123,7 @@ typedef struct mbedtls_pk_rsassa_pss_options { */ #define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0 -#if (defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT)) && \ +#if ( defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT) ) && \ MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE /* For RSA, the signature can be as large as the bignum module allows. * For RSA_ALT, the signature size is not necessarily tied to what the @@ -155,46 +157,25 @@ typedef struct mbedtls_pk_rsassa_pss_options { * types, lengths (represented by up to 2 bytes), and potential leading * zeros of the INTEGERs and the SEQUENCE. */ #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE -#define MBEDTLS_PK_SIGNATURE_MAX_SIZE (PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11) +#define MBEDTLS_PK_SIGNATURE_MAX_SIZE ( PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 ) #endif #endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */ -/* Internal helper to define which fields in the pk_context structure below - * should be used for EC keys: legacy ecp_keypair or the raw (PSA friendly) - * format. It should be noted that this only affects how data is stored, not - * which functions are used for various operations. The overall picture looks - * like this: - * - if USE_PSA is not defined and ECP_C is defined then use ecp_keypair data - * structure and legacy functions - * - if USE_PSA is defined and - * - if ECP_C then use ecp_keypair structure, convert data to a PSA friendly - * format and use PSA functions - * - if !ECP_C then use new raw data and PSA functions directly. - * - * The main reason for the "intermediate" (USE_PSA + ECP_C) above is that as long - * as ECP_C is defined mbedtls_pk_ec() gives the user a read/write access to the - * ecp_keypair structure inside the pk_context so they can modify it using - * ECP functions which are not under PK module's control. - */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) && \ - !defined(MBEDTLS_ECP_C) -#define MBEDTLS_PK_USE_PSA_EC_DATA -#endif - /** * \brief Types for interfacing with the debug module */ -typedef enum { +typedef enum +{ MBEDTLS_PK_DEBUG_NONE = 0, MBEDTLS_PK_DEBUG_MPI, MBEDTLS_PK_DEBUG_ECP, - MBEDTLS_PK_DEBUG_PSA_EC, } mbedtls_pk_debug_type; /** * \brief Item to send to the debug module */ -typedef struct mbedtls_pk_debug_item { +typedef struct mbedtls_pk_debug_item +{ mbedtls_pk_debug_type MBEDTLS_PRIVATE(type); const char *MBEDTLS_PRIVATE(name); void *MBEDTLS_PRIVATE(value); @@ -212,84 +193,67 @@ typedef struct mbedtls_pk_debug_item { */ typedef struct mbedtls_pk_info_t mbedtls_pk_info_t; -#define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN \ - PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) /** * \brief Public key container */ -typedef struct mbedtls_pk_context { - const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info); /**< Public key information */ - void *MBEDTLS_PRIVATE(pk_ctx); /**< Underlying public key context */ - /* The following field is used to store the ID of a private key in the - * following cases: - * - opaque key when MBEDTLS_USE_PSA_CRYPTO is defined - * - normal key when MBEDTLS_PK_USE_PSA_EC_DATA is defined. In this case: - * - the pk_ctx above is not not used to store the private key anymore. - * Actually that field not populated at all in this case because also - * the public key will be stored in raw format as explained below - * - this ID is used for all private key operations (ex: sign, check - * key pair, key write, etc) using PSA functions - * - * Note: this private key storing solution only affects EC keys, not the - * other ones. The latters still use the pk_ctx to store their own - * context. */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) - mbedtls_svc_key_id_t MBEDTLS_PRIVATE(priv_id); /**< Key ID for opaque keys */ -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - /* The following fields are meant for storing the public key in raw format - * which is handy for: - * - easily importing it into the PSA context - * - reducing the ECP module dependencies in the PK one. - * - * When MBEDTLS_PK_USE_PSA_EC_DATA is enabled: - * - the pk_ctx above is not used anymore for storing the public key - * inside the ecp_keypair structure - * - the following fields are used for all public key operations: signature - * verify, key pair check and key write. - * - For a key pair, priv_id contains the private key. For a public key, - * priv_id is null. - * Of course, when MBEDTLS_PK_USE_PSA_EC_DATA is not enabled, the legacy - * ecp_keypair structure is used for storing the public key and performing - * all the operations. - * - * Note: This new public key storing solution only works for EC keys, not - * other ones. The latters still use pk_ctx to store their own - * context. - */ -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - uint8_t MBEDTLS_PRIVATE(pub_raw)[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN]; /**< Raw public key */ - size_t MBEDTLS_PRIVATE(pub_raw_len); /**< Valid bytes in "pub_raw" */ - psa_ecc_family_t MBEDTLS_PRIVATE(ec_family); /**< EC family of pk */ - size_t MBEDTLS_PRIVATE(ec_bits); /**< Curve's bits of pk */ -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ +typedef struct mbedtls_pk_context +{ + const mbedtls_pk_info_t * MBEDTLS_PRIVATE(pk_info); /**< Public key information */ + void * MBEDTLS_PRIVATE(pk_ctx); /**< Underlying public key context */ } mbedtls_pk_context; #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /** * \brief Context for resuming operations */ -typedef struct { - const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info); /**< Public key information */ - void *MBEDTLS_PRIVATE(rs_ctx); /**< Underlying restart context */ +typedef struct +{ + const mbedtls_pk_info_t * MBEDTLS_PRIVATE(pk_info); /**< Public key information */ + void * MBEDTLS_PRIVATE(rs_ctx); /**< Underlying restart context */ } mbedtls_pk_restart_ctx; #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ /* Now we can declare functions that take a pointer to that */ typedef void mbedtls_pk_restart_ctx; #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ +#if defined(MBEDTLS_RSA_C) +/** + * Quick access to an RSA context inside a PK context. + * + * \warning You must make sure the PK context actually holds an RSA context + * before using this function! + */ +static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk ) +{ + return( (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx) ); +} +#endif /* MBEDTLS_RSA_C */ + +#if defined(MBEDTLS_ECP_C) +/** + * Quick access to an EC context inside a PK context. + * + * \warning You must make sure the PK context actually holds an EC context + * before using this function! + */ +static inline mbedtls_ecp_keypair *mbedtls_pk_ec( const mbedtls_pk_context pk ) +{ + return( (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx) ); +} +#endif /* MBEDTLS_ECP_C */ + #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) /** * \brief Types for RSA-alt abstraction */ -typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, size_t *olen, - const unsigned char *input, unsigned char *output, - size_t output_max_len); -typedef int (*mbedtls_pk_rsa_alt_sign_func)(void *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, unsigned int hashlen, - const unsigned char *hash, unsigned char *sig); -typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(void *ctx); +typedef int (*mbedtls_pk_rsa_alt_decrypt_func)( void *ctx, size_t *olen, + const unsigned char *input, unsigned char *output, + size_t output_max_len ); +typedef int (*mbedtls_pk_rsa_alt_sign_func)( void *ctx, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + mbedtls_md_type_t md_alg, unsigned int hashlen, + const unsigned char *hash, unsigned char *sig ); +typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)( void *ctx ); #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ /** @@ -299,7 +263,7 @@ typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(void *ctx); * * \return The PK info associated with the type or NULL if not found. */ -const mbedtls_pk_info_t *mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type); +const mbedtls_pk_info_t *mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type ); /** * \brief Initialize a #mbedtls_pk_context (as NONE). @@ -307,7 +271,7 @@ const mbedtls_pk_info_t *mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type); * \param ctx The context to initialize. * This must not be \c NULL. */ -void mbedtls_pk_init(mbedtls_pk_context *ctx); +void mbedtls_pk_init( mbedtls_pk_context *ctx ); /** * \brief Free the components of a #mbedtls_pk_context. @@ -320,7 +284,7 @@ void mbedtls_pk_init(mbedtls_pk_context *ctx); * PSA key and you still need to call psa_destroy_key() * independently if you want to destroy that key. */ -void mbedtls_pk_free(mbedtls_pk_context *ctx); +void mbedtls_pk_free( mbedtls_pk_context *ctx ); #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /** @@ -329,7 +293,7 @@ void mbedtls_pk_free(mbedtls_pk_context *ctx); * \param ctx The context to initialize. * This must not be \c NULL. */ -void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx); +void mbedtls_pk_restart_init( mbedtls_pk_restart_ctx *ctx ); /** * \brief Free the components of a restart context @@ -337,7 +301,7 @@ void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx); * \param ctx The context to clear. It must have been initialized. * If this is \c NULL, this function does nothing. */ -void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx); +void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx ); #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ /** @@ -355,47 +319,39 @@ void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx); * \note For contexts holding an RSA-alt key, use * \c mbedtls_pk_setup_rsa_alt() instead. */ -int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info); +int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ); #if defined(MBEDTLS_USE_PSA_CRYPTO) /** - * \brief Initialize a PK context to wrap a PSA key. - * - * This function creates a PK context which wraps a PSA key. The PSA wrapped - * key must be an EC or RSA key pair (DH is not suported in the PK module). - * - * Under the hood PSA functions will be used to perform the required - * operations and, based on the key type, used algorithms will be: - * * EC: - * * verify, verify_ext, sign, sign_ext: ECDSA. - * * RSA: - * * sign, decrypt: use the primary algorithm in the wrapped PSA key; - * * sign_ext: RSA PSS if the pk_type is #MBEDTLS_PK_RSASSA_PSS, otherwise - * it falls back to the sign() case; - * * verify, verify_ext, encrypt: not supported. - * - * In order for the above operations to succeed, the policy of the wrapped PSA - * key must allow the specified algorithm. - * - * Opaque PK contexts wrapping an EC keys also support \c mbedtls_pk_check_pair(), - * whereas RSA ones do not. - * - * \warning The PSA wrapped key must remain valid as long as the wrapping PK - * context is in use, that is at least between the point this function - * is called and the point mbedtls_pk_free() is called on this context. - * - * \param ctx The context to initialize. It must be empty (type NONE). - * \param key The PSA key to wrap, which must hold an ECC or RSA key pair. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input (context already - * used, invalid key identifier). - * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the key is not an ECC or - * RSA key pair. - * \return #MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure. + * \brief Initialize a PK context to wrap a PSA key. + * + * \note This function replaces mbedtls_pk_setup() for contexts + * that wrap a (possibly opaque) PSA key instead of + * storing and manipulating the key material directly. + * + * \param ctx The context to initialize. It must be empty (type NONE). + * \param key The PSA key to wrap, which must hold an ECC key pair + * (see notes below). + * + * \note The wrapped key must remain valid as long as the + * wrapping PK context is in use, that is at least between + * the point this function is called and the point + * mbedtls_pk_free() is called on this context. The wrapped + * key might then be independently used or destroyed. + * + * \note This function is currently only available for ECC key + * pairs (that is, ECC keys containing private key material). + * Support for other key types may be added later. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input + * (context already used, invalid key identifier). + * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the key is not an + * ECC key pair. + * \return #MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure. */ -int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx, - const mbedtls_svc_key_id_t key); +int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx, + const psa_key_id_t key ); #endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) @@ -414,10 +370,10 @@ int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx, * * \note This function replaces \c mbedtls_pk_setup() for RSA-alt. */ -int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key, - mbedtls_pk_rsa_alt_decrypt_func decrypt_func, - mbedtls_pk_rsa_alt_sign_func sign_func, - mbedtls_pk_rsa_alt_key_len_func key_len_func); +int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key, + mbedtls_pk_rsa_alt_decrypt_func decrypt_func, + mbedtls_pk_rsa_alt_sign_func sign_func, + mbedtls_pk_rsa_alt_key_len_func key_len_func ); #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ /** @@ -427,19 +383,19 @@ int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key, * * \return Key size in bits, or 0 on error */ -size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx); +size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx ); -/** - * \brief Get the length in bytes of the underlying key - * - * \param ctx The context to query. It must have been initialized. - * - * \return Key length in bytes, or 0 on error - */ -inline size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx) -{ - return (mbedtls_pk_get_bitlen(ctx) + 7) / 8; -} +///** +// * \brief Get the length in bytes of the underlying key +// * +// * \param ctx The context to query. It must have been initialized. +// * +// * \return Key length in bytes, or 0 on error +// */ +//static inline size_t mbedtls_pk_get_len( const mbedtls_pk_context *ctx ) +//{ +// return( ( mbedtls_pk_get_bitlen( ctx ) + 7 ) / 8 ); +//} /** * \brief Tell if a context can do the operation given by type @@ -453,270 +409,7 @@ inline size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx) * been initialized but not set up, or that has been * cleared with mbedtls_pk_free(). */ -int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type); - -#if defined(MBEDTLS_USE_PSA_CRYPTO) -/** - * \brief Tell if context can do the operation given by PSA algorithm - * - * \param ctx The context to query. It must have been initialized. - * \param alg PSA algorithm to check against, the following are allowed: - * PSA_ALG_RSA_PKCS1V15_SIGN(hash), - * PSA_ALG_RSA_PSS(hash), - * PSA_ALG_RSA_PKCS1V15_CRYPT, - * PSA_ALG_ECDSA(hash), - * PSA_ALG_ECDH, where hash is a specific hash. - * \param usage PSA usage flag to check against, must be composed of: - * PSA_KEY_USAGE_SIGN_HASH - * PSA_KEY_USAGE_DECRYPT - * PSA_KEY_USAGE_DERIVE. - * Context key must match all passed usage flags. - * - * \warning Since the set of allowed algorithms and usage flags may be - * expanded in the future, the return value \c 0 should not - * be taken in account for non-allowed algorithms and usage - * flags. - * - * \return 1 if the context can do operations on the given type. - * \return 0 if the context cannot do the operations on the given - * type, for non-allowed algorithms and usage flags, or - * for a context that has been initialized but not set up - * or that has been cleared with mbedtls_pk_free(). - */ -int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg, - psa_key_usage_t usage); -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) -/** - * \brief Determine valid PSA attributes that can be used to - * import a key into PSA. - * - * The attributes determined by this function are suitable - * for calling mbedtls_pk_import_into_psa() to create - * a PSA key with the same key material. - * - * The typical flow of operations involving this function is - * ``` - * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - * int ret = mbedtls_pk_get_psa_attributes(pk, &attributes); - * if (ret != 0) ...; // error handling omitted - * // Tweak attributes if desired - * psa_key_id_t key_id = 0; - * ret = mbedtls_pk_import_into_psa(pk, &attributes, &key_id); - * if (ret != 0) ...; // error handling omitted - * ``` - * - * \note This function does not support RSA-alt contexts - * (set up with mbedtls_pk_setup_rsa_alt()). - * - * \param[in] pk The PK context to use. It must have been set up. - * It can either contain a key pair or just a public key. - * \param usage A single `PSA_KEY_USAGE_xxx` flag among the following: - * - #PSA_KEY_USAGE_DECRYPT: \p pk must contain a - * key pair. The output \p attributes will contain a - * key pair type, and the usage policy will allow - * #PSA_KEY_USAGE_ENCRYPT as well as - * #PSA_KEY_USAGE_DECRYPT. - * - #PSA_KEY_USAGE_DERIVE: \p pk must contain a - * key pair. The output \p attributes will contain a - * key pair type. - * - #PSA_KEY_USAGE_ENCRYPT: The output - * \p attributes will contain a public key type. - * - #PSA_KEY_USAGE_SIGN_HASH: \p pk must contain a - * key pair. The output \p attributes will contain a - * key pair type, and the usage policy will allow - * #PSA_KEY_USAGE_VERIFY_HASH as well as - * #PSA_KEY_USAGE_SIGN_HASH. - * - #PSA_KEY_USAGE_SIGN_MESSAGE: \p pk must contain a - * key pair. The output \p attributes will contain a - * key pair type, and the usage policy will allow - * #PSA_KEY_USAGE_VERIFY_MESSAGE as well as - * #PSA_KEY_USAGE_SIGN_MESSAGE. - * - #PSA_KEY_USAGE_VERIFY_HASH: The output - * \p attributes will contain a public key type. - * - #PSA_KEY_USAGE_VERIFY_MESSAGE: The output - * \p attributes will contain a public key type. - * \param[out] attributes - * On success, valid attributes to import the key into PSA. - * - The lifetime and key identifier are unchanged. If the - * attribute structure was initialized or reset before - * calling this function, this will result in a volatile - * key. Call psa_set_key_identifier() before or after this - * function if you wish to create a persistent key. Call - * psa_set_key_lifetime() before or after this function if - * you wish to import the key in a secure element. - * - The key type and bit-size are determined by the contents - * of the PK context. If the PK context contains a key - * pair, the key type can be either a key pair type or - * the corresponding public key type, depending on - * \p usage. If the PK context contains a public key, - * the key type is a public key type. - * - The key's policy is determined by the key type and - * the \p usage parameter. The usage always allows - * \p usage, exporting and copying the key, and - * possibly other permissions as documented for the - * \p usage parameter. - * The permitted algorithm policy is determined as follows - * based on the #mbedtls_pk_type_t type of \p pk, - * the chosen \p usage and other factors: - * - #MBEDTLS_PK_RSA whose underlying - * #mbedtls_rsa_context has the padding mode - * #MBEDTLS_RSA_PKCS_V15: - * #PSA_ALG_RSA_PKCS1V15_SIGN(#PSA_ALG_ANY_HASH) - * if \p usage is SIGN/VERIFY, and - * #PSA_ALG_RSA_PKCS1V15_CRYPT - * if \p usage is ENCRYPT/DECRYPT. - * - #MBEDTLS_PK_RSA whose underlying - * #mbedtls_rsa_context has the padding mode - * #MBEDTLS_RSA_PKCS_V21 and the digest type - * corresponding to the PSA algorithm \c hash: - * #PSA_ALG_RSA_PSS_ANY_SALT(#PSA_ALG_ANY_HASH) - * if \p usage is SIGN/VERIFY, and - * #PSA_ALG_RSA_OAEP(\c hash) - * if \p usage is ENCRYPT/DECRYPT. - * - #MBEDTLS_PK_RSA_ALT: not supported. - * - #MBEDTLS_PK_ECDSA or #MBEDTLS_PK_ECKEY - * if \p usage is SIGN/VERIFY: - * #PSA_ALG_DETERMINISTIC_ECDSA(#PSA_ALG_ANY_HASH) - * if #MBEDTLS_ECDSA_DETERMINISTIC is enabled, - * otherwise #PSA_ALG_ECDSA(#PSA_ALG_ANY_HASH). - * - #MBEDTLS_PK_ECKEY_DH or #MBEDTLS_PK_ECKEY - * if \p usage is DERIVE: - * #PSA_ALG_ECDH. - * - #MBEDTLS_PK_OPAQUE: same as the primary algorithm - * set for the underlying PSA key, except that - * sign/decrypt flags are removed if the type is - * set to a public key type. - * The underlying key must allow \p usage. - * Note that the enrollment algorithm set with - * psa_set_key_enrollment_algorithm() is not copied. - * - * \return 0 on success. - * #MBEDTLS_ERR_PK_TYPE_MISMATCH if \p pk does not contain - * a key of the type identified in \p attributes. - * Another error code on other failures. - */ -int mbedtls_pk_get_psa_attributes(const mbedtls_pk_context *pk, - psa_key_usage_t usage, - psa_key_attributes_t *attributes); - -/** - * \brief Import a key into the PSA key store. - * - * This function is equivalent to calling psa_import_key() - * with the key material from \p pk. - * - * The typical way to use this function is: - * -# Call mbedtls_pk_get_psa_attributes() to obtain - * attributes for the given key. - * -# If desired, modify the attributes, for example: - * - To create a persistent key, call - * psa_set_key_identifier() and optionally - * psa_set_key_lifetime(). - * - To import only the public part of a key pair: - * - * psa_set_key_type(&attributes, - * PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( - * psa_get_key_type(&attributes))); - * - Restrict the key usage if desired. - * -# Call mbedtls_pk_import_into_psa(). - * - * \note This function does not support RSA-alt contexts - * (set up with mbedtls_pk_setup_rsa_alt()). - * - * \param[in] pk The PK context to use. It must have been set up. - * It can either contain a key pair or just a public key. - * \param[in] attributes - * The attributes to use for the new key. They must be - * compatible with \p pk. In particular, the key type - * must match the content of \p pk. - * If \p pk contains a key pair, the key type in - * attributes can be either the key pair type or the - * corresponding public key type (to import only the - * public part). - * \param[out] key_id - * On success, the identifier of the newly created key. - * On error, this is #MBEDTLS_SVC_KEY_ID_INIT. - * - * \return 0 on success. - * #MBEDTLS_ERR_PK_TYPE_MISMATCH if \p pk does not contain - * a key of the type identified in \p attributes. - * Another error code on other failures. - */ -int mbedtls_pk_import_into_psa(const mbedtls_pk_context *pk, - const psa_key_attributes_t *attributes, - mbedtls_svc_key_id_t *key_id); - -/** - * \brief Create a PK context starting from a key stored in PSA. - * This key: - * - must be exportable and - * - must be an RSA or EC key pair or public key (FFDH is not supported in PK). - * - * The resulting PK object will be a transparent type: - * - #MBEDTLS_PK_RSA for RSA keys or - * - #MBEDTLS_PK_ECKEY for EC keys. - * - * Once this functions returns the PK object will be completely - * independent from the original PSA key that it was generated - * from. - * Calling mbedtls_pk_sign(), mbedtls_pk_verify(), - * mbedtls_pk_encrypt(), mbedtls_pk_decrypt() on the resulting - * PK context will perform the corresponding algorithm for that - * PK context type. - * * For ECDSA, the choice of deterministic vs randomized will - * be based on the compile-time setting #MBEDTLS_ECDSA_DETERMINISTIC. - * * For an RSA key, the output PK context will allow both - * encrypt/decrypt and sign/verify regardless of the original - * key's policy. - * The original key's policy determines the output key's padding - * mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS, - * otherwise PKCS1 v1.5 is set. - * - * \param key_id The key identifier of the key stored in PSA. - * \param pk The PK context that will be filled. It must be initialized, - * but not set up. - * - * \return 0 on success. - * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA in case the provided input - * parameters are not correct. - */ -int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk); - -/** - * \brief Create a PK context for the public key of a PSA key. - * - * The key must be an RSA or ECC key. It can be either a - * public key or a key pair, and only the public key is copied. - * The resulting PK object will be a transparent type: - * - #MBEDTLS_PK_RSA for RSA keys or - * - #MBEDTLS_PK_ECKEY for EC keys. - * - * Once this functions returns the PK object will be completely - * independent from the original PSA key that it was generated - * from. - * Calling mbedtls_pk_verify() or - * mbedtls_pk_encrypt() on the resulting - * PK context will perform the corresponding algorithm for that - * PK context type. - * - * For an RSA key, the output PK context will allow both - * encrypt and verify regardless of the original key's policy. - * The original key's policy determines the output key's padding - * mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS, - * otherwise PKCS1 v1.5 is set. - * - * \param key_id The key identifier of the key stored in PSA. - * \param pk The PK context that will be filled. It must be initialized, - * but not set up. - * - * \return 0 on success. - * \return MBEDTLS_ERR_PK_BAD_INPUT_DATA in case the provided input - * parameters are not correct. - */ -int mbedtls_pk_copy_public_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk); -#endif /* MBEDTLS_PSA_CRYPTO_CLIENT */ +int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type ); /** * \brief Verify signature (including padding if relevant). @@ -736,21 +429,18 @@ int mbedtls_pk_copy_public_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_cont * \param sig Signature to verify * \param sig_len Signature length * - * \note For keys of type #MBEDTLS_PK_RSA, the signature algorithm is - * either PKCS#1 v1.5 or PSS (accepting any salt length), - * depending on the padding mode in the underlying RSA context. - * For a pk object constructed by parsing, this is PKCS#1 v1.5 - * by default. Use mbedtls_pk_verify_ext() to explicitly select - * a different algorithm. - * * \return 0 on success (signature is valid), * #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid - * signature in \p sig but its length is less than \p sig_len, + * signature in sig but its length is less than \p siglen, * or a specific error code. + * + * \note For RSA keys, the default padding type is PKCS#1 v1.5. + * Use \c mbedtls_pk_verify_ext( MBEDTLS_PK_RSASSA_PSS, ... ) + * to verify RSASSA_PSS signatures. */ -int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len); +int mbedtls_pk_verify( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ); /** * \brief Restartable version of \c mbedtls_pk_verify() @@ -772,11 +462,11 @@ int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of * operations was reached: see \c mbedtls_ecp_set_max_ops(). */ -int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len, - mbedtls_pk_restart_ctx *rs_ctx); +int mbedtls_pk_verify_restartable( mbedtls_pk_context *ctx, + mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + mbedtls_pk_restart_ctx *rs_ctx ); /** * \brief Verify signature, with options. @@ -795,7 +485,7 @@ int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx, * #MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be * used for this type of signatures, * #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid - * signature in \p sig but its length is less than \p sig_len, + * signature in sig but its length is less than \p siglen, * or a specific error code. * * \note If hash_len is 0, then the length associated with md_alg @@ -805,14 +495,12 @@ int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx, * * \note If type is MBEDTLS_PK_RSASSA_PSS, then options must point * to a mbedtls_pk_rsassa_pss_options structure, - * otherwise it must be NULL. Note that if - * #MBEDTLS_USE_PSA_CRYPTO is defined, the salt length is not - * verified as PSA_ALG_RSA_PSS_ANY_SALT is used. + * otherwise it must be NULL. */ -int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options, - mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len); +int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, + mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ); /** * \brief Make signature, including padding if relevant. @@ -833,60 +521,19 @@ int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options, * \param f_rng RNG function, must not be \c NULL. * \param p_rng RNG parameter * - * \note For keys of type #MBEDTLS_PK_RSA, the signature algorithm is - * either PKCS#1 v1.5 or PSS (using the largest possible salt - * length up to the hash length), depending on the padding mode - * in the underlying RSA context. For a pk object constructed - * by parsing, this is PKCS#1 v1.5 by default. Use - * mbedtls_pk_verify_ext() to explicitly select a different - * algorithm. - * * \return 0 on success, or a specific error code. * - * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0. - * For ECDSA, md_alg may never be MBEDTLS_MD_NONE. - */ -int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); - -/** - * \brief Make signature given a signature type. - * - * \param pk_type Signature type. - * \param ctx The PK context to use. It must have been set up - * with a private key. - * \param md_alg Hash algorithm used (see notes) - * \param hash Hash of the message to sign - * \param hash_len Hash length - * \param sig Place to write the signature. - * It must have enough room for the signature. - * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough. - * You may use a smaller buffer if it is large enough - * given the key type. - * \param sig_size The size of the \p sig buffer in bytes. - * \param sig_len On successful return, - * the number of bytes written to \p sig. - * \param f_rng RNG function, must not be \c NULL. - * \param p_rng RNG parameter - * - * \return 0 on success, or a specific error code. - * - * \note When \p pk_type is #MBEDTLS_PK_RSASSA_PSS, - * see #PSA_ALG_RSA_PSS for a description of PSS options used. + * \note For RSA keys, the default padding type is PKCS#1 v1.5. + * There is no interface in the PK module to make RSASSA-PSS + * signatures yet. * * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0. * For ECDSA, md_alg may never be MBEDTLS_MD_NONE. - * */ -int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type, - mbedtls_pk_context *ctx, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); +int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** * \brief Restartable version of \c mbedtls_pk_sign() @@ -917,12 +564,12 @@ int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type, * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of * operations was reached: see \c mbedtls_ecp_set_max_ops(). */ -int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, - mbedtls_pk_restart_ctx *rs_ctx); +int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx, + mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + mbedtls_pk_restart_ctx *rs_ctx ); /** * \brief Decrypt message (including padding if relevant). @@ -937,17 +584,14 @@ int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx, * \param f_rng RNG function, must not be \c NULL. * \param p_rng RNG parameter * - * \note For keys of type #MBEDTLS_PK_RSA, the signature algorithm is - * either PKCS#1 v1.5 or OAEP, depending on the padding mode in - * the underlying RSA context. For a pk object constructed by - * parsing, this is PKCS#1 v1.5 by default. + * \note For RSA keys, the default padding type is PKCS#1 v1.5. * * \return 0 on success, or a specific error code. */ -int mbedtls_pk_decrypt(mbedtls_pk_context *ctx, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); +int mbedtls_pk_decrypt( mbedtls_pk_context *ctx, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** * \brief Encrypt message (including padding if relevant). @@ -961,19 +605,16 @@ int mbedtls_pk_decrypt(mbedtls_pk_context *ctx, * \param f_rng RNG function, must not be \c NULL. * \param p_rng RNG parameter * - * \note For keys of type #MBEDTLS_PK_RSA, the signature algorithm is - * either PKCS#1 v1.5 or OAEP, depending on the padding mode in - * the underlying RSA context. For a pk object constructed by - * parsing, this is PKCS#1 v1.5 by default. - * * \note \p f_rng is used for padding generation. * + * \note For RSA keys, the default padding type is PKCS#1 v1.5. + * * \return 0 on success, or a specific error code. */ -int mbedtls_pk_encrypt(mbedtls_pk_context *ctx, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); +int mbedtls_pk_encrypt( mbedtls_pk_context *ctx, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** * \brief Check if a public-private pair of keys matches. @@ -989,10 +630,10 @@ int mbedtls_pk_encrypt(mbedtls_pk_context *ctx, * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA if a context is invalid. * \return Another non-zero value if the keys do not match. */ -int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, - const mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); +int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, + const mbedtls_pk_context *prv, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** * \brief Export debug information @@ -1002,7 +643,7 @@ int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, * * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA */ -int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items); +int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items ); /** * \brief Access the type name @@ -1011,7 +652,7 @@ int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items * * \return Type name on success, or "invalid PK" */ -const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx); +const char * mbedtls_pk_get_name( const mbedtls_pk_context *ctx ); /** * \brief Get the key type @@ -1021,64 +662,13 @@ const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx); * \return Type on success. * \return #MBEDTLS_PK_NONE for a context that has not been set up. */ -mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx); - -#if defined(MBEDTLS_RSA_C) -/** - * Quick access to an RSA context inside a PK context. - * - * \warning This function can only be used when the type of the context, as - * returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_RSA. - * Ensuring that is the caller's responsibility. - * Alternatively, you can check whether this function returns NULL. - * - * \return The internal RSA context held by the PK context, or NULL. - */ -inline mbedtls_rsa_context *mbedtls_pk_rsa(const mbedtls_pk_context pk) -{ - switch (mbedtls_pk_get_type(&pk)) { - case MBEDTLS_PK_RSA: - return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx); - default: - return NULL; - } -} -#endif /* MBEDTLS_RSA_C */ - -#if defined(MBEDTLS_ECP_C) -/** - * Quick access to an EC context inside a PK context. - * - * \warning This function can only be used when the type of the context, as - * returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_ECKEY, - * #MBEDTLS_PK_ECKEY_DH, or #MBEDTLS_PK_ECDSA. - * Ensuring that is the caller's responsibility. - * Alternatively, you can check whether this function returns NULL. - * - * \return The internal EC context held by the PK context, or NULL. - */ -inline mbedtls_ecp_keypair *mbedtls_pk_ec(const mbedtls_pk_context pk) -{ - switch (mbedtls_pk_get_type(&pk)) { - case MBEDTLS_PK_ECKEY: - case MBEDTLS_PK_ECKEY_DH: - case MBEDTLS_PK_ECDSA: - return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx); - default: - return NULL; - } -} -#endif /* MBEDTLS_ECP_C */ +mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx ); #if defined(MBEDTLS_PK_PARSE_C) /** \ingroup pk_module */ /** * \brief Parse a private key in PEM or DER format * - * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto - * subsystem must have been initialized by calling - * psa_crypto_init() before calling this function. - * * \param ctx The PK context to fill. It must have been initialized * but not set up. * \param key Input buffer to parse. @@ -1106,19 +696,15 @@ inline mbedtls_ecp_keypair *mbedtls_pk_ec(const mbedtls_pk_context pk) * * \return 0 if successful, or a specific PK or PEM error code */ -int mbedtls_pk_parse_key(mbedtls_pk_context *ctx, - const unsigned char *key, size_t keylen, - const unsigned char *pwd, size_t pwdlen, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); +int mbedtls_pk_parse_key( mbedtls_pk_context *ctx, + const unsigned char *key, size_t keylen, + const unsigned char *pwd, size_t pwdlen, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** \ingroup pk_module */ /** * \brief Parse a public key in PEM or DER format * - * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto - * subsystem must have been initialized by calling - * psa_crypto_init() before calling this function. - * * \param ctx The PK context to fill. It must have been initialized * but not set up. * \param key Input buffer to parse. @@ -1133,25 +719,18 @@ int mbedtls_pk_parse_key(mbedtls_pk_context *ctx, * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a * specific key type, check the result with mbedtls_pk_can_do(). * - * \note For compressed points, see #MBEDTLS_ECP_PF_COMPRESSED for - * limitations. - * * \note The key is also checked for correctness. * * \return 0 if successful, or a specific PK or PEM error code */ -int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx, - const unsigned char *key, size_t keylen); +int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, + const unsigned char *key, size_t keylen ); #if defined(MBEDTLS_FS_IO) /** \ingroup pk_module */ /** * \brief Load and parse a private key * - * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto - * subsystem must have been initialized by calling - * psa_crypto_init() before calling this function. - * * \param ctx The PK context to fill. It must have been initialized * but not set up. * \param path filename to read the private key from @@ -1171,9 +750,9 @@ int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx, * * \return 0 if successful, or a specific PK or PEM error code */ -int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx, - const char *path, const char *password, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng); +int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx, + const char *path, const char *password, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); /** \ingroup pk_module */ /** @@ -1192,7 +771,7 @@ int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx, * * \return 0 if successful, or a specific PK or PEM error code */ -int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path); +int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path ); #endif /* MBEDTLS_FS_IO */ #endif /* MBEDTLS_PK_PARSE_C */ @@ -1210,7 +789,7 @@ int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path); * \return length of data written if successful, or a specific * error code */ -int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size); +int mbedtls_pk_write_key_der( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size ); /** * \brief Write a public key to a SubjectPublicKeyInfo DER structure @@ -1225,7 +804,7 @@ int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, * \return length of data written if successful, or a specific * error code */ -int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size); +int mbedtls_pk_write_pubkey_der( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size ); #if defined(MBEDTLS_PEM_WRITE_C) /** @@ -1238,7 +817,7 @@ int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *bu * * \return 0 if successful, or a specific error code */ -int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size); +int mbedtls_pk_write_pubkey_pem( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size ); /** * \brief Write a private key to a PKCS#1 or SEC1 PEM string @@ -1250,7 +829,7 @@ int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *bu * * \return 0 if successful, or a specific error code */ -int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size); +int mbedtls_pk_write_key_pem( const mbedtls_pk_context *ctx, unsigned char *buf, size_t size ); #endif /* MBEDTLS_PEM_WRITE_C */ #endif /* MBEDTLS_PK_WRITE_C */ @@ -1270,8 +849,8 @@ int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, * * \return 0 if successful, or a specific PK error code */ -int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, - mbedtls_pk_context *pk); +int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end, + mbedtls_pk_context *pk ); #endif /* MBEDTLS_PK_PARSE_C */ #if defined(MBEDTLS_PK_WRITE_C) @@ -1285,10 +864,44 @@ int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, * * \return the length written or a negative error code */ -int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start, - const mbedtls_pk_context *key); +int mbedtls_pk_write_pubkey( unsigned char **p, unsigned char *start, + const mbedtls_pk_context *key ); #endif /* MBEDTLS_PK_WRITE_C */ +/* + * Internal module functions. You probably do not want to use these unless you + * know you do. + */ +#if defined(MBEDTLS_FS_IO) +int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n ); +#endif + +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/** + * \brief Turn an EC key into an opaque one. + * + * \warning This is a temporary utility function for tests. It might + * change or be removed at any time without notice. + * + * \note Only ECDSA keys are supported so far. Signing with the + * specified hash is the only allowed use of that key. + * + * \param pk Input: the EC key to import to a PSA key. + * Output: a PK context wrapping that PSA key. + * \param key Output: a PSA key identifier. + * It's the caller's responsibility to call + * psa_destroy_key() on that key identifier after calling + * mbedtls_pk_free() on the PK context. + * \param hash_alg The hash algorithm to allow for use with that key. + * + * \return \c 0 if successful. + * \return An Mbed TLS error code otherwise. + */ +int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk, + psa_key_id_t *key, + psa_algorithm_t hash_alg ); +#endif /* MBEDTLS_USE_PSA_CRYPTO */ + #ifdef __cplusplus } #endif diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/platform.h b/src/duckdb/third_party/mbedtls/include/mbedtls/platform.h index de3d71d9d..277a85c7d 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/platform.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/platform.h @@ -11,17 +11,22 @@ * implementations of these functions, or implementations specific to * their platform, which can be statically linked to the library or * dynamically configured at runtime. - * - * When all compilation options related to platform abstraction are - * disabled, this header just defines `mbedtls_xxx` function names - * as aliases to the standard `xxx` function. - * - * Most modules in the library and example programs are expected to - * include this header. */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_PLATFORM_H #define MBEDTLS_PLATFORM_H @@ -57,9 +62,7 @@ extern "C" { #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) #include #include -#if defined(MBEDTLS_HAVE_TIME) #include -#endif #if !defined(MBEDTLS_PLATFORM_STD_SNPRINTF) #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF) #define MBEDTLS_PLATFORM_STD_SNPRINTF mbedtls_platform_win32_snprintf /**< The default \c snprintf function to use. */ @@ -86,9 +89,6 @@ extern "C" { #if !defined(MBEDTLS_PLATFORM_STD_FREE) #define MBEDTLS_PLATFORM_STD_FREE free /**< The default \c free function to use. */ #endif -#if !defined(MBEDTLS_PLATFORM_STD_SETBUF) -#define MBEDTLS_PLATFORM_STD_SETBUF setbuf /**< The default \c setbuf function to use. */ -#endif #if !defined(MBEDTLS_PLATFORM_STD_EXIT) #define MBEDTLS_PLATFORM_STD_EXIT exit /**< The default \c exit function to use. */ #endif @@ -118,35 +118,22 @@ extern "C" { #endif #endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */ -/* Enable certain documented defines only when generating doxygen to avoid - * an "unrecognized define" error. */ -#if defined(__DOXYGEN__) && !defined(MBEDTLS_PLATFORM_STD_CALLOC) -#define MBEDTLS_PLATFORM_STD_CALLOC -#endif - -#if defined(__DOXYGEN__) && !defined(MBEDTLS_PLATFORM_STD_FREE) -#define MBEDTLS_PLATFORM_STD_FREE -#endif -/** \} name SECTION: Module settings */ +/* \} name SECTION: Module settings */ /* * The function pointers for calloc and free. - * Please see MBEDTLS_PLATFORM_STD_CALLOC and MBEDTLS_PLATFORM_STD_FREE - * in mbedtls_config.h for more information about behaviour and requirements. */ #if defined(MBEDTLS_PLATFORM_MEMORY) #if defined(MBEDTLS_PLATFORM_FREE_MACRO) && \ defined(MBEDTLS_PLATFORM_CALLOC_MACRO) -#undef mbedtls_free -#undef mbedtls_calloc #define mbedtls_free MBEDTLS_PLATFORM_FREE_MACRO #define mbedtls_calloc MBEDTLS_PLATFORM_CALLOC_MACRO #else /* For size_t */ #include -extern void *mbedtls_calloc(size_t n, size_t size); -extern void mbedtls_free(void *ptr); +extern void *mbedtls_calloc( size_t n, size_t size ); +extern void mbedtls_free( void *ptr ); /** * \brief This function dynamically sets the memory-management @@ -157,12 +144,10 @@ extern void mbedtls_free(void *ptr); * * \return \c 0. */ -int mbedtls_platform_set_calloc_free(void *(*calloc_func)(size_t, size_t), - void (*free_func)(void *)); +int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ), + void (*free_func)( void * ) ); #endif /* MBEDTLS_PLATFORM_FREE_MACRO && MBEDTLS_PLATFORM_CALLOC_MACRO */ #else /* !MBEDTLS_PLATFORM_MEMORY */ -#undef mbedtls_free -#undef mbedtls_calloc #define mbedtls_free free #define mbedtls_calloc calloc #endif /* MBEDTLS_PLATFORM_MEMORY && !MBEDTLS_PLATFORM_{FREE,CALLOC}_MACRO */ @@ -173,7 +158,7 @@ int mbedtls_platform_set_calloc_free(void *(*calloc_func)(size_t, size_t), #if defined(MBEDTLS_PLATFORM_FPRINTF_ALT) /* We need FILE * */ #include -extern int (*mbedtls_fprintf)(FILE *stream, const char *format, ...); +extern int (*mbedtls_fprintf)( FILE *stream, const char *format, ... ); /** * \brief This function dynamically configures the fprintf @@ -184,10 +169,9 @@ extern int (*mbedtls_fprintf)(FILE *stream, const char *format, ...); * * \return \c 0. */ -int mbedtls_platform_set_fprintf(int (*fprintf_func)(FILE *stream, const char *, - ...)); +int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *, + ... ) ); #else -#undef mbedtls_fprintf #if defined(MBEDTLS_PLATFORM_FPRINTF_MACRO) #define mbedtls_fprintf MBEDTLS_PLATFORM_FPRINTF_MACRO #else @@ -199,7 +183,7 @@ int mbedtls_platform_set_fprintf(int (*fprintf_func)(FILE *stream, const char *, * The function pointers for printf */ #if defined(MBEDTLS_PLATFORM_PRINTF_ALT) -extern int (*mbedtls_printf)(const char *format, ...); +extern int (*mbedtls_printf)( const char *format, ... ); /** * \brief This function dynamically configures the snprintf @@ -210,9 +194,8 @@ extern int (*mbedtls_printf)(const char *format, ...); * * \return \c 0 on success. */ -int mbedtls_platform_set_printf(int (*printf_func)(const char *, ...)); +int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) ); #else /* !MBEDTLS_PLATFORM_PRINTF_ALT */ -#undef mbedtls_printf #if defined(MBEDTLS_PLATFORM_PRINTF_MACRO) #define mbedtls_printf MBEDTLS_PLATFORM_PRINTF_MACRO #else @@ -231,11 +214,11 @@ int mbedtls_platform_set_printf(int (*printf_func)(const char *, ...)); */ #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_SNPRINTF) /* For Windows (inc. MSYS2), we provide our own fixed implementation */ -int mbedtls_platform_win32_snprintf(char *s, size_t n, const char *fmt, ...); +int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... ); #endif #if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT) -extern int (*mbedtls_snprintf)(char *s, size_t n, const char *format, ...); +extern int (*mbedtls_snprintf)( char * s, size_t n, const char * format, ... ); /** * \brief This function allows configuring a custom @@ -245,10 +228,9 @@ extern int (*mbedtls_snprintf)(char *s, size_t n, const char *format, ...); * * \return \c 0 on success. */ -int mbedtls_platform_set_snprintf(int (*snprintf_func)(char *s, size_t n, - const char *format, ...)); +int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n, + const char * format, ... ) ); #else /* MBEDTLS_PLATFORM_SNPRINTF_ALT */ -#undef mbedtls_snprintf #if defined(MBEDTLS_PLATFORM_SNPRINTF_MACRO) #define mbedtls_snprintf MBEDTLS_PLATFORM_SNPRINTF_MACRO #else @@ -268,12 +250,12 @@ int mbedtls_platform_set_snprintf(int (*snprintf_func)(char *s, size_t n, #if defined(MBEDTLS_PLATFORM_HAS_NON_CONFORMING_VSNPRINTF) #include /* For Older Windows (inc. MSYS2), we provide our own fixed implementation */ -int mbedtls_platform_win32_vsnprintf(char *s, size_t n, const char *fmt, va_list arg); +int mbedtls_platform_win32_vsnprintf( char *s, size_t n, const char *fmt, va_list arg ); #endif #if defined(MBEDTLS_PLATFORM_VSNPRINTF_ALT) #include -extern int (*mbedtls_vsnprintf)(char *s, size_t n, const char *format, va_list arg); +extern int (*mbedtls_vsnprintf)( char * s, size_t n, const char * format, va_list arg ); /** * \brief Set your own snprintf function pointer @@ -282,10 +264,9 @@ extern int (*mbedtls_vsnprintf)(char *s, size_t n, const char *format, va_list a * * \return \c 0 */ -int mbedtls_platform_set_vsnprintf(int (*vsnprintf_func)(char *s, size_t n, - const char *format, va_list arg)); +int mbedtls_platform_set_vsnprintf( int (*vsnprintf_func)( char * s, size_t n, + const char * format, va_list arg ) ); #else /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */ -#undef mbedtls_vsnprintf #if defined(MBEDTLS_PLATFORM_VSNPRINTF_MACRO) #define mbedtls_vsnprintf MBEDTLS_PLATFORM_VSNPRINTF_MACRO #else @@ -293,64 +274,11 @@ int mbedtls_platform_set_vsnprintf(int (*vsnprintf_func)(char *s, size_t n, #endif /* MBEDTLS_PLATFORM_VSNPRINTF_MACRO */ #endif /* MBEDTLS_PLATFORM_VSNPRINTF_ALT */ -/* - * The function pointers for setbuf - */ -#if defined(MBEDTLS_PLATFORM_SETBUF_ALT) -#include -/** - * \brief Function pointer to call for `setbuf()` functionality - * (changing the internal buffering on stdio calls). - * - * \note The library calls this function to disable - * buffering when reading or writing sensitive data, - * to avoid having extra copies of sensitive data - * remaining in stdio buffers after the file is - * closed. If this is not a concern, for example if - * your platform's stdio doesn't have any buffering, - * you can set mbedtls_setbuf to a function that - * does nothing. - * - * The library always calls this function with - * `buf` equal to `NULL`. - */ -extern void (*mbedtls_setbuf)(FILE *stream, char *buf); - -/** - * \brief Dynamically configure the function that is called - * when the mbedtls_setbuf() function is called by the - * library. - * - * \param setbuf_func The \c setbuf function implementation - * - * \return \c 0 - */ -int mbedtls_platform_set_setbuf(void (*setbuf_func)( - FILE *stream, char *buf)); -#else -#undef mbedtls_setbuf -#if defined(MBEDTLS_PLATFORM_SETBUF_MACRO) -/** - * \brief Macro defining the function for the library to - * call for `setbuf` functionality (changing the - * internal buffering on stdio calls). - * - * \note See extra comments on the mbedtls_setbuf() function - * pointer above. - * - * \return \c 0 on success, negative on error. - */ -#define mbedtls_setbuf MBEDTLS_PLATFORM_SETBUF_MACRO -#else -#define mbedtls_setbuf setbuf -#endif /* MBEDTLS_PLATFORM_SETBUF_MACRO */ -#endif /* MBEDTLS_PLATFORM_SETBUF_ALT */ - /* * The function pointers for exit */ #if defined(MBEDTLS_PLATFORM_EXIT_ALT) -extern void (*mbedtls_exit)(int status); +extern void (*mbedtls_exit)( int status ); /** * \brief This function dynamically configures the exit @@ -361,9 +289,8 @@ extern void (*mbedtls_exit)(int status); * * \return \c 0 on success. */ -int mbedtls_platform_set_exit(void (*exit_func)(int status)); +int mbedtls_platform_set_exit( void (*exit_func)( int status ) ); #else -#undef mbedtls_exit #if defined(MBEDTLS_PLATFORM_EXIT_MACRO) #define mbedtls_exit MBEDTLS_PLATFORM_EXIT_MACRO #else @@ -394,13 +321,13 @@ int mbedtls_platform_set_exit(void (*exit_func)(int status)); #if defined(MBEDTLS_ENTROPY_NV_SEED) #if !defined(MBEDTLS_PLATFORM_NO_STD_FUNCTIONS) && defined(MBEDTLS_FS_IO) /* Internal standard platform definitions */ -int mbedtls_platform_std_nv_seed_read(unsigned char *buf, size_t buf_len); -int mbedtls_platform_std_nv_seed_write(unsigned char *buf, size_t buf_len); +int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len ); +int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len ); #endif #if defined(MBEDTLS_PLATFORM_NV_SEED_ALT) -extern int (*mbedtls_nv_seed_read)(unsigned char *buf, size_t buf_len); -extern int (*mbedtls_nv_seed_write)(unsigned char *buf, size_t buf_len); +extern int (*mbedtls_nv_seed_read)( unsigned char *buf, size_t buf_len ); +extern int (*mbedtls_nv_seed_write)( unsigned char *buf, size_t buf_len ); /** * \brief This function allows configuring custom seed file writing and @@ -412,12 +339,10 @@ extern int (*mbedtls_nv_seed_write)(unsigned char *buf, size_t buf_len); * \return \c 0 on success. */ int mbedtls_platform_set_nv_seed( - int (*nv_seed_read_func)(unsigned char *buf, size_t buf_len), - int (*nv_seed_write_func)(unsigned char *buf, size_t buf_len) - ); + int (*nv_seed_read_func)( unsigned char *buf, size_t buf_len ), + int (*nv_seed_write_func)( unsigned char *buf, size_t buf_len ) + ); #else -#undef mbedtls_nv_seed_read -#undef mbedtls_nv_seed_write #if defined(MBEDTLS_PLATFORM_NV_SEED_READ_MACRO) && \ defined(MBEDTLS_PLATFORM_NV_SEED_WRITE_MACRO) #define mbedtls_nv_seed_read MBEDTLS_PLATFORM_NV_SEED_READ_MACRO @@ -437,7 +362,8 @@ int mbedtls_platform_set_nv_seed( * \note This structure may be used to assist platform-specific * setup or teardown operations. */ -typedef struct mbedtls_platform_context { +typedef struct mbedtls_platform_context +{ char MBEDTLS_PRIVATE(dummy); /**< A placeholder member, as empty structs are not portable. */ } mbedtls_platform_context; @@ -461,7 +387,7 @@ mbedtls_platform_context; * * \return \c 0 on success. */ -int mbedtls_platform_setup(mbedtls_platform_context *ctx); +int mbedtls_platform_setup( mbedtls_platform_context *ctx ); /** * \brief This function performs any platform teardown operations. * @@ -476,7 +402,7 @@ int mbedtls_platform_setup(mbedtls_platform_context *ctx); * \param ctx The platform context. * */ -void mbedtls_platform_teardown(mbedtls_platform_context *ctx); +void mbedtls_platform_teardown( mbedtls_platform_context *ctx ); #ifdef __cplusplus } diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/platform_time.h b/src/duckdb/third_party/mbedtls/include/mbedtls/platform_time.h index 97f1963ab..8d4b95d1d 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/platform_time.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/platform_time.h @@ -1,11 +1,23 @@ /** * \file platform_time.h * - * \brief Mbed TLS Platform time abstraction + * \brief mbed TLS Platform time abstraction */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_PLATFORM_TIME_H #define MBEDTLS_PLATFORM_TIME_H @@ -16,6 +28,14 @@ extern "C" { #endif +/** + * \name SECTION: Module settings + * + * The configuration options you can set for this module are in this section. + * Either change them in mbedtls_config.h or define them on the compiler command line. + * \{ + */ + /* * The time_t datatype */ @@ -27,34 +47,11 @@ typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t; typedef time_t mbedtls_time_t; #endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */ -#if defined(MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO) -typedef MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO mbedtls_ms_time_t; -#else -#include -#include -typedef int64_t mbedtls_ms_time_t; -#endif /* MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO */ - -/** - * \brief Get time in milliseconds. - * - * \return Monotonically-increasing current time in milliseconds. - * - * \note Define MBEDTLS_PLATFORM_MS_TIME_ALT to be able to provide an - * alternative implementation - * - * \warning This function returns a monotonically-increasing time value from a - * start time that will differ from platform to platform, and possibly - * from run to run of the process. - * - */ -mbedtls_ms_time_t mbedtls_ms_time(void); - /* * The function pointers for time */ #if defined(MBEDTLS_PLATFORM_TIME_ALT) -extern mbedtls_time_t (*mbedtls_time)(mbedtls_time_t *time); +extern mbedtls_time_t (*mbedtls_time)( mbedtls_time_t* time ); /** * \brief Set your own time function pointer @@ -63,7 +60,7 @@ extern mbedtls_time_t (*mbedtls_time)(mbedtls_time_t *time); * * \return 0 */ -int mbedtls_platform_set_time(mbedtls_time_t (*time_func)(mbedtls_time_t *time)); +int mbedtls_platform_set_time( mbedtls_time_t (*time_func)( mbedtls_time_t* time ) ); #else #if defined(MBEDTLS_PLATFORM_TIME_MACRO) #define mbedtls_time MBEDTLS_PLATFORM_TIME_MACRO diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/platform_util.h b/src/duckdb/third_party/mbedtls/include/mbedtls/platform_util.h index 1b371ef3f..5d2fefc36 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/platform_util.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/platform_util.h @@ -6,7 +6,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_PLATFORM_UTIL_H #define MBEDTLS_PLATFORM_UTIL_H @@ -23,20 +35,24 @@ extern "C" { #endif +/* Internal macros meant to be called only from within the library. */ +#define MBEDTLS_INTERNAL_VALIDATE_RET( cond, ret ) do { } while( 0 ) +#define MBEDTLS_INTERNAL_VALIDATE( cond ) do { } while( 0 ) + /* Internal helper macros for deprecating API constants. */ #if !defined(MBEDTLS_DEPRECATED_REMOVED) #if defined(MBEDTLS_DEPRECATED_WARNING) #define MBEDTLS_DEPRECATED __attribute__((deprecated)) -MBEDTLS_DEPRECATED typedef char const *mbedtls_deprecated_string_constant_t; -#define MBEDTLS_DEPRECATED_STRING_CONSTANT(VAL) \ - ((mbedtls_deprecated_string_constant_t) (VAL)) +MBEDTLS_DEPRECATED typedef char const * mbedtls_deprecated_string_constant_t; +#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) \ + ( (mbedtls_deprecated_string_constant_t) ( VAL ) ) MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; -#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(VAL) \ - ((mbedtls_deprecated_numeric_constant_t) (VAL)) +#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) \ + ( (mbedtls_deprecated_numeric_constant_t) ( VAL ) ) #else /* MBEDTLS_DEPRECATED_WARNING */ #define MBEDTLS_DEPRECATED -#define MBEDTLS_DEPRECATED_STRING_CONSTANT(VAL) VAL -#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(VAL) VAL +#define MBEDTLS_DEPRECATED_STRING_CONSTANT( VAL ) VAL +#define MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( VAL ) VAL #endif /* MBEDTLS_DEPRECATED_WARNING */ #endif /* MBEDTLS_DEPRECATED_REMOVED */ @@ -106,7 +122,7 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; * * This macro has an empty expansion. It exists for documentation purposes: * a #MBEDTLS_CHECK_RETURN_OPTIONAL annotation indicates that the function - * has been analyzed for return-check usefulness, whereas the lack of + * has been analyzed for return-check usefuless, whereas the lack of * an annotation indicates that the function has not been analyzed and its * return-check usefulness is unknown. */ @@ -126,14 +142,9 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; * https://stackoverflow.com/questions/40576003/ignoring-warning-wunused-result * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34 */ -#define MBEDTLS_IGNORE_RETURN(result) ((void) !(result)) +#define MBEDTLS_IGNORE_RETURN(result) ( (void) !( result ) ) #endif -/* If the following macro is defined, the library is being built by the test - * framework, and the framework is going to provide a replacement - * mbedtls_platform_zeroize() using a preprocessor macro, so the function - * declaration should be omitted. */ -#if !defined(MBEDTLS_TEST_DEFINES_ZEROIZE) //no-check-names /** * \brief Securely zeroize a buffer * @@ -156,8 +167,7 @@ MBEDTLS_DEPRECATED typedef int mbedtls_deprecated_numeric_constant_t; * \param len Length of the buffer in bytes * */ -void mbedtls_platform_zeroize(void *buf, size_t len); -#endif +void mbedtls_platform_zeroize( void *buf, size_t len ); #if defined(MBEDTLS_HAVE_TIME_DATE) /** @@ -186,8 +196,8 @@ void mbedtls_platform_zeroize(void *buf, size_t len); * \return Pointer to an object of type struct tm on success, otherwise * NULL */ -struct tm *mbedtls_platform_gmtime_r(const mbedtls_time_t *tt, - struct tm *tm_buf); +struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, + struct tm *tm_buf ); #endif /* MBEDTLS_HAVE_TIME_DATE */ #ifdef __cplusplus diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/private_access.h b/src/duckdb/third_party/mbedtls/include/mbedtls/private_access.h index 580f3eb44..98d3419f6 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/private_access.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/private_access.h @@ -1,11 +1,23 @@ -/** + /** * \file private_access.h * - * \brief Macro wrapper for struct's members. + * \brief Macro wrapper for struct's memebrs. */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_PRIVATE_ACCESS_H diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/rsa.h b/src/duckdb/third_party/mbedtls/include/mbedtls/rsa.h index c1e76b392..d03c31d71 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/rsa.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/rsa.h @@ -11,7 +11,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_RSA_H #define MBEDTLS_RSA_H @@ -62,7 +74,7 @@ /* * The above constants may be used even if the RSA module is compile out, - * eg for alternative (PKCS#11) RSA implementations in the PK layers. + * eg for alternative (PKCS#11) RSA implemenations in the PK layers. */ #ifdef __cplusplus @@ -73,20 +85,15 @@ extern "C" { // Regular implementation // -#if !defined(MBEDTLS_RSA_GEN_KEY_MIN_BITS) -#define MBEDTLS_RSA_GEN_KEY_MIN_BITS 1024 -#elif MBEDTLS_RSA_GEN_KEY_MIN_BITS < 128 -#error "MBEDTLS_RSA_GEN_KEY_MIN_BITS must be at least 128 bits" -#endif - /** * \brief The RSA context structure. */ -typedef struct mbedtls_rsa_context { +typedef struct mbedtls_rsa_context +{ int MBEDTLS_PRIVATE(ver); /*!< Reserved for internal purposes. - * Do not set this field in application - * code. Its meaning might change without - * notice. */ + * Do not set this field in application + * code. Its meaning might change without + * notice. */ size_t MBEDTLS_PRIVATE(len); /*!< The size of \p N in Bytes. */ mbedtls_mpi MBEDTLS_PRIVATE(N); /*!< The public modulus. */ @@ -109,12 +116,12 @@ typedef struct mbedtls_rsa_context { mbedtls_mpi MBEDTLS_PRIVATE(Vf); /*!< The cached un-blinding value. */ int MBEDTLS_PRIVATE(padding); /*!< Selects padding mode: - #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and - #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */ + #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and + #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */ int MBEDTLS_PRIVATE(hash_id); /*!< Hash identifier of mbedtls_md_type_t type, - as specified in md.h for use in the MGF - mask generating function used in the - EME-OAEP and EMSA-PSS encodings. */ + as specified in md.h for use in the MGF + mask generating function used in the + EME-OAEP and EMSA-PSS encodings. */ #if defined(MBEDTLS_THREADING_C) /* Invariant: the mutex is initialized iff ver != 0. */ mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); /*!< Thread-safety mutex. */ @@ -136,7 +143,7 @@ mbedtls_rsa_context; * * \param ctx The RSA context to initialize. This must not be \c NULL. */ -void mbedtls_rsa_init(mbedtls_rsa_context *ctx); +void mbedtls_rsa_init( mbedtls_rsa_context *ctx ); /** * \brief This function sets padding for an already initialized RSA @@ -172,30 +179,8 @@ void mbedtls_rsa_init(mbedtls_rsa_context *ctx); * \return #MBEDTLS_ERR_RSA_INVALID_PADDING failure: * \p padding or \p hash_id is invalid. */ -int mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding, - mbedtls_md_type_t hash_id); - -/** - * \brief This function retrieves padding mode of initialized - * RSA context. - * - * \param ctx The initialized RSA context. - * - * \return RSA padding mode. - * - */ -int mbedtls_rsa_get_padding_mode(const mbedtls_rsa_context *ctx); - -/** - * \brief This function retrieves hash identifier of mbedtls_md_type_t - * type. - * - * \param ctx The initialized RSA context. - * - * \return Hash identifier of mbedtls_md_type_t type. - * - */ -int mbedtls_rsa_get_md_alg(const mbedtls_rsa_context *ctx); +int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, + mbedtls_md_type_t hash_id ); /** * \brief This function imports a set of core parameters into an @@ -226,10 +211,10 @@ int mbedtls_rsa_get_md_alg(const mbedtls_rsa_context *ctx); * \return \c 0 on success. * \return A non-zero error code on failure. */ -int mbedtls_rsa_import(mbedtls_rsa_context *ctx, - const mbedtls_mpi *N, - const mbedtls_mpi *P, const mbedtls_mpi *Q, - const mbedtls_mpi *D, const mbedtls_mpi *E); +int mbedtls_rsa_import( mbedtls_rsa_context *ctx, + const mbedtls_mpi *N, + const mbedtls_mpi *P, const mbedtls_mpi *Q, + const mbedtls_mpi *D, const mbedtls_mpi *E ); /** * \brief This function imports core RSA parameters, in raw big-endian @@ -254,7 +239,7 @@ int mbedtls_rsa_import(mbedtls_rsa_context *ctx, * \param N The RSA modulus. This may be \c NULL. * \param N_len The Byte length of \p N; it is ignored if \p N == NULL. * \param P The first prime factor of \p N. This may be \c NULL. - * \param P_len The Byte length of \p P; it is ignored if \p P == NULL. + * \param P_len The Byte length of \p P; it ns ignored if \p P == NULL. * \param Q The second prime factor of \p N. This may be \c NULL. * \param Q_len The Byte length of \p Q; it is ignored if \p Q == NULL. * \param D The private exponent. This may be \c NULL. @@ -265,26 +250,26 @@ int mbedtls_rsa_import(mbedtls_rsa_context *ctx, * \return \c 0 on success. * \return A non-zero error code on failure. */ -int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx, - unsigned char const *N, size_t N_len, - unsigned char const *P, size_t P_len, - unsigned char const *Q, size_t Q_len, - unsigned char const *D, size_t D_len, - unsigned char const *E, size_t E_len); +int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx, + unsigned char const *N, size_t N_len, + unsigned char const *P, size_t P_len, + unsigned char const *Q, size_t Q_len, + unsigned char const *D, size_t D_len, + unsigned char const *E, size_t E_len ); /** * \brief This function completes an RSA context from * a set of imported core parameters. * - * To setup an RSA public key, precisely \c N and \c E + * To setup an RSA public key, precisely \p N and \p E * must have been imported. * * To setup an RSA private key, sufficient information must * be present for the other parameters to be derivable. * * The default implementation supports the following: - *
  • Derive \c P, \c Q from \c N, \c D, \c E.
  • - *
  • Derive \c N, \c D from \c P, \c Q, \c E.
+ *
  • Derive \p P, \p Q from \p N, \p D, \p E.
  • + *
  • Derive \p N, \p D from \p P, \p Q, \p E.
* Alternative implementations need not support these. * * If this function runs successfully, it guarantees that @@ -304,7 +289,7 @@ int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx, * failed. * */ -int mbedtls_rsa_complete(mbedtls_rsa_context *ctx); +int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ); /** * \brief This function exports the core parameters of an RSA key. @@ -346,9 +331,9 @@ int mbedtls_rsa_complete(mbedtls_rsa_context *ctx); * \return A non-zero return code on any other failure. * */ -int mbedtls_rsa_export(const mbedtls_rsa_context *ctx, - mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q, - mbedtls_mpi *D, mbedtls_mpi *E); +int mbedtls_rsa_export( const mbedtls_rsa_context *ctx, + mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q, + mbedtls_mpi *D, mbedtls_mpi *E ); /** * \brief This function exports core parameters of an RSA key @@ -397,12 +382,12 @@ int mbedtls_rsa_export(const mbedtls_rsa_context *ctx, * functionality or because of security policies. * \return A non-zero return code on any other failure. */ -int mbedtls_rsa_export_raw(const mbedtls_rsa_context *ctx, - unsigned char *N, size_t N_len, - unsigned char *P, size_t P_len, - unsigned char *Q, size_t Q_len, - unsigned char *D, size_t D_len, - unsigned char *E, size_t E_len); +int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx, + unsigned char *N, size_t N_len, + unsigned char *P, size_t P_len, + unsigned char *Q, size_t Q_len, + unsigned char *D, size_t D_len, + unsigned char *E, size_t E_len ); /** * \brief This function exports CRT parameters of a private RSA key. @@ -423,18 +408,8 @@ int mbedtls_rsa_export_raw(const mbedtls_rsa_context *ctx, * \return A non-zero error code on failure. * */ -int mbedtls_rsa_export_crt(const mbedtls_rsa_context *ctx, - mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP); - -/** - * \brief This function retrieves the length of the RSA modulus in bits. - * - * \param ctx The initialized RSA context. - * - * \return The length of the RSA modulus in bits. - * - */ -size_t mbedtls_rsa_get_bitlen(const mbedtls_rsa_context *ctx); +int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx, + mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP ); /** * \brief This function retrieves the length of RSA modulus in Bytes. @@ -444,7 +419,7 @@ size_t mbedtls_rsa_get_bitlen(const mbedtls_rsa_context *ctx); * \return The length of the RSA modulus in Bytes. * */ -size_t mbedtls_rsa_get_len(const mbedtls_rsa_context *ctx); +size_t mbedtls_rsa_get_len( const mbedtls_rsa_context *ctx ); /** * \brief This function generates an RSA keypair. @@ -464,10 +439,10 @@ size_t mbedtls_rsa_get_len(const mbedtls_rsa_context *ctx); * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - unsigned int nbits, int exponent); +int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + unsigned int nbits, int exponent ); /** * \brief This function checks if a context contains at least an RSA @@ -483,7 +458,7 @@ int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. * */ -int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx); +int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx ); /** * \brief This function checks if a context contains an RSA private key @@ -504,7 +479,7 @@ int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx); * the current function does not have access to them, * and therefore cannot check them. See mbedtls_rsa_complete(). * If you want to check the consistency of the entire - * content of a PKCS1-encoded RSA private key, for example, you + * content of an PKCS1-encoded RSA private key, for example, you * should use mbedtls_rsa_validate_params() before setting * up the RSA context. * Additionally, if the implementation performs empirical checks, @@ -521,7 +496,7 @@ int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx); * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_check_privkey(const mbedtls_rsa_context *ctx); +int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx ); /** * \brief This function checks a public-private RSA key pair. @@ -534,8 +509,8 @@ int mbedtls_rsa_check_privkey(const mbedtls_rsa_context *ctx); * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub, - const mbedtls_rsa_context *prv); +int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub, + const mbedtls_rsa_context *prv ); /** * \brief This function performs an RSA public key operation. @@ -551,21 +526,21 @@ int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub, * \note This function does not handle message padding. * * \note Make sure to set \p input[0] = 0 or ensure that - * input is smaller than \c N. + * input is smaller than \p N. * * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_public(mbedtls_rsa_context *ctx, - const unsigned char *input, - unsigned char *output); +int mbedtls_rsa_public( mbedtls_rsa_context *ctx, + const unsigned char *input, + unsigned char *output ); /** * \brief This function performs an RSA private key operation. * * \note Blinding is used if and only if a PRNG is provided. * - * \note If blinding is used, both the base of exponentiation + * \note If blinding is used, both the base of exponentation * and the exponent are blinded, providing protection * against some side-channel attacks. * @@ -589,11 +564,11 @@ int mbedtls_rsa_public(mbedtls_rsa_context *ctx, * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. * */ -int mbedtls_rsa_private(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - const unsigned char *input, - unsigned char *output); +int mbedtls_rsa_private( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + const unsigned char *input, + unsigned char *output ); /** * \brief This function adds the message padding, then performs an RSA @@ -618,12 +593,12 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx, * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_pkcs1_encrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - size_t ilen, - const unsigned char *input, - unsigned char *output); +int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + size_t ilen, + const unsigned char *input, + unsigned char *output ); /** * \brief This function performs a PKCS#1 v1.5 encryption operation @@ -645,12 +620,12 @@ int mbedtls_rsa_pkcs1_encrypt(mbedtls_rsa_context *ctx, * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - size_t ilen, - const unsigned char *input, - unsigned char *output); +int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + size_t ilen, + const unsigned char *input, + unsigned char *output ); /** * \brief This function performs a PKCS#1 v2.1 OAEP encryption @@ -659,7 +634,7 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_rsa_context *ctx, * \note The output buffer must be as large as the size * of ctx->N. For example, 128 Bytes if RSA-1024 is used. * - * \param ctx The initialized RSA context to use. + * \param ctx The initnialized RSA context to use. * \param f_rng The RNG function to use. This is needed for padding * generation and is mandatory. * \param p_rng The RNG context to be passed to \p f_rng. This may @@ -679,13 +654,13 @@ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_rsa_context *ctx, * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - const unsigned char *label, size_t label_len, - size_t ilen, - const unsigned char *input, - unsigned char *output); +int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + const unsigned char *label, size_t label_len, + size_t ilen, + const unsigned char *input, + unsigned char *output ); /** * \brief This function performs an RSA operation, then removes the @@ -694,10 +669,6 @@ int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx, * It is the generic wrapper for performing a PKCS#1 decryption * operation. * - * \warning When \p ctx->padding is set to #MBEDTLS_RSA_PKCS_V15, - * mbedtls_rsa_rsaes_pkcs1_v15_decrypt() is called, which is an - * inherently dangerous function (CWE-242). - * * \note The output buffer length \c output_max_len should be * as large as the size \p ctx->len of \p ctx->N (for example, * 128 Bytes if RSA-1024 is used) to be able to hold an @@ -722,23 +693,18 @@ int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx, * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_pkcs1_decrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - size_t *olen, - const unsigned char *input, - unsigned char *output, - size_t output_max_len); +int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + size_t *olen, + const unsigned char *input, + unsigned char *output, + size_t output_max_len ); /** * \brief This function performs a PKCS#1 v1.5 decryption * operation (RSAES-PKCS1-v1_5-DECRYPT). * - * \warning This is an inherently dangerous function (CWE-242). Unless - * it is used in a side channel free and safe way (eg. - * implementing the TLS protocol as per 7.4.7.1 of RFC 5246), - * the calling code is vulnerable. - * * \note The output buffer length \c output_max_len should be * as large as the size \p ctx->len of \p ctx->N, for example, * 128 Bytes if RSA-1024 is used, to be able to hold an @@ -764,13 +730,13 @@ int mbedtls_rsa_pkcs1_decrypt(mbedtls_rsa_context *ctx, * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. * */ -int mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - size_t *olen, - const unsigned char *input, - unsigned char *output, - size_t output_max_len); +int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + size_t *olen, + const unsigned char *input, + unsigned char *output, + size_t output_max_len ); /** * \brief This function performs a PKCS#1 v2.1 OAEP decryption @@ -805,14 +771,14 @@ int mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_rsa_context *ctx, * \return \c 0 on success. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - const unsigned char *label, size_t label_len, - size_t *olen, - const unsigned char *input, - unsigned char *output, - size_t output_max_len); +int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + const unsigned char *label, size_t label_len, + size_t *olen, + const unsigned char *input, + unsigned char *output, + size_t output_max_len ); /** * \brief This function performs a private RSA operation to sign @@ -848,13 +814,13 @@ int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx, * \return \c 0 if the signing operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_pkcs1_sign(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig); +int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + unsigned char *sig ); /** * \brief This function performs a PKCS#1 v1.5 signature @@ -880,15 +846,14 @@ int mbedtls_rsa_pkcs1_sign(mbedtls_rsa_context *ctx, * \return \c 0 if the signing operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsassa_pkcs1_v15_sign(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig); +int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + unsigned char *sig ); -#if defined(MBEDTLS_PKCS1_V21) /** * \brief This function performs a PKCS#1 v2.1 PSS signature * operation (RSASSA-PSS-SIGN). @@ -932,14 +897,14 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign(mbedtls_rsa_context *ctx, * \return \c 0 if the signing operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsassa_pss_sign_ext(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - int saltlen, - unsigned char *sig); +int mbedtls_rsa_rsassa_pss_sign_ext( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + int saltlen, + unsigned char *sig ); /** * \brief This function performs a PKCS#1 v2.1 PSS signature @@ -982,14 +947,13 @@ int mbedtls_rsa_rsassa_pss_sign_ext(mbedtls_rsa_context *ctx, * \return \c 0 if the signing operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig); -#endif /* MBEDTLS_PKCS1_V21 */ +int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + unsigned char *sig ); /** * \brief This function performs a public RSA operation and checks @@ -999,8 +963,8 @@ int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx, * verification. * * \note For PKCS#1 v2.1 encoding, see comments on - * mbedtls_rsa_rsassa_pss_verify() about \c md_alg and - * \c hash_id. + * mbedtls_rsa_rsassa_pss_verify() about \p md_alg and + * \p hash_id. * * \param ctx The initialized RSA public key context to use. * \param md_alg The message-digest algorithm used to hash the original data. @@ -1017,11 +981,11 @@ int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx, * \return \c 0 if the verify operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_pkcs1_verify(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - const unsigned char *sig); +int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + const unsigned char *sig ); /** * \brief This function performs a PKCS#1 v1.5 verification @@ -1042,11 +1006,11 @@ int mbedtls_rsa_pkcs1_verify(mbedtls_rsa_context *ctx, * \return \c 0 if the verify operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsassa_pkcs1_v15_verify(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - const unsigned char *sig); +int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + const unsigned char *sig ); /** * \brief This function performs a PKCS#1 v2.1 PSS verification @@ -1077,11 +1041,11 @@ int mbedtls_rsa_rsassa_pkcs1_v15_verify(mbedtls_rsa_context *ctx, * \return \c 0 if the verify operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsassa_pss_verify(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - const unsigned char *sig); +int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + const unsigned char *sig ); /** * \brief This function performs a PKCS#1 v2.1 PSS verification @@ -1117,13 +1081,13 @@ int mbedtls_rsa_rsassa_pss_verify(mbedtls_rsa_context *ctx, * \return \c 0 if the verify operation was successful. * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure. */ -int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - mbedtls_md_type_t mgf1_hash_id, - int expected_salt_len, - const unsigned char *sig); +int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + mbedtls_md_type_t mgf1_hash_id, + int expected_salt_len, + const unsigned char *sig ); /** * \brief This function copies the components of an RSA context. @@ -1134,7 +1098,7 @@ int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx, * \return \c 0 on success. * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory allocation failure. */ -int mbedtls_rsa_copy(mbedtls_rsa_context *dst, const mbedtls_rsa_context *src); +int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src ); /** * \brief This function frees the components of an RSA key. @@ -1143,7 +1107,7 @@ int mbedtls_rsa_copy(mbedtls_rsa_context *dst, const mbedtls_rsa_context *src); * this function is a no-op. If it is not \c NULL, it must * point to an initialized RSA context. */ -void mbedtls_rsa_free(mbedtls_rsa_context *ctx); +void mbedtls_rsa_free( mbedtls_rsa_context *ctx ); #if defined(MBEDTLS_SELF_TEST) @@ -1153,7 +1117,7 @@ void mbedtls_rsa_free(mbedtls_rsa_context *ctx); * \return \c 0 on success. * \return \c 1 on failure. */ -int mbedtls_rsa_self_test(int verbose); +int mbedtls_rsa_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/sha1.h b/src/duckdb/third_party/mbedtls/include/mbedtls/sha1.h index 592ffd13f..6b55174a5 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/sha1.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/sha1.h @@ -12,7 +12,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_SHA1_H #define MBEDTLS_SHA1_H @@ -42,7 +54,8 @@ extern "C" { * stronger message digests instead. * */ -typedef struct mbedtls_sha1_context { +typedef struct mbedtls_sha1_context +{ uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< The number of Bytes processed. */ uint32_t MBEDTLS_PRIVATE(state)[5]; /*!< The intermediate digest state. */ unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< The data block being processed. */ @@ -64,7 +77,7 @@ mbedtls_sha1_context; * This must not be \c NULL. * */ -void mbedtls_sha1_init(mbedtls_sha1_context *ctx); +void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); /** * \brief This function clears a SHA-1 context. @@ -79,7 +92,7 @@ void mbedtls_sha1_init(mbedtls_sha1_context *ctx); * SHA-1 context. * */ -void mbedtls_sha1_free(mbedtls_sha1_context *ctx); +void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); /** * \brief This function clones the state of a SHA-1 context. @@ -92,8 +105,8 @@ void mbedtls_sha1_free(mbedtls_sha1_context *ctx); * \param src The SHA-1 context to clone from. This must be initialized. * */ -void mbedtls_sha1_clone(mbedtls_sha1_context *dst, - const mbedtls_sha1_context *src); +void mbedtls_sha1_clone( mbedtls_sha1_context *dst, + const mbedtls_sha1_context *src ); /** * \brief This function starts a SHA-1 checksum calculation. @@ -108,7 +121,7 @@ void mbedtls_sha1_clone(mbedtls_sha1_context *dst, * \return A negative error code on failure. * */ -int mbedtls_sha1_starts(mbedtls_sha1_context *ctx); +int mbedtls_sha1_starts( mbedtls_sha1_context *ctx ); /** * \brief This function feeds an input buffer into an ongoing SHA-1 @@ -127,9 +140,9 @@ int mbedtls_sha1_starts(mbedtls_sha1_context *ctx); * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_sha1_update(mbedtls_sha1_context *ctx, - const unsigned char *input, - size_t ilen); +int mbedtls_sha1_update( mbedtls_sha1_context *ctx, + const unsigned char *input, + size_t ilen ); /** * \brief This function finishes the SHA-1 operation, and writes @@ -147,8 +160,8 @@ int mbedtls_sha1_update(mbedtls_sha1_context *ctx, * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_sha1_finish(mbedtls_sha1_context *ctx, - unsigned char output[20]); +int mbedtls_sha1_finish( mbedtls_sha1_context *ctx, + unsigned char output[20] ); /** * \brief SHA-1 process data block (internal use only). @@ -165,8 +178,8 @@ int mbedtls_sha1_finish(mbedtls_sha1_context *ctx, * \return A negative error code on failure. * */ -int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, - const unsigned char data[64]); +int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, + const unsigned char data[64] ); /** * \brief This function calculates the SHA-1 checksum of a buffer. @@ -191,9 +204,9 @@ int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, * \return A negative error code on failure. * */ -int mbedtls_sha1(const unsigned char *input, - size_t ilen, - unsigned char output[20]); +int mbedtls_sha1( const unsigned char *input, + size_t ilen, + unsigned char output[20] ); #if defined(MBEDTLS_SELF_TEST) @@ -208,7 +221,7 @@ int mbedtls_sha1(const unsigned char *input, * \return \c 1 on failure. * */ -int mbedtls_sha1_self_test(int verbose); +int mbedtls_sha1_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/sha256.h b/src/duckdb/third_party/mbedtls/include/mbedtls/sha256.h index ca568e291..0cbbac11f 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/sha256.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/sha256.h @@ -8,7 +8,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_SHA256_H #define MBEDTLS_SHA256_H @@ -37,14 +49,13 @@ extern "C" { * checksum calculations. The choice between these two is * made in the call to mbedtls_sha256_starts(). */ -typedef struct mbedtls_sha256_context { - unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< The data block being processed. */ +typedef struct mbedtls_sha256_context +{ uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< The number of Bytes processed. */ uint32_t MBEDTLS_PRIVATE(state)[8]; /*!< The intermediate digest state. */ -#if defined(MBEDTLS_SHA224_C) + unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< The data block being processed. */ int MBEDTLS_PRIVATE(is224); /*!< Determines which function to use: - 0: Use SHA-256, or 1: Use SHA-224. */ -#endif + 0: Use SHA-256, or 1: Use SHA-224. */ } mbedtls_sha256_context; @@ -57,7 +68,7 @@ mbedtls_sha256_context; * * \param ctx The SHA-256 context to initialize. This must not be \c NULL. */ -void mbedtls_sha256_init(mbedtls_sha256_context *ctx); +void mbedtls_sha256_init( mbedtls_sha256_context *ctx ); /** * \brief This function clears a SHA-256 context. @@ -66,7 +77,7 @@ void mbedtls_sha256_init(mbedtls_sha256_context *ctx); * case this function returns immediately. If it is not \c NULL, * it must point to an initialized SHA-256 context. */ -void mbedtls_sha256_free(mbedtls_sha256_context *ctx); +void mbedtls_sha256_free( mbedtls_sha256_context *ctx ); /** * \brief This function clones the state of a SHA-256 context. @@ -74,8 +85,8 @@ void mbedtls_sha256_free(mbedtls_sha256_context *ctx); * \param dst The destination context. This must be initialized. * \param src The context to clone. This must be initialized. */ -void mbedtls_sha256_clone(mbedtls_sha256_context *dst, - const mbedtls_sha256_context *src); +void mbedtls_sha256_clone( mbedtls_sha256_context *dst, + const mbedtls_sha256_context *src ); /** * \brief This function starts a SHA-224 or SHA-256 checksum @@ -85,14 +96,10 @@ void mbedtls_sha256_clone(mbedtls_sha256_context *dst, * \param is224 This determines which function to use. This must be * either \c 0 for SHA-256, or \c 1 for SHA-224. * - * \note is224 must be defined accordingly to the enabled - * MBEDTLS_SHA224_C/MBEDTLS_SHA256_C symbols otherwise the - * function will return #MBEDTLS_ERR_SHA512_BAD_INPUT_DATA. - * * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224); +int mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ); /** * \brief This function feeds an input buffer into an ongoing @@ -107,9 +114,9 @@ int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224); * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_sha256_update(mbedtls_sha256_context *ctx, - const unsigned char *input, - size_t ilen); +int mbedtls_sha256_update( mbedtls_sha256_context *ctx, + const unsigned char *input, + size_t ilen ); /** * \brief This function finishes the SHA-256 operation, and writes @@ -124,8 +131,8 @@ int mbedtls_sha256_update(mbedtls_sha256_context *ctx, * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_sha256_finish(mbedtls_sha256_context *ctx, - unsigned char *output); +int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, + unsigned char *output ); /** * \brief This function processes a single data block within @@ -139,8 +146,8 @@ int mbedtls_sha256_finish(mbedtls_sha256_context *ctx, * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, - const unsigned char data[64]); +int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, + const unsigned char data[64] ); /** * \brief This function calculates the SHA-224 or SHA-256 @@ -164,32 +171,20 @@ int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, * \return \c 0 on success. * \return A negative error code on failure. */ -int mbedtls_sha256(const unsigned char *input, - size_t ilen, - unsigned char *output, - int is224); +int mbedtls_sha256( const unsigned char *input, + size_t ilen, + unsigned char *output, + int is224 ); #if defined(MBEDTLS_SELF_TEST) -#if defined(MBEDTLS_SHA224_C) -/** - * \brief The SHA-224 checkup routine. - * - * \return \c 0 on success. - * \return \c 1 on failure. - */ -int mbedtls_sha224_self_test(int verbose); -#endif /* MBEDTLS_SHA224_C */ - -#if defined(MBEDTLS_SHA256_C) /** - * \brief The SHA-256 checkup routine. + * \brief The SHA-224 and SHA-256 checkup routine. * * \return \c 0 on success. * \return \c 1 on failure. */ -int mbedtls_sha256_self_test(int verbose); -#endif /* MBEDTLS_SHA256_C */ +int mbedtls_sha256_self_test( int verbose ); #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/include/mbedtls/sha512.h b/src/duckdb/third_party/mbedtls/include/mbedtls/sha512.h index 456385123..48901cc39 100644 --- a/src/duckdb/third_party/mbedtls/include/mbedtls/sha512.h +++ b/src/duckdb/third_party/mbedtls/include/mbedtls/sha512.h @@ -1 +1,205 @@ -// dummy \ No newline at end of file +/** + * \file sha512.h + * \brief This file contains SHA-384 and SHA-512 definitions and functions. + * + * The Secure Hash Algorithms 384 and 512 (SHA-384 and SHA-512) cryptographic + * hash functions are defined in FIPS 180-4: Secure Hash Standard (SHS). + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBEDTLS_SHA512_H +#define MBEDTLS_SHA512_H +#include "mbedtls/private_access.h" + +#include "mbedtls/build_info.h" + +#include +#include + +/** SHA-512 input data was malformed. */ +#define MBEDTLS_ERR_SHA512_BAD_INPUT_DATA -0x0075 + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(MBEDTLS_SHA512_ALT) +// Regular implementation +// + +/** + * \brief The SHA-512 context structure. + * + * The structure is used both for SHA-384 and for SHA-512 + * checksum calculations. The choice between these two is + * made in the call to mbedtls_sha512_starts(). + */ +typedef struct mbedtls_sha512_context +{ + uint64_t MBEDTLS_PRIVATE(total)[2]; /*!< The number of Bytes processed. */ + uint64_t MBEDTLS_PRIVATE(state)[8]; /*!< The intermediate digest state. */ + unsigned char MBEDTLS_PRIVATE(buffer)[128]; /*!< The data block being processed. */ +#if defined(MBEDTLS_SHA384_C) + int MBEDTLS_PRIVATE(is384); /*!< Determines which function to use: + 0: Use SHA-512, or 1: Use SHA-384. */ +#endif +} +mbedtls_sha512_context; + +#else /* MBEDTLS_SHA512_ALT */ +#include "sha512_alt.h" +#endif /* MBEDTLS_SHA512_ALT */ + +/** + * \brief This function initializes a SHA-512 context. + * + * \param ctx The SHA-512 context to initialize. This must + * not be \c NULL. + */ +void mbedtls_sha512_init( mbedtls_sha512_context *ctx ); + +/** + * \brief This function clears a SHA-512 context. + * + * \param ctx The SHA-512 context to clear. This may be \c NULL, + * in which case this function does nothing. If it + * is not \c NULL, it must point to an initialized + * SHA-512 context. + */ +void mbedtls_sha512_free( mbedtls_sha512_context *ctx ); + +/** + * \brief This function clones the state of a SHA-512 context. + * + * \param dst The destination context. This must be initialized. + * \param src The context to clone. This must be initialized. + */ +void mbedtls_sha512_clone( mbedtls_sha512_context *dst, + const mbedtls_sha512_context *src ); + +/** + * \brief This function starts a SHA-384 or SHA-512 checksum + * calculation. + * + * \param ctx The SHA-512 context to use. This must be initialized. + * \param is384 Determines which function to use. This must be + * either \c 0 for SHA-512, or \c 1 for SHA-384. + * + * \note When \c MBEDTLS_SHA384_C is not defined, + * \p is384 must be \c 0, or the function will return + * #MBEDTLS_ERR_SHA512_BAD_INPUT_DATA. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 ); + +/** + * \brief This function feeds an input buffer into an ongoing + * SHA-512 checksum calculation. + * + * \param ctx The SHA-512 context. This must be initialized + * and have a hash operation started. + * \param input The buffer holding the input data. This must + * be a readable buffer of length \p ilen Bytes. + * \param ilen The length of the input data in Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_sha512_update( mbedtls_sha512_context *ctx, + const unsigned char *input, + size_t ilen ); + +/** + * \brief This function finishes the SHA-512 operation, and writes + * the result to the output buffer. + * + * \param ctx The SHA-512 context. This must be initialized + * and have a hash operation started. + * \param output The SHA-384 or SHA-512 checksum result. + * This must be a writable buffer of length \c 64 bytes + * for SHA-512, \c 48 bytes for SHA-384. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_sha512_finish( mbedtls_sha512_context *ctx, + unsigned char *output ); + +/** + * \brief This function processes a single data block within + * the ongoing SHA-512 computation. + * This function is for internal use only. + * + * \param ctx The SHA-512 context. This must be initialized. + * \param data The buffer holding one block of data. This + * must be a readable buffer of length \c 128 Bytes. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, + const unsigned char data[128] ); + +/** + * \brief This function calculates the SHA-512 or SHA-384 + * checksum of a buffer. + * + * The function allocates the context, performs the + * calculation, and frees the context. + * + * The SHA-512 result is calculated as + * output = SHA-512(input buffer). + * + * \param input The buffer holding the input data. This must be + * a readable buffer of length \p ilen Bytes. + * \param ilen The length of the input data in Bytes. + * \param output The SHA-384 or SHA-512 checksum result. + * This must be a writable buffer of length \c 64 bytes + * for SHA-512, \c 48 bytes for SHA-384. + * \param is384 Determines which function to use. This must be either + * \c 0 for SHA-512, or \c 1 for SHA-384. + * + * \note When \c MBEDTLS_SHA384_C is not defined, \p is384 must + * be \c 0, or the function will return + * #MBEDTLS_ERR_SHA512_BAD_INPUT_DATA. + * + * \return \c 0 on success. + * \return A negative error code on failure. + */ +int mbedtls_sha512( const unsigned char *input, + size_t ilen, + unsigned char *output, + int is384 ); + +#if defined(MBEDTLS_SELF_TEST) + + /** + * \brief The SHA-384 or SHA-512 checkup routine. + * + * \return \c 0 on success. + * \return \c 1 on failure. + */ +int mbedtls_sha512_self_test( int verbose ); +#endif /* MBEDTLS_SELF_TEST */ + +#ifdef __cplusplus +} +#endif + +#endif /* mbedtls_sha512.h */ diff --git a/src/duckdb/third_party/mbedtls/library/aes.cpp b/src/duckdb/third_party/mbedtls/library/aes.cpp index c9196d1c9..4f772d631 100644 --- a/src/duckdb/third_party/mbedtls/library/aes.cpp +++ b/src/duckdb/third_party/mbedtls/library/aes.cpp @@ -1,15 +1,27 @@ /* - * FIPS-197 compliant AES implementation - * - * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ +* FIPS-197 compliant AES implementation +* +* Copyright The Mbed TLS Contributors +* SPDX-License-Identifier: Apache-2.0 +* +* Licensed under the Apache License, Version 2.0 (the "License"); you may +* not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ /* - * The AES block cipher was designed by Vincent Rijmen and Joan Daemen. - * - * https://csrc.nist.gov/csrc/media/projects/cryptographic-standards-and-guidelines/documents/aes-development/rijndael-ammended.pdf - * http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf - */ +* The AES block cipher was designed by Vincent Rijmen and Joan Daemen. +* +* http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf +* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf +*/ #include "common.h" @@ -21,437 +33,424 @@ #include "mbedtls/platform.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" - -#if defined(MBEDTLS_AES_USE_HARDWARE_ONLY) -#if !((defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(MBEDTLS_AESCE_C)) || \ - (defined(MBEDTLS_ARCH_IS_X64) && defined(MBEDTLS_AESNI_C)) || \ - (defined(MBEDTLS_ARCH_IS_X86) && defined(MBEDTLS_AESNI_C))) -#error "MBEDTLS_AES_USE_HARDWARE_ONLY defined, but not all prerequisites" -#endif -#endif - -#if defined(MBEDTLS_ARCH_IS_X86) -#if defined(MBEDTLS_PADLOCK_C) -#if !defined(MBEDTLS_HAVE_ASM) -#error "MBEDTLS_PADLOCK_C defined, but not all prerequisites" -#endif -#if defined(MBEDTLS_AES_USE_HARDWARE_ONLY) -#error "MBEDTLS_AES_USE_HARDWARE_ONLY cannot be defined when " \ - "MBEDTLS_PADLOCK_C is set" -#endif -#endif -#endif - #if defined(MBEDTLS_PADLOCK_C) #include "padlock.h" #endif #if defined(MBEDTLS_AESNI_C) #include "aesni.h" #endif -#if defined(MBEDTLS_AESCE_C) -#include "aesce.h" -#endif - -#include "ctr.h" -/* - * This is a convenience shorthand macro to check if we need reverse S-box and - * reverse tables. It's private and only defined in this file. - */ -#if (!defined(MBEDTLS_AES_DECRYPT_ALT) || \ - (!defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_AES_USE_HARDWARE_ONLY))) && \ - !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -#define MBEDTLS_AES_NEED_REVERSE_TABLES -#endif +#if defined(MBEDTLS_SELF_TEST) +//#if defined(MBEDTLS_PLATFORM_C) +//#include "mbedtls/platform.h" +//#else +//#include +//#define mbedtls_printf printf +//#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ #if !defined(MBEDTLS_AES_ALT) -#if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE) +/* Parameter validation macros based on platform_util.h */ +#define AES_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_AES_BAD_INPUT_DATA ) +#define AES_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) + +#if defined(MBEDTLS_PADLOCK_C) && \ + ( defined(MBEDTLS_HAVE_X86) || defined(MBEDTLS_PADLOCK_ALIGN16) ) static int aes_padlock_ace = -1; #endif #if defined(MBEDTLS_AES_ROM_TABLES) /* - * Forward S-box - */ -MBEDTLS_MAYBE_UNUSED static const unsigned char FSb[256] = -{ - 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, - 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, - 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, - 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, - 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, - 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, - 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, - 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, - 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, - 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, - 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, - 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, - 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, - 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, - 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, - 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, - 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, - 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, - 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, - 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, - 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, - 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, - 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, - 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, - 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, - 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, - 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, - 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, - 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, - 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, - 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, - 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 +* Forward S-box +*/ +static const unsigned char AESFSb[256] = + { + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, + 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, + 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, + 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, + 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, + 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, + 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, + 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, + 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, + 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, + 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, + 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, + 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, + 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, + 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, + 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, + 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, + 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, + 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, + 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, + 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, + 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, + 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, + 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, + 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, + 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 }; /* - * Forward tables - */ +* Forward tables +*/ #define FT \ \ - V(A5, 63, 63, C6), V(84, 7C, 7C, F8), V(99, 77, 77, EE), V(8D, 7B, 7B, F6), \ - V(0D, F2, F2, FF), V(BD, 6B, 6B, D6), V(B1, 6F, 6F, DE), V(54, C5, C5, 91), \ - V(50, 30, 30, 60), V(03, 01, 01, 02), V(A9, 67, 67, CE), V(7D, 2B, 2B, 56), \ - V(19, FE, FE, E7), V(62, D7, D7, B5), V(E6, AB, AB, 4D), V(9A, 76, 76, EC), \ - V(45, CA, CA, 8F), V(9D, 82, 82, 1F), V(40, C9, C9, 89), V(87, 7D, 7D, FA), \ - V(15, FA, FA, EF), V(EB, 59, 59, B2), V(C9, 47, 47, 8E), V(0B, F0, F0, FB), \ - V(EC, AD, AD, 41), V(67, D4, D4, B3), V(FD, A2, A2, 5F), V(EA, AF, AF, 45), \ - V(BF, 9C, 9C, 23), V(F7, A4, A4, 53), V(96, 72, 72, E4), V(5B, C0, C0, 9B), \ - V(C2, B7, B7, 75), V(1C, FD, FD, E1), V(AE, 93, 93, 3D), V(6A, 26, 26, 4C), \ - V(5A, 36, 36, 6C), V(41, 3F, 3F, 7E), V(02, F7, F7, F5), V(4F, CC, CC, 83), \ - V(5C, 34, 34, 68), V(F4, A5, A5, 51), V(34, E5, E5, D1), V(08, F1, F1, F9), \ - V(93, 71, 71, E2), V(73, D8, D8, AB), V(53, 31, 31, 62), V(3F, 15, 15, 2A), \ - V(0C, 04, 04, 08), V(52, C7, C7, 95), V(65, 23, 23, 46), V(5E, C3, C3, 9D), \ - V(28, 18, 18, 30), V(A1, 96, 96, 37), V(0F, 05, 05, 0A), V(B5, 9A, 9A, 2F), \ - V(09, 07, 07, 0E), V(36, 12, 12, 24), V(9B, 80, 80, 1B), V(3D, E2, E2, DF), \ - V(26, EB, EB, CD), V(69, 27, 27, 4E), V(CD, B2, B2, 7F), V(9F, 75, 75, EA), \ - V(1B, 09, 09, 12), V(9E, 83, 83, 1D), V(74, 2C, 2C, 58), V(2E, 1A, 1A, 34), \ - V(2D, 1B, 1B, 36), V(B2, 6E, 6E, DC), V(EE, 5A, 5A, B4), V(FB, A0, A0, 5B), \ - V(F6, 52, 52, A4), V(4D, 3B, 3B, 76), V(61, D6, D6, B7), V(CE, B3, B3, 7D), \ - V(7B, 29, 29, 52), V(3E, E3, E3, DD), V(71, 2F, 2F, 5E), V(97, 84, 84, 13), \ - V(F5, 53, 53, A6), V(68, D1, D1, B9), V(00, 00, 00, 00), V(2C, ED, ED, C1), \ - V(60, 20, 20, 40), V(1F, FC, FC, E3), V(C8, B1, B1, 79), V(ED, 5B, 5B, B6), \ - V(BE, 6A, 6A, D4), V(46, CB, CB, 8D), V(D9, BE, BE, 67), V(4B, 39, 39, 72), \ - V(DE, 4A, 4A, 94), V(D4, 4C, 4C, 98), V(E8, 58, 58, B0), V(4A, CF, CF, 85), \ - V(6B, D0, D0, BB), V(2A, EF, EF, C5), V(E5, AA, AA, 4F), V(16, FB, FB, ED), \ - V(C5, 43, 43, 86), V(D7, 4D, 4D, 9A), V(55, 33, 33, 66), V(94, 85, 85, 11), \ - V(CF, 45, 45, 8A), V(10, F9, F9, E9), V(06, 02, 02, 04), V(81, 7F, 7F, FE), \ - V(F0, 50, 50, A0), V(44, 3C, 3C, 78), V(BA, 9F, 9F, 25), V(E3, A8, A8, 4B), \ - V(F3, 51, 51, A2), V(FE, A3, A3, 5D), V(C0, 40, 40, 80), V(8A, 8F, 8F, 05), \ - V(AD, 92, 92, 3F), V(BC, 9D, 9D, 21), V(48, 38, 38, 70), V(04, F5, F5, F1), \ - V(DF, BC, BC, 63), V(C1, B6, B6, 77), V(75, DA, DA, AF), V(63, 21, 21, 42), \ - V(30, 10, 10, 20), V(1A, FF, FF, E5), V(0E, F3, F3, FD), V(6D, D2, D2, BF), \ - V(4C, CD, CD, 81), V(14, 0C, 0C, 18), V(35, 13, 13, 26), V(2F, EC, EC, C3), \ - V(E1, 5F, 5F, BE), V(A2, 97, 97, 35), V(CC, 44, 44, 88), V(39, 17, 17, 2E), \ - V(57, C4, C4, 93), V(F2, A7, A7, 55), V(82, 7E, 7E, FC), V(47, 3D, 3D, 7A), \ - V(AC, 64, 64, C8), V(E7, 5D, 5D, BA), V(2B, 19, 19, 32), V(95, 73, 73, E6), \ - V(A0, 60, 60, C0), V(98, 81, 81, 19), V(D1, 4F, 4F, 9E), V(7F, DC, DC, A3), \ - V(66, 22, 22, 44), V(7E, 2A, 2A, 54), V(AB, 90, 90, 3B), V(83, 88, 88, 0B), \ - V(CA, 46, 46, 8C), V(29, EE, EE, C7), V(D3, B8, B8, 6B), V(3C, 14, 14, 28), \ - V(79, DE, DE, A7), V(E2, 5E, 5E, BC), V(1D, 0B, 0B, 16), V(76, DB, DB, AD), \ - V(3B, E0, E0, DB), V(56, 32, 32, 64), V(4E, 3A, 3A, 74), V(1E, 0A, 0A, 14), \ - V(DB, 49, 49, 92), V(0A, 06, 06, 0C), V(6C, 24, 24, 48), V(E4, 5C, 5C, B8), \ - V(5D, C2, C2, 9F), V(6E, D3, D3, BD), V(EF, AC, AC, 43), V(A6, 62, 62, C4), \ - V(A8, 91, 91, 39), V(A4, 95, 95, 31), V(37, E4, E4, D3), V(8B, 79, 79, F2), \ - V(32, E7, E7, D5), V(43, C8, C8, 8B), V(59, 37, 37, 6E), V(B7, 6D, 6D, DA), \ - V(8C, 8D, 8D, 01), V(64, D5, D5, B1), V(D2, 4E, 4E, 9C), V(E0, A9, A9, 49), \ - V(B4, 6C, 6C, D8), V(FA, 56, 56, AC), V(07, F4, F4, F3), V(25, EA, EA, CF), \ - V(AF, 65, 65, CA), V(8E, 7A, 7A, F4), V(E9, AE, AE, 47), V(18, 08, 08, 10), \ - V(D5, BA, BA, 6F), V(88, 78, 78, F0), V(6F, 25, 25, 4A), V(72, 2E, 2E, 5C), \ - V(24, 1C, 1C, 38), V(F1, A6, A6, 57), V(C7, B4, B4, 73), V(51, C6, C6, 97), \ - V(23, E8, E8, CB), V(7C, DD, DD, A1), V(9C, 74, 74, E8), V(21, 1F, 1F, 3E), \ - V(DD, 4B, 4B, 96), V(DC, BD, BD, 61), V(86, 8B, 8B, 0D), V(85, 8A, 8A, 0F), \ - V(90, 70, 70, E0), V(42, 3E, 3E, 7C), V(C4, B5, B5, 71), V(AA, 66, 66, CC), \ - V(D8, 48, 48, 90), V(05, 03, 03, 06), V(01, F6, F6, F7), V(12, 0E, 0E, 1C), \ - V(A3, 61, 61, C2), V(5F, 35, 35, 6A), V(F9, 57, 57, AE), V(D0, B9, B9, 69), \ - V(91, 86, 86, 17), V(58, C1, C1, 99), V(27, 1D, 1D, 3A), V(B9, 9E, 9E, 27), \ - V(38, E1, E1, D9), V(13, F8, F8, EB), V(B3, 98, 98, 2B), V(33, 11, 11, 22), \ - V(BB, 69, 69, D2), V(70, D9, D9, A9), V(89, 8E, 8E, 07), V(A7, 94, 94, 33), \ - V(B6, 9B, 9B, 2D), V(22, 1E, 1E, 3C), V(92, 87, 87, 15), V(20, E9, E9, C9), \ - V(49, CE, CE, 87), V(FF, 55, 55, AA), V(78, 28, 28, 50), V(7A, DF, DF, A5), \ - V(8F, 8C, 8C, 03), V(F8, A1, A1, 59), V(80, 89, 89, 09), V(17, 0D, 0D, 1A), \ - V(DA, BF, BF, 65), V(31, E6, E6, D7), V(C6, 42, 42, 84), V(B8, 68, 68, D0), \ - V(C3, 41, 41, 82), V(B0, 99, 99, 29), V(77, 2D, 2D, 5A), V(11, 0F, 0F, 1E), \ - V(CB, B0, B0, 7B), V(FC, 54, 54, A8), V(D6, BB, BB, 6D), V(3A, 16, 16, 2C) - -#define V(a, b, c, d) 0x##a##b##c##d -MBEDTLS_MAYBE_UNUSED static const uint32_t FT0[256] = { FT }; + V(A5,63,63,C6), V(84,7C,7C,F8), V(99,77,77,EE), V(8D,7B,7B,F6), \ + V(0D,F2,F2,FF), V(BD,6B,6B,D6), V(B1,6F,6F,DE), V(54,C5,C5,91), \ + V(50,30,30,60), V(03,01,01,02), V(A9,67,67,CE), V(7D,2B,2B,56), \ + V(19,FE,FE,E7), V(62,D7,D7,B5), V(E6,AB,AB,4D), V(9A,76,76,EC), \ + V(45,CA,CA,8F), V(9D,82,82,1F), V(40,C9,C9,89), V(87,7D,7D,FA), \ + V(15,FA,FA,EF), V(EB,59,59,B2), V(C9,47,47,8E), V(0B,F0,F0,FB), \ + V(EC,AD,AD,41), V(67,D4,D4,B3), V(FD,A2,A2,5F), V(EA,AF,AF,45), \ + V(BF,9C,9C,23), V(F7,A4,A4,53), V(96,72,72,E4), V(5B,C0,C0,9B), \ + V(C2,B7,B7,75), V(1C,FD,FD,E1), V(AE,93,93,3D), V(6A,26,26,4C), \ + V(5A,36,36,6C), V(41,3F,3F,7E), V(02,F7,F7,F5), V(4F,CC,CC,83), \ + V(5C,34,34,68), V(F4,A5,A5,51), V(34,E5,E5,D1), V(08,F1,F1,F9), \ + V(93,71,71,E2), V(73,D8,D8,AB), V(53,31,31,62), V(3F,15,15,2A), \ + V(0C,04,04,08), V(52,C7,C7,95), V(65,23,23,46), V(5E,C3,C3,9D), \ + V(28,18,18,30), V(A1,96,96,37), V(0F,05,05,0A), V(B5,9A,9A,2F), \ + V(09,07,07,0E), V(36,12,12,24), V(9B,80,80,1B), V(3D,E2,E2,DF), \ + V(26,EB,EB,CD), V(69,27,27,4E), V(CD,B2,B2,7F), V(9F,75,75,EA), \ + V(1B,09,09,12), V(9E,83,83,1D), V(74,2C,2C,58), V(2E,1A,1A,34), \ + V(2D,1B,1B,36), V(B2,6E,6E,DC), V(EE,5A,5A,B4), V(FB,A0,A0,5B), \ + V(F6,52,52,A4), V(4D,3B,3B,76), V(61,D6,D6,B7), V(CE,B3,B3,7D), \ + V(7B,29,29,52), V(3E,E3,E3,DD), V(71,2F,2F,5E), V(97,84,84,13), \ + V(F5,53,53,A6), V(68,D1,D1,B9), V(00,00,00,00), V(2C,ED,ED,C1), \ + V(60,20,20,40), V(1F,FC,FC,E3), V(C8,B1,B1,79), V(ED,5B,5B,B6), \ + V(BE,6A,6A,D4), V(46,CB,CB,8D), V(D9,BE,BE,67), V(4B,39,39,72), \ + V(DE,4A,4A,94), V(D4,4C,4C,98), V(E8,58,58,B0), V(4A,CF,CF,85), \ + V(6B,D0,D0,BB), V(2A,EF,EF,C5), V(E5,AA,AA,4F), V(16,FB,FB,ED), \ + V(C5,43,43,86), V(D7,4D,4D,9A), V(55,33,33,66), V(94,85,85,11), \ + V(CF,45,45,8A), V(10,F9,F9,E9), V(06,02,02,04), V(81,7F,7F,FE), \ + V(F0,50,50,A0), V(44,3C,3C,78), V(BA,9F,9F,25), V(E3,A8,A8,4B), \ + V(F3,51,51,A2), V(FE,A3,A3,5D), V(C0,40,40,80), V(8A,8F,8F,05), \ + V(AD,92,92,3F), V(BC,9D,9D,21), V(48,38,38,70), V(04,F5,F5,F1), \ + V(DF,BC,BC,63), V(C1,B6,B6,77), V(75,DA,DA,AF), V(63,21,21,42), \ + V(30,10,10,20), V(1A,FF,FF,E5), V(0E,F3,F3,FD), V(6D,D2,D2,BF), \ + V(4C,CD,CD,81), V(14,0C,0C,18), V(35,13,13,26), V(2F,EC,EC,C3), \ + V(E1,5F,5F,BE), V(A2,97,97,35), V(CC,44,44,88), V(39,17,17,2E), \ + V(57,C4,C4,93), V(F2,A7,A7,55), V(82,7E,7E,FC), V(47,3D,3D,7A), \ + V(AC,64,64,C8), V(E7,5D,5D,BA), V(2B,19,19,32), V(95,73,73,E6), \ + V(A0,60,60,C0), V(98,81,81,19), V(D1,4F,4F,9E), V(7F,DC,DC,A3), \ + V(66,22,22,44), V(7E,2A,2A,54), V(AB,90,90,3B), V(83,88,88,0B), \ + V(CA,46,46,8C), V(29,EE,EE,C7), V(D3,B8,B8,6B), V(3C,14,14,28), \ + V(79,DE,DE,A7), V(E2,5E,5E,BC), V(1D,0B,0B,16), V(76,DB,DB,AD), \ + V(3B,E0,E0,DB), V(56,32,32,64), V(4E,3A,3A,74), V(1E,0A,0A,14), \ + V(DB,49,49,92), V(0A,06,06,0C), V(6C,24,24,48), V(E4,5C,5C,B8), \ + V(5D,C2,C2,9F), V(6E,D3,D3,BD), V(EF,AC,AC,43), V(A6,62,62,C4), \ + V(A8,91,91,39), V(A4,95,95,31), V(37,E4,E4,D3), V(8B,79,79,F2), \ + V(32,E7,E7,D5), V(43,C8,C8,8B), V(59,37,37,6E), V(B7,6D,6D,DA), \ + V(8C,8D,8D,01), V(64,D5,D5,B1), V(D2,4E,4E,9C), V(E0,A9,A9,49), \ + V(B4,6C,6C,D8), V(FA,56,56,AC), V(07,F4,F4,F3), V(25,EA,EA,CF), \ + V(AF,65,65,CA), V(8E,7A,7A,F4), V(E9,AE,AE,47), V(18,08,08,10), \ + V(D5,BA,BA,6F), V(88,78,78,F0), V(6F,25,25,4A), V(72,2E,2E,5C), \ + V(24,1C,1C,38), V(F1,A6,A6,57), V(C7,B4,B4,73), V(51,C6,C6,97), \ + V(23,E8,E8,CB), V(7C,DD,DD,A1), V(9C,74,74,E8), V(21,1F,1F,3E), \ + V(DD,4B,4B,96), V(DC,BD,BD,61), V(86,8B,8B,0D), V(85,8A,8A,0F), \ + V(90,70,70,E0), V(42,3E,3E,7C), V(C4,B5,B5,71), V(AA,66,66,CC), \ + V(D8,48,48,90), V(05,03,03,06), V(01,F6,F6,F7), V(12,0E,0E,1C), \ + V(A3,61,61,C2), V(5F,35,35,6A), V(F9,57,57,AE), V(D0,B9,B9,69), \ + V(91,86,86,17), V(58,C1,C1,99), V(27,1D,1D,3A), V(B9,9E,9E,27), \ + V(38,E1,E1,D9), V(13,F8,F8,EB), V(B3,98,98,2B), V(33,11,11,22), \ + V(BB,69,69,D2), V(70,D9,D9,A9), V(89,8E,8E,07), V(A7,94,94,33), \ + V(B6,9B,9B,2D), V(22,1E,1E,3C), V(92,87,87,15), V(20,E9,E9,C9), \ + V(49,CE,CE,87), V(FF,55,55,AA), V(78,28,28,50), V(7A,DF,DF,A5), \ + V(8F,8C,8C,03), V(F8,A1,A1,59), V(80,89,89,09), V(17,0D,0D,1A), \ + V(DA,BF,BF,65), V(31,E6,E6,D7), V(C6,42,42,84), V(B8,68,68,D0), \ + V(C3,41,41,82), V(B0,99,99,29), V(77,2D,2D,5A), V(11,0F,0F,1E), \ + V(CB,B0,B0,7B), V(FC,54,54,A8), V(D6,BB,BB,6D), V(3A,16,16,2C) + +#define V(a,b,c,d) 0x##a##b##c##d +static const uint32_t FT0[256] = { FT }; #undef V -#define V(a, b, c, d) 0x##b##c##d##a -MBEDTLS_MAYBE_UNUSED static const uint32_t FT1[256] = { FT }; +#if !defined(MBEDTLS_AES_FEWER_TABLES) + +#define V(a,b,c,d) 0x##b##c##d##a +static const uint32_t FT1[256] = { FT }; #undef V -#define V(a, b, c, d) 0x##c##d##a##b -MBEDTLS_MAYBE_UNUSED static const uint32_t FT2[256] = { FT }; +#define V(a,b,c,d) 0x##c##d##a##b +static const uint32_t FT2[256] = { FT }; #undef V -#define V(a, b, c, d) 0x##d##a##b##c -MBEDTLS_MAYBE_UNUSED static const uint32_t FT3[256] = { FT }; +#define V(a,b,c,d) 0x##d##a##b##c +static const uint32_t FT3[256] = { FT }; #undef V +#endif /* !MBEDTLS_AES_FEWER_TABLES */ + #undef FT /* - * Reverse S-box - */ -MBEDTLS_MAYBE_UNUSED static const unsigned char RSb[256] = -{ - 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, - 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, - 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, - 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, - 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, - 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, - 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, - 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, - 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, - 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, - 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, - 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, - 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, - 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, - 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, - 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, - 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, - 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, - 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, - 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, - 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, - 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, - 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, - 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, - 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, - 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, - 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, - 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, - 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, - 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, - 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, - 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D +* Reverse S-box +*/ +static const unsigned char RSb[256] = + { + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, + 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, + 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, + 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, + 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, + 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, + 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, + 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, + 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, + 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, + 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, + 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, + 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, + 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, + 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, + 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, + 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, + 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, + 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, + 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, + 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, + 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, + 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, + 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, + 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D }; /* - * Reverse tables - */ +* Reverse tables +*/ #define RT \ \ - V(50, A7, F4, 51), V(53, 65, 41, 7E), V(C3, A4, 17, 1A), V(96, 5E, 27, 3A), \ - V(CB, 6B, AB, 3B), V(F1, 45, 9D, 1F), V(AB, 58, FA, AC), V(93, 03, E3, 4B), \ - V(55, FA, 30, 20), V(F6, 6D, 76, AD), V(91, 76, CC, 88), V(25, 4C, 02, F5), \ - V(FC, D7, E5, 4F), V(D7, CB, 2A, C5), V(80, 44, 35, 26), V(8F, A3, 62, B5), \ - V(49, 5A, B1, DE), V(67, 1B, BA, 25), V(98, 0E, EA, 45), V(E1, C0, FE, 5D), \ - V(02, 75, 2F, C3), V(12, F0, 4C, 81), V(A3, 97, 46, 8D), V(C6, F9, D3, 6B), \ - V(E7, 5F, 8F, 03), V(95, 9C, 92, 15), V(EB, 7A, 6D, BF), V(DA, 59, 52, 95), \ - V(2D, 83, BE, D4), V(D3, 21, 74, 58), V(29, 69, E0, 49), V(44, C8, C9, 8E), \ - V(6A, 89, C2, 75), V(78, 79, 8E, F4), V(6B, 3E, 58, 99), V(DD, 71, B9, 27), \ - V(B6, 4F, E1, BE), V(17, AD, 88, F0), V(66, AC, 20, C9), V(B4, 3A, CE, 7D), \ - V(18, 4A, DF, 63), V(82, 31, 1A, E5), V(60, 33, 51, 97), V(45, 7F, 53, 62), \ - V(E0, 77, 64, B1), V(84, AE, 6B, BB), V(1C, A0, 81, FE), V(94, 2B, 08, F9), \ - V(58, 68, 48, 70), V(19, FD, 45, 8F), V(87, 6C, DE, 94), V(B7, F8, 7B, 52), \ - V(23, D3, 73, AB), V(E2, 02, 4B, 72), V(57, 8F, 1F, E3), V(2A, AB, 55, 66), \ - V(07, 28, EB, B2), V(03, C2, B5, 2F), V(9A, 7B, C5, 86), V(A5, 08, 37, D3), \ - V(F2, 87, 28, 30), V(B2, A5, BF, 23), V(BA, 6A, 03, 02), V(5C, 82, 16, ED), \ - V(2B, 1C, CF, 8A), V(92, B4, 79, A7), V(F0, F2, 07, F3), V(A1, E2, 69, 4E), \ - V(CD, F4, DA, 65), V(D5, BE, 05, 06), V(1F, 62, 34, D1), V(8A, FE, A6, C4), \ - V(9D, 53, 2E, 34), V(A0, 55, F3, A2), V(32, E1, 8A, 05), V(75, EB, F6, A4), \ - V(39, EC, 83, 0B), V(AA, EF, 60, 40), V(06, 9F, 71, 5E), V(51, 10, 6E, BD), \ - V(F9, 8A, 21, 3E), V(3D, 06, DD, 96), V(AE, 05, 3E, DD), V(46, BD, E6, 4D), \ - V(B5, 8D, 54, 91), V(05, 5D, C4, 71), V(6F, D4, 06, 04), V(FF, 15, 50, 60), \ - V(24, FB, 98, 19), V(97, E9, BD, D6), V(CC, 43, 40, 89), V(77, 9E, D9, 67), \ - V(BD, 42, E8, B0), V(88, 8B, 89, 07), V(38, 5B, 19, E7), V(DB, EE, C8, 79), \ - V(47, 0A, 7C, A1), V(E9, 0F, 42, 7C), V(C9, 1E, 84, F8), V(00, 00, 00, 00), \ - V(83, 86, 80, 09), V(48, ED, 2B, 32), V(AC, 70, 11, 1E), V(4E, 72, 5A, 6C), \ - V(FB, FF, 0E, FD), V(56, 38, 85, 0F), V(1E, D5, AE, 3D), V(27, 39, 2D, 36), \ - V(64, D9, 0F, 0A), V(21, A6, 5C, 68), V(D1, 54, 5B, 9B), V(3A, 2E, 36, 24), \ - V(B1, 67, 0A, 0C), V(0F, E7, 57, 93), V(D2, 96, EE, B4), V(9E, 91, 9B, 1B), \ - V(4F, C5, C0, 80), V(A2, 20, DC, 61), V(69, 4B, 77, 5A), V(16, 1A, 12, 1C), \ - V(0A, BA, 93, E2), V(E5, 2A, A0, C0), V(43, E0, 22, 3C), V(1D, 17, 1B, 12), \ - V(0B, 0D, 09, 0E), V(AD, C7, 8B, F2), V(B9, A8, B6, 2D), V(C8, A9, 1E, 14), \ - V(85, 19, F1, 57), V(4C, 07, 75, AF), V(BB, DD, 99, EE), V(FD, 60, 7F, A3), \ - V(9F, 26, 01, F7), V(BC, F5, 72, 5C), V(C5, 3B, 66, 44), V(34, 7E, FB, 5B), \ - V(76, 29, 43, 8B), V(DC, C6, 23, CB), V(68, FC, ED, B6), V(63, F1, E4, B8), \ - V(CA, DC, 31, D7), V(10, 85, 63, 42), V(40, 22, 97, 13), V(20, 11, C6, 84), \ - V(7D, 24, 4A, 85), V(F8, 3D, BB, D2), V(11, 32, F9, AE), V(6D, A1, 29, C7), \ - V(4B, 2F, 9E, 1D), V(F3, 30, B2, DC), V(EC, 52, 86, 0D), V(D0, E3, C1, 77), \ - V(6C, 16, B3, 2B), V(99, B9, 70, A9), V(FA, 48, 94, 11), V(22, 64, E9, 47), \ - V(C4, 8C, FC, A8), V(1A, 3F, F0, A0), V(D8, 2C, 7D, 56), V(EF, 90, 33, 22), \ - V(C7, 4E, 49, 87), V(C1, D1, 38, D9), V(FE, A2, CA, 8C), V(36, 0B, D4, 98), \ - V(CF, 81, F5, A6), V(28, DE, 7A, A5), V(26, 8E, B7, DA), V(A4, BF, AD, 3F), \ - V(E4, 9D, 3A, 2C), V(0D, 92, 78, 50), V(9B, CC, 5F, 6A), V(62, 46, 7E, 54), \ - V(C2, 13, 8D, F6), V(E8, B8, D8, 90), V(5E, F7, 39, 2E), V(F5, AF, C3, 82), \ - V(BE, 80, 5D, 9F), V(7C, 93, D0, 69), V(A9, 2D, D5, 6F), V(B3, 12, 25, CF), \ - V(3B, 99, AC, C8), V(A7, 7D, 18, 10), V(6E, 63, 9C, E8), V(7B, BB, 3B, DB), \ - V(09, 78, 26, CD), V(F4, 18, 59, 6E), V(01, B7, 9A, EC), V(A8, 9A, 4F, 83), \ - V(65, 6E, 95, E6), V(7E, E6, FF, AA), V(08, CF, BC, 21), V(E6, E8, 15, EF), \ - V(D9, 9B, E7, BA), V(CE, 36, 6F, 4A), V(D4, 09, 9F, EA), V(D6, 7C, B0, 29), \ - V(AF, B2, A4, 31), V(31, 23, 3F, 2A), V(30, 94, A5, C6), V(C0, 66, A2, 35), \ - V(37, BC, 4E, 74), V(A6, CA, 82, FC), V(B0, D0, 90, E0), V(15, D8, A7, 33), \ - V(4A, 98, 04, F1), V(F7, DA, EC, 41), V(0E, 50, CD, 7F), V(2F, F6, 91, 17), \ - V(8D, D6, 4D, 76), V(4D, B0, EF, 43), V(54, 4D, AA, CC), V(DF, 04, 96, E4), \ - V(E3, B5, D1, 9E), V(1B, 88, 6A, 4C), V(B8, 1F, 2C, C1), V(7F, 51, 65, 46), \ - V(04, EA, 5E, 9D), V(5D, 35, 8C, 01), V(73, 74, 87, FA), V(2E, 41, 0B, FB), \ - V(5A, 1D, 67, B3), V(52, D2, DB, 92), V(33, 56, 10, E9), V(13, 47, D6, 6D), \ - V(8C, 61, D7, 9A), V(7A, 0C, A1, 37), V(8E, 14, F8, 59), V(89, 3C, 13, EB), \ - V(EE, 27, A9, CE), V(35, C9, 61, B7), V(ED, E5, 1C, E1), V(3C, B1, 47, 7A), \ - V(59, DF, D2, 9C), V(3F, 73, F2, 55), V(79, CE, 14, 18), V(BF, 37, C7, 73), \ - V(EA, CD, F7, 53), V(5B, AA, FD, 5F), V(14, 6F, 3D, DF), V(86, DB, 44, 78), \ - V(81, F3, AF, CA), V(3E, C4, 68, B9), V(2C, 34, 24, 38), V(5F, 40, A3, C2), \ - V(72, C3, 1D, 16), V(0C, 25, E2, BC), V(8B, 49, 3C, 28), V(41, 95, 0D, FF), \ - V(71, 01, A8, 39), V(DE, B3, 0C, 08), V(9C, E4, B4, D8), V(90, C1, 56, 64), \ - V(61, 84, CB, 7B), V(70, B6, 32, D5), V(74, 5C, 6C, 48), V(42, 57, B8, D0) - - -#define V(a, b, c, d) 0x##a##b##c##d -MBEDTLS_MAYBE_UNUSED static const uint32_t RT0[256] = { RT }; + V(50,A7,F4,51), V(53,65,41,7E), V(C3,A4,17,1A), V(96,5E,27,3A), \ + V(CB,6B,AB,3B), V(F1,45,9D,1F), V(AB,58,FA,AC), V(93,03,E3,4B), \ + V(55,FA,30,20), V(F6,6D,76,AD), V(91,76,CC,88), V(25,4C,02,F5), \ + V(FC,D7,E5,4F), V(D7,CB,2A,C5), V(80,44,35,26), V(8F,A3,62,B5), \ + V(49,5A,B1,DE), V(67,1B,BA,25), V(98,0E,EA,45), V(E1,C0,FE,5D), \ + V(02,75,2F,C3), V(12,F0,4C,81), V(A3,97,46,8D), V(C6,F9,D3,6B), \ + V(E7,5F,8F,03), V(95,9C,92,15), V(EB,7A,6D,BF), V(DA,59,52,95), \ + V(2D,83,BE,D4), V(D3,21,74,58), V(29,69,E0,49), V(44,C8,C9,8E), \ + V(6A,89,C2,75), V(78,79,8E,F4), V(6B,3E,58,99), V(DD,71,B9,27), \ + V(B6,4F,E1,BE), V(17,AD,88,F0), V(66,AC,20,C9), V(B4,3A,CE,7D), \ + V(18,4A,DF,63), V(82,31,1A,E5), V(60,33,51,97), V(45,7F,53,62), \ + V(E0,77,64,B1), V(84,AE,6B,BB), V(1C,A0,81,FE), V(94,2B,08,F9), \ + V(58,68,48,70), V(19,FD,45,8F), V(87,6C,DE,94), V(B7,F8,7B,52), \ + V(23,D3,73,AB), V(E2,02,4B,72), V(57,8F,1F,E3), V(2A,AB,55,66), \ + V(07,28,EB,B2), V(03,C2,B5,2F), V(9A,7B,C5,86), V(A5,08,37,D3), \ + V(F2,87,28,30), V(B2,A5,BF,23), V(BA,6A,03,02), V(5C,82,16,ED), \ + V(2B,1C,CF,8A), V(92,B4,79,A7), V(F0,F2,07,F3), V(A1,E2,69,4E), \ + V(CD,F4,DA,65), V(D5,BE,05,06), V(1F,62,34,D1), V(8A,FE,A6,C4), \ + V(9D,53,2E,34), V(A0,55,F3,A2), V(32,E1,8A,05), V(75,EB,F6,A4), \ + V(39,EC,83,0B), V(AA,EF,60,40), V(06,9F,71,5E), V(51,10,6E,BD), \ + V(F9,8A,21,3E), V(3D,06,DD,96), V(AE,05,3E,DD), V(46,BD,E6,4D), \ + V(B5,8D,54,91), V(05,5D,C4,71), V(6F,D4,06,04), V(FF,15,50,60), \ + V(24,FB,98,19), V(97,E9,BD,D6), V(CC,43,40,89), V(77,9E,D9,67), \ + V(BD,42,E8,B0), V(88,8B,89,07), V(38,5B,19,E7), V(DB,EE,C8,79), \ + V(47,0A,7C,A1), V(E9,0F,42,7C), V(C9,1E,84,F8), V(00,00,00,00), \ + V(83,86,80,09), V(48,ED,2B,32), V(AC,70,11,1E), V(4E,72,5A,6C), \ + V(FB,FF,0E,FD), V(56,38,85,0F), V(1E,D5,AE,3D), V(27,39,2D,36), \ + V(64,D9,0F,0A), V(21,A6,5C,68), V(D1,54,5B,9B), V(3A,2E,36,24), \ + V(B1,67,0A,0C), V(0F,E7,57,93), V(D2,96,EE,B4), V(9E,91,9B,1B), \ + V(4F,C5,C0,80), V(A2,20,DC,61), V(69,4B,77,5A), V(16,1A,12,1C), \ + V(0A,BA,93,E2), V(E5,2A,A0,C0), V(43,E0,22,3C), V(1D,17,1B,12), \ + V(0B,0D,09,0E), V(AD,C7,8B,F2), V(B9,A8,B6,2D), V(C8,A9,1E,14), \ + V(85,19,F1,57), V(4C,07,75,AF), V(BB,DD,99,EE), V(FD,60,7F,A3), \ + V(9F,26,01,F7), V(BC,F5,72,5C), V(C5,3B,66,44), V(34,7E,FB,5B), \ + V(76,29,43,8B), V(DC,C6,23,CB), V(68,FC,ED,B6), V(63,F1,E4,B8), \ + V(CA,DC,31,D7), V(10,85,63,42), V(40,22,97,13), V(20,11,C6,84), \ + V(7D,24,4A,85), V(F8,3D,BB,D2), V(11,32,F9,AE), V(6D,A1,29,C7), \ + V(4B,2F,9E,1D), V(F3,30,B2,DC), V(EC,52,86,0D), V(D0,E3,C1,77), \ + V(6C,16,B3,2B), V(99,B9,70,A9), V(FA,48,94,11), V(22,64,E9,47), \ + V(C4,8C,FC,A8), V(1A,3F,F0,A0), V(D8,2C,7D,56), V(EF,90,33,22), \ + V(C7,4E,49,87), V(C1,D1,38,D9), V(FE,A2,CA,8C), V(36,0B,D4,98), \ + V(CF,81,F5,A6), V(28,DE,7A,A5), V(26,8E,B7,DA), V(A4,BF,AD,3F), \ + V(E4,9D,3A,2C), V(0D,92,78,50), V(9B,CC,5F,6A), V(62,46,7E,54), \ + V(C2,13,8D,F6), V(E8,B8,D8,90), V(5E,F7,39,2E), V(F5,AF,C3,82), \ + V(BE,80,5D,9F), V(7C,93,D0,69), V(A9,2D,D5,6F), V(B3,12,25,CF), \ + V(3B,99,AC,C8), V(A7,7D,18,10), V(6E,63,9C,E8), V(7B,BB,3B,DB), \ + V(09,78,26,CD), V(F4,18,59,6E), V(01,B7,9A,EC), V(A8,9A,4F,83), \ + V(65,6E,95,E6), V(7E,E6,FF,AA), V(08,CF,BC,21), V(E6,E8,15,EF), \ + V(D9,9B,E7,BA), V(CE,36,6F,4A), V(D4,09,9F,EA), V(D6,7C,B0,29), \ + V(AF,B2,A4,31), V(31,23,3F,2A), V(30,94,A5,C6), V(C0,66,A2,35), \ + V(37,BC,4E,74), V(A6,CA,82,FC), V(B0,D0,90,E0), V(15,D8,A7,33), \ + V(4A,98,04,F1), V(F7,DA,EC,41), V(0E,50,CD,7F), V(2F,F6,91,17), \ + V(8D,D6,4D,76), V(4D,B0,EF,43), V(54,4D,AA,CC), V(DF,04,96,E4), \ + V(E3,B5,D1,9E), V(1B,88,6A,4C), V(B8,1F,2C,C1), V(7F,51,65,46), \ + V(04,EA,5E,9D), V(5D,35,8C,01), V(73,74,87,FA), V(2E,41,0B,FB), \ + V(5A,1D,67,B3), V(52,D2,DB,92), V(33,56,10,E9), V(13,47,D6,6D), \ + V(8C,61,D7,9A), V(7A,0C,A1,37), V(8E,14,F8,59), V(89,3C,13,EB), \ + V(EE,27,A9,CE), V(35,C9,61,B7), V(ED,E5,1C,E1), V(3C,B1,47,7A), \ + V(59,DF,D2,9C), V(3F,73,F2,55), V(79,CE,14,18), V(BF,37,C7,73), \ + V(EA,CD,F7,53), V(5B,AA,FD,5F), V(14,6F,3D,DF), V(86,DB,44,78), \ + V(81,F3,AF,CA), V(3E,C4,68,B9), V(2C,34,24,38), V(5F,40,A3,C2), \ + V(72,C3,1D,16), V(0C,25,E2,BC), V(8B,49,3C,28), V(41,95,0D,FF), \ + V(71,01,A8,39), V(DE,B3,0C,08), V(9C,E4,B4,D8), V(90,C1,56,64), \ + V(61,84,CB,7B), V(70,B6,32,D5), V(74,5C,6C,48), V(42,57,B8,D0) + +#define V(a,b,c,d) 0x##a##b##c##d +static const uint32_t RT0[256] = { RT }; #undef V -#define V(a, b, c, d) 0x##b##c##d##a -MBEDTLS_MAYBE_UNUSED static const uint32_t RT1[256] = { RT }; +#if !defined(MBEDTLS_AES_FEWER_TABLES) + +#define V(a,b,c,d) 0x##b##c##d##a +static const uint32_t RT1[256] = { RT }; #undef V -#define V(a, b, c, d) 0x##c##d##a##b -MBEDTLS_MAYBE_UNUSED static const uint32_t RT2[256] = { RT }; +#define V(a,b,c,d) 0x##c##d##a##b +static const uint32_t RT2[256] = { RT }; #undef V -#define V(a, b, c, d) 0x##d##a##b##c -MBEDTLS_MAYBE_UNUSED static const uint32_t RT3[256] = { RT }; +#define V(a,b,c,d) 0x##d##a##b##c +static const uint32_t RT3[256] = { RT }; #undef V +#endif /* !MBEDTLS_AES_FEWER_TABLES */ + #undef RT /* - * Round constants - */ -MBEDTLS_MAYBE_UNUSED static const uint32_t round_constants[10] = -{ - 0x00000001, 0x00000002, 0x00000004, 0x00000008, - 0x00000010, 0x00000020, 0x00000040, 0x00000080, - 0x0000001B, 0x00000036 +* Round constants +*/ +static const uint32_t RCON[10] = + { + 0x00000001, 0x00000002, 0x00000004, 0x00000008, + 0x00000010, 0x00000020, 0x00000040, 0x00000080, + 0x0000001B, 0x00000036 }; #else /* MBEDTLS_AES_ROM_TABLES */ /* - * Forward S-box & tables - */ -MBEDTLS_MAYBE_UNUSED static unsigned char FSb[256]; -MBEDTLS_MAYBE_UNUSED static uint32_t FT0[256]; -MBEDTLS_MAYBE_UNUSED static uint32_t FT1[256]; -MBEDTLS_MAYBE_UNUSED static uint32_t FT2[256]; -MBEDTLS_MAYBE_UNUSED static uint32_t FT3[256]; +* Forward S-box & tables +*/ +static unsigned char AESFSb[256]; +static uint32_t FT0[256]; +#if !defined(MBEDTLS_AES_FEWER_TABLES) +static uint32_t FT1[256]; +static uint32_t FT2[256]; +static uint32_t FT3[256]; +#endif /* !MBEDTLS_AES_FEWER_TABLES */ /* - * Reverse S-box & tables - */ -MBEDTLS_MAYBE_UNUSED static unsigned char RSb[256]; - -MBEDTLS_MAYBE_UNUSED static uint32_t RT0[256]; -MBEDTLS_MAYBE_UNUSED static uint32_t RT1[256]; -MBEDTLS_MAYBE_UNUSED static uint32_t RT2[256]; -MBEDTLS_MAYBE_UNUSED static uint32_t RT3[256]; +* Reverse S-box & tables +*/ +static unsigned char RSb[256]; +static uint32_t RT0[256]; +#if !defined(MBEDTLS_AES_FEWER_TABLES) +static uint32_t RT1[256]; +static uint32_t RT2[256]; +static uint32_t RT3[256]; +#endif /* !MBEDTLS_AES_FEWER_TABLES */ /* - * Round constants - */ -MBEDTLS_MAYBE_UNUSED static uint32_t round_constants[10]; +* Round constants +*/ +static uint32_t RCON[10]; /* - * Tables generation code - */ -#define ROTL8(x) (((x) << 8) & 0xFFFFFFFF) | ((x) >> 24) -#define XTIME(x) (((x) << 1) ^ (((x) & 0x80) ? 0x1B : 0x00)) -#define MUL(x, y) (((x) && (y)) ? pow[(log[(x)]+log[(y)]) % 255] : 0) +* Tables generation code +*/ +#define ROTL8(x) ( ( (x) << 8 ) & 0xFFFFFFFF ) | ( (x) >> 24 ) +#define XTIME(x) ( ( (x) << 1 ) ^ ( ( (x) & 0x80 ) ? 0x1B : 0x00 ) ) +#define MUL(x,y) ( ( (x) && (y) ) ? pow[(log[(x)]+log[(y)]) % 255] : 0 ) -MBEDTLS_MAYBE_UNUSED static int aes_init_done = 0; +static int aes_init_done = 0; -MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void) +static void aes_gen_tables( void ) { - int i; - uint8_t x, y, z; - uint8_t pow[256]; - uint8_t log[256]; - - /* - * compute pow and log tables over GF(2^8) - */ - for (i = 0, x = 1; i < 256; i++) { - pow[i] = x; - log[x] = (uint8_t) i; - x ^= XTIME(x); - } - - /* - * calculate the round constants - */ - for (i = 0, x = 1; i < 10; i++) { - round_constants[i] = x; - x = XTIME(x); - } - - /* - * generate the forward and reverse S-boxes - */ - FSb[0x00] = 0x63; -#if defined(MBEDTLS_AES_NEED_REVERSE_TABLES) - RSb[0x63] = 0x00; -#endif - - for (i = 1; i < 256; i++) { - x = pow[255 - log[i]]; - - y = x; y = (y << 1) | (y >> 7); - x ^= y; y = (y << 1) | (y >> 7); - x ^= y; y = (y << 1) | (y >> 7); - x ^= y; y = (y << 1) | (y >> 7); - x ^= y ^ 0x63; - - FSb[i] = x; -#if defined(MBEDTLS_AES_NEED_REVERSE_TABLES) - RSb[x] = (unsigned char) i; -#endif - } - - /* - * generate the forward and reverse tables - */ - for (i = 0; i < 256; i++) { - x = FSb[i]; - y = XTIME(x); - z = y ^ x; - - FT0[i] = ((uint32_t) y) ^ - ((uint32_t) x << 8) ^ - ((uint32_t) x << 16) ^ - ((uint32_t) z << 24); + int i, x, y, z; + int pow[256]; + int log[256]; + + /* + * compute pow and log tables over GF(2^8) + */ + for( i = 0, x = 1; i < 256; i++ ) + { + pow[i] = x; + log[x] = i; + x = MBEDTLS_BYTE_0( x ^ XTIME( x ) ); + } + + /* + * calculate the round constants + */ + for( i = 0, x = 1; i < 10; i++ ) + { + RCON[i] = (uint32_t) x; + x = MBEDTLS_BYTE_0( XTIME( x ) ); + } + + /* + * generate the forward and reverse S-boxes + */ + AESFSb[0x00] = 0x63; + RSb[0x63] = 0x00; + + for( i = 1; i < 256; i++ ) + { + x = pow[255 - log[i]]; + + y = x; y = MBEDTLS_BYTE_0( ( y << 1 ) | ( y >> 7 ) ); + x ^= y; y = MBEDTLS_BYTE_0( ( y << 1 ) | ( y >> 7 ) ); + x ^= y; y = MBEDTLS_BYTE_0( ( y << 1 ) | ( y >> 7 ) ); + x ^= y; y = MBEDTLS_BYTE_0( ( y << 1 ) | ( y >> 7 ) ); + x ^= y ^ 0x63; + + AESFSb[i] = (unsigned char) x; + RSb[x] = (unsigned char) i; + } + + /* + * generate the forward and reverse tables + */ + for( i = 0; i < 256; i++ ) + { + x = AESFSb[i]; + y = MBEDTLS_BYTE_0( XTIME( x ) ); + z = MBEDTLS_BYTE_0( y ^ x ); + + FT0[i] = ( (uint32_t) y ) ^ + ( (uint32_t) x << 8 ) ^ + ( (uint32_t) x << 16 ) ^ + ( (uint32_t) z << 24 ); #if !defined(MBEDTLS_AES_FEWER_TABLES) - FT1[i] = ROTL8(FT0[i]); - FT2[i] = ROTL8(FT1[i]); - FT3[i] = ROTL8(FT2[i]); + FT1[i] = ROTL8( FT0[i] ); + FT2[i] = ROTL8( FT1[i] ); + FT3[i] = ROTL8( FT2[i] ); #endif /* !MBEDTLS_AES_FEWER_TABLES */ -#if defined(MBEDTLS_AES_NEED_REVERSE_TABLES) - x = RSb[i]; + x = RSb[i]; - RT0[i] = ((uint32_t) MUL(0x0E, x)) ^ - ((uint32_t) MUL(0x09, x) << 8) ^ - ((uint32_t) MUL(0x0D, x) << 16) ^ - ((uint32_t) MUL(0x0B, x) << 24); + RT0[i] = ( (uint32_t) MUL( 0x0E, x ) ) ^ + ( (uint32_t) MUL( 0x09, x ) << 8 ) ^ + ( (uint32_t) MUL( 0x0D, x ) << 16 ) ^ + ( (uint32_t) MUL( 0x0B, x ) << 24 ); #if !defined(MBEDTLS_AES_FEWER_TABLES) - RT1[i] = ROTL8(RT0[i]); - RT2[i] = ROTL8(RT1[i]); - RT3[i] = ROTL8(RT2[i]); + RT1[i] = ROTL8( RT0[i] ); + RT2[i] = ROTL8( RT1[i] ); + RT3[i] = ROTL8( RT2[i] ); #endif /* !MBEDTLS_AES_FEWER_TABLES */ -#endif /* MBEDTLS_AES_NEED_REVERSE_TABLES */ - } + } } #undef ROTL8 @@ -460,19 +459,19 @@ MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void) #if defined(MBEDTLS_AES_FEWER_TABLES) -#define ROTL8(x) ((uint32_t) ((x) << 8) + (uint32_t) ((x) >> 24)) -#define ROTL16(x) ((uint32_t) ((x) << 16) + (uint32_t) ((x) >> 16)) -#define ROTL24(x) ((uint32_t) ((x) << 24) + (uint32_t) ((x) >> 8)) +#define ROTL8(x) ( (uint32_t)( ( x ) << 8 ) + (uint32_t)( ( x ) >> 24 ) ) +#define ROTL16(x) ( (uint32_t)( ( x ) << 16 ) + (uint32_t)( ( x ) >> 16 ) ) +#define ROTL24(x) ( (uint32_t)( ( x ) << 24 ) + (uint32_t)( ( x ) >> 8 ) ) #define AES_RT0(idx) RT0[idx] -#define AES_RT1(idx) ROTL8(RT0[idx]) -#define AES_RT2(idx) ROTL16(RT0[idx]) -#define AES_RT3(idx) ROTL24(RT0[idx]) +#define AES_RT1(idx) ROTL8( RT0[idx] ) +#define AES_RT2(idx) ROTL16( RT0[idx] ) +#define AES_RT3(idx) ROTL24( RT0[idx] ) #define AES_FT0(idx) FT0[idx] -#define AES_FT1(idx) ROTL8(FT0[idx]) -#define AES_FT2(idx) ROTL16(FT0[idx]) -#define AES_FT3(idx) ROTL24(FT0[idx]) +#define AES_FT1(idx) ROTL8( FT0[idx] ) +#define AES_FT2(idx) ROTL16( FT0[idx] ) +#define AES_FT3(idx) ROTL24( FT0[idx] ) #else /* MBEDTLS_AES_FEWER_TABLES */ @@ -488,661 +487,595 @@ MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void) #endif /* MBEDTLS_AES_FEWER_TABLES */ -void mbedtls_aes_init(mbedtls_aes_context *ctx) +void mbedtls_aes_init( mbedtls_aes_context *ctx ) { - memset(ctx, 0, sizeof(mbedtls_aes_context)); + AES_VALIDATE( ctx != NULL ); + + memset( ctx, 0, sizeof( mbedtls_aes_context ) ); } -void mbedtls_aes_free(mbedtls_aes_context *ctx) +void mbedtls_aes_free( mbedtls_aes_context *ctx ) { - if (ctx == NULL) { - return; - } + if( ctx == NULL ) + return; - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_aes_context)); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_aes_context ) ); } #if defined(MBEDTLS_CIPHER_MODE_XTS) -void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx) -{ - mbedtls_aes_init(&ctx->crypt); - mbedtls_aes_init(&ctx->tweak); -} - -void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx) +void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx ) { - if (ctx == NULL) { - return; - } + AES_VALIDATE( ctx != NULL ); - mbedtls_aes_free(&ctx->crypt); - mbedtls_aes_free(&ctx->tweak); + mbedtls_aes_init( &ctx->crypt ); + mbedtls_aes_init( &ctx->tweak ); } -#endif /* MBEDTLS_CIPHER_MODE_XTS */ - -/* Some implementations need the round keys to be aligned. - * Return an offset to be added to buf, such that (buf + offset) is - * correctly aligned. - * Note that the offset is in units of elements of buf, i.e. 32-bit words, - * i.e. an offset of 1 means 4 bytes and so on. - */ -#if (defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE)) || \ - (defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2) -#define MAY_NEED_TO_ALIGN -#endif -MBEDTLS_MAYBE_UNUSED static unsigned mbedtls_aes_rk_offset(uint32_t *buf) +void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx ) { -#if defined(MAY_NEED_TO_ALIGN) - int align_16_bytes = 0; - -#if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE) - if (aes_padlock_ace == -1) { - aes_padlock_ace = mbedtls_padlock_has_support(MBEDTLS_PADLOCK_ACE); - } - if (aes_padlock_ace) { - align_16_bytes = 1; - } -#endif + if( ctx == NULL ) + return; -#if defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2 - if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) { - align_16_bytes = 1; - } -#endif - - if (align_16_bytes) { - /* These implementations needs 16-byte alignment - * for the round key array. */ - unsigned delta = ((uintptr_t) buf & 0x0000000fU) / 4; - if (delta == 0) { - return 0; - } else { - return 4 - delta; // 16 bytes = 4 uint32_t - } - } -#else /* MAY_NEED_TO_ALIGN */ - (void) buf; -#endif /* MAY_NEED_TO_ALIGN */ - - return 0; + mbedtls_aes_free( &ctx->crypt ); + mbedtls_aes_free( &ctx->tweak ); } +#endif /* MBEDTLS_CIPHER_MODE_XTS */ /* - * AES key schedule (encryption) - */ +* AES key schedule (encryption) +*/ #if !defined(MBEDTLS_AES_SETKEY_ENC_ALT) -int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits) +int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, + unsigned int keybits ) { - uint32_t *RK; + unsigned int i; + uint32_t *RK; - switch (keybits) { - case 128: ctx->nr = 10; break; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - case 192: ctx->nr = 12; break; - case 256: ctx->nr = 14; break; -#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */ - default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH; - } + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( key != NULL ); + + switch( keybits ) + { + case 128: ctx->nr = 10; break; + case 192: ctx->nr = 12; break; + case 256: ctx->nr = 14; break; + default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); + } #if !defined(MBEDTLS_AES_ROM_TABLES) - if (aes_init_done == 0) { - aes_gen_tables(); - aes_init_done = 1; - } + if( aes_init_done == 0 ) + { + aes_gen_tables(); + aes_init_done = 1; + } #endif - ctx->rk_offset = mbedtls_aes_rk_offset(ctx->buf); - RK = ctx->buf + ctx->rk_offset; +#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_PADLOCK_ALIGN16) + if( aes_padlock_ace == -1 ) + aes_padlock_ace = mbedtls_padlock_has_support( MBEDTLS_PADLOCK_ACE ); -#if defined(MBEDTLS_AESNI_HAVE_CODE) - if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) { - return mbedtls_aesni_setkey_enc((unsigned char *) RK, key, keybits); - } + if( aes_padlock_ace ) + ctx->rk = RK = MBEDTLS_PADLOCK_ALIGN16( ctx->buf ); + else #endif + ctx->rk = RK = ctx->buf; -#if defined(MBEDTLS_AESCE_HAVE_CODE) - if (MBEDTLS_AESCE_HAS_SUPPORT()) { - return mbedtls_aesce_setkey_enc((unsigned char *) RK, key, keybits); - } +#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) + if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) ) + return( mbedtls_aesni_setkey_enc( (unsigned char *) ctx->rk, key, keybits ) ); #endif -#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY) - for (unsigned int i = 0; i < (keybits >> 5); i++) { - RK[i] = MBEDTLS_GET_UINT32_LE(key, i << 2); - } - - switch (ctx->nr) { - case 10: - - for (unsigned int i = 0; i < 10; i++, RK += 4) { - RK[4] = RK[0] ^ round_constants[i] ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[3])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[3])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[3])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[3])] << 24); - - RK[5] = RK[1] ^ RK[4]; - RK[6] = RK[2] ^ RK[5]; - RK[7] = RK[3] ^ RK[6]; - } - break; - -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - case 12: - - for (unsigned int i = 0; i < 8; i++, RK += 6) { - RK[6] = RK[0] ^ round_constants[i] ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[5])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[5])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[5])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[5])] << 24); - - RK[7] = RK[1] ^ RK[6]; - RK[8] = RK[2] ^ RK[7]; - RK[9] = RK[3] ^ RK[8]; - RK[10] = RK[4] ^ RK[9]; - RK[11] = RK[5] ^ RK[10]; - } - break; - - case 14: - - for (unsigned int i = 0; i < 7; i++, RK += 8) { - RK[8] = RK[0] ^ round_constants[i] ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[7])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[7])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[7])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[7])] << 24); - - RK[9] = RK[1] ^ RK[8]; - RK[10] = RK[2] ^ RK[9]; - RK[11] = RK[3] ^ RK[10]; - - RK[12] = RK[4] ^ - ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[11])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[11])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[11])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[11])] << 24); - - RK[13] = RK[5] ^ RK[12]; - RK[14] = RK[6] ^ RK[13]; - RK[15] = RK[7] ^ RK[14]; - } - break; -#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */ - } - - return 0; -#endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */ + for( i = 0; i < ( keybits >> 5 ); i++ ) + { + RK[i] = MBEDTLS_GET_UINT32_LE( key, i << 2 ); + } + + switch( ctx->nr ) + { + case 10: + + for( i = 0; i < 10; i++, RK += 4 ) + { + RK[4] = RK[0] ^ RCON[i] ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( RK[3] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( RK[3] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( RK[3] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( RK[3] ) ] << 24 ); + + RK[5] = RK[1] ^ RK[4]; + RK[6] = RK[2] ^ RK[5]; + RK[7] = RK[3] ^ RK[6]; + } + break; + + case 12: + + for( i = 0; i < 8; i++, RK += 6 ) + { + RK[6] = RK[0] ^ RCON[i] ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( RK[5] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( RK[5] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( RK[5] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( RK[5] ) ] << 24 ); + + RK[7] = RK[1] ^ RK[6]; + RK[8] = RK[2] ^ RK[7]; + RK[9] = RK[3] ^ RK[8]; + RK[10] = RK[4] ^ RK[9]; + RK[11] = RK[5] ^ RK[10]; + } + break; + + case 14: + + for( i = 0; i < 7; i++, RK += 8 ) + { + RK[8] = RK[0] ^ RCON[i] ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( RK[7] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( RK[7] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( RK[7] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( RK[7] ) ] << 24 ); + + RK[9] = RK[1] ^ RK[8]; + RK[10] = RK[2] ^ RK[9]; + RK[11] = RK[3] ^ RK[10]; + + RK[12] = RK[4] ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( RK[11] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( RK[11] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( RK[11] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( RK[11] ) ] << 24 ); + + RK[13] = RK[5] ^ RK[12]; + RK[14] = RK[6] ^ RK[13]; + RK[15] = RK[7] ^ RK[14]; + } + break; + } + + return( 0 ); } #endif /* !MBEDTLS_AES_SETKEY_ENC_ALT */ /* - * AES key schedule (decryption) - */ -#if !defined(MBEDTLS_AES_SETKEY_DEC_ALT) && !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, - unsigned int keybits) +* AES key schedule (decryption) +*/ +#if !defined(MBEDTLS_AES_SETKEY_DEC_ALT) +int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key, + unsigned int keybits ) { -#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY) - uint32_t *SK; -#endif - int ret; - mbedtls_aes_context cty; - uint32_t *RK; + int i, j, ret; + mbedtls_aes_context cty; + uint32_t *RK; + uint32_t *SK; + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( key != NULL ); - mbedtls_aes_init(&cty); + mbedtls_aes_init( &cty ); - ctx->rk_offset = mbedtls_aes_rk_offset(ctx->buf); - RK = ctx->buf + ctx->rk_offset; +#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_PADLOCK_ALIGN16) + if( aes_padlock_ace == -1 ) + aes_padlock_ace = mbedtls_padlock_has_support( MBEDTLS_PADLOCK_ACE ); - /* Also checks keybits */ - if ((ret = mbedtls_aes_setkey_enc(&cty, key, keybits)) != 0) { - goto exit; - } + if( aes_padlock_ace ) + ctx->rk = RK = MBEDTLS_PADLOCK_ALIGN16( ctx->buf ); + else +#endif + ctx->rk = RK = ctx->buf; - ctx->nr = cty.nr; + /* Also checks keybits */ + if( ( ret = mbedtls_aes_setkey_enc( &cty, key, keybits ) ) != 0 ) + goto exit; -#if defined(MBEDTLS_AESNI_HAVE_CODE) - if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) { - mbedtls_aesni_inverse_key((unsigned char *) RK, - (const unsigned char *) (cty.buf + cty.rk_offset), ctx->nr); - goto exit; - } -#endif + ctx->nr = cty.nr; -#if defined(MBEDTLS_AESCE_HAVE_CODE) - if (MBEDTLS_AESCE_HAS_SUPPORT()) { - mbedtls_aesce_inverse_key( - (unsigned char *) RK, - (const unsigned char *) (cty.buf + cty.rk_offset), - ctx->nr); - goto exit; - } +#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) + if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) ) + { + mbedtls_aesni_inverse_key( (unsigned char *) ctx->rk, + (const unsigned char *) cty.rk, ctx->nr ); + goto exit; + } #endif -#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY) - SK = cty.buf + cty.rk_offset + cty.nr * 4; - - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; - SK -= 8; - for (int i = ctx->nr - 1; i > 0; i--, SK -= 8) { - for (int j = 0; j < 4; j++, SK++) { - *RK++ = AES_RT0(FSb[MBEDTLS_BYTE_0(*SK)]) ^ - AES_RT1(FSb[MBEDTLS_BYTE_1(*SK)]) ^ - AES_RT2(FSb[MBEDTLS_BYTE_2(*SK)]) ^ - AES_RT3(FSb[MBEDTLS_BYTE_3(*SK)]); - } - } - - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; - *RK++ = *SK++; -#endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */ + SK = cty.rk + cty.nr * 4; + + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + + for( i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8 ) + { + for( j = 0; j < 4; j++, SK++ ) + { + *RK++ = AES_RT0( AESFSb[ MBEDTLS_BYTE_0( *SK ) ] ) ^ + AES_RT1( AESFSb[ MBEDTLS_BYTE_1( *SK ) ] ) ^ + AES_RT2( AESFSb[ MBEDTLS_BYTE_2( *SK ) ] ) ^ + AES_RT3( AESFSb[ MBEDTLS_BYTE_3( *SK ) ] ); + } + } + + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + exit: - mbedtls_aes_free(&cty); + mbedtls_aes_free( &cty ); - return ret; + return( ret ); } -#endif /* !MBEDTLS_AES_SETKEY_DEC_ALT && !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */ +#endif /* !MBEDTLS_AES_SETKEY_DEC_ALT */ #if defined(MBEDTLS_CIPHER_MODE_XTS) -static int mbedtls_aes_xts_decode_keys(const unsigned char *key, - unsigned int keybits, - const unsigned char **key1, - unsigned int *key1bits, - const unsigned char **key2, - unsigned int *key2bits) +static int mbedtls_aes_xts_decode_keys( const unsigned char *key, + unsigned int keybits, + const unsigned char **key1, + unsigned int *key1bits, + const unsigned char **key2, + unsigned int *key2bits ) { - const unsigned int half_keybits = keybits / 2; - const unsigned int half_keybytes = half_keybits / 8; + const unsigned int half_keybits = keybits / 2; + const unsigned int half_keybytes = half_keybits / 8; + + switch( keybits ) + { + case 256: break; + case 512: break; + default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); + } + + *key1bits = half_keybits; + *key2bits = half_keybits; + *key1 = &key[0]; + *key2 = &key[half_keybytes]; + + return 0; +} - switch (keybits) { - case 256: break; - case 512: break; - default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH; - } +int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + const unsigned char *key1, *key2; + unsigned int key1bits, key2bits; - *key1bits = half_keybits; - *key2bits = half_keybits; - *key1 = &key[0]; - *key2 = &key[half_keybytes]; + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( key != NULL ); - return 0; -} + ret = mbedtls_aes_xts_decode_keys( key, keybits, &key1, &key1bits, + &key2, &key2bits ); + if( ret != 0 ) + return( ret ); -int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx, - const unsigned char *key, - unsigned int keybits) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - const unsigned char *key1, *key2; - unsigned int key1bits, key2bits; - - ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits, - &key2, &key2bits); - if (ret != 0) { - return ret; - } - - /* Set the tweak key. Always set tweak key for the encryption mode. */ - ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits); - if (ret != 0) { - return ret; - } - - /* Set crypt key for encryption. */ - return mbedtls_aes_setkey_enc(&ctx->crypt, key1, key1bits); + /* Set the tweak key. Always set tweak key for the encryption mode. */ + ret = mbedtls_aes_setkey_enc( &ctx->tweak, key2, key2bits ); + if( ret != 0 ) + return( ret ); + + /* Set crypt key for encryption. */ + return mbedtls_aes_setkey_enc( &ctx->crypt, key1, key1bits ); } -int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx, - const unsigned char *key, - unsigned int keybits) +int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx, + const unsigned char *key, + unsigned int keybits) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - const unsigned char *key1, *key2; - unsigned int key1bits, key2bits; - - ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits, - &key2, &key2bits); - if (ret != 0) { - return ret; - } - - /* Set the tweak key. Always set tweak key for encryption. */ - ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits); - if (ret != 0) { - return ret; - } - - /* Set crypt key for decryption. */ - return mbedtls_aes_setkey_dec(&ctx->crypt, key1, key1bits); + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + const unsigned char *key1, *key2; + unsigned int key1bits, key2bits; + + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( key != NULL ); + + ret = mbedtls_aes_xts_decode_keys( key, keybits, &key1, &key1bits, + &key2, &key2bits ); + if( ret != 0 ) + return( ret ); + + /* Set the tweak key. Always set tweak key for encryption. */ + ret = mbedtls_aes_setkey_enc( &ctx->tweak, key2, key2bits ); + if( ret != 0 ) + return( ret ); + + /* Set crypt key for decryption. */ + return mbedtls_aes_setkey_dec( &ctx->crypt, key1, key1bits ); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ -#define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \ - do \ - { \ - (X0) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y0)) ^ \ - AES_FT1(MBEDTLS_BYTE_1(Y1)) ^ \ - AES_FT2(MBEDTLS_BYTE_2(Y2)) ^ \ - AES_FT3(MBEDTLS_BYTE_3(Y3)); \ - \ - (X1) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y1)) ^ \ - AES_FT1(MBEDTLS_BYTE_1(Y2)) ^ \ - AES_FT2(MBEDTLS_BYTE_2(Y3)) ^ \ - AES_FT3(MBEDTLS_BYTE_3(Y0)); \ - \ - (X2) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y2)) ^ \ - AES_FT1(MBEDTLS_BYTE_1(Y3)) ^ \ - AES_FT2(MBEDTLS_BYTE_2(Y0)) ^ \ - AES_FT3(MBEDTLS_BYTE_3(Y1)); \ - \ - (X3) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y3)) ^ \ - AES_FT1(MBEDTLS_BYTE_1(Y0)) ^ \ - AES_FT2(MBEDTLS_BYTE_2(Y1)) ^ \ - AES_FT3(MBEDTLS_BYTE_3(Y2)); \ - } while (0) - -#define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \ - do \ - { \ - (X0) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y0)) ^ \ - AES_RT1(MBEDTLS_BYTE_1(Y3)) ^ \ - AES_RT2(MBEDTLS_BYTE_2(Y2)) ^ \ - AES_RT3(MBEDTLS_BYTE_3(Y1)); \ - \ - (X1) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y1)) ^ \ - AES_RT1(MBEDTLS_BYTE_1(Y0)) ^ \ - AES_RT2(MBEDTLS_BYTE_2(Y3)) ^ \ - AES_RT3(MBEDTLS_BYTE_3(Y2)); \ - \ - (X2) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y2)) ^ \ - AES_RT1(MBEDTLS_BYTE_1(Y1)) ^ \ - AES_RT2(MBEDTLS_BYTE_2(Y0)) ^ \ - AES_RT3(MBEDTLS_BYTE_3(Y3)); \ - \ - (X3) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y3)) ^ \ - AES_RT1(MBEDTLS_BYTE_1(Y2)) ^ \ - AES_RT2(MBEDTLS_BYTE_2(Y1)) ^ \ - AES_RT3(MBEDTLS_BYTE_3(Y0)); \ - } while (0) +#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ + do \ + { \ + (X0) = *RK++ ^ AES_FT0( MBEDTLS_BYTE_0( Y0 ) ) ^ \ + AES_FT1( MBEDTLS_BYTE_1( Y1 ) ) ^ \ + AES_FT2( MBEDTLS_BYTE_2( Y2 ) ) ^ \ + AES_FT3( MBEDTLS_BYTE_3( Y3 ) ); \ + \ + (X1) = *RK++ ^ AES_FT0( MBEDTLS_BYTE_0( Y1 ) ) ^ \ + AES_FT1( MBEDTLS_BYTE_1( Y2 ) ) ^ \ + AES_FT2( MBEDTLS_BYTE_2( Y3 ) ) ^ \ + AES_FT3( MBEDTLS_BYTE_3( Y0 ) ); \ + \ + (X2) = *RK++ ^ AES_FT0( MBEDTLS_BYTE_0( Y2 ) ) ^ \ + AES_FT1( MBEDTLS_BYTE_1( Y3 ) ) ^ \ + AES_FT2( MBEDTLS_BYTE_2( Y0 ) ) ^ \ + AES_FT3( MBEDTLS_BYTE_3( Y1 ) ); \ + \ + (X3) = *RK++ ^ AES_FT0( MBEDTLS_BYTE_0( Y3 ) ) ^ \ + AES_FT1( MBEDTLS_BYTE_1( Y0 ) ) ^ \ + AES_FT2( MBEDTLS_BYTE_2( Y1 ) ) ^ \ + AES_FT3( MBEDTLS_BYTE_3( Y2 ) ); \ + } while( 0 ) + +#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ + do \ + { \ + (X0) = *RK++ ^ AES_RT0( MBEDTLS_BYTE_0( Y0 ) ) ^ \ + AES_RT1( MBEDTLS_BYTE_1( Y3 ) ) ^ \ + AES_RT2( MBEDTLS_BYTE_2( Y2 ) ) ^ \ + AES_RT3( MBEDTLS_BYTE_3( Y1 ) ); \ + \ + (X1) = *RK++ ^ AES_RT0( MBEDTLS_BYTE_0( Y1 ) ) ^ \ + AES_RT1( MBEDTLS_BYTE_1( Y0 ) ) ^ \ + AES_RT2( MBEDTLS_BYTE_2( Y3 ) ) ^ \ + AES_RT3( MBEDTLS_BYTE_3( Y2 ) ); \ + \ + (X2) = *RK++ ^ AES_RT0( MBEDTLS_BYTE_0( Y2 ) ) ^ \ + AES_RT1( MBEDTLS_BYTE_1( Y1 ) ) ^ \ + AES_RT2( MBEDTLS_BYTE_2( Y0 ) ) ^ \ + AES_RT3( MBEDTLS_BYTE_3( Y3 ) ); \ + \ + (X3) = *RK++ ^ AES_RT0( MBEDTLS_BYTE_0( Y3 ) ) ^ \ + AES_RT1( MBEDTLS_BYTE_1( Y2 ) ) ^ \ + AES_RT2( MBEDTLS_BYTE_2( Y1 ) ) ^ \ + AES_RT3( MBEDTLS_BYTE_3( Y0 ) ); \ + } while( 0 ) /* - * AES-ECB block encryption - */ +* AES-ECB block encryption +*/ #if !defined(MBEDTLS_AES_ENCRYPT_ALT) -int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16]) +int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ) { - int i; - uint32_t *RK = ctx->buf + ctx->rk_offset; - struct { - uint32_t X[4]; - uint32_t Y[4]; - } t; - - t.X[0] = MBEDTLS_GET_UINT32_LE(input, 0); t.X[0] ^= *RK++; - t.X[1] = MBEDTLS_GET_UINT32_LE(input, 4); t.X[1] ^= *RK++; - t.X[2] = MBEDTLS_GET_UINT32_LE(input, 8); t.X[2] ^= *RK++; - t.X[3] = MBEDTLS_GET_UINT32_LE(input, 12); t.X[3] ^= *RK++; - - for (i = (ctx->nr >> 1) - 1; i > 0; i--) { - AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); - AES_FROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]); - } - - AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); - - t.X[0] = *RK++ ^ \ - ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[0])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[1])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[2])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[3])] << 24); - - t.X[1] = *RK++ ^ \ - ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[1])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[2])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[3])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[0])] << 24); - - t.X[2] = *RK++ ^ \ - ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[2])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[3])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[0])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[1])] << 24); - - t.X[3] = *RK++ ^ \ - ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[3])]) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[0])] << 8) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[1])] << 16) ^ - ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[2])] << 24); - - MBEDTLS_PUT_UINT32_LE(t.X[0], output, 0); - MBEDTLS_PUT_UINT32_LE(t.X[1], output, 4); - MBEDTLS_PUT_UINT32_LE(t.X[2], output, 8); - MBEDTLS_PUT_UINT32_LE(t.X[3], output, 12); - - mbedtls_platform_zeroize(&t, sizeof(t)); - - return 0; + int i; + uint32_t *RK = ctx->rk; + struct + { + uint32_t X[4]; + uint32_t Y[4]; + } t; + + t.X[0] = MBEDTLS_GET_UINT32_LE( input, 0 ); t.X[0] ^= *RK++; + t.X[1] = MBEDTLS_GET_UINT32_LE( input, 4 ); t.X[1] ^= *RK++; + t.X[2] = MBEDTLS_GET_UINT32_LE( input, 8 ); t.X[2] ^= *RK++; + t.X[3] = MBEDTLS_GET_UINT32_LE( input, 12 ); t.X[3] ^= *RK++; + + for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- ) + { + AES_FROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); + AES_FROUND( t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3] ); + } + + AES_FROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); + + t.X[0] = *RK++ ^ \ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( t.Y[0] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( t.Y[1] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( t.Y[2] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( t.Y[3] ) ] << 24 ); + + t.X[1] = *RK++ ^ \ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( t.Y[1] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( t.Y[2] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( t.Y[3] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( t.Y[0] ) ] << 24 ); + + t.X[2] = *RK++ ^ \ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( t.Y[2] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( t.Y[3] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( t.Y[0] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( t.Y[1] ) ] << 24 ); + + t.X[3] = *RK++ ^ \ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_0( t.Y[3] ) ] ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_1( t.Y[0] ) ] << 8 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_2( t.Y[1] ) ] << 16 ) ^ + ( (uint32_t) AESFSb[ MBEDTLS_BYTE_3( t.Y[2] ) ] << 24 ); + + MBEDTLS_PUT_UINT32_LE( t.X[0], output, 0 ); + MBEDTLS_PUT_UINT32_LE( t.X[1], output, 4 ); + MBEDTLS_PUT_UINT32_LE( t.X[2], output, 8 ); + MBEDTLS_PUT_UINT32_LE( t.X[3], output, 12 ); + + mbedtls_platform_zeroize( &t, sizeof( t ) ); + + return( 0 ); } #endif /* !MBEDTLS_AES_ENCRYPT_ALT */ /* - * AES-ECB block decryption - */ -#if !defined(MBEDTLS_AES_DECRYPT_ALT) && !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx, - const unsigned char input[16], - unsigned char output[16]) +* AES-ECB block decryption +*/ +#if !defined(MBEDTLS_AES_DECRYPT_ALT) +int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx, + const unsigned char input[16], + unsigned char output[16] ) { - int i; - uint32_t *RK = ctx->buf + ctx->rk_offset; - struct { - uint32_t X[4]; - uint32_t Y[4]; - } t; - - t.X[0] = MBEDTLS_GET_UINT32_LE(input, 0); t.X[0] ^= *RK++; - t.X[1] = MBEDTLS_GET_UINT32_LE(input, 4); t.X[1] ^= *RK++; - t.X[2] = MBEDTLS_GET_UINT32_LE(input, 8); t.X[2] ^= *RK++; - t.X[3] = MBEDTLS_GET_UINT32_LE(input, 12); t.X[3] ^= *RK++; - - for (i = (ctx->nr >> 1) - 1; i > 0; i--) { - AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); - AES_RROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]); - } - - AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]); - - t.X[0] = *RK++ ^ \ - ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[0])]) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[3])] << 8) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[2])] << 16) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[1])] << 24); - - t.X[1] = *RK++ ^ \ - ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[1])]) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[0])] << 8) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[3])] << 16) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[2])] << 24); - - t.X[2] = *RK++ ^ \ - ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[2])]) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[1])] << 8) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[0])] << 16) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[3])] << 24); - - t.X[3] = *RK++ ^ \ - ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[3])]) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[2])] << 8) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[1])] << 16) ^ - ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[0])] << 24); - - MBEDTLS_PUT_UINT32_LE(t.X[0], output, 0); - MBEDTLS_PUT_UINT32_LE(t.X[1], output, 4); - MBEDTLS_PUT_UINT32_LE(t.X[2], output, 8); - MBEDTLS_PUT_UINT32_LE(t.X[3], output, 12); - - mbedtls_platform_zeroize(&t, sizeof(t)); - - return 0; -} -#endif /* !MBEDTLS_AES_DECRYPT_ALT && !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */ - -/* VIA Padlock and our intrinsics-based implementation of AESNI require - * the round keys to be aligned on a 16-byte boundary. We take care of this - * before creating them, but the AES context may have moved (this can happen - * if the library is called from a language with managed memory), and in later - * calls it might have a different alignment with respect to 16-byte memory. - * So we may need to realign. - */ -MBEDTLS_MAYBE_UNUSED static void aes_maybe_realign(mbedtls_aes_context *ctx) -{ - unsigned new_offset = mbedtls_aes_rk_offset(ctx->buf); - if (new_offset != ctx->rk_offset) { - memmove(ctx->buf + new_offset, // new address - ctx->buf + ctx->rk_offset, // current address - (ctx->nr + 1) * 16); // number of round keys * bytes per rk - ctx->rk_offset = new_offset; - } + int i; + uint32_t *RK = ctx->rk; + struct + { + uint32_t X[4]; + uint32_t Y[4]; + } t; + + t.X[0] = MBEDTLS_GET_UINT32_LE( input, 0 ); t.X[0] ^= *RK++; + t.X[1] = MBEDTLS_GET_UINT32_LE( input, 4 ); t.X[1] ^= *RK++; + t.X[2] = MBEDTLS_GET_UINT32_LE( input, 8 ); t.X[2] ^= *RK++; + t.X[3] = MBEDTLS_GET_UINT32_LE( input, 12 ); t.X[3] ^= *RK++; + + for( i = ( ctx->nr >> 1 ) - 1; i > 0; i-- ) + { + AES_RROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); + AES_RROUND( t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3] ); + } + + AES_RROUND( t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3] ); + + t.X[0] = *RK++ ^ \ + ( (uint32_t) RSb[ MBEDTLS_BYTE_0( t.Y[0] ) ] ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_1( t.Y[3] ) ] << 8 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_2( t.Y[2] ) ] << 16 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_3( t.Y[1] ) ] << 24 ); + + t.X[1] = *RK++ ^ \ + ( (uint32_t) RSb[ MBEDTLS_BYTE_0( t.Y[1] ) ] ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_1( t.Y[0] ) ] << 8 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_2( t.Y[3] ) ] << 16 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_3( t.Y[2] ) ] << 24 ); + + t.X[2] = *RK++ ^ \ + ( (uint32_t) RSb[ MBEDTLS_BYTE_0( t.Y[2] ) ] ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_1( t.Y[1] ) ] << 8 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_2( t.Y[0] ) ] << 16 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_3( t.Y[3] ) ] << 24 ); + + t.X[3] = *RK++ ^ \ + ( (uint32_t) RSb[ MBEDTLS_BYTE_0( t.Y[3] ) ] ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_1( t.Y[2] ) ] << 8 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_2( t.Y[1] ) ] << 16 ) ^ + ( (uint32_t) RSb[ MBEDTLS_BYTE_3( t.Y[0] ) ] << 24 ); + + MBEDTLS_PUT_UINT32_LE( t.X[0], output, 0 ); + MBEDTLS_PUT_UINT32_LE( t.X[1], output, 4 ); + MBEDTLS_PUT_UINT32_LE( t.X[2], output, 8 ); + MBEDTLS_PUT_UINT32_LE( t.X[3], output, 12 ); + + mbedtls_platform_zeroize( &t, sizeof( t ) ); + + return( 0 ); } +#endif /* !MBEDTLS_AES_DECRYPT_ALT */ /* - * AES-ECB block encryption/decryption - */ -int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16]) +* AES-ECB block encryption/decryption +*/ +int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx, + int mode, + const unsigned char input[16], + unsigned char output[16] ) { - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - -#if defined(MAY_NEED_TO_ALIGN) - aes_maybe_realign(ctx); + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( input != NULL ); + AES_VALIDATE_RET( output != NULL ); + AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || + mode == MBEDTLS_AES_DECRYPT ); + +#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) + if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) ) + return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) ); #endif -#if defined(MBEDTLS_AESNI_HAVE_CODE) - if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) { - return mbedtls_aesni_crypt_ecb(ctx, mode, input, output); - } -#endif +#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) + if( aes_padlock_ace > 0) + { + if( mbedtls_padlock_xcryptecb( ctx, mode, input, output ) == 0 ) + return( 0 ); -#if defined(MBEDTLS_AESCE_HAVE_CODE) - if (MBEDTLS_AESCE_HAS_SUPPORT()) { - return mbedtls_aesce_crypt_ecb(ctx, mode, input, output); - } + // If padlock data misaligned, we just fall back to + // unaccelerated mode + // + } #endif -#if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE) - if (aes_padlock_ace > 0) { - return mbedtls_padlock_xcryptecb(ctx, mode, input, output); - } -#endif - -#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY) -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) - if (mode == MBEDTLS_AES_DECRYPT) { - return mbedtls_internal_aes_decrypt(ctx, input, output); - } else -#endif - { - return mbedtls_internal_aes_encrypt(ctx, input, output); - } -#endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */ + if( mode == MBEDTLS_AES_ENCRYPT ) + return( mbedtls_internal_aes_encrypt( ctx, input, output ) ); + else + return( mbedtls_internal_aes_decrypt( ctx, input, output ) ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) - /* - * AES-CBC buffer encryption/decryption - */ -int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) +* AES-CBC buffer encryption/decryption +*/ +int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - unsigned char temp[16]; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - /* Nothing to do if length is zero. */ - if (length == 0) { - return 0; - } - - if (length % 16) { - return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; - } - -#if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE) - if (aes_padlock_ace > 0) { - if (mbedtls_padlock_xcryptcbc(ctx, mode, length, iv, input, output) == 0) { - return 0; - } - - // If padlock data misaligned, we just fall back to - // unaccelerated mode - // - } + int i; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + unsigned char temp[16]; + + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || + mode == MBEDTLS_AES_DECRYPT ); + AES_VALIDATE_RET( iv != NULL ); + AES_VALIDATE_RET( input != NULL ); + AES_VALIDATE_RET( output != NULL ); + + if( length % 16 ) + return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); + +#if defined(MBEDTLS_PADLOCK_C) && defined(MBEDTLS_HAVE_X86) + if( aes_padlock_ace > 0 ) + { + if( mbedtls_padlock_xcryptcbc( ctx, mode, length, iv, input, output ) == 0 ) + return( 0 ); + + // If padlock data misaligned, we just fall back to + // unaccelerated mode + // + } #endif - const unsigned char *ivp = iv; - - if (mode == MBEDTLS_AES_DECRYPT) { - while (length > 0) { - memcpy(temp, input, 16); - ret = mbedtls_aes_crypt_ecb(ctx, mode, input, output); - if (ret != 0) { - goto exit; - } - /* Avoid using the NEON implementation of mbedtls_xor. Because of the dependency on - * the result for the next block in CBC, and the cost of transferring that data from - * NEON registers, NEON is slower on aarch64. */ - mbedtls_xor_no_simd(output, output, iv, 16); - - memcpy(iv, temp, 16); - - input += 16; - output += 16; - length -= 16; - } - } else { - while (length > 0) { - mbedtls_xor_no_simd(output, input, ivp, 16); - - ret = mbedtls_aes_crypt_ecb(ctx, mode, output, output); - if (ret != 0) { - goto exit; - } - ivp = output; - - input += 16; - output += 16; - length -= 16; - } - memcpy(iv, ivp, 16); - } - ret = 0; + if( mode == MBEDTLS_AES_DECRYPT ) + { + while( length > 0 ) + { + memcpy( temp, input, 16 ); + ret = mbedtls_aes_crypt_ecb( ctx, mode, input, output ); + if( ret != 0 ) + goto exit; + + for( i = 0; i < 16; i++ ) + output[i] = (unsigned char)( output[i] ^ iv[i] ); + + memcpy( iv, temp, 16 ); + + input += 16; + output += 16; + length -= 16; + } + } + else + { + while( length > 0 ) + { + for( i = 0; i < 16; i++ ) + output[i] = (unsigned char)( input[i] ^ iv[i] ); + + ret = mbedtls_aes_crypt_ecb( ctx, mode, output, output ); + if( ret != 0 ) + goto exit; + memcpy( iv, output, 16 ); + + input += 16; + output += 16; + length -= 16; + } + } + ret = 0; exit: - return ret; + return( ret ); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -1151,332 +1084,348 @@ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, typedef unsigned char mbedtls_be128[16]; /* - * GF(2^128) multiplication function - * - * This function multiplies a field element by x in the polynomial field - * representation. It uses 64-bit word operations to gain speed but compensates - * for machine endianness and hence works correctly on both big and little - * endian machines. - */ -#if defined(MBEDTLS_AESCE_C) || defined(MBEDTLS_AESNI_C) -MBEDTLS_OPTIMIZE_FOR_PERFORMANCE -#endif -inline void mbedtls_gf128mul_x_ble(unsigned char r[16], - const unsigned char x[16]) +* GF(2^128) multiplication function +* +* This function multiplies a field element by x in the polynomial field +* representation. It uses 64-bit word operations to gain speed but compensates +* for machine endianess and hence works correctly on both big and little +* endian machines. +*/ +static void mbedtls_gf128mul_x_ble( unsigned char r[16], + const unsigned char x[16] ) { - uint64_t a, b, ra, rb; + uint64_t a, b, ra, rb; - a = MBEDTLS_GET_UINT64_LE(x, 0); - b = MBEDTLS_GET_UINT64_LE(x, 8); + a = MBEDTLS_GET_UINT64_LE( x, 0 ); + b = MBEDTLS_GET_UINT64_LE( x, 8 ); - ra = (a << 1) ^ 0x0087 >> (8 - ((b >> 63) << 3)); - rb = (a >> 63) | (b << 1); + ra = ( a << 1 ) ^ 0x0087 >> ( 8 - ( ( b >> 63 ) << 3 ) ); + rb = ( a >> 63 ) | ( b << 1 ); - MBEDTLS_PUT_UINT64_LE(ra, r, 0); - MBEDTLS_PUT_UINT64_LE(rb, r, 8); + MBEDTLS_PUT_UINT64_LE( ra, r, 0 ); + MBEDTLS_PUT_UINT64_LE( rb, r, 8 ); } /* - * AES-XTS buffer encryption/decryption - * - * Use of MBEDTLS_OPTIMIZE_FOR_PERFORMANCE here and for mbedtls_gf128mul_x_ble() - * is a 3x performance improvement for gcc -Os, if we have hardware AES support. - */ -#if defined(MBEDTLS_AESCE_C) || defined(MBEDTLS_AESNI_C) -MBEDTLS_OPTIMIZE_FOR_PERFORMANCE -#endif -int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx, - int mode, - size_t length, - const unsigned char data_unit[16], - const unsigned char *input, - unsigned char *output) +* AES-XTS buffer encryption/decryption +*/ +int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx, + int mode, + size_t length, + const unsigned char data_unit[16], + const unsigned char *input, + unsigned char *output ) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t blocks = length / 16; - size_t leftover = length % 16; - unsigned char tweak[16]; - unsigned char prev_tweak[16]; - unsigned char tmp[16]; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - /* Data units must be at least 16 bytes long. */ - if (length < 16) { - return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; - } - - /* NIST SP 800-38E disallows data units larger than 2**20 blocks. */ - if (length > (1 << 20) * 16) { - return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; - } - - /* Compute the tweak. */ - ret = mbedtls_aes_crypt_ecb(&ctx->tweak, MBEDTLS_AES_ENCRYPT, - data_unit, tweak); - if (ret != 0) { - return ret; - } - - while (blocks--) { - if (MBEDTLS_UNLIKELY(leftover && (mode == MBEDTLS_AES_DECRYPT) && blocks == 0)) { - /* We are on the last block in a decrypt operation that has - * leftover bytes, so we need to use the next tweak for this block, - * and this tweak for the leftover bytes. Save the current tweak for - * the leftovers and then update the current tweak for use on this, - * the last full block. */ - memcpy(prev_tweak, tweak, sizeof(tweak)); - mbedtls_gf128mul_x_ble(tweak, tweak); - } - - mbedtls_xor(tmp, input, tweak, 16); - - ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp); - if (ret != 0) { - return ret; - } - - mbedtls_xor(output, tmp, tweak, 16); - - /* Update the tweak for the next block. */ - mbedtls_gf128mul_x_ble(tweak, tweak); - - output += 16; - input += 16; - } - - if (leftover) { - /* If we are on the leftover bytes in a decrypt operation, we need to - * use the previous tweak for these bytes (as saved in prev_tweak). */ - unsigned char *t = mode == MBEDTLS_AES_DECRYPT ? prev_tweak : tweak; - - /* We are now on the final part of the data unit, which doesn't divide - * evenly by 16. It's time for ciphertext stealing. */ - size_t i; - unsigned char *prev_output = output - 16; - - /* Copy ciphertext bytes from the previous block to our output for each - * byte of ciphertext we won't steal. */ - for (i = 0; i < leftover; i++) { - output[i] = prev_output[i]; - } - - /* Copy the remainder of the input for this final round. */ - mbedtls_xor(tmp, input, t, leftover); - - /* Copy ciphertext bytes from the previous block for input in this - * round. */ - mbedtls_xor(tmp + i, prev_output + i, t + i, 16 - i); - - ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp); - if (ret != 0) { - return ret; - } - - /* Write the result back to the previous block, overriding the previous - * output we copied. */ - mbedtls_xor(prev_output, tmp, t, 16); - } - - return 0; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t blocks = length / 16; + size_t leftover = length % 16; + unsigned char tweak[16]; + unsigned char prev_tweak[16]; + unsigned char tmp[16]; + + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || + mode == MBEDTLS_AES_DECRYPT ); + AES_VALIDATE_RET( data_unit != NULL ); + AES_VALIDATE_RET( input != NULL ); + AES_VALIDATE_RET( output != NULL ); + + /* Data units must be at least 16 bytes long. */ + if( length < 16 ) + return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; + + /* NIST SP 800-38E disallows data units larger than 2**20 blocks. */ + if( length > ( 1 << 20 ) * 16 ) + return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH; + + /* Compute the tweak. */ + ret = mbedtls_aes_crypt_ecb( &ctx->tweak, MBEDTLS_AES_ENCRYPT, + data_unit, tweak ); + if( ret != 0 ) + return( ret ); + + while( blocks-- ) + { + size_t i; + + if( leftover && ( mode == MBEDTLS_AES_DECRYPT ) && blocks == 0 ) + { + /* We are on the last block in a decrypt operation that has + * leftover bytes, so we need to use the next tweak for this block, + * and this tweak for the lefover bytes. Save the current tweak for + * the leftovers and then update the current tweak for use on this, + * the last full block. */ + memcpy( prev_tweak, tweak, sizeof( tweak ) ); + mbedtls_gf128mul_x_ble( tweak, tweak ); + } + + for( i = 0; i < 16; i++ ) + tmp[i] = input[i] ^ tweak[i]; + + ret = mbedtls_aes_crypt_ecb( &ctx->crypt, mode, tmp, tmp ); + if( ret != 0 ) + return( ret ); + + for( i = 0; i < 16; i++ ) + output[i] = tmp[i] ^ tweak[i]; + + /* Update the tweak for the next block. */ + mbedtls_gf128mul_x_ble( tweak, tweak ); + + output += 16; + input += 16; + } + + if( leftover ) + { + /* If we are on the leftover bytes in a decrypt operation, we need to + * use the previous tweak for these bytes (as saved in prev_tweak). */ + unsigned char *t = mode == MBEDTLS_AES_DECRYPT ? prev_tweak : tweak; + + /* We are now on the final part of the data unit, which doesn't divide + * evenly by 16. It's time for ciphertext stealing. */ + size_t i; + unsigned char *prev_output = output - 16; + + /* Copy ciphertext bytes from the previous block to our output for each + * byte of cyphertext we won't steal. At the same time, copy the + * remainder of the input for this final round (since the loop bounds + * are the same). */ + for( i = 0; i < leftover; i++ ) + { + output[i] = prev_output[i]; + tmp[i] = input[i] ^ t[i]; + } + + /* Copy ciphertext bytes from the previous block for input in this + * round. */ + for( ; i < 16; i++ ) + tmp[i] = prev_output[i] ^ t[i]; + + ret = mbedtls_aes_crypt_ecb( &ctx->crypt, mode, tmp, tmp ); + if( ret != 0 ) + return ret; + + /* Write the result back to the previous block, overriding the previous + * output we copied. */ + for( i = 0; i < 16; i++ ) + prev_output[i] = tmp[i] ^ t[i]; + } + + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ #if defined(MBEDTLS_CIPHER_MODE_CFB) /* - * AES-CFB128 buffer encryption/decryption - */ -int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx, - int mode, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) +* AES-CFB128 buffer encryption/decryption +*/ +int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) { - int c; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t n; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - n = *iv_off; - - if (n > 15) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - if (mode == MBEDTLS_AES_DECRYPT) { - while (length--) { - if (n == 0) { - ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); - if (ret != 0) { - goto exit; - } - } - - c = *input++; - *output++ = (unsigned char) (c ^ iv[n]); - iv[n] = (unsigned char) c; - - n = (n + 1) & 0x0F; - } - } else { - while (length--) { - if (n == 0) { - ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); - if (ret != 0) { - goto exit; - } - } - - iv[n] = *output++ = (unsigned char) (iv[n] ^ *input++); - - n = (n + 1) & 0x0F; - } - } - - *iv_off = n; - ret = 0; + int c; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t n; + + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || + mode == MBEDTLS_AES_DECRYPT ); + AES_VALIDATE_RET( iv_off != NULL ); + AES_VALIDATE_RET( iv != NULL ); + AES_VALIDATE_RET( input != NULL ); + AES_VALIDATE_RET( output != NULL ); + + n = *iv_off; + + if( n > 15 ) + return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + + if( mode == MBEDTLS_AES_DECRYPT ) + { + while( length-- ) + { + if( n == 0 ) + { + ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); + if( ret != 0 ) + goto exit; + } + + c = *input++; + *output++ = (unsigned char)( c ^ iv[n] ); + iv[n] = (unsigned char) c; + + n = ( n + 1 ) & 0x0F; + } + } + else + { + while( length-- ) + { + if( n == 0 ) + { + ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); + if( ret != 0 ) + goto exit; + } + + iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); + + n = ( n + 1 ) & 0x0F; + } + } + + *iv_off = n; + ret = 0; exit: - return ret; + return( ret ); } /* - * AES-CFB8 buffer encryption/decryption - */ -int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) +* AES-CFB8 buffer encryption/decryption +*/ +int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - unsigned char c; - unsigned char ov[17]; - - if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - while (length--) { - memcpy(ov, iv, 16); - ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); - if (ret != 0) { - goto exit; - } - - if (mode == MBEDTLS_AES_DECRYPT) { - ov[16] = *input; - } - - c = *output++ = (unsigned char) (iv[0] ^ *input++); - - if (mode == MBEDTLS_AES_ENCRYPT) { - ov[16] = c; - } - - memcpy(iv, ov + 1, 16); - } - ret = 0; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + unsigned char c; + unsigned char ov[17]; + + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT || + mode == MBEDTLS_AES_DECRYPT ); + AES_VALIDATE_RET( iv != NULL ); + AES_VALIDATE_RET( input != NULL ); + AES_VALIDATE_RET( output != NULL ); + while( length-- ) + { + memcpy( ov, iv, 16 ); + ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); + if( ret != 0 ) + goto exit; + + if( mode == MBEDTLS_AES_DECRYPT ) + ov[16] = *input; + + c = *output++ = (unsigned char)( iv[0] ^ *input++ ); + + if( mode == MBEDTLS_AES_ENCRYPT ) + ov[16] = c; + + memcpy( iv, ov + 1, 16 ); + } + ret = 0; exit: - return ret; + return( ret ); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) /* - * AES-OFB (Output Feedback Mode) buffer encryption/decryption - */ -int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx, - size_t length, - size_t *iv_off, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output) +* AES-OFB (Output Feedback Mode) buffer encryption/decryption +*/ +int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) { - int ret = 0; - size_t n; + int ret = 0; + size_t n; - n = *iv_off; + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( iv_off != NULL ); + AES_VALIDATE_RET( iv != NULL ); + AES_VALIDATE_RET( input != NULL ); + AES_VALIDATE_RET( output != NULL ); - if (n > 15) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } + n = *iv_off; - while (length--) { - if (n == 0) { - ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv); - if (ret != 0) { - goto exit; - } - } - *output++ = *input++ ^ iv[n]; + if( n > 15 ) + return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); - n = (n + 1) & 0x0F; - } + while( length-- ) + { + if( n == 0 ) + { + ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); + if( ret != 0 ) + goto exit; + } + *output++ = *input++ ^ iv[n]; - *iv_off = n; + n = ( n + 1 ) & 0x0F; + } + + *iv_off = n; exit: - return ret; + return( ret ); } #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) /* - * AES-CTR buffer encryption/decryption - */ -int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx, - size_t length, - size_t *nc_off, - unsigned char nonce_counter[16], - unsigned char stream_block[16], - const unsigned char *input, - unsigned char *output) +* AES-CTR buffer encryption/decryption +*/ +int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char *input, + unsigned char *output ) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - - size_t offset = *nc_off; - - if (offset > 0x0F) { - return MBEDTLS_ERR_AES_BAD_INPUT_DATA; - } - - for (size_t i = 0; i < length;) { - size_t n = 16; - if (offset == 0) { - ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block); - if (ret != 0) { - goto exit; - } - mbedtls_ctr_increment_counter(nonce_counter); - } else { - n -= offset; - } - - if (n > (length - i)) { - n = (length - i); - } - mbedtls_xor(&output[i], &input[i], &stream_block[offset], n); - // offset might be non-zero for the last block, but in that case, we don't use it again - offset = 0; - i += n; - } - - // capture offset for future resumption - *nc_off = (*nc_off + length) % 16; - - ret = 0; + int c, i; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t n; + + AES_VALIDATE_RET( ctx != NULL ); + AES_VALIDATE_RET( nc_off != NULL ); + AES_VALIDATE_RET( nonce_counter != NULL ); + AES_VALIDATE_RET( stream_block != NULL ); + AES_VALIDATE_RET( input != NULL ); + AES_VALIDATE_RET( output != NULL ); + + n = *nc_off; + + if ( n > 0x0F ) + return( MBEDTLS_ERR_AES_BAD_INPUT_DATA ); + + while( length-- ) + { + if( n == 0 ) { + ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block ); + if( ret != 0 ) + goto exit; + + for( i = 16; i > 0; i-- ) + if( ++nonce_counter[i - 1] != 0 ) + break; + } + c = *input++; + *output++ = (unsigned char)( c ^ stream_block[n] ); + + n = ( n + 1 ) & 0x0F; + } + + *nc_off = n; + ret = 0; exit: - return ret; + return( ret ); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ @@ -1484,808 +1433,737 @@ int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx, #if defined(MBEDTLS_SELF_TEST) /* - * AES test vectors from: - * - * http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip - */ -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -static const unsigned char aes_test_ecb_dec[][16] = -{ - { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, - 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, - 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 }, - { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, - 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE } -#endif +* AES test vectors from: +* +* http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip +*/ +static const unsigned char aes_test_ecb_dec[3][16] = + { + { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, + 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 }, + { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, + 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 }, + { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, + 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE } }; -#endif -static const unsigned char aes_test_ecb_enc[][16] = -{ - { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, - 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, - 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 }, - { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, - 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 } -#endif +static const unsigned char aes_test_ecb_enc[3][16] = + { + { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, + 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F }, + { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, + 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 }, + { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, + 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 } }; #if defined(MBEDTLS_CIPHER_MODE_CBC) -static const unsigned char aes_test_cbc_dec[][16] = -{ - { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73, - 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75, - 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B }, - { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75, - 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 } -#endif +static const unsigned char aes_test_cbc_dec[3][16] = + { + { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73, + 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 }, + { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75, + 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B }, + { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75, + 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 } }; -static const unsigned char aes_test_cbc_enc[][16] = -{ - { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84, - 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB, - 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 }, - { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5, - 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 } -#endif +static const unsigned char aes_test_cbc_enc[3][16] = + { + { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84, + 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D }, + { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB, + 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 }, + { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5, + 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 } }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) /* - * AES-CFB128 test vectors from: - * - * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf - */ -static const unsigned char aes_test_cfb128_key[][32] = -{ - { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, - 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, - 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, - 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }, - { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, - 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, - 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, - 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } -#endif +* AES-CFB128 test vectors from: +* +* http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf +*/ +static const unsigned char aes_test_cfb128_key[3][32] = + { + { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, + 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, + { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, + 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, + 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }, + { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, + 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, + 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, + 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } }; static const unsigned char aes_test_cfb128_iv[16] = -{ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F + { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; static const unsigned char aes_test_cfb128_pt[64] = -{ - 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, - 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, - 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, - 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, - 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, - 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, - 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, - 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 + { + 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, + 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, + 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, + 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, + 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, + 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, + 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, + 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 }; -static const unsigned char aes_test_cfb128_ct[][64] = -{ - { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, - 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, - 0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F, - 0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B, - 0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40, - 0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF, - 0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E, - 0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, - 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, - 0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21, - 0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A, - 0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1, - 0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9, - 0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0, - 0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF }, - { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, - 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, - 0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8, - 0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B, - 0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92, - 0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9, - 0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8, - 0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 } -#endif +static const unsigned char aes_test_cfb128_ct[3][64] = + { + { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, + 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, + 0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F, + 0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B, + 0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40, + 0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF, + 0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E, + 0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 }, + { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, + 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, + 0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21, + 0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A, + 0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1, + 0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9, + 0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0, + 0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF }, + { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, + 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, + 0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8, + 0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B, + 0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92, + 0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9, + 0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8, + 0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 } }; #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) /* - * AES-OFB test vectors from: - * - * https://csrc.nist.gov/publications/detail/sp/800-38a/final - */ -static const unsigned char aes_test_ofb_key[][32] = -{ - { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, - 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, - 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, - 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }, - { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, - 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, - 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, - 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } -#endif +* AES-OFB test vectors from: +* +* https://csrc.nist.gov/publications/detail/sp/800-38a/final +*/ +static const unsigned char aes_test_ofb_key[3][32] = + { + { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, + 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }, + { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, + 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, + 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B }, + { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, + 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, + 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, + 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } }; static const unsigned char aes_test_ofb_iv[16] = -{ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F + { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; static const unsigned char aes_test_ofb_pt[64] = -{ - 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, - 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, - 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, - 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, - 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, - 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, - 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, - 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 + { + 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, + 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, + 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, + 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, + 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, + 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, + 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, + 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 }; -static const unsigned char aes_test_ofb_ct[][64] = -{ - { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, - 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, - 0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, 0x8f, 0x03, - 0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25, - 0x97, 0x40, 0x05, 0x1e, 0x9c, 0x5f, 0xec, 0xf6, - 0x43, 0x44, 0xf7, 0xa8, 0x22, 0x60, 0xed, 0xcc, - 0x30, 0x4c, 0x65, 0x28, 0xf6, 0x59, 0xc7, 0x78, - 0x66, 0xa5, 0x10, 0xd9, 0xc1, 0xd6, 0xae, 0x5e }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) - { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, - 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, - 0xfc, 0xc2, 0x8b, 0x8d, 0x4c, 0x63, 0x83, 0x7c, - 0x09, 0xe8, 0x17, 0x00, 0xc1, 0x10, 0x04, 0x01, - 0x8d, 0x9a, 0x9a, 0xea, 0xc0, 0xf6, 0x59, 0x6f, - 0x55, 0x9c, 0x6d, 0x4d, 0xaf, 0x59, 0xa5, 0xf2, - 0x6d, 0x9f, 0x20, 0x08, 0x57, 0xca, 0x6c, 0x3e, - 0x9c, 0xac, 0x52, 0x4b, 0xd9, 0xac, 0xc9, 0x2a }, - { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, - 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, - 0x4f, 0xeb, 0xdc, 0x67, 0x40, 0xd2, 0x0b, 0x3a, - 0xc8, 0x8f, 0x6a, 0xd8, 0x2a, 0x4f, 0xb0, 0x8d, - 0x71, 0xab, 0x47, 0xa0, 0x86, 0xe8, 0x6e, 0xed, - 0xf3, 0x9d, 0x1c, 0x5b, 0xba, 0x97, 0xc4, 0x08, - 0x01, 0x26, 0x14, 0x1d, 0x67, 0xf3, 0x7b, 0xe8, - 0x53, 0x8f, 0x5a, 0x8b, 0xe7, 0x40, 0xe4, 0x84 } -#endif +static const unsigned char aes_test_ofb_ct[3][64] = + { + { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20, + 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A, + 0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, 0x8f, 0x03, + 0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25, + 0x97, 0x40, 0x05, 0x1e, 0x9c, 0x5f, 0xec, 0xf6, + 0x43, 0x44, 0xf7, 0xa8, 0x22, 0x60, 0xed, 0xcc, + 0x30, 0x4c, 0x65, 0x28, 0xf6, 0x59, 0xc7, 0x78, + 0x66, 0xa5, 0x10, 0xd9, 0xc1, 0xd6, 0xae, 0x5e }, + { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB, + 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74, + 0xfc, 0xc2, 0x8b, 0x8d, 0x4c, 0x63, 0x83, 0x7c, + 0x09, 0xe8, 0x17, 0x00, 0xc1, 0x10, 0x04, 0x01, + 0x8d, 0x9a, 0x9a, 0xea, 0xc0, 0xf6, 0x59, 0x6f, + 0x55, 0x9c, 0x6d, 0x4d, 0xaf, 0x59, 0xa5, 0xf2, + 0x6d, 0x9f, 0x20, 0x08, 0x57, 0xca, 0x6c, 0x3e, + 0x9c, 0xac, 0x52, 0x4b, 0xd9, 0xac, 0xc9, 0x2a }, + { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B, + 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60, + 0x4f, 0xeb, 0xdc, 0x67, 0x40, 0xd2, 0x0b, 0x3a, + 0xc8, 0x8f, 0x6a, 0xd8, 0x2a, 0x4f, 0xb0, 0x8d, + 0x71, 0xab, 0x47, 0xa0, 0x86, 0xe8, 0x6e, 0xed, + 0xf3, 0x9d, 0x1c, 0x5b, 0xba, 0x97, 0xc4, 0x08, + 0x01, 0x26, 0x14, 0x1d, 0x67, 0xf3, 0x7b, 0xe8, + 0x53, 0x8f, 0x5a, 0x8b, 0xe7, 0x40, 0xe4, 0x84 } }; #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) /* - * AES-CTR test vectors from: - * - * http://www.faqs.org/rfcs/rfc3686.html - */ - -static const unsigned char aes_test_ctr_key[][16] = -{ - { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC, - 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E }, - { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, - 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 }, - { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8, - 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC } +* AES-CTR test vectors from: +* +* http://www.faqs.org/rfcs/rfc3686.html +*/ + +static const unsigned char aes_test_ctr_key[3][16] = + { + { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC, + 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E }, + { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, + 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 }, + { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8, + 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC } }; -static const unsigned char aes_test_ctr_nonce_counter[][16] = -{ - { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, - { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, - 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 }, - { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, - 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 } +static const unsigned char aes_test_ctr_nonce_counter[3][16] = + { + { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, + { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, + 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 }, + { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, + 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 } }; -static const unsigned char aes_test_ctr_pt[][48] = -{ - { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, - 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 }, - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }, - - { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23 } +static const unsigned char aes_test_ctr_pt[3][48] = + { + { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, + 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 }, + + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }, + + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23 } }; -static const unsigned char aes_test_ctr_ct[][48] = -{ - { 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79, - 0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 }, - { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9, - 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88, - 0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8, - 0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 }, - { 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9, - 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7, - 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36, - 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53, - 0x25, 0xB2, 0x07, 0x2F } +static const unsigned char aes_test_ctr_ct[3][48] = + { + { 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79, + 0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 }, + { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9, + 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88, + 0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8, + 0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 }, + { 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9, + 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7, + 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36, + 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53, + 0x25, 0xB2, 0x07, 0x2F } }; static const int aes_test_ctr_len[3] = -{ 16, 32, 36 }; + { 16, 32, 36 }; #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) /* - * AES-XTS test vectors from: - * - * IEEE P1619/D16 Annex B - * https://web.archive.org/web/20150629024421/http://grouper.ieee.org/groups/1619/email/pdf00086.pdf - * (Archived from original at http://grouper.ieee.org/groups/1619/email/pdf00086.pdf) - */ +* AES-XTS test vectors from: +* +* IEEE P1619/D16 Annex B +* https://web.archive.org/web/20150629024421/http://grouper.ieee.org/groups/1619/email/pdf00086.pdf +* (Archived from original at http://grouper.ieee.org/groups/1619/email/pdf00086.pdf) +*/ static const unsigned char aes_test_xts_key[][32] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, - 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }, - { 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, - 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, - 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }, + { + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }, + { 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, + 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }, }; static const unsigned char aes_test_xts_pt32[][32] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }, - { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, - 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }, + { + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }, + { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }, }; static const unsigned char aes_test_xts_ct32[][32] = -{ - { 0x91, 0x7c, 0xf6, 0x9e, 0xbd, 0x68, 0xb2, 0xec, - 0x9b, 0x9f, 0xe9, 0xa3, 0xea, 0xdd, 0xa6, 0x92, - 0xcd, 0x43, 0xd2, 0xf5, 0x95, 0x98, 0xed, 0x85, - 0x8c, 0x02, 0xc2, 0x65, 0x2f, 0xbf, 0x92, 0x2e }, - { 0xc4, 0x54, 0x18, 0x5e, 0x6a, 0x16, 0x93, 0x6e, - 0x39, 0x33, 0x40, 0x38, 0xac, 0xef, 0x83, 0x8b, - 0xfb, 0x18, 0x6f, 0xff, 0x74, 0x80, 0xad, 0xc4, - 0x28, 0x93, 0x82, 0xec, 0xd6, 0xd3, 0x94, 0xf0 }, - { 0xaf, 0x85, 0x33, 0x6b, 0x59, 0x7a, 0xfc, 0x1a, - 0x90, 0x0b, 0x2e, 0xb2, 0x1e, 0xc9, 0x49, 0xd2, - 0x92, 0xdf, 0x4c, 0x04, 0x7e, 0x0b, 0x21, 0x53, - 0x21, 0x86, 0xa5, 0x97, 0x1a, 0x22, 0x7a, 0x89 }, + { + { 0x91, 0x7c, 0xf6, 0x9e, 0xbd, 0x68, 0xb2, 0xec, + 0x9b, 0x9f, 0xe9, 0xa3, 0xea, 0xdd, 0xa6, 0x92, + 0xcd, 0x43, 0xd2, 0xf5, 0x95, 0x98, 0xed, 0x85, + 0x8c, 0x02, 0xc2, 0x65, 0x2f, 0xbf, 0x92, 0x2e }, + { 0xc4, 0x54, 0x18, 0x5e, 0x6a, 0x16, 0x93, 0x6e, + 0x39, 0x33, 0x40, 0x38, 0xac, 0xef, 0x83, 0x8b, + 0xfb, 0x18, 0x6f, 0xff, 0x74, 0x80, 0xad, 0xc4, + 0x28, 0x93, 0x82, 0xec, 0xd6, 0xd3, 0x94, 0xf0 }, + { 0xaf, 0x85, 0x33, 0x6b, 0x59, 0x7a, 0xfc, 0x1a, + 0x90, 0x0b, 0x2e, 0xb2, 0x1e, 0xc9, 0x49, 0xd2, + 0x92, 0xdf, 0x4c, 0x04, 0x7e, 0x0b, 0x21, 0x53, + 0x21, 0x86, 0xa5, 0x97, 0x1a, 0x22, 0x7a, 0x89 }, }; static const unsigned char aes_test_xts_data_unit[][16] = -{ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, - { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, }; #endif /* MBEDTLS_CIPHER_MODE_XTS */ /* - * Checkup routine - */ -int mbedtls_aes_self_test(int verbose) +* Checkup routine +*/ +int mbedtls_aes_self_test( int verbose ) { - int ret = 0, i, j, u, mode; - unsigned int keybits; - unsigned char key[32]; - unsigned char buf[64]; - const unsigned char *aes_tests; -#if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB) || \ - defined(MBEDTLS_CIPHER_MODE_OFB) - unsigned char iv[16]; + int ret = 0, i, j, u, mode; + unsigned int keybits; + unsigned char key[32]; + unsigned char buf[64]; + const unsigned char *aes_tests; +#if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB) + unsigned char iv[16]; #endif #if defined(MBEDTLS_CIPHER_MODE_CBC) - unsigned char prv[16]; + unsigned char prv[16]; #endif #if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB) || \ - defined(MBEDTLS_CIPHER_MODE_OFB) - size_t offset; + defined(MBEDTLS_CIPHER_MODE_OFB) + size_t offset; #endif #if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_XTS) - int len; + int len; #endif #if defined(MBEDTLS_CIPHER_MODE_CTR) - unsigned char nonce_counter[16]; - unsigned char stream_block[16]; -#endif - mbedtls_aes_context ctx; - - memset(key, 0, 32); - mbedtls_aes_init(&ctx); - - if (verbose != 0) { -#if defined(MBEDTLS_AES_ALT) - mbedtls_printf(" AES note: alternative implementation.\n"); -#else /* MBEDTLS_AES_ALT */ -#if defined(MBEDTLS_AESNI_HAVE_CODE) -#if MBEDTLS_AESNI_HAVE_CODE == 1 - mbedtls_printf(" AES note: AESNI code present (assembly implementation).\n"); -#elif MBEDTLS_AESNI_HAVE_CODE == 2 - mbedtls_printf(" AES note: AESNI code present (intrinsics implementation).\n"); -#else -#error "Unrecognised value for MBEDTLS_AESNI_HAVE_CODE" -#endif - if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) { - mbedtls_printf(" AES note: using AESNI.\n"); - } else -#endif -#if defined(MBEDTLS_VIA_PADLOCK_HAVE_CODE) - if (mbedtls_padlock_has_support(MBEDTLS_PADLOCK_ACE)) { - mbedtls_printf(" AES note: using VIA Padlock.\n"); - } else -#endif -#if defined(MBEDTLS_AESCE_HAVE_CODE) - if (MBEDTLS_AESCE_HAS_SUPPORT()) { - mbedtls_printf(" AES note: using AESCE.\n"); - } else -#endif - { -#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY) - mbedtls_printf(" AES note: built-in implementation.\n"); -#endif - } -#endif /* MBEDTLS_AES_ALT */ - } - - /* - * ECB mode - */ - { - static const int num_tests = - sizeof(aes_test_ecb_enc) / sizeof(*aes_test_ecb_enc); - - for (i = 0; i < num_tests << 1; i++) { - u = i >> 1; - keybits = 128 + u * 64; - mode = i & 1; - - if (verbose != 0) { - mbedtls_printf(" AES-ECB-%3u (%s): ", keybits, - (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - } -#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) - if (mode == MBEDTLS_AES_DECRYPT) { - if (verbose != 0) { - mbedtls_printf("skipped\n"); - } - continue; - } -#endif - - memset(buf, 0, 16); - -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) - if (mode == MBEDTLS_AES_DECRYPT) { - ret = mbedtls_aes_setkey_dec(&ctx, key, keybits); - aes_tests = aes_test_ecb_dec[u]; - } else + unsigned char nonce_counter[16]; + unsigned char stream_block[16]; #endif - { - ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); - aes_tests = aes_test_ecb_enc[u]; - } - - /* - * AES-192 is an optional feature that may be unavailable when - * there is an alternative underlying implementation i.e. when - * MBEDTLS_AES_ALT is defined. - */ - if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { - mbedtls_printf("skipped\n"); - continue; - } else if (ret != 0) { - goto exit; - } - - for (j = 0; j < 10000; j++) { - ret = mbedtls_aes_crypt_ecb(&ctx, mode, buf, buf); - if (ret != 0) { - goto exit; - } - } - - if (memcmp(buf, aes_tests, 16) != 0) { - ret = 1; - goto exit; - } - - if (verbose != 0) { - mbedtls_printf("passed\n"); - } - } - - if (verbose != 0) { - mbedtls_printf("\n"); - } - } + mbedtls_aes_context ctx; + + memset( key, 0, 32 ); + mbedtls_aes_init( &ctx ); + + /* + * ECB mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + keybits = 128 + u * 64; + mode = i & 1; + + if( verbose != 0 ) + mbedtls_printf( " AES-ECB-%3u (%s): ", keybits, + ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + + memset( buf, 0, 16 ); + + if( mode == MBEDTLS_AES_DECRYPT ) + { + ret = mbedtls_aes_setkey_dec( &ctx, key, keybits ); + aes_tests = aes_test_ecb_dec[u]; + } + else + { + ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + aes_tests = aes_test_ecb_enc[u]; + } + + /* + * AES-192 is an optional feature that may be unavailable when + * there is an alternative underlying implementation i.e. when + * MBEDTLS_AES_ALT is defined. + */ + if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) + { + mbedtls_printf( "skipped\n" ); + continue; + } + else if( ret != 0 ) + { + goto exit; + } + + for( j = 0; j < 10000; j++ ) + { + ret = mbedtls_aes_crypt_ecb( &ctx, mode, buf, buf ); + if( ret != 0 ) + goto exit; + } + + if( memcmp( buf, aes_tests, 16 ) != 0 ) + { + ret = 1; + goto exit; + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); #if defined(MBEDTLS_CIPHER_MODE_CBC) - /* - * CBC mode - */ - { - static const int num_tests = - sizeof(aes_test_cbc_dec) / sizeof(*aes_test_cbc_dec); - - for (i = 0; i < num_tests << 1; i++) { - u = i >> 1; - keybits = 128 + u * 64; - mode = i & 1; - - if (verbose != 0) { - mbedtls_printf(" AES-CBC-%3u (%s): ", keybits, - (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - } - - memset(iv, 0, 16); - memset(prv, 0, 16); - memset(buf, 0, 16); - - if (mode == MBEDTLS_AES_DECRYPT) { - ret = mbedtls_aes_setkey_dec(&ctx, key, keybits); - aes_tests = aes_test_cbc_dec[u]; - } else { - ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); - aes_tests = aes_test_cbc_enc[u]; - } - - /* - * AES-192 is an optional feature that may be unavailable when - * there is an alternative underlying implementation i.e. when - * MBEDTLS_AES_ALT is defined. - */ - if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { - mbedtls_printf("skipped\n"); - continue; - } else if (ret != 0) { - goto exit; - } - - for (j = 0; j < 10000; j++) { - if (mode == MBEDTLS_AES_ENCRYPT) { - unsigned char tmp[16]; - - memcpy(tmp, prv, 16); - memcpy(prv, buf, 16); - memcpy(buf, tmp, 16); - } - - ret = mbedtls_aes_crypt_cbc(&ctx, mode, 16, iv, buf, buf); - if (ret != 0) { - goto exit; - } - - } - - if (memcmp(buf, aes_tests, 16) != 0) { - ret = 1; - goto exit; - } - - if (verbose != 0) { - mbedtls_printf("passed\n"); - } - } - - if (verbose != 0) { - mbedtls_printf("\n"); - } - } + /* + * CBC mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + keybits = 128 + u * 64; + mode = i & 1; + + if( verbose != 0 ) + mbedtls_printf( " AES-CBC-%3u (%s): ", keybits, + ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + + memset( iv , 0, 16 ); + memset( prv, 0, 16 ); + memset( buf, 0, 16 ); + + if( mode == MBEDTLS_AES_DECRYPT ) + { + ret = mbedtls_aes_setkey_dec( &ctx, key, keybits ); + aes_tests = aes_test_cbc_dec[u]; + } + else + { + ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + aes_tests = aes_test_cbc_enc[u]; + } + + /* + * AES-192 is an optional feature that may be unavailable when + * there is an alternative underlying implementation i.e. when + * MBEDTLS_AES_ALT is defined. + */ + if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) + { + mbedtls_printf( "skipped\n" ); + continue; + } + else if( ret != 0 ) + { + goto exit; + } + + for( j = 0; j < 10000; j++ ) + { + if( mode == MBEDTLS_AES_ENCRYPT ) + { + unsigned char tmp[16]; + + memcpy( tmp, prv, 16 ); + memcpy( prv, buf, 16 ); + memcpy( buf, tmp, 16 ); + } + + ret = mbedtls_aes_crypt_cbc( &ctx, mode, 16, iv, buf, buf ); + if( ret != 0 ) + goto exit; + + } + + if( memcmp( buf, aes_tests, 16 ) != 0 ) + { + ret = 1; + goto exit; + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) - /* - * CFB128 mode - */ - { - static const int num_tests = - sizeof(aes_test_cfb128_key) / sizeof(*aes_test_cfb128_key); - - for (i = 0; i < num_tests << 1; i++) { - u = i >> 1; - keybits = 128 + u * 64; - mode = i & 1; - - if (verbose != 0) { - mbedtls_printf(" AES-CFB128-%3u (%s): ", keybits, - (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - } - - memcpy(iv, aes_test_cfb128_iv, 16); - memcpy(key, aes_test_cfb128_key[u], keybits / 8); - - offset = 0; - ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); - /* - * AES-192 is an optional feature that may be unavailable when - * there is an alternative underlying implementation i.e. when - * MBEDTLS_AES_ALT is defined. - */ - if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { - mbedtls_printf("skipped\n"); - continue; - } else if (ret != 0) { - goto exit; - } - - if (mode == MBEDTLS_AES_DECRYPT) { - memcpy(buf, aes_test_cfb128_ct[u], 64); - aes_tests = aes_test_cfb128_pt; - } else { - memcpy(buf, aes_test_cfb128_pt, 64); - aes_tests = aes_test_cfb128_ct[u]; - } - - ret = mbedtls_aes_crypt_cfb128(&ctx, mode, 64, &offset, iv, buf, buf); - if (ret != 0) { - goto exit; - } - - if (memcmp(buf, aes_tests, 64) != 0) { - ret = 1; - goto exit; - } - - if (verbose != 0) { - mbedtls_printf("passed\n"); - } - } - - if (verbose != 0) { - mbedtls_printf("\n"); - } - } + /* + * CFB128 mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + keybits = 128 + u * 64; + mode = i & 1; + + if( verbose != 0 ) + mbedtls_printf( " AES-CFB128-%3u (%s): ", keybits, + ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + + memcpy( iv, aes_test_cfb128_iv, 16 ); + memcpy( key, aes_test_cfb128_key[u], keybits / 8 ); + + offset = 0; + ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + /* + * AES-192 is an optional feature that may be unavailable when + * there is an alternative underlying implementation i.e. when + * MBEDTLS_AES_ALT is defined. + */ + if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) + { + mbedtls_printf( "skipped\n" ); + continue; + } + else if( ret != 0 ) + { + goto exit; + } + + if( mode == MBEDTLS_AES_DECRYPT ) + { + memcpy( buf, aes_test_cfb128_ct[u], 64 ); + aes_tests = aes_test_cfb128_pt; + } + else + { + memcpy( buf, aes_test_cfb128_pt, 64 ); + aes_tests = aes_test_cfb128_ct[u]; + } + + ret = mbedtls_aes_crypt_cfb128( &ctx, mode, 64, &offset, iv, buf, buf ); + if( ret != 0 ) + goto exit; + + if( memcmp( buf, aes_tests, 64 ) != 0 ) + { + ret = 1; + goto exit; + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) - /* - * OFB mode - */ - { - static const int num_tests = - sizeof(aes_test_ofb_key) / sizeof(*aes_test_ofb_key); - - for (i = 0; i < num_tests << 1; i++) { - u = i >> 1; - keybits = 128 + u * 64; - mode = i & 1; - - if (verbose != 0) { - mbedtls_printf(" AES-OFB-%3u (%s): ", keybits, - (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - } - - memcpy(iv, aes_test_ofb_iv, 16); - memcpy(key, aes_test_ofb_key[u], keybits / 8); - - offset = 0; - ret = mbedtls_aes_setkey_enc(&ctx, key, keybits); - /* - * AES-192 is an optional feature that may be unavailable when - * there is an alternative underlying implementation i.e. when - * MBEDTLS_AES_ALT is defined. - */ - if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) { - mbedtls_printf("skipped\n"); - continue; - } else if (ret != 0) { - goto exit; - } - - if (mode == MBEDTLS_AES_DECRYPT) { - memcpy(buf, aes_test_ofb_ct[u], 64); - aes_tests = aes_test_ofb_pt; - } else { - memcpy(buf, aes_test_ofb_pt, 64); - aes_tests = aes_test_ofb_ct[u]; - } - - ret = mbedtls_aes_crypt_ofb(&ctx, 64, &offset, iv, buf, buf); - if (ret != 0) { - goto exit; - } - - if (memcmp(buf, aes_tests, 64) != 0) { - ret = 1; - goto exit; - } - - if (verbose != 0) { - mbedtls_printf("passed\n"); - } - } - - if (verbose != 0) { - mbedtls_printf("\n"); - } - } + /* + * OFB mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + keybits = 128 + u * 64; + mode = i & 1; + + if( verbose != 0 ) + mbedtls_printf( " AES-OFB-%3u (%s): ", keybits, + ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + + memcpy( iv, aes_test_ofb_iv, 16 ); + memcpy( key, aes_test_ofb_key[u], keybits / 8 ); + + offset = 0; + ret = mbedtls_aes_setkey_enc( &ctx, key, keybits ); + /* + * AES-192 is an optional feature that may be unavailable when + * there is an alternative underlying implementation i.e. when + * MBEDTLS_AES_ALT is defined. + */ + if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192 ) + { + mbedtls_printf( "skipped\n" ); + continue; + } + else if( ret != 0 ) + { + goto exit; + } + + if( mode == MBEDTLS_AES_DECRYPT ) + { + memcpy( buf, aes_test_ofb_ct[u], 64 ); + aes_tests = aes_test_ofb_pt; + } + else + { + memcpy( buf, aes_test_ofb_pt, 64 ); + aes_tests = aes_test_ofb_ct[u]; + } + + ret = mbedtls_aes_crypt_ofb( &ctx, 64, &offset, iv, buf, buf ); + if( ret != 0 ) + goto exit; + + if( memcmp( buf, aes_tests, 64 ) != 0 ) + { + ret = 1; + goto exit; + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) - /* - * CTR mode - */ - { - static const int num_tests = - sizeof(aes_test_ctr_key) / sizeof(*aes_test_ctr_key); - - for (i = 0; i < num_tests << 1; i++) { - u = i >> 1; - mode = i & 1; - - if (verbose != 0) { - mbedtls_printf(" AES-CTR-128 (%s): ", - (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - } - - memcpy(nonce_counter, aes_test_ctr_nonce_counter[u], 16); - memcpy(key, aes_test_ctr_key[u], 16); - - offset = 0; - if ((ret = mbedtls_aes_setkey_enc(&ctx, key, 128)) != 0) { - goto exit; - } - - len = aes_test_ctr_len[u]; - - if (mode == MBEDTLS_AES_DECRYPT) { - memcpy(buf, aes_test_ctr_ct[u], len); - aes_tests = aes_test_ctr_pt[u]; - } else { - memcpy(buf, aes_test_ctr_pt[u], len); - aes_tests = aes_test_ctr_ct[u]; - } - - ret = mbedtls_aes_crypt_ctr(&ctx, len, &offset, nonce_counter, - stream_block, buf, buf); - if (ret != 0) { - goto exit; - } - - if (memcmp(buf, aes_tests, len) != 0) { - ret = 1; - goto exit; - } - - if (verbose != 0) { - mbedtls_printf("passed\n"); - } - } - } - - if (verbose != 0) { - mbedtls_printf("\n"); - } + /* + * CTR mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + mode = i & 1; + + if( verbose != 0 ) + mbedtls_printf( " AES-CTR-128 (%s): ", + ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + + memcpy( nonce_counter, aes_test_ctr_nonce_counter[u], 16 ); + memcpy( key, aes_test_ctr_key[u], 16 ); + + offset = 0; + if( ( ret = mbedtls_aes_setkey_enc( &ctx, key, 128 ) ) != 0 ) + goto exit; + + len = aes_test_ctr_len[u]; + + if( mode == MBEDTLS_AES_DECRYPT ) + { + memcpy( buf, aes_test_ctr_ct[u], len ); + aes_tests = aes_test_ctr_pt[u]; + } + else + { + memcpy( buf, aes_test_ctr_pt[u], len ); + aes_tests = aes_test_ctr_ct[u]; + } + + ret = mbedtls_aes_crypt_ctr( &ctx, len, &offset, nonce_counter, + stream_block, buf, buf ); + if( ret != 0 ) + goto exit; + + if( memcmp( buf, aes_tests, len ) != 0 ) + { + ret = 1; + goto exit; + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) - /* - * XTS mode - */ - { - static const int num_tests = - sizeof(aes_test_xts_key) / sizeof(*aes_test_xts_key); - mbedtls_aes_xts_context ctx_xts; - - mbedtls_aes_xts_init(&ctx_xts); - - for (i = 0; i < num_tests << 1; i++) { - const unsigned char *data_unit; - u = i >> 1; - mode = i & 1; - - if (verbose != 0) { - mbedtls_printf(" AES-XTS-128 (%s): ", - (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc"); - } - - memset(key, 0, sizeof(key)); - memcpy(key, aes_test_xts_key[u], 32); - data_unit = aes_test_xts_data_unit[u]; - - len = sizeof(*aes_test_xts_ct32); - - if (mode == MBEDTLS_AES_DECRYPT) { - ret = mbedtls_aes_xts_setkey_dec(&ctx_xts, key, 256); - if (ret != 0) { - goto exit; - } - memcpy(buf, aes_test_xts_ct32[u], len); - aes_tests = aes_test_xts_pt32[u]; - } else { - ret = mbedtls_aes_xts_setkey_enc(&ctx_xts, key, 256); - if (ret != 0) { - goto exit; - } - memcpy(buf, aes_test_xts_pt32[u], len); - aes_tests = aes_test_xts_ct32[u]; - } - - - ret = mbedtls_aes_crypt_xts(&ctx_xts, mode, len, data_unit, - buf, buf); - if (ret != 0) { - goto exit; - } - - if (memcmp(buf, aes_tests, len) != 0) { - ret = 1; - goto exit; - } - - if (verbose != 0) { - mbedtls_printf("passed\n"); - } - } - - if (verbose != 0) { - mbedtls_printf("\n"); - } - - mbedtls_aes_xts_free(&ctx_xts); - } + { + static const int num_tests = + sizeof(aes_test_xts_key) / sizeof(*aes_test_xts_key); + mbedtls_aes_xts_context ctx_xts; + + /* + * XTS mode + */ + mbedtls_aes_xts_init( &ctx_xts ); + + for( i = 0; i < num_tests << 1; i++ ) + { + const unsigned char *data_unit; + u = i >> 1; + mode = i & 1; + + if( verbose != 0 ) + mbedtls_printf( " AES-XTS-128 (%s): ", + ( mode == MBEDTLS_AES_DECRYPT ) ? "dec" : "enc" ); + + memset( key, 0, sizeof( key ) ); + memcpy( key, aes_test_xts_key[u], 32 ); + data_unit = aes_test_xts_data_unit[u]; + + len = sizeof( *aes_test_xts_ct32 ); + + if( mode == MBEDTLS_AES_DECRYPT ) + { + ret = mbedtls_aes_xts_setkey_dec( &ctx_xts, key, 256 ); + if( ret != 0) + goto exit; + memcpy( buf, aes_test_xts_ct32[u], len ); + aes_tests = aes_test_xts_pt32[u]; + } + else + { + ret = mbedtls_aes_xts_setkey_enc( &ctx_xts, key, 256 ); + if( ret != 0) + goto exit; + memcpy( buf, aes_test_xts_pt32[u], len ); + aes_tests = aes_test_xts_ct32[u]; + } + + + ret = mbedtls_aes_crypt_xts( &ctx_xts, mode, len, data_unit, + buf, buf ); + if( ret != 0 ) + goto exit; + + if( memcmp( buf, aes_tests, len ) != 0 ) + { + ret = 1; + goto exit; + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); + + mbedtls_aes_xts_free( &ctx_xts ); + } #endif /* MBEDTLS_CIPHER_MODE_XTS */ - ret = 0; + ret = 0; exit: - if (ret != 0 && verbose != 0) { - mbedtls_printf("failed\n"); - } + if( ret != 0 && verbose != 0 ) + mbedtls_printf( "failed\n" ); - mbedtls_aes_free(&ctx); + mbedtls_aes_free( &ctx ); - return ret; + return( ret ); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/library/aesni.h b/src/duckdb/third_party/mbedtls/library/aesni.h index 59e27afd3..6b63dc037 100644 --- a/src/duckdb/third_party/mbedtls/library/aesni.h +++ b/src/duckdb/third_party/mbedtls/library/aesni.h @@ -1,162 +1 @@ -/** - * \file aesni.h - * - * \brief AES-NI for hardware AES acceleration on some Intel processors - * - * \warning These functions are only for internal use by other library - * functions; you must not call them directly. - */ -/* - * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ -#ifndef MBEDTLS_AESNI_H -#define MBEDTLS_AESNI_H - -#include "mbedtls/build_info.h" - -#include "mbedtls/aes.h" - -#define MBEDTLS_AESNI_AES 0x02000000u -#define MBEDTLS_AESNI_CLMUL 0x00000002u - -#if defined(MBEDTLS_AESNI_C) && \ - (defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_X86)) - -/* Can we do AESNI with intrinsics? - * (Only implemented with certain compilers, only for certain targets.) - */ -#undef MBEDTLS_AESNI_HAVE_INTRINSICS -#if defined(_MSC_VER) && !defined(__clang__) -/* Visual Studio supports AESNI intrinsics since VS 2008 SP1. We only support - * VS 2013 and up for other reasons anyway, so no need to check the version. */ -#define MBEDTLS_AESNI_HAVE_INTRINSICS -#endif -/* GCC-like compilers: currently, we only support intrinsics if the requisite - * target flag is enabled when building the library (e.g. `gcc -mpclmul -msse2` - * or `clang -maes -mpclmul`). */ -#if (defined(__GNUC__) || defined(__clang__)) && defined(__AES__) && defined(__PCLMUL__) -#define MBEDTLS_AESNI_HAVE_INTRINSICS -#endif -/* For 32-bit, we only support intrinsics */ -#if defined(MBEDTLS_ARCH_IS_X86) && (defined(__GNUC__) || defined(__clang__)) -#define MBEDTLS_AESNI_HAVE_INTRINSICS -#endif - -/* Choose the implementation of AESNI, if one is available. - * - * Favor the intrinsics-based implementation if it's available, for better - * maintainability. - * Performance is about the same (see #7380). - * In the long run, we will likely remove the assembly implementation. */ -#if defined(MBEDTLS_AESNI_HAVE_INTRINSICS) -#define MBEDTLS_AESNI_HAVE_CODE 2 // via intrinsics -#elif defined(MBEDTLS_HAVE_ASM) && \ - (defined(__GNUC__) || defined(__clang__)) && defined(MBEDTLS_ARCH_IS_X64) -/* Can we do AESNI with inline assembly? - * (Only implemented with gas syntax, only for 64-bit.) - */ -#define MBEDTLS_AESNI_HAVE_CODE 1 // via assembly -#else -#error "MBEDTLS_AESNI_C defined, but neither intrinsics nor assembly available" -#endif - -#if defined(MBEDTLS_AESNI_HAVE_CODE) - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \brief Internal function to detect the AES-NI feature in CPUs. - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param what The feature to detect - * (MBEDTLS_AESNI_AES or MBEDTLS_AESNI_CLMUL) - * - * \return 1 if CPU has support for the feature, 0 otherwise - */ -#if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY) -int mbedtls_aesni_has_support(unsigned int what); -#else -#define mbedtls_aesni_has_support(what) 1 -#endif - -/** - * \brief Internal AES-NI AES-ECB block encryption and decryption - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param ctx AES context - * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT - * \param input 16-byte input block - * \param output 16-byte output block - * - * \return 0 on success (cannot fail) - */ -int mbedtls_aesni_crypt_ecb(mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16]); - -/** - * \brief Internal GCM multiplication: c = a * b in GF(2^128) - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param c Result - * \param a First operand - * \param b Second operand - * - * \note Both operands and result are bit strings interpreted as - * elements of GF(2^128) as per the GCM spec. - */ -void mbedtls_aesni_gcm_mult(unsigned char c[16], - const unsigned char a[16], - const unsigned char b[16]); - -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -/** - * \brief Internal round key inversion. This function computes - * decryption round keys from the encryption round keys. - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param invkey Round keys for the equivalent inverse cipher - * \param fwdkey Original round keys (for encryption) - * \param nr Number of rounds (that is, number of round keys minus one) - */ -void mbedtls_aesni_inverse_key(unsigned char *invkey, - const unsigned char *fwdkey, - int nr); -#endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */ - -/** - * \brief Internal key expansion for encryption - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param rk Destination buffer where the round keys are written - * \param key Encryption key - * \param bits Key size in bits (must be 128, 192 or 256) - * - * \return 0 if successful, or MBEDTLS_ERR_AES_INVALID_KEY_LENGTH - */ -int mbedtls_aesni_setkey_enc(unsigned char *rk, - const unsigned char *key, - size_t bits); - -#ifdef __cplusplus -} -#endif - -#endif /* MBEDTLS_AESNI_HAVE_CODE */ -#endif /* MBEDTLS_AESNI_C && (MBEDTLS_ARCH_IS_X64 || MBEDTLS_ARCH_IS_X86) */ - -#endif /* MBEDTLS_AESNI_H */ +// dummy file to make amalgamantion happy diff --git a/src/duckdb/third_party/mbedtls/library/aria.cpp b/src/duckdb/third_party/mbedtls/library/aria.cpp new file mode 100644 index 000000000..bc05c4a31 --- /dev/null +++ b/src/duckdb/third_party/mbedtls/library/aria.cpp @@ -0,0 +1,1058 @@ +/* + * ARIA implementation + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * This implementation is based on the following standards: + * [1] http://210.104.33.10/ARIA/doc/ARIA-specification-e.pdf + * [2] https://tools.ietf.org/html/rfc5794 + */ + +#include "common.h" + +#if defined(MBEDTLS_ARIA_C) + +#include "mbedtls/aria.h" + +#include + +#if defined(MBEDTLS_SELF_TEST) +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#include +#define mbedtls_printf printf +#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ + +#if !defined(MBEDTLS_ARIA_ALT) + +#include "mbedtls/platform_util.h" + +#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \ + !defined(inline) && !defined(__cplusplus) +#define inline __inline +#endif + +/* Parameter validation macros */ +#define ARIA_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ) +#define ARIA_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) + +/* + * modify byte order: ( A B C D ) -> ( B A D C ), i.e. swap pairs of bytes + * + * This is submatrix P1 in [1] Appendix B.1 + * + * Common compilers fail to translate this to minimal number of instructions, + * so let's provide asm versions for common platforms with C fallback. + */ +#if defined(MBEDTLS_HAVE_ASM) +#if defined(__arm__) /* rev16 available from v6 up */ +/* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */ +#if defined(__GNUC__) && \ + ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 ) && \ + __ARM_ARCH >= 6 +static inline uint32_t aria_p1( uint32_t x ) +{ + uint32_t r; + __asm( "rev16 %0, %1" : "=l" (r) : "l" (x) ); + return( r ); +} +#define ARIA_P1 aria_p1 +#elif defined(__ARMCC_VERSION) && __ARMCC_VERSION < 6000000 && \ + ( __TARGET_ARCH_ARM >= 6 || __TARGET_ARCH_THUMB >= 3 ) +static inline uint32_t aria_p1( uint32_t x ) +{ + uint32_t r; + __asm( "rev16 r, x" ); + return( r ); +} +#define ARIA_P1 aria_p1 +#endif +#endif /* arm */ +#if defined(__GNUC__) && \ + defined(__i386__) || defined(__amd64__) || defined( __x86_64__) +/* I couldn't find an Intel equivalent of rev16, so two instructions */ +#define ARIA_P1(x) ARIA_P2( ARIA_P3( x ) ) +#endif /* x86 gnuc */ +#endif /* MBEDTLS_HAVE_ASM && GNUC */ +#if !defined(ARIA_P1) +#define ARIA_P1(x) ((((x) >> 8) & 0x00FF00FF) ^ (((x) & 0x00FF00FF) << 8)) +#endif + +/* + * modify byte order: ( A B C D ) -> ( C D A B ), i.e. rotate by 16 bits + * + * This is submatrix P2 in [1] Appendix B.1 + * + * Common compilers will translate this to a single instruction. + */ +#define ARIA_P2(x) (((x) >> 16) ^ ((x) << 16)) + +/* + * modify byte order: ( A B C D ) -> ( D C B A ), i.e. change endianness + * + * This is submatrix P3 in [1] Appendix B.1 + * + * Some compilers fail to translate this to a single instruction, + * so let's provide asm versions for common platforms with C fallback. + */ +#if defined(MBEDTLS_HAVE_ASM) +#if defined(__arm__) /* rev available from v6 up */ +/* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */ +#if defined(__GNUC__) && \ + ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 ) && \ + __ARM_ARCH >= 6 +static inline uint32_t aria_p3( uint32_t x ) +{ + uint32_t r; + __asm( "rev %0, %1" : "=l" (r) : "l" (x) ); + return( r ); +} +#define ARIA_P3 aria_p3 +#elif defined(__ARMCC_VERSION) && __ARMCC_VERSION < 6000000 && \ + ( __TARGET_ARCH_ARM >= 6 || __TARGET_ARCH_THUMB >= 3 ) +static inline uint32_t aria_p3( uint32_t x ) +{ + uint32_t r; + __asm( "rev r, x" ); + return( r ); +} +#define ARIA_P3 aria_p3 +#endif +#endif /* arm */ +#if defined(__GNUC__) && \ + defined(__i386__) || defined(__amd64__) || defined( __x86_64__) +static inline uint32_t aria_p3( uint32_t x ) +{ + __asm( "bswap %0" : "=r" (x) : "0" (x) ); + return( x ); +} +#define ARIA_P3 aria_p3 +#endif /* x86 gnuc */ +#endif /* MBEDTLS_HAVE_ASM && GNUC */ +#if !defined(ARIA_P3) +#define ARIA_P3(x) ARIA_P2( ARIA_P1 ( x ) ) +#endif + +/* + * ARIA Affine Transform + * (a, b, c, d) = state in/out + * + * If we denote the first byte of input by 0, ..., the last byte by f, + * then inputs are: a = 0123, b = 4567, c = 89ab, d = cdef. + * + * Reading [1] 2.4 or [2] 2.4.3 in columns and performing simple + * rearrangements on adjacent pairs, output is: + * + * a = 3210 + 4545 + 6767 + 88aa + 99bb + dccd + effe + * = 3210 + 4567 + 6745 + 89ab + 98ba + dcfe + efcd + * b = 0101 + 2323 + 5476 + 8998 + baab + eecc + ffdd + * = 0123 + 2301 + 5476 + 89ab + ba98 + efcd + fedc + * c = 0022 + 1133 + 4554 + 7667 + ab89 + dcdc + fefe + * = 0123 + 1032 + 4567 + 7654 + ab89 + dcfe + fedc + * d = 1001 + 2332 + 6644 + 7755 + 9898 + baba + cdef + * = 1032 + 2301 + 6745 + 7654 + 98ba + ba98 + cdef + * + * Note: another presentation of the A transform can be found as the first + * half of App. B.1 in [1] in terms of 4-byte operators P1, P2, P3 and P4. + * The implementation below uses only P1 and P2 as they are sufficient. + */ +static inline void aria_a( uint32_t *a, uint32_t *b, + uint32_t *c, uint32_t *d ) +{ + uint32_t ta, tb, tc; + ta = *b; // 4567 + *b = *a; // 0123 + *a = ARIA_P2( ta ); // 6745 + tb = ARIA_P2( *d ); // efcd + *d = ARIA_P1( *c ); // 98ba + *c = ARIA_P1( tb ); // fedc + ta ^= *d; // 4567+98ba + tc = ARIA_P2( *b ); // 2301 + ta = ARIA_P1( ta ) ^ tc ^ *c; // 2301+5476+89ab+fedc + tb ^= ARIA_P2( *d ); // ba98+efcd + tc ^= ARIA_P1( *a ); // 2301+7654 + *b ^= ta ^ tb; // 0123+2301+5476+89ab+ba98+efcd+fedc OUT + tb = ARIA_P2( tb ) ^ ta; // 2301+5476+89ab+98ba+cdef+fedc + *a ^= ARIA_P1( tb ); // 3210+4567+6745+89ab+98ba+dcfe+efcd OUT + ta = ARIA_P2( ta ); // 0123+7654+ab89+dcfe + *d ^= ARIA_P1( ta ) ^ tc; // 1032+2301+6745+7654+98ba+ba98+cdef OUT + tc = ARIA_P2( tc ); // 0123+5476 + *c ^= ARIA_P1( tc ) ^ ta; // 0123+1032+4567+7654+ab89+dcfe+fedc OUT +} + +/* + * ARIA Substitution Layer SL1 / SL2 + * (a, b, c, d) = state in/out + * (sa, sb, sc, sd) = 256 8-bit S-Boxes (see below) + * + * By passing sb1, sb2, is1, is2 as S-Boxes you get SL1 + * By passing is1, is2, sb1, sb2 as S-Boxes you get SL2 + */ +static inline void aria_sl( uint32_t *a, uint32_t *b, + uint32_t *c, uint32_t *d, + const uint8_t sa[256], const uint8_t sb[256], + const uint8_t sc[256], const uint8_t sd[256] ) +{ + *a = ( (uint32_t) sa[ MBEDTLS_BYTE_0( *a ) ] ) ^ + (((uint32_t) sb[ MBEDTLS_BYTE_1( *a ) ]) << 8) ^ + (((uint32_t) sc[ MBEDTLS_BYTE_2( *a ) ]) << 16) ^ + (((uint32_t) sd[ MBEDTLS_BYTE_3( *a ) ]) << 24); + *b = ( (uint32_t) sa[ MBEDTLS_BYTE_0( *b ) ] ) ^ + (((uint32_t) sb[ MBEDTLS_BYTE_1( *b ) ]) << 8) ^ + (((uint32_t) sc[ MBEDTLS_BYTE_2( *b ) ]) << 16) ^ + (((uint32_t) sd[ MBEDTLS_BYTE_3( *b ) ]) << 24); + *c = ( (uint32_t) sa[ MBEDTLS_BYTE_0( *c ) ] ) ^ + (((uint32_t) sb[ MBEDTLS_BYTE_1( *c ) ]) << 8) ^ + (((uint32_t) sc[ MBEDTLS_BYTE_2( *c ) ]) << 16) ^ + (((uint32_t) sd[ MBEDTLS_BYTE_3( *c ) ]) << 24); + *d = ( (uint32_t) sa[ MBEDTLS_BYTE_0( *d ) ] ) ^ + (((uint32_t) sb[ MBEDTLS_BYTE_1( *d ) ]) << 8) ^ + (((uint32_t) sc[ MBEDTLS_BYTE_2( *d ) ]) << 16) ^ + (((uint32_t) sd[ MBEDTLS_BYTE_3( *d ) ]) << 24); +} + +/* + * S-Boxes + */ +static const uint8_t aria_sb1[256] = +{ + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, 0x30, 0x01, 0x67, 0x2B, + 0xFE, 0xD7, 0xAB, 0x76, 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, + 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, 0xB7, 0xFD, 0x93, 0x26, + 0x36, 0x3F, 0xF7, 0xCC, 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, 0x07, 0x12, 0x80, 0xE2, + 0xEB, 0x27, 0xB2, 0x75, 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, + 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, 0x53, 0xD1, 0x00, 0xED, + 0x20, 0xFC, 0xB1, 0x5B, 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, 0x45, 0xF9, 0x02, 0x7F, + 0x50, 0x3C, 0x9F, 0xA8, 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, + 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, 0xCD, 0x0C, 0x13, 0xEC, + 0x5F, 0x97, 0x44, 0x17, 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, 0x46, 0xEE, 0xB8, 0x14, + 0xDE, 0x5E, 0x0B, 0xDB, 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, + 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, 0xE7, 0xC8, 0x37, 0x6D, + 0x8D, 0xD5, 0x4E, 0xA9, 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, 0xE8, 0xDD, 0x74, 0x1F, + 0x4B, 0xBD, 0x8B, 0x8A, 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, 0xE1, 0xF8, 0x98, 0x11, + 0x69, 0xD9, 0x8E, 0x94, 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, 0x41, 0x99, 0x2D, 0x0F, + 0xB0, 0x54, 0xBB, 0x16 +}; + +static const uint8_t aria_sb2[256] = +{ + 0xE2, 0x4E, 0x54, 0xFC, 0x94, 0xC2, 0x4A, 0xCC, 0x62, 0x0D, 0x6A, 0x46, + 0x3C, 0x4D, 0x8B, 0xD1, 0x5E, 0xFA, 0x64, 0xCB, 0xB4, 0x97, 0xBE, 0x2B, + 0xBC, 0x77, 0x2E, 0x03, 0xD3, 0x19, 0x59, 0xC1, 0x1D, 0x06, 0x41, 0x6B, + 0x55, 0xF0, 0x99, 0x69, 0xEA, 0x9C, 0x18, 0xAE, 0x63, 0xDF, 0xE7, 0xBB, + 0x00, 0x73, 0x66, 0xFB, 0x96, 0x4C, 0x85, 0xE4, 0x3A, 0x09, 0x45, 0xAA, + 0x0F, 0xEE, 0x10, 0xEB, 0x2D, 0x7F, 0xF4, 0x29, 0xAC, 0xCF, 0xAD, 0x91, + 0x8D, 0x78, 0xC8, 0x95, 0xF9, 0x2F, 0xCE, 0xCD, 0x08, 0x7A, 0x88, 0x38, + 0x5C, 0x83, 0x2A, 0x28, 0x47, 0xDB, 0xB8, 0xC7, 0x93, 0xA4, 0x12, 0x53, + 0xFF, 0x87, 0x0E, 0x31, 0x36, 0x21, 0x58, 0x48, 0x01, 0x8E, 0x37, 0x74, + 0x32, 0xCA, 0xE9, 0xB1, 0xB7, 0xAB, 0x0C, 0xD7, 0xC4, 0x56, 0x42, 0x26, + 0x07, 0x98, 0x60, 0xD9, 0xB6, 0xB9, 0x11, 0x40, 0xEC, 0x20, 0x8C, 0xBD, + 0xA0, 0xC9, 0x84, 0x04, 0x49, 0x23, 0xF1, 0x4F, 0x50, 0x1F, 0x13, 0xDC, + 0xD8, 0xC0, 0x9E, 0x57, 0xE3, 0xC3, 0x7B, 0x65, 0x3B, 0x02, 0x8F, 0x3E, + 0xE8, 0x25, 0x92, 0xE5, 0x15, 0xDD, 0xFD, 0x17, 0xA9, 0xBF, 0xD4, 0x9A, + 0x7E, 0xC5, 0x39, 0x67, 0xFE, 0x76, 0x9D, 0x43, 0xA7, 0xE1, 0xD0, 0xF5, + 0x68, 0xF2, 0x1B, 0x34, 0x70, 0x05, 0xA3, 0x8A, 0xD5, 0x79, 0x86, 0xA8, + 0x30, 0xC6, 0x51, 0x4B, 0x1E, 0xA6, 0x27, 0xF6, 0x35, 0xD2, 0x6E, 0x24, + 0x16, 0x82, 0x5F, 0xDA, 0xE6, 0x75, 0xA2, 0xEF, 0x2C, 0xB2, 0x1C, 0x9F, + 0x5D, 0x6F, 0x80, 0x0A, 0x72, 0x44, 0x9B, 0x6C, 0x90, 0x0B, 0x5B, 0x33, + 0x7D, 0x5A, 0x52, 0xF3, 0x61, 0xA1, 0xF7, 0xB0, 0xD6, 0x3F, 0x7C, 0x6D, + 0xED, 0x14, 0xE0, 0xA5, 0x3D, 0x22, 0xB3, 0xF8, 0x89, 0xDE, 0x71, 0x1A, + 0xAF, 0xBA, 0xB5, 0x81 +}; + +static const uint8_t aria_is1[256] = +{ + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, + 0x81, 0xF3, 0xD7, 0xFB, 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, 0x54, 0x7B, 0x94, 0x32, + 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, + 0x6D, 0x8B, 0xD1, 0x25, 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, + 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, 0x6C, 0x70, 0x48, 0x50, + 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, + 0xB8, 0xB3, 0x45, 0x06, 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, + 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, 0x3A, 0x91, 0x11, 0x41, + 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, + 0x1C, 0x75, 0xDF, 0x6E, 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, + 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, 0xFC, 0x56, 0x3E, 0x4B, + 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, + 0x27, 0x80, 0xEC, 0x5F, 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, 0xA0, 0xE0, 0x3B, 0x4D, + 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, + 0x55, 0x21, 0x0C, 0x7D +}; + +static const uint8_t aria_is2[256] = +{ + 0x30, 0x68, 0x99, 0x1B, 0x87, 0xB9, 0x21, 0x78, 0x50, 0x39, 0xDB, 0xE1, + 0x72, 0x09, 0x62, 0x3C, 0x3E, 0x7E, 0x5E, 0x8E, 0xF1, 0xA0, 0xCC, 0xA3, + 0x2A, 0x1D, 0xFB, 0xB6, 0xD6, 0x20, 0xC4, 0x8D, 0x81, 0x65, 0xF5, 0x89, + 0xCB, 0x9D, 0x77, 0xC6, 0x57, 0x43, 0x56, 0x17, 0xD4, 0x40, 0x1A, 0x4D, + 0xC0, 0x63, 0x6C, 0xE3, 0xB7, 0xC8, 0x64, 0x6A, 0x53, 0xAA, 0x38, 0x98, + 0x0C, 0xF4, 0x9B, 0xED, 0x7F, 0x22, 0x76, 0xAF, 0xDD, 0x3A, 0x0B, 0x58, + 0x67, 0x88, 0x06, 0xC3, 0x35, 0x0D, 0x01, 0x8B, 0x8C, 0xC2, 0xE6, 0x5F, + 0x02, 0x24, 0x75, 0x93, 0x66, 0x1E, 0xE5, 0xE2, 0x54, 0xD8, 0x10, 0xCE, + 0x7A, 0xE8, 0x08, 0x2C, 0x12, 0x97, 0x32, 0xAB, 0xB4, 0x27, 0x0A, 0x23, + 0xDF, 0xEF, 0xCA, 0xD9, 0xB8, 0xFA, 0xDC, 0x31, 0x6B, 0xD1, 0xAD, 0x19, + 0x49, 0xBD, 0x51, 0x96, 0xEE, 0xE4, 0xA8, 0x41, 0xDA, 0xFF, 0xCD, 0x55, + 0x86, 0x36, 0xBE, 0x61, 0x52, 0xF8, 0xBB, 0x0E, 0x82, 0x48, 0x69, 0x9A, + 0xE0, 0x47, 0x9E, 0x5C, 0x04, 0x4B, 0x34, 0x15, 0x79, 0x26, 0xA7, 0xDE, + 0x29, 0xAE, 0x92, 0xD7, 0x84, 0xE9, 0xD2, 0xBA, 0x5D, 0xF3, 0xC5, 0xB0, + 0xBF, 0xA4, 0x3B, 0x71, 0x44, 0x46, 0x2B, 0xFC, 0xEB, 0x6F, 0xD5, 0xF6, + 0x14, 0xFE, 0x7C, 0x70, 0x5A, 0x7D, 0xFD, 0x2F, 0x18, 0x83, 0x16, 0xA5, + 0x91, 0x1F, 0x05, 0x95, 0x74, 0xA9, 0xC1, 0x5B, 0x4A, 0x85, 0x6D, 0x13, + 0x07, 0x4F, 0x4E, 0x45, 0xB2, 0x0F, 0xC9, 0x1C, 0xA6, 0xBC, 0xEC, 0x73, + 0x90, 0x7B, 0xCF, 0x59, 0x8F, 0xA1, 0xF9, 0x2D, 0xF2, 0xB1, 0x00, 0x94, + 0x37, 0x9F, 0xD0, 0x2E, 0x9C, 0x6E, 0x28, 0x3F, 0x80, 0xF0, 0x3D, 0xD3, + 0x25, 0x8A, 0xB5, 0xE7, 0x42, 0xB3, 0xC7, 0xEA, 0xF7, 0x4C, 0x11, 0x33, + 0x03, 0xA2, 0xAC, 0x60 +}; + +/* + * Helper for key schedule: r = FO( p, k ) ^ x + */ +static void aria_fo_xor( uint32_t r[4], const uint32_t p[4], + const uint32_t k[4], const uint32_t x[4] ) +{ + uint32_t a, b, c, d; + + a = p[0] ^ k[0]; + b = p[1] ^ k[1]; + c = p[2] ^ k[2]; + d = p[3] ^ k[3]; + + aria_sl( &a, &b, &c, &d, aria_sb1, aria_sb2, aria_is1, aria_is2 ); + aria_a( &a, &b, &c, &d ); + + r[0] = a ^ x[0]; + r[1] = b ^ x[1]; + r[2] = c ^ x[2]; + r[3] = d ^ x[3]; +} + +/* + * Helper for key schedule: r = FE( p, k ) ^ x + */ +static void aria_fe_xor( uint32_t r[4], const uint32_t p[4], + const uint32_t k[4], const uint32_t x[4] ) +{ + uint32_t a, b, c, d; + + a = p[0] ^ k[0]; + b = p[1] ^ k[1]; + c = p[2] ^ k[2]; + d = p[3] ^ k[3]; + + aria_sl( &a, &b, &c, &d, aria_is1, aria_is2, aria_sb1, aria_sb2 ); + aria_a( &a, &b, &c, &d ); + + r[0] = a ^ x[0]; + r[1] = b ^ x[1]; + r[2] = c ^ x[2]; + r[3] = d ^ x[3]; +} + +/* + * Big endian 128-bit rotation: r = a ^ (b <<< n), used only in key setup. + * + * We chose to store bytes into 32-bit words in little-endian format (see + * MBEDTLS_GET_UINT32_LE / MBEDTLS_PUT_UINT32_LE ) so we need to reverse + * bytes here. + */ +static void aria_rot128( uint32_t r[4], const uint32_t a[4], + const uint32_t b[4], uint8_t n ) +{ + uint8_t i, j; + uint32_t t, u; + + const uint8_t n1 = n % 32; // bit offset + const uint8_t n2 = n1 ? 32 - n1 : 0; // reverse bit offset + + j = ( n / 32 ) % 4; // initial word offset + t = ARIA_P3( b[j] ); // big endian + for( i = 0; i < 4; i++ ) + { + j = ( j + 1 ) % 4; // get next word, big endian + u = ARIA_P3( b[j] ); + t <<= n1; // rotate + t |= u >> n2; + t = ARIA_P3( t ); // back to little endian + r[i] = a[i] ^ t; // store + t = u; // move to next word + } +} + +/* + * Set encryption key + */ +int mbedtls_aria_setkey_enc( mbedtls_aria_context *ctx, + const unsigned char *key, unsigned int keybits ) +{ + /* round constant masks */ + const uint32_t rc[3][4] = + { + { 0xB7C17C51, 0x940A2227, 0xE8AB13FE, 0xE06E9AFA }, + { 0xCC4AB16D, 0x20C8219E, 0xD5B128FF, 0xB0E25DEF }, + { 0x1D3792DB, 0x70E92621, 0x75972403, 0x0EC9E804 } + }; + + int i; + uint32_t w[4][4], *w2; + ARIA_VALIDATE_RET( ctx != NULL ); + ARIA_VALIDATE_RET( key != NULL ); + + if( keybits != 128 && keybits != 192 && keybits != 256 ) + return( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ); + + /* Copy key to W0 (and potential remainder to W1) */ + w[0][0] = MBEDTLS_GET_UINT32_LE( key, 0 ); + w[0][1] = MBEDTLS_GET_UINT32_LE( key, 4 ); + w[0][2] = MBEDTLS_GET_UINT32_LE( key, 8 ); + w[0][3] = MBEDTLS_GET_UINT32_LE( key, 12 ); + + memset( w[1], 0, 16 ); + if( keybits >= 192 ) + { + w[1][0] = MBEDTLS_GET_UINT32_LE( key, 16 ); // 192 bit key + w[1][1] = MBEDTLS_GET_UINT32_LE( key, 20 ); + } + if( keybits == 256 ) + { + w[1][2] = MBEDTLS_GET_UINT32_LE( key, 24 ); // 256 bit key + w[1][3] = MBEDTLS_GET_UINT32_LE( key, 28 ); + } + + i = ( keybits - 128 ) >> 6; // index: 0, 1, 2 + ctx->nr = 12 + 2 * i; // no. rounds: 12, 14, 16 + + aria_fo_xor( w[1], w[0], rc[i], w[1] ); // W1 = FO(W0, CK1) ^ KR + i = i < 2 ? i + 1 : 0; + aria_fe_xor( w[2], w[1], rc[i], w[0] ); // W2 = FE(W1, CK2) ^ W0 + i = i < 2 ? i + 1 : 0; + aria_fo_xor( w[3], w[2], rc[i], w[1] ); // W3 = FO(W2, CK3) ^ W1 + + for( i = 0; i < 4; i++ ) // create round keys + { + w2 = w[(i + 1) & 3]; + aria_rot128( ctx->rk[i ], w[i], w2, 128 - 19 ); + aria_rot128( ctx->rk[i + 4], w[i], w2, 128 - 31 ); + aria_rot128( ctx->rk[i + 8], w[i], w2, 61 ); + aria_rot128( ctx->rk[i + 12], w[i], w2, 31 ); + } + aria_rot128( ctx->rk[16], w[0], w[1], 19 ); + + /* w holds enough info to reconstruct the round keys */ + mbedtls_platform_zeroize( w, sizeof( w ) ); + + return( 0 ); +} + +/* + * Set decryption key + */ +int mbedtls_aria_setkey_dec( mbedtls_aria_context *ctx, + const unsigned char *key, unsigned int keybits ) +{ + int i, j, k, ret; + ARIA_VALIDATE_RET( ctx != NULL ); + ARIA_VALIDATE_RET( key != NULL ); + + ret = mbedtls_aria_setkey_enc( ctx, key, keybits ); + if( ret != 0 ) + return( ret ); + + /* flip the order of round keys */ + for( i = 0, j = ctx->nr; i < j; i++, j-- ) + { + for( k = 0; k < 4; k++ ) + { + uint32_t t = ctx->rk[i][k]; + ctx->rk[i][k] = ctx->rk[j][k]; + ctx->rk[j][k] = t; + } + } + + /* apply affine transform to middle keys */ + for( i = 1; i < ctx->nr; i++ ) + { + aria_a( &ctx->rk[i][0], &ctx->rk[i][1], + &ctx->rk[i][2], &ctx->rk[i][3] ); + } + + return( 0 ); +} + +/* + * Encrypt a block + */ +int mbedtls_aria_crypt_ecb( mbedtls_aria_context *ctx, + const unsigned char input[MBEDTLS_ARIA_BLOCKSIZE], + unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] ) +{ + int i; + + uint32_t a, b, c, d; + ARIA_VALIDATE_RET( ctx != NULL ); + ARIA_VALIDATE_RET( input != NULL ); + ARIA_VALIDATE_RET( output != NULL ); + + a = MBEDTLS_GET_UINT32_LE( input, 0 ); + b = MBEDTLS_GET_UINT32_LE( input, 4 ); + c = MBEDTLS_GET_UINT32_LE( input, 8 ); + d = MBEDTLS_GET_UINT32_LE( input, 12 ); + + i = 0; + while( 1 ) + { + a ^= ctx->rk[i][0]; + b ^= ctx->rk[i][1]; + c ^= ctx->rk[i][2]; + d ^= ctx->rk[i][3]; + i++; + + aria_sl( &a, &b, &c, &d, aria_sb1, aria_sb2, aria_is1, aria_is2 ); + aria_a( &a, &b, &c, &d ); + + a ^= ctx->rk[i][0]; + b ^= ctx->rk[i][1]; + c ^= ctx->rk[i][2]; + d ^= ctx->rk[i][3]; + i++; + + aria_sl( &a, &b, &c, &d, aria_is1, aria_is2, aria_sb1, aria_sb2 ); + if( i >= ctx->nr ) + break; + aria_a( &a, &b, &c, &d ); + } + + /* final key mixing */ + a ^= ctx->rk[i][0]; + b ^= ctx->rk[i][1]; + c ^= ctx->rk[i][2]; + d ^= ctx->rk[i][3]; + + MBEDTLS_PUT_UINT32_LE( a, output, 0 ); + MBEDTLS_PUT_UINT32_LE( b, output, 4 ); + MBEDTLS_PUT_UINT32_LE( c, output, 8 ); + MBEDTLS_PUT_UINT32_LE( d, output, 12 ); + + return( 0 ); +} + +/* Initialize context */ +void mbedtls_aria_init( mbedtls_aria_context *ctx ) +{ + ARIA_VALIDATE( ctx != NULL ); + memset( ctx, 0, sizeof( mbedtls_aria_context ) ); +} + +/* Clear context */ +void mbedtls_aria_free( mbedtls_aria_context *ctx ) +{ + if( ctx == NULL ) + return; + + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_aria_context ) ); +} + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +/* + * ARIA-CBC buffer encryption/decryption + */ +int mbedtls_aria_crypt_cbc( mbedtls_aria_context *ctx, + int mode, + size_t length, + unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ) +{ + int i; + unsigned char temp[MBEDTLS_ARIA_BLOCKSIZE]; + + ARIA_VALIDATE_RET( ctx != NULL ); + ARIA_VALIDATE_RET( mode == MBEDTLS_ARIA_ENCRYPT || + mode == MBEDTLS_ARIA_DECRYPT ); + ARIA_VALIDATE_RET( length == 0 || input != NULL ); + ARIA_VALIDATE_RET( length == 0 || output != NULL ); + ARIA_VALIDATE_RET( iv != NULL ); + + if( length % MBEDTLS_ARIA_BLOCKSIZE ) + return( MBEDTLS_ERR_ARIA_INVALID_INPUT_LENGTH ); + + if( mode == MBEDTLS_ARIA_DECRYPT ) + { + while( length > 0 ) + { + memcpy( temp, input, MBEDTLS_ARIA_BLOCKSIZE ); + mbedtls_aria_crypt_ecb( ctx, input, output ); + + for( i = 0; i < MBEDTLS_ARIA_BLOCKSIZE; i++ ) + output[i] = (unsigned char)( output[i] ^ iv[i] ); + + memcpy( iv, temp, MBEDTLS_ARIA_BLOCKSIZE ); + + input += MBEDTLS_ARIA_BLOCKSIZE; + output += MBEDTLS_ARIA_BLOCKSIZE; + length -= MBEDTLS_ARIA_BLOCKSIZE; + } + } + else + { + while( length > 0 ) + { + for( i = 0; i < MBEDTLS_ARIA_BLOCKSIZE; i++ ) + output[i] = (unsigned char)( input[i] ^ iv[i] ); + + mbedtls_aria_crypt_ecb( ctx, output, output ); + memcpy( iv, output, MBEDTLS_ARIA_BLOCKSIZE ); + + input += MBEDTLS_ARIA_BLOCKSIZE; + output += MBEDTLS_ARIA_BLOCKSIZE; + length -= MBEDTLS_ARIA_BLOCKSIZE; + } + } + + return( 0 ); +} +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CFB) +/* + * ARIA-CFB128 buffer encryption/decryption + */ +int mbedtls_aria_crypt_cfb128( mbedtls_aria_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ) +{ + unsigned char c; + size_t n; + + ARIA_VALIDATE_RET( ctx != NULL ); + ARIA_VALIDATE_RET( mode == MBEDTLS_ARIA_ENCRYPT || + mode == MBEDTLS_ARIA_DECRYPT ); + ARIA_VALIDATE_RET( length == 0 || input != NULL ); + ARIA_VALIDATE_RET( length == 0 || output != NULL ); + ARIA_VALIDATE_RET( iv != NULL ); + ARIA_VALIDATE_RET( iv_off != NULL ); + + n = *iv_off; + + /* An overly large value of n can lead to an unlimited + * buffer overflow. Therefore, guard against this + * outside of parameter validation. */ + if( n >= MBEDTLS_ARIA_BLOCKSIZE ) + return( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ); + + if( mode == MBEDTLS_ARIA_DECRYPT ) + { + while( length-- ) + { + if( n == 0 ) + mbedtls_aria_crypt_ecb( ctx, iv, iv ); + + c = *input++; + *output++ = c ^ iv[n]; + iv[n] = c; + + n = ( n + 1 ) & 0x0F; + } + } + else + { + while( length-- ) + { + if( n == 0 ) + mbedtls_aria_crypt_ecb( ctx, iv, iv ); + + iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); + + n = ( n + 1 ) & 0x0F; + } + } + + *iv_off = n; + + return( 0 ); +} +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +/* + * ARIA-CTR buffer encryption/decryption + */ +int mbedtls_aria_crypt_ctr( mbedtls_aria_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[MBEDTLS_ARIA_BLOCKSIZE], + unsigned char stream_block[MBEDTLS_ARIA_BLOCKSIZE], + const unsigned char *input, + unsigned char *output ) +{ + int c, i; + size_t n; + + ARIA_VALIDATE_RET( ctx != NULL ); + ARIA_VALIDATE_RET( length == 0 || input != NULL ); + ARIA_VALIDATE_RET( length == 0 || output != NULL ); + ARIA_VALIDATE_RET( nonce_counter != NULL ); + ARIA_VALIDATE_RET( stream_block != NULL ); + ARIA_VALIDATE_RET( nc_off != NULL ); + + n = *nc_off; + /* An overly large value of n can lead to an unlimited + * buffer overflow. Therefore, guard against this + * outside of parameter validation. */ + if( n >= MBEDTLS_ARIA_BLOCKSIZE ) + return( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA ); + + while( length-- ) + { + if( n == 0 ) { + mbedtls_aria_crypt_ecb( ctx, nonce_counter, + stream_block ); + + for( i = MBEDTLS_ARIA_BLOCKSIZE; i > 0; i-- ) + if( ++nonce_counter[i - 1] != 0 ) + break; + } + c = *input++; + *output++ = (unsigned char)( c ^ stream_block[n] ); + + n = ( n + 1 ) & 0x0F; + } + + *nc_off = n; + + return( 0 ); +} +#endif /* MBEDTLS_CIPHER_MODE_CTR */ +#endif /* !MBEDTLS_ARIA_ALT */ + +#if defined(MBEDTLS_SELF_TEST) + +/* + * Basic ARIA ECB test vectors from RFC 5794 + */ +static const uint8_t aria_test1_ecb_key[32] = // test key +{ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // 128 bit + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, // 192 bit + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F // 256 bit +}; + +static const uint8_t aria_test1_ecb_pt[MBEDTLS_ARIA_BLOCKSIZE] = // plaintext +{ + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, // same for all + 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF // key sizes +}; + +static const uint8_t aria_test1_ecb_ct[3][MBEDTLS_ARIA_BLOCKSIZE] = // ciphertext +{ + { 0xD7, 0x18, 0xFB, 0xD6, 0xAB, 0x64, 0x4C, 0x73, // 128 bit + 0x9D, 0xA9, 0x5F, 0x3B, 0xE6, 0x45, 0x17, 0x78 }, + { 0x26, 0x44, 0x9C, 0x18, 0x05, 0xDB, 0xE7, 0xAA, // 192 bit + 0x25, 0xA4, 0x68, 0xCE, 0x26, 0x3A, 0x9E, 0x79 }, + { 0xF9, 0x2B, 0xD7, 0xC7, 0x9F, 0xB7, 0x2E, 0x2F, // 256 bit + 0x2B, 0x8F, 0x80, 0xC1, 0x97, 0x2D, 0x24, 0xFC } +}; + +/* + * Mode tests from "Test Vectors for ARIA" Version 1.0 + * http://210.104.33.10/ARIA/doc/ARIA-testvector-e.pdf + */ +#if (defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB) || \ + defined(MBEDTLS_CIPHER_MODE_CTR)) +static const uint8_t aria_test2_key[32] = +{ + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, // 128 bit + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, // 192 bit + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff // 256 bit +}; + +static const uint8_t aria_test2_pt[48] = +{ + 0x11, 0x11, 0x11, 0x11, 0xaa, 0xaa, 0xaa, 0xaa, // same for all + 0x11, 0x11, 0x11, 0x11, 0xbb, 0xbb, 0xbb, 0xbb, + 0x11, 0x11, 0x11, 0x11, 0xcc, 0xcc, 0xcc, 0xcc, + 0x11, 0x11, 0x11, 0x11, 0xdd, 0xdd, 0xdd, 0xdd, + 0x22, 0x22, 0x22, 0x22, 0xaa, 0xaa, 0xaa, 0xaa, + 0x22, 0x22, 0x22, 0x22, 0xbb, 0xbb, 0xbb, 0xbb, +}; +#endif + +#if (defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB)) +static const uint8_t aria_test2_iv[MBEDTLS_ARIA_BLOCKSIZE] = +{ + 0x0f, 0x1e, 0x2d, 0x3c, 0x4b, 0x5a, 0x69, 0x78, // same for CBC, CFB + 0x87, 0x96, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0 // CTR has zero IV +}; +#endif + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +static const uint8_t aria_test2_cbc_ct[3][48] = // CBC ciphertext +{ + { 0x49, 0xd6, 0x18, 0x60, 0xb1, 0x49, 0x09, 0x10, // 128-bit key + 0x9c, 0xef, 0x0d, 0x22, 0xa9, 0x26, 0x81, 0x34, + 0xfa, 0xdf, 0x9f, 0xb2, 0x31, 0x51, 0xe9, 0x64, + 0x5f, 0xba, 0x75, 0x01, 0x8b, 0xdb, 0x15, 0x38, + 0xb5, 0x33, 0x34, 0x63, 0x4b, 0xbf, 0x7d, 0x4c, + 0xd4, 0xb5, 0x37, 0x70, 0x33, 0x06, 0x0c, 0x15 }, + { 0xaf, 0xe6, 0xcf, 0x23, 0x97, 0x4b, 0x53, 0x3c, // 192-bit key + 0x67, 0x2a, 0x82, 0x62, 0x64, 0xea, 0x78, 0x5f, + 0x4e, 0x4f, 0x7f, 0x78, 0x0d, 0xc7, 0xf3, 0xf1, + 0xe0, 0x96, 0x2b, 0x80, 0x90, 0x23, 0x86, 0xd5, + 0x14, 0xe9, 0xc3, 0xe7, 0x72, 0x59, 0xde, 0x92, + 0xdd, 0x11, 0x02, 0xff, 0xab, 0x08, 0x6c, 0x1e }, + { 0x52, 0x3a, 0x8a, 0x80, 0x6a, 0xe6, 0x21, 0xf1, // 256-bit key + 0x55, 0xfd, 0xd2, 0x8d, 0xbc, 0x34, 0xe1, 0xab, + 0x7b, 0x9b, 0x42, 0x43, 0x2a, 0xd8, 0xb2, 0xef, + 0xb9, 0x6e, 0x23, 0xb1, 0x3f, 0x0a, 0x6e, 0x52, + 0xf3, 0x61, 0x85, 0xd5, 0x0a, 0xd0, 0x02, 0xc5, + 0xf6, 0x01, 0xbe, 0xe5, 0x49, 0x3f, 0x11, 0x8b } +}; +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CFB) +static const uint8_t aria_test2_cfb_ct[3][48] = // CFB ciphertext +{ + { 0x37, 0x20, 0xe5, 0x3b, 0xa7, 0xd6, 0x15, 0x38, // 128-bit key + 0x34, 0x06, 0xb0, 0x9f, 0x0a, 0x05, 0xa2, 0x00, + 0xc0, 0x7c, 0x21, 0xe6, 0x37, 0x0f, 0x41, 0x3a, + 0x5d, 0x13, 0x25, 0x00, 0xa6, 0x82, 0x85, 0x01, + 0x7c, 0x61, 0xb4, 0x34, 0xc7, 0xb7, 0xca, 0x96, + 0x85, 0xa5, 0x10, 0x71, 0x86, 0x1e, 0x4d, 0x4b }, + { 0x41, 0x71, 0xf7, 0x19, 0x2b, 0xf4, 0x49, 0x54, // 192-bit key + 0x94, 0xd2, 0x73, 0x61, 0x29, 0x64, 0x0f, 0x5c, + 0x4d, 0x87, 0xa9, 0xa2, 0x13, 0x66, 0x4c, 0x94, + 0x48, 0x47, 0x7c, 0x6e, 0xcc, 0x20, 0x13, 0x59, + 0x8d, 0x97, 0x66, 0x95, 0x2d, 0xd8, 0xc3, 0x86, + 0x8f, 0x17, 0xe3, 0x6e, 0xf6, 0x6f, 0xd8, 0x4b }, + { 0x26, 0x83, 0x47, 0x05, 0xb0, 0xf2, 0xc0, 0xe2, // 256-bit key + 0x58, 0x8d, 0x4a, 0x7f, 0x09, 0x00, 0x96, 0x35, + 0xf2, 0x8b, 0xb9, 0x3d, 0x8c, 0x31, 0xf8, 0x70, + 0xec, 0x1e, 0x0b, 0xdb, 0x08, 0x2b, 0x66, 0xfa, + 0x40, 0x2d, 0xd9, 0xc2, 0x02, 0xbe, 0x30, 0x0c, + 0x45, 0x17, 0xd1, 0x96, 0xb1, 0x4d, 0x4c, 0xe1 } +}; +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +static const uint8_t aria_test2_ctr_ct[3][48] = // CTR ciphertext +{ + { 0xac, 0x5d, 0x7d, 0xe8, 0x05, 0xa0, 0xbf, 0x1c, // 128-bit key + 0x57, 0xc8, 0x54, 0x50, 0x1a, 0xf6, 0x0f, 0xa1, + 0x14, 0x97, 0xe2, 0xa3, 0x45, 0x19, 0xde, 0xa1, + 0x56, 0x9e, 0x91, 0xe5, 0xb5, 0xcc, 0xae, 0x2f, + 0xf3, 0xbf, 0xa1, 0xbf, 0x97, 0x5f, 0x45, 0x71, + 0xf4, 0x8b, 0xe1, 0x91, 0x61, 0x35, 0x46, 0xc3 }, + { 0x08, 0x62, 0x5c, 0xa8, 0xfe, 0x56, 0x9c, 0x19, // 192-bit key + 0xba, 0x7a, 0xf3, 0x76, 0x0a, 0x6e, 0xd1, 0xce, + 0xf4, 0xd1, 0x99, 0x26, 0x3e, 0x99, 0x9d, 0xde, + 0x14, 0x08, 0x2d, 0xbb, 0xa7, 0x56, 0x0b, 0x79, + 0xa4, 0xc6, 0xb4, 0x56, 0xb8, 0x70, 0x7d, 0xce, + 0x75, 0x1f, 0x98, 0x54, 0xf1, 0x88, 0x93, 0xdf }, + { 0x30, 0x02, 0x6c, 0x32, 0x96, 0x66, 0x14, 0x17, // 256-bit key + 0x21, 0x17, 0x8b, 0x99, 0xc0, 0xa1, 0xf1, 0xb2, + 0xf0, 0x69, 0x40, 0x25, 0x3f, 0x7b, 0x30, 0x89, + 0xe2, 0xa3, 0x0e, 0xa8, 0x6a, 0xa3, 0xc8, 0x8f, + 0x59, 0x40, 0xf0, 0x5a, 0xd7, 0xee, 0x41, 0xd7, + 0x13, 0x47, 0xbb, 0x72, 0x61, 0xe3, 0x48, 0xf1 } +}; +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#define ARIA_SELF_TEST_IF_FAIL \ + { \ + if( verbose ) \ + mbedtls_printf( "failed\n" ); \ + goto exit; \ + } else { \ + if( verbose ) \ + mbedtls_printf( "passed\n" ); \ + } + +/* + * Checkup routine + */ +int mbedtls_aria_self_test( int verbose ) +{ + int i; + uint8_t blk[MBEDTLS_ARIA_BLOCKSIZE]; + mbedtls_aria_context ctx; + int ret = 1; + +#if (defined(MBEDTLS_CIPHER_MODE_CFB) || defined(MBEDTLS_CIPHER_MODE_CTR)) + size_t j; +#endif + +#if (defined(MBEDTLS_CIPHER_MODE_CBC) || \ + defined(MBEDTLS_CIPHER_MODE_CFB) || \ + defined(MBEDTLS_CIPHER_MODE_CTR)) + uint8_t buf[48], iv[MBEDTLS_ARIA_BLOCKSIZE]; +#endif + + mbedtls_aria_init( &ctx ); + + /* + * Test set 1 + */ + for( i = 0; i < 3; i++ ) + { + /* test ECB encryption */ + if( verbose ) + mbedtls_printf( " ARIA-ECB-%d (enc): ", 128 + 64 * i ); + mbedtls_aria_setkey_enc( &ctx, aria_test1_ecb_key, 128 + 64 * i ); + mbedtls_aria_crypt_ecb( &ctx, aria_test1_ecb_pt, blk ); + if( memcmp( blk, aria_test1_ecb_ct[i], MBEDTLS_ARIA_BLOCKSIZE ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + + /* test ECB decryption */ + if( verbose ) + mbedtls_printf( " ARIA-ECB-%d (dec): ", 128 + 64 * i ); + mbedtls_aria_setkey_dec( &ctx, aria_test1_ecb_key, 128 + 64 * i ); + mbedtls_aria_crypt_ecb( &ctx, aria_test1_ecb_ct[i], blk ); + if( memcmp( blk, aria_test1_ecb_pt, MBEDTLS_ARIA_BLOCKSIZE ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + } + if( verbose ) + mbedtls_printf( "\n" ); + + /* + * Test set 2 + */ +#if defined(MBEDTLS_CIPHER_MODE_CBC) + for( i = 0; i < 3; i++ ) + { + /* Test CBC encryption */ + if( verbose ) + mbedtls_printf( " ARIA-CBC-%d (enc): ", 128 + 64 * i ); + mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i ); + memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE ); + memset( buf, 0x55, sizeof( buf ) ); + mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, 48, iv, + aria_test2_pt, buf ); + if( memcmp( buf, aria_test2_cbc_ct[i], 48 ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + + /* Test CBC decryption */ + if( verbose ) + mbedtls_printf( " ARIA-CBC-%d (dec): ", 128 + 64 * i ); + mbedtls_aria_setkey_dec( &ctx, aria_test2_key, 128 + 64 * i ); + memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE ); + memset( buf, 0xAA, sizeof( buf ) ); + mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, 48, iv, + aria_test2_cbc_ct[i], buf ); + if( memcmp( buf, aria_test2_pt, 48 ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + } + if( verbose ) + mbedtls_printf( "\n" ); + +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CFB) + for( i = 0; i < 3; i++ ) + { + /* Test CFB encryption */ + if( verbose ) + mbedtls_printf( " ARIA-CFB-%d (enc): ", 128 + 64 * i ); + mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i ); + memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE ); + memset( buf, 0x55, sizeof( buf ) ); + j = 0; + mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, 48, &j, iv, + aria_test2_pt, buf ); + if( memcmp( buf, aria_test2_cfb_ct[i], 48 ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + + /* Test CFB decryption */ + if( verbose ) + mbedtls_printf( " ARIA-CFB-%d (dec): ", 128 + 64 * i ); + mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i ); + memcpy( iv, aria_test2_iv, MBEDTLS_ARIA_BLOCKSIZE ); + memset( buf, 0xAA, sizeof( buf ) ); + j = 0; + mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, 48, &j, + iv, aria_test2_cfb_ct[i], buf ); + if( memcmp( buf, aria_test2_pt, 48 ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + } + if( verbose ) + mbedtls_printf( "\n" ); +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) + for( i = 0; i < 3; i++ ) + { + /* Test CTR encryption */ + if( verbose ) + mbedtls_printf( " ARIA-CTR-%d (enc): ", 128 + 64 * i ); + mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i ); + memset( iv, 0, MBEDTLS_ARIA_BLOCKSIZE ); // IV = 0 + memset( buf, 0x55, sizeof( buf ) ); + j = 0; + mbedtls_aria_crypt_ctr( &ctx, 48, &j, iv, blk, + aria_test2_pt, buf ); + if( memcmp( buf, aria_test2_ctr_ct[i], 48 ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + + /* Test CTR decryption */ + if( verbose ) + mbedtls_printf( " ARIA-CTR-%d (dec): ", 128 + 64 * i ); + mbedtls_aria_setkey_enc( &ctx, aria_test2_key, 128 + 64 * i ); + memset( iv, 0, MBEDTLS_ARIA_BLOCKSIZE ); // IV = 0 + memset( buf, 0xAA, sizeof( buf ) ); + j = 0; + mbedtls_aria_crypt_ctr( &ctx, 48, &j, iv, blk, + aria_test2_ctr_ct[i], buf ); + if( memcmp( buf, aria_test2_pt, 48 ) != 0 ) + ARIA_SELF_TEST_IF_FAIL; + } + if( verbose ) + mbedtls_printf( "\n" ); +#endif /* MBEDTLS_CIPHER_MODE_CTR */ + + ret = 0; + +exit: + mbedtls_aria_free( &ctx ); + return( ret ); +} + +#endif /* MBEDTLS_SELF_TEST */ + +#endif /* MBEDTLS_ARIA_C */ diff --git a/src/duckdb/third_party/mbedtls/library/asn1parse.cpp b/src/duckdb/third_party/mbedtls/library/asn1parse.cpp index 2e30f6bf0..bf7e195e7 100644 --- a/src/duckdb/third_party/mbedtls/library/asn1parse.cpp +++ b/src/duckdb/third_party/mbedtls/library/asn1parse.cpp @@ -2,13 +2,24 @@ * Generic ASN.1 parsing * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" -#if defined(MBEDTLS_ASN1_PARSE_C) || defined(MBEDTLS_X509_CREATE_C) || \ - defined(MBEDTLS_PSA_UTIL_HAVE_ECDSA) +#if defined(MBEDTLS_ASN1_PARSE_C) #include "mbedtls/asn1.h" #include "mbedtls/platform_util.h" @@ -20,197 +31,214 @@ #include "mbedtls/bignum.h" #endif +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#include +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif /* * ASN.1 DER decoding routines */ -int mbedtls_asn1_get_len(unsigned char **p, - const unsigned char *end, - size_t *len) +int mbedtls_asn1_get_len( unsigned char **p, + const unsigned char *end, + size_t *len ) { - if ((end - *p) < 1) { - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } + if( ( end - *p ) < 1 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); - if ((**p & 0x80) == 0) { + if( ( **p & 0x80 ) == 0 ) *len = *(*p)++; - } else { - int n = (**p) & 0x7F; - if (n == 0 || n > 4) { - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } - if ((end - *p) <= n) { - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } - *len = 0; - (*p)++; - while (n--) { - *len = (*len << 8) | **p; - (*p)++; + else + { + switch( **p & 0x7F ) + { + case 1: + if( ( end - *p ) < 2 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + + *len = (*p)[1]; + (*p) += 2; + break; + + case 2: + if( ( end - *p ) < 3 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + + *len = ( (size_t)(*p)[1] << 8 ) | (*p)[2]; + (*p) += 3; + break; + + case 3: + if( ( end - *p ) < 4 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + + *len = ( (size_t)(*p)[1] << 16 ) | + ( (size_t)(*p)[2] << 8 ) | (*p)[3]; + (*p) += 4; + break; + + case 4: + if( ( end - *p ) < 5 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); + + *len = ( (size_t)(*p)[1] << 24 ) | ( (size_t)(*p)[2] << 16 ) | + ( (size_t)(*p)[3] << 8 ) | (*p)[4]; + (*p) += 5; + break; + + default: + return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); } } - if (*len > (size_t) (end - *p)) { - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } + if( *len > (size_t) ( end - *p ) ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); - return 0; + return( 0 ); } -int mbedtls_asn1_get_tag(unsigned char **p, - const unsigned char *end, - size_t *len, int tag) +int mbedtls_asn1_get_tag( unsigned char **p, + const unsigned char *end, + size_t *len, int tag ) { - if ((end - *p) < 1) { - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } + if( ( end - *p ) < 1 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); - if (**p != tag) { - return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG; - } + if( **p != tag ) + return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ); (*p)++; - return mbedtls_asn1_get_len(p, end, len); + return( mbedtls_asn1_get_len( p, end, len ) ); } -#endif /* MBEDTLS_ASN1_PARSE_C || MBEDTLS_X509_CREATE_C || MBEDTLS_PSA_UTIL_HAVE_ECDSA */ -#if defined(MBEDTLS_ASN1_PARSE_C) -int mbedtls_asn1_get_bool(unsigned char **p, - const unsigned char *end, - int *val) +int mbedtls_asn1_get_bool( unsigned char **p, + const unsigned char *end, + int *val ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t len; - if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_BOOLEAN)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_BOOLEAN ) ) != 0 ) + return( ret ); - if (len != 1) { - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } + if( len != 1 ) + return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); - *val = (**p != 0) ? 1 : 0; + *val = ( **p != 0 ) ? 1 : 0; (*p)++; - return 0; + return( 0 ); } -static int asn1_get_tagged_int(unsigned char **p, - const unsigned char *end, - int tag, int *val) +static int asn1_get_tagged_int( unsigned char **p, + const unsigned char *end, + int tag, int *val ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t len; - if ((ret = mbedtls_asn1_get_tag(p, end, &len, tag)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, tag ) ) != 0 ) + return( ret ); /* * len==0 is malformed (0 must be represented as 020100 for INTEGER, * or 0A0100 for ENUMERATED tags */ - if (len == 0) { - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } + if( len == 0 ) + return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); /* This is a cryptography library. Reject negative integers. */ - if ((**p & 0x80) != 0) { - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } + if( ( **p & 0x80 ) != 0 ) + return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); /* Skip leading zeros. */ - while (len > 0 && **p == 0) { - ++(*p); + while( len > 0 && **p == 0 ) + { + ++( *p ); --len; } /* Reject integers that don't fit in an int. This code assumes that * the int type has no padding bit. */ - if (len > sizeof(int)) { - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } - if (len == sizeof(int) && (**p & 0x80) != 0) { - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } + if( len > sizeof( int ) ) + return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); + if( len == sizeof( int ) && ( **p & 0x80 ) != 0 ) + return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); *val = 0; - while (len-- > 0) { - *val = (*val << 8) | **p; + while( len-- > 0 ) + { + *val = ( *val << 8 ) | **p; (*p)++; } - return 0; + return( 0 ); } -int mbedtls_asn1_get_int(unsigned char **p, - const unsigned char *end, - int *val) +int mbedtls_asn1_get_int( unsigned char **p, + const unsigned char *end, + int *val ) { - return asn1_get_tagged_int(p, end, MBEDTLS_ASN1_INTEGER, val); + return( asn1_get_tagged_int( p, end, MBEDTLS_ASN1_INTEGER, val) ); } -int mbedtls_asn1_get_enum(unsigned char **p, - const unsigned char *end, - int *val) +int mbedtls_asn1_get_enum( unsigned char **p, + const unsigned char *end, + int *val ) { - return asn1_get_tagged_int(p, end, MBEDTLS_ASN1_ENUMERATED, val); + return( asn1_get_tagged_int( p, end, MBEDTLS_ASN1_ENUMERATED, val) ); } #if defined(MBEDTLS_BIGNUM_C) -int mbedtls_asn1_get_mpi(unsigned char **p, - const unsigned char *end, - mbedtls_mpi *X) +int mbedtls_asn1_get_mpi( unsigned char **p, + const unsigned char *end, + mbedtls_mpi *X ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t len; - if ((ret = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) + return( ret ); - ret = mbedtls_mpi_read_binary(X, *p, len); + ret = mbedtls_mpi_read_binary( X, *p, len ); *p += len; - return ret; + return( ret ); } #endif /* MBEDTLS_BIGNUM_C */ -int mbedtls_asn1_get_bitstring(unsigned char **p, const unsigned char *end, - mbedtls_asn1_bitstring *bs) +int mbedtls_asn1_get_bitstring( unsigned char **p, const unsigned char *end, + mbedtls_asn1_bitstring *bs) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; /* Certificate type is a single byte bitstring */ - if ((ret = mbedtls_asn1_get_tag(p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( p, end, &bs->len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 ) + return( ret ); /* Check length, subtract one for actual bit string length */ - if (bs->len < 1) { - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } + if( bs->len < 1 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); bs->len -= 1; /* Get number of unused bits, ensure unused bits <= 7 */ bs->unused_bits = **p; - if (bs->unused_bits > 7) { - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } + if( bs->unused_bits > 7 ) + return( MBEDTLS_ERR_ASN1_INVALID_LENGTH ); (*p)++; /* Get actual bitstring */ bs->p = *p; *p += bs->len; - if (*p != end) { - return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH; - } + if( *p != end ) + return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); - return 0; + return( 0 ); } /* @@ -222,105 +250,105 @@ int mbedtls_asn1_traverse_sequence_of( const unsigned char *end, unsigned char tag_must_mask, unsigned char tag_must_val, unsigned char tag_may_mask, unsigned char tag_may_val, - int (*cb)(void *ctx, int tag, - unsigned char *start, size_t len), - void *ctx) + int (*cb)( void *ctx, int tag, + unsigned char *start, size_t len ), + void *ctx ) { int ret; size_t len; /* Get main sequence tag */ - if ((ret = mbedtls_asn1_get_tag(p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return ret; + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + { + return( ret ); } - if (*p + len != end) { - return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH; - } + if( *p + len != end ) + return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); - while (*p < end) { + while( *p < end ) + { unsigned char const tag = *(*p)++; - if ((tag & tag_must_mask) != tag_must_val) { - return MBEDTLS_ERR_ASN1_UNEXPECTED_TAG; - } + if( ( tag & tag_must_mask ) != tag_must_val ) + return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ); - if ((ret = mbedtls_asn1_get_len(p, end, &len)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_len( p, end, &len ) ) != 0 ) + return( ret ); - if ((tag & tag_may_mask) == tag_may_val) { - if (cb != NULL) { - ret = cb(ctx, tag, *p, len); - if (ret != 0) { - return ret; - } + if( ( tag & tag_may_mask ) == tag_may_val ) + { + if( cb != NULL ) + { + ret = cb( ctx, tag, *p, len ); + if( ret != 0 ) + return( ret ); } } *p += len; } - return 0; + return( 0 ); } /* * Get a bit string without unused bits */ -int mbedtls_asn1_get_bitstring_null(unsigned char **p, const unsigned char *end, - size_t *len) +int mbedtls_asn1_get_bitstring_null( unsigned char **p, const unsigned char *end, + size_t *len ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - if ((ret = mbedtls_asn1_get_tag(p, end, len, MBEDTLS_ASN1_BIT_STRING)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( p, end, len, MBEDTLS_ASN1_BIT_STRING ) ) != 0 ) + return( ret ); - if (*len == 0) { - return MBEDTLS_ERR_ASN1_INVALID_DATA; - } - --(*len); + if( *len == 0 ) + return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + --( *len ); - if (**p != 0) { - return MBEDTLS_ERR_ASN1_INVALID_DATA; - } - ++(*p); + if( **p != 0 ) + return( MBEDTLS_ERR_ASN1_INVALID_DATA ); + ++( *p ); - return 0; + return( 0 ); } -void mbedtls_asn1_sequence_free(mbedtls_asn1_sequence *seq) +void mbedtls_asn1_sequence_free( mbedtls_asn1_sequence *seq ) { - while (seq != NULL) { + while( seq != NULL ) + { mbedtls_asn1_sequence *next = seq->next; - mbedtls_free(seq); + mbedtls_platform_zeroize( seq, sizeof( *seq ) ); + mbedtls_free( seq ); seq = next; } } -typedef struct { +typedef struct +{ int tag; mbedtls_asn1_sequence *cur; } asn1_get_sequence_of_cb_ctx_t; -static int asn1_get_sequence_of_cb(void *ctx, - int tag, - unsigned char *start, - size_t len) +static int asn1_get_sequence_of_cb( void *ctx, + int tag, + unsigned char *start, + size_t len ) { asn1_get_sequence_of_cb_ctx_t *cb_ctx = (asn1_get_sequence_of_cb_ctx_t *) ctx; mbedtls_asn1_sequence *cur = cb_ctx->cur; - if (cur->buf.p != NULL) { - cur->next = (struct mbedtls_asn1_sequence *) - mbedtls_calloc(1, sizeof(mbedtls_asn1_sequence)); + if( cur->buf.p != NULL ) + { + cur->next = + (struct mbedtls_asn1_sequence *) mbedtls_calloc( 1, sizeof( mbedtls_asn1_sequence ) ); - if (cur->next == NULL) { - return MBEDTLS_ERR_ASN1_ALLOC_FAILED; - } + if( cur->next == NULL ) + return( MBEDTLS_ERR_ASN1_ALLOC_FAILED ); cur = cur->next; } @@ -330,139 +358,124 @@ static int asn1_get_sequence_of_cb(void *ctx, cur->buf.tag = tag; cb_ctx->cur = cur; - return 0; + return( 0 ); } /* * Parses and splits an ASN.1 "SEQUENCE OF " */ -int mbedtls_asn1_get_sequence_of(unsigned char **p, - const unsigned char *end, - mbedtls_asn1_sequence *cur, - int tag) +int mbedtls_asn1_get_sequence_of( unsigned char **p, + const unsigned char *end, + mbedtls_asn1_sequence *cur, + int tag) { asn1_get_sequence_of_cb_ctx_t cb_ctx = { tag, cur }; - memset(cur, 0, sizeof(mbedtls_asn1_sequence)); - return mbedtls_asn1_traverse_sequence_of( - p, end, 0xFF, tag, 0, 0, - asn1_get_sequence_of_cb, &cb_ctx); + memset( cur, 0, sizeof( mbedtls_asn1_sequence ) ); + return( mbedtls_asn1_traverse_sequence_of( + p, end, 0xFF, tag, 0, 0, + asn1_get_sequence_of_cb, &cb_ctx ) ); } -int mbedtls_asn1_get_alg(unsigned char **p, - const unsigned char *end, - mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params) +int mbedtls_asn1_get_alg( unsigned char **p, + const unsigned char *end, + mbedtls_asn1_buf *alg, mbedtls_asn1_buf *params ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t len; - if ((ret = mbedtls_asn1_get_tag(p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + return( ret ); - if ((end - *p) < 1) { - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } + if( ( end - *p ) < 1 ) + return( MBEDTLS_ERR_ASN1_OUT_OF_DATA ); alg->tag = **p; end = *p + len; - if ((ret = mbedtls_asn1_get_tag(p, end, &alg->len, MBEDTLS_ASN1_OID)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( p, end, &alg->len, MBEDTLS_ASN1_OID ) ) != 0 ) + return( ret ); alg->p = *p; *p += alg->len; - if (*p == end) { - mbedtls_platform_zeroize(params, sizeof(mbedtls_asn1_buf)); - return 0; + if( *p == end ) + { + mbedtls_platform_zeroize( params, sizeof(mbedtls_asn1_buf) ); + return( 0 ); } params->tag = **p; (*p)++; - if ((ret = mbedtls_asn1_get_len(p, end, ¶ms->len)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_len( p, end, ¶ms->len ) ) != 0 ) + return( ret ); params->p = *p; *p += params->len; - if (*p != end) { - return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH; - } + if( *p != end ) + return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); - return 0; + return( 0 ); } -int mbedtls_asn1_get_alg_null(unsigned char **p, - const unsigned char *end, - mbedtls_asn1_buf *alg) +int mbedtls_asn1_get_alg_null( unsigned char **p, + const unsigned char *end, + mbedtls_asn1_buf *alg ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_asn1_buf params; - memset(¶ms, 0, sizeof(mbedtls_asn1_buf)); + memset( ¶ms, 0, sizeof(mbedtls_asn1_buf) ); - if ((ret = mbedtls_asn1_get_alg(p, end, alg, ¶ms)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_alg( p, end, alg, ¶ms ) ) != 0 ) + return( ret ); - if ((params.tag != MBEDTLS_ASN1_NULL && params.tag != 0) || params.len != 0) { - return MBEDTLS_ERR_ASN1_INVALID_DATA; - } + if( ( params.tag != MBEDTLS_ASN1_NULL && params.tag != 0 ) || params.len != 0 ) + return( MBEDTLS_ERR_ASN1_INVALID_DATA ); - return 0; + return( 0 ); } -#if !defined(MBEDTLS_DEPRECATED_REMOVED) -void mbedtls_asn1_free_named_data(mbedtls_asn1_named_data *cur) +void mbedtls_asn1_free_named_data( mbedtls_asn1_named_data *cur ) { - if (cur == NULL) { + if( cur == NULL ) return; - } - mbedtls_free(cur->oid.p); - mbedtls_free(cur->val.p); + mbedtls_free( cur->oid.p ); + mbedtls_free( cur->val.p ); - mbedtls_platform_zeroize(cur, sizeof(mbedtls_asn1_named_data)); + mbedtls_platform_zeroize( cur, sizeof( mbedtls_asn1_named_data ) ); } -#endif /* MBEDTLS_DEPRECATED_REMOVED */ -void mbedtls_asn1_free_named_data_list(mbedtls_asn1_named_data **head) +void mbedtls_asn1_free_named_data_list( mbedtls_asn1_named_data **head ) { mbedtls_asn1_named_data *cur; - while ((cur = *head) != NULL) { + while( ( cur = *head ) != NULL ) + { *head = cur->next; - mbedtls_free(cur->oid.p); - mbedtls_free(cur->val.p); - mbedtls_free(cur); - } -} - -void mbedtls_asn1_free_named_data_list_shallow(mbedtls_asn1_named_data *name) -{ - for (mbedtls_asn1_named_data *next; name != NULL; name = next) { - next = name->next; - mbedtls_free(name); + mbedtls_asn1_free_named_data( cur ); + mbedtls_free( cur ); } } -const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data(const mbedtls_asn1_named_data *list, - const char *oid, size_t len) +const mbedtls_asn1_named_data *mbedtls_asn1_find_named_data( const mbedtls_asn1_named_data *list, + const char *oid, size_t len ) { - while (list != NULL) { - if (list->oid.len == len && - memcmp(list->oid.p, oid, len) == 0) { + while( list != NULL ) + { + if( list->oid.len == len && + memcmp( list->oid.p, oid, len ) == 0 ) + { break; } list = list->next; } - return list; + return( list ); } #endif /* MBEDTLS_ASN1_PARSE_C */ diff --git a/src/duckdb/third_party/mbedtls/library/base64.cpp b/src/duckdb/third_party/mbedtls/library/base64.cpp index 9677dee5b..83daa0bcc 100644 --- a/src/duckdb/third_party/mbedtls/library/base64.cpp +++ b/src/duckdb/third_party/mbedtls/library/base64.cpp @@ -2,131 +2,117 @@ * RFC 1521 base64 encoding/decoding * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -#include - #include "common.h" #if defined(MBEDTLS_BASE64_C) #include "mbedtls/base64.h" -#include "base64_internal.h" #include "constant_time_internal.h" #include #if defined(MBEDTLS_SELF_TEST) #include +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#include +#define mbedtls_printf printf +#endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_SELF_TEST */ -MBEDTLS_STATIC_TESTABLE -unsigned char mbedtls_ct_base64_enc_char(unsigned char value) -{ - unsigned char digit = 0; - /* For each range of values, if value is in that range, mask digit with - * the corresponding value. Since value can only be in a single range, - * only at most one masking will change digit. */ - digit |= mbedtls_ct_uchar_in_range_if(0, 25, value, 'A' + value); - digit |= mbedtls_ct_uchar_in_range_if(26, 51, value, 'a' + value - 26); - digit |= mbedtls_ct_uchar_in_range_if(52, 61, value, '0' + value - 52); - digit |= mbedtls_ct_uchar_in_range_if(62, 62, value, '+'); - digit |= mbedtls_ct_uchar_in_range_if(63, 63, value, '/'); - return digit; -} - -MBEDTLS_STATIC_TESTABLE -signed char mbedtls_ct_base64_dec_value(unsigned char c) -{ - unsigned char val = 0; - /* For each range of digits, if c is in that range, mask val with - * the corresponding value. Since c can only be in a single range, - * only at most one masking will change val. Set val to one plus - * the desired value so that it stays 0 if c is in none of the ranges. */ - val |= mbedtls_ct_uchar_in_range_if('A', 'Z', c, c - 'A' + 0 + 1); - val |= mbedtls_ct_uchar_in_range_if('a', 'z', c, c - 'a' + 26 + 1); - val |= mbedtls_ct_uchar_in_range_if('0', '9', c, c - '0' + 52 + 1); - val |= mbedtls_ct_uchar_in_range_if('+', '+', c, c - '+' + 62 + 1); - val |= mbedtls_ct_uchar_in_range_if('/', '/', c, c - '/' + 63 + 1); - /* At this point, val is 0 if c is an invalid digit and v+1 if c is - * a digit with the value v. */ - return val - 1; -} +#define BASE64_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */ /* * Encode a buffer into base64 format */ -int mbedtls_base64_encode(unsigned char *dst, size_t dlen, size_t *olen, - const unsigned char *src, size_t slen) +int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen, + const unsigned char *src, size_t slen ) { size_t i, n; int C1, C2, C3; unsigned char *p; - if (slen == 0) { + if( slen == 0 ) + { *olen = 0; - return 0; + return( 0 ); } - n = slen / 3 + (slen % 3 != 0); + n = slen / 3 + ( slen % 3 != 0 ); - if (n > (SIZE_MAX - 1) / 4) { - *olen = SIZE_MAX; - return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL; + if( n > ( BASE64_SIZE_T_MAX - 1 ) / 4 ) + { + *olen = BASE64_SIZE_T_MAX; + return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); } n *= 4; - if ((dlen < n + 1) || (NULL == dst)) { + if( ( dlen < n + 1 ) || ( NULL == dst ) ) + { *olen = n + 1; - return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL; + return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); } - n = (slen / 3) * 3; + n = ( slen / 3 ) * 3; - for (i = 0, p = dst; i < n; i += 3) { + for( i = 0, p = dst; i < n; i += 3 ) + { C1 = *src++; C2 = *src++; C3 = *src++; - *p++ = mbedtls_ct_base64_enc_char((C1 >> 2) & 0x3F); - *p++ = mbedtls_ct_base64_enc_char((((C1 & 3) << 4) + (C2 >> 4)) - & 0x3F); - *p++ = mbedtls_ct_base64_enc_char((((C2 & 15) << 2) + (C3 >> 6)) - & 0x3F); - *p++ = mbedtls_ct_base64_enc_char(C3 & 0x3F); + *p++ = mbedtls_ct_base64_enc_char( ( C1 >> 2 ) & 0x3F ); + *p++ = mbedtls_ct_base64_enc_char( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) ) + & 0x3F ); + *p++ = mbedtls_ct_base64_enc_char( ( ( ( C2 & 15 ) << 2 ) + ( C3 >> 6 ) ) + & 0x3F ); + *p++ = mbedtls_ct_base64_enc_char( C3 & 0x3F ); } - if (i < slen) { + if( i < slen ) + { C1 = *src++; - C2 = ((i + 1) < slen) ? *src++ : 0; + C2 = ( ( i + 1 ) < slen ) ? *src++ : 0; - *p++ = mbedtls_ct_base64_enc_char((C1 >> 2) & 0x3F); - *p++ = mbedtls_ct_base64_enc_char((((C1 & 3) << 4) + (C2 >> 4)) - & 0x3F); + *p++ = mbedtls_ct_base64_enc_char( ( C1 >> 2 ) & 0x3F ); + *p++ = mbedtls_ct_base64_enc_char( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) ) + & 0x3F ); - if ((i + 1) < slen) { - *p++ = mbedtls_ct_base64_enc_char(((C2 & 15) << 2) & 0x3F); - } else { - *p++ = '='; - } + if( ( i + 1 ) < slen ) + *p++ = mbedtls_ct_base64_enc_char( ( ( C2 & 15 ) << 2 ) & 0x3F ); + else *p++ = '='; *p++ = '='; } - *olen = (size_t) (p - dst); + *olen = p - dst; *p = 0; - return 0; + return( 0 ); } /* * Decode a base64-formatted buffer */ -int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen, - const unsigned char *src, size_t slen) +int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen, + const unsigned char *src, size_t slen ) { size_t i; /* index in source */ size_t n; /* number of digits or trailing = in source */ @@ -137,97 +123,92 @@ int mbedtls_base64_decode(unsigned char *dst, size_t dlen, size_t *olen, unsigned char *p; /* First pass: check for validity and get output length */ - for (i = n = 0; i < slen; i++) { + for( i = n = 0; i < slen; i++ ) + { /* Skip spaces before checking for EOL */ spaces_present = 0; - while (i < slen && src[i] == ' ') { + while( i < slen && src[i] == ' ' ) + { ++i; spaces_present = 1; } /* Spaces at end of buffer are OK */ - if (i == slen) { + if( i == slen ) break; - } - if ((slen - i) >= 2 && - src[i] == '\r' && src[i + 1] == '\n') { + if( ( slen - i ) >= 2 && + src[i] == '\r' && src[i + 1] == '\n' ) continue; - } - if (src[i] == '\n') { + if( src[i] == '\n' ) continue; - } /* Space inside a line is an error */ - if (spaces_present) { - return MBEDTLS_ERR_BASE64_INVALID_CHARACTER; - } + if( spaces_present ) + return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); - if (src[i] > 127) { - return MBEDTLS_ERR_BASE64_INVALID_CHARACTER; - } + if( src[i] > 127 ) + return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); - if (src[i] == '=') { - if (++equals > 2) { - return MBEDTLS_ERR_BASE64_INVALID_CHARACTER; - } - } else { - if (equals != 0) { - return MBEDTLS_ERR_BASE64_INVALID_CHARACTER; - } - if (mbedtls_ct_base64_dec_value(src[i]) < 0) { - return MBEDTLS_ERR_BASE64_INVALID_CHARACTER; - } + if( src[i] == '=' ) + { + if( ++equals > 2 ) + return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); + } + else + { + if( equals != 0 ) + return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); + if( mbedtls_ct_base64_dec_value( src[i] ) < 0 ) + return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER ); } n++; } - if (n == 0) { + if( n == 0 ) + { *olen = 0; - return 0; + return( 0 ); } /* The following expression is to calculate the following formula without * risk of integer overflow in n: * n = ( ( n * 6 ) + 7 ) >> 3; */ - n = (6 * (n >> 3)) + ((6 * (n & 0x7) + 7) >> 3); + n = ( 6 * ( n >> 3 ) ) + ( ( 6 * ( n & 0x7 ) + 7 ) >> 3 ); n -= equals; - if (dst == NULL || dlen < n) { + if( dst == NULL || dlen < n ) + { *olen = n; - return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL; + return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); } equals = 0; - for (x = 0, p = dst; i > 0; i--, src++) { - if (*src == '\r' || *src == '\n' || *src == ' ') { + for( x = 0, p = dst; i > 0; i--, src++ ) + { + if( *src == '\r' || *src == '\n' || *src == ' ' ) continue; - } x = x << 6; - if (*src == '=') { + if( *src == '=' ) ++equals; - } else { - x |= mbedtls_ct_base64_dec_value(*src); - } + else + x |= mbedtls_ct_base64_dec_value( *src ); - if (++accumulated_digits == 4) { + if( ++accumulated_digits == 4 ) + { accumulated_digits = 0; - *p++ = MBEDTLS_BYTE_2(x); - if (equals <= 1) { - *p++ = MBEDTLS_BYTE_1(x); - } - if (equals <= 0) { - *p++ = MBEDTLS_BYTE_0(x); - } + *p++ = MBEDTLS_BYTE_2( x ); + if( equals <= 1 ) *p++ = MBEDTLS_BYTE_1( x ); + if( equals <= 0 ) *p++ = MBEDTLS_BYTE_0( x ); } } - *olen = (size_t) (p - dst); + *olen = p - dst; - return 0; + return( 0 ); } #if defined(MBEDTLS_SELF_TEST) @@ -251,47 +232,44 @@ static const unsigned char base64_test_enc[] = /* * Checkup routine */ -int mbedtls_base64_self_test(int verbose) +int mbedtls_base64_self_test( int verbose ) { size_t len; const unsigned char *src; unsigned char buffer[128]; - if (verbose != 0) { - mbedtls_printf(" Base64 encoding test: "); - } + if( verbose != 0 ) + mbedtls_printf( " Base64 encoding test: " ); src = base64_test_dec; - if (mbedtls_base64_encode(buffer, sizeof(buffer), &len, src, 64) != 0 || - memcmp(base64_test_enc, buffer, 88) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_base64_encode( buffer, sizeof( buffer ), &len, src, 64 ) != 0 || + memcmp( base64_test_enc, buffer, 88 ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); - return 1; + return( 1 ); } - if (verbose != 0) { - mbedtls_printf("passed\n Base64 decoding test: "); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n Base64 decoding test: " ); src = base64_test_enc; - if (mbedtls_base64_decode(buffer, sizeof(buffer), &len, src, 88) != 0 || - memcmp(base64_test_dec, buffer, 64) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_base64_decode( buffer, sizeof( buffer ), &len, src, 88 ) != 0 || + memcmp( base64_test_dec, buffer, 64 ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); - return 1; + return( 1 ); } - if (verbose != 0) { - mbedtls_printf("passed\n\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n\n" ); - return 0; + return( 0 ); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/library/bignum.cpp b/src/duckdb/third_party/mbedtls/library/bignum.cpp index 1c0f55c8e..d4b51ca57 100644 --- a/src/duckdb/third_party/mbedtls/library/bignum.cpp +++ b/src/duckdb/third_party/mbedtls/library/bignum.cpp @@ -2,7 +2,19 @@ * Multi-precision integer library * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* @@ -26,8 +38,6 @@ #if defined(MBEDTLS_BIGNUM_C) #include "mbedtls/bignum.h" -#include "bignum_core.h" -#include "bignum_internal.h" #include "bn_mul.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" @@ -36,150 +46,47 @@ #include #include +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" - - - -/* - * Conditionally select an MPI sign in constant time. - * (MPI sign is the field s in mbedtls_mpi. It is unsigned short and only 1 and -1 are valid - * values.) - */ -inline signed short mbedtls_ct_mpi_sign_if(mbedtls_ct_condition_t cond, - signed short sign1, signed short sign2) -{ - return (signed short) mbedtls_ct_uint_if(cond, sign1 + 1, sign2 + 1) - 1; -} - -/* - * Compare signed values in constant time - */ -int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X, - const mbedtls_mpi *Y, - unsigned *ret) -{ - mbedtls_ct_condition_t different_sign, X_is_negative, Y_is_negative, result; - - if (X->n != Y->n) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } - - /* - * Set N_is_negative to MBEDTLS_CT_FALSE if N >= 0, MBEDTLS_CT_TRUE if N < 0. - * We know that N->s == 1 if N >= 0 and N->s == -1 if N < 0. - */ - X_is_negative = mbedtls_ct_bool((X->s & 2) >> 1); - Y_is_negative = mbedtls_ct_bool((Y->s & 2) >> 1); - - /* - * If the signs are different, then the positive operand is the bigger. - * That is if X is negative (X_is_negative == 1), then X < Y is true and it - * is false if X is positive (X_is_negative == 0). - */ - different_sign = mbedtls_ct_bool_ne(X_is_negative, Y_is_negative); // true if different sign - result = mbedtls_ct_bool_and(different_sign, X_is_negative); - - /* - * Assuming signs are the same, compare X and Y. We switch the comparison - * order if they are negative so that we get the right result, regardles of - * sign. - */ - - /* This array is used to conditionally swap the pointers in const time */ - void * const p[2] = { X->p, Y->p }; - size_t i = mbedtls_ct_size_if_else_0(X_is_negative, 1); - mbedtls_ct_condition_t lt = mbedtls_mpi_core_lt_ct((const mbedtls_mpi_uint *)p[i], (const mbedtls_mpi_uint *)p[i ^ 1], X->n); - - /* - * Store in result iff the signs are the same (i.e., iff different_sign == false). If - * the signs differ, result has already been set, so we don't change it. - */ - result = mbedtls_ct_bool_or(result, - mbedtls_ct_bool_and(mbedtls_ct_bool_not(different_sign), lt)); - - *ret = mbedtls_ct_uint_if_else_0(result, 1); - - return 0; -} - -/* - * Conditionally assign X = Y, without leaking information - * about whether the assignment was made or not. - * (Leaking information about the respective sizes of X and Y is ok however.) - */ -#if defined(_MSC_VER) && defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) && \ - (_MSC_FULL_VER < 193131103) -/* - * MSVC miscompiles this function if it's inlined prior to Visual Studio 2022 version 17.1. See: - * https://developercommunity.visualstudio.com/t/c-compiler-miscompiles-part-of-mbedtls-library-on/1646989 - */ -__declspec(noinline) +#else +#include +#include +#define mbedtls_printf printf +#define mbedtls_calloc calloc +#define mbedtls_free free #endif -int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X, - const mbedtls_mpi *Y, - unsigned char assign) -{ - int ret = 0; - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n)); +#define MPI_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA ) +#define MPI_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) - { - mbedtls_ct_condition_t do_assign = mbedtls_ct_bool(assign); +#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */ +#define biL (ciL << 3) /* bits in limb */ +#define biH (ciL << 2) /* half limb size */ - X->s = mbedtls_ct_mpi_sign_if(do_assign, Y->s, X->s); - - mbedtls_mpi_core_cond_assign(X->p, Y->p, Y->n, do_assign); - - mbedtls_ct_condition_t do_not_assign = mbedtls_ct_bool_not(do_assign); - for (size_t i = Y->n; i < X->n; i++) { - X->p[i] = mbedtls_ct_mpi_uint_if_else_0(do_not_assign, X->p[i]); - } - } - -cleanup: - return ret; -} +#define MPI_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */ /* - * Conditionally swap X and Y, without leaking information - * about whether the swap was made or not. - * Here it is not ok to simply swap the pointers, which would lead to - * different memory access patterns when X and Y are used afterwards. + * Convert between bits/chars and number of limbs + * Divide first in order to avoid potential overflows */ -int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X, - mbedtls_mpi *Y, - unsigned char swap) -{ - int ret = 0; - int s; - - if (X == Y) { - return 0; - } - - mbedtls_ct_condition_t do_swap = mbedtls_ct_bool(swap); - - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, Y->n)); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(Y, X->n)); - - s = X->s; - X->s = mbedtls_ct_mpi_sign_if(do_swap, Y->s, X->s); - Y->s = mbedtls_ct_mpi_sign_if(do_swap, s, Y->s); - - mbedtls_mpi_core_cond_swap(X->p, Y->p, X->n, do_swap); - -cleanup: - return ret; -} +#define BITS_TO_LIMBS(i) ( (i) / biL + ( (i) % biL != 0 ) ) +#define CHARS_TO_LIMBS(i) ( (i) / ciL + ( (i) % ciL != 0 ) ) /* Implementation that should never be optimized out by the compiler */ -#define mbedtls_mpi_zeroize_and_free(v, n) mbedtls_zeroize_and_free(v, ciL * (n)) +static void mbedtls_mpi_zeroize( mbedtls_mpi_uint *v, size_t n ) +{ + mbedtls_platform_zeroize( v, ciL * n ); +} /* * Initialize one MPI */ -void mbedtls_mpi_init(mbedtls_mpi *X) +void mbedtls_mpi_init( mbedtls_mpi *X ) { + MPI_VALIDATE( X != NULL ); + X->s = 1; X->n = 0; X->p = NULL; @@ -188,14 +95,15 @@ void mbedtls_mpi_init(mbedtls_mpi *X) /* * Unallocate one MPI */ -void mbedtls_mpi_free(mbedtls_mpi *X) +void mbedtls_mpi_free( mbedtls_mpi *X ) { - if (X == NULL) { + if( X == NULL ) return; - } - if (X->p != NULL) { - mbedtls_mpi_zeroize_and_free(X->p, X->n); + if( X->p != NULL ) + { + mbedtls_mpi_zeroize( X->p, X->n ); + mbedtls_free( X->p ); } X->s = 1; @@ -206,93 +114,93 @@ void mbedtls_mpi_free(mbedtls_mpi *X) /* * Enlarge to the specified number of limbs */ -int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs) +int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs ) { mbedtls_mpi_uint *p; + MPI_VALIDATE_RET( X != NULL ); - if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) { - return MBEDTLS_ERR_MPI_ALLOC_FAILED; - } - - if (X->n < nblimbs) { - if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(nblimbs, ciL)) == NULL) { - return MBEDTLS_ERR_MPI_ALLOC_FAILED; - } + if( nblimbs > MBEDTLS_MPI_MAX_LIMBS ) + return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); - if (X->p != NULL) { - memcpy(p, X->p, X->n * ciL); - mbedtls_mpi_zeroize_and_free(X->p, X->n); + if( X->n < nblimbs ) + { + if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( nblimbs, ciL ) ) == NULL ) + return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); + + if( X->p != NULL ) + { + memcpy( p, X->p, X->n * ciL ); + mbedtls_mpi_zeroize( X->p, X->n ); + mbedtls_free( X->p ); } - /* nblimbs fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS - * fits, and we've checked that nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */ - X->n = (unsigned short) nblimbs; + X->n = nblimbs; X->p = p; } - return 0; + return( 0 ); } /* * Resize down as much as possible, * while keeping at least the specified number of limbs */ -int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs) +int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs ) { mbedtls_mpi_uint *p; size_t i; + MPI_VALIDATE_RET( X != NULL ); - if (nblimbs > MBEDTLS_MPI_MAX_LIMBS) { - return MBEDTLS_ERR_MPI_ALLOC_FAILED; - } + if( nblimbs > MBEDTLS_MPI_MAX_LIMBS ) + return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); /* Actually resize up if there are currently fewer than nblimbs limbs. */ - if (X->n <= nblimbs) { - return mbedtls_mpi_grow(X, nblimbs); - } + if( X->n <= nblimbs ) + return( mbedtls_mpi_grow( X, nblimbs ) ); /* After this point, then X->n > nblimbs and in particular X->n > 0. */ - for (i = X->n - 1; i > 0; i--) { - if (X->p[i] != 0) { + for( i = X->n - 1; i > 0; i-- ) + if( X->p[i] != 0 ) break; - } - } i++; - if (i < nblimbs) { + if( i < nblimbs ) i = nblimbs; - } - if ((p = (mbedtls_mpi_uint *) mbedtls_calloc(i, ciL)) == NULL) { - return MBEDTLS_ERR_MPI_ALLOC_FAILED; - } + if( ( p = (mbedtls_mpi_uint*)mbedtls_calloc( i, ciL ) ) == NULL ) + return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); - if (X->p != NULL) { - memcpy(p, X->p, i * ciL); - mbedtls_mpi_zeroize_and_free(X->p, X->n); + if( X->p != NULL ) + { + memcpy( p, X->p, i * ciL ); + mbedtls_mpi_zeroize( X->p, X->n ); + mbedtls_free( X->p ); } - /* i fits in n because we ensure that MBEDTLS_MPI_MAX_LIMBS - * fits, and we've checked that i <= nblimbs <= MBEDTLS_MPI_MAX_LIMBS. */ - X->n = (unsigned short) i; + X->n = i; X->p = p; - return 0; + return( 0 ); } /* Resize X to have exactly n limbs and set it to 0. */ -static int mbedtls_mpi_resize_clear(mbedtls_mpi *X, size_t limbs) +static int mbedtls_mpi_resize_clear( mbedtls_mpi *X, size_t limbs ) { - if (limbs == 0) { - mbedtls_mpi_free(X); - return 0; - } else if (X->n == limbs) { - memset(X->p, 0, limbs * ciL); + if( limbs == 0 ) + { + mbedtls_mpi_free( X ); + return( 0 ); + } + else if( X->n == limbs ) + { + memset( X->p, 0, limbs * ciL ); X->s = 1; - return 0; - } else { - mbedtls_mpi_free(X); - return mbedtls_mpi_grow(X, limbs); + return( 0 ); + } + else + { + mbedtls_mpi_free( X ); + return( mbedtls_mpi_grow( X, limbs ) ); } } @@ -302,402 +210,410 @@ static int mbedtls_mpi_resize_clear(mbedtls_mpi *X, size_t limbs) * This function is not constant-time. Leading zeros in Y may be removed. * * Ensure that X does not shrink. This is not guaranteed by the public API, - * but some code in the bignum module might still rely on this property. + * but some code in the bignum module relies on this property, for example + * in mbedtls_mpi_exp_mod(). */ -int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y) +int mbedtls_mpi_copy( mbedtls_mpi *X, const mbedtls_mpi *Y ) { int ret = 0; size_t i; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( Y != NULL ); - if (X == Y) { - return 0; - } + if( X == Y ) + return( 0 ); - if (Y->n == 0) { - if (X->n != 0) { + if( Y->n == 0 ) + { + if( X->n != 0 ) + { X->s = 1; - memset(X->p, 0, X->n * ciL); + memset( X->p, 0, X->n * ciL ); } - return 0; + return( 0 ); } - for (i = Y->n - 1; i > 0; i--) { - if (Y->p[i] != 0) { + for( i = Y->n - 1; i > 0; i-- ) + if( Y->p[i] != 0 ) break; - } - } i++; X->s = Y->s; - if (X->n < i) { - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i)); - } else { - memset(X->p + i, 0, (X->n - i) * ciL); + if( X->n < i ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i ) ); + } + else + { + memset( X->p + i, 0, ( X->n - i ) * ciL ); } - memcpy(X->p, Y->p, i * ciL); + memcpy( X->p, Y->p, i * ciL ); cleanup: - return ret; + return( ret ); } /* * Swap the contents of X and Y */ -void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y) +void mbedtls_mpi_swap( mbedtls_mpi *X, mbedtls_mpi *Y ) { mbedtls_mpi T; + MPI_VALIDATE( X != NULL ); + MPI_VALIDATE( Y != NULL ); - memcpy(&T, X, sizeof(mbedtls_mpi)); - memcpy(X, Y, sizeof(mbedtls_mpi)); - memcpy(Y, &T, sizeof(mbedtls_mpi)); -} - -inline mbedtls_mpi_uint mpi_sint_abs(mbedtls_mpi_sint z) -{ - if (z >= 0) { - return z; - } - /* Take care to handle the most negative value (-2^(biL-1)) correctly. - * A naive -z would have undefined behavior. - * Write this in a way that makes popular compilers happy (GCC, Clang, - * MSVC). */ - return (mbedtls_mpi_uint) 0 - (mbedtls_mpi_uint) z; + memcpy( &T, X, sizeof( mbedtls_mpi ) ); + memcpy( X, Y, sizeof( mbedtls_mpi ) ); + memcpy( Y, &T, sizeof( mbedtls_mpi ) ); } -/* Convert x to a sign, i.e. to 1, if x is positive, or -1, if x is negative. - * This looks awkward but generates smaller code than (x < 0 ? -1 : 1) */ -#define TO_SIGN(x) ((mbedtls_mpi_sint) (((mbedtls_mpi_uint) x) >> (biL - 1)) * -2 + 1) - /* * Set value from integer */ -int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z) +int mbedtls_mpi_lset( mbedtls_mpi *X, mbedtls_mpi_sint z ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + MPI_VALIDATE_RET( X != NULL ); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, 1)); - memset(X->p, 0, X->n * ciL); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, 1 ) ); + memset( X->p, 0, X->n * ciL ); - X->p[0] = mpi_sint_abs(z); - X->s = TO_SIGN(z); + X->p[0] = ( z < 0 ) ? -z : z; + X->s = ( z < 0 ) ? -1 : 1; cleanup: - return ret; + return( ret ); } /* * Get a specific bit */ -int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos) +int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos ) { - if (X->n * biL <= pos) { - return 0; - } + MPI_VALIDATE_RET( X != NULL ); + + if( X->n * biL <= pos ) + return( 0 ); - return (X->p[pos / biL] >> (pos % biL)) & 0x01; + return( ( X->p[pos / biL] >> ( pos % biL ) ) & 0x01 ); } +/* Get a specific byte, without range checks. */ +#define GET_BYTE( X, i ) \ + ( ( ( X )->p[( i ) / ciL] >> ( ( ( i ) % ciL ) * 8 ) ) & 0xff ) + /* * Set a bit to a specific value of 0 or 1 */ -int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val) +int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val ) { int ret = 0; size_t off = pos / biL; size_t idx = pos % biL; + MPI_VALIDATE_RET( X != NULL ); - if (val != 0 && val != 1) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + if( val != 0 && val != 1 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - if (X->n * biL <= pos) { - if (val == 0) { - return 0; - } + if( X->n * biL <= pos ) + { + if( val == 0 ) + return( 0 ); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, off + 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, off + 1 ) ); } - X->p[off] &= ~((mbedtls_mpi_uint) 0x01 << idx); + X->p[off] &= ~( (mbedtls_mpi_uint) 0x01 << idx ); X->p[off] |= (mbedtls_mpi_uint) val << idx; cleanup: - return ret; + return( ret ); } /* * Return the number of less significant zero-bits */ -size_t mbedtls_mpi_lsb(const mbedtls_mpi *X) +size_t mbedtls_mpi_lsb( const mbedtls_mpi *X ) { - size_t i; + size_t i, j, count = 0; + MBEDTLS_INTERNAL_VALIDATE_RET( X != NULL, 0 ); -#if defined(__has_builtin) -#if (MBEDTLS_MPI_UINT_MAX == UINT_MAX) && __has_builtin(__builtin_ctz) - #define mbedtls_mpi_uint_ctz __builtin_ctz -#elif (MBEDTLS_MPI_UINT_MAX == ULONG_MAX) && __has_builtin(__builtin_ctzl) - #define mbedtls_mpi_uint_ctz __builtin_ctzl -#elif (MBEDTLS_MPI_UINT_MAX == ULLONG_MAX) && __has_builtin(__builtin_ctzll) - #define mbedtls_mpi_uint_ctz __builtin_ctzll -#endif -#endif + for( i = 0; i < X->n; i++ ) + for( j = 0; j < biL; j++, count++ ) + if( ( ( X->p[i] >> j ) & 1 ) != 0 ) + return( count ); -#if defined(mbedtls_mpi_uint_ctz) - for (i = 0; i < X->n; i++) { - if (X->p[i] != 0) { - return i * biL + mbedtls_mpi_uint_ctz(X->p[i]); - } - } -#else - size_t count = 0; - for (i = 0; i < X->n; i++) { - for (size_t j = 0; j < biL; j++, count++) { - if (((X->p[i] >> j) & 1) != 0) { - return count; - } - } + return( 0 ); +} + +/* + * Count leading zero bits in a given integer + */ +static size_t mbedtls_clz( const mbedtls_mpi_uint x ) +{ + size_t j; + mbedtls_mpi_uint mask = (mbedtls_mpi_uint) 1 << (biL - 1); + + for( j = 0; j < biL; j++ ) + { + if( x & mask ) break; + + mask >>= 1; } -#endif - return 0; + return j; } /* * Return the number of bits */ -size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X) +size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X ) { - return mbedtls_mpi_core_bitlen(X->p, X->n); + size_t i, j; + + if( X->n == 0 ) + return( 0 ); + + for( i = X->n - 1; i > 0; i-- ) + if( X->p[i] != 0 ) + break; + + j = biL - mbedtls_clz( X->p[i] ); + + return( ( i * biL ) + j ); } /* * Return the total size in bytes */ -size_t mbedtls_mpi_size(const mbedtls_mpi *X) +size_t mbedtls_mpi_size( const mbedtls_mpi *X ) { - return (mbedtls_mpi_bitlen(X) + 7) >> 3; + return( ( mbedtls_mpi_bitlen( X ) + 7 ) >> 3 ); } /* * Convert an ASCII character to digit value */ -static int mpi_get_digit(mbedtls_mpi_uint *d, int radix, char c) +static int mpi_get_digit( mbedtls_mpi_uint *d, int radix, char c ) { *d = 255; - if (c >= 0x30 && c <= 0x39) { - *d = c - 0x30; - } - if (c >= 0x41 && c <= 0x46) { - *d = c - 0x37; - } - if (c >= 0x61 && c <= 0x66) { - *d = c - 0x57; - } + if( c >= 0x30 && c <= 0x39 ) *d = c - 0x30; + if( c >= 0x41 && c <= 0x46 ) *d = c - 0x37; + if( c >= 0x61 && c <= 0x66 ) *d = c - 0x57; - if (*d >= (mbedtls_mpi_uint) radix) { - return MBEDTLS_ERR_MPI_INVALID_CHARACTER; - } + if( *d >= (mbedtls_mpi_uint) radix ) + return( MBEDTLS_ERR_MPI_INVALID_CHARACTER ); - return 0; + return( 0 ); } /* * Import from an ASCII string */ -int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s) +int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t i, j, slen, n; int sign = 1; mbedtls_mpi_uint d; mbedtls_mpi T; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( s != NULL ); - if (radix < 2 || radix > 16) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + if( radix < 2 || radix > 16 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - mbedtls_mpi_init(&T); + mbedtls_mpi_init( &T ); - if (s[0] == 0) { - mbedtls_mpi_free(X); - return 0; + if( s[0] == 0 ) + { + mbedtls_mpi_free( X ); + return( 0 ); } - if (s[0] == '-') { + if( s[0] == '-' ) + { ++s; sign = -1; } - slen = strlen(s); + slen = strlen( s ); - if (radix == 16) { - if (slen > SIZE_MAX >> 2) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + if( radix == 16 ) + { + if( slen > MPI_SIZE_T_MAX >> 2 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - n = BITS_TO_LIMBS(slen << 2); + n = BITS_TO_LIMBS( slen << 2 ); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n)); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0)); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, n ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) ); - for (i = slen, j = 0; i > 0; i--, j++) { - MBEDTLS_MPI_CHK(mpi_get_digit(&d, radix, s[i - 1])); - X->p[j / (2 * ciL)] |= d << ((j % (2 * ciL)) << 2); + for( i = slen, j = 0; i > 0; i--, j++ ) + { + MBEDTLS_MPI_CHK( mpi_get_digit( &d, radix, s[i - 1] ) ); + X->p[j / ( 2 * ciL )] |= d << ( ( j % ( 2 * ciL ) ) << 2 ); } - } else { - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0)); + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) ); - for (i = 0; i < slen; i++) { - MBEDTLS_MPI_CHK(mpi_get_digit(&d, radix, s[i])); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T, X, radix)); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X, &T, d)); + for( i = 0; i < slen; i++ ) + { + MBEDTLS_MPI_CHK( mpi_get_digit( &d, radix, s[i] ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_int( &T, X, radix ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( X, &T, d ) ); } } - if (sign < 0 && mbedtls_mpi_bitlen(X) != 0) { + if( sign < 0 && mbedtls_mpi_bitlen( X ) != 0 ) X->s = -1; - } cleanup: - mbedtls_mpi_free(&T); + mbedtls_mpi_free( &T ); - return ret; + return( ret ); } /* * Helper to write the digits high-order first. */ -static int mpi_write_hlp(mbedtls_mpi *X, int radix, - char **p, const size_t buflen) +static int mpi_write_hlp( mbedtls_mpi *X, int radix, + char **p, const size_t buflen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi_uint r; size_t length = 0; char *p_end = *p + buflen; - do { - if (length >= buflen) { - return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL; + do + { + if( length >= buflen ) + { + return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); } - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_int(&r, X, radix)); - MBEDTLS_MPI_CHK(mbedtls_mpi_div_int(X, NULL, X, radix)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, radix ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_int( X, NULL, X, radix ) ); /* * Write the residue in the current position, as an ASCII character. */ - if (r < 0xA) { - *(--p_end) = (char) ('0' + r); - } else { - *(--p_end) = (char) ('A' + (r - 0xA)); - } + if( r < 0xA ) + *(--p_end) = (char)( '0' + r ); + else + *(--p_end) = (char)( 'A' + ( r - 0xA ) ); length++; - } while (mbedtls_mpi_cmp_int(X, 0) != 0); + } while( mbedtls_mpi_cmp_int( X, 0 ) != 0 ); - memmove(*p, p_end, length); + memmove( *p, p_end, length ); *p += length; cleanup: - return ret; + return( ret ); } /* * Export into an ASCII string */ -int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix, - char *buf, size_t buflen, size_t *olen) +int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix, + char *buf, size_t buflen, size_t *olen ) { int ret = 0; size_t n; char *p; mbedtls_mpi T; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( olen != NULL ); + MPI_VALIDATE_RET( buflen == 0 || buf != NULL ); - if (radix < 2 || radix > 16) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + if( radix < 2 || radix > 16 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - n = mbedtls_mpi_bitlen(X); /* Number of bits necessary to present `n`. */ - if (radix >= 4) { - n >>= 1; /* Number of 4-adic digits necessary to present + n = mbedtls_mpi_bitlen( X ); /* Number of bits necessary to present `n`. */ + if( radix >= 4 ) n >>= 1; /* Number of 4-adic digits necessary to present * `n`. If radix > 4, this might be a strict * overapproximation of the number of * radix-adic digits needed to present `n`. */ - } - if (radix >= 16) { - n >>= 1; /* Number of hexadecimal digits necessary to + if( radix >= 16 ) n >>= 1; /* Number of hexadecimal digits necessary to * present `n`. */ - } n += 1; /* Terminating null byte */ n += 1; /* Compensate for the divisions above, which round down `n` * in case it's not even. */ n += 1; /* Potential '-'-sign. */ - n += (n & 1); /* Make n even to have enough space for hexadecimal writing, + n += ( n & 1 ); /* Make n even to have enough space for hexadecimal writing, * which always uses an even number of hex-digits. */ - if (buflen < n) { + if( buflen < n ) + { *olen = n; - return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL; + return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); } p = buf; - mbedtls_mpi_init(&T); + mbedtls_mpi_init( &T ); - if (X->s == -1) { + if( X->s == -1 ) + { *p++ = '-'; buflen--; } - if (radix == 16) { + if( radix == 16 ) + { int c; size_t i, j, k; - for (i = X->n, k = 0; i > 0; i--) { - for (j = ciL; j > 0; j--) { - c = (X->p[i - 1] >> ((j - 1) << 3)) & 0xFF; + for( i = X->n, k = 0; i > 0; i-- ) + { + for( j = ciL; j > 0; j-- ) + { + c = ( X->p[i - 1] >> ( ( j - 1 ) << 3) ) & 0xFF; - if (c == 0 && k == 0 && (i + j) != 2) { + if( c == 0 && k == 0 && ( i + j ) != 2 ) continue; - } *(p++) = "0123456789ABCDEF" [c / 16]; *(p++) = "0123456789ABCDEF" [c % 16]; k = 1; } } - } else { - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&T, X)); + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &T, X ) ); - if (T.s == -1) { + if( T.s == -1 ) T.s = 1; - } - MBEDTLS_MPI_CHK(mpi_write_hlp(&T, radix, &p, buflen)); + MBEDTLS_MPI_CHK( mpi_write_hlp( &T, radix, &p, buflen ) ); } *p++ = '\0'; - *olen = (size_t) (p - buf); + *olen = p - buf; cleanup: - mbedtls_mpi_free(&T); + mbedtls_mpi_free( &T ); - return ret; + return( ret ); } #if defined(MBEDTLS_FS_IO) /* * Read X from an opened file */ -int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin) +int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin ) { mbedtls_mpi_uint d; size_t slen; @@ -706,43 +622,37 @@ int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin) * Buffer should have space for (short) label and decimal formatted MPI, * newline characters and '\0' */ - char s[MBEDTLS_MPI_RW_BUFFER_SIZE]; + char s[ MBEDTLS_MPI_RW_BUFFER_SIZE ]; - if (radix < 2 || radix > 16) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( fin != NULL ); - memset(s, 0, sizeof(s)); - if (fgets(s, sizeof(s) - 1, fin) == NULL) { - return MBEDTLS_ERR_MPI_FILE_IO_ERROR; - } + if( radix < 2 || radix > 16 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - slen = strlen(s); - if (slen == sizeof(s) - 2) { - return MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL; - } + memset( s, 0, sizeof( s ) ); + if( fgets( s, sizeof( s ) - 1, fin ) == NULL ) + return( MBEDTLS_ERR_MPI_FILE_IO_ERROR ); - if (slen > 0 && s[slen - 1] == '\n') { - slen--; s[slen] = '\0'; - } - if (slen > 0 && s[slen - 1] == '\r') { - slen--; s[slen] = '\0'; - } + slen = strlen( s ); + if( slen == sizeof( s ) - 2 ) + return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + + if( slen > 0 && s[slen - 1] == '\n' ) { slen--; s[slen] = '\0'; } + if( slen > 0 && s[slen - 1] == '\r' ) { slen--; s[slen] = '\0'; } p = s + slen; - while (p-- > s) { - if (mpi_get_digit(&d, radix, *p) != 0) { + while( p-- > s ) + if( mpi_get_digit( &d, radix, *p ) != 0 ) break; - } - } - return mbedtls_mpi_read_string(X, radix, p + 1); + return( mbedtls_mpi_read_string( X, radix, p + 1 ) ); } /* * Write X into an opened file (or stdout if fout == NULL) */ -int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, int radix, FILE *fout) +int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X, int radix, FILE *fout ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t n, slen, plen; @@ -750,56 +660,144 @@ int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, int radix, FILE * Buffer should have space for (short) label and decimal formatted MPI, * newline characters and '\0' */ - char s[MBEDTLS_MPI_RW_BUFFER_SIZE]; + char s[ MBEDTLS_MPI_RW_BUFFER_SIZE ]; + MPI_VALIDATE_RET( X != NULL ); - if (radix < 2 || radix > 16) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + if( radix < 2 || radix > 16 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - memset(s, 0, sizeof(s)); + memset( s, 0, sizeof( s ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_write_string(X, radix, s, sizeof(s) - 2, &n)); + MBEDTLS_MPI_CHK( mbedtls_mpi_write_string( X, radix, s, sizeof( s ) - 2, &n ) ); - if (p == NULL) { - p = ""; - } + if( p == NULL ) p = ""; - plen = strlen(p); - slen = strlen(s); + plen = strlen( p ); + slen = strlen( s ); s[slen++] = '\r'; s[slen++] = '\n'; - if (fout != NULL) { - if (fwrite(p, 1, plen, fout) != plen || - fwrite(s, 1, slen, fout) != slen) { - return MBEDTLS_ERR_MPI_FILE_IO_ERROR; - } - } else { - mbedtls_printf("%s%s", p, s); + if( fout != NULL ) + { + if( fwrite( p, 1, plen, fout ) != plen || + fwrite( s, 1, slen, fout ) != slen ) + return( MBEDTLS_ERR_MPI_FILE_IO_ERROR ); } + else + mbedtls_printf( "%s%s", p, s ); cleanup: - return ret; + return( ret ); } #endif /* MBEDTLS_FS_IO */ + +/* Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint + * into the storage form used by mbedtls_mpi. */ + +static mbedtls_mpi_uint mpi_uint_bigendian_to_host_c( mbedtls_mpi_uint x ) +{ + uint8_t i; + unsigned char *x_ptr; + mbedtls_mpi_uint tmp = 0; + + for( i = 0, x_ptr = (unsigned char*) &x; i < ciL; i++, x_ptr++ ) + { + tmp <<= CHAR_BIT; + tmp |= (mbedtls_mpi_uint) *x_ptr; + } + + return( tmp ); +} + +static mbedtls_mpi_uint mpi_uint_bigendian_to_host( mbedtls_mpi_uint x ) +{ +#if defined(__BYTE_ORDER__) + +/* Nothing to do on bigendian systems. */ +#if ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ) + return( x ); +#endif /* __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ */ + +#if ( __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) + +/* For GCC and Clang, have builtins for byte swapping. */ +#if defined(__GNUC__) && defined(__GNUC_PREREQ) +#if __GNUC_PREREQ(4,3) +#define have_bswap +#endif +#endif + +#if defined(__clang__) && defined(__has_builtin) +#if __has_builtin(__builtin_bswap32) && \ + __has_builtin(__builtin_bswap64) +#define have_bswap +#endif +#endif + +#if defined(have_bswap) + /* The compiler is hopefully able to statically evaluate this! */ + switch( sizeof(mbedtls_mpi_uint) ) + { + case 4: + return( __builtin_bswap32(x) ); + case 8: + return( __builtin_bswap64(x) ); + } +#endif +#endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */ +#endif /* __BYTE_ORDER__ */ + + /* Fall back to C-based reordering if we don't know the byte order + * or we couldn't use a compiler-specific builtin. */ + return( mpi_uint_bigendian_to_host_c( x ) ); +} + +static void mpi_bigendian_to_host( mbedtls_mpi_uint * const p, size_t limbs ) +{ + mbedtls_mpi_uint *cur_limb_left; + mbedtls_mpi_uint *cur_limb_right; + if( limbs == 0 ) + return; + + /* + * Traverse limbs and + * - adapt byte-order in each limb + * - swap the limbs themselves. + * For that, simultaneously traverse the limbs from left to right + * and from right to left, as long as the left index is not bigger + * than the right index (it's not a problem if limbs is odd and the + * indices coincide in the last iteration). + */ + for( cur_limb_left = p, cur_limb_right = p + ( limbs - 1 ); + cur_limb_left <= cur_limb_right; + cur_limb_left++, cur_limb_right-- ) + { + mbedtls_mpi_uint tmp; + /* Note that if cur_limb_left == cur_limb_right, + * this code effectively swaps the bytes only once. */ + tmp = mpi_uint_bigendian_to_host( *cur_limb_left ); + *cur_limb_left = mpi_uint_bigendian_to_host( *cur_limb_right ); + *cur_limb_right = tmp; + } +} + /* * Import X from unsigned binary data, little endian - * - * This function is guaranteed to return an MPI with exactly the necessary - * number of limbs (in particular, it does not skip 0s in the input). */ -int mbedtls_mpi_read_binary_le(mbedtls_mpi *X, - const unsigned char *buf, size_t buflen) +int mbedtls_mpi_read_binary_le( mbedtls_mpi *X, + const unsigned char *buf, size_t buflen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - const size_t limbs = CHARS_TO_LIMBS(buflen); + size_t i; + size_t const limbs = CHARS_TO_LIMBS( buflen ); /* Ensure that target MPI has exactly the necessary number of limbs */ - MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs)); + MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, limbs ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_le(X->p, X->n, buf, buflen)); + for( i = 0; i < buflen; i++ ) + X->p[i / ciL] |= ((mbedtls_mpi_uint) buf[i]) << ((i % ciL) << 3); cleanup: @@ -808,24 +806,34 @@ int mbedtls_mpi_read_binary_le(mbedtls_mpi *X, * upon failure is not necessary because failure only can happen before any * input is copied. */ - return ret; + return( ret ); } /* * Import X from unsigned binary data, big endian - * - * This function is guaranteed to return an MPI with exactly the necessary - * number of limbs (in particular, it does not skip 0s in the input). */ -int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, size_t buflen) +int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf, size_t buflen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - const size_t limbs = CHARS_TO_LIMBS(buflen); + size_t const limbs = CHARS_TO_LIMBS( buflen ); + size_t const overhead = ( limbs * ciL ) - buflen; + unsigned char *Xp; + + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( buflen == 0 || buf != NULL ); /* Ensure that target MPI has exactly the necessary number of limbs */ - MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs)); + MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, limbs ) ); + + /* Avoid calling `memcpy` with NULL source or destination argument, + * even if buflen is 0. */ + if( buflen != 0 ) + { + Xp = (unsigned char*) X->p; + memcpy( Xp + overhead, buf, buflen ); - MBEDTLS_MPI_CHK(mbedtls_mpi_core_read_be(X->p, X->n, buf, buflen)); + mpi_bigendian_to_host( X->p, limbs ); + } cleanup: @@ -834,435 +842,686 @@ int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, size_t buf * upon failure is not necessary because failure only can happen before any * input is copied. */ - return ret; + return( ret ); } /* * Export X into unsigned binary data, little endian */ -int mbedtls_mpi_write_binary_le(const mbedtls_mpi *X, - unsigned char *buf, size_t buflen) +int mbedtls_mpi_write_binary_le( const mbedtls_mpi *X, + unsigned char *buf, size_t buflen ) { - return mbedtls_mpi_core_write_le(X->p, X->n, buf, buflen); + size_t stored_bytes = X->n * ciL; + size_t bytes_to_copy; + size_t i; + + if( stored_bytes < buflen ) + { + bytes_to_copy = stored_bytes; + } + else + { + bytes_to_copy = buflen; + + /* The output buffer is smaller than the allocated size of X. + * However X may fit if its leading bytes are zero. */ + for( i = bytes_to_copy; i < stored_bytes; i++ ) + { + if( GET_BYTE( X, i ) != 0 ) + return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + } + } + + for( i = 0; i < bytes_to_copy; i++ ) + buf[i] = GET_BYTE( X, i ); + + if( stored_bytes < buflen ) + { + /* Write trailing 0 bytes */ + memset( buf + stored_bytes, 0, buflen - stored_bytes ); + } + + return( 0 ); } /* * Export X into unsigned binary data, big endian */ -int mbedtls_mpi_write_binary(const mbedtls_mpi *X, - unsigned char *buf, size_t buflen) +int mbedtls_mpi_write_binary( const mbedtls_mpi *X, + unsigned char *buf, size_t buflen ) { - return mbedtls_mpi_core_write_be(X->p, X->n, buf, buflen); + size_t stored_bytes; + size_t bytes_to_copy; + unsigned char *p; + size_t i; + + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( buflen == 0 || buf != NULL ); + + stored_bytes = X->n * ciL; + + if( stored_bytes < buflen ) + { + /* There is enough space in the output buffer. Write initial + * null bytes and record the position at which to start + * writing the significant bytes. In this case, the execution + * trace of this function does not depend on the value of the + * number. */ + bytes_to_copy = stored_bytes; + p = buf + buflen - stored_bytes; + memset( buf, 0, buflen - stored_bytes ); + } + else + { + /* The output buffer is smaller than the allocated size of X. + * However X may fit if its leading bytes are zero. */ + bytes_to_copy = buflen; + p = buf; + for( i = bytes_to_copy; i < stored_bytes; i++ ) + { + if( GET_BYTE( X, i ) != 0 ) + return( MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL ); + } + } + + for( i = 0; i < bytes_to_copy; i++ ) + p[bytes_to_copy - i - 1] = GET_BYTE( X, i ); + + return( 0 ); } /* * Left-shift: X <<= count */ -int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count) +int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t i; + size_t i, v0, t1; + mbedtls_mpi_uint r0 = 0, r1; + MPI_VALIDATE_RET( X != NULL ); - i = mbedtls_mpi_bitlen(X) + count; + v0 = count / (biL ); + t1 = count & (biL - 1); - if (X->n * biL < i) { - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, BITS_TO_LIMBS(i))); - } + i = mbedtls_mpi_bitlen( X ) + count; + + if( X->n * biL < i ) + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, BITS_TO_LIMBS( i ) ) ); ret = 0; - mbedtls_mpi_core_shift_l(X->p, X->n, count); + /* + * shift by count / limb_size + */ + if( v0 > 0 ) + { + for( i = X->n; i > v0; i-- ) + X->p[i - 1] = X->p[i - v0 - 1]; + + for( ; i > 0; i-- ) + X->p[i - 1] = 0; + } + + /* + * shift by count % limb_size + */ + if( t1 > 0 ) + { + for( i = v0; i < X->n; i++ ) + { + r1 = X->p[i] >> (biL - t1); + X->p[i] <<= t1; + X->p[i] |= r0; + r0 = r1; + } + } + cleanup: - return ret; + return( ret ); } /* * Right-shift: X >>= count */ -int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count) +int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count ) { - if (X->n != 0) { - mbedtls_mpi_core_shift_r(X->p, X->n, count); + size_t i, v0, v1; + mbedtls_mpi_uint r0 = 0, r1; + MPI_VALIDATE_RET( X != NULL ); + + v0 = count / biL; + v1 = count & (biL - 1); + + if( v0 > X->n || ( v0 == X->n && v1 > 0 ) ) + return mbedtls_mpi_lset( X, 0 ); + + /* + * shift by count / limb_size + */ + if( v0 > 0 ) + { + for( i = 0; i < X->n - v0; i++ ) + X->p[i] = X->p[i + v0]; + + for( ; i < X->n; i++ ) + X->p[i] = 0; } - return 0; + + /* + * shift by count % limb_size + */ + if( v1 > 0 ) + { + for( i = X->n; i > 0; i-- ) + { + r1 = X->p[i - 1] << (biL - v1); + X->p[i - 1] >>= v1; + X->p[i - 1] |= r0; + r0 = r1; + } + } + + return( 0 ); } /* * Compare unsigned values */ -int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y) +int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y ) { size_t i, j; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( Y != NULL ); - for (i = X->n; i > 0; i--) { - if (X->p[i - 1] != 0) { + for( i = X->n; i > 0; i-- ) + if( X->p[i - 1] != 0 ) break; - } - } - for (j = Y->n; j > 0; j--) { - if (Y->p[j - 1] != 0) { + for( j = Y->n; j > 0; j-- ) + if( Y->p[j - 1] != 0 ) break; - } - } - /* If i == j == 0, i.e. abs(X) == abs(Y), - * we end up returning 0 at the end of the function. */ + if( i == 0 && j == 0 ) + return( 0 ); - if (i > j) { - return 1; - } - if (j > i) { - return -1; - } + if( i > j ) return( 1 ); + if( j > i ) return( -1 ); - for (; i > 0; i--) { - if (X->p[i - 1] > Y->p[i - 1]) { - return 1; - } - if (X->p[i - 1] < Y->p[i - 1]) { - return -1; - } + for( ; i > 0; i-- ) + { + if( X->p[i - 1] > Y->p[i - 1] ) return( 1 ); + if( X->p[i - 1] < Y->p[i - 1] ) return( -1 ); } - return 0; + return( 0 ); } /* * Compare signed values */ -int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y) +int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y ) { size_t i, j; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( Y != NULL ); - for (i = X->n; i > 0; i--) { - if (X->p[i - 1] != 0) { + for( i = X->n; i > 0; i-- ) + if( X->p[i - 1] != 0 ) break; - } - } - for (j = Y->n; j > 0; j--) { - if (Y->p[j - 1] != 0) { + for( j = Y->n; j > 0; j-- ) + if( Y->p[j - 1] != 0 ) break; - } - } - if (i == 0 && j == 0) { - return 0; - } + if( i == 0 && j == 0 ) + return( 0 ); - if (i > j) { - return X->s; - } - if (j > i) { - return -Y->s; - } + if( i > j ) return( X->s ); + if( j > i ) return( -Y->s ); - if (X->s > 0 && Y->s < 0) { - return 1; - } - if (Y->s > 0 && X->s < 0) { - return -1; - } + if( X->s > 0 && Y->s < 0 ) return( 1 ); + if( Y->s > 0 && X->s < 0 ) return( -1 ); - for (; i > 0; i--) { - if (X->p[i - 1] > Y->p[i - 1]) { - return X->s; - } - if (X->p[i - 1] < Y->p[i - 1]) { - return -X->s; - } + for( ; i > 0; i-- ) + { + if( X->p[i - 1] > Y->p[i - 1] ) return( X->s ); + if( X->p[i - 1] < Y->p[i - 1] ) return( -X->s ); } - return 0; + return( 0 ); } /* * Compare signed values */ -int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z) +int mbedtls_mpi_cmp_int( const mbedtls_mpi *X, mbedtls_mpi_sint z ) { mbedtls_mpi Y; mbedtls_mpi_uint p[1]; + MPI_VALIDATE_RET( X != NULL ); - *p = mpi_sint_abs(z); - Y.s = TO_SIGN(z); + *p = ( z < 0 ) ? -z : z; + Y.s = ( z < 0 ) ? -1 : 1; Y.n = 1; Y.p = p; - return mbedtls_mpi_cmp_mpi(X, &Y); + return( mbedtls_mpi_cmp_mpi( X, &Y ) ); } /* * Unsigned addition: X = |A| + |B| (HAC 14.7) */ -int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) +int mbedtls_mpi_add_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t j; - mbedtls_mpi_uint *p; - mbedtls_mpi_uint c; + size_t i, j; + mbedtls_mpi_uint *o, *p, c, tmp; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); - if (X == B) { + if( X == B ) + { const mbedtls_mpi *T = A; A = X; B = T; } - if (X != A) { - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A)); - } + if( X != A ) + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, A ) ); /* - * X must always be positive as a result of unsigned additions. + * X should always be positive as a result of unsigned additions. */ X->s = 1; - for (j = B->n; j > 0; j--) { - if (B->p[j - 1] != 0) { + for( j = B->n; j > 0; j-- ) + if( B->p[j - 1] != 0 ) break; - } - } - /* Exit early to avoid undefined behavior on NULL+0 when X->n == 0 - * and B is 0 (of any size). */ - if (j == 0) { - return 0; - } + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, j ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j)); + o = B->p; p = X->p; c = 0; - /* j is the number of non-zero limbs of B. Add those to X. */ + /* + * tmp is used because it might happen that p == o + */ + for( i = 0; i < j; i++, o++, p++ ) + { + tmp= *o; + *p += c; c = ( *p < c ); + *p += tmp; c += ( *p < tmp ); + } - p = X->p; + while( c != 0 ) + { + if( i >= X->n ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i + 1 ) ); + p = X->p + i; + } - c = mbedtls_mpi_core_add(p, p, B->p, j); + *p += c; c = ( *p < c ); i++; p++; + } - p += j; +cleanup: - /* Now propagate any carry */ + return( ret ); +} - while (c != 0) { - if (j >= X->n) { - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, j + 1)); - p = X->p + j; - } +/** + * Helper for mbedtls_mpi subtraction. + * + * Calculate l - r where l and r have the same size. + * This function operates modulo (2^ciL)^n and returns the carry + * (1 if there was a wraparound, i.e. if `l < r`, and 0 otherwise). + * + * d may be aliased to l or r. + * + * \param n Number of limbs of \p d, \p l and \p r. + * \param[out] d The result of the subtraction. + * \param[in] l The left operand. + * \param[in] r The right operand. + * + * \return 1 if `l < r`. + * 0 if `l >= r`. + */ +static mbedtls_mpi_uint mpi_sub_hlp( size_t n, + mbedtls_mpi_uint *d, + const mbedtls_mpi_uint *l, + const mbedtls_mpi_uint *r ) +{ + size_t i; + mbedtls_mpi_uint c = 0, t, z; - *p += c; c = (*p < c); j++; p++; + for( i = 0; i < n; i++ ) + { + z = ( l[i] < c ); t = l[i] - c; + c = ( t < r[i] ) + z; d[i] = t - r[i]; } -cleanup: - - return ret; + return( c ); } /* * Unsigned subtraction: X = |A| - |B| (HAC 14.9, 14.10) */ -int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) +int mbedtls_mpi_sub_abs( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t n; mbedtls_mpi_uint carry; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); - for (n = B->n; n > 0; n--) { - if (B->p[n - 1] != 0) { + for( n = B->n; n > 0; n-- ) + if( B->p[n - 1] != 0 ) break; - } - } - if (n > A->n) { + if( n > A->n ) + { /* B >= (2^ciL)^n > A */ ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE; goto cleanup; } - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, A->n)); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, A->n ) ); /* Set the high limbs of X to match A. Don't touch the lower limbs * because X might be aliased to B, and we must not overwrite the * significant digits of B. */ - if (A->n > n && A != X) { - memcpy(X->p + n, A->p + n, (A->n - n) * ciL); - } - if (X->n > A->n) { - memset(X->p + A->n, 0, (X->n - A->n) * ciL); - } + if( A->n > n ) + memcpy( X->p + n, A->p + n, ( A->n - n ) * ciL ); + if( X->n > A->n ) + memset( X->p + A->n, 0, ( X->n - A->n ) * ciL ); - carry = mbedtls_mpi_core_sub(X->p, A->p, B->p, n); - if (carry != 0) { - /* Propagate the carry through the rest of X. */ - carry = mbedtls_mpi_core_sub_int(X->p + n, X->p + n, carry, X->n - n); - - /* If we have further carry/borrow, the result is negative. */ - if (carry != 0) { + carry = mpi_sub_hlp( n, X->p, A->p, B->p ); + if( carry != 0 ) + { + /* Propagate the carry to the first nonzero limb of X. */ + for( ; n < X->n && X->p[n] == 0; n++ ) + --X->p[n]; + /* If we ran out of space for the carry, it means that the result + * is negative. */ + if( n == X->n ) + { ret = MBEDTLS_ERR_MPI_NEGATIVE_VALUE; goto cleanup; } + --X->p[n]; } /* X should always be positive as a result of unsigned subtractions. */ X->s = 1; cleanup: - return ret; + return( ret ); } -/* Common function for signed addition and subtraction. - * Calculate A + B * flip_B where flip_B is 1 or -1. +/* + * Signed addition: X = A + B */ -static int add_sub_mpi(mbedtls_mpi *X, - const mbedtls_mpi *A, const mbedtls_mpi *B, - int flip_B) +int mbedtls_mpi_add_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) { int ret, s; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); s = A->s; - if (A->s * B->s * flip_B < 0) { - int cmp = mbedtls_mpi_cmp_abs(A, B); - if (cmp >= 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, A, B)); - /* If |A| = |B|, the result is 0 and we must set the sign bit - * to +1 regardless of which of A or B was negative. Otherwise, - * since |A| > |B|, the sign is the sign of A. */ - X->s = cmp == 0 ? 1 : s; - } else { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(X, B, A)); - /* Since |A| < |B|, the sign is the opposite of A. */ + if( A->s * B->s < 0 ) + { + if( mbedtls_mpi_cmp_abs( A, B ) >= 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, A, B ) ); + X->s = s; + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, B, A ) ); X->s = -s; } - } else { - MBEDTLS_MPI_CHK(mbedtls_mpi_add_abs(X, A, B)); + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( X, A, B ) ); X->s = s; } cleanup: - return ret; -} - -/* - * Signed addition: X = A + B - */ -int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) -{ - return add_sub_mpi(X, A, B, 1); + return( ret ); } /* * Signed subtraction: X = A - B */ -int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) +int mbedtls_mpi_sub_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) { - return add_sub_mpi(X, A, B, -1); + int ret, s; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); + + s = A->s; + if( A->s * B->s > 0 ) + { + if( mbedtls_mpi_cmp_abs( A, B ) >= 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, A, B ) ); + X->s = s; + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( X, B, A ) ); + X->s = -s; + } + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_add_abs( X, A, B ) ); + X->s = s; + } + +cleanup: + + return( ret ); } /* * Signed addition: X = A + b */ -int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b) +int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ) { mbedtls_mpi B; mbedtls_mpi_uint p[1]; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); - p[0] = mpi_sint_abs(b); - B.s = TO_SIGN(b); + p[0] = ( b < 0 ) ? -b : b; + B.s = ( b < 0 ) ? -1 : 1; B.n = 1; B.p = p; - return mbedtls_mpi_add_mpi(X, A, &B); + return( mbedtls_mpi_add_mpi( X, A, &B ) ); } /* * Signed subtraction: X = A - b */ -int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b) +int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b ) { mbedtls_mpi B; mbedtls_mpi_uint p[1]; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); - p[0] = mpi_sint_abs(b); - B.s = TO_SIGN(b); + p[0] = ( b < 0 ) ? -b : b; + B.s = ( b < 0 ) ? -1 : 1; B.n = 1; B.p = p; - return mbedtls_mpi_sub_mpi(X, A, &B); + return( mbedtls_mpi_sub_mpi( X, A, &B ) ); +} + +/** Helper for mbedtls_mpi multiplication. + * + * Add \p b * \p s to \p d. + * + * \param i The number of limbs of \p s. + * \param[in] s A bignum to multiply, of size \p i. + * It may overlap with \p d, but only if + * \p d <= \p s. + * Its leading limb must not be \c 0. + * \param[in,out] d The bignum to add to. + * It must be sufficiently large to store the + * result of the multiplication. This means + * \p i + 1 limbs if \p d[\p i - 1] started as 0 and \p b + * is not known a priori. + * \param b A scalar to multiply. + */ +static +#if defined(__APPLE__) && defined(__arm__) +/* + * Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn) + * appears to need this to prevent bad ARM code generation at -O3. + */ +__attribute__ ((noinline)) +#endif +void mpi_mul_hlp( size_t i, + const mbedtls_mpi_uint *s, + mbedtls_mpi_uint *d, + mbedtls_mpi_uint b ) +{ + mbedtls_mpi_uint c = 0; + +#if defined(MULADDC_HUIT) + for( ; i >= 8; i -= 8 ) + { + MULADDC_INIT + MULADDC_HUIT + MULADDC_STOP + } + + for( ; i > 0; i-- ) + { + MULADDC_INIT + MULADDC_CORE + MULADDC_STOP + } +#else /* MULADDC_HUIT */ + for( ; i >= 16; i -= 16 ) + { + MULADDC_INIT + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + MULADDC_STOP + } + + for( ; i >= 8; i -= 8 ) + { + MULADDC_INIT + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + + MULADDC_CORE MULADDC_CORE + MULADDC_CORE MULADDC_CORE + MULADDC_STOP + } + + for( ; i > 0; i-- ) + { + MULADDC_INIT + MULADDC_CORE + MULADDC_STOP + } +#endif /* MULADDC_HUIT */ + + while( c != 0 ) + { + *d += c; c = ( *d < c ); d++; + } } /* * Baseline multiplication: X = A * B (HAC 14.12) */ -int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) +int mbedtls_mpi_mul_mpi( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t i, j; mbedtls_mpi TA, TB; int result_is_zero = 0; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); - mbedtls_mpi_init(&TA); - mbedtls_mpi_init(&TB); + mbedtls_mpi_init( &TA ); mbedtls_mpi_init( &TB ); - if (X == A) { - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); A = &TA; - } - if (X == B) { - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); B = &TB; - } + if( X == A ) { MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TA, A ) ); A = &TA; } + if( X == B ) { MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TB, B ) ); B = &TB; } - for (i = A->n; i > 0; i--) { - if (A->p[i - 1] != 0) { + for( i = A->n; i > 0; i-- ) + if( A->p[i - 1] != 0 ) break; - } - } - if (i == 0) { + if( i == 0 ) result_is_zero = 1; - } - for (j = B->n; j > 0; j--) { - if (B->p[j - 1] != 0) { + for( j = B->n; j > 0; j-- ) + if( B->p[j - 1] != 0 ) break; - } - } - if (j == 0) { + if( j == 0 ) result_is_zero = 1; - } - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, i + j)); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(X, 0)); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, i + j ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( X, 0 ) ); - mbedtls_mpi_core_mul(X->p, A->p, i, B->p, j); + for( ; j > 0; j-- ) + mpi_mul_hlp( i, A->p, X->p + j - 1, B->p[j - 1] ); /* If the result is 0, we don't shortcut the operation, which reduces * but does not eliminate side channels leaking the zero-ness. We do * need to take care to set the sign bit properly since the library does * not fully support an MPI object with a value of 0 and s == -1. */ - if (result_is_zero) { + if( result_is_zero ) X->s = 1; - } else { + else X->s = A->s * B->s; - } cleanup: - mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TA); + mbedtls_mpi_free( &TB ); mbedtls_mpi_free( &TA ); - return ret; + return( ret ); } /* * Baseline multiplication: X = A * b */ -int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b) +int mbedtls_mpi_mul_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b ) { + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + + /* mpi_mul_hlp can't deal with a leading 0. */ size_t n = A->n; - while (n > 0 && A->p[n - 1] == 0) { + while( n > 0 && A->p[n - 1] == 0 ) --n; - } - /* The general method below doesn't work if b==0. */ - if (b == 0 || n == 0) { - return mbedtls_mpi_lset(X, 0); + /* The general method below doesn't work if n==0 or b==0. By chance + * calculating the result is trivial in those cases. */ + if( b == 0 || n == 0 ) + { + return( mbedtls_mpi_lset( X, 0 ) ); } - /* Calculate A*b as A + A*(b-1) to take advantage of mbedtls_mpi_core_mla */ + /* Calculate A*b as A + A*(b-1) to take advantage of mpi_mul_hlp */ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; /* In general, A * b requires 1 limb more than b. If * A->p[n - 1] * b / b == A->p[n - 1], then A * b fits in the same @@ -1271,32 +1530,27 @@ int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b * making the call to grow() unconditional causes slightly fewer * calls to calloc() in ECP code, presumably because it reuses the * same mpi for a while and this way the mpi is more likely to directly - * grow to its final size. - * - * Note that calculating A*b as 0 + A*b doesn't work as-is because - * A,X can be the same. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, n + 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A)); - mbedtls_mpi_core_mla(X->p, X->n, A->p, n, b - 1); + * grow to its final size. */ + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, n + 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, A ) ); + mpi_mul_hlp( n, A->p, X->p, b - 1 ); cleanup: - return ret; + return( ret ); } /* * Unsigned integer divide - double mbedtls_mpi_uint dividend, u1/u0, and * mbedtls_mpi_uint divisor, d */ -static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1, - mbedtls_mpi_uint u0, - mbedtls_mpi_uint d, - mbedtls_mpi_uint *r) +static mbedtls_mpi_uint mbedtls_int_div_int( mbedtls_mpi_uint u1, + mbedtls_mpi_uint u0, mbedtls_mpi_uint d, mbedtls_mpi_uint *r ) { #if defined(MBEDTLS_HAVE_UDBL) mbedtls_t_udbl dividend, quotient; #else const mbedtls_mpi_uint radix = (mbedtls_mpi_uint) 1 << biH; - const mbedtls_mpi_uint uint_halfword_mask = ((mbedtls_mpi_uint) 1 << biH) - 1; + const mbedtls_mpi_uint uint_halfword_mask = ( (mbedtls_mpi_uint) 1 << biH ) - 1; mbedtls_mpi_uint d0, d1, q0, q1, rAX, r0, quotient; mbedtls_mpi_uint u0_msw, u0_lsw; size_t s; @@ -1305,25 +1559,22 @@ static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1, /* * Check for overflow */ - if (0 == d || u1 >= d) { - if (r != NULL) { - *r = ~(mbedtls_mpi_uint) 0u; - } + if( 0 == d || u1 >= d ) + { + if (r != NULL) *r = ~0; - return ~(mbedtls_mpi_uint) 0u; + return ( ~0 ); } #if defined(MBEDTLS_HAVE_UDBL) dividend = (mbedtls_t_udbl) u1 << biL; dividend |= (mbedtls_t_udbl) u0; quotient = dividend / d; - if (quotient > ((mbedtls_t_udbl) 1 << biL) - 1) { - quotient = ((mbedtls_t_udbl) 1 << biL) - 1; - } + if( quotient > ( (mbedtls_t_udbl) 1 << biL ) - 1 ) + quotient = ( (mbedtls_t_udbl) 1 << biL ) - 1; - if (r != NULL) { - *r = (mbedtls_mpi_uint) (dividend - (quotient * d)); - } + if( r != NULL ) + *r = (mbedtls_mpi_uint)( dividend - (quotient * d ) ); return (mbedtls_mpi_uint) quotient; #else @@ -1336,11 +1587,11 @@ static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1, /* * Normalize the divisor, d, and dividend, u0, u1 */ - s = mbedtls_mpi_core_clz(d); + s = mbedtls_clz( d ); d = d << s; u1 = u1 << s; - u1 |= (u0 >> (biL - s)) & (-(mbedtls_mpi_sint) s >> (biL - 1)); + u1 |= ( u0 >> ( biL - s ) ) & ( -(mbedtls_mpi_sint)s >> ( biL - 1 ) ); u0 = u0 << s; d1 = d >> biH; @@ -1355,31 +1606,28 @@ static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1, q1 = u1 / d1; r0 = u1 - d1 * q1; - while (q1 >= radix || (q1 * d0 > radix * r0 + u0_msw)) { + while( q1 >= radix || ( q1 * d0 > radix * r0 + u0_msw ) ) + { q1 -= 1; r0 += d1; - if (r0 >= radix) { - break; - } + if ( r0 >= radix ) break; } - rAX = (u1 * radix) + (u0_msw - q1 * d); + rAX = ( u1 * radix ) + ( u0_msw - q1 * d ); q0 = rAX / d1; r0 = rAX - q0 * d1; - while (q0 >= radix || (q0 * d0 > radix * r0 + u0_lsw)) { + while( q0 >= radix || ( q0 * d0 > radix * r0 + u0_lsw ) ) + { q0 -= 1; r0 += d1; - if (r0 >= radix) { - break; - } + if ( r0 >= radix ) break; } - if (r != NULL) { - *r = (rAX * radix + u0_lsw - q0 * d) >> s; - } + if (r != NULL) + *r = ( rAX * radix + u0_lsw - q0 * d ) >> s; quotient = q1 * radix + q0; @@ -1390,20 +1638,21 @@ static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1, /* * Division by mbedtls_mpi: A = Q * B + R (HAC 14.20) */ -int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, - const mbedtls_mpi *B) +int mbedtls_mpi_div_mpi( mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, + const mbedtls_mpi *B ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t i, n, t, k; mbedtls_mpi X, Y, Z, T1, T2; mbedtls_mpi_uint TP2[3]; + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); - if (mbedtls_mpi_cmp_int(B, 0) == 0) { - return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO; - } + if( mbedtls_mpi_cmp_int( B, 0 ) == 0 ) + return( MBEDTLS_ERR_MPI_DIVISION_BY_ZERO ); - mbedtls_mpi_init(&X); mbedtls_mpi_init(&Y); mbedtls_mpi_init(&Z); - mbedtls_mpi_init(&T1); + mbedtls_mpi_init( &X ); mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &Z ); + mbedtls_mpi_init( &T1 ); /* * Avoid dynamic memory allocations for constant-size T2. * @@ -1412,188 +1661,196 @@ int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, * buffer. */ T2.s = 1; - T2.n = sizeof(TP2) / sizeof(*TP2); + T2.n = sizeof( TP2 ) / sizeof( *TP2 ); T2.p = TP2; - if (mbedtls_mpi_cmp_abs(A, B) < 0) { - if (Q != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(Q, 0)); - } - if (R != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, A)); - } - return 0; + if( mbedtls_mpi_cmp_abs( A, B ) < 0 ) + { + if( Q != NULL ) MBEDTLS_MPI_CHK( mbedtls_mpi_lset( Q, 0 ) ); + if( R != NULL ) MBEDTLS_MPI_CHK( mbedtls_mpi_copy( R, A ) ); + return( 0 ); } - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&X, A)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, B)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &X, A ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &Y, B ) ); X.s = Y.s = 1; - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&Z, A->n + 2)); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Z, 0)); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&T1, A->n + 2)); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &Z, A->n + 2 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Z, 0 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &T1, A->n + 2 ) ); - k = mbedtls_mpi_bitlen(&Y) % biL; - if (k < biL - 1) { + k = mbedtls_mpi_bitlen( &Y ) % biL; + if( k < biL - 1 ) + { k = biL - 1 - k; - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&X, k)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, k)); - } else { - k = 0; + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &X, k ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &Y, k ) ); } + else k = 0; n = X.n - 1; t = Y.n - 1; - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&Y, biL * (n - t))); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &Y, biL * ( n - t ) ) ); - while (mbedtls_mpi_cmp_mpi(&X, &Y) >= 0) { + while( mbedtls_mpi_cmp_mpi( &X, &Y ) >= 0 ) + { Z.p[n - t]++; - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &Y)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &X, &X, &Y ) ); } - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, biL * (n - t))); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &Y, biL * ( n - t ) ) ); - for (i = n; i > t; i--) { - if (X.p[i] >= Y.p[t]) { - Z.p[i - t - 1] = ~(mbedtls_mpi_uint) 0u; - } else { - Z.p[i - t - 1] = mbedtls_int_div_int(X.p[i], X.p[i - 1], - Y.p[t], NULL); + for( i = n; i > t ; i-- ) + { + if( X.p[i] >= Y.p[t] ) + Z.p[i - t - 1] = ~0; + else + { + Z.p[i - t - 1] = mbedtls_int_div_int( X.p[i], X.p[i - 1], + Y.p[t], NULL); } - T2.p[0] = (i < 2) ? 0 : X.p[i - 2]; - T2.p[1] = (i < 1) ? 0 : X.p[i - 1]; + T2.p[0] = ( i < 2 ) ? 0 : X.p[i - 2]; + T2.p[1] = ( i < 1 ) ? 0 : X.p[i - 1]; T2.p[2] = X.p[i]; Z.p[i - t - 1]++; - do { + do + { Z.p[i - t - 1]--; - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&T1, 0)); - T1.p[0] = (t < 1) ? 0 : Y.p[t - 1]; + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &T1, 0 ) ); + T1.p[0] = ( t < 1 ) ? 0 : Y.p[t - 1]; T1.p[1] = Y.p[t]; - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &T1, Z.p[i - t - 1])); - } while (mbedtls_mpi_cmp_mpi(&T1, &T2) > 0); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_int( &T1, &T1, Z.p[i - t - 1] ) ); + } + while( mbedtls_mpi_cmp_mpi( &T1, &T2 ) > 0 ); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_int(&T1, &Y, Z.p[i - t - 1])); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1, biL * (i - t - 1))); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&X, &X, &T1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_int( &T1, &Y, Z.p[i - t - 1] ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &T1, biL * ( i - t - 1 ) ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &X, &X, &T1 ) ); - if (mbedtls_mpi_cmp_int(&X, 0) < 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&T1, &Y)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&T1, biL * (i - t - 1))); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&X, &X, &T1)); + if( mbedtls_mpi_cmp_int( &X, 0 ) < 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &T1, &Y ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &T1, biL * ( i - t - 1 ) ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &X, &X, &T1 ) ); Z.p[i - t - 1]--; } } - if (Q != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(Q, &Z)); + if( Q != NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( Q, &Z ) ); Q->s = A->s * B->s; } - if (R != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&X, k)); + if( R != NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &X, k ) ); X.s = A->s; - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(R, &X)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( R, &X ) ); - if (mbedtls_mpi_cmp_int(R, 0) == 0) { + if( mbedtls_mpi_cmp_int( R, 0 ) == 0 ) R->s = 1; - } } cleanup: - mbedtls_mpi_free(&X); mbedtls_mpi_free(&Y); mbedtls_mpi_free(&Z); - mbedtls_mpi_free(&T1); - mbedtls_platform_zeroize(TP2, sizeof(TP2)); + mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); + mbedtls_mpi_free( &T1 ); + mbedtls_platform_zeroize( TP2, sizeof( TP2 ) ); - return ret; + return( ret ); } /* * Division by int: A = Q * b + R */ -int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R, - const mbedtls_mpi *A, - mbedtls_mpi_sint b) +int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R, + const mbedtls_mpi *A, + mbedtls_mpi_sint b ) { mbedtls_mpi B; mbedtls_mpi_uint p[1]; + MPI_VALIDATE_RET( A != NULL ); - p[0] = mpi_sint_abs(b); - B.s = TO_SIGN(b); + p[0] = ( b < 0 ) ? -b : b; + B.s = ( b < 0 ) ? -1 : 1; B.n = 1; B.p = p; - return mbedtls_mpi_div_mpi(Q, R, A, &B); + return( mbedtls_mpi_div_mpi( Q, R, A, &B ) ); } /* * Modulo: R = A mod B */ -int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B) +int mbedtls_mpi_mod_mpi( mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + MPI_VALIDATE_RET( R != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); - if (mbedtls_mpi_cmp_int(B, 0) < 0) { - return MBEDTLS_ERR_MPI_NEGATIVE_VALUE; - } + if( mbedtls_mpi_cmp_int( B, 0 ) < 0 ) + return( MBEDTLS_ERR_MPI_NEGATIVE_VALUE ); - MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(NULL, R, A, B)); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( NULL, R, A, B ) ); - while (mbedtls_mpi_cmp_int(R, 0) < 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(R, R, B)); - } + while( mbedtls_mpi_cmp_int( R, 0 ) < 0 ) + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( R, R, B ) ); - while (mbedtls_mpi_cmp_mpi(R, B) >= 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(R, R, B)); - } + while( mbedtls_mpi_cmp_mpi( R, B ) >= 0 ) + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( R, R, B ) ); cleanup: - return ret; + return( ret ); } /* * Modulo: r = A mod b */ -int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b) +int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b ) { size_t i; mbedtls_mpi_uint x, y, z; + MPI_VALIDATE_RET( r != NULL ); + MPI_VALIDATE_RET( A != NULL ); - if (b == 0) { - return MBEDTLS_ERR_MPI_DIVISION_BY_ZERO; - } + if( b == 0 ) + return( MBEDTLS_ERR_MPI_DIVISION_BY_ZERO ); - if (b < 0) { - return MBEDTLS_ERR_MPI_NEGATIVE_VALUE; - } + if( b < 0 ) + return( MBEDTLS_ERR_MPI_NEGATIVE_VALUE ); /* * handle trivial cases */ - if (b == 1 || A->n == 0) { + if( b == 1 ) + { *r = 0; - return 0; + return( 0 ); } - if (b == 2) { + if( b == 2 ) + { *r = A->p[0] & 1; - return 0; + return( 0 ); } /* * general case */ - for (i = A->n, y = 0; i > 0; i--) { + for( i = A->n, y = 0; i > 0; i-- ) + { x = A->p[i - 1]; - y = (y << biH) | (x >> biH); + y = ( y << biH ) | ( x >> biH ); z = y / b; y -= z * b; x <<= biH; - y = (y << biH) | (x >> biH); + y = ( y << biH ) | ( x >> biH ); z = y / b; y -= z * b; } @@ -1602,176 +1859,416 @@ int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_s * If A is negative, then the current y represents a negative value. * Flipping it to the positive side. */ - if (A->s < 0 && y != 0) { + if( A->s < 0 && y != 0 ) y = b - y; - } *r = y; - return 0; + return( 0 ); +} + +/* + * Fast Montgomery initialization (thanks to Tom St Denis) + */ +static void mpi_montg_init( mbedtls_mpi_uint *mm, const mbedtls_mpi *N ) +{ + mbedtls_mpi_uint x, m0 = N->p[0]; + unsigned int i; + + x = m0; + x += ( ( m0 + 2 ) & 4 ) << 1; + + for( i = biL; i >= 8; i /= 2 ) + x *= ( 2 - ( m0 * x ) ); + + *mm = ~x + 1; +} + +/** Montgomery multiplication: A = A * B * R^-1 mod N (HAC 14.36) + * + * \param[in,out] A One of the numbers to multiply. + * It must have at least as many limbs as N + * (A->n >= N->n), and any limbs beyond n are ignored. + * On successful completion, A contains the result of + * the multiplication A * B * R^-1 mod N where + * R = (2^ciL)^n. + * \param[in] B One of the numbers to multiply. + * It must be nonzero and must not have more limbs than N + * (B->n <= N->n). + * \param[in] N The modulo. N must be odd. + * \param mm The value calculated by `mpi_montg_init(&mm, N)`. + * This is -N^-1 mod 2^ciL. + * \param[in,out] T A bignum for temporary storage. + * It must be at least twice the limb size of N plus 2 + * (T->n >= 2 * (N->n + 1)). + * Its initial content is unused and + * its final content is indeterminate. + * Note that unlike the usual convention in the library + * for `const mbedtls_mpi*`, the content of T can change. + */ +static void mpi_montmul( mbedtls_mpi *A, const mbedtls_mpi *B, const mbedtls_mpi *N, mbedtls_mpi_uint mm, + const mbedtls_mpi *T ) +{ + size_t i, n, m; + mbedtls_mpi_uint u0, u1, *d; + + memset( T->p, 0, T->n * ciL ); + + d = T->p; + n = N->n; + m = ( B->n < n ) ? B->n : n; + + for( i = 0; i < n; i++ ) + { + /* + * T = (T + u0*B + u1*N) / 2^biL + */ + u0 = A->p[i]; + u1 = ( d[0] + u0 * B->p[0] ) * mm; + + mpi_mul_hlp( m, B->p, d, u0 ); + mpi_mul_hlp( n, N->p, d, u1 ); + + *d++ = u0; d[n + 1] = 0; + } + + /* At this point, d is either the desired result or the desired result + * plus N. We now potentially subtract N, avoiding leaking whether the + * subtraction is performed through side channels. */ + + /* Copy the n least significant limbs of d to A, so that + * A = d if d < N (recall that N has n limbs). */ + memcpy( A->p, d, n * ciL ); + /* If d >= N then we want to set A to d - N. To prevent timing attacks, + * do the calculation without using conditional tests. */ + /* Set d to d0 + (2^biL)^n - N where d0 is the current value of d. */ + d[n] += 1; + d[n] -= mpi_sub_hlp( n, d, d, N->p ); + /* If d0 < N then d < (2^biL)^n + * so d[n] == 0 and we want to keep A as it is. + * If d0 >= N then d >= (2^biL)^n, and d <= (2^biL)^n + N < 2 * (2^biL)^n + * so d[n] == 1 and we want to set A to the result of the subtraction + * which is d - (2^biL)^n, i.e. the n least significant limbs of d. + * This exactly corresponds to a conditional assignment. */ + mbedtls_ct_mpi_uint_cond_assign( n, A->p, d, (unsigned char) d[n] ); } /* - * Warning! If the parameter E_public has MBEDTLS_MPI_IS_PUBLIC as its value, - * this function is not constant time with respect to the exponent (parameter E). + * Montgomery reduction: A = A * R^-1 mod N + * + * See mpi_montmul() regarding constraints and guarantees on the parameters. + */ +static void mpi_montred( mbedtls_mpi *A, const mbedtls_mpi *N, + mbedtls_mpi_uint mm, const mbedtls_mpi *T ) +{ + mbedtls_mpi_uint z = 1; + mbedtls_mpi U; + + U.n = U.s = (int) z; + U.p = &z; + + mpi_montmul( A, &U, N, mm, T ); +} + +/** + * Select an MPI from a table without leaking the index. + * + * This is functionally equivalent to mbedtls_mpi_copy(R, T[idx]) except it + * reads the entire table in order to avoid leaking the value of idx to an + * attacker able to observe memory access patterns. + * + * \param[out] R Where to write the selected MPI. + * \param[in] T The table to read from. + * \param[in] T_size The number of elements in the table. + * \param[in] idx The index of the element to select; + * this must satisfy 0 <= idx < T_size. + * + * \return \c 0 on success, or a negative error code. */ -static int mbedtls_mpi_exp_mod_optionally_safe(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *E, int E_public, - const mbedtls_mpi *N, mbedtls_mpi *prec_RR) +static int mpi_select( mbedtls_mpi *R, const mbedtls_mpi *T, size_t T_size, size_t idx ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - if (mbedtls_mpi_cmp_int(N, 0) <= 0 || (N->p[0] & 1) == 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; + for( size_t i = 0; i < T_size; i++ ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_safe_cond_assign( R, &T[i], + (unsigned char) mbedtls_ct_size_bool_eq( i, idx ) ) ); } - if (mbedtls_mpi_cmp_int(E, 0) < 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } +cleanup: + return( ret ); +} - if (mbedtls_mpi_bitlen(E) > MBEDTLS_MPI_MAX_BITS || - mbedtls_mpi_bitlen(N) > MBEDTLS_MPI_MAX_BITS) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } +/* + * Sliding-window exponentiation: X = A^E mod N (HAC 14.85) + */ +int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A, + const mbedtls_mpi *E, const mbedtls_mpi *N, + mbedtls_mpi *prec_RR ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t wbits, wsize, one = 1; + size_t i, j, nblimbs; + size_t bufsize, nbits; + mbedtls_mpi_uint ei, mm, state; + mbedtls_mpi RR, T, W[ 1 << MBEDTLS_MPI_WINDOW_SIZE ], WW, Apos; + int neg; + + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( E != NULL ); + MPI_VALIDATE_RET( N != NULL ); + + if( mbedtls_mpi_cmp_int( N, 0 ) <= 0 || ( N->p[0] & 1 ) == 0 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + + if( mbedtls_mpi_cmp_int( E, 0 ) < 0 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + + if( mbedtls_mpi_bitlen( E ) > MBEDTLS_MPI_MAX_BITS || + mbedtls_mpi_bitlen( N ) > MBEDTLS_MPI_MAX_BITS ) + return ( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); /* - * Ensure that the exponent that we are passing to the core is not NULL. + * Init temps and window size */ - if (E->n == 0) { - ret = mbedtls_mpi_lset(X, 1); - return ret; - } + mpi_montg_init( &mm, N ); + mbedtls_mpi_init( &RR ); mbedtls_mpi_init( &T ); + mbedtls_mpi_init( &Apos ); + mbedtls_mpi_init( &WW ); + memset( W, 0, sizeof( W ) ); + + i = mbedtls_mpi_bitlen( E ); + + wsize = ( i > 671 ) ? 6 : ( i > 239 ) ? 5 : + ( i > 79 ) ? 4 : ( i > 23 ) ? 3 : 1; + +#if( MBEDTLS_MPI_WINDOW_SIZE < 6 ) + if( wsize > MBEDTLS_MPI_WINDOW_SIZE ) + wsize = MBEDTLS_MPI_WINDOW_SIZE; +#endif + + j = N->n + 1; + /* All W[i] and X must have at least N->n limbs for the mpi_montmul() + * and mpi_montred() calls later. Here we ensure that W[1] and X are + * large enough, and later we'll grow other W[i] to the same length. + * They must not be shrunk midway through this function! + */ + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, j ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &W[1], j ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &T, j * 2 ) ); /* - * Allocate working memory for mbedtls_mpi_core_exp_mod() + * Compensate for negative A (and correct at the end) */ - size_t T_limbs = mbedtls_mpi_core_exp_mod_working_limbs(N->n, E->n); - mbedtls_mpi_uint *T = (mbedtls_mpi_uint *) mbedtls_calloc(T_limbs, sizeof(mbedtls_mpi_uint)); - if (T == NULL) { - return MBEDTLS_ERR_MPI_ALLOC_FAILED; + neg = ( A->s == -1 ); + if( neg ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &Apos, A ) ); + Apos.s = 1; + A = &Apos; } - mbedtls_mpi RR; - mbedtls_mpi_init(&RR); - /* * If 1st call, pre-compute R^2 mod N */ - if (prec_RR == NULL || prec_RR->p == NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_core_get_mont_r2_unsafe(&RR, N)); + if( prec_RR == NULL || prec_RR->p == NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &RR, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &RR, N->n * 2 * biL ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &RR, &RR, N ) ); - if (prec_RR != NULL) { - *prec_RR = RR; - } - } else { - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(prec_RR, N->n)); - RR = *prec_RR; + if( prec_RR != NULL ) + memcpy( prec_RR, &RR, sizeof( mbedtls_mpi ) ); } + else + memcpy( &RR, prec_RR, sizeof( mbedtls_mpi ) ); /* - * To preserve constness we need to make a copy of A. Using X for this to - * save memory. + * W[1] = A * R^2 * R^-1 mod N = A * R mod N */ - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, A)); + if( mbedtls_mpi_cmp_mpi( A, N ) >= 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &W[1], A, N ) ); + /* This should be a no-op because W[1] is already that large before + * mbedtls_mpi_mod_mpi(), but it's necessary to avoid an overflow + * in mpi_montmul() below, so let's make sure. */ + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &W[1], N->n + 1 ) ); + } + else + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &W[1], A ) ); - /* - * Compensate for negative A (and correct at the end). - */ - X->s = 1; + /* Note that this is safe because W[1] always has at least N->n limbs + * (it grew above and was preserved by mbedtls_mpi_copy()). */ + mpi_montmul( &W[1], &RR, N, mm, &T ); /* - * Make sure that X is in a form that is safe for consumption by - * the core functions. - * - * - The core functions will not touch the limbs of X above N->n. The - * result will be correct if those limbs are 0, which the mod call - * ensures. - * - Also, X must have at least as many limbs as N for the calls to the - * core functions. + * X = R^2 * R^-1 mod N = R mod N */ - if (mbedtls_mpi_cmp_mpi(X, N) >= 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(X, X, N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, &RR ) ); + mpi_montred( X, N, mm, &T ); + + if( wsize > 1 ) + { + /* + * W[1 << (wsize - 1)] = W[1] ^ (wsize - 1) + */ + j = one << ( wsize - 1 ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &W[j], N->n + 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &W[j], &W[1] ) ); + + for( i = 0; i < wsize - 1; i++ ) + mpi_montmul( &W[j], &W[j], N, mm, &T ); + + /* + * W[i] = W[i - 1] * W[1] + */ + for( i = j + 1; i < ( one << wsize ); i++ ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &W[i], N->n + 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &W[i], &W[i - 1] ) ); + + mpi_montmul( &W[i], &W[1], N, mm, &T ); + } + } + + nblimbs = E->n; + bufsize = 0; + nbits = 0; + wbits = 0; + state = 0; + + while( 1 ) + { + if( bufsize == 0 ) + { + if( nblimbs == 0 ) + break; + + nblimbs--; + + bufsize = sizeof( mbedtls_mpi_uint ) << 3; + } + + bufsize--; + + ei = (E->p[nblimbs] >> bufsize) & 1; + + /* + * skip leading 0s + */ + if( ei == 0 && state == 0 ) + continue; + + if( ei == 0 && state == 1 ) + { + /* + * out of window, square X + */ + mpi_montmul( X, X, N, mm, &T ); + continue; + } + + /* + * add ei to current window + */ + state = 2; + + nbits++; + wbits |= ( ei << ( wsize - nbits ) ); + + if( nbits == wsize ) + { + /* + * X = X^wsize R^-1 mod N + */ + for( i = 0; i < wsize; i++ ) + mpi_montmul( X, X, N, mm, &T ); + + /* + * X = X * W[wbits] R^-1 mod N + */ + MBEDTLS_MPI_CHK( mpi_select( &WW, W, (size_t) 1 << wsize, wbits ) ); + mpi_montmul( X, &WW, N, mm, &T ); + + state--; + nbits = 0; + wbits = 0; + } } - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(X, N->n)); /* - * Convert to and from Montgomery around mbedtls_mpi_core_exp_mod(). + * process the remaining bits */ + for( i = 0; i < nbits; i++ ) { - mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N->p); - mbedtls_mpi_core_to_mont_rep(X->p, X->p, N->p, N->n, mm, RR.p, T); - if (E_public == MBEDTLS_MPI_IS_PUBLIC) { - mbedtls_mpi_core_exp_mod_unsafe(X->p, X->p, N->p, N->n, E->p, E->n, RR.p, T); - } else { - mbedtls_mpi_core_exp_mod(X->p, X->p, N->p, N->n, E->p, E->n, RR.p, T); - } - mbedtls_mpi_core_from_mont_rep(X->p, X->p, N->p, N->n, mm, T); + mpi_montmul( X, X, N, mm, &T ); + + wbits <<= 1; + + if( ( wbits & ( one << wsize ) ) != 0 ) + mpi_montmul( X, &W[1], N, mm, &T ); } /* - * Correct for negative A. + * X = A^E * R * R^-1 mod N = A^E mod N */ - if (A->s == -1 && (E->p[0] & 1) != 0) { - mbedtls_ct_condition_t is_x_non_zero = mbedtls_mpi_core_check_zero_ct(X->p, X->n); - X->s = mbedtls_ct_mpi_sign_if(is_x_non_zero, -1, 1); + mpi_montred( X, N, mm, &T ); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(X, N, X)); + if( neg && E->n != 0 && ( E->p[0] & 1 ) != 0 ) + { + X->s = -1; + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( X, N, X ) ); } cleanup: - mbedtls_mpi_zeroize_and_free(T, T_limbs); - - if (prec_RR == NULL || prec_RR->p == NULL) { - mbedtls_mpi_free(&RR); - } + for( i = ( one << ( wsize - 1 ) ); i < ( one << wsize ); i++ ) + mbedtls_mpi_free( &W[i] ); - return ret; -} + mbedtls_mpi_free( &W[1] ); mbedtls_mpi_free( &T ); mbedtls_mpi_free( &Apos ); + mbedtls_mpi_free( &WW ); -int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *E, const mbedtls_mpi *N, - mbedtls_mpi *prec_RR) -{ - return mbedtls_mpi_exp_mod_optionally_safe(X, A, E, MBEDTLS_MPI_IS_SECRET, N, prec_RR); -} + if( prec_RR == NULL || prec_RR->p == NULL ) + mbedtls_mpi_free( &RR ); -int mbedtls_mpi_exp_mod_unsafe(mbedtls_mpi *X, const mbedtls_mpi *A, - const mbedtls_mpi *E, const mbedtls_mpi *N, - mbedtls_mpi *prec_RR) -{ - return mbedtls_mpi_exp_mod_optionally_safe(X, A, E, MBEDTLS_MPI_IS_PUBLIC, N, prec_RR); + return( ret ); } /* * Greatest common divisor: G = gcd(A, B) (HAC 14.54) */ -int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B) +int mbedtls_mpi_gcd( mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t lz, lzt; mbedtls_mpi TA, TB; - mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TB); + MPI_VALIDATE_RET( G != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( B != NULL ); + + mbedtls_mpi_init( &TA ); mbedtls_mpi_init( &TB ); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TA, A)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, B)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TA, A ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TB, B ) ); - lz = mbedtls_mpi_lsb(&TA); - lzt = mbedtls_mpi_lsb(&TB); + lz = mbedtls_mpi_lsb( &TA ); + lzt = mbedtls_mpi_lsb( &TB ); /* The loop below gives the correct result when A==0 but not when B==0. * So have a special case for B==0. Leverage the fact that we just * calculated the lsb and lsb(B)==0 iff B is odd or 0 to make the test * slightly more efficient than cmp_int(). */ - if (lzt == 0 && mbedtls_mpi_get_bit(&TB, 0) == 0) { - ret = mbedtls_mpi_copy(G, A); + if( lzt == 0 && mbedtls_mpi_get_bit( &TB, 0 ) == 0 ) + { + ret = mbedtls_mpi_copy( G, A ); goto cleanup; } - if (lzt < lz) { + if( lzt < lz ) lz = lzt; - } TA.s = TB.s = 1; @@ -1808,24 +2305,28 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B) * TA becomes 0 which ends the loop (TB cannot be 0 if it is right-shifted * since in that case TB is calculated from TB-TA with the condition TB>TA). */ - while (mbedtls_mpi_cmp_int(&TA, 0) != 0) { + while( mbedtls_mpi_cmp_int( &TA, 0 ) != 0 ) + { /* Divisions by 2 preserve the invariant (I). */ - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, mbedtls_mpi_lsb(&TA))); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, mbedtls_mpi_lsb(&TB))); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TA, mbedtls_mpi_lsb( &TA ) ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TB, mbedtls_mpi_lsb( &TB ) ) ); /* Set either TA or TB to |TA-TB|/2. Since TA and TB are both odd, * TA-TB is even so the division by 2 has an integer result. * Invariant (I) is preserved since any odd divisor of both TA and TB * also divides |TA-TB|/2, and any odd divisor of both TA and |TA-TB|/2 - * also divides TB, and any odd divisor of both TB and |TA-TB|/2 also + * also divides TB, and any odd divisior of both TB and |TA-TB|/2 also * divides TA. */ - if (mbedtls_mpi_cmp_mpi(&TA, &TB) >= 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TA, &TA, &TB)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TA, 1)); - } else { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_abs(&TB, &TB, &TA)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TB, 1)); + if( mbedtls_mpi_cmp_mpi( &TA, &TB ) >= 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( &TA, &TA, &TB ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TA, 1 ) ); + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_abs( &TB, &TB, &TA ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TB, 1 ) ); } /* Note that one of TA or TB is still odd. */ } @@ -1839,179 +2340,269 @@ int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B) * In this case, lz = 0 and B = TB so gcd(A,B) = B = 2^lz * TB as well. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&TB, lz)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(G, &TB)); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &TB, lz ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( G, &TB ) ); cleanup: - mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TB); + mbedtls_mpi_free( &TA ); mbedtls_mpi_free( &TB ); - return ret; + return( ret ); +} + +/* Fill X with n_bytes random bytes. + * X must already have room for those bytes. + * The ordering of the bytes returned from the RNG is suitable for + * deterministic ECDSA (see RFC 6979 §3.3 and mbedtls_mpi_random()). + * The size and sign of X are unchanged. + * n_bytes must not be 0. + */ +static int mpi_fill_random_internal( + mbedtls_mpi *X, size_t n_bytes, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + const size_t limbs = CHARS_TO_LIMBS( n_bytes ); + const size_t overhead = ( limbs * ciL ) - n_bytes; + + if( X->n < limbs ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + + memset( X->p, 0, overhead ); + memset( (unsigned char *) X->p + limbs * ciL, 0, ( X->n - limbs ) * ciL ); + MBEDTLS_MPI_CHK( f_rng( p_rng, (unsigned char *) X->p + overhead, n_bytes ) ); + mpi_bigendian_to_host( X->p, limbs ); + +cleanup: + return( ret ); } /* * Fill X with size bytes of random. - * The bytes returned from the RNG are used in a specific order which - * is suitable for deterministic ECDSA (see the specification of - * mbedtls_mpi_random() and the implementation in mbedtls_mpi_fill_random()). + * + * Use a temporary bytes representation to make sure the result is the same + * regardless of the platform endianness (useful when f_rng is actually + * deterministic, eg for tests). */ -int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +int mbedtls_mpi_fill_random( mbedtls_mpi *X, size_t size, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - const size_t limbs = CHARS_TO_LIMBS(size); + size_t const limbs = CHARS_TO_LIMBS( size ); + + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( f_rng != NULL ); /* Ensure that target MPI has exactly the necessary number of limbs */ - MBEDTLS_MPI_CHK(mbedtls_mpi_resize_clear(X, limbs)); - if (size == 0) { - return 0; - } + MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, limbs ) ); + if( size == 0 ) + return( 0 ); - ret = mbedtls_mpi_core_fill_random(X->p, X->n, size, f_rng, p_rng); + ret = mpi_fill_random_internal( X, size, f_rng, p_rng ); cleanup: - return ret; + return( ret ); } -int mbedtls_mpi_random(mbedtls_mpi *X, - mbedtls_mpi_sint min, - const mbedtls_mpi *N, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +int mbedtls_mpi_random( mbedtls_mpi *X, + mbedtls_mpi_sint min, + const mbedtls_mpi *N, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { - if (min < 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } - if (mbedtls_mpi_cmp_int(N, min) <= 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA; + int count; + unsigned lt_lower = 1, lt_upper = 0; + size_t n_bits = mbedtls_mpi_bitlen( N ); + size_t n_bytes = ( n_bits + 7 ) / 8; + mbedtls_mpi lower_bound; + + if( min < 0 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + if( mbedtls_mpi_cmp_int( N, min ) <= 0 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + + /* + * When min == 0, each try has at worst a probability 1/2 of failing + * (the msb has a probability 1/2 of being 0, and then the result will + * be < N), so after 30 tries failure probability is a most 2**(-30). + * + * When N is just below a power of 2, as is the case when generating + * a random scalar on most elliptic curves, 1 try is enough with + * overwhelming probability. When N is just above a power of 2, + * as when generating a random scalar on secp224k1, each try has + * a probability of failing that is almost 1/2. + * + * The probabilities are almost the same if min is nonzero but negligible + * compared to N. This is always the case when N is crypto-sized, but + * it's convenient to support small N for testing purposes. When N + * is small, use a higher repeat count, otherwise the probability of + * failure is macroscopic. + */ + count = ( n_bytes > 4 ? 30 : 250 ); + + mbedtls_mpi_init( &lower_bound ); /* Ensure that target MPI has exactly the same number of limbs * as the upper bound, even if the upper bound has leading zeros. - * This is necessary for mbedtls_mpi_core_random. */ - int ret = mbedtls_mpi_resize_clear(X, N->n); - if (ret != 0) { - return ret; + * This is necessary for the mbedtls_mpi_lt_mpi_ct() check. */ + MBEDTLS_MPI_CHK( mbedtls_mpi_resize_clear( X, N->n ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( &lower_bound, N->n ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &lower_bound, min ) ); + + /* + * Match the procedure given in RFC 6979 §3.3 (deterministic ECDSA) + * when f_rng is a suitably parametrized instance of HMAC_DRBG: + * - use the same byte ordering; + * - keep the leftmost n_bits bits of the generated octet string; + * - try until result is in the desired range. + * This also avoids any bias, which is especially important for ECDSA. + */ + do + { + MBEDTLS_MPI_CHK( mpi_fill_random_internal( X, n_bytes, f_rng, p_rng ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( X, 8 * n_bytes - n_bits ) ); + + if( --count == 0 ) + { + ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; + goto cleanup; + } + + MBEDTLS_MPI_CHK( mbedtls_mpi_lt_mpi_ct( X, &lower_bound, <_lower ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lt_mpi_ct( X, N, <_upper ) ); } + while( lt_lower != 0 || lt_upper == 0 ); - return mbedtls_mpi_core_random(X->p, min, N->p, X->n, f_rng, p_rng); +cleanup: + mbedtls_mpi_free( &lower_bound ); + return( ret ); } /* * Modular inverse: X = A^-1 mod N (HAC 14.61 / 14.64) */ -int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N) +int mbedtls_mpi_inv_mod( mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi G, TA, TU, U1, U2, TB, TV, V1, V2; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( A != NULL ); + MPI_VALIDATE_RET( N != NULL ); - if (mbedtls_mpi_cmp_int(N, 1) <= 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + if( mbedtls_mpi_cmp_int( N, 1 ) <= 0 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - mbedtls_mpi_init(&TA); mbedtls_mpi_init(&TU); mbedtls_mpi_init(&U1); mbedtls_mpi_init(&U2); - mbedtls_mpi_init(&G); mbedtls_mpi_init(&TB); mbedtls_mpi_init(&TV); - mbedtls_mpi_init(&V1); mbedtls_mpi_init(&V2); + mbedtls_mpi_init( &TA ); mbedtls_mpi_init( &TU ); mbedtls_mpi_init( &U1 ); mbedtls_mpi_init( &U2 ); + mbedtls_mpi_init( &G ); mbedtls_mpi_init( &TB ); mbedtls_mpi_init( &TV ); + mbedtls_mpi_init( &V1 ); mbedtls_mpi_init( &V2 ); - MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, A, N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &G, A, N ) ); - if (mbedtls_mpi_cmp_int(&G, 1) != 0) { + if( mbedtls_mpi_cmp_int( &G, 1 ) != 0 ) + { ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; goto cleanup; } - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&TA, A, N)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TU, &TA)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TB, N)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&TV, N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &TA, A, N ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TU, &TA ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TB, N ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &TV, N ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U1, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&U2, 0)); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V1, 0)); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&V2, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &U1, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &U2, 0 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &V1, 0 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &V2, 1 ) ); - do { - while ((TU.p[0] & 1) == 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TU, 1)); - - if ((U1.p[0] & 1) != 0 || (U2.p[0] & 1) != 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&U1, &U1, &TB)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &TA)); + do + { + while( ( TU.p[0] & 1 ) == 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TU, 1 ) ); + + if( ( U1.p[0] & 1 ) != 0 || ( U2.p[0] & 1 ) != 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &U1, &U1, &TB ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &U2, &U2, &TA ) ); } - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U1, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&U2, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &U1, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &U2, 1 ) ); } - while ((TV.p[0] & 1) == 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&TV, 1)); + while( ( TV.p[0] & 1 ) == 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &TV, 1 ) ); - if ((V1.p[0] & 1) != 0 || (V2.p[0] & 1) != 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, &TB)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &TA)); + if( ( V1.p[0] & 1 ) != 0 || ( V2.p[0] & 1 ) != 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &V1, &V1, &TB ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &V2, &V2, &TA ) ); } - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V1, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&V2, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &V1, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &V2, 1 ) ); } - if (mbedtls_mpi_cmp_mpi(&TU, &TV) >= 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TU, &TU, &TV)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U1, &U1, &V1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&U2, &U2, &V2)); - } else { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&TV, &TV, &TU)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, &U1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V2, &V2, &U2)); + if( mbedtls_mpi_cmp_mpi( &TU, &TV ) >= 0 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &TU, &TU, &TV ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &U1, &U1, &V1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &U2, &U2, &V2 ) ); + } + else + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &TV, &TV, &TU ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &V1, &V1, &U1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &V2, &V2, &U2 ) ); } - } while (mbedtls_mpi_cmp_int(&TU, 0) != 0); - - while (mbedtls_mpi_cmp_int(&V1, 0) < 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&V1, &V1, N)); } + while( mbedtls_mpi_cmp_int( &TU, 0 ) != 0 ); - while (mbedtls_mpi_cmp_mpi(&V1, N) >= 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&V1, &V1, N)); - } + while( mbedtls_mpi_cmp_int( &V1, 0 ) < 0 ) + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &V1, &V1, N ) ); + + while( mbedtls_mpi_cmp_mpi( &V1, N ) >= 0 ) + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &V1, &V1, N ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(X, &V1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( X, &V1 ) ); cleanup: - mbedtls_mpi_free(&TA); mbedtls_mpi_free(&TU); mbedtls_mpi_free(&U1); mbedtls_mpi_free(&U2); - mbedtls_mpi_free(&G); mbedtls_mpi_free(&TB); mbedtls_mpi_free(&TV); - mbedtls_mpi_free(&V1); mbedtls_mpi_free(&V2); + mbedtls_mpi_free( &TA ); mbedtls_mpi_free( &TU ); mbedtls_mpi_free( &U1 ); mbedtls_mpi_free( &U2 ); + mbedtls_mpi_free( &G ); mbedtls_mpi_free( &TB ); mbedtls_mpi_free( &TV ); + mbedtls_mpi_free( &V1 ); mbedtls_mpi_free( &V2 ); - return ret; + return( ret ); } #if defined(MBEDTLS_GENPRIME) -/* Gaps between primes, starting at 3. https://oeis.org/A001223 */ -static const unsigned char small_prime_gaps[] = { - 2, 2, 4, 2, 4, 2, 4, 6, - 2, 6, 4, 2, 4, 6, 6, 2, - 6, 4, 2, 6, 4, 6, 8, 4, - 2, 4, 2, 4, 14, 4, 6, 2, - 10, 2, 6, 6, 4, 6, 6, 2, - 10, 2, 4, 2, 12, 12, 4, 2, - 4, 6, 2, 10, 6, 6, 6, 2, - 6, 4, 2, 10, 14, 4, 2, 4, - 14, 6, 10, 2, 4, 6, 8, 6, - 6, 4, 6, 8, 4, 8, 10, 2, - 10, 2, 6, 4, 6, 8, 4, 2, - 4, 12, 8, 4, 8, 4, 6, 12, - 2, 18, 6, 10, 6, 6, 2, 6, - 10, 6, 6, 2, 6, 6, 4, 2, - 12, 10, 2, 4, 6, 6, 2, 12, - 4, 6, 8, 10, 8, 10, 8, 6, - 6, 4, 8, 6, 4, 8, 4, 14, - 10, 12, 2, 10, 2, 4, 2, 10, - 14, 4, 2, 4, 14, 4, 2, 4, - 20, 4, 8, 10, 8, 4, 6, 6, - 14, 4, 6, 6, 8, 6, /*reaches 997*/ - 0 /* the last entry is effectively unused */ +static const int small_prime[] = +{ + 3, 5, 7, 11, 13, 17, 19, 23, + 29, 31, 37, 41, 43, 47, 53, 59, + 61, 67, 71, 73, 79, 83, 89, 97, + 101, 103, 107, 109, 113, 127, 131, 137, + 139, 149, 151, 157, 163, 167, 173, 179, + 181, 191, 193, 197, 199, 211, 223, 227, + 229, 233, 239, 241, 251, 257, 263, 269, + 271, 277, 281, 283, 293, 307, 311, 313, + 317, 331, 337, 347, 349, 353, 359, 367, + 373, 379, 383, 389, 397, 401, 409, 419, + 421, 431, 433, 439, 443, 449, 457, 461, + 463, 467, 479, 487, 491, 499, 503, 509, + 521, 523, 541, 547, 557, 563, 569, 571, + 577, 587, 593, 599, 601, 607, 613, 617, + 619, 631, 641, 643, 647, 653, 659, 661, + 673, 677, 683, 691, 701, 709, 719, 727, + 733, 739, 743, 751, 757, 761, 769, 773, + 787, 797, 809, 811, 821, 823, 827, 829, + 839, 853, 857, 859, 863, 877, 881, 883, + 887, 907, 911, 919, 929, 937, 941, 947, + 953, 967, 971, 977, 983, 991, 997, -103 }; /* @@ -2023,68 +2614,70 @@ static const unsigned char small_prime_gaps[] = { * MBEDTLS_ERR_MPI_NOT_ACCEPTABLE: certain non-prime * other negative: error */ -static int mpi_check_small_factors(const mbedtls_mpi *X) +static int mpi_check_small_factors( const mbedtls_mpi *X ) { int ret = 0; size_t i; mbedtls_mpi_uint r; - unsigned p = 3; /* The first odd prime */ - if ((X->p[0] & 1) == 0) { - return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; - } + if( ( X->p[0] & 1 ) == 0 ) + return( MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ); - for (i = 0; i < sizeof(small_prime_gaps); p += small_prime_gaps[i], i++) { - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_int(&r, X, p)); - if (r == 0) { - if (mbedtls_mpi_cmp_int(X, p) == 0) { - return 1; - } else { - return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; - } - } + for( i = 0; small_prime[i] > 0; i++ ) + { + if( mbedtls_mpi_cmp_int( X, small_prime[i] ) <= 0 ) + return( 1 ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, small_prime[i] ) ); + + if( r == 0 ) + return( MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ); } cleanup: - return ret; + return( ret ); } /* * Miller-Rabin pseudo-primality test (HAC 4.24) */ -static int mpi_miller_rabin(const mbedtls_mpi *X, size_t rounds, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +static int mpi_miller_rabin( const mbedtls_mpi *X, size_t rounds, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret, count; size_t i, j, k, s; mbedtls_mpi W, R, T, A, RR; - mbedtls_mpi_init(&W); mbedtls_mpi_init(&R); - mbedtls_mpi_init(&T); mbedtls_mpi_init(&A); - mbedtls_mpi_init(&RR); + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( f_rng != NULL ); + + mbedtls_mpi_init( &W ); mbedtls_mpi_init( &R ); + mbedtls_mpi_init( &T ); mbedtls_mpi_init( &A ); + mbedtls_mpi_init( &RR ); /* * W = |X| - 1 * R = W >> lsb( W ) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&W, X, 1)); - s = mbedtls_mpi_lsb(&W); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&R, &W)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&R, s)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &W, X, 1 ) ); + s = mbedtls_mpi_lsb( &W ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &R, &W ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &R, s ) ); - for (i = 0; i < rounds; i++) { + for( i = 0; i < rounds; i++ ) + { /* * pick a random A, 1 < A < |X| - 1 */ count = 0; do { - MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&A, X->n * ciL, f_rng, p_rng)); + MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &A, X->n * ciL, f_rng, p_rng ) ); - j = mbedtls_mpi_bitlen(&A); - k = mbedtls_mpi_bitlen(&W); + j = mbedtls_mpi_bitlen( &A ); + k = mbedtls_mpi_bitlen( &W ); if (j > k) { - A.p[A.n - 1] &= ((mbedtls_mpi_uint) 1 << (k - (A.n - 1) * biL - 1)) - 1; + A.p[A.n - 1] &= ( (mbedtls_mpi_uint) 1 << ( k - ( A.n - 1 ) * biL - 1 ) ) - 1; } if (count++ > 30) { @@ -2092,30 +2685,29 @@ static int mpi_miller_rabin(const mbedtls_mpi *X, size_t rounds, goto cleanup; } - } while (mbedtls_mpi_cmp_mpi(&A, &W) >= 0 || - mbedtls_mpi_cmp_int(&A, 1) <= 0); + } while ( mbedtls_mpi_cmp_mpi( &A, &W ) >= 0 || + mbedtls_mpi_cmp_int( &A, 1 ) <= 0 ); /* * A = A^R mod |X| */ - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&A, &A, &R, X, &RR)); + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &A, &A, &R, X, &RR ) ); - if (mbedtls_mpi_cmp_mpi(&A, &W) == 0 || - mbedtls_mpi_cmp_int(&A, 1) == 0) { + if( mbedtls_mpi_cmp_mpi( &A, &W ) == 0 || + mbedtls_mpi_cmp_int( &A, 1 ) == 0 ) continue; - } j = 1; - while (j < s && mbedtls_mpi_cmp_mpi(&A, &W) != 0) { + while( j < s && mbedtls_mpi_cmp_mpi( &A, &W ) != 0 ) + { /* * A = A * A mod |X| */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, &A, &A)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&A, &T, X)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T, &A, &A ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &A, &T, X ) ); - if (mbedtls_mpi_cmp_int(&A, 1) == 0) { + if( mbedtls_mpi_cmp_int( &A, 1 ) == 0 ) break; - } j++; } @@ -2123,53 +2715,54 @@ static int mpi_miller_rabin(const mbedtls_mpi *X, size_t rounds, /* * not prime if A != |X| - 1 or A == 1 */ - if (mbedtls_mpi_cmp_mpi(&A, &W) != 0 || - mbedtls_mpi_cmp_int(&A, 1) == 0) { + if( mbedtls_mpi_cmp_mpi( &A, &W ) != 0 || + mbedtls_mpi_cmp_int( &A, 1 ) == 0 ) + { ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; break; } } cleanup: - mbedtls_mpi_free(&W); mbedtls_mpi_free(&R); - mbedtls_mpi_free(&T); mbedtls_mpi_free(&A); - mbedtls_mpi_free(&RR); + mbedtls_mpi_free( &W ); mbedtls_mpi_free( &R ); + mbedtls_mpi_free( &T ); mbedtls_mpi_free( &A ); + mbedtls_mpi_free( &RR ); - return ret; + return( ret ); } /* * Pseudo-primality test: small factors, then Miller-Rabin */ -int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi XX; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( f_rng != NULL ); XX.s = 1; XX.n = X->n; XX.p = X->p; - if (mbedtls_mpi_cmp_int(&XX, 0) == 0 || - mbedtls_mpi_cmp_int(&XX, 1) == 0) { - return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; - } + if( mbedtls_mpi_cmp_int( &XX, 0 ) == 0 || + mbedtls_mpi_cmp_int( &XX, 1 ) == 0 ) + return( MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ); - if (mbedtls_mpi_cmp_int(&XX, 2) == 0) { - return 0; - } + if( mbedtls_mpi_cmp_int( &XX, 2 ) == 0 ) + return( 0 ); - if ((ret = mpi_check_small_factors(&XX)) != 0) { - if (ret == 1) { - return 0; - } + if( ( ret = mpi_check_small_factors( &XX ) ) != 0 ) + { + if( ret == 1 ) + return( 0 ); - return ret; + return( ret ); } - return mpi_miller_rabin(&XX, rounds, f_rng, p_rng); + return( mpi_miller_rabin( &XX, rounds, f_rng, p_rng ) ); } /* @@ -2179,9 +2772,9 @@ int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds, * be either 1024 bits or 1536 bits long, and flags must contain * MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR. */ -int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { #ifdef MBEDTLS_HAVE_INT64 // ceil(2^63.5) @@ -2196,105 +2789,107 @@ int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags, mbedtls_mpi_uint r; mbedtls_mpi Y; - if (nbits < 3 || nbits > MBEDTLS_MPI_MAX_BITS) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( f_rng != NULL ); - mbedtls_mpi_init(&Y); + if( nbits < 3 || nbits > MBEDTLS_MPI_MAX_BITS ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - n = BITS_TO_LIMBS(nbits); + mbedtls_mpi_init( &Y ); - if ((flags & MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR) == 0) { + n = BITS_TO_LIMBS( nbits ); + + if( ( flags & MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR ) == 0 ) + { /* * 2^-80 error probability, number of rounds chosen per HAC, table 4.4 */ - rounds = ((nbits >= 1300) ? 2 : (nbits >= 850) ? 3 : - (nbits >= 650) ? 4 : (nbits >= 350) ? 8 : - (nbits >= 250) ? 12 : (nbits >= 150) ? 18 : 27); - } else { + rounds = ( ( nbits >= 1300 ) ? 2 : ( nbits >= 850 ) ? 3 : + ( nbits >= 650 ) ? 4 : ( nbits >= 350 ) ? 8 : + ( nbits >= 250 ) ? 12 : ( nbits >= 150 ) ? 18 : 27 ); + } + else + { /* * 2^-100 error probability, number of rounds computed based on HAC, * fact 4.48 */ - rounds = ((nbits >= 1450) ? 4 : (nbits >= 1150) ? 5 : - (nbits >= 1000) ? 6 : (nbits >= 850) ? 7 : - (nbits >= 750) ? 8 : (nbits >= 500) ? 13 : - (nbits >= 250) ? 28 : (nbits >= 150) ? 40 : 51); + rounds = ( ( nbits >= 1450 ) ? 4 : ( nbits >= 1150 ) ? 5 : + ( nbits >= 1000 ) ? 6 : ( nbits >= 850 ) ? 7 : + ( nbits >= 750 ) ? 8 : ( nbits >= 500 ) ? 13 : + ( nbits >= 250 ) ? 28 : ( nbits >= 150 ) ? 40 : 51 ); } - while (1) { - MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(X, n * ciL, f_rng, p_rng)); + while( 1 ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( X, n * ciL, f_rng, p_rng ) ); /* make sure generated number is at least (nbits-1)+0.5 bits (FIPS 186-4 §B.3.3 steps 4.4, 5.5) */ - if (X->p[n-1] < CEIL_MAXUINT_DIV_SQRT2) { - continue; - } + if( X->p[n-1] < CEIL_MAXUINT_DIV_SQRT2 ) continue; k = n * biL; - if (k > nbits) { - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(X, k - nbits)); - } + if( k > nbits ) MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( X, k - nbits ) ); X->p[0] |= 1; - if ((flags & MBEDTLS_MPI_GEN_PRIME_FLAG_DH) == 0) { - ret = mbedtls_mpi_is_prime_ext(X, rounds, f_rng, p_rng); + if( ( flags & MBEDTLS_MPI_GEN_PRIME_FLAG_DH ) == 0 ) + { + ret = mbedtls_mpi_is_prime_ext( X, rounds, f_rng, p_rng ); - if (ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) { + if( ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ) goto cleanup; - } - } else { + } + else + { /* - * A necessary condition for Y and X = 2Y + 1 to be prime + * An necessary condition for Y and X = 2Y + 1 to be prime * is X = 2 mod 3 (which is equivalent to Y = 2 mod 3). * Make sure it is satisfied, while keeping X = 3 mod 4 */ X->p[0] |= 2; - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_int(&r, X, 3)); - if (r == 0) { - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X, X, 8)); - } else if (r == 1) { - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X, X, 4)); - } + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_int( &r, X, 3 ) ); + if( r == 0 ) + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( X, X, 8 ) ); + else if( r == 1 ) + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( X, X, 4 ) ); /* Set Y = (X-1) / 2, which is X / 2 because X is odd */ - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&Y, X)); - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&Y, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &Y, X ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &Y, 1 ) ); - while (1) { + while( 1 ) + { /* * First, check small factors for X and Y * before doing Miller-Rabin on any of them */ - if ((ret = mpi_check_small_factors(X)) == 0 && - (ret = mpi_check_small_factors(&Y)) == 0 && - (ret = mpi_miller_rabin(X, rounds, f_rng, p_rng)) - == 0 && - (ret = mpi_miller_rabin(&Y, rounds, f_rng, p_rng)) - == 0) { + if( ( ret = mpi_check_small_factors( X ) ) == 0 && + ( ret = mpi_check_small_factors( &Y ) ) == 0 && + ( ret = mpi_miller_rabin( X, rounds, f_rng, p_rng ) ) + == 0 && + ( ret = mpi_miller_rabin( &Y, rounds, f_rng, p_rng ) ) + == 0 ) goto cleanup; - } - if (ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) { + if( ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ) goto cleanup; - } /* * Next candidates. We want to preserve Y = (X-1) / 2 and * Y = 1 mod 2 and Y = 2 mod 3 (eq X = 3 mod 4 and X = 2 mod 3) * so up Y by 6 and X by 12. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(X, X, 12)); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&Y, &Y, 6)); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( X, X, 12 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( &Y, &Y, 6 ) ); } } } cleanup: - mbedtls_mpi_free(&Y); + mbedtls_mpi_free( &Y ); - return ret; + return( ret ); } #endif /* MBEDTLS_GENPRIME */ @@ -2313,173 +2908,162 @@ static const int gcd_pairs[GCD_PAIR_COUNT][3] = /* * Checkup routine */ -int mbedtls_mpi_self_test(int verbose) +int mbedtls_mpi_self_test( int verbose ) { int ret, i; mbedtls_mpi A, E, N, X, Y, U, V; - mbedtls_mpi_init(&A); mbedtls_mpi_init(&E); mbedtls_mpi_init(&N); mbedtls_mpi_init(&X); - mbedtls_mpi_init(&Y); mbedtls_mpi_init(&U); mbedtls_mpi_init(&V); - - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&A, 16, - "EFE021C2645FD1DC586E69184AF4A31E" \ - "D5F53E93B5F123FA41680867BA110131" \ - "944FE7952E2517337780CB0DB80E61AA" \ - "E7C8DDC6C5C6AADEB34EB38A2F40D5E6")); - - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&E, 16, - "B2E7EFD37075B9F03FF989C7C5051C20" \ - "34D2A323810251127E7BF8625A4F49A5" \ - "F3E27F4DA8BD59C47D6DAABA4C8127BD" \ - "5B5C25763222FEFCCFC38B832366C29E")); - - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&N, 16, - "0066A198186C18C10B2F5ED9B522752A" \ - "9830B69916E535C8F047518A889A43A5" \ - "94B6BED27A168D31D4A52F88925AA8F5")); - - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&X, &A, &N)); - - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16, - "602AB7ECA597A3D6B56FF9829A5E8B85" \ - "9E857EA95A03512E2BAE7391688D264A" \ - "A5663B0341DB9CCFD2C4C5F421FEC814" \ - "8001B72E848A38CAE1C65F78E56ABDEF" \ - "E12D3C039B8A02D6BE593F0BBBDA56F1" \ - "ECF677152EF804370C1A305CAF3B5BF1" \ - "30879B56C61DE584A0F53A2447A51E")); - - if (verbose != 0) { - mbedtls_printf(" MPI test #1 (mul_mpi): "); - } - - if (mbedtls_mpi_cmp_mpi(&X, &U) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + mbedtls_mpi_init( &A ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &N ); mbedtls_mpi_init( &X ); + mbedtls_mpi_init( &Y ); mbedtls_mpi_init( &U ); mbedtls_mpi_init( &V ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &A, 16, + "EFE021C2645FD1DC586E69184AF4A31E" \ + "D5F53E93B5F123FA41680867BA110131" \ + "944FE7952E2517337780CB0DB80E61AA" \ + "E7C8DDC6C5C6AADEB34EB38A2F40D5E6" ) ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &E, 16, + "B2E7EFD37075B9F03FF989C7C5051C20" \ + "34D2A323810251127E7BF8625A4F49A5" \ + "F3E27F4DA8BD59C47D6DAABA4C8127BD" \ + "5B5C25763222FEFCCFC38B832366C29E" ) ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &N, 16, + "0066A198186C18C10B2F5ED9B522752A" \ + "9830B69916E535C8F047518A889A43A5" \ + "94B6BED27A168D31D4A52F88925AA8F5" ) ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &X, &A, &N ) ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16, + "602AB7ECA597A3D6B56FF9829A5E8B85" \ + "9E857EA95A03512E2BAE7391688D264A" \ + "A5663B0341DB9CCFD2C4C5F421FEC814" \ + "8001B72E848A38CAE1C65F78E56ABDEF" \ + "E12D3C039B8A02D6BE593F0BBBDA56F1" \ + "ECF677152EF804370C1A305CAF3B5BF1" \ + "30879B56C61DE584A0F53A2447A51E" ) ); + + if( verbose != 0 ) + mbedtls_printf( " MPI test #1 (mul_mpi): " ); + + if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); - MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(&X, &Y, &A, &N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &X, &Y, &A, &N ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16, - "256567336059E52CAE22925474705F39A94")); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16, + "256567336059E52CAE22925474705F39A94" ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&V, 16, - "6613F26162223DF488E9CD48CC132C7A" \ - "0AC93C701B001B092E4E5B9F73BCD27B" \ - "9EE50D0657C77F374E903CDFA4C642")); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &V, 16, + "6613F26162223DF488E9CD48CC132C7A" \ + "0AC93C701B001B092E4E5B9F73BCD27B" \ + "9EE50D0657C77F374E903CDFA4C642" ) ); - if (verbose != 0) { - mbedtls_printf(" MPI test #2 (div_mpi): "); - } + if( verbose != 0 ) + mbedtls_printf( " MPI test #2 (div_mpi): " ); - if (mbedtls_mpi_cmp_mpi(&X, &U) != 0 || - mbedtls_mpi_cmp_mpi(&Y, &V) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 || + mbedtls_mpi_cmp_mpi( &Y, &V ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&X, &A, &E, &N, NULL)); + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &X, &A, &E, &N, NULL ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16, - "36E139AEA55215609D2816998ED020BB" \ - "BD96C37890F65171D948E9BC7CBAA4D9" \ - "325D24D6A3C12710F10A09FA08AB87")); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16, + "36E139AEA55215609D2816998ED020BB" \ + "BD96C37890F65171D948E9BC7CBAA4D9" \ + "325D24D6A3C12710F10A09FA08AB87" ) ); - if (verbose != 0) { - mbedtls_printf(" MPI test #3 (exp_mod): "); - } + if( verbose != 0 ) + mbedtls_printf( " MPI test #3 (exp_mod): " ); - if (mbedtls_mpi_cmp_mpi(&X, &U) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); - MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&X, &A, &N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &X, &A, &N ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&U, 16, - "003A0AAEDD7E784FC07D8F9EC6E3BFD5" \ - "C3DBA76456363A10869622EAC2DD84EC" \ - "C5B8A74DAC4D09E03B5E0BE779F2DF61")); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &U, 16, + "003A0AAEDD7E784FC07D8F9EC6E3BFD5" \ + "C3DBA76456363A10869622EAC2DD84EC" \ + "C5B8A74DAC4D09E03B5E0BE779F2DF61" ) ); - if (verbose != 0) { - mbedtls_printf(" MPI test #4 (inv_mod): "); - } + if( verbose != 0 ) + mbedtls_printf( " MPI test #4 (inv_mod): " ); - if (mbedtls_mpi_cmp_mpi(&X, &U) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_mpi_cmp_mpi( &X, &U ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); - if (verbose != 0) { - mbedtls_printf(" MPI test #5 (simple gcd): "); - } + if( verbose != 0 ) + mbedtls_printf( " MPI test #5 (simple gcd): " ); - for (i = 0; i < GCD_PAIR_COUNT; i++) { - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&X, gcd_pairs[i][0])); - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&Y, gcd_pairs[i][1])); + for( i = 0; i < GCD_PAIR_COUNT; i++ ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &X, gcd_pairs[i][0] ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &Y, gcd_pairs[i][1] ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&A, &X, &Y)); + MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &A, &X, &Y ) ); - if (mbedtls_mpi_cmp_int(&A, gcd_pairs[i][2]) != 0) { - if (verbose != 0) { - mbedtls_printf("failed at %d\n", i); - } + if( mbedtls_mpi_cmp_int( &A, gcd_pairs[i][2] ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed at %d\n", i ); ret = 1; goto cleanup; } } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); cleanup: - if (ret != 0 && verbose != 0) { - mbedtls_printf("Unexpected error, return code = %08X\n", (unsigned int) ret); - } + if( ret != 0 && verbose != 0 ) + mbedtls_printf( "Unexpected error, return code = %08X\n", (unsigned int) ret ); - mbedtls_mpi_free(&A); mbedtls_mpi_free(&E); mbedtls_mpi_free(&N); mbedtls_mpi_free(&X); - mbedtls_mpi_free(&Y); mbedtls_mpi_free(&U); mbedtls_mpi_free(&V); + mbedtls_mpi_free( &A ); mbedtls_mpi_free( &E ); mbedtls_mpi_free( &N ); mbedtls_mpi_free( &X ); + mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &U ); mbedtls_mpi_free( &V ); - if (verbose != 0) { - mbedtls_printf("\n"); - } + if( verbose != 0 ) + mbedtls_printf( "\n" ); - return ret; + return( ret ); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/library/bn_mul.h b/src/duckdb/third_party/mbedtls/library/bn_mul.h index 0738469db..b71ddd881 100644 --- a/src/duckdb/third_party/mbedtls/library/bn_mul.h +++ b/src/duckdb/third_party/mbedtls/library/bn_mul.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * Multiply source vector [s] with b, add result @@ -35,72 +47,58 @@ */ #if defined(MBEDTLS_HAVE_INT32) -#define MBEDTLS_BYTES_TO_T_UINT_4(a, b, c, d) \ - ((mbedtls_mpi_uint) (a) << 0) | \ - ((mbedtls_mpi_uint) (b) << 8) | \ - ((mbedtls_mpi_uint) (c) << 16) | \ - ((mbedtls_mpi_uint) (d) << 24) +#define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ) \ + ( (mbedtls_mpi_uint) (a) << 0 ) | \ + ( (mbedtls_mpi_uint) (b) << 8 ) | \ + ( (mbedtls_mpi_uint) (c) << 16 ) | \ + ( (mbedtls_mpi_uint) (d) << 24 ) -#define MBEDTLS_BYTES_TO_T_UINT_2(a, b) \ - MBEDTLS_BYTES_TO_T_UINT_4(a, b, 0, 0) +#define MBEDTLS_BYTES_TO_T_UINT_2( a, b ) \ + MBEDTLS_BYTES_TO_T_UINT_4( a, b, 0, 0 ) -#define MBEDTLS_BYTES_TO_T_UINT_8(a, b, c, d, e, f, g, h) \ - MBEDTLS_BYTES_TO_T_UINT_4(a, b, c, d), \ - MBEDTLS_BYTES_TO_T_UINT_4(e, f, g, h) +#define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \ + MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ), \ + MBEDTLS_BYTES_TO_T_UINT_4( e, f, g, h ) #else /* 64-bits */ -#define MBEDTLS_BYTES_TO_T_UINT_8(a, b, c, d, e, f, g, h) \ - ((mbedtls_mpi_uint) (a) << 0) | \ - ((mbedtls_mpi_uint) (b) << 8) | \ - ((mbedtls_mpi_uint) (c) << 16) | \ - ((mbedtls_mpi_uint) (d) << 24) | \ - ((mbedtls_mpi_uint) (e) << 32) | \ - ((mbedtls_mpi_uint) (f) << 40) | \ - ((mbedtls_mpi_uint) (g) << 48) | \ - ((mbedtls_mpi_uint) (h) << 56) +#define MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, e, f, g, h ) \ + ( (mbedtls_mpi_uint) (a) << 0 ) | \ + ( (mbedtls_mpi_uint) (b) << 8 ) | \ + ( (mbedtls_mpi_uint) (c) << 16 ) | \ + ( (mbedtls_mpi_uint) (d) << 24 ) | \ + ( (mbedtls_mpi_uint) (e) << 32 ) | \ + ( (mbedtls_mpi_uint) (f) << 40 ) | \ + ( (mbedtls_mpi_uint) (g) << 48 ) | \ + ( (mbedtls_mpi_uint) (h) << 56 ) -#define MBEDTLS_BYTES_TO_T_UINT_4(a, b, c, d) \ - MBEDTLS_BYTES_TO_T_UINT_8(a, b, c, d, 0, 0, 0, 0) +#define MBEDTLS_BYTES_TO_T_UINT_4( a, b, c, d ) \ + MBEDTLS_BYTES_TO_T_UINT_8( a, b, c, d, 0, 0, 0, 0 ) -#define MBEDTLS_BYTES_TO_T_UINT_2(a, b) \ - MBEDTLS_BYTES_TO_T_UINT_8(a, b, 0, 0, 0, 0, 0, 0) +#define MBEDTLS_BYTES_TO_T_UINT_2( a, b ) \ + MBEDTLS_BYTES_TO_T_UINT_8( a, b, 0, 0, 0, 0, 0, 0 ) #endif /* bits in mbedtls_mpi_uint */ -/* *INDENT-OFF* */ #if defined(MBEDTLS_HAVE_ASM) +#ifndef asm +#define asm __asm +#endif + /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */ #if defined(__GNUC__) && \ ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 ) -/* - * GCC < 5.0 treated the x86 ebx (which is used for the GOT) as a - * fixed reserved register when building as PIC, leading to errors - * like: bn_mul.h:46:13: error: PIC register clobbered by 'ebx' in 'asm' - * - * This is fixed by an improved register allocator in GCC 5+. From the - * release notes: - * Register allocation improvements: Reuse of the PIC hard register, - * instead of using a fixed register, was implemented on x86/x86-64 - * targets. This improves generated PIC code performance as more hard - * registers can be used. - */ -#if defined(__GNUC__) && __GNUC__ < 5 && defined(__PIC__) -#define MULADDC_CANNOT_USE_EBX -#endif - /* * Disable use of the i386 assembly code below if option -O0, to disable all * compiler optimisations, is passed, detected with __OPTIMIZE__ * This is done as the number of registers used in the assembly code doesn't * work with the -O0 option. */ -#if defined(__i386__) && defined(__OPTIMIZE__) && !defined(MULADDC_CANNOT_USE_EBX) +#if defined(__i386__) && defined(__OPTIMIZE__) -#define MULADDC_X1_INIT \ - { mbedtls_mpi_uint t; \ +#define MULADDC_INIT \ asm( \ "movl %%ebx, %0 \n\t" \ "movl %5, %%esi \n\t" \ @@ -108,7 +106,7 @@ "movl %7, %%ecx \n\t" \ "movl %8, %%ebx \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "lodsl \n\t" \ "mull %%ebx \n\t" \ "addl %%ecx, %%eax \n\t" \ @@ -118,21 +116,9 @@ "movl %%edx, %%ecx \n\t" \ "stosl \n\t" -#define MULADDC_X1_STOP \ - "movl %4, %%ebx \n\t" \ - "movl %%ecx, %1 \n\t" \ - "movl %%edi, %2 \n\t" \ - "movl %%esi, %3 \n\t" \ - : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \ - : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \ - : "eax", "ebx", "ecx", "edx", "esi", "edi" \ - ); } - #if defined(MBEDTLS_HAVE_SSE2) -#define MULADDC_X8_INIT MULADDC_X1_INIT - -#define MULADDC_X8_CORE \ +#define MULADDC_HUIT \ "movd %%ecx, %%mm1 \n\t" \ "movd %%ebx, %%mm0 \n\t" \ "movd (%%edi), %%mm3 \n\t" \ @@ -195,7 +181,7 @@ "psrlq $32, %%mm1 \n\t" \ "movd %%mm1, %%ecx \n\t" -#define MULADDC_X8_STOP \ +#define MULADDC_STOP \ "emms \n\t" \ "movl %4, %%ebx \n\t" \ "movl %%ecx, %1 \n\t" \ @@ -204,19 +190,29 @@ : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \ : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \ : "eax", "ebx", "ecx", "edx", "esi", "edi" \ - ); } \ + ); -#endif /* SSE2 */ +#else +#define MULADDC_STOP \ + "movl %4, %%ebx \n\t" \ + "movl %%ecx, %1 \n\t" \ + "movl %%edi, %2 \n\t" \ + "movl %%esi, %3 \n\t" \ + : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \ + : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \ + : "eax", "ebx", "ecx", "edx", "esi", "edi" \ + ); +#endif /* SSE2 */ #endif /* i386 */ #if defined(__amd64__) || defined (__x86_64__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "xorq %%r8, %%r8\n" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "movq (%%rsi), %%rax\n" \ "mulq %%rbx\n" \ "addq $8, %%rsi\n" \ @@ -228,7 +224,7 @@ "adcq %%rdx, %%rcx\n" \ "addq $8, %%rdi\n" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ : "+c" (c), "+D" (d), "+S" (s), "+m" (*(uint64_t (*)[16]) d) \ : "b" (b), "m" (*(const uint64_t (*)[16]) s) \ : "rax", "rdx", "r8" \ @@ -236,45 +232,33 @@ #endif /* AMD64 */ -// The following assembly code assumes that a pointer will fit in a 64-bit register -// (including ILP32 __aarch64__ ABIs such as on watchOS, hence the 2^32 - 1) -#if defined(__aarch64__) && (UINTPTR_MAX == 0xfffffffful || UINTPTR_MAX == 0xfffffffffffffffful) +#if defined(__aarch64__) -/* - * There are some issues around different compilers requiring different constraint - * syntax for updating pointers from assembly code (see notes for - * MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT in common.h), especially on aarch64_32 (aka ILP32). - * - * For this reason we cast the pointers to/from uintptr_t here. - */ -#define MULADDC_X1_INIT \ - do { uintptr_t muladdc_d = (uintptr_t) d, muladdc_s = (uintptr_t) s; asm( +#define MULADDC_INIT \ + asm( -#define MULADDC_X1_CORE \ - "ldr x4, [%x2], #8 \n\t" \ - "ldr x5, [%x1] \n\t" \ +#define MULADDC_CORE \ + "ldr x4, [%2], #8 \n\t" \ + "ldr x5, [%1] \n\t" \ "mul x6, x4, %4 \n\t" \ "umulh x7, x4, %4 \n\t" \ "adds x5, x5, x6 \n\t" \ "adc x7, x7, xzr \n\t" \ "adds x5, x5, %0 \n\t" \ "adc %0, x7, xzr \n\t" \ - "str x5, [%x1], #8 \n\t" + "str x5, [%1], #8 \n\t" -#define MULADDC_X1_STOP \ - : "+r" (c), \ - "+r" (muladdc_d), \ - "+r" (muladdc_s), \ - "+m" (*(uint64_t (*)[16]) d) \ +#define MULADDC_STOP \ + : "+r" (c), "+r" (d), "+r" (s), "+m" (*(uint64_t (*)[16]) d) \ : "r" (b), "m" (*(const uint64_t (*)[16]) s) \ : "x4", "x5", "x6", "x7", "cc" \ - ); d = (mbedtls_mpi_uint *)muladdc_d; s = (mbedtls_mpi_uint *)muladdc_s; } while (0); + ); #endif /* Aarch64 */ #if defined(__mc68020__) || defined(__mcpu32__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "movl %3, %%a2 \n\t" \ "movl %4, %%a3 \n\t" \ @@ -282,7 +266,7 @@ "movl %6, %%d2 \n\t" \ "moveq #0, %%d0 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "movel %%a2@+, %%d1 \n\t" \ "mulul %%d2, %%d4:%%d1 \n\t" \ "addl %%d3, %%d1 \n\t" \ @@ -291,7 +275,7 @@ "addl %%d1, %%a3@+ \n\t" \ "addxl %%d4, %%d3 \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "movl %%d3, %0 \n\t" \ "movl %%a3, %1 \n\t" \ "movl %%a2, %2 \n\t" \ @@ -300,9 +284,7 @@ : "d0", "d1", "d2", "d3", "d4", "a2", "a3" \ ); -#define MULADDC_X8_INIT MULADDC_X1_INIT - -#define MULADDC_X8_CORE \ +#define MULADDC_HUIT \ "movel %%a2@+, %%d1 \n\t" \ "mulul %%d2, %%d4:%%d1 \n\t" \ "addxl %%d3, %%d1 \n\t" \ @@ -345,15 +327,13 @@ "addl %%d1, %%a3@+ \n\t" \ "addxl %%d0, %%d3 \n\t" -#define MULADDC_X8_STOP MULADDC_X1_STOP - #endif /* MC68000 */ #if defined(__powerpc64__) || defined(__ppc64__) #if defined(__MACH__) && defined(__APPLE__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "ld r3, %3 \n\t" \ "ld r4, %4 \n\t" \ @@ -363,7 +343,7 @@ "addi r4, r4, -8 \n\t" \ "addic r5, r5, 0 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "ldu r7, 8(r3) \n\t" \ "mulld r8, r7, r6 \n\t" \ "mulhdu r9, r7, r6 \n\t" \ @@ -373,7 +353,7 @@ "addc r8, r8, r7 \n\t" \ "stdu r8, 8(r4) \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "addze r5, r5 \n\t" \ "addi r4, r4, 8 \n\t" \ "addi r3, r3, 8 \n\t" \ @@ -388,7 +368,7 @@ #else /* __MACH__ && __APPLE__ */ -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "ld %%r3, %3 \n\t" \ "ld %%r4, %4 \n\t" \ @@ -398,7 +378,7 @@ "addi %%r4, %%r4, -8 \n\t" \ "addic %%r5, %%r5, 0 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "ldu %%r7, 8(%%r3) \n\t" \ "mulld %%r8, %%r7, %%r6 \n\t" \ "mulhdu %%r9, %%r7, %%r6 \n\t" \ @@ -408,7 +388,7 @@ "addc %%r8, %%r8, %%r7 \n\t" \ "stdu %%r8, 8(%%r4) \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "addze %%r5, %%r5 \n\t" \ "addi %%r4, %%r4, 8 \n\t" \ "addi %%r3, %%r3, 8 \n\t" \ @@ -426,7 +406,7 @@ #if defined(__MACH__) && defined(__APPLE__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "lwz r3, %3 \n\t" \ "lwz r4, %4 \n\t" \ @@ -436,7 +416,7 @@ "addi r4, r4, -4 \n\t" \ "addic r5, r5, 0 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "lwzu r7, 4(r3) \n\t" \ "mullw r8, r7, r6 \n\t" \ "mulhwu r9, r7, r6 \n\t" \ @@ -446,7 +426,7 @@ "addc r8, r8, r7 \n\t" \ "stwu r8, 4(r4) \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "addze r5, r5 \n\t" \ "addi r4, r4, 4 \n\t" \ "addi r3, r3, 4 \n\t" \ @@ -460,7 +440,7 @@ #else /* __MACH__ && __APPLE__ */ -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "lwz %%r3, %3 \n\t" \ "lwz %%r4, %4 \n\t" \ @@ -470,7 +450,7 @@ "addi %%r4, %%r4, -4 \n\t" \ "addic %%r5, %%r5, 0 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "lwzu %%r7, 4(%%r3) \n\t" \ "mullw %%r8, %%r7, %%r6 \n\t" \ "mulhwu %%r9, %%r7, %%r6 \n\t" \ @@ -480,7 +460,7 @@ "addc %%r8, %%r8, %%r7 \n\t" \ "stwu %%r8, 4(%%r4) \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "addze %%r5, %%r5 \n\t" \ "addi %%r4, %%r4, 4 \n\t" \ "addi %%r3, %%r3, 4 \n\t" \ @@ -503,14 +483,14 @@ #if 0 && defined(__sparc__) #if defined(__sparc64__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "ldx %3, %%o0 \n\t" \ "ldx %4, %%o1 \n\t" \ "ld %5, %%o2 \n\t" \ "ld %6, %%o3 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "ld [%%o0], %%o4 \n\t" \ "inc 4, %%o0 \n\t" \ "ld [%%o1], %%o5 \n\t" \ @@ -523,7 +503,7 @@ "addx %%g1, 0, %%o2 \n\t" \ "inc 4, %%o1 \n\t" -#define MULADDC_X1_STOP \ + #define MULADDC_STOP \ "st %%o2, %0 \n\t" \ "stx %%o1, %1 \n\t" \ "stx %%o0, %2 \n\t" \ @@ -535,14 +515,14 @@ #else /* __sparc64__ */ -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "ld %3, %%o0 \n\t" \ "ld %4, %%o1 \n\t" \ "ld %5, %%o2 \n\t" \ "ld %6, %%o3 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "ld [%%o0], %%o4 \n\t" \ "inc 4, %%o0 \n\t" \ "ld [%%o1], %%o5 \n\t" \ @@ -555,7 +535,7 @@ "addx %%g1, 0, %%o2 \n\t" \ "inc 4, %%o1 \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "st %%o2, %0 \n\t" \ "st %%o1, %1 \n\t" \ "st %%o0, %2 \n\t" \ @@ -570,7 +550,7 @@ #if defined(__microblaze__) || defined(microblaze) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "lwi r3, %3 \n\t" \ "lwi r4, %4 \n\t" \ @@ -579,20 +559,10 @@ "andi r7, r6, 0xffff \n\t" \ "bsrli r6, r6, 16 \n\t" -#if(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) -#define MULADDC_LHUI \ - "lhui r9, r3, 0 \n\t" \ - "addi r3, r3, 2 \n\t" \ - "lhui r8, r3, 0 \n\t" -#else -#define MULADDC_LHUI \ +#define MULADDC_CORE \ "lhui r8, r3, 0 \n\t" \ "addi r3, r3, 2 \n\t" \ - "lhui r9, r3, 0 \n\t" -#endif - -#define MULADDC_X1_CORE \ - MULADDC_LHUI \ + "lhui r9, r3, 0 \n\t" \ "addi r3, r3, 2 \n\t" \ "mul r10, r9, r6 \n\t" \ "mul r11, r8, r7 \n\t" \ @@ -616,7 +586,7 @@ "swi r12, r4, 0 \n\t" \ "addi r4, r4, 4 \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "swi r5, %0 \n\t" \ "swi r4, %1 \n\t" \ "swi r3, %2 \n\t" \ @@ -630,7 +600,7 @@ #if defined(__tricore__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "ld.a %%a2, %3 \n\t" \ "ld.a %%a3, %4 \n\t" \ @@ -638,7 +608,7 @@ "ld.w %%d1, %6 \n\t" \ "xor %%d5, %%d5 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "ld.w %%d0, [%%a2+] \n\t" \ "madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \ "ld.w %%d0, [%%a3] \n\t" \ @@ -647,7 +617,7 @@ "mov %%d4, %%d3 \n\t" \ "st.w [%%a3+], %%d2 \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "st.w %0, %%d4 \n\t" \ "st.a %1, %%a3 \n\t" \ "st.a %2, %%a2 \n\t" \ @@ -658,16 +628,6 @@ #endif /* TriCore */ -#if defined(__arm__) - -#if defined(__thumb__) && !defined(__thumb2__) -#if defined(MBEDTLS_COMPILER_IS_GCC) -/* - * Thumb 1 ISA. This code path has only been tested successfully on gcc; - * it does not compile on clang or armclang. - */ - -#if !defined(__OPTIMIZE__) && defined(__GNUC__) /* * Note, gcc -O0 by default uses r7 for the frame pointer, so it complains about * our use of r7 below, unless -fomit-frame-pointer is passed. @@ -676,39 +636,32 @@ * x !=0, which we can detect using __OPTIMIZE__ (which is also defined by * clang and armcc5 under the same conditions). * - * If gcc needs to use r7, we use r1 as a scratch register and have a few extra - * instructions to preserve/restore it; otherwise, we can use r7 and avoid - * the preserve/restore overhead. + * So, only use the optimized assembly below for optimized build, which avoids + * the build error and is pretty reasonable anyway. */ -#define MULADDC_SCRATCH "RS .req r1 \n\t" -#define MULADDC_PRESERVE_SCRATCH "mov r10, r1 \n\t" -#define MULADDC_RESTORE_SCRATCH "mov r1, r10 \n\t" -#define MULADDC_SCRATCH_CLOBBER "r10" -#else /* !defined(__OPTIMIZE__) && defined(__GNUC__) */ -#define MULADDC_SCRATCH "RS .req r7 \n\t" -#define MULADDC_PRESERVE_SCRATCH "" -#define MULADDC_RESTORE_SCRATCH "" -#define MULADDC_SCRATCH_CLOBBER "r7" -#endif /* !defined(__OPTIMIZE__) && defined(__GNUC__) */ - -#define MULADDC_X1_INIT \ +#if defined(__GNUC__) && !defined(__OPTIMIZE__) +#define MULADDC_CANNOT_USE_R7 +#endif + +#if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7) + +#if defined(__thumb__) && !defined(__thumb2__) + +#define MULADDC_INIT \ asm( \ - MULADDC_SCRATCH \ "ldr r0, %3 \n\t" \ "ldr r1, %4 \n\t" \ "ldr r2, %5 \n\t" \ "ldr r3, %6 \n\t" \ - "lsr r4, r3, #16 \n\t" \ - "mov r9, r4 \n\t" \ - "lsl r4, r3, #16 \n\t" \ - "lsr r4, r4, #16 \n\t" \ - "mov r8, r4 \n\t" \ + "lsr r7, r3, #16 \n\t" \ + "mov r9, r7 \n\t" \ + "lsl r7, r3, #16 \n\t" \ + "lsr r7, r7, #16 \n\t" \ + "mov r8, r7 \n\t" - -#define MULADDC_X1_CORE \ - MULADDC_PRESERVE_SCRATCH \ +#define MULADDC_CORE \ "ldmia r0!, {r6} \n\t" \ - "lsr RS, r6, #16 \n\t" \ + "lsr r7, r6, #16 \n\t" \ "lsl r6, r6, #16 \n\t" \ "lsr r6, r6, #16 \n\t" \ "mov r4, r8 \n\t" \ @@ -716,12 +669,12 @@ "mov r3, r9 \n\t" \ "mul r6, r3 \n\t" \ "mov r5, r9 \n\t" \ - "mul r5, RS \n\t" \ + "mul r5, r7 \n\t" \ "mov r3, r8 \n\t" \ - "mul RS, r3 \n\t" \ + "mul r7, r3 \n\t" \ "lsr r3, r6, #16 \n\t" \ "add r5, r5, r3 \n\t" \ - "lsr r3, RS, #16 \n\t" \ + "lsr r3, r7, #16 \n\t" \ "add r5, r5, r3 \n\t" \ "add r4, r4, r2 \n\t" \ "mov r2, #0 \n\t" \ @@ -729,137 +682,84 @@ "lsl r3, r6, #16 \n\t" \ "add r4, r4, r3 \n\t" \ "adc r5, r2 \n\t" \ - "lsl r3, RS, #16 \n\t" \ + "lsl r3, r7, #16 \n\t" \ "add r4, r4, r3 \n\t" \ "adc r5, r2 \n\t" \ - MULADDC_RESTORE_SCRATCH \ "ldr r3, [r1] \n\t" \ "add r4, r4, r3 \n\t" \ "adc r2, r5 \n\t" \ "stmia r1!, {r4} \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "str r2, %0 \n\t" \ "str r1, %1 \n\t" \ "str r0, %2 \n\t" \ : "=m" (c), "=m" (d), "=m" (s) \ : "m" (s), "m" (d), "m" (c), "m" (b) \ : "r0", "r1", "r2", "r3", "r4", "r5", \ - "r6", MULADDC_SCRATCH_CLOBBER, "r8", "r9", "cc" \ + "r6", "r7", "r8", "r9", "cc" \ ); -#endif /* !defined(__ARMCC_VERSION) && !defined(__clang__) */ #elif (__ARM_ARCH >= 6) && \ defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1) -/* Armv6-M (or later) with DSP Instruction Set Extensions. - * Requires support for either Thumb 2 or Arm ISA. - */ -#define MULADDC_X1_INIT \ - { \ - mbedtls_mpi_uint tmp_a, tmp_b; \ - asm volatile ( - -#define MULADDC_X1_CORE \ - ".p2align 2 \n\t" \ - "ldr %[a], [%[in]], #4 \n\t" \ - "ldr %[b], [%[acc]] \n\t" \ - "umaal %[b], %[carry], %[scalar], %[a] \n\t" \ - "str %[b], [%[acc]], #4 \n\t" - -#define MULADDC_X1_STOP \ - : [a] "=&r" (tmp_a), \ - [b] "=&r" (tmp_b), \ - [in] "+r" (s), \ - [acc] "+r" (d), \ - [carry] "+l" (c) \ - : [scalar] "r" (b) \ - : "memory" \ - ); \ - } - -#define MULADDC_X2_INIT \ - { \ - mbedtls_mpi_uint tmp_a0, tmp_b0; \ - mbedtls_mpi_uint tmp_a1, tmp_b1; \ - asm volatile ( - - /* - Make sure loop is 4-byte aligned to avoid stalls - * upon repeated non-word aligned instructions in - * some microarchitectures. - * - Don't use ldm with post-increment or back-to-back - * loads with post-increment and same address register - * to avoid stalls on some microarchitectures. - * - Bunch loads and stores to reduce latency on some - * microarchitectures. E.g., on Cortex-M4, the first - * in a series of load/store operations has latency - * 2 cycles, while subsequent loads/stores are single-cycle. */ -#define MULADDC_X2_CORE \ - ".p2align 2 \n\t" \ - "ldr %[a0], [%[in]], #+8 \n\t" \ - "ldr %[b0], [%[acc]], #+8 \n\t" \ - "ldr %[a1], [%[in], #-4] \n\t" \ - "ldr %[b1], [%[acc], #-4] \n\t" \ - "umaal %[b0], %[carry], %[scalar], %[a0] \n\t" \ - "umaal %[b1], %[carry], %[scalar], %[a1] \n\t" \ - "str %[b0], [%[acc], #-8] \n\t" \ - "str %[b1], [%[acc], #-4] \n\t" - -#define MULADDC_X2_STOP \ - : [a0] "=&r" (tmp_a0), \ - [b0] "=&r" (tmp_b0), \ - [a1] "=&r" (tmp_a1), \ - [b1] "=&r" (tmp_b1), \ - [in] "+r" (s), \ - [acc] "+r" (d), \ - [carry] "+l" (c) \ - : [scalar] "r" (b) \ - : "memory" \ - ); \ - } - -#else /* Thumb 2 or Arm ISA, without DSP extensions */ - -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ + asm( + +#define MULADDC_CORE \ + "ldr r0, [%0], #4 \n\t" \ + "ldr r1, [%1] \n\t" \ + "umaal r1, %2, %3, r0 \n\t" \ + "str r1, [%1], #4 \n\t" + +#define MULADDC_STOP \ + : "=r" (s), "=r" (d), "=r" (c) \ + : "r" (b), "0" (s), "1" (d), "2" (c) \ + : "r0", "r1", "memory" \ + ); + +#else + +#define MULADDC_INIT \ asm( \ "ldr r0, %3 \n\t" \ "ldr r1, %4 \n\t" \ "ldr r2, %5 \n\t" \ "ldr r3, %6 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "ldr r4, [r0], #4 \n\t" \ "mov r5, #0 \n\t" \ "ldr r6, [r1] \n\t" \ "umlal r2, r5, r3, r4 \n\t" \ - "adds r4, r6, r2 \n\t" \ + "adds r7, r6, r2 \n\t" \ "adc r2, r5, #0 \n\t" \ - "str r4, [r1], #4 \n\t" + "str r7, [r1], #4 \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "str r2, %0 \n\t" \ "str r1, %1 \n\t" \ "str r0, %2 \n\t" \ : "=m" (c), "=m" (d), "=m" (s) \ : "m" (s), "m" (d), "m" (c), "m" (b) \ : "r0", "r1", "r2", "r3", "r4", "r5", \ - "r6", "cc" \ + "r6", "r7", "cc" \ ); -#endif /* ISA codepath selection */ +#endif /* Thumb */ -#endif /* defined(__arm__) */ +#endif /* ARMv3 */ #if defined(__alpha__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "ldq $1, %3 \n\t" \ "ldq $2, %4 \n\t" \ "ldq $3, %5 \n\t" \ "ldq $4, %6 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "ldq $6, 0($1) \n\t" \ "addq $1, 8, $1 \n\t" \ "mulq $6, $4, $7 \n\t" \ @@ -874,7 +774,7 @@ "addq $6, $3, $3 \n\t" \ "addq $5, $3, $3 \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "stq $3, %0 \n\t" \ "stq $2, %1 \n\t" \ "stq $1, %2 \n\t" \ @@ -886,14 +786,14 @@ #if defined(__mips__) && !defined(__mips64) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ asm( \ "lw $10, %3 \n\t" \ "lw $11, %4 \n\t" \ "lw $12, %5 \n\t" \ "lw $13, %6 \n\t" -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ "lw $14, 0($10) \n\t" \ "multu $13, $14 \n\t" \ "addi $10, $10, 4 \n\t" \ @@ -909,7 +809,7 @@ "addu $12, $12, $14 \n\t" \ "addi $11, $11, 4 \n\t" -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ "sw $12, %0 \n\t" \ "sw $11, %1 \n\t" \ "sw $10, %2 \n\t" \ @@ -923,13 +823,13 @@ #if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ __asm mov esi, s \ __asm mov edi, d \ __asm mov ecx, c \ __asm mov ebx, b -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ __asm lodsd \ __asm mul ebx \ __asm add eax, ecx \ @@ -939,18 +839,11 @@ __asm mov ecx, edx \ __asm stosd -#define MULADDC_X1_STOP \ - __asm mov c, ecx \ - __asm mov d, edi \ - __asm mov s, esi - #if defined(MBEDTLS_HAVE_SSE2) #define EMIT __asm _emit -#define MULADDC_X8_INIT MULADDC_X1_INIT - -#define MULADDC_X8_CORE \ +#define MULADDC_HUIT \ EMIT 0x0F EMIT 0x6E EMIT 0xC9 \ EMIT 0x0F EMIT 0x6E EMIT 0xC3 \ EMIT 0x0F EMIT 0x6E EMIT 0x1F \ @@ -1013,26 +906,33 @@ EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \ EMIT 0x0F EMIT 0x7E EMIT 0xC9 -#define MULADDC_X8_STOP \ +#define MULADDC_STOP \ EMIT 0x0F EMIT 0x77 \ __asm mov c, ecx \ __asm mov d, edi \ - __asm mov s, esi + __asm mov s, esi \ + +#else + +#define MULADDC_STOP \ + __asm mov c, ecx \ + __asm mov d, edi \ + __asm mov s, esi \ #endif /* SSE2 */ #endif /* MSVC */ #endif /* MBEDTLS_HAVE_ASM */ -#if !defined(MULADDC_X1_CORE) +#if !defined(MULADDC_CORE) #if defined(MBEDTLS_HAVE_UDBL) -#define MULADDC_X1_INIT \ +#define MULADDC_INIT \ { \ mbedtls_t_udbl r; \ mbedtls_mpi_uint r0, r1; -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ r = *(s++) * (mbedtls_t_udbl) b; \ r0 = (mbedtls_mpi_uint) r; \ r1 = (mbedtls_mpi_uint)( r >> biL ); \ @@ -1040,19 +940,18 @@ r0 += *d; r1 += (r0 < *d); \ c = r1; *(d++) = r0; -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ } -#else /* MBEDTLS_HAVE_UDBL */ - -#define MULADDC_X1_INIT \ +#else +#define MULADDC_INIT \ { \ mbedtls_mpi_uint s0, s1, b0, b1; \ mbedtls_mpi_uint r0, r1, rx, ry; \ b0 = ( b << biH ) >> biH; \ b1 = ( b >> biH ); -#define MULADDC_X1_CORE \ +#define MULADDC_CORE \ s0 = ( *s << biH ) >> biH; \ s1 = ( *s >> biH ); s++; \ rx = s0 * b1; r0 = s0 * b0; \ @@ -1066,29 +965,10 @@ r0 += *d; r1 += (r0 < *d); \ c = r1; *(d++) = r0; -#define MULADDC_X1_STOP \ +#define MULADDC_STOP \ } -#endif /* C (longlong) */ #endif /* C (generic) */ +#endif /* C (longlong) */ -#if !defined(MULADDC_X2_CORE) -#define MULADDC_X2_INIT MULADDC_X1_INIT -#define MULADDC_X2_STOP MULADDC_X1_STOP -#define MULADDC_X2_CORE MULADDC_X1_CORE MULADDC_X1_CORE -#endif /* MULADDC_X2_CORE */ - -#if !defined(MULADDC_X4_CORE) -#define MULADDC_X4_INIT MULADDC_X2_INIT -#define MULADDC_X4_STOP MULADDC_X2_STOP -#define MULADDC_X4_CORE MULADDC_X2_CORE MULADDC_X2_CORE -#endif /* MULADDC_X4_CORE */ - -#if !defined(MULADDC_X8_CORE) -#define MULADDC_X8_INIT MULADDC_X4_INIT -#define MULADDC_X8_STOP MULADDC_X4_STOP -#define MULADDC_X8_CORE MULADDC_X4_CORE MULADDC_X4_CORE -#endif /* MULADDC_X8_CORE */ - -/* *INDENT-ON* */ #endif /* bn_mul.h */ diff --git a/src/duckdb/third_party/mbedtls/library/camellia.cpp b/src/duckdb/third_party/mbedtls/library/camellia.cpp new file mode 100644 index 000000000..29d730ab5 --- /dev/null +++ b/src/duckdb/third_party/mbedtls/library/camellia.cpp @@ -0,0 +1,1087 @@ +/* + * Camellia implementation + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * The Camellia block cipher was designed by NTT and Mitsubishi Electric + * Corporation. + * + * http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/01espec.pdf + */ + +#include "common.h" + +#if defined(MBEDTLS_CAMELLIA_C) + +#include "mbedtls/camellia.h" +#include "mbedtls/platform_util.h" + +#include + +#if defined(MBEDTLS_SELF_TEST) +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#include +#define mbedtls_printf printf +#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ + +#if !defined(MBEDTLS_CAMELLIA_ALT) + +/* Parameter validation macros */ +#define CAMELLIA_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ) +#define CAMELLIA_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) + +static const unsigned char SIGMA_CHARS[6][8] = +{ + { 0xa0, 0x9e, 0x66, 0x7f, 0x3b, 0xcc, 0x90, 0x8b }, + { 0xb6, 0x7a, 0xe8, 0x58, 0x4c, 0xaa, 0x73, 0xb2 }, + { 0xc6, 0xef, 0x37, 0x2f, 0xe9, 0x4f, 0x82, 0xbe }, + { 0x54, 0xff, 0x53, 0xa5, 0xf1, 0xd3, 0x6f, 0x1c }, + { 0x10, 0xe5, 0x27, 0xfa, 0xde, 0x68, 0x2d, 0x1d }, + { 0xb0, 0x56, 0x88, 0xc2, 0xb3, 0xe6, 0xc1, 0xfd } +}; + +#if defined(MBEDTLS_CAMELLIA_SMALL_MEMORY) + +static const unsigned char FSb[256] = +{ + 112,130, 44,236,179, 39,192,229,228,133, 87, 53,234, 12,174, 65, + 35,239,107,147, 69, 25,165, 33,237, 14, 79, 78, 29,101,146,189, + 134,184,175,143,124,235, 31,206, 62, 48,220, 95, 94,197, 11, 26, + 166,225, 57,202,213, 71, 93, 61,217, 1, 90,214, 81, 86,108, 77, + 139, 13,154,102,251,204,176, 45,116, 18, 43, 32,240,177,132,153, + 223, 76,203,194, 52,126,118, 5,109,183,169, 49,209, 23, 4,215, + 20, 88, 58, 97,222, 27, 17, 28, 50, 15,156, 22, 83, 24,242, 34, + 254, 68,207,178,195,181,122,145, 36, 8,232,168, 96,252,105, 80, + 170,208,160,125,161,137, 98,151, 84, 91, 30,149,224,255,100,210, + 16,196, 0, 72,163,247,117,219,138, 3,230,218, 9, 63,221,148, + 135, 92,131, 2,205, 74,144, 51,115,103,246,243,157,127,191,226, + 82,155,216, 38,200, 55,198, 59,129,150,111, 75, 19,190, 99, 46, + 233,121,167,140,159,110,188,142, 41,245,249,182, 47,253,180, 89, + 120,152, 6,106,231, 70,113,186,212, 37,171, 66,136,162,141,250, + 114, 7,185, 85,248,238,172, 10, 54, 73, 42,104, 60, 56,241,164, + 64, 40,211,123,187,201, 67,193, 21,227,173,244,119,199,128,158 +}; + +#define SBOX1(n) FSb[(n)] +#define SBOX2(n) (unsigned char)((FSb[(n)] >> 7 ^ FSb[(n)] << 1) & 0xff) +#define SBOX3(n) (unsigned char)((FSb[(n)] >> 1 ^ FSb[(n)] << 7) & 0xff) +#define SBOX4(n) FSb[((n) << 1 ^ (n) >> 7) &0xff] + +#else /* MBEDTLS_CAMELLIA_SMALL_MEMORY */ + +static const unsigned char FSb[256] = +{ + 112, 130, 44, 236, 179, 39, 192, 229, 228, 133, 87, 53, 234, 12, 174, 65, + 35, 239, 107, 147, 69, 25, 165, 33, 237, 14, 79, 78, 29, 101, 146, 189, + 134, 184, 175, 143, 124, 235, 31, 206, 62, 48, 220, 95, 94, 197, 11, 26, + 166, 225, 57, 202, 213, 71, 93, 61, 217, 1, 90, 214, 81, 86, 108, 77, + 139, 13, 154, 102, 251, 204, 176, 45, 116, 18, 43, 32, 240, 177, 132, 153, + 223, 76, 203, 194, 52, 126, 118, 5, 109, 183, 169, 49, 209, 23, 4, 215, + 20, 88, 58, 97, 222, 27, 17, 28, 50, 15, 156, 22, 83, 24, 242, 34, + 254, 68, 207, 178, 195, 181, 122, 145, 36, 8, 232, 168, 96, 252, 105, 80, + 170, 208, 160, 125, 161, 137, 98, 151, 84, 91, 30, 149, 224, 255, 100, 210, + 16, 196, 0, 72, 163, 247, 117, 219, 138, 3, 230, 218, 9, 63, 221, 148, + 135, 92, 131, 2, 205, 74, 144, 51, 115, 103, 246, 243, 157, 127, 191, 226, + 82, 155, 216, 38, 200, 55, 198, 59, 129, 150, 111, 75, 19, 190, 99, 46, + 233, 121, 167, 140, 159, 110, 188, 142, 41, 245, 249, 182, 47, 253, 180, 89, + 120, 152, 6, 106, 231, 70, 113, 186, 212, 37, 171, 66, 136, 162, 141, 250, + 114, 7, 185, 85, 248, 238, 172, 10, 54, 73, 42, 104, 60, 56, 241, 164, + 64, 40, 211, 123, 187, 201, 67, 193, 21, 227, 173, 244, 119, 199, 128, 158 +}; + +static const unsigned char FSb2[256] = +{ + 224, 5, 88, 217, 103, 78, 129, 203, 201, 11, 174, 106, 213, 24, 93, 130, + 70, 223, 214, 39, 138, 50, 75, 66, 219, 28, 158, 156, 58, 202, 37, 123, + 13, 113, 95, 31, 248, 215, 62, 157, 124, 96, 185, 190, 188, 139, 22, 52, + 77, 195, 114, 149, 171, 142, 186, 122, 179, 2, 180, 173, 162, 172, 216, 154, + 23, 26, 53, 204, 247, 153, 97, 90, 232, 36, 86, 64, 225, 99, 9, 51, + 191, 152, 151, 133, 104, 252, 236, 10, 218, 111, 83, 98, 163, 46, 8, 175, + 40, 176, 116, 194, 189, 54, 34, 56, 100, 30, 57, 44, 166, 48, 229, 68, + 253, 136, 159, 101, 135, 107, 244, 35, 72, 16, 209, 81, 192, 249, 210, 160, + 85, 161, 65, 250, 67, 19, 196, 47, 168, 182, 60, 43, 193, 255, 200, 165, + 32, 137, 0, 144, 71, 239, 234, 183, 21, 6, 205, 181, 18, 126, 187, 41, + 15, 184, 7, 4, 155, 148, 33, 102, 230, 206, 237, 231, 59, 254, 127, 197, + 164, 55, 177, 76, 145, 110, 141, 118, 3, 45, 222, 150, 38, 125, 198, 92, + 211, 242, 79, 25, 63, 220, 121, 29, 82, 235, 243, 109, 94, 251, 105, 178, + 240, 49, 12, 212, 207, 140, 226, 117, 169, 74, 87, 132, 17, 69, 27, 245, + 228, 14, 115, 170, 241, 221, 89, 20, 108, 146, 84, 208, 120, 112, 227, 73, + 128, 80, 167, 246, 119, 147, 134, 131, 42, 199, 91, 233, 238, 143, 1, 61 +}; + +static const unsigned char FSb3[256] = +{ + 56, 65, 22, 118, 217, 147, 96, 242, 114, 194, 171, 154, 117, 6, 87, 160, + 145, 247, 181, 201, 162, 140, 210, 144, 246, 7, 167, 39, 142, 178, 73, 222, + 67, 92, 215, 199, 62, 245, 143, 103, 31, 24, 110, 175, 47, 226, 133, 13, + 83, 240, 156, 101, 234, 163, 174, 158, 236, 128, 45, 107, 168, 43, 54, 166, + 197, 134, 77, 51, 253, 102, 88, 150, 58, 9, 149, 16, 120, 216, 66, 204, + 239, 38, 229, 97, 26, 63, 59, 130, 182, 219, 212, 152, 232, 139, 2, 235, + 10, 44, 29, 176, 111, 141, 136, 14, 25, 135, 78, 11, 169, 12, 121, 17, + 127, 34, 231, 89, 225, 218, 61, 200, 18, 4, 116, 84, 48, 126, 180, 40, + 85, 104, 80, 190, 208, 196, 49, 203, 42, 173, 15, 202, 112, 255, 50, 105, + 8, 98, 0, 36, 209, 251, 186, 237, 69, 129, 115, 109, 132, 159, 238, 74, + 195, 46, 193, 1, 230, 37, 72, 153, 185, 179, 123, 249, 206, 191, 223, 113, + 41, 205, 108, 19, 100, 155, 99, 157, 192, 75, 183, 165, 137, 95, 177, 23, + 244, 188, 211, 70, 207, 55, 94, 71, 148, 250, 252, 91, 151, 254, 90, 172, + 60, 76, 3, 53, 243, 35, 184, 93, 106, 146, 213, 33, 68, 81, 198, 125, + 57, 131, 220, 170, 124, 119, 86, 5, 27, 164, 21, 52, 30, 28, 248, 82, + 32, 20, 233, 189, 221, 228, 161, 224, 138, 241, 214, 122, 187, 227, 64, 79 +}; + +static const unsigned char FSb4[256] = +{ + 112, 44, 179, 192, 228, 87, 234, 174, 35, 107, 69, 165, 237, 79, 29, 146, + 134, 175, 124, 31, 62, 220, 94, 11, 166, 57, 213, 93, 217, 90, 81, 108, + 139, 154, 251, 176, 116, 43, 240, 132, 223, 203, 52, 118, 109, 169, 209, 4, + 20, 58, 222, 17, 50, 156, 83, 242, 254, 207, 195, 122, 36, 232, 96, 105, + 170, 160, 161, 98, 84, 30, 224, 100, 16, 0, 163, 117, 138, 230, 9, 221, + 135, 131, 205, 144, 115, 246, 157, 191, 82, 216, 200, 198, 129, 111, 19, 99, + 233, 167, 159, 188, 41, 249, 47, 180, 120, 6, 231, 113, 212, 171, 136, 141, + 114, 185, 248, 172, 54, 42, 60, 241, 64, 211, 187, 67, 21, 173, 119, 128, + 130, 236, 39, 229, 133, 53, 12, 65, 239, 147, 25, 33, 14, 78, 101, 189, + 184, 143, 235, 206, 48, 95, 197, 26, 225, 202, 71, 61, 1, 214, 86, 77, + 13, 102, 204, 45, 18, 32, 177, 153, 76, 194, 126, 5, 183, 49, 23, 215, + 88, 97, 27, 28, 15, 22, 24, 34, 68, 178, 181, 145, 8, 168, 252, 80, + 208, 125, 137, 151, 91, 149, 255, 210, 196, 72, 247, 219, 3, 218, 63, 148, + 92, 2, 74, 51, 103, 243, 127, 226, 155, 38, 55, 59, 150, 75, 190, 46, + 121, 140, 110, 142, 245, 182, 253, 89, 152, 106, 70, 186, 37, 66, 162, 250, + 7, 85, 238, 10, 73, 104, 56, 164, 40, 123, 201, 193, 227, 244, 199, 158 +}; + +#define SBOX1(n) FSb[(n)] +#define SBOX2(n) FSb2[(n)] +#define SBOX3(n) FSb3[(n)] +#define SBOX4(n) FSb4[(n)] + +#endif /* MBEDTLS_CAMELLIA_SMALL_MEMORY */ + +static const unsigned char shifts[2][4][4] = +{ + { + { 1, 1, 1, 1 }, /* KL */ + { 0, 0, 0, 0 }, /* KR */ + { 1, 1, 1, 1 }, /* KA */ + { 0, 0, 0, 0 } /* KB */ + }, + { + { 1, 0, 1, 1 }, /* KL */ + { 1, 1, 0, 1 }, /* KR */ + { 1, 1, 1, 0 }, /* KA */ + { 1, 1, 0, 1 } /* KB */ + } +}; + +static const signed char indexes[2][4][20] = +{ + { + { 0, 1, 2, 3, 8, 9, 10, 11, 38, 39, + 36, 37, 23, 20, 21, 22, 27, -1, -1, 26 }, /* KL -> RK */ + { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, /* KR -> RK */ + { 4, 5, 6, 7, 12, 13, 14, 15, 16, 17, + 18, 19, -1, 24, 25, -1, 31, 28, 29, 30 }, /* KA -> RK */ + { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } /* KB -> RK */ + }, + { + { 0, 1, 2, 3, 61, 62, 63, 60, -1, -1, + -1, -1, 27, 24, 25, 26, 35, 32, 33, 34 }, /* KL -> RK */ + { -1, -1, -1, -1, 8, 9, 10, 11, 16, 17, + 18, 19, -1, -1, -1, -1, 39, 36, 37, 38 }, /* KR -> RK */ + { -1, -1, -1, -1, 12, 13, 14, 15, 58, 59, + 56, 57, 31, 28, 29, 30, -1, -1, -1, -1 }, /* KA -> RK */ + { 4, 5, 6, 7, 65, 66, 67, 64, 20, 21, + 22, 23, -1, -1, -1, -1, 43, 40, 41, 42 } /* KB -> RK */ + } +}; + +static const signed char transposes[2][20] = +{ + { + 21, 22, 23, 20, + -1, -1, -1, -1, + 18, 19, 16, 17, + 11, 8, 9, 10, + 15, 12, 13, 14 + }, + { + 25, 26, 27, 24, + 29, 30, 31, 28, + 18, 19, 16, 17, + -1, -1, -1, -1, + -1, -1, -1, -1 + } +}; + +/* Shift macro for 128 bit strings with rotation smaller than 32 bits (!) */ +#define ROTL(DEST, SRC, SHIFT) \ +{ \ + (DEST)[0] = (SRC)[0] << (SHIFT) ^ (SRC)[1] >> (32 - (SHIFT)); \ + (DEST)[1] = (SRC)[1] << (SHIFT) ^ (SRC)[2] >> (32 - (SHIFT)); \ + (DEST)[2] = (SRC)[2] << (SHIFT) ^ (SRC)[3] >> (32 - (SHIFT)); \ + (DEST)[3] = (SRC)[3] << (SHIFT) ^ (SRC)[0] >> (32 - (SHIFT)); \ +} + +#define FL(XL, XR, KL, KR) \ +{ \ + (XR) = ((((XL) & (KL)) << 1) | (((XL) & (KL)) >> 31)) ^ (XR); \ + (XL) = ((XR) | (KR)) ^ (XL); \ +} + +#define FLInv(YL, YR, KL, KR) \ +{ \ + (YL) = ((YR) | (KR)) ^ (YL); \ + (YR) = ((((YL) & (KL)) << 1) | (((YL) & (KL)) >> 31)) ^ (YR); \ +} + +#define SHIFT_AND_PLACE(INDEX, OFFSET) \ +{ \ + TK[0] = KC[(OFFSET) * 4 + 0]; \ + TK[1] = KC[(OFFSET) * 4 + 1]; \ + TK[2] = KC[(OFFSET) * 4 + 2]; \ + TK[3] = KC[(OFFSET) * 4 + 3]; \ + \ + for( i = 1; i <= 4; i++ ) \ + if( shifts[(INDEX)][(OFFSET)][i -1] ) \ + ROTL(TK + i * 4, TK, ( 15 * i ) % 32); \ + \ + for( i = 0; i < 20; i++ ) \ + if( indexes[(INDEX)][(OFFSET)][i] != -1 ) { \ + RK[indexes[(INDEX)][(OFFSET)][i]] = TK[ i ]; \ + } \ +} + +static void camellia_feistel( const uint32_t x[2], const uint32_t k[2], + uint32_t z[2]) +{ + uint32_t I0, I1; + I0 = x[0] ^ k[0]; + I1 = x[1] ^ k[1]; + + I0 = ((uint32_t) SBOX1( MBEDTLS_BYTE_3( I0 )) << 24) | + ((uint32_t) SBOX2( MBEDTLS_BYTE_2( I0 )) << 16) | + ((uint32_t) SBOX3( MBEDTLS_BYTE_1( I0 )) << 8) | + ((uint32_t) SBOX4( MBEDTLS_BYTE_0( I0 )) ); + I1 = ((uint32_t) SBOX2( MBEDTLS_BYTE_3( I1 )) << 24) | + ((uint32_t) SBOX3( MBEDTLS_BYTE_2( I1 )) << 16) | + ((uint32_t) SBOX4( MBEDTLS_BYTE_1( I1 )) << 8) | + ((uint32_t) SBOX1( MBEDTLS_BYTE_0( I1 )) ); + + I0 ^= (I1 << 8) | (I1 >> 24); + I1 ^= (I0 << 16) | (I0 >> 16); + I0 ^= (I1 >> 8) | (I1 << 24); + I1 ^= (I0 >> 8) | (I0 << 24); + + z[0] ^= I1; + z[1] ^= I0; +} + +void mbedtls_camellia_init( mbedtls_camellia_context *ctx ) +{ + CAMELLIA_VALIDATE( ctx != NULL ); + memset( ctx, 0, sizeof( mbedtls_camellia_context ) ); +} + +void mbedtls_camellia_free( mbedtls_camellia_context *ctx ) +{ + if( ctx == NULL ) + return; + + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_camellia_context ) ); +} + +/* + * Camellia key schedule (encryption) + */ +int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx, + const unsigned char *key, + unsigned int keybits ) +{ + int idx; + size_t i; + uint32_t *RK; + unsigned char t[64]; + uint32_t SIGMA[6][2]; + uint32_t KC[16]; + uint32_t TK[20]; + + CAMELLIA_VALIDATE_RET( ctx != NULL ); + CAMELLIA_VALIDATE_RET( key != NULL ); + + RK = ctx->rk; + + memset( t, 0, 64 ); + memset( RK, 0, sizeof(ctx->rk) ); + + switch( keybits ) + { + case 128: ctx->nr = 3; idx = 0; break; + case 192: + case 256: ctx->nr = 4; idx = 1; break; + default : return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + } + + for( i = 0; i < keybits / 8; ++i ) + t[i] = key[i]; + + if( keybits == 192 ) { + for( i = 0; i < 8; i++ ) + t[24 + i] = ~t[16 + i]; + } + + /* + * Prepare SIGMA values + */ + for( i = 0; i < 6; i++ ) { + SIGMA[i][0] = MBEDTLS_GET_UINT32_BE( SIGMA_CHARS[i], 0 ); + SIGMA[i][1] = MBEDTLS_GET_UINT32_BE( SIGMA_CHARS[i], 4 ); + } + + /* + * Key storage in KC + * Order: KL, KR, KA, KB + */ + memset( KC, 0, sizeof(KC) ); + + /* Store KL, KR */ + for( i = 0; i < 8; i++ ) + KC[i] = MBEDTLS_GET_UINT32_BE( t, i * 4 ); + + /* Generate KA */ + for( i = 0; i < 4; ++i ) + KC[8 + i] = KC[i] ^ KC[4 + i]; + + camellia_feistel( KC + 8, SIGMA[0], KC + 10 ); + camellia_feistel( KC + 10, SIGMA[1], KC + 8 ); + + for( i = 0; i < 4; ++i ) + KC[8 + i] ^= KC[i]; + + camellia_feistel( KC + 8, SIGMA[2], KC + 10 ); + camellia_feistel( KC + 10, SIGMA[3], KC + 8 ); + + if( keybits > 128 ) { + /* Generate KB */ + for( i = 0; i < 4; ++i ) + KC[12 + i] = KC[4 + i] ^ KC[8 + i]; + + camellia_feistel( KC + 12, SIGMA[4], KC + 14 ); + camellia_feistel( KC + 14, SIGMA[5], KC + 12 ); + } + + /* + * Generating subkeys + */ + + /* Manipulating KL */ + SHIFT_AND_PLACE( idx, 0 ); + + /* Manipulating KR */ + if( keybits > 128 ) { + SHIFT_AND_PLACE( idx, 1 ); + } + + /* Manipulating KA */ + SHIFT_AND_PLACE( idx, 2 ); + + /* Manipulating KB */ + if( keybits > 128 ) { + SHIFT_AND_PLACE( idx, 3 ); + } + + /* Do transpositions */ + for( i = 0; i < 20; i++ ) { + if( transposes[idx][i] != -1 ) { + RK[32 + 12 * idx + i] = RK[transposes[idx][i]]; + } + } + + return( 0 ); +} + +/* + * Camellia key schedule (decryption) + */ +int mbedtls_camellia_setkey_dec( mbedtls_camellia_context *ctx, + const unsigned char *key, + unsigned int keybits ) +{ + int idx, ret; + size_t i; + mbedtls_camellia_context cty; + uint32_t *RK; + uint32_t *SK; + CAMELLIA_VALIDATE_RET( ctx != NULL ); + CAMELLIA_VALIDATE_RET( key != NULL ); + + mbedtls_camellia_init( &cty ); + + /* Also checks keybits */ + if( ( ret = mbedtls_camellia_setkey_enc( &cty, key, keybits ) ) != 0 ) + goto exit; + + ctx->nr = cty.nr; + idx = ( ctx->nr == 4 ); + + RK = ctx->rk; + SK = cty.rk + 24 * 2 + 8 * idx * 2; + + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + + for( i = 22 + 8 * idx, SK -= 6; i > 0; i--, SK -= 4 ) + { + *RK++ = *SK++; + *RK++ = *SK++; + } + + SK -= 2; + + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + *RK++ = *SK++; + +exit: + mbedtls_camellia_free( &cty ); + + return( ret ); +} + +/* + * Camellia-ECB block encryption/decryption + */ +int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx, + int mode, + const unsigned char input[16], + unsigned char output[16] ) +{ + int NR; + uint32_t *RK, X[4]; + CAMELLIA_VALIDATE_RET( ctx != NULL ); + CAMELLIA_VALIDATE_RET( mode == MBEDTLS_CAMELLIA_ENCRYPT || + mode == MBEDTLS_CAMELLIA_DECRYPT ); + CAMELLIA_VALIDATE_RET( input != NULL ); + CAMELLIA_VALIDATE_RET( output != NULL ); + + ( (void) mode ); + + NR = ctx->nr; + RK = ctx->rk; + + X[0] = MBEDTLS_GET_UINT32_BE( input, 0 ); + X[1] = MBEDTLS_GET_UINT32_BE( input, 4 ); + X[2] = MBEDTLS_GET_UINT32_BE( input, 8 ); + X[3] = MBEDTLS_GET_UINT32_BE( input, 12 ); + + X[0] ^= *RK++; + X[1] ^= *RK++; + X[2] ^= *RK++; + X[3] ^= *RK++; + + while( NR ) { + --NR; + camellia_feistel( X, RK, X + 2 ); + RK += 2; + camellia_feistel( X + 2, RK, X ); + RK += 2; + camellia_feistel( X, RK, X + 2 ); + RK += 2; + camellia_feistel( X + 2, RK, X ); + RK += 2; + camellia_feistel( X, RK, X + 2 ); + RK += 2; + camellia_feistel( X + 2, RK, X ); + RK += 2; + + if( NR ) { + FL(X[0], X[1], RK[0], RK[1]); + RK += 2; + FLInv(X[2], X[3], RK[0], RK[1]); + RK += 2; + } + } + + X[2] ^= *RK++; + X[3] ^= *RK++; + X[0] ^= *RK++; + X[1] ^= *RK++; + + MBEDTLS_PUT_UINT32_BE( X[2], output, 0 ); + MBEDTLS_PUT_UINT32_BE( X[3], output, 4 ); + MBEDTLS_PUT_UINT32_BE( X[0], output, 8 ); + MBEDTLS_PUT_UINT32_BE( X[1], output, 12 ); + + return( 0 ); +} + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +/* + * Camellia-CBC buffer encryption/decryption + */ +int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx, + int mode, + size_t length, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) +{ + int i; + unsigned char temp[16]; + CAMELLIA_VALIDATE_RET( ctx != NULL ); + CAMELLIA_VALIDATE_RET( mode == MBEDTLS_CAMELLIA_ENCRYPT || + mode == MBEDTLS_CAMELLIA_DECRYPT ); + CAMELLIA_VALIDATE_RET( iv != NULL ); + CAMELLIA_VALIDATE_RET( length == 0 || input != NULL ); + CAMELLIA_VALIDATE_RET( length == 0 || output != NULL ); + + if( length % 16 ) + return( MBEDTLS_ERR_CAMELLIA_INVALID_INPUT_LENGTH ); + + if( mode == MBEDTLS_CAMELLIA_DECRYPT ) + { + while( length > 0 ) + { + memcpy( temp, input, 16 ); + mbedtls_camellia_crypt_ecb( ctx, mode, input, output ); + + for( i = 0; i < 16; i++ ) + output[i] = (unsigned char)( output[i] ^ iv[i] ); + + memcpy( iv, temp, 16 ); + + input += 16; + output += 16; + length -= 16; + } + } + else + { + while( length > 0 ) + { + for( i = 0; i < 16; i++ ) + output[i] = (unsigned char)( input[i] ^ iv[i] ); + + mbedtls_camellia_crypt_ecb( ctx, mode, output, output ); + memcpy( iv, output, 16 ); + + input += 16; + output += 16; + length -= 16; + } + } + + return( 0 ); +} +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CFB) +/* + * Camellia-CFB128 buffer encryption/decryption + */ +int mbedtls_camellia_crypt_cfb128( mbedtls_camellia_context *ctx, + int mode, + size_t length, + size_t *iv_off, + unsigned char iv[16], + const unsigned char *input, + unsigned char *output ) +{ + int c; + size_t n; + CAMELLIA_VALIDATE_RET( ctx != NULL ); + CAMELLIA_VALIDATE_RET( mode == MBEDTLS_CAMELLIA_ENCRYPT || + mode == MBEDTLS_CAMELLIA_DECRYPT ); + CAMELLIA_VALIDATE_RET( iv != NULL ); + CAMELLIA_VALIDATE_RET( iv_off != NULL ); + CAMELLIA_VALIDATE_RET( length == 0 || input != NULL ); + CAMELLIA_VALIDATE_RET( length == 0 || output != NULL ); + + n = *iv_off; + if( n >= 16 ) + return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + + if( mode == MBEDTLS_CAMELLIA_DECRYPT ) + { + while( length-- ) + { + if( n == 0 ) + mbedtls_camellia_crypt_ecb( ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv ); + + c = *input++; + *output++ = (unsigned char)( c ^ iv[n] ); + iv[n] = (unsigned char) c; + + n = ( n + 1 ) & 0x0F; + } + } + else + { + while( length-- ) + { + if( n == 0 ) + mbedtls_camellia_crypt_ecb( ctx, MBEDTLS_CAMELLIA_ENCRYPT, iv, iv ); + + iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ ); + + n = ( n + 1 ) & 0x0F; + } + } + + *iv_off = n; + + return( 0 ); +} +#endif /* MBEDTLS_CIPHER_MODE_CFB */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +/* + * Camellia-CTR buffer encryption/decryption + */ +int mbedtls_camellia_crypt_ctr( mbedtls_camellia_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char *input, + unsigned char *output ) +{ + int c, i; + size_t n; + CAMELLIA_VALIDATE_RET( ctx != NULL ); + CAMELLIA_VALIDATE_RET( nonce_counter != NULL ); + CAMELLIA_VALIDATE_RET( stream_block != NULL ); + CAMELLIA_VALIDATE_RET( nc_off != NULL ); + CAMELLIA_VALIDATE_RET( length == 0 || input != NULL ); + CAMELLIA_VALIDATE_RET( length == 0 || output != NULL ); + + n = *nc_off; + if( n >= 16 ) + return( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA ); + + while( length-- ) + { + if( n == 0 ) { + mbedtls_camellia_crypt_ecb( ctx, MBEDTLS_CAMELLIA_ENCRYPT, nonce_counter, + stream_block ); + + for( i = 16; i > 0; i-- ) + if( ++nonce_counter[i - 1] != 0 ) + break; + } + c = *input++; + *output++ = (unsigned char)( c ^ stream_block[n] ); + + n = ( n + 1 ) & 0x0F; + } + + *nc_off = n; + + return( 0 ); +} +#endif /* MBEDTLS_CIPHER_MODE_CTR */ +#endif /* !MBEDTLS_CAMELLIA_ALT */ + +#if defined(MBEDTLS_SELF_TEST) + +/* + * Camellia test vectors from: + * + * http://info.isl.ntt.co.jp/crypt/eng/camellia/technology.html: + * http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/intermediate.txt + * http://info.isl.ntt.co.jp/crypt/eng/camellia/dl/cryptrec/t_camellia.txt + * (For each bitlength: Key 0, Nr 39) + */ +#define CAMELLIA_TESTS_ECB 2 + +static const unsigned char camellia_test_ecb_key[3][CAMELLIA_TESTS_ECB][32] = +{ + { + { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } + }, + { + { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } + }, + { + { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, + 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } + }, +}; + +static const unsigned char camellia_test_ecb_plain[CAMELLIA_TESTS_ECB][16] = +{ + { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, + 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, + { 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } +}; + +static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] = +{ + { + { 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73, + 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43 }, + { 0x38, 0x3C, 0x6C, 0x2A, 0xAB, 0xEF, 0x7F, 0xDE, + 0x25, 0xCD, 0x47, 0x0B, 0xF7, 0x74, 0xA3, 0x31 } + }, + { + { 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8, + 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9 }, + { 0xD1, 0x76, 0x3F, 0xC0, 0x19, 0xD7, 0x7C, 0xC9, + 0x30, 0xBF, 0xF2, 0xA5, 0x6F, 0x7C, 0x93, 0x64 } + }, + { + { 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c, + 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09 }, + { 0x05, 0x03, 0xFB, 0x10, 0xAB, 0x24, 0x1E, 0x7C, + 0xF4, 0x5D, 0x8C, 0xDE, 0xEE, 0x47, 0x43, 0x35 } + } +}; + +#if defined(MBEDTLS_CIPHER_MODE_CBC) +#define CAMELLIA_TESTS_CBC 3 + +static const unsigned char camellia_test_cbc_key[3][32] = +{ + { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, + 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C } + , + { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52, + 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5, + 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B } + , + { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE, + 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81, + 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7, + 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 } +}; + +static const unsigned char camellia_test_cbc_iv[16] = + + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F } +; + +static const unsigned char camellia_test_cbc_plain[CAMELLIA_TESTS_CBC][16] = +{ + { 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, + 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A }, + { 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, + 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51 }, + { 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, + 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF } + +}; + +static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] = +{ + { + { 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0, + 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB }, + { 0xA2, 0xF2, 0xCF, 0x67, 0x16, 0x29, 0xEF, 0x78, + 0x40, 0xC5, 0xA5, 0xDF, 0xB5, 0x07, 0x48, 0x87 }, + { 0x0F, 0x06, 0x16, 0x50, 0x08, 0xCF, 0x8B, 0x8B, + 0x5A, 0x63, 0x58, 0x63, 0x62, 0x54, 0x3E, 0x54 } + }, + { + { 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2, + 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93 }, + { 0x5D, 0x5A, 0x86, 0x9B, 0xD1, 0x4C, 0xE5, 0x42, + 0x64, 0xF8, 0x92, 0xA6, 0xDD, 0x2E, 0xC3, 0xD5 }, + { 0x37, 0xD3, 0x59, 0xC3, 0x34, 0x98, 0x36, 0xD8, + 0x84, 0xE3, 0x10, 0xAD, 0xDF, 0x68, 0xC4, 0x49 } + }, + { + { 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A, + 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA }, + { 0x36, 0xCB, 0xEB, 0x73, 0xBD, 0x50, 0x4B, 0x40, + 0x70, 0xB1, 0xB7, 0xDE, 0x2B, 0x21, 0xEB, 0x50 }, + { 0xE3, 0x1A, 0x60, 0x55, 0x29, 0x7D, 0x96, 0xCA, + 0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83 } + } +}; +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + +#if defined(MBEDTLS_CIPHER_MODE_CTR) +/* + * Camellia-CTR test vectors from: + * + * http://www.faqs.org/rfcs/rfc5528.html + */ + +static const unsigned char camellia_test_ctr_key[3][16] = +{ + { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC, + 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E }, + { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7, + 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 }, + { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8, + 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC } +}; + +static const unsigned char camellia_test_ctr_nonce_counter[3][16] = +{ + { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, + { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59, + 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 }, + { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F, + 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 } +}; + +static const unsigned char camellia_test_ctr_pt[3][48] = +{ + { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62, + 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 }, + + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }, + + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23 } +}; + +static const unsigned char camellia_test_ctr_ct[3][48] = +{ + { 0xD0, 0x9D, 0xC2, 0x9A, 0x82, 0x14, 0x61, 0x9A, + 0x20, 0x87, 0x7C, 0x76, 0xDB, 0x1F, 0x0B, 0x3F }, + { 0xDB, 0xF3, 0xC7, 0x8D, 0xC0, 0x83, 0x96, 0xD4, + 0xDA, 0x7C, 0x90, 0x77, 0x65, 0xBB, 0xCB, 0x44, + 0x2B, 0x8E, 0x8E, 0x0F, 0x31, 0xF0, 0xDC, 0xA7, + 0x2C, 0x74, 0x17, 0xE3, 0x53, 0x60, 0xE0, 0x48 }, + { 0xB1, 0x9D, 0x1F, 0xCD, 0xCB, 0x75, 0xEB, 0x88, + 0x2F, 0x84, 0x9C, 0xE2, 0x4D, 0x85, 0xCF, 0x73, + 0x9C, 0xE6, 0x4B, 0x2B, 0x5C, 0x9D, 0x73, 0xF1, + 0x4F, 0x2D, 0x5D, 0x9D, 0xCE, 0x98, 0x89, 0xCD, + 0xDF, 0x50, 0x86, 0x96 } +}; + +static const int camellia_test_ctr_len[3] = + { 16, 32, 36 }; +#endif /* MBEDTLS_CIPHER_MODE_CTR */ + +/* + * Checkup routine + */ +int mbedtls_camellia_self_test( int verbose ) +{ + int i, j, u, v; + unsigned char key[32]; + unsigned char buf[64]; + unsigned char src[16]; + unsigned char dst[16]; +#if defined(MBEDTLS_CIPHER_MODE_CBC) + unsigned char iv[16]; +#endif +#if defined(MBEDTLS_CIPHER_MODE_CTR) + size_t offset, len; + unsigned char nonce_counter[16]; + unsigned char stream_block[16]; +#endif + int ret = 1; + + mbedtls_camellia_context ctx; + + mbedtls_camellia_init( &ctx ); + memset( key, 0, 32 ); + + for( j = 0; j < 6; j++ ) { + u = j >> 1; + v = j & 1; + + if( verbose != 0 ) + mbedtls_printf( " CAMELLIA-ECB-%3d (%s): ", 128 + u * 64, + (v == MBEDTLS_CAMELLIA_DECRYPT) ? "dec" : "enc"); + + for( i = 0; i < CAMELLIA_TESTS_ECB; i++ ) { + memcpy( key, camellia_test_ecb_key[u][i], 16 + 8 * u ); + + if( v == MBEDTLS_CAMELLIA_DECRYPT ) { + mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 ); + memcpy( src, camellia_test_ecb_cipher[u][i], 16 ); + memcpy( dst, camellia_test_ecb_plain[i], 16 ); + } else { /* MBEDTLS_CAMELLIA_ENCRYPT */ + mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 ); + memcpy( src, camellia_test_ecb_plain[i], 16 ); + memcpy( dst, camellia_test_ecb_cipher[u][i], 16 ); + } + + mbedtls_camellia_crypt_ecb( &ctx, v, src, buf ); + + if( memcmp( buf, dst, 16 ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); + goto exit; + } + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); + +#if defined(MBEDTLS_CIPHER_MODE_CBC) + /* + * CBC mode + */ + for( j = 0; j < 6; j++ ) + { + u = j >> 1; + v = j & 1; + + if( verbose != 0 ) + mbedtls_printf( " CAMELLIA-CBC-%3d (%s): ", 128 + u * 64, + ( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" ); + + memcpy( src, camellia_test_cbc_iv, 16 ); + memcpy( dst, camellia_test_cbc_iv, 16 ); + memcpy( key, camellia_test_cbc_key[u], 16 + 8 * u ); + + if( v == MBEDTLS_CAMELLIA_DECRYPT ) { + mbedtls_camellia_setkey_dec( &ctx, key, 128 + u * 64 ); + } else { + mbedtls_camellia_setkey_enc( &ctx, key, 128 + u * 64 ); + } + + for( i = 0; i < CAMELLIA_TESTS_CBC; i++ ) { + + if( v == MBEDTLS_CAMELLIA_DECRYPT ) { + memcpy( iv , src, 16 ); + memcpy( src, camellia_test_cbc_cipher[u][i], 16 ); + memcpy( dst, camellia_test_cbc_plain[i], 16 ); + } else { /* MBEDTLS_CAMELLIA_ENCRYPT */ + memcpy( iv , dst, 16 ); + memcpy( src, camellia_test_cbc_plain[i], 16 ); + memcpy( dst, camellia_test_cbc_cipher[u][i], 16 ); + } + + mbedtls_camellia_crypt_cbc( &ctx, v, 16, iv, src, buf ); + + if( memcmp( buf, dst, 16 ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); + goto exit; + } + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } +#endif /* MBEDTLS_CIPHER_MODE_CBC */ + + if( verbose != 0 ) + mbedtls_printf( "\n" ); + +#if defined(MBEDTLS_CIPHER_MODE_CTR) + /* + * CTR mode + */ + for( i = 0; i < 6; i++ ) + { + u = i >> 1; + v = i & 1; + + if( verbose != 0 ) + mbedtls_printf( " CAMELLIA-CTR-128 (%s): ", + ( v == MBEDTLS_CAMELLIA_DECRYPT ) ? "dec" : "enc" ); + + memcpy( nonce_counter, camellia_test_ctr_nonce_counter[u], 16 ); + memcpy( key, camellia_test_ctr_key[u], 16 ); + + offset = 0; + mbedtls_camellia_setkey_enc( &ctx, key, 128 ); + + if( v == MBEDTLS_CAMELLIA_DECRYPT ) + { + len = camellia_test_ctr_len[u]; + memcpy( buf, camellia_test_ctr_ct[u], len ); + + mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block, + buf, buf ); + + if( memcmp( buf, camellia_test_ctr_pt[u], len ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); + goto exit; + } + } + else + { + len = camellia_test_ctr_len[u]; + memcpy( buf, camellia_test_ctr_pt[u], len ); + + mbedtls_camellia_crypt_ctr( &ctx, len, &offset, nonce_counter, stream_block, + buf, buf ); + + if( memcmp( buf, camellia_test_ctr_ct[u], len ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); + goto exit; + } + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); +#endif /* MBEDTLS_CIPHER_MODE_CTR */ + + ret = 0; + +exit: + mbedtls_camellia_free( &ctx ); + return( ret ); +} + +#endif /* MBEDTLS_SELF_TEST */ + +#endif /* MBEDTLS_CAMELLIA_C */ diff --git a/src/duckdb/third_party/mbedtls/library/cipher.cpp b/src/duckdb/third_party/mbedtls/library/cipher.cpp index ea5d302df..b905e8556 100644 --- a/src/duckdb/third_party/mbedtls/library/cipher.cpp +++ b/src/duckdb/third_party/mbedtls/library/cipher.cpp @@ -1,12 +1,24 @@ /** * \file cipher.c * - * \brief Generic cipher wrapper for Mbed TLS + * \brief Generic cipher wrapper for mbed TLS * * \author Adriaan de Jong * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" @@ -18,7 +30,6 @@ #include "mbedtls/platform_util.h" #include "mbedtls/error.h" #include "mbedtls/constant_time.h" -#include "constant_time_internal.h" #include #include @@ -43,327 +54,261 @@ #include "mbedtls/cmac.h" #endif -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) +#if defined(MBEDTLS_USE_PSA_CRYPTO) #include "psa/crypto.h" -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#include "mbedtls/psa_util.h" +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_NIST_KW_C) #include "mbedtls/nist_kw.h" #endif +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif -static int supported_init = 0; +#define CIPHER_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ) +#define CIPHER_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) -inline const mbedtls_cipher_base_t *mbedtls_cipher_get_base( - const mbedtls_cipher_info_t *info) -{ - return mbedtls_cipher_base_lookup_table[info->base_idx]; -} +static int supported_init = 0; -const int *mbedtls_cipher_list(void) +const int *mbedtls_cipher_list( void ) { const mbedtls_cipher_definition_t *def; int *type; - if (!supported_init) { + if( ! supported_init ) + { def = mbedtls_cipher_definitions; type = mbedtls_cipher_supported; - while (def->type != 0) { + while( def->type != 0 ) *type++ = (*def++).type; - } *type = 0; supported_init = 1; } - return mbedtls_cipher_supported; + return( mbedtls_cipher_supported ); } const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type( - const mbedtls_cipher_type_t cipher_type) + const mbedtls_cipher_type_t cipher_type ) { const mbedtls_cipher_definition_t *def; - for (def = mbedtls_cipher_definitions; def->info != NULL; def++) { - if (def->type == cipher_type) { - return def->info; - } - } + for( def = mbedtls_cipher_definitions; def->info != NULL; def++ ) + if( def->type == cipher_type ) + return( def->info ); - return NULL; + return( NULL ); } const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string( - const char *cipher_name) + const char *cipher_name ) { const mbedtls_cipher_definition_t *def; - if (NULL == cipher_name) { - return NULL; - } + if( NULL == cipher_name ) + return( NULL ); - for (def = mbedtls_cipher_definitions; def->info != NULL; def++) { - if (!strcmp(def->info->name, cipher_name)) { - return def->info; - } - } + for( def = mbedtls_cipher_definitions; def->info != NULL; def++ ) + if( ! strcmp( def->info->name, cipher_name ) ) + return( def->info ); - return NULL; + return( NULL ); } const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_cipher_id_t cipher_id, int key_bitlen, - const mbedtls_cipher_mode_t mode) + const mbedtls_cipher_mode_t mode ) { const mbedtls_cipher_definition_t *def; - for (def = mbedtls_cipher_definitions; def->info != NULL; def++) { - if (mbedtls_cipher_get_base(def->info)->cipher == cipher_id && - mbedtls_cipher_info_get_key_bitlen(def->info) == (unsigned) key_bitlen && - def->info->mode == mode) { - return def->info; - } - } + for( def = mbedtls_cipher_definitions; def->info != NULL; def++ ) + if( def->info->base->cipher == cipher_id && + def->info->key_bitlen == (unsigned) key_bitlen && + def->info->mode == mode ) + return( def->info ); - return NULL; + return( NULL ); } -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) -inline psa_key_type_t mbedtls_psa_translate_cipher_type( - mbedtls_cipher_type_t cipher) +void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx ) { - switch (cipher) { - case MBEDTLS_CIPHER_AES_128_CCM: - case MBEDTLS_CIPHER_AES_192_CCM: - case MBEDTLS_CIPHER_AES_256_CCM: - case MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG: - case MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG: - case MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG: - case MBEDTLS_CIPHER_AES_128_GCM: - case MBEDTLS_CIPHER_AES_192_GCM: - case MBEDTLS_CIPHER_AES_256_GCM: - case MBEDTLS_CIPHER_AES_128_CBC: - case MBEDTLS_CIPHER_AES_192_CBC: - case MBEDTLS_CIPHER_AES_256_CBC: - case MBEDTLS_CIPHER_AES_128_ECB: - case MBEDTLS_CIPHER_AES_192_ECB: - case MBEDTLS_CIPHER_AES_256_ECB: - return PSA_KEY_TYPE_AES; - - /* ARIA not yet supported in PSA. */ - /* case MBEDTLS_CIPHER_ARIA_128_CCM: - case MBEDTLS_CIPHER_ARIA_192_CCM: - case MBEDTLS_CIPHER_ARIA_256_CCM: - case MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG: - case MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG: - case MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG: - case MBEDTLS_CIPHER_ARIA_128_GCM: - case MBEDTLS_CIPHER_ARIA_192_GCM: - case MBEDTLS_CIPHER_ARIA_256_GCM: - case MBEDTLS_CIPHER_ARIA_128_CBC: - case MBEDTLS_CIPHER_ARIA_192_CBC: - case MBEDTLS_CIPHER_ARIA_256_CBC: - return( PSA_KEY_TYPE_ARIA ); */ - - default: - return 0; - } + CIPHER_VALIDATE( ctx != NULL ); + memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) ); } -inline psa_algorithm_t mbedtls_psa_translate_cipher_mode( - mbedtls_cipher_mode_t mode, size_t taglen) +void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ) { - switch (mode) { - case MBEDTLS_MODE_ECB: - return PSA_ALG_ECB_NO_PADDING; - case MBEDTLS_MODE_GCM: - return PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, taglen); - case MBEDTLS_MODE_CCM: - return PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_CCM, taglen); - case MBEDTLS_MODE_CCM_STAR_NO_TAG: - return PSA_ALG_CCM_STAR_NO_TAG; - case MBEDTLS_MODE_CBC: - if (taglen == 0) { - return PSA_ALG_CBC_NO_PADDING; - } else { - return 0; - } - default: - return 0; - } -} -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ - -void mbedtls_cipher_init(mbedtls_cipher_context_t *ctx) -{ - memset(ctx, 0, sizeof(mbedtls_cipher_context_t)); -} - -void mbedtls_cipher_free(mbedtls_cipher_context_t *ctx) -{ - if (ctx == NULL) { + if( ctx == NULL ) return; - } -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { - if (ctx->cipher_ctx != NULL) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { + if( ctx->cipher_ctx != NULL ) + { mbedtls_cipher_context_psa * const cipher_psa = (mbedtls_cipher_context_psa *) ctx->cipher_ctx; - if (cipher_psa->slot_state == MBEDTLS_CIPHER_PSA_KEY_OWNED) { + if( cipher_psa->slot_state == MBEDTLS_CIPHER_PSA_KEY_OWNED ) + { /* xxx_free() doesn't allow to return failures. */ - (void) psa_destroy_key(cipher_psa->slot); + (void) psa_destroy_key( cipher_psa->slot ); } - mbedtls_zeroize_and_free(cipher_psa, sizeof(*cipher_psa)); + mbedtls_platform_zeroize( cipher_psa, sizeof( *cipher_psa ) ); + mbedtls_free( cipher_psa ); } - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_cipher_context_t)); + mbedtls_platform_zeroize( ctx, sizeof(mbedtls_cipher_context_t) ); return; } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_CMAC_C) - if (ctx->cmac_ctx) { - mbedtls_zeroize_and_free(ctx->cmac_ctx, - sizeof(mbedtls_cmac_context_t)); + if( ctx->cmac_ctx ) + { + mbedtls_platform_zeroize( ctx->cmac_ctx, + sizeof( mbedtls_cmac_context_t ) ); + mbedtls_free( ctx->cmac_ctx ); } #endif - if (ctx->cipher_ctx) { - mbedtls_cipher_get_base(ctx->cipher_info)->ctx_free_func(ctx->cipher_ctx); - } + if( ctx->cipher_ctx ) + ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx ); - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_cipher_context_t)); + mbedtls_platform_zeroize( ctx, sizeof(mbedtls_cipher_context_t) ); } -int mbedtls_cipher_setup(mbedtls_cipher_context_t *ctx, - const mbedtls_cipher_info_t *cipher_info) +int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info ) { - if (cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + CIPHER_VALIDATE_RET( ctx != NULL ); + if( cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - memset(ctx, 0, sizeof(mbedtls_cipher_context_t)); + memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) ); - if (mbedtls_cipher_get_base(cipher_info)->ctx_alloc_func != NULL) { - ctx->cipher_ctx = mbedtls_cipher_get_base(cipher_info)->ctx_alloc_func(); - if (ctx->cipher_ctx == NULL) { - return MBEDTLS_ERR_CIPHER_ALLOC_FAILED; - } - } + if( NULL == ( ctx->cipher_ctx = cipher_info->base->ctx_alloc_func() ) ) + return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED ); ctx->cipher_info = cipher_info; - return 0; +#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) + /* + * Ignore possible errors caused by a cipher mode that doesn't use padding + */ +#if defined(MBEDTLS_CIPHER_PADDING_PKCS7) + (void) mbedtls_cipher_set_padding_mode( ctx, MBEDTLS_PADDING_PKCS7 ); +#else + (void) mbedtls_cipher_set_padding_mode( ctx, MBEDTLS_PADDING_NONE ); +#endif +#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ + + return( 0 ); } -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) -int mbedtls_cipher_setup_psa(mbedtls_cipher_context_t *ctx, - const mbedtls_cipher_info_t *cipher_info, - size_t taglen) +#if defined(MBEDTLS_USE_PSA_CRYPTO) +int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx, + const mbedtls_cipher_info_t *cipher_info, + size_t taglen ) { psa_algorithm_t alg; mbedtls_cipher_context_psa *cipher_psa; - if (NULL == cipher_info || NULL == ctx) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( NULL == cipher_info || NULL == ctx ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); /* Check that the underlying cipher mode and cipher type are * supported by the underlying PSA Crypto implementation. */ - alg = mbedtls_psa_translate_cipher_mode(((mbedtls_cipher_mode_t) cipher_info->mode), taglen); - if (alg == 0) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } - if (mbedtls_psa_translate_cipher_type(((mbedtls_cipher_type_t) cipher_info->type)) == 0) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } + alg = mbedtls_psa_translate_cipher_mode( cipher_info->mode, taglen ); + if( alg == 0 ) + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + if( mbedtls_psa_translate_cipher_type( cipher_info->type ) == 0 ) + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); - memset(ctx, 0, sizeof(mbedtls_cipher_context_t)); + memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) ); - cipher_psa = mbedtls_calloc(1, sizeof(mbedtls_cipher_context_psa)); - if (cipher_psa == NULL) { - return MBEDTLS_ERR_CIPHER_ALLOC_FAILED; - } + cipher_psa = mbedtls_calloc( 1, sizeof(mbedtls_cipher_context_psa ) ); + if( cipher_psa == NULL ) + return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED ); cipher_psa->alg = alg; ctx->cipher_ctx = cipher_psa; ctx->cipher_info = cipher_info; ctx->psa_enabled = 1; - return 0; + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ -int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, - const unsigned char *key, - int key_bitlen, - const mbedtls_operation_t operation) +int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, + const unsigned char *key, + int key_bitlen, + const mbedtls_operation_t operation ) { - if (operation != MBEDTLS_ENCRYPT && operation != MBEDTLS_DECRYPT) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } -#if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) - if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) && - MBEDTLS_DECRYPT == operation) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } -#endif - -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( key != NULL ); + CIPHER_VALIDATE_RET( operation == MBEDTLS_ENCRYPT || + operation == MBEDTLS_DECRYPT ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { mbedtls_cipher_context_psa * const cipher_psa = (mbedtls_cipher_context_psa *) ctx->cipher_ctx; - size_t const key_bytelen = ((size_t) key_bitlen + 7) / 8; + size_t const key_bytelen = ( (size_t) key_bitlen + 7 ) / 8; psa_status_t status; psa_key_type_t key_type; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; /* PSA Crypto API only accepts byte-aligned keys. */ - if (key_bitlen % 8 != 0) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( key_bitlen % 8 != 0 ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); /* Don't allow keys to be set multiple times. */ - if (cipher_psa->slot_state != MBEDTLS_CIPHER_PSA_KEY_UNSET) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( cipher_psa->slot_state != MBEDTLS_CIPHER_PSA_KEY_UNSET ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); key_type = mbedtls_psa_translate_cipher_type( - ((mbedtls_cipher_type_t) ctx->cipher_info->type)); - if (key_type == 0) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } - psa_set_key_type(&attributes, key_type); + ctx->cipher_info->type ); + if( key_type == 0 ) + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); + psa_set_key_type( &attributes, key_type ); /* Mbed TLS' cipher layer doesn't enforce the mode of operation * (encrypt vs. decrypt): it is possible to setup a key for encryption * and use it for AEAD decryption. Until tests relying on this * are changed, allow any usage in PSA. */ - psa_set_key_usage_flags(&attributes, - PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT); - psa_set_key_algorithm(&attributes, cipher_psa->alg); - - status = psa_import_key(&attributes, key, key_bytelen, - &cipher_psa->slot); - switch (status) { + psa_set_key_usage_flags( &attributes, + /* mbedtls_psa_translate_cipher_operation( operation ); */ + PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT ); + psa_set_key_algorithm( &attributes, cipher_psa->alg ); + + status = psa_import_key( &attributes, key, key_bytelen, + &cipher_psa->slot ); + switch( status ) + { case PSA_SUCCESS: break; case PSA_ERROR_INSUFFICIENT_MEMORY: - return MBEDTLS_ERR_CIPHER_ALLOC_FAILED; + return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED ); case PSA_ERROR_NOT_SUPPORTED: - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); default: - return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); } /* Indicate that we own the key slot and need to * destroy it in mbedtls_cipher_free(). */ @@ -371,317 +316,316 @@ int mbedtls_cipher_setkey(mbedtls_cipher_context_t *ctx, ctx->key_bitlen = key_bitlen; ctx->operation = operation; - return 0; + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ - if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN) == 0 && - (int) mbedtls_cipher_info_get_key_bitlen(ctx->cipher_info) != key_bitlen) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + if( ( ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ) == 0 && + (int) ctx->cipher_info->key_bitlen != key_bitlen ) + { + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } ctx->key_bitlen = key_bitlen; ctx->operation = operation; -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) /* * For OFB, CFB and CTR mode always use the encryption key schedule */ - if (MBEDTLS_ENCRYPT == operation || - MBEDTLS_MODE_CFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_OFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_CTR == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key, - ctx->key_bitlen); + if( MBEDTLS_ENCRYPT == operation || + MBEDTLS_MODE_CFB == ctx->cipher_info->mode || + MBEDTLS_MODE_OFB == ctx->cipher_info->mode || + MBEDTLS_MODE_CTR == ctx->cipher_info->mode ) + { + return( ctx->cipher_info->base->setkey_enc_func( ctx->cipher_ctx, key, + ctx->key_bitlen ) ); } - if (MBEDTLS_DECRYPT == operation) { - return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_dec_func(ctx->cipher_ctx, key, - ctx->key_bitlen); - } -#else - if (operation == MBEDTLS_ENCRYPT || operation == MBEDTLS_DECRYPT) { - return mbedtls_cipher_get_base(ctx->cipher_info)->setkey_enc_func(ctx->cipher_ctx, key, - ctx->key_bitlen); - } -#endif + if( MBEDTLS_DECRYPT == operation ) + return( ctx->cipher_info->base->setkey_dec_func( ctx->cipher_ctx, key, + ctx->key_bitlen ) ); - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } -int mbedtls_cipher_set_iv(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, - size_t iv_len) +int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, + size_t iv_len ) { size_t actual_iv_size; - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ /* avoid buffer overflow in ctx->iv */ - if (iv_len > MBEDTLS_MAX_IV_LENGTH) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } + if( iv_len > MBEDTLS_MAX_IV_LENGTH ) + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); - if ((ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_IV_LEN) != 0) { + if( ( ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_IV_LEN ) != 0 ) actual_iv_size = iv_len; - } else { - actual_iv_size = mbedtls_cipher_info_get_iv_size(ctx->cipher_info); + else + { + actual_iv_size = ctx->cipher_info->iv_size; /* avoid reading past the end of input buffer */ - if (actual_iv_size > iv_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( actual_iv_size > iv_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } #if defined(MBEDTLS_CHACHA20_C) - if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20) { - /* Even though the actual_iv_size is overwritten with a correct value - * of 12 from the cipher info, return an error to indicate that - * the input iv_len is wrong. */ - if (iv_len != 12) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + if ( ctx->cipher_info->type == MBEDTLS_CIPHER_CHACHA20 ) + { + if ( 0 != mbedtls_chacha20_starts( (mbedtls_chacha20_context*)ctx->cipher_ctx, + iv, + 0U ) ) /* Initial counter value */ + { + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } - - if (0 != mbedtls_chacha20_starts((mbedtls_chacha20_context *) ctx->cipher_ctx, - iv, - 0U)) { /* Initial counter value */ - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - } -#if defined(MBEDTLS_CHACHAPOLY_C) - if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20_POLY1305 && - iv_len != 12) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; } #endif -#endif #if defined(MBEDTLS_GCM_C) - if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - return mbedtls_gcm_starts((mbedtls_gcm_context *) ctx->cipher_ctx, - ctx->operation, - iv, iv_len); + if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) + { + return( mbedtls_gcm_starts( (mbedtls_gcm_context *) ctx->cipher_ctx, + ctx->operation, + iv, iv_len ) ); } #endif #if defined(MBEDTLS_CCM_C) - if (MBEDTLS_MODE_CCM_STAR_NO_TAG == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_CCM_STAR_NO_TAG == ctx->cipher_info->mode ) + { int set_lengths_result; int ccm_star_mode; set_lengths_result = mbedtls_ccm_set_lengths( - (mbedtls_ccm_context *) ctx->cipher_ctx, - 0, 0, 0); - if (set_lengths_result != 0) { + (mbedtls_ccm_context *) ctx->cipher_ctx, + 0, 0, 0 ); + if( set_lengths_result != 0 ) return set_lengths_result; - } - if (ctx->operation == MBEDTLS_DECRYPT) { + if( ctx->operation == MBEDTLS_DECRYPT ) ccm_star_mode = MBEDTLS_CCM_STAR_DECRYPT; - } else if (ctx->operation == MBEDTLS_ENCRYPT) { + else if( ctx->operation == MBEDTLS_ENCRYPT ) ccm_star_mode = MBEDTLS_CCM_STAR_ENCRYPT; - } else { + else return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - return mbedtls_ccm_starts((mbedtls_ccm_context *) ctx->cipher_ctx, - ccm_star_mode, - iv, iv_len); + return( mbedtls_ccm_starts( (mbedtls_ccm_context *) ctx->cipher_ctx, + ccm_star_mode, + iv, iv_len ) ); } #endif - if (actual_iv_size != 0) { - memcpy(ctx->iv, iv, actual_iv_size); + if ( actual_iv_size != 0 ) + { + memcpy( ctx->iv, iv, actual_iv_size ); ctx->iv_size = actual_iv_size; } - return 0; + return( 0 ); } -int mbedtls_cipher_reset(mbedtls_cipher_context_t *ctx) +int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx ) { - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + CIPHER_VALIDATE_RET( ctx != NULL ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* We don't support resetting PSA-based * cipher contexts, yet. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ ctx->unprocessed_len = 0; - return 0; + return( 0 ); } #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) -int mbedtls_cipher_update_ad(mbedtls_cipher_context_t *ctx, - const unsigned char *ad, size_t ad_len) +int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx, + const unsigned char *ad, size_t ad_len ) { - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_GCM_C) - if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - return mbedtls_gcm_update_ad((mbedtls_gcm_context *) ctx->cipher_ctx, - ad, ad_len); + if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) + { + return( mbedtls_gcm_update_ad( (mbedtls_gcm_context *) ctx->cipher_ctx, + ad, ad_len ) ); } #endif #if defined(MBEDTLS_CHACHAPOLY_C) - if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { + if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) + { int result; mbedtls_chachapoly_mode_t mode; - mode = (ctx->operation == MBEDTLS_ENCRYPT) + mode = ( ctx->operation == MBEDTLS_ENCRYPT ) ? MBEDTLS_CHACHAPOLY_ENCRYPT : MBEDTLS_CHACHAPOLY_DECRYPT; - result = mbedtls_chachapoly_starts((mbedtls_chachapoly_context *) ctx->cipher_ctx, - ctx->iv, - mode); - if (result != 0) { - return result; - } + result = mbedtls_chachapoly_starts( (mbedtls_chachapoly_context*) ctx->cipher_ctx, + ctx->iv, + mode ); + if ( result != 0 ) + return( result ); - return mbedtls_chachapoly_update_aad((mbedtls_chachapoly_context *) ctx->cipher_ctx, - ad, ad_len); + return( mbedtls_chachapoly_update_aad( (mbedtls_chachapoly_context*) ctx->cipher_ctx, + ad, ad_len ) ); } #endif - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( 0 ); } #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ -int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *input, - size_t ilen, unsigned char *output, size_t *olen) +int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input, + size_t ilen, unsigned char *output, size_t *olen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t block_size; - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( ilen == 0 || input != NULL ); + CIPHER_VALIDATE_RET( output != NULL ); + CIPHER_VALIDATE_RET( olen != NULL ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ *olen = 0; - block_size = mbedtls_cipher_get_block_size(ctx); - if (0 == block_size) { - return MBEDTLS_ERR_CIPHER_INVALID_CONTEXT; + block_size = mbedtls_cipher_get_block_size( ctx ); + if ( 0 == block_size ) + { + return( MBEDTLS_ERR_CIPHER_INVALID_CONTEXT ); } - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_ECB) { - if (ilen != block_size) { - return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED; - } + if( ctx->cipher_info->mode == MBEDTLS_MODE_ECB ) + { + if( ilen != block_size ) + return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); *olen = ilen; - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ecb_func(ctx->cipher_ctx, - ctx->operation, input, - output))) { - return ret; + if( 0 != ( ret = ctx->cipher_info->base->ecb_func( ctx->cipher_ctx, + ctx->operation, input, output ) ) ) + { + return( ret ); } - return 0; + return( 0 ); } #if defined(MBEDTLS_GCM_C) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_GCM) { - return mbedtls_gcm_update((mbedtls_gcm_context *) ctx->cipher_ctx, - input, ilen, - output, ilen, olen); + if( ctx->cipher_info->mode == MBEDTLS_MODE_GCM ) + { + return( mbedtls_gcm_update( (mbedtls_gcm_context *) ctx->cipher_ctx, + input, ilen, + output, ilen, olen ) ); } #endif #if defined(MBEDTLS_CCM_C) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CCM_STAR_NO_TAG) { - return mbedtls_ccm_update((mbedtls_ccm_context *) ctx->cipher_ctx, - input, ilen, - output, ilen, olen); + if( ctx->cipher_info->mode == MBEDTLS_MODE_CCM_STAR_NO_TAG ) + { + return( mbedtls_ccm_update( (mbedtls_ccm_context *) ctx->cipher_ctx, + input, ilen, + output, ilen, olen ) ); } #endif #if defined(MBEDTLS_CHACHAPOLY_C) - if (((mbedtls_cipher_type_t) ctx->cipher_info->type) == MBEDTLS_CIPHER_CHACHA20_POLY1305) { + if ( ctx->cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 ) + { *olen = ilen; - return mbedtls_chachapoly_update((mbedtls_chachapoly_context *) ctx->cipher_ctx, - ilen, input, output); + return( mbedtls_chachapoly_update( (mbedtls_chachapoly_context*) ctx->cipher_ctx, + ilen, input, output ) ); } #endif - if (input == output && - (ctx->unprocessed_len != 0 || ilen % block_size)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + if( input == output && + ( ctx->unprocessed_len != 0 || ilen % block_size ) ) + { + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CBC) { + if( ctx->cipher_info->mode == MBEDTLS_MODE_CBC ) + { size_t copy_len = 0; /* * If there is not enough data for a full block, cache it. */ - if ((ctx->operation == MBEDTLS_DECRYPT && NULL != ctx->add_padding && - ilen <= block_size - ctx->unprocessed_len) || - (ctx->operation == MBEDTLS_DECRYPT && NULL == ctx->add_padding && - ilen < block_size - ctx->unprocessed_len) || - (ctx->operation == MBEDTLS_ENCRYPT && - ilen < block_size - ctx->unprocessed_len)) { - memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input, - ilen); + if( ( ctx->operation == MBEDTLS_DECRYPT && NULL != ctx->add_padding && + ilen <= block_size - ctx->unprocessed_len ) || + ( ctx->operation == MBEDTLS_DECRYPT && NULL == ctx->add_padding && + ilen < block_size - ctx->unprocessed_len ) || + ( ctx->operation == MBEDTLS_ENCRYPT && + ilen < block_size - ctx->unprocessed_len ) ) + { + memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input, + ilen ); ctx->unprocessed_len += ilen; - return 0; + return( 0 ); } /* * Process cached data first */ - if (0 != ctx->unprocessed_len) { + if( 0 != ctx->unprocessed_len ) + { copy_len = block_size - ctx->unprocessed_len; - memcpy(&(ctx->unprocessed_data[ctx->unprocessed_len]), input, - copy_len); + memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input, + copy_len ); - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx, - ctx->operation, - block_size, ctx->iv, - ctx-> - unprocessed_data, - output))) { - return ret; + if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, + ctx->operation, block_size, ctx->iv, + ctx->unprocessed_data, output ) ) ) + { + return( ret ); } *olen += block_size; @@ -695,20 +639,22 @@ int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *in /* * Cache final, incomplete block */ - if (0 != ilen) { + if( 0 != ilen ) + { /* Encryption: only cache partial blocks * Decryption w/ padding: always keep at least one whole block * Decryption w/o padding: only cache partial blocks */ copy_len = ilen % block_size; - if (copy_len == 0 && + if( copy_len == 0 && ctx->operation == MBEDTLS_DECRYPT && - NULL != ctx->add_padding) { + NULL != ctx->add_padding) + { copy_len = block_size; } - memcpy(ctx->unprocessed_data, &(input[ilen - copy_len]), - copy_len); + memcpy( ctx->unprocessed_data, &( input[ilen - copy_len] ), + copy_len ); ctx->unprocessed_len += copy_len; ilen -= copy_len; @@ -717,109 +663,105 @@ int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *in /* * Process remaining full blocks */ - if (ilen) { - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx, - ctx->operation, - ilen, ctx->iv, - input, - output))) { - return ret; + if( ilen ) + { + if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, + ctx->operation, ilen, ctx->iv, input, output ) ) ) + { + return( ret ); } *olen += ilen; } - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CFB) { - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cfb_func(ctx->cipher_ctx, - ctx->operation, ilen, - &ctx->unprocessed_len, - ctx->iv, - input, output))) { - return ret; + if( ctx->cipher_info->mode == MBEDTLS_MODE_CFB ) + { + if( 0 != ( ret = ctx->cipher_info->base->cfb_func( ctx->cipher_ctx, + ctx->operation, ilen, &ctx->unprocessed_len, ctx->iv, + input, output ) ) ) + { + return( ret ); } *olen = ilen; - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_OFB) { - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ofb_func(ctx->cipher_ctx, - ilen, - &ctx->unprocessed_len, - ctx->iv, - input, output))) { - return ret; + if( ctx->cipher_info->mode == MBEDTLS_MODE_OFB ) + { + if( 0 != ( ret = ctx->cipher_info->base->ofb_func( ctx->cipher_ctx, + ilen, &ctx->unprocessed_len, ctx->iv, input, output ) ) ) + { + return( ret ); } *olen = ilen; - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_CTR) { - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->ctr_func(ctx->cipher_ctx, - ilen, - &ctx->unprocessed_len, - ctx->iv, - ctx->unprocessed_data, - input, output))) { - return ret; + if( ctx->cipher_info->mode == MBEDTLS_MODE_CTR ) + { + if( 0 != ( ret = ctx->cipher_info->base->ctr_func( ctx->cipher_ctx, + ilen, &ctx->unprocessed_len, ctx->iv, + ctx->unprocessed_data, input, output ) ) ) + { + return( ret ); } *olen = ilen; - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_XTS) { - if (ctx->unprocessed_len > 0) { + if( ctx->cipher_info->mode == MBEDTLS_MODE_XTS ) + { + if( ctx->unprocessed_len > 0 ) { /* We can only process an entire data unit at a time. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } - ret = mbedtls_cipher_get_base(ctx->cipher_info)->xts_func(ctx->cipher_ctx, - ctx->operation, - ilen, - ctx->iv, - input, - output); - if (ret != 0) { - return ret; + ret = ctx->cipher_info->base->xts_func( ctx->cipher_ctx, + ctx->operation, ilen, ctx->iv, input, output ); + if( ret != 0 ) + { + return( ret ); } *olen = ilen; - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ #if defined(MBEDTLS_CIPHER_MODE_STREAM) - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) == MBEDTLS_MODE_STREAM) { - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->stream_func(ctx->cipher_ctx, - ilen, input, - output))) { - return ret; + if( ctx->cipher_info->mode == MBEDTLS_MODE_STREAM ) + { + if( 0 != ( ret = ctx->cipher_info->base->stream_func( ctx->cipher_ctx, + ilen, input, output ) ) ) + { + return( ret ); } *olen = ilen; - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_STREAM */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) @@ -827,46 +769,39 @@ int mbedtls_cipher_update(mbedtls_cipher_context_t *ctx, const unsigned char *in /* * PKCS7 (and PKCS5) padding: fill with ll bytes, with ll = padding_len */ -static void add_pkcs_padding(unsigned char *output, size_t output_len, - size_t data_len) +static void add_pkcs_padding( unsigned char *output, size_t output_len, + size_t data_len ) { size_t padding_len = output_len - data_len; unsigned char i; - for (i = 0; i < padding_len; i++) { + for( i = 0; i < padding_len; i++ ) output[data_len + i] = (unsigned char) padding_len; - } } -static int get_pkcs_padding(unsigned char *input, size_t input_len, - size_t *data_len) +static int get_pkcs_padding( unsigned char *input, size_t input_len, + size_t *data_len ) { size_t i, pad_idx; - unsigned char padding_len; + unsigned char padding_len, bad = 0; - if (NULL == input || NULL == data_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( NULL == input || NULL == data_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); padding_len = input[input_len - 1]; - if (padding_len == 0 || padding_len > input_len) { - return MBEDTLS_ERR_CIPHER_INVALID_PADDING; - } *data_len = input_len - padding_len; - mbedtls_ct_condition_t bad = mbedtls_ct_uint_gt(padding_len, input_len); - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_eq(padding_len, 0)); + /* Avoid logical || since it results in a branch */ + bad |= padding_len > input_len; + bad |= padding_len == 0; /* The number of bytes checked must be independent of padding_len, * so pick input_len, which is usually 8 or 16 (one block) */ pad_idx = input_len - padding_len; - for (i = 0; i < input_len; i++) { - mbedtls_ct_condition_t in_padding = mbedtls_ct_uint_ge(i, pad_idx); - mbedtls_ct_condition_t different = mbedtls_ct_uint_ne(input[i], padding_len); - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_bool_and(in_padding, different)); - } + for( i = 0; i < input_len; i++ ) + bad |= ( input[i] ^ padding_len ) * ( i >= pad_idx ); - return mbedtls_ct_error_if_else_0(bad, MBEDTLS_ERR_CIPHER_INVALID_PADDING); + return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ); } #endif /* MBEDTLS_CIPHER_PADDING_PKCS7 */ @@ -874,43 +809,38 @@ static int get_pkcs_padding(unsigned char *input, size_t input_len, /* * One and zeros padding: fill with 80 00 ... 00 */ -static void add_one_and_zeros_padding(unsigned char *output, - size_t output_len, size_t data_len) +static void add_one_and_zeros_padding( unsigned char *output, + size_t output_len, size_t data_len ) { size_t padding_len = output_len - data_len; unsigned char i = 0; output[data_len] = 0x80; - for (i = 1; i < padding_len; i++) { + for( i = 1; i < padding_len; i++ ) output[data_len + i] = 0x00; - } } -static int get_one_and_zeros_padding(unsigned char *input, size_t input_len, - size_t *data_len) +static int get_one_and_zeros_padding( unsigned char *input, size_t input_len, + size_t *data_len ) { - if (NULL == input || NULL == data_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + size_t i; + unsigned char done = 0, prev_done, bad; - mbedtls_ct_condition_t in_padding = MBEDTLS_CT_TRUE; - mbedtls_ct_condition_t bad = MBEDTLS_CT_TRUE; + if( NULL == input || NULL == data_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + bad = 0x80; *data_len = 0; - - for (ptrdiff_t i = (ptrdiff_t) (input_len) - 1; i >= 0; i--) { - mbedtls_ct_condition_t is_nonzero = mbedtls_ct_bool(input[i]); - - mbedtls_ct_condition_t hit_first_nonzero = mbedtls_ct_bool_and(is_nonzero, in_padding); - - *data_len = mbedtls_ct_size_if(hit_first_nonzero, i, *data_len); - - bad = mbedtls_ct_bool_if(hit_first_nonzero, mbedtls_ct_uint_ne(input[i], 0x80), bad); - - in_padding = mbedtls_ct_bool_and(in_padding, mbedtls_ct_bool_not(is_nonzero)); + for( i = input_len; i > 0; i-- ) + { + prev_done = done; + done |= ( input[i - 1] != 0 ); + *data_len |= ( i - 1 ) * ( done != prev_done ); + bad ^= input[i - 1] * ( done != prev_done ); } - return mbedtls_ct_error_if_else_0(bad, MBEDTLS_ERR_CIPHER_INVALID_PADDING); + return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ); + } #endif /* MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS */ @@ -918,46 +848,39 @@ static int get_one_and_zeros_padding(unsigned char *input, size_t input_len, /* * Zeros and len padding: fill with 00 ... 00 ll, where ll is padding length */ -static void add_zeros_and_len_padding(unsigned char *output, - size_t output_len, size_t data_len) +static void add_zeros_and_len_padding( unsigned char *output, + size_t output_len, size_t data_len ) { size_t padding_len = output_len - data_len; unsigned char i = 0; - for (i = 1; i < padding_len; i++) { + for( i = 1; i < padding_len; i++ ) output[data_len + i - 1] = 0x00; - } output[output_len - 1] = (unsigned char) padding_len; } -static int get_zeros_and_len_padding(unsigned char *input, size_t input_len, - size_t *data_len) +static int get_zeros_and_len_padding( unsigned char *input, size_t input_len, + size_t *data_len ) { size_t i, pad_idx; - unsigned char padding_len; - mbedtls_ct_condition_t bad; + unsigned char padding_len, bad = 0; - if (NULL == input || NULL == data_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( NULL == input || NULL == data_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); padding_len = input[input_len - 1]; *data_len = input_len - padding_len; /* Avoid logical || since it results in a branch */ - bad = mbedtls_ct_uint_gt(padding_len, input_len); - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_eq(padding_len, 0)); + bad |= padding_len > input_len; + bad |= padding_len == 0; /* The number of bytes checked must be independent of padding_len */ pad_idx = input_len - padding_len; - for (i = 0; i < input_len - 1; i++) { - mbedtls_ct_condition_t is_padding = mbedtls_ct_uint_ge(i, pad_idx); - mbedtls_ct_condition_t nonzero_pad_byte; - nonzero_pad_byte = mbedtls_ct_bool_if_else_0(is_padding, mbedtls_ct_bool(input[i])); - bad = mbedtls_ct_bool_or(bad, nonzero_pad_byte); - } + for( i = 0; i < input_len - 1; i++ ) + bad |= input[i] * ( i >= pad_idx ); - return mbedtls_ct_error_if_else_0(bad, MBEDTLS_ERR_CIPHER_INVALID_PADDING); + return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) ); } #endif /* MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN */ @@ -965,30 +888,33 @@ static int get_zeros_and_len_padding(unsigned char *input, size_t input_len, /* * Zero padding: fill with 00 ... 00 */ -static void add_zeros_padding(unsigned char *output, - size_t output_len, size_t data_len) +static void add_zeros_padding( unsigned char *output, + size_t output_len, size_t data_len ) { - memset(output + data_len, 0, output_len - data_len); + size_t i; + + for( i = data_len; i < output_len; i++ ) + output[i] = 0x00; } -static int get_zeros_padding(unsigned char *input, size_t input_len, - size_t *data_len) +static int get_zeros_padding( unsigned char *input, size_t input_len, + size_t *data_len ) { size_t i; - mbedtls_ct_condition_t done = MBEDTLS_CT_FALSE, prev_done; + unsigned char done = 0, prev_done; - if (NULL == input || NULL == data_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( NULL == input || NULL == data_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); *data_len = 0; - for (i = input_len; i > 0; i--) { + for( i = input_len; i > 0; i-- ) + { prev_done = done; - done = mbedtls_ct_bool_or(done, mbedtls_ct_uint_ne(input[i-1], 0)); - *data_len = mbedtls_ct_size_if(mbedtls_ct_bool_ne(done, prev_done), i, *data_len); + done |= ( input[i-1] != 0 ); + *data_len |= i * ( done != prev_done ); } - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_PADDING_ZEROS */ @@ -998,278 +924,284 @@ static int get_zeros_padding(unsigned char *input, size_t input_len, * There is no add_padding function (check for NULL in mbedtls_cipher_finish) * but a trivial get_padding function */ -static int get_no_padding(unsigned char *input, size_t input_len, - size_t *data_len) +static int get_no_padding( unsigned char *input, size_t input_len, + size_t *data_len ) { - if (NULL == input || NULL == data_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( NULL == input || NULL == data_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); *data_len = input_len; - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ -int mbedtls_cipher_finish(mbedtls_cipher_context_t *ctx, - unsigned char *output, size_t *olen) +int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx, + unsigned char *output, size_t *olen ) { - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } - -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( output != NULL ); + CIPHER_VALIDATE_RET( olen != NULL ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ *olen = 0; -#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) - /* CBC mode requires padding so we make sure a call to - * mbedtls_cipher_set_padding_mode has been done successfully. */ - if (MBEDTLS_MODE_CBC == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - if (ctx->get_padding == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( MBEDTLS_MODE_CFB == ctx->cipher_info->mode || + MBEDTLS_MODE_OFB == ctx->cipher_info->mode || + MBEDTLS_MODE_CTR == ctx->cipher_info->mode || + MBEDTLS_MODE_GCM == ctx->cipher_info->mode || + MBEDTLS_MODE_CCM_STAR_NO_TAG == ctx->cipher_info->mode || + MBEDTLS_MODE_XTS == ctx->cipher_info->mode || + MBEDTLS_MODE_STREAM == ctx->cipher_info->mode ) + { + return( 0 ); } -#endif - if (MBEDTLS_MODE_CFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_OFB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_CTR == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_CCM_STAR_NO_TAG == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_XTS == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_STREAM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - return 0; + if ( ( MBEDTLS_CIPHER_CHACHA20 == ctx->cipher_info->type ) || + ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) ) + { + return( 0 ); } - if ((MBEDTLS_CIPHER_CHACHA20 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) || - (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type))) { - return 0; - } - - if (MBEDTLS_MODE_ECB == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - if (ctx->unprocessed_len != 0) { - return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED; - } + if( MBEDTLS_MODE_ECB == ctx->cipher_info->mode ) + { + if( ctx->unprocessed_len != 0 ) + return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); - return 0; + return( 0 ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) - if (MBEDTLS_MODE_CBC == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_CBC == ctx->cipher_info->mode ) + { int ret = 0; - if (MBEDTLS_ENCRYPT == ctx->operation) { + if( MBEDTLS_ENCRYPT == ctx->operation ) + { /* check for 'no padding' mode */ - if (NULL == ctx->add_padding) { - if (0 != ctx->unprocessed_len) { - return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED; - } + if( NULL == ctx->add_padding ) + { + if( 0 != ctx->unprocessed_len ) + return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); - return 0; + return( 0 ); } - ctx->add_padding(ctx->unprocessed_data, mbedtls_cipher_get_iv_size(ctx), - ctx->unprocessed_len); - } else if (mbedtls_cipher_get_block_size(ctx) != ctx->unprocessed_len) { + ctx->add_padding( ctx->unprocessed_data, mbedtls_cipher_get_iv_size( ctx ), + ctx->unprocessed_len ); + } + else if( mbedtls_cipher_get_block_size( ctx ) != ctx->unprocessed_len ) + { /* * For decrypt operations, expect a full block, * or an empty block if no padding */ - if (NULL == ctx->add_padding && 0 == ctx->unprocessed_len) { - return 0; - } + if( NULL == ctx->add_padding && 0 == ctx->unprocessed_len ) + return( 0 ); - return MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED; + return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED ); } /* cipher block */ - if (0 != (ret = mbedtls_cipher_get_base(ctx->cipher_info)->cbc_func(ctx->cipher_ctx, - ctx->operation, - mbedtls_cipher_get_block_size( - ctx), - ctx->iv, - ctx->unprocessed_data, - output))) { - return ret; + if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx, + ctx->operation, mbedtls_cipher_get_block_size( ctx ), ctx->iv, + ctx->unprocessed_data, output ) ) ) + { + return( ret ); } /* Set output size for decryption */ - if (MBEDTLS_DECRYPT == ctx->operation) { - return ctx->get_padding(output, mbedtls_cipher_get_block_size(ctx), - olen); - } + if( MBEDTLS_DECRYPT == ctx->operation ) + return( ctx->get_padding( output, mbedtls_cipher_get_block_size( ctx ), + olen ) ); /* Set output size for encryption */ - *olen = mbedtls_cipher_get_block_size(ctx); - return 0; + *olen = mbedtls_cipher_get_block_size( ctx ); + return( 0 ); } #else ((void) output); #endif /* MBEDTLS_CIPHER_MODE_CBC */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) -int mbedtls_cipher_set_padding_mode(mbedtls_cipher_context_t *ctx, - mbedtls_cipher_padding_t mode) +int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx, + mbedtls_cipher_padding_t mode ) { - if (NULL == ctx->cipher_info || - MBEDTLS_MODE_CBC != ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + CIPHER_VALIDATE_RET( ctx != NULL ); + + if( NULL == ctx->cipher_info || MBEDTLS_MODE_CBC != ctx->cipher_info->mode ) + { + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* While PSA Crypto knows about CBC padding * schemes, we currently don't make them * accessible through the cipher layer. */ - if (mode != MBEDTLS_PADDING_NONE) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } + if( mode != MBEDTLS_PADDING_NONE ) + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); - return 0; + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ - switch (mode) { + switch( mode ) + { #if defined(MBEDTLS_CIPHER_PADDING_PKCS7) - case MBEDTLS_PADDING_PKCS7: - ctx->add_padding = add_pkcs_padding; - ctx->get_padding = get_pkcs_padding; - break; + case MBEDTLS_PADDING_PKCS7: + ctx->add_padding = add_pkcs_padding; + ctx->get_padding = get_pkcs_padding; + break; #endif #if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS) - case MBEDTLS_PADDING_ONE_AND_ZEROS: - ctx->add_padding = add_one_and_zeros_padding; - ctx->get_padding = get_one_and_zeros_padding; - break; + case MBEDTLS_PADDING_ONE_AND_ZEROS: + ctx->add_padding = add_one_and_zeros_padding; + ctx->get_padding = get_one_and_zeros_padding; + break; #endif #if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN) - case MBEDTLS_PADDING_ZEROS_AND_LEN: - ctx->add_padding = add_zeros_and_len_padding; - ctx->get_padding = get_zeros_and_len_padding; - break; + case MBEDTLS_PADDING_ZEROS_AND_LEN: + ctx->add_padding = add_zeros_and_len_padding; + ctx->get_padding = get_zeros_and_len_padding; + break; #endif #if defined(MBEDTLS_CIPHER_PADDING_ZEROS) - case MBEDTLS_PADDING_ZEROS: - ctx->add_padding = add_zeros_padding; - ctx->get_padding = get_zeros_padding; - break; + case MBEDTLS_PADDING_ZEROS: + ctx->add_padding = add_zeros_padding; + ctx->get_padding = get_zeros_padding; + break; #endif - case MBEDTLS_PADDING_NONE: - ctx->add_padding = NULL; - ctx->get_padding = get_no_padding; - break; + case MBEDTLS_PADDING_NONE: + ctx->add_padding = NULL; + ctx->get_padding = get_no_padding; + break; - default: - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + default: + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } - return 0; + return( 0 ); } #endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */ #if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C) -int mbedtls_cipher_write_tag(mbedtls_cipher_context_t *ctx, - unsigned char *tag, size_t tag_len) +int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx, + unsigned char *tag, size_t tag_len ) { - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - if (MBEDTLS_ENCRYPT != ctx->operation) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( MBEDTLS_ENCRYPT != ctx->operation ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_GCM_C) - if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) + { size_t output_length; /* The code here doesn't yet support alternative implementations * that can delay up to a block of output. */ - return mbedtls_gcm_finish((mbedtls_gcm_context *) ctx->cipher_ctx, - NULL, 0, &output_length, - tag, tag_len); + return( mbedtls_gcm_finish( (mbedtls_gcm_context *) ctx->cipher_ctx, + NULL, 0, &output_length, + tag, tag_len ) ); } #endif #if defined(MBEDTLS_CHACHAPOLY_C) - if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { + if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) + { /* Don't allow truncated MAC for Poly1305 */ - if (tag_len != 16U) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if ( tag_len != 16U ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - return mbedtls_chachapoly_finish( - (mbedtls_chachapoly_context *) ctx->cipher_ctx, tag); + return( mbedtls_chachapoly_finish( + (mbedtls_chachapoly_context*) ctx->cipher_ctx, tag ) ); } #endif - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( 0 ); } -int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, - const unsigned char *tag, size_t tag_len) +int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx, + const unsigned char *tag, size_t tag_len ) { unsigned char check_tag[16]; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - if (ctx->cipher_info == NULL) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL ); + if( ctx->cipher_info == NULL ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - if (MBEDTLS_DECRYPT != ctx->operation) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + if( MBEDTLS_DECRYPT != ctx->operation ) + { + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* While PSA Crypto has an API for multipart * operations, we currently don't make it * accessible through the cipher layer. */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ - /* Status to return on a non-authenticated algorithm. */ - ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + /* Status to return on a non-authenticated algorithm. It would make sense + * to return MBEDTLS_ERR_CIPHER_INVALID_CONTEXT or perhaps + * MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, but at the time I write this our + * unit tests assume 0. */ + ret = 0; #if defined(MBEDTLS_GCM_C) - if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) + { size_t output_length; /* The code here doesn't yet support alternative implementations * that can delay up to a block of output. */ - if (tag_len > sizeof(check_tag)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( tag_len > sizeof( check_tag ) ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - if (0 != (ret = mbedtls_gcm_finish( - (mbedtls_gcm_context *) ctx->cipher_ctx, - NULL, 0, &output_length, - check_tag, tag_len))) { - return ret; + if( 0 != ( ret = mbedtls_gcm_finish( + (mbedtls_gcm_context *) ctx->cipher_ctx, + NULL, 0, &output_length, + check_tag, tag_len ) ) ) + { + return( ret ); } /* Check the tag in "constant-time" */ - if (mbedtls_ct_memcmp(tag, check_tag, tag_len) != 0) { + if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 ) + { ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; goto exit; } @@ -1277,20 +1209,22 @@ int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CHACHAPOLY_C) - if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { + if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) + { /* Don't allow truncated MAC for Poly1305 */ - if (tag_len != sizeof(check_tag)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if ( tag_len != sizeof( check_tag ) ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); ret = mbedtls_chachapoly_finish( - (mbedtls_chachapoly_context *) ctx->cipher_ctx, check_tag); - if (ret != 0) { - return ret; + (mbedtls_chachapoly_context*) ctx->cipher_ctx, check_tag ); + if ( ret != 0 ) + { + return( ret ); } /* Check the tag in "constant-time" */ - if (mbedtls_ct_memcmp(tag, check_tag, tag_len) != 0) { + if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 ) + { ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; goto exit; } @@ -1298,24 +1232,31 @@ int mbedtls_cipher_check_tag(mbedtls_cipher_context_t *ctx, #endif /* MBEDTLS_CHACHAPOLY_C */ exit: - mbedtls_platform_zeroize(check_tag, tag_len); - return ret; + mbedtls_platform_zeroize( check_tag, tag_len ); + return( ret ); } #endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */ /* * Packet-oriented wrapper for non-AEAD modes */ -int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen) +int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t finish_olen; -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL ); + CIPHER_VALIDATE_RET( ilen == 0 || input != NULL ); + CIPHER_VALIDATE_RET( output != NULL ); + CIPHER_VALIDATE_RET( olen != NULL ); + +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* As in the non-PSA case, we don't check that * a key has been set. If not, the key slot will * still be in its default state of 0, which is @@ -1328,73 +1269,69 @@ int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, psa_cipher_operation_t cipher_op = PSA_CIPHER_OPERATION_INIT; size_t part_len; - if (ctx->operation == MBEDTLS_DECRYPT) { - status = psa_cipher_decrypt_setup(&cipher_op, - cipher_psa->slot, - cipher_psa->alg); - } else if (ctx->operation == MBEDTLS_ENCRYPT) { - status = psa_cipher_encrypt_setup(&cipher_op, - cipher_psa->slot, - cipher_psa->alg); - } else { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + if( ctx->operation == MBEDTLS_DECRYPT ) + { + status = psa_cipher_decrypt_setup( &cipher_op, + cipher_psa->slot, + cipher_psa->alg ); } + else if( ctx->operation == MBEDTLS_ENCRYPT ) + { + status = psa_cipher_encrypt_setup( &cipher_op, + cipher_psa->slot, + cipher_psa->alg ); + } + else + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); /* In the following, we can immediately return on an error, * because the PSA Crypto API guarantees that cipher operations * are terminated by unsuccessful calls to psa_cipher_update(), * and by any call to psa_cipher_finish(). */ - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; - } - - if (((mbedtls_cipher_mode_t) ctx->cipher_info->mode) != MBEDTLS_MODE_ECB) { - status = psa_cipher_set_iv(&cipher_op, iv, iv_len); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; - } + if( status != PSA_SUCCESS ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + + if( ctx->cipher_info->mode != MBEDTLS_MODE_ECB ) + { + status = psa_cipher_set_iv( &cipher_op, iv, iv_len ); + if( status != PSA_SUCCESS ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); } - status = psa_cipher_update(&cipher_op, - input, ilen, - output, ilen, olen); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; - } + status = psa_cipher_update( &cipher_op, + input, ilen, + output, ilen, olen ); + if( status != PSA_SUCCESS ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); - status = psa_cipher_finish(&cipher_op, - output + *olen, ilen - *olen, - &part_len); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; - } + status = psa_cipher_finish( &cipher_op, + output + *olen, ilen - *olen, + &part_len ); + if( status != PSA_SUCCESS ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); *olen += part_len; - return 0; + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ - if ((ret = mbedtls_cipher_set_iv(ctx, iv, iv_len)) != 0) { - return ret; - } + if( ( ret = mbedtls_cipher_set_iv( ctx, iv, iv_len ) ) != 0 ) + return( ret ); - if ((ret = mbedtls_cipher_reset(ctx)) != 0) { - return ret; - } + if( ( ret = mbedtls_cipher_reset( ctx ) ) != 0 ) + return( ret ); - if ((ret = mbedtls_cipher_update(ctx, input, ilen, - output, olen)) != 0) { - return ret; - } + if( ( ret = mbedtls_cipher_update( ctx, input, ilen, + output, olen ) ) != 0 ) + return( ret ); - if ((ret = mbedtls_cipher_finish(ctx, output + *olen, - &finish_olen)) != 0) { - return ret; - } + if( ( ret = mbedtls_cipher_finish( ctx, output + *olen, + &finish_olen ) ) != 0 ) + return( ret ); *olen += finish_olen; - return 0; + return( 0 ); } #if defined(MBEDTLS_CIPHER_MODE_AEAD) @@ -1402,15 +1339,16 @@ int mbedtls_cipher_crypt(mbedtls_cipher_context_t *ctx, * Packet-oriented encryption for AEAD modes: internal function used by * mbedtls_cipher_auth_encrypt_ext(). */ -static int mbedtls_cipher_aead_encrypt(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, - unsigned char *tag, size_t tag_len) +static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, + unsigned char *tag, size_t tag_len ) { -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* As in the non-PSA case, we don't check that * a key has been set. If not, the key slot will * still be in its default state of 0, which is @@ -1423,71 +1361,74 @@ static int mbedtls_cipher_aead_encrypt(mbedtls_cipher_context_t *ctx, /* PSA Crypto API always writes the authentication tag * at the end of the encrypted message. */ - if (output == NULL || tag != output + ilen) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } + if( output == NULL || tag != output + ilen ) + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); - status = psa_aead_encrypt(cipher_psa->slot, - cipher_psa->alg, - iv, iv_len, - ad, ad_len, - input, ilen, - output, ilen + tag_len, olen); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; - } + status = psa_aead_encrypt( cipher_psa->slot, + cipher_psa->alg, + iv, iv_len, + ad, ad_len, + input, ilen, + output, ilen + tag_len, olen ); + if( status != PSA_SUCCESS ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); *olen -= tag_len; - return 0; + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_GCM_C) - if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) + { *olen = ilen; - return mbedtls_gcm_crypt_and_tag((mbedtls_gcm_context *)ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT, - ilen, iv, iv_len, ad, ad_len, - input, output, tag_len, tag); + return( mbedtls_gcm_crypt_and_tag( (mbedtls_gcm_context *)ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT, + ilen, iv, iv_len, ad, ad_len, + input, output, tag_len, tag ) ); } #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) - if (MBEDTLS_MODE_CCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_CCM == ctx->cipher_info->mode ) + { *olen = ilen; - return mbedtls_ccm_encrypt_and_tag(ctx->cipher_ctx, ilen, - iv, iv_len, ad, ad_len, input, output, - tag, tag_len); + return( mbedtls_ccm_encrypt_and_tag( ctx->cipher_ctx, ilen, + iv, iv_len, ad, ad_len, input, output, + tag, tag_len ) ); } #endif /* MBEDTLS_CCM_C */ #if defined(MBEDTLS_CHACHAPOLY_C) - if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { + if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) + { /* ChachaPoly has fixed length nonce and MAC (tag) */ - if ((iv_len != mbedtls_cipher_info_get_iv_size(ctx->cipher_info)) || - (tag_len != 16U)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + if ( ( iv_len != ctx->cipher_info->iv_size ) || + ( tag_len != 16U ) ) + { + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } *olen = ilen; - return mbedtls_chachapoly_encrypt_and_tag(ctx->cipher_ctx, - ilen, iv, ad, ad_len, input, output, tag); + return( mbedtls_chachapoly_encrypt_and_tag( ctx->cipher_ctx, + ilen, iv, ad, ad_len, input, output, tag ) ); } #endif /* MBEDTLS_CHACHAPOLY_C */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } /* * Packet-oriented encryption for AEAD modes: internal function used by * mbedtls_cipher_auth_encrypt_ext(). */ -static int mbedtls_cipher_aead_decrypt(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, - const unsigned char *tag, size_t tag_len) +static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, + const unsigned char *tag, size_t tag_len ) { -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) - if (ctx->psa_enabled == 1) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) + if( ctx->psa_enabled == 1 ) + { /* As in the non-PSA case, we don't check that * a key has been set. If not, the key slot will * still be in its default state of 0, which is @@ -1500,81 +1441,80 @@ static int mbedtls_cipher_aead_decrypt(mbedtls_cipher_context_t *ctx, /* PSA Crypto API always writes the authentication tag * at the end of the encrypted message. */ - if (input == NULL || tag != input + ilen) { - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; - } + if( input == NULL || tag != input + ilen ) + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); - status = psa_aead_decrypt(cipher_psa->slot, - cipher_psa->alg, - iv, iv_len, - ad, ad_len, - input, ilen + tag_len, - output, ilen, olen); - if (status == PSA_ERROR_INVALID_SIGNATURE) { - return MBEDTLS_ERR_CIPHER_AUTH_FAILED; - } else if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED; - } + status = psa_aead_decrypt( cipher_psa->slot, + cipher_psa->alg, + iv, iv_len, + ad, ad_len, + input, ilen + tag_len, + output, ilen, olen ); + if( status == PSA_ERROR_INVALID_SIGNATURE ) + return( MBEDTLS_ERR_CIPHER_AUTH_FAILED ); + else if( status != PSA_SUCCESS ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); - return 0; + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO && !MBEDTLS_DEPRECATED_REMOVED */ +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #if defined(MBEDTLS_GCM_C) - if (MBEDTLS_MODE_GCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode ) + { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; *olen = ilen; - ret = mbedtls_gcm_auth_decrypt((mbedtls_gcm_context *)ctx->cipher_ctx, ilen, - iv, iv_len, ad, ad_len, - tag, tag_len, input, output); + ret = mbedtls_gcm_auth_decrypt( (mbedtls_gcm_context *)ctx->cipher_ctx, ilen, + iv, iv_len, ad, ad_len, + tag, tag_len, input, output ); - if (ret == MBEDTLS_ERR_GCM_AUTH_FAILED) { + if( ret == MBEDTLS_ERR_GCM_AUTH_FAILED ) ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; - } - return ret; + return( ret ); } #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) - if (MBEDTLS_MODE_CCM == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) { + if( MBEDTLS_MODE_CCM == ctx->cipher_info->mode ) + { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; *olen = ilen; - ret = mbedtls_ccm_auth_decrypt(ctx->cipher_ctx, ilen, - iv, iv_len, ad, ad_len, - input, output, tag, tag_len); + ret = mbedtls_ccm_auth_decrypt( ctx->cipher_ctx, ilen, + iv, iv_len, ad, ad_len, + input, output, tag, tag_len ); - if (ret == MBEDTLS_ERR_CCM_AUTH_FAILED) { + if( ret == MBEDTLS_ERR_CCM_AUTH_FAILED ) ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; - } - return ret; + return( ret ); } #endif /* MBEDTLS_CCM_C */ #if defined(MBEDTLS_CHACHAPOLY_C) - if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ((mbedtls_cipher_type_t) ctx->cipher_info->type)) { + if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) + { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; /* ChachaPoly has fixed length nonce and MAC (tag) */ - if ((iv_len != mbedtls_cipher_info_get_iv_size(ctx->cipher_info)) || - (tag_len != 16U)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; + if ( ( iv_len != ctx->cipher_info->iv_size ) || + ( tag_len != 16U ) ) + { + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); } *olen = ilen; - ret = mbedtls_chachapoly_auth_decrypt(ctx->cipher_ctx, ilen, - iv, ad, ad_len, tag, input, output); + ret = mbedtls_chachapoly_auth_decrypt( ctx->cipher_ctx, ilen, + iv, ad, ad_len, tag, input, output ); - if (ret == MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED) { + if( ret == MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED ) ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED; - } - return ret; + return( ret ); } #endif /* MBEDTLS_CHACHAPOLY_C */ - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); } #endif /* MBEDTLS_CIPHER_MODE_AEAD */ @@ -1582,100 +1522,110 @@ static int mbedtls_cipher_aead_decrypt(mbedtls_cipher_context_t *ctx, /* * Packet-oriented encryption for AEAD/NIST_KW: public function. */ -int mbedtls_cipher_auth_encrypt_ext(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t output_len, - size_t *olen, size_t tag_len) +int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t output_len, + size_t *olen, size_t tag_len ) { + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL ); + CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL ); + CIPHER_VALIDATE_RET( ilen == 0 || input != NULL ); + CIPHER_VALIDATE_RET( output != NULL ); + CIPHER_VALIDATE_RET( olen != NULL ); + #if defined(MBEDTLS_NIST_KW_C) - if ( -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) + if( +#if defined(MBEDTLS_USE_PSA_CRYPTO) ctx->psa_enabled == 0 && #endif - (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_KWP == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode))) { - mbedtls_nist_kw_mode_t mode = - (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) ? - MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP; + ( MBEDTLS_MODE_KW == ctx->cipher_info->mode || + MBEDTLS_MODE_KWP == ctx->cipher_info->mode ) ) + { + mbedtls_nist_kw_mode_t mode = ( MBEDTLS_MODE_KW == ctx->cipher_info->mode ) ? + MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP; /* There is no iv, tag or ad associated with KW and KWP, * so these length should be 0 as documented. */ - if (iv_len != 0 || tag_len != 0 || ad_len != 0) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( iv_len != 0 || tag_len != 0 || ad_len != 0 ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); (void) iv; (void) ad; - return mbedtls_nist_kw_wrap(ctx->cipher_ctx, mode, input, ilen, - output, olen, output_len); + return( mbedtls_nist_kw_wrap( ctx->cipher_ctx, mode, input, ilen, + output, olen, output_len ) ); } #endif /* MBEDTLS_NIST_KW_C */ #if defined(MBEDTLS_CIPHER_MODE_AEAD) /* AEAD case: check length before passing on to shared function */ - if (output_len < ilen + tag_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( output_len < ilen + tag_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - int ret = mbedtls_cipher_aead_encrypt(ctx, iv, iv_len, ad, ad_len, - input, ilen, output, olen, - output + ilen, tag_len); + int ret = mbedtls_cipher_aead_encrypt( ctx, iv, iv_len, ad, ad_len, + input, ilen, output, olen, + output + ilen, tag_len ); *olen += tag_len; - return ret; + return( ret ); #else - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); #endif /* MBEDTLS_CIPHER_MODE_AEAD */ } /* * Packet-oriented decryption for AEAD/NIST_KW: public function. */ -int mbedtls_cipher_auth_decrypt_ext(mbedtls_cipher_context_t *ctx, - const unsigned char *iv, size_t iv_len, - const unsigned char *ad, size_t ad_len, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t output_len, - size_t *olen, size_t tag_len) +int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx, + const unsigned char *iv, size_t iv_len, + const unsigned char *ad, size_t ad_len, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t output_len, + size_t *olen, size_t tag_len ) { + CIPHER_VALIDATE_RET( ctx != NULL ); + CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL ); + CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL ); + CIPHER_VALIDATE_RET( ilen == 0 || input != NULL ); + CIPHER_VALIDATE_RET( output_len == 0 || output != NULL ); + CIPHER_VALIDATE_RET( olen != NULL ); + #if defined(MBEDTLS_NIST_KW_C) - if ( -#if defined(MBEDTLS_USE_PSA_CRYPTO) && !defined(MBEDTLS_DEPRECATED_REMOVED) + if( +#if defined(MBEDTLS_USE_PSA_CRYPTO) ctx->psa_enabled == 0 && #endif - (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode) || - MBEDTLS_MODE_KWP == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode))) { - mbedtls_nist_kw_mode_t mode = - (MBEDTLS_MODE_KW == ((mbedtls_cipher_mode_t) ctx->cipher_info->mode)) ? - MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP; + ( MBEDTLS_MODE_KW == ctx->cipher_info->mode || + MBEDTLS_MODE_KWP == ctx->cipher_info->mode ) ) + { + mbedtls_nist_kw_mode_t mode = ( MBEDTLS_MODE_KW == ctx->cipher_info->mode ) ? + MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP; /* There is no iv, tag or ad associated with KW and KWP, * so these length should be 0 as documented. */ - if (iv_len != 0 || tag_len != 0 || ad_len != 0) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( iv_len != 0 || tag_len != 0 || ad_len != 0 ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); (void) iv; (void) ad; - return mbedtls_nist_kw_unwrap(ctx->cipher_ctx, mode, input, ilen, - output, olen, output_len); + return( mbedtls_nist_kw_unwrap( ctx->cipher_ctx, mode, input, ilen, + output, olen, output_len ) ); } #endif /* MBEDTLS_NIST_KW_C */ #if defined(MBEDTLS_CIPHER_MODE_AEAD) /* AEAD case: check length before passing on to shared function */ - if (ilen < tag_len || output_len < ilen - tag_len) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( ilen < tag_len || output_len < ilen - tag_len ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - return mbedtls_cipher_aead_decrypt(ctx, iv, iv_len, ad, ad_len, - input, ilen - tag_len, output, olen, - input + ilen - tag_len, tag_len); + return( mbedtls_cipher_aead_decrypt( ctx, iv, iv_len, ad, ad_len, + input, ilen - tag_len, output, olen, + input + ilen - tag_len, tag_len ) ); #else - return MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE ); #endif /* MBEDTLS_CIPHER_MODE_AEAD */ } #endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */ diff --git a/src/duckdb/third_party/mbedtls/library/cipher_wrap.cpp b/src/duckdb/third_party/mbedtls/library/cipher_wrap.cpp index bad4e7ce4..d7b2a3ce7 100644 --- a/src/duckdb/third_party/mbedtls/library/cipher_wrap.cpp +++ b/src/duckdb/third_party/mbedtls/library/cipher_wrap.cpp @@ -1,12 +1,24 @@ /** * \file cipher_wrap.c * - * \brief Generic cipher wrapper for Mbed TLS + * \brief Generic cipher wrapper for mbed TLS * * \author Adriaan de Jong * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" @@ -56,114 +68,110 @@ #include #endif +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#include +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif -enum mbedtls_cipher_base_index : uint8_t { - MBEDTLS_CIPHER_BASE_INDEX_AES = 0, - MBEDTLS_CIPHER_BASE_INDEX_GCM_AES = 3, -}; - -#if defined(MBEDTLS_GCM_C) && \ - (defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA) || \ - defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C)) +#if defined(MBEDTLS_GCM_C) /* shared by all GCM ciphers */ -static void *gcm_ctx_alloc(void) +static void *gcm_ctx_alloc( void ) { - void *ctx = mbedtls_calloc(1, sizeof(mbedtls_gcm_context)); + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) ); - if (ctx != NULL) { - mbedtls_gcm_init((mbedtls_gcm_context *) ctx); - } + if( ctx != NULL ) + mbedtls_gcm_init( (mbedtls_gcm_context *) ctx ); - return ctx; + return( ctx ); } -static void gcm_ctx_free(void *ctx) +static void gcm_ctx_free( void *ctx ) { - mbedtls_gcm_free((mbedtls_gcm_context *)ctx); - mbedtls_free(ctx); + mbedtls_gcm_free( (mbedtls_gcm_context *)ctx ); + mbedtls_free( ctx ); } #endif /* MBEDTLS_GCM_C */ -#if defined(MBEDTLS_CCM_C) && \ - (defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA) || \ - defined(MBEDTLS_ARIA_C) || defined(MBEDTLS_CAMELLIA_C)) +#if defined(MBEDTLS_CCM_C) /* shared by all CCM ciphers */ -static void *ccm_ctx_alloc(void) +static void *ccm_ctx_alloc( void ) { - void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ccm_context)); + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) ); - if (ctx != NULL) { - mbedtls_ccm_init((mbedtls_ccm_context *) ctx); - } + if( ctx != NULL ) + mbedtls_ccm_init( (mbedtls_ccm_context *) ctx ); - return ctx; + return( ctx ); } -static void ccm_ctx_free(void *ctx) +static void ccm_ctx_free( void *ctx ) { - mbedtls_ccm_free(ctx); - mbedtls_free(ctx); + mbedtls_ccm_free( ctx ); + mbedtls_free( ctx ); } #endif /* MBEDTLS_CCM_C */ #if defined(MBEDTLS_AES_C) -static int aes_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation, - const unsigned char *input, unsigned char *output) +static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, + const unsigned char *input, unsigned char *output ) { - return mbedtls_aes_crypt_ecb((mbedtls_aes_context *) ctx, operation, input, output); + return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int aes_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length, - unsigned char *iv, const unsigned char *input, unsigned char *output) +static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length, + unsigned char *iv, const unsigned char *input, unsigned char *output ) { - return mbedtls_aes_crypt_cbc((mbedtls_aes_context *) ctx, operation, length, iv, input, - output); + return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input, + output ); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) -static int aes_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation, - size_t length, size_t *iv_off, unsigned char *iv, - const unsigned char *input, unsigned char *output) +static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation, + size_t length, size_t *iv_off, unsigned char *iv, + const unsigned char *input, unsigned char *output ) { - return mbedtls_aes_crypt_cfb128((mbedtls_aes_context *) ctx, operation, length, iv_off, iv, - input, output); + return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv, + input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) -static int aes_crypt_ofb_wrap(void *ctx, size_t length, size_t *iv_off, - unsigned char *iv, const unsigned char *input, unsigned char *output) +static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off, + unsigned char *iv, const unsigned char *input, unsigned char *output ) { - return mbedtls_aes_crypt_ofb((mbedtls_aes_context *) ctx, length, iv_off, - iv, input, output); + return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off, + iv, input, output ); } #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) -static int aes_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off, - unsigned char *nonce_counter, unsigned char *stream_block, - const unsigned char *input, unsigned char *output) +static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, + unsigned char *nonce_counter, unsigned char *stream_block, + const unsigned char *input, unsigned char *output ) { - return mbedtls_aes_crypt_ctr((mbedtls_aes_context *) ctx, length, nc_off, nonce_counter, - stream_block, input, output); + return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter, + stream_block, input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) -static int aes_crypt_xts_wrap(void *ctx, mbedtls_operation_t operation, - size_t length, - const unsigned char data_unit[16], - const unsigned char *input, - unsigned char *output) +static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation, + size_t length, + const unsigned char data_unit[16], + const unsigned char *input, + unsigned char *output ) { mbedtls_aes_xts_context *xts_ctx = ctx; int mode; - switch (operation) { + switch( operation ) + { case MBEDTLS_ENCRYPT: mode = MBEDTLS_AES_ENCRYPT; break; @@ -174,42 +182,39 @@ static int aes_crypt_xts_wrap(void *ctx, mbedtls_operation_t operation, return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; } - return mbedtls_aes_crypt_xts(xts_ctx, mode, length, - data_unit, input, output); + return mbedtls_aes_crypt_xts( xts_ctx, mode, length, + data_unit, input, output ); } #endif /* MBEDTLS_CIPHER_MODE_XTS */ -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -static int aes_setkey_dec_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_aes_setkey_dec((mbedtls_aes_context *) ctx, key, key_bitlen); + return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen ); } -#endif -static int aes_setkey_enc_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_aes_setkey_enc((mbedtls_aes_context *) ctx, key, key_bitlen); + return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen ); } -static void *aes_ctx_alloc(void) +static void * aes_ctx_alloc( void ) { - mbedtls_aes_context *aes = (mbedtls_aes_context *)mbedtls_calloc(1, sizeof(mbedtls_aes_context)); + mbedtls_aes_context *aes = (mbedtls_aes_context *)mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) ); - if (aes == NULL) { - return NULL; - } + if( aes == NULL ) + return( NULL ); - mbedtls_aes_init(aes); + mbedtls_aes_init( aes ); - return aes; + return( aes ); } -static void aes_ctx_free(void *ctx) +static void aes_ctx_free( void *ctx ) { - mbedtls_aes_free((mbedtls_aes_context *) ctx); - mbedtls_free(ctx); + mbedtls_aes_free( (mbedtls_aes_context *) ctx ); + mbedtls_free( ctx ); } static const mbedtls_cipher_base_t aes_info = { @@ -234,232 +239,218 @@ static const mbedtls_cipher_base_t aes_info = { NULL, #endif aes_setkey_enc_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) aes_setkey_dec_wrap, -#endif aes_ctx_alloc, aes_ctx_free }; static const mbedtls_cipher_info_t aes_128_ecb_info = { - "AES-128-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_AES_128_ECB, + MBEDTLS_MODE_ECB, + 128, + "AES-128-ECB", 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 0, + 16, + &aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_ecb_info = { - "AES-192-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_AES_192_ECB, + MBEDTLS_MODE_ECB, + 192, + "AES-192-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; static const mbedtls_cipher_info_t aes_256_ecb_info = { - "AES-256-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_AES_256_ECB, + MBEDTLS_MODE_ECB, + 256, + "AES-256-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#endif #if defined(MBEDTLS_CIPHER_MODE_CBC) static const mbedtls_cipher_info_t aes_128_cbc_info = { + MBEDTLS_CIPHER_AES_128_CBC, + MBEDTLS_MODE_CBC, + 128, "AES-128-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_AES_128_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_cbc_info = { + MBEDTLS_CIPHER_AES_192_CBC, + MBEDTLS_MODE_CBC, + 192, "AES-192-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_AES_192_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; static const mbedtls_cipher_info_t aes_256_cbc_info = { + MBEDTLS_CIPHER_AES_256_CBC, + MBEDTLS_MODE_CBC, + 256, "AES-256-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_AES_256_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#endif #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) static const mbedtls_cipher_info_t aes_128_cfb128_info = { + MBEDTLS_CIPHER_AES_128_CFB128, + MBEDTLS_MODE_CFB, + 128, "AES-128-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_AES_128_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_cfb128_info = { + MBEDTLS_CIPHER_AES_192_CFB128, + MBEDTLS_MODE_CFB, + 192, "AES-192-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_AES_192_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; static const mbedtls_cipher_info_t aes_256_cfb128_info = { + MBEDTLS_CIPHER_AES_256_CFB128, + MBEDTLS_MODE_CFB, + 256, "AES-256-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_AES_256_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#endif #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_OFB) static const mbedtls_cipher_info_t aes_128_ofb_info = { + MBEDTLS_CIPHER_AES_128_OFB, + MBEDTLS_MODE_OFB, + 128, "AES-128-OFB", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_OFB, - MBEDTLS_CIPHER_AES_128_OFB, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_ofb_info = { + MBEDTLS_CIPHER_AES_192_OFB, + MBEDTLS_MODE_OFB, + 192, "AES-192-OFB", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_OFB, - MBEDTLS_CIPHER_AES_192_OFB, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; static const mbedtls_cipher_info_t aes_256_ofb_info = { + MBEDTLS_CIPHER_AES_256_OFB, + MBEDTLS_MODE_OFB, + 256, "AES-256-OFB", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_OFB, - MBEDTLS_CIPHER_AES_256_OFB, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#endif #endif /* MBEDTLS_CIPHER_MODE_OFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) static const mbedtls_cipher_info_t aes_128_ctr_info = { + MBEDTLS_CIPHER_AES_128_CTR, + MBEDTLS_MODE_CTR, + 128, "AES-128-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_AES_128_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_ctr_info = { + MBEDTLS_CIPHER_AES_192_CTR, + MBEDTLS_MODE_CTR, + 192, "AES-192-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_AES_192_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; static const mbedtls_cipher_info_t aes_256_ctr_info = { + MBEDTLS_CIPHER_AES_256_CTR, + MBEDTLS_MODE_CTR, + 256, "AES-256-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_AES_256_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_AES + 16, + &aes_info }; -#endif #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_CIPHER_MODE_XTS) -static int xts_aes_setkey_enc_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { mbedtls_aes_xts_context *xts_ctx = ctx; - return mbedtls_aes_xts_setkey_enc(xts_ctx, key, key_bitlen); + return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) ); } -static int xts_aes_setkey_dec_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { mbedtls_aes_xts_context *xts_ctx = ctx; - return mbedtls_aes_xts_setkey_dec(xts_ctx, key, key_bitlen); + return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) ); } -static void *xts_aes_ctx_alloc(void) +static void *xts_aes_ctx_alloc( void ) { - mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc(1, sizeof(*xts_ctx)); + mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) ); - if (xts_ctx != NULL) { - mbedtls_aes_xts_init(xts_ctx); - } + if( xts_ctx != NULL ) + mbedtls_aes_xts_init( xts_ctx ); - return xts_ctx; + return( xts_ctx ); } -static void xts_aes_ctx_free(void *ctx) +static void xts_aes_ctx_free( void *ctx ) { mbedtls_aes_xts_context *xts_ctx = ctx; - if (xts_ctx == NULL) { + if( xts_ctx == NULL ) return; - } - mbedtls_aes_xts_free(xts_ctx); - mbedtls_free(xts_ctx); + mbedtls_aes_xts_free( xts_ctx ); + mbedtls_free( xts_ctx ); } static const mbedtls_cipher_base_t xts_aes_info = { @@ -490,41 +481,36 @@ static const mbedtls_cipher_base_t xts_aes_info = { }; static const mbedtls_cipher_info_t aes_128_xts_info = { + MBEDTLS_CIPHER_AES_128_XTS, + MBEDTLS_MODE_XTS, + 256, "AES-128-XTS", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_XTS, - MBEDTLS_CIPHER_AES_128_XTS, 0, - MBEDTLS_CIPHER_BASE_INDEX_XTS_AES + 16, + &xts_aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_256_xts_info = { + MBEDTLS_CIPHER_AES_256_XTS, + MBEDTLS_MODE_XTS, + 512, "AES-256-XTS", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 512 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_XTS, - MBEDTLS_CIPHER_AES_256_XTS, 0, - MBEDTLS_CIPHER_BASE_INDEX_XTS_AES + 16, + &xts_aes_info }; -#endif #endif /* MBEDTLS_CIPHER_MODE_XTS */ -#endif /* MBEDTLS_AES_C */ -#if defined(MBEDTLS_GCM_C) && defined(MBEDTLS_CCM_GCM_CAN_AES) -static int gcm_aes_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +#if defined(MBEDTLS_GCM_C) +static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES, - key, key_bitlen); + return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES, + key, key_bitlen ); } -#endif /* MBEDTLS_GCM_C && MBEDTLS_CCM_GCM_CAN_AES */ -#if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA) static const mbedtls_cipher_base_t gcm_aes_info = { MBEDTLS_CIPHER_ID_AES, NULL, @@ -546,69 +532,54 @@ static const mbedtls_cipher_base_t gcm_aes_info = { #if defined(MBEDTLS_CIPHER_MODE_STREAM) NULL, #endif -#if defined(MBEDTLS_GCM_C) gcm_aes_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) gcm_aes_setkey_wrap, -#endif gcm_ctx_alloc, gcm_ctx_free, -#else - NULL, - NULL, - NULL, - NULL, -#endif /* MBEDTLS_GCM_C */ }; -#endif /* MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA */ -#if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA) static const mbedtls_cipher_info_t aes_128_gcm_info = { - "AES-128-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_AES_128_GCM, + MBEDTLS_MODE_GCM, + 128, + "AES-128-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_AES + 16, + &gcm_aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_gcm_info = { - "AES-192-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_AES_192_GCM, + MBEDTLS_MODE_GCM, + 192, + "AES-192-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_AES + 16, + &gcm_aes_info }; static const mbedtls_cipher_info_t aes_256_gcm_info = { - "AES-256-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_AES_256_GCM, + MBEDTLS_MODE_GCM, + 256, + "AES-256-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_AES + 16, + &gcm_aes_info }; -#endif -#endif /* MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA */ +#endif /* MBEDTLS_GCM_C */ -#if defined(MBEDTLS_CCM_C) && defined(MBEDTLS_CCM_GCM_CAN_AES) -static int ccm_aes_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +#if defined(MBEDTLS_CCM_C) +static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES, - key, key_bitlen); + return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES, + key, key_bitlen ); } -#endif /* MBEDTLS_CCM_C && MBEDTLS_CCM_GCM_CAN_AES */ -#if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA) static const mbedtls_cipher_base_t ccm_aes_info = { MBEDTLS_CIPHER_ID_AES, NULL, @@ -630,168 +601,149 @@ static const mbedtls_cipher_base_t ccm_aes_info = { #if defined(MBEDTLS_CIPHER_MODE_STREAM) NULL, #endif -#if defined(MBEDTLS_CCM_C) ccm_aes_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) ccm_aes_setkey_wrap, -#endif ccm_ctx_alloc, ccm_ctx_free, -#else - NULL, - NULL, - NULL, - NULL, -#endif }; -#endif /* MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA */ -#if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA) static const mbedtls_cipher_info_t aes_128_ccm_info = { - "AES-128-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_AES_128_CCM, + MBEDTLS_MODE_CCM, + 128, + "AES-128-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_AES + 16, + &ccm_aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_ccm_info = { - "AES-192-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_AES_192_CCM, + MBEDTLS_MODE_CCM, + 192, + "AES-192-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_AES + 16, + &ccm_aes_info }; static const mbedtls_cipher_info_t aes_256_ccm_info = { - "AES-256-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_AES_256_CCM, + MBEDTLS_MODE_CCM, + 256, + "AES-256-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_AES + 16, + &ccm_aes_info }; -#endif -#endif /* MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA */ -#if defined(MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_AES_VIA_LEGACY_OR_USE_PSA) static const mbedtls_cipher_info_t aes_128_ccm_star_no_tag_info = { - "AES-128-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 128, + "AES-128-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_AES + 16, + &ccm_aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_ccm_star_no_tag_info = { - "AES-192-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 192, + "AES-192-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_AES + 16, + &ccm_aes_info }; static const mbedtls_cipher_info_t aes_256_ccm_star_no_tag_info = { - "AES-256-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 256, + "AES-256-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_AES + 16, + &ccm_aes_info }; -#endif -#endif /* MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_AES_VIA_LEGACY_OR_USE_PSA */ +#endif /* MBEDTLS_CCM_C */ +#endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) -static int camellia_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation, - const unsigned char *input, unsigned char *output) +static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, + const unsigned char *input, unsigned char *output ) { - return mbedtls_camellia_crypt_ecb((mbedtls_camellia_context *) ctx, operation, input, - output); + return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input, + output ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int camellia_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, - size_t length, unsigned char *iv, - const unsigned char *input, unsigned char *output) +static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, + size_t length, unsigned char *iv, + const unsigned char *input, unsigned char *output ) { - return mbedtls_camellia_crypt_cbc((mbedtls_camellia_context *) ctx, operation, length, iv, - input, output); + return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv, + input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) -static int camellia_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation, - size_t length, size_t *iv_off, unsigned char *iv, - const unsigned char *input, unsigned char *output) +static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation, + size_t length, size_t *iv_off, unsigned char *iv, + const unsigned char *input, unsigned char *output ) { - return mbedtls_camellia_crypt_cfb128((mbedtls_camellia_context *) ctx, operation, length, - iv_off, iv, input, output); + return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length, + iv_off, iv, input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) -static int camellia_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off, - unsigned char *nonce_counter, unsigned char *stream_block, - const unsigned char *input, unsigned char *output) +static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, + unsigned char *nonce_counter, unsigned char *stream_block, + const unsigned char *input, unsigned char *output ) { - return mbedtls_camellia_crypt_ctr((mbedtls_camellia_context *) ctx, length, nc_off, - nonce_counter, stream_block, input, output); + return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off, + nonce_counter, stream_block, input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -static int camellia_setkey_dec_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_camellia_setkey_dec((mbedtls_camellia_context *) ctx, key, key_bitlen); + return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen ); } -#endif -static int camellia_setkey_enc_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_camellia_setkey_enc((mbedtls_camellia_context *) ctx, key, key_bitlen); + return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen ); } -static void *camellia_ctx_alloc(void) +static void * camellia_ctx_alloc( void ) { mbedtls_camellia_context *ctx; - ctx = (mbedtls_camellia_context *)mbedtls_calloc(1, sizeof(mbedtls_camellia_context)); + ctx = (mbedtls_camellia_context *)mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) ); - if (ctx == NULL) { - return NULL; - } + if( ctx == NULL ) + return( NULL ); - mbedtls_camellia_init(ctx); + mbedtls_camellia_init( ctx ); - return ctx; + return( ctx ); } -static void camellia_ctx_free(void *ctx) +static void camellia_ctx_free( void *ctx ) { - mbedtls_camellia_free((mbedtls_camellia_context *) ctx); - mbedtls_free(ctx); + mbedtls_camellia_free( (mbedtls_camellia_context *) ctx ); + mbedtls_free( ctx ); } static const mbedtls_cipher_base_t camellia_info = { @@ -816,157 +768,155 @@ static const mbedtls_cipher_base_t camellia_info = { NULL, #endif camellia_setkey_enc_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) camellia_setkey_dec_wrap, -#endif camellia_ctx_alloc, camellia_ctx_free }; static const mbedtls_cipher_info_t camellia_128_ecb_info = { - "CAMELLIA-128-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_CAMELLIA_128_ECB, + MBEDTLS_MODE_ECB, + 128, + "CAMELLIA-128-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_192_ecb_info = { - "CAMELLIA-192-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_CAMELLIA_192_ECB, + MBEDTLS_MODE_ECB, + 192, + "CAMELLIA-192-ECB", 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 0, + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_256_ecb_info = { - "CAMELLIA-256-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_CAMELLIA_256_ECB, + MBEDTLS_MODE_ECB, + 256, + "CAMELLIA-256-ECB", 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 0, + 16, + &camellia_info }; #if defined(MBEDTLS_CIPHER_MODE_CBC) static const mbedtls_cipher_info_t camellia_128_cbc_info = { + MBEDTLS_CIPHER_CAMELLIA_128_CBC, + MBEDTLS_MODE_CBC, + 128, "CAMELLIA-128-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_CAMELLIA_128_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_192_cbc_info = { + MBEDTLS_CIPHER_CAMELLIA_192_CBC, + MBEDTLS_MODE_CBC, + 192, "CAMELLIA-192-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_CAMELLIA_192_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_256_cbc_info = { + MBEDTLS_CIPHER_CAMELLIA_256_CBC, + MBEDTLS_MODE_CBC, + 256, "CAMELLIA-256-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_CAMELLIA_256_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) static const mbedtls_cipher_info_t camellia_128_cfb128_info = { + MBEDTLS_CIPHER_CAMELLIA_128_CFB128, + MBEDTLS_MODE_CFB, + 128, "CAMELLIA-128-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_CAMELLIA_128_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_192_cfb128_info = { + MBEDTLS_CIPHER_CAMELLIA_192_CFB128, + MBEDTLS_MODE_CFB, + 192, "CAMELLIA-192-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_CAMELLIA_192_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_256_cfb128_info = { + MBEDTLS_CIPHER_CAMELLIA_256_CFB128, + MBEDTLS_MODE_CFB, + 256, "CAMELLIA-256-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_CAMELLIA_256_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) static const mbedtls_cipher_info_t camellia_128_ctr_info = { + MBEDTLS_CIPHER_CAMELLIA_128_CTR, + MBEDTLS_MODE_CTR, + 128, "CAMELLIA-128-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_CAMELLIA_128_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_192_ctr_info = { + MBEDTLS_CIPHER_CAMELLIA_192_CTR, + MBEDTLS_MODE_CTR, + 192, "CAMELLIA-192-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_CAMELLIA_192_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; static const mbedtls_cipher_info_t camellia_256_ctr_info = { + MBEDTLS_CIPHER_CAMELLIA_256_CTR, + MBEDTLS_MODE_CTR, + 256, "CAMELLIA-256-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_CAMELLIA_256_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_CAMELLIA + 16, + &camellia_info }; #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_GCM_C) -static int gcm_camellia_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA, - key, key_bitlen); + return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA, + key, key_bitlen ); } static const mbedtls_cipher_base_t gcm_camellia_info = { @@ -991,53 +941,51 @@ static const mbedtls_cipher_base_t gcm_camellia_info = { NULL, #endif gcm_camellia_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) gcm_camellia_setkey_wrap, -#endif gcm_ctx_alloc, gcm_ctx_free, }; static const mbedtls_cipher_info_t camellia_128_gcm_info = { - "CAMELLIA-128-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_CAMELLIA_128_GCM, + MBEDTLS_MODE_GCM, + 128, + "CAMELLIA-128-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA + 16, + &gcm_camellia_info }; static const mbedtls_cipher_info_t camellia_192_gcm_info = { - "CAMELLIA-192-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_CAMELLIA_192_GCM, + MBEDTLS_MODE_GCM, + 192, + "CAMELLIA-192-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA + 16, + &gcm_camellia_info }; static const mbedtls_cipher_info_t camellia_256_gcm_info = { - "CAMELLIA-256-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_CAMELLIA_256_GCM, + MBEDTLS_MODE_GCM, + 256, + "CAMELLIA-256-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_CAMELLIA + 16, + &gcm_camellia_info }; #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) -static int ccm_camellia_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA, - key, key_bitlen); + return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA, + key, key_bitlen ); } static const mbedtls_cipher_base_t ccm_camellia_info = { @@ -1062,77 +1010,75 @@ static const mbedtls_cipher_base_t ccm_camellia_info = { NULL, #endif ccm_camellia_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) ccm_camellia_setkey_wrap, -#endif ccm_ctx_alloc, ccm_ctx_free, }; static const mbedtls_cipher_info_t camellia_128_ccm_info = { - "CAMELLIA-128-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_CAMELLIA_128_CCM, + MBEDTLS_MODE_CCM, + 128, + "CAMELLIA-128-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA + 16, + &ccm_camellia_info }; static const mbedtls_cipher_info_t camellia_192_ccm_info = { - "CAMELLIA-192-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_CAMELLIA_192_CCM, + MBEDTLS_MODE_CCM, + 192, + "CAMELLIA-192-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA + 16, + &ccm_camellia_info }; static const mbedtls_cipher_info_t camellia_256_ccm_info = { - "CAMELLIA-256-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_CAMELLIA_256_CCM, + MBEDTLS_MODE_CCM, + 256, + "CAMELLIA-256-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA + 16, + &ccm_camellia_info }; static const mbedtls_cipher_info_t camellia_128_ccm_star_no_tag_info = { - "CAMELLIA-128-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 128, + "CAMELLIA-128-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA + 16, + &ccm_camellia_info }; static const mbedtls_cipher_info_t camellia_192_ccm_star_no_tag_info = { - "CAMELLIA-192-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 192, + "CAMELLIA-192-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA + 16, + &ccm_camellia_info }; static const mbedtls_cipher_info_t camellia_256_ccm_star_no_tag_info = { - "CAMELLIA-256-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 256, + "CAMELLIA-256-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_CAMELLIA + 16, + &ccm_camellia_info }; #endif /* MBEDTLS_CCM_C */ @@ -1140,76 +1086,73 @@ static const mbedtls_cipher_info_t camellia_256_ccm_star_no_tag_info = { #if defined(MBEDTLS_ARIA_C) -static int aria_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation, - const unsigned char *input, unsigned char *output) +static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, + const unsigned char *input, unsigned char *output ) { (void) operation; - return mbedtls_aria_crypt_ecb((mbedtls_aria_context *) ctx, input, - output); + return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input, + output ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int aria_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, - size_t length, unsigned char *iv, - const unsigned char *input, unsigned char *output) +static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, + size_t length, unsigned char *iv, + const unsigned char *input, unsigned char *output ) { - return mbedtls_aria_crypt_cbc((mbedtls_aria_context *) ctx, operation, length, iv, - input, output); + return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv, + input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) -static int aria_crypt_cfb128_wrap(void *ctx, mbedtls_operation_t operation, - size_t length, size_t *iv_off, unsigned char *iv, - const unsigned char *input, unsigned char *output) +static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation, + size_t length, size_t *iv_off, unsigned char *iv, + const unsigned char *input, unsigned char *output ) { - return mbedtls_aria_crypt_cfb128((mbedtls_aria_context *) ctx, operation, length, - iv_off, iv, input, output); + return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length, + iv_off, iv, input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) -static int aria_crypt_ctr_wrap(void *ctx, size_t length, size_t *nc_off, - unsigned char *nonce_counter, unsigned char *stream_block, - const unsigned char *input, unsigned char *output) +static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, + unsigned char *nonce_counter, unsigned char *stream_block, + const unsigned char *input, unsigned char *output ) { - return mbedtls_aria_crypt_ctr((mbedtls_aria_context *) ctx, length, nc_off, - nonce_counter, stream_block, input, output); + return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off, + nonce_counter, stream_block, input, output ); } #endif /* MBEDTLS_CIPHER_MODE_CTR */ -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) -static int aria_setkey_dec_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_aria_setkey_dec((mbedtls_aria_context *) ctx, key, key_bitlen); + return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen ); } -#endif -static int aria_setkey_enc_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_aria_setkey_enc((mbedtls_aria_context *) ctx, key, key_bitlen); + return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen ); } -static void *aria_ctx_alloc(void) +static void * aria_ctx_alloc( void ) { mbedtls_aria_context *ctx; - ctx = (mbedtls_aria_context *)mbedtls_calloc(1, sizeof(mbedtls_aria_context)); + ctx = (mbedtls_aria_context *)mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) ); - if (ctx == NULL) { - return NULL; - } + if( ctx == NULL ) + return( NULL ); - mbedtls_aria_init(ctx); + mbedtls_aria_init( ctx ); - return ctx; + return( ctx ); } -static void aria_ctx_free(void *ctx) +static void aria_ctx_free( void *ctx ) { - mbedtls_aria_free((mbedtls_aria_context *) ctx); - mbedtls_free(ctx); + mbedtls_aria_free( (mbedtls_aria_context *) ctx ); + mbedtls_free( ctx ); } static const mbedtls_cipher_base_t aria_info = { @@ -1234,157 +1177,155 @@ static const mbedtls_cipher_base_t aria_info = { NULL, #endif aria_setkey_enc_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) aria_setkey_dec_wrap, -#endif aria_ctx_alloc, aria_ctx_free }; static const mbedtls_cipher_info_t aria_128_ecb_info = { - "ARIA-128-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_ARIA_128_ECB, + MBEDTLS_MODE_ECB, + 128, + "ARIA-128-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_192_ecb_info = { - "ARIA-192-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_ARIA_192_ECB, + MBEDTLS_MODE_ECB, + 192, + "ARIA-192-ECB", 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 0, + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_256_ecb_info = { - "ARIA-256-ECB", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_ARIA_256_ECB, + MBEDTLS_MODE_ECB, + 256, + "ARIA-256-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; #if defined(MBEDTLS_CIPHER_MODE_CBC) static const mbedtls_cipher_info_t aria_128_cbc_info = { + MBEDTLS_CIPHER_ARIA_128_CBC, + MBEDTLS_MODE_CBC, + 128, "ARIA-128-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_ARIA_128_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_192_cbc_info = { + MBEDTLS_CIPHER_ARIA_192_CBC, + MBEDTLS_MODE_CBC, + 192, "ARIA-192-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_ARIA_192_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_256_cbc_info = { + MBEDTLS_CIPHER_ARIA_256_CBC, + MBEDTLS_MODE_CBC, + 256, "ARIA-256-CBC", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_ARIA_256_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CFB) static const mbedtls_cipher_info_t aria_128_cfb128_info = { + MBEDTLS_CIPHER_ARIA_128_CFB128, + MBEDTLS_MODE_CFB, + 128, "ARIA-128-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_ARIA_128_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_192_cfb128_info = { + MBEDTLS_CIPHER_ARIA_192_CFB128, + MBEDTLS_MODE_CFB, + 192, "ARIA-192-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_ARIA_192_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_256_cfb128_info = { + MBEDTLS_CIPHER_ARIA_256_CFB128, + MBEDTLS_MODE_CFB, + 256, "ARIA-256-CFB128", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CFB, - MBEDTLS_CIPHER_ARIA_256_CFB128, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; #endif /* MBEDTLS_CIPHER_MODE_CFB */ #if defined(MBEDTLS_CIPHER_MODE_CTR) static const mbedtls_cipher_info_t aria_128_ctr_info = { + MBEDTLS_CIPHER_ARIA_128_CTR, + MBEDTLS_MODE_CTR, + 128, "ARIA-128-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_ARIA_128_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_192_ctr_info = { + MBEDTLS_CIPHER_ARIA_192_CTR, + MBEDTLS_MODE_CTR, + 192, "ARIA-192-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_ARIA_192_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; static const mbedtls_cipher_info_t aria_256_ctr_info = { + MBEDTLS_CIPHER_ARIA_256_CTR, + MBEDTLS_MODE_CTR, + 256, "ARIA-256-CTR", 16, - 16 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CTR, - MBEDTLS_CIPHER_ARIA_256_CTR, 0, - MBEDTLS_CIPHER_BASE_INDEX_ARIA + 16, + &aria_info }; #endif /* MBEDTLS_CIPHER_MODE_CTR */ #if defined(MBEDTLS_GCM_C) -static int gcm_aria_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_gcm_setkey((mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA, - key, key_bitlen); + return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA, + key, key_bitlen ); } static const mbedtls_cipher_base_t gcm_aria_info = { @@ -1409,53 +1350,51 @@ static const mbedtls_cipher_base_t gcm_aria_info = { NULL, #endif gcm_aria_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) gcm_aria_setkey_wrap, -#endif gcm_ctx_alloc, gcm_ctx_free, }; static const mbedtls_cipher_info_t aria_128_gcm_info = { - "ARIA-128-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_ARIA_128_GCM, + MBEDTLS_MODE_GCM, + 128, + "ARIA-128-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA + 16, + &gcm_aria_info }; static const mbedtls_cipher_info_t aria_192_gcm_info = { - "ARIA-192-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_ARIA_192_GCM, + MBEDTLS_MODE_GCM, + 192, + "ARIA-192-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA + 16, + &gcm_aria_info }; static const mbedtls_cipher_info_t aria_256_gcm_info = { - "ARIA-256-GCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_GCM, MBEDTLS_CIPHER_ARIA_256_GCM, + MBEDTLS_MODE_GCM, + 256, + "ARIA-256-GCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_GCM_ARIA + 16, + &gcm_aria_info }; #endif /* MBEDTLS_GCM_C */ #if defined(MBEDTLS_CCM_C) -static int ccm_aria_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_ccm_setkey((mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA, - key, key_bitlen); + return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA, + key, key_bitlen ); } static const mbedtls_cipher_base_t ccm_aria_info = { @@ -1480,77 +1419,75 @@ static const mbedtls_cipher_base_t ccm_aria_info = { NULL, #endif ccm_aria_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) ccm_aria_setkey_wrap, -#endif ccm_ctx_alloc, ccm_ctx_free, }; static const mbedtls_cipher_info_t aria_128_ccm_info = { - "ARIA-128-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_ARIA_128_CCM, + MBEDTLS_MODE_CCM, + 128, + "ARIA-128-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA + 16, + &ccm_aria_info }; static const mbedtls_cipher_info_t aria_192_ccm_info = { - "ARIA-192-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_ARIA_192_CCM, + MBEDTLS_MODE_CCM, + 192, + "ARIA-192-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA + 16, + &ccm_aria_info }; static const mbedtls_cipher_info_t aria_256_ccm_info = { - "ARIA-256-CCM", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM, MBEDTLS_CIPHER_ARIA_256_CCM, + MBEDTLS_MODE_CCM, + 256, + "ARIA-256-CCM", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA + 16, + &ccm_aria_info }; static const mbedtls_cipher_info_t aria_128_ccm_star_no_tag_info = { - "ARIA-128-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 128, + "ARIA-128-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA + 16, + &ccm_aria_info }; static const mbedtls_cipher_info_t aria_192_ccm_star_no_tag_info = { - "ARIA-192-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 192, + "ARIA-192-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA + 16, + &ccm_aria_info }; static const mbedtls_cipher_info_t aria_256_ccm_star_no_tag_info = { - "ARIA-256-CCM*-NO-TAG", - 16, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CCM_STAR_NO_TAG, MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG, + MBEDTLS_MODE_CCM_STAR_NO_TAG, + 256, + "ARIA-256-CCM*-NO-TAG", + 12, MBEDTLS_CIPHER_VARIABLE_IV_LEN, - MBEDTLS_CIPHER_BASE_INDEX_CCM_ARIA + 16, + &ccm_aria_info }; #endif /* MBEDTLS_CCM_C */ @@ -1558,123 +1495,121 @@ static const mbedtls_cipher_info_t aria_256_ccm_star_no_tag_info = { #if defined(MBEDTLS_DES_C) -static int des_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation, - const unsigned char *input, unsigned char *output) +static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, + const unsigned char *input, unsigned char *output ) { ((void) operation); - return mbedtls_des_crypt_ecb((mbedtls_des_context *) ctx, input, output); + return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output ); } -static int des3_crypt_ecb_wrap(void *ctx, mbedtls_operation_t operation, - const unsigned char *input, unsigned char *output) +static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, + const unsigned char *input, unsigned char *output ) { ((void) operation); - return mbedtls_des3_crypt_ecb((mbedtls_des3_context *) ctx, input, output); + return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output ); } #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int des_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length, - unsigned char *iv, const unsigned char *input, unsigned char *output) +static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length, + unsigned char *iv, const unsigned char *input, unsigned char *output ) { - return mbedtls_des_crypt_cbc((mbedtls_des_context *) ctx, operation, length, iv, input, - output); + return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input, + output ); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ #if defined(MBEDTLS_CIPHER_MODE_CBC) -static int des3_crypt_cbc_wrap(void *ctx, mbedtls_operation_t operation, size_t length, - unsigned char *iv, const unsigned char *input, unsigned char *output) +static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length, + unsigned char *iv, const unsigned char *input, unsigned char *output ) { - return mbedtls_des3_crypt_cbc((mbedtls_des3_context *) ctx, operation, length, iv, input, - output); + return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input, + output ); } #endif /* MBEDTLS_CIPHER_MODE_CBC */ -static int des_setkey_dec_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { ((void) key_bitlen); - return mbedtls_des_setkey_dec((mbedtls_des_context *) ctx, key); + return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key ); } -static int des_setkey_enc_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { ((void) key_bitlen); - return mbedtls_des_setkey_enc((mbedtls_des_context *) ctx, key); + return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key ); } -static int des3_set2key_dec_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { ((void) key_bitlen); - return mbedtls_des3_set2key_dec((mbedtls_des3_context *) ctx, key); + return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key ); } -static int des3_set2key_enc_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { ((void) key_bitlen); - return mbedtls_des3_set2key_enc((mbedtls_des3_context *) ctx, key); + return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key ); } -static int des3_set3key_dec_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { ((void) key_bitlen); - return mbedtls_des3_set3key_dec((mbedtls_des3_context *) ctx, key); + return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key ); } -static int des3_set3key_enc_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { ((void) key_bitlen); - return mbedtls_des3_set3key_enc((mbedtls_des3_context *) ctx, key); + return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key ); } -static void *des_ctx_alloc(void) +static void * des_ctx_alloc( void ) { - mbedtls_des_context *des = mbedtls_calloc(1, sizeof(mbedtls_des_context)); + mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) ); - if (des == NULL) { - return NULL; - } + if( des == NULL ) + return( NULL ); - mbedtls_des_init(des); + mbedtls_des_init( des ); - return des; + return( des ); } -static void des_ctx_free(void *ctx) +static void des_ctx_free( void *ctx ) { - mbedtls_des_free((mbedtls_des_context *) ctx); - mbedtls_free(ctx); + mbedtls_des_free( (mbedtls_des_context *) ctx ); + mbedtls_free( ctx ); } -static void *des3_ctx_alloc(void) +static void * des3_ctx_alloc( void ) { mbedtls_des3_context *des3; - des3 = mbedtls_calloc(1, sizeof(mbedtls_des3_context)); + des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) ); - if (des3 == NULL) { - return NULL; - } + if( des3 == NULL ) + return( NULL ); - mbedtls_des3_init(des3); + mbedtls_des3_init( des3 ); - return des3; + return( des3 ); } -static void des3_ctx_free(void *ctx) +static void des3_ctx_free( void *ctx ) { - mbedtls_des3_free((mbedtls_des3_context *) ctx); - mbedtls_free(ctx); + mbedtls_des3_free( (mbedtls_des3_context *) ctx ); + mbedtls_free( ctx ); } static const mbedtls_cipher_base_t des_info = { @@ -1705,26 +1640,26 @@ static const mbedtls_cipher_base_t des_info = { }; static const mbedtls_cipher_info_t des_ecb_info = { - "DES-ECB", - 8, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - MBEDTLS_KEY_LENGTH_DES >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_DES_ECB, + MBEDTLS_MODE_ECB, + MBEDTLS_KEY_LENGTH_DES, + "DES-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_DES + 8, + &des_info }; #if defined(MBEDTLS_CIPHER_MODE_CBC) static const mbedtls_cipher_info_t des_cbc_info = { + MBEDTLS_CIPHER_DES_CBC, + MBEDTLS_MODE_CBC, + MBEDTLS_KEY_LENGTH_DES, "DES-CBC", 8, - 8 >> MBEDTLS_IV_SIZE_SHIFT, - MBEDTLS_KEY_LENGTH_DES >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_DES_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_DES + 8, + &des_info }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -1756,26 +1691,26 @@ static const mbedtls_cipher_base_t des_ede_info = { }; static const mbedtls_cipher_info_t des_ede_ecb_info = { - "DES-EDE-ECB", - 8, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - MBEDTLS_KEY_LENGTH_DES_EDE >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_DES_EDE_ECB, + MBEDTLS_MODE_ECB, + MBEDTLS_KEY_LENGTH_DES_EDE, + "DES-EDE-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_DES_EDE + 8, + &des_ede_info }; #if defined(MBEDTLS_CIPHER_MODE_CBC) static const mbedtls_cipher_info_t des_ede_cbc_info = { + MBEDTLS_CIPHER_DES_EDE_CBC, + MBEDTLS_MODE_CBC, + MBEDTLS_KEY_LENGTH_DES_EDE, "DES-EDE-CBC", 8, - 8 >> MBEDTLS_IV_SIZE_SHIFT, - MBEDTLS_KEY_LENGTH_DES_EDE >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_DES_EDE_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_DES_EDE + 8, + &des_ede_info }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ @@ -1807,77 +1742,73 @@ static const mbedtls_cipher_base_t des_ede3_info = { }; static const mbedtls_cipher_info_t des_ede3_ecb_info = { - "DES-EDE3-ECB", - 8, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - MBEDTLS_KEY_LENGTH_DES_EDE3 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_ECB, MBEDTLS_CIPHER_DES_EDE3_ECB, + MBEDTLS_MODE_ECB, + MBEDTLS_KEY_LENGTH_DES_EDE3, + "DES-EDE3-ECB", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_DES_EDE3 + 8, + &des_ede3_info }; #if defined(MBEDTLS_CIPHER_MODE_CBC) static const mbedtls_cipher_info_t des_ede3_cbc_info = { + MBEDTLS_CIPHER_DES_EDE3_CBC, + MBEDTLS_MODE_CBC, + MBEDTLS_KEY_LENGTH_DES_EDE3, "DES-EDE3-CBC", 8, - 8 >> MBEDTLS_IV_SIZE_SHIFT, - MBEDTLS_KEY_LENGTH_DES_EDE3 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CBC, - MBEDTLS_CIPHER_DES_EDE3_CBC, 0, - MBEDTLS_CIPHER_BASE_INDEX_DES_EDE3 + 8, + &des_ede3_info }; #endif /* MBEDTLS_CIPHER_MODE_CBC */ #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_CHACHA20_C) -static int chacha20_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int chacha20_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - if (key_bitlen != 256U) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( key_bitlen != 256U ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - if (0 != mbedtls_chacha20_setkey((mbedtls_chacha20_context *) ctx, key)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - return 0; + return( 0 ); } -static int chacha20_stream_wrap(void *ctx, size_t length, - const unsigned char *input, - unsigned char *output) +static int chacha20_stream_wrap( void *ctx, size_t length, + const unsigned char *input, + unsigned char *output ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - ret = mbedtls_chacha20_update(ctx, length, input, output); - if (ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + ret = mbedtls_chacha20_update( ctx, length, input, output ); + if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - return ret; + return( ret ); } -static void *chacha20_ctx_alloc(void) +static void * chacha20_ctx_alloc( void ) { mbedtls_chacha20_context *ctx; - ctx = mbedtls_calloc(1, sizeof(mbedtls_chacha20_context)); + ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) ); - if (ctx == NULL) { - return NULL; - } + if( ctx == NULL ) + return( NULL ); - mbedtls_chacha20_init(ctx); + mbedtls_chacha20_init( ctx ); - return ctx; + return( ctx ); } -static void chacha20_ctx_free(void *ctx) +static void chacha20_ctx_free( void *ctx ) { - mbedtls_chacha20_free((mbedtls_chacha20_context *) ctx); - mbedtls_free(ctx); + mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx ); + mbedtls_free( ctx ); } static const mbedtls_cipher_base_t chacha20_base_info = { @@ -1902,59 +1833,54 @@ static const mbedtls_cipher_base_t chacha20_base_info = { chacha20_stream_wrap, #endif chacha20_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) chacha20_setkey_wrap, -#endif chacha20_ctx_alloc, chacha20_ctx_free }; static const mbedtls_cipher_info_t chacha20_info = { - "CHACHA20", - 1, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_STREAM, MBEDTLS_CIPHER_CHACHA20, + MBEDTLS_MODE_STREAM, + 256, + "CHACHA20", + 12, 0, - MBEDTLS_CIPHER_BASE_INDEX_CHACHA20_BASE + 1, + &chacha20_base_info }; #endif /* MBEDTLS_CHACHA20_C */ #if defined(MBEDTLS_CHACHAPOLY_C) -static int chachapoly_setkey_wrap(void *ctx, - const unsigned char *key, - unsigned int key_bitlen) +static int chachapoly_setkey_wrap( void *ctx, + const unsigned char *key, + unsigned int key_bitlen ) { - if (key_bitlen != 256U) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if( key_bitlen != 256U ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - if (0 != mbedtls_chachapoly_setkey((mbedtls_chachapoly_context *) ctx, key)) { - return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; - } + if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) ) + return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - return 0; + return( 0 ); } -static void *chachapoly_ctx_alloc(void) +static void * chachapoly_ctx_alloc( void ) { mbedtls_chachapoly_context *ctx; - ctx = mbedtls_calloc(1, sizeof(mbedtls_chachapoly_context)); + ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) ); - if (ctx == NULL) { - return NULL; - } + if( ctx == NULL ) + return( NULL ); - mbedtls_chachapoly_init(ctx); + mbedtls_chachapoly_init( ctx ); - return ctx; + return( ctx ); } -static void chachapoly_ctx_free(void *ctx) +static void chachapoly_ctx_free( void *ctx ) { - mbedtls_chachapoly_free((mbedtls_chachapoly_context *) ctx); - mbedtls_free(ctx); + mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx ); + mbedtls_free( ctx ); } static const mbedtls_cipher_base_t chachapoly_base_info = { @@ -1979,50 +1905,48 @@ static const mbedtls_cipher_base_t chachapoly_base_info = { NULL, #endif chachapoly_setkey_wrap, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) chachapoly_setkey_wrap, -#endif chachapoly_ctx_alloc, chachapoly_ctx_free }; static const mbedtls_cipher_info_t chachapoly_info = { - "CHACHA20-POLY1305", - 1, - 12 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_CHACHAPOLY, MBEDTLS_CIPHER_CHACHA20_POLY1305, + MBEDTLS_MODE_CHACHAPOLY, + 256, + "CHACHA20-POLY1305", + 12, 0, - MBEDTLS_CIPHER_BASE_INDEX_CHACHAPOLY_BASE + 1, + &chachapoly_base_info }; #endif /* MBEDTLS_CHACHAPOLY_C */ #if defined(MBEDTLS_CIPHER_NULL_CIPHER) -static int null_crypt_stream(void *ctx, size_t length, - const unsigned char *input, - unsigned char *output) +static int null_crypt_stream( void *ctx, size_t length, + const unsigned char *input, + unsigned char *output ) { ((void) ctx); - memmove(output, input, length); - return 0; + memmove( output, input, length ); + return( 0 ); } -static int null_setkey(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int null_setkey( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { ((void) ctx); ((void) key); ((void) key_bitlen); - return 0; + return( 0 ); } -static void *null_ctx_alloc(void) +static void * null_ctx_alloc( void ) { - return (void *) 1; + return( (void *) 1 ); } -static void null_ctx_free(void *ctx) +static void null_ctx_free( void *ctx ) { ((void) ctx); } @@ -2049,55 +1973,52 @@ static const mbedtls_cipher_base_t null_base_info = { null_crypt_stream, #endif null_setkey, -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) null_setkey, -#endif null_ctx_alloc, null_ctx_free }; static const mbedtls_cipher_info_t null_cipher_info = { - "NULL", - 1, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 0 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_STREAM, MBEDTLS_CIPHER_NULL, + MBEDTLS_MODE_STREAM, + 0, + "NULL", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_NULL_BASE + 1, + &null_base_info }; #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */ #if defined(MBEDTLS_NIST_KW_C) -static void *kw_ctx_alloc(void) +static void *kw_ctx_alloc( void ) { - void *ctx = mbedtls_calloc(1, sizeof(mbedtls_nist_kw_context)); + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) ); - if (ctx != NULL) { - mbedtls_nist_kw_init((mbedtls_nist_kw_context *) ctx); - } + if( ctx != NULL ) + mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx ); - return ctx; + return( ctx ); } -static void kw_ctx_free(void *ctx) +static void kw_ctx_free( void *ctx ) { - mbedtls_nist_kw_free(ctx); - mbedtls_free(ctx); + mbedtls_nist_kw_free( ctx ); + mbedtls_free( ctx ); } -static int kw_aes_setkey_wrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_nist_kw_setkey((mbedtls_nist_kw_context *) ctx, - MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1); + return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx, + MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 ); } -static int kw_aes_setkey_unwrap(void *ctx, const unsigned char *key, - unsigned int key_bitlen) +static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key, + unsigned int key_bitlen ) { - return mbedtls_nist_kw_setkey((mbedtls_nist_kw_context *) ctx, - MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0); + return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx, + MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 ); } static const mbedtls_cipher_base_t kw_aes_info = { @@ -2128,140 +2049,116 @@ static const mbedtls_cipher_base_t kw_aes_info = { }; static const mbedtls_cipher_info_t aes_128_nist_kw_info = { - "AES-128-KW", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_KW, MBEDTLS_CIPHER_AES_128_KW, + MBEDTLS_MODE_KW, + 128, + "AES-128-KW", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_KW_AES + 16, + &kw_aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_nist_kw_info = { - "AES-192-KW", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_KW, MBEDTLS_CIPHER_AES_192_KW, + MBEDTLS_MODE_KW, + 192, + "AES-192-KW", 0, - MBEDTLS_CIPHER_BASE_INDEX_KW_AES + 0, + 16, + &kw_aes_info }; static const mbedtls_cipher_info_t aes_256_nist_kw_info = { - "AES-256-KW", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_KW, MBEDTLS_CIPHER_AES_256_KW, + MBEDTLS_MODE_KW, + 256, + "AES-256-KW", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_KW_AES + 16, + &kw_aes_info }; -#endif static const mbedtls_cipher_info_t aes_128_nist_kwp_info = { - "AES-128-KWP", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 128 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_KWP, MBEDTLS_CIPHER_AES_128_KWP, + MBEDTLS_MODE_KWP, + 128, + "AES-128-KWP", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_KW_AES + 16, + &kw_aes_info }; -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) static const mbedtls_cipher_info_t aes_192_nist_kwp_info = { - "AES-192-KWP", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 192 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_KWP, MBEDTLS_CIPHER_AES_192_KWP, + MBEDTLS_MODE_KWP, + 192, + "AES-192-KWP", 0, - MBEDTLS_CIPHER_BASE_INDEX_KW_AES + 0, + 16, + &kw_aes_info }; static const mbedtls_cipher_info_t aes_256_nist_kwp_info = { - "AES-256-KWP", - 16, - 0 >> MBEDTLS_IV_SIZE_SHIFT, - 256 >> MBEDTLS_KEY_BITLEN_SHIFT, - MBEDTLS_MODE_KWP, MBEDTLS_CIPHER_AES_256_KWP, + MBEDTLS_MODE_KWP, + 256, + "AES-256-KWP", + 0, 0, - MBEDTLS_CIPHER_BASE_INDEX_KW_AES + 16, + &kw_aes_info }; -#endif #endif /* MBEDTLS_NIST_KW_C */ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] = { #if defined(MBEDTLS_AES_C) { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info }, { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info }, -#endif #if defined(MBEDTLS_CIPHER_MODE_CBC) { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info }, { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info }, #endif -#endif #if defined(MBEDTLS_CIPHER_MODE_CFB) { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info }, { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info }, #endif -#endif #if defined(MBEDTLS_CIPHER_MODE_OFB) { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info }, { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info }, #endif -#endif #if defined(MBEDTLS_CIPHER_MODE_CTR) { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info }, { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info }, #endif -#endif #if defined(MBEDTLS_CIPHER_MODE_XTS) { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info }, #endif -#endif -#endif /* MBEDTLS_AES_C */ -#if defined(MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA) +#if defined(MBEDTLS_GCM_C) { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info }, { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info }, #endif -#endif -#if defined(MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA) +#if defined(MBEDTLS_CCM_C) { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info }, { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info }, -#endif -#endif -#if defined(MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_AES_VIA_LEGACY_OR_USE_PSA) { MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG, &aes_128_ccm_star_no_tag_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG, &aes_192_ccm_star_no_tag_info }, { MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG, &aes_256_ccm_star_no_tag_info }, #endif -#endif +#endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info }, @@ -2352,16 +2249,12 @@ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] = #if defined(MBEDTLS_NIST_KW_C) { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info }, { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info }, -#endif { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info }, { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info }, #endif -#endif #if defined(MBEDTLS_CIPHER_NULL_CIPHER) { MBEDTLS_CIPHER_NULL, &null_cipher_info }, @@ -2370,13 +2263,8 @@ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] = { MBEDTLS_CIPHER_NONE, NULL } }; -#define NUM_CIPHERS (sizeof(mbedtls_cipher_definitions) / \ - sizeof(mbedtls_cipher_definitions[0])) +#define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \ + sizeof(mbedtls_cipher_definitions[0]) ) int mbedtls_cipher_supported[NUM_CIPHERS]; -const mbedtls_cipher_base_t *mbedtls_cipher_base_lookup_table[] = { - /* MBEDTLS_CIPHER_BASE_INDEX_AES */ &aes_info, - /* MBEDTLS_CIPHER_BASE_INDEX_GCM_AES */ &gcm_aes_info, -}; - #endif /* MBEDTLS_CIPHER_C */ diff --git a/src/duckdb/third_party/mbedtls/library/cipher_wrap.h b/src/duckdb/third_party/mbedtls/library/cipher_wrap.h index f22915120..90563d85d 100644 --- a/src/duckdb/third_party/mbedtls/library/cipher_wrap.h +++ b/src/duckdb/third_party/mbedtls/library/cipher_wrap.h @@ -7,7 +7,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_CIPHER_WRAP_H #define MBEDTLS_CIPHER_WRAP_H @@ -24,128 +36,85 @@ extern "C" { #endif -/* Support for GCM either through Mbed TLS SW implementation or PSA */ -#if defined(MBEDTLS_GCM_C) || \ - (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_GCM)) -#define MBEDTLS_CIPHER_HAVE_GCM_VIA_LEGACY_OR_USE_PSA -#endif - -#if (defined(MBEDTLS_GCM_C) && defined(MBEDTLS_AES_C)) || \ - (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_GCM) && defined(PSA_WANT_KEY_TYPE_AES)) -#define MBEDTLS_CIPHER_HAVE_GCM_AES_VIA_LEGACY_OR_USE_PSA -#endif - -#if defined(MBEDTLS_CCM_C) || \ - (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CCM)) -#define MBEDTLS_CIPHER_HAVE_CCM_VIA_LEGACY_OR_USE_PSA -#endif - -#if (defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)) || \ - (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CCM) && defined(PSA_WANT_KEY_TYPE_AES)) -#define MBEDTLS_CIPHER_HAVE_CCM_AES_VIA_LEGACY_OR_USE_PSA -#endif - -#if defined(MBEDTLS_CCM_C) || \ - (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CCM_STAR_NO_TAG)) -#define MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_VIA_LEGACY_OR_USE_PSA -#endif - -#if (defined(MBEDTLS_CCM_C) && defined(MBEDTLS_AES_C)) || \ - (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CCM_STAR_NO_TAG) && \ - defined(PSA_WANT_KEY_TYPE_AES)) -#define MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_AES_VIA_LEGACY_OR_USE_PSA -#endif - -#if defined(MBEDTLS_CHACHAPOLY_C) || \ - (defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_CHACHA20_POLY1305)) -#define MBEDTLS_CIPHER_HAVE_CHACHAPOLY_VIA_LEGACY_OR_USE_PSA -#endif - -#if defined(MBEDTLS_CIPHER_HAVE_GCM_VIA_LEGACY_OR_USE_PSA) || \ - defined(MBEDTLS_CIPHER_HAVE_CCM_VIA_LEGACY_OR_USE_PSA) || \ - defined(MBEDTLS_CIPHER_HAVE_CCM_STAR_NO_TAG_VIA_LEGACY_OR_USE_PSA) || \ - defined(MBEDTLS_CIPHER_HAVE_CHACHAPOLY_VIA_LEGACY_OR_USE_PSA) -#define MBEDTLS_CIPHER_HAVE_SOME_AEAD_VIA_LEGACY_OR_USE_PSA -#endif - /** * Base cipher information. The non-mode specific functions and values. */ -struct mbedtls_cipher_base_t { +struct mbedtls_cipher_base_t +{ /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */ mbedtls_cipher_id_t cipher; /** Encrypt using ECB */ - int (*ecb_func)(void *ctx, mbedtls_operation_t mode, - const unsigned char *input, unsigned char *output); + int (*ecb_func)( void *ctx, mbedtls_operation_t mode, + const unsigned char *input, unsigned char *output ); #if defined(MBEDTLS_CIPHER_MODE_CBC) /** Encrypt using CBC */ - int (*cbc_func)(void *ctx, mbedtls_operation_t mode, size_t length, - unsigned char *iv, const unsigned char *input, - unsigned char *output); + int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length, + unsigned char *iv, const unsigned char *input, + unsigned char *output ); #endif #if defined(MBEDTLS_CIPHER_MODE_CFB) /** Encrypt using CFB (Full length) */ - int (*cfb_func)(void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off, - unsigned char *iv, const unsigned char *input, - unsigned char *output); + int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off, + unsigned char *iv, const unsigned char *input, + unsigned char *output ); #endif #if defined(MBEDTLS_CIPHER_MODE_OFB) /** Encrypt using OFB (Full length) */ - int (*ofb_func)(void *ctx, size_t length, size_t *iv_off, - unsigned char *iv, - const unsigned char *input, - unsigned char *output); + int (*ofb_func)( void *ctx, size_t length, size_t *iv_off, + unsigned char *iv, + const unsigned char *input, + unsigned char *output ); #endif #if defined(MBEDTLS_CIPHER_MODE_CTR) /** Encrypt using CTR */ - int (*ctr_func)(void *ctx, size_t length, size_t *nc_off, - unsigned char *nonce_counter, unsigned char *stream_block, - const unsigned char *input, unsigned char *output); + int (*ctr_func)( void *ctx, size_t length, size_t *nc_off, + unsigned char *nonce_counter, unsigned char *stream_block, + const unsigned char *input, unsigned char *output ); #endif #if defined(MBEDTLS_CIPHER_MODE_XTS) /** Encrypt or decrypt using XTS. */ - int (*xts_func)(void *ctx, mbedtls_operation_t mode, size_t length, - const unsigned char data_unit[16], - const unsigned char *input, unsigned char *output); + int (*xts_func)( void *ctx, mbedtls_operation_t mode, size_t length, + const unsigned char data_unit[16], + const unsigned char *input, unsigned char *output ); #endif #if defined(MBEDTLS_CIPHER_MODE_STREAM) /** Encrypt using STREAM */ - int (*stream_func)(void *ctx, size_t length, - const unsigned char *input, unsigned char *output); + int (*stream_func)( void *ctx, size_t length, + const unsigned char *input, unsigned char *output ); #endif /** Set key for encryption purposes */ - int (*setkey_enc_func)(void *ctx, const unsigned char *key, - unsigned int key_bitlen); + int (*setkey_enc_func)( void *ctx, const unsigned char *key, + unsigned int key_bitlen ); -#if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT) /** Set key for decryption purposes */ - int (*setkey_dec_func)(void *ctx, const unsigned char *key, - unsigned int key_bitlen); -#endif + int (*setkey_dec_func)( void *ctx, const unsigned char *key, + unsigned int key_bitlen); /** Allocate a new context */ - void * (*ctx_alloc_func)(void); + void * (*ctx_alloc_func)( void ); /** Free the given context */ - void (*ctx_free_func)(void *ctx); + void (*ctx_free_func)( void *ctx ); }; -typedef struct { +typedef struct +{ mbedtls_cipher_type_t type; const mbedtls_cipher_info_t *info; } mbedtls_cipher_definition_t; #if defined(MBEDTLS_USE_PSA_CRYPTO) -typedef enum { +typedef enum +{ MBEDTLS_CIPHER_PSA_KEY_UNSET = 0, MBEDTLS_CIPHER_PSA_KEY_OWNED, /* Used for PSA-based cipher contexts which */ /* use raw key material internally imported */ @@ -158,9 +127,10 @@ typedef enum { /* destroyed when the context is freed. */ } mbedtls_cipher_psa_key_ownership; -typedef struct { +typedef struct +{ psa_algorithm_t alg; - mbedtls_svc_key_id_t slot; + psa_key_id_t slot; mbedtls_cipher_psa_key_ownership slot_state; } mbedtls_cipher_context_psa; #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -169,8 +139,6 @@ extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[]; extern int mbedtls_cipher_supported[]; -extern const mbedtls_cipher_base_t *mbedtls_cipher_base_lookup_table[]; - #ifdef __cplusplus } #endif diff --git a/src/duckdb/third_party/mbedtls/library/common.h b/src/duckdb/third_party/mbedtls/library/common.h index 1e2976b83..a630fcc45 100644 --- a/src/duckdb/third_party/mbedtls/library/common.h +++ b/src/duckdb/third_party/mbedtls/library/common.h @@ -5,27 +5,27 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_LIBRARY_COMMON_H #define MBEDTLS_LIBRARY_COMMON_H #include "mbedtls/build_info.h" -#include "alignment.h" -#include -#include #include -#include - -#if defined(__ARM_NEON) -#include -#define MBEDTLS_HAVE_NEON_INTRINSICS -#elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) -#include -#define MBEDTLS_HAVE_NEON_INTRINSICS -#endif /** Helper to define a function as static except when building invasive tests. * @@ -49,56 +49,18 @@ #endif #if defined(MBEDTLS_TEST_HOOKS) -extern void (*mbedtls_test_hook_test_fail)(const char *test, int line, const char *file); -#define MBEDTLS_TEST_HOOK_TEST_ASSERT(TEST) \ - do { \ - if ((!(TEST)) && ((*mbedtls_test_hook_test_fail) != NULL)) \ - { \ - (*mbedtls_test_hook_test_fail)( #TEST, __LINE__, __FILE__); \ - } \ - } while (0) +extern void (*mbedtls_test_hook_test_fail)( const char * test, int line, const char * file ); +#define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST ) \ + do { \ + if( ( ! ( TEST ) ) && ( ( *mbedtls_test_hook_test_fail ) != NULL ) ) \ + { \ + ( *mbedtls_test_hook_test_fail )( #TEST, __LINE__, __FILE__ ); \ + } \ + } while( 0 ) #else -#define MBEDTLS_TEST_HOOK_TEST_ASSERT(TEST) +#define MBEDTLS_TEST_HOOK_TEST_ASSERT( TEST ) #endif /* defined(MBEDTLS_TEST_HOOKS) */ -/** \def ARRAY_LENGTH - * Return the number of elements of a static or stack array. - * - * \param array A value of array (not pointer) type. - * - * \return The number of elements of the array. - */ -/* A correct implementation of ARRAY_LENGTH, but which silently gives - * a nonsensical result if called with a pointer rather than an array. */ -#define ARRAY_LENGTH_UNSAFE(array) \ - (sizeof(array) / sizeof(*(array))) - -#if defined(__GNUC__) -/* Test if arg and &(arg)[0] have the same type. This is true if arg is - * an array but not if it's a pointer. */ -#define IS_ARRAY_NOT_POINTER(arg) \ - (!__builtin_types_compatible_p(__typeof__(arg), \ - __typeof__(&(arg)[0]))) -/* A compile-time constant with the value 0. If `const_expr` is not a - * compile-time constant with a nonzero value, cause a compile-time error. */ -#define STATIC_ASSERT_EXPR(const_expr) \ - (0 && sizeof(struct { unsigned int STATIC_ASSERT : 1 - 2 * !(const_expr); })) - -/* Return the scalar value `value` (possibly promoted). This is a compile-time - * constant if `value` is. `condition` must be a compile-time constant. - * If `condition` is false, arrange to cause a compile-time error. */ -#define STATIC_ASSERT_THEN_RETURN(condition, value) \ - (STATIC_ASSERT_EXPR(condition) ? 0 : (value)) - -#define ARRAY_LENGTH(array) \ - (STATIC_ASSERT_THEN_RETURN(IS_ARRAY_NOT_POINTER(array), \ - ARRAY_LENGTH_UNSAFE(array))) - -#else -/* If we aren't sure the compiler supports our non-standard tricks, - * fall back to the unsafe implementation. */ -#define ARRAY_LENGTH(array) ARRAY_LENGTH_UNSAFE(array) -#endif /** Allow library to access its structs' private members. * * Although structs defined in header files are publicly available, @@ -106,332 +68,334 @@ extern void (*mbedtls_test_hook_test_fail)(const char *test, int line, const cha */ #define MBEDTLS_ALLOW_PRIVATE_ACCESS -/** - * \brief Securely zeroize a buffer then free it. - * - * Similar to making consecutive calls to - * \c mbedtls_platform_zeroize() and \c mbedtls_free(), but has - * code size savings, and potential for optimisation in the future. - * - * Guaranteed to be a no-op if \p buf is \c NULL and \p len is 0. +/** Byte Reading Macros * - * \param buf Buffer to be zeroized then freed. - * \param len Length of the buffer in bytes + * Given a multi-byte integer \p x, MBEDTLS_BYTE_n retrieves the n-th + * byte from x, where byte 0 is the least significant byte. */ -void mbedtls_zeroize_and_free(void *buf, size_t len); +#define MBEDTLS_BYTE_0( x ) ( (uint8_t) ( ( x ) & 0xff ) ) +#define MBEDTLS_BYTE_1( x ) ( (uint8_t) ( ( ( x ) >> 8 ) & 0xff ) ) +#define MBEDTLS_BYTE_2( x ) ( (uint8_t) ( ( ( x ) >> 16 ) & 0xff ) ) +#define MBEDTLS_BYTE_3( x ) ( (uint8_t) ( ( ( x ) >> 24 ) & 0xff ) ) +#define MBEDTLS_BYTE_4( x ) ( (uint8_t) ( ( ( x ) >> 32 ) & 0xff ) ) +#define MBEDTLS_BYTE_5( x ) ( (uint8_t) ( ( ( x ) >> 40 ) & 0xff ) ) +#define MBEDTLS_BYTE_6( x ) ( (uint8_t) ( ( ( x ) >> 48 ) & 0xff ) ) +#define MBEDTLS_BYTE_7( x ) ( (uint8_t) ( ( ( x ) >> 56 ) & 0xff ) ) -/** Return an offset into a buffer. +/** + * Get the unsigned 32 bits integer corresponding to four bytes in + * big-endian order (MSB first). * - * This is just the addition of an offset to a pointer, except that this - * function also accepts an offset of 0 into a buffer whose pointer is null. - * (`p + n` has undefined behavior when `p` is null, even when `n == 0`. - * A null pointer is a valid buffer pointer when the size is 0, for example - * as the result of `malloc(0)` on some platforms.) + * \param data Base address of the memory to get the four bytes from. + * \param offset Offset from \p data of the first and most significant + * byte of the four bytes to build the 32 bits unsigned + * integer from. + */ +#ifndef MBEDTLS_GET_UINT32_BE +#define MBEDTLS_GET_UINT32_BE( data , offset ) \ + ( \ + ( (uint32_t) ( data )[( offset ) ] << 24 ) \ + | ( (uint32_t) ( data )[( offset ) + 1] << 16 ) \ + | ( (uint32_t) ( data )[( offset ) + 2] << 8 ) \ + | ( (uint32_t) ( data )[( offset ) + 3] ) \ + ) +#endif + +/** + * Put in memory a 32 bits unsigned integer in big-endian order. * - * \param p Pointer to a buffer of at least n bytes. - * This may be \p NULL if \p n is zero. - * \param n An offset in bytes. - * \return Pointer to offset \p n in the buffer \p p. - * Note that this is only a valid pointer if the size of the - * buffer is at least \p n + 1. + * \param n 32 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 32 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the most significant + * byte of the 32 bits unsigned integer \p n. */ -inline unsigned char *mbedtls_buffer_offset( - unsigned char *p, size_t n) -{ - return p == NULL ? NULL : p + n; +#ifndef MBEDTLS_PUT_UINT32_BE +#define MBEDTLS_PUT_UINT32_BE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_3( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_2( n ); \ + ( data )[( offset ) + 2] = MBEDTLS_BYTE_1( n ); \ + ( data )[( offset ) + 3] = MBEDTLS_BYTE_0( n ); \ } +#endif -/** Return an offset into a read-only buffer. +/** + * Get the unsigned 32 bits integer corresponding to four bytes in + * little-endian order (LSB first). * - * Similar to mbedtls_buffer_offset(), but for const pointers. + * \param data Base address of the memory to get the four bytes from. + * \param offset Offset from \p data of the first and least significant + * byte of the four bytes to build the 32 bits unsigned + * integer from. + */ +#ifndef MBEDTLS_GET_UINT32_LE +#define MBEDTLS_GET_UINT32_LE( data, offset ) \ + ( \ + ( (uint32_t) ( data )[( offset ) ] ) \ + | ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \ + | ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \ + | ( (uint32_t) ( data )[( offset ) + 3] << 24 ) \ + ) +#endif + +/** + * Put in memory a 32 bits unsigned integer in little-endian order. * - * \param p Pointer to a buffer of at least n bytes. - * This may be \p NULL if \p n is zero. - * \param n An offset in bytes. - * \return Pointer to offset \p n in the buffer \p p. - * Note that this is only a valid pointer if the size of the - * buffer is at least \p n + 1. + * \param n 32 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 32 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the least significant + * byte of the 32 bits unsigned integer \p n. */ -inline const unsigned char *mbedtls_buffer_offset_const( - const unsigned char *p, size_t n) -{ - return p == NULL ? NULL : p + n; +#ifndef MBEDTLS_PUT_UINT32_LE +#define MBEDTLS_PUT_UINT32_LE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \ + ( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \ + ( data )[( offset ) + 3] = MBEDTLS_BYTE_3( n ); \ } - -/* Always inline mbedtls_xor() for similar reasons as mbedtls_xor_no_simd(). */ -#if defined(__IAR_SYSTEMS_ICC__) -#pragma inline = forced -#elif defined(__GNUC__) -__attribute__((always_inline)) #endif + /** - * Perform a fast block XOR operation, such that - * r[i] = a[i] ^ b[i] where 0 <= i < n + * Get the unsigned 16 bits integer corresponding to two bytes in + * little-endian order (LSB first). * - * \param r Pointer to result (buffer of at least \p n bytes). \p r - * may be equal to either \p a or \p b, but behaviour when - * it overlaps in other ways is undefined. - * \param a Pointer to input (buffer of at least \p n bytes) - * \param b Pointer to input (buffer of at least \p n bytes) - * \param n Number of bytes to process. - * - * \note Depending on the situation, it may be faster to use either mbedtls_xor() or - * mbedtls_xor_no_simd() (these are functionally equivalent). - * If the result is used immediately after the xor operation in non-SIMD code (e.g, in - * AES-CBC), there may be additional latency to transfer the data from SIMD to scalar - * registers, and in this case, mbedtls_xor_no_simd() may be faster. In other cases where - * the result is not used immediately (e.g., in AES-CTR), mbedtls_xor() may be faster. - * For targets without SIMD support, they will behave the same. + * \param data Base address of the memory to get the two bytes from. + * \param offset Offset from \p data of the first and least significant + * byte of the two bytes to build the 16 bits unsigned + * integer from. */ -inline void mbedtls_xor(unsigned char *r, - const unsigned char *a, - const unsigned char *b, - size_t n) -{ - size_t i = 0; -#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) -#if defined(MBEDTLS_HAVE_NEON_INTRINSICS) && \ - (!(defined(MBEDTLS_COMPILER_IS_GCC) && MBEDTLS_GCC_VERSION < 70300)) - /* Old GCC versions generate a warning here, so disable the NEON path for these compilers */ - for (; (i + 16) <= n; i += 16) { - uint8x16_t v1 = vld1q_u8(a + i); - uint8x16_t v2 = vld1q_u8(b + i); - uint8x16_t x = veorq_u8(v1, v2); - vst1q_u8(r + i, x); - } -#if defined(__IAR_SYSTEMS_ICC__) - /* This if statement helps some compilers (e.g., IAR) optimise out the byte-by-byte tail case - * where n is a constant multiple of 16. - * For other compilers (e.g. recent gcc and clang) it makes no difference if n is a compile-time - * constant, and is a very small perf regression if n is not a compile-time constant. */ - if (n % 16 == 0) { - return; - } -#endif -#elif defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64) - /* This codepath probably only makes sense on architectures with 64-bit registers */ - for (; (i + 8) <= n; i += 8) { - uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i); - mbedtls_put_unaligned_uint64(r + i, x); - } -#if defined(__IAR_SYSTEMS_ICC__) - if (n % 8 == 0) { - return; - } +#ifndef MBEDTLS_GET_UINT16_LE +#define MBEDTLS_GET_UINT16_LE( data, offset ) \ + ( \ + ( (uint16_t) ( data )[( offset ) ] ) \ + | ( (uint16_t) ( data )[( offset ) + 1] << 8 ) \ + ) #endif -#else - for (; (i + 4) <= n; i += 4) { - uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i); - mbedtls_put_unaligned_uint32(r + i, x); - } -#if defined(__IAR_SYSTEMS_ICC__) - if (n % 4 == 0) { - return; - } -#endif -#endif -#endif - for (; i < n; i++) { - r[i] = a[i] ^ b[i]; - } -} -/* Always inline mbedtls_xor_no_simd() as we see significant perf regressions when it does not get - * inlined (e.g., observed about 3x perf difference in gcm_mult_largetable with gcc 7 - 12) */ -#if defined(__IAR_SYSTEMS_ICC__) -#pragma inline = forced -#elif defined(__GNUC__) -__attribute__((always_inline)) -#endif /** - * Perform a fast block XOR operation, such that - * r[i] = a[i] ^ b[i] where 0 <= i < n - * - * In some situations, this can perform better than mbedtls_xor() (e.g., it's about 5% - * better in AES-CBC). + * Put in memory a 16 bits unsigned integer in little-endian order. * - * \param r Pointer to result (buffer of at least \p n bytes). \p r - * may be equal to either \p a or \p b, but behaviour when - * it overlaps in other ways is undefined. - * \param a Pointer to input (buffer of at least \p n bytes) - * \param b Pointer to input (buffer of at least \p n bytes) - * \param n Number of bytes to process. - * - * \note Depending on the situation, it may be faster to use either mbedtls_xor() or - * mbedtls_xor_no_simd() (these are functionally equivalent). - * If the result is used immediately after the xor operation in non-SIMD code (e.g, in - * AES-CBC), there may be additional latency to transfer the data from SIMD to scalar - * registers, and in this case, mbedtls_xor_no_simd() may be faster. In other cases where - * the result is not used immediately (e.g., in AES-CTR), mbedtls_xor() may be faster. - * For targets without SIMD support, they will behave the same. + * \param n 16 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 16 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the least significant + * byte of the 16 bits unsigned integer \p n. */ -inline void mbedtls_xor_no_simd(unsigned char *r, - const unsigned char *a, - const unsigned char *b, - size_t n) -{ - size_t i = 0; -#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) -#if defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64) - /* This codepath probably only makes sense on architectures with 64-bit registers */ - for (; (i + 8) <= n; i += 8) { - uint64_t x = mbedtls_get_unaligned_uint64(a + i) ^ mbedtls_get_unaligned_uint64(b + i); - mbedtls_put_unaligned_uint64(r + i, x); - } -#if defined(__IAR_SYSTEMS_ICC__) - /* This if statement helps some compilers (e.g., IAR) optimise out the byte-by-byte tail case - * where n is a constant multiple of 8. - * For other compilers (e.g. recent gcc and clang) it makes no difference if n is a compile-time - * constant, and is a very small perf regression if n is not a compile-time constant. */ - if (n % 8 == 0) { - return; - } -#endif -#else - for (; (i + 4) <= n; i += 4) { - uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i); - mbedtls_put_unaligned_uint32(r + i, x); - } -#if defined(__IAR_SYSTEMS_ICC__) - if (n % 4 == 0) { - return; - } -#endif -#endif -#endif - for (; i < n; i++) { - r[i] = a[i] ^ b[i]; - } +#ifndef MBEDTLS_PUT_UINT16_LE +#define MBEDTLS_PUT_UINT16_LE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \ } +#endif -/* Fix MSVC C99 compatible issue - * MSVC support __func__ from visual studio 2015( 1900 ) - * Use MSVC predefine macro to avoid name check fail. +/** + * Get the unsigned 16 bits integer corresponding to two bytes in + * big-endian order (MSB first). + * + * \param data Base address of the memory to get the two bytes from. + * \param offset Offset from \p data of the first and most significant + * byte of the two bytes to build the 16 bits unsigned + * integer from. */ -#if (defined(_MSC_VER) && (_MSC_VER <= 1900)) -#define /*no-check-names*/ __func__ __FUNCTION__ +#ifndef MBEDTLS_GET_UINT16_BE +#define MBEDTLS_GET_UINT16_BE( data, offset ) \ + ( \ + ( (uint16_t) ( data )[( offset ) ] << 8 ) \ + | ( (uint16_t) ( data )[( offset ) + 1] ) \ + ) #endif -/* Define `asm` for compilers which don't define it. */ -/* *INDENT-OFF* */ -#ifndef asm -#if defined(__IAR_SYSTEMS_ICC__) -#define asm __asm -#else -#define asm __asm__ -#endif +/** + * Put in memory a 16 bits unsigned integer in big-endian order. + * + * \param n 16 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 16 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the most significant + * byte of the 16 bits unsigned integer \p n. + */ +#ifndef MBEDTLS_PUT_UINT16_BE +#define MBEDTLS_PUT_UINT16_BE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_1( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_0( n ); \ +} #endif -/* *INDENT-ON* */ -/* - * Define the constraint used for read-only pointer operands to aarch64 asm. - * - * This is normally the usual "r", but for aarch64_32 (aka ILP32, - * as found in watchos), "p" is required to avoid warnings from clang. - * - * Note that clang does not recognise '+p' or '=p', and armclang - * does not recognise 'p' at all. Therefore, to update a pointer from - * aarch64 assembly, it is necessary to use something like: - * - * uintptr_t uptr = (uintptr_t) ptr; - * asm( "ldr x4, [%x0], #8" ... : "+r" (uptr) : : ) - * ptr = (void*) uptr; +/** + * Get the unsigned 24 bits integer corresponding to three bytes in + * big-endian order (MSB first). * - * Note that the "x" in "%x0" is neccessary; writing "%0" will cause warnings. + * \param data Base address of the memory to get the three bytes from. + * \param offset Offset from \p data of the first and most significant + * byte of the three bytes to build the 24 bits unsigned + * integer from. */ -#if defined(__aarch64__) && defined(MBEDTLS_HAVE_ASM) -#if UINTPTR_MAX == 0xfffffffful -/* ILP32: Specify the pointer operand slightly differently, as per #7787. */ -#define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "p" -#elif UINTPTR_MAX == 0xfffffffffffffffful -/* Normal case (64-bit pointers): use "r" as the constraint for pointer operands to asm */ -#define MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT "r" -#else -#error "Unrecognised pointer size for aarch64" -#endif +#ifndef MBEDTLS_GET_UINT24_BE +#define MBEDTLS_GET_UINT24_BE( data , offset ) \ + ( \ + ( (uint32_t) ( data )[( offset ) ] << 16 ) \ + | ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \ + | ( (uint32_t) ( data )[( offset ) + 2] ) \ + ) #endif -/* Always provide a static assert macro, so it can be used unconditionally. - * It does nothing on systems where we don't know how to define a static assert. - */ -/* Can't use the C11-style `defined(static_assert)` on FreeBSD, since it - * defines static_assert even with -std=c99, but then complains about it. +/** + * Put in memory a 24 bits unsigned integer in big-endian order. + * + * \param n 24 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 24 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the most significant + * byte of the 24 bits unsigned integer \p n. */ -#if defined(static_assert) && !defined(__FreeBSD__) -#define MBEDTLS_STATIC_ASSERT(expr, msg) static_assert(expr, msg) -#else -/* Make sure `MBEDTLS_STATIC_ASSERT(expr, msg);` is valid both inside and - * outside a function. We choose a struct declaration, which can be repeated - * any number of times and does not need a matching definition. */ -#define MBEDTLS_STATIC_ASSERT(expr, msg) \ - struct ISO_C_does_not_allow_extra_semicolon_outside_of_a_function +#ifndef MBEDTLS_PUT_UINT24_BE +#define MBEDTLS_PUT_UINT24_BE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_2( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \ + ( data )[( offset ) + 2] = MBEDTLS_BYTE_0( n ); \ +} #endif -#if defined(__has_builtin) -#define MBEDTLS_HAS_BUILTIN(x) __has_builtin(x) -#else -#define MBEDTLS_HAS_BUILTIN(x) 0 +/** + * Get the unsigned 24 bits integer corresponding to three bytes in + * little-endian order (LSB first). + * + * \param data Base address of the memory to get the three bytes from. + * \param offset Offset from \p data of the first and least significant + * byte of the three bytes to build the 24 bits unsigned + * integer from. + */ +#ifndef MBEDTLS_GET_UINT24_LE +#define MBEDTLS_GET_UINT24_LE( data, offset ) \ + ( \ + ( (uint32_t) ( data )[( offset ) ] ) \ + | ( (uint32_t) ( data )[( offset ) + 1] << 8 ) \ + | ( (uint32_t) ( data )[( offset ) + 2] << 16 ) \ + ) #endif -/* Define compiler branch hints */ -#if MBEDTLS_HAS_BUILTIN(__builtin_expect) -#define MBEDTLS_LIKELY(x) __builtin_expect(!!(x), 1) -#define MBEDTLS_UNLIKELY(x) __builtin_expect(!!(x), 0) -#else -#define MBEDTLS_LIKELY(x) x -#define MBEDTLS_UNLIKELY(x) x +/** + * Put in memory a 24 bits unsigned integer in little-endian order. + * + * \param n 24 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 24 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the least significant + * byte of the 24 bits unsigned integer \p n. + */ +#ifndef MBEDTLS_PUT_UINT24_LE +#define MBEDTLS_PUT_UINT24_LE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \ + ( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \ +} #endif -/* MBEDTLS_ASSUME may be used to provide additional information to the compiler - * which can result in smaller code-size. */ -#if MBEDTLS_HAS_BUILTIN(__builtin_assume) -/* clang provides __builtin_assume */ -#define MBEDTLS_ASSUME(x) __builtin_assume(x) -#elif MBEDTLS_HAS_BUILTIN(__builtin_unreachable) -/* gcc and IAR can use __builtin_unreachable */ -#define MBEDTLS_ASSUME(x) do { if (!(x)) __builtin_unreachable(); } while (0) -#elif defined(_MSC_VER) -/* Supported by MSVC since VS 2005 */ -#define MBEDTLS_ASSUME(x) __assume(x) -#else -#define MBEDTLS_ASSUME(x) do { } while (0) +/** + * Get the unsigned 64 bits integer corresponding to eight bytes in + * big-endian order (MSB first). + * + * \param data Base address of the memory to get the eight bytes from. + * \param offset Offset from \p data of the first and most significant + * byte of the eight bytes to build the 64 bits unsigned + * integer from. + */ +#ifndef MBEDTLS_GET_UINT64_BE +#define MBEDTLS_GET_UINT64_BE( data, offset ) \ + ( \ + ( (uint64_t) ( data )[( offset ) ] << 56 ) \ + | ( (uint64_t) ( data )[( offset ) + 1] << 48 ) \ + | ( (uint64_t) ( data )[( offset ) + 2] << 40 ) \ + | ( (uint64_t) ( data )[( offset ) + 3] << 32 ) \ + | ( (uint64_t) ( data )[( offset ) + 4] << 24 ) \ + | ( (uint64_t) ( data )[( offset ) + 5] << 16 ) \ + | ( (uint64_t) ( data )[( offset ) + 6] << 8 ) \ + | ( (uint64_t) ( data )[( offset ) + 7] ) \ + ) #endif -/* For gcc -Os, override with -O2 for a given function. +/** + * Put in memory a 64 bits unsigned integer in big-endian order. * - * This will not affect behaviour for other optimisation settings, e.g. -O0. + * \param n 64 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 64 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the most significant + * byte of the 64 bits unsigned integer \p n. */ -#if defined(MBEDTLS_COMPILER_IS_GCC) && defined(__OPTIMIZE_SIZE__) -#define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE __attribute__((optimize("-O2"))) -#else -#define MBEDTLS_OPTIMIZE_FOR_PERFORMANCE +#ifndef MBEDTLS_PUT_UINT64_BE +#define MBEDTLS_PUT_UINT64_BE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_7( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_6( n ); \ + ( data )[( offset ) + 2] = MBEDTLS_BYTE_5( n ); \ + ( data )[( offset ) + 3] = MBEDTLS_BYTE_4( n ); \ + ( data )[( offset ) + 4] = MBEDTLS_BYTE_3( n ); \ + ( data )[( offset ) + 5] = MBEDTLS_BYTE_2( n ); \ + ( data )[( offset ) + 6] = MBEDTLS_BYTE_1( n ); \ + ( data )[( offset ) + 7] = MBEDTLS_BYTE_0( n ); \ +} #endif -/* Suppress compiler warnings for unused functions and variables. */ -#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__has_attribute) -# if __has_attribute(unused) -# define MBEDTLS_MAYBE_UNUSED __attribute__((unused)) -# endif -#endif -#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__GNUC__) -# define MBEDTLS_MAYBE_UNUSED __attribute__((unused)) -#endif -#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(__IAR_SYSTEMS_ICC__) && defined(__VER__) -/* IAR does support __attribute__((unused)), but only if the -e flag (extended language support) - * is given; the pragma always works. - * Unfortunately the pragma affects the rest of the file where it is used, but this is harmless. - * Check for version 5.2 or later - this pragma may be supported by earlier versions, but I wasn't - * able to find documentation). +/** + * Get the unsigned 64 bits integer corresponding to eight bytes in + * little-endian order (LSB first). + * + * \param data Base address of the memory to get the eight bytes from. + * \param offset Offset from \p data of the first and least significant + * byte of the eight bytes to build the 64 bits unsigned + * integer from. */ -# if (__VER__ >= 5020000) -# define MBEDTLS_MAYBE_UNUSED _Pragma("diag_suppress=Pe177") -# endif +#ifndef MBEDTLS_GET_UINT64_LE +#define MBEDTLS_GET_UINT64_LE( data, offset ) \ + ( \ + ( (uint64_t) ( data )[( offset ) + 7] << 56 ) \ + | ( (uint64_t) ( data )[( offset ) + 6] << 48 ) \ + | ( (uint64_t) ( data )[( offset ) + 5] << 40 ) \ + | ( (uint64_t) ( data )[( offset ) + 4] << 32 ) \ + | ( (uint64_t) ( data )[( offset ) + 3] << 24 ) \ + | ( (uint64_t) ( data )[( offset ) + 2] << 16 ) \ + | ( (uint64_t) ( data )[( offset ) + 1] << 8 ) \ + | ( (uint64_t) ( data )[( offset ) ] ) \ + ) #endif -#if !defined(MBEDTLS_MAYBE_UNUSED) && defined(_MSC_VER) -# define MBEDTLS_MAYBE_UNUSED __pragma(warning(suppress:4189)) + +/** + * Put in memory a 64 bits unsigned integer in little-endian order. + * + * \param n 64 bits unsigned integer to put in memory. + * \param data Base address of the memory where to put the 64 + * bits unsigned integer in. + * \param offset Offset from \p data where to put the least significant + * byte of the 64 bits unsigned integer \p n. + */ +#ifndef MBEDTLS_PUT_UINT64_LE +#define MBEDTLS_PUT_UINT64_LE( n, data, offset ) \ +{ \ + ( data )[( offset ) ] = MBEDTLS_BYTE_0( n ); \ + ( data )[( offset ) + 1] = MBEDTLS_BYTE_1( n ); \ + ( data )[( offset ) + 2] = MBEDTLS_BYTE_2( n ); \ + ( data )[( offset ) + 3] = MBEDTLS_BYTE_3( n ); \ + ( data )[( offset ) + 4] = MBEDTLS_BYTE_4( n ); \ + ( data )[( offset ) + 5] = MBEDTLS_BYTE_5( n ); \ + ( data )[( offset ) + 6] = MBEDTLS_BYTE_6( n ); \ + ( data )[( offset ) + 7] = MBEDTLS_BYTE_7( n ); \ +} #endif -#if !defined(MBEDTLS_MAYBE_UNUSED) -# define MBEDTLS_MAYBE_UNUSED + +/* Fix MSVC C99 compatible issue + * MSVC support __func__ from visual studio 2015( 1900 ) + * Use MSVC predefine macro to avoid name check fail. + */ +#if (defined(_MSC_VER) && ( _MSC_VER <= 1900 )) +#define /*no-check-names*/ __func__ __FUNCTION__ #endif #endif /* MBEDTLS_LIBRARY_COMMON_H */ diff --git a/src/duckdb/third_party/mbedtls/library/constant_time.cpp b/src/duckdb/third_party/mbedtls/library/constant_time.cpp index e648a78a2..d2a2239e5 100644 --- a/src/duckdb/third_party/mbedtls/library/constant_time.cpp +++ b/src/duckdb/third_party/mbedtls/library/constant_time.cpp @@ -2,247 +2,800 @@ * Constant-time functions * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -/* + /* * The following functions are implemented without using comparison operators, as those * might be translated to branches by some compilers on some platforms. */ -#include -#include - #include "common.h" #include "constant_time_internal.h" #include "mbedtls/constant_time.h" #include "mbedtls/error.h" #include "mbedtls/platform_util.h" -#include +#if defined(MBEDTLS_BIGNUM_C) +#include "mbedtls/bignum.h" +#endif -#if !defined(MBEDTLS_CT_ASM) -/* - * Define an object with the value zero, such that the compiler cannot prove that it - * has the value zero (because it is volatile, it "may be modified in ways unknown to - * the implementation"). - */ -volatile mbedtls_ct_uint_t mbedtls_ct_zero = 0; +#if defined(MBEDTLS_SSL_TLS_C) +#include "ssl_misc.h" #endif -/* - * Define MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS where assembly is present to - * perform fast unaligned access to volatile data. - * - * This is needed because mbedtls_get_unaligned_uintXX etc don't support volatile - * memory accesses. - * - * Some of these definitions could be moved into alignment.h but for now they are - * only used here. - */ -#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) && \ - ((defined(MBEDTLS_CT_ARM_ASM) && (UINTPTR_MAX == 0xfffffffful)) || \ - defined(MBEDTLS_CT_AARCH64_ASM)) -/* We check pointer sizes to avoid issues with them not matching register size requirements */ -#define MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS +#if defined(MBEDTLS_RSA_C) +#include "mbedtls/rsa.h" +#endif -inline uint32_t mbedtls_get_unaligned_volatile_uint32(volatile const unsigned char *p) -{ - /* This is UB, even where it's safe: - * return *((volatile uint32_t*)p); - * so instead the same thing is expressed in assembly below. - */ - uint32_t r; -#if defined(MBEDTLS_CT_ARM_ASM) - asm volatile ("ldr %0, [%1]" : "=r" (r) : "r" (p) :); -#elif defined(MBEDTLS_CT_AARCH64_ASM) - asm volatile ("ldr %w0, [%1]" : "=r" (r) : MBEDTLS_ASM_AARCH64_PTR_CONSTRAINT(p) :); -#else -#error "No assembly defined for mbedtls_get_unaligned_volatile_uint32" +#if defined(MBEDTLS_BASE64_C) +#include "constant_time_invasive.h" #endif - return r; -} -#endif /* defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) && - (defined(MBEDTLS_CT_ARM_ASM) || defined(MBEDTLS_CT_AARCH64_ASM)) */ -int mbedtls_ct_memcmp(const void *a, - const void *b, - size_t n) +#include + +int mbedtls_ct_memcmp( const void *a, + const void *b, + size_t n ) { - size_t i = 0; - /* - * `A` and `B` are cast to volatile to ensure that the compiler - * generates code that always fully reads both buffers. - * Otherwise it could generate a test to exit early if `diff` has all - * bits set early in the loop. - */ + size_t i; volatile const unsigned char *A = (volatile const unsigned char *) a; volatile const unsigned char *B = (volatile const unsigned char *) b; - uint32_t diff = 0; - -#if defined(MBEDTLS_EFFICIENT_UNALIGNED_VOLATILE_ACCESS) - for (; (i + 4) <= n; i += 4) { - uint32_t x = mbedtls_get_unaligned_volatile_uint32(A + i); - uint32_t y = mbedtls_get_unaligned_volatile_uint32(B + i); - diff |= x ^ y; - } -#endif + volatile unsigned char diff = 0; - for (; i < n; i++) { + for( i = 0; i < n; i++ ) + { /* Read volatile data in order before computing diff. * This avoids IAR compiler warning: * 'the order of volatile accesses is undefined ..' */ unsigned char x = A[i], y = B[i]; - diff |= x ^ y; + diff = (diff | (x ^ y)); } + return( (int)diff ); +} -#if (INT_MAX < INT32_MAX) - /* We don't support int smaller than 32-bits, but if someone tried to build - * with this configuration, there is a risk that, for differing data, the - * only bits set in diff are in the top 16-bits, and would be lost by a - * simple cast from uint32 to int. - * This would have significant security implications, so protect against it. */ -#error "mbedtls_ct_memcmp() requires minimum 32-bit ints" -#else - /* The bit-twiddling ensures that when we cast uint32_t to int, we are casting - * a value that is in the range 0..INT_MAX - a value larger than this would - * result in implementation defined behaviour. - * - * This ensures that the value returned by the function is non-zero iff - * diff is non-zero. - */ - return (int) ((diff & 0xffff) | (diff >> 16)); +unsigned mbedtls_ct_uint_mask( unsigned value ) +{ + /* MSVC has a warning about unary minus on unsigned, but this is + * well-defined and precisely what we want to do here */ +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4146 ) +#endif + return( - ( ( value | - value ) >> ( sizeof( value ) * 8 - 1 ) ) ); +#if defined(_MSC_VER) +#pragma warning( pop ) #endif } -#if defined(MBEDTLS_NIST_KW_C) +#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) -int mbedtls_ct_memcmp_partial(const void *a, - const void *b, - size_t n, - size_t skip_head, - size_t skip_tail) +size_t mbedtls_ct_size_mask( size_t value ) { - unsigned int diff = 0; + /* MSVC has a warning about unary minus on unsigned integer types, + * but this is well-defined and precisely what we want to do here. */ +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4146 ) +#endif + return( - ( ( value | - value ) >> ( sizeof( value ) * 8 - 1 ) ) ); +#if defined(_MSC_VER) +#pragma warning( pop ) +#endif +} - volatile const unsigned char *A = (volatile const unsigned char *) a; - volatile const unsigned char *B = (volatile const unsigned char *) b; +#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ - size_t valid_end = n - skip_tail; +#if defined(MBEDTLS_BIGNUM_C) - for (size_t i = 0; i < n; i++) { - unsigned char x = A[i], y = B[i]; - unsigned int d = x ^ y; - mbedtls_ct_condition_t valid = mbedtls_ct_bool_and(mbedtls_ct_uint_ge(i, skip_head), - mbedtls_ct_uint_lt(i, valid_end)); - diff |= mbedtls_ct_uint_if_else_0(valid, d); - } +mbedtls_mpi_uint mbedtls_ct_mpi_uint_mask( mbedtls_mpi_uint value ) +{ + /* MSVC has a warning about unary minus on unsigned, but this is + * well-defined and precisely what we want to do here */ +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4146 ) +#endif + return( - ( ( value | - value ) >> ( sizeof( value ) * 8 - 1 ) ) ); +#if defined(_MSC_VER) +#pragma warning( pop ) +#endif +} + +#endif /* MBEDTLS_BIGNUM_C */ + +#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) + +/** Constant-flow mask generation for "less than" comparison: + * - if \p x < \p y, return all-bits 1, that is (size_t) -1 + * - otherwise, return all bits 0, that is 0 + * + * This function can be used to write constant-time code by replacing branches + * with bit operations using masks. + * + * \param x The first value to analyze. + * \param y The second value to analyze. + * + * \return All-bits-one if \p x is less than \p y, otherwise zero. + */ +static size_t mbedtls_ct_size_mask_lt( size_t x, + size_t y ) +{ + /* This has the most significant bit set if and only if x < y */ + const size_t sub = x - y; + + /* sub1 = (x < y) ? 1 : 0 */ + const size_t sub1 = sub >> ( sizeof( sub ) * 8 - 1 ); + + /* mask = (x < y) ? 0xff... : 0x00... */ + const size_t mask = mbedtls_ct_size_mask( sub1 ); - /* Since we go byte-by-byte, the only bits set will be in the bottom 8 bits, so the - * cast from uint to int is safe. */ - return (int) diff; + return( mask ); } +size_t mbedtls_ct_size_mask_ge( size_t x, + size_t y ) +{ + return( ~mbedtls_ct_size_mask_lt( x, y ) ); +} + +#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ + +#if defined(MBEDTLS_BASE64_C) + +/* Return 0xff if low <= c <= high, 0 otherwise. + * + * Constant flow with respect to c. + */ +MBEDTLS_STATIC_TESTABLE +unsigned char mbedtls_ct_uchar_mask_of_range( unsigned char low, + unsigned char high, + unsigned char c ) +{ + /* low_mask is: 0 if low <= c, 0x...ff if low > c */ + unsigned low_mask = ( (unsigned) c - low ) >> 8; + /* high_mask is: 0 if c <= high, 0x...ff if c > high */ + unsigned high_mask = ( (unsigned) high - c ) >> 8; + return( ~( low_mask | high_mask ) & 0xff ); +} + +#endif /* MBEDTLS_BASE64_C */ + +unsigned mbedtls_ct_size_bool_eq( size_t x, + size_t y ) +{ + /* diff = 0 if x == y, non-zero otherwise */ + const size_t diff = x ^ y; + + /* MSVC has a warning about unary minus on unsigned integer types, + * but this is well-defined and precisely what we want to do here. */ +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4146 ) +#endif + + /* diff_msb's most significant bit is equal to x != y */ + const size_t diff_msb = ( diff | (size_t) -diff ); + +#if defined(_MSC_VER) +#pragma warning( pop ) +#endif + + /* diff1 = (x != y) ? 1 : 0 */ + const unsigned diff1 = diff_msb >> ( sizeof( diff_msb ) * 8 - 1 ); + + return( 1 ^ diff1 ); +} + +#if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) + +/** Constant-flow "greater than" comparison: + * return x > y + * + * This is equivalent to \p x > \p y, but is likely to be compiled + * to code using bitwise operation rather than a branch. + * + * \param x The first value to analyze. + * \param y The second value to analyze. + * + * \return 1 if \p x greater than \p y, otherwise 0. + */ +static unsigned mbedtls_ct_size_gt( size_t x, + size_t y ) +{ + /* Return the sign bit (1 for negative) of (y - x). */ + return( ( y - x ) >> ( sizeof( size_t ) * 8 - 1 ) ); +} + +#endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */ + +#if defined(MBEDTLS_BIGNUM_C) + +unsigned mbedtls_ct_mpi_uint_lt( const mbedtls_mpi_uint x, + const mbedtls_mpi_uint y ) +{ + mbedtls_mpi_uint ret; + mbedtls_mpi_uint cond; + + /* + * Check if the most significant bits (MSB) of the operands are different. + */ + cond = ( x ^ y ); + /* + * If the MSB are the same then the difference x-y will be negative (and + * have its MSB set to 1 during conversion to unsigned) if and only if x> ( sizeof( mbedtls_mpi_uint ) * 8 - 1 ); + + return (unsigned) ret; +} + +#endif /* MBEDTLS_BIGNUM_C */ + +unsigned mbedtls_ct_uint_if( unsigned condition, + unsigned if1, + unsigned if0 ) +{ + unsigned mask = mbedtls_ct_uint_mask( condition ); + return( ( mask & if1 ) | (~mask & if0 ) ); +} + +#if defined(MBEDTLS_BIGNUM_C) + +/** Select between two sign values without branches. + * + * This is functionally equivalent to `condition ? if1 : if0` but uses only bit + * operations in order to avoid branches. + * + * \note if1 and if0 must be either 1 or -1, otherwise the result + * is undefined. + * + * \param condition Condition to test. + * \param if1 The first sign; must be either +1 or -1. + * \param if0 The second sign; must be either +1 or -1. + * + * \return \c if1 if \p condition is nonzero, otherwise \c if0. + * */ +static int mbedtls_ct_cond_select_sign( unsigned char condition, + int if1, + int if0 ) +{ + /* In order to avoid questions about what we can reasonably assume about + * the representations of signed integers, move everything to unsigned + * by taking advantage of the fact that if1 and if0 are either +1 or -1. */ + unsigned uif1 = if1 + 1; + unsigned uif0 = if0 + 1; + + /* condition was 0 or 1, mask is 0 or 2 as are uif1 and uif0 */ + const unsigned mask = condition << 1; + + /* select uif1 or uif0 */ + unsigned ur = ( uif0 & ~mask ) | ( uif1 & mask ); + + /* ur is now 0 or 2, convert back to -1 or +1 */ + return( (int) ur - 1 ); +} + +void mbedtls_ct_mpi_uint_cond_assign( size_t n, + mbedtls_mpi_uint *dest, + const mbedtls_mpi_uint *src, + unsigned char condition ) +{ + size_t i; + + /* MSVC has a warning about unary minus on unsigned integer types, + * but this is well-defined and precisely what we want to do here. */ +#if defined(_MSC_VER) +#pragma warning( push ) +#pragma warning( disable : 4146 ) #endif + /* all-bits 1 if condition is 1, all-bits 0 if condition is 0 */ + const mbedtls_mpi_uint mask = -condition; + +#if defined(_MSC_VER) +#pragma warning( pop ) +#endif + + for( i = 0; i < n; i++ ) + dest[i] = ( src[i] & mask ) | ( dest[i] & ~mask ); +} + +#endif /* MBEDTLS_BIGNUM_C */ + +#if defined(MBEDTLS_BASE64_C) + +unsigned char mbedtls_ct_base64_enc_char( unsigned char value ) +{ + unsigned char digit = 0; + /* For each range of values, if value is in that range, mask digit with + * the corresponding value. Since value can only be in a single range, + * only at most one masking will change digit. */ + digit |= mbedtls_ct_uchar_mask_of_range( 0, 25, value ) & ( 'A' + value ); + digit |= mbedtls_ct_uchar_mask_of_range( 26, 51, value ) & ( 'a' + value - 26 ); + digit |= mbedtls_ct_uchar_mask_of_range( 52, 61, value ) & ( '0' + value - 52 ); + digit |= mbedtls_ct_uchar_mask_of_range( 62, 62, value ) & '+'; + digit |= mbedtls_ct_uchar_mask_of_range( 63, 63, value ) & '/'; + return( digit ); +} + +signed char mbedtls_ct_base64_dec_value( unsigned char c ) +{ + unsigned char val = 0; + /* For each range of digits, if c is in that range, mask val with + * the corresponding value. Since c can only be in a single range, + * only at most one masking will change val. Set val to one plus + * the desired value so that it stays 0 if c is in none of the ranges. */ + val |= mbedtls_ct_uchar_mask_of_range( 'A', 'Z', c ) & ( c - 'A' + 0 + 1 ); + val |= mbedtls_ct_uchar_mask_of_range( 'a', 'z', c ) & ( c - 'a' + 26 + 1 ); + val |= mbedtls_ct_uchar_mask_of_range( '0', '9', c ) & ( c - '0' + 52 + 1 ); + val |= mbedtls_ct_uchar_mask_of_range( '+', '+', c ) & ( c - '+' + 62 + 1 ); + val |= mbedtls_ct_uchar_mask_of_range( '/', '/', c ) & ( c - '/' + 63 + 1 ); + /* At this point, val is 0 if c is an invalid digit and v+1 if c is + * a digit with the value v. */ + return( val - 1 ); +} + +#endif /* MBEDTLS_BASE64_C */ + #if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) -void mbedtls_ct_memmove_left(void *start, size_t total, size_t offset) +/** Shift some data towards the left inside a buffer. + * + * `mbedtls_ct_mem_move_to_left(start, total, offset)` is functionally + * equivalent to + * ``` + * memmove(start, start + offset, total - offset); + * memset(start + offset, 0, total - offset); + * ``` + * but it strives to use a memory access pattern (and thus total timing) + * that does not depend on \p offset. This timing independence comes at + * the expense of performance. + * + * \param start Pointer to the start of the buffer. + * \param total Total size of the buffer. + * \param offset Offset from which to copy \p total - \p offset bytes. + */ +static void mbedtls_ct_mem_move_to_left( void *start, + size_t total, + size_t offset ) { - volatile unsigned char *buf = (unsigned char *) start; - for (size_t i = 0; i < total; i++) { - mbedtls_ct_condition_t no_op = mbedtls_ct_uint_gt(total - offset, i); + volatile unsigned char *buf = (volatile unsigned char *) start; + size_t i, n; + if( total == 0 ) + return; + for( i = 0; i < total; i++ ) + { + unsigned no_op = mbedtls_ct_size_gt( total - offset, i ); /* The first `total - offset` passes are a no-op. The last * `offset` passes shift the data one byte to the left and * zero out the last byte. */ - for (size_t n = 0; n < total - 1; n++) { + for( n = 0; n < total - 1; n++ ) + { unsigned char current = buf[n]; - unsigned char next = buf[n+1]; - buf[n] = mbedtls_ct_uint_if(no_op, current, next); + unsigned char next = buf[n+1]; + buf[n] = mbedtls_ct_uint_if( no_op, current, next ); } - buf[total-1] = mbedtls_ct_uint_if_else_0(no_op, buf[total-1]); + buf[total-1] = mbedtls_ct_uint_if( no_op, buf[total-1], 0 ); } } #endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */ -void mbedtls_ct_memcpy_if(mbedtls_ct_condition_t condition, - unsigned char *dest, - const unsigned char *src1, - const unsigned char *src2, - size_t len) -{ -#if defined(MBEDTLS_CT_SIZE_64) - const uint64_t mask = (uint64_t) condition; - const uint64_t not_mask = (uint64_t) ~mbedtls_ct_compiler_opaque(condition); -#else - const uint32_t mask = (uint32_t) condition; - const uint32_t not_mask = (uint32_t) ~mbedtls_ct_compiler_opaque(condition); -#endif +#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) - /* If src2 is NULL, setup src2 so that we read from the destination address. - * - * This means that if src2 == NULL && condition is false, the result will be a - * no-op because we read from dest and write the same data back into dest. - */ - if (src2 == NULL) { - src2 = dest; - } +void mbedtls_ct_memcpy_if_eq( unsigned char *dest, + const unsigned char *src, + size_t len, + size_t c1, + size_t c2 ) +{ + /* mask = c1 == c2 ? 0xff : 0x00 */ + const size_t equal = mbedtls_ct_size_bool_eq( c1, c2 ); + const unsigned char mask = (unsigned char) mbedtls_ct_size_mask( equal ); /* dest[i] = c1 == c2 ? src[i] : dest[i] */ - size_t i = 0; -#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) -#if defined(MBEDTLS_CT_SIZE_64) - for (; (i + 8) <= len; i += 8) { - uint64_t a = mbedtls_get_unaligned_uint64(src1 + i) & mask; - uint64_t b = mbedtls_get_unaligned_uint64(src2 + i) & not_mask; - mbedtls_put_unaligned_uint64(dest + i, a | b); + for( size_t i = 0; i < len; i++ ) + dest[i] = ( src[i] & mask ) | ( dest[i] & ~mask ); +} + +void mbedtls_ct_memcpy_offset( unsigned char *dest, + const unsigned char *src, + size_t offset, + size_t offset_min, + size_t offset_max, + size_t len ) +{ + size_t offsetval; + + for( offsetval = offset_min; offsetval <= offset_max; offsetval++ ) + { + mbedtls_ct_memcpy_if_eq( dest, src + offsetval, len, + offsetval, offset ); } -#else - for (; (i + 4) <= len; i += 4) { - uint32_t a = mbedtls_get_unaligned_uint32(src1 + i) & mask; - uint32_t b = mbedtls_get_unaligned_uint32(src2 + i) & not_mask; - mbedtls_put_unaligned_uint32(dest + i, a | b); +} + +int mbedtls_ct_hmac( mbedtls_md_context_t *ctx, + const unsigned char *add_data, + size_t add_data_len, + const unsigned char *data, + size_t data_len_secret, + size_t min_data_len, + size_t max_data_len, + unsigned char *output ) +{ + /* + * This function breaks the HMAC abstraction and uses the md_clone() + * extension to the MD API in order to get constant-flow behaviour. + * + * HMAC(msg) is defined as HASH(okey + HASH(ikey + msg)) where + means + * concatenation, and okey/ikey are the XOR of the key with some fixed bit + * patterns (see RFC 2104, sec. 2), which are stored in ctx->hmac_ctx. + * + * We'll first compute inner_hash = HASH(ikey + msg) by hashing up to + * minlen, then cloning the context, and for each byte up to maxlen + * finishing up the hash computation, keeping only the correct result. + * + * Then we only need to compute HASH(okey + inner_hash) and we're done. + */ + const mbedtls_md_type_t md_alg = mbedtls_md_get_type( ctx->md_info ); + /* TLS 1.2 only supports SHA-384, SHA-256, SHA-1, MD-5, + * all of which have the same block size except SHA-384. */ + const size_t block_size = md_alg == MBEDTLS_MD_SHA384 ? 128 : 64; + const unsigned char * const ikey = ctx->hmac_ctx; + const unsigned char * const okey = ikey + block_size; + const size_t hash_size = mbedtls_md_get_size( ctx->md_info ); + + unsigned char aux_out[MBEDTLS_MD_MAX_SIZE]; + mbedtls_md_context_t aux; + size_t offset; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + + mbedtls_md_init( &aux ); + +#define MD_CHK( func_call ) \ + do { \ + ret = (func_call); \ + if( ret != 0 ) \ + goto cleanup; \ + } while( 0 ) + + MD_CHK( mbedtls_md_setup( &aux, ctx->md_info, 0 ) ); + + /* After hmac_start() of hmac_reset(), ikey has already been hashed, + * so we can start directly with the message */ + MD_CHK( mbedtls_md_update( ctx, add_data, add_data_len ) ); + MD_CHK( mbedtls_md_update( ctx, data, min_data_len ) ); + + /* For each possible length, compute the hash up to that point */ + for( offset = min_data_len; offset <= max_data_len; offset++ ) + { + MD_CHK( mbedtls_md_clone( &aux, ctx ) ); + MD_CHK( mbedtls_md_finish( &aux, aux_out ) ); + /* Keep only the correct inner_hash in the output buffer */ + mbedtls_ct_memcpy_if_eq( output, aux_out, hash_size, + offset, data_len_secret ); + + if( offset < max_data_len ) + MD_CHK( mbedtls_md_update( ctx, data + offset, 1 ) ); } -#endif /* defined(MBEDTLS_CT_SIZE_64) */ -#endif /* MBEDTLS_EFFICIENT_UNALIGNED_ACCESS */ - for (; i < len; i++) { - dest[i] = (src1[i] & mask) | (src2[i] & not_mask); + + /* The context needs to finish() before it starts() again */ + MD_CHK( mbedtls_md_finish( ctx, aux_out ) ); + + /* Now compute HASH(okey + inner_hash) */ + MD_CHK( mbedtls_md_starts( ctx ) ); + MD_CHK( mbedtls_md_update( ctx, okey, block_size ) ); + MD_CHK( mbedtls_md_update( ctx, output, hash_size ) ); + MD_CHK( mbedtls_md_finish( ctx, output ) ); + + /* Done, get ready for next time */ + MD_CHK( mbedtls_md_hmac_reset( ctx ) ); + +#undef MD_CHK + +cleanup: + mbedtls_md_free( &aux ); + return( ret ); +} + +#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ + +#if defined(MBEDTLS_BIGNUM_C) + +#define MPI_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA ) + +/* + * Conditionally assign X = Y, without leaking information + * about whether the assignment was made or not. + * (Leaking information about the respective sizes of X and Y is ok however.) + */ +int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, + const mbedtls_mpi *Y, + unsigned char assign ) +{ + int ret = 0; + size_t i; + mbedtls_mpi_uint limb_mask; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( Y != NULL ); + + /* all-bits 1 if assign is 1, all-bits 0 if assign is 0 */ + limb_mask = mbedtls_ct_mpi_uint_mask( assign );; + + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, Y->n ) ); + + X->s = mbedtls_ct_cond_select_sign( assign, Y->s, X->s ); + + mbedtls_ct_mpi_uint_cond_assign( Y->n, X->p, Y->p, assign ); + + for( i = Y->n; i < X->n; i++ ) + X->p[i] &= ~limb_mask; + +cleanup: + return( ret ); +} + +/* + * Conditionally swap X and Y, without leaking information + * about whether the swap was made or not. + * Here it is not ok to simply swap the pointers, which whould lead to + * different memory access patterns when X and Y are used afterwards. + */ +int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, + mbedtls_mpi *Y, + unsigned char swap ) +{ + int ret, s; + size_t i; + mbedtls_mpi_uint limb_mask; + mbedtls_mpi_uint tmp; + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( Y != NULL ); + + if( X == Y ) + return( 0 ); + + /* all-bits 1 if swap is 1, all-bits 0 if swap is 0 */ + limb_mask = mbedtls_ct_mpi_uint_mask( swap ); + + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( X, Y->n ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_grow( Y, X->n ) ); + + s = X->s; + X->s = mbedtls_ct_cond_select_sign( swap, Y->s, X->s ); + Y->s = mbedtls_ct_cond_select_sign( swap, s, Y->s ); + + + for( i = 0; i < X->n; i++ ) + { + tmp = X->p[i]; + X->p[i] = ( X->p[i] & ~limb_mask ) | ( Y->p[i] & limb_mask ); + Y->p[i] = ( Y->p[i] & ~limb_mask ) | ( tmp & limb_mask ); } + +cleanup: + return( ret ); } -void mbedtls_ct_memcpy_offset(unsigned char *dest, - const unsigned char *src, - size_t offset, - size_t offset_min, - size_t offset_max, - size_t len) +/* + * Compare signed values in constant time + */ +int mbedtls_mpi_lt_mpi_ct( const mbedtls_mpi *X, + const mbedtls_mpi *Y, + unsigned *ret ) { - size_t offsetval; + size_t i; + /* The value of any of these variables is either 0 or 1 at all times. */ + unsigned cond, done, X_is_negative, Y_is_negative; + + MPI_VALIDATE_RET( X != NULL ); + MPI_VALIDATE_RET( Y != NULL ); + MPI_VALIDATE_RET( ret != NULL ); + + if( X->n != Y->n ) + return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; + + /* + * Set sign_N to 1 if N >= 0, 0 if N < 0. + * We know that N->s == 1 if N >= 0 and N->s == -1 if N < 0. + */ + X_is_negative = ( X->s & 2 ) >> 1; + Y_is_negative = ( Y->s & 2 ) >> 1; + + /* + * If the signs are different, then the positive operand is the bigger. + * That is if X is negative (X_is_negative == 1), then X < Y is true and it + * is false if X is positive (X_is_negative == 0). + */ + cond = ( X_is_negative ^ Y_is_negative ); + *ret = cond & X_is_negative; + + /* + * This is a constant-time function. We might have the result, but we still + * need to go through the loop. Record if we have the result already. + */ + done = cond; - for (offsetval = offset_min; offsetval <= offset_max; offsetval++) { - mbedtls_ct_memcpy_if(mbedtls_ct_uint_eq(offsetval, offset), dest, src + offsetval, NULL, - len); + for( i = X->n; i > 0; i-- ) + { + /* + * If Y->p[i - 1] < X->p[i - 1] then X < Y is true if and only if both + * X and Y are negative. + * + * Again even if we can make a decision, we just mark the result and + * the fact that we are done and continue looping. + */ + cond = mbedtls_ct_mpi_uint_lt( Y->p[i - 1], X->p[i - 1] ); + *ret |= cond & ( 1 - done ) & X_is_negative; + done |= cond; + + /* + * If X->p[i - 1] < Y->p[i - 1] then X < Y is true if and only if both + * X and Y are positive. + * + * Again even if we can make a decision, we just mark the result and + * the fact that we are done and continue looping. + */ + cond = mbedtls_ct_mpi_uint_lt( X->p[i - 1], Y->p[i - 1] ); + *ret |= cond & ( 1 - done ) & ( 1 - X_is_negative ); + done |= cond; } + + return( 0 ); } +#endif /* MBEDTLS_BIGNUM_C */ + #if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) -void mbedtls_ct_zeroize_if(mbedtls_ct_condition_t condition, void *buf, size_t len) +int mbedtls_ct_rsaes_pkcs1_v15_unpadding( unsigned char *input, + size_t ilen, + unsigned char *output, + size_t output_max_len, + size_t *olen ) { - uint32_t mask = (uint32_t) ~condition; - uint8_t *p = (uint8_t *) buf; - size_t i = 0; -#if defined(MBEDTLS_EFFICIENT_UNALIGNED_ACCESS) - for (; (i + 4) <= len; i += 4) { - mbedtls_put_unaligned_uint32((void *) (p + i), - mbedtls_get_unaligned_uint32((void *) (p + i)) & mask); - } -#endif - for (; i < len; i++) { - p[i] = p[i] & mask; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t i, plaintext_max_size; + + /* The following variables take sensitive values: their value must + * not leak into the observable behavior of the function other than + * the designated outputs (output, olen, return value). Otherwise + * this would open the execution of the function to + * side-channel-based variants of the Bleichenbacher padding oracle + * attack. Potential side channels include overall timing, memory + * access patterns (especially visible to an adversary who has access + * to a shared memory cache), and branches (especially visible to + * an adversary who has access to a shared code cache or to a shared + * branch predictor). */ + size_t pad_count = 0; + unsigned bad = 0; + unsigned char pad_done = 0; + size_t plaintext_size = 0; + unsigned output_too_large; + + plaintext_max_size = ( output_max_len > ilen - 11 ) ? ilen - 11 + : output_max_len; + + /* Check and get padding length in constant time and constant + * memory trace. The first byte must be 0. */ + bad |= input[0]; + + + /* Decode EME-PKCS1-v1_5 padding: 0x00 || 0x02 || PS || 0x00 + * where PS must be at least 8 nonzero bytes. */ + bad |= input[1] ^ MBEDTLS_RSA_CRYPT; + + /* Read the whole buffer. Set pad_done to nonzero if we find + * the 0x00 byte and remember the padding length in pad_count. */ + for( i = 2; i < ilen; i++ ) + { + pad_done |= ((input[i] | (unsigned char)-input[i]) >> 7) ^ 1; + pad_count += ((pad_done | (unsigned char)-pad_done) >> 7) ^ 1; } + + + /* If pad_done is still zero, there's no data, only unfinished padding. */ + bad |= mbedtls_ct_uint_if( pad_done, 0, 1 ); + + /* There must be at least 8 bytes of padding. */ + bad |= mbedtls_ct_size_gt( 8, pad_count ); + + /* If the padding is valid, set plaintext_size to the number of + * remaining bytes after stripping the padding. If the padding + * is invalid, avoid leaking this fact through the size of the + * output: use the maximum message size that fits in the output + * buffer. Do it without branches to avoid leaking the padding + * validity through timing. RSA keys are small enough that all the + * size_t values involved fit in unsigned int. */ + plaintext_size = mbedtls_ct_uint_if( + bad, (unsigned) plaintext_max_size, + (unsigned) ( ilen - pad_count - 3 ) ); + + /* Set output_too_large to 0 if the plaintext fits in the output + * buffer and to 1 otherwise. */ + output_too_large = mbedtls_ct_size_gt( plaintext_size, + plaintext_max_size ); + + /* Set ret without branches to avoid timing attacks. Return: + * - INVALID_PADDING if the padding is bad (bad != 0). + * - OUTPUT_TOO_LARGE if the padding is good but the decrypted + * plaintext does not fit in the output buffer. + * - 0 if the padding is correct. */ + ret = - (int) mbedtls_ct_uint_if( + bad, - MBEDTLS_ERR_RSA_INVALID_PADDING, + mbedtls_ct_uint_if( output_too_large, + - MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE, + 0 ) ); + + /* If the padding is bad or the plaintext is too large, zero the + * data that we're about to copy to the output buffer. + * We need to copy the same amount of data + * from the same buffer whether the padding is good or not to + * avoid leaking the padding validity through overall timing or + * through memory or cache access patterns. */ + bad = mbedtls_ct_uint_mask( bad | output_too_large ); + for( i = 11; i < ilen; i++ ) + input[i] &= ~bad; + + /* If the plaintext is too large, truncate it to the buffer size. + * Copy anyway to avoid revealing the length through timing, because + * revealing the length is as bad as revealing the padding validity + * for a Bleichenbacher attack. */ + plaintext_size = mbedtls_ct_uint_if( output_too_large, + (unsigned) plaintext_max_size, + (unsigned) plaintext_size ); + + /* Move the plaintext to the leftmost position where it can start in + * the working buffer, i.e. make it start plaintext_max_size from + * the end of the buffer. Do this with a memory access trace that + * does not depend on the plaintext size. After this move, the + * starting location of the plaintext is no longer sensitive + * information. */ + mbedtls_ct_mem_move_to_left( input + ilen - plaintext_max_size, + plaintext_max_size, + plaintext_max_size - plaintext_size ); + + /* Finally copy the decrypted plaintext plus trailing zeros into the output + * buffer. If output_max_len is 0, then output may be an invalid pointer + * and the result of memcpy() would be undefined; prevent undefined + * behavior making sure to depend only on output_max_len (the size of the + * user-provided output buffer), which is independent from plaintext + * length, validity of padding, success of the decryption, and other + * secrets. */ + if( output_max_len != 0 ) + memcpy( output, input + ilen - plaintext_max_size, plaintext_max_size ); + + /* Report the amount of data we copied to the output buffer. In case + * of errors (bad padding or output too large), the value of *olen + * when this function returns is not specified. Making it equivalent + * to the good case limits the risks of leaking the padding validity. */ + *olen = plaintext_size; + + return( ret ); } -#endif /* defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) */ +#endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */ diff --git a/src/duckdb/third_party/mbedtls/library/constant_time_internal.h b/src/duckdb/third_party/mbedtls/library/constant_time_internal.h index 92a026fcd..053cf123c 100644 --- a/src/duckdb/third_party/mbedtls/library/constant_time_internal.h +++ b/src/duckdb/third_party/mbedtls/library/constant_time_internal.h @@ -2,578 +2,325 @@ * Constant-time functions * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_CONSTANT_TIME_INTERNAL_H #define MBEDTLS_CONSTANT_TIME_INTERNAL_H -#include -#include - #include "common.h" #if defined(MBEDTLS_BIGNUM_C) #include "mbedtls/bignum.h" #endif -/* The constant-time interface provides various operations that are likely - * to result in constant-time code that does not branch or use conditional - * instructions for secret data (for secret pointers, this also applies to - * the data pointed to). - * - * It has three main parts: - * - * - boolean operations - * These are all named mbedtls_ct__. - * They operate over and return mbedtls_ct_condition_t. - * All arguments are considered secret. - * example: bool x = y | z => x = mbedtls_ct_bool_or(y, z) - * example: bool x = y == z => x = mbedtls_ct_uint_eq(y, z) - * - * - conditional data selection - * These are all named mbedtls_ct__if and mbedtls_ct__if_else_0 - * All arguments are considered secret. - * example: size_t a = x ? b : c => a = mbedtls_ct_size_if(x, b, c) - * example: unsigned a = x ? b : 0 => a = mbedtls_ct_uint_if_else_0(x, b) - * - * - block memory operations - * Only some arguments are considered secret, as documented for each - * function. - * example: if (x) memcpy(...) => mbedtls_ct_memcpy_if(x, ...) - * - * mbedtls_ct_condition_t must be treated as opaque and only created and - * manipulated via the functions in this header. The compiler should never - * be able to prove anything about its value at compile-time. - * - * mbedtls_ct_uint_t is an unsigned integer type over which constant time - * operations may be performed via the functions in this header. It is as big - * as the larger of size_t and mbedtls_mpi_uint, i.e. it is safe to cast - * to/from "unsigned int", "size_t", and "mbedtls_mpi_uint" (and any other - * not-larger integer types). - * - * For Arm (32-bit, 64-bit and Thumb), x86 and x86-64, assembly implementations - * are used to ensure that the generated code is constant time. For other - * architectures, it uses a plain C fallback designed to yield constant-time code - * (this has been observed to be constant-time on latest gcc, clang and MSVC - * as of May 2023). - * - * For readability, the inline definitions are separated out into - * constant_time_impl.h. - */ - -#if (SIZE_MAX > 0xffffffffffffffffULL) -/* Pointer size > 64-bit */ -typedef size_t mbedtls_ct_condition_t; -typedef size_t mbedtls_ct_uint_t; -typedef ptrdiff_t mbedtls_ct_int_t; -#define MBEDTLS_CT_TRUE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(SIZE_MAX)) -#elif (SIZE_MAX > 0xffffffff) || defined(MBEDTLS_HAVE_INT64) -/* 32-bit < pointer size <= 64-bit, or 64-bit MPI */ -typedef uint64_t mbedtls_ct_condition_t; -typedef uint64_t mbedtls_ct_uint_t; -typedef int64_t mbedtls_ct_int_t; -#define MBEDTLS_CT_SIZE_64 -#define MBEDTLS_CT_TRUE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(UINT64_MAX)) -#else -/* Pointer size <= 32-bit, and no 64-bit MPIs */ -typedef uint32_t mbedtls_ct_condition_t; -typedef uint32_t mbedtls_ct_uint_t; -typedef int32_t mbedtls_ct_int_t; -#define MBEDTLS_CT_SIZE_32 -#define MBEDTLS_CT_TRUE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(UINT32_MAX)) +#if defined(MBEDTLS_SSL_TLS_C) +#include "ssl_misc.h" #endif -#define MBEDTLS_CT_FALSE ((mbedtls_ct_condition_t) mbedtls_ct_compiler_opaque(0)) -/* ============================================================================ - * Boolean operations - */ +#include -/** Convert a number into a mbedtls_ct_condition_t. - * - * \param x Number to convert. - * - * \return MBEDTLS_CT_TRUE if \p x != 0, or MBEDTLS_CT_FALSE if \p x == 0 - * - */ -inline mbedtls_ct_condition_t mbedtls_ct_bool(mbedtls_ct_uint_t x); -/** Boolean "not equal" operation. +/** Turn a value into a mask: + * - if \p value == 0, return the all-bits 0 mask, aka 0 + * - otherwise, return the all-bits 1 mask, aka (unsigned) -1 * - * Functionally equivalent to: + * This function can be used to write constant-time code by replacing branches + * with bit operations using masks. * - * \p x != \p y + * \param value The value to analyze. * - * \param x The first value to analyze. - * \param y The second value to analyze. - * - * \return MBEDTLS_CT_TRUE if \p x != \p y, otherwise MBEDTLS_CT_FALSE. + * \return Zero if \p value is zero, otherwise all-bits-one. */ -inline mbedtls_ct_condition_t mbedtls_ct_uint_ne(mbedtls_ct_uint_t x, mbedtls_ct_uint_t y); +unsigned mbedtls_ct_uint_mask( unsigned value ); -/** Boolean "equals" operation. - * - * Functionally equivalent to: - * - * \p x == \p y - * - * \param x The first value to analyze. - * \param y The second value to analyze. - * - * \return MBEDTLS_CT_TRUE if \p x == \p y, otherwise MBEDTLS_CT_FALSE. - */ -inline mbedtls_ct_condition_t mbedtls_ct_uint_eq(mbedtls_ct_uint_t x, - mbedtls_ct_uint_t y); +#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) -/** Boolean "less than" operation. - * - * Functionally equivalent to: +/** Turn a value into a mask: + * - if \p value == 0, return the all-bits 0 mask, aka 0 + * - otherwise, return the all-bits 1 mask, aka (size_t) -1 * - * \p x < \p y + * This function can be used to write constant-time code by replacing branches + * with bit operations using masks. * - * \param x The first value to analyze. - * \param y The second value to analyze. + * \param value The value to analyze. * - * \return MBEDTLS_CT_TRUE if \p x < \p y, otherwise MBEDTLS_CT_FALSE. + * \return Zero if \p value is zero, otherwise all-bits-one. */ -inline mbedtls_ct_condition_t mbedtls_ct_uint_lt(mbedtls_ct_uint_t x, mbedtls_ct_uint_t y); +size_t mbedtls_ct_size_mask( size_t value ); -/** Boolean "greater than" operation. - * - * Functionally equivalent to: - * - * \p x > \p y - * - * \param x The first value to analyze. - * \param y The second value to analyze. - * - * \return MBEDTLS_CT_TRUE if \p x > \p y, otherwise MBEDTLS_CT_FALSE. - */ -inline mbedtls_ct_condition_t mbedtls_ct_uint_gt(mbedtls_ct_uint_t x, - mbedtls_ct_uint_t y); +#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ -/** Boolean "greater or equal" operation. - * - * Functionally equivalent to: - * - * \p x >= \p y - * - * \param x The first value to analyze. - * \param y The second value to analyze. - * - * \return MBEDTLS_CT_TRUE if \p x >= \p y, - * otherwise MBEDTLS_CT_FALSE. - */ -inline mbedtls_ct_condition_t mbedtls_ct_uint_ge(mbedtls_ct_uint_t x, - mbedtls_ct_uint_t y); +#if defined(MBEDTLS_BIGNUM_C) -/** Boolean "less than or equal" operation. +/** Turn a value into a mask: + * - if \p value == 0, return the all-bits 0 mask, aka 0 + * - otherwise, return the all-bits 1 mask, aka (mbedtls_mpi_uint) -1 * - * Functionally equivalent to: + * This function can be used to write constant-time code by replacing branches + * with bit operations using masks. * - * \p x <= \p y - * - * \param x The first value to analyze. - * \param y The second value to analyze. + * \param value The value to analyze. * - * \return MBEDTLS_CT_TRUE if \p x <= \p y, - * otherwise MBEDTLS_CT_FALSE. + * \return Zero if \p value is zero, otherwise all-bits-one. */ -inline mbedtls_ct_condition_t mbedtls_ct_uint_le(mbedtls_ct_uint_t x, - mbedtls_ct_uint_t y); +mbedtls_mpi_uint mbedtls_ct_mpi_uint_mask( mbedtls_mpi_uint value ); -/** Boolean not-equals operation. - * - * Functionally equivalent to: - * - * \p x != \p y - * - * \param x The first value to analyze. - * \param y The second value to analyze. - * - * \note This is more efficient than mbedtls_ct_uint_ne if both arguments are - * mbedtls_ct_condition_t. - * - * \return MBEDTLS_CT_TRUE if \p x != \p y, - * otherwise MBEDTLS_CT_FALSE. - */ -inline mbedtls_ct_condition_t mbedtls_ct_bool_ne(mbedtls_ct_condition_t x, - mbedtls_ct_condition_t y); +#endif /* MBEDTLS_BIGNUM_C */ -/** Boolean "and" operation. - * - * Functionally equivalent to: - * - * \p x && \p y - * - * \param x The first value to analyze. - * \param y The second value to analyze. - * - * \return MBEDTLS_CT_TRUE if \p x && \p y, - * otherwise MBEDTLS_CT_FALSE. - */ -inline mbedtls_ct_condition_t mbedtls_ct_bool_and(mbedtls_ct_condition_t x, - mbedtls_ct_condition_t y); +#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) -/** Boolean "or" operation. - * - * Functionally equivalent to: +/** Constant-flow mask generation for "greater or equal" comparison: + * - if \p x >= \p y, return all-bits 1, that is (size_t) -1 + * - otherwise, return all bits 0, that is 0 * - * \p x || \p y + * This function can be used to write constant-time code by replacing branches + * with bit operations using masks. * * \param x The first value to analyze. * \param y The second value to analyze. * - * \return MBEDTLS_CT_TRUE if \p x || \p y, - * otherwise MBEDTLS_CT_FALSE. - */ -inline mbedtls_ct_condition_t mbedtls_ct_bool_or(mbedtls_ct_condition_t x, - mbedtls_ct_condition_t y); - -/** Boolean "not" operation. - * - * Functionally equivalent to: - * - * ! \p x - * - * \param x The value to invert - * - * \return MBEDTLS_CT_FALSE if \p x, otherwise MBEDTLS_CT_TRUE. - */ -inline mbedtls_ct_condition_t mbedtls_ct_bool_not(mbedtls_ct_condition_t x); - - -/* ============================================================================ - * Data selection operations - */ - -/** Choose between two size_t values. - * - * Functionally equivalent to: - * - * condition ? if1 : if0. - * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. - * \param if0 Value to use if \p condition == MBEDTLS_CT_FALSE. - * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise \c if0. + * \return All-bits-one if \p x is greater or equal than \p y, + * otherwise zero. */ -inline size_t mbedtls_ct_size_if(mbedtls_ct_condition_t condition, - size_t if1, - size_t if0); +size_t mbedtls_ct_size_mask_ge( size_t x, + size_t y ); -/** Choose between two unsigned values. - * - * Functionally equivalent to: - * - * condition ? if1 : if0. - * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. - * \param if0 Value to use if \p condition == MBEDTLS_CT_FALSE. - * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise \c if0. - */ -inline unsigned mbedtls_ct_uint_if(mbedtls_ct_condition_t condition, - unsigned if1, - unsigned if0); +#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ -/** Choose between two mbedtls_ct_condition_t values. - * - * Functionally equivalent to: +/** Constant-flow boolean "equal" comparison: + * return x == y * - * condition ? if1 : if0. + * This is equivalent to \p x == \p y, but is likely to be compiled + * to code using bitwise operation rather than a branch. * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. - * \param if0 Value to use if \p condition == MBEDTLS_CT_FALSE. + * \param x The first value to analyze. + * \param y The second value to analyze. * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise \c if0. + * \return 1 if \p x equals to \p y, otherwise 0. */ -inline mbedtls_ct_condition_t mbedtls_ct_bool_if(mbedtls_ct_condition_t condition, - mbedtls_ct_condition_t if1, - mbedtls_ct_condition_t if0); +unsigned mbedtls_ct_size_bool_eq( size_t x, + size_t y ); #if defined(MBEDTLS_BIGNUM_C) -/** Choose between two mbedtls_mpi_uint values. - * - * Functionally equivalent to: - * - * condition ? if1 : if0. - * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. - * \param if0 Value to use if \p condition == MBEDTLS_CT_FALSE. - * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise \c if0. - */ -inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if(mbedtls_ct_condition_t condition, \ - mbedtls_mpi_uint if1, \ - mbedtls_mpi_uint if0); - -#endif - -/** Choose between an unsigned value and 0. - * - * Functionally equivalent to: - * - * condition ? if1 : 0. +/** Decide if an integer is less than the other, without branches. * - * Functionally equivalent to mbedtls_ct_uint_if(condition, if1, 0) but - * results in smaller code size. + * This is equivalent to \p x < \p y, but is likely to be compiled + * to code using bitwise operation rather than a branch. * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. + * \param x The first value to analyze. + * \param y The second value to analyze. * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise 0. + * \return 1 if \p x is less than \p y, otherwise 0. */ -inline unsigned mbedtls_ct_uint_if_else_0(mbedtls_ct_condition_t condition, unsigned if1); +unsigned mbedtls_ct_mpi_uint_lt( const mbedtls_mpi_uint x, + const mbedtls_mpi_uint y ); -/** Choose between an mbedtls_ct_condition_t and 0. - * - * Functionally equivalent to: - * - * condition ? if1 : 0. - * - * Functionally equivalent to mbedtls_ct_bool_if(condition, if1, 0) but - * results in smaller code size. - * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. - * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise 0. - */ -inline mbedtls_ct_condition_t mbedtls_ct_bool_if_else_0(mbedtls_ct_condition_t condition, - mbedtls_ct_condition_t if1); +#endif /* MBEDTLS_BIGNUM_C */ -/** Choose between a size_t value and 0. - * - * Functionally equivalent to: - * - * condition ? if1 : 0. +/** Choose between two integer values without branches. * - * Functionally equivalent to mbedtls_ct_size_if(condition, if1, 0) but - * results in smaller code size. + * This is equivalent to `condition ? if1 : if0`, but is likely to be compiled + * to code using bitwise operation rather than a branch. * * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. + * \param if1 Value to use if \p condition is nonzero. + * \param if0 Value to use if \p condition is zero. * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise 0. + * \return \c if1 if \p condition is nonzero, otherwise \c if0. */ -inline size_t mbedtls_ct_size_if_else_0(mbedtls_ct_condition_t condition, size_t if1); +unsigned mbedtls_ct_uint_if( unsigned condition, + unsigned if1, + unsigned if0 ); #if defined(MBEDTLS_BIGNUM_C) -/** Choose between an mbedtls_mpi_uint value and 0. +/** Conditionally assign a value without branches. * - * Functionally equivalent to: - * - * condition ? if1 : 0. - * - * Functionally equivalent to mbedtls_ct_mpi_uint_if(condition, if1, 0) but - * results in smaller code size. - * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. + * This is equivalent to `if ( condition ) dest = src`, but is likely + * to be compiled to code using bitwise operation rather than a branch. * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise 0. + * \param n \p dest and \p src must be arrays of limbs of size n. + * \param dest The MPI to conditionally assign to. This must point + * to an initialized MPI. + * \param src The MPI to be assigned from. This must point to an + * initialized MPI. + * \param condition Condition to test, must be 0 or 1. */ -inline mbedtls_mpi_uint mbedtls_ct_mpi_uint_if_else_0(mbedtls_ct_condition_t condition, - mbedtls_mpi_uint if1); +void mbedtls_ct_mpi_uint_cond_assign( size_t n, + mbedtls_mpi_uint *dest, + const mbedtls_mpi_uint *src, + unsigned char condition ); -#endif +#endif /* MBEDTLS_BIGNUM_C */ -/** Constant-flow char selection - * - * \param low Secret. Bottom of range - * \param high Secret. Top of range - * \param c Secret. Value to compare to range - * \param t Secret. Value to return, if in range - * - * \return \p t if \p low <= \p c <= \p high, 0 otherwise. - */ -inline unsigned char mbedtls_ct_uchar_in_range_if(unsigned char low, - unsigned char high, - unsigned char c, - unsigned char t); +#if defined(MBEDTLS_BASE64_C) -/** Choose between two error values. The values must be in the range [-32767..0]. - * - * Functionally equivalent to: +/** Given a value in the range 0..63, return the corresponding Base64 digit. * - * condition ? if1 : if0. + * The implementation assumes that letters are consecutive (e.g. ASCII + * but not EBCDIC). * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. - * \param if0 Value to use if \p condition == MBEDTLS_CT_FALSE. + * \param value A value in the range 0..63. * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise \c if0. + * \return A base64 digit converted from \p value. */ -inline int mbedtls_ct_error_if(mbedtls_ct_condition_t condition, int if1, int if0); +unsigned char mbedtls_ct_base64_enc_char( unsigned char value ); -/** Choose between an error value and 0. The error value must be in the range [-32767..0]. - * - * Functionally equivalent to: +/** Given a Base64 digit, return its value. * - * condition ? if1 : 0. + * If c is not a Base64 digit ('A'..'Z', 'a'..'z', '0'..'9', '+' or '/'), + * return -1. * - * Functionally equivalent to mbedtls_ct_error_if(condition, if1, 0) but - * results in smaller code size. + * The implementation assumes that letters are consecutive (e.g. ASCII + * but not EBCDIC). * - * \param condition Condition to test. - * \param if1 Value to use if \p condition == MBEDTLS_CT_TRUE. + * \param c A base64 digit. * - * \return \c if1 if \p condition == MBEDTLS_CT_TRUE, otherwise 0. + * \return The value of the base64 digit \p c. */ -inline int mbedtls_ct_error_if_else_0(mbedtls_ct_condition_t condition, int if1); +signed char mbedtls_ct_base64_dec_value( unsigned char c ); -/* ============================================================================ - * Block memory operations - */ +#endif /* MBEDTLS_BASE64_C */ -#if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) +#if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) -/** Conditionally set a block of memory to zero. +/** Conditional memcpy without branches. * - * Regardless of the condition, every byte will be read once and written to - * once. + * This is equivalent to `if ( c1 == c2 ) memcpy(dest, src, len)`, but is likely + * to be compiled to code using bitwise operation rather than a branch. * - * \param condition Secret. Condition to test. - * \param buf Secret. Pointer to the start of the buffer. - * \param len Number of bytes to set to zero. - * - * \warning Unlike mbedtls_platform_zeroize, this does not have the same guarantees - * about not being optimised away if the memory is never read again. + * \param dest The pointer to conditionally copy to. + * \param src The pointer to copy from. Shouldn't overlap with \p dest. + * \param len The number of bytes to copy. + * \param c1 The first value to analyze in the condition. + * \param c2 The second value to analyze in the condition. */ -void mbedtls_ct_zeroize_if(mbedtls_ct_condition_t condition, void *buf, size_t len); - -/** Shift some data towards the left inside a buffer. - * - * Functionally equivalent to: - * - * memmove(start, start + offset, total - offset); - * memset(start + (total - offset), 0, offset); - * - * Timing independence comes at the expense of performance. - * - * \param start Secret. Pointer to the start of the buffer. - * \param total Total size of the buffer. - * \param offset Secret. Offset from which to copy \p total - \p offset bytes. - */ -void mbedtls_ct_memmove_left(void *start, - size_t total, - size_t offset); - -#endif /* defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) */ - -/** Conditional memcpy. - * - * Functionally equivalent to: - * - * if (condition) { - * memcpy(dest, src1, len); - * } else { - * if (src2 != NULL) - * memcpy(dest, src2, len); - * } - * - * It will always read len bytes from src1. - * If src2 != NULL, it will always read len bytes from src2. - * If src2 == NULL, it will instead read len bytes from dest (as if src2 == dest). - * - * \param condition The condition - * \param dest Secret. Destination pointer. - * \param src1 Secret. Pointer to copy from (if \p condition == MBEDTLS_CT_TRUE). - * This may be equal to \p dest, but may not overlap in other ways. - * \param src2 Secret (contents only - may branch to determine if this parameter is NULL). - * Pointer to copy from (if \p condition == MBEDTLS_CT_FALSE and \p src2 is not NULL). May be NULL. - * This may be equal to \p dest, but may not overlap it in other ways. It may overlap with \p src1. - * \param len Number of bytes to copy. - */ -void mbedtls_ct_memcpy_if(mbedtls_ct_condition_t condition, - unsigned char *dest, - const unsigned char *src1, - const unsigned char *src2, - size_t len - ); +void mbedtls_ct_memcpy_if_eq( unsigned char *dest, + const unsigned char *src, + size_t len, + size_t c1, size_t c2 ); -/** Copy data from a secret position. +/** Copy data from a secret position with constant flow. * - * Functionally equivalent to: + * This function copies \p len bytes from \p src_base + \p offset_secret to \p + * dst, with a code flow and memory access pattern that does not depend on \p + * offset_secret, but only on \p offset_min, \p offset_max and \p len. + * Functionally equivalent to `memcpy(dst, src + offset_secret, len)`. * - * memcpy(dst, src + offset, len) - * - * This function copies \p len bytes from \p src + \p offset to - * \p dst, with a code flow and memory access pattern that does not depend on - * \p offset, but only on \p offset_min, \p offset_max and \p len. - * - * \note This function reads from \p dest, but the value that - * is read does not influence the result and this - * function's behavior is well-defined regardless of the - * contents of the buffers. This may result in false - * positives from static or dynamic analyzers, especially - * if \p dest is not initialized. - * - * \param dest Secret. The destination buffer. This must point to a writable + * \param dest The destination buffer. This must point to a writable * buffer of at least \p len bytes. - * \param src Secret. The base of the source buffer. This must point to a + * \param src The base of the source buffer. This must point to a * readable buffer of at least \p offset_max + \p len - * bytes. Shouldn't overlap with \p dest - * \param offset Secret. The offset in the source buffer from which to copy. + * bytes. Shouldn't overlap with \p dest. + * \param offset The offset in the source buffer from which to copy. * This must be no less than \p offset_min and no greater * than \p offset_max. * \param offset_min The minimal value of \p offset. * \param offset_max The maximal value of \p offset. * \param len The number of bytes to copy. */ -void mbedtls_ct_memcpy_offset(unsigned char *dest, - const unsigned char *src, - size_t offset, - size_t offset_min, - size_t offset_max, - size_t len); - -/* Documented in include/mbedtls/constant_time.h. a and b are secret. - - int mbedtls_ct_memcmp(const void *a, - const void *b, - size_t n); - */ - -#if defined(MBEDTLS_NIST_KW_C) - -/** Constant-time buffer comparison without branches. - * - * Similar to mbedtls_ct_memcmp, except that the result only depends on part of - * the input data - differences in the head or tail are ignored. Functionally equivalent to: - * - * memcmp(a + skip_head, b + skip_head, size - skip_head - skip_tail) - * - * Time taken depends on \p n, but not on \p skip_head or \p skip_tail . - * - * Behaviour is undefined if ( \p skip_head + \p skip_tail) > \p n. - * - * \param a Secret. Pointer to the first buffer, containing at least \p n bytes. May not be NULL. - * \param b Secret. Pointer to the second buffer, containing at least \p n bytes. May not be NULL. - * \param n The number of bytes to examine (total size of the buffers). - * \param skip_head Secret. The number of bytes to treat as non-significant at the start of the buffer. - * These bytes will still be read. - * \param skip_tail Secret. The number of bytes to treat as non-significant at the end of the buffer. - * These bytes will still be read. - * - * \return Zero if the contents of the two buffers are the same, otherwise non-zero. - */ -int mbedtls_ct_memcmp_partial(const void *a, - const void *b, - size_t n, - size_t skip_head, - size_t skip_tail); +void mbedtls_ct_memcpy_offset( unsigned char *dest, + const unsigned char *src, + size_t offset, + size_t offset_min, + size_t offset_max, + size_t len ); + +/** Compute the HMAC of variable-length data with constant flow. + * + * This function computes the HMAC of the concatenation of \p add_data and \p + * data, and does with a code flow and memory access pattern that does not + * depend on \p data_len_secret, but only on \p min_data_len and \p + * max_data_len. In particular, this function always reads exactly \p + * max_data_len bytes from \p data. + * + * \param ctx The HMAC context. It must have keys configured + * with mbedtls_md_hmac_starts() and use one of the + * following hashes: SHA-384, SHA-256, SHA-1 or MD-5. + * It is reset using mbedtls_md_hmac_reset() after + * the computation is complete to prepare for the + * next computation. + * \param add_data The first part of the message whose HMAC is being + * calculated. This must point to a readable buffer + * of \p add_data_len bytes. + * \param add_data_len The length of \p add_data in bytes. + * \param data The buffer containing the second part of the + * message. This must point to a readable buffer + * of \p max_data_len bytes. + * \param data_len_secret The length of the data to process in \p data. + * This must be no less than \p min_data_len and no + * greater than \p max_data_len. + * \param min_data_len The minimal length of the second part of the + * message, read from \p data. + * \param max_data_len The maximal length of the second part of the + * message, read from \p data. + * \param output The HMAC will be written here. This must point to + * a writable buffer of sufficient size to hold the + * HMAC value. + * + * \retval 0 on success. + * \retval #MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED + * The hardware accelerator failed. + */ +int mbedtls_ct_hmac( mbedtls_md_context_t *ctx, + const unsigned char *add_data, + size_t add_data_len, + const unsigned char *data, + size_t data_len_secret, + size_t min_data_len, + size_t max_data_len, + unsigned char *output ); + +#endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ -#endif +#if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) -/* Include the implementation of inline functions above. */ -#include "constant_time_impl.h" +/** This function performs the unpadding part of a PKCS#1 v1.5 decryption + * operation (EME-PKCS1-v1_5 decoding). + * + * \note The return value from this function is a sensitive value + * (this is unusual). #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE shouldn't happen + * in a well-written application, but 0 vs #MBEDTLS_ERR_RSA_INVALID_PADDING + * is often a situation that an attacker can provoke and leaking which + * one is the result is precisely the information the attacker wants. + * + * \param input The input buffer which is the payload inside PKCS#1v1.5 + * encryption padding, called the "encoded message EM" + * by the terminology. + * \param ilen The length of the payload in the \p input buffer. + * \param output The buffer for the payload, called "message M" by the + * PKCS#1 terminology. This must be a writable buffer of + * length \p output_max_len bytes. + * \param olen The address at which to store the length of + * the payload. This must not be \c NULL. + * \param output_max_len The length in bytes of the output buffer \p output. + * + * \return \c 0 on success. + * \return #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE + * The output buffer is too small for the unpadded payload. + * \return #MBEDTLS_ERR_RSA_INVALID_PADDING + * The input doesn't contain properly formatted padding. + */ +int mbedtls_ct_rsaes_pkcs1_v15_unpadding( unsigned char *input, + size_t ilen, + unsigned char *output, + size_t output_max_len, + size_t *olen ); + +#endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */ #endif /* MBEDTLS_CONSTANT_TIME_INTERNAL_H */ diff --git a/src/duckdb/third_party/mbedtls/library/constant_time_invasive.h b/src/duckdb/third_party/mbedtls/library/constant_time_invasive.h new file mode 100644 index 000000000..4620ca137 --- /dev/null +++ b/src/duckdb/third_party/mbedtls/library/constant_time_invasive.h @@ -0,0 +1,51 @@ +/** + * \file constant_time_invasive.h + * + * \brief Constant-time module: interfaces for invasive testing only. + * + * The interfaces in this file are intended for testing purposes only. + * They SHOULD NOT be made available in library integrations except when + * building the library for testing. + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MBEDTLS_CONSTANT_TIME_INVASIVE_H +#define MBEDTLS_CONSTANT_TIME_INVASIVE_H + +#include "common.h" + +#if defined(MBEDTLS_TEST_HOOKS) + +/** Turn a value into a mask: + * - if \p low <= \p c <= \p high, + * return the all-bits 1 mask, aka (unsigned) -1 + * - otherwise, return the all-bits 0 mask, aka 0 + * + * \param low The value to analyze. + * \param high The value to analyze. + * \param c The value to analyze. + * + * \return All-bits-one if \p low <= \p c <= \p high, otherwise zero. + */ +unsigned char mbedtls_ct_uchar_mask_of_range( unsigned char low, + unsigned char high, + unsigned char c ); + +#endif /* MBEDTLS_TEST_HOOKS */ + +#endif /* MBEDTLS_CONSTANT_TIME_INVASIVE_H */ diff --git a/src/duckdb/third_party/mbedtls/library/entropy.cpp b/src/duckdb/third_party/mbedtls/library/entropy.cpp new file mode 100644 index 000000000..5e1f65f13 --- /dev/null +++ b/src/duckdb/third_party/mbedtls/library/entropy.cpp @@ -0,0 +1,701 @@ +/* + * Entropy accumulator implementation + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common.h" + +#if defined(MBEDTLS_ENTROPY_C) + +#include "mbedtls/entropy.h" +#include "entropy_poll.h" +#include "mbedtls/platform_util.h" +#include "mbedtls/error.h" + +#include + +#if defined(MBEDTLS_FS_IO) +#include +#endif + +#if defined(MBEDTLS_ENTROPY_NV_SEED) +#include "mbedtls/platform.h" +#endif + +#if defined(MBEDTLS_SELF_TEST) +//#if defined(MBEDTLS_PLATFORM_C) +//#include "mbedtls/platform.h" +//#else +//#include +//#define mbedtls_printf printf +//#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ + + +#define ENTROPY_MAX_LOOP 256 /**< Maximum amount to loop before error */ + +void mbedtls_entropy_init( mbedtls_entropy_context *ctx ) +{ + ctx->source_count = 0; + memset( ctx->source, 0, sizeof( ctx->source ) ); + +#if defined(MBEDTLS_THREADING_C) + mbedtls_mutex_init( &ctx->mutex ); +#endif + + ctx->accumulator_started = 0; +#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) + mbedtls_sha512_init( &ctx->accumulator ); +#else + mbedtls_sha256_init( &ctx->accumulator ); +#endif + + /* Reminder: Update ENTROPY_HAVE_STRONG in the test files + * when adding more strong entropy sources here. */ + +#if !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) +#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) + mbedtls_entropy_add_source( ctx, mbedtls_platform_entropy_poll, NULL, + MBEDTLS_ENTROPY_MIN_PLATFORM, + MBEDTLS_ENTROPY_SOURCE_STRONG ); +#endif +#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) + mbedtls_entropy_add_source( ctx, mbedtls_hardware_poll, NULL, + MBEDTLS_ENTROPY_MIN_HARDWARE, + MBEDTLS_ENTROPY_SOURCE_STRONG ); +#endif +#if defined(MBEDTLS_ENTROPY_NV_SEED) + mbedtls_entropy_add_source( ctx, mbedtls_nv_seed_poll, NULL, + MBEDTLS_ENTROPY_BLOCK_SIZE, + MBEDTLS_ENTROPY_SOURCE_STRONG ); + ctx->initial_entropy_run = 0; +#endif +#endif /* MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES */ +} + +void mbedtls_entropy_free( mbedtls_entropy_context *ctx ) +{ + /* If the context was already free, don't call free() again. + * This is important for mutexes which don't allow double-free. */ + if( ctx->accumulator_started == -1 ) + return; + +#if defined(MBEDTLS_THREADING_C) + mbedtls_mutex_free( &ctx->mutex ); +#endif +#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) + mbedtls_sha512_free( &ctx->accumulator ); +#else + mbedtls_sha256_free( &ctx->accumulator ); +#endif +#if defined(MBEDTLS_ENTROPY_NV_SEED) + ctx->initial_entropy_run = 0; +#endif + ctx->source_count = 0; + mbedtls_platform_zeroize( ctx->source, sizeof( ctx->source ) ); + ctx->accumulator_started = -1; +} + +int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx, + mbedtls_entropy_f_source_ptr f_source, void *p_source, + size_t threshold, int strong ) +{ + int idx, ret = 0; + +#if defined(MBEDTLS_THREADING_C) + if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) + return( ret ); +#endif + + idx = ctx->source_count; + if( idx >= MBEDTLS_ENTROPY_MAX_SOURCES ) + { + ret = MBEDTLS_ERR_ENTROPY_MAX_SOURCES; + goto exit; + } + + ctx->source[idx].f_source = f_source; + ctx->source[idx].p_source = p_source; + ctx->source[idx].threshold = threshold; + ctx->source[idx].strong = strong; + + ctx->source_count++; + +exit: +#if defined(MBEDTLS_THREADING_C) + if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) + return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); +#endif + + return( ret ); +} + +/* + * Entropy accumulator update + */ +static int entropy_update( mbedtls_entropy_context *ctx, unsigned char source_id, + const unsigned char *data, size_t len ) +{ + unsigned char header[2]; + unsigned char tmp[MBEDTLS_ENTROPY_BLOCK_SIZE]; + size_t use_len = len; + const unsigned char *p = data; + int ret = 0; + + if( use_len > MBEDTLS_ENTROPY_BLOCK_SIZE ) + { +#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) + if( ( ret = mbedtls_sha512( data, len, tmp, 0 ) ) != 0 ) + goto cleanup; +#else + if( ( ret = mbedtls_sha256( data, len, tmp, 0 ) ) != 0 ) + goto cleanup; +#endif + p = tmp; + use_len = MBEDTLS_ENTROPY_BLOCK_SIZE; + } + + header[0] = source_id; + header[1] = use_len & 0xFF; + + /* + * Start the accumulator if this has not already happened. Note that + * it is sufficient to start the accumulator here only because all calls to + * gather entropy eventually execute this code. + */ +#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) + if( ctx->accumulator_started == 0 && + ( ret = mbedtls_sha512_starts( &ctx->accumulator, 0 ) ) != 0 ) + goto cleanup; + else + ctx->accumulator_started = 1; + if( ( ret = mbedtls_sha512_update( &ctx->accumulator, header, 2 ) ) != 0 ) + goto cleanup; + ret = mbedtls_sha512_update( &ctx->accumulator, p, use_len ); +#else + if( ctx->accumulator_started == 0 && + ( ret = mbedtls_sha256_starts( &ctx->accumulator, 0 ) ) != 0 ) + goto cleanup; + else + ctx->accumulator_started = 1; + if( ( ret = mbedtls_sha256_update( &ctx->accumulator, header, 2 ) ) != 0 ) + goto cleanup; + ret = mbedtls_sha256_update( &ctx->accumulator, p, use_len ); +#endif + +cleanup: + mbedtls_platform_zeroize( tmp, sizeof( tmp ) ); + + return( ret ); +} + +int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx, + const unsigned char *data, size_t len ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + +#if defined(MBEDTLS_THREADING_C) + if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) + return( ret ); +#endif + + ret = entropy_update( ctx, MBEDTLS_ENTROPY_SOURCE_MANUAL, data, len ); + +#if defined(MBEDTLS_THREADING_C) + if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) + return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); +#endif + + return( ret ); +} + +/* + * Run through the different sources to add entropy to our accumulator + */ +static int entropy_gather_internal( mbedtls_entropy_context *ctx ) +{ + int ret = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + int i; + int have_one_strong = 0; + unsigned char buf[MBEDTLS_ENTROPY_MAX_GATHER]; + size_t olen; + + if( ctx->source_count == 0 ) + return( MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED ); + + /* + * Run through our entropy sources + */ + for( i = 0; i < ctx->source_count; i++ ) + { + if( ctx->source[i].strong == MBEDTLS_ENTROPY_SOURCE_STRONG ) + have_one_strong = 1; + + olen = 0; + if( ( ret = ctx->source[i].f_source( ctx->source[i].p_source, + buf, MBEDTLS_ENTROPY_MAX_GATHER, &olen ) ) != 0 ) + { + goto cleanup; + } + + /* + * Add if we actually gathered something + */ + if( olen > 0 ) + { + if( ( ret = entropy_update( ctx, (unsigned char) i, + buf, olen ) ) != 0 ) + return( ret ); + ctx->source[i].size += olen; + } + } + + if( have_one_strong == 0 ) + ret = MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE; + +cleanup: + mbedtls_platform_zeroize( buf, sizeof( buf ) ); + + return( ret ); +} + +/* + * Thread-safe wrapper for entropy_gather_internal() + */ +int mbedtls_entropy_gather( mbedtls_entropy_context *ctx ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + +#if defined(MBEDTLS_THREADING_C) + if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) + return( ret ); +#endif + + ret = entropy_gather_internal( ctx ); + +#if defined(MBEDTLS_THREADING_C) + if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) + return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); +#endif + + return( ret ); +} + +int mbedtls_entropy_func( void *data, unsigned char *output, size_t len ) +{ + int ret, count = 0, i, thresholds_reached; + size_t strong_size; + mbedtls_entropy_context *ctx = (mbedtls_entropy_context *) data; + unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; + + if( len > MBEDTLS_ENTROPY_BLOCK_SIZE ) + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + +#if defined(MBEDTLS_ENTROPY_NV_SEED) + /* Update the NV entropy seed before generating any entropy for outside + * use. + */ + if( ctx->initial_entropy_run == 0 ) + { + ctx->initial_entropy_run = 1; + if( ( ret = mbedtls_entropy_update_nv_seed( ctx ) ) != 0 ) + return( ret ); + } +#endif + +#if defined(MBEDTLS_THREADING_C) + if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) + return( ret ); +#endif + + /* + * Always gather extra entropy before a call + */ + do + { + if( count++ > ENTROPY_MAX_LOOP ) + { + ret = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + goto exit; + } + + if( ( ret = entropy_gather_internal( ctx ) ) != 0 ) + goto exit; + + thresholds_reached = 1; + strong_size = 0; + for( i = 0; i < ctx->source_count; i++ ) + { + if( ctx->source[i].size < ctx->source[i].threshold ) + thresholds_reached = 0; + if( ctx->source[i].strong == MBEDTLS_ENTROPY_SOURCE_STRONG ) + strong_size += ctx->source[i].size; + } + } + while( ! thresholds_reached || strong_size < MBEDTLS_ENTROPY_BLOCK_SIZE ); + + memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE ); + +#if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR) + /* + * Note that at this stage it is assumed that the accumulator was started + * in a previous call to entropy_update(). If this is not guaranteed, the + * code below will fail. + */ + if( ( ret = mbedtls_sha512_finish( &ctx->accumulator, buf ) ) != 0 ) + goto exit; + + /* + * Reset accumulator and counters and recycle existing entropy + */ + mbedtls_sha512_free( &ctx->accumulator ); + mbedtls_sha512_init( &ctx->accumulator ); + if( ( ret = mbedtls_sha512_starts( &ctx->accumulator, 0 ) ) != 0 ) + goto exit; + if( ( ret = mbedtls_sha512_update( &ctx->accumulator, buf, + MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) + goto exit; + + /* + * Perform second SHA-512 on entropy + */ + if( ( ret = mbedtls_sha512( buf, MBEDTLS_ENTROPY_BLOCK_SIZE, + buf, 0 ) ) != 0 ) + goto exit; +#else /* MBEDTLS_ENTROPY_SHA512_ACCUMULATOR */ + if( ( ret = mbedtls_sha256_finish( &ctx->accumulator, buf ) ) != 0 ) + goto exit; + + /* + * Reset accumulator and counters and recycle existing entropy + */ + mbedtls_sha256_free( &ctx->accumulator ); + mbedtls_sha256_init( &ctx->accumulator ); + if( ( ret = mbedtls_sha256_starts( &ctx->accumulator, 0 ) ) != 0 ) + goto exit; + if( ( ret = mbedtls_sha256_update( &ctx->accumulator, buf, + MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) + goto exit; + + /* + * Perform second SHA-256 on entropy + */ + if( ( ret = mbedtls_sha256( buf, MBEDTLS_ENTROPY_BLOCK_SIZE, + buf, 0 ) ) != 0 ) + goto exit; +#endif /* MBEDTLS_ENTROPY_SHA512_ACCUMULATOR */ + + for( i = 0; i < ctx->source_count; i++ ) + ctx->source[i].size = 0; + + memcpy( output, buf, len ); + + ret = 0; + +exit: + mbedtls_platform_zeroize( buf, sizeof( buf ) ); + +#if defined(MBEDTLS_THREADING_C) + if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) + return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); +#endif + + return( ret ); +} + +#if defined(MBEDTLS_ENTROPY_NV_SEED) +int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx ) +{ + int ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR; + unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; + + /* Read new seed and write it to NV */ + if( ( ret = mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) + return( ret ); + + if( mbedtls_nv_seed_write( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 ) + return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR ); + + /* Manually update the remaining stream with a separator value to diverge */ + memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE ); + ret = mbedtls_entropy_update_manual( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ); + + return( ret ); +} +#endif /* MBEDTLS_ENTROPY_NV_SEED */ + +#if defined(MBEDTLS_FS_IO) +int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + FILE *f = NULL; + unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; + + if( ( ret = mbedtls_entropy_func( ctx, buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) ) != 0 ) + { + ret = MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + goto exit; + } + + if( ( f = fopen( path, "wb" ) ) == NULL ) + { + ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR; + goto exit; + } + + if( fwrite( buf, 1, MBEDTLS_ENTROPY_BLOCK_SIZE, f ) != MBEDTLS_ENTROPY_BLOCK_SIZE ) + { + ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR; + goto exit; + } + + ret = 0; + +exit: + mbedtls_platform_zeroize( buf, sizeof( buf ) ); + + if( f != NULL ) + fclose( f ); + + return( ret ); +} + +int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path ) +{ + int ret = 0; + FILE *f; + size_t n; + unsigned char buf[ MBEDTLS_ENTROPY_MAX_SEED_SIZE ]; + + if( ( f = fopen( path, "rb" ) ) == NULL ) + return( MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR ); + + fseek( f, 0, SEEK_END ); + n = (size_t) ftell( f ); + fseek( f, 0, SEEK_SET ); + + if( n > MBEDTLS_ENTROPY_MAX_SEED_SIZE ) + n = MBEDTLS_ENTROPY_MAX_SEED_SIZE; + + if( fread( buf, 1, n, f ) != n ) + ret = MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR; + else + ret = mbedtls_entropy_update_manual( ctx, buf, n ); + + fclose( f ); + + mbedtls_platform_zeroize( buf, sizeof( buf ) ); + + if( ret != 0 ) + return( ret ); + + return( mbedtls_entropy_write_seed_file( ctx, path ) ); +} +#endif /* MBEDTLS_FS_IO */ + +#if defined(MBEDTLS_SELF_TEST) +/* + * Dummy source function + */ +static int entropy_dummy_source( void *data, unsigned char *output, + size_t len, size_t *olen ) +{ + ((void) data); + + memset( output, 0x2a, len ); + *olen = len; + + return( 0 ); +} + +#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) + +static int mbedtls_entropy_source_self_test_gather( unsigned char *buf, size_t buf_len ) +{ + int ret = 0; + size_t entropy_len = 0; + size_t olen = 0; + size_t attempts = buf_len; + + while( attempts > 0 && entropy_len < buf_len ) + { + if( ( ret = mbedtls_hardware_poll( NULL, buf + entropy_len, + buf_len - entropy_len, &olen ) ) != 0 ) + return( ret ); + + entropy_len += olen; + attempts--; + } + + if( entropy_len < buf_len ) + { + ret = 1; + } + + return( ret ); +} + + +static int mbedtls_entropy_source_self_test_check_bits( const unsigned char *buf, + size_t buf_len ) +{ + unsigned char set= 0xFF; + unsigned char unset = 0x00; + size_t i; + + for( i = 0; i < buf_len; i++ ) + { + set &= buf[i]; + unset |= buf[i]; + } + + return( set == 0xFF || unset == 0x00 ); +} + +/* + * A test to ensure hat the entropy sources are functioning correctly + * and there is no obvious failure. The test performs the following checks: + * - The entropy source is not providing only 0s (all bits unset) or 1s (all + * bits set). + * - The entropy source is not providing values in a pattern. Because the + * hardware could be providing data in an arbitrary length, this check polls + * the hardware entropy source twice and compares the result to ensure they + * are not equal. + * - The error code returned by the entropy source is not an error. + */ +int mbedtls_entropy_source_self_test( int verbose ) +{ + int ret = 0; + unsigned char buf0[2 * sizeof( unsigned long long int )]; + unsigned char buf1[2 * sizeof( unsigned long long int )]; + + if( verbose != 0 ) + mbedtls_printf( " ENTROPY_BIAS test: " ); + + memset( buf0, 0x00, sizeof( buf0 ) ); + memset( buf1, 0x00, sizeof( buf1 ) ); + + if( ( ret = mbedtls_entropy_source_self_test_gather( buf0, sizeof( buf0 ) ) ) != 0 ) + goto cleanup; + if( ( ret = mbedtls_entropy_source_self_test_gather( buf1, sizeof( buf1 ) ) ) != 0 ) + goto cleanup; + + /* Make sure that the returned values are not all 0 or 1 */ + if( ( ret = mbedtls_entropy_source_self_test_check_bits( buf0, sizeof( buf0 ) ) ) != 0 ) + goto cleanup; + if( ( ret = mbedtls_entropy_source_self_test_check_bits( buf1, sizeof( buf1 ) ) ) != 0 ) + goto cleanup; + + /* Make sure that the entropy source is not returning values in a + * pattern */ + ret = memcmp( buf0, buf1, sizeof( buf0 ) ) == 0; + +cleanup: + if( verbose != 0 ) + { + if( ret != 0 ) + mbedtls_printf( "failed\n" ); + else + mbedtls_printf( "passed\n" ); + + mbedtls_printf( "\n" ); + } + + return( ret != 0 ); +} + +#endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */ + +/* + * The actual entropy quality is hard to test, but we can at least + * test that the functions don't cause errors and write the correct + * amount of data to buffers. + */ +int mbedtls_entropy_self_test( int verbose ) +{ + int ret = 1; + mbedtls_entropy_context ctx; + unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 }; + unsigned char acc[MBEDTLS_ENTROPY_BLOCK_SIZE] = { 0 }; + size_t i, j; + + if( verbose != 0 ) + mbedtls_printf( " ENTROPY test: " ); + + mbedtls_entropy_init( &ctx ); + + /* First do a gather to make sure we have default sources */ + if( ( ret = mbedtls_entropy_gather( &ctx ) ) != 0 ) + goto cleanup; + + ret = mbedtls_entropy_add_source( &ctx, entropy_dummy_source, NULL, 16, + MBEDTLS_ENTROPY_SOURCE_WEAK ); + if( ret != 0 ) + goto cleanup; + + if( ( ret = mbedtls_entropy_update_manual( &ctx, buf, sizeof buf ) ) != 0 ) + goto cleanup; + + /* + * To test that mbedtls_entropy_func writes correct number of bytes: + * - use the whole buffer and rely on ASan to detect overruns + * - collect entropy 8 times and OR the result in an accumulator: + * any byte should then be 0 with probably 2^(-64), so requiring + * each of the 32 or 64 bytes to be non-zero has a false failure rate + * of at most 2^(-58) which is acceptable. + */ + for( i = 0; i < 8; i++ ) + { + if( ( ret = mbedtls_entropy_func( &ctx, buf, sizeof( buf ) ) ) != 0 ) + goto cleanup; + + for( j = 0; j < sizeof( buf ); j++ ) + acc[j] |= buf[j]; + } + + for( j = 0; j < sizeof( buf ); j++ ) + { + if( acc[j] == 0 ) + { + ret = 1; + goto cleanup; + } + } + +#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) + if( ( ret = mbedtls_entropy_source_self_test( 0 ) ) != 0 ) + goto cleanup; +#endif + +cleanup: + mbedtls_entropy_free( &ctx ); + + if( verbose != 0 ) + { + if( ret != 0 ) + mbedtls_printf( "failed\n" ); + else + mbedtls_printf( "passed\n" ); + + mbedtls_printf( "\n" ); + } + + return( ret != 0 ); +} +#endif /* MBEDTLS_SELF_TEST */ + +#endif /* MBEDTLS_ENTROPY_C */ diff --git a/src/duckdb/third_party/mbedtls/library/entropy_poll.cpp b/src/duckdb/third_party/mbedtls/library/entropy_poll.cpp new file mode 100644 index 000000000..067ec2f3c --- /dev/null +++ b/src/duckdb/third_party/mbedtls/library/entropy_poll.cpp @@ -0,0 +1,265 @@ +/* + * Platform-specific and custom entropy polling functions + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if defined(__linux__) && !defined(_GNU_SOURCE) +/* Ensure that syscall() is available even when compiling with -std=c99 */ +#define _GNU_SOURCE +#endif + +#include "common.h" + +#include + +#if defined(MBEDTLS_ENTROPY_C) + +#include "mbedtls/entropy.h" +#include "entropy_poll.h" +#include "mbedtls/error.h" + +#if defined(MBEDTLS_TIMING_C) +#include "mbedtls/timing.h" +#endif +#if defined(MBEDTLS_ENTROPY_NV_SEED) +#include "mbedtls/platform.h" +#endif + +#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) + +#if !defined(unix) && !defined(__unix__) && !defined(__unix) && \ + !defined(__APPLE__) && !defined(_WIN32) && !defined(__QNXNTO__) && \ + !defined(__HAIKU__) && !defined(__midipix__) && !defined(__MVS__) +#error "Platform entropy sources only work on Unix and Windows, see MBEDTLS_NO_PLATFORM_ENTROPY in mbedtls_config.h" +#endif + +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) + +#include +#include +#include + +#if defined(__MINGW32__) +// MINGW +int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len, + size_t *olen ) +{ + HCRYPTPROV provider; + ((void) data); + *olen = 0; + + if( CryptAcquireContext( &provider, NULL, NULL, + PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) == FALSE ) + { + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + } + + if( CryptGenRandom( provider, (DWORD) len, output ) == FALSE ) + { + CryptReleaseContext( provider, 0 ); + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + } + + CryptReleaseContext( provider, 0 ); + *olen = len; + + return( 0 ); +} +#else +int mbedtls_platform_entropy_poll(void *data, unsigned char *output, size_t len, + size_t *olen) +{ + ((void) data); + *olen = 0; + + /* + * BCryptGenRandom takes ULONG for size, which is smaller than size_t on + * 64-bit Windows platforms. Extract entropy in chunks of len (dependent + * on ULONG_MAX) size. + */ + while (len != 0) { + unsigned long ulong_bytes = + (len > ULONG_MAX) ? ULONG_MAX : (unsigned long) len; + + if (!BCRYPT_SUCCESS(BCryptGenRandom(NULL, output, ulong_bytes, + BCRYPT_USE_SYSTEM_PREFERRED_RNG))) { + return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED; + } + + *olen += ulong_bytes; + len -= ulong_bytes; + } + + return 0; +} +#endif +#else /* _WIN32 && !EFIX64 && !EFI32 */ + +/* + * Test for Linux getrandom() support. + * Since there is no wrapper in the libc yet, use the generic syscall wrapper + * available in GNU libc and compatible libc's (eg uClibc). + */ +#if ((defined(__linux__) && defined(__GLIBC__)) || defined(__midipix__)) +#include +#include +#if defined(SYS_getrandom) +#define HAVE_GETRANDOM +#include + +static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags ) +{ + /* MemSan cannot understand that the syscall writes to the buffer */ +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) + memset( buf, 0, buflen ); +#endif +#endif + return( syscall( SYS_getrandom, buf, buflen, flags ) ); +} +#endif /* SYS_getrandom */ +#endif /* __linux__ || __midipix__ */ + +#if defined(__FreeBSD__) || defined(__DragonFly__) +#include +#if (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || \ + (defined(__DragonFly__) && __DragonFly_version >= 500700) +#include +#include +#define HAVE_GETRANDOM +static int getrandom_wrapper( void *buf, size_t buflen, unsigned int flags ) +{ + return getrandom( buf, buflen, flags ); +} +#endif /* (__FreeBSD__ && __FreeBSD_version >= 1200000) || + (__DragonFly__ && __DragonFly_version >= 500700) */ +#endif /* __FreeBSD__ || __DragonFly__ */ + +/* + * Some BSD systems provide KERN_ARND. + * This is equivalent to reading from /dev/urandom, only it doesn't require an + * open file descriptor, and provides up to 256 bytes per call (basically the + * same as getentropy(), but with a longer history). + * + * Documentation: https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7 + */ +#if (defined(__FreeBSD__) || defined(__NetBSD__)) && !defined(HAVE_GETRANDOM) +#include +#include +#if defined(KERN_ARND) +#define HAVE_SYSCTL_ARND + +static int sysctl_arnd_wrapper( unsigned char *buf, size_t buflen ) +{ + int name[2]; + size_t len; + + name[0] = CTL_KERN; + name[1] = KERN_ARND; + + while( buflen > 0 ) + { + len = buflen > 256 ? 256 : buflen; + if( sysctl(name, 2, buf, &len, NULL, 0) == -1 ) + return( -1 ); + buflen -= len; + buf += len; + } + return( 0 ); +} +#endif /* KERN_ARND */ +#endif /* __FreeBSD__ || __NetBSD__ */ + +#include + +int mbedtls_platform_entropy_poll( void *data, + unsigned char *output, size_t len, size_t *olen ) +{ + FILE *file; + size_t read_len; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + ((void) data); + +#if defined(HAVE_GETRANDOM) + ret = getrandom_wrapper( output, len, 0 ); + if( ret >= 0 ) + { + *olen = ret; + return( 0 ); + } + else if( errno != ENOSYS ) + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + /* Fall through if the system call isn't known. */ +#else + ((void) ret); +#endif /* HAVE_GETRANDOM */ + +#if defined(HAVE_SYSCTL_ARND) + ((void) file); + ((void) read_len); + if( sysctl_arnd_wrapper( output, len ) == -1 ) + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + *olen = len; + return( 0 ); +#else + + *olen = 0; + + file = fopen( "/dev/urandom", "rb" ); + if( file == NULL ) + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + + read_len = fread( output, 1, len, file ); + if( read_len != len ) + { + fclose( file ); + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + } + + fclose( file ); + *olen = len; + + return( 0 ); +#endif /* HAVE_SYSCTL_ARND */ +} +#endif /* _WIN32 && !EFIX64 && !EFI32 */ +#endif /* !MBEDTLS_NO_PLATFORM_ENTROPY */ + +#if defined(MBEDTLS_ENTROPY_NV_SEED) +int mbedtls_nv_seed_poll( void *data, + unsigned char *output, size_t len, size_t *olen ) +{ + unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; + size_t use_len = MBEDTLS_ENTROPY_BLOCK_SIZE; + ((void) data); + + memset( buf, 0, MBEDTLS_ENTROPY_BLOCK_SIZE ); + + if( mbedtls_nv_seed_read( buf, MBEDTLS_ENTROPY_BLOCK_SIZE ) < 0 ) + return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED ); + + if( len < use_len ) + use_len = len; + + memcpy( output, buf, use_len ); + *olen = use_len; + + return( 0 ); +} +#endif /* MBEDTLS_ENTROPY_NV_SEED */ + +#endif /* MBEDTLS_ENTROPY_C */ diff --git a/src/duckdb/third_party/mbedtls/library/entropy_poll.h b/src/duckdb/third_party/mbedtls/library/entropy_poll.h new file mode 100644 index 000000000..aef1a0977 --- /dev/null +++ b/src/duckdb/third_party/mbedtls/library/entropy_poll.h @@ -0,0 +1,76 @@ +/** + * \file entropy_poll.h + * + * \brief Platform-specific and custom entropy polling functions + */ +/* + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBEDTLS_ENTROPY_POLL_H +#define MBEDTLS_ENTROPY_POLL_H + +#include "mbedtls/build_info.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Default thresholds for built-in sources, in bytes + */ +#define MBEDTLS_ENTROPY_MIN_PLATFORM 32 /**< Minimum for platform source */ +#if !defined(MBEDTLS_ENTROPY_MIN_HARDWARE) +#define MBEDTLS_ENTROPY_MIN_HARDWARE 32 /**< Minimum for the hardware source */ +#endif + +#if !defined(MBEDTLS_NO_PLATFORM_ENTROPY) +/** + * \brief Platform-specific entropy poll callback + */ +int mbedtls_platform_entropy_poll( void *data, + unsigned char *output, size_t len, size_t *olen ); +#endif + +#if defined(MBEDTLS_ENTROPY_HARDWARE_ALT) +/** + * \brief Entropy poll callback for a hardware source + * + * \warning This is not provided by mbed TLS! + * See \c MBEDTLS_ENTROPY_HARDWARE_ALT in mbedtls_config.h. + * + * \note This must accept NULL as its first argument. + */ +int mbedtls_hardware_poll( void *data, + unsigned char *output, size_t len, size_t *olen ); +#endif + +#if defined(MBEDTLS_ENTROPY_NV_SEED) +/** + * \brief Entropy poll callback for a non-volatile seed file + * + * \note This must accept NULL as its first argument. + */ +int mbedtls_nv_seed_poll( void *data, + unsigned char *output, size_t len, size_t *olen ); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* entropy_poll.h */ diff --git a/src/duckdb/third_party/mbedtls/library/gcm.cpp b/src/duckdb/third_party/mbedtls/library/gcm.cpp index f4384cb04..8505cf4e0 100644 --- a/src/duckdb/third_party/mbedtls/library/gcm.cpp +++ b/src/duckdb/third_party/mbedtls/library/gcm.cpp @@ -2,7 +2,19 @@ * NIST SP800-38D compliant GCM implementation * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* @@ -20,14 +32,8 @@ #if defined(MBEDTLS_GCM_C) #include "mbedtls/gcm.h" -#include "mbedtls/platform.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" -#include "mbedtls/constant_time.h" - -#if defined(MBEDTLS_BLOCK_CIPHER_C) -#include "block_cipher_internal.h" -#endif #include @@ -35,57 +41,30 @@ #include "aesni.h" #endif -#if defined(MBEDTLS_AESCE_C) -#include "aesce.h" -#endif +#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) +#include "mbedtls/aes.h" +#include "mbedtls/platform.h" +#if !defined(MBEDTLS_PLATFORM_C) +#include +#define mbedtls_printf printf +#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ #if !defined(MBEDTLS_GCM_ALT) -/* Used to select the acceleration mechanism */ -#define MBEDTLS_GCM_ACC_SMALLTABLE 0 -#define MBEDTLS_GCM_ACC_LARGETABLE 1 -#define MBEDTLS_GCM_ACC_AESNI 2 -#define MBEDTLS_GCM_ACC_AESCE 3 +/* Parameter validation macros */ +#define GCM_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_GCM_BAD_INPUT ) +#define GCM_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) /* * Initialize a context */ -void mbedtls_gcm_init(mbedtls_gcm_context *ctx) -{ - memset(ctx, 0, sizeof(mbedtls_gcm_context)); -} - -inline void gcm_set_acceleration(mbedtls_gcm_context *ctx) +void mbedtls_gcm_init( mbedtls_gcm_context *ctx ) { -#if defined(MBEDTLS_GCM_LARGE_TABLE) - ctx->acceleration = MBEDTLS_GCM_ACC_LARGETABLE; -#else - ctx->acceleration = MBEDTLS_GCM_ACC_SMALLTABLE; -#endif - -#if defined(MBEDTLS_AESNI_HAVE_CODE) - /* With CLMUL support, we need only h, not the rest of the table */ - if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) { - ctx->acceleration = MBEDTLS_GCM_ACC_AESNI; - } -#endif - -#if defined(MBEDTLS_AESCE_HAVE_CODE) - if (MBEDTLS_AESCE_HAS_SUPPORT()) { - ctx->acceleration = MBEDTLS_GCM_ACC_AESCE; - } -#endif -} - -inline void gcm_gen_table_rightshift(uint64_t dst[2], const uint64_t src[2]) -{ - uint8_t *u8Dst = (uint8_t *) dst; - uint8_t *u8Src = (uint8_t *) src; - - MBEDTLS_PUT_UINT64_BE(MBEDTLS_GET_UINT64_BE(&src[1], 0) >> 1, &dst[1], 0); - u8Dst[8] |= (u8Src[7] & 0x01) << 7; - MBEDTLS_PUT_UINT64_BE(MBEDTLS_GET_UINT64_BE(&src[0], 0) >> 1, &dst[0], 0); - u8Dst[0] ^= (u8Src[15] & 0x01) ? 0xE1 : 0; + GCM_VALIDATE( ctx != NULL ); + memset( ctx, 0, sizeof( mbedtls_gcm_context ) ); } /* @@ -96,202 +75,109 @@ inline void gcm_gen_table_rightshift(uint64_t dst[2], const uint64_t src[2]) * is the high-order bit of HH corresponds to P^0 and the low-order bit of HL * corresponds to P^127. */ -static int gcm_gen_table(mbedtls_gcm_context *ctx) +static int gcm_gen_table( mbedtls_gcm_context *ctx ) { int ret, i, j; - uint64_t u64h[2] = { 0 }; - uint8_t *h = (uint8_t *) u64h; - -#if defined(MBEDTLS_BLOCK_CIPHER_C) - ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, h, h); -#else + uint64_t hi, lo; + uint64_t vl, vh; + unsigned char h[16]; size_t olen = 0; - ret = mbedtls_cipher_update(&ctx->cipher_ctx, h, 16, h, &olen); -#endif - if (ret != 0) { - return ret; - } - gcm_set_acceleration(ctx); + memset( h, 0, 16 ); + if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, h, 16, h, &olen ) ) != 0 ) + return( ret ); - /* MBEDTLS_GCM_HTABLE_SIZE/2 = 1000 corresponds to 1 in GF(2^128) */ - ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2][0] = u64h[0]; - ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2][1] = u64h[1]; + /* pack h as two 64-bits ints, big-endian */ + hi = MBEDTLS_GET_UINT32_BE( h, 0 ); + lo = MBEDTLS_GET_UINT32_BE( h, 4 ); + vh = (uint64_t) hi << 32 | lo; - switch (ctx->acceleration) { -#if defined(MBEDTLS_AESNI_HAVE_CODE) - case MBEDTLS_GCM_ACC_AESNI: - return 0; -#endif + hi = MBEDTLS_GET_UINT32_BE( h, 8 ); + lo = MBEDTLS_GET_UINT32_BE( h, 12 ); + vl = (uint64_t) hi << 32 | lo; -#if defined(MBEDTLS_AESCE_HAVE_CODE) - case MBEDTLS_GCM_ACC_AESCE: - return 0; + /* 8 = 1000 corresponds to 1 in GF(2^128) */ + ctx->HL[8] = vl; + ctx->HH[8] = vh; + +#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) + /* With CLMUL support, we need only h, not the rest of the table */ + if( mbedtls_aesni_has_support( MBEDTLS_AESNI_CLMUL ) ) + return( 0 ); #endif - default: - /* 0 corresponds to 0 in GF(2^128) */ - ctx->H[0][0] = 0; - ctx->H[0][1] = 0; + /* 0 corresponds to 0 in GF(2^128) */ + ctx->HH[0] = 0; + ctx->HL[0] = 0; - for (i = MBEDTLS_GCM_HTABLE_SIZE/4; i > 0; i >>= 1) { - gcm_gen_table_rightshift(ctx->H[i], ctx->H[i*2]); - } + for( i = 4; i > 0; i >>= 1 ) + { + uint32_t T = ( vl & 1 ) * 0xe1000000U; + vl = ( vh << 63 ) | ( vl >> 1 ); + vh = ( vh >> 1 ) ^ ( (uint64_t) T << 32); -#if !defined(MBEDTLS_GCM_LARGE_TABLE) - /* pack elements of H as 64-bits ints, big-endian */ - for (i = MBEDTLS_GCM_HTABLE_SIZE/2; i > 0; i >>= 1) { - MBEDTLS_PUT_UINT64_BE(ctx->H[i][0], &ctx->H[i][0], 0); - MBEDTLS_PUT_UINT64_BE(ctx->H[i][1], &ctx->H[i][1], 0); - } -#endif + ctx->HL[i] = vl; + ctx->HH[i] = vh; + } - for (i = 2; i < MBEDTLS_GCM_HTABLE_SIZE; i <<= 1) { - for (j = 1; j < i; j++) { - mbedtls_xor_no_simd((unsigned char *) ctx->H[i+j], - (unsigned char *) ctx->H[i], - (unsigned char *) ctx->H[j], - 16); - } - } + for( i = 2; i <= 8; i *= 2 ) + { + uint64_t *HiL = ctx->HL + i, *HiH = ctx->HH + i; + vh = *HiH; + vl = *HiL; + for( j = 1; j < i; j++ ) + { + HiH[j] = vh ^ ctx->HH[j]; + HiL[j] = vl ^ ctx->HL[j]; + } } - return 0; + return( 0 ); } -int mbedtls_gcm_setkey(mbedtls_gcm_context *ctx, - mbedtls_cipher_id_t cipher, - const unsigned char *key, - unsigned int keybits) +int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, + mbedtls_cipher_id_t cipher, + const unsigned char *key, + unsigned int keybits ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - - if (keybits != 128 && keybits != 192 && keybits != 256) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } - -#if defined(MBEDTLS_BLOCK_CIPHER_C) - mbedtls_block_cipher_free(&ctx->block_cipher_ctx); - - if ((ret = mbedtls_block_cipher_setup(&ctx->block_cipher_ctx, cipher)) != 0) { - return ret; - } - - if ((ret = mbedtls_block_cipher_setkey(&ctx->block_cipher_ctx, key, keybits)) != 0) { - return ret; - } -#else const mbedtls_cipher_info_t *cipher_info; - cipher_info = mbedtls_cipher_info_from_values(cipher, keybits, - MBEDTLS_MODE_ECB); - if (cipher_info == NULL) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } + GCM_VALIDATE_RET( ctx != NULL ); + GCM_VALIDATE_RET( key != NULL ); + GCM_VALIDATE_RET( keybits == 128 || keybits == 192 || keybits == 256 ); - if (mbedtls_cipher_info_get_block_size(cipher_info) != 16) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } + cipher_info = mbedtls_cipher_info_from_values( cipher, keybits, + MBEDTLS_MODE_ECB ); + if( cipher_info == NULL ) + return( MBEDTLS_ERR_GCM_BAD_INPUT ); - mbedtls_cipher_free(&ctx->cipher_ctx); + if( cipher_info->block_size != 16 ) + return( MBEDTLS_ERR_GCM_BAD_INPUT ); - if ((ret = mbedtls_cipher_setup(&ctx->cipher_ctx, cipher_info)) != 0) { - return ret; - } + mbedtls_cipher_free( &ctx->cipher_ctx ); - if ((ret = mbedtls_cipher_setkey(&ctx->cipher_ctx, key, keybits, - MBEDTLS_ENCRYPT)) != 0) { - return ret; - } -#endif + if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) + return( ret ); - if ((ret = gcm_gen_table(ctx)) != 0) { - return ret; + if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keybits, + MBEDTLS_ENCRYPT ) ) != 0 ) + { + return( ret ); } - return 0; -} - -#if defined(MBEDTLS_GCM_LARGE_TABLE) -static const uint16_t last8[256] = { - 0x0000, 0xc201, 0x8403, 0x4602, 0x0807, 0xca06, 0x8c04, 0x4e05, - 0x100e, 0xd20f, 0x940d, 0x560c, 0x1809, 0xda08, 0x9c0a, 0x5e0b, - 0x201c, 0xe21d, 0xa41f, 0x661e, 0x281b, 0xea1a, 0xac18, 0x6e19, - 0x3012, 0xf213, 0xb411, 0x7610, 0x3815, 0xfa14, 0xbc16, 0x7e17, - 0x4038, 0x8239, 0xc43b, 0x063a, 0x483f, 0x8a3e, 0xcc3c, 0x0e3d, - 0x5036, 0x9237, 0xd435, 0x1634, 0x5831, 0x9a30, 0xdc32, 0x1e33, - 0x6024, 0xa225, 0xe427, 0x2626, 0x6823, 0xaa22, 0xec20, 0x2e21, - 0x702a, 0xb22b, 0xf429, 0x3628, 0x782d, 0xba2c, 0xfc2e, 0x3e2f, - 0x8070, 0x4271, 0x0473, 0xc672, 0x8877, 0x4a76, 0x0c74, 0xce75, - 0x907e, 0x527f, 0x147d, 0xd67c, 0x9879, 0x5a78, 0x1c7a, 0xde7b, - 0xa06c, 0x626d, 0x246f, 0xe66e, 0xa86b, 0x6a6a, 0x2c68, 0xee69, - 0xb062, 0x7263, 0x3461, 0xf660, 0xb865, 0x7a64, 0x3c66, 0xfe67, - 0xc048, 0x0249, 0x444b, 0x864a, 0xc84f, 0x0a4e, 0x4c4c, 0x8e4d, - 0xd046, 0x1247, 0x5445, 0x9644, 0xd841, 0x1a40, 0x5c42, 0x9e43, - 0xe054, 0x2255, 0x6457, 0xa656, 0xe853, 0x2a52, 0x6c50, 0xae51, - 0xf05a, 0x325b, 0x7459, 0xb658, 0xf85d, 0x3a5c, 0x7c5e, 0xbe5f, - 0x00e1, 0xc2e0, 0x84e2, 0x46e3, 0x08e6, 0xcae7, 0x8ce5, 0x4ee4, - 0x10ef, 0xd2ee, 0x94ec, 0x56ed, 0x18e8, 0xdae9, 0x9ceb, 0x5eea, - 0x20fd, 0xe2fc, 0xa4fe, 0x66ff, 0x28fa, 0xeafb, 0xacf9, 0x6ef8, - 0x30f3, 0xf2f2, 0xb4f0, 0x76f1, 0x38f4, 0xfaf5, 0xbcf7, 0x7ef6, - 0x40d9, 0x82d8, 0xc4da, 0x06db, 0x48de, 0x8adf, 0xccdd, 0x0edc, - 0x50d7, 0x92d6, 0xd4d4, 0x16d5, 0x58d0, 0x9ad1, 0xdcd3, 0x1ed2, - 0x60c5, 0xa2c4, 0xe4c6, 0x26c7, 0x68c2, 0xaac3, 0xecc1, 0x2ec0, - 0x70cb, 0xb2ca, 0xf4c8, 0x36c9, 0x78cc, 0xbacd, 0xfccf, 0x3ece, - 0x8091, 0x4290, 0x0492, 0xc693, 0x8896, 0x4a97, 0x0c95, 0xce94, - 0x909f, 0x529e, 0x149c, 0xd69d, 0x9898, 0x5a99, 0x1c9b, 0xde9a, - 0xa08d, 0x628c, 0x248e, 0xe68f, 0xa88a, 0x6a8b, 0x2c89, 0xee88, - 0xb083, 0x7282, 0x3480, 0xf681, 0xb884, 0x7a85, 0x3c87, 0xfe86, - 0xc0a9, 0x02a8, 0x44aa, 0x86ab, 0xc8ae, 0x0aaf, 0x4cad, 0x8eac, - 0xd0a7, 0x12a6, 0x54a4, 0x96a5, 0xd8a0, 0x1aa1, 0x5ca3, 0x9ea2, - 0xe0b5, 0x22b4, 0x64b6, 0xa6b7, 0xe8b2, 0x2ab3, 0x6cb1, 0xaeb0, - 0xf0bb, 0x32ba, 0x74b8, 0xb6b9, 0xf8bc, 0x3abd, 0x7cbf, 0xbebe -}; - -static void gcm_mult_largetable(uint8_t *output, const uint8_t *x, uint64_t H[256][2]) -{ - int i; - uint64_t u64z[2]; - uint16_t *u16z = (uint16_t *) u64z; - uint8_t *u8z = (uint8_t *) u64z; - uint8_t rem; - - u64z[0] = 0; - u64z[1] = 0; + if( ( ret = gcm_gen_table( ctx ) ) != 0 ) + return( ret ); - if (MBEDTLS_IS_BIG_ENDIAN) { - for (i = 15; i > 0; i--) { - mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[x[i]], 16); - rem = u8z[15]; - - u64z[1] >>= 8; - u8z[8] = u8z[7]; - u64z[0] >>= 8; - - u16z[0] ^= MBEDTLS_GET_UINT16_LE(&last8[rem], 0); - } - } else { - for (i = 15; i > 0; i--) { - mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[x[i]], 16); - rem = u8z[15]; - - u64z[1] <<= 8; - u8z[8] = u8z[7]; - u64z[0] <<= 8; - - u16z[0] ^= last8[rem]; - } - } - - mbedtls_xor_no_simd(output, u8z, (uint8_t *) H[x[0]], 16); + return( 0 ); } -#else + /* * Shoup's method for multiplication use this table with * last4[x] = x times P^128 * where x and last4[x] are seen as elements of GF(2^128) as in [MGV] */ -static const uint16_t last4[16] = +static const uint64_t last4[16] = { 0x0000, 0x1c20, 0x3840, 0x2460, 0x7080, 0x6ca0, 0x48c0, 0x54e0, @@ -299,152 +185,130 @@ static const uint16_t last4[16] = 0x9180, 0x8da0, 0xa9c0, 0xb5e0 }; -static void gcm_mult_smalltable(uint8_t *output, const uint8_t *x, uint64_t H[16][2]) +/* + * Sets output to x times H using the precomputed tables. + * x and output are seen as elements of GF(2^128) as in [MGV]. + */ +static void gcm_mult( mbedtls_gcm_context *ctx, const unsigned char x[16], + unsigned char output[16] ) { int i = 0; unsigned char lo, hi, rem; - uint64_t u64z[2]; - const uint64_t *pu64z = NULL; - uint8_t *u8z = (uint8_t *) u64z; + uint64_t zh, zl; - lo = x[15] & 0xf; - hi = (x[15] >> 4) & 0xf; - - pu64z = H[lo]; +#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64) + if( mbedtls_aesni_has_support( MBEDTLS_AESNI_CLMUL ) ) { + unsigned char h[16]; - rem = (unsigned char) pu64z[1] & 0xf; - u64z[1] = (pu64z[0] << 60) | (pu64z[1] >> 4); - u64z[0] = (pu64z[0] >> 4); - u64z[0] ^= (uint64_t) last4[rem] << 48; - mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[hi], 16); + MBEDTLS_PUT_UINT32_BE( ctx->HH[8] >> 32, h, 0 ); + MBEDTLS_PUT_UINT32_BE( ctx->HH[8], h, 4 ); + MBEDTLS_PUT_UINT32_BE( ctx->HL[8] >> 32, h, 8 ); + MBEDTLS_PUT_UINT32_BE( ctx->HL[8], h, 12 ); - for (i = 14; i >= 0; i--) { - lo = x[i] & 0xf; - hi = (x[i] >> 4) & 0xf; - - rem = (unsigned char) u64z[1] & 0xf; - u64z[1] = (u64z[0] << 60) | (u64z[1] >> 4); - u64z[0] = (u64z[0] >> 4); - u64z[0] ^= (uint64_t) last4[rem] << 48; - mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[lo], 16); - - rem = (unsigned char) u64z[1] & 0xf; - u64z[1] = (u64z[0] << 60) | (u64z[1] >> 4); - u64z[0] = (u64z[0] >> 4); - u64z[0] ^= (uint64_t) last4[rem] << 48; - mbedtls_xor_no_simd(u8z, u8z, (uint8_t *) H[hi], 16); + mbedtls_aesni_gcm_mult( output, x, h ); + return; } +#endif /* MBEDTLS_AESNI_C && MBEDTLS_HAVE_X86_64 */ - MBEDTLS_PUT_UINT64_BE(u64z[0], output, 0); - MBEDTLS_PUT_UINT64_BE(u64z[1], output, 8); -} -#endif + lo = x[15] & 0xf; -/* - * Sets output to x times H using the precomputed tables. - * x and output are seen as elements of GF(2^128) as in [MGV]. - */ -static void gcm_mult(mbedtls_gcm_context *ctx, const unsigned char x[16], - unsigned char output[16]) -{ - switch (ctx->acceleration) { -#if defined(MBEDTLS_AESNI_HAVE_CODE) - case MBEDTLS_GCM_ACC_AESNI: - mbedtls_aesni_gcm_mult(output, x, (uint8_t *) ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2]); - break; -#endif + zh = ctx->HH[lo]; + zl = ctx->HL[lo]; -#if defined(MBEDTLS_AESCE_HAVE_CODE) - case MBEDTLS_GCM_ACC_AESCE: - mbedtls_aesce_gcm_mult(output, x, (uint8_t *) ctx->H[MBEDTLS_GCM_HTABLE_SIZE/2]); - break; -#endif + for( i = 15; i >= 0; i-- ) + { + lo = x[i] & 0xf; + hi = ( x[i] >> 4 ) & 0xf; -#if defined(MBEDTLS_GCM_LARGE_TABLE) - case MBEDTLS_GCM_ACC_LARGETABLE: - gcm_mult_largetable(output, x, ctx->H); - break; -#else - case MBEDTLS_GCM_ACC_SMALLTABLE: - gcm_mult_smalltable(output, x, ctx->H); - break; -#endif + if( i != 15 ) + { + rem = (unsigned char) zl & 0xf; + zl = ( zh << 60 ) | ( zl >> 4 ); + zh = ( zh >> 4 ); + zh ^= (uint64_t) last4[rem] << 48; + zh ^= ctx->HH[lo]; + zl ^= ctx->HL[lo]; + + } + + rem = (unsigned char) zl & 0xf; + zl = ( zh << 60 ) | ( zl >> 4 ); + zh = ( zh >> 4 ); + zh ^= (uint64_t) last4[rem] << 48; + zh ^= ctx->HH[hi]; + zl ^= ctx->HL[hi]; } - return; + MBEDTLS_PUT_UINT32_BE( zh >> 32, output, 0 ); + MBEDTLS_PUT_UINT32_BE( zh, output, 4 ); + MBEDTLS_PUT_UINT32_BE( zl >> 32, output, 8 ); + MBEDTLS_PUT_UINT32_BE( zl, output, 12 ); } -int mbedtls_gcm_starts(mbedtls_gcm_context *ctx, - int mode, - const unsigned char *iv, size_t iv_len) +int mbedtls_gcm_starts( mbedtls_gcm_context *ctx, + int mode, + const unsigned char *iv, size_t iv_len ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char work_buf[16]; + size_t i; const unsigned char *p; - size_t use_len; + size_t use_len, olen = 0; uint64_t iv_bits; -#if !defined(MBEDTLS_BLOCK_CIPHER_C) - size_t olen = 0; -#endif + + GCM_VALIDATE_RET( ctx != NULL ); + GCM_VALIDATE_RET( iv != NULL ); /* IV is limited to 2^64 bits, so 2^61 bytes */ /* IV is not allowed to be zero length */ - if (iv_len == 0 || (uint64_t) iv_len >> 61 != 0) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } + if( iv_len == 0 || (uint64_t) iv_len >> 61 != 0 ) + return( MBEDTLS_ERR_GCM_BAD_INPUT ); - memset(ctx->y, 0x00, sizeof(ctx->y)); - memset(ctx->buf, 0x00, sizeof(ctx->buf)); + memset( ctx->y, 0x00, sizeof(ctx->y) ); + memset( ctx->buf, 0x00, sizeof(ctx->buf) ); ctx->mode = mode; ctx->len = 0; ctx->add_len = 0; - if (iv_len == 12) { - memcpy(ctx->y, iv, iv_len); + if( iv_len == 12 ) + { + memcpy( ctx->y, iv, iv_len ); ctx->y[15] = 1; - } else { - memset(work_buf, 0x00, 16); - iv_bits = (uint64_t) iv_len * 8; - MBEDTLS_PUT_UINT64_BE(iv_bits, work_buf, 8); + } + else + { + memset( work_buf, 0x00, 16 ); + iv_bits = (uint64_t)iv_len * 8; + MBEDTLS_PUT_UINT64_BE( iv_bits, work_buf, 8 ); p = iv; - while (iv_len > 0) { - use_len = (iv_len < 16) ? iv_len : 16; + while( iv_len > 0 ) + { + use_len = ( iv_len < 16 ) ? iv_len : 16; -#if defined(MBEDTLS_COMPILER_IS_GCC) && (MBEDTLS_GCC_VERSION >= 70110) -#pragma GCC diagnostic push -#pragma GCC diagnostic warning "-Wstringop-overflow=0" -#endif - - mbedtls_xor(ctx->y, ctx->y, p, use_len); + for( i = 0; i < use_len; i++ ) + ctx->y[i] ^= p[i]; -#if defined(MBEDTLS_COMPILER_IS_GCC) && (MBEDTLS_GCC_VERSION >= 70110) -#pragma GCC diagnostic pop -#endif - - gcm_mult(ctx, ctx->y, ctx->y); + gcm_mult( ctx, ctx->y, ctx->y ); iv_len -= use_len; p += use_len; } - mbedtls_xor(ctx->y, ctx->y, work_buf, 16); + for( i = 0; i < 16; i++ ) + ctx->y[i] ^= work_buf[i]; - gcm_mult(ctx, ctx->y, ctx->y); + gcm_mult( ctx, ctx->y, ctx->y ); } - -#if defined(MBEDTLS_BLOCK_CIPHER_C) - ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ctx->base_ectr); -#else - ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ctx->base_ectr, &olen); -#endif - if (ret != 0) { - return ret; + if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctx->y, 16, + ctx->base_ectr, &olen ) ) != 0 ) + { + return( ret ); } - return 0; + return( 0 ); } /** @@ -464,39 +328,32 @@ int mbedtls_gcm_starts(mbedtls_gcm_context *ctx, * * len > 0 && len % 16 == 0: the authentication tag is correct if * the data ends now. */ -int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx, - const unsigned char *add, size_t add_len) +int mbedtls_gcm_update_ad( mbedtls_gcm_context *ctx, + const unsigned char *add, size_t add_len ) { const unsigned char *p; - size_t use_len, offset; - uint64_t new_add_len; + size_t use_len, i, offset; - /* AD is limited to 2^64 bits, ie 2^61 bytes - * Also check for possible overflow */ -#if SIZE_MAX > 0xFFFFFFFFFFFFFFFFULL - if (add_len > 0xFFFFFFFFFFFFFFFFULL) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } -#endif - new_add_len = ctx->add_len + (uint64_t) add_len; - if (new_add_len < ctx->add_len || new_add_len >> 61 != 0) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } + GCM_VALIDATE_RET( add_len == 0 || add != NULL ); + + /* IV is limited to 2^64 bits, so 2^61 bytes */ + if( (uint64_t) add_len >> 61 != 0 ) + return( MBEDTLS_ERR_GCM_BAD_INPUT ); offset = ctx->add_len % 16; p = add; - if (offset != 0) { + if( offset != 0 ) + { use_len = 16 - offset; - if (use_len > add_len) { + if( use_len > add_len ) use_len = add_len; - } - mbedtls_xor(ctx->buf + offset, ctx->buf + offset, p, use_len); + for( i = 0; i < use_len; i++ ) + ctx->buf[i+offset] ^= p[i]; - if (offset + use_len == 16) { - gcm_mult(ctx, ctx->buf, ctx->buf); - } + if( offset + use_len == 16 ) + gcm_mult( ctx, ctx->buf, ctx->buf ); ctx->add_len += use_len; add_len -= use_len; @@ -505,115 +362,120 @@ int mbedtls_gcm_update_ad(mbedtls_gcm_context *ctx, ctx->add_len += add_len; - while (add_len >= 16) { - mbedtls_xor(ctx->buf, ctx->buf, p, 16); + while( add_len >= 16 ) + { + for( i = 0; i < 16; i++ ) + ctx->buf[i] ^= p[i]; - gcm_mult(ctx, ctx->buf, ctx->buf); + gcm_mult( ctx, ctx->buf, ctx->buf ); add_len -= 16; p += 16; } - if (add_len > 0) { - mbedtls_xor(ctx->buf, ctx->buf, p, add_len); + if( add_len > 0 ) + { + for( i = 0; i < add_len; i++ ) + ctx->buf[i] ^= p[i]; } - return 0; + return( 0 ); } /* Increment the counter. */ -static void gcm_incr(unsigned char y[16]) +static void gcm_incr( unsigned char y[16] ) { - uint32_t x = MBEDTLS_GET_UINT32_BE(y, 12); - x++; - MBEDTLS_PUT_UINT32_BE(x, y, 12); + size_t i; + for( i = 16; i > 12; i-- ) + if( ++y[i - 1] != 0 ) + break; } /* Calculate and apply the encryption mask. Process use_len bytes of data, * starting at position offset in the mask block. */ -static int gcm_mask(mbedtls_gcm_context *ctx, - unsigned char ectr[16], - size_t offset, size_t use_len, - const unsigned char *input, - unsigned char *output) +static int gcm_mask( mbedtls_gcm_context *ctx, + unsigned char ectr[16], + size_t offset, size_t use_len, + const unsigned char *input, + unsigned char *output ) { + size_t i; + size_t olen = 0; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; -#if defined(MBEDTLS_BLOCK_CIPHER_C) - ret = mbedtls_block_cipher_encrypt(&ctx->block_cipher_ctx, ctx->y, ectr); -#else - size_t olen = 0; - ret = mbedtls_cipher_update(&ctx->cipher_ctx, ctx->y, 16, ectr, &olen); -#endif - if (ret != 0) { - mbedtls_platform_zeroize(ectr, 16); - return ret; + if( ( ret = mbedtls_cipher_update( &ctx->cipher_ctx, ctx->y, 16, ectr, + &olen ) ) != 0 ) + { + mbedtls_platform_zeroize( ectr, 16 ); + return( ret ); } - if (ctx->mode == MBEDTLS_GCM_DECRYPT) { - mbedtls_xor(ctx->buf + offset, ctx->buf + offset, input, use_len); - } - mbedtls_xor(output, ectr + offset, input, use_len); - if (ctx->mode == MBEDTLS_GCM_ENCRYPT) { - mbedtls_xor(ctx->buf + offset, ctx->buf + offset, output, use_len); + for( i = 0; i < use_len; i++ ) + { + if( ctx->mode == MBEDTLS_GCM_DECRYPT ) + ctx->buf[offset + i] ^= input[i]; + output[i] = ectr[offset + i] ^ input[i]; + if( ctx->mode == MBEDTLS_GCM_ENCRYPT ) + ctx->buf[offset + i] ^= output[i]; } - - return 0; + return( 0 ); } -int mbedtls_gcm_update(mbedtls_gcm_context *ctx, - const unsigned char *input, size_t input_length, - unsigned char *output, size_t output_size, - size_t *output_length) +int mbedtls_gcm_update( mbedtls_gcm_context *ctx, + const unsigned char *input, size_t input_length, + unsigned char *output, size_t output_size, + size_t *output_length ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; const unsigned char *p = input; unsigned char *out_p = output; size_t offset; - unsigned char ectr[16] = { 0 }; + unsigned char ectr[16]; - if (output_size < input_length) { - return MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL; - } + if( output_size < input_length ) + return( MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL ); + GCM_VALIDATE_RET( output_length != NULL ); *output_length = input_length; /* Exit early if input_length==0 so that we don't do any pointer arithmetic * on a potentially null pointer. * Returning early also means that the last partial block of AD remains * untouched for mbedtls_gcm_finish */ - if (input_length == 0) { - return 0; - } + if( input_length == 0 ) + return( 0 ); - if (output > input && (size_t) (output - input) < input_length) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } + GCM_VALIDATE_RET( ctx != NULL ); + GCM_VALIDATE_RET( input != NULL ); + GCM_VALIDATE_RET( output != NULL ); + + if( output > input && (size_t) ( output - input ) < input_length ) + return( MBEDTLS_ERR_GCM_BAD_INPUT ); /* Total length is restricted to 2^39 - 256 bits, ie 2^36 - 2^5 bytes * Also check for possible overflow */ - if (ctx->len + input_length < ctx->len || - (uint64_t) ctx->len + input_length > 0xFFFFFFFE0ull) { - return MBEDTLS_ERR_GCM_BAD_INPUT; + if( ctx->len + input_length < ctx->len || + (uint64_t) ctx->len + input_length > 0xFFFFFFFE0ull ) + { + return( MBEDTLS_ERR_GCM_BAD_INPUT ); } - if (ctx->len == 0 && ctx->add_len % 16 != 0) { - gcm_mult(ctx, ctx->buf, ctx->buf); + if( ctx->len == 0 && ctx->add_len % 16 != 0 ) + { + gcm_mult( ctx, ctx->buf, ctx->buf ); } offset = ctx->len % 16; - if (offset != 0) { + if( offset != 0 ) + { size_t use_len = 16 - offset; - if (use_len > input_length) { + if( use_len > input_length ) use_len = input_length; - } - if ((ret = gcm_mask(ctx, ectr, offset, use_len, p, out_p)) != 0) { - return ret; - } + if( ( ret = gcm_mask( ctx, ectr, offset, use_len, p, out_p ) ) != 0 ) + return( ret ); - if (offset + use_len == 16) { - gcm_mult(ctx, ctx->buf, ctx->buf); - } + if( offset + use_len == 16 ) + gcm_mult( ctx, ctx->buf, ctx->buf ); ctx->len += use_len; input_length -= use_len; @@ -623,166 +485,178 @@ int mbedtls_gcm_update(mbedtls_gcm_context *ctx, ctx->len += input_length; - while (input_length >= 16) { - gcm_incr(ctx->y); - if ((ret = gcm_mask(ctx, ectr, 0, 16, p, out_p)) != 0) { - return ret; - } + while( input_length >= 16 ) + { + gcm_incr( ctx->y ); + if( ( ret = gcm_mask( ctx, ectr, 0, 16, p, out_p ) ) != 0 ) + return( ret ); - gcm_mult(ctx, ctx->buf, ctx->buf); + gcm_mult( ctx, ctx->buf, ctx->buf ); input_length -= 16; p += 16; out_p += 16; } - if (input_length > 0) { - gcm_incr(ctx->y); - if ((ret = gcm_mask(ctx, ectr, 0, input_length, p, out_p)) != 0) { - return ret; - } + if( input_length > 0 ) + { + gcm_incr( ctx->y ); + if( ( ret = gcm_mask( ctx, ectr, 0, input_length, p, out_p ) ) != 0 ) + return( ret ); } - mbedtls_platform_zeroize(ectr, sizeof(ectr)); - return 0; + mbedtls_platform_zeroize( ectr, sizeof( ectr ) ); + return( 0 ); } -int mbedtls_gcm_finish(mbedtls_gcm_context *ctx, - unsigned char *output, size_t output_size, - size_t *output_length, - unsigned char *tag, size_t tag_len) +int mbedtls_gcm_finish( mbedtls_gcm_context *ctx, + unsigned char *output, size_t output_size, + size_t *output_length, + unsigned char *tag, size_t tag_len ) { unsigned char work_buf[16]; + size_t i; uint64_t orig_len; uint64_t orig_add_len; + GCM_VALIDATE_RET( ctx != NULL ); + GCM_VALIDATE_RET( tag != NULL ); + /* We never pass any output in finish(). The output parameter exists only * for the sake of alternative implementations. */ (void) output; (void) output_size; *output_length = 0; - /* Total length is restricted to 2^39 - 256 bits, ie 2^36 - 2^5 bytes - * and AD length is restricted to 2^64 bits, ie 2^61 bytes so neither of - * the two multiplications would overflow. */ orig_len = ctx->len * 8; orig_add_len = ctx->add_len * 8; - if (ctx->len == 0 && ctx->add_len % 16 != 0) { - gcm_mult(ctx, ctx->buf, ctx->buf); + if( ctx->len == 0 && ctx->add_len % 16 != 0 ) + { + gcm_mult( ctx, ctx->buf, ctx->buf ); } - if (tag_len > 16 || tag_len < 4) { - return MBEDTLS_ERR_GCM_BAD_INPUT; - } + if( tag_len > 16 || tag_len < 4 ) + return( MBEDTLS_ERR_GCM_BAD_INPUT ); - if (ctx->len % 16 != 0) { - gcm_mult(ctx, ctx->buf, ctx->buf); - } + if( ctx->len % 16 != 0 ) + gcm_mult( ctx, ctx->buf, ctx->buf ); - memcpy(tag, ctx->base_ectr, tag_len); + memcpy( tag, ctx->base_ectr, tag_len ); - if (orig_len || orig_add_len) { - memset(work_buf, 0x00, 16); + if( orig_len || orig_add_len ) + { + memset( work_buf, 0x00, 16 ); - MBEDTLS_PUT_UINT32_BE((orig_add_len >> 32), work_buf, 0); - MBEDTLS_PUT_UINT32_BE((orig_add_len), work_buf, 4); - MBEDTLS_PUT_UINT32_BE((orig_len >> 32), work_buf, 8); - MBEDTLS_PUT_UINT32_BE((orig_len), work_buf, 12); + MBEDTLS_PUT_UINT32_BE( ( orig_add_len >> 32 ), work_buf, 0 ); + MBEDTLS_PUT_UINT32_BE( ( orig_add_len ), work_buf, 4 ); + MBEDTLS_PUT_UINT32_BE( ( orig_len >> 32 ), work_buf, 8 ); + MBEDTLS_PUT_UINT32_BE( ( orig_len ), work_buf, 12 ); - mbedtls_xor(ctx->buf, ctx->buf, work_buf, 16); + for( i = 0; i < 16; i++ ) + ctx->buf[i] ^= work_buf[i]; - gcm_mult(ctx, ctx->buf, ctx->buf); + gcm_mult( ctx, ctx->buf, ctx->buf ); - mbedtls_xor(tag, tag, ctx->buf, tag_len); + for( i = 0; i < tag_len; i++ ) + tag[i] ^= ctx->buf[i]; } - return 0; + return( 0 ); } -int mbedtls_gcm_crypt_and_tag(mbedtls_gcm_context *ctx, - int mode, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *input, - unsigned char *output, - size_t tag_len, - unsigned char *tag) +int mbedtls_gcm_crypt_and_tag( mbedtls_gcm_context *ctx, + int mode, + size_t length, + const unsigned char *iv, + size_t iv_len, + const unsigned char *add, + size_t add_len, + const unsigned char *input, + unsigned char *output, + size_t tag_len, + unsigned char *tag ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t olen; - if ((ret = mbedtls_gcm_starts(ctx, mode, iv, iv_len)) != 0) { - return ret; - } + GCM_VALIDATE_RET( ctx != NULL ); + GCM_VALIDATE_RET( iv != NULL ); + GCM_VALIDATE_RET( add_len == 0 || add != NULL ); + GCM_VALIDATE_RET( length == 0 || input != NULL ); + GCM_VALIDATE_RET( length == 0 || output != NULL ); + GCM_VALIDATE_RET( tag != NULL ); - if ((ret = mbedtls_gcm_update_ad(ctx, add, add_len)) != 0) { - return ret; - } + if( ( ret = mbedtls_gcm_starts( ctx, mode, iv, iv_len ) ) != 0 ) + return( ret ); - if ((ret = mbedtls_gcm_update(ctx, input, length, - output, length, &olen)) != 0) { - return ret; - } + if( ( ret = mbedtls_gcm_update_ad( ctx, add, add_len ) ) != 0 ) + return( ret ); - if ((ret = mbedtls_gcm_finish(ctx, NULL, 0, &olen, tag, tag_len)) != 0) { - return ret; - } + if( ( ret = mbedtls_gcm_update( ctx, input, length, + output, length, &olen ) ) != 0 ) + return( ret ); + + if( ( ret = mbedtls_gcm_finish( ctx, NULL, 0, &olen, tag, tag_len ) ) != 0 ) + return( ret ); - return 0; + return( 0 ); } -int mbedtls_gcm_auth_decrypt(mbedtls_gcm_context *ctx, - size_t length, - const unsigned char *iv, - size_t iv_len, - const unsigned char *add, - size_t add_len, - const unsigned char *tag, - size_t tag_len, - const unsigned char *input, - unsigned char *output) +int mbedtls_gcm_auth_decrypt( mbedtls_gcm_context *ctx, + size_t length, + const unsigned char *iv, + size_t iv_len, + const unsigned char *add, + size_t add_len, + const unsigned char *tag, + size_t tag_len, + const unsigned char *input, + unsigned char *output ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char check_tag[16]; + size_t i; int diff; - if ((ret = mbedtls_gcm_crypt_and_tag(ctx, MBEDTLS_GCM_DECRYPT, length, - iv, iv_len, add, add_len, - input, output, tag_len, check_tag)) != 0) { - return ret; + GCM_VALIDATE_RET( ctx != NULL ); + GCM_VALIDATE_RET( iv != NULL ); + GCM_VALIDATE_RET( add_len == 0 || add != NULL ); + GCM_VALIDATE_RET( tag != NULL ); + GCM_VALIDATE_RET( length == 0 || input != NULL ); + GCM_VALIDATE_RET( length == 0 || output != NULL ); + + if( ( ret = mbedtls_gcm_crypt_and_tag( ctx, MBEDTLS_GCM_DECRYPT, length, + iv, iv_len, add, add_len, + input, output, tag_len, check_tag ) ) != 0 ) + { + return( ret ); } /* Check tag in "constant-time" */ - diff = mbedtls_ct_memcmp(tag, check_tag, tag_len); + for( diff = 0, i = 0; i < tag_len; i++ ) + diff |= tag[i] ^ check_tag[i]; - if (diff != 0) { - mbedtls_platform_zeroize(output, length); - return MBEDTLS_ERR_GCM_AUTH_FAILED; + if( diff != 0 ) + { + mbedtls_platform_zeroize( output, length ); + return( MBEDTLS_ERR_GCM_AUTH_FAILED ); } - return 0; + return( 0 ); } -void mbedtls_gcm_free(mbedtls_gcm_context *ctx) +void mbedtls_gcm_free( mbedtls_gcm_context *ctx ) { - if (ctx == NULL) { + if( ctx == NULL ) return; - } -#if defined(MBEDTLS_BLOCK_CIPHER_C) - mbedtls_block_cipher_free(&ctx->block_cipher_ctx); -#else - mbedtls_cipher_free(&ctx->cipher_ctx); -#endif - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_gcm_context)); + mbedtls_cipher_free( &ctx->cipher_ctx ); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_gcm_context ) ); } #endif /* !MBEDTLS_GCM_ALT */ -#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_CCM_GCM_CAN_AES) +#if defined(MBEDTLS_SELF_TEST) && defined(MBEDTLS_AES_C) /* * AES-GCM test vectors from: * @@ -791,9 +665,9 @@ void mbedtls_gcm_free(mbedtls_gcm_context *ctx) #define MAX_TESTS 6 static const int key_index_test_data[MAX_TESTS] = -{ 0, 0, 1, 1, 1, 1 }; + { 0, 0, 1, 1, 1, 1 }; -static const unsigned char key_test_data[][32] = +static const unsigned char key_test_data[MAX_TESTS][32] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -806,12 +680,12 @@ static const unsigned char key_test_data[][32] = }; static const size_t iv_len_test_data[MAX_TESTS] = -{ 12, 12, 12, 12, 8, 60 }; + { 12, 12, 12, 12, 8, 60 }; static const int iv_index_test_data[MAX_TESTS] = -{ 0, 0, 1, 1, 1, 2 }; + { 0, 0, 1, 1, 1, 2 }; -static const unsigned char iv_test_data[][64] = +static const unsigned char iv_test_data[MAX_TESTS][64] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, @@ -828,12 +702,12 @@ static const unsigned char iv_test_data[][64] = }; static const size_t add_len_test_data[MAX_TESTS] = -{ 0, 0, 0, 20, 20, 20 }; + { 0, 0, 0, 20, 20, 20 }; static const int add_index_test_data[MAX_TESTS] = -{ 0, 0, 0, 1, 1, 1 }; + { 0, 0, 0, 1, 1, 1 }; -static const unsigned char additional_test_data[][64] = +static const unsigned char additional_test_data[MAX_TESTS][64] = { { 0x00 }, { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, @@ -842,12 +716,12 @@ static const unsigned char additional_test_data[][64] = }; static const size_t pt_len_test_data[MAX_TESTS] = -{ 0, 16, 64, 60, 60, 60 }; + { 0, 16, 64, 60, 60, 60 }; static const int pt_index_test_data[MAX_TESTS] = -{ 0, 0, 1, 1, 1, 1 }; + { 0, 0, 1, 1, 1, 1 }; -static const unsigned char pt_test_data[][64] = +static const unsigned char pt_test_data[MAX_TESTS][64] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, @@ -861,7 +735,7 @@ static const unsigned char pt_test_data[][64] = 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55 }, }; -static const unsigned char ct_test_data[][64] = +static const unsigned char ct_test_data[MAX_TESTS * 3][64] = { { 0x00 }, { 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, @@ -898,7 +772,6 @@ static const unsigned char ct_test_data[][64] = 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, 0x4c, 0x34, 0xae, 0xe5 }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { 0x00 }, { 0x98, 0xe7, 0x24, 0x7c, 0x07, 0xf0, 0xfe, 0x41, 0x1c, 0x26, 0x7e, 0x43, 0x84, 0xb0, 0xf6, 0x00 }, @@ -969,10 +842,9 @@ static const unsigned char ct_test_data[][64] = 0x2d, 0xa3, 0xeb, 0xf1, 0xc5, 0xd8, 0x2c, 0xde, 0xa2, 0x41, 0x89, 0x97, 0x20, 0x0e, 0xf8, 0x2e, 0x44, 0xae, 0x7e, 0x3f }, -#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */ }; -static const unsigned char tag_test_data[][16] = +static const unsigned char tag_test_data[MAX_TESTS * 3][16] = { { 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61, 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a }, @@ -986,7 +858,6 @@ static const unsigned char tag_test_data[][16] = 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb }, { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50 }, -#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) { 0xcd, 0x33, 0xb2, 0x8a, 0xc7, 0x73, 0xf7, 0x4b, 0xa0, 0x0e, 0xd1, 0xf3, 0x12, 0x57, 0x24, 0x35 }, { 0x2f, 0xf5, 0x8d, 0x80, 0x03, 0x39, 0x27, 0xab, @@ -1011,10 +882,9 @@ static const unsigned char tag_test_data[][16] = 0x5e, 0x45, 0x49, 0x13, 0xfe, 0x2e, 0xa8, 0xf2 }, { 0xa4, 0x4a, 0x82, 0x66, 0xee, 0x1c, 0x8e, 0xb0, 0xc8, 0xb5, 0xd4, 0xcf, 0x5a, 0xe9, 0xf1, 0x9a }, -#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */ }; -int mbedtls_gcm_self_test(int verbose) +int mbedtls_gcm_self_test( int verbose ) { mbedtls_gcm_context ctx; unsigned char buf[64]; @@ -1023,306 +893,267 @@ int mbedtls_gcm_self_test(int verbose) mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES; size_t olen; - if (verbose != 0) { -#if defined(MBEDTLS_GCM_ALT) - mbedtls_printf(" GCM note: alternative implementation.\n"); -#else /* MBEDTLS_GCM_ALT */ -#if defined(MBEDTLS_AESNI_HAVE_CODE) - if (mbedtls_aesni_has_support(MBEDTLS_AESNI_CLMUL)) { - mbedtls_printf(" GCM note: using AESNI.\n"); - } else -#endif - -#if defined(MBEDTLS_AESCE_HAVE_CODE) - if (MBEDTLS_AESCE_HAS_SUPPORT()) { - mbedtls_printf(" GCM note: using AESCE.\n"); - } else -#endif - - mbedtls_printf(" GCM note: built-in implementation.\n"); -#endif /* MBEDTLS_GCM_ALT */ - } - - static const int loop_limit = - (sizeof(ct_test_data) / sizeof(*ct_test_data)) / MAX_TESTS; - - for (j = 0; j < loop_limit; j++) { + for( j = 0; j < 3; j++ ) + { int key_len = 128 + 64 * j; - for (i = 0; i < MAX_TESTS; i++) { - if (verbose != 0) { - mbedtls_printf(" AES-GCM-%3d #%d (%s): ", - key_len, i, "enc"); - } + for( i = 0; i < MAX_TESTS; i++ ) + { + mbedtls_gcm_init( &ctx ); - mbedtls_gcm_init(&ctx); + if( verbose != 0 ) + mbedtls_printf( " AES-GCM-%3d #%d (%s): ", + key_len, i, "enc" ); - ret = mbedtls_gcm_setkey(&ctx, cipher, - key_test_data[key_index_test_data[i]], - key_len); + ret = mbedtls_gcm_setkey( &ctx, cipher, + key_test_data[key_index_test_data[i]], + key_len ); /* * AES-192 is an optional feature that may be unavailable when * there is an alternative underlying implementation i.e. when * MBEDTLS_AES_ALT is defined. */ - if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && key_len == 192) { - mbedtls_printf("skipped\n"); + if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && key_len == 192 ) + { + mbedtls_printf( "skipped\n" ); break; - } else if (ret != 0) { + } + else if( ret != 0 ) + { goto exit; } - ret = mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_ENCRYPT, - pt_len_test_data[i], - iv_test_data[iv_index_test_data[i]], - iv_len_test_data[i], - additional_test_data[add_index_test_data[i]], - add_len_test_data[i], - pt_test_data[pt_index_test_data[i]], - buf, 16, tag_buf); + ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, + pt_len_test_data[i], + iv_test_data[iv_index_test_data[i]], + iv_len_test_data[i], + additional_test_data[add_index_test_data[i]], + add_len_test_data[i], + pt_test_data[pt_index_test_data[i]], + buf, 16, tag_buf ); #if defined(MBEDTLS_GCM_ALT) /* Allow alternative implementations to only support 12-byte nonces. */ - if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && - iv_len_test_data[i] != 12) { - mbedtls_printf("skipped\n"); + if( ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && + iv_len_test_data[i] != 12 ) + { + mbedtls_printf( "skipped\n" ); break; } #endif /* defined(MBEDTLS_GCM_ALT) */ - if (ret != 0) { + if( ret != 0 ) goto exit; - } - if (memcmp(buf, ct_test_data[j * 6 + i], - pt_len_test_data[i]) != 0 || - memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) { + if ( memcmp( buf, ct_test_data[j * 6 + i], + pt_len_test_data[i] ) != 0 || + memcmp( tag_buf, tag_test_data[j * 6 + i], 16 ) != 0 ) + { ret = 1; goto exit; } - mbedtls_gcm_free(&ctx); + mbedtls_gcm_free( &ctx ); - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); - mbedtls_gcm_init(&ctx); + mbedtls_gcm_init( &ctx ); - if (verbose != 0) { - mbedtls_printf(" AES-GCM-%3d #%d (%s): ", - key_len, i, "dec"); - } + if( verbose != 0 ) + mbedtls_printf( " AES-GCM-%3d #%d (%s): ", + key_len, i, "dec" ); - ret = mbedtls_gcm_setkey(&ctx, cipher, - key_test_data[key_index_test_data[i]], - key_len); - if (ret != 0) { + ret = mbedtls_gcm_setkey( &ctx, cipher, + key_test_data[key_index_test_data[i]], + key_len ); + if( ret != 0 ) goto exit; - } - ret = mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_GCM_DECRYPT, - pt_len_test_data[i], - iv_test_data[iv_index_test_data[i]], - iv_len_test_data[i], - additional_test_data[add_index_test_data[i]], - add_len_test_data[i], - ct_test_data[j * 6 + i], buf, 16, tag_buf); + ret = mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_DECRYPT, + pt_len_test_data[i], + iv_test_data[iv_index_test_data[i]], + iv_len_test_data[i], + additional_test_data[add_index_test_data[i]], + add_len_test_data[i], + ct_test_data[j * 6 + i], buf, 16, tag_buf ); - if (ret != 0) { + if( ret != 0 ) goto exit; - } - if (memcmp(buf, pt_test_data[pt_index_test_data[i]], - pt_len_test_data[i]) != 0 || - memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) { + if( memcmp( buf, pt_test_data[pt_index_test_data[i]], + pt_len_test_data[i] ) != 0 || + memcmp( tag_buf, tag_test_data[j * 6 + i], 16 ) != 0 ) + { ret = 1; goto exit; } - mbedtls_gcm_free(&ctx); + mbedtls_gcm_free( &ctx ); - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); - mbedtls_gcm_init(&ctx); + mbedtls_gcm_init( &ctx ); - if (verbose != 0) { - mbedtls_printf(" AES-GCM-%3d #%d split (%s): ", - key_len, i, "enc"); - } + if( verbose != 0 ) + mbedtls_printf( " AES-GCM-%3d #%d split (%s): ", + key_len, i, "enc" ); - ret = mbedtls_gcm_setkey(&ctx, cipher, - key_test_data[key_index_test_data[i]], - key_len); - if (ret != 0) { + ret = mbedtls_gcm_setkey( &ctx, cipher, + key_test_data[key_index_test_data[i]], + key_len ); + if( ret != 0 ) goto exit; - } - ret = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_ENCRYPT, - iv_test_data[iv_index_test_data[i]], - iv_len_test_data[i]); - if (ret != 0) { + ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_ENCRYPT, + iv_test_data[iv_index_test_data[i]], + iv_len_test_data[i] ); + if( ret != 0 ) goto exit; - } - ret = mbedtls_gcm_update_ad(&ctx, - additional_test_data[add_index_test_data[i]], - add_len_test_data[i]); - if (ret != 0) { + ret = mbedtls_gcm_update_ad( &ctx, + additional_test_data[add_index_test_data[i]], + add_len_test_data[i] ); + if( ret != 0 ) goto exit; - } - if (pt_len_test_data[i] > 32) { + if( pt_len_test_data[i] > 32 ) + { size_t rest_len = pt_len_test_data[i] - 32; - ret = mbedtls_gcm_update(&ctx, - pt_test_data[pt_index_test_data[i]], - 32, - buf, sizeof(buf), &olen); - if (ret != 0) { + ret = mbedtls_gcm_update( &ctx, + pt_test_data[pt_index_test_data[i]], + 32, + buf, sizeof( buf ), &olen ); + if( ret != 0 ) goto exit; - } - if (olen != 32) { + if( olen != 32 ) goto exit; - } - ret = mbedtls_gcm_update(&ctx, - pt_test_data[pt_index_test_data[i]] + 32, - rest_len, - buf + 32, sizeof(buf) - 32, &olen); - if (ret != 0) { + ret = mbedtls_gcm_update( &ctx, + pt_test_data[pt_index_test_data[i]] + 32, + rest_len, + buf + 32, sizeof( buf ) - 32, &olen ); + if( ret != 0 ) goto exit; - } - if (olen != rest_len) { + if( olen != rest_len ) goto exit; - } - } else { - ret = mbedtls_gcm_update(&ctx, - pt_test_data[pt_index_test_data[i]], - pt_len_test_data[i], - buf, sizeof(buf), &olen); - if (ret != 0) { + } + else + { + ret = mbedtls_gcm_update( &ctx, + pt_test_data[pt_index_test_data[i]], + pt_len_test_data[i], + buf, sizeof( buf ), &olen ); + if( ret != 0 ) goto exit; - } - if (olen != pt_len_test_data[i]) { + if( olen != pt_len_test_data[i] ) goto exit; - } } - ret = mbedtls_gcm_finish(&ctx, NULL, 0, &olen, tag_buf, 16); - if (ret != 0) { + ret = mbedtls_gcm_finish( &ctx, NULL, 0, &olen, tag_buf, 16 ); + if( ret != 0 ) goto exit; - } - if (memcmp(buf, ct_test_data[j * 6 + i], - pt_len_test_data[i]) != 0 || - memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) { + if( memcmp( buf, ct_test_data[j * 6 + i], + pt_len_test_data[i] ) != 0 || + memcmp( tag_buf, tag_test_data[j * 6 + i], 16 ) != 0 ) + { ret = 1; goto exit; } - mbedtls_gcm_free(&ctx); + mbedtls_gcm_free( &ctx ); - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); - mbedtls_gcm_init(&ctx); + mbedtls_gcm_init( &ctx ); - if (verbose != 0) { - mbedtls_printf(" AES-GCM-%3d #%d split (%s): ", - key_len, i, "dec"); - } + if( verbose != 0 ) + mbedtls_printf( " AES-GCM-%3d #%d split (%s): ", + key_len, i, "dec" ); - ret = mbedtls_gcm_setkey(&ctx, cipher, - key_test_data[key_index_test_data[i]], - key_len); - if (ret != 0) { + ret = mbedtls_gcm_setkey( &ctx, cipher, + key_test_data[key_index_test_data[i]], + key_len ); + if( ret != 0 ) goto exit; - } - ret = mbedtls_gcm_starts(&ctx, MBEDTLS_GCM_DECRYPT, - iv_test_data[iv_index_test_data[i]], - iv_len_test_data[i]); - if (ret != 0) { + ret = mbedtls_gcm_starts( &ctx, MBEDTLS_GCM_DECRYPT, + iv_test_data[iv_index_test_data[i]], + iv_len_test_data[i] ); + if( ret != 0 ) goto exit; - } - ret = mbedtls_gcm_update_ad(&ctx, - additional_test_data[add_index_test_data[i]], - add_len_test_data[i]); - if (ret != 0) { + ret = mbedtls_gcm_update_ad( &ctx, + additional_test_data[add_index_test_data[i]], + add_len_test_data[i] ); + if( ret != 0 ) goto exit; - } - if (pt_len_test_data[i] > 32) { + if( pt_len_test_data[i] > 32 ) + { size_t rest_len = pt_len_test_data[i] - 32; - ret = mbedtls_gcm_update(&ctx, - ct_test_data[j * 6 + i], 32, - buf, sizeof(buf), &olen); - if (ret != 0) { + ret = mbedtls_gcm_update( &ctx, + ct_test_data[j * 6 + i], 32, + buf, sizeof( buf ), &olen ); + if( ret != 0 ) goto exit; - } - if (olen != 32) { + if( olen != 32 ) goto exit; - } - ret = mbedtls_gcm_update(&ctx, - ct_test_data[j * 6 + i] + 32, - rest_len, - buf + 32, sizeof(buf) - 32, &olen); - if (ret != 0) { + ret = mbedtls_gcm_update( &ctx, + ct_test_data[j * 6 + i] + 32, + rest_len, + buf + 32, sizeof( buf ) - 32, &olen ); + if( ret != 0 ) goto exit; - } - if (olen != rest_len) { + if( olen != rest_len ) goto exit; - } - } else { - ret = mbedtls_gcm_update(&ctx, - ct_test_data[j * 6 + i], - pt_len_test_data[i], - buf, sizeof(buf), &olen); - if (ret != 0) { + } + else + { + ret = mbedtls_gcm_update( &ctx, + ct_test_data[j * 6 + i], + pt_len_test_data[i], + buf, sizeof( buf ), &olen ); + if( ret != 0 ) goto exit; - } - if (olen != pt_len_test_data[i]) { + if( olen != pt_len_test_data[i] ) goto exit; - } } - ret = mbedtls_gcm_finish(&ctx, NULL, 0, &olen, tag_buf, 16); - if (ret != 0) { + ret = mbedtls_gcm_finish( &ctx, NULL, 0, &olen, tag_buf, 16 ); + if( ret != 0 ) goto exit; - } - if (memcmp(buf, pt_test_data[pt_index_test_data[i]], - pt_len_test_data[i]) != 0 || - memcmp(tag_buf, tag_test_data[j * 6 + i], 16) != 0) { + if( memcmp( buf, pt_test_data[pt_index_test_data[i]], + pt_len_test_data[i] ) != 0 || + memcmp( tag_buf, tag_test_data[j * 6 + i], 16 ) != 0 ) + { ret = 1; goto exit; } - mbedtls_gcm_free(&ctx); + mbedtls_gcm_free( &ctx ); - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); } } - if (verbose != 0) { - mbedtls_printf("\n"); - } + if( verbose != 0 ) + mbedtls_printf( "\n" ); ret = 0; exit: - if (ret != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } - mbedtls_gcm_free(&ctx); + if( ret != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); + mbedtls_gcm_free( &ctx ); } - return ret; + return( ret ); } #endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C */ diff --git a/src/duckdb/third_party/mbedtls/library/md.cpp b/src/duckdb/third_party/mbedtls/library/md.cpp index 10c6844ad..56ca22971 100644 --- a/src/duckdb/third_party/mbedtls/library/md.cpp +++ b/src/duckdb/third_party/mbedtls/library/md.cpp @@ -1,57 +1,58 @@ /** * \file md.c * - * \brief Generic message digest wrapper for Mbed TLS + * \brief Generic message digest wrapper for mbed TLS * * \author Adriaan de Jong * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ - -#include "common.h" - -/* - * Availability of functions in this module is controlled by two - * feature macros: - * - MBEDTLS_MD_C enables the whole module; - * - MBEDTLS_MD_LIGHT enables only functions for hashing and accessing - * most hash metadata (everything except string names); is it - * automatically set whenever MBEDTLS_MD_C is defined. + * SPDX-License-Identifier: Apache-2.0 * - * In this file, functions from MD_LIGHT are at the top, MD_C at the end. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * In the future we may want to change the contract of some functions - * (behaviour with NULL arguments) depending on whether MD_C is defined or - * only MD_LIGHT. Also, the exact scope of MD_LIGHT might vary. + * http://www.apache.org/licenses/LICENSE-2.0 * - * For these reasons, we're keeping MD_LIGHT internal for now. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -#if defined(MBEDTLS_MD_LIGHT) + +#include "common.h" + +#if defined(MBEDTLS_MD_C) #include "mbedtls/md.h" #include "md_wrap.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" +#if defined(MBEDTLS_MD5_C) #include "mbedtls/md5.h" +#endif +#if defined(MBEDTLS_RIPEMD160_C) #include "mbedtls/ripemd160.h" +#endif +#if defined(MBEDTLS_SHA1_C) #include "mbedtls/sha1.h" +#endif +#if defined(MBEDTLS_SHA256_C) #include "mbedtls/sha256.h" -#include "mbedtls/sha512.h" -#include "mbedtls/sha3.h" - -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) -#include -#include "md_psa.h" -#include "psa_util_internal.h" #endif - -#if defined(MBEDTLS_MD_SOME_PSA) -#include "psa_crypto_core.h" +#if defined(MBEDTLS_SHA512_C) +#include "mbedtls/sha512.h" #endif +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#include +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif #include @@ -59,864 +60,539 @@ #include #endif -/* See comment above MBEDTLS_MD_MAX_SIZE in md.h */ -#if defined(MBEDTLS_PSA_CRYPTO_C) && MBEDTLS_MD_MAX_SIZE < PSA_HASH_MAX_SIZE -#error "Internal error: MBEDTLS_MD_MAX_SIZE < PSA_HASH_MAX_SIZE" +#if defined(MBEDTLS_MD5_C) +const mbedtls_md_info_t mbedtls_md5_info = { + "MD5", + MBEDTLS_MD_MD5, + 16, + 64, +}; #endif -#if defined(MBEDTLS_MD_C) -#define MD_INFO(type, out_size, block_size) type, out_size, block_size, -#else -#define MD_INFO(type, out_size, block_size) type, out_size, +#if defined(MBEDTLS_RIPEMD160_C) +const mbedtls_md_info_t mbedtls_ripemd160_info = { + "RIPEMD160", + MBEDTLS_MD_RIPEMD160, + 20, + 64, +}; #endif -#if defined(MBEDTLS_MD_CAN_MD5) -static const mbedtls_md_info_t mbedtls_md5_info = { - MD_INFO(MBEDTLS_MD_MD5, 16, 64) +#if defined(MBEDTLS_SHA1_C) +const mbedtls_md_info_t mbedtls_sha1_info = { + "SHA1", + MBEDTLS_MD_SHA1, + 20, + 64, }; #endif -#if defined(MBEDTLS_MD_CAN_RIPEMD160) -static const mbedtls_md_info_t mbedtls_ripemd160_info = { - MD_INFO(MBEDTLS_MD_RIPEMD160, 20, 64) +#if defined(MBEDTLS_SHA224_C) +const mbedtls_md_info_t mbedtls_sha224_info = { + "SHA224", + MBEDTLS_MD_SHA224, + 28, + 64, }; #endif -#if defined(MBEDTLS_MD_CAN_SHA1) -static const mbedtls_md_info_t mbedtls_sha1_info = { - MD_INFO(MBEDTLS_MD_SHA1, 20, 64) +#if defined(MBEDTLS_SHA256_C) +const mbedtls_md_info_t mbedtls_sha256_info = { + "SHA256", + MBEDTLS_MD_SHA256, + 32, + 64, }; #endif -#if defined(MBEDTLS_MD_CAN_SHA224) -static const mbedtls_md_info_t mbedtls_sha224_info = { - MD_INFO(MBEDTLS_MD_SHA224, 28, 64) +#if defined(MBEDTLS_SHA384_C) +const mbedtls_md_info_t mbedtls_sha384_info = { + "SHA384", + MBEDTLS_MD_SHA384, + 48, + 128, }; #endif -#if defined(MBEDTLS_MD_CAN_SHA256) -static const mbedtls_md_info_t mbedtls_sha256_info = { - MD_INFO(MBEDTLS_MD_SHA256, 32, 64) +#if defined(MBEDTLS_SHA512_C) +const mbedtls_md_info_t mbedtls_sha512_info = { + "SHA512", + MBEDTLS_MD_SHA512, + 64, + 128, }; #endif -#if defined(MBEDTLS_MD_CAN_SHA384) -static const mbedtls_md_info_t mbedtls_sha384_info = { - MD_INFO(MBEDTLS_MD_SHA384, 48, 128) -}; +/* + * Reminder: update profiles in x509_crt.c when adding a new hash! + */ +static const int supported_digests[] = { + +#if defined(MBEDTLS_SHA512_C) + MBEDTLS_MD_SHA512, #endif -#if defined(MBEDTLS_MD_CAN_SHA512) -static const mbedtls_md_info_t mbedtls_sha512_info = { - MD_INFO(MBEDTLS_MD_SHA512, 64, 128) -}; +#if defined(MBEDTLS_SHA384_C) + MBEDTLS_MD_SHA384, #endif -#if defined(MBEDTLS_MD_CAN_SHA3_224) -static const mbedtls_md_info_t mbedtls_sha3_224_info = { - MD_INFO(MBEDTLS_MD_SHA3_224, 28, 144) -}; +#if defined(MBEDTLS_SHA256_C) + MBEDTLS_MD_SHA256, +#endif +#if defined(MBEDTLS_SHA224_C) + MBEDTLS_MD_SHA224, #endif -#if defined(MBEDTLS_MD_CAN_SHA3_256) -static const mbedtls_md_info_t mbedtls_sha3_256_info = { - MD_INFO(MBEDTLS_MD_SHA3_256, 32, 136) -}; +#if defined(MBEDTLS_SHA1_C) + MBEDTLS_MD_SHA1, #endif -#if defined(MBEDTLS_MD_CAN_SHA3_384) -static const mbedtls_md_info_t mbedtls_sha3_384_info = { - MD_INFO(MBEDTLS_MD_SHA3_384, 48, 104) -}; +#if defined(MBEDTLS_RIPEMD160_C) + MBEDTLS_MD_RIPEMD160, #endif -#if defined(MBEDTLS_MD_CAN_SHA3_512) -static const mbedtls_md_info_t mbedtls_sha3_512_info = { - MD_INFO(MBEDTLS_MD_SHA3_512, 64, 72) -}; +#if defined(MBEDTLS_MD5_C) + MBEDTLS_MD_MD5, #endif -const mbedtls_md_info_t *mbedtls_md_info_from_type(mbedtls_md_type_t md_type) + MBEDTLS_MD_NONE +}; + +const int *mbedtls_md_list( void ) { - switch (md_type) { -#if defined(MBEDTLS_MD_CAN_MD5) - case MBEDTLS_MD_MD5: - return &mbedtls_md5_info; -#endif -#if defined(MBEDTLS_MD_CAN_RIPEMD160) - case MBEDTLS_MD_RIPEMD160: - return &mbedtls_ripemd160_info; -#endif -#if defined(MBEDTLS_MD_CAN_SHA1) - case MBEDTLS_MD_SHA1: - return &mbedtls_sha1_info; -#endif -#if defined(MBEDTLS_MD_CAN_SHA224) - case MBEDTLS_MD_SHA224: - return &mbedtls_sha224_info; -#endif -#if defined(MBEDTLS_MD_CAN_SHA256) - case MBEDTLS_MD_SHA256: - return &mbedtls_sha256_info; + return( supported_digests ); +} + +const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ) +{ + if( NULL == md_name ) + return( NULL ); + + /* Get the appropriate digest information */ +#if defined(MBEDTLS_MD5_C) + if( !strcmp( "MD5", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_MD5 ); #endif -#if defined(MBEDTLS_MD_CAN_SHA384) - case MBEDTLS_MD_SHA384: - return &mbedtls_sha384_info; +#if defined(MBEDTLS_RIPEMD160_C) + if( !strcmp( "RIPEMD160", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_RIPEMD160 ); #endif -#if defined(MBEDTLS_MD_CAN_SHA512) - case MBEDTLS_MD_SHA512: - return &mbedtls_sha512_info; +#if defined(MBEDTLS_SHA1_C) + if( !strcmp( "SHA1", md_name ) || !strcmp( "SHA", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_SHA1 ); #endif -#if defined(MBEDTLS_MD_CAN_SHA3_224) - case MBEDTLS_MD_SHA3_224: - return &mbedtls_sha3_224_info; +#if defined(MBEDTLS_SHA224_C) + if( !strcmp( "SHA224", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_SHA224 ); #endif -#if defined(MBEDTLS_MD_CAN_SHA3_256) - case MBEDTLS_MD_SHA3_256: - return &mbedtls_sha3_256_info; +#if defined(MBEDTLS_SHA256_C) + if( !strcmp( "SHA256", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ); #endif -#if defined(MBEDTLS_MD_CAN_SHA3_384) - case MBEDTLS_MD_SHA3_384: - return &mbedtls_sha3_384_info; +#if defined(MBEDTLS_SHA384_C) + if( !strcmp( "SHA384", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_SHA384 ); #endif -#if defined(MBEDTLS_MD_CAN_SHA3_512) - case MBEDTLS_MD_SHA3_512: - return &mbedtls_sha3_512_info; +#if defined(MBEDTLS_SHA512_C) + if( !strcmp( "SHA512", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 ); #endif - default: - return NULL; - } + return( NULL ); } -#if defined(MBEDTLS_MD_SOME_PSA) -static psa_algorithm_t psa_alg_of_md(const mbedtls_md_info_t *info) +const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type ) { - switch (info->type) { -#if defined(MBEDTLS_MD_MD5_VIA_PSA) + switch( md_type ) + { +#if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return PSA_ALG_MD5; + return( &mbedtls_md5_info ); #endif -#if defined(MBEDTLS_MD_RIPEMD160_VIA_PSA) +#if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return PSA_ALG_RIPEMD160; + return( &mbedtls_ripemd160_info ); #endif -#if defined(MBEDTLS_MD_SHA1_VIA_PSA) +#if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return PSA_ALG_SHA_1; + return( &mbedtls_sha1_info ); #endif -#if defined(MBEDTLS_MD_SHA224_VIA_PSA) +#if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return PSA_ALG_SHA_224; + return( &mbedtls_sha224_info ); #endif -#if defined(MBEDTLS_MD_SHA256_VIA_PSA) +#if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return PSA_ALG_SHA_256; + return( &mbedtls_sha256_info ); #endif -#if defined(MBEDTLS_MD_SHA384_VIA_PSA) +#if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return PSA_ALG_SHA_384; + return( &mbedtls_sha384_info ); #endif -#if defined(MBEDTLS_MD_SHA512_VIA_PSA) +#if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return PSA_ALG_SHA_512; -#endif -#if defined(MBEDTLS_MD_SHA3_224_VIA_PSA) - case MBEDTLS_MD_SHA3_224: - return PSA_ALG_SHA3_224; -#endif -#if defined(MBEDTLS_MD_SHA3_256_VIA_PSA) - case MBEDTLS_MD_SHA3_256: - return PSA_ALG_SHA3_256; -#endif -#if defined(MBEDTLS_MD_SHA3_384_VIA_PSA) - case MBEDTLS_MD_SHA3_384: - return PSA_ALG_SHA3_384; -#endif -#if defined(MBEDTLS_MD_SHA3_512_VIA_PSA) - case MBEDTLS_MD_SHA3_512: - return PSA_ALG_SHA3_512; + return( &mbedtls_sha512_info ); #endif default: - return PSA_ALG_NONE; + return( NULL ); } } -static int md_can_use_psa(const mbedtls_md_info_t *info) +void mbedtls_md_init( mbedtls_md_context_t *ctx ) { - psa_algorithm_t alg = psa_alg_of_md(info); - if (alg == PSA_ALG_NONE) { - return 0; - } - - return psa_can_do_hash(alg); + memset( ctx, 0, sizeof( mbedtls_md_context_t ) ); } -#endif /* MBEDTLS_MD_SOME_PSA */ -void mbedtls_md_init(mbedtls_md_context_t *ctx) +void mbedtls_md_free( mbedtls_md_context_t *ctx ) { - /* Note: this sets engine (if present) to MBEDTLS_MD_ENGINE_LEGACY */ - memset(ctx, 0, sizeof(mbedtls_md_context_t)); -} - -void mbedtls_md_free(mbedtls_md_context_t *ctx) -{ - if (ctx == NULL || ctx->md_info == NULL) { + if( ctx == NULL || ctx->md_info == NULL ) return; - } - if (ctx->md_ctx != NULL) { -#if defined(MBEDTLS_MD_SOME_PSA) - if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) { - psa_hash_abort(ctx->md_ctx); - } else -#endif - switch (ctx->md_info->type) { + if( ctx->md_ctx != NULL ) + { + switch( ctx->md_info->type ) + { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - mbedtls_md5_free(ctx->md_ctx); + mbedtls_md5_free( ctx->md_ctx ); break; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - mbedtls_ripemd160_free(ctx->md_ctx); + mbedtls_ripemd160_free( ctx->md_ctx ); break; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - mbedtls_sha1_free((mbedtls_sha1_context *)ctx->md_ctx); + mbedtls_sha1_free((mbedtls_sha1_context *) ctx->md_ctx ); break; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - mbedtls_sha256_free((mbedtls_sha256_context *)ctx->md_ctx); + mbedtls_sha256_free((mbedtls_sha256_context *) ctx->md_ctx ); break; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - mbedtls_sha256_free((mbedtls_sha256_context *)ctx->md_ctx); + mbedtls_sha256_free((mbedtls_sha256_context *) ctx->md_ctx ); break; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - mbedtls_sha512_free(ctx->md_ctx); + mbedtls_sha512_free( ctx->md_ctx ); break; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - mbedtls_sha512_free(ctx->md_ctx); - break; -#endif -#if defined(MBEDTLS_SHA3_C) - case MBEDTLS_MD_SHA3_224: - case MBEDTLS_MD_SHA3_256: - case MBEDTLS_MD_SHA3_384: - case MBEDTLS_MD_SHA3_512: - mbedtls_sha3_free(ctx->md_ctx); + mbedtls_sha512_free( ctx->md_ctx ); break; #endif default: /* Shouldn't happen */ break; } - mbedtls_free(ctx->md_ctx); + mbedtls_free( ctx->md_ctx ); } -#if defined(MBEDTLS_MD_C) - if (ctx->hmac_ctx != NULL) { - mbedtls_zeroize_and_free(ctx->hmac_ctx, - 2 * ctx->md_info->block_size); + if( ctx->hmac_ctx != NULL ) + { + mbedtls_platform_zeroize( ctx->hmac_ctx, + 2 * ctx->md_info->block_size ); + mbedtls_free( ctx->hmac_ctx ); } -#endif - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_md_context_t)); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_md_context_t ) ); } -int mbedtls_md_clone(mbedtls_md_context_t *dst, - const mbedtls_md_context_t *src) +int mbedtls_md_clone( mbedtls_md_context_t *dst, + const mbedtls_md_context_t *src ) { - if (dst == NULL || dst->md_info == NULL || + if( dst == NULL || dst->md_info == NULL || src == NULL || src->md_info == NULL || - dst->md_info != src->md_info) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; + dst->md_info != src->md_info ) + { + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } -#if defined(MBEDTLS_MD_SOME_PSA) - if (src->engine != dst->engine) { - /* This can happen with src set to legacy because PSA wasn't ready - * yet, and dst to PSA because it became ready in the meantime. - * We currently don't support that case (we'd need to re-allocate - * md_ctx to the size of the appropriate MD context). */ - return MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE; - } - - if (src->engine == MBEDTLS_MD_ENGINE_PSA) { - psa_status_t status = psa_hash_clone(src->md_ctx, dst->md_ctx); - return mbedtls_md_error_from_psa(status); - } -#endif - - switch (src->md_info->type) { + switch( src->md_info->type ) + { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - mbedtls_md5_clone(dst->md_ctx, src->md_ctx); + mbedtls_md5_clone( dst->md_ctx, src->md_ctx ); break; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - mbedtls_ripemd160_clone(dst->md_ctx, src->md_ctx); + mbedtls_ripemd160_clone( dst->md_ctx, src->md_ctx ); break; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - mbedtls_sha1_clone((mbedtls_sha1_context *)dst->md_ctx, (mbedtls_sha1_context *)src->md_ctx); + mbedtls_sha1_clone((mbedtls_sha1_context *) dst->md_ctx, (mbedtls_sha1_context *)src->md_ctx ); break; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - mbedtls_sha256_clone((mbedtls_sha256_context *)dst->md_ctx, (mbedtls_sha256_context *)src->md_ctx); + mbedtls_sha256_clone((mbedtls_sha256_context *) dst->md_ctx, (mbedtls_sha256_context *) src->md_ctx ); break; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - mbedtls_sha256_clone((mbedtls_sha256_context *)dst->md_ctx, (mbedtls_sha256_context *)src->md_ctx); + mbedtls_sha256_clone((mbedtls_sha256_context *) dst->md_ctx, (mbedtls_sha256_context *)src->md_ctx ); break; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - mbedtls_sha512_clone(dst->md_ctx, src->md_ctx); + mbedtls_sha512_clone( dst->md_ctx, src->md_ctx ); break; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - mbedtls_sha512_clone(dst->md_ctx, src->md_ctx); - break; -#endif -#if defined(MBEDTLS_SHA3_C) - case MBEDTLS_MD_SHA3_224: - case MBEDTLS_MD_SHA3_256: - case MBEDTLS_MD_SHA3_384: - case MBEDTLS_MD_SHA3_512: - mbedtls_sha3_clone(dst->md_ctx, src->md_ctx); + mbedtls_sha512_clone( dst->md_ctx, src->md_ctx ); break; #endif default: - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } - return 0; + return( 0 ); } -#define ALLOC(type) \ +#define ALLOC( type ) \ do { \ - ctx->md_ctx = (mbedtls_##type##_context*) mbedtls_calloc(1, sizeof(mbedtls_##type##_context)); \ - if (ctx->md_ctx == NULL) \ - return MBEDTLS_ERR_MD_ALLOC_FAILED; \ - mbedtls_##type##_init((mbedtls_##type##_context*)ctx->md_ctx); \ + ctx->md_ctx = (mbedtls_##type##_context*) mbedtls_calloc( 1, sizeof( mbedtls_##type##_context ) ); \ + if( ctx->md_ctx == NULL ) \ + return( MBEDTLS_ERR_MD_ALLOC_FAILED ); \ + mbedtls_##type##_init((mbedtls_##type##_context*) ctx->md_ctx ); \ } \ - while (0) + while( 0 ) -int mbedtls_md_setup(mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac) +int mbedtls_md_setup( mbedtls_md_context_t *ctx, const mbedtls_md_info_t *md_info, int hmac ) { -#if defined(MBEDTLS_MD_C) - if (ctx == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } -#endif - if (md_info == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } + if( md_info == NULL || ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); ctx->md_info = md_info; ctx->md_ctx = NULL; -#if defined(MBEDTLS_MD_C) ctx->hmac_ctx = NULL; -#else - if (hmac != 0) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } -#endif -#if defined(MBEDTLS_MD_SOME_PSA) - if (md_can_use_psa(ctx->md_info)) { - ctx->md_ctx = mbedtls_calloc(1, sizeof(psa_hash_operation_t)); - if (ctx->md_ctx == NULL) { - return MBEDTLS_ERR_MD_ALLOC_FAILED; - } - ctx->engine = MBEDTLS_MD_ENGINE_PSA; - } else -#endif - switch (md_info->type) { + switch( md_info->type ) + { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - ALLOC(md5); + ALLOC( md5 ); break; #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - ALLOC(ripemd160); + ALLOC( ripemd160 ); break; #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - ALLOC(sha1); + ALLOC( sha1 ); break; #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - ALLOC(sha256); + ALLOC( sha256 ); break; #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - ALLOC(sha256); + ALLOC( sha256 ); break; #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - ALLOC(sha512); + ALLOC( sha512 ); break; #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - ALLOC(sha512); - break; -#endif -#if defined(MBEDTLS_SHA3_C) - case MBEDTLS_MD_SHA3_224: - case MBEDTLS_MD_SHA3_256: - case MBEDTLS_MD_SHA3_384: - case MBEDTLS_MD_SHA3_512: - ALLOC(sha3); + ALLOC( sha512 ); break; #endif default: - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } -#if defined(MBEDTLS_MD_C) - if (hmac != 0) { - ctx->hmac_ctx = mbedtls_calloc(2, md_info->block_size); - if (ctx->hmac_ctx == NULL) { - mbedtls_md_free(ctx); - return MBEDTLS_ERR_MD_ALLOC_FAILED; + if( hmac != 0 ) + { + ctx->hmac_ctx = mbedtls_calloc( 2, md_info->block_size ); + if( ctx->hmac_ctx == NULL ) + { + mbedtls_md_free( ctx ); + return( MBEDTLS_ERR_MD_ALLOC_FAILED ); } } -#endif - return 0; + return( 0 ); } #undef ALLOC -int mbedtls_md_starts(mbedtls_md_context_t *ctx) +int mbedtls_md_starts( mbedtls_md_context_t *ctx ) { -#if defined(MBEDTLS_MD_C) - if (ctx == NULL || ctx->md_info == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } -#endif + if( ctx == NULL || ctx->md_info == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); -#if defined(MBEDTLS_MD_SOME_PSA) - if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) { - psa_algorithm_t alg = psa_alg_of_md(ctx->md_info); - psa_hash_abort(ctx->md_ctx); - psa_status_t status = psa_hash_setup(ctx->md_ctx, alg); - return mbedtls_md_error_from_psa(status); - } -#endif - - switch (ctx->md_info->type) { + switch( ctx->md_info->type ) + { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return mbedtls_md5_starts(ctx->md_ctx); + return( mbedtls_md5_starts( ctx->md_ctx ) ); #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return mbedtls_ripemd160_starts(ctx->md_ctx); + return( mbedtls_ripemd160_starts( ctx->md_ctx ) ); #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return mbedtls_sha1_starts((mbedtls_sha1_context *)ctx->md_ctx); + return( mbedtls_sha1_starts( (mbedtls_sha1_context *)ctx->md_ctx ) ); #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return mbedtls_sha256_starts((mbedtls_sha256_context *)ctx->md_ctx, 1); + return( mbedtls_sha256_starts( (mbedtls_sha256_context *)ctx->md_ctx, 1 ) ); #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return mbedtls_sha256_starts((mbedtls_sha256_context *)ctx->md_ctx, 0); + return( mbedtls_sha256_starts( (mbedtls_sha256_context *) ctx->md_ctx, 0 ) ); #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return mbedtls_sha512_starts(ctx->md_ctx, 1); + return( mbedtls_sha512_starts( ctx->md_ctx, 1 ) ); #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return mbedtls_sha512_starts(ctx->md_ctx, 0); -#endif -#if defined(MBEDTLS_SHA3_C) - case MBEDTLS_MD_SHA3_224: - return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_224); - case MBEDTLS_MD_SHA3_256: - return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_256); - case MBEDTLS_MD_SHA3_384: - return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_384); - case MBEDTLS_MD_SHA3_512: - return mbedtls_sha3_starts(ctx->md_ctx, MBEDTLS_SHA3_512); + return( mbedtls_sha512_starts( ctx->md_ctx, 0 ) ); #endif default: - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } } -int mbedtls_md_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen) +int mbedtls_md_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) { -#if defined(MBEDTLS_MD_C) - if (ctx == NULL || ctx->md_info == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } -#endif + if( ctx == NULL || ctx->md_info == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); -#if defined(MBEDTLS_MD_SOME_PSA) - if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) { - psa_status_t status = psa_hash_update(ctx->md_ctx, input, ilen); - return mbedtls_md_error_from_psa(status); - } -#endif - - switch (ctx->md_info->type) { + switch( ctx->md_info->type ) + { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return mbedtls_md5_update(ctx->md_ctx, input, ilen); + return( mbedtls_md5_update( ctx->md_ctx, input, ilen ) ); #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return mbedtls_ripemd160_update(ctx->md_ctx, input, ilen); + return( mbedtls_ripemd160_update( ctx->md_ctx, input, ilen ) ); #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return mbedtls_sha1_update((mbedtls_sha1_context *)ctx->md_ctx, input, ilen); + return( mbedtls_sha1_update( (mbedtls_sha1_context *)ctx->md_ctx, input, ilen ) ); #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return mbedtls_sha256_update((mbedtls_sha256_context *)ctx->md_ctx, input, ilen); + return( mbedtls_sha256_update( (mbedtls_sha256_context *)ctx->md_ctx, input, ilen ) ); #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return mbedtls_sha256_update((mbedtls_sha256_context *)ctx->md_ctx, input, ilen); + return( mbedtls_sha256_update( (mbedtls_sha256_context *)ctx->md_ctx, input, ilen ) ); #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return mbedtls_sha512_update(ctx->md_ctx, input, ilen); + return( mbedtls_sha512_update( ctx->md_ctx, input, ilen ) ); #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return mbedtls_sha512_update(ctx->md_ctx, input, ilen); -#endif -#if defined(MBEDTLS_SHA3_C) - case MBEDTLS_MD_SHA3_224: - case MBEDTLS_MD_SHA3_256: - case MBEDTLS_MD_SHA3_384: - case MBEDTLS_MD_SHA3_512: - return mbedtls_sha3_update(ctx->md_ctx, input, ilen); + return( mbedtls_sha512_update( ctx->md_ctx, input, ilen ) ); #endif default: - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } } -int mbedtls_md_finish(mbedtls_md_context_t *ctx, unsigned char *output) +int mbedtls_md_finish( mbedtls_md_context_t *ctx, unsigned char *output ) { -#if defined(MBEDTLS_MD_C) - if (ctx == NULL || ctx->md_info == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } -#endif + if( ctx == NULL || ctx->md_info == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); -#if defined(MBEDTLS_MD_SOME_PSA) - if (ctx->engine == MBEDTLS_MD_ENGINE_PSA) { - size_t size = ctx->md_info->size; - psa_status_t status = psa_hash_finish(ctx->md_ctx, - output, size, &size); - return mbedtls_md_error_from_psa(status); - } -#endif - - switch (ctx->md_info->type) { + switch( ctx->md_info->type ) + { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return mbedtls_md5_finish(ctx->md_ctx, output); + return( mbedtls_md5_finish( ctx->md_ctx, output ) ); #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return mbedtls_ripemd160_finish(ctx->md_ctx, output); + return( mbedtls_ripemd160_finish( ctx->md_ctx, output ) ); #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return mbedtls_sha1_finish((mbedtls_sha1_context *)ctx->md_ctx, output); + return( mbedtls_sha1_finish((mbedtls_sha1_context *) ctx->md_ctx, output ) ); #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return mbedtls_sha256_finish((mbedtls_sha256_context *)ctx->md_ctx, output); + return( mbedtls_sha256_finish((mbedtls_sha256_context *) ctx->md_ctx, output ) ); #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return mbedtls_sha256_finish((mbedtls_sha256_context *)ctx->md_ctx, output); + return( mbedtls_sha256_finish((mbedtls_sha256_context *) (mbedtls_sha256_context *)ctx->md_ctx, output ) ); #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return mbedtls_sha512_finish(ctx->md_ctx, output); + return( mbedtls_sha512_finish( ctx->md_ctx, output ) ); #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return mbedtls_sha512_finish(ctx->md_ctx, output); -#endif -#if defined(MBEDTLS_SHA3_C) - case MBEDTLS_MD_SHA3_224: - case MBEDTLS_MD_SHA3_256: - case MBEDTLS_MD_SHA3_384: - case MBEDTLS_MD_SHA3_512: - return mbedtls_sha3_finish(ctx->md_ctx, output, ctx->md_info->size); + return( mbedtls_sha512_finish( ctx->md_ctx, output ) ); #endif default: - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } } -int mbedtls_md(const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, - unsigned char *output) +int mbedtls_md( const mbedtls_md_info_t *md_info, const unsigned char *input, size_t ilen, + unsigned char *output ) { - if (md_info == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } + if( md_info == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); -#if defined(MBEDTLS_MD_SOME_PSA) - if (md_can_use_psa(md_info)) { - size_t size = md_info->size; - psa_status_t status = psa_hash_compute(psa_alg_of_md(md_info), - input, ilen, - output, size, &size); - return mbedtls_md_error_from_psa(status); - } -#endif - - switch (md_info->type) { + switch( md_info->type ) + { #if defined(MBEDTLS_MD5_C) case MBEDTLS_MD_MD5: - return mbedtls_md5(input, ilen, output); + return( mbedtls_md5( input, ilen, output ) ); #endif #if defined(MBEDTLS_RIPEMD160_C) case MBEDTLS_MD_RIPEMD160: - return mbedtls_ripemd160(input, ilen, output); + return( mbedtls_ripemd160( input, ilen, output ) ); #endif #if defined(MBEDTLS_SHA1_C) case MBEDTLS_MD_SHA1: - return mbedtls_sha1(input, ilen, output); + return( mbedtls_sha1( input, ilen, output ) ); #endif #if defined(MBEDTLS_SHA224_C) case MBEDTLS_MD_SHA224: - return mbedtls_sha256(input, ilen, output, 1); + return( mbedtls_sha256( input, ilen, output, 1 ) ); #endif #if defined(MBEDTLS_SHA256_C) case MBEDTLS_MD_SHA256: - return mbedtls_sha256(input, ilen, output, 0); + return( mbedtls_sha256( input, ilen, output, 0 ) ); #endif #if defined(MBEDTLS_SHA384_C) case MBEDTLS_MD_SHA384: - return mbedtls_sha512(input, ilen, output, 1); + return( mbedtls_sha512( input, ilen, output, 1 ) ); #endif #if defined(MBEDTLS_SHA512_C) case MBEDTLS_MD_SHA512: - return mbedtls_sha512(input, ilen, output, 0); -#endif -#if defined(MBEDTLS_SHA3_C) - case MBEDTLS_MD_SHA3_224: - return mbedtls_sha3(MBEDTLS_SHA3_224, input, ilen, output, md_info->size); - case MBEDTLS_MD_SHA3_256: - return mbedtls_sha3(MBEDTLS_SHA3_256, input, ilen, output, md_info->size); - case MBEDTLS_MD_SHA3_384: - return mbedtls_sha3(MBEDTLS_SHA3_384, input, ilen, output, md_info->size); - case MBEDTLS_MD_SHA3_512: - return mbedtls_sha3(MBEDTLS_SHA3_512, input, ilen, output, md_info->size); + return( mbedtls_sha512( input, ilen, output, 0 ) ); #endif default: - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } -} - -unsigned char mbedtls_md_get_size(const mbedtls_md_info_t *md_info) -{ - if (md_info == NULL) { - return 0; - } - - return md_info->size; -} - -mbedtls_md_type_t mbedtls_md_get_type(const mbedtls_md_info_t *md_info) -{ - if (md_info == NULL) { - return MBEDTLS_MD_NONE; - } - - return md_info->type; -} - -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) -int mbedtls_md_error_from_psa(psa_status_t status) -{ - return PSA_TO_MBEDTLS_ERR_LIST(status, psa_to_md_errors, - psa_generic_status_to_mbedtls); -} -#endif /* MBEDTLS_PSA_CRYPTO_CLIENT */ - - -/************************************************************************ - * Functions above this separator are part of MBEDTLS_MD_LIGHT, * - * functions below are only available when MBEDTLS_MD_C is set. * - ************************************************************************/ -#if defined(MBEDTLS_MD_C) - -/* - * Reminder: update profiles in x509_crt.c when adding a new hash! - */ -static const int supported_digests[] = { - -#if defined(MBEDTLS_MD_CAN_SHA512) - MBEDTLS_MD_SHA512, -#endif - -#if defined(MBEDTLS_MD_CAN_SHA384) - MBEDTLS_MD_SHA384, -#endif - -#if defined(MBEDTLS_MD_CAN_SHA256) - MBEDTLS_MD_SHA256, -#endif -#if defined(MBEDTLS_MD_CAN_SHA224) - MBEDTLS_MD_SHA224, -#endif - -#if defined(MBEDTLS_MD_CAN_SHA1) - MBEDTLS_MD_SHA1, -#endif - -#if defined(MBEDTLS_MD_CAN_RIPEMD160) - MBEDTLS_MD_RIPEMD160, -#endif - -#if defined(MBEDTLS_MD_CAN_MD5) - MBEDTLS_MD_MD5, -#endif - -#if defined(MBEDTLS_MD_CAN_SHA3_224) - MBEDTLS_MD_SHA3_224, -#endif - -#if defined(MBEDTLS_MD_CAN_SHA3_256) - MBEDTLS_MD_SHA3_256, -#endif - -#if defined(MBEDTLS_MD_CAN_SHA3_384) - MBEDTLS_MD_SHA3_384, -#endif - -#if defined(MBEDTLS_MD_CAN_SHA3_512) - MBEDTLS_MD_SHA3_512, -#endif - - MBEDTLS_MD_NONE -}; - -const int *mbedtls_md_list(void) -{ - return supported_digests; -} - -typedef struct { - const char *md_name; - mbedtls_md_type_t md_type; -} md_name_entry; - -static const md_name_entry md_names[] = { -#if defined(MBEDTLS_MD_CAN_MD5) - { "MD5", MBEDTLS_MD_MD5 }, -#endif -#if defined(MBEDTLS_MD_CAN_RIPEMD160) - { "RIPEMD160", MBEDTLS_MD_RIPEMD160 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA1) - { "SHA1", MBEDTLS_MD_SHA1 }, - { "SHA", MBEDTLS_MD_SHA1 }, // compatibility fallback -#endif -#if defined(MBEDTLS_MD_CAN_SHA224) - { "SHA224", MBEDTLS_MD_SHA224 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA256) - { "SHA256", MBEDTLS_MD_SHA256 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA384) - { "SHA384", MBEDTLS_MD_SHA384 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA512) - { "SHA512", MBEDTLS_MD_SHA512 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_224) - { "SHA3-224", MBEDTLS_MD_SHA3_224 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_256) - { "SHA3-256", MBEDTLS_MD_SHA3_256 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_384) - { "SHA3-384", MBEDTLS_MD_SHA3_384 }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_512) - { "SHA3-512", MBEDTLS_MD_SHA3_512 }, -#endif - { NULL, MBEDTLS_MD_NONE }, -}; - -const mbedtls_md_info_t *mbedtls_md_info_from_string(const char *md_name) -{ - if (NULL == md_name) { - return NULL; - } - - const md_name_entry *entry = md_names; - while (entry->md_name != NULL && - strcmp(entry->md_name, md_name) != 0) { - ++entry; - } - - return mbedtls_md_info_from_type(entry->md_type); -} - -const char *mbedtls_md_get_name(const mbedtls_md_info_t *md_info) -{ - if (md_info == NULL) { - return NULL; + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } - - const md_name_entry *entry = md_names; - while (entry->md_type != MBEDTLS_MD_NONE && - entry->md_type != md_info->type) { - ++entry; - } - - return entry->md_name; -} - -const mbedtls_md_info_t *mbedtls_md_info_from_ctx( - const mbedtls_md_context_t *ctx) -{ - if (ctx == NULL) { - return NULL; - } - - return ctx->MBEDTLS_PRIVATE(md_info); } #if defined(MBEDTLS_FS_IO) -int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path, unsigned char *output) +int mbedtls_md_file( const mbedtls_md_info_t *md_info, const char *path, unsigned char *output ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; FILE *f; @@ -924,68 +600,56 @@ int mbedtls_md_file(const mbedtls_md_info_t *md_info, const char *path, unsigned mbedtls_md_context_t ctx; unsigned char buf[1024]; - if (md_info == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } - - if ((f = fopen(path, "rb")) == NULL) { - return MBEDTLS_ERR_MD_FILE_IO_ERROR; - } + if( md_info == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); - /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */ - mbedtls_setbuf(f, NULL); + if( ( f = fopen( path, "rb" ) ) == NULL ) + return( MBEDTLS_ERR_MD_FILE_IO_ERROR ); - mbedtls_md_init(&ctx); + mbedtls_md_init( &ctx ); - if ((ret = mbedtls_md_setup(&ctx, md_info, 0)) != 0) { + if( ( ret = mbedtls_md_setup( &ctx, md_info, 0 ) ) != 0 ) goto cleanup; - } - if ((ret = mbedtls_md_starts(&ctx)) != 0) { + if( ( ret = mbedtls_md_starts( &ctx ) ) != 0 ) goto cleanup; - } - while ((n = fread(buf, 1, sizeof(buf), f)) > 0) { - if ((ret = mbedtls_md_update(&ctx, buf, n)) != 0) { + while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) + if( ( ret = mbedtls_md_update( &ctx, buf, n ) ) != 0 ) goto cleanup; - } - } - if (ferror(f) != 0) { + if( ferror( f ) != 0 ) ret = MBEDTLS_ERR_MD_FILE_IO_ERROR; - } else { - ret = mbedtls_md_finish(&ctx, output); - } + else + ret = mbedtls_md_finish( &ctx, output ); cleanup: - mbedtls_platform_zeroize(buf, sizeof(buf)); - fclose(f); - mbedtls_md_free(&ctx); + mbedtls_platform_zeroize( buf, sizeof( buf ) ); + fclose( f ); + mbedtls_md_free( &ctx ); - return ret; + return( ret ); } #endif /* MBEDTLS_FS_IO */ -int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen) +int mbedtls_md_hmac_starts( mbedtls_md_context_t *ctx, const unsigned char *key, size_t keylen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char sum[MBEDTLS_MD_MAX_SIZE]; unsigned char *ipad, *opad; + size_t i; - if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } + if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); - if (keylen > (size_t) ctx->md_info->block_size) { - if ((ret = mbedtls_md_starts(ctx)) != 0) { + if( keylen > (size_t) ctx->md_info->block_size ) + { + if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) goto cleanup; - } - if ((ret = mbedtls_md_update(ctx, key, keylen)) != 0) { + if( ( ret = mbedtls_md_update( ctx, key, keylen ) ) != 0 ) goto cleanup; - } - if ((ret = mbedtls_md_finish(ctx, sum)) != 0) { + if( ( ret = mbedtls_md_finish( ctx, sum ) ) != 0 ) goto cleanup; - } keylen = ctx->md_info->size; key = sum; @@ -994,115 +658,165 @@ int mbedtls_md_hmac_starts(mbedtls_md_context_t *ctx, const unsigned char *key, ipad = (unsigned char *) ctx->hmac_ctx; opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size; - memset(ipad, 0x36, ctx->md_info->block_size); - memset(opad, 0x5C, ctx->md_info->block_size); + memset( ipad, 0x36, ctx->md_info->block_size ); + memset( opad, 0x5C, ctx->md_info->block_size ); - mbedtls_xor(ipad, ipad, key, keylen); - mbedtls_xor(opad, opad, key, keylen); + for( i = 0; i < keylen; i++ ) + { + ipad[i] = (unsigned char)( ipad[i] ^ key[i] ); + opad[i] = (unsigned char)( opad[i] ^ key[i] ); + } - if ((ret = mbedtls_md_starts(ctx)) != 0) { + if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) goto cleanup; - } - if ((ret = mbedtls_md_update(ctx, ipad, - ctx->md_info->block_size)) != 0) { + if( ( ret = mbedtls_md_update( ctx, ipad, + ctx->md_info->block_size ) ) != 0 ) goto cleanup; - } cleanup: - mbedtls_platform_zeroize(sum, sizeof(sum)); + mbedtls_platform_zeroize( sum, sizeof( sum ) ); - return ret; + return( ret ); } -int mbedtls_md_hmac_update(mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen) +int mbedtls_md_hmac_update( mbedtls_md_context_t *ctx, const unsigned char *input, size_t ilen ) { - if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } + if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); - return mbedtls_md_update(ctx, input, ilen); + return( mbedtls_md_update( ctx, input, ilen ) ); } -int mbedtls_md_hmac_finish(mbedtls_md_context_t *ctx, unsigned char *output) +int mbedtls_md_hmac_finish( mbedtls_md_context_t *ctx, unsigned char *output ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char tmp[MBEDTLS_MD_MAX_SIZE]; unsigned char *opad; - if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } + if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); opad = (unsigned char *) ctx->hmac_ctx + ctx->md_info->block_size; - if ((ret = mbedtls_md_finish(ctx, tmp)) != 0) { - return ret; - } - if ((ret = mbedtls_md_starts(ctx)) != 0) { - return ret; - } - if ((ret = mbedtls_md_update(ctx, opad, - ctx->md_info->block_size)) != 0) { - return ret; - } - if ((ret = mbedtls_md_update(ctx, tmp, - ctx->md_info->size)) != 0) { - return ret; - } - return mbedtls_md_finish(ctx, output); + if( ( ret = mbedtls_md_finish( ctx, tmp ) ) != 0 ) + return( ret ); + if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) + return( ret ); + if( ( ret = mbedtls_md_update( ctx, opad, + ctx->md_info->block_size ) ) != 0 ) + return( ret ); + if( ( ret = mbedtls_md_update( ctx, tmp, + ctx->md_info->size ) ) != 0 ) + return( ret ); + return( mbedtls_md_finish( ctx, output ) ); } -int mbedtls_md_hmac_reset(mbedtls_md_context_t *ctx) +int mbedtls_md_hmac_reset( mbedtls_md_context_t *ctx ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *ipad; - if (ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } + if( ctx == NULL || ctx->md_info == NULL || ctx->hmac_ctx == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); ipad = (unsigned char *) ctx->hmac_ctx; - if ((ret = mbedtls_md_starts(ctx)) != 0) { - return ret; - } - return mbedtls_md_update(ctx, ipad, ctx->md_info->block_size); + if( ( ret = mbedtls_md_starts( ctx ) ) != 0 ) + return( ret ); + return( mbedtls_md_update( ctx, ipad, ctx->md_info->block_size ) ); } -int mbedtls_md_hmac(const mbedtls_md_info_t *md_info, - const unsigned char *key, size_t keylen, - const unsigned char *input, size_t ilen, - unsigned char *output) +int mbedtls_md_hmac( const mbedtls_md_info_t *md_info, + const unsigned char *key, size_t keylen, + const unsigned char *input, size_t ilen, + unsigned char *output ) { mbedtls_md_context_t ctx; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - if (md_info == NULL) { - return MBEDTLS_ERR_MD_BAD_INPUT_DATA; - } + if( md_info == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); - mbedtls_md_init(&ctx); + mbedtls_md_init( &ctx ); - if ((ret = mbedtls_md_setup(&ctx, md_info, 1)) != 0) { + if( ( ret = mbedtls_md_setup( &ctx, md_info, 1 ) ) != 0 ) goto cleanup; - } - if ((ret = mbedtls_md_hmac_starts(&ctx, key, keylen)) != 0) { + if( ( ret = mbedtls_md_hmac_starts( &ctx, key, keylen ) ) != 0 ) goto cleanup; - } - if ((ret = mbedtls_md_hmac_update(&ctx, input, ilen)) != 0) { + if( ( ret = mbedtls_md_hmac_update( &ctx, input, ilen ) ) != 0 ) goto cleanup; - } - if ((ret = mbedtls_md_hmac_finish(&ctx, output)) != 0) { + if( ( ret = mbedtls_md_hmac_finish( &ctx, output ) ) != 0 ) goto cleanup; - } cleanup: - mbedtls_md_free(&ctx); + mbedtls_md_free( &ctx ); - return ret; + return( ret ); } -#endif /* MBEDTLS_MD_C */ +int mbedtls_md_process( mbedtls_md_context_t *ctx, const unsigned char *data ) +{ + if( ctx == NULL || ctx->md_info == NULL ) + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + + switch( ctx->md_info->type ) + { +#if defined(MBEDTLS_MD5_C) + case MBEDTLS_MD_MD5: + return( mbedtls_internal_md5_process( ctx->md_ctx, data ) ); +#endif +#if defined(MBEDTLS_RIPEMD160_C) + case MBEDTLS_MD_RIPEMD160: + return( mbedtls_internal_ripemd160_process( ctx->md_ctx, data ) ); +#endif +#if defined(MBEDTLS_SHA1_C) + case MBEDTLS_MD_SHA1: + return( mbedtls_internal_sha1_process((mbedtls_sha1_context *) ctx->md_ctx, data ) ); +#endif +#if defined(MBEDTLS_SHA224_C) + case MBEDTLS_MD_SHA224: + return( mbedtls_internal_sha256_process((mbedtls_sha256_context *) ctx->md_ctx, data ) ); +#endif +#if defined(MBEDTLS_SHA256_C) + case MBEDTLS_MD_SHA256: + return( mbedtls_internal_sha256_process((mbedtls_sha256_context *) ctx->md_ctx, data ) ); +#endif +#if defined(MBEDTLS_SHA384_C) + case MBEDTLS_MD_SHA384: + return( mbedtls_internal_sha512_process( ctx->md_ctx, data ) ); +#endif +#if defined(MBEDTLS_SHA512_C) + case MBEDTLS_MD_SHA512: + return( mbedtls_internal_sha512_process( ctx->md_ctx, data ) ); +#endif + default: + return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); + } +} + +unsigned char mbedtls_md_get_size( const mbedtls_md_info_t *md_info ) +{ + if( md_info == NULL ) + return( 0 ); -#endif /* MBEDTLS_MD_LIGHT */ + return md_info->size; +} + +mbedtls_md_type_t mbedtls_md_get_type( const mbedtls_md_info_t *md_info ) +{ + if( md_info == NULL ) + return( MBEDTLS_MD_NONE ); + + return md_info->type; +} + +const char *mbedtls_md_get_name( const mbedtls_md_info_t *md_info ) +{ + if( md_info == NULL ) + return( NULL ); + + return md_info->name; +} + +#endif /* MBEDTLS_MD_C */ diff --git a/src/duckdb/third_party/mbedtls/library/md_wrap.h b/src/duckdb/third_party/mbedtls/library/md_wrap.h index dad123540..90c795731 100644 --- a/src/duckdb/third_party/mbedtls/library/md_wrap.h +++ b/src/duckdb/third_party/mbedtls/library/md_wrap.h @@ -9,7 +9,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_MD_WRAP_H #define MBEDTLS_MD_WRAP_H @@ -26,19 +38,43 @@ extern "C" { * Message digest information. * Allows message digest functions to be called in a generic way. */ -struct mbedtls_md_info_t { +struct mbedtls_md_info_t +{ + /** Name of the message digest */ + const char * name; + /** Digest identifier */ mbedtls_md_type_t type; /** Output length of the digest function in bytes */ unsigned char size; -#if defined(MBEDTLS_MD_C) /** Block length of the digest function in bytes */ unsigned char block_size; -#endif }; +#if defined(MBEDTLS_MD5_C) +extern const mbedtls_md_info_t mbedtls_md5_info; +#endif +#if defined(MBEDTLS_RIPEMD160_C) +extern const mbedtls_md_info_t mbedtls_ripemd160_info; +#endif +#if defined(MBEDTLS_SHA1_C) +extern const mbedtls_md_info_t mbedtls_sha1_info; +#endif +#if defined(MBEDTLS_SHA224_C) +extern const mbedtls_md_info_t mbedtls_sha224_info; +#endif +#if defined(MBEDTLS_SHA256_C) +extern const mbedtls_md_info_t mbedtls_sha256_info; +#endif +#if defined(MBEDTLS_SHA384_C) +extern const mbedtls_md_info_t mbedtls_sha384_info; +#endif +#if defined(MBEDTLS_SHA512_C) +extern const mbedtls_md_info_t mbedtls_sha512_info; +#endif + #ifdef __cplusplus } #endif diff --git a/src/duckdb/third_party/mbedtls/library/oid.cpp b/src/duckdb/third_party/mbedtls/library/oid.cpp index 7f2a71de1..fd6bbfd83 100644 --- a/src/duckdb/third_party/mbedtls/library/oid.cpp +++ b/src/duckdb/third_party/mbedtls/library/oid.cpp @@ -4,7 +4,19 @@ * \brief Object Identifier (OID) database * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" @@ -14,12 +26,15 @@ #include "mbedtls/oid.h" #include "mbedtls/rsa.h" #include "mbedtls/error.h" -#include "mbedtls/pk.h" #include #include +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#define mbedtls_snprintf snprintf +#endif /* * Macro to automatically add the size of #define'd OIDs @@ -41,23 +56,23 @@ * Macro to generate an internal function for oid_XXX_from_asn1() (used by * the other functions) */ -#define FN_OID_TYPED_FROM_ASN1(TYPE_T, NAME, LIST) \ - static const TYPE_T *oid_ ## NAME ## _from_asn1( \ - const mbedtls_asn1_buf *oid) \ +#define FN_OID_TYPED_FROM_ASN1( TYPE_T, NAME, LIST ) \ + static const TYPE_T * oid_ ## NAME ## _from_asn1( \ + const mbedtls_asn1_buf *oid ) \ { \ const TYPE_T *p = (LIST); \ const mbedtls_oid_descriptor_t *cur = \ (const mbedtls_oid_descriptor_t *) p; \ - if (p == NULL || oid == NULL) return NULL; \ - while (cur->asn1 != NULL) { \ - if (cur->asn1_len == oid->len && \ - memcmp(cur->asn1, oid->p, oid->len) == 0) { \ - return p; \ + if( p == NULL || oid == NULL ) return( NULL ); \ + while( cur->asn1 != NULL ) { \ + if( cur->asn1_len == oid->len && \ + memcmp( cur->asn1, oid->p, oid->len ) == 0 ) { \ + return( p ); \ } \ p++; \ cur = (const mbedtls_oid_descriptor_t *) p; \ } \ - return NULL; \ + return( NULL ); \ } #if !defined(MBEDTLS_X509_REMOVE_INFO) @@ -66,13 +81,13 @@ * descriptor of an mbedtls_oid_descriptor_t wrapper. */ #define FN_OID_GET_DESCRIPTOR_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \ - int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1) \ - { \ - const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid); \ - if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND; \ - *ATTR1 = data->descriptor.ATTR1; \ - return 0; \ - } +int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \ +{ \ + const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ + if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + *ATTR1 = data->descriptor.ATTR1; \ + return( 0 ); \ +} #endif /* MBEDTLS_X509_REMOVE_INFO */ /* @@ -80,13 +95,13 @@ * mbedtls_oid_descriptor_t wrapper. */ #define FN_OID_GET_ATTR1(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1) \ - int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1) \ - { \ - const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid); \ - if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND; \ - *ATTR1 = data->ATTR1; \ - return 0; \ - } +int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1 ) \ +{ \ + const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ + if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + *ATTR1 = data->ATTR1; \ + return( 0 ); \ +} /* * Macro to generate a function for retrieving two attributes from an @@ -94,34 +109,34 @@ */ #define FN_OID_GET_ATTR2(FN_NAME, TYPE_T, TYPE_NAME, ATTR1_TYPE, ATTR1, \ ATTR2_TYPE, ATTR2) \ - int FN_NAME(const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, \ - ATTR2_TYPE * ATTR2) \ - { \ - const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1(oid); \ - if (data == NULL) return MBEDTLS_ERR_OID_NOT_FOUND; \ - *(ATTR1) = data->ATTR1; \ - *(ATTR2) = data->ATTR2; \ - return 0; \ - } +int FN_NAME( const mbedtls_asn1_buf *oid, ATTR1_TYPE * ATTR1, \ + ATTR2_TYPE * ATTR2 ) \ +{ \ + const TYPE_T *data = oid_ ## TYPE_NAME ## _from_asn1( oid ); \ + if( data == NULL ) return( MBEDTLS_ERR_OID_NOT_FOUND ); \ + *(ATTR1) = data->ATTR1; \ + *(ATTR2) = data->ATTR2; \ + return( 0 ); \ +} /* * Macro to generate a function for retrieving the OID based on a single * attribute from a mbedtls_oid_descriptor_t wrapper. */ #define FN_OID_GET_OID_BY_ATTR1(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1) \ - int FN_NAME(ATTR1_TYPE ATTR1, const char **oid, size_t *olen) \ - { \ - const TYPE_T *cur = (LIST); \ - while (cur->descriptor.asn1 != NULL) { \ - if (cur->ATTR1 == (ATTR1)) { \ - *oid = cur->descriptor.asn1; \ - *olen = cur->descriptor.asn1_len; \ - return 0; \ - } \ - cur++; \ - } \ - return MBEDTLS_ERR_OID_NOT_FOUND; \ - } +int FN_NAME( ATTR1_TYPE ATTR1, const char **oid, size_t *olen ) \ +{ \ + const TYPE_T *cur = (LIST); \ + while( cur->descriptor.asn1 != NULL ) { \ + if( cur->ATTR1 == (ATTR1) ) { \ + *oid = cur->descriptor.asn1; \ + *olen = cur->descriptor.asn1_len; \ + return( 0 ); \ + } \ + cur++; \ + } \ + return( MBEDTLS_ERR_OID_NOT_FOUND ); \ +} /* * Macro to generate a function for retrieving the OID based on two @@ -129,20 +144,20 @@ */ #define FN_OID_GET_OID_BY_ATTR2(FN_NAME, TYPE_T, LIST, ATTR1_TYPE, ATTR1, \ ATTR2_TYPE, ATTR2) \ - int FN_NAME(ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid, \ - size_t *olen) \ - { \ - const TYPE_T *cur = (LIST); \ - while (cur->descriptor.asn1 != NULL) { \ - if (cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2)) { \ - *oid = cur->descriptor.asn1; \ - *olen = cur->descriptor.asn1_len; \ - return 0; \ - } \ - cur++; \ - } \ - return MBEDTLS_ERR_OID_NOT_FOUND; \ - } +int FN_NAME( ATTR1_TYPE ATTR1, ATTR2_TYPE ATTR2, const char **oid , \ + size_t *olen ) \ +{ \ + const TYPE_T *cur = (LIST); \ + while( cur->descriptor.asn1 != NULL ) { \ + if( cur->ATTR1 == (ATTR1) && cur->ATTR2 == (ATTR2) ) { \ + *oid = cur->descriptor.asn1; \ + *olen = cur->descriptor.asn1_len; \ + return( 0 ); \ + } \ + cur++; \ + } \ + return( MBEDTLS_ERR_OID_NOT_FOUND ); \ +} /* * For X520 attribute types @@ -155,98 +170,83 @@ typedef struct { static const oid_x520_attr_t oid_x520_attr_type[] = { { - OID_DESCRIPTOR(MBEDTLS_OID_AT_CN, "id-at-commonName", "Common Name"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_CN, "id-at-commonName", "Common Name" ), "CN", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_COUNTRY, "id-at-countryName", "Country"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_COUNTRY, "id-at-countryName", "Country" ), "C", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_LOCALITY, "id-at-locality", "Locality"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_LOCALITY, "id-at-locality", "Locality" ), "L", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_STATE, "id-at-state", "State"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_STATE, "id-at-state", "State" ), "ST", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_ORGANIZATION, "id-at-organizationName", - "Organization"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_ORGANIZATION,"id-at-organizationName", "Organization" ), "O", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_ORG_UNIT, "id-at-organizationalUnitName", "Org Unit"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_ORG_UNIT, "id-at-organizationalUnitName", "Org Unit" ), "OU", }, { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS9_EMAIL, - "emailAddress", - "E-mail address"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS9_EMAIL, "emailAddress", "E-mail address" ), "emailAddress", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_SERIAL_NUMBER, - "id-at-serialNumber", - "Serial number"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_SERIAL_NUMBER,"id-at-serialNumber", "Serial number" ), "serialNumber", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_POSTAL_ADDRESS, - "id-at-postalAddress", - "Postal address"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_POSTAL_ADDRESS,"id-at-postalAddress", "Postal address" ), "postalAddress", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_POSTAL_CODE, "id-at-postalCode", "Postal code"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_POSTAL_CODE, "id-at-postalCode", "Postal code" ), "postalCode", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_SUR_NAME, "id-at-surName", "Surname"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_SUR_NAME, "id-at-surName", "Surname" ), "SN", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_GIVEN_NAME, "id-at-givenName", "Given name"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_GIVEN_NAME, "id-at-givenName", "Given name" ), "GN", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_INITIALS, "id-at-initials", "Initials"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_INITIALS, "id-at-initials", "Initials" ), "initials", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_GENERATION_QUALIFIER, - "id-at-generationQualifier", - "Generation qualifier"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_GENERATION_QUALIFIER, "id-at-generationQualifier", "Generation qualifier" ), "generationQualifier", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_TITLE, "id-at-title", "Title"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_TITLE, "id-at-title", "Title" ), "title", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_DN_QUALIFIER, - "id-at-dnQualifier", - "Distinguished Name qualifier"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_DN_QUALIFIER,"id-at-dnQualifier", "Distinguished Name qualifier" ), "dnQualifier", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_PSEUDONYM, "id-at-pseudonym", "Pseudonym"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_PSEUDONYM, "id-at-pseudonym", "Pseudonym" ), "pseudonym", }, { - OID_DESCRIPTOR(MBEDTLS_OID_UID, "id-uid", "User Id"), + OID_DESCRIPTOR( MBEDTLS_OID_UID, "id-uid", "User Id" ), "uid", }, { - OID_DESCRIPTOR(MBEDTLS_OID_DOMAIN_COMPONENT, - "id-domainComponent", - "Domain component"), + OID_DESCRIPTOR( MBEDTLS_OID_DOMAIN_COMPONENT, "id-domainComponent", "Domain component" ), "DC", }, { - OID_DESCRIPTOR(MBEDTLS_OID_AT_UNIQUE_IDENTIFIER, - "id-at-uniqueIdentifier", - "Unique Identifier"), + OID_DESCRIPTOR( MBEDTLS_OID_AT_UNIQUE_IDENTIFIER, "id-at-uniqueIdentifier", "Unique Identifier" ), "uniqueIdentifier", }, { @@ -256,11 +256,7 @@ static const oid_x520_attr_t oid_x520_attr_type[] = }; FN_OID_TYPED_FROM_ASN1(oid_x520_attr_t, x520_attr, oid_x520_attr_type) -FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name, - oid_x520_attr_t, - x520_attr, - const char *, - short_name) +FN_OID_GET_ATTR1(mbedtls_oid_get_attr_short_name, oid_x520_attr_t, x520_attr, const char *, short_name) /* * For X509 extensions @@ -273,51 +269,29 @@ typedef struct { static const oid_x509_ext_t oid_x509_ext[] = { { - OID_DESCRIPTOR(MBEDTLS_OID_BASIC_CONSTRAINTS, - "id-ce-basicConstraints", - "Basic Constraints"), + OID_DESCRIPTOR( MBEDTLS_OID_BASIC_CONSTRAINTS, "id-ce-basicConstraints", "Basic Constraints" ), MBEDTLS_OID_X509_EXT_BASIC_CONSTRAINTS, }, { - OID_DESCRIPTOR(MBEDTLS_OID_KEY_USAGE, "id-ce-keyUsage", "Key Usage"), + OID_DESCRIPTOR( MBEDTLS_OID_KEY_USAGE, "id-ce-keyUsage", "Key Usage" ), MBEDTLS_OID_X509_EXT_KEY_USAGE, }, { - OID_DESCRIPTOR(MBEDTLS_OID_EXTENDED_KEY_USAGE, - "id-ce-extKeyUsage", - "Extended Key Usage"), + OID_DESCRIPTOR( MBEDTLS_OID_EXTENDED_KEY_USAGE, "id-ce-extKeyUsage", "Extended Key Usage" ), MBEDTLS_OID_X509_EXT_EXTENDED_KEY_USAGE, }, { - OID_DESCRIPTOR(MBEDTLS_OID_SUBJECT_ALT_NAME, - "id-ce-subjectAltName", - "Subject Alt Name"), + OID_DESCRIPTOR( MBEDTLS_OID_SUBJECT_ALT_NAME, "id-ce-subjectAltName", "Subject Alt Name" ), MBEDTLS_OID_X509_EXT_SUBJECT_ALT_NAME, }, { - OID_DESCRIPTOR(MBEDTLS_OID_NS_CERT_TYPE, - "id-netscape-certtype", - "Netscape Certificate Type"), + OID_DESCRIPTOR( MBEDTLS_OID_NS_CERT_TYPE, "id-netscape-certtype", "Netscape Certificate Type" ), MBEDTLS_OID_X509_EXT_NS_CERT_TYPE, }, { - OID_DESCRIPTOR(MBEDTLS_OID_CERTIFICATE_POLICIES, - "id-ce-certificatePolicies", - "Certificate Policies"), + OID_DESCRIPTOR( MBEDTLS_OID_CERTIFICATE_POLICIES, "id-ce-certificatePolicies", "Certificate Policies" ), MBEDTLS_OID_X509_EXT_CERTIFICATE_POLICIES, }, - { - OID_DESCRIPTOR(MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER, - "id-ce-subjectKeyIdentifier", - "Subject Key Identifier"), - MBEDTLS_OID_X509_EXT_SUBJECT_KEY_IDENTIFIER, - }, - { - OID_DESCRIPTOR(MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER, - "id-ce-authorityKeyIdentifier", - "Authority Key Identifier"), - MBEDTLS_OID_X509_EXT_AUTHORITY_KEY_IDENTIFIER, - }, { NULL_OID_DESCRIPTOR, 0, @@ -330,43 +304,30 @@ FN_OID_GET_ATTR1(mbedtls_oid_get_x509_ext_type, oid_x509_ext_t, x509_ext, int, e #if !defined(MBEDTLS_X509_REMOVE_INFO) static const mbedtls_oid_descriptor_t oid_ext_key_usage[] = { - OID_DESCRIPTOR(MBEDTLS_OID_SERVER_AUTH, - "id-kp-serverAuth", - "TLS Web Server Authentication"), - OID_DESCRIPTOR(MBEDTLS_OID_CLIENT_AUTH, - "id-kp-clientAuth", - "TLS Web Client Authentication"), - OID_DESCRIPTOR(MBEDTLS_OID_CODE_SIGNING, "id-kp-codeSigning", "Code Signing"), - OID_DESCRIPTOR(MBEDTLS_OID_EMAIL_PROTECTION, "id-kp-emailProtection", "E-mail Protection"), - OID_DESCRIPTOR(MBEDTLS_OID_TIME_STAMPING, "id-kp-timeStamping", "Time Stamping"), - OID_DESCRIPTOR(MBEDTLS_OID_OCSP_SIGNING, "id-kp-OCSPSigning", "OCSP Signing"), - OID_DESCRIPTOR(MBEDTLS_OID_WISUN_FAN, - "id-kp-wisun-fan-device", - "Wi-SUN Alliance Field Area Network (FAN)"), + OID_DESCRIPTOR( MBEDTLS_OID_SERVER_AUTH, "id-kp-serverAuth", "TLS Web Server Authentication" ), + OID_DESCRIPTOR( MBEDTLS_OID_CLIENT_AUTH, "id-kp-clientAuth", "TLS Web Client Authentication" ), + OID_DESCRIPTOR( MBEDTLS_OID_CODE_SIGNING, "id-kp-codeSigning", "Code Signing" ), + OID_DESCRIPTOR( MBEDTLS_OID_EMAIL_PROTECTION, "id-kp-emailProtection", "E-mail Protection" ), + OID_DESCRIPTOR( MBEDTLS_OID_TIME_STAMPING, "id-kp-timeStamping", "Time Stamping" ), + OID_DESCRIPTOR( MBEDTLS_OID_OCSP_SIGNING, "id-kp-OCSPSigning", "OCSP Signing" ), + OID_DESCRIPTOR( MBEDTLS_OID_WISUN_FAN, "id-kp-wisun-fan-device", "Wi-SUN Alliance Field Area Network (FAN)" ), NULL_OID_DESCRIPTOR, }; FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, ext_key_usage, oid_ext_key_usage) -FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage, - mbedtls_oid_descriptor_t, - ext_key_usage, - const char *, - description) +FN_OID_GET_ATTR1(mbedtls_oid_get_extended_key_usage, mbedtls_oid_descriptor_t, ext_key_usage, const char *, description) static const mbedtls_oid_descriptor_t oid_certificate_policies[] = { - OID_DESCRIPTOR(MBEDTLS_OID_ANY_POLICY, "anyPolicy", "Any Policy"), + OID_DESCRIPTOR( MBEDTLS_OID_ANY_POLICY, "anyPolicy", "Any Policy" ), NULL_OID_DESCRIPTOR, }; FN_OID_TYPED_FROM_ASN1(mbedtls_oid_descriptor_t, certificate_policies, oid_certificate_policies) -FN_OID_GET_ATTR1(mbedtls_oid_get_certificate_policies, - mbedtls_oid_descriptor_t, - certificate_policies, - const char *, - description) +FN_OID_GET_ATTR1(mbedtls_oid_get_certificate_policies, mbedtls_oid_descriptor_t, certificate_policies, const char *, description) #endif /* MBEDTLS_X509_REMOVE_INFO */ +#if defined(MBEDTLS_MD_C) /* * For SignatureAlgorithmIdentifier */ @@ -379,88 +340,84 @@ typedef struct { static const oid_sig_alg_t oid_sig_alg[] = { #if defined(MBEDTLS_RSA_C) -#if defined(MBEDTLS_MD_CAN_MD5) +#if defined(MBEDTLS_MD5_C) { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_MD5, "md5WithRSAEncryption", "RSA with MD5"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_MD5, "md5WithRSAEncryption", "RSA with MD5" ), MBEDTLS_MD_MD5, MBEDTLS_PK_RSA, }, -#endif /* MBEDTLS_MD_CAN_MD5 */ -#if defined(MBEDTLS_MD_CAN_SHA1) +#endif /* MBEDTLS_MD5_C */ +#if defined(MBEDTLS_SHA1_C) { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA1, "sha-1WithRSAEncryption", "RSA with SHA1"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA1, "sha-1WithRSAEncryption", "RSA with SHA1" ), MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA, }, -#endif /* MBEDTLS_MD_CAN_SHA1 */ -#if defined(MBEDTLS_MD_CAN_SHA224) +#endif /* MBEDTLS_SHA1_C */ +#if defined(MBEDTLS_SHA224_C) { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA224, "sha224WithRSAEncryption", - "RSA with SHA-224"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA224, "sha224WithRSAEncryption", "RSA with SHA-224" ), MBEDTLS_MD_SHA224, MBEDTLS_PK_RSA, }, -#endif /* MBEDTLS_MD_CAN_SHA224 */ -#if defined(MBEDTLS_MD_CAN_SHA256) +#endif +#if defined(MBEDTLS_SHA256_C) { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA256, "sha256WithRSAEncryption", - "RSA with SHA-256"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA256, "sha256WithRSAEncryption", "RSA with SHA-256" ), MBEDTLS_MD_SHA256, MBEDTLS_PK_RSA, }, -#endif /* MBEDTLS_MD_CAN_SHA256 */ -#if defined(MBEDTLS_MD_CAN_SHA384) +#endif /* MBEDTLS_SHA256_C */ +#if defined(MBEDTLS_SHA384_C) { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA384, "sha384WithRSAEncryption", - "RSA with SHA-384"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA384, "sha384WithRSAEncryption", "RSA with SHA-384" ), MBEDTLS_MD_SHA384, MBEDTLS_PK_RSA, }, -#endif /* MBEDTLS_MD_CAN_SHA384 */ -#if defined(MBEDTLS_MD_CAN_SHA512) +#endif /* MBEDTLS_SHA384_C */ +#if defined(MBEDTLS_SHA512_C) { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_SHA512, "sha512WithRSAEncryption", - "RSA with SHA-512"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_SHA512, "sha512WithRSAEncryption", "RSA with SHA-512" ), MBEDTLS_MD_SHA512, MBEDTLS_PK_RSA, }, -#endif /* MBEDTLS_MD_CAN_SHA512 */ -#if defined(MBEDTLS_MD_CAN_SHA1) +#endif /* MBEDTLS_SHA512_C */ +#if defined(MBEDTLS_SHA1_C) { - OID_DESCRIPTOR(MBEDTLS_OID_RSA_SHA_OBS, "sha-1WithRSAEncryption", "RSA with SHA1"), + OID_DESCRIPTOR( MBEDTLS_OID_RSA_SHA_OBS, "sha-1WithRSAEncryption", "RSA with SHA1" ), MBEDTLS_MD_SHA1, MBEDTLS_PK_RSA, }, -#endif /* MBEDTLS_MD_CAN_SHA1 */ +#endif /* MBEDTLS_SHA1_C */ #endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_CAN_ECDSA_SOME) -#if defined(MBEDTLS_MD_CAN_SHA1) +#if defined(MBEDTLS_ECDSA_C) +#if defined(MBEDTLS_SHA1_C) { - OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA1, "ecdsa-with-SHA1", "ECDSA with SHA1"), + OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA1, "ecdsa-with-SHA1", "ECDSA with SHA1" ), MBEDTLS_MD_SHA1, MBEDTLS_PK_ECDSA, }, -#endif /* MBEDTLS_MD_CAN_SHA1 */ -#if defined(MBEDTLS_MD_CAN_SHA224) +#endif /* MBEDTLS_SHA1_C */ +#if defined(MBEDTLS_SHA224_C) { - OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA224, "ecdsa-with-SHA224", "ECDSA with SHA224"), + OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA224, "ecdsa-with-SHA224", "ECDSA with SHA224" ), MBEDTLS_MD_SHA224, MBEDTLS_PK_ECDSA, }, #endif -#if defined(MBEDTLS_MD_CAN_SHA256) +#if defined(MBEDTLS_SHA256_C) { - OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA256, "ecdsa-with-SHA256", "ECDSA with SHA256"), + OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA256, "ecdsa-with-SHA256", "ECDSA with SHA256" ), MBEDTLS_MD_SHA256, MBEDTLS_PK_ECDSA, }, -#endif /* MBEDTLS_MD_CAN_SHA256 */ -#if defined(MBEDTLS_MD_CAN_SHA384) +#endif /* MBEDTLS_SHA256_C */ +#if defined(MBEDTLS_SHA384_C) { - OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA384, "ecdsa-with-SHA384", "ECDSA with SHA384"), + OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA384, "ecdsa-with-SHA384", "ECDSA with SHA384" ), MBEDTLS_MD_SHA384, MBEDTLS_PK_ECDSA, }, -#endif /* MBEDTLS_MD_CAN_SHA384 */ -#if defined(MBEDTLS_MD_CAN_SHA512) +#endif /* MBEDTLS_SHA384_C */ +#if defined(MBEDTLS_SHA512_C) { - OID_DESCRIPTOR(MBEDTLS_OID_ECDSA_SHA512, "ecdsa-with-SHA512", "ECDSA with SHA512"), + OID_DESCRIPTOR( MBEDTLS_OID_ECDSA_SHA512, "ecdsa-with-SHA512", "ECDSA with SHA512" ), MBEDTLS_MD_SHA512, MBEDTLS_PK_ECDSA, }, -#endif /* MBEDTLS_MD_CAN_SHA512 */ -#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */ +#endif /* MBEDTLS_SHA512_C */ +#endif /* MBEDTLS_ECDSA_C */ #if defined(MBEDTLS_RSA_C) { - OID_DESCRIPTOR(MBEDTLS_OID_RSASSA_PSS, "RSASSA-PSS", "RSASSA-PSS"), + OID_DESCRIPTOR( MBEDTLS_OID_RSASSA_PSS, "RSASSA-PSS", "RSASSA-PSS" ), MBEDTLS_MD_NONE, MBEDTLS_PK_RSASSA_PSS, }, #endif /* MBEDTLS_RSA_C */ @@ -473,27 +430,12 @@ static const oid_sig_alg_t oid_sig_alg[] = FN_OID_TYPED_FROM_ASN1(oid_sig_alg_t, sig_alg, oid_sig_alg) #if !defined(MBEDTLS_X509_REMOVE_INFO) -FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc, - oid_sig_alg_t, - sig_alg, - const char *, - description) +FN_OID_GET_DESCRIPTOR_ATTR1(mbedtls_oid_get_sig_alg_desc, oid_sig_alg_t, sig_alg, const char *, description) #endif -FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg, - oid_sig_alg_t, - sig_alg, - mbedtls_md_type_t, - md_alg, - mbedtls_pk_type_t, - pk_alg) -FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg, - oid_sig_alg_t, - oid_sig_alg, - mbedtls_pk_type_t, - pk_alg, - mbedtls_md_type_t, - md_alg) +FN_OID_GET_ATTR2(mbedtls_oid_get_sig_alg, oid_sig_alg_t, sig_alg, mbedtls_md_type_t, md_alg, mbedtls_pk_type_t, pk_alg) +FN_OID_GET_OID_BY_ATTR2(mbedtls_oid_get_oid_by_sig_alg, oid_sig_alg_t, oid_sig_alg, mbedtls_pk_type_t, pk_alg, mbedtls_md_type_t, md_alg) +#endif /* MBEDTLS_MD_C */ /* * For PublicKeyInfo (PKCS1, RFC 5480) @@ -506,15 +448,15 @@ typedef struct { static const oid_pk_alg_t oid_pk_alg[] = { { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS1_RSA, "rsaEncryption", "RSA"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS1_RSA, "rsaEncryption", "RSA" ), MBEDTLS_PK_RSA, }, { - OID_DESCRIPTOR(MBEDTLS_OID_EC_ALG_UNRESTRICTED, "id-ecPublicKey", "Generic EC key"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_ALG_UNRESTRICTED, "id-ecPublicKey", "Generic EC key" ), MBEDTLS_PK_ECKEY, }, { - OID_DESCRIPTOR(MBEDTLS_OID_EC_ALG_ECDH, "id-ecDH", "EC key for ECDH"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_ALG_ECDH, "id-ecDH", "EC key for ECDH" ), MBEDTLS_PK_ECKEY_DH, }, { @@ -525,15 +467,11 @@ static const oid_pk_alg_t oid_pk_alg[] = FN_OID_TYPED_FROM_ASN1(oid_pk_alg_t, pk_alg, oid_pk_alg) FN_OID_GET_ATTR1(mbedtls_oid_get_pk_alg, oid_pk_alg_t, pk_alg, mbedtls_pk_type_t, pk_alg) -FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_pk_alg, - oid_pk_alg_t, - oid_pk_alg, - mbedtls_pk_type_t, - pk_alg) +FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_pk_alg, oid_pk_alg_t, oid_pk_alg, mbedtls_pk_type_t, pk_alg) -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_ECP_C) /* - * For elliptic curves that use namedCurve inside ECParams (RFC 5480) + * For namedCurve (RFC 5480) */ typedef struct { mbedtls_oid_descriptor_t descriptor; @@ -542,72 +480,72 @@ typedef struct { static const oid_ecp_grp_t oid_ecp_grp[] = { -#if defined(MBEDTLS_ECP_HAVE_SECP192R1) +#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP192R1, "secp192r1", "secp192r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP192R1, "secp192r1", "secp192r1" ), MBEDTLS_ECP_DP_SECP192R1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP192R1 */ -#if defined(MBEDTLS_ECP_HAVE_SECP224R1) +#endif /* MBEDTLS_ECP_DP_SECP192R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP224R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP224R1, "secp224r1", "secp224r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP224R1, "secp224r1", "secp224r1" ), MBEDTLS_ECP_DP_SECP224R1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP224R1 */ -#if defined(MBEDTLS_ECP_HAVE_SECP256R1) +#endif /* MBEDTLS_ECP_DP_SECP224R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP256R1, "secp256r1", "secp256r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP256R1, "secp256r1", "secp256r1" ), MBEDTLS_ECP_DP_SECP256R1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP256R1 */ -#if defined(MBEDTLS_ECP_HAVE_SECP384R1) +#endif /* MBEDTLS_ECP_DP_SECP256R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP384R1, "secp384r1", "secp384r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP384R1, "secp384r1", "secp384r1" ), MBEDTLS_ECP_DP_SECP384R1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP384R1 */ -#if defined(MBEDTLS_ECP_HAVE_SECP521R1) +#endif /* MBEDTLS_ECP_DP_SECP384R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP521R1, "secp521r1", "secp521r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP521R1, "secp521r1", "secp521r1" ), MBEDTLS_ECP_DP_SECP521R1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP521R1 */ -#if defined(MBEDTLS_ECP_HAVE_SECP192K1) +#endif /* MBEDTLS_ECP_DP_SECP521R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP192K1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP192K1, "secp192k1", "secp192k1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP192K1, "secp192k1", "secp192k1" ), MBEDTLS_ECP_DP_SECP192K1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP192K1 */ -#if defined(MBEDTLS_ECP_HAVE_SECP224K1) +#endif /* MBEDTLS_ECP_DP_SECP192K1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP224K1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP224K1, "secp224k1", "secp224k1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP224K1, "secp224k1", "secp224k1" ), MBEDTLS_ECP_DP_SECP224K1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP224K1 */ -#if defined(MBEDTLS_ECP_HAVE_SECP256K1) +#endif /* MBEDTLS_ECP_DP_SECP224K1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_SECP256K1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_SECP256K1, "secp256k1", "secp256k1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_SECP256K1, "secp256k1", "secp256k1" ), MBEDTLS_ECP_DP_SECP256K1, }, -#endif /* MBEDTLS_ECP_HAVE_SECP256K1 */ -#if defined(MBEDTLS_ECP_HAVE_BP256R1) +#endif /* MBEDTLS_ECP_DP_SECP256K1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_BP256R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP256R1, "brainpoolP256r1", "brainpool256r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_BP256R1, "brainpoolP256r1","brainpool256r1" ), MBEDTLS_ECP_DP_BP256R1, }, -#endif /* MBEDTLS_ECP_HAVE_BP256R1 */ -#if defined(MBEDTLS_ECP_HAVE_BP384R1) +#endif /* MBEDTLS_ECP_DP_BP256R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_BP384R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP384R1, "brainpoolP384r1", "brainpool384r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_BP384R1, "brainpoolP384r1","brainpool384r1" ), MBEDTLS_ECP_DP_BP384R1, }, -#endif /* MBEDTLS_ECP_HAVE_BP384R1 */ -#if defined(MBEDTLS_ECP_HAVE_BP512R1) +#endif /* MBEDTLS_ECP_DP_BP384R1_ENABLED */ +#if defined(MBEDTLS_ECP_DP_BP512R1_ENABLED) { - OID_DESCRIPTOR(MBEDTLS_OID_EC_GRP_BP512R1, "brainpoolP512r1", "brainpool512r1"), + OID_DESCRIPTOR( MBEDTLS_OID_EC_GRP_BP512R1, "brainpoolP512r1","brainpool512r1" ), MBEDTLS_ECP_DP_BP512R1, }, -#endif /* MBEDTLS_ECP_HAVE_BP512R1 */ +#endif /* MBEDTLS_ECP_DP_BP512R1_ENABLED */ { NULL_OID_DESCRIPTOR, MBEDTLS_ECP_DP_NONE, @@ -616,53 +554,8 @@ static const oid_ecp_grp_t oid_ecp_grp[] = FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_t, grp_id, oid_ecp_grp) FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp, oid_ecp_grp_t, grp_id, mbedtls_ecp_group_id, grp_id) -FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp, - oid_ecp_grp_t, - oid_ecp_grp, - mbedtls_ecp_group_id, - grp_id) - -/* - * For Elliptic Curve algorithms that are directly - * encoded in the AlgorithmIdentifier (RFC 8410) - */ -typedef struct { - mbedtls_oid_descriptor_t descriptor; - mbedtls_ecp_group_id grp_id; -} oid_ecp_grp_algid_t; - -static const oid_ecp_grp_algid_t oid_ecp_grp_algid[] = -{ -#if defined(MBEDTLS_ECP_HAVE_CURVE25519) - { - OID_DESCRIPTOR(MBEDTLS_OID_X25519, "X25519", "X25519"), - MBEDTLS_ECP_DP_CURVE25519, - }, -#endif /* MBEDTLS_ECP_HAVE_CURVE25519 */ -#if defined(MBEDTLS_ECP_HAVE_CURVE448) - { - OID_DESCRIPTOR(MBEDTLS_OID_X448, "X448", "X448"), - MBEDTLS_ECP_DP_CURVE448, - }, -#endif /* MBEDTLS_ECP_HAVE_CURVE448 */ - { - NULL_OID_DESCRIPTOR, - MBEDTLS_ECP_DP_NONE, - }, -}; - -FN_OID_TYPED_FROM_ASN1(oid_ecp_grp_algid_t, grp_id_algid, oid_ecp_grp_algid) -FN_OID_GET_ATTR1(mbedtls_oid_get_ec_grp_algid, - oid_ecp_grp_algid_t, - grp_id_algid, - mbedtls_ecp_group_id, - grp_id) -FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp_algid, - oid_ecp_grp_algid_t, - oid_ecp_grp_algid, - mbedtls_ecp_group_id, - grp_id) -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ +FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_ec_grp, oid_ecp_grp_t, oid_ecp_grp, mbedtls_ecp_group_id, grp_id) +#endif /* MBEDTLS_ECP_C */ #if defined(MBEDTLS_CIPHER_C) /* @@ -676,25 +569,13 @@ typedef struct { static const oid_cipher_alg_t oid_cipher_alg[] = { { - OID_DESCRIPTOR(MBEDTLS_OID_DES_CBC, "desCBC", "DES-CBC"), + OID_DESCRIPTOR( MBEDTLS_OID_DES_CBC, "desCBC", "DES-CBC" ), MBEDTLS_CIPHER_DES_CBC, }, { - OID_DESCRIPTOR(MBEDTLS_OID_DES_EDE3_CBC, "des-ede3-cbc", "DES-EDE3-CBC"), + OID_DESCRIPTOR( MBEDTLS_OID_DES_EDE3_CBC, "des-ede3-cbc", "DES-EDE3-CBC" ), MBEDTLS_CIPHER_DES_EDE3_CBC, }, - { - OID_DESCRIPTOR(MBEDTLS_OID_AES_128_CBC, "aes128-cbc", "AES128-CBC"), - MBEDTLS_CIPHER_AES_128_CBC, - }, - { - OID_DESCRIPTOR(MBEDTLS_OID_AES_192_CBC, "aes192-cbc", "AES192-CBC"), - MBEDTLS_CIPHER_AES_192_CBC, - }, - { - OID_DESCRIPTOR(MBEDTLS_OID_AES_256_CBC, "aes256-cbc", "AES256-CBC"), - MBEDTLS_CIPHER_AES_256_CBC, - }, { NULL_OID_DESCRIPTOR, MBEDTLS_CIPHER_NONE, @@ -702,13 +583,10 @@ static const oid_cipher_alg_t oid_cipher_alg[] = }; FN_OID_TYPED_FROM_ASN1(oid_cipher_alg_t, cipher_alg, oid_cipher_alg) -FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg, - oid_cipher_alg_t, - cipher_alg, - mbedtls_cipher_type_t, - cipher_alg) +FN_OID_GET_ATTR1(mbedtls_oid_get_cipher_alg, oid_cipher_alg_t, cipher_alg, mbedtls_cipher_type_t, cipher_alg) #endif /* MBEDTLS_CIPHER_C */ +#if defined(MBEDTLS_MD_C) /* * For digestAlgorithm */ @@ -719,72 +597,48 @@ typedef struct { static const oid_md_alg_t oid_md_alg[] = { -#if defined(MBEDTLS_MD_CAN_MD5) +#if defined(MBEDTLS_MD5_C) { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_MD5, "id-md5", "MD5"), + OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_MD5, "id-md5", "MD5" ), MBEDTLS_MD_MD5, }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA1) +#endif /* MBEDTLS_MD5_C */ +#if defined(MBEDTLS_SHA1_C) { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA1, "id-sha1", "SHA-1"), + OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA1, "id-sha1", "SHA-1" ), MBEDTLS_MD_SHA1, }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA224) +#endif /* MBEDTLS_SHA1_C */ +#if defined(MBEDTLS_SHA224_C) { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA224, "id-sha224", "SHA-224"), + OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA224, "id-sha224", "SHA-224" ), MBEDTLS_MD_SHA224, }, #endif -#if defined(MBEDTLS_MD_CAN_SHA256) +#if defined(MBEDTLS_SHA256_C) { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA256, "id-sha256", "SHA-256"), + OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA256, "id-sha256", "SHA-256" ), MBEDTLS_MD_SHA256, }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA384) +#endif /* MBEDTLS_SHA256_C */ +#if defined(MBEDTLS_SHA384_C) { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA384, "id-sha384", "SHA-384"), + OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA384, "id-sha384", "SHA-384" ), MBEDTLS_MD_SHA384, }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA512) +#endif /* MBEDTLS_SHA384_C */ +#if defined(MBEDTLS_SHA512_C) { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA512, "id-sha512", "SHA-512"), + OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_SHA512, "id-sha512", "SHA-512" ), MBEDTLS_MD_SHA512, }, -#endif -#if defined(MBEDTLS_MD_CAN_RIPEMD160) +#endif /* MBEDTLS_SHA512_C */ +#if defined(MBEDTLS_RIPEMD160_C) { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_RIPEMD160, "id-ripemd160", "RIPEMD-160"), + OID_DESCRIPTOR( MBEDTLS_OID_DIGEST_ALG_RIPEMD160, "id-ripemd160", "RIPEMD-160" ), MBEDTLS_MD_RIPEMD160, }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_224) - { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_224, "id-sha3-224", "SHA-3-224"), - MBEDTLS_MD_SHA3_224, - }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_256) - { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_256, "id-sha3-256", "SHA-3-256"), - MBEDTLS_MD_SHA3_256, - }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_384) - { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_384, "id-sha3-384", "SHA-3-384"), - MBEDTLS_MD_SHA3_384, - }, -#endif -#if defined(MBEDTLS_MD_CAN_SHA3_512) - { - OID_DESCRIPTOR(MBEDTLS_OID_DIGEST_ALG_SHA3_512, "id-sha3-512", "SHA-3-512"), - MBEDTLS_MD_SHA3_512, - }, -#endif +#endif /* MBEDTLS_RIPEMD160_C */ { NULL_OID_DESCRIPTOR, MBEDTLS_MD_NONE, @@ -793,11 +647,7 @@ static const oid_md_alg_t oid_md_alg[] = FN_OID_TYPED_FROM_ASN1(oid_md_alg_t, md_alg, oid_md_alg) FN_OID_GET_ATTR1(mbedtls_oid_get_md_alg, oid_md_alg_t, md_alg, mbedtls_md_type_t, md_alg) -FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_md, - oid_md_alg_t, - oid_md_alg, - mbedtls_md_type_t, - md_alg) +FN_OID_GET_OID_BY_ATTR1(mbedtls_oid_get_oid_by_md, oid_md_alg_t, oid_md_alg, mbedtls_md_type_t, md_alg) /* * For HMAC digestAlgorithm @@ -809,66 +659,36 @@ typedef struct { static const oid_md_hmac_t oid_md_hmac[] = { -#if defined(MBEDTLS_MD_CAN_SHA1) +#if defined(MBEDTLS_SHA1_C) { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA1, "hmacSHA1", "HMAC-SHA-1"), + OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA1, "hmacSHA1", "HMAC-SHA-1" ), MBEDTLS_MD_SHA1, }, -#endif /* MBEDTLS_MD_CAN_SHA1 */ -#if defined(MBEDTLS_MD_CAN_SHA224) +#endif /* MBEDTLS_SHA1_C */ +#if defined(MBEDTLS_SHA224_C) { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA224, "hmacSHA224", "HMAC-SHA-224"), + OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA224, "hmacSHA224", "HMAC-SHA-224" ), MBEDTLS_MD_SHA224, }, -#endif /* MBEDTLS_MD_CAN_SHA224 */ -#if defined(MBEDTLS_MD_CAN_SHA256) +#endif +#if defined(MBEDTLS_SHA256_C) { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA256, "hmacSHA256", "HMAC-SHA-256"), + OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA256, "hmacSHA256", "HMAC-SHA-256" ), MBEDTLS_MD_SHA256, }, -#endif /* MBEDTLS_MD_CAN_SHA256 */ -#if defined(MBEDTLS_MD_CAN_SHA384) +#endif /* MBEDTLS_SHA256_C */ +#if defined(MBEDTLS_SHA384_C) { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA384, "hmacSHA384", "HMAC-SHA-384"), + OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA384, "hmacSHA384", "HMAC-SHA-384" ), MBEDTLS_MD_SHA384, }, -#endif /* MBEDTLS_MD_CAN_SHA384 */ -#if defined(MBEDTLS_MD_CAN_SHA512) +#endif /* MBEDTLS_SHA384_C */ +#if defined(MBEDTLS_SHA512_C) { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA512, "hmacSHA512", "HMAC-SHA-512"), + OID_DESCRIPTOR( MBEDTLS_OID_HMAC_SHA512, "hmacSHA512", "HMAC-SHA-512" ), MBEDTLS_MD_SHA512, }, -#endif /* MBEDTLS_MD_CAN_SHA512 */ -#if defined(MBEDTLS_MD_CAN_SHA3_224) - { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_224, "hmacSHA3-224", "HMAC-SHA3-224"), - MBEDTLS_MD_SHA3_224, - }, -#endif /* MBEDTLS_MD_CAN_SHA3_224 */ -#if defined(MBEDTLS_MD_CAN_SHA3_256) - { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_256, "hmacSHA3-256", "HMAC-SHA3-256"), - MBEDTLS_MD_SHA3_256, - }, -#endif /* MBEDTLS_MD_CAN_SHA3_256 */ -#if defined(MBEDTLS_MD_CAN_SHA3_384) - { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_384, "hmacSHA3-384", "HMAC-SHA3-384"), - MBEDTLS_MD_SHA3_384, - }, -#endif /* MBEDTLS_MD_CAN_SHA3_384 */ -#if defined(MBEDTLS_MD_CAN_SHA3_512) - { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_SHA3_512, "hmacSHA3-512", "HMAC-SHA3-512"), - MBEDTLS_MD_SHA3_512, - }, -#endif /* MBEDTLS_MD_CAN_SHA3_512 */ -#if defined(MBEDTLS_MD_CAN_RIPEMD160) - { - OID_DESCRIPTOR(MBEDTLS_OID_HMAC_RIPEMD160, "hmacRIPEMD160", "HMAC-RIPEMD160"), - MBEDTLS_MD_RIPEMD160, - }, -#endif /* MBEDTLS_MD_CAN_RIPEMD160 */ +#endif /* MBEDTLS_SHA512_C */ { NULL_OID_DESCRIPTOR, MBEDTLS_MD_NONE, @@ -877,8 +697,9 @@ static const oid_md_hmac_t oid_md_hmac[] = FN_OID_TYPED_FROM_ASN1(oid_md_hmac_t, md_hmac, oid_md_hmac) FN_OID_GET_ATTR1(mbedtls_oid_get_md_hmac, oid_md_hmac_t, md_hmac, mbedtls_md_type_t, md_hmac) +#endif /* MBEDTLS_MD_C */ -#if defined(MBEDTLS_PKCS12_C) && defined(MBEDTLS_CIPHER_C) +#if defined(MBEDTLS_PKCS12_C) /* * For PKCS#12 PBEs */ @@ -891,15 +712,11 @@ typedef struct { static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] = { { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC, - "pbeWithSHAAnd3-KeyTripleDES-CBC", - "PBE with SHA1 and 3-Key 3DES"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS12_PBE_SHA1_DES3_EDE_CBC, "pbeWithSHAAnd3-KeyTripleDES-CBC", "PBE with SHA1 and 3-Key 3DES" ), MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE3_CBC, }, { - OID_DESCRIPTOR(MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC, - "pbeWithSHAAnd2-KeyTripleDES-CBC", - "PBE with SHA1 and 2-Key 3DES"), + OID_DESCRIPTOR( MBEDTLS_OID_PKCS12_PBE_SHA1_DES2_EDE_CBC, "pbeWithSHAAnd2-KeyTripleDES-CBC", "PBE with SHA1 and 2-Key 3DES" ), MBEDTLS_MD_SHA1, MBEDTLS_CIPHER_DES_EDE_CBC, }, { @@ -909,258 +726,23 @@ static const oid_pkcs12_pbe_alg_t oid_pkcs12_pbe_alg[] = }; FN_OID_TYPED_FROM_ASN1(oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, oid_pkcs12_pbe_alg) -FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg, - oid_pkcs12_pbe_alg_t, - pkcs12_pbe_alg, - mbedtls_md_type_t, - md_alg, - mbedtls_cipher_type_t, - cipher_alg) -#endif /* MBEDTLS_PKCS12_C && MBEDTLS_CIPHER_C */ +FN_OID_GET_ATTR2(mbedtls_oid_get_pkcs12_pbe_alg, oid_pkcs12_pbe_alg_t, pkcs12_pbe_alg, mbedtls_md_type_t, md_alg, mbedtls_cipher_type_t, cipher_alg) +#endif /* MBEDTLS_PKCS12_C */ + +#define OID_SAFE_SNPRINTF \ + do { \ + if( ret < 0 || (size_t) ret >= n ) \ + return( MBEDTLS_ERR_OID_BUF_TOO_SMALL ); \ + \ + n -= (size_t) ret; \ + p += (size_t) ret; \ + } while( 0 ) /* Return the x.y.z.... style numeric string for the given OID */ -int mbedtls_oid_get_numeric_string(char *buf, size_t size, - const mbedtls_asn1_buf *oid) +int mbedtls_oid_get_numeric_string( char *buf, size_t size, + const mbedtls_asn1_buf *oid ) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - char *p = buf; - size_t n = size; - unsigned int value = 0; - - if (size > INT_MAX) { - /* Avoid overflow computing return value */ - return MBEDTLS_ERR_ASN1_INVALID_LENGTH; - } - - if (oid->len <= 0) { - /* OID must not be empty */ - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } - - for (size_t i = 0; i < oid->len; i++) { - /* Prevent overflow in value. */ - if (value > (UINT_MAX >> 7)) { - return MBEDTLS_ERR_ASN1_INVALID_DATA; - } - if ((value == 0) && ((oid->p[i]) == 0x80)) { - /* Overlong encoding is not allowed */ - return MBEDTLS_ERR_ASN1_INVALID_DATA; - } - - value <<= 7; - value |= oid->p[i] & 0x7F; - - if (!(oid->p[i] & 0x80)) { - /* Last byte */ - if (n == size) { - int component1; - unsigned int component2; - /* First subidentifier contains first two OID components */ - if (value >= 80) { - component1 = '2'; - component2 = value - 80; - } else if (value >= 40) { - component1 = '1'; - component2 = value - 40; - } else { - component1 = '0'; - component2 = value; - } - ret = mbedtls_snprintf(p, n, "%c.%u", component1, component2); - } else { - ret = mbedtls_snprintf(p, n, ".%u", value); - } - if (ret < 2 || (size_t) ret >= n) { - return MBEDTLS_ERR_OID_BUF_TOO_SMALL; - } - n -= (size_t) ret; - p += ret; - value = 0; - } - } - - if (value != 0) { - /* Unterminated subidentifier */ - return MBEDTLS_ERR_ASN1_OUT_OF_DATA; - } - - return (int) (size - n); -} - -static int oid_parse_number(unsigned int *num, const char **p, const char *bound) -{ - int ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - - *num = 0; - - while (*p < bound && **p >= '0' && **p <= '9') { - ret = 0; - if (*num > (UINT_MAX / 10)) { - return MBEDTLS_ERR_ASN1_INVALID_DATA; - } - *num *= 10; - *num += **p - '0'; - (*p)++; - } - return ret; -} - -static size_t oid_subidentifier_num_bytes(unsigned int value) -{ - size_t num_bytes = 0; - - do { - value >>= 7; - num_bytes++; - } while (value != 0); - - return num_bytes; -} - -static int oid_subidentifier_encode_into(unsigned char **p, - unsigned char *bound, - unsigned int value) -{ - size_t num_bytes = oid_subidentifier_num_bytes(value); - - if ((size_t) (bound - *p) < num_bytes) { - return MBEDTLS_ERR_OID_BUF_TOO_SMALL; - } - (*p)[num_bytes - 1] = (unsigned char) (value & 0x7f); - value >>= 7; - - for (size_t i = 2; i <= num_bytes; i++) { - (*p)[num_bytes - i] = 0x80 | (unsigned char) (value & 0x7f); - value >>= 7; - } - *p += num_bytes; - - return 0; -} - -/* Return the OID for the given x.y.z.... style numeric string */ -int mbedtls_oid_from_numeric_string(mbedtls_asn1_buf *oid, - const char *oid_str, size_t size) -{ - int ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - const char *str_ptr = oid_str; - const char *str_bound = oid_str + size; - unsigned int val = 0; - unsigned int component1, component2; - size_t encoded_len; - unsigned char *resized_mem; - - /* Count the number of dots to get a worst-case allocation size. */ - size_t num_dots = 0; - for (size_t i = 0; i < size; i++) { - if (oid_str[i] == '.') { - num_dots++; - } - } - /* Allocate maximum possible required memory: - * There are (num_dots + 1) integer components, but the first 2 share the - * same subidentifier, so we only need num_dots subidentifiers maximum. */ - if (num_dots == 0 || (num_dots > MBEDTLS_OID_MAX_COMPONENTS - 1)) { - return MBEDTLS_ERR_ASN1_INVALID_DATA; - } - /* Each byte can store 7 bits, calculate number of bytes for a - * subidentifier: - * - * bytes = ceil(subidentifer_size * 8 / 7) - */ - size_t bytes_per_subidentifier = (((sizeof(unsigned int) * 8) - 1) / 7) - + 1; - size_t max_possible_bytes = num_dots * bytes_per_subidentifier; - oid->p = (unsigned char*) mbedtls_calloc(max_possible_bytes, 1); - if (oid->p == NULL) { - return MBEDTLS_ERR_ASN1_ALLOC_FAILED; - } - unsigned char *out_ptr = oid->p; - unsigned char *out_bound = oid->p + max_possible_bytes; - - ret = oid_parse_number(&component1, &str_ptr, str_bound); - if (ret != 0) { - goto error; - } - if (component1 > 2) { - /* First component can't be > 2 */ - ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - goto error; - } - if (str_ptr >= str_bound || *str_ptr != '.') { - ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - goto error; - } - str_ptr++; - - ret = oid_parse_number(&component2, &str_ptr, str_bound); - if (ret != 0) { - goto error; - } - if ((component1 < 2) && (component2 > 39)) { - /* Root nodes 0 and 1 may have up to 40 children, numbered 0-39 */ - ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - goto error; - } - if (str_ptr < str_bound) { - if (*str_ptr == '.') { - str_ptr++; - } else { - ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - goto error; - } - } - - if (component2 > (UINT_MAX - (component1 * 40))) { - ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - goto error; - } - ret = oid_subidentifier_encode_into(&out_ptr, out_bound, - (component1 * 40) + component2); - if (ret != 0) { - goto error; - } - - while (str_ptr < str_bound) { - ret = oid_parse_number(&val, &str_ptr, str_bound); - if (ret != 0) { - goto error; - } - if (str_ptr < str_bound) { - if (*str_ptr == '.') { - str_ptr++; - } else { - ret = MBEDTLS_ERR_ASN1_INVALID_DATA; - goto error; - } - } - - ret = oid_subidentifier_encode_into(&out_ptr, out_bound, val); - if (ret != 0) { - goto error; - } - } - - encoded_len = (size_t) (out_ptr - oid->p); - resized_mem = (unsigned char*) mbedtls_calloc(encoded_len, 1); - if (resized_mem == NULL) { - ret = MBEDTLS_ERR_ASN1_ALLOC_FAILED; - goto error; - } - memcpy(resized_mem, oid->p, encoded_len); - mbedtls_free(oid->p); - oid->p = resized_mem; - oid->len = encoded_len; - - oid->tag = MBEDTLS_ASN1_OID; - - return 0; - -error: - mbedtls_free(oid->p); - oid->p = NULL; - oid->len = 0; - return ret; + return MBEDTLS_ERR_ERROR_GENERIC_ERROR; // patched because it used to require printf which would fail on Windows } #endif /* MBEDTLS_OID_C */ diff --git a/src/duckdb/third_party/mbedtls/library/padlock.h b/src/duckdb/third_party/mbedtls/library/padlock.h index 92d72af51..6b63dc037 100644 --- a/src/duckdb/third_party/mbedtls/library/padlock.h +++ b/src/duckdb/third_party/mbedtls/library/padlock.h @@ -1,111 +1 @@ -/** - * \file padlock.h - * - * \brief VIA PadLock ACE for HW encryption/decryption supported by some - * processors - * - * \warning These functions are only for internal use by other library - * functions; you must not call them directly. - */ -/* - * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later - */ -#ifndef MBEDTLS_PADLOCK_H -#define MBEDTLS_PADLOCK_H - -#include "mbedtls/build_info.h" - -#include "mbedtls/aes.h" - -#define MBEDTLS_ERR_PADLOCK_DATA_MISALIGNED -0x0030 /**< Input data should be aligned. */ - -#if defined(__has_feature) -#if __has_feature(address_sanitizer) -#define MBEDTLS_HAVE_ASAN -#endif -#endif - -/* - * - `padlock` is implements with GNUC assembly for x86 target. - * - Some versions of ASan result in errors about not enough registers. - */ -#if defined(MBEDTLS_PADLOCK_C) && \ - defined(__GNUC__) && defined(MBEDTLS_ARCH_IS_X86) && \ - defined(MBEDTLS_HAVE_ASM) && \ - !defined(MBEDTLS_HAVE_ASAN) - -#define MBEDTLS_VIA_PADLOCK_HAVE_CODE - -#include - -#define MBEDTLS_PADLOCK_RNG 0x000C -#define MBEDTLS_PADLOCK_ACE 0x00C0 -#define MBEDTLS_PADLOCK_PHE 0x0C00 -#define MBEDTLS_PADLOCK_PMM 0x3000 - -#define MBEDTLS_PADLOCK_ALIGN16(x) (uint32_t *) (16 + ((int32_t) (x) & ~15)) - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * \brief Internal PadLock detection routine - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param feature The feature to detect - * - * \return non-zero if CPU has support for the feature, 0 otherwise - */ -int mbedtls_padlock_has_support(int feature); - -/** - * \brief Internal PadLock AES-ECB block en(de)cryption - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param ctx AES context - * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT - * \param input 16-byte input block - * \param output 16-byte output block - * - * \return 0 if success, 1 if operation failed - */ -int mbedtls_padlock_xcryptecb(mbedtls_aes_context *ctx, - int mode, - const unsigned char input[16], - unsigned char output[16]); - -/** - * \brief Internal PadLock AES-CBC buffer en(de)cryption - * - * \note This function is only for internal use by other library - * functions; you must not call it directly. - * - * \param ctx AES context - * \param mode MBEDTLS_AES_ENCRYPT or MBEDTLS_AES_DECRYPT - * \param length length of the input data - * \param iv initialization vector (updated after use) - * \param input buffer holding the input data - * \param output buffer holding the output data - * - * \return 0 if success, 1 if operation failed - */ -int mbedtls_padlock_xcryptcbc(mbedtls_aes_context *ctx, - int mode, - size_t length, - unsigned char iv[16], - const unsigned char *input, - unsigned char *output); - -#ifdef __cplusplus -} -#endif - -#endif /* HAVE_X86 */ - -#endif /* padlock.h */ +// dummy file to make amalgamantion happy diff --git a/src/duckdb/third_party/mbedtls/library/pem.cpp b/src/duckdb/third_party/mbedtls/library/pem.cpp index d663fa242..67dd4e6f2 100644 --- a/src/duckdb/third_party/mbedtls/library/pem.cpp +++ b/src/duckdb/third_party/mbedtls/library/pem.cpp @@ -2,7 +2,19 @@ * Privacy Enhanced Mail (PEM) decoding * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" @@ -12,199 +24,172 @@ #include "mbedtls/pem.h" #include "mbedtls/base64.h" #include "mbedtls/des.h" +#ifdef MBEDTLS_AES_C #include "mbedtls/aes.h" -#include "mbedtls/md.h" +#endif +#ifdef MBEDTLS_MD5_C +#include "mbedtls/md5.h" +#endif #include "mbedtls/cipher.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" #include +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" - -#if defined(MBEDTLS_USE_PSA_CRYPTO) -#include "psa/crypto.h" +#else +#include +#define mbedtls_calloc calloc +#define mbedtls_free free #endif -#if defined(MBEDTLS_MD_CAN_MD5) && \ - defined(MBEDTLS_CIPHER_MODE_CBC) && \ - (defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C)) -#define PEM_RFC1421 -#endif /* MBEDTLS_MD_CAN_MD5 && - MBEDTLS_CIPHER_MODE_CBC && - ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ - #if defined(MBEDTLS_PEM_PARSE_C) -void mbedtls_pem_init(mbedtls_pem_context *ctx) +void mbedtls_pem_init( mbedtls_pem_context *ctx ) { - memset(ctx, 0, sizeof(mbedtls_pem_context)); + memset( ctx, 0, sizeof( mbedtls_pem_context ) ); } -#if defined(PEM_RFC1421) +#if defined(MBEDTLS_MD5_C) && defined(MBEDTLS_CIPHER_MODE_CBC) && \ + ( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) ) /* * Read a 16-byte hex string and convert it to binary */ -static int pem_get_iv(const unsigned char *s, unsigned char *iv, - size_t iv_len) +static int pem_get_iv( const unsigned char *s, unsigned char *iv, + size_t iv_len ) { size_t i, j, k; - memset(iv, 0, iv_len); - - for (i = 0; i < iv_len * 2; i++, s++) { - if (*s >= '0' && *s <= '9') { - j = *s - '0'; - } else - if (*s >= 'A' && *s <= 'F') { - j = *s - '7'; - } else - if (*s >= 'a' && *s <= 'f') { - j = *s - 'W'; - } else { - return MBEDTLS_ERR_PEM_INVALID_ENC_IV; - } + memset( iv, 0, iv_len ); - k = ((i & 1) != 0) ? j : j << 4; + for( i = 0; i < iv_len * 2; i++, s++ ) + { + if( *s >= '0' && *s <= '9' ) j = *s - '0'; else + if( *s >= 'A' && *s <= 'F' ) j = *s - '7'; else + if( *s >= 'a' && *s <= 'f' ) j = *s - 'W'; else + return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); - iv[i >> 1] = (unsigned char) (iv[i >> 1] | k); + k = ( ( i & 1 ) != 0 ) ? j : j << 4; + + iv[i >> 1] = (unsigned char)( iv[i >> 1] | k ); } - return 0; + return( 0 ); } -static int pem_pbkdf1(unsigned char *key, size_t keylen, - unsigned char *iv, - const unsigned char *pwd, size_t pwdlen) +static int pem_pbkdf1( unsigned char *key, size_t keylen, + unsigned char *iv, + const unsigned char *pwd, size_t pwdlen ) { - mbedtls_md_context_t md5_ctx; - const mbedtls_md_info_t *md5_info; + mbedtls_md5_context md5_ctx; unsigned char md5sum[16]; size_t use_len; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_md_init(&md5_ctx); - - /* Prepare the context. (setup() errors gracefully on NULL info.) */ - md5_info = mbedtls_md_info_from_type(MBEDTLS_MD_MD5); - if ((ret = mbedtls_md_setup(&md5_ctx, md5_info, 0)) != 0) { - goto exit; - } + mbedtls_md5_init( &md5_ctx ); /* * key[ 0..15] = MD5(pwd || IV) */ - if ((ret = mbedtls_md_starts(&md5_ctx)) != 0) { + if( ( ret = mbedtls_md5_starts( &md5_ctx ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_update(&md5_ctx, pwd, pwdlen)) != 0) { + if( ( ret = mbedtls_md5_update( &md5_ctx, pwd, pwdlen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_update(&md5_ctx, iv, 8)) != 0) { + if( ( ret = mbedtls_md5_update( &md5_ctx, iv, 8 ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_finish(&md5_ctx, md5sum)) != 0) { + if( ( ret = mbedtls_md5_finish( &md5_ctx, md5sum ) ) != 0 ) goto exit; - } - if (keylen <= 16) { - memcpy(key, md5sum, keylen); + if( keylen <= 16 ) + { + memcpy( key, md5sum, keylen ); goto exit; } - memcpy(key, md5sum, 16); + memcpy( key, md5sum, 16 ); /* * key[16..23] = MD5(key[ 0..15] || pwd || IV]) */ - if ((ret = mbedtls_md_starts(&md5_ctx)) != 0) { + if( ( ret = mbedtls_md5_starts( &md5_ctx ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_update(&md5_ctx, md5sum, 16)) != 0) { + if( ( ret = mbedtls_md5_update( &md5_ctx, md5sum, 16 ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_update(&md5_ctx, pwd, pwdlen)) != 0) { + if( ( ret = mbedtls_md5_update( &md5_ctx, pwd, pwdlen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_update(&md5_ctx, iv, 8)) != 0) { + if( ( ret = mbedtls_md5_update( &md5_ctx, iv, 8 ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_finish(&md5_ctx, md5sum)) != 0) { + if( ( ret = mbedtls_md5_finish( &md5_ctx, md5sum ) ) != 0 ) goto exit; - } use_len = 16; - if (keylen < 32) { + if( keylen < 32 ) use_len = keylen - 16; - } - memcpy(key + 16, md5sum, use_len); + memcpy( key + 16, md5sum, use_len ); exit: - mbedtls_md_free(&md5_ctx); - mbedtls_platform_zeroize(md5sum, 16); + mbedtls_md5_free( &md5_ctx ); + mbedtls_platform_zeroize( md5sum, 16 ); - return ret; + return( ret ); } #if defined(MBEDTLS_DES_C) /* * Decrypt with DES-CBC, using PBKDF1 for key derivation */ -static int pem_des_decrypt(unsigned char des_iv[8], - unsigned char *buf, size_t buflen, - const unsigned char *pwd, size_t pwdlen) +static int pem_des_decrypt( unsigned char des_iv[8], + unsigned char *buf, size_t buflen, + const unsigned char *pwd, size_t pwdlen ) { mbedtls_des_context des_ctx; unsigned char des_key[8]; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_des_init(&des_ctx); + mbedtls_des_init( &des_ctx ); - if ((ret = pem_pbkdf1(des_key, 8, des_iv, pwd, pwdlen)) != 0) { + if( ( ret = pem_pbkdf1( des_key, 8, des_iv, pwd, pwdlen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_des_setkey_dec(&des_ctx, des_key)) != 0) { + if( ( ret = mbedtls_des_setkey_dec( &des_ctx, des_key ) ) != 0 ) goto exit; - } - ret = mbedtls_des_crypt_cbc(&des_ctx, MBEDTLS_DES_DECRYPT, buflen, - des_iv, buf, buf); + ret = mbedtls_des_crypt_cbc( &des_ctx, MBEDTLS_DES_DECRYPT, buflen, + des_iv, buf, buf ); exit: - mbedtls_des_free(&des_ctx); - mbedtls_platform_zeroize(des_key, 8); + mbedtls_des_free( &des_ctx ); + mbedtls_platform_zeroize( des_key, 8 ); - return ret; + return( ret ); } /* * Decrypt with 3DES-CBC, using PBKDF1 for key derivation */ -static int pem_des3_decrypt(unsigned char des3_iv[8], - unsigned char *buf, size_t buflen, - const unsigned char *pwd, size_t pwdlen) +static int pem_des3_decrypt( unsigned char des3_iv[8], + unsigned char *buf, size_t buflen, + const unsigned char *pwd, size_t pwdlen ) { mbedtls_des3_context des3_ctx; unsigned char des3_key[24]; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_des3_init(&des3_ctx); + mbedtls_des3_init( &des3_ctx ); - if ((ret = pem_pbkdf1(des3_key, 24, des3_iv, pwd, pwdlen)) != 0) { + if( ( ret = pem_pbkdf1( des3_key, 24, des3_iv, pwd, pwdlen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_des3_set3key_dec(&des3_ctx, des3_key)) != 0) { + if( ( ret = mbedtls_des3_set3key_dec( &des3_ctx, des3_key ) ) != 0 ) goto exit; - } - ret = mbedtls_des3_crypt_cbc(&des3_ctx, MBEDTLS_DES_DECRYPT, buflen, - des3_iv, buf, buf); + ret = mbedtls_des3_crypt_cbc( &des3_ctx, MBEDTLS_DES_DECRYPT, buflen, + des3_iv, buf, buf ); exit: - mbedtls_des3_free(&des3_ctx); - mbedtls_platform_zeroize(des3_key, 24); + mbedtls_des3_free( &des3_ctx ); + mbedtls_platform_zeroize( des3_key, 24 ); - return ret; + return( ret ); } #endif /* MBEDTLS_DES_C */ @@ -212,340 +197,297 @@ static int pem_des3_decrypt(unsigned char des3_iv[8], /* * Decrypt with AES-XXX-CBC, using PBKDF1 for key derivation */ -static int pem_aes_decrypt(unsigned char aes_iv[16], unsigned int keylen, - unsigned char *buf, size_t buflen, - const unsigned char *pwd, size_t pwdlen) +static int pem_aes_decrypt( unsigned char aes_iv[16], unsigned int keylen, + unsigned char *buf, size_t buflen, + const unsigned char *pwd, size_t pwdlen ) { mbedtls_aes_context aes_ctx; unsigned char aes_key[32]; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_aes_init(&aes_ctx); + mbedtls_aes_init( &aes_ctx ); - if ((ret = pem_pbkdf1(aes_key, keylen, aes_iv, pwd, pwdlen)) != 0) { + if( ( ret = pem_pbkdf1( aes_key, keylen, aes_iv, pwd, pwdlen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_aes_setkey_dec(&aes_ctx, aes_key, keylen * 8)) != 0) { + if( ( ret = mbedtls_aes_setkey_dec( &aes_ctx, aes_key, keylen * 8 ) ) != 0 ) goto exit; - } - ret = mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_DECRYPT, buflen, - aes_iv, buf, buf); + ret = mbedtls_aes_crypt_cbc( &aes_ctx, MBEDTLS_AES_DECRYPT, buflen, + aes_iv, buf, buf ); exit: - mbedtls_aes_free(&aes_ctx); - mbedtls_platform_zeroize(aes_key, keylen); + mbedtls_aes_free( &aes_ctx ); + mbedtls_platform_zeroize( aes_key, keylen ); - return ret; + return( ret ); } #endif /* MBEDTLS_AES_C */ -#if defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) -static int pem_check_pkcs_padding(unsigned char *input, size_t input_len, size_t *data_len) -{ - /* input_len > 0 is guaranteed by mbedtls_pem_read_buffer(). */ - size_t pad_len = input[input_len - 1]; - size_t i; - - if (pad_len > input_len) { - return MBEDTLS_ERR_PEM_PASSWORD_MISMATCH; - } - - *data_len = input_len - pad_len; - - for (i = *data_len; i < input_len; i++) { - if (input[i] != pad_len) { - return MBEDTLS_ERR_PEM_PASSWORD_MISMATCH; - } - } - - return 0; -} -#endif /* MBEDTLS_DES_C || MBEDTLS_AES_C */ - -#endif /* PEM_RFC1421 */ +#endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC && + ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ -int mbedtls_pem_read_buffer(mbedtls_pem_context *ctx, const char *header, const char *footer, - const unsigned char *data, const unsigned char *pwd, - size_t pwdlen, size_t *use_len) +int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer, + const unsigned char *data, const unsigned char *pwd, + size_t pwdlen, size_t *use_len ) { int ret, enc; size_t len; unsigned char *buf; const unsigned char *s1, *s2, *end; -#if defined(PEM_RFC1421) +#if defined(MBEDTLS_MD5_C) && defined(MBEDTLS_CIPHER_MODE_CBC) && \ + ( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) ) unsigned char pem_iv[16]; mbedtls_cipher_type_t enc_alg = MBEDTLS_CIPHER_NONE; #else ((void) pwd); ((void) pwdlen); -#endif /* PEM_RFC1421 */ +#endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC && + ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ - if (ctx == NULL) { - return MBEDTLS_ERR_PEM_BAD_INPUT_DATA; - } + if( ctx == NULL ) + return( MBEDTLS_ERR_PEM_BAD_INPUT_DATA ); - s1 = (unsigned char *) strstr((const char *) data, header); + s1 = (unsigned char *) strstr( (const char *) data, header ); - if (s1 == NULL) { - return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } + if( s1 == NULL ) + return( MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ); - s2 = (unsigned char *) strstr((const char *) data, footer); + s2 = (unsigned char *) strstr( (const char *) data, footer ); - if (s2 == NULL || s2 <= s1) { - return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } + if( s2 == NULL || s2 <= s1 ) + return( MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ); - s1 += strlen(header); - if (*s1 == ' ') { - s1++; - } - if (*s1 == '\r') { - s1++; - } - if (*s1 == '\n') { - s1++; - } else { - return MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } + s1 += strlen( header ); + if( *s1 == ' ' ) s1++; + if( *s1 == '\r' ) s1++; + if( *s1 == '\n' ) s1++; + else return( MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ); end = s2; - end += strlen(footer); - if (*end == ' ') { - end++; - } - if (*end == '\r') { - end++; - } - if (*end == '\n') { - end++; - } - *use_len = (size_t) (end - data); + end += strlen( footer ); + if( *end == ' ' ) end++; + if( *end == '\r' ) end++; + if( *end == '\n' ) end++; + *use_len = end - data; enc = 0; - if (s2 - s1 >= 22 && memcmp(s1, "Proc-Type: 4,ENCRYPTED", 22) == 0) { -#if defined(PEM_RFC1421) + if( s2 - s1 >= 22 && memcmp( s1, "Proc-Type: 4,ENCRYPTED", 22 ) == 0 ) + { +#if defined(MBEDTLS_MD5_C) && defined(MBEDTLS_CIPHER_MODE_CBC) && \ + ( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) ) enc++; s1 += 22; - if (*s1 == '\r') { - s1++; - } - if (*s1 == '\n') { - s1++; - } else { - return MBEDTLS_ERR_PEM_INVALID_DATA; - } + if( *s1 == '\r' ) s1++; + if( *s1 == '\n' ) s1++; + else return( MBEDTLS_ERR_PEM_INVALID_DATA ); #if defined(MBEDTLS_DES_C) - if (s2 - s1 >= 23 && memcmp(s1, "DEK-Info: DES-EDE3-CBC,", 23) == 0) { + if( s2 - s1 >= 23 && memcmp( s1, "DEK-Info: DES-EDE3-CBC,", 23 ) == 0 ) + { enc_alg = MBEDTLS_CIPHER_DES_EDE3_CBC; s1 += 23; - if (s2 - s1 < 16 || pem_get_iv(s1, pem_iv, 8) != 0) { - return MBEDTLS_ERR_PEM_INVALID_ENC_IV; - } + if( s2 - s1 < 16 || pem_get_iv( s1, pem_iv, 8 ) != 0 ) + return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); s1 += 16; - } else if (s2 - s1 >= 18 && memcmp(s1, "DEK-Info: DES-CBC,", 18) == 0) { + } + else if( s2 - s1 >= 18 && memcmp( s1, "DEK-Info: DES-CBC,", 18 ) == 0 ) + { enc_alg = MBEDTLS_CIPHER_DES_CBC; s1 += 18; - if (s2 - s1 < 16 || pem_get_iv(s1, pem_iv, 8) != 0) { - return MBEDTLS_ERR_PEM_INVALID_ENC_IV; - } + if( s2 - s1 < 16 || pem_get_iv( s1, pem_iv, 8) != 0 ) + return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); s1 += 16; } #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_AES_C) - if (s2 - s1 >= 14 && memcmp(s1, "DEK-Info: AES-", 14) == 0) { - if (s2 - s1 < 22) { - return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG; - } else if (memcmp(s1, "DEK-Info: AES-128-CBC,", 22) == 0) { + if( s2 - s1 >= 14 && memcmp( s1, "DEK-Info: AES-", 14 ) == 0 ) + { + if( s2 - s1 < 22 ) + return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ); + else if( memcmp( s1, "DEK-Info: AES-128-CBC,", 22 ) == 0 ) enc_alg = MBEDTLS_CIPHER_AES_128_CBC; - } else if (memcmp(s1, "DEK-Info: AES-192-CBC,", 22) == 0) { + else if( memcmp( s1, "DEK-Info: AES-192-CBC,", 22 ) == 0 ) enc_alg = MBEDTLS_CIPHER_AES_192_CBC; - } else if (memcmp(s1, "DEK-Info: AES-256-CBC,", 22) == 0) { + else if( memcmp( s1, "DEK-Info: AES-256-CBC,", 22 ) == 0 ) enc_alg = MBEDTLS_CIPHER_AES_256_CBC; - } else { - return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG; - } + else + return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ); s1 += 22; - if (s2 - s1 < 32 || pem_get_iv(s1, pem_iv, 16) != 0) { - return MBEDTLS_ERR_PEM_INVALID_ENC_IV; - } + if( s2 - s1 < 32 || pem_get_iv( s1, pem_iv, 16 ) != 0 ) + return( MBEDTLS_ERR_PEM_INVALID_ENC_IV ); s1 += 32; } #endif /* MBEDTLS_AES_C */ - if (enc_alg == MBEDTLS_CIPHER_NONE) { - return MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG; - } + if( enc_alg == MBEDTLS_CIPHER_NONE ) + return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG ); - if (*s1 == '\r') { - s1++; - } - if (*s1 == '\n') { - s1++; - } else { - return MBEDTLS_ERR_PEM_INVALID_DATA; - } + if( *s1 == '\r' ) s1++; + if( *s1 == '\n' ) s1++; + else return( MBEDTLS_ERR_PEM_INVALID_DATA ); #else - return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE; -#endif /* PEM_RFC1421 */ - } - - if (s1 >= s2) { - return MBEDTLS_ERR_PEM_INVALID_DATA; + return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE ); +#endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC && + ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ } - ret = mbedtls_base64_decode(NULL, 0, &len, s1, (size_t) (s2 - s1)); + if( s1 >= s2 ) + return( MBEDTLS_ERR_PEM_INVALID_DATA ); - if (ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret); - } + ret = mbedtls_base64_decode( NULL, 0, &len, s1, s2 - s1 ); - if (len == 0) { - return MBEDTLS_ERR_PEM_BAD_INPUT_DATA; - } + if( ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) ); - if ((buf = (unsigned char *)mbedtls_calloc(1, len)) == NULL) { - return MBEDTLS_ERR_PEM_ALLOC_FAILED; - } + if( ( buf = (unsigned char *) mbedtls_calloc( 1, len ) ) == NULL ) + return( MBEDTLS_ERR_PEM_ALLOC_FAILED ); - if ((ret = mbedtls_base64_decode(buf, len, &len, s1, (size_t) (s2 - s1))) != 0) { - mbedtls_zeroize_and_free(buf, len); - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PEM_INVALID_DATA, ret); + if( ( ret = mbedtls_base64_decode( buf, len, &len, s1, s2 - s1 ) ) != 0 ) + { + mbedtls_platform_zeroize( buf, len ); + mbedtls_free( buf ); + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PEM_INVALID_DATA, ret ) ); } - if (enc != 0) { -#if defined(PEM_RFC1421) - if (pwd == NULL) { - mbedtls_zeroize_and_free(buf, len); - return MBEDTLS_ERR_PEM_PASSWORD_REQUIRED; + if( enc != 0 ) + { +#if defined(MBEDTLS_MD5_C) && defined(MBEDTLS_CIPHER_MODE_CBC) && \ + ( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) ) + if( pwd == NULL ) + { + mbedtls_platform_zeroize( buf, len ); + mbedtls_free( buf ); + return( MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ); } ret = 0; #if defined(MBEDTLS_DES_C) - if (enc_alg == MBEDTLS_CIPHER_DES_EDE3_CBC) { - ret = pem_des3_decrypt(pem_iv, buf, len, pwd, pwdlen); - } else if (enc_alg == MBEDTLS_CIPHER_DES_CBC) { - ret = pem_des_decrypt(pem_iv, buf, len, pwd, pwdlen); - } + if( enc_alg == MBEDTLS_CIPHER_DES_EDE3_CBC ) + ret = pem_des3_decrypt( pem_iv, buf, len, pwd, pwdlen ); + else if( enc_alg == MBEDTLS_CIPHER_DES_CBC ) + ret = pem_des_decrypt( pem_iv, buf, len, pwd, pwdlen ); #endif /* MBEDTLS_DES_C */ #if defined(MBEDTLS_AES_C) - if (enc_alg == MBEDTLS_CIPHER_AES_128_CBC) { - ret = pem_aes_decrypt(pem_iv, 16, buf, len, pwd, pwdlen); - } else if (enc_alg == MBEDTLS_CIPHER_AES_192_CBC) { - ret = pem_aes_decrypt(pem_iv, 24, buf, len, pwd, pwdlen); - } else if (enc_alg == MBEDTLS_CIPHER_AES_256_CBC) { - ret = pem_aes_decrypt(pem_iv, 32, buf, len, pwd, pwdlen); - } + if( enc_alg == MBEDTLS_CIPHER_AES_128_CBC ) + ret = pem_aes_decrypt( pem_iv, 16, buf, len, pwd, pwdlen ); + else if( enc_alg == MBEDTLS_CIPHER_AES_192_CBC ) + ret = pem_aes_decrypt( pem_iv, 24, buf, len, pwd, pwdlen ); + else if( enc_alg == MBEDTLS_CIPHER_AES_256_CBC ) + ret = pem_aes_decrypt( pem_iv, 32, buf, len, pwd, pwdlen ); #endif /* MBEDTLS_AES_C */ - if (ret != 0) { - mbedtls_zeroize_and_free(buf, len); - return ret; + if( ret != 0 ) + { + mbedtls_free( buf ); + return( ret ); } - /* Check PKCS padding and update data length based on padding info. - * This can be used to detect invalid padding data and password - * mismatches. */ - size_t unpadded_len; - ret = pem_check_pkcs_padding(buf, len, &unpadded_len); - if (ret != 0) { - mbedtls_zeroize_and_free(buf, len); - return ret; + /* + * The result will be ASN.1 starting with a SEQUENCE tag, with 1 to 3 + * length bytes (allow 4 to be sure) in all known use cases. + * + * Use that as a heuristic to try to detect password mismatches. + */ + if( len <= 2 || buf[0] != 0x30 || buf[1] > 0x83 ) + { + mbedtls_platform_zeroize( buf, len ); + mbedtls_free( buf ); + return( MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ); } - len = unpadded_len; #else - mbedtls_zeroize_and_free(buf, len); - return MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE; -#endif /* PEM_RFC1421 */ + mbedtls_platform_zeroize( buf, len ); + mbedtls_free( buf ); + return( MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE ); +#endif /* MBEDTLS_MD5_C && MBEDTLS_CIPHER_MODE_CBC && + ( MBEDTLS_AES_C || MBEDTLS_DES_C ) */ } ctx->buf = buf; ctx->buflen = len; - return 0; + return( 0 ); } -void mbedtls_pem_free(mbedtls_pem_context *ctx) +void mbedtls_pem_free( mbedtls_pem_context *ctx ) { - if (ctx == NULL) { - return; + if ( ctx->buf != NULL ) + { + mbedtls_platform_zeroize( ctx->buf, ctx->buflen ); + mbedtls_free( ctx->buf ); } + mbedtls_free( ctx->info ); - if (ctx->buf != NULL) { - mbedtls_zeroize_and_free(ctx->buf, ctx->buflen); - } - mbedtls_free(ctx->info); - - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pem_context)); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_pem_context ) ); } #endif /* MBEDTLS_PEM_PARSE_C */ #if defined(MBEDTLS_PEM_WRITE_C) -int mbedtls_pem_write_buffer(const char *header, const char *footer, - const unsigned char *der_data, size_t der_len, - unsigned char *buf, size_t buf_len, size_t *olen) +int mbedtls_pem_write_buffer( const char *header, const char *footer, + const unsigned char *der_data, size_t der_len, + unsigned char *buf, size_t buf_len, size_t *olen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *encode_buf = NULL, *c, *p = buf; size_t len = 0, use_len, add_len = 0; - mbedtls_base64_encode(NULL, 0, &use_len, der_data, der_len); - add_len = strlen(header) + strlen(footer) + (((use_len > 2) ? (use_len - 2) : 0) / 64) + 1; + mbedtls_base64_encode( NULL, 0, &use_len, der_data, der_len ); + add_len = strlen( header ) + strlen( footer ) + ( use_len / 64 ) + 1; - if (use_len + add_len > buf_len) { + if( use_len + add_len > buf_len ) + { *olen = use_len + add_len; - return MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL; + return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL ); } - if (use_len != 0 && - ((encode_buf = mbedtls_calloc(1, use_len)) == NULL)) { - return MBEDTLS_ERR_PEM_ALLOC_FAILED; - } + if( use_len != 0 && + ( ( encode_buf = mbedtls_calloc( 1, use_len ) ) == NULL ) ) + return( MBEDTLS_ERR_PEM_ALLOC_FAILED ); - if ((ret = mbedtls_base64_encode(encode_buf, use_len, &use_len, der_data, - der_len)) != 0) { - mbedtls_free(encode_buf); - return ret; + if( ( ret = mbedtls_base64_encode( encode_buf, use_len, &use_len, der_data, + der_len ) ) != 0 ) + { + mbedtls_free( encode_buf ); + return( ret ); } - memcpy(p, header, strlen(header)); - p += strlen(header); + memcpy( p, header, strlen( header ) ); + p += strlen( header ); c = encode_buf; - while (use_len) { - len = (use_len > 64) ? 64 : use_len; - memcpy(p, c, len); + while( use_len ) + { + len = ( use_len > 64 ) ? 64 : use_len; + memcpy( p, c, len ); use_len -= len; p += len; c += len; *p++ = '\n'; } - memcpy(p, footer, strlen(footer)); - p += strlen(footer); + memcpy( p, footer, strlen( footer ) ); + p += strlen( footer ); *p++ = '\0'; - *olen = (size_t) (p - buf); + *olen = p - buf; - /* Clean any remaining data previously written to the buffer */ - memset(buf + *olen, 0, buf_len - *olen); + /* Clean any remaining data previously written to the buffer */ + memset( buf + *olen, 0, buf_len - *olen ); - mbedtls_free(encode_buf); - return 0; + mbedtls_free( encode_buf ); + return( 0 ); } #endif /* MBEDTLS_PEM_WRITE_C */ #endif /* MBEDTLS_PEM_PARSE_C || MBEDTLS_PEM_WRITE_C */ + diff --git a/src/duckdb/third_party/mbedtls/library/pk.cpp b/src/duckdb/third_party/mbedtls/library/pk.cpp index a0ff59cee..ea4869c14 100644 --- a/src/duckdb/third_party/mbedtls/library/pk.cpp +++ b/src/duckdb/third_party/mbedtls/library/pk.cpp @@ -2,7 +2,19 @@ * Public Key abstraction layer * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" @@ -10,83 +22,65 @@ #if defined(MBEDTLS_PK_C) #include "mbedtls/pk.h" #include "pk_wrap.h" -#include "pkwrite.h" -#include "pk_internal.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" #if defined(MBEDTLS_RSA_C) #include "mbedtls/rsa.h" -#include "rsa_internal.h" #endif -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_ECP_C) #include "mbedtls/ecp.h" #endif #if defined(MBEDTLS_ECDSA_C) #include "mbedtls/ecdsa.h" #endif -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) -#include "psa_util_internal.h" +#if defined(MBEDTLS_USE_PSA_CRYPTO) #include "mbedtls/psa_util.h" #endif #include #include -#define PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE \ - (PSA_EXPORT_KEY_PAIR_MAX_SIZE > PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) ? \ - PSA_EXPORT_KEY_PAIR_MAX_SIZE : PSA_EXPORT_PUBLIC_KEY_MAX_SIZE +/* Parameter validation macros based on platform_util.h */ +#define PK_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_PK_BAD_INPUT_DATA ) +#define PK_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) /* * Initialise a mbedtls_pk_context */ -void mbedtls_pk_init(mbedtls_pk_context *ctx) +void mbedtls_pk_init( mbedtls_pk_context *ctx ) { + PK_VALIDATE( ctx != NULL ); + ctx->pk_info = NULL; ctx->pk_ctx = NULL; -#if defined(MBEDTLS_USE_PSA_CRYPTO) - ctx->priv_id = MBEDTLS_SVC_KEY_ID_INIT; -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - memset(ctx->pub_raw, 0, sizeof(ctx->pub_raw)); - ctx->pub_raw_len = 0; - ctx->ec_family = 0; - ctx->ec_bits = 0; -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ } /* * Free (the components of) a mbedtls_pk_context */ -void mbedtls_pk_free(mbedtls_pk_context *ctx) +void mbedtls_pk_free( mbedtls_pk_context *ctx ) { - if (ctx == NULL) { + if( ctx == NULL ) return; - } - if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) { - ctx->pk_info->ctx_free_func(ctx->pk_ctx); - } + if ( ctx->pk_info != NULL ) + ctx->pk_info->ctx_free_func( ctx->pk_ctx ); -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - /* The ownership of the priv_id key for opaque keys is external of the PK - * module. It's the user responsibility to clear it after use. */ - if ((ctx->pk_info != NULL) && (ctx->pk_info->type != MBEDTLS_PK_OPAQUE)) { - psa_destroy_key(ctx->priv_id); - } -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ - - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context)); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_pk_context ) ); } #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /* * Initialize a restart context */ -void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx) +void mbedtls_pk_restart_init( mbedtls_pk_restart_ctx *ctx ) { + PK_VALIDATE( ctx != NULL ); ctx->pk_info = NULL; ctx->rs_ctx = NULL; } @@ -94,14 +88,15 @@ void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx) /* * Free the components of a restart context */ -void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx) +void mbedtls_pk_restart_free( mbedtls_pk_restart_ctx *ctx ) { - if (ctx == NULL || ctx->pk_info == NULL || - ctx->pk_info->rs_free_func == NULL) { + if( ctx == NULL || ctx->pk_info == NULL || + ctx->pk_info->rs_free_func == NULL ) + { return; } - ctx->pk_info->rs_free_func(ctx->rs_ctx); + ctx->pk_info->rs_free_func( ctx->rs_ctx ); ctx->pk_info = NULL; ctx->rs_ctx = NULL; @@ -111,84 +106,79 @@ void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx) /* * Get pk_info structure from type */ -const mbedtls_pk_info_t *mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type) +const mbedtls_pk_info_t * mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type ) { - switch (pk_type) { + switch( pk_type ) { #if defined(MBEDTLS_RSA_C) case MBEDTLS_PK_RSA: - return &mbedtls_rsa_info; -#endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) + return( &mbedtls_rsa_info ); +#endif +#if defined(MBEDTLS_ECP_C) case MBEDTLS_PK_ECKEY: - return &mbedtls_eckey_info; + return( &mbedtls_eckey_info ); case MBEDTLS_PK_ECKEY_DH: - return &mbedtls_eckeydh_info; -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ -#if defined(MBEDTLS_PK_CAN_ECDSA_SOME) + return( &mbedtls_eckeydh_info ); +#endif +#if defined(MBEDTLS_ECDSA_C) case MBEDTLS_PK_ECDSA: - return &mbedtls_ecdsa_info; -#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */ + return( &mbedtls_ecdsa_info ); +#endif /* MBEDTLS_PK_RSA_ALT omitted on purpose */ default: - return NULL; + return( NULL ); } } /* * Initialise context */ -int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info) +int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ) { - if (info == NULL || ctx->pk_info != NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( ctx != NULL ); + if( info == NULL || ctx->pk_info != NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - if ((info->ctx_alloc_func != NULL) && - ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL)) { - return MBEDTLS_ERR_PK_ALLOC_FAILED; - } + if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) + return( MBEDTLS_ERR_PK_ALLOC_FAILED ); ctx->pk_info = info; - return 0; + return( 0 ); } #if defined(MBEDTLS_USE_PSA_CRYPTO) /* * Initialise a PSA-wrapping context */ -int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx, - const mbedtls_svc_key_id_t key) +int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx, + const psa_key_id_t key ) { - const mbedtls_pk_info_t *info = NULL; + const mbedtls_pk_info_t * const info = &mbedtls_pk_opaque_info; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + psa_key_id_t *pk_ctx; psa_key_type_t type; - if (ctx == NULL || ctx->pk_info != NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( ctx == NULL || ctx->pk_info != NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - if (PSA_SUCCESS != psa_get_key_attributes(key, &attributes)) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - type = psa_get_key_type(&attributes); - psa_reset_key_attributes(&attributes); - -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type)) { - info = &mbedtls_ecdsa_opaque_info; - } else -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ - if (type == PSA_KEY_TYPE_RSA_KEY_PAIR) { - info = &mbedtls_rsa_opaque_info; - } else { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; - } + if( PSA_SUCCESS != psa_get_key_attributes( key, &attributes ) ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + type = psa_get_key_type( &attributes ); + psa_reset_key_attributes( &attributes ); + + /* Current implementation of can_do() relies on this. */ + if( ! PSA_KEY_TYPE_IS_ECC_KEY_PAIR( type ) ) + return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) ; + + if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) + return( MBEDTLS_ERR_PK_ALLOC_FAILED ); ctx->pk_info = info; - ctx->priv_id = key; - return 0; + pk_ctx = (psa_key_id_t *) ctx->pk_ctx; + *pk_ctx = key; + + return( 0 ); } #endif /* MBEDTLS_USE_PSA_CRYPTO */ @@ -196,21 +186,20 @@ int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx, /* * Initialize an RSA-alt context */ -int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key, - mbedtls_pk_rsa_alt_decrypt_func decrypt_func, - mbedtls_pk_rsa_alt_sign_func sign_func, - mbedtls_pk_rsa_alt_key_len_func key_len_func) +int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key, + mbedtls_pk_rsa_alt_decrypt_func decrypt_func, + mbedtls_pk_rsa_alt_sign_func sign_func, + mbedtls_pk_rsa_alt_key_len_func key_len_func ) { mbedtls_rsa_alt_context *rsa_alt; const mbedtls_pk_info_t *info = &mbedtls_rsa_alt_info; - if (ctx->pk_info != NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( ctx != NULL ); + if( ctx->pk_info != NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - if ((ctx->pk_ctx = info->ctx_alloc_func()) == NULL) { - return MBEDTLS_ERR_PK_ALLOC_FAILED; - } + if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL ) + return( MBEDTLS_ERR_PK_ALLOC_FAILED ); ctx->pk_info = info; @@ -221,1287 +210,440 @@ int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key, rsa_alt->sign_func = sign_func; rsa_alt->key_len_func = key_len_func; - return 0; + return( 0 ); } #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ /* * Tell if a PK can do the operations of the given type */ -int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type) +int mbedtls_pk_can_do( const mbedtls_pk_context *ctx, mbedtls_pk_type_t type ) { /* A context with null pk_info is not set up yet and can't do anything. * For backward compatibility, also accept NULL instead of a context * pointer. */ - if (ctx == NULL || ctx->pk_info == NULL) { - return 0; - } + if( ctx == NULL || ctx->pk_info == NULL ) + return( 0 ); - return ctx->pk_info->can_do(type); + return( ctx->pk_info->can_do( type ) ); } -#if defined(MBEDTLS_USE_PSA_CRYPTO) -/* - * Tell if a PK can do the operations of the given PSA algorithm - */ -int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg, - psa_key_usage_t usage) -{ - psa_key_usage_t key_usage; - - /* A context with null pk_info is not set up yet and can't do anything. - * For backward compatibility, also accept NULL instead of a context - * pointer. */ - if (ctx == NULL || ctx->pk_info == NULL) { - return 0; - } - - /* Filter out non allowed algorithms */ - if (PSA_ALG_IS_ECDSA(alg) == 0 && - PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) == 0 && - PSA_ALG_IS_RSA_PSS(alg) == 0 && - alg != PSA_ALG_RSA_PKCS1V15_CRYPT && - PSA_ALG_IS_ECDH(alg) == 0) { - return 0; - } - - /* Filter out non allowed usage flags */ - if (usage == 0 || - (usage & ~(PSA_KEY_USAGE_SIGN_HASH | - PSA_KEY_USAGE_DECRYPT | - PSA_KEY_USAGE_DERIVE)) != 0) { - return 0; - } - - /* Wildcard hash is not allowed */ - if (PSA_ALG_IS_SIGN_HASH(alg) && - PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH) { - return 0; - } - - if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_OPAQUE) { - mbedtls_pk_type_t type; - - if (PSA_ALG_IS_ECDSA(alg) || PSA_ALG_IS_ECDH(alg)) { - type = MBEDTLS_PK_ECKEY; - } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || - alg == PSA_ALG_RSA_PKCS1V15_CRYPT) { - type = MBEDTLS_PK_RSA; - } else if (PSA_ALG_IS_RSA_PSS(alg)) { - type = MBEDTLS_PK_RSASSA_PSS; - } else { - return 0; - } - - if (ctx->pk_info->can_do(type) == 0) { - return 0; - } - - switch (type) { - case MBEDTLS_PK_ECKEY: - key_usage = PSA_KEY_USAGE_SIGN_HASH | PSA_KEY_USAGE_DERIVE; - break; - case MBEDTLS_PK_RSA: - case MBEDTLS_PK_RSASSA_PSS: - key_usage = PSA_KEY_USAGE_SIGN_HASH | - PSA_KEY_USAGE_SIGN_MESSAGE | - PSA_KEY_USAGE_DECRYPT; - break; - default: - /* Should never happen */ - return 0; - } - - return (key_usage & usage) == usage; - } - - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_status_t status; - - status = psa_get_key_attributes(ctx->priv_id, &attributes); - if (status != PSA_SUCCESS) { - return 0; - } - - psa_algorithm_t key_alg = psa_get_key_algorithm(&attributes); - /* Key's enrollment is available only when an Mbed TLS implementation of PSA - * Crypto is being used, i.e. when MBEDTLS_PSA_CRYPTO_C is defined. - * Even though we don't officially support using other implementations of PSA - * Crypto with TLS and X.509 (yet), we try to keep vendor's customizations - * separated. */ -#if defined(MBEDTLS_PSA_CRYPTO_C) - psa_algorithm_t key_alg2 = psa_get_key_enrollment_algorithm(&attributes); -#endif /* MBEDTLS_PSA_CRYPTO_C */ - key_usage = psa_get_key_usage_flags(&attributes); - psa_reset_key_attributes(&attributes); - - if ((key_usage & usage) != usage) { - return 0; - } - - /* - * Common case: the key alg [or alg2] only allows alg. - * This will match PSA_ALG_RSA_PKCS1V15_CRYPT & PSA_ALG_IS_ECDH - * directly. - * This would also match ECDSA/RSA_PKCS1V15_SIGN/RSA_PSS with - * a fixed hash on key_alg [or key_alg2]. - */ - if (alg == key_alg) { - return 1; - } -#if defined(MBEDTLS_PSA_CRYPTO_C) - if (alg == key_alg2) { - return 1; - } -#endif /* MBEDTLS_PSA_CRYPTO_C */ - - /* - * If key_alg [or key_alg2] is a hash-and-sign with a wildcard for the hash, - * and alg is the same hash-and-sign family with any hash, - * then alg is compliant with this key alg - */ - if (PSA_ALG_IS_SIGN_HASH(alg)) { - if (PSA_ALG_IS_SIGN_HASH(key_alg) && - PSA_ALG_SIGN_GET_HASH(key_alg) == PSA_ALG_ANY_HASH && - (alg & ~PSA_ALG_HASH_MASK) == (key_alg & ~PSA_ALG_HASH_MASK)) { - return 1; - } -#if defined(MBEDTLS_PSA_CRYPTO_C) - if (PSA_ALG_IS_SIGN_HASH(key_alg2) && - PSA_ALG_SIGN_GET_HASH(key_alg2) == PSA_ALG_ANY_HASH && - (alg & ~PSA_ALG_HASH_MASK) == (key_alg2 & ~PSA_ALG_HASH_MASK)) { - return 1; - } -#endif /* MBEDTLS_PSA_CRYPTO_C */ - } - - return 0; -} -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - -#if defined(MBEDTLS_PSA_CRYPTO_CLIENT) -#if defined(MBEDTLS_RSA_C) -static psa_algorithm_t psa_algorithm_for_rsa(const mbedtls_rsa_context *rsa, - int want_crypt) -{ - if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) { - if (want_crypt) { - mbedtls_md_type_t md_type = (mbedtls_md_type_t) mbedtls_rsa_get_md_alg(rsa); - return PSA_ALG_RSA_OAEP(mbedtls_md_psa_alg_from_type(md_type)); - } else { - return PSA_ALG_RSA_PSS_ANY_SALT(PSA_ALG_ANY_HASH); - } - } else { - if (want_crypt) { - return PSA_ALG_RSA_PKCS1V15_CRYPT; - } else { - return PSA_ALG_RSA_PKCS1V15_SIGN(PSA_ALG_ANY_HASH); - } - } -} -#endif /* MBEDTLS_RSA_C */ - -int mbedtls_pk_get_psa_attributes(const mbedtls_pk_context *pk, - psa_key_usage_t usage, - psa_key_attributes_t *attributes) -{ - mbedtls_pk_type_t pk_type = mbedtls_pk_get_type(pk); - - psa_key_usage_t more_usage = usage; - if (usage == PSA_KEY_USAGE_SIGN_MESSAGE) { - more_usage |= PSA_KEY_USAGE_VERIFY_MESSAGE; - } else if (usage == PSA_KEY_USAGE_SIGN_HASH) { - more_usage |= PSA_KEY_USAGE_VERIFY_HASH; - } else if (usage == PSA_KEY_USAGE_DECRYPT) { - more_usage |= PSA_KEY_USAGE_ENCRYPT; - } - more_usage |= PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_COPY; - - int want_private = !(usage == PSA_KEY_USAGE_VERIFY_MESSAGE || - usage == PSA_KEY_USAGE_VERIFY_HASH || - usage == PSA_KEY_USAGE_ENCRYPT); - - switch (pk_type) { -#if defined(MBEDTLS_RSA_C) - case MBEDTLS_PK_RSA: - { - int want_crypt = 0; /* 0: sign/verify; 1: encrypt/decrypt */ - switch (usage) { - case PSA_KEY_USAGE_SIGN_MESSAGE: - case PSA_KEY_USAGE_SIGN_HASH: - case PSA_KEY_USAGE_VERIFY_MESSAGE: - case PSA_KEY_USAGE_VERIFY_HASH: - /* Nothing to do. */ - break; - case PSA_KEY_USAGE_DECRYPT: - case PSA_KEY_USAGE_ENCRYPT: - want_crypt = 1; - break; - default: - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - /* Detect the presence of a private key in a way that works both - * in CRT and non-CRT configurations. */ - mbedtls_rsa_context *rsa = mbedtls_pk_rsa(*pk); - int has_private = (mbedtls_rsa_check_privkey(rsa) == 0); - if (want_private && !has_private) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - psa_set_key_type(attributes, (want_private ? - PSA_KEY_TYPE_RSA_KEY_PAIR : - PSA_KEY_TYPE_RSA_PUBLIC_KEY)); - psa_set_key_bits(attributes, mbedtls_pk_get_bitlen(pk)); - psa_set_key_algorithm(attributes, - psa_algorithm_for_rsa(rsa, want_crypt)); - break; - } -#endif /* MBEDTLS_RSA_C */ - -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - case MBEDTLS_PK_ECKEY: - case MBEDTLS_PK_ECKEY_DH: - case MBEDTLS_PK_ECDSA: - { - int sign_ok = (pk_type != MBEDTLS_PK_ECKEY_DH); - int derive_ok = (pk_type != MBEDTLS_PK_ECDSA); -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - psa_ecc_family_t family = pk->ec_family; - size_t bits = pk->ec_bits; - int has_private = 0; - if (pk->priv_id != MBEDTLS_SVC_KEY_ID_INIT) { - has_private = 1; - } -#else - const mbedtls_ecp_keypair *ec = mbedtls_pk_ec_ro(*pk); - int has_private = (ec->d.n != 0); - size_t bits = 0; - psa_ecc_family_t family = - mbedtls_ecc_group_to_psa(ec->grp.id, &bits); -#endif - psa_algorithm_t alg = 0; - switch (usage) { - case PSA_KEY_USAGE_SIGN_MESSAGE: - case PSA_KEY_USAGE_SIGN_HASH: - case PSA_KEY_USAGE_VERIFY_MESSAGE: - case PSA_KEY_USAGE_VERIFY_HASH: - if (!sign_ok) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } -#if defined(MBEDTLS_ECDSA_DETERMINISTIC) - alg = PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_ANY_HASH); -#else - alg = PSA_ALG_ECDSA(PSA_ALG_ANY_HASH); -#endif - break; - case PSA_KEY_USAGE_DERIVE: - alg = PSA_ALG_ECDH; - if (!derive_ok) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - break; - default: - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - if (want_private && !has_private) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - psa_set_key_type(attributes, (want_private ? - PSA_KEY_TYPE_ECC_KEY_PAIR(family) : - PSA_KEY_TYPE_ECC_PUBLIC_KEY(family))); - psa_set_key_bits(attributes, bits); - psa_set_key_algorithm(attributes, alg); - break; - } -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ - -#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) - case MBEDTLS_PK_RSA_ALT: - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; -#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ - -#if defined(MBEDTLS_USE_PSA_CRYPTO) - case MBEDTLS_PK_OPAQUE: - { - psa_key_attributes_t old_attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; - status = psa_get_key_attributes(pk->priv_id, &old_attributes); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - psa_key_type_t old_type = psa_get_key_type(&old_attributes); - switch (usage) { - case PSA_KEY_USAGE_SIGN_MESSAGE: - case PSA_KEY_USAGE_SIGN_HASH: - case PSA_KEY_USAGE_VERIFY_MESSAGE: - case PSA_KEY_USAGE_VERIFY_HASH: - if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type) || - old_type == PSA_KEY_TYPE_RSA_KEY_PAIR)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - break; - case PSA_KEY_USAGE_DECRYPT: - case PSA_KEY_USAGE_ENCRYPT: - if (old_type != PSA_KEY_TYPE_RSA_KEY_PAIR) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - break; - case PSA_KEY_USAGE_DERIVE: - if (!(PSA_KEY_TYPE_IS_ECC_KEY_PAIR(old_type))) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - break; - default: - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - psa_key_type_t new_type = old_type; - /* Opaque keys are always key pairs, so we don't need a check - * on the input if the required usage is private. We just need - * to adjust the type correctly if the required usage is public. */ - if (!want_private) { - new_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(new_type); - } - more_usage = psa_get_key_usage_flags(&old_attributes); - if ((usage & more_usage) == 0) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - psa_set_key_type(attributes, new_type); - psa_set_key_bits(attributes, psa_get_key_bits(&old_attributes)); - psa_set_key_algorithm(attributes, psa_get_key_algorithm(&old_attributes)); - break; - } -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - - default: - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - psa_set_key_usage_flags(attributes, more_usage); - /* Key's enrollment is available only when an Mbed TLS implementation of PSA - * Crypto is being used, i.e. when MBEDTLS_PSA_CRYPTO_C is defined. - * Even though we don't officially support using other implementations of PSA - * Crypto with TLS and X.509 (yet), we try to keep vendor's customizations - * separated. */ -#if defined(MBEDTLS_PSA_CRYPTO_C) - psa_set_key_enrollment_algorithm(attributes, PSA_ALG_NONE); -#endif - - return 0; -} - -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) || defined(MBEDTLS_USE_PSA_CRYPTO) -static psa_status_t export_import_into_psa(mbedtls_svc_key_id_t old_key_id, - const psa_key_attributes_t *attributes, - mbedtls_svc_key_id_t *new_key_id) -{ - unsigned char key_buffer[PSA_EXPORT_KEY_PAIR_MAX_SIZE]; - size_t key_length = 0; - psa_status_t status = psa_export_key(old_key_id, - key_buffer, sizeof(key_buffer), - &key_length); - if (status != PSA_SUCCESS) { - return status; - } - status = psa_import_key(attributes, key_buffer, key_length, new_key_id); - mbedtls_platform_zeroize(key_buffer, key_length); - return status; -} - -static int copy_into_psa(mbedtls_svc_key_id_t old_key_id, - const psa_key_attributes_t *attributes, - mbedtls_svc_key_id_t *new_key_id) -{ - /* Normally, we prefer copying: it's more efficient and works even - * for non-exportable keys. */ - psa_status_t status = psa_copy_key(old_key_id, attributes, new_key_id); - if (status == PSA_ERROR_NOT_PERMITTED /*missing COPY usage*/ || - status == PSA_ERROR_INVALID_ARGUMENT /*incompatible policy*/) { - /* There are edge cases where copying won't work, but export+import - * might: - * - If the old key does not allow PSA_KEY_USAGE_COPY. - * - If the old key's usage does not allow what attributes wants. - * Because the key was intended for use in the pk module, and may - * have had a policy chosen solely for what pk needs rather than - * based on a detailed understanding of PSA policies, we are a bit - * more liberal than psa_copy_key() here. - */ - /* Here we need to check that the types match, otherwise we risk - * importing nonsensical data. */ - psa_key_attributes_t old_attributes = PSA_KEY_ATTRIBUTES_INIT; - status = psa_get_key_attributes(old_key_id, &old_attributes); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - psa_key_type_t old_type = psa_get_key_type(&old_attributes); - psa_reset_key_attributes(&old_attributes); - if (old_type != psa_get_key_type(attributes)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - status = export_import_into_psa(old_key_id, attributes, new_key_id); - } - return PSA_PK_TO_MBEDTLS_ERR(status); -} -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA || MBEDTLS_USE_PSA_CRYPTO */ - -static int import_pair_into_psa(const mbedtls_pk_context *pk, - const psa_key_attributes_t *attributes, - mbedtls_svc_key_id_t *key_id) -{ - switch (mbedtls_pk_get_type(pk)) { -#if defined(MBEDTLS_RSA_C) - case MBEDTLS_PK_RSA: - { - if (psa_get_key_type(attributes) != PSA_KEY_TYPE_RSA_KEY_PAIR) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - unsigned char key_buffer[ - PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)]; - unsigned char *const key_end = key_buffer + sizeof(key_buffer); - unsigned char *key_data = key_end; - int ret = mbedtls_rsa_write_key(mbedtls_pk_rsa(*pk), - key_buffer, &key_data); - if (ret < 0) { - return ret; - } - size_t key_length = key_end - key_data; - ret = PSA_PK_TO_MBEDTLS_ERR(psa_import_key(attributes, - key_data, key_length, - key_id)); - mbedtls_platform_zeroize(key_data, key_length); - return ret; - } -#endif /* MBEDTLS_RSA_C */ - -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - case MBEDTLS_PK_ECKEY: - case MBEDTLS_PK_ECKEY_DH: - case MBEDTLS_PK_ECDSA: - { - /* We need to check the curve family, otherwise the import could - * succeed with nonsensical data. - * We don't check the bit-size: it's optional in attributes, - * and if it's specified, psa_import_key() will know from the key - * data length and will check that the bit-size matches. */ - psa_key_type_t to_type = psa_get_key_type(attributes); -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - psa_ecc_family_t from_family = pk->ec_family; -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - const mbedtls_ecp_keypair *ec = mbedtls_pk_ec_ro(*pk); - size_t from_bits = 0; - psa_ecc_family_t from_family = mbedtls_ecc_group_to_psa(ec->grp.id, - &from_bits); -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ - if (to_type != PSA_KEY_TYPE_ECC_KEY_PAIR(from_family)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - if (mbedtls_svc_key_id_is_null(pk->priv_id)) { - /* We have a public key and want a key pair. */ - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - return copy_into_psa(pk->priv_id, attributes, key_id); -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - if (ec->d.n == 0) { - /* Private key not set. Assume the input is a public key only. - * (The other possibility is that it's an incomplete object - * where the group is set but neither the public key nor - * the private key. This is not possible through ecp.h - * functions, so we don't bother reporting a more suitable - * error in that case.) */ - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - unsigned char key_buffer[PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)]; - size_t key_length = 0; - int ret = mbedtls_ecp_write_key_ext(ec, &key_length, - key_buffer, sizeof(key_buffer)); - if (ret < 0) { - return ret; - } - ret = PSA_PK_TO_MBEDTLS_ERR(psa_import_key(attributes, - key_buffer, key_length, - key_id)); - mbedtls_platform_zeroize(key_buffer, key_length); - return ret; -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ - } -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ - -#if defined(MBEDTLS_USE_PSA_CRYPTO) - case MBEDTLS_PK_OPAQUE: - return copy_into_psa(pk->priv_id, attributes, key_id); -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - - default: - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } -} - -static int import_public_into_psa(const mbedtls_pk_context *pk, - const psa_key_attributes_t *attributes, - mbedtls_svc_key_id_t *key_id) -{ - psa_key_type_t psa_type = psa_get_key_type(attributes); - -#if defined(MBEDTLS_RSA_C) || \ - (defined(MBEDTLS_PK_HAVE_ECC_KEYS) && !defined(MBEDTLS_PK_USE_PSA_EC_DATA)) || \ - defined(MBEDTLS_USE_PSA_CRYPTO) - unsigned char key_buffer[PSA_EXPORT_PUBLIC_KEY_MAX_SIZE]; -#endif - unsigned char *key_data = NULL; - size_t key_length = 0; - - switch (mbedtls_pk_get_type(pk)) { -#if defined(MBEDTLS_RSA_C) - case MBEDTLS_PK_RSA: - { - if (psa_type != PSA_KEY_TYPE_RSA_PUBLIC_KEY) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - unsigned char *const key_end = key_buffer + sizeof(key_buffer); - key_data = key_end; - int ret = mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*pk), - key_buffer, &key_data); - if (ret < 0) { - return ret; - } - key_length = (size_t) ret; - break; - } -#endif /*MBEDTLS_RSA_C */ - -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - case MBEDTLS_PK_ECKEY: - case MBEDTLS_PK_ECKEY_DH: - case MBEDTLS_PK_ECDSA: - { - /* We need to check the curve family, otherwise the import could - * succeed with nonsensical data. - * We don't check the bit-size: it's optional in attributes, - * and if it's specified, psa_import_key() will know from the key - * data length and will check that the bit-size matches. */ -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(pk->ec_family)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - key_data = (unsigned char *) pk->pub_raw; - key_length = pk->pub_raw_len; -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - const mbedtls_ecp_keypair *ec = mbedtls_pk_ec_ro(*pk); - size_t from_bits = 0; - psa_ecc_family_t from_family = mbedtls_ecc_group_to_psa(ec->grp.id, - &from_bits); - if (psa_type != PSA_KEY_TYPE_ECC_PUBLIC_KEY(from_family)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - int ret = mbedtls_ecp_write_public_key( - ec, MBEDTLS_ECP_PF_UNCOMPRESSED, - &key_length, key_buffer, sizeof(key_buffer)); - if (ret < 0) { - return ret; - } - key_data = key_buffer; -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ - break; - } -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ - -#if defined(MBEDTLS_USE_PSA_CRYPTO) - case MBEDTLS_PK_OPAQUE: - { - psa_key_attributes_t old_attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_status_t status = - psa_get_key_attributes(pk->priv_id, &old_attributes); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - psa_key_type_t old_type = psa_get_key_type(&old_attributes); - psa_reset_key_attributes(&old_attributes); - if (psa_type != PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(old_type)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - status = psa_export_public_key(pk->priv_id, - key_buffer, sizeof(key_buffer), - &key_length); - if (status != PSA_SUCCESS) { - return PSA_PK_TO_MBEDTLS_ERR(status); - } - key_data = key_buffer; - break; - } -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - - default: - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - return PSA_PK_TO_MBEDTLS_ERR(psa_import_key(attributes, - key_data, key_length, - key_id)); -} - -int mbedtls_pk_import_into_psa(const mbedtls_pk_context *pk, - const psa_key_attributes_t *attributes, - mbedtls_svc_key_id_t *key_id) -{ - /* Set the output immediately so that it won't contain garbage even - * if we error out before calling psa_import_key(). */ - *key_id = MBEDTLS_SVC_KEY_ID_INIT; - -#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) - if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_RSA_ALT) { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; - } -#endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ - - int want_public = PSA_KEY_TYPE_IS_PUBLIC_KEY(psa_get_key_type(attributes)); - if (want_public) { - return import_public_into_psa(pk, attributes, key_id); - } else { - return import_pair_into_psa(pk, attributes, key_id); - } -} - -static int copy_from_psa(mbedtls_svc_key_id_t key_id, - mbedtls_pk_context *pk, - int public_only) -{ - psa_status_t status; - psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; - psa_key_type_t key_type; - size_t key_bits; - /* Use a buffer size large enough to contain either a key pair or public key. */ - unsigned char exp_key[PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE]; - size_t exp_key_len; - int ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; - - if (pk == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - status = psa_get_key_attributes(key_id, &key_attr); - if (status != PSA_SUCCESS) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - if (public_only) { - status = psa_export_public_key(key_id, exp_key, sizeof(exp_key), &exp_key_len); - } else { - status = psa_export_key(key_id, exp_key, sizeof(exp_key), &exp_key_len); - } - if (status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - goto exit; - } - - key_type = psa_get_key_type(&key_attr); - if (public_only) { - key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type); - } - key_bits = psa_get_key_bits(&key_attr); - -#if defined(MBEDTLS_RSA_C) - if ((key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) || - (key_type == PSA_KEY_TYPE_RSA_PUBLIC_KEY)) { - - ret = mbedtls_pk_setup(pk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)); - if (ret != 0) { - goto exit; - } - - if (key_type == PSA_KEY_TYPE_RSA_KEY_PAIR) { - ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), exp_key, exp_key_len); - } else { - ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*pk), exp_key, exp_key_len); - } - if (ret != 0) { - goto exit; - } - - psa_algorithm_t alg_type = psa_get_key_algorithm(&key_attr); - mbedtls_md_type_t md_type = MBEDTLS_MD_NONE; - if (PSA_ALG_GET_HASH(alg_type) != PSA_ALG_ANY_HASH) { - md_type = mbedtls_md_type_from_psa_alg(alg_type); - } - - if (PSA_ALG_IS_RSA_OAEP(alg_type) || PSA_ALG_IS_RSA_PSS(alg_type)) { - ret = mbedtls_rsa_set_padding(mbedtls_pk_rsa(*pk), MBEDTLS_RSA_PKCS_V21, md_type); - } else if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg_type) || - alg_type == PSA_ALG_RSA_PKCS1V15_CRYPT) { - ret = mbedtls_rsa_set_padding(mbedtls_pk_rsa(*pk), MBEDTLS_RSA_PKCS_V15, md_type); - } - if (ret != 0) { - goto exit; - } - } else -#endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) || - PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type)) { - mbedtls_ecp_group_id grp_id; - - ret = mbedtls_pk_setup(pk, mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY)); - if (ret != 0) { - goto exit; - } - - grp_id = mbedtls_ecc_group_from_psa(PSA_KEY_TYPE_ECC_GET_FAMILY(key_type), key_bits); - ret = mbedtls_pk_ecc_set_group(pk, grp_id); - if (ret != 0) { - goto exit; - } - - if (PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type)) { - ret = mbedtls_pk_ecc_set_key(pk, exp_key, exp_key_len); - if (ret != 0) { - goto exit; - } - ret = mbedtls_pk_ecc_set_pubkey_from_prv(pk, exp_key, exp_key_len, - mbedtls_psa_get_random, - MBEDTLS_PSA_RANDOM_STATE); - } else { - ret = mbedtls_pk_ecc_set_pubkey(pk, exp_key, exp_key_len); - } - if (ret != 0) { - goto exit; - } - } else -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ - { - (void) key_bits; - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - -exit: - psa_reset_key_attributes(&key_attr); - mbedtls_platform_zeroize(exp_key, sizeof(exp_key)); - - return ret; -} - -int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id, - mbedtls_pk_context *pk) -{ - return copy_from_psa(key_id, pk, 0); -} - -int mbedtls_pk_copy_public_from_psa(mbedtls_svc_key_id_t key_id, - mbedtls_pk_context *pk) -{ - return copy_from_psa(key_id, pk, 1); -} -#endif /* MBEDTLS_PSA_CRYPTO_CLIENT */ - /* * Helper for mbedtls_pk_sign and mbedtls_pk_verify */ -inline int pk_hashlen_helper(mbedtls_md_type_t md_alg, size_t *hash_len) +static inline int pk_hashlen_helper( mbedtls_md_type_t md_alg, size_t *hash_len ) { - if (*hash_len != 0) { - return 0; - } + const mbedtls_md_info_t *md_info; - *hash_len = mbedtls_md_get_size_from_type(md_alg); + if( *hash_len != 0 ) + return( 0 ); - if (*hash_len == 0) { - return -1; - } + if( ( md_info = mbedtls_md_info_from_type( md_alg ) ) == NULL ) + return( -1 ); - return 0; + *hash_len = mbedtls_md_get_size( md_info ); + return( 0 ); } #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /* * Helper to set up a restart context if needed */ -static int pk_restart_setup(mbedtls_pk_restart_ctx *ctx, - const mbedtls_pk_info_t *info) +static int pk_restart_setup( mbedtls_pk_restart_ctx *ctx, + const mbedtls_pk_info_t *info ) { /* Don't do anything if already set up or invalid */ - if (ctx == NULL || ctx->pk_info != NULL) { - return 0; - } + if( ctx == NULL || ctx->pk_info != NULL ) + return( 0 ); /* Should never happen when we're called */ - if (info->rs_alloc_func == NULL || info->rs_free_func == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( info->rs_alloc_func == NULL || info->rs_free_func == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - if ((ctx->rs_ctx = info->rs_alloc_func()) == NULL) { - return MBEDTLS_ERR_PK_ALLOC_FAILED; - } + if( ( ctx->rs_ctx = info->rs_alloc_func() ) == NULL ) + return( MBEDTLS_ERR_PK_ALLOC_FAILED ); ctx->pk_info = info; - return 0; + return( 0 ); } #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ /* * Verify a signature (restartable) */ -int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len, - mbedtls_pk_restart_ctx *rs_ctx) +int mbedtls_pk_verify_restartable( mbedtls_pk_context *ctx, + mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + mbedtls_pk_restart_ctx *rs_ctx ) { - if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( ctx != NULL ); + PK_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && hash_len == 0 ) || + hash != NULL ); + PK_VALIDATE_RET( sig != NULL ); - if (ctx->pk_info == NULL || - pk_hashlen_helper(md_alg, &hash_len) != 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( ctx->pk_info == NULL || + pk_hashlen_helper( md_alg, &hash_len ) != 0 ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /* optimization: use non-restartable version if restart disabled */ - if (rs_ctx != NULL && + if( rs_ctx != NULL && mbedtls_ecp_restart_is_enabled() && - ctx->pk_info->verify_rs_func != NULL) { + ctx->pk_info->verify_rs_func != NULL ) + { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { - return ret; - } + if( ( ret = pk_restart_setup( rs_ctx, ctx->pk_info ) ) != 0 ) + return( ret ); - ret = ctx->pk_info->verify_rs_func(ctx, - md_alg, hash, hash_len, sig, sig_len, rs_ctx->rs_ctx); + ret = ctx->pk_info->verify_rs_func( ctx->pk_ctx, + md_alg, hash, hash_len, sig, sig_len, rs_ctx->rs_ctx ); - if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) { - mbedtls_pk_restart_free(rs_ctx); - } + if( ret != MBEDTLS_ERR_ECP_IN_PROGRESS ) + mbedtls_pk_restart_free( rs_ctx ); - return ret; + return( ret ); } #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ (void) rs_ctx; #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - if (ctx->pk_info->verify_func == NULL) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } + if( ctx->pk_info->verify_func == NULL ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); - return ctx->pk_info->verify_func(ctx, md_alg, hash, hash_len, - sig, sig_len); + return( ctx->pk_info->verify_func( ctx->pk_ctx, md_alg, hash, hash_len, + sig, sig_len ) ); } /* * Verify a signature */ -int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) +int mbedtls_pk_verify( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ) { - return mbedtls_pk_verify_restartable(ctx, md_alg, hash, hash_len, - sig, sig_len, NULL); + return( mbedtls_pk_verify_restartable( ctx, md_alg, hash, hash_len, + sig, sig_len, NULL ) ); } /* * Verify a signature with options */ -int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options, - mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) +int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options, + mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ) { - if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( ctx != NULL ); + PK_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && hash_len == 0 ) || + hash != NULL ); + PK_VALIDATE_RET( sig != NULL ); - if (ctx->pk_info == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( ctx->pk_info == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - if (!mbedtls_pk_can_do(ctx, type)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } + if( ! mbedtls_pk_can_do( ctx, type ) ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); - if (type != MBEDTLS_PK_RSASSA_PSS) { - /* General case: no options */ - if (options != NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( type == MBEDTLS_PK_RSASSA_PSS ) + { +#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + const mbedtls_pk_rsassa_pss_options *pss_opts; - return mbedtls_pk_verify(ctx, md_alg, hash, hash_len, sig, sig_len); - } +#if SIZE_MAX > UINT_MAX + if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); +#endif /* SIZE_MAX > UINT_MAX */ - /* Ensure the PK context is of the right type otherwise mbedtls_pk_rsa() - * below would return a NULL pointer. */ - if (mbedtls_pk_get_type(ctx) != MBEDTLS_PK_RSA) { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; - } + if( options == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); -#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - const mbedtls_pk_rsassa_pss_options *pss_opts; + pss_opts = (const mbedtls_pk_rsassa_pss_options *) options; -#if SIZE_MAX > UINT_MAX - if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } -#endif + if( sig_len < mbedtls_pk_get_len( ctx ) ) + return( MBEDTLS_ERR_RSA_VERIFY_FAILED ); - if (options == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + ret = mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_pk_rsa( *ctx ), + md_alg, (unsigned int) hash_len, hash, + pss_opts->mgf1_hash_id, + pss_opts->expected_salt_len, + sig ); + if( ret != 0 ) + return( ret ); - pss_opts = (const mbedtls_pk_rsassa_pss_options *) options; + if( sig_len > mbedtls_pk_get_len( ctx ) ) + return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); -#if defined(MBEDTLS_USE_PSA_CRYPTO) - if (pss_opts->mgf1_hash_id == md_alg) { - unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES]; - unsigned char *p; - int key_len; - size_t signature_length; - psa_status_t status = PSA_ERROR_DATA_CORRUPT; - psa_status_t destruction_status = PSA_ERROR_DATA_CORRUPT; - - psa_algorithm_t psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg); - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_algorithm_t psa_sig_alg = PSA_ALG_RSA_PSS_ANY_SALT(psa_md_alg); - p = buf + sizeof(buf); - key_len = mbedtls_rsa_write_pubkey(mbedtls_pk_rsa(*ctx), buf, &p); - - if (key_len < 0) { - return key_len; - } - - psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY); - psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH); - psa_set_key_algorithm(&attributes, psa_sig_alg); - - status = psa_import_key(&attributes, - buf + sizeof(buf) - key_len, key_len, - &key_id); - if (status != PSA_SUCCESS) { - psa_destroy_key(key_id); - return PSA_PK_TO_MBEDTLS_ERR(status); - } - - /* This function requires returning MBEDTLS_ERR_PK_SIG_LEN_MISMATCH - * on a valid signature with trailing data in a buffer, but - * mbedtls_psa_rsa_verify_hash requires the sig_len to be exact, - * so for this reason the passed sig_len is overwritten. Smaller - * signature lengths should not be accepted for verification. */ - signature_length = sig_len > mbedtls_pk_get_len(ctx) ? - mbedtls_pk_get_len(ctx) : sig_len; - status = psa_verify_hash(key_id, psa_sig_alg, hash, - hash_len, sig, signature_length); - destruction_status = psa_destroy_key(key_id); - - if (status == PSA_SUCCESS && sig_len > mbedtls_pk_get_len(ctx)) { - return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH; - } - - if (status == PSA_SUCCESS) { - status = destruction_status; - } - - return PSA_PK_RSA_TO_MBEDTLS_ERR(status); - } else -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - { - if (sig_len < mbedtls_pk_get_len(ctx)) { - return MBEDTLS_ERR_RSA_VERIFY_FAILED; - } - - ret = mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_pk_rsa(*ctx), - md_alg, (unsigned int) hash_len, hash, - pss_opts->mgf1_hash_id, - pss_opts->expected_salt_len, - sig); - if (ret != 0) { - return ret; - } - - if (sig_len > mbedtls_pk_get_len(ctx)) { - return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH; - } - - return 0; - } + return( 0 ); #else - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; + return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); #endif /* MBEDTLS_RSA_C && MBEDTLS_PKCS1_V21 */ + } + + /* General case: no options */ + if( options != NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + + return( mbedtls_pk_verify( ctx, md_alg, hash, hash_len, sig, sig_len ) ); } /* * Make a signature (restartable) */ -int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, - mbedtls_pk_restart_ctx *rs_ctx) -{ - if ((md_alg != MBEDTLS_MD_NONE || hash_len != 0) && hash == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - if (ctx->pk_info == NULL || pk_hashlen_helper(md_alg, &hash_len) != 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } +int mbedtls_pk_sign_restartable( mbedtls_pk_context *ctx, + mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + mbedtls_pk_restart_ctx *rs_ctx ) +{ + PK_VALIDATE_RET( ctx != NULL ); + PK_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && hash_len == 0 ) || + hash != NULL ); + PK_VALIDATE_RET( sig != NULL ); + + if( ctx->pk_info == NULL || + pk_hashlen_helper( md_alg, &hash_len ) != 0 ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /* optimization: use non-restartable version if restart disabled */ - if (rs_ctx != NULL && + if( rs_ctx != NULL && mbedtls_ecp_restart_is_enabled() && - ctx->pk_info->sign_rs_func != NULL) { + ctx->pk_info->sign_rs_func != NULL ) + { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - if ((ret = pk_restart_setup(rs_ctx, ctx->pk_info)) != 0) { - return ret; - } + if( ( ret = pk_restart_setup( rs_ctx, ctx->pk_info ) ) != 0 ) + return( ret ); - ret = ctx->pk_info->sign_rs_func(ctx, md_alg, - hash, hash_len, - sig, sig_size, sig_len, - f_rng, p_rng, rs_ctx->rs_ctx); + ret = ctx->pk_info->sign_rs_func( ctx->pk_ctx, md_alg, + hash, hash_len, + sig, sig_size, sig_len, + f_rng, p_rng, rs_ctx->rs_ctx ); - if (ret != MBEDTLS_ERR_ECP_IN_PROGRESS) { - mbedtls_pk_restart_free(rs_ctx); - } + if( ret != MBEDTLS_ERR_ECP_IN_PROGRESS ) + mbedtls_pk_restart_free( rs_ctx ); - return ret; + return( ret ); } #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ (void) rs_ctx; #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - if (ctx->pk_info->sign_func == NULL) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } + if( ctx->pk_info->sign_func == NULL ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); - return ctx->pk_info->sign_func(ctx, md_alg, - hash, hash_len, - sig, sig_size, sig_len, - f_rng, p_rng); + return( ctx->pk_info->sign_func( ctx->pk_ctx, md_alg, + hash, hash_len, + sig, sig_size, sig_len, + f_rng, p_rng ) ); } /* * Make a signature */ -int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +int mbedtls_pk_sign( mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - return mbedtls_pk_sign_restartable(ctx, md_alg, hash, hash_len, - sig, sig_size, sig_len, - f_rng, p_rng, NULL); -} - -/* - * Make a signature given a signature type. - */ -int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type, - mbedtls_pk_context *ctx, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) -{ - if (ctx->pk_info == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - if (!mbedtls_pk_can_do(ctx, pk_type)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - - if (pk_type != MBEDTLS_PK_RSASSA_PSS) { - return mbedtls_pk_sign(ctx, md_alg, hash, hash_len, - sig, sig_size, sig_len, f_rng, p_rng); - } - -#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PKCS1_V21) - -#if defined(MBEDTLS_USE_PSA_CRYPTO) - const psa_algorithm_t psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg); - if (psa_md_alg == 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - if (mbedtls_pk_get_type(ctx) == MBEDTLS_PK_OPAQUE) { - psa_status_t status; - - /* PSA_ALG_RSA_PSS() behaves the same as PSA_ALG_RSA_PSS_ANY_SALT() when - * performing a signature, but they are encoded differently. Instead of - * extracting the proper one from the wrapped key policy, just try both. */ - status = psa_sign_hash(ctx->priv_id, PSA_ALG_RSA_PSS(psa_md_alg), - hash, hash_len, - sig, sig_size, sig_len); - if (status == PSA_ERROR_NOT_PERMITTED) { - status = psa_sign_hash(ctx->priv_id, PSA_ALG_RSA_PSS_ANY_SALT(psa_md_alg), - hash, hash_len, - sig, sig_size, sig_len); - } - return PSA_PK_RSA_TO_MBEDTLS_ERR(status); - } - - return mbedtls_pk_psa_rsa_sign_ext(PSA_ALG_RSA_PSS(psa_md_alg), - ctx->pk_ctx, hash, hash_len, - sig, sig_size, sig_len); -#else /* MBEDTLS_USE_PSA_CRYPTO */ - - if (sig_size < mbedtls_pk_get_len(ctx)) { - return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL; - } - - if (pk_hashlen_helper(md_alg, &hash_len) != 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - mbedtls_rsa_context *const rsa_ctx = mbedtls_pk_rsa(*ctx); - - const int ret = mbedtls_rsa_rsassa_pss_sign_no_mode_check(rsa_ctx, f_rng, p_rng, md_alg, - (unsigned int) hash_len, hash, sig); - if (ret == 0) { - *sig_len = rsa_ctx->len; - } - return ret; - -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - -#else - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; -#endif /* MBEDTLS_RSA_C && MBEDTLS_PKCS1_V21 */ + return( mbedtls_pk_sign_restartable( ctx, md_alg, hash, hash_len, + sig, sig_size, sig_len, + f_rng, p_rng, NULL ) ); } /* * Decrypt message */ -int mbedtls_pk_decrypt(mbedtls_pk_context *ctx, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +int mbedtls_pk_decrypt( mbedtls_pk_context *ctx, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - if (ctx->pk_info == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( ctx != NULL ); + PK_VALIDATE_RET( input != NULL || ilen == 0 ); + PK_VALIDATE_RET( output != NULL || osize == 0 ); + PK_VALIDATE_RET( olen != NULL ); - if (ctx->pk_info->decrypt_func == NULL) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } + if( ctx->pk_info == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - return ctx->pk_info->decrypt_func(ctx, input, ilen, - output, olen, osize, f_rng, p_rng); + if( ctx->pk_info->decrypt_func == NULL ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + + return( ctx->pk_info->decrypt_func( ctx->pk_ctx, input, ilen, + output, olen, osize, f_rng, p_rng ) ); } /* * Encrypt message */ -int mbedtls_pk_encrypt(mbedtls_pk_context *ctx, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +int mbedtls_pk_encrypt( mbedtls_pk_context *ctx, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - if (ctx->pk_info == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( ctx != NULL ); + PK_VALIDATE_RET( input != NULL || ilen == 0 ); + PK_VALIDATE_RET( output != NULL || osize == 0 ); + PK_VALIDATE_RET( olen != NULL ); - if (ctx->pk_info->encrypt_func == NULL) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } + if( ctx->pk_info == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - return ctx->pk_info->encrypt_func(ctx, input, ilen, - output, olen, osize, f_rng, p_rng); + if( ctx->pk_info->encrypt_func == NULL ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + + return( ctx->pk_info->encrypt_func( ctx->pk_ctx, input, ilen, + output, olen, osize, f_rng, p_rng ) ); } /* * Check public-private key pair */ -int mbedtls_pk_check_pair(const mbedtls_pk_context *pub, - const mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +int mbedtls_pk_check_pair( const mbedtls_pk_context *pub, + const mbedtls_pk_context *prv, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { - if (pub->pk_info == NULL || - prv->pk_info == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( pub != NULL ); + PK_VALIDATE_RET( prv != NULL ); - if (f_rng == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; + if( pub->pk_info == NULL || + prv->pk_info == NULL ) + { + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); } - if (prv->pk_info->check_pair_func == NULL) { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; - } + if( f_rng == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - if (prv->pk_info->type == MBEDTLS_PK_RSA_ALT) { - if (pub->pk_info->type != MBEDTLS_PK_RSA) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } - } else { - if ((prv->pk_info->type != MBEDTLS_PK_OPAQUE) && - (pub->pk_info != prv->pk_info)) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } + if( prv->pk_info->check_pair_func == NULL ) + return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + + if( prv->pk_info->type == MBEDTLS_PK_RSA_ALT ) + { + if( pub->pk_info->type != MBEDTLS_PK_RSA ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + } + else + { + if( pub->pk_info != prv->pk_info ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); } - return prv->pk_info->check_pair_func((mbedtls_pk_context *) pub, - (mbedtls_pk_context *) prv, - f_rng, p_rng); + return( prv->pk_info->check_pair_func( pub->pk_ctx, prv->pk_ctx, f_rng, p_rng ) ); } /* * Get key size in bits */ -size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx) +size_t mbedtls_pk_get_bitlen( const mbedtls_pk_context *ctx ) { /* For backward compatibility, accept NULL or a context that * isn't set up yet, and return a fake value that should be safe. */ - if (ctx == NULL || ctx->pk_info == NULL) { - return 0; - } + if( ctx == NULL || ctx->pk_info == NULL ) + return( 0 ); - return ctx->pk_info->get_bitlen((mbedtls_pk_context *) ctx); + return( ctx->pk_info->get_bitlen( ctx->pk_ctx ) ); } /* * Export debug information */ -int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items) +int mbedtls_pk_debug( const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items ) { - if (ctx->pk_info == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + PK_VALIDATE_RET( ctx != NULL ); + if( ctx->pk_info == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); - if (ctx->pk_info->debug_func == NULL) { - return MBEDTLS_ERR_PK_TYPE_MISMATCH; - } + if( ctx->pk_info->debug_func == NULL ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); - ctx->pk_info->debug_func((mbedtls_pk_context *) ctx, items); - return 0; + ctx->pk_info->debug_func( ctx->pk_ctx, items ); + return( 0 ); } /* * Access the PK type name */ -const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx) +const char *mbedtls_pk_get_name( const mbedtls_pk_context *ctx ) { - if (ctx == NULL || ctx->pk_info == NULL) { - return "invalid PK"; - } + if( ctx == NULL || ctx->pk_info == NULL ) + return( "invalid PK" ); - return ctx->pk_info->name; + return( ctx->pk_info->name ); } /* * Access the PK type */ -mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx) +mbedtls_pk_type_t mbedtls_pk_get_type( const mbedtls_pk_context *ctx ) { - if (ctx == NULL || ctx->pk_info == NULL) { - return MBEDTLS_PK_NONE; - } + if( ctx == NULL || ctx->pk_info == NULL ) + return( MBEDTLS_PK_NONE ); - return ctx->pk_info->type; + return( ctx->pk_info->type ); } +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/* + * Load the key to a PSA key slot, + * then turn the PK context into a wrapper for that key slot. + * + * Currently only works for EC private keys. + */ +int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk, + psa_key_id_t *key, + psa_algorithm_t hash_alg ) +{ +#if !defined(MBEDTLS_ECP_C) + ((void) pk); + ((void) key); + ((void) hash_alg); + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); +#else + const mbedtls_ecp_keypair *ec; + unsigned char d[MBEDTLS_ECP_MAX_BYTES]; + size_t d_len; + psa_ecc_family_t curve_id; + psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + psa_key_type_t key_type; + size_t bits; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + + /* export the private key material in the format PSA wants */ + if( mbedtls_pk_get_type( pk ) != MBEDTLS_PK_ECKEY ) + return( MBEDTLS_ERR_PK_TYPE_MISMATCH ); + + ec = mbedtls_pk_ec( *pk ); + d_len = ( ec->grp.nbits + 7 ) / 8; + if( ( ret = mbedtls_mpi_write_binary( &ec->d, d, d_len ) ) != 0 ) + return( ret ); + + curve_id = mbedtls_ecc_group_to_psa( ec->grp.id, &bits ); + key_type = PSA_KEY_TYPE_ECC_KEY_PAIR( curve_id ); + + /* prepare the key attributes */ + psa_set_key_type( &attributes, key_type ); + psa_set_key_bits( &attributes, bits ); + psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH ); + psa_set_key_algorithm( &attributes, PSA_ALG_ECDSA(hash_alg) ); + + /* import private key into PSA */ + if( PSA_SUCCESS != psa_import_key( &attributes, d, d_len, key ) ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); + + /* make PK context wrap the key slot */ + mbedtls_pk_free( pk ); + mbedtls_pk_init( pk ); + + return( mbedtls_pk_setup_opaque( pk, *key ) ); +#endif /* MBEDTLS_ECP_C */ +} +#endif /* MBEDTLS_USE_PSA_CRYPTO */ #endif /* MBEDTLS_PK_C */ diff --git a/src/duckdb/third_party/mbedtls/library/pk_wrap.cpp b/src/duckdb/third_party/mbedtls/library/pk_wrap.cpp index 2ac558b0f..80c0aad27 100644 --- a/src/duckdb/third_party/mbedtls/library/pk_wrap.cpp +++ b/src/duckdb/third_party/mbedtls/library/pk_wrap.cpp @@ -2,22 +2,32 @@ * Public Key abstraction layer: wrapper functions * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" -#include "mbedtls/platform_util.h" - #if defined(MBEDTLS_PK_C) #include "pk_wrap.h" -#include "pk_internal.h" #include "mbedtls/error.h" -#include "mbedtls/psa_util.h" /* Even if RSA not activated, for the sake of RSA-alt */ #include "mbedtls/rsa.h" +#include + #if defined(MBEDTLS_ECP_C) #include "mbedtls/ecp.h" #endif @@ -27,813 +37,270 @@ #endif #if defined(MBEDTLS_USE_PSA_CRYPTO) -#include "psa_util_internal.h" -#include "psa/crypto.h" +#include "mbedtls/asn1write.h" +#endif -#if defined(MBEDTLS_RSA_C) -#include "pkwrite.h" -#include "rsa_internal.h" +#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) +#include "mbedtls/platform_util.h" #endif -#if defined(MBEDTLS_PK_CAN_ECDSA_SOME) -#include "mbedtls/asn1write.h" +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#include "psa/crypto.h" +#include "mbedtls/psa_util.h" #include "mbedtls/asn1.h" #endif -#endif /* MBEDTLS_USE_PSA_CRYPTO */ +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#include +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif #include #include -#include #if defined(MBEDTLS_RSA_C) -static int rsa_can_do(mbedtls_pk_type_t type) +static int rsa_can_do( mbedtls_pk_type_t type ) { - return type == MBEDTLS_PK_RSA || - type == MBEDTLS_PK_RSASSA_PSS; + return( type == MBEDTLS_PK_RSA || + type == MBEDTLS_PK_RSASSA_PSS ); } -static size_t rsa_get_bitlen(mbedtls_pk_context *pk) +static size_t rsa_get_bitlen( const void *ctx ) { - const mbedtls_rsa_context *rsa = (const mbedtls_rsa_context *) pk->pk_ctx; - return mbedtls_rsa_get_bitlen(rsa); + const mbedtls_rsa_context * rsa = (const mbedtls_rsa_context *) ctx; + return( 8 * mbedtls_rsa_get_len( rsa ) ); } -#if defined(MBEDTLS_USE_PSA_CRYPTO) -static int rsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) +static int rsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ) { - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_status_t status; - int key_len; - unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES]; - unsigned char *p = buf + sizeof(buf); - psa_algorithm_t psa_alg_md; - size_t rsa_len = mbedtls_rsa_get_len(rsa); + mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; + size_t rsa_len = mbedtls_rsa_get_len( rsa ); #if SIZE_MAX > UINT_MAX - if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } -#endif + if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); +#endif /* SIZE_MAX > UINT_MAX */ - if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) { - psa_alg_md = PSA_ALG_RSA_PSS(mbedtls_md_psa_alg_from_type(md_alg)); - } else { - psa_alg_md = PSA_ALG_RSA_PKCS1V15_SIGN(mbedtls_md_psa_alg_from_type(md_alg)); - } + if( sig_len < rsa_len ) + return( MBEDTLS_ERR_RSA_VERIFY_FAILED ); - if (sig_len < rsa_len) { - return MBEDTLS_ERR_RSA_VERIFY_FAILED; - } - - key_len = mbedtls_rsa_write_pubkey(rsa, buf, &p); - if (key_len <= 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH); - psa_set_key_algorithm(&attributes, psa_alg_md); - psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY); - - status = psa_import_key(&attributes, - buf + sizeof(buf) - key_len, key_len, - &key_id); - if (status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - status = psa_verify_hash(key_id, psa_alg_md, hash, hash_len, - sig, sig_len); - if (status != PSA_SUCCESS) { - ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status); - goto cleanup; - } - ret = 0; - -cleanup: - status = psa_destroy_key(key_id); - if (ret == 0 && status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - } - - return ret; -} -#else /* MBEDTLS_USE_PSA_CRYPTO */ -static int rsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; - size_t rsa_len = mbedtls_rsa_get_len(rsa); - -#if SIZE_MAX > UINT_MAX - if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } -#endif - - if (sig_len < rsa_len) { - return MBEDTLS_ERR_RSA_VERIFY_FAILED; - } - - if ((ret = mbedtls_rsa_pkcs1_verify(rsa, md_alg, - (unsigned int) hash_len, - hash, sig)) != 0) { - return ret; - } + if( ( ret = mbedtls_rsa_pkcs1_verify( rsa, md_alg, + (unsigned int) hash_len, + hash, sig ) ) != 0 ) + return( ret ); /* The buffer contains a valid signature followed by extra data. * We have a special error code for that so that so that callers can * use mbedtls_pk_verify() to check "Does the buffer start with a * valid signature?" and not just "Does the buffer contain a valid * signature?". */ - if (sig_len > rsa_len) { - return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH; - } - - return 0; -} -#endif /* MBEDTLS_USE_PSA_CRYPTO */ + if( sig_len > rsa_len ) + return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); -#if defined(MBEDTLS_USE_PSA_CRYPTO) -int mbedtls_pk_psa_rsa_sign_ext(psa_algorithm_t alg, - mbedtls_rsa_context *rsa_ctx, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, - size_t *sig_len) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_status_t status; - int key_len; - unsigned char *buf = NULL; - unsigned char *p; - - buf = mbedtls_calloc(1, MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES); - if (buf == NULL) { - return MBEDTLS_ERR_PK_ALLOC_FAILED; - } - p = buf + MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES; - - *sig_len = mbedtls_rsa_get_len(rsa_ctx); - if (sig_size < *sig_len) { - mbedtls_free(buf); - return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL; - } - - key_len = mbedtls_rsa_write_key(rsa_ctx, buf, &p); - if (key_len <= 0) { - mbedtls_free(buf); - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH); - psa_set_key_algorithm(&attributes, alg); - psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_KEY_PAIR); - - status = psa_import_key(&attributes, - buf + MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES - key_len, key_len, - &key_id); - if (status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - goto cleanup; - } - status = psa_sign_hash(key_id, alg, hash, hash_len, - sig, sig_size, sig_len); - if (status != PSA_SUCCESS) { - ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - ret = 0; - -cleanup: - mbedtls_free(buf); - status = psa_destroy_key(key_id); - if (ret == 0 && status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - } - return ret; + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) -static int rsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int rsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - ((void) f_rng); - ((void) p_rng); - - psa_algorithm_t psa_md_alg; - psa_md_alg = mbedtls_md_psa_alg_from_type(md_alg); - if (psa_md_alg == 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - psa_algorithm_t psa_alg; - if (mbedtls_rsa_get_padding_mode(mbedtls_pk_rsa(*pk)) == MBEDTLS_RSA_PKCS_V21) { - psa_alg = PSA_ALG_RSA_PSS(psa_md_alg); - } else { - psa_alg = PSA_ALG_RSA_PKCS1V15_SIGN(psa_md_alg); - } - - return mbedtls_pk_psa_rsa_sign_ext(psa_alg, pk->pk_ctx, hash, hash_len, - sig, sig_size, sig_len); -} -#else /* MBEDTLS_USE_PSA_CRYPTO */ -static int rsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) -{ - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; + mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; #if SIZE_MAX > UINT_MAX - if (md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } -#endif + if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); +#endif /* SIZE_MAX > UINT_MAX */ - *sig_len = mbedtls_rsa_get_len(rsa); - if (sig_size < *sig_len) { - return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL; - } + *sig_len = mbedtls_rsa_get_len( rsa ); + if( sig_size < *sig_len ) + return( MBEDTLS_ERR_PK_BUFFER_TOO_SMALL ); - return mbedtls_rsa_pkcs1_sign(rsa, f_rng, p_rng, - md_alg, (unsigned int) hash_len, - hash, sig); + return( mbedtls_rsa_pkcs1_sign( rsa, f_rng, p_rng, + md_alg, (unsigned int) hash_len, + hash, sig ) ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO */ - -#if defined(MBEDTLS_USE_PSA_CRYPTO) -static int rsa_decrypt_wrap(mbedtls_pk_context *pk, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) -{ - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_algorithm_t psa_md_alg, decrypt_alg; - psa_status_t status; - int key_len; - unsigned char buf[MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES]; - unsigned char *p = buf + sizeof(buf); - - ((void) f_rng); - ((void) p_rng); - - if (ilen != mbedtls_rsa_get_len(rsa)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - key_len = mbedtls_rsa_write_key(rsa, buf, &p); - if (key_len <= 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_KEY_PAIR); - psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DECRYPT); - if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) { - psa_md_alg = mbedtls_md_psa_alg_from_type((mbedtls_md_type_t) mbedtls_rsa_get_md_alg(rsa)); - decrypt_alg = PSA_ALG_RSA_OAEP(psa_md_alg); - } else { - decrypt_alg = PSA_ALG_RSA_PKCS1V15_CRYPT; - } - psa_set_key_algorithm(&attributes, decrypt_alg); - - status = psa_import_key(&attributes, - buf + sizeof(buf) - key_len, key_len, - &key_id); - if (status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - status = psa_asymmetric_decrypt(key_id, decrypt_alg, - input, ilen, - NULL, 0, - output, osize, olen); - if (status != PSA_SUCCESS) { - ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status); - goto cleanup; - } - ret = 0; - -cleanup: - mbedtls_platform_zeroize(buf, sizeof(buf)); - status = psa_destroy_key(key_id); - if (ret == 0 && status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - } - - return ret; -} -#else /* MBEDTLS_USE_PSA_CRYPTO */ -static int rsa_decrypt_wrap(mbedtls_pk_context *pk, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int rsa_decrypt_wrap( void *ctx, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; + mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; - if (ilen != mbedtls_rsa_get_len(rsa)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ilen != mbedtls_rsa_get_len( rsa ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - return mbedtls_rsa_pkcs1_decrypt(rsa, f_rng, p_rng, - olen, input, output, osize); + return( mbedtls_rsa_pkcs1_decrypt( rsa, f_rng, p_rng, + olen, input, output, osize ) ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) -static int rsa_encrypt_wrap(mbedtls_pk_context *pk, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int rsa_encrypt_wrap( void *ctx, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_algorithm_t psa_md_alg, psa_encrypt_alg; - psa_status_t status; - int key_len; - unsigned char buf[MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES]; - unsigned char *p = buf + sizeof(buf); - - ((void) f_rng); - ((void) p_rng); - - if (mbedtls_rsa_get_len(rsa) > osize) { - return MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE; - } + mbedtls_rsa_context * rsa = (mbedtls_rsa_context *) ctx; + *olen = mbedtls_rsa_get_len( rsa ); - key_len = mbedtls_rsa_write_pubkey(rsa, buf, &p); - if (key_len <= 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( *olen > osize ) + return( MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE ); - psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT); - if (mbedtls_rsa_get_padding_mode(rsa) == MBEDTLS_RSA_PKCS_V21) { - psa_md_alg = mbedtls_md_psa_alg_from_type((mbedtls_md_type_t) mbedtls_rsa_get_md_alg(rsa)); - psa_encrypt_alg = PSA_ALG_RSA_OAEP(psa_md_alg); - } else { - psa_encrypt_alg = PSA_ALG_RSA_PKCS1V15_CRYPT; - } - psa_set_key_algorithm(&attributes, psa_encrypt_alg); - psa_set_key_type(&attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY); - - status = psa_import_key(&attributes, - buf + sizeof(buf) - key_len, key_len, - &key_id); - if (status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - status = psa_asymmetric_encrypt(key_id, psa_encrypt_alg, - input, ilen, - NULL, 0, - output, osize, olen); - if (status != PSA_SUCCESS) { - ret = PSA_PK_RSA_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - ret = 0; - -cleanup: - status = psa_destroy_key(key_id); - if (ret == 0 && status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - } - - return ret; + return( mbedtls_rsa_pkcs1_encrypt( rsa, f_rng, p_rng, + ilen, input, output ) ); } -#else /* MBEDTLS_USE_PSA_CRYPTO */ -static int rsa_encrypt_wrap(mbedtls_pk_context *pk, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) -{ - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; - *olen = mbedtls_rsa_get_len(rsa); - - if (*olen > osize) { - return MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE; - } - - return mbedtls_rsa_pkcs1_encrypt(rsa, f_rng, p_rng, - ilen, input, output); -} -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -static int rsa_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +static int rsa_check_pair_wrap( const void *pub, const void *prv, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { (void) f_rng; (void) p_rng; - return mbedtls_rsa_check_pub_priv((const mbedtls_rsa_context *) pub->pk_ctx, - (const mbedtls_rsa_context *) prv->pk_ctx); + return( mbedtls_rsa_check_pub_priv( (const mbedtls_rsa_context *) pub, + (const mbedtls_rsa_context *) prv ) ); } -static void *rsa_alloc_wrap(void) +static void *rsa_alloc_wrap( void ) { - void *ctx = mbedtls_calloc(1, sizeof(mbedtls_rsa_context)); + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_context ) ); - if (ctx != NULL) { - mbedtls_rsa_init((mbedtls_rsa_context *) ctx); - } + if( ctx != NULL ) + mbedtls_rsa_init( (mbedtls_rsa_context *) ctx ); - return ctx; + return( ctx ); } -static void rsa_free_wrap(void *ctx) +static void rsa_free_wrap( void *ctx ) { - mbedtls_rsa_free((mbedtls_rsa_context *) ctx); - mbedtls_free(ctx); + mbedtls_rsa_free( (mbedtls_rsa_context *) ctx ); + mbedtls_free( ctx ); } -static void rsa_debug(mbedtls_pk_context *pk, mbedtls_pk_debug_item *items) +static void rsa_debug( const void *ctx, mbedtls_pk_debug_item *items ) { #if defined(MBEDTLS_RSA_ALT) /* Not supported */ - (void) pk; + (void) ctx; (void) items; #else - mbedtls_rsa_context *rsa = (mbedtls_rsa_context *) pk->pk_ctx; - items->type = MBEDTLS_PK_DEBUG_MPI; items->name = "rsa.N"; - items->value = &(rsa->N); + items->value = &( ((mbedtls_rsa_context *) ctx)->N ); items++; items->type = MBEDTLS_PK_DEBUG_MPI; items->name = "rsa.E"; - items->value = &(rsa->E); + items->value = &( ((mbedtls_rsa_context *) ctx)->E ); #endif } const mbedtls_pk_info_t mbedtls_rsa_info = { - /* type */ MBEDTLS_PK_RSA, - /* name */ "RSA", - /* get_bitlen */ rsa_get_bitlen, - /* can_do */ rsa_can_do, - /* verify_func */ rsa_verify_wrap, - /* sign_func */ rsa_sign_wrap, + MBEDTLS_PK_RSA, + "RSA", + rsa_get_bitlen, + rsa_can_do, + rsa_verify_wrap, + rsa_sign_wrap, #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - /* verify_rs_func */ NULL, - /* sign_rs_func */ NULL, - /* rs_alloc_func */ NULL, - /* rs_free_func */ NULL, -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - /* decrypt_func */ rsa_decrypt_wrap, - /* encrypt_func */ rsa_encrypt_wrap, - /* check_pair_func */ rsa_check_pair_wrap, - /* ctx_alloc_func */ rsa_alloc_wrap, - /* ctx_free_func */ rsa_free_wrap, + NULL, + NULL, +#endif + rsa_decrypt_wrap, + rsa_encrypt_wrap, + rsa_check_pair_wrap, + rsa_alloc_wrap, + rsa_free_wrap, #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - /* rs_alloc_func */ NULL, - /* rs_free_func */ NULL, + NULL, + NULL, #endif - /* debug_func */ rsa_debug + rsa_debug, }; #endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_ECP_C) /* * Generic EC key */ -static int eckey_can_do(mbedtls_pk_type_t type) -{ - return type == MBEDTLS_PK_ECKEY || - type == MBEDTLS_PK_ECKEY_DH || - type == MBEDTLS_PK_ECDSA; -} - -static size_t eckey_get_bitlen(mbedtls_pk_context *pk) -{ -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - return pk->ec_bits; -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - mbedtls_ecp_keypair *ecp = (mbedtls_ecp_keypair *) pk->pk_ctx; - return ecp->grp.pbits; -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ -} - -#if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) -#if defined(MBEDTLS_USE_PSA_CRYPTO) -/* Common helper for ECDSA verify using PSA functions. */ -static int ecdsa_verify_psa(unsigned char *key, size_t key_len, - psa_ecc_family_t curve, size_t curve_bits, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_algorithm_t psa_sig_md = PSA_ALG_ECDSA_ANY; - size_t signature_len = PSA_ECDSA_SIGNATURE_SIZE(curve_bits); - size_t converted_sig_len; - unsigned char extracted_sig[PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE]; - unsigned char *p; - psa_status_t status; - - if (curve == 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - - psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve)); - psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_VERIFY_HASH); - psa_set_key_algorithm(&attributes, psa_sig_md); - - status = psa_import_key(&attributes, key, key_len, &key_id); - if (status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - if (signature_len > sizeof(extracted_sig)) { - ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; - goto cleanup; - } - - p = (unsigned char *) sig; - ret = mbedtls_ecdsa_der_to_raw(curve_bits, p, sig_len, extracted_sig, - sizeof(extracted_sig), &converted_sig_len); - if (ret != 0) { - goto cleanup; - } - - if (converted_sig_len != signature_len) { - ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; - goto cleanup; - } - - status = psa_verify_hash(key_id, psa_sig_md, hash, hash_len, - extracted_sig, signature_len); - if (status != PSA_SUCCESS) { - ret = PSA_PK_ECDSA_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - ret = 0; - -cleanup: - status = psa_destroy_key(key_id); - if (ret == 0 && status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - } - - return ret; -} - -static int ecdsa_opaque_verify_wrap(mbedtls_pk_context *pk, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) -{ - (void) md_alg; - unsigned char key[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN]; - size_t key_len; - psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; - psa_ecc_family_t curve; - size_t curve_bits; - psa_status_t status; - - status = psa_get_key_attributes(pk->priv_id, &key_attr); - if (status != PSA_SUCCESS) { - return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status); - } - curve = PSA_KEY_TYPE_ECC_GET_FAMILY(psa_get_key_type(&key_attr)); - curve_bits = psa_get_key_bits(&key_attr); - psa_reset_key_attributes(&key_attr); - - status = psa_export_public_key(pk->priv_id, key, sizeof(key), &key_len); - if (status != PSA_SUCCESS) { - return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status); - } - - return ecdsa_verify_psa(key, key_len, curve, curve_bits, - hash, hash_len, sig, sig_len); -} - -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) -static int ecdsa_verify_wrap(mbedtls_pk_context *pk, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) +static int eckey_can_do( mbedtls_pk_type_t type ) { - (void) md_alg; - psa_ecc_family_t curve = pk->ec_family; - size_t curve_bits = pk->ec_bits; - - return ecdsa_verify_psa(pk->pub_raw, pk->pub_raw_len, curve, curve_bits, - hash, hash_len, sig, sig_len); + return( type == MBEDTLS_PK_ECKEY || + type == MBEDTLS_PK_ECKEY_DH || + type == MBEDTLS_PK_ECDSA ); } -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ -static int ecdsa_verify_wrap(mbedtls_pk_context *pk, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) -{ - (void) md_alg; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_ecp_keypair *ctx = pk->pk_ctx; - unsigned char key[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH]; - size_t key_len; - size_t curve_bits; - psa_ecc_family_t curve = mbedtls_ecc_group_to_psa(ctx->grp.id, &curve_bits); - ret = mbedtls_ecp_point_write_binary(&ctx->grp, &ctx->Q, - MBEDTLS_ECP_PF_UNCOMPRESSED, - &key_len, key, sizeof(key)); - if (ret != 0) { - return ret; - } - - return ecdsa_verify_psa(key, key_len, curve, curve_bits, - hash, hash_len, sig, sig_len); -} -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ -#else /* MBEDTLS_USE_PSA_CRYPTO */ -static int ecdsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len) +static size_t eckey_get_bitlen( const void *ctx ) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - ((void) md_alg); - - ret = mbedtls_ecdsa_read_signature((mbedtls_ecdsa_context *) pk->pk_ctx, - hash, hash_len, sig, sig_len); - - if (ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) { - return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH; - } - - return ret; + return( ((mbedtls_ecp_keypair *) ctx)->grp.pbits ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ -#if defined(MBEDTLS_PK_CAN_ECDSA_SIGN) -#if defined(MBEDTLS_USE_PSA_CRYPTO) -/* Common helper for ECDSA sign using PSA functions. - * Instead of extracting key's properties in order to check which kind of ECDSA - * signature it supports, we try both deterministic and non-deterministic. - */ -static int ecdsa_sign_psa(mbedtls_svc_key_id_t key_id, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len) +#if defined(MBEDTLS_ECDSA_C) +/* Forward declarations */ +static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ); + +static int ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ); + +static int eckey_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - psa_status_t status; - psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; - size_t key_bits = 0; + mbedtls_ecdsa_context ecdsa; - status = psa_get_key_attributes(key_id, &key_attr); - if (status != PSA_SUCCESS) { - return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status); - } - key_bits = psa_get_key_bits(&key_attr); - psa_reset_key_attributes(&key_attr); - - status = psa_sign_hash(key_id, - PSA_ALG_DETERMINISTIC_ECDSA(mbedtls_md_psa_alg_from_type(md_alg)), - hash, hash_len, sig, sig_size, sig_len); - if (status == PSA_SUCCESS) { - goto done; - } else if (status != PSA_ERROR_NOT_PERMITTED) { - return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status); - } + mbedtls_ecdsa_init( &ecdsa ); - status = psa_sign_hash(key_id, - PSA_ALG_ECDSA(mbedtls_md_psa_alg_from_type(md_alg)), - hash, hash_len, sig, sig_size, sig_len); - if (status != PSA_SUCCESS) { - return PSA_PK_ECDSA_TO_MBEDTLS_ERR(status); - } + if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 ) + ret = ecdsa_verify_wrap( &ecdsa, md_alg, hash, hash_len, sig, sig_len ); -done: - ret = mbedtls_ecdsa_raw_to_der(key_bits, sig, *sig_len, sig, sig_size, sig_len); + mbedtls_ecdsa_free( &ecdsa ); - return ret; + return( ret ); } -static int ecdsa_opaque_sign_wrap(mbedtls_pk_context *pk, - mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, - size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) -{ - ((void) f_rng); - ((void) p_rng); - - return ecdsa_sign_psa(pk->priv_id, md_alg, hash, hash_len, sig, sig_size, - sig_len); -} - -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) -/* When PK_USE_PSA_EC_DATA is defined opaque and non-opaque keys end up - * using the same function. */ -#define ecdsa_sign_wrap ecdsa_opaque_sign_wrap -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ -static int ecdsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int eckey_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_status_t status; - mbedtls_ecp_keypair *ctx = pk->pk_ctx; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - unsigned char buf[MBEDTLS_PSA_MAX_EC_KEY_PAIR_LENGTH]; - size_t curve_bits; - psa_ecc_family_t curve = - mbedtls_ecc_group_to_psa(ctx->grp.id, &curve_bits); - size_t key_len = PSA_BITS_TO_BYTES(curve_bits); - psa_algorithm_t psa_hash = mbedtls_md_psa_alg_from_type(md_alg); - psa_algorithm_t psa_sig_md = MBEDTLS_PK_PSA_ALG_ECDSA_MAYBE_DET(psa_hash); - ((void) f_rng); - ((void) p_rng); - - if (curve == 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + mbedtls_ecdsa_context ecdsa; - if (key_len > sizeof(buf)) { - return MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - } - ret = mbedtls_mpi_write_binary(&ctx->d, buf, key_len); - if (ret != 0) { - goto cleanup; - } + mbedtls_ecdsa_init( &ecdsa ); - psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(curve)); - psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH); - psa_set_key_algorithm(&attributes, psa_sig_md); + if( ( ret = mbedtls_ecdsa_from_keypair( &ecdsa, ctx ) ) == 0 ) + ret = ecdsa_sign_wrap( &ecdsa, md_alg, hash, hash_len, + sig, sig_size, sig_len, + f_rng, p_rng ); - status = psa_import_key(&attributes, buf, key_len, &key_id); - if (status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - goto cleanup; - } - - ret = ecdsa_sign_psa(key_id, md_alg, hash, hash_len, sig, sig_size, sig_len); + mbedtls_ecdsa_free( &ecdsa ); -cleanup: - mbedtls_platform_zeroize(buf, sizeof(buf)); - status = psa_destroy_key(key_id); - if (ret == 0 && status != PSA_SUCCESS) { - ret = PSA_PK_TO_MBEDTLS_ERR(status); - } - - return ret; + return( ret ); } -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ -#else /* MBEDTLS_USE_PSA_CRYPTO */ -static int ecdsa_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) -{ - return mbedtls_ecdsa_write_signature((mbedtls_ecdsa_context *) pk->pk_ctx, - md_alg, hash, hash_len, - sig, sig_size, sig_len, - f_rng, p_rng); -} -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#endif /* MBEDTLS_PK_CAN_ECDSA_SIGN */ -#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) +#if defined(MBEDTLS_ECP_RESTARTABLE) /* Forward declarations */ -static int ecdsa_verify_rs_wrap(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len, - void *rs_ctx); +static int ecdsa_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + void *rs_ctx ); -static int ecdsa_sign_rs_wrap(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, - void *rs_ctx); +static int ecdsa_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + void *rs_ctx ); /* * Restart context for ECDSA operations with ECKEY context @@ -841,710 +308,721 @@ static int ecdsa_sign_rs_wrap(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg, * We need to store an actual ECDSA context, as we need to pass the same to * the underlying ecdsa function, so we can't create it on the fly every time. */ -typedef struct { +typedef struct +{ mbedtls_ecdsa_restart_ctx ecdsa_rs; mbedtls_ecdsa_context ecdsa_ctx; } eckey_restart_ctx; -static void *eckey_rs_alloc(void) +static void *eckey_rs_alloc( void ) { eckey_restart_ctx *rs_ctx; - void *ctx = mbedtls_calloc(1, sizeof(eckey_restart_ctx)); + void *ctx = mbedtls_calloc( 1, sizeof( eckey_restart_ctx ) ); - if (ctx != NULL) { + if( ctx != NULL ) + { rs_ctx = ctx; - mbedtls_ecdsa_restart_init(&rs_ctx->ecdsa_rs); - mbedtls_ecdsa_init(&rs_ctx->ecdsa_ctx); + mbedtls_ecdsa_restart_init( &rs_ctx->ecdsa_rs ); + mbedtls_ecdsa_init( &rs_ctx->ecdsa_ctx ); } - return ctx; + return( ctx ); } -static void eckey_rs_free(void *ctx) +static void eckey_rs_free( void *ctx ) { eckey_restart_ctx *rs_ctx; - if (ctx == NULL) { + if( ctx == NULL) return; - } rs_ctx = ctx; - mbedtls_ecdsa_restart_free(&rs_ctx->ecdsa_rs); - mbedtls_ecdsa_free(&rs_ctx->ecdsa_ctx); + mbedtls_ecdsa_restart_free( &rs_ctx->ecdsa_rs ); + mbedtls_ecdsa_free( &rs_ctx->ecdsa_ctx ); - mbedtls_free(ctx); + mbedtls_free( ctx ); } -static int eckey_verify_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len, - void *rs_ctx) +static int eckey_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + void *rs_ctx ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; eckey_restart_ctx *rs = rs_ctx; /* Should never happen */ - if (rs == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( rs == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); /* set up our own sub-context if needed (that is, on first run) */ - if (rs->ecdsa_ctx.grp.pbits == 0) { - MBEDTLS_MPI_CHK(mbedtls_ecdsa_from_keypair(&rs->ecdsa_ctx, pk->pk_ctx)); - } + if( rs->ecdsa_ctx.grp.pbits == 0 ) + MBEDTLS_MPI_CHK( mbedtls_ecdsa_from_keypair( &rs->ecdsa_ctx, ctx ) ); - MBEDTLS_MPI_CHK(ecdsa_verify_rs_wrap(pk, - md_alg, hash, hash_len, - sig, sig_len, &rs->ecdsa_rs)); + MBEDTLS_MPI_CHK( ecdsa_verify_rs_wrap( &rs->ecdsa_ctx, + md_alg, hash, hash_len, + sig, sig_len, &rs->ecdsa_rs ) ); cleanup: - return ret; + return( ret ); } -static int eckey_sign_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, - void *rs_ctx) +static int eckey_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + void *rs_ctx ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; eckey_restart_ctx *rs = rs_ctx; /* Should never happen */ - if (rs == NULL) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } + if( rs == NULL ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); /* set up our own sub-context if needed (that is, on first run) */ - if (rs->ecdsa_ctx.grp.pbits == 0) { - MBEDTLS_MPI_CHK(mbedtls_ecdsa_from_keypair(&rs->ecdsa_ctx, pk->pk_ctx)); - } + if( rs->ecdsa_ctx.grp.pbits == 0 ) + MBEDTLS_MPI_CHK( mbedtls_ecdsa_from_keypair( &rs->ecdsa_ctx, ctx ) ); - MBEDTLS_MPI_CHK(ecdsa_sign_rs_wrap(pk, md_alg, - hash, hash_len, sig, sig_size, sig_len, - f_rng, p_rng, &rs->ecdsa_rs)); + MBEDTLS_MPI_CHK( ecdsa_sign_rs_wrap( &rs->ecdsa_ctx, md_alg, + hash, hash_len, sig, sig_size, sig_len, + f_rng, p_rng, &rs->ecdsa_rs ) ); cleanup: - return ret; + return( ret ); } -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ +#endif /* MBEDTLS_ECP_RESTARTABLE */ +#endif /* MBEDTLS_ECDSA_C */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) -static int eckey_check_pair_psa(mbedtls_pk_context *pub, mbedtls_pk_context *prv) +static int eckey_check_pair( const void *pub, const void *prv, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { - psa_status_t status; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - uint8_t prv_key_buf[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH]; - size_t prv_key_len; - mbedtls_svc_key_id_t key_id = prv->priv_id; - - status = psa_export_public_key(key_id, prv_key_buf, sizeof(prv_key_buf), - &prv_key_len); - ret = PSA_PK_TO_MBEDTLS_ERR(status); - if (ret != 0) { - return ret; - } + return( mbedtls_ecp_check_pub_priv( (const mbedtls_ecp_keypair *) pub, + (const mbedtls_ecp_keypair *) prv, + f_rng, p_rng ) ); +} - if (memcmp(prv_key_buf, pub->pub_raw, pub->pub_raw_len) != 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } +static void *eckey_alloc_wrap( void ) +{ + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecp_keypair ) ); + + if( ctx != NULL ) + mbedtls_ecp_keypair_init( ctx ); - return 0; + return( ctx ); } -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ -static int eckey_check_pair_psa(mbedtls_pk_context *pub, mbedtls_pk_context *prv) + +static void eckey_free_wrap( void *ctx ) { - psa_status_t status; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - uint8_t prv_key_buf[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH]; - size_t prv_key_len; - psa_status_t destruction_status; - mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT; - psa_key_attributes_t key_attr = PSA_KEY_ATTRIBUTES_INIT; - uint8_t pub_key_buf[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH]; - size_t pub_key_len; - size_t curve_bits; - const psa_ecc_family_t curve = - mbedtls_ecc_group_to_psa(mbedtls_pk_ec_ro(*prv)->grp.id, &curve_bits); - const size_t curve_bytes = PSA_BITS_TO_BYTES(curve_bits); + mbedtls_ecp_keypair_free( (mbedtls_ecp_keypair *) ctx ); + mbedtls_free( ctx ); +} - if (curve == 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } +static void eckey_debug( const void *ctx, mbedtls_pk_debug_item *items ) +{ + items->type = MBEDTLS_PK_DEBUG_ECP; + items->name = "eckey.Q"; + items->value = &( ((mbedtls_ecp_keypair *) ctx)->Q ); +} - psa_set_key_type(&key_attr, PSA_KEY_TYPE_ECC_KEY_PAIR(curve)); - psa_set_key_usage_flags(&key_attr, PSA_KEY_USAGE_EXPORT); +const mbedtls_pk_info_t mbedtls_eckey_info = { + MBEDTLS_PK_ECKEY, + "EC", + eckey_get_bitlen, + eckey_can_do, +#if defined(MBEDTLS_ECDSA_C) + eckey_verify_wrap, + eckey_sign_wrap, +#if defined(MBEDTLS_ECP_RESTARTABLE) + eckey_verify_rs_wrap, + eckey_sign_rs_wrap, +#endif +#else /* MBEDTLS_ECDSA_C */ + NULL, + NULL, +#endif /* MBEDTLS_ECDSA_C */ + NULL, + NULL, + eckey_check_pair, + eckey_alloc_wrap, + eckey_free_wrap, +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) + eckey_rs_alloc, + eckey_rs_free, +#endif + eckey_debug, +}; - ret = mbedtls_mpi_write_binary(&mbedtls_pk_ec_ro(*prv)->d, - prv_key_buf, curve_bytes); - if (ret != 0) { - mbedtls_platform_zeroize(prv_key_buf, sizeof(prv_key_buf)); - return ret; - } +/* + * EC key restricted to ECDH + */ +static int eckeydh_can_do( mbedtls_pk_type_t type ) +{ + return( type == MBEDTLS_PK_ECKEY || + type == MBEDTLS_PK_ECKEY_DH ); +} - status = psa_import_key(&key_attr, prv_key_buf, curve_bytes, &key_id); - mbedtls_platform_zeroize(prv_key_buf, sizeof(prv_key_buf)); - ret = PSA_PK_TO_MBEDTLS_ERR(status); - if (ret != 0) { - return ret; - } +const mbedtls_pk_info_t mbedtls_eckeydh_info = { + MBEDTLS_PK_ECKEY_DH, + "EC_DH", + eckey_get_bitlen, /* Same underlying key structure */ + eckeydh_can_do, + NULL, + NULL, +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) + NULL, + NULL, +#endif + NULL, + NULL, + eckey_check_pair, + eckey_alloc_wrap, /* Same underlying key structure */ + eckey_free_wrap, /* Same underlying key structure */ +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) + NULL, + NULL, +#endif + eckey_debug, /* Same underlying key structure */ +}; +#endif /* MBEDTLS_ECP_C */ - // From now on prv_key_buf is used to store the public key of prv. - status = psa_export_public_key(key_id, prv_key_buf, sizeof(prv_key_buf), - &prv_key_len); - ret = PSA_PK_TO_MBEDTLS_ERR(status); - destruction_status = psa_destroy_key(key_id); - if (ret != 0) { - return ret; - } else if (destruction_status != PSA_SUCCESS) { - return PSA_PK_TO_MBEDTLS_ERR(destruction_status); - } +#if defined(MBEDTLS_ECDSA_C) +static int ecdsa_can_do( mbedtls_pk_type_t type ) +{ + return( type == MBEDTLS_PK_ECDSA ); +} - ret = mbedtls_ecp_point_write_binary(&mbedtls_pk_ec_rw(*pub)->grp, - &mbedtls_pk_ec_rw(*pub)->Q, - MBEDTLS_ECP_PF_UNCOMPRESSED, - &pub_key_len, pub_key_buf, - sizeof(pub_key_buf)); - if (ret != 0) { - return ret; +#if defined(MBEDTLS_USE_PSA_CRYPTO) +/* + * An ASN.1 encoded signature is a sequence of two ASN.1 integers. Parse one of + * those integers and convert it to the fixed-length encoding expected by PSA. + */ +static int extract_ecdsa_sig_int( unsigned char **from, const unsigned char *end, + unsigned char *to, size_t to_len ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t unpadded_len, padding_len; + + if( ( ret = mbedtls_asn1_get_tag( from, end, &unpadded_len, + MBEDTLS_ASN1_INTEGER ) ) != 0 ) + { + return( ret ); } - if (memcmp(prv_key_buf, pub_key_buf, curve_bytes) != 0) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; + while( unpadded_len > 0 && **from == 0x00 ) + { + ( *from )++; + unpadded_len--; } - return 0; -} -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ + if( unpadded_len > to_len || unpadded_len == 0 ) + return( MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); -static int eckey_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) -{ - (void) f_rng; - (void) p_rng; - return eckey_check_pair_psa(pub, prv); + padding_len = to_len - unpadded_len; + memset( to, 0x00, padding_len ); + memcpy( to + padding_len, *from, unpadded_len ); + ( *from ) += unpadded_len; + + return( 0 ); } -#else /* MBEDTLS_USE_PSA_CRYPTO */ -static int eckey_check_pair_wrap(mbedtls_pk_context *pub, mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) + +/* + * Convert a signature from an ASN.1 sequence of two integers + * to a raw {r,s} buffer. Note: the provided sig buffer must be at least + * twice as big as int_size. + */ +static int extract_ecdsa_sig( unsigned char **p, const unsigned char *end, + unsigned char *sig, size_t int_size ) { - return mbedtls_ecp_check_pub_priv((const mbedtls_ecp_keypair *) pub->pk_ctx, - (const mbedtls_ecp_keypair *) prv->pk_ctx, - f_rng, p_rng); + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t tmp_size; + + if( ( ret = mbedtls_asn1_get_tag( p, end, &tmp_size, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + return( ret ); + + /* Extract r */ + if( ( ret = extract_ecdsa_sig_int( p, end, sig, int_size ) ) != 0 ) + return( ret ); + /* Extract s */ + if( ( ret = extract_ecdsa_sig_int( p, end, sig + int_size, int_size ) ) != 0 ) + return( ret ); + + return( 0 ); } -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) -/* When PK_USE_PSA_EC_DATA is defined opaque and non-opaque keys end up - * using the same function. */ -#define ecdsa_opaque_check_pair_wrap eckey_check_pair_wrap -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ -static int ecdsa_opaque_check_pair_wrap(mbedtls_pk_context *pub, - mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ) { + mbedtls_ecdsa_context *ctx = ctx_arg; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + psa_key_id_t key_id = 0; psa_status_t status; - uint8_t exp_pub_key[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN]; - size_t exp_pub_key_len = 0; - uint8_t pub_key[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN]; - size_t pub_key_len = 0; - int ret; - (void) f_rng; - (void) p_rng; + mbedtls_pk_context key; + int key_len; + /* see ECP_PUB_DER_MAX_BYTES in pkwrite.c */ + unsigned char buf[30 + 2 * MBEDTLS_ECP_MAX_BYTES]; + unsigned char *p; + mbedtls_pk_info_t pk_info = mbedtls_eckey_info; + psa_algorithm_t psa_sig_md = PSA_ALG_ECDSA_ANY; + size_t curve_bits; + psa_ecc_family_t curve = + mbedtls_ecc_group_to_psa( ctx->grp.id, &curve_bits ); + const size_t signature_part_size = ( ctx->grp.nbits + 7 ) / 8; + ((void) md_alg); - status = psa_export_public_key(prv->priv_id, exp_pub_key, sizeof(exp_pub_key), - &exp_pub_key_len); - if (status != PSA_SUCCESS) { - ret = psa_pk_status_to_mbedtls(status); - return ret; + if( curve == 0 ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + + /* mbedtls_pk_write_pubkey() expects a full PK context; + * re-construct one to make it happy */ + key.pk_info = &pk_info; + key.pk_ctx = ctx; + p = buf + sizeof( buf ); + key_len = mbedtls_pk_write_pubkey( &p, buf, &key ); + if( key_len <= 0 ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + + psa_set_key_type( &attributes, PSA_KEY_TYPE_ECC_PUBLIC_KEY( curve ) ); + psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH ); + psa_set_key_algorithm( &attributes, psa_sig_md ); + + status = psa_import_key( &attributes, + buf + sizeof( buf ) - key_len, key_len, + &key_id ); + if( status != PSA_SUCCESS ) + { + ret = mbedtls_psa_err_translate_pk( status ); + goto cleanup; } - ret = mbedtls_ecp_point_write_binary(&(mbedtls_pk_ec_ro(*pub)->grp), - &(mbedtls_pk_ec_ro(*pub)->Q), - MBEDTLS_ECP_PF_UNCOMPRESSED, - &pub_key_len, pub_key, sizeof(pub_key)); - if (ret != 0) { - return ret; + + /* We don't need the exported key anymore and can + * reuse its buffer for signature extraction. */ + if( 2 * signature_part_size > sizeof( buf ) ) + { + ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; + goto cleanup; } - if ((exp_pub_key_len != pub_key_len) || - memcmp(exp_pub_key, pub_key, exp_pub_key_len)) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; + + p = (unsigned char*) sig; + if( ( ret = extract_ecdsa_sig( &p, sig + sig_len, buf, + signature_part_size ) ) != 0 ) + { + goto cleanup; } - return 0; -} -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ -#endif /* MBEDTLS_USE_PSA_CRYPTO */ -#if !defined(MBEDTLS_PK_USE_PSA_EC_DATA) -static void *eckey_alloc_wrap(void) -{ - void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecp_keypair)); + if( psa_verify_hash( key_id, psa_sig_md, + hash, hash_len, + buf, 2 * signature_part_size ) + != PSA_SUCCESS ) + { + ret = MBEDTLS_ERR_ECP_VERIFY_FAILED; + goto cleanup; + } - if (ctx != NULL) { - mbedtls_ecp_keypair_init(ctx); + if( p != sig + sig_len ) + { + ret = MBEDTLS_ERR_PK_SIG_LEN_MISMATCH; + goto cleanup; } + ret = 0; - return ctx; +cleanup: + psa_destroy_key( key_id ); + return( ret ); } - -static void eckey_free_wrap(void *ctx) +#else /* MBEDTLS_USE_PSA_CRYPTO */ +static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ) { - mbedtls_ecp_keypair_free((mbedtls_ecp_keypair *) ctx); - mbedtls_free(ctx); -} -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + ((void) md_alg); -static void eckey_debug(mbedtls_pk_context *pk, mbedtls_pk_debug_item *items) -{ -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - items->type = MBEDTLS_PK_DEBUG_PSA_EC; - items->name = "eckey.Q"; - items->value = pk; -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - mbedtls_ecp_keypair *ecp = (mbedtls_ecp_keypair *) pk->pk_ctx; - items->type = MBEDTLS_PK_DEBUG_ECP; - items->name = "eckey.Q"; - items->value = &(ecp->Q); -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ -} + ret = mbedtls_ecdsa_read_signature( (mbedtls_ecdsa_context *) ctx, + hash, hash_len, sig, sig_len ); -const mbedtls_pk_info_t mbedtls_eckey_info = { - .type = MBEDTLS_PK_ECKEY, - .name = "EC", - .get_bitlen = eckey_get_bitlen, - .can_do = eckey_can_do, -#if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) - .verify_func = ecdsa_verify_wrap, /* Compatible key structures */ -#else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ - .verify_func = NULL, -#endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ -#if defined(MBEDTLS_PK_CAN_ECDSA_SIGN) - .sign_func = ecdsa_sign_wrap, /* Compatible key structures */ -#else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ - .sign_func = NULL, -#endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ -#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - .verify_rs_func = eckey_verify_rs_wrap, - .sign_rs_func = eckey_sign_rs_wrap, - .rs_alloc_func = eckey_rs_alloc, - .rs_free_func = eckey_rs_free, -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - .decrypt_func = NULL, - .encrypt_func = NULL, - .check_pair_func = eckey_check_pair_wrap, -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - .ctx_alloc_func = NULL, - .ctx_free_func = NULL, -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - .ctx_alloc_func = eckey_alloc_wrap, - .ctx_free_func = eckey_free_wrap, -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ - .debug_func = eckey_debug, -}; + if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) + return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); -/* - * EC key restricted to ECDH - */ -static int eckeydh_can_do(mbedtls_pk_type_t type) -{ - return type == MBEDTLS_PK_ECKEY || - type == MBEDTLS_PK_ECKEY_DH; + return( ret ); } +#endif /* MBEDTLS_USE_PSA_CRYPTO */ -const mbedtls_pk_info_t mbedtls_eckeydh_info = { - .type = MBEDTLS_PK_ECKEY_DH, - .name = "EC_DH", - .get_bitlen = eckey_get_bitlen, /* Same underlying key structure */ - .can_do = eckeydh_can_do, - .verify_func = NULL, - .sign_func = NULL, -#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - .verify_rs_func = NULL, - .sign_rs_func = NULL, -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - .decrypt_func = NULL, - .encrypt_func = NULL, - .check_pair_func = eckey_check_pair_wrap, -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - .ctx_alloc_func = NULL, - .ctx_free_func = NULL, -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - .ctx_alloc_func = eckey_alloc_wrap, /* Same underlying key structure */ - .ctx_free_func = eckey_free_wrap, /* Same underlying key structure */ -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ - .debug_func = eckey_debug, /* Same underlying key structure */ -}; - -#if defined(MBEDTLS_PK_CAN_ECDSA_SOME) -static int ecdsa_can_do(mbedtls_pk_type_t type) +static int ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - return type == MBEDTLS_PK_ECDSA; + return( mbedtls_ecdsa_write_signature( (mbedtls_ecdsa_context *) ctx, + md_alg, hash, hash_len, + sig, sig_size, sig_len, + f_rng, p_rng ) ); } -#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) -static int ecdsa_verify_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len, - void *rs_ctx) +#if defined(MBEDTLS_ECP_RESTARTABLE) +static int ecdsa_verify_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + void *rs_ctx ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; ((void) md_alg); ret = mbedtls_ecdsa_read_signature_restartable( - (mbedtls_ecdsa_context *) pk->pk_ctx, - hash, hash_len, sig, sig_len, - (mbedtls_ecdsa_restart_ctx *) rs_ctx); + (mbedtls_ecdsa_context *) ctx, + hash, hash_len, sig, sig_len, + (mbedtls_ecdsa_restart_ctx *) rs_ctx ); - if (ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH) { - return MBEDTLS_ERR_PK_SIG_LEN_MISMATCH; - } + if( ret == MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH ) + return( MBEDTLS_ERR_PK_SIG_LEN_MISMATCH ); - return ret; + return( ret ); } -static int ecdsa_sign_rs_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, - void *rs_ctx) +static int ecdsa_sign_rs_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng, + void *rs_ctx ) { - return mbedtls_ecdsa_write_signature_restartable( - (mbedtls_ecdsa_context *) pk->pk_ctx, - md_alg, hash, hash_len, sig, sig_size, sig_len, f_rng, p_rng, - (mbedtls_ecdsa_restart_ctx *) rs_ctx); + return( mbedtls_ecdsa_write_signature_restartable( + (mbedtls_ecdsa_context *) ctx, + md_alg, hash, hash_len, sig, sig_size, sig_len, f_rng, p_rng, + (mbedtls_ecdsa_restart_ctx *) rs_ctx ) ); } +#endif /* MBEDTLS_ECP_RESTARTABLE */ -static void *ecdsa_rs_alloc(void) +static void *ecdsa_alloc_wrap( void ) { - void *ctx = mbedtls_calloc(1, sizeof(mbedtls_ecdsa_restart_ctx)); + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_context ) ); - if (ctx != NULL) { - mbedtls_ecdsa_restart_init(ctx); - } + if( ctx != NULL ) + mbedtls_ecdsa_init( (mbedtls_ecdsa_context *) ctx ); + + return( ctx ); +} + +static void ecdsa_free_wrap( void *ctx ) +{ + mbedtls_ecdsa_free( (mbedtls_ecdsa_context *) ctx ); + mbedtls_free( ctx ); +} - return ctx; +#if defined(MBEDTLS_ECP_RESTARTABLE) +static void *ecdsa_rs_alloc( void ) +{ + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_restart_ctx ) ); + + if( ctx != NULL ) + mbedtls_ecdsa_restart_init( ctx ); + + return( ctx ); } -static void ecdsa_rs_free(void *ctx) +static void ecdsa_rs_free( void *ctx ) { - mbedtls_ecdsa_restart_free(ctx); - mbedtls_free(ctx); + mbedtls_ecdsa_restart_free( ctx ); + mbedtls_free( ctx ); } -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ +#endif /* MBEDTLS_ECP_RESTARTABLE */ const mbedtls_pk_info_t mbedtls_ecdsa_info = { - .type = MBEDTLS_PK_ECDSA, - .name = "ECDSA", - .get_bitlen = eckey_get_bitlen, /* Compatible key structures */ - .can_do = ecdsa_can_do, -#if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) - .verify_func = ecdsa_verify_wrap, /* Compatible key structures */ -#else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ - .verify_func = NULL, -#endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ -#if defined(MBEDTLS_PK_CAN_ECDSA_SIGN) - .sign_func = ecdsa_sign_wrap, /* Compatible key structures */ -#else /* MBEDTLS_PK_CAN_ECDSA_SIGN */ - .sign_func = NULL, -#endif /* MBEDTLS_PK_CAN_ECDSA_SIGN */ -#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - .verify_rs_func = ecdsa_verify_rs_wrap, - .sign_rs_func = ecdsa_sign_rs_wrap, - .rs_alloc_func = ecdsa_rs_alloc, - .rs_free_func = ecdsa_rs_free, -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - .decrypt_func = NULL, - .encrypt_func = NULL, - .check_pair_func = eckey_check_pair_wrap, /* Compatible key structures */ -#if defined(MBEDTLS_PK_USE_PSA_EC_DATA) - .ctx_alloc_func = NULL, - .ctx_free_func = NULL, -#else /* MBEDTLS_PK_USE_PSA_EC_DATA */ - .ctx_alloc_func = eckey_alloc_wrap, /* Compatible key structures */ - .ctx_free_func = eckey_free_wrap, /* Compatible key structures */ -#endif /* MBEDTLS_PK_USE_PSA_EC_DATA */ - .debug_func = eckey_debug, /* Compatible key structures */ + MBEDTLS_PK_ECDSA, + "ECDSA", + eckey_get_bitlen, /* Compatible key structures */ + ecdsa_can_do, + ecdsa_verify_wrap, + ecdsa_sign_wrap, +#if defined(MBEDTLS_ECP_RESTARTABLE) + ecdsa_verify_rs_wrap, + ecdsa_sign_rs_wrap, +#endif + NULL, + NULL, + eckey_check_pair, /* Compatible key structures */ + ecdsa_alloc_wrap, + ecdsa_free_wrap, +#if defined(MBEDTLS_ECP_RESTARTABLE) + ecdsa_rs_alloc, + ecdsa_rs_free, +#endif + eckey_debug, /* Compatible key structures */ }; -#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */ -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ +#endif /* MBEDTLS_ECDSA_C */ #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) /* * Support for alternative RSA-private implementations */ -static int rsa_alt_can_do(mbedtls_pk_type_t type) +static int rsa_alt_can_do( mbedtls_pk_type_t type ) { - return type == MBEDTLS_PK_RSA; + return( type == MBEDTLS_PK_RSA ); } -static size_t rsa_alt_get_bitlen(mbedtls_pk_context *pk) +static size_t rsa_alt_get_bitlen( const void *ctx ) { - const mbedtls_rsa_alt_context *rsa_alt = pk->pk_ctx; + const mbedtls_rsa_alt_context *rsa_alt = (const mbedtls_rsa_alt_context *) ctx; - return 8 * rsa_alt->key_len_func(rsa_alt->key); + return( 8 * rsa_alt->key_len_func( rsa_alt->key ) ); } -static int rsa_alt_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - mbedtls_rsa_alt_context *rsa_alt = pk->pk_ctx; + mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx; #if SIZE_MAX > UINT_MAX - if (UINT_MAX < hash_len) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } -#endif - - *sig_len = rsa_alt->key_len_func(rsa_alt->key); - if (*sig_len > MBEDTLS_PK_SIGNATURE_MAX_SIZE) { - return MBEDTLS_ERR_PK_BAD_INPUT_DATA; - } - if (*sig_len > sig_size) { - return MBEDTLS_ERR_PK_BUFFER_TOO_SMALL; - } - - return rsa_alt->sign_func(rsa_alt->key, f_rng, p_rng, - md_alg, (unsigned int) hash_len, hash, sig); + if( UINT_MAX < hash_len ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); +#endif /* SIZE_MAX > UINT_MAX */ + + *sig_len = rsa_alt->key_len_func( rsa_alt->key ); + if( *sig_len > MBEDTLS_PK_SIGNATURE_MAX_SIZE ) + return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); + if( *sig_len > sig_size ) + return( MBEDTLS_ERR_PK_BUFFER_TOO_SMALL ); + + return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, + md_alg, (unsigned int) hash_len, hash, sig ) ); } -static int rsa_alt_decrypt_wrap(mbedtls_pk_context *pk, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int rsa_alt_decrypt_wrap( void *ctx, + const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - mbedtls_rsa_alt_context *rsa_alt = pk->pk_ctx; + mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx; ((void) f_rng); ((void) p_rng); - if (ilen != rsa_alt->key_len_func(rsa_alt->key)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ilen != rsa_alt->key_len_func( rsa_alt->key ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - return rsa_alt->decrypt_func(rsa_alt->key, - olen, input, output, osize); + return( rsa_alt->decrypt_func( rsa_alt->key, + olen, input, output, osize ) ); } #if defined(MBEDTLS_RSA_C) -static int rsa_alt_check_pair(mbedtls_pk_context *pub, mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +static int rsa_alt_check_pair( const void *pub, const void *prv, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { unsigned char sig[MBEDTLS_MPI_MAX_SIZE]; unsigned char hash[32]; size_t sig_len = 0; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - if (rsa_alt_get_bitlen(prv) != rsa_get_bitlen(pub)) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; - } + if( rsa_alt_get_bitlen( prv ) != rsa_get_bitlen( pub ) ) + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); - memset(hash, 0x2a, sizeof(hash)); + memset( hash, 0x2a, sizeof( hash ) ); - if ((ret = rsa_alt_sign_wrap(prv, MBEDTLS_MD_NONE, - hash, sizeof(hash), - sig, sizeof(sig), &sig_len, - f_rng, p_rng)) != 0) { - return ret; + if( ( ret = rsa_alt_sign_wrap( (void *) prv, MBEDTLS_MD_NONE, + hash, sizeof( hash ), + sig, sizeof( sig ), &sig_len, + f_rng, p_rng ) ) != 0 ) + { + return( ret ); } - if (rsa_verify_wrap(pub, MBEDTLS_MD_NONE, - hash, sizeof(hash), sig, sig_len) != 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + if( rsa_verify_wrap( (void *) pub, MBEDTLS_MD_NONE, + hash, sizeof( hash ), sig, sig_len ) != 0 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } - return 0; + return( 0 ); } #endif /* MBEDTLS_RSA_C */ -static void *rsa_alt_alloc_wrap(void) +static void *rsa_alt_alloc_wrap( void ) { - void *ctx = mbedtls_calloc(1, sizeof(mbedtls_rsa_alt_context)); + void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_rsa_alt_context ) ); - if (ctx != NULL) { - memset(ctx, 0, sizeof(mbedtls_rsa_alt_context)); - } + if( ctx != NULL ) + memset( ctx, 0, sizeof( mbedtls_rsa_alt_context ) ); - return ctx; + return( ctx ); } -static void rsa_alt_free_wrap(void *ctx) +static void rsa_alt_free_wrap( void *ctx ) { - mbedtls_zeroize_and_free(ctx, sizeof(mbedtls_rsa_alt_context)); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_rsa_alt_context ) ); + mbedtls_free( ctx ); } const mbedtls_pk_info_t mbedtls_rsa_alt_info = { - .type = MBEDTLS_PK_RSA_ALT, - .name = "RSA-alt", - .get_bitlen = rsa_alt_get_bitlen, - .can_do = rsa_alt_can_do, - .verify_func = NULL, - .sign_func = rsa_alt_sign_wrap, + MBEDTLS_PK_RSA_ALT, + "RSA-alt", + rsa_alt_get_bitlen, + rsa_alt_can_do, + NULL, + rsa_alt_sign_wrap, #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - .verify_rs_func = NULL, - .sign_rs_func = NULL, - .rs_alloc_func = NULL, - .rs_free_func = NULL, -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - .decrypt_func = rsa_alt_decrypt_wrap, - .encrypt_func = NULL, + NULL, + NULL, +#endif + rsa_alt_decrypt_wrap, + NULL, #if defined(MBEDTLS_RSA_C) - .check_pair_func = rsa_alt_check_pair, + rsa_alt_check_pair, #else - .check_pair_func = NULL, + NULL, #endif - .ctx_alloc_func = rsa_alt_alloc_wrap, - .ctx_free_func = rsa_alt_free_wrap, - .debug_func = NULL, + rsa_alt_alloc_wrap, + rsa_alt_free_wrap, +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) + NULL, + NULL, +#endif + NULL, }; + #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */ #if defined(MBEDTLS_USE_PSA_CRYPTO) -static size_t opaque_get_bitlen(mbedtls_pk_context *pk) + +static void *pk_opaque_alloc_wrap( void ) { - size_t bits; - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + void *ctx = mbedtls_calloc( 1, sizeof( psa_key_id_t ) ); - if (PSA_SUCCESS != psa_get_key_attributes(pk->priv_id, &attributes)) { - return 0; - } + /* no _init() function to call, an calloc() already zeroized */ - bits = psa_get_key_bits(&attributes); - psa_reset_key_attributes(&attributes); - return bits; + return( ctx ); } -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) -static int ecdsa_opaque_can_do(mbedtls_pk_type_t type) +static void pk_opaque_free_wrap( void *ctx ) { - return type == MBEDTLS_PK_ECKEY || - type == MBEDTLS_PK_ECDSA; + mbedtls_platform_zeroize( ctx, sizeof( psa_key_id_t ) ); + mbedtls_free( ctx ); } -const mbedtls_pk_info_t mbedtls_ecdsa_opaque_info = { - .type = MBEDTLS_PK_OPAQUE, - .name = "Opaque", - .get_bitlen = opaque_get_bitlen, - .can_do = ecdsa_opaque_can_do, -#if defined(MBEDTLS_PK_CAN_ECDSA_VERIFY) - .verify_func = ecdsa_opaque_verify_wrap, -#else /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ - .verify_func = NULL, -#endif /* MBEDTLS_PK_CAN_ECDSA_VERIFY */ -#if defined(MBEDTLS_PK_CAN_ECDSA_SIGN) - .sign_func = ecdsa_opaque_sign_wrap, -#else /* MBEDTLS_PK_CAN_ECDSA_SIGN */ - .sign_func = NULL, -#endif /* MBEDTLS_PK_CAN_ECDSA_SIGN */ -#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - .verify_rs_func = NULL, - .sign_rs_func = NULL, - .rs_alloc_func = NULL, - .rs_free_func = NULL, -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ - .decrypt_func = NULL, - .encrypt_func = NULL, - .check_pair_func = ecdsa_opaque_check_pair_wrap, - .ctx_alloc_func = NULL, - .ctx_free_func = NULL, - .debug_func = NULL, -}; -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ +static size_t pk_opaque_get_bitlen( const void *ctx ) +{ + const psa_key_id_t *key = (const psa_key_id_t *) ctx; + size_t bits; + psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; + + if( PSA_SUCCESS != psa_get_key_attributes( *key, &attributes ) ) + return( 0 ); + + bits = psa_get_key_bits( &attributes ); + psa_reset_key_attributes( &attributes ); + return( bits ); +} -static int rsa_opaque_can_do(mbedtls_pk_type_t type) +static int pk_opaque_can_do( mbedtls_pk_type_t type ) { - return type == MBEDTLS_PK_RSA || - type == MBEDTLS_PK_RSASSA_PSS; + /* For now opaque PSA keys can only wrap ECC keypairs, + * as checked by setup_psa(). + * Also, ECKEY_DH does not really make sense with the current API. */ + return( type == MBEDTLS_PK_ECKEY || + type == MBEDTLS_PK_ECDSA ); } -#if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) -static int rsa_opaque_decrypt(mbedtls_pk_context *pk, - const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +#if defined(MBEDTLS_ECDSA_C) + +/* + * Simultaneously convert and move raw MPI from the beginning of a buffer + * to an ASN.1 MPI at the end of the buffer. + * See also mbedtls_asn1_write_mpi(). + * + * p: pointer to the end of the output buffer + * start: start of the output buffer, and also of the mpi to write at the end + * n_len: length of the mpi to read from start + */ +static int asn1_write_mpibuf( unsigned char **p, unsigned char *start, + size_t n_len ) { - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_algorithm_t alg; - psa_key_type_t type; - psa_status_t status; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t len = 0; - /* PSA has its own RNG */ - (void) f_rng; - (void) p_rng; + if( (size_t)( *p - start ) < n_len ) + return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); + + len = n_len; + *p -= len; + memmove( *p, start, len ); - status = psa_get_key_attributes(pk->priv_id, &attributes); - if (status != PSA_SUCCESS) { - return PSA_PK_TO_MBEDTLS_ERR(status); + /* ASN.1 DER encoding requires minimal length, so skip leading 0s. + * Neither r nor s should be 0, but as a failsafe measure, still detect + * that rather than overflowing the buffer in case of a PSA error. */ + while( len > 0 && **p == 0x00 ) + { + ++(*p); + --len; } - type = psa_get_key_type(&attributes); - alg = psa_get_key_algorithm(&attributes); - psa_reset_key_attributes(&attributes); + /* this is only reached if the signature was invalid */ + if( len == 0 ) + return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED ); - if (!PSA_KEY_TYPE_IS_RSA(type)) { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; - } + /* if the msb is 1, ASN.1 requires that we prepend a 0. + * Neither r nor s can be 0, so we can assume len > 0 at all times. */ + if( **p & 0x80 ) + { + if( *p - start < 1 ) + return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL ); - status = psa_asymmetric_decrypt(pk->priv_id, alg, input, ilen, NULL, 0, output, osize, olen); - if (status != PSA_SUCCESS) { - return PSA_PK_RSA_TO_MBEDTLS_ERR(status); + *--(*p) = 0x00; + len += 1; } - return 0; + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( p, start, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( p, start, + MBEDTLS_ASN1_INTEGER ) ); + + return( (int) len ); } -#endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */ -static int rsa_opaque_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +/* Transcode signature from PSA format to ASN.1 sequence. + * See ecdsa_signature_to_asn1 in ecdsa.c, but with byte buffers instead of + * MPIs, and in-place. + * + * [in/out] sig: the signature pre- and post-transcoding + * [in/out] sig_len: signature length pre- and post-transcoding + * [int] buf_len: the available size the in/out buffer + */ +static int pk_ecdsa_sig_asn1_from_psa( unsigned char *sig, size_t *sig_len, + size_t buf_len ) { -#if defined(MBEDTLS_RSA_C) - psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; - psa_algorithm_t alg; - psa_key_type_t type; - psa_status_t status; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t len = 0; + const size_t rs_len = *sig_len / 2; + unsigned char *p = sig + buf_len; - /* PSA has its own RNG */ - (void) f_rng; - (void) p_rng; + MBEDTLS_ASN1_CHK_ADD( len, asn1_write_mpibuf( &p, sig + rs_len, rs_len ) ); + MBEDTLS_ASN1_CHK_ADD( len, asn1_write_mpibuf( &p, sig, rs_len ) ); - status = psa_get_key_attributes(pk->priv_id, &attributes); - if (status != PSA_SUCCESS) { - return PSA_PK_TO_MBEDTLS_ERR(status); - } + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &p, sig, len ) ); + MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &p, sig, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ); - type = psa_get_key_type(&attributes); - alg = psa_get_key_algorithm(&attributes); - psa_reset_key_attributes(&attributes); + memmove( sig, p, len ); + *sig_len = len; - if (PSA_KEY_TYPE_IS_RSA(type)) { - alg = (alg & ~PSA_ALG_HASH_MASK) | mbedtls_md_psa_alg_from_type(md_alg); - } else { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; - } + return( 0 ); +} - status = psa_sign_hash(pk->priv_id, alg, hash, hash_len, sig, sig_size, sig_len); - if (status != PSA_SUCCESS) { - if (PSA_KEY_TYPE_IS_RSA(type)) { - return PSA_PK_RSA_TO_MBEDTLS_ERR(status); - } else { - return PSA_PK_TO_MBEDTLS_ERR(status); - } - } +#endif /* MBEDTLS_ECDSA_C */ - return 0; -#else /* !MBEDTLS_RSA_C */ - ((void) pk); +static int pk_opaque_sign_wrap( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) +{ +#if !defined(MBEDTLS_ECDSA_C) + ((void) ctx); ((void) md_alg); ((void) hash); ((void) hash_len); @@ -1553,33 +1031,48 @@ static int rsa_opaque_sign_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg ((void) sig_len); ((void) f_rng); ((void) p_rng); - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; -#endif /* !MBEDTLS_RSA_C */ + return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); +#else /* !MBEDTLS_ECDSA_C */ + const psa_key_id_t *key = (const psa_key_id_t *) ctx; + psa_algorithm_t alg = PSA_ALG_ECDSA( mbedtls_psa_translate_md( md_alg ) ); + psa_status_t status; + + /* PSA has its own RNG */ + (void) f_rng; + (void) p_rng; + + /* make the signature */ + status = psa_sign_hash( *key, alg, hash, hash_len, + sig, sig_size, sig_len ); + if( status != PSA_SUCCESS ) + return( mbedtls_psa_err_translate_pk( status ) ); + + /* transcode it to ASN.1 sequence */ + return( pk_ecdsa_sig_asn1_from_psa( sig, sig_len, sig_size ) ); +#endif /* !MBEDTLS_ECDSA_C */ } -const mbedtls_pk_info_t mbedtls_rsa_opaque_info = { - .type = MBEDTLS_PK_OPAQUE, - .name = "Opaque", - .get_bitlen = opaque_get_bitlen, - .can_do = rsa_opaque_can_do, - .verify_func = NULL, - .sign_func = rsa_opaque_sign_wrap, +const mbedtls_pk_info_t mbedtls_pk_opaque_info = { + MBEDTLS_PK_OPAQUE, + "Opaque", + pk_opaque_get_bitlen, + pk_opaque_can_do, + NULL, /* verify - will be done later */ + pk_opaque_sign_wrap, #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) - .verify_rs_func = NULL, - .sign_rs_func = NULL, - .rs_alloc_func = NULL, - .rs_free_func = NULL, -#endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ -#if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) - .decrypt_func = rsa_opaque_decrypt, -#else /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */ - .decrypt_func = NULL, -#endif /* PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC */ - .encrypt_func = NULL, - .check_pair_func = NULL, - .ctx_alloc_func = NULL, - .ctx_free_func = NULL, - .debug_func = NULL, + NULL, /* restartable verify - not relevant */ + NULL, /* restartable sign - not relevant */ +#endif + NULL, /* decrypt - will be done later */ + NULL, /* encrypt - will be done later */ + NULL, /* check_pair - could be done later or left NULL */ + pk_opaque_alloc_wrap, + pk_opaque_free_wrap, +#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) + NULL, /* restart alloc - not relevant */ + NULL, /* restart free - not relevant */ +#endif + NULL, /* debug - could be done later, or even left NULL */ }; #endif /* MBEDTLS_USE_PSA_CRYPTO */ diff --git a/src/duckdb/third_party/mbedtls/library/pk_wrap.h b/src/duckdb/third_party/mbedtls/library/pk_wrap.h index be096da53..6f5addf75 100644 --- a/src/duckdb/third_party/mbedtls/library/pk_wrap.h +++ b/src/duckdb/third_party/mbedtls/library/pk_wrap.h @@ -5,7 +5,19 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef MBEDTLS_PK_WRAP_H @@ -15,11 +27,8 @@ #include "mbedtls/pk.h" -#if defined(MBEDTLS_USE_PSA_CRYPTO) -#include "psa/crypto.h" -#endif - -struct mbedtls_pk_info_t { +struct mbedtls_pk_info_t +{ /** Public key type */ mbedtls_pk_type_t type; @@ -27,76 +36,77 @@ struct mbedtls_pk_info_t { const char *name; /** Get key size in bits */ - size_t (*get_bitlen)(mbedtls_pk_context *pk); + size_t (*get_bitlen)( const void * ); /** Tell if the context implements this type (e.g. ECKEY can do ECDSA) */ - int (*can_do)(mbedtls_pk_type_t type); + int (*can_do)( mbedtls_pk_type_t type ); /** Verify signature */ - int (*verify_func)(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len); + int (*verify_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len ); /** Make signature */ - int (*sign_func)(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); + int (*sign_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /** Verify signature (restartable) */ - int (*verify_rs_func)(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - const unsigned char *sig, size_t sig_len, - void *rs_ctx); + int (*verify_rs_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + const unsigned char *sig, size_t sig_len, + void *rs_ctx ); /** Make signature (restartable) */ - int (*sign_rs_func)(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, size_t *sig_len, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, void *rs_ctx); + int (*sign_rs_func)( void *ctx, mbedtls_md_type_t md_alg, + const unsigned char *hash, size_t hash_len, + unsigned char *sig, size_t sig_size, size_t *sig_len, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, void *rs_ctx ); #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ /** Decrypt message */ - int (*decrypt_func)(mbedtls_pk_context *pk, const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); + int (*decrypt_func)( void *ctx, const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** Encrypt message */ - int (*encrypt_func)(mbedtls_pk_context *pk, const unsigned char *input, size_t ilen, - unsigned char *output, size_t *olen, size_t osize, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); + int (*encrypt_func)( void *ctx, const unsigned char *input, size_t ilen, + unsigned char *output, size_t *olen, size_t osize, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** Check public-private key pair */ - int (*check_pair_func)(mbedtls_pk_context *pub, mbedtls_pk_context *prv, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); + int (*check_pair_func)( const void *pub, const void *prv, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** Allocate a new context */ - void * (*ctx_alloc_func)(void); + void * (*ctx_alloc_func)( void ); /** Free the given context */ - void (*ctx_free_func)(void *ctx); + void (*ctx_free_func)( void *ctx ); #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE) /** Allocate the restart context */ - void *(*rs_alloc_func)(void); + void * (*rs_alloc_func)( void ); /** Free the restart context */ - void (*rs_free_func)(void *rs_ctx); + void (*rs_free_func)( void *rs_ctx ); #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */ /** Interface with the debug module */ - void (*debug_func)(mbedtls_pk_context *pk, mbedtls_pk_debug_item *items); + void (*debug_func)( const void *ctx, mbedtls_pk_debug_item *items ); }; #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) /* Container for RSA-alt */ -typedef struct { +typedef struct +{ void *key; mbedtls_pk_rsa_alt_decrypt_func decrypt_func; mbedtls_pk_rsa_alt_sign_func sign_func; @@ -108,12 +118,12 @@ typedef struct { extern const mbedtls_pk_info_t mbedtls_rsa_info; #endif -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_ECP_C) extern const mbedtls_pk_info_t mbedtls_eckey_info; extern const mbedtls_pk_info_t mbedtls_eckeydh_info; #endif -#if defined(MBEDTLS_PK_CAN_ECDSA_SOME) +#if defined(MBEDTLS_ECDSA_C) extern const mbedtls_pk_info_t mbedtls_ecdsa_info; #endif @@ -122,17 +132,7 @@ extern const mbedtls_pk_info_t mbedtls_rsa_alt_info; #endif #if defined(MBEDTLS_USE_PSA_CRYPTO) -extern const mbedtls_pk_info_t mbedtls_ecdsa_opaque_info; -extern const mbedtls_pk_info_t mbedtls_rsa_opaque_info; - -#if defined(MBEDTLS_RSA_C) -int mbedtls_pk_psa_rsa_sign_ext(psa_algorithm_t psa_alg_md, - mbedtls_rsa_context *rsa_ctx, - const unsigned char *hash, size_t hash_len, - unsigned char *sig, size_t sig_size, - size_t *sig_len); -#endif /* MBEDTLS_RSA_C */ - -#endif /* MBEDTLS_USE_PSA_CRYPTO */ +extern const mbedtls_pk_info_t mbedtls_pk_opaque_info; +#endif #endif /* MBEDTLS_PK_WRAP_H */ diff --git a/src/duckdb/third_party/mbedtls/library/pkparse.cpp b/src/duckdb/third_party/mbedtls/library/pkparse.cpp index 6f478f012..b2d3bb074 100644 --- a/src/duckdb/third_party/mbedtls/library/pkparse.cpp +++ b/src/duckdb/third_party/mbedtls/library/pkparse.cpp @@ -2,7 +2,19 @@ * Public Key layer for parsing key files and structures * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "common.h" @@ -13,25 +25,19 @@ #include "mbedtls/asn1.h" #include "mbedtls/oid.h" #include "mbedtls/platform_util.h" -#include "mbedtls/platform.h" #include "mbedtls/error.h" -#include "mbedtls/ecp.h" -#include "pk_internal.h" #include -#if defined(MBEDTLS_USE_PSA_CRYPTO) -#include "mbedtls/psa_util.h" -#include "psa/crypto.h" -#endif - -/* Key types */ #if defined(MBEDTLS_RSA_C) #include "mbedtls/rsa.h" -#include "rsa_internal.h" #endif - -/* Extended formats */ +#if defined(MBEDTLS_ECP_C) +#include "mbedtls/ecp.h" +#endif +#if defined(MBEDTLS_ECDSA_C) +#include "mbedtls/ecdsa.h" +#endif #if defined(MBEDTLS_PEM_PARSE_C) #include "mbedtls/pem.h" #endif @@ -42,55 +48,180 @@ #include "mbedtls/pkcs12.h" #endif -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#include +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif + +/* Parameter validation macros based on platform_util.h */ +#define PK_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_PK_BAD_INPUT_DATA ) +#define PK_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) -/*********************************************************************** - * - * Low-level ECC parsing: optional support for SpecifiedECDomain - * - * There are two functions here that are used by the rest of the code: - * - pk_ecc_tag_is_speficied_ec_domain() - * - pk_ecc_group_id_from_specified() - * - * All the other functions are internal to this section. - * - * The two "public" functions have a dummy variant provided - * in configs without MBEDTLS_PK_PARSE_EC_EXTENDED. This acts as an - * abstraction layer for this macro, which should not appear outside - * this section. +#if defined(MBEDTLS_FS_IO) +/* + * Load all data from a file into a given buffer. * - **********************************************************************/ - -#if !defined(MBEDTLS_PK_PARSE_EC_EXTENDED) -/* See the "real" version for documentation */ -static int pk_ecc_tag_is_specified_ec_domain(int tag) + * The file is expected to contain either PEM or DER encoded data. + * A terminating null byte is always appended. It is included in the announced + * length only if the data looks like it is PEM encoded. + */ +int mbedtls_pk_load_file( const char *path, unsigned char **buf, size_t *n ) { - (void) tag; - return 0; + FILE *f; + long size; + + PK_VALIDATE_RET( path != NULL ); + PK_VALIDATE_RET( buf != NULL ); + PK_VALIDATE_RET( n != NULL ); + + if( ( f = fopen( path, "rb" ) ) == NULL ) + return( MBEDTLS_ERR_PK_FILE_IO_ERROR ); + + fseek( f, 0, SEEK_END ); + if( ( size = ftell( f ) ) == -1 ) + { + fclose( f ); + return( MBEDTLS_ERR_PK_FILE_IO_ERROR ); + } + fseek( f, 0, SEEK_SET ); + + *n = (size_t) size; + + if( *n + 1 == 0 || + ( *buf = mbedtls_calloc( 1, *n + 1 ) ) == NULL ) + { + fclose( f ); + return( MBEDTLS_ERR_PK_ALLOC_FAILED ); + } + + if( fread( *buf, 1, *n, f ) != *n ) + { + fclose( f ); + + mbedtls_platform_zeroize( *buf, *n ); + mbedtls_free( *buf ); + + return( MBEDTLS_ERR_PK_FILE_IO_ERROR ); + } + + fclose( f ); + + (*buf)[*n] = '\0'; + + if( strstr( (const char *) *buf, "-----BEGIN " ) != NULL ) + ++*n; + + return( 0 ); } -/* See the "real" version for documentation */ -static int pk_ecc_group_id_from_specified(const mbedtls_asn1_buf *params, - mbedtls_ecp_group_id *grp_id) +/* + * Load and parse a private key + */ +int mbedtls_pk_parse_keyfile( mbedtls_pk_context *ctx, + const char *path, const char *pwd, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { - (void) params; - (void) grp_id; - return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t n; + unsigned char *buf; + + PK_VALIDATE_RET( ctx != NULL ); + PK_VALIDATE_RET( path != NULL ); + + if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) + return( ret ); + + if( pwd == NULL ) + ret = mbedtls_pk_parse_key( ctx, buf, n, NULL, 0, f_rng, p_rng ); + else + ret = mbedtls_pk_parse_key( ctx, buf, n, + (const unsigned char *) pwd, strlen( pwd ), f_rng, p_rng ); + + mbedtls_platform_zeroize( buf, n ); + mbedtls_free( buf ); + + return( ret ); } -#else /* MBEDTLS_PK_PARSE_EC_EXTENDED */ + /* - * Tell if the passed tag might be the start of SpecifiedECDomain - * (that is, a sequence). + * Load and parse a public key */ -static int pk_ecc_tag_is_specified_ec_domain(int tag) +int mbedtls_pk_parse_public_keyfile( mbedtls_pk_context *ctx, const char *path ) { - return tag == (MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t n; + unsigned char *buf; + + PK_VALIDATE_RET( ctx != NULL ); + PK_VALIDATE_RET( path != NULL ); + + if( ( ret = mbedtls_pk_load_file( path, &buf, &n ) ) != 0 ) + return( ret ); + + ret = mbedtls_pk_parse_public_key( ctx, buf, n ); + + mbedtls_platform_zeroize( buf, n ); + mbedtls_free( buf ); + + return( ret ); } +#endif /* MBEDTLS_FS_IO */ + +#if defined(MBEDTLS_ECP_C) +/* Minimally parse an ECParameters buffer to and mbedtls_asn1_buf + * + * ECParameters ::= CHOICE { + * namedCurve OBJECT IDENTIFIER + * specifiedCurve SpecifiedECDomain -- = SEQUENCE { ... } + * -- implicitCurve NULL + * } + */ +static int pk_get_ecparams( unsigned char **p, const unsigned char *end, + mbedtls_asn1_buf *params ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + if ( end - *p < 1 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_OUT_OF_DATA ) ); + + /* Tag may be either OID or SEQUENCE */ + params->tag = **p; + if( params->tag != MBEDTLS_ASN1_OID +#if defined(MBEDTLS_PK_PARSE_EC_EXTENDED) + && params->tag != ( MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) +#endif + ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ); + } + + if( ( ret = mbedtls_asn1_get_tag( p, end, ¶ms->len, params->tag ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + } + + params->p = *p; + *p += params->len; + + if( *p != end ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); + + return( 0 ); +} + +#if defined(MBEDTLS_PK_PARSE_EC_EXTENDED) /* * Parse a SpecifiedECDomain (SEC 1 C.2) and (mostly) fill the group with it. * WARNING: the resulting group should only be used with - * pk_ecc_group_id_from_specified(), since its base point may not be set correctly + * pk_group_id_from_specified(), since its base point may not be set correctly * if it was encoded compressed. * * SpecifiedECDomain ::= SEQUENCE { @@ -106,23 +237,21 @@ static int pk_ecc_tag_is_specified_ec_domain(int tag) * * We only support prime-field as field type, and ignore hash and cofactor. */ -static int pk_group_from_specified(const mbedtls_asn1_buf *params, mbedtls_ecp_group *grp) +static int pk_group_from_specified( const mbedtls_asn1_buf *params, mbedtls_ecp_group *grp ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *p = params->p; - const unsigned char *const end = params->p + params->len; + const unsigned char * const end = params->p + params->len; const unsigned char *end_field, *end_curve; size_t len; int ver; /* SpecifiedECDomainVersion ::= INTEGER { 1, 2, 3 } */ - if ((ret = mbedtls_asn1_get_int(&p, end, &ver)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_int( &p, end, &ver ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - if (ver < 1 || ver > 3) { - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; - } + if( ver < 1 || ver > 3 ) + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); /* * FieldID { FIELD-ID:IOSet } ::= SEQUENCE { -- Finite field @@ -130,10 +259,9 @@ static int pk_group_from_specified(const mbedtls_asn1_buf *params, mbedtls_ecp_g * parameters FIELD-ID.&Type({IOSet}{@fieldType}) * } */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + return( ret ); end_field = p + len; @@ -145,28 +273,26 @@ static int pk_group_from_specified(const mbedtls_asn1_buf *params, mbedtls_ecp_g * } * prime-field OBJECT IDENTIFIER ::= { id-fieldType 1 } */ - if ((ret = mbedtls_asn1_get_tag(&p, end_field, &len, MBEDTLS_ASN1_OID)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( &p, end_field, &len, MBEDTLS_ASN1_OID ) ) != 0 ) + return( ret ); - if (len != MBEDTLS_OID_SIZE(MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD) || - memcmp(p, MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD, len) != 0) { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; + if( len != MBEDTLS_OID_SIZE( MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD ) || + memcmp( p, MBEDTLS_OID_ANSI_X9_62_PRIME_FIELD, len ) != 0 ) + { + return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); } p += len; /* Prime-p ::= INTEGER -- Field of size p. */ - if ((ret = mbedtls_asn1_get_mpi(&p, end_field, &grp->P)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_mpi( &p, end_field, &grp->P ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - grp->pbits = mbedtls_mpi_bitlen(&grp->P); + grp->pbits = mbedtls_mpi_bitlen( &grp->P ); - if (p != end_field) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); - } + if( p != end_field ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); /* * Curve ::= SEQUENCE { @@ -177,10 +303,9 @@ static int pk_group_from_specified(const mbedtls_asn1_buf *params, mbedtls_ecp_g * -- with version equal to ecdpVer2 or ecdpVer3 * } */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return ret; - } + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + return( ret ); end_curve = p + len; @@ -188,50 +313,51 @@ static int pk_group_from_specified(const mbedtls_asn1_buf *params, mbedtls_ecp_g * FieldElement ::= OCTET STRING * containing an integer in the case of a prime field */ - if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 || - (ret = mbedtls_mpi_read_binary(&grp->A, p, len)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 || + ( ret = mbedtls_mpi_read_binary( &grp->A, p, len ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } p += len; - if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0 || - (ret = mbedtls_mpi_read_binary(&grp->B, p, len)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 || + ( ret = mbedtls_mpi_read_binary( &grp->B, p, len ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } p += len; /* Ignore seed BIT STRING OPTIONAL */ - if ((ret = mbedtls_asn1_get_tag(&p, end_curve, &len, MBEDTLS_ASN1_BIT_STRING)) == 0) { + if( ( ret = mbedtls_asn1_get_tag( &p, end_curve, &len, MBEDTLS_ASN1_BIT_STRING ) ) == 0 ) p += len; - } - if (p != end_curve) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); - } + if( p != end_curve ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); /* * ECPoint ::= OCTET STRING */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - if ((ret = mbedtls_ecp_point_read_binary(grp, &grp->G, - (const unsigned char *) p, len)) != 0) { + if( ( ret = mbedtls_ecp_point_read_binary( grp, &grp->G, + ( const unsigned char *) p, len ) ) != 0 ) + { /* * If we can't read the point because it's compressed, cheat by * reading only the X coordinate and the parity bit of Y. */ - if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE || - (p[0] != 0x02 && p[0] != 0x03) || - len != mbedtls_mpi_size(&grp->P) + 1 || - mbedtls_mpi_read_binary(&grp->G.X, p + 1, len - 1) != 0 || - mbedtls_mpi_lset(&grp->G.Y, p[0] - 2) != 0 || - mbedtls_mpi_lset(&grp->G.Z, 1) != 0) { - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; + if( ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE || + ( p[0] != 0x02 && p[0] != 0x03 ) || + len != mbedtls_mpi_size( &grp->P ) + 1 || + mbedtls_mpi_read_binary( &grp->G.X, p + 1, len - 1 ) != 0 || + mbedtls_mpi_lset( &grp->G.Y, p[0] - 2 ) != 0 || + mbedtls_mpi_lset( &grp->G.Z, 1 ) != 0 ) + { + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); } } @@ -240,227 +366,208 @@ static int pk_group_from_specified(const mbedtls_asn1_buf *params, mbedtls_ecp_g /* * order INTEGER */ - if ((ret = mbedtls_asn1_get_mpi(&p, end, &grp->N)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_mpi( &p, end, &grp->N ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - grp->nbits = mbedtls_mpi_bitlen(&grp->N); + grp->nbits = mbedtls_mpi_bitlen( &grp->N ); /* * Allow optional elements by purposefully not enforcing p == end here. */ - return 0; + return( 0 ); } /* * Find the group id associated with an (almost filled) group as generated by * pk_group_from_specified(), or return an error if unknown. */ -static int pk_group_id_from_group(const mbedtls_ecp_group *grp, mbedtls_ecp_group_id *grp_id) +static int pk_group_id_from_group( const mbedtls_ecp_group *grp, mbedtls_ecp_group_id *grp_id ) { int ret = 0; mbedtls_ecp_group ref; const mbedtls_ecp_group_id *id; - mbedtls_ecp_group_init(&ref); + mbedtls_ecp_group_init( &ref ); - for (id = mbedtls_ecp_grp_id_list(); *id != MBEDTLS_ECP_DP_NONE; id++) { + for( id = mbedtls_ecp_grp_id_list(); *id != MBEDTLS_ECP_DP_NONE; id++ ) + { /* Load the group associated to that id */ - mbedtls_ecp_group_free(&ref); - MBEDTLS_MPI_CHK(mbedtls_ecp_group_load(&ref, *id)); + mbedtls_ecp_group_free( &ref ); + MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &ref, *id ) ); /* Compare to the group we were given, starting with easy tests */ - if (grp->pbits == ref.pbits && grp->nbits == ref.nbits && - mbedtls_mpi_cmp_mpi(&grp->P, &ref.P) == 0 && - mbedtls_mpi_cmp_mpi(&grp->A, &ref.A) == 0 && - mbedtls_mpi_cmp_mpi(&grp->B, &ref.B) == 0 && - mbedtls_mpi_cmp_mpi(&grp->N, &ref.N) == 0 && - mbedtls_mpi_cmp_mpi(&grp->G.X, &ref.G.X) == 0 && - mbedtls_mpi_cmp_mpi(&grp->G.Z, &ref.G.Z) == 0 && + if( grp->pbits == ref.pbits && grp->nbits == ref.nbits && + mbedtls_mpi_cmp_mpi( &grp->P, &ref.P ) == 0 && + mbedtls_mpi_cmp_mpi( &grp->A, &ref.A ) == 0 && + mbedtls_mpi_cmp_mpi( &grp->B, &ref.B ) == 0 && + mbedtls_mpi_cmp_mpi( &grp->N, &ref.N ) == 0 && + mbedtls_mpi_cmp_mpi( &grp->G.X, &ref.G.X ) == 0 && + mbedtls_mpi_cmp_mpi( &grp->G.Z, &ref.G.Z ) == 0 && /* For Y we may only know the parity bit, so compare only that */ - mbedtls_mpi_get_bit(&grp->G.Y, 0) == mbedtls_mpi_get_bit(&ref.G.Y, 0)) { + mbedtls_mpi_get_bit( &grp->G.Y, 0 ) == mbedtls_mpi_get_bit( &ref.G.Y, 0 ) ) + { break; } + } cleanup: - mbedtls_ecp_group_free(&ref); + mbedtls_ecp_group_free( &ref ); *grp_id = *id; - if (ret == 0 && *id == MBEDTLS_ECP_DP_NONE) { + if( ret == 0 && *id == MBEDTLS_ECP_DP_NONE ) ret = MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; - } - return ret; + return( ret ); } /* * Parse a SpecifiedECDomain (SEC 1 C.2) and find the associated group ID */ -static int pk_ecc_group_id_from_specified(const mbedtls_asn1_buf *params, - mbedtls_ecp_group_id *grp_id) +static int pk_group_id_from_specified( const mbedtls_asn1_buf *params, + mbedtls_ecp_group_id *grp_id ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_ecp_group grp; - mbedtls_ecp_group_init(&grp); + mbedtls_ecp_group_init( &grp ); - if ((ret = pk_group_from_specified(params, &grp)) != 0) { + if( ( ret = pk_group_from_specified( params, &grp ) ) != 0 ) goto cleanup; - } - ret = pk_group_id_from_group(&grp, grp_id); + ret = pk_group_id_from_group( &grp, grp_id ); cleanup: - /* The API respecting lifecycle for mbedtls_ecp_group struct is - * _init(), _load() and _free(). In pk_ecc_group_id_from_specified() the - * temporary grp breaks that flow and it's members are populated - * by pk_group_id_from_group(). As such mbedtls_ecp_group_free() - * which is assuming a group populated by _setup() may not clean-up - * properly -> Manually free it's members. - */ - mbedtls_mpi_free(&grp.N); - mbedtls_mpi_free(&grp.P); - mbedtls_mpi_free(&grp.A); - mbedtls_mpi_free(&grp.B); - mbedtls_ecp_point_free(&grp.G); + mbedtls_ecp_group_free( &grp ); - return ret; + return( ret ); } #endif /* MBEDTLS_PK_PARSE_EC_EXTENDED */ -/*********************************************************************** - * - * Unsorted (yet!) from this point on until the next section header - * - **********************************************************************/ - -/* Minimally parse an ECParameters buffer to and mbedtls_asn1_buf +/* + * Use EC parameters to initialise an EC group * * ECParameters ::= CHOICE { * namedCurve OBJECT IDENTIFIER * specifiedCurve SpecifiedECDomain -- = SEQUENCE { ... } * -- implicitCurve NULL - * } */ -static int pk_get_ecparams(unsigned char **p, const unsigned char *end, - mbedtls_asn1_buf *params) +static int pk_use_ecparams( const mbedtls_asn1_buf *params, mbedtls_ecp_group *grp ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + mbedtls_ecp_group_id grp_id; - if (end - *p < 1) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_OUT_OF_DATA); - } - - /* Acceptable tags: OID for namedCurve, or specifiedECDomain */ - params->tag = **p; - if (params->tag != MBEDTLS_ASN1_OID && - !pk_ecc_tag_is_specified_ec_domain(params->tag)) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_UNEXPECTED_TAG); + if( params->tag == MBEDTLS_ASN1_OID ) + { + if( mbedtls_oid_get_ec_grp( params, &grp_id ) != 0 ) + return( MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE ); } - - if ((ret = mbedtls_asn1_get_tag(p, end, ¶ms->len, params->tag)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + else + { +#if defined(MBEDTLS_PK_PARSE_EC_EXTENDED) + if( ( ret = pk_group_id_from_specified( params, &grp_id ) ) != 0 ) + return( ret ); +#else + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); +#endif } - params->p = *p; - *p += params->len; + /* + * grp may already be initilialized; if so, make sure IDs match + */ + if( grp->id != MBEDTLS_ECP_DP_NONE && grp->id != grp_id ) + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); - if (*p != end) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); - } + if( ( ret = mbedtls_ecp_group_load( grp, grp_id ) ) != 0 ) + return( ret ); - return 0; + return( 0 ); } /* - * Use EC parameters to initialise an EC group + * EC public key is an EC point * - * ECParameters ::= CHOICE { - * namedCurve OBJECT IDENTIFIER - * specifiedCurve SpecifiedECDomain -- = SEQUENCE { ... } - * -- implicitCurve NULL + * The caller is responsible for clearing the structure upon failure if + * desired. Take care to pass along the possible ECP_FEATURE_UNAVAILABLE + * return code of mbedtls_ecp_point_read_binary() and leave p in a usable state. */ -static int pk_use_ecparams(const mbedtls_asn1_buf *params, mbedtls_pk_context *pk) +static int pk_get_ecpubkey( unsigned char **p, const unsigned char *end, + mbedtls_ecp_keypair *key ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - mbedtls_ecp_group_id grp_id; - if (params->tag == MBEDTLS_ASN1_OID) { - if (mbedtls_oid_get_ec_grp(params, &grp_id) != 0) { - return MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE; - } - } else { - ret = pk_ecc_group_id_from_specified(params, &grp_id); - if (ret != 0) { - return ret; - } + if( ( ret = mbedtls_ecp_point_read_binary( &key->grp, &key->Q, + (const unsigned char *) *p, end - *p ) ) == 0 ) + { + ret = mbedtls_ecp_check_pubkey( &key->grp, &key->Q ); } - return mbedtls_pk_ecc_set_group(pk, grp_id); -} - -#if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES) - -/* - * Load an RFC8410 EC key, which doesn't have any parameters - */ -static int pk_use_ecparams_rfc8410(const mbedtls_asn1_buf *params, - mbedtls_ecp_group_id grp_id, - mbedtls_pk_context *pk) -{ - if (params->tag != 0 || params->len != 0) { - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; - } + /* + * We know mbedtls_ecp_point_read_binary consumed all bytes or failed + */ + *p = (unsigned char *) end; - return mbedtls_pk_ecc_set_group(pk, grp_id); + return( ret ); } +#endif /* MBEDTLS_ECP_C */ +#if defined(MBEDTLS_RSA_C) /* - * Parse an RFC 8410 encoded private EC key - * - * CurvePrivateKey ::= OCTET STRING + * RSAPublicKey ::= SEQUENCE { + * modulus INTEGER, -- n + * publicExponent INTEGER -- e + * } */ -static int pk_parse_key_rfc8410_der(mbedtls_pk_context *pk, - unsigned char *key, size_t keylen, const unsigned char *end, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int pk_get_rsapubkey( unsigned char **p, + const unsigned char *end, + mbedtls_rsa_context *rsa ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t len; - if ((ret = mbedtls_asn1_get_tag(&key, (key + keylen), &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); - if (key + len != end) { - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; - } + if( *p + len != end ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - /* - * Load the private key - */ - ret = mbedtls_pk_ecc_set_key(pk, key, len); - if (ret != 0) { - return ret; - } + /* Import N */ + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); + + if( ( ret = mbedtls_rsa_import_raw( rsa, *p, len, NULL, 0, NULL, 0, + NULL, 0, NULL, 0 ) ) != 0 ) + return( MBEDTLS_ERR_PK_INVALID_PUBKEY ); + + *p += len; + + /* Import E */ + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, MBEDTLS_ASN1_INTEGER ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); + + if( ( ret = mbedtls_rsa_import_raw( rsa, NULL, 0, NULL, 0, NULL, 0, + NULL, 0, *p, len ) ) != 0 ) + return( MBEDTLS_ERR_PK_INVALID_PUBKEY ); + + *p += len; - /* pk_parse_key_pkcs8_unencrypted_der() only supports version 1 PKCS8 keys, - * which never contain a public key. As such, derive the public key - * unconditionally. */ - if ((ret = mbedtls_pk_ecc_set_pubkey_from_prv(pk, key, len, f_rng, p_rng)) != 0) { - return ret; + if( mbedtls_rsa_complete( rsa ) != 0 || + mbedtls_rsa_check_pubkey( rsa ) != 0 ) + { + return( MBEDTLS_ERR_PK_INVALID_PUBKEY ); } - return 0; -} -#endif /* MBEDTLS_PK_HAVE_RFC8410_CURVES */ + if( *p != end ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ + return( 0 ); +} +#endif /* MBEDTLS_RSA_C */ /* Get a PK algorithm identifier * @@ -468,45 +575,32 @@ static int pk_parse_key_rfc8410_der(mbedtls_pk_context *pk, * algorithm OBJECT IDENTIFIER, * parameters ANY DEFINED BY algorithm OPTIONAL } */ -static int pk_get_pk_alg(unsigned char **p, - const unsigned char *end, - mbedtls_pk_type_t *pk_alg, mbedtls_asn1_buf *params, - void *ec_grp_id) +static int pk_get_pk_alg( unsigned char **p, + const unsigned char *end, + mbedtls_pk_type_t *pk_alg, mbedtls_asn1_buf *params ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_asn1_buf alg_oid; - memset(params, 0, sizeof(mbedtls_asn1_buf)); + memset( params, 0, sizeof(mbedtls_asn1_buf) ); - if ((ret = mbedtls_asn1_get_alg(p, end, &alg_oid, params)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_ALG, ret); - } + if( ( ret = mbedtls_asn1_get_alg( p, end, &alg_oid, params ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_ALG, ret ) ); - ret = mbedtls_oid_get_pk_alg(&alg_oid, pk_alg); -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - if (ret == MBEDTLS_ERR_OID_NOT_FOUND) { - ret = mbedtls_oid_get_ec_grp_algid(&alg_oid, reinterpret_cast(ec_grp_id)); - if (ret == 0) { - *pk_alg = MBEDTLS_PK_ECKEY; - } - } -#else - (void) ec_grp_id; -#endif - if (ret != 0) { - return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; - } + if( mbedtls_oid_get_pk_alg( &alg_oid, pk_alg ) != 0 ) + return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); /* * No parameters with RSA (only for EC) */ - if (*pk_alg == MBEDTLS_PK_RSA && - ((params->tag != MBEDTLS_ASN1_NULL && params->tag != 0) || - params->len != 0)) { - return MBEDTLS_ERR_PK_INVALID_ALG; + if( *pk_alg == MBEDTLS_PK_RSA && + ( ( params->tag != MBEDTLS_ASN1_NULL && params->tag != 0 ) || + params->len != 0 ) ) + { + return( MBEDTLS_ERR_PK_INVALID_ALG ); } - return 0; + return( 0 ); } /* @@ -514,103 +608,266 @@ static int pk_get_pk_alg(unsigned char **p, * algorithm AlgorithmIdentifier, * subjectPublicKey BIT STRING } */ -int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end, - mbedtls_pk_context *pk) +int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end, + mbedtls_pk_context *pk ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t len; mbedtls_asn1_buf alg_params; mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE; - int ec_grp_id = 0; const mbedtls_pk_info_t *pk_info; - if ((ret = mbedtls_asn1_get_tag(p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + PK_VALIDATE_RET( p != NULL ); + PK_VALIDATE_RET( *p != NULL ); + PK_VALIDATE_RET( end != NULL ); + PK_VALIDATE_RET( pk != NULL ); + + if( ( ret = mbedtls_asn1_get_tag( p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } end = *p + len; - if ((ret = pk_get_pk_alg(p, end, &pk_alg, &alg_params, &ec_grp_id)) != 0) { - return ret; - } + if( ( ret = pk_get_pk_alg( p, end, &pk_alg, &alg_params ) ) != 0 ) + return( ret ); - if ((ret = mbedtls_asn1_get_bitstring_null(p, end, &len)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret); - } + if( ( ret = mbedtls_asn1_get_bitstring_null( p, end, &len ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, ret ) ); - if (*p + len != end) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); - } + if( *p + len != end ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) { - return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; - } + if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL ) + return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); - if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) { - return ret; - } + if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ) + return( ret ); #if defined(MBEDTLS_RSA_C) - if (pk_alg == MBEDTLS_PK_RSA) { - ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*pk), *p, (size_t) (end - *p)); - if (ret == 0) { - /* On success all the input has been consumed by the parsing function. */ - *p += end - *p; - } else if ((ret <= MBEDTLS_ERR_ASN1_OUT_OF_DATA) && - (ret >= MBEDTLS_ERR_ASN1_BUF_TOO_SMALL)) { - /* In case of ASN1 error codes add MBEDTLS_ERR_PK_INVALID_PUBKEY. */ - ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, ret); - } else { - ret = MBEDTLS_ERR_PK_INVALID_PUBKEY; - } + if( pk_alg == MBEDTLS_PK_RSA ) + { + ret = pk_get_rsapubkey( p, end, mbedtls_pk_rsa( *pk ) ); } else #endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - if (pk_alg == MBEDTLS_PK_ECKEY_DH || pk_alg == MBEDTLS_PK_ECKEY) { -#if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES) - if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) { - ret = pk_use_ecparams_rfc8410(&alg_params, ec_grp_id, pk); - } else -#endif - { - ret = pk_use_ecparams(&alg_params, pk); - } - if (ret == 0) { - ret = mbedtls_pk_ecc_set_pubkey(pk, *p, (size_t) (end - *p)); - *p += end - *p; - } +#if defined(MBEDTLS_ECP_C) + if( pk_alg == MBEDTLS_PK_ECKEY_DH || pk_alg == MBEDTLS_PK_ECKEY ) + { + ret = pk_use_ecparams( &alg_params, &mbedtls_pk_ec( *pk )->grp ); + if( ret == 0 ) + ret = pk_get_ecpubkey( p, end, mbedtls_pk_ec( *pk ) ); } else -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ - ret = MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; +#endif /* MBEDTLS_ECP_C */ + ret = MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; + + if( ret == 0 && *p != end ) + ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); + + if( ret != 0 ) + mbedtls_pk_free( pk ); + + return( ret ); +} + +#if defined(MBEDTLS_RSA_C) +/* + * Wrapper around mbedtls_asn1_get_mpi() that rejects zero. + * + * The value zero is: + * - never a valid value for an RSA parameter + * - interpreted as "omitted, please reconstruct" by mbedtls_rsa_complete(). + * + * Since values can't be omitted in PKCS#1, passing a zero value to + * rsa_complete() would be incorrect, so reject zero values early. + */ +static int asn1_get_nonzero_mpi( unsigned char **p, + const unsigned char *end, + mbedtls_mpi *X ) +{ + int ret; + + ret = mbedtls_asn1_get_mpi( p, end, X ); + if( ret != 0 ) + return( ret ); + + if( mbedtls_mpi_cmp_int( X, 0 ) == 0 ) + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + + return( 0 ); +} + +/* + * Parse a PKCS#1 encoded private RSA key + */ +static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa, + const unsigned char *key, + size_t keylen ) +{ + int ret, version; + size_t len; + unsigned char *p, *end; + + mbedtls_mpi T; + mbedtls_mpi_init( &T ); - if (ret == 0 && *p != end) { - ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_INVALID_PUBKEY, - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); + p = (unsigned char *) key; + end = p + keylen; + + /* + * This function parses the RSAPrivateKey (PKCS#1) + * + * RSAPrivateKey ::= SEQUENCE { + * version Version, + * modulus INTEGER, -- n + * publicExponent INTEGER, -- e + * privateExponent INTEGER, -- d + * prime1 INTEGER, -- p + * prime2 INTEGER, -- q + * exponent1 INTEGER, -- d mod (p-1) + * exponent2 INTEGER, -- d mod (q-1) + * coefficient INTEGER, -- (inverse of q) mod p + * otherPrimeInfos OtherPrimeInfos OPTIONAL + * } + */ + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } - if (ret != 0) { - mbedtls_pk_free(pk); + end = p + len; + + if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + } + + if( version != 0 ) + { + return( MBEDTLS_ERR_PK_KEY_INVALID_VERSION ); } - return ret; + /* Import N */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_rsa_import( rsa, &T, NULL, NULL, + NULL, NULL ) ) != 0 ) + goto cleanup; + + /* Import E */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_rsa_import( rsa, NULL, NULL, NULL, + NULL, &T ) ) != 0 ) + goto cleanup; + + /* Import D */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_rsa_import( rsa, NULL, NULL, NULL, + &T, NULL ) ) != 0 ) + goto cleanup; + + /* Import P */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_rsa_import( rsa, NULL, &T, NULL, + NULL, NULL ) ) != 0 ) + goto cleanup; + + /* Import Q */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_rsa_import( rsa, NULL, NULL, &T, + NULL, NULL ) ) != 0 ) + goto cleanup; + +#if !defined(MBEDTLS_RSA_NO_CRT) && !defined(MBEDTLS_RSA_ALT) + /* + * The RSA CRT parameters DP, DQ and QP are nominally redundant, in + * that they can be easily recomputed from D, P and Q. However by + * parsing them from the PKCS1 structure it is possible to avoid + * recalculating them which both reduces the overhead of loading + * RSA private keys into memory and also avoids side channels which + * can arise when computing those values, since all of D, P, and Q + * are secret. See https://eprint.iacr.org/2020/055 for a + * description of one such attack. + */ + + /* Import DP */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_mpi_copy( &rsa->DP, &T ) ) != 0 ) + goto cleanup; + + /* Import DQ */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_mpi_copy( &rsa->DQ, &T ) ) != 0 ) + goto cleanup; + + /* Import QP */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = mbedtls_mpi_copy( &rsa->QP, &T ) ) != 0 ) + goto cleanup; + +#else + /* Verify existance of the CRT params */ + if( ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 || + ( ret = asn1_get_nonzero_mpi( &p, end, &T ) ) != 0 ) + goto cleanup; +#endif + + /* rsa_complete() doesn't complete anything with the default + * implementation but is still called: + * - for the benefit of alternative implementation that may want to + * pre-compute stuff beyond what's provided (eg Montgomery factors) + * - as is also sanity-checks the key + * + * Furthermore, we also check the public part for consistency with + * mbedtls_pk_parse_pubkey(), as it includes size minima for example. + */ + if( ( ret = mbedtls_rsa_complete( rsa ) ) != 0 || + ( ret = mbedtls_rsa_check_pubkey( rsa ) ) != 0 ) + { + goto cleanup; + } + + if( p != end ) + { + ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ); + } + +cleanup: + + mbedtls_mpi_free( &T ); + + if( ret != 0 ) + { + /* Wrap error code if it's coming from a lower level */ + if( ( ret & 0xff80 ) == 0 ) + ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ); + else + ret = MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; + + mbedtls_rsa_free( rsa ); + } + + return( ret ); } +#endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_ECP_C) /* * Parse a SEC1 encoded private EC key */ -static int pk_parse_key_sec1_der(mbedtls_pk_context *pk, - const unsigned char *key, size_t keylen, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int pk_parse_key_sec1_der( mbedtls_ecp_keypair *eck, + const unsigned char *key, size_t keylen, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; int version, pubkey_done; - size_t len, d_len; - mbedtls_asn1_buf params = { 0, 0, NULL }; + size_t len; + mbedtls_asn1_buf params; unsigned char *p = (unsigned char *) key; - unsigned char *d; unsigned char *end = p + keylen; unsigned char *end2; @@ -624,107 +881,108 @@ static int pk_parse_key_sec1_der(mbedtls_pk_context *pk, * publicKey [1] BIT STRING OPTIONAL * } */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } end = p + len; - if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - if (version != 1) { - return MBEDTLS_ERR_PK_KEY_INVALID_VERSION; - } + if( version != 1 ) + return( MBEDTLS_ERR_PK_KEY_INVALID_VERSION ); - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - /* Keep a reference to the position fo the private key. It will be used - * later in this function. */ - d = p; - d_len = len; + if( ( ret = mbedtls_mpi_read_binary( &eck->d, p, len ) ) != 0 ) + { + mbedtls_ecp_keypair_free( eck ); + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); + } p += len; pubkey_done = 0; - if (p != end) { + if( p != end ) + { /* * Is 'parameters' present? */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | - 0)) == 0) { - if ((ret = pk_get_ecparams(&p, p + len, ¶ms)) != 0 || - (ret = pk_use_ecparams(¶ms, pk)) != 0) { - return ret; + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 0 ) ) == 0 ) + { + if( ( ret = pk_get_ecparams( &p, p + len, ¶ms) ) != 0 || + ( ret = pk_use_ecparams( ¶ms, &eck->grp ) ) != 0 ) + { + mbedtls_ecp_keypair_free( eck ); + return( ret ); } - } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + } + else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) + { + mbedtls_ecp_keypair_free( eck ); + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } } - /* - * Load the private key - */ - ret = mbedtls_pk_ecc_set_key(pk, d, d_len); - if (ret != 0) { - return ret; - } - - if (p != end) { + if( p != end ) + { /* * Is 'publickey' present? If not, or if we can't read it (eg because it * is compressed), create it from the private key. */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | - 1)) == 0) { + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONTEXT_SPECIFIC | MBEDTLS_ASN1_CONSTRUCTED | 1 ) ) == 0 ) + { end2 = p + len; - if ((ret = mbedtls_asn1_get_bitstring_null(&p, end2, &len)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_bitstring_null( &p, end2, &len ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - if (p + len != end2) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); - } + if( p + len != end2 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_LENGTH_MISMATCH ) ); - if ((ret = mbedtls_pk_ecc_set_pubkey(pk, p, (size_t) (end2 - p))) == 0) { + if( ( ret = pk_get_ecpubkey( &p, end2, eck ) ) == 0 ) pubkey_done = 1; - } else { + else + { /* - * The only acceptable failure mode of mbedtls_pk_ecc_set_pubkey() above + * The only acceptable failure mode of pk_get_ecpubkey() above * is if the point format is not recognized. */ - if (ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE) { - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; - } + if( ret != MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ) + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); } - } else if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + } + else if( ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) + { + mbedtls_ecp_keypair_free( eck ); + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } } - if (!pubkey_done) { - if ((ret = mbedtls_pk_ecc_set_pubkey_from_prv(pk, d, d_len, f_rng, p_rng)) != 0) { - return ret; - } + if( ! pubkey_done && + ( ret = mbedtls_ecp_mul( &eck->grp, &eck->Q, &eck->d, &eck->grp.G, + f_rng, p_rng ) ) != 0 ) + { + mbedtls_ecp_keypair_free( eck ); + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } - return 0; -} -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ + if( ( ret = mbedtls_ecp_check_privkey( &eck->grp, &eck->d ) ) != 0 ) + { + mbedtls_ecp_keypair_free( eck ); + return( ret ); + } -/*********************************************************************** - * - * PKCS#8 parsing functions - * - **********************************************************************/ + return( 0 ); +} +#endif /* MBEDTLS_ECP_C */ /* * Parse an unencrypted PKCS#8 encoded private key @@ -740,9 +998,9 @@ static int pk_parse_key_sec1_der(mbedtls_pk_context *pk, * */ static int pk_parse_key_pkcs8_unencrypted_der( - mbedtls_pk_context *pk, - const unsigned char *key, size_t keylen, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) + mbedtls_pk_context *pk, + const unsigned char* key, size_t keylen, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { int ret, version; size_t len; @@ -750,10 +1008,9 @@ static int pk_parse_key_pkcs8_unencrypted_der( unsigned char *p = (unsigned char *) key; unsigned char *end = p + keylen; mbedtls_pk_type_t pk_alg = MBEDTLS_PK_NONE; - int ec_grp_id = 0; const mbedtls_pk_info_t *pk_info; -#if !defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if !defined(MBEDTLS_ECP_C) (void) f_rng; (void) p_rng; #endif @@ -774,82 +1031,62 @@ static int pk_parse_key_pkcs8_unencrypted_der( * The PrivateKey OCTET STRING is a SEC1 ECPrivateKey */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } end = p + len; - if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_int( &p, end, &version ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - if (version != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret); - } + if( version != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_VERSION, ret ) ); - if ((ret = pk_get_pk_alg(&p, end, &pk_alg, ¶ms, &ec_grp_id)) != 0) { - return ret; + if( ( ret = pk_get_pk_alg( &p, end, &pk_alg, ¶ms ) ) != 0 ) + { + return( ret ); } - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - if (len < 1) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_OUT_OF_DATA); - } + if( len < 1 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, + MBEDTLS_ERR_ASN1_OUT_OF_DATA ) ); - if ((pk_info = mbedtls_pk_info_from_type(pk_alg)) == NULL) { - return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; - } + if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL ) + return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); - if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0) { - return ret; - } + if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ) + return( ret ); #if defined(MBEDTLS_RSA_C) - if (pk_alg == MBEDTLS_PK_RSA) { - if ((ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), p, len)) != 0) { - mbedtls_pk_free(pk); - return ret; + if( pk_alg == MBEDTLS_PK_RSA ) + { + if( ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), p, len ) ) != 0 ) + { + mbedtls_pk_free( pk ); + return( ret ); } } else #endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - if (pk_alg == MBEDTLS_PK_ECKEY || pk_alg == MBEDTLS_PK_ECKEY_DH) { -#if defined(MBEDTLS_PK_HAVE_RFC8410_CURVES) - if (MBEDTLS_PK_IS_RFC8410_GROUP_ID(ec_grp_id)) { - if ((ret = - pk_use_ecparams_rfc8410(¶ms, ec_grp_id, pk)) != 0 || - (ret = - pk_parse_key_rfc8410_der(pk, p, len, end, f_rng, - p_rng)) != 0) { - mbedtls_pk_free(pk); - return ret; - } - } else -#endif +#if defined(MBEDTLS_ECP_C) + if( pk_alg == MBEDTLS_PK_ECKEY || pk_alg == MBEDTLS_PK_ECKEY_DH ) + { + if( ( ret = pk_use_ecparams( ¶ms, &mbedtls_pk_ec( *pk )->grp ) ) != 0 || + ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), p, len, f_rng, p_rng ) ) != 0 ) { - if ((ret = pk_use_ecparams(¶ms, pk)) != 0 || - (ret = pk_parse_key_sec1_der(pk, p, len, f_rng, p_rng)) != 0) { - mbedtls_pk_free(pk); - return ret; - } + mbedtls_pk_free( pk ); + return( ret ); } } else -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ - return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; +#endif /* MBEDTLS_ECP_C */ + return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); - end = p + len; - if (end != (key + keylen)) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, - MBEDTLS_ERR_ASN1_LENGTH_MISMATCH); - } - - return 0; + return( 0 ); } /* @@ -862,29 +1099,27 @@ static int pk_parse_key_pkcs8_unencrypted_der( * */ #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C) -MBEDTLS_STATIC_TESTABLE int mbedtls_pk_parse_key_pkcs8_encrypted_der( - mbedtls_pk_context *pk, - unsigned char *key, size_t keylen, - const unsigned char *pwd, size_t pwdlen, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int pk_parse_key_pkcs8_encrypted_der( + mbedtls_pk_context *pk, + unsigned char *key, size_t keylen, + const unsigned char *pwd, size_t pwdlen, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { int ret, decrypted = 0; size_t len; unsigned char *buf; unsigned char *p, *end; mbedtls_asn1_buf pbe_alg_oid, pbe_params; -#if defined(MBEDTLS_PKCS12_C) && defined(MBEDTLS_CIPHER_PADDING_PKCS7) && defined(MBEDTLS_CIPHER_C) +#if defined(MBEDTLS_PKCS12_C) mbedtls_cipher_type_t cipher_alg; mbedtls_md_type_t md_alg; #endif - size_t outlen = 0; p = key; end = p + keylen; - if (pwdlen == 0) { - return MBEDTLS_ERR_PK_PASSWORD_REQUIRED; - } + if( pwdlen == 0 ) + return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED ); /* * This function parses the EncryptedPrivateKeyInfo object (PKCS#8) @@ -901,79 +1136,76 @@ MBEDTLS_STATIC_TESTABLE int mbedtls_pk_parse_key_pkcs8_encrypted_der( * The EncryptedData OCTET STRING is a PKCS#8 PrivateKeyInfo * */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, + MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); } end = p + len; - if ((ret = mbedtls_asn1_get_alg(&p, end, &pbe_alg_oid, &pbe_params)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_alg( &p, end, &pbe_alg_oid, &pbe_params ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_OCTET_STRING)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret); - } + if( ( ret = mbedtls_asn1_get_tag( &p, end, &len, MBEDTLS_ASN1_OCTET_STRING ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret ) ); buf = p; /* * Decrypt EncryptedData with appropriate PBE */ -#if defined(MBEDTLS_PKCS12_C) && defined(MBEDTLS_CIPHER_PADDING_PKCS7) && defined(MBEDTLS_CIPHER_C) - if (mbedtls_oid_get_pkcs12_pbe_alg(&pbe_alg_oid, &md_alg, &cipher_alg) == 0) { - if ((ret = mbedtls_pkcs12_pbe_ext(&pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, - cipher_alg, md_alg, - pwd, pwdlen, p, len, buf, len, &outlen)) != 0) { - if (ret == MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH) { - return MBEDTLS_ERR_PK_PASSWORD_MISMATCH; - } +#if defined(MBEDTLS_PKCS12_C) + if( mbedtls_oid_get_pkcs12_pbe_alg( &pbe_alg_oid, &md_alg, &cipher_alg ) == 0 ) + { + if( ( ret = mbedtls_pkcs12_pbe( &pbe_params, MBEDTLS_PKCS12_PBE_DECRYPT, + cipher_alg, md_alg, + pwd, pwdlen, p, len, buf ) ) != 0 ) + { + if( ret == MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH ) + return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); - return ret; + return( ret ); } decrypted = 1; - } else -#endif /* MBEDTLS_PKCS12_C && MBEDTLS_CIPHER_PADDING_PKCS7 && MBEDTLS_CIPHER_C */ -#if defined(MBEDTLS_PKCS5_C) && defined(MBEDTLS_CIPHER_PADDING_PKCS7) && defined(MBEDTLS_CIPHER_C) - if (MBEDTLS_OID_CMP(MBEDTLS_OID_PKCS5_PBES2, &pbe_alg_oid) == 0) { - if ((ret = mbedtls_pkcs5_pbes2_ext(&pbe_params, MBEDTLS_PKCS5_DECRYPT, pwd, pwdlen, - p, len, buf, len, &outlen)) != 0) { - if (ret == MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH) { - return MBEDTLS_ERR_PK_PASSWORD_MISMATCH; - } + } + else +#endif /* MBEDTLS_PKCS12_C */ +#if defined(MBEDTLS_PKCS5_C) + if( MBEDTLS_OID_CMP( MBEDTLS_OID_PKCS5_PBES2, &pbe_alg_oid ) == 0 ) + { + if( ( ret = mbedtls_pkcs5_pbes2( &pbe_params, MBEDTLS_PKCS5_DECRYPT, pwd, pwdlen, + p, len, buf ) ) != 0 ) + { + if( ret == MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH ) + return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); - return ret; + return( ret ); } decrypted = 1; - } else -#endif /* MBEDTLS_PKCS5_C && MBEDTLS_CIPHER_PADDING_PKCS7 && MBEDTLS_CIPHER_C */ + } + else +#endif /* MBEDTLS_PKCS5_C */ { ((void) pwd); } - if (decrypted == 0) { - return MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE; - } - return pk_parse_key_pkcs8_unencrypted_der(pk, buf, outlen, f_rng, p_rng); + if( decrypted == 0 ) + return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE ); + + return( pk_parse_key_pkcs8_unencrypted_der( pk, buf, len, f_rng, p_rng ) ); } #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */ -/*********************************************************************** - * - * Top-level functions, with format auto-discovery - * - **********************************************************************/ - /* * Parse a private key */ -int mbedtls_pk_parse_key(mbedtls_pk_context *pk, - const unsigned char *key, size_t keylen, - const unsigned char *pwd, size_t pwdlen, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +int mbedtls_pk_parse_key( mbedtls_pk_context *pk, + const unsigned char *key, size_t keylen, + const unsigned char *pwd, size_t pwdlen, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; const mbedtls_pk_info_t *pk_info; @@ -982,114 +1214,121 @@ int mbedtls_pk_parse_key(mbedtls_pk_context *pk, mbedtls_pem_context pem; #endif - if (keylen == 0) { - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; - } + PK_VALIDATE_RET( pk != NULL ); + if( keylen == 0 ) + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + PK_VALIDATE_RET( key != NULL ); #if defined(MBEDTLS_PEM_PARSE_C) - mbedtls_pem_init(&pem); + mbedtls_pem_init( &pem ); #if defined(MBEDTLS_RSA_C) /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ - if (key[keylen - 1] != '\0') { + if( key[keylen - 1] != '\0' ) ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } else { - ret = mbedtls_pem_read_buffer(&pem, - PEM_BEGIN_PRIVATE_KEY_RSA, PEM_END_PRIVATE_KEY_RSA, - key, pwd, pwdlen, &len); - } + else + ret = mbedtls_pem_read_buffer( &pem, + "-----BEGIN RSA PRIVATE KEY-----", + "-----END RSA PRIVATE KEY-----", + key, pwd, pwdlen, &len ); - if (ret == 0) { - pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA); - if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 || - (ret = mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), - pem.buf, pem.buflen)) != 0) { - mbedtls_pk_free(pk); + if( ret == 0 ) + { + pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ); + if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 || + ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), + pem.buf, pem.buflen ) ) != 0 ) + { + mbedtls_pk_free( pk ); } - mbedtls_pem_free(&pem); - return ret; - } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) { - return MBEDTLS_ERR_PK_PASSWORD_MISMATCH; - } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) { - return MBEDTLS_ERR_PK_PASSWORD_REQUIRED; - } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { - return ret; + mbedtls_pem_free( &pem ); + return( ret ); } + else if( ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ) + return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); + else if( ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ) + return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED ); + else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) + return( ret ); #endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) +#if defined(MBEDTLS_ECP_C) /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ - if (key[keylen - 1] != '\0') { + if( key[keylen - 1] != '\0' ) ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } else { - ret = mbedtls_pem_read_buffer(&pem, - PEM_BEGIN_PRIVATE_KEY_EC, - PEM_END_PRIVATE_KEY_EC, - key, pwd, pwdlen, &len); - } - if (ret == 0) { - pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY); - - if ((ret = mbedtls_pk_setup(pk, pk_info)) != 0 || - (ret = pk_parse_key_sec1_der(pk, - pem.buf, pem.buflen, - f_rng, p_rng)) != 0) { - mbedtls_pk_free(pk); + else + ret = mbedtls_pem_read_buffer( &pem, + "-----BEGIN EC PRIVATE KEY-----", + "-----END EC PRIVATE KEY-----", + key, pwd, pwdlen, &len ); + if( ret == 0 ) + { + pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ); + + if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 || + ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), + pem.buf, pem.buflen, + f_rng, p_rng ) ) != 0 ) + { + mbedtls_pk_free( pk ); } - mbedtls_pem_free(&pem); - return ret; - } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH) { - return MBEDTLS_ERR_PK_PASSWORD_MISMATCH; - } else if (ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED) { - return MBEDTLS_ERR_PK_PASSWORD_REQUIRED; - } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { - return ret; + mbedtls_pem_free( &pem ); + return( ret ); } -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ + else if( ret == MBEDTLS_ERR_PEM_PASSWORD_MISMATCH ) + return( MBEDTLS_ERR_PK_PASSWORD_MISMATCH ); + else if( ret == MBEDTLS_ERR_PEM_PASSWORD_REQUIRED ) + return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED ); + else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) + return( ret ); +#endif /* MBEDTLS_ECP_C */ /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ - if (key[keylen - 1] != '\0') { + if( key[keylen - 1] != '\0' ) ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } else { - ret = mbedtls_pem_read_buffer(&pem, - PEM_BEGIN_PRIVATE_KEY_PKCS8, PEM_END_PRIVATE_KEY_PKCS8, - key, NULL, 0, &len); - } - if (ret == 0) { - if ((ret = pk_parse_key_pkcs8_unencrypted_der(pk, - pem.buf, pem.buflen, f_rng, p_rng)) != 0) { - mbedtls_pk_free(pk); + else + ret = mbedtls_pem_read_buffer( &pem, + "-----BEGIN PRIVATE KEY-----", + "-----END PRIVATE KEY-----", + key, NULL, 0, &len ); + if( ret == 0 ) + { + if( ( ret = pk_parse_key_pkcs8_unencrypted_der( pk, + pem.buf, pem.buflen, f_rng, p_rng ) ) != 0 ) + { + mbedtls_pk_free( pk ); } - mbedtls_pem_free(&pem); - return ret; - } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { - return ret; + mbedtls_pem_free( &pem ); + return( ret ); } + else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) + return( ret ); #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C) /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ - if (key[keylen - 1] != '\0') { + if( key[keylen - 1] != '\0' ) ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } else { - ret = mbedtls_pem_read_buffer(&pem, - PEM_BEGIN_ENCRYPTED_PRIVATE_KEY_PKCS8, - PEM_END_ENCRYPTED_PRIVATE_KEY_PKCS8, - key, NULL, 0, &len); - } - if (ret == 0) { - if ((ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, pem.buf, pem.buflen, - pwd, pwdlen, f_rng, p_rng)) != 0) { - mbedtls_pk_free(pk); + else + ret = mbedtls_pem_read_buffer( &pem, + "-----BEGIN ENCRYPTED PRIVATE KEY-----", + "-----END ENCRYPTED PRIVATE KEY-----", + key, NULL, 0, &len ); + if( ret == 0 ) + { + if( ( ret = pk_parse_key_pkcs8_encrypted_der( pk, pem.buf, pem.buflen, + pwd, pwdlen, f_rng, p_rng ) ) != 0 ) + { + mbedtls_pk_free( pk ); } - mbedtls_pem_free(&pem); - return ret; - } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { - return ret; + mbedtls_pem_free( &pem ); + return( ret ); } + else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) + return( ret ); #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */ #else ((void) pwd); @@ -1104,81 +1343,84 @@ int mbedtls_pk_parse_key(mbedtls_pk_context *pk, * error */ #if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C) - if (pwdlen != 0) { + { unsigned char *key_copy; - if ((key_copy = mbedtls_calloc(1, keylen)) == NULL) { - return MBEDTLS_ERR_PK_ALLOC_FAILED; - } + if( ( key_copy = mbedtls_calloc( 1, keylen ) ) == NULL ) + return( MBEDTLS_ERR_PK_ALLOC_FAILED ); - memcpy(key_copy, key, keylen); + memcpy( key_copy, key, keylen ); - ret = mbedtls_pk_parse_key_pkcs8_encrypted_der(pk, key_copy, keylen, - pwd, pwdlen, f_rng, p_rng); + ret = pk_parse_key_pkcs8_encrypted_der( pk, key_copy, keylen, + pwd, pwdlen, f_rng, p_rng ); - mbedtls_zeroize_and_free(key_copy, keylen); + mbedtls_platform_zeroize( key_copy, keylen ); + mbedtls_free( key_copy ); } - if (ret == 0) { - return 0; - } + if( ret == 0 ) + return( 0 ); - mbedtls_pk_free(pk); - mbedtls_pk_init(pk); + mbedtls_pk_free( pk ); + mbedtls_pk_init( pk ); - if (ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH) { - return ret; + if( ret == MBEDTLS_ERR_PK_PASSWORD_MISMATCH ) + { + return( ret ); } #endif /* MBEDTLS_PKCS12_C || MBEDTLS_PKCS5_C */ - ret = pk_parse_key_pkcs8_unencrypted_der(pk, key, keylen, f_rng, p_rng); - if (ret == 0) { - return 0; + ret = pk_parse_key_pkcs8_unencrypted_der( pk, key, keylen, f_rng, p_rng ); + if( ret == 0 ) + { + return( 0 ); } - mbedtls_pk_free(pk); - mbedtls_pk_init(pk); + mbedtls_pk_free( pk ); + mbedtls_pk_init( pk ); #if defined(MBEDTLS_RSA_C) - pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA); - if (mbedtls_pk_setup(pk, pk_info) == 0 && - mbedtls_rsa_parse_key(mbedtls_pk_rsa(*pk), key, keylen) == 0) { - return 0; + pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ); + if( mbedtls_pk_setup( pk, pk_info ) == 0 && + pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), key, keylen ) == 0 ) + { + return( 0 ); } - mbedtls_pk_free(pk); - mbedtls_pk_init(pk); + mbedtls_pk_free( pk ); + mbedtls_pk_init( pk ); #endif /* MBEDTLS_RSA_C */ -#if defined(MBEDTLS_PK_HAVE_ECC_KEYS) - pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY); - if (mbedtls_pk_setup(pk, pk_info) == 0 && - pk_parse_key_sec1_der(pk, - key, keylen, f_rng, p_rng) == 0) { - return 0; +#if defined(MBEDTLS_ECP_C) + pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ); + if( mbedtls_pk_setup( pk, pk_info ) == 0 && + pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), + key, keylen, f_rng, p_rng ) == 0 ) + { + return( 0 ); } - mbedtls_pk_free(pk); -#endif /* MBEDTLS_PK_HAVE_ECC_KEYS */ + mbedtls_pk_free( pk ); +#endif /* MBEDTLS_ECP_C */ - /* If MBEDTLS_RSA_C is defined but MBEDTLS_PK_HAVE_ECC_KEYS isn't, + /* If MBEDTLS_RSA_C is defined but MBEDTLS_ECP_C isn't, * it is ok to leave the PK context initialized but not * freed: It is the caller's responsibility to call pk_init() * before calling this function, and to call pk_free() - * when it fails. If MBEDTLS_PK_HAVE_ECC_KEYS is defined but MBEDTLS_RSA_C + * when it fails. If MBEDTLS_ECP_C is defined but MBEDTLS_RSA_C * isn't, this leads to mbedtls_pk_free() being called * twice, once here and once by the caller, but this is * also ok and in line with the mbedtls_pk_free() calls * on failed PEM parsing attempts. */ - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); } /* * Parse a public key */ -int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx, - const unsigned char *key, size_t keylen) +int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, + const unsigned char *key, size_t keylen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *p; @@ -1190,203 +1432,98 @@ int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx, mbedtls_pem_context pem; #endif - if (keylen == 0) { - return MBEDTLS_ERR_PK_KEY_INVALID_FORMAT; - } + PK_VALIDATE_RET( ctx != NULL ); + if( keylen == 0 ) + return( MBEDTLS_ERR_PK_KEY_INVALID_FORMAT ); + PK_VALIDATE_RET( key != NULL || keylen == 0 ); #if defined(MBEDTLS_PEM_PARSE_C) - mbedtls_pem_init(&pem); + mbedtls_pem_init( &pem ); #if defined(MBEDTLS_RSA_C) /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ - if (key[keylen - 1] != '\0') { + if( key[keylen - 1] != '\0' ) ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } else { - ret = mbedtls_pem_read_buffer(&pem, - PEM_BEGIN_PUBLIC_KEY_RSA, PEM_END_PUBLIC_KEY_RSA, - key, NULL, 0, &len); - } + else + ret = mbedtls_pem_read_buffer( &pem, + "-----BEGIN RSA PUBLIC KEY-----", + "-----END RSA PUBLIC KEY-----", + key, NULL, 0, &len ); - if (ret == 0) { + if( ret == 0 ) + { p = pem.buf; - if ((pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == NULL) { - mbedtls_pem_free(&pem); - return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; - } + if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) + return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); - if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) { - mbedtls_pem_free(&pem); - return ret; - } + if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 ) + return( ret ); - if ((ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*ctx), p, pem.buflen)) != 0) { - mbedtls_pk_free(ctx); - } + if ( ( ret = pk_get_rsapubkey( &p, p + pem.buflen, mbedtls_pk_rsa( *ctx ) ) ) != 0 ) + mbedtls_pk_free( ctx ); - mbedtls_pem_free(&pem); - return ret; - } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { - mbedtls_pem_free(&pem); - return ret; + mbedtls_pem_free( &pem ); + return( ret ); + } + else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) + { + mbedtls_pem_free( &pem ); + return( ret ); } #endif /* MBEDTLS_RSA_C */ /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ - if (key[keylen - 1] != '\0') { + if( key[keylen - 1] != '\0' ) ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; - } else { - ret = mbedtls_pem_read_buffer(&pem, - PEM_BEGIN_PUBLIC_KEY, PEM_END_PUBLIC_KEY, - key, NULL, 0, &len); - } + else + ret = mbedtls_pem_read_buffer( &pem, + "-----BEGIN PUBLIC KEY-----", + "-----END PUBLIC KEY-----", + key, NULL, 0, &len ); - if (ret == 0) { + if( ret == 0 ) + { /* * Was PEM encoded */ p = pem.buf; - ret = mbedtls_pk_parse_subpubkey(&p, p + pem.buflen, ctx); - mbedtls_pem_free(&pem); - return ret; - } else if (ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT) { - mbedtls_pem_free(&pem); - return ret; + ret = mbedtls_pk_parse_subpubkey( &p, p + pem.buflen, ctx ); + mbedtls_pem_free( &pem ); + return( ret ); + } + else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT ) + { + mbedtls_pem_free( &pem ); + return( ret ); } - mbedtls_pem_free(&pem); + mbedtls_pem_free( &pem ); #endif /* MBEDTLS_PEM_PARSE_C */ #if defined(MBEDTLS_RSA_C) - if ((pk_info = mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)) == NULL) { - return MBEDTLS_ERR_PK_UNKNOWN_PK_ALG; - } + if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) + return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); - if ((ret = mbedtls_pk_setup(ctx, pk_info)) != 0) { - return ret; - } + if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 ) + return( ret ); - p = (unsigned char *) key; - ret = mbedtls_rsa_parse_pubkey(mbedtls_pk_rsa(*ctx), p, keylen); - if (ret == 0) { - return ret; + p = (unsigned char *)key; + ret = pk_get_rsapubkey( &p, p + keylen, mbedtls_pk_rsa( *ctx ) ); + if( ret == 0 ) + { + return( ret ); } - mbedtls_pk_free(ctx); - if (ret != MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) { - return ret; + mbedtls_pk_free( ctx ); + if( ret != ( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_PK_INVALID_PUBKEY, + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG ) ) ) + { + return( ret ); } #endif /* MBEDTLS_RSA_C */ p = (unsigned char *) key; - ret = mbedtls_pk_parse_subpubkey(&p, p + keylen, ctx); + ret = mbedtls_pk_parse_subpubkey( &p, p + keylen, ctx ); - return ret; + return( ret ); } -/*********************************************************************** - * - * Top-level functions, with filesystem support - * - **********************************************************************/ - -#if defined(MBEDTLS_FS_IO) -/* - * Load all data from a file into a given buffer. - * - * The file is expected to contain either PEM or DER encoded data. - * A terminating null byte is always appended. It is included in the announced - * length only if the data looks like it is PEM encoded. - */ -int mbedtls_pk_load_file(const char *path, unsigned char **buf, size_t *n) -{ - FILE *f; - long size; - - if ((f = fopen(path, "rb")) == NULL) { - return MBEDTLS_ERR_PK_FILE_IO_ERROR; - } - - /* Ensure no stdio buffering of secrets, as such buffers cannot be wiped. */ - mbedtls_setbuf(f, NULL); - - fseek(f, 0, SEEK_END); - if ((size = ftell(f)) == -1) { - fclose(f); - return MBEDTLS_ERR_PK_FILE_IO_ERROR; - } - fseek(f, 0, SEEK_SET); - - *n = (size_t) size; - - if (*n + 1 == 0 || - (*buf = mbedtls_calloc(1, *n + 1)) == NULL) { - fclose(f); - return MBEDTLS_ERR_PK_ALLOC_FAILED; - } - - if (fread(*buf, 1, *n, f) != *n) { - fclose(f); - - mbedtls_zeroize_and_free(*buf, *n); - - return MBEDTLS_ERR_PK_FILE_IO_ERROR; - } - - fclose(f); - - (*buf)[*n] = '\0'; - - if (strstr((const char *) *buf, "-----BEGIN ") != NULL) { - ++*n; - } - - return 0; -} - -/* - * Load and parse a private key - */ -int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx, - const char *path, const char *pwd, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t n; - unsigned char *buf; - - if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) { - return ret; - } - - if (pwd == NULL) { - ret = mbedtls_pk_parse_key(ctx, buf, n, NULL, 0, f_rng, p_rng); - } else { - ret = mbedtls_pk_parse_key(ctx, buf, n, - (const unsigned char *) pwd, strlen(pwd), f_rng, p_rng); - } - - mbedtls_zeroize_and_free(buf, n); - - return ret; -} - -/* - * Load and parse a public key - */ -int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t n; - unsigned char *buf; - - if ((ret = mbedtls_pk_load_file(path, &buf, &n)) != 0) { - return ret; - } - - ret = mbedtls_pk_parse_public_key(ctx, buf, n); - - mbedtls_zeroize_and_free(buf, n); - - return ret; -} -#endif /* MBEDTLS_FS_IO */ - #endif /* MBEDTLS_PK_PARSE_C */ diff --git a/src/duckdb/third_party/mbedtls/library/platform_util.cpp b/src/duckdb/third_party/mbedtls/library/platform_util.cpp index 19ef07aea..6d6f17d29 100644 --- a/src/duckdb/third_party/mbedtls/library/platform_util.cpp +++ b/src/duckdb/third_party/mbedtls/library/platform_util.cpp @@ -3,64 +3,42 @@ * library. * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * Ensure gmtime_r is available even with -std=c99; must be defined before - * mbedtls_config.h, which pulls in glibc's features.h. Harmless on other platforms - * except OpenBSD, where it stops us accessing explicit_bzero. + * mbedtls_config.h, which pulls in glibc's features.h. Harmless on other platforms. */ -#if !defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__) +#if !defined(_POSIX_C_SOURCE) #define _POSIX_C_SOURCE 200112L #endif -#if !defined(_GNU_SOURCE) -/* Clang requires this to get support for explicit_bzero */ -#define _GNU_SOURCE -#endif - #include "common.h" #include "mbedtls/platform_util.h" #include "mbedtls/platform.h" +#ifdef MBEDTLS_THREADING_C #include "mbedtls/threading.h" - -#include - -#ifndef __STDC_WANT_LIB_EXT1__ -#define __STDC_WANT_LIB_EXT1__ 1 /* Ask for the C11 gmtime_s() and memset_s() if available */ #endif +#include #include -#if defined(_WIN32) -#include -#endif - -// Detect platforms known to support explicit_bzero() -#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25) -#define MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO 1 -#elif (defined(__FreeBSD__) && (__FreeBSD_version >= 1100037)) || defined(__OpenBSD__) -#define MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO 1 -#endif - #if !defined(MBEDTLS_PLATFORM_ZEROIZE_ALT) - -#undef HAVE_MEMORY_SANITIZER -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#include -#define HAVE_MEMORY_SANITIZER -#endif -#endif - /* - * Where possible, we try to detect the presence of a platform-provided - * secure memset, such as explicit_bzero(), that is safe against being optimized - * out, and use that. - * - * For other platforms, we provide an implementation that aims not to be - * optimized out by the compiler. + * This implementation should never be optimized out by the compiler * * This implementation for mbedtls_platform_zeroize() was inspired from Colin * Percival's blog article at: @@ -75,88 +53,39 @@ * (refer to http://www.daemonology.net/blog/2014-09-05-erratum.html for * details), optimizations of the following form are still possible: * - * if (memset_func != memset) - * memset_func(buf, 0, len); + * if( memset_func != memset ) + * memset_func( buf, 0, len ); * * Note that it is extremely difficult to guarantee that - * the memset() call will not be optimized out by aggressive compilers + * mbedtls_platform_zeroize() will not be optimized out by aggressive compilers * in a portable way. For this reason, Mbed TLS also provides the configuration * option MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure * mbedtls_platform_zeroize() to use a suitable implementation for their * platform and needs. */ -#if !defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO) && !(defined(__STDC_LIB_EXT1__) && \ - !defined(__IAR_SYSTEMS_ICC__)) \ - && !defined(_WIN32) -static void *(*const volatile memset_func)(void *, int, size_t) = memset; -#endif +static void * (* const volatile memset_func)( void *, int, size_t ) = memset; -void mbedtls_platform_zeroize(void *buf, size_t len) +void mbedtls_platform_zeroize( void *buf, size_t len ) { - if (len > 0) { -#if defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO) - explicit_bzero(buf, len); -#if defined(HAVE_MEMORY_SANITIZER) - /* You'd think that Msan would recognize explicit_bzero() as - * equivalent to bzero(), but it actually doesn't on several - * platforms, including Linux (Ubuntu 20.04). - * https://github.com/google/sanitizers/issues/1507 - * https://github.com/openssh/openssh-portable/commit/74433a19bb6f4cef607680fa4d1d7d81ca3826aa - */ - __msan_unpoison(buf, len); -#endif -#elif defined(__STDC_LIB_EXT1__) && !defined(__IAR_SYSTEMS_ICC__) - memset_s(buf, len, 0, len); -#elif defined(_WIN32) - SecureZeroMemory(buf, len); -#else - memset_func(buf, 0, len); -#endif + MBEDTLS_INTERNAL_VALIDATE( len == 0 || buf != NULL ); -#if defined(__GNUC__) - /* For clang and recent gcc, pretend that we have some assembly that reads the - * zero'd memory as an additional protection against being optimised away. */ -#if defined(__clang__) || (__GNUC__ >= 10) -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wvla" -#elif defined(MBEDTLS_COMPILER_IS_GCC) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wvla" -#endif - asm volatile ("" : : "m" (*(char (*)[len]) buf) :); -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(MBEDTLS_COMPILER_IS_GCC) -#pragma GCC diagnostic pop -#endif -#endif -#endif - } + if( len > 0 ) + memset_func( buf, 0, len ); } #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */ -void mbedtls_zeroize_and_free(void *buf, size_t len) -{ - if (buf != NULL) { - mbedtls_platform_zeroize(buf, len); - } - - mbedtls_free(buf); -} - #if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT) #include #if !defined(_WIN32) && (defined(unix) || \ defined(__unix) || defined(__unix__) || (defined(__APPLE__) && \ - defined(__MACH__)) || defined(__midipix__)) + defined(__MACH__))) #include #endif /* !_WIN32 && (unix || __unix || __unix__ || - * (__APPLE__ && __MACH__) || __midipix__) */ + * (__APPLE__ && __MACH__)) */ -#if !((defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L) || \ - (defined(_POSIX_THREAD_SAFE_FUNCTIONS) && \ - _POSIX_THREAD_SAFE_FUNCTIONS >= 200112L)) +#if !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \ + ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \ + _POSIX_THREAD_SAFE_FUNCTIONS >= 200112L ) ) /* * This is a convenience shorthand macro to avoid checking the long * preprocessor conditions above. Ideally, we could expose this macro in @@ -164,100 +93,47 @@ void mbedtls_zeroize_and_free(void *buf, size_t len) * threading.h. However, this macro is not part of the Mbed TLS public API, so * we keep it private by only defining it in this file */ -#if !(defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)) || \ - (defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)) +#if ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) #define PLATFORM_UTIL_USE_GMTIME -#endif +#endif /* ! ( defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) ) */ -#endif /* !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \ - ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \ +#endif /* !( ( defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L ) || \ + ( defined(_POSIX_THREAD_SAFE_FUNCTIONS ) && \ _POSIX_THREAD_SAFE_FUNCTIONS >= 200112L ) ) */ -struct tm *mbedtls_platform_gmtime_r(const mbedtls_time_t *tt, - struct tm *tm_buf) +struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt, + struct tm *tm_buf ) { -#if defined(_WIN32) && !defined(PLATFORM_UTIL_USE_GMTIME) -#if defined(__STDC_LIB_EXT1__) - return (gmtime_s(tt, tm_buf) == 0) ? NULL : tm_buf; -#else - /* MSVC and mingw64 argument order and return value are inconsistent with the C11 standard */ - return (gmtime_s(tm_buf, tt) == 0) ? tm_buf : NULL; -#endif +#if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32) + return( ( gmtime_s( tm_buf, tt ) == 0 ) ? tm_buf : NULL ); #elif !defined(PLATFORM_UTIL_USE_GMTIME) - return gmtime_r(tt, tm_buf); + return( gmtime_r( tt, tm_buf ) ); #else struct tm *lt; #if defined(MBEDTLS_THREADING_C) - if (mbedtls_mutex_lock(&mbedtls_threading_gmtime_mutex) != 0) { - return NULL; - } + if( mbedtls_mutex_lock( &mbedtls_threading_gmtime_mutex ) != 0 ) + return( NULL ); #endif /* MBEDTLS_THREADING_C */ - lt = gmtime(tt); + lt = gmtime( tt ); - if (lt != NULL) { - memcpy(tm_buf, lt, sizeof(struct tm)); + if( lt != NULL ) + { + memcpy( tm_buf, lt, sizeof( struct tm ) ); } #if defined(MBEDTLS_THREADING_C) - if (mbedtls_mutex_unlock(&mbedtls_threading_gmtime_mutex) != 0) { - return NULL; - } + if( mbedtls_mutex_unlock( &mbedtls_threading_gmtime_mutex ) != 0 ) + return( NULL ); #endif /* MBEDTLS_THREADING_C */ - return (lt == NULL) ? NULL : tm_buf; + return( ( lt == NULL ) ? NULL : tm_buf ); #endif /* _WIN32 && !EFIX64 && !EFI32 */ } #endif /* MBEDTLS_HAVE_TIME_DATE && MBEDTLS_PLATFORM_GMTIME_R_ALT */ #if defined(MBEDTLS_TEST_HOOKS) -void (*mbedtls_test_hook_test_fail)(const char *, int, const char *); +void (*mbedtls_test_hook_test_fail)( const char *, int, const char *); #endif /* MBEDTLS_TEST_HOOKS */ -#if defined(MBEDTLS_HAVE_TIME) && !defined(MBEDTLS_PLATFORM_MS_TIME_ALT) - -#include -#if !defined(_WIN32) && \ - (defined(unix) || defined(__unix) || defined(__unix__) || \ - (defined(__APPLE__) && defined(__MACH__)) || defined(__HAIKU__) || defined(__midipix__)) -#include -#endif \ - /* !_WIN32 && (unix || __unix || __unix__ || (__APPLE__ && __MACH__) || __HAIKU__ || __midipix__) */ -#if (defined(_POSIX_VERSION) && _POSIX_VERSION >= 199309L) || defined(__HAIKU__) -mbedtls_ms_time_t mbedtls_ms_time(void) -{ - int ret; - struct timespec tv; - mbedtls_ms_time_t current_ms; - -#if defined(__linux__) && defined(CLOCK_BOOTTIME) || defined(__midipix__) - ret = clock_gettime(CLOCK_BOOTTIME, &tv); -#else - ret = clock_gettime(CLOCK_MONOTONIC, &tv); -#endif - if (ret) { - return time(NULL) * 1000; - } - - current_ms = tv.tv_sec; - - return current_ms*1000 + tv.tv_nsec / 1000000; -} -#elif defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || \ - defined(__MINGW32__) || defined(_WIN64) -#include -mbedtls_ms_time_t mbedtls_ms_time(void) -{ - FILETIME ct; - mbedtls_ms_time_t current_ms; - - GetSystemTimeAsFileTime(&ct); - current_ms = ((mbedtls_ms_time_t) ct.dwLowDateTime + - ((mbedtls_ms_time_t) (ct.dwHighDateTime) << 32LL))/10000; - return current_ms; -} -#else -#error "No mbedtls_ms_time available" -#endif -#endif /* MBEDTLS_HAVE_TIME && !MBEDTLS_PLATFORM_MS_TIME_ALT */ diff --git a/src/duckdb/third_party/mbedtls/library/rsa.cpp b/src/duckdb/third_party/mbedtls/library/rsa.cpp index 07aeb69cd..2f94c216b 100644 --- a/src/duckdb/third_party/mbedtls/library/rsa.cpp +++ b/src/duckdb/third_party/mbedtls/library/rsa.cpp @@ -2,7 +2,19 @@ * The RSA public-key cryptosystem * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* @@ -28,606 +40,97 @@ #if defined(MBEDTLS_RSA_C) #include "mbedtls/rsa.h" -#include "bignum_core.h" -#include "bignum_internal.h" #include "rsa_alt_helpers.h" -#include "rsa_internal.h" #include "mbedtls/oid.h" -#include "mbedtls/asn1write.h" #include "mbedtls/platform_util.h" #include "mbedtls/error.h" #include "constant_time_internal.h" #include "mbedtls/constant_time.h" -#include "md_psa.h" #include +#if defined(MBEDTLS_PKCS1_V21) +#include "mbedtls/md.h" +#endif + #if defined(MBEDTLS_PKCS1_V15) && !defined(__OpenBSD__) && !defined(__NetBSD__) #include #endif +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" - -/* - * Wrapper around mbedtls_asn1_get_mpi() that rejects zero. - * - * The value zero is: - * - never a valid value for an RSA parameter - * - interpreted as "omitted, please reconstruct" by mbedtls_rsa_complete(). - * - * Since values can't be omitted in PKCS#1, passing a zero value to - * rsa_complete() would be incorrect, so reject zero values early. - */ -static int asn1_get_nonzero_mpi(unsigned char **p, - const unsigned char *end, - mbedtls_mpi *X) -{ - int ret; - - ret = mbedtls_asn1_get_mpi(p, end, X); - if (ret != 0) { - return ret; - } - - if (mbedtls_mpi_cmp_int(X, 0) == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - return 0; -} - -int mbedtls_rsa_parse_key(mbedtls_rsa_context *rsa, const unsigned char *key, size_t keylen) -{ - int ret, version; - size_t len; - unsigned char *p, *end; - - mbedtls_mpi T; - mbedtls_mpi_init(&T); - - p = (unsigned char *) key; - end = p + keylen; - - /* - * This function parses the RSAPrivateKey (PKCS#1) - * - * RSAPrivateKey ::= SEQUENCE { - * version Version, - * modulus INTEGER, -- n - * publicExponent INTEGER, -- e - * privateExponent INTEGER, -- d - * prime1 INTEGER, -- p - * prime2 INTEGER, -- q - * exponent1 INTEGER, -- d mod (p-1) - * exponent2 INTEGER, -- d mod (q-1) - * coefficient INTEGER, -- (inverse of q) mod p - * otherPrimeInfos OtherPrimeInfos OPTIONAL - * } - */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return ret; - } - - if (end != p + len) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - if ((ret = mbedtls_asn1_get_int(&p, end, &version)) != 0) { - return ret; - } - - if (version != 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - /* Import N */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_rsa_import(rsa, &T, NULL, NULL, - NULL, NULL)) != 0) { - goto cleanup; - } - - /* Import E */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, - NULL, &T)) != 0) { - goto cleanup; - } - - /* Import D */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_rsa_import(rsa, NULL, NULL, NULL, - &T, NULL)) != 0) { - goto cleanup; - } - - /* Import P */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_rsa_import(rsa, NULL, &T, NULL, - NULL, NULL)) != 0) { - goto cleanup; - } - - /* Import Q */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_rsa_import(rsa, NULL, NULL, &T, - NULL, NULL)) != 0) { - goto cleanup; - } - -#if !defined(MBEDTLS_RSA_NO_CRT) && !defined(MBEDTLS_RSA_ALT) - /* - * The RSA CRT parameters DP, DQ and QP are nominally redundant, in - * that they can be easily recomputed from D, P and Q. However by - * parsing them from the PKCS1 structure it is possible to avoid - * recalculating them which both reduces the overhead of loading - * RSA private keys into memory and also avoids side channels which - * can arise when computing those values, since all of D, P, and Q - * are secret. See https://eprint.iacr.org/2020/055 for a - * description of one such attack. - */ - - /* Import DP */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_mpi_copy(&rsa->DP, &T)) != 0) { - goto cleanup; - } - - /* Import DQ */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_mpi_copy(&rsa->DQ, &T)) != 0) { - goto cleanup; - } - - /* Import QP */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = mbedtls_mpi_copy(&rsa->QP, &T)) != 0) { - goto cleanup; - } - #else - /* Verify existence of the CRT params */ - if ((ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0 || - (ret = asn1_get_nonzero_mpi(&p, end, &T)) != 0) { - goto cleanup; - } +#include +#define mbedtls_printf printf +#define mbedtls_calloc calloc +#define mbedtls_free free #endif - /* rsa_complete() doesn't complete anything with the default - * implementation but is still called: - * - for the benefit of alternative implementation that may want to - * pre-compute stuff beyond what's provided (eg Montgomery factors) - * - as is also sanity-checks the key - * - * Furthermore, we also check the public part for consistency with - * mbedtls_pk_parse_pubkey(), as it includes size minima for example. - */ - if ((ret = mbedtls_rsa_complete(rsa)) != 0 || - (ret = mbedtls_rsa_check_pubkey(rsa)) != 0) { - goto cleanup; - } - - if (p != end) { - ret = MBEDTLS_ERR_ASN1_LENGTH_MISMATCH; - } - -cleanup: - - mbedtls_mpi_free(&T); - - if (ret != 0) { - mbedtls_rsa_free(rsa); - } - - return ret; -} - -int mbedtls_rsa_parse_pubkey(mbedtls_rsa_context *rsa, const unsigned char *key, size_t keylen) -{ - unsigned char *p = (unsigned char *) key; - unsigned char *end = (unsigned char *) (key + keylen); - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t len; - - /* - * RSAPublicKey ::= SEQUENCE { - * modulus INTEGER, -- n - * publicExponent INTEGER -- e - * } - */ - - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, - MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) { - return ret; - } - - if (end != p + len) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - /* Import N */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) { - return ret; - } - - if ((ret = mbedtls_rsa_import_raw(rsa, p, len, NULL, 0, NULL, 0, - NULL, 0, NULL, 0)) != 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - p += len; - - /* Import E */ - if ((ret = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_INTEGER)) != 0) { - return ret; - } - - if ((ret = mbedtls_rsa_import_raw(rsa, NULL, 0, NULL, 0, NULL, 0, - NULL, 0, p, len)) != 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - p += len; - - if (mbedtls_rsa_complete(rsa) != 0 || - mbedtls_rsa_check_pubkey(rsa) != 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - if (p != end) { - return MBEDTLS_ERR_ASN1_LENGTH_MISMATCH; - } - - return 0; -} - -int mbedtls_rsa_write_key(const mbedtls_rsa_context *rsa, unsigned char *start, - unsigned char **p) -{ - size_t len = 0; - int ret; - - mbedtls_mpi T; /* Temporary holding the exported parameters */ - - /* - * Export the parameters one after another to avoid simultaneous copies. - */ - - mbedtls_mpi_init(&T); - - /* Export QP */ - if ((ret = mbedtls_rsa_export_crt(rsa, NULL, NULL, &T)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export DQ */ - if ((ret = mbedtls_rsa_export_crt(rsa, NULL, &T, NULL)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export DP */ - if ((ret = mbedtls_rsa_export_crt(rsa, &T, NULL, NULL)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export Q */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, &T, NULL, NULL)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export P */ - if ((ret = mbedtls_rsa_export(rsa, NULL, &T, NULL, NULL, NULL)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export D */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, &T, NULL)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export E */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export N */ - if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - -end_of_export: - - mbedtls_mpi_free(&T); - if (ret < 0) { - return ret; - } - - MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_int(p, start, 0)); - MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); - MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, - MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE)); - - return (int) len; -} - -/* - * RSAPublicKey ::= SEQUENCE { - * modulus INTEGER, -- n - * publicExponent INTEGER -- e - * } - */ -int mbedtls_rsa_write_pubkey(const mbedtls_rsa_context *rsa, unsigned char *start, - unsigned char **p) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t len = 0; - mbedtls_mpi T; - - mbedtls_mpi_init(&T); - - /* Export E */ - if ((ret = mbedtls_rsa_export(rsa, NULL, NULL, NULL, NULL, &T)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - - /* Export N */ - if ((ret = mbedtls_rsa_export(rsa, &T, NULL, NULL, NULL, NULL)) != 0 || - (ret = mbedtls_asn1_write_mpi(p, start, &T)) < 0) { - goto end_of_export; - } - len += ret; - -end_of_export: - - mbedtls_mpi_free(&T); - if (ret < 0) { - return ret; - } - - MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); - MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_CONSTRUCTED | - MBEDTLS_ASN1_SEQUENCE)); - - return (int) len; -} - -#if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) - -/** This function performs the unpadding part of a PKCS#1 v1.5 decryption - * operation (EME-PKCS1-v1_5 decoding). - * - * \note The return value from this function is a sensitive value - * (this is unusual). #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE shouldn't happen - * in a well-written application, but 0 vs #MBEDTLS_ERR_RSA_INVALID_PADDING - * is often a situation that an attacker can provoke and leaking which - * one is the result is precisely the information the attacker wants. - * - * \param input The input buffer which is the payload inside PKCS#1v1.5 - * encryption padding, called the "encoded message EM" - * by the terminology. - * \param ilen The length of the payload in the \p input buffer. - * \param output The buffer for the payload, called "message M" by the - * PKCS#1 terminology. This must be a writable buffer of - * length \p output_max_len bytes. - * \param olen The address at which to store the length of - * the payload. This must not be \c NULL. - * \param output_max_len The length in bytes of the output buffer \p output. - * - * \return \c 0 on success. - * \return #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE - * The output buffer is too small for the unpadded payload. - * \return #MBEDTLS_ERR_RSA_INVALID_PADDING - * The input doesn't contain properly formatted padding. - */ -static int mbedtls_ct_rsaes_pkcs1_v15_unpadding(unsigned char *input, - size_t ilen, - unsigned char *output, - size_t output_max_len, - size_t *olen) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - size_t i, plaintext_max_size; - - /* The following variables take sensitive values: their value must - * not leak into the observable behavior of the function other than - * the designated outputs (output, olen, return value). Otherwise - * this would open the execution of the function to - * side-channel-based variants of the Bleichenbacher padding oracle - * attack. Potential side channels include overall timing, memory - * access patterns (especially visible to an adversary who has access - * to a shared memory cache), and branches (especially visible to - * an adversary who has access to a shared code cache or to a shared - * branch predictor). */ - size_t pad_count = 0; - mbedtls_ct_condition_t bad; - mbedtls_ct_condition_t pad_done; - size_t plaintext_size = 0; - mbedtls_ct_condition_t output_too_large; - - plaintext_max_size = (output_max_len > ilen - 11) ? ilen - 11 - : output_max_len; - - /* Check and get padding length in constant time and constant - * memory trace. The first byte must be 0. */ - bad = mbedtls_ct_bool(input[0]); - - - /* Decode EME-PKCS1-v1_5 padding: 0x00 || 0x02 || PS || 0x00 - * where PS must be at least 8 nonzero bytes. */ - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_ne(input[1], MBEDTLS_RSA_CRYPT)); - - /* Read the whole buffer. Set pad_done to nonzero if we find - * the 0x00 byte and remember the padding length in pad_count. */ - pad_done = MBEDTLS_CT_FALSE; - for (i = 2; i < ilen; i++) { - mbedtls_ct_condition_t found = mbedtls_ct_uint_eq(input[i], 0); - pad_done = mbedtls_ct_bool_or(pad_done, found); - pad_count += mbedtls_ct_uint_if_else_0(mbedtls_ct_bool_not(pad_done), 1); - } - - /* If pad_done is still zero, there's no data, only unfinished padding. */ - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_bool_not(pad_done)); - - /* There must be at least 8 bytes of padding. */ - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_gt(8, pad_count)); - - /* If the padding is valid, set plaintext_size to the number of - * remaining bytes after stripping the padding. If the padding - * is invalid, avoid leaking this fact through the size of the - * output: use the maximum message size that fits in the output - * buffer. Do it without branches to avoid leaking the padding - * validity through timing. RSA keys are small enough that all the - * size_t values involved fit in unsigned int. */ - plaintext_size = mbedtls_ct_uint_if( - bad, (unsigned) plaintext_max_size, - (unsigned) (ilen - pad_count - 3)); - - /* Set output_too_large to 0 if the plaintext fits in the output - * buffer and to 1 otherwise. */ - output_too_large = mbedtls_ct_uint_gt(plaintext_size, - plaintext_max_size); - - /* Set ret without branches to avoid timing attacks. Return: - * - INVALID_PADDING if the padding is bad (bad != 0). - * - OUTPUT_TOO_LARGE if the padding is good but the decrypted - * plaintext does not fit in the output buffer. - * - 0 if the padding is correct. */ - ret = mbedtls_ct_error_if( - bad, - MBEDTLS_ERR_RSA_INVALID_PADDING, - mbedtls_ct_error_if_else_0(output_too_large, MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE) - ); - - /* If the padding is bad or the plaintext is too large, zero the - * data that we're about to copy to the output buffer. - * We need to copy the same amount of data - * from the same buffer whether the padding is good or not to - * avoid leaking the padding validity through overall timing or - * through memory or cache access patterns. */ - mbedtls_ct_zeroize_if(mbedtls_ct_bool_or(bad, output_too_large), input + 11, ilen - 11); - - /* If the plaintext is too large, truncate it to the buffer size. - * Copy anyway to avoid revealing the length through timing, because - * revealing the length is as bad as revealing the padding validity - * for a Bleichenbacher attack. */ - plaintext_size = mbedtls_ct_uint_if(output_too_large, - (unsigned) plaintext_max_size, - (unsigned) plaintext_size); - - /* Move the plaintext to the leftmost position where it can start in - * the working buffer, i.e. make it start plaintext_max_size from - * the end of the buffer. Do this with a memory access trace that - * does not depend on the plaintext size. After this move, the - * starting location of the plaintext is no longer sensitive - * information. */ - mbedtls_ct_memmove_left(input + ilen - plaintext_max_size, - plaintext_max_size, - plaintext_max_size - plaintext_size); - - /* Finally copy the decrypted plaintext plus trailing zeros into the output - * buffer. If output_max_len is 0, then output may be an invalid pointer - * and the result of memcpy() would be undefined; prevent undefined - * behavior making sure to depend only on output_max_len (the size of the - * user-provided output buffer), which is independent from plaintext - * length, validity of padding, success of the decryption, and other - * secrets. */ - if (output_max_len != 0) { - memcpy(output, input + ilen - plaintext_max_size, plaintext_max_size); - } - - /* Report the amount of data we copied to the output buffer. In case - * of errors (bad padding or output too large), the value of *olen - * when this function returns is not specified. Making it equivalent - * to the good case limits the risks of leaking the padding validity. */ - *olen = plaintext_size; - - return ret; -} - -#endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */ - #if !defined(MBEDTLS_RSA_ALT) -int mbedtls_rsa_import(mbedtls_rsa_context *ctx, - const mbedtls_mpi *N, - const mbedtls_mpi *P, const mbedtls_mpi *Q, - const mbedtls_mpi *D, const mbedtls_mpi *E) +/* Parameter validation macros */ +#define RSA_VALIDATE_RET( cond ) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_RSA_BAD_INPUT_DATA ) +#define RSA_VALIDATE( cond ) \ + MBEDTLS_INTERNAL_VALIDATE( cond ) + +int mbedtls_rsa_import( mbedtls_rsa_context *ctx, + const mbedtls_mpi *N, + const mbedtls_mpi *P, const mbedtls_mpi *Q, + const mbedtls_mpi *D, const mbedtls_mpi *E ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + RSA_VALIDATE_RET( ctx != NULL ); - if ((N != NULL && (ret = mbedtls_mpi_copy(&ctx->N, N)) != 0) || - (P != NULL && (ret = mbedtls_mpi_copy(&ctx->P, P)) != 0) || - (Q != NULL && (ret = mbedtls_mpi_copy(&ctx->Q, Q)) != 0) || - (D != NULL && (ret = mbedtls_mpi_copy(&ctx->D, D)) != 0) || - (E != NULL && (ret = mbedtls_mpi_copy(&ctx->E, E)) != 0)) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); + if( ( N != NULL && ( ret = mbedtls_mpi_copy( &ctx->N, N ) ) != 0 ) || + ( P != NULL && ( ret = mbedtls_mpi_copy( &ctx->P, P ) ) != 0 ) || + ( Q != NULL && ( ret = mbedtls_mpi_copy( &ctx->Q, Q ) ) != 0 ) || + ( D != NULL && ( ret = mbedtls_mpi_copy( &ctx->D, D ) ) != 0 ) || + ( E != NULL && ( ret = mbedtls_mpi_copy( &ctx->E, E ) ) != 0 ) ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); } - if (N != NULL) { - ctx->len = mbedtls_mpi_size(&ctx->N); - } + if( N != NULL ) + ctx->len = mbedtls_mpi_size( &ctx->N ); - return 0; + return( 0 ); } -int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx, - unsigned char const *N, size_t N_len, - unsigned char const *P, size_t P_len, - unsigned char const *Q, size_t Q_len, - unsigned char const *D, size_t D_len, - unsigned char const *E, size_t E_len) +int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx, + unsigned char const *N, size_t N_len, + unsigned char const *P, size_t P_len, + unsigned char const *Q, size_t Q_len, + unsigned char const *D, size_t D_len, + unsigned char const *E, size_t E_len ) { int ret = 0; + RSA_VALIDATE_RET( ctx != NULL ); - if (N != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->N, N, N_len)); - ctx->len = mbedtls_mpi_size(&ctx->N); + if( N != NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->N, N, N_len ) ); + ctx->len = mbedtls_mpi_size( &ctx->N ); } - if (P != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->P, P, P_len)); - } + if( P != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->P, P, P_len ) ); - if (Q != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->Q, Q, Q_len)); - } + if( Q != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->Q, Q, Q_len ) ); - if (D != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->D, D, D_len)); - } + if( D != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->D, D, D_len ) ); - if (E != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&ctx->E, E, E_len)); - } + if( E != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &ctx->E, E, E_len ) ); cleanup: - if (ret != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); - } + if( ret != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); - return 0; + return( 0 ); } /* @@ -635,8 +138,8 @@ int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx, * that the RSA primitives will be able to execute without error. * It does *not* make guarantees for consistency of the parameters. */ -static int rsa_check_context(mbedtls_rsa_context const *ctx, int is_priv, - int blinding_needed) +static int rsa_check_context( mbedtls_rsa_context const *ctx, int is_priv, + int blinding_needed ) { #if !defined(MBEDTLS_RSA_NO_CRT) /* blinding_needed is only used for NO_CRT to decide whether @@ -644,9 +147,10 @@ static int rsa_check_context(mbedtls_rsa_context const *ctx, int is_priv, ((void) blinding_needed); #endif - if (ctx->len != mbedtls_mpi_size(&ctx->N) || - ctx->len > MBEDTLS_MPI_MAX_SIZE) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( ctx->len != mbedtls_mpi_size( &ctx->N ) || + ctx->len > MBEDTLS_MPI_MAX_SIZE ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } /* @@ -655,21 +159,23 @@ static int rsa_check_context(mbedtls_rsa_context const *ctx, int is_priv, /* Modular exponentiation wrt. N is always used for * RSA public key operations. */ - if (mbedtls_mpi_cmp_int(&ctx->N, 0) <= 0 || - mbedtls_mpi_get_bit(&ctx->N, 0) == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( mbedtls_mpi_cmp_int( &ctx->N, 0 ) <= 0 || + mbedtls_mpi_get_bit( &ctx->N, 0 ) == 0 ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } #if !defined(MBEDTLS_RSA_NO_CRT) /* Modular exponentiation for P and Q is only * used for private key operations and if CRT * is used. */ - if (is_priv && - (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 || - mbedtls_mpi_get_bit(&ctx->P, 0) == 0 || - mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0 || - mbedtls_mpi_get_bit(&ctx->Q, 0) == 0)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( is_priv && + ( mbedtls_mpi_cmp_int( &ctx->P, 0 ) <= 0 || + mbedtls_mpi_get_bit( &ctx->P, 0 ) == 0 || + mbedtls_mpi_cmp_int( &ctx->Q, 0 ) <= 0 || + mbedtls_mpi_get_bit( &ctx->Q, 0 ) == 0 ) ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } #endif /* !MBEDTLS_RSA_NO_CRT */ @@ -678,21 +184,20 @@ static int rsa_check_context(mbedtls_rsa_context const *ctx, int is_priv, */ /* Always need E for public key operations */ - if (mbedtls_mpi_cmp_int(&ctx->E, 0) <= 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( mbedtls_mpi_cmp_int( &ctx->E, 0 ) <= 0 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); #if defined(MBEDTLS_RSA_NO_CRT) /* For private key operations, use D or DP & DQ * as (unblinded) exponents. */ - if (is_priv && mbedtls_mpi_cmp_int(&ctx->D, 0) <= 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( is_priv && mbedtls_mpi_cmp_int( &ctx->D, 0 ) <= 0 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); #else - if (is_priv && - (mbedtls_mpi_cmp_int(&ctx->DP, 0) <= 0 || - mbedtls_mpi_cmp_int(&ctx->DQ, 0) <= 0)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( is_priv && + ( mbedtls_mpi_cmp_int( &ctx->DP, 0 ) <= 0 || + mbedtls_mpi_cmp_int( &ctx->DQ, 0 ) <= 0 ) ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } #endif /* MBEDTLS_RSA_NO_CRT */ @@ -700,26 +205,28 @@ static int rsa_check_context(mbedtls_rsa_context const *ctx, int is_priv, * so check that P, Q >= 1 if that hasn't yet been * done as part of 1. */ #if defined(MBEDTLS_RSA_NO_CRT) - if (is_priv && blinding_needed && - (mbedtls_mpi_cmp_int(&ctx->P, 0) <= 0 || - mbedtls_mpi_cmp_int(&ctx->Q, 0) <= 0)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( is_priv && blinding_needed && + ( mbedtls_mpi_cmp_int( &ctx->P, 0 ) <= 0 || + mbedtls_mpi_cmp_int( &ctx->Q, 0 ) <= 0 ) ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } #endif /* It wouldn't lead to an error if it wasn't satisfied, * but check for QP >= 1 nonetheless. */ #if !defined(MBEDTLS_RSA_NO_CRT) - if (is_priv && - mbedtls_mpi_cmp_int(&ctx->QP, 0) <= 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( is_priv && + mbedtls_mpi_cmp_int( &ctx->QP, 0 ) <= 0 ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } #endif - return 0; + return( 0 ); } -int mbedtls_rsa_complete(mbedtls_rsa_context *ctx) +int mbedtls_rsa_complete( mbedtls_rsa_context *ctx ) { int ret = 0; int have_N, have_P, have_Q, have_D, have_E; @@ -728,16 +235,18 @@ int mbedtls_rsa_complete(mbedtls_rsa_context *ctx) #endif int n_missing, pq_missing, d_missing, is_pub, is_priv; - have_N = (mbedtls_mpi_cmp_int(&ctx->N, 0) != 0); - have_P = (mbedtls_mpi_cmp_int(&ctx->P, 0) != 0); - have_Q = (mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0); - have_D = (mbedtls_mpi_cmp_int(&ctx->D, 0) != 0); - have_E = (mbedtls_mpi_cmp_int(&ctx->E, 0) != 0); + RSA_VALIDATE_RET( ctx != NULL ); + + have_N = ( mbedtls_mpi_cmp_int( &ctx->N, 0 ) != 0 ); + have_P = ( mbedtls_mpi_cmp_int( &ctx->P, 0 ) != 0 ); + have_Q = ( mbedtls_mpi_cmp_int( &ctx->Q, 0 ) != 0 ); + have_D = ( mbedtls_mpi_cmp_int( &ctx->D, 0 ) != 0 ); + have_E = ( mbedtls_mpi_cmp_int( &ctx->E, 0 ) != 0 ); #if !defined(MBEDTLS_RSA_NO_CRT) - have_DP = (mbedtls_mpi_cmp_int(&ctx->DP, 0) != 0); - have_DQ = (mbedtls_mpi_cmp_int(&ctx->DQ, 0) != 0); - have_QP = (mbedtls_mpi_cmp_int(&ctx->QP, 0) != 0); + have_DP = ( mbedtls_mpi_cmp_int( &ctx->DP, 0 ) != 0 ); + have_DQ = ( mbedtls_mpi_cmp_int( &ctx->DQ, 0 ) != 0 ); + have_QP = ( mbedtls_mpi_cmp_int( &ctx->QP, 0 ) != 0 ); #endif /* @@ -758,40 +267,44 @@ int mbedtls_rsa_complete(mbedtls_rsa_context *ctx) /* These three alternatives are mutually exclusive */ is_priv = n_missing || pq_missing || d_missing; - if (!is_priv && !is_pub) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( !is_priv && !is_pub ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); /* * Step 1: Deduce N if P, Q are provided. */ - if (!have_N && have_P && have_Q) { - if ((ret = mbedtls_mpi_mul_mpi(&ctx->N, &ctx->P, - &ctx->Q)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); + if( !have_N && have_P && have_Q ) + { + if( ( ret = mbedtls_mpi_mul_mpi( &ctx->N, &ctx->P, + &ctx->Q ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); } - ctx->len = mbedtls_mpi_size(&ctx->N); + ctx->len = mbedtls_mpi_size( &ctx->N ); } /* * Step 2: Deduce and verify all remaining core parameters. */ - if (pq_missing) { - ret = mbedtls_rsa_deduce_primes(&ctx->N, &ctx->E, &ctx->D, - &ctx->P, &ctx->Q); - if (ret != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); - } - - } else if (d_missing) { - if ((ret = mbedtls_rsa_deduce_private_exponent(&ctx->P, - &ctx->Q, - &ctx->E, - &ctx->D)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); + if( pq_missing ) + { + ret = mbedtls_rsa_deduce_primes( &ctx->N, &ctx->E, &ctx->D, + &ctx->P, &ctx->Q ); + if( ret != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); + + } + else if( d_missing ) + { + if( ( ret = mbedtls_rsa_deduce_private_exponent( &ctx->P, + &ctx->Q, + &ctx->E, + &ctx->D ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); } } @@ -801,12 +314,12 @@ int mbedtls_rsa_complete(mbedtls_rsa_context *ctx) */ #if !defined(MBEDTLS_RSA_NO_CRT) - if (is_priv && !(have_DP && have_DQ && have_QP)) { - ret = mbedtls_rsa_deduce_crt(&ctx->P, &ctx->Q, &ctx->D, - &ctx->DP, &ctx->DQ, &ctx->QP); - if (ret != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); - } + if( is_priv && ! ( have_DP && have_DQ && have_QP ) ) + { + ret = mbedtls_rsa_deduce_crt( &ctx->P, &ctx->Q, &ctx->D, + &ctx->DP, &ctx->DQ, &ctx->QP ); + if( ret != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); } #endif /* MBEDTLS_RSA_NO_CRT */ @@ -814,96 +327,94 @@ int mbedtls_rsa_complete(mbedtls_rsa_context *ctx) * Step 3: Basic sanity checks */ - return rsa_check_context(ctx, is_priv, 1); + return( rsa_check_context( ctx, is_priv, 1 ) ); } -int mbedtls_rsa_export_raw(const mbedtls_rsa_context *ctx, - unsigned char *N, size_t N_len, - unsigned char *P, size_t P_len, - unsigned char *Q, size_t Q_len, - unsigned char *D, size_t D_len, - unsigned char *E, size_t E_len) +int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx, + unsigned char *N, size_t N_len, + unsigned char *P, size_t P_len, + unsigned char *Q, size_t Q_len, + unsigned char *D, size_t D_len, + unsigned char *E, size_t E_len ) { int ret = 0; int is_priv; + RSA_VALIDATE_RET( ctx != NULL ); /* Check if key is private or public */ is_priv = - mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; - - if (!is_priv) { + mbedtls_mpi_cmp_int( &ctx->N, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->P, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->Q, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->D, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->E, 0 ) != 0; + + if( !is_priv ) + { /* If we're trying to export private parameters for a public key, * something must be wrong. */ - if (P != NULL || Q != NULL || D != NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( P != NULL || Q != NULL || D != NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } - if (N != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->N, N, N_len)); - } + if( N != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &ctx->N, N, N_len ) ); - if (P != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->P, P, P_len)); - } + if( P != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &ctx->P, P, P_len ) ); - if (Q != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->Q, Q, Q_len)); - } + if( Q != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &ctx->Q, Q, Q_len ) ); - if (D != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->D, D, D_len)); - } + if( D != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &ctx->D, D, D_len ) ); - if (E != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&ctx->E, E, E_len)); - } + if( E != NULL ) + MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &ctx->E, E, E_len ) ); cleanup: - return ret; + return( ret ); } -int mbedtls_rsa_export(const mbedtls_rsa_context *ctx, - mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q, - mbedtls_mpi *D, mbedtls_mpi *E) +int mbedtls_rsa_export( const mbedtls_rsa_context *ctx, + mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q, + mbedtls_mpi *D, mbedtls_mpi *E ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; int is_priv; + RSA_VALIDATE_RET( ctx != NULL ); /* Check if key is private or public */ is_priv = - mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; - - if (!is_priv) { + mbedtls_mpi_cmp_int( &ctx->N, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->P, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->Q, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->D, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->E, 0 ) != 0; + + if( !is_priv ) + { /* If we're trying to export private parameters for a public key, * something must be wrong. */ - if (P != NULL || Q != NULL || D != NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( P != NULL || Q != NULL || D != NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } /* Export all requested core parameters. */ - if ((N != NULL && (ret = mbedtls_mpi_copy(N, &ctx->N)) != 0) || - (P != NULL && (ret = mbedtls_mpi_copy(P, &ctx->P)) != 0) || - (Q != NULL && (ret = mbedtls_mpi_copy(Q, &ctx->Q)) != 0) || - (D != NULL && (ret = mbedtls_mpi_copy(D, &ctx->D)) != 0) || - (E != NULL && (ret = mbedtls_mpi_copy(E, &ctx->E)) != 0)) { - return ret; + if( ( N != NULL && ( ret = mbedtls_mpi_copy( N, &ctx->N ) ) != 0 ) || + ( P != NULL && ( ret = mbedtls_mpi_copy( P, &ctx->P ) ) != 0 ) || + ( Q != NULL && ( ret = mbedtls_mpi_copy( Q, &ctx->Q ) ) != 0 ) || + ( D != NULL && ( ret = mbedtls_mpi_copy( D, &ctx->D ) ) != 0 ) || + ( E != NULL && ( ret = mbedtls_mpi_copy( E, &ctx->E ) ) != 0 ) ) + { + return( ret ); } - return 0; + return( 0 ); } /* @@ -912,47 +423,51 @@ int mbedtls_rsa_export(const mbedtls_rsa_context *ctx, * write DER encoded RSA keys. The helper function mbedtls_rsa_deduce_crt * can be used in this case. */ -int mbedtls_rsa_export_crt(const mbedtls_rsa_context *ctx, - mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP) +int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx, + mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; int is_priv; + RSA_VALIDATE_RET( ctx != NULL ); /* Check if key is private or public */ is_priv = - mbedtls_mpi_cmp_int(&ctx->N, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->P, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->Q, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->D, 0) != 0 && - mbedtls_mpi_cmp_int(&ctx->E, 0) != 0; + mbedtls_mpi_cmp_int( &ctx->N, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->P, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->Q, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->D, 0 ) != 0 && + mbedtls_mpi_cmp_int( &ctx->E, 0 ) != 0; - if (!is_priv) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( !is_priv ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); #if !defined(MBEDTLS_RSA_NO_CRT) /* Export all requested blinding parameters. */ - if ((DP != NULL && (ret = mbedtls_mpi_copy(DP, &ctx->DP)) != 0) || - (DQ != NULL && (ret = mbedtls_mpi_copy(DQ, &ctx->DQ)) != 0) || - (QP != NULL && (ret = mbedtls_mpi_copy(QP, &ctx->QP)) != 0)) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); + if( ( DP != NULL && ( ret = mbedtls_mpi_copy( DP, &ctx->DP ) ) != 0 ) || + ( DQ != NULL && ( ret = mbedtls_mpi_copy( DQ, &ctx->DQ ) ) != 0 ) || + ( QP != NULL && ( ret = mbedtls_mpi_copy( QP, &ctx->QP ) ) != 0 ) ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); } #else - if ((ret = mbedtls_rsa_deduce_crt(&ctx->P, &ctx->Q, &ctx->D, - DP, DQ, QP)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret); + if( ( ret = mbedtls_rsa_deduce_crt( &ctx->P, &ctx->Q, &ctx->D, + DP, DQ, QP ) ) != 0 ) + { + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_BAD_INPUT_DATA, ret ) ); } #endif - return 0; + return( 0 ); } /* * Initialize an RSA context */ -void mbedtls_rsa_init(mbedtls_rsa_context *ctx) +void mbedtls_rsa_init( mbedtls_rsa_context *ctx ) { - memset(ctx, 0, sizeof(mbedtls_rsa_context)); + RSA_VALIDATE( ctx != NULL ); + + memset( ctx, 0, sizeof( mbedtls_rsa_context ) ); ctx->padding = MBEDTLS_RSA_PKCS_V15; ctx->hash_id = MBEDTLS_MD_NONE; @@ -961,17 +476,18 @@ void mbedtls_rsa_init(mbedtls_rsa_context *ctx) /* Set ctx->ver to nonzero to indicate that the mutex has been * initialized and will need to be freed. */ ctx->ver = 1; - mbedtls_mutex_init(&ctx->mutex); + mbedtls_mutex_init( &ctx->mutex ); #endif } /* * Set padding for an existing RSA context */ -int mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding, - mbedtls_md_type_t hash_id) +int mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, + mbedtls_md_type_t hash_id ) { - switch (padding) { + switch( padding ) + { #if defined(MBEDTLS_PKCS1_V15) case MBEDTLS_RSA_PKCS_V15: break; @@ -982,56 +498,34 @@ int mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding, break; #endif default: - return MBEDTLS_ERR_RSA_INVALID_PADDING; + return( MBEDTLS_ERR_RSA_INVALID_PADDING ); } -#if defined(MBEDTLS_PKCS1_V21) - if ((padding == MBEDTLS_RSA_PKCS_V21) && - (hash_id != MBEDTLS_MD_NONE)) { - /* Just make sure this hash is supported in this build. */ - if (mbedtls_md_info_from_type(hash_id) == NULL) { - return MBEDTLS_ERR_RSA_INVALID_PADDING; - } + if( ( padding == MBEDTLS_RSA_PKCS_V21 ) && + ( hash_id != MBEDTLS_MD_NONE ) ) + { + const mbedtls_md_info_t *md_info; + + md_info = mbedtls_md_info_from_type( hash_id ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_INVALID_PADDING ); } -#endif /* MBEDTLS_PKCS1_V21 */ ctx->padding = padding; ctx->hash_id = hash_id; - return 0; + return( 0 ); } /* - * Get padding mode of initialized RSA context + * Get length in bytes of RSA modulus */ -int mbedtls_rsa_get_padding_mode(const mbedtls_rsa_context *ctx) -{ - return ctx->padding; -} -/* - * Get hash identifier of mbedtls_md_type_t type - */ -int mbedtls_rsa_get_md_alg(const mbedtls_rsa_context *ctx) +size_t mbedtls_rsa_get_len( const mbedtls_rsa_context *ctx ) { - return ctx->hash_id; + return( ctx->len ); } -/* - * Get length in bits of RSA modulus - */ -size_t mbedtls_rsa_get_bitlen(const mbedtls_rsa_context *ctx) -{ - return mbedtls_mpi_bitlen(&ctx->N); -} - -/* - * Get length in bytes of RSA modulus - */ -size_t mbedtls_rsa_get_len(const mbedtls_rsa_context *ctx) -{ - return ctx->len; -} #if defined(MBEDTLS_GENPRIME) @@ -1041,34 +535,31 @@ size_t mbedtls_rsa_get_len(const mbedtls_rsa_context *ctx) * This generation method follows the RSA key pair generation procedure of * FIPS 186-4 if 2^16 < exponent < 2^256 and nbits = 2048 or nbits = 3072. */ -int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - unsigned int nbits, int exponent) +int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + unsigned int nbits, int exponent ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_mpi H, G, L; int prime_quality = 0; + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( f_rng != NULL ); /* * If the modulus is 1024 bit long or shorter, then the security strength of * the RSA algorithm is less than or equal to 80 bits and therefore an error * rate of 2^-80 is sufficient. */ - if (nbits > 1024) { + if( nbits > 1024 ) prime_quality = MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR; - } - mbedtls_mpi_init(&H); - mbedtls_mpi_init(&G); - mbedtls_mpi_init(&L); + mbedtls_mpi_init( &H ); + mbedtls_mpi_init( &G ); + mbedtls_mpi_init( &L ); - if (exponent < 3 || nbits % 2 != 0) { - ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - goto cleanup; - } - - if (nbits < MBEDTLS_RSA_GEN_KEY_MIN_BITS) { + if( nbits < 128 || exponent < 3 || nbits % 2 != 0 ) + { ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA; goto cleanup; } @@ -1079,56 +570,54 @@ int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, * 2. GCD( E, (P-1)*(Q-1) ) == 1 * 3. E^-1 mod LCM(P-1, Q-1) > 2^( nbits / 2 ) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&ctx->E, exponent)); + MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &ctx->E, exponent ) ); - do { - MBEDTLS_MPI_CHK(mbedtls_mpi_gen_prime(&ctx->P, nbits >> 1, - prime_quality, f_rng, p_rng)); + do + { + MBEDTLS_MPI_CHK( mbedtls_mpi_gen_prime( &ctx->P, nbits >> 1, + prime_quality, f_rng, p_rng ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_gen_prime(&ctx->Q, nbits >> 1, - prime_quality, f_rng, p_rng)); + MBEDTLS_MPI_CHK( mbedtls_mpi_gen_prime( &ctx->Q, nbits >> 1, + prime_quality, f_rng, p_rng ) ); /* make sure the difference between p and q is not too small (FIPS 186-4 §B.3.3 step 5.4) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&H, &ctx->P, &ctx->Q)); - if (mbedtls_mpi_bitlen(&H) <= ((nbits >= 200) ? ((nbits >> 1) - 99) : 0)) { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &H, &ctx->P, &ctx->Q ) ); + if( mbedtls_mpi_bitlen( &H ) <= ( ( nbits >= 200 ) ? ( ( nbits >> 1 ) - 99 ) : 0 ) ) continue; - } /* not required by any standards, but some users rely on the fact that P > Q */ - if (H.s < 0) { - mbedtls_mpi_swap(&ctx->P, &ctx->Q); - } + if( H.s < 0 ) + mbedtls_mpi_swap( &ctx->P, &ctx->Q ); /* Temporarily replace P,Q by P-1, Q-1 */ - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&ctx->P, &ctx->P, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&ctx->Q, &ctx->Q, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&H, &ctx->P, &ctx->Q)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &ctx->P, &ctx->P, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &ctx->Q, &ctx->Q, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &H, &ctx->P, &ctx->Q ) ); /* check GCD( E, (P-1)*(Q-1) ) == 1 (FIPS 186-4 §B.3.1 criterion 2(a)) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, &ctx->E, &H)); - if (mbedtls_mpi_cmp_int(&G, 1) != 0) { + MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &G, &ctx->E, &H ) ); + if( mbedtls_mpi_cmp_int( &G, 1 ) != 0 ) continue; - } /* compute smallest possible D = E^-1 mod LCM(P-1, Q-1) (FIPS 186-4 §B.3.1 criterion 3(b)) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(&G, &ctx->P, &ctx->Q)); - MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(&L, NULL, &H, &G)); - MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(&ctx->D, &ctx->E, &L)); + MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( &G, &ctx->P, &ctx->Q ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &L, NULL, &H, &G ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &ctx->D, &ctx->E, &L ) ); - if (mbedtls_mpi_bitlen(&ctx->D) <= ((nbits + 1) / 2)) { // (FIPS 186-4 §B.3.1 criterion 3(a)) + if( mbedtls_mpi_bitlen( &ctx->D ) <= ( ( nbits + 1 ) / 2 ) ) // (FIPS 186-4 §B.3.1 criterion 3(a)) continue; - } break; - } while (1); + } + while( 1 ); /* Restore P,Q */ - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&ctx->P, &ctx->P, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&ctx->Q, &ctx->Q, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( &ctx->P, &ctx->P, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( &ctx->Q, &ctx->Q, 1 ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->N, &ctx->P, &ctx->Q)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->N, &ctx->P, &ctx->Q ) ); - ctx->len = mbedtls_mpi_size(&ctx->N); + ctx->len = mbedtls_mpi_size( &ctx->N ); #if !defined(MBEDTLS_RSA_NO_CRT) /* @@ -1136,29 +625,29 @@ int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, * DQ = D mod (Q - 1) * QP = Q^-1 mod P */ - MBEDTLS_MPI_CHK(mbedtls_rsa_deduce_crt(&ctx->P, &ctx->Q, &ctx->D, - &ctx->DP, &ctx->DQ, &ctx->QP)); + MBEDTLS_MPI_CHK( mbedtls_rsa_deduce_crt( &ctx->P, &ctx->Q, &ctx->D, + &ctx->DP, &ctx->DQ, &ctx->QP ) ); #endif /* MBEDTLS_RSA_NO_CRT */ /* Double-check */ - MBEDTLS_MPI_CHK(mbedtls_rsa_check_privkey(ctx)); + MBEDTLS_MPI_CHK( mbedtls_rsa_check_privkey( ctx ) ); cleanup: - mbedtls_mpi_free(&H); - mbedtls_mpi_free(&G); - mbedtls_mpi_free(&L); + mbedtls_mpi_free( &H ); + mbedtls_mpi_free( &G ); + mbedtls_mpi_free( &L ); - if (ret != 0) { - mbedtls_rsa_free(ctx); + if( ret != 0 ) + { + mbedtls_rsa_free( ctx ); - if ((-ret & ~0x7f) == 0) { - ret = MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_KEY_GEN_FAILED, ret); - } - return ret; + if( ( -ret & ~0x7f ) == 0 ) + ret = MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_KEY_GEN_FAILED, ret ); + return( ret ); } - return 0; + return( 0 ); } #endif /* MBEDTLS_GENPRIME */ @@ -1166,117 +655,130 @@ int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx, /* * Check a public RSA key */ -int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx) +int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx ) { - if (rsa_check_context(ctx, 0 /* public */, 0 /* no blinding */) != 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; - } + RSA_VALIDATE_RET( ctx != NULL ); - if (mbedtls_mpi_bitlen(&ctx->N) < 128) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + if( rsa_check_context( ctx, 0 /* public */, 0 /* no blinding */ ) != 0 ) + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); + + if( mbedtls_mpi_bitlen( &ctx->N ) < 128 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } - if (mbedtls_mpi_get_bit(&ctx->E, 0) == 0 || - mbedtls_mpi_bitlen(&ctx->E) < 2 || - mbedtls_mpi_cmp_mpi(&ctx->E, &ctx->N) >= 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + if( mbedtls_mpi_get_bit( &ctx->E, 0 ) == 0 || + mbedtls_mpi_bitlen( &ctx->E ) < 2 || + mbedtls_mpi_cmp_mpi( &ctx->E, &ctx->N ) >= 0 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } - return 0; + return( 0 ); } /* * Check for the consistency of all fields in an RSA private key context */ -int mbedtls_rsa_check_privkey(const mbedtls_rsa_context *ctx) +int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx ) { - if (mbedtls_rsa_check_pubkey(ctx) != 0 || - rsa_check_context(ctx, 1 /* private */, 1 /* blinding */) != 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + RSA_VALIDATE_RET( ctx != NULL ); + + if( mbedtls_rsa_check_pubkey( ctx ) != 0 || + rsa_check_context( ctx, 1 /* private */, 1 /* blinding */ ) != 0 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } - if (mbedtls_rsa_validate_params(&ctx->N, &ctx->P, &ctx->Q, - &ctx->D, &ctx->E, NULL, NULL) != 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + if( mbedtls_rsa_validate_params( &ctx->N, &ctx->P, &ctx->Q, + &ctx->D, &ctx->E, NULL, NULL ) != 0 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } #if !defined(MBEDTLS_RSA_NO_CRT) - else if (mbedtls_rsa_validate_crt(&ctx->P, &ctx->Q, &ctx->D, - &ctx->DP, &ctx->DQ, &ctx->QP) != 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + else if( mbedtls_rsa_validate_crt( &ctx->P, &ctx->Q, &ctx->D, + &ctx->DP, &ctx->DQ, &ctx->QP ) != 0 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } #endif - return 0; + return( 0 ); } /* * Check if contexts holding a public and private key match */ -int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub, - const mbedtls_rsa_context *prv) +int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub, + const mbedtls_rsa_context *prv ) { - if (mbedtls_rsa_check_pubkey(pub) != 0 || - mbedtls_rsa_check_privkey(prv) != 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + RSA_VALIDATE_RET( pub != NULL ); + RSA_VALIDATE_RET( prv != NULL ); + + if( mbedtls_rsa_check_pubkey( pub ) != 0 || + mbedtls_rsa_check_privkey( prv ) != 0 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } - if (mbedtls_mpi_cmp_mpi(&pub->N, &prv->N) != 0 || - mbedtls_mpi_cmp_mpi(&pub->E, &prv->E) != 0) { - return MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; + if( mbedtls_mpi_cmp_mpi( &pub->N, &prv->N ) != 0 || + mbedtls_mpi_cmp_mpi( &pub->E, &prv->E ) != 0 ) + { + return( MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ); } - return 0; + return( 0 ); } /* * Do an RSA public key operation */ -int mbedtls_rsa_public(mbedtls_rsa_context *ctx, - const unsigned char *input, - unsigned char *output) +int mbedtls_rsa_public( mbedtls_rsa_context *ctx, + const unsigned char *input, + unsigned char *output ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t olen; mbedtls_mpi T; + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( input != NULL ); + RSA_VALIDATE_RET( output != NULL ); - if (rsa_check_context(ctx, 0 /* public */, 0 /* no blinding */)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( rsa_check_context( ctx, 0 /* public */, 0 /* no blinding */ ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - mbedtls_mpi_init(&T); + mbedtls_mpi_init( &T ); #if defined(MBEDTLS_THREADING_C) - if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) { - return ret; - } + if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) + return( ret ); #endif - MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&T, input, ctx->len)); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &T, input, ctx->len ) ); - if (mbedtls_mpi_cmp_mpi(&T, &ctx->N) >= 0) { + if( mbedtls_mpi_cmp_mpi( &T, &ctx->N ) >= 0 ) + { ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA; goto cleanup; } olen = ctx->len; - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod_unsafe(&T, &T, &ctx->E, &ctx->N, &ctx->RN)); - MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&T, output, olen)); + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &T, &T, &ctx->E, &ctx->N, &ctx->RN ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &T, output, olen ) ); cleanup: #if defined(MBEDTLS_THREADING_C) - if (mbedtls_mutex_unlock(&ctx->mutex) != 0) { - return MBEDTLS_ERR_THREADING_MUTEX_ERROR; - } + if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) + return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); #endif - mbedtls_mpi_free(&T); + mbedtls_mpi_free( &T ); - if (ret != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_PUBLIC_FAILED, ret); - } + if( ret != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PUBLIC_FAILED, ret ) ); - return 0; + return( 0 ); } /* @@ -1285,101 +787,63 @@ int mbedtls_rsa_public(mbedtls_rsa_context *ctx, * DSS, and other systems. In : Advances in Cryptology-CRYPTO'96. Springer * Berlin Heidelberg, 1996. p. 104-113. */ -static int rsa_prepare_blinding(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), void *p_rng) +static int rsa_prepare_blinding( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) { int ret, count = 0; mbedtls_mpi R; - mbedtls_mpi_init(&R); + mbedtls_mpi_init( &R ); - if (ctx->Vf.p != NULL) { + if( ctx->Vf.p != NULL ) + { /* We already have blinding values, just update them by squaring */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vi, &ctx->Vi, &ctx->Vi)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vi, &ctx->Vi, &ctx->N)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vf, &ctx->Vf, &ctx->Vf)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vf, &ctx->Vf, &ctx->N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->Vi, &ctx->Vi, &ctx->Vi ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->Vi, &ctx->Vi, &ctx->N ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->Vf, &ctx->Vf, &ctx->Vf ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->Vf, &ctx->Vf, &ctx->N ) ); goto cleanup; } /* Unblinding value: Vf = random number, invertible mod N */ do { - if (count++ > 10) { + if( count++ > 10 ) + { ret = MBEDTLS_ERR_RSA_RNG_FAILED; goto cleanup; } - MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&ctx->Vf, ctx->len - 1, f_rng, p_rng)); + MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &ctx->Vf, ctx->len - 1, f_rng, p_rng ) ); /* Compute Vf^-1 as R * (R Vf)^-1 to avoid leaks from inv_mod. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, ctx->len - 1, f_rng, p_rng)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vi, &ctx->Vf, &R)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vi, &ctx->Vi, &ctx->N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, ctx->len - 1, f_rng, p_rng ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->Vi, &ctx->Vf, &R ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->Vi, &ctx->Vi, &ctx->N ) ); /* At this point, Vi is invertible mod N if and only if both Vf and R * are invertible mod N. If one of them isn't, we don't need to know * which one, we just loop and choose new values for both of them. * (Each iteration succeeds with overwhelming probability.) */ - ret = mbedtls_mpi_inv_mod(&ctx->Vi, &ctx->Vi, &ctx->N); - if (ret != 0 && ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE) { + ret = mbedtls_mpi_inv_mod( &ctx->Vi, &ctx->Vi, &ctx->N ); + if( ret != 0 && ret != MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ) goto cleanup; - } - } while (ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE); + } while( ret == MBEDTLS_ERR_MPI_NOT_ACCEPTABLE ); /* Finish the computation of Vf^-1 = R * (R Vf)^-1 */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&ctx->Vi, &ctx->Vi, &R)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&ctx->Vi, &ctx->Vi, &ctx->N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &ctx->Vi, &ctx->Vi, &R ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &ctx->Vi, &ctx->Vi, &ctx->N ) ); /* Blinding value: Vi = Vf^(-e) mod N * (Vi already contains Vf^-1 at this point) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&ctx->Vi, &ctx->Vi, &ctx->E, &ctx->N, &ctx->RN)); - - -cleanup: - mbedtls_mpi_free(&R); - - return ret; -} + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &ctx->Vi, &ctx->Vi, &ctx->E, &ctx->N, &ctx->RN ) ); -/* - * Unblind - * T = T * Vf mod N - */ -static int rsa_unblind(mbedtls_mpi *T, mbedtls_mpi *Vf, const mbedtls_mpi *N) -{ - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - const mbedtls_mpi_uint mm = mbedtls_mpi_core_montmul_init(N->p); - const size_t nlimbs = N->n; - const size_t tlimbs = mbedtls_mpi_core_montmul_working_limbs(nlimbs); - mbedtls_mpi RR, M_T; - - mbedtls_mpi_init(&RR); - mbedtls_mpi_init(&M_T); - - MBEDTLS_MPI_CHK(mbedtls_mpi_core_get_mont_r2_unsafe(&RR, N)); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(&M_T, tlimbs)); - - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(T, nlimbs)); - MBEDTLS_MPI_CHK(mbedtls_mpi_grow(Vf, nlimbs)); - - /* T = T * Vf mod N - * Reminder: montmul(A, B, N) = A * B * R^-1 mod N - * Usually both operands are multiplied by R mod N beforehand (by calling - * `to_mont_rep()` on them), yielding a result that's also * R mod N (aka - * "in the Montgomery domain"). Here we only multiply one operand by R mod - * N, so the result is directly what we want - no need to call - * `from_mont_rep()` on it. */ - mbedtls_mpi_core_to_mont_rep(T->p, T->p, N->p, nlimbs, mm, RR.p, M_T.p); - mbedtls_mpi_core_montmul(T->p, T->p, Vf->p, nlimbs, N->p, nlimbs, mm, M_T.p); cleanup: + mbedtls_mpi_free( &R ); - mbedtls_mpi_free(&RR); - mbedtls_mpi_free(&M_T); - - return ret; + return( ret ); } /* @@ -1388,10 +852,10 @@ static int rsa_unblind(mbedtls_mpi *T, mbedtls_mpi *Vf, const mbedtls_mpi *N) * the more bits of the key can be recovered. See [3]. * * Collecting n collisions with m bit long blinding value requires 2^(m-m/n) - * observations on average. + * observations on avarage. * * For example with 28 byte blinding to achieve 2 collisions the adversary has - * to make 2^112 observations on average. + * to make 2^112 observations on avarage. * * (With the currently (as of 2017 April) known best algorithms breaking 2048 * bit RSA requires approximately as much time as trying out 2^112 random keys. @@ -1406,11 +870,11 @@ static int rsa_unblind(mbedtls_mpi *T, mbedtls_mpi *Vf, const mbedtls_mpi *N) /* * Do an RSA private key operation */ -int mbedtls_rsa_private(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - const unsigned char *input, - unsigned char *output) +int mbedtls_rsa_private( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + const unsigned char *input, + unsigned char *output ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t olen; @@ -1429,106 +893,125 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx, /* Temporaries holding the blinded exponents for * the mod p resp. mod q computation (if used). */ mbedtls_mpi DP_blind, DQ_blind; + + /* Pointers to actual exponents to be used - either the unblinded + * or the blinded ones, depending on the presence of a PRNG. */ + mbedtls_mpi *DP = &ctx->DP; + mbedtls_mpi *DQ = &ctx->DQ; #else /* Temporary holding the blinded exponent (if used). */ mbedtls_mpi D_blind; + + /* Pointer to actual exponent to be used - either the unblinded + * or the blinded one, depending on the presence of a PRNG. */ + mbedtls_mpi *D = &ctx->D; #endif /* MBEDTLS_RSA_NO_CRT */ /* Temporaries holding the initial input and the double * checked result; should be the same in the end. */ - mbedtls_mpi input_blinded, check_result_blinded; + mbedtls_mpi I, C; - if (f_rng == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( input != NULL ); + RSA_VALIDATE_RET( output != NULL ); + + if( f_rng == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (rsa_check_context(ctx, 1 /* private key checks */, - 1 /* blinding on */) != 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( rsa_check_context( ctx, 1 /* private key checks */, + 1 /* blinding on */ ) != 0 ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } #if defined(MBEDTLS_THREADING_C) - if ((ret = mbedtls_mutex_lock(&ctx->mutex)) != 0) { - return ret; - } + if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) + return( ret ); #endif /* MPI Initialization */ - mbedtls_mpi_init(&T); + mbedtls_mpi_init( &T ); - mbedtls_mpi_init(&P1); - mbedtls_mpi_init(&Q1); - mbedtls_mpi_init(&R); + mbedtls_mpi_init( &P1 ); + mbedtls_mpi_init( &Q1 ); + mbedtls_mpi_init( &R ); #if defined(MBEDTLS_RSA_NO_CRT) - mbedtls_mpi_init(&D_blind); + mbedtls_mpi_init( &D_blind ); #else - mbedtls_mpi_init(&DP_blind); - mbedtls_mpi_init(&DQ_blind); + mbedtls_mpi_init( &DP_blind ); + mbedtls_mpi_init( &DQ_blind ); #endif #if !defined(MBEDTLS_RSA_NO_CRT) - mbedtls_mpi_init(&TP); mbedtls_mpi_init(&TQ); + mbedtls_mpi_init( &TP ); mbedtls_mpi_init( &TQ ); #endif - mbedtls_mpi_init(&input_blinded); - mbedtls_mpi_init(&check_result_blinded); + mbedtls_mpi_init( &I ); + mbedtls_mpi_init( &C ); /* End of MPI initialization */ - MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&T, input, ctx->len)); - if (mbedtls_mpi_cmp_mpi(&T, &ctx->N) >= 0) { + MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &T, input, ctx->len ) ); + if( mbedtls_mpi_cmp_mpi( &T, &ctx->N ) >= 0 ) + { ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA; goto cleanup; } + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &I, &T ) ); + /* * Blinding * T = T * Vi mod N */ - MBEDTLS_MPI_CHK(rsa_prepare_blinding(ctx, f_rng, p_rng)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, &T, &ctx->Vi)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&T, &T, &ctx->N)); - - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&input_blinded, &T)); + MBEDTLS_MPI_CHK( rsa_prepare_blinding( ctx, f_rng, p_rng ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T, &T, &ctx->Vi ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &T, &T, &ctx->N ) ); /* * Exponent blinding */ - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&P1, &ctx->P, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&Q1, &ctx->Q, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &P1, &ctx->P, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &Q1, &ctx->Q, 1 ) ); #if defined(MBEDTLS_RSA_NO_CRT) /* * D_blind = ( P - 1 ) * ( Q - 1 ) * R + D */ - MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, RSA_EXPONENT_BLINDING, - f_rng, p_rng)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &P1, &Q1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&D_blind, &D_blind, &R)); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&D_blind, &D_blind, &ctx->D)); + MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, RSA_EXPONENT_BLINDING, + f_rng, p_rng ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &D_blind, &P1, &Q1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &D_blind, &D_blind, &R ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &D_blind, &D_blind, &ctx->D ) ); + + D = &D_blind; #else /* * DP_blind = ( P - 1 ) * R + DP */ - MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, RSA_EXPONENT_BLINDING, - f_rng, p_rng)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&DP_blind, &P1, &R)); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DP_blind, &DP_blind, - &ctx->DP)); + MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, RSA_EXPONENT_BLINDING, + f_rng, p_rng ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &DP_blind, &P1, &R ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &DP_blind, &DP_blind, + &ctx->DP ) ); + + DP = &DP_blind; /* * DQ_blind = ( Q - 1 ) * R + DQ */ - MBEDTLS_MPI_CHK(mbedtls_mpi_fill_random(&R, RSA_EXPONENT_BLINDING, - f_rng, p_rng)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&DQ_blind, &Q1, &R)); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&DQ_blind, &DQ_blind, - &ctx->DQ)); + MBEDTLS_MPI_CHK( mbedtls_mpi_fill_random( &R, RSA_EXPONENT_BLINDING, + f_rng, p_rng ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &DQ_blind, &Q1, &R ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &DQ_blind, &DQ_blind, + &ctx->DQ ) ); + + DQ = &DQ_blind; #endif /* MBEDTLS_RSA_NO_CRT */ #if defined(MBEDTLS_RSA_NO_CRT) - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&T, &T, &D_blind, &ctx->N, &ctx->RN)); + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &T, &T, D, &ctx->N, &ctx->RN ) ); #else /* * Faster decryption using the CRT @@ -1537,72 +1020,72 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx, * TQ = input ^ dQ mod Q */ - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TP, &T, &DP_blind, &ctx->P, &ctx->RP)); - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&TQ, &T, &DQ_blind, &ctx->Q, &ctx->RQ)); + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &TP, &T, DP, &ctx->P, &ctx->RP ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &TQ, &T, DQ, &ctx->Q, &ctx->RQ ) ); /* * T = (TP - TQ) * (Q^-1 mod P) mod P */ - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&T, &TP, &TQ)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&TP, &T, &ctx->QP)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&T, &TP, &ctx->P)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &T, &TP, &TQ ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &TP, &T, &ctx->QP ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &T, &TP, &ctx->P ) ); /* * T = TQ + T * Q */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&TP, &T, &ctx->Q)); - MBEDTLS_MPI_CHK(mbedtls_mpi_add_mpi(&T, &TQ, &TP)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &TP, &T, &ctx->Q ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_mpi( &T, &TQ, &TP ) ); #endif /* MBEDTLS_RSA_NO_CRT */ - /* Verify the result to prevent glitching attacks. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&check_result_blinded, &T, &ctx->E, - &ctx->N, &ctx->RN)); - if (mbedtls_mpi_cmp_mpi(&check_result_blinded, &input_blinded) != 0) { - ret = MBEDTLS_ERR_RSA_VERIFY_FAILED; - goto cleanup; - } - /* * Unblind * T = T * Vf mod N */ - MBEDTLS_MPI_CHK(rsa_unblind(&T, &ctx->Vf, &ctx->N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T, &T, &ctx->Vf ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &T, &T, &ctx->N ) ); + + /* Verify the result to prevent glitching attacks. */ + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &C, &T, &ctx->E, + &ctx->N, &ctx->RN ) ); + if( mbedtls_mpi_cmp_mpi( &C, &I ) != 0 ) + { + ret = MBEDTLS_ERR_RSA_VERIFY_FAILED; + goto cleanup; + } olen = ctx->len; - MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(&T, output, olen)); + MBEDTLS_MPI_CHK( mbedtls_mpi_write_binary( &T, output, olen ) ); cleanup: #if defined(MBEDTLS_THREADING_C) - if (mbedtls_mutex_unlock(&ctx->mutex) != 0) { - return MBEDTLS_ERR_THREADING_MUTEX_ERROR; - } + if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) + return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); #endif - mbedtls_mpi_free(&P1); - mbedtls_mpi_free(&Q1); - mbedtls_mpi_free(&R); + mbedtls_mpi_free( &P1 ); + mbedtls_mpi_free( &Q1 ); + mbedtls_mpi_free( &R ); #if defined(MBEDTLS_RSA_NO_CRT) - mbedtls_mpi_free(&D_blind); + mbedtls_mpi_free( &D_blind ); #else - mbedtls_mpi_free(&DP_blind); - mbedtls_mpi_free(&DQ_blind); + mbedtls_mpi_free( &DP_blind ); + mbedtls_mpi_free( &DQ_blind ); #endif - mbedtls_mpi_free(&T); + mbedtls_mpi_free( &T ); #if !defined(MBEDTLS_RSA_NO_CRT) - mbedtls_mpi_free(&TP); mbedtls_mpi_free(&TQ); + mbedtls_mpi_free( &TP ); mbedtls_mpi_free( &TQ ); #endif - mbedtls_mpi_free(&check_result_blinded); - mbedtls_mpi_free(&input_blinded); + mbedtls_mpi_free( &C ); + mbedtls_mpi_free( &I ); - if (ret != 0 && ret >= -0x007f) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_PRIVATE_FAILED, ret); - } + if( ret != 0 && ret >= -0x007f ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_PRIVATE_FAILED, ret ) ); - return ret; + return( ret ); } #if defined(MBEDTLS_PKCS1_V21) @@ -1613,61 +1096,43 @@ int mbedtls_rsa_private(mbedtls_rsa_context *ctx, * \param dlen length of destination buffer * \param src source of the mask generation * \param slen length of the source buffer - * \param md_alg message digest to use + * \param md_ctx message digest context to use */ -static int mgf_mask(unsigned char *dst, size_t dlen, unsigned char *src, - size_t slen, mbedtls_md_type_t md_alg) +static int mgf_mask( unsigned char *dst, size_t dlen, unsigned char *src, + size_t slen, mbedtls_md_context_t *md_ctx ) { + unsigned char mask[MBEDTLS_MD_MAX_SIZE]; unsigned char counter[4]; unsigned char *p; unsigned int hlen; size_t i, use_len; - unsigned char mask[MBEDTLS_MD_MAX_SIZE]; int ret = 0; - const mbedtls_md_info_t *md_info; - mbedtls_md_context_t md_ctx; - - mbedtls_md_init(&md_ctx); - md_info = mbedtls_md_info_from_type(md_alg); - if (md_info == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - mbedtls_md_init(&md_ctx); - if ((ret = mbedtls_md_setup(&md_ctx, md_info, 0)) != 0) { - goto exit; - } - hlen = mbedtls_md_get_size(md_info); + memset( mask, 0, MBEDTLS_MD_MAX_SIZE ); + memset( counter, 0, 4 ); - memset(mask, 0, sizeof(mask)); - memset(counter, 0, 4); + hlen = mbedtls_md_get_size( md_ctx->md_info ); /* Generate and apply dbMask */ p = dst; - while (dlen > 0) { + while( dlen > 0 ) + { use_len = hlen; - if (dlen < hlen) { + if( dlen < hlen ) use_len = dlen; - } - if ((ret = mbedtls_md_starts(&md_ctx)) != 0) { + if( ( ret = mbedtls_md_starts( md_ctx ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_update(&md_ctx, src, slen)) != 0) { + if( ( ret = mbedtls_md_update( md_ctx, src, slen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_update(&md_ctx, counter, 4)) != 0) { + if( ( ret = mbedtls_md_update( md_ctx, counter, 4 ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_md_finish(&md_ctx, mask)) != 0) { + if( ( ret = mbedtls_md_finish( md_ctx, mask ) ) != 0 ) goto exit; - } - for (i = 0; i < use_len; ++i) { + for( i = 0; i < use_len; ++i ) *p++ ^= mask[i]; - } counter[3]++; @@ -1675,82 +1140,9 @@ static int mgf_mask(unsigned char *dst, size_t dlen, unsigned char *src, } exit: - mbedtls_platform_zeroize(mask, sizeof(mask)); - mbedtls_md_free(&md_ctx); - - return ret; -} - -/** - * Generate Hash(M') as in RFC 8017 page 43 points 5 and 6. - * - * \param hash the input hash - * \param hlen length of the input hash - * \param salt the input salt - * \param slen length of the input salt - * \param out the output buffer - must be large enough for \p md_alg - * \param md_alg message digest to use - */ -static int hash_mprime(const unsigned char *hash, size_t hlen, - const unsigned char *salt, size_t slen, - unsigned char *out, mbedtls_md_type_t md_alg) -{ - const unsigned char zeros[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - mbedtls_md_context_t md_ctx; - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - - const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(md_alg); - if (md_info == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - mbedtls_md_init(&md_ctx); - if ((ret = mbedtls_md_setup(&md_ctx, md_info, 0)) != 0) { - goto exit; - } - if ((ret = mbedtls_md_starts(&md_ctx)) != 0) { - goto exit; - } - if ((ret = mbedtls_md_update(&md_ctx, zeros, sizeof(zeros))) != 0) { - goto exit; - } - if ((ret = mbedtls_md_update(&md_ctx, hash, hlen)) != 0) { - goto exit; - } - if ((ret = mbedtls_md_update(&md_ctx, salt, slen)) != 0) { - goto exit; - } - if ((ret = mbedtls_md_finish(&md_ctx, out)) != 0) { - goto exit; - } - -exit: - mbedtls_md_free(&md_ctx); + mbedtls_platform_zeroize( mask, sizeof( mask ) ); - return ret; -} - -/** - * Compute a hash. - * - * \param md_alg algorithm to use - * \param input input message to hash - * \param ilen input length - * \param output the output buffer - must be large enough for \p md_alg - */ -static int compute_hash(mbedtls_md_type_t md_alg, - const unsigned char *input, size_t ilen, - unsigned char *output) -{ - const mbedtls_md_info_t *md_info; - - md_info = mbedtls_md_info_from_type(md_alg); - if (md_info == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - return mbedtls_md(md_info, input, ilen, output); + return( ret ); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -1758,71 +1150,80 @@ static int compute_hash(mbedtls_md_type_t md_alg, /* * Implementation of the PKCS#1 v2.1 RSAES-OAEP-ENCRYPT function */ -int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - const unsigned char *label, size_t label_len, - size_t ilen, - const unsigned char *input, - unsigned char *output) +int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + const unsigned char *label, size_t label_len, + size_t ilen, + const unsigned char *input, + unsigned char *output ) { size_t olen; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *p = output; unsigned int hlen; + const mbedtls_md_info_t *md_info; + mbedtls_md_context_t md_ctx; - if (f_rng == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( output != NULL ); + RSA_VALIDATE_RET( ilen == 0 || input != NULL ); + RSA_VALIDATE_RET( label_len == 0 || label != NULL ); - hlen = mbedtls_md_get_size_from_type((mbedtls_md_type_t) ctx->hash_id); - if (hlen == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( f_rng == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + + md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); olen = ctx->len; + hlen = mbedtls_md_get_size( md_info ); /* first comparison checks for overflow */ - if (ilen + 2 * hlen + 2 < ilen || olen < ilen + 2 * hlen + 2) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ilen + 2 * hlen + 2 < ilen || olen < ilen + 2 * hlen + 2 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - memset(output, 0, olen); + memset( output, 0, olen ); *p++ = 0; /* Generate a random octet string seed */ - if ((ret = f_rng(p_rng, p, hlen)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_RNG_FAILED, ret); - } + if( ( ret = f_rng( p_rng, p, hlen ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ); p += hlen; /* Construct DB */ - ret = compute_hash((mbedtls_md_type_t) ctx->hash_id, label, label_len, p); - if (ret != 0) { - return ret; - } + if( ( ret = mbedtls_md( md_info, label, label_len, p ) ) != 0 ) + return( ret ); p += hlen; p += olen - 2 * hlen - 2 - ilen; *p++ = 1; - if (ilen != 0) { - memcpy(p, input, ilen); - } + if( ilen != 0 ) + memcpy( p, input, ilen ); + + mbedtls_md_init( &md_ctx ); + if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 ) + goto exit; /* maskedDB: Apply dbMask to DB */ - if ((ret = mgf_mask(output + hlen + 1, olen - hlen - 1, output + 1, hlen, - (mbedtls_md_type_t) ctx->hash_id)) != 0) { - return ret; - } + if( ( ret = mgf_mask( output + hlen + 1, olen - hlen - 1, output + 1, hlen, + &md_ctx ) ) != 0 ) + goto exit; /* maskedSeed: Apply seedMask to seed */ - if ((ret = mgf_mask(output + 1, hlen, output + hlen + 1, olen - hlen - 1, - (mbedtls_md_type_t) ctx->hash_id)) != 0) { - return ret; - } + if( ( ret = mgf_mask( output + 1, hlen, output + hlen + 1, olen - hlen - 1, + &md_ctx ) ) != 0 ) + goto exit; - return mbedtls_rsa_public(ctx, output, output); +exit: + mbedtls_md_free( &md_ctx ); + + if( ret != 0 ) + return( ret ); + + return( mbedtls_rsa_public( ctx, output, output ) ); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -1830,82 +1231,88 @@ int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx, /* * Implementation of the PKCS#1 v2.1 RSAES-PKCS1-V1_5-ENCRYPT function */ -int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, size_t ilen, - const unsigned char *input, - unsigned char *output) +int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, size_t ilen, + const unsigned char *input, + unsigned char *output ) { size_t nb_pad, olen; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *p = output; + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( output != NULL ); + RSA_VALIDATE_RET( ilen == 0 || input != NULL ); + olen = ctx->len; /* first comparison checks for overflow */ - if (ilen + 11 < ilen || olen < ilen + 11) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ilen + 11 < ilen || olen < ilen + 11 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); nb_pad = olen - 3 - ilen; *p++ = 0; - if (f_rng == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( f_rng == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); *p++ = MBEDTLS_RSA_CRYPT; - while (nb_pad-- > 0) { + while( nb_pad-- > 0 ) + { int rng_dl = 100; do { - ret = f_rng(p_rng, p, 1); - } while (*p == 0 && --rng_dl && ret == 0); + ret = f_rng( p_rng, p, 1 ); + } while( *p == 0 && --rng_dl && ret == 0 ); /* Check if RNG failed to generate data */ - if (rng_dl == 0 || ret != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_RNG_FAILED, ret); - } + if( rng_dl == 0 || ret != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ); p++; } *p++ = 0; - if (ilen != 0) { - memcpy(p, input, ilen); - } + if( ilen != 0 ) + memcpy( p, input, ilen ); - return mbedtls_rsa_public(ctx, output, output); + return( mbedtls_rsa_public( ctx, output, output ) ); } #endif /* MBEDTLS_PKCS1_V15 */ /* * Add the message padding, then do an RSA operation */ -int mbedtls_rsa_pkcs1_encrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - size_t ilen, - const unsigned char *input, - unsigned char *output) +int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + size_t ilen, + const unsigned char *input, + unsigned char *output ) { - switch (ctx->padding) { + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( output != NULL ); + RSA_VALIDATE_RET( ilen == 0 || input != NULL ); + + switch( ctx->padding ) + { #if defined(MBEDTLS_PKCS1_V15) case MBEDTLS_RSA_PKCS_V15: - return mbedtls_rsa_rsaes_pkcs1_v15_encrypt(ctx, f_rng, p_rng, - ilen, input, output); + return mbedtls_rsa_rsaes_pkcs1_v15_encrypt( ctx, f_rng, p_rng, + ilen, input, output ); #endif #if defined(MBEDTLS_PKCS1_V21) case MBEDTLS_RSA_PKCS_V21: - return mbedtls_rsa_rsaes_oaep_encrypt(ctx, f_rng, p_rng, NULL, 0, - ilen, input, output); + return mbedtls_rsa_rsaes_oaep_encrypt( ctx, f_rng, p_rng, NULL, 0, + ilen, input, output ); #endif default: - return MBEDTLS_ERR_RSA_INVALID_PADDING; + return( MBEDTLS_ERR_RSA_INVALID_PADDING ); } } @@ -1913,98 +1320,112 @@ int mbedtls_rsa_pkcs1_encrypt(mbedtls_rsa_context *ctx, /* * Implementation of the PKCS#1 v2.1 RSAES-OAEP-DECRYPT function */ -int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - const unsigned char *label, size_t label_len, - size_t *olen, - const unsigned char *input, - unsigned char *output, - size_t output_max_len) +int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + const unsigned char *label, size_t label_len, + size_t *olen, + const unsigned char *input, + unsigned char *output, + size_t output_max_len ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t ilen, i, pad_len; - unsigned char *p; - mbedtls_ct_condition_t bad, in_padding; + unsigned char *p, bad, pad_done; unsigned char buf[MBEDTLS_MPI_MAX_SIZE]; unsigned char lhash[MBEDTLS_MD_MAX_SIZE]; unsigned int hlen; + const mbedtls_md_info_t *md_info; + mbedtls_md_context_t md_ctx; + + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( output_max_len == 0 || output != NULL ); + RSA_VALIDATE_RET( label_len == 0 || label != NULL ); + RSA_VALIDATE_RET( input != NULL ); + RSA_VALIDATE_RET( olen != NULL ); /* * Parameters sanity checks */ - if (ctx->padding != MBEDTLS_RSA_PKCS_V21) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ctx->padding != MBEDTLS_RSA_PKCS_V21 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); ilen = ctx->len; - if (ilen < 16 || ilen > sizeof(buf)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ilen < 16 || ilen > sizeof( buf ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - hlen = mbedtls_md_get_size_from_type((mbedtls_md_type_t) ctx->hash_id); - if (hlen == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + + hlen = mbedtls_md_get_size( md_info ); // checking for integer underflow - if (2 * hlen + 2 > ilen) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( 2 * hlen + 2 > ilen ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); /* * RSA operation */ - ret = mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf); + ret = mbedtls_rsa_private( ctx, f_rng, p_rng, input, buf ); - if (ret != 0) { + if( ret != 0 ) goto cleanup; - } /* * Unmask data and generate lHash */ + mbedtls_md_init( &md_ctx ); + if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 ) + { + mbedtls_md_free( &md_ctx ); + goto cleanup; + } + /* seed: Apply seedMask to maskedSeed */ - if ((ret = mgf_mask(buf + 1, hlen, buf + hlen + 1, ilen - hlen - 1, - (mbedtls_md_type_t) ctx->hash_id)) != 0 || - /* DB: Apply dbMask to maskedDB */ - (ret = mgf_mask(buf + hlen + 1, ilen - hlen - 1, buf + 1, hlen, - (mbedtls_md_type_t) ctx->hash_id)) != 0) { + if( ( ret = mgf_mask( buf + 1, hlen, buf + hlen + 1, ilen - hlen - 1, + &md_ctx ) ) != 0 || + /* DB: Apply dbMask to maskedDB */ + ( ret = mgf_mask( buf + hlen + 1, ilen - hlen - 1, buf + 1, hlen, + &md_ctx ) ) != 0 ) + { + mbedtls_md_free( &md_ctx ); goto cleanup; } + mbedtls_md_free( &md_ctx ); + /* Generate lHash */ - ret = compute_hash((mbedtls_md_type_t) ctx->hash_id, - label, label_len, lhash); - if (ret != 0) { + if( ( ret = mbedtls_md( md_info, label, label_len, lhash ) ) != 0 ) goto cleanup; - } /* * Check contents, in "constant-time" */ p = buf; + bad = 0; - bad = mbedtls_ct_bool(*p++); /* First byte must be 0 */ + bad |= *p++; /* First byte must be 0 */ p += hlen; /* Skip seed */ /* Check lHash */ - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_bool(mbedtls_ct_memcmp(lhash, p, hlen))); - p += hlen; + for( i = 0; i < hlen; i++ ) + bad |= lhash[i] ^ *p++; /* Get zero-padding len, but always read till end of buffer * (minus one, for the 01 byte) */ pad_len = 0; - in_padding = MBEDTLS_CT_TRUE; - for (i = 0; i < ilen - 2 * hlen - 2; i++) { - in_padding = mbedtls_ct_bool_and(in_padding, mbedtls_ct_uint_eq(p[i], 0)); - pad_len += mbedtls_ct_uint_if_else_0(in_padding, 1); + pad_done = 0; + for( i = 0; i < ilen - 2 * hlen - 2; i++ ) + { + pad_done |= p[i]; + pad_len += ((pad_done | (unsigned char)-pad_done) >> 7) ^ 1; } p += pad_len; - bad = mbedtls_ct_bool_or(bad, mbedtls_ct_uint_ne(*p++, 0x01)); + bad |= *p++ ^ 0x01; /* * The only information "leaked" is whether the padding was correct or not @@ -2012,27 +1433,28 @@ int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx, * recommendations in PKCS#1 v2.2: an opponent cannot distinguish between * the different error conditions. */ - if (bad != MBEDTLS_CT_FALSE) { + if( bad != 0 ) + { ret = MBEDTLS_ERR_RSA_INVALID_PADDING; goto cleanup; } - if (ilen - ((size_t) (p - buf)) > output_max_len) { + if( ilen - ( p - buf ) > output_max_len ) + { ret = MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE; goto cleanup; } - *olen = ilen - ((size_t) (p - buf)); - if (*olen != 0) { - memcpy(output, p, *olen); - } + *olen = ilen - (p - buf); + if( *olen != 0 ) + memcpy( output, p, *olen ); ret = 0; cleanup: - mbedtls_platform_zeroize(buf, sizeof(buf)); - mbedtls_platform_zeroize(lhash, sizeof(lhash)); + mbedtls_platform_zeroize( buf, sizeof( buf ) ); + mbedtls_platform_zeroize( lhash, sizeof( lhash ) ); - return ret; + return( ret ); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -2040,83 +1462,91 @@ int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx, /* * Implementation of the PKCS#1 v2.1 RSAES-PKCS1-V1_5-DECRYPT function */ -int mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - size_t *olen, - const unsigned char *input, - unsigned char *output, - size_t output_max_len) +int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + size_t *olen, + const unsigned char *input, + unsigned char *output, + size_t output_max_len ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t ilen; unsigned char buf[MBEDTLS_MPI_MAX_SIZE]; + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( output_max_len == 0 || output != NULL ); + RSA_VALIDATE_RET( input != NULL ); + RSA_VALIDATE_RET( olen != NULL ); + ilen = ctx->len; - if (ctx->padding != MBEDTLS_RSA_PKCS_V15) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ctx->padding != MBEDTLS_RSA_PKCS_V15 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (ilen < 16 || ilen > sizeof(buf)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ilen < 16 || ilen > sizeof( buf ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - ret = mbedtls_rsa_private(ctx, f_rng, p_rng, input, buf); + ret = mbedtls_rsa_private( ctx, f_rng, p_rng, input, buf ); - if (ret != 0) { + if( ret != 0 ) goto cleanup; - } - ret = mbedtls_ct_rsaes_pkcs1_v15_unpadding(buf, ilen, - output, output_max_len, olen); + ret = mbedtls_ct_rsaes_pkcs1_v15_unpadding( buf, ilen, + output, output_max_len, olen ); cleanup: - mbedtls_platform_zeroize(buf, sizeof(buf)); + mbedtls_platform_zeroize( buf, sizeof( buf ) ); - return ret; + return( ret ); } #endif /* MBEDTLS_PKCS1_V15 */ /* * Do an RSA operation, then remove the message padding */ -int mbedtls_rsa_pkcs1_decrypt(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - size_t *olen, - const unsigned char *input, - unsigned char *output, - size_t output_max_len) +int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + size_t *olen, + const unsigned char *input, + unsigned char *output, + size_t output_max_len) { - switch (ctx->padding) { + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( output_max_len == 0 || output != NULL ); + RSA_VALIDATE_RET( input != NULL ); + RSA_VALIDATE_RET( olen != NULL ); + + switch( ctx->padding ) + { #if defined(MBEDTLS_PKCS1_V15) case MBEDTLS_RSA_PKCS_V15: - return mbedtls_rsa_rsaes_pkcs1_v15_decrypt(ctx, f_rng, p_rng, olen, - input, output, output_max_len); + return mbedtls_rsa_rsaes_pkcs1_v15_decrypt( ctx, f_rng, p_rng, olen, + input, output, output_max_len ); #endif #if defined(MBEDTLS_PKCS1_V21) case MBEDTLS_RSA_PKCS_V21: - return mbedtls_rsa_rsaes_oaep_decrypt(ctx, f_rng, p_rng, NULL, 0, - olen, input, output, - output_max_len); + return mbedtls_rsa_rsaes_oaep_decrypt( ctx, f_rng, p_rng, NULL, 0, + olen, input, output, + output_max_len ); #endif default: - return MBEDTLS_ERR_RSA_INVALID_PADDING; + return( MBEDTLS_ERR_RSA_INVALID_PADDING ); } } #if defined(MBEDTLS_PKCS1_V21) -static int rsa_rsassa_pss_sign_no_mode_check(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - int saltlen, - unsigned char *sig) +static int rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + int saltlen, + unsigned char *sig ) { size_t olen; unsigned char *p = sig; @@ -2124,163 +1554,150 @@ static int rsa_rsassa_pss_sign_no_mode_check(mbedtls_rsa_context *ctx, size_t slen, min_slen, hlen, offset = 0; int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t msb; - mbedtls_md_type_t hash_id; + const mbedtls_md_info_t *md_info; + mbedtls_md_context_t md_ctx; + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && + hashlen == 0 ) || + hash != NULL ); + RSA_VALIDATE_RET( sig != NULL ); - if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ctx->padding != MBEDTLS_RSA_PKCS_V21 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (f_rng == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( f_rng == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); olen = ctx->len; - if (md_alg != MBEDTLS_MD_NONE) { + if( md_alg != MBEDTLS_MD_NONE ) + { /* Gather length of hash to sign */ - size_t exp_hashlen = mbedtls_md_get_size_from_type(md_alg); - if (exp_hashlen == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + md_info = mbedtls_md_info_from_type( md_alg ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (hashlen != exp_hashlen) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( hashlen != mbedtls_md_get_size( md_info ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } - hash_id = (mbedtls_md_type_t) ctx->hash_id; - if (hash_id == MBEDTLS_MD_NONE) { - hash_id = md_alg; - } - hlen = mbedtls_md_get_size_from_type(hash_id); - if (hlen == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + md_info = mbedtls_md_info_from_type( (mbedtls_md_type_t) ctx->hash_id ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (saltlen == MBEDTLS_RSA_SALT_LEN_ANY) { - /* Calculate the largest possible salt length, up to the hash size. - * Normally this is the hash length, which is the maximum salt length - * according to FIPS 185-4 §5.5 (e) and common practice. If there is not - * enough room, use the maximum salt length that fits. The constraint is - * that the hash length plus the salt length plus 2 bytes must be at most - * the key length. This complies with FIPS 186-4 §5.5 (e) and RFC 8017 - * (PKCS#1 v2.2) §9.1.1 step 3. */ + hlen = mbedtls_md_get_size( md_info ); + + if (saltlen == MBEDTLS_RSA_SALT_LEN_ANY) + { + /* Calculate the largest possible salt length, up to the hash size. + * Normally this is the hash length, which is the maximum salt length + * according to FIPS 185-4 §5.5 (e) and common practice. If there is not + * enough room, use the maximum salt length that fits. The constraint is + * that the hash length plus the salt length plus 2 bytes must be at most + * the key length. This complies with FIPS 186-4 §5.5 (e) and RFC 8017 + * (PKCS#1 v2.2) §9.1.1 step 3. */ min_slen = hlen - 2; - if (olen < hlen + min_slen + 2) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } else if (olen >= hlen + hlen + 2) { + if( olen < hlen + min_slen + 2 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + else if( olen >= hlen + hlen + 2 ) slen = hlen; - } else { + else slen = olen - hlen - 2; - } - } else if ((saltlen < 0) || (saltlen + hlen + 2 > olen)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } else { + } + else if ( (saltlen < 0) || (saltlen + hlen + 2 > olen) ) + { + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + } + else + { slen = (size_t) saltlen; } - memset(sig, 0, olen); + memset( sig, 0, olen ); /* Note: EMSA-PSS encoding is over the length of N - 1 bits */ - msb = mbedtls_mpi_bitlen(&ctx->N) - 1; + msb = mbedtls_mpi_bitlen( &ctx->N ) - 1; p += olen - hlen - slen - 2; *p++ = 0x01; /* Generate salt of length slen in place in the encoded message */ salt = p; - if ((ret = f_rng(p_rng, salt, slen)) != 0) { - return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_RSA_RNG_FAILED, ret); - } + if( ( ret = f_rng( p_rng, salt, slen ) ) != 0 ) + return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_RSA_RNG_FAILED, ret ) ); p += slen; + mbedtls_md_init( &md_ctx ); + if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 ) + goto exit; + /* Generate H = Hash( M' ) */ - ret = hash_mprime(hash, hashlen, salt, slen, p, hash_id); - if (ret != 0) { - return ret; - } + if( ( ret = mbedtls_md_starts( &md_ctx ) ) != 0 ) + goto exit; + if( ( ret = mbedtls_md_update( &md_ctx, p, 8 ) ) != 0 ) + goto exit; + if( ( ret = mbedtls_md_update( &md_ctx, hash, hashlen ) ) != 0 ) + goto exit; + if( ( ret = mbedtls_md_update( &md_ctx, salt, slen ) ) != 0 ) + goto exit; + if( ( ret = mbedtls_md_finish( &md_ctx, p ) ) != 0 ) + goto exit; /* Compensate for boundary condition when applying mask */ - if (msb % 8 == 0) { + if( msb % 8 == 0 ) offset = 1; - } /* maskedDB: Apply dbMask to DB */ - ret = mgf_mask(sig + offset, olen - hlen - 1 - offset, p, hlen, hash_id); - if (ret != 0) { - return ret; - } + if( ( ret = mgf_mask( sig + offset, olen - hlen - 1 - offset, p, hlen, + &md_ctx ) ) != 0 ) + goto exit; - msb = mbedtls_mpi_bitlen(&ctx->N) - 1; - sig[0] &= 0xFF >> (olen * 8 - msb); + msb = mbedtls_mpi_bitlen( &ctx->N ) - 1; + sig[0] &= 0xFF >> ( olen * 8 - msb ); p += hlen; *p++ = 0xBC; - return mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig); -} +exit: + mbedtls_md_free( &md_ctx ); -static int rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - int saltlen, - unsigned char *sig) -{ - if (ctx->padding != MBEDTLS_RSA_PKCS_V21) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - if ((ctx->hash_id == MBEDTLS_MD_NONE) && (md_alg == MBEDTLS_MD_NONE)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - return rsa_rsassa_pss_sign_no_mode_check(ctx, f_rng, p_rng, md_alg, hashlen, hash, saltlen, - sig); -} + if( ret != 0 ) + return( ret ); -int mbedtls_rsa_rsassa_pss_sign_no_mode_check(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig) -{ - return rsa_rsassa_pss_sign_no_mode_check(ctx, f_rng, p_rng, md_alg, - hashlen, hash, MBEDTLS_RSA_SALT_LEN_ANY, sig); + return mbedtls_rsa_private( ctx, f_rng, p_rng, sig, sig ); } /* * Implementation of the PKCS#1 v2.1 RSASSA-PSS-SIGN function with * the option to pass in the salt length. */ -int mbedtls_rsa_rsassa_pss_sign_ext(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - int saltlen, - unsigned char *sig) +int mbedtls_rsa_rsassa_pss_sign_ext( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + int saltlen, + unsigned char *sig ) { - return rsa_rsassa_pss_sign(ctx, f_rng, p_rng, md_alg, - hashlen, hash, saltlen, sig); + return rsa_rsassa_pss_sign( ctx, f_rng, p_rng, md_alg, + hashlen, hash, saltlen, sig ); } + /* * Implementation of the PKCS#1 v2.1 RSASSA-PSS-SIGN function */ -int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig) +int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + unsigned char *sig ) { - return rsa_rsassa_pss_sign(ctx, f_rng, p_rng, md_alg, - hashlen, hash, MBEDTLS_RSA_SALT_LEN_ANY, sig); + return rsa_rsassa_pss_sign( ctx, f_rng, p_rng, md_alg, + hashlen, hash, MBEDTLS_RSA_SALT_LEN_ANY, sig ); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -2306,11 +1723,11 @@ int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx, * - dst points to a buffer of size at least dst_len. * */ -static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - size_t dst_len, - unsigned char *dst) +static int rsa_rsassa_pkcs1_v15_encode( mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + size_t dst_len, + unsigned char *dst ) { size_t oid_size = 0; size_t nb_pad = dst_len; @@ -2318,27 +1735,24 @@ static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg, const char *oid = NULL; /* Are we signing hashed or raw data? */ - if (md_alg != MBEDTLS_MD_NONE) { - unsigned char md_size = mbedtls_md_get_size_from_type(md_alg); - if (md_size == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( md_alg != MBEDTLS_MD_NONE ) + { + const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type( md_alg ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (mbedtls_oid_get_oid_by_md(md_alg, &oid, &oid_size) != 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( mbedtls_oid_get_oid_by_md( md_alg, &oid, &oid_size ) != 0 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (hashlen != md_size) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( hashlen != mbedtls_md_get_size( md_info ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); /* Double-check that 8 + hashlen + oid_size can be used as a * 1-byte ASN.1 length encoding and that there's no overflow. */ - if (8 + hashlen + oid_size >= 0x80 || + if( 8 + hashlen + oid_size >= 0x80 || 10 + hashlen < hashlen || - 10 + hashlen + oid_size < 10 + hashlen) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + 10 + hashlen + oid_size < 10 + hashlen ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); /* * Static bounds check: @@ -2348,23 +1762,22 @@ static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg, * - Need hashlen bytes for hash * - Need oid_size bytes for hash alg OID. */ - if (nb_pad < 10 + hashlen + oid_size) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( nb_pad < 10 + hashlen + oid_size ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); nb_pad -= 10 + hashlen + oid_size; - } else { - if (nb_pad < hashlen) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + } + else + { + if( nb_pad < hashlen ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); nb_pad -= hashlen; } /* Need space for signature header and padding delimiter (3 bytes), * and 8 bytes for the minimal padding */ - if (nb_pad < 3 + 8) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( nb_pad < 3 + 8 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); nb_pad -= 3; /* Now nb_pad is the amount of memory to be filled @@ -2373,14 +1786,15 @@ static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg, /* Write signature header and padding */ *p++ = 0; *p++ = MBEDTLS_RSA_SIGN; - memset(p, 0xFF, nb_pad); + memset( p, 0xFF, nb_pad ); p += nb_pad; *p++ = 0; /* Are we signing raw data? */ - if (md_alg == MBEDTLS_MD_NONE) { - memcpy(p, hash, hashlen); - return 0; + if( md_alg == MBEDTLS_MD_NONE ) + { + memcpy( p, hash, hashlen ); + return( 0 ); } /* Signing hashed data, add corresponding ASN.1 structure @@ -2397,60 +1811,61 @@ static int rsa_rsassa_pkcs1_v15_encode(mbedtls_md_type_t md_alg, * TAG-OCTET + LEN [ HASH ] ] */ *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED; - *p++ = (unsigned char) (0x08 + oid_size + hashlen); + *p++ = (unsigned char)( 0x08 + oid_size + hashlen ); *p++ = MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED; - *p++ = (unsigned char) (0x04 + oid_size); + *p++ = (unsigned char)( 0x04 + oid_size ); *p++ = MBEDTLS_ASN1_OID; *p++ = (unsigned char) oid_size; - memcpy(p, oid, oid_size); + memcpy( p, oid, oid_size ); p += oid_size; *p++ = MBEDTLS_ASN1_NULL; *p++ = 0x00; *p++ = MBEDTLS_ASN1_OCTET_STRING; *p++ = (unsigned char) hashlen; - memcpy(p, hash, hashlen); + memcpy( p, hash, hashlen ); p += hashlen; /* Just a sanity-check, should be automatic * after the initial bounds check. */ - if (p != dst + dst_len) { - mbedtls_platform_zeroize(dst, dst_len); - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; + if( p != dst + dst_len ) + { + mbedtls_platform_zeroize( dst, dst_len ); + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } - return 0; + return( 0 ); } /* * Do an RSA operation to sign the message digest */ -int mbedtls_rsa_rsassa_pkcs1_v15_sign(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig) +int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + unsigned char *sig ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *sig_try = NULL, *verif = NULL; - if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && + hashlen == 0 ) || + hash != NULL ); + RSA_VALIDATE_RET( sig != NULL ); - if (ctx->padding != MBEDTLS_RSA_PKCS_V15) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( ctx->padding != MBEDTLS_RSA_PKCS_V15 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); /* * Prepare PKCS1-v1.5 encoding (padding and hash identifier) */ - if ((ret = rsa_rsassa_pkcs1_v15_encode(md_alg, hashlen, hash, - ctx->len, sig)) != 0) { - return ret; - } + if( ( ret = rsa_rsassa_pkcs1_v15_encode( md_alg, hashlen, hash, + ctx->len, sig ) ) != 0 ) + return( ret ); /* Private key operation * @@ -2458,68 +1873,73 @@ int mbedtls_rsa_rsassa_pkcs1_v15_sign(mbedtls_rsa_context *ctx, * temporary buffer and check it before returning it. */ - sig_try = (unsigned char*) mbedtls_calloc(1, ctx->len); - if (sig_try == NULL) { - return MBEDTLS_ERR_MPI_ALLOC_FAILED; - } + sig_try = (unsigned char *) mbedtls_calloc( 1, ctx->len ); + if( sig_try == NULL ) + return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); - verif = (unsigned char*) mbedtls_calloc(1, ctx->len); - if (verif == NULL) { - mbedtls_free(sig_try); - return MBEDTLS_ERR_MPI_ALLOC_FAILED; + verif = (unsigned char *) mbedtls_calloc( 1, ctx->len ); + if( verif == NULL ) + { + mbedtls_free( sig_try ); + return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); } - MBEDTLS_MPI_CHK(mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig_try)); - MBEDTLS_MPI_CHK(mbedtls_rsa_public(ctx, sig_try, verif)); + MBEDTLS_MPI_CHK( mbedtls_rsa_private( ctx, f_rng, p_rng, sig, sig_try ) ); + MBEDTLS_MPI_CHK( mbedtls_rsa_public( ctx, sig_try, verif ) ); - if (mbedtls_ct_memcmp(verif, sig, ctx->len) != 0) { + if( mbedtls_ct_memcmp( verif, sig, ctx->len ) != 0 ) + { ret = MBEDTLS_ERR_RSA_PRIVATE_FAILED; goto cleanup; } - memcpy(sig, sig_try, ctx->len); + memcpy( sig, sig_try, ctx->len ); cleanup: - mbedtls_zeroize_and_free(sig_try, ctx->len); - mbedtls_zeroize_and_free(verif, ctx->len); - - if (ret != 0) { - memset(sig, '!', ctx->len); - } - return ret; + mbedtls_platform_zeroize( sig_try, ctx->len ); + mbedtls_platform_zeroize( verif, ctx->len ); + mbedtls_free( sig_try ); + mbedtls_free( verif ); + + if( ret != 0 ) + memset( sig, '!', ctx->len ); + return( ret ); } #endif /* MBEDTLS_PKCS1_V15 */ /* * Do an RSA operation to sign the message digest */ -int mbedtls_rsa_pkcs1_sign(mbedtls_rsa_context *ctx, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - unsigned char *sig) +int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + unsigned char *sig ) { - if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - switch (ctx->padding) { + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && + hashlen == 0 ) || + hash != NULL ); + RSA_VALIDATE_RET( sig != NULL ); + + switch( ctx->padding ) + { #if defined(MBEDTLS_PKCS1_V15) case MBEDTLS_RSA_PKCS_V15: - return mbedtls_rsa_rsassa_pkcs1_v15_sign(ctx, f_rng, p_rng, - md_alg, hashlen, hash, sig); + return mbedtls_rsa_rsassa_pkcs1_v15_sign( ctx, f_rng, p_rng, + md_alg, hashlen, hash, sig ); #endif #if defined(MBEDTLS_PKCS1_V21) case MBEDTLS_RSA_PKCS_V21: - return mbedtls_rsa_rsassa_pss_sign(ctx, f_rng, p_rng, md_alg, - hashlen, hash, sig); + return mbedtls_rsa_rsassa_pss_sign( ctx, f_rng, p_rng, md_alg, + hashlen, hash, sig ); #endif default: - return MBEDTLS_ERR_RSA_INVALID_PADDING; + return( MBEDTLS_ERR_RSA_INVALID_PADDING ); } } @@ -2527,143 +1947,169 @@ int mbedtls_rsa_pkcs1_sign(mbedtls_rsa_context *ctx, /* * Implementation of the PKCS#1 v2.1 RSASSA-PSS-VERIFY function */ -int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - mbedtls_md_type_t mgf1_hash_id, - int expected_salt_len, - const unsigned char *sig) +int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + mbedtls_md_type_t mgf1_hash_id, + int expected_salt_len, + const unsigned char *sig ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t siglen; unsigned char *p; unsigned char *hash_start; unsigned char result[MBEDTLS_MD_MAX_SIZE]; + unsigned char zeros[8]; unsigned int hlen; size_t observed_salt_len, msb; - unsigned char buf[MBEDTLS_MPI_MAX_SIZE] = { 0 }; + const mbedtls_md_info_t *md_info; + mbedtls_md_context_t md_ctx; + unsigned char buf[MBEDTLS_MPI_MAX_SIZE]; - if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( sig != NULL ); + RSA_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && + hashlen == 0 ) || + hash != NULL ); siglen = ctx->len; - if (siglen < 16 || siglen > sizeof(buf)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( siglen < 16 || siglen > sizeof( buf ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - ret = mbedtls_rsa_public(ctx, sig, buf); + ret = mbedtls_rsa_public( ctx, sig, buf ); - if (ret != 0) { - return ret; - } + if( ret != 0 ) + return( ret ); p = buf; - if (buf[siglen - 1] != 0xBC) { - return MBEDTLS_ERR_RSA_INVALID_PADDING; - } + if( buf[siglen - 1] != 0xBC ) + return( MBEDTLS_ERR_RSA_INVALID_PADDING ); - if (md_alg != MBEDTLS_MD_NONE) { + if( md_alg != MBEDTLS_MD_NONE ) + { /* Gather length of hash to sign */ - size_t exp_hashlen = mbedtls_md_get_size_from_type(md_alg); - if (exp_hashlen == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + md_info = mbedtls_md_info_from_type( md_alg ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); - if (hashlen != exp_hashlen) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( hashlen != mbedtls_md_get_size( md_info ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); } - hlen = mbedtls_md_get_size_from_type(mgf1_hash_id); - if (hlen == 0) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + md_info = mbedtls_md_info_from_type( mgf1_hash_id ); + if( md_info == NULL ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); + + hlen = mbedtls_md_get_size( md_info ); + + memset( zeros, 0, 8 ); /* * Note: EMSA-PSS verification is over the length of N - 1 bits */ - msb = mbedtls_mpi_bitlen(&ctx->N) - 1; + msb = mbedtls_mpi_bitlen( &ctx->N ) - 1; - if (buf[0] >> (8 - siglen * 8 + msb)) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( buf[0] >> ( 8 - siglen * 8 + msb ) ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); /* Compensate for boundary condition when applying mask */ - if (msb % 8 == 0) { + if( msb % 8 == 0 ) + { p++; siglen -= 1; } - if (siglen < hlen + 2) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + if( siglen < hlen + 2 ) + return( MBEDTLS_ERR_RSA_BAD_INPUT_DATA ); hash_start = p + siglen - hlen - 1; - ret = mgf_mask(p, siglen - hlen - 1, hash_start, hlen, mgf1_hash_id); - if (ret != 0) { - return ret; - } + mbedtls_md_init( &md_ctx ); + if( ( ret = mbedtls_md_setup( &md_ctx, md_info, 0 ) ) != 0 ) + goto exit; + + ret = mgf_mask( p, siglen - hlen - 1, hash_start, hlen, &md_ctx ); + if( ret != 0 ) + goto exit; - buf[0] &= 0xFF >> (siglen * 8 - msb); + buf[0] &= 0xFF >> ( siglen * 8 - msb ); - while (p < hash_start - 1 && *p == 0) { + while( p < hash_start - 1 && *p == 0 ) p++; - } - if (*p++ != 0x01) { - return MBEDTLS_ERR_RSA_INVALID_PADDING; + if( *p++ != 0x01 ) + { + ret = MBEDTLS_ERR_RSA_INVALID_PADDING; + goto exit; } - observed_salt_len = (size_t) (hash_start - p); + observed_salt_len = hash_start - p; - if (expected_salt_len != MBEDTLS_RSA_SALT_LEN_ANY && - observed_salt_len != (size_t) expected_salt_len) { - return MBEDTLS_ERR_RSA_INVALID_PADDING; + if( expected_salt_len != MBEDTLS_RSA_SALT_LEN_ANY && + observed_salt_len != (size_t) expected_salt_len ) + { + ret = MBEDTLS_ERR_RSA_INVALID_PADDING; + goto exit; } /* * Generate H = Hash( M' ) */ - ret = hash_mprime(hash, hashlen, p, observed_salt_len, - result, mgf1_hash_id); - if (ret != 0) { - return ret; - } + ret = mbedtls_md_starts( &md_ctx ); + if ( ret != 0 ) + goto exit; + ret = mbedtls_md_update( &md_ctx, zeros, 8 ); + if ( ret != 0 ) + goto exit; + ret = mbedtls_md_update( &md_ctx, hash, hashlen ); + if ( ret != 0 ) + goto exit; + ret = mbedtls_md_update( &md_ctx, p, observed_salt_len ); + if ( ret != 0 ) + goto exit; + ret = mbedtls_md_finish( &md_ctx, result ); + if ( ret != 0 ) + goto exit; - if (memcmp(hash_start, result, hlen) != 0) { - return MBEDTLS_ERR_RSA_VERIFY_FAILED; + if( memcmp( hash_start, result, hlen ) != 0 ) + { + ret = MBEDTLS_ERR_RSA_VERIFY_FAILED; + goto exit; } - return 0; +exit: + mbedtls_md_free( &md_ctx ); + + return( ret ); } /* * Simplified PKCS#1 v2.1 RSASSA-PSS-VERIFY function */ -int mbedtls_rsa_rsassa_pss_verify(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - const unsigned char *sig) +int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + const unsigned char *sig ) { mbedtls_md_type_t mgf1_hash_id; - if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( sig != NULL ); + RSA_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && + hashlen == 0 ) || + hash != NULL ); - mgf1_hash_id = (ctx->hash_id != MBEDTLS_MD_NONE) + mgf1_hash_id = ( ctx->hash_id != MBEDTLS_MD_NONE ) ? (mbedtls_md_type_t) ctx->hash_id : md_alg; - return mbedtls_rsa_rsassa_pss_verify_ext(ctx, - md_alg, hashlen, hash, - mgf1_hash_id, - MBEDTLS_RSA_SALT_LEN_ANY, - sig); + return( mbedtls_rsa_rsassa_pss_verify_ext( ctx, + md_alg, hashlen, hash, + mgf1_hash_id, + MBEDTLS_RSA_SALT_LEN_ANY, + sig ) ); } #endif /* MBEDTLS_PKCS1_V21 */ @@ -2672,19 +2118,21 @@ int mbedtls_rsa_rsassa_pss_verify(mbedtls_rsa_context *ctx, /* * Implementation of the PKCS#1 v2.1 RSASSA-PKCS1-v1_5-VERIFY function */ -int mbedtls_rsa_rsassa_pkcs1_v15_verify(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - const unsigned char *sig) +int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + const unsigned char *sig ) { int ret = 0; size_t sig_len; unsigned char *encoded = NULL, *encoded_expected = NULL; - if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( sig != NULL ); + RSA_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && + hashlen == 0 ) || + hash != NULL ); sig_len = ctx->len; @@ -2692,151 +2140,159 @@ int mbedtls_rsa_rsassa_pkcs1_v15_verify(mbedtls_rsa_context *ctx, * Prepare expected PKCS1 v1.5 encoding of hash. */ - if ((encoded = (unsigned char*) mbedtls_calloc(1, sig_len)) == NULL || - (encoded_expected = (unsigned char*) mbedtls_calloc(1, sig_len)) == NULL) { + if( ( encoded = (unsigned char *) mbedtls_calloc( 1, sig_len ) ) == NULL || + ( encoded_expected = (unsigned char *) mbedtls_calloc( 1, sig_len ) ) == NULL ) + { ret = MBEDTLS_ERR_MPI_ALLOC_FAILED; goto cleanup; } - if ((ret = rsa_rsassa_pkcs1_v15_encode(md_alg, hashlen, hash, sig_len, - encoded_expected)) != 0) { + if( ( ret = rsa_rsassa_pkcs1_v15_encode( md_alg, hashlen, hash, sig_len, + encoded_expected ) ) != 0 ) goto cleanup; - } /* * Apply RSA primitive to get what should be PKCS1 encoded hash. */ - ret = mbedtls_rsa_public(ctx, sig, encoded); - if (ret != 0) { + ret = mbedtls_rsa_public( ctx, sig, encoded ); + if( ret != 0 ) goto cleanup; - } /* * Compare */ - if ((ret = mbedtls_ct_memcmp(encoded, encoded_expected, - sig_len)) != 0) { + if( ( ret = mbedtls_ct_memcmp( encoded, encoded_expected, + sig_len ) ) != 0 ) + { ret = MBEDTLS_ERR_RSA_VERIFY_FAILED; goto cleanup; } cleanup: - if (encoded != NULL) { - mbedtls_zeroize_and_free(encoded, sig_len); + if( encoded != NULL ) + { + mbedtls_platform_zeroize( encoded, sig_len ); + mbedtls_free( encoded ); } - if (encoded_expected != NULL) { - mbedtls_zeroize_and_free(encoded_expected, sig_len); + if( encoded_expected != NULL ) + { + mbedtls_platform_zeroize( encoded_expected, sig_len ); + mbedtls_free( encoded_expected ); } - return ret; + return( ret ); } #endif /* MBEDTLS_PKCS1_V15 */ /* * Do an RSA operation and check the message digest */ -int mbedtls_rsa_pkcs1_verify(mbedtls_rsa_context *ctx, - mbedtls_md_type_t md_alg, - unsigned int hashlen, - const unsigned char *hash, - const unsigned char *sig) +int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx, + mbedtls_md_type_t md_alg, + unsigned int hashlen, + const unsigned char *hash, + const unsigned char *sig ) { - if ((md_alg != MBEDTLS_MD_NONE || hashlen != 0) && hash == NULL) { - return MBEDTLS_ERR_RSA_BAD_INPUT_DATA; - } - - switch (ctx->padding) { + RSA_VALIDATE_RET( ctx != NULL ); + RSA_VALIDATE_RET( sig != NULL ); + RSA_VALIDATE_RET( ( md_alg == MBEDTLS_MD_NONE && + hashlen == 0 ) || + hash != NULL ); + + switch( ctx->padding ) + { #if defined(MBEDTLS_PKCS1_V15) case MBEDTLS_RSA_PKCS_V15: - return mbedtls_rsa_rsassa_pkcs1_v15_verify(ctx, md_alg, - hashlen, hash, sig); + return mbedtls_rsa_rsassa_pkcs1_v15_verify( ctx, md_alg, + hashlen, hash, sig ); #endif #if defined(MBEDTLS_PKCS1_V21) case MBEDTLS_RSA_PKCS_V21: - return mbedtls_rsa_rsassa_pss_verify(ctx, md_alg, - hashlen, hash, sig); + return mbedtls_rsa_rsassa_pss_verify( ctx, md_alg, + hashlen, hash, sig ); #endif default: - return MBEDTLS_ERR_RSA_INVALID_PADDING; + return( MBEDTLS_ERR_RSA_INVALID_PADDING ); } } /* * Copy the components of an RSA key */ -int mbedtls_rsa_copy(mbedtls_rsa_context *dst, const mbedtls_rsa_context *src) +int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + RSA_VALIDATE_RET( dst != NULL ); + RSA_VALIDATE_RET( src != NULL ); dst->len = src->len; - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->N, &src->N)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->E, &src->E)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->N, &src->N ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->E, &src->E ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->D, &src->D)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->P, &src->P)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Q, &src->Q)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->D, &src->D ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->P, &src->P ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->Q, &src->Q ) ); #if !defined(MBEDTLS_RSA_NO_CRT) - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->DP, &src->DP)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->DQ, &src->DQ)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->QP, &src->QP)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RP, &src->RP)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RQ, &src->RQ)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->DP, &src->DP ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->DQ, &src->DQ ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->QP, &src->QP ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->RP, &src->RP ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->RQ, &src->RQ ) ); #endif - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->RN, &src->RN)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->RN, &src->RN ) ); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Vi, &src->Vi)); - MBEDTLS_MPI_CHK(mbedtls_mpi_copy(&dst->Vf, &src->Vf)); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->Vi, &src->Vi ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &dst->Vf, &src->Vf ) ); dst->padding = src->padding; dst->hash_id = src->hash_id; cleanup: - if (ret != 0) { - mbedtls_rsa_free(dst); - } + if( ret != 0 ) + mbedtls_rsa_free( dst ); - return ret; + return( ret ); } /* * Free the components of an RSA key */ -void mbedtls_rsa_free(mbedtls_rsa_context *ctx) +void mbedtls_rsa_free( mbedtls_rsa_context *ctx ) { - if (ctx == NULL) { + if( ctx == NULL ) return; - } - mbedtls_mpi_free(&ctx->Vi); - mbedtls_mpi_free(&ctx->Vf); - mbedtls_mpi_free(&ctx->RN); - mbedtls_mpi_free(&ctx->D); - mbedtls_mpi_free(&ctx->Q); - mbedtls_mpi_free(&ctx->P); - mbedtls_mpi_free(&ctx->E); - mbedtls_mpi_free(&ctx->N); + mbedtls_mpi_free( &ctx->Vi ); + mbedtls_mpi_free( &ctx->Vf ); + mbedtls_mpi_free( &ctx->RN ); + mbedtls_mpi_free( &ctx->D ); + mbedtls_mpi_free( &ctx->Q ); + mbedtls_mpi_free( &ctx->P ); + mbedtls_mpi_free( &ctx->E ); + mbedtls_mpi_free( &ctx->N ); #if !defined(MBEDTLS_RSA_NO_CRT) - mbedtls_mpi_free(&ctx->RQ); - mbedtls_mpi_free(&ctx->RP); - mbedtls_mpi_free(&ctx->QP); - mbedtls_mpi_free(&ctx->DQ); - mbedtls_mpi_free(&ctx->DP); + mbedtls_mpi_free( &ctx->RQ ); + mbedtls_mpi_free( &ctx->RP ); + mbedtls_mpi_free( &ctx->QP ); + mbedtls_mpi_free( &ctx->DQ ); + mbedtls_mpi_free( &ctx->DP ); #endif /* MBEDTLS_RSA_NO_CRT */ #if defined(MBEDTLS_THREADING_C) /* Free the mutex, but only if it hasn't been freed already. */ - if (ctx->ver != 0) { - mbedtls_mutex_free(&ctx->mutex); + if( ctx->ver != 0 ) + { + mbedtls_mutex_free( &ctx->mutex ); ctx->ver = 0; } #endif @@ -2846,6 +2302,7 @@ void mbedtls_rsa_free(mbedtls_rsa_context *ctx) #if defined(MBEDTLS_SELF_TEST) +#include "mbedtls/sha1.h" /* * Example RSA-1024 keypair, for test purposes @@ -2887,34 +2344,31 @@ void mbedtls_rsa_free(mbedtls_rsa_context *ctx) "\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD" #if defined(MBEDTLS_PKCS1_V15) -static int myrand(void *rng_state, unsigned char *output, size_t len) +static int myrand( void *rng_state, unsigned char *output, size_t len ) { #if !defined(__OpenBSD__) && !defined(__NetBSD__) size_t i; - if (rng_state != NULL) { + if( rng_state != NULL ) rng_state = NULL; - } - for (i = 0; i < len; ++i) { + for( i = 0; i < len; ++i ) output[i] = rand(); - } #else - if (rng_state != NULL) { + if( rng_state != NULL ) rng_state = NULL; - } - arc4random_buf(output, len); + arc4random_buf( output, len ); #endif /* !OpenBSD && !NetBSD */ - return 0; + return( 0 ); } #endif /* MBEDTLS_PKCS1_V15 */ /* * Checkup routine */ -int mbedtls_rsa_self_test(int verbose) +int mbedtls_rsa_self_test( int verbose ) { int ret = 0; #if defined(MBEDTLS_PKCS1_V15) @@ -2923,142 +2377,133 @@ int mbedtls_rsa_self_test(int verbose) unsigned char rsa_plaintext[PT_LEN]; unsigned char rsa_decrypted[PT_LEN]; unsigned char rsa_ciphertext[KEY_LEN]; -#if defined(MBEDTLS_MD_CAN_SHA1) +#if defined(MBEDTLS_SHA1_C) unsigned char sha1sum[20]; #endif mbedtls_mpi K; - mbedtls_mpi_init(&K); - mbedtls_rsa_init(&rsa); + mbedtls_mpi_init( &K ); + mbedtls_rsa_init( &rsa ); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_N)); - MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, &K, NULL, NULL, NULL, NULL)); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_P)); - MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, &K, NULL, NULL, NULL)); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_Q)); - MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, NULL, &K, NULL, NULL)); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_D)); - MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, NULL, NULL, &K, NULL)); - MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&K, 16, RSA_E)); - MBEDTLS_MPI_CHK(mbedtls_rsa_import(&rsa, NULL, NULL, NULL, NULL, &K)); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_N ) ); + MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, &K, NULL, NULL, NULL, NULL ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_P ) ); + MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, &K, NULL, NULL, NULL ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_Q ) ); + MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, &K, NULL, NULL ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_D ) ); + MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, NULL, &K, NULL ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_read_string( &K, 16, RSA_E ) ); + MBEDTLS_MPI_CHK( mbedtls_rsa_import( &rsa, NULL, NULL, NULL, NULL, &K ) ); - MBEDTLS_MPI_CHK(mbedtls_rsa_complete(&rsa)); + MBEDTLS_MPI_CHK( mbedtls_rsa_complete( &rsa ) ); - if (verbose != 0) { - mbedtls_printf(" RSA key validation: "); - } + if( verbose != 0 ) + mbedtls_printf( " RSA key validation: " ); - if (mbedtls_rsa_check_pubkey(&rsa) != 0 || - mbedtls_rsa_check_privkey(&rsa) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_rsa_check_pubkey( &rsa ) != 0 || + mbedtls_rsa_check_privkey( &rsa ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n PKCS#1 encryption : "); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n PKCS#1 encryption : " ); - memcpy(rsa_plaintext, RSA_PT, PT_LEN); + memcpy( rsa_plaintext, RSA_PT, PT_LEN ); - if (mbedtls_rsa_pkcs1_encrypt(&rsa, myrand, NULL, - PT_LEN, rsa_plaintext, - rsa_ciphertext) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_rsa_pkcs1_encrypt( &rsa, myrand, NULL, + PT_LEN, rsa_plaintext, + rsa_ciphertext ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n PKCS#1 decryption : "); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n PKCS#1 decryption : " ); - if (mbedtls_rsa_pkcs1_decrypt(&rsa, myrand, NULL, - &len, rsa_ciphertext, rsa_decrypted, - sizeof(rsa_decrypted)) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_rsa_pkcs1_decrypt( &rsa, myrand, NULL, + &len, rsa_ciphertext, rsa_decrypted, + sizeof(rsa_decrypted) ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (memcmp(rsa_decrypted, rsa_plaintext, len) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( memcmp( rsa_decrypted, rsa_plaintext, len ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); -#if defined(MBEDTLS_MD_CAN_SHA1) - if (verbose != 0) { - mbedtls_printf(" PKCS#1 data sign : "); - } +#if defined(MBEDTLS_SHA1_C) + if( verbose != 0 ) + mbedtls_printf( " PKCS#1 data sign : " ); - if (mbedtls_md(mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), - rsa_plaintext, PT_LEN, sha1sum) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_sha1( rsa_plaintext, PT_LEN, sha1sum ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); - return 1; + return( 1 ); } - if (mbedtls_rsa_pkcs1_sign(&rsa, myrand, NULL, - MBEDTLS_MD_SHA1, 20, - sha1sum, rsa_ciphertext) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_rsa_pkcs1_sign( &rsa, myrand, NULL, + MBEDTLS_MD_SHA1, 20, + sha1sum, rsa_ciphertext ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n PKCS#1 sig. verify: "); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n PKCS#1 sig. verify: " ); - if (mbedtls_rsa_pkcs1_verify(&rsa, MBEDTLS_MD_SHA1, 20, - sha1sum, rsa_ciphertext) != 0) { - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( mbedtls_rsa_pkcs1_verify( &rsa, MBEDTLS_MD_SHA1, 20, + sha1sum, rsa_ciphertext ) != 0 ) + { + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); ret = 1; goto cleanup; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } -#endif /* MBEDTLS_MD_CAN_SHA1 */ + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); +#endif /* MBEDTLS_SHA1_C */ - if (verbose != 0) { - mbedtls_printf("\n"); - } + if( verbose != 0 ) + mbedtls_printf( "\n" ); cleanup: - mbedtls_mpi_free(&K); - mbedtls_rsa_free(&rsa); + mbedtls_mpi_free( &K ); + mbedtls_rsa_free( &rsa ); #else /* MBEDTLS_PKCS1_V15 */ ((void) verbose); #endif /* MBEDTLS_PKCS1_V15 */ - return ret; + return( ret ); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.cpp b/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.cpp index 5c265a992..dff2d9345 100644 --- a/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.cpp +++ b/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.cpp @@ -2,7 +2,19 @@ * Helper functions for the RSA module * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * */ @@ -47,9 +59,9 @@ * of (a) and (b) above to attempt to factor N. * */ -int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N, - mbedtls_mpi const *E, mbedtls_mpi const *D, - mbedtls_mpi *P, mbedtls_mpi *Q) +int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, + mbedtls_mpi const *E, mbedtls_mpi const *D, + mbedtls_mpi *P, mbedtls_mpi *Q ) { int ret = 0; @@ -62,46 +74,48 @@ int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N, mbedtls_mpi K; /* Temporary holding the current candidate */ const unsigned char primes[] = { 2, - 3, 5, 7, 11, 13, 17, 19, 23, - 29, 31, 37, 41, 43, 47, 53, 59, - 61, 67, 71, 73, 79, 83, 89, 97, - 101, 103, 107, 109, 113, 127, 131, 137, - 139, 149, 151, 157, 163, 167, 173, 179, - 181, 191, 193, 197, 199, 211, 223, 227, - 229, 233, 239, 241, 251 }; - - const size_t num_primes = sizeof(primes) / sizeof(*primes); - - if (P == NULL || Q == NULL || P->p != NULL || Q->p != NULL) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } - - if (mbedtls_mpi_cmp_int(N, 0) <= 0 || - mbedtls_mpi_cmp_int(D, 1) <= 0 || - mbedtls_mpi_cmp_mpi(D, N) >= 0 || - mbedtls_mpi_cmp_int(E, 1) <= 0 || - mbedtls_mpi_cmp_mpi(E, N) >= 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; + 3, 5, 7, 11, 13, 17, 19, 23, + 29, 31, 37, 41, 43, 47, 53, 59, + 61, 67, 71, 73, 79, 83, 89, 97, + 101, 103, 107, 109, 113, 127, 131, 137, + 139, 149, 151, 157, 163, 167, 173, 179, + 181, 191, 193, 197, 199, 211, 223, 227, + 229, 233, 239, 241, 251 + }; + + const size_t num_primes = sizeof( primes ) / sizeof( *primes ); + + if( P == NULL || Q == NULL || P->p != NULL || Q->p != NULL ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); + + if( mbedtls_mpi_cmp_int( N, 0 ) <= 0 || + mbedtls_mpi_cmp_int( D, 1 ) <= 0 || + mbedtls_mpi_cmp_mpi( D, N ) >= 0 || + mbedtls_mpi_cmp_int( E, 1 ) <= 0 || + mbedtls_mpi_cmp_mpi( E, N ) >= 0 ) + { + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); } /* * Initializations and temporary changes */ - mbedtls_mpi_init(&K); - mbedtls_mpi_init(&T); + mbedtls_mpi_init( &K ); + mbedtls_mpi_init( &T ); /* T := DE - 1 */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&T, D, E)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&T, &T, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &T, D, E ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &T, &T, 1 ) ); - if ((order = (uint16_t) mbedtls_mpi_lsb(&T)) == 0) { + if( ( order = (uint16_t) mbedtls_mpi_lsb( &T ) ) == 0 ) + { ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA; goto cleanup; } /* After this operation, T holds the largest odd divisor of DE - 1. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_shift_r(&T, order)); + MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &T, order ) ); /* * Actual work @@ -109,49 +123,49 @@ int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N, /* Skip trying 2 if N == 1 mod 8 */ attempt = 0; - if (N->p[0] % 8 == 1) { + if( N->p[0] % 8 == 1 ) attempt = 1; - } - for (; attempt < num_primes; ++attempt) { - MBEDTLS_MPI_CHK(mbedtls_mpi_lset(&K, primes[attempt])); + for( ; attempt < num_primes; ++attempt ) + { + mbedtls_mpi_lset( &K, primes[attempt] ); /* Check if gcd(K,N) = 1 */ - MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(P, &K, N)); - if (mbedtls_mpi_cmp_int(P, 1) != 0) { + MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( P, &K, N ) ); + if( mbedtls_mpi_cmp_int( P, 1 ) != 0 ) continue; - } /* Go through K^T + 1, K^(2T) + 1, K^(4T) + 1, ... * and check whether they have nontrivial GCD with N. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_exp_mod(&K, &K, &T, N, - Q /* temporarily use Q for storing Montgomery - * multiplication helper values */)); + MBEDTLS_MPI_CHK( mbedtls_mpi_exp_mod( &K, &K, &T, N, + Q /* temporarily use Q for storing Montgomery + * multiplication helper values */ ) ); - for (iter = 1; iter <= order; ++iter) { + for( iter = 1; iter <= order; ++iter ) + { /* If we reach 1 prematurely, there's no point * in continuing to square K */ - if (mbedtls_mpi_cmp_int(&K, 1) == 0) { + if( mbedtls_mpi_cmp_int( &K, 1 ) == 0 ) break; - } - MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&K, &K, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(P, &K, N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_add_int( &K, &K, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( P, &K, N ) ); - if (mbedtls_mpi_cmp_int(P, 1) == 1 && - mbedtls_mpi_cmp_mpi(P, N) == -1) { + if( mbedtls_mpi_cmp_int( P, 1 ) == 1 && + mbedtls_mpi_cmp_mpi( P, N ) == -1 ) + { /* * Have found a nontrivial divisor P of N. * Set Q := N / P. */ - MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(Q, NULL, N, P)); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( Q, NULL, N, P ) ); goto cleanup; } - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, &K, &K)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, N)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, &K, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, &K, &K ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &K, &K, N ) ); } /* @@ -161,7 +175,8 @@ int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N, * Check if that's the case and abort if not, to avoid very long, * yet eventually failing, computations if N,D,E were not sane. */ - if (mbedtls_mpi_cmp_int(&K, 1) != 0) { + if( mbedtls_mpi_cmp_int( &K, 1 ) != 0 ) + { break; } } @@ -170,103 +185,106 @@ int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N, cleanup: - mbedtls_mpi_free(&K); - mbedtls_mpi_free(&T); - return ret; + mbedtls_mpi_free( &K ); + mbedtls_mpi_free( &T ); + return( ret ); } /* * Given P, Q and the public exponent E, deduce D. * This is essentially a modular inversion. */ -int mbedtls_rsa_deduce_private_exponent(mbedtls_mpi const *P, - mbedtls_mpi const *Q, - mbedtls_mpi const *E, - mbedtls_mpi *D) +int mbedtls_rsa_deduce_private_exponent( mbedtls_mpi const *P, + mbedtls_mpi const *Q, + mbedtls_mpi const *E, + mbedtls_mpi *D ) { int ret = 0; mbedtls_mpi K, L; - if (D == NULL || mbedtls_mpi_cmp_int(D, 0) != 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; - } + if( D == NULL || mbedtls_mpi_cmp_int( D, 0 ) != 0 ) + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); - if (mbedtls_mpi_cmp_int(P, 1) <= 0 || - mbedtls_mpi_cmp_int(Q, 1) <= 0 || - mbedtls_mpi_cmp_int(E, 0) == 0) { - return MBEDTLS_ERR_MPI_BAD_INPUT_DATA; + if( mbedtls_mpi_cmp_int( P, 1 ) <= 0 || + mbedtls_mpi_cmp_int( Q, 1 ) <= 0 || + mbedtls_mpi_cmp_int( E, 0 ) == 0 ) + { + return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA ); } - mbedtls_mpi_init(&K); - mbedtls_mpi_init(&L); + mbedtls_mpi_init( &K ); + mbedtls_mpi_init( &L ); /* Temporarily put K := P-1 and L := Q-1 */ - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, P, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&L, Q, 1)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, P, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &L, Q, 1 ) ); /* Temporarily put D := gcd(P-1, Q-1) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_gcd(D, &K, &L)); + MBEDTLS_MPI_CHK( mbedtls_mpi_gcd( D, &K, &L ) ); /* K := LCM(P-1, Q-1) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, &K, &L)); - MBEDTLS_MPI_CHK(mbedtls_mpi_div_mpi(&K, NULL, &K, D)); + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, &K, &L ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_div_mpi( &K, NULL, &K, D ) ); /* Compute modular inverse of E in LCM(P-1, Q-1) */ - MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(D, E, &K)); + MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( D, E, &K ) ); cleanup: - mbedtls_mpi_free(&K); - mbedtls_mpi_free(&L); + mbedtls_mpi_free( &K ); + mbedtls_mpi_free( &L ); - return ret; + return( ret ); } -int mbedtls_rsa_deduce_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q, - const mbedtls_mpi *D, mbedtls_mpi *DP, - mbedtls_mpi *DQ, mbedtls_mpi *QP) +int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q, + const mbedtls_mpi *D, mbedtls_mpi *DP, + mbedtls_mpi *DQ, mbedtls_mpi *QP ) { int ret = 0; mbedtls_mpi K; - mbedtls_mpi_init(&K); + mbedtls_mpi_init( &K ); /* DP = D mod P-1 */ - if (DP != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, P, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(DP, D, &K)); + if( DP != NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, P, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( DP, D, &K ) ); } /* DQ = D mod Q-1 */ - if (DQ != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, Q, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(DQ, D, &K)); + if( DQ != NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, Q, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( DQ, D, &K ) ); } /* QP = Q^{-1} mod P */ - if (QP != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_inv_mod(QP, Q, P)); + if( QP != NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( QP, Q, P ) ); } cleanup: - mbedtls_mpi_free(&K); + mbedtls_mpi_free( &K ); - return ret; + return( ret ); } /* * Check that core RSA parameters are sane. */ -int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, - const mbedtls_mpi *Q, const mbedtls_mpi *D, - const mbedtls_mpi *E, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng) +int mbedtls_rsa_validate_params( const mbedtls_mpi *N, const mbedtls_mpi *P, + const mbedtls_mpi *Q, const mbedtls_mpi *D, + const mbedtls_mpi *E, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ) { int ret = 0; mbedtls_mpi K, L; - mbedtls_mpi_init(&K); - mbedtls_mpi_init(&L); + mbedtls_mpi_init( &K ); + mbedtls_mpi_init( &L ); /* * Step 1: If PRNG provided, check that P and Q are prime @@ -278,14 +296,16 @@ int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, * rate of at most 2^-100 and we are aiming for the same certainty here as * well. */ - if (f_rng != NULL && P != NULL && - (ret = mbedtls_mpi_is_prime_ext(P, 50, f_rng, p_rng)) != 0) { + if( f_rng != NULL && P != NULL && + ( ret = mbedtls_mpi_is_prime_ext( P, 50, f_rng, p_rng ) ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } - if (f_rng != NULL && Q != NULL && - (ret = mbedtls_mpi_is_prime_ext(Q, 50, f_rng, p_rng)) != 0) { + if( f_rng != NULL && Q != NULL && + ( ret = mbedtls_mpi_is_prime_ext( Q, 50, f_rng, p_rng ) ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } @@ -298,10 +318,12 @@ int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, * Step 2: Check that 1 < N = P * Q */ - if (P != NULL && Q != NULL && N != NULL) { - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, P, Q)); - if (mbedtls_mpi_cmp_int(N, 1) <= 0 || - mbedtls_mpi_cmp_mpi(&K, N) != 0) { + if( P != NULL && Q != NULL && N != NULL ) + { + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, P, Q ) ); + if( mbedtls_mpi_cmp_int( N, 1 ) <= 0 || + mbedtls_mpi_cmp_mpi( &K, N ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } @@ -311,11 +333,13 @@ int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, * Step 3: Check and 1 < D, E < N if present. */ - if (N != NULL && D != NULL && E != NULL) { - if (mbedtls_mpi_cmp_int(D, 1) <= 0 || - mbedtls_mpi_cmp_int(E, 1) <= 0 || - mbedtls_mpi_cmp_mpi(D, N) >= 0 || - mbedtls_mpi_cmp_mpi(E, N) >= 0) { + if( N != NULL && D != NULL && E != NULL ) + { + if ( mbedtls_mpi_cmp_int( D, 1 ) <= 0 || + mbedtls_mpi_cmp_int( E, 1 ) <= 0 || + mbedtls_mpi_cmp_mpi( D, N ) >= 0 || + mbedtls_mpi_cmp_mpi( E, N ) >= 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } @@ -325,29 +349,33 @@ int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, * Step 4: Check that D, E are inverse modulo P-1 and Q-1 */ - if (P != NULL && Q != NULL && D != NULL && E != NULL) { - if (mbedtls_mpi_cmp_int(P, 1) <= 0 || - mbedtls_mpi_cmp_int(Q, 1) <= 0) { + if( P != NULL && Q != NULL && D != NULL && E != NULL ) + { + if( mbedtls_mpi_cmp_int( P, 1 ) <= 0 || + mbedtls_mpi_cmp_int( Q, 1 ) <= 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } /* Compute DE-1 mod P-1 */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, D, E)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&L, P, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, &L)); - if (mbedtls_mpi_cmp_int(&K, 0) != 0) { + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, D, E ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, &K, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &L, P, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &K, &K, &L ) ); + if( mbedtls_mpi_cmp_int( &K, 0 ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } /* Compute DE-1 mod Q-1 */ - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, D, E)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&L, Q, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, &L)); - if (mbedtls_mpi_cmp_int(&K, 0) != 0) { + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, D, E ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, &K, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &L, Q, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &K, &K, &L ) ); + if( mbedtls_mpi_cmp_int( &K, 0 ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } @@ -355,75 +383,85 @@ int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, cleanup: - mbedtls_mpi_free(&K); - mbedtls_mpi_free(&L); + mbedtls_mpi_free( &K ); + mbedtls_mpi_free( &L ); /* Wrap MPI error codes by RSA check failure error code */ - if (ret != 0 && ret != MBEDTLS_ERR_RSA_KEY_CHECK_FAILED) { + if( ret != 0 && ret != MBEDTLS_ERR_RSA_KEY_CHECK_FAILED ) + { ret += MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; } - return ret; + return( ret ); } /* * Check that RSA CRT parameters are in accordance with core parameters. */ -int mbedtls_rsa_validate_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q, - const mbedtls_mpi *D, const mbedtls_mpi *DP, - const mbedtls_mpi *DQ, const mbedtls_mpi *QP) +int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q, + const mbedtls_mpi *D, const mbedtls_mpi *DP, + const mbedtls_mpi *DQ, const mbedtls_mpi *QP ) { int ret = 0; mbedtls_mpi K, L; - mbedtls_mpi_init(&K); - mbedtls_mpi_init(&L); + mbedtls_mpi_init( &K ); + mbedtls_mpi_init( &L ); /* Check that DP - D == 0 mod P - 1 */ - if (DP != NULL) { - if (P == NULL) { + if( DP != NULL ) + { + if( P == NULL ) + { ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA; goto cleanup; } - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, P, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&L, DP, D)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&L, &L, &K)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, P, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &L, DP, D ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &L, &L, &K ) ); - if (mbedtls_mpi_cmp_int(&L, 0) != 0) { + if( mbedtls_mpi_cmp_int( &L, 0 ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } } /* Check that DQ - D == 0 mod Q - 1 */ - if (DQ != NULL) { - if (Q == NULL) { + if( DQ != NULL ) + { + if( Q == NULL ) + { ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA; goto cleanup; } - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, Q, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_mpi(&L, DQ, D)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&L, &L, &K)); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, Q, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &L, DQ, D ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &L, &L, &K ) ); - if (mbedtls_mpi_cmp_int(&L, 0) != 0) { + if( mbedtls_mpi_cmp_int( &L, 0 ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } } /* Check that QP * Q - 1 == 0 mod P */ - if (QP != NULL) { - if (P == NULL || Q == NULL) { + if( QP != NULL ) + { + if( P == NULL || Q == NULL ) + { ret = MBEDTLS_ERR_RSA_BAD_INPUT_DATA; goto cleanup; } - MBEDTLS_MPI_CHK(mbedtls_mpi_mul_mpi(&K, QP, Q)); - MBEDTLS_MPI_CHK(mbedtls_mpi_sub_int(&K, &K, 1)); - MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&K, &K, P)); - if (mbedtls_mpi_cmp_int(&K, 0) != 0) { + MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( &K, QP, Q ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_sub_int( &K, &K, 1 ) ); + MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &K, &K, P ) ); + if( mbedtls_mpi_cmp_int( &K, 0 ) != 0 ) + { ret = MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; goto cleanup; } @@ -432,16 +470,17 @@ int mbedtls_rsa_validate_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q, cleanup: /* Wrap MPI error codes by RSA check failure error code */ - if (ret != 0 && + if( ret != 0 && ret != MBEDTLS_ERR_RSA_KEY_CHECK_FAILED && - ret != MBEDTLS_ERR_RSA_BAD_INPUT_DATA) { + ret != MBEDTLS_ERR_RSA_BAD_INPUT_DATA ) + { ret += MBEDTLS_ERR_RSA_KEY_CHECK_FAILED; } - mbedtls_mpi_free(&K); - mbedtls_mpi_free(&L); + mbedtls_mpi_free( &K ); + mbedtls_mpi_free( &L ); - return ret; + return( ret ); } #endif /* MBEDTLS_RSA_C */ diff --git a/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.h b/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.h index 052b02491..d6fc8e592 100644 --- a/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.h +++ b/src/duckdb/third_party/mbedtls/library/rsa_alt_helpers.h @@ -36,10 +36,24 @@ */ /* * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * */ -#ifndef MBEDTLS_RSA_ALT_HELPERS_H -#define MBEDTLS_RSA_ALT_HELPERS_H + +#ifndef MBEDTLS_RSA_INTERNAL_H +#define MBEDTLS_RSA_INTERNAL_H #include "mbedtls/build_info.h" @@ -74,9 +88,9 @@ extern "C" { * use the helper function \c mbedtls_rsa_validate_params. * */ -int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N, mbedtls_mpi const *E, - mbedtls_mpi const *D, - mbedtls_mpi *P, mbedtls_mpi *Q); +int mbedtls_rsa_deduce_primes( mbedtls_mpi const *N, mbedtls_mpi const *E, + mbedtls_mpi const *D, + mbedtls_mpi *P, mbedtls_mpi *Q ); /** * \brief Compute RSA private exponent from @@ -99,10 +113,10 @@ int mbedtls_rsa_deduce_primes(mbedtls_mpi const *N, mbedtls_mpi const *E, * \note This function does not check whether P and Q are primes. * */ -int mbedtls_rsa_deduce_private_exponent(mbedtls_mpi const *P, - mbedtls_mpi const *Q, - mbedtls_mpi const *E, - mbedtls_mpi *D); +int mbedtls_rsa_deduce_private_exponent( mbedtls_mpi const *P, + mbedtls_mpi const *Q, + mbedtls_mpi const *E, + mbedtls_mpi *D ); /** @@ -125,9 +139,9 @@ int mbedtls_rsa_deduce_private_exponent(mbedtls_mpi const *P, * prime and whether D is a valid private exponent. * */ -int mbedtls_rsa_deduce_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q, - const mbedtls_mpi *D, mbedtls_mpi *DP, - mbedtls_mpi *DQ, mbedtls_mpi *QP); +int mbedtls_rsa_deduce_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q, + const mbedtls_mpi *D, mbedtls_mpi *DP, + mbedtls_mpi *DQ, mbedtls_mpi *QP ); /** @@ -160,11 +174,11 @@ int mbedtls_rsa_deduce_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q, * to perform specific checks only. E.g., calling it with * (-,P,-,-,-) and a PRNG amounts to a primality check for P. */ -int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, - const mbedtls_mpi *Q, const mbedtls_mpi *D, - const mbedtls_mpi *E, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng); +int mbedtls_rsa_validate_params( const mbedtls_mpi *N, const mbedtls_mpi *P, + const mbedtls_mpi *Q, const mbedtls_mpi *D, + const mbedtls_mpi *E, + int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); /** * \brief Check validity of RSA CRT parameters @@ -195,9 +209,9 @@ int mbedtls_rsa_validate_params(const mbedtls_mpi *N, const mbedtls_mpi *P, * to perform specific checks only. E.g., calling it with the * parameters (P, -, D, DP, -, -) will check DP = D mod P-1. */ -int mbedtls_rsa_validate_crt(const mbedtls_mpi *P, const mbedtls_mpi *Q, - const mbedtls_mpi *D, const mbedtls_mpi *DP, - const mbedtls_mpi *DQ, const mbedtls_mpi *QP); +int mbedtls_rsa_validate_crt( const mbedtls_mpi *P, const mbedtls_mpi *Q, + const mbedtls_mpi *D, const mbedtls_mpi *DP, + const mbedtls_mpi *DQ, const mbedtls_mpi *QP ); #ifdef __cplusplus } diff --git a/src/duckdb/third_party/mbedtls/library/sha1.cpp b/src/duckdb/third_party/mbedtls/library/sha1.cpp index dacfe263f..88e47e7c7 100644 --- a/src/duckdb/third_party/mbedtls/library/sha1.cpp +++ b/src/duckdb/third_party/mbedtls/library/sha1.cpp @@ -2,7 +2,19 @@ * FIPS-180-1 compliant SHA-1 implementation * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * The SHA-1 standard was published by NIST in 1993. @@ -20,35 +32,53 @@ #include +#if defined(MBEDTLS_SELF_TEST) +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" +#else +#include +#define mbedtls_printf printf +#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ + +#define SHA1_VALIDATE_RET(cond) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA1_BAD_INPUT_DATA ) + +#define SHA1_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) #if !defined(MBEDTLS_SHA1_ALT) -void mbedtls_sha1_init(mbedtls_sha1_context *ctx) +void mbedtls_sha1_init( mbedtls_sha1_context *ctx ) { - memset(ctx, 0, sizeof(mbedtls_sha1_context)); + SHA1_VALIDATE( ctx != NULL ); + + memset( ctx, 0, sizeof( mbedtls_sha1_context ) ); } -void mbedtls_sha1_free(mbedtls_sha1_context *ctx) +void mbedtls_sha1_free( mbedtls_sha1_context *ctx ) { - if (ctx == NULL) { + if( ctx == NULL ) return; - } - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha1_context)); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha1_context ) ); } -void mbedtls_sha1_clone(mbedtls_sha1_context *dst, - const mbedtls_sha1_context *src) +void mbedtls_sha1_clone( mbedtls_sha1_context *dst, + const mbedtls_sha1_context *src ) { + SHA1_VALIDATE( dst != NULL ); + SHA1_VALIDATE( src != NULL ); + *dst = *src; } /* * SHA-1 context setup */ -int mbedtls_sha1_starts(mbedtls_sha1_context *ctx) +int mbedtls_sha1_starts( mbedtls_sha1_context *ctx ) { + SHA1_VALIDATE_RET( ctx != NULL ); + ctx->total[0] = 0; ctx->total[1] = 0; @@ -58,51 +88,55 @@ int mbedtls_sha1_starts(mbedtls_sha1_context *ctx) ctx->state[3] = 0x10325476; ctx->state[4] = 0xC3D2E1F0; - return 0; + return( 0 ); } #if !defined(MBEDTLS_SHA1_PROCESS_ALT) -int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, - const unsigned char data[64]) +int mbedtls_internal_sha1_process( mbedtls_sha1_context *ctx, + const unsigned char data[64] ) { - struct { + struct + { uint32_t temp, W[16], A, B, C, D, E; } local; - local.W[0] = MBEDTLS_GET_UINT32_BE(data, 0); - local.W[1] = MBEDTLS_GET_UINT32_BE(data, 4); - local.W[2] = MBEDTLS_GET_UINT32_BE(data, 8); - local.W[3] = MBEDTLS_GET_UINT32_BE(data, 12); - local.W[4] = MBEDTLS_GET_UINT32_BE(data, 16); - local.W[5] = MBEDTLS_GET_UINT32_BE(data, 20); - local.W[6] = MBEDTLS_GET_UINT32_BE(data, 24); - local.W[7] = MBEDTLS_GET_UINT32_BE(data, 28); - local.W[8] = MBEDTLS_GET_UINT32_BE(data, 32); - local.W[9] = MBEDTLS_GET_UINT32_BE(data, 36); - local.W[10] = MBEDTLS_GET_UINT32_BE(data, 40); - local.W[11] = MBEDTLS_GET_UINT32_BE(data, 44); - local.W[12] = MBEDTLS_GET_UINT32_BE(data, 48); - local.W[13] = MBEDTLS_GET_UINT32_BE(data, 52); - local.W[14] = MBEDTLS_GET_UINT32_BE(data, 56); - local.W[15] = MBEDTLS_GET_UINT32_BE(data, 60); - -#define S(x, n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n)))) - -#define SHA1R(t) \ + SHA1_VALIDATE_RET( ctx != NULL ); + SHA1_VALIDATE_RET( (const unsigned char *)data != NULL ); + + local.W[ 0] = MBEDTLS_GET_UINT32_BE( data, 0 ); + local.W[ 1] = MBEDTLS_GET_UINT32_BE( data, 4 ); + local.W[ 2] = MBEDTLS_GET_UINT32_BE( data, 8 ); + local.W[ 3] = MBEDTLS_GET_UINT32_BE( data, 12 ); + local.W[ 4] = MBEDTLS_GET_UINT32_BE( data, 16 ); + local.W[ 5] = MBEDTLS_GET_UINT32_BE( data, 20 ); + local.W[ 6] = MBEDTLS_GET_UINT32_BE( data, 24 ); + local.W[ 7] = MBEDTLS_GET_UINT32_BE( data, 28 ); + local.W[ 8] = MBEDTLS_GET_UINT32_BE( data, 32 ); + local.W[ 9] = MBEDTLS_GET_UINT32_BE( data, 36 ); + local.W[10] = MBEDTLS_GET_UINT32_BE( data, 40 ); + local.W[11] = MBEDTLS_GET_UINT32_BE( data, 44 ); + local.W[12] = MBEDTLS_GET_UINT32_BE( data, 48 ); + local.W[13] = MBEDTLS_GET_UINT32_BE( data, 52 ); + local.W[14] = MBEDTLS_GET_UINT32_BE( data, 56 ); + local.W[15] = MBEDTLS_GET_UINT32_BE( data, 60 ); + +#define S(x,n) (((x) << (n)) | (((x) & 0xFFFFFFFF) >> (32 - (n)))) + +#define R(t) \ ( \ - local.temp = local.W[((t) - 3) & 0x0F] ^ \ - local.W[((t) - 8) & 0x0F] ^ \ - local.W[((t) - 14) & 0x0F] ^ \ - local.W[(t) & 0x0F], \ - (local.W[(t) & 0x0F] = S(local.temp, 1)) \ + local.temp = local.W[( (t) - 3 ) & 0x0F] ^ \ + local.W[( (t) - 8 ) & 0x0F] ^ \ + local.W[( (t) - 14 ) & 0x0F] ^ \ + local.W[ (t) & 0x0F], \ + ( local.W[(t) & 0x0F] = S(local.temp,1) ) \ ) -#define SHA1P(a, b, c, d, e, x) \ +#define P(a,b,c,d,e,x) \ do \ { \ - (e) += S((a), 5) + F((b), (c), (d)) + K + (x); \ - (b) = S((b), 30); \ - } while (0) + (e) += S((a),5) + F((b),(c),(d)) + K + (x); \ + (b) = S((b),30); \ + } while( 0 ) local.A = ctx->state[0]; local.B = ctx->state[1]; @@ -110,113 +144,115 @@ int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, local.D = ctx->state[3]; local.E = ctx->state[4]; -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define F(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) #define K 0x5A827999 - SHA1P(local.A, local.B, local.C, local.D, local.E, local.W[0]); - SHA1P(local.E, local.A, local.B, local.C, local.D, local.W[1]); - SHA1P(local.D, local.E, local.A, local.B, local.C, local.W[2]); - SHA1P(local.C, local.D, local.E, local.A, local.B, local.W[3]); - SHA1P(local.B, local.C, local.D, local.E, local.A, local.W[4]); - SHA1P(local.A, local.B, local.C, local.D, local.E, local.W[5]); - SHA1P(local.E, local.A, local.B, local.C, local.D, local.W[6]); - SHA1P(local.D, local.E, local.A, local.B, local.C, local.W[7]); - SHA1P(local.C, local.D, local.E, local.A, local.B, local.W[8]); - SHA1P(local.B, local.C, local.D, local.E, local.A, local.W[9]); - SHA1P(local.A, local.B, local.C, local.D, local.E, local.W[10]); - SHA1P(local.E, local.A, local.B, local.C, local.D, local.W[11]); - SHA1P(local.D, local.E, local.A, local.B, local.C, local.W[12]); - SHA1P(local.C, local.D, local.E, local.A, local.B, local.W[13]); - SHA1P(local.B, local.C, local.D, local.E, local.A, local.W[14]); - SHA1P(local.A, local.B, local.C, local.D, local.E, local.W[15]); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(16)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(17)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(18)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(19)); + P( local.A, local.B, local.C, local.D, local.E, local.W[0] ); + P( local.E, local.A, local.B, local.C, local.D, local.W[1] ); + P( local.D, local.E, local.A, local.B, local.C, local.W[2] ); + P( local.C, local.D, local.E, local.A, local.B, local.W[3] ); + P( local.B, local.C, local.D, local.E, local.A, local.W[4] ); + P( local.A, local.B, local.C, local.D, local.E, local.W[5] ); + P( local.E, local.A, local.B, local.C, local.D, local.W[6] ); + P( local.D, local.E, local.A, local.B, local.C, local.W[7] ); + P( local.C, local.D, local.E, local.A, local.B, local.W[8] ); + P( local.B, local.C, local.D, local.E, local.A, local.W[9] ); + P( local.A, local.B, local.C, local.D, local.E, local.W[10] ); + P( local.E, local.A, local.B, local.C, local.D, local.W[11] ); + P( local.D, local.E, local.A, local.B, local.C, local.W[12] ); + P( local.C, local.D, local.E, local.A, local.B, local.W[13] ); + P( local.B, local.C, local.D, local.E, local.A, local.W[14] ); + P( local.A, local.B, local.C, local.D, local.E, local.W[15] ); + P( local.E, local.A, local.B, local.C, local.D, R(16) ); + P( local.D, local.E, local.A, local.B, local.C, R(17) ); + P( local.C, local.D, local.E, local.A, local.B, R(18) ); + P( local.B, local.C, local.D, local.E, local.A, R(19) ); #undef K #undef F -#define F(x, y, z) ((x) ^ (y) ^ (z)) +#define F(x,y,z) ((x) ^ (y) ^ (z)) #define K 0x6ED9EBA1 - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(20)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(21)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(22)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(23)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(24)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(25)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(26)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(27)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(28)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(29)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(30)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(31)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(32)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(33)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(34)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(35)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(36)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(37)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(38)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(39)); + P( local.A, local.B, local.C, local.D, local.E, R(20) ); + P( local.E, local.A, local.B, local.C, local.D, R(21) ); + P( local.D, local.E, local.A, local.B, local.C, R(22) ); + P( local.C, local.D, local.E, local.A, local.B, R(23) ); + P( local.B, local.C, local.D, local.E, local.A, R(24) ); + P( local.A, local.B, local.C, local.D, local.E, R(25) ); + P( local.E, local.A, local.B, local.C, local.D, R(26) ); + P( local.D, local.E, local.A, local.B, local.C, R(27) ); + P( local.C, local.D, local.E, local.A, local.B, R(28) ); + P( local.B, local.C, local.D, local.E, local.A, R(29) ); + P( local.A, local.B, local.C, local.D, local.E, R(30) ); + P( local.E, local.A, local.B, local.C, local.D, R(31) ); + P( local.D, local.E, local.A, local.B, local.C, R(32) ); + P( local.C, local.D, local.E, local.A, local.B, R(33) ); + P( local.B, local.C, local.D, local.E, local.A, R(34) ); + P( local.A, local.B, local.C, local.D, local.E, R(35) ); + P( local.E, local.A, local.B, local.C, local.D, R(36) ); + P( local.D, local.E, local.A, local.B, local.C, R(37) ); + P( local.C, local.D, local.E, local.A, local.B, R(38) ); + P( local.B, local.C, local.D, local.E, local.A, R(39) ); #undef K #undef F -#define F(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define F(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) #define K 0x8F1BBCDC - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(40)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(41)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(42)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(43)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(44)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(45)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(46)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(47)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(48)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(49)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(50)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(51)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(52)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(53)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(54)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(55)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(56)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(57)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(58)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(59)); + P( local.A, local.B, local.C, local.D, local.E, R(40) ); + P( local.E, local.A, local.B, local.C, local.D, R(41) ); + P( local.D, local.E, local.A, local.B, local.C, R(42) ); + P( local.C, local.D, local.E, local.A, local.B, R(43) ); + P( local.B, local.C, local.D, local.E, local.A, R(44) ); + P( local.A, local.B, local.C, local.D, local.E, R(45) ); + P( local.E, local.A, local.B, local.C, local.D, R(46) ); + P( local.D, local.E, local.A, local.B, local.C, R(47) ); + P( local.C, local.D, local.E, local.A, local.B, R(48) ); + P( local.B, local.C, local.D, local.E, local.A, R(49) ); + P( local.A, local.B, local.C, local.D, local.E, R(50) ); + P( local.E, local.A, local.B, local.C, local.D, R(51) ); + P( local.D, local.E, local.A, local.B, local.C, R(52) ); + P( local.C, local.D, local.E, local.A, local.B, R(53) ); + P( local.B, local.C, local.D, local.E, local.A, R(54) ); + P( local.A, local.B, local.C, local.D, local.E, R(55) ); + P( local.E, local.A, local.B, local.C, local.D, R(56) ); + P( local.D, local.E, local.A, local.B, local.C, R(57) ); + P( local.C, local.D, local.E, local.A, local.B, R(58) ); + P( local.B, local.C, local.D, local.E, local.A, R(59) ); #undef K #undef F -#define F(x, y, z) ((x) ^ (y) ^ (z)) +#define F(x,y,z) ((x) ^ (y) ^ (z)) #define K 0xCA62C1D6 - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(60)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(61)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(62)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(63)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(64)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(65)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(66)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(67)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(68)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(69)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(70)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(71)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(72)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(73)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(74)); - SHA1P(local.A, local.B, local.C, local.D, local.E, SHA1R(75)); - SHA1P(local.E, local.A, local.B, local.C, local.D, SHA1R(76)); - SHA1P(local.D, local.E, local.A, local.B, local.C, SHA1R(77)); - SHA1P(local.C, local.D, local.E, local.A, local.B, SHA1R(78)); - SHA1P(local.B, local.C, local.D, local.E, local.A, SHA1R(79)); + P( local.A, local.B, local.C, local.D, local.E, R(60) ); + P( local.E, local.A, local.B, local.C, local.D, R(61) ); + P( local.D, local.E, local.A, local.B, local.C, R(62) ); + P( local.C, local.D, local.E, local.A, local.B, R(63) ); + P( local.B, local.C, local.D, local.E, local.A, R(64) ); + P( local.A, local.B, local.C, local.D, local.E, R(65) ); + P( local.E, local.A, local.B, local.C, local.D, R(66) ); + P( local.D, local.E, local.A, local.B, local.C, R(67) ); + P( local.C, local.D, local.E, local.A, local.B, R(68) ); + P( local.B, local.C, local.D, local.E, local.A, R(69) ); + P( local.A, local.B, local.C, local.D, local.E, R(70) ); + P( local.E, local.A, local.B, local.C, local.D, R(71) ); + P( local.D, local.E, local.A, local.B, local.C, R(72) ); + P( local.C, local.D, local.E, local.A, local.B, R(73) ); + P( local.B, local.C, local.D, local.E, local.A, R(74) ); + P( local.A, local.B, local.C, local.D, local.E, R(75) ); + P( local.E, local.A, local.B, local.C, local.D, R(76) ); + P( local.D, local.E, local.A, local.B, local.C, R(77) ); + P( local.C, local.D, local.E, local.A, local.B, R(78) ); + P( local.B, local.C, local.D, local.E, local.A, R(79) ); #undef K #undef F +#undef R +#undef P ctx->state[0] += local.A; ctx->state[1] += local.B; @@ -225,9 +261,9 @@ int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, ctx->state[4] += local.E; /* Zeroise buffers and variables to clear sensitive data from memory. */ - mbedtls_platform_zeroize(&local, sizeof(local)); + mbedtls_platform_zeroize( &local, sizeof( local ) ); - return 0; + return( 0 ); } #endif /* !MBEDTLS_SHA1_PROCESS_ALT */ @@ -235,17 +271,19 @@ int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, /* * SHA-1 process buffer */ -int mbedtls_sha1_update(mbedtls_sha1_context *ctx, - const unsigned char *input, - size_t ilen) +int mbedtls_sha1_update( mbedtls_sha1_context *ctx, + const unsigned char *input, + size_t ilen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t fill; uint32_t left; - if (ilen == 0) { - return 0; - } + SHA1_VALIDATE_RET( ctx != NULL ); + SHA1_VALIDATE_RET( ilen == 0 || input != NULL ); + + if( ilen == 0 ) + return( 0 ); left = ctx->total[0] & 0x3F; fill = 64 - left; @@ -253,48 +291,49 @@ int mbedtls_sha1_update(mbedtls_sha1_context *ctx, ctx->total[0] += (uint32_t) ilen; ctx->total[0] &= 0xFFFFFFFF; - if (ctx->total[0] < (uint32_t) ilen) { + if( ctx->total[0] < (uint32_t) ilen ) ctx->total[1]++; - } - if (left && ilen >= fill) { - memcpy((void *) (ctx->buffer + left), input, fill); + if( left && ilen >= fill ) + { + memcpy( (void *) (ctx->buffer + left), input, fill ); - if ((ret = mbedtls_internal_sha1_process(ctx, ctx->buffer)) != 0) { - return ret; - } + if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); input += fill; ilen -= fill; left = 0; } - while (ilen >= 64) { - if ((ret = mbedtls_internal_sha1_process(ctx, input)) != 0) { - return ret; - } + while( ilen >= 64 ) + { + if( ( ret = mbedtls_internal_sha1_process( ctx, input ) ) != 0 ) + return( ret ); input += 64; ilen -= 64; } - if (ilen > 0) { - memcpy((void *) (ctx->buffer + left), input, ilen); - } + if( ilen > 0 ) + memcpy( (void *) (ctx->buffer + left), input, ilen ); - return 0; + return( 0 ); } /* * SHA-1 final digest */ -int mbedtls_sha1_finish(mbedtls_sha1_context *ctx, - unsigned char output[20]) +int mbedtls_sha1_finish( mbedtls_sha1_context *ctx, + unsigned char output[20] ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; uint32_t used; uint32_t high, low; + SHA1_VALIDATE_RET( ctx != NULL ); + SHA1_VALIDATE_RET( (unsigned char *)output != NULL ); + /* * Add padding: 0x80 then 0x00 until 8 bytes remain for the length */ @@ -302,48 +341,45 @@ int mbedtls_sha1_finish(mbedtls_sha1_context *ctx, ctx->buffer[used++] = 0x80; - if (used <= 56) { + if( used <= 56 ) + { /* Enough room for padding + length in current block */ - memset(ctx->buffer + used, 0, 56 - used); - } else { + memset( ctx->buffer + used, 0, 56 - used ); + } + else + { /* We'll need an extra block */ - memset(ctx->buffer + used, 0, 64 - used); + memset( ctx->buffer + used, 0, 64 - used ); - if ((ret = mbedtls_internal_sha1_process(ctx, ctx->buffer)) != 0) { - goto exit; - } + if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); - memset(ctx->buffer, 0, 56); + memset( ctx->buffer, 0, 56 ); } /* * Add message length */ - high = (ctx->total[0] >> 29) - | (ctx->total[1] << 3); - low = (ctx->total[0] << 3); + high = ( ctx->total[0] >> 29 ) + | ( ctx->total[1] << 3 ); + low = ( ctx->total[0] << 3 ); - MBEDTLS_PUT_UINT32_BE(high, ctx->buffer, 56); - MBEDTLS_PUT_UINT32_BE(low, ctx->buffer, 60); + MBEDTLS_PUT_UINT32_BE( high, ctx->buffer, 56 ); + MBEDTLS_PUT_UINT32_BE( low, ctx->buffer, 60 ); - if ((ret = mbedtls_internal_sha1_process(ctx, ctx->buffer)) != 0) { - goto exit; - } + if( ( ret = mbedtls_internal_sha1_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); /* * Output final state */ - MBEDTLS_PUT_UINT32_BE(ctx->state[0], output, 0); - MBEDTLS_PUT_UINT32_BE(ctx->state[1], output, 4); - MBEDTLS_PUT_UINT32_BE(ctx->state[2], output, 8); - MBEDTLS_PUT_UINT32_BE(ctx->state[3], output, 12); - MBEDTLS_PUT_UINT32_BE(ctx->state[4], output, 16); + MBEDTLS_PUT_UINT32_BE( ctx->state[0], output, 0 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[1], output, 4 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[2], output, 8 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[3], output, 12 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[4], output, 16 ); - ret = 0; - -exit: - mbedtls_sha1_free(ctx); - return ret; + return( 0 ); } #endif /* !MBEDTLS_SHA1_ALT */ @@ -351,30 +387,31 @@ int mbedtls_sha1_finish(mbedtls_sha1_context *ctx, /* * output = SHA-1( input buffer ) */ -int mbedtls_sha1(const unsigned char *input, - size_t ilen, - unsigned char output[20]) +int mbedtls_sha1( const unsigned char *input, + size_t ilen, + unsigned char output[20] ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_sha1_context ctx; - mbedtls_sha1_init(&ctx); + SHA1_VALIDATE_RET( ilen == 0 || input != NULL ); + SHA1_VALIDATE_RET( (unsigned char *)output != NULL ); - if ((ret = mbedtls_sha1_starts(&ctx)) != 0) { + mbedtls_sha1_init( &ctx ); + + if( ( ret = mbedtls_sha1_starts( &ctx ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_sha1_update(&ctx, input, ilen)) != 0) { + if( ( ret = mbedtls_sha1_update( &ctx, input, ilen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_sha1_finish(&ctx, output)) != 0) { + if( ( ret = mbedtls_sha1_finish( &ctx, output ) ) != 0 ) goto exit; - } exit: - mbedtls_sha1_free(&ctx); - return ret; + mbedtls_sha1_free( &ctx ); + + return( ret ); } #if defined(MBEDTLS_SELF_TEST) @@ -406,73 +443,71 @@ static const unsigned char sha1_test_sum[3][20] = /* * Checkup routine */ -int mbedtls_sha1_self_test(int verbose) +int mbedtls_sha1_self_test( int verbose ) { int i, j, buflen, ret = 0; unsigned char buf[1024]; unsigned char sha1sum[20]; mbedtls_sha1_context ctx; - mbedtls_sha1_init(&ctx); + mbedtls_sha1_init( &ctx ); /* * SHA-1 */ - for (i = 0; i < 3; i++) { - if (verbose != 0) { - mbedtls_printf(" SHA-1 test #%d: ", i + 1); - } + for( i = 0; i < 3; i++ ) + { + if( verbose != 0 ) + mbedtls_printf( " SHA-1 test #%d: ", i + 1 ); - if ((ret = mbedtls_sha1_starts(&ctx)) != 0) { + if( ( ret = mbedtls_sha1_starts( &ctx ) ) != 0 ) goto fail; - } - if (i == 2) { - memset(buf, 'a', buflen = 1000); + if( i == 2 ) + { + memset( buf, 'a', buflen = 1000 ); - for (j = 0; j < 1000; j++) { - ret = mbedtls_sha1_update(&ctx, buf, buflen); - if (ret != 0) { + for( j = 0; j < 1000; j++ ) + { + ret = mbedtls_sha1_update( &ctx, buf, buflen ); + if( ret != 0 ) goto fail; - } } - } else { - ret = mbedtls_sha1_update(&ctx, sha1_test_buf[i], - sha1_test_buflen[i]); - if (ret != 0) { + } + else + { + ret = mbedtls_sha1_update( &ctx, sha1_test_buf[i], + sha1_test_buflen[i] ); + if( ret != 0 ) goto fail; - } } - if ((ret = mbedtls_sha1_finish(&ctx, sha1sum)) != 0) { + if( ( ret = mbedtls_sha1_finish( &ctx, sha1sum ) ) != 0 ) goto fail; - } - if (memcmp(sha1sum, sha1_test_sum[i], 20) != 0) { + if( memcmp( sha1sum, sha1_test_sum[i], 20 ) != 0 ) + { ret = 1; goto fail; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); } - if (verbose != 0) { - mbedtls_printf("\n"); - } + if( verbose != 0 ) + mbedtls_printf( "\n" ); goto exit; fail: - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); exit: - mbedtls_sha1_free(&ctx); + mbedtls_sha1_free( &ctx ); - return ret; + return( ret ); } #endif /* MBEDTLS_SELF_TEST */ diff --git a/src/duckdb/third_party/mbedtls/library/sha256.cpp b/src/duckdb/third_party/mbedtls/library/sha256.cpp index 159acccae..c35894532 100644 --- a/src/duckdb/third_party/mbedtls/library/sha256.cpp +++ b/src/duckdb/third_party/mbedtls/library/sha256.cpp @@ -2,7 +2,19 @@ * FIPS-180-2 compliant SHA-256 implementation * * Copyright The Mbed TLS Contributors - * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * The SHA-256 Secure Hash Standard was published by NIST in 2002. @@ -10,47 +22,9 @@ * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf */ -#if defined(__clang__) && (__clang_major__ >= 4) - -/* Ideally, we would simply use MBEDTLS_ARCH_IS_ARMV8_A in the following #if, - * but that is defined by build_info.h, and we need this block to happen first. */ -#if defined(__ARM_ARCH) && (__ARM_ARCH_PROFILE == 'A') -#if __ARM_ARCH >= 8 -#define MBEDTLS_SHA256_ARCH_IS_ARMV8_A -#endif -#endif - -#if defined(MBEDTLS_SHA256_ARCH_IS_ARMV8_A) && !defined(__ARM_FEATURE_CRYPTO) -/* TODO: Re-consider above after https://reviews.llvm.org/D131064 merged. - * - * The intrinsic declaration are guarded by predefined ACLE macros in clang: - * these are normally only enabled by the -march option on the command line. - * By defining the macros ourselves we gain access to those declarations without - * requiring -march on the command line. - * - * `arm_neon.h` is included by common.h, so we put these defines - * at the top of this file, before any includes. - */ -#define __ARM_FEATURE_CRYPTO 1 -/* See: https://arm-software.github.io/acle/main/acle.html#cryptographic-extensions - * - * `__ARM_FEATURE_CRYPTO` is deprecated, but we need to continue to specify it - * for older compilers. - */ -#define __ARM_FEATURE_SHA2 1 -#define MBEDTLS_ENABLE_ARM_CRYPTO_EXTENSIONS_COMPILER_FLAG -#endif - -#endif /* defined(__clang__) && (__clang_major__ >= 4) */ - -/* Ensure that SIG_SETMASK is defined when -std=c99 is used. */ -#if !defined(_GNU_SOURCE) -#define _GNU_SOURCE -#endif - #include "common.h" -#if defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA224_C) +#if defined(MBEDTLS_SHA256_C) #include "mbedtls/sha256.h" #include "mbedtls/platform_util.h" @@ -58,214 +32,67 @@ #include +#if defined(MBEDTLS_SELF_TEST) +#if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" - -#if defined(MBEDTLS_ARCH_IS_ARMV8_A) - -# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \ - defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) -# if !defined(MBEDTLS_HAVE_NEON_INTRINSICS) -# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) -# warning "Target does not support NEON instructions" -# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT -# else -# error "Target does not support NEON instructions" -# endif -# endif -# endif - -# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \ - defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) -/* *INDENT-OFF* */ - -# if !defined(__ARM_FEATURE_CRYPTO) || defined(MBEDTLS_ENABLE_ARM_CRYPTO_EXTENSIONS_COMPILER_FLAG) -# if defined(__ARMCOMPILER_VERSION) -# if __ARMCOMPILER_VERSION <= 6090000 -# error "Must use minimum -march=armv8-a+crypto for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*" -# endif -# pragma clang attribute push (__attribute__((target("sha2"))), apply_to=function) -# define MBEDTLS_POP_TARGET_PRAGMA -# elif defined(__clang__) -# if __clang_major__ < 4 -# error "A more recent Clang is required for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*" -# endif -# pragma clang attribute push (__attribute__((target("crypto"))), apply_to=function) -# define MBEDTLS_POP_TARGET_PRAGMA -# elif defined(__GNUC__) - /* FIXME: GCC 5 claims to support Armv8 Crypto Extensions, but some - * intrinsics are missing. Missing intrinsics could be worked around. - */ -# if __GNUC__ < 6 -# error "A more recent GCC is required for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*" -# else -# pragma GCC push_options -# pragma GCC target ("arch=armv8-a+crypto") -# define MBEDTLS_POP_TARGET_PRAGMA -# endif -# else -# error "Only GCC and Clang supported for MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_*" -# endif -# endif -/* *INDENT-ON* */ - -# endif -# if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) -# if defined(__unix__) -# if defined(__linux__) -/* Our preferred method of detection is getauxval() */ -# include -/* These are not always defined via sys/auxv.h */ -# if !defined(HWCAP_SHA2) -# define HWCAP_SHA2 (1 << 6) -# endif -# if !defined(HWCAP2_SHA2) -# define HWCAP2_SHA2 (1 << 3) -# endif -# endif -/* Use SIGILL on Unix, and fall back to it on Linux */ -# include -# endif -# endif -#elif !defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) -# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY -# undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT -#endif - -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) -/* - * Capability detection code comes early, so we can disable - * MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT if no detection mechanism found - */ -#if defined(MBEDTLS_ARCH_IS_ARM64) && defined(HWCAP_SHA2) -static int mbedtls_a64_crypto_sha256_determine_support(void) -{ - return (getauxval(AT_HWCAP) & HWCAP_SHA2) ? 1 : 0; -} -#elif defined(MBEDTLS_ARCH_IS_ARM32) && defined(HWCAP2_SHA2) -static int mbedtls_a64_crypto_sha256_determine_support(void) -{ - return (getauxval(AT_HWCAP2) & HWCAP2_SHA2) ? 1 : 0; -} -#elif defined(__APPLE__) -static int mbedtls_a64_crypto_sha256_determine_support(void) -{ - return 1; -} -#elif defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#include - -static int mbedtls_a64_crypto_sha256_determine_support(void) -{ - return IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) ? - 1 : 0; -} -#elif defined(__unix__) && defined(SIG_SETMASK) -/* Detection with SIGILL, setjmp() and longjmp() */ -#include -#include - -static jmp_buf return_from_sigill; - -/* - * Armv8-A SHA256 support detection via SIGILL - */ -static void sigill_handler(int signal) -{ - (void) signal; - longjmp(return_from_sigill, 1); -} - -static int mbedtls_a64_crypto_sha256_determine_support(void) -{ - struct sigaction old_action, new_action; - - sigset_t old_mask; - if (sigprocmask(0, NULL, &old_mask)) { - return 0; - } - - sigemptyset(&new_action.sa_mask); - new_action.sa_flags = 0; - new_action.sa_handler = sigill_handler; - - sigaction(SIGILL, &new_action, &old_action); - - static int ret = 0; - - if (setjmp(return_from_sigill) == 0) { /* First return only */ - /* If this traps, we will return a second time from setjmp() with 1 */ -#if defined(MBEDTLS_ARCH_IS_ARM64) - asm volatile ("sha256h q0, q0, v0.4s" : : : "v0"); -#else - asm volatile ("sha256h.32 q0, q0, q0" : : : "q0"); -#endif - ret = 1; - } - - sigaction(SIGILL, &old_action, NULL); - sigprocmask(SIG_SETMASK, &old_mask, NULL); - - return ret; -} #else -#warning "No mechanism to detect ARMV8_CRYPTO found, using C code only" -#undef MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT -#endif /* HWCAP_SHA2, __APPLE__, __unix__ && SIG_SETMASK */ +#include +#include +#define mbedtls_printf printf +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ -#endif /* MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT */ +#define SHA256_VALIDATE_RET(cond) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA256_BAD_INPUT_DATA ) +#define SHA256_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) #if !defined(MBEDTLS_SHA256_ALT) -#define SHA256_BLOCK_SIZE 64 - -void mbedtls_sha256_init(mbedtls_sha256_context *ctx) +void mbedtls_sha256_init( mbedtls_sha256_context *ctx ) { - memset(ctx, 0, sizeof(mbedtls_sha256_context)); + SHA256_VALIDATE( ctx != NULL ); + + memset( ctx, 0, sizeof( mbedtls_sha256_context ) ); } -void mbedtls_sha256_free(mbedtls_sha256_context *ctx) +void mbedtls_sha256_free( mbedtls_sha256_context *ctx ) { - if (ctx == NULL) { + if( ctx == NULL ) return; - } - mbedtls_platform_zeroize(ctx, sizeof(mbedtls_sha256_context)); + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha256_context ) ); } -void mbedtls_sha256_clone(mbedtls_sha256_context *dst, - const mbedtls_sha256_context *src) +void mbedtls_sha256_clone( mbedtls_sha256_context *dst, + const mbedtls_sha256_context *src ) { + SHA256_VALIDATE( dst != NULL ); + SHA256_VALIDATE( src != NULL ); + *dst = *src; } /* * SHA-256 context setup */ -int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) +int mbedtls_sha256_starts( mbedtls_sha256_context *ctx, int is224 ) { -#if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C) - if (is224 != 0 && is224 != 1) { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } -#elif defined(MBEDTLS_SHA256_C) - if (is224 != 0) { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } -#else /* defined MBEDTLS_SHA224_C only */ - if (is224 == 0) { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } + SHA256_VALIDATE_RET( ctx != NULL ); + +#if defined(MBEDTLS_SHA224_C) + SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); +#else + SHA256_VALIDATE_RET( is224 == 0 ); #endif ctx->total[0] = 0; ctx->total[1] = 0; - if (is224 == 0) { -#if defined(MBEDTLS_SHA256_C) + if( is224 == 0 ) + { + /* SHA-256 */ ctx->state[0] = 0x6A09E667; ctx->state[1] = 0xBB67AE85; ctx->state[2] = 0x3C6EF372; @@ -274,9 +101,11 @@ int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) ctx->state[5] = 0x9B05688C; ctx->state[6] = 0x1F83D9AB; ctx->state[7] = 0x5BE0CD19; -#endif - } else { + } + else + { #if defined(MBEDTLS_SHA224_C) + /* SHA-224 */ ctx->state[0] = 0xC1059ED8; ctx->state[1] = 0x367CD507; ctx->state[2] = 0x3070DD17; @@ -288,11 +117,9 @@ int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224) #endif } -#if defined(MBEDTLS_SHA224_C) ctx->is224 = is224; -#endif - return 0; + return( 0 ); } #if !defined(MBEDTLS_SHA256_PROCESS_ALT) @@ -316,157 +143,17 @@ static const uint32_t K[] = 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2, }; -#endif - -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) || \ - defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) - -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) -# define mbedtls_internal_sha256_process_many_a64_crypto mbedtls_internal_sha256_process_many -# define mbedtls_internal_sha256_process_a64_crypto mbedtls_internal_sha256_process -#endif - -static size_t mbedtls_internal_sha256_process_many_a64_crypto( - mbedtls_sha256_context *ctx, const uint8_t *msg, size_t len) -{ - uint32x4_t abcd = vld1q_u32(&ctx->state[0]); - uint32x4_t efgh = vld1q_u32(&ctx->state[4]); - - size_t processed = 0; - - for (; - len >= SHA256_BLOCK_SIZE; - processed += SHA256_BLOCK_SIZE, - msg += SHA256_BLOCK_SIZE, - len -= SHA256_BLOCK_SIZE) { - uint32x4_t tmp, abcd_prev; - - uint32x4_t abcd_orig = abcd; - uint32x4_t efgh_orig = efgh; - - uint32x4_t sched0 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 0)); - uint32x4_t sched1 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 1)); - uint32x4_t sched2 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 2)); - uint32x4_t sched3 = vreinterpretq_u32_u8(vld1q_u8(msg + 16 * 3)); - -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ /* Will be true if not defined */ - /* Untested on BE */ - sched0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched0))); - sched1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched1))); - sched2 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched2))); - sched3 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(sched3))); -#endif +#define SHR(x,n) (((x) & 0xFFFFFFFF) >> (n)) +#define ROTR(x,n) (SHR(x,n) | ((x) << (32 - (n)))) - /* Rounds 0 to 3 */ - tmp = vaddq_u32(sched0, vld1q_u32(&K[0])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - - /* Rounds 4 to 7 */ - tmp = vaddq_u32(sched1, vld1q_u32(&K[4])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - - /* Rounds 8 to 11 */ - tmp = vaddq_u32(sched2, vld1q_u32(&K[8])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - - /* Rounds 12 to 15 */ - tmp = vaddq_u32(sched3, vld1q_u32(&K[12])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - - for (int t = 16; t < 64; t += 16) { - /* Rounds t to t + 3 */ - sched0 = vsha256su1q_u32(vsha256su0q_u32(sched0, sched1), sched2, sched3); - tmp = vaddq_u32(sched0, vld1q_u32(&K[t])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - - /* Rounds t + 4 to t + 7 */ - sched1 = vsha256su1q_u32(vsha256su0q_u32(sched1, sched2), sched3, sched0); - tmp = vaddq_u32(sched1, vld1q_u32(&K[t + 4])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - - /* Rounds t + 8 to t + 11 */ - sched2 = vsha256su1q_u32(vsha256su0q_u32(sched2, sched3), sched0, sched1); - tmp = vaddq_u32(sched2, vld1q_u32(&K[t + 8])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - - /* Rounds t + 12 to t + 15 */ - sched3 = vsha256su1q_u32(vsha256su0q_u32(sched3, sched0), sched1, sched2); - tmp = vaddq_u32(sched3, vld1q_u32(&K[t + 12])); - abcd_prev = abcd; - abcd = vsha256hq_u32(abcd_prev, efgh, tmp); - efgh = vsha256h2q_u32(efgh, abcd_prev, tmp); - } +#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) +#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) - abcd = vaddq_u32(abcd, abcd_orig); - efgh = vaddq_u32(efgh, efgh_orig); - } - - vst1q_u32(&ctx->state[0], abcd); - vst1q_u32(&ctx->state[4], efgh); - - return processed; -} - -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) -/* - * This function is for internal use only if we are building both C and Armv8-A - * versions, otherwise it is renamed to be the public mbedtls_internal_sha256_process() - */ -static -#endif -int mbedtls_internal_sha256_process_a64_crypto(mbedtls_sha256_context *ctx, - const unsigned char data[SHA256_BLOCK_SIZE]) -{ - return (mbedtls_internal_sha256_process_many_a64_crypto(ctx, data, - SHA256_BLOCK_SIZE) == - SHA256_BLOCK_SIZE) ? 0 : -1; -} +#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22)) +#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25)) -#endif /* MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT || MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY */ - -#if defined(MBEDTLS_POP_TARGET_PRAGMA) -#if defined(__clang__) -#pragma clang attribute pop -#elif defined(__GNUC__) -#pragma GCC pop_options -#endif -#undef MBEDTLS_POP_TARGET_PRAGMA -#endif - -#if !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) -#define mbedtls_internal_sha256_process_many_c mbedtls_internal_sha256_process_many -#define mbedtls_internal_sha256_process_c mbedtls_internal_sha256_process -#endif - - -#if !defined(MBEDTLS_SHA256_PROCESS_ALT) && \ - !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) - -#define SHR(x, n) (((x) & 0xFFFFFFFF) >> (n)) -#define ROTR(x, n) (SHR(x, n) | ((x) << (32 - (n)))) - -#define S0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) -#define S1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) - -#define S2(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) -#define S3(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) - -#define F0(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) -#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) #define R(t) \ ( \ @@ -474,45 +161,41 @@ int mbedtls_internal_sha256_process_a64_crypto(mbedtls_sha256_context *ctx, S0(local.W[(t) - 15]) + local.W[(t) - 16] \ ) -#define P(a, b, c, d, e, f, g, h, x, K) \ +#define P(a,b,c,d,e,f,g,h,x,K) \ do \ { \ - local.temp1 = (h) + S3(e) + F1((e), (f), (g)) + (K) + (x); \ - local.temp2 = S2(a) + F0((a), (b), (c)); \ + local.temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \ + local.temp2 = S2(a) + F0((a),(b),(c)); \ (d) += local.temp1; (h) = local.temp1 + local.temp2; \ - } while (0) + } while( 0 ) -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) -/* - * This function is for internal use only if we are building both C and Armv8 - * versions, otherwise it is renamed to be the public mbedtls_internal_sha256_process() - */ -static -#endif -int mbedtls_internal_sha256_process_c(mbedtls_sha256_context *ctx, - const unsigned char data[SHA256_BLOCK_SIZE]) +int mbedtls_internal_sha256_process( mbedtls_sha256_context *ctx, + const unsigned char data[64] ) { - struct { + struct + { uint32_t temp1, temp2, W[64]; uint32_t A[8]; } local; unsigned int i; - for (i = 0; i < 8; i++) { + SHA256_VALIDATE_RET( ctx != NULL ); + SHA256_VALIDATE_RET( (const unsigned char *)data != NULL ); + + for( i = 0; i < 8; i++ ) local.A[i] = ctx->state[i]; - } #if defined(MBEDTLS_SHA256_SMALLER) - for (i = 0; i < 64; i++) { - if (i < 16) { - local.W[i] = MBEDTLS_GET_UINT32_BE(data, 4 * i); - } else { - R(i); - } + for( i = 0; i < 64; i++ ) + { + if( i < 16 ) + local.W[i] = MBEDTLS_GET_UINT32_BE( data, 4 * i ); + else + R( i ); - P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], - local.A[5], local.A[6], local.A[7], local.W[i], K[i]); + P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], + local.A[5], local.A[6], local.A[7], local.W[i], K[i] ); local.temp1 = local.A[7]; local.A[7] = local.A[6]; local.A[6] = local.A[5]; local.A[5] = local.A[4]; @@ -521,189 +204,129 @@ int mbedtls_internal_sha256_process_c(mbedtls_sha256_context *ctx, local.A[0] = local.temp1; } #else /* MBEDTLS_SHA256_SMALLER */ - for (i = 0; i < 16; i++) { - local.W[i] = MBEDTLS_GET_UINT32_BE(data, 4 * i); - } - - for (i = 0; i < 16; i += 8) { - P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], - local.A[5], local.A[6], local.A[7], local.W[i+0], K[i+0]); - P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], - local.A[4], local.A[5], local.A[6], local.W[i+1], K[i+1]); - P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], - local.A[3], local.A[4], local.A[5], local.W[i+2], K[i+2]); - P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], - local.A[2], local.A[3], local.A[4], local.W[i+3], K[i+3]); - P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], - local.A[1], local.A[2], local.A[3], local.W[i+4], K[i+4]); - P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], - local.A[0], local.A[1], local.A[2], local.W[i+5], K[i+5]); - P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], - local.A[7], local.A[0], local.A[1], local.W[i+6], K[i+6]); - P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], - local.A[6], local.A[7], local.A[0], local.W[i+7], K[i+7]); - } - - for (i = 16; i < 64; i += 8) { - P(local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], - local.A[5], local.A[6], local.A[7], R(i+0), K[i+0]); - P(local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], - local.A[4], local.A[5], local.A[6], R(i+1), K[i+1]); - P(local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], - local.A[3], local.A[4], local.A[5], R(i+2), K[i+2]); - P(local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], - local.A[2], local.A[3], local.A[4], R(i+3), K[i+3]); - P(local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], - local.A[1], local.A[2], local.A[3], R(i+4), K[i+4]); - P(local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], - local.A[0], local.A[1], local.A[2], R(i+5), K[i+5]); - P(local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], - local.A[7], local.A[0], local.A[1], R(i+6), K[i+6]); - P(local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], - local.A[6], local.A[7], local.A[0], R(i+7), K[i+7]); + for( i = 0; i < 16; i++ ) + local.W[i] = MBEDTLS_GET_UINT32_BE( data, 4 * i ); + + for( i = 0; i < 16; i += 8 ) + { + P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], + local.A[5], local.A[6], local.A[7], local.W[i+0], K[i+0] ); + P( local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], + local.A[4], local.A[5], local.A[6], local.W[i+1], K[i+1] ); + P( local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], + local.A[3], local.A[4], local.A[5], local.W[i+2], K[i+2] ); + P( local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], + local.A[2], local.A[3], local.A[4], local.W[i+3], K[i+3] ); + P( local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], + local.A[1], local.A[2], local.A[3], local.W[i+4], K[i+4] ); + P( local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], + local.A[0], local.A[1], local.A[2], local.W[i+5], K[i+5] ); + P( local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], + local.A[7], local.A[0], local.A[1], local.W[i+6], K[i+6] ); + P( local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], + local.A[6], local.A[7], local.A[0], local.W[i+7], K[i+7] ); + } + + for( i = 16; i < 64; i += 8 ) + { + P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], + local.A[5], local.A[6], local.A[7], R(i+0), K[i+0] ); + P( local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], + local.A[4], local.A[5], local.A[6], R(i+1), K[i+1] ); + P( local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], + local.A[3], local.A[4], local.A[5], R(i+2), K[i+2] ); + P( local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], + local.A[2], local.A[3], local.A[4], R(i+3), K[i+3] ); + P( local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], + local.A[1], local.A[2], local.A[3], R(i+4), K[i+4] ); + P( local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], + local.A[0], local.A[1], local.A[2], R(i+5), K[i+5] ); + P( local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], + local.A[7], local.A[0], local.A[1], R(i+6), K[i+6] ); + P( local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], + local.A[6], local.A[7], local.A[0], R(i+7), K[i+7] ); } #endif /* MBEDTLS_SHA256_SMALLER */ - for (i = 0; i < 8; i++) { + for( i = 0; i < 8; i++ ) ctx->state[i] += local.A[i]; - } /* Zeroise buffers and variables to clear sensitive data from memory. */ - mbedtls_platform_zeroize(&local, sizeof(local)); - - return 0; -} - -#endif /* !MBEDTLS_SHA256_PROCESS_ALT && !MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY */ - - -#if !defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY) - -static size_t mbedtls_internal_sha256_process_many_c( - mbedtls_sha256_context *ctx, const uint8_t *data, size_t len) -{ - size_t processed = 0; - - while (len >= SHA256_BLOCK_SIZE) { - if (mbedtls_internal_sha256_process_c(ctx, data) != 0) { - return 0; - } - - data += SHA256_BLOCK_SIZE; - len -= SHA256_BLOCK_SIZE; - - processed += SHA256_BLOCK_SIZE; - } - - return processed; -} - -#endif /* !MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY */ + mbedtls_platform_zeroize( &local, sizeof( local ) ); - -#if defined(MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT) - -static int mbedtls_a64_crypto_sha256_has_support(void) -{ - static int done = 0; - static int supported = 0; - - if (!done) { - supported = mbedtls_a64_crypto_sha256_determine_support(); - done = 1; - } - - return supported; + return( 0 ); } -static size_t mbedtls_internal_sha256_process_many(mbedtls_sha256_context *ctx, - const uint8_t *msg, size_t len) -{ - if (mbedtls_a64_crypto_sha256_has_support()) { - return mbedtls_internal_sha256_process_many_a64_crypto(ctx, msg, len); - } else { - return mbedtls_internal_sha256_process_many_c(ctx, msg, len); - } -} - -int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, - const unsigned char data[SHA256_BLOCK_SIZE]) -{ - if (mbedtls_a64_crypto_sha256_has_support()) { - return mbedtls_internal_sha256_process_a64_crypto(ctx, data); - } else { - return mbedtls_internal_sha256_process_c(ctx, data); - } -} - -#endif /* MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_IF_PRESENT */ +#undef P +#undef R +#endif /* !MBEDTLS_SHA256_PROCESS_ALT */ /* * SHA-256 process buffer */ -int mbedtls_sha256_update(mbedtls_sha256_context *ctx, - const unsigned char *input, - size_t ilen) +int mbedtls_sha256_update( mbedtls_sha256_context *ctx, + const unsigned char *input, + size_t ilen ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t fill; uint32_t left; - if (ilen == 0) { - return 0; - } + SHA256_VALIDATE_RET( ctx != NULL ); + SHA256_VALIDATE_RET( ilen == 0 || input != NULL ); + + if( ilen == 0 ) + return( 0 ); left = ctx->total[0] & 0x3F; - fill = SHA256_BLOCK_SIZE - left; + fill = 64 - left; ctx->total[0] += (uint32_t) ilen; ctx->total[0] &= 0xFFFFFFFF; - if (ctx->total[0] < (uint32_t) ilen) { + if( ctx->total[0] < (uint32_t) ilen ) ctx->total[1]++; - } - if (left && ilen >= fill) { - memcpy((void *) (ctx->buffer + left), input, fill); + if( left && ilen >= fill ) + { + memcpy( (void *) (ctx->buffer + left), input, fill ); - if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) { - return ret; - } + if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); input += fill; ilen -= fill; left = 0; } - while (ilen >= SHA256_BLOCK_SIZE) { - size_t processed = - mbedtls_internal_sha256_process_many(ctx, input, ilen); - if (processed < SHA256_BLOCK_SIZE) { - return MBEDTLS_ERR_ERROR_GENERIC_ERROR; - } + while( ilen >= 64 ) + { + if( ( ret = mbedtls_internal_sha256_process( ctx, input ) ) != 0 ) + return( ret ); - input += processed; - ilen -= processed; + input += 64; + ilen -= 64; } - if (ilen > 0) { - memcpy((void *) (ctx->buffer + left), input, ilen); - } + if( ilen > 0 ) + memcpy( (void *) (ctx->buffer + left), input, ilen ); - return 0; + return( 0 ); } /* * SHA-256 final digest */ -int mbedtls_sha256_finish(mbedtls_sha256_context *ctx, - unsigned char *output) +int mbedtls_sha256_finish( mbedtls_sha256_context *ctx, + unsigned char *output ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; uint32_t used; uint32_t high, low; - int truncated = 0; + + SHA256_VALIDATE_RET( ctx != NULL ); + SHA256_VALIDATE_RET( (unsigned char *)output != NULL ); /* * Add padding: 0x80 then 0x00 until 8 bytes remain for the length @@ -712,57 +335,52 @@ int mbedtls_sha256_finish(mbedtls_sha256_context *ctx, ctx->buffer[used++] = 0x80; - if (used <= 56) { + if( used <= 56 ) + { /* Enough room for padding + length in current block */ - memset(ctx->buffer + used, 0, 56 - used); - } else { + memset( ctx->buffer + used, 0, 56 - used ); + } + else + { /* We'll need an extra block */ - memset(ctx->buffer + used, 0, SHA256_BLOCK_SIZE - used); + memset( ctx->buffer + used, 0, 64 - used ); - if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) { - goto exit; - } + if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); - memset(ctx->buffer, 0, 56); + memset( ctx->buffer, 0, 56 ); } /* * Add message length */ - high = (ctx->total[0] >> 29) - | (ctx->total[1] << 3); - low = (ctx->total[0] << 3); + high = ( ctx->total[0] >> 29 ) + | ( ctx->total[1] << 3 ); + low = ( ctx->total[0] << 3 ); - MBEDTLS_PUT_UINT32_BE(high, ctx->buffer, 56); - MBEDTLS_PUT_UINT32_BE(low, ctx->buffer, 60); + MBEDTLS_PUT_UINT32_BE( high, ctx->buffer, 56 ); + MBEDTLS_PUT_UINT32_BE( low, ctx->buffer, 60 ); - if ((ret = mbedtls_internal_sha256_process(ctx, ctx->buffer)) != 0) { - goto exit; - } + if( ( ret = mbedtls_internal_sha256_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); /* * Output final state */ - MBEDTLS_PUT_UINT32_BE(ctx->state[0], output, 0); - MBEDTLS_PUT_UINT32_BE(ctx->state[1], output, 4); - MBEDTLS_PUT_UINT32_BE(ctx->state[2], output, 8); - MBEDTLS_PUT_UINT32_BE(ctx->state[3], output, 12); - MBEDTLS_PUT_UINT32_BE(ctx->state[4], output, 16); - MBEDTLS_PUT_UINT32_BE(ctx->state[5], output, 20); - MBEDTLS_PUT_UINT32_BE(ctx->state[6], output, 24); + MBEDTLS_PUT_UINT32_BE( ctx->state[0], output, 0 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[1], output, 4 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[2], output, 8 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[3], output, 12 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[4], output, 16 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[5], output, 20 ); + MBEDTLS_PUT_UINT32_BE( ctx->state[6], output, 24 ); #if defined(MBEDTLS_SHA224_C) - truncated = ctx->is224; + if( ctx->is224 == 0 ) #endif - if (!truncated) { - MBEDTLS_PUT_UINT32_BE(ctx->state[7], output, 28); - } - - ret = 0; + MBEDTLS_PUT_UINT32_BE( ctx->state[7], output, 28 ); -exit: - mbedtls_sha256_free(ctx); - return ret; + return( 0 ); } #endif /* !MBEDTLS_SHA256_ALT */ @@ -770,72 +388,61 @@ int mbedtls_sha256_finish(mbedtls_sha256_context *ctx, /* * output = SHA-256( input buffer ) */ -int mbedtls_sha256(const unsigned char *input, - size_t ilen, - unsigned char *output, - int is224) +int mbedtls_sha256( const unsigned char *input, + size_t ilen, + unsigned char *output, + int is224 ) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; mbedtls_sha256_context ctx; -#if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C) - if (is224 != 0 && is224 != 1) { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } -#elif defined(MBEDTLS_SHA256_C) - if (is224 != 0) { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } -#else /* defined MBEDTLS_SHA224_C only */ - if (is224 == 0) { - return MBEDTLS_ERR_SHA256_BAD_INPUT_DATA; - } +#if defined(MBEDTLS_SHA224_C) + SHA256_VALIDATE_RET( is224 == 0 || is224 == 1 ); +#else + SHA256_VALIDATE_RET( is224 == 0 ); #endif - mbedtls_sha256_init(&ctx); + SHA256_VALIDATE_RET( ilen == 0 || input != NULL ); + SHA256_VALIDATE_RET( (unsigned char *)output != NULL ); + + mbedtls_sha256_init( &ctx ); - if ((ret = mbedtls_sha256_starts(&ctx, is224)) != 0) { + if( ( ret = mbedtls_sha256_starts( &ctx, is224 ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_sha256_update(&ctx, input, ilen)) != 0) { + if( ( ret = mbedtls_sha256_update( &ctx, input, ilen ) ) != 0 ) goto exit; - } - if ((ret = mbedtls_sha256_finish(&ctx, output)) != 0) { + if( ( ret = mbedtls_sha256_finish( &ctx, output ) ) != 0 ) goto exit; - } exit: - mbedtls_sha256_free(&ctx); + mbedtls_sha256_free( &ctx ); - return ret; + return( ret ); } #if defined(MBEDTLS_SELF_TEST) /* * FIPS-180-2 test vectors */ -static const unsigned char sha_test_buf[3][57] = +static const unsigned char sha256_test_buf[3][57] = { { "abc" }, { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }, { "" } }; -static const size_t sha_test_buflen[3] = +static const size_t sha256_test_buflen[3] = { 3, 56, 1000 }; -typedef const unsigned char (sha_test_sum_t)[32]; - -/* - * SHA-224 test vectors - */ -#if defined(MBEDTLS_SHA224_C) -static sha_test_sum_t sha224_test_sum[] = +static const unsigned char sha256_test_sum[6][32] = { + /* + * SHA-224 test vectors + */ { 0x23, 0x09, 0x7D, 0x22, 0x34, 0x05, 0xD8, 0x22, 0x86, 0x42, 0xA4, 0x77, 0xBD, 0xA2, 0x55, 0xB3, 0x2A, 0xAD, 0xBC, 0xE4, 0xBD, 0xA0, 0xB3, 0xF7, @@ -847,16 +454,11 @@ static sha_test_sum_t sha224_test_sum[] = { 0x20, 0x79, 0x46, 0x55, 0x98, 0x0C, 0x91, 0xD8, 0xBB, 0xB4, 0xC1, 0xEA, 0x97, 0x61, 0x8A, 0x4B, 0xF0, 0x3F, 0x42, 0x58, 0x19, 0x48, 0xB2, 0xEE, - 0x4E, 0xE7, 0xAD, 0x67 } -}; -#endif + 0x4E, 0xE7, 0xAD, 0x67 }, -/* - * SHA-256 test vectors - */ -#if defined(MBEDTLS_SHA256_C) -static sha_test_sum_t sha256_test_sum[] = -{ + /* + * SHA-256 test vectors + */ { 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, @@ -870,111 +472,89 @@ static sha_test_sum_t sha256_test_sum[] = 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E, 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 } }; -#endif /* * Checkup routine */ -static int mbedtls_sha256_common_self_test(int verbose, int is224) +int mbedtls_sha256_self_test( int verbose ) { - int i, buflen, ret = 0; + int i, j, k, buflen, ret = 0; unsigned char *buf; unsigned char sha256sum[32]; mbedtls_sha256_context ctx; -#if defined(MBEDTLS_SHA224_C) && defined(MBEDTLS_SHA256_C) - sha_test_sum_t *sha_test_sum = (is224) ? sha224_test_sum : sha256_test_sum; -#elif defined(MBEDTLS_SHA256_C) - sha_test_sum_t *sha_test_sum = sha256_test_sum; -#else - sha_test_sum_t *sha_test_sum = sha224_test_sum; -#endif + buf = mbedtls_calloc( 1024, sizeof(unsigned char) ); + if( NULL == buf ) + { + if( verbose != 0 ) + mbedtls_printf( "Buffer allocation failed\n" ); - buf = mbedtls_calloc(1024, sizeof(unsigned char)); - if (NULL == buf) { - if (verbose != 0) { - mbedtls_printf("Buffer allocation failed\n"); - } - - return 1; + return( 1 ); } - mbedtls_sha256_init(&ctx); + mbedtls_sha256_init( &ctx ); - for (i = 0; i < 3; i++) { - if (verbose != 0) { - mbedtls_printf(" SHA-%d test #%d: ", 256 - is224 * 32, i + 1); - } + for( i = 0; i < 6; i++ ) + { + j = i % 3; + k = i < 3; - if ((ret = mbedtls_sha256_starts(&ctx, is224)) != 0) { + if( verbose != 0 ) + mbedtls_printf( " SHA-%d test #%d: ", 256 - k * 32, j + 1 ); + + if( ( ret = mbedtls_sha256_starts( &ctx, k ) ) != 0 ) goto fail; - } - if (i == 2) { - memset(buf, 'a', buflen = 1000); + if( j == 2 ) + { + memset( buf, 'a', buflen = 1000 ); - for (int j = 0; j < 1000; j++) { - ret = mbedtls_sha256_update(&ctx, buf, buflen); - if (ret != 0) { + for( j = 0; j < 1000; j++ ) + { + ret = mbedtls_sha256_update( &ctx, buf, buflen ); + if( ret != 0 ) goto fail; - } } - } else { - ret = mbedtls_sha256_update(&ctx, sha_test_buf[i], - sha_test_buflen[i]); - if (ret != 0) { - goto fail; - } + } + else + { + ret = mbedtls_sha256_update( &ctx, sha256_test_buf[j], + sha256_test_buflen[j] ); + if( ret != 0 ) + goto fail; } - if ((ret = mbedtls_sha256_finish(&ctx, sha256sum)) != 0) { + if( ( ret = mbedtls_sha256_finish( &ctx, sha256sum ) ) != 0 ) goto fail; - } - if (memcmp(sha256sum, sha_test_sum[i], 32 - is224 * 4) != 0) { + if( memcmp( sha256sum, sha256_test_sum[i], 32 - k * 4 ) != 0 ) + { ret = 1; goto fail; } - if (verbose != 0) { - mbedtls_printf("passed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); } - if (verbose != 0) { - mbedtls_printf("\n"); - } + if( verbose != 0 ) + mbedtls_printf( "\n" ); goto exit; fail: - if (verbose != 0) { - mbedtls_printf("failed\n"); - } + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); exit: - mbedtls_sha256_free(&ctx); - mbedtls_free(buf); - - return ret; -} - -#if defined(MBEDTLS_SHA256_C) -int mbedtls_sha256_self_test(int verbose) -{ - return mbedtls_sha256_common_self_test(verbose, 0); -} -#endif /* MBEDTLS_SHA256_C */ + mbedtls_sha256_free( &ctx ); + mbedtls_free( buf ); -#if defined(MBEDTLS_SHA224_C) -int mbedtls_sha224_self_test(int verbose) -{ - return mbedtls_sha256_common_self_test(verbose, 1); + return( ret ); } -#endif /* MBEDTLS_SHA224_C */ #endif /* MBEDTLS_SELF_TEST */ -#endif /* MBEDTLS_SHA256_C || MBEDTLS_SHA224_C */ +#endif /* MBEDTLS_SHA256_C */ diff --git a/src/duckdb/third_party/mbedtls/library/sha512.cpp b/src/duckdb/third_party/mbedtls/library/sha512.cpp new file mode 100644 index 000000000..2b4cc547e --- /dev/null +++ b/src/duckdb/third_party/mbedtls/library/sha512.cpp @@ -0,0 +1,618 @@ +/* + * FIPS-180-2 compliant SHA-384/512 implementation + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * The SHA-512 Secure Hash Standard was published by NIST in 2002. + * + * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf + */ + +#include "common.h" + +#if defined(MBEDTLS_SHA512_C) + +#include "mbedtls/sha512.h" +#include "mbedtls/platform_util.h" +#include "mbedtls/error.h" + +#if defined(_MSC_VER) || defined(__WATCOMC__) + #define UL64(x) x##ui64 +#else + #define UL64(x) x##ULL +#endif + +#include + +#if defined(MBEDTLS_SELF_TEST) +#if defined(MBEDTLS_PLATFORM_C) +#include "mbedtls/platform.h" +#else +#include +#include +#define mbedtls_printf printf +#define mbedtls_calloc calloc +#define mbedtls_free free +#endif /* MBEDTLS_PLATFORM_C */ +#endif /* MBEDTLS_SELF_TEST */ + +#define SHA512_VALIDATE_RET(cond) \ + MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_SHA512_BAD_INPUT_DATA ) +#define SHA512_VALIDATE(cond) MBEDTLS_INTERNAL_VALIDATE( cond ) + +#if !defined(MBEDTLS_SHA512_ALT) + +#if defined(MBEDTLS_SHA512_SMALLER) +static void sha512_put_uint64_be( uint64_t n, unsigned char *b, uint8_t i ) +{ + MBEDTLS_PUT_UINT64_BE(n, b, i); +} +#else +#define sha512_put_uint64_be MBEDTLS_PUT_UINT64_BE +#endif /* MBEDTLS_SHA512_SMALLER */ + +void mbedtls_sha512_init( mbedtls_sha512_context *ctx ) +{ + SHA512_VALIDATE( ctx != NULL ); + + memset( ctx, 0, sizeof( mbedtls_sha512_context ) ); +} + +void mbedtls_sha512_free( mbedtls_sha512_context *ctx ) +{ + if( ctx == NULL ) + return; + + mbedtls_platform_zeroize( ctx, sizeof( mbedtls_sha512_context ) ); +} + +void mbedtls_sha512_clone( mbedtls_sha512_context *dst, + const mbedtls_sha512_context *src ) +{ + SHA512_VALIDATE( dst != NULL ); + SHA512_VALIDATE( src != NULL ); + + *dst = *src; +} + +/* + * SHA-512 context setup + */ +int mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 ) +{ + SHA512_VALIDATE_RET( ctx != NULL ); +#if defined(MBEDTLS_SHA384_C) + SHA512_VALIDATE_RET( is384 == 0 || is384 == 1 ); +#else + SHA512_VALIDATE_RET( is384 == 0 ); +#endif + + ctx->total[0] = 0; + ctx->total[1] = 0; + + if( is384 == 0 ) + { + /* SHA-512 */ + ctx->state[0] = UL64(0x6A09E667F3BCC908); + ctx->state[1] = UL64(0xBB67AE8584CAA73B); + ctx->state[2] = UL64(0x3C6EF372FE94F82B); + ctx->state[3] = UL64(0xA54FF53A5F1D36F1); + ctx->state[4] = UL64(0x510E527FADE682D1); + ctx->state[5] = UL64(0x9B05688C2B3E6C1F); + ctx->state[6] = UL64(0x1F83D9ABFB41BD6B); + ctx->state[7] = UL64(0x5BE0CD19137E2179); + } + else + { +#if !defined(MBEDTLS_SHA384_C) + return( MBEDTLS_ERR_SHA512_BAD_INPUT_DATA ); +#else + /* SHA-384 */ + ctx->state[0] = UL64(0xCBBB9D5DC1059ED8); + ctx->state[1] = UL64(0x629A292A367CD507); + ctx->state[2] = UL64(0x9159015A3070DD17); + ctx->state[3] = UL64(0x152FECD8F70E5939); + ctx->state[4] = UL64(0x67332667FFC00B31); + ctx->state[5] = UL64(0x8EB44A8768581511); + ctx->state[6] = UL64(0xDB0C2E0D64F98FA7); + ctx->state[7] = UL64(0x47B5481DBEFA4FA4); +#endif /* MBEDTLS_SHA384_C */ + } + +#if defined(MBEDTLS_SHA384_C) + ctx->is384 = is384; +#endif + + return( 0 ); +} + +#if !defined(MBEDTLS_SHA512_PROCESS_ALT) + +/* + * Round constants + */ +static const uint64_t K[80] = +{ + UL64(0x428A2F98D728AE22), UL64(0x7137449123EF65CD), + UL64(0xB5C0FBCFEC4D3B2F), UL64(0xE9B5DBA58189DBBC), + UL64(0x3956C25BF348B538), UL64(0x59F111F1B605D019), + UL64(0x923F82A4AF194F9B), UL64(0xAB1C5ED5DA6D8118), + UL64(0xD807AA98A3030242), UL64(0x12835B0145706FBE), + UL64(0x243185BE4EE4B28C), UL64(0x550C7DC3D5FFB4E2), + UL64(0x72BE5D74F27B896F), UL64(0x80DEB1FE3B1696B1), + UL64(0x9BDC06A725C71235), UL64(0xC19BF174CF692694), + UL64(0xE49B69C19EF14AD2), UL64(0xEFBE4786384F25E3), + UL64(0x0FC19DC68B8CD5B5), UL64(0x240CA1CC77AC9C65), + UL64(0x2DE92C6F592B0275), UL64(0x4A7484AA6EA6E483), + UL64(0x5CB0A9DCBD41FBD4), UL64(0x76F988DA831153B5), + UL64(0x983E5152EE66DFAB), UL64(0xA831C66D2DB43210), + UL64(0xB00327C898FB213F), UL64(0xBF597FC7BEEF0EE4), + UL64(0xC6E00BF33DA88FC2), UL64(0xD5A79147930AA725), + UL64(0x06CA6351E003826F), UL64(0x142929670A0E6E70), + UL64(0x27B70A8546D22FFC), UL64(0x2E1B21385C26C926), + UL64(0x4D2C6DFC5AC42AED), UL64(0x53380D139D95B3DF), + UL64(0x650A73548BAF63DE), UL64(0x766A0ABB3C77B2A8), + UL64(0x81C2C92E47EDAEE6), UL64(0x92722C851482353B), + UL64(0xA2BFE8A14CF10364), UL64(0xA81A664BBC423001), + UL64(0xC24B8B70D0F89791), UL64(0xC76C51A30654BE30), + UL64(0xD192E819D6EF5218), UL64(0xD69906245565A910), + UL64(0xF40E35855771202A), UL64(0x106AA07032BBD1B8), + UL64(0x19A4C116B8D2D0C8), UL64(0x1E376C085141AB53), + UL64(0x2748774CDF8EEB99), UL64(0x34B0BCB5E19B48A8), + UL64(0x391C0CB3C5C95A63), UL64(0x4ED8AA4AE3418ACB), + UL64(0x5B9CCA4F7763E373), UL64(0x682E6FF3D6B2B8A3), + UL64(0x748F82EE5DEFB2FC), UL64(0x78A5636F43172F60), + UL64(0x84C87814A1F0AB72), UL64(0x8CC702081A6439EC), + UL64(0x90BEFFFA23631E28), UL64(0xA4506CEBDE82BDE9), + UL64(0xBEF9A3F7B2C67915), UL64(0xC67178F2E372532B), + UL64(0xCA273ECEEA26619C), UL64(0xD186B8C721C0C207), + UL64(0xEADA7DD6CDE0EB1E), UL64(0xF57D4F7FEE6ED178), + UL64(0x06F067AA72176FBA), UL64(0x0A637DC5A2C898A6), + UL64(0x113F9804BEF90DAE), UL64(0x1B710B35131C471B), + UL64(0x28DB77F523047D84), UL64(0x32CAAB7B40C72493), + UL64(0x3C9EBE0A15C9BEBC), UL64(0x431D67C49C100D4C), + UL64(0x4CC5D4BECB3E42B6), UL64(0x597F299CFC657E2A), + UL64(0x5FCB6FAB3AD6FAEC), UL64(0x6C44198C4A475817) +}; + +int mbedtls_internal_sha512_process( mbedtls_sha512_context *ctx, + const unsigned char data[128] ) +{ + int i; + struct + { + uint64_t temp1, temp2, W[80]; + uint64_t A[8]; + } local; + + SHA512_VALIDATE_RET( ctx != NULL ); + SHA512_VALIDATE_RET( (const unsigned char *)data != NULL ); + +#define SHR(x,n) ((x) >> (n)) +#define ROTR(x,n) (SHR((x),(n)) | ((x) << (64 - (n)))) + +#define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7)) +#define S1(x) (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x, 6)) + +#define S2(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39)) +#define S3(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41)) + +#define F0(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) + +#define P(a,b,c,d,e,f,g,h,x,K) \ + do \ + { \ + local.temp1 = (h) + S3(e) + F1((e),(f),(g)) + (K) + (x); \ + local.temp2 = S2(a) + F0((a),(b),(c)); \ + (d) += local.temp1; (h) = local.temp1 + local.temp2; \ + } while( 0 ) + + for( i = 0; i < 8; i++ ) + local.A[i] = ctx->state[i]; + +#if defined(MBEDTLS_SHA512_SMALLER) + for( i = 0; i < 80; i++ ) + { + if( i < 16 ) + { + local.W[i] = MBEDTLS_GET_UINT64_BE( data, i << 3 ); + } + else + { + local.W[i] = S1(local.W[i - 2]) + local.W[i - 7] + + S0(local.W[i - 15]) + local.W[i - 16]; + } + + P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], + local.A[5], local.A[6], local.A[7], local.W[i], K[i] ); + + local.temp1 = local.A[7]; local.A[7] = local.A[6]; + local.A[6] = local.A[5]; local.A[5] = local.A[4]; + local.A[4] = local.A[3]; local.A[3] = local.A[2]; + local.A[2] = local.A[1]; local.A[1] = local.A[0]; + local.A[0] = local.temp1; + } +#else /* MBEDTLS_SHA512_SMALLER */ + for( i = 0; i < 16; i++ ) + { + local.W[i] = MBEDTLS_GET_UINT64_BE( data, i << 3 ); + } + + for( ; i < 80; i++ ) + { + local.W[i] = S1(local.W[i - 2]) + local.W[i - 7] + + S0(local.W[i - 15]) + local.W[i - 16]; + } + + i = 0; + do + { + P( local.A[0], local.A[1], local.A[2], local.A[3], local.A[4], + local.A[5], local.A[6], local.A[7], local.W[i], K[i] ); i++; + P( local.A[7], local.A[0], local.A[1], local.A[2], local.A[3], + local.A[4], local.A[5], local.A[6], local.W[i], K[i] ); i++; + P( local.A[6], local.A[7], local.A[0], local.A[1], local.A[2], + local.A[3], local.A[4], local.A[5], local.W[i], K[i] ); i++; + P( local.A[5], local.A[6], local.A[7], local.A[0], local.A[1], + local.A[2], local.A[3], local.A[4], local.W[i], K[i] ); i++; + P( local.A[4], local.A[5], local.A[6], local.A[7], local.A[0], + local.A[1], local.A[2], local.A[3], local.W[i], K[i] ); i++; + P( local.A[3], local.A[4], local.A[5], local.A[6], local.A[7], + local.A[0], local.A[1], local.A[2], local.W[i], K[i] ); i++; + P( local.A[2], local.A[3], local.A[4], local.A[5], local.A[6], + local.A[7], local.A[0], local.A[1], local.W[i], K[i] ); i++; + P( local.A[1], local.A[2], local.A[3], local.A[4], local.A[5], + local.A[6], local.A[7], local.A[0], local.W[i], K[i] ); i++; + } + while( i < 80 ); +#endif /* MBEDTLS_SHA512_SMALLER */ + + for( i = 0; i < 8; i++ ) + ctx->state[i] += local.A[i]; + + /* Zeroise buffers and variables to clear sensitive data from memory. */ + mbedtls_platform_zeroize( &local, sizeof( local ) ); + + return( 0 ); +} + +#endif /* !MBEDTLS_SHA512_PROCESS_ALT */ + +/* + * SHA-512 process buffer + */ +int mbedtls_sha512_update( mbedtls_sha512_context *ctx, + const unsigned char *input, + size_t ilen ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + size_t fill; + unsigned int left; + + SHA512_VALIDATE_RET( ctx != NULL ); + SHA512_VALIDATE_RET( ilen == 0 || input != NULL ); + + if( ilen == 0 ) + return( 0 ); + + left = (unsigned int) (ctx->total[0] & 0x7F); + fill = 128 - left; + + ctx->total[0] += (uint64_t) ilen; + + if( ctx->total[0] < (uint64_t) ilen ) + ctx->total[1]++; + + if( left && ilen >= fill ) + { + memcpy( (void *) (ctx->buffer + left), input, fill ); + + if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); + + input += fill; + ilen -= fill; + left = 0; + } + + while( ilen >= 128 ) + { + if( ( ret = mbedtls_internal_sha512_process( ctx, input ) ) != 0 ) + return( ret ); + + input += 128; + ilen -= 128; + } + + if( ilen > 0 ) + memcpy( (void *) (ctx->buffer + left), input, ilen ); + + return( 0 ); +} + +/* + * SHA-512 final digest + */ +int mbedtls_sha512_finish( mbedtls_sha512_context *ctx, + unsigned char *output ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + unsigned used; + uint64_t high, low; + + SHA512_VALIDATE_RET( ctx != NULL ); + SHA512_VALIDATE_RET( (unsigned char *)output != NULL ); + + /* + * Add padding: 0x80 then 0x00 until 16 bytes remain for the length + */ + used = ctx->total[0] & 0x7F; + + ctx->buffer[used++] = 0x80; + + if( used <= 112 ) + { + /* Enough room for padding + length in current block */ + memset( ctx->buffer + used, 0, 112 - used ); + } + else + { + /* We'll need an extra block */ + memset( ctx->buffer + used, 0, 128 - used ); + + if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); + + memset( ctx->buffer, 0, 112 ); + } + + /* + * Add message length + */ + high = ( ctx->total[0] >> 61 ) + | ( ctx->total[1] << 3 ); + low = ( ctx->total[0] << 3 ); + + sha512_put_uint64_be( high, ctx->buffer, 112 ); + sha512_put_uint64_be( low, ctx->buffer, 120 ); + + if( ( ret = mbedtls_internal_sha512_process( ctx, ctx->buffer ) ) != 0 ) + return( ret ); + + /* + * Output final state + */ + sha512_put_uint64_be( ctx->state[0], output, 0 ); + sha512_put_uint64_be( ctx->state[1], output, 8 ); + sha512_put_uint64_be( ctx->state[2], output, 16 ); + sha512_put_uint64_be( ctx->state[3], output, 24 ); + sha512_put_uint64_be( ctx->state[4], output, 32 ); + sha512_put_uint64_be( ctx->state[5], output, 40 ); + +#if defined(MBEDTLS_SHA384_C) + if( ctx->is384 == 0 ) +#endif + { + sha512_put_uint64_be( ctx->state[6], output, 48 ); + sha512_put_uint64_be( ctx->state[7], output, 56 ); + } + + return( 0 ); +} + +#endif /* !MBEDTLS_SHA512_ALT */ + +/* + * output = SHA-512( input buffer ) + */ +int mbedtls_sha512( const unsigned char *input, + size_t ilen, + unsigned char *output, + int is384 ) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + mbedtls_sha512_context ctx; + +#if defined(MBEDTLS_SHA384_C) + SHA512_VALIDATE_RET( is384 == 0 || is384 == 1 ); +#else + SHA512_VALIDATE_RET( is384 == 0 ); +#endif + SHA512_VALIDATE_RET( ilen == 0 || input != NULL ); + SHA512_VALIDATE_RET( (unsigned char *)output != NULL ); + + mbedtls_sha512_init( &ctx ); + + if( ( ret = mbedtls_sha512_starts( &ctx, is384 ) ) != 0 ) + goto exit; + + if( ( ret = mbedtls_sha512_update( &ctx, input, ilen ) ) != 0 ) + goto exit; + + if( ( ret = mbedtls_sha512_finish( &ctx, output ) ) != 0 ) + goto exit; + +exit: + mbedtls_sha512_free( &ctx ); + + return( ret ); +} + +#if defined(MBEDTLS_SELF_TEST) + +/* + * FIPS-180-2 test vectors + */ +static const unsigned char sha512_test_buf[3][113] = +{ + { "abc" }, + { "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" }, + { "" } +}; + +static const size_t sha512_test_buflen[3] = +{ + 3, 112, 1000 +}; + +static const unsigned char sha512_test_sum[][64] = +{ +#if defined(MBEDTLS_SHA384_C) + /* + * SHA-384 test vectors + */ + { 0xCB, 0x00, 0x75, 0x3F, 0x45, 0xA3, 0x5E, 0x8B, + 0xB5, 0xA0, 0x3D, 0x69, 0x9A, 0xC6, 0x50, 0x07, + 0x27, 0x2C, 0x32, 0xAB, 0x0E, 0xDE, 0xD1, 0x63, + 0x1A, 0x8B, 0x60, 0x5A, 0x43, 0xFF, 0x5B, 0xED, + 0x80, 0x86, 0x07, 0x2B, 0xA1, 0xE7, 0xCC, 0x23, + 0x58, 0xBA, 0xEC, 0xA1, 0x34, 0xC8, 0x25, 0xA7 }, + { 0x09, 0x33, 0x0C, 0x33, 0xF7, 0x11, 0x47, 0xE8, + 0x3D, 0x19, 0x2F, 0xC7, 0x82, 0xCD, 0x1B, 0x47, + 0x53, 0x11, 0x1B, 0x17, 0x3B, 0x3B, 0x05, 0xD2, + 0x2F, 0xA0, 0x80, 0x86, 0xE3, 0xB0, 0xF7, 0x12, + 0xFC, 0xC7, 0xC7, 0x1A, 0x55, 0x7E, 0x2D, 0xB9, + 0x66, 0xC3, 0xE9, 0xFA, 0x91, 0x74, 0x60, 0x39 }, + { 0x9D, 0x0E, 0x18, 0x09, 0x71, 0x64, 0x74, 0xCB, + 0x08, 0x6E, 0x83, 0x4E, 0x31, 0x0A, 0x4A, 0x1C, + 0xED, 0x14, 0x9E, 0x9C, 0x00, 0xF2, 0x48, 0x52, + 0x79, 0x72, 0xCE, 0xC5, 0x70, 0x4C, 0x2A, 0x5B, + 0x07, 0xB8, 0xB3, 0xDC, 0x38, 0xEC, 0xC4, 0xEB, + 0xAE, 0x97, 0xDD, 0xD8, 0x7F, 0x3D, 0x89, 0x85 }, +#endif /* MBEDTLS_SHA384_C */ + + /* + * SHA-512 test vectors + */ + { 0xDD, 0xAF, 0x35, 0xA1, 0x93, 0x61, 0x7A, 0xBA, + 0xCC, 0x41, 0x73, 0x49, 0xAE, 0x20, 0x41, 0x31, + 0x12, 0xE6, 0xFA, 0x4E, 0x89, 0xA9, 0x7E, 0xA2, + 0x0A, 0x9E, 0xEE, 0xE6, 0x4B, 0x55, 0xD3, 0x9A, + 0x21, 0x92, 0x99, 0x2A, 0x27, 0x4F, 0xC1, 0xA8, + 0x36, 0xBA, 0x3C, 0x23, 0xA3, 0xFE, 0xEB, 0xBD, + 0x45, 0x4D, 0x44, 0x23, 0x64, 0x3C, 0xE8, 0x0E, + 0x2A, 0x9A, 0xC9, 0x4F, 0xA5, 0x4C, 0xA4, 0x9F }, + { 0x8E, 0x95, 0x9B, 0x75, 0xDA, 0xE3, 0x13, 0xDA, + 0x8C, 0xF4, 0xF7, 0x28, 0x14, 0xFC, 0x14, 0x3F, + 0x8F, 0x77, 0x79, 0xC6, 0xEB, 0x9F, 0x7F, 0xA1, + 0x72, 0x99, 0xAE, 0xAD, 0xB6, 0x88, 0x90, 0x18, + 0x50, 0x1D, 0x28, 0x9E, 0x49, 0x00, 0xF7, 0xE4, + 0x33, 0x1B, 0x99, 0xDE, 0xC4, 0xB5, 0x43, 0x3A, + 0xC7, 0xD3, 0x29, 0xEE, 0xB6, 0xDD, 0x26, 0x54, + 0x5E, 0x96, 0xE5, 0x5B, 0x87, 0x4B, 0xE9, 0x09 }, + { 0xE7, 0x18, 0x48, 0x3D, 0x0C, 0xE7, 0x69, 0x64, + 0x4E, 0x2E, 0x42, 0xC7, 0xBC, 0x15, 0xB4, 0x63, + 0x8E, 0x1F, 0x98, 0xB1, 0x3B, 0x20, 0x44, 0x28, + 0x56, 0x32, 0xA8, 0x03, 0xAF, 0xA9, 0x73, 0xEB, + 0xDE, 0x0F, 0xF2, 0x44, 0x87, 0x7E, 0xA6, 0x0A, + 0x4C, 0xB0, 0x43, 0x2C, 0xE5, 0x77, 0xC3, 0x1B, + 0xEB, 0x00, 0x9C, 0x5C, 0x2C, 0x49, 0xAA, 0x2E, + 0x4E, 0xAD, 0xB2, 0x17, 0xAD, 0x8C, 0xC0, 0x9B } +}; + +#define ARRAY_LENGTH( a ) ( sizeof( a ) / sizeof( ( a )[0] ) ) + +/* + * Checkup routine + */ +int mbedtls_sha512_self_test( int verbose ) +{ + int i, j, k, buflen, ret = 0; + unsigned char *buf; + unsigned char sha512sum[64]; + mbedtls_sha512_context ctx; + + buf = mbedtls_calloc( 1024, sizeof(unsigned char) ); + if( NULL == buf ) + { + if( verbose != 0 ) + mbedtls_printf( "Buffer allocation failed\n" ); + + return( 1 ); + } + + mbedtls_sha512_init( &ctx ); + + for( i = 0; i < (int) ARRAY_LENGTH(sha512_test_sum); i++ ) + { + j = i % 3; +#if defined(MBEDTLS_SHA384_C) + k = i < 3; +#else + k = 0; +#endif + + if( verbose != 0 ) + mbedtls_printf( " SHA-%d test #%d: ", 512 - k * 128, j + 1 ); + + if( ( ret = mbedtls_sha512_starts( &ctx, k ) ) != 0 ) + goto fail; + + if( j == 2 ) + { + memset( buf, 'a', buflen = 1000 ); + + for( j = 0; j < 1000; j++ ) + { + ret = mbedtls_sha512_update( &ctx, buf, buflen ); + if( ret != 0 ) + goto fail; + } + } + else + { + ret = mbedtls_sha512_update( &ctx, sha512_test_buf[j], + sha512_test_buflen[j] ); + if( ret != 0 ) + goto fail; + } + + if( ( ret = mbedtls_sha512_finish( &ctx, sha512sum ) ) != 0 ) + goto fail; + + if( memcmp( sha512sum, sha512_test_sum[i], 64 - k * 16 ) != 0 ) + { + ret = 1; + goto fail; + } + + if( verbose != 0 ) + mbedtls_printf( "passed\n" ); + } + + if( verbose != 0 ) + mbedtls_printf( "\n" ); + + goto exit; + +fail: + if( verbose != 0 ) + mbedtls_printf( "failed\n" ); + +exit: + mbedtls_sha512_free( &ctx ); + mbedtls_free( buf ); + + return( ret ); +} + +#undef ARRAY_LENGTH + +#endif /* MBEDTLS_SELF_TEST */ + +#endif /* MBEDTLS_SHA512_C */ diff --git a/src/duckdb/third_party/mbedtls/mbedtls_wrapper.cpp b/src/duckdb/third_party/mbedtls/mbedtls_wrapper.cpp index a85edc28d..66bcc628c 100644 --- a/src/duckdb/third_party/mbedtls/mbedtls_wrapper.cpp +++ b/src/duckdb/third_party/mbedtls/mbedtls_wrapper.cpp @@ -4,14 +4,16 @@ #define MBEDTLS_ALLOW_PRIVATE_ACCESS #include "duckdb/common/helper.hpp" +#include "mbedtls/entropy.h" #include "mbedtls/gcm.h" -#include "mbedtls/md.h" #include "mbedtls/pk.h" #include "mbedtls/sha1.h" #include "mbedtls/sha256.h" +#ifdef MBEDTLS_NO_ENTROPY_SOURCE #include "duckdb/common/random_engine.hpp" #include "duckdb/common/types/timestamp.hpp" +#endif #include @@ -221,6 +223,7 @@ bool MbedTlsWrapper::AESGCMStateMBEDTLS::IsOpenSSL() { void MbedTlsWrapper::AESGCMStateMBEDTLS::GenerateRandomData(duckdb::data_ptr_t data, duckdb::idx_t len) { +#ifdef MBEDTLS_NO_ENTROPY_SOURCE duckdb::RandomEngine random_engine(duckdb::Timestamp::GetCurrentTimestamp().value); while (len != 0) { const auto random_integer = random_engine.NextRandomInteger(); @@ -229,6 +232,21 @@ void MbedTlsWrapper::AESGCMStateMBEDTLS::GenerateRandomData(duckdb::data_ptr_t d data += next; len -= next; } +#else + duckdb::data_t buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; + mbedtls_entropy_context entropy; + mbedtls_entropy_init(&entropy); + + while (len != 0) { + if (mbedtls_entropy_func(&entropy, buf, MBEDTLS_ENTROPY_BLOCK_SIZE) != 0) { + throw runtime_error("Unable to generate random data"); + } + const auto next = duckdb::MinValue(len, MBEDTLS_ENTROPY_BLOCK_SIZE); + memcpy(data, buf, next); + data += next; + len -= next; + } +#endif } void MbedTlsWrapper::AESGCMStateMBEDTLS::InitializeEncryption(duckdb::const_data_ptr_t iv, duckdb::idx_t iv_len, const std::string *key) { diff --git a/src/duckdb/third_party/skiplist/SkipList.h b/src/duckdb/third_party/skiplist/SkipList.h index 1b9b95381..5b015acc3 100644 --- a/src/duckdb/third_party/skiplist/SkipList.h +++ b/src/duckdb/third_party/skiplist/SkipList.h @@ -493,7 +493,7 @@ namespace duckdb_skiplistlib { const std::string &message() const { return msg; } - virtual ~Exception() noexcept {} + virtual ~Exception() throw() {} protected: std::string msg; diff --git a/src/duckdb/third_party/utf8proc/utf8proc_wrapper.cpp b/src/duckdb/third_party/utf8proc/utf8proc_wrapper.cpp index b3e766101..40db1d609 100644 --- a/src/duckdb/third_party/utf8proc/utf8proc_wrapper.cpp +++ b/src/duckdb/third_party/utf8proc/utf8proc_wrapper.cpp @@ -2,7 +2,6 @@ #include "utf8proc.hpp" #include "duckdb/common/assert.hpp" #include "duckdb/common/exception.hpp" -#include "duckdb/common/helper.hpp" using namespace std; @@ -75,43 +74,33 @@ static inline UnicodeType UTF8ExtraByteLoop(const int first_pos_seq, int utf8cha UnicodeType Utf8Proc::Analyze(const char *s, size_t len, UnicodeInvalidReason *invalid_reason, size_t *invalid_pos) { UnicodeType type = UnicodeType::ASCII; - static constexpr uint64_t MASK = 0x8080808080808080U; - for (size_t i = 0; i < len;) { - // Check 8 bytes at a time until we hit non-ASCII - for (; i + sizeof(uint64_t) <= len; i += sizeof(uint64_t)) { - if (Load(const_data_ptr_cast(s + i)) & MASK) { - break; // Non-ASCII in the next 8 bytes - } + for (size_t i = 0; i < len; i++) { + int c = (int)s[i]; + + if ((c & 0x80) == 0) { + continue; } - // Check 1 byte at a time for the next 8 bytes - const auto end = MinValue(i + sizeof(uint64_t), len); - for (; i < end; i++) { - int c = (int)s[i]; - if ((c & 0x80) == 0) { - continue; - } - int first_pos_seq = i; - - if ((c & 0xE0) == 0xC0) { - /* 2 byte sequence */ - int utf8char = c & 0x1F; - type = UTF8ExtraByteLoop<1, 0x000780>(first_pos_seq, utf8char, i, s, len, invalid_reason, invalid_pos); - } else if ((c & 0xF0) == 0xE0) { - /* 3 byte sequence */ - int utf8char = c & 0x0F; - type = UTF8ExtraByteLoop<2, 0x00F800>(first_pos_seq, utf8char, i, s, len, invalid_reason, invalid_pos); - } else if ((c & 0xF8) == 0xF0) { - /* 4 byte sequence */ - int utf8char = c & 0x07; - type = UTF8ExtraByteLoop<3, 0x1F0000>(first_pos_seq, utf8char, i, s, len, invalid_reason, invalid_pos); - } else { - /* invalid UTF-8 start byte */ - AssignInvalidUTF8Reason(invalid_reason, invalid_pos, i, UnicodeInvalidReason::BYTE_MISMATCH); - return UnicodeType::INVALID; - } - if (type == UnicodeType::INVALID) { - return type; - } + int first_pos_seq = i; + + if ((c & 0xE0) == 0xC0) { + /* 2 byte sequence */ + int utf8char = c & 0x1F; + type = UTF8ExtraByteLoop<1, 0x000780>(first_pos_seq, utf8char, i, s, len, invalid_reason, invalid_pos); + } else if ((c & 0xF0) == 0xE0) { + /* 3 byte sequence */ + int utf8char = c & 0x0F; + type = UTF8ExtraByteLoop<2, 0x00F800>(first_pos_seq, utf8char, i, s, len, invalid_reason, invalid_pos); + } else if ((c & 0xF8) == 0xF0) { + /* 4 byte sequence */ + int utf8char = c & 0x07; + type = UTF8ExtraByteLoop<3, 0x1F0000>(first_pos_seq, utf8char, i, s, len, invalid_reason, invalid_pos); + } else { + /* invalid UTF-8 start byte */ + AssignInvalidUTF8Reason(invalid_reason, invalid_pos, i, UnicodeInvalidReason::BYTE_MISMATCH); + return UnicodeType::INVALID; + } + if (type == UnicodeType::INVALID) { + return type; } } return type; diff --git a/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp b/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp index 2e06816e0..1dda62f9f 100644 --- a/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +++ b/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp @@ -348,17 +348,17 @@ #include "extension/icu/third_party/icu/i18n/wintzimpl.cpp" -#include "extension/icu/third_party/icu/i18n/double-conversion-double-to-string.cpp" +#include "extension/icu/third_party/icu/i18n/double-conversion-cached-powers.cpp" -#include "extension/icu/third_party/icu/i18n/double-conversion-strtod.cpp" +#include "extension/icu/third_party/icu/i18n/double-conversion-string-to-double.cpp" -#include "extension/icu/third_party/icu/i18n/double-conversion-fast-dtoa.cpp" +#include "extension/icu/third_party/icu/i18n/double-conversion-double-to-string.cpp" #include "extension/icu/third_party/icu/i18n/double-conversion-bignum-dtoa.cpp" -#include "extension/icu/third_party/icu/i18n/double-conversion-string-to-double.cpp" +#include "extension/icu/third_party/icu/i18n/double-conversion-strtod.cpp" #include "extension/icu/third_party/icu/i18n/double-conversion-bignum.cpp" -#include "extension/icu/third_party/icu/i18n/double-conversion-cached-powers.cpp" +#include "extension/icu/third_party/icu/i18n/double-conversion-fast-dtoa.cpp" diff --git a/src/duckdb/ub_src_catalog.cpp b/src/duckdb/ub_src_catalog.cpp index 91d1c54e1..5578f46ab 100644 --- a/src/duckdb/ub_src_catalog.cpp +++ b/src/duckdb/ub_src_catalog.cpp @@ -18,7 +18,5 @@ #include "src/catalog/dependency_catalog_set.cpp" -#include "src/catalog/entry_lookup_info.cpp" - #include "src/catalog/similar_catalog_entry.cpp" diff --git a/src/duckdb/ub_src_common.cpp b/src/duckdb/ub_src_common.cpp index bf89076d5..2632a1276 100644 --- a/src/duckdb/ub_src_common.cpp +++ b/src/duckdb/ub_src_common.cpp @@ -8,8 +8,6 @@ #include "src/common/cgroups.cpp" -#include "src/common/complex_json.cpp" - #include "src/common/compressed_file_system.cpp" #include "src/common/constants.cpp" @@ -42,6 +40,10 @@ #include "src/common/local_file_system.cpp" +#include "src/common/multi_file_list.cpp" + +#include "src/common/multi_file_reader.cpp" + #include "src/common/error_data.cpp" #include "src/common/opener_file_system.cpp" diff --git a/src/duckdb/ub_src_execution_operator_csv_scanner_sniffer.cpp b/src/duckdb/ub_src_execution_operator_csv_scanner_sniffer.cpp index bec557689..61cfd4912 100644 --- a/src/duckdb/ub_src_execution_operator_csv_scanner_sniffer.cpp +++ b/src/duckdb/ub_src_execution_operator_csv_scanner_sniffer.cpp @@ -4,8 +4,6 @@ #include "src/execution/operator/csv_scanner/sniffer/header_detection.cpp" -#include "src/execution/operator/csv_scanner/sniffer/set_columns.cpp" - #include "src/execution/operator/csv_scanner/sniffer/type_detection.cpp" #include "src/execution/operator/csv_scanner/sniffer/type_refinement.cpp" diff --git a/src/duckdb/ub_src_execution_operator_csv_scanner_table_function.cpp b/src/duckdb/ub_src_execution_operator_csv_scanner_table_function.cpp index fc6dd3009..b5215a21d 100644 --- a/src/duckdb/ub_src_execution_operator_csv_scanner_table_function.cpp +++ b/src/duckdb/ub_src_execution_operator_csv_scanner_table_function.cpp @@ -2,5 +2,3 @@ #include "src/execution/operator/csv_scanner/table_function/global_csv_state.cpp" -#include "src/execution/operator/csv_scanner/table_function/csv_multi_file_info.cpp" - diff --git a/src/duckdb/ub_src_function_cast.cpp b/src/duckdb/ub_src_function_cast.cpp index c0e6544cf..2be5a82fd 100644 --- a/src/duckdb/ub_src_function_cast.cpp +++ b/src/duckdb/ub_src_function_cast.cpp @@ -32,7 +32,5 @@ #include "src/function/cast/varint_casts.cpp" -#include "src/function/cast/nested_to_varchar_cast.cpp" - #include "src/function/cast/vector_cast_helpers.cpp" diff --git a/src/duckdb/ub_src_function_scalar_struct.cpp b/src/duckdb/ub_src_function_scalar_struct.cpp index 1668111a0..67f447661 100644 --- a/src/duckdb/ub_src_function_scalar_struct.cpp +++ b/src/duckdb/ub_src_function_scalar_struct.cpp @@ -1,5 +1,3 @@ -#include "src/function/scalar/struct/remap_struct.cpp" - #include "src/function/scalar/struct/struct_extract.cpp" #include "src/function/scalar/struct/struct_pack.cpp" diff --git a/src/duckdb/ub_src_function_scalar_system.cpp b/src/duckdb/ub_src_function_scalar_system.cpp index cb4c47ed8..98eac32ca 100644 --- a/src/duckdb/ub_src_function_scalar_system.cpp +++ b/src/duckdb/ub_src_function_scalar_system.cpp @@ -2,9 +2,3 @@ #include "src/function/scalar/system/write_log.cpp" -#include "src/function/scalar/system/current_transaction_id.cpp" - -#include "src/function/scalar/system/current_connection_id.cpp" - -#include "src/function/scalar/system/current_query_id.cpp" - diff --git a/src/duckdb/ub_src_function_table_system.cpp b/src/duckdb/ub_src_function_table_system.cpp index e14831cdb..3204515dd 100644 --- a/src/duckdb/ub_src_function_table_system.cpp +++ b/src/duckdb/ub_src_function_table_system.cpp @@ -26,8 +26,6 @@ #include "src/function/table/system/duckdb_secrets.cpp" -#include "src/function/table/system/duckdb_prepared_statements.cpp" - #include "src/function/table/system/duckdb_which_secret.cpp" #include "src/function/table/system/duckdb_secret_types.cpp" diff --git a/src/duckdb/ub_src_parser_tableref.cpp b/src/duckdb/ub_src_parser_tableref.cpp index b3033b098..56aab8800 100644 --- a/src/duckdb/ub_src_parser_tableref.cpp +++ b/src/duckdb/ub_src_parser_tableref.cpp @@ -1,5 +1,3 @@ -#include "src/parser/tableref/at_clause.cpp" - #include "src/parser/tableref/basetableref.cpp" #include "src/parser/tableref/delimgetref.cpp" diff --git a/src/duckdb/ub_src_planner.cpp b/src/duckdb/ub_src_planner.cpp index 159c3d4ec..450ea623c 100644 --- a/src/duckdb/ub_src_planner.cpp +++ b/src/duckdb/ub_src_planner.cpp @@ -30,5 +30,3 @@ #include "src/planner/table_filter.cpp" -#include "src/planner/table_filter_state.cpp" -