示例#1
0
文件: rvine.c 项目: yasserglez/dml
dml_vine_t *
dml_vine_alloc_rvine(const size_t dim)
{
    dml_vine_t *vine;

    vine = g_malloc(sizeof(dml_vine_t));
    vine->type = DML_VINE_RVINE;
    vine->dim = dim;
    vine->trees = 0;
    vine->order = g_malloc_n(dim, sizeof(size_t));
    // R-vine matrix.
    vine->matrix = g_malloc_n(dim, sizeof(size_t *));
    for (size_t i = 0; i < dim; i++) {
        vine->matrix[i] = g_malloc0_n(i + 1, sizeof(size_t));
    }
    // Lower triangular matrix with the copulas.
    vine->copulas = g_malloc_n(dim, sizeof(dml_copula_t **));
    vine->copulas[0] = NULL;
    for (size_t i = 1; i < dim; i++) {
        vine->copulas[i] = g_malloc0_n(i, sizeof(dml_copula_t *));
    }
    vine->fit = vine_fit_rvine;
    vine->ran = vine_ran_rvine;
    vine->free = vine_free_rvine;

    return vine;
}
示例#2
0
static struct scope_state *scope_state_new(const struct scope_config *config)
{
	struct scope_state *state;

	state = g_malloc0(sizeof(struct scope_state));
	state->analog_channels = g_malloc0_n(config->analog_channels,
			sizeof(struct analog_channel_state));
	state->digital_channels = g_malloc0_n(
			config->digital_channels, sizeof(gboolean));
	state->digital_pods = g_malloc0_n(config->digital_pods,
			sizeof(gboolean));

