tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

02_ifdef_out_unneeded_function_in_Time.patch (8035B)


      1 # User Bob Owen <bobowencode@gmail.com>
      2 Don't compile (or remove) the following from class Time: FromStringInternal,
      3 Midnight, UTCExplode, LocalExplode, UTCMidnight, LocalMidnight and operator<<.
      4 
      5 The first has a dependency on nspr, which causes issues. The others are not
      6 needed and bring in more dependencies.
      7 
      8 Also remove base::subtle::LiveTicksNowIgnoringOverride and calling functions as
      9 they create a dependency on mincore lib and are not used.
     10 
     11 diff --git a/base/time/time.cc b/base/time/time.cc
     12 --- a/base/time/time.cc
     13 +++ b/base/time/time.cc
     14 @@ -33,18 +33,20 @@ std::atomic<TimeNowFunction> g_time_now_
     15     &subtle::TimeNowIgnoringOverride};
     16 
     17 std::atomic<TimeNowFunction> g_time_now_from_system_time_function{
     18     &subtle::TimeNowFromSystemTimeIgnoringOverride};
     19 
     20 std::atomic<TimeTicksNowFunction> g_time_ticks_now_function{
     21     &subtle::TimeTicksNowIgnoringOverride};
     22 
     23 +#if !defined(MOZ_SANDBOX)
     24 std::atomic<LiveTicksNowFunction> g_live_ticks_now_function{
     25     &subtle::LiveTicksNowIgnoringOverride};
     26 +#endif
     27 
     28 std::atomic<ThreadTicksNowFunction> g_thread_ticks_now_function{
     29     &subtle::ThreadTicksNowIgnoringOverride};
     30 
     31 }  // namespace internal
     32 
     33 // TimeDelta ------------------------------------------------------------------
     34 
     35 @@ -92,16 +94,17 @@ Time Time::Now() {
     36 
     37 // static
     38 Time Time::NowFromSystemTime() {
     39   // Just use g_time_now_function because it returns the system time.
     40   return internal::g_time_now_from_system_time_function.load(
     41       std::memory_order_relaxed)();
     42 }
     43 
     44 +#if !defined(MOZ_SANDBOX)
     45 Time Time::Midnight(bool is_local) const {
     46   Exploded exploded;
     47   Explode(is_local, &exploded);
     48   exploded.hour = 0;
     49   exploded.minute = 0;
     50   exploded.second = 0;
     51   exploded.millisecond = 0;
     52   Time out_time;
     53 @@ -142,16 +145,17 @@ bool Time::FromStringInternal(const char
     54                                        is_local ? PR_FALSE : PR_TRUE,
     55                                        &result_time);
     56   if (result != PR_SUCCESS)
     57     return false;
     58 
     59   *parsed_time = UnixEpoch() + Microseconds(result_time);
     60   return true;
     61 }
     62 +#endif
     63 
     64 // static
     65 bool Time::ExplodedMostlyEquals(const Exploded& lhs, const Exploded& rhs) {
     66   return std::tie(lhs.year, lhs.month, lhs.day_of_month, lhs.hour, lhs.minute,
     67                   lhs.second, lhs.millisecond) ==
     68          std::tie(rhs.year, rhs.month, rhs.day_of_month, rhs.hour, rhs.minute,
     69                   rhs.second, rhs.millisecond);
     70 }
     71 @@ -182,32 +186,34 @@ int64_t Time::ToRoundedDownMillisecondsS
     72   // If |us_| is negative and includes fractions of a millisecond, subtract one
     73   // more to effect the round towards -infinity. C-style integer truncation
     74   // takes care of all other cases.
     75   const int64_t millis = us_ / kMicrosecondsPerMillisecond;
     76   const int64_t submillis = us_ % kMicrosecondsPerMillisecond;
     77   return millis - kEpochOffsetMillis - (submillis < 0);
     78 }
     79 
     80 +#if !defined(MOZ_SANDBOX)
     81 std::ostream& operator<<(std::ostream& os, Time time) {
     82   Time::Exploded exploded;
     83   time.UTCExplode(&exploded);
     84   // Can't call `UnlocalizedTimeFormatWithPattern()`/`TimeFormatAsIso8601()`
     85   // since `//base` can't depend on `//base:i18n`.
     86   //
     87   // TODO(pkasting): Consider whether `operator<<()` should move to
     88   // `base/i18n/time_formatting.h` -- would let us implement in terms of
     89   // existing time formatting, but might be confusing.
     90   return os << StringPrintf("%04d-%02d-%02d %02d:%02d:%02d.%06" PRId64 " UTC",
     91                             exploded.year, exploded.month,
     92                             exploded.day_of_month, exploded.hour,
     93                             exploded.minute, exploded.second,
     94                             time.ToDeltaSinceWindowsEpoch().InMicroseconds() %
     95                                 Time::kMicrosecondsPerSecond);
     96 }
     97 +#endif
     98 
     99 // TimeTicks ------------------------------------------------------------------
    100 
    101 // static
    102 TimeTicks TimeTicks::Now() {
    103   return internal::g_time_ticks_now_function.load(std::memory_order_relaxed)();
    104 }
    105 
    106 @@ -262,20 +268,22 @@ std::ostream& operator<<(std::ostream& o
    107   // real microseconds, the only real guarantee is that the number never goes
    108   // down during a single run.
    109   const TimeDelta as_time_delta = time_ticks - TimeTicks();
    110   return os << as_time_delta.InMicroseconds() << " bogo-microseconds";
    111 }
    112 
    113 // LiveTicks ------------------------------------------------------------------
    114 
    115 +#if !defined(MOZ_SANDBOX)
    116 // static
    117 LiveTicks LiveTicks::Now() {
    118   return internal::g_live_ticks_now_function.load(std::memory_order_relaxed)();
    119 }
    120 +#endif
    121 
    122 #if !BUILDFLAG(IS_WIN)
    123 namespace subtle {
    124 LiveTicks LiveTicksNowIgnoringOverride() {
    125   // On non-windows platforms LiveTicks is equivalent to TimeTicks already.
    126   // Subtract the empty `TimeTicks` from `TimeTicks::Now()` to get a `TimeDelta`
    127   // that can be added to the empty `LiveTicks`.
    128   return LiveTicks() + (TimeTicks::Now() - TimeTicks());
    129 diff --git a/base/time/time.h b/base/time/time.h
    130 --- a/base/time/time.h
    131 +++ b/base/time/time.h
    132 @@ -804,16 +804,17 @@ class BASE_EXPORT Time : public time_int
    133                                        Time* parsed_time) {
    134     return FromStringInternal(time_string, true, parsed_time);
    135   }
    136   [[nodiscard]] static bool FromUTCString(const char* time_string,
    137                                           Time* parsed_time) {
    138     return FromStringInternal(time_string, false, parsed_time);
    139   }
    140 
    141 +#if !defined(MOZ_SANDBOX)
    142   // Fills the given |exploded| structure with either the local time or UTC from
    143   // this Time instance. If the conversion cannot be made, the output will be
    144   // assigned invalid values. Use Exploded::HasValidValues() to confirm a
    145   // successful conversion.
    146   //
    147   // Y10K compliance: This method will successfully convert all Times that
    148   // represent dates on/after the start of the year 1601 and on/before the start
    149   // of the year 30828. Some platforms might convert over a wider input range.
    150 @@ -822,16 +823,17 @@ class BASE_EXPORT Time : public time_int
    151   // on Exploded for more information.
    152   void UTCExplode(Exploded* exploded) const { Explode(false, exploded); }
    153   void LocalExplode(Exploded* exploded) const { Explode(true, exploded); }
    154 
    155   // The following two functions round down the time to the nearest day in
    156   // either UTC or local time. It will represent midnight on that day.
    157   Time UTCMidnight() const { return Midnight(false); }
    158   Time LocalMidnight() const { return Midnight(true); }
    159 +#endif
    160 
    161   // For legacy deserialization only. Converts an integer value representing
    162   // Time to a class. This may be used when deserializing a |Time| structure,
    163   // using a value known to be compatible. It is not provided as a constructor
    164   // because the integer type may be unclear from the perspective of a caller.
    165   //
    166   // DEPRECATED - Do not use in new code. When deserializing from `base::Value`,
    167   // prefer the helpers from //base/json/values_util.h instead.
    168 diff --git a/base/time/time_win.cc b/base/time/time_win.cc
    169 --- a/base/time/time_win.cc
    170 +++ b/base/time/time_win.cc
    171 @@ -639,25 +639,27 @@ bool TimeTicks::IsConsistentAcrossProces
    172 // static
    173 TimeTicks::Clock TimeTicks::GetClock() {
    174   return IsHighResolution() ? Clock::WIN_QPC
    175                             : Clock::WIN_ROLLOVER_PROTECTED_TIME_GET_TIME;
    176 }
    177 
    178 // LiveTicks ------------------------------------------------------------------
    179 
    180 +#if !defined(MOZ_SANDBOX)
    181 namespace subtle {
    182 LiveTicks LiveTicksNowIgnoringOverride() {
    183   ULONGLONG unbiased_interrupt_time;
    184   QueryUnbiasedInterruptTimePrecise(&unbiased_interrupt_time);
    185   // QueryUnbiasedInterruptTimePrecise gets the interrupt time in system time
    186   // units of 100 nanoseconds.
    187   return LiveTicks() + Nanoseconds(unbiased_interrupt_time * 100);
    188 }
    189 }  // namespace subtle
    190 +#endif
    191 
    192 // ThreadTicks ----------------------------------------------------------------
    193 
    194 namespace subtle {
    195 ThreadTicks ThreadTicksNowIgnoringOverride() {
    196   return ThreadTicks::GetForThread(PlatformThread::CurrentHandle());
    197 }
    198 }  // namespace subtle