Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit40029fb

Browse files
committed
`fixup! -1 business
* doc and code change for -1* put state parsing in one place, I guess??
1 parentb796221 commit40029fb

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

‎Lib/lzma.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ def __init__(self, filename=None, mode="r", *,
9292
should have an entry for "id" indicating ID of the filter, plus
9393
additional entries for options to the filter.
9494
95-
threads (if provided) should be anon-negative integerindicating how
96-
many background threads to create for the compressor (only when using
97-
FORMAT_XZ, otherwise the compression will be single-threaded).
95+
threads (if provided) should be anonnegative integeror -1 indicating
96+
howmany background threads to create for the compressor (only when
97+
usingFORMAT_XZ, otherwise the compression will be single-threaded).
9898
If 0, the number of threads is set to the number of CPU cores.
99+
If -1, the single-thread non-chunked compressor is used (the file will
100+
not be available for parallel decompression).
99101
"""
100102
self._fp=None
101103
self._closefp=False

‎Lib/test/test_lzma.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ def test_roundtrip_xz(self):
282282
lzd=LZMADecompressor()
283283
self._test_decompressor(lzd,cdata,lzma.CHECK_CRC64)
284284

285+
deftest_roundtrip_xz_nonchunk(self):
286+
lzc=LZMACompressor(threads=-1)
287+
cdata=lzc.compress(INPUT)+lzc.flush()
288+
lzd=LZMADecompressor()
289+
self._test_decompressor(lzd,cdata,lzma.CHECK_CRC64)
290+
285291
deftest_roundtrip_xz_mt(self):
286292
lzc=LZMACompressor(threads=0)
287293
cdata=lzc.compress(INPUT)+lzc.flush()
@@ -687,7 +693,7 @@ def test_init_bad_filter_spec(self):
687693

688694
deftest_init_bad_threads(self):
689695
withself.assertRaises(ValueError):
690-
LZMAFile(BytesIO(),"w",threads=-1)
696+
LZMAFile(BytesIO(),"w",threads=-2)
691697

692698
deftest_init_with_preset_and_filters(self):
693699
withself.assertRaises(ValueError):

‎Modules/_lzmamodule.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -654,24 +654,24 @@ Compressor_init_xz(_lzma_state *state, lzma_stream *lzs,
654654
intthreads)
655655
{
656656
lzma_retlzret;
657+
lzma_filterfilters[LZMA_FILTERS_MAX+1];
658+
659+
if (filterspecs!=Py_None) {
660+
if (parse_filter_chain_spec(state,filters,filterspecs)==-1) {
661+
return-1;
662+
}
663+
}
657664

658-
if (threads==1) {
665+
if (threads==-1) {
659666
if (filterspecs==Py_None) {
660667
lzret=lzma_easy_encoder(lzs,preset,check);
661668
}else {
662-
lzma_filterfilters[LZMA_FILTERS_MAX+1];
663-
664-
if (parse_filter_chain_spec(state,filters,filterspecs)==-1) {
665-
return-1;
666-
}
667-
668669
lzret=lzma_stream_encoder(lzs,filters,check);
669-
free_filter_chain(filters);
670670
}
671671
}else {
672672
if (threads<0) {
673673
PyErr_SetString(PyExc_ValueError,
674-
"threads must be a non-negative integer");
674+
"threads must be a non-negative integer or -1");
675675
return-1;
676676
}
677677

@@ -695,12 +695,6 @@ Compressor_init_xz(_lzma_state *state, lzma_stream *lzs,
695695
if (filterspecs==Py_None) {
696696
lzret=lzma_stream_encoder_mt(lzs,&mt);
697697
}else {
698-
lzma_filterfilters[LZMA_FILTERS_MAX+1];
699-
700-
if (parse_filter_chain_spec(state,filters,filterspecs)==-1) {
701-
return-1;
702-
}
703-
704698
mt.filters=filters;
705699
lzret=lzma_stream_encoder_mt(lzs,&mt);
706700
free_filter_chain(filters);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp