Esempio n. 1
0
/* Put @ace into @sd. If no ACE corresponding to @ace currently exists,
 * it will be added in the right place. If it does already exist, its
 * flags (in particular INHERITED_ACE) will be preserved and only the
 * mask will be changed.
 */
static void
set_ace (E2kSecurityDescriptor *sd, E2k_ACE *ace)
{
	E2k_ACE *aces = (E2k_ACE *)sd->priv->aces->data;
	int low, mid = 0, high, cmp = -1;

	low = 0;
	high = sd->priv->aces->len - 1;
	while (low <= high) {
		mid = (low + high) / 2;
		cmp = ace_compar (ace, &aces[mid], sd);
		if (cmp == 0) {
			if (ace->Mask)
				aces[mid].Mask = ace->Mask;
			else
				g_array_remove_index (sd->priv->aces, mid);
			return;
		} else if (cmp < 0)
			high = mid - 1;
		else
			low = mid + 1;
	}

	if (ace->Mask)
		g_array_insert_vals (sd->priv->aces, cmp < 0 ? mid : mid + 1, ace, 1);
}
Esempio n. 2
0
void GLibArrayImpl::Insert(LArrayInst * inst, int index, void * value)
{
//TODO- Should we use this slightly more sane implementation?
/*
    GPtrArray *array = (GPtrArray *)this->m_impl;
    if ((index + 1) == array->len) 
    {
        // add to the end of the array 
        g_ptr_array_add (array, value);
        return;
    }      
    if (index >= array->len)
    {
        // extend and add PAST the end of the array
        g_ptr_array_set_size (array, index + 1);
        array->pdata[index] = value;
        return;
    }       
    // normal case - shift all elements starting at @index 1 position to the right 
    g_ptr_array_set_size (array, array->len + 1);
    for (int i = array->len - 2; i >= index; i--)
        array->pdata[i + 1] = array->pdata[i];
    array->pdata[index] = value;
*/
	g_return_if_fail(inst != NULL);
	g_array_insert_vals(dynamic_cast<GLibArrayInst *>(inst)->m_array, index, value, 1);
}
Esempio n. 3
0
/**
 * This function adds images into image list. It is kinda special as it does not
 * use yank buffer as an input. It should be used at special occasions only,
 * like for loading image_group from image_pile.
 *
 * \param group image list into which images will be added
 * \param index position to which images will be added
 * \param data array containing list of image pointers
 * \param size number of pointers in array
 * \return OK on success
 */
