chromium/third_party/lzma_sdk/C/LzmaDec.c

/* LzmaDec.c -- LZMA Decoder
2021-04-01 : Igor Pavlov : Public domain */

#include "Precomp.h"

#include <string.h>

/* #include "CpuArch.h" */
#include "LzmaDec.h"

#define kNumTopBits
#define kTopValue

#define kNumBitModelTotalBits
#define kBitModelTotal

#define RC_INIT_SIZE

#ifndef _LZMA_DEC_OPT

#define kNumMoveBits
#define NORMALIZE

#define IF_BIT_0(p)
#define UPDATE_0(p)
#define UPDATE_1(p)
#define GET_BIT2(p, i, A0, A1)

#define TREE_GET_BIT(probs, i)

#define REV_BIT(p, i, A0, A1)
#define REV_BIT_VAR(  p, i, m)
#define REV_BIT_CONST(p, i, m)
#define REV_BIT_LAST( p, i, m)

#define TREE_DECODE(probs, limit, i)

/* #define _LZMA_SIZE_OPT */

#ifdef _LZMA_SIZE_OPT
#define TREE_6_DECODE
#else
#define TREE_6_DECODE(probs, i)
#endif

#define NORMAL_LITER_DEC
#define MATCHED_LITER_DEC

#endif // _LZMA_DEC_OPT


#define NORMALIZE_CHECK

#define IF_BIT_0_CHECK(p)
#define UPDATE_0_CHECK
#define UPDATE_1_CHECK
#define GET_BIT2_CHECK(p, i, A0, A1)
#define GET_BIT_CHECK(p, i)
#define TREE_DECODE_CHECK(probs, limit, i)


#define REV_BIT_CHECK(p, i, m)


#define kNumPosBitsMax
#define kNumPosStatesMax

#define kLenNumLowBits
#define kLenNumLowSymbols
#define kLenNumHighBits
#define kLenNumHighSymbols

#define LenLow
#define LenHigh
#define kNumLenProbs

#define LenChoice
#define LenChoice2

#define kNumStates
#define kNumStates2
#define kNumLitStates

#define kStartPosModelIndex
#define kEndPosModelIndex
#define kNumFullDistances

#define kNumPosSlotBits
#define kNumLenToPosStates

#define kNumAlignBits
#define kAlignTableSize

#define kMatchMinLen
#define kMatchSpecLenStart

#define kMatchSpecLen_Error_Data
#define kMatchSpecLen_Error_Fail

/* External ASM code needs same CLzmaProb array layout. So don't change it. */

/* (probs_1664) is faster and better for code size at some platforms */
/*
#ifdef MY_CPU_X86_OR_AMD64
*/
#define kStartOffset
#define GET_PROBS
/*
#define GET_PROBS p->probs + kStartOffset
#else
#define kStartOffset 0
#define GET_PROBS p->probs
#endif
*/

#define SpecPos
#define IsRep0Long
#define RepLenCoder
#define LenCoder
#define IsMatch
#define Align
#define IsRep
#define IsRepG0
#define IsRepG1
#define IsRepG2
#define PosSlot
#define Literal
#define NUM_BASE_PROBS

#if Align != 0 && kStartOffset != 0
  #error Stop_Compiling_Bad_LZMA_kAlign
#endif

#if NUM_BASE_PROBS != 1984
  #error Stop_Compiling_Bad_LZMA_PROBS
#endif


#define LZMA_LIT_SIZE

#define LzmaProps_GetNumProbs(p)


#define CALC_POS_STATE(processedPos, pbMask)
#define COMBINED_PS_STATE
#define GET_LEN_STATE

#define LZMA_DIC_MIN

/*
p->remainLen : shows status of LZMA decoder:
    < kMatchSpecLenStart  : the number of bytes to be copied with (p->rep0) offset
    = kMatchSpecLenStart  : the LZMA stream was finished with end mark
    = kMatchSpecLenStart + 1  : need init range coder
    = kMatchSpecLenStart + 2  : need init range coder and state
    = kMatchSpecLen_Error_Fail                : Internal Code Failure
    = kMatchSpecLen_Error_Data + [0 ... 273]  : LZMA Data Error
*/

/* ---------- LZMA_DECODE_REAL ---------- */
/*
LzmaDec_DecodeReal_3() can be implemented in external ASM file.
3 - is the code compatibility version of that function for check at link time.
*/

#define LZMA_DECODE_REAL

