forked from premiere/premiere-libtorrent
add workaround for GCC bug in MingW (broken support for PVOID64) and improve resiliency of storage
This commit is contained in:
parent
5f98dec91b
commit
4deafb5e29
12
src/file.cpp
12
src/file.cpp
|
@ -1503,6 +1503,12 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
int num_pages = (size + m_page_size - 1) / m_page_size;
|
||||
// allocate array of FILE_SEGMENT_ELEMENT for ReadFileScatter
|
||||
FILE_SEGMENT_ELEMENT* segment_array = TORRENT_ALLOCA(FILE_SEGMENT_ELEMENT, num_pages + 1);
|
||||
#ifdef __GNUC__
|
||||
// MingW seems to have issues with 64 bit wide pointers
|
||||
// (PVOID64) and only assign the low 32 bits. Therefore, make
|
||||
// sure the other 32 bits are cleared out
|
||||
memset(segment_array, 0, (num_pages + 1) * sizeof(FILE_SEGMENT_ELEMENT));
|
||||
#endif
|
||||
FILE_SEGMENT_ELEMENT* cur_seg = segment_array;
|
||||
|
||||
for (file::iovec_t const* i = bufs, *end(bufs + num_bufs); i < end; ++i)
|
||||
|
@ -1738,6 +1744,12 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
int num_pages = (size + m_page_size - 1) / m_page_size;
|
||||
// allocate array of FILE_SEGMENT_ELEMENT for WriteFileGather
|
||||
FILE_SEGMENT_ELEMENT* segment_array = TORRENT_ALLOCA(FILE_SEGMENT_ELEMENT, num_pages + 1);
|
||||
#ifdef __GNUC__
|
||||
// MingW seems to have issues with 64 bit wide pointers
|
||||
// (PVOID64) and only assign the low 32 bits. Therefore, make
|
||||
// sure the other 32 bits are cleared out
|
||||
memset(segment_array, 0, (num_pages + 1) * sizeof(FILE_SEGMENT_ELEMENT));
|
||||
#endif
|
||||
FILE_SEGMENT_ELEMENT* cur_seg = segment_array;
|
||||
|
||||
for (file::iovec_t const* i = bufs, *end(bufs + num_bufs); i < end; ++i)
|
||||
|
|
|
@ -1640,7 +1640,7 @@ ret:
|
|||
j.cache_min_time = cache_expiry;
|
||||
TORRENT_ASSERT(r.length <= 16 * 1024);
|
||||
m_io_thread.add_job(j, handler);
|
||||
#ifdef TORRENT_DEBUG
|
||||
#ifdef TORRENT_USE_ASSERTS
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
// if this assert is hit, it suggests
|
||||
// that check_files was not successful
|
||||
|
@ -1683,7 +1683,7 @@ ret:
|
|||
// since that is the size of the pool allocator's buffers
|
||||
TORRENT_ASSERT(r.length <= 16 * 1024);
|
||||
m_io_thread.add_job(j, handler);
|
||||
#ifdef TORRENT_DEBUG
|
||||
#ifdef TORRENT_USE_ASSERTS
|
||||
mutex::scoped_lock l(m_mutex);
|
||||
// if this assert is hit, it suggests
|
||||
// that check_files was not successful
|
||||
|
@ -1745,6 +1745,7 @@ ret:
|
|||
|
||||
int slot = slot_for(piece);
|
||||
TORRENT_ASSERT(slot != has_no_slot);
|
||||
if (slot < 0) return sha1_hash(0);
|
||||
int read = hash_for_slot(slot, ph, m_files.piece_size(piece));
|
||||
if (readback) *readback = read;
|
||||
if (m_storage->error()) return sha1_hash(0);
|
||||
|
@ -1829,6 +1830,8 @@ ret:
|
|||
TORRENT_ASSERT(num_bufs > 0);
|
||||
m_last_piece = piece_index;
|
||||
int slot = slot_for(piece_index);
|
||||
TORRENT_ASSERT(slot >= 0);
|
||||
if (slot < 0) return 0;
|
||||
return m_storage->readv(bufs, slot, offset, num_bufs);
|
||||
}
|
||||
|
||||
|
@ -1870,7 +1873,7 @@ ret:
|
|||
std::map<int, partial_hash>::iterator i = m_piece_hasher.find(piece_index);
|
||||
if (i != m_piece_hasher.end())
|
||||
{
|
||||
#ifdef TORRENT_DEBUG
|
||||
#ifdef TORRENT_USE_ASSERTS
|
||||
TORRENT_ASSERT(i->second.offset > 0);
|
||||
int hash_offset = i->second.offset;
|
||||
TORRENT_ASSERT(offset >= hash_offset);
|
||||
|
|
Loading…
Reference in New Issue