void hlt_classifier_add(hlt_classifier* c, hlt_classifier_field** fields, int64_t priority, const hlt_type_info* vtype, void* value, hlt_exception** excpt, hlt_execution_context* ctx) { if ( c->compiled ) { hlt_set_exception(excpt, &hlt_exception_value_error, 0, ctx); return; } hlt_classifier_rule* r = hlt_malloc(sizeof(hlt_classifier_rule)); r->priority = priority; r->fields = fields; r->value = _to_voidp(vtype, value); GC_CCTOR_GENERIC(r->value, vtype, ctx); if ( c->num_rules >= c->max_rules ) { // Grow rule array. int64_t old_max_rules = c->max_rules; c->max_rules = (old_max_rules ? (int)(old_max_rules * 1.5) : 5); c->rules = (hlt_classifier_rule**) hlt_realloc(c->rules, c->max_rules * sizeof(hlt_classifier_rule), old_max_rules * sizeof(hlt_classifier_rule)); } c->rules[c->num_rules++] = r; if ( priority > c->max_prio ) c->max_prio = priority; #ifdef DEBUG DBG_LOG("hilti-classifier", "%s: new rule %p with priority %d for classifier %p", "classifier_add", r, priority, c); dbg_print_fields(c, "classifier_add", fields); #endif }
void __hlt_memory_nullbuffer_add(__hlt_memory_nullbuffer* nbuf, const hlt_type_info* ti, void* obj, hlt_execution_context* ctx) { int64_t nbpos = _nullbuffer_index(nbuf, obj); if ( nbuf->flush_pos >= 0 ) { // We're flushing. if ( nbpos == nbuf->flush_pos ) // Deleting this right now. return; if ( nbpos > nbuf->flush_pos ) // In the buffer, and still getting there. return; // Either not yet in the buffer, or we passed it already. Delete // directly, we must not further modify the nullbuffer while flushing. #ifdef DEBUG __hlt_gchdr* hdr = (__hlt_gchdr*)obj; assert(hdr->ref_cnt <= 0); _UNUSED(hdr); #endif if ( ti->obj_dtor ) (*(ti->obj_dtor))(ti, obj, ctx); if ( nbpos >= 0 ) // Just to be safe. nbuf->objs[nbpos].obj = 0; __hlt_free(obj, ti->tag, "nullbuffer_add (during flush)"); return; } if ( nbpos >= 0 ) // Already in the buffer. return; #ifdef DEBUG __hlt_gchdr* hdr = (__hlt_gchdr*)obj; _dbg_mem_gc("nullbuffer_add", ti, hdr, "", 0, ctx); #endif if ( nbuf->used >= nbuf->allocated ) { size_t nsize = (nbuf->allocated * 2); nbuf->objs = (struct __obj_with_rtti*)hlt_realloc(nbuf->objs, sizeof(struct __obj_with_rtti) * nsize, sizeof(struct __obj_with_rtti) * nbuf->allocated); nbuf->allocated = nsize; } struct __obj_with_rtti x; x.ti = ti; x.obj = obj; nbuf->objs[nbuf->used++] = x; #ifdef DEBUG ++__hlt_globals()->num_nullbuffer; if ( nbuf->used > __hlt_globals()->max_nullbuffer ) // Not thread-safe, but doesn't matter. __hlt_globals()->max_nullbuffer = nbuf->used; #endif }