diff --git a/ChangeLog.txt b/ChangeLog.txt index 6e09770989..a6a86c1002 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,14 @@ Entries may not always be in chronological/commit order. See license at the end of file. */ +2023-01-23 12:46 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * include/harbour.hbx + ! added missing hb_socketSetNoSigPipe() + + * src/rdd/dbfcdx/dbfcdx1.c + * redirect all debug output to stderr + * reenabled light debug code for early detection of index corruption + 2023-01-23 12:28 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/gtqtc/gtqtc.h * contrib/gtqtc/gtqtc1.cpp diff --git a/include/harbour.hbx b/include/harbour.hbx index 764d17495e..4c4c8950e1 100644 --- a/include/harbour.hbx +++ b/include/harbour.hbx @@ -849,6 +849,7 @@ DYNAMIC hb_socketSetFilter DYNAMIC hb_socketSetKeepAlive DYNAMIC hb_socketSetMulticast DYNAMIC hb_socketSetNoDelay +DYNAMIC hb_socketSetNoSigPipe DYNAMIC hb_socketSetRcvBufSize DYNAMIC hb_socketSetReuseAddr DYNAMIC hb_socketSetSndBufSize diff --git a/src/rdd/dbfcdx/dbfcdx1.c b/src/rdd/dbfcdx/dbfcdx1.c index 519c316e77..b745bcb5fc 100644 --- a/src/rdd/dbfcdx/dbfcdx1.c +++ b/src/rdd/dbfcdx/dbfcdx1.c @@ -54,8 +54,8 @@ # define HB_CDX_PACKTRAIL #endif -/* #define HB_CDX_DBGCODE +/* #define HB_CDX_DBGCODE_EXT #define HB_CDX_DSPDBG_INFO #define HB_CDX_DBGTIME @@ -130,19 +130,19 @@ static void hb_cdxDspTags( LPCDXINDEX pIndex ) { LPCDXTAG pTag = NULL; - printf( "\r\n*TAGS*" ); + fprintf( stderr, "\r\n*TAGS*" ); while( pIndex ) { - printf( "\r\nBAG: [%s] ->", pIndex->szFileName ); + fprintf( stderr, "\r\nBAG: [%s] ->", pIndex->szFileName ); pTag = pIndex->TagList; while( pTag ) { - printf( " {%s}", pTag->szName ); + fprintf( stderr, " {%s}", pTag->szName ); pTag = pTag->pNext; } pIndex = pIndex->pNext; } - printf( "\r\n*END*\r\n" ); fflush( stdout ); + fprintf( stderr, "\r\n*END*\r\n" ); fflush( stderr ); } #endif @@ -1494,7 +1494,7 @@ static HB_BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, int iKey ) #ifdef HB_CDX_DBGCODE else if( iTmp < 0 ) { - printf( "\r\npPage->Page=%lx, iLen=%d, iDup=%d, iTrl=%d", pPage->Page, iLen, iDup, iTrl ); fflush( stdout ); + fprintf( stderr, "\r\npPage->Page=%lx, iLen=%d, iDup=%d, iTrl=%d", pPage->Page, iLen, iDup, iTrl ); fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageGetKeyVal: index corrupted." ); } #endif @@ -1503,7 +1503,7 @@ static HB_BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, int iKey ) pPage->bufKeyLen = ( HB_SHORT ) ( iLen - iTrl ); pPage->bufKeyNum++; #if 0 - printf( "\r\npPage->Page=%lx, iKey=%d, iLen=%d, iDup=%d, iTrl=%d, ulRec=%d, val[%s]", pPage->Page, pPage->bufKeyNum - 1, iLen, iDup, iTrl, HB_GET_LE_UINT32( &hb_cdxPageExtKeyPool( pPage )[ iPos ] ), pKeyVal ); fflush( stdout ); + fprintf( stderr, "\r\npPage->Page=%lx, iKey=%d, iLen=%d, iDup=%d, iTrl=%d, ulRec=%d, val[%s]", pPage->Page, pPage->bufKeyNum - 1, iLen, iDup, iTrl, HB_GET_LE_UINT32( &hb_cdxPageExtKeyPool( pPage )[ iPos ] ), pKeyVal ); fflush( stderr ); #endif } return pKeyVal; @@ -1606,14 +1606,14 @@ static void hb_cdxPageCheckKeys( LPCDXPAGE pPage ) if( K > 0 || ( K == 0 && ulRecPrev >= ulRec ) ) { if( pPage->PageType & CDX_NODE_LEAF ) - printf( "\r\niFree=%d, ReqByte=%d, RNBits=%d, DCBits=%d, TCBits=%d", - pPage->iFree, pPage->ReqByte, pPage->RNBits, pPage->DCBits, pPage->TCBits ); - printf( "\r\nikey=%d, pPage->iKeys=%d, K=%d, ulRecPrev=%ld, ulRec=%ld", - i, pPage->iKeys, K, ulRecPrev, ulRec ); - printf( "\r\npbValPrev=[%s] pbVal=[%s], [%d], pPage->pKeyBuf=%p, pPage->iCurKey=%d", - pbValPrev, pbVal, memcmp( pbValPrev, pbVal, iLen ), - pPage->pKeyBuf, pPage->iCurKey ); - fflush( stdout ); + fprintf( stderr, "\r\niFree=%d, ReqByte=%d, RNBits=%d, DCBits=%d, TCBits=%d", + pPage->iFree, pPage->ReqByte, pPage->RNBits, pPage->DCBits, pPage->TCBits ); + fprintf( stderr, "\r\nikey=%d, pPage->iKeys=%d, K=%d, ulRecPrev=%ld, ulRec=%ld", + i, pPage->iKeys, K, ulRecPrev, ulRec ); + fprintf( stderr, "\r\npbValPrev=[%s] pbVal=[%s], [%d], pPage->pKeyBuf=%p, pPage->iCurKey=%d", + pbValPrev, pbVal, memcmp( pbValPrev, pbVal, iLen ), + pPage->pKeyBuf, pPage->iCurKey ); + fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageCheckKeys: index corrupted." ); } } @@ -1653,14 +1653,14 @@ static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys } if( iTrl != HB_GET_LE_UINT16( &pKeyBuf[ iPos + iNum + 6 ] ) ) { - printf( "\r\niTrl=%d, keybuf->iTrl=%d, iKey=%d/%d\r\n", iTrl, HB_GET_LE_UINT16( &pKeyBuf[ iPos + iNum + 6 ] ), iKey, iKeys ); - fflush( stdout ); + fprintf( stderr, "\r\niTrl=%d, keybuf->iTrl=%d, iKey=%d/%d\r\n", iTrl, HB_GET_LE_UINT16( &pKeyBuf[ iPos + iNum + 6 ] ), iKey, iKeys ); + fflush( stderr ); bErr = HB_TRUE; } if( iDup != ( iKey == 0 ? 0 : HB_GET_LE_UINT16( &pKeyBuf[ iPos + iNum + 4 ] ) ) ) { - printf( "\r\niDup=%d, keybuf->iDup=%d (iTrl=%d), iKey=%d/%d\r\n", iDup, HB_GET_LE_UINT16( &pKeyBuf[ iPos + iNum + 4 ] ), iTrl, iKey, iKeys ); - fflush( stdout ); + fprintf( stderr, "\r\niDup=%d, keybuf->iDup=%d (iTrl=%d), iKey=%d/%d\r\n", iDup, HB_GET_LE_UINT16( &pKeyBuf[ iPos + iNum + 4 ] ), iTrl, iKey, iKeys ); + fflush( stderr ); bErr = HB_TRUE; } if( iKey > 0 ) @@ -1673,15 +1673,15 @@ static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum - iLen ] ) >= HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum ] ) ) ) { - printf( "\r\nikey=%d, iKeys=%d, K=%d, ulRecPrev=%ld, ulRec=%ld", - iKey, iKeys, K, - ( HB_ULONG ) HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum - iLen ] ), - ( HB_ULONG ) HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum ] ) ); - printf( "\r\npbValPrev=[%s] pbVal=[%s], [%d], pKeyBuf=%p", - &pKeyBuf[ iPos - iLen ], &pKeyBuf[ iPos ], - memcmp( &pKeyBuf[ iPos - iLen ], &pKeyBuf[ iPos ], iNum ), - pKeyBuf ); - fflush( stdout ); + fprintf( stderr, "\r\nikey=%d, iKeys=%d, K=%d, ulRecPrev=%ld, ulRec=%ld", + iKey, iKeys, K, + ( HB_ULONG ) HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum - iLen ] ), + ( HB_ULONG ) HB_GET_LE_UINT32( &pKeyBuf[ iPos + iNum ] ) ); + fprintf( stderr, "\r\npbValPrev=[%s] pbVal=[%s], [%d], pKeyBuf=%p", + &pKeyBuf[ iPos - iLen ], &pKeyBuf[ iPos ], + memcmp( &pKeyBuf[ iPos - iLen ], &pKeyBuf[ iPos ], iNum ), + pKeyBuf ); + fflush( stderr ); bErr = HB_TRUE; } } @@ -1689,15 +1689,15 @@ static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys } if( fSpc && ( iFree != pPage->iFree /* || iFree < 0 */ ) ) { - printf( "\r\nFreeSpace calculated wrong! iFree=%d, pPage->iFree=%d, ReqByte=%d, RNBits=%d, DCBits=%d, TCBits=%d", - iFree, pPage->iFree, pPage->ReqByte, pPage->RNBits, pPage->DCBits, pPage->TCBits ); - fflush( stdout ); + fprintf( stderr, "\r\nFreeSpace calculated wrong! iFree=%d, pPage->iFree=%d, ReqByte=%d, RNBits=%d, DCBits=%d, TCBits=%d", + iFree, pPage->iFree, pPage->ReqByte, pPage->RNBits, pPage->DCBits, pPage->TCBits ); + fflush( stderr ); bErr = HB_TRUE; } if( bErr ) { - printf( "\r\nPage=%lx, Page->iFree=%d, iLen=%d\r\n", pPage->Page, pPage->iFree, iNum ); - fflush( stdout ); + fprintf( stderr, "\r\nPage=%lx, Page->iFree=%d, iLen=%d\r\n", pPage->Page, pPage->iFree, iNum ); + fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageCheckDupTrl: index corrupted." ); } } @@ -1724,14 +1724,14 @@ static void hb_cdxChkLeafRecord( const HB_BYTE * pSrc, if( ulRec != ulRec2 || iDup != iDup2 || iTrl != iTrl2 ) { - printf( "\r\nDCBits=%d[%X], TCBits=%d[%X] ", pPage->DCBits, pPage->DCMask, pPage->TCBits, pPage->TCMask ); + fprintf( stderr, "\r\nDCBits=%d[%X], TCBits=%d[%X] ", pPage->DCBits, pPage->DCMask, pPage->TCBits, pPage->TCMask ); for( iTmp = 0; iTmp < pPage->ReqByte; ++iTmp ) - printf( "%02X ", pSrc[ iTmp ] ); + fprintf( stderr, "%02X ", pSrc[ iTmp ] ); iTmp = ( ( iTrl << pPage->DCBits ) | iDup ) << ( 24 - pPage->TCBits - pPage->DCBits ); - printf( " %6X", iTmp ); - printf( "\r\nhb_cdxChkLeafRecord: ReqByte=%d, ulRec[%lu=>%lu], iDup[%d=>%d], iTrl[%d=>%d]\r\n", - pPage->ReqByte, ulRec, ulRec2, iDup, iDup2, iTrl, iTrl2 ); - fflush( stdout ); + fprintf( stderr, " %6X", iTmp ); + fprintf( stderr, "\r\nhb_cdxChkLeafRecord: ReqByte=%d, ulRec[%lu=>%lu], iDup[%d=>%d], iTrl[%d=>%d]\r\n", + pPage->ReqByte, ulRec, ulRec2, iDup, iDup2, iTrl, iTrl2 ); + fflush( stderr ); hb_cdxErrInternal( "hb_cdxChkLeafRecord: wrong leaf record." ); } } @@ -1771,8 +1771,8 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys #ifdef HB_CDX_DBGCODE if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) { - printf( "\r\npPage->Page=%lx. left=%lx, right=%lx", - pPage->Page, pPage->Left, pPage->Right ); fflush( stdout ); + fprintf( stderr, "\r\npPage->Page=%lx. left=%lx, right=%lx", + pPage->Page, pPage->Left, pPage->Right ); fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageLeafEncode: page is not a leaf." ); } #endif @@ -1797,7 +1797,7 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys iTrl = HB_GET_LE_UINT16( &pSrc[ iNum + 6 ] ); iTmp = iNum - iTrl - iDup; #if 0 - printf( "\r\nKEY=%d, REC=%ld, DUP=%d, TRL=%d, VAL[%s]", iKey, ulRec, iDup, iTrl, pSrc ); + fprintf( stderr, "\r\nKEY=%d, REC=%ld, DUP=%d, TRL=%d, VAL[%s]", iKey, ulRec, iDup, iTrl, pSrc ); #endif hb_cdxSetLeafRecord( pRecPos, ulRec, iDup, iTrl, iReq, pPage->DCBits, pPage->TCBits ); @@ -1812,8 +1812,8 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys #ifdef HB_CDX_DBGCODE else if( iTmp < 0 ) { - printf( "\r\n[%s][%s]", pSrc - iLen, pSrc ); - printf( "\r\npPage->Page=0x%lx, iKey=%d, iNum=%d, iDup=%d, iTrl=%d", pPage->Page, iKey, iNum, iDup, iTrl ); fflush( stdout ); + fprintf( stderr, "\r\n[%s][%s]", pSrc - iLen, pSrc ); + fprintf( stderr, "\r\npPage->Page=0x%lx, iKey=%d, iNum=%d, iDup=%d, iTrl=%d", pPage->Page, iKey, iNum, iDup, iTrl ); fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageLeafEncode: index corrupted." ); } #endif @@ -1823,9 +1823,9 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys #ifdef HB_CDX_DBGCODE if( pKeyPos - pRecPos != pPage->iFree ) { - printf( "\r\nPage=0x%lx, calc=%d, iFree=%d, req=%u, keys=%d, keyLen=%d\r\n", - pPage->Page, ( int ) ( pKeyPos - pRecPos ), pPage->iFree, pPage->ReqByte, iKeys, iNum ); - fflush( stdout ); + fprintf( stderr, "\r\nPage=0x%lx, calc=%d, iFree=%d, req=%u, keys=%d, keyLen=%d\r\n", + pPage->Page, ( int ) ( pKeyPos - pRecPos ), pPage->iFree, pPage->ReqByte, iKeys, iNum ); + fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageLeafEncode: FreeSpace calculated wrong!" ); } if( pPage->iFree < 0 ) @@ -1839,7 +1839,7 @@ static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKeys HB_BYTE * pKeyBf = pPage->pKeyBuf; pPage->pKeyBuf = NULL; #if 0 - printf( "\r\nhb_cdxPageLeafEncode: check keys" ); + fprintf( stderr, "\r\nhb_cdxPageLeafEncode: check keys" ); if( iKeys > 0 ) { pPage->bufKeyNum = 0; hb_cdxPageGetKeyVal( pPage, iKeys - 1 ); } #endif hb_cdxPageCheckKeys( pPage ); @@ -1861,7 +1861,7 @@ static void hb_cdxPageLeafDecode( LPCDXPAGE pPage, HB_BYTE * pKeyBuf ) #ifdef HB_CDX_DBGCODE if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) { - printf( "\r\npPage->Page=%lx", pPage->Page ); fflush( stdout ); + fprintf( stderr, "\r\npPage->Page=%lx", pPage->Page ); fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageLeafDecode: page is not a leaf." ); } #endif @@ -1895,7 +1895,7 @@ static void hb_cdxPageLeafDecode( LPCDXPAGE pPage, HB_BYTE * pKeyBuf ) #ifdef HB_CDX_DBGCODE else if( iNew < 0 ) { - printf( "\r\npPage->Page=%lx, iLen=%d, iDup=%d, iTrl=%d", pPage->Page, iLen, iDup, iTrl ); fflush( stdout ); + fprintf( stderr, "\r\npPage->Page=%lx, iLen=%d, iDup=%d, iTrl=%d", pPage->Page, iLen, iDup, iTrl ); fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageLeafDecode: index corrupted." ); } #endif @@ -1979,10 +1979,10 @@ static void hb_cdxPageCalcLeafSpace( LPCDXPAGE pPage, HB_BYTE * pKeyBuf, int iKe if( iSize > pPage->iFree ) break; #ifdef HB_CDX_DSPDBG_INFO_X - printf( "\r\npPage->Page=%lx, ulRec=%lx, RNMask=%lx/%lx, RNBits=%d/%d, DCB=%d, TCB=%d (%lx), iKey=%d/%d", - pPage->Page, ulRec, RNMask, pPage->RNMask, RNBits, pPage->RNBits, - pPage->DCBits, pPage->TCBits, HB_CDXBITMASK( RNBits ), iKey, iKeys ); - fflush( stdout ); + fprintf( stderr, "\r\npPage->Page=%lx, ulRec=%lx, RNMask=%lx/%lx, RNBits=%d/%d, DCB=%d, TCB=%d (%lx), iKey=%d/%d", + pPage->Page, ulRec, RNMask, pPage->RNMask, RNBits, pPage->RNBits, + pPage->DCBits, pPage->TCBits, HB_CDXBITMASK( RNBits ), iKey, iKeys ); + fflush( stderr ); #endif pPage->RNMask = RNMask; pPage->RNBits = RNBits; @@ -2016,11 +2016,11 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) pPage->pKeyBuf = pKeyBuf; } #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\ndelkey: Page=%lx, iKey=%d/%d, rec=%ld, iFree=%d", - pPage->Page, iKey, pPage->iKeys, - ( HB_ULONG ) HB_GET_LE_UINT32( &pPage->pKeyBuf[ ( iKey + 1 ) * iLen - 8 ] ), - pPage->iFree ); - fflush( stdout ); + fprintf( stderr, "\r\ndelkey: Page=%lx, iKey=%d/%d, rec=%ld, iFree=%d", + pPage->Page, iKey, pPage->iKeys, + ( HB_ULONG ) HB_GET_LE_UINT32( &pPage->pKeyBuf[ ( iKey + 1 ) * iLen - 8 ] ), + pPage->iFree ); + fflush( stderr ); #endif iSpc = pPage->ReqByte + pPage->TagParent->uiLen - HB_GET_LE_UINT16( &pPage->pKeyBuf[ ( iKey + 1 ) * iLen - 4 ] ) - @@ -2054,17 +2054,17 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) ++iDup; } #ifdef HB_CDX_DSPDBG_INFO - printf( "+%d=%d", iSpc + iDup, pPage->iFree + iSpc + iDup ); + fprintf( stderr, "+%d=%d", iSpc + iDup, pPage->iFree + iSpc + iDup ); if( iSpc + iDup < 0 ) - printf( " iLen=%d, iDup=%d, iNum=%d pd=%d pt=%d cd=%d ct=%d nd=%d nt=%d", - iLen - 8, iDup, iNum, - HB_GET_LE_UINT16( &pPage->pKeyBuf[ iPrev + iLen - 4 ] ), - HB_GET_LE_UINT16( &pPage->pKeyBuf[ iPrev + iLen - 2 ] ), - iDupCurr, - HB_GET_LE_UINT16( &pPage->pKeyBuf[ iNext - 2 ] ), - iDupNext, - iTrlNext ); - fflush( stdout ); + fprintf( stderr, " iLen=%d, iDup=%d, iNum=%d pd=%d pt=%d cd=%d ct=%d nd=%d nt=%d", + iLen - 8, iDup, iNum, + HB_GET_LE_UINT16( &pPage->pKeyBuf[ iPrev + iLen - 4 ] ), + HB_GET_LE_UINT16( &pPage->pKeyBuf[ iPrev + iLen - 2 ] ), + iDupCurr, + HB_GET_LE_UINT16( &pPage->pKeyBuf[ iNext - 2 ] ), + iDupNext, + iTrlNext ); + fflush( stderr ); #endif } HB_PUT_LE_UINT16( &pPage->pKeyBuf[ iPos ], iDup ); @@ -2104,10 +2104,10 @@ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) int iRet = 0; #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\naddkey: Page=%lx, iKey=%d/%d, rec=%ld, iFree=%d", - pPage->Page, pPage->iCurKey, pPage->iKeys, pKey->rec, - pPage->iFree ); - fflush( stdout ); + fprintf( stderr, "\r\naddkey: Page=%lx, iKey=%d/%d, rec=%ld, iFree=%d", + pPage->Page, pPage->iCurKey, pPage->iKeys, pKey->rec, + pPage->iFree ); + fflush( stderr ); #endif #ifdef HB_CDX_DBGCODE if( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) @@ -2221,9 +2221,9 @@ static void hb_cdxPageIntSetKey( LPCDXPAGE pPage, int iKey, HB_BOOL fIns, HB_BYT HB_BYTE * pKeyPool = hb_cdxPageIntKeyPool( pPage ); #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nintSetKey (%s): Page=%lx, iKey=%d/%d, ulPag=%lx", - fIns ? "ins" : "set", pPage->Page, iKey, pPage->iKeys, ulPag ); - fflush( stdout ); + fprintf( stderr, "\r\nintSetKey (%s): Page=%lx, iKey=%d/%d, ulPag=%lx", + fIns ? "ins" : "set", pPage->Page, iKey, pPage->iKeys, ulPag ); + fflush( stderr ); #endif #ifdef HB_CDX_DBGCODE if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) @@ -2263,10 +2263,10 @@ static void hb_cdxPageIntDelKey( LPCDXPAGE pPage, int iKey ) HB_BYTE * pKeyPool = hb_cdxPageIntKeyPool( pPage ); #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nintDelKey: Page=%lx, iKey=%d/%d, ulPag=%lx", - pPage->Page, iKey, pPage->iKeys, - ( HB_ULONG ) HB_GET_BE_UINT32( &pKeyPool[ ( iKey + 1 ) * iLen - 4 ] ) ); - fflush( stdout ); + fprintf( stderr, "\r\nintDelKey: Page=%lx, iKey=%d/%d, ulPag=%lx", + pPage->Page, iKey, pPage->iKeys, + ( HB_ULONG ) HB_GET_BE_UINT32( &pKeyPool[ ( iKey + 1 ) * iLen - 4 ] ) ); + fflush( stderr ); #endif #ifdef HB_CDX_DBGCODE if( ( pPage->PageType & CDX_NODE_LEAF ) != 0 ) @@ -2548,7 +2548,7 @@ static void hb_cdxPageGetChild( LPCDXPAGE pPage ) } } #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nGetChild: Parent=%lx, Child=%lx", pPage->Page, ulPage ); fflush( stdout ); + fprintf( stderr, "\r\nGetChild: Parent=%lx, Child=%lx", pPage->Page, ulPage ); fflush( stderr ); #endif if( pPage->Child == NULL ) pPage->Child = hb_cdxPageNew( pPage->TagParent, pPage, ulPage ); @@ -2590,8 +2590,8 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) } #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nleaf balance: Page=%lx (%d/%d)", pPage->Page, iFirstKey, iBlncKeys ); - fflush( stdout ); + fprintf( stderr, "\r\nleaf balance: Page=%lx (%d/%d)", pPage->Page, iFirstKey, iBlncKeys ); + fflush( stderr ); #endif if( ( iChildRet & ( NODE_SPLIT | NODE_JOIN ) ) == 0 && @@ -2613,10 +2613,10 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) if( i > 0 && ( childs[ i ]->Page != childs[ i - 1 ]->Right || childs[ i ]->Left != childs[ i - 1 ]->Page ) ) { - printf( "\r\nchilds[%d]->Page=%lx, childs[%d]->Right=%lx, childs[%d]->Page=%lx, childs[%d]->Left=%lx", - i - 1, childs[ i - 1 ]->Page, i - 1, childs[ i - 1 ]->Right, - i, childs[ i ]->Page, i, childs[ i ]->Left ); - fflush( stdout ); + fprintf( stderr, "\r\nchilds[%d]->Page=%lx, childs[%d]->Right=%lx, childs[%d]->Page=%lx, childs[%d]->Left=%lx", + i - 1, childs[ i - 1 ]->Page, i - 1, childs[ i - 1 ]->Right, + i, childs[ i ]->Page, i, childs[ i ]->Left ); + fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageKeyLeafBalance: index corrupted." ); } #endif @@ -2640,9 +2640,9 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) iKeys += childs[ i ]->iKeys; #ifdef HB_CDX_DSPDBG_INFO - printf( ", childs[%d]->Page=%lx(%d/%d)", i, childs[ i ]->Page, childs[ i ]->iKeys, childs[ i ]->iFree ); - printf( "(%d/%d/%d:%d,%lx)", i, iSkip, iBlncKeys, iKeys, childs[ i ]->Right ); - fflush( stdout ); + fprintf( stderr, ", childs[%d]->Page=%lx(%d/%d)", i, childs[ i ]->Page, childs[ i ]->iKeys, childs[ i ]->iFree ); + fprintf( stderr, "(%d/%d/%d:%d,%lx)", i, iSkip, iBlncKeys, iKeys, childs[ i ]->Right ); + fflush( stderr ); #endif } if( ( iChildRet & NODE_SPLIT ) == 0 ) @@ -2663,8 +2663,8 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) return iRet; } #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nleaf balance: Page=%lx iKeys=%d", pPage->Page, iKeys ); - fflush( stdout ); + fprintf( stderr, "\r\nleaf balance: Page=%lx iKeys=%d", pPage->Page, iKeys ); + fflush( stderr ); #endif if( iKeys > 0 ) { @@ -2701,15 +2701,15 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) iKeys -= childs[ i - 1 ]->iKeys; iSkip++; #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\niSkip=%d, iBlncKeys=%d", iSkip, iBlncKeys ); - fflush( stdout ); + fprintf( stderr, "\r\niSkip=%d, iBlncKeys=%d", iSkip, iBlncKeys ); + fflush( stderr ); #endif } } pPtr += childs[ i ]->iKeys * iLen; #ifdef HB_CDX_DSPDBG_INFO - printf( ", childs[%d]->iKeys=%d", i, childs[ i ]->iKeys ); - fflush( stdout ); + fprintf( stderr, ", childs[%d]->iKeys=%d", i, childs[ i ]->iKeys ); + fflush( stderr ); #endif } } @@ -2755,7 +2755,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) for( j = 0; j < iMax && pPtr[ ( iKeys - 1 ) * iLen + j ] == pbKey[ j ]; j++ ) {} #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\niDup=%d, iTrl=%d ", j, iLen - 8 - iMax ); fflush( stdout ); + fprintf( stderr, "\r\niDup=%d, iTrl=%d ", j, iLen - 8 - iMax ); fflush( stderr ); #endif iSize -= j; iMaxReq = lpTmpPage->ReqByte; @@ -2773,9 +2773,9 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) else { #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\ninserting iDup=%d #keys=%d/%d (%d) parent=%lx, child=%lx (%d), rec=%ld", - j, iKeys, lpTmpPage->iKeys, i, pPage->Page, lpTmpPage->Page, iSize, ( HB_ULONG ) HB_GET_LE_UINT32( pPtr + iLen - 8 ) ); - fflush( stdout ); + fprintf( stderr, "\r\ninserting iDup=%d #keys=%d/%d (%d) parent=%lx, child=%lx (%d), rec=%ld", + j, iKeys, lpTmpPage->iKeys, i, pPage->Page, lpTmpPage->Page, iSize, ( HB_ULONG ) HB_GET_LE_UINT32( pPtr + iLen - 8 ) ); + fflush( stderr ); #endif if( iBufSize >= iKeys + lpTmpPage->iKeys ) { @@ -2810,7 +2810,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) HB_PUT_LE_UINT16( &pPtr[ iLen - 4 ], iDup ); iKeys += lpTmpPage->iKeys; #ifdef HB_CDX_DSPDBG_INFO - printf( " iDup2=%d, iTrl2=%d ", iDup, HB_GET_LE_UINT16( &pPtr[ iLen - 2 ] ) ); fflush( stdout ); + fprintf( stderr, " iDup2=%d, iTrl2=%d ", iDup, HB_GET_LE_UINT16( &pPtr[ iLen - 2 ] ) ); fflush( stderr ); #endif } pPtr = pKeyPool; @@ -2830,8 +2830,8 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) iSize += ( iMaxReq - childs[ i ]->ReqByte ) * childs[ i ]->iKeys; if( iSize != childs[ i ]->iFree ) { - printf( "\r\ninserting, iSize=%d, childs[ i ]->iFree=%d", iSize, childs[ i ]->iFree ); fflush( stdout ); - printf( "\r\niKeys=%d, iMaxReq=%d", iKeys, iMaxReq ); fflush( stdout ); + fprintf( stderr, "\r\ninserting, iSize=%d, childs[ i ]->iFree=%d", iSize, childs[ i ]->iFree ); fflush( stderr ); + fprintf( stderr, "\r\niKeys=%d, iMaxReq=%d", iKeys, iMaxReq ); fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageGetChild: index corrupted." ); } #endif @@ -2859,8 +2859,8 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) iBlncKeys++; iRet |= NODE_BALANCE; #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nleaf balance: new child[%d]->Page=%lx", i, childs[ i ]->Page ); - fflush( stdout ); + fprintf( stderr, "\r\nleaf balance: new child[%d]->Page=%lx", i, childs[ i ]->Page ); + fflush( stderr ); #endif } } @@ -2877,8 +2877,8 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) childs[ i ]->iFree == iChFree[ i ] ) { #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\niskip++\r\n" ); - fflush( stdout ); + fprintf( stderr, "\r\niskip++\r\n" ); + fflush( stderr ); #endif iSkip++; } @@ -2896,8 +2896,8 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) else iBlncKeys++; #ifdef HB_CDX_DSPDBG_INFO - printf( " (%d/%d)", childs[ i ]->iKeys, childs[ i ]->iFree ); - fflush( stdout ); + fprintf( stderr, " (%d/%d)", childs[ i ]->iKeys, childs[ i ]->iFree ); + fflush( stderr ); #endif #ifdef HB_CDX_DBGCODE_EXT hb_cdxPageCheckKeys( childs[ i ] ); @@ -2960,8 +2960,8 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) /* Delete parent key */ iBlncKeys--; #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nleaf balance: free child[%d]->Page=%lx", iBlncKeys, childs[ iBlncKeys ]->Page ); - fflush( stdout ); + fprintf( stderr, "\r\nleaf balance: free child[%d]->Page=%lx", iBlncKeys, childs[ iBlncKeys ]->Page ); + fflush( stderr ); #endif if( childs[ iBlncKeys ]->pKeyBuf ) { @@ -3026,8 +3026,8 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) } #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nbalance: Page=%lx(%d) (%d/%d)", pPage->Page, pPage->iKeys, iFirstKey, iBlncKeys ); - fflush( stdout ); + fprintf( stderr, "\r\nbalance: Page=%lx(%d) (%d/%d)", pPage->Page, pPage->iKeys, iFirstKey, iBlncKeys ); + fflush( stderr ); #endif if( ! fForce && iBlncKeys < 2 ) @@ -3048,10 +3048,10 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) if( i > 0 && ( childs[ i ]->Page != childs[ i - 1 ]->Right || childs[ i ]->Left != childs[ i - 1 ]->Page ) ) { - printf( "\r\nchilds[%d]->Page=%lx, childs[%d]->Right=%lx, childs[%d]->Page=%lx, childs[%d]->Left=%lx", - i - 1, childs[ i - 1 ]->Page, i - 1, childs[ i - 1 ]->Right, - i, childs[ i ]->Page, i, childs[ i ]->Left ); - fflush( stdout ); + fprintf( stderr, "\r\nchilds[%d]->Page=%lx, childs[%d]->Right=%lx, childs[%d]->Page=%lx, childs[%d]->Left=%lx", + i - 1, childs[ i - 1 ]->Page, i - 1, childs[ i - 1 ]->Right, + i, childs[ i ]->Page, i, childs[ i ]->Left ); + fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageKeyIntBalance: index corrupted." ); } #endif @@ -3062,8 +3062,8 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) if( childs[ i ]->iKeys < iMin ) iMin = childs[ i ]->iKeys; #ifdef HB_CDX_DSPDBG_INFO - printf( ", childs[%d]->Page=%lx(%d)", i, childs[ i ]->Page, childs[ i ]->iKeys ); - fflush( stdout ); + fprintf( stderr, ", childs[%d]->Page=%lx(%d)", i, childs[ i ]->Page, childs[ i ]->iKeys ); + fflush( stderr ); #endif } iNeedKeys = ( iKeys + pPage->TagParent->MaxKeys - 1 ) @@ -3176,8 +3176,8 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) hb_cdxPageFree( lpTmpPage, HB_FALSE ); } #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nint balance: new child[%d]->Page=%lx", iBlncKeys, childs[ iBlncKeys ]->Page ); - fflush( stdout ); + fprintf( stderr, "\r\nint balance: new child[%d]->Page=%lx", iBlncKeys, childs[ iBlncKeys ]->Page ); + fflush( stderr ); #endif iBlncKeys++; iRet |= NODE_BALANCE; @@ -3234,8 +3234,8 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) { /* Delete parent key */ #ifdef HB_CDX_DSPDBG_INFO - printf( "\r\nbalance: free child[%d]->Page=%lx", i, childs[ i ]->Page ); - fflush( stdout ); + fprintf( stderr, "\r\nbalance: free child[%d]->Page=%lx", i, childs[ i ]->Page ); + fflush( stderr ); #endif hb_cdxPageIntDelKey( pPage, iFirstKey + i ); childs[ i ]->Owner = NULL; @@ -3280,7 +3280,7 @@ static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) childs[ i ]->Page ); } #ifdef HB_CDX_DSPDBG_INFO - printf( " (%d)", childs[ i ]->iKeys ); + fprintf( stderr, " (%d)", childs[ i ]->iKeys ); #endif #ifdef HB_CDX_DBGCODE_EXT hb_cdxPageCheckKeys( childs[ i ] ); @@ -3924,12 +3924,12 @@ static int hb_cdxPageSeekKey( LPCDXPAGE pPage, LPCDXKEY pKey, HB_ULONG ulKeyRec hb_cdxPageGetKeyRec( pPage, pPage->iCurKey ) != hb_cdxPageGetKeyRec( pPage->Child, pPage->Child->iKeys - 1 ) ) { - printf( "\r\nkeyLen=%u", pPage->TagParent->uiLen ); - printf( "\r\nparent=%lx, iKey=%d, rec=%lu", pPage->Page, pPage->iCurKey, hb_cdxPageGetKeyRec( pPage, pPage->iCurKey ) ); - printf( "\r\n child=%lx, iKey=%d, rec=%lu", pPage->Child->Page, pPage->Child->iKeys - 1, hb_cdxPageGetKeyRec( pPage->Child, pPage->Child->iKeys - 1 ) ); - printf( "\r\nparent val=[%s]", hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ) ); - printf( "\r\n child val=[%s]", hb_cdxPageGetKeyVal( pPage->Child, pPage->Child->iKeys - 1 ) ); - fflush( stdout ); + fprintf( stderr, "\r\nkeyLen=%u", pPage->TagParent->uiLen ); + fprintf( stderr, "\r\nparent=%lx, iKey=%d, rec=%lu", pPage->Page, pPage->iCurKey, hb_cdxPageGetKeyRec( pPage, pPage->iCurKey ) ); + fprintf( stderr, "\r\n child=%lx, iKey=%d, rec=%lu", pPage->Child->Page, pPage->Child->iKeys - 1, hb_cdxPageGetKeyRec( pPage->Child, pPage->Child->iKeys - 1 ) ); + fprintf( stderr, "\r\nparent val=[%s]", hb_cdxPageGetKeyVal( pPage, pPage->iCurKey ) ); + fprintf( stderr, "\r\n child val=[%s]", hb_cdxPageGetKeyVal( pPage->Child, pPage->Child->iKeys - 1 ) ); + fflush( stderr ); hb_cdxErrInternal( "hb_cdxPageSeekKey: wrong parent key." ); } #endif @@ -7132,25 +7132,26 @@ static HB_ERRCODE hb_cdxClose( CDXAREAP pArea ) hb_cdxOrdListClear( pArea, HB_TRUE, NULL ); #ifdef HB_CDX_DBGTIME - printf( "\r\ncdxTimeIntBld=%f, cdxTimeExtBld=%f, cdxTimeBld=%f\r\n" - "cdxTimeGetKey=%f, cdxTimeFreeKey=%f\r\n" - "cdxTimeExtBlc=%f, cdxTimeIntBlc=%f\r\n" - "cdxTimeIdxBld=%f\r\n" - "cdxTimeTotal=%f\r\n", - ( double ) cdxTimeIntBld / 1000000, ( double ) cdxTimeExtBld / 1000000, - ( double ) ( cdxTimeIntBld + cdxTimeExtBld ) / 1000000, - ( double ) cdxTimeGetKey / 1000000, ( double ) cdxTimeFreeKey / 1000000, - ( double ) cdxTimeIntBlc / 1000000, ( double ) cdxTimeExtBlc / 1000000, - ( double ) cdxTimeIdxBld / 1000000, - ( double ) ( cdxTimeIntBld + cdxTimeExtBld + cdxTimeIdxBld + - cdxTimeGetKey + cdxTimeFreeKey + - cdxTimeExtBlc + cdxTimeIntBlc ) / 1000000 ); - fflush( stdout ); + fprintf( stderr, + "\r\ncdxTimeIntBld=%f, cdxTimeExtBld=%f, cdxTimeBld=%f\r\n" + "cdxTimeGetKey=%f, cdxTimeFreeKey=%f\r\n" + "cdxTimeExtBlc=%f, cdxTimeIntBlc=%f\r\n" + "cdxTimeIdxBld=%f\r\n" + "cdxTimeTotal=%f\r\n", + ( double ) cdxTimeIntBld / 1000000, ( double ) cdxTimeExtBld / 1000000, + ( double ) ( cdxTimeIntBld + cdxTimeExtBld ) / 1000000, + ( double ) cdxTimeGetKey / 1000000, ( double ) cdxTimeFreeKey / 1000000, + ( double ) cdxTimeIntBlc / 1000000, ( double ) cdxTimeExtBlc / 1000000, + ( double ) cdxTimeIdxBld / 1000000, + ( double ) ( cdxTimeIntBld + cdxTimeExtBld + cdxTimeIdxBld + + cdxTimeGetKey + cdxTimeFreeKey + + cdxTimeExtBlc + cdxTimeIntBlc ) / 1000000 ); + fflush( stderr ); cdxTimeIntBld = cdxTimeExtBld = 0; #endif #ifdef HB_CDX_DBGUPDT - printf( "\r\n#reads=%ld, #writes=%ld, stacksize=%d\r\n", cdxReadNO, cdxWriteNO, cdxStackSize ); - fflush( stdout ); + fprintf( stderr, "\r\n#reads=%ld, #writes=%ld, stacksize=%d\r\n", cdxReadNO, cdxWriteNO, cdxStackSize ); + fflush( stderr ); cdxReadNO = cdxWriteNO = 0; #endif } @@ -9446,9 +9447,9 @@ static void hb_cdxSortOut( LPCDXSORTINFO pSort ) pSort->ulPages = pSort->ulCurPage + 1; pSort->ulPgKeys = pSort->ulMaxKey / pSort->ulPages; /* - printf( "\r\npSort->ulMaxKey=%ld, pSort->ulPages=%ld, pSort->ulPgKeys=%ld, size=%ld\r\n", - pSort->ulMaxKey, pSort->ulPages, pSort->ulPgKeys, - pSort->ulMaxKey * ( pSort->keyLen + 4 ) ); fflush(stdout); + fprintf( stderr, "\r\npSort->ulMaxKey=%ld, pSort->ulPages=%ld, pSort->ulPgKeys=%ld, size=%ld\r\n", + pSort->ulMaxKey, pSort->ulPages, pSort->ulPgKeys, + pSort->ulMaxKey * ( pSort->keyLen + 4 ) ); fflush( stderr ); */ if( pSort->ulPages > 1 ) { @@ -9494,8 +9495,8 @@ static void hb_cdxSortOut( LPCDXSORTINFO pSort ) i = ( pSort->ulLastRec < ulRec ) ? -1 : 1; if( i > 0 ) { - printf( "\r\nulKey=%ld, pKeyVal=[%s][%ld], pKeyLast=[%s][%ld]\r\n", - ulKey, pKeyVal, ulRec, pSort->pLastKey, pSort->ulLastRec ); fflush( stdout ); + fprintf( stderr, "\r\nulKey=%ld, pKeyVal=[%s][%ld], pKeyLast=[%s][%ld]\r\n", + ulKey, pKeyVal, ulRec, pSort->pLastKey, pSort->ulLastRec ); fflush( stderr ); hb_errInternal( 9305, "hb_cdxSortOut: sorting fails.", NULL, NULL ); } }