contrib/python-zstandard/c-ext/compressor.c
changeset 30895 c32454d69b85
parent 30830 08fa3a76a080
child 31796 e0dc40530c5a
equal deleted inserted replaced
30894:5b60464efbde 30895:c32454d69b85
    14 	ZSTD_customMem zmem;
    14 	ZSTD_customMem zmem;
    15 	assert(!compressor->cdict);
    15 	assert(!compressor->cdict);
    16 	Py_BEGIN_ALLOW_THREADS
    16 	Py_BEGIN_ALLOW_THREADS
    17 	memset(&zmem, 0, sizeof(zmem));
    17 	memset(&zmem, 0, sizeof(zmem));
    18 	compressor->cdict = ZSTD_createCDict_advanced(compressor->dict->dictData,
    18 	compressor->cdict = ZSTD_createCDict_advanced(compressor->dict->dictData,
    19 		compressor->dict->dictSize, *zparams, zmem);
    19 		compressor->dict->dictSize, 1, *zparams, zmem);
    20 	Py_END_ALLOW_THREADS
    20 	Py_END_ALLOW_THREADS
    21 
    21 
    22 	if (!compressor->cdict) {
    22 	if (!compressor->cdict) {
    23 		PyErr_SetString(ZstdError, "could not create compression dictionary");
    23 		PyErr_SetString(ZstdError, "could not create compression dictionary");
    24 		return 1;
    24 		return 1;
   126 	self->cctx = NULL;
   126 	self->cctx = NULL;
   127 	self->dict = NULL;
   127 	self->dict = NULL;
   128 	self->cparams = NULL;
   128 	self->cparams = NULL;
   129 	self->cdict = NULL;
   129 	self->cdict = NULL;
   130 
   130 
   131 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO!O!OOO", kwlist,
   131 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iO!O!OOO:ZstdCompressor",
   132 		&level, &ZstdCompressionDictType, &dict,
   132 		kwlist,	&level, &ZstdCompressionDictType, &dict,
   133 		&CompressionParametersType, &params,
   133 		&CompressionParametersType, &params,
   134 		&writeChecksum, &writeContentSize, &writeDictID)) {
   134 		&writeChecksum, &writeContentSize, &writeDictID)) {
   135 		return -1;
   135 		return -1;
   136 	}
   136 	}
   137 
   137 
   241 	size_t zresult;
   241 	size_t zresult;
   242 	PyObject* writeResult;
   242 	PyObject* writeResult;
   243 	PyObject* totalReadPy;
   243 	PyObject* totalReadPy;
   244 	PyObject* totalWritePy;
   244 	PyObject* totalWritePy;
   245 
   245 
   246 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|nkk", kwlist, &source, &dest, &sourceSize,
   246 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|nkk:copy_stream", kwlist,
   247 		&inSize, &outSize)) {
   247 		&source, &dest, &sourceSize, &inSize, &outSize)) {
   248 		return NULL;
   248 		return NULL;
   249 	}
   249 	}
   250 
   250 
   251 	if (!PyObject_HasAttrString(source, "read")) {
   251 	if (!PyObject_HasAttrString(source, "read")) {
   252 		PyErr_SetString(PyExc_ValueError, "first argument must have a read() method");
   252 		PyErr_SetString(PyExc_ValueError, "first argument must have a read() method");
   400 	size_t dictSize = 0;
   400 	size_t dictSize = 0;
   401 	size_t zresult;
   401 	size_t zresult;
   402 	ZSTD_parameters zparams;
   402 	ZSTD_parameters zparams;
   403 
   403 
   404 #if PY_MAJOR_VERSION >= 3
   404 #if PY_MAJOR_VERSION >= 3
   405 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|O",
   405 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y#|O:compress",
   406 #else
   406 #else
   407 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O",
   407 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O:compress",
   408 #endif
   408 #endif
   409 		kwlist, &source, &sourceSize, &allowEmpty)) {
   409 		kwlist, &source, &sourceSize, &allowEmpty)) {
   410 		return NULL;
   410 		return NULL;
   411 	}
   411 	}
   412 
   412 
   510 	ZstdCompressionObj* result = PyObject_New(ZstdCompressionObj, &ZstdCompressionObjType);
   510 	ZstdCompressionObj* result = PyObject_New(ZstdCompressionObj, &ZstdCompressionObjType);
   511 	if (!result) {
   511 	if (!result) {
   512 		return NULL;
   512 		return NULL;
   513 	}
   513 	}
   514 
   514 
   515 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|n", kwlist, &inSize)) {
   515 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|n:compressobj", kwlist, &inSize)) {
   516 		return NULL;
   516 		return NULL;
   517 	}
   517 	}
   518 
   518 
   519 	result->cstream = CStream_from_ZstdCompressor(self, inSize);
   519 	result->cstream = CStream_from_ZstdCompressor(self, inSize);
   520 	if (!result->cstream) {
   520 	if (!result->cstream) {
   572 	Py_ssize_t sourceSize = 0;
   572 	Py_ssize_t sourceSize = 0;
   573 	size_t inSize = ZSTD_CStreamInSize();
   573 	size_t inSize = ZSTD_CStreamInSize();
   574 	size_t outSize = ZSTD_CStreamOutSize();
   574 	size_t outSize = ZSTD_CStreamOutSize();
   575 	ZstdCompressorIterator* result;
   575 	ZstdCompressorIterator* result;
   576 
   576 
   577 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nkk", kwlist, &reader, &sourceSize,
   577 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nkk:read_from", kwlist,
   578 		&inSize, &outSize)) {
   578 		&reader, &sourceSize, &inSize, &outSize)) {
   579 		return NULL;
   579 		return NULL;
   580 	}
   580 	}
   581 
   581 
   582 	result = PyObject_New(ZstdCompressorIterator, &ZstdCompressorIteratorType);
   582 	result = PyObject_New(ZstdCompressorIterator, &ZstdCompressorIteratorType);
   583 	if (!result) {
   583 	if (!result) {
   691 	PyObject* writer;
   691 	PyObject* writer;
   692 	ZstdCompressionWriter* result;
   692 	ZstdCompressionWriter* result;
   693 	Py_ssize_t sourceSize = 0;
   693 	Py_ssize_t sourceSize = 0;
   694 	size_t outSize = ZSTD_CStreamOutSize();
   694 	size_t outSize = ZSTD_CStreamOutSize();
   695 
   695 
   696 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nk", kwlist, &writer, &sourceSize,
   696 	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nk:write_to", kwlist,
   697 		&outSize)) {
   697 		&writer, &sourceSize, &outSize)) {
   698 		return NULL;
   698 		return NULL;
   699 	}
   699 	}
   700 
   700 
   701 	if (!PyObject_HasAttrString(writer, "write")) {
   701 	if (!PyObject_HasAttrString(writer, "write")) {
   702 		PyErr_SetString(PyExc_ValueError, "must pass an object with a write() method");
   702 		PyErr_SetString(PyExc_ValueError, "must pass an object with a write() method");