Index: base/callback.h.pump |
diff --git a/base/callback.h.pump b/base/callback.h.pump |
index 8aecdc859d35baf57e03d589e71afd60dcd3124d..eee3371a45205edce63b957b608ff13370cf82e3 100644 |
--- a/base/callback.h.pump |
+++ b/base/callback.h.pump |
@@ -129,26 +129,26 @@ $var MAX_ARITY = 6 |
// The Callback classes represent a generic function pointer. Internally, |
// it stores a refcounted piece of state that represents the target function |
// and all its bound parameters. Each Callback specialization has a templated |
-// constructor that takes an InvokerStorageHolder<> object. In the context of |
-// the constructor, the static type of this InvokerStorageHolder<> object |
+// constructor that takes an BindStateHolder<> object. In the context of |
+// the constructor, the static type of this BindStateHolder<> object |
// uniquely identifies the function it is representing, all its bound |
// parameters, and a DoInvoke() that is capable of invoking the target. |
// |
-// Callback's constructor is takes the InvokerStorageHolder<> that has the |
+// Callback's constructor is takes the BindStateHolder<> that has the |
// full static type and erases the target function type, and the bound |
// parameters. It does this by storing a pointer to the specific DoInvoke() |
-// function, and upcasting the state of InvokerStorageHolder<> to a |
-// InvokerStorageBase. This is safe as long as this InvokerStorageBase pointer |
+// function, and upcasting the state of BindStateHolder<> to a |
+// BindStateBase. This is safe as long as this BindStateBase pointer |
// is only used with the stored DoInvoke() pointer. |
// |
-// To create InvokerStorageHolder<> objects, we use the Bind() functions. |
+// To create BindStateHolder<> objects, we use the Bind() functions. |
// These functions, along with a set of internal templates, are reponsible for |
// |
// - Unwrapping the function signature into return type, and parameters |
// - Determining the number of parameters that are bound |
// - Creating the storage for the bound parameters |
// - Performing compile-time asserts to avoid error-prone behavior |
-// - Returning an InvokerStorageHolder<> with an DoInvoke() that has an arity |
+// - Returning an BindStateHolder<> with an DoInvoke() that has an arity |
// matching the number of unbound parameters, and knows the correct |
// refcounting semantics for the target object if we are binding a class |
// method. |
@@ -250,14 +250,11 @@ class Callback<R($for ARG , [[A$(ARG)]])> : public internal::CallbackBase { |
]] |
public: |
- typedef R(*PolymorphicInvoke)( |
- internal::InvokerStorageBase*[[]] |
-$if ARITY != 0 [[, ]] |
-$for ARG , [[typename internal::ParamTraits<A$(ARG)>::ForwardType]]); |
+ typedef R(RunType)($for ARG , [[A$(ARG)]]); |
Callback() : CallbackBase(NULL, NULL) { } |
- // We pass InvokerStorageHolder by const ref to avoid incurring an |
+ // We pass BindStateHolder by const ref to avoid incurring an |
// unnecessary AddRef/Unref pair even though we will modify the object. |
// We cannot use a normal reference because the compiler will warn |
// since this is often used on a return value, which is a temporary. |
@@ -265,13 +262,13 @@ $for ARG , [[typename internal::ParamTraits<A$(ARG)>::ForwardType]]); |
// Note that this constructor CANNOT be explicit, and that Bind() CANNOT |
// return the exact Callback<> type. See base/bind.h for details. |
template <typename T> |
- Callback(const internal::InvokerStorageHolder<T>& invoker_holder) |
- : CallbackBase( |
- reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke), |
- &invoker_holder.invoker_storage_) { |
- COMPILE_ASSERT((is_same<PolymorphicInvoke, |
- typename T::Invoker::DoInvokeType>::value), |
- callback_type_does_not_match_bind_result); |
+ Callback(const internal::BindStateHolder<T>& bind_state_holder) |
+ : CallbackBase(NULL, &bind_state_holder.bind_state_) { |
+ // Force the assignment to a location variable of PolymorphicInvoke |
+ // so the compiler will typecheck that the passed in Run() method has |
+ // the correct type. |
+ PolymorphicInvoke invoke_func = &T::InvokerType::Run; |
+ polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
} |
bool Equals(const Callback& other) const { |
@@ -279,15 +276,22 @@ $for ARG , [[typename internal::ParamTraits<A$(ARG)>::ForwardType]]); |
} |
R Run($for ARG , |
- [[typename internal::ParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const { |
+ [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType a$(ARG)]]) const { |
PolymorphicInvoke f = |
reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
- return f(invoker_storage_.get()[[]] |
+ return f(bind_state_.get()[[]] |
$if ARITY != 0 [[, ]] |
$for ARG , |
[[a$(ARG)]]); |
} |
+ |
+ private: |
+ typedef R(*PolymorphicInvoke)( |
+ internal::BindStateBase*[[]] |
+$if ARITY != 0 [[, ]] |
+$for ARG , [[typename internal::CallbackParamTraits<A$(ARG)>::ForwardType]]); |
+ |
}; |