Add LZMA_RET_INTERNAL1..8 to lzma_ret and use one for LZMA_TIMED_OUT.

LZMA_TIMED_OUT is *internally* used as a value for lzma_ret
enumeration. Previously it was #defined to 32 and cast to lzma_ret.
That way it wasn't visible in the public API, but this was hackish.

Now the public API has eight LZMA_RET_INTERNALx members and
LZMA_TIMED_OUT is #defined to LZMA_RET_INTERNAL1. This way
the code is cleaner overall although the public API has a few
extra mysterious enum members.
This commit is contained in:
Lasse Collin 2019-06-24 23:25:41 +03:00
parent 159c43875e
commit 1b4675cebf
4 changed files with 25 additions and 7 deletions

View File

@ -235,7 +235,7 @@ typedef enum {
* how to report bugs. * how to report bugs.
*/ */
LZMA_SEEK_NEEDED = 12 LZMA_SEEK_NEEDED = 12,
/**< /**<
* \brief Request to change the input file position * \brief Request to change the input file position
* *
@ -251,6 +251,19 @@ typedef enum {
* After seeking the application should read new input and * After seeking the application should read new input and
* pass it normally via lzma_stream.next_in and .avail_in. * pass it normally via lzma_stream.next_in and .avail_in.
*/ */
/*
* These eumerations may be used internally by liblzma
* but they will never be returned to applications.
*/
LZMA_RET_INTERNAL1 = 101,
LZMA_RET_INTERNAL2 = 102,
LZMA_RET_INTERNAL3 = 103,
LZMA_RET_INTERNAL4 = 104,
LZMA_RET_INTERNAL5 = 105,
LZMA_RET_INTERNAL6 = 106,
LZMA_RET_INTERNAL7 = 107,
LZMA_RET_INTERNAL8 = 108
} lzma_ret; } lzma_ret;

View File

@ -298,9 +298,7 @@ lzma_code(lzma_stream *strm, lzma_action action)
strm->internal->avail_in = strm->avail_in; strm->internal->avail_in = strm->avail_in;
// Cast is needed to silence a warning about LZMA_TIMED_OUT, which switch (ret) {
// isn't part of lzma_ret enumeration.
switch ((unsigned int)(ret)) {
case LZMA_OK: case LZMA_OK:
// Don't return LZMA_BUF_ERROR when it happens the first time. // Don't return LZMA_BUF_ERROR when it happens the first time.
// This is to avoid returning LZMA_BUF_ERROR when avail_out // This is to avoid returning LZMA_BUF_ERROR when avail_out

View File

@ -83,9 +83,8 @@
/// Special return value (lzma_ret) to indicate that a timeout was reached /// Special return value (lzma_ret) to indicate that a timeout was reached
/// and lzma_code() must not return LZMA_BUF_ERROR. This is converted to /// and lzma_code() must not return LZMA_BUF_ERROR. This is converted to
/// LZMA_OK in lzma_code(). This is not in the lzma_ret enumeration because /// LZMA_OK in lzma_code().
/// there's no need to have it in the public API. #define LZMA_TIMED_OUT LZMA_RET_INTERNAL1
#define LZMA_TIMED_OUT 32
typedef struct lzma_next_coder_s lzma_next_coder; typedef struct lzma_next_coder_s lzma_next_coder;

View File

@ -833,6 +833,14 @@ message_strm(lzma_ret code)
case LZMA_GET_CHECK: case LZMA_GET_CHECK:
case LZMA_PROG_ERROR: case LZMA_PROG_ERROR:
case LZMA_SEEK_NEEDED: case LZMA_SEEK_NEEDED:
case LZMA_RET_INTERNAL1:
case LZMA_RET_INTERNAL2:
case LZMA_RET_INTERNAL3:
case LZMA_RET_INTERNAL4:
case LZMA_RET_INTERNAL5:
case LZMA_RET_INTERNAL6:
case LZMA_RET_INTERNAL7:
case LZMA_RET_INTERNAL8:
// Without "default", compiler will warn if new constants // Without "default", compiler will warn if new constants
// are added to lzma_ret, it is not too easy to forget to // are added to lzma_ret, it is not too easy to forget to
// add the new constants to this function. // add the new constants to this function.