[svn] commit: r3186 - in /branches/vorner-sockcreator/src: bin/sockcreator/tests/Makefile.am bin/sockcreator/tests/sockcreator_tests.cc lib/util/io/fd.cc lib/util/io/fd.h lib/util/unittests/fork.cc lib/util/unittests/fork.h
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Oct 12 12:05:42 UTC 2010
Author: vorner
Date: Tue Oct 12 12:05:42 2010
New Revision: 3186
Log:
Use void * as memory buffers, not char *
For one, many builtin functions do this (memcpy, read, etc). And, it
would be more correct to use unsigned char * (because of aliasing
rules), but that makes C++ unhappy when passing string literals there.
Got rid of -fno-strict-aliasing in sockcreator tests.
Modified:
branches/vorner-sockcreator/src/bin/sockcreator/tests/Makefile.am
branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc
branches/vorner-sockcreator/src/lib/util/io/fd.cc
branches/vorner-sockcreator/src/lib/util/io/fd.h
branches/vorner-sockcreator/src/lib/util/unittests/fork.cc
branches/vorner-sockcreator/src/lib/util/unittests/fork.h
Modified: branches/vorner-sockcreator/src/bin/sockcreator/tests/Makefile.am
==============================================================================
--- branches/vorner-sockcreator/src/bin/sockcreator/tests/Makefile.am (original)
+++ branches/vorner-sockcreator/src/bin/sockcreator/tests/Makefile.am Tue Oct 12 12:05:42 2010
@@ -1,11 +1,6 @@
CLEANFILES = *.gcno *.gcda
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
-# This is here because of juggling with sockaddr pointer.
-# It is somehow required by the BSD socket interface, but it
-# breaks C++ strict aliasing rules, so we need to ask the compiler
-# not to use them.
-AM_CPPFLAGS += -fno-strict-aliasing
AM_CXXFLAGS = $(B10_CXXFLAGS)
if USE_STATIC_LINK
Modified: branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc
==============================================================================
--- branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc (original)
+++ branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc Tue Oct 12 12:05:42 2010
@@ -39,8 +39,8 @@
* This is a macro so ASSERT_* does abort the TEST, not just the
* function inside.
*/
-#define TEST_ANY_CREATE(SOCK_TYPE, ADDR_TYPE, ADDR_FAMILY, ADDR_SET, \
- CHECK_SOCK) \
+#define TEST_ANY_CREATE(SOCK_TYPE, ADDR_TYPE, ADDR_FAMILY, FAMILY_FIELD, \
+ ADDR_SET, CHECK_SOCK) \
do { \
/*
* This should create an address that binds on all interfaces
@@ -49,9 +49,9 @@
struct ADDR_TYPE addr; \
memset(&addr, 0, sizeof addr); \
ADDR_SET(addr); \
+ addr.FAMILY_FIELD = ADDR_FAMILY; \
struct sockaddr *addr_ptr = static_cast<struct sockaddr *>( \
static_cast<void *>(&addr)); \
- addr_ptr->sa_family = ADDR_FAMILY; \
\
int socket = get_sock(SOCK_TYPE, addr_ptr, sizeof addr); \
/* Provide even nice error message. */ \
@@ -89,21 +89,23 @@
* Several tests to ensure we can create the sockets.
*/
TEST(get_sock, udp4_create) {
- TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in, AF_INET, INADDR_SET, UDP_CHECK);
+ TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in, AF_INET, sin_family, INADDR_SET,
+ UDP_CHECK);
}
TEST(get_sock, tcp4_create) {
- TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in, AF_INET, INADDR_SET, TCP_CHECK);
+ TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in, AF_INET, sin_family, INADDR_SET,
+ TCP_CHECK);
}
TEST(get_sock, udp6_create) {
- TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in6, AF_INET6, IN6ADDR_SET,
- UDP_CHECK);
+ TEST_ANY_CREATE(SOCK_DGRAM, sockaddr_in6, AF_INET6, sin6_family,
+ IN6ADDR_SET, UDP_CHECK);
}
TEST(get_sock, tcp6_create) {
- TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in6, AF_INET6, IN6ADDR_SET,
- TCP_CHECK);
+ TEST_ANY_CREATE(SOCK_STREAM, sockaddr_in6, AF_INET6, sin6_family,
+ IN6ADDR_SET, TCP_CHECK);
}
/*
Modified: branches/vorner-sockcreator/src/lib/util/io/fd.cc
==============================================================================
--- branches/vorner-sockcreator/src/lib/util/io/fd.cc (original)
+++ branches/vorner-sockcreator/src/lib/util/io/fd.cc Tue Oct 12 12:05:42 2010
@@ -22,7 +22,8 @@
namespace io {
bool
-write_data(const int fd, const char *buffer, const size_t length) {
+write_data(const int fd, const void *buffer_v, const size_t length) {
+ const unsigned char *buffer(static_cast<const unsigned char *>(buffer_v));
size_t rest(length);
// Just keep writing until all is written
while (rest) {
@@ -42,7 +43,8 @@
}
ssize_t
-read_data(const int fd, char *buffer, const size_t length) {
+read_data(const int fd, void *buffer_v, const size_t length) {
+ unsigned char *buffer(static_cast<unsigned char *>(buffer_v));
size_t rest(length), already(0);
while (rest) { // Stil something to read
ssize_t amount(read(fd, buffer, rest));
Modified: branches/vorner-sockcreator/src/lib/util/io/fd.h
==============================================================================
--- branches/vorner-sockcreator/src/lib/util/io/fd.h (original)
+++ branches/vorner-sockcreator/src/lib/util/io/fd.h Tue Oct 12 12:05:42 2010
@@ -39,7 +39,7 @@
* \param length How much data is there to write.
*/
bool
-write_data(const int fd, const char *data, const size_t length);
+write_data(const int fd, const void *data, const size_t length);
/*
* \short read() that reads everything.
@@ -52,7 +52,7 @@
* \param length How many of them.
*/
ssize_t
-read_data(const int fd, char *buffer, const size_t length);
+read_data(const int fd, void *buffer, const size_t length);
}
}
Modified: branches/vorner-sockcreator/src/lib/util/unittests/fork.cc
==============================================================================
--- branches/vorner-sockcreator/src/lib/util/unittests/fork.cc (original)
+++ branches/vorner-sockcreator/src/lib/util/unittests/fork.cc Tue Oct 12 12:05:42 2010
@@ -69,7 +69,8 @@
* Used to provide the input in non-blocking/asynchronous way.
*/
pid_t
-provide_input(int *read_pipe, const char *input, const size_t length) {
+provide_input(int *read_pipe, const void *input, const size_t length)
+{
int pipes[2];
if (pipe(pipes)) {
return -1;
@@ -94,7 +95,8 @@
* with given data. Used to check output of run in asynchronous way.
*/
pid_t
-check_output(int *write_pipe, const char *output, const size_t length) {
+check_output(int *write_pipe, const void *output, const size_t length)
+{
int pipes[2];
if (pipe(pipes)) {
return -1;
@@ -105,7 +107,7 @@
return pid;
} else {
close(pipes[1]);
- char buffer[length + 1];
+ unsigned char buffer[length + 1];
// Try to read one byte more to see if the output ends here
size_t got_length(read_data(pipes[0], buffer, length + 1));
bool ok(true);
@@ -116,13 +118,15 @@
ok = false;
}
if(!ok || memcmp(buffer, output, length)) {
+ const unsigned char *output_c(static_cast<const unsigned char *>(
+ output));
// If the differ, print what we have
for(size_t i(0); i != got_length; ++ i) {
fprintf(stderr, "%02hhx", buffer[i]);
}
fprintf(stderr, "\n");
for(size_t i(0); i != length; ++ i) {
- fprintf(stderr, "%02hhx", output[i]);
+ fprintf(stderr, "%02hhx", output_c[i]);
}
fprintf(stderr, "\n");
exit(1);
Modified: branches/vorner-sockcreator/src/lib/util/unittests/fork.h
==============================================================================
--- branches/vorner-sockcreator/src/lib/util/unittests/fork.h (original)
+++ branches/vorner-sockcreator/src/lib/util/unittests/fork.h Tue Oct 12 12:05:42 2010
@@ -40,10 +40,10 @@
process_ok(pid_t process);
pid_t
-provide_input(int *read_pipe, const char *input, const size_t length);
+provide_input(int *read_pipe, const void *input, const size_t length);
pid_t
-check_output(int *write_pipe, const char *output, const size_t length);
+check_output(int *write_pipe, const void *output, const size_t length);
} // End of the namespace
}
More information about the bind10-changes
mailing list