ObjFW  Check-in [6202189a07]

Overview
Comment:Add functions to read & write BE/LE value pointers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6202189a07a501a46035c4a6175d307871bba8a6e751291dc89b2e130a750139
User & Date: js on 2017-08-13 13:48:45
Other Links: manifest | tags
Context
2017-08-13
13:50
OFArray: Fix MessagePack encoding check-in: ada612eac9 user: js tags: trunk
13:48
Add functions to read & write BE/LE value pointers check-in: 6202189a07 user: js tags: trunk
11:51
Add -[OFMutableData increaseCountBy:] check-in: e3c4bf8e3b user: js tags: trunk
Changes

Modified src/macros.h from [8a33280748] to [b2dbaa72d1].

563
564
565
566
567
568
569






















































































































































570
571
572
573
574
575
576
# define OF_BSWAP_DOUBLE_IF_LE(i) (i)
#else
# define OF_BSWAP_FLOAT_IF_BE(i) (i)
# define OF_BSWAP_DOUBLE_IF_BE(i) (i)
# define OF_BSWAP_FLOAT_IF_LE(i) OF_BSWAP_FLOAT(i)
# define OF_BSWAP_DOUBLE_IF_LE(i) OF_BSWAP_DOUBLE(i)
#endif























































































































































#define OF_ROL(value, bits)						\
    (((bits) % (sizeof(value) * 8)) > 0					\
    ? ((value) << ((bits) % (sizeof(value) * 8))) |			\
    ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))	\
    : (value))
#define OF_ROR(value, bits)						\







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# define OF_BSWAP_DOUBLE_IF_LE(i) (i)
#else
# define OF_BSWAP_FLOAT_IF_BE(i) (i)
# define OF_BSWAP_DOUBLE_IF_BE(i) (i)
# define OF_BSWAP_FLOAT_IF_LE(i) OF_BSWAP_FLOAT(i)
# define OF_BSWAP_DOUBLE_IF_LE(i) OF_BSWAP_DOUBLE(i)
#endif

static OF_INLINE uint16_t
of_be16_ptr_read(void *ptr)
{
	uint16_t value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP16_IF_LE(value);
}

static OF_INLINE uint32_t
of_be32_ptr_read(void *ptr)
{
	uint32_t value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP32_IF_LE(value);
}

static OF_INLINE uint64_t
of_be64_ptr_read(void *ptr)
{
	uint64_t value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP64_IF_LE(value);
}

static OF_INLINE float
of_be_float_ptr_read(void *ptr)
{
	float value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP_FLOAT_IF_LE(value);
}

static OF_INLINE double
of_be_double_ptr_read(void *ptr)
{
	double value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP_DOUBLE_IF_LE(value);
}

static OF_INLINE uint16_t
of_le16_ptr_read(void *ptr)
{
	uint16_t value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP16_IF_BE(value);
}

static OF_INLINE uint32_t
of_le32_ptr_read(void *ptr)
{
	uint32_t value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP32_IF_BE(value);
}

static OF_INLINE uint64_t
of_le64_ptr_read(void *ptr)
{
	uint64_t value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP64_IF_BE(value);
}

static OF_INLINE float
of_le_float_ptr_read(void *ptr)
{
	float value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP_FLOAT_IF_BE(value);
}

static OF_INLINE double
of_le_double_ptr_read(void *ptr)
{
	double value;
	memcpy(&value, ptr, sizeof(value));
	return OF_BSWAP_DOUBLE_IF_BE(value);
}

static OF_INLINE void
of_be16_ptr_write(void *ptr, uint16_t value)
{
	value = OF_BSWAP16_IF_LE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_be32_ptr_write(void *ptr, uint32_t value)
{
	value = OF_BSWAP32_IF_LE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_be64_ptr_write(void *ptr, uint64_t value)
{
	value = OF_BSWAP64_IF_LE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_be_float_ptr_write(void *ptr, float value)
{
	value = OF_BSWAP_FLOAT_IF_LE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_be_double_ptr_write(void *ptr, double value)
{
	value = OF_BSWAP_DOUBLE_IF_LE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_le16_ptr_write(void *ptr, uint16_t value)
{
	value = OF_BSWAP16_IF_BE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_le32_ptr_write(void *ptr, uint32_t value)
{
	value = OF_BSWAP32_IF_BE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_le64_ptr_write(void *ptr, uint64_t value)
{
	value = OF_BSWAP64_IF_BE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_le_float_ptr_write(void *ptr, float value)
{
	value = OF_BSWAP_FLOAT_IF_BE(value);
	memcpy(ptr, &value, sizeof(value));
}

static OF_INLINE void
of_le_double_ptr_write(void *ptr, double value)
{
	value = OF_BSWAP_DOUBLE_IF_BE(value);
	memcpy(ptr, &value, sizeof(value));
}

#define OF_ROL(value, bits)						\
    (((bits) % (sizeof(value) * 8)) > 0					\
    ? ((value) << ((bits) % (sizeof(value) * 8))) |			\
    ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8))))	\
    : (value))
#define OF_ROR(value, bits)						\