diff options
Diffstat (limited to 'src/main/c/common')
-rw-r--r-- | src/main/c/common/assert_is.h | 39 | ||||
-rw-r--r-- | src/main/c/common/commonbase.h (renamed from src/main/c/common/commonKludge.h) | 0 | ||||
-rw-r--r-- | src/main/c/common/offset_of.h | 9 | ||||
-rw-r--r-- | src/main/c/common/windoof.h | 59 |
4 files changed, 107 insertions, 0 deletions
diff --git a/src/main/c/common/assert_is.h b/src/main/c/common/assert_is.h new file mode 100644 index 0000000..316bf02 --- /dev/null +++ b/src/main/c/common/assert_is.h @@ -0,0 +1,39 @@ + +#if !NDEBUG +#define TPL_assert_is(T, PRED) static inline T*assert_is_##T(void*p,\ +const char*f,int l){if(p==NULL){fprintf(stderr,"assert(" STR_QUOT(T)\ +" != NULL) %s:%d\n",f,l);abort();}T*obj=p;if(!(PRED)){fprintf(stderr,\ +"ssert(type is \""STR_QUOT(T)"\") %s:%d\n",f,l);abort();}return p; } +#else +#define TPL_assert_is(T, PRED) static inline T*assert_is_##T(void*p,\ +const char*f,int l){return p;} +#endif + + + +/* Example usage: */ + +/* add some magic to your struct under check */ +typedef struct Person Person; +struct Person { + char tYPE[sizeof"Hi, I'm a Person"]; +}; + +/* instantiate a checker */ +TPL_assert_is(Person, !strcmp(obj->tYPE, "Hi, I'm a Person")) +#define assert_is_Person(p) assert_is_Person(p, __FILE__, __LINE__) + +/* make sure magic is initialized (ALSO MAKE SURE TO PROPERLY INVALIDATE + * IT IN DTOR!)*/ +static void someCaller( void ){ + Person p = {0}; + strcpy(p.tYPE, "Hi, I'm a Person"); + void *ptr = p; /*whops compiler cannot help us any longer*/ + someCallee(ptr); +} + +/* verify you reall got a Person*/ +static void someCallee( void*shouldBeAPerson ){ + Person *p = assert_is_Person(shouldBeAPerson); +} + diff --git a/src/main/c/common/commonKludge.h b/src/main/c/common/commonbase.h index e0f0cba..e0f0cba 100644 --- a/src/main/c/common/commonKludge.h +++ b/src/main/c/common/commonbase.h diff --git a/src/main/c/common/offset_of.h b/src/main/c/common/offset_of.h new file mode 100644 index 0000000..7d9179d --- /dev/null +++ b/src/main/c/common/offset_of.h @@ -0,0 +1,9 @@ +#ifndef INCGUARD_yisgKqALPG4lfEqb +#define INCGUARD_yisgKqALPG4lfEqb + + +#define container_of(P, T, M) \ + ((T*)( ((size_t)P) - ((size_t)((char*)&((T*)0)->M - (char*)0) ))) + + +#endif /* INCGUARD_yisgKqALPG4lfEqb */ diff --git a/src/main/c/common/windoof.h b/src/main/c/common/windoof.h new file mode 100644 index 0000000..6ed9b41 --- /dev/null +++ b/src/main/c/common/windoof.h @@ -0,0 +1,59 @@ + +#if 0 +# include <windows.h> +#else + +#include <stdint.h> + +//#define HANDLE void* +//typedef int BOOL; +//typedef unsigned long LPDWORD; + + +typedef struct _PROCESS_INFORMATION { + void* hProcess; + void* hThread; + uint32_t dwProcessId; + uint32_t dwThreadId; +} PROCESS_INFORMATION, *PPROCESS_INFORMATION, *LPPROCESS_INFORMATION; + + +typedef struct _SECURITY_ATTRIBUTES { + uint32_t nLength; + void* lpSecurityDescriptor; + int bInheritHandle; +} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; + + +typedef struct _STARTUPINFOA { + uint32_t cb; + char *lpReserved; + char *lpDesktop; + char *lpTitle; + uint32_t dwX; + uint32_t dwY; + uint32_t dwXSize; + uint32_t dwYSize; + uint32_t dwXCountChars; + uint32_t dwYCountChars; + uint32_t dwFillAttribute; + uint32_t dwFlags; + short wShowWindow; + short cbReserved2; + uint8_t lpReserved2; + void *hStdInput, *hStdOutput, *hStdError; +} STARTUPINFOA, *LPSTARTUPINFOA; + + + +int CreateProcessA( char const*, char*, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, int, uint32_t, + void*, char const*, LPSTARTUPINFOA, LPPROCESS_INFORMATION ); + + +int GetExitCodeProcess(void*, unsigned long*); + + + + + +#endif /*manual windoof on/off switch*/ |