<commit_before>#include <stdlib.h>

#include "gc.h"
#include "value.h"
#include "stack.h"

Stack* new_stack()
{
	Stack* nstack = malloc(sizeof(Stack));
	nstack->size = 0;
	nstack->head = NULL;
	return nstack;
}

void copy_stack(Stack *old, Stack *new)
{
	Node *cur = old->head;
	Node **to = &new->head;
	while (cur != NULL)
	{
		*to = malloc(sizeof(Node));
		(*to)->data = cur->data;
		cur = cur->next;
		to = &(*to)->next;
	}
	*to = NULL;
	new->size = old->size;
}

void push(Stack *stack, V v)
{
	Node *new_node = malloc(sizeof(Node));
	if (new_node != NULL)
	{
		new_node->data = v;
		new_node->next = (stack->size++ > 0) ? stack->head : NULL;
		stack->head = new_node;
	}
}

V pop(Stack *stack)
{
	if (stack->size > 0)
	{
		Node *top = stack->head;
		V v = top->data;
		stack->size--;
		stack->head = top->next;
		free(top);<commit_msg>Fixes bug in copy not adding new references<commit_after>#include <stdlib.h>

#include "gc.h"
#include "value.h"
#include "stack.h"

Stack* new_stack()
{
	Stack* nstack = malloc(sizeof(Stack));
	nstack->size = 0;
	nstack->head = NULL;
	return nstack;
}

void copy_stack(Stack *old, Stack *new)
{
	Node *cur = old->head;
	Node **to = &new->head;
	while (cur != NULL)
	{
		*to = malloc(sizeof(Node));
		(*to)->data = add_ref(cur->data);
		cur = cur->next;
		to = &(*to)->next;
	}
	*to = NULL;
	new->size = old->size;
}

void push(Stack *stack, V v)
{
	Node *new_node = malloc(sizeof(Node));
	if (new_node != NULL)
	{
		new_node->data = v;
		new_node->next = (stack->size++ > 0) ? stack->head : NULL;
		stack->head = new_node;
	}
}

V pop(Stack *stack)
{
	if (stack->size > 0)
	{
		Node *top = stack->head;
		V v = top->data;
		stack->size--;
		stack->head = top->next;
		free(top);
{'fraction_non_alphanumeric': 0.20709714950552646, 'fraction_numerical': 0.0034904013961605585, 'mean_word_length': 3.4559585492227978, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3888981', 'n_tokens_mistral': 759, 'n_tokens_neox': 720, 'n_words': 168}