ObjFW  Check-in [e0459c419c]

Overview
Comment:Reduce usage of unions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e0459c419cca642ffb041ce56ce4c30385093fb1fbca83f707902ee3c67772c6
User & Date: js on 2020-04-19 14:52:59
Other Links: manifest | tags
Context
2020-04-19
15:24
Several documentation improvements check-in: f27905c199 user: js tags: trunk
14:52
Reduce usage of unions check-in: e0459c419c user: js tags: trunk
14:07
Update buildsys check-in: dcebb980d6 user: js tags: trunk
Changes

Modified src/OFColor.m from [c54ddadacf] to [cae3bcbbaf].

    82     82   
    83     83   	return true;
    84     84   }
    85     85   
    86     86   - (uint32_t)hash
    87     87   {
    88     88   	uint32_t hash;
    89         -	union {
    90         -		float f;
    91         -		unsigned char b[sizeof(float)];
    92         -	} f;
           89  +	float tmp;
    93     90   
    94     91   	OF_HASH_INIT(hash);
    95     92   
    96         -	f.f = OF_BSWAP_FLOAT_IF_LE(_red);
           93  +	tmp = OF_BSWAP_FLOAT_IF_LE(_red);
           94  +	for (uint_fast8_t i = 0; i < sizeof(float); i++)
           95  +		OF_HASH_ADD(hash, ((char *)&tmp)[i]);
           96  +
           97  +	tmp = OF_BSWAP_FLOAT_IF_LE(_green);
    97     98   	for (uint_fast8_t i = 0; i < sizeof(float); i++)
    98         -		OF_HASH_ADD(hash, f.b[i]);
           99  +		OF_HASH_ADD(hash, ((char *)&tmp)[i]);
    99    100   
   100         -	f.f = OF_BSWAP_FLOAT_IF_LE(_green);
          101  +	tmp = OF_BSWAP_FLOAT_IF_LE(_blue);
   101    102   	for (uint_fast8_t i = 0; i < sizeof(float); i++)
   102         -		OF_HASH_ADD(hash, f.b[i]);
          103  +		OF_HASH_ADD(hash, ((char *)&tmp)[i]);
   103    104   
   104         -	f.f = OF_BSWAP_FLOAT_IF_LE(_blue);
          105  +	tmp = OF_BSWAP_FLOAT_IF_LE(_alpha);
   105    106   	for (uint_fast8_t i = 0; i < sizeof(float); i++)
   106         -		OF_HASH_ADD(hash, f.b[i]);
   107         -
   108         -	f.f = OF_BSWAP_FLOAT_IF_LE(_alpha);
   109         -	for (uint_fast8_t i = 0; i < sizeof(float); i++)
   110         -		OF_HASH_ADD(hash, f.b[i]);
          107  +		OF_HASH_ADD(hash, ((char *)&tmp)[i]);
   111    108   
   112    109   	OF_HASH_FINALIZE(hash);
   113    110   
   114    111   	return hash;
   115    112   }
   116    113   
   117    114   - (void)getRed: (float *)red

