Exemple #1
0
/* We test deprecated functionality here */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS

#ifdef G_ENABLE_DEBUG
static void
test_slice_nodebug (void)
{
  const gchar *oldval;

  oldval = g_getenv ("G_SLICE");
  g_unsetenv ("G_SLICE");

  if (g_test_subprocess ())
    {
      gpointer p, q;

      p = g_slice_alloc (237);
      q = g_slice_alloc (259);
      g_slice_free1 (237, p);
      g_slice_free1 (259, q);

      g_slice_debug_tree_statistics ();
      return;
    }
  g_test_trap_subprocess (NULL, 1000000, 0);
  g_test_trap_assert_passed ();
  g_test_trap_assert_stderr ("*GSlice: MemChecker: root=NULL*");

  if (oldval)
    g_setenv ("G_SLICE", oldval, TRUE);
}
Exemple #2
0
static void
test_slice_debug (void)
{
  const gchar *oldval;

  oldval = g_getenv ("G_SLICE");
  g_setenv ("G_SLICE", "debug-blocks:always-malloc", TRUE);

  if (g_test_subprocess ())
    {
      gpointer p, q;

      p = g_slice_alloc (237);
      q = g_slice_alloc (259);
      g_slice_free1 (237, p);
      g_slice_free1 (259, q);

      g_slice_debug_tree_statistics ();
      return;
    }
  g_test_trap_subprocess (NULL, 1000000, 0);
  g_test_trap_assert_passed ();
  g_test_trap_assert_stderr ("*GSlice: MemChecker: * trunks, * branches, * old branches*");

  if (oldval)
    g_setenv ("G_SLICE", oldval, TRUE);
  else
    g_unsetenv ("G_SLICE");
}
Exemple #3
0
int main(int argc, char* argv[])
{
	GHashTable *table;
	table = g_hash_table_new_full(g_int_hash, g_int_equal, do_free_item, do_free_item);	

	int i = 0;
	for (i = 0; i < 100; i++) {
		int* key = g_slice_alloc(sizeof(int));
		int* value = g_slice_alloc(sizeof(int));
		
		*key = i;
		*value = i + 1;

		g_hash_table_insert(table, key, value);
	}
	
	int key = 1;
	int* pval = g_hash_table_lookup(table, &key);
	if (pval == NULL) {
		printf("can find\n");
	} else {
		printf("%d\n", *pval);
	}

	g_hash_table_destroy(table);
	return 0;
}
Exemple #4
0
static void
console_controller_reprint_suffix(ConsoleController *ctrl)
{
	gchar *suffix, *suffix_cmd, *backspace;

	glong bksplen, avlen, suflen = 0;
	InputNode *cursor = ctrl->input_cursor->next;

	if (cursor) {
		avlen = ctrl->input_length + 1;
		suffix = (gchar*) g_slice_alloc(avlen * sizeof(gchar));
		while(cursor) {
			suffix[suflen++] = cursor->charData;
			cursor = cursor->next;
		}
		suffix[suflen] = '\0';

		bksplen = slice_sprintnum(&backspace, "\033[O\033[%dD\033[N", suflen);
		if (suflen + bksplen > avlen) {
			suffix_cmd = (gchar*) g_slice_alloc((suflen + bksplen) * sizeof(gchar));
			g_stpcpy(suffix_cmd, suffix);
		} else {
			suffix_cmd = suffix;
		}
		g_stpcpy(suffix_cmd + suflen, backspace);
	}

	if (suflen) {
		vte_terminal_feed(ctrl->terminal, suffix_cmd, suflen + bksplen);
		if (suffix_cmd != suffix) g_slice_free1((suflen + bksplen) * sizeof(gchar), suffix_cmd);
		g_slice_free1(avlen * sizeof(gchar), suffix);
		g_slice_free1(bksplen * sizeof(gchar), backspace);
	}
}
Exemple #5
0
static gpointer
test_sliced_mem_thread (gpointer data)
{
  guint32 rand_accu = 2147483563;
  guint i, j;
  guint8 **ps;
  guint   *ss;

  /* initialize random numbers */
  if (data)
    rand_accu = *(guint32*) data;
  else
    {
      GTimeVal rand_tv;
      g_get_current_time (&rand_tv);
      rand_accu = rand_tv.tv_usec + (rand_tv.tv_sec << 16);
    }

  ps = g_new (guint8*, number_of_blocks);
  ss = g_new (guint, number_of_blocks);
  /* create number_of_blocks random sizes */
  for (i = 0; i < number_of_blocks; i++)
    ss[i] = quick_rand32() % prime_size;
  /* allocate number_of_blocks blocks */
  for (i = 0; i < number_of_blocks; i++)
    ps[i] = g_slice_alloc (ss[i] + corruption());
  for (j = 0; j < number_of_repetitions; j++)
    {
      /* free number_of_blocks/2 blocks */
      for (i = 0; i < number_of_blocks; i += 2)
        g_slice_free1 (ss[i] + corruption(), ps[i] + corruption());
      /* allocate number_of_blocks/2 blocks with new sizes */
      for (i = 0; i < number_of_blocks; i += 2)
        {
          ss[i] = quick_rand32() % prime_size;
          ps[i] = g_slice_alloc (ss[i] + corruption());
        }
    }
  /* free number_of_blocks blocks */
  for (i = 0; i < number_of_blocks; i++)
    g_slice_free1 (ss[i] + corruption(), ps[i] + corruption());
  /* alloc and free many equally sized chunks in a row */
  for (i = 0; i < number_of_repetitions; i++)
    {
      guint sz = quick_rand32() % prime_size;
      guint k = number_of_blocks / 100;
      for (j = 0; j < k; j++)
        ps[j] = g_slice_alloc (sz + corruption());
      for (j = 0; j < k; j++)
        g_slice_free1 (sz + corruption(), ps[j] + corruption());
    }
  g_free (ps);
  g_free (ss);

  return NULL;
}
static gboolean
configure_filters (GstMfxFilter * filter)
{
  GstMfxFilterOpData *op;
  mfxExtBuffer *ext_buf;
  guint i, len;
  len = filter->filter_op_data->len;

  if (!filter->inited) {
    check_supported_filters (filter);
  }

  /* If AlgList is available when filter is already initialized
  and if current number of filter is not equal to new number of
  filter requested, deallocate resources when resetting */
  if (filter->vpp_use.AlgList &&
      (len != filter->vpp_use.NumAlg)) {
    g_slice_free1 ((filter->vpp_use.NumAlg * sizeof (mfxU32)),
        filter->vpp_use.AlgList);
    g_slice_free1 (((filter->vpp_use.NumAlg + 1) * sizeof (mfxExtBuffer *)),
        filter->ext_buffer);
  }
  if (!len)
    return FALSE;

  memset (&filter->vpp_use, 0, sizeof (mfxExtVPPDoUse));
  filter->vpp_use.Header.BufferId = MFX_EXTBUFF_VPP_DOUSE;
  filter->vpp_use.Header.BufferSz = sizeof (mfxExtVPPDoUse);
  filter->vpp_use.NumAlg = len;
  filter->vpp_use.AlgList = g_slice_alloc (len * sizeof (mfxU32));
  if (!filter->vpp_use.AlgList)
    return FALSE;

  filter->ext_buffer = g_slice_alloc (
      (len + 1) * sizeof (mfxExtBuffer *));
  if (!filter->ext_buffer)
    return FALSE;

  for (i = 0; i < len; i++) {
    op = (GstMfxFilterOpData *) g_ptr_array_index (filter->filter_op_data, i);
    ext_buf = (mfxExtBuffer *) op->filter;
    filter->vpp_use.AlgList[i] = ext_buf->BufferId;
    filter->ext_buffer[i + 1] = (mfxExtBuffer *) op->filter;
  }

  filter->ext_buffer[0] = (mfxExtBuffer *) & filter->vpp_use;

  filter->params.NumExtParam = len + 1;
  filter->params.ExtParam = (mfxExtBuffer **) & filter->ext_buffer[0];

  return TRUE;
}
static guint16 *
read_file_to_buffer (const gchar *name, gsize count, GError *e)
{
  GError *error = NULL;
  guint16 *depth = NULL;
  GFile *new_file = g_file_new_for_path (name);
  GFileInputStream *input_stream = g_file_read (new_file,
                                                NULL,
                                                &error);
  if (error != NULL)
    {
      g_debug ("ERROR: %s", error->message);
    }
  else
    {
      gsize bread = 0;
      depth = g_slice_alloc (count);
      g_input_stream_read_all ((GInputStream *) input_stream,
                               depth,
                               count,
                               &bread,
                               NULL,
                               &error);

      if (error != NULL)
        {
          g_debug ("ERROR: %s", error->message);
        }
    }
  return depth;
}
Exemple #8
0
static void	ug_selector_page_add_filter (UgSelectorPage* page, GtkListStore* filter_store, gchar* key, UgSelectorItem* value)
{
	GtkTreeIter		iter;
	UgSelectorItem*	filter_item;
	GList*			filter_list;
	gchar*			orig_key;

	if (g_hash_table_lookup_extended (page->filter.hash, key,
			(gpointer*) &orig_key, (gpointer*) &filter_list) == FALSE)
	{
		filter_item = g_slice_alloc (sizeof (UgSelectorItem));
		filter_item->uri  = key;
		filter_item->mark = TRUE;
		filter_item->dataset = NULL;
		gtk_list_store_append (filter_store, &iter);
		gtk_list_store_set (filter_store, &iter, 0, filter_item, -1);
		filter_list = NULL;
	}
	else {
		g_hash_table_steal (page->filter.hash, key);
		g_free (key);
		key = orig_key;
	}
	filter_list = g_list_prepend (filter_list, value);
	g_hash_table_insert (page->filter.hash, key, filter_list);
}
static guchar *
create_grayscale_buffer (guint16 *buffer, guint width, guint height)
{
  gint i,j;
  gint size;
  guchar *grayscale_buffer;

  size = width * height * sizeof (guchar) * 3;
  grayscale_buffer = g_slice_alloc (size);
  /*Paint it white*/
  memset (grayscale_buffer, 255, size);

  for (i = 0; i < width; i++)
    {
      for (j = 0; j < height; j++)
        {
          guint16 value = round (buffer[j * width + i]  * 256. / 3000.);
          if (value != 0)
            {
              gint index = j * width + i;
              grayscale_buffer_set_value (grayscale_buffer,
                                          index,
                                          value);
            }
        }
    }

  return grayscale_buffer;
}
static
bool
n2p_has_property(void *object, struct PP_Var name, struct PP_Var *exception)
{
    if (name.type != PP_VARTYPE_STRING) {
        trace_error("%s, name is not a string\n", __func__);
        // TODO: fill exception
        return false;
    }

    struct has_property_param_s *p = g_slice_alloc(sizeof(*p));
    p->object =     object;
    p->name =       name;
    p->exception =  exception;
    p->m_loop =     ppb_message_loop_get_current();
    p->depth =      ppb_message_loop_get_depth(p->m_loop) + 1;

    ppb_message_loop_post_work_with_result(p->m_loop, PP_MakeCCB(n2p_has_property_comt, p), 0,
                                           PP_OK, p->depth, __func__);
    ppb_message_loop_run_nested(p->m_loop);

    bool result = p->result;
    g_slice_free1(sizeof(*p), p);

    return result;
}
/* must hold array lock */
static gpointer
freelist_alloc (gsize size, gboolean reuse)
{
  gpointer mem;
  FreeListNode *free, **prev;
  gsize real_size;

  if (reuse)
    {
      for (free = freelist, prev = &freelist; free != NULL; prev = &free->next, free = free->next)
    {
      if (G_ATOMIC_ARRAY_DATA_SIZE (free) == size)
        {
          *prev = free->next;
          return (gpointer)free;
        }
    }
    }

  real_size = sizeof (gsize) + MAX (size, sizeof (FreeListNode));
  mem = g_slice_alloc (real_size);
#ifdef GSTREAMER_LITE
  if (mem == NULL) {
    return NULL;
  }
#endif // GSTREAMER_LITE
  mem = ((char *) mem) + sizeof (gsize);
  G_ATOMIC_ARRAY_DATA_SIZE (mem) = size;
  return mem;
}
Exemple #12
0
static inline JPollEvent *j_poll_event_new(struct epoll_event *event)
{
    JPollEvent *jpe = (JPollEvent *) g_slice_alloc(sizeof(JPollEvent));
    jpe->type = event->events;
    jpe->jsock = (JSocket *) event->data.ptr;
    return jpe;
}
Exemple #13
0
JParser *j_parser_alloc(const gchar * name)
{
    JParser *p = (JParser *) g_slice_alloc(sizeof(JParser));
    p->name = g_strdup(name);
    p->nodes = NULL;
    return p;
}
void
ppb_graphics2d_paint_image_data(PP_Resource graphics_2d, PP_Resource image_data,
                                const struct PP_Point *top_left, const struct PP_Rect *src_rect)
{
    struct pp_graphics2d_s *g2d = pp_resource_acquire(graphics_2d, PP_RESOURCE_GRAPHICS2D);
    if (!g2d) {
        trace_error("%s, bad resource\n", __func__);
        return;
    }

    struct g2d_paint_task_s *pt = g_slice_alloc(sizeof(*pt));
    pt->type = gpt_paint_id;
    pp_resource_ref(image_data);
    pt->image_data = image_data;
    pt->src_is_set = !!src_rect;

    if (top_left) {
        memcpy(&pt->ofs, top_left, sizeof(*top_left));
    } else {
        pt->ofs.x = pt->ofs.y = 0;
    }
    if (src_rect)
        memcpy(&pt->src, src_rect, sizeof(*src_rect));

    g2d->task_list = g_list_append(g2d->task_list, pt);
    pp_resource_release(graphics_2d);
}
static void
infinoted_plugin_manager_add_connection(InfinotedPluginManager* manager,
                                        InfinotedPluginInstance* instance,
                                        InfXmlConnection* connection)
{
  gpointer plugin_info;
  gpointer hash;
  gpointer connection_info;

  plugin_info = instance+1;
  hash = infinoted_plugin_manager_hash(plugin_info, connection);
  g_assert(g_hash_table_lookup(manager->connections, hash) == NULL);

  if(instance->plugin->connection_info_size > 0)
  {
    connection_info = g_slice_alloc(instance->plugin->connection_info_size);
    g_hash_table_insert(manager->connections, hash, connection_info);
  }

  if(instance->plugin->on_connection_added != NULL)
  {
    instance->plugin->on_connection_added(
      connection,
      plugin_info,
      connection_info
    );
  }
}
bool
p2n_get_property(NPObject *npobj, NPIdentifier name, NPVariant *np_result)
{
    if (!npn.identifierisstring(name)) {
        trace_error("%s, name is not a string\n", __func__);
        return false;
    }

    if (npobj->_class == &p2n_proxy_class) {
        struct get_property_param_s *p = g_slice_alloc(sizeof(*p));
        p->npobj =      npobj;
        p->name =       npn.utf8fromidentifier(name);
        p->np_result =  np_result;
        p->m_loop =     ppb_message_loop_get_for_browser_thread();
        p->depth =      ppb_message_loop_get_depth(p->m_loop) + 1;

        ppb_message_loop_post_work_with_result(p->m_loop,
                                               PP_MakeCCB(p2n_get_property_prepare_comt, p), 0,
                                               PP_OK, 0, __func__);
        ppb_message_loop_run_nested(p->m_loop);
        bool result = p->result;
        npn.memfree(p->name);
        g_slice_free1(sizeof(*p), p);
        return result;
    } else {
        return npobj->_class->getProperty(npobj, name, np_result);
    }
}
// Schedules task for execution on browser thread.
//
// Since there is no access to browser event loop, we start a nested event loop which is terminated
// as long as there is no tasks left. That way we can implement waiting as entering a nested loop
// and thus avoid deadlocks.
void
ppb_core_call_on_browser_thread(PP_Instance instance, void (*func)(void *), void *user_data)
{
    struct call_on_browser_thread_task_s *task = g_slice_alloc(sizeof(*task));
    task->func = func;
    task->user_data = user_data;

    // Push task into queue. The only purpose is to put task into queue even if message loop
    // is currenly terminating (in teardown state), so we are ignoring that. There are three
    // possible loop states. Message loop is either running, stopped, or terminating. If it's
    // still running, task will be executed in the context of that loop. If it's stopped or
    // stopping right now, task will be pushed to a queue. After that code below will schedule
    // nested loop on browser thread.
    PP_Resource m_loop = ppb_message_loop_get_for_browser_thread();
    ppb_message_loop_post_work_with_result(m_loop, PP_MakeCCB(call_on_browser_thread_comt, task), 0,
                                           PP_OK, 0, __func__);

    struct pp_instance_s *pp_i = instance ? tables_get_pp_instance(instance)
                                          : tables_get_some_pp_instance();
    if (!pp_i) {
        trace_error("%s, no alive instance available\n", __func__);
        return;
    }

    // Schedule activation routine.
    pthread_mutex_lock(&display.lock);
    if (pp_i->npp)
        npn.pluginthreadasynccall(pp_i->npp, activate_browser_thread_ml_ptac, user_data);
    pthread_mutex_unlock(&display.lock);
}
Exemple #18
0
/**
 * mio_new_file_full:
 * @filename: Filename to open, passed as-is to @open_func as the first argument
 * @mode: Mode in which open the file, passed as-is to @open_func as the second
 *        argument
 * @open_func: A function with the fopen() semantic to use to open the file
 * @close_func: A function with the fclose() semantic to close the file when
 *              the #MIO object is destroyed, or %NULL not to close the #FILE
 *              object
 * 
 * Creates a new #MIO object working on a file, from a filename and an opening
 * function. See also mio_new_file().
 * 
 * This function is generally overkill and mio_new_file() should often be used
 * instead, but it allows to specify a custom function to open a file, as well
 * as a close function. The former is useful e.g. if you need to wrap fopen()
 * for some reason (like filename encoding conversion for example), and the
 * latter allows you both to match your custom open function and to choose
 * whether the underlying #FILE object should or not be closed when mio_free()
 * is called on the returned object.
 * 
 * Free-function: mio_free()
 * 
 * Returns: A new #MIO on success, or %NULL on failure.
 */
