Skip to content

Commit 2eba343

Browse files
Abseil Teamvslashg
Abseil Team
authored andcommitted
Export of internal Abseil changes
-- baf626d27ff1547776745f3b601cc42f703d4bdf by Greg Falcon <[email protected]>: Import of CCTZ from GitHub. PiperOrigin-RevId: 315486679 -- 39d4e7f9214c5a74e4ee4b8a7f4af26479925029 by Gennadiy Rozental <[email protected]>: Avoid order dependant test cases. PiperOrigin-RevId: 315327948 -- 8feb187703a28bb0c5cfc5dd6091e3faa90a8e61 by Gennadiy Rozental <[email protected]>: Avoid order dependant test cases. PiperOrigin-RevId: 315317018 -- cffd8fddad15908ec9de7f21f65b20528972e3fa by Gennadiy Rozental <[email protected]>: Avoid order dependant test cases. PiperOrigin-RevId: 315311587 -- 48997a0ceb231b75c14eb4b1eb3b66af69e49f42 by Tom Manshreck <[email protected]>: Nit: remove extra "the" PiperOrigin-RevId: 314959763 -- 9516f44a4b5d3055427c95e80c8c04a6321e4221 by Gennadiy Rozental <[email protected]>: Import of CCTZ from GitHub. PiperOrigin-RevId: 314925147 -- 4f8691d74a4eb42ed03ef29c9588a01b78829941 by Abseil Team <[email protected]>: Uninclude util/bits/bits.h PiperOrigin-RevId: 314858384 -- 02b42a8ec5e5561b29b4e5f93cc1482c3c72ef2d by Abseil Team <[email protected]>: Google-internal changes only. PiperOrigin-RevId: 314855667 -- 146013d69dabafbe2030e23ced7b741d9e8d417c by Gennadiy Rozental <[email protected]>: Uninclude util/bits/bits.h PiperOrigin-RevId: 314838927 GitOrigin-RevId: baf626d27ff1547776745f3b601cc42f703d4bdf Change-Id: I2602286fb13cf35a88bdd80fe0b44974d4388d46
1 parent a8b03d9 commit 2eba343

File tree

9 files changed

+215
-65
lines changed

9 files changed

+215
-65
lines changed

absl/base/internal/low_level_scheduling.h

-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ extern "C" void __google_enable_rescheduling(bool disable_result);
2929