extern RCode group_insert(ImageGroup* group, gint index, Image* data[], guint size) {
	unsigned int source_index = 0;
	unsigned int target_index = 0;
	ImageGroupRecord* buffer = NULL;

	ASSERT(NULL != group);
	ASSERT(NULL != group->list);

	/* check position into which images are being inserted
	 * we do not fail if index = list length ( which is one record after the
	 * last one to be able to add at the end of array */
	if ( index < 0 || group->list->len < index ) {
		ERROR_SET(ERROR.OUT_OF_RANGE);
		ERROR_NOTE("Index %d out of range [0, %d]", index, group->list->len);
		return FAIL;
	}

	// allocate internal buffer for insertions
	TRACE_MESSAGE(IGRP, TL_DEBUG, "Allocate insert buffer (size=%d)", size);
	buffer = (ImageGroupRecord*) g_try_malloc0(size*sizeof(ImageGroupRecord));
	if ( NULL == buffer ) {
		ERROR_SET(ERROR.MEMORY_FAILURE);
		return FAIL;
	}

	// prepare data in buffer for insertion
	TRACE_MESSAGE(IGRP, TL_DEBUG, "Preparing values into insert buffer (count=%d)",size);
	for ( source_index = 0, target_index = 0; source_index < size; source_index++ ) {
		TagList *tags = image_get_groups(data[source_index]);

		if ( FALSE == taglist_contains(tags, group->tag) ) {
			buffer[target_index].image = data[source_index];
			buffer[target_index].select = FALSE;

			image_ref(buffer[target_index].image);
			taglist_insert(tags, group->tag);
			target_index++;
		}
	}

	// compute position into which to insert and insert the data
	TRACE_MESSAGE(IGRP, TL_INFO, "Inserting records into group (name='%s', index=%d, count=%d, filtered=%d)",
		group->name, index, target_index, (size - target_index)
	);
	group->list = g_array_insert_vals(group->list, index, (gpointer)buffer, target_index);

	// deallocate insert buffer
	g_free( (gpointer)buffer );

	return OK;
}
Esempio n. 4
0
int main(void) {
  GArray *a = g_array_new(FALSE, FALSE, sizeof(int));
  int x[2] = { 1, 5 };
  g_array_append_vals(a, &x, 2);
  print_array(a);
  printf("Insert '2'\n");
  int b = 2;
  g_array_insert_val(a, 1, b);
  print_array(a);
  printf("Inserting multiple values\n");
  int y[2] = { 3, 4 };
  g_array_insert_vals(a, 2, y, 2);
  print_array(a);
  g_array_free(a, FALSE);
}
Esempio n. 5
0
static void on_recent_menu_item_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, const gchar *name)
{
	RecentProgram *recent = (RecentProgram *) array_find(recent_programs, name, TRUE);

	if (recent && utils_filenamecmp(recent->name, *program_executable ? program_executable :
		program_load_script))
	{
		char *configfile = recent_file_name(recent->id);
		GKeyFile *config = g_key_file_new();
		GError *gerror = NULL;
		gchar *message;

		if (g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, &gerror))
		{
			save_program_settings();
			recent = (RecentProgram *) array_find(recent_programs, name, TRUE);
			stash_foreach((GFunc) stash_group_load_from_key_file, config);
			if ((unsigned) option_inspect_expand > EXPAND_MAX)
				option_inspect_expand = 100;
			breaks_load(config);
			watches_load(config);
			inspects_load(config);
			parse_load(config);
			message = g_strdup_printf(_("Loaded debug settings for %s."), recent->name);
			g_array_insert_vals(recent_programs, 0, ++recent, 1);
			array_remove(recent_programs, recent);
			recent_menu_create();
			program_configure();
		}
		else
		{
			message = g_strdup_printf(_("Could not load debug settings file %s: %s."),
				configfile, gerror->message);
			g_error_free(gerror);
		}

		if (menuitem)
			ui_set_statusbar(TRUE, "%s", message);
		else
			msgwin_status_add("%s", message);

		g_free(message);
		g_key_file_free(config);
		g_free(configfile);
	}
}
Esempio n. 6
0
static void save_program_settings(void)
{
	const gchar *program_name = *program_executable ? program_executable :
		program_load_script;

	if (*program_name)
	{
		RecentProgram *recent = (RecentProgram *) array_find(recent_programs, program_name,
			TRUE);
		GKeyFile *config = g_key_file_new();
		char *configfile;

		if (!recent)
		{
			recent = (RecentProgram *) array_append(recent_programs);
			recent->name = g_strdup(program_name);

			for (recent->id = 1; recent->id < RECENT_COUNT; recent->id++)
				if ((recent_bitmap & (1 << recent->id)) == 0)
					break;

			recent_bitmap |= 1 << recent->id;
		}

		configfile = recent_file_name(recent->id);
		stash_foreach((GFunc) stash_group_save_to_key_file, config);
		breaks_save(config);
		watches_save(config);
		inspects_save(config);
		parse_save(config);
		utils_key_file_write_to_file(config, configfile);
		g_free(configfile);
		g_key_file_free(config);

		g_array_insert_vals(recent_programs, 0, ++recent, 1);
		array_remove(recent_programs, recent);
		recent_menu_create();

		if (recent_programs->len > RECENT_COUNT)
		{
			recent_bitmap &= ~(1 << recent->id);
			array_remove(recent_programs, recent);
		}
	}
}
Esempio n. 7
0
/**
 * Enumerate scan options supported by this driver.
 *
 * Before calling sr_driver_scan_options_list(), the user must have previously
 * initialized the driver by calling sr_driver_init().
 *
 * @param driver The driver to enumerate options for. This must be a pointer
 *               to one of the entries returned by sr_driver_list(). Must not
 *               be NULL.
 *
 * @return A GArray * of uint32_t entries, or NULL on invalid arguments. Each
 *         entry is a configuration key that is supported as a scan option.
 *         The array must be freed by the caller using g_array_free().
 *
 * @since 0.4.0
 */
