Incremental

This commit is contained in:
Gilbert Clark 2014-11-24 14:28:17 -05:00
parent be5cb549a9
commit 6055b56f5c
3 changed files with 114 additions and 122 deletions

View file

@ -249,38 +249,34 @@ TraversalCode Func::Traverse(TraversalCallback* cb) const
ValWrapper* Func::HandlePluginResult(ValWrapper* plugin_result, val_list* args, function_flavor flavor) const
{
// We either have not received a plugin result, or the plugin result hasn't been processed (read: fall into ::Call method)
if(!plugin_result)
return NULL;
// We either have not received a plugin result, or the plugin result hasn't been processed (read: fall into ::Call method)
if(!plugin_result)
return NULL;
if(!plugin_result->processed)
{
if(plugin_result->value)
{
Unref(plugin_result->value);
plugin_result->value = NULL;
}
delete plugin_result;
return NULL;
}
if(!plugin_result->processed)
{
if(plugin_result->value)
{
Unref(plugin_result->value);
plugin_result->value = NULL;
}
delete plugin_result;
return NULL;
}
switch ( flavor ) {
case FUNC_FLAVOR_EVENT:
if(plugin_result->value)
{
char sbuf[1024];
snprintf(sbuf, 1024, "plugin returned non-void result for event %s", this->Name());
reporter->InternalError(sbuf);
}
if(plugin_result->value)
{
reporter->InternalError("plugin returned non-void result for event %s", this->Name());
}
break;
case FUNC_FLAVOR_HOOK:
if ( plugin_result->value->Type()->Tag() != TYPE_BOOL )
{
char sbuf[1024];
snprintf(sbuf, 1024, "plugin returned non-bool for hook %s", this->Name());
reporter->InternalError(sbuf);
}
{
reporter->InternalError("plugin returned non-bool for hook %s", this->Name());
}
break;
case FUNC_FLAVOR_FUNCTION:
@ -289,19 +285,15 @@ ValWrapper* Func::HandlePluginResult(ValWrapper* plugin_result, val_list* args,
if ( (! yt) || yt->Tag() == TYPE_VOID )
{
if(plugin_result && plugin_result->value)
{
char sbuf[1024];
snprintf(sbuf, 1024, "plugin returned non-void result for void method %s", this->Name());
reporter->InternalError(sbuf);
}
}
if(plugin_result && plugin_result->value)
{
reporter->InternalError("plugin returned non-void result for void method %s", this->Name());
}
}
else if ( plugin_result->value && plugin_result->value->Type()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY)
{
char sbuf[1024];
snprintf(sbuf, 1024, "plugin returned wrong type (got %d, expecting %d) for %s", plugin_result->value->Type()->Tag(), yt->Tag(), this->Name());
reporter->InternalError(sbuf);
}
reporter->InternalError("plugin returned wrong type (got %d, expecting %d) for %s", plugin_result->value->Type()->Tag(), yt->Tag(), this->Name());
}
break;
}
@ -358,13 +350,13 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
ValWrapper* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
plugin_result = HandlePluginResult(plugin_result, args, Flavor());
if(plugin_result)
{
Val *result = plugin_result->value;
delete plugin_result;
return result;
}
plugin_result = HandlePluginResult(plugin_result, args, Flavor());
if(plugin_result)
{
Val *result = plugin_result->value;
delete plugin_result;
return result;
}
if ( bodies.empty() )
{
@ -455,11 +447,11 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
// Warn if the function returns something, but we returned from
// the function without an explicit return, or without a value.
else if ( FType()->YieldType() && FType()->YieldType()->Tag() != TYPE_VOID &&
(flow != FLOW_RETURN /* we fell off the end */ ||
! result /* explicit return with no result */) &&
! f->HasDelayed() )
(flow != FLOW_RETURN /* we fell off the end */ ||
! result /* explicit return with no result */) &&
! f->HasDelayed() )
reporter->Warning("non-void function returns without a value: %s",
Name());
Name());
if ( result && g_trace_state.DoTrace() )
{
@ -580,13 +572,13 @@ Val* BuiltinFunc::Call(val_list* args, Frame* parent) const
ValWrapper* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
plugin_result = HandlePluginResult(plugin_result, args, FUNC_FLAVOR_FUNCTION);
if(plugin_result)
{
Val *result = plugin_result->value;
delete plugin_result;
return result;
}
plugin_result = HandlePluginResult(plugin_result, args, FUNC_FLAVOR_FUNCTION);
if(plugin_result)
{
Val *result = plugin_result->value;
delete plugin_result;
return result;
}
if ( g_trace_state.DoTrace() )
{

View file

@ -83,12 +83,12 @@ void HookArgument::Describe(ODesc* d) const
d->Add("<null>");
break;
case FRAME:
if ( arg.frame )
arg.frame->Describe(d);
else
d->Add("<null>");
break;
case FRAME:
if ( arg.frame )
arg.frame->Describe(d);
else
d->Add("<null>");
break;
case FUNC:
if ( arg.func )
@ -132,24 +132,24 @@ void HookArgument::Describe(ODesc* d) const
d->Add("<void ptr>");
break;
case WRAPPED_VAL:
if ( arg.wrapper )
{
d->Add("wrapped(");
if(arg.wrapper->value)
{
arg.wrapper->value->Describe(d);
}
else
d->Add("<null>");
d->Add(")");
}
else
{
d->Add("<null>");
}
case WRAPPED_VAL:
if ( arg.wrapper )
{
d->Add("wrapped(");
if(arg.wrapper->value)
{
arg.wrapper->value->Describe(d);
}
else
d->Add("<null>");
d->Add(")");
}
else
{
d->Add("<null>");
}
break;
break;
}
}
@ -226,7 +226,7 @@ void Plugin::InitPostScript()
Plugin::bif_item_list Plugin::BifItems() const
{
return bif_items;
return bif_items;
}
void Plugin::Done()
@ -399,7 +399,7 @@ void Plugin::Describe(ODesc* d) const
type = "<unknown>";
}
d->Add(" ");
d->Add(" ");
d->Add("[");
d->Add(type);
d->Add("] ");
@ -414,7 +414,7 @@ void Plugin::Describe(ODesc* d) const
HookType hook = (*i).first;
int prio = (*i).second;
d->Add(" Implements ");
d->Add(" Implements ");
d->Add(hook_name(hook));
d->Add(" (priority ");
d->Add(prio);

