source: trunk/python2/include/aff4_errors.h@ 209

Last change on this file since 209 was 196, checked in by tim, 15 years ago

experimental python bindings generator as provided by Michael Cohen

File size: 2.0 KB
Line 
1/*
2** aff4_errors.h
3**
4** Made by mic
5** Login <mic@laptop>
6**
7** Started on Sat Mar 6 20:54:25 2010 mic
8** Last update Sat Mar 6 20:54:25 2010 mic
9*/
10
11#ifndef AFF4_ERRORS_H_
12# define AFF4_ERRORS_H_
13
14// Some helpful little things
15#define ERROR_BUFFER_SIZE 1024
16
17/** This is used for error reporting. This is similar to the way
18 python does it, i.e. we set the error flag and return NULL.
19*/
20enum _error_type {
21 EZero,EGeneric,EOverflow,EWarning,
22 EUnderflow,EIOError, ENoMemory, EInvalidParameter, ERuntimeError, EKeyError,
23
24 // Reserved for impossible conditions
25 EProgrammingError
26};
27
28void *raise_errors(enum _error_type t, char *string, ...);
29
30/** We only set the error state if its not already set */
31#define RaiseError(t, message, ...) \
32 if(*aff4_get_current_error(NULL) == EZero) { \
33 raise_errors(t, "%s: (%s:%d) " message, __FUNCTION__, __FILE__, __LINE__, ## __VA_ARGS__); \
34 };
35
36#define LogWarnings(format, ...) \
37 do { \
38 RaiseError(EWarning, format, ## __VA_ARGS__); \
39 PrintError(); \
40 } while(0);
41
42#define ClearError() \
43 do {*aff4_get_current_error(NULL) = EZero;} while(0);
44
45#define PrintError() \
46 do {char *error_str; if(*aff4_get_current_error(&error_str)) fprintf(stdout, "%s", error_str); fflush(stdout); ClearError(); }while(0);
47
48#define CheckError(error) \
49 (*aff4_get_current_error(NULL) == error)
50
51/** The current error state is returned by this function.
52
53 This is done in a thread safe manner.
54 */
55enum _error_type *aff4_get_current_error(char **error_str);
56
57
58// These macros are used when we need to do something which might
59// change the error state on the error path of a function.
60#define PUSH_ERROR_STATE { enum _error_type *tmp_error_p = aff4_get_current_error(NULL); enum _error_type tmp_error = *tmp_error_p; enum _error_type exception __attribute__((unused));
61
62#define POP_ERROR_STATE *tmp_error_p = tmp_error;};
63
64
65void error_init();
66
67#endif /* !AFF4_ERRORS_H_ */
Note: See TracBrowser for help on using the repository browser.