6 #ifndef misc_header_included
7 #define misc_header_included
51 #define TIMEOUT_CODE (128+14)
54 #define STRINGIFY_SECOND_STAGE(symbol) #symbol
58 #define STRINGIFY(symbol) STRINGIFY_SECOND_STAGE(symbol)
61 #define abort() pips_stop(internal_error_log, -1, "abort() called")
62 #define exit(code) pips_stop(user_error_log, code, "exit(%d) called", code)
67 # if defined(CURRENT_FUNCTION)
68 # undef CURRENT_FUNCTION
71 #define pips_unknown_function "Unknown Function Name"
73 # if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
74 # define CURRENT_FUNCTION __func__
76 # if defined(__GNUC__)
77 # define CURRENT_FUNCTION __FUNCTION__
79 # define CURRENT_FUNCTION pips_unknown_function
96 #define pips_debug(level, format, args...) \
99 fprintf(stderr, "[%s] " format, CURRENT_FUNCTION, ##args); \
103 #define pips_user_warning(format, args...) \
104 pips_user_warning_func(CURRENT_FUNCTION, __FILE__, __LINE__, format, ##args)
106 #define pips_user_error(format, args...) \
107 pips_user_error_func(CURRENT_FUNCTION, __FILE__, __LINE__, format, ##args)
109 #define pips_user_irrecoverable_error(format, args...) \
110 pips_user_irrecoverable_error_func(CURRENT_FUNCTION, __FILE__, __LINE__, \
114 #define pips_internal_error(format, args...) \
115 pips_internal_error_func(CURRENT_FUNCTION, __FILE__ , __LINE__, \
118 #define pips_log(args...) \
119 pips_log_func(CURRENT_FUNCTION, __FILE__, __LINE__, ##args)
121 #define pips_stop(args...) \
122 pips_stop_func(CURRENT_FUNCTION, __FILE__, __LINE__, ##args)
124 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
126 #define pips_debug(level, ...) \
129 pips_debug_func(level, CURRENT_FUNCTION, __VA_ARGS__); \
132 #define pips_user_warning(...) \
133 pips_user_warning_func(CURRENT_FUNCTION, __FILE__, __LINE__, __VA_ARGS__)
135 #define pips_user_error(...) \
136 pips_user_error_func(CURRENT_FUNCTION, __FILE__, __LINE__, __VA_ARGS__)
138 #define pips_user_irrecoverable_error(...) \
139 pips_user_irrecoverable_error_func(CURRENT_FUNCTION, __FILE__, __LINE__, \
142 #define pips_internal_error(...) \
143 pips_internal_error_func(CURRENT_FUNCTION, __FILE__ , __LINE__, \
146 #define pips_log(...) \
147 pips_log_func(CURRENT_FUNCTION, __FILE__, __LINE__, __VA_ARGS__)
149 #define pips_stop(...) \
150 pips_log_func(CURRENT_FUNCTION, __FILE__, __LINE__, __VA_ARGS__)
153 #define pips_debug pips_debug_func2
154 #define pips_user_warning pips_user_warning_func2
155 #define pips_user_error pips_user_error_func2
156 #define pips_user_irrecoverable_error pips_user_irrecoverable_error_func2
157 #define pips_internal_error pips_internal_error_func2
158 #define pips_log pips_log_func2
159 #define pips_stop pips_stop_func2
162 #define pips_where(out) \
163 fprintf(out, "[%s] (%s:%d) ", CURRENT_FUNCTION, __FILE__, __LINE__)
165 #define debug_on(env) \
166 debug_on_function(env, CURRENT_FUNCTION, __FILE__, __LINE__)
168 #define debug_off() \
169 debug_off_function(CURRENT_FUNCTION, __FILE__, __LINE__)
174 #define pips_assert(what, predicate)
175 #define pips_user_assert(what, predicate)
176 #define ifdebug(l) if(0)
180 #define pips_assert(what, predicate) \
182 if (!(predicate)) { \
183 pips_internal_error("assertion failed\n\n '%s' not verified\n\n", \
189 #define pips_user_assert(what, predicate) \
191 if (!(predicate)) { \
192 pips_user_error("assertion failed\n\n '%s' not verified\n\n" \
193 "this is a USER ERROR, I guess\n", what); \
197 #define ifdebug(l) if (the_current_debug_level>=(l))
201 #define pips_exit(code, format, args...) \
202 pips_user_warning(format, ##args), exit(code)
206 #define same_string_p(s1, s2) function_same_string_p(s1,s2)
207 #define same_stringn_p(a,b,c) (!strncmp((a),(b),(c)))
211 #define MAXPATHLEN 1024
214 #define PIPS_CATCH(what) \
215 if (push_debug_status(), \
216 setjmp(*push_exception_on_stack(what, __CURRENT_FUNCTION_NAME__, \
217 __FILE__, __LINE__, pop_debug_status)))
220 #define SIGN_EQ(a,b) ((((a)>0 && (b)>0) || ((a)<0 && (b)<0)) ? true : false)
221 #define FORTRAN_DIV(n,d) (SIGN_EQ((n),(d)) ? ABS(n)/ABS(d) : -(ABS(n)/ABS(d)))
222 #define C_DIVISION(n,d) ((n)/(d))
223 #define FORTRAN_MOD(n,m) (SIGN_EQ((n),(m)) ? ABS(n)%ABS(m) : -(ABS(n)%ABS(m)))
224 #define C_MODULO(n,m) ((n)%(m))
233 #define asprintf safe_asprintf
234 #define vasprintf safe_vasprintf
236 #ifndef __has_attribute
237 #define __has_attribute(att) 0
240 #define _UNUSED_ __attribute__((unused))
241 #define _NORETURN_ __attribute__((noreturn))
243 #if __has_attribute(fallthrough)
244 #define _FALLTHROUGH_ __attribute__((fallthrough))
246 #define _FALLTHROUGH_
259 const char *,
const char *,
const int,
const char *, va_list *);
261 const char *,
const char *,
const int,
const char *, ...);
270 #define user_warning(fn, ...) \
271 pips_user_warning_func(fn, __FILE__, __LINE__, __VA_ARGS__)
273 #define user_error(fn, ...) \
274 pips_user_error_func(fn, __FILE__, __LINE__, __VA_ARGS__)
282 extern void debug_on_function(
const char *,
const char *,
const char *,
const int );
285 extern void debug(
const int ,
const char *,
const char *, ...);
290 extern FILE *
check_fopen(
const char *,
const char *);
291 extern FILE *
safe_fopen(
const char *,
const char *);
295 extern int safe_fseek(FILE *,
long int ,
int ,
char *);
300 extern char *
safe_fgets(
char *,
int , FILE *,
char *);
303 extern int safe_fputs(
char *, FILE *,
char *);
304 extern int safe_fread(
char *,
int ,
int , FILE *,
char *);
305 extern int safe_fwrite(
char *,
int ,
int , FILE *,
char *);
311 extern string nth_path(
const char *,
int );
322 extern void safe_cat(FILE *, FILE *);
323 extern void safe_append(FILE *,
char *,
int ,
bool );
332 extern void safe_link(
const char *,
const char *);
336 extern FILE *
fopen_config(
const char *,
const char *,
const char *);
351 extern void user_log(
const char *, ...);
375 extern void pips_log_desc(
const pips_log_t tag,
const string ,
const string ,
const string ,
const string ,
const int ,
const string ,
const string ,
const int ,
const int ,
const string ,
const string ,
const string );
376 extern void pips_log_alist(
const pips_log_t tag,
const string ,
const string ,
const string ,
const string ,
const int ,
const string ,
const string ,
const int ,
const int ,
const string ,
const string ,
const string , va_list *);
377 extern void pips_log_func(
const string ,
const string ,
const int ,
const pips_log_t tag,
const string ,
const string ,
const string ,
const string ,
const int ,
const int ,
const string ,
const string ,
const string , ...);
382 extern void start_dotting(FILE *,
const char ,
const char *, ...);
void set_pips_meta_informations(const char *, const char *, const char *)
void sort_list_of_strings(list)
Sort a list of strings.
void user_log(const char *,...)
void set_debug_stack_pointer(const int)
long int safe_ftell(FILE *, char *)
double get_process_memory_size(void)
void pips_user_warning_func(const char *, const char *, const int, const char *,...)
void safe_cat(FILE *, FILE *)
FILE * safe_freopen(char *, char *, FILE *)
void print_debug_stack(void)
function used to debug (can be called from dbx) BB 6.12.91
void pips_log_desc(const pips_log_t tag, const string, const string, const string, const string, const int, const string, const string, const int, const int, const string, const string, const string)
log entry with preprocessed format/arguments
void push_pips_context(char const *, char const *, int)
exception.c
void _NORETURN_ pips_internal_error_func2(const char *,...)
void _NORETURN_ pips_user_irrecoverable_error_func2(const char *,...)
void(* pips_internal_error_handler)(const char *, const char *,...)
PIPS_ERROR is a function that should be called to terminate PIPS execution when data structures are c...
void safe_symlink(const char *, const char *)
void pips_user_warning_alist(const char *, const char *, const int, const char *, va_list *)
void push_performance_spy(void)
perf_spy.c
int safe_fputc(int, FILE *, char *)
bool purge_directory(char *)
void close_log_file(void)
void pop_performance_spy(FILE *, string)
void update_list_from_array(list, gen_array_t)
Just modify the strings in a list from an array of strings.
void list_files_in_directory(gen_array_t, string, string, bool(*)(const char *))
The same as the previous safe_list_files_in_directory() but with no return code and a call to user er...
void(* reset_func_t)(void)
void append_to_warning_file(const char *, const char *, va_list *)
To be used in error handling functions.
char * strescape(const char *)
protect a string, for example for use in a system call list of non escaped characters in the macro ab...
void _NORETURN_ pips_user_irrecoverable_error_alist(const char *, const char *, const int, const char *, va_list *)
void safe_system(string)
system.c
string list_to_string(list)
Return the malloc()ed version of the concatenation of all the strings in the list.
char * pips_initial_filename(char *, char *)
The source file name access path is shortened or not depending on the property.
void safe_rewind(FILE *, char *)
int safe_fwrite(char *, int, int, FILE *, char *)
int safe_getc(FILE *, char *)
void debug(const int, const char *, const char *,...)
ARARGS0.
void pop_pips_context(char const *, char const *, int)
char * pips_basename(char *, char *)
string safe_read_nth_line(string, int)
Assumes "fn" is the name of a text file, opens it, and returns its nth line (starting with 1) in a ne...
int safe_fputs(char *, FILE *, char *)
measurement_type
Measurement type for mem_spy.c.
char * get_cwd(void)
returns the current working directory name.
pips_log_t
Warning! Do not modify this file that is automatically generated!
@ irrecoverable_error_log
bool file_exists_p(const char *)
int get_debug_level(void)
GET_DEBUG_LEVEL returns the current debugging level.
string nth_path(const char *, int)
Returns the allocated nth path from colon-separated path string.
void pips_log_func(const string, const string, const int, const pips_log_t tag, const string, const string, const string, const string, const int, const int, const string, const string, const string,...)
direct pips_log call with format and free arguments ("...")
char * safe_system_output(char *)
attempt shell substitutions to what.
char * pips_filename(char *, char *, bool)
Some OS do not define basename and dirname.
void safe_copy(char *, char *)
char * safe_readline(FILE *)
returns the allocated line read, whatever its length.
int safe_fread(char *, int, int, FILE *, char *)
FILE * safe_fopen(const char *, const char *)
bool directory_exists_p(const char *)
void list_to_array(list, gen_array_t)
args.c
int safe_system_no_abort_no_warning(string)
the command to be executed
void debug_on_function(const char *, const char *, const char *, const int)
bool function_same_string_p(const char *, const char *)
void _NORETURN_ pips_internal_error_func(const char *, const char *, const int, const char *,...)
bool file_readable_p(char *)
int safe_fgetc(FILE *, char *)
void safe_append(FILE *, char *, int, bool)
char * safe_system_substitute(char *)
returns what after variable, command and file substitutions.
void _NORETURN_ pips_user_error_func(const char *, const char *, const int, const char *,...)
void safe_link(const char *, const char *)
Create a hard link to topath.
void pips_thanks(string, string)
display pips thanks on startup, if it on a tty.
void safe_copy_line_interval(string, int, int, FILE *)
Assumes "fn" is the name of a text file, opens it, and copies the lines whose number belongs to [f....
string safe_get_line_interval(const string, int, int)
return lines f-l from file fn as a string
int safe_list_files_in_directory(gen_array_t, string, string, bool(*)(const char *))
returns a sorted arg list of files matching regular expression re in directory 'dir' and with file_na...
int safe_fflush(FILE *, char *)
void reset_hooks_is_empty(void)
check that the stack was cleaned.
void open_warning_file(const char *)
void close_warning_file(void)
int safe_display(char *)
Display a file through $PIPS_MORE (or $PAGER) if stdout is a TTY, on stdout otherwise.
string user_request(const char *,...)
void open_log_file(const string)
int the_current_debug_level
cproto-generated files
char * find_file_in_directories(const char *, const char *)
returns an allocated string pointing to the file, possibly with an additional path taken from colon-s...
string get_pips_current_pass_name(void)
Export this piece of information to customize warning functions in passes.
void reset_pips_current_computation(void)
char * safe_fgets(char *, int, FILE *, char *)
char * safe_new_tmp_file(char *)
SunOS forgets to declare this one.
void pips_debug_function(const int, const char *,...)
pips_debug is a nice macro that depends on gcc to generate the function name and to handle a variable...
void(* pips_log_handler)(const char *fmt, va_list *args)
USER_LOG is a function that should be called to log the current PIPS request, as soon as it is releva...
string(* pips_request_handler)(const char *, va_list *)
default assignment of pips_request_handler is default_user_request.
void reset_hooks_unregister(reset_func_t)
remove registered cleanup hook.
string pips_log_tag_name(pips_log_t tag)
void _NORETURN_ pips_user_error_func2(const char *,...)
FILE * check_fopen(const char *, const char *)
file.c
void start_dotting(FILE *, const char, const char *,...)
dotting.c
void(* pips_error_handler)(const char *, const char *, va_list *)
PROMPT_USER schould be implemented.
void safe_unlink(const char *)
Delete the given file.
bool create_directory(char *)
string get_pips_current_module(void)
char * pips_dirname(char *)
void pips_user_log_func(const char *,...)
string default_user_request(const char *, va_list *)
USER_REQUEST is a function that should be called to request some data from the user.
int safe_asprintf(char **, const char *,...)
int safe_fclose(FILE *, const char *)
void reset_hooks_register(reset_func_t)
reset_hooks.c
void _NORETURN_ pips_stop_func(const char *, const char *, const int, pips_log_t, int, const string,...)
expecititely declare "noreturn" functions...
double get_process_gross_heap_size(void)
void log_on_file(const char *)
_int get_debug_stack_pointer(void)
The pair get_ and set_debug_stack_pointer() should never be used except to clean up the stack after a...
void reset_hooks_call(void)
this function is expected to be called when catching an exception.
int safe_fseek(FILE *, long int, int, char *)
void pips_malloc_debug(void)
malloc_debug.c
void debug_off_function(const char *, const char *, const int)
FILE * fopen_config(const char *, const char *, const char *)
void pips_log_stop(const char *, const char *, const int, const pips_log_t tag, const int, const string,...)
quick log and stop, called on timeout this must not invoke malloc as it may still held locks if inter...
int safe_putc(int, FILE *, char *)
int safe_system_no_abort(string)
the command to be executed
void close_xml_logfile(void)
void open_xml_logfile(const char *)
char * safe_readfile(FILE *)
returns the file as an allocated string.
void set_pips_current_computation(const char *, const char *)
message.c
void pips_log_alist(const pips_log_t tag, const string, const string, const string, const string, const int, const string, const string, const int, const int, const string, const string, const string, va_list *)
log entry with unprocessed format/alist arguments
void(* pips_warning_handler)(const char *, const char *, va_list *)
default assignment of pips_warning_handler is default_user_warning.
void set_debug_level(const int)
SET_DEBUG_LEVEL is a function that sets the current debuging level to the value passed as argument.
void _NORETURN_ pips_stop_func2(pips_log_t, int, const string,...)
void _NORETURN_ pips_user_irrecoverable_error_func(const char *, const char *, const int, const char *,...)
int safe_vasprintf(char **, const char *, va_list)
void pips_user_warning_func2(const char *,...)
fallback version without a calling function name
The structure used to build lists in NewGen.