<commit_before>// LaminaFS is Copyright (c) 2016 <NAME>
// See LICENSE for license information.

#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "FileContext.h"

#if !defined(LAMINAFS_DISABLE_DIRECTORY_DEVICE)
#include "device/Directory.h"
#endif

#include <algorithm>
#include <atomic>
#include <string.h>
#include <stdlib.h>

#ifdef __linux__
#include <malloc.h>
#endif

using namespace laminaFS;

#define LOG(MSG,...) if (_log) { _log(MSG, ##__VA_ARGS__); }

enum lfs_file_operation_t {
	LFS_OP_EXISTS,
	LFS_OP_SIZE,
	LFS_OP_READ,
	LFS_OP_WRITE,
	LFS_OP_APPEND,
	LFS_OP_DELETE,
	LFS_OP_CREATE_DIR,
	LFS_OP_DELETE_DIR,
};

struct lfs_work_item_t {
	lfs_file_operation_t _operation;
	lfs_work_item_callback_t _callback = nullptr;
	void *_callbackUserData = nullptr;
	lfs_allocator_t _allocator;

	char *_filename = nullptr;

	void *_buffer = nullptr;
	uint64_t _bufferBytes = 0;

	lfs_error_code_t _resultCode = LFS_OK;
	bool _nullTerminate = false;
	std::atomic<bool> _completed;
};

void *default_alloc_func(void *, size_t bytes, size_t alignment) {
#ifdef _WIN32
	return _aligned_malloc(bytes, alignment);
#else
	return memalign(alignment, bytes);
#endif
}

void default_free_func(void *, void *ptr) {
#ifdef _WIN32
	_aligned_free(ptr);
#else
	free(ptr);
#endif
}

extern "C" {
	lfs_allocator_t lfs_default_allocator = { default_alloc_func, default_free_func, nullptr };
}
<commit_msg>Working allocation for macOS.<commit_after>// LaminaFS is Copyright (c) 2016 <NAME>
// See LICENSE for license information.

#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "FileContext.h"

#if !defined(LAMINAFS_DISABLE_DIRECTORY_DEVICE)
#include "device/Directory.h"
#endif

#include <algorithm>
#include <atomic>
#include <string.h>
#include <stdlib.h>

#ifdef __linux__
#include <malloc.h>
#endif

using namespace laminaFS;

#define LOG(MSG,...) if (_log) { _log(MSG, ##__VA_ARGS__); }

enum lfs_file_operation_t {
	LFS_OP_EXISTS,
	LFS_OP_SIZE,
	LFS_OP_READ,
	LFS_OP_WRITE,
	LFS_OP_APPEND,
	LFS_OP_DELETE,
	LFS_OP_CREATE_DIR,
	LFS_OP_DELETE_DIR,
};

struct lfs_work_item_t {
	lfs_file_operation_t _operation;
	lfs_work_item_callback_t _callback = nullptr;
	void *_callbackUserData = nullptr;
	lfs_allocator_t _allocator;

	char *_filename = nullptr;

	void *_buffer = nullptr;
	uint64_t _bufferBytes = 0;

	lfs_error_code_t _resultCode = LFS_OK;
	bool _nullTerminate = false;
	std::atomic<bool> _completed;
};

void *default_alloc_func(void *, size_t bytes, size_t alignment) {
#ifdef _WIN32
	return _aligned_malloc(bytes, alignment);
#elif __APPLE__
	void *ptr = nullptr;
	// XXX: macOS requires sizeof(void*)  multiples for alignment
	size_t aligned_alignment = (alignment + sizeof(void*) - 1) & (~(sizeof(void*) - 1));
	posix_memalign(&ptr, aligned_alignment, bytes);
	return ptr;
#else
	return memalign(alignment, bytes);
#endif
}

void default_free_func(void *, void *ptr) {
#ifdef _WIN32
	_aligned_free(ptr);
#else
	free(ptr);
#endif
}

extern "C" {
	lfs_allocator_t lfs_default_allocator = { default_alloc_func, default_free_func, nullptr };
}

{'fraction_non_alphanumeric': 0.10966482264887732, 'fraction_numerical': 0.009111617312072893, 'mean_word_length': 6.0504587155963305, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6772436', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1186, 'n_words': 263}