diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-28 19:35:08 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-28 19:35:08 +0000 |
commit | 63263f9bbfab37dc221155031ee406a0d26d9b86 (patch) | |
tree | ad5f0fc703a25d0c6ace02fbf64b1a02e9dbf3a0 /ipc/ipc_message_utils.h | |
parent | 5ee921c655edd07b59c3f4671618bc40e94e4c13 (diff) | |
download | chromium_src-63263f9bbfab37dc221155031ee406a0d26d9b86.zip chromium_src-63263f9bbfab37dc221155031ee406a0d26d9b86.tar.gz chromium_src-63263f9bbfab37dc221155031ee406a0d26d9b86.tar.bz2 |
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
Diffstat (limited to 'ipc/ipc_message_utils.h')
-rw-r--r-- | ipc/ipc_message_utils.h | 71 |
1 files changed, 22 insertions, 49 deletions
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<int> { }; template <> -struct ParamTraits<long> { - typedef long param_type; +struct ParamTraits<unsigned int> { + 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<int*>(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<unsigned long> { - typedef unsigned long param_type; +struct ParamTraits<long> { + 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<unsigned long>(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<size_t> { - typedef size_t param_type; +struct ParamTraits<unsigned long> { + 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<long*>(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<uint32> { - typedef uint32 param_type; +struct ParamTraits<long long> { + typedef long long param_type; static void Write(Message* m, const param_type& p) { - m->WriteUInt32(p); + m->WriteInt64(static_cast<int64>(p)); } static bool Read(const Message* m, void** iter, param_type* r) { - return m->ReadUInt32(iter, r); + return m->ReadInt64(iter, reinterpret_cast<int64*>(r)); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%u", p)); + l->append(Int64ToWString(static_cast<int64>(p))); } }; -#endif // defined(OS_MACOSX) template <> -struct ParamTraits<int64> { - typedef int64 param_type; +struct ParamTraits<unsigned long long> { + 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<uint64> { - typedef uint64 param_type; - static void Write(Message* m, const param_type& p) { - m->WriteInt64(static_cast<int64>(p)); - } - static bool Read(const Message* m, void** iter, param_type* r) { return m->ReadInt64(iter, reinterpret_cast<int64*>(r)); } static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"%" WidePRId64, p)); + l->append(Uint64ToWString(p)); } }; |