@ -41,10 +41,13 @@ void Function_Release (IM3Function i_function)
{
m3Free ( i_function - > constants ) ;
for ( int i = 0 ; i < i_function - > numNames ; i + + )
{
// name can be an alias of fieldUtf8
if ( i_function - > name ! = i_function - > import . fieldUtf8 )
if ( i_function - > name s[ i ] ! = i_function - > import . fieldUtf8 )
{
m3Free ( i_function - > name ) ;
m3Free ( i_function - > names [ i ] ) ;
}
}
FreeImportInfo ( & i_function - > import ) ;
@ -90,10 +93,30 @@ void Function_FreeCompiledCode (IM3Function i_function)
cstr_t GetFunctionName ( IM3Function i_function )
{
u16 numNames = 0 ;
cstr_t * names = GetFunctionNames ( i_function , & numNames ) ;
if ( numNames > 0 )
return names [ 0 ] ;
else
return " <unnamed> " ;
}
cstr_t * GetFunctionNames ( IM3Function i_function , u16 * o_numNames )
{
if ( o_numNames = = NULL )
return NULL ;
if ( i_function - > import . fieldUtf8 )
return i_function - > import . fieldUtf8 ;
{
* o_numNames = 1 ;
return & i_function - > import . fieldUtf8 ;
}
else
return ( i_function - > name ) ? i_function - > name : " <unnamed> " ;
{
* o_numNames = i_function - > numNames ;
return i_function - > names ;
}
}
@ -616,7 +639,7 @@ _ (m3ReallocArray (& io_module->table0, IM3Function, endElement, io_mo
u32 functionIndex ;
_ ( ReadLEB_u32 ( & functionIndex , & bytes , end ) ) ;
_throwif ( " function index out of range " , functionIndex > = io_module - > numFunctions ) ;
IM3Function function = & io_module - > functions [ functionIndex ] ; d_m3Assert ( function ) ; //printf ("table: %s\n", function->name );
IM3Function function = & io_module - > functions [ functionIndex ] ; d_m3Assert ( function ) ; //printf ("table: %s\n", GetFunctionName(function) );
io_module - > table0 [ e + offset ] = function ;
}
}
@ -692,9 +715,12 @@ void * v_FindFunction (IM3Module i_module, const char * const i_name)
bool isImported = f - > import . moduleUtf8 or f - > import . fieldUtf8 ;
if ( not isImported and f - > name )
if ( isImported )
continue ;
for ( int j = 0 ; j < f - > numNames ; j + + )
{
if ( strcmp ( f - > name , i_name ) = = 0 )
if ( f - > names [ j ] and strcmp ( f - > name s [ j ] , i_name ) = = 0 )
return f ;
}
}