| 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 |
int set_parameter(ZSTD_CCtx_params *params, ZSTD_cParameter param, int value) { |
| 14 |
size_t zresult = ZSTD_CCtxParams_setParameter(params, param, value); |
| 15 |
if (ZSTD_isError(zresult)) { |
| 16 |
PyErr_Format(ZstdError, |
| 17 |
"unable to set compression context parameter: %s", |
| 18 |
ZSTD_getErrorName(zresult)); |
| 19 |
return 1; |
| 20 |
} |
| 21 |
|
| 22 |
return 0; |
| 23 |
} |
| 24 |
|
| 25 |
#define TRY_SET_PARAMETER(params, param, value) \ |
| 26 |
if (set_parameter(params, param, value)) \ |
| 27 |
return -1; |
| 28 |
|
| 29 |
#define TRY_COPY_PARAMETER(source, dest, param) \ |
| 30 |
{ \ |
| 31 |
int result; \ |
| 32 |
size_t zresult = ZSTD_CCtxParams_getParameter(source, param, &result); \ |
| 33 |
if (ZSTD_isError(zresult)) { \ |
| 34 |
return 1; \ |
| 35 |
} \ |
| 36 |
zresult = ZSTD_CCtxParams_setParameter(dest, param, result); \ |
| 37 |
if (ZSTD_isError(zresult)) { \ |
| 38 |
return 1; \ |
| 39 |
} \ |
| 40 |
} |
| 41 |
|
| 42 |
int set_parameters(ZSTD_CCtx_params *params, |
| 43 |
ZstdCompressionParametersObject *obj) { |
| 44 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_nbWorkers); |
| 45 |
|
| 46 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_format); |
| 47 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_compressionLevel); |
| 48 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_windowLog); |
| 49 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_hashLog); |
| 50 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_chainLog); |
| 51 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_searchLog); |
| 52 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_minMatch); |
| 53 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_targetLength); |
| 54 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_strategy); |
| 55 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_contentSizeFlag); |
| 56 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_checksumFlag); |
| 57 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_dictIDFlag); |
| 58 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_jobSize); |
| 59 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_overlapLog); |
| 60 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_forceMaxWindow); |
| 61 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_enableLongDistanceMatching); |
| 62 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_ldmHashLog); |
| 63 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_ldmMinMatch); |
| 64 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_ldmBucketSizeLog); |
| 65 |
TRY_COPY_PARAMETER(obj->params, params, ZSTD_c_ldmHashRateLog); |
| 66 |
|
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
int reset_params(ZstdCompressionParametersObject *params) { |
| 71 |
if (params->params) { |
| 72 |
ZSTD_CCtxParams_reset(params->params); |
| 73 |
} |
| 74 |
else { |
| 75 |
params->params = ZSTD_createCCtxParams(); |
| 76 |
if (!params->params) { |
| 77 |
PyErr_NoMemory(); |
| 78 |
return 1; |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
return set_parameters(params->params, params); |
| 83 |
} |
| 84 |
|
| 85 |
#define TRY_GET_PARAMETER(params, param, value) \ |
| 86 |
{ \ |
| 87 |
size_t zresult = ZSTD_CCtxParams_getParameter(params, param, value); \ |
| 88 |
if (ZSTD_isError(zresult)) { \ |
| 89 |
PyErr_Format(ZstdError, "unable to retrieve parameter: %s", \ |
| 90 |
ZSTD_getErrorName(zresult)); \ |
| 91 |
return 1; \ |
| 92 |
} \ |
| 93 |
} |
| 94 |
|
| 95 |
int to_cparams(ZstdCompressionParametersObject *params, |
| 96 |
ZSTD_compressionParameters *cparams) { |
| 97 |
int value; |
| 98 |
|
| 99 |
TRY_GET_PARAMETER(params->params, ZSTD_c_windowLog, &value); |
| 100 |
cparams->windowLog = value; |
| 101 |
|
| 102 |
TRY_GET_PARAMETER(params->params, ZSTD_c_chainLog, &value); |
| 103 |
cparams->chainLog = value; |
| 104 |
|
| 105 |
TRY_GET_PARAMETER(params->params, ZSTD_c_hashLog, &value); |
| 106 |
cparams->hashLog = value; |
| 107 |
|
| 108 |
TRY_GET_PARAMETER(params->params, ZSTD_c_searchLog, &value); |
| 109 |
cparams->searchLog = value; |
| 110 |
|
| 111 |
TRY_GET_PARAMETER(params->params, ZSTD_c_minMatch, &value); |
| 112 |
cparams->minMatch = value; |
| 113 |
|
| 114 |
TRY_GET_PARAMETER(params->params, ZSTD_c_targetLength, &value); |
| 115 |
cparams->targetLength = value; |
| 116 |
|
| 117 |
TRY_GET_PARAMETER(params->params, ZSTD_c_strategy, &value); |
| 118 |
cparams->strategy = value; |
| 119 |
|
| 120 |
return 0; |
| 121 |
} |
| 122 |
|
| 123 |
static int ZstdCompressionParameters_init(ZstdCompressionParametersObject *self, |
| 124 |
PyObject *args, PyObject *kwargs) { |
| 125 |
static char *kwlist[] = {"format", |
| 126 |
"compression_level", |
| 127 |
"window_log", |
| 128 |
"hash_log", |
| 129 |
"chain_log", |
| 130 |
"search_log", |
| 131 |
"min_match", |
| 132 |
"target_length", |
| 133 |
"strategy", |
| 134 |
"write_content_size", |
| 135 |
"write_checksum", |
| 136 |
"write_dict_id", |
| 137 |
"job_size", |
| 138 |
"overlap_log", |
| 139 |
"force_max_window", |
| 140 |
"enable_ldm", |
| 141 |
"ldm_hash_log", |
| 142 |
"ldm_min_match", |
| 143 |
"ldm_bucket_size_log", |
| 144 |
"ldm_hash_rate_log", |
| 145 |
"threads", |
| 146 |
NULL}; |
| 147 |
|
| 148 |
int format = 0; |
| 149 |
int compressionLevel = 0; |
| 150 |
int windowLog = 0; |
| 151 |
int hashLog = 0; |
| 152 |
int chainLog = 0; |
| 153 |
int searchLog = 0; |
| 154 |
int minMatch = 0; |
| 155 |
int targetLength = 0; |
| 156 |
int strategy = -1; |
| 157 |
int contentSizeFlag = 1; |
| 158 |
int checksumFlag = 0; |
| 159 |
int dictIDFlag = 0; |
| 160 |
int jobSize = 0; |
| 161 |
int overlapLog = -1; |
| 162 |
int forceMaxWindow = 0; |
| 163 |
int enableLDM = 0; |
| 164 |
int ldmHashLog = 0; |
| 165 |
int ldmMinMatch = 0; |
| 166 |
int ldmBucketSizeLog = 0; |
| 167 |
int ldmHashRateLog = -1; |
| 168 |
int threads = 0; |
| 169 |
|
| 170 |
if (!PyArg_ParseTupleAndKeywords( |
| 171 |
args, kwargs, "|iiiiiiiiiiiiiiiiiiiii:ZstdCompressionParameters", |
| 172 |
kwlist, &format, &compressionLevel, &windowLog, &hashLog, &chainLog, |
| 173 |
&searchLog, &minMatch, &targetLength, &strategy, &contentSizeFlag, |
| 174 |
&checksumFlag, &dictIDFlag, &jobSize, &overlapLog, &forceMaxWindow, |
| 175 |
&enableLDM, &ldmHashLog, &ldmMinMatch, &ldmBucketSizeLog, |
| 176 |
&ldmHashRateLog, &threads)) { |
| 177 |
return -1; |
| 178 |
} |
| 179 |
|
| 180 |
if (reset_params(self)) { |
| 181 |
return -1; |
| 182 |
} |
| 183 |
|
| 184 |
if (threads < 0) { |
| 185 |
threads = cpu_count(); |
| 186 |
} |
| 187 |
|
| 188 |
/* We need to set ZSTD_c_nbWorkers before ZSTD_c_jobSize and |
| 189 |
* ZSTD_c_overlapLog because setting ZSTD_c_nbWorkers resets the other |
| 190 |
* parameters. */ |
| 191 |
TRY_SET_PARAMETER(self->params, ZSTD_c_nbWorkers, threads); |
| 192 |
|
| 193 |
TRY_SET_PARAMETER(self->params, ZSTD_c_format, format); |
| 194 |
TRY_SET_PARAMETER(self->params, ZSTD_c_compressionLevel, compressionLevel); |
| 195 |
TRY_SET_PARAMETER(self->params, ZSTD_c_windowLog, windowLog); |
| 196 |
TRY_SET_PARAMETER(self->params, ZSTD_c_hashLog, hashLog); |
| 197 |
TRY_SET_PARAMETER(self->params, ZSTD_c_chainLog, chainLog); |
| 198 |
TRY_SET_PARAMETER(self->params, ZSTD_c_searchLog, searchLog); |
| 199 |
TRY_SET_PARAMETER(self->params, ZSTD_c_minMatch, minMatch); |
| 200 |
TRY_SET_PARAMETER(self->params, ZSTD_c_targetLength, targetLength); |
| 201 |
|
| 202 |
if (strategy == -1) { |
| 203 |
strategy = 0; |
| 204 |
} |
| 205 |
|
| 206 |
TRY_SET_PARAMETER(self->params, ZSTD_c_strategy, strategy); |
| 207 |
TRY_SET_PARAMETER(self->params, ZSTD_c_contentSizeFlag, contentSizeFlag); |
| 208 |
TRY_SET_PARAMETER(self->params, ZSTD_c_checksumFlag, checksumFlag); |
| 209 |
TRY_SET_PARAMETER(self->params, ZSTD_c_dictIDFlag, dictIDFlag); |
| 210 |
TRY_SET_PARAMETER(self->params, ZSTD_c_jobSize, jobSize); |
| 211 |
|
| 212 |
if (overlapLog == -1) { |
| 213 |
overlapLog = 0; |
| 214 |
} |
| 215 |
|
| 216 |
TRY_SET_PARAMETER(self->params, ZSTD_c_overlapLog, overlapLog); |
| 217 |
TRY_SET_PARAMETER(self->params, ZSTD_c_forceMaxWindow, forceMaxWindow); |
| 218 |
TRY_SET_PARAMETER(self->params, ZSTD_c_enableLongDistanceMatching, |
| 219 |
enableLDM); |
| 220 |
TRY_SET_PARAMETER(self->params, ZSTD_c_ldmHashLog, ldmHashLog); |
| 221 |
TRY_SET_PARAMETER(self->params, ZSTD_c_ldmMinMatch, ldmMinMatch); |
| 222 |
TRY_SET_PARAMETER(self->params, ZSTD_c_ldmBucketSizeLog, ldmBucketSizeLog); |
| 223 |
|
| 224 |
if (ldmHashRateLog == -1) { |
| 225 |
ldmHashRateLog = 0; |
| 226 |
} |
| 227 |
|
| 228 |
TRY_SET_PARAMETER(self->params, ZSTD_c_ldmHashRateLog, ldmHashRateLog); |
| 229 |
|
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
ZstdCompressionParametersObject * |
| 234 |
CompressionParameters_from_level(PyObject *undef, PyObject *args, |
| 235 |
PyObject *kwargs) { |
| 236 |
int managedKwargs = 0; |
| 237 |
int level; |
| 238 |
PyObject *sourceSize = NULL; |
| 239 |
PyObject *dictSize = NULL; |
| 240 |
unsigned PY_LONG_LONG iSourceSize = 0; |
| 241 |
Py_ssize_t iDictSize = 0; |
| 242 |
PyObject *val; |
| 243 |
ZSTD_compressionParameters params; |
| 244 |
ZstdCompressionParametersObject *result = NULL; |
| 245 |
int res; |
| 246 |
|
| 247 |
if (!PyArg_ParseTuple(args, "i:from_level", &level)) { |
| 248 |
return NULL; |
| 249 |
} |
| 250 |
|
| 251 |
if (!kwargs) { |
| 252 |
kwargs = PyDict_New(); |
| 253 |
if (!kwargs) { |
| 254 |
return NULL; |
| 255 |
} |
| 256 |
managedKwargs = 1; |
| 257 |
} |
| 258 |
|
| 259 |
sourceSize = PyDict_GetItemString(kwargs, "source_size"); |
| 260 |
if (sourceSize) { |
| 261 |
iSourceSize = PyLong_AsUnsignedLongLong(sourceSize); |
| 262 |
if (iSourceSize == (unsigned PY_LONG_LONG)(-1)) { |
| 263 |
goto cleanup; |
| 264 |
} |
| 265 |
|
| 266 |
PyDict_DelItemString(kwargs, "source_size"); |
| 267 |
} |
| 268 |
|
| 269 |
dictSize = PyDict_GetItemString(kwargs, "dict_size"); |
| 270 |
if (dictSize) { |
| 271 |
iDictSize = PyLong_AsSsize_t(dictSize); |
| 272 |
if (iDictSize == -1) { |
| 273 |
goto cleanup; |
| 274 |
} |
| 275 |
|
| 276 |
PyDict_DelItemString(kwargs, "dict_size"); |
| 277 |
} |
| 278 |
|
| 279 |
params = ZSTD_getCParams(level, iSourceSize, iDictSize); |
| 280 |
|
| 281 |
/* Values derived from the input level and sizes are passed along to the |
| 282 |
constructor. But only if a value doesn't already exist. */ |
| 283 |
val = PyDict_GetItemString(kwargs, "window_log"); |
| 284 |
if (!val) { |
| 285 |
val = PyLong_FromUnsignedLong(params.windowLog); |
| 286 |
if (!val) { |
| 287 |
goto cleanup; |
| 288 |
} |
| 289 |
PyDict_SetItemString(kwargs, "window_log", val); |
| 290 |
Py_DECREF(val); |
| 291 |
} |
| 292 |
|
| 293 |
val = PyDict_GetItemString(kwargs, "chain_log"); |
| 294 |
if (!val) { |
| 295 |
val = PyLong_FromUnsignedLong(params.chainLog); |
| 296 |
if (!val) { |
| 297 |
goto cleanup; |
| 298 |
} |
| 299 |
PyDict_SetItemString(kwargs, "chain_log", val); |
| 300 |
Py_DECREF(val); |
| 301 |
} |
| 302 |
|
| 303 |
val = PyDict_GetItemString(kwargs, "hash_log"); |
| 304 |
if (!val) { |
| 305 |
val = PyLong_FromUnsignedLong(params.hashLog); |
| 306 |
if (!val) { |
| 307 |
goto cleanup; |
| 308 |
} |
| 309 |
PyDict_SetItemString(kwargs, "hash_log", val); |
| 310 |
Py_DECREF(val); |
| 311 |
} |
| 312 |
|
| 313 |
val = PyDict_GetItemString(kwargs, "search_log"); |
| 314 |
if (!val) { |
| 315 |
val = PyLong_FromUnsignedLong(params.searchLog); |
| 316 |
if (!val) { |
| 317 |
goto cleanup; |
| 318 |
} |
| 319 |
PyDict_SetItemString(kwargs, "search_log", val); |
| 320 |
Py_DECREF(val); |
| 321 |
} |
| 322 |
|
| 323 |
val = PyDict_GetItemString(kwargs, "min_match"); |
| 324 |
if (!val) { |
| 325 |
val = PyLong_FromUnsignedLong(params.minMatch); |
| 326 |
if (!val) { |
| 327 |
goto cleanup; |
| 328 |
} |
| 329 |
PyDict_SetItemString(kwargs, "min_match", val); |
| 330 |
Py_DECREF(val); |
| 331 |
} |
| 332 |
|
| 333 |
val = PyDict_GetItemString(kwargs, "target_length"); |
| 334 |
if (!val) { |
| 335 |
val = PyLong_FromUnsignedLong(params.targetLength); |
| 336 |
if (!val) { |
| 337 |
goto cleanup; |
| 338 |
} |
| 339 |
PyDict_SetItemString(kwargs, "target_length", val); |
| 340 |
Py_DECREF(val); |
| 341 |
} |
| 342 |
|
| 343 |
val = PyDict_GetItemString(kwargs, "strategy"); |
| 344 |
if (!val) { |
| 345 |
val = PyLong_FromUnsignedLong(params.strategy); |
| 346 |
if (!val) { |
| 347 |
goto cleanup; |
| 348 |
} |
| 349 |
PyDict_SetItemString(kwargs, "strategy", val); |
| 350 |
Py_DECREF(val); |
| 351 |
} |
| 352 |
|
| 353 |
result = PyObject_New(ZstdCompressionParametersObject, |
| 354 |
ZstdCompressionParametersType); |
| 355 |
if (!result) { |
| 356 |
goto cleanup; |
| 357 |
} |
| 358 |
|
| 359 |
result->params = NULL; |
| 360 |
|
| 361 |
val = PyTuple_New(0); |
| 362 |
if (!val) { |
| 363 |
Py_CLEAR(result); |
| 364 |
goto cleanup; |
| 365 |
} |
| 366 |
|
| 367 |
res = ZstdCompressionParameters_init(result, val, kwargs); |
| 368 |
Py_DECREF(val); |
| 369 |
|
| 370 |
if (res) { |
| 371 |
Py_CLEAR(result); |
| 372 |
goto cleanup; |
| 373 |
} |
| 374 |
|
| 375 |
cleanup: |
| 376 |
if (managedKwargs) { |
| 377 |
Py_DECREF(kwargs); |
| 378 |
} |
| 379 |
|
| 380 |
return result; |
| 381 |
} |
| 382 |
|
| 383 |
PyObject *ZstdCompressionParameters_estimated_compression_context_size( |
| 384 |
ZstdCompressionParametersObject *self) { |
| 385 |
return PyLong_FromSize_t( |
| 386 |
ZSTD_estimateCCtxSize_usingCCtxParams(self->params)); |
| 387 |
} |
| 388 |
|
| 389 |
static void |
| 390 |
ZstdCompressionParameters_dealloc(ZstdCompressionParametersObject *self) { |
| 391 |
if (self->params) { |
| 392 |
ZSTD_freeCCtxParams(self->params); |
| 393 |
self->params = NULL; |
| 394 |
} |
| 395 |
|
| 396 |
PyObject_Del(self); |
| 397 |
} |
| 398 |
|
| 399 |
#define PARAM_GETTER(name, param) \ |
| 400 |
PyObject *ZstdCompressionParameters_get_##name(PyObject *self, \ |
| 401 |
void *unused) { \ |
| 402 |
int result; \ |
| 403 |
size_t zresult; \ |
| 404 |
ZstdCompressionParametersObject *p = \ |
| 405 |
(ZstdCompressionParametersObject *)(self); \ |
| 406 |
zresult = ZSTD_CCtxParams_getParameter(p->params, param, &result); \ |
| 407 |
if (ZSTD_isError(zresult)) { \ |
| 408 |
PyErr_Format(ZstdError, "unable to get compression parameter: %s", \ |
| 409 |
ZSTD_getErrorName(zresult)); \ |
| 410 |
return NULL; \ |
| 411 |
} \ |
| 412 |
return PyLong_FromLong(result); \ |
| 413 |
} |
| 414 |
|
| 415 |
PARAM_GETTER(format, ZSTD_c_format) |
| 416 |
PARAM_GETTER(compression_level, ZSTD_c_compressionLevel) |
| 417 |
PARAM_GETTER(window_log, ZSTD_c_windowLog) |
| 418 |
PARAM_GETTER(hash_log, ZSTD_c_hashLog) |
| 419 |
PARAM_GETTER(chain_log, ZSTD_c_chainLog) |
| 420 |
PARAM_GETTER(search_log, ZSTD_c_searchLog) |
| 421 |
PARAM_GETTER(min_match, ZSTD_c_minMatch) |
| 422 |
PARAM_GETTER(target_length, ZSTD_c_targetLength) |
| 423 |
PARAM_GETTER(strategy, ZSTD_c_strategy) |
| 424 |
PARAM_GETTER(write_content_size, ZSTD_c_contentSizeFlag) |
| 425 |
PARAM_GETTER(write_checksum, ZSTD_c_checksumFlag) |
| 426 |
PARAM_GETTER(write_dict_id, ZSTD_c_dictIDFlag) |
| 427 |
PARAM_GETTER(job_size, ZSTD_c_jobSize) |
| 428 |
PARAM_GETTER(overlap_log, ZSTD_c_overlapLog) |
| 429 |
PARAM_GETTER(force_max_window, ZSTD_c_forceMaxWindow) |
| 430 |
PARAM_GETTER(enable_ldm, ZSTD_c_enableLongDistanceMatching) |
| 431 |
PARAM_GETTER(ldm_hash_log, ZSTD_c_ldmHashLog) |
| 432 |
PARAM_GETTER(ldm_min_match, ZSTD_c_ldmMinMatch) |
| 433 |
PARAM_GETTER(ldm_bucket_size_log, ZSTD_c_ldmBucketSizeLog) |
| 434 |
PARAM_GETTER(ldm_hash_rate_log, ZSTD_c_ldmHashRateLog) |
| 435 |
PARAM_GETTER(threads, ZSTD_c_nbWorkers) |
| 436 |
|
| 437 |
static PyMethodDef ZstdCompressionParameters_methods[] = { |
| 438 |
{"from_level", (PyCFunction)CompressionParameters_from_level, |
| 439 |
METH_VARARGS | METH_KEYWORDS | METH_STATIC, NULL}, |
| 440 |
{"estimated_compression_context_size", |
| 441 |
(PyCFunction)ZstdCompressionParameters_estimated_compression_context_size, |
| 442 |
METH_NOARGS, NULL}, |
| 443 |
{NULL, NULL}}; |
| 444 |
|
| 445 |
#define GET_SET_ENTRY(name) \ |
| 446 |
{ #name, ZstdCompressionParameters_get_##name, NULL, NULL, NULL } |
| 447 |
|
| 448 |
static PyGetSetDef ZstdCompressionParameters_getset[] = { |
| 449 |
GET_SET_ENTRY(format), |
| 450 |
GET_SET_ENTRY(compression_level), |
| 451 |
GET_SET_ENTRY(window_log), |
| 452 |
GET_SET_ENTRY(hash_log), |
| 453 |
GET_SET_ENTRY(chain_log), |
| 454 |
GET_SET_ENTRY(search_log), |
| 455 |
GET_SET_ENTRY(min_match), |
| 456 |
GET_SET_ENTRY(target_length), |
| 457 |
GET_SET_ENTRY(strategy), |
| 458 |
GET_SET_ENTRY(write_content_size), |
| 459 |
GET_SET_ENTRY(write_checksum), |
| 460 |
GET_SET_ENTRY(write_dict_id), |
| 461 |
GET_SET_ENTRY(threads), |
| 462 |
GET_SET_ENTRY(job_size), |
| 463 |
GET_SET_ENTRY(overlap_log), |
| 464 |
GET_SET_ENTRY(force_max_window), |
| 465 |
GET_SET_ENTRY(enable_ldm), |
| 466 |
GET_SET_ENTRY(ldm_hash_log), |
| 467 |
GET_SET_ENTRY(ldm_min_match), |
| 468 |
GET_SET_ENTRY(ldm_bucket_size_log), |
| 469 |
GET_SET_ENTRY(ldm_hash_rate_log), |
| 470 |
{NULL}}; |
| 471 |
|
| 472 |
PyType_Slot ZstdCompressionParametersSlots[] = { |
| 473 |
{Py_tp_dealloc, ZstdCompressionParameters_dealloc}, |
| 474 |
{Py_tp_methods, ZstdCompressionParameters_methods}, |
| 475 |
{Py_tp_getset, ZstdCompressionParameters_getset}, |
| 476 |
{Py_tp_init, ZstdCompressionParameters_init}, |
| 477 |
{Py_tp_new, PyType_GenericNew}, |
| 478 |
{0, NULL}, |
| 479 |
}; |
| 480 |
|
| 481 |
PyType_Spec ZstdCompressionParametersSpec = { |
| 482 |
"zstandard.backend_c.ZstdCompressionParameters", |
| 483 |
sizeof(ZstdCompressionParametersObject), |
| 484 |
0, |
| 485 |
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, |
| 486 |
ZstdCompressionParametersSlots, |
| 487 |
}; |
| 488 |
|
| 489 |
PyTypeObject *ZstdCompressionParametersType; |
| 490 |
|
| 491 |
void compressionparams_module_init(PyObject *mod) { |
| 492 |
ZstdCompressionParametersType = |
| 493 |
(PyTypeObject *)PyType_FromSpec(&ZstdCompressionParametersSpec); |
| 494 |
if (PyType_Ready(ZstdCompressionParametersType) < 0) { |
| 495 |
return; |
| 496 |
} |
| 497 |
|
| 498 |
Py_INCREF(ZstdCompressionParametersType); |
| 499 |
PyModule_AddObject(mod, "ZstdCompressionParameters", |
| 500 |
(PyObject *)ZstdCompressionParametersType); |
| 501 |
} |