mirror of
https://github.com/throwtheswitch/cexception.git
synced 2026-10-02 14:57:23 +00:00
Merge pull request #3 from SteinHeselmans/master
dos2unix on files that had CRLF
This commit is contained in:
+30
-30
@@ -1,30 +1,30 @@
|
|||||||
Copyright (c) 2007-2014 Mark VanderVoord
|
Copyright (c) 2007-2014 Mark VanderVoord
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person
|
Permission is hereby granted, free of charge, to any person
|
||||||
obtaining a copy of this software and associated documentation
|
obtaining a copy of this software and associated documentation
|
||||||
files (the "Software"), to deal in the Software without
|
files (the "Software"), to deal in the Software without
|
||||||
restriction, including without limitation the rights to use,
|
restriction, including without limitation the rights to use,
|
||||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the
|
copies of the Software, and to permit persons to whom the
|
||||||
Software is furnished to do so, subject to the following
|
Software is furnished to do so, subject to the following
|
||||||
conditions:
|
conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
The above copyright notice and this permission notice shall be
|
||||||
included in all copies or substantial portions of the Software.
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
The end-user documentation included with the redistribution, if
|
The end-user documentation included with the redistribution, if
|
||||||
any, must include the following acknowledgment: "This product
|
any, must include the following acknowledgment: "This product
|
||||||
includes software developed for the CEXCeption Project, by Mark
|
includes software developed for the CEXCeption Project, by Mark
|
||||||
VanderVoord and other contributors", in the same place and form
|
VanderVoord and other contributors", in the same place and form
|
||||||
as other third-party acknowledgments. Alternately, this
|
as other third-party acknowledgments. Alternately, this
|
||||||
acknowledgment may appear in the software itself, in the same
|
acknowledgment may appear in the software itself, in the same
|
||||||
form and location as other such third-party acknowledgments.
|
form and location as other such third-party acknowledgments.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
OTHER DEALINGS IN THE SOFTWARE.
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
#include "CException.h"
|
#include "CException.h"
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||||
volatile CEXCEPTION_FRAME_T CExceptionFrames[CEXCEPTION_NUM_ID] = {{ 0 }};
|
volatile CEXCEPTION_FRAME_T CExceptionFrames[CEXCEPTION_NUM_ID] = {{ 0 }};
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
// Throw
|
// Throw
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
void Throw(CEXCEPTION_T ExceptionID)
|
void Throw(CEXCEPTION_T ExceptionID)
|
||||||
{
|
{
|
||||||
unsigned int MY_ID = CEXCEPTION_GET_ID;
|
unsigned int MY_ID = CEXCEPTION_GET_ID;
|
||||||
CExceptionFrames[MY_ID].Exception = ExceptionID;
|
CExceptionFrames[MY_ID].Exception = ExceptionID;
|
||||||
if (CExceptionFrames[MY_ID].pFrame)
|
if (CExceptionFrames[MY_ID].pFrame)
|
||||||
{
|
{
|
||||||
longjmp(*CExceptionFrames[MY_ID].pFrame, 1);
|
longjmp(*CExceptionFrames[MY_ID].pFrame, 1);
|
||||||
}
|
}
|
||||||
CEXCEPTION_NO_CATCH_HANDLER(ExceptionID);
|
CEXCEPTION_NO_CATCH_HANDLER(ExceptionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
// Explanation of what it's all for:
|
// Explanation of what it's all for:
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
/*
|
/*
|
||||||
#define Try
|
#define Try
|
||||||
{ <- give us some local scope. most compilers are happy with this
|
{ <- give us some local scope. most compilers are happy with this
|
||||||
jmp_buf *PrevFrame, NewFrame; <- prev frame points to the last try block's frame. new frame gets created on stack for this Try block
|
jmp_buf *PrevFrame, NewFrame; <- prev frame points to the last try block's frame. new frame gets created on stack for this Try block
|
||||||
unsigned int MY_ID = CEXCEPTION_GET_ID; <- look up this task's id for use in frame array. always 0 if single-tasking
|
unsigned int MY_ID = CEXCEPTION_GET_ID; <- look up this task's id for use in frame array. always 0 if single-tasking
|
||||||
PrevFrame = CExceptionFrames[CEXCEPTION_GET_ID].pFrame; <- set pointer to point at old frame (which array is currently pointing at)
|
PrevFrame = CExceptionFrames[CEXCEPTION_GET_ID].pFrame; <- set pointer to point at old frame (which array is currently pointing at)
|
||||||
CExceptionFrames[MY_ID].pFrame = &NewFrame; <- set array to point at my new frame instead, now
|
CExceptionFrames[MY_ID].pFrame = &NewFrame; <- set array to point at my new frame instead, now
|
||||||
CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- initialize my exception id to be NONE
|
CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- initialize my exception id to be NONE
|
||||||
if (setjmp(NewFrame) == 0) { <- do setjmp. it returns 1 if longjump called, otherwise 0
|
if (setjmp(NewFrame) == 0) { <- do setjmp. it returns 1 if longjump called, otherwise 0
|
||||||
if (&PrevFrame) <- this is here to force proper scoping. it requires braces or a single line to be but after Try, otherwise won't compile. This is always true at this point.
|
if (&PrevFrame) <- this is here to force proper scoping. it requires braces or a single line to be but after Try, otherwise won't compile. This is always true at this point.
|
||||||
|
|
||||||
#define Catch(e)
|
#define Catch(e)
|
||||||
else { } <- this also forces proper scoping. Without this they could stick their own 'else' in and it would get ugly
|
else { } <- this also forces proper scoping. Without this they could stick their own 'else' in and it would get ugly
|
||||||
CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- no errors happened, so just set the exception id to NONE (in case it was corrupted)
|
CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- no errors happened, so just set the exception id to NONE (in case it was corrupted)
|
||||||
}
|
}
|
||||||
else <- an exception occurred
|
else <- an exception occurred
|
||||||
{ e = CExceptionFrames[MY_ID].Exception; e=e;} <- assign the caught exception id to the variable passed in.
|
{ e = CExceptionFrames[MY_ID].Exception; e=e;} <- assign the caught exception id to the variable passed in.
|
||||||
CExceptionFrames[MY_ID].pFrame = PrevFrame; <- make the pointer in the array point at the previous frame again, as if NewFrame never existed.
|
CExceptionFrames[MY_ID].pFrame = PrevFrame; <- make the pointer in the array point at the previous frame again, as if NewFrame never existed.
|
||||||
} <- finish off that local scope we created to have our own variables
|
} <- finish off that local scope we created to have our own variables
|
||||||
if (CExceptionFrames[CEXCEPTION_GET_ID].Exception != CEXCEPTION_NONE) <- start the actual 'catch' processing if we have an exception id saved away
|
if (CExceptionFrames[CEXCEPTION_GET_ID].Exception != CEXCEPTION_NONE) <- start the actual 'catch' processing if we have an exception id saved away
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
#Tool and Lib Locations
|
#Tool and Lib Locations
|
||||||
C_COMPILER=gcc
|
C_COMPILER=gcc
|
||||||
C_LIBS=C:/MinGW/lib
|
C_LIBS=C:/MinGW/lib
|
||||||
UNITY_DIR=vendor/unity/src
|
UNITY_DIR=vendor/unity/src
|
||||||
|
|
||||||
#Test File To Be Created
|
#Test File To Be Created
|
||||||
OUT_FILE=test_cexceptions
|
OUT_FILE=test_cexceptions
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
OUT_EXTENSION=.exe
|
OUT_EXTENSION=.exe
|
||||||
else
|
else
|
||||||
OUT_EXTENSION=.out
|
OUT_EXTENSION=.out
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#Options
|
#Options
|
||||||
SRC_FILES=lib/CException.c test/TestException.c test/TestException_Runner.c $(UNITY_DIR)/unity.c
|
SRC_FILES=lib/CException.c test/TestException.c test/TestException_Runner.c $(UNITY_DIR)/unity.c
|
||||||
INC_DIRS=-Ilib -Itest -I$(UNITY_DIR)
|
INC_DIRS=-Ilib -Itest -I$(UNITY_DIR)
|
||||||
LIB_DIRS=-L$(C_LIBS)
|
LIB_DIRS=-L$(C_LIBS)
|
||||||
SYMBOLS=-DTEST -DCEXCEPTION_USE_CONFIG_FILE
|
SYMBOLS=-DTEST -DCEXCEPTION_USE_CONFIG_FILE
|
||||||
|
|
||||||
#Default Task: Compile And Run Tests
|
#Default Task: Compile And Run Tests
|
||||||
default:
|
default:
|
||||||
$(C_COMPILER) $(INC_DIRS) $(LIB_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(OUT_FILE)$(OUT_EXTENSION)
|
$(C_COMPILER) $(INC_DIRS) $(LIB_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(OUT_FILE)$(OUT_EXTENSION)
|
||||||
$(OUT_FILE)$(OUT_EXTENSION)
|
$(OUT_FILE)$(OUT_EXTENSION)
|
||||||
|
|
||||||
+46
-46
@@ -1,46 +1,46 @@
|
|||||||
#ifndef _EXCEPTION_H
|
#ifndef _EXCEPTION_H
|
||||||
#define _EXCEPTION_H
|
#define _EXCEPTION_H
|
||||||
|
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
|
||||||
extern volatile int TestingTheFallback;
|
extern volatile int TestingTheFallback;
|
||||||
extern volatile int TestingTheFallbackId;
|
extern volatile int TestingTheFallbackId;
|
||||||
|
|
||||||
//Optionally define the exception type (something like an int which can be directly assigned)
|
//Optionally define the exception type (something like an int which can be directly assigned)
|
||||||
#define CEXCEPTION_T int
|
#define CEXCEPTION_T int
|
||||||
|
|
||||||
// Optionally define the reserved value representing NO EXCEPTION
|
// Optionally define the reserved value representing NO EXCEPTION
|
||||||
#define CEXCEPTION_NONE (1234)
|
#define CEXCEPTION_NONE (1234)
|
||||||
|
|
||||||
// Optionally define a special handler for unhandled exceptions
|
// Optionally define a special handler for unhandled exceptions
|
||||||
#define CEXCEPTION_NO_CATCH_HANDLER(id) \
|
#define CEXCEPTION_NO_CATCH_HANDLER(id) \
|
||||||
{ \
|
{ \
|
||||||
if (!TestingTheFallback) \
|
if (!TestingTheFallback) \
|
||||||
{ \
|
{ \
|
||||||
TEST_FAIL_MESSAGE("Unexpected Exception!"); \
|
TEST_FAIL_MESSAGE("Unexpected Exception!"); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
TestingTheFallbackId = id; \
|
TestingTheFallbackId = id; \
|
||||||
TestingTheFallback--; \
|
TestingTheFallback--; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multi-Tasking environments will need a couple of macros defined to make this library
|
// Multi-Tasking environments will need a couple of macros defined to make this library
|
||||||
// properly handle multiple exception stacks. You will need to include and required
|
// properly handle multiple exception stacks. You will need to include and required
|
||||||
// definitions, then define the following macros:
|
// definitions, then define the following macros:
|
||||||
// EXCEPTION_GET_ID - returns the id of the current task indexed 0 to (numtasks - 1)
|
// EXCEPTION_GET_ID - returns the id of the current task indexed 0 to (numtasks - 1)
|
||||||
// EXCEPTION_NUM_ID - returns the number of tasks that might be returned
|
// EXCEPTION_NUM_ID - returns the number of tasks that might be returned
|
||||||
//
|
//
|
||||||
// For example, Quadros might include the following implementation:
|
// For example, Quadros might include the following implementation:
|
||||||
#ifndef TEST
|
#ifndef TEST
|
||||||
#include "OSAPI.h"
|
#include "OSAPI.h"
|
||||||
#define CEXCEPTION_GET_ID (KS_GetTaskID())
|
#define CEXCEPTION_GET_ID (KS_GetTaskID())
|
||||||
#define CEXCEPTION_NUM_ID (NTASKS + 1)
|
#define CEXCEPTION_NUM_ID (NTASKS + 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//This could be a good place to define/include some error ID's:
|
//This could be a good place to define/include some error ID's:
|
||||||
#define ERROR_ID_EVERYTHING_IS_BROKEN (0x88)
|
#define ERROR_ID_EVERYTHING_IS_BROKEN (0x88)
|
||||||
#define ERROR_ID_ONLY_THIS_IS_BROKEN (0x77)
|
#define ERROR_ID_ONLY_THIS_IS_BROKEN (0x77)
|
||||||
|
|
||||||
#endif // _EXCEPTION_H
|
#endif // _EXCEPTION_H
|
||||||
|
|||||||
Reference in New Issue
Block a user