Debian Codegraph @

c-ext/constants.c

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