diff options
| author | Mike Buland <mike@xagasoft.com> | 2024-10-01 11:21:13 -0700 |
|---|---|---|
| committer | Mike Buland <mike@xagasoft.com> | 2024-10-01 11:21:13 -0700 |
| commit | 00651aeaf50f8481a2c894f9462cd3b8eb6971d6 (patch) | |
| tree | 72630f5c1918e8188b92e6f93f0122dbea8022d1 /src/stable | |
| parent | 373b8f42902686ea1181b1edd8c2c06555cad8fd (diff) | |
| download | libbu++-00651aeaf50f8481a2c894f9462cd3b8eb6971d6.tar.gz libbu++-00651aeaf50f8481a2c894f9462cd3b8eb6971d6.tar.bz2 libbu++-00651aeaf50f8481a2c894f9462cd3b8eb6971d6.tar.xz libbu++-00651aeaf50f8481a2c894f9462cd3b8eb6971d6.zip | |
More myriad fixes, it passes all existing unit tests.
Diffstat (limited to '')
| -rw-r--r-- | src/stable/myriad.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp index 85daa0d..f9fcd3e 100644 --- a/src/stable/myriad.cpp +++ b/src/stable/myriad.cpp | |||
| @@ -12,13 +12,13 @@ | |||
| 12 | #define MyriadRead( target, size ) if( rBacking.read( target, size ) < size ) \ | 12 | #define MyriadRead( target, size ) if( rBacking.read( target, size ) < size ) \ |
| 13 | { \ | 13 | { \ |
| 14 | throw Bu::MyriadException( Bu::MyriadException::invalidFormat, \ | 14 | throw Bu::MyriadException( Bu::MyriadException::invalidFormat, \ |
| 15 | "Insufficent data reading myriad data from backing stream."); \ | 15 | "Insufficient data reading myriad data from backing stream."); \ |
| 16 | } (void)0 | 16 | } (void)0 |
| 17 | 17 | ||
| 18 | #define ReqRead( stream, target, size ) if( stream.read( target, size ) < size ) \ | 18 | #define ReqRead( stream, target, size ) if( stream.read( target, size ) < size ) \ |
| 19 | { \ | 19 | { \ |
| 20 | throw Bu::MyriadException( Bu::MyriadException::invalidFormat, \ | 20 | throw Bu::MyriadException( Bu::MyriadException::invalidFormat, \ |
| 21 | "Insufficent data reading from myriad stream."); \ | 21 | "Insufficient data reading from myriad stream."); \ |
| 22 | } (void)0 | 22 | } (void)0 |
| 23 | 23 | ||
| 24 | namespace Bu | 24 | namespace Bu |
| @@ -112,7 +112,7 @@ Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, | |||
| 112 | } | 112 | } |
| 113 | { | 113 | { |
| 114 | Bu::MutexLocker l2( mBacking ); | 114 | Bu::MutexLocker l2( mBacking ); |
| 115 | if( (eMode&Write) && rBacking.isWritable() ) | 115 | if( (eMode&Write) && !rBacking.isWritable() ) |
| 116 | { | 116 | { |
| 117 | throw Bu::MyriadException( MyriadException::badMode, | 117 | throw Bu::MyriadException( MyriadException::badMode, |
| 118 | "Backing stream does not support writing."); | 118 | "Backing stream does not support writing."); |
| @@ -398,6 +398,8 @@ bool Bu::Myriad::loadMyriad() | |||
| 398 | 398 | ||
| 399 | lFreeBlocks = hUnusedBlocks.getKeys(); | 399 | lFreeBlocks = hUnusedBlocks.getKeys(); |
| 400 | //Bu::println("Free blocks: %1").arg( lFreeBlocks.getSize() ); | 400 | //Bu::println("Free blocks: %1").arg( lFreeBlocks.getSize() ); |
| 401 | |||
| 402 | bIsNewStream = false; | ||
| 401 | 403 | ||
| 402 | return true; | 404 | return true; |
| 403 | } | 405 | } |
| @@ -434,14 +436,11 @@ void Bu::Myriad::createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks ) | |||
| 434 | //Bu::println(" Adjustment: %1 bytes / %2 cur blocks, %3 computed blocks (%4 target bytes).").arg( iHeaderStreamBytes+(iHeaderStreamBlocks*4) ).arg( iHeaderStreamBlocks ).arg( blkDiv((iHeaderStreamBytes+(iHeaderStreamBlocks*4)), iBlockSize) ).arg( iHeaderStreamBlocks*iBlockSize ); | 436 | //Bu::println(" Adjustment: %1 bytes / %2 cur blocks, %3 computed blocks (%4 target bytes).").arg( iHeaderStreamBytes+(iHeaderStreamBlocks*4) ).arg( iHeaderStreamBlocks ).arg( blkDiv((iHeaderStreamBytes+(iHeaderStreamBlocks*4)), iBlockSize) ).arg( iHeaderStreamBlocks*iBlockSize ); |
| 435 | } | 437 | } |
| 436 | 438 | ||
| 437 | if( iPreallocateBlocks > iHeaderStreamBlocks ) | 439 | if( iPreallocateBlocks < iHeaderStreamBlocks ) |
| 438 | { | 440 | { |
| 439 | rBacking.setSize( iBlockSize*iPreallocateBlocks ); | 441 | iPreallocateBlocks = iHeaderStreamBlocks; |
| 440 | } | ||
| 441 | else | ||
| 442 | { | ||
| 443 | rBacking.setSize( iBlockSize*iHeaderStreamBlocks ); | ||
| 444 | } | 442 | } |
| 443 | rBacking.setSize( iBlockSize*iPreallocateBlocks ); | ||
| 445 | 444 | ||
| 446 | // | 445 | // |
| 447 | // Write Myriad header | 446 | // Write Myriad header |
| @@ -540,14 +539,15 @@ void Bu::Myriad::writeHeader() | |||
| 540 | uint32_t uStreamSize = pStream->getSize(); | 539 | uint32_t uStreamSize = pStream->getSize(); |
| 541 | mbHeader.write( &uStreamId, 4 ); | 540 | mbHeader.write( &uStreamId, 4 ); |
| 542 | mbHeader.write( &uStreamSize, 4 ); | 541 | mbHeader.write( &uStreamSize, 4 ); |
| 542 | int32_t iBlocks = Bu::blkDiv( uStreamSize, (uint32_t)iBlockSize ); | ||
| 543 | Bu::Array<int32_t> aBlocks = pStream->getBlockList(); | 543 | Bu::Array<int32_t> aBlocks = pStream->getBlockList(); |
| 544 | 544 | ||
| 545 | //Bu::println(" Stream %1 is %2 bytes %3 blocks (%4 blocks computed)").arg( *i ).arg( uStreamSize ).arg( aBlocks.getSize() ).arg( Bu::blkDiv( (int)uStreamSize, (int)iBlockSize ) ); | 545 | //Bu::println(" Stream %1 is %2 bytes %3 blocks (%4 blocks computed)").arg( *i ).arg( uStreamSize ).arg( aBlocks.getSize() ).arg( Bu::blkDiv( (int)uStreamSize, (int)iBlockSize ) ); |
| 546 | 546 | ||
| 547 | for( Bu::Array<int32_t>::iterator i = aBlocks.begin(); i; i++ ) | 547 | // for( Bu::Array<int32_t>::iterator i = aBlocks.begin(); i; i++ ) |
| 548 | for( int j = 0; j < iBlocks; j++ ) | ||
| 548 | { | 549 | { |
| 549 | int32_t iIdx = *i; | 550 | mbHeader.write( &aBlocks[j], 4 ); |
| 550 | mbHeader.write( &iIdx, 4 ); | ||
| 551 | } | 551 | } |
| 552 | } | 552 | } |
| 553 | 553 | ||
| @@ -768,7 +768,7 @@ int32_t Bu::Myriad::Stream::read( int32_t iStart, void *pTarget, | |||
| 768 | 768 | ||
| 769 | if( iStart+iSize >= this->iSize ) | 769 | if( iStart+iSize >= this->iSize ) |
| 770 | { | 770 | { |
| 771 | int32_t iDiff = this->iSize-(iStart+iSize); | 771 | int32_t iDiff = (iStart+iSize)-this->iSize; |
| 772 | iSize -= iDiff; | 772 | iSize -= iDiff; |
| 773 | iStart += iDiff; | 773 | iStart += iDiff; |
| 774 | } | 774 | } |
