Skip to content

Commit 1f37f66

Browse files
author
Tor Didriksen
committed
Bug#18357597 REPLACE FLOATSTORE/FLOATGET MACROS WITH INLINE FUNCTIONS
For better type safety: replace macros with inline functions. Note: kept some strange formatting for easier diff/review.
1 parent b95a4b3 commit 1f37f66

25 files changed

+234
-178
lines changed

client/mysqltest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6328,7 +6328,7 @@ int read_line(char *buf, int size)
63286328
{
63296329
if (!(charlen= my_mbcharlen(charset_info, (unsigned char) c)))
63306330
{
6331-
char c1= my_getc(cur_file->file);
6331+
int c1= my_getc(cur_file->file);
63326332
if (c1 == EOF)
63336333
{
63346334
*p++= c;

client/sql_string.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -606,7 +606,7 @@ void String::qs_append(double d)
606606
void String::qs_append(double *d)
607607
{
608608
double ld;
609-
float8get(ld, (char*) d);
609+
float8get(&ld, (char*) d);
610610
qs_append(ld);
611611
}
612612

include/big_endian.h

+55-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -13,40 +13,46 @@
1313
along with this program; if not, write to the Free Software
1414
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
1515

16+
#include <string.h>
17+
1618
/*
1719
Data in big-endian format.
1820
*/
19-
#define float4store(T,A) do { *(T)= ((uchar *) &A)[3];\
20-
*((T)+1)=(char) ((uchar *) &A)[2];\
21-
*((T)+2)=(char) ((uchar *) &A)[1];\
22-
*((T)+3)=(char) ((uchar *) &A)[0]; } while(0)
21+
static inline void float4store(uchar *T, float A)
22+
{ *(T)= ((uchar *) &A)[3];
23+
*((T)+1)=(char) ((uchar *) &A)[2];
24+
*((T)+2)=(char) ((uchar *) &A)[1];
25+
*((T)+3)=(char) ((uchar *) &A)[0]; }
2326

24-
#define float4get(V,M) do { float def_temp;\
25-
((uchar*) &def_temp)[0]=(M)[3];\
26-
((uchar*) &def_temp)[1]=(M)[2];\
27-
((uchar*) &def_temp)[2]=(M)[1];\
28-
((uchar*) &def_temp)[3]=(M)[0];\
29-
(V)=def_temp; } while(0)
27+
static inline void float4get (float *V, const uchar *M)
28+
{ float def_temp;
29+
((uchar*) &def_temp)[0]=(M)[3];
30+
((uchar*) &def_temp)[1]=(M)[2];
31+
((uchar*) &def_temp)[2]=(M)[1];
32+
((uchar*) &def_temp)[3]=(M)[0];
33+
(*V)=def_temp; }
3034

31-
#define float8store(T,V) do { *(T)= ((uchar *) &V)[7];\
32-
*((T)+1)=(char) ((uchar *) &V)[6];\
33-
*((T)+2)=(char) ((uchar *) &V)[5];\
34-
*((T)+3)=(char) ((uchar *) &V)[4];\
35-
*((T)+4)=(char) ((uchar *) &V)[3];\
36-
*((T)+5)=(char) ((uchar *) &V)[2];\
37-
*((T)+6)=(char) ((uchar *) &V)[1];\
38-
*((T)+7)=(char) ((uchar *) &V)[0]; } while(0)
35+
static inline void float8store(uchar *T, double V)
36+
{ *(T)= ((uchar *) &V)[7];
37+
*((T)+1)=(char) ((uchar *) &V)[6];
38+
*((T)+2)=(char) ((uchar *) &V)[5];
39+
*((T)+3)=(char) ((uchar *) &V)[4];
40+
*((T)+4)=(char) ((uchar *) &V)[3];
41+
*((T)+5)=(char) ((uchar *) &V)[2];
42+
*((T)+6)=(char) ((uchar *) &V)[1];
43+
*((T)+7)=(char) ((uchar *) &V)[0]; }
3944