MIO *
mio_new_file_full (const gchar  *filename,
                   const gchar  *mode,
                   MIOFOpenFunc  open_func,
                   MIOFCloseFunc close_func)
{
  MIO *mio;
  
  /* we need to create the MIO object first, because we may not be able to close
   * the opened file if the user passed NULL as the close function, which means
   * that everything must succeed if we've opened the file successfully */
  mio = g_slice_alloc (sizeof *mio);
  if (mio) {
    FILE *fp = open_func (filename, mode);
    
    if (! fp) {
      g_slice_free1 (sizeof *mio, mio);
      mio = NULL;
    } else {
      mio->type = MIO_TYPE_FILE;
      mio->impl.file.fp = fp;
      mio->impl.file.close_func = close_func;
      /* function table filling */
      FILE_SET_VTABLE (mio);
    }
  }
  
  return mio;
}
Exemple #19
0
/**
 * mio_new_memory:
 * @data: Initial data (may be %NULL)
 * @size: Length of @data in bytes
 * @realloc_func: A function with the realloc() semantic used to grow the
 *                buffer, or %NULL to disable buffer growing
 * @free_func: A function with the free() semantic to destroy the data together
 *             with the object, or %NULL not to destroy the data
 * 
 * Creates a new #MIO object working on memory.
 * 
 * To allow the buffer to grow, you must provide a @realloc_func, otherwise
 * trying to write after the end of the current data will fail.
 * 
 * If you want the buffer to be freed together with the #MIO object, you must
 * give a @free_func; otherwise the data will still live after #MIO object
 * termination.
 * 
 * <example>
 * <title>Basic creation of a non-growable, freeable #MIO object</title>
 * <programlisting>
 * MIO *mio = mio_new_memory (data, size, NULL, g_free);
 * </programlisting>
 * </example>
 * 
 * <example>
 * <title>Basic creation of an empty growable and freeable #MIO object</title>
 * <programlisting>
 * MIO *mio = mio_new_memory (NULL, 0, g_try_realloc, g_free);
 * </programlisting>
 * </example>
 * 
 * Free-function: mio_free()
 * 
 * Returns: A new #MIO on success, or %NULL on failure.
 */
