Exemplo n.º 1
0
	void warning(bsparse_error_s id, ...) {
		if(!error_callback)
			return;
		int line, column;
		getpos(p, line, column);
		error_callback(id, geturl(), line, column, (const char**)xva_start(id));
	}
Exemplo n.º 2
0
Arquivo: state.c Projeto: 0x73/rust
struct backtrace_state *
backtrace_create_state (const char *filename, int threaded,
			backtrace_error_callback error_callback,
			void *data)
{
  struct backtrace_state init_state;
  struct backtrace_state *state;

#ifndef HAVE_SYNC_FUNCTIONS
  if (threaded)
    {
      error_callback (data, "backtrace library does not support threads", 0);
      return NULL;
    }
#endif

  memset (&init_state, 0, sizeof init_state);
  init_state.filename = filename;
  init_state.threaded = threaded;

  state = ((struct backtrace_state *)
	   backtrace_alloc (&init_state, sizeof *state, error_callback, data));
  if (state == NULL)
    return NULL;
  *state = init_state;

  return state;
}
Exemplo n.º 3
0
void
log_error(const std::string &error)
{
  last_error = error;
  
  if(error_callback)
  {
    error_callback("sdl-wrapper: " + error);
  }
}
Exemplo n.º 4
0
static void print_error(char *str, ...)
{
	char buf[1024];
	va_list ap;

	va_start(ap, str);
	vsprintf(buf, str, ap);
	va_end(ap);

	if (error_callback) error_callback(buf);
}
Exemplo n.º 5
0
static void print_error(const char *str, ...)
{
	char buf[512];
	va_list ap;

	va_start(ap, str);
	vsnprintf(buf, sizeof(buf), str, ap);
	va_end(ap);
	buf[sizeof(buf) - 1] = '\0';

	if (error_callback) error_callback(buf);
}
Exemplo n.º 6
0
JNIEXPORT jintArray JNICALL Java_nl_kb_jp2_JP2Reader_getJp2Specs
  (JNIEnv *env, jclass cls, jstring fname) {

    const char *filename = (*env)->GetStringUTFChars(env, fname, 0);
    jintArray ary = (*env)->NewIntArray(env, FIELD_LEN);

    int data[FIELD_LEN];
    int i = 0;
    for(i = 0; i < FIELD_LEN; ++i) { data[i] = 0; }
    data[0] = READ_FAILURE;

    FILE *fptr = fopen(filename, "rb");
    if(fptr != NULL && is_jp2(fptr)) {
        opj_dparameters_t parameters;
        opj_set_default_decoder_parameters(&parameters);
        struct opj_res resources = opj_init(filename, &parameters);

        opj_codestream_info_v2_t* info = get_info(&resources);
        if(resources.status == 0) {
            data[0] = READ_SUCCESS;
            data[1] = resources.image->x1;
            data[2] = resources.image->y1;
            data[3] = info->tw;
            data[4] = info->th;
            data[5] = info->tdx;
            data[6] = info->tdy;
            data[7] = info->m_default_tile_info.tccp_info[0].numresolutions;
            data[8] = resources.image->numcomps;
        }
        opj_cleanup(&resources);
    } else {
        error_callback("Cannot read file:", NULL);
        error_callback(filename, NULL);
    }
    (*env)->SetIntArrayRegion(env, ary, 0, FIELD_LEN, data);
    return ary;
}
Exemplo n.º 7
0
void *
backtrace_alloc (struct backtrace_state *state,
                 size_t size, backtrace_error_callback error_callback,
                 void *data)
{
    void *ret;
    int locked;
    struct backtrace_freelist_struct **pp;
    size_t pagesize;
    size_t asksize;
    void *page;

    ret = NULL;

    /* If we can acquire the lock, then see if there is space on the
       free list.  If we can't acquire the lock, drop straight into
       using mmap.  __sync_lock_test_and_set returns the old state of
       the lock, so we have acquired it if it returns 0.  */

    if (!state->threaded)
        locked = 1;
    else
        locked = __sync_lock_test_and_set (&state->lock_alloc, 1) == 0;

    if (locked)
    {
        for (pp = &state->freelist; *pp != NULL; pp = &(*pp)->next)
        {
            if ((*pp)->size >= size)
            {
                struct backtrace_freelist_struct *p;

                p = *pp;
                *pp = p->next;

                /* Round for alignment; we assume that no type we care about
                is more than 8 bytes.  */
                size = (size + 7) & ~ (size_t) 7;
                if (size < p->size)
                    backtrace_free_locked (state, (char *) p + size,
                                           p->size - size);

                ret = (void *) p;

                break;
            }
        }

        if (state->threaded)
            __sync_lock_release (&state->lock_alloc);
    }

    if (ret == NULL)
    {
        /* Allocate a new page.  */

        pagesize = getpagesize ();
        asksize = (size + pagesize - 1) & ~ (pagesize - 1);
        page = mmap (NULL, asksize, PROT_READ | PROT_WRITE,
                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
        if (page == NULL)
            error_callback (data, "mmap", errno);
        else
        {
            size = (size + 7) & ~ (size_t) 7;
            if (size < asksize)
                backtrace_free (state, (char *) page + size, asksize - size,
                                error_callback, data);

            ret = page;
        }
    }

    return ret;
}
Exemplo n.º 8
0
int parse_path(const char *path,char *result,struct vnode **ret_vnode,int (*error_callback) (struct dentry *dentry,const char *name), int (*verify_callback)(struct dentry *dentry ) ) { 
  char *args = (char *)path;
  struct vnode *vnode ; /*pointer to the current vnode*/
  struct mountpoint *mp ;
  char output[MAX_PATH+1];
  int err = -1;
  if( ret_vnode )
    *ret_vnode = NULL;

  if( !args ) {
    goto out;
  }

  while (isspace(*args) ) ++args;
  if (! *args) {
    goto out;
  }
  vnode = vnode_lookup(current->files_struct.cwd);
  if(! vnode) { 
    printf("Invalid CURRENT WORKING DIRECTORY %s. vnode not found in Function %s...\n",current->files_struct.cwd,__FUNCTION__);
    goto out;
  }
  trim_file_separator(args,output,sizeof(output)-1);
  {
    char *ptr = output;
    char *ptr1 ;
    char path[MAX_PATH+1], abs_path[MAX_PATH+1]="";
    struct vnode *traverse = vnode;
    struct dentry *dentry ;
    if(output[0] == FILE_SEPARATOR) {
      /*look for a mount point in the path and set the current to that of the mount point*/
      if( ( mp = get_mount(output) ) ) { 
	ptr += strlen(mp->path);
	traverse = mp->v;
      } else {
	error_callback(NULL,args);
	goto out;
      }
    }

    if(strcmp(traverse->name.abs_name,FILE_SEPARATOR_STR) ) 
      strncpy(abs_path,traverse->name.abs_name,sizeof(abs_path)-1);

    while ( ptr && *ptr ) { 
      ptr1 = strchr(ptr,FILE_SEPARATOR);
      if(ptr1)  
	*ptr1++ = 0;
      if(*ptr) { 
	if (!strcmp(ptr,".") ) {
	  /*ignore this guy or current directory references*/
	} else if (!strcmp(ptr,"..") ) { 
	  if(traverse->parent) { 
	    traverse = traverse->parent; /*shift to the parent vnode*/
	    /*overwrite the absolute path*/
	    strncpy(abs_path,traverse->name.abs_name,sizeof(abs_path)-1);
	  } else {
	    error_callback(NULL,args);
	    goto out;
	  }
	} else {
	  sprintf(path,"%s%s",FILE_SEPARATOR_STR,ptr);
	  strncat(abs_path,path,sizeof(abs_path) - strlen(abs_path) - 1);
	  /*no we try to get a dentry corresponding to the current vnode*/
	  dentry = vfs_lookup_dentry(traverse,ptr);
	  if(!dentry) {
	    error_callback(NULL,args);
	    goto out;
	  }
	  if(! verify_callback(dentry) ) {
	    error_callback(dentry,args);
	    goto out;
	  }
	  traverse = vnode_find(abs_path); /*we now get the vnode*/
	  if(! traverse) { 
	    printf("cannot chdir to %s.vnode not found...\n",args);
	    goto out;
	  }
	}
      }
      ptr = ptr1;
    }
    strncpy(result,traverse->name.abs_name,MAX_PATH);
    if(ret_vnode)
      *ret_vnode = traverse;
  }
  err = 0;
 out:
  return err;
}
Exemplo n.º 9
0
DECLARE_TEST(error, output) {
#if BUILD_ENABLE_LOG
	error_callback_fn callback_error = error_callback();
	log_callback_fn callback_log = log_callback();
	string_const_t shortmsg = string_const(STRING_CONST("Short message with prefix"));
    string_const_t longmsg = string_const(STRING_CONST("Longer message which should be output without a prefix"));

	error_set_callback(ignore_error_handler);
	log_set_callback(log_verify_callback);

    log_enable_stdout(false);
    log_warn(HASH_TEST, WARNING_SUSPICIOUS, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [suspicious]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_warn(HASH_TEST, (warning_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_prefix(false);
    log_enable_stdout(false);
	log_warn(HASH_TEST, WARNING_SYSTEM_CALL_FAIL, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [deprecated]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

	log_enable_prefix(false);
    log_enable_stdout(false);
	log_error(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_panic(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [deprecated]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_panic(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

	log_enable_prefix(false);
    log_enable_stdout(false);
	log_panic(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);
    
	error_context_push(STRING_CONST("one"), STRING_CONST("dataone"));
	error_context_push(STRING_CONST("two"), STRING_CONST("datatwo"));
	error_context_push(STRING_CONST("three"), STRING_CONST("datathree"));

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error_context(HASH_TEST, ERRORLEVEL_INFO);
    log_enable_stdout(true);

    error_context_pop();
    error_context_pop();
    error_context_pop();

	EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When one: dataone"), 0), STRING_NPOS);
	EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When two: datatwo"), 0), STRING_NPOS);
	EXPECT_SIZENE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When three: datathree"), 0), STRING_NPOS);

	log_set_callback(callback_log);
	error_set_callback(callback_error);
#endif
	return 0;
}