Skip to content

Commit

Permalink
Fix ssize_t definition. (#80)
Browse files Browse the repository at this point in the history
* Fix linter.
  • Loading branch information
trivialfis authored Feb 18, 2019
1 parent 0101a47 commit 1cc34f0
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 102 deletions.
94 changes: 50 additions & 44 deletions include/dmlc/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/*! \brief whether use glog for logging */
#ifndef DMLC_USE_GLOG
#define DMLC_USE_GLOG 0
#endif
#endif // DMLC_USE_GLOG

/*!
* \brief whether throw dmlc::Error instead of
Expand All @@ -19,23 +19,23 @@
*/
#ifndef DMLC_LOG_FATAL_THROW
#define DMLC_LOG_FATAL_THROW 1
#endif
#endif // DMLC_LOG_FATAL_THROW

/*!
* \brief whether always log a message before throw
* This can help identify the error that cannot be catched.
*/
#ifndef DMLC_LOG_BEFORE_THROW
#define DMLC_LOG_BEFORE_THROW 1
#endif
#endif // DMLC_LOG_BEFORE_THROW

/*!
* \brief Whether to use customized logger,
* whose output can be decided by other libraries.
*/
#ifndef DMLC_LOG_CUSTOMIZE
#define DMLC_LOG_CUSTOMIZE 0
#endif
#endif // DMLC_LOG_CUSTOMIZE

/*!
* \brief Wheter to print stack trace for fatal error,
Expand All @@ -45,40 +45,40 @@
&& defined(__GNUC__) && !defined(__MINGW32__) \
&& !defined(__sun) && !defined(__SVR4))
#define DMLC_LOG_STACK_TRACE 1
#endif
#endif // guards

/*! \brief whether compile with hdfs support */
#ifndef DMLC_USE_HDFS
#define DMLC_USE_HDFS 0
#endif
#endif // DMLC_USE_HDFS

/*! \brief whether compile with s3 support */
#ifndef DMLC_USE_S3
#define DMLC_USE_S3 0
#endif
#endif // DMLC_USE_S3

/*! \brief whether or not use parameter server */
#ifndef DMLC_USE_PS
#define DMLC_USE_PS 0
#endif
#endif // DMLC_USE_PS

/*! \brief whether or not use c++11 support */
#ifndef DMLC_USE_CXX11
#if defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER)
#define DMLC_USE_CXX11 1
#else
#define DMLC_USE_CXX11 (__cplusplus >= 201103L)
#endif
#endif
#endif // defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER)
#endif // DMLC_USE_CXX11

/*! \brief strict CXX11 support */
#ifndef DMLC_STRICT_CXX11
#if defined(_MSC_VER)
#define DMLC_STRICT_CXX11 1
#else
#define DMLC_STRICT_CXX11 (__cplusplus >= 201103L)
#endif
#endif
#endif // defined(_MSC_VER)
#endif // DMLC_STRICT_CXX11

/*! \brief Whether cxx11 thread local is supported */
#ifndef DMLC_CXX11_THREAD_LOCAL
Expand All @@ -87,17 +87,17 @@
#define DMLC_CXX11_THREAD_LOCAL 1
#else
#define DMLC_CXX11_THREAD_LOCAL 0
#endif
#endif // (_MSC_VER >= 1900)
#else
#define DMLC_CXX11_THREAD_LOCAL (__cplusplus >= 201103L)
#endif
#endif
#endif // defined(_MSC_VER)
#endif // DMLC_CXX11_THREAD_LOCAL


/*! \brief whether RTTI is enabled */
#ifndef DMLC_ENABLE_RTTI
#define DMLC_ENABLE_RTTI 1
#endif
#endif // DMLC_ENABLE_RTTI

/// check if g++ is before 4.6
#if DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)
Expand All @@ -107,8 +107,8 @@
"compile without c++0x, some features may be disabled")
#undef DMLC_USE_CXX11
#define DMLC_USE_CXX11 0
#endif
#endif
#endif // __GNUC__ == 4 && __GNUC_MINOR__ < 6
#endif // DMLC_USE_CXX11 && defined(__GNUC__) && !defined(__clang_version__)


/*!
Expand All @@ -117,19 +117,19 @@
*/
#ifndef DMLC_ENABLE_STD_THREAD
#define DMLC_ENABLE_STD_THREAD DMLC_USE_CXX11
#endif
#endif // DMLC_ENABLE_STD_THREAD

