Skip to content

Commit

Permalink
Revert of Revert "Update legacy Tuple-using code." (patchset chromium#1
Browse files Browse the repository at this point in the history
… id:1 of https://codereview.chromium.org/826573002/)

Reason for revert:
The tests should have failed with this. Undoing the revert.

Original issue's description:
> Revert "Update legacy Tuple-using code."
>
> This reverts commit 12f4b98
>
> BUG=440675, 444827
>
> Committed: https://chromium.googlesource.com/chromium/src/+/85748694f2a119a057088f77f70b97f11607473c

TBR=
NOTREECHECKS=true
NOTRY=true
BUG=440675, 444827

Review URL: https://codereview.chromium.org/794073003

Cr-Commit-Position: refs/heads/master@{#309586}
  • Loading branch information
avi authored and Commit bot committed Dec 23, 2014
1 parent 809cd0c commit 4f841af
Show file tree
Hide file tree
Showing 8 changed files with 1,580 additions and 1,655 deletions.
65 changes: 0 additions & 65 deletions base/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,71 +124,6 @@ struct TupleLeaf {
T x;
};

// For legacy compatibility, we name the first 8 tuple elements "a", "b", ...
// TODO(mdempsky): Update users to use get<N>() (crbug.com/440675).

#define DEFINE_TUPLE_LEAF(N, x) \
template <typename T> \
struct TupleLeaf<N, T> { \
TupleLeaf() {} \
explicit TupleLeaf(typename TupleTraits<T>::ParamType x) : x(x) {} \
\
T& get() { return x; } \
const T& get() const { return x; } \
\
T x; \
}

DEFINE_TUPLE_LEAF(0, a);
DEFINE_TUPLE_LEAF(1, b);
DEFINE_TUPLE_LEAF(2, c);
DEFINE_TUPLE_LEAF(3, d);
DEFINE_TUPLE_LEAF(4, e);
DEFINE_TUPLE_LEAF(5, f);
DEFINE_TUPLE_LEAF(6, g);
DEFINE_TUPLE_LEAF(7, h);

#undef DEFINE_TUPLE_LEAF

// Deprecated compat aliases
// TODO(mdempsky): Update users to just use Tuple instead (crbug.com/440675).

using Tuple0 = Tuple<>;
template <typename A>
using Tuple1 = Tuple<A>;
template <typename A, typename B>
using Tuple2 = Tuple<A, B>;
template <typename A, typename B, typename C>
using Tuple3 = Tuple<A, B, C>;
template <typename A, typename B, typename C, typename D>
using Tuple4 = Tuple<A, B, C, D>;
template <typename A, typename B, typename C, typename D, typename E>
using Tuple5 = Tuple<A, B, C, D, E>;
template <typename A,
typename B,
typename C,
typename D,
typename E,
typename F>
using Tuple6 = Tuple<A, B, C, D, E, F>;
template <typename A,
typename B,
typename C,
typename D,
typename E,
typename F,
typename G>
using Tuple7 = Tuple<A, B, C, D, E, F, G>;
template <typename A,
typename B,
typename C,
typename D,
typename E,
typename F,
typename G,
typename H>
using Tuple8 = Tuple<A, B, C, D, E, F, G, H>;

// Tuple getters --------------------------------------------------------------
//
// Allows accessing an arbitrary tuple element by index.
Expand Down
6 changes: 3 additions & 3 deletions chrome/common/chrome_utility_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef CHROME_COMMON_CHROME_UTILITY_MESSAGES_H_
#define CHROME_COMMON_CHROME_UTILITY_MESSAGES_H_

typedef std::vector<Tuple2<SkBitmap, base::FilePath> > DecodedImages;
typedef std::vector<Tuple<SkBitmap, base::FilePath>> DecodedImages;

#endif // CHROME_COMMON_CHROME_UTILITY_MESSAGES_H_

Expand All @@ -38,9 +38,9 @@ IPC_STRUCT_TRAITS_END()

#if defined(OS_WIN)

// A vector of filters, each being a Tuple2 containing a display string (i.e.
// A vector of filters, each being a Tuple containing a display string (i.e.
// "Text Files") and a filter pattern (i.e. "*.txt").
typedef std::vector<Tuple2<base::string16, base::string16> >
typedef std::vector<Tuple<base::string16, base::string16>>
GetOpenFileNameFilter;

IPC_STRUCT_BEGIN(ChromeUtilityMsg_GetSaveFileName_Params)
Expand Down
35 changes: 18 additions & 17 deletions ipc/ipc_message_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
void (T::*func)(P*, TA)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
(obj->*func)(parameter, p.a); \
(obj->*func)(parameter, get<0>(p)); \
return true; \
} \
return false; \
Expand All @@ -469,7 +469,7 @@
void (T::*func)(P*, TA, TB)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
(obj->*func)(parameter, p.a, p.b); \
(obj->*func)(parameter, get<0>(p), get<1>(p)); \
return true; \
} \
return false; \
Expand All @@ -481,7 +481,7 @@
void (T::*func)(P*, TA, TB, TC)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
(obj->*func)(parameter, p.a, p.b, p.c); \
(obj->*func)(parameter, get<0>(p), get<1>(p), get<2>(p)); \
return true; \
} \
return false; \
Expand All @@ -494,7 +494,7 @@
void (T::*func)(P*, TA, TB, TC, TD)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
(obj->*func)(parameter, p.a, p.b, p.c, p.d); \
(obj->*func)(parameter, get<0>(p), get<1>(p), get<2>(p), get<3>(p)); \
return true; \
} \
return false; \
Expand All @@ -507,7 +507,8 @@
void (T::*func)(P*, TA, TB, TC, TD, TE)) { \
Schema::Param p; \
if (Read(msg, &p)) { \
(obj->*func)(parameter, p.a, p.b, p.c, p.d, p.e); \
(obj->*func)(parameter, get<0>(p), get<1>(p), get<2>(p), get<3>(p), \
get<4>(p)); \
return true; \
} \
return false; \
Expand Down Expand Up @@ -817,18 +818,18 @@
#define IPC_TYPE_OUT_3(t1, t2, t3) t1* arg6, t2* arg7, t3* arg8
#define IPC_TYPE_OUT_4(t1, t2, t3, t4) t1* arg6, t2* arg7, t3* arg8, t4* arg9

#define IPC_TUPLE_IN_0() Tuple0
#define IPC_TUPLE_IN_1(t1) Tuple1<t1>
#define IPC_TUPLE_IN_2(t1, t2) Tuple2<t1, t2>
#define IPC_TUPLE_IN_3(t1, t2, t3) Tuple3<t1, t2, t3>
#define IPC_TUPLE_IN_4(t1, t2, t3, t4) Tuple4<t1, t2, t3, t4>
#define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) Tuple5<t1, t2, t3, t4, t5>

#define IPC_TUPLE_OUT_0() Tuple0
#define IPC_TUPLE_OUT_1(t1) Tuple1<t1&>
#define IPC_TUPLE_OUT_2(t1, t2) Tuple2<t1&, t2&>
#define IPC_TUPLE_OUT_3(t1, t2, t3) Tuple3<t1&, t2&, t3&>
#define IPC_TUPLE_OUT_4(t1, t2, t3, t4) Tuple4<t1&, t2&, t3&, t4&>
#define IPC_TUPLE_IN_0() Tuple<>
#define IPC_TUPLE_IN_1(t1) Tuple<t1>
#define IPC_TUPLE_IN_2(t1, t2) Tuple<t1, t2>
#define IPC_TUPLE_IN_3(t1, t2, t3) Tuple<t1, t2, t3>
#define IPC_TUPLE_IN_4(t1, t2, t3, t4) Tuple<t1, t2, t3, t4>
#define IPC_TUPLE_IN_5(t1, t2, t3, t4, t5) Tuple<t1, t2, t3, t4, t5>

#define IPC_TUPLE_OUT_0() Tuple<>
#define IPC_TUPLE_OUT_1(t1) Tuple<t1&>
#define IPC_TUPLE_OUT_2(t1, t2) Tuple<t1&, t2&>
#define IPC_TUPLE_OUT_3(t1, t2, t3) Tuple<t1&, t2&, t3&>
#define IPC_TUPLE_OUT_4(t1, t2, t3, t4) Tuple<t1&, t2&, t3&, t4&>

#define IPC_NAME_IN_0() MakeTuple()
#define IPC_NAME_IN_1(t1) MakeRefTuple(arg1)
Expand Down
116 changes: 58 additions & 58 deletions ipc/ipc_message_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ struct IPC_EXPORT ParamTraits<base::TimeTicks> {
};

template <>
struct ParamTraits<Tuple0> {
typedef Tuple0 param_type;
struct ParamTraits<Tuple<>> {
typedef Tuple<> param_type;
static void Write(Message* m, const param_type& p) {
}
static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
Expand All @@ -532,112 +532,112 @@ struct ParamTraits<Tuple0> {
};

template <class A>
struct ParamTraits< Tuple1<A> > {
typedef Tuple1<A> param_type;
struct ParamTraits<Tuple<A>> {
typedef Tuple<A> param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.a);
WriteParam(m, get<0>(p));
}
static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
return ReadParam(m, iter, &r->a);
return ReadParam(m, iter, &get<0>(*r));
}
static void Log(const param_type& p, std::string* l) {
LogParam(p.a, l);
LogParam(get<0>(p), l);
}
};

template <class A, class B>
struct ParamTraits< Tuple2<A, B> > {
typedef Tuple2<A, B> param_type;
struct ParamTraits< Tuple<A, B> > {
typedef Tuple<A, B> param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.a);
WriteParam(m, p.b);
WriteParam(m, get<0>(p));
WriteParam(m, get<1>(p));
}
static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
return (ReadParam(m, iter, &r->a) &&
ReadParam(m, iter, &r->b));
return (ReadParam(m, iter, &get<0>(*r)) &&
ReadParam(m, iter, &get<1>(*r)));
}
static void Log(const param_type& p, std::string* l) {
LogParam(p.a, l);
LogParam(get<0>(p), l);
l->append(", ");
LogParam(p.b, l);
LogParam(get<1>(p), l);
}
};

template <class A, class B, class C>
struct ParamTraits< Tuple3<A, B, C> > {
typedef Tuple3<A, B, C> param_type;
struct ParamTraits< Tuple<A, B, C> > {
typedef Tuple<A, B, C> param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.a);
WriteParam(m, p.b);
WriteParam(m, p.c);
WriteParam(m, get<0>(p));
WriteParam(m, get<1>(p));
WriteParam(m, get<2>(p));
}
static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
return (ReadParam(m, iter, &r->a) &&
ReadParam(m, iter, &r->b) &&
ReadParam(m, iter, &r->c));
return (ReadParam(m, iter, &get<0>(*r)) &&
ReadParam(m, iter, &get<1>(*r)) &&
ReadParam(m, iter, &get<2>(*r)));
}
static void Log(const param_type& p, std::string* l) {
LogParam(p.a, l);
LogParam(get<0>(p), l);
l->append(", ");
LogParam(p.b, l);
LogParam(get<1>(p), l);
l->append(", ");
LogParam(p.c, l);
LogParam(get<2>(p), l);
}
};

template <class A, class B, class C, class D>
struct ParamTraits< Tuple4<A, B, C, D> > {
typedef Tuple4<A, B, C, D> param_type;
struct ParamTraits< Tuple<A, B, C, D> > {
typedef Tuple<A, B, C, D> param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.a);
WriteParam(m, p.b);
WriteParam(m, p.c);
WriteParam(m, p.d);
WriteParam(m, get<0>(p));
WriteParam(m, get<1>(p));
WriteParam(m, get<2>(p));
WriteParam(m, get<3>(p));
}
static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
return (ReadParam(m, iter, &r->a) &&
ReadParam(m, iter, &r->b) &&
ReadParam(m, iter, &r->c) &&
ReadParam(m, iter, &r->d));
return (ReadParam(m, iter, &get<0>(*r)) &&
ReadParam(m, iter, &get<1>(*r)) &&
ReadParam(m, iter, &get<2>(*r)) &&
ReadParam(m, iter, &get<3>(*r)));
}
static void Log(const param_type& p, std::string* l) {
LogParam(p.a, l);
LogParam(get<0>(p), l);
l->append(", ");
LogParam(p.b, l);
LogParam(get<1>(p), l);
l->append(", ");
LogParam(p.c, l);
LogParam(get<2>(p), l);
l->append(", ");
LogParam(p.d, l);
LogParam(get<3>(p), l);
}
};

