<commit_before>#ifndef LIP_MEMORY_H
#define LIP_MEMORY_H

#include "common.h"

#define LIP_ALIGN_OF(TYPE) offsetof(struct { char c; TYPE t;}, t)
#define lip_new(ALLOCATOR, TYPE) (TYPE*)(lip_malloc(ALLOCATOR, sizeof(TYPE)))
#define LIP_ARRAY_BLOCK(TYPE, LENGTH) \
	{ \
		.element_size = sizeof(TYPE), \
		.num_elements = LENGTH, \
		.alignment = LIP_ALIGN_OF(TYPE) \
	}
#define LIP_STATIC_ARRAY_LEN(ARRAY) (sizeof((ARRAY)) / sizeof((ARRAY)[0]))

typedef struct lip_memblock_info_s lip_memblock_info_t;

struct lip_allocator_s
{
	void*(*realloc)(void* self, void* old, size_t size);
	void(*free)(void* self, void* mem);
};

struct lip_memblock_info_s
{
	size_t element_size;
	size_t num_elements;
	uint8_t alignment;
	ptrdiff_t offset;
};

extern lip_allocator_t* lip_default_allocator;

lip_memblock_info_t
lip_align_memblocks(unsigned int num_blocks, lip_memblock_info_t** blocks);

LIP_MAYBE_UNUSED static inline void*
lip_locate_memblock(void* base, lip_memblock_info_t* block)
{
	return (char*)base + block->offset;
}

LIP_MAYBE_UNUSED static inline void*
lip_realloc(lip_allocator_t* allocator, void* ptr, size_t size)
{
	return allocator->realloc(allocator, ptr, size);
}

LIP_MAYBE_UNUSED static inline void*
lip_malloc(lip_allocator_t* allocator, size_t size)
{
	return lip_realloc(allocator, 0, size);
}

LIP_MAYBE_UNUSED static inline void
lip_free(lip_allocator_t* allocator, void* ptr)
{
	allocator->free(allocator, ptr);
}

LIP_MAYBE_UNUSED static inline void*
lip_align_ptr(void* ptr, size_t alignment)
{
	ptrdiff_t rem = (uintptr_t)ptr % alignment;
	ptrdiff_t shift = alignment - rem;
	return (char*)ptr + (rem == 0 ? 0 : shift);
}

#endif<commit_msg>Simplify lip_align_ptr<commit_after>#ifndef LIP_MEMORY_H
#define LIP_MEMORY_H

#include "common.h"

#define LIP_ALIGN_OF(TYPE) offsetof(struct { char c; TYPE t;}, t)
#define lip_new(ALLOCATOR, TYPE) (TYPE*)(lip_malloc(ALLOCATOR, sizeof(TYPE)))
#define LIP_ARRAY_BLOCK(TYPE, LENGTH) \
	{ \
		.element_size = sizeof(TYPE), \
		.num_elements = LENGTH, \
		.alignment = LIP_ALIGN_OF(TYPE) \
	}
#define LIP_STATIC_ARRAY_LEN(ARRAY) (sizeof((ARRAY)) / sizeof((ARRAY)[0]))

typedef struct lip_memblock_info_s lip_memblock_info_t;

struct lip_allocator_s
{
	void*(*realloc)(void* self, void* old, size_t size);
	void(*free)(void* self, void* mem);
};

struct lip_memblock_info_s
{
	size_t element_size;
	size_t num_elements;
	uint8_t alignment;
	ptrdiff_t offset;
};

extern lip_allocator_t* lip_default_allocator;

lip_memblock_info_t
lip_align_memblocks(unsigned int num_blocks, lip_memblock_info_t** blocks);

LIP_MAYBE_UNUSED static inline void*
lip_locate_memblock(void* base, lip_memblock_info_t* block)
{
	return (char*)base + block->offset;
}

LIP_MAYBE_UNUSED static inline void*
lip_realloc(lip_allocator_t* allocator, void* ptr, size_t size)
{
	return allocator->realloc(allocator, ptr, size);
}

LIP_MAYBE_UNUSED static inline void*
lip_malloc(lip_allocator_t* allocator, size_t size)
{
	return lip_realloc(allocator, 0, size);
}

LIP_MAYBE_UNUSED static inline void
lip_free(lip_allocator_t* allocator, void* ptr)
{
	allocator->free(allocator, ptr);
}

LIP_MAYBE_UNUSED static inline void*
lip_align_ptr(void* ptr, size_t alignment)
{
	return (void*)(((uintptr_t)ptr + alignment - 1) / alignment * alignment);
}

#endif
{'fraction_non_alphanumeric': 0.11648418491484185, 'fraction_numerical': 0.002737226277372263, 'mean_word_length': 6.702576112412178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2592516', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1290, 'n_words': 266}