Skip to content

Commit 5daf392

Browse files
authored
Merge pull request #90 from fancycode/lzma-sdk-25.01
Update to LZMA SDK 25.01 and always enable multithreading.
2 parents 3da7418 + 515bc1c commit 5daf392

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+20804
-9289
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dist
44
*.pyc
55
*.egg-info
66
*.so
7+
*.patch~
78
*.pyd
89
RELEASE-VERSION
910
/.pc

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Python bindings for LZMA
22

3-
* **PyLZMA** Copyright (C) 2004-2015 Joachim Bauch
4-
* **7-Zip** Copyright (C) 1999-2010 Igor Pavlov
5-
* **LZMA SDK** Copyright (C) 1999-2010 Igor Pavlov
3+
* **PyLZMA** Copyright (C) 2004-2025 Joachim Bauch
4+
* **7-Zip** Copyright (C) 1999-2025 Igor Pavlov
5+
* **LZMA SDK** Copyright (C) 1999-2025 Igor Pavlov
66

77
[![Linux Build Status](https://github.com/fancycode/pylzma/workflows/test/badge.svg)](https://github.com/fancycode/pylzma/actions)
88
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/5a7k7v9k2a0eiuom/branch/master?svg=true

patches/series

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
streaming_encoder.patch
2-
strict_prototype.patch

patches/streaming_encoder.patch

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,51 @@ Index: pylzma/src/sdk/C/LzmaEnc.c
22
===================================================================
33
--- pylzma.orig/src/sdk/C/LzmaEnc.c
44
+++ pylzma/src/sdk/C/LzmaEnc.c
5-
@@ -2259,8 +2259,9 @@ void LzmaEnc_Destroy(CLzmaEncHandle p, I
5+
@@ -2385,9 +2385,9 @@ void LzmaEnc_Destroy(CLzmaEncHandle p, I
66
}
77

88

9+
-Z7_NO_INLINE
910
-static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpackSize)
1011
+SRes LzmaEnc_CodeOneBlock(CLzmaEncHandle pp, UInt32 maxPackSize, UInt32 maxUnpackSize)
1112
{
1213
+ CLzmaEnc *p = (CLzmaEnc *) pp;
1314
UInt32 nowPos32, startPos32;
1415
if (p->needInit)
1516
{
16-
@@ -2715,7 +2716,7 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEn
17+
@@ -2872,7 +2872,7 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEn
1718
return SZ_OK;
1819
}
1920

20-
-static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
21-
+SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
21+
-static SRes LzmaEnc_Prepare(CLzmaEncHandle p,
22+
+SRes LzmaEnc_Prepare(CLzmaEncHandle p,
23+
ISeqOutStreamPtr outStream,
24+
ISeqInStreamPtr inStream,
2225
ISzAllocPtr alloc, ISzAllocPtr allocBig)
23-
{
24-
CLzmaEnc *p = (CLzmaEnc *)pp;
25-
@@ -2974,3 +2975,9 @@ SRes LzmaEncode(Byte *dest, SizeT *destL
26-
LzmaEnc_Destroy(p, alloc, allocBig);
27-
return res;
26+
@@ -2883,6 +2883,12 @@ static SRes LzmaEnc_Prepare(CLzmaEncHand
27+
return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
2828
}
29-
+
29+
3030
+BoolInt LzmaEnc_IsFinished(CLzmaEncHandle pp)
3131
+{
3232
+ CLzmaEnc *p = (CLzmaEnc *)pp;
3333
+ return p->finished;
3434
+}
35+
+
36+
SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle p,
37+
ISeqInStreamPtr inStream, UInt32 keepWindowSize,
38+
ISzAllocPtr alloc, ISzAllocPtr allocBig)
3539
Index: pylzma/src/sdk/C/LzmaEnc.h
3640
===================================================================
3741
--- pylzma.orig/src/sdk/C/LzmaEnc.h
3842
+++ pylzma/src/sdk/C/LzmaEnc.h
39-
@@ -73,4 +73,11 @@ SRes LzmaEncode(Byte *dest, SizeT *destL
43+
@@ -82,4 +82,11 @@ SRes LzmaEncode(Byte *dest, SizeT *destL
4044

4145
EXTERN_C_END
4246

4347
+/* ---------- Streaming Interface ---------- */
4448
+
45-
+SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ISzAllocPtr alloc, ISzAllocPtr allocBig);
49+
+SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStreamPtr outStream, ISeqInStreamPtr inStream, ISzAllocPtr alloc, ISzAllocPtr allocBig);
4650
+SRes LzmaEnc_CodeOneBlock(CLzmaEncHandle pp, UInt32 maxPackSize, UInt32 maxUnpackSize);
4751
+BoolInt LzmaEnc_IsFinished(CLzmaEncHandle pp);
4852
+void LzmaEnc_Finish(CLzmaEncHandle pp);

patches/strict_prototype.patch

Lines changed: 0 additions & 17 deletions
This file was deleted.

setup.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ def __new__(cls, s):
8585

8686
library_dirs = []
8787

88-
# platforms that multithreaded compression is supported on
89-
mt_platforms = (
90-
'win32',
91-
)
92-
9388
if IS_WINDOWS:
9489
# don't try to import MSVC compiler on non-windows platforms
9590
# as this triggers unnecessary warnings
@@ -107,14 +102,7 @@ class MSVCCompiler(object):
107102
class build_ext(_build_ext):
108103

109104
def build_extension(self, ext):
110-
self.with_mt = ENABLE_MULTITHREADING
111-
if self.with_mt and not sys.platform in mt_platforms:
112-
warn("""\
113-
Multithreading is not supported on the platform "%s",
114-
please contact [email protected] for more informations.""" % (sys.platform), UnsupportedPlatformWarning)
115-
self.with_mt = False
116-
117-
if self.with_mt:
105+
if ENABLE_MULTITHREADING:
118106
log.info('adding support for multithreaded compression')
119107
ext.define_macros.append(('COMPRESS_MF_MT', 1))
120108
ext.sources += (
@@ -124,7 +112,7 @@ def build_extension(self, ext):
124112
'src/sdk/C/Threads.c',
125113
)
126114
else:
127-
ext.define_macros.append(('_7ZIP_ST', 1))
115+
ext.define_macros.append(('Z7_ST', 1))
128116

129117
if isinstance(self.compiler, MSVCCompiler) or getattr(self.compiler, 'compiler_type', '') == 'msvc':
130118
# set flags only available when using MSVC
@@ -163,6 +151,7 @@ def build_extension(self, ext):
163151
('PY_SSIZE_T_CLEAN', 1),
164152
]
165153
lzma_files = (
154+
'src/sdk/C/7zStream.c',
166155
'src/sdk/C/Aes.c',
167156
'src/sdk/C/AesOpt.c',
168157
'src/sdk/C/Bcj2.c',
@@ -172,11 +161,14 @@ def build_extension(self, ext):
172161
'src/sdk/C/CpuArch.c',
173162
'src/sdk/C/Delta.c',
174163
'src/sdk/C/LzFind.c',
164+
'src/sdk/C/LzFindOpt.c',
175165
'src/sdk/C/LzmaDec.c',
176166
'src/sdk/C/LzmaEnc.c',
177167
'src/sdk/C/Lzma2Dec.c',
178168
'src/sdk/C/Lzma2Enc.c',
179169
'src/sdk/C/Sha256.c',
170+
'src/sdk/C/Sha256Opt.c',
171+
'src/sdk/C/SwapBytes.c',
180172
'src/sdk/C/Ppmd7.c',
181173
'src/sdk/C/Ppmd7Dec.c',
182174
)

src/pylzma/pylzma.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pylzma_calculate_key(PyObject *self, PyObject *args, PyObject *kwargs)
130130

131131
const char
132132
doc_bcj_x86_convert[] = \
133-
"bcj_x86_convert(data) -- Perform BCJ x86 conversion.";
133+
"bcj_x86_convert(data, [encoding]) -- Perform BCJ x86 conversion.";
134134

135135
static PyObject *
136136
pylzma_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) \
164167
const char \
165168
doc_bcj_##id##_convert[] = \
166-
"bcj_" #id "_convert(data) -- Perform BCJ " #name " conversion."; \
169+
"bcj_" #id "_convert(data, [encoding]) -- Perform BCJ " #name " conversion."; \
167170
\
168171
static PyObject * \
169172
pylzma_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

194201
DEFINE_BCJ_CONVERTER(arm, ARM);
195202
DEFINE_BCJ_CONVERTER(armt, ARMT);
203+
DEFINE_BCJ_CONVERTER(arm64, ARM64);
196204
DEFINE_BCJ_CONVERTER(ppc, PPC);
205+
DEFINE_BCJ_CONVERTER(riscv, RISCV);
197206
DEFINE_BCJ_CONVERTER(sparc, SPARC);
198207
DEFINE_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

371380
static Byte
372381
ReadByte(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},

src/sdk/C/7z.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* 7z.h -- 7z interface
2-
2017-04-03 : Igor Pavlov : Public domain */
2+
2023-04-02 : Igor Pavlov : Public domain */
33

4-
#ifndef __7Z_H
5-
#define __7Z_H
4+
#ifndef ZIP7_INC_7Z_H
5+
#define ZIP7_INC_7Z_H
66

77
#include "7zTypes.h"
88

@@ -91,12 +91,14 @@ typedef struct
9191
UInt64 *CoderUnpackSizes; // for all coders in all folders
9292

9393
Byte *CodersData;
94+
95+
UInt64 RangeLimit;
9496
} CSzAr;
9597

9698
UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);
9799

98100
SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
99-
ILookInStream *stream, UInt64 startPos,
101+
ILookInStreamPtr stream, UInt64 startPos,
100102
Byte *outBuffer, size_t outSize,
101103
ISzAllocPtr allocMain);
102104

@@ -172,7 +174,7 @@ UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16
172174

173175
SRes SzArEx_Extract(
174176
const CSzArEx *db,
175-
ILookInStream *inStream,
177+
ILookInStreamPtr inStream,
176178
UInt32 fileIndex, /* index of file */
177179
UInt32 *blockIndex, /* index of solid block */
178180
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
@@ -194,7 +196,7 @@ SZ_ERROR_INPUT_EOF
194196
SZ_ERROR_FAIL
195197
*/
196198

197-
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
199+
SRes SzArEx_Open(CSzArEx *p, ILookInStreamPtr inStream,
198200
ISzAllocPtr allocMain, ISzAllocPtr allocTemp);
199201

200202
EXTERN_C_END

0 commit comments

Comments
 (0)