Commit 8250cece authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix compilation on Windows:

- Fixes for type-conversion
  (time_t   is not interchangeable  with  my_time_t on Windows as time_t s 64 bit while my_time_t is long)
- BIGENDIAN-> ARCH_BIGENDIAN . 
  BIGENDIAN constant  is defined in winsock2.h (as 0)
- added explicit cast for longlong->double conversion in sql/item.h  (fixed many warnings) 

Also, HAVE_SNPRINTF is now defined and snprintf is defined to _snprintf in config-win.h
parent a85ccfed
...@@ -293,10 +293,9 @@ inline ulonglong double2ulonglong(double d) ...@@ -293,10 +293,9 @@ inline ulonglong double2ulonglong(double d)
#define FILE_SHARE_DELETE 0 /* Not implemented on Win 98/ME */ #define FILE_SHARE_DELETE 0 /* Not implemented on Win 98/ME */
#endif #endif
#ifdef NOT_USED
#define HAVE_SNPRINTF /* Gave link error */ #define HAVE_SNPRINTF
#define _snprintf snprintf #define snprintf _snprintf
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */ #define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */
......
...@@ -902,7 +902,7 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp); ...@@ -902,7 +902,7 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp);
extern ulonglong my_getsystime(void); extern ulonglong my_getsystime(void);
#define my_micro_time() (my_getsystime()/10) #define my_micro_time() (my_getsystime()/10)
#define hrtime_to_time(X) ((time_t)((X).val/1000000)) #define hrtime_to_time(X) ((my_time_t)((X).val/1000000))
#define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL)) #define hrtime_from_time(X) ((ulonglong)((X)*1000000ULL))
#define hrtime_to_double(X) ((X).val/1e6) #define hrtime_to_double(X) ((X).val/1e6)
#define hrtime_sec_part(X) ((X).val%1000000) #define hrtime_sec_part(X) ((X).val%1000000)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "mysys_priv.h" #include "mysys_priv.h"
#include <m_string.h> #include <m_string.h>
#include <my_time.h>
/* /*
get date as string get date as string
......
...@@ -108,7 +108,10 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp) ...@@ -108,7 +108,10 @@ void my_diff_and_hrtime(my_timediff_t *interval, my_hrtime_t *timestamp)
{ {
interval->val= my_getsystime() / 10; interval->val= my_getsystime() / 10;
#if defined(__WIN__) || defined(HAVE_GETHRTIME) #if defined(__WIN__) || defined(HAVE_GETHRTIME)
timestamp->val= my_hrtime(); {
my_hrtime_t t= my_hrtime();
timestamp->val= t.val;
}
#else #else
timestamp->val= interval->val; timestamp->val= interval->val;
#endif #endif
......
...@@ -1245,7 +1245,7 @@ int number_to_time(double nr, MYSQL_TIME *ltime, int *was_cut) ...@@ -1245,7 +1245,7 @@ int number_to_time(double nr, MYSQL_TIME *ltime, int *was_cut)
ltime->hour = tmp/100/100; ltime->hour = tmp/100/100;
ltime->minute= tmp/100%100; ltime->minute= tmp/100%100;
ltime->second= tmp%100; ltime->second= tmp%100;
ltime->second_part= (nr-tmp)*1e6; ltime->second_part= (ulong)((nr-tmp)*1e6);
if (ltime->minute < 60 && ltime->second < 60) if (ltime->minute < 60 && ltime->second < 60)
return 0; return 0;
...@@ -1363,7 +1363,7 @@ MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time) ...@@ -1363,7 +1363,7 @@ MYSQL_TIME *unpack_time(longlong packed, MYSQL_TIME *my_time)
get_one(my_time->hour, 24ULL); get_one(my_time->hour, 24ULL);
get_one(my_time->day, 32ULL); get_one(my_time->day, 32ULL);
get_one(my_time->month, 13ULL); get_one(my_time->month, 13ULL);
my_time->year= packed; my_time->year= (uint)packed;
my_time->time_type= MYSQL_TIMESTAMP_DATETIME; my_time->time_type= MYSQL_TIMESTAMP_DATETIME;
return my_time; return my_time;
} }
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
#pragma interface /* gcc class implementation */ #pragma interface /* gcc class implementation */
#endif #endif
#ifdef WORDS_BIGENDIAN #ifdef WORDS_ARCH_BIGENDIAN
#define BIGENDIAN 1 #define ARCH_BIGENDIAN 1
#else #else
#define BIGENDIAN 0 #define ARCH_BIGENDIAN 0
#endif #endif
#define NOT_FIXED_DEC 31 #define NOT_FIXED_DEC 31
...@@ -548,12 +548,12 @@ class Field ...@@ -548,12 +548,12 @@ class Field
bool low_byte_first_from, bool low_byte_first_to) bool low_byte_first_from, bool low_byte_first_to)
{ {
int32 val; int32 val;
if (BIGENDIAN && low_byte_first_from) if (ARCH_BIGENDIAN && low_byte_first_from)
val = sint4korr(from); val = sint4korr(from);
else else
longget(val, from); longget(val, from);
if (BIGENDIAN && low_byte_first_to) if (ARCH_BIGENDIAN && low_byte_first_to)
int4store(to, val); int4store(to, val);
else else
longstore(to, val); longstore(to, val);
...@@ -566,12 +566,12 @@ class Field ...@@ -566,12 +566,12 @@ class Field
bool low_byte_first_from, bool low_byte_first_to) bool low_byte_first_from, bool low_byte_first_to)
{ {
int64 val; int64 val;
if (BIGENDIAN && low_byte_first_from) if (ARCH_BIGENDIAN && low_byte_first_from)
val = sint8korr(from); val = sint8korr(from);
else else
longlongget(val, from); longlongget(val, from);
if (BIGENDIAN && low_byte_first_to) if (ARCH_BIGENDIAN && low_byte_first_to)
int8store(to, val); int8store(to, val);
else else
longlongstore(to, val); longlongstore(to, val);
...@@ -883,12 +883,12 @@ class Field_short :public Field_num { ...@@ -883,12 +883,12 @@ class Field_short :public Field_num {
uint max_length, bool low_byte_first) uint max_length, bool low_byte_first)
{ {
int16 val; int16 val;
if (BIGENDIAN && table->s->db_low_byte_first) if (ARCH_BIGENDIAN && table->s->db_low_byte_first)
val = sint2korr(from); val = sint2korr(from);
else else
shortget(val, from); shortget(val, from);
if (BIGENDIAN && low_byte_first) if (ARCH_BIGENDIAN && low_byte_first)
int2store(to, val); int2store(to, val);
else else
shortstore(to, val); shortstore(to, val);
...@@ -899,12 +899,12 @@ class Field_short :public Field_num { ...@@ -899,12 +899,12 @@ class Field_short :public Field_num {
uint param_data, bool low_byte_first) uint param_data, bool low_byte_first)
{ {
int16 val; int16 val;
if (BIGENDIAN && low_byte_first) if (ARCH_BIGENDIAN && low_byte_first)
val = sint2korr(from); val = sint2korr(from);
else else
shortget(val, from); shortget(val, from);
if (BIGENDIAN && table->s->db_low_byte_first) if (ARCH_BIGENDIAN && table->s->db_low_byte_first)
int2store(to, val); int2store(to, val);
else else
shortstore(to, val); shortstore(to, val);
...@@ -1200,7 +1200,7 @@ class Field_timestamp :public Field_str { ...@@ -1200,7 +1200,7 @@ class Field_timestamp :public Field_str {
virtual long get_timestamp(ulong *sec_part) const; virtual long get_timestamp(ulong *sec_part) const;
virtual void store_TIME(my_time_t timestamp, ulong sec_part) virtual void store_TIME(my_time_t timestamp, ulong sec_part)
{ {
if (BIGENDIAN && table && table->s->db_low_byte_first) if (ARCH_BIGENDIAN && table && table->s->db_low_byte_first)
int4store(ptr,timestamp); int4store(ptr,timestamp);
else else
longstore(ptr,(uint32) timestamp); longstore(ptr,(uint32) timestamp);
......
...@@ -1786,7 +1786,7 @@ class Item_datetime :public Item_int ...@@ -1786,7 +1786,7 @@ class Item_datetime :public Item_int
Item_datetime() :Item_int(0) { unsigned_flag=0; } Item_datetime() :Item_int(0) { unsigned_flag=0; }
int save_in_field(Field *field, bool no_conversions); int save_in_field(Field *field, bool no_conversions);
longlong val_int(); longlong val_int();
double val_real() { return val_int(); } double val_real() { return (double)val_int(); }
void set(longlong packed); void set(longlong packed);
}; };
......
...@@ -86,7 +86,7 @@ static bool sec_to_time(double seconds, MYSQL_TIME *ltime) ...@@ -86,7 +86,7 @@ static bool sec_to_time(double seconds, MYSQL_TIME *ltime)
ltime->hour= (uint) (seconds/3600); ltime->hour= (uint) (seconds/3600);
ltime->minute= sec/60; ltime->minute= sec/60;
ltime->second= sec % 60; ltime->second= sec % 60;
ltime->second_part= (ulong)((seconds - trunc(seconds))*1e6); ltime->second_part= (ulong)((seconds - floor(seconds))*1e6);
return 0; return 0;
......
...@@ -2063,10 +2063,11 @@ void Log_event::print_base64(IO_CACHE* file, ...@@ -2063,10 +2063,11 @@ void Log_event::print_base64(IO_CACHE* file,
void Log_event::print_timestamp(IO_CACHE* file, time_t* ts) void Log_event::print_timestamp(IO_CACHE* file, time_t* ts)
{ {
struct tm *res; struct tm *res;
time_t my_when= when;
DBUG_ENTER("Log_event::print_timestamp"); DBUG_ENTER("Log_event::print_timestamp");
if (!ts) if (!ts)
{ {
ts = &when; ts = &my_when;
} }
res=localtime(ts); res=localtime(ts);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment