gem intead of hawk in tre
This commit is contained in:
parent
40d8800dab
commit
c25b251efc
@ -208,11 +208,10 @@ extern "C" {
|
||||
* \return #hawk_pio_t object on success, #HAWK_NULL on failure
|
||||
*/
|
||||
HAWK_EXPORT hawk_pio_t* hawk_pio_open (
|
||||
hawk_gem_t* gem, /**< hawk */
|
||||
hawk_gem_t* gem, /**< gem */
|
||||
hawk_oow_t ext, /**< extension size */
|
||||
const hawk_ooch_t* cmd, /**< command to execute */
|
||||
int flags /**< 0 or a number OR'ed of the
|
||||
#hawk_pio_flag_t enumerators*/
|
||||
int flags /**< 0 or a number OR'ed of the #hawk_pio_flag_t enumerators*/
|
||||
);
|
||||
|
||||
/**
|
||||
@ -231,10 +230,9 @@ HAWK_EXPORT void hawk_pio_close (
|
||||
*/
|
||||
HAWK_EXPORT int hawk_pio_init (
|
||||
hawk_pio_t* pio, /**< pio object */
|
||||
hawk_gem_t* gem, /**< hawk */
|
||||
hawk_gem_t* gem, /**< gem */
|
||||
const hawk_ooch_t* cmd, /**< command to execute */
|
||||
int flags /**< 0 or a number OR'ed of the
|
||||
#hawk_pio_flag_t enumerators*/
|
||||
int flags /**< 0 or a number OR'ed of the #hawk_pio_flag_t enumerators*/
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ typedef struct hawk_pma_t hawk_pma_t;
|
||||
|
||||
struct hawk_pma_t
|
||||
{
|
||||
hawk_t* hawk;
|
||||
hawk_gem_t* gem;
|
||||
|
||||
hawk_pma_blk_t* blocks;
|
||||
hawk_pma_blk_t* current;
|
||||
@ -79,8 +79,8 @@ extern "C" {
|
||||
* The hawk_pma_open() function creates a pool-based memory allocator.
|
||||
*/
|
||||
HAWK_EXPORT hawk_pma_t* hawk_pma_open (
|
||||
hawk_t* hawk, /**< hawk */
|
||||
hawk_oow_t xtnsize /**< extension size in bytes */
|
||||
hawk_gem_t* gem, /**< gem */
|
||||
hawk_oow_t xtnsize /**< extension size in bytes */
|
||||
);
|
||||
|
||||
/**
|
||||
@ -92,7 +92,7 @@ HAWK_EXPORT void hawk_pma_close (
|
||||
|
||||
HAWK_EXPORT int hawk_pma_init (
|
||||
hawk_pma_t* pma, /**< memory allocator */
|
||||
hawk_t* hawk /**< hawk */
|
||||
hawk_gem_t* gem /**< gem */
|
||||
);
|
||||
|
||||
HAWK_EXPORT void hawk_pma_fini (
|
||||
@ -139,7 +139,7 @@ HAWK_EXPORT void* hawk_pma_calloc (
|
||||
HAWK_EXPORT void* hawk_pma_realloc (
|
||||
hawk_pma_t* pma, /**< memory allocator */
|
||||
void* blk, /**< memory block */
|
||||
hawk_oow_t size /**< new size in bytes */
|
||||
hawk_oow_t size /**< new size in bytes */
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -56,7 +56,7 @@ typedef enum hawk_tre_errnum_t hawk_tre_errnum_t;
|
||||
typedef struct hawk_tre_t hawk_tre_t;
|
||||
struct hawk_tre_t
|
||||
{
|
||||
hawk_t* hawk;
|
||||
hawk_gem_t* gem;
|
||||
hawk_tre_errnum_t errnum;
|
||||
|
||||
hawk_oow_t re_nsub; /* Number of parenthesized subexpressions. */
|
||||
@ -109,7 +109,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
HAWK_EXPORT hawk_tre_t* hawk_tre_open (
|
||||
hawk_t* hawk,
|
||||
hawk_gem_t* gem,
|
||||
hawk_oow_t xtnsize
|
||||
);
|
||||
|
||||
@ -119,7 +119,7 @@ HAWK_EXPORT void hawk_tre_close (
|
||||
|
||||
HAWK_EXPORT int hawk_tre_init (
|
||||
hawk_tre_t* tre,
|
||||
hawk_t* hawk
|
||||
hawk_gem_t* gem
|
||||
);
|
||||
|
||||
HAWK_EXPORT void hawk_tre_fini (
|
||||
|
@ -503,7 +503,7 @@ int hawk_buildrex (
|
||||
|
||||
if (code)
|
||||
{
|
||||
tre = hawk_tre_open(awk, 0);
|
||||
tre = hawk_tre_open(hawk_getgem(awk), 0);
|
||||
if (tre == HAWK_NULL)
|
||||
{
|
||||
*errnum = HAWK_ENOMEM;
|
||||
@ -529,7 +529,7 @@ int hawk_buildrex (
|
||||
|
||||
if (icode)
|
||||
{
|
||||
itre = hawk_tre_open(awk, 0);
|
||||
itre = hawk_tre_open(hawk_getgem(awk), 0);
|
||||
if (itre == HAWK_NULL)
|
||||
{
|
||||
if (tre) hawk_tre_close (tre);
|
||||
|
@ -53,16 +53,16 @@
|
||||
(HAWK_SIZEOF(type) - (((hawk_uintptr_t)ptr) % HAWK_SIZEOF(type))) : 0)
|
||||
|
||||
|
||||
hawk_pma_t* hawk_pma_open (hawk_t* hawk, hawk_oow_t xtnsize)
|
||||
hawk_pma_t* hawk_pma_open (hawk_gem_t* gem, hawk_oow_t xtnsize)
|
||||
{
|
||||
hawk_pma_t* pma;
|
||||
|
||||
pma = (hawk_pma_t*)hawk_allocmem(hawk, HAWK_SIZEOF(*pma) + xtnsize);
|
||||
pma = (hawk_pma_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(*pma) + xtnsize);
|
||||
if (!pma) return HAWK_NULL;
|
||||
|
||||
if (hawk_pma_init(pma, hawk) <= -1)
|
||||
if (hawk_pma_init(pma, gem) <= -1)
|
||||
{
|
||||
hawk_freemem (hawk, pma);
|
||||
hawk_gem_freemem (gem, pma);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
@ -73,13 +73,13 @@ hawk_pma_t* hawk_pma_open (hawk_t* hawk, hawk_oow_t xtnsize)
|
||||
void hawk_pma_close (hawk_pma_t* pma)
|
||||
{
|
||||
hawk_pma_fini (pma);
|
||||
hawk_freemem (pma->hawk, pma);
|
||||
hawk_gem_freemem (pma->gem, pma);
|
||||
}
|
||||
|
||||
int hawk_pma_init (hawk_pma_t* pma, hawk_t* hawk)
|
||||
int hawk_pma_init (hawk_pma_t* pma, hawk_gem_t* gem)
|
||||
{
|
||||
HAWK_MEMSET (pma, 0, HAWK_SIZEOF(*pma));
|
||||
pma->hawk = hawk;
|
||||
pma->gem = gem;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -91,18 +91,18 @@ void hawk_pma_fini (hawk_pma_t* pma)
|
||||
|
||||
void hawk_pma_clear (hawk_pma_t* pma)
|
||||
{
|
||||
hawk_t* hawk = pma->hawk;
|
||||
hawk_t* gem = pma->gem;
|
||||
hawk_pma_blk_t* tmp, * l = pma->blocks;
|
||||
|
||||
while (l != HAWK_NULL)
|
||||
{
|
||||
tmp = l->next;
|
||||
hawk_freemem (hawk, l);
|
||||
hawk_gem_freemem (gem, l);
|
||||
l = tmp;
|
||||
}
|
||||
|
||||
HAWK_MEMSET (pma, 0, HAWK_SIZEOF(*pma));
|
||||
pma->hawk = hawk;
|
||||
pma->gem = gem;
|
||||
}
|
||||
/* Returns a new memory allocator or NULL if out of memory. */
|
||||
|
||||
@ -126,7 +126,7 @@ void* hawk_pma_alloc (hawk_pma_t* pma, hawk_oow_t size)
|
||||
else
|
||||
block_size = HAWK_PMA_BLOCK_SIZE;
|
||||
|
||||
l = hawk_allocmem(pma->hawk, HAWK_SIZEOF(*l) + block_size);
|
||||
l = hawk_gem_allocmem(pma->gem, HAWK_SIZEOF(*l) + block_size);
|
||||
if (l == HAWK_NULL)
|
||||
{
|
||||
pma->failed = 1;
|
||||
@ -155,7 +155,7 @@ void* hawk_pma_alloc (hawk_pma_t* pma, hawk_oow_t size)
|
||||
|
||||
void* hawk_pma_calloc (hawk_pma_t* pma, hawk_oow_t size)
|
||||
{
|
||||
void* ptr = hawk_pma_alloc (pma, size);
|
||||
void* ptr = hawk_pma_alloc(pma, size);
|
||||
if (ptr) HAWK_MEMSET (ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
@ -75,11 +75,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Algorithms to setup tags so that submatch addressing can be done.
|
||||
*/
|
||||
|
||||
static HAWK_INLINE void* xcalloc (hawk_t* hawk, hawk_oow_t nmemb, hawk_oow_t size)
|
||||
static HAWK_INLINE void* xcalloc (hawk_gem_t* gem, hawk_oow_t nmemb, hawk_oow_t size)
|
||||
{
|
||||
void* ptr = hawk_allocmem(hawk, nmemb * size);
|
||||
if (ptr) HAWK_MEMSET (ptr, 0, nmemb * size);
|
||||
return ptr;
|
||||
return hawk_gem_callocmem(gem, nmemb * size);
|
||||
}
|
||||
|
||||
/* Inserts a catenation node to the root of the tree given in `node'.
|
||||
@ -213,25 +211,25 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree,
|
||||
tnfa->minimal_tags[0] = -1;
|
||||
}
|
||||
|
||||
regset = xmalloc(mem->hawk, sizeof(*regset) * ((tnfa->num_submatches + 1) * 2));
|
||||
regset = xmalloc(mem->gem, sizeof(*regset) * ((tnfa->num_submatches + 1) * 2));
|
||||
if (regset == NULL)
|
||||
return REG_ESPACE;
|
||||
regset[0] = -1;
|
||||
orig_regset = regset;
|
||||
|
||||
parents = xmalloc(mem->hawk, sizeof(*parents) * (tnfa->num_submatches + 1));
|
||||
parents = xmalloc(mem->gem, sizeof(*parents) * (tnfa->num_submatches + 1));
|
||||
if (parents == NULL)
|
||||
{
|
||||
xfree(mem->hawk, regset);
|
||||
xfree(mem->gem, regset);
|
||||
return REG_ESPACE;
|
||||
}
|
||||
parents[0] = -1;
|
||||
|
||||
saved_states = xmalloc(mem->hawk, sizeof(*saved_states) * (tnfa->num_submatches + 1));
|
||||
saved_states = xmalloc(mem->gem, sizeof(*saved_states) * (tnfa->num_submatches + 1));
|
||||
if (saved_states == NULL)
|
||||
{
|
||||
xfree(mem->hawk,regset);
|
||||
xfree(mem->hawk,parents);
|
||||
xfree(mem->gem,regset);
|
||||
xfree(mem->gem,parents);
|
||||
return REG_ESPACE;
|
||||
}
|
||||
else
|
||||
@ -289,7 +287,7 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree,
|
||||
tnfa->submatch_data[id].parents = NULL;
|
||||
if (i > 0)
|
||||
{
|
||||
int *p = xmalloc(mem->hawk, sizeof(*p) * (i + 1));
|
||||
int *p = xmalloc(mem->gem, sizeof(*p) * (i + 1));
|
||||
if (p == NULL)
|
||||
{
|
||||
status = REG_ESPACE;
|
||||
@ -683,9 +681,9 @@ tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree,
|
||||
tnfa->end_tag = num_tags;
|
||||
tnfa->num_tags = num_tags;
|
||||
tnfa->num_minimals = num_minimals;
|
||||
xfree(mem->hawk,orig_regset);
|
||||
xfree(mem->hawk,parents);
|
||||
xfree(mem->hawk,saved_states);
|
||||
xfree(mem->gem,orig_regset);
|
||||
xfree(mem->gem,parents);
|
||||
xfree(mem->gem,saved_states);
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -1504,7 +1502,7 @@ tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree)
|
||||
if (status != REG_OK)
|
||||
return status;
|
||||
/* Allocate arrays for the tags and parameters. */
|
||||
tags = xmalloc(mem->hawk, sizeof(*tags) * (num_tags + 1));
|
||||
tags = xmalloc(mem->gem, sizeof(*tags) * (num_tags + 1));
|
||||
if (!tags)
|
||||
return REG_ESPACE;
|
||||
tags[0] = -1;
|
||||
@ -1516,7 +1514,7 @@ tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree)
|
||||
* TRE_PARAM_LAST);
|
||||
if (!params)
|
||||
{
|
||||
xfree(mem->hawk,tags);
|
||||
xfree(mem->gem,tags);
|
||||
return REG_ESPACE;
|
||||
}
|
||||
}
|
||||
@ -1526,13 +1524,13 @@ tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree)
|
||||
&assertions, params, NULL, NULL);
|
||||
if (status != REG_OK)
|
||||
{
|
||||
xfree(mem->hawk,tags);
|
||||
xfree(mem->gem,tags);
|
||||
return status;
|
||||
}
|
||||
node->firstpos =
|
||||
tre_set_union(mem, cat->right->firstpos, cat->left->firstpos,
|
||||
tags, assertions, params);
|
||||
xfree(mem->hawk,tags);
|
||||
xfree(mem->gem,tags);
|
||||
if (!node->firstpos)
|
||||
return REG_ESPACE;
|
||||
}
|
||||
@ -1553,7 +1551,7 @@ tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree)
|
||||
if (status != REG_OK)
|
||||
return status;
|
||||
/* Allocate arrays for the tags and parameters. */
|
||||
tags = xmalloc(mem->hawk,sizeof(int) * (num_tags + 1));
|
||||
tags = xmalloc(mem->gem,sizeof(int) * (num_tags + 1));
|
||||
if (!tags)
|
||||
return REG_ESPACE;
|
||||
tags[0] = -1;
|
||||
@ -1565,7 +1563,7 @@ tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree)
|
||||
* TRE_PARAM_LAST);
|
||||
if (!params)
|
||||
{
|
||||
xfree(mem->hawk,tags);
|
||||
xfree(mem->gem,tags);
|
||||
return REG_ESPACE;
|
||||
}
|
||||
}
|
||||
@ -1575,13 +1573,13 @@ tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree)
|
||||
&assertions, params, NULL, NULL);
|
||||
if (status != REG_OK)
|
||||
{
|
||||
xfree(mem->hawk,tags);
|
||||
xfree(mem->gem,tags);
|
||||
return status;
|
||||
}
|
||||
node->lastpos =
|
||||
tre_set_union(mem, cat->left->lastpos, cat->right->lastpos,
|
||||
tags, assertions, params);
|
||||
xfree(mem->hawk,tags);
|
||||
xfree(mem->gem,tags);
|
||||
if (!node->lastpos)
|
||||
return REG_ESPACE;
|
||||
}
|
||||
@ -1604,7 +1602,7 @@ tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree)
|
||||
|
||||
/* Adds a transition from each position in `p1' to each position in `p2'. */
|
||||
static reg_errcode_t
|
||||
tre_make_trans(hawk_t* hawk, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
|
||||
tre_make_trans(hawk_gem_t* gem, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
|
||||
tre_tnfa_transition_t *transitions,
|
||||
int *counts, int *offs)
|
||||
{
|
||||
@ -1676,7 +1674,7 @@ tre_make_trans(hawk_t* hawk, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
|
||||
if (p1->neg_classes != NULL)
|
||||
{
|
||||
for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++);
|
||||
trans->neg_classes = xmalloc(hawk,sizeof(*trans->neg_classes) * (i + 1));
|
||||
trans->neg_classes = xmalloc(gem,sizeof(*trans->neg_classes) * (i + 1));
|
||||
if (trans->neg_classes == NULL) return REG_ESPACE;
|
||||
for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++)
|
||||
trans->neg_classes[i] = p1->neg_classes[i];
|
||||
@ -1696,13 +1694,13 @@ tre_make_trans(hawk_t* hawk, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
|
||||
j++;
|
||||
|
||||
/* If we are overwriting a transition, free the old tag array. */
|
||||
if (trans->tags != NULL) xfree(hawk,trans->tags);
|
||||
if (trans->tags != NULL) xfree(gem,trans->tags);
|
||||
trans->tags = NULL;
|
||||
|
||||
/* If there were any tags, allocate an array and fill it. */
|
||||
if (i + j > 0)
|
||||
{
|
||||
trans->tags = xmalloc(hawk,sizeof(*trans->tags) * (i + j + 1));
|
||||
trans->tags = xmalloc(gem,sizeof(*trans->tags) * (i + j + 1));
|
||||
if (!trans->tags)
|
||||
return REG_ESPACE;
|
||||
i = 0;
|
||||
@ -1737,8 +1735,7 @@ tre_make_trans(hawk_t* hawk, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
|
||||
if (p1->params || p2->params)
|
||||
{
|
||||
if (!trans->params)
|
||||
trans->params = xmalloc(hawk,sizeof(*trans->params)
|
||||
* TRE_PARAM_LAST);
|
||||
trans->params = xmalloc(gem,sizeof(*trans->params) * TRE_PARAM_LAST);
|
||||
if (!trans->params)
|
||||
return REG_ESPACE;
|
||||
for (i = 0; i < TRE_PARAM_LAST; i++)
|
||||
@ -1752,8 +1749,7 @@ tre_make_trans(hawk_t* hawk, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (trans->params)
|
||||
xfree(hawk,trans->params);
|
||||
if (trans->params) xfree(gem,trans->params);
|
||||
trans->params = NULL;
|
||||
}
|
||||
|
||||
@ -1823,7 +1819,7 @@ tre_make_trans(hawk_t* hawk, tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2,
|
||||
strings). The TNFA takes O(n^2) space in the worst case, `n' is size of
|
||||
the regexp. */
|
||||
static reg_errcode_t
|
||||
tre_ast_to_tnfa(hawk_t* hawk, tre_ast_node_t *node, tre_tnfa_transition_t *transitions,
|
||||
tre_ast_to_tnfa(hawk_gem_t* gem, tre_ast_node_t *node, tre_tnfa_transition_t *transitions,
|
||||
int *counts, int *offs)
|
||||
{
|
||||
tre_union_t *uni;
|
||||
@ -1838,24 +1834,24 @@ tre_ast_to_tnfa(hawk_t* hawk, tre_ast_node_t *node, tre_tnfa_transition_t *trans
|
||||
break;
|
||||
case UNION:
|
||||
uni = (tre_union_t *)node->obj;
|
||||
errcode = tre_ast_to_tnfa(hawk, uni->left, transitions, counts, offs);
|
||||
errcode = tre_ast_to_tnfa(gem, uni->left, transitions, counts, offs);
|
||||
if (errcode != REG_OK)
|
||||
return errcode;
|
||||
errcode = tre_ast_to_tnfa(hawk, uni->right, transitions, counts, offs);
|
||||
errcode = tre_ast_to_tnfa(gem, uni->right, transitions, counts, offs);
|
||||
break;
|
||||
|
||||
case CATENATION:
|
||||
cat = (tre_catenation_t *)node->obj;
|
||||
/* Add a transition from each position in cat->left->lastpos
|
||||
to each position in cat->right->firstpos. */
|
||||
errcode = tre_make_trans(hawk, cat->left->lastpos, cat->right->firstpos,
|
||||
errcode = tre_make_trans(gem, cat->left->lastpos, cat->right->firstpos,
|
||||
transitions, counts, offs);
|
||||
if (errcode != REG_OK)
|
||||
return errcode;
|
||||
errcode = tre_ast_to_tnfa(hawk, cat->left, transitions, counts, offs);
|
||||
errcode = tre_ast_to_tnfa(gem, cat->left, transitions, counts, offs);
|
||||
if (errcode != REG_OK)
|
||||
return errcode;
|
||||
errcode = tre_ast_to_tnfa(hawk, cat->right, transitions, counts, offs);
|
||||
errcode = tre_ast_to_tnfa(gem, cat->right, transitions, counts, offs);
|
||||
break;
|
||||
|
||||
case ITERATION:
|
||||
@ -1867,12 +1863,12 @@ tre_ast_to_tnfa(hawk_t* hawk, tre_ast_node_t *node, tre_tnfa_transition_t *trans
|
||||
assert(iter->min == 0 || iter->min == 1);
|
||||
/* Add a transition from each last position in the iterated
|
||||
expression to each first position. */
|
||||
errcode = tre_make_trans(hawk, iter->arg->lastpos, iter->arg->firstpos,
|
||||
errcode = tre_make_trans(gem, iter->arg->lastpos, iter->arg->firstpos,
|
||||
transitions, counts, offs);
|
||||
if (errcode != REG_OK)
|
||||
return errcode;
|
||||
}
|
||||
errcode = tre_ast_to_tnfa(hawk, iter->arg, transitions, counts, offs);
|
||||
errcode = tre_ast_to_tnfa(gem, iter->arg, transitions, counts, offs);
|
||||
break;
|
||||
}
|
||||
return errcode;
|
||||
@ -1909,12 +1905,12 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
/* Allocate a stack used throughout the compilation process for various
|
||||
purposes. */
|
||||
/* HAWK: deleted limit on the stack size
|
||||
stack = tre_stack_new(preg->hawk, 512, 10240, 128); */
|
||||
stack = tre_stack_new(preg->hawk, 512, -1, 128);
|
||||
stack = tre_stack_new(preg->gem, 512, 10240, 128); */
|
||||
stack = tre_stack_new(preg->gem, 512, -1, 128);
|
||||
if (!stack)
|
||||
return REG_ESPACE;
|
||||
/* Allocate a fast memory allocator. */
|
||||
mem = tre_mem_new(preg->hawk);
|
||||
mem = tre_mem_new(preg->gem);
|
||||
if (!mem)
|
||||
{
|
||||
tre_stack_destroy(stack);
|
||||
@ -1950,7 +1946,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
ERROR_EXIT(REG_ESUBREG);
|
||||
|
||||
/* Allocate the TNFA struct. */
|
||||
tnfa = xcalloc(preg->hawk, 1, sizeof(tre_tnfa_t));
|
||||
tnfa = xcalloc(preg->gem, 1, sizeof(tre_tnfa_t));
|
||||
if (tnfa == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
tnfa->have_backrefs = parse_ctx.max_backref >= 0;
|
||||
@ -1974,7 +1970,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
|
||||
if (tnfa->num_tags > 0)
|
||||
{
|
||||
tag_directions = xmalloc(preg->hawk,sizeof(*tag_directions)
|
||||
tag_directions = xmalloc(preg->gem,sizeof(*tag_directions)
|
||||
* (tnfa->num_tags + 1));
|
||||
if (tag_directions == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
@ -1982,12 +1978,12 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
HAWK_MEMSET(tag_directions, -1,
|
||||
sizeof(*tag_directions) * (tnfa->num_tags + 1));
|
||||
}
|
||||
tnfa->minimal_tags = xcalloc(preg->hawk, (unsigned)tnfa->num_tags * 2 + 1,
|
||||
tnfa->minimal_tags = xcalloc(preg->gem, (unsigned)tnfa->num_tags * 2 + 1,
|
||||
sizeof(tnfa->minimal_tags));
|
||||
if (tnfa->minimal_tags == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
|
||||
submatch_data = xcalloc(preg->hawk,(unsigned)parse_ctx.submatch_id,
|
||||
submatch_data = xcalloc(preg->gem,(unsigned)parse_ctx.submatch_id,
|
||||
sizeof(*submatch_data));
|
||||
if (submatch_data == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
@ -2036,17 +2032,17 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
if (errcode != REG_OK)
|
||||
ERROR_EXIT(errcode);
|
||||
|
||||
counts = xmalloc(preg->hawk,sizeof(int) * parse_ctx.position);
|
||||
counts = xmalloc(preg->gem,sizeof(int) * parse_ctx.position);
|
||||
if (counts == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
|
||||
offs = xmalloc(preg->hawk,sizeof(int) * parse_ctx.position);
|
||||
offs = xmalloc(preg->gem,sizeof(int) * parse_ctx.position);
|
||||
if (offs == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
|
||||
for (i = 0; i < parse_ctx.position; i++)
|
||||
counts[i] = 0;
|
||||
tre_ast_to_tnfa(preg->hawk, tree, NULL, counts, NULL);
|
||||
tre_ast_to_tnfa(preg->gem, tree, NULL, counts, NULL);
|
||||
|
||||
add = 0;
|
||||
for (i = 0; i < parse_ctx.position; i++)
|
||||
@ -2055,14 +2051,14 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
add += counts[i] + 1;
|
||||
counts[i] = 0;
|
||||
}
|
||||
transitions = xcalloc(preg->hawk, (unsigned)add + 1, sizeof(*transitions));
|
||||
transitions = xcalloc(preg->gem, (unsigned)add + 1, sizeof(*transitions));
|
||||
if (transitions == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
tnfa->transitions = transitions;
|
||||
tnfa->num_transitions = add;
|
||||
|
||||
DPRINT(("Converting to TNFA:\n"));
|
||||
errcode = tre_ast_to_tnfa(preg->hawk, tree, transitions, counts, offs);
|
||||
errcode = tre_ast_to_tnfa(preg->gem, tree, transitions, counts, offs);
|
||||
if (errcode != REG_OK)
|
||||
ERROR_EXIT(errcode);
|
||||
|
||||
@ -2077,7 +2073,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
int count = 0;
|
||||
tre_cint_t k;
|
||||
DPRINT(("Characters that can start a match:"));
|
||||
tnfa->firstpos_chars = xcalloc(preg->hawk, 256, sizeof(char));
|
||||
tnfa->firstpos_chars = xcalloc(preg->gem, 256, sizeof(char));
|
||||
if (tnfa->firstpos_chars == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
for (p = tree->firstpos; p->position >= 0; p++)
|
||||
@ -2104,7 +2100,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
{
|
||||
DPRINT(("first char must be %d\n", k));
|
||||
tnfa->first_char = k;
|
||||
xfree(preg->hawk,tnfa->firstpos_chars);
|
||||
xfree(preg->gem,tnfa->firstpos_chars);
|
||||
tnfa->firstpos_chars = NULL;
|
||||
break;
|
||||
}
|
||||
@ -2154,7 +2150,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
p++;
|
||||
}
|
||||
|
||||
initial = xcalloc(preg->hawk, (unsigned)i + 1, sizeof(tre_tnfa_transition_t));
|
||||
initial = xcalloc(preg->gem, (unsigned)i + 1, sizeof(tre_tnfa_transition_t));
|
||||
if (initial == NULL)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
tnfa->initial = initial;
|
||||
@ -2171,7 +2167,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; p->tags[j] >= 0; j++);
|
||||
initial[i].tags = xmalloc(preg->hawk,sizeof(*p->tags) * (j + 1));
|
||||
initial[i].tags = xmalloc(preg->gem,sizeof(*p->tags) * (j + 1));
|
||||
if (!initial[i].tags)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
HAWK_MEMCPY (initial[i].tags, p->tags, sizeof(*p->tags) * (j + 1));
|
||||
@ -2179,7 +2175,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
initial[i].params = NULL;
|
||||
if (p->params)
|
||||
{
|
||||
initial[i].params = xmalloc(preg->hawk,sizeof(*p->params) * TRE_PARAM_LAST);
|
||||
initial[i].params = xmalloc(preg->gem,sizeof(*p->params) * TRE_PARAM_LAST);
|
||||
if (!initial[i].params)
|
||||
ERROR_EXIT(REG_ESPACE);
|
||||
HAWK_MEMCPY (initial[i].params, p->params,
|
||||
@ -2199,8 +2195,8 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
|
||||
|
||||
tre_mem_destroy(mem);
|
||||
tre_stack_destroy(stack);
|
||||
xfree(preg->hawk,counts);
|
||||
xfree(preg->hawk,offs);
|
||||
xfree(preg->gem,counts);
|
||||
xfree(preg->gem,offs);
|
||||
|
||||
preg->TRE_REGEX_T_FIELD = (void *)tnfa;
|
||||
return REG_OK;
|
||||
@ -2211,9 +2207,9 @@ error_exit:
|
||||
if (stack != NULL)
|
||||
tre_stack_destroy(stack);
|
||||
if (counts != NULL)
|
||||
xfree(preg->hawk,counts);
|
||||
xfree(preg->gem,counts);
|
||||
if (offs != NULL)
|
||||
xfree(preg->hawk,offs);
|
||||
xfree(preg->gem,offs);
|
||||
preg->TRE_REGEX_T_FIELD = (void *)tnfa;
|
||||
tre_free(preg);
|
||||
return errcode;
|
||||
@ -2233,46 +2229,46 @@ void tre_free (regex_t *preg)
|
||||
if (tnfa->transitions[i].state)
|
||||
{
|
||||
if (tnfa->transitions[i].tags)
|
||||
xfree(preg->hawk,tnfa->transitions[i].tags);
|
||||
xfree(preg->gem,tnfa->transitions[i].tags);
|
||||
if (tnfa->transitions[i].neg_classes)
|
||||
xfree(preg->hawk,tnfa->transitions[i].neg_classes);
|
||||
xfree(preg->gem,tnfa->transitions[i].neg_classes);
|
||||
if (tnfa->transitions[i].params)
|
||||
xfree(preg->hawk,tnfa->transitions[i].params);
|
||||
xfree(preg->gem,tnfa->transitions[i].params);
|
||||
}
|
||||
if (tnfa->transitions)
|
||||
xfree(preg->hawk,tnfa->transitions);
|
||||
xfree(preg->gem,tnfa->transitions);
|
||||
|
||||
if (tnfa->initial)
|
||||
{
|
||||
for (trans = tnfa->initial; trans->state; trans++)
|
||||
{
|
||||
if (trans->tags)
|
||||
xfree(preg->hawk,trans->tags);
|
||||
xfree(preg->gem,trans->tags);
|
||||
if (trans->params)
|
||||
xfree(preg->hawk,trans->params);
|
||||
xfree(preg->gem,trans->params);
|
||||
}
|
||||
xfree(preg->hawk,tnfa->initial);
|
||||
xfree(preg->gem,tnfa->initial);
|
||||
}
|
||||
|
||||
if (tnfa->submatch_data)
|
||||
{
|
||||
for (i = 0; i < tnfa->num_submatches; i++)
|
||||
if (tnfa->submatch_data[i].parents)
|
||||
xfree(preg->hawk,tnfa->submatch_data[i].parents);
|
||||
xfree(preg->hawk,tnfa->submatch_data);
|
||||
xfree(preg->gem,tnfa->submatch_data[i].parents);
|
||||
xfree(preg->gem,tnfa->submatch_data);
|
||||
}
|
||||
|
||||
if (tnfa->tag_directions)
|
||||
xfree(preg->hawk,tnfa->tag_directions);
|
||||
xfree(preg->gem,tnfa->tag_directions);
|
||||
/* HAWK: deleted */
|
||||
/*
|
||||
if (tnfa->firstpos_chars)
|
||||
xfree(preg->hawk,tnfa->firstpos_chars);
|
||||
xfree(preg->gem,tnfa->firstpos_chars);
|
||||
*/
|
||||
/* END HAWK */
|
||||
if (tnfa->minimal_tags)
|
||||
xfree(preg->hawk,tnfa->minimal_tags);
|
||||
xfree(preg->hawk,tnfa);
|
||||
xfree(preg->gem,tnfa->minimal_tags);
|
||||
xfree(preg->gem,tnfa);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
@ -191,7 +191,7 @@ typedef struct tre_backtrack_struct
|
||||
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
|
||||
|
||||
reg_errcode_t
|
||||
tre_tnfa_run_backtrack(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
tre_tnfa_run_backtrack(hawk_gem_t* gem, const tre_tnfa_t *tnfa, const void *string,
|
||||
int len, tre_str_type_t type, int *match_tags,
|
||||
int eflags, int *match_end_ofs)
|
||||
{
|
||||
@ -232,7 +232,7 @@ tre_tnfa_run_backtrack(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
int *states_seen = NULL;
|
||||
|
||||
/* Memory allocator to for allocating the backtracking stack. */
|
||||
tre_mem_t mem = tre_bt_mem_new(hawk);
|
||||
tre_mem_t mem = tre_bt_mem_new(gem);
|
||||
|
||||
/* The backtracking stack. */
|
||||
tre_backtrack_t stack;
|
||||
@ -261,7 +261,7 @@ tre_tnfa_run_backtrack(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
|
||||
if (tnfa->num_tags)
|
||||
{
|
||||
tags = xmalloc(hawk, sizeof(*tags) * tnfa->num_tags);
|
||||
tags = xmalloc(gem, sizeof(*tags) * tnfa->num_tags);
|
||||
if (!tags)
|
||||
{
|
||||
ret = REG_ESPACE;
|
||||
@ -270,7 +270,7 @@ tre_tnfa_run_backtrack(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
}
|
||||
if (tnfa->num_submatches)
|
||||
{
|
||||
pmatch = xmalloc(hawk, sizeof(*pmatch) * tnfa->num_submatches);
|
||||
pmatch = xmalloc(gem, sizeof(*pmatch) * tnfa->num_submatches);
|
||||
if (!pmatch)
|
||||
{
|
||||
ret = REG_ESPACE;
|
||||
@ -279,7 +279,7 @@ tre_tnfa_run_backtrack(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
}
|
||||
if (tnfa->num_states)
|
||||
{
|
||||
states_seen = xmalloc(hawk, sizeof(*states_seen) * tnfa->num_states);
|
||||
states_seen = xmalloc(gem, sizeof(*states_seen) * tnfa->num_states);
|
||||
if (!states_seen)
|
||||
{
|
||||
ret = REG_ESPACE;
|
||||
@ -333,7 +333,7 @@ retry:
|
||||
{
|
||||
/* Backtrack to this state. */
|
||||
DPRINT(("saving state %d for backtracking\n", trans_i->state_id));
|
||||
BT_STACK_PUSH(hawk, pos, str_byte, str_wide, trans_i->state,
|
||||
BT_STACK_PUSH(gem, pos, str_byte, str_wide, trans_i->state,
|
||||
trans_i->state_id, next_c, tags, mbstate);
|
||||
{
|
||||
int *tmp = trans_i->tags;
|
||||
@ -548,7 +548,7 @@ retry:
|
||||
jump back here if needed. */
|
||||
DPRINT((" saving state %d for backtracking\n",
|
||||
trans_i->state_id));
|
||||
BT_STACK_PUSH(hawk, pos, str_byte, str_wide, trans_i->state,
|
||||
BT_STACK_PUSH(gem, pos, str_byte, str_wide, trans_i->state,
|
||||
trans_i->state_id, next_c, tags, mbstate);
|
||||
{
|
||||
int *tmp;
|
||||
@ -632,9 +632,9 @@ backtrack:
|
||||
|
||||
error_exit:
|
||||
tre_bt_mem_destroy(mem);
|
||||
if (tags) xfree(hawk, tags);
|
||||
if (pmatch) xfree(hawk, pmatch);
|
||||
if (states_seen) xfree(hawk, states_seen);
|
||||
if (tags) xfree(gem, tags);
|
||||
if (pmatch) xfree(gem, pmatch);
|
||||
if (states_seen) xfree(gem, states_seen);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ tre_print_reach(const tre_tnfa_t *tnfa, tre_tnfa_reach_t *reach, int num_tags)
|
||||
#endif /* TRE_DEBUG */
|
||||
|
||||
reg_errcode_t
|
||||
tre_tnfa_run_parallel(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string, int len,
|
||||
tre_tnfa_run_parallel(hawk_gem_t* gem, const tre_tnfa_t *tnfa, const void *string, int len,
|
||||
tre_str_type_t type, int *match_tags, int eflags,
|
||||
int *match_end_ofs)
|
||||
{
|
||||
@ -177,7 +177,7 @@ tre_tnfa_run_parallel(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
+ (rbytes + xbytes * tnfa->num_states) * 2 + tbytes + pbytes;
|
||||
|
||||
/* Allocate the memory. */
|
||||
buf = xmalloc(hawk, (unsigned)total_bytes);
|
||||
buf = xmalloc(gem, (unsigned)total_bytes);
|
||||
if (buf == NULL) return REG_ESPACE;
|
||||
HAWK_MEMSET(buf, 0, (size_t)total_bytes);
|
||||
|
||||
@ -218,7 +218,7 @@ tre_tnfa_run_parallel(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
str_byte = hawk_find_bchar_in_bcstr(orig_str, first);
|
||||
if (str_byte == NULL)
|
||||
{
|
||||
if (buf) xfree(hawk, buf);
|
||||
if (buf) xfree(gem, buf);
|
||||
return REG_NOMATCH;
|
||||
}
|
||||
DPRINT(("skipped %lu chars\n", (unsigned long)(str_byte - orig_str)));
|
||||
@ -485,7 +485,7 @@ tre_tnfa_run_parallel(hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
|
||||
DPRINT(("match end offset = %d\n", match_eo));
|
||||
|
||||
if (buf) xfree(hawk, buf);
|
||||
if (buf) xfree(gem, buf);
|
||||
|
||||
*match_end_ofs = match_eo;
|
||||
return match_eo >= 0 ? REG_OK : REG_NOMATCH;
|
||||
|
@ -158,7 +158,7 @@ tre_new_item(tre_mem_t mem, int min, int max, int *i, int *max_i, tre_ast_node_t
|
||||
if (*max_i > 1024)
|
||||
return REG_ESPACE;
|
||||
*max_i *= 2;
|
||||
new_items = xrealloc(mem->hawk, array, sizeof(*items) * *max_i);
|
||||
new_items = xrealloc(mem->gem, array, sizeof(*items) * *max_i);
|
||||
if (new_items == NULL)
|
||||
return REG_ESPACE;
|
||||
*items = array = new_items;
|
||||
@ -395,7 +395,7 @@ tre_parse_bracket(tre_parse_ctx_t *ctx, tre_ast_node_t **result)
|
||||
int num_neg_classes = 0;
|
||||
|
||||
/* Start off with an array of `max_i' elements. */
|
||||
items = xmalloc(ctx->mem->hawk, sizeof(*items) * max_i);
|
||||
items = xmalloc(ctx->mem->gem, sizeof(*items) * max_i);
|
||||
if (items == NULL) return REG_ESPACE;
|
||||
|
||||
if (*ctx->re == CHAR_CARET)
|
||||
@ -537,7 +537,7 @@ tre_parse_bracket(tre_parse_ctx_t *ctx, tre_ast_node_t **result)
|
||||
#endif /* TRE_DEBUG */
|
||||
|
||||
parse_bracket_done:
|
||||
xfree(ctx->mem->hawk, items);
|
||||
xfree(ctx->mem->gem, items);
|
||||
ctx->position++;
|
||||
*result = node;
|
||||
return status;
|
||||
|
@ -229,9 +229,9 @@ typedef hawk_pma_t* tre_mem_t;
|
||||
#define tre_mem_alloc(mem,size) hawk_pma_alloc(mem,size)
|
||||
#define tre_mem_calloc(mem,size) hawk_pma_calloc(mem,size)
|
||||
|
||||
#define xmalloc(hawk,size) hawk_allocmem(hawk,size)
|
||||
#define xfree(hawk,ptr) hawk_freemem(hawk,ptr)
|
||||
#define xrealloc(hawk,ptr,new_size) hawk_reallocmem(hawk, ptr, new_size)
|
||||
#define xmalloc(gem,size) hawk_gem_allocmem(gem,size)
|
||||
#define xfree(gem,ptr) hawk_gem_freemem(gem,ptr)
|
||||
#define xrealloc(gem,ptr,new_size) hawk_gem_reallocmem(gem, ptr, new_size)
|
||||
|
||||
|
||||
/* tre-ast.h */
|
||||
@ -428,13 +428,13 @@ void tre_fill_pmatch(
|
||||
const tre_tnfa_t *tnfa, int *tags, int match_eo);
|
||||
|
||||
reg_errcode_t tre_tnfa_run_backtrack(
|
||||
hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string,
|
||||
hawk_gem_t* gem, const tre_tnfa_t *tnfa, const void *string,
|
||||
int len, tre_str_type_t type, int *match_tags,
|
||||
int eflags, int *match_end_ofs);
|
||||
|
||||
|
||||
reg_errcode_t tre_tnfa_run_parallel(
|
||||
hawk_t* hawk, const tre_tnfa_t *tnfa, const void *string, int len,
|
||||
hawk_gem_t* gem, const tre_tnfa_t *tnfa, const void *string, int len,
|
||||
tre_str_type_t type, int *match_tags, int eflags,
|
||||
int *match_end_ofs);
|
||||
|
||||
|
@ -69,7 +69,7 @@ union tre_stack_item
|
||||
|
||||
struct tre_stack_rec
|
||||
{
|
||||
hawk_t* hawk;
|
||||
hawk_gem_t* gem;
|
||||
int size;
|
||||
int max_size;
|
||||
int increment;
|
||||
@ -78,24 +78,24 @@ struct tre_stack_rec
|
||||
};
|
||||
|
||||
|
||||
tre_stack_t* tre_stack_new(hawk_t* hawk, int size, int max_size, int increment)
|
||||
tre_stack_t* tre_stack_new(hawk_gem_t* gem, int size, int max_size, int increment)
|
||||
{
|
||||
tre_stack_t *s;
|
||||
|
||||
s = xmalloc(hawk, sizeof(*s));
|
||||
s = xmalloc(gem, sizeof(*s));
|
||||
if (s != NULL)
|
||||
{
|
||||
s->stack = xmalloc(hawk, sizeof(*s->stack) * size);
|
||||
s->stack = xmalloc(gem, sizeof(*s->stack) * size);
|
||||
if (s->stack == NULL)
|
||||
{
|
||||
xfree(hawk, s);
|
||||
xfree(gem, s);
|
||||
return NULL;
|
||||
}
|
||||
s->size = size;
|
||||
s->max_size = max_size;
|
||||
s->increment = increment;
|
||||
s->ptr = 0;
|
||||
s->hawk = hawk;
|
||||
s->gem = gem;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@ -103,8 +103,8 @@ tre_stack_t* tre_stack_new(hawk_t* hawk, int size, int max_size, int increment)
|
||||
void
|
||||
tre_stack_destroy(tre_stack_t *s)
|
||||
{
|
||||
xfree(s->hawk,s->stack);
|
||||
xfree(s->hawk,s);
|
||||
xfree(s->gem,s->stack);
|
||||
xfree(s->gem,s);
|
||||
}
|
||||
|
||||
int
|
||||
@ -140,7 +140,7 @@ tre_stack_push(tre_stack_t *s, union tre_stack_item value)
|
||||
if (new_size > s->max_size) */
|
||||
if (s->max_size > 0 && new_size > s->max_size)
|
||||
new_size = s->max_size;
|
||||
new_buffer = xrealloc(s->hawk, s->stack, sizeof(*new_buffer) * new_size);
|
||||
new_buffer = xrealloc(s->gem, s->stack, sizeof(*new_buffer) * new_size);
|
||||
if (new_buffer == NULL)
|
||||
{
|
||||
DPRINT(("tre_stack_push: realloc failed.\n"));
|
||||
|
@ -71,7 +71,7 @@ typedef struct tre_stack_rec tre_stack_t;
|
||||
allocated with realloc() if all space gets used up. Returns the stack
|
||||
object or NULL if out of memory. */
|
||||
tre_stack_t *
|
||||
tre_stack_new(hawk_t* hawk, int size, int max_size, int increment);
|
||||
tre_stack_new(hawk_gem_t* gem, int size, int max_size, int increment);
|
||||
|
||||
/* Frees the stack object. */
|
||||
void
|
||||
|
@ -27,16 +27,16 @@
|
||||
#include "tre-prv.h"
|
||||
#include "tre-compile.h"
|
||||
|
||||
hawk_tre_t* hawk_tre_open (hawk_t* hawk, hawk_oow_t xtnsize)
|
||||
hawk_tre_t* hawk_tre_open (hawk_gem_t* gem, hawk_oow_t xtnsize)
|
||||
{
|
||||
hawk_tre_t* tre;
|
||||
|
||||
tre = (hawk_tre_t*)hawk_allocmem(hawk, HAWK_SIZEOF(hawk_tre_t) + xtnsize);
|
||||
tre = (hawk_tre_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(hawk_tre_t) + xtnsize);
|
||||
if (!tre) return HAWK_NULL;
|
||||
|
||||
if (hawk_tre_init(tre, hawk) <= -1)
|
||||
if (hawk_tre_init(tre, gem) <= -1)
|
||||
{
|
||||
hawk_freemem (hawk, tre);
|
||||
hawk_gem_freemem (gem, tre);
|
||||
return HAWK_NULL;
|
||||
}
|
||||
|
||||
@ -47,13 +47,13 @@ hawk_tre_t* hawk_tre_open (hawk_t* hawk, hawk_oow_t xtnsize)
|
||||
void hawk_tre_close (hawk_tre_t* tre)
|
||||
{
|
||||
hawk_tre_fini (tre);
|
||||
hawk_freemem (tre->hawk, tre);
|
||||
hawk_gem_freemem (tre->gem, tre);
|
||||
}
|
||||
|
||||
int hawk_tre_init (hawk_tre_t* tre, hawk_t* hawk)
|
||||
int hawk_tre_init (hawk_tre_t* tre, hawk_gem_t* gem)
|
||||
{
|
||||
HAWK_MEMSET (tre, 0, HAWK_SIZEOF(*tre));
|
||||
tre->hawk = hawk;
|
||||
tre->gem = gem;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ static int tre_match(
|
||||
int *tags = HAWK_NULL, eo;
|
||||
if (tnfa->num_tags > 0 && nmatch > 0)
|
||||
{
|
||||
tags = xmalloc (preg->hawk, sizeof(*tags) * tnfa->num_tags);
|
||||
tags = xmalloc (preg->gem, sizeof(*tags) * tnfa->num_tags);
|
||||
if (tags == HAWK_NULL) return REG_ESPACE;
|
||||
}
|
||||
|
||||
@ -193,21 +193,21 @@ static int tre_match(
|
||||
{
|
||||
/* The regex has back references, use the backtracking matcher. */
|
||||
status = tre_tnfa_run_backtrack (
|
||||
preg->hawk, tnfa, string, (int)len, type,
|
||||
preg->gem, tnfa, string, (int)len, type,
|
||||
tags, eflags, &eo);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Exact matching, no back references, use the parallel matcher. */
|
||||
status = tre_tnfa_run_parallel (
|
||||
preg->hawk, tnfa, string, (int)len, type,
|
||||
preg->gem, tnfa, string, (int)len, type,
|
||||
tags, eflags, &eo);
|
||||
}
|
||||
|
||||
if (status == REG_OK)
|
||||
/* A match was found, so fill the submatch registers. */
|
||||
tre_fill_pmatch(nmatch, pmatch, tnfa->cflags, tnfa, tags, eo);
|
||||
if (tags) xfree (preg->hawk, tags);
|
||||
if (tags) xfree (preg->gem, tags);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user