@@ -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 \
@@ -193,7 +200,9 @@ pylzma_bcj_##id##_convert(PyObject *self, PyObject *args) \
193200
194201DEFINE_BCJ_CONVERTER (arm , ARM );
195202DEFINE_BCJ_CONVERTER (armt , ARMT );
203+ DEFINE_BCJ_CONVERTER (arm64 , ARM64 );
196204DEFINE_BCJ_CONVERTER (ppc , PPC );
205+ DEFINE_BCJ_CONVERTER (riscv , RISCV );
197206DEFINE_BCJ_CONVERTER (sparc , SPARC );
198207DEFINE_BCJ_CONVERTER (ia64 , IA64 );
199208
@@ -259,7 +268,7 @@ pylzma_bcj2_decode(PyObject *self, PyObject *args)
259268 }
260269
261270 // Conversion must be finished and the output buffer filled completely.
262- if (!Bcj2Dec_IsFinished (& dec )) {
271+ if (!Bcj2Dec_IsMaybeFinished (& dec )) {
263272 goto error ;
264273 } else if (dec .dest != dec .destLim || dec .state != BCJ2_STREAM_MAIN ) {
265274 goto error ;
@@ -370,7 +379,7 @@ typedef struct
370379
371380static Byte
372381ReadByte (const IByteIn * pp ) {
373- CByteInToLook * p = CONTAINER_FROM_VTBL (pp , CByteInToLook , vt );
382+ CByteInToLook * p = Z7_CONTAINER_FROM_VTBL (pp , CByteInToLook , vt );
374383 if (p -> cur != p -> end ) {
375384 return * p -> cur ++ ;
376385 }
@@ -404,7 +413,6 @@ pylzma_ppmd_decompress(PyObject *self, PyObject *args)
404413 unsigned order ;
405414 UInt32 memSize ;
406415 CPpmd7 ppmd ;
407- CPpmd7z_RangeDec rc ;
408416 CByteInToLook s ;
409417 SRes res = SZ_OK ;
410418 CMemoryLookInStream stream ;
@@ -446,30 +454,29 @@ pylzma_ppmd_decompress(PyObject *self, PyObject *args)
446454 CreateMemoryLookInStream (& stream , (Byte * ) data , length );
447455 tmp = (Byte * ) PyBytes_AS_STRING (result );
448456 Py_BEGIN_ALLOW_THREADS
449- Ppmd7z_RangeDec_CreateVTable (& rc );
450457 s .vt .Read = ReadByte ;
451458 s .inStream = & stream .s ;
452459 s .begin = s .end = s .cur = NULL ;
453460 s .extra = False ;
454461 s .res = SZ_OK ;
455462 s .processed = 0 ;
456- rc .Stream = & s .vt ;
457- if (!Ppmd7z_RangeDec_Init (& rc )) {
463+ ppmd . rc . dec .Stream = & s .vt ;
464+ if (!Ppmd7z_RangeDec_Init (& ppmd . rc . dec )) {
458465 res = SZ_ERROR_DATA ;
459466 } else if (s .extra ) {
460467 res = (s .res != SZ_OK ? s .res : SZ_ERROR_DATA );
461468 } else {
462469 SizeT i ;
463470 for (i = 0 ; i < outsize ; i ++ ) {
464- int sym = Ppmd7_DecodeSymbol (& ppmd , & rc . vt );
471+ int sym = Ppmd7z_DecodeSymbol (& ppmd );
465472 if (s .extra || sym < 0 ) {
466473 break ;
467474 }
468475 tmp [i ] = (Byte )sym ;
469476 }
470477 if (i != outsize ) {
471478 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 )) {
479+ } else if (s .processed + (s .cur - s .begin ) != (UInt64 )length || !Ppmd7z_RangeDec_IsFinishedOK (& ppmd . rc . dec )) {
473480 res = SZ_ERROR_DATA ;
474481 }
475482 }
@@ -498,7 +505,9 @@ methods[] = {
498505 {"bcj_x86_convert" , (PyCFunction )pylzma_bcj_x86_convert , METH_VARARGS , (char * )& doc_bcj_x86_convert },
499506 {"bcj_arm_convert" , (PyCFunction )pylzma_bcj_arm_convert , METH_VARARGS , (char * )& doc_bcj_arm_convert },
500507 {"bcj_armt_convert" , (PyCFunction )pylzma_bcj_armt_convert , METH_VARARGS , (char * )& doc_bcj_armt_convert },
508+ {"bcj_arm64_convert" , (PyCFunction )pylzma_bcj_arm64_convert , METH_VARARGS , (char * )& doc_bcj_arm64_convert },
501509 {"bcj_ppc_convert" , (PyCFunction )pylzma_bcj_ppc_convert , METH_VARARGS , (char * )& doc_bcj_ppc_convert },
510+ {"bcj_riscv_convert" , (PyCFunction )pylzma_bcj_riscv_convert , METH_VARARGS , (char * )& doc_bcj_riscv_convert },
502511 {"bcj_sparc_convert" , (PyCFunction )pylzma_bcj_sparc_convert , METH_VARARGS , (char * )& doc_bcj_sparc_convert },
503512 {"bcj_ia64_convert" , (PyCFunction )pylzma_bcj_ia64_convert , METH_VARARGS , (char * )& doc_bcj_ia64_convert },
504513 {"bcj2_decode" , (PyCFunction )pylzma_bcj2_decode , METH_VARARGS , (char * )& doc_bcj2_decode },
0 commit comments