* at the top of the source tree.
*/
+/*** MODULEINFO
+ <support_level>extended</support_level>
+ ***/
+
#include "asterisk.h"
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/ast_expr.h"
#define AST_API_MODULE 1
#include "asterisk/lock.h"
-#include "asterisk/strings.h"
-
-/* I included this from utils.c, so as not to have everything in that .c
- file included */
-/*!
- * core handler for dynamic strings.
- * This is not meant to be called directly, but rather through the
- * various wrapper macros
- * ast_str_set(...)
- * ast_str_append(...)
- * ast_str_set_va(...)
- * ast_str_append_va(...)
- */
-int __ast_str_helper(struct ast_str **buf, size_t max_len,
- int append, const char *fmt, va_list ap)
-{
- int res, need;
- int offset = (append && (*buf)->len) ? (*buf)->used : 0;
-
- if (max_len < 0)
- max_len = (*buf)->len; /* don't exceed the allocated space */
- /*
- * Ask vsnprintf how much space we need. Remember that vsnprintf
- * does not count the final '\0' so we must add 1.
- */
- res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap);
-
- need = res + offset + 1;
- /*
- * If there is not enough space and we are below the max length,
- * reallocate the buffer and return a message telling to retry.
- */
- if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) {
- if (max_len && max_len < need) /* truncate as needed */
- need = max_len;
- else if (max_len == 0) /* if unbounded, give more room for next time */
- need += 16 + need/4;
- if (ast_str_make_space(buf, need)) {
- return AST_DYNSTR_BUILD_FAILED;
- }
- (*buf)->str[offset] = '\0'; /* Truncate the partial write. */
-
- /* va_end() and va_start() must be done before calling
- * vsnprintf() again. */
- return AST_DYNSTR_BUILD_RETRY;
- }
- /* update space used, keep in mind the truncation */
- (*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset;
-
- return res;
-}
#ifndef DEBUG_THREADS
enum ast_lock_type {
AST_MUTEX,
AST_WRLOCK,
};
#endif
+#ifdef DEBUG_THREADLOCALS
+#define MALLOC_FAILURE_MSG \
+ ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);
+
+void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func);
+
+void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func)
+{
+ void *p;
+
+ if (!(p = calloc(num, len)))
+ MALLOC_FAILURE_MSG;
+
+ return p;
+}
+#endif
+
+#ifdef DEBUG_THREADS
+#ifdef HAVE_BKTR
void ast_store_lock_info(enum ast_lock_type type, const char *filename,
- int line_num, const char *func, const char *lock_name, void *lock_addr);
+ int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt);
void ast_store_lock_info(enum ast_lock_type type, const char *filename,
- int line_num, const char *func, const char *lock_name, void *lock_addr)
+ int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt)
+{
+ /* not a lot to do in a standalone w/o threading! */
+}
+
+void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt);
+void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt)
{
/* not a lot to do in a standalone w/o threading! */
}
-void ast_mark_lock_acquired(void);
-void ast_mark_lock_acquired(void)
+int __ast_bt_get_addresses(struct ast_bt *bt);
+int __ast_bt_get_addresses(struct ast_bt *bt)
+{
+ /* Suck it, you stupid utils directory! */
+ return 0;
+}
+char **__ast_bt_get_symbols(void **addresses, size_t num_frames);
+char **__ast_bt_get_symbols(void **addresses, size_t num_frames)
+{
+ char **foo = calloc(num_frames, sizeof(char *) + 1);
+ if (foo) {
+ int i;
+ for (i = 0; i < num_frames; i++) {
+ foo[i] = (char *) foo + sizeof(char *) * num_frames;
+ }
+ }
+ return foo;
+}
+#else
+void ast_store_lock_info(enum ast_lock_type type, const char *filename,
+ int line_num, const char *func, const char *lock_name, void *lock_addr);
+void ast_store_lock_info(enum ast_lock_type type, const char *filename,
+ int line_num, const char *func, const char *lock_name, void *lock_addr)
{
/* not a lot to do in a standalone w/o threading! */
}
{
/* not a lot to do in a standalone w/o threading! */
}
+#endif /* HAVE_BKTR */
+
+void ast_suspend_lock_info(void *lock_addr)
+{
+}
+void ast_restore_lock_info(void *lock_addr)
+{
+}
+void ast_mark_lock_acquired(void *);
+void ast_mark_lock_acquired(void *foo)
+{
+ /* not a lot to do in a standalone w/o threading! */
+}
+#endif /* DEBUG_THREADS */
+
static int global_lineno = 1;
static int global_expr_count=0;
/* Our own version of ast_log, since the expr parser uses it. */
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
+void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__((format(printf,5,6)));
void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
{
va_list vars;
va_start(vars,fmt);
-
+
printf("LOG: lev:%d file:%s line:%d func: %s ",
level, file, line, function);
vprintf(fmt, vars);
fflush(stdout);
va_end(vars);
}
-//void ast_register_file_version(const char *file, const char *version);
-//void ast_unregister_file_version(const char *file);
char *find_var(const char *varname);
void set_var(const char *varname, const char *varval);
int check_eval(char *buffer, char *error_report);
void parse_file(const char *fname);
-void ast_register_file_version(const char *file, const char *version) { }
-int ast_add_profile(const char *x, uint64_t scale) { return 0;}
-
+int ast_add_profile(const char *x, uint64_t scale) { return 0;}
int ast_atomic_fetchadd_int_slow(volatile int *p, int v)
{
int ret;
return ret;
}
-void ast_unregister_file_version(const char *file)
-{
-}
-
char *find_var(const char *varname) /* the list should be pretty short, if there's any list at all */
{
struct varz *t;
unsigned int warn_found = 0;
error_report[0] = 0;
-
+
for (cp = buffer; *cp; ++cp)
{
switch (*cp)
global_lineno);
}
break;
-
+
case '>':
case '<':
case '!':
++warn_found;
}
break;
-
+
case '|':
case '&':
case '=':
if (*cp == '$' && *(cp+1) == '{') {
int brack_lev = 1;
char *xp= cp+2;
-
+
while (*xp) {
if (*xp == '{')
brack_lev++;
else if (*xp == '}')
brack_lev--;
-
+
if (brack_lev == 0)
break;
xp++;
if (*xp == '}') {
char varname[200];
char *val;
-
+
strncpy(varname,cp+2, xp-cp-2);
varname[xp-cp-2] = 0;
cp = xp;
int c1;
char last_char= 0;
char buffer[30000]; /* I sure hope no expr gets this big! */
-
+
if (!f) {
fprintf(stderr,"Couldn't open %s for reading... need an extensions.conf file to parse!\n",fname);
exit(20);
fprintf(stderr,"Couldn't open 'expr2_log' file for writing... please fix and re-run!\n");
exit(21);
}
-
+
global_lineno = 1;
-
+
while ((c1 = fgetc(f)) != EOF) {
if (c1 == '\n')
global_lineno++;
int bufcount = 0;
int retval;
char error_report[30000];
-
+
while ((c1 = fgetc(f)) != EOF) {
if (c1 == '[')
bracklev++;
fclose(l);
printf("--- ERROR --- A newline in the middle of an expression at line %d!\n", global_lineno);
}
-
+
if (bracklev == 0)
break;
buffer[bufcount++] = c1;
printf("--- ERROR --- EOF reached in middle of an expression at line %d!\n", global_lineno);
exit(22);
}
-
+
buffer[bufcount] = 0;
/* update stats */
global_expr_tot_size += bufcount;
global_expr_count++;
if (bufcount > global_expr_max_size)
global_expr_max_size = bufcount;
-
+
retval = check_expr(buffer, error_report); /* check_expr should bump the warning counter */
if (retval != 0) {
/* print error report */
- printf("Warning(s) at line %d, expression: $[%s]; see expr2_log file for details\n",
+ printf("Warning(s) at line %d, expression: $[%s]; see expr2_log file for details\n",
global_lineno, buffer);
fprintf(l, "%s", error_report);
}
global_warn_count,
global_expr_max_size,
(global_expr_count) ? global_expr_tot_size/global_expr_count : 0);
-
+
fclose(f);
fclose(l);
}
{
int argc1;
char *eq;
-
+
if (argc < 2) {
printf("check_expr -- a program to look thru extensions.conf files for $[...] expressions,\n");
printf(" and run them thru the parser, looking for problems\n");
printf(" Note that messages about operators not being surrounded by spaces is merely to alert\n");
printf(" you to possible problems where you might be expecting those operators as part of a string.\n");
printf(" (to include operators in a string, wrap with double quotes!)\n");
-
+
exit(19);
}
global_varlist = 0;
}
/* parse command args for x=y and set varz */
-
+
parse_file(argv[1]);
return 0;
}