Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/archival/libarchive/decompress_unlzma.c

    r3232 r3621  
    4646
    4747
    48 /* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
    49 static size_inline void rc_read(rc_t *rc)
     48/* Called once in rc_do_normalize() */
     49static void rc_read(rc_t *rc)
    5050{
    5151    int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
     
    5454    if (buffer_size <= 0)
    5555        bb_error_msg_and_die("unexpected EOF");
     56    rc->buffer_end = RC_BUFFER + buffer_size;
    5657    rc->ptr = RC_BUFFER;
    57     rc->buffer_end = RC_BUFFER + buffer_size;
    5858}
    5959
     
    6666    rc->code = (rc->code << 8) | *rc->ptr++;
    6767}
     68static ALWAYS_INLINE void rc_normalize(rc_t *rc)
     69{
     70    if (rc->range < (1 << RC_TOP_BITS)) {
     71        rc_do_normalize(rc);
     72    }
     73}
    6874
    6975/* Called once */
     
    7985
    8086    for (i = 0; i < 5; i++) {
    81 #if ENABLE_FEATURE_LZMA_FAST
    82         if (rc->ptr >= rc->buffer_end)
    83             rc_read(rc);
    84         rc->code = (rc->code << 8) | *rc->ptr++;
    85 #else
    8687        rc_do_normalize(rc);
    87 #endif
    88     }
    89     rc->range = 0xFFFFFFFF;
     88    }
     89    rc->range = 0xffffffff;
    9090    return rc;
    9191}
     
    9595{
    9696    free(rc);
    97 }
    98 
    99 static ALWAYS_INLINE void rc_normalize(rc_t *rc)
    100 {
    101     if (rc->range < (1 << RC_TOP_BITS)) {
    102         rc_do_normalize(rc);
    103     }
    10497}
    10598
     
    121114
    122115/* Called 4 times in unlzma loop */
    123 static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
     116static ALWAYS_INLINE int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
    124117{
    125118    int ret = rc_is_bit_1(rc, p);
     
    214207
    215208IF_DESKTOP(long long) int FAST_FUNC
    216 unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
     209unpack_lzma_stream(transformer_state_t *xstate)
    217210{
    218211    IF_DESKTOP(long long total_written = 0;)
     
    222215    uint32_t literal_pos_mask;
    223216    uint16_t *p;
    224     int num_bits;
    225     int num_probs;
    226217    rc_t *rc;
    227218    int i;
     
    233224    uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
    234225
    235     if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
     226    if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
    236227     || header.pos >= (9 * 5 * 5)
    237228    ) {
     
    247238    literal_pos_mask = (1 << lp) - 1;
    248239
     240    /* Example values from linux-3.3.4.tar.lzma:
     241     * dict_size: 64M, dst_size: 2^64-1
     242     */
    249243    header.dict_size = SWAP_LE32(header.dict_size);
    250244    header.dst_size = SWAP_LE64(header.dst_size);
     
    255249    buffer = xmalloc(MIN(header.dst_size, header.dict_size));
    256250
    257     num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
    258     p = xmalloc(num_probs * sizeof(*p));
    259     num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
    260     for (i = 0; i < num_probs; i++)
    261         p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
    262 
    263     rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
     251    {
     252        int num_probs;
     253
     254        num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
     255        p = xmalloc(num_probs * sizeof(*p));
     256        num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
     257        for (i = 0; i < num_probs; i++)
     258            p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
     259    }
     260
     261    rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */
    264262
    265263    while (global_pos + buffer_pos < header.dst_size) {
     
    309307                buffer_pos = 0;
    310308                global_pos += header.dict_size;
    311                 if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
     309                if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
    312310                    goto bad;
    313311                IF_DESKTOP(total_written += header.dict_size;)
     
    318316#endif
    319317        } else {
     318            int num_bits;
    320319            int offset;
    321320            uint16_t *prob2;
     
    442441                    buffer_pos = 0;
    443442                    global_pos += header.dict_size;
    444                     if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
     443                    if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
    445444                        goto bad;
    446445                    IF_DESKTOP(total_written += header.dict_size;)
     
    448447                len--;
    449448            } while (len != 0 && buffer_pos < header.dst_size);
     449            /* FIXME: ...........^^^^^
     450             * shouldn't it be "global_pos + buffer_pos < header.dst_size"?
     451             */
    450452        }
    451453    }
     
    454456        IF_NOT_DESKTOP(int total_written = 0; /* success */)
    455457        IF_DESKTOP(total_written += buffer_pos;)
    456         if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
     458        if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
    457459 bad:
    458460            total_written = -1; /* failure */
Note: See TracChangeset for help on using the changeset viewer.