gem intead of hawk in tre

This commit is contained in:
hyung-hwan 2019-12-18 08:34:44 +00:00
parent 40d8800dab
commit c25b251efc
13 changed files with 140 additions and 146 deletions

View File

@ -208,11 +208,10 @@ extern "C" {
* \return #hawk_pio_t object on success, #HAWK_NULL on failure * \return #hawk_pio_t object on success, #HAWK_NULL on failure
*/ */
HAWK_EXPORT hawk_pio_t* hawk_pio_open ( HAWK_EXPORT hawk_pio_t* hawk_pio_open (
hawk_gem_t* gem, /**< hawk */ hawk_gem_t* gem, /**< gem */
hawk_oow_t ext, /**< extension size */ hawk_oow_t ext, /**< extension size */
const hawk_ooch_t* cmd, /**< command to execute */ const hawk_ooch_t* cmd, /**< command to execute */
int flags /**< 0 or a number OR'ed of the int flags /**< 0 or a number OR'ed of the #hawk_pio_flag_t enumerators*/
#hawk_pio_flag_t enumerators*/
); );
/** /**
@ -231,10 +230,9 @@ HAWK_EXPORT void hawk_pio_close (
*/ */
HAWK_EXPORT int hawk_pio_init ( HAWK_EXPORT int hawk_pio_init (
hawk_pio_t* pio, /**< pio object */ hawk_pio_t* pio, /**< pio object */
hawk_gem_t* gem, /**< hawk */ hawk_gem_t* gem, /**< gem */
const hawk_ooch_t* cmd, /**< command to execute */ const hawk_ooch_t* cmd, /**< command to execute */
int flags /**< 0 or a number OR'ed of the int flags /**< 0 or a number OR'ed of the #hawk_pio_flag_t enumerators*/
#hawk_pio_flag_t enumerators*/
); );
/** /**

View File

@ -61,7 +61,7 @@ typedef struct hawk_pma_t hawk_pma_t;
struct hawk_pma_t struct hawk_pma_t
{ {
hawk_t* hawk; hawk_gem_t* gem;
hawk_pma_blk_t* blocks; hawk_pma_blk_t* blocks;
hawk_pma_blk_t* current; hawk_pma_blk_t* current;
@ -79,7 +79,7 @@ extern "C" {
* The hawk_pma_open() function creates a pool-based memory allocator. * The hawk_pma_open() function creates a pool-based memory allocator.
*/ */
HAWK_EXPORT hawk_pma_t* hawk_pma_open ( HAWK_EXPORT hawk_pma_t* hawk_pma_open (
hawk_t* hawk, /**< hawk */ hawk_gem_t* gem, /**< gem */
hawk_oow_t xtnsize /**< extension size in bytes */ 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_EXPORT int hawk_pma_init (
hawk_pma_t* pma, /**< memory allocator */ hawk_pma_t* pma, /**< memory allocator */
hawk_t* hawk /**< hawk */ hawk_gem_t* gem /**< gem */
); );
HAWK_EXPORT void hawk_pma_fini ( HAWK_EXPORT void hawk_pma_fini (

View File

@ -56,7 +56,7 @@ typedef enum hawk_tre_errnum_t hawk_tre_errnum_t;
typedef struct hawk_tre_t hawk_tre_t; typedef struct hawk_tre_t hawk_tre_t;
struct hawk_tre_t struct hawk_tre_t
{ {
hawk_t* hawk; hawk_gem_t* gem;
hawk_tre_errnum_t errnum; hawk_tre_errnum_t errnum;
hawk_oow_t re_nsub; /* Number of parenthesized subexpressions. */ hawk_oow_t re_nsub; /* Number of parenthesized subexpressions. */
@ -109,7 +109,7 @@ extern "C" {
#endif #endif
HAWK_EXPORT hawk_tre_t* hawk_tre_open ( HAWK_EXPORT hawk_tre_t* hawk_tre_open (
hawk_t* hawk, hawk_gem_t* gem,
hawk_oow_t xtnsize hawk_oow_t xtnsize
); );
@ -119,7 +119,7 @@ HAWK_EXPORT void hawk_tre_close (
HAWK_EXPORT int hawk_tre_init ( HAWK_EXPORT int hawk_tre_init (
hawk_tre_t* tre, hawk_tre_t* tre,
hawk_t* hawk hawk_gem_t* gem
); );
HAWK_EXPORT void hawk_tre_fini ( HAWK_EXPORT void hawk_tre_fini (

View File

@ -503,7 +503,7 @@ int hawk_buildrex (
if (code) if (code)
{ {
tre = hawk_tre_open(awk, 0); tre = hawk_tre_open(hawk_getgem(awk), 0);
if (tre == HAWK_NULL) if (tre == HAWK_NULL)
{ {
*errnum = HAWK_ENOMEM; *errnum = HAWK_ENOMEM;
@ -529,7 +529,7 @@ int hawk_buildrex (
if (icode) if (icode)
{ {
itre = hawk_tre_open(awk, 0); itre = hawk_tre_open(hawk_getgem(awk), 0);
if (itre == HAWK_NULL) if (itre == HAWK_NULL)
{ {
if (tre) hawk_tre_close (tre); if (tre) hawk_tre_close (tre);

View File

@ -53,16 +53,16 @@
(HAWK_SIZEOF(type) - (((hawk_uintptr_t)ptr) % HAWK_SIZEOF(type))) : 0) (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; 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 (!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; 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) void hawk_pma_close (hawk_pma_t* pma)
{ {
hawk_pma_fini (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)); HAWK_MEMSET (pma, 0, HAWK_SIZEOF(*pma));
pma->hawk = hawk; pma->gem = gem;
return 0; return 0;
} }
@ -91,18 +91,18 @@ void hawk_pma_fini (hawk_pma_t* pma)
void hawk_pma_clear (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; hawk_pma_blk_t* tmp, * l = pma->blocks;
while (l != HAWK_NULL) while (l != HAWK_NULL)
{ {
tmp = l->next; tmp = l->next;
hawk_freemem (hawk, l); hawk_gem_freemem (gem, l);
l = tmp; l = tmp;
} }
HAWK_MEMSET (pma, 0, HAWK_SIZEOF(*pma)); HAWK_MEMSET (pma, 0, HAWK_SIZEOF(*pma));
pma->hawk = hawk; pma->gem = gem;
} }
/* Returns a new memory allocator or NULL if out of memory. */ /* 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 else
block_size = HAWK_PMA_BLOCK_SIZE; 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) if (l == HAWK_NULL)
{ {
pma->failed = 1; 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* 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); if (ptr) HAWK_MEMSET (ptr, 0, size);
return ptr; return ptr;
} }

View File

@ -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. 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); return hawk_gem_callocmem(gem, nmemb * size);
if (ptr) HAWK_MEMSET (ptr, 0, nmemb * size);
return ptr;
} }
/* Inserts a catenation node to the root of the tree given in `node'. /* 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; 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) if (regset == NULL)
return REG_ESPACE; return REG_ESPACE;
regset[0] = -1; regset[0] = -1;
orig_regset = regset; 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) if (parents == NULL)
{ {
xfree(mem->hawk, regset); xfree(mem->gem, regset);
return REG_ESPACE; return REG_ESPACE;
} }
parents[0] = -1; 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) if (saved_states == NULL)
{ {
xfree(mem->hawk,regset); xfree(mem->gem,regset);
xfree(mem->hawk,parents); xfree(mem->gem,parents);
return REG_ESPACE; return REG_ESPACE;
} }
else 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; tnfa->submatch_data[id].parents = NULL;
if (i > 0) if (i > 0)
{ {
int *p = xmalloc(mem->hawk, sizeof(*p) * (i + 1)); int *p = xmalloc(mem->gem, sizeof(*p) * (i + 1));
if (p == NULL) if (p == NULL)
{ {
status = REG_ESPACE; 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->end_tag = num_tags;
tnfa->num_tags = num_tags; tnfa->num_tags = num_tags;
tnfa->num_minimals = num_minimals; tnfa->num_minimals = num_minimals;
xfree(mem->hawk,orig_regset); xfree(mem->gem,orig_regset);
xfree(mem->hawk,parents); xfree(mem->gem,parents);
xfree(mem->hawk,saved_states); xfree(mem->gem,saved_states);
return status; 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) if (status != REG_OK)
return status; return status;
/* Allocate arrays for the tags and parameters. */ /* 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) if (!tags)
return REG_ESPACE; return REG_ESPACE;
tags[0] = -1; 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); * TRE_PARAM_LAST);
if (!params) if (!params)
{ {
xfree(mem->hawk,tags); xfree(mem->gem,tags);
return REG_ESPACE; 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); &assertions, params, NULL, NULL);
if (status != REG_OK) if (status != REG_OK)
{ {
xfree(mem->hawk,tags); xfree(mem->gem,tags);
return status; return status;
} }
node->firstpos = node->firstpos =
tre_set_union(mem, cat->right->firstpos, cat->left->firstpos, tre_set_union(mem, cat->right->firstpos, cat->left->firstpos,
tags, assertions, params); tags, assertions, params);
xfree(mem->hawk,tags); xfree(mem->gem,tags);
if (!node->firstpos) if (!node->firstpos)
return REG_ESPACE; 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) if (status != REG_OK)
return status; return status;
/* Allocate arrays for the tags and parameters. */ /* 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) if (!tags)
return REG_ESPACE; return REG_ESPACE;
tags[0] = -1; 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); * TRE_PARAM_LAST);
if (!params) if (!params)
{ {
xfree(mem->hawk,tags); xfree(mem->gem,tags);
return REG_ESPACE; 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); &assertions, params, NULL, NULL);
if (status != REG_OK) if (status != REG_OK)
{ {
xfree(mem->hawk,tags); xfree(mem->gem,tags);
return status; return status;
} }
node->lastpos = node->lastpos =
tre_set_union(mem, cat->left->lastpos, cat->right->lastpos, tre_set_union(mem, cat->left->lastpos, cat->right->lastpos,
tags, assertions, params); tags, assertions, params);
xfree(mem->hawk,tags); xfree(mem->gem,tags);
if (!node->lastpos) if (!node->lastpos)
return REG_ESPACE; 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'. */ /* Adds a transition from each position in `p1' to each position in `p2'. */
static reg_errcode_t 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, tre_tnfa_transition_t *transitions,
int *counts, int *offs) 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) if (p1->neg_classes != NULL)
{ {
for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++); 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; if (trans->neg_classes == NULL) return REG_ESPACE;
for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++) for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++)
trans->neg_classes[i] = p1->neg_classes[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++; j++;
/* If we are overwriting a transition, free the old tag array. */ /* 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; trans->tags = NULL;
/* If there were any tags, allocate an array and fill it. */ /* If there were any tags, allocate an array and fill it. */
if (i + j > 0) 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) if (!trans->tags)
return REG_ESPACE; return REG_ESPACE;
i = 0; 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 (p1->params || p2->params)
{ {
if (!trans->params) if (!trans->params)
trans->params = xmalloc(hawk,sizeof(*trans->params) trans->params = xmalloc(gem,sizeof(*trans->params) * TRE_PARAM_LAST);
* TRE_PARAM_LAST);
if (!trans->params) if (!trans->params)
return REG_ESPACE; return REG_ESPACE;
for (i = 0; i < TRE_PARAM_LAST; i++) 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 else
{ {
if (trans->params) if (trans->params) xfree(gem,trans->params);
xfree(hawk,trans->params);
trans->params = NULL; 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 strings). The TNFA takes O(n^2) space in the worst case, `n' is size of
the regexp. */ the regexp. */
static reg_errcode_t 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) int *counts, int *offs)
{ {
tre_union_t *uni; 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; break;
case UNION: case UNION:
uni = (tre_union_t *)node->obj; 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) if (errcode != REG_OK)
return errcode; 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; break;
case CATENATION: case CATENATION:
cat = (tre_catenation_t *)node->obj; cat = (tre_catenation_t *)node->obj;
/* Add a transition from each position in cat->left->lastpos /* Add a transition from each position in cat->left->lastpos
to each position in cat->right->firstpos. */ 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); transitions, counts, offs);
if (errcode != REG_OK) if (errcode != REG_OK)
return errcode; 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) if (errcode != REG_OK)
return errcode; 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; break;
case ITERATION: 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); assert(iter->min == 0 || iter->min == 1);
/* Add a transition from each last position in the iterated /* Add a transition from each last position in the iterated
expression to each first position. */ 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); transitions, counts, offs);
if (errcode != REG_OK) if (errcode != REG_OK)
return errcode; 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; break;
} }
return errcode; 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 /* Allocate a stack used throughout the compilation process for various
purposes. */ purposes. */
/* HAWK: deleted limit on the stack size /* HAWK: deleted limit on the stack size
stack = tre_stack_new(preg->hawk, 512, 10240, 128); */ stack = tre_stack_new(preg->gem, 512, 10240, 128); */
stack = tre_stack_new(preg->hawk, 512, -1, 128); stack = tre_stack_new(preg->gem, 512, -1, 128);
if (!stack) if (!stack)
return REG_ESPACE; return REG_ESPACE;
/* Allocate a fast memory allocator. */ /* Allocate a fast memory allocator. */
mem = tre_mem_new(preg->hawk); mem = tre_mem_new(preg->gem);
if (!mem) if (!mem)
{ {
tre_stack_destroy(stack); 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); ERROR_EXIT(REG_ESUBREG);
/* Allocate the TNFA struct. */ /* 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) if (tnfa == NULL)
ERROR_EXIT(REG_ESPACE); ERROR_EXIT(REG_ESPACE);
tnfa->have_backrefs = parse_ctx.max_backref >= 0; 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) 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)); * (tnfa->num_tags + 1));
if (tag_directions == NULL) if (tag_directions == NULL)
ERROR_EXIT(REG_ESPACE); 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, HAWK_MEMSET(tag_directions, -1,
sizeof(*tag_directions) * (tnfa->num_tags + 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)); sizeof(tnfa->minimal_tags));
if (tnfa->minimal_tags == NULL) if (tnfa->minimal_tags == NULL)
ERROR_EXIT(REG_ESPACE); 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)); sizeof(*submatch_data));
if (submatch_data == NULL) if (submatch_data == NULL)
ERROR_EXIT(REG_ESPACE); 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) if (errcode != REG_OK)
ERROR_EXIT(errcode); ERROR_EXIT(errcode);
counts = xmalloc(preg->hawk,sizeof(int) * parse_ctx.position); counts = xmalloc(preg->gem,sizeof(int) * parse_ctx.position);
if (counts == NULL) if (counts == NULL)
ERROR_EXIT(REG_ESPACE); 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) if (offs == NULL)
ERROR_EXIT(REG_ESPACE); ERROR_EXIT(REG_ESPACE);
for (i = 0; i < parse_ctx.position; i++) for (i = 0; i < parse_ctx.position; i++)
counts[i] = 0; 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; add = 0;
for (i = 0; i < parse_ctx.position; i++) 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; add += counts[i] + 1;
counts[i] = 0; counts[i] = 0;
} }
transitions = xcalloc(preg->hawk, (unsigned)add + 1, sizeof(*transitions)); transitions = xcalloc(preg->gem, (unsigned)add + 1, sizeof(*transitions));
if (transitions == NULL) if (transitions == NULL)
ERROR_EXIT(REG_ESPACE); ERROR_EXIT(REG_ESPACE);
tnfa->transitions = transitions; tnfa->transitions = transitions;
tnfa->num_transitions = add; tnfa->num_transitions = add;
DPRINT(("Converting to TNFA:\n")); 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) if (errcode != REG_OK)
ERROR_EXIT(errcode); 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; int count = 0;
tre_cint_t k; tre_cint_t k;
DPRINT(("Characters that can start a match:")); 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) if (tnfa->firstpos_chars == NULL)
ERROR_EXIT(REG_ESPACE); ERROR_EXIT(REG_ESPACE);
for (p = tree->firstpos; p->position >= 0; p++) 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)); DPRINT(("first char must be %d\n", k));
tnfa->first_char = k; tnfa->first_char = k;
xfree(preg->hawk,tnfa->firstpos_chars); xfree(preg->gem,tnfa->firstpos_chars);
tnfa->firstpos_chars = NULL; tnfa->firstpos_chars = NULL;
break; break;
} }
@ -2154,7 +2150,7 @@ int tre_compile (regex_t *preg, const tre_char_t *regex, size_t n, int cflags)
p++; 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) if (initial == NULL)
ERROR_EXIT(REG_ESPACE); ERROR_EXIT(REG_ESPACE);
tnfa->initial = initial; 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; int j;
for (j = 0; p->tags[j] >= 0; 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) if (!initial[i].tags)
ERROR_EXIT(REG_ESPACE); ERROR_EXIT(REG_ESPACE);
HAWK_MEMCPY (initial[i].tags, p->tags, sizeof(*p->tags) * (j + 1)); 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; initial[i].params = NULL;
if (p->params) 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) if (!initial[i].params)
ERROR_EXIT(REG_ESPACE); ERROR_EXIT(REG_ESPACE);
HAWK_MEMCPY (initial[i].params, p->params, 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_mem_destroy(mem);
tre_stack_destroy(stack); tre_stack_destroy(stack);
xfree(preg->hawk,counts); xfree(preg->gem,counts);
xfree(preg->hawk,offs); xfree(preg->gem,offs);
preg->TRE_REGEX_T_FIELD = (void *)tnfa; preg->TRE_REGEX_T_FIELD = (void *)tnfa;
return REG_OK; return REG_OK;
@ -2211,9 +2207,9 @@ error_exit:
if (stack != NULL) if (stack != NULL)
tre_stack_destroy(stack); tre_stack_destroy(stack);
if (counts != NULL) if (counts != NULL)
xfree(preg->hawk,counts); xfree(preg->gem,counts);
if (offs != NULL) if (offs != NULL)
xfree(preg->hawk,offs); xfree(preg->gem,offs);
preg->TRE_REGEX_T_FIELD = (void *)tnfa; preg->TRE_REGEX_T_FIELD = (void *)tnfa;
tre_free(preg); tre_free(preg);
return errcode; return errcode;
@ -2233,46 +2229,46 @@ void tre_free (regex_t *preg)
if (tnfa->transitions[i].state) if (tnfa->transitions[i].state)
{ {
if (tnfa->transitions[i].tags) 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) 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) if (tnfa->transitions[i].params)
xfree(preg->hawk,tnfa->transitions[i].params); xfree(preg->gem,tnfa->transitions[i].params);
} }
if (tnfa->transitions) if (tnfa->transitions)
xfree(preg->hawk,tnfa->transitions); xfree(preg->gem,tnfa->transitions);
if (tnfa->initial) if (tnfa->initial)
{ {
for (trans = tnfa->initial; trans->state; trans++) for (trans = tnfa->initial; trans->state; trans++)
{ {
if (trans->tags) if (trans->tags)
xfree(preg->hawk,trans->tags); xfree(preg->gem,trans->tags);
if (trans->params) 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) if (tnfa->submatch_data)
{ {
for (i = 0; i < tnfa->num_submatches; i++) for (i = 0; i < tnfa->num_submatches; i++)
if (tnfa->submatch_data[i].parents) if (tnfa->submatch_data[i].parents)
xfree(preg->hawk,tnfa->submatch_data[i].parents); xfree(preg->gem,tnfa->submatch_data[i].parents);
xfree(preg->hawk,tnfa->submatch_data); xfree(preg->gem,tnfa->submatch_data);
} }
if (tnfa->tag_directions) if (tnfa->tag_directions)
xfree(preg->hawk,tnfa->tag_directions); xfree(preg->gem,tnfa->tag_directions);
/* HAWK: deleted */ /* HAWK: deleted */
/* /*
if (tnfa->firstpos_chars) if (tnfa->firstpos_chars)
xfree(preg->hawk,tnfa->firstpos_chars); xfree(preg->gem,tnfa->firstpos_chars);
*/ */
/* END HAWK */ /* END HAWK */
if (tnfa->minimal_tags) if (tnfa->minimal_tags)
xfree(preg->hawk,tnfa->minimal_tags); xfree(preg->gem,tnfa->minimal_tags);
xfree(preg->hawk,tnfa); xfree(preg->gem,tnfa);
} }
/* EOF */ /* EOF */

View File

@ -191,7 +191,7 @@ typedef struct tre_backtrack_struct
#define MIN(a, b) ((a) <= (b) ? (a) : (b)) #define MIN(a, b) ((a) <= (b) ? (a) : (b))
reg_errcode_t 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 len, tre_str_type_t type, int *match_tags,
int eflags, int *match_end_ofs) 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; int *states_seen = NULL;
/* Memory allocator to for allocating the backtracking stack. */ /* 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. */ /* The backtracking stack. */
tre_backtrack_t 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) if (tnfa->num_tags)
{ {
tags = xmalloc(hawk, sizeof(*tags) * tnfa->num_tags); tags = xmalloc(gem, sizeof(*tags) * tnfa->num_tags);
if (!tags) if (!tags)
{ {
ret = REG_ESPACE; 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) if (tnfa->num_submatches)
{ {
pmatch = xmalloc(hawk, sizeof(*pmatch) * tnfa->num_submatches); pmatch = xmalloc(gem, sizeof(*pmatch) * tnfa->num_submatches);
if (!pmatch) if (!pmatch)
{ {
ret = REG_ESPACE; 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) 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) if (!states_seen)
{ {
ret = REG_ESPACE; ret = REG_ESPACE;
@ -333,7 +333,7 @@ retry:
{ {
/* Backtrack to this state. */ /* Backtrack to this state. */
DPRINT(("saving state %d for backtracking\n", trans_i->state_id)); 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); trans_i->state_id, next_c, tags, mbstate);
{ {
int *tmp = trans_i->tags; int *tmp = trans_i->tags;
@ -548,7 +548,7 @@ retry:
jump back here if needed. */ jump back here if needed. */
DPRINT((" saving state %d for backtracking\n", DPRINT((" saving state %d for backtracking\n",
trans_i->state_id)); 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); trans_i->state_id, next_c, tags, mbstate);
{ {
int *tmp; int *tmp;
@ -632,9 +632,9 @@ backtrack:
error_exit: error_exit:
tre_bt_mem_destroy(mem); tre_bt_mem_destroy(mem);
if (tags) xfree(hawk, tags); if (tags) xfree(gem, tags);
if (pmatch) xfree(hawk, pmatch); if (pmatch) xfree(gem, pmatch);
if (states_seen) xfree(hawk, states_seen); if (states_seen) xfree(gem, states_seen);
return ret; return ret;
} }

View File

@ -117,7 +117,7 @@ tre_print_reach(const tre_tnfa_t *tnfa, tre_tnfa_reach_t *reach, int num_tags)
#endif /* TRE_DEBUG */ #endif /* TRE_DEBUG */
reg_errcode_t 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, tre_str_type_t type, int *match_tags, int eflags,
int *match_end_ofs) 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; + (rbytes + xbytes * tnfa->num_states) * 2 + tbytes + pbytes;
/* Allocate the memory. */ /* Allocate the memory. */
buf = xmalloc(hawk, (unsigned)total_bytes); buf = xmalloc(gem, (unsigned)total_bytes);
if (buf == NULL) return REG_ESPACE; if (buf == NULL) return REG_ESPACE;
HAWK_MEMSET(buf, 0, (size_t)total_bytes); 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); str_byte = hawk_find_bchar_in_bcstr(orig_str, first);
if (str_byte == NULL) if (str_byte == NULL)
{ {
if (buf) xfree(hawk, buf); if (buf) xfree(gem, buf);
return REG_NOMATCH; return REG_NOMATCH;
} }
DPRINT(("skipped %lu chars\n", (unsigned long)(str_byte - orig_str))); 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)); DPRINT(("match end offset = %d\n", match_eo));
if (buf) xfree(hawk, buf); if (buf) xfree(gem, buf);
*match_end_ofs = match_eo; *match_end_ofs = match_eo;
return match_eo >= 0 ? REG_OK : REG_NOMATCH; return match_eo >= 0 ? REG_OK : REG_NOMATCH;

View File

@ -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) if (*max_i > 1024)
return REG_ESPACE; return REG_ESPACE;
*max_i *= 2; *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) if (new_items == NULL)
return REG_ESPACE; return REG_ESPACE;
*items = array = new_items; *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; int num_neg_classes = 0;
/* Start off with an array of `max_i' elements. */ /* 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 (items == NULL) return REG_ESPACE;
if (*ctx->re == CHAR_CARET) 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 */ #endif /* TRE_DEBUG */
parse_bracket_done: parse_bracket_done:
xfree(ctx->mem->hawk, items); xfree(ctx->mem->gem, items);
ctx->position++; ctx->position++;
*result = node; *result = node;
return status; return status;

View File

@ -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_alloc(mem,size) hawk_pma_alloc(mem,size)
#define tre_mem_calloc(mem,size) hawk_pma_calloc(mem,size) #define tre_mem_calloc(mem,size) hawk_pma_calloc(mem,size)
#define xmalloc(hawk,size) hawk_allocmem(hawk,size) #define xmalloc(gem,size) hawk_gem_allocmem(gem,size)
#define xfree(hawk,ptr) hawk_freemem(hawk,ptr) #define xfree(gem,ptr) hawk_gem_freemem(gem,ptr)
#define xrealloc(hawk,ptr,new_size) hawk_reallocmem(hawk, ptr, new_size) #define xrealloc(gem,ptr,new_size) hawk_gem_reallocmem(gem, ptr, new_size)
/* tre-ast.h */ /* tre-ast.h */
@ -428,13 +428,13 @@ void tre_fill_pmatch(
const tre_tnfa_t *tnfa, int *tags, int match_eo); const tre_tnfa_t *tnfa, int *tags, int match_eo);
reg_errcode_t tre_tnfa_run_backtrack( 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 len, tre_str_type_t type, int *match_tags,
int eflags, int *match_end_ofs); int eflags, int *match_end_ofs);
reg_errcode_t tre_tnfa_run_parallel( 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, tre_str_type_t type, int *match_tags, int eflags,
int *match_end_ofs); int *match_end_ofs);

View File

@ -69,7 +69,7 @@ union tre_stack_item
struct tre_stack_rec struct tre_stack_rec
{ {
hawk_t* hawk; hawk_gem_t* gem;
int size; int size;
int max_size; int max_size;
int increment; 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; tre_stack_t *s;
s = xmalloc(hawk, sizeof(*s)); s = xmalloc(gem, sizeof(*s));
if (s != NULL) if (s != NULL)
{ {
s->stack = xmalloc(hawk, sizeof(*s->stack) * size); s->stack = xmalloc(gem, sizeof(*s->stack) * size);
if (s->stack == NULL) if (s->stack == NULL)
{ {
xfree(hawk, s); xfree(gem, s);
return NULL; return NULL;
} }
s->size = size; s->size = size;
s->max_size = max_size; s->max_size = max_size;
s->increment = increment; s->increment = increment;
s->ptr = 0; s->ptr = 0;
s->hawk = hawk; s->gem = gem;
} }
return s; return s;
} }
@ -103,8 +103,8 @@ tre_stack_t* tre_stack_new(hawk_t* hawk, int size, int max_size, int increment)
void void
tre_stack_destroy(tre_stack_t *s) tre_stack_destroy(tre_stack_t *s)
{ {
xfree(s->hawk,s->stack); xfree(s->gem,s->stack);
xfree(s->hawk,s); xfree(s->gem,s);
} }
int int
@ -140,7 +140,7 @@ tre_stack_push(tre_stack_t *s, union tre_stack_item value)
if (new_size > s->max_size) */ if (new_size > s->max_size) */
if (s->max_size > 0 && new_size > s->max_size) if (s->max_size > 0 && new_size > s->max_size)
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) if (new_buffer == NULL)
{ {
DPRINT(("tre_stack_push: realloc failed.\n")); DPRINT(("tre_stack_push: realloc failed.\n"));

View File

@ -71,7 +71,7 @@ typedef struct tre_stack_rec tre_stack_t;
allocated with realloc() if all space gets used up. Returns the stack allocated with realloc() if all space gets used up. Returns the stack
object or NULL if out of memory. */ object or NULL if out of memory. */
tre_stack_t * 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. */ /* Frees the stack object. */
void void

View File

@ -27,16 +27,16 @@
#include "tre-prv.h" #include "tre-prv.h"
#include "tre-compile.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; 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 (!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; 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) void hawk_tre_close (hawk_tre_t* tre)
{ {
hawk_tre_fini (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)); HAWK_MEMSET (tre, 0, HAWK_SIZEOF(*tre));
tre->hawk = hawk; tre->gem = gem;
return 0; return 0;
} }
@ -184,7 +184,7 @@ static int tre_match(
int *tags = HAWK_NULL, eo; int *tags = HAWK_NULL, eo;
if (tnfa->num_tags > 0 && nmatch > 0) 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; if (tags == HAWK_NULL) return REG_ESPACE;
} }
@ -193,21 +193,21 @@ static int tre_match(
{ {
/* The regex has back references, use the backtracking matcher. */ /* The regex has back references, use the backtracking matcher. */
status = tre_tnfa_run_backtrack ( status = tre_tnfa_run_backtrack (
preg->hawk, tnfa, string, (int)len, type, preg->gem, tnfa, string, (int)len, type,
tags, eflags, &eo); tags, eflags, &eo);
} }
else else
{ {
/* Exact matching, no back references, use the parallel matcher. */ /* Exact matching, no back references, use the parallel matcher. */
status = tre_tnfa_run_parallel ( status = tre_tnfa_run_parallel (
preg->hawk, tnfa, string, (int)len, type, preg->gem, tnfa, string, (int)len, type,
tags, eflags, &eo); tags, eflags, &eo);
} }
if (status == REG_OK) if (status == REG_OK)
/* A match was found, so fill the submatch registers. */ /* A match was found, so fill the submatch registers. */
tre_fill_pmatch(nmatch, pmatch, tnfa->cflags, tnfa, tags, eo); tre_fill_pmatch(nmatch, pmatch, tnfa->cflags, tnfa, tags, eo);
if (tags) xfree (preg->hawk, tags); if (tags) xfree (preg->gem, tags);
return status; return status;
} }