<commit_before>/*
 * mpool.c, part of "klib" project.
 *
 *  Created on: 31.05.2015, 01:47
 *      Author: <NAME> <<EMAIL>>
 */

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

/*
 * mpool.pool structure:
 *
 * +---- struct _mblk ---+  allocated +---- struct _mblk ---+  allocated +---
 * |                     |   memory   |                     |    memory  |
 * +--------+-----+------+------------+--------+-----+------+------------+---
 * | 0x1515 | 0/1 | size | size_bytes | 0x1515 | 0/1 | size | size_bytes |
 * +--------+-----+------+------------+--------+-----+------+------------+---
 *      |       |      |        |
 *      |       |      |        +---- memory returned by mp_alloc()
 *      |       |      +---- block size
 *      |       +---- free/busy
 *       +---- block signature
 */

#define MP_VALID( ptr, mp ) \
    ((char *)(ptr) >= (mp)->min && \
    (char *)(ptr) <= (mp)->max && \
    (((struct _mblk *)(ptr)) - 1)->signature == MBLK_SIGNATURE)

#define MB_VALID( mb, mp ) \
    ((char *)((mb)+1) >= (mp)->min && \
    (char *)((mb)+1) <= (mp)->max && \
    (mb)->signature == MBLK_SIGNATURE)

mpool mp_create( size_t size )
{
    size_t add_size = sizeof(struct _mblk);
    mpool mp = malloc( sizeof(struct _mpool) + size + add_size );
    if( !mp ) return NULL;

    mp->flags = 0;
    mp->size = size;
    mp->min = mp->pool + sizeof(struct _mblk);
    mp->max = mp->pool + size - MBLK_MIN;
    ((mblk)mp->pool)->status = 0;<commit_msg>format<commit_after>/*
 * mpool.c, part of "klib" project.
 *
 *  Created on: 31.05.2015, 01:47
 *      Author: <NAME> <<EMAIL>>
 */

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

/*
 * mpool.pool structure:
 *
 * +---- struct _mblk ---+  allocated +---- struct _mblk ---+  allocated +---
 * |                     |   memory   |                     |    memory  |
 * +--------+-----+------+------------+--------+-----+------+------------+---
 * | 0x1515 | 0/1 | size | size_bytes | 0x1515 | 0/1 | size | size_bytes |
 * +--------+-----+------+------------+--------+-----+------+------------+---
 *      |      |     |         |
 *      |      |     |         +---- memory returned by mp_alloc()
 *      |      |     +---- block size
 *      |      +---- free/busy
 *      +---- block signature
 */

#define MP_VALID( ptr, mp ) \
    ((char *)(ptr) >= (mp)->min && \
    (char *)(ptr) <= (mp)->max && \
    (((struct _mblk *)(ptr)) - 1)->signature == MBLK_SIGNATURE)

#define MB_VALID( mb, mp ) \
    ((char *)((mb)+1) >= (mp)->min && \
    (char *)((mb)+1) <= (mp)->max && \
    (mb)->signature == MBLK_SIGNATURE)

mpool mp_create( size_t size )
{
    size_t add_size = sizeof(struct _mblk);
    mpool mp = malloc( sizeof(struct _mpool) + size + add_size );
    if( !mp ) return NULL;

    mp->flags = 0;
    mp->size = size;
    mp->min = mp->pool + sizeof(struct _mblk);
    mp->max = mp->pool + size - MBLK_MIN;
    ((mblk)mp->pool)->status = 0;
{'fraction_non_alphanumeric': 0.29202623403520883, 'fraction_numerical': 0.021401449775629963, 'mean_word_length': 1.4009942004971003, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 43, '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': '427534', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1027, 'n_words': 207}