Ignore:
Timestamp:
Mar 28, 2011, 4:31:05 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) break the mac build and introduce new crashes.

This is partially to address #4145 "Downloads stuck at 100%" by refactoring the bitset, bitfield, and tr_completion; however, the ripple effect is larger than usual so things may get worse in the short term before getting better.

livings124: to fix the mac build, remove bitset.[ch] from xcode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/resume.c

    r12204 r12248  
    1717#include "transmission.h"
    1818#include "bencode.h"
    19 #include "bitset.h"
    2019#include "completion.h"
    2120#include "metainfo.h" /* tr_metainfoGetBasename() */
     
    410409
    411410static void
     411bitfieldToBenc( const tr_bitfield * b, tr_benc * benc )
     412{
     413    if( tr_bitfieldHasAll( b ) )
     414        tr_bencInitStr( benc, "all", 3 );
     415    else if( tr_bitfieldHasNone( b ) )
     416        tr_bencInitStr( benc, "none", 4 );
     417    else
     418        tr_bencInitRaw( benc, b->bits, b->byte_count );
     419}
     420
     421
     422static void
    412423saveProgress( tr_benc * dict, tr_torrent * tor )
    413424{
     
    470481
    471482    /* add the blocks bitfield */
    472     tr_bitsetToBenc( tr_cpBlockBitset( &tor->completion ),
    473                      tr_bencDictAdd( prog, KEY_PROGRESS_BLOCKS ) );
     483    bitfieldToBenc( &tor->completion.blockBitfield,
     484                    tr_bencDictAdd( prog, KEY_PROGRESS_BLOCKS ) );
    474485}
    475486
     
    493504        tr_benc * l;
    494505        tr_benc * b;
    495         struct tr_bitset bitset = TR_BITSET_INIT;
     506        struct tr_bitfield blocks = TR_BITFIELD_INIT;
    496507
    497508        if( tr_bencDictFindList( prog, KEY_PROGRESS_CHECKTIME, &l ) )
     
    568579
    569580        err = NULL;
     581        tr_bitfieldConstruct( &blocks, tor->blockCount );
    570582
    571583        if(( b = tr_bencDictFind( prog, KEY_PROGRESS_BLOCKS )))
    572584        {
    573             if( !tr_bitsetFromBenc( &bitset, b ) )
    574                 err = "Invalid value for PIECES";
     585            size_t buflen;
     586            const uint8_t * buf;
     587
     588            if( !tr_bencGetRaw( b, &buf, &buflen ) )
     589                err = "Invalid value for \"blocks\"";
     590            else if( ( buflen == 3 ) && !memcmp( buf, "all", 3 ) )
     591                tr_bitfieldSetHasAll( &blocks );
     592            else if( ( buflen == 4 ) && !memcmp( buf, "none", 4 ) )
     593                tr_bitfieldSetHasNone( &blocks );
     594            else
     595                tr_bitfieldSetRaw( &blocks, buf, buflen );
    575596        }
    576597        else if( tr_bencDictFindStr( prog, KEY_PROGRESS_HAVE, &str ) )
    577598        {
    578599            if( !strcmp( str, "all" ) )
    579                 tr_bitsetSetHaveAll( &bitset );
     600                tr_bitfieldSetHasAll( &blocks );
    580601            else
    581602                err = "Invalid value for HAVE";
     
    583604        else if( tr_bencDictFindRaw( prog, KEY_PROGRESS_BITFIELD, &raw, &rawlen ) )
    584605        {
    585             bitset.bitfield.bits = (void*) raw;
    586             bitset.bitfield.byteCount = rawlen;
    587             bitset.bitfield.bitCount = rawlen * 8;
     606            tr_bitfieldSetRaw( &blocks, raw, rawlen );
    588607        }
    589608        else err = "Couldn't find 'pieces' or 'have' or 'bitfield'";
    590609
    591         if( !err && !tr_cpBlockBitsetInit( &tor->completion, &bitset ) )
     610        if( !err && !tr_cpBlockInit( &tor->completion, &blocks ) )
    592611            err = "Error loading bitfield";
    593612        if( err != NULL )
    594613            tr_tordbg( tor, "Torrent needs to be verified - %s", err );
    595614
     615        tr_bitfieldDestruct( &blocks );
    596616        ret = TR_FR_PROGRESS;
    597617    }
Note: See TracChangeset for help on using the changeset viewer.