void _binpachilti_sink_connect_intern(binpac_sink* sink, const hlt_type_info* type, void** pobj, binpac_parser* parser, hlt_bytes* mtype, hlt_exception** excpt, hlt_execution_context* ctx) { __parser_state* state = hlt_malloc(sizeof(__parser_state)); state->parser = parser; GC_CCTOR(state->parser, hlt_BinPACHilti_Parser, ctx); state->pobj = *pobj; GC_CCTOR_GENERIC(&state->pobj, type, ctx); state->data = 0; state->resume = 0; state->disconnected = 0; state->next = sink->head; sink->head = state; #ifdef DEBUG if ( mtype ) { hlt_string s = hlt_string_decode(mtype, Hilti_Charset_ASCII, excpt, ctx); char* r1 = hlt_string_to_native(s, excpt, ctx); char* r2 = hlt_string_to_native(parser->name, excpt, ctx); DBG_LOG("binpac-sinks", "connected parser %s [%p] to sink %p for MIME type %s", r2, *pobj, sink, r1); hlt_free(r1); hlt_free(r2); } else { char* p = hlt_string_to_native(parser->name, excpt, ctx); DBG_LOG("binpac-sinks", "connected parser %s [%p] to sink %p", p, *pobj, sink); hlt_free(p); } #endif }
void __hlt_context_set_thread_context(hlt_execution_context* ctx, hlt_type_info* type, void* tctx) { GC_DTOR_GENERIC(&ctx->tcontext, ctx->tcontext_type, ctx); ctx->tcontext = tctx; ctx->tcontext_type = type; GC_CCTOR_GENERIC(&ctx->tcontext, ctx->tcontext_type, ctx); }
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 }
static void __cctor_state(__parser_state* state, hlt_execution_context* ctx) { for ( ; state; state = state->next ) { GC_CCTOR(state->parser, hlt_BinPACHilti_Parser, ctx); GC_CCTOR_GENERIC(&state->pobj, state->parser->type_info, ctx); GC_CCTOR(state->data, hlt_bytes, ctx); GC_CCTOR(state->resume, hlt_exception, ctx); } }
static inline void _hlt_exception_init(hlt_exception* excpt, hlt_exception_type* type, void* arg, const char* location, hlt_execution_context* ctx) { excpt->type = type; if ( arg ) { excpt->arg = hlt_malloc(type->argtype->size); memcpy(excpt->arg, &arg, type->argtype->size); GC_CCTOR_GENERIC(excpt->arg, type->argtype, ctx); } else arg = 0; excpt->fiber = 0; excpt->vid = HLT_VID_MAIN; excpt->location = location; }