/*
LZMA_DECODE_REAL()
In:
  RangeCoder is normalized
  if (p->dicPos == limit)
  {
    LzmaDec_TryDummy() was called before to exclude LITERAL and MATCH-REP cases.
    So first symbol can be only MATCH-NON-REP. And if that MATCH-NON-REP symbol
    is not END_OF_PAYALOAD_MARKER, then the function doesn't write any byte to dictionary,
    the function returns SZ_OK, and the caller can use (p->remainLen) and (p->reps[0]) later.
  }

Processing:
  The first LZMA symbol will be decoded in any case.
  All main checks for limits are at the end of main loop,
  It decodes additional LZMA-symbols while (p->buf < bufLimit && dicPos < limit),
  RangeCoder is still without last normalization when (p->buf < bufLimit) is being checked.
  But if (p->buf < bufLimit), the caller provided at least (LZMA_REQUIRED_INPUT_MAX + 1) bytes for
  next iteration  before limit (bufLimit + LZMA_REQUIRED_INPUT_MAX),
  that is enough for worst case LZMA symbol with one additional RangeCoder normalization for one bit.
  So that function never reads bufLimit [LZMA_REQUIRED_INPUT_MAX] byte.

Out:
  RangeCoder is normalized
  Result:
    SZ_OK - OK
      p->remainLen:
        < kMatchSpecLenStart : the number of bytes to be copied with (p->reps[0]) offset
        = kMatchSpecLenStart : the LZMA stream was finished with end mark

    SZ_ERROR_DATA - error, when the MATCH-Symbol refers out of dictionary
      p->remainLen : undefined
      p->reps[*]    : undefined
*/


#ifdef _LZMA_DEC_OPT

int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit);

#else

static
int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
{}
#endif



static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
{}


/*
At staring of new stream we have one of the following symbols:
  - Literal        - is allowed
  - Non-Rep-Match  - is allowed only if it's end marker symbol
  - Rep-Match      - is not allowed
We use early check of (RangeCoder:Code) over kBadRepCode to simplify main decoding code
*/

#define kRange0
#define kBound0
#define kBadRepCode
#if kBadRepCode != (0xC0000000 - 0x400)
  #error Stop_Compiling_Bad_LZMA_Check
#endif


/*
LzmaDec_DecodeReal2():
  It calls LZMA_DECODE_REAL() and it adjusts limit according (p->checkDicSize).

We correct (p->checkDicSize) after LZMA_DECODE_REAL() and in LzmaDec_WriteRem(),
and we support the following state of (p->checkDicSize):
  if (total_processed < p->prop.dicSize) then
  {
    (total_processed == p->processedPos)
    (p->checkDicSize == 0)
  }
  else
    (p->checkDicSize == p->prop.dicSize)
*/

static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
{}



ELzmaDummy;


#define IS_DUMMY_END_MARKER_POSSIBLE(dummyRes)

static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, const Byte **bufOut)
{}

void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState);
void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState)
{}

void LzmaDec_Init(CLzmaDec *p)
{}


/*
LZMA supports optional end_marker.
So the decoder can lookahead for one additional LZMA-Symbol to check end_marker.
That additional LZMA-Symbol can require up to LZMA_REQUIRED_INPUT_MAX bytes in input stream.
When the decoder reaches dicLimit, it looks (finishMode) parameter:
  if (finishMode == LZMA_FINISH_ANY), the decoder doesn't lookahead
  if (finishMode != LZMA_FINISH_ANY), the decoder lookahead, if end_marker is possible for current position

When the decoder lookahead, and the lookahead symbol is not end_marker, we have two ways:
  1) Strict mode (default) : the decoder returns SZ_ERROR_DATA.
  2) The relaxed mode (alternative mode) : we could return SZ_OK, and the caller
     must check (status) value. The caller can show the error,
     if the end of stream is expected, and the (status) is noit
     LZMA_STATUS_FINISHED_WITH_MARK or LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK.
*/


#define RETURN__NOT_FINISHED__FOR_FINISH
  // return SZ_OK; // for relaxed mode


SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
    ELzmaFinishMode finishMode, ELzmaStatus *status)
{}



SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{}

void LzmaDec_FreeProbs(CLzmaDec *p, ISzAllocPtr alloc)
{}

static void LzmaDec_FreeDict(CLzmaDec *p, ISzAllocPtr alloc)
{}

void LzmaDec_Free(CLzmaDec *p, ISzAllocPtr alloc)
{}

SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
{}

static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAllocPtr alloc)
{}

SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
{}

SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
{}

SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
    ELzmaStatus *status, ISzAllocPtr alloc)
{}