Sha256: e6ce3a82bd96996b4800d7d2fba8bc5eb0dbc34c96472c17961ebebf01003ac4

Contents?: true

Size: 945 Bytes

Versions: 12

Compression:

Stored size: 945 Bytes

Contents

#include "stack.h"
#include <string.h>

int
redcarpet_stack_grow(struct stack *st, size_t new_size)
{
	void **new_st;

	if (st->asize >= new_size)
		return 0;

	new_st = realloc(st->item, new_size * sizeof(void *));
	if (new_st == NULL)
		return -1;

	memset(new_st + st->asize, 0x0,
		(new_size - st->asize) * sizeof(void *));

	st->item = new_st;
	st->asize = new_size;

	if (st->size > new_size)
		st->size = new_size;

	return 0;
}

void
redcarpet_stack_free(struct stack *st)
{
	if (!st)
		return;

	free(st->item);

	st->item = NULL;
	st->size = 0;
	st->asize = 0;
}

int
redcarpet_stack_init(struct stack *st, size_t initial_size)
{
	st->item = NULL;
	st->size = 0;
	st->asize = 0;

	if (!initial_size)
		initial_size = 8;

	return redcarpet_stack_grow(st, initial_size);
}

int
redcarpet_stack_push(struct stack *st, void *item)
{
	if (redcarpet_stack_grow(st, st->size * 2) < 0)
		return -1;

	st->item[st->size++] = item;
	return 0;
}

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
redcarpet-3.3.2 ext/redcarpet/stack.c
redcarpet-3.3.1 ext/redcarpet/stack.c
redcarpet-3.3.0 ext/redcarpet/stack.c
redcarpet-3.2.3 ext/redcarpet/stack.c
tight-redcarpet-3.2.0 ext/redcarpet/stack.c
redcarpet-3.2.2 ext/redcarpet/stack.c
redcarpet-3.2.1 ext/redcarpet/stack.c
redcarpet-3.2.0 ext/redcarpet/stack.c
tight-redcarpet-3.1.1 ext/redcarpet/stack.c
redcarpet-3.1.2 ext/redcarpet/stack.c
redcarpet-3.1.1 ext/redcarpet/stack.c
redcarpet-3.1.0 ext/redcarpet/stack.c