	return state;
}
示例#3
0
文件: rvine.c 项目: yasserglez/dml
static void
vine_fit_rvine(dml_vine_t *vine,
               const gsl_matrix *data,
               const dml_vine_weight_t weight,
               const dml_vine_trunc_t trunc,
               const dml_copula_indeptest_t indeptest,
               const double indeptest_level,
               const dml_copula_type_t *types,
               const size_t types_size,
               const dml_copula_select_t select,
               const gsl_rng *rng)
{
    igraph_t **trees;

    trees = g_malloc0_n(data->size2 - 1, sizeof(igraph_t *));
    fit_rvine_trees(trees, data, weight, trunc, indeptest, indeptest_level,
                    types, types_size, select, rng);
    rvine_trees_to_vine(vine, trees);

    // If the vine was truncated, free the memory of the last tree.
    if (vine->trees > 0 && vine->trees != data->size2 - 1) {
        rvine_tree_cleanup(trees[vine->trees - 1]);
    }
    for (size_t i = 0; i < data->size2 - 1; i++) {
        if (trees[i] != NULL) {
            igraph_destroy(trees[i]);
            g_free(trees[i]);
        } else {
            break;
        }
    }
    g_free(trees);
}
static UChar *
ustring_from_utf8 (const gchar *utf8, int32_t *ustrLength)
{
  UChar *dest;
  int32_t destLength, utf8Length = strlen (utf8);
  UErrorCode errorCode;

  errorCode = 0;
  u_strFromUTF8 (NULL, 0, &destLength, utf8, utf8Length, &errorCode);
  if (errorCode != U_BUFFER_OVERFLOW_ERROR)
    {
      g_warning ("can't get the number of chars in UTF-8 string: %s",
		 u_errorName (errorCode));
      return NULL;
    }

  dest = g_malloc0_n (destLength + 1, sizeof(UChar));

  errorCode = 0;
  u_strFromUTF8 (dest, destLength + 1, NULL, utf8, utf8Length, &errorCode);
  if (errorCode != U_ZERO_ERROR)
    {
      g_free (dest);
      g_warning ("can't convert UTF-8 string to ustring: %s",
		 u_errorName (errorCode));
      return NULL;
    }

  *ustrLength = destLength;
  return dest;
}
示例#5
0
文件: ui.c 项目: spk121/jahaziel
void ui_init(void)
{
    RAII_VARIABLE(GtkBuilder *, builder, gtk_builder_new(), xgtk_builder_object_unref);
    GError     *error = NULL;

    if(!gtk_builder_add_from_file(builder, UI_FILE, &error))
    {
        g_warning("%s", error->message);
        exit(1);
    }
    ui = g_malloc0_n(1, sizeof(JahUI));
    
    /* Get UI pointers from the Glade file */
    JAH_GET_WIDGET(builder, main_window, ui);
    JAH_GET_WIDGET(builder, connect_dialog, ui);
    JAH_GET_OBJECT(builder, connect_server_combobox_entry, GTK_ENTRY, ui);
    JAH_GET_OBJECT(builder, connect_username_combobox_entry, GTK_ENTRY, ui);
    JAH_GET_OBJECT(builder, statusbar, GTK_STATUSBAR, ui);
    JAH_GET_OBJECT(builder, worker_list_store, GTK_LIST_STORE, ui);
    JAH_GET_OBJECT(builder, call_client_list_view, GTK_TREE_VIEW, ui);

    gtk_builder_connect_signals(builder, NULL);

    gtk_widget_show(ui->main_window);
    
    store = create_store();
    create_view(store, ui->call_client_list_view);
    gtk_widget_show(GTK_WIDGET(ui->call_client_list_view));
}
示例#6
0
static void
nimf_settings_page_key_update_gsettings_strv (NimfSettingsPageKey *page_key,
                                              GtkTreeModel        *model)
{
  gchar       **vals;
  GtkTreeIter   iter;
  gint          i;

  vals = g_malloc0_n (1, sizeof (gchar *));

  if (gtk_tree_model_get_iter_first (model, &iter))
  {
    i = 0;
    do {
      gtk_tree_model_get (model, &iter, 0, &vals[i], -1);
      vals = g_realloc_n (vals, sizeof (gchar *), i + 2);
      vals[i + 1] = NULL;
      i++;
    } while (gtk_tree_model_iter_next (model, &iter));
  }

  g_settings_set_strv (page_key->gsettings,
                       page_key->key, (const gchar **) vals);

  g_strfreev (vals);
}
示例#7
0
gchar *dt_util_glist_to_str(const gchar *separator, GList *items)
{
  if(items == NULL) return NULL;

  const unsigned int count = g_list_length(items);
  gchar *result = NULL;

  // add the entries to an char* array
  items = g_list_first(items);
  gchar **strings = g_malloc0_n(count + 1, sizeof(gchar *));
  if(items != NULL)
  {
    int i = 0;
    do
    {
      strings[i++] = items->data;
    } while((items = g_list_next(items)) != NULL);
  }

  // join them into a single string
  result = g_strjoinv(separator, strings);

  // free the array
  g_free(strings);

  return result;
}
示例#8
0
static void
realloc_mem (UcaRingBufferPrivate *priv)
{
    if (priv->data != NULL)
        g_free (priv->data);

    priv->data = g_malloc0_n (priv->n_blocks_total, priv->block_size);
}
示例#9
0
void gui_init(dt_lib_module_t *self)
{
  /* initialize ui widgets */
  dt_lib_snapshots_t *d = (dt_lib_snapshots_t *)g_malloc0(sizeof(dt_lib_snapshots_t));
  self->data = (void *)d;

  /* initialize snapshot storages */
  d->size = 4;
  d->snapshot = (dt_lib_snapshot_t *)g_malloc0_n(d->size, sizeof(dt_lib_snapshot_t));
  d->vp_xpointer = 0.5;
  d->vp_ypointer = 0.5;
  d->vertical = TRUE;

  /* initialize ui containers */
  self->widget = gtk_vbox_new(FALSE,2);
  d->snapshots_box = gtk_vbox_new(FALSE,0);

  /* create take snapshot button */
  GtkWidget *button = gtk_button_new_with_label(_("take snapshot"));
  d->take_button = button;
  g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(_lib_snapshots_add_button_clicked_callback), self);
  g_object_set(button, "tooltip-text",
               _("take snapshot to compare with another image or the same image at another stage of development"),
               (char *)NULL);

  /*
   * initialize snapshots
   */
  char wdname[32]= {0};
  char localtmpdir[PATH_MAX]= {0};
  dt_loc_get_tmp_dir (localtmpdir, sizeof(localtmpdir));

  for (int k=0; k<d->size; k++)
  {
    /* create snapshot button */
    d->snapshot[k].button = dtgtk_togglebutton_new_with_label (wdname,NULL,CPF_STYLE_FLAT);
    g_signal_connect(G_OBJECT ( d->snapshot[k].button), "clicked",
                     G_CALLBACK (_lib_snapshots_toggled_callback),
                     self);

    /* assign snapshot number to widget */
    g_object_set_data(G_OBJECT(d->snapshot[k].button),"snapshot",GINT_TO_POINTER(k+1));

    /* setup filename for snapshot */
    snprintf(d->snapshot[k].filename, sizeof(d->snapshot[k].filename), "%s/dt_snapshot_%d.png",localtmpdir,k);

    /* add button to snapshot box */
    gtk_box_pack_start(GTK_BOX(d->snapshots_box),d->snapshot[k].button,TRUE,TRUE,0);

    /* prevent widget to show on external show all */
    gtk_widget_set_no_show_all(d->snapshot[k].button, TRUE);
  }

  /* add snapshot box and take snapshot button to widget ui*/
  gtk_box_pack_start(GTK_BOX(self->widget), d->snapshots_box,TRUE,TRUE,0);
  gtk_box_pack_start(GTK_BOX(self->widget), button, TRUE,TRUE,0);

}
示例#10
0
void *g_try_malloc0_n(size_t nmemb, size_t size)
{
    int nomem;

    if (nomem) {
        return NULL;
    }
    return g_malloc0_n(nmemb, size);
}
static gchar *
photos_search_match_manager_get_filter (PhotosBaseManager *mngr, gint flags)
{
  PhotosSearchMatchManager *self = PHOTOS_SEARCH_MATCH_MANAGER (mngr);
  GHashTable *objects;
  PhotosSearchMatch *search_match;
  const gchar *blank = "(true)";
  gchar *filter = NULL;
  gchar *ret_val = NULL;
  gchar **filters = NULL;
  gchar **terms = NULL;
  guint i;
  guint n_terms;

  if (!(flags & PHOTOS_QUERY_FLAGS_SEARCH))
    goto out;

  terms = photos_search_controller_get_terms (self->priv->srch_cntrlr);
  n_terms = g_strv_length (terms);
  if (n_terms == 0)
    goto out;

  objects = photos_base_manager_get_objects (PHOTOS_BASE_MANAGER (self));
  filters = (gchar **) g_malloc0_n (n_terms + 1, sizeof (gchar *));

  for (i = 0; terms[i] != NULL; i++)
    {
      GHashTableIter iter;
      const gchar *id;

      g_hash_table_iter_init (&iter, objects);
      while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &search_match))
        photos_search_match_set_filter_term (search_match, terms[i]);

      search_match = PHOTOS_SEARCH_MATCH (photos_base_manager_get_active_object (PHOTOS_BASE_MANAGER (self)));
      id = photos_filterable_get_id (PHOTOS_FILTERABLE (search_match));
      if (g_strcmp0 (id, PHOTOS_SEARCH_MATCH_STOCK_ALL) == 0)
        filter = photos_base_manager_get_all_filter (PHOTOS_BASE_MANAGER (self));
      else
        filter = photos_filterable_get_filter (PHOTOS_FILTERABLE (search_match));

      filters[i] = filter;
      filter = NULL;
    }

  filter = g_strjoinv (" && ", filters);
  ret_val = g_strconcat ("(", filter, ")", NULL);

 out:
  g_free (filter);
  g_strfreev (filters);
  g_strfreev (terms);
  return (ret_val == NULL) ? g_strdup (blank) : ret_val;
}
示例#12
0
/**
 * facq_window_fun:
 * @n_samples: The desired number of points in the returned vector.
 * @type: The type of window function to return, see #FacqWindowFunType for
 * available types.
 *
 * Computes @n_samples of the window function determined by @type, and creates a
 * vector containing the computed samples.
 *
 * Returns: A real vector, you must free it with g_free().
 */
