extzstd 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +28 -14
  3. data/contrib/zstd/CHANGELOG +301 -56
  4. data/contrib/zstd/CONTRIBUTING.md +169 -72
  5. data/contrib/zstd/LICENSE +4 -4
  6. data/contrib/zstd/Makefile +116 -87
  7. data/contrib/zstd/Package.swift +36 -0
  8. data/contrib/zstd/README.md +62 -32
  9. data/contrib/zstd/TESTING.md +2 -3
  10. data/contrib/zstd/appveyor.yml +52 -136
  11. data/contrib/zstd/lib/BUCK +5 -7
  12. data/contrib/zstd/lib/Makefile +225 -222
  13. data/contrib/zstd/lib/README.md +51 -6
  14. data/contrib/zstd/lib/common/allocations.h +55 -0
  15. data/contrib/zstd/lib/common/bits.h +200 -0
  16. data/contrib/zstd/lib/common/bitstream.h +45 -62
  17. data/contrib/zstd/lib/common/compiler.h +205 -22
  18. data/contrib/zstd/lib/common/cpu.h +1 -3
  19. data/contrib/zstd/lib/common/debug.c +1 -1
  20. data/contrib/zstd/lib/common/debug.h +12 -19
  21. data/contrib/zstd/lib/common/entropy_common.c +172 -48
  22. data/contrib/zstd/lib/common/error_private.c +10 -2
  23. data/contrib/zstd/lib/common/error_private.h +82 -3
  24. data/contrib/zstd/lib/common/fse.h +37 -86
  25. data/contrib/zstd/lib/common/fse_decompress.c +117 -92
  26. data/contrib/zstd/lib/common/huf.h +99 -166
  27. data/contrib/zstd/lib/common/mem.h +124 -142
  28. data/contrib/zstd/lib/common/pool.c +54 -27
  29. data/contrib/zstd/lib/common/pool.h +10 -4
  30. data/contrib/zstd/lib/common/portability_macros.h +156 -0
  31. data/contrib/zstd/lib/common/threading.c +74 -19
  32. data/contrib/zstd/lib/common/threading.h +5 -10
  33. data/contrib/zstd/lib/common/xxhash.c +7 -847
  34. data/contrib/zstd/lib/common/xxhash.h +5568 -167
  35. data/contrib/zstd/lib/common/zstd_common.c +2 -37
  36. data/contrib/zstd/lib/common/zstd_deps.h +111 -0
  37. data/contrib/zstd/lib/common/zstd_internal.h +132 -187
  38. data/contrib/zstd/lib/common/zstd_trace.h +163 -0
  39. data/contrib/zstd/lib/compress/clevels.h +134 -0
  40. data/contrib/zstd/lib/compress/fse_compress.c +83 -157
  41. data/contrib/zstd/lib/compress/hist.c +27 -29
  42. data/contrib/zstd/lib/compress/hist.h +2 -2
  43. data/contrib/zstd/lib/compress/huf_compress.c +916 -279
  44. data/contrib/zstd/lib/compress/zstd_compress.c +3773 -1019
  45. data/contrib/zstd/lib/compress/zstd_compress_internal.h +610 -203
  46. data/contrib/zstd/lib/compress/zstd_compress_literals.c +119 -42
  47. data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
  48. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +42 -19
  49. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
  50. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +49 -317
  51. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
  52. data/contrib/zstd/lib/compress/zstd_cwksp.h +320 -103
  53. data/contrib/zstd/lib/compress/zstd_double_fast.c +388 -151
  54. data/contrib/zstd/lib/compress/zstd_double_fast.h +3 -2
  55. data/contrib/zstd/lib/compress/zstd_fast.c +729 -265
  56. data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
  57. data/contrib/zstd/lib/compress/zstd_lazy.c +1270 -251
  58. data/contrib/zstd/lib/compress/zstd_lazy.h +61 -1
  59. data/contrib/zstd/lib/compress/zstd_ldm.c +324 -219
  60. data/contrib/zstd/lib/compress/zstd_ldm.h +9 -2
  61. data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
  62. data/contrib/zstd/lib/compress/zstd_opt.c +481 -209
  63. data/contrib/zstd/lib/compress/zstd_opt.h +1 -1
  64. data/contrib/zstd/lib/compress/zstdmt_compress.c +181 -457
  65. data/contrib/zstd/lib/compress/zstdmt_compress.h +34 -113
  66. data/contrib/zstd/lib/decompress/huf_decompress.c +1199 -565
  67. data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +576 -0
  68. data/contrib/zstd/lib/decompress/zstd_ddict.c +12 -12
  69. data/contrib/zstd/lib/decompress/zstd_ddict.h +2 -2
  70. data/contrib/zstd/lib/decompress/zstd_decompress.c +627 -157
  71. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1086 -326
  72. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +19 -5
  73. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +62 -13
  74. data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
  75. data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
  76. data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
  77. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
  78. data/contrib/zstd/lib/dictBuilder/cover.c +73 -52
  79. data/contrib/zstd/lib/dictBuilder/cover.h +7 -6
  80. data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
  81. data/contrib/zstd/lib/dictBuilder/fastcover.c +44 -35
  82. data/contrib/zstd/lib/dictBuilder/zdict.c +103 -111
  83. data/contrib/zstd/lib/legacy/zstd_legacy.h +8 -1
  84. data/contrib/zstd/lib/legacy/zstd_v01.c +21 -54
  85. data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
  86. data/contrib/zstd/lib/legacy/zstd_v02.c +29 -70
  87. data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
  88. data/contrib/zstd/lib/legacy/zstd_v03.c +30 -73
  89. data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
  90. data/contrib/zstd/lib/legacy/zstd_v04.c +29 -71
  91. data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
  92. data/contrib/zstd/lib/legacy/zstd_v05.c +40 -86
  93. data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
  94. data/contrib/zstd/lib/legacy/zstd_v06.c +47 -88
  95. data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
  96. data/contrib/zstd/lib/legacy/zstd_v07.c +40 -83
  97. data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
  98. data/contrib/zstd/lib/libzstd.mk +214 -0
  99. data/contrib/zstd/lib/libzstd.pc.in +7 -6
  100. data/contrib/zstd/lib/module.modulemap +35 -0
  101. data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +203 -34
  102. data/contrib/zstd/lib/zstd.h +1217 -287
  103. data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +28 -8
  104. data/ext/extconf.rb +7 -6
  105. data/ext/extzstd.c +19 -10
  106. data/ext/extzstd.h +6 -0
  107. data/ext/libzstd_conf.h +0 -1
  108. data/ext/zstd_decompress_asm.S +1 -0
  109. data/gemstub.rb +3 -21
  110. data/lib/extzstd/version.rb +6 -1
  111. data/lib/extzstd.rb +0 -2
  112. data/test/test_basic.rb +0 -5
  113. metadata +18 -6
