<commit_before>#include <stdlib.h>

#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>

// arguments:
// 1. row
// 2. orig
static int lua_unwind_row(lua_State *L) {
    size_t row_size, orig_size;
    const char* row = luaL_checklstring(L, 1, &row_size);
    const char* orig = luaL_checklstring(L, 2, &orig_size);
    luaL_argcheck(L, row_size >= orig_size, 1,
            "Length of row on consensus must be >= "
            "length of row on original sequence");
    char* result = malloc(row_size);
    int orig_i = 0;
    int i;
    for (i = 0; i < row_size; i++) {
        char c = row[i];
        if (c == '-') {
            result[i] = '-';
        } else {
            luaL_argcheck(L, orig_i < orig_size, 2,
                "Length of original row is not sufficient");
            result[i] = orig[orig_i];
            orig_i += 1;
        }
    }
    luaL_argcheck(L, orig_i == orig_size, 2,
        "Original row is too long");
    lua_pushlstring(L, result, row_size);
    free(result);
    return 1;
}

int luaopen_npge_alignment_cunwind_row(
        lua_State *L) {
    lua_pushcfunction(L, lua_unwind_row);
    return 1;
}<commit_msg>unwind_row.c: do not use malloc<commit_after>#define LUA_LIB
#include <lua.h>
#include <lauxlib.h>

// arguments:
// 1. row
// 2. orig
static int lua_unwind_row(lua_State *L) {
    size_t row_size, orig_size;
    const char* row = luaL_checklstring(L, 1, &row_size);
    const char* orig = luaL_checklstring(L, 2, &orig_size);
    luaL_argcheck(L, row_size >= orig_size, 1,
            "Length of row on consensus must be >= "
            "length of row on original sequence");
    char* result = lua_newuserdata(L, row_size);
    int orig_i = 0;
    int i;
    for (i = 0; i < row_size; i++) {
        char c = row[i];
        if (c == '-') {
            result[i] = '-';
        } else {
            luaL_argcheck(L, orig_i < orig_size, 2,
                "Length of original row is not sufficient");
            result[i] = orig[orig_i];
            orig_i += 1;
        }
    }
    luaL_argcheck(L, orig_i == orig_size, 2,
        "Original row is too long");
    lua_pushlstring(L, result, row_size);
    return 1;
}

int luaopen_npge_alignment_cunwind_row(
        lua_State *L) {
    lua_pushcfunction(L, lua_unwind_row);
    return 1;
}
{'fraction_non_alphanumeric': 0.1279930343926861, 'fraction_numerical': 0.01044841097083152, 'mean_word_length': 2.292263610315186, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '6696213', 'n_tokens_mistral': 886, 'n_tokens_neox': 830, 'n_words': 218}