gdouble *facq_window_fun(gsize n_samples,FacqWindowFunType type)
{
	gdouble *ret = NULL;
	guint i = 0;

	ret = g_malloc0_n(n_samples,sizeof(gdouble));

	for(i = 0;i < n_samples;i++)
		DISPATCHER(ret[i],i,n_samples,type);

	return ret;
}
示例#13
0
static void
nimf_libhangul_init (NimfLibhangul *hangul)
{
  g_debug (G_STRLOC ": %s", G_STRFUNC);

  gchar **hanja_keys;

  hangul->settings = g_settings_new ("org.nimf.engines.nimf-libhangul");
  hangul->method = g_settings_get_string (hangul->settings, "get-method-infos");
  hangul->is_double_consonant_rule =
    g_settings_get_boolean (hangul->settings, "double-consonant-rule");
  hangul->is_auto_reordering =
    g_settings_get_boolean (hangul->settings, "auto-reordering");
  hangul->ignore_reset_in_commit_cb =
    g_settings_get_boolean (hangul->settings, "ignore-reset-in-commit-cb");

  hanja_keys = g_settings_get_strv (hangul->settings, "hanja-keys");
  hangul->hanja_keys = nimf_key_newv ((const gchar **) hanja_keys);
  hangul->context = hangul_ic_new (hangul->method);

  hangul->id = g_strdup ("nimf-libhangul");
  hangul->preedit_string = g_strdup ("");
  hangul->preedit_attrs  = g_malloc0_n (2, sizeof (NimfPreeditAttr *));
  hangul->preedit_attrs[0] = nimf_preedit_attr_new (NIMF_PREEDIT_ATTR_UNDERLINE, 0, 0);
  hangul->preedit_attrs[1] = NULL;

  if (nimf_libhangul_hanja_table_ref_count == 0)
  {
    nimf_libhangul_hanja_table  = hanja_table_load (NULL);
    nimf_libhangul_symbol_table = hanja_table_load (MSSYMBOL_PATH);
  }

  nimf_libhangul_hanja_table_ref_count++;

  g_strfreev (hanja_keys);

  nimf_libhangul_update_transition_cb (hangul);

  g_signal_connect (hangul->settings, "changed::get-method-infos",
                    G_CALLBACK (on_changed_method), hangul);
  g_signal_connect (hangul->settings, "changed::trigger-keys",
                    G_CALLBACK (on_changed_keys), hangul);
  g_signal_connect (hangul->settings, "changed::hanja-keys",
                    G_CALLBACK (on_changed_keys), hangul);
  g_signal_connect (hangul->settings, "changed::double-consonant-rule",
                    G_CALLBACK (on_changed_double_consonant_rule), hangul);
  g_signal_connect (hangul->settings, "changed::auto-reordering",
                    G_CALLBACK (on_changed_auto_reordering), hangul);
  g_signal_connect (hangul->settings, "changed::ignore-reset-in-commit-cb",
                    G_CALLBACK (on_changed_ignore_reset_in_commit_cb), hangul);
}
示例#14
0
static char *_dt_collection_compute_datetime(const char *operator, const char *input)
{
  int len = strlen(input);
  if(len < 4) return NULL;

  struct tm tm1 = { 0 };

  // we initialise all the values of tm, depending of the operator
  // we allow unreal values like "2014:02:31" as it's just text comparison at the end
  if(strcmp(operator, ">") == 0 || strcmp(operator, "<=") == 0)
  {
    // we set all values to their maximum
    tm1.tm_mon = 11;
    tm1.tm_mday = 31;
    tm1.tm_hour = 23;
    tm1.tm_min = 59;
    tm1.tm_sec = 59;
  }

  // we read the input date, depending of his length
  if(len < 7)
  {
    if(!strptime(input, "%Y", &tm1)) return NULL;
  }
  else if(len < 10)
  {
    if(!strptime(input, "%Y:%m", &tm1)) return NULL;
  }
  else if(len < 13)
  {
    if(!strptime(input, "%Y:%m:%d", &tm1)) return NULL;
  }
  else if(len < 16)
  {
    if(!strptime(input, "%Y:%m:%d %H", &tm1)) return NULL;
  }
  else if(len < 19)
  {
    if(!strptime(input, "%Y:%m:%d %H:%M", &tm1)) return NULL;
  }
  else
  {
    if(!strptime(input, "%Y:%m:%d %H:%M:%S", &tm1)) return NULL;
  }

  // we return the created date
  char *ret = (char *)g_malloc0_n(20, sizeof(char));
  strftime(ret, 20, "%Y:%m:%d %H:%M:%S", &tm1);
  return ret;
}
示例#15
0
文件: threads.c 项目: denji/proxysql
void init_proxyipc() {
	int i;
	PROXY_TRACE();
	proxyipc.fdIn=g_malloc0_n(glovars.mysql_threads,sizeof(int));
	proxyipc.fdOut=g_malloc0_n(glovars.mysql_threads,sizeof(int));
	proxyipc.queue=g_malloc0_n(glovars.mysql_threads+1,sizeof(GAsyncQueue *));
	// create pipes
	for (i=0; i<glovars.mysql_threads; i++) {
		int fds[2];
		int rc;
		rc=pipe(fds);
		assert(rc==0);
//		if (rc==-1) {
//			perror("pipe");
//			assert(rc==0);
//		}
		proxyipc.fdIn[i]=fds[0];
		proxyipc.fdOut[i]=fds[1];
	}
	// initialize the async queue
	for (i=0; i<glovars.mysql_threads+1; i++) {
		proxyipc.queue[i]=g_async_queue_new();
	}
}
示例#16
0
/**
 * rg_ring_sized_new:
 * @element_size: (in): The size per element.
 * @reserved_size: (in): The number of elements to allocate.
 * @element_destroy: (in): Notification called when removing an element.
 *
 * Creates a new instance of #RgRing with the given number of elements.
 *
 * Returns: A new #RgRing.
 */
