Skip to content

Commit bc21f4e

Browse files
committed
Update to LZMA SDK 25.01 and always enable multithreading.
1 parent 3da7418 commit bc21f4e

Some content is hidden

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

118 files changed

+20797
-9286
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

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: 19 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
\
@@ -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

371378
static Byte
372379
ReadByte(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
}

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)