本文整理汇总了C++中xxfree函数的典型用法代码示例。如果您正苦于以下问题:C++ xxfree函数的具体用法?C++ xxfree怎么用?C++ xxfree使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xxfree函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: io_free
void io_free(struct io_buf_handle *iobh) {
if (iobh->io_buf != NULL) {
xxfree(iobh->io_buf);
(iobh->io_buf) = NULL;
}
xxfree(iobh);
}
示例2: sigma_cleanup
void sigma_cleanup (struct fsm *net, int force) {
int i,j,first,maxsigma,*attested;
struct fsm_state *fsm;
struct sigma *sig, *sig_prev, *sign;
if (force == 0) {
if (sigma_find_number(IDENTITY, net->sigma) != -1)
return;
if (sigma_find_number(UNKNOWN, net->sigma) != -1)
return;
}
maxsigma = sigma_max(net->sigma);
if (maxsigma < 0) { return; }
attested = xxmalloc(sizeof(int)*(maxsigma+1));
for (i=0; i<=maxsigma; i++)
*(attested+i) = 0;
fsm = net->states;
for (i=0; (fsm+i)->state_no != -1; i++) {
if ((fsm+i)->in >=0)
*(attested+(fsm+i)->in) = 1;
if ((fsm+i)->out >=0)
*(attested+(fsm+i)->out) = 1;
}
for (i=3,j=3; i<=maxsigma;i++ ) {
if (*(attested+i)) {
*(attested+i) = j;
j++;
}
}
for (i=0; (fsm+i)->state_no != -1; i++) {
if ((fsm+i)->in > 2)
(fsm+i)->in = *(attested+(fsm+i)->in);
if ((fsm+i)->out > 2)
(fsm+i)->out = *(attested+(fsm+i)->out);
}
sig_prev = NULL;
for (sig = net->sigma; sig != NULL && sig->number != -1; sig = sign) {
first = 1;
sign = sig->next;
if (!*(attested+(sig->number))) {
xxfree(sig->symbol);
xxfree(sig);
if (sig_prev != NULL) {
sig_prev->next = sign;
first = 0;
} else {
first = 0;
net->sigma = sign;
}
} else {
sig->number = sig->number >= 3 ? *(attested+(sig->number)) : sig->number;
}
if (first)
sig_prev = sig;
}
xxfree(attested);
return;
}
示例3: nhash_free
static void nhash_free(struct nhash_list *nptr, int size) {
struct nhash_list *nptr2, *nnext;
int i;
for (i=0; i < size; i++) {
for (nptr2 = (nptr+i)->next; nptr2 != NULL; nptr2 = nnext) {
nnext = nptr2->next;
xxfree(nptr2);
}
}
xxfree(nptr);
}
示例4: fsm_isstarfree
int fsm_isstarfree(struct fsm *net) {
#define DFS_WHITE 0
#define DFS_GRAY 1
#define DFS_BLACK 2
struct fsm *sfnet;
struct state_array *state_array;
struct fsm_state *curr_ptr;
int v, vp, is_star_free;
short int in;
char *dfs_map;
sfnet = fsm_subset(net, SUBSET_TEST_STAR_FREE);
is_star_free = 1;
state_array = map_firstlines(net);
ptr_stack_clear();
ptr_stack_push(state_array->transitions);
dfs_map = xxcalloc(sfnet->statecount, sizeof(char));
while(!ptr_stack_isempty()) {
curr_ptr = ptr_stack_pop();
nopop:
v = curr_ptr->state_no; /* source state number */
vp = curr_ptr->target; /* target state number */
if (v == -1 || vp == -1) {
*(dfs_map+v) = DFS_BLACK;
continue;
}
*(dfs_map+v) = DFS_GRAY;
in = curr_ptr->in;
if (*(dfs_map+vp) == DFS_GRAY && in == maxsigma) {
/* Not star-free */
is_star_free = 0;
break;
}
if (v == (curr_ptr+1)->state_no) {
ptr_stack_push(curr_ptr+1);
}
if (*(dfs_map+vp) == DFS_WHITE) {
curr_ptr = (state_array+vp)->transitions;
goto nopop;
}
}
ptr_stack_clear();
xxfree(dfs_map);
xxfree(state_array);
//stack_add(sfnet);
return(is_star_free);
}
示例5: apply_clear_index
void apply_clear_index(struct apply_handle *h) {
if (h->index_in) {
apply_clear_index_list(h, h->index_in);
xxfree(h->index_in);
h->index_in = NULL;
}
if (h->index_out) {
apply_clear_index_list(h, h->index_out);
xxfree(h->index_out);
h->index_out = NULL;
}
}
示例6: my_realloc_hook
static void * my_realloc_hook (void * ptr, size_t sz, const void *) {
// NULL ptr = malloc.
if (ptr == NULL) {
return xxmalloc(sz);
}
if (sz == 0) {
xxfree (ptr);
#if defined(__APPLE__)
// 0 size = free. We return a small object. This behavior is
// apparently required under Mac OS X and optional under POSIX.
return xxmalloc(1);
#else
// For POSIX, don't return anything.
return NULL;
#endif
}
size_t objSize = xxmalloc_usable_size(ptr);
#if 0
// Custom logic here to ensure we only do a logarithmic number of
// reallocations (with a constant space overhead).
// Don't change size if the object is shrinking by less than half.
if ((objSize / 2 < sz) && (sz <= objSize)) {
// Do nothing.
return ptr;
}
// If the object is growing by less than 2X, double it.
if ((objSize < sz) && (sz < objSize * 2)) {
sz = objSize * 2;
}
#endif
void * buf = xxmalloc(sz);
if (buf != NULL) {
// Successful malloc.
// Copy the contents of the original object
// up to the size of the new block.
size_t minSize = (objSize < sz) ? objSize : sz;
memcpy (buf, ptr, minSize);
xxfree (ptr);
}
// Return a pointer to the new one.
return buf;
}
示例7: e_closure_free
static void e_closure_free() {
int i;
struct e_closure_memo *eptr, *eprev;
xxfree(marktable);
for (i=0;i < num_states; i++) {
eptr = (e_closure_memo+i)->next;
for (eprev = NULL; eptr != NULL; ) {
eprev = eptr;
eptr = eptr->next;
xxfree(eprev);
}
}
xxfree(e_closure_memo);
}
示例8: xxcalloc
struct fsm_read_handle *fsm_read_init(struct fsm *net) {
struct fsm_read_handle *handle;
struct fsm_state *fsm;
int i, j, k, num_states, num_initials, num_finals, sno, *finals_head, *initials_head, *states_head;
unsigned char *lookuptable;
if (net == NULL) {return (NULL);}
num_states = net->statecount;
lookuptable = xxcalloc(num_states, sizeof(unsigned char));
num_initials = num_finals = 0;
for (i=0, fsm=net->states; (fsm+i)->state_no != -1; i++) {
sno = (fsm+i)->state_no;
if ((fsm+i)->start_state) {
if (!(*(lookuptable+sno) & 1)) {
*(lookuptable+sno) |= 1;
num_initials++;
}
}
if ((fsm+i)->final_state) {
if (!(*(lookuptable+sno) & 2)) {
*(lookuptable+sno) |= 2;
num_finals++;
}
}
}
finals_head = xxcalloc(num_finals+1,sizeof(int));
initials_head = xxcalloc(num_initials+1,sizeof(int));
states_head = xxcalloc(num_states+1,sizeof(int));
for (i=j=k=0; i < num_states; i++) {
if (*(lookuptable+i) & 1) {
*(initials_head+j) = i;
j++;
}
if (*(lookuptable+i) & 2) {
*(finals_head+k) = i;
k++;
}
*(states_head+i) = i;
}
*(initials_head+j) = -1;
*(finals_head+k) = -1;
*(states_head+i) = -1;
xxfree(lookuptable);
handle = xxcalloc(1,sizeof(struct fsm_read_handle));
handle->finals_head = finals_head;
handle->initials_head = initials_head;
handle->states_head = states_head;
handle->fsm_sigma_list = sigma_to_list(net->sigma);
handle->sigma_list_size = sigma_max(net->sigma)+1;
handle->arcs_head = fsm;
return(handle);
}
示例9: file_to_mem
struct fsm *fsm_read_text_file(char *filename) {
struct fsm_trie_handle *th;
char *text, *textp1, *textp2;
int lastword;
text = file_to_mem(filename);
if (text == NULL) {
return NULL;
}
textp1 = text;
th = fsm_trie_init();
for (lastword = 0 ; lastword == 0 ; textp1 = textp2+1) {
for (textp2 = textp1 ; *textp2 != '\n' && *textp2 != '\0'; textp2++) {
}
if (*textp2 == '\0') {
lastword = 1;
if (textp2 == textp1)
break;
}
*textp2 = '\0';
if (strlen(textp1) > 0)
fsm_trie_add_word(th, textp1);
}
xxfree(text);
return(fsm_trie_done(th));
}
示例10: apply_mark_flagstates
void apply_mark_flagstates(struct apply_handle *h) {
int i;
struct fsm_state *fsm;
/* Create bitarray with those states that have a flag symbol on an arc */
/* This is needed to decide whether we can perform a binary search. */
if (!h->has_flags || h->flag_lookup == NULL) {
return;
}
if (h->flagstates) {
xxfree(h->flagstates);
}
h->flagstates = xxcalloc(BITNSLOTS(h->last_net->statecount), sizeof(uint8_t));
fsm = h->last_net->states;
for (i=0; (fsm+i)->state_no != -1; i++) {
if ((fsm+i)->target == -1) {
continue;
}
if ((h->flag_lookup+(fsm+i)->in)->type) {
BITSET(h->flagstates,(fsm+i)->state_no);
}
if ((h->flag_lookup+(fsm+i)->out)->type) {
BITSET(h->flagstates,(fsm+i)->state_no);
}
}
}
示例11: add_defined
int add_defined (struct fsm *net, char *string) {
struct defined *defined, *defined_prev;
int redefine;
redefine = 0;
if (net == NULL) { return 0; }
fsm_count(net);
if (defines == NULL) {
defined = xxmalloc(sizeof(struct defined));
defines = defined;
defined->next = NULL;
} else {
for (defined = defines; defined != NULL; defined = defined->next) {
defined_prev = defined;
if (strcmp(defined->name, string) == 0) {
redefine = 1;
break;
}
}
if (redefine == 0) {
defined_prev->next = xxmalloc(sizeof(struct defined));
defined = defined_prev->next;
defined->next = NULL;
}
}
if (redefine) {
fsm_destroy(defined->net);
xxfree(defined->name);
}
defined->name = xxstrdup(string);
defined->net = net;
return(redefine);
}
示例12: my_memalign_hook
static void * my_memalign_hook (size_t size, size_t alignment, const void *) {
// Check for non power-of-two alignment, or mistake in size.
if ((alignment == 0) ||
(alignment & (alignment - 1)))
{
return NULL;
}
// Try to just allocate an object of the requested size.
// If it happens to be aligned properly, just return it.
void * ptr = xxmalloc (size);
if (((size_t) ptr & (alignment - 1)) == (size_t) ptr) {
// It is already aligned just fine; return it.
return ptr;
}
// It was not aligned as requested: free the object.
xxfree (ptr);
// Now get a big chunk of memory and align the object within it.
// NOTE: this REQUIRES that the underlying allocator be able
// to free the aligned object, or ignore the free request.
void * buf = xxmalloc (2 * alignment + size);
void * alignedPtr = (void *) (((size_t) buf + alignment - 1) & ~(alignment - 1));
return alignedPtr;
}
示例13: return
struct fsm *fsm_construct_done(struct fsm_construct_handle *handle) {
int i;
struct fsm *net;
struct fsm_state_list *sl;
struct fsm_trans_list *trans, *transnext;
struct fsm_sigma_hash *sigmahash, *sigmahashnext;
sl = handle->fsm_state_list;
if (handle->maxstate == -1 || handle->numfinals == 0) {
return(fsm_empty_set());
}
fsm_state_init((handle->maxsigma)+1);
for (i=0; i <= handle->maxstate; i++) {
fsm_state_set_current_state(i, (sl+i)->is_final, (sl+i)->is_initial);
for (trans = (sl+i)->fsm_trans_list; trans != NULL; trans = trans->next) {
fsm_state_add_arc(i, trans->in, trans->out, trans->target, (sl+i)->is_final, (sl+i)->is_initial);
}
fsm_state_end_state();
}
net = fsm_create("");
xxfree(net->sigma);
fsm_state_close(net);
net->sigma = fsm_construct_convert_sigma(handle);
if (handle->name != NULL) {
strncpy(net->name, handle->name, 40);
xxfree(handle->name);
} else {
sprintf(net->name, "%X",rand());
}
/* Free transitions */
for (i=0; i < handle->fsm_state_list_size; i++) {
trans = (((handle->fsm_state_list)+i)->fsm_trans_list);
while (trans != NULL) {
transnext = trans->next;
xxfree(trans);
trans = transnext;
}
}
/* Free hash table */
for (i=0; i < SIGMA_HASH_SIZE; i++) {
sigmahash = (((handle->fsm_sigma_hash)+i)->next);
while (sigmahash != NULL) {
sigmahashnext = sigmahash->next;
xxfree(sigmahash);
sigmahash = sigmahashnext;
}
}
xxfree(handle->fsm_sigma_list);
xxfree(handle->fsm_sigma_hash);
xxfree(handle->fsm_state_list);
xxfree(handle);
sigma_sort(net);
return(net);
}
示例14: sigma_sort
int sigma_sort(struct fsm *net) {
#ifdef ORIGINAL
int(*comp)() = ssortcmp;
#else
int(*comp)(const void*, const void*) = ssortcmp;
#endif
int size, i, max, *replacearray;
struct ssort *ssort;
struct sigma *sigma;
struct fsm_state *fsm_state;
size = sigma_max(net->sigma);
if (size < 0) { return 1; }
ssort = xxmalloc(sizeof(struct ssort)*size);
for (i=0, sigma=net->sigma; sigma != NULL; sigma=sigma->next) {
if (sigma->number > IDENTITY) {
ssort[i].symbol = (char *)sigma->symbol;
ssort[i].number = sigma->number;
i++;
}
}
max = i;
qsort(ssort, max, sizeof(struct ssort), comp);
replacearray = xxmalloc(sizeof(int)*(size+3));
for (i=0; i<max; i++)
replacearray[(ssort+i)->number] = i+3;
/* Replace arcs */
for(i=0, fsm_state = net->states; (fsm_state+i)->state_no != -1; i++) {
if ((fsm_state+i)->in > IDENTITY)
(fsm_state+i)->in = replacearray[(fsm_state+i)->in];
if ((fsm_state+i)->out > IDENTITY)
(fsm_state+i)->out = replacearray[(fsm_state+i)->out];
}
/* Replace sigma */
for (i=0, sigma=net->sigma; sigma != NULL; sigma=sigma->next) {
if (sigma->number > IDENTITY) {
sigma->number = i+3;
sigma->symbol = (ssort+i)->symbol;
i++;
}
}
xxfree(replacearray);
xxfree(ssort);
return(1);
}
示例15: sh_done
void sh_done(struct sh_handle *sh) {
int i;
struct sh_hashtable *hash, *hashp;
for (i=0; i < STRING_HASH_SIZE; i++) {
hash = sh->hash + i;
if (hash->string != NULL)
xxfree(hash->string);
for (hash=hash->next ; hash != NULL ; hash = hashp) {
hashp = hash->next;
if (hash->string != NULL)
xxfree(hash->string);
xxfree(hash);
}
}
xxfree(sh->hash);
xxfree(sh);
}