Skip to content

Commit

Permalink
CHANGE: use noreturn attribute in Trap* functions and mark these …
Browse files Browse the repository at this point in the history
…as DEAD_END to silence compiler warnings
  • Loading branch information
Oldes committed Apr 26, 2024
1 parent 9a3a117 commit ea437a6
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 63 deletions.
49 changes: 33 additions & 16 deletions src/core/c-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2024 Rebol Open Source Developers
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -504,168 +505,183 @@ static REBOL_STATE Top_State; // Boot var: holds error state during boot

/***********************************************************************
**
*/ void Trap0(REBCNT num)
*/ REB_NORETURN void Trap0(REBCNT num)
/*
***********************************************************************/
{
Throw_Error(Make_Error(num, 0, 0, 0));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap1(REBCNT num, REBVAL *arg1)
*/ REB_NORETURN void Trap1(REBCNT num, REBVAL *arg1)
/*
***********************************************************************/
{
Throw_Error(Make_Error(num, arg1, 0, 0));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap2(REBCNT num, REBVAL *arg1, REBVAL *arg2)
*/ REB_NORETURN void Trap2(REBCNT num, REBVAL *arg1, REBVAL *arg2)
/*
***********************************************************************/
{
Throw_Error(Make_Error(num, arg1, arg2, 0));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap3(REBCNT num, REBVAL *arg1, REBVAL *arg2, REBVAL *arg3)
*/ REB_NORETURN void Trap3(REBCNT num, REBVAL *arg1, REBVAL *arg2, REBVAL *arg3)
/*
***********************************************************************/
{
Throw_Error(Make_Error(num, arg1, arg2, arg3));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Arg(REBVAL *arg)
*/ REB_NORETURN void Trap_Arg(REBVAL *arg)
/*
***********************************************************************/
{
Trap1(RE_INVALID_ARG, arg);
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Type(REBVAL *arg)
*/ REB_NORETURN void Trap_Type(REBVAL *arg)
/*
** <type> type is not allowed here
**
***********************************************************************/
{
Trap1(RE_INVALID_TYPE, Of_Type(arg));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Range(REBVAL *arg)
*/ REB_NORETURN void Trap_Range(REBVAL *arg)
/*
** value out of range: <value>
**
***********************************************************************/
{
Trap1(RE_OUT_OF_RANGE, arg);
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Word(REBCNT num, REBCNT sym, REBVAL *arg)
*/ REB_NORETURN void Trap_Word(REBCNT num, REBCNT sym, REBVAL *arg)
/*
***********************************************************************/
{
Init_Word(DS_TOP, sym);
if (arg) Trap2(num, DS_TOP, arg);
else Trap1(num, DS_TOP);
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Action(REBCNT type, REBCNT action)
*/ REB_NORETURN void Trap_Action(REBCNT type, REBCNT action)
/*
***********************************************************************/
{
Trap2(RE_CANNOT_USE, Get_Action_Word(action), Get_Type(type));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Math_Args(REBCNT type, REBCNT action)
*/ REB_NORETURN void Trap_Math_Args(REBCNT type, REBCNT action)
/*
***********************************************************************/
{
Trap2(RE_NOT_RELATED, Get_Action_Word(action), Get_Type(type));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Types(REBCNT errnum, REBCNT type1, REBCNT type2)
*/ REB_NORETURN void Trap_Types(REBCNT errnum, REBCNT type1, REBCNT type2)
/*
***********************************************************************/
{
if (type2 != 0) Trap2(errnum, Get_Type(type1), Get_Type(type2));
Trap1(errnum, Get_Type(type1));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Expect(REBVAL *object, REBCNT index, REBCNT type)
*/ REB_NORETURN void Trap_Expect(REBVAL *object, REBCNT index, REBCNT type)
/*
** Object field is not of expected type.
** PORT expected SCHEME of OBJECT type
**
***********************************************************************/
{
Trap3(RE_EXPECT_TYPE, Of_Type(object), Obj_Word(object, index), Get_Type(type));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Make(REBCNT type, REBVAL *spec)
*/ REB_NORETURN void Trap_Make(REBCNT type, REBVAL *spec)
/*
***********************************************************************/
{
Trap2(RE_BAD_MAKE_ARG, Get_Type(type), spec);
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Num(REBCNT err, REBCNT num)
*/ REB_NORETURN void Trap_Num(REBCNT err, REBCNT num)
/*
***********************************************************************/
{
DS_PUSH_INTEGER(num);
Trap1(err, DS_TOP);
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Reflect(REBCNT type, REBVAL *arg)
*/ REB_NORETURN void Trap_Reflect(REBCNT type, REBVAL *arg)
/*
***********************************************************************/
{
Trap2(RE_CANNOT_USE, arg, Get_Type(type));
DEAD_END;
}


/***********************************************************************
**
*/ void Trap_Port(REBCNT errnum, REBSER *port, REBINT err_code)
*/ REB_NORETURN void Trap_Port(REBCNT errnum, REBSER *port, REBINT err_code)
/*
***********************************************************************/
{
Expand All @@ -679,6 +695,7 @@ static REBOL_STATE Top_State; // Boot var: holds error state during boot

DS_PUSH_INTEGER(-err_code);
Trap2(errnum, val, DS_TOP);
DEAD_END;
}


Expand Down
6 changes: 3 additions & 3 deletions src/core/d-crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2023 Rebol Open Source Developers
** Copyright 2012-2024 Rebol Open Source Developers
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -121,8 +121,8 @@ enum Crash_Msg_Nums {
#else
OS_CRASH(Crash_Msgs[CM_ERROR], buf);
#endif
// will not reach here, but...
abort(); // just to silent the function declared 'noreturn' should not return warning
// will not reach here...
DEAD_END;
}

/***********************************************************************
Expand Down
6 changes: 1 addition & 5 deletions src/core/f-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2024 Rebol Open Source Developers
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -172,7 +173,6 @@
return n;

Trap_Range(val);
return 0;
}


Expand All @@ -186,7 +186,6 @@
if (IS_DECIMAL(val) || IS_PERCENT(val)) return (REBI64)VAL_DECIMAL(val);
if (IS_MONEY(val)) return deci_to_int(VAL_DECI(val));
Trap_Arg(val);
return 0;
}


Expand All @@ -200,7 +199,6 @@
if (IS_INTEGER(val)) return (REBDEC)VAL_INT64(val);
if (IS_MONEY(val)) return deci_to_decimal(VAL_DECI(val));
Trap_Arg(val);
return 0;
}


Expand Down Expand Up @@ -235,7 +233,6 @@
return n;

Trap_Range(val);
DEAD_END;
}


Expand Down Expand Up @@ -612,7 +609,6 @@
if (IS_LOGIC(arg)) return (VAL_LOGIC(arg) != 0);
if (IS_DECIMAL(arg) || IS_PERCENT(arg)) return (VAL_DECIMAL(arg) != 0.0);
Trap_Arg(arg);
DEAD_END;
}


Expand Down
4 changes: 1 addition & 3 deletions src/core/n-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2023 Rebol Open Source Developers
** Copyright 2012-2024 Rebol Open Source Developers
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -154,8 +154,6 @@ static int Check_Char_Range(REBVAL *val, REBINT limit)
}

Trap_Arg(types);

return 0; // for compiler
}


Expand Down
3 changes: 1 addition & 2 deletions src/core/p-checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2023 Rebol Open Source Contributors
** Copyright 2012-2024 Rebol Open Source Contributors
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -284,7 +284,6 @@
method = Obj_Value(spec, STD_PORT_SPEC_CHECKSUM_METHOD);
if (!method || !IS_WORD(method)) {
Trap1(RE_INVALID_SPEC, spec);
return 0; //just to make xcode analyze happy
}

req = Use_Port_State(port, RDI_CHECKSUM, sizeof(REBREQ));
Expand Down
4 changes: 1 addition & 3 deletions src/core/p-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2023 Rebol Open Source Contributors
** Copyright 2012-2024 Rebol Open Source Contributors
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -478,7 +478,6 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
Trap1(RE_INVALID_SPEC, spec);
}
Trap_Port(RE_CANNOT_OPEN, port, err);
return FALSE;
}


Expand Down Expand Up @@ -1037,7 +1036,6 @@ static void free_crypt_cipher_context(CRYPT_CTX *ctx);
}
if (!Crypt_Open(port)) {
Trap_Port(RE_CANNOT_OPEN, port, 0);
return R_FALSE;
}
return R_ARG1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/p-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ enum Transport_Types {

if (!info || !IS_OBJECT(info)) {
Trap_Port(RE_INVALID_SPEC, port, -10);
return; // prevents compiler's warning
DEAD_END;
}

obj = CLONE_OBJECT(VAL_OBJ_FRAME(info));
Expand Down
2 changes: 1 addition & 1 deletion src/core/t-char.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2024 Rebol Open Source Developers
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -72,7 +73,6 @@
arg = (REBINT)VAL_DECIMAL(val);
else {
Trap_Math_Args(REB_CHAR, action);
return R_NONE; // just to make xcode happy
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/t-gob.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** REBOL [R3] Language Interpreter and Run-time Environment
**
** Copyright 2012 REBOL Technologies
** Copyright 2012-2024 Rebol Open Source Developers
** REBOL is a trademark of REBOL Technologies
**
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -792,7 +793,6 @@ const REBCNT Gob_Flag_Words[] = {
tail = GOB_PANE(gob) ? GOB_TAIL(gob) : 0;
} else if (!(IS_DATATYPE(val) && action == A_MAKE)){
Trap_Arg(val);
return R_FALSE; // shut-up compiler's warnings
}

// unary actions
Expand Down
Loading

0 comments on commit ea437a6

Please sign in to comment.