Modified src/OFData+MessagePackValue.m from [95748cc907] to [caaaf51219].

   276    276   		if (length < 9)
   277    277   			@throw [OFTruncatedDataException exception];
   278    278   
   279    279   		*object = [OFNumber numberWithInt64: readUInt64(buffer + 1)];
   280    280   		return 9;
   281    281   	/* Floating point */
   282    282   	case 0xCA:; /* float 32 */
   283         -		union {
   284         -			unsigned char u8[4];
   285         -			float f;
   286         -		} f;
          283  +		float f;
   287    284   
   288    285   		if (length < 5)
   289    286   			@throw [OFTruncatedDataException exception];
   290    287   
   291         -		memcpy(&f.u8, buffer + 1, 4);
          288  +		memcpy(&f, buffer + 1, 4);
   292    289   
   293         -		*object = [OFNumber numberWithFloat: OF_BSWAP_FLOAT_IF_LE(f.f)];
          290  +		*object = [OFNumber numberWithFloat: OF_BSWAP_FLOAT_IF_LE(f)];
   294    291   		return 5;
   295    292   	case 0xCB:; /* float 64 */
   296         -		union {
   297         -			unsigned char u8[8];
   298         -			double d;
   299         -		} d;
          293  +		double d;
   300    294   
   301    295   		if (length < 9)
   302    296   			@throw [OFTruncatedDataException exception];
   303    297   
   304         -		memcpy(&d.u8, buffer + 1, 8);
          298  +		memcpy(&d, buffer + 1, 8);
   305    299   
   306         -		*object = [OFNumber numberWithDouble:
   307         -		    OF_BSWAP_DOUBLE_IF_LE(d.d)];
          300  +		*object = [OFNumber numberWithDouble: OF_BSWAP_DOUBLE_IF_LE(d)];
   308    301   		return 9;
   309    302   	/* nil */
   310    303   	case 0xC0:
   311    304   		*object = [OFNull null];
   312    305   		return 1;
   313    306   	/* false */
   314    307   	case 0xC2:

Modified src/OFDate.m from [ab9874f31d] to [b94395832f].

   336    336   
   337    337   - (instancetype)initWithSerialization: (OFXMLElement *)element
   338    338   {
   339    339   	self = [super init];
   340    340   
   341    341   	@try {
   342    342   		void *pool = objc_autoreleasePoolPush();
   343         -		union {
   344         -			double d;
   345         -			uint64_t u;
   346         -		} d;
   347    343   
   348    344   		if (![element.name isEqual: self.className] ||
   349    345   		    ![element.namespace isEqual: OF_SERIALIZATION_NS])
   350    346   			@throw [OFInvalidArgumentException exception];
   351    347   
   352         -		d.u = (uint64_t)element.hexadecimalValue;
   353         -		d.u = OF_BSWAP64_IF_LE(d.u);
   354         -		_seconds = OF_BSWAP_DOUBLE_IF_LE(d.d);
          348  +		_seconds = OF_BSWAP_DOUBLE_IF_LE(OF_INT_TO_DOUBLE_RAW(
          349  +		    OF_BSWAP64_IF_LE(element.hexadecimalValue)));
   355    350   
   356    351   		objc_autoreleasePoolPop(pool);
   357    352   	} @catch (id e) {
   358    353   		[self release];
   359    354   		@throw e;
   360    355   	}
   361    356   
................................................................................
   379    374   
   380    375   	return true;
   381    376   }
   382    377   
   383    378   - (uint32_t)hash
   384    379   {
   385    380   	uint32_t hash;
   386         -	union {
   387         -		double d;
   388         -		uint8_t b[sizeof(double)];
   389         -	} d;
   390         -
   391         -	d.d = OF_BSWAP_DOUBLE_IF_BE(_seconds);
          381  +	double tmp;
   392    382   
   393    383   	OF_HASH_INIT(hash);
          384  +
          385  +	tmp = OF_BSWAP_DOUBLE_IF_BE(_seconds);
   394    386   
   395    387   	for (size_t i = 0; i < sizeof(double); i++)
   396         -		OF_HASH_ADD(hash, d.b[i]);
          388  +		OF_HASH_ADD(hash, ((char *)&tmp)[i]);
   397    389   
   398    390   	OF_HASH_FINALIZE(hash);
   399    391   
   400    392   	return hash;
   401    393   }
   402    394   
   403    395   - (id)copy
