mirror of
https://github.com/ThrowTheSwitch/CException
synced 2025-05-18 17:29:33 -04:00
cleaned up order of inclusion and testability
git-svn-id: http://cexception.svn.sourceforge.net/svnroot/cexception/trunk@3 50f63946-2846-0410-8d77-f904c773002e
This commit is contained in:
parent
fecd94cb5c
commit
7044cfe1a8
54
lib/CException.h
Normal file
54
lib/CException.h
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef _CEXCEPTION_H
|
||||
#define _CEXCEPTION_H
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifndef EXCEPTION_NONE
|
||||
#define EXCEPTION_NONE (0x5A5A5A5A)
|
||||
#endif
|
||||
|
||||
#ifndef EXCEPTION_NUM_ID
|
||||
#define EXCEPTION_NUM_ID (1) //there is only the one stack by default
|
||||
#endif
|
||||
|
||||
#ifndef EXCEPTION_GET_ID
|
||||
#define EXCEPTION_GET_ID (0) //use the first index always because there is only one anyway
|
||||
#endif
|
||||
|
||||
//exception frame structures
|
||||
typedef struct {
|
||||
jmp_buf* pFrame;
|
||||
volatile unsigned int Exception;
|
||||
volatile unsigned int Details;
|
||||
} EXCEPTION_FRAME_T;
|
||||
extern volatile EXCEPTION_FRAME_T ExceptionFrames[];
|
||||
|
||||
#define MY_FRAME (ExceptionFrames[EXCEPTION_GET_ID])
|
||||
#define MY_FRAME_FAST (ExceptionFrames[MY_ID])
|
||||
#define EXCEPTION_ID (MY_FRAME.Exception)
|
||||
#define EXCEPTION_DETAILS (MY_FRAME.Details)
|
||||
|
||||
#define Try \
|
||||
{ \
|
||||
jmp_buf *PrevFrame, NewFrame; \
|
||||
unsigned int MY_ID = EXCEPTION_GET_ID; \
|
||||
PrevFrame = MY_FRAME.pFrame; \
|
||||
MY_FRAME_FAST.pFrame = &NewFrame; \
|
||||
MY_FRAME_FAST.Details = 0; \
|
||||
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
||||
if (setjmp(NewFrame) == 0) { \
|
||||
if (&PrevFrame)
|
||||
|
||||
#define Catch \
|
||||
else { } \
|
||||
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
||||
} \
|
||||
MY_FRAME_FAST.pFrame = PrevFrame; \
|
||||
} \
|
||||
if (MY_FRAME.Exception != EXCEPTION_NONE)
|
||||
|
||||
#define Throw(id) ThrowDetailed(id, __LINE__)
|
||||
void ThrowDetailed(unsigned int ExceptionID, unsigned int Details);
|
||||
void Rethrow(void);
|
||||
|
||||
#endif // _CEXCEPTION_H
|
@ -1,43 +1,23 @@
|
||||
#ifndef _EXCEPTION_H
|
||||
#define _EXCEPTION_H
|
||||
|
||||
#include <setjmp.h>
|
||||
#include "ExceptionConfig.h"
|
||||
// Define the reserved value representing NO EXCEPTION
|
||||
#define EXCEPTION_NONE (0x5A5A5A5A)
|
||||
|
||||
//exception frame structures
|
||||
typedef struct {
|
||||
jmp_buf* pFrame;
|
||||
volatile unsigned int Exception;
|
||||
volatile unsigned int Details;
|
||||
} EXCEPTION_FRAME_T;
|
||||
extern volatile EXCEPTION_FRAME_T ExceptionFrames[];
|
||||
// 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 EXCEPTION_GET_ID() (KS_GetTaskID())
|
||||
#define EXCEPTION_NUM_ID (NTASKS + 1)
|
||||
#endif
|
||||
|
||||
#define MY_FRAME (ExceptionFrames[EXCEPTION_GET_ID()])
|
||||
#define MY_FRAME_FAST (ExceptionFrames[MY_ID])
|
||||
#define EXCEPTION_ID (MY_FRAME.Exception)
|
||||
#define EXCEPTION_DETAILS (MY_FRAME.Details)
|
||||
|
||||
#define Try \
|
||||
{ \
|
||||
jmp_buf *PrevFrame, NewFrame; \
|
||||
unsigned int MY_ID = EXCEPTION_GET_ID(); \
|
||||
PrevFrame = MY_FRAME.pFrame; \
|
||||
MY_FRAME_FAST.pFrame = &NewFrame; \
|
||||
MY_FRAME_FAST.Details = 0; \
|
||||
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
||||
if (setjmp(NewFrame) == 0) { \
|
||||
if (&PrevFrame)
|
||||
|
||||
#define Catch \
|
||||
else { } \
|
||||
MY_FRAME_FAST.Exception = EXCEPTION_NONE; \
|
||||
} \
|
||||
MY_FRAME_FAST.pFrame = PrevFrame; \
|
||||
} \
|
||||
if (MY_FRAME.Exception != EXCEPTION_NONE)
|
||||
|
||||
#define Throw(id) ThrowDetailed(id, __LINE__)
|
||||
void ThrowDetailed(unsigned int ExceptionID, unsigned int Details);
|
||||
void Rethrow(void);
|
||||
// INCLUDE THE ACTUAL CEXCEPTION LIBRARY
|
||||
#include "CException.h"
|
||||
|
||||
#endif // _EXCEPTION_H
|
||||
|
@ -1,26 +0,0 @@
|
||||
#ifndef _EXCEPTION_CONFIG_H
|
||||
#define _EXCEPTION_CONFIG_H
|
||||
|
||||
//#define EXCEPTION_MULTI_STACK
|
||||
#define EXCEPTION_NONE (0x5A5A5A5A)
|
||||
|
||||
//if using multistack support and not currently running a test, must include multistack support
|
||||
#undef EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
|
||||
#ifndef TEST
|
||||
#ifdef EXCEPTION_MULTI_STACK
|
||||
#define EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//define the method of automatically looking up the current frame index (mappable from task ID if the task ID's are consecutive)
|
||||
// The example below supports the Quadros OS in Multi-Stack Mode. Most RTOS will support a similar function call.
|
||||
#ifdef EXCEPTION_INCLUDE_MULTI_STACK_SUPPORT
|
||||
#include "OSAPI.h"
|
||||
#define EXCEPTION_GET_ID() (KS_GetTaskID())
|
||||
#define EXCEPTION_NUM_ID (NTASKS + 1)
|
||||
#else
|
||||
#define EXCEPTION_GET_ID() (0) //use the first index always because there is only one anyway
|
||||
#define EXCEPTION_NUM_ID (1) //there is only the one stack
|
||||
#endif
|
||||
|
||||
#endif //_EXCEPTION_CONFIG_H
|
4
makefile
4
makefile
@ -1,7 +1,7 @@
|
||||
#Tool and Lib Locations
|
||||
C_COMPILER=gcc
|
||||
C_LIBS=C:/MinGW/lib
|
||||
UNITY_DIR=../../unity/src
|
||||
UNITY_DIR=vendor/unity/src
|
||||
|
||||
#Test File To Be Created
|
||||
OUT_FILE=test_cexceptions
|
||||
@ -12,7 +12,7 @@ OUT_EXTENSION=.out
|
||||
endif
|
||||
|
||||
#Options
|
||||
SRC_FILES=lib/Exception.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)
|
||||
LIB_DIRS=-L$(C_LIBS)
|
||||
SYMBOLS=-DTEST
|
||||
|
@ -1,9 +1,6 @@
|
||||
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||
#include "unity.h"
|
||||
#include "Exception.h"
|
||||
#include <setjmp.h>
|
||||
|
||||
jmp_buf AbortFrame;
|
||||
|
||||
extern void setUp(void);
|
||||
extern void tearDown(void);
|
||||
@ -21,7 +18,7 @@ extern void test_CanThrowADetailedExceptionAndCheckOutTheResults(void);
|
||||
|
||||
static void runTest(UnityTestFunction test)
|
||||
{
|
||||
if (setjmp(AbortFrame) == 0)
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
setUp();
|
||||
Try
|
||||
|
Loading…
x
Reference in New Issue
Block a user