From 63263f9bbfab37dc221155031ee406a0d26d9b86 Mon Sep 17 00:00:00 2001 From: "deanm@chromium.org" Date: Tue, 28 Jul 2009 19:35:08 +0000 Subject: Fix the massive type confusion for ParamTraits in the IPC code. By using non-primitive types (like size_t), we are constantly having problems with duplicate definitions for the same type. Just implement all of the IPC using the primitive types (int, long, etc), and there is no confusion. Also fix a bunch of incorrect format specifiers. Review URL: http://codereview.chromium.org/159520 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21872 0039d316-1c4b-4281-b951-d872f2087c98 --- ipc/ipc_message_utils.h | 71 +++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) (limited to 'ipc') diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index 4e25b85..2b2ff91 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -147,99 +147,72 @@ struct ParamTraits { }; template <> -struct ParamTraits { - typedef long param_type; +struct ParamTraits { + typedef unsigned int param_type; static void Write(Message* m, const param_type& p) { - m->WriteLong(p); + m->WriteInt(p); } static bool Read(const Message* m, void** iter, param_type* r) { - return m->ReadLong(iter, r); + return m->ReadInt(iter, reinterpret_cast(r)); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%l", p)); + l->append(StringPrintf(L"%d", p)); } }; -#if defined(OS_LINUX) || defined(OS_WIN) -// On Linux, unsigned long is used for serializing X window ids. -// On Windows, it's used for serializing process ids. -// On Mac, it conflicts with some other definition. template <> -struct ParamTraits { - typedef unsigned long param_type; +struct ParamTraits { + typedef long param_type; static void Write(Message* m, const param_type& p) { m->WriteLong(p); } static bool Read(const Message* m, void** iter, param_type* r) { - long read_output; - if (!m->ReadLong(iter, &read_output)) - return false; - *r = static_cast(read_output); - return true; + return m->ReadLong(iter, r); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%ul", p)); + l->append(StringPrintf(L"%ld", p)); } }; -#endif template <> -struct ParamTraits { - typedef size_t param_type; +struct ParamTraits { + typedef unsigned long param_type; static void Write(Message* m, const param_type& p) { - m->WriteSize(p); + m->WriteLong(p); } static bool Read(const Message* m, void** iter, param_type* r) { - return m->ReadSize(iter, r); + return m->ReadLong(iter, reinterpret_cast(r)); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%u", p)); + l->append(StringPrintf(L"%lu", p)); } }; -#if defined(OS_MACOSX) -// On Linux size_t & uint32 can be the same type. -// TODO(playmobil): Fix compilation if this is not the case. template <> -struct ParamTraits { - typedef uint32 param_type; +struct ParamTraits { + typedef long long param_type; static void Write(Message* m, const param_type& p) { - m->WriteUInt32(p); + m->WriteInt64(static_cast(p)); } static bool Read(const Message* m, void** iter, param_type* r) { - return m->ReadUInt32(iter, r); + return m->ReadInt64(iter, reinterpret_cast(r)); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%u", p)); + l->append(Int64ToWString(static_cast(p))); } }; -#endif // defined(OS_MACOSX) template <> -struct ParamTraits { - typedef int64 param_type; +struct ParamTraits { + typedef unsigned long long param_type; static void Write(Message* m, const param_type& p) { m->WriteInt64(p); } static bool Read(const Message* m, void** iter, param_type* r) { - return m->ReadInt64(iter, r); - } - static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%" WidePRId64, p)); - } -}; - -template <> -struct ParamTraits { - typedef uint64 param_type; - static void Write(Message* m, const param_type& p) { - m->WriteInt64(static_cast(p)); - } - static bool Read(const Message* m, void** iter, param_type* r) { return m->ReadInt64(iter, reinterpret_cast(r)); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%" WidePRId64, p)); + l->append(Uint64ToWString(p)); } }; -- cgit v1.1