99 * modify it under the terms of the GNU Lesser General Public
1010 * License as published by the Free Software Foundation; either
1111 * version 2.1 of the License, or (at your option) any later version.
12- *
12+ *
1313 * This library is distributed in the hope that it will be useful,
1414 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1515 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1616 * Lesser General Public License for more details.
17- *
17+ *
1818 * You should have received a copy of the GNU Lesser General Public
1919 * License along with this library; if not, write to the Free Software
2020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21- *
21+ *
2222 * $Id$
2323 *
2424 */
3131static int
3232pylzma_decomp_init (CDecompressionObject * self , PyObject * args , PyObject * kwargs )
3333{
34- PY_LONG_LONG max_length = -1 ;
34+ Py_ssize_t max_length = -1 ;
3535 int lzma2 = 0 ;
36-
36+
3737 // possible keywords for this function
3838 static char * kwlist [] = {"maxlength" , "lzma2" , NULL };
39-
40- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|Li " , kwlist , & max_length , & lzma2 ))
39+
40+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|ni " , kwlist , & max_length , & lzma2 ))
4141 return -1 ;
42-
42+
4343 if (max_length == 0 || max_length < -1 ) {
4444 PyErr_SetString (PyExc_ValueError , "the decompressed size must be greater than zero" );
4545 return -1 ;
4646 }
47-
47+
4848 self -> unconsumed_tail = NULL ;
4949 self -> unconsumed_length = 0 ;
5050 self -> need_properties = 1 ;
@@ -72,30 +72,30 @@ pylzma_decomp_decompress(CDecompressionObject *self, PyObject *args)
7272 Byte * next_in , * next_out ;
7373 PARSE_LENGTH_TYPE length ;
7474 int res ;
75- PY_LONG_LONG bufsize = BLOCK_SIZE ;
75+ Py_ssize_t bufsize = BLOCK_SIZE ;
7676 SizeT avail_in ;
7777 SizeT inProcessed , outProcessed ;
7878 ELzmaStatus status ;
79-
80- if (!PyArg_ParseTuple (args , "s#|L " , & data , & length , & bufsize )){
79+
80+ if (!PyArg_ParseTuple (args , "s#|n " , & data , & length , & bufsize )){
8181 return NULL ;
8282 }
8383
8484 if (bufsize <= 0 ) {
8585 PyErr_SetString (PyExc_ValueError , "bufsize must be greater than zero" );
8686 return NULL ;
8787 }
88-
88+
8989 if (self -> unconsumed_length > 0 ) {
9090 self -> unconsumed_tail = (unsigned char * ) realloc (self -> unconsumed_tail , self -> unconsumed_length + length );
9191 next_in = (unsigned char * ) self -> unconsumed_tail ;
9292 memcpy (next_in + self -> unconsumed_length , data , length );
9393 } else {
9494 next_in = data ;
9595 }
96-
96+
9797 if (self -> need_properties ) {
98- int propertiesLength = self -> lzma2 ? 1 : LZMA_PROPS_SIZE ;
98+ SizeT propertiesLength = self -> lzma2 ? 1 : LZMA_PROPS_SIZE ;
9999 if ((self -> unconsumed_length + length ) < propertiesLength ) {
100100 // we need enough bytes to read the properties
101101 self -> unconsumed_tail = (unsigned char * ) realloc (self -> unconsumed_tail , self -> unconsumed_length + length );
@@ -118,7 +118,7 @@ pylzma_decomp_decompress(CDecompressionObject *self, PyObject *args)
118118 PyErr_SetString (PyExc_TypeError , "Incorrect stream properties" );
119119 return NULL ;
120120 }
121-
121+
122122 next_in += propertiesLength ;
123123 self -> unconsumed_length -= propertiesLength ;
124124 if (self -> unconsumed_length > 0 ) {
@@ -143,7 +143,7 @@ pylzma_decomp_decompress(CDecompressionObject *self, PyObject *args)
143143 } else {
144144 FREE_AND_NULL (self -> unconsumed_tail );
145145 }
146-
146+
147147 self -> need_properties = 0 ;
148148 if (self -> lzma2 ) {
149149 Lzma2Dec_Init (& self -> state .lzma2 );
@@ -158,13 +158,13 @@ pylzma_decomp_decompress(CDecompressionObject *self, PyObject *args)
158158 // no more bytes to decompress
159159 return PyBytes_FromString ("" );
160160 }
161-
161+
162162 result = PyBytes_FromStringAndSize (NULL , bufsize );
163163 if (result == NULL ) {
164164 PyErr_NoMemory ();
165165 goto exit ;
166166 }
167-
167+
168168 next_out = (unsigned char * ) PyBytes_AS_STRING (result );
169169 Py_BEGIN_ALLOW_THREADS
170170 // Decompress until EOS marker is reached
@@ -181,7 +181,7 @@ pylzma_decomp_decompress(CDecompressionObject *self, PyObject *args)
181181 self -> total_out += outProcessed ;
182182 next_in += inProcessed ;
183183 avail_in -= inProcessed ;
184-
184+
185185 if (res != SZ_OK ) {
186186 DEC_AND_NULL (result );
187187 PyErr_SetString (PyExc_ValueError , "data error during decompression" );
@@ -207,10 +207,10 @@ pylzma_decomp_decompress(CDecompressionObject *self, PyObject *args)
207207 } else {
208208 FREE_AND_NULL (self -> unconsumed_tail );
209209 }
210-
210+
211211 self -> unconsumed_length = avail_in ;
212212 _PyBytes_Resize (& result , outProcessed );
213-
213+
214214exit :
215215 return result ;
216216}
@@ -224,27 +224,27 @@ pylzma_decomp_flush(CDecompressionObject *self, PyObject *args)
224224{
225225 PyObject * result = NULL ;
226226 int res ;
227- SizeT avail_out , outsize ;
227+ Py_ssize_t avail_out , outsize ;
228228 unsigned char * tmp ;
229229 SizeT inProcessed , outProcessed ;
230230 ELzmaStatus status ;
231-
231+
232232 if (self -> max_length != -1 ) {
233233 avail_out = self -> max_length - self -> total_out ;
234234 } else {
235235 avail_out = BLOCK_SIZE ;
236236 }
237-
237+
238238 if (avail_out == 0 ) {
239239 // no more remaining data
240240 return PyBytes_FromString ("" );
241241 }
242-
242+
243243 result = PyBytes_FromStringAndSize (NULL , avail_out );
244244 if (result == NULL ) {
245245 return NULL ;
246246 }
247-
247+
248248 tmp = (unsigned char * ) PyBytes_AS_STRING (result );
249249 outsize = 0 ;
250250 while (1 ) {
@@ -278,46 +278,46 @@ pylzma_decomp_flush(CDecompressionObject *self, PyObject *args)
278278 FREE_AND_NULL (self -> unconsumed_tail );
279279 }
280280 Py_END_ALLOW_THREADS
281-
281+
282282 if (res != SZ_OK ) {
283283 PyErr_SetString (PyExc_ValueError , "data error during decompression" );
284284 DEC_AND_NULL (result );
285285 goto exit ;
286286 }
287-
287+
288288 if (!outProcessed && self -> max_length != -1 && self -> total_out < self -> max_length ) {
289289 PyErr_SetString (PyExc_ValueError , "data error during decompression" );
290290 DEC_AND_NULL (result );
291291 goto exit ;
292292 }
293-
293+
294294 self -> total_out += outProcessed ;
295295 outsize += outProcessed ;
296- if (outProcessed < avail_out || (outProcessed == avail_out && self -> max_length != -1 )) {
296+ if (outProcessed < ( SizeT ) avail_out || (outProcessed == ( SizeT ) avail_out && self -> max_length != -1 )) {
297297 break ;
298298 }
299-
299+
300300 if (self -> max_length != -1 ) {
301301 PyErr_SetString (PyExc_ValueError , "not enough input data for decompression" );
302302 DEC_AND_NULL (result );
303303 goto exit ;
304304 }
305-
305+
306306 avail_out -= outProcessed ;
307-
307+
308308 // Output buffer is full, might be more data for decompression
309309 if (_PyBytes_Resize (& result , outsize + BLOCK_SIZE ) != 0 ) {
310310 goto exit ;
311311 }
312-
312+
313313 avail_out += BLOCK_SIZE ;
314314 tmp = (unsigned char * ) PyBytes_AS_STRING (result ) + outsize ;
315315 }
316-
316+
317317 if (outsize != PyBytes_GET_SIZE (result )) {
318318 _PyBytes_Resize (& result , outsize );
319319 }
320-
320+
321321exit :
322322 return result ;
323323}
@@ -329,14 +329,14 @@ doc_decomp_reset[] = \
329329static PyObject *
330330pylzma_decomp_reset (CDecompressionObject * self , PyObject * args , PyObject * kwargs )
331331{
332- PY_LONG_LONG max_length = -1 ;
333-
332+ Py_ssize_t max_length = -1 ;
333+
334334 // possible keywords for this function
335335 static char * kwlist [] = {"maxlength" , NULL };
336-
337- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|L " , kwlist , & max_length ))
336+
337+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|n " , kwlist , & max_length ))
338338 return NULL ;
339-
339+
340340 if (self -> lzma2 ) {
341341 Lzma2Dec_Free (& self -> state .lzma2 , & allocator );
342342 Lzma2Dec_Construct (& self -> state .lzma2 );
@@ -349,7 +349,7 @@ pylzma_decomp_reset(CDecompressionObject *self, PyObject *args, PyObject *kwargs
349349 self -> need_properties = 1 ;
350350 self -> total_out = 0 ;
351351 self -> max_length = max_length ;
352-
352+
353353 Py_INCREF (Py_None );
354354 return Py_None ;
355355}
0 commit comments