Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: ppapi/shared_impl/private/net_address_private_impl.cc

Issue 824153003: replace COMPILE_ASSERT with static_assert in ppapi/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ppapi/shared_impl/ppb_trace_event_impl.cc ('k') | ppapi/thunk/ppb_text_input_thunk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/private/net_address_private_impl.h" 5 #include "ppapi/shared_impl/private/net_address_private_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <winsock2.h> 9 #include <winsock2.h>
10 #include <ws2tcpip.h> 10 #include <ws2tcpip.h>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // IPv4 addresses are 4 bytes. IPv6 are 16 bytes. Addresses are stored in net 85 // IPv4 addresses are 4 bytes. IPv6 are 16 bytes. Addresses are stored in net
86 // order (big-endian), which only affects IPv6 addresses, which consist of 8 86 // order (big-endian), which only affects IPv6 addresses, which consist of 8
87 // 16-bit components. These will be byte-swapped on small-endian hosts. 87 // 16-bit components. These will be byte-swapped on small-endian hosts.
88 uint8_t address[kIPv6AddressSize]; 88 uint8_t address[kIPv6AddressSize];
89 }; 89 };
90 90
91 // Make sure that sizeof(NetAddress) is the same for all compilers. This ensures 91 // Make sure that sizeof(NetAddress) is the same for all compilers. This ensures
92 // that the alignment is the same on both sides of the NaCl proxy, which is 92 // that the alignment is the same on both sides of the NaCl proxy, which is
93 // important because we serialize and deserialize PP_NetAddress_Private by 93 // important because we serialize and deserialize PP_NetAddress_Private by
94 // simply copying the raw bytes. 94 // simply copying the raw bytes.
95 COMPILE_ASSERT(sizeof(NetAddress) == 28, 95 static_assert(sizeof(NetAddress) == 28,
96 NetAddress_different_for_compiler); 96 "NetAddress different for compiler");
97 97
98 // Make sure the storage in |PP_NetAddress_Private| is big enough. (Do it here 98 // Make sure the storage in |PP_NetAddress_Private| is big enough. (Do it here
99 // since the data is opaque elsewhere.) 99 // since the data is opaque elsewhere.)
100 COMPILE_ASSERT(sizeof(reinterpret_cast<PP_NetAddress_Private*>(0)->data) >= 100 static_assert(sizeof(reinterpret_cast<PP_NetAddress_Private*>(0)->data) >=
101 sizeof(NetAddress), 101 sizeof(NetAddress),
102 PP_NetAddress_Private_data_too_small); 102 "PP_NetAddress_Private data too small");
103 103
104 size_t GetAddressSize(const NetAddress* net_addr) { 104 size_t GetAddressSize(const NetAddress* net_addr) {
105 return net_addr->is_ipv6 ? kIPv6AddressSize : kIPv4AddressSize; 105 return net_addr->is_ipv6 ? kIPv6AddressSize : kIPv4AddressSize;
106 } 106 }
107 107
108 // Convert to embedded struct if it has been initialized. 108 // Convert to embedded struct if it has been initialized.
109 NetAddress* ToNetAddress(PP_NetAddress_Private* addr) { 109 NetAddress* ToNetAddress(PP_NetAddress_Private* addr) {
110 if (!addr || addr->size != sizeof(NetAddress)) 110 if (!addr || addr->size != sizeof(NetAddress))
111 return NULL; 111 return NULL;
112 return reinterpret_cast<NetAddress*>(addr->data); 112 return reinterpret_cast<NetAddress*>(addr->data);
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 PP_NetAddress_IPv4* ipv4_addr) { 549 PP_NetAddress_IPv4* ipv4_addr) {
550 if (!ipv4_addr) 550 if (!ipv4_addr)
551 return false; 551 return false;
552 552
553 const NetAddress* net_addr = ToNetAddress(&addr); 553 const NetAddress* net_addr = ToNetAddress(&addr);
554 if (!IsValid(net_addr) || net_addr->is_ipv6) 554 if (!IsValid(net_addr) || net_addr->is_ipv6)
555 return false; 555 return false;
556 556
557 ipv4_addr->port = ConvertToNetEndian16(net_addr->port); 557 ipv4_addr->port = ConvertToNetEndian16(net_addr->port);
558 558
559 COMPILE_ASSERT(sizeof(ipv4_addr->addr) == kIPv4AddressSize, 559 static_assert(sizeof(ipv4_addr->addr) == kIPv4AddressSize,
560 mismatched_IPv4_address_size); 560 "mismatched IPv4 address size");
561 memcpy(ipv4_addr->addr, net_addr->address, kIPv4AddressSize); 561 memcpy(ipv4_addr->addr, net_addr->address, kIPv4AddressSize);
562 562
563 return true; 563 return true;
564 } 564 }
565 565
566 // static 566 // static
567 bool NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv6Address( 567 bool NetAddressPrivateImpl::DescribeNetAddressPrivateAsIPv6Address(
568 const PP_NetAddress_Private& addr, 568 const PP_NetAddress_Private& addr,
569 PP_NetAddress_IPv6* ipv6_addr) { 569 PP_NetAddress_IPv6* ipv6_addr) {
570 if (!ipv6_addr) 570 if (!ipv6_addr)
571 return false; 571 return false;
572 572
573 const NetAddress* net_addr = ToNetAddress(&addr); 573 const NetAddress* net_addr = ToNetAddress(&addr);
574 if (!IsValid(net_addr) || !net_addr->is_ipv6) 574 if (!IsValid(net_addr) || !net_addr->is_ipv6)
575 return false; 575 return false;
576 576
577 ipv6_addr->port = ConvertToNetEndian16(net_addr->port); 577 ipv6_addr->port = ConvertToNetEndian16(net_addr->port);
578 578
579 COMPILE_ASSERT(sizeof(ipv6_addr->addr) == kIPv6AddressSize, 579 static_assert(sizeof(ipv6_addr->addr) == kIPv6AddressSize,
580 mismatched_IPv6_address_size); 580 "mismatched IPv6 address size");
581 memcpy(ipv6_addr->addr, net_addr->address, kIPv6AddressSize); 581 memcpy(ipv6_addr->addr, net_addr->address, kIPv6AddressSize);
582 582
583 return true; 583 return true;
584 } 584 }
585 585
586 } // namespace ppapi 586 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_trace_event_impl.cc ('k') | ppapi/thunk/ppb_text_input_thunk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698