compressionparams.c 17 KB

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