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 shared\n"
21 "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 overridden\n"
125 " by parameters of digested dictionary.\n"
126 "2. ZstdDict has a digested dictionaries cache for each compression level.\n"
127 " It\'s faster when loading again a digested dictionary with the same\n"
128 " 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 overridden.\n"
161 "2. Loading an undigested dictionary is costly. If load an undigested dictionary\n"
162 " multiple times, consider reusing a compressor object.\n"
163 "3. No need to use this for decompression.");
164 #if defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
165 # undef _zstd_ZstdDict_as_undigested_dict_DOCSTR
166 #endif
167 #define _zstd_ZstdDict_as_undigested_dict_DOCSTR _zstd_ZstdDict_as_undigested_dict__doc__
168
169 #if !defined(_zstd_ZstdDict_as_undigested_dict_DOCSTR)
170 # define _zstd_ZstdDict_as_undigested_dict_DOCSTR NULL
171 #endif
172 #if defined(_ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF)
173 # undef _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF
174 # 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},
175 #else
176 # define _ZSTD_ZSTDDICT_AS_UNDIGESTED_DICT_GETSETDEF {"as_undigested_dict", (getter)_zstd_ZstdDict_as_undigested_dict_get, NULL, _zstd_ZstdDict_as_undigested_dict_DOCSTR},
177 #endif
178
179 static PyObject *
180 _zstd_ZstdDict_as_undigested_dict_get_impl(ZstdDict *self);
181
182 static PyObject *
183 _zstd_ZstdDict_as_undigested_dict_get(PyObject *self, void *Py_UNUSED(context))
184 {
185 return _zstd_ZstdDict_as_undigested_dict_get_impl((ZstdDict *)self);
186 }
187
188 PyDoc_STRVAR(_zstd_ZstdDict_as_prefix__doc__,
189 "Load as a prefix to compressor/decompressor.\n"
190 "\n"
191 "Pass this attribute as zstd_dict argument:\n"
192 "compress(dat, zstd_dict=zd.as_prefix)\n"
193 "\n"
194 "1. Prefix is compatible with long distance matching, while dictionary is not.\n"
195 "2. It only works for the first frame, then the compressor/decompressor will\n"
196 " return to no prefix state.\n"
197 "3. When decompressing, must use the same prefix as when compressing.");
198 #if defined(_zstd_ZstdDict_as_prefix_DOCSTR)
199 # undef _zstd_ZstdDict_as_prefix_DOCSTR
200 #endif
201 #define _zstd_ZstdDict_as_prefix_DOCSTR _zstd_ZstdDict_as_prefix__doc__
202
203 #if !defined(_zstd_ZstdDict_as_prefix_DOCSTR)
204 # define _zstd_ZstdDict_as_prefix_DOCSTR NULL
205 #endif
206 #if defined(_ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF)
207 # undef _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF
208 # 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},
209 #else
210 # define _ZSTD_ZSTDDICT_AS_PREFIX_GETSETDEF {"as_prefix", (getter)_zstd_ZstdDict_as_prefix_get, NULL, _zstd_ZstdDict_as_prefix_DOCSTR},
211 #endif
212
213 static PyObject *
214 _zstd_ZstdDict_as_prefix_get_impl(ZstdDict *self);
215
216 static PyObject *
217 _zstd_ZstdDict_as_prefix_get(PyObject *self, void *Py_UNUSED(context))
218 {
219 return _zstd_ZstdDict_as_prefix_get_impl((ZstdDict *)self);
220 }
221 /*[clinic end generated code: output=f41d9e2e2cc2928f input=a9049054013a1b77]*/