[libChf] remove more unnecessary macros

This commit is contained in:
Gwenhael Le Moine 2024-10-08 13:16:19 +02:00
parent e103e6880b
commit ed3fa2ead9
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
7 changed files with 33 additions and 114 deletions

View file

@ -268,9 +268,9 @@ static ChfAction EmulatorLoopHandler( const ChfDescriptor* d, const ChfState s,
/* 2.1: Chf release 2 fixed the spelling of 'SIGNALING' */ /* 2.1: Chf release 2 fixed the spelling of 'SIGNALING' */
case CHF_SIGNALING: case CHF_SIGNALING:
/* ChfSignal() in progress */ /* ChfSignal() in progress */
if ( ChfGetModuleId( d ) == CPU_CHF_MODULE_ID ) { if ( d->module_id == CPU_CHF_MODULE_ID ) {
/* Condition from CPU modules; check Condition Code */ /* Condition from CPU modules; check Condition Code */
switch ( ChfGetConditionCode( d ) ) { switch ( d->condition_code ) {
case CPU_I_SHUTDN: case CPU_I_SHUTDN:
{ {
/* 3.1: CPU_SPIN_SHUTDN is not defined, and the cpu emulator /* 3.1: CPU_SPIN_SHUTDN is not defined, and the cpu emulator

View file

@ -1130,74 +1130,6 @@ the macros the Chf library provides for this purpose.
@end deftp @end deftp
The following macros are provided to access a condition descriptor:
@deftypefn Macro {ChfDescriptor *} ChfGetNextDescriptor (Chf Descriptor *d)
@cindex Next condition descriptor
Returns to the caller the condition descriptor that hierarchically
follows @code{d} in the current condition group, or the special
value @code{CHF_NULL_DESCRIPTOR} if @code{d} is the last descriptor of the
group.
@end deftypefn
@deftypefn Macro int ChfGetModuleId (Chf Descriptor *d)
@cindex Module identifier
Returns to the caller the identifier of the module that generated
the condition @code{d}.
@end deftypefn
@deftypefn Macro int ChfGetConditionCode (Chf Descriptor *d)
@cindex Condition Code
Returns to the caller the condition code of the condition @code{d}.
@end deftypefn
@deftypefn Macro ChfSeverity ChfGetSeverity (Chf Descriptor *d)
@cindex Severity
Returns to the caller the severity level of the condition @code{d}.
@xref{ChfSeverity}.
@end deftypefn
@deftypefn Macro int ChfGetLineNumber (Chf Descriptor *d)
@cindex Line number
Returns to the caller the source line number where the condition @code{d}
was generated. This piece of information is available only if the
Chf compile-time option @code{CHF_EXTENDED_INFO} was set when the source
file that generated the condition was compiled, otherwise the special
value @code{CHF_UNKNOWN_LINE_NUMBER} is returned instead.
@end deftypefn
@deftypefn Macro {const char *} ChfGetFileName (Chf Descriptor *d)
@cindex File name
Returns to the caller the file name where the condition @code{d}
was generated. This piece of information is available only if the
Chf compile-time option @code{CHF_EXTENDED_INFO} was set when the source
file that generated the condition was compiled, otherwise the special
value @code{CHF_UNKNOWN_FILE_NAME} is returned instead.
@end deftypefn
@deftypefn Macro {char *} ChfGetPartialMessage (Chf Descriptor *d)
@cindex Partial condition message
Returns to the caller the partial condition message that was associated
with the condition @code{d} when it was generated. The partial condition
message contains the result of the execution of @code{sprintf()} using
the message template associated with the condition as format, and the
ancillary condition arguments as additional arguments.
@end deftypefn
@node Condition handling state, Handler actions, Condition descriptors, General condition handling @node Condition handling state, Handler actions, Condition descriptors, General condition handling

View file

@ -199,18 +199,6 @@ typedef /* Message retrieval 'exit' function */
} \ } \
} }
/* -------------------------------------------------------------------------
Other macros
------------------------------------------------------------------------- */
#define ChfGetNextDescriptor( d ) ( d )->next
#define ChfGetModuleId( d ) ( d )->module_id
#define ChfGetConditionCode( d ) ( d )->condition_code
#define ChfGetSeverity( d ) ( d )->severity
#define ChfGetLineNumber( d ) ( d )->line_number
#define ChfGetFileName( d ) ( d )->file_name
#define ChfGetPartialMessage( d ) ( d )->message
/* ------------------------------------------------------------------------- /* -------------------------------------------------------------------------
Function prototypes Function prototypes
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */

View file

@ -42,23 +42,6 @@
# include <pthread.h> # include <pthread.h>
#endif #endif
/* Abort codes message table; the relative position of the messages must
match the numeric codes CHF_ABORT_xxxx defined in ChfPriv.h
*/
static const char* message_table[] = { ( const char* )NULL,
"Not initialized",
"Temporary message buffer overflow",
"Invalid action from last chance handler",
"Already initialized",
"Unwind request while unwinding",
"Improperly handled condition",
"Fatal condition while unwinding",
"Condition stack overflow",
"Can't prime a new Chf context",
"Pthread interaction failed" };
#define MESSAGE_TABLE_SIZE ( sizeof( message_table ) / sizeof( const char* ) )
/* .+ /* .+
.title : ChfAbort .title : ChfAbort
@ -109,10 +92,26 @@ static const char* message_table[] = { ( const char* )NULL,
void ChfAbort( /* Abort application */ void ChfAbort( /* Abort application */
const int abort_code ) const int abort_code )
{ {
/* Abort codes message table; the relative position of the messages must
match the numeric codes CHF_ABORT_xxxx defined in ChfPriv.h
*/
const char* message_table[] = { ( const char* )NULL,
"Not initialized",
"Temporary message buffer overflow",
"Invalid action from last chance handler",
"Already initialized",
"Unwind request while unwinding",
"Improperly handled condition",
"Fatal condition while unwinding",
"Condition stack overflow",
"Can't prime a new Chf context",
"Pthread interaction failed" };
if ( abort_code != CHF_ABORT_SILENT ) { if ( abort_code != CHF_ABORT_SILENT ) {
fputs( CHF_ABORT_HEADER, stderr ); fputs( CHF_ABORT_HEADER, stderr );
if ( abort_code < 0 || abort_code >= ( int )MESSAGE_TABLE_SIZE ) if ( abort_code < 0 || abort_code >= ( int )( sizeof( message_table ) / sizeof( const char* ) ) )
fprintf( stderr, CHF_ABORT_BAD_CODE_FMT, abort_code ); fprintf( stderr, CHF_ABORT_BAD_CODE_FMT, abort_code );
else else

View file

@ -83,7 +83,7 @@ static ChfAction StructuredHelper( const ChfDescriptor* desc, const ChfState sta
ChfAction action; ChfAction action;
const ChfDescriptor* d; const ChfDescriptor* d;
return ( ( state == CHF_SIGNALING && ChfGetSeverity( desc ) == CHF_FATAL ) ? CHF_UNWIND_KEEP : CHF_RESIGNAL ); return ( ( state == CHF_SIGNALING && desc->severity == CHF_FATAL ) ? CHF_UNWIND_KEEP : CHF_RESIGNAL );
} }
/* .+ /* .+

View file

@ -169,12 +169,12 @@ static ChfAction DefaultHandler( const ChfDescriptor* desc, const ChfState state
is done atomically if multithreading support is enabled. is done atomically if multithreading support is enabled.
In Win32, the default handler does not print anything. In Win32, the default handler does not print anything.
*/ */
if ( ChfGetSeverity( desc ) > CHF_SUCCESS ) { if ( desc->severity > CHF_SUCCESS ) {
#ifdef _REENTRANT #ifdef _REENTRANT
if ( pthread_mutex_lock( &fputs_mutex ) ) if ( pthread_mutex_lock( &fputs_mutex ) )
ChfAbort( CHF_ABORT_PTHREAD ); ChfAbort( CHF_ABORT_PTHREAD );
#endif #endif
for ( d = desc; d != CHF_NULL_DESCRIPTOR; d = ChfGetNextDescriptor( d ) ) for ( d = desc; d != CHF_NULL_DESCRIPTOR; d = d->next )
fputs( ChfBuildMessage( d ), stderr ); fputs( ChfBuildMessage( d ), stderr );
#ifdef _REENTRANT #ifdef _REENTRANT
if ( pthread_mutex_unlock( &fputs_mutex ) ) if ( pthread_mutex_unlock( &fputs_mutex ) )
@ -183,7 +183,7 @@ static ChfAction DefaultHandler( const ChfDescriptor* desc, const ChfState state
} }
/* Determine the handler action */ /* Determine the handler action */
switch ( ChfGetSeverity( desc ) ) { switch ( desc->severity ) {
case CHF_SUCCESS: case CHF_SUCCESS:
case CHF_INFO: case CHF_INFO:
case CHF_WARNING: case CHF_WARNING:
@ -374,15 +374,15 @@ char* ChfBuildMessage( /* Build a condition message */
tmp_p = scopy( tmp_p, "\t", tmp_end ); tmp_p = scopy( tmp_p, "\t", tmp_end );
/* The message continues with the module name */ /* The message continues with the module name */
ChfSprintf( def_message, CHF_DEF_MID_MSG_FMT, ChfGetModuleId( descriptor ) ); ChfSprintf( def_message, CHF_DEF_MID_MSG_FMT, descriptor->module_id );
tmp_p = scopy( tmp_p, ChfGetMessage( CHF_MODULE_NAMES_SET, ChfGetModuleId( descriptor ), def_message ), tmp_end ); tmp_p = scopy( tmp_p, ChfGetMessage( CHF_MODULE_NAMES_SET, descriptor->module_id, def_message ), tmp_end );
/* Add also the extended information, if any */ /* Add also the extended information, if any */
if ( ChfGetLineNumber( descriptor ) != CHF_UNKNOWN_LINE_NUMBER ) { if ( descriptor->line_number != CHF_UNKNOWN_LINE_NUMBER ) {
tmp_p = scopy( tmp_p, " ", tmp_end ); tmp_p = scopy( tmp_p, " ", tmp_end );
ChfSprintf( def_message, CHF_EXTENDED_INFO_FMT, ChfGetFileName( descriptor ), ChfGetLineNumber( descriptor ) ); ChfSprintf( def_message, CHF_EXTENDED_INFO_FMT, descriptor->file_name, descriptor->line_number );
tmp_p = scopy( tmp_p, def_message, tmp_end ); tmp_p = scopy( tmp_p, def_message, tmp_end );
} }
@ -391,14 +391,14 @@ char* ChfBuildMessage( /* Build a condition message */
/* Add the severity code of the message */ /* Add the severity code of the message */
tmp_p = scopy( tmp_p, tmp_p = scopy( tmp_p,
( ( severity = ChfGetSeverity( descriptor ) ) < CHF_SUCCESS || severity > CHF_FATAL ) ? CHF_UNKNOWN_SEVERITY ( ( severity = descriptor->severity ) < CHF_SUCCESS || severity > CHF_FATAL ) ? CHF_UNKNOWN_SEVERITY
: severity_name[ severity ], : severity_name[ severity ],
tmp_end ); tmp_end );
tmp_p = scopy( tmp_p, separator, tmp_end ); tmp_p = scopy( tmp_p, separator, tmp_end );
/* The message ends with the partial message from the descriptor */ /* The message ends with the partial message from the descriptor */
tmp_p = scopy( tmp_p, ChfGetPartialMessage( descriptor ), tmp_end ); tmp_p = scopy( tmp_p, descriptor->message, tmp_end );
( void )scopy( tmp_p, CHF_MESSAGE_TERMINATOR, tmp_end ); ( void )scopy( tmp_p, CHF_MESSAGE_TERMINATOR, tmp_end );
return chf_context.message_buffer; return chf_context.message_buffer;

View file

@ -165,8 +165,8 @@ void ChfSignal( const int module_id )
if ( chf_context.condition_sp > chf_context.condition_base ) { if ( chf_context.condition_sp > chf_context.condition_base ) {
if ( chf_context.state == CHF_SIGNALING ) { if ( chf_context.state == CHF_SIGNALING ) {
/* Force the new severity to CHF_FATAL if necessary */ /* Force the new severity to CHF_FATAL if necessary */
if ( ChfGetSeverity( current_condition ) == CHF_FATAL ) if ( current_condition->severity == CHF_FATAL )
ChfGetSeverity( chf_context.condition_sp - 1 ) = CHF_FATAL; ( chf_context.condition_sp - 1 )->severity = CHF_FATAL;
/* Link together the condition groups */ /* Link together the condition groups */
chf_context.condition_base->next = current_condition; chf_context.condition_base->next = current_condition;
@ -181,7 +181,7 @@ void ChfSignal( const int module_id )
/* The action CHF_CONTINUE is not allowed if the current condition /* The action CHF_CONTINUE is not allowed if the current condition
severity is CHF_FATAL; it's automatically changed to CHF_RESIGNAL severity is CHF_FATAL; it's automatically changed to CHF_RESIGNAL
*/ */
if ( handler_result == CHF_CONTINUE && ChfGetSeverity( current_condition ) == CHF_FATAL ) if ( handler_result == CHF_CONTINUE && current_condition->severity == CHF_FATAL )
handler_result = CHF_RESIGNAL; handler_result = CHF_RESIGNAL;
} }