Index: runtime/src/kmp_affinity.h =================================================================== --- runtime/src/kmp_affinity.h +++ runtime/src/kmp_affinity.h @@ -56,7 +56,9 @@ } int error = errno; if (abort_on_error) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), KMP_ERR( error ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -69,7 +71,9 @@ } int error = errno; if (abort_on_error) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), KMP_ERR( error ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -263,7 +267,9 @@ } int error = errno; if (abort_on_error) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), KMP_ERR( error ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -276,7 +282,9 @@ } int error = errno; if (abort_on_error) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), KMP_ERR( error ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( FatalSysError ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -377,8 +385,9 @@ if (__kmp_SetThreadGroupAffinity(GetCurrentThread(), &ga, NULL) == 0) { DWORD error = GetLastError(); if (abort_on_error) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetThreadAffMask ), - KMP_ERR( error ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetThreadAffMask ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -386,8 +395,9 @@ if (!SetThreadAffinityMask( GetCurrentThread(), *mask )) { DWORD error = GetLastError(); if (abort_on_error) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetThreadAffMask ), - KMP_ERR( error ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetThreadAffMask ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -402,8 +412,10 @@ if (__kmp_GetThreadGroupAffinity(GetCurrentThread(), &ga) == 0) { DWORD error = GetLastError(); if (abort_on_error) { + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg(kmp_ms_fatal, KMP_MSG(FunctionError, "GetThreadGroupAffinity()"), - KMP_ERR(error), __kmp_msg_null); + err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -416,8 +428,10 @@ if (!GetProcessAffinityMask(GetCurrentProcess(), &newMask, &sysMask)) { DWORD error = GetLastError(); if (abort_on_error) { + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg(kmp_ms_fatal, KMP_MSG(FunctionError, "GetProcessAffinityMask()"), - KMP_ERR(error), __kmp_msg_null); + err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -425,8 +439,10 @@ if (! retval) { DWORD error = GetLastError(); if (abort_on_error) { + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg(kmp_ms_fatal, KMP_MSG(FunctionError, "SetThreadAffinityMask()"), - KMP_ERR(error), __kmp_msg_null); + err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } return error; } @@ -434,8 +450,10 @@ if (! newMask) { DWORD error = GetLastError(); if (abort_on_error) { + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg(kmp_ms_fatal, KMP_MSG(FunctionError, "SetThreadAffinityMask()"), - KMP_ERR(error), __kmp_msg_null); + err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } } *mask = retval; Index: runtime/src/kmp_affinity.cpp =================================================================== --- runtime/src/kmp_affinity.cpp +++ runtime/src/kmp_affinity.cpp @@ -3863,21 +3863,25 @@ if (f == NULL) { int code = errno; if (__kmp_cpuinfo_file != NULL) { + kmp_msg_t err_code = KMP_ERR(code); __kmp_msg( kmp_ms_fatal, KMP_MSG(CantOpenFileForReading, filename), - KMP_ERR(code), + err_code, KMP_HNT(NameComesFrom_CPUINFO_FILE), __kmp_msg_null ); + __kmp_str_free(&err_code.str); } else { + kmp_msg_t err_code = KMP_ERR(code); __kmp_msg( - kmp_ms_fatal, - KMP_MSG(CantOpenFileForReading, filename), - KMP_ERR(code), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG(CantOpenFileForReading, filename), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } } int line = 0; Index: runtime/src/kmp_environment.c =================================================================== --- runtime/src/kmp_environment.c +++ runtime/src/kmp_environment.c @@ -98,63 +98,67 @@ char * result = NULL; #if KMP_OS_UNIX - char const * value = getenv( name ); - if ( value != NULL ) { - size_t len = KMP_STRLEN( value ) + 1; - result = (char *) KMP_INTERNAL_MALLOC( len ); - if ( result == NULL ) { - KMP_FATAL( MemoryAllocFailed ); - }; // if - KMP_STRNCPY_S( result, len, value, len ); + char const * value = getenv( name ); + if ( value != NULL ) { + size_t len = KMP_STRLEN( value ) + 1; + result = (char *) KMP_INTERNAL_MALLOC( len ); + if ( result == NULL ) { + KMP_FATAL( MemoryAllocFailed ); }; // if + KMP_STRNCPY_S( result, len, value, len ); + }; // if #elif KMP_OS_WINDOWS - /* - We use GetEnvironmentVariable for Windows* OS instead of getenv because the act of - loading a DLL on Windows* OS makes any user-set environment variables (i.e. with putenv()) - unavailable. getenv() apparently gets a clean copy of the env variables as they existed - at the start of the run. - JH 12/23/2002 - */ - DWORD rc; - rc = GetEnvironmentVariable( name, NULL, 0 ); - if ( ! rc ) { - DWORD error = GetLastError(); - if ( error != ERROR_ENVVAR_NOT_FOUND ) { - __kmp_msg( + /* + We use GetEnvironmentVariable for Windows* OS instead of getenv because the act of + loading a DLL on Windows* OS makes any user-set environment variables (i.e. with putenv()) + unavailable. getenv() apparently gets a clean copy of the env variables as they existed + at the start of the run. + JH 12/23/2002 + */ + DWORD rc; + rc = GetEnvironmentVariable( name, NULL, 0 ); + if ( ! rc ) { + DWORD error = GetLastError(); + if ( error != ERROR_ENVVAR_NOT_FOUND ) { + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg( kmp_ms_fatal, KMP_MSG( CantGetEnvVar, name ), - KMP_ERR( error ), + err_code, __kmp_msg_null - ); - }; // if - // Variable is not found, it's ok, just continue. - } else { - DWORD len = rc; - result = (char *) KMP_INTERNAL_MALLOC( len ); - if ( result == NULL ) { - KMP_FATAL( MemoryAllocFailed ); - }; // if - rc = GetEnvironmentVariable( name, result, len ); - if ( ! rc ) { - // GetEnvironmentVariable() may return 0 if variable is empty. - // In such a case GetLastError() returns ERROR_SUCCESS. - DWORD error = GetLastError(); - if ( error != ERROR_SUCCESS ) { - // Unexpected error. The variable should be in the environment, - // and buffer should be large enough. - __kmp_msg( + ); + __kmp_str_free(&err_code.str); + }; // if + // Variable is not found, it's ok, just continue. + } else { + DWORD len = rc; + result = (char *) KMP_INTERNAL_MALLOC( len ); + if ( result == NULL ) { + KMP_FATAL( MemoryAllocFailed ); + }; // if + rc = GetEnvironmentVariable( name, result, len ); + if ( ! rc ) { + // GetEnvironmentVariable() may return 0 if variable is empty. + // In such a case GetLastError() returns ERROR_SUCCESS. + DWORD error = GetLastError(); + if ( error != ERROR_SUCCESS ) { + // Unexpected error. The variable should be in the environment, + // and buffer should be large enough. + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg( kmp_ms_fatal, KMP_MSG( CantGetEnvVar, name ), - KMP_ERR( error ), + err_code, __kmp_msg_null - ); - KMP_INTERNAL_FREE( (void *) result ); - result = NULL; - }; // if + ); + __kmp_str_free(&err_code.str); + KMP_INTERNAL_FREE( (void *) result ); + result = NULL; }; // if }; // if + }; // if #else - #error Unknown or unsupported OS. + #error Unknown or unsupported OS. #endif return result; @@ -187,19 +191,21 @@ if ( rc == 0 ) { DWORD error = GetLastError(); if ( error != ERROR_ENVVAR_NOT_FOUND ) { + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantGetEnvVar, name ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantGetEnvVar, name ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); }; // if return 0; }; // if return 1; - #else + #else #error Unknown or unsupported OS. - #endif + #endif } // func __kmp_env_exists @@ -233,23 +239,27 @@ }; // if DWORD error = GetLastError(); if ( error != ERROR_ENVVAR_NOT_FOUND ) { + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_fatal, KMP_MSG( CantGetEnvVar, name ), - KMP_ERR( error ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if }; // if rc = SetEnvironmentVariable( name, value ); if ( ! rc ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_fatal, KMP_MSG( CantSetEnvVar, name ), - KMP_ERR( error ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if #else #error Unknown or unsupported OS. @@ -268,12 +278,14 @@ BOOL rc = SetEnvironmentVariable( name, NULL ); if ( ! rc ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_fatal, KMP_MSG( CantSetEnvVar, name ), - KMP_ERR( error ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if #else #error Unknown or unsupported OS. @@ -516,12 +528,14 @@ char * mem = GetEnvironmentStrings(); if ( mem == NULL ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_fatal, KMP_MSG( CantGetEnvironment ), - KMP_ERR( error ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if ___kmp_env_blk_parse_windows( block, mem ); FreeEnvironmentStrings( mem ); @@ -566,11 +580,10 @@ ) { KMP_INTERNAL_FREE( (void *) block->vars ); - KMP_INTERNAL_FREE( (void *) block->bulk ); + __kmp_str_free(&(block->bulk)); block->count = 0; block->vars = NULL; - block->bulk = NULL; } // __kmp_env_blk_free Index: runtime/src/kmp_i18n.h =================================================================== --- runtime/src/kmp_i18n.h +++ runtime/src/kmp_i18n.h @@ -156,12 +156,16 @@ #define KMP_WARNING( ... ) __kmp_msg( kmp_ms_warning, KMP_MSG( __VA_ARGS__ ), __kmp_msg_null ) #define KMP_FATAL( ... ) __kmp_msg( kmp_ms_fatal, KMP_MSG( __VA_ARGS__ ), __kmp_msg_null ) #define KMP_SYSFAIL( func, error ) \ - __kmp_msg( \ - kmp_ms_fatal, \ - KMP_MSG( FunctionError, func ), \ - KMP_SYSERRCODE( error ), \ - __kmp_msg_null \ - ) + { \ + kmp_msg_t error_code = KMP_SYSERRCODE( error ); \ + __kmp_msg( \ + kmp_ms_fatal, \ + KMP_MSG( FunctionError, func ), \ + error_code, \ + __kmp_msg_null \ + ); \ + __kmp_str_free(&error_code.str); \ + } // Check error, if not zero, generate fatal error message. #define KMP_CHECK_SYSFAIL( func, error ) \ Index: runtime/src/kmp_i18n.c =================================================================== --- runtime/src/kmp_i18n.c +++ runtime/src/kmp_i18n.c @@ -148,14 +148,16 @@ // Infinite recursion will not occur -- status is KMP_I18N_ABSENT now, so // __kmp_i18n_catgets() will not try to open catalog, but will return default message. + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_warning, KMP_MSG( CantOpenMessageCatalog, name ), - KMP_ERR( error ), + err_code, KMP_HNT( CheckEnvVar, "NLSPATH", nlspath ), KMP_HNT( CheckEnvVar, "LANG", lang ), __kmp_msg_null ); + __kmp_str_free(&err_code.str); KMP_INFORM( WillUseDefaultMessages ); KMP_INTERNAL_FREE( nlspath ); KMP_INTERNAL_FREE( lang ); @@ -317,7 +319,7 @@ table->size = 0; KMP_INTERNAL_FREE( (void *) table->sect ); table->sect = NULL; -} // kmp_i8n_table_free +} // kmp_i18n_table_free void @@ -411,14 +413,16 @@ Issue a hint in this case to let cause of trouble more understandable. */ - __kmp_msg( - kmp_ms_warning, - KMP_MSG( CantOpenMessageCatalog, path.str ), - KMP_SYSERRCODE( error ), - ( error == ERROR_BAD_EXE_FORMAT ? KMP_HNT( BadExeFormat, path.str, KMP_ARCH_STR ) : __kmp_msg_null ), - __kmp_msg_null - ); - KMP_INFORM( WillUseDefaultMessages ); + __kmp_msg_t err_msg = KMP_SYSERRCODE(error); + __kmp_msg( + kmp_ms_warning, + KMP_MSG( CantOpenMessageCatalog, path.str ), + err_msg, + ( error == ERROR_BAD_EXE_FORMAT ? KMP_HNT( BadExeFormat, path.str, KMP_ARCH_STR ) : __kmp_msg_null ), + __kmp_msg_null + ); + __kmp_str_free(&err_msg.str); + KMP_INFORM( WillUseDefaultMessages ); } } else { // status == KMP_I18N_OPENED @@ -824,12 +828,11 @@ // XSI version of strerror_r. int size = 2048; - // TODO: Add checking result of malloc(). char * buffer = (char *) KMP_INTERNAL_MALLOC( size ); - int rc; if (buffer == NULL) { - KMP_FATAL(MemoryAllocFailed); + KMP_FATAL(MemoryAllocFailed); } + int rc; rc = strerror_r( err, buffer, size ); if ( rc == -1 ) { rc = errno; // XSI version sets errno. @@ -839,7 +842,7 @@ size *= 2; buffer = (char *) KMP_INTERNAL_MALLOC( size ); if (buffer == NULL) { - KMP_FATAL(MemoryAllocFailed); + KMP_FATAL(MemoryAllocFailed); } rc = strerror_r( err, buffer, size ); if ( rc == -1 ) { @@ -932,9 +935,9 @@ }; }; // switch fmsg = __kmp_msg_format( format, message.num, message.str ); - KMP_INTERNAL_FREE( (void *) message.str ); + __kmp_str_free(&message.str); __kmp_str_buf_cat( & buffer, fmsg.str, fmsg.len ); - KMP_INTERNAL_FREE( (void *) fmsg.str ); + __kmp_str_free(&fmsg.str); // Format other messages. va_start( args, message ); @@ -958,9 +961,9 @@ }; }; // switch fmsg = __kmp_msg_format( format, message.num, message.str ); - KMP_INTERNAL_FREE( (void *) message.str ); + __kmp_str_free(&message.str); __kmp_str_buf_cat( & buffer, fmsg.str, fmsg.len ); - KMP_INTERNAL_FREE( (void *) fmsg.str ); + __kmp_str_free(&fmsg.str); }; // forever va_end( args ); Index: runtime/src/kmp_itt.c =================================================================== --- runtime/src/kmp_itt.c +++ runtime/src/kmp_itt.c @@ -105,10 +105,14 @@ char const * library = va_arg( args, char const * ); #if KMP_OS_WINDOWS int sys_err = va_arg( args, int ); - __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_SYSERRCODE( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); #else char const * sys_err = va_arg( args, char const * ); - __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), KMP_SYSERRMESG( sys_err ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_SYSERRMESG( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( IttLoadLibFailed, library ), err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); #endif } break; case __itt_error_no_symbol : { @@ -130,12 +134,16 @@ case __itt_error_cant_read_env : { char const * var = va_arg( args, char const * ); int sys_err = va_arg( args, int ); - __kmp_msg( kmp_ms_warning, KMP_MSG( CantGetEnvVar, var ), KMP_ERR( sys_err ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_ERR( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( CantGetEnvVar, var ), err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); } break; case __itt_error_system : { char const * func = va_arg( args, char const * ); int sys_err = va_arg( args, int ); - __kmp_msg( kmp_ms_warning, KMP_MSG( IttFunctionError, func ), KMP_SYSERRCODE( sys_err ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_SYSERRCODE( sys_err ); + __kmp_msg( kmp_ms_warning, KMP_MSG( IttFunctionError, func ), err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); } break; default : { KMP_WARNING( IttUnknownError, err ); Index: runtime/src/kmp_runtime.c =================================================================== --- runtime/src/kmp_runtime.c +++ runtime/src/kmp_runtime.c @@ -4434,12 +4434,14 @@ status = __kmp_get_system_affinity( old_mask, TRUE ); int error = errno; if ( status != 0 ) { + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_fatal, KMP_MSG( ChangeThreadAffMaskError ), - KMP_ERR( error ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); } } __kmp_set_system_affinity( __kmp_affin_fullMask, TRUE ); @@ -6518,7 +6520,9 @@ */ int rc = atexit( __kmp_internal_end_atexit ); if ( rc != 0 ) { - __kmp_msg( kmp_ms_fatal, KMP_MSG( FunctionError, "atexit()" ), KMP_ERR( rc ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_ERR( rc ); + __kmp_msg( kmp_ms_fatal, KMP_MSG( FunctionError, "atexit()" ), err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if } #endif Index: runtime/src/kmp_settings.c =================================================================== --- runtime/src/kmp_settings.c +++ runtime/src/kmp_settings.c @@ -360,7 +360,7 @@ char const * value, char const * * out ) { - KMP_INTERNAL_FREE( (void *) * out ); + __kmp_str_free(out); * out = __kmp_str_format( "%s", value ); } // __kmp_stg_parse_str #endif @@ -418,12 +418,12 @@ char buffer[256]; char *t; int hasSuffix; - KMP_INTERNAL_FREE( (void *) * out ); + __kmp_str_free(out); t = (char *) strrchr(value, '.'); hasSuffix = t && __kmp_str_eqf( t, suffix ); t = __kmp_str_format( "%s%s", value, hasSuffix ? "" : suffix ); __kmp_expand_file_name( buffer, sizeof(buffer), t); - KMP_INTERNAL_FREE(t); + __kmp_str_free(&t); * out = __kmp_str_format( "%s", buffer ); } // __kmp_stg_parse_file #endif @@ -2235,7 +2235,7 @@ #undef set_respect #undef set_granularity - KMP_INTERNAL_FREE( buffer ); + __kmp_str_free((const char **) &buffer); if ( proclist ) { if ( ! type ) { Index: runtime/src/kmp_str.c =================================================================== --- runtime/src/kmp_str.c +++ runtime/src/kmp_str.c @@ -420,8 +420,7 @@ kmp_str_loc_t * loc ) { __kmp_str_fname_free( & loc->fname ); - KMP_INTERNAL_FREE( loc->_bulk ); - loc->_bulk = NULL; + __kmp_str_free((const char **) &(loc->_bulk)); loc->file = NULL; loc->func = NULL; } // kmp_str_loc_free @@ -478,8 +477,6 @@ So standard malloc() is the only available option. */ -// TODO: Find and replace all regular free() with __kmp_str_free(). - char * __kmp_str_format( // Allocated string. char const * format, // Format string. Index: runtime/src/z_Linux_util.c =================================================================== --- runtime/src/z_Linux_util.c +++ runtime/src/z_Linux_util.c @@ -165,12 +165,14 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_warning, KMP_MSG( GetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -193,12 +195,14 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( SetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( SetAffSysCallNotSupported, env_var ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -241,12 +245,14 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( GetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( GetAffSysCallNotSupported, env_var ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -272,12 +278,14 @@ && (__kmp_affinity_type != affinity_default) && (__kmp_affinity_type != affinity_disabled))) { int error = errno; + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_warning, - KMP_MSG( SetAffSysCallNotSupported, env_var ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_warning, + KMP_MSG( SetAffSysCallNotSupported, env_var ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } KMP_AFFINITY_DISABLE(); KMP_INTERNAL_FREE(buf); @@ -494,12 +502,15 @@ KA_TRACE( 10, ("__kmp_terminate_thread: kill (%d)\n", gtid ) ); status = pthread_cancel( th->th.th_info.ds.ds_thread ); if ( status != 0 && status != ESRCH ) { + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( kmp_ms_fatal, KMP_MSG( CantTerminateWorkerThread ), - KMP_ERR( status ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); + }; // if #endif __kmp_yield( TRUE ); @@ -710,13 +721,15 @@ rc = sched_setscheduler( 0, sched, & param ); if ( rc != 0 ) { int error = errno; - __kmp_msg( - kmp_ms_warning, - KMP_MSG( CantChangeMonitorPriority ), - KMP_ERR( error ), - KMP_MSG( MonitorWillStarve ), - __kmp_msg_null - ); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg( + kmp_ms_warning, + KMP_MSG( CantChangeMonitorPriority ), + err_code, + KMP_MSG( MonitorWillStarve ), + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); }; // if } else { // We cannot abort here, because number of CPUs may be enough for all the threads, @@ -892,11 +905,15 @@ #ifdef KMP_THREAD_ATTR status = pthread_attr_init( &thread_attr ); if ( status != 0 ) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantInitThreadAttrs ), KMP_ERR( status ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantInitThreadAttrs ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); }; // if status = pthread_attr_setdetachstate( & thread_attr, PTHREAD_CREATE_JOINABLE ); if ( status != 0 ) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerState ), KMP_ERR( status ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerState ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); }; // if /* Set stack size for this thread now. @@ -928,8 +945,10 @@ }; // if # endif /* KMP_BACKUP_STKSIZE */ if ( status != 0 ) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerStackSize, stack_size ), KMP_ERR( status ), - KMP_HNT( ChangeWorkerStackSize ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerStackSize, stack_size ), err_code, + KMP_HNT( ChangeWorkerStackSize ), __kmp_msg_null); + __kmp_str_free(&err_code.str); }; // if # endif /* _POSIX_THREAD_ATTR_STACKSIZE */ @@ -939,17 +958,23 @@ if ( status != 0 || ! handle ) { // ??? Why do we check handle?? #ifdef _POSIX_THREAD_ATTR_STACKSIZE if ( status == EINVAL ) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerStackSize, stack_size ), KMP_ERR( status ), - KMP_HNT( IncreaseWorkerStackSize ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerStackSize, stack_size ), err_code, + KMP_HNT( IncreaseWorkerStackSize ), __kmp_msg_null); + __kmp_str_free(&err_code.str); }; if ( status == ENOMEM ) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerStackSize, stack_size ), KMP_ERR( status ), + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantSetWorkerStackSize, stack_size ), err_code, KMP_HNT( DecreaseWorkerStackSize ), __kmp_msg_null); + __kmp_str_free(&err_code.str); }; #endif /* _POSIX_THREAD_ATTR_STACKSIZE */ if ( status == EAGAIN ) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( NoResourcesForWorkerThread ), KMP_ERR( status ), - KMP_HNT( Decrease_NUM_THREADS ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( NoResourcesForWorkerThread ), err_code, + KMP_HNT( Decrease_NUM_THREADS ), __kmp_msg_null); + __kmp_str_free(&err_code.str); }; // if KMP_SYSFAIL( "pthread_create", status ); }; // if @@ -959,7 +984,9 @@ #ifdef KMP_THREAD_ATTR status = pthread_attr_destroy( & thread_attr ); if ( status ) { - __kmp_msg(kmp_ms_warning, KMP_MSG( CantDestroyThreadAttrs ), KMP_ERR( status ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_warning, KMP_MSG( CantDestroyThreadAttrs ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); }; // if #endif /* KMP_THREAD_ATTR */ @@ -1006,21 +1033,25 @@ } status = pthread_attr_init( &thread_attr ); if ( status != 0 ) { + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantInitThreadAttrs ), - KMP_ERR( status ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantInitThreadAttrs ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); }; // if status = pthread_attr_setdetachstate( & thread_attr, PTHREAD_CREATE_JOINABLE ); if ( status != 0 ) { + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( kmp_ms_fatal, KMP_MSG( CantSetMonitorState ), - KMP_ERR( status ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if #ifdef _POSIX_THREAD_ATTR_STACKSIZE @@ -1055,13 +1086,15 @@ __kmp_monitor_stksize *= 2; goto retry; } + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( - kmp_ms_warning, // should this be fatal? BB - KMP_MSG( CantSetMonitorStackSize, (long int) __kmp_monitor_stksize ), - KMP_ERR( status ), - KMP_HNT( ChangeMonitorStackSize ), - __kmp_msg_null - ); + kmp_ms_warning, // should this be fatal? BB + KMP_MSG( CantSetMonitorStackSize, (long int) __kmp_monitor_stksize ), + err_code, + KMP_HNT( ChangeMonitorStackSize ), + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); }; // if #endif /* _POSIX_THREAD_ATTR_STACKSIZE */ @@ -1074,32 +1107,38 @@ __kmp_monitor_stksize *= 2; goto retry; } + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( kmp_ms_fatal, KMP_MSG( CantSetMonitorStackSize, __kmp_monitor_stksize ), - KMP_ERR( status ), + err_code, KMP_HNT( IncreaseMonitorStackSize ), __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if if ( status == ENOMEM ) { + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantSetMonitorStackSize, __kmp_monitor_stksize ), - KMP_ERR( status ), - KMP_HNT( DecreaseMonitorStackSize ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantSetMonitorStackSize, __kmp_monitor_stksize ), + err_code, + KMP_HNT( DecreaseMonitorStackSize ), + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); }; // if #endif /* _POSIX_THREAD_ATTR_STACKSIZE */ if ( status == EAGAIN ) { + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( kmp_ms_fatal, KMP_MSG( NoResourcesForMonitorThread ), - KMP_ERR( status ), + err_code, KMP_HNT( DecreaseNumberOfThreadsInUse ), __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if KMP_SYSFAIL( "pthread_create", status ); }; // if @@ -1117,12 +1156,14 @@ #ifdef KMP_THREAD_ATTR status = pthread_attr_destroy( & thread_attr ); if ( status != 0 ) { + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( // kmp_ms_warning, KMP_MSG( CantDestroyThreadAttrs ), - KMP_ERR( status ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if #endif @@ -1175,12 +1216,14 @@ KA_TRACE( 10, ("__kmp_reap_monitor: try to join with monitor\n") ); status = pthread_join( th->th.th_info.ds.ds_thread, & exit_val); if (exit_val != th) { + kmp_msg_t err_code = KMP_ERR( status ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( ReapMonitorError ), - KMP_ERR( status ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( ReapMonitorError ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } th->th.th_info.ds.ds_tid = KMP_GTID_DNE; @@ -1208,7 +1251,9 @@ #ifdef KMP_DEBUG /* Don't expose these to the user until we understand when they trigger */ if ( status != 0 ) { - __kmp_msg(kmp_ms_fatal, KMP_MSG( ReapWorkerError ), KMP_ERR( status ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( status ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( ReapWorkerError ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } if ( exit_val != th ) { KA_TRACE( 10, ( "__kmp_reap_worker: worker T#%d did not reap properly, exit_val = %p\n", Index: runtime/src/z_Windows_NT_util.c =================================================================== --- runtime/src/z_Windows_NT_util.c +++ runtime/src/z_Windows_NT_util.c @@ -560,12 +560,14 @@ if (__kmp_SetThreadGroupAffinity(GetCurrentThread(), &ga, NULL) == 0) { DWORD error = GetLastError(); if (__kmp_affinity_verbose) { // AC: continue silently if not verbose + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( kmp_ms_warning, KMP_MSG( CantSetThreadAffMask ), - KMP_ERR( error ), + err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); } } } else { @@ -926,14 +928,15 @@ status = QueryPerformanceFrequency( & freq ); if (! status) { - DWORD error = GetLastError(); - __kmp_msg( - kmp_ms_fatal, - KMP_MSG( FunctionError, "QueryPerformanceFrequency()" ), - KMP_ERR( error ), - __kmp_msg_null - ); - + DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg( + kmp_ms_fatal, + KMP_MSG( FunctionError, "QueryPerformanceFrequency()" ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } else { __kmp_win32_tick = ((double) 1.0) / (double) freq.QuadPart; @@ -1068,12 +1071,14 @@ status = SetThreadPriority( monitor, THREAD_PRIORITY_HIGHEST ); if (! status) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantSetThreadPriority ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantSetThreadPriority ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } /* register us as monitor */ @@ -1113,12 +1118,14 @@ status = SetThreadPriority( monitor, THREAD_PRIORITY_NORMAL ); if (! status) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantSetThreadPriority ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantSetThreadPriority ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } if (__kmp_global.g.g_abort != 0) { @@ -1229,7 +1236,9 @@ if ( handle == 0 ) { DWORD error = GetLastError(); - __kmp_msg(kmp_ms_fatal, KMP_MSG( CantCreateThread ), KMP_ERR( error ), __kmp_msg_null); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg(kmp_ms_fatal, KMP_MSG( CantCreateThread ), err_code, __kmp_msg_null); + __kmp_str_free(&err_code.str); } else { th->th.th_info.ds.ds_thread = handle; } @@ -1268,12 +1277,14 @@ __kmp_monitor_ev = CreateEvent( NULL, TRUE, FALSE, NULL ); if ( __kmp_monitor_ev == NULL ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantCreateEvent ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantCreateEvent ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); }; // if #if USE_ITT_BUILD __kmp_itt_system_object_created( __kmp_monitor_ev, "Event" ); @@ -1301,12 +1312,14 @@ (LPVOID) th, STACK_SIZE_PARAM_IS_A_RESERVATION, &idThread ); if (handle == 0) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantCreateThread ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantCreateThread ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } else th->th.th_info.ds.ds_thread = handle; @@ -1334,12 +1347,14 @@ rc = GetExitCodeThread( th->th.th_info.ds.ds_thread, exit_val ); if ( rc == 0 ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( FunctionError, "GetExitCodeThread()" ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( FunctionError, "GetExitCodeThread()" ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); }; // if return ( *exit_val == STILL_ACTIVE ); } @@ -1456,12 +1471,14 @@ status = SetEvent( __kmp_monitor_ev ); if ( status == FALSE ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantSetEvent ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantSetEvent ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } KA_TRACE( 10, ( "__kmp_reap_monitor: reaping thread (%d)\n", th->th.th_info.ds.ds_gtid ) ); __kmp_reap_common( th ); @@ -1508,7 +1525,9 @@ sig_func_t old = signal( signum, handler ); if ( old == SIG_ERR ) { int error = errno; - __kmp_msg( kmp_ms_fatal, KMP_MSG( FunctionError, "signal" ), KMP_ERR( error ), __kmp_msg_null ); + kmp_msg_t err_code = KMP_ERR( error ); + __kmp_msg( kmp_ms_fatal, KMP_MSG( FunctionError, "signal" ), err_code, __kmp_msg_null ); + __kmp_str_free(&err_code.str); }; // if return old; } @@ -1599,12 +1618,14 @@ status = SleepEx( (DWORD) millis, FALSE ); if ( status ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( FunctionError, "SleepEx()" ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( FunctionError, "SleepEx()" ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } } @@ -1642,12 +1663,14 @@ rc = CloseHandle( tHandle ); if ( !rc ) { DWORD error = GetLastError(); + kmp_msg_t err_code = KMP_ERR( error ); __kmp_msg( - kmp_ms_fatal, - KMP_MSG( CantCloseHandle ), - KMP_ERR( error ), - __kmp_msg_null - ); + kmp_ms_fatal, + KMP_MSG( CantCloseHandle ), + err_code, + __kmp_msg_null + ); + __kmp_str_free(&err_code.str); } }