Merge remote branch 'origin/topic/jsiwek/pybroccoli-fixes'

* origin/topic/jsiwek/pybroccoli-fixes:
  Move event arg. record coercion check; now only done for recv'd remote events
  Update istate.pybroccoli test.
This commit is contained in:
Robin Sommer 2011-07-01 18:56:27 -07:00
commit 8432258db0
2 changed files with 25 additions and 1 deletions

View file

@ -2734,6 +2734,30 @@ void RemoteSerializer::GotEvent(const char* name, double time,
e->handler = event;
e->args = args;
// If needed, coerce received record arguments to the expected record type.
if ( e->handler->FType() )
{
const type_list* arg_types = e->handler->FType()->ArgTypes()->Types();
loop_over_list(*args, i)
{
Val* v = (*args)[i];
BroType* v_t = v->Type();
BroType* arg_t = (*arg_types)[i];
if ( v_t->Tag() == TYPE_RECORD && arg_t->Tag() == TYPE_RECORD )
{
if ( ! same_type(v_t, arg_t) )
{
Val* nv = v->AsRecordVal()->CoerceTo(arg_t->AsRecordType());
if ( nv )
{
args->replace(i, nv);
Unref(v);
}
}
}
}
}
events.append(e);
}

View file

@ -14,6 +14,6 @@ Servus
[a=42, b=6.6.7.7]
42, 6.6.7.7
==== coerced record
[a=13, b=<uninitialized>, c=helloworld]
[one=<uninitialized>, a=13, b=<uninitialized>, c=helloworld, d=<uninitialized>]
13
helloworld