@@ -5,9 +5,9 @@ possible.
5
5
  ## Our Development Process
6
6
  New versions are being developed in the "dev" branch,
7
7
  or in their own feature branch.
8
- When they are deemed ready for a release, they are merged into "master".
8
+ When they are deemed ready for a release, they are merged into "release".
9
9
 
10
- As a consequences, all contributions must stage first through "dev"
10
+ As a consequence, all contributions must stage first through "dev"
11
11
  or their own feature branch.
12
12
 
13
13
  ## Pull Requests
@@ -47,7 +47,7 @@ Our contribution process works in three main stages:
47
47
  * Topic and development:
48
48
  * Make a new branch on your fork about the topic you're developing for
49
49
  ```
50
- # branch names should be consise but sufficiently informative
50
+ # branch names should be concise but sufficiently informative
51
51
  git checkout -b <branch-name>
52
52
  git push origin <branch-name>
53
53
  ```
@@ -68,8 +68,8 @@ Our contribution process works in three main stages:
68
68
  ```
69
69
  2. Code Review and CI tests
70
70
  * Ensure CI tests pass:
71
- * Before sharing anything to the community, make sure that all CI tests pass on your local fork.
72
- See our section on setting up your CI environment for more information on how to do this.
71
+ * Before sharing anything to the community, create a pull request in your own fork against the dev branch
72
+ and make sure that all GitHub Actions CI tests pass. See the Continuous Integration section below for more information.
73
73
  * Ensure that static analysis passes on your development machine. See the Static Analysis section
74
74
  below to see how to do this.
75
75
  * Create a pull request:
@@ -104,7 +104,7 @@ Our contribution process works in three main stages:
104
104
  issue at hand, then please indicate this by requesting that an issue be closed by commenting.
105
105
  * Just because your changes have been merged does not mean the topic or larger issue is complete. Remember
106
106
  that the change must make it to an official zstd release for it to be meaningful. We recommend
107
- that contributers track the activity on their pull request and corresponding issue(s) page(s) until
107
+ that contributors track the activity on their pull request and corresponding issue(s) page(s) until
108
108
  their change makes it to the next release of zstd. Users will often discover bugs in your code or
109
109
  suggest ways to refine and improve your initial changes even after the pull request is merged.
110
110
 
@@ -126,6 +126,56 @@ just `contrib/largeNbDicts` and nothing else, you can run:
126
126
  scan-build make -C contrib/largeNbDicts largeNbDicts
127
127
  ```
