duckdb 0.10.2-dev0.0 → 0.10.2-dev5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (700) hide show
  1. package/binding.gyp +22 -18
  2. package/binding.gyp.in +3 -0
  3. package/package.json +1 -1
  4. package/src/duckdb/extension/icu/icu-timezone.cpp +3 -1
  5. package/src/duckdb/extension/icu/icu_extension.cpp +6 -2
  6. package/src/duckdb/extension/json/buffered_json_reader.cpp +10 -3
  7. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +2 -0
  8. package/src/duckdb/extension/json/include/json_scan.hpp +13 -7
  9. package/src/duckdb/extension/json/include/json_serializer.hpp +5 -4
  10. package/src/duckdb/extension/json/include/json_structure.hpp +3 -3
  11. package/src/duckdb/extension/json/json_functions/json_serialize_plan.cpp +15 -5
  12. package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +15 -6
  13. package/src/duckdb/extension/json/json_functions/json_structure.cpp +21 -20
  14. package/src/duckdb/extension/json/json_functions/read_json.cpp +37 -3
  15. package/src/duckdb/extension/json/json_functions.cpp +7 -2
  16. package/src/duckdb/extension/json/json_scan.cpp +57 -33
  17. package/src/duckdb/extension/parquet/column_reader.cpp +12 -3
  18. package/src/duckdb/extension/parquet/column_writer.cpp +44 -7
  19. package/src/duckdb/extension/parquet/include/parquet_writer.hpp +5 -1
  20. package/src/duckdb/extension/parquet/parquet_extension.cpp +30 -3
  21. package/src/duckdb/extension/parquet/parquet_metadata.cpp +1 -1
  22. package/src/duckdb/extension/parquet/parquet_writer.cpp +4 -2
  23. package/src/duckdb/extension/parquet/zstd_file_system.cpp +1 -1
  24. package/src/duckdb/src/catalog/catalog.cpp +5 -1
  25. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +21 -5
  26. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +8 -9
  27. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +3 -7
  28. package/src/duckdb/src/catalog/catalog_entry/sequence_catalog_entry.cpp +1 -1
  29. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +6 -7
  30. package/src/duckdb/src/catalog/catalog_entry.cpp +8 -0
  31. package/src/duckdb/src/catalog/catalog_search_path.cpp +5 -0
  32. package/src/duckdb/src/catalog/catalog_set.cpp +2 -2
  33. package/src/duckdb/src/catalog/default/default_functions.cpp +6 -6
  34. package/src/duckdb/src/catalog/default/default_schemas.cpp +1 -1
  35. package/src/duckdb/src/catalog/default/default_views.cpp +7 -7
  36. package/src/duckdb/src/catalog/dependency_catalog_set.cpp +2 -1
  37. package/src/duckdb/src/catalog/dependency_list.cpp +92 -8
  38. package/src/duckdb/src/catalog/dependency_manager.cpp +53 -68
  39. package/src/duckdb/src/catalog/duck_catalog.cpp +1 -1
  40. package/src/duckdb/src/common/adbc/adbc.cpp +287 -45
  41. package/src/duckdb/src/common/arrow/appender/union_data.cpp +2 -2
  42. package/src/duckdb/src/common/box_renderer.cpp +12 -12
  43. package/src/duckdb/src/common/crypto/md5.cpp +2 -1
  44. package/src/duckdb/src/common/enum_util.cpp +307 -1
  45. package/src/duckdb/src/common/enums/expression_type.cpp +4 -0
  46. package/src/duckdb/src/common/enums/optimizer_type.cpp +1 -1
  47. package/src/duckdb/src/common/file_system.cpp +60 -13
  48. package/src/duckdb/src/common/filename_pattern.cpp +13 -13
  49. package/src/duckdb/src/common/gzip_file_system.cpp +1 -1
  50. package/src/duckdb/src/common/http_state.cpp +1 -1
  51. package/src/duckdb/src/common/local_file_system.cpp +72 -71
  52. package/src/duckdb/src/common/multi_file_reader.cpp +48 -28
  53. package/src/duckdb/src/common/row_operations/row_matcher.cpp +2 -2
  54. package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +13 -1
  55. package/src/duckdb/src/common/serializer/buffered_file_writer.cpp +32 -13
  56. package/src/duckdb/src/common/string_util.cpp +2 -3
  57. package/src/duckdb/src/common/tree_renderer.cpp +32 -67
  58. package/src/duckdb/src/common/types/bit.cpp +6 -6
  59. package/src/duckdb/src/common/types/data_chunk.cpp +2 -2
  60. package/src/duckdb/src/common/types/hash.cpp +6 -6
  61. package/src/duckdb/src/common/types/hyperloglog.cpp +2 -0
  62. package/src/duckdb/src/common/types/row/tuple_data_allocator.cpp +13 -0
  63. package/src/duckdb/src/common/types/row/tuple_data_layout.cpp +5 -7
  64. package/src/duckdb/src/common/types/uuid.cpp +1 -1
  65. package/src/duckdb/src/common/types/vector.cpp +22 -14
  66. package/src/duckdb/src/common/types.cpp +8 -1
  67. package/src/duckdb/src/common/vector_operations/comparison_operators.cpp +20 -18
  68. package/src/duckdb/src/common/vector_operations/generators.cpp +1 -1
  69. package/src/duckdb/src/common/vector_operations/is_distinct_from.cpp +267 -110
  70. package/src/duckdb/src/common/vector_operations/vector_hash.cpp +52 -23
  71. package/src/duckdb/src/common/virtual_file_system.cpp +33 -20
  72. package/src/duckdb/src/core_functions/aggregate/algebraic/avg.cpp +2 -2
  73. package/src/duckdb/src/core_functions/aggregate/distributive/minmax.cpp +3 -3
  74. package/src/duckdb/src/core_functions/aggregate/distributive/sum.cpp +31 -16
  75. package/src/duckdb/src/core_functions/aggregate/holistic/quantile.cpp +3 -0
  76. package/src/duckdb/src/core_functions/aggregate/nested/list.cpp +2 -0
  77. package/src/duckdb/src/core_functions/core_functions.cpp +1 -1
  78. package/src/duckdb/src/core_functions/function_list.cpp +2 -2
  79. package/src/duckdb/src/core_functions/scalar/date/time_bucket.cpp +1 -1
  80. package/src/duckdb/src/core_functions/scalar/generic/system_functions.cpp +46 -17
  81. package/src/duckdb/src/core_functions/scalar/list/array_slice.cpp +1 -1
  82. package/src/duckdb/src/core_functions/scalar/list/flatten.cpp +82 -45
  83. package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +2 -2
  84. package/src/duckdb/src/core_functions/scalar/list/list_sort.cpp +3 -0
  85. package/src/duckdb/src/core_functions/scalar/math/numeric.cpp +3 -2
  86. package/src/duckdb/src/core_functions/scalar/string/hex.cpp +2 -4
  87. package/src/duckdb/src/core_functions/scalar/string/repeat.cpp +12 -21
  88. package/src/duckdb/src/execution/column_binding_resolver.cpp +2 -10
  89. package/src/duckdb/src/execution/expression_executor/execute_comparison.cpp +133 -66
  90. package/src/duckdb/src/execution/expression_executor/execute_function.cpp +0 -2
  91. package/src/duckdb/src/execution/expression_executor.cpp +0 -4
  92. package/src/duckdb/src/execution/expression_executor_state.cpp +1 -1
  93. package/src/duckdb/src/execution/index/art/art.cpp +2 -2
  94. package/src/duckdb/src/execution/index/unknown_index.cpp +13 -13
  95. package/src/duckdb/src/execution/join_hashtable.cpp +1 -1
  96. package/src/duckdb/src/execution/nested_loop_join/nested_loop_join_mark.cpp +0 -1
  97. package/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer.cpp +10 -7
  98. package/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer_manager.cpp +32 -1
  99. package/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_file_handle.cpp +16 -2
  100. package/src/duckdb/src/execution/operator/csv_scanner/scanner/scanner_boundary.cpp +7 -7
  101. package/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp +354 -159
  102. package/src/duckdb/src/execution/operator/csv_scanner/sniffer/csv_sniffer.cpp +11 -2
  103. package/src/duckdb/src/execution/operator/csv_scanner/sniffer/dialect_detection.cpp +22 -7
  104. package/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_detection.cpp +1 -1
  105. package/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.cpp +10 -10
  106. package/src/duckdb/src/execution/operator/csv_scanner/table_function/csv_file_scanner.cpp +9 -18
  107. package/src/duckdb/src/execution/operator/csv_scanner/table_function/global_csv_state.cpp +180 -47
  108. package/src/duckdb/src/execution/operator/csv_scanner/util/csv_error.cpp +100 -58
  109. package/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp +88 -21
  110. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +12 -13
  111. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +2 -0
  112. package/src/duckdb/src/execution/operator/persistent/csv_rejects_table.cpp +118 -23
  113. package/src/duckdb/src/execution/operator/persistent/physical_batch_copy_to_file.cpp +2 -2
  114. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +14 -5
  115. package/src/duckdb/src/execution/operator/persistent/physical_copy_database.cpp +1 -1
  116. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +5 -5
  117. package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +1 -1
  118. package/src/duckdb/src/execution/physical_plan/plan_simple.cpp +0 -9
  119. package/src/duckdb/src/execution/physical_plan/plan_vacuum.cpp +18 -0
  120. package/src/duckdb/src/execution/physical_plan_generator.cpp +5 -3
  121. package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +81 -106
  122. package/src/duckdb/src/execution/reservoir_sample.cpp +1 -1
  123. package/src/duckdb/src/execution/window_executor.cpp +48 -28
  124. package/src/duckdb/src/execution/window_segment_tree.cpp +20 -23
  125. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +1 -1
  126. package/src/duckdb/src/function/cast/enum_casts.cpp +20 -55
  127. package/src/duckdb/src/function/cast/vector_cast_helpers.cpp +10 -9
  128. package/src/duckdb/src/function/cast_rules.cpp +9 -1
  129. package/src/duckdb/src/function/compression_config.cpp +1 -1
  130. package/src/duckdb/src/function/function_binder.cpp +45 -44
  131. package/src/duckdb/src/function/function_set.cpp +9 -9
  132. package/src/duckdb/src/function/pragma/pragma_queries.cpp +1 -2
  133. package/src/duckdb/src/function/scalar/compressed_materialization/compress_integral.cpp +21 -5
  134. package/src/duckdb/src/function/scalar/compressed_materialization/compress_string.cpp +2 -2
  135. package/src/duckdb/src/function/scalar/list/list_select.cpp +5 -2
  136. package/src/duckdb/src/function/scalar/list/list_zip.cpp +5 -4
  137. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +60 -32
  138. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +1 -1
  139. package/src/duckdb/src/function/scalar/strftime_format.cpp +31 -25
  140. package/src/duckdb/src/function/scalar/string/caseconvert.cpp +6 -6
  141. package/src/duckdb/src/function/scalar/string/length.cpp +23 -2
  142. package/src/duckdb/src/function/scalar/string/like.cpp +1 -1
  143. package/src/duckdb/src/function/scalar/string/regexp/regexp_extract_all.cpp +1 -1
  144. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +3 -3
  145. package/src/duckdb/src/function/table/arrow/arrow_array_scan_state.cpp +1 -1
  146. package/src/duckdb/src/function/table/arrow.cpp +7 -1
  147. package/src/duckdb/src/function/table/copy_csv.cpp +17 -13
  148. package/src/duckdb/src/function/table/read_csv.cpp +52 -39
  149. package/src/duckdb/src/function/table/sniff_csv.cpp +7 -13
  150. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +1 -1
  151. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +7 -1
  152. package/src/duckdb/src/function/table/system/duckdb_extensions.cpp +12 -2
  153. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +1 -2
  154. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +2 -2
  155. package/src/duckdb/src/function/table/system/pragma_metadata_info.cpp +9 -2
  156. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +10 -6
  157. package/src/duckdb/src/function/table/table_scan.cpp +1 -4
  158. package/src/duckdb/src/function/table/version/pragma_version.cpp +3 -3
  159. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +6 -2
  160. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  161. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +1 -1
  162. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +1 -1
  163. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +6 -1
  164. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +3 -3
  165. package/src/duckdb/src/include/duckdb/catalog/default/default_functions.hpp +3 -3
  166. package/src/duckdb/src/include/duckdb/catalog/dependency.hpp +26 -4
  167. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +39 -6
  168. package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +19 -14
  169. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +1 -1
  170. package/src/duckdb/src/include/duckdb/catalog/standard_entry.hpp +4 -0
  171. package/src/duckdb/src/include/duckdb/common/allocator.hpp +3 -3
  172. package/src/duckdb/src/include/duckdb/common/arrow/arrow_wrapper.hpp +1 -1
  173. package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +1 -1
  174. package/src/duckdb/src/include/duckdb/common/box_renderer.hpp +16 -16
  175. package/src/duckdb/src/include/duckdb/common/crypto/md5.hpp +0 -1
  176. package/src/duckdb/src/include/duckdb/common/enum_util.hpp +32 -0
  177. package/src/duckdb/src/include/duckdb/common/enums/expression_type.hpp +4 -2
  178. package/src/duckdb/src/include/duckdb/common/exception/binder_exception.hpp +14 -10
  179. package/src/duckdb/src/include/duckdb/common/exception/catalog_exception.hpp +4 -4
  180. package/src/duckdb/src/include/duckdb/common/exception/conversion_exception.hpp +6 -6
  181. package/src/duckdb/src/include/duckdb/common/exception/http_exception.hpp +3 -3
  182. package/src/duckdb/src/include/duckdb/common/exception/parser_exception.hpp +4 -4
  183. package/src/duckdb/src/include/duckdb/common/exception/transaction_exception.hpp +2 -2
  184. package/src/duckdb/src/include/duckdb/common/exception.hpp +57 -58
  185. package/src/duckdb/src/include/duckdb/common/exception_format_value.hpp +2 -2
  186. package/src/duckdb/src/include/duckdb/common/extra_type_info.hpp +2 -2
  187. package/src/duckdb/src/include/duckdb/common/file_open_flags.hpp +134 -0
  188. package/src/duckdb/src/include/duckdb/common/file_opener.hpp +9 -6
  189. package/src/duckdb/src/include/duckdb/common/file_system.hpp +35 -36
  190. package/src/duckdb/src/include/duckdb/common/filename_pattern.hpp +4 -6
  191. package/src/duckdb/src/include/duckdb/common/fixed_size_map.hpp +13 -13
  192. package/src/duckdb/src/include/duckdb/common/helper.hpp +42 -47
  193. package/src/duckdb/src/include/duckdb/common/http_state.hpp +1 -1
  194. package/src/duckdb/src/include/duckdb/common/hugeint.hpp +2 -2
  195. package/src/duckdb/src/include/duckdb/common/index_vector.hpp +10 -10
  196. package/src/duckdb/src/include/duckdb/common/local_file_system.hpp +13 -10
  197. package/src/duckdb/src/include/duckdb/common/memory_safety.hpp +3 -3
  198. package/src/duckdb/src/include/duckdb/common/multi_file_reader_options.hpp +1 -1
  199. package/src/duckdb/src/include/duckdb/common/opener_file_system.hpp +50 -24
  200. package/src/duckdb/src/include/duckdb/common/operator/abs.hpp +12 -4
  201. package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +5 -5
  202. package/src/duckdb/src/include/duckdb/common/pipe_file_system.hpp +1 -1
  203. package/src/duckdb/src/include/duckdb/common/platform.h +1 -1
  204. package/src/duckdb/src/include/duckdb/common/printer.hpp +5 -5
  205. package/src/duckdb/src/include/duckdb/common/profiler.hpp +2 -2
  206. package/src/duckdb/src/include/duckdb/common/progress_bar/display/terminal_progress_bar_display.hpp +5 -5
  207. package/src/duckdb/src/include/duckdb/common/random_engine.hpp +1 -1
  208. package/src/duckdb/src/include/duckdb/common/re2_regex.hpp +7 -7
  209. package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +3 -0
  210. package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_writer.hpp +2 -2
  211. package/src/duckdb/src/include/duckdb/common/serializer/deserialization_data.hpp +17 -6
  212. package/src/duckdb/src/include/duckdb/common/serializer/deserializer.hpp +12 -0
  213. package/src/duckdb/src/include/duckdb/common/serializer/serialization_traits.hpp +14 -0
  214. package/src/duckdb/src/include/duckdb/common/serializer/serializer.hpp +16 -0
  215. package/src/duckdb/src/include/duckdb/common/sort/duckdb_pdqsort.hpp +3 -0
  216. package/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp +2 -0
  217. package/src/duckdb/src/include/duckdb/common/string_util.hpp +4 -4
  218. package/src/duckdb/src/include/duckdb/common/tree_renderer.hpp +24 -25
  219. package/src/duckdb/src/include/duckdb/common/typedefs.hpp +5 -5
  220. package/src/duckdb/src/include/duckdb/common/types/cast_helpers.hpp +1 -2
  221. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection.hpp +10 -10
  222. package/src/duckdb/src/include/duckdb/common/types/column/column_data_collection_iterators.hpp +5 -5
  223. package/src/duckdb/src/include/duckdb/common/types/column/partitioned_column_data.hpp +1 -1
  224. package/src/duckdb/src/include/duckdb/common/types/constraint_conflict_info.hpp +1 -2
  225. package/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp +2 -2
  226. package/src/duckdb/src/include/duckdb/common/types/date.hpp +1 -1
  227. package/src/duckdb/src/include/duckdb/common/types/hash.hpp +5 -5
  228. package/src/duckdb/src/include/duckdb/common/types/hyperloglog.hpp +1 -1
  229. package/src/duckdb/src/include/duckdb/common/types/interval.hpp +4 -4
  230. package/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp +1 -1
  231. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_layout.hpp +10 -3
  232. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp +1 -1
  233. package/src/duckdb/src/include/duckdb/common/types/selection_vector.hpp +12 -12
  234. package/src/duckdb/src/include/duckdb/common/types/string_heap.hpp +1 -1
  235. package/src/duckdb/src/include/duckdb/common/types/string_type.hpp +21 -20
  236. package/src/duckdb/src/include/duckdb/common/types/time.hpp +2 -2
  237. package/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +3 -3
  238. package/src/duckdb/src/include/duckdb/common/types/uuid.hpp +2 -2
  239. package/src/duckdb/src/include/duckdb/common/types/value.hpp +2 -2
  240. package/src/duckdb/src/include/duckdb/common/types/vector.hpp +15 -7
  241. package/src/duckdb/src/include/duckdb/common/types/vector_buffer.hpp +1 -1
  242. package/src/duckdb/src/include/duckdb/common/types.hpp +14 -10
  243. package/src/duckdb/src/include/duckdb/common/uhugeint.hpp +2 -2
  244. package/src/duckdb/src/include/duckdb/common/union_by_name.hpp +1 -1
  245. package/src/duckdb/src/include/duckdb/common/unique_ptr.hpp +15 -14
  246. package/src/duckdb/src/include/duckdb/common/vector.hpp +21 -21
  247. package/src/duckdb/src/include/duckdb/common/vector_operations/aggregate_executor.hpp +2 -0
  248. package/src/duckdb/src/include/duckdb/common/vector_operations/general_cast.hpp +2 -1
  249. package/src/duckdb/src/include/duckdb/common/vector_operations/generic_executor.hpp +2 -3
  250. package/src/duckdb/src/include/duckdb/common/vector_operations/unary_executor.hpp +3 -2
  251. package/src/duckdb/src/include/duckdb/common/vector_operations/vector_operations.hpp +50 -32
  252. package/src/duckdb/src/include/duckdb/common/virtual_file_system.hpp +10 -11
  253. package/src/duckdb/src/include/duckdb/core_functions/aggregate/distributive_functions.hpp +1 -1
  254. package/src/duckdb/src/include/duckdb/core_functions/aggregate/sum_helpers.hpp +13 -1
  255. package/src/duckdb/src/include/duckdb/core_functions/function_list.hpp +1 -1
  256. package/src/duckdb/src/include/duckdb/core_functions/lambda_functions.hpp +2 -1
  257. package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +1 -1
  258. package/src/duckdb/src/include/duckdb/execution/column_binding_resolver.hpp +1 -1
  259. package/src/duckdb/src/include/duckdb/execution/expression_executor.hpp +1 -1
  260. package/src/duckdb/src/include/duckdb/execution/expression_executor_state.hpp +2 -5
  261. package/src/duckdb/src/include/duckdb/execution/merge_sort_tree.hpp +3 -3
  262. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/aggregate_object.hpp +2 -2
  263. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/distinct_aggregate_data.hpp +1 -1
  264. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/base_scanner.hpp +1 -1
  265. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/column_count_scanner.hpp +0 -3
  266. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer.hpp +9 -6
  267. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_buffer_manager.hpp +3 -0
  268. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_error.hpp +40 -22
  269. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_file_handle.hpp +5 -0
  270. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_file_scanner.hpp +1 -0
  271. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_option.hpp +6 -4
  272. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_reader_options.hpp +24 -10
  273. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/csv_state_machine.hpp +4 -0
  274. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/global_csv_state.hpp +3 -1
  275. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/skip_scanner.hpp +0 -3
  276. package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/string_value_scanner.hpp +58 -17
  277. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_batch_collector.hpp +1 -1
  278. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_explain_analyze.hpp +1 -1
  279. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_prepare.hpp +3 -3
  280. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_set.hpp +1 -1
  281. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_vacuum.hpp +4 -1
  282. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_rejects_table.hpp +16 -5
  283. package/src/duckdb/src/include/duckdb/execution/physical_operator_states.hpp +6 -6
  284. package/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp +2 -1
  285. package/src/duckdb/src/include/duckdb/execution/window_executor.hpp +1 -1
  286. package/src/duckdb/src/include/duckdb/execution/window_segment_tree.hpp +1 -1
  287. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +1 -1
  288. package/src/duckdb/src/include/duckdb/function/cast/cast_function_set.hpp +5 -5
  289. package/src/duckdb/src/include/duckdb/function/cast/default_casts.hpp +4 -4
  290. package/src/duckdb/src/include/duckdb/function/cast/vector_cast_helpers.hpp +6 -6
  291. package/src/duckdb/src/include/duckdb/function/compression_function.hpp +4 -4
  292. package/src/duckdb/src/include/duckdb/function/copy_function.hpp +10 -13
  293. package/src/duckdb/src/include/duckdb/function/function.hpp +3 -3
  294. package/src/duckdb/src/include/duckdb/function/function_binder.hpp +24 -23
  295. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +1 -1
  296. package/src/duckdb/src/include/duckdb/function/function_set.hpp +1 -1
  297. package/src/duckdb/src/include/duckdb/function/pragma_function.hpp +1 -1
  298. package/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp +3 -3
  299. package/src/duckdb/src/include/duckdb/function/scalar/strftime_format.hpp +7 -7
  300. package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +3 -3
  301. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +6 -6
  302. package/src/duckdb/src/include/duckdb/function/table/arrow/arrow_duck_schema.hpp +4 -4
  303. package/src/duckdb/src/include/duckdb/function/table/arrow.hpp +2 -2
  304. package/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +1 -3
  305. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +1 -1
  306. package/src/duckdb/src/include/duckdb/function/table_function.hpp +12 -11
  307. package/src/duckdb/src/include/duckdb/function/udf_function.hpp +66 -60
  308. package/src/duckdb/src/include/duckdb/main/appender.hpp +6 -6
  309. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +3 -1
  310. package/src/duckdb/src/include/duckdb/main/buffered_data/buffered_data.hpp +2 -2
  311. package/src/duckdb/src/include/duckdb/main/buffered_data/simple_buffered_data.hpp +1 -1
  312. package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +2 -2
  313. package/src/duckdb/src/include/duckdb/main/chunk_scan_state/query_result.hpp +2 -2
  314. package/src/duckdb/src/include/duckdb/main/client_context.hpp +1 -1
  315. package/src/duckdb/src/include/duckdb/main/client_context_file_opener.hpp +3 -2
  316. package/src/duckdb/src/include/duckdb/main/client_data.hpp +1 -0
  317. package/src/duckdb/src/include/duckdb/main/client_properties.hpp +2 -1
  318. package/src/duckdb/src/include/duckdb/main/config.hpp +14 -5
  319. package/src/duckdb/src/include/duckdb/main/connection.hpp +27 -26
  320. package/src/duckdb/src/include/duckdb/main/database.hpp +19 -3
  321. package/src/duckdb/src/include/duckdb/main/database_file_opener.hpp +58 -0
  322. package/src/duckdb/src/include/duckdb/main/database_path_and_type.hpp +2 -2
  323. package/src/duckdb/src/include/duckdb/main/error_manager.hpp +6 -6
  324. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +8 -0
  325. package/src/duckdb/src/include/duckdb/main/extension_helper.hpp +1 -0
  326. package/src/duckdb/src/include/duckdb/main/external_dependencies.hpp +2 -1
  327. package/src/duckdb/src/include/duckdb/main/prepared_statement.hpp +8 -8
  328. package/src/duckdb/src/include/duckdb/main/query_profiler.hpp +2 -59
  329. package/src/duckdb/src/include/duckdb/main/query_result.hpp +3 -3
  330. package/src/duckdb/src/include/duckdb/main/relation/query_relation.hpp +1 -1
  331. package/src/duckdb/src/include/duckdb/main/relation.hpp +1 -1
  332. package/src/duckdb/src/include/duckdb/main/secret/secret.hpp +11 -7
  333. package/src/duckdb/src/include/duckdb/main/secret/secret_manager.hpp +2 -2
  334. package/src/duckdb/src/include/duckdb/main/secret/secret_storage.hpp +4 -4
  335. package/src/duckdb/src/include/duckdb/main/settings.hpp +78 -70
  336. package/src/duckdb/src/include/duckdb/optimizer/column_lifetime_analyzer.hpp +45 -0
  337. package/src/duckdb/src/include/duckdb/optimizer/compressed_materialization.hpp +11 -13
  338. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +2 -2
  339. package/src/duckdb/src/include/duckdb/optimizer/join_order/cost_model.hpp +1 -1
  340. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_node.hpp +1 -1
  341. package/src/duckdb/src/include/duckdb/optimizer/join_order/query_graph.hpp +1 -1
  342. package/src/duckdb/src/include/duckdb/optimizer/join_order/query_graph_manager.hpp +1 -1
  343. package/src/duckdb/src/include/duckdb/optimizer/join_order/relation_manager.hpp +1 -1
  344. package/src/duckdb/src/include/duckdb/optimizer/matcher/expression_matcher.hpp +7 -7
  345. package/src/duckdb/src/include/duckdb/optimizer/matcher/function_matcher.hpp +7 -7
  346. package/src/duckdb/src/include/duckdb/optimizer/matcher/type_matcher.hpp +1 -1
  347. package/src/duckdb/src/include/duckdb/optimizer/optimizer.hpp +3 -0
  348. package/src/duckdb/src/include/duckdb/optimizer/statistics_propagator.hpp +32 -30
  349. package/src/duckdb/src/include/duckdb/optimizer/unnest_rewriter.hpp +1 -1
  350. package/src/duckdb/src/include/duckdb/parallel/event.hpp +1 -1
  351. package/src/duckdb/src/include/duckdb/parallel/executor_task.hpp +1 -1
  352. package/src/duckdb/src/include/duckdb/parallel/interrupt.hpp +2 -2
  353. package/src/duckdb/src/include/duckdb/parallel/pipeline_event.hpp +1 -1
  354. package/src/duckdb/src/include/duckdb/parser/column_list.hpp +4 -4
  355. package/src/duckdb/src/include/duckdb/parser/constraints/unique_constraint.hpp +49 -8
  356. package/src/duckdb/src/include/duckdb/parser/expression/bound_expression.hpp +1 -1
  357. package/src/duckdb/src/include/duckdb/parser/expression/positional_reference_expression.hpp +1 -1
  358. package/src/duckdb/src/include/duckdb/parser/expression/star_expression.hpp +1 -1
  359. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_scalar_function_info.hpp +1 -1
  360. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_function_info.hpp +1 -1
  361. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +1 -1
  362. package/src/duckdb/src/include/duckdb/parser/parsed_data/copy_database_info.hpp +40 -0
  363. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_function_info.hpp +2 -1
  364. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_index_info.hpp +1 -0
  365. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_info.hpp +2 -1
  366. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_macro_info.hpp +1 -1
  367. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_pragma_function_info.hpp +1 -1
  368. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_secret_info.hpp +2 -2
  369. package/src/duckdb/src/include/duckdb/parser/parsed_data/extra_drop_info.hpp +3 -3
  370. package/src/duckdb/src/include/duckdb/parser/parsed_data/parse_info.hpp +3 -2
  371. package/src/duckdb/src/include/duckdb/parser/parsed_data/vacuum_info.hpp +2 -5
  372. package/src/duckdb/src/include/duckdb/parser/parser.hpp +1 -1
  373. package/src/duckdb/src/include/duckdb/parser/parser_extension.hpp +3 -3
  374. package/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +1 -1
  375. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +3 -5
  376. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +2 -2
  377. package/src/duckdb/src/include/duckdb/planner/binder.hpp +16 -9
  378. package/src/duckdb/src/include/duckdb/planner/expression/bound_case_expression.hpp +1 -1
  379. package/src/duckdb/src/include/duckdb/planner/expression/bound_cast_expression.hpp +1 -1
  380. package/src/duckdb/src/include/duckdb/planner/expression/bound_default_expression.hpp +1 -1
  381. package/src/duckdb/src/include/duckdb/planner/expression/bound_expanded_expression.hpp +34 -0
  382. package/src/duckdb/src/include/duckdb/planner/expression/bound_subquery_expression.hpp +1 -1
  383. package/src/duckdb/src/include/duckdb/planner/expression.hpp +1 -1
  384. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +5 -8
  385. package/src/duckdb/src/include/duckdb/planner/expression_binder/column_alias_binder.hpp +3 -4
  386. package/src/duckdb/src/include/duckdb/planner/expression_binder/group_binder.hpp +3 -2
  387. package/src/duckdb/src/include/duckdb/planner/expression_binder/having_binder.hpp +3 -5
  388. package/src/duckdb/src/include/duckdb/planner/expression_binder/order_binder.hpp +6 -14
  389. package/src/duckdb/src/include/duckdb/planner/expression_binder/qualify_binder.hpp +3 -6
  390. package/src/duckdb/src/include/duckdb/planner/expression_binder/select_bind_state.hpp +52 -0
  391. package/src/duckdb/src/include/duckdb/planner/expression_binder/select_binder.hpp +4 -10
  392. package/src/duckdb/src/include/duckdb/planner/expression_binder/table_function_binder.hpp +5 -2
  393. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +1 -0
  394. package/src/duckdb/src/include/duckdb/planner/expression_iterator.hpp +2 -0
  395. package/src/duckdb/src/include/duckdb/planner/filter/conjunction_filter.hpp +3 -6
  396. package/src/duckdb/src/include/duckdb/planner/logical_operator.hpp +2 -0
  397. package/src/duckdb/src/include/duckdb/planner/logical_tokens.hpp +1 -0
  398. package/src/duckdb/src/include/duckdb/planner/operator/list.hpp +1 -0
  399. package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_database.hpp +4 -12
  400. package/src/duckdb/src/include/duckdb/planner/operator/logical_create_secret.hpp +1 -1
  401. package/src/duckdb/src/include/duckdb/planner/operator/logical_cteref.hpp +2 -2
  402. package/src/duckdb/src/include/duckdb/planner/operator/logical_delim_get.hpp +1 -1
  403. package/src/duckdb/src/include/duckdb/planner/operator/logical_dummy_scan.hpp +1 -1
  404. package/src/duckdb/src/include/duckdb/planner/operator/logical_explain.hpp +1 -1
  405. package/src/duckdb/src/include/duckdb/planner/operator/logical_export.hpp +2 -2
  406. package/src/duckdb/src/include/duckdb/planner/operator/logical_expression_get.hpp +2 -2
  407. package/src/duckdb/src/include/duckdb/planner/operator/logical_extension_operator.hpp +2 -2
  408. package/src/duckdb/src/include/duckdb/planner/operator/logical_materialized_cte.hpp +2 -2
  409. package/src/duckdb/src/include/duckdb/planner/operator/logical_pragma.hpp +1 -1
  410. package/src/duckdb/src/include/duckdb/planner/operator/logical_prepare.hpp +3 -2
  411. package/src/duckdb/src/include/duckdb/planner/operator/logical_recursive_cte.hpp +3 -3
  412. package/src/duckdb/src/include/duckdb/planner/operator/logical_reset.hpp +1 -1
  413. package/src/duckdb/src/include/duckdb/planner/operator/logical_set.hpp +2 -1
  414. package/src/duckdb/src/include/duckdb/planner/operator/logical_vacuum.hpp +52 -0
  415. package/src/duckdb/src/include/duckdb/planner/operator_extension.hpp +1 -1
  416. package/src/duckdb/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp +2 -2
  417. package/src/duckdb/src/include/duckdb/planner/query_node/bound_select_node.hpp +5 -4
  418. package/src/duckdb/src/include/duckdb/planner/subquery/flatten_dependent_join.hpp +2 -2
  419. package/src/duckdb/src/include/duckdb/storage/arena_allocator.hpp +4 -1
  420. package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +1 -1
  421. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +3 -3
  422. package/src/duckdb/src/include/duckdb/storage/checkpoint/row_group_writer.hpp +2 -3
  423. package/src/duckdb/src/include/duckdb/storage/checkpoint/string_checkpoint_state.hpp +1 -1
  424. package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +3 -3
  425. package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +5 -5
  426. package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_analyze.hpp +1 -1
  427. package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_compress.hpp +1 -1
  428. package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_fetch.hpp +1 -1
  429. package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_scan.hpp +1 -1
  430. package/src/duckdb/src/include/duckdb/storage/compression/alprd/algorithm/alprd.hpp +3 -3
  431. package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_analyze.hpp +2 -2
  432. package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_compress.hpp +1 -1
  433. package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_fetch.hpp +1 -1
  434. package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_scan.hpp +3 -3
  435. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/flag_buffer.hpp +1 -1
  436. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/leading_zero_buffer.hpp +3 -3
  437. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp.hpp +3 -3
  438. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_analyze.hpp +0 -1
  439. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_fetch.hpp +1 -1
  440. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_scan.hpp +4 -4
  441. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas.hpp +4 -4
  442. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_analyze.hpp +0 -1
  443. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_fetch.hpp +1 -1
  444. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_scan.hpp +3 -3
  445. package/src/duckdb/src/include/duckdb/storage/data_pointer.hpp +1 -1
  446. package/src/duckdb/src/include/duckdb/storage/index.hpp +1 -1
  447. package/src/duckdb/src/include/duckdb/storage/magic_bytes.hpp +1 -1
  448. package/src/duckdb/src/include/duckdb/storage/object_cache.hpp +3 -3
  449. package/src/duckdb/src/include/duckdb/storage/optimistic_data_writer.hpp +1 -1
  450. package/src/duckdb/src/include/duckdb/storage/partial_block_manager.hpp +1 -1
  451. package/src/duckdb/src/include/duckdb/storage/single_file_block_manager.hpp +4 -1
  452. package/src/duckdb/src/include/duckdb/storage/standard_buffer_manager.hpp +24 -24
  453. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats_union.hpp +3 -3
  454. package/src/duckdb/src/include/duckdb/storage/statistics/segment_statistics.hpp +2 -2
  455. package/src/duckdb/src/include/duckdb/storage/storage_info.hpp +2 -2
  456. package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +4 -4
  457. package/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +9 -6
  458. package/src/duckdb/src/include/duckdb/storage/table/append_state.hpp +1 -1
  459. package/src/duckdb/src/include/duckdb/storage/table/chunk_info.hpp +2 -2
  460. package/src/duckdb/src/include/duckdb/storage/table/column_checkpoint_state.hpp +1 -1
  461. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +10 -1
  462. package/src/duckdb/src/include/duckdb/storage/table/data_table_info.hpp +3 -2
  463. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +1 -1
  464. package/src/duckdb/src/include/duckdb/storage/table/row_group_segment_tree.hpp +1 -1
  465. package/src/duckdb/src/include/duckdb/storage/table/row_version_manager.hpp +2 -1
  466. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +3 -3
  467. package/src/duckdb/src/include/duckdb/storage/table/segment_lock.hpp +1 -1
  468. package/src/duckdb/src/include/duckdb/storage/table/segment_tree.hpp +4 -4
  469. package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +2 -0
  470. package/src/duckdb/src/include/duckdb/storage/table/table_index_list.hpp +3 -2
  471. package/src/duckdb/src/include/duckdb/storage/table/table_statistics.hpp +1 -1
  472. package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +1 -1
  473. package/src/duckdb/src/include/duckdb/storage/table_storage_info.hpp +2 -1
  474. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +1 -1
  475. package/src/duckdb/src/include/duckdb/transaction/delete_info.hpp +20 -1
  476. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +1 -1
  477. package/src/duckdb/src/include/duckdb/transaction/transaction_data.hpp +1 -1
  478. package/src/duckdb/src/include/duckdb/transaction/undo_buffer.hpp +1 -1
  479. package/src/duckdb/src/include/duckdb/transaction/update_info.hpp +1 -1
  480. package/src/duckdb/src/main/appender.cpp +1 -1
  481. package/src/duckdb/src/main/attached_database.cpp +11 -3
  482. package/src/duckdb/src/main/capi/arrow-c.cpp +6 -2
  483. package/src/duckdb/src/main/capi/cast/utils-c.cpp +1 -1
  484. package/src/duckdb/src/main/capi/duckdb-c.cpp +1 -1
  485. package/src/duckdb/src/main/capi/pending-c.cpp +1 -1
  486. package/src/duckdb/src/main/capi/prepared-c.cpp +2 -2
  487. package/src/duckdb/src/main/capi/result-c.cpp +4 -4
  488. package/src/duckdb/src/main/client_context.cpp +4 -12
  489. package/src/duckdb/src/main/client_context_file_opener.cpp +15 -3
  490. package/src/duckdb/src/main/client_data.cpp +5 -0
  491. package/src/duckdb/src/main/config.cpp +82 -82
  492. package/src/duckdb/src/main/database.cpp +31 -7
  493. package/src/duckdb/src/main/database_manager.cpp +3 -2
  494. package/src/duckdb/src/main/database_path_and_type.cpp +4 -4
  495. package/src/duckdb/src/main/error_manager.cpp +1 -1
  496. package/src/duckdb/src/main/extension/extension_alias.cpp +9 -9
  497. package/src/duckdb/src/main/extension/extension_helper.cpp +10 -5
  498. package/src/duckdb/src/main/extension/extension_install.cpp +1 -1
  499. package/src/duckdb/src/main/extension/extension_load.cpp +111 -37
  500. package/src/duckdb/src/main/query_profiler.cpp +1 -118
  501. package/src/duckdb/src/main/secret/secret_manager.cpp +1 -2
  502. package/src/duckdb/src/main/secret/secret_storage.cpp +1 -1
  503. package/src/duckdb/src/main/settings/settings.cpp +81 -65
  504. package/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp +8 -1
  505. package/src/duckdb/src/optimizer/compressed_materialization/compress_aggregate.cpp +3 -0
  506. package/src/duckdb/src/optimizer/compressed_materialization.cpp +26 -28
  507. package/src/duckdb/src/optimizer/cse_optimizer.cpp +5 -5
  508. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +10 -6
  509. package/src/duckdb/src/optimizer/optimizer.cpp +14 -17
  510. package/src/duckdb/src/optimizer/pushdown/pushdown_cross_product.cpp +16 -5
  511. package/src/duckdb/src/optimizer/pushdown/pushdown_inner_join.cpp +7 -4
  512. package/src/duckdb/src/optimizer/pushdown/pushdown_set_operation.cpp +2 -2
  513. package/src/duckdb/src/optimizer/remove_unused_columns.cpp +3 -3
  514. package/src/duckdb/src/optimizer/rule/ordered_aggregate_optimizer.cpp +2 -2
  515. package/src/duckdb/src/optimizer/statistics/expression/propagate_aggregate.cpp +1 -1
  516. package/src/duckdb/src/optimizer/statistics/expression/propagate_between.cpp +8 -8
  517. package/src/duckdb/src/optimizer/statistics/expression/propagate_case.cpp +1 -1
  518. package/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp +1 -1
  519. package/src/duckdb/src/optimizer/statistics/expression/propagate_columnref.cpp +1 -1
  520. package/src/duckdb/src/optimizer/statistics/expression/propagate_comparison.cpp +7 -7
  521. package/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp +6 -6
  522. package/src/duckdb/src/optimizer/statistics/expression/propagate_constant.cpp +1 -1
  523. package/src/duckdb/src/optimizer/statistics/expression/propagate_function.cpp +2 -2
  524. package/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp +10 -10
  525. package/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp +1 -1
  526. package/src/duckdb/src/optimizer/statistics/operator/propagate_cross_product.cpp +1 -1
  527. package/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +14 -7
  528. package/src/duckdb/src/optimizer/statistics/operator/propagate_get.cpp +2 -2
  529. package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +9 -9
  530. package/src/duckdb/src/optimizer/statistics/operator/propagate_limit.cpp +1 -1
  531. package/src/duckdb/src/optimizer/statistics/operator/propagate_order.cpp +1 -1
  532. package/src/duckdb/src/optimizer/statistics/operator/propagate_projection.cpp +2 -2
  533. package/src/duckdb/src/optimizer/statistics/operator/propagate_set_operation.cpp +1 -1
  534. package/src/duckdb/src/optimizer/statistics/operator/propagate_window.cpp +1 -1
  535. package/src/duckdb/src/optimizer/statistics_propagator.cpp +39 -18
  536. package/src/duckdb/src/parallel/pipeline_finish_event.cpp +1 -1
  537. package/src/duckdb/src/parallel/task_scheduler.cpp +8 -1
  538. package/src/duckdb/src/parser/constraints/unique_constraint.cpp +4 -2
  539. package/src/duckdb/src/parser/parsed_data/create_index_info.cpp +64 -0
  540. package/src/duckdb/src/parser/parsed_data/vacuum_info.cpp +1 -0
  541. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +13 -5
  542. package/src/duckdb/src/parser/transform/expression/transform_subquery.cpp +24 -0
  543. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +1 -8
  544. package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +2 -1
  545. package/src/duckdb/src/parser/transform/statement/transform_create_index.cpp +3 -0
  546. package/src/duckdb/src/parser/transform/statement/transform_delete.cpp +2 -6
  547. package/src/duckdb/src/parser/transform/statement/transform_insert.cpp +2 -6
  548. package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +2 -6
  549. package/src/duckdb/src/parser/transform/statement/transform_pragma.cpp +1 -1
  550. package/src/duckdb/src/parser/transform/statement/transform_select.cpp +5 -2
  551. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +2 -8
  552. package/src/duckdb/src/parser/transform/statement/transform_update.cpp +1 -6
  553. package/src/duckdb/src/parser/transform/statement/transform_use.cpp +3 -2
  554. package/src/duckdb/src/parser/transformer.cpp +14 -2
  555. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +40 -17
  556. package/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +8 -3
  557. package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +32 -30
  558. package/src/duckdb/src/planner/binder/query_node/bind_cte_node.cpp +28 -17
  559. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +146 -101
  560. package/src/duckdb/src/planner/binder/query_node/bind_setop_node.cpp +28 -26
  561. package/src/duckdb/src/planner/binder/query_node/plan_cte_node.cpp +29 -0
  562. package/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp +10 -10
  563. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +3 -2
  564. package/src/duckdb/src/planner/binder/statement/bind_copy_database.cpp +23 -28
  565. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +11 -12
  566. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +9 -11
  567. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +10 -13
  568. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +3 -3
  569. package/src/duckdb/src/planner/binder/statement/bind_set.cpp +3 -0
  570. package/src/duckdb/src/planner/binder/statement/bind_vacuum.cpp +66 -65
  571. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +54 -46
  572. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +3 -0
  573. package/src/duckdb/src/planner/binder/tableref/bind_subqueryref.cpp +1 -1
  574. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +5 -5
  575. package/src/duckdb/src/planner/binder.cpp +78 -6
  576. package/src/duckdb/src/planner/expression/bound_cast_expression.cpp +11 -3
  577. package/src/duckdb/src/planner/expression/bound_expanded_expression.cpp +22 -0
  578. package/src/duckdb/src/planner/expression_binder/base_select_binder.cpp +11 -58
  579. package/src/duckdb/src/planner/expression_binder/column_alias_binder.cpp +5 -8
  580. package/src/duckdb/src/planner/expression_binder/group_binder.cpp +5 -4
  581. package/src/duckdb/src/planner/expression_binder/having_binder.cpp +5 -19
  582. package/src/duckdb/src/planner/expression_binder/lateral_binder.cpp +8 -8
  583. package/src/duckdb/src/planner/expression_binder/order_binder.cpp +42 -26
  584. package/src/duckdb/src/planner/expression_binder/qualify_binder.cpp +3 -22
  585. package/src/duckdb/src/planner/expression_binder/select_bind_state.cpp +52 -0
  586. package/src/duckdb/src/planner/expression_binder/select_binder.cpp +43 -5
  587. package/src/duckdb/src/planner/expression_binder/table_function_binder.cpp +19 -7
  588. package/src/duckdb/src/planner/logical_operator.cpp +20 -3
  589. package/src/duckdb/src/planner/operator/logical_copy_database.cpp +4 -14
  590. package/src/duckdb/src/planner/operator/logical_delete.cpp +1 -1
  591. package/src/duckdb/src/planner/operator/logical_get.cpp +1 -1
  592. package/src/duckdb/src/planner/operator/logical_insert.cpp +1 -1
  593. package/src/duckdb/src/planner/operator/logical_update.cpp +1 -1
  594. package/src/duckdb/src/planner/operator/logical_vacuum.cpp +65 -0
  595. package/src/duckdb/src/planner/planner.cpp +4 -4
  596. package/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp +26 -27
  597. package/src/duckdb/src/storage/arena_allocator.cpp +9 -0
  598. package/src/duckdb/src/storage/buffer/buffer_pool_reservation.cpp +1 -1
  599. package/src/duckdb/src/storage/buffer_manager.cpp +2 -10
  600. package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +2 -3
  601. package/src/duckdb/src/storage/checkpoint_manager.cpp +15 -8
  602. package/src/duckdb/src/storage/compression/bitpacking.cpp +6 -1
  603. package/src/duckdb/src/storage/compression/string_uncompressed.cpp +1 -1
  604. package/src/duckdb/src/storage/data_pointer.cpp +1 -1
  605. package/src/duckdb/src/storage/data_table.cpp +18 -7
  606. package/src/duckdb/src/storage/local_storage.cpp +8 -5
  607. package/src/duckdb/src/storage/magic_bytes.cpp +6 -5
  608. package/src/duckdb/src/storage/partial_block_manager.cpp +1 -1
  609. package/src/duckdb/src/storage/serialization/serialize_logical_operator.cpp +20 -9
  610. package/src/duckdb/src/storage/serialization/serialize_nodes.cpp +12 -10
  611. package/src/duckdb/src/storage/serialization/serialize_parse_info.cpp +23 -0
  612. package/src/duckdb/src/storage/single_file_block_manager.cpp +46 -19
  613. package/src/duckdb/src/storage/standard_buffer_manager.cpp +21 -5
  614. package/src/duckdb/src/storage/statistics/array_stats.cpp +1 -1
  615. package/src/duckdb/src/storage/statistics/base_statistics.cpp +2 -3
  616. package/src/duckdb/src/storage/statistics/list_stats.cpp +1 -1
  617. package/src/duckdb/src/storage/statistics/struct_stats.cpp +1 -1
  618. package/src/duckdb/src/storage/storage_info.cpp +19 -19
  619. package/src/duckdb/src/storage/storage_manager.cpp +18 -13
  620. package/src/duckdb/src/storage/table/chunk_info.cpp +11 -3
  621. package/src/duckdb/src/storage/table/column_data.cpp +88 -66
  622. package/src/duckdb/src/storage/table/row_group.cpp +7 -7
  623. package/src/duckdb/src/storage/table/row_version_manager.cpp +2 -2
  624. package/src/duckdb/src/storage/table/standard_column_data.cpp +4 -0
  625. package/src/duckdb/src/storage/table/update_segment.cpp +3 -1
  626. package/src/duckdb/src/storage/table_index_list.cpp +6 -1
  627. package/src/duckdb/src/storage/temporary_file_manager.cpp +1 -1
  628. package/src/duckdb/src/storage/wal_replay.cpp +8 -7
  629. package/src/duckdb/src/storage/write_ahead_log.cpp +3 -4
  630. package/src/duckdb/src/transaction/cleanup_state.cpp +10 -3
  631. package/src/duckdb/src/transaction/commit_state.cpp +11 -4
  632. package/src/duckdb/src/transaction/duck_transaction.cpp +23 -3
  633. package/src/duckdb/src/transaction/rollback_state.cpp +1 -1
  634. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
  635. package/src/duckdb/src/transaction/undo_buffer.cpp +3 -1
  636. package/src/duckdb/third_party/fmt/include/fmt/core.h +0 -5
  637. package/src/duckdb/third_party/fsst/fsst.h +1 -1
  638. package/src/duckdb/third_party/fsst/libfsst.cpp +1 -140
  639. package/src/duckdb/third_party/fsst/libfsst.hpp +0 -13
  640. package/src/duckdb/third_party/hyperloglog/hyperloglog.hpp +4 -0
  641. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +8 -1
  642. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +2 -1
  643. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +15401 -15354
  644. package/src/duckdb/third_party/libpg_query/src_backend_parser_scan.cpp +299 -538
  645. package/src/duckdb/third_party/lz4/lz4.cpp +2605 -0
  646. package/src/duckdb/third_party/lz4/lz4.hpp +843 -0
  647. package/src/duckdb/third_party/parquet/parquet_types.cpp +3 -0
  648. package/src/duckdb/third_party/parquet/parquet_types.h +2 -1
  649. package/src/duckdb/third_party/re2/re2/bitmap256.cc +44 -0
  650. package/src/duckdb/third_party/re2/re2/bitmap256.h +3 -35
  651. package/src/duckdb/third_party/re2/re2/bitstate.cc +31 -24
  652. package/src/duckdb/third_party/re2/re2/compile.cc +146 -164
  653. package/src/duckdb/third_party/re2/re2/dfa.cc +174 -181
  654. package/src/duckdb/third_party/re2/re2/filtered_re2.cc +19 -3
  655. package/src/duckdb/third_party/re2/re2/filtered_re2.h +27 -23
  656. package/src/duckdb/third_party/re2/re2/mimics_pcre.cc +21 -11
  657. package/src/duckdb/third_party/re2/re2/nfa.cc +91 -131
  658. package/src/duckdb/third_party/re2/re2/onepass.cc +11 -10
  659. package/src/duckdb/third_party/re2/re2/parse.cc +171 -154
  660. package/src/duckdb/third_party/re2/re2/perl_groups.cc +35 -35
  661. package/src/duckdb/third_party/re2/re2/pod_array.h +55 -0
  662. package/src/duckdb/third_party/re2/re2/prefilter.cc +40 -40
  663. package/src/duckdb/third_party/re2/re2/prefilter.h +24 -2
  664. package/src/duckdb/third_party/re2/re2/prefilter_tree.cc +70 -84
  665. package/src/duckdb/third_party/re2/re2/prefilter_tree.h +5 -4
  666. package/src/duckdb/third_party/re2/re2/prog.cc +315 -58
  667. package/src/duckdb/third_party/re2/re2/prog.h +77 -44
  668. package/src/duckdb/third_party/re2/re2/re2.cc +333 -221
  669. package/src/duckdb/third_party/re2/re2/re2.h +277 -201
  670. package/src/duckdb/third_party/re2/re2/regexp.cc +137 -105
  671. package/src/duckdb/third_party/re2/re2/regexp.h +45 -40
  672. package/src/duckdb/third_party/re2/re2/set.cc +40 -17
  673. package/src/duckdb/third_party/re2/re2/set.h +11 -6
  674. package/src/duckdb/third_party/re2/re2/simplify.cc +50 -41
  675. package/src/duckdb/third_party/re2/re2/sparse_array.h +392 -0
  676. package/src/duckdb/third_party/re2/re2/sparse_set.h +264 -0
  677. package/src/duckdb/third_party/re2/re2/stringpiece.cc +1 -1
  678. package/src/duckdb/third_party/re2/re2/stringpiece.h +11 -8
  679. package/src/duckdb/third_party/re2/re2/tostring.cc +8 -6
  680. package/src/duckdb/third_party/re2/re2/unicode_casefold.cc +39 -10
  681. package/src/duckdb/third_party/re2/re2/unicode_casefold.h +1 -1
  682. package/src/duckdb/third_party/re2/re2/unicode_groups.cc +5019 -4566
  683. package/src/duckdb/third_party/re2/re2/unicode_groups.h +1 -1
  684. package/src/duckdb/third_party/re2/re2/walker-inl.h +21 -20
  685. package/src/duckdb/third_party/re2/util/logging.h +14 -18
  686. package/src/duckdb/third_party/re2/util/mix.h +4 -4
  687. package/src/duckdb/third_party/re2/util/mutex.h +48 -15
  688. package/src/duckdb/third_party/re2/util/rune.cc +5 -5
  689. package/src/duckdb/third_party/re2/util/strutil.cc +1 -16
  690. package/src/duckdb/third_party/re2/util/strutil.h +1 -3
  691. package/src/duckdb/third_party/re2/util/utf.h +1 -1
  692. package/src/duckdb/third_party/re2/util/util.h +9 -1
  693. package/src/duckdb/third_party/utf8proc/include/utf8proc_wrapper.hpp +2 -0
  694. package/src/duckdb/third_party/utf8proc/utf8proc_wrapper.cpp +36 -1
  695. package/src/duckdb/ub_src_common.cpp +0 -2
  696. package/src/duckdb/ub_src_execution_physical_plan.cpp +2 -0
  697. package/src/duckdb/ub_src_planner_expression.cpp +2 -0
  698. package/src/duckdb/ub_src_planner_expression_binder.cpp +2 -0
  699. package/src/duckdb/ub_src_planner_operator.cpp +2 -0
  700. package/test/jsdoc.test.ts +3 -0