MIO *
mio_new_memory (guchar         *data,
                gsize           size,
                MIOReallocFunc  realloc_func,
                GDestroyNotify  free_func)
{
  MIO  *mio;
  
  mio = g_slice_alloc (sizeof *mio);
  if (mio) {
    mio->type = MIO_TYPE_MEMORY;
    mio->impl.mem.buf = data;
    mio->impl.mem.ungetch = EOF;
    mio->impl.mem.pos = 0;
    mio->impl.mem.size = size;
    mio->impl.mem.allocated_size = size;
    mio->impl.mem.realloc_func = realloc_func;
    mio->impl.mem.free_func = free_func;
    mio->impl.mem.eof = FALSE;
    mio->impl.mem.error = FALSE;
    /* function table filling */
    MEM_SET_VTABLE (mio);
  }
  
  return mio;
}
Exemple #20
0
static guchar *
create_grayscale_buffer (BufferInfo *buffer_info, gint dimension_reduction)
{
  gint i,j;
  gint size;
  guchar *grayscale_buffer;
  guint16 *reduced_buffer;

  reduced_buffer = buffer_info->reduced_buffer;

  size = buffer_info->width * buffer_info->height * sizeof (guchar) * 3;
  grayscale_buffer = g_slice_alloc (size);
  /*Paint is white*/
  memset (grayscale_buffer, 255, size);

  for (i = 0; i < buffer_info->reduced_width; i++)
    {
      for (j = 0; j < buffer_info->reduced_height; j++)
        {
          if (reduced_buffer[j * buffer_info->reduced_width + i] != 0)
            {
              gint index = j * dimension_reduction * buffer_info->width +
                i * dimension_reduction;
              grayscale_buffer_set_value (grayscale_buffer, index, 0);
            }
        }
    }

  return grayscale_buffer;
}
Exemple #21
0
void xml_node_add_tag(XmlNode * node, char * key, char * value)
{
	XmlKeyValue * kv = g_slice_alloc(sizeof(XmlKeyValue));
	kv -> key = g_strdup(key);
	kv -> value = g_strdup(value);
	g_sequence_append(node -> tags, kv);
}
Exemple #22
0
static void gst_imx_ipu_blitter_init(GstImxIpuBlitter *ipu_blitter)
{
	if (!gst_imx_ipu_open())
	{
		GST_ELEMENT_ERROR(ipu_blitter, RESOURCE, OPEN_READ_WRITE, ("could not open IPU device"), (NULL));
		return;
	}

	gst_video_info_init(&(ipu_blitter->input_video_info));
	gst_video_info_init(&(ipu_blitter->output_video_info));
	ipu_blitter->allocator = NULL;
	ipu_blitter->input_frame = NULL;
	ipu_blitter->output_frame = NULL;
	ipu_blitter->use_entire_input_frame = TRUE;

	ipu_blitter->priv = g_slice_alloc(sizeof(GstImxIpuBlitterPrivate));
	memset(&(ipu_blitter->priv->main_task), 0, sizeof(struct ipu_task));

	ipu_blitter->visibility_mask = 0;
	ipu_blitter->fill_color = 0xFF000000;
	ipu_blitter->num_empty_regions = 0;

	ipu_blitter->clipped_outer_region_updated = FALSE;
	ipu_blitter->num_output_pages = 1;
	ipu_blitter->num_cleared_output_pages = 0;

	ipu_blitter->deinterlacing_enabled = GST_IMX_IPU_BLITTER_DEINTERLACE_DEFAULT;
}
Exemple #23
0
CoglPrimitive *
cogl_primitive_new_with_attributes (CoglVerticesMode mode,
                                    int n_vertices,
                                    CoglAttribute **attributes,
                                    int n_attributes)
{
  CoglPrimitive *primitive;
  int i;

  primitive = g_slice_alloc (sizeof (CoglPrimitive) +
                             sizeof (CoglAttribute *) * (n_attributes - 1));
  primitive->mode = mode;
  primitive->first_vertex = 0;
  primitive->n_vertices = n_vertices;
  primitive->indices = NULL;
  primitive->immutable_ref = 0;

  primitive->n_attributes = n_attributes;
  primitive->n_embedded_attributes = n_attributes;
  primitive->attributes = &primitive->embedded_attribute;
  for (i = 0; i < n_attributes; i++)
    {
      CoglAttribute *attribute = attributes[i];
      cogl_object_ref (attribute);

      _COGL_RETURN_VAL_IF_FAIL (cogl_is_attribute (attribute), NULL);

      primitive->attributes[i] = attribute;
    }

  return _cogl_primitive_object_new (primitive);
}
static
struct PP_Var
n2p_call(void *object, struct PP_Var method_name, uint32_t argc, struct PP_Var *argv,
         struct PP_Var *exception)
{
    if (method_name.type != PP_VARTYPE_STRING) {
        trace_error("%s, method_name is not a string\n", __func__);
        // TODO: fill exception
        return PP_MakeUndefined();
    }