................................................................................
   427    419   	return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"];
   428    420   }
   429    421   
   430    422   - (OFXMLElement *)XMLElementBySerializing
   431    423   {
   432    424   	void *pool = objc_autoreleasePoolPush();
   433    425   	OFXMLElement *element;
   434         -	union {
   435         -		double d;
   436         -		uint64_t u;
   437         -	} d;
   438    426   
   439    427   	element = [OFXMLElement elementWithName: self.className
   440    428   				      namespace: OF_SERIALIZATION_NS];
   441    429   
   442         -	d.d = OF_BSWAP_DOUBLE_IF_LE(_seconds);
   443         -	element.stringValue =
   444         -	    [OFString stringWithFormat: @"%016" PRIx64, OF_BSWAP64_IF_LE(d.u)];
          430  +	element.stringValue = [OFString stringWithFormat: @"%016" PRIx64,
          431  +	    OF_BSWAP64_IF_LE(OF_DOUBLE_TO_INT_RAW(OF_BSWAP_DOUBLE_IF_LE(
          432  +	    _seconds)))];
   445    433   
   446    434   	[element retain];
   447    435   
   448    436   	objc_autoreleasePoolPop(pool);
   449    437   
   450    438   	return [element autorelease];
   451    439   }

Modified src/OFLocale.m from [0b5d50eb1d] to [aa7c2af69a].

   451    451   		if (GetVar("Language", buffer, sizeof(buffer), 0) > 0)
   452    452   			_language = [[OFString alloc]
   453    453   			    initWithCString: buffer
   454    454   				   encoding: _encoding];
   455    455   
   456    456   		if ((locale = OpenLocale(NULL)) != NULL) {
   457    457   			@try {
   458         -				union {
   459         -					uint32_t u32;
   460         -					char c[4];
   461         -				} territory;
          458  +				uint32_t territory;
   462    459   				size_t length;
   463    460   
   464         -				territory.u32 =
          461  +				territory =
   465    462   				    OF_BSWAP32_IF_LE(locale->loc_CountryCode);
   466    463   
   467    464   				for (length = 0; length < 4; length++)
   468         -					if (territory.c[length] == 0)
          465  +					if (((char *)territory)[length] == 0)
   469    466   						break;
   470    467   
   471    468   				_territory = [[OFString alloc]
   472    469   				    initWithCString: territory.c
   473    470   					   encoding: _encoding
   474    471   					     length: length];
   475    472   			} @finally {

Modified src/OFMD5Hash.h from [afbdcd7e31] to [7314ebcbd4].

    30     30   @interface OFMD5Hash: OFObject <OFCryptoHash>
    31     31   {
    32     32   	OFSecureData *_iVarsData;
    33     33   	struct of_md5_hash_ivars {
    34     34   		uint32_t state[4];
    35     35   		uint64_t bits;
    36     36   		union of_md5_hash_buffer {
    37         -			uint8_t bytes[64];
           37  +			unsigned char bytes[64];
    38     38   			uint32_t words[16];
    39     39   		} buffer;
    40     40   		size_t bufferLength;
    41     41   	} *_iVars;
    42     42   	bool _allowsSwappableMemory;
    43     43   	bool _calculated;
    44     44   }
    45     45   @end
    46     46   
    47     47   OF_ASSUME_NONNULL_END

Modified src/OFNumber.m from [5a67a624f2] to [f96cb2d4be].

   554    554   			 */
   555    555   			_type = OF_NUMBER_TYPE_UINTMAX;
   556    556   			_value.uIntMax = element.decimalValue;
   557    557   		} else if ([typeString isEqual: @"signed"]) {
   558    558   			_type = OF_NUMBER_TYPE_INTMAX;
   559    559   			_value.intMax = element.decimalValue;
   560    560   		} else if ([typeString isEqual: @"float"]) {
   561         -			union {
   562         -				float f;
   563         -				uint32_t u;
   564         -			} f;
   565         -
   566         -			f.u = OF_BSWAP32_IF_LE(
   567         -			    (uint32_t)element.hexadecimalValue);
   568         -
   569    561   			_type = OF_NUMBER_TYPE_FLOAT;
   570         -			_value.float_ = OF_BSWAP_FLOAT_IF_LE(f.f);
          562  +			_value.float_ = OF_BSWAP_FLOAT_IF_LE(
          563  +			    OF_INT_TO_FLOAT_RAW(OF_BSWAP32_IF_LE(
          564  +			    (uint32_t)element.hexadecimalValue)));
   571    565   		} else if ([typeString isEqual: @"double"]) {
   572         -			union {
   573         -				double d;
   574         -				uint64_t u;
   575         -			} d;
   576         -
   577         -			d.u = OF_BSWAP64_IF_LE(
   578         -			    (uint64_t)element.hexadecimalValue);
   579         -
   580    566   			_type = OF_NUMBER_TYPE_DOUBLE;
   581         -			_value.double_ = OF_BSWAP_DOUBLE_IF_LE(d.d);
          567  +			_value.double_ = OF_BSWAP_DOUBLE_IF_LE(
          568  +			    OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE(
          569  +			    (uint64_t)element.hexadecimalValue)));
   582    570   		} else
   583    571   			@throw [OFInvalidArgumentException exception];
   584    572   
   585    573   		objc_autoreleasePoolPop(pool);
   586    574   	} @catch (id e) {
   587    575   		[self release];
   588    576   		@throw e;
................................................................................
  1071   1059   				type &= ~OF_NUMBER_TYPE_FLOAT;
  1072   1060   		}
  1073   1061   	}
  1074   1062   
  1075   1063   	OF_HASH_INIT(hash);
  1076   1064   
  1077   1065   	if (type & OF_NUMBER_TYPE_FLOAT) {
  1078         -		union {
  1079         -			double d;
  1080         -			uint8_t b[sizeof(double)];
  1081         -		} d;
         1066  +		double d;
  1082   1067   
  1083   1068   		if (isnan(self.doubleValue))
  1084   1069   			return 0;
  1085   1070   
  1086         -		d.d = OF_BSWAP_DOUBLE_IF_BE(self.doubleValue);
         1071  +		d = OF_BSWAP_DOUBLE_IF_BE(self.doubleValue);
  1087   1072   
  1088   1073   		for (uint_fast8_t i = 0; i < sizeof(double); i++)
  1089         -			OF_HASH_ADD(hash, d.b[i]);
         1074  +			OF_HASH_ADD(hash, ((char *)&d)[i]);
  1090   1075   	} else if (type & OF_NUMBER_TYPE_SIGNED) {
  1091   1076   		intmax_t v = self.intMaxValue * -1;
  1092   1077   
  1093   1078   		while (v != 0) {
  1094   1079   			OF_HASH_ADD(hash, v & 0xFF);
  1095   1080   			v >>= 8;
  1096   1081   		}
................................................................................
  1214   1199   	case OF_NUMBER_TYPE_INT8:
  1215   1200   	case OF_NUMBER_TYPE_INT16:
  1216   1201   	case OF_NUMBER_TYPE_INT32:
  1217   1202   	case OF_NUMBER_TYPE_INT64:
  1218   1203   	case OF_NUMBER_TYPE_SSIZE:
  1219   1204   	case OF_NUMBER_TYPE_INTMAX:
  1220   1205   	case OF_NUMBER_TYPE_PTRDIFF:
  1221         -	case OF_NUMBER_TYPE_INTPTR:;
         1206  +	case OF_NUMBER_TYPE_INTPTR:
  1222   1207   		[element addAttributeWithName: @"type"
  1223   1208   				  stringValue: @"signed"];
  1224   1209   		break;
  1225         -	case OF_NUMBER_TYPE_FLOAT:;
  1226         -		union {
  1227         -			float f;
  1228         -			uint32_t u;
  1229         -		} f;
  1230         -
  1231         -		f.f = OF_BSWAP_FLOAT_IF_LE(_value.float_);
  1232         -
         1210  +	case OF_NUMBER_TYPE_FLOAT:
  1233   1211   		[element addAttributeWithName: @"type"
  1234   1212   				  stringValue: @"float"];
  1235         -		element.stringValue =
  1236         -		    [OFString stringWithFormat: @"%08" PRIx32,
  1237         -						OF_BSWAP32_IF_LE(f.u)];
         1213  +		element.stringValue = [OFString stringWithFormat: @"%08" PRIx32,
         1214  +		    OF_BSWAP32_IF_LE(OF_FLOAT_TO_INT_RAW(OF_BSWAP_FLOAT_IF_LE(
         1215  +		    _value.float_)))];
  1238   1216   
  1239   1217   		break;
  1240         -	case OF_NUMBER_TYPE_DOUBLE:;
  1241         -		union {
  1242         -			double d;
  1243         -			uint64_t u;
  1244         -		} d;
  1245         -
  1246         -		d.d = OF_BSWAP_DOUBLE_IF_LE(_value.double_);
  1247         -
         1218  +	case OF_NUMBER_TYPE_DOUBLE:
  1248   1219   		[element addAttributeWithName: @"type"
  1249   1220   				  stringValue: @"double"];
  1250         -		element.stringValue =
  1251         -		    [OFString stringWithFormat: @"%016" PRIx64,
  1252         -						OF_BSWAP64_IF_LE(d.u)];
         1221  +		element.stringValue = [OFString
         1222  +		    stringWithFormat: @"%016" PRIx64,
         1223  +		    OF_BSWAP64_IF_LE(OF_DOUBLE_TO_INT_RAW(OF_BSWAP_DOUBLE_IF_LE(
         1224  +		    _value.double_)))];
  1253   1225   
  1254   1226   		break;
  1255   1227   	default:
  1256   1228   		@throw [OFInvalidFormatException exception];
  1257   1229   	}
  1258   1230   
  1259   1231   	[element retain];