128
128
 
129
+ ### Pitfalls of static analysis
130
+ `scan-build` is part of our regular CI suite. Other static analyzers are not.
131
+
132
+ It can be useful to look at additional static analyzers once in a while (and we do), but it's not a good idea to multiply the nb of analyzers run continuously at each commit and PR. The reasons are :
133
+
134
+ - Static analyzers are full of false positive. The signal to noise ratio is actually pretty low.
135
+ - A good CI policy is "zero-warning tolerance". That means that all issues must be solved, including false positives. This quickly becomes a tedious workload.
136
+ - Multiple static analyzers will feature multiple kind of false positives, sometimes applying to the same code but in different ways leading to :
137
+ + tortuous code, trying to please multiple constraints, hurting readability and therefore maintenance. Sometimes, such complexity introduce other more subtle bugs, that are just out of scope of the analyzers.
138
+ + sometimes, these constraints are mutually exclusive : if one try to solve one, the other static analyzer will complain, they can't be both happy at the same time.
139
+ - As if that was not enough, the list of false positives change with each version. It's hard enough to follow one static analyzer, but multiple ones with their own update agenda, this quickly becomes a massive velocity reducer.
140
+
141
+ This is different from running a static analyzer once in a while, looking at the output, and __cherry picking__ a few warnings that seem helpful, either because they detected a genuine risk of bug, or because it helps expressing the code in a way which is more readable or more difficult to misuse. These kinds of reports can be useful, and are accepted.
142
+
143
+ ## Continuous Integration
144
+ CI tests run every time a pull request (PR) is created or updated. The exact tests
145
+ that get run will depend on the destination branch you specify. Some tests take
146
+ longer to run than others. Currently, our CI is set up to run a short
147
+ series of tests when creating a PR to the dev branch and a longer series of tests
148
+ when creating a PR to the release branch. You can look in the configuration files
149
+ of the respective CI platform for more information on what gets run when.
150
+
151
+ Most people will just want to create a PR with the destination set to their local dev
152
+ branch of zstd. You can then find the status of the tests on the PR's page. You can also
153
+ re-run tests and cancel running tests from the PR page or from the respective CI's dashboard.
154
+
155
+ Almost all of zstd's CI runs on GitHub Actions (configured at `.github/workflows`), which will automatically run on PRs to your
156
+ own fork. A small number of tests run on other services (e.g. Travis CI, Circle CI, Appveyor).
157
+ These require work to set up on your local fork, and (at least for Travis CI) cost money.
158
+ Therefore, if the PR on your local fork passes GitHub Actions, feel free to submit a PR
159
+ against the main repo.
160
+
161
+ ### Third-party CI
162
+ A small number of tests cannot run on GitHub Actions, or have yet to be migrated.
163
+ For these, we use a variety of third-party services (listed below). It is not necessary to set
164
+ these up on your fork in order to contribute to zstd; however, we do link to instructions for those
165
+ who want earlier signal.
166
+
167
+ | Service | Purpose | Setup Links | Config Path |
168
+ |-----------|------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
169
+ | Travis CI | Used for testing on non-x86 architectures such as PowerPC | https://docs.travis-ci.com/user/tutorial/#to-get-started-with-travis-ci-using-github <br> https://github.com/marketplace/travis-ci | `.travis.yml` |
170
+ | AppVeyor | Used for some Windows testing (e.g. cygwin, mingw) | https://www.appveyor.com/blog/2018/10/02/github-apps-integration/ <br> https://github.com/marketplace/appveyor | `appveyor.yml` |
171
+ | Cirrus CI | Used for testing on FreeBSD | https://github.com/marketplace/cirrus-ci/ | `.cirrus.yml` |
172
+ | Circle CI | Historically was used to provide faster signal,<br/> but we may be able to migrate these to Github Actions | https://circleci.com/docs/2.0/getting-started/#setting-up-circleci <br> https://youtu.be/Js3hMUsSZ2c <br> https://circleci.com/docs/2.0/enable-checks/ | `.circleci/config.yml` |
173
+
174
+ Note: the instructions linked above mostly cover how to set up a repository with CI from scratch.
175
+ The general idea should be the same for setting up CI on your fork of zstd, but you may have to
176
+ follow slightly different steps. In particular, please ignore any instructions related to setting up
177
+ config files (since zstd already has configs for each of these services).
178
+
129
179
  ## Performance
