aboutsummaryrefslogtreecommitdiff
path: root/C/Lzma2Enc.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--C/Lzma2Enc.c174
1 files changed, 88 insertions, 86 deletions
diff --git a/C/Lzma2Enc.c b/C/Lzma2Enc.c
index e61a5df..703e146 100644
--- a/C/Lzma2Enc.c
+++ b/C/Lzma2Enc.c
@@ -1,18 +1,18 @@
1/* Lzma2Enc.c -- LZMA2 Encoder 1/* Lzma2Enc.c -- LZMA2 Encoder
22021-02-09 : Igor Pavlov : Public domain */ 22023-04-13 : Igor Pavlov : Public domain */
3 3
4#include "Precomp.h" 4#include "Precomp.h"
5 5
6#include <string.h> 6#include <string.h>
7 7
8/* #define _7ZIP_ST */ 8/* #define Z7_ST */
9 9
10#include "Lzma2Enc.h" 10#include "Lzma2Enc.h"
11 11
12#ifndef _7ZIP_ST 12#ifndef Z7_ST
13#include "MtCoder.h" 13#include "MtCoder.h"
14#else 14#else
15#define MTCODER__THREADS_MAX 1 15#define MTCODER_THREADS_MAX 1
16#endif 16#endif
17 17
18#define LZMA2_CONTROL_LZMA (1 << 7) 18#define LZMA2_CONTROL_LZMA (1 << 7)
@@ -40,7 +40,7 @@
40typedef struct 40typedef struct
41{ 41{
42 ISeqInStream vt; 42 ISeqInStream vt;
43 ISeqInStream *realStream; 43 ISeqInStreamPtr realStream;
44 UInt64 limit; 44 UInt64 limit;
45 UInt64 processed; 45 UInt64 processed;
46 int finished; 46 int finished;
@@ -53,15 +53,15 @@ static void LimitedSeqInStream_Init(CLimitedSeqInStream *p)
53 p->finished = 0; 53 p->finished = 0;
54} 54}
55 55
56static SRes LimitedSeqInStream_Read(const ISeqInStream *pp, void *data, size_t *size) 56static SRes LimitedSeqInStream_Read(ISeqInStreamPtr pp, void *data, size_t *size)
57{ 57{
58 CLimitedSeqInStream *p = CONTAINER_FROM_VTBL(pp, CLimitedSeqInStream, vt); 58 Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(CLimitedSeqInStream)
59 size_t size2 = *size; 59 size_t size2 = *size;
60 SRes res = SZ_OK; 60 SRes res = SZ_OK;
61 61
62 if (p->limit != (UInt64)(Int64)-1) 62 if (p->limit != (UInt64)(Int64)-1)
63 { 63 {
64 UInt64 rem = p->limit - p->processed; 64 const UInt64 rem = p->limit - p->processed;
65 if (size2 > rem) 65 if (size2 > rem)
66 size2 = (size_t)rem; 66 size2 = (size_t)rem;
67 } 67 }
@@ -95,8 +95,8 @@ static SRes Lzma2EncInt_InitStream(CLzma2EncInt *p, const CLzma2EncProps *props)
95 { 95 {
96 SizeT propsSize = LZMA_PROPS_SIZE; 96 SizeT propsSize = LZMA_PROPS_SIZE;
97 Byte propsEncoded[LZMA_PROPS_SIZE]; 97 Byte propsEncoded[LZMA_PROPS_SIZE];
98 RINOK(LzmaEnc_SetProps(p->enc, &props->lzmaProps)); 98 RINOK(LzmaEnc_SetProps(p->enc, &props->lzmaProps))
99 RINOK(LzmaEnc_WriteProperties(p->enc, propsEncoded, &propsSize)); 99 RINOK(LzmaEnc_WriteProperties(p->enc, propsEncoded, &propsSize))
100 p->propsByte = propsEncoded[0]; 100 p->propsByte = propsEncoded[0];
101 p->propsAreSet = True; 101 p->propsAreSet = True;
102 } 102 }
@@ -111,23 +111,23 @@ static void Lzma2EncInt_InitBlock(CLzma2EncInt *p)
111} 111}
112 112
113 113
114SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 keepWindowSize, 114SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle p, ISeqInStreamPtr inStream, UInt32 keepWindowSize,
115 ISzAllocPtr alloc, ISzAllocPtr allocBig); 115 ISzAllocPtr alloc, ISzAllocPtr allocBig);
116SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, 116SRes LzmaEnc_MemPrepare(CLzmaEncHandle p, const Byte *src, SizeT srcLen,
117 UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig); 117 UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig);
118SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit, 118SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle p, BoolInt reInit,
119 Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize); 119 Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
120const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp); 120const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle p);
121void LzmaEnc_Finish(CLzmaEncHandle pp); 121void LzmaEnc_Finish(CLzmaEncHandle p);
122void LzmaEnc_SaveState(CLzmaEncHandle pp); 122void LzmaEnc_SaveState(CLzmaEncHandle p);
123void LzmaEnc_RestoreState(CLzmaEncHandle pp); 123void LzmaEnc_RestoreState(CLzmaEncHandle p);
124 124
125/* 125/*
126UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp); 126UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle p);
127*/ 127*/
128 128
129static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf, 129static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
130 size_t *packSizeRes, ISeqOutStream *outStream) 130 size_t *packSizeRes, ISeqOutStreamPtr outStream)
131{ 131{
132 size_t packSizeLimit = *packSizeRes; 132 size_t packSizeLimit = *packSizeRes;
133 size_t packSize = packSizeLimit; 133 size_t packSize = packSizeLimit;
@@ -167,7 +167,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
167 167
168 while (unpackSize > 0) 168 while (unpackSize > 0)
169 { 169 {
170 UInt32 u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE; 170 const UInt32 u = (unpackSize < LZMA2_COPY_CHUNK_SIZE) ? unpackSize : LZMA2_COPY_CHUNK_SIZE;
171 if (packSizeLimit - destPos < u + 3) 171 if (packSizeLimit - destPos < u + 3)
172 return SZ_ERROR_OUTPUT_EOF; 172 return SZ_ERROR_OUTPUT_EOF;
173 outBuf[destPos++] = (Byte)(p->srcPos == 0 ? LZMA2_CONTROL_COPY_RESET_DIC : LZMA2_CONTROL_COPY_NO_RESET); 173 outBuf[destPos++] = (Byte)(p->srcPos == 0 ? LZMA2_CONTROL_COPY_RESET_DIC : LZMA2_CONTROL_COPY_NO_RESET);
@@ -196,9 +196,9 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
196 196
197 { 197 {
198 size_t destPos = 0; 198 size_t destPos = 0;
199 UInt32 u = unpackSize - 1; 199 const UInt32 u = unpackSize - 1;
200 UInt32 pm = (UInt32)(packSize - 1); 200 const UInt32 pm = (UInt32)(packSize - 1);
201 unsigned mode = (p->srcPos == 0) ? 3 : (p->needInitState ? (p->needInitProp ? 2 : 1) : 0); 201 const unsigned mode = (p->srcPos == 0) ? 3 : (p->needInitState ? (p->needInitProp ? 2 : 1) : 0);
202 202
203 PRF(printf(" ")); 203 PRF(printf(" "));
204 204
@@ -231,7 +231,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
231void Lzma2EncProps_Init(CLzma2EncProps *p) 231void Lzma2EncProps_Init(CLzma2EncProps *p)
232{ 232{
233 LzmaEncProps_Init(&p->lzmaProps); 233 LzmaEncProps_Init(&p->lzmaProps);
234 p->blockSize = LZMA2_ENC_PROPS__BLOCK_SIZE__AUTO; 234 p->blockSize = LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO;
235 p->numBlockThreads_Reduced = -1; 235 p->numBlockThreads_Reduced = -1;
236 p->numBlockThreads_Max = -1; 236 p->numBlockThreads_Max = -1;
237 p->numTotalThreads = -1; 237 p->numTotalThreads = -1;
@@ -251,8 +251,8 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
251 t2 = p->numBlockThreads_Max; 251 t2 = p->numBlockThreads_Max;
252 t3 = p->numTotalThreads; 252 t3 = p->numTotalThreads;
253 253
254 if (t2 > MTCODER__THREADS_MAX) 254 if (t2 > MTCODER_THREADS_MAX)
255 t2 = MTCODER__THREADS_MAX; 255 t2 = MTCODER_THREADS_MAX;
256 256
257 if (t3 <= 0) 257 if (t3 <= 0)
258 { 258 {
@@ -268,8 +268,8 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
268 t1 = 1; 268 t1 = 1;
269 t2 = t3; 269 t2 = t3;
270 } 270 }
271 if (t2 > MTCODER__THREADS_MAX) 271 if (t2 > MTCODER_THREADS_MAX)
272 t2 = MTCODER__THREADS_MAX; 272 t2 = MTCODER_THREADS_MAX;
273 } 273 }
274 else if (t1 <= 0) 274 else if (t1 <= 0)
275 { 275 {
@@ -286,8 +286,8 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
286 286
287 fileSize = p->lzmaProps.reduceSize; 287 fileSize = p->lzmaProps.reduceSize;
288 288
289 if ( p->blockSize != LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID 289 if ( p->blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID
290 && p->blockSize != LZMA2_ENC_PROPS__BLOCK_SIZE__AUTO 290 && p->blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO
291 && (p->blockSize < fileSize || fileSize == (UInt64)(Int64)-1)) 291 && (p->blockSize < fileSize || fileSize == (UInt64)(Int64)-1))
292 p->lzmaProps.reduceSize = p->blockSize; 292 p->lzmaProps.reduceSize = p->blockSize;
293 293
@@ -297,19 +297,19 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
297 297
298 t1 = p->lzmaProps.numThreads; 298 t1 = p->lzmaProps.numThreads;
299 299
300 if (p->blockSize == LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID) 300 if (p->blockSize == LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID)
301 { 301 {
302 t2r = t2 = 1; 302 t2r = t2 = 1;
303 t3 = t1; 303 t3 = t1;
304 } 304 }
305 else if (p->blockSize == LZMA2_ENC_PROPS__BLOCK_SIZE__AUTO && t2 <= 1) 305 else if (p->blockSize == LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO && t2 <= 1)
306 { 306 {
307 /* if there is no block multi-threading, we use SOLID block */ 307 /* if there is no block multi-threading, we use SOLID block */
308 p->blockSize = LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID; 308 p->blockSize = LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID;
309 } 309 }
310 else 310 else
311 { 311 {
312 if (p->blockSize == LZMA2_ENC_PROPS__BLOCK_SIZE__AUTO) 312 if (p->blockSize == LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO)
313 { 313 {
314 const UInt32 kMinSize = (UInt32)1 << 20; 314 const UInt32 kMinSize = (UInt32)1 << 20;
315 const UInt32 kMaxSize = (UInt32)1 << 28; 315 const UInt32 kMaxSize = (UInt32)1 << 28;
@@ -344,7 +344,7 @@ void Lzma2EncProps_Normalize(CLzma2EncProps *p)
344} 344}
345 345
346 346
347static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize) 347static SRes Progress(ICompressProgressPtr p, UInt64 inSize, UInt64 outSize)
348{ 348{
349 return (p && ICompressProgress_Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK; 349 return (p && ICompressProgress_Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK;
350} 350}
@@ -352,7 +352,7 @@ static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
352 352
353/* ---------- Lzma2 ---------- */ 353/* ---------- Lzma2 ---------- */
354 354
355typedef struct 355struct CLzma2Enc
356{ 356{
357 Byte propEncoded; 357 Byte propEncoded;
358 CLzma2EncProps props; 358 CLzma2EncProps props;
@@ -363,23 +363,22 @@ typedef struct
363 ISzAllocPtr alloc; 363 ISzAllocPtr alloc;
364 ISzAllocPtr allocBig; 364 ISzAllocPtr allocBig;
365 365
366 CLzma2EncInt coders[MTCODER__THREADS_MAX]; 366 CLzma2EncInt coders[MTCODER_THREADS_MAX];
367 367
368 #ifndef _7ZIP_ST 368 #ifndef Z7_ST
369 369
370 ISeqOutStream *outStream; 370 ISeqOutStreamPtr outStream;
371 Byte *outBuf; 371 Byte *outBuf;
372 size_t outBuf_Rem; /* remainder in outBuf */ 372 size_t outBuf_Rem; /* remainder in outBuf */
373 373
374 size_t outBufSize; /* size of allocated outBufs[i] */ 374 size_t outBufSize; /* size of allocated outBufs[i] */
375 size_t outBufsDataSizes[MTCODER__BLOCKS_MAX]; 375 size_t outBufsDataSizes[MTCODER_BLOCKS_MAX];
376 BoolInt mtCoder_WasConstructed; 376 BoolInt mtCoder_WasConstructed;
377 CMtCoder mtCoder; 377 CMtCoder mtCoder;
378 Byte *outBufs[MTCODER__BLOCKS_MAX]; 378 Byte *outBufs[MTCODER_BLOCKS_MAX];
379 379
380 #endif 380 #endif
381 381};
382} CLzma2Enc;
383 382
384 383
385 384
@@ -396,30 +395,30 @@ CLzma2EncHandle Lzma2Enc_Create(ISzAllocPtr alloc, ISzAllocPtr allocBig)
396 p->allocBig = allocBig; 395 p->allocBig = allocBig;
397 { 396 {
398 unsigned i; 397 unsigned i;
399 for (i = 0; i < MTCODER__THREADS_MAX; i++) 398 for (i = 0; i < MTCODER_THREADS_MAX; i++)
400 p->coders[i].enc = NULL; 399 p->coders[i].enc = NULL;
401 } 400 }
402 401
403 #ifndef _7ZIP_ST 402 #ifndef Z7_ST
404 p->mtCoder_WasConstructed = False; 403 p->mtCoder_WasConstructed = False;
405 { 404 {
406 unsigned i; 405 unsigned i;
407 for (i = 0; i < MTCODER__BLOCKS_MAX; i++) 406 for (i = 0; i < MTCODER_BLOCKS_MAX; i++)
408 p->outBufs[i] = NULL; 407 p->outBufs[i] = NULL;
409 p->outBufSize = 0; 408 p->outBufSize = 0;
410 } 409 }
411 #endif 410 #endif
412 411
413 return p; 412 return (CLzma2EncHandle)p;
414} 413}
415 414
416 415
417#ifndef _7ZIP_ST 416#ifndef Z7_ST
418 417
419static void Lzma2Enc_FreeOutBufs(CLzma2Enc *p) 418static void Lzma2Enc_FreeOutBufs(CLzma2Enc *p)
420{ 419{
421 unsigned i; 420 unsigned i;
422 for (i = 0; i < MTCODER__BLOCKS_MAX; i++) 421 for (i = 0; i < MTCODER_BLOCKS_MAX; i++)
423 if (p->outBufs[i]) 422 if (p->outBufs[i])
424 { 423 {
425 ISzAlloc_Free(p->alloc, p->outBufs[i]); 424 ISzAlloc_Free(p->alloc, p->outBufs[i]);
@@ -430,12 +429,13 @@ static void Lzma2Enc_FreeOutBufs(CLzma2Enc *p)
430 429
431#endif 430#endif
432 431
432// #define GET_CLzma2Enc_p CLzma2Enc *p = (CLzma2Enc *)(void *)p;
433 433
434void Lzma2Enc_Destroy(CLzma2EncHandle pp) 434void Lzma2Enc_Destroy(CLzma2EncHandle p)
435{ 435{
436 CLzma2Enc *p = (CLzma2Enc *)pp; 436 // GET_CLzma2Enc_p
437 unsigned i; 437 unsigned i;
438 for (i = 0; i < MTCODER__THREADS_MAX; i++) 438 for (i = 0; i < MTCODER_THREADS_MAX; i++)
439 { 439 {
440 CLzma2EncInt *t = &p->coders[i]; 440 CLzma2EncInt *t = &p->coders[i];
441 if (t->enc) 441 if (t->enc)
@@ -446,7 +446,7 @@ void Lzma2Enc_Destroy(CLzma2EncHandle pp)
446 } 446 }
447 447
448 448
449 #ifndef _7ZIP_ST 449 #ifndef Z7_ST
450 if (p->mtCoder_WasConstructed) 450 if (p->mtCoder_WasConstructed)
451 { 451 {
452 MtCoder_Destruct(&p->mtCoder); 452 MtCoder_Destruct(&p->mtCoder);
@@ -458,13 +458,13 @@ void Lzma2Enc_Destroy(CLzma2EncHandle pp)
458 ISzAlloc_Free(p->alloc, p->tempBufLzma); 458 ISzAlloc_Free(p->alloc, p->tempBufLzma);
459 p->tempBufLzma = NULL; 459 p->tempBufLzma = NULL;
460 460
461 ISzAlloc_Free(p->alloc, pp); 461 ISzAlloc_Free(p->alloc, p);
462} 462}
463 463
464 464
465SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props) 465SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props)
466{ 466{
467 CLzma2Enc *p = (CLzma2Enc *)pp; 467 // GET_CLzma2Enc_p
468 CLzmaEncProps lzmaProps = props->lzmaProps; 468 CLzmaEncProps lzmaProps = props->lzmaProps;
469 LzmaEncProps_Normalize(&lzmaProps); 469 LzmaEncProps_Normalize(&lzmaProps);
470 if (lzmaProps.lc + lzmaProps.lp > LZMA2_LCLP_MAX) 470 if (lzmaProps.lc + lzmaProps.lp > LZMA2_LCLP_MAX)
@@ -475,16 +475,16 @@ SRes Lzma2Enc_SetProps(CLzma2EncHandle pp, const CLzma2EncProps *props)
475} 475}
476 476
477 477
478void Lzma2Enc_SetDataSize(CLzmaEncHandle pp, UInt64 expectedDataSiize) 478void Lzma2Enc_SetDataSize(CLzma2EncHandle p, UInt64 expectedDataSiize)
479{ 479{
480 CLzma2Enc *p = (CLzma2Enc *)pp; 480 // GET_CLzma2Enc_p
481 p->expectedDataSize = expectedDataSiize; 481 p->expectedDataSize = expectedDataSiize;
482} 482}
483 483
484 484
485Byte Lzma2Enc_WriteProperties(CLzma2EncHandle pp) 485Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p)
486{ 486{
487 CLzma2Enc *p = (CLzma2Enc *)pp; 487 // GET_CLzma2Enc_p
488 unsigned i; 488 unsigned i;
489 UInt32 dicSize = LzmaEncProps_GetDictSize(&p->props.lzmaProps); 489 UInt32 dicSize = LzmaEncProps_GetDictSize(&p->props.lzmaProps);
490 for (i = 0; i < 40; i++) 490 for (i = 0; i < 40; i++)
@@ -497,12 +497,12 @@ Byte Lzma2Enc_WriteProperties(CLzma2EncHandle pp)
497static SRes Lzma2Enc_EncodeMt1( 497static SRes Lzma2Enc_EncodeMt1(
498 CLzma2Enc *me, 498 CLzma2Enc *me,
499 CLzma2EncInt *p, 499 CLzma2EncInt *p,
500 ISeqOutStream *outStream, 500 ISeqOutStreamPtr outStream,
501 Byte *outBuf, size_t *outBufSize, 501 Byte *outBuf, size_t *outBufSize,
502 ISeqInStream *inStream, 502 ISeqInStreamPtr inStream,
503 const Byte *inData, size_t inDataSize, 503 const Byte *inData, size_t inDataSize,
504 int finished, 504 int finished,
505 ICompressProgress *progress) 505 ICompressProgressPtr progress)
506{ 506{
507 UInt64 unpackTotal = 0; 507 UInt64 unpackTotal = 0;
508 UInt64 packTotal = 0; 508 UInt64 packTotal = 0;
@@ -540,12 +540,12 @@ static SRes Lzma2Enc_EncodeMt1(
540 } 540 }
541 } 541 }
542 542
543 RINOK(Lzma2EncInt_InitStream(p, &me->props)); 543 RINOK(Lzma2EncInt_InitStream(p, &me->props))
544 544
545 for (;;) 545 for (;;)
546 { 546 {
547 SRes res = SZ_OK; 547 SRes res = SZ_OK;
548 size_t inSizeCur = 0; 548 SizeT inSizeCur = 0;
549 549
550 Lzma2EncInt_InitBlock(p); 550 Lzma2EncInt_InitBlock(p);
551 551
@@ -559,7 +559,7 @@ static SRes Lzma2Enc_EncodeMt1(
559 if (me->expectedDataSize != (UInt64)(Int64)-1 559 if (me->expectedDataSize != (UInt64)(Int64)-1
560 && me->expectedDataSize >= unpackTotal) 560 && me->expectedDataSize >= unpackTotal)
561 expected = me->expectedDataSize - unpackTotal; 561 expected = me->expectedDataSize - unpackTotal;
562 if (me->props.blockSize != LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID 562 if (me->props.blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID
563 && expected > me->props.blockSize) 563 && expected > me->props.blockSize)
564 expected = (size_t)me->props.blockSize; 564 expected = (size_t)me->props.blockSize;
565 565
@@ -569,14 +569,14 @@ static SRes Lzma2Enc_EncodeMt1(
569 &limitedInStream.vt, 569 &limitedInStream.vt,
570 LZMA2_KEEP_WINDOW_SIZE, 570 LZMA2_KEEP_WINDOW_SIZE,
571 me->alloc, 571 me->alloc,
572 me->allocBig)); 572 me->allocBig))
573 } 573 }
574 else 574 else
575 { 575 {
576 inSizeCur = inDataSize - (size_t)unpackTotal; 576 inSizeCur = (SizeT)(inDataSize - (size_t)unpackTotal);
577 if (me->props.blockSize != LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID 577 if (me->props.blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID
578 && inSizeCur > me->props.blockSize) 578 && inSizeCur > me->props.blockSize)
579 inSizeCur = (size_t)me->props.blockSize; 579 inSizeCur = (SizeT)(size_t)me->props.blockSize;
580 580
581 // LzmaEnc_SetDataSize(p->enc, inSizeCur); 581 // LzmaEnc_SetDataSize(p->enc, inSizeCur);
582 582
@@ -584,7 +584,7 @@ static SRes Lzma2Enc_EncodeMt1(
584 inData + (size_t)unpackTotal, inSizeCur, 584 inData + (size_t)unpackTotal, inSizeCur,
585 LZMA2_KEEP_WINDOW_SIZE, 585 LZMA2_KEEP_WINDOW_SIZE,
586 me->alloc, 586 me->alloc,
587 me->allocBig)); 587 me->allocBig))
588 } 588 }
589 589
590 for (;;) 590 for (;;)
@@ -621,7 +621,7 @@ static SRes Lzma2Enc_EncodeMt1(
621 621
622 unpackTotal += p->srcPos; 622 unpackTotal += p->srcPos;
623 623
624 RINOK(res); 624 RINOK(res)
625 625
626 if (p->srcPos != (inStream ? limitedInStream.processed : inSizeCur)) 626 if (p->srcPos != (inStream ? limitedInStream.processed : inSizeCur))
627 return SZ_ERROR_FAIL; 627 return SZ_ERROR_FAIL;
@@ -652,12 +652,12 @@ static SRes Lzma2Enc_EncodeMt1(
652 652
653 653
654 654
655#ifndef _7ZIP_ST 655#ifndef Z7_ST
656 656
657static SRes Lzma2Enc_MtCallback_Code(void *pp, unsigned coderIndex, unsigned outBufIndex, 657static SRes Lzma2Enc_MtCallback_Code(void *p, unsigned coderIndex, unsigned outBufIndex,
658 const Byte *src, size_t srcSize, int finished) 658 const Byte *src, size_t srcSize, int finished)
659{ 659{
660 CLzma2Enc *me = (CLzma2Enc *)pp; 660 CLzma2Enc *me = (CLzma2Enc *)p;
661 size_t destSize = me->outBufSize; 661 size_t destSize = me->outBufSize;
662 SRes res; 662 SRes res;
663 CMtProgressThunk progressThunk; 663 CMtProgressThunk progressThunk;
@@ -692,9 +692,9 @@ static SRes Lzma2Enc_MtCallback_Code(void *pp, unsigned coderIndex, unsigned out
692} 692}
693 693
694 694
695static SRes Lzma2Enc_MtCallback_Write(void *pp, unsigned outBufIndex) 695static SRes Lzma2Enc_MtCallback_Write(void *p, unsigned outBufIndex)
696{ 696{
697 CLzma2Enc *me = (CLzma2Enc *)pp; 697 CLzma2Enc *me = (CLzma2Enc *)p;
698 size_t size = me->outBufsDataSizes[outBufIndex]; 698 size_t size = me->outBufsDataSizes[outBufIndex];
699 const Byte *data = me->outBufs[outBufIndex]; 699 const Byte *data = me->outBufs[outBufIndex];
700 700
@@ -713,14 +713,14 @@ static SRes Lzma2Enc_MtCallback_Write(void *pp, unsigned outBufIndex)
713 713
714 714
715 715
716SRes Lzma2Enc_Encode2(CLzma2EncHandle pp, 716SRes Lzma2Enc_Encode2(CLzma2EncHandle p,
717 ISeqOutStream *outStream, 717 ISeqOutStreamPtr outStream,
718 Byte *outBuf, size_t *outBufSize, 718 Byte *outBuf, size_t *outBufSize,
719 ISeqInStream *inStream, 719 ISeqInStreamPtr inStream,
720 const Byte *inData, size_t inDataSize, 720 const Byte *inData, size_t inDataSize,
721 ICompressProgress *progress) 721 ICompressProgressPtr progress)
722{ 722{
723 CLzma2Enc *p = (CLzma2Enc *)pp; 723 // GET_CLzma2Enc_p
724 724
725 if (inStream && inData) 725 if (inStream && inData)
726 return SZ_ERROR_PARAM; 726 return SZ_ERROR_PARAM;
@@ -730,11 +730,11 @@ SRes Lzma2Enc_Encode2(CLzma2EncHandle pp,
730 730
731 { 731 {
732 unsigned i; 732 unsigned i;
733 for (i = 0; i < MTCODER__THREADS_MAX; i++) 733 for (i = 0; i < MTCODER_THREADS_MAX; i++)
734 p->coders[i].propsAreSet = False; 734 p->coders[i].propsAreSet = False;
735 } 735 }
736 736
737 #ifndef _7ZIP_ST 737 #ifndef Z7_ST
738 738
739 if (p->props.numBlockThreads_Reduced > 1) 739 if (p->props.numBlockThreads_Reduced > 1)
740 { 740 {
@@ -772,7 +772,7 @@ SRes Lzma2Enc_Encode2(CLzma2EncHandle pp,
772 return SZ_ERROR_PARAM; /* SZ_ERROR_MEM */ 772 return SZ_ERROR_PARAM; /* SZ_ERROR_MEM */
773 773
774 { 774 {
775 size_t destBlockSize = p->mtCoder.blockSize + (p->mtCoder.blockSize >> 10) + 16; 775 const size_t destBlockSize = p->mtCoder.blockSize + (p->mtCoder.blockSize >> 10) + 16;
776 if (destBlockSize < p->mtCoder.blockSize) 776 if (destBlockSize < p->mtCoder.blockSize)
777 return SZ_ERROR_PARAM; 777 return SZ_ERROR_PARAM;
778 if (p->outBufSize != destBlockSize) 778 if (p->outBufSize != destBlockSize)
@@ -784,7 +784,7 @@ SRes Lzma2Enc_Encode2(CLzma2EncHandle pp,
784 p->mtCoder.expectedDataSize = p->expectedDataSize; 784 p->mtCoder.expectedDataSize = p->expectedDataSize;
785 785
786 { 786 {
787 SRes res = MtCoder_Code(&p->mtCoder); 787 const SRes res = MtCoder_Code(&p->mtCoder);
788 if (!outStream) 788 if (!outStream)
789 *outBufSize = (size_t)(p->outBuf - outBuf); 789 *outBufSize = (size_t)(p->outBuf - outBuf);
790 return res; 790 return res;
@@ -801,3 +801,5 @@ SRes Lzma2Enc_Encode2(CLzma2EncHandle pp,
801 True, /* finished */ 801 True, /* finished */
802 progress); 802 progress);
803} 803}
804
805#undef PRF