RgRing*
rg_ring_sized_new (guint          element_size,
                     guint          reserved_size,
                     GDestroyNotify element_destroy)
{
  RgRingImpl *ring_impl;

  ring_impl = g_slice_new0 (RgRingImpl);
  ring_impl->elt_size = element_size;
  ring_impl->len = reserved_size;
  ring_impl->data = g_malloc0_n (reserved_size, element_size);
  ring_impl->destroy = element_destroy;
  ring_impl->ref_count = 1;

  return (RgRing *)ring_impl;
}
示例#17
0
文件: logger.c 项目: moisseev/rspamd
ucl_object_t *
rspamd_log_errorbuf_export (const rspamd_logger_t *logger)
{
	struct rspamd_logger_error_elt *cpy, *cur;
	ucl_object_t *top = ucl_object_typed_new (UCL_ARRAY);
	guint i;

	if (logger->errlog == NULL) {
		return top;
	}

	cpy = g_malloc0_n (logger->errlog->max_elts,
			sizeof (*cpy) + logger->errlog->elt_len);
	memcpy (cpy, logger->errlog->elts, logger->errlog->max_elts *
			(sizeof (*cpy) + logger->errlog->elt_len));

	for (i = 0; i < logger->errlog->max_elts; i ++) {
		cur = (struct rspamd_logger_error_elt *)((guchar *)cpy +
				i * ((sizeof (*cpy) + logger->errlog->elt_len)));
		if (cur->completed) {
			ucl_object_t *obj = ucl_object_typed_new (UCL_OBJECT);

			ucl_object_insert_key (obj, ucl_object_fromdouble (cur->ts),
					"ts", 0, false);
			ucl_object_insert_key (obj, ucl_object_fromint (cur->pid),
					"pid", 0, false);
			ucl_object_insert_key (obj,
					ucl_object_fromstring (g_quark_to_string (cur->ptype)),
					"type", 0, false);
			ucl_object_insert_key (obj, ucl_object_fromstring (cur->id),
					"id", 0, false);
			ucl_object_insert_key (obj, ucl_object_fromstring (cur->module),
					"module", 0, false);
			ucl_object_insert_key (obj, ucl_object_fromstring (cur->message),
					"message", 0, false);

			ucl_array_append (top, obj);
		}
	}

	ucl_object_array_sort (top, rspamd_log_errlog_cmp);
	g_free (cpy);

	return top;
}
示例#18
0
gchar *dt_loc_get_home_dir(const gchar *user)
{
  if(user == NULL || g_strcmp0(user, g_get_user_name()) == 0)
  {
    const char *home_dir = g_getenv("HOME");
    return g_strdup((home_dir != NULL) ? home_dir : g_get_home_dir());
  }

#if defined HAVE_GETPWNAM_R
  /* if the given username is not the same as the current one, we try
   * to retrieve the pw dir from the password file entry */
  struct passwd pwd;
  struct passwd *result;
#ifdef _SC_GETPW_R_SIZE_MAX
  int bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
  if(bufsize < 0)
  {
    bufsize = 4096;
  }
#else
  int bufsize = 4096;
#endif

  gchar *buffer = g_malloc0_n(bufsize, sizeof(gchar));
  if(buffer == NULL)
  {
    return NULL;
  }

  getpwnam_r(user, &pwd, buffer, bufsize, &result);
  if(result == NULL)
  {
    g_free(buffer);
    return NULL;
  }

  gchar *dir = g_strdup(pwd.pw_dir);
  g_free(buffer);

  return dir;
#else
  return NULL;
#endif
}
示例#19
0
/**
 * Builds the tooltip text for a GtkEntry. Uses the same datatype as
 * used for initializing the auto completion table above.
 *
 * @return g_malloc()'ed string. Must be free'd by the caller.
 */