130
180
  Performance is extremely important for zstd and we only merge pull requests whose performance
131
181
  landscape and corresponding trade-offs have been adequately analyzed, reproduced, and presented.
@@ -147,7 +197,7 @@ something subtle merged is extensive benchmarking. You will be doing us a great
147
197
  take the time to run extensive, long-duration, and potentially cross-(os, platform, process, etc)
148
198
  benchmarks on your end before submitting a PR. Of course, you will not be able to benchmark
149
199
  your changes on every single processor and os out there (and neither will we) but do that best
150
- you can:) We've adding some things to think about when benchmarking below in the Benchmarking
200
+ you can:) We've added some things to think about when benchmarking below in the Benchmarking
151
201
  Performance section which might be helpful for you.
152
202
  3. Optimizing performance for a certain OS, processor vendor, compiler, or network system is a perfectly
153
203
  legitimate thing to do as long as it does not harm the overall performance health of Zstd.
@@ -223,7 +273,7 @@ for that options you have just provided. If you want to look at the internals of
223
273
  benchmarking script works, you can check out programs/benchzstd.c
224
274
 
225
275
  For example: say you have made a change that you believe improves the speed of zstd level 1. The
226
- very first thing you should use to asses whether you actually achieved any sort of improvement
276
+ very first thing you should use to assess whether you actually achieved any sort of improvement
227
277
  is `zstd -b`. You might try to do something like this. Note: you can use the `-i` option to
228
278
  specify a running time for your benchmark in seconds (default is 3 seconds).
229
279
  Usually, the longer the running time, the more stable your results will be.
@@ -249,24 +299,24 @@ this method of evaluation will not be sufficient.
249
299
  ### Profiling
250
300
  There are a number of great profilers out there. We're going to briefly mention how you can
251
301
  profile your code using `instruments` on mac, `perf` on linux and `visual studio profiler`
252
- on windows.
302
+ on Windows.
253
303
 
254
304
  Say you have an idea for a change that you think will provide some good performance gains
255
305
  for level 1 compression on Zstd. Typically this means, you have identified a section of
256
306
  code that you think can be made to run faster.
257
307
 
258
308
  The first thing you will want to do is make sure that the piece of code is actually taking up
259
- a notable amount of time to run. It is usually not worth optimzing something which accounts for less than
309
+ a notable amount of time to run. It is usually not worth optimizing something which accounts for less than
260
310
  0.0001% of the total running time. Luckily, there are tools to help with this.
261
311
  Profilers will let you see how much time your code spends inside a particular function.
