Browse Source

src: remove VS 2013 compatibility hacks

We can remove some Visual Studio 2013-specific workarounds now that
support for that compiler has officially been dropped.

PR-URL: https://github.com/nodejs/node/pull/8067
Refs: https://github.com/nodejs/node/issues/7484
Refs: https://github.com/nodejs/node/pull/8049
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joao Reis <reis@janeasystems.com>
v6.x
Ben Noordhuis 9 years ago
committed by Jeremiah Senkpiel
parent
commit
6ddfe89fdf
  1. 21
      src/node_internals.h
  2. 24
      src/util-inl.h
  3. 16
      src/util.h

21
src/node_internals.h

@ -106,29 +106,8 @@ void RegisterSignalHandler(int signal,
bool reset_handler = false);
#endif
#ifdef _WIN32
// emulate snprintf() on windows, _snprintf() doesn't zero-terminate the buffer
// on overflow...
// VS 2015 added a standard conform snprintf
#if defined( _MSC_VER ) && (_MSC_VER < 1900)
#include <stdarg.h>
inline static int snprintf(char *buffer, size_t n, const char *format, ...) {
va_list argp;
va_start(argp, format);
int ret = _vscprintf(format, argp);
vsnprintf_s(buffer, n, _TRUNCATE, format, argp);
va_end(argp);
return ret;
}
#endif
#endif
#if defined(_MSC_VER) && _MSC_VER < 1900
#define arraysize(a) (sizeof(a) / sizeof(*a)) // Workaround for VS 2013.
#else
template <typename T, size_t N>
constexpr size_t arraysize(const T(&)[N]) { return N; }
#endif
#ifndef ROUND_UP
# define ROUND_UP(a, b) ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))

24
src/util-inl.h

@ -28,33 +28,33 @@ bool ListNode<T>::IsEmpty() const {
return prev_ == this;
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
ListHead<T, M>::Iterator::Iterator(ListNode<T>* node) : node_(node) {}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
T* ListHead<T, M>::Iterator::operator*() const {
return ContainerOf(M, node_);
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
const typename ListHead<T, M>::Iterator&
ListHead<T, M>::Iterator::operator++() {
node_ = node_->next_;
return *this;
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
bool ListHead<T, M>::Iterator::operator!=(const Iterator& that) const {
return node_ != that.node_;
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
ListHead<T, M>::~ListHead() {
while (IsEmpty() == false)
head_.next_->Remove();
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
void ListHead<T, M>::MoveBack(ListHead* that) {
if (IsEmpty())
return;
@ -67,7 +67,7 @@ void ListHead<T, M>::MoveBack(ListHead* that) {
head_.next_ = &head_;
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
void ListHead<T, M>::PushBack(T* element) {
ListNode<T>* that = &(element->*M);
head_.prev_->next_ = that;
@ -76,7 +76,7 @@ void ListHead<T, M>::PushBack(T* element) {
head_.prev_ = that;
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
void ListHead<T, M>::PushFront(T* element) {
ListNode<T>* that = &(element->*M);
head_.next_->prev_ = that;
@ -85,12 +85,12 @@ void ListHead<T, M>::PushFront(T* element) {
head_.next_ = that;
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
bool ListHead<T, M>::IsEmpty() const {
return head_.IsEmpty();
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
T* ListHead<T, M>::PopFront() {
if (IsEmpty())
return nullptr;
@ -99,12 +99,12 @@ T* ListHead<T, M>::PopFront() {
return ContainerOf(M, node);
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
typename ListHead<T, M>::Iterator ListHead<T, M>::begin() const {
return Iterator(head_.next_);
}
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
typename ListHead<T, M>::Iterator ListHead<T, M>::end() const {
return Iterator(const_cast<ListNode<T>*>(&head_));
}

16
src/util.h

@ -135,18 +135,8 @@ template <typename T> using remove_reference = std::remove_reference<T>;
template <typename T>
class ListNode;
template <typename T>
using ListNodeMember = ListNode<T> T::*;
// VS 2013 doesn't understand dependent templates.
#ifdef _MSC_VER
#define ListNodeMember(T) ListNodeMember
#else
#define ListNodeMember(T) ListNodeMember<T>
#endif
// TAILQ-style intrusive list head.
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
class ListHead;
template <typename T>
@ -158,13 +148,13 @@ class ListNode {
inline bool IsEmpty() const;
private:
template <typename U, ListNodeMember(U) M> friend class ListHead;
template <typename U, ListNode<U> (U::*M)> friend class ListHead;
ListNode* prev_;
ListNode* next_;
DISALLOW_COPY_AND_ASSIGN(ListNode);
};
template <typename T, ListNodeMember(T) M>
template <typename T, ListNode<T> (T::*M)>
class ListHead {
public:
class Iterator {

Loading…
Cancel
Save