Example #1
0
static void global_add( HMODULE hModule )
{
    global_object *pobject;
    global_object *nobject;

    if( hModule == NULL )
        return;

    pobject = global_search( hModule );

    /* Do not add object again if it's already on the list */
    if( pobject )
        return;

    for( pobject = &first_object; pobject->next ; pobject = pobject->next );

    nobject = malloc( sizeof(global_object) );

    /* Should this be enough to fail global_add, and therefore also fail
     * dlopen?
     */
    if( !nobject )
        return;

    pobject->next = nobject;
    nobject->previous = pobject;
    nobject->hModule = hModule;
}
Example #2
0
File: dlfcn.c Project: n13l/openaaa
static void 
global_add(HMODULE module)
{
    global_object *pobject;
    global_object *nobject;

    if (module == NULL)
        return;

    pobject = global_search(module);
    /* Do not add object again if it's already on the list */
    if(pobject)
        return;

    for (pobject = &first_object; pobject->next ; pobject = pobject->next);

    nobject = malloc( sizeof(global_object) );

    if( !nobject )
        return;

    pobject->next = nobject;
    nobject->next = NULL;
    nobject->previous = pobject;
    nobject->hModule = module;
}
Example #3
0
static void edit_find_ok_callback(read_direction_t direction, Widget w, XtPointer context, XtPointer info)
{ /* "Find" is the label here */
  char *str = NULL, *buf = NULL;
  XmString s1;
  XEN proc;
  str = XmTextGetString(edit_find_text);
  if ((str) && (*str))
    { 
      clear_global_search_procedure(true);
      ss->search_expr = mus_strdup(str);
      redirect_errors_to(errors_to_find_text, NULL);
      proc = snd_catch_any(eval_str_wrapper, str, str);
      redirect_errors_to(NULL, NULL);
      if ((XEN_PROCEDURE_P(proc)) && (procedure_arity_ok(proc, 1)))
	{
	  ss->search_proc = proc;
	  ss->search_proc_loc = snd_protect(proc);
#if HAVE_SCHEME
	  if (optimization(ss) > 0)
	    ss->search_tree = mus_run_form_to_ptree_1_b(XEN_PROCEDURE_SOURCE(proc));
#endif
	  buf = (char *)calloc(PRINT_BUFFER_SIZE, sizeof(char));
	  mus_snprintf(buf, PRINT_BUFFER_SIZE, "find: %s", str);
	  set_label(edit_find_label, buf);
	  /* XmTextSetString(edit_find_text, NULL); */
	  free(buf);
	}
    }
  else
    {
      if (ss->search_expr == NULL)
	{
	  char *temp = NULL;
	  /* using global search_proc set by user */
	  buf = (char *)calloc(PRINT_BUFFER_SIZE, sizeof(char));
	  mus_snprintf(buf, PRINT_BUFFER_SIZE, "find: %s", temp = (char *)XEN_AS_STRING(ss->search_proc));
#if HAVE_SCHEME
	  if (temp) free(temp);
#endif
	  set_label(edit_find_label, buf);
	  /* XmTextSetString(edit_find_text, NULL); */
	  free(buf);
	}
    }
  if (str) XtFree(str);
  if ((XEN_PROCEDURE_P(ss->search_proc)) || (ss->search_tree))
    {
      s1 = XmStringCreateLocalized((char *)"Stop");
      XtVaSetValues(cancelB, XmNlabelString, s1, NULL);
      XmStringFree(s1);
      redirect_xen_error_to(stop_search_if_error, NULL);
      str = global_search(direction);
      redirect_xen_error_to(NULL, NULL);
      s1 = XmStringCreateLocalized((char *)"Go Away");
      XtVaSetValues(cancelB, XmNlabelString, s1, NULL);
      XmStringFree(s1);
      if ((str) && (*str)) set_label(edit_find_label, str);
    }
} 
Example #4
0
Solution *Solver::solve(){

	std::ofstream out_file (file_out.c_str());
	if (!out_file.is_open()) {
		std::cout << "Unable to open file";
	}

	init();
	// ------ print solution -------
	print_solution(current_solution);
	//print_file_solution(0, current_solution, out_file);
	// ------ print solution -------

   clock_t start, end, total;

	start = clock();


	for(unsigned int i=0;i<max_iterations;i++){

		iter_cost_time = 0;

		std::cout << "----- iteration "<< i << " ------" << std::endl;

		local_search();

		// ------ print solution -------
		std::cout << "local search  ";
		print_solution(current_solution);
		print_file_solution(i, current_solution, out_file);
		// ------ print solution -------

		global_search();

		// ------ print solution -------
		std::cout << "global search ";
		print_solution(current_solution);
		//print_file_solution(i, current_solution, out_file);
		// ------ print solution -------

		tabu_list->update_tabu();

	    total_cost_time += iter_cost_time;

		if(global_best_cost == 0)
			break;
	}

	end = clock();
	total = end - start;

    printf("\nTotal OpenCL Kernel time in milliseconds = %0.3f ms\n", (total_cost_time / 1000000.0) );
    printf("Total CPU time in milliseconds = %0.3f ms\n", total /1000.0);

	return global_best;
}
Example #5
0
/**
 * get_starts
 *
 * Create a list of starting points for EM. 
 *
 * If dataset->prob > 0, samples subsequences in the input dataset for good
 * starting points. Otherwise, e_cons is specified as the starting point.
 *
 * In order to generate starting points for EM, get_starts either performs
 * a "global search", or else uses a specified consensus string. Global search
 * always includes substring search, but several other algorithms ("branching"
 * searches) can optionally be run after substring search in order to improve
 * the starting points from which EM shall be run.
 *
 * Returns number of starting points in list.
 */