3030
namespace absl {
3131
ABSL_NAMESPACE_BEGIN
32-
class CondVar;
33-
class Mutex;
34-
3532
namespace base_internal {
3633

3734
class SchedulingHelper; // To allow use of SchedulingGuard.
@@ -80,8 +77,6 @@ class SchedulingGuard {
8077
};
8178

8279
// Access to SchedulingGuard is explicitly white-listed.
83-
friend class absl::CondVar;
84-
friend class absl::Mutex;
8580
friend class SchedulingHelper;
8681
friend class SpinLock;
8782

absl/flags/commandlineflag_test.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ ABSL_FLAG(std::string, string_flag, "dflt",
3434
absl::StrCat("string_flag", " help"));
3535
ABSL_RETIRED_FLAG(bool, bool_retired_flag, false, "bool_retired_flag help");
3636

37+
// These are only used to test default values.
38+
ABSL_FLAG(int, int_flag2, 201, "");
39+
ABSL_FLAG(std::string, string_flag2, "dflt", "");
40+
3741
namespace {
3842

3943
namespace flags = absl::flags_internal;
@@ -94,15 +98,15 @@ TEST_F(CommandLineFlagTest, TestAttributesAccessMethods) {
9498
// --------------------------------------------------------------------
9599

96100
TEST_F(CommandLineFlagTest, TestValueAccessMethods) {
97-
absl::SetFlag(&FLAGS_int_flag, 301);
98-
auto* flag_01 = absl::FindCommandLineFlag("int_flag");
101+
absl::SetFlag(&FLAGS_int_flag2, 301);
102+
auto* flag_01 = absl::FindCommandLineFlag("int_flag2");
99103

100104
ASSERT_TRUE(flag_01);
101105
EXPECT_EQ(flag_01->CurrentValue(), "301");
102106
EXPECT_EQ(flag_01->DefaultValue(), "201");
103107

104-
absl::SetFlag(&FLAGS_string_flag, "new_str_value");
105-
auto* flag_02 = absl::FindCommandLineFlag("string_flag");
108+
absl::SetFlag(&FLAGS_string_flag2, "new_str_value");
109+
auto* flag_02 = absl::FindCommandLineFlag("string_flag2");
106110

107111
ASSERT_TRUE(flag_02);
108112
EXPECT_EQ(flag_02->CurrentValue(), "new_str_value");

absl/flags/internal/program_name_test.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace {
2525

2626
namespace flags = absl::flags_internal;
2727

28-
TEST(FlagsPathUtilTest, TestInitialProgamName) {
28+
TEST(FlagsPathUtilTest, TestProgamNameInterfaces) {
2929
flags::SetProgramInvocationName("absl/flags/program_name_test");
3030
std::string program_name = flags::ProgramInvocationName();
3131
for (char& c : program_name)
@@ -43,9 +43,7 @@ TEST(FlagsPathUtilTest, TestInitialProgamName) {
4343

4444
EXPECT_TRUE(absl::EndsWith(program_name, expect_name)) << program_name;
4545
EXPECT_EQ(flags::ShortProgramInvocationName(), expect_basename);
46-
}
4746

48-
TEST(FlagsPathUtilTest, TestProgamNameInterfaces) {
4947
flags::SetProgramInvocationName("a/my_test");
5048

5149
EXPECT_EQ(flags::ProgramInvocationName(), "a/my_test");

absl/flags/parse_test.cc

+4
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,10 @@ TEST_F(ParseTest, TestFlagfileInFlagfile) {
637637
"--flagfile=$0/parse_test.ff2",
638638
};
639639

640+
GetFlagfileFlag({{"parse_test.ff2", absl::MakeConstSpan(ff2_data)},
641+
{"parse_test.ff1", absl::MakeConstSpan(ff1_data)}},
642+
flagfile_flag);
643+
640644
const char* in_args1[] = {
641645
"testbin",
642646
GetFlagfileFlag({{"parse_test.ff3", absl::MakeConstSpan(ff3_data)}},

absl/strings/str_format.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//
2020
// The `str_format` library is a typesafe replacement for the family of
2121
// `printf()` string formatting routines within the `<cstdio>` standard library
22-
// header. Like the `printf` family, the `str_format` uses a "format string" to
22+
// header. Like the `printf` family, `str_format` uses a "format string" to
2323
// perform argument substitutions based on types. See the `FormatSpec` section
2424
// below for format string documentation.
2525
//

absl/synchronization/mutex.cc

-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
using absl::base_internal::CurrentThreadIdentityIfPresent;
6060
using absl::base_internal::PerThreadSynch;
61-
using absl::base_internal::SchedulingGuard;
6261
using absl::base_internal::ThreadIdentity;
6362
using absl::synchronization_internal::GetOrCreateCurrentThreadIdentity;
6463
using absl::synchronization_internal::GraphCycles;
@@ -1109,7 +1108,6 @@ void Mutex::TryRemove(PerThreadSynch *s) {
11091108
// on the mutex queue. In this case, remove "s" from the queue and return
11101109
// true, otherwise return false.
11111110
ABSL_XRAY_LOG_ARGS(1) void Mutex::Block(PerThreadSynch *s) {
1112-
SchedulingGuard::ScopedDisable disable_rescheduling;
11131111
while (s->state.load(std::memory_order_acquire) == PerThreadSynch::kQueued) {
11141112
if (!DecrementSynchSem(this, s, s->waitp->timeout)) {
11151113
// After a timeout, we go into a spin loop until we remove ourselves
@@ -1899,7 +1897,6 @@ static void CheckForMutexCorruption(intptr_t v, const char* label) {
18991897
}
19001898

19011899
void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
1902-
SchedulingGuard::ScopedDisable disable_rescheduling;
19031900
int c = 0;
19041901
intptr_t v = mu_.load(std::memory_order_relaxed);
19051902
if ((v & kMuEvent) != 0) {
@@ -2019,7 +2016,6 @@ void Mutex::LockSlowLoop(SynchWaitParams *waitp, int flags) {
20192016
// or it is in the process of blocking on a condition variable; it must requeue
20202017
// itself on the mutex/condvar to wait for its condition to become true.
20212018
ABSL_ATTRIBUTE_NOINLINE void Mutex::UnlockSlow(SynchWaitParams *waitp) {
2022-
SchedulingGuard::ScopedDisable disable_rescheduling;
20232019
intptr_t v = mu_.load(std::memory_order_relaxed);
20242020
this->AssertReaderHeld();
20252021
CheckForMutexCorruption(v, "Unlock");
@@ -2335,7 +2331,6 @@ void Mutex::Trans(MuHow how) {
23352331
// It will later acquire the mutex with high probability. Otherwise, we
23362332
// enqueue thread w on this mutex.
23372333
void Mutex::Fer(PerThreadSynch *w) {
2338-
SchedulingGuard::ScopedDisable disable_rescheduling;
23392334
int c = 0;
23402335
ABSL_RAW_CHECK(w->waitp->cond == nullptr,
23412336
"Mutex::Fer while waiting on Condition");
@@ -2434,7 +2429,6 @@ CondVar::~CondVar() {
24342429

24352430
// Remove thread s from the list of waiters on this condition variable.
24362431
void CondVar::Remove(PerThreadSynch *s) {
2437-
SchedulingGuard::ScopedDisable disable_rescheduling;
24382432
intptr_t v;
24392433
int c = 0;
24402434
for (v = cv_.load(std::memory_order_relaxed);;
@@ -2595,7 +2589,6 @@ void CondVar::Wakeup(PerThreadSynch *w) {
25952589
}
25962590

25972591
void CondVar::Signal() {
2598-
SchedulingGuard::ScopedDisable disable_rescheduling;
25992592
ABSL_TSAN_MUTEX_PRE_SIGNAL(nullptr, 0);
26002593
intptr_t v;
26012594
int c = 0;

absl/time/internal/cctz/src/time_zone_format.cc

+100-24
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,48 @@ char* strptime(const char* s, const char* fmt, std::tm* tm) {
6767
}
6868
#endif
6969

70+
// Convert a cctz::weekday to a tm_wday value (0-6, Sunday = 0).
71+
int ToTmWday(weekday wd) {
72+
switch (wd) {
73+
case weekday::sunday:
74+
return 0;
75+
case weekday::monday:
76+
return 1;
77+
case weekday::tuesday:
78+
return 2;
79+
case weekday::wednesday:
80+
return 3;
81+
case weekday::thursday:
82+
return 4;
83+
case weekday::friday:
84+
return 5;
85+
case weekday::saturday:
86+
return 6;
87+
}
88+
return 0; /*NOTREACHED*/
89+
}
90+
91+
// Convert a tm_wday value (0-6, Sunday = 0) to a cctz::weekday.
92+
weekday FromTmWday(int tm_wday) {
93+
switch (tm_wday) {
94+
case 0:
95+
return weekday::sunday;
96+
case 1:
97+
return weekday::monday;
98+
case 2:
99+
return weekday::tuesday;
100+
case 3:
101+
return weekday::wednesday;
102+
case 4:
103+
return weekday::thursday;
104+
case 5:
105+
return weekday::friday;
106+
case 6:
107+
return weekday::saturday;
108+
}
109+
return weekday::sunday; /*NOTREACHED*/
110+
}
111+
70112
std::tm ToTM(const time_zone::absolute_lookup& al) {
71113
std::tm tm{};
72114
tm.tm_sec = al.cs.second();
@@ -84,34 +126,19 @@ std::tm ToTM(const time_zone::absolute_lookup& al) {
84126
tm.tm_year = static_cast<int>(al.cs.year() - 1900);
85127
}
86128

87-
switch (get_weekday(al.cs)) {
88-
case weekday::sunday:
89-
tm.tm_wday = 0;
90-
break;
91-
case weekday::monday:
92-
tm.tm_wday = 1;
93-
break;
94-
case weekday::tuesday:
95-
tm.tm_wday = 2;
96-
break;
97-
case weekday::wednesday:
98-
tm.tm_wday = 3;
99-
break;
100-
case weekday::thursday:
101-
tm.tm_wday = 4;
102-
break;
103-
case weekday::friday:
104-
tm.tm_wday = 5;
105-
break;
106-
case weekday::saturday:
107-
tm.tm_wday = 6;
108-
break;
109-
}
129+
tm.tm_wday = ToTmWday(get_weekday(al.cs));
110130
tm.tm_yday = get_yearday(al.cs) - 1;
111131
tm.tm_isdst = al.is_dst ? 1 : 0;
112132
return tm;
113133
}
114134

135+
// Returns the week of the year [0:53] given a civil day and the day on
136+
// which weeks are defined to start.
137+
int ToWeek(const civil_day& cd, weekday week_start) {
138+
const civil_day d(cd.year() % 400, cd.month(), cd.day());
139+
return static_cast<int>((d - prev_weekday(civil_year(d), week_start)) / 7);
140+
}
141+
115142
const char kDigits[] = "0123456789";
116143

117144
// Formats a 64-bit integer in the given field width. Note that it is up
@@ -355,7 +382,7 @@ std::string format(const std::string& format, const time_point<seconds>& tp,
355382
if (cur == end || (cur - percent) % 2 == 0) continue;
356383

357384
// Simple specifiers that we handle ourselves.
358-
if (strchr("YmdeHMSzZs%", *cur)) {
385+
if (strchr("YmdeUuWwHMSzZs%", *cur)) {
359386
if (cur - 1 != pending) {
360387
FormatTM(&result, std::string(pending, cur - 1), tm);
361388
}
@@ -376,6 +403,22 @@ std::string format(const std::string& format, const time_point<seconds>& tp,
376403
if (*cur == 'e' && *bp == '0') *bp = ' '; // for Windows
377404
result.append(bp, static_cast<std::size_t>(ep - bp));
378405
break;
406+
case 'U':
407+
bp = Format02d(ep, ToWeek(civil_day(al.cs), weekday::sunday));
408+
result.append(bp, static_cast<std::size_t>(ep - bp));
409+
break;
410+
case 'u':
411+
bp = Format64(ep, 0, tm.tm_wday ? tm.tm_wday : 7);
412+
result.append(bp, static_cast<std::size_t>(ep - bp));
413+
break;
414+
case 'W':
415+
bp = Format02d(ep, ToWeek(civil_day(al.cs), weekday::monday));
416+
result.append(bp, static_cast<std::size_t>(ep - bp));
417+
break;
418+
case 'w':
419+
bp = Format64(ep, 0, tm.tm_wday);
420+
result.append(bp, static_cast<std::size_t>(ep - bp));
421+
break;
379422
case 'H':
380423
bp = Format02d(ep, al.cs.hour());
381424
result.append(bp, static_cast<std::size_t>(ep - bp));
@@ -610,6 +653,17 @@ const char* ParseTM(const char* dp, const char* fmt, std::tm* tm) {
610653
return dp;
611654
}
612655

656+
// Sets year, tm_mon and tm_mday given the year, week_num, and tm_wday,
657+
// and the day on which weeks are defined to start.
658+
void FromWeek(int week_num, weekday week_start, year_t* year, std::tm* tm) {
659+
const civil_year y(*year % 400);
660+
civil_day cd = prev_weekday(y, week_start); // week 0
661+
cd = next_weekday(cd - 1, FromTmWday(tm->tm_wday)) + (week_num * 7);
662+
*year += cd.year() - y.year();
663+
tm->tm_mon = cd.month() - 1;
664+
tm->tm_mday = cd.day();
665+
}
666+
613667
} // namespace
614668

615669
// Uses strptime(3) to parse the given input. Supports the same extended
@@ -659,6 +713,8 @@ bool parse(const std::string& format, const std::string& input,
659713
const char* fmt = format.c_str(); // NUL terminated
660714
bool twelve_hour = false;
661715
bool afternoon = false;
716+
int week_num = -1;
717+
weekday week_start = weekday::sunday;
662718

663719
bool saw_percent_s = false;
664720
std::int_fast64_t percent_s = 0;
@@ -697,10 +753,27 @@ bool parse(const std::string& format, const std::string& input,
697753
case 'm':
698754
data = ParseInt(data, 2, 1, 12, &tm.tm_mon);
699755
if (data != nullptr) tm.tm_mon -= 1;
756+
week_num = -1;
700757
continue;
701758
case 'd':
702759
case 'e':
703760
data = ParseInt(data, 2, 1, 31, &tm.tm_mday);
761+
week_num = -1;
762+
continue;
763+
case 'U':
764+
data = ParseInt(data, 0, 0, 53, &week_num);
765+
week_start = weekday::sunday;
766+
continue;
767+
case 'W':
768+
data = ParseInt(data, 0, 0, 53, &week_num);
769+
week_start = weekday::monday;
770+
continue;
771+
case 'u':
772+
data = ParseInt(data, 0, 1, 7, &tm.tm_wday);
773+
if (data != nullptr) tm.tm_wday %= 7;
774+
continue;
775+
case 'w':
776+
data = ParseInt(data, 0, 0, 6, &tm.tm_wday);
704777
continue;
705778
case 'H':
706779
data = ParseInt(data, 2, 0, 23, &tm.tm_hour);
@@ -891,6 +964,9 @@ bool parse(const std::string& format, const std::string& input,
891964
year += 1900;
892965
}
893966

967+
// Compute year, tm.tm_mon and tm.tm_mday if we parsed a week number.
968+
if (week_num != -1) FromWeek(week_num, week_start, &year, &tm);
969+
894970
const int month = tm.tm_mon + 1;
895971
civil_second cs(year, month, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
896972

0 commit comments

Comments
 (0)