~siborgium/sregex-streaming-api

c53b39b45d3b6a3eeb4af82035a32ff42446d7fd — Sergey Smirnykh 2 years ago fcedad9
Some fixes:
 - explicitly set C standard to C99
 - use malloc/realloc to allocate initial states
 - add sre_vm_pike_free to avoid leaks
 - use aligned_alloc if C11 is avaliable
4 files changed, 13 insertions(+), 0 deletions(-)

M CMakeLists.txt
M include/sregex/sregex.h
M src/sregex/sre_palloc.c
M src/sregex/sre_vm_pike.c
M CMakeLists.txt => CMakeLists.txt +1 -0
@@ 1,5 1,6 @@
cmake_minimum_required(VERSION 3.2.0)
project(Sregex)
set (CMAKE_C_STANDARD 99)

set (INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set (SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)

M include/sregex/sregex.h => include/sregex/sregex.h +1 -0
@@ 134,6 134,7 @@ SRE_API sre_vm_pike_ctx_t *sre_vm_pike_create_ctx(sre_pool_t *pool,
SRE_API sre_int_t sre_vm_pike_exec(sre_vm_pike_ctx_t *ctx, sre_char *input,
    size_t len, unsigned eof, sre_int_t **pending_matched);

SRE_API void sre_vm_pike_free (sre_vm_pike_ctx_t *ctx);

/* the Thompson VM API */


M src/sregex/sre_palloc.c => src/sregex/sre_palloc.c +5 -0
@@ 6,6 6,7 @@

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h> // posix_memalign

#ifndef DDEBUG
#define DDEBUG 0


@@ 368,6 369,7 @@ sre_pool_cleanup_add(sre_pool_t *p, size_t size)
static void *
sre_memalign(size_t alignment, size_t size)
{
#ifndef _ISOC11_SOURCE
    void  *p;
    int    err;



@@ 378,5 380,8 @@ sre_memalign(size_t alignment, size_t size)
    }

    return p;
#else
    return aligned_alloc(alignment, size);
#endif
}
#endif

M src/sregex/sre_vm_pike.c => src/sregex/sre_vm_pike.c +6 -0
@@ 714,6 714,12 @@ step_done:
    return SRE_AWAIT;
}

void sre_vm_pike_free (sre_vm_pike_ctx_t *ctx) {
    if (ctx->initial_states) {
        free (ctx->initial_states);
    }
}


static void
sre_vm_pike_prepare_temp_captures(sre_program_t *prog, sre_vm_pike_ctx_t *ctx)