gchar *
dt_gtkentry_build_completion_tooltip_text (const gchar *header,
    const dt_gtkentry_completion_spec *compl_list)
{
  const unsigned int tooltip_len = 1024;
  gchar *tt = g_malloc0_n(tooltip_len, sizeof(gchar));
  gsize tt_size = sizeof(gchar)*tooltip_len;
  dt_gtkentry_completion_spec const *p;

  g_strlcat(tt, header, tt_size);
  g_strlcat(tt, "\n", tt_size);

  for(p = compl_list; p->description != NULL; p++)
  {
    g_strlcat(tt, p->description, tt_size);
    g_strlcat(tt, "\n", tt_size);
  }

  return tt;
}
示例#20
0
文件: util.c 项目: vifino/dwb
/* util_keyval_to_char (guint keyval)      return: char * (alloc) {{{*/
char *
util_keyval_to_char(guint keyval, gboolean ignore_whitespace) 
{
    char *key = NULL;
    guint32 unichar;
    int length;
    if ( (unichar = gdk_keyval_to_unicode(keyval)) ) 
    {
        if (ignore_whitespace && !g_unichar_isgraph(unichar))
            return NULL;
        key = g_malloc0_n(6, sizeof(char));
        if ( key && (length = g_unichar_to_utf8(unichar, key))) 
        {
            memset(&key[length], '\0', 6-length); 
            return key;
        }
        else 
            g_free(key);
    }
    return NULL;
}/*}}}*/
示例#21
0
文件: dvine.c 项目: yasserglez/dml
dml_vine_t *
dml_vine_alloc_dvine(const size_t dim)
{
    dml_vine_t *vine;

    vine = g_malloc(sizeof(dml_vine_t));
    vine->type = DML_VINE_DVINE;
    vine->dim = dim;
    vine->trees = 0;
    vine->order = g_malloc_n(dim, sizeof(size_t));
    vine->matrix = NULL; // Not used. D-vine represented by the order of the variables.
    // Upper triangular matrix with the parameters of the copulas.
    vine->copulas = g_malloc_n(dim - 1, sizeof(dml_copula_t **));
    for (size_t i = 0; i < dim - 1; i++) {
        vine->copulas[i] = g_malloc0_n(dim - 1 - i, sizeof(dml_copula_t *));
    }
    vine->fit = vine_fit_dvine;
    vine->ran = vine_ran_dvine;
    vine->free = vine_free_dvine;

    return vine;
}
示例#22
0
GStrv
photos_utils_convert_paths_to_uris (const gchar *const *paths)
{
  GStrv uris = NULL;
  guint i;
  guint n_paths;

  if (paths == NULL)
    goto out;

  n_paths = g_strv_length ((GStrv) paths);
  uris = (GStrv) g_malloc0_n (n_paths + 1, sizeof (gchar *));

  for (i = 0; paths[i] != NULL; i++)
    {
      g_autofree gchar *uri = NULL;

      uri = photos_utils_convert_path_to_uri (paths[i]);
      uris[i] = g_steal_pointer (&uri);
    }

 out:
  return uris;
}
示例#23
0
void process(struct dt_iop_module_t *self, dt_dev_pixelpipe_iop_t *piece, const void *const ivoid,
             void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
{
  dt_iop_watermark_data_t *data = (dt_iop_watermark_data_t *)piece->data;
  float *in = (float *)ivoid;
  float *out = (float *)ovoid;
  const int ch = piece->colors;
  double angle = (M_PI / 180) * -data->rotate;

  /* Load svg if not loaded */
  gchar *svgdoc = _watermark_get_svgdoc(self, data, &piece->pipe->image);
  if(!svgdoc)
  {
    memcpy(ovoid, ivoid, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height);
    return;
  }

  /* create the rsvghandle from parsed svg data */
  GError *error = NULL;
  RsvgHandle *svg = rsvg_handle_new_from_data((const guint8 *)svgdoc, strlen(svgdoc), &error);
  g_free(svgdoc);
  if(!svg || error)
  {
    memcpy(ovoid, ivoid, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height);
    return;
  }

  /* setup stride for performance */
  int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, roi_out->width);

  /* create cairo memory surface */
  guint8 *image = (guint8 *)g_malloc0_n(roi_out->height, stride);
  cairo_surface_t *surface = cairo_image_surface_create_for_data(image, CAIRO_FORMAT_ARGB32, roi_out->width,
                                                                 roi_out->height, stride);
  if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS)
  {
    //   fprintf(stderr,"Cairo surface error: %s\n",cairo_status_to_string(cairo_surface_status(surface)));
    g_free(image);
    memcpy(ovoid, ivoid, (size_t)sizeof(float) * ch * roi_out->width * roi_out->height);
    return;
  }

  /* create cairo context and setup transformation/scale */
  cairo_t *cr = cairo_create(surface);

  /* get the dimension of svg */
  RsvgDimensionData dimension;
  rsvg_handle_get_dimensions(svg, &dimension);

  //  width/height of current (possibly cropped) image
  const float iw = piece->buf_in.width;
  const float ih = piece->buf_in.height;
  const float uscale = data->scale / 100.0; // user scale, from GUI in percent

  // wbase, hbase are the base width and height, this is the multiplicator used for the offset computing
  // scale is the scale of the watermark itself and is used only to render it.

  float wbase, hbase, scale;

  if(data->sizeto == DT_SCALE_IMAGE)
  {
    // in image mode, the wbase and hbase are just the image width and height
    wbase = iw;
    hbase = ih;
    if(dimension.width > dimension.height)
      scale = (iw * roi_out->scale) / dimension.width;
    else
      scale = (ih * roi_out->scale) / dimension.height;
  }
  else
  {
    // in larger/smaller side mode, set wbase and hbase to the largest or smallest side of the image
    float larger;
    if(dimension.width > dimension.height)
      larger = (float)dimension.width;
    else
      larger = (float)dimension.height;

    if(iw > ih)
    {
      wbase = hbase = (data->sizeto == DT_SCALE_LARGER_BORDER) ? iw : ih;
      scale = (data->sizeto == DT_SCALE_LARGER_BORDER) ? (iw / larger) : (ih / larger);
    }
    else
    {
      wbase = hbase = (data->sizeto == DT_SCALE_SMALLER_BORDER) ? iw : ih;
      scale = (data->sizeto == DT_SCALE_SMALLER_BORDER) ? (iw / larger) : (ih / larger);
    }
    scale *= roi_out->scale;
  }

  scale *= uscale;

  // compute the width and height of the SVG object in image dimension. This is only used to properly
  // layout the watermark based on the alignment.

  float svg_width, svg_height;

  if(dimension.width > dimension.height)
  {
    if(data->sizeto == DT_SCALE_IMAGE || (iw > ih && data->sizeto == DT_SCALE_LARGER_BORDER)
       || (iw < ih && data->sizeto == DT_SCALE_SMALLER_BORDER))
    {
      svg_width = iw * uscale;
      svg_height = dimension.height * (svg_width / dimension.width);
    }
    else
    {
      svg_width = ih * uscale;
      svg_height = dimension.height * (svg_width / dimension.width);
    }
  }
  else
  {
    if(data->sizeto == DT_SCALE_IMAGE || (ih > iw && data->sizeto == DT_SCALE_LARGER_BORDER)
       || (ih < iw && data->sizeto == DT_SCALE_SMALLER_BORDER))
    {
      svg_height = ih * uscale;
      svg_width = dimension.width * (svg_height / dimension.height);
    }
    else
    {
      svg_height = iw * uscale;
      svg_width = dimension.width * (svg_height / dimension.height);
    }
  }

  // compute bounding box of rotated watermark
  float bb_width, bb_height;
  bb_width = fabs(svg_width * cos(angle)) + fabs(svg_height * sin(angle));
  bb_height = fabs(svg_width * sin(angle)) + fabs(svg_height * cos(angle));
  float bX = bb_width / 2.0 - svg_width / 2.0;
  float bY = bb_height / 2.0 - svg_height / 2.0;

  // compute translation for the given alignment in image dimension

  float ty = 0, tx = 0;
  if(data->alignment >= 0 && data->alignment < 3) // Align to verttop
    ty = bY;
  else if(data->alignment >= 3 && data->alignment < 6) // Align to vertcenter
    ty = (ih / 2.0) - (svg_height / 2.0);
  else if(data->alignment >= 6 && data->alignment < 9) // Align to vertbottom
    ty = ih - svg_height - bY;

  if(data->alignment == 0 || data->alignment == 3 || data->alignment == 6)
    tx = bX;
  else if(data->alignment == 1 || data->alignment == 4 || data->alignment == 7)
    tx = (iw / 2.0) - (svg_width / 2.0);
  else if(data->alignment == 2 || data->alignment == 5 || data->alignment == 8)
    tx = iw - svg_width - bX;

  // translate to position
  cairo_translate(cr, -roi_in->x, -roi_in->y);

  // add translation for the given value in GUI (xoffset,yoffset)
  tx += data->xoffset * wbase;
  ty += data->yoffset * hbase;

  cairo_translate(cr, tx * roi_out->scale, ty * roi_out->scale);

  // compute the center of the svg to rotate from the center
  float cX = svg_width / 2.0 * roi_out->scale;
  float cY = svg_height / 2.0 * roi_out->scale;

  cairo_translate(cr, cX, cY);
  cairo_rotate(cr, angle);
  cairo_translate(cr, -cX, -cY);

  // now set proper scale for the watermark itself
  cairo_scale(cr, scale, scale);

  /* render svg into surface*/
  dt_pthread_mutex_lock(&darktable.plugin_threadsafe);
  rsvg_handle_render_cairo(svg, cr);
  dt_pthread_mutex_unlock(&darktable.plugin_threadsafe);

  cairo_destroy(cr);

  /* ensure that all operations on surface finishing up */
  cairo_surface_flush(surface);

  /* render surface on output */
  guint8 *sd = image;
  float opacity = data->opacity / 100.0;
  /*
  #ifdef _OPENMP
    #pragma omp parallel for default(none) shared(in, out,sd,opacity) schedule(static)
  #endif
  */
  for(int j = 0; j < roi_out->height; j++)
    for(int i = 0; i < roi_out->width; i++)
    {
      float alpha = (sd[3] / 255.0) * opacity;
      /* svg uses a premultiplied alpha, so only use opacity for the blending */
      out[0] = ((1.0 - alpha) * in[0]) + (opacity * (sd[2] / 255.0));
      out[1] = ((1.0 - alpha) * in[1]) + (opacity * (sd[1] / 255.0));
      out[2] = ((1.0 - alpha) * in[2]) + (opacity * (sd[0] / 255.0));
      out[3] = in[3];

      out += ch;
      in += ch;
      sd += 4;
    }


  /* clean up */
  cairo_surface_destroy(surface);
  g_object_unref(svg);
  g_free(image);
}
示例#24
0
文件: rvine.c 项目: yasserglez/dml
static void
vine_ran_rvine(const dml_vine_t *vine, const gsl_rng *rng, gsl_matrix *data)
{
    size_t n, m;
    gsl_vector ***vdirect, ***vindirect;
    gsl_vector *z1 = NULL, *z2 = NULL, *hinv = NULL; // Initialized to avoid GCC warnings.
    size_t **M;

    n = vine->dim;
    m = data->size1;
    vdirect = g_malloc_n(n, sizeof(gsl_vector **));
    vindirect = g_malloc_n(n, sizeof(gsl_vector **));
    for (size_t i = 0; i < n; i++) {
        vdirect[i] = g_malloc0_n(n, sizeof(gsl_vector *));
        vindirect[i] = g_malloc0_n(n, sizeof(gsl_vector *));
    }
    M = g_malloc_n(n, sizeof(size_t *));
    for (size_t i = 0; i < n; i++) {
        M[i] = g_malloc0_n(i + 1, sizeof(size_t));
    }

    // Line 4.
    for (size_t k = 0; k < n; k++) {
        vdirect[n - 1][k] = gsl_vector_alloc(m);
        for (size_t i = 0; i < m; i++) {
            gsl_vector_set(vdirect[n - 1][k], i, gsl_rng_uniform(rng));
        }
    }
    // Line 5.
    for (size_t k = 0; k < n; k++) {
        M[k][k] = vine->matrix[k][k];
        M[n - 1][k] = vine->matrix[n - 1][k];
        for (size_t i = n - 2; i > k; i--) {
            if (vine->matrix[i][k] > M[i + 1][k]) {
                M[i][k] = vine->matrix[i][k];
            } else {
                M[i][k] = M[i + 1][k];
            }
        }
    }
    // Line 6.
    gsl_matrix_set_col(data, vine->order[0], vdirect[n - 1][n - 1]);

    // for loop in line 7.
    for (size_t k = n - 2; /* See break call. */; k--) {
        // for loop in line 8.
        for (size_t i = k + 1; i < n; i++) {
            // Line 14.
            if (vine->matrix[i][k] != 0
                    && dml_copula_type(vine->copulas[i][k]) != DML_COPULA_INDEP) {
                if (M[i][k] == vine->matrix[i][k]) {
                    z2 = vdirect[i][n - M[i][k]];
                } else {
                    z2 = vindirect[i][n - M[i][k]];
                }
                hinv = gsl_vector_alloc(m);
                dml_copula_hinv(vine->copulas[i][k], vdirect[n - 1][k], z2, hinv);
                gsl_vector_free(vdirect[n - 1][k]);
                vdirect[n - 1][k] = hinv;
            }
        }
        // Line 16.
        gsl_matrix_set_col(data, vine->order[n - k - 1], vdirect[n - 1][k]);

        if (k == 0) break; // Avoid problems decrementing the unsigned k if k is 0.

        // for loop in line 17.
        for (size_t i = n - 1; i > k; i--) {
            // Line 18.
            z1 = vdirect[i][k];
            // Line 19.
            if (vdirect[i - 1][k] == NULL) {
                vdirect[i - 1][k] = gsl_vector_alloc(m);
            }
            if (vine->matrix[i][k] == 0
                    || dml_copula_type(vine->copulas[i][k]) == DML_COPULA_INDEP) {
                // Vine truncated or independence copula.
                gsl_vector_memcpy(vdirect[i - 1][k], z1);
            } else {
                dml_copula_h(vine->copulas[i][k], z1, z2, vdirect[i - 1][k]);
            }
            if (vindirect[i - 1][k] == NULL) {
                vindirect[i - 1][k] = gsl_vector_alloc(m);
            }
            gsl_vector_memcpy(vindirect[i - 1][k], vdirect[i - 1][k]);
        }
    }

    // Freeing memory.
    for (size_t i = 0; i < n; i++) {
        g_free(M[i]);
    }
    g_free(M);
    for (size_t i = 0; i < n; i++) {
        for (size_t j = 0; j < n; j++) {
            if (vdirect[i][j] != NULL) {
                gsl_vector_free(vdirect[i][j]);
            }
            if (vindirect[i][j] != NULL) {
                gsl_vector_free(vindirect[i][j]);
            }
        }
        g_free(vdirect[i]);
        g_free(vindirect[i]);
    }
    g_free(vdirect);
    g_free(vindirect);
}
示例#25
0
void *g_malloc0(size_t size)
{
    return g_malloc0_n(1, size);
}
示例#26
0
static void
mem_overflow (void)
{
  gsize a = G_MAXSIZE / 10 + 10;
  gsize b = 10;
  gpointer p, q;
  typedef char X[10];

#define CHECK_PASS(P)	p = (P); g_assert (p == NULL);
#define CHECK_FAIL(P)	p = (P); g_assert (p != NULL);

  CHECK_PASS (g_try_malloc_n (a, a));
  CHECK_PASS (g_try_malloc_n (a, b));
  CHECK_PASS (g_try_malloc_n (b, a));
  CHECK_FAIL (g_try_malloc_n (b, b));

  CHECK_PASS (g_try_malloc0_n (a, a));
  CHECK_PASS (g_try_malloc0_n (a, b));
  CHECK_PASS (g_try_malloc0_n (b, a));
  CHECK_FAIL (g_try_malloc0_n (b, b));

  q = g_malloc (1);
  CHECK_PASS (g_try_realloc_n (q, a, a));
  CHECK_PASS (g_try_realloc_n (q, a, b));
  CHECK_PASS (g_try_realloc_n (q, b, a));
  CHECK_FAIL (g_try_realloc_n (q, b, b));
  free (p);

  CHECK_PASS (g_try_new (X, a));
  CHECK_FAIL (g_try_new (X, b));

  CHECK_PASS (g_try_new0 (X, a));
  CHECK_FAIL (g_try_new0 (X, b));

  q = g_try_malloc (1);
  CHECK_PASS (g_try_renew (X, q, a));
  CHECK_FAIL (g_try_renew (X, q, b));
  free (p);

#undef CHECK_FAIL
#undef CHECK_PASS

#define CHECK_FAIL(P)	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) { p = (P); exit (0); } g_test_trap_assert_failed();
#define CHECK_PASS(P)	if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR)) { p = (P); exit (0); } g_test_trap_assert_passed();

  CHECK_FAIL (g_malloc_n (a, a));
  CHECK_FAIL (g_malloc_n (a, b));
  CHECK_FAIL (g_malloc_n (b, a));
  CHECK_PASS (g_malloc_n (b, b));

  CHECK_FAIL (g_malloc0_n (a, a));
  CHECK_FAIL (g_malloc0_n (a, b));
  CHECK_FAIL (g_malloc0_n (b, a));
  CHECK_PASS (g_malloc0_n (b, b));

  q = g_malloc (1);
  CHECK_FAIL (g_realloc_n (q, a, a));
  CHECK_FAIL (g_realloc_n (q, a, b));
  CHECK_FAIL (g_realloc_n (q, b, a));
  CHECK_PASS (g_realloc_n (q, b, b));
  free (q);

  CHECK_FAIL (g_new (X, a));
  CHECK_PASS (g_new (X, b));

  CHECK_FAIL (g_new0 (X, a));
  CHECK_PASS (g_new0 (X, b));

  q = g_malloc (1);
  CHECK_FAIL (g_renew (X, q, a));
  CHECK_PASS (g_renew (X, q, b));
  free (q);
}
示例#27
0
/**
 * facq_stream_data_to_socket:
 * @stmd: A #FacqStreamData object.
 * @socket: A connected #GSocket.
 * @err: A #GError, it will be set in case of error if not %NULL.
 *
 * Sends the information contained in the #FacqStreamData (minus bps), @stmd, to the
 * receiver at the other side of the socket connection. It can block or not
 * depending on the "blocking" property of the #GSocket, @socket.
 *
 * Returns: %TRUE if successful, %FALSE in other case.
 */