Modified src/OFRIPEMD160Hash.h from [b0c573b36f] to [bd428762b3].

    30     30   @interface OFRIPEMD160Hash: OFObject <OFCryptoHash>
    31     31   {
    32     32   	OFSecureData *_iVarsData;
    33     33   	struct of_ripemd160_hash_ivars {
    34     34   		uint32_t state[5];
    35     35   		uint64_t bits;
    36     36   		union of_ripemd160_hash_buffer {
    37         -			uint8_t bytes[64];
           37  +			unsigned char bytes[64];
    38     38   			uint32_t words[16];
    39     39   		} buffer;
    40     40   		size_t bufferLength;
    41     41   	} *_iVars;
    42     42   	bool _allowsSwappableMemory;
    43     43   	bool _calculated;
    44     44   }
    45     45   @end
    46     46   
    47     47   OF_ASSUME_NONNULL_END

Modified src/OFSHA1Hash.h from [812276bc67] to [bd4ba48e95].

    30     30   @interface OFSHA1Hash: OFObject <OFCryptoHash>
    31     31   {
    32     32   	OFSecureData *_iVarsData;
    33     33   	struct of_sha1_hash_ivars {
    34     34   		uint32_t state[5];
    35     35   		uint64_t bits;
    36     36   		union of_sha1_hash_buffer {
    37         -			uint8_t bytes[64];
           37  +			unsigned char bytes[64];
    38     38   			uint32_t words[80];
    39     39   		} buffer;
    40     40   		size_t bufferLength;
    41     41   	} *_iVars;
    42     42   	bool _allowsSwappableMemory;
    43     43   	bool _calculated;
    44     44   }
    45     45   @end
    46     46   
    47     47   OF_ASSUME_NONNULL_END

