<commit_before>#include <gojira/config.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>

#if GOJIRA_ENABLE_FILES
#include <gojira/runtime/runtime.h>
#include <gojira/runtime/garbage.h>
#include <gojira/runtime/builtin.h>
#include <gojira/runtime/printer.h>
#include <gojira/runtime/files.h>
#include <gojira/parse_debug.h>

// needed because fclose() technically doesn't match the type specification
// of shared_dtor, which requres a void return
static void free_file( void *ptr ){
	if ( ptr ){
		fclose( (FILE *)ptr );
		printf( "got here\n" );
	}
}

token_t *builtin_open( stack_frame_t *frame ){
	token_t *ret = NULL;
	char *fname;
	char *mode;
	FILE *fp;

	if ( frame->ntokens >= 3 ){
		if ( frame->expr->next->type == TYPE_STRING ){
			fname = shared_get( frame->expr->next->data );

			if ( frame->expr->next->next->type == TYPE_STRING ){
				mode = shared_get( frame->expr->next->next->data );

				if (( fp = fopen( fname, mode ))){
					ret = alloc_token( );
					ret->type  = TYPE_FILE;
					ret->flags = T_FLAG_HAS_SHARED;
					ret->data  = shared_new( fp, free_file );
<commit_msg>Changing printf in free_file into a debugging statement<commit_after>#include <gojira/config.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>

#if GOJIRA_ENABLE_FILES
#include <gojira/runtime/runtime.h>
#include <gojira/runtime/garbage.h>
#include <gojira/runtime/builtin.h>
#include <gojira/runtime/printer.h>
#include <gojira/runtime/files.h>
#include <gojira/parse_debug.h>

// needed because fclose() technically doesn't match the type specification
// of shared_dtor, which requres a void return
static void free_file( void *ptr ){
	if ( ptr ){
		DEBUGP( "[%s] Closing file at %p\n", __func__, ptr );
		fclose( (FILE *)ptr );
	}
}

token_t *builtin_open( stack_frame_t *frame ){
	token_t *ret = NULL;
	char *fname;
	char *mode;
	FILE *fp;

	if ( frame->ntokens >= 3 ){
		if ( frame->expr->next->type == TYPE_STRING ){
			fname = shared_get( frame->expr->next->data );

			if ( frame->expr->next->next->type == TYPE_STRING ){
				mode = shared_get( frame->expr->next->next->data );

				if (( fp = fopen( fname, mode ))){
					ret = alloc_token( );
					ret->type  = TYPE_FILE;
					ret->flags = T_FLAG_HAS_SHARED;
					ret->data  = shared_new( fp, free_file );

{'fraction_non_alphanumeric': 0.16137339055793992, 'fraction_numerical': 0.0008583690987124463, 'mean_word_length': 3.9073684210526314, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 63, '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': '7031508', 'n_tokens_mistral': 940, 'n_tokens_neox': 871, 'n_words': 204}