Browse Source

Fix building on MacOS

There were a number of issues that built up over time as we weren't
testing on OS X, and as clang got more pedantic. They are listed below
as best I understand them:

htonll - OS X defines this. Linux does not. We took a few strategies to
get around this:

 - Remove unused htonll defs/calls
 - Do not try to redefine htonll
 - Add HAVE_HTONLL to ifdef around when necessary.

The pragmas in libgearman/command and error_code allow us to keep
building while gperf fixes their issues that clang exposes. We tried
with gperf 3.1, but this only fixed the register issue, not the cast
precision warnings.

A few things were just minor warnings that clang reports that gcc does
not.
Clint Byrum 7 years ago
parent
commit
fb05e80af2

+ 2 - 0
configure.ac

@@ -175,6 +175,8 @@ AC_CHECK_HEADERS_ONCE([syslog.h])
 AC_CHECK_HEADERS_ONCE([unistd.h])
 AC_CHECK_HEADERS_ONCE([winsock2.h])
 AC_CHECK_HEADERS_ONCE([libmemcached-1.0/types/return.h])
+AC_CHECK_DECL([htonll],[AC_DEFINE([HAVE_HTONLL],[1],
+              [Define to 1 if you have htonll.])])
 
 AM_CONDITIONAL([BUILD_WIN32_WRAPPERS],[test "x$ac_cv_header_winsock2_h" = "xyes"])
 AS_IF([test "x$ac_cv_header_winsock2_h" = "xyes"],

+ 0 - 76
libgearman-server/byteorder.cc

@@ -1,76 +0,0 @@
-/*
-  Taken from libmemcached.
- */
-
-/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- * 
- *  Gearmand client and server library.
- *
- *  Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
- *  Copyright (C) 2006-2009 Brian Aker
- *  All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are
- *  met:
- *
- *      * Redistributions of source code must retain the above copyright
- *  notice, this list of conditions and the following disclaimer.
- *
- *      * Redistributions in binary form must reproduce the above
- *  copyright notice, this list of conditions and the following disclaimer
- *  in the documentation and/or other materials provided with the
- *  distribution.
- *
- *      * The names of its contributors may not be used to endorse or
- *  promote products derived from this software without specific prior
- *  written permission.
- *
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "gear_config.h"
-
-#include <libgearman-server/byteorder.h>
-
-#ifndef swap64
-/* Byte swap a 64-bit number. */
-static inline uint64_t swap64(uint64_t in)
-{
- #ifndef WORDS_BIGENDIAN
-  /* Little endian, flip the bytes around until someone makes a faster/better
-   * way to do this. */
-  uint64_t rv= 0;
-  for (uint8_t x= 0; x < 8; ++x)
-  {
-    rv= (rv << 8) | (in & 0xff);
-    in >>= 8;
-  }
-  return rv;
- #else
-  /* big-endian machines don't need byte swapping */
-  return in;
- #endif
-}
-#endif
-
-uint64_t ntohll(uint64_t value)
-{
-  return swap64(value);
-}
-
-uint64_t htonll(uint64_t value)
-{
-  return swap64(value);
-}

+ 0 - 67
libgearman-server/byteorder.h

@@ -1,67 +0,0 @@
-/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- * 
- *  Gearmand client and server library.   
- *  Taken from libmemcached.
- *
- *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
- *  Copyright (C) 2006-2009 Brian Aker All rights reserved.
- *
- *  Redistribution and use in source and binary forms, with or without
- *  modification, are permitted provided that the following conditions are
- *  met:
- *
- *      * Redistributions of source code must retain the above copyright
- *  notice, this list of conditions and the following disclaimer.
- *
- *      * Redistributions in binary form must reproduce the above
- *  copyright notice, this list of conditions and the following disclaimer
- *  in the documentation and/or other materials provided with the
- *  distribution.
- *
- *      * The names of its contributors may not be used to endorse or
- *  promote products derived from this software without specific prior
- *  written permission.
- *
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#pragma once
-
-#ifndef HAVE_HTONLL
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-uint64_t ntohll(uint64_t);
-
-uint64_t htonll(uint64_t);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-#ifdef linux
-/* /usr/include/netinet/in.h defines macros from ntohs() to _bswap_nn to
- * optimize the conversion functions, but the prototypes generate warnings
- * from gcc. The conversion methods isn't the bottleneck for my app, so
- * just remove the warnings by undef'ing the optimization ..
- */
-#undef ntohs
-#undef ntohl
-#undef htons
-#undef htonl
-#endif

+ 0 - 1
libgearman-server/common.h

@@ -44,7 +44,6 @@
 #pragma once
 
 #include <libgearman-server/gearmand.h>
-#include <libgearman-server/byteorder.h>
 #include "libgearman-server/config.hpp"
 
 #include "libgearman/assert.hpp"

+ 0 - 1
libgearman-server/gearmand.h

@@ -57,7 +57,6 @@
 
 #include <libgearman-server/constants.h>
 #include <libgearman-server/wakeup.h>
-#include <libgearman-server/byteorder.h>
 #include <libgearman-server/log.h>
 #include <libgearman-server/packet.h>
 #include <libgearman-server/connection.h>

+ 0 - 2
libgearman-server/include.am

@@ -31,7 +31,6 @@ noinst_HEADERS+= libgearman-server/queue.hpp
 noinst_HEADERS+= libgearman-server/text.h
 noinst_HEADERS+= \
 		 libgearman-server/byte.h \
-		 libgearman-server/byteorder.h \
 		 libgearman-server/client.h \
 		 libgearman-server/common.h \
 		 libgearman-server/config.h \
@@ -61,7 +60,6 @@ libgearman_server_libgearman_server_la_SOURCES+= libgearman/vector.cc
 libgearman_server_libgearman_server_la_SOURCES+= libgearman-server/text.cc
 libgearman_server_libgearman_server_la_SOURCES+= libgearman-server/config.cc
 libgearman_server_libgearman_server_la_SOURCES+= \
-						 libgearman-server/byteorder.cc \
 						 libgearman-server/client.cc \
 						 libgearman-server/connection.cc \
 						 libgearman-server/function.cc \

+ 1 - 1
libgearman-server/server.cc

@@ -623,7 +623,7 @@ gearmand_error_t gearman_server_run_command(gearman_server_con_st *server_con,
                                           server_job->data, server_job->data_size,
                                           NULL);
       }
