diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index a5f46cbb4c..c1b1058db0 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -301,9 +301,10 @@ extern BOOL HB_EXPORT hb_extIsArray( int iParam ); #define hb_ret() hb_itemClear( &hb_stack.Return ) #define hb_reta( ulLen ) hb_arrayNew( &hb_stack.Return, ulLen ) #define hb_retc( szText ) hb_itemPutC( &hb_stack.Return, szText ) -#define hb_retc_buffer( szText, ulLen ) hb_itemPutCPtr( &hb_stack.Return, szText, ulLen ) +#define hb_retc_buffer( szText ) hb_itemPutCPtr( &hb_stack.Return, szText, strlen( szText ) ) #define hb_retc_const( szText ) hb_itemPutCConst( &hb_stack.Return, szText ) #define hb_retclen( szText, ulLen ) hb_itemPutCL( &hb_stack.Return, szText, ulLen ) +#define hb_retclen_buffer( szText, ulLen ) hb_itemPutCPtr( &hb_stack.Return, szText, ulLen ) #define hb_retds( szDate ) hb_itemPutDS( &hb_stack.Return, szDate ) #define hb_retd( lYear, lMonth, lDay ) hb_itemPutD( &hb_stack.Return, lYear, lMonth, lDay ) #define hb_retdl( lJulian ) hb_itemPutDL( &hb_stack.Return, lJulian ) @@ -322,9 +323,10 @@ extern int HB_EXPORT hb_pcount( void ); /* returns the number of sup extern void HB_EXPORT hb_ret( void ); /* post a NIL return value */ extern void HB_EXPORT hb_retc( char * szText ); /* returns a string */ -extern void HB_EXPORT hb_retcbuffer( char * szText, ULONG ulLen ); /* returns a string without duplicating it */ -extern void HB_EXPORT hb_retcconst( char * szText ); /* returns a string as a pcode based string */ +extern void HB_EXPORT hb_retc_buffer( char * szText ); /* sames as above, but accepts an allocated buffer */ +extern void HB_EXPORT hb_retc_const( char * szText ); /* returns a string as a pcode based string */ extern void HB_EXPORT hb_retclen( char * szText, ULONG ulLen ); /* returns a string with a specific length */ +extern void HB_EXPORT hb_retclen_buffer( char * szText, ULONG ulLen ); /* sames as above, but accepts an allocated buffer */ extern void HB_EXPORT hb_retds( char * szDate ); /* returns a date, must use yyyymmdd format */ extern void HB_EXPORT hb_retd( long lYear, long lMonth, long lDay ); /* returns a date */ extern void HB_EXPORT hb_retdl( long lJulian ); /* returns a long value as a julian date */ diff --git a/harbour/source/rtl/ampm.c b/harbour/source/rtl/ampm.c index 3123d45b93..d1274d2f05 100644 --- a/harbour/source/rtl/ampm.c +++ b/harbour/source/rtl/ampm.c @@ -91,7 +91,6 @@ HB_FUNC( AMPM ) strcpy( pszResult + ulTimeLen, bAM ? " am" : " pm" ); - hb_retclen( pszResult, ulTimeLen + 3 ); - hb_xfree( pszResult ); + hb_retclen_buffer( pszResult, ulTimeLen + 3 ); } diff --git a/harbour/source/rtl/descend.c b/harbour/source/rtl/descend.c index 31ee7ac2fd..8331d665c4 100644 --- a/harbour/source/rtl/descend.c +++ b/harbour/source/rtl/descend.c @@ -80,11 +80,10 @@ HB_FUNC( DESCEND ) { char * szBuffer = ( char * ) hb_xgrab( ulLen ); hb_strDescend( szBuffer, hb_itemGetCPtr( pItem ), ulLen ); - hb_retclen( szBuffer, ulLen ); - hb_xfree( szBuffer ); + hb_retclen_buffer( szBuffer, ulLen ); } else - hb_retc( "" ); + hb_retc( NULL ); } else if( HB_IS_DATE( pItem ) ) hb_retnl( 5231808 - hb_itemGetDL( pItem ) ); diff --git a/harbour/source/rtl/gete.c b/harbour/source/rtl/gete.c index bb3120c0d6..223d786679 100644 --- a/harbour/source/rtl/gete.c +++ b/harbour/source/rtl/gete.c @@ -102,18 +102,20 @@ HB_FUNC( GETENV ) szValue = hb_getenv( pszName ); - hb_retc( szValue && szValue[ 0 ] != '\0' ? szValue : ( ( ISCHAR( 2 ) ? hb_parc( 2 ) : "" ) ) ); - - if( szValue ) - hb_xfree( ( void * ) szValue ); + if( szValue && szValue[ 0 ] != '\0' ) + hb_retc_buffer( szValue ); + else if( ISCHAR( 2 ) ) + hb_retc( hb_parc( 2 ) ); + else + hb_retc( NULL ); } else - hb_retc( "" ); + hb_retc( NULL ); hb_itemFreeC( pszName ); } else - hb_retc( "" ); + hb_retc( NULL ); } /* NOTE: Undocumented Clipper function. [vszakats] */ diff --git a/harbour/source/rtl/langapi.c b/harbour/source/rtl/langapi.c index bce5440e15..950e11d942 100644 --- a/harbour/source/rtl/langapi.c +++ b/harbour/source/rtl/langapi.c @@ -222,9 +222,7 @@ HB_FUNC( HB_LANGSELECT ) HB_FUNC( HB_LANGNAME ) { - char * pszName = hb_langName(); - hb_retc( pszName ); - hb_xfree( pszName ); + hb_retc_buffer( hb_langName() ); } HB_FUNC( HB_LANGERRMSG ) diff --git a/harbour/source/rtl/memofile.c b/harbour/source/rtl/memofile.c index b724b8c93d..e716fadcdf 100644 --- a/harbour/source/rtl/memofile.c +++ b/harbour/source/rtl/memofile.c @@ -95,16 +95,16 @@ HB_FUNC( MEMOREAD ) hb_fsClose( fhnd ); - hb_itemPutCPtr( hb_itemReturnPtr(), ( char * ) pbyBuffer, ulSize ); + hb_retclen_buffer( ( char * ) pbyBuffer, ulSize ); } else - hb_retc( "" ); + hb_retc( NULL ); } else - hb_retc( "" ); + hb_retc( NULL ); } else - hb_retc( "" ); + hb_retc( NULL ); } HB_FUNC( MEMOWRIT ) diff --git a/harbour/source/rtl/memoline.c b/harbour/source/rtl/memoline.c index 8486080a69..c2b7c61f21 100644 --- a/harbour/source/rtl/memoline.c +++ b/harbour/source/rtl/memoline.c @@ -55,7 +55,7 @@ HB_FUNC( MEMOLINE ) { - char * pszString = ISCHAR( 1 ) ? hb_parc( 1 ) : ""; + char * pszString = hb_parc( 1 ); ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; ULONG ulLineNumber = ISNUM( 3 ) ? hb_parni( 3 ) : 1; ULONG ulTabLength = ISNUM( 4 ) ? hb_parni( 4 ) : 4; @@ -171,10 +171,9 @@ HB_FUNC( MEMOLINE ) } - hb_retclen( pszLine, ulLineLength ); - hb_xfree( pszLine ); + hb_retclen_buffer( pszLine, ulLineLength ); } else - hb_retc( "" ); + hb_retc( NULL ); } diff --git a/harbour/source/rtl/mlcount.c b/harbour/source/rtl/mlcount.c index eac78add69..47f7b17fc7 100644 --- a/harbour/source/rtl/mlcount.c +++ b/harbour/source/rtl/mlcount.c @@ -54,7 +54,7 @@ HB_FUNC( MLCOUNT ) { - char * pszString = ISCHAR( 1 ) ? hb_parc( 1 ) : ""; + char * pszString = hb_parc( 1 ); ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; ULONG ulTabLength = ISNUM( 3 ) ? hb_parni( 3 ) : 4; ULONG ulLastSpace = 0; diff --git a/harbour/source/rtl/mlctopos.c b/harbour/source/rtl/mlctopos.c index e8631c3df8..209c35df58 100644 --- a/harbour/source/rtl/mlctopos.c +++ b/harbour/source/rtl/mlctopos.c @@ -54,7 +54,7 @@ HB_FUNC( MLCTOPOS ) { - char * pszString = ISCHAR( 1 ) ? hb_parc( 1 ) : ""; + char * pszString = hb_parc( 1 ); ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; ULONG ulLine = ISNUM( 3 ) ? hb_parnl( 3 ) : 1; ULONG ulCol = ISNUM( 4 ) ? hb_parnl( 4 ) : 0; diff --git a/harbour/source/rtl/mlpos.c b/harbour/source/rtl/mlpos.c index 48a9afb952..6bab259152 100644 --- a/harbour/source/rtl/mlpos.c +++ b/harbour/source/rtl/mlpos.c @@ -54,7 +54,7 @@ HB_FUNC( MLPOS ) { - char * pszString = ISCHAR( 1 ) ? hb_parc( 1 ) : ""; + char * pszString = hb_parc( 1 ); ULONG ulLineLength = hb_parni( 2 ); ULONG ulLine = hb_parni( 3 ); ULONG ulTabLength = ISNUM( 4 ) ? hb_parni( 4 ) : 4; diff --git a/harbour/source/rtl/mouseapi.c b/harbour/source/rtl/mouseapi.c index 1f477b1510..2aad066f75 100644 --- a/harbour/source/rtl/mouseapi.c +++ b/harbour/source/rtl/mouseapi.c @@ -254,9 +254,7 @@ HB_FUNC( MSAVESTATE ) uiPos += sizeof( int ); *( pBuffer + uiPos ) = iRight; - hb_retclen( ( char * ) pBuffer, uiLen ); - - hb_xfree( pBuffer ); + hb_retclen_buffer( ( char * ) pBuffer, uiLen ); } HB_FUNC( MRESTSTATE ) diff --git a/harbour/source/rtl/mpostolc.c b/harbour/source/rtl/mpostolc.c index 7fbffff834..6518b6e54f 100644 --- a/harbour/source/rtl/mpostolc.c +++ b/harbour/source/rtl/mpostolc.c @@ -54,7 +54,7 @@ HB_FUNC( MPOSTOLC ) { - char * pszString = ISCHAR( 1 ) ? hb_parc( 1 ) : ""; + char * pszString = hb_parc( 1 ); ULONG ulLineLength = ISNUM( 2 ) ? hb_parni( 2 ) : 79; ULONG ulPos = ISNUM( 3 ) ? hb_parnl( 3 ) : 1; ULONG ulTabLength = ISNUM( 4 ) ? hb_parni( 4 ) : 4; diff --git a/harbour/source/rtl/mtran.c b/harbour/source/rtl/mtran.c index 686171f5f0..14cc012477 100644 --- a/harbour/source/rtl/mtran.c +++ b/harbour/source/rtl/mtran.c @@ -99,11 +99,9 @@ HB_FUNC( MEMOTRAN ) ULONG ulResultLen; hb_strMemotran( pszResult, &ulResultLen, hb_itemGetCPtr( pString ), hb_itemGetCLen( pString ), cHardcr, cSoftcr ); - hb_retclen( pszResult, ulResultLen ); - - hb_xfree( pszResult ); + hb_retclen_buffer( pszResult, ulResultLen ); } else - hb_retc( "" ); + hb_retc( NULL ); } diff --git a/harbour/source/rtl/oemansi.c b/harbour/source/rtl/oemansi.c index d35ee45974..87aeb55cfe 100644 --- a/harbour/source/rtl/oemansi.c +++ b/harbour/source/rtl/oemansi.c @@ -72,14 +72,13 @@ HB_FUNC( HB_ANSITOOEM ) CharToOemBuff( ( LPCSTR ) hb_itemGetCPtr( pString ), ( LPSTR ) pszDst, ulLen ); - hb_retclen( pszDst, ulLen ); - hb_xfree( pszDst ); + hb_retclen_buffer( pszDst, ulLen ); } #else hb_itemReturn( pString ); #endif else - hb_retc( "" ); + hb_retc( NULL ); } HB_FUNC( HB_OEMTOANSI ) @@ -94,14 +93,13 @@ HB_FUNC( HB_OEMTOANSI ) OemToCharBuff( ( LPCSTR ) hb_itemGetCPtr( pString ), ( LPSTR ) pszDst, ulLen ); - hb_retclen( pszDst, ulLen ); - hb_xfree( pszDst ); + hb_retclen_buffer( pszDst, ulLen ); } #else hb_itemReturn( pString ); #endif else - hb_retc( "" ); + hb_retc( NULL ); } #endif diff --git a/harbour/source/rtl/oldbox.c b/harbour/source/rtl/oldbox.c index 7909a649a6..529da743a0 100644 --- a/harbour/source/rtl/oldbox.c +++ b/harbour/source/rtl/oldbox.c @@ -68,7 +68,7 @@ HB_FUNC( __BOX ) hb_itemGetNI( pLeft), hb_itemGetNI( pBottom ), hb_itemGetNI( pRight ), - ( BYTE * ) ( ISCHAR( 5 ) ? hb_parc( 5 ) : " " ) ); + ( BYTE * ) hb_parc( 5 ) ); } HB_FUNC( __BOXD ) diff --git a/harbour/source/rtl/padc.c b/harbour/source/rtl/padc.c index a5b2e323a2..2b84679508 100644 --- a/harbour/source/rtl/padc.c +++ b/harbour/source/rtl/padc.c @@ -83,8 +83,7 @@ HB_FUNC( PADC ) szResult[ lLen ] = '\0'; - hb_retclen( szResult, lLen ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, lLen ); } else { @@ -95,6 +94,6 @@ HB_FUNC( PADC ) } } else - hb_retc( "" ); + hb_retc( NULL ); } diff --git a/harbour/source/rtl/padl.c b/harbour/source/rtl/padl.c index 00d012c846..f1be546c86 100644 --- a/harbour/source/rtl/padl.c +++ b/harbour/source/rtl/padl.c @@ -78,8 +78,7 @@ HB_FUNC( PADL ) for(; lPos > 0; lPos-- ) szResult[ lPos - 1 ] = cPad; - hb_retclen( szResult, lLen ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, lLen ); } else { @@ -90,6 +89,6 @@ HB_FUNC( PADL ) } } else - hb_retc( "" ); + hb_retc( NULL ); } diff --git a/harbour/source/rtl/padr.c b/harbour/source/rtl/padr.c index a5f545611f..0dab6ca509 100644 --- a/harbour/source/rtl/padr.c +++ b/harbour/source/rtl/padr.c @@ -78,8 +78,7 @@ HB_FUNC( PADR ) for( lPos = ( long ) ulSize; lPos < lLen; lPos++ ) szResult[ lPos ] = cPad; - hb_retclen( szResult, ( ULONG ) lLen ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, ( ULONG ) lLen ); } else { @@ -90,6 +89,6 @@ HB_FUNC( PADR ) } } else - hb_retc( "" ); + hb_retc( NULL ); } diff --git a/harbour/source/rtl/philes.c b/harbour/source/rtl/philes.c index 0a22d0fe66..e5621596b4 100644 --- a/harbour/source/rtl/philes.c +++ b/harbour/source/rtl/philes.c @@ -146,7 +146,7 @@ HB_FUNC( FERASE ) { hb_fsSetError( 3 ); - hb_retni( ( ISCHAR( 1 ) && + hb_retni( ( ISCHAR( 1 ) && hb_fsDelete( ( BYTE * ) hb_parc( 1 ) ) ) ? 0 : -1 ); } @@ -154,7 +154,7 @@ HB_FUNC( FRENAME ) { hb_fsSetError( 2 ); - hb_retni( ( ISCHAR( 1 ) && ISCHAR( 2 ) && + hb_retni( ( ISCHAR( 1 ) && ISCHAR( 2 ) && hb_fsRename( ( BYTE * ) hb_parc( 1 ), ( BYTE * ) hb_parc( 2 ) ) ) ? 0 : -1 ); } @@ -185,15 +185,13 @@ HB_FUNC( FREADSTR ) /* NOTE: Clipper will not return zero chars from this functions. */ - hb_retc( ( char * ) buffer ); - - hb_xfree( buffer ); + hb_retc_buffer( ( char * ) buffer ); } else - hb_retc( "" ); + hb_retc( NULL ); } else - hb_retc( "" ); + hb_retc( NULL ); } /* NOTE: This function should not return the leading and trailing */ @@ -203,14 +201,13 @@ HB_FUNC( FREADSTR ) HB_FUNC( CURDIR ) { + BYTE byBuffer[ _POSIX_PATH_MAX + 1 ]; USHORT uiErrorOld = hb_fsError(); - BYTE * pbyBuffer = ( BYTE * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); hb_fsCurDirBuff( ( ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) ? - ( USHORT )( toupper( *hb_parc( 1 ) ) - 'A' + 1 ) : 0, pbyBuffer, _POSIX_PATH_MAX + 1 ); + ( USHORT )( toupper( *hb_parc( 1 ) ) - 'A' + 1 ) : 0, byBuffer, _POSIX_PATH_MAX + 1 ); - hb_retc( ( char * ) pbyBuffer ); - hb_xfree( pbyBuffer ); + hb_retc( ( char * ) byBuffer ); hb_fsSetError( uiErrorOld ); } diff --git a/harbour/source/rtl/replic.c b/harbour/source/rtl/replic.c index 011187bfa6..30faa67468 100644 --- a/harbour/source/rtl/replic.c +++ b/harbour/source/rtl/replic.c @@ -79,14 +79,13 @@ HB_FUNC( REPLICATE ) szPtr += ulLen; } - hb_retclen( szResult, ulLen * lTimes ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, ulLen * lTimes ); } else hb_errRT_BASE_SubstR( EG_STROVERFLOW, 1234, NULL, "REPLICATE", 2, hb_paramError( 1 ), hb_paramError( 2 ) ); } else - hb_retc( "" ); + hb_retc( NULL ); } else hb_errRT_BASE_SubstR( EG_ARG, 1106, NULL, "REPLICATE", 2, hb_paramError( 1 ), hb_paramError( 2 ) ); diff --git a/harbour/source/rtl/saverest.c b/harbour/source/rtl/saverest.c index 60835c3f73..1d3a8b7f1c 100644 --- a/harbour/source/rtl/saverest.c +++ b/harbour/source/rtl/saverest.c @@ -67,9 +67,7 @@ HB_FUNC( SAVESCREEN ) pBuffer = hb_xgrab( uiSize ); hb_gtSave( uiTop, uiLeft, uiBottom, uiRight, pBuffer ); - hb_retclen( ( char * ) pBuffer, uiSize ); - - hb_xfree( ( char * ) pBuffer ); + hb_retclen_buffer( ( char * ) pBuffer, uiSize ); } HB_FUNC( RESTSCREEN ) diff --git a/harbour/source/rtl/space.c b/harbour/source/rtl/space.c index 4acee79dd4..c8d8639ce1 100644 --- a/harbour/source/rtl/space.c +++ b/harbour/source/rtl/space.c @@ -72,11 +72,10 @@ HB_FUNC( SPACE ) /* hb_errRT_BASE( EG_STROVERFLOW, 1233, NULL, "SPACE" ); */ hb_xmemset( szResult, ' ', lLen ); - hb_retclen( szResult, lLen ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, lLen ); } else - hb_retc( "" ); + hb_retc( NULL ); } else hb_errRT_BASE_SubstR( EG_ARG, 1105, NULL, "SPACE", 1, hb_paramError( 1 ) ); diff --git a/harbour/source/rtl/str.c b/harbour/source/rtl/str.c index e0cdf46111..ca9fbe80e9 100644 --- a/harbour/source/rtl/str.c +++ b/harbour/source/rtl/str.c @@ -87,12 +87,9 @@ HB_FUNC( STR ) char * szResult = hb_itemStr( pNumber, pWidth, pDec ); if( szResult ) - { - hb_retc( szResult ); - hb_xfree( szResult ); - } + hb_retc_buffer( szResult ); else - hb_retc( "" ); + hb_retc( NULL ); } else hb_errRT_BASE_SubstR( EG_ARG, 1099, NULL, "STR", 3, hb_paramError( 1 ), hb_paramError( 2 ), hb_paramError( 3 ) ); diff --git a/harbour/source/rtl/strtran.c b/harbour/source/rtl/strtran.c index 45d5cd4571..5bfdd1609d 100644 --- a/harbour/source/rtl/strtran.c +++ b/harbour/source/rtl/strtran.c @@ -85,7 +85,7 @@ HB_FUNC( STRTRAN ) if( !ulStart ) { /* Clipper seems to work this way */ - hb_retc( "" ); + hb_retc( NULL ); } else if( ulStart > 0 ) { @@ -174,8 +174,7 @@ HB_FUNC( STRTRAN ) i++; } } - hb_retclen( szResult, ulLength ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, ulLength ); } else hb_retclen( szText, ulText ); diff --git a/harbour/source/rtl/strzero.c b/harbour/source/rtl/strzero.c index 90b7af7f73..d31b5d3676 100644 --- a/harbour/source/rtl/strzero.c +++ b/harbour/source/rtl/strzero.c @@ -116,11 +116,10 @@ HB_FUNC( STRZERO ) szResult[ ulPos++ ] = '0'; } - hb_retc( szResult ); - hb_xfree( szResult ); + hb_retc_buffer( szResult ); } else - hb_retc( "" ); + hb_retc( NULL ); } else #ifdef HB_C52_STRICT diff --git a/harbour/source/rtl/stuff.c b/harbour/source/rtl/stuff.c index 0769306683..e480c2c443 100644 --- a/harbour/source/rtl/stuff.c +++ b/harbour/source/rtl/stuff.c @@ -83,13 +83,12 @@ HB_FUNC( STUFF ) hb_xmemcpy( szResult + ulPos + ulInsert, szText + ulPos + ulDel, ulText - ( ulPos + ulDel ) ); szResult[ ulTotalLen ] = '\0'; - hb_retclen( szResult, ulTotalLen ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, ulTotalLen ); } else - hb_retc( "" ); + hb_retc( NULL ); } else - hb_retc( "" ); + hb_retc( NULL ); } diff --git a/harbour/source/rtl/transfrm.c b/harbour/source/rtl/transfrm.c index 487e163a2c..02c09c8c81 100644 --- a/harbour/source/rtl/transfrm.c +++ b/harbour/source/rtl/transfrm.c @@ -590,8 +590,7 @@ HB_FUNC( TRANSFORM ) if( uiPicFlags & PF_EMPTY ) memset( szResult, ' ', ulResultPos ); - hb_retclen( szResult, ( uiPicFlags & PF_WIDTH && ulResultPos > ulParamS ) ? ulParamS : ulResultPos ); - hb_xfree( szResult ); + hb_retclen_buffer( szResult, ( uiPicFlags & PF_WIDTH && ulResultPos > ulParamS ) ? ulParamS : ulResultPos ); } } else if( pPic || ISNIL( 2 ) ) /* Picture is an empty string or NIL */ @@ -605,12 +604,9 @@ HB_FUNC( TRANSFORM ) char * szStr = hb_itemStr( pValue, NULL, NULL ); if( szStr ) - { - hb_retc( szStr ); - hb_xfree( szStr ); - } + hb_retc_buffer( szStr ); else - hb_retc( "" ); + hb_retc( NULL ); } else if( HB_IS_DATE( pValue ) ) { diff --git a/harbour/source/rtl/valtostr.c b/harbour/source/rtl/valtostr.c index 6ffa52a820..f04ff71438 100644 --- a/harbour/source/rtl/valtostr.c +++ b/harbour/source/rtl/valtostr.c @@ -61,10 +61,10 @@ HB_FUNC( HB_VALTOSTR ) BOOL bFreeReq; char * buffer = hb_itemString( hb_param( 1, HB_IT_ANY ), &ulLen, &bFreeReq ); - hb_retclen( buffer, ulLen ); - if( bFreeReq ) - hb_xfree( buffer ); + hb_retclen_buffer( buffer, ulLen ); + else + hb_retclen( buffer, ulLen ); } #endif diff --git a/harbour/source/rtl/version.c b/harbour/source/rtl/version.c index 8c19db4626..36f4ef240a 100644 --- a/harbour/source/rtl/version.c +++ b/harbour/source/rtl/version.c @@ -65,22 +65,16 @@ HB_FUNC( OS ) { - char * pszPlatform = hb_verPlatform(); - hb_retc( pszPlatform ); - hb_xfree( pszPlatform ); + hb_retc_buffer( hb_verPlatform() ); } HB_FUNC( HB_COMPILER ) { - char * pszCompiler = hb_verCompiler(); - hb_retc( pszCompiler ); - hb_xfree( pszCompiler ); + hb_retc_buffer( hb_verCompiler() ); } HB_FUNC( VERSION ) { - char * pszVersion = hb_verHarbour(); - hb_retc( pszVersion ); - hb_xfree( pszVersion ); + hb_retc_buffer( hb_verHarbour() ); } diff --git a/harbour/source/vm/extend.c b/harbour/source/vm/extend.c index 5e056eb1f5..24e581169f 100644 --- a/harbour/source/vm/extend.c +++ b/harbour/source/vm/extend.c @@ -502,11 +502,11 @@ void HB_EXPORT hb_retc( char * szText ) hb_itemPutC( &hb_stack.Return, szText ); } -void HB_EXPORT hb_retc_buffer( char * szText, ULONG ulLen ) +void HB_EXPORT hb_retc_buffer( char * szText ) { HB_TRACE(HB_TR_DEBUG, ("hb_retcbuffer(%s, %lu)", szText, ulLen)); - hb_itemPutCPtr( &hb_stack.Return, szText, ulLen ); + hb_itemPutCPtr( &hb_stack.Return, szText, strlen( szText ) ); } void HB_EXPORT hb_retc_const( char * szText ) @@ -523,6 +523,13 @@ void HB_EXPORT hb_retclen( char * szText, ULONG ulLen ) hb_itemPutCL( &hb_stack.Return, szText, ulLen ); } +void HB_EXPORT hb_retclen_buffer( char * szText, ULONG ulLen ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_retclen_buffer(%s, %lu)", szText, ulLen)); + + hb_itemPutCPtr( &hb_stack.Return, szText, ulLen ); +} + /* szDate must have YYYYMMDD format */ void HB_EXPORT hb_retds( char * szDate ) @@ -786,4 +793,4 @@ void HB_EXPORT hb_stornd( double dNumber, int iParam, ... ) else if( bByRef || iParam == -1 ) hb_itemPutND( pItem, dNumber ); } -} +} \ No newline at end of file diff --git a/harbour/source/vm/itemapi.c b/harbour/source/vm/itemapi.c index aa3a4d42ba..3b6a8a6310 100644 --- a/harbour/source/vm/itemapi.c +++ b/harbour/source/vm/itemapi.c @@ -65,6 +65,7 @@ * hb_itemGetCPtr() * hb_itemGetCLen() * hb_itemGetNLen() + * hb_itemPutCConst() * hb_itemPutNLen() * hb_itemPutNDLen() * hb_itemPutNILen() @@ -192,16 +193,23 @@ PHB_ITEM hb_itemPutC( PHB_ITEM pItem, char * szText ) else pItem = hb_itemNew( NULL ); - if( szText == NULL ) - szText = ""; - pItem->type = HB_IT_STRING; - pItem->item.asString.length = strlen( szText ); - pItem->item.asString.value = ( char * ) hb_xgrab( pItem->item.asString.length + 1 ); - pItem->item.asString.bPcode = FALSE; - pItem->item.asString.puiHolders = ( USHORT * ) hb_xgrab( sizeof( USHORT ) ); - * ( pItem->item.asString.puiHolders ) = 1; - strcpy( pItem->item.asString.value, szText ); + + if( szText == NULL ) + { + pItem->item.asString.length = 0; + pItem->item.asString.value = ""; + pItem->item.asString.bPcode = TRUE; + } + else + { + pItem->item.asString.length = strlen( szText ); + pItem->item.asString.value = ( char * ) hb_xgrab( pItem->item.asString.length + 1 ); + pItem->item.asString.bPcode = FALSE; + pItem->item.asString.puiHolders = ( USHORT * ) hb_xgrab( sizeof( USHORT ) ); + * ( pItem->item.asString.puiHolders ) = 1; + strcpy( pItem->item.asString.value, szText ); + } return pItem; } @@ -215,14 +223,20 @@ PHB_ITEM hb_itemPutCConst( PHB_ITEM pItem, char * szText ) else pItem = hb_itemNew( NULL ); - if( szText == NULL ) - szText = ""; - pItem->type = HB_IT_STRING; - pItem->item.asString.length = strlen( szText ); - pItem->item.asString.value = szText; pItem->item.asString.bPcode = TRUE; + if( szText == NULL ) + { + pItem->item.asString.length = 0; + pItem->item.asString.value = ""; + } + else + { + pItem->item.asString.length = strlen( szText ); + pItem->item.asString.value = szText; + } + return pItem; } @@ -239,20 +253,24 @@ PHB_ITEM hb_itemPutCL( PHB_ITEM pItem, char * szText, ULONG ulLen ) trash if the szText buffer is NULL, at least with hb_retclen(). [vszakats] */ + pItem->type = HB_IT_STRING; + if( szText == NULL ) { - szText = ""; - ulLen = 0; + pItem->item.asString.length = 0; + pItem->item.asString.value = ""; + pItem->item.asString.bPcode = TRUE; + } + else + { + pItem->item.asString.length = ulLen; + pItem->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); + hb_xmemcpy( pItem->item.asString.value, szText, ulLen ); + pItem->item.asString.value[ ulLen ] = '\0'; + pItem->item.asString.bPcode = FALSE; + pItem->item.asString.puiHolders = ( USHORT * ) hb_xgrab( sizeof( USHORT ) ); + * ( pItem->item.asString.puiHolders ) = 1; } - - pItem->type = HB_IT_STRING; - pItem->item.asString.length = ulLen; - pItem->item.asString.value = ( char * ) hb_xgrab( ulLen + 1 ); - hb_xmemcpy( pItem->item.asString.value, szText, ulLen ); - pItem->item.asString.value[ ulLen ] = '\0'; - pItem->item.asString.bPcode = FALSE; - pItem->item.asString.puiHolders = ( USHORT * ) hb_xgrab( sizeof( USHORT ) ); - * ( pItem->item.asString.puiHolders ) = 1; return pItem; }