mirror of
https://github.com/throwtheswitch/cexception.git
synced 2026-07-29 23:37:49 +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
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
The end-user documentation included with the redistribution, if
|
||||
any, must include the following acknowledgment: "This product
|
||||
includes software developed for the CEXCeption Project, by Mark
|
||||
VanderVoord and other contributors", in the same place and form
|
||||
as other third-party acknowledgments. Alternately, this
|
||||
acknowledgment may appear in the software itself, in the same
|
||||
form and location as other such third-party acknowledgments.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
Copyright (c) 2007-2014 Mark VanderVoord
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
The end-user documentation included with the redistribution, if
|
||||
any, must include the following acknowledgment: "This product
|
||||
includes software developed for the CEXCeption Project, by Mark
|
||||
VanderVoord and other contributors", in the same place and form
|
||||
as other third-party acknowledgments. Alternately, this
|
||||
acknowledgment may appear in the software itself, in the same
|
||||
form and location as other such third-party acknowledgments.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
+46
-46
@@ -1,46 +1,46 @@
|
||||
#include "CException.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
volatile CEXCEPTION_FRAME_T CExceptionFrames[CEXCEPTION_NUM_ID] = {{ 0 }};
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// Throw
|
||||
//------------------------------------------------------------------------------------------
|
||||
void Throw(CEXCEPTION_T ExceptionID)
|
||||
{
|
||||
unsigned int MY_ID = CEXCEPTION_GET_ID;
|
||||
CExceptionFrames[MY_ID].Exception = ExceptionID;
|
||||
if (CExceptionFrames[MY_ID].pFrame)
|
||||
{
|
||||
longjmp(*CExceptionFrames[MY_ID].pFrame, 1);
|
||||
}
|
||||
CEXCEPTION_NO_CATCH_HANDLER(ExceptionID);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// Explanation of what it's all for:
|
||||
//------------------------------------------------------------------------------------------
|
||||
/*
|
||||
#define Try
|
||||
{ <- 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
|
||||
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)
|
||||
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
|
||||
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.
|
||||
|
||||
#define Catch(e)
|
||||
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)
|
||||
}
|
||||
else <- an exception occurred
|
||||
{ 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.
|
||||
} <- 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
|
||||
*/
|
||||
|
||||
#include "CException.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
volatile CEXCEPTION_FRAME_T CExceptionFrames[CEXCEPTION_NUM_ID] = {{ 0 }};
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// Throw
|
||||
//------------------------------------------------------------------------------------------
|
||||
void Throw(CEXCEPTION_T ExceptionID)
|
||||
{
|
||||
unsigned int MY_ID = CEXCEPTION_GET_ID;
|
||||
CExceptionFrames[MY_ID].Exception = ExceptionID;
|
||||
if (CExceptionFrames[MY_ID].pFrame)
|
||||
{
|
||||
longjmp(*CExceptionFrames[MY_ID].pFrame, 1);
|
||||
}
|
||||
CEXCEPTION_NO_CATCH_HANDLER(ExceptionID);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
// Explanation of what it's all for:
|
||||
//------------------------------------------------------------------------------------------
|
||||
/*
|
||||
#define Try
|
||||
{ <- 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
|
||||
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)
|
||||
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
|
||||
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.
|
||||
|
||||
#define Catch(e)
|
||||
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)
|
||||
}
|
||||
else <- an exception occurred
|
||||
{ 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.
|
||||
} <- 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
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#Tool and Lib Locations
|
||||
C_COMPILER=gcc
|
||||
C_LIBS=C:/MinGW/lib
|
||||
UNITY_DIR=vendor/unity/src
|
||||
|
||||
#Test File To Be Created
|
||||
OUT_FILE=test_cexceptions
|
||||
ifeq ($(OS),Windows_NT)
|
||||
OUT_EXTENSION=.exe
|
||||
else
|
||||
OUT_EXTENSION=.out
|
||||
endif
|
||||
|
||||
#Options
|
||||
SRC_FILES=lib/CException.c test/TestException.c test/TestException_Runner.c $(UNITY_DIR)/unity.c
|
||||
INC_DIRS=-Ilib -Itest -I$(UNITY_DIR)
|
||||
LIB_DIRS=-L$(C_LIBS)
|
||||
SYMBOLS=-DTEST -DCEXCEPTION_USE_CONFIG_FILE
|
||||
|
||||
#Default Task: Compile And Run Tests
|
||||
default:
|
||||
$(C_COMPILER) $(INC_DIRS) $(LIB_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(OUT_FILE)$(OUT_EXTENSION)
|
||||
$(OUT_FILE)$(OUT_EXTENSION)
|
||||
#Tool and Lib Locations
|
||||
C_COMPILER=gcc
|
||||
C_LIBS=C:/MinGW/lib
|
||||
UNITY_DIR=vendor/unity/src
|
||||
|
||||
#Test File To Be Created
|
||||
OUT_FILE=test_cexceptions
|
||||
ifeq ($(OS),Windows_NT)
|
||||
OUT_EXTENSION=.exe
|
||||
else
|
||||
OUT_EXTENSION=.out
|
||||
endif
|
||||
|
||||
#Options
|
||||
SRC_FILES=lib/CException.c test/TestException.c test/TestException_Runner.c $(UNITY_DIR)/unity.c
|
||||
INC_DIRS=-Ilib -Itest -I$(UNITY_DIR)
|
||||
LIB_DIRS=-L$(C_LIBS)
|
||||
SYMBOLS=-DTEST -DCEXCEPTION_USE_CONFIG_FILE
|
||||
|
||||
#Default Task: Compile And Run Tests
|
||||
default:
|
||||
$(C_COMPILER) $(INC_DIRS) $(LIB_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(OUT_FILE)$(OUT_EXTENSION)
|
||||
$(OUT_FILE)$(OUT_EXTENSION)
|
||||
|
||||
+46
-46
@@ -1,46 +1,46 @@
|
||||
#ifndef _EXCEPTION_H
|
||||
#define _EXCEPTION_H
|
||||
|
||||
#include "unity.h"
|
||||
|
||||
extern volatile int TestingTheFallback;
|
||||
extern volatile int TestingTheFallbackId;
|
||||
|
||||
//Optionally define the exception type (something like an int which can be directly assigned)
|
||||
#define CEXCEPTION_T int
|
||||
|
||||
// Optionally define the reserved value representing NO EXCEPTION
|
||||
#define CEXCEPTION_NONE (1234)
|
||||
|
||||
// Optionally define a special handler for unhandled exceptions
|
||||
#define CEXCEPTION_NO_CATCH_HANDLER(id) \
|
||||
{ \
|
||||
if (!TestingTheFallback) \
|
||||
{ \
|
||||
TEST_FAIL_MESSAGE("Unexpected Exception!"); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
TestingTheFallbackId = id; \
|
||||
TestingTheFallback--; \
|
||||
} \
|
||||
}
|
||||
|
||||
// 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
|
||||
// definitions, then define the following macros:
|
||||
// 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
|
||||
//
|
||||
// For example, Quadros might include the following implementation:
|
||||
#ifndef TEST
|
||||
#include "OSAPI.h"
|
||||
#define CEXCEPTION_GET_ID (KS_GetTaskID())
|
||||
#define CEXCEPTION_NUM_ID (NTASKS + 1)
|
||||
#endif
|
||||
|
||||
//This could be a good place to define/include some error ID's:
|
||||
#define ERROR_ID_EVERYTHING_IS_BROKEN (0x88)
|
||||
#define ERROR_ID_ONLY_THIS_IS_BROKEN (0x77)
|
||||
|
||||
#endif // _EXCEPTION_H
|
||||
#ifndef _EXCEPTION_H
|
||||
#define _EXCEPTION_H
|
||||
|
||||
#include "unity.h"
|
||||
|
||||
extern volatile int TestingTheFallback;
|
||||
extern volatile int TestingTheFallbackId;
|
||||
|
||||
//Optionally define the exception type (something like an int which can be directly assigned)
|
||||
#define CEXCEPTION_T int
|
||||
|
||||
// Optionally define the reserved value representing NO EXCEPTION
|
||||
#define CEXCEPTION_NONE (1234)
|
||||
|
||||
// Optionally define a special handler for unhandled exceptions
|
||||
#define CEXCEPTION_NO_CATCH_HANDLER(id) \
|
||||
{ \
|
||||
if (!TestingTheFallback) \
|
||||
{ \
|
||||
TEST_FAIL_MESSAGE("Unexpected Exception!"); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
TestingTheFallbackId = id; \
|
||||
TestingTheFallback--; \
|
||||
} \
|
||||
}
|
||||
|
||||
// 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
|
||||
// definitions, then define the following macros:
|
||||
// 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
|
||||
//
|
||||
// For example, Quadros might include the following implementation:
|
||||
#ifndef TEST
|
||||
#include "OSAPI.h"
|
||||
#define CEXCEPTION_GET_ID (KS_GetTaskID())
|
||||
#define CEXCEPTION_NUM_ID (NTASKS + 1)
|
||||
#endif
|
||||
|
||||
//This could be a good place to define/include some error ID's:
|
||||
#define ERROR_ID_EVERYTHING_IS_BROKEN (0x88)
|
||||
#define ERROR_ID_ONLY_THIS_IS_BROKEN (0x77)
|
||||
|
||||
#endif // _EXCEPTION_H
|
||||
|
||||
Reference in New Issue
Block a user