SR_API GArray *sr_driver_scan_options_list(const struct sr_dev_driver *driver)
{
	GVariant *gvar;
	const uint32_t *opts;
	gsize num_opts;
	GArray *result;

	if (sr_config_list(driver, NULL, NULL, SR_CONF_SCAN_OPTIONS, &gvar) != SR_OK)
		return NULL;

	opts = g_variant_get_fixed_array(gvar, &num_opts, sizeof(uint32_t));

	result = g_array_sized_new(FALSE, FALSE, sizeof(uint32_t), num_opts);

	g_array_insert_vals(result, 0, opts, num_opts);

	g_variant_unref(gvar);

	return result;
}
Esempio n. 8
0
void
gv_areas_insert_nodes(GvAreas *areas, gint area_id, gint ring_id,
		      gint node_id, gint num_nodes, GvVertex *vertex)
{
    GvArea *area;
    GArray *ring;
    GvShapeChangeInfo change_info = {GV_CHANGE_REPLACE, 1, NULL};

    change_info.shape_id = &area_id;

    g_return_if_fail(area_id >= 0 && area_id < areas->areas->len);
    area = gv_areas_get_area(areas, area_id);
    g_return_if_fail(ring_id >= 0 && ring_id < area->rings->len);
    ring = gv_areas_get_ring(area, ring_id);
    g_return_if_fail(node_id >= 0 && node_id < ring->len);

    gv_data_changing(GV_DATA(areas), &change_info);
    
    g_array_insert_vals(ring, node_id, vertex, num_nodes);

    gv_data_changed(GV_DATA(areas), &change_info);
}
static void
ft_operation_provide_or_accept_file_cb (TpChannel *proxy,
    const GValue *address,
    const GError *error,
    gpointer user_data,
    GObject *weak_object)
{
  EmpathyTpFile *self = EMPATHY_TP_FILE (weak_object);
  GError *myerr = NULL;

  g_cancellable_set_error_if_cancelled (self->priv->cancellable, &myerr);

  if (error != NULL)
    {
      if (myerr != NULL)
        {
          /* if we were both cancelled and failed when calling the method,
          * report the method error.
          */
          g_clear_error (&myerr);
        }

      myerr = g_error_copy (error);
    }

  if (myerr != NULL)
    {
      DEBUG ("Error: %s", myerr->message);
      ft_operation_close_with_error (self, myerr);
      g_clear_error (&myerr);
      return;
    }

  if (G_VALUE_TYPE (address) == DBUS_TYPE_G_UCHAR_ARRAY)
    {
      self->priv->socket_address = g_value_dup_boxed (address);
    }
  else if (G_VALUE_TYPE (address) == G_TYPE_STRING)
    {
      /* Old bugged version of telepathy-salut used to store the address
       * as a 's' instead of an 'ay' */
      const gchar *path;

      path = g_value_get_string (address);
      self->priv->socket_address = g_array_sized_new (TRUE, FALSE,
          sizeof (gchar), strlen (path));
      g_array_insert_vals (self->priv->socket_address, 0, path, strlen (path));
    }
  else if (G_VALUE_TYPE (address) == TP_STRUCT_TYPE_SOCKET_ADDRESS_IPV4)
    {
      GValueArray *val_array;
      GValue *v;
      const char *addr;

      val_array = g_value_get_boxed (address);

      /* IPV4 address */
      v = g_value_array_get_nth (val_array, 0);
      addr = g_value_get_string (v);
      self->priv->socket_address = g_array_sized_new (TRUE, FALSE,
          sizeof (gchar), strlen (addr));
      g_array_insert_vals (self->priv->socket_address, 0, addr, strlen (addr));

      /* port number */
      v = g_value_array_get_nth (val_array, 1);
      self->priv->port = g_value_get_uint (v);
    }

  DEBUG ("Got socket address: %s, port (not zero if IPV4): %d",
      self->priv->socket_address->data, self->priv->port);

  /* if the channel is already open, start the transfer now, otherwise,
   * wait for the state change signal.
   */
  if (self->priv->state == TP_FILE_TRANSFER_STATE_OPEN)
    tp_file_start_transfer (self);
}
static void
gst_file_index_add_association (GstIndex * index, GstIndexEntry * entry)
{
  GstFileIndex *fileindex = GST_FILE_INDEX (index);
  GstFileIndexId *id_index;
  gint mx;
  GstIndexAssociation sample;
  gboolean exact;

  id_index = g_hash_table_lookup (fileindex->id_index, &entry->id);
  if (!id_index)
    return;

  if (!id_index->nformats) {
    gint fx;

    id_index->nformats = GST_INDEX_NASSOCS (entry);
    GST_LOG_OBJECT (fileindex, "creating %d formats for %d",
        id_index->nformats, entry->id);
    id_index->format = g_new (GstFormat, id_index->nformats);
    for (fx = 0; fx < id_index->nformats; fx++)
      id_index->format[fx] = GST_INDEX_ASSOC_FORMAT (entry, fx);
    _fc_alloc_array (id_index);
  } else {
    /* only sanity checking */
    if (id_index->nformats != GST_INDEX_NASSOCS (entry))
      GST_WARNING_OBJECT (fileindex, "arity change %d -> %d",
          id_index->nformats, GST_INDEX_NASSOCS (entry));
    else {
      gint fx;

      for (fx = 0; fx < id_index->nformats; fx++)
        if (id_index->format[fx] != GST_INDEX_ASSOC_FORMAT (entry, fx))
          GST_WARNING_OBJECT (fileindex, "format[%d] changed %d -> %d",
              fx, id_index->format[fx], GST_INDEX_ASSOC_FORMAT (entry, fx));
    }
  }

  /* this is a hack, we should use a private structure instead */
  sample.format = 0;
  sample.value = GST_INDEX_ASSOC_VALUE (entry, 0);

  exact =
      _fc_bsearch (id_index->array, ARRAY_ROW_SIZE (id_index),
      &mx, file_index_compare, &sample, id_index);

  if (exact) {
    /* maybe overwrite instead? */
    GST_DEBUG_OBJECT (index,
        "Ignoring duplicate index association at %" G_GINT64_FORMAT,
        GST_INDEX_ASSOC_VALUE (entry, 0));
    return;
  }

  {
    gchar *row_data = (gchar *) g_malloc (ARRAY_ROW_SIZE (id_index));
    gint fx;

    gint32 flags_host = GST_INDEX_ASSOC_FLAGS (entry);

    ARRAY_ROW_FLAGS (row_data) = GINT32_TO_BE (flags_host);

    for (fx = 0; fx < id_index->nformats; fx++) {
      gint64 val_host = GST_INDEX_ASSOC_VALUE (entry, fx);

      ARRAY_ROW_VALUE (row_data, fx) = GINT64_TO_BE (val_host);
    }

    g_array_insert_vals (id_index->array, mx, row_data, 1);

    g_free (row_data);
  }
}