/*! \brief whether enable regex support, actually need g++-4.9 or higher*/
#ifndef DMLC_USE_REGEX
#define DMLC_USE_REGEX DMLC_STRICT_CXX11
#endif
#endif // DMLC_USE_REGEX

/*! \brief helper macro to supress unused warning */
#if defined(__GNUC__)
#define DMLC_ATTRIBUTE_UNUSED __attribute__((unused))
#else
#define DMLC_ATTRIBUTE_UNUSED
#endif
#endif // defined(__GNUC__)

/*! \brief helper macro to generate string concat */
#define DMLC_STR_CONCAT_(__x, __y) __x##__y
Expand All @@ -154,41 +154,46 @@
# define DISALLOW_COPY_AND_ASSIGN(T) \
T(T const&); \
T& operator=(T const&)
# endif
#endif
# endif // DMLC_USE_CXX11
#endif // DISALLOW_COPY_AND_ASSIGN

///
/// code block to handle optionally loading
///
#if !defined(__GNUC__)
#define fopen64 std::fopen
#endif
#endif // !defined(__GNUC__)

#if (defined __MINGW32__) && !(defined __MINGW64__)
#define fopen64 std::fopen
#endif
#endif // (defined __MINGW32__) && !(defined __MINGW64__)

#ifdef _MSC_VER
#if _MSC_VER < 1900

# if _MSC_VER < 1900
// NOTE: sprintf_s is not equivalent to snprintf,
// they are equivalent when success, which is sufficient for our case
#define snprintf sprintf_s
#define vsnprintf vsprintf_s
#endif
# define snprintf sprintf_s
# define vsnprintf vsprintf_s
# endif // _MSC_VER < 1900

#else
#ifdef _FILE_OFFSET_BITS
#if _FILE_OFFSET_BITS == 32
#pragma message("Warning: FILE OFFSET BITS defined to be 32 bit")
#endif
#endif

#ifdef __APPLE__
#define off64_t off_t
#define fopen64 std::fopen
#endif

# ifdef _FILE_OFFSET_BITS
# if _FILE_OFFSET_BITS == 32
# pragma message("Warning: FILE OFFSET BITS defined to be 32 bit")
# endif // _FILE_OFFSET_BITS == 32
# endif // _FILE_OFFSET_BITS

# ifdef __APPLE__
# define off64_t off_t
# define fopen64 std::fopen
# endif // __APPLE__

extern "C" {
#include <sys/types.h>
}
#endif
#endif // _MSC_VER

#ifdef _MSC_VER
//! \cond Doxygen_Suppress
Expand All @@ -203,23 +208,24 @@ typedef unsigned __int64 uint64_t;
//! \endcond
#else
#include <inttypes.h>
#endif
#endif // _MSC_VER

#include <string>
#include <vector>

#if defined(_MSC_VER) && _MSC_VER < 1900
#define noexcept_true throw ()
#define noexcept_false
#define noexcept(a) noexcept_##a
#endif
#endif // defined(_MSC_VER) && _MSC_VER < 1900

#if DMLC_USE_CXX11
#define DMLC_THROW_EXCEPTION noexcept(false)
#define DMLC_NO_EXCEPTION noexcept(true)
#else
#define DMLC_THROW_EXCEPTION
#define DMLC_NO_EXCEPTION
#endif
#endif // DMLC_USE_CXX11

