Debian Codegraph @

src/c/compression_zstd/clinic/zstddict.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #include "backports_zstd_edits.h"
6
7 PyDoc_STRVAR(_zstd_ZstdDict_new__doc__,
8 "ZstdDict(dict_content, /, *, is_raw=False)\n"
9 "--\n"
10 "\n"
11 "Represents a Zstandard dictionary.\n"
12 "\n"
13 " dict_content\n"
14 " The content of a Zstandard dictionary as a bytes-like object.\n"
15 " is_raw\n"
16 " If true, perform no checks on *dict_content*, useful for some\n"
17 " advanced cases. Otherwise, check that the content represents\n"
18 " a Zstandard dictionary created by the zstd library or CLI.\n"
19 "\n"
20 "The dictionary can be used for compression or decompression, and can be\n"
21 "shared by multiple ZstdCompressor or ZstdDecompressor objects.");
22
23 static PyObject *
24 _zstd_ZstdDict_new_impl(PyTypeObject *type, Py_buffer *dict_content,
25 int is_raw);
26
27 static PyObject *
28 _zstd_ZstdDict_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
29 {
30 PyObject *return_value = NULL;
31 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
32
33 #define NUM_KEYWORDS 1
34 static struct {
35 PyGC_Head _this_is_not_used;
36 PyObject_VAR_HEAD
37 Py_hash_t ob_hash;
38 PyObject *ob_item[NUM_KEYWORDS];
39 } _kwtuple = {
40 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
41 .ob_hash = -1,
42 .ob_item = { &_Py_ID(is_raw), },
43 };
44 #undef NUM_KEYWORDS
45 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
46
47 #else // !Py_BUILD_CORE
48 # define KWTUPLE NULL
49 #endif // !Py_BUILD_CORE
50
51 static const char * const _keywords[] = {"", "is_raw", NULL};
52 static _PyArg_Parser _parser = {
53 .keywords = _keywords,
54 .fname = "ZstdDict",
55 .kwtuple = KWTUPLE,
56 };
57 #undef KWTUPLE
58 PyObject *argsbuf[2];
59 PyObject * const *fastargs;
60 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
61 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
62 Py_buffer dict_content = {NULL, NULL};
63 int is_raw = 0;
64
65 fastargs = BACKPORTSZSTD__PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
66 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
67 if (!fastargs) {
68 goto exit;
69 }
70 if (PyObject_GetBuffer(fastargs[0], &dict_content, PyBUF_SIMPLE) != 0) {
71 goto exit;
72 }
73 if (!noptargs) {
74 goto skip_optional_kwonly;
75 }
76 is_raw = PyObject_IsTrue(fastargs[1]);
77 if (is_raw < 0) {
78 goto exit;
79 }
80 skip_optional_kwonly:
81 return_value = _zstd_ZstdDict_new_impl(type, &dict_content, is_raw);
82
83 exit:
84 /* Cleanup for dict_content */
85 if (dict_content.obj) {
86 PyBuffer_Release(&dict_content);
87 }
88
89 return return_value;
90 }
91
92 PyDoc_STRVAR(_zstd_ZstdDict_dict_content__doc__,
93 "The content of a Zstandard dictionary, as a bytes object.");
94 #if defined(_zstd_ZstdDict_dict_content_DOCSTR)
95 # undef _zstd_ZstdDict_dict_content_DOCSTR
96 #endif
97 #define _zstd_ZstdDict_dict_content_DOCSTR _zstd_ZstdDict_dict_content__doc__
98
99 #if !defined(_zstd_ZstdDict_dict_content_DOCSTR)
100 # define _zstd_ZstdDict_dict_content_DOCSTR NULL
101 #endif
102 #if defined(_ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF)
103 # undef _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF
104 # define _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF {"dict_content", (getter)_zstd_ZstdDict_dict_content_get, (setter)_zstd_ZstdDict_dict_content_set, _zstd_ZstdDict_dict_content_DOCSTR},
105 #else
106 # define _ZSTD_ZSTDDICT_DICT_CONTENT_GETSETDEF {"dict_content", (getter)_zstd_ZstdDict_dict_content_get, NULL, _zstd_ZstdDict_dict_content_DOCSTR},
107 #endif
108
109 static PyObject *
110 _zstd_ZstdDict_dict_content_get_impl(ZstdDict *self);
111
112 static PyObject *
113 _zstd_ZstdDict_dict_content_get(PyObject *self, void *Py_UNUSED(context))
114 {
115 return _zstd_ZstdDict_dict_content_get_impl((ZstdDict *)self);
116 }
117
118 PyDoc_STRVAR(_zstd_ZstdDict_as_digested_dict__doc__,
119 "Load as a digested dictionary to compressor.\n"
120 "\n"
121 "Pass this attribute as zstd_dict argument:\n"
122 "compress(dat, zstd_dict=zd.as_digested_dict)\n"
123 "\n"
124 "1. Some advanced compression parameters of compressor may be\n"
125 " overridden by parameters of digested dictionary.\n"
126 "2. ZstdDict has a digested dictionaries cache for each compression\n"
127 " level. It\'s faster when loading again a digested dictionary with\n"
128 " the same compression level.\n"
129 "3. No need to use this for decompression.");
130 #if defined(_zstd_ZstdDict_as_digested_dict_DOCSTR)
131 # undef _zstd_ZstdDict_as_digested_dict_DOCSTR
132 #endif
133 #define _zstd_ZstdDict_as_digested_dict_DOCSTR _zstd_ZstdDict_as_digested_dict__doc__
134
135 #if !defined(_zstd_ZstdDict_as_digested_dict_DOCSTR)
136 # define _zstd_ZstdDict_as_digested_dict_DOCSTR NULL
137 #endif
138 #if defined(_ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF)
139 # undef _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF
140 # define _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF {"as_digested_dict", (getter)_zstd_ZstdDict_as_digested_dict_get, (setter)_zstd_ZstdDict_as_digested_dict_set, _zstd_ZstdDict_as_digested_dict_DOCSTR},
141 #else
142 # define _ZSTD_ZSTDDICT_AS_DIGESTED_DICT_GETSETDEF {"as_digested_dict", (getter)_zstd_ZstdDict_as_digested_dict_get, NULL, _zstd_ZstdDict_as_digested_dict_DOCSTR},
143 #endif
144
145 static PyObject *
146 _zstd_ZstdDict_as_digested_dict_get_impl(ZstdDict *self);
147
148 static PyObject *
149 _zstd_ZstdDict_as_digested_dict_get(PyObject *self, void *Py_UNUSED(context))
150 {
151 return _zstd_ZstdDict_as_digested_dict_get_impl((ZstdDict *)self);
152 }
153
154 PyDoc_STRVAR(_zstd_ZstdDict_as_undigested_dict__doc__,
155 "Load as an undigested dictionary to compressor.\n"
156 "\n"
157 "Pass this attribute as zstd_dict argument:\n"
158 "compress(dat, zstd_dict=zd.as_undigested_dict)\n"
159 "\n"
160 "1. The advanced compression parameters of compressor will not be\n"
161 " overridden.\n"
162 "2. Loading an undigested dictionary is costly. If load an undigested\n"
163 " dictionary multiple times, consider reusing a compressor object.\n"
164 "3. No need to use this for decompression.");
165 #if defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
166 # undef _zstd_ZstdDict_as_undigested_dict_DOCSTR
167 #endif
168 #define _zstd_ZstdDict_as_undigested_dict_DOCSTR _zstd_ZstdDict_as_undigested_dict__doc__
169
170 #if !defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
171 # define _zstd_ZstdDict_as_undigested_dict_DOCSTR NULL
172 #endif
173 #if defined(_ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF)
174 # undef _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF
175 # define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, (setter)_zstd_ZstdDict_as_undigested_dict_set, _zstd_ZstdDict_as_undigested_dict_DOCSTR},
176 #else
177 # define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, NULL, _zstd_ZstdDict_as_undigested_dict_DOCSTR},
178 #endif
179
180 static PyObject *
181 _zstd_ZstdDict_as_undigested_dict_get_impl(ZstdDict *self);
182
183 static PyObject *
184 _zstd_ZstdDict_as_undigested_dict_get(PyObject *self, void *Py_UNUSED(context))
185 {
186 return _zstd_ZstdDict_as_undigested_dict_get_impl((ZstdDict *)self);
187 }
188
189 PyDoc_STRVAR(_zstd_ZstdDict_as_prefix__doc__,
190 "Load as a prefix to compressor/decompressor.\n"
191 "\n"
192 "Pass this attribute as zstd_dict argument:\n"
193 "compress(dat, zstd_dict=zd.as_prefix)\n"
194 "\n"
195 "1. Prefix is compatible with long distance matching, while\n"
196 " dictionary is not.\n"
197 "2. It only works for the first frame, then the\n"
198 " compressor/decompressor will return to no prefix state.\n"
199 "3. When decompressing, must use the same prefix as when compressing.");
200 #if defined(_zstd_ZstdDict_as_prefix_DOCSTR)
201 # undef _zstd_ZstdDict_as_prefix_DOCSTR
202 #endif
203 #define _zstd_ZstdDict_as_prefix_DOCSTR _zstd_ZstdDict_as_prefix__doc__
204
205 #if !defined(_zstd_ZstdDict_as_prefix_DOCSTR)
206 # define _zstd_ZstdDict_as_prefix_DOCSTR NULL
207 #endif
208 #if defined(_ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF)
209 # undef _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF
210 # define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, (setter)_zstd_ZstdDict_as_prefix_set, _zstd_ZstdDict_as_prefix_DOCSTR},
211 #else
212 # define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, NULL, _zstd_ZstdDict_as_prefix_DOCSTR},
213 #endif
214
215 static PyObject *
216 _zstd_ZstdDict_as_prefix_get_impl(ZstdDict *self);
217
218 static PyObject *
219 _zstd_ZstdDict_as_prefix_get(PyObject *self, void *Py_UNUSED(context))
220 {
221 return _zstd_ZstdDict_as_prefix_get_impl((ZstdDict *)self);
222 }
223 /*[clinic end generated code: output=49b66061b4fcdb5f input=a9049054013a1b77]*/