19991111-01:18 GMT+1 Victor Szel <info@szelvesz.hu>

This commit is contained in:
Viktor Szakats
1999-11-11 00:30:38 +00:00
parent 8ed0a85e06
commit 5cf0426d93
6 changed files with 127 additions and 80 deletions

View File

@@ -1,3 +1,33 @@
19991111-01:18 GMT+1 Victor Szel <info@szelvesz.hu>
* source/rtl/fm.c
! hb_xrealloc() check for a passed NULL pointer.
! hb_xrealloc() signature check moved before any MEMINFO usage.
! Explicit \n changed to hb_consoleGetNewLine() call.
! 256 buffer size for symbol names changed to HB_SYMBOL_NAME_LEN constant.
! Now the hb_xrealloc() is returning a NULL pointer (instead of trash)
when the passed length is zero, and it's also freeing the pointer with
free().
% hb_xrealloc() - pResult variable optimized out.
* source/rtl/hbsetup.h
+ HB_SYMBOL_NAME_LEN constant added to set the maximum handled symbol
name length in Harbour (both compiler/runtime), this can be set to any
value by specifying C_USR=-DHB_SYMBOL_NAME_LEN=10 in the make process.
TODO: Add support for the compiler to cut the symbols to this size on
compile. This way the /10 switch may be replaced by this #define,
since /10 works perfect when the RTL also "knows" about this limit,
and is compiled using this limit.
* include/hbtrace.h
! Every macro names prefixed with HB_
* source/vm/hvm.c
! Explicit buffer sizes are now determined using the HB_SYMBOL_NAME_LEN
constant. They can't overrun anymore.
* source/vm/dynsym.c
% hb_dynsymGet(), hb_dynsymFindName() - Using local stack for temp symbol
name buffer instead of hb_xgrab()/hb_xfree(). Some optimalizations.
Now they will cut the symbol name to the HB_SYMBOL_NAME_LEN size, so
by setting this to 10, we're 100% Cl*pper compatible from this respect.
These functions are now faster.
19991110-23:20 GMT+1 Victor Szel <info@szelvesz.hu>
* include/hbtrace.h
% Excluded trace calls are converted to nohting instead of "do {} while 0"

View File

@@ -157,6 +157,17 @@
#define HARBOUR_USE_GTAPI
#endif
/* ***********************************************************************
* You can set here the maximum symbol name length handled by Harbour
* compiler and runtime. You can override this setting in the make process.
*
* By default this value is 128
*/
#ifndef HB_SYMBOL_NAME_LEN
#define HB_SYMBOL_NAME_LEN 128
#endif
/* ***********************************************************************
* Operating system specific definitions
*/

View File