40-
#define float8get(V,M) do { double def_temp;\
41-
((uchar*) &def_temp)[0]=(M)[7];\
42-
((uchar*) &def_temp)[1]=(M)[6];\
43-
((uchar*) &def_temp)[2]=(M)[5];\
44-
((uchar*) &def_temp)[3]=(M)[4];\
45-
((uchar*) &def_temp)[4]=(M)[3];\
46-
((uchar*) &def_temp)[5]=(M)[2];\
47-
((uchar*) &def_temp)[6]=(M)[1];\
48-
((uchar*) &def_temp)[7]=(M)[0];\
49-
(V) = def_temp; } while(0)
45+
static inline void float8get (double *V, const uchar *M)
46+
{ double def_temp;
47+
((uchar*) &def_temp)[0]=(M)[7];
48+
((uchar*) &def_temp)[1]=(M)[6];
49+
((uchar*) &def_temp)[2]=(M)[5];
50+
((uchar*) &def_temp)[3]=(M)[4];
51+
((uchar*) &def_temp)[4]=(M)[3];
52+
((uchar*) &def_temp)[5]=(M)[2];
53+
((uchar*) &def_temp)[6]=(M)[1];
54+
((uchar*) &def_temp)[7]=(M)[0];
55+
(*V) = def_temp; }
5056

5157
#define ushortget(V,M) do { V = (uint16) (((uint16) ((uchar) (M)[1]))+\
5258
((uint16) ((uint16) (M)[0]) << 8)); } while(0)
@@ -72,11 +78,25 @@
7278
*(((char*)T)+1)=(((A) >> 16));\
7379
*(((char*)T)+0)=(((A) >> 24)); } while(0)
7480

75-
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
76-
/* Cast away type qualifiers (necessary as macro takes argument by value). */
77-
#define floatstore(T,V) memcpy((T), (void*) (&V), sizeof(float))
78-
#define doubleget(V,M) memcpy(&V, (M), sizeof(double))
79-
/* Cast away type qualifiers (necessary as macro takes argument by value). */
80-
#define doublestore(T,V) memcpy((T), (void*) &V, sizeof(double))
81+
static inline void floatget(float *V, const uchar *M)
82+
{
83+
memcpy(V, (M), sizeof(float));
84+
}
85+
86+
static inline void floatstore(uchar *T, float V)
87+
{
88+
memcpy((T), (&V), sizeof(float));
89+
}
90+
91+
static inline void doubleget(double *V, const uchar *M)
92+
{
93+
memcpy(V, (M), sizeof(double));
94+
}
95+
96+
static inline void doublestore(uchar *T, double V)
97+
{
98+
memcpy((T), &V, sizeof(double));
99+
}
100+
81101
#define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong))
82102
#define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong))

include/byte_order_generic_x86.h

-21
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,3 @@ static inline void int8store(uchar *T, ulonglong A)
113113
{
114114
*((ulonglong*) T)= A;
115115
}
116-
117-
118-
119-
typedef union {
120-
double v;
121-
long m[2];
122-
} doubleget_union;
123-
#define doubleget(V,M) do { doubleget_union _tmp; \
124-
_tmp.m[0] = *((long*)(M)); \
125-
_tmp.m[1] = *(((long*) (M))+1); \
126-
(V) = _tmp.v;\
127-
} while(0)
128-
#define doublestore(T,V) do { *((long *) T) = ((doubleget_union *)&V)->m[0]; \
129-
*(((long *) T)+1) = ((doubleget_union *)&V)->m[1];\
130-
} while (0)
131-
#define float4get(V,M) do { *((float *) &(V)) = *((float*) (M)); } while(0)
132-
#define float8get(V,M) doubleget((V),(M))
133-
#define float4store(V,M) memcpy((uchar*)(V), (uchar*)(&M), sizeof(float))
134-
#define floatstore(T,V) memcpy((uchar*)(T), (uchar*)(&V), sizeof(float))
135-
#define floatget(V,M) memcpy((uchar*)(&V),(uchar*) (M), sizeof(float))
136-
#define float8store(V,M) doublestore((V),(M))

include/little_endian.h

+48-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -17,55 +17,67 @@
1717
Data in little-endian format.
1818
*/
1919