gboolean facq_stream_data_to_socket(const FacqStreamData *stmd,GSocket *socket,GError **err)
{
	gdouble period = 0;
	guint32 n_channels = 0, i = 0;
	guint32 *channels = NULL, *units = NULL;
	gssize ret = -1;
	GError *local_err = NULL;
	gdouble *tmp = NULL;

	/* period */
	period = GDOUBLE_TO_BE(stmd->period);
	ret = facq_net_send(socket,(gchar *)&period,sizeof(gdouble),3,&local_err);
	if(ret != sizeof(gdouble) || local_err)
		goto error;

	/* n_channels */
	n_channels = GUINT32_TO_BE(facq_stream_data_get_n_channels(stmd));
	ret = facq_net_send(socket,(gchar *)&n_channels,sizeof(guint32),3,&local_err);
	if(ret != sizeof(guint32) || local_err)
		goto error;

	/* chanlist */
	channels = facq_chanlist_to_comedi_chanlist(stmd->chanlist,NULL);
	for(i = 0;i < stmd->n_channels;i++){
		channels[i] = GUINT32_TO_BE(channels[i]);
	}
	ret = facq_net_send(socket,(gchar *)channels,stmd->n_channels*sizeof(guint32),3,&local_err);
	if(ret != ( sizeof(guint32)*stmd->n_channels) || local_err)
		goto error;
	g_free(channels);

	/* units */
	units = g_malloc0_n(stmd->n_channels,sizeof(guint32));
	for(i = 0;i < stmd->n_channels;i++){
		units[i] = GUINT32_TO_BE(stmd->units[i]);
	}
	ret = facq_net_send(socket,(gchar *)units,sizeof(guint32)*stmd->n_channels,3,&local_err);
	if(ret != (sizeof(guint32)*stmd->n_channels) || local_err)
		goto error;
	g_free(units);

	/* max and min*/
	tmp = g_malloc0_n(stmd->n_channels,sizeof(gdouble));
	for(i = 0;i < stmd->n_channels;i++){
		tmp[i] = GDOUBLE_TO_BE(stmd->max[i]);
	}
	ret = facq_net_send(socket,(gchar *)&tmp,sizeof(gdouble)*stmd->n_channels,3,&local_err);
	if(ret != (sizeof(gdouble)*stmd->n_channels) || local_err)
		goto error;
	for(i = 0;i < stmd->n_channels;i++){
		tmp[i] = GDOUBLE_TO_BE(stmd->min[i]);
	}
	ret = facq_net_send(socket,(gchar *)&tmp,sizeof(gdouble)*stmd->n_channels,3,&local_err);
	if(ret != (sizeof(gdouble)*stmd->n_channels) || local_err)
		goto error;
	g_free(tmp);

	return TRUE;

	error:
	if(units)
		g_free(units);
	if(tmp)
		g_free(tmp);
	if(channels)
		g_free(channels);
	if(local_err)
		g_propagate_error(err,local_err);
	else
		if(err != NULL)
			g_set_error_literal(err,G_IO_ERROR,
						G_IO_ERROR_FAILED,"Unknown error sending the data");
	return FALSE;
}
static void
photos_search_type_manager_init (PhotosSearchTypeManager *self)
{
  PhotosSearchType *search_type;
  gchar *item_filter;
  gchar *all_filter;
  gchar *blacklisted_mime_types_filter;
  gchar *col_filter;
  gchar **strv;
  guint i;
  guint n_elements;

  n_elements = G_N_ELEMENTS (BLACKLISTED_MIME_TYPES);
  strv = (gchar **) g_malloc0_n (n_elements + 1, sizeof (gchar *));
  for (i = 0; i < n_elements; i++)
    strv[i] = g_strdup_printf ("nie:mimeType(?urn) != '%s'", BLACKLISTED_MIME_TYPES[i]);

  blacklisted_mime_types_filter = g_strjoinv (" && ", strv);

  item_filter = g_strdup_printf ("(fn:contains (?type, 'nmm#Photo') && %s)", blacklisted_mime_types_filter);
  col_filter = g_strdup_printf ("(fn:contains (?type, 'nfo#DataContainer')"
                                " && ?count > 0"
                                " && (fn:starts-with (nao:identifier (?urn), '%s')"
                                "     || (?urn = nfo:image-category-screenshot)))",
                                PHOTOS_QUERY_COLLECTIONS_IDENTIFIER);
  all_filter = g_strdup_printf ("(%s || %s)", col_filter, item_filter);

  search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_ALL,
                                             _("All"),
                                             "?urn a rdfs:Resource. "
                                             "OPTIONAL {?item a nmm:Photo; nie:isPartOf ?urn}",
                                             all_filter);
  photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type));
  g_object_unref (search_type);

  search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_COLLECTIONS,
                                             _("Albums"),
                                             "?urn a nfo:DataContainer. "
                                             "?item a nmm:Photo; nie:isPartOf ?urn.",
                                             col_filter);
  photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type));
  g_object_unref (search_type);

  search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_FAVORITES,
                                             _("Favorites"),
                                             "?urn a nmm:Photo; nao:hasTag nao:predefined-tag-favorite. ",
                                             blacklisted_mime_types_filter);
  photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type));
  g_object_unref (search_type);

  search_type = photos_search_type_new_full (PHOTOS_SEARCH_TYPE_STOCK_PHOTOS,
                                             _("Photos"),
                                             "?urn a nmm:Photo",
                                             blacklisted_mime_types_filter);
  photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (search_type));
  g_object_unref (search_type);

  photos_base_manager_set_active_object_by_id (PHOTOS_BASE_MANAGER (self), PHOTOS_SEARCH_TYPE_STOCK_ALL);

  g_free (item_filter);
  g_free (all_filter);
  g_free (blacklisted_mime_types_filter);
  g_free (col_filter);
  g_strfreev (strv);
}
示例#29
0
static void hev_scgi_handler_cgi_handle(HevSCGIHandler *handler, GObject *scgi_task)
{
	HevSCGIHandlerCGI *self = HEV_SCGI_HANDLER_CGI(handler);
	HevSCGIHandlerCGIPrivate *priv = HEV_SCGI_HANDLER_CGI_GET_PRIVATE(self);

	HevSCGIHandlerCGITaskData *task_data = NULL;
	gchar *str = NULL, **argv = NULL, *workdir = NULL;
	GPid pid = 0;
	GError *error = NULL;
	GObject *connection = NULL;
	GSocket *socket = NULL;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	task_data = g_slice_new0(HevSCGIHandlerCGITaskData);
	if(!task_data)
	{
		g_critical("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);
		return;
	}

	connection = hev_scgi_task_get_socket_connection(HEV_SCGI_TASK(scgi_task));
	socket = g_socket_connection_get_socket(G_SOCKET_CONNECTION(connection));
	task_data->fd = g_socket_get_fd(socket);

	task_data->scgi_task = scgi_task;
	task_data->scgi_request = hev_scgi_task_get_request(HEV_SCGI_TASK(scgi_task));
	task_data->scgi_response = hev_scgi_task_get_response(HEV_SCGI_TASK(scgi_task));
	task_data->req_hash_table =
		hev_scgi_request_get_header_hash_table(HEV_SCGI_REQUEST(task_data->scgi_request));

	task_data->envp =
		g_malloc0_n(g_hash_table_size(task_data->req_hash_table)+1, sizeof(gchar *));
	g_hash_table_foreach(task_data->req_hash_table, req_hash_table_foreach_handler, task_data);

	/* Script file and Work dir */
	str = g_hash_table_lookup(task_data->req_hash_table, "SCRIPT_FILE");
	argv = g_malloc0_n(2, sizeof(gchar *));
	if(str)
	{
		argv[0] = g_strdup(str);
		workdir = g_path_get_dirname(str);
	}
	else
	{
		argv[0] = g_key_file_get_string(priv->config, "Module", "CGIBinPath", NULL);
		workdir = g_key_file_get_string(priv->config, "Module", "WorkDir", NULL);

		if(NULL == argv[0])
		  argv[0] = g_strdup(HEV_SCGI_HANDLER_CGI_BIN_PATH);
		if(NULL == workdir)
		  workdir = g_strdup(HEV_SCGI_HANDLER_CGI_WORK_DIR);
	}

#ifdef G_OS_UNIX
	/* User and Group */
	str = g_hash_table_lookup(task_data->req_hash_table, "_USER");
	if(str)
	  task_data->user = g_strdup(str);
	else
	  task_data->user = g_key_file_get_string(priv->config, "Module", "User", NULL);

	str = g_hash_table_lookup(task_data->req_hash_table, "_GROUP");
	if(str)
	  task_data->group = g_strdup(str);
	else
	  task_data->group = g_key_file_get_string(priv->config, "Module", "Group", NULL);
#endif /* G_OS_UNIX */

	if(g_spawn_async(workdir, argv, task_data->envp, G_SPAWN_DO_NOT_REAP_CHILD,
					hev_scgi_handler_spawn_child_setup_handler,
					task_data, &pid, &error))
	{
		g_object_ref(scgi_task);
		g_child_watch_add(pid, hev_scgi_handler_child_watch_handler, task_data);
	}
	else
	{
		g_critical("%s:%d[%s]=>(%s)", __FILE__, __LINE__,
					__FUNCTION__, error->message);
		g_error_free(error);
	}

	g_strfreev(argv);
	g_free(workdir);
}
示例#30
0
文件: svgload.c 项目: lovell/libvips
static void *
vips_foreign_load_svg_zalloc( void *opaque, unsigned items, unsigned size )
{
	return( g_malloc0_n( items, size ) );
}