View file

@ -34,24 +34,24 @@ class Plugin;
* Plugins' function handlers return a result of this type.
*/
struct ValWrapper {
Val* value; //< value being wrapped by this object
bool processed; //< true if execution should *STOP* (read: the plugin is replacing a method), and false if execution should *CONTINUE* (read: bro should execute a method)
Val* value; //< value being wrapped by this object
bool processed; //< true if execution should *STOP* (read: the plugin is replacing a method), and false if execution should *CONTINUE* (read: bro should execute a method)
/**
Wrapper for a specific value. If we're setting a value, we assume we've processed something.
/**
Wrapper for a specific value. If we're setting a value, we assume we've processed something.
@param value value to be wrapped
*/
ValWrapper(Val* value)
: value(value), processed(true) { }
@param value value to be wrapped
*/
ValWrapper(Val* value)
: value(value), processed(true) { }
/**
Wrapper for a specific value. If we're setting 'processed', we assume there's a reason we're not setting a Val and set that to NULL.
/**
Wrapper for a specific value. If we're setting 'processed', we assume there's a reason we're not setting a Val and set that to NULL.
@param processed whether or not an execution of a function was handled by the plugin
*/
ValWrapper(bool processed)
: value(NULL), processed(processed) { }
@param processed whether or not an execution of a function was handled by the plugin
*/
ValWrapper(bool processed)
: value(NULL), processed(processed) { }
};
/**
@ -237,15 +237,15 @@ public:
*/
HookArgument(void* p) { type = VOIDP; arg.voidp = p; }
/**
* Constructor with a ValWrapper argument.
*/
HookArgument(ValWrapper* a) { type = WRAPPED_VAL; arg.wrapper = a; }
/**
* Constructor with a ValWrapper argument.
*/
HookArgument(ValWrapper* a) { type = WRAPPED_VAL; arg.wrapper = a; }
/**
* Constructor with a Frame argument.
*/
HookArgument(Frame* f) { type = FRAME; arg.frame = f; }
/**
* Constructor with a Frame argument.
*/
HookArgument(Frame* f) { type = FRAME; arg.frame = f; }
/**
* Returns the value for a boolen argument. The argument's type must
@ -289,17 +289,17 @@ public:
*/
const Val* AsVal() const { assert(type == VAL); return arg.val; }
/**
* Returns the value for a Bro wrapped value argument. The argument's type must
* match accordingly.
*/
const ValWrapper* AsValWrapper() const { assert(type == VAL_WRAPPER); return arg.wrapper; }
/**
* Returns the value for a Bro wrapped value argument. The argument's type must
* match accordingly.
*/
const ValWrapper* AsValWrapper() const { assert(type == VAL_WRAPPER); return arg.wrapper; }
/**
* Returns the value for a Bro frame argument. The argument's type must
* match accordingly.
*/
const Frame* AsFrame() const { assert(type == FRAME); return arg.frame; }
/**
* Returns the value for a Bro frame argument. The argument's type must
* match accordingly.
*/
const Frame* AsFrame() const { assert(type == FRAME); return arg.frame; }
/**
* Returns the value for a list of Bro values argument. The argument's type must
@ -332,10 +332,10 @@ private:
double double_;
const Event* event;
const Func* func;
const Frame* frame;
const Frame* frame;
int int_;
const Val* val;
const ValWrapper* wrapper;
const ValWrapper* wrapper;
const val_list* vals;
const void* voidp;
} arg;
@ -564,7 +564,7 @@ protected:
* actually has code to execute for it. By calling this method, the
* plugin tells Bro to raise the event even if there's no correspondong
* handler; it will then go into HookQueueEvent() just as any other.
*
*
* @param handler The event handler being interested in.
*/
void RequestEvent(EventHandlerPtr handler);
@ -621,11 +621,11 @@ protected:
* counting.
*
* @return If the plugin handled the call, a ValWrapper with the
* processed flag set to true, and a value set on the object with
* a+1 reference count containing the result value to pass back to the
* interpreter. If the plugin did not handle the call, it may either
* return NULL *or* return a ValWrapper with the processed flag set to
* 'false'.
* processed flag set to true, and a value set on the object with
* a+1 reference count containing the result value to pass back to the
* interpreter. If the plugin did not handle the call, it may either
* return NULL *or* return a ValWrapper with the processed flag set to
* 'false'.
*/
virtual ValWrapper* HookCallFunction(const Func* func, Frame *parent, val_list* args);