void flx_collector_t::scan_object(void *p, int reclimit) { Word_t reachable = (parity & 1UL) ^ 1UL; again: if(debug) fprintf(stderr,"Scan object %p, reachable bit value = %d\n",p,(int)reachable); Word_t cand = (Word_t)p; Word_t head=cand; Word_t *ppshape = (Word_t*)JudyLLast(j_shape,&head,&je); if(ppshape==(Word_t*)PPJERR)judyerror("scan_object"); if(ppshape == NULL) return; // no lower object /* if(debug) { fprintf(stderr,"Found candidate object %p, &shape=%p, shape(1) %p\n",(void*)fp,(void*)w,(void*)(*w)); fprintf(stderr," .. type=%s!\n",((gc_shape_t*)(*w & ~1UL))->cname); } */ if( (*ppshape & 1UL) == reachable) return; // already handled gc_shape_t *pshape = (gc_shape_t*)(*ppshape & ~1UL); unsigned long n = get_count((void*)head) * pshape->count * pshape->amt; if(cand >= (Word_t)(void*)((unsigned char*)(void*)head+n)) return; // not interior if(debug) fprintf(stderr,"MARKING object %p, shape %p, type=%s\n",(void*)head,pshape,pshape->cname); *ppshape = (*ppshape & ~1uL) | reachable; if(pshape->flags & gc_flags_conservative) { unsigned long n_used = get_used((void*)head) * pshape->count; // end of object, rounded down to size of a void* void **end = (void**)( (unsigned char*)(void*)head + n_used * n / sizeof(void*) * sizeof(void*) ); for ( void **i = (void**)head; i != end; i = i+1) { //if(debug) // fprintf(stderr, "Check if *%p=%p is a pointer\n",i,*(void**)i); if(reclimit==0) Judy1Set(&j_tmp,(Word_t)*i,&je); else scan_object(*i,reclimit -1); } } else { unsigned long dyncount = get_used((void*)head); if(pshape->scanner) { void *r = pshape->scanner(this, pshape, (void*)head,dyncount,reclimit); if (r) { p = r; goto again; } } } }
strp ugh_client_cookie_out_set(ugh_client_t *c, char *data, size_t size) { strp vptr = aux_pool_malloc(c->pool, sizeof(*vptr)); if (NULL == vptr) return NULL; Judy1Set(&c->cookies_out_hash, (Word_t) vptr, PJE0); vptr->data = data; vptr->size = size; return vptr; }
char set_s_selected(struct symbol *s, char value) { if(value) { Judy1Set ((Pvoid_t)&GLOBALS->s_selected, (Word_t)s, PJE0); } else { Judy1Unset ((Pvoid_t)&GLOBALS->s_selected, (Word_t)s, PJE0); } return(value); }
int Judy1Dup(PPvoid_t PPDest, Pvoid_t PSource, JError_t * PJError) { Pvoid_t newJArray = 0; // new Judy1 array to ppopulate Word_t kindex; // Key/index int Ins_rv = 0; // Insert return value for (kindex = 0L, Ins_rv = Judy1First(PSource, &kindex, PJError); Ins_rv == 1; Ins_rv = Judy1Next(PSource, &kindex, PJError)) { Ins_rv = Judy1Set(&newJArray, kindex, PJError); } if (Ins_rv == JERR) return Ins_rv; *PPDest = newJArray; return Ins_rv; } /* Judy1Dup */
static PyObject* PyJudyIntSet_add(PyJudyIntSet* self, PyObject* key) { Word_t v; if (!pyobject_as_word_t(key, &v)) { PyErr_Format(PyExc_ValueError, "we only support integers in the range [0, 2**%i-1]", sizeof(Word_t) == 4 ? 32 : 64); return 0; } JError_t JError; Word_t w = Judy1Set(&self->s, v, &JError); if (w == JERR) { judy_set_error(&JError); return 0; } Py_INCREF(Py_None); return Py_None; }
void build_tree_from_name(const char *s, int which) { struct tree *t, *nt; struct tree *tchain = NULL, *tchain_iter; struct tree *prevt; #ifdef _WAVE_HAVE_JUDY PPvoid_t PPValue = NULL; char str[2048]; #endif if(s==NULL || !s[0]) return; t = GLOBALS->treeroot; if(t) { prevt = NULL; while(s) { rs: s=get_module_name(s); if(t && !strcmp(t->name, GLOBALS->module_tree_c_1)) { prevt = t; t = t->child; continue; } #ifdef _WAVE_HAVE_JUDY rescan: if(prevt && prevt->children_in_gui) { /* find with judy */ int len = gen_hier_string(str, prevt); strcpy(str+len, GLOBALS->module_tree_c_1); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); if(*PPValue) { t = *PPValue; prevt = t; t = t->child; continue; } goto construct; } #endif tchain = tchain_iter = t; if(s && t) { #ifdef _WAVE_HAVE_JUDY int dep = 0; #endif nt = t->next; while(nt) { if(nt && !strcmp(nt->name, GLOBALS->module_tree_c_1)) { /* move to front to speed up next compare if in same hier during build */ if(prevt) { tchain_iter->next = nt->next; nt->next = tchain; prevt->child = nt; } prevt = nt; t = nt->child; goto rs; } tchain_iter = nt; nt = nt->next; #ifdef _WAVE_HAVE_JUDY dep++; #endif } #ifdef _WAVE_HAVE_JUDY if(prevt && (dep >= FST_TREE_SEARCH_NEXT_LIMIT)) { int len = gen_hier_string(str, prevt); prevt->children_in_gui = 1; /* "borrowed" for tree build */ t = prevt->child; Judy1Set ((Pvoid_t)&GLOBALS->sym_tree_addresses, (Word_t)prevt, PJE0); /* assemble judy based on scopename + prevt pnt */ while(t) { strcpy(str+len, t->name); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); *PPValue = t; t = t->next; } goto rescan; /* this level of hier is built, now do insert */ } #endif } #ifdef _WAVE_HAVE_JUDY construct: #endif nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1); memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1); if(s) { nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME; #ifdef _WAVE_HAVE_JUDY if(prevt && prevt->children_in_gui) { *PPValue = nt; } #endif if(prevt) /* make first in chain */ { nt->next = prevt->child; prevt->child = nt; } else /* make second in chain as it's toplevel */ { nt->next = tchain->next; tchain->next = nt; } } else { nt->child = prevt; /* parent */ nt->t_which = which; nt->next = GLOBALS->terminals_tchain_tree_c_1; GLOBALS->terminals_tchain_tree_c_1 = nt; return; } /* blindly clone fac from next part of hier on down */ t = nt; while(s) { s=get_module_name(s); nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1); memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1); if(s) { nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME; t->child = nt; t = nt; } else { nt->child = t; /* parent */ nt->t_which = which; nt->next = GLOBALS->terminals_tchain_tree_c_1; GLOBALS->terminals_tchain_tree_c_1 = nt; } } } } else { /* blindly create first fac in the tree (only ever called once) */ while(s) { s=get_module_name(s); nt=(struct tree *)talloc_2(sizeof(struct tree)+GLOBALS->module_len_tree_c_1); memcpy(nt->name, GLOBALS->module_tree_c_1, GLOBALS->module_len_tree_c_1); if(!s) nt->t_which=which; else nt->t_which = WAVE_T_WHICH_UNDEFINED_COMPNAME; if((GLOBALS->treeroot)&&(t)) /* scan-build : && t should be unnecessary to avoid null pointer deref, but add defensively */ { t->child = nt; t = nt; } else { GLOBALS->treeroot = t = nt; } } } }
/* * decorated module add */ void allocate_and_decorate_module_tree_node(unsigned char ttype, const char *scopename, const char *compname, uint32_t scopename_len, uint32_t compname_len, uint32_t t_stem, uint32_t t_istem) { struct tree *t; int mtyp = WAVE_T_WHICH_UNDEFINED_COMPNAME; #ifdef _WAVE_HAVE_JUDY char str[2048]; #endif if(compname && compname[0] && strcmp(scopename, compname)) { int ix = add_to_comp_name_table(compname, compname_len); if(ix) { ix--; mtyp = WAVE_T_WHICH_COMPNAME_START - ix; } } if(GLOBALS->treeroot) { if(GLOBALS->mod_tree_parent) { #ifdef _WAVE_HAVE_JUDY if(GLOBALS->mod_tree_parent->children_in_gui) { PPvoid_t PPValue; /* find with judy */ int len = gen_hier_string(str, GLOBALS->mod_tree_parent); strcpy(str+len, scopename); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); if(*PPValue) { GLOBALS->mod_tree_parent = *PPValue; return; } t = talloc_2(sizeof(struct tree) + scopename_len); *PPValue = t; goto t_allocated; } else { int dep = 0; #endif t = GLOBALS->mod_tree_parent->child; while(t) { if(!strcmp(t->name, scopename)) { GLOBALS->mod_tree_parent = t; return; } t = t->next; #ifdef _WAVE_HAVE_JUDY dep++; #endif } #ifdef _WAVE_HAVE_JUDY if(dep >= FST_TREE_SEARCH_NEXT_LIMIT) { PPvoid_t PPValue; int len = gen_hier_string(str, GLOBALS->mod_tree_parent); GLOBALS->mod_tree_parent->children_in_gui = 1; /* "borrowed" for tree build */ t = GLOBALS->mod_tree_parent->child; Judy1Set ((Pvoid_t)&GLOBALS->sym_tree_addresses, (Word_t)GLOBALS->mod_tree_parent, PJE0); /* assemble judy based on scopename + GLOBALS->mod_tree_parent pnt */ while(t) { strcpy(str+len, t->name); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); *PPValue = t; t = t->next; } strcpy(str+len, scopename); PPValue = JudySLIns(&GLOBALS->sym_tree, (uint8_t *)str, PJE0); t = talloc_2(sizeof(struct tree) + scopename_len); *PPValue = t; goto t_allocated; } } #endif t = talloc_2(sizeof(struct tree) + scopename_len); #ifdef _WAVE_HAVE_JUDY t_allocated: #endif strcpy(t->name, scopename); t->kind = ttype; t->t_which = mtyp; t->t_stem = t_stem; t->t_istem = t_istem; if(GLOBALS->mod_tree_parent->child) { t->next = GLOBALS->mod_tree_parent->child; } GLOBALS->mod_tree_parent->child = t; GLOBALS->mod_tree_parent = t; } else { t = GLOBALS->treeroot; while(t) { if(!strcmp(t->name, scopename)) { GLOBALS->mod_tree_parent = t; return; } t = t->next; } t = talloc_2(sizeof(struct tree) + scopename_len); strcpy(t->name, scopename); t->kind = ttype; t->t_which = mtyp; t->t_stem = t_stem; t->t_istem = t_istem; t->next = GLOBALS->treeroot; GLOBALS->mod_tree_parent = GLOBALS->treeroot = t; } } else { t = talloc_2(sizeof(struct tree) + scopename_len); strcpy(t->name, scopename); t->kind = ttype; t->t_which = mtyp; t->t_stem = t_stem; t->t_istem = t_istem; GLOBALS->mod_tree_parent = GLOBALS->treeroot = t; } }
void flx_collector_t::register_pointer(void *q, int reclimit) { if(reclimit==0)Judy1Set(&j_tmp,(Word_t)q,&je); else scan_object(q, reclimit-1); }
void flx_collector_t::post_delete(void *fp) { Judy1Set(&j_tmp,(Word_t)fp,&je); }