template <class A, class B, class C, class D, class E>
struct ParamTraits< Tuple5<A, B, C, D, E> > {
typedef Tuple5<A, B, C, D, E> param_type;
struct ParamTraits< Tuple<A, B, C, D, E> > {
typedef Tuple<A, B, C, D, E> param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.a);
WriteParam(m, p.b);
WriteParam(m, p.c);
WriteParam(m, p.d);
WriteParam(m, p.e);
WriteParam(m, get<0>(p));
WriteParam(m, get<1>(p));
WriteParam(m, get<2>(p));
WriteParam(m, get<3>(p));
WriteParam(m, get<4>(p));
}
static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
return (ReadParam(m, iter, &r->a) &&
ReadParam(m, iter, &r->b) &&
ReadParam(m, iter, &r->c) &&
ReadParam(m, iter, &r->d) &&
ReadParam(m, iter, &r->e));
return (ReadParam(m, iter, &get<0>(*r)) &&
ReadParam(m, iter, &get<1>(*r)) &&
ReadParam(m, iter, &get<2>(*r)) &&
ReadParam(m, iter, &get<3>(*r)) &&
ReadParam(m, iter, &get<4>(*r)));
}
static void Log(const param_type& p, std::string* l) {
LogParam(p.a, l);
LogParam(get<0>(p), l);
l->append(", ");
LogParam(p.b, l);
LogParam(get<1>(p), l);
l->append(", ");
LogParam(p.c, l);
LogParam(get<2>(p), l);
l->append(", ");
LogParam(p.d, l);
LogParam(get<3>(p), l);
l->append(", ");
LogParam(p.e, l);
LogParam(get<4>(p), l);
}
};