Modified src/OFSHA224Or256Hash.h from [9b410449c3] to [deb793f9c1].

    31     31   @private
    32     32   	OFSecureData *_iVarsData;
    33     33   @protected
    34     34   	struct of_sha224_or_256_hash_ivars {
    35     35   		uint32_t state[8];
    36     36   		uint64_t bits;
    37     37   		union of_sha224_or_256_hash_buffer {
    38         -			uint8_t bytes[64];
           38  +			unsigned char bytes[64];
    39     39   			uint32_t words[64];
    40     40   		} buffer;
    41     41   		size_t bufferLength;
    42     42   	} *_iVars;
    43     43   @private
    44     44   	bool _allowsSwappableMemory;
    45     45   	bool _calculated;
    46     46   	OF_RESERVE_IVARS(4)
    47     47   }
    48     48   @end
    49     49   
    50     50   OF_ASSUME_NONNULL_END

Modified src/OFSHA384Or512Hash.h from [b0f0d3732f] to [e5381155b9].

    31     31   @private
    32     32   	OFSecureData *_iVarsData;
    33     33   @protected
    34     34   	struct of_sha384_or_512_hash_ivars {
    35     35   		uint64_t state[8];
    36     36   		uint64_t bits[2];
    37     37   		union of_sha384_or_512_hash_buffer {
    38         -			uint8_t bytes[128];
           38  +			unsigned char bytes[128];
    39     39   			uint64_t words[80];
    40     40   		} buffer;
    41     41   		size_t bufferLength;
    42     42   	} *_iVars;
    43     43   @private
    44     44   	bool _allowsSwappableMemory;
    45     45   	bool _calculated;
    46     46   	OF_RESERVE_IVARS(4)
    47     47   }
    48     48   @end
    49     49   
    50     50   OF_ASSUME_NONNULL_END