262
- If your target code snippit is only part of a function, it might be worth trying to
263
- isolate that snippit by moving it to its own function (this is usually not necessary but
312
+ If your target code snippet is only part of a function, it might be worth trying to
313
+ isolate that snippet by moving it to its own function (this is usually not necessary but
264
314
  might be).
265
315
 
266
- Most profilers (including the profilers dicusssed below) will generate a call graph of
267
- functions for you. Your goal will be to find your function of interest in this call grapch
268
- and then inspect the time spent inside of it. You might also want to to look at the
269
- annotated assembly which most profilers will provide you with.
316
+ Most profilers (including the profilers discussed below) will generate a call graph of
317
+ functions for you. Your goal will be to find your function of interest in this call graph
318
+ and then inspect the time spent inside of it. You might also want to look at the annotated
319
+ assembly which most profilers will provide you with.
270
320
 
271
321
  #### Instruments
272
322
  We will once again consider the scenario where you think you've identified a piece of code
@@ -280,23 +330,23 @@ Instruments.
280
330
  * You will want a benchmark that runs for at least a few seconds (5 seconds will
281
331
  usually be long enough). This way the profiler will have something to work with
282
332
  and you will have ample time to attach your profiler to this process:)
283
- * I will just use benchzstd as my bencharmking script for this example:
333
+ * I will just use benchzstd as my benchmarmking script for this example:
284
334
  ```
285
335
  $ zstd -b1 -i5 <my-data> # this will run for 5 seconds
286
336
  ```
287
337
  5. Once you run your benchmarking script, switch back over to instruments and attach your
288
338
  process to the time profiler. You can do this by:
289
339
  * Clicking on the `All Processes` drop down in the top left of the toolbar.
290
- * Selecting your process from the dropdown. In my case, it is just going to be labled
340
+ * Selecting your process from the dropdown. In my case, it is just going to be labeled
291
341
  `zstd`
292
342
  * Hitting the bright red record circle button on the top left of the toolbar
293
- 6. You profiler will now start collecting metrics from your bencharking script. Once
343
+ 6. You profiler will now start collecting metrics from your benchmarking script. Once
294
344
  you think you have collected enough samples (usually this is the case after 3 seconds of
295
345
  recording), stop your profiler.
296
346
  7. Make sure that in toolbar of the bottom window, `profile` is selected.
297
347
  8. You should be able to see your call graph.
298
348
  * If you don't see the call graph or an incomplete call graph, make sure you have compiled
299
- zstd and your benchmarking scripg using debug flags. On mac and linux, this just means
349
+ zstd and your benchmarking script using debug flags. On mac and linux, this just means
300
350
  you will have to supply the `-g` flag alone with your build script. You might also
301
351
  have to provide the `-fno-omit-frame-pointer` flag
302
352
  9. Dig down the graph to find your function call and then inspect it by double clicking
@@ -315,7 +365,7 @@ Some general notes on perf:
315
365
  counter statistics. Perf uses a high resolution timer and this is likely one
316
366
  of the first things your team will run when assessing your PR.
317
367
  * Perf has a long list of hardware counters that can be viewed with `perf --list`.
318
- When measuring optimizations, something worth trying is to make sure the handware
368
+ When measuring optimizations, something worth trying is to make sure the hardware
319
369
  counters you expect to be impacted by your change are in fact being so. For example,
320
370
  if you expect the L1 cache misses to decrease with your change, you can look at the
321
371
  counter `L1-dcache-load-misses`
@@ -325,57 +375,6 @@ counter `L1-dcache-load-misses`
325
375
 
326
376
  TODO
327
377
 
