From a7e0e45857738c2bd33bf96186b9fdefccdcd3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Thu, 23 Jun 2016 00:54:16 +0200 Subject: [PATCH] 2016-06-23 00:54 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/hbapiitm.h * src/vm/itemapi.c + added new C function: PHB_ITEM hb_itemPutNil( PHB_ITEM pItem ); * src/rdd/dbf1.c ! fixed yet another RDDI_SETHEADER clearing in internal DBF RDD code * clear few passed variables before internal SELF_INFO() and SELF_RDDINFO() read calls - they were safe in current code but potentially may badly interact with 3-rd party DBF RDD wrappers. --- ChangeLog.txt | 12 ++++++++++++ include/hbapiitm.h | 1 + src/rdd/dbf1.c | 26 ++++++++++++++------------ src/vm/itemapi.c | 12 ++++++++++++ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 34bf39ea17..fd6ce135f2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,18 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2016-06-23 00:54 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * include/hbapiitm.h + * src/vm/itemapi.c + + added new C function: + PHB_ITEM hb_itemPutNil( PHB_ITEM pItem ); + + * src/rdd/dbf1.c + ! fixed yet another RDDI_SETHEADER clearing in internal DBF RDD code + * clear few passed variables before internal SELF_INFO() and + SELF_RDDINFO() read calls - they were safe in current code but + potentially may badly interact with 3-rd party DBF RDD wrappers. + 2016-06-22 23:58 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/dbinfo.ch * updated few comments diff --git a/include/hbapiitm.h b/include/hbapiitm.h index 58ab8019d7..4e008c20fa 100644 --- a/include/hbapiitm.h +++ b/include/hbapiitm.h @@ -131,6 +131,7 @@ extern HB_EXPORT PHB_ITEM hb_itemPutNumType( PHB_ITEM pItem, double dNumber, extern HB_EXPORT PHB_ITEM hb_itemPutPtr ( PHB_ITEM pItem, void * pValue ); extern HB_EXPORT PHB_ITEM hb_itemPutPtrGC ( PHB_ITEM pItem, void * pValue ); extern HB_EXPORT PHB_ITEM hb_itemPutSymbol ( PHB_ITEM pItem, PHB_SYMB pSym ); +extern HB_EXPORT PHB_ITEM hb_itemPutNil ( PHB_ITEM pItem ); extern HB_EXPORT HB_BOOL hb_itemRelease ( PHB_ITEM pItem ); extern HB_EXPORT PHB_ITEM hb_itemReturn ( PHB_ITEM pItem ); extern HB_EXPORT PHB_ITEM hb_itemReturnForward( PHB_ITEM pItem ); diff --git a/src/rdd/dbf1.c b/src/rdd/dbf1.c index 51ef4715b6..4ea0ca9d63 100644 --- a/src/rdd/dbf1.c +++ b/src/rdd/dbf1.c @@ -3117,7 +3117,7 @@ static HB_ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo ) if( ! pFileName->szExtension && hb_setGetDefExtension() ) { - pItem = hb_itemPutC( pItem, NULL ); + pItem = hb_itemPutNil( pItem ); if( SELF_INFO( &pArea->area, DBI_TABLEEXT, pItem ) != HB_SUCCESS ) { hb_itemRelease( pItem ); @@ -3141,7 +3141,7 @@ static HB_ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo ) if( pArea->bLockType == 0 ) { - pItem = hb_itemPutNI( pItem, 0 ); + pItem = hb_itemPutNil( pItem ); if( SELF_INFO( &pArea->area, DBI_LOCKSCHEME, pItem ) != HB_SUCCESS ) { hb_itemRelease( pItem ); @@ -3162,7 +3162,7 @@ static HB_ERRCODE hb_dbfCreate( DBFAREAP pArea, LPDBOPENINFO pCreateInfo ) else if( pArea->bMemoType == 0 ) { /* get memo type */ - pItem = hb_itemPutNI( pItem, 0 ); + pItem = hb_itemPutNil( pItem ); if( SELF_INFO( &pArea->area, DBI_MEMOTYPE, pItem ) != HB_SUCCESS ) { hb_itemRelease( pItem ); @@ -4096,9 +4096,10 @@ static HB_ERRCODE hb_dbfNewArea( DBFAREAP pArea ) pArea->uiSetHeader = DB_SETHEADER_APPENDSYNC; { - PHB_ITEM pItem = hb_itemPutNI( NULL, 0 ); + PHB_ITEM pItem = hb_itemNew( NULL ); if( SELF_RDDINFO( SELF_RDDNODE( &pArea->area ), RDDI_TABLETYPE, 0, pItem ) == HB_SUCCESS ) pArea->bTableType = ( HB_BYTE ) hb_itemGetNI( pItem ); + hb_itemClear( pItem ); if( SELF_RDDINFO( SELF_RDDNODE( &pArea->area ), RDDI_SETHEADER, 0, pItem ) == HB_SUCCESS ) pArea->uiSetHeader = ( HB_BYTE ) hb_itemGetNI( pItem ); hb_itemRelease( pItem ); @@ -4139,6 +4140,7 @@ static HB_ERRCODE hb_dbfOpen( DBFAREAP pArea, LPDBOPENINFO pOpenInfo ) if( ! pArea->fTrigger ) { + hb_itemClear( pItem ); if( SELF_RDDINFO( SELF_RDDNODE( &pArea->area ), RDDI_TRIGGER, pOpenInfo->ulConnection, pItem ) == HB_SUCCESS ) { @@ -6338,7 +6340,7 @@ static HB_ERRCODE hb_dbfDrop( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pIte if( ! pFileName->szExtension && ( ! fTable || hb_setGetDefExtension() ) ) { /* Add default extension if missing */ - pFileExt = hb_itemPutC( NULL, NULL ); + pFileExt = hb_itemPutNil( pFileExt ); if( SELF_RDDINFO( pRDD, fTable ? RDDI_TABLEEXT : RDDI_ORDBAGEXT, ulConnect, pFileExt ) == HB_SUCCESS ) pFileName->szExtension = hb_itemGetCPtr( pFileExt ); } @@ -6359,7 +6361,7 @@ static HB_ERRCODE hb_dbfDrop( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pIte * the path set by hb_FileExists() */ pFileName = hb_fsFNameSplit( szFileName ); - pFileExt = hb_itemPutC( pFileExt, NULL ); + pFileExt = hb_itemPutNil( pFileExt ); if( SELF_RDDINFO( pRDD, RDDI_MEMOEXT, ulConnect, pFileExt ) == HB_SUCCESS ) { szExt = hb_itemGetCPtr( pFileExt ); @@ -6374,7 +6376,7 @@ static HB_ERRCODE hb_dbfDrop( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pIte * and try to delete production index also if it exists * in the same directory as table file */ - pFileExt = hb_itemPutC( pFileExt, NULL ); + hb_itemClear( pFileExt ); if( SELF_RDDINFO( pRDD, RDDI_ORDSTRUCTEXT, ulConnect, pFileExt ) == HB_SUCCESS ) { szExt = hb_itemGetCPtr( pFileExt ); @@ -6418,7 +6420,7 @@ static HB_ERRCODE hb_dbfExists( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pI if( ! pFileName->szExtension && ( ! fTable || hb_setGetDefExtension() ) ) { - pFileExt = hb_itemPutC( NULL, NULL ); + pFileExt = hb_itemPutNil( pFileExt ); if( SELF_RDDINFO( pRDD, fTable ? RDDI_TABLEEXT : RDDI_ORDBAGEXT, ulConnect, pFileExt ) == HB_SUCCESS ) pFileName->szExtension = hb_itemGetCPtr( pFileExt ); } @@ -6457,7 +6459,7 @@ static HB_ERRCODE hb_dbfRename( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pI if( ! pFileName->szExtension && ( ! fTable || hb_setGetDefExtension() ) ) { /* Add default extension if missing */ - pFileExt = hb_itemPutC( pFileExt, NULL ); + pFileExt = hb_itemPutNil( pFileExt ); if( SELF_RDDINFO( pRDD, fTable ? RDDI_TABLEEXT : RDDI_ORDBAGEXT, ulConnect, pFileExt ) == HB_SUCCESS ) pFileName->szExtension = hb_itemGetCPtr( pFileExt ); } @@ -6477,7 +6479,7 @@ static HB_ERRCODE hb_dbfRename( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pI if( ! pFileNameNew->szExtension && ( ! fTable || hb_setGetDefExtension() ) ) { /* Add default extension if missing */ - pFileExt = hb_itemPutC( pFileExt, NULL ); + pFileExt = hb_itemPutNil( pFileExt ); if( SELF_RDDINFO( pRDD, fTable ? RDDI_TABLEEXT : RDDI_ORDBAGEXT, ulConnect, pFileExt ) == HB_SUCCESS ) pFileNameNew->szExtension = hb_itemGetCPtr( pFileExt ); } @@ -6493,7 +6495,7 @@ static HB_ERRCODE hb_dbfRename( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pI * supported and if yes then try to rename memo file if it exists * in the same directory as table file */ - pFileExt = hb_itemPutC( pFileExt, NULL ); + pFileExt = hb_itemPutNil( pFileExt ); if( SELF_RDDINFO( pRDD, RDDI_MEMOEXT, ulConnect, pFileExt ) == HB_SUCCESS ) { szExt = hb_itemGetCPtr( pFileExt ); @@ -6510,7 +6512,7 @@ static HB_ERRCODE hb_dbfRename( LPRDDNODE pRDD, PHB_ITEM pItemTable, PHB_ITEM pI * and try to rename production index also if it exists * in the same directory as table file */ - pFileExt = hb_itemPutC( pFileExt, NULL ); + hb_itemClear( pFileExt ); if( SELF_RDDINFO( pRDD, RDDI_ORDSTRUCTEXT, ulConnect, pFileExt ) == HB_SUCCESS ) { szExt = hb_itemGetCPtr( pFileExt ); diff --git a/src/vm/itemapi.c b/src/vm/itemapi.c index c3dbe0342e..f46db9802d 100644 --- a/src/vm/itemapi.c +++ b/src/vm/itemapi.c @@ -234,6 +234,18 @@ PHB_ITEM hb_itemArrayPut( PHB_ITEM pArray, HB_SIZE nIndex, PHB_ITEM pItem ) return pArray; } +PHB_ITEM hb_itemPutNil( PHB_ITEM pItem ) +{ + HB_TRACE( HB_TR_DEBUG, ( "hb_itemPutNil(%p)", pItem ) ); + + if( pItem ) + hb_itemSetNil( pItem ); + else + pItem = hb_itemNew( NULL ); + + return pItem; +} + PHB_ITEM hb_itemPutC( PHB_ITEM pItem, const char * szText ) { HB_SIZE nLen, nAlloc;