Modified src/OFTarArchive.m from [fe80dcdcf2] to [9fc8cae7a2].

    96     96   			_mode = OF_TAR_ARCHIVE_MODE_WRITE;
    97     97   		else if ([mode isEqual: @"a"])
    98     98   			_mode = OF_TAR_ARCHIVE_MODE_APPEND;
    99     99   		else
   100    100   			@throw [OFInvalidArgumentException exception];
   101    101   
   102    102   		if (_mode == OF_TAR_ARCHIVE_MODE_APPEND) {
   103         -			union {
   104         -				char c[1024];
   105         -				uint32_t u32[1024 / sizeof(uint32_t)];
   106         -			} buffer;
          103  +			uint32_t buffer[1024 / sizeof(uint32_t)];
   107    104   			bool empty = true;
   108    105   
   109    106   			if (![_stream isKindOfClass: [OFSeekableStream class]])
   110    107   				@throw [OFInvalidArgumentException exception];
   111    108   
   112    109   			[(OFSeekableStream *)_stream seekToOffset: -1024
   113    110   							   whence: SEEK_END];
   114         -			[_stream readIntoBuffer: buffer.c
          111  +			[_stream readIntoBuffer: buffer
   115    112   				    exactLength: 1024];
   116    113   
   117    114   			for (size_t i = 0; i < 1024 / sizeof(uint32_t); i++)
   118         -				if (buffer.u32[i] != 0)
          115  +				if (buffer[i] != 0)
   119    116   					empty = false;
   120    117   
   121    118   			if (!empty)
   122    119   				@throw [OFInvalidFormatException exception];
   123    120   
   124    121   			[(OFSeekableStream *)stream seekToOffset: -1024
   125    122   							  whence: SEEK_END];
................................................................................
   164    161   
   165    162   	[super dealloc];
   166    163   }
   167    164   
   168    165   - (OFTarArchiveEntry *)nextEntry
   169    166   {
   170    167   	OFTarArchiveEntry *entry;
   171         -	union {
   172         -		unsigned char c[512];
   173         -		uint32_t u32[512 / sizeof(uint32_t)];
   174         -	} buffer;
          168  +	uint32_t buffer[512 / sizeof(uint32_t)];
   175    169   	bool empty = true;
   176    170   
   177    171   	if (_mode != OF_TAR_ARCHIVE_MODE_READ)
   178    172   		@throw [OFInvalidArgumentException exception];
   179    173   
   180    174   	[(OFTarArchiveFileReadStream *)_lastReturnedStream of_skip];
   181    175   	@try {
................................................................................
   185    179   	}
   186    180   	[_lastReturnedStream release];
   187    181   	_lastReturnedStream = nil;
   188    182   
   189    183   	if (_stream.atEndOfStream)
   190    184   		return nil;
   191    185   
   192         -	[_stream readIntoBuffer: buffer.c
          186  +	[_stream readIntoBuffer: buffer
   193    187   		    exactLength: 512];
   194    188   
   195    189   	for (size_t i = 0; i < 512 / sizeof(uint32_t); i++)
   196         -		if (buffer.u32[i] != 0)
          190  +		if (buffer[i] != 0)
   197    191   			empty = false;
   198    192   
   199    193   	if (empty) {
   200         -		[_stream readIntoBuffer: buffer.c
          194  +		[_stream readIntoBuffer: buffer
   201    195   			    exactLength: 512];
   202    196   
   203    197   		for (size_t i = 0; i < 512 / sizeof(uint32_t); i++)
   204         -			if (buffer.u32[i] != 0)
          198  +			if (buffer[i] != 0)
   205    199   				@throw [OFInvalidFormatException exception];
   206    200   
   207    201   		return nil;
   208    202   	}
   209    203   
   210    204   	entry = [[[OFTarArchiveEntry alloc]
   211         -	    of_initWithHeader: buffer.c
          205  +	    of_initWithHeader: (unsigned char *)buffer
   212    206   		     encoding: _encoding] autorelease];
   213    207   
   214    208   	_lastReturnedStream = [[OFTarArchiveFileReadStream alloc]
   215    209   	    of_initWithStream: _stream
   216    210   			entry: entry];
   217    211   
   218    212   	return entry;

Modified src/macros.h from [798f22e9e5] to [0ec579f5ac].

   548    548   # define OF_BSWAP64(i) \
   549    549       (__builtin_constant_p(i) ? OF_BSWAP64_CONST(i) : OF_BSWAP64_NONCONST(i))
   550    550   #else
   551    551   # define OF_BSWAP16(i) OF_BSWAP16_CONST(i)
   552    552   # define OF_BSWAP32(i) OF_BSWAP32_CONST(i)
   553    553   # define OF_BSWAP64(i) OF_BSWAP64_CONST(i)
   554    554   #endif
          555  +
          556  +static OF_INLINE uint32_t
          557  +OF_FLOAT_TO_INT_RAW(float f)
          558  +{
          559  +	uint32_t ret;
          560  +	memcpy(&ret, &f, 4);
          561  +	return ret;
          562  +}
          563  +
          564  +static OF_INLINE float
          565  +OF_INT_TO_FLOAT_RAW(uint32_t u32)
          566  +{
          567  +	float ret;
          568  +	memcpy(&ret, &u32, 4);
          569  +	return ret;
          570  +}
          571  +
          572  +static OF_INLINE uint64_t
          573  +OF_DOUBLE_TO_INT_RAW(double d)
          574  +{
          575  +	uint64_t ret;
          576  +	memcpy(&ret, &d, 8);
          577  +	return ret;
          578  +}
          579  +
          580  +static OF_INLINE double
          581  +OF_INT_TO_DOUBLE_RAW(uint64_t u64)
          582  +{
          583  +	double ret;
          584  +	memcpy(&ret, &u64, 8);
          585  +	return ret;
          586  +}
   555    587   
   556    588   static OF_INLINE float OF_CONST_FUNC
   557    589   OF_BSWAP_FLOAT(float f)
   558    590   {
   559         -	union {
   560         -		float f;
   561         -		uint32_t i;
   562         -	} u;
   563         -
   564         -	u.f = f;
   565         -	u.i = OF_BSWAP32(u.i);
   566         -
   567         -	return u.f;
          591  +	return OF_INT_TO_FLOAT_RAW(OF_BSWAP32(OF_FLOAT_TO_INT_RAW(f)));
   568    592   }
   569    593   
   570    594   static OF_INLINE double OF_CONST_FUNC
   571    595   OF_BSWAP_DOUBLE(double d)
   572    596   {
   573         -	union {
   574         -		double d;
   575         -		uint64_t i;
   576         -	} u;
   577         -
   578         -	u.d = d;
   579         -	u.i = OF_BSWAP64(u.i);
   580         -
   581         -	return u.d;
          597  +	return OF_INT_TO_DOUBLE_RAW(OF_BSWAP64(OF_DOUBLE_TO_INT_RAW(d)));
   582    598   }
   583    599   
   584    600   #ifdef OF_BIG_ENDIAN
   585    601   # define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i)
   586    602   # define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i)
   587    603   # define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i)
   588    604   # define OF_BSWAP16_IF_LE(i) (i)