328
-
329
- ## Setting up continuous integration (CI) on your fork
330
- Zstd uses a number of different continuous integration (CI) tools to ensure that new changes
331
- are well tested before they make it to an official release. Specifically, we use the platforms
332
- travis-ci, circle-ci, and appveyor.
333
-
334
- Changes cannot be merged into the main dev branch unless they pass all of our CI tests.
335
- The easiest way to run these CI tests on your own before submitting a PR to our dev branch
336
- is to configure your personal fork of zstd with each of the CI platforms. Below, you'll find
337
- instructions for doing this.
338
-
339
- ### travis-ci
340
- Follow these steps to link travis-ci with your github fork of zstd
341
-
342
- 1. Make sure you are logged into your github account
343
- 2. Go to https://travis-ci.org/
344
- 3. Click 'Sign in with Github' on the top right
345
- 4. Click 'Authorize travis-ci'
346
- 5. Click 'Activate all repositories using Github Apps'
347
- 6. Select 'Only select repositories' and select your fork of zstd from the drop down
348
- 7. Click 'Approve and Install'
349
- 8. Click 'Sign in with Github' again. This time, it will be for travis-pro (which will let you view your tests on the web dashboard)
350
- 9. Click 'Authorize travis-pro'
351
- 10. You should have travis set up on your fork now.
352
-
353
- ### circle-ci
354
- TODO
355
-
356
- ### appveyor
357
- Follow these steps to link circle-ci with your girhub fork of zstd
358
-
359
- 1. Make sure you are logged into your github account
360
- 2. Go to https://www.appveyor.com/
361
- 3. Click 'Sign in' on the top right
362
- 4. Select 'Github' on the left panel
363
- 5. Click 'Authorize appveyor'
364
- 6. You might be asked to select which repositories you want to give appveyor permission to. Select your fork of zstd if you're prompted
365
- 7. You should have appveyor set up on your fork now.
366
-
367
- ### General notes on CI
368
- CI tests run every time a pull request (PR) is created or updated. The exact tests
369
- that get run will depend on the destination branch you specify. Some tests take
370
- longer to run than others. Currently, our CI is set up to run a short
371
- series of tests when creating a PR to the dev branch and a longer series of tests
372
- when creating a PR to the master branch. You can look in the configuration files
373
- of the respective CI platform for more information on what gets run when.
374
-
375
- Most people will just want to create a PR with the destination set to their local dev
376
- branch of zstd. You can then find the status of the tests on the PR's page. You can also
377
- re-run tests and cancel running tests from the PR page or from the respective CI's dashboard.
378
-
379
378
  ## Issues
380
379
  We use GitHub issues to track public bugs. Please ensure your description is
381
380
  clear and has sufficient instructions to be able to reproduce the issue.
@@ -385,7 +384,105 @@ disclosure of security bugs. In those cases, please go through the process
385
384
  outlined on that page and do not file a public issue.
386
385
 
387
386
  ## Coding Style
