int ERR_pop_to_mark(void) {
  ERR_STATE *const state = err_get_state();
  struct err_error_st *error;

  while (state->bottom != state->top) {
    error = &state->errors[state->top];

    if ((error->flags & ERR_FLAG_MARK) != 0) {
      break;
    }

    err_clear(error);
    if (state->top == 0) {
      state->top = ERR_NUM_ERRORS - 1;
    } else {
      state->top--;
    }
  }

  if (state->bottom == state->top) {
    return 0;
  }

  error->flags &= ~ERR_FLAG_MARK;
  return 1;
}
Esempio n. 2
0
/* Runs in task threads */
void rs_threaded_load_fn(void* params, void* result, uint thread_id, uint job_id, int worker_idx)
{
    struct rs_load_job_params* lparams = (struct rs_load_job_params*)params;
    struct rs_load_job_result* lresult = (struct rs_load_job_result*)result;

    if (worker_idx >= (int)lparams->cnt)
        return;

    util_sleep(100);

    void* ptr = NULL;
    struct rs_load_data* ldata = lparams->load_items[worker_idx];
    switch (ldata->type)    {
    case RS_RESOURCE_TEXTURE:
        ptr = gfx_texture_loaddds(ldata->filepath, ldata->params.tex.first_mipidx,
            ldata->params.tex.srgb, thread_id);
        if (ptr != NULL)
            log_printf(LOG_LOAD, "(texture) \"%s\" - id: %d", ldata->filepath, GET_ID(ldata->hdl));
        break;
    case RS_RESOURCE_MODEL:
        ptr = gfx_model_load(g_rs.alloc, ldata->filepath, thread_id);
        if (ptr != NULL)
            log_printf(LOG_LOAD, "(model) \"%s\" - id: %d", ldata->filepath, GET_ID(ldata->hdl));
        break;

    case RS_RESOURCE_ANIMREEL:
        ptr = anim_load(g_rs.alloc, ldata->filepath, thread_id);
        if (ptr != NULL)
            log_printf(LOG_LOAD, "(anim-reel) \"%s\" - id:%d", ldata->filepath, GET_ID(ldata->hdl));
        break;

    case RS_RESOURCE_PHXPREFAB:
        ptr = phx_prefab_load(ldata->filepath, g_rs.alloc, thread_id);
        if (ptr != NULL)
            log_printf(LOG_LOAD, "(physics) \"%s\" - id: %d", ldata->filepath, GET_ID(ldata->hdl));
        break;

    case RS_RESOURCE_SCRIPT:
        ptr = sct_load(ldata->filepath, thread_id);
        if (ptr != NULL)
            log_printf(LOG_LOAD, "(script) \"%s\" - id: %d", ldata->filepath, GET_ID(ldata->hdl));
        break;

    case RS_RESOURCE_ANIMCTRL:
        ptr = anim_ctrl_load(g_rs.alloc, ldata->filepath, thread_id);
        if (ptr != NULL)
            log_printf(LOG_LOAD, "(anim-ctrl) \"%s\" - id: %d", ldata->filepath, GET_ID(ldata->hdl));
        break;

    default:
        ASSERT(0);
    }

    if (ptr == NULL)   {
        log_printf(LOG_WARNING, "res-mgr: loading resource '%s' failed", ldata->filepath);
        err_clear();
    }

    lresult->ptrs[worker_idx] = ptr;
}
Esempio n. 3
0
boolean Parser::skip_matched_parens() {
  istream& in = *(istream*)_inptr;
  char lparen = in.get();
  if (lparen == '(' || lparen ==  '[' || lparen == '[') {
    int status = 0;

    while (status==0) {

      /* run parser until an unexpected rparen */
      status = parser (_inptr, _infunc, _eoffunc, _errfunc, NULL, NULL,
			   _buffer, _bufsiz, &_bufptr, _token, _toksiz, 
			   &_linenum, &_pfbuf, &_pfsiz, &_pfnum);
      if (status) {
	int errid = comerr_get();
	err_clear();
	if (errid == ERR_UNEXPECTED_RPAREN && lparen == '(')
	  return true;
	else  if (errid == ERR_UNEXPECTED_RBRACKET && lparen == '[')
	  return true;
	else  if (errid == ERR_UNEXPECTED_RBRACE && lparen == '{')
	  return true;
	else
	  return false;
      } 
    }
    return true;
  } else {
    in.unget();
    return false;
  }
}
static uint32_t get_error_values(int inc, int top, const char **file, int *line,
                                 char **data, int *flags) {
  unsigned i = 0;
  ERR_STATE *state;
  struct err_error_st *error;
  uint32_t ret;

  state = err_get_state();

  if (state->bottom == state->top) {
    return 0;
  }

  if (top) {
    /* last error */
    i = state->top;
  } else {
    i = (state->bottom + 1) % ERR_NUM_ERRORS;
  }

  error = &state->errors[i];
  ret = error->packed;

  if (file != NULL && line != NULL) {
    if (error->file == NULL) {
      *file = "NA";
      *line = 0;
    } else {
      *file = error->file;
      *line = error->line;
    }
  }

  if (data != NULL) {
    if (error->data == NULL) {
      *data = "";
      if (flags != NULL) {
        *flags = 0;
      }
    } else {
      *data = error->data;
      if (flags != NULL) {
        *flags = error->flags & ERR_FLAG_PUBLIC_MASK;
      }
      error->data = NULL;
      error->flags = 0;
    }
  }

  if (inc) {
    assert(!top);
    err_clear(error);
    state->bottom = i;
  }

  return ret;
}
void ERR_clear_error(void) {
  ERR_STATE *const state = err_get_state();
  unsigned i;

  for (i = 0; i < ERR_NUM_ERRORS; i++) {
    err_clear(&state->errors[i]);
  }

  state->top = state->bottom = 0;
}
Esempio n. 6
0
void ERR_clear_error(void)
{
    int i;
    ERR_STATE *es;

    es = ERR_get_state();

    for (i = 0; i < ERR_NUM_ERRORS; i++) {
        err_clear(es, i);
    }
    es->top = es->bottom = 0;
}
Esempio n. 7
0
/*
 * err_kill - deinitialise the error handling subsystem
 *  returns: error code
 */