@@ -63,11 +63,11 @@
/*
* This is black magic...
* What we do here is to generate calls to ECHO_CREATE only for those
* What we do here is to generate calls to HB_ECHO_CREATE only for those
* levels that are less or equal to the COMPILATION time HB_TR_LEVEL.
*/
#define ECHO_CREATE(l, x) do \
#define HB_ECHO_CREATE(l, x) do \
{ \
if (hb_tr_level() >= l) { \
hb_tr_file_ = __FILE__; \
@@ -78,43 +78,43 @@
} while (0)
#if HB_TR_LEVEL >= HB_TR_DEBUG
#define _ECHO_TRACE_HB_TR_DEBUG(x) ECHO_CREATE(HB_TR_DEBUG, x)
#define HB_ECHO_TRACE_HB_TR_DEBUG(x) HB_ECHO_CREATE(HB_TR_DEBUG, x)
#else
#define _ECHO_TRACE_HB_TR_DEBUG(x)
#define HB_ECHO_TRACE_HB_TR_DEBUG(x)
#endif
#if HB_TR_LEVEL >= HB_TR_INFO
#define _ECHO_TRACE_HB_TR_INFO(x) ECHO_CREATE(HB_TR_INFO, x)
#define HB_ECHO_TRACE_HB_TR_INFO(x) HB_ECHO_CREATE(HB_TR_INFO, x)
#else
#define _ECHO_TRACE_HB_TR_INFO(x)
#define HB_ECHO_TRACE_HB_TR_INFO(x)
#endif
#if HB_TR_LEVEL >= HB_TR_WARNING
#define _ECHO_TRACE_HB_TR_WARNING(x) ECHO_CREATE(HB_TR_WARNING, x)
#define HB_ECHO_TRACE_HB_TR_WARNING(x) HB_ECHO_CREATE(HB_TR_WARNING, x)
#else
#define _ECHO_TRACE_HB_TR_WARNING(x)
#define HB_ECHO_TRACE_HB_TR_WARNING(x)
#endif
#if HB_TR_LEVEL >= HB_TR_ERROR
#define _ECHO_TRACE_HB_TR_ERROR(x) ECHO_CREATE(HB_TR_ERROR, x)
#define HB_ECHO_TRACE_HB_TR_ERROR(x) HB_ECHO_CREATE(HB_TR_ERROR, x)
#else
#define _ECHO_TRACE_HB_TR_ERROR(x)
#define HB_ECHO_TRACE_HB_TR_ERROR(x)
#endif
#if HB_TR_LEVEL >= HB_TR_FATAL
#define _ECHO_TRACE_HB_TR_FATAL(x) ECHO_CREATE(HB_TR_FATAL, x)
#define HB_ECHO_TRACE_HB_TR_FATAL(x) HB_ECHO_CREATE(HB_TR_FATAL, x)
#else
#define _ECHO_TRACE_HB_TR_FATAL(x)
#define HB_ECHO_TRACE_HB_TR_FATAL(x)
#endif
#if 1 /* always! */
#define _ECHO_TRACE_HB_TR_ALWAYS(x) ECHO_CREATE(HB_TR_ALWAYS, x)
#define HB_ECHO_TRACE_HB_TR_ALWAYS(x) HB_ECHO_CREATE(HB_TR_ALWAYS, x)
#else
#define _ECHO_TRACE_HB_TR_ALWAYS(x)
#define HB_ECHO_TRACE_HB_TR_ALWAYS(x)
#endif
#define HB_TRACE(l, x) _ECHO_TRACE_##l(x)
#define HB_TRACE(l, x) HB_ECHO_TRACE_##l(x)

View File

@@ -49,6 +49,10 @@
*
*/
/* TODO: hb_xrealloc() is not completely consistent now, since it will
destroy the pointer when called with a zero parameter, and return NULL.
But will not accept NULL pointer as a parameter. [vszel] */
/* NOTE: If you turn this on, the memory subsystem will collect information
about several statistical data about memory management, it will show
these on exit if memory seem to have leaked.
@@ -76,7 +80,7 @@ typedef struct _HB_MEMINFO
ULONG ulSignature;
ULONG ulSize;
USHORT uiProcLine;
char szProcName[ 256 ];
char szProcName[ HB_SYMBOL_NAME_LEN + 1 ];
struct _HB_MEMINFO * pPrevBlock;
struct _HB_MEMINFO * pNextBlock;
} HB_MEMINFO, * PHB_MEMINFO;
@@ -234,61 +238,75 @@ void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */
PHB_MEMINFO pMemBlock;
ULONG ulMemSize;
void * pResult;
HB_TRACE(HB_TR_DEBUG, ("hb_xrealloc(%p, %lu)", pMem, ulSize));
if( ! pMem )
hb_errInternal( 9999, "hb_xrealloc called with a NULL pointer", NULL, NULL );
pMemBlock = ( PHB_MEMINFO ) ( ( char * ) pMem - sizeof( HB_MEMINFO ) );
if( pMemBlock->ulSignature != HB_MEMINFO_SIGNATURE )
hb_errInternal( 9999, "hb_xrealloc called with a bad pointer", NULL, NULL );
ulMemSize = pMemBlock->ulSize;
if( ulSize == 0 )
{
DeleteNode( pMemBlock );
free( ( void * ) pMem );
pMem = NULL;
s_lMemoryBlocks--;
}
else
{
if( pMemBlock->ulSignature != HB_MEMINFO_SIGNATURE )
hb_errInternal( 9999, "hb_xrealloc called with a bad pointer", NULL, NULL );
pMem = realloc( pMemBlock, ulSize + sizeof( HB_MEMINFO ) );
pResult = realloc( pMemBlock, ulSize + sizeof( HB_MEMINFO ) );
if( pResult )
if( pMem )
{
( ( PHB_MEMINFO ) pResult )->pPrevBlock = pMemBlock->pPrevBlock;
( ( PHB_MEMINFO ) pResult )->pNextBlock = pMemBlock->pNextBlock;
( ( PHB_MEMINFO ) pMem )->pPrevBlock = pMemBlock->pPrevBlock;
( ( PHB_MEMINFO ) pMem )->pNextBlock = pMemBlock->pNextBlock;
if( pMemBlock->pPrevBlock )
( ( PHB_MEMINFO ) pResult )->pPrevBlock->pNextBlock = ( PHB_MEMINFO ) pResult;
if( ( ( PHB_MEMINFO ) pResult )->pNextBlock )
( ( PHB_MEMINFO ) pResult )->pNextBlock->pPrevBlock = ( PHB_MEMINFO ) pResult;
( ( PHB_MEMINFO ) pMem )->pPrevBlock->pNextBlock = ( PHB_MEMINFO ) pMem;
if( ( ( PHB_MEMINFO ) pMem )->pNextBlock )
( ( PHB_MEMINFO ) pMem )->pNextBlock->pPrevBlock = ( PHB_MEMINFO ) pMem;
}
}
if( ! pResult )
hb_errInternal( 9999, "hb_xrealloc can't reallocate memory", NULL, NULL );
( ( PHB_MEMINFO ) pResult )->ulSignature = HB_MEMINFO_SIGNATURE;
( ( PHB_MEMINFO ) pResult )->ulSize = ulSize; /* size of the memory block */
if( ! ulSize )
s_lMemoryBlocks--;
s_lMemoryConsumed += ( ulSize - ulMemSize );
if( s_lMemoryMaxConsumed < s_lMemoryConsumed )
s_lMemoryMaxConsumed = s_lMemoryConsumed;
return ( char * ) pResult + sizeof( HB_MEMINFO );
if( ! pMem )
hb_errInternal( 9999, "hb_xrealloc can't reallocate memory", NULL, NULL );
( ( PHB_MEMINFO ) pMem )->ulSignature = HB_MEMINFO_SIGNATURE;
( ( PHB_MEMINFO ) pMem )->ulSize = ulSize; /* size of the memory block */
return ( char * ) pMem + sizeof( HB_MEMINFO );
#else
void * pResult;
HB_TRACE(HB_TR_DEBUG, ("hb_xrealloc(%p, %lu)", pMem, ulSize));
pResult = realloc( ( char * ) pMem, ulSize );
if( ! pMem )
hb_errInternal( 9999, "hb_xrealloc called with a NULL pointer", NULL, NULL );
if( ! pResult )
hb_errInternal( 9999, "hb_xrealloc can't reallocate memory", NULL, NULL );
if( ulSize == 0 )
{
free( ( void * ) pMem );
pMem = NULL;
}
else
{
pMem = realloc( ( char * ) pMem, ulSize );
return ( char * ) pResult;
if( ! pMem )
hb_errInternal( 9999, "hb_xrealloc can't reallocate memory", NULL, NULL );
}
return ( char * ) pMem;
#endif
}
@@ -316,7 +334,7 @@ void hb_xfree( void * pMem ) /* frees fixed memory */
free( ( void * ) pMemBlock );
}
else
hb_errInternal( 9999, "hb_xfree called with a null pointer", NULL, NULL );
hb_errInternal( 9999, "hb_xfree called with a NULL pointer", NULL, NULL );
#else
@@ -327,7 +345,7 @@ void hb_xfree( void * pMem ) /* frees fixed memory */
free( ( char * ) pMem - sizeof( ULONG ) - sizeof( ULONG ) );
}
else
hb_errInternal( 9999, "hb_xfree called with a null pointer", NULL, NULL );
hb_errInternal( 9999, "hb_xfree called with a NULL pointer", NULL, NULL );
#endif
}
@@ -358,29 +376,33 @@ void hb_xexit( void ) /* Deinitialize fixed memory subsystem */
#ifdef HB_FM_STATISTICS
if( s_lMemoryBlocks || hb_cmdargCheck( "INFO" ) )
{
char buffer[ 100 ];
hb_outerr( hb_consoleGetNewLine(), 0 );
hb_outerr( "----------------------------------------", 0 );
hb_outerr( hb_consoleGetNewLine(), 0 );
sprintf( buffer, "Total memory allocated: %li bytes (%li blocks)", s_lMemoryMaxConsumed, s_lMemoryMaxBlocks );
hb_outerr( buffer, 0 );
if( s_lMemoryBlocks )
/* NOTE: Put this in a separate block to optimize stack space usage [vszel] */
{
char buffer[ 100 ];
hb_outerr( hb_consoleGetNewLine(), 0 );
sprintf( buffer, "WARNING! Memory allocated but not released: %li bytes (%li blocks)", s_lMemoryConsumed, s_lMemoryBlocks );
hb_outerr( "----------------------------------------", 0 );
hb_outerr( hb_consoleGetNewLine(), 0 );
sprintf( buffer, "Total memory allocated: %li bytes (%li blocks)", s_lMemoryMaxConsumed, s_lMemoryMaxBlocks );
hb_outerr( buffer, 0 );
if( s_lMemoryBlocks )
{
hb_outerr( hb_consoleGetNewLine(), 0 );
sprintf( buffer, "WARNING! Memory allocated but not released: %li bytes (%li blocks)", s_lMemoryConsumed, s_lMemoryBlocks );
hb_outerr( buffer, 0 );
}
}
if( s_pFirstBlock )
{
char buffer[ HB_SYMBOL_NAME_LEN + 40 ];
PHB_MEMINFO pMemBlock = s_pFirstBlock;
USHORT ui = 1;
do
{
sprintf( buffer, "\nblock %i: %s line %i", ui++, pMemBlock->szProcName,
sprintf( buffer, "%sblock %i: %s line %i", hb_consoleGetNewLine(), ui++, pMemBlock->szProcName,
pMemBlock->uiProcLine );
HB_TRACE( HB_TR_ERROR, (buffer));
pMemBlock = pMemBlock->pNextBlock;

View File

@@ -131,43 +131,27 @@ PHB_DYNS hb_dynsymNew( PHB_SYMB pSymbol ) /* creates a new dynamic symbol */
PHB_DYNS hb_dynsymGet( char * szName ) /* finds and creates a symbol if not found */
{
PHB_DYNS pDynSym;
char * szUprName;
char szUprName[ HB_SYMBOL_NAME_LEN + 1 ];
HB_TRACE(HB_TR_DEBUG, ("hb_dynsymGet(%s)", szName));
szUprName = ( char * ) hb_xgrab( strlen( szName ) + 1 );
strcpy( szUprName, szName ); /* make a copy as we may get a const string */
hb_strupr( szUprName ); /* turn it uppercase */
/* if( strlen( szUprName ) > 10 )
szUprName[ 10 ] = '\0'; keeps this here for 10 chars /c compatibility mode */
pDynSym = hb_dynsymFind( szUprName );
/* make a copy as we may get a const string, the turn it to uppercase */
pDynSym = hb_dynsymFind( hb_strncpyUpper( szUprName, szName, HB_SYMBOL_NAME_LEN ) );
if( ! pDynSym ) /* Does it exists ? */
pDynSym = hb_dynsymNew( hb_symbolNew( szUprName ) ); /* Make new symbol */
hb_xfree( szUprName ); /* release memory */
return pDynSym;
}
PHB_DYNS hb_dynsymFindName( char * szName ) /* finds a symbol */
{
PHB_DYNS pDynSym;
ULONG ulLen;
char * szUprName;
char szUprName[ HB_SYMBOL_NAME_LEN + 1 ];
HB_TRACE(HB_TR_DEBUG, ("hb_dynsymFindName(%s)", szName));
ulLen = strlen( szName );
szUprName = ( char * ) hb_xgrab( ulLen + 1 );
hb_strncpyUpper( szUprName, szName, ulLen ); /* make a copy as we may get a const string */
/* if( strlen( szUprName ) > 10 )
szUprName[ 10 ] = '\0'; keeps this here for 10 chars /c compatibility mode */
pDynSym = hb_dynsymFind( szUprName );
hb_xfree( szUprName ); /* release memory */
/* make a copy as we may get a const string */
pDynSym = hb_dynsymFind( hb_strncpyUpper( szUprName, szName, HB_SYMBOL_NAME_LEN ) );
return pDynSym;
}

View File

@@ -3129,7 +3129,7 @@ void hb_stackDispCall( void )
while( pBase != hb_stack.pItems )
{
char buffer[ 128 ];
char buffer[ HB_SYMBOL_NAME_LEN + HB_SYMBOL_NAME_LEN + 32 ];
pBase = hb_stack.pItems + pBase->item.asSymbol.stackbase;
@@ -3661,7 +3661,7 @@ void hb_vmRequestCancel( void )
if( hb_set.HB_SET_CANCEL )
{
char buffer[ 128 ];
char buffer[ HB_SYMBOL_NAME_LEN + 32 ];
hb_outerr( hb_consoleGetNewLine(), 0 );
sprintf( buffer, "Cancelled at: %s (%i)", hb_stack.pBase->item.asSymbol.value->szName, hb_stack.pBase->item.asSymbol.lineno );