20-
#ifndef MY_BYTE_ORDER_ARCH_OPTIMIZED
21-
#define float4get(V,M) memcpy(&V, (M), sizeof(float))
22-
#define float4store(V,M) memcpy(V, (&M), sizeof(float))
23-
#define float8get(V,M) doubleget((V),(M))
24-
#define float8store(V,M) doublestore((V),(M))
20+
#include <string.h>
21+
22+
static inline void float4get (float *V, const uchar *M)
23+
{
24+
memcpy(V, (M), sizeof(float));
25+
}
26+
27+
static inline void float4store(uchar *V, float M)
28+
{
29+
memcpy(V, (&M), sizeof(float));
30+
}
31+
32+
static inline void float8get (double *V, const uchar *M)
33+
{
34+
memcpy(V, M, sizeof(double));
35+
}
36+
37+
static inline void float8store(uchar *V, double M)
38+
{
39+
memcpy(V, &M, sizeof(double));
40+
}
41+
42+
static inline void floatget (float *V, const uchar *M) { float4get(V, M); }
43+
static inline void floatstore (uchar *V, float M) { float4store(V, M); }
2544

2645
/* Bi-endian hardware.... */
2746
#if defined(__FLOAT_WORD_ORDER) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN)
28-
#define doublestore(T,V) do { *(((char*)T)+0)=(char) ((uchar *) &V)[4];\
29-
*(((char*)T)+1)=(char) ((uchar *) &V)[5];\
30-
*(((char*)T)+2)=(char) ((uchar *) &V)[6];\
31-
*(((char*)T)+3)=(char) ((uchar *) &V)[7];\
32-
*(((char*)T)+4)=(char) ((uchar *) &V)[0];\
33-
*(((char*)T)+5)=(char) ((uchar *) &V)[1];\
34-
*(((char*)T)+6)=(char) ((uchar *) &V)[2];\
35-
*(((char*)T)+7)=(char) ((uchar *) &V)[3]; }\
36-
while(0)
37-
#define doubleget(V,M) do { double def_temp;\
38-
((uchar*) &def_temp)[0]=(M)[4];\
39-
((uchar*) &def_temp)[1]=(M)[5];\
40-
((uchar*) &def_temp)[2]=(M)[6];\
41-
((uchar*) &def_temp)[3]=(M)[7];\
42-
((uchar*) &def_temp)[4]=(M)[0];\
43-
((uchar*) &def_temp)[5]=(M)[1];\
44-
((uchar*) &def_temp)[6]=(M)[2];\
45-
((uchar*) &def_temp)[7]=(M)[3];\
46-
(V) = def_temp; } while(0)
47+
static inline void doublestore(uchar *T, double V)
48+
{ *(((char*)T)+0)=(char) ((uchar *) &V)[4];
49+
*(((char*)T)+1)=(char) ((uchar *) &V)[5];
50+
*(((char*)T)+2)=(char) ((uchar *) &V)[6];
51+
*(((char*)T)+3)=(char) ((uchar *) &V)[7];
52+
*(((char*)T)+4)=(char) ((uchar *) &V)[0];
53+
*(((char*)T)+5)=(char) ((uchar *) &V)[1];
54+
*(((char*)T)+6)=(char) ((uchar *) &V)[2];
55+
*(((char*)T)+7)=(char) ((uchar *) &V)[3]; }
56+
static inline void doubleget(double *V, const uchar *M)
57+
{ double def_temp;
58+
((uchar*) &def_temp)[0]=(M)[4];
59+
((uchar*) &def_temp)[1]=(M)[5];
60+
((uchar*) &def_temp)[2]=(M)[6];
61+
((uchar*) &def_temp)[3]=(M)[7];
62+
((uchar*) &def_temp)[4]=(M)[0];
63+
((uchar*) &def_temp)[5]=(M)[1];
64+
((uchar*) &def_temp)[6]=(M)[2];
65+
((uchar*) &def_temp)[7]=(M)[3];
66+
(*V) = def_temp; }
67+
4768
#else /* Bi-endian hardware.... */
4869

49-
/* Cast away type qualifiers (necessary as macro takes argument by value). */
50-
#define doublestore(T,V) memcpy((T), (void*) &V, sizeof(double))
51-
#define doubleget(V,M) memcpy(&V, (M), sizeof(double))
70+
static inline void doublestore(uchar *T, double V) { memcpy(T, &V, sizeof(double)); }
71+
static inline void doubleget (double *V, const uchar *M) { memcpy(V, M, sizeof(double)); }
5272

5373
#endif /* Bi-endian hardware.... */
5474