Expand Down Expand Up @@ -912,7 +912,7 @@ class SyncMessageSchema {
Method func) {
Message* reply = SyncMessage::GenerateReply(msg);
if (ok) {
Tuple1<Message&> t = MakeRefTuple(*reply);
Tuple<Message&> t = MakeRefTuple(*reply);
ConnectMessageAndReply(msg, reply);
DispatchToMethod(obj, func, send_params, &t);
} else {
Expand Down
16 changes: 8 additions & 8 deletions sandbox/linux/seccomp-bpf/codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ size_t CodeGen::Offset(Node target) const {
// TODO(mdempsky): Move into a general base::Tuple helper library.
bool CodeGen::MemoKeyLess::operator()(const MemoKey& lhs,
const MemoKey& rhs) const {
if (lhs.a != rhs.a)
return lhs.a < rhs.a;
if (lhs.b != rhs.b)
return lhs.b < rhs.b;
if (lhs.c != rhs.c)
return lhs.c < rhs.c;
if (lhs.d != rhs.d)
return lhs.d < rhs.d;
if (get<0>(lhs) != get<0>(rhs))
return get<0>(lhs) < get<0>(rhs);
if (get<1>(lhs) != get<1>(rhs))
return get<1>(lhs) < get<1>(rhs);
if (get<2>(lhs) != get<2>(rhs))
return get<2>(lhs) < get<2>(rhs);
if (get<3>(lhs) != get<3>(rhs))
return get<3>(lhs) < get<3>(rhs);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion sandbox/linux/seccomp-bpf/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class SANDBOX_EXPORT CodeGen {
void Compile(Node head, Program* program);

private:
using MemoKey = Tuple4<uint16_t, uint32_t, Node, Node>;
using MemoKey = Tuple<uint16_t, uint32_t, Node, Node>;
struct MemoKeyLess {
bool operator()(const MemoKey& lhs, const MemoKey& rhs) const;
};
Expand Down
Loading

0 comments on commit 4f841af

Please sign in to comment.