Skip to content

Commit

Permalink
src: remove VS 2013 compatibility hacks
Browse files Browse the repository at this point in the history
We can remove some Visual Studio 2013-specific workarounds now that
support for that compiler has officially been dropped.

Refs: nodejs#7484
Refs: nodejs#8049
  • Loading branch information
bnoordhuis committed Aug 11, 2016
1 parent 51d45db commit ae1fac2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 43 deletions.
21 changes: 0 additions & 21 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,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))
Expand Down
24 changes: 12 additions & 12 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@ bool ListNode<T>::IsEmpty() const {
return prev_ == this;
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
ListHead<T, M>::Iterator::Iterator(ListNode<T>* node) : node_(node) {}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
T* ListHead<T, M>::Iterator::operator*() const {
return ContainerOf(M, node_);
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<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, ListNodeMember<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, ListNodeMember<T> M>
ListHead<T, M>::~ListHead() {
while (IsEmpty() == false)
head_.next_->Remove();
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
void ListHead<T, M>::MoveBack(ListHead* that) {
if (IsEmpty())
return;
Expand All @@ -67,7 +67,7 @@ void ListHead<T, M>::MoveBack(ListHead* that) {
head_.next_ = &head_;
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
void ListHead<T, M>::PushBack(T* element) {
ListNode<T>* that = &(element->*M);
head_.prev_->next_ = that;
Expand All @@ -76,7 +76,7 @@ void ListHead<T, M>::PushBack(T* element) {
head_.prev_ = that;
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
void ListHead<T, M>::PushFront(T* element) {
ListNode<T>* that = &(element->*M);
head_.next_->prev_ = that;
Expand All @@ -85,12 +85,12 @@ void ListHead<T, M>::PushFront(T* element) {
head_.next_ = that;
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
bool ListHead<T, M>::IsEmpty() const {
return head_.IsEmpty();
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
T* ListHead<T, M>::PopFront() {
if (IsEmpty())
return nullptr;
Expand All @@ -99,12 +99,12 @@ T* ListHead<T, M>::PopFront() {
return ContainerOf(M, node);
}

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<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, ListNodeMember<T> M>
typename ListHead<T, M>::Iterator ListHead<T, M>::end() const {
return Iterator(const_cast<ListNode<T>*>(&head_));
}
Expand Down
13 changes: 3 additions & 10 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,8 @@ 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, ListNodeMember<T> M>
class ListHead;

template <typename T>
Expand All @@ -147,13 +140,13 @@ class ListNode {
inline bool IsEmpty() const;

private:
template <typename U, ListNodeMember(U) M> friend class ListHead;
template <typename U, ListNodeMember<U> M> friend class ListHead;
ListNode* prev_;
ListNode* next_;
DISALLOW_COPY_AND_ASSIGN(ListNode);
};

template <typename T, ListNodeMember(T) M>
template <typename T, ListNodeMember<T> M>
class ListHead {
public:
class Iterator {
Expand Down

0 comments on commit ae1fac2

Please sign in to comment.