constants.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Copyright (c) 2016-present, Gregory Szorc
  3. * All rights reserved.
  4. *
  5. * This software may be modified and distributed under the terms
  6. * of the BSD license. See the LICENSE file for details.
  7. */
  8. #include "python-zstandard.h"
  9. extern PyObject *ZstdError;
  10. static char frame_header[] = {
  11. '\x28',
  12. '\xb5',
  13. '\x2f',
  14. '\xfd',
  15. };
  16. void constants_module_init(PyObject *mod) {
  17. PyObject *version;
  18. PyObject *zstdVersion;
  19. PyObject *frameHeader;
  20. version = PyUnicode_FromString(PYTHON_ZSTANDARD_VERSION);
  21. PyModule_AddObject(mod, "__version__", version);
  22. ZstdError = PyErr_NewException("zstd.ZstdError", NULL, NULL);
  23. PyModule_AddObject(mod, "ZstdError", ZstdError);
  24. PyModule_AddIntConstant(mod, "FLUSH_BLOCK", 0);
  25. PyModule_AddIntConstant(mod, "FLUSH_FRAME", 1);
  26. PyModule_AddIntConstant(mod, "COMPRESSOBJ_FLUSH_FINISH",
  27. compressorobj_flush_finish);
  28. PyModule_AddIntConstant(mod, "COMPRESSOBJ_FLUSH_BLOCK",
  29. compressorobj_flush_block);
  30. /* For now, the version is a simple tuple instead of a dedicated type. */
  31. zstdVersion = PyTuple_New(3);
  32. PyTuple_SetItem(zstdVersion, 0, PyLong_FromLong(ZSTD_VERSION_MAJOR));
  33. PyTuple_SetItem(zstdVersion, 1, PyLong_FromLong(ZSTD_VERSION_MINOR));
  34. PyTuple_SetItem(zstdVersion, 2, PyLong_FromLong(ZSTD_VERSION_RELEASE));
  35. PyModule_AddObject(mod, "ZSTD_VERSION", zstdVersion);
  36. frameHeader = PyBytes_FromStringAndSize(frame_header, sizeof(frame_header));
  37. if (frameHeader) {
  38. PyModule_AddObject(mod, "FRAME_HEADER", frameHeader);
  39. }
  40. else {
  41. PyErr_Format(PyExc_ValueError, "could not create frame header object");
  42. }
  43. PyModule_AddObject(mod, "CONTENTSIZE_UNKNOWN",
  44. PyLong_FromUnsignedLongLong(ZSTD_CONTENTSIZE_UNKNOWN));
  45. PyModule_AddObject(mod, "CONTENTSIZE_ERROR",
  46. PyLong_FromUnsignedLongLong(ZSTD_CONTENTSIZE_ERROR));
  47. PyModule_AddIntConstant(mod, "MAX_COMPRESSION_LEVEL", ZSTD_maxCLevel());
  48. PyModule_AddIntConstant(mod, "COMPRESSION_RECOMMENDED_INPUT_SIZE",
  49. (long)ZSTD_CStreamInSize());
  50. PyModule_AddIntConstant(mod, "COMPRESSION_RECOMMENDED_OUTPUT_SIZE",
  51. (long)ZSTD_CStreamOutSize());
  52. PyModule_AddIntConstant(mod, "DECOMPRESSION_RECOMMENDED_INPUT_SIZE",
  53. (long)ZSTD_DStreamInSize());
  54. PyModule_AddIntConstant(mod, "DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE",
  55. (long)ZSTD_DStreamOutSize());
  56. PyModule_AddIntConstant(mod, "MAGIC_NUMBER", ZSTD_MAGICNUMBER);
  57. PyModule_AddIntConstant(mod, "BLOCKSIZELOG_MAX", ZSTD_BLOCKSIZELOG_MAX);
  58. PyModule_AddIntConstant(mod, "BLOCKSIZE_MAX", ZSTD_BLOCKSIZE_MAX);
  59. PyModule_AddIntConstant(mod, "WINDOWLOG_MIN", ZSTD_WINDOWLOG_MIN);
  60. PyModule_AddIntConstant(mod, "WINDOWLOG_MAX", ZSTD_WINDOWLOG_MAX);
  61. PyModule_AddIntConstant(mod, "CHAINLOG_MIN", ZSTD_CHAINLOG_MIN);
  62. PyModule_AddIntConstant(mod, "CHAINLOG_MAX", ZSTD_CHAINLOG_MAX);
  63. PyModule_AddIntConstant(mod, "HASHLOG_MIN", ZSTD_HASHLOG_MIN);
  64. PyModule_AddIntConstant(mod, "HASHLOG_MAX", ZSTD_HASHLOG_MAX);
  65. PyModule_AddIntConstant(mod, "SEARCHLOG_MIN", ZSTD_SEARCHLOG_MIN);
  66. PyModule_AddIntConstant(mod, "SEARCHLOG_MAX", ZSTD_SEARCHLOG_MAX);
  67. PyModule_AddIntConstant(mod, "MINMATCH_MIN", ZSTD_MINMATCH_MIN);
  68. PyModule_AddIntConstant(mod, "MINMATCH_MAX", ZSTD_MINMATCH_MAX);
  69. /* TODO SEARCHLENGTH_* is deprecated. */
  70. PyModule_AddIntConstant(mod, "SEARCHLENGTH_MIN", ZSTD_MINMATCH_MIN);
  71. PyModule_AddIntConstant(mod, "SEARCHLENGTH_MAX", ZSTD_MINMATCH_MAX);
  72. PyModule_AddIntConstant(mod, "TARGETLENGTH_MIN", ZSTD_TARGETLENGTH_MIN);
  73. PyModule_AddIntConstant(mod, "TARGETLENGTH_MAX", ZSTD_TARGETLENGTH_MAX);
  74. PyModule_AddIntConstant(mod, "LDM_MINMATCH_MIN", ZSTD_LDM_MINMATCH_MIN);
  75. PyModule_AddIntConstant(mod, "LDM_MINMATCH_MAX", ZSTD_LDM_MINMATCH_MAX);
  76. PyModule_AddIntConstant(mod, "LDM_BUCKETSIZELOG_MAX",
  77. ZSTD_LDM_BUCKETSIZELOG_MAX);
  78. PyModule_AddIntConstant(mod, "STRATEGY_FAST", ZSTD_fast);
  79. PyModule_AddIntConstant(mod, "STRATEGY_DFAST", ZSTD_dfast);
  80. PyModule_AddIntConstant(mod, "STRATEGY_GREEDY", ZSTD_greedy);
  81. PyModule_AddIntConstant(mod, "STRATEGY_LAZY", ZSTD_lazy);
  82. PyModule_AddIntConstant(mod, "STRATEGY_LAZY2", ZSTD_lazy2);
  83. PyModule_AddIntConstant(mod, "STRATEGY_BTLAZY2", ZSTD_btlazy2);
  84. PyModule_AddIntConstant(mod, "STRATEGY_BTOPT", ZSTD_btopt);
  85. PyModule_AddIntConstant(mod, "STRATEGY_BTULTRA", ZSTD_btultra);
  86. PyModule_AddIntConstant(mod, "STRATEGY_BTULTRA2", ZSTD_btultra2);
  87. PyModule_AddIntConstant(mod, "DICT_TYPE_AUTO", ZSTD_dct_auto);
  88. PyModule_AddIntConstant(mod, "DICT_TYPE_RAWCONTENT", ZSTD_dct_rawContent);
  89. PyModule_AddIntConstant(mod, "DICT_TYPE_FULLDICT", ZSTD_dct_fullDict);
  90. PyModule_AddIntConstant(mod, "FORMAT_ZSTD1", ZSTD_f_zstd1);
  91. PyModule_AddIntConstant(mod, "FORMAT_ZSTD1_MAGICLESS",
  92. ZSTD_f_zstd1_magicless);
  93. }