387
+ It's a pretty long topic, which is difficult to summarize in a single paragraph.
388
+ As a rule of thumbs, try to imitate the coding style of
389
+ similar lines of codes around your contribution.
390
+ The following is a non-exhaustive list of rules employed in zstd code base:
391
+
392
+ ### C90
393
+ This code base is following strict C90 standard,
394
+ with 2 extensions : 64-bit `long long` types, and variadic macros.
395
+ This rule is applied strictly to code within `lib/` and `programs/`.
396
+ Sub-project in `contrib/` are allowed to use other conventions.
397
+
398
+ ### C++ direct compatibility : symbol mangling
399
+ All public symbol declarations must be wrapped in `extern “C” { … }`,
400
+ so that this project can be compiled as C++98 code,
401
+ and linked into C++ applications.
402
+
403
+ ### Minimal Frugal
404
+ This design requirement is fundamental to preserve the portability of the code base.
405
+ #### Dependencies
406
+ - Reduce dependencies to the minimum possible level.
407
+ Any dependency should be considered “bad” by default,
408
+ and only tolerated because it provides a service in a better way than can be achieved locally.
409
+ The only external dependencies this repository tolerates are
410
+ standard C libraries, and in rare cases, system level headers.
411
+ - Within `lib/`, this policy is even more drastic.
412
+ The only external dependencies allowed are `<assert.h>`, `<stdlib.h>`, `<string.h>`,
413
+ and even then, not directly.
414
+ In particular, no function shall ever allocate on heap directly,
415
+ and must use instead `ZSTD_malloc()` and equivalent.
416
+ Other accepted non-symbol headers are `<stddef.h>` and `<limits.h>`.
417
+ - Within the project, there is a strict hierarchy of dependencies that must be respected.
418
+ `programs/` is allowed to depend on `lib/`, but only its public API.
419
+ Within `lib/`, `lib/common` doesn't depend on any other directory.
420
+ `lib/compress` and `lib/decompress` shall not depend on each other.
421
+ `lib/dictBuilder` can depend on `lib/common` and `lib/compress`, but not `lib/decompress`.
422
+ #### Resources
423
+ - Functions in `lib/` must use very little stack space,
424
+ several dozens of bytes max.
425
+ Everything larger must use the heap allocator,
426
+ or require a scratch buffer to be emplaced manually.
427
+
428
+ ### Naming
429
+ * All public symbols are prefixed with `ZSTD_`
430
+ + private symbols, with a scope limited to their own unit, are free of this restriction.
431
+ However, since `libzstd` source code can be amalgamated,
432
+ each symbol name must attempt to be (and remain) unique.
433
+ Avoid too generic names that could become ground for future collisions.
434
+ This generally implies usage of some form of prefix.
435
+ * For symbols (functions and variables), naming convention is `PREFIX_camelCase`.
436
+ + In some advanced cases, one can also find :
437
+ - `PREFIX_prefix2_camelCase`
438
+ - `PREFIX_camelCase_extendedQualifier`
439
+ * Multi-words names generally consist of an action followed by object:
440
+ - for example : `ZSTD_createCCtx()`
441
+ * Prefer positive actions
442
+ - `goBackward` rather than `notGoForward`
443
+ * Type names (`struct`, etc.) follow similar convention,
444
+ except that they are allowed and even invited to start by an Uppercase letter.
445
+ Example : `ZSTD_CCtx`, `ZSTD_CDict`
446
+ * Macro names are all Capital letters.
447
+ The same composition rules (`PREFIX_NAME_QUALIFIER`) apply.
448
+ * File names are all lowercase letters.
449
+ The convention is `snake_case`.
450
+ File names **must** be unique across the entire code base,
451
+ even when they stand in clearly separated directories.
452
+
453
+ ### Qualifiers
454
+ * This code base is `const` friendly, if not `const` fanatical.
455
+ Any variable that can be `const` (aka. read-only) **must** be `const`.
456
+ Any pointer which content will not be modified must be `const`.
457
+ This property is then controlled at compiler level.
458
+ `const` variables are an important signal to readers that this variable isn't modified.
459
+ Conversely, non-const variables are a signal to readers to watch out for modifications later on in the function.
460
+ * If a function must be inlined, mention it explicitly,
461
+ using project's own portable macros, such as `FORCE_INLINE_ATTR`,
462
+ defined in `lib/common/compiler.h`.
463
+
464
+ ### Debugging
465
+ * **Assertions** are welcome, and should be used very liberally,
466
+ to control any condition the code expects for its correct execution.
467
+ These assertion checks will be run in debug builds, and disabled in production.
468
+ * For traces, this project provides its own debug macros,
469
+ in particular `DEBUGLOG(level, ...)`, defined in `lib/common/debug.h`.
470
+
471
+ ### Code documentation
472
+ * Avoid code documentation that merely repeats what the code is already stating.
473
+ Whenever applicable, prefer employing the code as the primary way to convey explanations.
474
+ Example 1 : `int nbTokens = n;` instead of `int i = n; /* i is a nb of tokens *./`.
475
+ Example 2 : `assert(size > 0);` instead of `/* here, size should be positive */`.
476
+ * At declaration level, the documentation explains how to use the function or variable
477
+ and when applicable why it's needed, of the scenarios where it can be useful.
478
+ * At implementation level, the documentation explains the general outline of the algorithm employed,
479
+ and when applicable why this specific choice was preferred.
480
+
481
+ ### General layout
388
482
  * 4 spaces for indentation rather than tabs
483
+ * Code documentation shall directly precede function declaration or implementation
484
+ * Function implementations and its code documentation should be preceded and followed by an empty line
485
+
389
486
 
390
487
  ## License
391
488
  By contributing to Zstandard, you agree that your contributions will be licensed
data/contrib/zstd/LICENSE CHANGED
@@ -2,7 +2,7 @@ BSD License
2
2
 
3
3
  For Zstandard software
4
4
 
5
- Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
5
+ Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
6
6
 
7
7
  Redistribution and use in source and binary forms, with or without modification,
8
8
  are permitted provided that the following conditions are met:
@@ -14,9 +14,9 @@ are permitted provided that the following conditions are met:
14
14
  this list of conditions and the following disclaimer in the documentation
15
15
  and/or other materials provided with the distribution.
16
16
 
17
- * Neither the name Facebook nor the names of its contributors may be used to
18
- endorse or promote products derived from this software without specific
19
- prior written permission.
17
+ * Neither the name Facebook, nor Meta, nor the names of its contributors may
18
+ be used to endorse or promote products derived from this software without
19
+ specific prior written permission.
20
20
 
21
21
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22
22
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED