~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/mach0data.ic

Merged in InnoDB Plugin tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
ulint
31
31
mach_read_from_1(
32
32
/*=============*/
33
 
                        /* out: ulint integer, >= 0, < 256 */
34
 
        byte*   b)      /* in: pointer to byte */
 
33
                                /* out: ulint integer, >= 0, < 256 */
 
34
        const byte*     b)      /* in: pointer to byte */
35
35
{
36
36
        ut_ad(b);
37
37
        return((ulint)(b[0]));
61
61
ulint
62
62
mach_read_from_2(
63
63
/*=============*/
64
 
                        /* out: ulint integer */
65
 
        byte*   b)      /* in: pointer to 2 bytes */
 
64
                                /* out: ulint integer */
 
65
        const byte*     b)      /* in: pointer to 2 bytes */
66
66
{
67
67
        ut_ad(b);
68
68
        return( ((ulint)(b[0]) << 8)
75
75
to the canonical format, for fast bytewise equality test
76
76
against memory. */
77
77
UNIV_INLINE
78
 
uint16_t
 
78
uint16
79
79
mach_encode_2(
80
80
/*==========*/
81
81
                        /* out: 16-bit integer in canonical format */
82
82
        ulint   n)      /* in: integer in machine-dependent format */
83
83
{
84
 
        uint16_t        ret;
 
84
        uint16  ret;
85
85
        ut_ad(2 == sizeof ret);
86
86
        mach_write_to_2((byte*) &ret, n);
87
87
        return(ret);
95
95
mach_decode_2(
96
96
/*==========*/
97
97
                        /* out: integer in machine-dependent format */
98
 
        uint16_t        n)      /* in: 16-bit integer in canonical format */
 
98
        uint16  n)      /* in: 16-bit integer in canonical format */
99
99
{
100
100
        ut_ad(2 == sizeof n);
101
 
        return(mach_read_from_2((byte*) &n));
 
101
        return(mach_read_from_2((const byte*) &n));
102
102
}
103
103
 
104
104
/***********************************************************
126
126
ulint
127
127
mach_read_from_3(
128
128
/*=============*/
129
 
                        /* out: ulint integer */
130
 
        byte*   b)      /* in: pointer to 3 bytes */
 
129
                                /* out: ulint integer */
 
130
        const byte*     b)      /* in: pointer to 3 bytes */
131
131
{
132
132
        ut_ad(b);
133
133
        return( ((ulint)(b[0]) << 16)
161
161
ulint
162
162
mach_read_from_4(
163
163
/*=============*/
164
 
                        /* out: ulint integer */
165
 
        byte*   b)      /* in: pointer to four bytes */
 
164
                                /* out: ulint integer */
 
165
        const byte*     b)      /* in: pointer to four bytes */
166
166
{
167
167
        ut_ad(b);
168
168
        return( ((ulint)(b[0]) << 24)
236
236
ulint
237
237
mach_read_compressed(
238
238
/*=================*/
239
 
                        /* out: read integer (< 2^32) */
240
 
        byte*   b)      /* in: pointer to memory from where to read */
 
239
                                /* out: read integer (< 2^32) */
 
240
        const byte*     b)      /* in: pointer to memory from where to read */
241
241
{
242
242
        ulint   flag;
243
243
 
275
275
        mach_write_to_4(b + 4, ut_dulint_get_low(n));
276
276
}
277
277
 
 
278
/***********************************************************
 
279
The following function is used to store data in 8 consecutive
 
280
bytes. We store the most significant byte to the lowest address. */
 
281
UNIV_INLINE
 
282
void
 
283
mach_write_ull(
 
284
/*===========*/
 
285
        byte*           b,      /* in: pointer to 8 bytes where to store */
 
286
        ib_uint64_t     n)      /* in: 64-bit integer to be stored */
 
287
{
 
288
        ut_ad(b);
 
289
 
 
290
        mach_write_to_4(b, (ulint) (n >> 32));
 
291
        mach_write_to_4(b + 4, (ulint) n);
 
292
}
 
293
 
278
294
/************************************************************
279
295
The following function is used to fetch data from 8 consecutive
280
296
bytes. The most significant byte is at the lowest address. */
282
298
dulint
283
299
mach_read_from_8(
284
300
/*=============*/
285
 
                        /* out: dulint integer */
286
 
        byte*   b)      /* in: pointer to 8 bytes */
 
301
                                /* out: dulint integer */
 
302
        const byte*     b)      /* in: pointer to 8 bytes */
287
303
{
288
304
        ulint   high;
289
305
        ulint   low;
296
312
        return(ut_dulint_create(high, low));
297
313
}
298
314
 
 
315
/************************************************************
 
316
The following function is used to fetch data from 8 consecutive
 
317
bytes. The most significant byte is at the lowest address. */
 
318
UNIV_INLINE
 
319
ib_uint64_t
 
320
mach_read_ull(
 
321
/*==========*/
 
322
                                /* out: 64-bit integer */
 
323
        const byte*     b)      /* in: pointer to 8 bytes */
 
324
{
 
325
        ib_uint64_t     ull;
 
326
 
 
327
        ull = ((ib_uint64_t) mach_read_from_4(b)) << 32;
 
328
        ull |= (ib_uint64_t) mach_read_from_4(b + 4);
 
329
 
 
330
        return(ull);
 
331
}
 
332
 
299
333
/***********************************************************
300
334
The following function is used to store data in 7 consecutive
301
335
bytes. We store the most significant byte to the lowest address. */
319
353
dulint
320
354
mach_read_from_7(
321
355
/*=============*/
322
 
                        /* out: dulint integer */
323
 
        byte*   b)      /* in: pointer to 7 bytes */
 
356
                                /* out: dulint integer */
 
357
        const byte*     b)      /* in: pointer to 7 bytes */
