Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,18 @@ def build_extension(self, ext):
if isinstance(self.compiler, MSVCCompiler) or getattr(self.compiler, 'compiler_type', '') == 'msvc':
# set flags only available when using MSVC
ext.extra_link_args.append('/MANIFEST')
# conversion from '__int64' to 'Py_ssize_t', possible loss of data
ext.extra_compile_args.append('/we4244')
# conversion from 'size_t' to 'int', possible loss of data
ext.extra_compile_args.append('/we4267')
if COMPILE_DEBUG:
ext.extra_compile_args.append('/Zi')
ext.extra_compile_args.append('/MTd')
ext.extra_link_args.append('/DEBUG')
else:
ext.extra_compile_args.append('/MT')
else:
ext.extra_compile_args.append('-Werror=sign-compare')

_build_ext.build_extension(self, ext)

Expand Down
8 changes: 4 additions & 4 deletions src/compat/LzmaCompatDecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int LZMACALL lzmaCompatDecode(lzma_stream *s)
{
UInt32 bound;
UInt32 pos;

/* restore decoder state */
lzma_stream _s = *s;

Expand Down Expand Up @@ -240,7 +240,7 @@ int LZMACALL lzmaCompatDecode(lzma_stream *s)
while (numProbs--)
p[numProbs] = kBitModelTotal >> 1;


//for (i = 0, newDictionarySize = 0; i < 4; i++)
for (i = 0, _s.temp3 = 0; i < 4; i++)
{
Expand Down Expand Up @@ -306,7 +306,7 @@ int LZMACALL lzmaCompatDecode(lzma_stream *s)
}
}
while (symbol < 0x100);
previousByte = symbol;
previousByte = (Byte)symbol;
}
isPreviousMatch = 0;
}
Expand All @@ -319,7 +319,7 @@ int LZMACALL lzmaCompatDecode(lzma_stream *s)
RC_GET_BIT(LZMA_C_LITD, prob, symbol)
}
while (symbol < 0x100);
previousByte = symbol;
previousByte = (Byte)symbol;
}
NEED_OUT(LZMA_C_OUTPUT_1);
PUT_BYTE(previousByte);
Expand Down
20 changes: 10 additions & 10 deletions src/pylzma/pylzma.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static PyObject *
pylzma_calculate_key(PyObject *self, PyObject *args, PyObject *kwargs)
{
char *password;
PARSE_LENGTH_TYPE pwlen;
Py_ssize_t pwlen;
int cycles;
PyObject *pysalt=NULL;
char *salt;
Expand Down Expand Up @@ -136,7 +136,7 @@ static PyObject *
pylzma_bcj_x86_convert(PyObject *self, PyObject *args)
{
char *data;
PARSE_LENGTH_TYPE length;
Py_ssize_t length;
int encoding=0;
PyObject *result;

Expand Down Expand Up @@ -169,7 +169,7 @@ static PyObject * \
pylzma_bcj_##id##_convert(PyObject *self, PyObject *args) \
{ \
char *data; \
PARSE_LENGTH_TYPE length; \
Py_ssize_t length; \
int encoding=0; \
PyObject *result; \
\
Expand Down Expand Up @@ -205,8 +205,8 @@ static PyObject *
pylzma_bcj2_decode(PyObject *self, PyObject *args)
{
char *main_data, *call_data, *jump_data, *rc_data;
PARSE_LENGTH_TYPE main_length, call_length, jump_length, rc_length;
PARSE_LENGTH_TYPE dest_len = -1;
Py_ssize_t main_length, call_length, jump_length, rc_length;
Py_ssize_t dest_len = -1;
CBcj2Dec dec;
SRes res;
PyObject *result;
Expand Down Expand Up @@ -280,7 +280,7 @@ static PyObject *
pylzma_delta_decode(PyObject *self, PyObject *args)
{
char *data;
PARSE_LENGTH_TYPE length;
Py_ssize_t length;
unsigned int delta;
Byte state[DELTA_STATE_SIZE];
Byte *tmp;
Expand Down Expand Up @@ -320,7 +320,7 @@ static PyObject *
pylzma_delta_encode(PyObject *self, PyObject *args)
{
char *data;
PARSE_LENGTH_TYPE length;
Py_ssize_t length;
unsigned int delta;
Byte state[DELTA_STATE_SIZE];
Byte *tmp;
Expand Down Expand Up @@ -395,9 +395,9 @@ static PyObject *
pylzma_ppmd_decompress(PyObject *self, PyObject *args)
{
char *data;
PARSE_LENGTH_TYPE length;
Py_ssize_t length;
char *props;
PARSE_LENGTH_TYPE propssize;
Py_ssize_t propssize;
unsigned int outsize;
PyObject *result;
Byte *tmp;
Expand Down Expand Up @@ -469,7 +469,7 @@ pylzma_ppmd_decompress(PyObject *self, PyObject *args)
}
if (i != outsize) {
res = (s.res != SZ_OK ? s.res : SZ_ERROR_DATA);
} else if (s.processed + (s.cur - s.begin) != length || !Ppmd7z_RangeDec_IsFinishedOK(&rc)) {
} else if (s.processed + (s.cur - s.begin) != (UInt64)length || !Ppmd7z_RangeDec_IsFinishedOK(&rc)) {
res = SZ_ERROR_DATA;
}
}
Expand Down
14 changes: 3 additions & 11 deletions src/pylzma/pylzma.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* $Id$
*
*/
Expand Down Expand Up @@ -96,14 +96,6 @@ PyInterpreterState* _pylzma_interpreterState;
0,
#endif

#if defined(PY_SSIZE_T_CLEAN) && (PY_VERSION_HEX >= 0x02040000)
#define PARSE_LENGTH_TYPE Py_ssize_t
#define PARSE_LENGTH_FORMAT "%zd"
#else
#define PARSE_LENGTH_TYPE int
#define PARSE_LENGTH_FORMAT "%d"
#endif

// Handle tp_print -> tp_vectorcall_offset change in Python 3.8+
#if PY_VERSION_HEX >= 0x03080000
#define PYLZMA_TP_PRINT 0
Expand Down
34 changes: 17 additions & 17 deletions src/pylzma/pylzma_aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* $Id$
*
*/
Expand All @@ -43,16 +43,16 @@ int
aesdecrypt_init(CAESDecryptObject *self, PyObject *args, PyObject *kwargs)
{
char *key=NULL;
PARSE_LENGTH_TYPE keylength=0;
Py_ssize_t keylength=0;
char *iv=NULL;
PARSE_LENGTH_TYPE ivlength=0;
Py_ssize_t ivlength=0;
int offset;

// possible keywords for this function
static char *kwlist[] = {"key", "iv", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s#s#", kwlist, &key, &keylength, &iv, &ivlength))
return -1;

memset(&self->aesBuf, 0, sizeof(self->aesBuf));
self->aes = (UInt32 *) self->aesBuf;
// AES code expects aligned memory
Expand All @@ -64,15 +64,15 @@ aesdecrypt_init(CAESDecryptObject *self, PyObject *args, PyObject *kwargs)

if (keylength > 0) {
if (keylength != 16 && keylength != 24 && keylength != 32) {
PyErr_Format(PyExc_TypeError, "key must be 16, 24 or 32 bytes, got " PARSE_LENGTH_FORMAT, keylength);
PyErr_Format(PyExc_TypeError, "key must be 16, 24 or 32 bytes, got %zd", keylength);
return -1;
}

Aes_SetKey_Dec(self->aes + 4, (Byte *) key, keylength);
Aes_SetKey_Dec(self->aes + 4, (Byte *) key, (unsigned)keylength);
}
if (ivlength > 0) {
if (ivlength != AES_BLOCK_SIZE) {
PyErr_Format(PyExc_TypeError, "iv must be %d bytes, got " PARSE_LENGTH_FORMAT, AES_BLOCK_SIZE, ivlength);
PyErr_Format(PyExc_TypeError, "iv must be %d bytes, got %zd", AES_BLOCK_SIZE, ivlength);
return -1;
}

Expand All @@ -81,28 +81,28 @@ aesdecrypt_init(CAESDecryptObject *self, PyObject *args, PyObject *kwargs)
return 0;
}

static char
static char
doc_aesdecrypt_decrypt[] = \
"decrypt(data) -- Decrypt given data.";

static PyObject *
aesdecrypt_decrypt(CAESDecryptObject *self, PyObject *args)
{
char *data;
PARSE_LENGTH_TYPE length;
Py_ssize_t length;
PyObject *result;
char *out;
PARSE_LENGTH_TYPE outlength;
Py_ssize_t outlength;
char *tmpdata = NULL;

if (!PyArg_ParseTuple(args, "s#", &data, &length))
return NULL;

if (length % AES_BLOCK_SIZE) {
PyErr_Format(PyExc_TypeError, "data must be a multiple of %d bytes, got " PARSE_LENGTH_FORMAT, AES_BLOCK_SIZE, length);
PyErr_Format(PyExc_TypeError, "data must be a multiple of %d bytes, got %zd", AES_BLOCK_SIZE, length);
return NULL;
}

result = PyBytes_FromStringAndSize(NULL, length);
if (result == NULL) {
return NULL;
Expand Down
28 changes: 14 additions & 14 deletions src/pylzma/pylzma_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* $Id$
*
*/
Expand All @@ -44,7 +44,7 @@ pylzma_compress(PyObject *self, PyObject *args, PyObject *kwargs)
CMemoryInStream inStream;
Byte header[LZMA_PROPS_SIZE];
size_t headerSize = LZMA_PROPS_SIZE;
int res;
int res;
// possible keywords for this function
static char *kwlist[] = {"data", "dictionary", "fastBytes", "literalContextBits",
"literalPosBits", "posBits", "algorithm", "eos", "multithreading", "matchfinder", NULL};
Expand All @@ -58,37 +58,37 @@ pylzma_compress(PyObject *self, PyObject *args, PyObject *kwargs)
char *matchfinder = NULL; // matchfinder algorithm
int algorithm = 2;
char *data;
PARSE_LENGTH_TYPE length;
Py_ssize_t length;

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|iiiiiiiis", kwlist, &data, &length, &dictionary, &fastBytes,
&literalContextBits, &literalPosBits, &posBits, &algorithm, &eos, &multithreading, &matchfinder))
return NULL;

outStream.data = NULL;
CHECK_RANGE(dictionary, 0, 27, "dictionary must be between 0 and 27");
CHECK_RANGE(fastBytes, 5, 273, "fastBytes must be between 5 and 273");
CHECK_RANGE(literalContextBits, 0, 8, "literalContextBits must be between 0 and 8");
CHECK_RANGE(literalPosBits, 0, 4, "literalPosBits must be between 0 and 4");
CHECK_RANGE(posBits, 0, 4, "posBits must be between 0 and 4");
CHECK_RANGE(algorithm, 0, 2, "algorithm must be between 0 and 2");

if (matchfinder != NULL) {
#if (PY_VERSION_HEX >= 0x02050000)
PyErr_WarnEx(PyExc_DeprecationWarning, "matchfinder selection is deprecated and will be ignored", 1);
#else
PyErr_Warn(PyExc_DeprecationWarning, "matchfinder selection is deprecated and will be ignored");
#endif
}

encoder = LzmaEnc_Create(&allocator);
if (encoder == NULL)
return PyErr_NoMemory();

CreateMemoryInStream(&inStream, (Byte *) data, length);
CreateMemoryOutStream(&outStream);

LzmaEncProps_Init(&props);

props.dictSize = 1 << dictionary;
props.lc = literalContextBits;
props.lp = literalPosBits;
Expand Down Expand Up @@ -119,16 +119,16 @@ pylzma_compress(PyObject *self, PyObject *args, PyObject *kwargs)
PyErr_Format(PyExc_TypeError, "Error during compressing: %d", res);
goto exit;
}

result = PyBytes_FromStringAndSize((const char *) outStream.data, outStream.size);

exit:
if (encoder != NULL) {
LzmaEnc_Destroy(encoder, &allocator, &allocator);
}
if (outStream.data != NULL) {
free(outStream.data);
}

return result;
}
Loading