-      else if (packet->command == GEARMAN_COMMAND_GRAB_JOB_ALL and server_job->reducer)
+      else if (packet->command == GEARMAN_COMMAND_GRAB_JOB_ALL and *server_job->reducer != '\0')
       {
         gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM,
                            "Sending reduce submission, Partitioner: %.*s(%lu) Reducer: %.*s(%lu) Unique: %.*s(%lu) with data sized (%lu)" ,

+ 4 - 0
libgearman/byteorder.cc

@@ -65,6 +65,8 @@ static inline uint64_t swap64(uint64_t in)
 }
 #endif
 
+#ifndef HAVE_HTONLL
+
 uint64_t ntohll(uint64_t value)
 {
   return swap64(value);
@@ -74,3 +76,5 @@ uint64_t htonll(uint64_t value)
 {
   return swap64(value);
 }
+
+#endif

+ 0 - 10
libgearman/byteorder.h

@@ -40,16 +40,6 @@
 
 #pragma once
 
-#ifndef HAVE_HTONLL
-
-GEARMAN_INTERNAL_API
-uint64_t ntohll(uint64_t);
-
-GEARMAN_INTERNAL_API
-uint64_t htonll(uint64_t);
-
-#endif
-
 #ifdef linux
 /* /usr/include/netinet/in.h defines macros from ntohs() to _bswap_nn to
  * optimize the conversion functions, but the prototypes generate warnings

+ 9 - 1
libgearman/command.cc

@@ -40,7 +40,15 @@
 #include <libgearman/common.h>
 
 #include <libgearman-1.0/visibility.h>
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-register"
+#pragma clang diagnostic ignored "-Wshorten-64-to-32"
+#endif
 #include "libgearman/command.hpp"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 #include "libgearman/strcommand.h"
 
 #include "libgearman/assert.hpp"
@@ -133,7 +141,7 @@ const gearman_command_info_st *gearman_command_info(gearman_command_t command)
   return command_info;
 }
 
-const struct gearman_command_info_st * gearman_command_lookup (register const char *str, register unsigned int len)
+const struct gearman_command_info_st * gearman_command_lookup (const char *str, unsigned int len)
 {
   const struct gearman_command_string_st* com_str= String2gearman_command_t::in_word_set(str, len);
   return gearman_command_info(com_str->code);

Some files were not shown because too many files changed in this diff