/*! \brief namespace for dmlc */
namespace dmlc {
Expand Down Expand Up @@ -272,6 +278,6 @@ inline const char* BeginPtr(const std::string &str) {
#if defined(_MSC_VER) && _MSC_VER < 1900
#define constexpr const
#define alignof __alignof
#endif
#endif // defined(_MSC_VER) && _MSC_VER < 1900

#endif // DMLC_BASE_H_
12 changes: 6 additions & 6 deletions include/dmlc/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "./base.h"
#if DMLC_USE_CXX11
#include <type_traits>
#endif
#endif // DMLC_USE_CXX11
#include <string>

namespace dmlc {
Expand All @@ -25,7 +25,7 @@ struct is_pod {
#else
/*! \brief the value of the traits */
static const bool value = false;
#endif
#endif // DMLC_USE_CXX11
};


Expand All @@ -41,7 +41,7 @@ struct is_integral {
#else
/*! \brief the value of the traits */
static const bool value = false;
#endif
#endif // DMLC_USE_CXX11
};

/*!
Expand All @@ -56,7 +56,7 @@ struct is_floating_point {
#else
/*! \brief the value of the traits */
static const bool value = false;
#endif
#endif // DMLC_USE_CXX11
};

/*!
Expand All @@ -72,7 +72,7 @@ struct is_arithmetic {
/*! \brief the value of the traits */
static const bool value = (dmlc::is_integral<T>::value ||
dmlc::is_floating_point<T>::value);
#endif
#endif // DMLC_USE_CXX11
};

/*!
Expand Down Expand Up @@ -147,7 +147,7 @@ DMLC_DECLARE_TRAITS(is_integral, uint64_t, true);
DMLC_DECLARE_TRAITS(is_floating_point, float, true);
DMLC_DECLARE_TRAITS(is_floating_point, double, true);

#endif
#endif // DMLC_USE_CXX11

DMLC_DECLARE_TYPE_NAME(float, "float");
DMLC_DECLARE_TYPE_NAME(double, "double");
Expand Down
4 changes: 2 additions & 2 deletions include/rabit/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#else
#define RABIT_EXTERN_C
#include <stdio.h>
#endif
#endif // __cplusplus

#if defined(_MSC_VER) || defined(_WIN32)
#define RABIT_DLL RABIT_EXTERN_C __declspec(dllexport)
#else
#define RABIT_DLL RABIT_EXTERN_C
#endif
#endif // defined(_MSC_VER) || defined(_WIN32)

/*! \brief rabit unsigned long type */
typedef unsigned long rbt_ulong; // NOLINT(*)
Expand Down
6 changes: 3 additions & 3 deletions include/rabit/internal/rabit-inl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright by Contributors
* Copyright (c) 2014-2019 by Contributors
* \file rabit-inl.h
* \brief implementation of inline template function for rabit interface
*
Expand Down Expand Up @@ -188,7 +188,7 @@ inline void TrackerPrintf(const char *fmt, ...) {
msg.resize(strlen(msg.c_str()));
TrackerPrint(msg);
}
#endif
#endif // RABIT_STRICT_CXX98_
// load latest check point
inline int LoadCheckPoint(Serializable *global_model,
Serializable *local_model) {
Expand Down Expand Up @@ -323,6 +323,6 @@ inline void SerializeReducer<DType>::Allreduce(DType *sendrecvobj,
std::function<void()> prepare_fun) {
this->Allreduce(sendrecvobj, max_nbytes, count, InvokeLambda_, &prepare_fun);
}
#endif
#endif // DMLC_USE_CXX11
} // namespace rabit
#endif // RABIT_INTERNAL_RABIT_INL_H_
16 changes: 8 additions & 8 deletions include/rabit/internal/timer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright by Contributors
* Copyright (c) 2014-2019 by Contributors
* \file timer.h
* \brief This file defines the utils for timing
* \author Tianqi Chen, Nacho, Tianyi
Expand All @@ -10,7 +10,7 @@
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif
#endif // __MACH__
#include "./utils.h"

namespace rabit {
Expand All @@ -19,22 +19,22 @@ namespace utils {
* \brief return time in seconds, not cross platform, avoid to use this in most places
*/
inline double GetTime(void) {
#ifdef __MACH__
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
utils::Check(clock_get_time(cclock, &mts) == 0, "failed to get time");
mach_port_deallocate(mach_task_self(), cclock);
return static_cast<double>(mts.tv_sec) + static_cast<double>(mts.tv_nsec) * 1e-9;
#else
#if defined(__unix__) || defined(__linux__)
#else
#if defined(__unix__) || defined(__linux__)
timespec ts;
utils::Check(clock_gettime(CLOCK_REALTIME, &ts) == 0, "failed to get time");
return static_cast<double>(ts.tv_sec) + static_cast<double>(ts.tv_nsec) * 1e-9;
#else
#else
return static_cast<double>(time(NULL));
#endif
#endif
#endif // defined(__unix__) || defined(__linux__)
#endif // __MACH__
}
} // namespace utils
} // namespace rabit
Expand Down
Loading

0 comments on commit 1cc34f0

Please sign in to comment.