324
358
{
325
359
        ulint   high;
326
360
        ulint   low;
356
390
dulint
357
391
mach_read_from_6(
358
392
/*=============*/
359
 
                        /* out: dulint integer */
360
 
        byte*   b)      /* in: pointer to 7 bytes */
 
393
                                /* out: dulint integer */
 
394
        const byte*     b)      /* in: pointer to 6 bytes */
361
395
{
362
396
        ulint   high;
363
397
        ulint   low;
408
442
dulint
409
443
mach_dulint_read_compressed(
410
444
/*========================*/
411
 
                        /* out: read dulint */
412
 
        byte*   b)      /* in: pointer to memory from where to read */
 
445
                                /* out: read dulint */
 
446
        const byte*     b)      /* in: pointer to memory from where to read */
413
447
{
414
448
        ulint   high;
415
449
        ulint   low;
475
509
dulint
476
510
mach_dulint_read_much_compressed(
477
511
/*=============================*/
478
 
                        /* out: read dulint */
479
 
        byte*   b)      /* in: pointer to memory from where to read */
 
512
                                /* out: read dulint */
 
513
        const byte*     b)      /* in: pointer to memory from where to read */
480
514
{
481
515
        ulint   high;
482
516
        ulint   low;
504
538
double
505
539
mach_double_read(
506
540
/*=============*/
507
 
                        /* out: double read */
508
 
        byte*   b)      /* in: pointer to memory from where to read */
 
541
                                /* out: double read */
 
542
        const byte*     b)      /* in: pointer to memory from where to read */
509
543
{
510
544
        double  d;
511
545
        ulint   i;
553
587
float
554
588
mach_float_read(
555
589
/*============*/
556
 
                        /* out: float read */
557
 
        byte*   b)      /* in: pointer to memory from where to read */
 
590
                                /* out: float read */
 
591
        const byte*     b)      /* in: pointer to memory from where to read */
558
592
{
559
593
        float   d;
560
594
        ulint   i;
602
636
ulint
603
637
mach_read_from_n_little_endian(
604
638
/*===========================*/
605
 
                                /* out: unsigned long int */
606
 
        byte*   buf,            /* in: from where to read */
607
 
        ulint   buf_size)       /* in: from how many bytes to read */
 
639
                                        /* out: unsigned long int */
 
640
        const byte*     buf,            /* in: from where to read */
 
641
        ulint           buf_size)       /* in: from how many bytes to read */
608
642
{
609
643
        ulint   n       = 0;
610
 
        byte*   ptr;
 
644
        const byte*     ptr;
611
645
 
612
646
        ut_ad(buf_size <= sizeof(ulint));
613
647
        ut_ad(buf_size > 0);
667
701
ulint
668
702
mach_read_from_2_little_endian(
669
703
/*===========================*/
670
 
                                /* out: unsigned long int */
671
 
        byte*   buf)            /* in: from where to read */
 
704
                                        /* out: unsigned long int */
 
705
        const byte*     buf)            /* in: from where to read */
672
706
{
673
707
        return((ulint)(*buf) + ((ulint)(*(buf + 1))) * 256);
674
708
}
696
730
Convert integral type from storage byte order (big endian) to
697
731
host byte order. */
698
732
UNIV_INLINE
699
 
void
 
733
ullint
700
734
mach_read_int_type(
701
735
/*===============*/
702
 
        byte*           dest,           /* out: where to write */
 
736
                                        /* out: integer value */
703
737
        const byte*     src,            /* in: where to read from */
704
738
        ulint           len,            /* in: length of src */
705
739
        ibool           unsigned_type)  /* in: signed or unsigned flag */
706
740
{
707
 
#ifdef WORDS_BIGENDIAN
708
 
        memcpy(dest, src, len);
709
 
 
710
 
        if (!unsigned_type) {
711
 
                dest[0] ^= 128;
712
 
        }
713
 
#else
714
 
        byte*           ptr;
715
 
 
716
 
        /* Convert integer data from Innobase to a little-endian format,
717
 
        sign bit restored to normal. */
718
 
 
719
 
        for (ptr = dest + len; ptr != dest; ++src) {
720
 
                --ptr;
721
 
                *ptr = *src;
722
 
        }
723
 
 
724
 
        if (!unsigned_type) {
725
 
                dest[len - 1] ^= 128;
726
 
        }
727
 
#endif
 
741
        /* XXX this can be optimized on big-endian machines */
 
742
 
 
743
        ullint  ret;
 
744
        uint    i;
 
745
 
 
746
        if (unsigned_type || (src[0] & 0x80)) {
 
747
 
 
748
                ret = 0x0000000000000000ULL;
 
749
        } else {
 
750
 
 
751
                ret = 0xFFFFFFFFFFFFFF00ULL;
 
752
        }
 
753
 
 
754
        if (unsigned_type) {
 
755
 
 
756
                ret |= src[0];
 
757
        } else {
 
758
 
 
759
                ret |= src[0] ^ 0x80;
 
760
        }
 
761
 
 
762
        for (i = 1; i < len; i++) {
 
763
                ret <<= 8;
 
764
                ret |= src[i];
 
765
        }
 
766
 
 
767
        return(ret);
728
768
}