Fix symbol issues in static build.

This commit is contained in:
Adam Ierymenko 2020-06-15 15:02:07 -07:00
parent 1a38dfdbde
commit 346d4b572b
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
5 changed files with 14 additions and 8 deletions

View file

@ -43,7 +43,7 @@ void *Buf::operator new(std::size_t sz)
s_pool.store(0);
b = (Buf *) malloc(sz);
if (!b)
throw std::bad_alloc();
throw Utils::BadAllocException;
++s_allocated;
}

View file

@ -19,6 +19,7 @@
#include <iterator>
#include <algorithm>
#include <memory>
#include <stdexcept>
namespace ZeroTier {
@ -114,14 +115,14 @@ public:
{
if (likely(i < _s))
return reinterpret_cast<T *>(_m)[i];
throw std::out_of_range("i > capacity");
throw Utils::OutOfRangeException;
}
ZT_INLINE const T &operator[](const unsigned int i) const
{
if (likely(i < _s))
return reinterpret_cast<const T *>(_m)[i];
throw std::out_of_range("i > capacity");
throw Utils::OutOfRangeException;
}
static constexpr unsigned int capacity() noexcept
@ -150,7 +151,7 @@ public:
{
if (likely(_s < C))
new(reinterpret_cast<T *>(_m) + _s++) T(v);
else throw std::out_of_range("capacity exceeded");
throw Utils::OutOfRangeException;
}
/**
@ -200,7 +201,7 @@ public:
ZT_INLINE void resize(unsigned int ns)
{
if (unlikely(ns > C))
throw std::out_of_range("capacity exceeded");
throw Utils::OutOfRangeException;
unsigned int s = _s;
while (s < ns)
new(reinterpret_cast<T *>(_m) + s++) T();

View file

@ -84,6 +84,8 @@ CPUIDRegisters::CPUIDRegisters() noexcept
const CPUIDRegisters CPUID;
#endif
const std::bad_alloc BadAllocException;
const std::out_of_range OutOfRangeException("access out of range");
const uint64_t ZERO256[4] = {0, 0, 0, 0};
const char HEXCHARS[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
const uint64_t s_mapNonce = getSecureRandomU64();

View file

@ -69,6 +69,9 @@ struct CPUIDRegisters
extern const CPUIDRegisters CPUID;
#endif
extern const std::bad_alloc BadAllocException;
extern const std::out_of_range OutOfRangeException;
/**
* 256 zero bits / 32 zero bytes
*/
@ -862,7 +865,7 @@ struct Mallocator
return nullptr;
pointer temp = (pointer)malloc(s * sizeof(T));
if (temp == nullptr)
throw std::bad_alloc();
throw BadAllocException;
return temp;
}

View file

@ -14,8 +14,8 @@
package zerotier
// #cgo CFLAGS: -O3 -I${SRCDIR}/../../build/core
// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup -lc++
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all -lstdc++
// #include "../../serviceiocore/GoGlue.h"
import "C"