Skip to content

Commit

Permalink
Optimized allocations; fixed invalid triglyph;improve enable/disable …
Browse files Browse the repository at this point in the history
…memory loggin; improved linux mac address resolution
  • Loading branch information
d3x0r committed Jul 30, 2024
1 parent abe5656 commit 5ebc9b9
Show file tree
Hide file tree
Showing 15 changed files with 521 additions and 280 deletions.
4 changes: 3 additions & 1 deletion include/procreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,11 @@ PROCREG_PROC( void, RegisterAndCreateGlobalWithInit )( POINTER *ppGlobal, uintpt
* Add a transaltion tree index at the same time.
*/
PROCREG_PROC( CTEXTSTR, SaveNameConcatN )( CTEXTSTR name1, ... );
// no space stripping, saves literal text
// no space stripping, saves literal text (case insensitive indexing; '/' and '\' are the same)
PROCREG_PROC( CTEXTSTR, SaveText )( CTEXTSTR text );

// no space stripping, saves literal text (case sensitive indexing; '/' and '\' are the same)
PROCREG_PROC( CTEXTSTR, SaveTextCS )( CTEXTSTR text );

PROCREG_NAMESPACE_END

Expand Down
3 changes: 3 additions & 0 deletions include/sack_typelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3147,9 +3147,12 @@ TYPELIB_PROC CPOINTER TYPELIB_CALLTYPE FindInBinaryTree( PTREEROOT root, uintp


// result of fuzzy routine is 0 = match. 100 = inexact match
// 101 = no longer matching; result with last 100 match.
// 1 = no match, actual may be larger
// -1 = no match, actual may be lesser
// 100 = inexact match- checks nodes near for better match.
//
// Basically scans left and right from 100 match to find best match.
TYPELIB_PROC CPOINTER TYPELIB_CALLTYPE LocateInBinaryTree( PTREEROOT root, uintptr_t key
, int (CPROC*fuzzy)( uintptr_t psv, uintptr_t node_key ) );

Expand Down
7 changes: 6 additions & 1 deletion include/sharemem.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,12 @@ MEM_PROC void MEM_API GetMemStats ( uint32_t *pFree, uint32_t *pUsed, uint32_t
bTrueFalse : if TRUE, allocation logging is turned on. Enables
logging when each block is Allocated, Released,
or Held. */
MEM_PROC int MEM_API SetAllocateLogging ( LOGICAL bTrueFalse );
MEM_PROC int MEM_API SetAllocateLoggingEx ( LOGICAL bTrueFalse DBG_PASS );
#define SetAllocateLogging(tf) SetAllocateLoggingEx( tf DBG_SRC )
MEM_PROC int MEM_API ClearAllocateLoggingEx ( LOGICAL bTrueFalse DBG_PASS );
#define ClearAllocateLogging(tf) ClearAllocateLoggingEx( tf DBG_SRC )
MEM_PROC int MEM_API ResetAllocateLoggingEx ( LOGICAL bTrueFalse DBG_PASS );
#define ResetAllocateLogging(tf) ResetAllocateLoggingEx( tf DBG_SRC )
/* disables storing file/line, also disables auto GetMemStats
checking
Parameters
Expand Down
6 changes: 5 additions & 1 deletion src/SQLlib/sqlstruc.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ typedef struct data_collection_tag
size_t *result_len;
TEXTSTR *results;
//uint32_t nResults; // this is columns
TEXTSTR *fields;
CTEXTSTR *fields;
PDATALIST *ppdlResults;
#if defined( USE_SQLITE ) || defined( USE_SQLITE_INTERFACE )
sqlite3_stmt *stmt;
Expand Down Expand Up @@ -172,6 +172,9 @@ struct odbc_queue
PLINKQUEUE connections;
};

typedef char SQL_TIME_BUFFER[32];
#define MAXSQL_TIME_BUFFERSPERSET 256
DeclareSet( SQL_TIME_BUFFER );

#ifdef SQLLIB_SOURCE
struct pssql_global
Expand Down Expand Up @@ -227,6 +230,7 @@ struct pssql_global

// ----- shared with option code; these need to be shared between instances.
PTREEROOT tables; // some
PSQL_TIME_BUFFERSET time_buffers;

};
#endif
Expand Down
41 changes: 29 additions & 12 deletions src/SQLlib/sqlstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2368,10 +2368,7 @@ void ReleaseCollectionResults( PCOLLECT pCollect, int bEntire )
int idx;
if( bEntire && pCollect->fields )
{
for( idx = 0; idx < pCollect->columns; idx++ )
{
Release( (POINTER)pCollect->fields[idx] );
}
// column text is saved in name cache
Release( (POINTER)pCollect->fields );
pCollect->fields = NULL;
Release( pCollect->result_len );
Expand Down Expand Up @@ -3436,7 +3433,7 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )

# if defined( USE_SQLITE ) || defined( USE_SQLITE_INTERFACE )
if( odbc->flags.bSQLite_native ) {
val->name = DupCStr( sqlite3_column_name( collection->stmt, idx - 1 ) );
val->name = (TEXTSTR)SaveTextCS( sqlite3_column_name( collection->stmt, idx - 1 ) );
val->nameLen = StrLen( val->name );
}
#endif
Expand Down Expand Up @@ -3473,7 +3470,8 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )
result_cmd = WM_SQL_RESULT_ERROR;
break;
}
val->name = DupCStrLen( colname, namelen );
colname[namelen] = 0;
val->name = (TEXTSTR)SaveTextCS( colname );
val->nameLen = namelen;
}
#endif
Expand Down Expand Up @@ -3507,7 +3505,7 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )
if( !collection->fields )
{
len = ( sizeof( CTEXTSTR ) * (collection->columns + 1) );
collection->fields = NewArray( TEXTSTR, collection->columns + 1 );
collection->fields = NewArray( CTEXTSTR, collection->columns + 1 );
MemSet( collection->fields, 0, len );
len = (sizeof( size_t ) * (collection->columns + 1));
collection->result_len = NewArray( size_t, collection->columns + 1 );
Expand All @@ -3531,7 +3529,7 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )
if( odbc->flags.bSQLite_native )
{
collection->fields[idx-1] =
DupCStr( sqlite3_column_name(collection->stmt
SaveTextCS( sqlite3_column_name(collection->stmt
, idx - 1 ) );
collection->column_types[idx-1] = sqlite3_column_type( collection->stmt, idx - 1 );
}
Expand Down Expand Up @@ -3583,7 +3581,7 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )
}
//lprintf( "col %s is %d %d", colname, collection->colsizes[idx-1], collection->coltypes[idx-1] );
colname[namelen] = 0; // always nul terminate this.
collection->fields[idx-1] = StrDup( colname );
collection->fields[idx-1] = SaveTextCS( colname );
}
#endif
} // for
Expand Down Expand Up @@ -3865,6 +3863,7 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )
case SQL_VARCHAR:
case SQL_LONGVARCHAR:
val->value_type = JSOX_VALUE_STRING;
if( val->string ) Release( val->string );
do {
rc = SQLGetData( collection->hstmt
, (short)(idx)
Expand Down Expand Up @@ -3912,6 +3911,7 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )
case SQL_WCHAR:
case SQL_WVARCHAR:
case SQL_WLONGVARCHAR:
if( val->string ) Release( val->string );
val->value_type = JSOX_VALUE_STRING;
rc = SQLGetData( collection->hstmt
, (short)(idx)
Expand Down Expand Up @@ -3962,9 +3962,10 @@ int __GetSQLResult( PODBC odbc, PCOLLECT collection, int bMore )
if( rc == SQL_SUCCESS ) {
if( ResultLen == SQL_NULL_DATA ) {
val->value_type = JSOX_VALUE_NULL;
val->string = NULL;
if( pvtData )vtprintf( pvtData, "%sNULL", idx > 1 ? "," : "" );
}else {
char *isoTime = NewArray( char, 32 );
char *isoTime = (char*)GetFromSet( SQL_TIME_BUFFER, &g.time_buffers );
val->stringLen = snprintf( isoTime, 32, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ"
, ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction );
val->value_type = JSOX_VALUE_DATE;
Expand Down Expand Up @@ -4907,7 +4908,23 @@ void SQLEndQuery( PODBC odbc )
//-----------------------------------------------------------------------

void ReleaseSQLResults( PDATALIST *ppdlResults ) {
jsox_dispose_message( ppdlResults );
if( ppdlResults && *ppdlResults ) {
PDATALIST pdlResults = *ppdlResults;
INDEX idx;
struct jsox_value_container * val;
DATA_FORALL( pdlResults, idx, struct jsox_value_container *, val ) {
// names are saved in cache and shouldn't be released...
//if( val->base.name ) Release( val->base.name );
//lprintf( "Value type:%s %s %d", val->string, val->name, val->value_type );
if( val->value_type == JSOX_VALUE_DATE ){
DeleteFromSet( SQL_TIME_BUFFER, &g.time_buffers, val->string );
} else
if( val->string ) Release( val->string );
}
DeleteDataList( ppdlResults );
*ppdlResults = NULL;
}
//jsox_dispose_message( ppdlResults );
}

int SQLRecordQuery_js( PODBC odbc
Expand All @@ -4921,7 +4938,7 @@ int SQLRecordQuery_js( PODBC odbc
int once = 0;
PCOLLECT collection;
if( !(*pdlResults) )
(*pdlResults) = CreateDataList( sizeof ( struct jsox_value_container ) );
(*pdlResults) = CreateDataList( sizeof ( struct jsox_value_container ) );

// clean up what we think of as our result set data (reset to nothing)

Expand Down
4 changes: 2 additions & 2 deletions src/configlib/configscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -3113,7 +3113,7 @@ CONFIGSCR_PROC( PCONFIG_HANDLER, CreateConfigurationEvaluator )( void )
{
if( !(g._disabled_allocate_logging++) )
{
g._last_allocate_logging = SetAllocateLogging( FALSE );
g._last_allocate_logging = ClearAllocateLogging( FALSE );
}
}
pch = (PCONFIG_HANDLER)Allocate( sizeof( CONFIG_HANDLER ) );
Expand Down Expand Up @@ -3299,7 +3299,7 @@ CONFIGSCR_PROC( void, DestroyConfigurationEvaluator )( PCONFIG_HANDLER pch )
g._disabled_allocate_logging--;
if( !g._disabled_allocate_logging )
{
SetAllocateLogging( g._last_allocate_logging );
ResetAllocateLogging( g._last_allocate_logging );
}
}
DeleteList( &pch->states );
Expand Down
12 changes: 9 additions & 3 deletions src/filesyslib/winfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ TEXTSTR ExpandPathExx( CTEXTSTR path, struct file_system_interface* fsi DBG_PASS
{
TEXTSTR tmp_path;
if( !path ) return NULL;
tmp_path = StrDup( path );
tmp_path = StrDupEx( path DBG_RELAY );
//LocalInit();
#if !defined( __FILESYS_NO_FILE_LOGGING__ )
if( ( *winfile_local ).flags.bLogOpenClose )
Expand Down Expand Up @@ -707,7 +707,8 @@ TEXTSTR ExpandPathExx( CTEXTSTR path, struct file_system_interface* fsi DBG_PASS
} else if( StrChr( path, '%' ) != NULL ) {
tmp_path = ExpandPathVariable( path );
} else {
tmp_path = StrDupEx( path DBG_RELAY );
// is already duplicated, no changes were made.
//tmp_path = StrDupEx( path DBG_RELAY );
}
}
{
Expand Down Expand Up @@ -1182,8 +1183,10 @@ struct file* FindFileByName( INDEX group, char const* filename, struct file_syst
INDEX idx;
LocalInit();
EnterCriticalSec( &( *winfile_local ).cs_files );
//lprintf( "Find file: %s in %p", filename, winfile_local->files );
LIST_FORALL( ( *winfile_local ).files, idx, struct file*, file )
{
//lprintf( "Is it %d %d %s?", !mount, file->mount == mount, file->name );
if( ( file->group == group )
&& ( PathCmp( file->name, filename ) == 0 )
&& ( ( !mount ) || file->mount == mount ) ) {
Expand All @@ -1196,6 +1199,7 @@ struct file* FindFileByName( INDEX group, char const* filename, struct file_syst
}

LeaveCriticalSec( &( *winfile_local ).cs_files );
//if( file ) lprintf( "found file" ); else lprintf( "file not found" );
return file;

}
Expand Down Expand Up @@ -1746,6 +1750,7 @@ FILE* sack_fopenEx( INDEX group, CTEXTSTR filename, CTEXTSTR opts, struct file_s
}
}
EnterCriticalSec( &( *winfile_local ).cs_files );
//lprintf( "Adding file to winfile_local.files... %p", winfile_local->files);
AddLink( &( *winfile_local ).files, file );
allocedIndex = 0;
LeaveCriticalSec( &( *winfile_local ).cs_files );
Expand Down Expand Up @@ -2909,14 +2914,15 @@ static void* CPROC sack_filesys_open( uintptr_t psv, const char* filename, const
#else
char *tmpFilename = StrDup( filename );
{ char* tmp; if( LONG_PATHCHAR ) for( tmp = tmpFilename; tmp[0]; tmp++ ) if( tmp[0] == '\\' ) tmp[0] = LONG_PATHCHAR; }
result = fopen( filename, opts );
result = fopen( tmpFilename, opts );
{
int h = fileno( (FILE*)result );
if( h >= 0 ) {
int flags = fcntl( h, F_GETFD, 0 );
if( flags >= 0 ) fcntl( h, F_SETFD, flags | FD_CLOEXEC );
}
}
Release( tmpFilename );
#endif

return result;
Expand Down
2 changes: 1 addition & 1 deletion src/memlib/memory_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ TEXTSTR DupCStrLenEx( const char * original, size_t chars DBG_PASS )
TEXTSTR result, _result;
if( !original )
return NULL;
_result = result = NewArray( TEXTCHAR, chars + 1 );// (TEXTSTR)AllocateEx( (len + 1) * sizeof( result[0] ) DBG_RELAY );
_result = result = /*NewArray( TEXTCHAR, chars + 1 );//*/ (TEXTSTR)AllocateEx( (chars + 1) * sizeof( result[0] ) DBG_RELAY );
len = 0;
while( len < chars ) ((*result++) = (*original++)), len++;
result[0] = 0;
Expand Down
Loading

0 comments on commit 5ebc9b9

Please sign in to comment.