Ejemplo n.º 1
0
static void
AutoEngSetBuffLen(FcitxAutoEngState *autoEngState, size_t len)
{
    unsigned int size = fcitx_utils_align_to(len + 1, MAX_USER_INPUT);
    if (autoEngState->buff_size != size) {
        autoEngState->buf = realloc(autoEngState->buf, size);
        autoEngState->buff_size = size;
    }
    autoEngState->buf[len] = '\0';
    autoEngState->auto_space = false;
}
Ejemplo n.º 2
0
FCITX_EXPORT_API
void
fcitx_obj_pool_init_with_prealloc(FcitxObjPool* pool, size_t size,
                                  size_t prealloc)
{
    size = fcitx_utils_align_to(size + sizeof(int), sizeof(int));
    pool->ele_size = size;
    pool->next_free = 0;
    pool->alloc = size * prealloc;
    pool->array = malloc(pool->alloc);

    size_t offset = 0;
    unsigned int i = 0;
    for (offset = 0, i = 0; i < prealloc - 1; offset += size, i++) {
        *(int*)(pool->array + offset) = i + 1;
    }
    *(int*)(pool->array + offset) = FCITX_OBJECT_POOL_INVALID_ID;
}