@@ -130,7 +130,7 @@ pylzma_calculate_key(PyObject *self, PyObject *args, PyObject *kwargs)
130130
131131const char
132132doc_bcj_x86_convert [] = \
133- "bcj_x86_convert(data) -- Perform BCJ x86 conversion." ;
133+ "bcj_x86_convert(data, [encoding] ) -- Perform BCJ x86 conversion." ;
134134
135135static PyObject *
136136pylzma_bcj_x86_convert (PyObject * self , PyObject * args )
@@ -150,10 +150,13 @@ pylzma_bcj_x86_convert(PyObject *self, PyObject *args)
150150
151151 result = PyBytes_FromStringAndSize (data , length );
152152 if (result != NULL ) {
153- UInt32 state ;
153+ UInt32 state = Z7_BRANCH_CONV_ST_X86_STATE_INIT_VAL ;
154154 Py_BEGIN_ALLOW_THREADS
155- x86_Convert_Init (state );
156- x86_Convert ((Byte * ) PyBytes_AS_STRING (result ), length , 0 , & state , encoding );
155+ if (encoding ) {
156+ Z7_BRANCH_CONV_ST_ENC (X86 )((Byte * ) PyBytes_AS_STRING (result ), length , 0 , & state );
157+ } else {
158+ Z7_BRANCH_CONV_ST_DEC (X86 )((Byte * ) PyBytes_AS_STRING (result ), length , 0 , & state );
159+ }
157160 Py_END_ALLOW_THREADS
158161 }
159162
@@ -163,7 +166,7 @@ pylzma_bcj_x86_convert(PyObject *self, PyObject *args)
163166#define DEFINE_BCJ_CONVERTER (id , name ) \
164167const char \
165168doc_bcj_##id##_convert[] = \
166- "bcj_" #id "_convert(data) -- Perform BCJ " #name " conversion."; \
169+ "bcj_" #id "_convert(data, [encoding] ) -- Perform BCJ " #name " conversion."; \
167170\
168171static PyObject * \
169172pylzma_bcj_##id##_convert(PyObject *self, PyObject *args) \
@@ -184,7 +187,11 @@ pylzma_bcj_##id##_convert(PyObject *self, PyObject *args) \
184187 result = PyBytes_FromStringAndSize(data, length); \
185188 if (result != NULL) { \
186189 Py_BEGIN_ALLOW_THREADS \
187- name##_Convert((Byte *) PyBytes_AS_STRING(result), length, 0, encoding); \
190+ if (encoding) { \
191+ Z7_BRANCH_CONV_ENC(name)((Byte *) PyBytes_AS_STRING(result), length, 0); \
192+ } else { \
193+ Z7_BRANCH_CONV_DEC(name)((Byte *) PyBytes_AS_STRING(result), length, 0); \
194+ } \
188195 Py_END_ALLOW_THREADS \
189196 } \
190197 \
@@ -259,7 +266,7 @@ pylzma_bcj2_decode(PyObject *self, PyObject *args)
259266 }
260267
261268 // Conversion must be finished and the output buffer filled completely.
262- if (!Bcj2Dec_IsFinished (& dec )) {
269+ if (!Bcj2Dec_IsMaybeFinished (& dec )) {
263270 goto error ;
264271 } else if (dec .dest != dec .destLim || dec .state != BCJ2_STREAM_MAIN ) {
265272 goto error ;
@@ -370,7 +377,7 @@ typedef struct
370377
371378static Byte
372379ReadByte (const IByteIn * pp ) {
373- CByteInToLook * p = CONTAINER_FROM_VTBL (pp , CByteInToLook , vt );
380+ CByteInToLook * p = Z7_CONTAINER_FROM_VTBL (pp , CByteInToLook , vt );
374381 if (p -> cur != p -> end ) {
375382 return * p -> cur ++ ;
376383 }
@@ -404,7 +411,6 @@ pylzma_ppmd_decompress(PyObject *self, PyObject *args)
404411 unsigned order ;
405412 UInt32 memSize ;
406413 CPpmd7 ppmd ;
407- CPpmd7z_RangeDec rc ;
408414 CByteInToLook s ;
409415 SRes res = SZ_OK ;
410416 CMemoryLookInStream stream ;
@@ -446,30 +452,29 @@ pylzma_ppmd_decompress(PyObject *self, PyObject *args)
446452 CreateMemoryLookInStream (& stream , (Byte * ) data , length );
447453 tmp = (Byte * ) PyBytes_AS_STRING (result );
448454 Py_BEGIN_ALLOW_THREADS
449- Ppmd7z_RangeDec_CreateVTable (& rc );
450455 s .vt .Read = ReadByte ;
451456 s .inStream = & stream .s ;
452457 s .begin = s .end = s .cur = NULL ;
453458 s .extra = False ;
454459 s .res = SZ_OK ;
455460 s .processed = 0 ;
456- rc .Stream = & s .vt ;
457- if (!Ppmd7z_RangeDec_Init (& rc )) {
461+ ppmd . rc . dec .Stream = & s .vt ;
462+ if (!Ppmd7z_RangeDec_Init (& ppmd . rc . dec )) {
458463 res = SZ_ERROR_DATA ;
459464 } else if (s .extra ) {
460465 res = (s .res != SZ_OK ? s .res : SZ_ERROR_DATA );
461466 } else {
462467 SizeT i ;
463468 for (i = 0 ; i < outsize ; i ++ ) {
464- int sym = Ppmd7_DecodeSymbol (& ppmd , & rc . vt );
469+ int sym = Ppmd7z_DecodeSymbol (& ppmd );
465470 if (s .extra || sym < 0 ) {
466471 break ;
467472 }
468473 tmp [i ] = (Byte )sym ;
469474 }
470475 if (i != outsize ) {
471476 res = (s .res != SZ_OK ? s .res : SZ_ERROR_DATA );
472- } else if (s .processed + (s .cur - s .begin ) != (UInt64 )length || !Ppmd7z_RangeDec_IsFinishedOK (& rc )) {
477+ } else if (s .processed + (s .cur - s .begin ) != (UInt64 )length || !Ppmd7z_RangeDec_IsFinishedOK (& ppmd . rc . dec )) {
473478 res = SZ_ERROR_DATA ;
474479 }
475480 }
0 commit comments