From 8d04f58eda9c5890a7a93f8d9b0a720b268d2c4b Mon Sep 17 00:00:00 2001 From: Gilbert Clark Date: Fri, 19 Sep 2014 21:55:47 -0400 Subject: [PATCH] Reverting change to const status of network_time. Also, see FIXME: in Func.cc / HandlePluginResult ... --- src/Func.cc | 23 ++++++++++++++++++----- src/plugin/Manager.cc | 2 +- src/plugin/Manager.h | 2 +- src/plugin/Plugin.cc | 2 +- src/plugin/Plugin.h | 4 ++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Func.cc b/src/Func.cc index 19ed5e1ea6..9a4ff6a4fb 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -269,12 +269,28 @@ Val* Func::HandlePluginResult(Val* plugin_result, val_list* args, function_flavo if ( (! yt) || yt->Tag() == TYPE_VOID ) { Unref(plugin_result); - plugin_result = 0; + plugin_result = NULL; } else { - if ( plugin_result->Type()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY) + /* + FIXME: I know this probably isn't a good idea, but what's the better solution? + + Hack: we want a way to force a NULL return in certain cases (e.g. function delayed). Since no function should ever reasonably return + an error, we use the error type to represent this case. + + Note that re-using a type that a function could reasonably return breaks down in the case of e.g. a delayed function, where the function + will have a very specific type but still return NULL because things have not yet been evaluated. Thus, if the delayed method returns a + bool, and our garbage return value is a bool, then how do we know whether or not the Val* returned by the function is actually meaningful + in the general case? + */ + if ( plugin_result->Type()->Tag() == TYPE_ERROR ) + { + Unref(plugin_result); + plugin_result = NULL; + } + else if ( plugin_result->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->Type()->Tag(), yt->Tag(), this->Name()); @@ -286,11 +302,8 @@ Val* Func::HandlePluginResult(Val* plugin_result, val_list* args, function_flavo } } - /* - Let the plugin handle the reference counting loop_over_list(*args, i) Unref((*args)[i]); - */ return plugin_result; } diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index f416172153..60e4d4fb78 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -645,7 +645,7 @@ void Manager::HookDrainEvents() const } -void Manager::HookUpdateNetworkTime(const double network_time) const +void Manager::HookUpdateNetworkTime(double network_time) const { HookArgumentList args; diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index 349db3e483..02071fa5b7 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -261,7 +261,7 @@ public: * * @param network_time The new network time. */ - void HookUpdateNetworkTime(const double network_time) const; + void HookUpdateNetworkTime(double network_time) const; /** * Hook that informs plugins that the event queue is being drained. diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index b0ccf38990..9565236d81 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -285,7 +285,7 @@ void Plugin::HookDrainEvents() { } -void Plugin::HookUpdateNetworkTime(const double network_time) +void Plugin::HookUpdateNetworkTime(double network_time) { } diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index 7794b496b2..a921047b09 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -605,9 +605,9 @@ protected: * Hook for updates to network time. This method will be called * whenever network time is advanced. * - * @param networkt_time The new network time. + * @param network_time The new network time. */ - virtual void HookUpdateNetworkTime(const double network_time); + virtual void HookUpdateNetworkTime(double network_time); /** * Hook for destruction of objects registered with