1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  * Module Info:	Datatype conversions for the H5T interface.
16  */
17 
18 /****************/
19 /* Module Setup */
20 /****************/
21 
22 #define H5T_PACKAGE		/*suppress error about including H5Tpkg	     */
23 
24 /* Interface initialization */
25 #define H5_INTERFACE_INIT_FUNC	H5T_init_conv_interface
26 
27 
28 /***********/
29 /* Headers */
30 /***********/
31 #include "H5private.h"		/* Generic Functions			*/
32 #include "H5Dprivate.h"		/* Datasets				*/
33 #include "H5Eprivate.h"		/* Error handling		  	*/
34 #include "H5FLprivate.h"	/* Free Lists                           */
35 #include "H5HGprivate.h"	/* Global Heaps				*/
36 #include "H5Iprivate.h"		/* IDs			  		*/
37 #include "H5MMprivate.h"	/* Memory management			*/
38 #include "H5Pprivate.h"		/* Property lists			*/
39 #include "H5Tpkg.h"		/* Datatypes				*/
40 
41 
42 /****************/
43 /* Local Macros */
44 /****************/
45 
46 /*
47  * These macros are for the bodies of functions that convert buffers of one
48  * atomic type to another using hardware.
49  *
50  * They all start with `H5T_CONV_' and end with two letters that represent the
51  * source and destination types, respectively. The letters `s' and `S' refer to
52  * signed integers while the letters `u' and `U' refer to unsigned integers, and
53  * the letters `f' and `F' refer to floating-point values.
54  *
55  * The letter which is capitalized indicates that the corresponding type
56  * (source or destination) is at least as large as the other type.
57  *
58  * Certain conversions may experience overflow conditions which arise when the
59  * source value has a magnitude that cannot be represented by the destination
60  * type.
61  *
62  * Suffix	Description
63  * ------	-----------
64  * sS:		Signed integers to signed integers where the destination is
65  *		at least as wide as the source.	 This case cannot generate
66  *		overflows.
67  *
68  * sU:		Signed integers to unsigned integers where the destination is
69  *		at least as wide as the source.	 This case experiences
70  *		overflows when the source value is negative.
71  *
72  * uS:		Unsigned integers to signed integers where the destination is
73  *		at least as wide as the source.	 This case can experience
74  *		overflows when the source and destination are the same size.
75  *
76  * uU:		Unsigned integers to unsigned integers where the destination
77  *		is at least as wide as the source.  Overflows are not
78  *		possible in this case.
79  *
80  * Ss:		Signed integers to signed integers where the source is at
81  *		least as large as the destination.  Overflows can occur when
82  *		the destination is narrower than the source.
83  *
84  * Su:		Signed integers to unsigned integers where the source is at
85  *		least as large as the destination.  Overflows occur when the
86  *		source value is negative and can also occur if the
87  *		destination is narrower than the source.
88  *
89  * Us:		Unsigned integers to signed integers where the source is at
90  *		least as large as the destination.  Overflows can occur for
91  *		all sizes.
92  *
93  * Uu:		Unsigned integers to unsigned integers where the source is at
94  *		least as large as the destination. Overflows can occur if the
95  *		destination is narrower than the source.
96  *
97  * su:		Conversion from signed integers to unsigned integers where
98  *		the source and destination are the same size. Overflow occurs
99  *		when the source value is negative.
100  *
101  * us:		Conversion from unsigned integers to signed integers where
102  *		the source and destination are the same size.  Overflow
103  *		occurs when the source magnitude is too large for the
104  *		destination.
105  *
106  * fF:		Floating-point values to floating-point values where the
107  *              destination is at least as wide as the source.	 This case
108  *              cannot generate overflows.
109  *
110  * Ff:		Floating-point values to floating-point values the source is at
111  *		least as large as the destination.  Overflows can occur when
112  *		the destination is narrower than the source.
113  *
114  * xF:          Integers to float-point(float or double) values where the desination
115  *              is at least as wide as the source.  This case cannot generate
116  *              overflows.
117  *
118  * Fx:          Float-point(float or double) values to integer where the source is
119  *              at least as wide as the destination.  Overflow can occur
120  *              when the source magnitude is too large for the destination.
121  *
122  * The macros take a subset of these arguments in the order listed here:
123  *
124  * CDATA:	A pointer to the H5T_cdata_t structure that was passed to the
125  *		conversion function.
126  *
127  * STYPE:	The hid_t value for the source datatype.
128  *
129  * DTYPE:	The hid_t value for the destination datatype.
130  *
131  * BUF:		A pointer to the conversion buffer.
132  *
133  * NELMTS:	The number of values to be converted.
134  *
135  * ST:		The C name for source datatype (e.g., int)
136  *
137  * DT:		The C name for the destination datatype (e.g., signed char)
138  *
139  * D_MIN:	The minimum possible destination value.	 For unsigned
140  *		destination types this should be zero.	For signed
141  *		destination types it's a negative value with a magnitude that
142  *		is usually one greater than D_MAX.  Source values which are
143  *		smaller than D_MIN generate overflows.
144  *
145  * D_MAX:	The maximum possible destination value. Source values which
146  *		are larger than D_MAX generate overflows.
147  *
148  * The macros are implemented with a generic programming technique, similar
149  * to templates in C++.  The macro which defines the "core" part of the
150  * conversion (which actually moves the data from the source to the destination)
151  * is invoked inside the H5T_CONV "template" macro by "gluing" it together,
152  * which allows the core conversion macro to be invoked as necessary.
153  *
154  * "Core" macros come in two flavors: one which calls the exception handling
155  * routine and one which doesn't (the "_NOEX" variant).  The presence of the
156  * exception handling routine is detected before the loop over the values and
157  * the appropriate core routine loop is executed.
158  *
159  * The generic "core" macros are: (others are specific to particular conversion)
160  *
161  * Suffix	Description
162  * ------	-----------
163  * xX:		Generic Conversion where the destination is at least as
164  *              wide as the source.  This case cannot generate overflows.
165  *
166  * Xx:		Generic signed conversion where the source is at least as large
167  *              as the destination.  Overflows can occur when the destination is
168  *              narrower than the source.
169  *
170  * Ux:		Generic conversion for the `Us', `Uu' & `us' cases
171  *		Overflow occurs when the source magnitude is too large for the
172  *		destination.
173  *
174  */
175 #define H5T_CONV_xX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
176     *(D) = (DT)(*(S));							      \
177 }
178 #define H5T_CONV_xX_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
179     *(D) = (DT)(*(S));							      \
180 }
181 
182 /* Added a condition branch(else if (*(S) == (DT)(D_MAX))) which seems redundant.
183  * It handles a special situation when the source is "float" and assigned the value
184  * of "INT_MAX".  A compiler may do roundup making this value "INT_MAX+1".  However,
185  * when do comparison "if (*(S) > (DT)(D_MAX))", the compiler may consider them
186  * equal. In this case, do not return exception but make sure the maximum is assigned
187  * to the destination.   SLU - 2005/06/29
188  */
189 #define H5T_CONV_Xx_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
190     if (*(S) > (ST)(D_MAX)) {                                                 \
191         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
192                 src_id, dst_id, S, D, cb_struct.user_data);                   \
193         if(except_ret == H5T_CONV_UNHANDLED)                                  \
194             /* Let compiler convert if case is ignored by user handler*/      \
195             *(D) = (DT)(D_MAX);						      \
196         else if(except_ret == H5T_CONV_ABORT)                                 \
197             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
198         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
199     } else if (*(S) < (ST)(D_MIN)) {                                          \
200         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW, \
201                 src_id, dst_id, S, D, cb_struct.user_data);                   \
202         if(except_ret == H5T_CONV_UNHANDLED)                                  \
203             /* Let compiler convert if case is ignored by user handler*/      \
204             *(D) = (DT)(D_MIN);						      \
205         else if(except_ret == H5T_CONV_ABORT)                                 \
206             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
207         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
208     } else 								      \
209         *(D) = (DT)(*(S));						      \
210 }
211 #define H5T_CONV_Xx_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
212     if (*(S) > (ST)(D_MAX)) {                                                 \
213         *(D) = (DT)(D_MAX);						      \
214     } else if (*(S) < (ST)(D_MIN)) {                                          \
215         *(D) = (DT)(D_MIN);						      \
216     } else 								      \
217         *(D) = (DT)(*(S));						      \
218 }
219 
220 #define H5T_CONV_Ux_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
221     if (*(S) > (ST)(D_MAX)) {                                                 \
222         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI,               \
223                 src_id, dst_id, S, D, cb_struct.user_data);                   \
224         if(except_ret == H5T_CONV_UNHANDLED)                                  \
225             /* Let compiler convert if case is ignored by user handler*/      \
226             *(D) = (DT)(D_MAX);						      \
227         else if(except_ret == H5T_CONV_ABORT)                                 \
228             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
229         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
230     } else								      \
231         *(D) = (DT)(*(S));						      \
232 }
233 #define H5T_CONV_Ux_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
234     if (*(S) > (ST)(D_MAX)) {                                                 \
235         *(D) = (DT)(D_MAX);						      \
236     } else								      \
237         *(D) = (DT)(*(S));						      \
238 }
239 
240 #define H5T_CONV_sS(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
241     HDcompile_assert(sizeof(ST)<=sizeof(DT));				      \
242     H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
243 }
244 
245 #define H5T_CONV_sU_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
246     if (*(S) < 0) {                                                           \
247         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW,              \
248                 src_id, dst_id, S, D, cb_struct.user_data);                   \
249         if(except_ret == H5T_CONV_UNHANDLED)                                  \
250             /* Let compiler convert if case is ignored by user handler*/      \
251             *(D) = 0;						              \
252         else if(except_ret == H5T_CONV_ABORT)                                 \
253             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
254         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
255     } else								      \
256         *(D) = (DT)(*(S));						      \
257 }
258 #define H5T_CONV_sU_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
259     if(*(S) < 0)                                                              \
260         *(D) = 0;						              \
261     else								      \
262         *(D) = (DT)(*(S));						      \
263 }
264 
265 #define H5T_CONV_sU(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
266     HDcompile_assert(sizeof(ST)<=sizeof(DT));				      \
267     H5T_CONV(H5T_CONV_sU, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
268 }
269 
270 #define H5T_CONV_uS_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
271     if(sizeof(ST) == sizeof(DT) && *(S) > (DT)(D_MAX)) {                      \
272         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI,               \
273                 src_id, dst_id, S, D, cb_struct.user_data);                   \
274         if(except_ret == H5T_CONV_UNHANDLED)                                  \
275             /* Let compiler convert if case is ignored by user handler*/      \
276             *(D) = (DT)(D_MAX);						      \
277         else if(except_ret == H5T_CONV_ABORT)                                 \
278             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
279         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
280     } else								      \
281         *(D) = (DT)(*(S));						      \
282 }
283 #define H5T_CONV_uS_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
284     if (sizeof(ST)==sizeof(DT) && *(S) > (DT)(D_MAX)) {                       \
285         *(D) = (D_MAX);							      \
286     } else								      \
287         *(D) = (DT)(*(S));						      \
288 }
289 
290 #define H5T_CONV_uS(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
291     HDcompile_assert(sizeof(ST)<=sizeof(DT));				      \
292     H5T_CONV(H5T_CONV_uS, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
293 }
294 
295 #define H5T_CONV_uU(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
296     HDcompile_assert(sizeof(ST)<=sizeof(DT));				      \
297     H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
298 }
299 
300 #define H5T_CONV_Ss(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
301     HDcompile_assert(sizeof(ST)>=sizeof(DT));				      \
302     H5T_CONV(H5T_CONV_Xx, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
303 }
304 
305 #define H5T_CONV_Su_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
306     if(*(S) < 0) {                                                            \
307         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW,              \
308                 src_id, dst_id, S, D, cb_struct.user_data);                   \
309         if(except_ret == H5T_CONV_UNHANDLED)                                  \
310             /* Let compiler convert if case is ignored by user handler*/      \
311             *(D) = 0;						              \
312         else if(except_ret == H5T_CONV_ABORT)                                 \
313             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
314         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
315     } else if (sizeof(ST)>sizeof(DT) && *(S) > (ST)(D_MAX)) {                 \
316         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI,               \
317                 src_id, dst_id, S, D, cb_struct.user_data);                   \
318         if(except_ret == H5T_CONV_UNHANDLED)                                  \
319             /* Let compiler convert if case is ignored by user handler*/      \
320             *(D) = (DT)(D_MAX);						      \
321         else if(except_ret == H5T_CONV_ABORT)                                 \
322             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
323         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
324     } else								      \
325         *(D) = (DT)(*(S));						      \
326 }
327 #define H5T_CONV_Su_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
328     if(*(S) < 0)                                                              \
329         *(D) = 0;						              \
330     else if (sizeof(ST)>sizeof(DT) && *(S) > (ST)(D_MAX))                     \
331         *(D) = (DT)(D_MAX);						      \
332     else								      \
333         *(D) = (DT)(*(S));						      \
334 }
335 
336 #define H5T_CONV_Su(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
337     HDcompile_assert(sizeof(ST)>=sizeof(DT));				      \
338     H5T_CONV(H5T_CONV_Su, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
339 }
340 
341 #define H5T_CONV_Us(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
342     HDcompile_assert(sizeof(ST)>=sizeof(DT));				      \
343     H5T_CONV(H5T_CONV_Ux, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
344 }
345 
346 #define H5T_CONV_Uu(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
347     HDcompile_assert(sizeof(ST)>=sizeof(DT));				      \
348     H5T_CONV(H5T_CONV_Ux, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
349 }
350 
351 #define H5T_CONV_su_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
352     /* Assumes memory format of unsigned & signed integers is same */	      \
353     if(*(S) < 0) {                                                            \
354         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW,              \
355                 src_id, dst_id, S, D, cb_struct.user_data);                   \
356         if(except_ret == H5T_CONV_UNHANDLED)                                  \
357             /* Let compiler convert if case is ignored by user handler*/      \
358             *(D) = 0;						              \
359         else if(except_ret == H5T_CONV_ABORT)                                 \
360             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
361         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
362     } else								      \
363         *(D) = (DT)(*(S));						      \
364 }
365 #define H5T_CONV_su_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
366     /* Assumes memory format of unsigned & signed integers is same */	      \
367     if(*(S) < 0)                                                              \
368         *(D) = 0;						              \
369     else								      \
370         *(D) = (DT)(*(S));						      \
371 }
372 
373 #define H5T_CONV_su(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
374     HDcompile_assert(sizeof(ST)==sizeof(DT));				      \
375     H5T_CONV(H5T_CONV_su, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
376 }
377 
378 #define H5T_CONV_us_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
379     /* Assumes memory format of unsigned & signed integers is same */	      \
380     if (*(S) > (ST)(D_MAX)) {                                                 \
381         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI,               \
382                 src_id, dst_id, S, D, cb_struct.user_data);                   \
383         if(except_ret == H5T_CONV_UNHANDLED)                                  \
384             /* Let compiler convert if case is ignored by user handler*/      \
385             *(D) = (DT)(D_MAX);						      \
386         else if(except_ret == H5T_CONV_ABORT)                                 \
387             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
388         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
389     } else								      \
390         *(D) = (DT)(*(S));						      \
391 }
392 #define H5T_CONV_us_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
393     /* Assumes memory format of unsigned & signed integers is same */	      \
394     if(*(S) > (ST)(D_MAX))                                                    \
395         *(D) = (DT)(D_MAX);						      \
396     else								      \
397         *(D) = (DT)(*(S));						      \
398 }
399 
400 #define H5T_CONV_us(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
401     HDcompile_assert(sizeof(ST)==sizeof(DT));				      \
402     H5T_CONV(H5T_CONV_us, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
403 }
404 
405 #define H5T_CONV_fF(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
406     HDcompile_assert(sizeof(ST)<=sizeof(DT));				      \
407     H5T_CONV(H5T_CONV_xX, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
408 }
409 
410 /* Same as H5T_CONV_Xx_CORE, except that instead of using D_MAX and D_MIN
411  * when an overflow occurs, use the 'float' infinity values.
412  */
413 #define H5T_CONV_Ff_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
414     if(*(S) > (ST)(D_MAX)) {                                                  \
415         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI,               \
416                 src_id, dst_id, S, D, cb_struct.user_data);                   \
417         if(except_ret == H5T_CONV_UNHANDLED)                                  \
418             /* Let compiler convert if case is ignored by user handler*/      \
419             *(D) = (H5T_NATIVE_FLOAT_POS_INF_g);		              \
420         else if(except_ret == H5T_CONV_ABORT)                                 \
421             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
422         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
423     } else if (*(S) < (ST)(D_MIN)) {                                          \
424         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW,              \
425                 src_id, dst_id, S, D, cb_struct.user_data);                   \
426         if(except_ret == H5T_CONV_UNHANDLED)                                  \
427             /* Let compiler convert if case is ignored by user handler*/      \
428             *(D) = (H5T_NATIVE_FLOAT_NEG_INF_g);		              \
429         else if(except_ret == H5T_CONV_ABORT)                                 \
430             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
431         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
432     } else								      \
433         *(D) = (DT)(*(S));						      \
434 }
435 #define H5T_CONV_Ff_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
436     if(*(S) > (ST)(D_MAX))                                                    \
437         *(D) = (H5T_NATIVE_FLOAT_POS_INF_g);		                      \
438     else if (*(S) < (ST)(D_MIN))                                              \
439         *(D) = (H5T_NATIVE_FLOAT_NEG_INF_g);		                      \
440     else								      \
441         *(D) = (DT)(*(S));					              \
442 }
443 
444 #define H5T_CONV_Ff(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
445     HDcompile_assert(sizeof(ST)>=sizeof(DT));				      \
446     H5T_CONV(H5T_CONV_Ff, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, N)              \
447 }
448 
449 #define H5T_HI_LO_BIT_SET(TYP, V, LO, HI) {                                   \
450     unsigned count;                                                           \
451     unsigned char p;                                                          \
452     unsigned u;                                                               \
453                                                                               \
454     count = 0;                                                                \
455     for(u = 0; u < sizeof(TYP); u++) {                                        \
456         count = (((unsigned)sizeof(TYP) - 1) - u) * 8;                        \
457         p = (unsigned char)((V) >> count);                                    \
458         if(p > 0) {                                                           \
459             if(p & 0x80)                                                      \
460                 count += 7;                                                   \
461             else if(p & 0x40)                                                 \
462                 count += 6;                                                   \
463             else if(p & 0x20)                                                 \
464                 count += 5;                                                   \
465             else if(p & 0x10)                                                 \
466                 count += 4;                                                   \
467             else if(p & 0x08)                                                 \
468                 count += 3;                                                   \
469             else if(p & 0x04)                                                 \
470                 count += 2;                                                   \
471             else if(p & 0x02)                                                 \
472                 count += 1;                                                   \
473             break;                                                            \
474         } /* end if */                                                        \
475     } /* end for */                                                           \
476                                                                               \
477     HI = count;                                                               \
478                                                                               \
479     count = 0;                                                                \
480     for(u = 0; u < sizeof(TYP); u++) {                                        \
481         p = (unsigned char)((V) >> (u * 8));                                  \
482         if(p > 0) {                                                           \
483             count = u * 8;                                                    \
484                                                                               \
485             if(p & 0x01)                                                      \
486                 ;                                                             \
487             else if(p & 0x02)                                                 \
488                 count += 1;                                                   \
489             else if(p & 0x04)                                                 \
490                 count += 2;                                                   \
491             else if(p & 0x08)                                                 \
492                 count += 3;                                                   \
493             else if(p & 0x10)                                                 \
494                 count += 4;                                                   \
495             else if(p & 0x20)                                                 \
496                 count += 5;                                                   \
497             else if(p & 0x40)                                                 \
498                 count += 6;                                                   \
499             else if(p & 0x80)                                                 \
500                 count += 7;                                                   \
501             break;                                                            \
502         } /* end if */                                                        \
503     } /* end for */                                                           \
504                                                                               \
505     LO = count;                                                               \
506 }
507 
508 #define H5T_CONV_xF_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
509     if (sprec > dprec) {						      \
510         unsigned low_bit_pos, high_bit_pos;                                   \
511                                                                               \
512         /* Detect high & low bits set in source */                            \
513         H5T_HI_LO_BIT_SET(ST, *(S), low_bit_pos, high_bit_pos)                \
514                                                                               \
515         /* Check for more bits of precision in src than available in dst */   \
516         if((high_bit_pos - low_bit_pos) >= dprec) {			      \
517             H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_PRECISION,          \
518                     src_id, dst_id, S, D, cb_struct.user_data);               \
519             if(except_ret == H5T_CONV_UNHANDLED)                              \
520                 /* Let compiler convert if case is ignored by user handler*/  \
521                 *(D) = (DT)(*(S));					      \
522             else if(except_ret == H5T_CONV_ABORT)                             \
523                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
524             /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
525         }        							      \
526         else                                                                  \
527             *(D) = (DT)(*(S));						      \
528     }        								      \
529     else                                                                      \
530         *(D) = (DT)(*(S));						      \
531 }
532 #define H5T_CONV_xF_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
533     *(D) = (DT)(*(S));							      \
534 }
535 
536 #define H5T_CONV_xF(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
537     H5T_CONV(H5T_CONV_xF, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, Y)                 \
538 }
539 
540 /* Quincey added the condition branch (else if (*(S) != (ST)((DT)(*(S))))).
541  * It handles a special situation when the source is "float" and assigned the value
542  * of "INT_MAX".  Compilers do roundup making this value "INT_MAX+1".  This branch
543  * is to check that situation and return exception for some compilers, mainly GCC.
544  * The branch if (*(S) > (DT)(D_MAX) || (sprec < dprec && *(S) ==
545  * (ST)(D_MAX))) is for some compilers like Sun, HP, IBM, and SGI where under
546  * the same situation the "int" doesn't overflow.  SLU - 2005/9/12
547  */
548 #define H5T_CONV_Fx_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
549     if(*(S) > (ST)(D_MAX) || (sprec < dprec && *(S) == (ST)(D_MAX))) {        \
550         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, \
551                 src_id, dst_id, S, D, cb_struct.user_data);                   \
552         if(except_ret == H5T_CONV_UNHANDLED)                                  \
553             /* Let compiler convert if case is ignored by user handler*/      \
554             *(D) = (DT)(D_MAX);						      \
555         else if(except_ret == H5T_CONV_ABORT)                                 \
556             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
557         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
558     } else if (*(S) < (ST)(D_MIN)) {                                          \
559         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW, \
560                 src_id, dst_id, S, D, cb_struct.user_data);                   \
561         if(except_ret == H5T_CONV_UNHANDLED)                                  \
562             /* Let compiler convert if case is ignored by user handler*/      \
563             *(D) = (DT)(D_MIN);						      \
564         else if(except_ret == H5T_CONV_ABORT)                                 \
565             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
566         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
567     } else if (*(S) != (ST)((DT)(*(S)))) {                                    \
568         H5T_conv_ret_t except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_TRUNCATE, \
569                 src_id, dst_id, S, D, cb_struct.user_data);                   \
570         if(except_ret == H5T_CONV_UNHANDLED)                                  \
571             /* Let compiler convert if case is ignored by user handler*/      \
572             *(D) = (DT)(*(S));						      \
573         else if(except_ret == H5T_CONV_ABORT)                                 \
574             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception") \
575         /* if(except_ret==H5T_CONV_HANDLED): Fall through, user handled it */ \
576     }        								      \
577     else                                                                      \
578         *(D) = (DT)(*(S));						      \
579 }
580 #define H5T_CONV_Fx_NOEX_CORE(S,D,ST,DT,D_MIN,D_MAX) {			      \
581     if(*(S) > (ST)(D_MAX))                                                    \
582         *(D) = (DT)(D_MAX);						      \
583     else if(*(S) < (ST)(D_MIN))                                               \
584         *(D) = (DT)(D_MIN);						      \
585     else                                                                      \
586         *(D) = (DT)(*(S));					              \
587 }
588 
589 #define H5T_CONV_Fx(STYPE,DTYPE,ST,DT,D_MIN,D_MAX) {			      \
590     H5T_CONV(H5T_CONV_Fx, STYPE, DTYPE, ST, DT, D_MIN, D_MAX, Y)              \
591 }
592 
593 /* Since all "no exception" cores do the same thing (assign the value in the
594  * source location to the destination location, using casting), use one "core"
595  * to do them all.
596  */
597 #ifndef H5_WANT_DCONV_EXCEPTION
598 #define H5T_CONV_NO_EXCEPT_CORE(S,D,ST,DT,D_MIN,D_MAX) {		      \
599     *(D) = (DT)(*(S));		        				      \
600 }
601 #endif /* H5_WANT_DCONV_EXCEPTION */
602 
603 
604 /* The main part of every integer hardware conversion macro */
605 #define H5T_CONV(GUTS,STYPE,DTYPE,ST,DT,D_MIN,D_MAX,PREC)  		      \
606 {                                                                             \
607     herr_t      ret_value=SUCCEED;      /* Return value         */            \
608                                                                               \
609     FUNC_ENTER_PACKAGE                                                        \
610                                                                               \
611 {                                                                             \
612     size_t	elmtno;			/*element number		*/    \
613     H5T_CONV_DECL_PREC(PREC)            /*declare precision variables, or not */ \
614     uint8_t     *src_buf;		/*'raw' source buffer		*/    \
615     uint8_t     *dst_buf;		/*'raw' destination buffer	*/    \
616     ST	*src, *s;			/*source buffer			*/    \
617     DT	*dst, *d;			/*destination buffer		*/    \
618     H5T_t	*st, *dt;		/*datatype descriptors		*/    \
619     ST	src_aligned;			/*source aligned type		*/    \
620     DT	dst_aligned;			/*destination aligned type	*/    \
621     hbool_t	s_mv, d_mv;		/*move data to align it?	*/    \
622     ssize_t	s_stride, d_stride;	/*src and dst strides		*/    \
623     size_t      safe;                   /*how many elements are safe to process in each pass */ \
624     H5P_genplist_t      *plist;         /*Property list pointer         */    \
625     H5T_conv_cb_t       cb_struct;      /*conversion callback structure */    \
626                                                                               \
627     switch (cdata->command) {						      \
628     case H5T_CONV_INIT:							      \
629 	/* Sanity check and initialize statistics */			      \
630 	cdata->need_bkg = H5T_BKG_NO;					      \
631         if (NULL==(st=(H5T_t*)H5I_object(src_id)) || NULL==(dt=(H5T_t*)H5I_object(dst_id)))   \
632             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,		      \
633                           "unable to dereference datatype object ID")	      \
634 	if (st->shared->size!=sizeof(ST) || dt->shared->size!=sizeof(DT))     \
635 	    HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL,		      \
636 			  "disagreement about datatype size")		      \
637 	CI_ALLOC_PRIV	                                                      \
638 	break;								      \
639 									      \
640     case H5T_CONV_FREE:							      \
641 	/* Print and free statistics */					      \
642 	CI_PRINT_STATS(STYPE,DTYPE);					      \
643 	CI_FREE_PRIV	                                                      \
644 	break;								      \
645 									      \
646     case H5T_CONV_CONV:							      \
647 	/* Initialize source & destination strides */			      \
648 	if (buf_stride) {						      \
649             HDassert(buf_stride >= sizeof(ST));				      \
650             HDassert(buf_stride >= sizeof(DT));				      \
651 	    s_stride = d_stride = (ssize_t)buf_stride;			      \
652 	} else {							      \
653             s_stride = sizeof(ST);					      \
654             d_stride = sizeof(DT);					      \
655         }								      \
656 									      \
657 	/* Is alignment required for source or dest? */			      \
658 	s_mv = H5T_NATIVE_##STYPE##_ALIGN_g>1 &&			      \
659                ((size_t)buf%H5T_NATIVE_##STYPE##_ALIGN_g ||		      \
660      /* Cray */ ((size_t)((ST*)buf)!=(size_t)buf) ||			      \
661 		(size_t)s_stride%H5T_NATIVE_##STYPE##_ALIGN_g);			      \
662 	d_mv = H5T_NATIVE_##DTYPE##_ALIGN_g>1 &&			      \
663                ((size_t)buf%H5T_NATIVE_##DTYPE##_ALIGN_g ||		      \
664      /* Cray */ ((size_t)((DT*)buf)!=(size_t)buf) ||			      \
665                 (size_t)d_stride%H5T_NATIVE_##DTYPE##_ALIGN_g);			      \
666 	CI_INC_SRC(s_mv)						      \
667 	CI_INC_DST(d_mv)						      \
668 	                                                                      \
669         /* Get the plist structure */                                         \
670         if(NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER)))    \
671             HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID") \
672                                                                               \
673         /* Get conversion exception callback property */                      \
674         if(H5P_get(plist, H5D_XFER_CONV_CB_NAME, &cb_struct) < 0)             \
675             HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get conversion exception callback") \
676                                                                               \
677         /* Get source and destination datatypes */			      \
678         if(NULL == (st = (H5T_t *)H5I_object(src_id)) || NULL == (dt = (H5T_t *)H5I_object(dst_id))) \
679             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to dereference datatype object ID") \
680 									      \
681         H5T_CONV_SET_PREC(PREC)            /*init precision variables, or not */ \
682                                                                               \
683         /* The outer loop of the type conversion macro, controlling which */  \
684         /* direction the buffer is walked */				      \
685         while (nelmts>0) {						      \
686             /* Check if we need to go backwards through the buffer */	      \
687             if(d_stride>s_stride) {					      \
688                 /* Compute the number of "safe" destination elements at */    \
689                 /* the end of the buffer (Those which don't overlap with */   \
690                 /* any source elements at the beginning of the buffer) */     \
691                 safe = nelmts - (((nelmts * (size_t)s_stride) + (size_t)(d_stride - 1)) / (size_t)d_stride);      \
692 									      \
693                 /* If we're down to the last few elements, just wrap up */    \
694                 /* with a "real" reverse copy */			      \
695                 if(safe<2) {						      \
696                     src = (ST *)(src_buf = (uint8_t *)buf + (nelmts - 1) * (size_t)s_stride); \
697                     dst = (DT *)(dst_buf = (uint8_t *)buf + (nelmts - 1) * (size_t)d_stride); \
698                     s_stride = -s_stride;				      \
699                     d_stride = -d_stride;				      \
700 									      \
701                     safe=nelmts;					      \
702                 } /* end if */						      \
703                 else {							      \
704                     src = (ST *)(src_buf = (uint8_t *)buf + (nelmts - safe) * (size_t)s_stride); \
705                     dst = (DT *)(dst_buf = (uint8_t *)buf + (nelmts - safe) * (size_t)d_stride); \
706                 } /* end else */					      \
707             } /* end if */						      \
708             else {							      \
709                 /* Single forward pass over all data */			      \
710                 src = (ST *)(src_buf = (uint8_t*)buf);			      \
711                 dst = (DT *)(dst_buf = (uint8_t*)buf);			      \
712                 safe=nelmts;						      \
713             } /* end else */						      \
714                                                                               \
715             /* Perform loop over elements to convert */			      \
716             if (s_mv && d_mv) {						      \
717                 /* Alignment is required for both source and dest */	      \
718                 s = &src_aligned;					      \
719                 H5T_CONV_LOOP_OUTER(PRE_SALIGN,PRE_DALIGN,POST_SALIGN,POST_DALIGN,GUTS,s,d,ST,DT,D_MIN,D_MAX) \
720             } else if(s_mv) {						      \
721                 /* Alignment is required only for source */		      \
722                 s = &src_aligned;					      \
723                 H5T_CONV_LOOP_OUTER(PRE_SALIGN,PRE_DNOALIGN,POST_SALIGN,POST_DNOALIGN,GUTS,s,dst,ST,DT,D_MIN,D_MAX) \
724             } else if(d_mv) {						      \
725                 /* Alignment is required only for destination */	      \
726                 H5T_CONV_LOOP_OUTER(PRE_SNOALIGN,PRE_DALIGN,POST_SNOALIGN,POST_DALIGN,GUTS,src,d,ST,DT,D_MIN,D_MAX) \
727             } else {							      \
728                 /* Alignment is not required for both source and destination */ \
729                 H5T_CONV_LOOP_OUTER(PRE_SNOALIGN,PRE_DNOALIGN,POST_SNOALIGN,POST_DNOALIGN,GUTS,src,dst,ST,DT,D_MIN,D_MAX) \
730             }	 	 	 	 	 	 	 	      \
731 									      \
732             /* Decrement number of elements left to convert */		      \
733             nelmts-=safe;						      \
734         } /* end while */						      \
735         break;								      \
736 									      \
737     default:								      \
738 	HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL,		      \
739 		      "unknown conversion command");			      \
740     }									      \
741 }                                                                             \
742 									      \
743 done:                                                                         \
744     FUNC_LEAVE_NOAPI(ret_value)                                               \
745 }
746 
747 /* Declare the source & destination precision variables */
748 #define H5T_CONV_DECL_PREC(PREC) H5_GLUE(H5T_CONV_DECL_PREC_, PREC)
749 
750 #define H5T_CONV_DECL_PREC_Y                                                  \
751     size_t	sprec;			/*source precision		*/    \
752     size_t	dprec;			/*destination precision		*/    \
753     H5T_class_t tclass;                 /*datatype's class		*/
754 
755 #define H5T_CONV_DECL_PREC_N            /*no precision variables        */
756 
757 /* Initialize the source & destination precision variables */
758 #define H5T_CONV_SET_PREC(PREC) H5_GLUE(H5T_CONV_SET_PREC_, PREC)
759 
760 #define H5T_CONV_SET_PREC_Y                                                   \
761         /* Get source & destination precisions into a variable */	      \
762         tclass = st->shared->type;					      \
763         HDassert(tclass == H5T_INTEGER || tclass == H5T_FLOAT);		      \
764         if(tclass == H5T_INTEGER)					      \
765             sprec = st->shared->u.atomic.prec;				      \
766         else								      \
767             sprec = 1 + st->shared->u.atomic.u.f.msize;			      \
768         tclass = dt->shared->type;					      \
769         HDassert(tclass == H5T_INTEGER || tclass == H5T_FLOAT);		      \
770         if(tclass == H5T_INTEGER)					      \
771             dprec = dt->shared->u.atomic.prec;				      \
772         else								      \
773             dprec = 1 + dt->shared->u.atomic.u.f.msize;
774 
775 #define H5T_CONV_SET_PREC_N             /*don't init precision variables */
776 
777 /* Macro defining action on source data which needs to be aligned (before main action) */
778 #define H5T_CONV_LOOP_PRE_SALIGN(ST) {					      \
779     HDmemcpy(&src_aligned, src, sizeof(ST));				      \
780 }
781 
782 /* Macro defining action on source data which doesn't need to be aligned (before main action) */
783 #define H5T_CONV_LOOP_PRE_SNOALIGN(ST) {				      \
784 }
785 
786 /* Macro defining action on destination data which needs to be aligned (before main action) */
787 #define H5T_CONV_LOOP_PRE_DALIGN(DT) {					      \
788     d = &dst_aligned;							      \
789 }
790 
791 /* Macro defining action on destination data which doesn't need to be aligned (before main action) */
792 #define H5T_CONV_LOOP_PRE_DNOALIGN(DT) {				      \
793 }
794 
795 /* Macro defining action on source data which needs to be aligned (after main action) */
796 #define H5T_CONV_LOOP_POST_SALIGN(ST) {					      \
797 }
798 
799 /* Macro defining action on source data which doesn't need to be aligned (after main action) */
800 #define H5T_CONV_LOOP_POST_SNOALIGN(ST) {				      \
801 }
802 
803 /* Macro defining action on destination data which needs to be aligned (after main action) */
804 #define H5T_CONV_LOOP_POST_DALIGN(DT) {					      \
805     HDmemcpy(dst, &dst_aligned, sizeof(DT));				      \
806 }
807 
808 /* Macro defining action on destination data which doesn't need to be aligned (after main action) */
809 #define H5T_CONV_LOOP_POST_DNOALIGN(DT) {				      \
810 }
811 
812 /* The outer wrapper for the type conversion loop, to check for an exception handling routine */
813 #define H5T_CONV_LOOP_OUTER(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,GUTS,S,D,ST,DT,D_MIN,D_MAX) \
814     if(cb_struct.func) {			                              \
815         H5T_CONV_LOOP(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,GUTS,S,D,ST,DT,D_MIN,D_MAX) \
816     }                                                                         \
817     else {                                                                    \
818         H5T_CONV_LOOP(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,H5_GLUE(GUTS,_NOEX),S,D,ST,DT,D_MIN,D_MAX) \
819     }
820 
821 /* The inner loop of the type conversion macro, actually converting the elements */
822 #define H5T_CONV_LOOP(PRE_SALIGN_GUTS,PRE_DALIGN_GUTS,POST_SALIGN_GUTS,POST_DALIGN_GUTS,GUTS,S,D,ST,DT,D_MIN,D_MAX) \
823     for (elmtno=0; elmtno<safe; elmtno++) {				      \
824         /* Handle source pre-alignment */				      \
825         H5_GLUE(H5T_CONV_LOOP_,PRE_SALIGN_GUTS)(ST)			      \
826                                                                               \
827         /* Handle destination pre-alignment */				      \
828         H5_GLUE(H5T_CONV_LOOP_,PRE_DALIGN_GUTS)(DT)			      \
829                                                                               \
830         /* ... user-defined stuff here -- the conversion ... */		      \
831         H5T_CONV_LOOP_GUTS(GUTS,S,D,ST,DT,D_MIN,D_MAX)			      \
832                                                                               \
833         /* Handle source post-alignment */				      \
834         H5_GLUE(H5T_CONV_LOOP_,POST_SALIGN_GUTS)(ST)			      \
835                                                                               \
836         /* Handle destination post-alignment */				      \
837         H5_GLUE(H5T_CONV_LOOP_,POST_DALIGN_GUTS)(DT)			      \
838                                                                               \
839         /* Advance pointers */						      \
840         src_buf += s_stride;						      \
841         src = (ST *)src_buf;						      \
842         dst_buf += d_stride;						      \
843         dst = (DT *)dst_buf;						      \
844     }
845 
846 /* Macro to call the actual "guts" of the type conversion, or call the "no exception" guts */
847 #ifdef H5_WANT_DCONV_EXCEPTION
848 #define H5T_CONV_LOOP_GUTS(GUTS,S,D,ST,DT,D_MIN,D_MAX)			      \
849         /* ... user-defined stuff here -- the conversion ... */		      \
850         H5_GLUE(GUTS,_CORE)(S,D,ST,DT,D_MIN,D_MAX)
851 #else /* H5_WANT_DCONV_EXCEPTION */
852 #define H5T_CONV_LOOP_GUTS(GUTS,S,D,ST,DT,D_MIN,D_MAX)			      \
853         H5_GLUE(H5T_CONV_NO_EXCEPT,_CORE)(S,D,ST,DT,D_MIN,D_MAX)
854 #endif /* H5_WANT_DCONV_EXCEPTION */
855 
856 
857 #ifdef H5T_DEBUG
858 
859 /* Print alignment statistics */
860 #   define CI_PRINT_STATS(STYPE,DTYPE) {				      \
861     if (H5DEBUG(T) && ((H5T_conv_hw_t *)cdata->priv)->s_aligned) {	      \
862 	HDfprintf(H5DEBUG(T),						      \
863 		  "      %Hu src elements aligned on %lu-byte boundaries\n",  \
864 		  ((H5T_conv_hw_t *)cdata->priv)->s_aligned,		      \
865 		  (unsigned long)H5T_NATIVE_##STYPE##_ALIGN_g);		      \
866     }									      \
867     if (H5DEBUG(T) && ((H5T_conv_hw_t *)cdata->priv)->d_aligned) {	      \
868 	HDfprintf(H5DEBUG(T),						      \
869 		  "      %Hu dst elements aligned on %lu-byte boundaries\n",  \
870 		  ((H5T_conv_hw_t *)cdata->priv)->d_aligned,		      \
871 		  (unsigned long)H5T_NATIVE_##DTYPE##_ALIGN_g);		      \
872     }									      \
873 }
874 
875 /* Allocate private alignment structure for atomic types */
876 #   define CI_ALLOC_PRIV \
877 	if (NULL==(cdata->priv=H5MM_calloc(sizeof(H5T_conv_hw_t)))) {	      \
878 	    HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,		      \
879 			  "memory allocation failed");			      \
880 	}
881 
882 /* Free private alignment structure for atomic types */
883 #   define CI_FREE_PRIV                                 \
884     if(cdata->priv!=NULL)                               \
885         cdata->priv = H5MM_xfree(cdata->priv);
886 
887 /* Increment source alignment counter */
888 #   define CI_INC_SRC(s)   if (s) ((H5T_conv_hw_t *)cdata->priv)->s_aligned += nelmts;
889 
890 /* Increment destination alignment counter */
891 #   define CI_INC_DST(d)   if (d) ((H5T_conv_hw_t *)cdata->priv)->d_aligned += nelmts;
892 #else /* H5T_DEBUG */
893 #   define CI_PRINT_STATS(STYPE,DTYPE) /*void*/
894 #   define CI_ALLOC_PRIV cdata->priv=NULL;
895 #   define CI_FREE_PRIV  /* void */
896 #   define CI_INC_SRC(s) /* void */
897 #   define CI_INC_DST(d) /* void */
898 #endif /* H5T_DEBUG */
899 
900 /* Swap two elements (I & J) of an array using a temporary variable */
901 #define H5_SWAP_BYTES(ARRAY,I,J) {uint8_t _tmp; _tmp=ARRAY[I]; ARRAY[I]=ARRAY[J]; ARRAY[J]=_tmp;}
902 
903 /* Minimum size of variable-length conversion buffer */
904 #define H5T_VLEN_MIN_CONF_BUF_SIZE      4096
905 
906 /******************/
907 /* Local Typedefs */
908 /******************/
909 
910 /* Conversion data for H5T__conv_struct() */
911 typedef struct H5T_conv_struct_t {
912     int	*src2dst;		/*mapping from src to dst member num */
913     hid_t	*src_memb_id;		/*source member type ID's	     */
914     hid_t	*dst_memb_id;		/*destination member type ID's	     */
915     H5T_path_t	**memb_path;		/*conversion path for each member    */
916     H5T_subset_info_t   subset_info;    /*info related to compound subsets   */
917     unsigned            src_nmembs;     /*needed by free function            */
918 } H5T_conv_struct_t;
919 
920 /* Conversion data for H5T__conv_enum() */
921 typedef struct H5T_enum_struct_t {
922     int	base;			/*lowest `in' value		     */
923     unsigned length;		/*num elements in arrays	     */
924     int	*src2dst;		/*map from src to dst index	     */
925 } H5T_enum_struct_t;
926 
927 /* Conversion data for the hardware conversion functions */
928 typedef struct H5T_conv_hw_t {
929     size_t	s_aligned;		/*number source elements aligned     */
930     size_t	d_aligned;		/*number destination elements aligned*/
931 } H5T_conv_hw_t;
932 
933 /********************/
934 /* Package Typedefs */
935 /********************/
936 
937 
938 /********************/
939 /* Local Prototypes */
940 /********************/
941 
942 static herr_t H5T_reverse_order(uint8_t *rev, uint8_t *s, size_t size, H5T_order_t order);
943 
944 
945 /*********************/
946 /* Public Variables */
947 /*********************/
948 
949 
950 /*********************/
951 /* Package Variables */
952 /*********************/
953 
954 
955 /*****************************/
956 /* Library Private Variables */
957 /*****************************/
958 
959 
960 /*******************/
961 /* Local Variables */
962 /*******************/
963 
964 /* Declare a free list to manage pieces of vlen data */
965 H5FL_BLK_DEFINE_STATIC(vlen_seq);
966 
967 /* Declare a free list to manage pieces of array data */
968 H5FL_BLK_DEFINE_STATIC(array_seq);
969 
970 
971 /*--------------------------------------------------------------------------
972 NAME
973    H5T_init_conv_interface -- Initialize interface-specific information
974 USAGE
975     herr_t H5T_init_conv_interface()
976 RETURNS
977     Non-negative on success/Negative on failure
978 DESCRIPTION
979     Initializes any interface-specific data or routines.  (Just calls
980     H5T_init() currently).
981 --------------------------------------------------------------------------*/
982 static herr_t
H5T_init_conv_interface(void)983 H5T_init_conv_interface(void)
984 {
985     FUNC_ENTER_NOAPI_NOINIT_NOERR
986 
987     FUNC_LEAVE_NOAPI(H5T_init())
988 } /* H5T_init_conv_interface() */
989 
990 
991 /*-------------------------------------------------------------------------
992  * Function:	H5T__conv_noop
993  *
994  * Purpose:	The no-op conversion.  The library knows about this
995  *		conversion without it being registered.
996  *
997  * Return: 	Non-negative on success/Negative on failure
998  *
999  * Programmer:	Robb Matzke
1000  *		Wednesday, January 14, 1998
1001  *
1002  *-------------------------------------------------------------------------
1003  */
1004 herr_t
H5T__conv_noop(hid_t H5_ATTR_UNUSED src_id,hid_t H5_ATTR_UNUSED dst_id,H5T_cdata_t * cdata,size_t H5_ATTR_UNUSED nelmts,size_t H5_ATTR_UNUSED buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void H5_ATTR_UNUSED * buf,void H5_ATTR_UNUSED * background,hid_t H5_ATTR_UNUSED dxpl_id)1005 H5T__conv_noop(hid_t H5_ATTR_UNUSED src_id, hid_t H5_ATTR_UNUSED dst_id, H5T_cdata_t *cdata,
1006 	      size_t H5_ATTR_UNUSED nelmts, size_t H5_ATTR_UNUSED buf_stride,
1007               size_t H5_ATTR_UNUSED bkg_stride, void H5_ATTR_UNUSED *buf,
1008 	      void H5_ATTR_UNUSED *background, hid_t H5_ATTR_UNUSED dxpl_id)
1009 {
1010     herr_t      ret_value = SUCCEED;       /* Return value */
1011 
1012     FUNC_ENTER_PACKAGE
1013 
1014     switch(cdata->command) {
1015         case H5T_CONV_INIT:
1016             cdata->need_bkg = H5T_BKG_NO;
1017             break;
1018 
1019         case H5T_CONV_CONV:
1020             /* Nothing to convert */
1021             break;
1022 
1023         case H5T_CONV_FREE:
1024             break;
1025 
1026         default:
1027             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
1028     } /* end switch */
1029 
1030 done:
1031     FUNC_LEAVE_NOAPI(ret_value)
1032 } /* end H5T__conv_noop() */
1033 
1034 
1035 /*-------------------------------------------------------------------------
1036  * Function:	H5T__conv_order_opt
1037  *
1038  * Purpose:	Convert one type to another when byte order is the only
1039  *		difference. This is the optimized version of H5T__conv_order()
1040  *              for a handful of different sizes.
1041  *
1042  * Note:	This is a soft conversion function.
1043  *
1044  * Return:	Non-negative on success/Negative on failure
1045  *
1046  * Programmer:	Robb Matzke
1047  *		Friday, January 25, 2002
1048  *
1049  * Modifications:
1050  *
1051  *-------------------------------------------------------------------------
1052  */
1053 herr_t
H5T__conv_order_opt(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * _buf,void H5_ATTR_UNUSED * background,hid_t H5_ATTR_UNUSED dxpl_id)1054 H5T__conv_order_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
1055                    size_t nelmts, size_t buf_stride,
1056                    size_t H5_ATTR_UNUSED bkg_stride, void *_buf,
1057                    void H5_ATTR_UNUSED *background, hid_t H5_ATTR_UNUSED dxpl_id)
1058 {
1059     uint8_t	*buf = (uint8_t*)_buf;
1060     H5T_t	*src = NULL;
1061     H5T_t	*dst = NULL;
1062     size_t      i;
1063     herr_t      ret_value = SUCCEED;       /* Return value */
1064 
1065     FUNC_ENTER_PACKAGE
1066 
1067     switch(cdata->command) {
1068         case H5T_CONV_INIT:
1069             /* Capability query */
1070             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
1071                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
1072             if(src->shared->size != dst->shared->size ||
1073                     0 != src->shared->u.atomic.offset ||
1074                     0 != dst->shared->u.atomic.offset)
1075                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1076             if((src->shared->type == H5T_REFERENCE && dst->shared->type != H5T_REFERENCE) ||
1077                     (dst->shared->type == H5T_REFERENCE && src->shared->type != H5T_REFERENCE))
1078                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1079             if(src->shared->type != H5T_REFERENCE &&
1080                     !((H5T_ORDER_BE == src->shared->u.atomic.order && H5T_ORDER_LE == dst->shared->u.atomic.order) ||
1081                       (H5T_ORDER_LE == src->shared->u.atomic.order && H5T_ORDER_BE == dst->shared->u.atomic.order)))
1082                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1083             if(src->shared->size != 1 && src->shared->size != 2 && src->shared->size != 4 &&
1084                     src->shared->size != 8 && src->shared->size != 16)
1085                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1086             switch(src->shared->type) {
1087                 case H5T_INTEGER:
1088                 case H5T_BITFIELD:
1089                 case H5T_REFERENCE:
1090                     /* nothing to check */
1091                     break;
1092 
1093                 case H5T_FLOAT:
1094                     if(src->shared->u.atomic.u.f.sign != dst->shared->u.atomic.u.f.sign ||
1095                             src->shared->u.atomic.u.f.epos != dst->shared->u.atomic.u.f.epos ||
1096                             src->shared->u.atomic.u.f.esize != dst->shared->u.atomic.u.f.esize ||
1097                             src->shared->u.atomic.u.f.ebias != dst->shared->u.atomic.u.f.ebias ||
1098                             src->shared->u.atomic.u.f.mpos != dst->shared->u.atomic.u.f.mpos ||
1099                             src->shared->u.atomic.u.f.msize != dst->shared->u.atomic.u.f.msize ||
1100                             src->shared->u.atomic.u.f.norm != dst->shared->u.atomic.u.f.norm ||
1101                             src->shared->u.atomic.u.f.pad != dst->shared->u.atomic.u.f.pad)
1102                         HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1103                     break;
1104 
1105                 case H5T_NO_CLASS:
1106                 case H5T_TIME:
1107                 case H5T_STRING:
1108                 case H5T_OPAQUE:
1109                 case H5T_COMPOUND:
1110                 case H5T_ENUM:
1111                 case H5T_VLEN:
1112                 case H5T_ARRAY:
1113                 case H5T_NCLASSES:
1114                 default:
1115                     HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1116             }
1117             cdata->need_bkg = H5T_BKG_NO;
1118             break;
1119 
1120         case H5T_CONV_CONV:
1121             /* The conversion */
1122             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
1123                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
1124 
1125             /* Check for "no op" reference conversion */
1126             if(src->shared->type == H5T_REFERENCE) {
1127                 /* Sanity check */
1128                 if(dst->shared->type != H5T_REFERENCE)
1129                     HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_REFERENCE datatype")
1130 
1131                 /* Check if we are on a little-endian machine (the order that
1132                  * the addresses in the file must be) and just get out now, there
1133                  * is no need to convert the object reference.  Yes, this is
1134                  * icky and non-portable, but I can't think of a better way to
1135                  * support allowing the objno in the H5O_info_t struct and the
1136                  * hobj_ref_t type to be compared directly without introducing a
1137                  * "native" hobj_ref_t datatype and I think that would break a
1138                  * lot of existing programs.  -QAK
1139                  */
1140                 if(H5T_native_order_g == H5T_ORDER_LE)
1141                     break;
1142             } /* end if */
1143 
1144             buf_stride = buf_stride ? buf_stride : src->shared->size;
1145             switch(src->shared->size) {
1146                 case 1:
1147                     /*no-op*/
1148                     break;
1149 
1150                 case 2:
1151                     for(/*void*/; nelmts >= 20; nelmts -= 20) {
1152                         H5_SWAP_BYTES(buf, 0,   1); /*  0 */
1153                         buf += buf_stride;
1154                         H5_SWAP_BYTES(buf, 0,   1); /*  1 */
1155                         buf += buf_stride;
1156                         H5_SWAP_BYTES(buf, 0,   1); /*  2 */
1157                         buf += buf_stride;
1158                         H5_SWAP_BYTES(buf, 0,   1); /*  3 */
1159                         buf += buf_stride;
1160                         H5_SWAP_BYTES(buf, 0,   1); /*  4 */
1161                         buf += buf_stride;
1162                         H5_SWAP_BYTES(buf, 0,   1); /*  5 */
1163                         buf += buf_stride;
1164                         H5_SWAP_BYTES(buf, 0,   1); /*  6 */
1165                         buf += buf_stride;
1166                         H5_SWAP_BYTES(buf, 0,   1); /*  7 */
1167                         buf += buf_stride;
1168                         H5_SWAP_BYTES(buf, 0,   1); /*  8 */
1169                         buf += buf_stride;
1170                         H5_SWAP_BYTES(buf, 0,   1); /*  9 */
1171                         buf += buf_stride;
1172                         H5_SWAP_BYTES(buf, 0,   1); /* 10 */
1173                         buf += buf_stride;
1174                         H5_SWAP_BYTES(buf, 0,   1); /* 11 */
1175                         buf += buf_stride;
1176                         H5_SWAP_BYTES(buf, 0,   1); /* 12 */
1177                         buf += buf_stride;
1178                         H5_SWAP_BYTES(buf, 0,   1); /* 13 */
1179                         buf += buf_stride;
1180                         H5_SWAP_BYTES(buf, 0,   1); /* 14 */
1181                         buf += buf_stride;
1182                         H5_SWAP_BYTES(buf, 0,   1); /* 15 */
1183                         buf += buf_stride;
1184                         H5_SWAP_BYTES(buf, 0,   1); /* 16 */
1185                         buf += buf_stride;
1186                         H5_SWAP_BYTES(buf, 0,   1); /* 17 */
1187                         buf += buf_stride;
1188                         H5_SWAP_BYTES(buf, 0,   1); /* 18 */
1189                         buf += buf_stride;
1190                         H5_SWAP_BYTES(buf, 0,   1); /* 19 */
1191                         buf += buf_stride;
1192                     } /* end for */
1193                     for(i = 0; i < nelmts; i++, buf += buf_stride)
1194                         H5_SWAP_BYTES(buf, 0, 1);
1195                     break;
1196 
1197                 case 4:
1198                     for(/*void*/; nelmts >= 20; nelmts -= 20) {
1199                         H5_SWAP_BYTES(buf,  0,  3); /*  0 */
1200                         H5_SWAP_BYTES(buf,  1,  2);
1201                         buf += buf_stride;
1202                         H5_SWAP_BYTES(buf,  0,  3); /*  1 */
1203                         H5_SWAP_BYTES(buf,  1,  2);
1204                         buf += buf_stride;
1205                         H5_SWAP_BYTES(buf,  0,  3); /*  2 */
1206                         H5_SWAP_BYTES(buf,  1,  2);
1207                         buf += buf_stride;
1208                         H5_SWAP_BYTES(buf,  0,  3); /*  3 */
1209                         H5_SWAP_BYTES(buf,  1,  2);
1210                         buf += buf_stride;
1211                         H5_SWAP_BYTES(buf,  0,  3); /*  4 */
1212                         H5_SWAP_BYTES(buf,  1,  2);
1213                         buf += buf_stride;
1214                         H5_SWAP_BYTES(buf,  0,  3); /*  5 */
1215                         H5_SWAP_BYTES(buf,  1,  2);
1216                         buf += buf_stride;
1217                         H5_SWAP_BYTES(buf,  0,  3); /*  6 */
1218                         H5_SWAP_BYTES(buf,  1,  2);
1219                         buf += buf_stride;
1220                         H5_SWAP_BYTES(buf,  0,  3); /*  7 */
1221                         H5_SWAP_BYTES(buf,  1,  2);
1222                         buf += buf_stride;
1223                         H5_SWAP_BYTES(buf,  0,  3); /*  8 */
1224                         H5_SWAP_BYTES(buf,  1,  2);
1225                         buf += buf_stride;
1226                         H5_SWAP_BYTES(buf,  0,  3); /*  9 */
1227                         H5_SWAP_BYTES(buf,  1,  2);
1228                         buf += buf_stride;
1229                         H5_SWAP_BYTES(buf,  0,  3); /* 10 */
1230                         H5_SWAP_BYTES(buf,  1,  2);
1231                         buf += buf_stride;
1232                         H5_SWAP_BYTES(buf,  0,  3); /* 11 */
1233                         H5_SWAP_BYTES(buf,  1,  2);
1234                         buf += buf_stride;
1235                         H5_SWAP_BYTES(buf,  0,  3); /* 12 */
1236                         H5_SWAP_BYTES(buf,  1,  2);
1237                         buf += buf_stride;
1238                         H5_SWAP_BYTES(buf,  0,  3); /* 13 */
1239                         H5_SWAP_BYTES(buf,  1,  2);
1240                         buf += buf_stride;
1241                         H5_SWAP_BYTES(buf,  0,  3); /* 14 */
1242                         H5_SWAP_BYTES(buf,  1,  2);
1243                         buf += buf_stride;
1244                         H5_SWAP_BYTES(buf,  0,  3); /* 15 */
1245                         H5_SWAP_BYTES(buf,  1,  2);
1246                         buf += buf_stride;
1247                         H5_SWAP_BYTES(buf,  0,  3); /* 16 */
1248                         H5_SWAP_BYTES(buf,  1,  2);
1249                         buf += buf_stride;
1250                         H5_SWAP_BYTES(buf,  0,  3); /* 17 */
1251                         H5_SWAP_BYTES(buf,  1,  2);
1252                         buf += buf_stride;
1253                         H5_SWAP_BYTES(buf,  0,  3); /* 18 */
1254                         H5_SWAP_BYTES(buf,  1,  2);
1255                         buf += buf_stride;
1256                         H5_SWAP_BYTES(buf,  0,  3); /* 19 */
1257                         H5_SWAP_BYTES(buf,  1,  2);
1258                         buf += buf_stride;
1259                     } /* end for */
1260                     for(i = 0; i < nelmts; i++, buf += buf_stride) {
1261                         H5_SWAP_BYTES(buf, 0, 3);
1262                         H5_SWAP_BYTES(buf, 1, 2);
1263                     } /* end for */
1264                     break;
1265 
1266                 case 8:
1267                     for(/*void*/; nelmts >= 10; nelmts -= 10) {
1268                         H5_SWAP_BYTES(buf,  0,  7); /*  0 */
1269                         H5_SWAP_BYTES(buf,  1,  6);
1270                         H5_SWAP_BYTES(buf,  2,  5);
1271                         H5_SWAP_BYTES(buf,  3,  4);
1272                         buf += buf_stride;
1273                         H5_SWAP_BYTES(buf,  0,  7); /*  1 */
1274                         H5_SWAP_BYTES(buf,  1,  6);
1275                         H5_SWAP_BYTES(buf,  2,  5);
1276                         H5_SWAP_BYTES(buf,  3,  4);
1277                         buf += buf_stride;
1278                         H5_SWAP_BYTES(buf,  0,  7); /*  2 */
1279                         H5_SWAP_BYTES(buf,  1,  6);
1280                         H5_SWAP_BYTES(buf,  2,  5);
1281                         H5_SWAP_BYTES(buf,  3,  4);
1282                         buf += buf_stride;
1283                         H5_SWAP_BYTES(buf,  0,  7); /*  3 */
1284                         H5_SWAP_BYTES(buf,  1,  6);
1285                         H5_SWAP_BYTES(buf,  2,  5);
1286                         H5_SWAP_BYTES(buf,  3,  4);
1287                         buf += buf_stride;
1288                         H5_SWAP_BYTES(buf,  0,  7); /*  4 */
1289                         H5_SWAP_BYTES(buf,  1,  6);
1290                         H5_SWAP_BYTES(buf,  2,  5);
1291                         H5_SWAP_BYTES(buf,  3,  4);
1292                         buf += buf_stride;
1293                         H5_SWAP_BYTES(buf,  0,  7); /*  5 */
1294                         H5_SWAP_BYTES(buf,  1,  6);
1295                         H5_SWAP_BYTES(buf,  2,  5);
1296                         H5_SWAP_BYTES(buf,  3,  4);
1297                         buf += buf_stride;
1298                         H5_SWAP_BYTES(buf,  0,  7); /*  6 */
1299                         H5_SWAP_BYTES(buf,  1,  6);
1300                         H5_SWAP_BYTES(buf,  2,  5);
1301                         H5_SWAP_BYTES(buf,  3,  4);
1302                         buf += buf_stride;
1303                         H5_SWAP_BYTES(buf,  0,  7); /*  7 */
1304                         H5_SWAP_BYTES(buf,  1,  6);
1305                         H5_SWAP_BYTES(buf,  2,  5);
1306                         H5_SWAP_BYTES(buf,  3,  4);
1307                         buf += buf_stride;
1308                         H5_SWAP_BYTES(buf,  0,  7); /*  8 */
1309                         H5_SWAP_BYTES(buf,  1,  6);
1310                         H5_SWAP_BYTES(buf,  2,  5);
1311                         H5_SWAP_BYTES(buf,  3,  4);
1312                         buf += buf_stride;
1313                         H5_SWAP_BYTES(buf,  0,  7); /*  9 */
1314                         H5_SWAP_BYTES(buf,  1,  6);
1315                         H5_SWAP_BYTES(buf,  2,  5);
1316                         H5_SWAP_BYTES(buf,  3,  4);
1317                         buf += buf_stride;
1318                     } /* end for */
1319                     for(i = 0; i < nelmts; i++, buf += buf_stride) {
1320                         H5_SWAP_BYTES(buf, 0, 7);
1321                         H5_SWAP_BYTES(buf, 1, 6);
1322                         H5_SWAP_BYTES(buf, 2, 5);
1323                         H5_SWAP_BYTES(buf, 3, 4);
1324                     } /* end for */
1325                     break;
1326 
1327                 case 16:
1328                     for(/*void*/; nelmts >= 10; nelmts -= 10) {
1329                         H5_SWAP_BYTES(buf,   0,  15); /*  0 */
1330                         H5_SWAP_BYTES(buf,   1,  14);
1331                         H5_SWAP_BYTES(buf,   2,  13);
1332                         H5_SWAP_BYTES(buf,   3,  12);
1333                         H5_SWAP_BYTES(buf,   4,  11);
1334                         H5_SWAP_BYTES(buf,   5,  10);
1335                         H5_SWAP_BYTES(buf,   6,   9);
1336                         H5_SWAP_BYTES(buf,   7,   8);
1337                         buf += buf_stride;
1338                         H5_SWAP_BYTES(buf,   0,  15); /*  1 */
1339                         H5_SWAP_BYTES(buf,   1,  14);
1340                         H5_SWAP_BYTES(buf,   2,  13);
1341                         H5_SWAP_BYTES(buf,   3,  12);
1342                         H5_SWAP_BYTES(buf,   4,  11);
1343                         H5_SWAP_BYTES(buf,   5,  10);
1344                         H5_SWAP_BYTES(buf,   6,   9);
1345                         H5_SWAP_BYTES(buf,   7,   8);
1346                         buf += buf_stride;
1347                         H5_SWAP_BYTES(buf,   0,  15); /*  2 */
1348                         H5_SWAP_BYTES(buf,   1,  14);
1349                         H5_SWAP_BYTES(buf,   2,  13);
1350                         H5_SWAP_BYTES(buf,   3,  12);
1351                         H5_SWAP_BYTES(buf,   4,  11);
1352                         H5_SWAP_BYTES(buf,   5,  10);
1353                         H5_SWAP_BYTES(buf,   6,   9);
1354                         H5_SWAP_BYTES(buf,   7,   8);
1355                         buf += buf_stride;
1356                         H5_SWAP_BYTES(buf,   0,  15); /*  3 */
1357                         H5_SWAP_BYTES(buf,   1,  14);
1358                         H5_SWAP_BYTES(buf,   2,  13);
1359                         H5_SWAP_BYTES(buf,   3,  12);
1360                         H5_SWAP_BYTES(buf,   4,  11);
1361                         H5_SWAP_BYTES(buf,   5,  10);
1362                         H5_SWAP_BYTES(buf,   6,   9);
1363                         H5_SWAP_BYTES(buf,   7,   8);
1364                         buf += buf_stride;
1365                         H5_SWAP_BYTES(buf,   0,  15); /*  4 */
1366                         H5_SWAP_BYTES(buf,   1,  14);
1367                         H5_SWAP_BYTES(buf,   2,  13);
1368                         H5_SWAP_BYTES(buf,   3,  12);
1369                         H5_SWAP_BYTES(buf,   4,  11);
1370                         H5_SWAP_BYTES(buf,   5,  10);
1371                         H5_SWAP_BYTES(buf,   6,   9);
1372                         H5_SWAP_BYTES(buf,   7,   8);
1373                         buf += buf_stride;
1374                         H5_SWAP_BYTES(buf,   0,  15); /*  5 */
1375                         H5_SWAP_BYTES(buf,   1,  14);
1376                         H5_SWAP_BYTES(buf,   2,  13);
1377                         H5_SWAP_BYTES(buf,   3,  12);
1378                         H5_SWAP_BYTES(buf,   4,  11);
1379                         H5_SWAP_BYTES(buf,   5,  10);
1380                         H5_SWAP_BYTES(buf,   6,   9);
1381                         H5_SWAP_BYTES(buf,   7,   8);
1382                         buf += buf_stride;
1383                         H5_SWAP_BYTES(buf,   0,  15); /*  6 */
1384                         H5_SWAP_BYTES(buf,   1,  14);
1385                         H5_SWAP_BYTES(buf,   2,  13);
1386                         H5_SWAP_BYTES(buf,   3,  12);
1387                         H5_SWAP_BYTES(buf,   4,  11);
1388                         H5_SWAP_BYTES(buf,   5,  10);
1389                         H5_SWAP_BYTES(buf,   6,   9);
1390                         H5_SWAP_BYTES(buf,   7,   8);
1391                         buf += buf_stride;
1392                         H5_SWAP_BYTES(buf,   0,  15); /*  7 */
1393                         H5_SWAP_BYTES(buf,   1,  14);
1394                         H5_SWAP_BYTES(buf,   2,  13);
1395                         H5_SWAP_BYTES(buf,   3,  12);
1396                         H5_SWAP_BYTES(buf,   4,  11);
1397                         H5_SWAP_BYTES(buf,   5,  10);
1398                         H5_SWAP_BYTES(buf,   6,   9);
1399                         H5_SWAP_BYTES(buf,   7,   8);
1400                         buf += buf_stride;
1401                         H5_SWAP_BYTES(buf,   0,  15); /*  8 */
1402                         H5_SWAP_BYTES(buf,   1,  14);
1403                         H5_SWAP_BYTES(buf,   2,  13);
1404                         H5_SWAP_BYTES(buf,   3,  12);
1405                         H5_SWAP_BYTES(buf,   4,  11);
1406                         H5_SWAP_BYTES(buf,   5,  10);
1407                         H5_SWAP_BYTES(buf,   6,   9);
1408                         H5_SWAP_BYTES(buf,   7,   8);
1409                         buf += buf_stride;
1410                         H5_SWAP_BYTES(buf,   0,  15); /*  9 */
1411                         H5_SWAP_BYTES(buf,   1,  14);
1412                         H5_SWAP_BYTES(buf,   2,  13);
1413                         H5_SWAP_BYTES(buf,   3,  12);
1414                         H5_SWAP_BYTES(buf,   4,  11);
1415                         H5_SWAP_BYTES(buf,   5,  10);
1416                         H5_SWAP_BYTES(buf,   6,   9);
1417                         H5_SWAP_BYTES(buf,   7,   8);
1418                         buf += buf_stride;
1419                     } /* end for */
1420                     for(i = 0; i < nelmts; i++, buf += buf_stride) {
1421                         H5_SWAP_BYTES(buf, 0, 15);
1422                         H5_SWAP_BYTES(buf, 1, 14);
1423                         H5_SWAP_BYTES(buf, 2, 13);
1424                         H5_SWAP_BYTES(buf, 3, 12);
1425                         H5_SWAP_BYTES(buf, 4, 11);
1426                         H5_SWAP_BYTES(buf, 5, 10);
1427                         H5_SWAP_BYTES(buf, 6,  9);
1428                         H5_SWAP_BYTES(buf, 7,  8);
1429                     } /* end for */
1430                     break;
1431 
1432                 default:
1433                     HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "invalid conversion size")
1434             } /* end switch */
1435             break;
1436 
1437         case H5T_CONV_FREE:
1438             /* Free private data */
1439             break;
1440 
1441         default:
1442             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
1443     } /* end switch */
1444 
1445 done:
1446     FUNC_LEAVE_NOAPI(ret_value)
1447 } /* end H5T__conv_order_opt() */
1448 
1449 
1450 /*-------------------------------------------------------------------------
1451  * Function:	H5T__conv_order
1452  *
1453  * Purpose:	Convert one type to another when byte order is the only
1454  *		difference.
1455  *
1456  * Note:	This is a soft conversion function.
1457  *
1458  * Return:	Non-negative on success/Negative on failure
1459  *
1460  * Programmer:	Robb Matzke
1461  *		Tuesday, January 13, 1998
1462  *
1463  * Modifications:
1464  *		Robb Matzke, 1999-06-16
1465  *		Added the `stride' argument. If its value is non-zero then we
1466  *		stride through memory converting one value at each location;
1467  *		otherwise we assume that the values should be packed.
1468  *
1469  * 		Robb Matzke, 1999-06-16
1470  *		Added support for bitfields.
1471  *-------------------------------------------------------------------------
1472  */
1473 herr_t
H5T__conv_order(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * _buf,void H5_ATTR_UNUSED * background,hid_t H5_ATTR_UNUSED dxpl_id)1474 H5T__conv_order(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
1475 	       size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *_buf,
1476                void H5_ATTR_UNUSED *background, hid_t H5_ATTR_UNUSED dxpl_id)
1477 {
1478     uint8_t	*buf = (uint8_t*)_buf;
1479     H5T_t	*src = NULL;
1480     H5T_t	*dst = NULL;
1481     size_t	i;
1482     size_t	j, md;
1483     herr_t      ret_value = SUCCEED;       /* Return value */
1484 
1485     FUNC_ENTER_PACKAGE
1486 
1487     switch(cdata->command) {
1488         case H5T_CONV_INIT:
1489             /* Capability query */
1490             if(NULL == (src = (H5T_t *)H5I_object(src_id)) ||
1491                     NULL == (dst = (H5T_t *)H5I_object(dst_id)))
1492                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
1493             if(src->shared->size != dst->shared->size || 0 != src->shared->u.atomic.offset ||
1494                     0 != dst->shared->u.atomic.offset ||
1495                     !((H5T_ORDER_BE == src->shared->u.atomic.order &&
1496                        H5T_ORDER_LE == dst->shared->u.atomic.order) ||
1497                       (H5T_ORDER_LE == src->shared->u.atomic.order &&
1498                        H5T_ORDER_BE == dst->shared->u.atomic.order)))
1499                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1500             switch(src->shared->type) {
1501                 case H5T_INTEGER:
1502                 case H5T_BITFIELD:
1503                     /* nothing to check */
1504                     break;
1505 
1506                 case H5T_FLOAT:
1507                     if(src->shared->u.atomic.u.f.sign != dst->shared->u.atomic.u.f.sign ||
1508                             src->shared->u.atomic.u.f.epos != dst->shared->u.atomic.u.f.epos ||
1509                             src->shared->u.atomic.u.f.esize != dst->shared->u.atomic.u.f.esize ||
1510                             src->shared->u.atomic.u.f.ebias != dst->shared->u.atomic.u.f.ebias ||
1511                             src->shared->u.atomic.u.f.mpos != dst->shared->u.atomic.u.f.mpos ||
1512                             src->shared->u.atomic.u.f.msize != dst->shared->u.atomic.u.f.msize ||
1513                             src->shared->u.atomic.u.f.norm != dst->shared->u.atomic.u.f.norm ||
1514                             src->shared->u.atomic.u.f.pad != dst->shared->u.atomic.u.f.pad) {
1515                         HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1516                     } /* end if */
1517                     break;
1518 
1519                 case H5T_NO_CLASS:
1520                 case H5T_TIME:
1521                 case H5T_STRING:
1522                 case H5T_OPAQUE:
1523                 case H5T_COMPOUND:
1524                 case H5T_REFERENCE:
1525                 case H5T_ENUM:
1526                 case H5T_VLEN:
1527                 case H5T_ARRAY:
1528                 case H5T_NCLASSES:
1529                 default:
1530                     HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "conversion not supported")
1531             } /* end switch */
1532             cdata->need_bkg = H5T_BKG_NO;
1533             break;
1534 
1535         case H5T_CONV_CONV:
1536             /* The conversion */
1537             if(NULL == (src = (H5T_t *)H5I_object(src_id)))
1538                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
1539 
1540             buf_stride = buf_stride ? buf_stride : src->shared->size;
1541             md = src->shared->size / 2;
1542             for(i = 0; i < nelmts; i++, buf += buf_stride)
1543                 for(j = 0; j < md; j++)
1544                     H5_SWAP_BYTES(buf, j, src->shared->size - (j + 1));
1545             break;
1546 
1547         case H5T_CONV_FREE:
1548             /* Free private data */
1549             break;
1550 
1551         default:
1552             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
1553     } /* end switch */
1554 
1555 done:
1556     FUNC_LEAVE_NOAPI(ret_value)
1557 } /* end H5T__conv_order() */
1558 
1559 
1560 /*-------------------------------------------------------------------------
1561  * Function:	H5T__conv_b_b
1562  *
1563  * Purpose:	Convert from one bitfield to any other bitfield.
1564  *
1565  * Return:	Non-negative on success/Negative on failure
1566  *
1567  * Programmer:	Robb Matzke
1568  *		Thursday, May 20, 1999
1569  *
1570  * Modifications:
1571  *		Robb Matzke, 1999-06-16
1572  *		Added support for non-zero strides. If BUF_STRIDE is non-zero
1573  *		then convert one value at each memory location advancing
1574  *		BUF_STRIDE bytes each time; otherwise assume both source and
1575  *		destination values are packed.
1576  *-------------------------------------------------------------------------
1577  */
1578 herr_t
H5T__conv_b_b(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * _buf,void H5_ATTR_UNUSED * background,hid_t dxpl_id)1579 H5T__conv_b_b(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
1580 	     size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *_buf,
1581              void H5_ATTR_UNUSED *background, hid_t dxpl_id)
1582 {
1583     uint8_t	*buf = (uint8_t*)_buf;
1584     H5T_t	*src = NULL, *dst = NULL;	/*source and dest datatypes	*/
1585     ssize_t	direction;		/*direction of traversal	*/
1586     size_t	elmtno;			/*element number		*/
1587     size_t	olap;			/*num overlapping elements	*/
1588     size_t	half_size;		/*1/2 of total size for swapping*/
1589     uint8_t	*s, *sp, *d, *dp;	/*source and dest traversal ptrs*/
1590     uint8_t	dbuf[256];		/*temp destination buffer	*/
1591     size_t	msb_pad_offset;		/*offset for dest MSB padding	*/
1592     size_t	i;
1593     uint8_t     *src_rev=NULL;          /*order-reversed source buffer  */
1594     H5P_genplist_t      *plist;         /*property list pointer         */
1595     H5T_conv_cb_t       cb_struct = {NULL, NULL};      /*conversion callback structure */
1596     H5T_conv_ret_t      except_ret;     /*return of callback function   */
1597     hbool_t             reverse;        /*if reverse the order of destination        */
1598     herr_t      ret_value = SUCCEED;      /* Return value */
1599 
1600     FUNC_ENTER_PACKAGE
1601 
1602     switch(cdata->command) {
1603         case H5T_CONV_INIT:
1604             /* Capability query */
1605             if(NULL == (src = (H5T_t *)H5I_object(src_id)) ||
1606                     NULL == (dst = (H5T_t *)H5I_object(dst_id)))
1607                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
1608             if(H5T_ORDER_LE != src->shared->u.atomic.order &&
1609                     H5T_ORDER_BE != src->shared->u.atomic.order)
1610                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
1611             if(H5T_ORDER_LE != dst->shared->u.atomic.order &&
1612                     H5T_ORDER_BE != dst->shared->u.atomic.order)
1613                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
1614             cdata->need_bkg = H5T_BKG_NO;
1615             break;
1616 
1617         case H5T_CONV_FREE:
1618             break;
1619 
1620         case H5T_CONV_CONV:
1621             /* Get the datatypes */
1622             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
1623                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
1624 
1625             /*
1626              * Do we process the values from beginning to end or vice versa? Also,
1627              * how many of the elements have the source and destination areas
1628              * overlapping?
1629              */
1630             if(src->shared->size == dst->shared->size || buf_stride) {
1631                 sp = dp = (uint8_t*)buf;
1632                 direction = 1;
1633                 olap = nelmts;
1634             } else if(src->shared->size >= dst->shared->size) {
1635                 double olap_d = HDceil((double)(dst->shared->size) /
1636                                        (double)(src->shared->size - dst->shared->size));
1637 
1638                 olap = (size_t)olap_d;
1639                 sp = dp = (uint8_t*)buf;
1640                 direction = 1;
1641             } else {
1642                 double olap_d = HDceil((double)(src->shared->size) /
1643                                        (double)(dst->shared->size - src->shared->size));
1644                 olap = (size_t)olap_d;
1645                 sp = (uint8_t*)buf + (nelmts-1) * src->shared->size;
1646                 dp = (uint8_t*)buf + (nelmts-1) * dst->shared->size;
1647                 direction = -1;
1648             }
1649 
1650             /* Get the plist structure */
1651             if(NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER)))
1652                 HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
1653 
1654             /* Get conversion exception callback property */
1655             if(H5P_get(plist, H5D_XFER_CONV_CB_NAME, &cb_struct) < 0)
1656                 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get conversion exception callback")
1657 
1658             /* Allocate space for order-reversed source buffer */
1659             src_rev = (uint8_t *)H5MM_calloc(src->shared->size);
1660 
1661             /* The conversion loop */
1662             H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
1663             H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
1664             H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
1665             for(elmtno = 0; elmtno < nelmts; elmtno++) {
1666 
1667                 /*
1668                  * If the source and destination buffers overlap then use a
1669                  * temporary buffer for the destination.
1670                  */
1671                 if(direction > 0) {
1672                     s = sp;
1673                     d = elmtno < olap ? dbuf : dp;
1674                 } /* end if */
1675                 else {
1676                     s = sp;
1677                     d = (elmtno + olap) >= nelmts ? dbuf : dp;
1678                 } /* end else */
1679 #ifndef NDEBUG
1680                 /* I don't quite trust the overlap calculations yet --rpm */
1681                 if(d == dbuf)
1682                     HDassert((dp >= sp && dp < sp + src->shared->size) ||
1683                             (sp >= dp && sp < dp + dst->shared->size));
1684                 else
1685                     HDassert((dp < sp && dp + dst->shared->size<=sp) ||
1686                             (sp < dp && sp + src->shared->size<=dp));
1687 #endif
1688 
1689                 /*
1690                  * Put the data in little endian order so our loops aren't so
1691                  * complicated.  We'll do all the conversion stuff assuming
1692                  * little endian and then we'll fix the order at the end.
1693                  */
1694                 if(H5T_ORDER_BE == src->shared->u.atomic.order) {
1695                     half_size = src->shared->size / 2;
1696                     for(i = 0; i < half_size; i++) {
1697                         uint8_t tmp = s[src->shared->size - (i + 1)];
1698                         s[src->shared->size - (i + 1)] = s[i];
1699                         s[i] = tmp;
1700                     } /* end for */
1701                 } /* end if */
1702 
1703                 /* Initiate these variables */
1704                 except_ret = H5T_CONV_UNHANDLED;
1705                 reverse    = TRUE;
1706 
1707                 /*
1708                  * Copy the significant part of the value. If the source is larger
1709                  * than the destination then invoke the overflow function or copy
1710                  * as many bits as possible. Zero extra bits in the destination.
1711                  */
1712                 if(src->shared->u.atomic.prec > dst->shared->u.atomic.prec) {
1713                     /*overflow*/
1714                     if(cb_struct.func) { /*If user's exception handler is present, use it*/
1715                         H5T_reverse_order(src_rev, s, src->shared->size, src->shared->u.atomic.order); /*reverse order first*/
1716                         except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
1717                                 src_rev, d, cb_struct.user_data);
1718                     } /* end if */
1719 
1720                     if(except_ret == H5T_CONV_UNHANDLED) {
1721                         H5T__bit_copy(d, dst->shared->u.atomic.offset,
1722                                      s, src->shared->u.atomic.offset, dst->shared->u.atomic.prec);
1723                     } else if(except_ret == H5T_CONV_ABORT)
1724                         HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
1725                     else if(except_ret == H5T_CONV_HANDLED)
1726                         /*Don't reverse because user handles it*/
1727                         reverse = FALSE;
1728                 } else {
1729                     H5T__bit_copy(d, dst->shared->u.atomic.offset,
1730                                  s, src->shared->u.atomic.offset,
1731                                  src->shared->u.atomic.prec);
1732                     H5T__bit_set(d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
1733                                 dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
1734                 }
1735 
1736                 /*
1737                  * Fill the destination padding areas.
1738                  */
1739                 switch(dst->shared->u.atomic.lsb_pad) {
1740                     case H5T_PAD_ZERO:
1741                         H5T__bit_set(d, (size_t)0, dst->shared->u.atomic.offset, FALSE);
1742                         break;
1743 
1744                     case H5T_PAD_ONE:
1745                         H5T__bit_set(d, (size_t)0, dst->shared->u.atomic.offset, TRUE);
1746                         break;
1747 
1748                     case H5T_PAD_ERROR:
1749                     case H5T_PAD_BACKGROUND:
1750                     case H5T_NPAD:
1751                     default:
1752                         HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported LSB padding")
1753                 } /* end switch */
1754                 msb_pad_offset = dst->shared->u.atomic.offset + dst->shared->u.atomic.prec;
1755                 switch(dst->shared->u.atomic.msb_pad) {
1756                     case H5T_PAD_ZERO:
1757                         H5T__bit_set(d, msb_pad_offset, 8 * dst->shared->size - msb_pad_offset, FALSE);
1758                         break;
1759 
1760                     case H5T_PAD_ONE:
1761                         H5T__bit_set(d, msb_pad_offset, 8 * dst->shared->size - msb_pad_offset, TRUE);
1762                         break;
1763 
1764                     case H5T_PAD_ERROR:
1765                     case H5T_PAD_BACKGROUND:
1766                     case H5T_NPAD:
1767                     default:
1768                         HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported MSB padding")
1769                 } /* end switch */
1770 
1771                 /*
1772                  * Put the destination in the correct byte order.  See note at
1773                  * beginning of loop.
1774                  */
1775                 if(H5T_ORDER_BE == dst->shared->u.atomic.order && reverse) {
1776                     half_size = dst->shared->size / 2;
1777                     for(i = 0; i < half_size; i++) {
1778                         uint8_t tmp = d[dst->shared->size - (i + 1)];
1779                         d[dst->shared->size - (i + 1)] = d[i];
1780                         d[i] = tmp;
1781                     } /* end for */
1782                 } /* end if */
1783 
1784                 /*
1785                  * If we had used a temporary buffer for the destination then we
1786                  * should copy the value to the true destination buffer.
1787                  */
1788                 if(d == dbuf)
1789                     HDmemcpy(dp, d, dst->shared->size);
1790                 if(buf_stride) {
1791                     sp += direction * (ssize_t)buf_stride; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
1792                     dp += direction * (ssize_t)buf_stride; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
1793                 } /* end if */
1794                 else {
1795                     sp += direction * (ssize_t)src->shared->size; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
1796                     dp += direction * (ssize_t)dst->shared->size; /* Note that cast is checked with H5_CHECK_OVERFLOW, above */
1797                 } /* end else */
1798             } /* end for */
1799 
1800             break;
1801 
1802         default:
1803             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
1804     } /* end switch */
1805 
1806 done:
1807     if(src_rev)
1808         H5MM_free(src_rev);
1809     FUNC_LEAVE_NOAPI(ret_value)
1810 } /* end H5T__conv_b_b() */
1811 
1812 
1813 /*-------------------------------------------------------------------------
1814  * Function:	H5T_conv_struct_free
1815  *
1816  * Purpose:	Free the private data structure used by the compound
1817  *      conversion functions.
1818  *
1819  * Return:	The result of H5MM_xfree(priv) (NULL)
1820  *
1821  * Programmer:	Neil Fortner
1822  *		Wednesday, October 1, 2008
1823  *
1824  * Modifications:
1825  *
1826  *-------------------------------------------------------------------------
1827  */
1828 static H5T_conv_struct_t *
H5T_conv_struct_free(H5T_conv_struct_t * priv)1829 H5T_conv_struct_free(H5T_conv_struct_t *priv)
1830 {
1831     int         *src2dst = priv->src2dst;
1832     hid_t       *src_memb_id = priv->src_memb_id,
1833                 *dst_memb_id = priv->dst_memb_id;
1834     unsigned    i;
1835 
1836     FUNC_ENTER_NOAPI_NOINIT_NOERR
1837 
1838     for(i = 0; i < priv->src_nmembs; i++)
1839         if(src2dst[i] >= 0) {
1840             int status;
1841 
1842             status = H5I_dec_ref(src_memb_id[i]);
1843             HDassert(status >= 0);
1844             status = H5I_dec_ref(dst_memb_id[src2dst[i]]);
1845             HDassert(status >= 0);
1846         } /* end if */
1847 
1848     H5MM_xfree(src2dst);
1849     H5MM_xfree(src_memb_id);
1850     H5MM_xfree(dst_memb_id);
1851     H5MM_xfree(priv->memb_path);
1852 
1853     FUNC_LEAVE_NOAPI((H5T_conv_struct_t *)H5MM_xfree(priv))
1854 } /* end H5T_conv_struct_free() */
1855 
1856 
1857 /*-------------------------------------------------------------------------
1858  * Function:	H5T_conv_struct_init
1859  *
1860  * Purpose:	Initialize the `priv' field of `cdata' with conversion
1861  *		information that is relatively constant.  If `priv' is
1862  *		already initialized then the member conversion functions
1863  *		are recalculated.
1864  *
1865  *		Priv fields are indexed by source member number or
1866  *		destination member number depending on whether the field
1867  *		contains information about the source datatype or the
1868  *		destination datatype (fields that contains the same
1869  *		information for both source and destination are indexed by
1870  *		source member number).  The src2dst[] priv array maps source
1871  *		member numbers to destination member numbers, but if the
1872  *		source member doesn't have a corresponding destination member
1873  *		then the src2dst[i]=-1.
1874  *
1875  * Return:	Non-negative on success/Negative on failure
1876  *
1877  * Programmer:	Robb Matzke
1878  *		Monday, January 26, 1998
1879  *
1880  * Modifications:
1881  *              Raymond Lu, 3 May 2007
1882  *              Added the detection for a special optimization case when the
1883  *              source and destination members are a subset of each other, and
1884  *              the order is the same, and no conversion is needed.  For example:
1885  *                  struct source {            struct destination {
1886  *                      TYPE1 A;      -->          TYPE1 A;
1887  *                      TYPE2 B;      -->          TYPE2 B;
1888  *                      TYPE3 C;      -->          TYPE3 C;
1889  *                  };                             TYPE4 D;
1890  *                                                 TYPE5 E;
1891  *                                             };
1892  *              or
1893  *                  struct destination {       struct source {
1894  *                      TYPE1 A;      <--          TYPE1 A;
1895  *                      TYPE2 B;      <--          TYPE2 B;
1896  *                      TYPE3 C;      <--          TYPE3 C;
1897  *                  };                             TYPE4 D;
1898  *                                                 TYPE5 E;
1899  *                                             };
1900  *              The optimization is simply moving data to the appropriate
1901  *              places in the buffer.
1902  *
1903  *-------------------------------------------------------------------------
1904  */
1905 static herr_t
H5T_conv_struct_init(H5T_t * src,H5T_t * dst,H5T_cdata_t * cdata,hid_t dxpl_id)1906 H5T_conv_struct_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata, hid_t dxpl_id)
1907 {
1908     H5T_conv_struct_t	*priv = (H5T_conv_struct_t*)(cdata->priv);
1909     int		        *src2dst = NULL;
1910     unsigned            src_nmembs, dst_nmembs;
1911     unsigned		i, j;
1912     herr_t              ret_value = SUCCEED;       /* Return value */
1913 
1914     FUNC_ENTER_NOAPI_NOINIT
1915 
1916     src_nmembs = src->shared->u.compnd.nmembs;
1917     dst_nmembs = dst->shared->u.compnd.nmembs;
1918 
1919     if(!priv) {
1920         /*
1921          * Allocate private data structure and arrays.
1922          */
1923         if(NULL == (priv = (H5T_conv_struct_t *)(cdata->priv=H5MM_calloc(sizeof(H5T_conv_struct_t)))) ||
1924                 NULL == (priv->src2dst = (int *)H5MM_malloc(src_nmembs * sizeof(int))) ||
1925                 NULL == (priv->src_memb_id = (hid_t *)H5MM_malloc(src_nmembs * sizeof(hid_t))) ||
1926                 NULL == (priv->dst_memb_id = (hid_t *)H5MM_malloc(dst_nmembs * sizeof(hid_t))))
1927             HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
1928         src2dst = priv->src2dst;
1929         priv->src_nmembs = src_nmembs;
1930 
1931         /* The flag of special optimization to indicate if source members and destination
1932          * members are a subset of each other.  Initialize it to FALSE */
1933         priv->subset_info.subset = H5T_SUBSET_FALSE;
1934         priv->subset_info.copy_size = 0;
1935 
1936         /*
1937          * Insure that members are sorted.
1938          */
1939         H5T__sort_value(src, NULL);
1940         H5T__sort_value(dst, NULL);
1941 
1942         /*
1943          * Build a mapping from source member number to destination member
1944          * number. If some source member is not a destination member then that
1945          * mapping element will be negative.  Also create atoms for each
1946          * source and destination member datatype so we can look up the
1947          * member datatype conversion functions later.
1948          */
1949         for(i = 0; i < src_nmembs; i++) {
1950             src2dst[i] = -1;
1951             for(j = 0; j < dst_nmembs; j++) {
1952                 if(!HDstrcmp(src->shared->u.compnd.memb[i].name, dst->shared->u.compnd.memb[j].name)) {
1953                     H5_CHECKED_ASSIGN(src2dst[i], int, j, unsigned);
1954                     break;
1955                 } /* end if */
1956             } /* end for */
1957             if(src2dst[i] >= 0) {
1958                 hid_t	tid;
1959                 H5T_t	*type;
1960 
1961                 type = H5T_copy(src->shared->u.compnd.memb[i].type, H5T_COPY_ALL);
1962                 tid = H5I_register(H5I_DATATYPE, type, FALSE);
1963                 HDassert(tid >= 0);
1964                 priv->src_memb_id[i] = tid;
1965 
1966                 type = H5T_copy(dst->shared->u.compnd.memb[src2dst[i]].type, H5T_COPY_ALL);
1967                 tid = H5I_register(H5I_DATATYPE, type, FALSE);
1968                 HDassert(tid >= 0);
1969                 priv->dst_memb_id[src2dst[i]] = tid;
1970             } /* end if */
1971         } /* end for */
1972     } /* end if */
1973     else {
1974         /* Restore sorted conditions for the datatypes */
1975         /* (Required for the src2dst array to be valid) */
1976         H5T__sort_value(src, NULL);
1977         H5T__sort_value(dst, NULL);
1978     } /* end else */
1979 
1980     /*
1981      * (Re)build the cache of member conversion functions and pointers to
1982      * their cdata entries.
1983      */
1984     src2dst = priv->src2dst;
1985     H5MM_xfree(priv->memb_path);
1986     if(NULL == (priv->memb_path = (H5T_path_t **)H5MM_malloc(src->shared->u.compnd.nmembs * sizeof(H5T_path_t*))))
1987         HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
1988 
1989     for(i = 0; i < src_nmembs; i++) {
1990         if(src2dst[i] >= 0) {
1991             H5T_path_t *tpath = H5T_path_find(src->shared->u.compnd.memb[i].type, dst->shared->u.compnd.memb[src2dst[i]].type, NULL, NULL, dxpl_id, FALSE);
1992 
1993             if(NULL == (priv->memb_path[i] = tpath)) {
1994                 cdata->priv = H5T_conv_struct_free(priv);
1995                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unable to convert member datatype")
1996             } /* end if */
1997         } /* end if */
1998     } /* end for */
1999 
2000     /* The compound conversion functions need a background buffer */
2001     cdata->need_bkg = H5T_BKG_YES;
2002 
2003     if(src_nmembs < dst_nmembs) {
2004         priv->subset_info.subset = H5T_SUBSET_SRC;
2005         for(i = 0; i < src_nmembs; i++) {
2006             /* If any of source members doesn't have counterpart in the same
2007                 * order or there's conversion between members, don't do the
2008                 * optimization.
2009                 */
2010             if(src2dst[i] != (int)i || (src->shared->u.compnd.memb[i].offset != dst->shared->u.compnd.memb[i].offset) || (priv->memb_path[i])->is_noop == FALSE) {
2011                 priv->subset_info.subset = H5T_SUBSET_FALSE;
2012                 break;
2013             } /* end if */
2014         } /* end for */
2015         /* Compute the size of the data to be copied for each element.  It
2016             * may be smaller than either src or dst if there is extra space at
2017             * the end of src.
2018             */
2019         if(priv->subset_info.subset == H5T_SUBSET_SRC)
2020             priv->subset_info.copy_size = src->shared->u.compnd.memb[src_nmembs - 1].offset
2021                 + src->shared->u.compnd.memb[src_nmembs - 1].size;
2022     } else if(dst_nmembs < src_nmembs) {
2023         priv->subset_info.subset = H5T_SUBSET_DST;
2024         for(i = 0; i < dst_nmembs; i++) {
2025             /* If any of source members doesn't have counterpart in the same order or
2026                 * there's conversion between members, don't do the optimization. */
2027             if(src2dst[i] != (int)i || (src->shared->u.compnd.memb[i].offset != dst->shared->u.compnd.memb[i].offset) || (priv->memb_path[i])->is_noop == FALSE) {
2028                 priv->subset_info.subset = H5T_SUBSET_FALSE;
2029                 break;
2030             }
2031         } /* end for */
2032         /* Compute the size of the data to be copied for each element.  It
2033             * may be smaller than either src or dst if there is extra space at
2034             * the end of dst.
2035             */
2036         if(priv->subset_info.subset == H5T_SUBSET_DST)
2037             priv->subset_info.copy_size = dst->shared->u.compnd.memb[dst_nmembs-1].offset
2038                 + dst->shared->u.compnd.memb[dst_nmembs-1].size;
2039     } else /* If the numbers of source and dest members are equal and no conversion is needed,
2040             * the case should have been handled as noop earlier in H5Dio.c. */
2041         {;}
2042 
2043     cdata->recalc = FALSE;
2044 
2045 done:
2046     FUNC_LEAVE_NOAPI(ret_value)
2047 } /* end H5T_conv_struct_init() */
2048 
2049 
2050 /*-------------------------------------------------------------------------
2051  * Function:	H5T__conv_struct_subset
2052  *
2053  * Purpose:     A quick way to return a field in a struct private in this
2054  *              file.  The flag SMEMBS_SUBSET indicates whether the source
2055  *              members are a subset of destination or the destination
2056  *              members are a subset of the source, and the order is the
2057  *              same, and no conversion is needed.  For example:
2058  *                  struct source {            struct destination {
2059  *                      TYPE1 A;      -->          TYPE1 A;
2060  *                      TYPE2 B;      -->          TYPE2 B;
2061  *                      TYPE3 C;      -->          TYPE3 C;
2062  *                  };                             TYPE4 D;
2063  *                                                 TYPE5 E;
2064  *                                             };
2065  *
2066  * Return:      A pointer to the subset info struct in p.  Points directly
2067  *              into the structure.
2068  *
2069  * Programmer:	Raymond Lu
2070  *		8 June 2007
2071  *
2072  *-------------------------------------------------------------------------
2073  */
2074 H5T_subset_info_t *
H5T__conv_struct_subset(const H5T_cdata_t * cdata)2075 H5T__conv_struct_subset(const H5T_cdata_t *cdata)
2076 {
2077     H5T_conv_struct_t	*priv;
2078 
2079     FUNC_ENTER_PACKAGE_NOERR
2080 
2081     HDassert(cdata);
2082     HDassert(cdata->priv);
2083 
2084     priv = (H5T_conv_struct_t *)(cdata->priv);
2085 
2086     FUNC_LEAVE_NOAPI((H5T_subset_info_t *) &priv->subset_info)
2087 } /* end H5T__conv_struct_subset() */
2088 
2089 
2090 /*-------------------------------------------------------------------------
2091  * Function:	H5T__conv_struct
2092  *
2093  * Purpose:	Converts between compound datatypes.  This is a soft
2094  *		conversion function.  The algorithm is basically:
2095  *
2096  * 		For each element do
2097  *		  For I=1..NELMTS do
2098  *		    If sizeof detination type <= sizeof source type then
2099  *		      Convert member to destination type;
2100  *		    Move member as far left as possible;
2101  *
2102  *		  For I=NELMTS..1 do
2103  *		    If not destination type then
2104  *		      Convert member to destination type;
2105  *		    Move member to correct position in BKG
2106  *
2107  *		  Copy BKG to BUF
2108  *
2109  * Return:	Non-negative on success/Negative on failure
2110  *
2111  * Programmer:	Robb Matzke
2112  *		Thursday, January 22, 1998
2113  *
2114  *-------------------------------------------------------------------------
2115  */
2116 herr_t
H5T__conv_struct(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t bkg_stride,void * _buf,void * _bkg,hid_t dxpl_id)2117 H5T__conv_struct(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
2118     size_t buf_stride, size_t bkg_stride, void *_buf, void *_bkg, hid_t dxpl_id)
2119 {
2120     uint8_t	*buf = (uint8_t *)_buf;	/*cast for pointer arithmetic	*/
2121     uint8_t	*bkg = (uint8_t *)_bkg;	/*background pointer arithmetic	*/
2122     uint8_t     *xbuf = buf, *xbkg = bkg;   /*temp pointers into buf and bkg*/
2123     H5T_t	*src = NULL;		/*source datatype		*/
2124     H5T_t	*dst = NULL;		/*destination datatype		*/
2125     int	*src2dst = NULL;	/*maps src member to dst member	*/
2126     H5T_cmemb_t	*src_memb = NULL;	/*source struct member descript.*/
2127     H5T_cmemb_t	*dst_memb = NULL;	/*destination struct memb desc.	*/
2128     size_t	offset;			/*byte offset wrt struct	*/
2129     ssize_t	src_delta;	        /*source stride	*/
2130     ssize_t	bkg_delta;	        /*background stride	*/
2131     size_t	elmtno;
2132     unsigned	u;		        /*counters			*/
2133     int	        i;			/*counters			*/
2134     H5T_conv_struct_t *priv = (H5T_conv_struct_t *)(cdata->priv);
2135     herr_t      ret_value = SUCCEED;       /* Return value */
2136 
2137     FUNC_ENTER_PACKAGE
2138 
2139     switch(cdata->command) {
2140         case H5T_CONV_INIT:
2141             /*
2142              * First, determine if this conversion function applies to the
2143              * conversion path SRC_ID-->DST_ID.  If not, return failure;
2144              * otherwise initialize the `priv' field of `cdata' with information
2145              * that remains (almost) constant for this conversion path.
2146              */
2147             if (NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2148                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype")
2149             if(H5T_COMPOUND != src->shared->type)
2150                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_COMPOUND datatype")
2151             if(H5T_COMPOUND != dst->shared->type)
2152                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_COMPOUND datatype")
2153 
2154             if(H5T_conv_struct_init(src, dst, cdata, dxpl_id) < 0)
2155                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data")
2156             break;
2157 
2158         case H5T_CONV_FREE:
2159             /*
2160              * Free the private conversion data.
2161              */
2162             cdata->priv = H5T_conv_struct_free(priv);
2163             break;
2164 
2165         case H5T_CONV_CONV:
2166             /*
2167              * Conversion.
2168              */
2169             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2170                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype")
2171             HDassert(priv);
2172             HDassert(bkg && cdata->need_bkg);
2173 
2174             if(cdata->recalc && H5T_conv_struct_init(src, dst, cdata, dxpl_id) < 0)
2175                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data")
2176 
2177             /*
2178              * Insure that members are sorted.
2179              */
2180             H5T__sort_value(src, NULL);
2181             H5T__sort_value(dst, NULL);
2182             src2dst = priv->src2dst;
2183 
2184             /*
2185              * Direction of conversion and striding through background.
2186              */
2187             if(buf_stride) {
2188                 H5_CHECKED_ASSIGN(src_delta, ssize_t, buf_stride, size_t);
2189                 if(!bkg_stride) {
2190                     H5_CHECKED_ASSIGN(bkg_delta, ssize_t, dst->shared->size, size_t);
2191                 } /* end if */
2192                 else
2193                     H5_CHECKED_ASSIGN(bkg_delta, ssize_t, bkg_stride, size_t);
2194             } /* end if */
2195             else if(dst->shared->size <= src->shared->size) {
2196                 H5_CHECKED_ASSIGN(src_delta, ssize_t, src->shared->size, size_t);
2197                 H5_CHECKED_ASSIGN(bkg_delta, ssize_t, dst->shared->size, size_t);
2198             } /* end else-if */
2199             else {
2200                 H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
2201                 src_delta = -(ssize_t)src->shared->size;
2202                 H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
2203                 bkg_delta = -(ssize_t)dst->shared->size;
2204                 xbuf += (nelmts - 1) * src->shared->size;
2205                 xbkg += (nelmts - 1) * dst->shared->size;
2206             } /* end else */
2207 
2208             /* Conversion loop... */
2209             for(elmtno = 0; elmtno < nelmts; elmtno++) {
2210                 /*
2211                  * For each source member which will be present in the
2212                  * destination, convert the member to the destination type unless
2213                  * it is larger than the source type.  Then move the member to the
2214                  * left-most unoccupied position in the buffer.  This makes the
2215                  * data point as small as possible with all the free space on the
2216                  * right side.
2217                  */
2218                 for(u = 0, offset = 0; u < src->shared->u.compnd.nmembs; u++) {
2219                     if(src2dst[u] < 0)
2220                         continue; /*subsetting*/
2221                     src_memb = src->shared->u.compnd.memb + u;
2222                     dst_memb = dst->shared->u.compnd.memb + src2dst[u];
2223 
2224                     if(dst_memb->size <= src_memb->size) {
2225                         if(H5T_convert(priv->memb_path[u], priv->src_memb_id[u],
2226                                 priv->dst_memb_id[src2dst[u]],
2227                                 (size_t)1, (size_t)0, (size_t)0, /*no striding (packed array)*/
2228                                 xbuf + src_memb->offset, xbkg + dst_memb->offset,
2229                                 dxpl_id) < 0)
2230                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound datatype member")
2231                         HDmemmove(xbuf + offset, xbuf + src_memb->offset, dst_memb->size);
2232                         offset += dst_memb->size;
2233                     } /* end if */
2234                     else {
2235                         HDmemmove (xbuf+offset, xbuf+src_memb->offset,
2236                                    src_memb->size);
2237                         offset += src_memb->size;
2238                     } /* end else */
2239                 } /* end for */
2240 
2241                 /*
2242                  * For each source member which will be present in the
2243                  * destination, convert the member to the destination type if it
2244                  * is larger than the source type (that is, has not been converted
2245                  * yet).  Then copy the member to the destination offset in the
2246                  * background buffer.
2247                  */
2248                 H5_CHECK_OVERFLOW(src->shared->u.compnd.nmembs, size_t, int);
2249                 for(i = (int)src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
2250                     if(src2dst[i] < 0)
2251                         continue; /*subsetting*/
2252                     src_memb = src->shared->u.compnd.memb + i;
2253                     dst_memb = dst->shared->u.compnd.memb + src2dst[i];
2254 
2255                     if(dst_memb->size > src_memb->size) {
2256                         offset -= src_memb->size;
2257                         if(H5T_convert(priv->memb_path[i],
2258                                     priv->src_memb_id[i], priv->dst_memb_id[src2dst[i]],
2259                                     (size_t)1, (size_t)0, (size_t)0, /*no striding (packed array)*/
2260                                     xbuf + offset, xbkg + dst_memb->offset,
2261                                     dxpl_id) < 0)
2262                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound datatype member")
2263                     } /* end if */
2264                     else
2265                         offset -= dst_memb->size;
2266                     HDmemmove(xbkg + dst_memb->offset, xbuf + offset, dst_memb->size);
2267                 } /* end for */
2268                 HDassert(0 == offset);
2269 
2270                 /*
2271                  * Update pointers
2272                  */
2273                 xbuf += src_delta;
2274                 xbkg += bkg_delta;
2275             } /* end for */
2276 
2277             /* If the bkg_delta was set to -(dst->shared->size), make it positive now */
2278             if(buf_stride == 0 && dst->shared->size > src->shared->size)
2279                 H5_CHECKED_ASSIGN(bkg_delta, ssize_t, dst->shared->size, size_t);
2280 
2281             /*
2282              * Copy the background buffer back into the in-place conversion
2283              * buffer.
2284              */
2285             for(xbuf = buf, xbkg = bkg, elmtno = 0; elmtno < nelmts; elmtno++) {
2286                 HDmemmove(xbuf, xbkg, dst->shared->size);
2287                 xbuf += buf_stride ? buf_stride : dst->shared->size;
2288                 xbkg += bkg_delta;
2289             } /* end for */
2290             break;
2291 
2292         default:
2293             /* Some other command we don't know about yet.*/
2294             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
2295     } /* end switch */
2296 
2297 done:
2298     FUNC_LEAVE_NOAPI(ret_value)
2299 } /* end H5T__conv_struct() */
2300 
2301 
2302 /*-------------------------------------------------------------------------
2303  * Function:	H5T__conv_struct_opt
2304  *
2305  * Purpose:	Converts between compound datatypes in a manner more
2306  *		efficient than the general-purpose H5T__conv_struct()
2307  *		function.  This function isn't applicable if the destination
2308  *		is larger than the source type. This is a soft conversion
2309  *		function.  The algorithm is basically:
2310  *
2311  * 		For each member of the struct
2312  *		  If sizeof detination type <= sizeof source type then
2313  *		    Convert member to destination type for all elements
2314  *		    Move memb to BKG buffer for all elements
2315  *		  Else
2316  *		    Move member as far left as possible for all elements
2317  *
2318  *		For each member of the struct (in reverse order)
2319  *		  If not destination type then
2320  *		    Convert member to destination type for all elements
2321  *		    Move member to correct position in BKG for all elements
2322  *
2323  *		Copy BKG to BUF for all elements
2324  *
2325  * Return:	Non-negative on success/Negative on failure
2326  *
2327  * Programmer:	Robb Matzke
2328  *		Thursday, January 22, 1998
2329  *
2330  * Modifications:
2331  *		Robb Matzke, 1999-06-16
2332  *              Added support for non-zero strides. If BUF_STRIDE is
2333  *              non-zero then convert one value at each memory location
2334  *              advancing BUF_STRIDE bytes each time; otherwise assume both
2335  *              source and destination values are packed.
2336  *
2337  * 		Robb Matzke, 1999-06-16
2338  *		If the source and destination data structs are the same size
2339  *		then we can convert on a field-by-field basis instead of an
2340  *		element by element basis. In other words, for all struct
2341  *		elements being converted by this function call, first convert
2342  *		all of the field1's, then all field2's, etc. This can
2343  *		drastically reduce the number of calls to H5T_convert() and
2344  *		thereby eliminate most of the conversion constant overhead.
2345  *
2346  *              Robb Matzke, 2000-05-17
2347  *              Added the BKG_STRIDE argument to fix a design bug. If
2348  *              BUF_STRIDE and BKG_STRIDE are both non-zero then each
2349  *              data element converted will be placed temporarily at a
2350  *              multiple of BKG_STRIDE in the BKG buffer; otherwise the
2351  *              BKG buffer is assumed to be a packed array of destination
2352  *              datatype.
2353  *
2354  *              Raymond Lu, 3 May 2007
2355  *              Optimize a special case when the source and destination members
2356  *              are a subset of each other, and the order is the same, and no
2357  *              conversion is needed.  For example:
2358  *                  struct source {            struct destination {
2359  *                      TYPE1 A;      -->          TYPE1 A;
2360  *                      TYPE2 B;      -->          TYPE2 B;
2361  *                      TYPE3 C;      -->          TYPE3 C;
2362  *                  };                             TYPE4 D;
2363  *                                                 TYPE5 E;
2364  *                                             };
2365  *              The optimization is simply moving data to the appropriate
2366  *              places in the buffer.
2367  *
2368  *-------------------------------------------------------------------------
2369  */
2370 herr_t
H5T__conv_struct_opt(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t bkg_stride,void * _buf,void * _bkg,hid_t dxpl_id)2371 H5T__conv_struct_opt(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
2372     size_t nelmts, size_t buf_stride, size_t bkg_stride, void *_buf,
2373     void *_bkg, hid_t dxpl_id)
2374 {
2375     uint8_t	*buf = (uint8_t *)_buf;	/*cast for pointer arithmetic	*/
2376     uint8_t	*bkg = (uint8_t *)_bkg;	/*background pointer arithmetic	*/
2377     uint8_t	*xbuf = NULL;		/*temporary pointer into `buf'	*/
2378     uint8_t	*xbkg = NULL;		/*temporary pointer into `bkg'	*/
2379     H5T_t	*src = NULL;		/*source datatype		*/
2380     H5T_t	*dst = NULL;		/*destination datatype		*/
2381     int	*src2dst = NULL;		/*maps src member to dst member	*/
2382     H5T_cmemb_t	*src_memb = NULL;	/*source struct member descript.*/
2383     H5T_cmemb_t	*dst_memb = NULL;	/*destination struct memb desc.	*/
2384     size_t	offset;			/*byte offset wrt struct	*/
2385     size_t	elmtno;			/*element counter		*/
2386     size_t      copy_size;              /*size of element for copying   */
2387     H5T_conv_struct_t *priv = NULL;	/*private data			*/
2388     hbool_t     no_stride = FALSE;      /*flag to indicate no stride    */
2389     unsigned	u;			/*counters			*/
2390     int		i;			/*counters			*/
2391     herr_t      ret_value = SUCCEED;    /* Return value */
2392 
2393     FUNC_ENTER_PACKAGE
2394 
2395     switch(cdata->command) {
2396         case H5T_CONV_INIT:
2397             /*
2398              * First, determine if this conversion function applies to the
2399              * conversion path SRC_ID-->DST_ID.  If not, return failure;
2400              * otherwise initialize the `priv' field of `cdata' with information
2401              * that remains (almost) constant for this conversion path.
2402              */
2403             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2404                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
2405             if(H5T_COMPOUND != src->shared->type)
2406                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_COMPOUND datatype")
2407             if(H5T_COMPOUND != dst->shared->type)
2408                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_COMPOUND datatype")
2409 
2410             /* Initialize data which is relatively constant */
2411             if(H5T_conv_struct_init(src, dst, cdata, dxpl_id) < 0)
2412                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data")
2413             priv = (H5T_conv_struct_t *)(cdata->priv);
2414             src2dst = priv->src2dst;
2415 
2416             /*
2417              * If the destination type is not larger than the source type then
2418              * this conversion function is guaranteed to work (provided all
2419              * members can be converted also). Otherwise the determination is
2420              * quite a bit more complicated. Essentially we have to make sure
2421              * that there is always room in the source buffer to do the
2422              * conversion of a member in place. This is basically the same pair
2423              * of loops as in the actual conversion except it checks that there
2424              * is room for each conversion instead of actually doing anything.
2425              */
2426             if(dst->shared->size > src->shared->size) {
2427                 for(u = 0, offset = 0; u < src->shared->u.compnd.nmembs; u++) {
2428                     if(src2dst[u] < 0)
2429                         continue;
2430                     src_memb = src->shared->u.compnd.memb + u;
2431                     dst_memb = dst->shared->u.compnd.memb + src2dst[u];
2432                     if(dst_memb->size > src_memb->size)
2433                         offset += src_memb->size;
2434                 } /* end for */
2435                 H5_CHECK_OVERFLOW(src->shared->u.compnd.nmembs, size_t, int);
2436                 for(i = (int)src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
2437                     if(src2dst[i] < 0)
2438                         continue;
2439                     src_memb = src->shared->u.compnd.memb + i;
2440                     dst_memb = dst->shared->u.compnd.memb + src2dst[i];
2441                     if(dst_memb->size > src_memb->size) {
2442                         offset -= src_memb->size;
2443                         if(dst_memb->size > src->shared->size-offset) {
2444                             cdata->priv = H5T_conv_struct_free(priv);
2445                             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "convertion is unsupported by this function")
2446                         } /* end if */
2447                     } /* end if */
2448                 } /* end for */
2449             } /* end if */
2450             break;
2451 
2452         case H5T_CONV_FREE:
2453             /*
2454              * Free the private conversion data.
2455              */
2456             cdata->priv = H5T_conv_struct_free((H5T_conv_struct_t *)(cdata->priv));
2457             break;
2458 
2459         case H5T_CONV_CONV:
2460             /*
2461              * Conversion.
2462              */
2463             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2464                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
2465 
2466             /* Update cached data if necessary */
2467             if(cdata->recalc && H5T_conv_struct_init(src, dst, cdata, dxpl_id)<0)
2468                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize conversion data")
2469             priv = (H5T_conv_struct_t *)(cdata->priv);
2470             HDassert(priv);
2471             src2dst = priv->src2dst;
2472             HDassert(bkg && cdata->need_bkg);
2473 
2474             /*
2475              * Insure that members are sorted.
2476              */
2477             H5T__sort_value(src, NULL);
2478             H5T__sort_value(dst, NULL);
2479 
2480             /*
2481              * Calculate strides. If BUF_STRIDE is non-zero then convert one
2482              * data element at every BUF_STRIDE bytes through the main buffer
2483              * (BUF), leaving the result of each conversion at the same
2484              * location; otherwise assume the source and destination data are
2485              * packed tightly based on src->shared->size and dst->shared->size.  Also, if
2486              * BUF_STRIDE and BKG_STRIDE are both non-zero then place
2487              * background data into the BKG buffer at multiples of BKG_STRIDE;
2488              * otherwise assume BKG buffer is the packed destination datatype.
2489              */
2490             if(!buf_stride || !bkg_stride)
2491                 bkg_stride = dst->shared->size;
2492             if(!buf_stride) {
2493                 no_stride = TRUE;
2494                 buf_stride = src->shared->size;
2495             } /* end if */
2496 
2497             if(priv->subset_info.subset == H5T_SUBSET_SRC || priv->subset_info.subset == H5T_SUBSET_DST) {
2498                 /* If the optimization flag is set to indicate source members are a subset and
2499                  * in the top of the destination, simply copy the source members to background buffer.
2500                  */
2501                 xbuf = buf;
2502                 xbkg = bkg;
2503                 copy_size = priv->subset_info.copy_size;
2504 
2505                 for(elmtno = 0; elmtno < nelmts; elmtno++) {
2506                     HDmemmove(xbkg, xbuf, copy_size);
2507 
2508                     /* Update pointers */
2509                     xbuf += buf_stride;
2510                     xbkg += bkg_stride;
2511                 } /* end for */
2512             } /* end if */
2513             else {
2514                 /*
2515                  * For each member where the destination is not larger than the
2516                  * source, stride through all the elements converting only that member
2517                  * in each element and then copying the element to its final
2518                  * destination in the bkg buffer. Otherwise move the element as far
2519                  * left as possible in the buffer.
2520                  */
2521                 for(u = 0, offset = 0; u < src->shared->u.compnd.nmembs; u++) {
2522                     if(src2dst[u] < 0)
2523                         continue; /*subsetting*/
2524                     src_memb = src->shared->u.compnd.memb + u;
2525                     dst_memb = dst->shared->u.compnd.memb + src2dst[u];
2526 
2527                     if(dst_memb->size <= src_memb->size) {
2528                         xbuf = buf + src_memb->offset;
2529                         xbkg = bkg + dst_memb->offset;
2530                         if(H5T_convert(priv->memb_path[u], priv->src_memb_id[u],
2531                                 priv->dst_memb_id[src2dst[u]], nelmts,
2532                                 buf_stride, bkg_stride, xbuf, xbkg, dxpl_id) < 0)
2533                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound datatype member")
2534                         for(elmtno = 0; elmtno < nelmts; elmtno++) {
2535                             HDmemmove(xbkg, xbuf, dst_memb->size);
2536                             xbuf += buf_stride;
2537                             xbkg += bkg_stride;
2538                         } /* end for */
2539                     } /* end if */
2540                     else {
2541                         for(xbuf = buf, elmtno = 0; elmtno < nelmts; elmtno++) {
2542                             HDmemmove(xbuf + offset, xbuf + src_memb->offset, src_memb->size);
2543                             xbuf += buf_stride;
2544                         } /* end for */
2545                         offset += src_memb->size;
2546                     } /* end else */
2547                 } /* end else */
2548 
2549                 /*
2550                  * Work from right to left, converting those members that weren't
2551                  * converted in the previous loop (those members where the destination
2552                  * is larger than the source) and them to their final position in the
2553                  * bkg buffer.
2554                  */
2555                 H5_CHECK_OVERFLOW(src->shared->u.compnd.nmembs, size_t, int);
2556                 for(i = (int)src->shared->u.compnd.nmembs - 1; i >= 0; --i) {
2557                     if(src2dst[i] < 0)
2558                         continue;
2559                     src_memb = src->shared->u.compnd.memb + i;
2560                     dst_memb = dst->shared->u.compnd.memb + src2dst[i];
2561 
2562                     if(dst_memb->size > src_memb->size) {
2563                         offset -= src_memb->size;
2564                         xbuf = buf + offset;
2565                         xbkg = bkg + dst_memb->offset;
2566                         if(H5T_convert(priv->memb_path[i], priv->src_memb_id[i],
2567                                 priv->dst_memb_id[src2dst[i]], nelmts,
2568                                 buf_stride, bkg_stride, xbuf, xbkg, dxpl_id) < 0)
2569                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to convert compound datatype member")
2570                         for(elmtno = 0; elmtno < nelmts; elmtno++) {
2571                             HDmemmove(xbkg, xbuf, dst_memb->size);
2572                             xbuf += buf_stride;
2573                             xbkg += bkg_stride;
2574                         } /* end for */
2575                     } /* end if */
2576                 } /* end for */
2577             } /* end else */
2578 
2579             if(no_stride)
2580                 buf_stride = dst->shared->size;
2581 
2582             /* Move background buffer into result buffer */
2583             for(xbuf = buf, xbkg = bkg, elmtno = 0; elmtno < nelmts; elmtno++) {
2584                 HDmemmove(xbuf, xbkg, dst->shared->size);
2585                 xbuf += buf_stride;
2586                 xbkg += bkg_stride;
2587             } /* end for */
2588             break;
2589 
2590         default:
2591             /* Some other command we don't know about yet.*/
2592             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
2593     } /* end switch */
2594 
2595 done:
2596     FUNC_LEAVE_NOAPI(ret_value)
2597 } /* end H5T__conv_struct_opt() */
2598 
2599 
2600 /*-------------------------------------------------------------------------
2601  * Function:	H5T_conv_enum_init
2602  *
2603  * Purpose:	Initialize information for H5T__conv_enum().
2604  *
2605  * Return:	Success:	Non-negative
2606  *
2607  *		Failure:	Negative
2608  *
2609  * Programmer:	Robb Matzke
2610  *              Monday, January  4, 1999
2611  *
2612  * Modifications:
2613  *
2614  *-------------------------------------------------------------------------
2615  */
2616 static herr_t
H5T_conv_enum_init(H5T_t * src,H5T_t * dst,H5T_cdata_t * cdata)2617 H5T_conv_enum_init(H5T_t *src, H5T_t *dst, H5T_cdata_t *cdata)
2618 {
2619     H5T_enum_struct_t	*priv = NULL;	/*private conversion data	*/
2620     int		n;		/*src value cast as native int	*/
2621     int		domain[2] = {0, 0};	/*min and max source values	*/
2622     int		*map = NULL;	/*map from src value to dst idx	*/
2623     unsigned	length;		/*nelmts in map array		*/
2624     unsigned	i, j;		/*counters			*/
2625     herr_t      ret_value = SUCCEED;    /* Return value */
2626 
2627     FUNC_ENTER_NOAPI_NOINIT
2628 
2629     cdata->need_bkg = H5T_BKG_NO;
2630     if(NULL == (priv = (H5T_enum_struct_t *)(cdata->priv = H5MM_calloc(sizeof(*priv)))))
2631 	HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
2632     if(0 == src->shared->u.enumer.nmembs)
2633 	HGOTO_DONE(SUCCEED);
2634 
2635     /*
2636      * Check that the source symbol names are a subset of the destination
2637      * symbol names and build a map from source member index to destination
2638      * member index.
2639      */
2640     H5T__sort_name(src, NULL);
2641     H5T__sort_name(dst, NULL);
2642     if(NULL == (priv->src2dst = (int *)H5MM_malloc(src->shared->u.enumer.nmembs * sizeof(int))))
2643 	HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
2644     for(i = 0, j = 0;
2645              i < src->shared->u.enumer.nmembs && j < dst->shared->u.enumer.nmembs;
2646              i++, j++) {
2647 	while(j < dst->shared->u.enumer.nmembs &&
2648 	       HDstrcmp(src->shared->u.enumer.name[i], dst->shared->u.enumer.name[j]))
2649             j++;
2650 	if(j >= dst->shared->u.enumer.nmembs)
2651 	    HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "source type is not a subset of destination type")
2652 	priv->src2dst[i] = (int)j;
2653     } /* end for */
2654 
2655     /*
2656      * The conversion function will use an O(log N) lookup method for each
2657      * value converted. However, if all of the following constraints are met
2658      * then we can build a perfect hash table and use an O(1) lookup method.
2659      *
2660      *	  A: The source datatype size matches one of our native datatype
2661      *	     sizes.
2662      *
2663      *	  B: After casting the source value bit pattern to a native type
2664      *	     the size of the range of values is less than 20% larger than
2665      *	     the number of values.
2666      *
2667      * If this special case is met then we use the source bit pattern cast as
2668      * a native integer type as an index into the `val2dst'. The values of
2669      * that array are the index numbers in the destination type or negative
2670      * if the entry is unused.
2671      *
2672      * (This optimized algorithm doesn't work when the byte orders are different.
2673      * The code such as "n = *((int*)(src->shared->u.enumer.value+i*src->shared->size));"
2674      * can change the value significantly. i.g. if the source value is big-endian 0x0000000f,
2675      * executing the casting on little-endian machine will get a big number 0x0f000000.
2676      * Then it can't meet the condition
2677      * "if(src->shared->u.enumer.nmembs<2 || (double)length/src->shared->u.enumer.nmembs<1.2)"
2678      * Because this is the optimized code, we won't fix it. It should still work in some
2679      * situations. SLU - 2011/5/24)
2680      */
2681     if(1 == src->shared->size || sizeof(short) == src->shared->size || sizeof(int) == src->shared->size) {
2682 	for(i = 0; i < src->shared->u.enumer.nmembs; i++) {
2683 	    if(1 == src->shared->size)
2684 		n = *((signed char *)(src->shared->u.enumer.value + i));
2685 	    else if (sizeof(short) == src->shared->size)
2686 		n = *((short *)(src->shared->u.enumer.value + i * src->shared->size));
2687 	    else
2688 		n = *((int *)(src->shared->u.enumer.value + i * src->shared->size));
2689 	    if(0 == i) {
2690 		domain[0] = domain[1] = n;
2691 	    } else {
2692 		domain[0] = MIN(domain[0], n);
2693 		domain[1] = MAX(domain[1], n);
2694 	    }
2695 	} /* end for */
2696 
2697         HDassert(domain[1] >= domain[0]);
2698 	length = (unsigned)(domain[1] - domain[0]) + 1;
2699 	if(src->shared->u.enumer.nmembs < 2 ||
2700                 (double)length / src->shared->u.enumer.nmembs < (double)(1.2f)) {
2701 	    priv->base = domain[0];
2702 	    priv->length = length;
2703 	    if(NULL == (map = (int *)H5MM_malloc(length * sizeof(int))))
2704 		HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed")
2705 	    for(i = 0; i < length; i++)
2706                 map[i] = -1; /*entry unused*/
2707 	    for(i = 0; i < src->shared->u.enumer.nmembs; i++) {
2708 		if(1 == src->shared->size)
2709 		    n = *((signed char *)(src->shared->u.enumer.value + i));
2710 		else if(sizeof(short) == src->shared->size)
2711 		    n = *((short *)(src->shared->u.enumer.value + i * src->shared->size));
2712 		else
2713 		    n = *((int *)(src->shared->u.enumer.value + i * src->shared->size));
2714 		n -= priv->base;
2715 		HDassert(n >= 0 && (unsigned)n < priv->length);
2716 		HDassert(map[n] < 0);
2717 		map[n] = priv->src2dst[i];
2718 	    } /* end for */
2719 
2720 	    /*
2721 	     * Replace original src2dst array with our new one. The original
2722 	     * was indexed by source member number while the new one is
2723 	     * indexed by source values.
2724 	     */
2725 	    H5MM_xfree(priv->src2dst);
2726 	    priv->src2dst = map;
2727 	    HGOTO_DONE(SUCCEED);
2728 	}
2729     }
2730 
2731     /* Sort source type by value and adjust src2dst[] appropriately */
2732     H5T__sort_value(src, priv->src2dst);
2733 
2734 done:
2735     if (ret_value<0 && priv) {
2736 	H5MM_xfree(priv->src2dst);
2737 	H5MM_xfree(priv);
2738 	cdata->priv = NULL;
2739     }
2740     FUNC_LEAVE_NOAPI(ret_value)
2741 }
2742 
2743 
2744 /*-------------------------------------------------------------------------
2745  * Function:	H5T__conv_enum
2746  *
2747  * Purpose:	Converts one type of enumerated data to another.
2748  *
2749  * Return:	Success:	Non-negative
2750  *
2751  *		Failure:	negative
2752  *
2753  * Programmer:	Robb Matzke
2754  *              Monday, January  4, 1999
2755  *-------------------------------------------------------------------------
2756  */
2757 herr_t
H5T__conv_enum(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * _buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)2758 H5T__conv_enum(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
2759 	      size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *_buf,
2760               void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
2761 {
2762     uint8_t	*buf = (uint8_t*)_buf;	/*cast for pointer arithmetic	*/
2763     H5T_t	*src = NULL, *dst = NULL;	/*src and dst datatypes	*/
2764     uint8_t	*s = NULL, *d = NULL;	/*src and dst BUF pointers	*/
2765     ssize_t	src_delta, dst_delta;	/*conversion strides		*/
2766     int	n;			/*src value cast as native int	*/
2767     H5T_enum_struct_t *priv = (H5T_enum_struct_t*)(cdata->priv);
2768     H5P_genplist_t      *plist;         /*property list pointer         */
2769     H5T_conv_cb_t       cb_struct;      /*conversion callback structure */
2770     H5T_conv_ret_t      except_ret;     /*return of callback function   */
2771     size_t	i;			/*counters			*/
2772     herr_t      ret_value = SUCCEED;    /* Return value                 */
2773 
2774     FUNC_ENTER_PACKAGE
2775 
2776     switch(cdata->command) {
2777         case H5T_CONV_INIT:
2778             /*
2779              * Determine if this conversion function applies to the conversion
2780              * path SRC_ID->DST_ID.  If not return failure; otherwise initialize
2781              * the `priv' field of `cdata' with information about the underlying
2782              * integer conversion.
2783              */
2784             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2785                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype")
2786             if(H5T_ENUM != src->shared->type)
2787                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_ENUM datatype")
2788             if(H5T_ENUM != dst->shared->type)
2789                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_ENUM datatype")
2790 
2791             if(H5T_conv_enum_init(src, dst, cdata) < 0)
2792                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to initialize private data")
2793             break;
2794 
2795         case H5T_CONV_FREE:
2796 #ifdef H5T_DEBUG
2797             if (H5DEBUG(T)) {
2798                 fprintf(H5DEBUG(T), "      Using %s mapping function%s\n",
2799                         priv->length?"O(1)":"O(log N)",
2800                         priv->length?"":", where N is the number of enum members");
2801             }
2802 #endif
2803             if (priv) {
2804                 H5MM_xfree(priv->src2dst);
2805                 H5MM_xfree(priv);
2806             }
2807             cdata->priv = NULL;
2808             break;
2809 
2810         case H5T_CONV_CONV:
2811             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2812                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
2813             if(H5T_ENUM != src->shared->type)
2814                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_ENUM datatype")
2815             if(H5T_ENUM != dst->shared->type)
2816                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_ENUM datatype")
2817 
2818             /* priv->src2dst map was computed for certain sort keys. Make sure those same
2819              * sort keys are used here during conversion. See H5T_conv_enum_init(). But
2820              * we actually don't care about the source type's order when doing the O(1)
2821              * conversion algorithm, which is turned on by non-zero priv->length */
2822             H5T__sort_name(dst, NULL);
2823             if(!priv->length)
2824                 H5T__sort_value(src, NULL);
2825 
2826             /*
2827              * Direction of conversion.
2828              */
2829             if(buf_stride) {
2830                 H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
2831                 src_delta = dst_delta = (ssize_t)buf_stride;
2832                 s = d = buf;
2833             } else if(dst->shared->size <= src->shared->size) {
2834                 H5_CHECKED_ASSIGN(src_delta, ssize_t, src->shared->size, size_t);
2835                 H5_CHECKED_ASSIGN(dst_delta, ssize_t, dst->shared->size, size_t);
2836                 s = d = buf;
2837             } else {
2838                 H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
2839                 H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
2840                 src_delta = -(ssize_t)src->shared->size;
2841                 dst_delta = -(ssize_t)dst->shared->size;
2842                 s = buf + (nelmts - 1) * src->shared->size;
2843                 d = buf + (nelmts - 1) * dst->shared->size;
2844             }
2845 
2846             /* Get the plist structure */
2847             if(NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER)))
2848                 HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
2849 
2850             /* Get conversion exception callback property */
2851             if(H5P_get(plist, H5D_XFER_CONV_CB_NAME, &cb_struct) < 0)
2852                 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get conversion exception callback")
2853 
2854             for(i = 0; i < nelmts; i++, s += src_delta, d += dst_delta) {
2855                 if(priv->length) {
2856                     /* Use O(1) lookup */
2857                     /* (The casting won't work when the byte orders are different. i.g. if the source value
2858                      * is big-endian 0x0000000f, the direct casting "n = *((int*)s);" will make it a big
2859                      * number 0x0f000000 on little-endian machine. But we won't fix it because it's an
2860                      * optimization code. Please also see the comment in the H5T_conv_enum_init() function.
2861                      * SLU - 2011/5/24)
2862                      */
2863                     if(1 == src->shared->size)
2864                         n = *((signed char*)s);
2865                     else if(sizeof(short) == src->shared->size)
2866                         n = *((short*)s);
2867                     else
2868                         n = *((int*)s);
2869                     n -= priv->base;
2870                     if(n < 0 || (unsigned)n >= priv->length || priv->src2dst[n] < 0) {
2871                         /*overflow*/
2872                         except_ret = H5T_CONV_UNHANDLED;
2873                         /*If user's exception handler is present, use it*/
2874                         if(cb_struct.func)
2875                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
2876                                     s, d, cb_struct.user_data);
2877 
2878                         if(except_ret == H5T_CONV_UNHANDLED)
2879                             HDmemset(d, 0xff, dst->shared->size);
2880                         else if(except_ret == H5T_CONV_ABORT)
2881                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
2882                     } else
2883                         HDmemcpy(d,
2884                                  dst->shared->u.enumer.value + (unsigned)priv->src2dst[n] * dst->shared->size,
2885                                  dst->shared->size);
2886                 } /* end if */
2887                 else {
2888                     /* Use O(log N) lookup */
2889                     unsigned lt = 0;
2890                     unsigned rt = src->shared->u.enumer.nmembs;
2891                     unsigned md;
2892                     int cmp;
2893 
2894                     while(lt < rt) {
2895                         md = (lt + rt) / 2;
2896                         cmp = HDmemcmp(s, src->shared->u.enumer.value + md * src->shared->size,
2897                                        src->shared->size);
2898                         if(cmp < 0)
2899                             rt = md;
2900                         else if(cmp > 0)
2901                             lt = md + 1;
2902                         else
2903                             break;
2904                     } /* end while */
2905                     if(lt >= rt) {
2906                         except_ret = H5T_CONV_UNHANDLED;
2907                         /*If user's exception handler is present, use it*/
2908                         if(cb_struct.func)
2909                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
2910                                     src, d, cb_struct.user_data);
2911 
2912                         if(except_ret == H5T_CONV_UNHANDLED)
2913                             HDmemset(d, 0xff, dst->shared->size);
2914                         else if(except_ret == H5T_CONV_ABORT)
2915                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
2916                     } /* end if */
2917                     else {
2918                         HDassert(priv->src2dst[md] >= 0);
2919                         HDmemcpy(d,
2920                                  dst->shared->u.enumer.value + (unsigned)priv->src2dst[md] * dst->shared->size,
2921                                  dst->shared->size);
2922                     } /* end else */
2923                 } /* end else */
2924             }
2925 
2926             break;
2927 
2928         default:
2929             /* Some other command we don't know about yet.*/
2930             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
2931     } /* end switch */
2932 
2933 done:
2934     FUNC_LEAVE_NOAPI(ret_value)
2935 } /* end H5T__conv_enum() */
2936 
2937 
2938 /*-------------------------------------------------------------------------
2939  * Function:	H5T__conv_enum_numeric
2940  *
2941  * Purpose:	Converts enumerated data to a numeric type (integer or
2942  *              floating-point number). This function is registered into
2943  *              the conversion table twice in H5T_init_interface in H5T.c.
2944  *              Once for enum-integer conversion. Once for enum-float conversion.
2945  *
2946  * Return:	Success:	Non-negative
2947  *
2948  *		Failure:	negative
2949  *
2950  * Programmer:	Raymond Lu
2951  *              12 October 2012
2952  *-------------------------------------------------------------------------
2953  */
2954 herr_t
H5T__conv_enum_numeric(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t H5_ATTR_UNUSED buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * _buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)2955 H5T__conv_enum_numeric(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
2956 	      size_t H5_ATTR_UNUSED buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *_buf,
2957               void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
2958 {
2959     H5T_t	*src, *dst;		/*src and dst datatypes	*/
2960     H5T_t	*src_parent;		/*parent type for src           */
2961     hid_t       src_parent_id = -1;     /*ID for parent of the source   */
2962     H5T_path_t  *tpath;                 /* Conversion information       */
2963     herr_t      ret_value = SUCCEED;    /* Return value                 */
2964 
2965     FUNC_ENTER_PACKAGE
2966 
2967     switch(cdata->command) {
2968         case H5T_CONV_INIT:
2969             /*
2970              * Determine if this conversion function applies to the conversion
2971              * path SRC_ID->DST_ID.  If not, return failure.
2972              */
2973             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2974                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype")
2975             if(H5T_ENUM != src->shared->type)
2976                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "source type is not a H5T_ENUM datatype")
2977             if(H5T_INTEGER != dst->shared->type && H5T_FLOAT != dst->shared->type)
2978                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "destination is not an integer type")
2979 
2980             cdata->need_bkg = H5T_BKG_NO;
2981             break;
2982 
2983         case H5T_CONV_FREE:
2984             break;
2985 
2986         case H5T_CONV_CONV:
2987             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
2988                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
2989 
2990             src_parent = src->shared->parent;
2991 
2992             if(NULL == (tpath = H5T_path_find(src_parent, dst, NULL, NULL, dxpl_id, FALSE))) {
2993 	        HGOTO_ERROR(H5E_DATASET, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest datatype")
2994             } else if(!H5T_path_noop(tpath)) {
2995                 if((src_parent_id = H5I_register(H5I_DATATYPE, H5T_copy(src_parent, H5T_COPY_ALL), FALSE)) < 0)
2996                     HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion")
2997 
2998                 /* Convert the data */
2999                 if(H5T_convert(tpath, src_parent_id, dst_id, nelmts, buf_stride, bkg_stride, _buf, bkg, dxpl_id) < 0)
3000                     HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed")
3001             }
3002             break;
3003 
3004         default:
3005             /* Some other command we don't know about yet.*/
3006             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
3007     } /* end switch */
3008 
3009 done:
3010     /* Release the temporary datatype IDs used */
3011     if(src_parent_id >= 0)
3012         H5I_dec_ref(src_parent_id);
3013 
3014     FUNC_LEAVE_NOAPI(ret_value)
3015 } /* end H5T__conv_enum_numeric() */
3016 
3017 
3018 /*-------------------------------------------------------------------------
3019  * Function:	H5T__conv_vlen
3020  *
3021  * Purpose:	Converts between VL datatypes in memory and on disk.
3022  *		This is a soft conversion function.  The algorithm is
3023  *		basically:
3024  *
3025  *      	For every VL struct in the main buffer:
3026  *		  1. Allocate space for temporary dst VL data (reuse buffer
3027  *		     if possible)
3028  *                2. Copy VL data from src buffer into dst buffer
3029  *                3. Convert VL data into dst representation
3030  *                4. Allocate buffer in dst heap
3031  *		  5. Free heap objects storing old data
3032  *                6. Write dst VL data into dst heap
3033  *                7. Store (heap ID or pointer) and length in main dst buffer
3034  *
3035  * Return:	Non-negative on success/Negative on failure
3036  *
3037  * Programmer:	Quincey Koziol
3038  *		Wednesday, May 26, 1999
3039  *
3040  * Modifications:
3041  *
3042  *		Quincey Koziol, 2 July, 1999
3043  *		Enabled support for non-zero strides. If BUF_STRIDE is non-zero
3044  *		then convert one value at each memory location advancing
3045  *		BUF_STRIDE bytes each time; otherwise assume both source and
3046  *		destination values are packed.
3047  *
3048  *		Raymond Lu, 26 June, 2002
3049  *		Background buffer is used for freeing heap objects storing
3050  * 		old data.  At this moment, it only frees the first level of
3051  *		VL datatype.  It doesn't handle nested VL datatypes.
3052  *
3053  *              Raymond Lu, 8 November 2011
3054  *              I put a condition check to prevent the conversion of VL strings
3055  *              between ASCII and UTF8.
3056  *-------------------------------------------------------------------------
3057  */
3058 herr_t
H5T__conv_vlen(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t bkg_stride,void * buf,void * bkg,hid_t dxpl_id)3059 H5T__conv_vlen(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
3060     size_t buf_stride, size_t bkg_stride, void *buf, void *bkg, hid_t dxpl_id)
3061 {
3062     H5T_vlen_alloc_info_t _vl_alloc_info;       /* VL allocation info buffer */
3063     H5T_vlen_alloc_info_t *vl_alloc_info = &_vl_alloc_info;   /* VL allocation info */
3064     H5T_path_t	*tpath = NULL;		/* Type conversion path		     */
3065     hbool_t     noop_conv = FALSE;      /* Flag to indicate a noop conversion */
3066     hbool_t     write_to_file = FALSE;  /* Flag to indicate writing to file */
3067     htri_t      parent_is_vlen;         /* Flag to indicate parent is vlen datatyp */
3068     hid_t   	tsrc_id = -1, tdst_id = -1;/*temporary type atoms	     */
3069     H5T_t	*src = NULL;		/*source datatype		     */
3070     H5T_t	*dst = NULL;		/*destination datatype		     */
3071     H5HG_t	bg_hobjid, parent_hobjid;
3072     uint8_t	*s = NULL;		/*source buffer			*/
3073     uint8_t	*d = NULL;		/*destination buffer		*/
3074     uint8_t	*b = NULL;		/*background buffer		*/
3075     ssize_t	s_stride, d_stride;	/*src and dst strides		*/
3076     ssize_t	b_stride;	        /*bkg stride			*/
3077     size_t      safe;                   /*how many elements are safe to process in each pass */
3078     size_t	bg_seq_len = 0;
3079     size_t	src_base_size, dst_base_size;/*source & destination base size*/
3080     void	*conv_buf = NULL;     	/*temporary conversion buffer 	     */
3081     size_t	conv_buf_size = 0;  	/*size of conversion buffer in bytes */
3082     void	*tmp_buf = NULL;     	/*temporary background buffer 	     */
3083     size_t	tmp_buf_size = 0;	/*size of temporary bkg buffer	     */
3084     hbool_t     nested = FALSE;         /*flag of nested VL case             */
3085     size_t	elmtno;			/*element number counter	     */
3086     herr_t      ret_value = SUCCEED;    /* Return value */
3087 
3088     FUNC_ENTER_PACKAGE
3089 
3090     switch(cdata->command) {
3091         case H5T_CONV_INIT:
3092             /*
3093              * First, determine if this conversion function applies to the
3094              * conversion path SRC_ID-->DST_ID.  If not, return failure;
3095              * otherwise initialize the `priv' field of `cdata' with
3096              * information that remains (almost) constant for this
3097              * conversion path.
3098              */
3099             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
3100                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a datatype")
3101             if(H5T_VLEN != src->shared->type)
3102                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_VLEN datatype")
3103             if(H5T_VLEN != dst->shared->type)
3104                 HGOTO_ERROR(H5E_DATATYPE, H5E_BADTYPE, FAIL, "not a H5T_VLEN datatype")
3105             if(H5T_VLEN_STRING == src->shared->u.vlen.type && H5T_VLEN_STRING == dst->shared->u.vlen.type) {
3106                 if((H5T_CSET_ASCII == src->shared->u.vlen.cset && H5T_CSET_UTF8 == dst->shared->u.vlen.cset)
3107                     || (H5T_CSET_ASCII == dst->shared->u.vlen.cset && H5T_CSET_UTF8 == src->shared->u.vlen.cset))
3108                     HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "The library doesn't convert between strings of ASCII and UTF")
3109             }
3110 
3111             /* Variable-length types don't need a background buffer */
3112             cdata->need_bkg = H5T_BKG_NO;
3113 
3114             break;
3115 
3116         case H5T_CONV_FREE:
3117             /* QAK - Nothing to do currently */
3118             break;
3119 
3120         case H5T_CONV_CONV:
3121             /*
3122              * Conversion.
3123              */
3124             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
3125                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
3126 
3127             /* Initialize source & destination strides */
3128             if(buf_stride) {
3129                 HDassert(buf_stride >= src->shared->size);
3130                 HDassert(buf_stride >= dst->shared->size);
3131                 H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
3132                 s_stride = d_stride = (ssize_t)buf_stride;
3133             } /* end if */
3134             else {
3135                 H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
3136                 H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
3137                 s_stride = (ssize_t)src->shared->size;
3138                 d_stride = (ssize_t)dst->shared->size;
3139             } /* end else */
3140             if(bkg) {
3141                 if(bkg_stride)
3142                     b_stride = (ssize_t)bkg_stride;
3143                 else
3144                     b_stride = d_stride;
3145             } /* end if */
3146             else
3147                 b_stride = 0;
3148 
3149             /* Get the size of the base types in src & dst */
3150             src_base_size = H5T_get_size(src->shared->parent);
3151             dst_base_size = H5T_get_size(dst->shared->parent);
3152 
3153             /* Set up conversion path for base elements */
3154             if(NULL == (tpath = H5T_path_find(src->shared->parent, dst->shared->parent, NULL, NULL, dxpl_id, FALSE)))
3155                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest datatypes")
3156             else if(!H5T_path_noop(tpath)) {
3157                 if((tsrc_id = H5I_register(H5I_DATATYPE, H5T_copy(src->shared->parent, H5T_COPY_ALL), FALSE)) < 0 ||
3158                         (tdst_id = H5I_register(H5I_DATATYPE, H5T_copy(dst->shared->parent, H5T_COPY_ALL), FALSE)) < 0)
3159                     HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion")
3160             } /* end else-if */
3161             else
3162                 noop_conv = TRUE;
3163 
3164             /* Check if we need a temporary buffer for this conversion */
3165             if((parent_is_vlen = H5T_detect_class(dst->shared->parent, H5T_VLEN, FALSE)) < 0)
3166                 HGOTO_ERROR(H5E_DATATYPE, H5E_SYSTEM, FAIL, "internal error when detecting variable-length class")
3167             if(tpath->cdata.need_bkg || parent_is_vlen) {
3168                 /* Set up initial background buffer */
3169                 tmp_buf_size = MAX(src_base_size, dst_base_size);
3170                 if(NULL == (tmp_buf = H5FL_BLK_CALLOC(vlen_seq,tmp_buf_size)))
3171                     HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "memory allocation failed for type conversion")
3172             } /* end if */
3173 
3174             /* Get the allocation info */
3175             if(H5T_vlen_get_alloc_info(dxpl_id, &vl_alloc_info) < 0)
3176                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info")
3177 
3178             /* Set flags to indicate we are writing to or reading from the file */
3179             if(dst->shared->u.vlen.f != NULL)
3180                 write_to_file = TRUE;
3181 
3182             /* Set the flag for nested VL case */
3183             if(write_to_file && parent_is_vlen && bkg != NULL)
3184                 nested = TRUE;
3185 
3186             /* The outer loop of the type conversion macro, controlling which */
3187             /* direction the buffer is walked */
3188             while(nelmts > 0) {
3189                 /* Check if we need to go backwards through the buffer */
3190                 if(d_stride > s_stride) {
3191                     /* Sanity check */
3192                     HDassert(s_stride > 0);
3193                     HDassert(d_stride > 0);
3194                     HDassert(b_stride >= 0);
3195 
3196                     /* Compute the number of "safe" destination elements at */
3197                     /* the end of the buffer (Those which don't overlap with */
3198                     /* any source elements at the beginning of the buffer) */
3199                     safe = nelmts - (((nelmts * (size_t)s_stride) + ((size_t)d_stride - 1)) / (size_t)d_stride);
3200 
3201                     /* If we're down to the last few elements, just wrap up */
3202                     /* with a "real" reverse copy */
3203                     if(safe < 2) {
3204                         s = (uint8_t *)buf + (nelmts - 1) * (size_t)s_stride;
3205                         d = (uint8_t *)buf + (nelmts - 1) * (size_t)d_stride;
3206                         b = (uint8_t *)bkg + (nelmts - 1) * (size_t)b_stride;
3207                         s_stride = -s_stride;
3208                         d_stride = -d_stride;
3209                         b_stride = -b_stride;
3210 
3211                         safe = nelmts;
3212                     } /* end if */
3213                     else {
3214                         s = (uint8_t *)buf + (nelmts - safe) * (size_t)s_stride;
3215                         d = (uint8_t *)buf + (nelmts - safe) * (size_t)d_stride;
3216                         b = (uint8_t *)bkg + (nelmts - safe) * (size_t)b_stride;
3217                     } /* end else */
3218                 } /* end if */
3219                 else {
3220                     /* Single forward pass over all data */
3221                     s = d = (uint8_t *)buf;
3222                     b = (uint8_t *)bkg;
3223                     safe = nelmts;
3224                 } /* end else */
3225 
3226                 for(elmtno = 0; elmtno < safe; elmtno++) {
3227                     /* Check for "nil" source sequence */
3228                     if((*(src->shared->u.vlen.isnull))(src->shared->u.vlen.f, s)) {
3229                         /* Write "nil" sequence to destination location */
3230                         if((*(dst->shared->u.vlen.setnull))(dst->shared->u.vlen.f, dxpl_id, d, b) < 0)
3231                             HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't set VL data to 'nil'")
3232                     } /* end if */
3233                     else {
3234                         ssize_t sseq_len;   /* (signed) The number of elements in the current sequence*/
3235                         size_t 	seq_len;    /* The number of elements in the current sequence*/
3236 
3237                         /* Get length of element sequences */
3238                         if((sseq_len = (*(src->shared->u.vlen.getlen))(s)) < 0)
3239                             HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "incorrect length")
3240                         seq_len = (size_t)sseq_len;
3241 
3242                         /* If we are reading from memory and there is no conversion, just get the pointer to sequence */
3243                         if(write_to_file && noop_conv) {
3244                             /* Get direct pointer to sequence */
3245                             if(NULL == (conv_buf = (*(src->shared->u.vlen.getptr))(s)))
3246                                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid source pointer")
3247                         } /* end if */
3248                         else {
3249                             size_t	src_size, dst_size;     /*source & destination total size in bytes*/
3250 
3251                             src_size = seq_len * src_base_size;
3252                             dst_size = seq_len * dst_base_size;
3253 
3254                             /* Check if conversion buffer is large enough, resize if
3255                              * necessary.  If the SEQ_LEN is 0, allocate a minimal size buffer.
3256                              */
3257 			    if(!seq_len && !conv_buf) {
3258                                 conv_buf_size = ((1 / H5T_VLEN_MIN_CONF_BUF_SIZE) + 1) * H5T_VLEN_MIN_CONF_BUF_SIZE;
3259                                 if(NULL == (conv_buf = H5FL_BLK_CALLOC(vlen_seq, conv_buf_size)))
3260                                     HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
3261 			    }
3262                             else if(conv_buf_size < MAX(src_size, dst_size)) {
3263                                 /* Only allocate conversion buffer in H5T_VLEN_MIN_CONF_BUF_SIZE increments */
3264                                 conv_buf_size = ((MAX(src_size, dst_size) / H5T_VLEN_MIN_CONF_BUF_SIZE) + 1) * H5T_VLEN_MIN_CONF_BUF_SIZE;
3265                                 if(NULL == (conv_buf = H5FL_BLK_REALLOC(vlen_seq, conv_buf, conv_buf_size)))
3266                                     HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
3267                                 HDmemset(conv_buf, 0, conv_buf_size);
3268                             } /* end if */
3269 
3270                             /* Read in VL sequence */
3271                             if((*(src->shared->u.vlen.read))(src->shared->u.vlen.f, dxpl_id, s, conv_buf, src_size) < 0)
3272                                 HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL data")
3273                         } /* end else */
3274 
3275                         if(!noop_conv) {
3276                             /* Check if temporary buffer is large enough, resize if necessary */
3277                             /* (Chain off the conversion buffer size) */
3278                             if(tmp_buf && tmp_buf_size < conv_buf_size) {
3279                                 /* Set up initial background buffer */
3280                                 tmp_buf_size = conv_buf_size;
3281                                 if(NULL == (tmp_buf = H5FL_BLK_REALLOC(vlen_seq, tmp_buf, tmp_buf_size)))
3282                                     HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
3283                                 HDmemset(tmp_buf, 0, tmp_buf_size);
3284                             } /* end if */
3285 
3286                             /* If we are writing and there is a nested VL type, read
3287                              * the sequence into the background buffer */
3288                             if(nested) {
3289                                 const uint8_t *tmp = b;
3290 
3291                                 UINT32DECODE(tmp, bg_seq_len);
3292                                 if(bg_seq_len > 0) {
3293                                     if(tmp_buf_size < (bg_seq_len * MAX(src_base_size, dst_base_size))) {
3294                                         tmp_buf_size = (bg_seq_len * MAX(src_base_size, dst_base_size));
3295                                         if(NULL == (tmp_buf = H5FL_BLK_REALLOC(vlen_seq, tmp_buf, tmp_buf_size)))
3296                                             HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
3297                                         HDmemset(tmp_buf, 0, tmp_buf_size);
3298                                     } /* end if */
3299                                     H5F_addr_decode(dst->shared->u.vlen.f, &tmp, &(bg_hobjid.addr));
3300                                     UINT32DECODE(tmp, bg_hobjid.idx);
3301                                     if(NULL == H5HG_read(dst->shared->u.vlen.f, dxpl_id, &bg_hobjid, tmp_buf, NULL))
3302                                         HGOTO_ERROR(H5E_DATATYPE, H5E_READERROR, FAIL, "can't read VL sequence into background buffer")
3303                                 } /* end if */
3304 
3305                                 /* If the sequence gets shorter, pad out the original sequence with zeros */
3306                                 if(bg_seq_len < seq_len)
3307                                     HDmemset((uint8_t *)tmp_buf + dst_base_size * bg_seq_len, 0, (seq_len - bg_seq_len) * dst_base_size);
3308                             } /* end if */
3309 
3310                             /* Convert VL sequence */
3311                             if(H5T_convert(tpath, tsrc_id, tdst_id, seq_len, (size_t)0, (size_t)0, conv_buf, tmp_buf, dxpl_id) < 0)
3312                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed")
3313                         } /* end if */
3314 
3315                         /* Write sequence to destination location */
3316                         if((*(dst->shared->u.vlen.write))(dst->shared->u.vlen.f, dxpl_id, vl_alloc_info, d, conv_buf, b, seq_len, dst_base_size) < 0)
3317                             HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "can't write VL data")
3318 
3319                         if(!noop_conv) {
3320                             /* For nested VL case, free leftover heap objects from the deeper level if the length of new data elements is shorter than the old data elements.*/
3321                             if(nested && seq_len < bg_seq_len) {
3322                                 size_t parent_seq_len;
3323                                 const uint8_t *tmp;
3324                                 size_t u;
3325 
3326                                 /* TMP_P is reset each time in the loop because DST_BASE_SIZE may include some data in addition to VL info. - SLU */
3327                                 for(u = seq_len; u < bg_seq_len; u++) {
3328                                     tmp = (uint8_t *)tmp_buf + u * dst_base_size;
3329                                     UINT32DECODE(tmp, parent_seq_len);
3330                                     if(parent_seq_len > 0) {
3331                                         H5F_addr_decode(dst->shared->u.vlen.f, &tmp, &(parent_hobjid.addr));
3332                                         UINT32DECODE(tmp, parent_hobjid.idx);
3333                                         if(H5HG_remove(dst->shared->u.vlen.f, dxpl_id, &parent_hobjid) < 0)
3334                                             HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object")
3335                                     } /* end if */
3336                                 } /* end for */
3337                             } /* end if */
3338                         } /* end if */
3339                     } /* end else */
3340 
3341                     /* Advance pointers */
3342                     s += s_stride;
3343                     d += d_stride;
3344                     b += b_stride;
3345                 } /* end for */
3346 
3347                 /* Decrement number of elements left to convert */
3348                 nelmts -= safe;
3349             } /* end while */
3350 
3351             /* Release the temporary datatype IDs used */
3352             if(tsrc_id >= 0)
3353                 H5I_dec_ref(tsrc_id);
3354             if(tdst_id >= 0)
3355                 H5I_dec_ref(tdst_id);
3356             break;
3357 
3358         default:    /* Some other command we don't know about yet.*/
3359             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
3360     }   /* end switch */
3361 
3362 done:
3363     /* If the conversion buffer doesn't need to be freed, reset its pointer */
3364     if(write_to_file && noop_conv)
3365         conv_buf = NULL;
3366     /* Release the conversion buffer (always allocated, except on errors) */
3367     if(conv_buf)
3368         conv_buf = H5FL_BLK_FREE(vlen_seq, conv_buf);
3369     /* Release the background buffer, if we have one */
3370     if(tmp_buf)
3371         tmp_buf = H5FL_BLK_FREE(vlen_seq, tmp_buf);
3372 
3373     FUNC_LEAVE_NOAPI(ret_value)
3374 } /* end H5T__conv_vlen() */
3375 
3376 
3377 /*-------------------------------------------------------------------------
3378  * Function:	H5T__conv_array
3379  *
3380  * Purpose:	Converts between array datatypes in memory and on disk.
3381  *		This is a soft conversion function.
3382  *
3383  * Return:	Non-negative on success/Negative on failure
3384  *
3385  * Programmer:	Quincey Koziol
3386  *		Monday, November 6, 2000
3387  *
3388  * Modifications:
3389  *
3390  *-------------------------------------------------------------------------
3391  */
3392 herr_t
H5T__conv_array(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t bkg_stride,void * _buf,void H5_ATTR_UNUSED * _bkg,hid_t dxpl_id)3393 H5T__conv_array(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
3394 	      size_t buf_stride, size_t bkg_stride, void *_buf,
3395               void H5_ATTR_UNUSED *_bkg, hid_t dxpl_id)
3396 {
3397     H5T_path_t	*tpath;		        /* Type conversion path		     */
3398     hid_t       tsrc_id = -1, tdst_id = -1;/*temporary type atoms	     */
3399     H5T_t	*src = NULL;	        /*source datatype		     */
3400     H5T_t	*dst = NULL;	        /*destination datatype		     */
3401     uint8_t	*sp, *dp;	        /*source and dest traversal ptrs     */
3402     ssize_t	src_delta, dst_delta;	/*source & destination stride	     */
3403     int	        direction;		/*direction of traversal	     */
3404     size_t	elmtno;			/*element number counter	     */
3405     unsigned    u;                      /* local index variable */
3406     void	*bkg_buf = NULL;     	/*temporary background buffer 	     */
3407     herr_t      ret_value=SUCCEED;       /* Return value */
3408 
3409     FUNC_ENTER_PACKAGE
3410 
3411     switch (cdata->command) {
3412         case H5T_CONV_INIT:
3413             /*
3414              * First, determine if this conversion function applies to the
3415              * conversion path SRC_ID-->DST_ID.  If not, return failure;
3416              * otherwise initialize the `priv' field of `cdata' with
3417              * information that remains (almost) constant for this
3418              * conversion path.
3419              */
3420             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
3421                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
3422             HDassert(H5T_ARRAY==src->shared->type);
3423             HDassert(H5T_ARRAY==dst->shared->type);
3424 
3425             /* Check the number and sizes of the dimensions */
3426             if(src->shared->u.array.ndims != dst->shared->u.array.ndims)
3427                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "array datatypes do not have the same number of dimensions")
3428             for(u = 0; u < src->shared->u.array.ndims; u++)
3429                 if(src->shared->u.array.dim[u] != dst->shared->u.array.dim[u])
3430                     HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "array datatypes do not have the same sizes of dimensions")
3431 
3432             /* Array datatypes don't need a background buffer */
3433             cdata->need_bkg = H5T_BKG_NO;
3434 
3435             break;
3436 
3437         case H5T_CONV_FREE:
3438             /* QAK - Nothing to do currently */
3439             break;
3440 
3441         case H5T_CONV_CONV:
3442             /*
3443              * Conversion.
3444              */
3445             if (NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
3446                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
3447 
3448             /*
3449              * Do we process the values from beginning to end or vice
3450              * versa? Also, how many of the elements have the source and
3451              * destination areas overlapping?
3452              */
3453             if(src->shared->size >= dst->shared->size || buf_stride > 0) {
3454                 sp = dp = (uint8_t*)_buf;
3455                 direction = 1;
3456             } else {
3457                 sp = (uint8_t*)_buf + (nelmts - 1) *
3458                      (buf_stride ? buf_stride : src->shared->size);
3459                 dp = (uint8_t*)_buf + (nelmts - 1) *
3460                      (buf_stride ? buf_stride : dst->shared->size);
3461                 direction = -1;
3462             }
3463 
3464             /*
3465              * Direction & size of buffer traversal.
3466              */
3467             H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
3468             H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
3469             H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
3470             src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src->shared->size);
3471             dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst->shared->size);
3472 
3473             /* Set up conversion path for base elements */
3474             if(NULL == (tpath = H5T_path_find(src->shared->parent, dst->shared->parent, NULL, NULL, dxpl_id, FALSE))) {
3475                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unable to convert between src and dest datatypes")
3476             } else if (!H5T_path_noop(tpath)) {
3477                 if((tsrc_id = H5I_register(H5I_DATATYPE, H5T_copy(src->shared->parent, H5T_COPY_ALL), FALSE)) < 0 ||
3478                         (tdst_id = H5I_register(H5I_DATATYPE, H5T_copy(dst->shared->parent, H5T_COPY_ALL), FALSE)) < 0)
3479                     HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register types for conversion")
3480             }
3481 
3482             /* Check if we need a background buffer for this conversion */
3483             if(tpath->cdata.need_bkg) {
3484                 size_t	bkg_buf_size;	        /*size of background buffer in bytes */
3485 
3486                 /* Allocate background buffer */
3487                 bkg_buf_size = src->shared->u.array.nelem * MAX(src->shared->size, dst->shared->size);
3488                 if(NULL == (bkg_buf = H5FL_BLK_CALLOC(array_seq, bkg_buf_size)))
3489                     HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for type conversion")
3490             } /* end if */
3491 
3492             /* Perform the actual conversion */
3493             for(elmtno = 0; elmtno < nelmts; elmtno++) {
3494                 /* Copy the source array into the correct location for the destination */
3495                 HDmemmove(dp, sp, src->shared->size);
3496 
3497                 /* Convert array */
3498                 if(H5T_convert(tpath, tsrc_id, tdst_id, src->shared->u.array.nelem, (size_t)0, bkg_stride, dp, bkg_buf, dxpl_id) < 0)
3499                     HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "datatype conversion failed")
3500 
3501                 /* Advance the source & destination pointers */
3502                 sp += src_delta;
3503                 dp += dst_delta;
3504             } /* end for */
3505 
3506             /* Release the temporary datatype IDs used */
3507             if(tsrc_id >= 0)
3508                 H5I_dec_ref(tsrc_id);
3509             if(tdst_id >= 0)
3510                 H5I_dec_ref(tdst_id);
3511             break;
3512 
3513         default:    /* Some other command we don't know about yet.*/
3514             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
3515     } /* end switch */
3516 
3517 done:
3518     /* Release the background buffer, if we have one */
3519     if(bkg_buf)
3520         bkg_buf = H5FL_BLK_FREE(array_seq, bkg_buf);
3521 
3522     FUNC_LEAVE_NOAPI(ret_value)
3523 } /* end H5T__conv_array() */
3524 
3525 
3526 /*-------------------------------------------------------------------------
3527  * Function:	H5T__conv_i_i
3528  *
3529  * Purpose:	Convert one integer type to another.  This is the catch-all
3530  *		function for integer conversions and is probably not
3531  *		particularly fast.
3532  *
3533  * Return:	Non-negative on success/Negative on failure
3534  *
3535  * Programmer:	Robb Matzke
3536  *		Wednesday, June 10, 1998
3537  *
3538  * Modifications:
3539  *		Robb Matzke, 7 Jul 1998
3540  *		Added overflow handling.
3541  *
3542  *		Robb Matzke, 1999-06-16
3543  *		Added support for non-zero strides. If BUF_STRIDE is non-zero
3544  *		then convert one value at each memory location advancing
3545  *		BUF_STRIDE bytes each time; otherwise assume both source and
3546  *		destination values are packed.
3547  *
3548  *              Raymond Lu
3549  *              Wednesday, April 21, 2004
3550  *              There is a new design for exception handling like overflow,
3551  *              which is passed in as a transfer property.
3552  *-------------------------------------------------------------------------
3553  */
3554 herr_t
H5T__conv_i_i(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t dxpl_id)3555 H5T__conv_i_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
3556     size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
3557     hid_t dxpl_id)
3558 {
3559     H5T_t	*src = NULL;		/*source datatype		*/
3560     H5T_t	*dst = NULL;		/*destination datatype		*/
3561     ssize_t	src_delta, dst_delta;	/*source & destination stride	*/
3562     int		direction;		/*direction of traversal	*/
3563     size_t	elmtno;			/*element number		*/
3564     size_t	half_size;		/*half the type size		*/
3565     size_t	olap;			/*num overlapping elements	*/
3566     uint8_t	*s, *sp, *d, *dp;	/*source and dest traversal ptrs*/
3567     uint8_t     *src_rev=NULL;          /*order-reversed source buffer  */
3568     uint8_t	dbuf[64];		/*temp destination buffer	*/
3569     size_t	first;
3570     ssize_t	sfirst;			/*a signed version of `first'	*/
3571     size_t	i;                      /*Local index variables         */
3572     H5P_genplist_t      *plist;         /*property list pointer         */
3573     H5T_conv_cb_t       cb_struct={NULL, NULL};      /*conversion callback structure */
3574     H5T_conv_ret_t      except_ret;     /*return of callback function   */
3575     hbool_t             reverse;        /*if reverse the order of destination        */
3576     herr_t      ret_value=SUCCEED;       /* Return value */
3577 
3578     FUNC_ENTER_PACKAGE
3579 
3580     switch(cdata->command) {
3581         case H5T_CONV_INIT:
3582             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
3583                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
3584             if(H5T_ORDER_LE != src->shared->u.atomic.order && H5T_ORDER_BE != src->shared->u.atomic.order)
3585                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
3586             if(H5T_ORDER_LE != dst->shared->u.atomic.order && H5T_ORDER_BE != dst->shared->u.atomic.order)
3587                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
3588             if(dst->shared->size > sizeof dbuf)
3589                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination size is too large")
3590             cdata->need_bkg = H5T_BKG_NO;
3591             break;
3592 
3593         case H5T_CONV_FREE:
3594             break;
3595 
3596         case H5T_CONV_CONV:
3597             /* Get the datatypes */
3598             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
3599                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
3600 
3601             /*
3602              * Do we process the values from beginning to end or vice versa? Also,
3603              * how many of the elements have the source and destination areas
3604              * overlapping?
3605              */
3606             if (src->shared->size==dst->shared->size || buf_stride) {
3607                 sp = dp = (uint8_t*)buf;
3608                 direction = 1;
3609                 olap = nelmts;
3610             } else if (src->shared->size>=dst->shared->size) {
3611                 double olap_d = HDceil((double)(dst->shared->size)/
3612                                        (double)(src->shared->size-dst->shared->size));
3613 
3614                 olap = (size_t)olap_d;
3615                 sp = dp = (uint8_t*)buf;
3616                 direction = 1;
3617             } else {
3618                 double olap_d = HDceil((double)(src->shared->size)/
3619                                        (double)(dst->shared->size-src->shared->size));
3620                 olap = (size_t)olap_d;
3621                 sp = (uint8_t*)buf + (nelmts - 1) * src->shared->size;
3622                 dp = (uint8_t*)buf + (nelmts - 1) * dst->shared->size;
3623                 direction = -1;
3624             }
3625 
3626             /*
3627              * Direction & size of buffer traversal.
3628              */
3629             H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
3630             H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
3631             H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
3632             src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src->shared->size);
3633             dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst->shared->size);
3634 
3635             /* Get the plist structure */
3636             if(NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER)))
3637                 HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
3638 
3639             /* Get conversion exception callback property */
3640             if(H5P_get(plist,H5D_XFER_CONV_CB_NAME, &cb_struct) < 0)
3641                 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get conversion exception callback")
3642 
3643             /* Allocate space for order-reversed source buffer */
3644             src_rev = (uint8_t*)H5MM_calloc(src->shared->size);
3645 
3646             /* The conversion loop */
3647             for(elmtno = 0; elmtno < nelmts; elmtno++) {
3648 
3649                 /*
3650                  * If the source and destination buffers overlap then use a
3651                  * temporary buffer for the destination.
3652                  */
3653                 if(direction > 0) {
3654                     s = sp;
3655                     d = elmtno < olap ? dbuf : dp;
3656                 } else {
3657                     s = sp;
3658                     d = elmtno + olap >= nelmts ? dbuf : dp;
3659                 }
3660 #ifndef NDEBUG
3661                 /* I don't quite trust the overlap calculations yet --rpm */
3662                 if (d==dbuf) {
3663                     HDassert((dp>=sp && dp<sp+src->shared->size) || (sp>=dp && sp<dp+dst->shared->size));
3664                 } else {
3665                     HDassert((dp<sp && dp+dst->shared->size<=sp) || (sp<dp && sp+src->shared->size<=dp));
3666                 }
3667 #endif
3668 
3669                 /*
3670                  * Put the data in little endian order so our loops aren't so
3671                  * complicated.  We'll do all the conversion stuff assuming
3672                  * little endian and then we'll fix the order at the end.
3673                  */
3674                 if (H5T_ORDER_BE==src->shared->u.atomic.order) {
3675                     half_size = src->shared->size/2;
3676                     for (i=0; i<half_size; i++) {
3677                         uint8_t tmp = s[src->shared->size-(i+1)];
3678                         s[src->shared->size-(i+1)] = s[i];
3679                         s[i] = tmp;
3680                     }
3681                 }
3682 
3683                 /*
3684                  * What is the bit number for the msb bit of S which is set? The
3685                  * bit number is relative to the significant part of the number.
3686                  */
3687                 sfirst = H5T__bit_find (s, src->shared->u.atomic.offset, src->shared->u.atomic.prec,
3688                                        H5T_BIT_MSB, TRUE);
3689                 first = (size_t)sfirst;
3690 
3691                 /* Set these variables to default */
3692                 except_ret = H5T_CONV_UNHANDLED;
3693                 reverse    = TRUE;
3694 
3695                 if (sfirst<0) {
3696                     /*
3697                      * The source has no bits set and must therefore be zero.
3698                      * Set the destination to zero.
3699                      */
3700                     H5T__bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, FALSE);
3701 
3702                 } else if (H5T_SGN_NONE==src->shared->u.atomic.u.i.sign &&
3703                            H5T_SGN_NONE==dst->shared->u.atomic.u.i.sign) {
3704                     /*
3705                      * Source and destination are both unsigned, but if the
3706                      * source has more precision bits than the destination then
3707                      * it's possible to overflow.  When overflow occurs the
3708                      * destination will be set to the maximum possible value.
3709                      */
3710                     if (src->shared->u.atomic.prec <= dst->shared->u.atomic.prec) {
3711                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3712                               src->shared->u.atomic.prec);
3713                         H5T__bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
3714                              dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
3715                     } else if (first>=dst->shared->u.atomic.prec) {
3716                         /*overflow*/
3717                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
3718                             H5T_reverse_order(src_rev, s, src->shared->size, src->shared->u.atomic.order); /*reverse order first*/
3719                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
3720                                     src_rev, d, cb_struct.user_data);
3721                         }
3722 
3723                         if(except_ret == H5T_CONV_UNHANDLED) {
3724                             H5T__bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, TRUE);
3725                         } else if(except_ret == H5T_CONV_ABORT)
3726                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
3727                         else if(except_ret == H5T_CONV_HANDLED)
3728                             /*Don't reverse because user handles it already*/
3729                             reverse = FALSE;
3730                     } else {
3731                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3732                               dst->shared->u.atomic.prec);
3733                     }
3734 
3735                 } else if (H5T_SGN_2==src->shared->u.atomic.u.i.sign &&
3736                            H5T_SGN_NONE==dst->shared->u.atomic.u.i.sign) {
3737                     /*
3738                      * If the source is signed and the destination isn't then we
3739                      * can have overflow if the source contains more bits than
3740                      * the destination (destination is set to the maximum
3741                      * possible value) or overflow if the source is negative
3742                      * (destination is set to zero).
3743                      */
3744                     if (first+1 == src->shared->u.atomic.prec) {
3745                         /*overflow - source is negative*/
3746                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
3747                             H5T_reverse_order(src_rev, s, src->shared->size, src->shared->u.atomic.order); /*reverse order first*/
3748                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW, src_id, dst_id,
3749                                     src_rev, d, cb_struct.user_data);
3750                         }
3751 
3752                         if(except_ret == H5T_CONV_UNHANDLED) {
3753                             H5T__bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, FALSE);
3754                         } else if(except_ret == H5T_CONV_ABORT)
3755                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
3756                         else if(except_ret == H5T_CONV_HANDLED)
3757                             /*Don't reverse because user handles it already*/
3758                             reverse = FALSE;
3759                     } else if (src->shared->u.atomic.prec < dst->shared->u.atomic.prec) {
3760                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3761                               src->shared->u.atomic.prec-1);
3762                         H5T__bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec-1,
3763                              (dst->shared->u.atomic.prec-src->shared->u.atomic.prec)+1, FALSE);
3764                     } else if (first>=dst->shared->u.atomic.prec) {
3765                         /*overflow - source is positive*/
3766                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
3767                             H5T_reverse_order(src_rev, s, src->shared->size, src->shared->u.atomic.order); /*reverse order first*/
3768                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
3769                                     src_rev, d, cb_struct.user_data);
3770                         }
3771 
3772                         if(except_ret == H5T_CONV_UNHANDLED)
3773                             H5T__bit_set (d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec, TRUE);
3774                         else if(except_ret == H5T_CONV_ABORT)
3775                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
3776                         else if(except_ret == H5T_CONV_HANDLED)
3777                             /*Don't reverse because user handles it already*/
3778                             reverse = FALSE;
3779                     } else {
3780                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3781                               dst->shared->u.atomic.prec);
3782                     }
3783 
3784                 } else if (H5T_SGN_NONE==src->shared->u.atomic.u.i.sign &&
3785                            H5T_SGN_2==dst->shared->u.atomic.u.i.sign) {
3786                     /*
3787                      * If the source is not signed but the destination is then
3788                      * overflow can occur in which case the destination is set to
3789                      * the largest possible value (all bits set except the msb).
3790                      */
3791                     if (first+1 >= dst->shared->u.atomic.prec) {
3792                         /*overflow*/
3793                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
3794                             H5T_reverse_order(src_rev, s, src->shared->size, src->shared->u.atomic.order); /*reverse order first*/
3795                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
3796                                     src_rev, d, cb_struct.user_data);
3797                         }
3798 
3799                         if(except_ret == H5T_CONV_UNHANDLED) {
3800                             H5T__bit_set(d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec-1, TRUE);
3801                             H5T__bit_set(d, (dst->shared->u.atomic.offset + dst->shared->u.atomic.prec-1), (size_t)1, FALSE);
3802                         } else if(except_ret == H5T_CONV_ABORT)
3803                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
3804                         else if(except_ret == H5T_CONV_HANDLED)
3805                             /*Don't reverse because user handles it already*/
3806                             reverse = FALSE;
3807                     } else if (src->shared->u.atomic.prec<dst->shared->u.atomic.prec) {
3808                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3809                               src->shared->u.atomic.prec);
3810                         H5T__bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
3811                              dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
3812                     } else {
3813                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3814                               dst->shared->u.atomic.prec);
3815                     }
3816                 } else if (first+1 == src->shared->u.atomic.prec) {
3817                     /*
3818                      * Both the source and the destination are signed and the
3819                      * source value is negative.  We could experience overflow
3820                      * if the destination isn't wide enough in which case the
3821                      * destination is set to a negative number with the largest
3822                      * possible magnitude.
3823                      */
3824                     ssize_t sfz = H5T__bit_find (s, src->shared->u.atomic.offset,
3825                                     src->shared->u.atomic.prec-1, H5T_BIT_MSB, FALSE);
3826                     size_t fz = (size_t)sfz;
3827 
3828                     if (sfz>=0 && fz+1>=dst->shared->u.atomic.prec) {
3829                         /*overflow*/
3830                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
3831                             H5T_reverse_order(src_rev, s, src->shared->size, src->shared->u.atomic.order); /*reverse order first*/
3832                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW, src_id, dst_id,
3833                                     src_rev, d, cb_struct.user_data);
3834                         }
3835 
3836                         if(except_ret == H5T_CONV_UNHANDLED) {
3837                             H5T__bit_set(d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec-1, FALSE);
3838                             H5T__bit_set(d, (dst->shared->u.atomic.offset + dst->shared->u.atomic.prec-1), (size_t)1, TRUE);
3839                         } else if(except_ret == H5T_CONV_ABORT)
3840                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
3841                         else if(except_ret == H5T_CONV_HANDLED)
3842                             /*Don't reverse because user handles it already*/
3843                             reverse = FALSE;
3844                     } else if (src->shared->u.atomic.prec<dst->shared->u.atomic.prec) {
3845                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset, src->shared->u.atomic.prec);
3846                         H5T__bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec, dst->shared->u.atomic.prec-src->shared->u.atomic.prec, TRUE);
3847                     } else {
3848                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset, dst->shared->u.atomic.prec);
3849                     }
3850 
3851                 } else {
3852                     /*
3853                      * Source and destination are both signed but the source
3854                      * value is positive.  We could have an overflow in which
3855                      * case the destination is set to the largest possible
3856                      * positive value.
3857                      */
3858                     if (first+1>=dst->shared->u.atomic.prec) {
3859                         /*overflow*/
3860                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
3861                             H5T_reverse_order(src_rev, s, src->shared->size, src->shared->u.atomic.order); /*reverse order first*/
3862                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id, src_rev, d,
3863                                     cb_struct.user_data);
3864                         }
3865 
3866                         if(except_ret == H5T_CONV_UNHANDLED) {
3867                             H5T__bit_set(d, dst->shared->u.atomic.offset, dst->shared->u.atomic.prec-1, TRUE);
3868                             H5T__bit_set(d, (dst->shared->u.atomic.offset + dst->shared->u.atomic.prec-1), (size_t)1, FALSE);
3869                         } else if(except_ret == H5T_CONV_ABORT)
3870                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
3871                         else if(except_ret == H5T_CONV_HANDLED)
3872                             /*Don't reverse because user handles it already*/
3873                             reverse = FALSE;
3874                     } else if (src->shared->u.atomic.prec<dst->shared->u.atomic.prec) {
3875                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3876                               src->shared->u.atomic.prec);
3877                         H5T__bit_set (d, dst->shared->u.atomic.offset+src->shared->u.atomic.prec,
3878                              dst->shared->u.atomic.prec-src->shared->u.atomic.prec, FALSE);
3879                     } else {
3880                         H5T__bit_copy (d, dst->shared->u.atomic.offset, s, src->shared->u.atomic.offset,
3881                               dst->shared->u.atomic.prec);
3882                     }
3883                 }
3884 
3885                 /*
3886                  * Set padding areas in destination.
3887                  */
3888                 if (dst->shared->u.atomic.offset>0) {
3889                     HDassert(H5T_PAD_ZERO==dst->shared->u.atomic.lsb_pad || H5T_PAD_ONE==dst->shared->u.atomic.lsb_pad);
3890                     H5T__bit_set(d, (size_t)0, dst->shared->u.atomic.offset, (hbool_t)(H5T_PAD_ONE==dst->shared->u.atomic.lsb_pad));
3891                 }
3892                 if (dst->shared->u.atomic.offset+dst->shared->u.atomic.prec!=8*dst->shared->size) {
3893                     HDassert(H5T_PAD_ZERO==dst->shared->u.atomic.msb_pad || H5T_PAD_ONE==dst->shared->u.atomic.msb_pad);
3894                     H5T__bit_set (d, dst->shared->u.atomic.offset+dst->shared->u.atomic.prec,
3895                                  8*dst->shared->size - (dst->shared->u.atomic.offset+ dst->shared->u.atomic.prec),
3896                                  (hbool_t)(H5T_PAD_ONE==dst->shared->u.atomic.msb_pad));
3897                 }
3898 
3899                 /*
3900                  * Put the destination in the correct byte order.  See note at
3901                  * beginning of loop.
3902                  */
3903                 if (H5T_ORDER_BE==dst->shared->u.atomic.order && reverse) {
3904                     half_size = dst->shared->size/2;
3905                     for (i=0; i<half_size; i++) {
3906                         uint8_t tmp = d[dst->shared->size-(i+1)];
3907                         d[dst->shared->size-(i+1)] = d[i];
3908                         d[i] = tmp;
3909                     }
3910                 }
3911 
3912                 /*
3913                  * If we had used a temporary buffer for the destination then we
3914                  * should copy the value to the true destination buffer.
3915                  */
3916                 if(d==dbuf)
3917                     HDmemcpy(dp, d, dst->shared->size);
3918 
3919                 /* Advance source & destination pointers by delta amounts */
3920                 sp += src_delta;
3921                 dp += dst_delta;
3922             } /* end for */
3923 
3924             break;
3925 
3926         default:
3927             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
3928     } /* end switch */
3929 
3930 done:
3931     if(src_rev)
3932         H5MM_free(src_rev);
3933     FUNC_LEAVE_NOAPI(ret_value)
3934 } /* end H5T__conv_i_i() */
3935 
3936 
3937 /*-------------------------------------------------------------------------
3938  * Function:	H5T__conv_f_f
3939  *
3940  * Purpose:	Convert one floating point type to another.  This is a catch
3941  *		all for floating point conversions and is probably not
3942  *		particularly fast!
3943  *
3944  * Return:	Non-negative on success/Negative on failure
3945  *
3946  * Programmer:	Robb Matzke
3947  *		Tuesday, June 23, 1998
3948  *
3949  * Modifications:
3950  *		Robb Matzke, 7 Jul 1998
3951  *		Added overflow handling.
3952  *
3953  *		Robb Matzke, 1999-06-16
3954  *		Added support for non-zero strides. If BUF_STRIDE is non-zero
3955  *		then convert one value at each memory location advancing
3956  *		BUF_STRIDE bytes each time; otherwise assume both source and
3957  *		destination values are packed.
3958  *
3959  *              Robb Matzke, 2001-02-02
3960  *              Oops, forgot to increment the exponent when rounding the
3961  *              significand resulted in a carry. Thanks to Guillaume Colin
3962  *              de Verdiere for finding this one!
3963  *
3964  *              Raymond Lu, 2006-03-13
3965  *              Added support for VAX floating-point types.
3966  *-------------------------------------------------------------------------
3967  */
3968 herr_t
H5T__conv_f_f(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t dxpl_id)3969 H5T__conv_f_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
3970     size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
3971     hid_t dxpl_id)
3972 {
3973     /* Traversal-related variables */
3974     H5T_t	*src_p;			/*source datatype		*/
3975     H5T_t	*dst_p;			/*destination datatype		*/
3976     H5T_atomic_t src;			/*atomic source info		*/
3977     H5T_atomic_t dst;			/*atomic destination info	*/
3978     ssize_t	src_delta, dst_delta;	/*source & destination stride	*/
3979     int	direction;		        /*forward or backward traversal	*/
3980     size_t	elmtno;			/*element number		*/
3981     size_t	half_size;		/*half the type size		*/
3982     size_t      tsize;                  /*type size for swapping bytes  */
3983     size_t	olap;			/*num overlapping elements	*/
3984     ssize_t	bitno = 0;		/*bit number			*/
3985     uint8_t	*s, *sp, *d, *dp;	/*source and dest traversal ptrs*/
3986     uint8_t     *src_rev = NULL;        /*order-reversed source buffer  */
3987     uint8_t	dbuf[64];		/*temp destination buffer	*/
3988     uint8_t     tmp1, tmp2;             /*temp variables for swapping bytes*/
3989 
3990     /* Conversion-related variables */
3991     int64_t	expo;			/*exponent			*/
3992     hssize_t	expo_max;		/*maximum possible dst exponent	*/
3993     size_t	msize = 0;		/*useful size of mantissa in src*/
3994     size_t	mpos;			/*offset to useful mant is src	*/
3995     uint64_t    sign;                   /*source sign bit value         */
3996     size_t	mrsh;			/*amount to right shift mantissa*/
3997     hbool_t	carry = 0;		/*carry after rounding mantissa	*/
3998     size_t	i;			/*miscellaneous counters	*/
3999     size_t	implied;		/*destination implied bits	*/
4000     hbool_t     denormalized = FALSE;   /*is either source or destination denormalized?*/
4001     H5P_genplist_t      *plist;         /*property list pointer         */
4002     H5T_conv_cb_t       cb_struct = {NULL, NULL};      /*conversion callback structure */
4003     H5T_conv_ret_t      except_ret;     /*return of callback function   */
4004     hbool_t             reverse;        /*if reverse the order of destination        */
4005     herr_t      ret_value = SUCCEED;    /*return value                 */
4006 
4007     FUNC_ENTER_PACKAGE
4008 
4009     switch(cdata->command) {
4010         case H5T_CONV_INIT:
4011             if(NULL == (src_p = (H5T_t *)H5I_object(src_id)) || NULL == (dst_p = (H5T_t *)H5I_object(dst_id)))
4012                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
4013             src = src_p->shared->u.atomic;
4014             dst = dst_p->shared->u.atomic;
4015             if(H5T_ORDER_LE != src.order && H5T_ORDER_BE != src.order && H5T_ORDER_VAX != src.order)
4016                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
4017             if(H5T_ORDER_LE != dst.order && H5T_ORDER_BE != dst.order && H5T_ORDER_VAX != dst.order)
4018                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
4019             if(dst_p->shared->size > sizeof(dbuf))
4020                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination size is too large")
4021             if(8 * sizeof(expo) - 1 < src.u.f.esize || 8 * sizeof(expo) - 1 < dst.u.f.esize)
4022                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "exponent field is too large")
4023             cdata->need_bkg = H5T_BKG_NO;
4024             break;
4025 
4026         case H5T_CONV_FREE:
4027             break;
4028 
4029         case H5T_CONV_CONV:
4030             /* Get the datatypes */
4031             if(NULL == (src_p = (H5T_t *)H5I_object(src_id)) || NULL == (dst_p = (H5T_t *)H5I_object(dst_id)))
4032                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
4033             src = src_p->shared->u.atomic;
4034             dst = dst_p->shared->u.atomic;
4035             expo_max = ((hssize_t)1 << dst.u.f.esize) - 1;
4036 
4037             /*
4038              * Do we process the values from beginning to end or vice versa? Also,
4039              * how many of the elements have the source and destination areas
4040              * overlapping?
4041              */
4042             if (src_p->shared->size==dst_p->shared->size || buf_stride) {
4043                 sp = dp = (uint8_t*)buf;
4044                 direction = 1;
4045                 olap = nelmts;
4046             } else if (src_p->shared->size>=dst_p->shared->size) {
4047                 double olap_d = HDceil((double)(dst_p->shared->size)/
4048                                        (double)(src_p->shared->size-dst_p->shared->size));
4049                 olap = (size_t)olap_d;
4050                 sp = dp = (uint8_t*)buf;
4051                 direction = 1;
4052             } else {
4053                 double olap_d = HDceil((double)(src_p->shared->size)/
4054                                        (double)(dst_p->shared->size-src_p->shared->size));
4055                 olap = (size_t)olap_d;
4056                 sp = (uint8_t*)buf + (nelmts-1) * src_p->shared->size;
4057                 dp = (uint8_t*)buf + (nelmts-1) * dst_p->shared->size;
4058                 direction = -1;
4059             }
4060 
4061             /*
4062              * Direction & size of buffer traversal.
4063              */
4064             H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
4065             H5_CHECK_OVERFLOW(src_p->shared->size, size_t, ssize_t);
4066             H5_CHECK_OVERFLOW(dst_p->shared->size, size_t, ssize_t);
4067             src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src_p->shared->size);
4068             dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst_p->shared->size);
4069 
4070             /* Get the plist structure */
4071             if(NULL == (plist = H5P_object_verify(dxpl_id,H5P_DATASET_XFER)))
4072                 HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
4073 
4074             /* Get conversion exception callback property */
4075             if(H5P_get(plist,H5D_XFER_CONV_CB_NAME, &cb_struct) < 0)
4076                 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get conversion exception callback")
4077 
4078             /* Allocate space for order-reversed source buffer */
4079             src_rev = (uint8_t*)H5MM_calloc(src_p->shared->size);
4080 
4081             /* The conversion loop */
4082             for (elmtno=0; elmtno<nelmts; elmtno++) {
4083                 /* Set these variables to default */
4084                 except_ret = H5T_CONV_UNHANDLED;
4085                 reverse    = TRUE;
4086 
4087                 /*
4088                  * If the source and destination buffers overlap then use a
4089                  * temporary buffer for the destination.
4090                  */
4091                 if (direction>0) {
4092                     s = sp;
4093                     d = elmtno<olap ? dbuf : dp;
4094                 } else {
4095                     s = sp;
4096                     d = elmtno+olap >= nelmts ? dbuf : dp;
4097                 }
4098 #ifndef NDEBUG
4099                 /* I don't quite trust the overlap calculations yet --rpm */
4100                 if (d==dbuf) {
4101                     HDassert((dp>=sp && dp<sp+src_p->shared->size) ||
4102                             (sp>=dp && sp<dp+dst_p->shared->size));
4103                 } else {
4104                     HDassert((dp<sp && dp+dst_p->shared->size<=sp) ||
4105                             (sp<dp && sp+src_p->shared->size<=dp));
4106                 }
4107 #endif
4108 
4109                 /*
4110                  * Put the data in little endian order so our loops aren't so
4111                  * complicated.  We'll do all the conversion stuff assuming
4112                  * little endian and then we'll fix the order at the end.
4113                  */
4114                 if (H5T_ORDER_BE==src.order) {
4115                     half_size = src_p->shared->size/2;
4116                     for (i=0; i<half_size; i++) {
4117                         tmp1 = s[src_p->shared->size-(i+1)];
4118                         s[src_p->shared->size-(i+1)] = s[i];
4119                         s[i] = tmp1;
4120                     }
4121                 } else if (H5T_ORDER_VAX==src.order) {
4122                     tsize = src_p->shared->size;
4123                     HDassert(0 == tsize % 2);
4124 
4125                     for (i = 0; i < tsize; i += 4) {
4126                         tmp1 = s[i];
4127                         tmp2 = s[i+1];
4128 
4129                         s[i] = s[(tsize-2)-i];
4130                         s[i+1] = s[(tsize-1)-i];
4131 
4132                         s[(tsize-2)-i] = tmp1;
4133                         s[(tsize-1)-i] = tmp2;
4134                     }
4135                 }
4136 
4137                 /*
4138                  * Find the sign bit value of the source.
4139                  */
4140                 sign = H5T__bit_get_d(s, src.u.f.sign, (size_t)1);
4141 
4142                 /*
4143                  * Check for special cases: +0, -0, +Inf, -Inf, NaN
4144                  */
4145                 if (H5T__bit_find (s, src.u.f.mpos, src.u.f.msize,
4146                                   H5T_BIT_LSB, TRUE)<0) {
4147                     if (H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
4148                                       H5T_BIT_LSB, TRUE)<0) {
4149                         /* +0 or -0 */
4150                         H5T__bit_copy (d, dst.u.f.sign, s, src.u.f.sign, (size_t)1);
4151                         H5T__bit_set (d, dst.u.f.epos, dst.u.f.esize, FALSE);
4152                         H5T__bit_set (d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4153                         goto padding;
4154                     } else if (H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
4155                                              H5T_BIT_LSB, FALSE)<0) {
4156                         /* +Inf or -Inf */
4157                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
4158                             /*reverse order first*/
4159                             H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
4160                             if(sign)
4161                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_NINF,
4162                                     src_id, dst_id, src_rev, d, cb_struct.user_data);
4163                             else
4164                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_PINF,
4165                                     src_id, dst_id, src_rev, d, cb_struct.user_data);
4166                         }
4167 
4168                         if(except_ret == H5T_CONV_UNHANDLED) {
4169                             H5T__bit_copy (d, dst.u.f.sign, s, src.u.f.sign, (size_t)1);
4170                             H5T__bit_set (d, dst.u.f.epos, dst.u.f.esize, TRUE);
4171                             H5T__bit_set (d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4172                             /*If the destination no implied mantissa bit, we'll need to set
4173                              *the 1st bit of mantissa to 1.  The Intel-Linux long double is
4174                              *this case.*/
4175                             if (H5T_NORM_NONE==dst.u.f.norm)
4176                                 H5T__bit_set (d, dst.u.f.mpos+dst.u.f.msize-1, (size_t)1, TRUE);
4177                         } else if(except_ret == H5T_CONV_HANDLED) {
4178                             /*No need to reverse the order of destination because user handles it*/
4179                             reverse = FALSE;
4180                             goto next;
4181                         } else if(except_ret == H5T_CONV_ABORT)
4182                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
4183 
4184                         goto padding;
4185                     }
4186                 } else if (H5T_NORM_NONE==src.u.f.norm && H5T__bit_find (s, src.u.f.mpos, src.u.f.msize-1,
4187                                   H5T_BIT_LSB, TRUE)<0 && H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
4188                                   H5T_BIT_LSB, FALSE)<0) {
4189                     /*This is a special case for the source of no implied mantissa bit.
4190                      *If the exponent bits are all 1s and only the 1st bit of mantissa
4191                      *is set to 1.  It's infinity. The Intel-Linux "long double" is this case.*/
4192                     /* +Inf or -Inf */
4193                     if(cb_struct.func) { /*If user's exception handler is present, use it*/
4194                         /*reverse order first*/
4195                         H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
4196                         if(sign)
4197                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_NINF,
4198                                 src_id, dst_id, src_rev, d, cb_struct.user_data);
4199                         else
4200                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_PINF,
4201                                 src_id, dst_id, src_rev, d, cb_struct.user_data);
4202                     }
4203 
4204                     if(except_ret == H5T_CONV_UNHANDLED) {
4205                         H5T__bit_copy (d, dst.u.f.sign, s, src.u.f.sign, (size_t)1);
4206                         H5T__bit_set (d, dst.u.f.epos, dst.u.f.esize, TRUE);
4207                         H5T__bit_set (d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4208                         /*If the destination no implied mantissa bit, we'll need to set
4209                          *the 1st bit of mantissa to 1.  The Intel-Linux long double is
4210                          *this case.*/
4211                         if (H5T_NORM_NONE==dst.u.f.norm)
4212                             H5T__bit_set (d, dst.u.f.mpos+dst.u.f.msize-1, (size_t)1, TRUE);
4213                     } else if(except_ret == H5T_CONV_HANDLED) {
4214                         /*No need to reverse the order of destination because user handles it*/
4215                         reverse = FALSE;
4216                         goto next;
4217                     } else if(except_ret == H5T_CONV_ABORT)
4218                         HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
4219 
4220                     goto padding;
4221                 /* Temporary solution to handle VAX special values.
4222                  * Note that even though we don't support VAX anymore, we
4223                  * still need to handle legacy VAX files so this code must
4224                  * remain in place.
4225                  */
4226                 } else if (H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
4227                                          H5T_BIT_LSB, FALSE)<0) {
4228                     /* NaN */
4229                     if(cb_struct.func) { /*If user's exception handler is present, use it*/
4230                         /*reverse order first*/
4231                         H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
4232                         except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_NAN,
4233                                 src_id, dst_id, src_rev, d, cb_struct.user_data);
4234                     }
4235 
4236                     if(except_ret == H5T_CONV_UNHANDLED) {
4237                         /* There are many NaN values, so we just set all bits of
4238                          * the significand. */
4239                         H5T__bit_copy (d, dst.u.f.sign, s, src.u.f.sign, (size_t)1);
4240                         H5T__bit_set (d, dst.u.f.epos, dst.u.f.esize, TRUE);
4241                         H5T__bit_set(d, dst.u.f.mpos, dst.u.f.msize, TRUE);
4242                     } else if(except_ret == H5T_CONV_HANDLED) {
4243                         /*No need to reverse the order of destination because user handles it*/
4244                         reverse = FALSE;
4245                         goto next;
4246                     } else if(except_ret == H5T_CONV_ABORT)
4247                         HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
4248 
4249                     goto padding;
4250                 }
4251 
4252                 /*
4253                  * Get the exponent as an unsigned quantity from the section of
4254                  * the source bit field where it's located.	 Don't worry about
4255                  * the exponent bias yet.
4256                  */
4257                 expo = (int64_t)H5T__bit_get_d(s, src.u.f.epos, src.u.f.esize);
4258 
4259                 if(expo==0)
4260                    denormalized=TRUE;
4261 
4262                 /*
4263                  * Set markers for the source mantissa, excluding the leading `1'
4264                  * (might be implied).
4265                  */
4266                 implied = 1;
4267                 mpos = src.u.f.mpos;
4268                 mrsh = 0;
4269                 if(0 == expo || H5T_NORM_NONE == src.u.f.norm) {
4270                     if((bitno = H5T__bit_find(s, src.u.f.mpos, src.u.f.msize, H5T_BIT_MSB, TRUE)) > 0) {
4271                         msize = (size_t)bitno;
4272                     } else if (0==bitno) {
4273                         msize = 1;
4274                         H5T__bit_set(s, src.u.f.mpos, (size_t)1, FALSE);
4275                     }
4276                 } else if (H5T_NORM_IMPLIED==src.u.f.norm) {
4277                     msize = src.u.f.msize;
4278                 } else {
4279                     HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
4280                 }
4281 
4282                 /*
4283                  * The sign for the destination is the same as the sign for the
4284                  * source in all cases.
4285                  */
4286                 H5T__bit_copy (d, dst.u.f.sign, s, src.u.f.sign, (size_t)1);
4287 
4288                 /*
4289                  * Calculate the true source exponent by adjusting according to
4290                  * the source exponent bias.
4291                  */
4292                 if (0==expo || H5T_NORM_NONE==src.u.f.norm) {
4293                     HDassert(bitno>=0);
4294                     expo -= (int64_t)((src.u.f.ebias - 1) + (src.u.f.msize - (size_t)bitno));
4295                 } else if (H5T_NORM_IMPLIED==src.u.f.norm) {
4296                     expo -= (int64_t)src.u.f.ebias;
4297                 } else {
4298                     HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
4299                 }
4300 
4301                 /*
4302                  * If the destination is not normalized then right shift the
4303                  * mantissa by one.
4304                  */
4305                 if (H5T_NORM_NONE==dst.u.f.norm)
4306                     mrsh++;
4307 
4308                 /*
4309                  * Calculate the destination exponent by adding the destination
4310                  * bias and clipping by the minimum and maximum possible
4311                  * destination exponent values.
4312                  */
4313                 expo += (int64_t)dst.u.f.ebias;
4314 
4315                 if (expo < -(hssize_t)(dst.u.f.msize)) {
4316                     /* The exponent is way too small.  Result is zero. */
4317                     expo = 0;
4318                     H5T__bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4319                     msize = 0;
4320                 } else if (expo<=0) {
4321                     /*
4322                      * The exponent is too small to fit in the exponent field,
4323                      * but by shifting the mantissa to the right we can
4324                      * accomodate that value.  The mantissa of course is no
4325                      * longer normalized.
4326                      */
4327                     mrsh += (size_t)(1 - expo);
4328                     expo = 0;
4329                     denormalized=TRUE;
4330                 } else if (expo>=expo_max) {
4331                     /*
4332                      * The exponent is too large to fit in the available region
4333                      * or it results in the maximum possible value.	 Use positive
4334                      * or negative infinity instead unless the application
4335                      * specifies something else.  Before calling the overflow
4336                      * handler make sure the source buffer we hand it is in the
4337                      * original byte order.
4338                      */
4339                     if(cb_struct.func) { /*If user's exception handler is present, use it*/
4340                         /*reverse order first*/
4341                         H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
4342                         except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
4343                                 src_rev, d, cb_struct.user_data);
4344                     }
4345 
4346                     if(except_ret == H5T_CONV_UNHANDLED) {
4347                         expo = expo_max;
4348                         H5T__bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4349                         msize = 0;
4350                     } else if(except_ret == H5T_CONV_ABORT)
4351                         HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
4352                     else if(except_ret == H5T_CONV_HANDLED) {
4353                         reverse = FALSE;
4354                         goto next;
4355                     }
4356                 }
4357 
4358                 /*
4359                  * If the destination mantissa is smaller than the source
4360                  * mantissa then round the source mantissa. Rounding may cause a
4361                  * carry in which case the exponent has to be re-evaluated for
4362                  * overflow.  That is, if `carry' is clear then the implied
4363                  * mantissa bit is `1', else it is `10' binary.
4364                  */
4365                 if (msize>0 && mrsh<=dst.u.f.msize && mrsh+msize>dst.u.f.msize) {
4366                     bitno = (ssize_t)(mrsh + msize - dst.u.f.msize);
4367                     HDassert(bitno >= 0 && (size_t)bitno <= msize);
4368                     /* If the 1st bit being cut off is set and source isn't denormalized.*/
4369                     if(H5T__bit_get_d(s, (mpos + (size_t)bitno) - 1, (size_t)1) && !denormalized) {
4370                         /* Don't do rounding if exponent is 111...110 and mantissa is 111...11.
4371                          * To do rounding and increment exponent in this case will create an infinity value.*/
4372                         if((H5T__bit_find(s, mpos + (size_t)bitno, msize - (size_t)bitno, H5T_BIT_LSB, FALSE) >= 0 || expo < expo_max - 1)) {
4373                             carry = (hbool_t)H5T__bit_inc(s, mpos + (size_t)bitno - 1, 1 + msize - (size_t)bitno);
4374                             if(carry)
4375                                 implied = 2;
4376                         }
4377                     } else if(H5T__bit_get_d(s, (mpos + (size_t)bitno) - 1, (size_t)1) && denormalized)
4378                         /* For either source or destination, denormalized value doesn't increment carry.*/
4379                         H5T__bit_inc(s, mpos + (size_t)bitno - 1, 1 + msize - (size_t)bitno);
4380                 }
4381                 else
4382                     carry=0;
4383 
4384                 /*
4385                  * Write the mantissa to the destination
4386                  */
4387                 if (mrsh>dst.u.f.msize+1) {
4388                     H5T__bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4389                 } else if (mrsh==dst.u.f.msize+1) {
4390                     H5T__bit_set(d, dst.u.f.mpos+1, dst.u.f.msize-1, FALSE);
4391                     H5T__bit_set(d, dst.u.f.mpos, (size_t)1, TRUE);
4392                 } else if (mrsh==dst.u.f.msize) {
4393                     H5T__bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4394                     H5T__bit_set_d(d, dst.u.f.mpos, MIN(2, dst.u.f.msize), (hsize_t)implied);
4395                 } else {
4396                     if (mrsh>0) {
4397                         H5T__bit_set(d, dst.u.f.mpos+dst.u.f.msize-mrsh, mrsh,
4398                                     FALSE);
4399                         H5T__bit_set_d(d, dst.u.f.mpos+dst.u.f.msize-mrsh, (size_t)2,
4400                                       (hsize_t)implied);
4401                     }
4402                     if (mrsh+msize>=dst.u.f.msize) {
4403                         H5T__bit_copy(d, dst.u.f.mpos,
4404                                      s, (mpos+msize+mrsh-dst.u.f.msize),
4405                                      dst.u.f.msize-mrsh);
4406                     } else {
4407                         H5T__bit_copy(d, dst.u.f.mpos+dst.u.f.msize-(mrsh+msize),
4408                                      s, mpos, msize);
4409                         H5T__bit_set(d, dst.u.f.mpos, dst.u.f.msize-(mrsh+msize),
4410                                     FALSE);
4411                     }
4412                 }
4413 
4414                 /* Write the exponent */
4415                 if (carry) {
4416                     expo++;
4417                     if (expo>=expo_max) {
4418                         /*
4419                          * The exponent is too large to fit in the available
4420                          * region or it results in the maximum possible value.
4421                          * Use positive or negative infinity instead unless the
4422                          * application specifies something else.  Before
4423                          * calling the overflow handler make sure the source
4424                          * buffer we hand it is in the original byte order.
4425                          */
4426                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
4427                             /*reverse order first*/
4428                             H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
4429                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
4430                                     src_rev, d, cb_struct.user_data);
4431                         }
4432 
4433                         if(except_ret == H5T_CONV_UNHANDLED) {
4434                             expo = expo_max;
4435                             H5T__bit_set(d, dst.u.f.mpos, dst.u.f.msize, FALSE);
4436                         } else if(except_ret == H5T_CONV_ABORT)
4437                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
4438                         else if(except_ret == H5T_CONV_HANDLED) {
4439                             reverse = FALSE;
4440                             goto next;
4441                         }
4442                     }
4443                 }
4444                 /*reset CARRY*/
4445                 carry = 0;
4446 
4447                 H5_CHECK_OVERFLOW(expo,hssize_t,hsize_t);
4448                 H5T__bit_set_d(d, dst.u.f.epos, dst.u.f.esize, (hsize_t)expo);
4449 
4450             padding:
4451 
4452                 /*
4453                  * Set external padding areas
4454                  */
4455                 if (dst.offset>0) {
4456                     HDassert(H5T_PAD_ZERO==dst.lsb_pad || H5T_PAD_ONE==dst.lsb_pad);
4457                     H5T__bit_set (d, (size_t)0, dst.offset, (hbool_t)(H5T_PAD_ONE==dst.lsb_pad));
4458                 }
4459                 if (dst.offset+dst.prec!=8*dst_p->shared->size) {
4460                     HDassert(H5T_PAD_ZERO==dst.msb_pad || H5T_PAD_ONE==dst.msb_pad);
4461                     H5T__bit_set (d, dst.offset+dst.prec, 8*dst_p->shared->size - (dst.offset+dst.prec),
4462                          (hbool_t)(H5T_PAD_ONE==dst.msb_pad));
4463                 }
4464 
4465                 /*
4466                  * Put the destination in the correct byte order.  See note at
4467                  * beginning of loop.
4468                  */
4469                 if (H5T_ORDER_BE==dst.order && reverse) {
4470                     half_size = dst_p->shared->size/2;
4471                     for (i=0; i<half_size; i++) {
4472                         uint8_t tmp = d[dst_p->shared->size-(i+1)];
4473                         d[dst_p->shared->size-(i+1)] = d[i];
4474                         d[i] = tmp;
4475                     }
4476                 } else if (H5T_ORDER_VAX==dst.order && reverse) {
4477                     tsize = dst_p->shared->size;
4478                     HDassert(0 == tsize % 2);
4479 
4480                     for (i = 0; i < tsize; i += 4) {
4481                         tmp1 = d[i];
4482                         tmp2 = d[i+1];
4483 
4484                         d[i] = d[(tsize-2)-i];
4485                         d[i+1] = d[(tsize-1)-i];
4486 
4487                         d[(tsize-2)-i] = tmp1;
4488                         d[(tsize-1)-i] = tmp2;
4489                     }
4490                 }
4491 
4492                 /*
4493                  * If we had used a temporary buffer for the destination then we
4494                  * should copy the value to the true destination buffer.
4495                  */
4496             next:
4497                 if(d == dbuf)
4498                     HDmemcpy(dp, d, dst_p->shared->size);
4499 
4500                 /* Advance source & destination pointers by delta amounts */
4501                 sp += src_delta;
4502                 dp += dst_delta;
4503             }
4504 
4505             break;
4506 
4507         default:
4508             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
4509     } /* end switch */
4510 
4511 done:
4512     if(src_rev)
4513         H5MM_free(src_rev);
4514 
4515     FUNC_LEAVE_NOAPI(ret_value)
4516 } /* end H5T__conv_f_f() */
4517 
4518 
4519 /*-------------------------------------------------------------------------
4520  * Function:	H5T__conv_s_s
4521  *
4522  * Purpose:	Convert one fixed-length string type to another.
4523  *
4524  * Return:	Non-negative on success/Negative on failure
4525  *
4526  * Programmer:	Robb Matzke
4527  *		Friday, August	7, 1998
4528  *
4529  * Modifications:
4530  *		Robb Matzke, 1999-06-16
4531  *		Added support for non-zero strides. If BUF_STRIDE is non-zero
4532  *		then convert one value at each memory location advancing
4533  *		BUF_STRIDE bytes each time; otherwise assume both source and
4534  *		destination values are packed.
4535  *
4536  *              Raymond Lu, 8 November 2011
4537  *              I put a condition check to prevent the conversion of strings
4538  *              between ASCII and UTF8.
4539  *-------------------------------------------------------------------------
4540  */
4541 herr_t
H5T__conv_s_s(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4542 H5T__conv_s_s(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
4543 	      size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *buf,
4544               void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
4545 {
4546     H5T_t	*src=NULL;		/*source datatype		*/
4547     H5T_t	*dst=NULL;		/*destination datatype		*/
4548     ssize_t	src_delta, dst_delta;	/*source & destination stride	*/
4549     int	        direction;		/*direction of traversal	*/
4550     size_t	elmtno;			/*element number		*/
4551     size_t	olap;			/*num overlapping elements	*/
4552     size_t	nchars=0;		/*number of characters copied	*/
4553     uint8_t	*s, *sp, *d, *dp;	/*src and dst traversal pointers*/
4554     uint8_t	*dbuf=NULL;		/*temp buf for overlap convers.	*/
4555     herr_t      ret_value=SUCCEED;       /* Return value */
4556 
4557     FUNC_ENTER_PACKAGE
4558 
4559     switch(cdata->command) {
4560         case H5T_CONV_INIT:
4561             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
4562                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
4563             if(8 * src->shared->size != src->shared->u.atomic.prec || 8 * dst->shared->size != dst->shared->u.atomic.prec)
4564                 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad precision")
4565             if(0 != src->shared->u.atomic.offset || 0 != dst->shared->u.atomic.offset)
4566                 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad offset")
4567             if(H5T_CSET_ASCII != src->shared->u.atomic.u.s.cset && H5T_CSET_UTF8 != src->shared->u.atomic.u.s.cset)
4568                 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad source character set")
4569             if(H5T_CSET_ASCII != dst->shared->u.atomic.u.s.cset && H5T_CSET_UTF8 != dst->shared->u.atomic.u.s.cset)
4570                 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad destination character set")
4571             if((H5T_CSET_ASCII == src->shared->u.atomic.u.s.cset && H5T_CSET_UTF8 == dst->shared->u.atomic.u.s.cset)
4572                     || (H5T_CSET_ASCII == dst->shared->u.atomic.u.s.cset && H5T_CSET_UTF8 == src->shared->u.atomic.u.s.cset))
4573                 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "The library doesn't convert between strings of ASCII and UTF")
4574             if(src->shared->u.atomic.u.s.pad < 0 || src->shared->u.atomic.u.s.pad >= H5T_NSTR ||
4575                     dst->shared->u.atomic.u.s.pad < 0 || dst->shared->u.atomic.u.s.pad >= H5T_NSTR)
4576                 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad character padding")
4577             cdata->need_bkg = H5T_BKG_NO;
4578             break;
4579 
4580         case H5T_CONV_FREE:
4581             break;
4582 
4583         case H5T_CONV_CONV:
4584             /* Get the datatypes */
4585             if(NULL == (src = (H5T_t *)H5I_object(src_id)) || NULL == (dst = (H5T_t *)H5I_object(dst_id)))
4586                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
4587 
4588             /*
4589              * Do we process the values from beginning to end or vice versa? Also,
4590              * how many of the elements have the source and destination areas
4591              * overlapping?
4592              */
4593             if (src->shared->size==dst->shared->size || buf_stride) {
4594                 /*
4595                  * When the source and destination are the same size we can do
4596                  * all the conversions in place.
4597                  */
4598                 sp = dp = (uint8_t*)buf;
4599                 direction = 1;
4600                 olap = 0;
4601             } else if (src->shared->size>=dst->shared->size) {
4602                 double olapd = HDceil((double)(dst->shared->size)/
4603                           (double)(src->shared->size-dst->shared->size));
4604                 olap = (size_t)olapd;
4605                 sp = dp = (uint8_t*)buf;
4606                 direction = 1;
4607             } else {
4608                 double olapd = HDceil((double)(src->shared->size)/
4609                           (double)(dst->shared->size-src->shared->size));
4610                 olap = (size_t)olapd;
4611                 sp = (uint8_t*)buf + (nelmts-1) * src->shared->size;
4612                 dp = (uint8_t*)buf + (nelmts-1) * dst->shared->size;
4613                 direction = -1;
4614             }
4615 
4616             /*
4617              * Direction & size of buffer traversal.
4618              */
4619             H5_CHECK_OVERFLOW(buf_stride, size_t, ssize_t);
4620             H5_CHECK_OVERFLOW(src->shared->size, size_t, ssize_t);
4621             H5_CHECK_OVERFLOW(dst->shared->size, size_t, ssize_t);
4622             src_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : src->shared->size);
4623             dst_delta = (ssize_t)direction * (ssize_t)(buf_stride ? buf_stride : dst->shared->size);
4624 
4625             /* Allocate the overlap buffer */
4626             if(NULL == (dbuf = (uint8_t *)H5MM_malloc(dst->shared->size)))
4627                 HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for string conversion")
4628 
4629             /* The conversion loop. */
4630             for(elmtno = 0; elmtno < nelmts; elmtno++) {
4631 
4632                 /*
4633                  * If the source and destination buffers overlap then use a
4634                  * temporary buffer for the destination.
4635                  */
4636                 if(direction > 0) {
4637                     s = sp;
4638                     d = elmtno < olap ? dbuf : dp;
4639                 } else {
4640                     s = sp;
4641                     d = elmtno + olap >= nelmts ? dbuf : dp;
4642                 }
4643 #ifndef NDEBUG
4644                 /* I don't quite trust the overlap calculations yet --rpm */
4645                 if (src->shared->size==dst->shared->size || buf_stride) {
4646                     HDassert(s==d);
4647                 } else if (d==dbuf) {
4648                     HDassert((dp>=sp && dp<sp+src->shared->size) ||
4649                        (sp>=dp && sp<dp+dst->shared->size));
4650                 } else {
4651                     HDassert((dp<sp && dp+dst->shared->size<=sp) ||
4652                        (sp<dp && sp+src->shared->size<=dp));
4653                 }
4654 #endif
4655 
4656                 /* Copy characters from source to destination */
4657                 switch(src->shared->u.atomic.u.s.pad) {
4658                     case H5T_STR_NULLTERM:
4659                         for (nchars=0;
4660                              nchars<dst->shared->size && nchars<src->shared->size && s[nchars];
4661                              nchars++) {
4662                             d[nchars] = s[nchars];
4663                         }
4664                         break;
4665 
4666                     case H5T_STR_NULLPAD:
4667                         for (nchars=0;
4668                              nchars<dst->shared->size && nchars<src->shared->size && s[nchars];
4669                              nchars++) {
4670                             d[nchars] = s[nchars];
4671                         }
4672                         break;
4673 
4674                     case H5T_STR_SPACEPAD:
4675                         nchars = src->shared->size;
4676                         while (nchars>0 && ' '==s[nchars-1])
4677                             --nchars;
4678                         nchars = MIN(dst->shared->size, nchars);
4679                         if(d != s)
4680                             HDmemcpy(d, s, nchars);
4681                         break;
4682 
4683                     case H5T_STR_RESERVED_3:
4684                     case H5T_STR_RESERVED_4:
4685                     case H5T_STR_RESERVED_5:
4686                     case H5T_STR_RESERVED_6:
4687                     case H5T_STR_RESERVED_7:
4688                     case H5T_STR_RESERVED_8:
4689                     case H5T_STR_RESERVED_9:
4690                     case H5T_STR_RESERVED_10:
4691                     case H5T_STR_RESERVED_11:
4692                     case H5T_STR_RESERVED_12:
4693                     case H5T_STR_RESERVED_13:
4694                     case H5T_STR_RESERVED_14:
4695                     case H5T_STR_RESERVED_15:
4696                     case H5T_STR_ERROR:
4697                     default:
4698                         HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "source string padding method not supported")
4699                 } /* end switch */
4700 
4701                 /* Terminate or pad the destination */
4702                 switch(dst->shared->u.atomic.u.s.pad) {
4703                     case H5T_STR_NULLTERM:
4704                         while(nchars < dst->shared->size)
4705                             d[nchars++] = '\0';
4706                         d[dst->shared->size - 1] = '\0';
4707                         break;
4708 
4709                     case H5T_STR_NULLPAD:
4710                         while(nchars < dst->shared->size)
4711                             d[nchars++] = '\0';
4712                         break;
4713 
4714                     case H5T_STR_SPACEPAD:
4715                         while(nchars < dst->shared->size)
4716                             d[nchars++] = ' ';
4717                         break;
4718 
4719                     case H5T_STR_RESERVED_3:
4720                     case H5T_STR_RESERVED_4:
4721                     case H5T_STR_RESERVED_5:
4722                     case H5T_STR_RESERVED_6:
4723                     case H5T_STR_RESERVED_7:
4724                     case H5T_STR_RESERVED_8:
4725                     case H5T_STR_RESERVED_9:
4726                     case H5T_STR_RESERVED_10:
4727                     case H5T_STR_RESERVED_11:
4728                     case H5T_STR_RESERVED_12:
4729                     case H5T_STR_RESERVED_13:
4730                     case H5T_STR_RESERVED_14:
4731                     case H5T_STR_RESERVED_15:
4732                     case H5T_STR_ERROR:
4733                     default:
4734                         HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination string padding method not supported")
4735                 } /* end switch */
4736 
4737                 /*
4738                  * If we used a temporary buffer for the destination then we
4739                  * should copy the value to the true destination buffer.
4740                  */
4741                 if(d == dbuf)
4742                     HDmemcpy(dp, d, dst->shared->size);
4743 
4744                 /* Advance source & destination pointers by delta amounts */
4745                 sp += src_delta;
4746                 dp += dst_delta;
4747             } /* end for */
4748             break;
4749 
4750         default:
4751             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown converson command")
4752     } /* end switch */
4753 
4754 done:
4755     H5MM_xfree(dbuf);
4756 
4757     FUNC_LEAVE_NOAPI(ret_value)
4758 } /* end H5T__conv_s_s() */
4759 
4760 
4761 /*-------------------------------------------------------------------------
4762  * Function:	H5T__conv_schar_uchar
4763  *
4764  * Purpose:	Converts `signed char' to `unsigned char'
4765  *
4766  * Return:	Success:	non-negative
4767  *
4768  *		Failure:	negative
4769  *
4770  * Programmer:	Robb Matzke
4771  *		Monday, November 16, 1998
4772  *
4773  * Modifications:
4774  *
4775  *-------------------------------------------------------------------------
4776  */
4777 herr_t
H5T__conv_schar_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4778 H5T__conv_schar_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4779 		     size_t nelmts, size_t buf_stride,
4780                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
4781                      hid_t H5_ATTR_UNUSED dxpl_id)
4782 {
4783     H5T_CONV_su(SCHAR, UCHAR, signed char, unsigned char, -, -);
4784 }
4785 
4786 
4787 /*-------------------------------------------------------------------------
4788  * Function:	H5T__conv_uchar_schar
4789  *
4790  * Purpose:	Converts `unsigned char' to `signed char'
4791  *
4792  * Return:	Success:	non-negative
4793  *
4794  *		Failure:	negative
4795  *
4796  * Programmer:	Robb Matzke
4797  *		Monday, November 16, 1998
4798  *
4799  * Modifications:
4800  *
4801  *-------------------------------------------------------------------------
4802  */
4803 herr_t
H5T__conv_uchar_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4804 H5T__conv_uchar_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4805 		     size_t nelmts, size_t buf_stride,
4806                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
4807                      hid_t H5_ATTR_UNUSED dxpl_id)
4808 {
4809     H5T_CONV_us(UCHAR, SCHAR, unsigned char, signed char, -, SCHAR_MAX);
4810 }
4811 
4812 
4813 /*-------------------------------------------------------------------------
4814  * Function:	H5T__conv_schar_short
4815  *
4816  * Purpose:	Converts `signed char' to `short'
4817  *
4818  * Return:	Success:	Non-negative
4819  *
4820  *		Failure:	Negative
4821  *
4822  * Programmer:	Robb Matzke
4823  *		Friday, November 13, 1998
4824  *
4825  * Modifications:
4826  *
4827  *-------------------------------------------------------------------------
4828  */
4829 herr_t
H5T__conv_schar_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4830 H5T__conv_schar_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4831 		     size_t nelmts, size_t buf_stride,
4832                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
4833                      hid_t H5_ATTR_UNUSED dxpl_id)
4834 {
4835     H5T_CONV_sS(SCHAR, SHORT, signed char, short, -, -);
4836 }
4837 
4838 
4839 /*-------------------------------------------------------------------------
4840  * Function:	H5T__conv_schar_ushort
4841  *
4842  * Purpose:	Converts `signed char' to `unsigned short'
4843  *
4844  * Return:	Success:	Non-negative
4845  *
4846  *		Failure:	Negative
4847  *
4848  * Programmer:	Robb Matzke
4849  *		Friday, November 13, 1998
4850  *
4851  * Modifications:
4852  *
4853  *-------------------------------------------------------------------------
4854  */
4855 herr_t
H5T__conv_schar_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4856 H5T__conv_schar_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4857 		      size_t nelmts, size_t buf_stride,
4858                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
4859                       hid_t H5_ATTR_UNUSED dxpl_id)
4860 {
4861     H5T_CONV_sU(SCHAR, USHORT, signed char, unsigned short, -, -);
4862 }
4863 
4864 
4865 /*-------------------------------------------------------------------------
4866  * Function:	H5T__conv_uchar_short
4867  *
4868  * Purpose:	Converts `unsigned char' to `short'
4869  *
4870  * Return:	Success:	non-negative
4871  *
4872  *		Failure:	negative
4873  *
4874  * Programmer:	Robb Matzke
4875  *		Friday, November 13, 1998
4876  *
4877  * Modifications:
4878  *
4879  *-------------------------------------------------------------------------
4880  */
4881 herr_t
H5T__conv_uchar_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4882 H5T__conv_uchar_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4883 		     size_t nelmts, size_t buf_stride,
4884                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
4885                      hid_t H5_ATTR_UNUSED dxpl_id)
4886 {
4887     H5T_CONV_uS(UCHAR, SHORT, unsigned char, short, -, SHRT_MAX);
4888 }
4889 
4890 
4891 /*-------------------------------------------------------------------------
4892  * Function:	H5T__conv_uchar_ushort
4893  *
4894  * Purpose:	Converts `unsigned char' to `unsigned short'
4895  *
4896  * Return:	Success:	non-negative
4897  *
4898  *		Failure:	negative
4899  *
4900  * Programmer:	Robb Matzke
4901  *		Friday, November 13, 1998
4902  *
4903  * Modifications:
4904  *
4905  *-------------------------------------------------------------------------
4906  */
4907 herr_t
H5T__conv_uchar_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4908 H5T__conv_uchar_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4909 		      size_t nelmts, size_t buf_stride,
4910                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
4911                       hid_t H5_ATTR_UNUSED dxpl_id)
4912 {
4913     H5T_CONV_uU(UCHAR, USHORT, unsigned char, unsigned short, -, -);
4914 }
4915 
4916 
4917 /*-------------------------------------------------------------------------
4918  * Function:	H5T__conv_schar_int
4919  *
4920  * Purpose:	Converts `signed char' to `int'
4921  *
4922  * Return:	Success:	Non-negative
4923  *
4924  *		Failure:	Negative
4925  *
4926  * Programmer:	Robb Matzke
4927  *		Friday, November 13, 1998
4928  *
4929  * Modifications:
4930  *
4931  *-------------------------------------------------------------------------
4932  */
4933 herr_t
H5T__conv_schar_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4934 H5T__conv_schar_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4935 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
4936                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
4937 {
4938     H5T_CONV_sS(SCHAR, INT, signed char, int, -, -);
4939 }
4940 
4941 
4942 /*-------------------------------------------------------------------------
4943  * Function:	H5T__conv_schar_uint
4944  *
4945  * Purpose:	Converts `signed char' to `unsigned int'
4946  *
4947  * Return:	Success:	Non-negative
4948  *
4949  *		Failure:	Negative
4950  *
4951  * Programmer:	Robb Matzke
4952  *		Friday, November 13, 1998
4953  *
4954  * Modifications:
4955  *
4956  *-------------------------------------------------------------------------
4957  */
4958 herr_t
H5T__conv_schar_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4959 H5T__conv_schar_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4960 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
4961                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
4962 {
4963     H5T_CONV_sU(SCHAR, UINT, signed char, unsigned, -, -);
4964 }
4965 
4966 
4967 /*-------------------------------------------------------------------------
4968  * Function:	H5T__conv_uchar_int
4969  *
4970  * Purpose:	Converts `unsigned char' to `int'
4971  *
4972  * Return:	Success:	Non-negative
4973  *
4974  *		Failure:	Negative
4975  *
4976  * Programmer:	Robb Matzke
4977  *		Friday, November 13, 1998
4978  *
4979  * Modifications:
4980  *
4981  *-------------------------------------------------------------------------
4982  */
4983 herr_t
H5T__conv_uchar_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)4984 H5T__conv_uchar_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
4985 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
4986                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
4987 {
4988     H5T_CONV_uS(UCHAR, INT, unsigned char, int, -, INT_MAX);
4989 }
4990 
4991 
4992 /*-------------------------------------------------------------------------
4993  * Function:	H5T__conv_uchar_uint
4994  *
4995  * Purpose:	Converts `unsigned char' to `unsigned int'
4996  *
4997  * Return:	Success:	Non-negative
4998  *
4999  *		Failure:	Negative
5000  *
5001  * Programmer:	Robb Matzke
5002  *		Friday, November 13, 1998
5003  *
5004  * Modifications:
5005  *
5006  *-------------------------------------------------------------------------
5007  */
5008 herr_t
H5T__conv_uchar_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5009 H5T__conv_uchar_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5010 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
5011                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
5012 {
5013     H5T_CONV_uU(UCHAR, UINT, unsigned char, unsigned, -, -);
5014 }
5015 
5016 
5017 /*-------------------------------------------------------------------------
5018  * Function:	H5T__conv_schar_long
5019  *
5020  * Purpose:	Converts `signed char' to `long'
5021  *
5022  * Return:	Success:	Non-negative
5023  *
5024  *		Failure:	Negative
5025  *
5026  * Programmer:	Robb Matzke
5027  *		Friday, November 13, 1998
5028  *
5029  * Modifications:
5030  *
5031  *-------------------------------------------------------------------------
5032  */
5033 herr_t
H5T__conv_schar_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5034 H5T__conv_schar_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5035 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
5036                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
5037 {
5038     H5T_CONV_sS(SCHAR, LONG, signed char, long, -, -);
5039 }
5040 
5041 
5042 /*-------------------------------------------------------------------------
5043  * Function:	H5T__conv_schar_ulong
5044  *
5045  * Purpose:	Converts `signed char' to `unsigned long'
5046  *
5047  * Return:	Success:	Non-negative
5048  *
5049  *		Failure:	Negative
5050  *
5051  * Programmer:	Robb Matzke
5052  *		Friday, November 13, 1998
5053  *
5054  * Modifications:
5055  *
5056  *-------------------------------------------------------------------------
5057  */
5058 herr_t
H5T__conv_schar_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5059 H5T__conv_schar_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5060 		     size_t nelmts, size_t buf_stride,
5061                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5062 		     hid_t H5_ATTR_UNUSED dxpl_id)
5063 {
5064     H5T_CONV_sU(SCHAR, ULONG, signed char, unsigned long, -, -);
5065 }
5066 
5067 
5068 /*-------------------------------------------------------------------------
5069  * Function:	H5T__conv_uchar_long
5070  *
5071  * Purpose:	Converts `unsigned char' to `long'
5072  *
5073  * Return:	Success:	Non-negative
5074  *
5075  *		Failure:	Negative
5076  *
5077  * Programmer:	Robb Matzke
5078  *		Friday, November 13, 1998
5079  *
5080  * Modifications:
5081  *
5082  *-------------------------------------------------------------------------
5083  */
5084 herr_t
H5T__conv_uchar_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5085 H5T__conv_uchar_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5086 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
5087                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
5088 {
5089     H5T_CONV_uS(UCHAR, LONG, unsigned char, long, -, LONG_MAX);
5090 }
5091 
5092 
5093 /*-------------------------------------------------------------------------
5094  * Function:	H5T__conv_uchar_ulong
5095  *
5096  * Purpose:	Converts `unsigned char' to `unsigned long'
5097  *
5098  * Return:	Success:	Non-negative
5099  *
5100  *		Failure:	Negative
5101  *
5102  * Programmer:	Robb Matzke
5103  *		Friday, November 13, 1998
5104  *
5105  * Modifications:
5106  *
5107  *-------------------------------------------------------------------------
5108  */
5109 herr_t
H5T__conv_uchar_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5110 H5T__conv_uchar_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5111 		     size_t nelmts, size_t buf_stride,
5112                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5113 		     hid_t H5_ATTR_UNUSED dxpl_id)
5114 {
5115     H5T_CONV_uU(UCHAR, ULONG, unsigned char, unsigned long, -, -);
5116 }
5117 
5118 
5119 /*-------------------------------------------------------------------------
5120  * Function:	H5T__conv_schar_llong
5121  *
5122  * Purpose:	Converts `signed char' to `long long'
5123  *
5124  * Return:	Success:	Non-negative
5125  *
5126  *		Failure:	Negative
5127  *
5128  * Programmer:	Robb Matzke
5129  *		Friday, November 13, 1998
5130  *
5131  * Modifications:
5132  *
5133  *-------------------------------------------------------------------------
5134  */
5135 herr_t
H5T__conv_schar_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5136 H5T__conv_schar_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5137 		     size_t nelmts, size_t buf_stride,
5138                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5139 		     hid_t H5_ATTR_UNUSED dxpl_id)
5140 {
5141     H5T_CONV_sS(SCHAR, LLONG, signed char, long long, -, -);
5142 }
5143 
5144 
5145 /*-------------------------------------------------------------------------
5146  * Function:	H5T__conv_schar_ullong
5147  *
5148  * Purpose:	Converts `signed char' to `unsigned long long'
5149  *
5150  * Return:	Success:	Non-negative
5151  *
5152  *		Failure:	Negative
5153  *
5154  * Programmer:	Robb Matzke
5155  *		Friday, November 13, 1998
5156  *
5157  * Modifications:
5158  *
5159  *-------------------------------------------------------------------------
5160  */
5161 herr_t
H5T__conv_schar_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5162 H5T__conv_schar_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5163 		      size_t nelmts, size_t buf_stride,
5164                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5165                       hid_t H5_ATTR_UNUSED dxpl_id)
5166 {
5167     H5T_CONV_sU(SCHAR, ULLONG, signed char, unsigned long long, -, -);
5168 }
5169 
5170 
5171 /*-------------------------------------------------------------------------
5172  * Function:	H5T__conv_uchar_llong
5173  *
5174  * Purpose:	Converts `unsigned char' to `long long'
5175  *
5176  * Return:	Success:	Non-negative
5177  *
5178  *		Failure:	Negative
5179  *
5180  * Programmer:	Robb Matzke
5181  *		Friday, November 13, 1998
5182  *
5183  * Modifications:
5184  *
5185  *-------------------------------------------------------------------------
5186  */
5187 herr_t
H5T__conv_uchar_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5188 H5T__conv_uchar_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5189 		     size_t nelmts, size_t buf_stride,
5190                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5191 		     hid_t H5_ATTR_UNUSED dxpl_id)
5192 {
5193     H5T_CONV_uS(UCHAR, LLONG, unsigned char, long long, -, LLONG_MAX);
5194 }
5195 
5196 
5197 /*-------------------------------------------------------------------------
5198  * Function:	H5T__conv_uchar_ullong
5199  *
5200  * Purpose:	Converts `unsigned char' to `unsigned long long'
5201  *
5202  * Return:	Success:	Non-negative
5203  *
5204  *		Failure:	Negative
5205  *
5206  * Programmer:	Robb Matzke
5207  *		Friday, November 13, 1998
5208  *
5209  * Modifications:
5210  *
5211  *-------------------------------------------------------------------------
5212  */
5213 herr_t
H5T__conv_uchar_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5214 H5T__conv_uchar_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5215 		      size_t nelmts, size_t buf_stride,
5216                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5217                       hid_t H5_ATTR_UNUSED dxpl_id)
5218 {
5219     H5T_CONV_uU(UCHAR, ULLONG, unsigned char, unsigned long long, -, -);
5220 }
5221 
5222 
5223 /*-------------------------------------------------------------------------
5224  * Function:	H5T__conv_short_schar
5225  *
5226  * Purpose:	Converts `short' to `signed char'
5227  *
5228  * Return:	Success:	non-negative
5229  *
5230  *		Failure:	negative
5231  *
5232  * Programmer:	Robb Matzke
5233  *		Friday, November 13, 1998
5234  *
5235  * Modifications:
5236  *
5237  *-------------------------------------------------------------------------
5238  */
5239 herr_t
H5T__conv_short_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5240 H5T__conv_short_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5241 		     size_t nelmts, size_t buf_stride,
5242                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5243 		     hid_t H5_ATTR_UNUSED dxpl_id)
5244 {
5245     H5T_CONV_Ss(SHORT, SCHAR, short, signed char, SCHAR_MIN, SCHAR_MAX);
5246 }
5247 
5248 
5249 /*-------------------------------------------------------------------------
5250  * Function:	H5T__conv_short_uchar
5251  *
5252  * Purpose:	Converts `short' to `unsigned char'
5253  *
5254  * Return:	Success:	non-negative
5255  *
5256  *		Failure:	negative
5257  *
5258  * Programmer:	Robb Matzke
5259  *		Friday, November 13, 1998
5260  *
5261  * Modifications:
5262  *
5263  *-------------------------------------------------------------------------
5264  */
5265 herr_t
H5T__conv_short_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5266 H5T__conv_short_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5267 		     size_t nelmts, size_t buf_stride,
5268                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5269 		     hid_t H5_ATTR_UNUSED dxpl_id)
5270 {
5271     H5T_CONV_Su(SHORT, UCHAR, short, unsigned char, -, UCHAR_MAX);
5272 }
5273 
5274 
5275 /*-------------------------------------------------------------------------
5276  * Function:	H5T__conv_ushort_schar
5277  *
5278  * Purpose:	Converts `unsigned short' to `signed char'
5279  *
5280  * Return:	Success:	non-negative
5281  *
5282  *		Failure:	negative
5283  *
5284  * Programmer:	Robb Matzke
5285  *		Friday, November 13, 1998
5286  *
5287  * Modifications:
5288  *
5289  *-------------------------------------------------------------------------
5290  */
5291 herr_t
H5T__conv_ushort_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5292 H5T__conv_ushort_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5293 		      size_t nelmts, size_t buf_stride,
5294                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5295                       hid_t H5_ATTR_UNUSED dxpl_id)
5296 {
5297     H5T_CONV_Us(USHORT, SCHAR, unsigned short, signed char, -, SCHAR_MAX);
5298 }
5299 
5300 
5301 /*-------------------------------------------------------------------------
5302  * Function:	H5T__conv_ushort_uchar
5303  *
5304  * Purpose:	Converts `unsigned short' to `unsigned char'
5305  *
5306  * Return:	Success:	non-negative
5307  *
5308  *		Failure:	negative
5309  *
5310  * Programmer:	Robb Matzke
5311  *		Friday, November 13, 1998
5312  *
5313  * Modifications:
5314  *
5315  *-------------------------------------------------------------------------
5316  */
5317 herr_t
H5T__conv_ushort_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5318 H5T__conv_ushort_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5319 		      size_t nelmts, size_t buf_stride,
5320                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5321                       hid_t H5_ATTR_UNUSED dxpl_id)
5322 {
5323     H5T_CONV_Uu(USHORT, UCHAR, unsigned short, unsigned char, -, UCHAR_MAX);
5324 }
5325 
5326 
5327 /*-------------------------------------------------------------------------
5328  * Function:	H5T__conv_short_ushort
5329  *
5330  * Purpose:	Converts `short' to `unsigned short'
5331  *
5332  * Return:	Success:	non-negative
5333  *
5334  *		Failure:	negative
5335  *
5336  * Programmer:	Robb Matzke
5337  *		Monday, November 16, 1998
5338  *
5339  * Modifications:
5340  *
5341  *-------------------------------------------------------------------------
5342  */
5343 herr_t
H5T__conv_short_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5344 H5T__conv_short_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5345 		      size_t nelmts, size_t buf_stride,
5346                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5347                       hid_t H5_ATTR_UNUSED dxpl_id)
5348 {
5349     H5T_CONV_su(SHORT, USHORT, short, unsigned short, -, -);
5350 }
5351 
5352 
5353 /*-------------------------------------------------------------------------
5354  * Function:	H5T__conv_ushort_short
5355  *
5356  * Purpose:	Converts `unsigned short' to `short'
5357  *
5358  * Return:	Success:	non-negative
5359  *
5360  *		Failure:	negative
5361  *
5362  * Programmer:	Robb Matzke
5363  *		Monday, November 16, 1998
5364  *
5365  * Modifications:
5366  *
5367  *-------------------------------------------------------------------------
5368  */
5369 herr_t
H5T__conv_ushort_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5370 H5T__conv_ushort_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5371 		      size_t nelmts, size_t buf_stride,
5372                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5373                       hid_t H5_ATTR_UNUSED dxpl_id)
5374 {
5375     H5T_CONV_us(USHORT, SHORT, unsigned short, short, -, SHRT_MAX);
5376 }
5377 
5378 
5379 /*-------------------------------------------------------------------------
5380  * Function:	H5T__conv_short_int
5381  *
5382  * Purpose:	Converts `short' to `int'
5383  *
5384  * Return:	Success:	non-negative
5385  *
5386  *		Failure:	negative
5387  *
5388  * Programmer:	Robb Matzke
5389  *		Friday, November 13, 1998
5390  *
5391  * Modifications:
5392  *
5393  *-------------------------------------------------------------------------
5394  */
5395 herr_t
H5T__conv_short_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5396 H5T__conv_short_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5397 		   size_t nelmts, size_t buf_stride,
5398                    size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5399 		   hid_t H5_ATTR_UNUSED dxpl_id)
5400 {
5401     H5T_CONV_sS(SHORT, INT, short, int, -, -);
5402 }
5403 
5404 
5405 /*-------------------------------------------------------------------------
5406  * Function:	H5T__conv_short_uint
5407  *
5408  * Purpose:	Converts `short' to `unsigned int'
5409  *
5410  * Return:	Success:	Non-negative
5411  *
5412  *		Failure:	Negative
5413  *
5414  * Programmer:	Robb Matzke
5415  *		Friday, November 13, 1998
5416  *
5417  * Modifications:
5418  *
5419  *-------------------------------------------------------------------------
5420  */
5421 herr_t
H5T__conv_short_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5422 H5T__conv_short_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5423 		    size_t nelmts, size_t buf_stride,
5424                     size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5425 		    hid_t H5_ATTR_UNUSED dxpl_id)
5426 {
5427     H5T_CONV_sU(SHORT, UINT, short, unsigned, -, -);
5428 }
5429 
5430 
5431 /*-------------------------------------------------------------------------
5432  * Function:	H5T__conv_ushort_int
5433  *
5434  * Purpose:	Converts `unsigned short' to `int'
5435  *
5436  * Return:	Success:	Non-negative
5437  *
5438  *		Failure:	Negative
5439  *
5440  * Programmer:	Robb Matzke
5441  *		Friday, November 13, 1998
5442  *
5443  * Modifications:
5444  *
5445  *-------------------------------------------------------------------------
5446  */
5447 herr_t
H5T__conv_ushort_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5448 H5T__conv_ushort_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5449 		    size_t nelmts, size_t buf_stride,
5450                     size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5451 		    hid_t H5_ATTR_UNUSED dxpl_id)
5452 {
5453     H5T_CONV_uS(USHORT, INT, unsigned short, int, -, INT_MAX);
5454 }
5455 
5456 
5457 /*-------------------------------------------------------------------------
5458  * Function:	H5T__conv_ushort_uint
5459  *
5460  * Purpose:	Converts `unsigned short' to `unsigned int'
5461  *
5462  * Return:	Success:	non-negative
5463  *
5464  *		Failure:	negative
5465  *
5466  * Programmer:	Robb Matzke
5467  *		Friday, November 13, 1998
5468  *
5469  * Modifications:
5470  *
5471  *-------------------------------------------------------------------------
5472  */
5473 herr_t
H5T__conv_ushort_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5474 H5T__conv_ushort_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5475 		     size_t nelmts, size_t buf_stride,
5476                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5477 		     hid_t H5_ATTR_UNUSED dxpl_id)
5478 {
5479     H5T_CONV_uU(USHORT, UINT, unsigned short, unsigned, -, -);
5480 }
5481 
5482 
5483 /*-------------------------------------------------------------------------
5484  * Function:	H5T__conv_short_long
5485  *
5486  * Purpose:	Converts `short' to `long'
5487  *
5488  * Return:	Success:	non-negative
5489  *
5490  *		Failure:	negative
5491  *
5492  * Programmer:	Robb Matzke
5493  *		Friday, November 13, 1998
5494  *
5495  * Modifications:
5496  *
5497  *-------------------------------------------------------------------------
5498  */
5499 herr_t
H5T__conv_short_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5500 H5T__conv_short_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5501 		    size_t nelmts, size_t buf_stride,
5502                     size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5503 		    hid_t H5_ATTR_UNUSED dxpl_id)
5504 {
5505     H5T_CONV_sS(SHORT, LONG, short, long, -, -);
5506 }
5507 
5508 
5509 /*-------------------------------------------------------------------------
5510  * Function:	H5T__conv_short_ulong
5511  *
5512  * Purpose:	Converts `short' to `unsigned long'
5513  *
5514  * Return:	Success:	Non-negative
5515  *
5516  *		Failure:	Negative
5517  *
5518  * Programmer:	Robb Matzke
5519  *		Friday, November 13, 1998
5520  *
5521  * Modifications:
5522  *
5523  *-------------------------------------------------------------------------
5524  */
5525 herr_t
H5T__conv_short_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5526 H5T__conv_short_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5527 		     size_t nelmts, size_t buf_stride,
5528                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5529 		     hid_t H5_ATTR_UNUSED dxpl_id)
5530 {
5531     H5T_CONV_sU(SHORT, ULONG, short, unsigned long, -, -);
5532 }
5533 
5534 
5535 /*-------------------------------------------------------------------------
5536  * Function:	H5T__conv_ushort_long
5537  *
5538  * Purpose:	Converts `unsigned short' to `long'
5539  *
5540  * Return:	Success:	Non-negative
5541  *
5542  *		Failure:	Negative
5543  *
5544  * Programmer:	Robb Matzke
5545  *		Friday, November 13, 1998
5546  *
5547  * Modifications:
5548  *
5549  *-------------------------------------------------------------------------
5550  */
5551 herr_t
H5T__conv_ushort_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5552 H5T__conv_ushort_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5553 		     size_t nelmts, size_t buf_stride,
5554                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5555 		     hid_t H5_ATTR_UNUSED dxpl_id)
5556 {
5557     H5T_CONV_uS(USHORT, LONG, unsigned short, long, -, LONG_MAX);
5558 }
5559 
5560 
5561 /*-------------------------------------------------------------------------
5562  * Function:	H5T__conv_ushort_ulong
5563  *
5564  * Purpose:	Converts `unsigned short' to `unsigned long'
5565  *
5566  * Return:	Success:	non-negative
5567  *
5568  *		Failure:	negative
5569  *
5570  * Programmer:	Robb Matzke
5571  *		Friday, November 13, 1998
5572  *
5573  * Modifications:
5574  *
5575  *-------------------------------------------------------------------------
5576  */
5577 herr_t
H5T__conv_ushort_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5578 H5T__conv_ushort_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5579 		      size_t nelmts, size_t buf_stride,
5580                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5581                       hid_t H5_ATTR_UNUSED dxpl_id)
5582 {
5583     H5T_CONV_uU(USHORT, ULONG, unsigned short, unsigned long, -, -);
5584 }
5585 
5586 
5587 /*-------------------------------------------------------------------------
5588  * Function:	H5T__conv_short_llong
5589  *
5590  * Purpose:	Converts `short' to `long long'
5591  *
5592  * Return:	Success:	Non-negative
5593  *
5594  *		Failure:	Negative
5595  *
5596  * Programmer:	Robb Matzke
5597  *		Friday, November 13, 1998
5598  *
5599  * Modifications:
5600  *
5601  *-------------------------------------------------------------------------
5602  */
5603 herr_t
H5T__conv_short_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5604 H5T__conv_short_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5605 		     size_t nelmts, size_t buf_stride,
5606                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5607 		     hid_t H5_ATTR_UNUSED dxpl_id)
5608 {
5609     H5T_CONV_sS(SHORT, LLONG, short, long long, -, -);
5610 }
5611 
5612 
5613 /*-------------------------------------------------------------------------
5614  * Function:	H5T__conv_short_ullong
5615  *
5616  * Purpose:	Converts `short' to `unsigned long long'
5617  *
5618  * Return:	Success:	Non-negative
5619  *
5620  *		Failure:	Negative
5621  *
5622  * Programmer:	Robb Matzke
5623  *		Friday, November 13, 1998
5624  *
5625  * Modifications:
5626  *
5627  *-------------------------------------------------------------------------
5628  */
5629 herr_t
H5T__conv_short_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5630 H5T__conv_short_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5631 		      size_t nelmts, size_t buf_stride,
5632                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5633                       hid_t H5_ATTR_UNUSED dxpl_id)
5634 {
5635     H5T_CONV_sU(SHORT, ULLONG, short, unsigned long long, -, -);
5636 }
5637 
5638 
5639 /*-------------------------------------------------------------------------
5640  * Function:	H5T__conv_ushort_llong
5641  *
5642  * Purpose:	Converts `unsigned short' to `long long'
5643  *
5644  * Return:	Success:	Non-negative
5645  *
5646  *		Failure:	Negative
5647  *
5648  * Programmer:	Robb Matzke
5649  *		Friday, November 13, 1998
5650  *
5651  * Modifications:
5652  *
5653  *-------------------------------------------------------------------------
5654  */
5655 herr_t
H5T__conv_ushort_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5656 H5T__conv_ushort_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5657 		      size_t nelmts, size_t buf_stride,
5658                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5659                       hid_t H5_ATTR_UNUSED dxpl_id)
5660 {
5661     H5T_CONV_uS(USHORT, LLONG, unsigned short, long long, -, LLONG_MAX);
5662 }
5663 
5664 
5665 /*-------------------------------------------------------------------------
5666  * Function:	H5T__conv_ushort_ullong
5667  *
5668  * Purpose:	Converts `unsigned short' to `unsigned long long'
5669  *
5670  * Return:	Success:	Non-negative
5671  *
5672  *		Failure:	Negative
5673  *
5674  * Programmer:	Robb Matzke
5675  *		Friday, November 13, 1998
5676  *
5677  * Modifications:
5678  *
5679  *-------------------------------------------------------------------------
5680  */
5681 herr_t
H5T__conv_ushort_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5682 H5T__conv_ushort_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5683 		       size_t nelmts, size_t buf_stride,
5684                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5685                        hid_t H5_ATTR_UNUSED dxpl_id)
5686 {
5687     H5T_CONV_uU(USHORT, ULLONG, unsigned short, unsigned long long, -, -);
5688 }
5689 
5690 
5691 /*-------------------------------------------------------------------------
5692  * Function:	H5T__conv_int_schar
5693  *
5694  * Purpose:	Converts `int' to `signed char'
5695  *
5696  * Return:	Success:	non-negative
5697  *
5698  *		Failure:	negative
5699  *
5700  * Programmer:	Robb Matzke
5701  *		Friday, November 13, 1998
5702  *
5703  * Modifications:
5704  *
5705  *-------------------------------------------------------------------------
5706  */
5707 herr_t
H5T__conv_int_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5708 H5T__conv_int_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5709 		   size_t nelmts, size_t buf_stride,
5710                    size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5711 		   hid_t H5_ATTR_UNUSED dxpl_id)
5712 {
5713     H5T_CONV_Ss(INT, SCHAR, int, signed char, SCHAR_MIN, SCHAR_MAX);
5714 }
5715 
5716 
5717 /*-------------------------------------------------------------------------
5718  * Function:	H5T__conv_int_uchar
5719  *
5720  * Purpose:	Converts `int' to `unsigned char'
5721  *
5722  * Return:	Success:	non-negative
5723  *
5724  *		Failure:	negative
5725  *
5726  * Programmer:	Robb Matzke
5727  *		Friday, November 13, 1998
5728  *
5729  * Modifications:
5730  *
5731  *-------------------------------------------------------------------------
5732  */
5733 herr_t
H5T__conv_int_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5734 H5T__conv_int_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5735 		   size_t nelmts, size_t buf_stride,
5736                    size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5737 		   hid_t H5_ATTR_UNUSED dxpl_id)
5738 {
5739     H5T_CONV_Su(INT, UCHAR, int, unsigned char, -, UCHAR_MAX);
5740 }
5741 
5742 
5743 /*-------------------------------------------------------------------------
5744  * Function:	H5T__conv_uint_schar
5745  *
5746  * Purpose:	Converts `unsigned int' to `signed char'
5747  *
5748  * Return:	Success:	non-negative
5749  *
5750  *		Failure:	negative
5751  *
5752  * Programmer:	Robb Matzke
5753  *		Friday, November 13, 1998
5754  *
5755  * Modifications:
5756  *
5757  *-------------------------------------------------------------------------
5758  */
5759 herr_t
H5T__conv_uint_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5760 H5T__conv_uint_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5761 		    size_t nelmts, size_t buf_stride,
5762                     size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5763 		    hid_t H5_ATTR_UNUSED dxpl_id)
5764 {
5765     H5T_CONV_Us(UINT, SCHAR, unsigned, signed char, -, SCHAR_MAX);
5766 }
5767 
5768 
5769 /*-------------------------------------------------------------------------
5770  * Function:	H5T__conv_uint_uchar
5771  *
5772  * Purpose:	Converts `unsigned int' to `unsigned char'
5773  *
5774  * Return:	Success:	non-negative
5775  *
5776  *		Failure:	negative
5777  *
5778  * Programmer:	Robb Matzke
5779  *		Friday, November 13, 1998
5780  *
5781  * Modifications:
5782  *
5783  *-------------------------------------------------------------------------
5784  */
5785 herr_t
H5T__conv_uint_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5786 H5T__conv_uint_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5787 		    size_t nelmts, size_t buf_stride,
5788                     size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5789 		    hid_t H5_ATTR_UNUSED dxpl_id)
5790 {
5791     H5T_CONV_Uu(UINT, UCHAR, unsigned, unsigned char, -, UCHAR_MAX);
5792 }
5793 
5794 
5795 /*-------------------------------------------------------------------------
5796  * Function:	H5T__conv_int_short
5797  *
5798  * Purpose:	Converts `int' to `short'
5799  *
5800  * Return:	Success:	non-negative
5801  *
5802  *		Failure:	negative
5803  *
5804  * Programmer:	Robb Matzke
5805  *		Friday, November 13, 1998
5806  *
5807  * Modifications:
5808  *
5809  *-------------------------------------------------------------------------
5810  */
5811 herr_t
H5T__conv_int_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5812 H5T__conv_int_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5813 		   size_t nelmts, size_t buf_stride,
5814                    size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5815 		   hid_t H5_ATTR_UNUSED dxpl_id)
5816 {
5817     H5T_CONV_Ss(INT, SHORT, int, short, SHRT_MIN, SHRT_MAX);
5818 }
5819 
5820 
5821 /*-------------------------------------------------------------------------
5822  * Function:	H5T__conv_int_ushort
5823  *
5824  * Purpose:	Converts `int' to `unsigned short'
5825  *
5826  * Return:	Success:	non-negative
5827  *
5828  *		Failure:	negative
5829  *
5830  * Programmer:	Robb Matzke
5831  *		Friday, November 13, 1998
5832  *
5833  * Modifications:
5834  *
5835  *-------------------------------------------------------------------------
5836  */
5837 herr_t
H5T__conv_int_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5838 H5T__conv_int_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5839 		    size_t nelmts, size_t buf_stride,
5840                     size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5841 		    hid_t H5_ATTR_UNUSED dxpl_id)
5842 {
5843     H5T_CONV_Su(INT, USHORT, int, unsigned short, -, USHRT_MAX);
5844 }
5845 
5846 
5847 /*-------------------------------------------------------------------------
5848  * Function:	H5T__conv_uint_short
5849  *
5850  * Purpose:	Converts `unsigned int' to `short'
5851  *
5852  * Return:	Success:	non-negative
5853  *
5854  *		Failure:	negative
5855  *
5856  * Programmer:	Robb Matzke
5857  *		Friday, November 13, 1998
5858  *
5859  * Modifications:
5860  *
5861  *-------------------------------------------------------------------------
5862  */
5863 herr_t
H5T__conv_uint_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5864 H5T__conv_uint_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5865 		    size_t nelmts, size_t buf_stride,
5866                     size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5867 		    hid_t H5_ATTR_UNUSED dxpl_id)
5868 {
5869     H5T_CONV_Us(UINT, SHORT, unsigned, short, -, SHRT_MAX);
5870 }
5871 
5872 
5873 /*-------------------------------------------------------------------------
5874  * Function:	H5T__conv_uint_ushort
5875  *
5876  * Purpose:	Converts `unsigned int' to `unsigned short'
5877  *
5878  * Return:	Success:	non-negative
5879  *
5880  *		Failure:	negative
5881  *
5882  * Programmer:	Robb Matzke
5883  *		Friday, November 13, 1998
5884  *
5885  * Modifications:
5886  *
5887  *-------------------------------------------------------------------------
5888  */
5889 herr_t
H5T__conv_uint_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5890 H5T__conv_uint_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5891 		     size_t nelmts, size_t buf_stride,
5892                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
5893 		     hid_t H5_ATTR_UNUSED dxpl_id)
5894 {
5895     H5T_CONV_Uu(UINT, USHORT, unsigned, unsigned short, -, USHRT_MAX);
5896 }
5897 
5898 
5899 /*-------------------------------------------------------------------------
5900  * Function:	H5T__conv_int_uint
5901  *
5902  * Purpose:	Converts `int' to `unsigned int'
5903  *
5904  * Return:	Success:	non-negative
5905  *
5906  *		Failure:	negative
5907  *
5908  * Programmer:	Robb Matzke
5909  *		Monday, November 16, 1998
5910  *
5911  * Modifications:
5912  *
5913  *-------------------------------------------------------------------------
5914  */
5915 herr_t
H5T__conv_int_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5916 H5T__conv_int_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5917 		  size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
5918                   void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
5919 {
5920     H5T_CONV_su(INT, UINT, int, unsigned, -, -);
5921 }
5922 
5923 
5924 /*-------------------------------------------------------------------------
5925  * Function:	H5T__conv_uint_int
5926  *
5927  * Purpose:	Converts `unsigned int' to `int'
5928  *
5929  * Return:	Success:	non-negative
5930  *
5931  *		Failure:	negative
5932  *
5933  * Programmer:	Robb Matzke
5934  *		Monday, November 16, 1998
5935  *
5936  * Modifications:
5937  *
5938  *-------------------------------------------------------------------------
5939  */
5940 herr_t
H5T__conv_uint_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5941 H5T__conv_uint_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5942 		  size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
5943                   void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
5944 {
5945     H5T_CONV_us(UINT, INT, unsigned, int, -, INT_MAX);
5946 }
5947 
5948 
5949 /*-------------------------------------------------------------------------
5950  * Function:	H5T__conv_int_long
5951  *
5952  * Purpose:	Converts `int' to `long'
5953  *
5954  * Return:	Success:	non-negative
5955  *
5956  *		Failure:	negative
5957  *
5958  * Programmer:	Robb Matzke
5959  *		Friday, November 13, 1998
5960  *
5961  * Modifications:
5962  *
5963  *-------------------------------------------------------------------------
5964  */
5965 herr_t
H5T__conv_int_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5966 H5T__conv_int_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5967 		  size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
5968                   void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
5969 {
5970     H5T_CONV_sS(INT, LONG, int, long, -, -);
5971 }
5972 
5973 
5974 /*-------------------------------------------------------------------------
5975  * Function:	H5T__conv_int_ulong
5976  *
5977  * Purpose:	Converts `int' to `unsigned long'
5978  *
5979  * Return:	Success:	Non-negative
5980  *
5981  *		Failure:	Negative
5982  *
5983  * Programmer:	Robb Matzke
5984  *		Friday, November 13, 1998
5985  *
5986  * Modifications:
5987  *
5988  *-------------------------------------------------------------------------
5989  */
5990 herr_t
H5T__conv_int_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)5991 H5T__conv_int_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
5992 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
5993                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
5994 {
5995     H5T_CONV_sU(INT, LONG, int, unsigned long, -, -);
5996 }
5997 
5998 
5999 /*-------------------------------------------------------------------------
6000  * Function:	H5T__conv_uint_long
6001  *
6002  * Purpose:	Converts `unsigned int' to `long'
6003  *
6004  * Return:	Success:	Non-negative
6005  *
6006  *		Failure:	Negative
6007  *
6008  * Programmer:	Robb Matzke
6009  *		Friday, November 13, 1998
6010  *
6011  * Modifications:
6012  *
6013  *-------------------------------------------------------------------------
6014  */
6015 herr_t
H5T__conv_uint_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6016 H5T__conv_uint_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6017 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6018                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6019 {
6020     H5T_CONV_uS(UINT, LONG, unsigned, long, -, LONG_MAX);
6021 }
6022 
6023 
6024 /*-------------------------------------------------------------------------
6025  * Function:	H5T__conv_uint_ulong
6026  *
6027  * Purpose:	Converts `unsigned int' to `unsigned long'
6028  *
6029  * Return:	Success:	non-negative
6030  *
6031  *		Failure:	negative
6032  *
6033  * Programmer:	Robb Matzke
6034  *		Friday, November 13, 1998
6035  *
6036  * Modifications:
6037  *
6038  *-------------------------------------------------------------------------
6039  */
6040 herr_t
H5T__conv_uint_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6041 H5T__conv_uint_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6042 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6043                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6044 {
6045     H5T_CONV_uU(UINT, ULONG, unsigned, unsigned long, -, -);
6046 }
6047 
6048 
6049 /*-------------------------------------------------------------------------
6050  * Function:	H5T__conv_int_llong
6051  *
6052  * Purpose:	Converts `int' to `long long'
6053  *
6054  * Return:	Success:	Non-negative
6055  *
6056  *		Failure:	Negative
6057  *
6058  * Programmer:	Robb Matzke
6059  *		Friday, November 13, 1998
6060  *
6061  * Modifications:
6062  *
6063  *-------------------------------------------------------------------------
6064  */
6065 herr_t
H5T__conv_int_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6066 H5T__conv_int_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6067 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6068                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6069 {
6070     H5T_CONV_sS(INT, LLONG, int, long long, -, -);
6071 }
6072 
6073 
6074 /*-------------------------------------------------------------------------
6075  * Function:	H5T__conv_int_ullong
6076  *
6077  * Purpose:	Converts `int' to `unsigned long long'
6078  *
6079  * Return:	Success:	Non-negative
6080  *
6081  *		Failure:	Negative
6082  *
6083  * Programmer:	Robb Matzke
6084  *		Friday, November 13, 1998
6085  *
6086  * Modifications:
6087  *
6088  *-------------------------------------------------------------------------
6089  */
6090 herr_t
H5T__conv_int_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6091 H5T__conv_int_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6092 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6093                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6094 {
6095     H5T_CONV_sU(INT, ULLONG, int, unsigned long long, -, -);
6096 }
6097 
6098 
6099 /*-------------------------------------------------------------------------
6100  * Function:	H5T__conv_uint_llong
6101  *
6102  * Purpose:	Converts `unsigned int' to `long long'
6103  *
6104  * Return:	Success:	Non-negative
6105  *
6106  *		Failure:	Negative
6107  *
6108  * Programmer:	Robb Matzke
6109  *		Friday, November 13, 1998
6110  *
6111  * Modifications:
6112  *
6113  *-------------------------------------------------------------------------
6114  */
6115 herr_t
H5T__conv_uint_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6116 H5T__conv_uint_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6117 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6118                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6119 {
6120     H5T_CONV_uS(UINT, LLONG, unsigned, long long, -, LLONG_MAX);
6121 }
6122 
6123 
6124 /*-------------------------------------------------------------------------
6125  * Function:	H5T__conv_uint_ullong
6126  *
6127  * Purpose:	Converts `unsigned int' to `unsigned long long'
6128  *
6129  * Return:	Success:	Non-negative
6130  *
6131  *		Failure:	Negative
6132  *
6133  * Programmer:	Robb Matzke
6134  *		Friday, November 13, 1998
6135  *
6136  * Modifications:
6137  *
6138  *-------------------------------------------------------------------------
6139  */
6140 herr_t
H5T__conv_uint_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6141 H5T__conv_uint_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6142 		     size_t nelmts, size_t buf_stride,
6143                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6144 		     hid_t H5_ATTR_UNUSED dxpl_id)
6145 {
6146     H5T_CONV_uU(UINT, ULLONG, unsigned, unsigned long long, -, -);
6147 }
6148 
6149 
6150 /*-------------------------------------------------------------------------
6151  * Function:	H5T__conv_long_schar
6152  *
6153  * Purpose:	Converts `long' to `signed char'
6154  *
6155  * Return:	Success:	non-negative
6156  *
6157  *		Failure:	negative
6158  *
6159  * Programmer:	Robb Matzke
6160  *		Friday, November 13, 1998
6161  *
6162  * Modifications:
6163  *
6164  *-------------------------------------------------------------------------
6165  */
6166 herr_t
H5T__conv_long_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6167 H5T__conv_long_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6168 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6169                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6170 {
6171     H5T_CONV_Ss(LONG, SCHAR, long, signed char, SCHAR_MIN, SCHAR_MAX);
6172 }
6173 
6174 
6175 /*-------------------------------------------------------------------------
6176  * Function:	H5T__conv_long_uchar
6177  *
6178  * Purpose:	Converts `long' to `unsigned char'
6179  *
6180  * Return:	Success:	non-negative
6181  *
6182  *		Failure:	negative
6183  *
6184  * Programmer:	Robb Matzke
6185  *		Friday, November 13, 1998
6186  *
6187  * Modifications:
6188  *
6189  *-------------------------------------------------------------------------
6190  */
6191 herr_t
H5T__conv_long_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6192 H5T__conv_long_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6193 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6194                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6195 {
6196     H5T_CONV_Su(LONG, UCHAR, long, unsigned char, -, UCHAR_MAX);
6197 }
6198 
6199 
6200 /*-------------------------------------------------------------------------
6201  * Function:	H5T__conv_ulong_schar
6202  *
6203  * Purpose:	Converts `unsigned long' to `signed char'
6204  *
6205  * Return:	Success:	non-negative
6206  *
6207  *		Failure:	negative
6208  *
6209  * Programmer:	Robb Matzke
6210  *		Friday, November 13, 1998
6211  *
6212  * Modifications:
6213  *
6214  *-------------------------------------------------------------------------
6215  */
6216 herr_t
H5T__conv_ulong_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6217 H5T__conv_ulong_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6218 		     size_t nelmts, size_t buf_stride,
6219                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6220 		     hid_t H5_ATTR_UNUSED dxpl_id)
6221 {
6222     H5T_CONV_Us(ULONG, SCHAR, unsigned long, signed char, -, SCHAR_MAX);
6223 }
6224 
6225 
6226 /*-------------------------------------------------------------------------
6227  * Function:	H5T__conv_ulong_uchar
6228  *
6229  * Purpose:	Converts `unsigned long' to `unsigned char'
6230  *
6231  * Return:	Success:	non-negative
6232  *
6233  *		Failure:	negative
6234  *
6235  * Programmer:	Robb Matzke
6236  *		Friday, November 13, 1998
6237  *
6238  * Modifications:
6239  *
6240  *-------------------------------------------------------------------------
6241  */
6242 herr_t
H5T__conv_ulong_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6243 H5T__conv_ulong_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6244 		     size_t nelmts, size_t buf_stride,
6245                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6246 		     hid_t H5_ATTR_UNUSED dxpl_id)
6247 {
6248     H5T_CONV_Uu(ULONG, UCHAR, unsigned long, unsigned char, -, UCHAR_MAX);
6249 }
6250 
6251 
6252 /*-------------------------------------------------------------------------
6253  * Function:	H5T__conv_long_short
6254  *
6255  * Purpose:	Converts `long' to `short'
6256  *
6257  * Return:	Success:	non-negative
6258  *
6259  *		Failure:	negative
6260  *
6261  * Programmer:	Robb Matzke
6262  *		Friday, November 13, 1998
6263  *
6264  * Modifications:
6265  *
6266  *-------------------------------------------------------------------------
6267  */
6268 herr_t
H5T__conv_long_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6269 H5T__conv_long_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6270 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6271                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6272 {
6273     H5T_CONV_Ss(LONG, SHORT, long, short, SHRT_MIN, SHRT_MAX);
6274 }
6275 
6276 
6277 /*-------------------------------------------------------------------------
6278  * Function:	H5T__conv_long_ushort
6279  *
6280  * Purpose:	Converts `long' to `unsigned short'
6281  *
6282  * Return:	Success:	non-negative
6283  *
6284  *		Failure:	negative
6285  *
6286  * Programmer:	Robb Matzke
6287  *		Friday, November 13, 1998
6288  *
6289  * Modifications:
6290  *
6291  *-------------------------------------------------------------------------
6292  */
6293 herr_t
H5T__conv_long_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6294 H5T__conv_long_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6295 		     size_t nelmts, size_t buf_stride,
6296                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6297 		     hid_t H5_ATTR_UNUSED dxpl_id)
6298 {
6299     H5T_CONV_Su(LONG, USHORT, long, unsigned short, -, USHRT_MAX);
6300 }
6301 
6302 
6303 /*-------------------------------------------------------------------------
6304  * Function:	H5T__conv_ulong_short
6305  *
6306  * Purpose:	Converts `unsigned long' to `short'
6307  *
6308  * Return:	Success:	non-negative
6309  *
6310  *		Failure:	negative
6311  *
6312  * Programmer:	Robb Matzke
6313  *		Friday, November 13, 1998
6314  *
6315  * Modifications:
6316  *
6317  *-------------------------------------------------------------------------
6318  */
6319 herr_t
H5T__conv_ulong_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6320 H5T__conv_ulong_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6321 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6322                      void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6323 {
6324     H5T_CONV_Us(ULONG, SHORT, unsigned long, short, -, SHRT_MAX);
6325 }
6326 
6327 
6328 /*-------------------------------------------------------------------------
6329  * Function:	H5T__conv_ulong_ushort
6330  *
6331  * Purpose:	Converts `unsigned long' to `unsigned short'
6332  *
6333  * Return:	Success:	non-negative
6334  *
6335  *		Failure:	negative
6336  *
6337  * Programmer:	Robb Matzke
6338  *		Friday, November 13, 1998
6339  *
6340  * Modifications:
6341  *
6342  *-------------------------------------------------------------------------
6343  */
6344 herr_t
H5T__conv_ulong_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6345 H5T__conv_ulong_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6346 		      size_t nelmts, size_t buf_stride,
6347                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6348                       hid_t H5_ATTR_UNUSED dxpl_id)
6349 {
6350     H5T_CONV_Uu(ULONG, USHORT, unsigned long, unsigned short, -, USHRT_MAX);
6351 }
6352 
6353 
6354 /*-------------------------------------------------------------------------
6355  * Function:	H5T__conv_long_int
6356  *
6357  * Purpose:	Converts `long' to `int'
6358  *
6359  * Return:	Success:	non-negative
6360  *
6361  *		Failure:	negative
6362  *
6363  * Programmer:	Robb Matzke
6364  *		Friday, November 13, 1998
6365  *
6366  * Modifications:
6367  *
6368  *-------------------------------------------------------------------------
6369  */
6370 herr_t
H5T__conv_long_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6371 H5T__conv_long_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6372 		  size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6373                   void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6374 {
6375     H5T_CONV_Ss(LONG, INT, long, int, INT_MIN, INT_MAX);
6376 }
6377 
6378 
6379 /*-------------------------------------------------------------------------
6380  * Function:	H5T__conv_long_uint
6381  *
6382  * Purpose:	Converts `long' to `unsigned int'
6383  *
6384  * Return:	Success:	non-negative
6385  *
6386  *		Failure:	negative
6387  *
6388  * Programmer:	Robb Matzke
6389  *		Friday, November 13, 1998
6390  *
6391  * Modifications:
6392  *
6393  *-------------------------------------------------------------------------
6394  */
6395 herr_t
H5T__conv_long_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6396 H5T__conv_long_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6397 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6398                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6399 {
6400     H5T_CONV_Su(LONG, UINT, long, unsigned, -, UINT_MAX);
6401 }
6402 
6403 
6404 /*-------------------------------------------------------------------------
6405  * Function:	H5T__conv_ulong_int
6406  *
6407  * Purpose:	Converts `unsigned long' to `int'
6408  *
6409  * Return:	Success:	non-negative
6410  *
6411  *		Failure:	negative
6412  *
6413  * Programmer:	Robb Matzke
6414  *		Friday, November 13, 1998
6415  *
6416  * Modifications:
6417  *
6418  *-------------------------------------------------------------------------
6419  */
6420 herr_t
H5T__conv_ulong_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6421 H5T__conv_ulong_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6422 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6423                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6424 {
6425     H5T_CONV_Us(ULONG, INT, unsigned long, int, -, INT_MAX);
6426 }
6427 
6428 
6429 /*-------------------------------------------------------------------------
6430  * Function:	H5T__conv_ulong_uint
6431  *
6432  * Purpose:	Converts `unsigned long' to `unsigned int'
6433  *
6434  * Return:	Success:	non-negative
6435  *
6436  *		Failure:	negative
6437  *
6438  * Programmer:	Robb Matzke
6439  *		Friday, November 13, 1998
6440  *
6441  * Modifications:
6442  *
6443  *-------------------------------------------------------------------------
6444  */
6445 herr_t
H5T__conv_ulong_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6446 H5T__conv_ulong_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6447 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6448                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6449 {
6450     H5T_CONV_Uu(ULONG, UINT, unsigned long, unsigned, -, UINT_MAX);
6451 }
6452 
6453 
6454 /*-------------------------------------------------------------------------
6455  * Function:	H5T__conv_long_ulong
6456  *
6457  * Purpose:	Converts `long' to `unsigned long'
6458  *
6459  * Return:	Success:	non-negative
6460  *
6461  *		Failure:	negative
6462  *
6463  * Programmer:	Robb Matzke
6464  *		Monday, November 16, 1998
6465  *
6466  * Modifications:
6467  *
6468  *-------------------------------------------------------------------------
6469  */
6470 herr_t
H5T__conv_long_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6471 H5T__conv_long_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6472 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6473                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6474 {
6475     H5T_CONV_su(LONG, ULONG, long, unsigned long, -, -);
6476 }
6477 
6478 
6479 /*-------------------------------------------------------------------------
6480  * Function:	H5T__conv_ulong_long
6481  *
6482  * Purpose:	Converts `unsigned long' to `long'
6483  *
6484  * Return:	Success:	non-negative
6485  *
6486  *		Failure:	negative
6487  *
6488  * Programmer:	Robb Matzke
6489  *		Monday, November 16, 1998
6490  *
6491  * Modifications:
6492  *
6493  *-------------------------------------------------------------------------
6494  */
6495 herr_t
H5T__conv_ulong_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6496 H5T__conv_ulong_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6497 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6498                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6499 {
6500     H5T_CONV_us(ULONG, LONG, unsigned long, long, -, LONG_MAX);
6501 }
6502 
6503 
6504 /*-------------------------------------------------------------------------
6505  * Function:	H5T__conv_long_llong
6506  *
6507  * Purpose:	Converts `long' to `long long'
6508  *
6509  * Return:	Success:	Non-negative
6510  *
6511  *		Failure:	Negative
6512  *
6513  * Programmer:	Robb Matzke
6514  *		Friday, November 13, 1998
6515  *
6516  * Modifications:
6517  *
6518  *-------------------------------------------------------------------------
6519  */
6520 herr_t
H5T__conv_long_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6521 H5T__conv_long_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6522 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6523                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6524 {
6525     H5T_CONV_sS(LONG, LLONG, long, long long, -, -);
6526 }
6527 
6528 
6529 /*-------------------------------------------------------------------------
6530  * Function:	H5T__conv_long_ullong
6531  *
6532  * Purpose:	Converts `long' to `unsigned long long'
6533  *
6534  * Return:	Success:	Non-negative
6535  *
6536  *		Failure:	Negative
6537  *
6538  * Programmer:	Robb Matzke
6539  *		Friday, November 13, 1998
6540  *
6541  * Modifications:
6542  *
6543  *-------------------------------------------------------------------------
6544  */
6545 herr_t
H5T__conv_long_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6546 H5T__conv_long_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6547 		     size_t nelmts, size_t buf_stride,
6548                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6549 		     hid_t H5_ATTR_UNUSED dxpl_id)
6550 {
6551     H5T_CONV_sU(LONG, ULLONG, long, unsigned long long, -, -);
6552 }
6553 
6554 
6555 /*-------------------------------------------------------------------------
6556  * Function:	H5T__conv_ulong_llong
6557  *
6558  * Purpose:	Converts `unsigned long' to `long long'
6559  *
6560  * Return:	Success:	Non-negative
6561  *
6562  *		Failure:	Negative
6563  *
6564  * Programmer:	Robb Matzke
6565  *		Friday, November 13, 1998
6566  *
6567  * Modifications:
6568  *
6569  *-------------------------------------------------------------------------
6570  */
6571 herr_t
H5T__conv_ulong_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6572 H5T__conv_ulong_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6573 		     size_t nelmts, size_t buf_stride,
6574                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6575 		     hid_t H5_ATTR_UNUSED dxpl_id)
6576 {
6577     H5T_CONV_uS(ULONG, LLONG, unsigned long, long long, -, LLONG_MAX);
6578 }
6579 
6580 
6581 /*-------------------------------------------------------------------------
6582  * Function:	H5T__conv_ulong_ullong
6583  *
6584  * Purpose:	Converts `unsigned long' to `unsigned long long'
6585  *
6586  * Return:	Success:	Non-negative
6587  *
6588  *		Failure:	Negative
6589  *
6590  * Programmer:	Robb Matzke
6591  *		Friday, November 13, 1998
6592  *
6593  * Modifications:
6594  *
6595  *-------------------------------------------------------------------------
6596  */
6597 herr_t
H5T__conv_ulong_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6598 H5T__conv_ulong_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6599 		      size_t nelmts, size_t buf_stride,
6600                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6601                       hid_t H5_ATTR_UNUSED dxpl_id)
6602 {
6603     H5T_CONV_uU(ULONG, ULLONG, unsigned long, unsigned long long, -, -);
6604 }
6605 
6606 
6607 /*-------------------------------------------------------------------------
6608  * Function:	H5T__conv_llong_schar
6609  *
6610  * Purpose:	Converts `long long' to `signed char'
6611  *
6612  * Return:	Success:	Non-negative
6613  *
6614  *		Failure:	Negative
6615  *
6616  * Programmer:	Robb Matzke
6617  *		Friday, November 13, 1998
6618  *
6619  * Modifications:
6620  *
6621  *-------------------------------------------------------------------------
6622  */
6623 herr_t
H5T__conv_llong_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6624 H5T__conv_llong_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6625 		     size_t nelmts, size_t buf_stride,
6626                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6627 		     hid_t H5_ATTR_UNUSED dxpl_id)
6628 {
6629     H5T_CONV_Ss(LLONG, SCHAR, long long, signed char, SCHAR_MIN, SCHAR_MAX);
6630 }
6631 
6632 
6633 /*-------------------------------------------------------------------------
6634  * Function:	H5T__conv_llong_uchar
6635  *
6636  * Purpose:	Converts `long long' to `unsigned char'
6637  *
6638  * Return:	Success:	Non-negative
6639  *
6640  *		Failure:	Negative
6641  *
6642  * Programmer:	Robb Matzke
6643  *		Friday, November 13, 1998
6644  *
6645  * Modifications:
6646  *
6647  *-------------------------------------------------------------------------
6648  */
6649 herr_t
H5T__conv_llong_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6650 H5T__conv_llong_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6651 		     size_t nelmts, size_t buf_stride,
6652                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6653 		     hid_t H5_ATTR_UNUSED dxpl_id)
6654 {
6655     H5T_CONV_Su(LLONG, UCHAR, long long, unsigned char, -, UCHAR_MAX);
6656 }
6657 
6658 
6659 /*-------------------------------------------------------------------------
6660  * Function:	H5T__conv_ullong_schar
6661  *
6662  * Purpose:	Converts `unsigned long long' to `signed char'
6663  *
6664  * Return:	Success:	Non-negative
6665  *
6666  *		Failure:	Negative
6667  *
6668  * Programmer:	Robb Matzke
6669  *		Friday, November 13, 1998
6670  *
6671  * Modifications:
6672  *
6673  *-------------------------------------------------------------------------
6674  */
6675 herr_t
H5T__conv_ullong_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6676 H5T__conv_ullong_schar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6677 		      size_t nelmts, size_t buf_stride,
6678                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6679                       hid_t H5_ATTR_UNUSED dxpl_id)
6680 {
6681     H5T_CONV_Us(ULLONG, SCHAR, unsigned long long, signed char, -, SCHAR_MAX);
6682 }
6683 
6684 
6685 /*-------------------------------------------------------------------------
6686  * Function:	H5T__conv_ullong_uchar
6687  *
6688  * Purpose:	Converts `unsigned long long' to `unsigned char'
6689  *
6690  * Return:	Success:	Non-negative
6691  *
6692  *		Failure:	Negative
6693  *
6694  * Programmer:	Robb Matzke
6695  *		Friday, November 13, 1998
6696  *
6697  * Modifications:
6698  *
6699  *-------------------------------------------------------------------------
6700  */
6701 herr_t
H5T__conv_ullong_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6702 H5T__conv_ullong_uchar(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6703                       size_t nelmts, size_t buf_stride,
6704                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6705                       hid_t H5_ATTR_UNUSED dxpl_id)
6706 {
6707     H5T_CONV_Uu(ULLONG, UCHAR, unsigned long long, unsigned char, -, UCHAR_MAX);
6708 }
6709 
6710 
6711 /*-------------------------------------------------------------------------
6712  * Function:	H5T__conv_llong_short
6713  *
6714  * Purpose:	Converts `long long' to `short'
6715  *
6716  * Return:	Success:	Non-negative
6717  *
6718  *		Failure:	Negative
6719  *
6720  * Programmer:	Robb Matzke
6721  *		Friday, November 13, 1998
6722  *
6723  * Modifications:
6724  *
6725  *-------------------------------------------------------------------------
6726  */
6727 herr_t
H5T__conv_llong_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6728 H5T__conv_llong_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6729 		     size_t nelmts, size_t buf_stride,
6730                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6731 		     hid_t H5_ATTR_UNUSED dxpl_id)
6732 {
6733     H5T_CONV_Ss(LLONG, SHORT, long long, short, SHRT_MIN, SHRT_MAX);
6734 }
6735 
6736 
6737 /*-------------------------------------------------------------------------
6738  * Function:	H5T__conv_llong_ushort
6739  *
6740  * Purpose:	Converts `long long' to `unsigned short'
6741  *
6742  * Return:	Success:	Non-negative
6743  *
6744  *		Failure:	Negative
6745  *
6746  * Programmer:	Robb Matzke
6747  *		Friday, November 13, 1998
6748  *
6749  * Modifications:
6750  *
6751  *-------------------------------------------------------------------------
6752  */
6753 herr_t
H5T__conv_llong_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6754 H5T__conv_llong_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6755 		      size_t nelmts, size_t buf_stride,
6756                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6757                       hid_t H5_ATTR_UNUSED dxpl_id)
6758 {
6759     H5T_CONV_Su(LLONG, USHORT, long long, unsigned short, -, USHRT_MAX);
6760 }
6761 
6762 
6763 /*-------------------------------------------------------------------------
6764  * Function:	H5T__conv_ullong_short
6765  *
6766  * Purpose:	Converts `unsigned long long' to `short'
6767  *
6768  * Return:	Success:	Non-negative
6769  *
6770  *		Failure:	Negative
6771  *
6772  * Programmer:	Robb Matzke
6773  *		Friday, November 13, 1998
6774  *
6775  * Modifications:
6776  *
6777  *-------------------------------------------------------------------------
6778  */
6779 herr_t
H5T__conv_ullong_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6780 H5T__conv_ullong_short(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6781 		      size_t nelmts, size_t buf_stride,
6782                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6783                       hid_t H5_ATTR_UNUSED dxpl_id)
6784 {
6785     H5T_CONV_Us(ULLONG, SHORT, unsigned long long, short, -, SHRT_MAX);
6786 }
6787 
6788 
6789 /*-------------------------------------------------------------------------
6790  * Function:	H5T__conv_ullong_ushort
6791  *
6792  * Purpose:	Converts `unsigned long long' to `unsigned short'
6793  *
6794  * Return:	Success:	Non-negative
6795  *
6796  *		Failure:	Negative
6797  *
6798  * Programmer:	Robb Matzke
6799  *		Friday, November 13, 1998
6800  *
6801  * Modifications:
6802  *
6803  *-------------------------------------------------------------------------
6804  */
6805 herr_t
H5T__conv_ullong_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6806 H5T__conv_ullong_ushort(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6807 		       size_t nelmts, size_t buf_stride,
6808                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6809                        hid_t H5_ATTR_UNUSED dxpl_id)
6810 {
6811     H5T_CONV_Uu(ULLONG, USHORT, unsigned long long, unsigned short, -, USHRT_MAX);
6812 }
6813 
6814 
6815 /*-------------------------------------------------------------------------
6816  * Function:	H5T__conv_llong_int
6817  *
6818  * Purpose:	Converts `long long' to `int'
6819  *
6820  * Return:	Success:	Non-negative
6821  *
6822  *		Failure:	Negative
6823  *
6824  * Programmer:	Robb Matzke
6825  *		Friday, November 13, 1998
6826  *
6827  * Modifications:
6828  *
6829  *-------------------------------------------------------------------------
6830  */
6831 herr_t
H5T__conv_llong_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6832 H5T__conv_llong_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6833 		   size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6834                    void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6835 {
6836     H5T_CONV_Ss(LLONG, INT, long long, int, INT_MIN, INT_MAX);
6837 }
6838 
6839 
6840 /*-------------------------------------------------------------------------
6841  * Function:	H5T__conv_llong_uint
6842  *
6843  * Purpose:	Converts `long long' to `unsigned int'
6844  *
6845  * Return:	Success:	Non-negative
6846  *
6847  *		Failure:	Negative
6848  *
6849  * Programmer:	Robb Matzke
6850  *		Friday, November 13, 1998
6851  *
6852  * Modifications:
6853  *
6854  *-------------------------------------------------------------------------
6855  */
6856 herr_t
H5T__conv_llong_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6857 H5T__conv_llong_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6858 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6859                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6860 {
6861     H5T_CONV_Su(LLONG, UINT, long long, unsigned, -, UINT_MAX);
6862 }
6863 
6864 
6865 /*-------------------------------------------------------------------------
6866  * Function:	H5T__conv_ullong_int
6867  *
6868  * Purpose:	Converts `unsigned long long' to `int'
6869  *
6870  * Return:	Success:	Non-negative
6871  *
6872  *		Failure:	Negative
6873  *
6874  * Programmer:	Robb Matzke
6875  *		Friday, November 13, 1998
6876  *
6877  * Modifications:
6878  *
6879  *-------------------------------------------------------------------------
6880  */
6881 herr_t
H5T__conv_ullong_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6882 H5T__conv_ullong_int(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6883 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6884                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6885 {
6886     H5T_CONV_Us(ULLONG, INT, unsigned long long, int, -, INT_MAX);
6887 }
6888 
6889 
6890 /*-------------------------------------------------------------------------
6891  * Function:	H5T__conv_ullong_uint
6892  *
6893  * Purpose:	Converts `unsigned long long' to `unsigned int'
6894  *
6895  * Return:	Success:	Non-negative
6896  *
6897  *		Failure:	Negative
6898  *
6899  * Programmer:	Robb Matzke
6900  *		Friday, November 13, 1998
6901  *
6902  * Modifications:
6903  *
6904  *-------------------------------------------------------------------------
6905  */
6906 herr_t
H5T__conv_ullong_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6907 H5T__conv_ullong_uint(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6908 		     size_t nelmts, size_t buf_stride,
6909                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6910 		     hid_t H5_ATTR_UNUSED dxpl_id)
6911 {
6912     H5T_CONV_Uu(ULLONG, UINT, unsigned long long, unsigned, -, UINT_MAX);
6913 }
6914 
6915 
6916 /*-------------------------------------------------------------------------
6917  * Function:	H5T__conv_llong_long
6918  *
6919  * Purpose:	Converts `long long' to `long'
6920  *
6921  * Return:	Success:	Non-negative
6922  *
6923  *		Failure:	Negative
6924  *
6925  * Programmer:	Robb Matzke
6926  *		Friday, November 13, 1998
6927  *
6928  * Modifications:
6929  *
6930  *-------------------------------------------------------------------------
6931  */
6932 herr_t
H5T__conv_llong_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6933 H5T__conv_llong_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6934 		    size_t nelmts, size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride,
6935                     void *buf, void H5_ATTR_UNUSED *bkg, hid_t H5_ATTR_UNUSED dxpl_id)
6936 {
6937     H5T_CONV_Ss(LLONG, LONG, long long, long, LONG_MIN, LONG_MAX);
6938 }
6939 
6940 
6941 /*-------------------------------------------------------------------------
6942  * Function:	H5T__conv_llong_ulong
6943  *
6944  * Purpose:	Converts `long long' to `unsigned long'
6945  *
6946  * Return:	Success:	Non-negative
6947  *
6948  *		Failure:	Negative
6949  *
6950  * Programmer:	Robb Matzke
6951  *		Friday, November 13, 1998
6952  *
6953  * Modifications:
6954  *
6955  *-------------------------------------------------------------------------
6956  */
6957 herr_t
H5T__conv_llong_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6958 H5T__conv_llong_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6959 		     size_t nelmts, size_t buf_stride,
6960                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6961 		     hid_t H5_ATTR_UNUSED dxpl_id)
6962 {
6963     H5T_CONV_Su(LLONG, ULONG, long long, unsigned long, -, ULONG_MAX);
6964 }
6965 
6966 
6967 /*-------------------------------------------------------------------------
6968  * Function:	H5T__conv_ullong_long
6969  *
6970  * Purpose:	Converts `unsigned long long' to `long'
6971  *
6972  * Return:	Success:	Non-negative
6973  *
6974  *		Failure:	Negative
6975  *
6976  * Programmer:	Robb Matzke
6977  *		Friday, November 13, 1998
6978  *
6979  * Modifications:
6980  *
6981  *-------------------------------------------------------------------------
6982  */
6983 herr_t
H5T__conv_ullong_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)6984 H5T__conv_ullong_long(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
6985 		     size_t nelmts, size_t buf_stride,
6986                      size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
6987 		     hid_t H5_ATTR_UNUSED dxpl_id)
6988 {
6989     H5T_CONV_Us(ULLONG, LONG, unsigned long long, long, -, LONG_MAX);
6990 }
6991 
6992 
6993 /*-------------------------------------------------------------------------
6994  * Function:	H5T__conv_ullong_ulong
6995  *
6996  * Purpose:	Converts `unsigned long long' to `unsigned long'
6997  *
6998  * Return:	Success:	Non-negative
6999  *
7000  *		Failure:	Negative
7001  *
7002  * Programmer:	Robb Matzke
7003  *		Friday, November 13, 1998
7004  *
7005  * Modifications:
7006  *
7007  *-------------------------------------------------------------------------
7008  */
7009 herr_t
H5T__conv_ullong_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7010 H5T__conv_ullong_ulong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7011 		      size_t nelmts, size_t buf_stride,
7012                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7013                       hid_t H5_ATTR_UNUSED dxpl_id)
7014 {
7015     H5T_CONV_Uu(ULLONG, ULONG, unsigned long long, unsigned long, -, ULONG_MAX);
7016 }
7017 
7018 
7019 /*-------------------------------------------------------------------------
7020  * Function:	H5T__conv_llong_ullong
7021  *
7022  * Purpose:	Converts `long long' to `unsigned long long'
7023  *
7024  * Return:	Success:	non-negative
7025  *
7026  *		Failure:	negative
7027  *
7028  * Programmer:	Robb Matzke
7029  *		Monday, November 16, 1998
7030  *
7031  * Modifications:
7032  *
7033  *-------------------------------------------------------------------------
7034  */
7035 herr_t
H5T__conv_llong_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7036 H5T__conv_llong_ullong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7037 		      size_t nelmts, size_t buf_stride,
7038                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7039                       hid_t H5_ATTR_UNUSED dxpl_id)
7040 {
7041     H5T_CONV_su(LLONG, ULLONG, long long, unsigned long long, -, -);
7042 }
7043 
7044 
7045 /*-------------------------------------------------------------------------
7046  * Function:	H5T__conv_ullong_llong
7047  *
7048  * Purpose:	Converts `unsigned long long' to `long long'
7049  *
7050  * Return:	Success:	non-negative
7051  *
7052  *		Failure:	negative
7053  *
7054  * Programmer:	Robb Matzke
7055  *		Monday, November 16, 1998
7056  *
7057  * Modifications:
7058  *
7059  *-------------------------------------------------------------------------
7060  */
7061 herr_t
H5T__conv_ullong_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7062 H5T__conv_ullong_llong(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7063 		      size_t nelmts, size_t buf_stride,
7064                       size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7065                       hid_t H5_ATTR_UNUSED dxpl_id)
7066 {
7067     H5T_CONV_us(ULLONG, LLONG, unsigned long long, long long, -, LLONG_MAX);
7068 }
7069 
7070 
7071 /*-------------------------------------------------------------------------
7072  * Function:	H5T__conv_float_double
7073  *
7074  * Purpose:	Convert native `float' to native `double' using hardware.
7075  *		This is a fast special case.
7076  *
7077  * Return:	Non-negative on success/Negative on failure
7078  *
7079  * Programmer:	Robb Matzke
7080  *		Tuesday, June 23, 1998
7081  *
7082  * Modifications:
7083  *		Robb Matzke, 1999-06-16
7084  *		Added support for non-zero strides. If BUF_STRIDE is non-zero
7085  *		then convert one value at each memory location advancing
7086  *		BUF_STRIDE bytes each time; otherwise assume both source and
7087  *		destination values are packed.
7088  *-------------------------------------------------------------------------
7089  */
7090 herr_t
H5T__conv_float_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7091 H5T__conv_float_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7092 		       size_t nelmts, size_t buf_stride,
7093                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7094                        hid_t H5_ATTR_UNUSED dxpl_id)
7095 {
7096     H5T_CONV_fF(FLOAT, DOUBLE, float, double, -, -);
7097 }
7098 
7099 
7100 /*-------------------------------------------------------------------------
7101  * Function:	H5T__conv_float_ldouble
7102  *
7103  * Purpose:	Convert native `float' to native `long double' using hardware.
7104  *		This is a fast special case.
7105  *
7106  * Return:	Non-negative on success/Negative on failure
7107  *
7108  * Programmer:	Raymond Lu
7109  *		Friday, Feb 25, 2005
7110  *
7111  * Modifications:
7112  *
7113  *-------------------------------------------------------------------------
7114  */
7115 #if H5_SIZEOF_LONG_DOUBLE != 0
7116 herr_t
H5T__conv_float_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7117 H5T__conv_float_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7118 		       size_t nelmts, size_t buf_stride,
7119                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7120                        hid_t H5_ATTR_UNUSED dxpl_id)
7121 {
7122     H5T_CONV_fF(FLOAT, LDOUBLE, float, long double, -, -);
7123 }
7124 #endif /* H5_SIZEOF_LONG_DOUBLE != 0 */
7125 
7126 
7127 /*-------------------------------------------------------------------------
7128  * Function:	H5T__conv_double_float
7129  *
7130  * Purpose:	Convert native `double' to native `float' using hardware.
7131  *		This is a fast special case.
7132  *
7133  * Return:	Non-negative on success/Negative on failure
7134  *
7135  * Programmer:	Robb Matzke
7136  *		Tuesday, June 23, 1998
7137  *
7138  * Modifications:
7139  *		Robb Matzke, 7 Jul 1998
7140  *		Added overflow handling.
7141  *
7142  *		Robb Matzke, 1999-06-16
7143  *		Added support for non-zero strides. If BUF_STRIDE is non-zero
7144  *		then convert one value at each memory location advancing
7145  *		BUF_STRIDE bytes each time; otherwise assume both source and
7146  *		destination values are packed.
7147  *-------------------------------------------------------------------------
7148  */
7149 herr_t
H5T__conv_double_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7150 H5T__conv_double_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7151 		       size_t nelmts, size_t buf_stride,
7152                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7153                        hid_t H5_ATTR_UNUSED dxpl_id)
7154 {
7155     H5T_CONV_Ff(DOUBLE, FLOAT, double, float, -FLT_MAX, FLT_MAX);
7156 }
7157 
7158 
7159 /*-------------------------------------------------------------------------
7160  * Function:	H5T__conv_double_ldouble
7161  *
7162  * Purpose:	Convert native `double' to native `long double' using hardware.
7163  *		This is a fast special case.
7164  *
7165  * Return:	Non-negative on success/Negative on failure
7166  *
7167  * Programmer:	Raymond Lu
7168  *		Friday, Feb 25, 2005
7169  *
7170  * Modifications:
7171  *
7172  *-------------------------------------------------------------------------
7173  */
7174 #if H5_SIZEOF_LONG_DOUBLE != 0
7175 herr_t
H5T__conv_double_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7176 H5T__conv_double_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7177 		       size_t nelmts, size_t buf_stride,
7178                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7179                        hid_t H5_ATTR_UNUSED dxpl_id)
7180 {
7181     H5T_CONV_fF(DOUBLE, LDOUBLE, double, long double, -, -);
7182 }
7183 #endif /* H5_SIZEOF_LONG_DOUBLE != 0 */
7184 
7185 
7186 /*-------------------------------------------------------------------------
7187  * Function:	H5T__conv_ldouble_float
7188  *
7189  * Purpose:	Convert native `long double' to native `float' using hardware.
7190  *		This is a fast special case.
7191  *
7192  * Return:	Non-negative on success/Negative on failure
7193  *
7194  * Programmer:	Raymond Lu
7195  *		Friday, Feb 25, 2005
7196  *
7197  * Modifications:
7198  *
7199  *-------------------------------------------------------------------------
7200  */
7201 #if H5_SIZEOF_LONG_DOUBLE != 0
7202 herr_t
H5T__conv_ldouble_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7203 H5T__conv_ldouble_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7204 		       size_t nelmts, size_t buf_stride,
7205                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7206                        hid_t H5_ATTR_UNUSED dxpl_id)
7207 {
7208     H5T_CONV_Ff(LDOUBLE, FLOAT, long double, float, -FLT_MAX, FLT_MAX);
7209 }
7210 #endif /* H5_SIZEOF_LONG_DOUBLE != 0 */
7211 
7212 
7213 /*-------------------------------------------------------------------------
7214  * Function:	H5T__conv_ldouble_double
7215  *
7216  * Purpose:	Convert native `long double' to native `double' using hardware.
7217  *		This is a fast special case.
7218  *
7219  * Return:	Non-negative on success/Negative on failure
7220  *
7221  * Programmer:	Raymond Lu
7222  *		Friday, Feb 25, 2005
7223  *
7224  * Modifications:
7225  *
7226  *-------------------------------------------------------------------------
7227  */
7228 #if H5_SIZEOF_LONG_DOUBLE != 0
7229 herr_t
H5T__conv_ldouble_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7230 H5T__conv_ldouble_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7231 		       size_t nelmts, size_t buf_stride,
7232                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7233                        hid_t H5_ATTR_UNUSED dxpl_id)
7234 {
7235     H5T_CONV_Ff(LDOUBLE, DOUBLE, long double, double, -DBL_MAX, DBL_MAX);
7236 }
7237 #endif /* H5_SIZEOF_LONG_DOUBLE != 0 */
7238 
7239 
7240 /*-------------------------------------------------------------------------
7241  * Function:	H5T__conv_schar_float
7242  *
7243  * Purpose:	Convert native signed char to native float using hardware.
7244  *		This is a fast special case.
7245  *
7246  * Return:	Non-negative on success/Negative on failure
7247  *
7248  * Programmer:	Raymond Lu
7249  *		Friday, November 7, 2003
7250  *
7251  * Modifications:
7252  *
7253  *-------------------------------------------------------------------------
7254  */
7255 herr_t
H5T__conv_schar_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7256 H5T__conv_schar_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7257 		       size_t nelmts, size_t buf_stride,
7258                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7259                        hid_t H5_ATTR_UNUSED dxpl_id)
7260 {
7261     H5T_CONV_xF(SCHAR, FLOAT, signed char, float, -, -);
7262 }
7263 
7264 
7265 /*-------------------------------------------------------------------------
7266  * Function:	H5T__conv_schar_double
7267  *
7268  * Purpose:	Convert native signed char to native double using hardware.
7269  *		This is a fast special case.
7270  *
7271  * Return:	Non-negative on success/Negative on failure
7272  *
7273  * Programmer:	Raymond Lu
7274  *		Friday, November 7, 2003
7275  *
7276  * Modifications:
7277  *
7278  *-------------------------------------------------------------------------
7279  */
7280 herr_t
H5T__conv_schar_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7281 H5T__conv_schar_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7282 		       size_t nelmts, size_t buf_stride,
7283                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7284                        hid_t H5_ATTR_UNUSED dxpl_id)
7285 {
7286     H5T_CONV_xF(SCHAR, DOUBLE, signed char, double, -, -);
7287 }
7288 
7289 
7290 /*-------------------------------------------------------------------------
7291  * Function:	H5T__conv_schar_ldouble
7292  *
7293  * Purpose:	Convert native signed char to native long double using
7294  *              hardware.  This is a fast special case.
7295  *
7296  * Return:	Non-negative on success/Negative on failure
7297  *
7298  * Programmer:	Raymond Lu
7299  *		Tuesday, Febuary 1, 2005
7300  *
7301  * Modifications:
7302  *
7303  *-------------------------------------------------------------------------
7304  */
7305 herr_t
H5T__conv_schar_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7306 H5T__conv_schar_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7307 		       size_t nelmts, size_t buf_stride,
7308                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7309                        hid_t H5_ATTR_UNUSED dxpl_id)
7310 {
7311     H5T_CONV_xF(SCHAR, LDOUBLE, signed char, long double, -, -);
7312 }
7313 
7314 
7315 /*-------------------------------------------------------------------------
7316  * Function:	H5T__conv_uchar_float
7317  *
7318  * Purpose:	Convert native unsigned char to native float using hardware.
7319  *		This is a fast special case.
7320  *
7321  * Return:	Non-negative on success/Negative on failure
7322  *
7323  * Programmer:	Raymond Lu
7324  *		Friday, November 7, 2003
7325  *
7326  * Modifications:
7327  *
7328  *-------------------------------------------------------------------------
7329  */
7330 herr_t
H5T__conv_uchar_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7331 H5T__conv_uchar_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7332 		       size_t nelmts, size_t buf_stride,
7333                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7334                        hid_t H5_ATTR_UNUSED dxpl_id)
7335 {
7336     H5T_CONV_xF(UCHAR, FLOAT, unsigned char, float, -, -);
7337 }
7338 
7339 
7340 /*-------------------------------------------------------------------------
7341  * Function:	H5T__conv_uchar_double
7342  *
7343  * Purpose:	Convert native unsigned char to native double using hardware.
7344  *		This is a fast special case.
7345  *
7346  * Return:	Non-negative on success/Negative on failure
7347  *
7348  * Programmer:	Raymond Lu
7349  *		Friday, November 7, 2003
7350  *
7351  * Modifications:
7352  *
7353  *-------------------------------------------------------------------------
7354  */
7355 herr_t
H5T__conv_uchar_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7356 H5T__conv_uchar_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7357 		       size_t nelmts, size_t buf_stride,
7358                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7359                        hid_t H5_ATTR_UNUSED dxpl_id)
7360 {
7361     H5T_CONV_xF(UCHAR, DOUBLE, unsigned char, double, -, -);
7362 }
7363 
7364 
7365 /*-------------------------------------------------------------------------
7366  * Function:	H5T__conv_uchar_ldouble
7367  *
7368  * Purpose:	Convert native unsigned char to native long double using
7369  *              hardware.  This is a fast special case.
7370  *
7371  * Return:	Non-negative on success/Negative on failure
7372  *
7373  * Programmer:	Raymond Lu
7374  *		Tuesday, Febuary 1, 2005
7375  *
7376  * Modifications:
7377  *
7378  *-------------------------------------------------------------------------
7379  */
7380 herr_t
H5T__conv_uchar_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7381 H5T__conv_uchar_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7382 		       size_t nelmts, size_t buf_stride,
7383                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7384                        hid_t H5_ATTR_UNUSED dxpl_id)
7385 {
7386     H5T_CONV_xF(UCHAR, LDOUBLE, unsigned char, long double, -, -);
7387 }
7388 
7389 
7390 /*-------------------------------------------------------------------------
7391  * Function:	H5T__conv_short_float
7392  *
7393  * Purpose:	Convert native short to native float using hardware.
7394  *		This is a fast special case.
7395  *
7396  * Return:	Non-negative on success/Negative on failure
7397  *
7398  * Programmer:	Raymond Lu
7399  *		Friday, November 7, 2003
7400  *
7401  * Modifications:
7402  *
7403  *-------------------------------------------------------------------------
7404  */
7405 herr_t
H5T__conv_short_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7406 H5T__conv_short_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7407 		       size_t nelmts, size_t buf_stride,
7408                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7409                        hid_t H5_ATTR_UNUSED dxpl_id)
7410 {
7411     H5T_CONV_xF(SHORT, FLOAT, short, float, -, -);
7412 }
7413 
7414 
7415 /*-------------------------------------------------------------------------
7416  * Function:	H5T__conv_short_double
7417  *
7418  * Purpose:	Convert native short to native double using hardware.
7419  *		This is a fast special case.
7420  *
7421  * Return:	Non-negative on success/Negative on failure
7422  *
7423  * Programmer:	Raymond Lu
7424  *		Friday, November 7, 2003
7425  *
7426  * Modifications:
7427  *
7428  *-------------------------------------------------------------------------
7429  */
7430 herr_t
H5T__conv_short_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7431 H5T__conv_short_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7432 		       size_t nelmts, size_t buf_stride,
7433                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7434                        hid_t H5_ATTR_UNUSED dxpl_id)
7435 {
7436     H5T_CONV_xF(SHORT, DOUBLE, short, double, -, -);
7437 }
7438 
7439 
7440 /*-------------------------------------------------------------------------
7441  * Function:	H5T__conv_short_ldouble
7442  *
7443  * Purpose:	Convert native short to native long double using hardware.
7444  *		This is a fast special case.
7445  *
7446  * Return:	Non-negative on success/Negative on failure
7447  *
7448  * Programmer:	Raymond Lu
7449  *		Tuesday, Febuary 1, 2005
7450  *
7451  * Modifications:
7452  *
7453  *-------------------------------------------------------------------------
7454  */
7455 herr_t
H5T__conv_short_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7456 H5T__conv_short_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7457 		       size_t nelmts, size_t buf_stride,
7458                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7459                        hid_t H5_ATTR_UNUSED dxpl_id)
7460 {
7461     H5T_CONV_xF(SHORT, LDOUBLE, short, long double, -, -);
7462 }
7463 
7464 
7465 /*-------------------------------------------------------------------------
7466  * Function:	H5T__conv_ushort_float
7467  *
7468  * Purpose:	Convert native unsigned short to native float using hardware.
7469  *		This is a fast special case.
7470  *
7471  * Return:	Non-negative on success/Negative on failure
7472  *
7473  * Programmer:	Raymond Lu
7474  *		Friday, November 7, 2003
7475  *
7476  * Modifications:
7477  *
7478  *-------------------------------------------------------------------------
7479  */
7480 herr_t
H5T__conv_ushort_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7481 H5T__conv_ushort_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7482 		       size_t nelmts, size_t buf_stride,
7483                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7484                        hid_t H5_ATTR_UNUSED dxpl_id)
7485 {
7486     H5T_CONV_xF(USHORT, FLOAT, unsigned short, float, -, -);
7487 }
7488 
7489 
7490 /*-------------------------------------------------------------------------
7491  * Function:	H5T__conv_ushort_double
7492  *
7493  * Purpose:	Convert native unsigned short to native double using hardware.
7494  *		This is a fast special case.
7495  *
7496  * Return:	Non-negative on success/Negative on failure
7497  *
7498  * Programmer:	Raymond Lu
7499  *		Friday, November 7, 2003
7500  *
7501  * Modifications:
7502  *
7503  *-------------------------------------------------------------------------
7504  */
7505 herr_t
H5T__conv_ushort_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7506 H5T__conv_ushort_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7507 		       size_t nelmts, size_t buf_stride,
7508                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7509                        hid_t H5_ATTR_UNUSED dxpl_id)
7510 {
7511     H5T_CONV_xF(USHORT, DOUBLE, unsigned short, double, -, -);
7512 }
7513 
7514 
7515 /*-------------------------------------------------------------------------
7516  * Function:	H5T__conv_ushort_ldouble
7517  *
7518  * Purpose:	Convert native unsigned short to native long double using
7519  *              hardware.  This is a fast special case.
7520  *
7521  * Return:	Non-negative on success/Negative on failure
7522  *
7523  * Programmer:	Raymond Lu
7524  *		Tuesday, Febuary 1, 2005
7525  *
7526  * Modifications:
7527  *
7528  *-------------------------------------------------------------------------
7529  */
7530 herr_t
H5T__conv_ushort_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7531 H5T__conv_ushort_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7532 		       size_t nelmts, size_t buf_stride,
7533                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7534                        hid_t H5_ATTR_UNUSED dxpl_id)
7535 {
7536     H5T_CONV_xF(USHORT, LDOUBLE, unsigned short, long double, -, -);
7537 }
7538 
7539 
7540 /*-------------------------------------------------------------------------
7541  * Function:	H5T__conv_int_float
7542  *
7543  * Purpose:	Convert native integer to native float using hardware.
7544  *		This is a fast special case.
7545  *
7546  * Return:	Non-negative on success/Negative on failure
7547  *
7548  * Programmer:	Raymond Lu
7549  *		Friday, November 7, 2003
7550  *
7551  * Modifications:
7552  *
7553  *-------------------------------------------------------------------------
7554  */
7555 herr_t
H5T__conv_int_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7556 H5T__conv_int_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7557 		       size_t nelmts, size_t buf_stride,
7558                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7559                        hid_t H5_ATTR_UNUSED dxpl_id)
7560 {
7561     H5T_CONV_xF(INT, FLOAT, int, float, -, -);
7562 }
7563 
7564 
7565 /*-------------------------------------------------------------------------
7566  * Function:	H5T__conv_int_double
7567  *
7568  * Purpose:	Convert native integer to native double using hardware.
7569  *		This is a fast special case.
7570  *
7571  * Return:	Non-negative on success/Negative on failure
7572  *
7573  * Programmer:	Raymond Lu
7574  *		Friday, November 7, 2003
7575  *
7576  * Modifications:
7577  *
7578  *-------------------------------------------------------------------------
7579  */
7580 herr_t
H5T__conv_int_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7581 H5T__conv_int_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7582 		       size_t nelmts, size_t buf_stride,
7583                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7584                        hid_t H5_ATTR_UNUSED dxpl_id)
7585 {
7586     H5T_CONV_xF(INT, DOUBLE, int, double, -, -);
7587 }
7588 
7589 
7590 /*-------------------------------------------------------------------------
7591  * Function:	H5T__conv_int_ldouble
7592  *
7593  * Purpose:	Convert native integer to native long double using hardware.
7594  *		This is a fast special case.
7595  *
7596  * Return:	Non-negative on success/Negative on failure
7597  *
7598  * Programmer:	Raymond Lu
7599  *		Tuesday, Febuary 1, 2005
7600  *
7601  * Modifications:
7602  *
7603  *-------------------------------------------------------------------------
7604  */
7605 herr_t
H5T__conv_int_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7606 H5T__conv_int_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7607 		       size_t nelmts, size_t buf_stride,
7608                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7609                        hid_t H5_ATTR_UNUSED dxpl_id)
7610 {
7611     H5T_CONV_xF(INT, LDOUBLE, int, long double, -, -);
7612 }
7613 
7614 
7615 /*-------------------------------------------------------------------------
7616  * Function:	H5T__conv_uint_float
7617  *
7618  * Purpose:	Convert native unsigned integer to native float using
7619  *              hardware.  This is a fast special case.
7620  *
7621  * Return:	Non-negative on success/Negative on failure
7622  *
7623  * Programmer:	Raymond Lu
7624  *		Friday, November 7, 2003
7625  *
7626  * Modifications:
7627  *
7628  *-------------------------------------------------------------------------
7629  */
7630 herr_t
H5T__conv_uint_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7631 H5T__conv_uint_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7632 		       size_t nelmts, size_t buf_stride,
7633                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7634                        hid_t H5_ATTR_UNUSED dxpl_id)
7635 {
7636     H5T_CONV_xF(UINT, FLOAT, unsigned int, float, -, -);
7637 }
7638 
7639 
7640 /*-------------------------------------------------------------------------
7641  * Function:	H5T__conv_uint_double
7642  *
7643  * Purpose:	Convert native unsigned integer to native double using
7644  *              hardware.  This is a fast special case.
7645  *
7646  * Return:	Non-negative on success/Negative on failure
7647  *
7648  * Programmer:	Raymond Lu
7649  *		Friday, November 7, 2003
7650  *
7651  * Modifications:
7652  *
7653  *-------------------------------------------------------------------------
7654  */
7655 herr_t
H5T__conv_uint_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7656 H5T__conv_uint_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7657 		       size_t nelmts, size_t buf_stride,
7658                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7659                        hid_t H5_ATTR_UNUSED dxpl_id)
7660 {
7661     H5T_CONV_xF(UINT, DOUBLE, unsigned int, double, -, -);
7662 }
7663 
7664 
7665 /*-------------------------------------------------------------------------
7666  * Function:	H5T__conv_uint_ldouble
7667  *
7668  * Purpose:	Convert native unsigned integer to native long double using
7669  *              hardware.  This is a fast special case.
7670  *
7671  * Return:	Non-negative on success/Negative on failure
7672  *
7673  * Programmer:	Raymond Lu
7674  *		Tuesday, Febuary 1, 2005
7675  *
7676  * Modifications:
7677  *
7678  *-------------------------------------------------------------------------
7679  */
7680 herr_t
H5T__conv_uint_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7681 H5T__conv_uint_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7682 		       size_t nelmts, size_t buf_stride,
7683                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7684                        hid_t H5_ATTR_UNUSED dxpl_id)
7685 {
7686     H5T_CONV_xF(UINT, LDOUBLE, unsigned int, long double, -, -);
7687 }
7688 
7689 
7690 /*-------------------------------------------------------------------------
7691  * Function:	H5T__conv_long_float
7692  *
7693  * Purpose:	Convert native long to native float using hardware.
7694  *		This is a fast special case.
7695  *
7696  * Return:	Non-negative on success/Negative on failure
7697  *
7698  * Programmer:	Raymond Lu
7699  *		Friday, November 7, 2003
7700  *
7701  * Modifications:
7702  *
7703  *-------------------------------------------------------------------------
7704  */
7705 herr_t
H5T__conv_long_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7706 H5T__conv_long_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7707 		       size_t nelmts, size_t buf_stride,
7708                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7709                        hid_t H5_ATTR_UNUSED dxpl_id)
7710 {
7711     H5T_CONV_xF(LONG, FLOAT, long, float, -, -);
7712 }
7713 
7714 
7715 /*-------------------------------------------------------------------------
7716  * Function:	H5T__conv_long_double
7717  *
7718  * Purpose:	Convert native long to native double using hardware.
7719  *		This is a fast special case.
7720  *
7721  * Return:	Non-negative on success/Negative on failure
7722  *
7723  * Programmer:	Raymond Lu
7724  *		Friday, November 7, 2003
7725  *
7726  * Modifications:
7727  *
7728  *-------------------------------------------------------------------------
7729  */
7730 herr_t
H5T__conv_long_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7731 H5T__conv_long_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7732 		       size_t nelmts, size_t buf_stride,
7733                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7734                        hid_t H5_ATTR_UNUSED dxpl_id)
7735 {
7736     H5T_CONV_xF(LONG, DOUBLE, long, double, -, -);
7737 }
7738 
7739 
7740 /*-------------------------------------------------------------------------
7741  * Function:	H5T__conv_long_ldouble
7742  *
7743  * Purpose:	Convert native long to native long double using hardware.
7744  *		This is a fast special case.
7745  *
7746  * Return:	Non-negative on success/Negative on failure
7747  *
7748  * Programmer:	Raymond Lu
7749  *		Tuesday, Febuary 1, 2005
7750  *
7751  * Modifications:
7752  *
7753  *-------------------------------------------------------------------------
7754  */
7755 herr_t
H5T__conv_long_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7756 H5T__conv_long_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7757 		       size_t nelmts, size_t buf_stride,
7758                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7759                        hid_t H5_ATTR_UNUSED dxpl_id)
7760 {
7761     H5T_CONV_xF(LONG, LDOUBLE, long, long double, -, -);
7762 }
7763 
7764 
7765 /*-------------------------------------------------------------------------
7766  * Function:	H5T__conv_ulong_float
7767  *
7768  * Purpose:	Convert native unsigned long to native float using hardware.
7769  *		This is a fast special case.
7770  *
7771  * Return:	Non-negative on success/Negative on failure
7772  *
7773  * Programmer:	Raymond Lu
7774  *		Friday, November 7, 2003
7775  *
7776  * Modifications:
7777  *
7778  *-------------------------------------------------------------------------
7779  */
7780 herr_t
H5T__conv_ulong_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7781 H5T__conv_ulong_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7782 		       size_t nelmts, size_t buf_stride,
7783                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7784                        hid_t H5_ATTR_UNUSED dxpl_id)
7785 {
7786     H5T_CONV_xF(ULONG, FLOAT, unsigned long, float, -, -);
7787 }
7788 
7789 
7790 /*-------------------------------------------------------------------------
7791  * Function:	H5T__conv_ulong_double
7792  *
7793  * Purpose:	Convert native unsigned long to native double using hardware.
7794  *		This is a fast special case.
7795  *
7796  * Return:	Non-negative on success/Negative on failure
7797  *
7798  * Programmer:	Raymond Lu
7799  *		Friday, November 7, 2003
7800  *
7801  * Modifications:
7802  *
7803  *-------------------------------------------------------------------------
7804  */
7805 herr_t
H5T__conv_ulong_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7806 H5T__conv_ulong_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7807 		       size_t nelmts, size_t buf_stride,
7808                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7809                        hid_t H5_ATTR_UNUSED dxpl_id)
7810 {
7811     H5T_CONV_xF(ULONG, DOUBLE, unsigned long, double, -, -);
7812 }
7813 
7814 
7815 /*-------------------------------------------------------------------------
7816  * Function:	H5T__conv_ulong_ldouble
7817  *
7818  * Purpose:	Convert native unsigned long to native long double using
7819  *              hardware.  This is a fast special case.
7820  *
7821  * Return:	Non-negative on success/Negative on failure
7822  *
7823  * Programmer:	Raymond Lu
7824  *		Tuesday, Febuary 1, 2005
7825  *
7826  * Modifications:
7827  *
7828  *-------------------------------------------------------------------------
7829  */
7830 herr_t
H5T__conv_ulong_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7831 H5T__conv_ulong_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7832 		       size_t nelmts, size_t buf_stride,
7833                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7834                        hid_t H5_ATTR_UNUSED dxpl_id)
7835 {
7836     H5T_CONV_xF(ULONG, LDOUBLE, unsigned long, long double, -, -);
7837 }
7838 
7839 
7840 /*-------------------------------------------------------------------------
7841  * Function:	H5T__conv_llong_float
7842  *
7843  * Purpose:	Convert native long long to native float using hardware.
7844  *		This is a fast special case.
7845  *
7846  * Return:	Non-negative on success/Negative on failure
7847  *
7848  * Programmer:	Raymond Lu
7849  *		Friday, November 7, 2003
7850  *
7851  * Modifications:
7852  *
7853  *-------------------------------------------------------------------------
7854  */
7855 herr_t
H5T__conv_llong_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7856 H5T__conv_llong_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7857 		       size_t nelmts, size_t buf_stride,
7858                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7859                        hid_t H5_ATTR_UNUSED dxpl_id)
7860 {
7861     H5T_CONV_xF(LLONG, FLOAT, long long, float, -, -);
7862 }
7863 
7864 
7865 /*-------------------------------------------------------------------------
7866  * Function:	H5T__conv_llong_double
7867  *
7868  * Purpose:	Convert native long long to native double using hardware.
7869  *		This is a fast special case.
7870  *
7871  * Return:	Non-negative on success/Negative on failure
7872  *
7873  * Programmer:	Raymond Lu
7874  *		Friday, November 7, 2003
7875  *
7876  * Modifications:
7877  *
7878  *-------------------------------------------------------------------------
7879  */
7880 herr_t
H5T__conv_llong_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7881 H5T__conv_llong_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7882 		       size_t nelmts, size_t buf_stride,
7883                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7884                        hid_t H5_ATTR_UNUSED dxpl_id)
7885 {
7886     H5T_CONV_xF(LLONG, DOUBLE, long long, double, -, -);
7887 }
7888 
7889 
7890 /*-------------------------------------------------------------------------
7891  * Function:	H5T__conv_llong_ldouble
7892  *
7893  * Purpose:	Convert native long long to native long double using
7894  *              hardware.  This is a fast special case.
7895  *
7896  * Return:	Non-negative on success/Negative on failure
7897  *
7898  * Programmer:	Raymond Lu
7899  *		Tuesday, Febuary 1, 2005
7900  *
7901  * Modifications:
7902  *
7903  *-------------------------------------------------------------------------
7904  */
7905 #if H5T_CONV_INTERNAL_LLONG_LDOUBLE
7906 herr_t
H5T__conv_llong_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7907 H5T__conv_llong_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7908 		       size_t nelmts, size_t buf_stride,
7909                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7910                        hid_t H5_ATTR_UNUSED dxpl_id)
7911 {
7912     H5T_CONV_xF(LLONG, LDOUBLE, long long, long double, -, -);
7913 }
7914 #endif /* H5T_CONV_INTERNAL_LLONG_LDOUBLE */
7915 
7916 
7917 /*-------------------------------------------------------------------------
7918  * Function:	H5T__conv_ullong_float
7919  *
7920  * Purpose:	Convert native unsigned long long to native float using
7921  *              hardware.  This is a fast special case.
7922  *
7923  * Return:	Non-negative on success/Negative on failure
7924  *
7925  * Programmer:	Raymond Lu
7926  *		Friday, November 7, 2003
7927  *
7928  * Modifications:
7929  *
7930  *-------------------------------------------------------------------------
7931  */
7932 herr_t
H5T__conv_ullong_float(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7933 H5T__conv_ullong_float (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7934 		       size_t nelmts, size_t buf_stride,
7935                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7936                        hid_t H5_ATTR_UNUSED dxpl_id)
7937 {
7938     H5T_CONV_xF(ULLONG, FLOAT, unsigned long long, float, -, -);
7939 }
7940 
7941 
7942 /*-------------------------------------------------------------------------
7943  * Function:	H5T__conv_ullong_double
7944  *
7945  * Purpose:	Convert native unsigned long long to native double using
7946  *              hardware.  This is a fast special case.
7947  *
7948  * Return:	Non-negative on success/Negative on failure
7949  *
7950  * Programmer:	Raymond Lu
7951  *		Friday, November 7, 2003
7952  *
7953  * Modifications:
7954  *
7955  *-------------------------------------------------------------------------
7956  */
7957 herr_t
H5T__conv_ullong_double(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7958 H5T__conv_ullong_double (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7959 		       size_t nelmts, size_t buf_stride,
7960                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7961                        hid_t H5_ATTR_UNUSED dxpl_id)
7962 {
7963     H5T_CONV_xF(ULLONG, DOUBLE, unsigned long long, double, -, -);
7964 }
7965 
7966 
7967 /*-------------------------------------------------------------------------
7968  * Function:	H5T__conv_ullong_ldouble
7969  *
7970  * Purpose:	Convert native unsigned long long to native long double using
7971  *              hardware.  This is a fast special case.
7972  *
7973  * Return:	Non-negative on success/Negative on failure
7974  *
7975  * Programmer:	Raymond Lu
7976  *		Tuesday, Febuary 1, 2005
7977  *
7978  * Modifications:
7979  *
7980  *-------------------------------------------------------------------------
7981  */
7982 #if H5T_CONV_INTERNAL_ULLONG_LDOUBLE
7983 herr_t
H5T__conv_ullong_ldouble(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)7984 H5T__conv_ullong_ldouble (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
7985 		       size_t nelmts, size_t buf_stride,
7986                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
7987                        hid_t H5_ATTR_UNUSED dxpl_id)
7988 {
7989     H5T_CONV_xF(ULLONG, LDOUBLE, unsigned long long, long double, -, -);
7990 }
7991 #endif /*H5T_CONV_INTERNAL_ULLONG_LDOUBLE*/
7992 
7993 
7994 /*-------------------------------------------------------------------------
7995  * Function:	H5T__conv_float_schar
7996  *
7997  * Purpose:	Convert native float to native signed char using
7998  *              hardware.  This is a fast special case.
7999  *
8000  * Return:	Non-negative on success/Negative on failure
8001  *
8002  * Programmer:	Raymond Lu
8003  *		Friday, November 7, 2003
8004  *
8005  * Modifications:
8006  *
8007  *-------------------------------------------------------------------------
8008  */
8009 herr_t
H5T__conv_float_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8010 H5T__conv_float_schar (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8011 		       size_t nelmts, size_t buf_stride,
8012                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8013                        hid_t H5_ATTR_UNUSED dxpl_id)
8014 {
8015 H5_GCC_DIAG_OFF(float-equal)
8016     H5T_CONV_Fx(FLOAT, SCHAR, float, signed char, SCHAR_MIN, SCHAR_MAX);
8017 H5_GCC_DIAG_ON(float-equal)
8018 }
8019 
8020 
8021 /*-------------------------------------------------------------------------
8022  * Function:	H5T__conv_float_uchar
8023  *
8024  * Purpose:	Convert native float to native unsigned char using
8025  *              hardware.  This is a fast special case.
8026  *
8027  * Return:	Non-negative on success/Negative on failure
8028  *
8029  * Programmer:	Raymond Lu
8030  *		Friday, November 7, 2003
8031  *
8032  * Modifications:
8033  *
8034  *-------------------------------------------------------------------------
8035  */
8036 herr_t
H5T__conv_float_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8037 H5T__conv_float_uchar (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8038 		       size_t nelmts, size_t buf_stride,
8039                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8040                        hid_t H5_ATTR_UNUSED dxpl_id)
8041 {
8042 H5_GCC_DIAG_OFF(float-equal)
8043     H5T_CONV_Fx(FLOAT, UCHAR, float, unsigned char, 0, UCHAR_MAX);
8044 H5_GCC_DIAG_ON(float-equal)
8045 }
8046 
8047 
8048 /*-------------------------------------------------------------------------
8049  * Function:	H5T__conv_double_schar
8050  *
8051  * Purpose:	Convert native double to native signed char using
8052  *              hardware.  This is a fast special case.
8053  *
8054  * Return:	Non-negative on success/Negative on failure
8055  *
8056  * Programmer:	Raymond Lu
8057  *		Friday, November 7, 2003
8058  *
8059  * Modifications:
8060  *
8061  *-------------------------------------------------------------------------
8062  */
8063 herr_t
H5T__conv_double_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8064 H5T__conv_double_schar (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8065 		       size_t nelmts, size_t buf_stride,
8066                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8067                        hid_t H5_ATTR_UNUSED dxpl_id)
8068 {
8069 H5_GCC_DIAG_OFF(float-equal)
8070     H5T_CONV_Fx(DOUBLE, SCHAR, double, signed char, SCHAR_MIN, SCHAR_MAX);
8071 H5_GCC_DIAG_ON(float-equal)
8072 }
8073 
8074 
8075 /*-------------------------------------------------------------------------
8076  * Function:	H5T__conv_double_uchar
8077  *
8078  * Purpose:	Convert native double to native unsigned char using
8079  *              hardware.  This is a fast special case.
8080  *
8081  * Return:	Non-negative on success/Negative on failure
8082  *
8083  * Programmer:	Raymond Lu
8084  *		Friday, November 7, 2003
8085  *
8086  * Modifications:
8087  *
8088  *-------------------------------------------------------------------------
8089  */
8090 herr_t
H5T__conv_double_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8091 H5T__conv_double_uchar (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8092 		       size_t nelmts, size_t buf_stride,
8093                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8094                        hid_t H5_ATTR_UNUSED dxpl_id)
8095 {
8096 H5_GCC_DIAG_OFF(float-equal)
8097     H5T_CONV_Fx(DOUBLE, UCHAR, double, unsigned char, 0, UCHAR_MAX);
8098 H5_GCC_DIAG_ON(float-equal)
8099 }
8100 
8101 
8102 /*-------------------------------------------------------------------------
8103  * Function:	H5T__conv_ldouble_schar
8104  *
8105  * Purpose:	Convert native long double to native signed char using
8106  *              hardware.  This is a fast special case.
8107  *
8108  * Return:	Non-negative on success/Negative on failure
8109  *
8110  * Programmer:	Raymond Lu
8111  *		Tuesday, Febuary 1, 2005
8112  *
8113  * Modifications:
8114  *
8115  *-------------------------------------------------------------------------
8116  */
8117 herr_t
H5T__conv_ldouble_schar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8118 H5T__conv_ldouble_schar (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8119 		       size_t nelmts, size_t buf_stride,
8120                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8121                        hid_t H5_ATTR_UNUSED dxpl_id)
8122 {
8123 H5_GCC_DIAG_OFF(float-equal)
8124     H5T_CONV_Fx(LDOUBLE, SCHAR, long double, signed char, SCHAR_MIN, SCHAR_MAX);
8125 H5_GCC_DIAG_ON(float-equal)
8126 }
8127 
8128 
8129 /*-------------------------------------------------------------------------
8130  * Function:	H5T__conv_ldouble_uchar
8131  *
8132  * Purpose:	Convert native long double to native unsigned char using
8133  *              hardware.  This is a fast special case.
8134  *
8135  * Return:	Non-negative on success/Negative on failure
8136  *
8137  * Programmer:	Raymond Lu
8138  *		Tuesday, Febuary 1, 2005
8139  *
8140  * Modifications:
8141  *
8142  *-------------------------------------------------------------------------
8143  */
8144 herr_t
H5T__conv_ldouble_uchar(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8145 H5T__conv_ldouble_uchar (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8146 		       size_t nelmts, size_t buf_stride,
8147                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8148                        hid_t H5_ATTR_UNUSED dxpl_id)
8149 {
8150 H5_GCC_DIAG_OFF(float-equal)
8151     H5T_CONV_Fx(LDOUBLE, UCHAR, long double, unsigned char, 0, UCHAR_MAX);
8152 H5_GCC_DIAG_ON(float-equal)
8153 }
8154 
8155 
8156 /*-------------------------------------------------------------------------
8157  * Function:	H5T__conv_float_short
8158  *
8159  * Purpose:	Convert native float to native short using
8160  *              hardware.  This is a fast special case.
8161  *
8162  * Return:	Non-negative on success/Negative on failure
8163  *
8164  * Programmer:	Raymond Lu
8165  *		Friday, November 7, 2003
8166  *
8167  * Modifications:
8168  *
8169  *-------------------------------------------------------------------------
8170  */
8171 herr_t
H5T__conv_float_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8172 H5T__conv_float_short (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8173 		       size_t nelmts, size_t buf_stride,
8174                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8175                        hid_t H5_ATTR_UNUSED dxpl_id)
8176 {
8177 H5_GCC_DIAG_OFF(float-equal)
8178     H5T_CONV_Fx(FLOAT, SHORT, float, short, SHRT_MIN, SHRT_MAX);
8179 H5_GCC_DIAG_ON(float-equal)
8180 }
8181 
8182 
8183 /*-------------------------------------------------------------------------
8184  * Function:	H5T__conv_float_ushort
8185  *
8186  * Purpose:	Convert native float to native unsigned short using
8187  *              hardware.  This is a fast special case.
8188  *
8189  * Return:	Non-negative on success/Negative on failure
8190  *
8191  * Programmer:	Raymond Lu
8192  *		Friday, November 7, 2003
8193  *
8194  * Modifications:
8195  *
8196  *-------------------------------------------------------------------------
8197  */
8198 herr_t
H5T__conv_float_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8199 H5T__conv_float_ushort (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8200 		       size_t nelmts, size_t buf_stride,
8201                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8202                        hid_t H5_ATTR_UNUSED dxpl_id)
8203 {
8204 H5_GCC_DIAG_OFF(float-equal)
8205     H5T_CONV_Fx(FLOAT, USHORT, float, unsigned short, 0, USHRT_MAX);
8206 H5_GCC_DIAG_ON(float-equal)
8207 }
8208 
8209 
8210 /*-------------------------------------------------------------------------
8211  * Function:	H5T__conv_double_short
8212  *
8213  * Purpose:	Convert native double to native short using
8214  *              hardware.  This is a fast special case.
8215  *
8216  * Return:	Non-negative on success/Negative on failure
8217  *
8218  * Programmer:	Raymond Lu
8219  *		Friday, November 7, 2003
8220  *
8221  * Modifications:
8222  *
8223  *-------------------------------------------------------------------------
8224  */
8225 herr_t
H5T__conv_double_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8226 H5T__conv_double_short (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8227 		       size_t nelmts, size_t buf_stride,
8228                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8229                        hid_t H5_ATTR_UNUSED dxpl_id)
8230 {
8231 H5_GCC_DIAG_OFF(float-equal)
8232     H5T_CONV_Fx(DOUBLE, SHORT, double, short, SHRT_MIN, SHRT_MAX);
8233 H5_GCC_DIAG_ON(float-equal)
8234 }
8235 
8236 
8237 /*-------------------------------------------------------------------------
8238  * Function:	H5T__conv_double_ushort
8239  *
8240  * Purpose:	Convert native double to native unsigned short using
8241  *              hardware.  This is a fast special case.
8242  *
8243  * Return:	Non-negative on success/Negative on failure
8244  *
8245  * Programmer:	Raymond Lu
8246  *		Friday, November 7, 2003
8247  *
8248  * Modifications:
8249  *
8250  *-------------------------------------------------------------------------
8251  */
8252 herr_t
H5T__conv_double_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8253 H5T__conv_double_ushort (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8254 		       size_t nelmts, size_t buf_stride,
8255                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8256                        hid_t H5_ATTR_UNUSED dxpl_id)
8257 {
8258 H5_GCC_DIAG_OFF(float-equal)
8259     H5T_CONV_Fx(DOUBLE, USHORT, double, unsigned short, 0, USHRT_MAX);
8260 H5_GCC_DIAG_ON(float-equal)
8261 }
8262 
8263 
8264 /*-------------------------------------------------------------------------
8265  * Function:	H5T__conv_ldouble_short
8266  *
8267  * Purpose:	Convert native long double to native short using
8268  *              hardware.  This is a fast special case.
8269  *
8270  * Return:	Non-negative on success/Negative on failure
8271  *
8272  * Programmer:	Raymond Lu
8273  *		Tuesday, Febuary 1, 2005
8274  *
8275  * Modifications:
8276  *
8277  *-------------------------------------------------------------------------
8278  */
8279 herr_t
H5T__conv_ldouble_short(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8280 H5T__conv_ldouble_short (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8281 		       size_t nelmts, size_t buf_stride,
8282                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8283                        hid_t H5_ATTR_UNUSED dxpl_id)
8284 {
8285 H5_GCC_DIAG_OFF(float-equal)
8286     H5T_CONV_Fx(LDOUBLE, SHORT, long double, short, SHRT_MIN, SHRT_MAX);
8287 H5_GCC_DIAG_ON(float-equal)
8288 }
8289 
8290 
8291 /*-------------------------------------------------------------------------
8292  * Function:	H5T__conv_ldouble_ushort
8293  *
8294  * Purpose:	Convert native long double to native unsigned short using
8295  *              hardware.  This is a fast special case.
8296  *
8297  * Return:	Non-negative on success/Negative on failure
8298  *
8299  * Programmer:	Raymond Lu
8300  *		Tuesday, Febuary 1, 2005
8301  *
8302  * Modifications:
8303  *
8304  *-------------------------------------------------------------------------
8305  */
8306 herr_t
H5T__conv_ldouble_ushort(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8307 H5T__conv_ldouble_ushort (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8308 		       size_t nelmts, size_t buf_stride,
8309                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8310                        hid_t H5_ATTR_UNUSED dxpl_id)
8311 {
8312 H5_GCC_DIAG_OFF(float-equal)
8313     H5T_CONV_Fx(LDOUBLE, USHORT, long double, unsigned short, 0, USHRT_MAX);
8314 H5_GCC_DIAG_ON(float-equal)
8315 }
8316 
8317 
8318 /*-------------------------------------------------------------------------
8319  * Function:	H5T__conv_float_int
8320  *
8321  * Purpose:	Convert native float to native int using
8322  *              hardware.  This is a fast special case.
8323  *
8324  * Return:	Non-negative on success/Negative on failure
8325  *
8326  * Programmer:	Raymond Lu
8327  *		Friday, November 7, 2003
8328  *
8329  * Modifications:
8330  *
8331  *-------------------------------------------------------------------------
8332  */
8333 herr_t
H5T__conv_float_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8334 H5T__conv_float_int (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8335 		       size_t nelmts, size_t buf_stride,
8336                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8337                        hid_t H5_ATTR_UNUSED dxpl_id)
8338 {
8339 H5_GCC_DIAG_OFF(float-equal)
8340     H5T_CONV_Fx(FLOAT, INT, float, int, INT_MIN, INT_MAX);
8341 H5_GCC_DIAG_ON(float-equal)
8342 }
8343 
8344 
8345 /*-------------------------------------------------------------------------
8346  * Function:	H5T__conv_float_uint
8347  *
8348  * Purpose:	Convert native float to native unsigned int using
8349  *              hardware.  This is a fast special case.
8350  *
8351  * Return:	Non-negative on success/Negative on failure
8352  *
8353  * Programmer:	Raymond Lu
8354  *		Friday, November 7, 2003
8355  *
8356  * Modifications:
8357  *
8358  *-------------------------------------------------------------------------
8359  */
8360 herr_t
H5T__conv_float_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8361 H5T__conv_float_uint (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8362 		       size_t nelmts, size_t buf_stride,
8363                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8364                        hid_t H5_ATTR_UNUSED dxpl_id)
8365 {
8366 H5_GCC_DIAG_OFF(float-equal)
8367     H5T_CONV_Fx(FLOAT, UINT, float, unsigned int, 0, UINT_MAX);
8368 H5_GCC_DIAG_ON(float-equal)
8369 }
8370 
8371 
8372 /*-------------------------------------------------------------------------
8373  * Function:	H5T__conv_double_int
8374  *
8375  * Purpose:	Convert native double to native int using
8376  *              hardware.  This is a fast special case.
8377  *
8378  * Return:	Non-negative on success/Negative on failure
8379  *
8380  * Programmer:	Raymond Lu
8381  *		Friday, November 7, 2003
8382  *
8383  * Modifications:
8384  *
8385  *-------------------------------------------------------------------------
8386  */
8387 herr_t
H5T__conv_double_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8388 H5T__conv_double_int (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8389 		       size_t nelmts, size_t buf_stride,
8390                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8391                        hid_t H5_ATTR_UNUSED dxpl_id)
8392 {
8393 H5_GCC_DIAG_OFF(float-equal)
8394     H5T_CONV_Fx(DOUBLE, INT, double, int, INT_MIN, INT_MAX);
8395 H5_GCC_DIAG_ON(float-equal)
8396 }
8397 
8398 
8399 /*-------------------------------------------------------------------------
8400  * Function:	H5T__conv_double_uint
8401  *
8402  * Purpose:	Convert native double to native unsigned int using
8403  *              hardware.  This is a fast special case.
8404  *
8405  * Return:	Non-negative on success/Negative on failure
8406  *
8407  * Programmer:	Raymond Lu
8408  *		Friday, November 7, 2003
8409  *
8410  * Modifications:
8411  *
8412  *-------------------------------------------------------------------------
8413  */
8414 herr_t
H5T__conv_double_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8415 H5T__conv_double_uint (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8416 		       size_t nelmts, size_t buf_stride,
8417                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8418                        hid_t H5_ATTR_UNUSED dxpl_id)
8419 {
8420 H5_GCC_DIAG_OFF(float-equal)
8421     H5T_CONV_Fx(DOUBLE, UINT, double, unsigned int, 0, UINT_MAX);
8422 H5_GCC_DIAG_ON(float-equal)
8423 }
8424 
8425 
8426 /*-------------------------------------------------------------------------
8427  * Function:	H5T__conv_ldouble_int
8428  *
8429  * Purpose:	Convert native long double to native int using
8430  *              hardware.  This is a fast special case.
8431  *
8432  * Return:	Non-negative on success/Negative on failure
8433  *
8434  * Programmer:	Raymond Lu
8435  *		Tuesday, Febuary 1, 2005
8436  *
8437  * Modifications:
8438  *
8439  *-------------------------------------------------------------------------
8440  */
8441 herr_t
H5T__conv_ldouble_int(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8442 H5T__conv_ldouble_int (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8443 		       size_t nelmts, size_t buf_stride,
8444                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8445                        hid_t H5_ATTR_UNUSED dxpl_id)
8446 {
8447 H5_GCC_DIAG_OFF(float-equal)
8448     H5T_CONV_Fx(LDOUBLE, INT, long double, int, INT_MIN, INT_MAX);
8449 H5_GCC_DIAG_ON(float-equal)
8450 }
8451 
8452 
8453 /*-------------------------------------------------------------------------
8454  * Function:	H5T__conv_ldouble_uint
8455  *
8456  * Purpose:	Convert native long double to native unsigned int using
8457  *              hardware.  This is a fast special case.
8458  *
8459  * Return:	Non-negative on success/Negative on failure
8460  *
8461  * Programmer:	Raymond Lu
8462  *		Tuesday, Febuary 1, 2005
8463  *
8464  * Modifications:
8465  *
8466  *-------------------------------------------------------------------------
8467  */
8468 herr_t
H5T__conv_ldouble_uint(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8469 H5T__conv_ldouble_uint (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8470 		       size_t nelmts, size_t buf_stride,
8471                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8472                        hid_t H5_ATTR_UNUSED dxpl_id)
8473 {
8474 H5_GCC_DIAG_OFF(float-equal)
8475     H5T_CONV_Fx(LDOUBLE, UINT, long double, unsigned int, 0, UINT_MAX);
8476 H5_GCC_DIAG_ON(float-equal)
8477 }
8478 
8479 
8480 /*-------------------------------------------------------------------------
8481  * Function:	H5T__conv_float_long
8482  *
8483  * Purpose:	Convert native float to native long using
8484  *              hardware.  This is a fast special case.
8485  *
8486  * Return:	Non-negative on success/Negative on failure
8487  *
8488  * Programmer:	Raymond Lu
8489  *		Friday, November 7, 2003
8490  *
8491  * Modifications:
8492  *
8493  *-------------------------------------------------------------------------
8494  */
8495 herr_t
H5T__conv_float_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8496 H5T__conv_float_long (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8497 		       size_t nelmts, size_t buf_stride,
8498                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8499                        hid_t H5_ATTR_UNUSED dxpl_id)
8500 {
8501 H5_GCC_DIAG_OFF(float-equal)
8502     H5T_CONV_Fx(FLOAT, LONG, float, long, LONG_MIN, LONG_MAX);
8503 H5_GCC_DIAG_ON(float-equal)
8504 }
8505 
8506 
8507 /*-------------------------------------------------------------------------
8508  * Function:	H5T__conv_float_ulong
8509  *
8510  * Purpose:	Convert native float to native unsigned long using
8511  *              hardware.  This is a fast special case.
8512  *
8513  * Return:	Non-negative on success/Negative on failure
8514  *
8515  * Programmer:	Raymond Lu
8516  *		Friday, November 7, 2003
8517  *
8518  * Modifications:
8519  *
8520  *-------------------------------------------------------------------------
8521  */
8522 herr_t
H5T__conv_float_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8523 H5T__conv_float_ulong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8524 		       size_t nelmts, size_t buf_stride,
8525                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8526                        hid_t H5_ATTR_UNUSED dxpl_id)
8527 {
8528 H5_GCC_DIAG_OFF(float-equal)
8529     H5T_CONV_Fx(FLOAT, ULONG, float, unsigned long, 0, ULONG_MAX);
8530 H5_GCC_DIAG_ON(float-equal)
8531 }
8532 
8533 
8534 /*-------------------------------------------------------------------------
8535  * Function:	H5T__conv_double_long
8536  *
8537  * Purpose:	Convert native double to native long using
8538  *              hardware.  This is a fast special case.
8539  *
8540  * Return:	Non-negative on success/Negative on failure
8541  *
8542  * Programmer:	Raymond Lu
8543  *		Friday, November 7, 2003
8544  *
8545  * Modifications:
8546  *
8547  *-------------------------------------------------------------------------
8548  */
8549 herr_t
H5T__conv_double_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8550 H5T__conv_double_long (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8551 		       size_t nelmts, size_t buf_stride,
8552                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8553                        hid_t H5_ATTR_UNUSED dxpl_id)
8554 {
8555 H5_GCC_DIAG_OFF(float-equal)
8556     H5T_CONV_Fx(DOUBLE, LONG, double, long, LONG_MIN, LONG_MAX);
8557 H5_GCC_DIAG_ON(float-equal)
8558 }
8559 
8560 
8561 /*-------------------------------------------------------------------------
8562  * Function:	H5T__conv_double_ulong
8563  *
8564  * Purpose:	Convert native double to native unsigned long using
8565  *              hardware.  This is a fast special case.
8566  *
8567  * Return:	Non-negative on success/Negative on failure
8568  *
8569  * Programmer:	Raymond Lu
8570  *		Friday, November 7, 2003
8571  *
8572  * Modifications:
8573  *
8574  *-------------------------------------------------------------------------
8575  */
8576 herr_t
H5T__conv_double_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8577 H5T__conv_double_ulong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8578 		       size_t nelmts, size_t buf_stride,
8579                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8580                        hid_t H5_ATTR_UNUSED dxpl_id)
8581 {
8582 H5_GCC_DIAG_OFF(float-equal)
8583     H5T_CONV_Fx(DOUBLE, ULONG, double, unsigned long, 0, ULONG_MAX);
8584 H5_GCC_DIAG_ON(float-equal)
8585 }
8586 
8587 
8588 /*-------------------------------------------------------------------------
8589  * Function:	H5T__conv_ldouble_long
8590  *
8591  * Purpose:	Convert native long double to native long using
8592  *              hardware.  This is a fast special case.
8593  *
8594  * Return:	Non-negative on success/Negative on failure
8595  *
8596  * Programmer:	Raymond Lu
8597  *		Tuesday, Febuary 1, 2005
8598  *
8599  * Modifications:
8600  *
8601  *-------------------------------------------------------------------------
8602  */
8603 herr_t
H5T__conv_ldouble_long(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8604 H5T__conv_ldouble_long (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8605 		       size_t nelmts, size_t buf_stride,
8606                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8607                        hid_t H5_ATTR_UNUSED dxpl_id)
8608 {
8609 H5_GCC_DIAG_OFF(float-equal)
8610     H5T_CONV_Fx(LDOUBLE, LONG, long double, long, LONG_MIN, LONG_MAX);
8611 H5_GCC_DIAG_ON(float-equal)
8612 }
8613 
8614 
8615 /*-------------------------------------------------------------------------
8616  * Function:	H5T__conv_ldouble_ulong
8617  *
8618  * Purpose:	Convert native long double to native unsigned long using
8619  *              hardware.  This is a fast special case.
8620  *
8621  * Return:	Non-negative on success/Negative on failure
8622  *
8623  * Programmer:	Raymond Lu
8624  *		Tuesday, Febuary 1, 2005
8625  *
8626  * Modifications:
8627  *
8628  *-------------------------------------------------------------------------
8629  */
8630 herr_t
H5T__conv_ldouble_ulong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8631 H5T__conv_ldouble_ulong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8632 		       size_t nelmts, size_t buf_stride,
8633                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8634                        hid_t H5_ATTR_UNUSED dxpl_id)
8635 {
8636 H5_GCC_DIAG_OFF(float-equal)
8637     H5T_CONV_Fx(LDOUBLE, ULONG, long double, unsigned long, 0, ULONG_MAX);
8638 H5_GCC_DIAG_ON(float-equal)
8639 }
8640 
8641 
8642 /*-------------------------------------------------------------------------
8643  * Function:	H5T__conv_float_llong
8644  *
8645  * Purpose:	Convert native float to native long long using
8646  *              hardware.  This is a fast special case.
8647  *
8648  * Return:	Non-negative on success/Negative on failure
8649  *
8650  * Programmer:	Raymond Lu
8651  *		Friday, November 7, 2003
8652  *
8653  * Modifications:
8654  *
8655  *-------------------------------------------------------------------------
8656  */
8657 herr_t
H5T__conv_float_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8658 H5T__conv_float_llong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8659 		       size_t nelmts, size_t buf_stride,
8660                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8661                        hid_t H5_ATTR_UNUSED dxpl_id)
8662 {
8663 H5_GCC_DIAG_OFF(float-equal)
8664     H5T_CONV_Fx(FLOAT, LLONG, float, long long, LLONG_MIN, LLONG_MAX);
8665 H5_GCC_DIAG_ON(float-equal)
8666 }
8667 
8668 
8669 /*-------------------------------------------------------------------------
8670  * Function:	H5T__conv_float_ullong
8671  *
8672  * Purpose:	Convert native float to native unsigned long long using
8673  *              hardware.  This is a fast special case.
8674  *
8675  * Return:	Non-negative on success/Negative on failure
8676  *
8677  * Programmer:	Raymond Lu
8678  *		Friday, November 7, 2003
8679  *
8680  * Modifications:
8681  *
8682  *-------------------------------------------------------------------------
8683  */
8684 herr_t
H5T__conv_float_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8685 H5T__conv_float_ullong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8686 		       size_t nelmts, size_t buf_stride,
8687                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8688                        hid_t H5_ATTR_UNUSED dxpl_id)
8689 {
8690     H5T_CONV_Fx(FLOAT, ULLONG, float, unsigned long long, 0, ULLONG_MAX);
8691 }
8692 
8693 
8694 /*-------------------------------------------------------------------------
8695  * Function:	H5T__conv_double_llong
8696  *
8697  * Purpose:	Convert native double to native long long using
8698  *              hardware.  This is a fast special case.
8699  *
8700  * Return:	Non-negative on success/Negative on failure
8701  *
8702  * Programmer:	Raymond Lu
8703  *		Friday, November 7, 2003
8704  *
8705  * Modifications:
8706  *
8707  *-------------------------------------------------------------------------
8708  */
8709 herr_t
H5T__conv_double_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8710 H5T__conv_double_llong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8711 		       size_t nelmts, size_t buf_stride,
8712                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8713                        hid_t H5_ATTR_UNUSED dxpl_id)
8714 {
8715 H5_GCC_DIAG_OFF(float-equal)
8716     H5T_CONV_Fx(DOUBLE, LLONG, double, long long, LLONG_MIN, LLONG_MAX);
8717 H5_GCC_DIAG_ON(float-equal)
8718 }
8719 
8720 
8721 /*-------------------------------------------------------------------------
8722  * Function:	H5T__conv_double_ullong
8723  *
8724  * Purpose:	Convert native double to native unsigned long long using
8725  *              hardware.  This is a fast special case.
8726  *
8727  * Return:	Non-negative on success/Negative on failure
8728  *
8729  * Programmer:	Raymond Lu
8730  *		Friday, November 7, 2003
8731  *
8732  * Modifications:
8733  *
8734  *-------------------------------------------------------------------------
8735  */
8736 herr_t
H5T__conv_double_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t dxpl_id)8737 H5T__conv_double_ullong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8738 		       size_t nelmts, size_t buf_stride,
8739                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8740                        hid_t dxpl_id)
8741 {
8742     H5T_CONV_Fx(DOUBLE, ULLONG, double, unsigned long long, 0, ULLONG_MAX);
8743 }
8744 
8745 
8746 /*-------------------------------------------------------------------------
8747  * Function:	H5T__conv_ldouble_llong
8748  *
8749  * Purpose:	Convert native long double to native long long using
8750  *              hardware.  This is a fast special case.
8751  *
8752  * Return:	Non-negative on success/Negative on failure
8753  *
8754  * Programmer:	Raymond Lu
8755  *		Tuesday, Febuary 1, 2005
8756  *
8757  * Modifications:
8758  *
8759  *-------------------------------------------------------------------------
8760  */
8761 #if H5T_CONV_INTERNAL_LDOUBLE_LLONG
8762 herr_t
H5T__conv_ldouble_llong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t H5_ATTR_UNUSED dxpl_id)8763 H5T__conv_ldouble_llong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8764 		       size_t nelmts, size_t buf_stride,
8765                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8766                        hid_t H5_ATTR_UNUSED dxpl_id)
8767 {
8768 H5_GCC_DIAG_OFF(float-equal)
8769     H5T_CONV_Fx(LDOUBLE, LLONG, long double, long long, LLONG_MIN, LLONG_MAX);
8770 H5_GCC_DIAG_ON(float-equal)
8771 }
8772 #endif /*H5T_CONV_INTERNAL_LDOUBLE_LLONG*/
8773 
8774 
8775 /*-------------------------------------------------------------------------
8776  * Function:	H5T__conv_ldouble_ullong
8777  *
8778  * Purpose:	Convert native long double to native unsigned long long using
8779  *              hardware.  This is a fast special case.
8780  *
8781  * Return:	Non-negative on success/Negative on failure
8782  *
8783  * Programmer:	Raymond Lu
8784  *		Tuesday, Febuary 1, 2005
8785  *
8786  * Modifications:
8787  *
8788  *-------------------------------------------------------------------------
8789  */
8790 #if H5T_CONV_INTERNAL_LDOUBLE_ULLONG
8791 herr_t
H5T__conv_ldouble_ullong(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t dxpl_id)8792 H5T__conv_ldouble_ullong (hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata,
8793 		       size_t nelmts, size_t buf_stride,
8794                        size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8795                        hid_t dxpl_id)
8796 {
8797     H5T_CONV_Fx(LDOUBLE, ULLONG, long double, unsigned long long, 0, ULLONG_MAX);
8798 }
8799 #endif /*H5T_CONV_INTERNAL_LDOUBLE_ULLONG*/
8800 
8801 
8802 /*-------------------------------------------------------------------------
8803  * Function:	H5T__conv_f_i
8804  *
8805  * Purpose:	Convert one floating-point type to an integer.  This is
8806  *              the catch-all function for float-integer conversions and
8807  *              is probably not particularly fast.
8808  *
8809  * Return:	Non-negative on success/Negative on failure
8810  *
8811  * Programmer:	Raymond Lu
8812  *		Wednesday, Jan 21, 2004
8813  *
8814  * Modifications:
8815  *
8816  *              Raymond Lu
8817  *              Wednesday, April 21, 2004
8818  *              There is a new design for exception handling like overflow,
8819  *              which is passed in as a transfer property.
8820  *
8821  *              Raymond Lu
8822  *              Monday, March 13, 2006
8823  *              Added support for VAX floating-point types.
8824  *-------------------------------------------------------------------------
8825  */
8826 herr_t
H5T__conv_f_i(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t dxpl_id)8827 H5T__conv_f_i(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
8828     size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
8829     hid_t dxpl_id)
8830 {
8831     /* Traversal-related variables */
8832     H5T_t	*src_p;			/*source datatype		*/
8833     H5T_t	*dst_p;			/*destination datatype		*/
8834     H5T_atomic_t src;			/*atomic source info		*/
8835     H5T_atomic_t dst;			/*atomic destination info	*/
8836     int	direction;		        /*forward or backward traversal	*/
8837     size_t	elmtno;			/*element number		*/
8838     size_t	half_size;		/*half the type size		*/
8839     size_t      tsize;                  /*type size for swapping bytes  */
8840     size_t	olap;			/*num overlapping elements	*/
8841     uint8_t	*s, *sp, *d, *dp;	/*source and dest traversal ptrs*/
8842     uint8_t     *src_rev=NULL;          /*order-reversed source buffer  */
8843     uint8_t	dbuf[64];		/*temp destination buffer	*/
8844     uint8_t     tmp1, tmp2;             /*temp variables for swapping bytes*/
8845 
8846     /* Conversion-related variables */
8847     hssize_t	expo;			/*source exponent		*/
8848     hssize_t    sign;                   /*source sign bit value         */
8849     uint8_t     *int_buf=NULL;          /*buffer for temporary value    */
8850     size_t      buf_size;               /*buffer size for temporary value */
8851     size_t	i;			/*miscellaneous counters	*/
8852     size_t	first;                  /*first bit(MSB) in an integer  */
8853     ssize_t	sfirst;			/*a signed version of `first'	*/
8854     H5P_genplist_t      *plist;         /*Property list pointer         */
8855     H5T_conv_cb_t       cb_struct={NULL, NULL};      /*conversion callback structure */
8856     hbool_t     truncated;              /*if fraction value is dropped  */
8857     hbool_t     reverse;                /*if reverse order of destination at the end */
8858     H5T_conv_ret_t      except_ret;     /*return of callback function   */
8859     herr_t      ret_value=SUCCEED;      /* Return value                 */
8860 
8861     FUNC_ENTER_PACKAGE
8862 
8863     switch(cdata->command) {
8864         case H5T_CONV_INIT:
8865             if(NULL == (src_p = (H5T_t*)H5I_object(src_id)) || NULL == (dst_p = (H5T_t*)H5I_object(dst_id)))
8866                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
8867             src = src_p->shared->u.atomic;
8868             dst = dst_p->shared->u.atomic;
8869             if(H5T_ORDER_LE != src.order && H5T_ORDER_BE != src.order && H5T_ORDER_VAX != src.order)
8870                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
8871             if(dst_p->shared->size > sizeof(dbuf))
8872                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination size is too large")
8873             if(8 * sizeof(expo) - 1 < src.u.f.esize)
8874                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "exponent field is too large")
8875             cdata->need_bkg = H5T_BKG_NO;
8876             break;
8877 
8878         case H5T_CONV_FREE:
8879             break;
8880 
8881         case H5T_CONV_CONV:
8882             /* Get the datatypes */
8883             if(NULL == (src_p = (H5T_t*)H5I_object(src_id)) || NULL == (dst_p = (H5T_t*)H5I_object(dst_id)))
8884                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
8885             src = src_p->shared->u.atomic;
8886             dst = dst_p->shared->u.atomic;
8887 
8888             /*
8889              * Do we process the values from beginning to end or vice versa? Also,
8890              * how many of the elements have the source and destination areas
8891              * overlapping?
8892              */
8893             if(src_p->shared->size==dst_p->shared->size || buf_stride) {
8894                 sp = dp = (uint8_t*)buf;
8895                 direction = 1;
8896                 olap = nelmts;
8897             } else if (src_p->shared->size>=dst_p->shared->size) {
8898                 double olap_d = HDceil((double)(dst_p->shared->size)/
8899                                        (double)(src_p->shared->size-dst_p->shared->size));
8900                 olap = (size_t)olap_d;
8901                 sp = dp = (uint8_t*)buf;
8902                 direction = 1;
8903             } else {
8904                 double olap_d = HDceil((double)(src_p->shared->size)/
8905                                        (double)(dst_p->shared->size-src_p->shared->size));
8906                 olap = (size_t)olap_d;
8907                 sp = (uint8_t*)buf + (nelmts-1) * src_p->shared->size;
8908                 dp = (uint8_t*)buf + (nelmts-1) * dst_p->shared->size;
8909                 direction = -1;
8910             }
8911 
8912             /* Allocate enough space for the buffer holding temporary
8913              * converted value
8914              */
8915             buf_size = (size_t)HDpow((double)2.0f, (double)src.u.f.esize) / 8 + 1;
8916             int_buf = (uint8_t*)H5MM_calloc(buf_size);
8917 
8918             /* Get the plist structure. Do I need to close it? */
8919             if(NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER)))
8920                 HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
8921 
8922             /* Get conversion exception callback property */
8923             if(H5P_get(plist, H5D_XFER_CONV_CB_NAME, &cb_struct) < 0)
8924                 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get conversion exception callback")
8925 
8926             /* Allocate space for order-reversed source buffer */
8927             src_rev = (uint8_t*)H5MM_calloc(src_p->shared->size);
8928 
8929             /* The conversion loop */
8930             for(elmtno = 0; elmtno < nelmts; elmtno++) {
8931                 /* Set these variables to default */
8932                 except_ret = H5T_CONV_UNHANDLED;
8933                 truncated  = FALSE;
8934                 reverse    = TRUE;
8935 
8936                 /*
8937                  * If the source and destination buffers overlap then use a
8938                  * temporary buffer for the destination.
8939                  */
8940                 if(direction > 0) {
8941                     s = sp;
8942                     d = elmtno<olap ? dbuf : dp;
8943                 } else {
8944                     s = sp;
8945                     d = elmtno+olap >= nelmts ? dbuf : dp;
8946                 }
8947 #ifndef NDEBUG
8948                 /* I don't quite trust the overlap calculations yet --rpm */
8949                 if (d==dbuf) {
8950                     HDassert((dp>=sp && dp<sp+src_p->shared->size) ||
8951                             (sp>=dp && sp<dp+dst_p->shared->size));
8952                 } else {
8953                     HDassert((dp<sp && dp+dst_p->shared->size<=sp) ||
8954                             (sp<dp && sp+src_p->shared->size<=dp));
8955                 }
8956 #endif
8957                 /*
8958                  * Put the data in little endian order so our loops aren't so
8959                  * complicated.  We'll do all the conversion stuff assuming
8960                  * little endian and then we'll fix the order at the end.
8961                  */
8962                 if (H5T_ORDER_BE==src.order) {
8963                     half_size = src_p->shared->size/2;
8964                     for (i=0; i<half_size; i++) {
8965                         tmp1 = s[src_p->shared->size-(i+1)];
8966                         s[src_p->shared->size-(i+1)] = s[i];
8967                         s[i] = tmp1;
8968                     }
8969                 } else if (H5T_ORDER_VAX==src.order) {
8970                     tsize = src_p->shared->size;
8971                     HDassert(0 == tsize % 2);
8972 
8973                     for (i = 0; i < tsize; i += 4) {
8974                         tmp1 = s[i];
8975                         tmp2 = s[i+1];
8976 
8977                         s[i] = s[(tsize-2)-i];
8978                         s[i+1] = s[(tsize-1)-i];
8979 
8980                         s[(tsize-2)-i] = tmp1;
8981                         s[(tsize-1)-i] = tmp2;
8982                     }
8983                 }
8984 
8985                 /*zero-set all destination bits*/
8986                 H5T__bit_set (d, dst.offset, dst.prec, FALSE);
8987 
8988                 /*
8989                  * Find the sign bit value of the source.
8990                  */
8991                 sign = H5T__bit_get_d(s, src.u.f.sign, (size_t)1);
8992 
8993                 /*
8994                  * Check for special cases: +0, -0, +Inf, -Inf, NaN
8995                  */
8996                 if (H5T__bit_find (s, src.u.f.mpos, src.u.f.msize,
8997                                   H5T_BIT_LSB, TRUE)<0) {
8998                     if (H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
8999                                       H5T_BIT_LSB, TRUE)<0) {
9000                         /* +0 or -0 */
9001                         /* Set all bits to zero */
9002                         goto padding;
9003                     } else if (H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
9004                                              H5T_BIT_LSB, FALSE)<0) {
9005                         /* +Infinity or -Infinity */
9006                         if(sign) { /* -Infinity */
9007                             if(cb_struct.func) { /*If user's exception handler is present, use it*/
9008                                 /*reverse order first*/
9009                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9010                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_NINF,
9011                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9012                             }
9013 
9014                             if(except_ret == H5T_CONV_UNHANDLED) {
9015                                 if (H5T_SGN_2==dst.u.i.sign)
9016                                     H5T__bit_set (d, dst.prec-1, (size_t)1, TRUE);
9017                             } else if(except_ret == H5T_CONV_HANDLED) {
9018                                 /*No need to reverse the order of destination because user handles it*/
9019                                 reverse = FALSE;
9020                                 goto next;
9021                             } else if(except_ret == H5T_CONV_ABORT)
9022                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9023                         } else { /* +Infinity */
9024                             if(cb_struct.func) { /*If user's exception handler is present, use it*/
9025                                 /*reverse order first*/
9026                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9027                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_PINF,
9028                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9029                             }
9030 
9031                             if(except_ret == H5T_CONV_UNHANDLED) {
9032                                 if (H5T_SGN_NONE==dst.u.i.sign)
9033                                     H5T__bit_set (d, dst.offset, dst.prec, TRUE);
9034                                 else if (H5T_SGN_2==dst.u.i.sign)
9035                                     H5T__bit_set (d, dst.offset, dst.prec-1, TRUE);
9036                             } else if(except_ret == H5T_CONV_HANDLED) {
9037                                 /*No need to reverse the order of destination because user handles it*/
9038                                 reverse = FALSE;
9039                                 goto next;
9040                             } else if(except_ret == H5T_CONV_ABORT)
9041                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9042                         }
9043                         goto padding;
9044                     }
9045                 } else if (H5T_NORM_NONE==src.u.f.norm && H5T__bit_find (s, src.u.f.mpos, src.u.f.msize-1,
9046                                   H5T_BIT_LSB, TRUE)<0 && H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
9047                                   H5T_BIT_LSB, FALSE)<0) {
9048                     /*This is a special case for the source of no implied mantissa bit.
9049                      *If the exponent bits are all 1s and only the 1st bit of mantissa
9050                      *is set to 1.  It's infinity. The Intel-Linux "long double" is this case.*/
9051                     /* +Infinity or -Infinity */
9052                     if(sign) { /* -Infinity */
9053                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
9054                             /*reverse order first*/
9055                             H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9056                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_NINF,
9057                                     src_id, dst_id, src_rev, d, cb_struct.user_data);
9058                         }
9059 
9060                         if(except_ret == H5T_CONV_UNHANDLED) {
9061                             if (H5T_SGN_2==dst.u.i.sign)
9062                                 H5T__bit_set (d, dst.prec-1, (size_t)1, TRUE);
9063                         } else if(except_ret == H5T_CONV_HANDLED) {
9064                             /*No need to reverse the order of destination because user handles it*/
9065                             reverse = FALSE;
9066                             goto next;
9067                         } else if(except_ret == H5T_CONV_ABORT)
9068                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9069                     } else { /* +Infinity */
9070                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
9071                             /*reverse order first*/
9072                             H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9073                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_PINF,
9074                                     src_id, dst_id, src_rev, d, cb_struct.user_data);
9075                         }
9076 
9077                         if(except_ret == H5T_CONV_UNHANDLED) {
9078                             if (H5T_SGN_NONE==dst.u.i.sign)
9079                                 H5T__bit_set (d, dst.offset, dst.prec, TRUE);
9080                             else if (H5T_SGN_2==dst.u.i.sign)
9081                                 H5T__bit_set (d, dst.offset, dst.prec-1, TRUE);
9082                         } else if(except_ret == H5T_CONV_HANDLED) {
9083                             /*No need to reverse the order of destination because user handles it*/
9084                             reverse = FALSE;
9085                             goto next;
9086                         } else if(except_ret == H5T_CONV_ABORT)
9087                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9088                     }
9089                     goto padding;
9090                 } else if (H5T__bit_find (s, src.u.f.epos, src.u.f.esize,
9091                                          H5T_BIT_LSB, FALSE)<0) {
9092                     /* NaN */
9093                     if(cb_struct.func) { /*If user's exception handler is present, use it*/
9094                         /*reverse order first*/
9095                         H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9096                         except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_NAN,
9097                                 src_id, dst_id, src_rev, d, cb_struct.user_data);
9098                     }
9099 
9100                     if(except_ret == H5T_CONV_UNHANDLED) {
9101                         /*Just set all bits to zero.*/
9102                         goto padding;
9103                     } else if(except_ret == H5T_CONV_HANDLED) {
9104                         /*No need to reverse the order of destination because user handles it*/
9105                         reverse = FALSE;
9106                         goto next;
9107                     } else if(except_ret == H5T_CONV_ABORT)
9108                         HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9109 
9110                     goto padding;
9111                 }
9112 
9113                 /*
9114                  * Get the exponent as an unsigned quantity from the section of
9115                  * the source bit field where it's located.   Not expecting
9116                  * exponent to be greater than the maximal value of hssize_t.
9117                  */
9118                 expo = H5T__bit_get_d(s, src.u.f.epos, src.u.f.esize);
9119 
9120                 /*
9121                  * Calculate the true source exponent by adjusting according to
9122                  * the source exponent bias.
9123                  */
9124                 if (0==expo || H5T_NORM_NONE==src.u.f.norm) {
9125                     expo -= (src.u.f.ebias-1);
9126                 } else if (H5T_NORM_IMPLIED==src.u.f.norm) {
9127                     expo -= src.u.f.ebias;
9128                 } else {
9129                     HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
9130                 }
9131 
9132                 /*
9133                  * Get the mantissa as bit vector from the section of
9134                  * the source bit field where it's located.
9135                  * Keep the little-endian order in the buffer.
9136                  * A sequence 0x01020304 will be like in the buffer,
9137                  *      04      03      02      01
9138                  *      |       |       |       |
9139                  *      V       V       V       V
9140                  *    buf[0]  buf[1]  buf[2]  buf[3]
9141                  */
9142                 H5T__bit_copy(int_buf, (size_t)0, s, src.u.f.mpos, src.u.f.msize);
9143 
9144                 /*
9145                  * Restore the implicit bit for mantissa if it's implied.
9146                  * Equivalent to mantissa |= (hsize_t)1<<src.u.f.msize.
9147                  */
9148                 if(H5T_NORM_IMPLIED == src.u.f.norm)
9149                     H5T__bit_inc(int_buf, src.u.f.msize, 8 * buf_size - src.u.f.msize);
9150 
9151                 /*
9152                  * Shift mantissa part by exponent minus mantissa size(right shift),
9153                  * or by mantissa size minus exponent(left shift).  Example: Sequence
9154                  * 10...010111, expo=20, expo-msize=-3.  Right-shift the sequence, we get
9155                  * 00010...10.  The last three bits were dropped.
9156                  */
9157                 H5T__bit_shift(int_buf, (ssize_t)(expo-src.u.f.msize), (size_t)0, buf_size * 8);
9158 
9159                 /*
9160                  * If expo is less than mantissa size, the frantional value is dropped off
9161                  * during conversion.  Set exception type to be "truncate"
9162                  */
9163                 if ((size_t)expo < src.u.f.msize && cb_struct.func)
9164                     truncated = TRUE;
9165 
9166                 /*
9167                  * What is the bit position for the most significant bit(MSB) of S
9168                  * which is set?  This is checked before converted to negative
9169                  * integer.
9170                  */
9171                 sfirst = H5T__bit_find(int_buf, (size_t)0, 8 * buf_size, H5T_BIT_MSB, TRUE);
9172                 first = (size_t)sfirst;
9173 
9174                 if(sfirst < 0) {
9175                     /*
9176                      * The source has no bits set and must therefore be zero.
9177                      * Set the destination to zero - nothing to do.
9178                      */
9179                 } else if (H5T_SGN_NONE==dst.u.i.sign) { /*destination is unsigned*/
9180                     /*
9181                      * Destination is unsigned.  Library's default way: If the source value
9182                      * is greater than the maximal destination value then it overflows, the
9183                      * destination will be set to the maximum possible value.  When the
9184                      * source is negative, underflow happens.  Set the destination to be
9185                      * zero(do nothing).  If user's exception handler is set, call it and
9186                      * let user handle it.
9187                      */
9188                     if(sign) { /*source is negative*/
9189                         if(cb_struct.func) { /*If user's exception handler is present, use it*/
9190                             /*reverse order first*/
9191                             H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9192                             except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW,
9193                                     src_id, dst_id, src_rev, d, cb_struct.user_data);
9194                             if(except_ret == H5T_CONV_ABORT)
9195                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9196                             else if(except_ret == H5T_CONV_HANDLED) {
9197                                 /*No need to reverse the order of destination because user handles it*/
9198                                 reverse = FALSE;
9199                                 goto next;
9200                             }
9201                         }
9202                     } else { /*source is positive*/
9203                         if (first>=dst.prec) {
9204                             /*overflow*/
9205                             if(cb_struct.func) { /*If user's exception handler is present, use it*/
9206                                 /*reverse order first*/
9207                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9208                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI,
9209                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9210                             }
9211 
9212                             if(except_ret == H5T_CONV_UNHANDLED)
9213                                 H5T__bit_set (d, dst.offset, dst.prec, TRUE);
9214                             else if(except_ret == H5T_CONV_HANDLED) {
9215                                 /*No need to reverse the order of destination because user handles it*/
9216                                 reverse = FALSE;
9217                                 goto next;
9218                             } else if(except_ret == H5T_CONV_ABORT)
9219                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9220                         } else if (first <dst.prec) {
9221                             if(truncated && cb_struct.func) { /*If user's exception handler is present, use it*/
9222                                 /*reverse order first*/
9223                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9224                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_TRUNCATE,
9225                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9226                             }
9227 
9228                             if(except_ret == H5T_CONV_UNHANDLED)
9229                                 /*copy source value into it if case is ignored by user handler*/
9230                                 H5T__bit_copy (d, dst.offset, int_buf, (size_t)0, first+1);
9231                             else if(except_ret == H5T_CONV_HANDLED) {
9232                                 /*No need to reverse the order of destination because user handles it*/
9233                                 reverse = FALSE;
9234                                 goto next;
9235                             } else if(except_ret == H5T_CONV_ABORT)
9236                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9237                         }
9238                     }
9239                 } else if (H5T_SGN_2==dst.u.i.sign) {  /*Destination is signed*/
9240                     if(sign) { /*source is negative*/
9241                         if(first < dst.prec-1) {
9242                             if(truncated && cb_struct.func) { /*If user's exception handler is present, use it*/
9243                                 /*reverse order first*/
9244                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9245                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_TRUNCATE,
9246                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9247                             }
9248 
9249                             if(except_ret == H5T_CONV_UNHANDLED) { /*If this case ignored by user handler*/
9250                                 /*Convert to integer representation.  Equivalent to ~(value - 1).*/
9251                                 H5T__bit_dec(int_buf, (size_t)0, 8 * buf_size);
9252                                 H5T__bit_neg(int_buf, (size_t)0, 8 * buf_size);
9253 
9254                                 /*copy source value into destination*/
9255                                 H5T__bit_copy(d, dst.offset, int_buf, (size_t)0, dst.prec-1);
9256                                 H5T__bit_set(d, (dst.offset + dst.prec-1), (size_t)1, TRUE);
9257                             } else if(except_ret == H5T_CONV_ABORT)
9258                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9259                             else if(except_ret == H5T_CONV_HANDLED) {
9260                                 /*No need to reverse the order of destination because user handles it*/
9261                                 reverse = FALSE;
9262                                 goto next;
9263                             }
9264                         } else {
9265                             /* if underflows and no callback, do nothing except turn on
9266                              * the sign bit because 0x80...00 is the biggest negative value.
9267                              */
9268                             if(cb_struct.func) { /*If user's exception handler is present, use it*/
9269                                 /*reverse order first*/
9270                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9271                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_LOW,
9272                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9273                             }
9274 
9275                             if(except_ret == H5T_CONV_UNHANDLED)
9276                                 H5T__bit_set(d, (dst.offset + dst.prec-1), (size_t)1, TRUE);
9277                             else if(except_ret == H5T_CONV_ABORT)
9278                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9279                             else if(except_ret == H5T_CONV_HANDLED) {
9280                                 /*No need to reverse the order of destination because user handles it*/
9281                                 reverse = FALSE;
9282                                 goto next;
9283                             }
9284                         }
9285                     } else { /*source is positive*/
9286                         if (first >= dst.prec-1) {
9287                             /*overflow*/
9288                             if(cb_struct.func) { /*If user's exception handler is present, use it*/
9289                                 /*reverse order first*/
9290                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9291                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI,
9292                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9293                             }
9294 
9295                             if(except_ret == H5T_CONV_UNHANDLED)
9296                                 H5T__bit_set(d, dst.offset, dst.prec-1, TRUE);
9297                             else if(except_ret == H5T_CONV_ABORT)
9298                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9299                             else if(except_ret == H5T_CONV_HANDLED) {
9300                                 /*No need to reverse the order of destination because user handles it*/
9301                                 reverse = FALSE;
9302                                 goto next;
9303                             }
9304                         } else if(first < dst.prec-1) {
9305                             if(truncated && cb_struct.func) { /*If user's exception handler is present, use it*/
9306                                 /*reverse order first*/
9307                                 H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order);
9308                                 except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_TRUNCATE,
9309                                         src_id, dst_id, src_rev, d, cb_struct.user_data);
9310                             }
9311 
9312                             if(except_ret == H5T_CONV_UNHANDLED) {
9313                                 /*copy source value into it if case is ignored by user handler*/
9314                                 H5T__bit_copy (d, dst.offset, int_buf, (size_t)0, first+1);
9315                             } else if(except_ret == H5T_CONV_ABORT)
9316                                 HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9317                             else if(except_ret == H5T_CONV_HANDLED) {
9318                                 /*No need to reverse the order of destination because user handles it*/
9319                                 reverse = FALSE;
9320                                 goto next;
9321                             }
9322                         }
9323                     }
9324                 }
9325 
9326             padding:
9327                 /*
9328                  * Set padding areas in destination.
9329                  */
9330                 if (dst.offset>0) {
9331                     HDassert(H5T_PAD_ZERO==dst.lsb_pad || H5T_PAD_ONE==dst.lsb_pad);
9332                     H5T__bit_set(d, (size_t)0, dst.offset, (hbool_t)(H5T_PAD_ONE==dst.lsb_pad));
9333                 }
9334                 if (dst.offset+dst.prec!=8*dst_p->shared->size) {
9335                     HDassert(H5T_PAD_ZERO==dst.msb_pad || H5T_PAD_ONE==dst.msb_pad);
9336                     H5T__bit_set(d, dst.offset+dst.prec,
9337                                  8*dst_p->shared->size - (dst.offset+ dst.prec),
9338                                  (hbool_t)(H5T_PAD_ONE==dst.msb_pad));
9339                 }
9340 
9341                 /*
9342                  * Put the destination in the correct byte order.  See note at
9343                  * beginning of loop.
9344                  */
9345                 if (H5T_ORDER_BE==dst.order && reverse) {
9346                     half_size = dst_p->shared->size/2;
9347                     for (i=0; i<half_size; i++) {
9348                         tmp1 = d[dst_p->shared->size-(i+1)];
9349                         d[dst_p->shared->size-(i+1)] = d[i];
9350                         d[i] = tmp1;
9351                     }
9352                 }
9353 
9354             next:
9355                 /*
9356                  * If we had used a temporary buffer for the destination then we
9357                  * should copy the value to the true destination buffer.
9358                  */
9359                 if (d==dbuf)
9360                     HDmemcpy (dp, d, dst_p->shared->size);
9361                 if (buf_stride) {
9362                     sp += direction * buf_stride;
9363                     dp += direction * buf_stride;
9364                 } else {
9365                     sp += direction * src_p->shared->size;
9366                     dp += direction * dst_p->shared->size;
9367                 }
9368 
9369                 HDmemset(int_buf, 0, buf_size);
9370             }
9371 
9372             break;
9373 
9374         default:
9375             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
9376     } /* end switch */
9377 
9378 done:
9379     if(int_buf)
9380         H5MM_xfree(int_buf);
9381     if(src_rev)
9382         H5MM_free(src_rev);
9383 
9384     FUNC_LEAVE_NOAPI(ret_value)
9385 } /* end H5T__conv_f_i() */
9386 
9387 
9388 /*-------------------------------------------------------------------------
9389  * Function:	H5T__conv_i_f
9390  *
9391  * Purpose:	Convert one integer type to a floating-point type.  This is
9392  *              the catch-all function for integer-float conversions and
9393  *              is probably not particularly fast.
9394  *
9395  * Return:	Non-negative on success/Negative on failure
9396  *
9397  * Programmer:	Raymond Lu
9398  *		Friday, Feb 6, 2004
9399  *
9400  * Modifications:
9401  *
9402  *              Raymond Lu
9403  *              Wednesday, April 21, 2004
9404  *              There is a new design for exception handling like overflow,
9405  *              which is passed in as a transfer property.
9406  *
9407  *              Raymond Lu
9408  *              Monday, March 13, 2006
9409  *              Added support for VAX floating-point types.
9410  *-------------------------------------------------------------------------
9411  */
9412 herr_t
H5T__conv_i_f(hid_t src_id,hid_t dst_id,H5T_cdata_t * cdata,size_t nelmts,size_t buf_stride,size_t H5_ATTR_UNUSED bkg_stride,void * buf,void H5_ATTR_UNUSED * bkg,hid_t dxpl_id)9413 H5T__conv_i_f(hid_t src_id, hid_t dst_id, H5T_cdata_t *cdata, size_t nelmts,
9414     size_t buf_stride, size_t H5_ATTR_UNUSED bkg_stride, void *buf, void H5_ATTR_UNUSED *bkg,
9415     hid_t dxpl_id)
9416 {
9417     /* Traversal-related variables */
9418     H5T_t	*src_p;			/*source datatype		*/
9419     H5T_t	*dst_p;			/*destination datatype		*/
9420     H5T_atomic_t src;			/*atomic source info		*/
9421     H5T_atomic_t dst;			/*atomic destination info	*/
9422     int	direction;		/*forward or backward traversal	*/
9423     size_t	elmtno;			/*element number		*/
9424     size_t	half_size;		/*half the type size		*/
9425     size_t      tsize;                  /*type size for swapping bytes  */
9426     size_t	olap;			/*num overlapping elements	*/
9427     uint8_t	*s, *sp, *d, *dp;	/*source and dest traversal ptrs*/
9428     uint8_t     *src_rev = NULL;        /*order-reversed source buffer  */
9429     uint8_t	dbuf[64];		/*temp destination buffer	*/
9430     uint8_t     tmp1, tmp2;             /*temp variables for swapping bytes*/
9431 
9432     /* Conversion-related variables */
9433     hsize_t	expo;			/*destination exponent		*/
9434     hsize_t	expo_max;		/*maximal possible exponent value       */
9435     size_t      sign;                   /*source sign bit value         */
9436     hbool_t     is_max_neg;             /*source is maximal negative value*/
9437     hbool_t     do_round;               /*whether there is roundup      */
9438     uint8_t     *int_buf = NULL;        /*buffer for temporary value    */
9439     size_t      buf_size;               /*buffer size for temporary value */
9440     size_t	i;			/*miscellaneous counters	*/
9441     size_t	first;                  /*first bit(MSB) in an integer  */
9442     ssize_t	sfirst;			/*a signed version of `first'	*/
9443     H5P_genplist_t      *plist;         /*Property list pointer         */
9444     H5T_conv_cb_t       cb_struct = {NULL, NULL};      /*conversion callback structure */
9445     H5T_conv_ret_t      except_ret;     /*return of callback function   */
9446     hbool_t             reverse;        /*if reverse the order of destination   */
9447     herr_t      ret_value = SUCCEED;    /* Return value */
9448 
9449     FUNC_ENTER_PACKAGE
9450 
9451     switch(cdata->command) {
9452         case H5T_CONV_INIT:
9453             if(NULL == (src_p = (H5T_t *)H5I_object(src_id)) || NULL == (dst_p = (H5T_t *)H5I_object(dst_id)))
9454                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
9455             src = src_p->shared->u.atomic;
9456             dst = dst_p->shared->u.atomic;
9457             if(H5T_ORDER_LE != dst.order && H5T_ORDER_BE != dst.order && H5T_ORDER_VAX != dst.order)
9458                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unsupported byte order")
9459             if(dst_p->shared->size > sizeof(dbuf))
9460                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "destination size is too large")
9461             if(8 * sizeof(expo) - 1 < src.u.f.esize)
9462                 HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "exponent field is too large")
9463             cdata->need_bkg = H5T_BKG_NO;
9464             break;
9465 
9466         case H5T_CONV_FREE:
9467             break;
9468 
9469         case H5T_CONV_CONV:
9470             /* Get the datatypes */
9471             if(NULL == (src_p = (H5T_t *)H5I_object(src_id)) || NULL == (dst_p = (H5T_t *)H5I_object(dst_id)))
9472                 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
9473             src = src_p->shared->u.atomic;
9474             dst = dst_p->shared->u.atomic;
9475 
9476             /*
9477              * Do we process the values from beginning to end or vice versa? Also,
9478              * how many of the elements have the source and destination areas
9479              * overlapping?
9480              */
9481             if (src_p->shared->size==dst_p->shared->size || buf_stride) {
9482                 sp = dp = (uint8_t*)buf;
9483                 direction = 1;
9484                 olap = nelmts;
9485             } else if (src_p->shared->size>=dst_p->shared->size) {
9486                 double olap_d = HDceil((double)(dst_p->shared->size)/
9487                                        (double)(src_p->shared->size-dst_p->shared->size));
9488                 olap = (size_t)olap_d;
9489                 sp = dp = (uint8_t*)buf;
9490                 direction = 1;
9491             } else {
9492                 double olap_d = HDceil((double)(src_p->shared->size)/
9493                                        (double)(dst_p->shared->size-src_p->shared->size));
9494                 olap = (size_t)olap_d;
9495                 sp = (uint8_t*)buf + (nelmts-1) * src_p->shared->size;
9496                 dp = (uint8_t*)buf + (nelmts-1) * dst_p->shared->size;
9497                 direction = -1;
9498             }
9499 
9500             /* Allocate enough space for the buffer holding temporary
9501              * converted value
9502              */
9503             buf_size = (src.prec > dst.u.f.msize ? src.prec : dst.u.f.msize)/8 + 1;
9504             int_buf = (uint8_t*)H5MM_calloc(buf_size);
9505 
9506             /* Get the plist structure */
9507             if(NULL == (plist = H5P_object_verify(dxpl_id,H5P_DATASET_XFER)))
9508                 HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find property list for ID")
9509 
9510             /* Get conversion exception callback property */
9511             if(H5P_get(plist,H5D_XFER_CONV_CB_NAME, &cb_struct) < 0)
9512                 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get conversion exception callback")
9513 
9514             /* Allocate space for order-reversed source buffer */
9515             src_rev = (uint8_t*)H5MM_calloc(src_p->shared->size);
9516 
9517             /* The conversion loop */
9518             for (elmtno=0; elmtno<nelmts; elmtno++) {
9519                 /* Set these variables to default */
9520                 except_ret = H5T_CONV_UNHANDLED;
9521                 reverse    = TRUE;
9522 
9523                 /* Make sure these variables are reset to 0. */
9524                 sign = 0;               /*source sign bit value         */
9525                 is_max_neg = 0;         /*source is maximal negative value*/
9526                 do_round = 0;           /*whether there is roundup      */
9527                 sfirst = 0;
9528 
9529                 /*
9530                  * If the source and destination buffers overlap then use a
9531                  * temporary buffer for the destination.
9532                  */
9533                 if (direction>0) {
9534                     s = sp;
9535                     d = elmtno<olap ? dbuf : dp;
9536                 } else {
9537                     s = sp;
9538                     d = elmtno+olap >= nelmts ? dbuf : dp;
9539                 }
9540 #ifndef NDEBUG
9541                 /* I don't quite trust the overlap calculations yet --rpm */
9542                 if (d==dbuf) {
9543                     HDassert((dp>=sp && dp<sp+src_p->shared->size) ||
9544                             (sp>=dp && sp<dp+dst_p->shared->size));
9545                 } else {
9546                     HDassert((dp<sp && dp+dst_p->shared->size<=sp) ||
9547                             (sp<dp && sp+src_p->shared->size<=dp));
9548                 }
9549 #endif
9550 
9551                 /*
9552                  * Put the data in little endian order so our loops aren't so
9553                  * complicated.  We'll do all the conversion stuff assuming
9554                  * little endian and then we'll fix the order at the end.
9555                  */
9556                 if (H5T_ORDER_BE==src.order) {
9557                     half_size = src_p->shared->size/2;
9558                     for (i=0; i<half_size; i++) {
9559                         tmp1 = s[src_p->shared->size-(i+1)];
9560                         s[src_p->shared->size-(i+1)] = s[i];
9561                         s[i] = tmp1;
9562                     }
9563                 }
9564 
9565                 /*zero-set all destination bits*/
9566                 H5T__bit_set (d, dst.offset, dst.prec, FALSE);
9567 
9568                 /* Copy source into a temporary buffer */
9569                 H5T__bit_copy(int_buf, (size_t)0, s, src.offset, src.prec);
9570 
9571                 /*
9572                  * Find the sign bit value of the source.
9573                  */
9574                 if(H5T_SGN_2 == src.u.i.sign)
9575                     sign = (size_t)H5T__bit_get_d(int_buf, src.prec - 1, (size_t)1);
9576 
9577                 /*
9578                  * What is the bit position(starting from 0 as first one) for the most significant
9579 		 * bit(MSB) of S which is set?
9580                  */
9581                 if(H5T_SGN_2 == src.u.i.sign) {
9582                     sfirst = H5T__bit_find(int_buf, (size_t)0, src.prec - 1, H5T_BIT_MSB, TRUE);
9583                     if(sign && sfirst < 0)
9584 			/* The case 0x80...00, which is negative with maximal value */
9585                         is_max_neg = 1;
9586                 } else if(H5T_SGN_NONE == src.u.i.sign)
9587                     sfirst = H5T__bit_find(int_buf, (size_t)0, src.prec, H5T_BIT_MSB, TRUE);
9588 
9589                 /* Handle special cases here.  Integer is zero */
9590                 if(!sign && sfirst < 0)
9591                     goto padding;
9592 
9593                 /*
9594                  * Convert source integer if it's negative
9595                  */
9596                 if(H5T_SGN_2 == src.u.i.sign && sign) {
9597                     if(!is_max_neg) {
9598                         /* Equivalent to ~(i - 1) */
9599                         H5T__bit_dec(int_buf, (size_t)0, buf_size * 8);
9600                         H5T__bit_neg(int_buf, (size_t)0, buf_size * 8);
9601                         sfirst = H5T__bit_find(int_buf, (size_t)0, src.prec - 1, H5T_BIT_MSB, TRUE);
9602                     } else {
9603 			/* If it's maximal negative number 0x80...000, treat it as if it overflowed
9604 			 * (create a carry) to help conversion.  i.e. a character type number 0x80
9605 			 * is treated as 0x100.
9606 			 */
9607                         sfirst = (ssize_t)(src.prec - 1);
9608                         is_max_neg = 0;
9609                     }
9610                     if(sfirst < 0)
9611                         HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "zero bit not found")
9612 
9613                     /* Sign bit has been negated if bit vector isn't 0x80...00.  Set all bits in front of
9614                      * sign bit to 0 in the temporary buffer because they're all negated from the previous
9615 		     * step. */
9616                     H5T__bit_set(int_buf, src.prec, (buf_size * 8) - src.prec, 0);
9617 
9618                     /* Set sign bit in destination */
9619                     H5T__bit_set_d(d, dst.u.f.sign, (size_t)1, (hsize_t)sign);
9620                 } /* end if */
9621 
9622                 first = (size_t)sfirst;
9623 
9624                 /*
9625                  * Calculate the true destination exponent by adjusting according to
9626                  * the destination exponent bias.  Implied and non-implied normalization
9627                  * should be the same.
9628                  */
9629                 if (H5T_NORM_NONE==dst.u.f.norm || H5T_NORM_IMPLIED==dst.u.f.norm) {
9630                     expo = first + dst.u.f.ebias;
9631                 } else {
9632                     HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "normalization method not implemented yet")
9633                 }
9634 
9635                 /* Handle mantissa part here */
9636                 if (H5T_NORM_IMPLIED==dst.u.f.norm) {
9637                     /* Imply first bit */
9638                     H5T__bit_set(int_buf, first, (size_t)1, 0);
9639        		} else if (H5T_NORM_NONE==dst.u.f.norm) {
9640 		    first++;
9641 		}
9642 
9643                 /* Roundup for mantissa */
9644                 if(first > dst.u.f.msize) {
9645 		    /* If the bit sequence is bigger than the mantissa part, there'll be some
9646                      * precision loss.  Let user's handler deal with the case if it's present
9647                      */
9648                     if(cb_struct.func) {
9649                         H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order); /*reverse order first*/
9650                         except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_PRECISION, src_id, dst_id,
9651                                 src_rev, d, cb_struct.user_data);
9652                     }
9653 
9654                     if(except_ret == H5T_CONV_HANDLED) {
9655                         reverse = FALSE;
9656                         goto padding;
9657                     } else if(except_ret == H5T_CONV_ABORT)
9658                         HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9659 
9660 		    /* If user's exception handler does deal with it, we do it by dropping off the
9661 		     * extra bits at the end and do rounding.  If we have .50...0(decimal) after radix
9662 		     * point, we do roundup when the least significant digit before radix is odd, we do
9663 		     * rounddown if it's even.
9664 		     */
9665 
9666                     /* Check 1st dropoff bit, see if it's set. */
9667                     if(H5T__bit_get_d(int_buf, ((first - dst.u.f.msize) - 1), (size_t)1)) {
9668                     	/* Check all bits after 1st dropoff bit, see if any of them is set. */
9669                         if(((first - dst.u.f.msize) - 1) > 0 && H5T__bit_get_d(int_buf, (size_t)0, ((first - dst.u.f.msize) - 1)))
9670                             do_round = 1;
9671                         else {  /* The .50...0 case */
9672                             /* Check if the least significant bit is odd. */
9673                             if(H5T__bit_get_d(int_buf, (first - dst.u.f.msize), (size_t)1))
9674                                do_round = 1;
9675                         }
9676 		    }
9677 
9678                     /* Right shift to drop off extra bits */
9679                     H5T__bit_shift(int_buf, (ssize_t)(dst.u.f.msize - first), (size_t)0, buf_size * 8);
9680 
9681                     if(do_round) {
9682                         H5T__bit_inc(int_buf, (size_t)0, buf_size * 8);
9683                         do_round = 0;
9684 
9685 			/* If integer is like 0x0ff...fff and we need to round up the
9686 			 * last f, we get 0x100...000.  Treat this special case here.
9687 			 */
9688                     	if(H5T__bit_get_d(int_buf, dst.u.f.msize, (size_t)1)) {
9689                 	    if (H5T_NORM_IMPLIED==dst.u.f.norm) {
9690 			        /* The bit at this 1's position was impled already, so this
9691 			         * number should be 0x200...000.  We need to increment the
9692 			         * exponent in this case.
9693 			         */
9694 			    	expo++;
9695        			    } else if (H5T_NORM_NONE==dst.u.f.norm) {
9696 				/* Right shift 1 bit to let the carried 1 fit in the mantissa,
9697 				 * and increment exponent by 1.
9698 				 */
9699                                 H5T__bit_shift(int_buf, (ssize_t)-1, (size_t)0, buf_size * 8);
9700 			 	expo++;
9701 			    }
9702 			}
9703                     }
9704                 } else {
9705                     /* The bit sequence can fit mantissa part.  Left shift to fit in from high-order of
9706 		     * bit position. */
9707                     H5T__bit_shift(int_buf, (ssize_t)(dst.u.f.msize - first), (size_t)0, dst.u.f.msize);
9708                 }
9709 
9710 
9711                 /* Check if the exponent is too big */
9712                 expo_max = (hsize_t)HDpow((double)2.0f, (double)dst.u.f.esize) - 1;
9713 
9714                 if(expo > expo_max) {  /*overflows*/
9715                     if(cb_struct.func) { /*user's exception handler.  Reverse back source order*/
9716                         H5T_reverse_order(src_rev, s, src_p->shared->size, src_p->shared->u.atomic.order); /*reverse order first*/
9717                         except_ret = (cb_struct.func)(H5T_CONV_EXCEPT_RANGE_HI, src_id, dst_id,
9718                                 src_rev, d, cb_struct.user_data);
9719 
9720                         if(except_ret == H5T_CONV_ABORT)
9721                             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCONVERT, FAIL, "can't handle conversion exception")
9722                         else if(except_ret == H5T_CONV_HANDLED) {
9723                             reverse = FALSE;
9724                             goto padding;
9725                         }
9726                     } else {
9727                         /*make destination infinity by setting exponent to maximal number and
9728                          *mantissa to zero.*/
9729                         expo = expo_max;
9730                         HDmemset(int_buf, 0, buf_size);
9731                     }
9732                 }
9733 
9734                 if(except_ret == H5T_CONV_UNHANDLED) {
9735                     /* Set exponent in destination */
9736                     H5T__bit_set_d(d, dst.u.f.epos, dst.u.f.esize, expo);
9737 
9738                     /* Copy mantissa into destination */
9739                     H5T__bit_copy(d, dst.u.f.mpos, int_buf, (size_t)0, (buf_size * 8) > dst.u.f.msize ? dst.u.f.msize : buf_size * 8);
9740                 }
9741 
9742             padding:
9743                 /*
9744                  * Set padding areas in destination.
9745                  */
9746                 if(dst.offset > 0) {
9747                     HDassert(H5T_PAD_ZERO == dst.lsb_pad || H5T_PAD_ONE == dst.lsb_pad);
9748                     H5T__bit_set(d, (size_t)0, dst.offset, (hbool_t)(H5T_PAD_ONE==dst.lsb_pad));
9749                 }
9750                 if(dst.offset + dst.prec != 8 * dst_p->shared->size) {
9751                     HDassert(H5T_PAD_ZERO == dst.msb_pad || H5T_PAD_ONE == dst.msb_pad);
9752                     H5T__bit_set(d, dst.offset + dst.prec,
9753                                  8 * dst_p->shared->size - (dst.offset + dst.prec),
9754                                  (hbool_t)(H5T_PAD_ONE == dst.msb_pad));
9755                 }
9756 
9757                 /*
9758                  * Put the destination in the correct byte order.  See note at
9759                  * beginning of loop.
9760                  */
9761                 if (H5T_ORDER_BE==dst.order && reverse) {
9762                     half_size = dst_p->shared->size/2;
9763                     for (i=0; i<half_size; i++) {
9764                         uint8_t tmp = d[dst_p->shared->size-(i+1)];
9765                         d[dst_p->shared->size-(i+1)] = d[i];
9766                         d[i] = tmp;
9767                     }
9768                 } else if (H5T_ORDER_VAX==dst.order && reverse) {
9769                     tsize = dst_p->shared->size;
9770                     HDassert(0 == tsize % 2);
9771 
9772                     for (i = 0; i < tsize; i += 4) {
9773                         tmp1 = d[i];
9774                         tmp2 = d[i+1];
9775 
9776                         d[i] = d[(tsize-2)-i];
9777                         d[i+1] = d[(tsize-1)-i];
9778 
9779                         d[(tsize-2)-i] = tmp1;
9780                         d[(tsize-1)-i] = tmp2;
9781                     }
9782                 }
9783 
9784                 /*
9785                  * If we had used a temporary buffer for the destination then we
9786                  * should copy the value to the true destination buffer.
9787                  */
9788                 if (d==dbuf)
9789                     HDmemcpy (dp, d, dst_p->shared->size);
9790                 if (buf_stride) {
9791                     sp += direction * buf_stride;
9792                     dp += direction * buf_stride;
9793                 } else {
9794                     sp += direction * src_p->shared->size;
9795                     dp += direction * dst_p->shared->size;
9796                 }
9797 
9798                 HDmemset(int_buf, 0, buf_size);
9799             }
9800 
9801             break;
9802 
9803         default:
9804             HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, FAIL, "unknown conversion command")
9805     } /* end switch */
9806 
9807 done:
9808     if(int_buf)
9809         H5MM_xfree(int_buf);
9810     if(src_rev)
9811         H5MM_free(src_rev);
9812 
9813     FUNC_LEAVE_NOAPI(ret_value)
9814 } /* end H5T__conv_i_f() */
9815 
9816 
9817 /*-------------------------------------------------------------------------
9818  * Function:	H5T_reverse_order
9819  *
9820  * Purpose:	Internal assisting function to reverse the order of
9821  *              a sequence of byte when it's big endian or VAX order.
9822  *              The byte sequence simulates the endian order.
9823  *
9824  * Return:      Success:        A pointer to the reversed byte sequence
9825  *
9826  *              Failure:        Null
9827  *
9828  * Programmer:	Raymond Lu
9829  *		April 26, 2004
9830  *
9831  * Modifications:
9832  *
9833  *              Raymond Lu
9834  *              March 13, 2006
9835  *              Add support for VAX floating-point types.
9836  *-------------------------------------------------------------------------
9837  */
9838 static herr_t
H5T_reverse_order(uint8_t * rev,uint8_t * s,size_t size,H5T_order_t order)9839 H5T_reverse_order(uint8_t *rev, uint8_t *s, size_t size, H5T_order_t order)
9840 {
9841     size_t      i;
9842 
9843     FUNC_ENTER_NOAPI_NOINIT_NOERR
9844 
9845     HDassert(s);
9846     HDassert(size);
9847 
9848     if (H5T_ORDER_VAX == order) {
9849         for (i = 0; i < size; i += 2) {
9850             rev[i] = s[(size - 2) - i];
9851             rev[i + 1] = s[(size - 1) - i];
9852         }
9853     } else if (H5T_ORDER_BE == order) {
9854         for (i=0; i<size; i++)
9855             rev[size-(i+1)] = s[i];
9856     } else {
9857         for (i=0; i<size; i++)
9858             rev[i] = s[i];
9859     }
9860 
9861     FUNC_LEAVE_NOAPI(SUCCEED)
9862 }
9863 
9864