Skip to content

Commit 48cd904

Browse files
committed
Various beast cleanups
1 parent 69d1771 commit 48cd904

File tree

6 files changed

+43
-24
lines changed

6 files changed

+43
-24
lines changed

Subtrees/beast/modules/beast_core/memory/beast_Atomic.h

+8-9
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,14 @@ class Atomic
148148
volatile Type value;
149149

150150
private:
151-
#if BEAST_CLANG || __GNUC__ >= 4
152-
#define BEAST_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__))
153-
#else
154-
#define BEAST_ATTRIBUTE_MAY_ALIAS
155-
#endif
156-
static inline Type castFrom32Bit (int32 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; }
157-
static inline Type castFrom64Bit (int64 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; }
158-
static inline int32 castTo32Bit (Type value) noexcept { int32 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int32*)&value; return *tmp; }
159-
static inline int64 castTo64Bit (Type value) noexcept { int64 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int64*)&value; return *tmp; }
151+
template <typename Dest, typename Source>
152+
static inline Dest castTo (Source value) noexcept { union { Dest d; Source s; } u; u.s = value; return u.d; }
153+
154+
static inline Type castFrom32Bit (int32 value) noexcept { return castTo <Type, int32> (value); }
155+
static inline Type castFrom64Bit (int64 value) noexcept { return castTo <Type, int64> (value); }
156+
static inline int32 castTo32Bit (Type value) noexcept { return castTo <int32, Type> (value); }
157+
static inline int64 castTo64Bit (Type value) noexcept { return castTo <int64, Type> (value); }
158+
160159

161160
Type operator++ (int); // better to just use pre-increment with atomics..
162161
Type operator-- (int);

Subtrees/beast/modules/beast_core/native/beast_bsd_Threads.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ void Process::terminate()
5454

5555
BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger()
5656
{
57-
bassertfalse; // XXX not implemented for FreeBSD!
57+
// XXX not implemented for FreeBSD!
58+
bassertfalse;
5859
return false;
5960
}
6061

Subtrees/beast/modules/beast_core/native/beast_linux_SystemStats.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int SystemStats::getMemorySizeInMegabytes()
7878
struct sysinfo sysi;
7979

8080
if (sysinfo (&sysi) == 0)
81-
return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
81+
return sysi.totalram * sysi.mem_unit / (1024 * 1024);
8282

8383
return 0;
8484
}
@@ -94,11 +94,8 @@ String SystemStats::getLogonName()
9494
const char* user = getenv ("USER");
9595

9696
if (user == nullptr)
97-
{
98-
struct passwd* const pw = getpwuid (getuid());
99-
if (pw != nullptr)
97+
if (passwd* const pw = getpwuid (getuid()))
10098
user = pw->pw_name;
101-
}
10299

103100
return CharPointer_UTF8 (user);
104101
}
@@ -117,11 +114,12 @@ String SystemStats::getComputerName()
117114
return String::empty;
118115
}
119116

120-
String getLocaleValue (nl_item key)
117+
static String getLocaleValue (nl_item key)
121118
{
122119
const char* oldLocale = ::setlocale (LC_ALL, "");
123-
return String (const_cast <const char*> (nl_langinfo (key)));
120+
String result (String::fromUTF8 (nl_langinfo (key)));
124121
::setlocale (LC_ALL, oldLocale);
122+
return result;
125123
}
126124

127125
String SystemStats::getUserLanguage() { return getLocaleValue (_NL_IDENTIFICATION_LANGUAGE); }
@@ -141,7 +139,7 @@ SystemStats::CPUFlags::CPUFlags()
141139
}
142140

143141
//==============================================================================
144-
uint32 beast_millisecondsSinceStartup() noexcept
142+
uint32 BEAST_millisecondsSinceStartup() noexcept
145143
{
146144
timespec t;
147145
clock_gettime (CLOCK_MONOTONIC, &t);

Subtrees/beast/modules/beast_core/text/beast_String.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,8 @@ class StringCreationHelper
12001200
dest = result.getCharPointer();
12011201
}
12021202

1203-
StringCreationHelper (const String::CharPointerType& source_)
1204-
: source (source_), dest (nullptr), allocatedBytes (StringHolder::getAllocatedNumBytes (source)), bytesWritten (0)
1203+
StringCreationHelper (const String::CharPointerType s)
1204+
: source (s), dest (nullptr), allocatedBytes (StringHolder::getAllocatedNumBytes (s)), bytesWritten (0)
12051205
{
12061206
result.preallocateBytes (allocatedBytes);
12071207
dest = result.getCharPointer();
@@ -1531,7 +1531,8 @@ String String::quoted (const beast_wchar quoteCharacter) const
15311531
}
15321532

15331533
//==============================================================================
1534-
static String::CharPointerType findTrimmedEnd (const String::CharPointerType& start, String::CharPointerType end)
1534+
static String::CharPointerType findTrimmedEnd (const String::CharPointerType start,
1535+
String::CharPointerType end)
15351536
{
15361537
while (end > start)
15371538
{

Subtrees/beast/modules/beast_core/text/beast_TextDiff.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ struct TextDiffHelpers
3030
StringRegion (const String& s) noexcept
3131
: text (s.getCharPointer()), start (0), length (s.length()) {}
3232

33-
StringRegion (const String::CharPointerType& t, int s, int len) noexcept
33+
StringRegion (const String::CharPointerType t, int s, int len) noexcept
3434
: text (t), start (s), length (len) {}
3535

3636
String::CharPointerType text;
3737
int start, length;
3838
};
3939

40-
static void addInsertion (TextDiff& td, const String::CharPointerType& text, int index, int length)
40+
static void addInsertion (TextDiff& td, const String::CharPointerType text, int index, int length)
4141
{
4242
TextDiff::Change c;
4343
c.insertedText = String (text, (size_t) length);
@@ -99,7 +99,7 @@ struct TextDiffHelpers
9999
}
100100

101101
static int findLongestCommonSubstring (String::CharPointerType a, const int lenA,
102-
const String::CharPointerType& b, const int lenB,
102+
const String::CharPointerType b, const int lenB,
103103
int& indexInA, int& indexInB)
104104
{
105105
if (lenA == 0 || lenB == 0)

TODO.txt

+20
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,23 @@ boost::recursive_mutex
208208

209209
Replace recursive_mutex with beast::Mutex to remove boost dependency
210210

211+
--------------------------------------------------------------------------------
212+
Davidisms
213+
--------------------------------------------------------------------------------
214+
215+
(Figure out a good place to record information like this permanently)
216+
217+
Regarding a defect where a failing transaction was being submitted over and over
218+
again on the network (July 3, 2013)
219+
220+
The core problem was an interaction between two bits of logic.
221+
1) Normally, we won't relay a transaction again if we already recently relayed
222+
it. But this is bypassed if the transaction failed in a way that could
223+
allow it to succeed later. This way, if one server discovers a transaction
224+
can now work, it can get all servers to retry it.
225+
2) Normally, we won't relay a transaction if we think it can't claim a fee.
226+
But if we're not sure it can't claim a fee because we're in an unhealthy
227+
state, we propagate the transaction to let other servers decide if they
228+
think it can claim a fee.
229+
With these two bits of logic, two unhealthy servers could infinitely propagate
230+
a transaction back and forth between each other.

0 commit comments

Comments
 (0)