mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
sync + MacOSX fix
This commit is contained in:
parent
cb6232406a
commit
8cc12fdbf3
4
configure
vendored
4
configure
vendored
|
@ -32068,7 +32068,9 @@ $as_echo "$ulib_cc_flag" >&6; }
|
|||
## compiling a program using computed gotos, a GCC extension, you may get better runtime performance if you disable the global
|
||||
## common subexpression elimination pass by adding -fno-gcse to the command line
|
||||
## ----------------------------------------------------------------------------------------------------------------------------------
|
||||
MAYBE_FLAGS="$MAYBE_FLAGS -fno-stack-protector -fno-stack-protector-all -ffast-math -ftree-vectorize -fno-crossjumping -fno-gcse -Ofast" ## -ffunction-sections -fdata-sections
|
||||
## -ffunction-sections -fdata-sections
|
||||
## ----------------------------------------------------------------------------------------------------------------------------------
|
||||
MAYBE_FLAGS="$MAYBE_FLAGS -fno-stack-protector -fno-stack-protector-all -ffast-math -ftree-vectorize -fno-crossjumping -fno-gcse -fpartial-inlining -Ofast"
|
||||
|
||||
if test "$use_distcc" != "yes" -a "$cross_compiling" != "yes"; then
|
||||
MAYBE_FLAGS="$MAYBE_FLAGS -flto -ffat-lto-objects -fuse-linker-plugin -march=native -mtune=native" # NB: distcc don't work with this...
|
||||
|
|
|
@ -2299,7 +2299,9 @@ if test "$ac_cv_c_compiler_gnu" = "yes" -a "x$GCC_IS_CLANG" = xno -a "x$OPERATIN
|
|||
## compiling a program using computed gotos, a GCC extension, you may get better runtime performance if you disable the global
|
||||
## common subexpression elimination pass by adding -fno-gcse to the command line
|
||||
## ----------------------------------------------------------------------------------------------------------------------------------
|
||||
MAYBE_FLAGS="$MAYBE_FLAGS -fno-stack-protector -fno-stack-protector-all -ffast-math -ftree-vectorize -fno-crossjumping -fno-gcse -Ofast" ## -ffunction-sections -fdata-sections
|
||||
## -ffunction-sections -fdata-sections
|
||||
## ----------------------------------------------------------------------------------------------------------------------------------
|
||||
MAYBE_FLAGS="$MAYBE_FLAGS -fno-stack-protector -fno-stack-protector-all -ffast-math -ftree-vectorize -fno-crossjumping -fno-gcse -fpartial-inlining -Ofast"
|
||||
|
||||
if test "$use_distcc" != "yes" -a "$cross_compiling" != "yes"; then
|
||||
MAYBE_FLAGS="$MAYBE_FLAGS -flto -ffat-lto-objects -fuse-linker-plugin -march=native -mtune=native" # NB: distcc don't work with this...
|
||||
|
|
|
@ -224,8 +224,8 @@ public:
|
|||
|
||||
U_INTERNAL_ASSERT(u_now->tv_sec % U_ONE_HOUR_IN_SECOND)
|
||||
|
||||
u_put_unalignedp16(ptr, u_dd((u_now->tv_sec / 60) % 60));
|
||||
u_put_unalignedp16(ptr+3, u_dd( u_now->tv_sec % 60));
|
||||
U_NUM2STR16(ptr, (u_now->tv_sec / 60) % 60);
|
||||
U_NUM2STR16(ptr+3,u_now->tv_sec % 60);
|
||||
}
|
||||
|
||||
// The daysTo() function returns the number of days between two date
|
||||
|
@ -315,11 +315,11 @@ public:
|
|||
U_RETURN(week_number);
|
||||
}
|
||||
|
||||
int getDayOfWeek()
|
||||
uint32_t getDayOfWeek()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UTimeDate::getDayOfWeek()")
|
||||
|
||||
int day_of_week = (getJulian() + 1) % 7; // gives the value 0 for Sunday ... 6 for Saturday
|
||||
uint32_t day_of_week = (getJulian() + 1) % 7; // gives the value 0 for Sunday ... 6 for Saturday: [Sun,Sat]([0,6])
|
||||
|
||||
U_RETURN(day_of_week);
|
||||
}
|
||||
|
@ -358,17 +358,17 @@ public:
|
|||
addDays(day_of_week ? 8-day_of_week : 1);
|
||||
}
|
||||
|
||||
void setDayOfWeek(int day_of_week)
|
||||
void setDayOfWeek(uint32_t day_of_week)
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UTimeDate::setDayOfWeek()")
|
||||
U_TRACE(0, "UTimeDate::setDayOfWeek(%u)", day_of_week)
|
||||
|
||||
int diff = day_of_week - getDayOfWeek();
|
||||
U_INTERNAL_ASSERT(day_of_week <= 6)
|
||||
|
||||
U_INTERNAL_DUMP("diff = %d", diff)
|
||||
uint32_t diff = weekday_difference(day_of_week, getDayOfWeek());
|
||||
|
||||
if (diff) addDays(diff);
|
||||
|
||||
U_ASSERT_EQUALS(day_of_week, getDayOfWeek())
|
||||
U_ASSERT_EQUALS(getDayOfWeek(), day_of_week)
|
||||
}
|
||||
|
||||
void setYearAndWeek(int year, int week)
|
||||
|
@ -388,7 +388,13 @@ public:
|
|||
|
||||
fromJulian(julian = toJulian(1, month, _year));
|
||||
|
||||
setDayOfWeek(1);
|
||||
int diff = 1 - getDayOfWeek();
|
||||
|
||||
U_INTERNAL_DUMP("diff = %d", diff)
|
||||
|
||||
if (diff) addDays(diff);
|
||||
|
||||
U_ASSERT_EQUALS(getDayOfWeek(), 1)
|
||||
}
|
||||
|
||||
// Print date with format
|
||||
|
@ -579,5 +585,35 @@ protected:
|
|||
void fromJulian(int julian);
|
||||
static int toJulian(int day, int month, int year);
|
||||
static UString _ago(time_t tm, uint32_t granularity);
|
||||
|
||||
static uint32_t weekday_difference(uint32_t x, uint32_t y) // Returns the number of days from the weekday y to the weekday x
|
||||
{
|
||||
U_TRACE(0, "UTimeDate::weekday_difference(%u,%u)", x, y)
|
||||
|
||||
U_INTERNAL_ASSERT(x <= 6)
|
||||
U_INTERNAL_ASSERT(y <= 6)
|
||||
|
||||
x -= y;
|
||||
|
||||
U_RETURN(x <= 6 ? x : x + 7); // The result is always in the range [0, 6]
|
||||
}
|
||||
|
||||
static uint32_t next_weekday(uint32_t x)
|
||||
{
|
||||
U_TRACE(0, "UTimeDate::next_weekday(%u)", x)
|
||||
|
||||
U_INTERNAL_ASSERT(x <= 6)
|
||||
|
||||
U_RETURN(x < 6 ? x+1 : 0);
|
||||
}
|
||||
|
||||
static uint32_t prev_weekday(uint32_t x)
|
||||
{
|
||||
U_TRACE(0, "UTimeDate::prev_weekday(%u)", x)
|
||||
|
||||
U_INTERNAL_ASSERT(x <= 6)
|
||||
|
||||
U_RETURN(x > 0 ? x-1 : 6);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1128,8 +1128,8 @@ public:
|
|||
|
||||
long l = *(long*)pval;
|
||||
|
||||
int type = (l > UINT_MAX || l < INT_MAX ? UValue::REAL_VALUE :
|
||||
l > 0 ? UValue::UINT_VALUE : UValue::INT_VALUE);
|
||||
int type = (l > (long)UINT_MAX || l < (long)INT_MAX ? UValue::REAL_VALUE :
|
||||
l > 0 ? UValue::UINT_VALUE : UValue::INT_VALUE);
|
||||
|
||||
json.value.ival = UValue::getJsonValue(type, (void*)(l & 0x00000000FFFFFFFFULL));
|
||||
}
|
||||
|
|
|
@ -1331,6 +1331,11 @@ public:
|
|||
{
|
||||
U_TRACE_NO_PARAM(0, "UString::UString(move)")
|
||||
|
||||
// Move the value (including the allocated memory) from the first object to the second one, and leave the first one empty.
|
||||
// It will not need the value anyway, because the only operation that will be executed on it is the destruction. We must
|
||||
// leave it in the state where destructor can be safely called without causing any problems such as releasing the resources
|
||||
// that were stolen and now owned by another object
|
||||
|
||||
rep = str.rep;
|
||||
str.rep = UStringRep::string_rep_null;
|
||||
UStringRep::string_rep_null->hold();
|
||||
|
|
|
@ -201,6 +201,38 @@ public:
|
|||
|
||||
// EXT
|
||||
|
||||
bool skipToken();
|
||||
bool skipToken(const char* token, uint32_t sz)
|
||||
{
|
||||
U_TRACE(0, "UTokenizer::skipToken(%.*S,%u)", sz, token, sz)
|
||||
|
||||
if ((uint32_t)str.remain(s) >= sz &&
|
||||
memcmp(s, token, sz) == 0)
|
||||
{
|
||||
s += sz;
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
void skipNumber()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UTokenizer::skipNumber()")
|
||||
|
||||
for (; s < end; ++s)
|
||||
{
|
||||
char c = *s;
|
||||
|
||||
if (u__isnumberchar(c) == false &&
|
||||
u__toupper(c) != 'E') // scientific notation (Ex: 1.45e-10)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UString substr() const
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UTokenizer::substr()")
|
||||
|
@ -223,42 +255,11 @@ public:
|
|||
U_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
void skipNumber()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UTokenizer::skipNumber()")
|
||||
|
||||
for (; s < end; ++s)
|
||||
{
|
||||
char c = *s;
|
||||
|
||||
if (u__isnumberchar(c) == false &&
|
||||
u__toupper(c) != 'E') // scientific notation (Ex: 1.45e-10)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
UString getTokenQueryParser();
|
||||
|
||||
int getTokenId(UString* ptoken);
|
||||
bool tokenSeen(const UString* x);
|
||||
|
||||
UString getTokenQueryParser();
|
||||
|
||||
bool skipToken(const char* token, uint32_t sz)
|
||||
{
|
||||
U_TRACE(0, "UTokenizer::skipToken(%.*S,%u)", sz, token, sz)
|
||||
|
||||
if ((uint32_t)str.remain(s) >= sz &&
|
||||
memcmp(s, token, sz) == 0)
|
||||
{
|
||||
s += sz;
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
static const char* group;
|
||||
static bool group_skip, avoid_punctuation;
|
||||
static uint32_t group_len, group_len_div_2;
|
||||
|
|
|
@ -433,6 +433,17 @@ public:
|
|||
static void clearSession();
|
||||
static void removeDataSession();
|
||||
|
||||
static void removeCookieSession()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UHTTP::removeCookieSession()")
|
||||
|
||||
UString cookie(100U);
|
||||
|
||||
cookie.snprintf(U_CONSTANT_TO_PARAM("ulib.s%u=; expires=%#8D"), sid_counter_cur, u_now->tv_sec - U_ONE_DAY_IN_SECOND);
|
||||
|
||||
addSetCookie(cookie);
|
||||
}
|
||||
|
||||
static void setSessionCookie(UString* param = 0);
|
||||
|
||||
static bool getDataStorage();
|
||||
|
@ -1063,7 +1074,6 @@ private:
|
|||
static bool checkGetRequestIfModified() U_NO_EXPORT;
|
||||
static void setCGIShellScript(UString& command) U_NO_EXPORT;
|
||||
static bool checkIfSourceHasChangedAndCompileUSP() U_NO_EXPORT;
|
||||
static void removeDataSession(const UString& token) U_NO_EXPORT;
|
||||
static bool checkIfUSP(UStringRep* key, void* value) U_NO_EXPORT;
|
||||
static bool compileUSP(const char* path, uint32_t len) U_NO_EXPORT;
|
||||
static void manageDataForCache(const UString& file_name) U_NO_EXPORT;
|
||||
|
|
|
@ -406,7 +406,9 @@ static char* dtoa_rapidjson(double value, char* buffer)
|
|||
{
|
||||
// 1234e7 -> 12340000000
|
||||
|
||||
# ifndef U_COVERITY_FALSE_POSITIVE
|
||||
memset(buffer+length, '0', k);
|
||||
# endif
|
||||
|
||||
buffer += kk;
|
||||
|
||||
|
@ -440,7 +442,9 @@ static char* dtoa_rapidjson(double value, char* buffer)
|
|||
|
||||
u_put_unalignedp16(buffer, U_MULTICHAR_CONSTANT16('0','.'));
|
||||
|
||||
# ifndef U_COVERITY_FALSE_POSITIVE
|
||||
memset(buffer+2, '0', -kk);
|
||||
# endif
|
||||
|
||||
return buffer+length+offset;
|
||||
}
|
||||
|
|
|
@ -272,13 +272,14 @@ next:
|
|||
kqevents = (struct kevent*) UMemoryPool::_malloc(max_connection, sizeof(struct kevent), true);
|
||||
kqrevents = (struct kevent*) UMemoryPool::_malloc(max_connection, sizeof(struct kevent), true);
|
||||
|
||||
// Check for Mac OS X kqueue bug. If kqueue works, then kevent will succeed, and it will stick an error in events[0]. If kqueue is broken, then kevent will fail
|
||||
// Check for Mac OS X kqueue bug. If kqueue works, then kevent will succeed, and it will stick an error in events[0].
|
||||
// If kqueue is broken, then kevent will fail (This detects an old bug in Mac OS X 10.4, fixed in 10.5)
|
||||
|
||||
EV_SET(kqevents, -1, EVFILT_READ, EV_ADD, 0, 0, 0);
|
||||
|
||||
if (U_SYSCALL(kevent, "%d,%p,%d,%p,%d,%p", kq, kqevents, 1, kqrevents, max_connection, 0) != 1 ||
|
||||
kqrevents[0].ident != -1 ||
|
||||
kqrevents[0].flags != EV_ERROR)
|
||||
(kqrevents[0].flags & EV_ERROR) != 0)
|
||||
{
|
||||
U_ERROR("Detected broken kevent()...");
|
||||
}
|
||||
|
|
|
@ -169,7 +169,8 @@ loop: if (delim)
|
|||
|
||||
goto tok;
|
||||
}
|
||||
else if (group_skip)
|
||||
|
||||
if (group_skip)
|
||||
{
|
||||
// -------------------------------------------------------------------
|
||||
// examples:
|
||||
|
@ -204,9 +205,8 @@ tok: n = s - p;
|
|||
while (u__ispunct(*p))
|
||||
{
|
||||
--n;
|
||||
++p;
|
||||
|
||||
if (p == s) goto loop;
|
||||
if (++p == s) goto loop;
|
||||
}
|
||||
|
||||
while (u__ispunct(p[n-1]))
|
||||
|
@ -227,6 +227,108 @@ tok: n = s - p;
|
|||
U_RETURN(false);
|
||||
}
|
||||
|
||||
bool UTokenizer::skipToken()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UTokenizer::skipToken()")
|
||||
|
||||
const char* p = s;
|
||||
uint32_t shift = 1, n;
|
||||
|
||||
while (s < end)
|
||||
{
|
||||
loop: if (delim)
|
||||
{
|
||||
s = u_delimit_token(s, &p, end, delim, 0);
|
||||
|
||||
if (p) goto tok;
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
s = u_skip(s, end, 0, 0);
|
||||
|
||||
if (s == end) break;
|
||||
|
||||
if (group)
|
||||
{
|
||||
if (memcmp(s, group, group_len_div_2) == 0)
|
||||
{
|
||||
p = s + group_len_div_2 - 1;
|
||||
s = u_strpend(p, end - p, group, group_len, '\0');
|
||||
|
||||
++p;
|
||||
|
||||
if (s == 0) s = end;
|
||||
|
||||
U_INTERNAL_DUMP("p = %.*S s = %.*S", s - p, p, end - s, s)
|
||||
|
||||
if (group_skip)
|
||||
{
|
||||
s += group_len_div_2;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
shift = group_len_div_2;
|
||||
|
||||
goto tok;
|
||||
}
|
||||
|
||||
if (group_skip)
|
||||
{
|
||||
// -------------------------------------------------------------------
|
||||
// examples:
|
||||
// -------------------------------------------------------------------
|
||||
// <date>03/11/2005 10:17:46</date>
|
||||
// <description>description_556adfbc-0107-5000-ede4-d208</description>
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
s = u_delimit_token(s, &p, end, 0, 0);
|
||||
|
||||
if (s < end)
|
||||
{
|
||||
const char* x = (char*) memchr(p, group[0], s - p);
|
||||
|
||||
if (x && (memcmp(x, group, group_len_div_2) == 0))
|
||||
{
|
||||
s = x;
|
||||
shift = 0;
|
||||
}
|
||||
}
|
||||
|
||||
goto tok;
|
||||
}
|
||||
}
|
||||
|
||||
s = u_delimit_token(s, &p, end, 0, 0);
|
||||
|
||||
tok: n = s - p;
|
||||
|
||||
if (avoid_punctuation)
|
||||
{
|
||||
while (u__ispunct(*p))
|
||||
{
|
||||
--n;
|
||||
|
||||
if (++p == s) goto loop;
|
||||
}
|
||||
|
||||
while (u__ispunct(p[n-1]))
|
||||
{
|
||||
--n;
|
||||
|
||||
if (n == 0) goto loop;
|
||||
}
|
||||
}
|
||||
|
||||
s += shift;
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
bool UTokenizer::tokenSeen(const UString* x)
|
||||
{
|
||||
U_TRACE(0, "UTokenizer::tokenSeen(%V)", x->rep)
|
||||
|
|
|
@ -2256,7 +2256,7 @@ void UHTTP2::handlerResponse()
|
|||
default: // use literal header field without indexing - indexed name
|
||||
{
|
||||
u_put_unalignedp32(ptr+HTTP2_FRAME_HEADER_SIZE, U_MULTICHAR_CONSTANT32(0x08,0x03,0x30+(U_http_info.nResponseCode / 100),'\0'));
|
||||
u_put_unalignedp16(ptr+HTTP2_FRAME_HEADER_SIZE+3, u_dd(U_http_info.nResponseCode % 100));
|
||||
U_NUM2STR16(ptr+HTTP2_FRAME_HEADER_SIZE+3, U_http_info.nResponseCode % 100);
|
||||
|
||||
sz += 4;
|
||||
dst += 4;
|
||||
|
|
|
@ -5164,21 +5164,6 @@ void UHTTP::addSetCookie(const UString& cookie)
|
|||
U_INTERNAL_DUMP("set_cookie = %V", set_cookie->rep)
|
||||
}
|
||||
|
||||
U_NO_EXPORT void UHTTP::removeDataSession(const UString& token)
|
||||
{
|
||||
U_TRACE(0, "UHTTP::removeDataSession(%V)", token.rep)
|
||||
|
||||
U_INTERNAL_ASSERT(token)
|
||||
|
||||
UString cookie(100U);
|
||||
|
||||
cookie.snprintf(U_CONSTANT_TO_PARAM("ulib.s%u=; expires=%#8D"), sid_counter_cur, u_now->tv_sec - U_ONE_DAY_IN_SECOND);
|
||||
|
||||
addSetCookie(cookie);
|
||||
|
||||
U_SRV_LOG("Delete session ulib.s%u keyid=%V", sid_counter_cur, token.rep);
|
||||
}
|
||||
|
||||
void UHTTP::removeDataSession()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UHTTP::removeDataSession()")
|
||||
|
@ -5192,7 +5177,9 @@ void UHTTP::removeDataSession()
|
|||
{
|
||||
data_session->clear();
|
||||
|
||||
removeDataSession(data_session->keyid);
|
||||
removeCookieSession();
|
||||
|
||||
U_SRV_LOG("Delete session ulib.s%u keyid=%V", sid_counter_cur, data_session->keyid.rep);
|
||||
|
||||
# ifdef U_LOG_DISABLE
|
||||
(void) db_session->remove(data_session->keyid);
|
||||
|
@ -5340,7 +5327,9 @@ bool UHTTP::getCookie(UString* cookie, UString* data)
|
|||
|
||||
if (check == false)
|
||||
{
|
||||
removeDataSession(token);
|
||||
removeCookieSession();
|
||||
|
||||
U_SRV_LOG("Delete session ulib.s%u keyid=%V", sid_counter_cur, token.rep);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
@ -10061,7 +10050,7 @@ U_NO_EXPORT void UHTTP::setResponseForRange(uint32_t _start, uint32_t _end, uint
|
|||
// Single range
|
||||
|
||||
U_INTERNAL_ASSERT(_start <= _end)
|
||||
U_INTERNAL_ASSERT_RANGE(_start,_end,range_size-1)
|
||||
U_INTERNAL_ASSERT_RANGE(_start, _end, range_size-1)
|
||||
|
||||
UString tmp(100U);
|
||||
|
||||
|
@ -10120,7 +10109,7 @@ U_NO_EXPORT int UHTTP::checkGetRequestForRange(const UString& data)
|
|||
|
||||
U_INTERNAL_DUMP("cur_start = %ld cur_end = %ld", cur_start, cur_end)
|
||||
|
||||
if (cur_end >= range_size) cur_end = range_size - 1;
|
||||
if (cur_end >= (long)range_size) cur_end = range_size - 1;
|
||||
|
||||
if (cur_start <= cur_end)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user