int
err_kill () {

	int errc;

	/* post last message */
	err_printf ("preparing to kill error subsystem ... bye!\n");

	/* clear log */
	if (errc = err_clear ()) {
		return errc;
	}

	/* all went ok */
	return ERR_NONE;
}
Esempio n. 8
0
File: err.c Progetto: 2asoft/xray-16
int ERR_pop_to_mark(void)
	{
	ERR_STATE *es;

	es=ERR_get_state();

	while(es->bottom != es->top
		&& (es->err_flags[es->top] & ERR_FLAG_MARK) == 0)
		{
		err_clear(es,es->top);
		es->top-=1;
		if (es->top == -1) es->top=ERR_NUM_ERRORS-1;
		}
		
	if (es->bottom == es->top) return 0;
	es->err_flags[es->top]&=~ERR_FLAG_MARK;
	return 1;
	}
Esempio n. 9
0
/*
 * err_init - init error subsystem
 *   filename(in): path to file to log errors to
 *  returns: ERR_IO_FILE_WRITE_FAIL, ERR_NONE
 */
int
err_init (char *filename, bool print_header) {
	
	int errc = ERR_NONE;

	/* reset file */
	FILE * f = fopen (filename, "w");

	if (f == NULL) {
		return ERR_IO_FILE_WRITE_FAIL;
	} else {
		if (print_header) {
			fprintf (f, "trace-tlk version %d.%d.%d\n", VER_MAJOR, VER_MINOR, VER_RELEASE);
			fprintf (f, "Copyright (c) 2012 Vasile Vilvoiu. All rights reserved.\n");
			fprintf (f, "Contact the author at [email protected]\n");
			fprintf (f, "======================== ERROR LOG ====================\n");
		}

		fclose (f);
	}

	/* remember file name */
	if (err_log_file_name != NULL) {
		free (err_log_file_name);
	}

	err_log_file_name = strdup (filename);

	if (err_log_file_name == NULL) {
		return ERR_OUT_OF_MEMORY;
	}

	/* clear the log */
	if (errc = err_clear()) {
		return errc;
	}

	/* all ok */
	return ERR_NONE;
}
void ERR_remove_thread_state(const CRYPTO_THREADID *tid) {
  CRYPTO_THREADID current;
  ERR_STATE *state;
  unsigned i;

  if (tid == NULL) {
    CRYPTO_THREADID_current(&current);
    tid = &current;
  }

  err_fns_check();
  state = ERRFN(release_state)(tid);
  if (state == NULL) {
    return;
  }

  for (i = 0; i < ERR_NUM_ERRORS; i++) {
    err_clear(&state->errors[i]);
  }

  OPENSSL_free(state);
}
void ERR_put_error(int library, int func, int reason, const char *file,
                   unsigned line) {
  ERR_STATE *const state = err_get_state();
  struct err_error_st *error;

  if (library == ERR_LIB_SYS && reason == 0) {
#if defined(WIN32)
    reason = GetLastError();
#else
    reason = errno;
#endif
  }

  state->top = (state->top + 1) % ERR_NUM_ERRORS;
  if (state->top == state->bottom) {
    state->bottom = (state->bottom + 1) % ERR_NUM_ERRORS;
  }

  error = &state->errors[state->top];
  err_clear(error);
  error->file = file;
  error->line = line;
  error->packed = ERR_PACK(library, func, reason);
}
Esempio n. 12
0
reshandle_t rs_load_animctrl(const char* ctrl_filepath, uint flags)
{
    reshandle_t res_hdl = INVALID_HANDLE;
    reshandle_t override_hdl = res_hdl;

    if (!g_rs.init)
        return INVALID_HANDLE;

    struct hashtable_item_chained* item = hashtable_chained_find(&g_rs.dict,
        hash_str(ctrl_filepath));
    if (item != NULL)   {
        uint idx = (uint)item->value;
        struct rs_resource* res = (struct rs_resource*)g_rs.ress.buffer + idx;
        res_hdl = res->hdl;
    }

    if (res_hdl != INVALID_HANDLE && BIT_CHECK(flags, RS_LOAD_REFRESH))    {
        /* rs_resource already loaded, but refresh flag is set, so we reload it */
        if (BIT_CHECK(g_rs.flags, RS_FLAG_BGLOADING))   {
            res_hdl = rs_animctrl_queueload(ctrl_filepath, res_hdl);
        }   else    {
            override_hdl =  res_hdl;
            res_hdl = INVALID_HANDLE;
        }
    }   else if (res_hdl != INVALID_HANDLE) {
        /* add ref count */
        struct rs_resource* ress = (struct rs_resource*)g_rs.ress.buffer;
        ress[GET_INDEX(res_hdl)].ref_cnt ++;
    }

    /* rs_resource is not loaded before, so we just have to load it for the first time */
    if (res_hdl == INVALID_HANDLE)  {
        if(BIT_CHECK(g_rs.flags, RS_FLAG_BGLOADING))  {
            res_hdl = rs_animctrl_queueload(ctrl_filepath, INVALID_HANDLE);
        }   else    {
            /* determine file extension, then load the texture based on that */
            char ext[128];
            path_getfileext(ext, ctrl_filepath);
            anim_ctrl ctrl = NULL;

            /* model files should be valid extension */
            if (str_isequal_nocase(ext, "json"))
                ctrl = anim_ctrl_load((struct allocator*)g_rs.alloc, ctrl_filepath, 0);

            if (ctrl == NULL) {
                log_printf(LOG_WARNING, "res-mgr: loading rs_resource '%s' failed:"
                    " could not load anim-ctrl", ctrl_filepath);
                err_clear();
                if (override_hdl != INVALID_HANDLE)
                    rs_remove_fromdb(override_hdl);
                return INVALID_HANDLE;
            }

            res_hdl = rs_add_resource(ctrl_filepath, ctrl, override_hdl, rs_animctrl_unload);

            /* add to hot-loading files */
            if (BIT_CHECK(g_rs.flags, RS_FLAG_HOTLOADING) && !BIT_CHECK(flags, RS_LOAD_REFRESH))
                fio_mon_reg(ctrl_filepath, rs_animctrl_reload, res_hdl, 0, 0);

            log_printf(LOG_LOAD, "(anim-ctrl) \"%s\" - id: %d", ctrl_filepath, GET_ID(res_hdl));
        }
    }

    return res_hdl;
}
Esempio n. 13
0
reshandle_t rs_load_texture(const char* tex_filepath, uint first_mipidx,
		int srgb, uint flags)
{
    reshandle_t res_hdl = INVALID_HANDLE;
    reshandle_t override_hdl = res_hdl;

    if (!g_rs.init)
        return INVALID_HANDLE;

    struct hashtable_item_chained* item = hashtable_chained_find(&g_rs.dict,
        hash_str(tex_filepath));
    if (item != NULL)   {
        uint idx = (uint)item->value;
        struct rs_resource* res = (struct rs_resource*)g_rs.ress.buffer + idx;
        res_hdl = res->hdl;
    }

    if (res_hdl != INVALID_HANDLE && BIT_CHECK(flags, RS_LOAD_REFRESH))    {
        /* rs_resource already loaded, but refresh flag is set, so we reload it */
        if (BIT_CHECK(g_rs.flags, RS_FLAG_BGLOADING))   {
            res_hdl = rs_texture_queueload(tex_filepath, first_mipidx, srgb, res_hdl);
        }   else    {
            override_hdl =  res_hdl;
            res_hdl = INVALID_HANDLE;
        }
    }   else if (res_hdl != INVALID_HANDLE) {
        /* add ref count */
        struct rs_resource* ress = (struct rs_resource*)g_rs.ress.buffer;
        ress[GET_INDEX(res_hdl)].ref_cnt ++;
    }

    /* rs_resource is not loaded before, so we just have to load it for the first time */
    if (res_hdl == INVALID_HANDLE)  {
        if(BIT_CHECK(g_rs.flags, RS_FLAG_BGLOADING))  {
            res_hdl = rs_texture_queueload(tex_filepath, first_mipidx, srgb, INVALID_HANDLE);
        }   else    {
        	/* determine file extension, then load the texture based on that */
        	char ext[128];
        	path_getfileext(ext, tex_filepath);
        	gfx_texture tex = NULL;

        	if (str_isequal_nocase(ext, "dds"))
        		tex  = gfx_texture_loaddds(tex_filepath, first_mipidx, srgb, 0);

            if (tex == NULL) {
                log_printf(LOG_WARNING, "res-mgr: loading rs_resource '%s' failed:"
                    " could not load texture", tex_filepath);
                err_clear();
                if (override_hdl != INVALID_HANDLE)
                    rs_remove_fromdb(override_hdl);
                return INVALID_HANDLE;
            }

            res_hdl = rs_add_resource(tex_filepath, tex, override_hdl, rs_texture_unload);

            /* add to hot-loading files */
            if (BIT_CHECK(g_rs.flags, RS_FLAG_HOTLOADING) && !BIT_CHECK(flags, RS_LOAD_REFRESH))   {
                fio_mon_reg(tex_filepath, rs_texture_reload, res_hdl, (uptr_t)first_mipidx,
                    (uptr_t)srgb);
            }

            log_printf(LOG_LOAD, "(texture) \"%s\" - id: %d", tex_filepath, GET_ID(res_hdl));
        }
    }

    return res_hdl;
}
Esempio n. 14
0
static unsigned long get_error_values(int inc, int top, const char **file,
                                      int *line, const char **data,
                                      int *flags)
{
    int i = 0;
    ERR_STATE *es;
    unsigned long ret;

    es = ERR_get_state();
    if (es == NULL)
        return 0;

    if (inc && top) {
        if (file)
            *file = "";
        if (line)
            *line = 0;
        if (data)
            *data = "";
        if (flags)
            *flags = 0;

        return ERR_R_INTERNAL_ERROR;
    }

    while (es->bottom != es->top) {
        if (es->err_flags[es->top] & ERR_FLAG_CLEAR) {
            err_clear(es, es->top);
            es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
            continue;
        }
        i = (es->bottom + 1) % ERR_NUM_ERRORS;
        if (es->err_flags[i] & ERR_FLAG_CLEAR) {
            es->bottom = i;
            err_clear(es, es->bottom);
            continue;
        }
        break;
    }

    if (es->bottom == es->top)
        return 0;

    if (top)
        i = es->top;            /* last error */
    else
        i = (es->bottom + 1) % ERR_NUM_ERRORS; /* first error */

    ret = es->err_buffer[i];
    if (inc) {
        es->bottom = i;
        es->err_buffer[i] = 0;
    }

    if (file != NULL && line != NULL) {
        if (es->err_file[i] == NULL) {
            *file = "NA";
            *line = 0;
        } else {
            *file = es->err_file[i];
            *line = es->err_line[i];
        }
    }

    if (data == NULL) {
        if (inc) {
            err_clear_data(es, i);
        }
    } else {
        if (es->err_data[i] == NULL) {
            *data = "";
            if (flags != NULL)
                *flags = 0;
        } else {
            *data = es->err_data[i];
            if (flags != NULL)
                *flags = es->err_data_flags[i];
        }
    }
    return ret;
}