    struct call_param_s *p = g_slice_alloc(sizeof(*p));
    p->object =         object;
    p->method_name =    method_name;
    p->argc =           argc;
    p->argv =           argv;
    p->exception =      exception;
    p->m_loop =         ppb_message_loop_get_current();
    p->depth =          ppb_message_loop_get_depth(p->m_loop) + 1;

    ppb_message_loop_post_work_with_result(p->m_loop, PP_MakeCCB(n2p_call_comt, p), 0, PP_OK,
                                           p->depth, __func__);
    ppb_message_loop_run_nested(p->m_loop);

    struct PP_Var result = p->result;
    g_slice_free1(sizeof(*p), p);

    return result;
}
Exemple #25
0
void *moloch_size_alloc(int size, int zero)
{
    size += 8;
    void *mem = (zero?g_slice_alloc0(size):g_slice_alloc(size));
    memcpy(mem, &size, 4);
    return mem + 8;
}
Exemple #26
0
JNode *j_node_alloc(JNodeType type, gpointer data)
{
    JNode *n = (JNode *) g_slice_alloc(sizeof(JNode));
    n->type = type;
    n->data = data;
    return n;
}
static void
infinoted_plugin_manager_add_session(InfinotedPluginManager* manager,
                                     InfinotedPluginInstance* instance,
                                     const InfBrowserIter* iter,
                                     InfSessionProxy* proxy)
{
  gpointer plugin_info;
  gpointer hash;
  gpointer session_info;

  if(infinoted_plugin_manager_check_session_type(instance, proxy))
  {
    plugin_info = instance+1;
    hash = infinoted_plugin_manager_hash(plugin_info, proxy);
    g_assert(g_hash_table_lookup(manager->sessions, hash) == NULL);

    if(instance->plugin->session_info_size > 0)
    {
      session_info = g_slice_alloc(instance->plugin->session_info_size);
      g_hash_table_insert(manager->sessions, hash, session_info);
    }

    if(instance->plugin->on_session_added != NULL)
    {
      instance->plugin->on_session_added(
        iter,
        proxy,
        plugin_info,
        session_info
      );
    }
  }
}
Exemple #28
0
gpointer
g_mem_chunk_alloc (GMemChunk *mem_chunk)
{
    g_return_val_if_fail (mem_chunk != NULL, NULL);

    return g_slice_alloc (mem_chunk->alloc_size);
}
static int aes_f8_session_key_init(struct crypto_context *c) {
	unsigned char m[16];
	int i;
	int k_e_len, k_s_len; /* n_e, n_s */
	unsigned char *key;

	aes_cm_session_key_init(c);

	k_e_len = c->crypto_suite->session_key_len;
	k_s_len = c->crypto_suite->session_salt_len;
	key = (unsigned char *) c->session_key;

	/* m = k_s || 0x555..5 */
	memcpy(m, c->session_salt, k_s_len);
	for (i = k_s_len; i < k_e_len; i++)
		m[i] = 0x55;
	/* IV' = E(k_e XOR m, IV) */
	for (i = 0; i < k_e_len; i++)
		m[i] ^= key[i];

	c->session_key_ctx[1] = g_slice_alloc(sizeof(EVP_CIPHER_CTX));
	EVP_CIPHER_CTX_init(c->session_key_ctx[1]);
	EVP_EncryptInit_ex(c->session_key_ctx[1], EVP_aes_128_ecb(), NULL, m, NULL);

	return 0;
}
Exemple #30
0
struct rspamd_stat_async_elt*
rspamd_stat_ctx_register_async (rspamd_stat_async_handler handler,
		rspamd_stat_async_cleanup cleanup,
		gpointer d,
		gdouble timeout)
{
	struct rspamd_stat_async_elt *elt;
	struct rspamd_stat_ctx *st_ctx;

	st_ctx = rspamd_stat_get_ctx ();
	g_assert (st_ctx != NULL);

	elt = g_slice_alloc (sizeof (*elt));
	REF_INIT_RETAIN (elt, rspamd_async_elt_dtor);
	elt->handler = handler;
	elt->cleanup = cleanup;
	elt->ud = d;
	elt->timeout = timeout;
	/* Enabled by default */
	elt->enabled = TRUE;

	event_set (&elt->timer_ev, -1, EV_TIMEOUT, rspamd_async_elt_on_timer, elt);
	event_base_set (st_ctx->ev_base, &elt->timer_ev);
	/*
	 * First we set timeval to zero as we want cb to be executed as
	 * fast as possible
	 */
	elt->tv.tv_sec = 0;
	elt->tv.tv_usec = 0;
	event_add (&elt->timer_ev, &elt->tv);

	g_queue_push_tail (st_ctx->async_elts, elt);

	return elt;
}