Beispiel #1
0
int		parse_header(int fd_src, t_parser *parser,
                             header_t *header, int *size)
{
  char		*line;

  reset_str(header->comment, COMMENT_LENGTH + 1);
  if ((line = get_next_size(fd_src, parser, size)) == NULL)
    return (1);
  if (parse_header_line(line, NAME_CMD_STRING, header->prog_name) == 1)
  {
    syntax_error(parser->line_nb);
    return (1);
  }
  free(line);
  header->prog_size = 0;
  if ((line = get_next_size(fd_src, parser, size)) == NULL)
    return (1);
  if (parse_header_line(line, COMMENT_CMD_STRING, header->comment) == 1)
  {
    syntax_error(parser->line_nb);
    return (1);
  }
  free(line);
  return (0);
}
Beispiel #2
0
static GstFlowReturn
gst_chop_my_data_process (GstChopMyData * chopmydata, gboolean flush)
{
  GstFlowReturn ret = GST_FLOW_OK;
  GstBuffer *buffer;

  if (chopmydata->next_size == 0) {
    get_next_size (chopmydata);
  }

  while (gst_adapter_available (chopmydata->adapter) >= chopmydata->next_size) {
    buffer =
        gst_adapter_take_buffer (chopmydata->adapter, chopmydata->next_size);

    chopmydata->next_size = 0;

    ret = gst_pad_push (chopmydata->srcpad, buffer);
    if (ret != GST_FLOW_OK) {
      return ret;
    }

    get_next_size (chopmydata);
  }

  if (flush) {
    buffer = gst_adapter_take_buffer (chopmydata->adapter,
        gst_adapter_available (chopmydata->adapter));
    ret = gst_pad_push (chopmydata->srcpad, buffer);
  }

  return ret;
}
static GstFlowReturn
gst_chop_my_data_process (GstChopMyData * chopmydata, gboolean flush)
{
  GstFlowReturn ret = GST_FLOW_OK;
  GstBuffer *buffer;

  if (chopmydata->next_size == 0) {
    get_next_size (chopmydata);
  }

  while (gst_adapter_available (chopmydata->adapter) >= chopmydata->next_size) {
    buffer =
        gst_adapter_take_buffer (chopmydata->adapter, chopmydata->next_size);

    GST_BUFFER_PTS (buffer) = gst_adapter_prev_pts (chopmydata->adapter, NULL);
    GST_BUFFER_DTS (buffer) = gst_adapter_prev_dts (chopmydata->adapter, NULL);

    chopmydata->next_size = 0;

    ret = gst_pad_push (chopmydata->srcpad, buffer);
    if (ret != GST_FLOW_OK) {
      return ret;
    }

    get_next_size (chopmydata);
  }

  if (flush) {
    guint min_size = chopmydata->min_size;

    while (gst_adapter_available (chopmydata->adapter) >= min_size) {
      buffer = gst_adapter_take_buffer (chopmydata->adapter, min_size);
      ret = gst_pad_push (chopmydata->srcpad, buffer);
      if (ret != GST_FLOW_OK)
        break;
    }
    gst_adapter_clear (chopmydata->adapter);
  }

  return ret;
}
Beispiel #4
0
/**
 * mono_mempool_alloc:
 * \param pool the memory pool to use
 * \param size size of the memory block
 *
 * Allocates a new block of memory in \p pool .
 *
 * \returns the address of a newly allocated memory block.
 */
gpointer
(mono_mempool_alloc) (MonoMemPool *pool, guint size)
{
	gpointer rval = pool->pos; // Return value

	// Normal case: Just bump up pos pointer and we are done
	size = ALIGN_SIZE (size);
	pool->pos = (guint8*)rval + size;

#ifdef TRACE_ALLOCATIONS
	if (pool == mono_get_corlib ()->mempool) {
		mono_backtrace (size);
	}
#endif

	// If we have just overflowed the current block, we need to back up and try again.
	if (G_UNLIKELY (pool->pos >= pool->end)) {
		pool->pos -= size;  // Back out

		// For large objects, allocate the object into its own block.
		// (In individual allocation mode, the constant will be 0 and this path will always be taken)
		if (size >= MONO_MEMPOOL_PREFER_INDIVIDUAL_ALLOCATION_SIZE) {
			guint new_size = SIZEOF_MEM_POOL + size;
			MonoMemPool *np = (MonoMemPool *)g_malloc (new_size);

			np->next = pool->next;
			np->size = new_size;
			pool->next = np;
			pool->d.allocated += new_size;
			UnlockedAdd64 (&total_bytes_allocated, new_size);

			rval = (guint8*)np + SIZEOF_MEM_POOL;
		} else {
			// Notice: any unused memory at the end of the old head becomes simply abandoned in this case until the mempool is freed (see Bugzilla #35136)
			guint new_size = get_next_size (pool, size);
			MonoMemPool *np = (MonoMemPool *)g_malloc (new_size);

			np->next = pool->next;
			np->size = new_size;
			pool->next = np;
			pool->pos = (guint8*)np + SIZEOF_MEM_POOL;
			pool->end = (guint8*)np + new_size;
			pool->d.allocated += new_size;
			UnlockedAdd64 (&total_bytes_allocated, new_size);

			rval = pool->pos;
			pool->pos += size;
		}
	}

	return rval;
}
Beispiel #5
0
/**
 * mono_mempool_alloc:
 * @pool: the momory pool to use
 * @size: size of the momory block
 *
 * Allocates a new block of memory in @pool.
 *
 * Returns: the address of a newly allocated memory block.
 */
gpointer
mono_mempool_alloc (MonoMemPool *pool, guint size)
{
	gpointer rval;
	
	size = (size + MEM_ALIGN - 1) & ~(MEM_ALIGN - 1);

#ifdef MALLOC_ALLOCATION
	{
		Chunk *c = g_malloc (size);

		c->next = pool->chunks;
		pool->chunks = c;
		c->size = size - sizeof(Chunk);

		pool->allocated += size;

		rval = ((guint8*)c) + sizeof (Chunk);
	}
#else
	rval = pool->pos;
	pool->pos = (guint8*)rval + size;

#ifdef TRACE_ALLOCATIONS
	if (pool == mono_get_corlib ()->mempool) {
		mono_backtrace (size);
	}
#endif
	if (G_UNLIKELY (pool->pos >= pool->end)) {
		pool->pos -= size;
		if (size >= 4096) {
			MonoMemPool *np = g_malloc (sizeof (MonoMemPool) + size);
			np->next = pool->next;
			pool->next = np;
			np->pos = (guint8*)np + sizeof (MonoMemPool);
			np->size = sizeof (MonoMemPool) + size;
			np->end = np->pos + np->size - sizeof (MonoMemPool);
			pool->d.allocated += sizeof (MonoMemPool) + size;
			total_bytes_allocated += sizeof (MonoMemPool) + size;
			return (guint8*)np + sizeof (MonoMemPool);
		} else {
			int new_size = get_next_size (pool, size);
			MonoMemPool *np = g_malloc (new_size);
			np->next = pool->next;
			pool->next = np;
			pool->pos = (guint8*)np + sizeof (MonoMemPool);
			np->pos = (guint8*)np + sizeof (MonoMemPool);
			np->size = new_size;
			np->end = np->pos;
			pool->end = pool->pos + new_size - sizeof (MonoMemPool);
			pool->d.allocated += new_size;
			total_bytes_allocated += new_size;

			rval = pool->pos;
			pool->pos += size;
		}
	}
#endif

	return rval;
}