55-
#endif /* !MY_BYTE_ORDER_ARCH_OPTIMIZED */
56-
5775
#define ushortget(V,M) do { uchar *pM= (uchar*)(M);V = uint2korr(pM);} while(0)
5876
#define shortget(V,M) do { uchar *pM= (uchar*)(M);V = sint2korr(pM);} while(0)
5977
#define longget(V,M) do { uchar *pM= (uchar*)(M);V = sint4korr(pM);} while(0)
6078
#define ulongget(V,M) do { uchar *pM= (uchar*)(M);V = uint4korr(pM);} while(0)
6179
#define shortstore(T,V) int2store(T,V)
6280
#define longstore(T,V) int4store(T,V)
6381

64-
#ifndef floatstore
65-
/* Cast away type qualifiers (necessary as macro takes argument by value). */
66-
#define floatstore(T,V) memcpy((T), (void*) (&V), sizeof(float))
67-
#define floatget(V,M) memcpy(&V, (M), sizeof(float))
68-
#endif
69-
7082
#define longlongget(V,M) memcpy(&V, (M), sizeof(ulonglong))
7183
#define longlongstore(T,V) memcpy((T), &V, sizeof(ulonglong))

include/my_byteorder.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
for integer types, but 'get' (assume 'getter') for floating point types.
2424
*/
2525
#if defined(__i386__) || defined(_WIN32)
26-
#define MY_BYTE_ORDER_ARCH_OPTIMIZED
2726
#include "byte_order_generic_x86.h"
2827
#elif defined(__x86_64__)
2928
#include "byte_order_generic_x86_64.h"
@@ -122,4 +121,23 @@ static inline void int8store(char *pT, ulonglong A)
122121
#include "little_endian.h"
123122
#endif
124123

124+
#ifdef __cplusplus
125+
126+
static inline void float4store(char *V, float M)
127+
{
128+
float4store(static_cast<uchar*>(static_cast<void*>(V)), M);
129+
}
130+
131+
static inline void float8get(double *V, const char *M)
132+
{
133+
float8get(V, static_cast<const uchar*>(static_cast<const void*>(M)));
134+
}
135+
136+
static inline void float8store(char *V, double M)
137+
{
138+
float8store(static_cast<uchar*>(static_cast<void*>(V)), M);
139+
}
140+
141+
#endif /* __cplusplus */
142+
125143
#endif /* MY_BYTEORDER_INCLUDED */

libmysql/libmysql.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -3606,15 +3606,15 @@ static void fetch_result_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
36063606
case MYSQL_TYPE_FLOAT:
36073607
{
36083608
float value;
3609-
float4get(value,*row);
3609+
float4get(&value,*row);
36103610
fetch_float_with_conversion(param, field, value, MY_GCVT_ARG_FLOAT);
36113611
*row+= 4;
36123612
break;
36133613
}
36143614
case MYSQL_TYPE_DOUBLE:
36153615
{
36163616
double value;
3617-
float8get(value,*row);
3617+
float8get(&value,*row);
36183618
fetch_float_with_conversion(param, field, value, MY_GCVT_ARG_DOUBLE);
36193619
*row+= 8;
36203620
break;
@@ -3721,7 +3721,7 @@ static void fetch_result_float(MYSQL_BIND *param,
37213721
uchar **row)
37223722
{
37233723
float value;
3724-
float4get(value,*row);
3724+
float4get(&value,*row);
37253725
floatstore(param->buffer, value);
37263726
*row+= 4;
37273727
}
@@ -3731,7 +3731,7 @@ static void fetch_result_double(MYSQL_BIND *param,
37313731
uchar **row)
37323732
{
37333733
double value;
3734-
float8get(value,*row);
3734+
float8get(&value,*row);
37353735
doublestore(param->buffer, value);
37363736
*row+= 8;
37373737
}

mysys/stacktrace.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -703,8 +703,11 @@ static size_t my_safe_vsnprintf(char *to, size_t size,
703703
my_safe_utoa(base, uval, &buff[sizeof(buff)-1]) :
704704
my_safe_itoa(base, ival, &buff[sizeof(buff)-1]);
705705

706-
/* Strip off "ffffffff" if we have 'x' format without 'll' */
707-
if (*format == 'x' && !have_longlong && ival < 0)
706+
/*
707+
Strip off "ffffffff" if we have 'x' format without 'll'
708+
Similarly for 'p' format on 32bit systems.
709+
*/
710+
if (base == 16 && !have_longlong && ival < 0)
708711
val_as_str+= 8;
709712

710713
while (*val_as_str && to < end)

0 commit comments

Comments
 (0)