extern S_POINT *get_starts(
  DATASET *dataset,  ///< the dataset
  MODEL *model,      ///< the model
  char *e_cons,      ///< encoded consensus sequence
  int *n_starts      ///< number of starting points
)
{
  S_POINT *s_points = NULL;     // array of starting points to perform EM from
  BOOLEAN pal = dataset->pal;	/* force DNA palindromes */
  int min_w = model->min_w;     // minimum width
  int max_w = model->max_w;     // maximum width
  double min_nsites = model->min_nsites;        // min. allowed sites
  double max_nsites = model->max_nsites;        // max. allowed sites
  double sample_prob = dataset->prob; // sampling probability for subsequences

  // Generate geometric progressions over width and nsites. Make these
  // progressions identical to those used in original meme:
  int n_ns;
  int *central_ns = make_geometric_prog(min_nsites, max_nsites, 2, &n_ns);

  int n_ws;
  int *central_ws =
    make_width_prog(min_w, max_w, sqrt(2), &n_ws, pal, model->all_widths);

  // Create a matrix of S_POINTS over which global search will be performed.
  // Each S_POINT corresponds to a separate combination of n and w:
  SP_MATRIX *sp_matrix =
    create_spoint_matrix(central_ws, n_ws, central_ns, n_ns, dataset);

  // Fill in the starting points with the subsequence to use
  if (!e_cons && sample_prob != 0) { // sample subsequences (and do branching)
    // Perform "global search" in order to find starting points for EM.
    // global_search() will establish a string, from which EM will be
    // performed, for a number of S_POINT objects in the matrix (one string per
    // S_POINT). This process results in S_POINTS in the matrix being filled
    // in:
    global_search(sp_matrix, dataset, model);
  } else { // don't sample subsequences
    // Use the specified consensus sequence, "e_cons", in order to fill in
    // the sp_matrix:
    use_input_cons(sp_matrix, e_cons);
  }

  // Choose (from the matrix) which S_POINTS em will be executed from:
  s_points = choose_em_starts(sp_matrix, dataset, model, n_starts);

  // Free memory associated with the sp_matrix, as we no longer need it:
  free_sp_matrix(sp_matrix);

  return s_points;
} // get_starts
Example #6
0
static void global_rem( HMODULE hModule )
{
	global_object *pobject;
	if( hModule == NULL )
		return;
	pobject = global_search( hModule );
	if( !pobject )
		return;
	if( pobject->next )
		pobject->next->previous = pobject->previous;
	if( pobject->previous )
		pobject->previous->next = pobject->next;
	free( pobject );
}
Example #7
0
static GList*
node_symbol_list_member (IJsSymbol *obj)
{
	NodeSymbol* self = NODE_SYMBOL (obj);
	NodeSymbolPrivate *priv = NODE_SYMBOL_PRIVATE(self);

	gchar *name = get_complex_node_type (priv->node, priv->my_cx);

	if (!name)
		return NULL;
	GList *t = js_context_get_member_list (priv->my_cx, name);
	if (t)
		return t;

	IJsSymbol *sym = global_search (name);
	if (sym)
		return ijs_symbol_list_member (sym);
	return NULL;
}
Example #8
0
static gchar*
get_complex_node_type (JSNode *node, JSContext *my_cx)
{
	Type *name = js_context_get_node_type (my_cx, node);
	if (!name)
		return NULL;

	if (!name->isFuncCall)
		return name->name;

	IJsSymbol* sym = global_search (name->name);
	if (sym && ijs_symbol_get_base_type (sym) == BASE_FUNC)
	{
		GList *ret = ijs_symbol_get_func_ret_type (sym);
		if (ret)
		{
			g_assert (ret->data != NULL);
			return (gchar*)ret->data;
		}
	}
	return NULL;
}
Example #9
0
static IJsSymbol*
node_symbol_get_member (IJsSymbol *obj, const gchar * name)
{
	NodeSymbol* self = NODE_SYMBOL (obj);
	NodeSymbolPrivate *priv = NODE_SYMBOL_PRIVATE(self);

	gchar *tname = get_complex_node_type (priv->node, priv->my_cx);
	if (!tname)
		return NULL;

	if (js_context_get_member_list (priv->my_cx, tname)) //TODO:Fix mem leak
	{
			return IJS_SYMBOL (
				node_symbol_new (js_context_get_member (priv->my_cx, tname, name),
									name, priv->my_cx));
	}
	IJsSymbol *t = global_search (tname);
	if (t)
		return ijs_symbol_get_member (t, name);

	return NULL;
}
Example #10
0
void *dlopen( const char *file, int mode )
{
	HMODULE hModule;
	UINT uMode;

	current_error = NULL;

	/* Do not let Windows display the critical-error-handler message box */
	uMode = SetErrorMode( SEM_FAILCRITICALERRORS );

	if( file == 0 )
	{
		/* POSIX says that if the value of file is 0, a handle on a global
		 * symbol object must be provided. That object must be able to access
		 * all symbols from the original program file, and any objects loaded
		 * with the RTLD_GLOBAL flag.
		 * The return value from GetModuleHandle( ) allows us to retrieve
		 * symbols only from the original program file. For objects loaded with
		 * the RTLD_GLOBAL flag, we create our own list later on.
		 */
		hModule = GetModuleHandle( NULL );

		if( !hModule )
			save_err_ptr_str( file );
	}
	else
	{
		char lpFileName[MAX_PATH];
		int i;

		/* MSDN says backslashes *must* be used instead of forward slashes. */
		for( i = 0 ; i < sizeof(lpFileName)-1 ; i++ )
		{
			if( !file[i] )
				break;
			else if( file[i] == '/' )
				lpFileName[i] = '\\';
			else
				lpFileName[i] = file[i];
		}
		lpFileName[i] = '\0';

		/* POSIX says the search path is implementation-defined.
		 * LOAD_WITH_ALTERED_SEARCH_PATH is used to make it behave more closely
		 * to UNIX's search paths (start with system folders instead of current
		 * folder).
		 */
		hModule = LoadLibraryEx( (LPSTR) lpFileName, NULL, 
				LOAD_WITH_ALTERED_SEARCH_PATH );

		/* If the object was loaded with RTLD_GLOBAL, add it to list of global
		 * objects, so that its symbols may be retrieved even if the handle for
		 * the original program file is passed. POSIX says that if the same
		 * file is specified in multiple invocations, and any of them are
		 * RTLD_GLOBAL, even if any further invocations use RTLD_LOCAL, the
		 * symbols will remain global.
		 */
		if( !hModule )
			save_err_str( lpFileName );
		else if( (mode & RTLD_GLOBAL) )
			global_add( hModule );
		else if( (mode & RTLD_NOLOAD) )
		{
			global_object *pobject = global_search( hModule );

			// when RLTD_NOLOAD is set, POSIX says that the module handle
			// returned is NULL when the object was not previously loaded.
			if(!pobject)
				hModule = NULL;
		}
	}

	/* Return to previous state of the error-mode bit flags. */
	SetErrorMode( uMode );

	return (void *) hModule;
}
Example #11
0
void search_in_wc(const char *what)
{
	global_search(what, what);
}
Example #12
0
static IJsSymbol*
find (const gchar* name, IJsSymbol *sym)
{
	gchar *vname = NULL, *left = NULL;
	if (!sym)
		return NULL;
	if (!name)
		return NULL;
	int i;
	for (i = 0; i < strlen (name); i++)
	{
		if (name[i] != '.')
			continue;
		vname = g_strndup (name, i);
		left = g_strdup (name + i + 1);
		break;
	}
	if (!vname)
		vname = g_strdup (name);
	if (strlen (vname) == 0)
	{
		g_free (vname);
		g_free (left);
		return NULL;
	}
	gboolean is_func_call = *((vname + strlen (vname)) - 1) == ')';
	if (is_func_call)
		vname [strlen (vname) - 2] = '\0';
	GList *j;////TODO
	for (j = ijs_symbol_list_member (sym); j; j = g_list_next (j))
	{
		gchar *t = (gchar*)j->data;
//puts (t);
		if (strcmp (vname, t) != 0 )
			continue;
		if (!is_func_call)
		{
			if (!left)
				return ijs_symbol_get_member (sym, t);
			IJsSymbol *tjs = ijs_symbol_get_member (sym, t);
			IJsSymbol *ret = find (left, tjs);
			g_object_unref (tjs);
			return ret;
		}
		else
		{
			IJsSymbol *s = ijs_symbol_get_member (sym, t);
			if (!s)
				return NULL;
			if (ijs_symbol_get_base_type (s) != BASE_FUNC)
			{
				g_object_unref (s);
				return NULL;
			}
			GList* rets = ijs_symbol_get_func_ret_type (s);
			g_object_unref (s);
			if (rets == NULL)
			{
				return NULL;
			}
			//TODO: Fix
			IJsSymbol *ret = global_search (rets->data);
			if (!ret)
				return NULL;
			if (!left)
				return ret;
			s = find (left, ret);
			g_object_unref (ret);
			return s;
		}
	}
	return NULL;
}