mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
A cleanup for MDEV-16939: avoid timeval initialization related problems in the future (compilation failures on Windows)
Adding a helper class Timeval, to initialize "struct timeval" in a safe way. As a bonus, adding a method Timeval::trunc(), so the caller now can have one line instead of five lines (declaration, initializations of sec and usec, truncation, passing to store_TIMEVAL()).
This commit is contained in:
@@ -5059,12 +5059,7 @@ int Field_timestamp::store_TIME_with_warning(THD *thd, const Datetime *dt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adjust and store the value
|
// Adjust and store the value
|
||||||
timeval tv;
|
store_TIMEVAL(Timeval(timestamp, l_time->second_part).trunc(decimals()));
|
||||||
tv.tv_sec= timestamp;
|
|
||||||
tv.tv_usec= l_time->second_part;
|
|
||||||
|
|
||||||
my_timeval_trunc(&tv, decimals());
|
|
||||||
store_TIMEVAL(tv);
|
|
||||||
|
|
||||||
// Calculate return value and send warnings if needed
|
// Calculate return value and send warnings if needed
|
||||||
if (unlikely(conversion_error)) // e.g. DATETIME in the DST gap
|
if (unlikely(conversion_error)) // e.g. DATETIME in the DST gap
|
||||||
|
@@ -2756,11 +2756,7 @@ public:
|
|||||||
}
|
}
|
||||||
void store_TIME(my_time_t timestamp, ulong sec_part)
|
void store_TIME(my_time_t timestamp, ulong sec_part)
|
||||||
{
|
{
|
||||||
timeval tv;
|
store_TIMEVAL(Timeval(timestamp, sec_part).trunc(decimals()));
|
||||||
tv.tv_sec= timestamp;
|
|
||||||
tv.tv_usec= sec_part;
|
|
||||||
my_timeval_trunc(&tv, decimals());
|
|
||||||
store_TIMEVAL(tv);
|
|
||||||
}
|
}
|
||||||
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
|
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
|
||||||
uchar *pack(uchar *to, const uchar *from,
|
uchar *pack(uchar *to, const uchar *from,
|
||||||
|
@@ -831,4 +831,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Timeval: public timeval
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Timeval(my_time_t sec, ulong usec)
|
||||||
|
{
|
||||||
|
tv_sec= sec;
|
||||||
|
tv_usec= usec;
|
||||||
|
}
|
||||||
|
Timeval &trunc(uint dec)
|
||||||
|
{
|
||||||
|
my_timeval_trunc(this, dec);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* STRUCTS_INCLUDED */
|
#endif /* STRUCTS_INCLUDED */
|
||||||
|
Reference in New Issue
Block a user