@@ -0,0 +1,2605 @@
1
+ /*
2
+ LZ4 - Fast LZ compression algorithm
3
+ Copyright (C) 2011-2020, Yann Collet.
4
+
5
+ BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are
9
+ met:
10
+
11
+ * Redistributions of source code must retain the above copyright
12
+ notice, this list of conditions and the following disclaimer.
13
+ * Redistributions in binary form must reproduce the above
14
+ copyright notice, this list of conditions and the following disclaimer
15
+ in the documentation and/or other materials provided with the
16
+ distribution.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ You can contact the author at :
31
+ - LZ4 homepage : http://www.lz4.org
32
+ - LZ4 source repository : https://github.com/lz4/lz4
33
+ */
34
+
35
+ /*-************************************
36
+ * Tuning parameters
37
+ **************************************/
38
+ /*
39
+ * LZ4_HEAPMODE :
40
+ * Select how default compression functions will allocate memory for their hash table,
41
+ * in memory stack (0:default, fastest), or in memory heap (1:requires malloc()).
42
+ */
43
+ #ifndef LZ4_HEAPMODE
44
+ # define LZ4_HEAPMODE 0
45
+ #endif
46
+
47
+ /*
48
+ * LZ4_ACCELERATION_DEFAULT :
49
+ * Select "acceleration" for LZ4_compress_fast() when parameter value <= 0
50
+ */
51
+ #define LZ4_ACCELERATION_DEFAULT 1
52
+ /*
53
+ * LZ4_ACCELERATION_MAX :
54
+ * Any "acceleration" value higher than this threshold
55
+ * get treated as LZ4_ACCELERATION_MAX instead (fix #876)
56
+ */
57
+ #define LZ4_ACCELERATION_MAX 65537
58
+
59
+
60
+ /*-************************************
61
+ * CPU Feature Detection
62
+ **************************************/
63
+ /* LZ4_FORCE_MEMORY_ACCESS
64
+ * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
65
+ * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
66
+ * The below switch allow to select different access method for improved performance.
67
+ * Method 0 (default) : use `memcpy()`. Safe and portable.
68
+ * Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
69
+ * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
70
+ * Method 2 : direct access. This method is portable but violate C standard.
71
+ * It can generate buggy code on targets which assembly generation depends on alignment.
72
+ * But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
73
+ * See https://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
74
+ * Prefer these methods in priority order (0 > 1 > 2)
75
+ */
76
+ #ifndef LZ4_FORCE_MEMORY_ACCESS /* can be defined externally */
77
+ # if defined(__GNUC__) && \
78
+ ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) \
79
+ || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
80
+ # define LZ4_FORCE_MEMORY_ACCESS 2
81
+ # elif (defined(__INTEL_COMPILER) && !defined(_WIN32)) || defined(__GNUC__)
82
+ # define LZ4_FORCE_MEMORY_ACCESS 1
83
+ # endif
84
+ #endif
85
+
86
+ /*
87
+ * LZ4_FORCE_SW_BITCOUNT
88
+ * Define this parameter if your target system or compiler does not support hardware bit count
89
+ */
90
+ #if defined(_MSC_VER) && defined(_WIN32_WCE) /* Visual Studio for WinCE doesn't support Hardware bit count */
91
+ # undef LZ4_FORCE_SW_BITCOUNT /* avoid double def */
92
+ # define LZ4_FORCE_SW_BITCOUNT
93
+ #endif
94
+
95
+
96
+
97
+ /*-************************************
98
+ * Dependency
99
+ **************************************/
100
+ /*
101
+ * LZ4_SRC_INCLUDED:
102
+ * Amalgamation flag, whether lz4.c is included
103
+ */
104
+ #ifndef LZ4_SRC_INCLUDED
105
+ # define LZ4_SRC_INCLUDED 1
106
+ #endif
107
+
108
+ #ifndef LZ4_STATIC_LINKING_ONLY
109
+ #define LZ4_STATIC_LINKING_ONLY
110
+ #endif
111
+
112
+ #ifndef LZ4_DISABLE_DEPRECATE_WARNINGS
113
+ #define LZ4_DISABLE_DEPRECATE_WARNINGS /* due to LZ4_decompress_safe_withPrefix64k */
114
+ #endif
115
+
116
+ #define LZ4_STATIC_LINKING_ONLY /* LZ4_DISTANCE_MAX */
117
+ #include <stdlib.h>
118
+
119
+ #include "lz4.hpp"
120
+ /* see also "memory routines" below */
121
+
122
+
123
+ /*-************************************
124
+ * Compiler Options
125
+ **************************************/
126
+
127
+ #define LZ4_FORCE_INLINE static
128
+ #define LZ4_FORCE_O2
129
+
130
+ #if (defined(__GNUC__) && (__GNUC__ >= 3)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 800)) || defined(__clang__)
131
+ # define expect(expr,value) (__builtin_expect ((expr),(value)) )
132
+ #else
133
+ # define expect(expr,value) (expr)
134
+ #endif
135
+
136
+ #ifndef likely
137
+ #define likely(expr) expect((expr) != 0, 1)
138
+ #endif
139
+ #ifndef unlikely
140
+ #define unlikely(expr) expect((expr) != 0, 0)
141
+ #endif
142
+
143
+ /* Should the alignment test prove unreliable, for some reason,
144
+ * it can be disabled by setting LZ4_ALIGN_TEST to 0 */
145
+ #ifndef LZ4_ALIGN_TEST /* can be externally provided */
146
+ # define LZ4_ALIGN_TEST 1
147
+ #endif
148
+
149
+ namespace duckdb_lz4 {
150
+ /*-************************************
151
+ * Memory routines
152
+ **************************************/
153
+
154
+ /*! LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION :
155
+ * Disable relatively high-level LZ4/HC functions that use dynamic memory
156
+ * allocation functions (malloc(), calloc(), free()).
157
+ *
158
+ * Note that this is a compile-time switch. And since it disables
159
+ * public/stable LZ4 v1 API functions, we don't recommend using this
160
+ * symbol to generate a library for distribution.
161
+ *
162
+ * The following public functions are removed when this symbol is defined.
163
+ * - lz4 : LZ4_createStream, LZ4_freeStream,
164
+ * LZ4_createStreamDecode, LZ4_freeStreamDecode, LZ4_create (deprecated)
165
+ * - lz4hc : LZ4_createStreamHC, LZ4_freeStreamHC,
166
+ * LZ4_createHC (deprecated), LZ4_freeHC (deprecated)
167
+ * - lz4frame, lz4file : All LZ4F_* functions
168
+ */
169
+ #if defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
170
+ # define ALLOC(s) lz4_error_memory_allocation_is_disabled
171
+ # define ALLOC_AND_ZERO(s) lz4_error_memory_allocation_is_disabled
172
+ # define FREEMEM(p) lz4_error_memory_allocation_is_disabled
173
+ #elif defined(LZ4_USER_MEMORY_FUNCTIONS)
174
+ /* memory management functions can be customized by user project.
175
+ * Below functions must exist somewhere in the Project
176
+ * and be available at link time */
177
+ void* LZ4_malloc(size_t s);
178
+ void* LZ4_calloc(size_t n, size_t s);
179
+ void LZ4_free(void* p);
180
+ # define ALLOC(s) LZ4_malloc(s)
181
+ # define ALLOC_AND_ZERO(s) LZ4_calloc(1,s)
182
+ # define FREEMEM(p) LZ4_free(p)
183
+ #else
184
+ # include <stdlib.h> /* malloc, calloc, free */
185
+ # define ALLOC(s) malloc(s)
186
+ # define ALLOC_AND_ZERO(s) calloc(1,s)
187
+ # define FREEMEM(p) free(p)
188
+ #endif
189
+
190
+ #if ! LZ4_FREESTANDING
191
+ # include <string.h> /* memset, memcpy */
192
+ #endif
193
+ #if !defined(LZ4_memset)
194
+ # define LZ4_memset(p,v,s) memset((p),(v),(s))
195
+ #endif
196
+ #define MEM_INIT(p,v,s) LZ4_memset((p),(v),(s))
197
+
198
+
199
+ /*-************************************
200
+ * Common Constants
201
+ **************************************/
202
+ #define MINMATCH 4
203
+
204
+ #define WILDCOPYLENGTH 8
205
+ #define LASTLITERALS 5 /* see ../doc/lz4_Block_format.md#parsing-restrictions */
206
+ #define MFLIMIT 12 /* see ../doc/lz4_Block_format.md#parsing-restrictions */
207
+ #define MATCH_SAFEGUARD_DISTANCE ((2*WILDCOPYLENGTH) - MINMATCH) /* ensure it's possible to write 2 x wildcopyLength without overflowing output buffer */
208
+ #define FASTLOOP_SAFE_DISTANCE 64
209
+ static const int LZ4_minLength = (MFLIMIT+1);
210
+
211
+ #define KB *(1 <<10)
212
+ #define MB *(1 <<20)
213
+ #define GB *(1U<<30)
214
+
215
+ #define LZ4_DISTANCE_ABSOLUTE_MAX 65535
216
+ #if (LZ4_DISTANCE_MAX > LZ4_DISTANCE_ABSOLUTE_MAX) /* max supported by LZ4 format */
217
+ # error "LZ4_DISTANCE_MAX is too big : must be <= 65535"
218
+ #endif
219
+
220
+ #define ML_BITS 4
221
+ #define ML_MASK ((1U<<ML_BITS)-1)
222
+ #define RUN_BITS (8-ML_BITS)
223
+ #define RUN_MASK ((1U<<RUN_BITS)-1)
224
+
225
+
226
+ /*-************************************
227
+ * Error detection
228
+ **************************************/
229
+ #if defined(LZ4_DEBUG) && (LZ4_DEBUG>=1)
230
+ # include <assert.h>
231
+ #else
232
+ # ifndef assert
233
+ # define assert(condition) ((void)0)
234
+ # endif
235
+ #endif
236
+
237
+ #define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(int)(!!(c)) }; } /* use after variable declarations */
238
+
239
+ #if defined(LZ4_DEBUG) && (LZ4_DEBUG>=2)
240
+ # include <stdio.h>
241
+ static int g_debuglog_enable = 1;
242
+ # define DEBUGLOG(l, ...) { \
243
+ if ((g_debuglog_enable) && (l<=LZ4_DEBUG)) { \
244
+ fprintf(stderr, __FILE__ ": "); \
245
+ fprintf(stderr, __VA_ARGS__); \
246
+ fprintf(stderr, " \n"); \
247
+ } }
248
+ #else
249
+ # define DEBUGLOG(l, ...) {} /* disabled */
250
+ #endif
251
+
252
+ static int LZ4_isAligned(const void* ptr, size_t alignment)
253
+ {
254
+ return ((size_t)ptr & (alignment -1)) == 0;
255
+ }
256
+
257
+
258
+ /*-************************************
259
+ * Types
260
+ **************************************/
261
+ #include <limits.h>
262
+ #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
263
+ # include <stdint.h>
264
+ typedef uint8_t BYTE;
265
+ typedef uint16_t U16;
266
+ typedef uint32_t U32;
267
+ typedef int32_t S32;
268
+ typedef uint64_t U64;
269
+ typedef uintptr_t uptrval;
270
+ #else
271
+ # if UINT_MAX != 4294967295UL
272
+ # error "LZ4 code (when not C++ or C99) assumes that sizeof(int) == 4"
273
+ # endif
274
+ typedef unsigned char BYTE;
275
+ typedef unsigned short U16;
276
+ typedef unsigned int U32;
277
+ typedef signed int S32;
278
+ typedef unsigned long long U64;
279
+ typedef size_t uptrval; /* generally true, except OpenVMS-64 */
280
+ #endif
281
+
282
+ #if defined(__x86_64__)
283
+ typedef U64 reg_t; /* 64-bits in x32 mode */
284
+ #else
285
+ typedef size_t reg_t; /* 32-bits in x32 mode */
286
+ #endif
287
+
288
+ typedef enum {
289
+ notLimited = 0,
290
+ limitedOutput = 1,
291
+ fillOutput = 2
292
+ } limitedOutput_directive;
293
+
294
+
295
+ /*-************************************
296
+ * Reading and writing into memory
297
+ **************************************/
298
+
299
+ /**
300
+ * LZ4 relies on memcpy with a constant size being inlined. In freestanding
301
+ * environments, the compiler can't assume the implementation of memcpy() is
302
+ * standard compliant, so it can't apply its specialized memcpy() inlining
303
+ * logic. When possible, use __builtin_memcpy() to tell the compiler to analyze
304
+ * memcpy() as if it were standard compliant, so it can inline it in freestanding
305
+ * environments. This is needed when decompressing the Linux Kernel, for example.
306
+ */
307
+ #if !defined(LZ4_memcpy)
308
+ # if defined(__GNUC__) && (__GNUC__ >= 4)
309
+ # define LZ4_memcpy(dst, src, size) __builtin_memcpy(dst, src, size)
310
+ # else
311
+ # define LZ4_memcpy(dst, src, size) memcpy(dst, src, size)
312
+ # endif
313
+ #endif
314
+
315
+ #if !defined(LZ4_memmove)
316
+ # if defined(__GNUC__) && (__GNUC__ >= 4)
317
+ # define LZ4_memmove __builtin_memmove
318
+ # else
319
+ # define LZ4_memmove memmove
320
+ # endif
321
+ #endif
322
+
323
+ static unsigned LZ4_isLittleEndian(void)
324
+ {
325
+ const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
326
+ return one.c[0];
327
+ }
328
+
329
+
330
+ #if defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==2)
331
+ /* lie to the compiler about data alignment; use with caution */
332
+
333
+ static U16 LZ4_read16(const void* memPtr) { return *(const U16*) memPtr; }
334
+ static U32 LZ4_read32(const void* memPtr) { return *(const U32*) memPtr; }
335
+ static reg_t LZ4_read_ARCH(const void* memPtr) { return *(const reg_t*) memPtr; }
336
+
337
+ static void LZ4_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
338
+ static void LZ4_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; }
339
+
340
+ #elif defined(LZ4_FORCE_MEMORY_ACCESS) && (LZ4_FORCE_MEMORY_ACCESS==1)
341
+
342
+ /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
343
+ /* currently only defined for gcc and icc */
344
+ typedef union { U16 u16; U32 u32; reg_t uArch; } __attribute__((packed)) LZ4_unalign;
345
+
346
+ static U16 LZ4_read16(const void* ptr) { return ((const LZ4_unalign*)ptr)->u16; }
347
+ static U32 LZ4_read32(const void* ptr) { return ((const LZ4_unalign*)ptr)->u32; }
348
+ static reg_t LZ4_read_ARCH(const void* ptr) { return ((const LZ4_unalign*)ptr)->uArch; }
349
+
350
+ static void LZ4_write16(void* memPtr, U16 value) { ((LZ4_unalign*)memPtr)->u16 = value; }
351
+ static void LZ4_write32(void* memPtr, U32 value) { ((LZ4_unalign*)memPtr)->u32 = value; }
352
+
353
+ #else /* safe and portable access using memcpy() */
354
+
355
+ static U16 LZ4_read16(const void* memPtr)
356
+ {
357
+ U16 val; LZ4_memcpy(&val, memPtr, sizeof(val)); return val;
358
+ }
359
+
360
+ static U32 LZ4_read32(const void* memPtr)
361
+ {
362
+ U32 val; LZ4_memcpy(&val, memPtr, sizeof(val)); return val;
363
+ }
364
+
365
+ static reg_t LZ4_read_ARCH(const void* memPtr)
366
+ {
367
+ reg_t val; LZ4_memcpy(&val, memPtr, sizeof(val)); return val;
368
+ }
369
+
370
+ static void LZ4_write16(void* memPtr, U16 value)
371
+ {
372
+ LZ4_memcpy(memPtr, &value, sizeof(value));
373
+ }
374
+
375
+ static void LZ4_write32(void* memPtr, U32 value)
376
+ {
377
+ LZ4_memcpy(memPtr, &value, sizeof(value));
378
+ }
379
+
380
+ #endif /* LZ4_FORCE_MEMORY_ACCESS */
381
+
382
+
383
+ static U16 LZ4_readLE16(const void* memPtr)
384
+ {
385
+ if (LZ4_isLittleEndian()) {
386
+ return LZ4_read16(memPtr);
387
+ } else {
388
+ const BYTE* p = (const BYTE*)memPtr;
389
+ return (U16)((U16)p[0] + (p[1]<<8));
390
+ }
391
+ }
392
+
393
+ static void LZ4_writeLE16(void* memPtr, U16 value)
394
+ {
395
+ if (LZ4_isLittleEndian()) {
396
+ LZ4_write16(memPtr, value);
397
+ } else {
398
+ BYTE* p = (BYTE*)memPtr;
399
+ p[0] = (BYTE) value;
400
+ p[1] = (BYTE)(value>>8);
401
+ }
402
+ }
403
+
404
+ /* customized variant of memcpy, which can overwrite up to 8 bytes beyond dstEnd */
405
+ LZ4_FORCE_INLINE
406
+ void LZ4_wildCopy8(void* dstPtr, const void* srcPtr, void* dstEnd)
407
+ {
408
+ BYTE* d = (BYTE*)dstPtr;
409
+ const BYTE* s = (const BYTE*)srcPtr;
410
+ BYTE* const e = (BYTE*)dstEnd;
411
+
412
+ do { LZ4_memcpy(d,s,8); d+=8; s+=8; } while (d<e);
413
+ }
414
+
415
+ static const unsigned inc32table[8] = {0, 1, 2, 1, 0, 4, 4, 4};
416
+ static const int dec64table[8] = {0, 0, 0, -1, -4, 1, 2, 3};
417
+
418
+
419
+ #ifndef LZ4_FAST_DEC_LOOP
420
+ # if defined __i386__ || defined _M_IX86 || defined __x86_64__ || defined _M_X64
421
+ # define LZ4_FAST_DEC_LOOP 1
422
+ # elif defined(__aarch64__) && defined(__APPLE__)
423
+ # define LZ4_FAST_DEC_LOOP 1
424
+ # elif defined(__aarch64__) && !defined(__clang__)
425
+ /* On non-Apple aarch64, we disable this optimization for clang because
426
+ * on certain mobile chipsets, performance is reduced with clang. For
427
+ * more information refer to https://github.com/lz4/lz4/pull/707 */
428
+ # define LZ4_FAST_DEC_LOOP 1
429
+ # else
430
+ # define LZ4_FAST_DEC_LOOP 0
431
+ # endif
432
+ #endif
433
+
434
+ #if LZ4_FAST_DEC_LOOP
435
+
436
+ LZ4_FORCE_INLINE void
437
+ LZ4_memcpy_using_offset_base(BYTE* dstPtr, const BYTE* srcPtr, BYTE* dstEnd, const size_t offset)
438
+ {
439
+ assert(srcPtr + offset == dstPtr);
440
+ if (offset < 8) {
441
+ LZ4_write32(dstPtr, 0); /* silence an msan warning when offset==0 */
442
+ dstPtr[0] = srcPtr[0];
443
+ dstPtr[1] = srcPtr[1];
444
+ dstPtr[2] = srcPtr[2];
445
+ dstPtr[3] = srcPtr[3];
446
+ srcPtr += inc32table[offset];
447
+ LZ4_memcpy(dstPtr+4, srcPtr, 4);
448
+ srcPtr -= dec64table[offset];
449
+ dstPtr += 8;
450
+ } else {
451
+ LZ4_memcpy(dstPtr, srcPtr, 8);
452
+ dstPtr += 8;
453
+ srcPtr += 8;
454
+ }
455
+
456
+ LZ4_wildCopy8(dstPtr, srcPtr, dstEnd);
457
+ }
458
+
459
+ /* customized variant of memcpy, which can overwrite up to 32 bytes beyond dstEnd
460
+ * this version copies two times 16 bytes (instead of one time 32 bytes)
461
+ * because it must be compatible with offsets >= 16. */
462
+ LZ4_FORCE_INLINE void
463
+ LZ4_wildCopy32(void* dstPtr, const void* srcPtr, void* dstEnd)
464
+ {
465
+ BYTE* d = (BYTE*)dstPtr;
466
+ const BYTE* s = (const BYTE*)srcPtr;
467
+ BYTE* const e = (BYTE*)dstEnd;
468
+
469
+ do { LZ4_memcpy(d,s,16); LZ4_memcpy(d+16,s+16,16); d+=32; s+=32; } while (d<e);
470
+ }
471
+
472
+ /* LZ4_memcpy_using_offset() presumes :
473
+ * - dstEnd >= dstPtr + MINMATCH
474
+ * - there is at least 8 bytes available to write after dstEnd */
475
+ LZ4_FORCE_INLINE void
476
+ LZ4_memcpy_using_offset(BYTE* dstPtr, const BYTE* srcPtr, BYTE* dstEnd, const size_t offset)
477
+ {
478
+ BYTE v[8];
479
+
480
+ assert(dstEnd >= dstPtr + MINMATCH);
481
+
482
+ switch(offset) {
483
+ case 1:
484
+ MEM_INIT(v, *srcPtr, 8);
485
+ break;
486
+ case 2:
487
+ LZ4_memcpy(v, srcPtr, 2);
488
+ LZ4_memcpy(&v[2], srcPtr, 2);
489
+ #if defined(_MSC_VER) && (_MSC_VER <= 1933) /* MSVC 2022 ver 17.3 or earlier */
490
+ # pragma warning(push)
491
+ # pragma warning(disable : 6385) /* warning C6385: Reading invalid data from 'v'. */
492
+ #endif
493
+ LZ4_memcpy(&v[4], v, 4);
494
+ #if defined(_MSC_VER) && (_MSC_VER <= 1933) /* MSVC 2022 ver 17.3 or earlier */
495
+ # pragma warning(pop)
496
+ #endif
497
+ break;
498
+ case 4:
499
+ LZ4_memcpy(v, srcPtr, 4);
500
+ LZ4_memcpy(&v[4], srcPtr, 4);
501
+ break;
502
+ default:
503
+ LZ4_memcpy_using_offset_base(dstPtr, srcPtr, dstEnd, offset);
504
+ return;
505
+ }
506
+
507
+ LZ4_memcpy(dstPtr, v, 8);
508
+ dstPtr += 8;
509
+ while (dstPtr < dstEnd) {
510
+ LZ4_memcpy(dstPtr, v, 8);
511
+ dstPtr += 8;
512
+ }
513
+ }
514
+ #endif
515
+
516
+
517
+ /*-************************************
518
+ * Common functions
519
+ **************************************/
520
+ static unsigned LZ4_NbCommonBytes (reg_t val)
521
+ {
522
+ assert(val != 0);
523
+ if (LZ4_isLittleEndian()) {
524
+ if (sizeof(val) == 8) {
525
+ const U64 m = 0x0101010101010101ULL;
526
+ val ^= val - 1;
527
+ return (unsigned)(((U64)((val & (m - 1)) * m)) >> 56);
528
+ } else /* 32 bits */ {
529
+ const U32 m = 0x01010101;
530
+ return (unsigned)((((val - 1) ^ val) & (m - 1)) * m) >> 24;
531
+ }
532
+ } else /* Big Endian CPU */ {
533
+ assert(false);
534
+ return 0;
535
+ }
536
+ }
537
+
538
+
539
+ #define STEPSIZE sizeof(reg_t)
540
+ LZ4_FORCE_INLINE
541
+ unsigned LZ4_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* pInLimit)
542
+ {
543
+ const BYTE* const pStart = pIn;
544
+
545
+ if (likely(pIn < pInLimit-(STEPSIZE-1))) {
546
+ reg_t const diff = LZ4_read_ARCH(pMatch) ^ LZ4_read_ARCH(pIn);
547
+ if (!diff) {
548
+ pIn+=STEPSIZE; pMatch+=STEPSIZE;
549
+ } else {
550
+ return LZ4_NbCommonBytes(diff);
551
+ } }
552
+
553
+ while (likely(pIn < pInLimit-(STEPSIZE-1))) {
554
+ reg_t const diff = LZ4_read_ARCH(pMatch) ^ LZ4_read_ARCH(pIn);
555
+ if (!diff) { pIn+=STEPSIZE; pMatch+=STEPSIZE; continue; }
556
+ pIn += LZ4_NbCommonBytes(diff);
557
+ return (unsigned)(pIn - pStart);
558
+ }
559
+
560
+ if ((STEPSIZE==8) && (pIn<(pInLimit-3)) && (LZ4_read32(pMatch) == LZ4_read32(pIn))) { pIn+=4; pMatch+=4; }
561
+ if ((pIn<(pInLimit-1)) && (LZ4_read16(pMatch) == LZ4_read16(pIn))) { pIn+=2; pMatch+=2; }
562
+ if ((pIn<pInLimit) && (*pMatch == *pIn)) pIn++;
563
+ return (unsigned)(pIn - pStart);
564
+ }
565
+
566
+
567
+ #ifndef LZ4_COMMONDEFS_ONLY
568
+ /*-************************************
569
+ * Local Constants
570
+ **************************************/
571
+ static const int LZ4_64Klimit = ((64 KB) + (MFLIMIT-1));
572
+ static const U32 LZ4_skipTrigger = 6; /* Increase this value ==> compression run slower on incompressible data */
573
+
574
+
575
+ /*-************************************
576
+ * Local Structures and types
577
+ **************************************/
578
+ typedef enum { clearedTable = 0, byPtr, byU32, byU16 } tableType_t;
579
+
580
+ /**
581
+ * This enum distinguishes several different modes of accessing previous
582
+ * content in the stream.
583
+ *
584
+ * - noDict : There is no preceding content.
585
+ * - withPrefix64k : Table entries up to ctx->dictSize before the current blob
586
+ * blob being compressed are valid and refer to the preceding
587
+ * content (of length ctx->dictSize), which is available
588
+ * contiguously preceding in memory the content currently
589
+ * being compressed.
590
+ * - usingExtDict : Like withPrefix64k, but the preceding content is somewhere
591
+ * else in memory, starting at ctx->dictionary with length
592
+ * ctx->dictSize.
593
+ * - usingDictCtx : Everything concerning the preceding content is
594
+ * in a separate context, pointed to by ctx->dictCtx.
595
+ * ctx->dictionary, ctx->dictSize, and table entries
596
+ * in the current context that refer to positions
597
+ * preceding the beginning of the current compression are
598
+ * ignored. Instead, ctx->dictCtx->dictionary and ctx->dictCtx
599
+ * ->dictSize describe the location and size of the preceding
600
+ * content, and matches are found by looking in the ctx
601
+ * ->dictCtx->hashTable.
602
+ */
603
+ typedef enum { noDict = 0, withPrefix64k, usingExtDict, usingDictCtx } dict_directive;
604
+ typedef enum { noDictIssue = 0, dictSmall } dictIssue_directive;
605
+
606
+
607
+ /*-************************************
608
+ * Local Utils
609
+ **************************************/
610
+ int LZ4_versionNumber (void) { return LZ4_VERSION_NUMBER; }
611
+ const char* LZ4_versionString(void) { return LZ4_VERSION_STRING; }
612
+ int LZ4_compressBound(int isize) { return LZ4_COMPRESSBOUND(isize); }
613
+ int LZ4_sizeofState(void) { return sizeof(LZ4_stream_t); }
614
+
615
+
616
+ /*-****************************************
617
+ * Internal Definitions, used only in Tests
618
+ *******************************************/
619
+ //#if defined (__cplusplus)
620
+ //extern "C" {
621
+ //#endif
622
+
623
+ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int srcSize);
624
+
625
+ int LZ4_decompress_safe_forceExtDict(const char* source, char* dest,
626
+ int compressedSize, int maxOutputSize,
627
+ const void* dictStart, size_t dictSize);
628
+ int LZ4_decompress_safe_partial_forceExtDict(const char* source, char* dest,
629
+ int compressedSize, int targetOutputSize, int dstCapacity,
630
+ const void* dictStart, size_t dictSize);
631
+ //#if defined (__cplusplus)
632
+ //}
633
+ //#endif
634
+
635
+ /*-******************************
636
+ * Compression functions
637
+ ********************************/
638
+ LZ4_FORCE_INLINE U32 LZ4_hash4(U32 sequence, tableType_t const tableType)
639
+ {
640
+ if (tableType == byU16)
641
+ return ((sequence * 2654435761U) >> ((MINMATCH*8)-(LZ4_HASHLOG+1)));
642
+ else
643
+ return ((sequence * 2654435761U) >> ((MINMATCH*8)-LZ4_HASHLOG));
644
+ }
645
+
646
+ LZ4_FORCE_INLINE U32 LZ4_hash5(U64 sequence, tableType_t const tableType)
647
+ {
648
+ const U32 hashLog = (tableType == byU16) ? LZ4_HASHLOG+1 : LZ4_HASHLOG;
649
+ if (LZ4_isLittleEndian()) {
650
+ const U64 prime5bytes = 889523592379ULL;
651
+ return (U32)(((sequence << 24) * prime5bytes) >> (64 - hashLog));
652
+ } else {
653
+ const U64 prime8bytes = 11400714785074694791ULL;
654
+ return (U32)(((sequence >> 24) * prime8bytes) >> (64 - hashLog));
655
+ }
656
+ }
657
+
658
+ LZ4_FORCE_INLINE U32 LZ4_hashPosition(const void* const p, tableType_t const tableType)
659
+ {
660
+ if ((sizeof(reg_t)==8) && (tableType != byU16)) return LZ4_hash5(LZ4_read_ARCH(p), tableType);
661
+ return LZ4_hash4(LZ4_read32(p), tableType);
662
+ }
663
+
664
+ LZ4_FORCE_INLINE void LZ4_clearHash(U32 h, void* tableBase, tableType_t const tableType)
665
+ {
666
+ switch (tableType)
667
+ {
668
+ default: /* fallthrough */
669
+ case clearedTable: { /* illegal! */ assert(0); return; }
670
+ case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = NULL; return; }
671
+ case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = 0; return; }
672
+ case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = 0; return; }
673
+ }
674
+ }
675
+
676
+ LZ4_FORCE_INLINE void LZ4_putIndexOnHash(U32 idx, U32 h, void* tableBase, tableType_t const tableType)
677
+ {
678
+ switch (tableType)
679
+ {
680
+ default: /* fallthrough */
681
+ case clearedTable: /* fallthrough */
682
+ case byPtr: { /* illegal! */ assert(0); return; }
683
+ case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = idx; return; }
684
+ case byU16: { U16* hashTable = (U16*) tableBase; assert(idx < 65536); hashTable[h] = (U16)idx; return; }
685
+ }
686
+ }
687
+
688
+ LZ4_FORCE_INLINE void LZ4_putPositionOnHash(const BYTE* p, U32 h,
689
+ void* tableBase, tableType_t const tableType,
690
+ const BYTE* srcBase)
691
+ {
692
+ switch (tableType)
693
+ {
694
+ case clearedTable: { /* illegal! */ assert(0); return; }
695
+ case byPtr: { const BYTE** hashTable = (const BYTE**)tableBase; hashTable[h] = p; return; }
696
+ case byU32: { U32* hashTable = (U32*) tableBase; hashTable[h] = (U32)(p-srcBase); return; }
697
+ case byU16: { U16* hashTable = (U16*) tableBase; hashTable[h] = (U16)(p-srcBase); return; }
698
+ }
699
+ }
700
+
701
+ LZ4_FORCE_INLINE void LZ4_putPosition(const BYTE* p, void* tableBase, tableType_t tableType, const BYTE* srcBase)
702
+ {
703
+ U32 const h = LZ4_hashPosition(p, tableType);
704
+ LZ4_putPositionOnHash(p, h, tableBase, tableType, srcBase);
705
+ }
706
+
707
+ /* LZ4_getIndexOnHash() :
708
+ * Index of match position registered in hash table.
709
+ * hash position must be calculated by using base+index, or dictBase+index.
710
+ * Assumption 1 : only valid if tableType == byU32 or byU16.
711
+ * Assumption 2 : h is presumed valid (within limits of hash table)
712
+ */
713
+ LZ4_FORCE_INLINE U32 LZ4_getIndexOnHash(U32 h, const void* tableBase, tableType_t tableType)
714
+ {
715
+ LZ4_STATIC_ASSERT(LZ4_MEMORY_USAGE > 2);
716
+ if (tableType == byU32) {
717
+ const U32* const hashTable = (const U32*) tableBase;
718
+ assert(h < (1U << (LZ4_MEMORY_USAGE-2)));
719
+ return hashTable[h];
720
+ }
721
+ if (tableType == byU16) {
722
+ const U16* const hashTable = (const U16*) tableBase;
723
+ assert(h < (1U << (LZ4_MEMORY_USAGE-1)));
724
+ return hashTable[h];
725
+ }
726
+ assert(0); return 0; /* forbidden case */
727
+ }
728
+
729
+ static const BYTE* LZ4_getPositionOnHash(U32 h, const void* tableBase, tableType_t tableType, const BYTE* srcBase)
730
+ {
731
+ if (tableType == byPtr) { const BYTE* const* hashTable = (const BYTE* const*) tableBase; return hashTable[h]; }
732
+ if (tableType == byU32) { const U32* const hashTable = (const U32*) tableBase; return hashTable[h] + srcBase; }
733
+ { const U16* const hashTable = (const U16*) tableBase; return hashTable[h] + srcBase; } /* default, to ensure a return */
734
+ }
735
+
736
+ LZ4_FORCE_INLINE const BYTE*
737
+ LZ4_getPosition(const BYTE* p,
738
+ const void* tableBase, tableType_t tableType,
739
+ const BYTE* srcBase)
740
+ {
741
+ U32 const h = LZ4_hashPosition(p, tableType);
742
+ return LZ4_getPositionOnHash(h, tableBase, tableType, srcBase);
743
+ }
744
+
745
+ LZ4_FORCE_INLINE void
746
+ LZ4_prepareTable(LZ4_stream_t_internal* const cctx,
747
+ const int inputSize,
748
+ const tableType_t tableType) {
749
+ /* If the table hasn't been used, it's guaranteed to be zeroed out, and is
750
+ * therefore safe to use no matter what mode we're in. Otherwise, we figure
751
+ * out if it's safe to leave as is or whether it needs to be reset.
752
+ */
753
+ if ((tableType_t)cctx->tableType != clearedTable) {
754
+ assert(inputSize >= 0);
755
+ if ((tableType_t)cctx->tableType != tableType
756
+ || ((tableType == byU16) && cctx->currentOffset + (unsigned)inputSize >= 0xFFFFU)
757
+ || ((tableType == byU32) && cctx->currentOffset > 1 GB)
758
+ || tableType == byPtr
759
+ || inputSize >= 4 KB)
760
+ {
761
+ DEBUGLOG(4, "LZ4_prepareTable: Resetting table in %p", cctx);
762
+ MEM_INIT(cctx->hashTable, 0, LZ4_HASHTABLESIZE);
763
+ cctx->currentOffset = 0;
764
+ cctx->tableType = (U32)clearedTable;
765
+ } else {
766
+ DEBUGLOG(4, "LZ4_prepareTable: Re-use hash table (no reset)");
767
+ }
768
+ }
769
+
770
+ /* Adding a gap, so all previous entries are > LZ4_DISTANCE_MAX back,
771
+ * is faster than compressing without a gap.
772
+ * However, compressing with currentOffset == 0 is faster still,
773
+ * so we preserve that case.
774
+ */
775
+ if (cctx->currentOffset != 0 && tableType == byU32) {
776
+ DEBUGLOG(5, "LZ4_prepareTable: adding 64KB to currentOffset");
777
+ cctx->currentOffset += 64 KB;
778
+ }
779
+
780
+ /* Finally, clear history */
781
+ cctx->dictCtx = NULL;
782
+ cctx->dictionary = NULL;
783
+ cctx->dictSize = 0;
784
+ }
785
+
786
+ /** LZ4_compress_generic() :
787
+ * inlined, to ensure branches are decided at compilation time.
788
+ * Presumed already validated at this stage:
789
+ * - source != NULL
790
+ * - inputSize > 0
791
+ */
792
+ LZ4_FORCE_INLINE int LZ4_compress_generic_validated(
793
+ LZ4_stream_t_internal* const cctx,
794
+ const char* const source,
795
+ char* const dest,
796
+ const int inputSize,
797
+ int* inputConsumed, /* only written when outputDirective == fillOutput */
798
+ const int maxOutputSize,
799
+ const limitedOutput_directive outputDirective,
800
+ const tableType_t tableType,
801
+ const dict_directive dictDirective,
802
+ const dictIssue_directive dictIssue,
803
+ const int acceleration)
804
+ {
805
+ int result;
806
+ const BYTE* ip = (const BYTE*) source;
807
+
808
+ U32 const startIndex = cctx->currentOffset;
809
+ const BYTE* base = (const BYTE*) source - startIndex;
810
+ const BYTE* lowLimit;
811
+
812
+ const LZ4_stream_t_internal* dictCtx = (const LZ4_stream_t_internal*) cctx->dictCtx;
813
+ const BYTE* const dictionary =
814
+ dictDirective == usingDictCtx ? dictCtx->dictionary : cctx->dictionary;
815
+ const U32 dictSize =
816
+ dictDirective == usingDictCtx ? dictCtx->dictSize : cctx->dictSize;
817
+ const U32 dictDelta = (dictDirective == usingDictCtx) ? startIndex - dictCtx->currentOffset : 0; /* make indexes in dictCtx comparable with index in current context */
818
+
819
+ int const maybe_extMem = (dictDirective == usingExtDict) || (dictDirective == usingDictCtx);
820
+ U32 const prefixIdxLimit = startIndex - dictSize; /* used when dictDirective == dictSmall */
821
+ const BYTE* const dictEnd = dictionary ? dictionary + dictSize : dictionary;
822
+ const BYTE* anchor = (const BYTE*) source;
823
+ const BYTE* const iend = ip + inputSize;
824
+ const BYTE* const mflimitPlusOne = iend - MFLIMIT + 1;
825
+ const BYTE* const matchlimit = iend - LASTLITERALS;
826
+
827
+ /* the dictCtx currentOffset is indexed on the start of the dictionary,
828
+ * while a dictionary in the current context precedes the currentOffset */
829
+ const BYTE* dictBase = (dictionary == NULL) ? NULL :
830
+ (dictDirective == usingDictCtx) ?
831
+ dictionary + dictSize - dictCtx->currentOffset :
832
+ dictionary + dictSize - startIndex;
833
+
834
+ BYTE* op = (BYTE*) dest;
835
+ BYTE* const olimit = op + maxOutputSize;
836
+
837
+ U32 offset = 0;
838
+ U32 forwardH;
839
+
840
+ DEBUGLOG(5, "LZ4_compress_generic_validated: srcSize=%i, tableType=%u", inputSize, tableType);
841
+ assert(ip != NULL);
842
+ /* If init conditions are not met, we don't have to mark stream
843
+ * as having dirty context, since no action was taken yet */
844
+ if (outputDirective == fillOutput && maxOutputSize < 1) { return 0; } /* Impossible to store anything */
845
+ if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) { return 0; } /* Size too large (not within 64K limit) */
846
+ if (tableType==byPtr) assert(dictDirective==noDict); /* only supported use case with byPtr */
847
+ assert(acceleration >= 1);
848
+
849
+ lowLimit = (const BYTE*)source - (dictDirective == withPrefix64k ? dictSize : 0);
850
+
851
+ /* Update context state */
852
+ if (dictDirective == usingDictCtx) {
853
+ /* Subsequent linked blocks can't use the dictionary. */
854
+ /* Instead, they use the block we just compressed. */
855
+ cctx->dictCtx = NULL;
856
+ cctx->dictSize = (U32)inputSize;
857
+ } else {
858
+ cctx->dictSize += (U32)inputSize;
859
+ }
860
+ cctx->currentOffset += (U32)inputSize;
861
+ cctx->tableType = (U32)tableType;
862
+
863
+ if (inputSize<LZ4_minLength) goto _last_literals; /* Input too small, no compression (all literals) */
864
+
865
+ /* First Byte */
866
+ LZ4_putPosition(ip, cctx->hashTable, tableType, base);
867
+ ip++; forwardH = LZ4_hashPosition(ip, tableType);
868
+
869
+ /* Main Loop */
870
+ for ( ; ; ) {
871
+ const BYTE* match;
872
+ BYTE* token;
873
+ const BYTE* filledIp;
874
+
875
+ /* Find a match */
876
+ if (tableType == byPtr) {
877
+ const BYTE* forwardIp = ip;
878
+ int step = 1;
879
+ int searchMatchNb = acceleration << LZ4_skipTrigger;
880
+ do {
881
+ U32 const h = forwardH;
882
+ ip = forwardIp;
883
+ forwardIp += step;
884
+ step = (searchMatchNb++ >> LZ4_skipTrigger);
885
+
886
+ if (unlikely(forwardIp > mflimitPlusOne)) goto _last_literals;
887
+ assert(ip < mflimitPlusOne);
888
+
889
+ match = LZ4_getPositionOnHash(h, cctx->hashTable, tableType, base);
890
+ forwardH = LZ4_hashPosition(forwardIp, tableType);
891
+ LZ4_putPositionOnHash(ip, h, cctx->hashTable, tableType, base);
892
+
893
+ } while ( (match+LZ4_DISTANCE_MAX < ip)
894
+ || (LZ4_read32(match) != LZ4_read32(ip)) );
895
+
896
+ } else { /* byU32, byU16 */
897
+
898
+ const BYTE* forwardIp = ip;
899
+ int step = 1;
900
+ int searchMatchNb = acceleration << LZ4_skipTrigger;
901
+ do {
902
+ U32 const h = forwardH;
903
+ U32 const current = (U32)(forwardIp - base);
904
+ U32 matchIndex = LZ4_getIndexOnHash(h, cctx->hashTable, tableType);
905
+ assert(matchIndex <= current);
906
+ assert(forwardIp - base < (ptrdiff_t)(2 GB - 1));
907
+ ip = forwardIp;
908
+ forwardIp += step;
909
+ step = (searchMatchNb++ >> LZ4_skipTrigger);
910
+
911
+ if (unlikely(forwardIp > mflimitPlusOne)) goto _last_literals;
912
+ assert(ip < mflimitPlusOne);
913
+
914
+ if (dictDirective == usingDictCtx) {
915
+ if (matchIndex < startIndex) {
916
+ /* there was no match, try the dictionary */
917
+ assert(tableType == byU32);
918
+ matchIndex = LZ4_getIndexOnHash(h, dictCtx->hashTable, byU32);
919
+ match = dictBase + matchIndex;
920
+ matchIndex += dictDelta; /* make dictCtx index comparable with current context */
921
+ lowLimit = dictionary;
922
+ } else {
923
+ match = base + matchIndex;
924
+ lowLimit = (const BYTE*)source;
925
+ }
926
+ } else if (dictDirective == usingExtDict) {
927
+ if (matchIndex < startIndex) {
928
+ DEBUGLOG(7, "extDict candidate: matchIndex=%5u < startIndex=%5u", matchIndex, startIndex);
929
+ assert(startIndex - matchIndex >= MINMATCH);
930
+ assert(dictBase);
931
+ match = dictBase + matchIndex;
932
+ lowLimit = dictionary;
933
+ } else {
934
+ match = base + matchIndex;
935
+ lowLimit = (const BYTE*)source;
936
+ }
937
+ } else { /* single continuous memory segment */
938
+ match = base + matchIndex;
939
+ }
940
+ forwardH = LZ4_hashPosition(forwardIp, tableType);
941
+ LZ4_putIndexOnHash(current, h, cctx->hashTable, tableType);
942
+
943
+ DEBUGLOG(7, "candidate at pos=%u (offset=%u \n", matchIndex, current - matchIndex);
944
+ if ((dictIssue == dictSmall) && (matchIndex < prefixIdxLimit)) { continue; } /* match outside of valid area */
945
+ assert(matchIndex < current);
946
+ if ( ((tableType != byU16) || (LZ4_DISTANCE_MAX < LZ4_DISTANCE_ABSOLUTE_MAX))
947
+ && (matchIndex+LZ4_DISTANCE_MAX < current)) {
948
+ continue;
949
+ } /* too far */
950
+ assert((current - matchIndex) <= LZ4_DISTANCE_MAX); /* match now expected within distance */
951
+
952
+ if (LZ4_read32(match) == LZ4_read32(ip)) {
953
+ if (maybe_extMem) offset = current - matchIndex;
954
+ break; /* match found */
955
+ }
956
+
957
+ } while(1);
958
+ }
959
+
960
+ /* Catch up */
961
+ filledIp = ip;
962
+ while (((ip>anchor) & (match > lowLimit)) && (unlikely(ip[-1]==match[-1]))) { ip--; match--; }
963
+
964
+ /* Encode Literals */
965
+ { unsigned const litLength = (unsigned)(ip - anchor);
966
+ token = op++;
967
+ if ((outputDirective == limitedOutput) && /* Check output buffer overflow */
968
+ (unlikely(op + litLength + (2 + 1 + LASTLITERALS) + (litLength/255) > olimit)) ) {
969
+ return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
970
+ }
971
+ if ((outputDirective == fillOutput) &&
972
+ (unlikely(op + (litLength+240)/255 /* litlen */ + litLength /* literals */ + 2 /* offset */ + 1 /* token */ + MFLIMIT - MINMATCH /* min last literals so last match is <= end - MFLIMIT */ > olimit))) {
973
+ op--;
974
+ goto _last_literals;
975
+ }
976
+ if (litLength >= RUN_MASK) {
977
+ int len = (int)(litLength - RUN_MASK);
978
+ *token = (RUN_MASK<<ML_BITS);
979
+ for(; len >= 255 ; len-=255) *op++ = 255;
980
+ *op++ = (BYTE)len;
981
+ }
982
+ else *token = (BYTE)(litLength<<ML_BITS);
983
+
984
+ /* Copy Literals */
985
+ LZ4_wildCopy8(op, anchor, op+litLength);
986
+ op+=litLength;
987
+ DEBUGLOG(6, "seq.start:%i, literals=%u, match.start:%i",
988
+ (int)(anchor-(const BYTE*)source), litLength, (int)(ip-(const BYTE*)source));
989
+ }
990
+
991
+ _next_match:
992
+ /* at this stage, the following variables must be correctly set :
993
+ * - ip : at start of LZ operation
994
+ * - match : at start of previous pattern occurrence; can be within current prefix, or within extDict
995
+ * - offset : if maybe_ext_memSegment==1 (constant)
996
+ * - lowLimit : must be == dictionary to mean "match is within extDict"; must be == source otherwise
997
+ * - token and *token : position to write 4-bits for match length; higher 4-bits for literal length supposed already written
998
+ */
999
+
1000
+ if ((outputDirective == fillOutput) &&
1001
+ (op + 2 /* offset */ + 1 /* token */ + MFLIMIT - MINMATCH /* min last literals so last match is <= end - MFLIMIT */ > olimit)) {
1002
+ /* the match was too close to the end, rewind and go to last literals */
1003
+ op = token;
1004
+ goto _last_literals;
1005
+ }
1006
+
1007
+ /* Encode Offset */
1008
+ if (maybe_extMem) { /* static test */
1009
+ DEBUGLOG(6, " with offset=%u (ext if > %i)", offset, (int)(ip - (const BYTE*)source));
1010
+ assert(offset <= LZ4_DISTANCE_MAX && offset > 0);
1011
+ LZ4_writeLE16(op, (U16)offset); op+=2;
1012
+ } else {
1013
+ DEBUGLOG(6, " with offset=%u (same segment)", (U32)(ip - match));
1014
+ assert(ip-match <= LZ4_DISTANCE_MAX);
1015
+ LZ4_writeLE16(op, (U16)(ip - match)); op+=2;
1016
+ }
1017
+
1018
+ /* Encode MatchLength */
1019
+ { unsigned matchCode;
1020
+
1021
+ if ( (dictDirective==usingExtDict || dictDirective==usingDictCtx)
1022
+ && (lowLimit==dictionary) /* match within extDict */ ) {
1023
+ const BYTE* limit = ip + (dictEnd-match);
1024
+ assert(dictEnd > match);
1025
+ if (limit > matchlimit) limit = matchlimit;
1026
+ matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, limit);
1027
+ ip += (size_t)matchCode + MINMATCH;
1028
+ if (ip==limit) {
1029
+ unsigned const more = LZ4_count(limit, (const BYTE*)source, matchlimit);
1030
+ matchCode += more;
1031
+ ip += more;
1032
+ }
1033
+ DEBUGLOG(6, " with matchLength=%u starting in extDict", matchCode+MINMATCH);
1034
+ } else {
1035
+ matchCode = LZ4_count(ip+MINMATCH, match+MINMATCH, matchlimit);
1036
+ ip += (size_t)matchCode + MINMATCH;
1037
+ DEBUGLOG(6, " with matchLength=%u", matchCode+MINMATCH);
1038
+ }
1039
+
1040
+ if ((outputDirective) && /* Check output buffer overflow */
1041
+ (unlikely(op + (1 + LASTLITERALS) + (matchCode+240)/255 > olimit)) ) {
1042
+ if (outputDirective == fillOutput) {
1043
+ /* Match description too long : reduce it */
1044
+ U32 newMatchCode = 15 /* in token */ - 1 /* to avoid needing a zero byte */ + ((U32)(olimit - op) - 1 - LASTLITERALS) * 255;
1045
+ ip -= matchCode - newMatchCode;
1046
+ assert(newMatchCode < matchCode);
1047
+ matchCode = newMatchCode;
1048
+ if (unlikely(ip <= filledIp)) {
1049
+ /* We have already filled up to filledIp so if ip ends up less than filledIp
1050
+ * we have positions in the hash table beyond the current position. This is
1051
+ * a problem if we reuse the hash table. So we have to remove these positions
1052
+ * from the hash table.
1053
+ */
1054
+ const BYTE* ptr;
1055
+ DEBUGLOG(5, "Clearing %u positions", (U32)(filledIp - ip));
1056
+ for (ptr = ip; ptr <= filledIp; ++ptr) {
1057
+ U32 const h = LZ4_hashPosition(ptr, tableType);
1058
+ LZ4_clearHash(h, cctx->hashTable, tableType);
1059
+ }
1060
+ }
1061
+ } else {
1062
+ assert(outputDirective == limitedOutput);
1063
+ return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
1064
+ }
1065
+ }
1066
+ if (matchCode >= ML_MASK) {
1067
+ *token += ML_MASK;
1068
+ matchCode -= ML_MASK;
1069
+ LZ4_write32(op, 0xFFFFFFFF);
1070
+ while (matchCode >= 4*255) {
1071
+ op+=4;
1072
+ LZ4_write32(op, 0xFFFFFFFF);
1073
+ matchCode -= 4*255;
1074
+ }
1075
+ op += matchCode / 255;
1076
+ *op++ = (BYTE)(matchCode % 255);
1077
+ } else
1078
+ *token += (BYTE)(matchCode);
1079
+ }
1080
+ /* Ensure we have enough space for the last literals. */
1081
+ assert(!(outputDirective == fillOutput && op + 1 + LASTLITERALS > olimit));
1082
+
1083
+ anchor = ip;
1084
+
1085
+ /* Test end of chunk */
1086
+ if (ip >= mflimitPlusOne) break;
1087
+
1088
+ /* Fill table */
1089
+ LZ4_putPosition(ip-2, cctx->hashTable, tableType, base);
1090
+
1091
+ /* Test next position */
1092
+ if (tableType == byPtr) {
1093
+
1094
+ match = LZ4_getPosition(ip, cctx->hashTable, tableType, base);
1095
+ LZ4_putPosition(ip, cctx->hashTable, tableType, base);
1096
+ if ( (match+LZ4_DISTANCE_MAX >= ip)
1097
+ && (LZ4_read32(match) == LZ4_read32(ip)) )
1098
+ { token=op++; *token=0; goto _next_match; }
1099
+
1100
+ } else { /* byU32, byU16 */
1101
+
1102
+ U32 const h = LZ4_hashPosition(ip, tableType);
1103
+ U32 const current = (U32)(ip-base);
1104
+ U32 matchIndex = LZ4_getIndexOnHash(h, cctx->hashTable, tableType);
1105
+ assert(matchIndex < current);
1106
+ if (dictDirective == usingDictCtx) {
1107
+ if (matchIndex < startIndex) {
1108
+ /* there was no match, try the dictionary */
1109
+ matchIndex = LZ4_getIndexOnHash(h, dictCtx->hashTable, byU32);
1110
+ match = dictBase + matchIndex;
1111
+ lowLimit = dictionary; /* required for match length counter */
1112
+ matchIndex += dictDelta;
1113
+ } else {
1114
+ match = base + matchIndex;
1115
+ lowLimit = (const BYTE*)source; /* required for match length counter */
1116
+ }
1117
+ } else if (dictDirective==usingExtDict) {
1118
+ if (matchIndex < startIndex) {
1119
+ assert(dictBase);
1120
+ match = dictBase + matchIndex;
1121
+ lowLimit = dictionary; /* required for match length counter */
1122
+ } else {
1123
+ match = base + matchIndex;
1124
+ lowLimit = (const BYTE*)source; /* required for match length counter */
1125
+ }
1126
+ } else { /* single memory segment */
1127
+ match = base + matchIndex;
1128
+ }
1129
+ LZ4_putIndexOnHash(current, h, cctx->hashTable, tableType);
1130
+ assert(matchIndex < current);
1131
+ if ( ((dictIssue==dictSmall) ? (matchIndex >= prefixIdxLimit) : 1)
1132
+ && (((tableType==byU16) && (LZ4_DISTANCE_MAX == LZ4_DISTANCE_ABSOLUTE_MAX)) ? 1 : (matchIndex+LZ4_DISTANCE_MAX >= current))
1133
+ && (LZ4_read32(match) == LZ4_read32(ip)) ) {
1134
+ token=op++;
1135
+ *token=0;
1136
+ if (maybe_extMem) offset = current - matchIndex;
1137
+ DEBUGLOG(6, "seq.start:%i, literals=%u, match.start:%i",
1138
+ (int)(anchor-(const BYTE*)source), 0, (int)(ip-(const BYTE*)source));
1139
+ goto _next_match;
1140
+ }
1141
+ }
1142
+
1143
+ /* Prepare next loop */
1144
+ forwardH = LZ4_hashPosition(++ip, tableType);
1145
+
1146
+ }
1147
+
1148
+ _last_literals:
1149
+ /* Encode Last Literals */
1150
+ { size_t lastRun = (size_t)(iend - anchor);
1151
+ if ( (outputDirective) && /* Check output buffer overflow */
1152
+ (op + lastRun + 1 + ((lastRun+255-RUN_MASK)/255) > olimit)) {
1153
+ if (outputDirective == fillOutput) {
1154
+ /* adapt lastRun to fill 'dst' */
1155
+ assert(olimit >= op);
1156
+ lastRun = (size_t)(olimit-op) - 1/*token*/;
1157
+ lastRun -= (lastRun + 256 - RUN_MASK) / 256; /*additional length tokens*/
1158
+ } else {
1159
+ assert(outputDirective == limitedOutput);
1160
+ return 0; /* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
1161
+ }
1162
+ }
1163
+ DEBUGLOG(6, "Final literal run : %i literals", (int)lastRun);
1164
+ if (lastRun >= RUN_MASK) {
1165
+ size_t accumulator = lastRun - RUN_MASK;
1166
+ *op++ = RUN_MASK << ML_BITS;
1167
+ for(; accumulator >= 255 ; accumulator-=255) *op++ = 255;
1168
+ *op++ = (BYTE) accumulator;
1169
+ } else {
1170
+ *op++ = (BYTE)(lastRun<<ML_BITS);
1171
+ }
1172
+ LZ4_memcpy(op, anchor, lastRun);
1173
+ ip = anchor + lastRun;
1174
+ op += lastRun;
1175
+ }
1176
+
1177
+ if (outputDirective == fillOutput) {
1178
+ *inputConsumed = (int) (((const char*)ip)-source);
1179
+ }
1180
+ result = (int)(((char*)op) - dest);
1181
+ assert(result > 0);
1182
+ DEBUGLOG(5, "LZ4_compress_generic: compressed %i bytes into %i bytes", inputSize, result);
1183
+ return result;
1184
+ }
1185
+
1186
+ /** LZ4_compress_generic() :
1187
+ * inlined, to ensure branches are decided at compilation time;
1188
+ * takes care of src == (NULL, 0)
1189
+ * and forward the rest to LZ4_compress_generic_validated */
1190
+ LZ4_FORCE_INLINE int LZ4_compress_generic(
1191
+ LZ4_stream_t_internal* const cctx,
1192
+ const char* const src,
1193
+ char* const dst,
1194
+ const int srcSize,
1195
+ int *inputConsumed, /* only written when outputDirective == fillOutput */
1196
+ const int dstCapacity,
1197
+ const limitedOutput_directive outputDirective,
1198
+ const tableType_t tableType,
1199
+ const dict_directive dictDirective,
1200
+ const dictIssue_directive dictIssue,
1201
+ const int acceleration)
1202
+ {
1203
+ DEBUGLOG(5, "LZ4_compress_generic: srcSize=%i, dstCapacity=%i",
1204
+ srcSize, dstCapacity);
1205
+
1206
+ if ((U32)srcSize > (U32)LZ4_MAX_INPUT_SIZE) { return 0; } /* Unsupported srcSize, too large (or negative) */
1207
+ if (srcSize == 0) { /* src == NULL supported if srcSize == 0 */
1208
+ if (outputDirective != notLimited && dstCapacity <= 0) return 0; /* no output, can't write anything */
1209
+ DEBUGLOG(5, "Generating an empty block");
1210
+ assert(outputDirective == notLimited || dstCapacity >= 1);
1211
+ assert(dst != NULL);
1212
+ dst[0] = 0;
1213
+ if (outputDirective == fillOutput) {
1214
+ assert (inputConsumed != NULL);
1215
+ *inputConsumed = 0;
1216
+ }
1217
+ return 1;
1218
+ }
1219
+ assert(src != NULL);
1220
+
1221
+ return LZ4_compress_generic_validated(cctx, src, dst, srcSize,
1222
+ inputConsumed, /* only written into if outputDirective == fillOutput */
1223
+ dstCapacity, outputDirective,
1224
+ tableType, dictDirective, dictIssue, acceleration);
1225
+ }
1226
+
1227
+
1228
+ int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
1229
+ {
1230
+ LZ4_stream_t_internal* const ctx = & LZ4_initStream(state, sizeof(LZ4_stream_t)) -> internal_donotuse;
1231
+ assert(ctx != NULL);
1232
+ if (acceleration < 1) acceleration = LZ4_ACCELERATION_DEFAULT;
1233
+ if (acceleration > LZ4_ACCELERATION_MAX) acceleration = LZ4_ACCELERATION_MAX;
1234
+ if (maxOutputSize >= LZ4_compressBound(inputSize)) {
1235
+ if (inputSize < LZ4_64Klimit) {
1236
+ return LZ4_compress_generic(ctx, source, dest, inputSize, NULL, 0, notLimited, byU16, noDict, noDictIssue, acceleration);
1237
+ } else {
1238
+ const tableType_t tableType = ((sizeof(void*)==4) && ((uptrval)source > LZ4_DISTANCE_MAX)) ? byPtr : byU32;
1239
+ return LZ4_compress_generic(ctx, source, dest, inputSize, NULL, 0, notLimited, tableType, noDict, noDictIssue, acceleration);
1240
+ }
1241
+ } else {
1242
+ if (inputSize < LZ4_64Klimit) {
1243
+ return LZ4_compress_generic(ctx, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, byU16, noDict, noDictIssue, acceleration);
1244
+ } else {
1245
+ const tableType_t tableType = ((sizeof(void*)==4) && ((uptrval)source > LZ4_DISTANCE_MAX)) ? byPtr : byU32;
1246
+ return LZ4_compress_generic(ctx, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, tableType, noDict, noDictIssue, acceleration);
1247
+ }
1248
+ }
1249
+ }
1250
+
1251
+ /**
1252
+ * LZ4_compress_fast_extState_fastReset() :
1253
+ * A variant of LZ4_compress_fast_extState().
1254
+ *
1255
+ * Using this variant avoids an expensive initialization step. It is only safe
1256
+ * to call if the state buffer is known to be correctly initialized already
1257
+ * (see comment in lz4.h on LZ4_resetStream_fast() for a definition of
1258
+ * "correctly initialized").
1259
+ */
1260
+ int LZ4_compress_fast_extState_fastReset(void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration)
1261
+ {
1262
+ LZ4_stream_t_internal* ctx = &((LZ4_stream_t*)state)->internal_donotuse;
1263
+ if (acceleration < 1) acceleration = LZ4_ACCELERATION_DEFAULT;
1264
+ if (acceleration > LZ4_ACCELERATION_MAX) acceleration = LZ4_ACCELERATION_MAX;
1265
+
1266
+ if (dstCapacity >= LZ4_compressBound(srcSize)) {
1267
+ if (srcSize < LZ4_64Klimit) {
1268
+ const tableType_t tableType = byU16;
1269
+ LZ4_prepareTable(ctx, srcSize, tableType);
1270
+ if (ctx->currentOffset) {
1271
+ return LZ4_compress_generic(ctx, src, dst, srcSize, NULL, 0, notLimited, tableType, noDict, dictSmall, acceleration);
1272
+ } else {
1273
+ return LZ4_compress_generic(ctx, src, dst, srcSize, NULL, 0, notLimited, tableType, noDict, noDictIssue, acceleration);
1274
+ }
1275
+ } else {
1276
+ const tableType_t tableType = ((sizeof(void*)==4) && ((uptrval)src > LZ4_DISTANCE_MAX)) ? byPtr : byU32;
1277
+ LZ4_prepareTable(ctx, srcSize, tableType);
1278
+ return LZ4_compress_generic(ctx, src, dst, srcSize, NULL, 0, notLimited, tableType, noDict, noDictIssue, acceleration);
1279
+ }
1280
+ } else {
1281
+ if (srcSize < LZ4_64Klimit) {
1282
+ const tableType_t tableType = byU16;
1283
+ LZ4_prepareTable(ctx, srcSize, tableType);
1284
+ if (ctx->currentOffset) {
1285
+ return LZ4_compress_generic(ctx, src, dst, srcSize, NULL, dstCapacity, limitedOutput, tableType, noDict, dictSmall, acceleration);
1286
+ } else {
1287
+ return LZ4_compress_generic(ctx, src, dst, srcSize, NULL, dstCapacity, limitedOutput, tableType, noDict, noDictIssue, acceleration);
1288
+ }
1289
+ } else {
1290
+ const tableType_t tableType = ((sizeof(void*)==4) && ((uptrval)src > LZ4_DISTANCE_MAX)) ? byPtr : byU32;
1291
+ LZ4_prepareTable(ctx, srcSize, tableType);
1292
+ return LZ4_compress_generic(ctx, src, dst, srcSize, NULL, dstCapacity, limitedOutput, tableType, noDict, noDictIssue, acceleration);
1293
+ }
1294
+ }
1295
+ }
1296
+
1297
+
1298
+ int LZ4_compress_fast(const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
1299
+ {
1300
+ int result;
1301
+ #if (LZ4_HEAPMODE)
1302
+ LZ4_stream_t* ctxPtr = (LZ4_stream_t*)ALLOC(sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
1303
+ if (ctxPtr == NULL) return 0;
1304
+ #else
1305
+ LZ4_stream_t ctx;
1306
+ LZ4_stream_t* const ctxPtr = &ctx;
1307
+ #endif
1308
+ result = LZ4_compress_fast_extState(ctxPtr, source, dest, inputSize, maxOutputSize, acceleration);
1309
+
1310
+ #if (LZ4_HEAPMODE)
1311
+ FREEMEM(ctxPtr);
1312
+ #endif
1313
+ return result;
1314
+ }
1315
+
1316
+
1317
+ int LZ4_compress_default(const char* src, char* dst, int srcSize, int maxOutputSize)
1318
+ {
1319
+ return LZ4_compress_fast(src, dst, srcSize, maxOutputSize, 1);
1320
+ }
1321
+
1322
+
1323
+ /* Note!: This function leaves the stream in an unclean/broken state!
1324
+ * It is not safe to subsequently use the same state with a _fastReset() or
1325
+ * _continue() call without resetting it. */
1326
+ static int LZ4_compress_destSize_extState (LZ4_stream_t* state, const char* src, char* dst, int* srcSizePtr, int targetDstSize)
1327
+ {
1328
+ void* const s = LZ4_initStream(state, sizeof (*state));
1329
+ assert(s != NULL); (void)s;
1330
+
1331
+ if (targetDstSize >= LZ4_compressBound(*srcSizePtr)) { /* compression success is guaranteed */
1332
+ return LZ4_compress_fast_extState(state, src, dst, *srcSizePtr, targetDstSize, 1);
1333
+ } else {
1334
+ if (*srcSizePtr < LZ4_64Klimit) {
1335
+ return LZ4_compress_generic(&state->internal_donotuse, src, dst, *srcSizePtr, srcSizePtr, targetDstSize, fillOutput, byU16, noDict, noDictIssue, 1);
1336
+ } else {
1337
+ tableType_t const addrMode = ((sizeof(void*)==4) && ((uptrval)src > LZ4_DISTANCE_MAX)) ? byPtr : byU32;
1338
+ return LZ4_compress_generic(&state->internal_donotuse, src, dst, *srcSizePtr, srcSizePtr, targetDstSize, fillOutput, addrMode, noDict, noDictIssue, 1);
1339
+ } }
1340
+ }
1341
+
1342
+
1343
+ int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targetDstSize)
1344
+ {
1345
+ #if (LZ4_HEAPMODE)
1346
+ LZ4_stream_t* ctx = (LZ4_stream_t*)ALLOC(sizeof(LZ4_stream_t)); /* malloc-calloc always properly aligned */
1347
+ if (ctx == NULL) return 0;
1348
+ #else
1349
+ LZ4_stream_t ctxBody;
1350
+ LZ4_stream_t* ctx = &ctxBody;
1351
+ #endif
1352
+
1353
+ int result = LZ4_compress_destSize_extState(ctx, src, dst, srcSizePtr, targetDstSize);
1354
+
1355
+ #if (LZ4_HEAPMODE)
1356
+ FREEMEM(ctx);
1357
+ #endif
1358
+ return result;
1359
+ }
1360
+
1361
+
1362
+
1363
+ /*-******************************
1364
+ * Streaming functions
1365
+ ********************************/
1366
+
1367
+ #if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
1368
+ LZ4_stream_t* LZ4_createStream(void)
1369
+ {
1370
+ LZ4_stream_t* const lz4s = (LZ4_stream_t*)ALLOC(sizeof(LZ4_stream_t));
1371
+ LZ4_STATIC_ASSERT(sizeof(LZ4_stream_t) >= sizeof(LZ4_stream_t_internal));
1372
+ DEBUGLOG(4, "LZ4_createStream %p", lz4s);
1373
+ if (lz4s == NULL) return NULL;
1374
+ LZ4_initStream(lz4s, sizeof(*lz4s));
1375
+ return lz4s;
1376
+ }
1377
+ #endif
1378
+
1379
+ static size_t LZ4_stream_t_alignment(void)
1380
+ {
1381
+ #if LZ4_ALIGN_TEST
1382
+ typedef struct { char c; LZ4_stream_t t; } t_a;
1383
+ return sizeof(t_a) - sizeof(LZ4_stream_t);
1384
+ #else
1385
+ return 1; /* effectively disabled */
1386
+ #endif
1387
+ }
1388
+
1389
+ LZ4_stream_t* LZ4_initStream (void* buffer, size_t size)
1390
+ {
1391
+ DEBUGLOG(5, "LZ4_initStream");
1392
+ if (buffer == NULL) { return NULL; }
1393
+ if (size < sizeof(LZ4_stream_t)) { return NULL; }
1394
+ if (!LZ4_isAligned(buffer, LZ4_stream_t_alignment())) return NULL;
1395
+ MEM_INIT(buffer, 0, sizeof(LZ4_stream_t_internal));
1396
+ return (LZ4_stream_t*)buffer;
1397
+ }
1398
+
1399
+ /* resetStream is now deprecated,
1400
+ * prefer initStream() which is more general */
1401
+ void LZ4_resetStream (LZ4_stream_t* LZ4_stream)
1402
+ {
1403
+ DEBUGLOG(5, "LZ4_resetStream (ctx:%p)", LZ4_stream);
1404
+ MEM_INIT(LZ4_stream, 0, sizeof(LZ4_stream_t_internal));
1405
+ }
1406
+
1407
+ void LZ4_resetStream_fast(LZ4_stream_t* ctx) {
1408
+ LZ4_prepareTable(&(ctx->internal_donotuse), 0, byU32);
1409
+ }
1410
+
1411
+ #if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
1412
+ int LZ4_freeStream (LZ4_stream_t* LZ4_stream)
1413
+ {
1414
+ if (!LZ4_stream) return 0; /* support free on NULL */
1415
+ DEBUGLOG(5, "LZ4_freeStream %p", LZ4_stream);
1416
+ FREEMEM(LZ4_stream);
1417
+ return (0);
1418
+ }
1419
+ #endif
1420
+
1421
+
1422
+ #define HASH_UNIT sizeof(reg_t)
1423
+ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
1424
+ {
1425
+ LZ4_stream_t_internal* dict = &LZ4_dict->internal_donotuse;
1426
+ const tableType_t tableType = byU32;
1427
+ const BYTE* p = (const BYTE*)dictionary;
1428
+ const BYTE* const dictEnd = p + dictSize;
1429
+ const BYTE* base;
1430
+
1431
+ DEBUGLOG(4, "LZ4_loadDict (%i bytes from %p into %p)", dictSize, dictionary, LZ4_dict);
1432
+
1433
+ /* It's necessary to reset the context,
1434
+ * and not just continue it with prepareTable()
1435
+ * to avoid any risk of generating overflowing matchIndex
1436
+ * when compressing using this dictionary */
1437
+ LZ4_resetStream(LZ4_dict);
1438
+
1439
+ /* We always increment the offset by 64 KB, since, if the dict is longer,
1440
+ * we truncate it to the last 64k, and if it's shorter, we still want to
1441
+ * advance by a whole window length so we can provide the guarantee that
1442
+ * there are only valid offsets in the window, which allows an optimization
1443
+ * in LZ4_compress_fast_continue() where it uses noDictIssue even when the
1444
+ * dictionary isn't a full 64k. */
1445
+ dict->currentOffset += 64 KB;
1446
+
1447
+ if (dictSize < (int)HASH_UNIT) {
1448
+ return 0;
1449
+ }
1450
+
1451
+ if ((dictEnd - p) > 64 KB) p = dictEnd - 64 KB;
1452
+ base = dictEnd - dict->currentOffset;
1453
+ dict->dictionary = p;
1454
+ dict->dictSize = (U32)(dictEnd - p);
1455
+ dict->tableType = (U32)tableType;
1456
+
1457
+ while (p <= dictEnd-HASH_UNIT) {
1458
+ LZ4_putPosition(p, dict->hashTable, tableType, base);
1459
+ p+=3;
1460
+ }
1461
+
1462
+ return (int)dict->dictSize;
1463
+ }
1464
+
1465
+ void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream)
1466
+ {
1467
+ const LZ4_stream_t_internal* dictCtx = (dictionaryStream == NULL) ? NULL :
1468
+ &(dictionaryStream->internal_donotuse);
1469
+
1470
+ DEBUGLOG(4, "LZ4_attach_dictionary (%p, %p, size %u)",
1471
+ workingStream, dictionaryStream,
1472
+ dictCtx != NULL ? dictCtx->dictSize : 0);
1473
+
1474
+ if (dictCtx != NULL) {
1475
+ /* If the current offset is zero, we will never look in the
1476
+ * external dictionary context, since there is no value a table
1477
+ * entry can take that indicate a miss. In that case, we need
1478
+ * to bump the offset to something non-zero.
1479
+ */
1480
+ if (workingStream->internal_donotuse.currentOffset == 0) {
1481
+ workingStream->internal_donotuse.currentOffset = 64 KB;
1482
+ }
1483
+
1484
+ /* Don't actually attach an empty dictionary.
1485
+ */
1486
+ if (dictCtx->dictSize == 0) {
1487
+ dictCtx = NULL;
1488
+ }
1489
+ }
1490
+ workingStream->internal_donotuse.dictCtx = dictCtx;
1491
+ }
1492
+
1493
+
1494
+ static void LZ4_renormDictT(LZ4_stream_t_internal* LZ4_dict, int nextSize)
1495
+ {
1496
+ assert(nextSize >= 0);
1497
+ if (LZ4_dict->currentOffset + (unsigned)nextSize > 0x80000000) { /* potential ptrdiff_t overflow (32-bits mode) */
1498
+ /* rescale hash table */
1499
+ U32 const delta = LZ4_dict->currentOffset - 64 KB;
1500
+ const BYTE* dictEnd = LZ4_dict->dictionary + LZ4_dict->dictSize;
1501
+ int i;
1502
+ DEBUGLOG(4, "LZ4_renormDictT");
1503
+ for (i=0; i<LZ4_HASH_SIZE_U32; i++) {
1504
+ if (LZ4_dict->hashTable[i] < delta) LZ4_dict->hashTable[i]=0;
1505
+ else LZ4_dict->hashTable[i] -= delta;
1506
+ }
1507
+ LZ4_dict->currentOffset = 64 KB;
1508
+ if (LZ4_dict->dictSize > 64 KB) LZ4_dict->dictSize = 64 KB;
1509
+ LZ4_dict->dictionary = dictEnd - LZ4_dict->dictSize;
1510
+ }
1511
+ }
1512
+
1513
+
1514
+ int LZ4_compress_fast_continue (LZ4_stream_t* LZ4_stream,
1515
+ const char* source, char* dest,
1516
+ int inputSize, int maxOutputSize,
1517
+ int acceleration)
1518
+ {
1519
+ const tableType_t tableType = byU32;
1520
+ LZ4_stream_t_internal* const streamPtr = &LZ4_stream->internal_donotuse;
1521
+ const char* dictEnd = streamPtr->dictSize ? (const char*)streamPtr->dictionary + streamPtr->dictSize : NULL;
1522
+
1523
+ DEBUGLOG(5, "LZ4_compress_fast_continue (inputSize=%i, dictSize=%u)", inputSize, streamPtr->dictSize);
1524
+
1525
+ LZ4_renormDictT(streamPtr, inputSize); /* fix index overflow */
1526
+ if (acceleration < 1) acceleration = LZ4_ACCELERATION_DEFAULT;
1527
+ if (acceleration > LZ4_ACCELERATION_MAX) acceleration = LZ4_ACCELERATION_MAX;
1528
+
1529
+ /* invalidate tiny dictionaries */
1530
+ if ( (streamPtr->dictSize < 4) /* tiny dictionary : not enough for a hash */
1531
+ && (dictEnd != source) /* prefix mode */
1532
+ && (inputSize > 0) /* tolerance : don't lose history, in case next invocation would use prefix mode */
1533
+ && (streamPtr->dictCtx == NULL) /* usingDictCtx */
1534
+ ) {
1535
+ DEBUGLOG(5, "LZ4_compress_fast_continue: dictSize(%u) at addr:%p is too small", streamPtr->dictSize, streamPtr->dictionary);
1536
+ /* remove dictionary existence from history, to employ faster prefix mode */
1537
+ streamPtr->dictSize = 0;
1538
+ streamPtr->dictionary = (const BYTE*)source;
1539
+ dictEnd = source;
1540
+ }
1541
+
1542
+ /* Check overlapping input/dictionary space */
1543
+ { const char* const sourceEnd = source + inputSize;
1544
+ if ((sourceEnd > (const char*)streamPtr->dictionary) && (sourceEnd < dictEnd)) {
1545
+ streamPtr->dictSize = (U32)(dictEnd - sourceEnd);
1546
+ if (streamPtr->dictSize > 64 KB) streamPtr->dictSize = 64 KB;
1547
+ if (streamPtr->dictSize < 4) streamPtr->dictSize = 0;
1548
+ streamPtr->dictionary = (const BYTE*)dictEnd - streamPtr->dictSize;
1549
+ }
1550
+ }
1551
+
1552
+ /* prefix mode : source data follows dictionary */
1553
+ if (dictEnd == source) {
1554
+ if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset))
1555
+ return LZ4_compress_generic(streamPtr, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, tableType, withPrefix64k, dictSmall, acceleration);
1556
+ else
1557
+ return LZ4_compress_generic(streamPtr, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, tableType, withPrefix64k, noDictIssue, acceleration);
1558
+ }
1559
+
1560
+ /* external dictionary mode */
1561
+ { int result;
1562
+ if (streamPtr->dictCtx) {
1563
+ /* We depend here on the fact that dictCtx'es (produced by
1564
+ * LZ4_loadDict) guarantee that their tables contain no references
1565
+ * to offsets between dictCtx->currentOffset - 64 KB and
1566
+ * dictCtx->currentOffset - dictCtx->dictSize. This makes it safe
1567
+ * to use noDictIssue even when the dict isn't a full 64 KB.
1568
+ */
1569
+ if (inputSize > 4 KB) {
1570
+ /* For compressing large blobs, it is faster to pay the setup
1571
+ * cost to copy the dictionary's tables into the active context,
1572
+ * so that the compression loop is only looking into one table.
1573
+ */
1574
+ LZ4_memcpy(streamPtr, streamPtr->dictCtx, sizeof(*streamPtr));
1575
+ result = LZ4_compress_generic(streamPtr, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, tableType, usingExtDict, noDictIssue, acceleration);
1576
+ } else {
1577
+ result = LZ4_compress_generic(streamPtr, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, tableType, usingDictCtx, noDictIssue, acceleration);
1578
+ }
1579
+ } else { /* small data <= 4 KB */
1580
+ if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) {
1581
+ result = LZ4_compress_generic(streamPtr, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, tableType, usingExtDict, dictSmall, acceleration);
1582
+ } else {
1583
+ result = LZ4_compress_generic(streamPtr, source, dest, inputSize, NULL, maxOutputSize, limitedOutput, tableType, usingExtDict, noDictIssue, acceleration);
1584
+ }
1585
+ }
1586
+ streamPtr->dictionary = (const BYTE*)source;
1587
+ streamPtr->dictSize = (U32)inputSize;
1588
+ return result;
1589
+ }
1590
+ }
1591
+
1592
+
1593
+ /* Hidden debug function, to force-test external dictionary mode */
1594
+ int LZ4_compress_forceExtDict (LZ4_stream_t* LZ4_dict, const char* source, char* dest, int srcSize)
1595
+ {
1596
+ LZ4_stream_t_internal* streamPtr = &LZ4_dict->internal_donotuse;
1597
+ int result;
1598
+
1599
+ LZ4_renormDictT(streamPtr, srcSize);
1600
+
1601
+ if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) {
1602
+ result = LZ4_compress_generic(streamPtr, source, dest, srcSize, NULL, 0, notLimited, byU32, usingExtDict, dictSmall, 1);
1603
+ } else {
1604
+ result = LZ4_compress_generic(streamPtr, source, dest, srcSize, NULL, 0, notLimited, byU32, usingExtDict, noDictIssue, 1);
1605
+ }
1606
+
1607
+ streamPtr->dictionary = (const BYTE*)source;
1608
+ streamPtr->dictSize = (U32)srcSize;
1609
+
1610
+ return result;
1611
+ }
1612
+
1613
+
1614
+ /*! LZ4_saveDict() :
1615
+ * If previously compressed data block is not guaranteed to remain available at its memory location,
1616
+ * save it into a safer place (char* safeBuffer).
1617
+ * Note : no need to call LZ4_loadDict() afterwards, dictionary is immediately usable,
1618
+ * one can therefore call LZ4_compress_fast_continue() right after.
1619
+ * @return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error.
1620
+ */
1621
+ int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize)
1622
+ {
1623
+ LZ4_stream_t_internal* const dict = &LZ4_dict->internal_donotuse;
1624
+
1625
+ DEBUGLOG(5, "LZ4_saveDict : dictSize=%i, safeBuffer=%p", dictSize, safeBuffer);
1626
+
1627
+ if ((U32)dictSize > 64 KB) { dictSize = 64 KB; } /* useless to define a dictionary > 64 KB */
1628
+ if ((U32)dictSize > dict->dictSize) { dictSize = (int)dict->dictSize; }
1629
+
1630
+ if (safeBuffer == NULL) assert(dictSize == 0);
1631
+ if (dictSize > 0) {
1632
+ const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize;
1633
+ assert(dict->dictionary);
1634
+ LZ4_memmove(safeBuffer, previousDictEnd - dictSize, (size_t)dictSize);
1635
+ }
1636
+
1637
+ dict->dictionary = (const BYTE*)safeBuffer;
1638
+ dict->dictSize = (U32)dictSize;
1639
+
1640
+ return dictSize;
1641
+ }
1642
+
1643
+
1644
+
1645
+ /*-*******************************
1646
+ * Decompression functions
1647
+ ********************************/
1648
+
1649
+ typedef enum { decode_full_block = 0, partial_decode = 1 } earlyEnd_directive;
1650
+
1651
+ #undef MIN
1652
+ #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
1653
+
1654
+
1655
+ /* variant for decompress_unsafe()
1656
+ * does not know end of input
1657
+ * presumes input is well formed
1658
+ * note : will consume at least one byte */
1659
+ size_t read_long_length_no_check(const BYTE** pp)
1660
+ {
1661
+ size_t b, l = 0;
1662
+ do { b = **pp; (*pp)++; l += b; } while (b==255);
1663
+ DEBUGLOG(6, "read_long_length_no_check: +length=%zu using %zu input bytes", l, l/255 + 1)
1664
+ return l;
1665
+ }
1666
+
1667
+ /* core decoder variant for LZ4_decompress_fast*()
1668
+ * for legacy support only : these entry points are deprecated.
1669
+ * - Presumes input is correctly formed (no defense vs malformed inputs)
1670
+ * - Does not know input size (presume input buffer is "large enough")
1671
+ * - Decompress a full block (only)
1672
+ * @return : nb of bytes read from input.
1673
+ * Note : this variant is not optimized for speed, just for maintenance.
1674
+ * the goal is to remove support of decompress_fast*() variants by v2.0
1675
+ **/
1676
+ LZ4_FORCE_INLINE int
1677
+ LZ4_decompress_unsafe_generic(
1678
+ const BYTE* const istart,
1679
+ BYTE* const ostart,
1680
+ int decompressedSize,
1681
+
1682
+ size_t prefixSize,
1683
+ const BYTE* const dictStart, /* only if dict==usingExtDict */
1684
+ const size_t dictSize /* note: =0 if dictStart==NULL */
1685
+ )
1686
+ {
1687
+ const BYTE* ip = istart;
1688
+ BYTE* op = (BYTE*)ostart;
1689
+ BYTE* const oend = ostart + decompressedSize;
1690
+ const BYTE* const prefixStart = ostart - prefixSize;
1691
+
1692
+ DEBUGLOG(5, "LZ4_decompress_unsafe_generic");
1693
+ if (dictStart == NULL) assert(dictSize == 0);
1694
+
1695
+ while (1) {
1696
+ /* start new sequence */
1697
+ unsigned token = *ip++;
1698
+
1699
+ /* literals */
1700
+ { size_t ll = token >> ML_BITS;
1701
+ if (ll==15) {
1702
+ /* long literal length */
1703
+ ll += read_long_length_no_check(&ip);
1704
+ }
1705
+ if ((size_t)(oend-op) < ll) return -1; /* output buffer overflow */
1706
+ LZ4_memmove(op, ip, ll); /* support in-place decompression */
1707
+ op += ll;
1708
+ ip += ll;
1709
+ if ((size_t)(oend-op) < MFLIMIT) {
1710
+ if (op==oend) break; /* end of block */
1711
+ DEBUGLOG(5, "invalid: literals end at distance %zi from end of block", oend-op);
1712
+ /* incorrect end of block :
1713
+ * last match must start at least MFLIMIT==12 bytes before end of output block */
1714
+ return -1;
1715
+ } }
1716
+
1717
+ /* match */
1718
+ { size_t ml = token & 15;
1719
+ size_t const offset = LZ4_readLE16(ip);
1720
+ ip+=2;
1721
+
1722
+ if (ml==15) {
1723
+ /* long literal length */
1724
+ ml += read_long_length_no_check(&ip);
1725
+ }
1726
+ ml += MINMATCH;
1727
+
1728
+ if ((size_t)(oend-op) < ml) return -1; /* output buffer overflow */
1729
+
1730
+ { const BYTE* match = op - offset;
1731
+
1732
+ /* out of range */
1733
+ if (offset > (size_t)(op - prefixStart) + dictSize) {
1734
+ DEBUGLOG(6, "offset out of range");
1735
+ return -1;
1736
+ }
1737
+
1738
+ /* check special case : extDict */
1739
+ if (offset > (size_t)(op - prefixStart)) {
1740
+ /* extDict scenario */
1741
+ const BYTE* const dictEnd = dictStart + dictSize;
1742
+ const BYTE* extMatch = dictEnd - (offset - (size_t)(op-prefixStart));
1743
+ size_t const extml = (size_t)(dictEnd - extMatch);
1744
+ if (extml > ml) {
1745
+ /* match entirely within extDict */
1746
+ LZ4_memmove(op, extMatch, ml);
1747
+ op += ml;
1748
+ ml = 0;
1749
+ } else {
1750
+ /* match split between extDict & prefix */
1751
+ LZ4_memmove(op, extMatch, extml);
1752
+ op += extml;
1753
+ ml -= extml;
1754
+ }
1755
+ match = prefixStart;
1756
+ }
1757
+
1758
+ /* match copy - slow variant, supporting overlap copy */
1759
+ { size_t u;
1760
+ for (u=0; u<ml; u++) {
1761
+ op[u] = match[u];
1762
+ } } }
1763
+ op += ml;
1764
+ if ((size_t)(oend-op) < LASTLITERALS) {
1765
+ DEBUGLOG(5, "invalid: match ends at distance %zi from end of block", oend-op);
1766
+ /* incorrect end of block :
1767
+ * last match must stop at least LASTLITERALS==5 bytes before end of output block */
1768
+ return -1;
1769
+ }
1770
+ } /* match */
1771
+ } /* main loop */
1772
+ return (int)(ip - istart);
1773
+ }
1774
+
1775
+
1776
+ /* Read the variable-length literal or match length.
1777
+ *
1778
+ * @ip : input pointer
1779
+ * @ilimit : position after which if length is not decoded, the input is necessarily corrupted.
1780
+ * @initial_check - check ip >= ipmax before start of loop. Returns initial_error if so.
1781
+ * @error (output) - error code. Must be set to 0 before call.
1782
+ **/
1783
+ typedef size_t Rvl_t;
1784
+ static const Rvl_t rvl_error = (Rvl_t)(-1);
1785
+ LZ4_FORCE_INLINE Rvl_t
1786
+ read_variable_length(const BYTE** ip, const BYTE* ilimit,
1787
+ int initial_check)
1788
+ {
1789
+ Rvl_t s, length = 0;
1790
+ assert(ip != NULL);
1791
+ assert(*ip != NULL);
1792
+ assert(ilimit != NULL);
1793
+ if (initial_check && unlikely((*ip) >= ilimit)) { /* read limit reached */
1794
+ return rvl_error;
1795
+ }
1796
+ do {
1797
+ s = **ip;
1798
+ (*ip)++;
1799
+ length += s;
1800
+ if (unlikely((*ip) > ilimit)) { /* read limit reached */
1801
+ return rvl_error;
1802
+ }
1803
+ /* accumulator overflow detection (32-bit mode only) */
1804
+ if ((sizeof(length)<8) && unlikely(length > ((Rvl_t)(-1)/2)) ) {
1805
+ return rvl_error;
1806
+ }
1807
+ } while (s==255);
1808
+
1809
+ return length;
1810
+ }
1811
+
1812
+ /*! LZ4_decompress_generic() :
1813
+ * This generic decompression function covers all use cases.
1814
+ * It shall be instantiated several times, using different sets of directives.
1815
+ * Note that it is important for performance that this function really get inlined,
1816
+ * in order to remove useless branches during compilation optimization.
1817
+ */
1818
+ LZ4_FORCE_INLINE int
1819
+ LZ4_decompress_generic(
1820
+ const char* const src,
1821
+ char* const dst,
1822
+ int srcSize,
1823
+ int outputSize, /* If endOnInput==endOnInputSize, this value is `dstCapacity` */
1824
+
1825
+ earlyEnd_directive partialDecoding, /* full, partial */
1826
+ dict_directive dict, /* noDict, withPrefix64k, usingExtDict */
1827
+ const BYTE* const lowPrefix, /* always <= dst, == dst when no prefix */
1828
+ const BYTE* const dictStart, /* only if dict==usingExtDict */
1829
+ const size_t dictSize /* note : = 0 if noDict */
1830
+ )
1831
+ {
1832
+ if ((src == NULL) || (outputSize < 0)) { return -1; }
1833
+
1834
+ { const BYTE* ip = (const BYTE*) src;
1835
+ const BYTE* const iend = ip + srcSize;
1836
+
1837
+ BYTE* op = (BYTE*) dst;
1838
+ BYTE* const oend = op + outputSize;
1839
+ BYTE* cpy;
1840
+
1841
+ const BYTE* const dictEnd = (dictStart == NULL) ? NULL : dictStart + dictSize;
1842
+
1843
+ const int checkOffset = (dictSize < (int)(64 KB));
1844
+
1845
+
1846
+ /* Set up the "end" pointers for the shortcut. */
1847
+ const BYTE* const shortiend = iend - 14 /*maxLL*/ - 2 /*offset*/;
1848
+ const BYTE* const shortoend = oend - 14 /*maxLL*/ - 18 /*maxML*/;
1849
+
1850
+ const BYTE* match;
1851
+ size_t offset;
1852
+ unsigned token;
1853
+ size_t length;
1854
+
1855
+
1856
+ DEBUGLOG(5, "LZ4_decompress_generic (srcSize:%i, dstSize:%i)", srcSize, outputSize);
1857
+
1858
+ /* Special cases */
1859
+ assert(lowPrefix <= op);
1860
+ if (unlikely(outputSize==0)) {
1861
+ /* Empty output buffer */
1862
+ if (partialDecoding) return 0;
1863
+ return ((srcSize==1) && (*ip==0)) ? 0 : -1;
1864
+ }
1865
+ if (unlikely(srcSize==0)) { return -1; }
1866
+
1867
+ /* LZ4_FAST_DEC_LOOP:
1868
+ * designed for modern OoO performance cpus,
1869
+ * where copying reliably 32-bytes is preferable to an unpredictable branch.
1870
+ * note : fast loop may show a regression for some client arm chips. */
1871
+ #if LZ4_FAST_DEC_LOOP
1872
+ if ((oend - op) < FASTLOOP_SAFE_DISTANCE) {
1873
+ DEBUGLOG(6, "skip fast decode loop");
1874
+ goto safe_decode;
1875
+ }
1876
+
1877
+ /* Fast loop : decode sequences as long as output < oend-FASTLOOP_SAFE_DISTANCE */
1878
+ while (1) {
1879
+ /* Main fastloop assertion: We can always wildcopy FASTLOOP_SAFE_DISTANCE */
1880
+ assert(oend - op >= FASTLOOP_SAFE_DISTANCE);
1881
+ assert(ip < iend);
1882
+ token = *ip++;
1883
+ length = token >> ML_BITS; /* literal length */
1884
+
1885
+ /* decode literal length */
1886
+ if (length == RUN_MASK) {
1887
+ size_t const addl = read_variable_length(&ip, iend-RUN_MASK, 1);
1888
+ if (addl == rvl_error) { goto _output_error; }
1889
+ length += addl;
1890
+ if (unlikely((uptrval)(op)+length<(uptrval)(op))) { goto _output_error; } /* overflow detection */
1891
+ if (unlikely((uptrval)(ip)+length<(uptrval)(ip))) { goto _output_error; } /* overflow detection */
1892
+
1893
+ /* copy literals */
1894
+ cpy = op+length;
1895
+ LZ4_STATIC_ASSERT(MFLIMIT >= WILDCOPYLENGTH);
1896
+ if ((cpy>oend-32) || (ip+length>iend-32)) { goto safe_literal_copy; }
1897
+ LZ4_wildCopy32(op, ip, cpy);
1898
+ ip += length; op = cpy;
1899
+ } else {
1900
+ cpy = op+length;
1901
+ DEBUGLOG(7, "copy %u bytes in a 16-bytes stripe", (unsigned)length);
1902
+ /* We don't need to check oend, since we check it once for each loop below */
1903
+ if (ip > iend-(16 + 1/*max lit + offset + nextToken*/)) { goto safe_literal_copy; }
1904
+ /* Literals can only be <= 14, but hope compilers optimize better when copy by a register size */
1905
+ LZ4_memcpy(op, ip, 16);
1906
+ ip += length; op = cpy;
1907
+ }
1908
+
1909
+ /* get offset */
1910
+ offset = LZ4_readLE16(ip); ip+=2;
1911
+ match = op - offset;
1912
+ assert(match <= op); /* overflow check */
1913
+
1914
+ /* get matchlength */
1915
+ length = token & ML_MASK;
1916
+
1917
+ if (length == ML_MASK) {
1918
+ size_t const addl = read_variable_length(&ip, iend - LASTLITERALS + 1, 0);
1919
+ if (addl == rvl_error) { goto _output_error; }
1920
+ length += addl;
1921
+ length += MINMATCH;
1922
+ if (unlikely((uptrval)(op)+length<(uptrval)op)) { goto _output_error; } /* overflow detection */
1923
+ if ((checkOffset) && (unlikely(match + dictSize < lowPrefix))) { goto _output_error; } /* Error : offset outside buffers */
1924
+ if (op + length >= oend - FASTLOOP_SAFE_DISTANCE) {
1925
+ goto safe_match_copy;
1926
+ }
1927
+ } else {
1928
+ length += MINMATCH;
1929
+ if (op + length >= oend - FASTLOOP_SAFE_DISTANCE) {
1930
+ goto safe_match_copy;
1931
+ }
1932
+
1933
+ /* Fastpath check: skip LZ4_wildCopy32 when true */
1934
+ if ((dict == withPrefix64k) || (match >= lowPrefix)) {
1935
+ if (offset >= 8) {
1936
+ assert(match >= lowPrefix);
1937
+ assert(match <= op);
1938
+ assert(op + 18 <= oend);
1939
+
1940
+ LZ4_memcpy(op, match, 8);
1941
+ LZ4_memcpy(op+8, match+8, 8);
1942
+ LZ4_memcpy(op+16, match+16, 2);
1943
+ op += length;
1944
+ continue;
1945
+ } } }
1946
+
1947
+ if (checkOffset && (unlikely(match + dictSize < lowPrefix))) { goto _output_error; } /* Error : offset outside buffers */
1948
+ /* match starting within external dictionary */
1949
+ if ((dict==usingExtDict) && (match < lowPrefix)) {
1950
+ assert(dictEnd != NULL);
1951
+ if (unlikely(op+length > oend-LASTLITERALS)) {
1952
+ if (partialDecoding) {
1953
+ DEBUGLOG(7, "partialDecoding: dictionary match, close to dstEnd");
1954
+ length = MIN(length, (size_t)(oend-op));
1955
+ } else {
1956
+ goto _output_error; /* end-of-block condition violated */
1957
+ } }
1958
+
1959
+ if (length <= (size_t)(lowPrefix-match)) {
1960
+ /* match fits entirely within external dictionary : just copy */
1961
+ LZ4_memmove(op, dictEnd - (lowPrefix-match), length);
1962
+ op += length;
1963
+ } else {
1964
+ /* match stretches into both external dictionary and current block */
1965
+ size_t const copySize = (size_t)(lowPrefix - match);
1966
+ size_t const restSize = length - copySize;
1967
+ LZ4_memcpy(op, dictEnd - copySize, copySize);
1968
+ op += copySize;
1969
+ if (restSize > (size_t)(op - lowPrefix)) { /* overlap copy */
1970
+ BYTE* const endOfMatch = op + restSize;
1971
+ const BYTE* copyFrom = lowPrefix;
1972
+ while (op < endOfMatch) { *op++ = *copyFrom++; }
1973
+ } else {
1974
+ LZ4_memcpy(op, lowPrefix, restSize);
1975
+ op += restSize;
1976
+ } }
1977
+ continue;
1978
+ }
1979
+
1980
+ /* copy match within block */
1981
+ cpy = op + length;
1982
+
1983
+ assert((op <= oend) && (oend-op >= 32));
1984
+ if (unlikely(offset<16)) {
1985
+ LZ4_memcpy_using_offset(op, match, cpy, offset);
1986
+ } else {
1987
+ LZ4_wildCopy32(op, match, cpy);
1988
+ }
1989
+
1990
+ op = cpy; /* wildcopy correction */
1991
+ }
1992
+ safe_decode:
1993
+ #endif
1994
+
1995
+ /* Main Loop : decode remaining sequences where output < FASTLOOP_SAFE_DISTANCE */
1996
+ while (1) {
1997
+ assert(ip < iend);
1998
+ token = *ip++;
1999
+ length = token >> ML_BITS; /* literal length */
2000
+
2001
+ /* A two-stage shortcut for the most common case:
2002
+ * 1) If the literal length is 0..14, and there is enough space,
2003
+ * enter the shortcut and copy 16 bytes on behalf of the literals
2004
+ * (in the fast mode, only 8 bytes can be safely copied this way).
2005
+ * 2) Further if the match length is 4..18, copy 18 bytes in a similar
2006
+ * manner; but we ensure that there's enough space in the output for
2007
+ * those 18 bytes earlier, upon entering the shortcut (in other words,
2008
+ * there is a combined check for both stages).
2009
+ */
2010
+ if ( (length != RUN_MASK)
2011
+ /* strictly "less than" on input, to re-enter the loop with at least one byte */
2012
+ && likely((ip < shortiend) & (op <= shortoend)) ) {
2013
+ /* Copy the literals */
2014
+ LZ4_memcpy(op, ip, 16);
2015
+ op += length; ip += length;
2016
+
2017
+ /* The second stage: prepare for match copying, decode full info.
2018
+ * If it doesn't work out, the info won't be wasted. */
2019
+ length = token & ML_MASK; /* match length */
2020
+ offset = LZ4_readLE16(ip); ip += 2;
2021
+ match = op - offset;
2022
+ assert(match <= op); /* check overflow */
2023
+
2024
+ /* Do not deal with overlapping matches. */
2025
+ if ( (length != ML_MASK)
2026
+ && (offset >= 8)
2027
+ && (dict==withPrefix64k || match >= lowPrefix) ) {
2028
+ /* Copy the match. */
2029
+ LZ4_memcpy(op + 0, match + 0, 8);
2030
+ LZ4_memcpy(op + 8, match + 8, 8);
2031
+ LZ4_memcpy(op +16, match +16, 2);
2032
+ op += length + MINMATCH;
2033
+ /* Both stages worked, load the next token. */
2034
+ continue;
2035
+ }
2036
+
2037
+ /* The second stage didn't work out, but the info is ready.
2038
+ * Propel it right to the point of match copying. */
2039
+ goto _copy_match;
2040
+ }
2041
+
2042
+ /* decode literal length */
2043
+ if (length == RUN_MASK) {
2044
+ size_t const addl = read_variable_length(&ip, iend-RUN_MASK, 1);
2045
+ if (addl == rvl_error) { goto _output_error; }
2046
+ length += addl;
2047
+ if (unlikely((uptrval)(op)+length<(uptrval)(op))) { goto _output_error; } /* overflow detection */
2048
+ if (unlikely((uptrval)(ip)+length<(uptrval)(ip))) { goto _output_error; } /* overflow detection */
2049
+ }
2050
+
2051
+ /* copy literals */
2052
+ cpy = op+length;
2053
+ #if LZ4_FAST_DEC_LOOP
2054
+ safe_literal_copy:
2055
+ #endif
2056
+ LZ4_STATIC_ASSERT(MFLIMIT >= WILDCOPYLENGTH);
2057
+ if ((cpy>oend-MFLIMIT) || (ip+length>iend-(2+1+LASTLITERALS))) {
2058
+ /* We've either hit the input parsing restriction or the output parsing restriction.
2059
+ * In the normal scenario, decoding a full block, it must be the last sequence,
2060
+ * otherwise it's an error (invalid input or dimensions).
2061
+ * In partialDecoding scenario, it's necessary to ensure there is no buffer overflow.
2062
+ */
2063
+ if (partialDecoding) {
2064
+ /* Since we are partial decoding we may be in this block because of the output parsing
2065
+ * restriction, which is not valid since the output buffer is allowed to be undersized.
2066
+ */
2067
+ DEBUGLOG(7, "partialDecoding: copying literals, close to input or output end")
2068
+ DEBUGLOG(7, "partialDecoding: literal length = %u", (unsigned)length);
2069
+ DEBUGLOG(7, "partialDecoding: remaining space in dstBuffer : %i", (int)(oend - op));
2070
+ DEBUGLOG(7, "partialDecoding: remaining space in srcBuffer : %i", (int)(iend - ip));
2071
+ /* Finishing in the middle of a literals segment,
2072
+ * due to lack of input.
2073
+ */
2074
+ if (ip+length > iend) {
2075
+ length = (size_t)(iend-ip);
2076
+ cpy = op + length;
2077
+ }
2078
+ /* Finishing in the middle of a literals segment,
2079
+ * due to lack of output space.
2080
+ */
2081
+ if (cpy > oend) {
2082
+ cpy = oend;
2083
+ assert(op<=oend);
2084
+ length = (size_t)(oend-op);
2085
+ }
2086
+ } else {
2087
+ /* We must be on the last sequence (or invalid) because of the parsing limitations
2088
+ * so check that we exactly consume the input and don't overrun the output buffer.
2089
+ */
2090
+ if ((ip+length != iend) || (cpy > oend)) {
2091
+ DEBUGLOG(6, "should have been last run of literals")
2092
+ DEBUGLOG(6, "ip(%p) + length(%i) = %p != iend (%p)", ip, (int)length, ip+length, iend);
2093
+ DEBUGLOG(6, "or cpy(%p) > oend(%p)", cpy, oend);
2094
+ goto _output_error;
2095
+ }
2096
+ }
2097
+ LZ4_memmove(op, ip, length); /* supports overlapping memory regions, for in-place decompression scenarios */
2098
+ ip += length;
2099
+ op += length;
2100
+ /* Necessarily EOF when !partialDecoding.
2101
+ * When partialDecoding, it is EOF if we've either
2102
+ * filled the output buffer or
2103
+ * can't proceed with reading an offset for following match.
2104
+ */
2105
+ if (!partialDecoding || (cpy == oend) || (ip >= (iend-2))) {
2106
+ break;
2107
+ }
2108
+ } else {
2109
+ LZ4_wildCopy8(op, ip, cpy); /* can overwrite up to 8 bytes beyond cpy */
2110
+ ip += length; op = cpy;
2111
+ }
2112
+
2113
+ /* get offset */
2114
+ offset = LZ4_readLE16(ip); ip+=2;
2115
+ match = op - offset;
2116
+
2117
+ /* get matchlength */
2118
+ length = token & ML_MASK;
2119
+
2120
+ _copy_match:
2121
+ if (length == ML_MASK) {
2122
+ size_t const addl = read_variable_length(&ip, iend - LASTLITERALS + 1, 0);
2123
+ if (addl == rvl_error) { goto _output_error; }
2124
+ length += addl;
2125
+ if (unlikely((uptrval)(op)+length<(uptrval)op)) goto _output_error; /* overflow detection */
2126
+ }
2127
+ length += MINMATCH;
2128
+
2129
+ #if LZ4_FAST_DEC_LOOP
2130
+ safe_match_copy:
2131
+ #endif
2132
+ if ((checkOffset) && (unlikely(match + dictSize < lowPrefix))) goto _output_error; /* Error : offset outside buffers */
2133
+ /* match starting within external dictionary */
2134
+ if ((dict==usingExtDict) && (match < lowPrefix)) {
2135
+ assert(dictEnd != NULL);
2136
+ if (unlikely(op+length > oend-LASTLITERALS)) {
2137
+ if (partialDecoding) length = MIN(length, (size_t)(oend-op));
2138
+ else goto _output_error; /* doesn't respect parsing restriction */
2139
+ }
2140
+
2141
+ if (length <= (size_t)(lowPrefix-match)) {
2142
+ /* match fits entirely within external dictionary : just copy */
2143
+ LZ4_memmove(op, dictEnd - (lowPrefix-match), length);
2144
+ op += length;
2145
+ } else {
2146
+ /* match stretches into both external dictionary and current block */
2147
+ size_t const copySize = (size_t)(lowPrefix - match);
2148
+ size_t const restSize = length - copySize;
2149
+ LZ4_memcpy(op, dictEnd - copySize, copySize);
2150
+ op += copySize;
2151
+ if (restSize > (size_t)(op - lowPrefix)) { /* overlap copy */
2152
+ BYTE* const endOfMatch = op + restSize;
2153
+ const BYTE* copyFrom = lowPrefix;
2154
+ while (op < endOfMatch) *op++ = *copyFrom++;
2155
+ } else {
2156
+ LZ4_memcpy(op, lowPrefix, restSize);
2157
+ op += restSize;
2158
+ } }
2159
+ continue;
2160
+ }
2161
+ assert(match >= lowPrefix);
2162
+
2163
+ /* copy match within block */
2164
+ cpy = op + length;
2165
+
2166
+ /* partialDecoding : may end anywhere within the block */
2167
+ assert(op<=oend);
2168
+ if (partialDecoding && (cpy > oend-MATCH_SAFEGUARD_DISTANCE)) {
2169
+ size_t const mlen = MIN(length, (size_t)(oend-op));
2170
+ const BYTE* const matchEnd = match + mlen;
2171
+ BYTE* const copyEnd = op + mlen;
2172
+ if (matchEnd > op) { /* overlap copy */
2173
+ while (op < copyEnd) { *op++ = *match++; }
2174
+ } else {
2175
+ LZ4_memcpy(op, match, mlen);
2176
+ }
2177
+ op = copyEnd;
2178
+ if (op == oend) { break; }
2179
+ continue;
2180
+ }
2181
+
2182
+ if (unlikely(offset<8)) {
2183
+ LZ4_write32(op, 0); /* silence msan warning when offset==0 */
2184
+ op[0] = match[0];
2185
+ op[1] = match[1];
2186
+ op[2] = match[2];
2187
+ op[3] = match[3];
2188
+ match += inc32table[offset];
2189
+ LZ4_memcpy(op+4, match, 4);
2190
+ match -= dec64table[offset];
2191
+ } else {
2192
+ LZ4_memcpy(op, match, 8);
2193
+ match += 8;
2194
+ }
2195
+ op += 8;
2196
+
2197
+ if (unlikely(cpy > oend-MATCH_SAFEGUARD_DISTANCE)) {
2198
+ BYTE* const oCopyLimit = oend - (WILDCOPYLENGTH-1);
2199
+ if (cpy > oend-LASTLITERALS) { goto _output_error; } /* Error : last LASTLITERALS bytes must be literals (uncompressed) */
2200
+ if (op < oCopyLimit) {
2201
+ LZ4_wildCopy8(op, match, oCopyLimit);
2202
+ match += oCopyLimit - op;
2203
+ op = oCopyLimit;
2204
+ }
2205
+ while (op < cpy) { *op++ = *match++; }
2206
+ } else {
2207
+ LZ4_memcpy(op, match, 8);
2208
+ if (length > 16) { LZ4_wildCopy8(op+8, match+8, cpy); }
2209
+ }
2210
+ op = cpy; /* wildcopy correction */
2211
+ }
2212
+
2213
+ /* end of decoding */
2214
+ DEBUGLOG(5, "decoded %i bytes", (int) (((char*)op)-dst));
2215
+ return (int) (((char*)op)-dst); /* Nb of output bytes decoded */
2216
+
2217
+ /* Overflow error detected */
2218
+ _output_error:
2219
+ return (int) (-(((const char*)ip)-src))-1;
2220
+ }
2221
+ }
2222
+
2223
+
2224
+ /*===== Instantiate the API decoding functions. =====*/
2225
+
2226
+ LZ4_FORCE_O2
2227
+ int LZ4_decompress_safe(const char* source, char* dest, int compressedSize, int maxDecompressedSize)
2228
+ {
2229
+ return LZ4_decompress_generic(source, dest, compressedSize, maxDecompressedSize,
2230
+ decode_full_block, noDict,
2231
+ (BYTE*)dest, NULL, 0);
2232
+ }
2233
+
2234
+ LZ4_FORCE_O2
2235
+ int LZ4_decompress_safe_partial(const char* src, char* dst, int compressedSize, int targetOutputSize, int dstCapacity)
2236
+ {
2237
+ dstCapacity = MIN(targetOutputSize, dstCapacity);
2238
+ return LZ4_decompress_generic(src, dst, compressedSize, dstCapacity,
2239
+ partial_decode,
2240
+ noDict, (BYTE*)dst, NULL, 0);
2241
+ }
2242
+
2243
+ LZ4_FORCE_O2
2244
+ int LZ4_decompress_fast(const char* source, char* dest, int originalSize)
2245
+ {
2246
+ DEBUGLOG(5, "LZ4_decompress_fast");
2247
+ return LZ4_decompress_unsafe_generic(
2248
+ (const BYTE*)source, (BYTE*)dest, originalSize,
2249
+ 0, NULL, 0);
2250
+ }
2251
+
2252
+ /*===== Instantiate a few more decoding cases, used more than once. =====*/
2253
+
2254
+ LZ4_FORCE_O2 /* Exported, an obsolete API function. */
2255
+ int LZ4_decompress_safe_withPrefix64k(const char* source, char* dest, int compressedSize, int maxOutputSize)
2256
+ {
2257
+ return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize,
2258
+ decode_full_block, withPrefix64k,
2259
+ (BYTE*)dest - 64 KB, NULL, 0);
2260
+ }
2261
+
2262
+ LZ4_FORCE_O2
2263
+ static int LZ4_decompress_safe_partial_withPrefix64k(const char* source, char* dest, int compressedSize, int targetOutputSize, int dstCapacity)
2264
+ {
2265
+ dstCapacity = MIN(targetOutputSize, dstCapacity);
2266
+ return LZ4_decompress_generic(source, dest, compressedSize, dstCapacity,
2267
+ partial_decode, withPrefix64k,
2268
+ (BYTE*)dest - 64 KB, NULL, 0);
2269
+ }
2270
+
2271
+ /* Another obsolete API function, paired with the previous one. */
2272
+ int LZ4_decompress_fast_withPrefix64k(const char* source, char* dest, int originalSize)
2273
+ {
2274
+ return LZ4_decompress_unsafe_generic(
2275
+ (const BYTE*)source, (BYTE*)dest, originalSize,
2276
+ 64 KB, NULL, 0);
2277
+ }
2278
+
2279
+ LZ4_FORCE_O2
2280
+ static int LZ4_decompress_safe_withSmallPrefix(const char* source, char* dest, int compressedSize, int maxOutputSize,
2281
+ size_t prefixSize)
2282
+ {
2283
+ return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize,
2284
+ decode_full_block, noDict,
2285
+ (BYTE*)dest-prefixSize, NULL, 0);
2286
+ }
2287
+
2288
+ LZ4_FORCE_O2
2289
+ static int LZ4_decompress_safe_partial_withSmallPrefix(const char* source, char* dest, int compressedSize, int targetOutputSize, int dstCapacity,
2290
+ size_t prefixSize)
2291
+ {
2292
+ dstCapacity = MIN(targetOutputSize, dstCapacity);
2293
+ return LZ4_decompress_generic(source, dest, compressedSize, dstCapacity,
2294
+ partial_decode, noDict,
2295
+ (BYTE*)dest-prefixSize, NULL, 0);
2296
+ }
2297
+
2298
+ LZ4_FORCE_O2
2299
+ int LZ4_decompress_safe_forceExtDict(const char* source, char* dest,
2300
+ int compressedSize, int maxOutputSize,
2301
+ const void* dictStart, size_t dictSize)
2302
+ {
2303
+ return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize,
2304
+ decode_full_block, usingExtDict,
2305
+ (BYTE*)dest, (const BYTE*)dictStart, dictSize);
2306
+ }
2307
+
2308
+ LZ4_FORCE_O2
2309
+ int LZ4_decompress_safe_partial_forceExtDict(const char* source, char* dest,
2310
+ int compressedSize, int targetOutputSize, int dstCapacity,
2311
+ const void* dictStart, size_t dictSize)
2312
+ {
2313
+ dstCapacity = MIN(targetOutputSize, dstCapacity);
2314
+ return LZ4_decompress_generic(source, dest, compressedSize, dstCapacity,
2315
+ partial_decode, usingExtDict,
2316
+ (BYTE*)dest, (const BYTE*)dictStart, dictSize);
2317
+ }
2318
+
2319
+ LZ4_FORCE_O2
2320
+ static int LZ4_decompress_fast_extDict(const char* source, char* dest, int originalSize,
2321
+ const void* dictStart, size_t dictSize)
2322
+ {
2323
+ return LZ4_decompress_unsafe_generic(
2324
+ (const BYTE*)source, (BYTE*)dest, originalSize,
2325
+ 0, (const BYTE*)dictStart, dictSize);
2326
+ }
2327
+
2328
+ /* The "double dictionary" mode, for use with e.g. ring buffers: the first part
2329
+ * of the dictionary is passed as prefix, and the second via dictStart + dictSize.
2330
+ * These routines are used only once, in LZ4_decompress_*_continue().
2331
+ */
2332
+ LZ4_FORCE_INLINE
2333
+ int LZ4_decompress_safe_doubleDict(const char* source, char* dest, int compressedSize, int maxOutputSize,
2334
+ size_t prefixSize, const void* dictStart, size_t dictSize)
2335
+ {
2336
+ return LZ4_decompress_generic(source, dest, compressedSize, maxOutputSize,
2337
+ decode_full_block, usingExtDict,
2338
+ (BYTE*)dest-prefixSize, (const BYTE*)dictStart, dictSize);
2339
+ }
2340
+
2341
+ /*===== streaming decompression functions =====*/
2342
+
2343
+ #if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
2344
+ LZ4_streamDecode_t* LZ4_createStreamDecode(void)
2345
+ {
2346
+ LZ4_STATIC_ASSERT(sizeof(LZ4_streamDecode_t) >= sizeof(LZ4_streamDecode_t_internal));
2347
+ return (LZ4_streamDecode_t*) ALLOC_AND_ZERO(sizeof(LZ4_streamDecode_t));
2348
+ }
2349
+
2350
+ int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream)
2351
+ {
2352
+ if (LZ4_stream == NULL) { return 0; } /* support free on NULL */
2353
+ FREEMEM(LZ4_stream);
2354
+ return 0;
2355
+ }
2356
+ #endif
2357
+
2358
+ /*! LZ4_setStreamDecode() :
2359
+ * Use this function to instruct where to find the dictionary.
2360
+ * This function is not necessary if previous data is still available where it was decoded.
2361
+ * Loading a size of 0 is allowed (same effect as no dictionary).
2362
+ * @return : 1 if OK, 0 if error
2363
+ */
2364
+ int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize)
2365
+ {
2366
+ LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse;
2367
+ lz4sd->prefixSize = (size_t)dictSize;
2368
+ if (dictSize) {
2369
+ assert(dictionary != NULL);
2370
+ lz4sd->prefixEnd = (const BYTE*) dictionary + dictSize;
2371
+ } else {
2372
+ lz4sd->prefixEnd = (const BYTE*) dictionary;
2373
+ }
2374
+ lz4sd->externalDict = NULL;
2375
+ lz4sd->extDictSize = 0;
2376
+ return 1;
2377
+ }
2378
+
2379
+ /*! LZ4_decoderRingBufferSize() :
2380
+ * when setting a ring buffer for streaming decompression (optional scenario),
2381
+ * provides the minimum size of this ring buffer
2382
+ * to be compatible with any source respecting maxBlockSize condition.
2383
+ * Note : in a ring buffer scenario,
2384
+ * blocks are presumed decompressed next to each other.
2385
+ * When not enough space remains for next block (remainingSize < maxBlockSize),
2386
+ * decoding resumes from beginning of ring buffer.
2387
+ * @return : minimum ring buffer size,
2388
+ * or 0 if there is an error (invalid maxBlockSize).
2389
+ */
2390
+ int LZ4_decoderRingBufferSize(int maxBlockSize)
2391
+ {
2392
+ if (maxBlockSize < 0) return 0;
2393
+ if (maxBlockSize > LZ4_MAX_INPUT_SIZE) return 0;
2394
+ if (maxBlockSize < 16) maxBlockSize = 16;
2395
+ return LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize);
2396
+ }
2397
+
2398
+ /*
2399
+ *_continue() :
2400
+ These decoding functions allow decompression of multiple blocks in "streaming" mode.
2401
+ Previously decoded blocks must still be available at the memory position where they were decoded.
2402
+ If it's not possible, save the relevant part of decoded data into a safe buffer,
2403
+ and indicate where it stands using LZ4_setStreamDecode()
2404
+ */
2405
+ LZ4_FORCE_O2
2406
+ int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxOutputSize)
2407
+ {
2408
+ LZ4_streamDecode_t_internal* lz4sd = &LZ4_streamDecode->internal_donotuse;
2409
+ int result;
2410
+
2411
+ if (lz4sd->prefixSize == 0) {
2412
+ /* The first call, no dictionary yet. */
2413
+ assert(lz4sd->extDictSize == 0);
2414
+ result = LZ4_decompress_safe(source, dest, compressedSize, maxOutputSize);
2415
+ if (result <= 0) return result;
2416
+ lz4sd->prefixSize = (size_t)result;
2417
+ lz4sd->prefixEnd = (BYTE*)dest + result;
2418
+ } else if (lz4sd->prefixEnd == (BYTE*)dest) {
2419
+ /* They're rolling the current segment. */
2420
+ if (lz4sd->prefixSize >= 64 KB - 1)
2421
+ result = LZ4_decompress_safe_withPrefix64k(source, dest, compressedSize, maxOutputSize);
2422
+ else if (lz4sd->extDictSize == 0)
2423
+ result = LZ4_decompress_safe_withSmallPrefix(source, dest, compressedSize, maxOutputSize,
2424
+ lz4sd->prefixSize);
2425
+ else
2426
+ result = LZ4_decompress_safe_doubleDict(source, dest, compressedSize, maxOutputSize,
2427
+ lz4sd->prefixSize, lz4sd->externalDict, lz4sd->extDictSize);
2428
+ if (result <= 0) return result;
2429
+ lz4sd->prefixSize += (size_t)result;
2430
+ lz4sd->prefixEnd += result;
2431
+ } else {
2432
+ /* The buffer wraps around, or they're switching to another buffer. */
2433
+ lz4sd->extDictSize = lz4sd->prefixSize;
2434
+ lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize;
2435
+ result = LZ4_decompress_safe_forceExtDict(source, dest, compressedSize, maxOutputSize,
2436
+ lz4sd->externalDict, lz4sd->extDictSize);
2437
+ if (result <= 0) return result;
2438
+ lz4sd->prefixSize = (size_t)result;
2439
+ lz4sd->prefixEnd = (BYTE*)dest + result;
2440
+ }
2441
+
2442
+ return result;
2443
+ }
2444
+
2445
+ LZ4_FORCE_O2 int
2446
+ LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode,
2447
+ const char* source, char* dest, int originalSize)
2448
+ {
2449
+ LZ4_streamDecode_t_internal* const lz4sd =
2450
+ (assert(LZ4_streamDecode!=NULL), &LZ4_streamDecode->internal_donotuse);
2451
+ int result;
2452
+
2453
+ DEBUGLOG(5, "LZ4_decompress_fast_continue (toDecodeSize=%i)", originalSize);
2454
+ assert(originalSize >= 0);
2455
+
2456
+ if (lz4sd->prefixSize == 0) {
2457
+ DEBUGLOG(5, "first invocation : no prefix nor extDict");
2458
+ assert(lz4sd->extDictSize == 0);
2459
+ result = LZ4_decompress_fast(source, dest, originalSize);
2460
+ if (result <= 0) return result;
2461
+ lz4sd->prefixSize = (size_t)originalSize;
2462
+ lz4sd->prefixEnd = (BYTE*)dest + originalSize;
2463
+ } else if (lz4sd->prefixEnd == (BYTE*)dest) {
2464
+ DEBUGLOG(5, "continue using existing prefix");
2465
+ result = LZ4_decompress_unsafe_generic(
2466
+ (const BYTE*)source, (BYTE*)dest, originalSize,
2467
+ lz4sd->prefixSize,
2468
+ lz4sd->externalDict, lz4sd->extDictSize);
2469
+ if (result <= 0) return result;
2470
+ lz4sd->prefixSize += (size_t)originalSize;
2471
+ lz4sd->prefixEnd += originalSize;
2472
+ } else {
2473
+ DEBUGLOG(5, "prefix becomes extDict");
2474
+ lz4sd->extDictSize = lz4sd->prefixSize;
2475
+ lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize;
2476
+ result = LZ4_decompress_fast_extDict(source, dest, originalSize,
2477
+ lz4sd->externalDict, lz4sd->extDictSize);
2478
+ if (result <= 0) return result;
2479
+ lz4sd->prefixSize = (size_t)originalSize;
2480
+ lz4sd->prefixEnd = (BYTE*)dest + originalSize;
2481
+ }
2482
+
2483
+ return result;
2484
+ }
2485
+
2486
+
2487
+ /*
2488
+ Advanced decoding functions :
2489
+ *_usingDict() :
2490
+ These decoding functions work the same as "_continue" ones,
2491
+ the dictionary must be explicitly provided within parameters
2492
+ */
2493
+
2494
+ int LZ4_decompress_safe_usingDict(const char* source, char* dest, int compressedSize, int maxOutputSize, const char* dictStart, int dictSize)
2495
+ {
2496
+ if (dictSize==0)
2497
+ return LZ4_decompress_safe(source, dest, compressedSize, maxOutputSize);
2498
+ if (dictStart+dictSize == dest) {
2499
+ if (dictSize >= 64 KB - 1) {
2500
+ return LZ4_decompress_safe_withPrefix64k(source, dest, compressedSize, maxOutputSize);
2501
+ }
2502
+ assert(dictSize >= 0);
2503
+ return LZ4_decompress_safe_withSmallPrefix(source, dest, compressedSize, maxOutputSize, (size_t)dictSize);
2504
+ }
2505
+ assert(dictSize >= 0);
2506
+ return LZ4_decompress_safe_forceExtDict(source, dest, compressedSize, maxOutputSize, dictStart, (size_t)dictSize);
2507
+ }
2508
+
2509
+ int LZ4_decompress_safe_partial_usingDict(const char* source, char* dest, int compressedSize, int targetOutputSize, int dstCapacity, const char* dictStart, int dictSize)
2510
+ {
2511
+ if (dictSize==0)
2512
+ return LZ4_decompress_safe_partial(source, dest, compressedSize, targetOutputSize, dstCapacity);
2513
+ if (dictStart+dictSize == dest) {
2514
+ if (dictSize >= 64 KB - 1) {
2515
+ return LZ4_decompress_safe_partial_withPrefix64k(source, dest, compressedSize, targetOutputSize, dstCapacity);
2516
+ }
2517
+ assert(dictSize >= 0);
2518
+ return LZ4_decompress_safe_partial_withSmallPrefix(source, dest, compressedSize, targetOutputSize, dstCapacity, (size_t)dictSize);
2519
+ }
2520
+ assert(dictSize >= 0);
2521
+ return LZ4_decompress_safe_partial_forceExtDict(source, dest, compressedSize, targetOutputSize, dstCapacity, dictStart, (size_t)dictSize);
2522
+ }
2523
+
2524
+ int LZ4_decompress_fast_usingDict(const char* source, char* dest, int originalSize, const char* dictStart, int dictSize)
2525
+ {
2526
+ if (dictSize==0 || dictStart+dictSize == dest)
2527
+ return LZ4_decompress_unsafe_generic(
2528
+ (const BYTE*)source, (BYTE*)dest, originalSize,
2529
+ (size_t)dictSize, NULL, 0);
2530
+ assert(dictSize >= 0);
2531
+ return LZ4_decompress_fast_extDict(source, dest, originalSize, dictStart, (size_t)dictSize);
2532
+ }
2533
+
2534
+
2535
+ /*=*************************************************
2536
+ * Obsolete Functions
2537
+ ***************************************************/
2538
+ /* obsolete compression functions */
2539
+ int LZ4_compress_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize)
2540
+ {
2541
+ return LZ4_compress_default(source, dest, inputSize, maxOutputSize);
2542
+ }
2543
+ int LZ4_compress(const char* src, char* dest, int srcSize)
2544
+ {
2545
+ return LZ4_compress_default(src, dest, srcSize, LZ4_compressBound(srcSize));
2546
+ }
2547
+ int LZ4_compress_limitedOutput_withState (void* state, const char* src, char* dst, int srcSize, int dstSize)
2548
+ {
2549
+ return LZ4_compress_fast_extState(state, src, dst, srcSize, dstSize, 1);
2550
+ }
2551
+ int LZ4_compress_withState (void* state, const char* src, char* dst, int srcSize)
2552
+ {
2553
+ return LZ4_compress_fast_extState(state, src, dst, srcSize, LZ4_compressBound(srcSize), 1);
2554
+ }
2555
+ int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_stream, const char* src, char* dst, int srcSize, int dstCapacity)
2556
+ {
2557
+ return LZ4_compress_fast_continue(LZ4_stream, src, dst, srcSize, dstCapacity, 1);
2558
+ }
2559
+ int LZ4_compress_continue (LZ4_stream_t* LZ4_stream, const char* source, char* dest, int inputSize)
2560
+ {
2561
+ return LZ4_compress_fast_continue(LZ4_stream, source, dest, inputSize, LZ4_compressBound(inputSize), 1);
2562
+ }
2563
+
2564
+ /*
2565
+ These decompression functions are deprecated and should no longer be used.
2566
+ They are only provided here for compatibility with older user programs.
2567
+ - LZ4_uncompress is totally equivalent to LZ4_decompress_fast
2568
+ - LZ4_uncompress_unknownOutputSize is totally equivalent to LZ4_decompress_safe
2569
+ */
2570
+ int LZ4_uncompress (const char* source, char* dest, int outputSize)
2571
+ {
2572
+ return LZ4_decompress_fast(source, dest, outputSize);
2573
+ }
2574
+ int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize)
2575
+ {
2576
+ return LZ4_decompress_safe(source, dest, isize, maxOutputSize);
2577
+ }
2578
+
2579
+ /* Obsolete Streaming functions */
2580
+
2581
+ int LZ4_sizeofStreamState(void) { return sizeof(LZ4_stream_t); }
2582
+
2583
+ int LZ4_resetStreamState(void* state, char* inputBuffer)
2584
+ {
2585
+ (void)inputBuffer;
2586
+ LZ4_resetStream((LZ4_stream_t*)state);
2587
+ return 0;
2588
+ }
2589
+
2590
+ #if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
2591
+ void* LZ4_create (char* inputBuffer)
2592
+ {
2593
+ (void)inputBuffer;
2594
+ return LZ4_createStream();
2595
+ }
2596
+ #endif
2597
+
2598
+ char* LZ4_slideInputBuffer (void* state)
2599
+ {
2600
+ /* avoid const char * -> char * conversion warning */
2601
+ return (char *)(uptrval)((LZ4_stream_t*)state)->internal_donotuse.dictionary;
2602
+ }
2603
+
2604
+ #endif /* LZ4_COMMONDEFS_ONLY */
2605
+ }