[Pkg-ocaml-maint-commits] [SCM] bin-prot packaging branch, master, updated. debian/1.3.1-2-3-g7258470
Stephane Glondu
steph at glondu.net
Fri Jul 15 22:37:26 UTC 2011
The following commit has been merged in the master branch:
commit 23e18a5b57ab0c9cf484c657c32341bb4a5b2073
Author: Stephane Glondu <steph at glondu.net>
Date: Fri Jul 15 23:37:09 2011 +0200
Fix more alignment issues
diff --git a/debian/patches/0003-Fix-alignment.patch b/debian/patches/0003-Fix-alignment.patch
index e178ef3..9b0cdaf 100644
--- a/debian/patches/0003-Fix-alignment.patch
+++ b/debian/patches/0003-Fix-alignment.patch
@@ -2,19 +2,28 @@ From: Stephane Glondu <steph at glondu.net>
Date: Wed, 13 Jul 2011 21:02:17 +0200
Subject: Fix alignment
-This patch fixes FTBFS on architectures that need aligned double
-access (e.g. mipsel).
+This patch fixes various aligment issues. Fixes FTBFS on e.g. armel
+and mipsel.
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=631829
---
- lib/read_stubs.c | 4 +++-
- lib/write_stubs.c | 3 ++-
- 2 files changed, 5 insertions(+), 2 deletions(-)
+ lib/read_stubs.c | 56 +++++++++++++++++++++++---------------
+ lib/write_stubs.c | 76 ++++++++++++++++++++++++++++++++---------------------
+ 2 files changed, 80 insertions(+), 52 deletions(-)
diff --git a/lib/read_stubs.c b/lib/read_stubs.c
-index dfdef9e..c8dac01 100644
+index dfdef9e..c6b6fee 100644
--- a/lib/read_stubs.c
+++ b/lib/read_stubs.c
+@@ -90,7 +90,7 @@ static inline void raise_Read_error(int loc, unsigned long pos)
+ TYPE n; \
+ if (unlikely(next > eptr)) \
+ caml_raise_constant(*v_bin_prot_exc_Buffer_short); \
+- n = *(TYPE *) *sptr_ptr; \
++ memcpy(&n, sptr, LEN); \
+ CHECK \
+ *sptr_ptr = next; \
+ return n; \
@@ -399,9 +399,11 @@ CAMLprim inline value read_float_stub(char **sptr_ptr, char *eptr)
{
char *sptr = *sptr_ptr;
@@ -28,11 +37,196 @@ index dfdef9e..c8dac01 100644
}
MK_ML_READER(float)
+@@ -472,7 +474,7 @@ CAMLprim value read_variant_tag_stub(char **sptr_ptr, char *eptr)
+ char *next = sptr + 4;
+ int n;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- n = *(int *) sptr;
++ memcpy(&n, sptr, 4);
+ if (likely(Is_long(n))) {
+ *sptr_ptr = next;
+ return (value) n;
+@@ -491,7 +493,7 @@ CAMLprim value ml_read_variant_tag_stub(value v_buf, value v_pos_ref)
+ if (unlikely(pos < 0)) caml_array_bound_error();
+ if (unlikely(next_pos > (unsigned long) *buf->dim))
+ caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- n = *(int *) sptr;
++ memcpy(&n, sptr, 4);
+ if (likely(Is_long(n))) {
+ Field(v_pos_ref, 0) = Val_long(next_pos);
+ return (value) n;
+@@ -607,16 +609,15 @@ CAMLprim inline value read_int_64bit_stub(char **sptr_ptr, char *eptr)
+ long upper;
+ #endif
+ char *sptr = *sptr_ptr;
+- long *lsptr = (long *) sptr;
+ char *next = sptr + 8;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+ #ifdef ARCH_SIXTYFOUR
+- n = *lsptr;
++ memcpy(&n, sptr, 8);
+ if (unlikely(n < -0x4000000000000000L || n > 0x3FFFFFFFFFFFFFFFL))
+ raise_Error(READ_ERROR_INT_OVERFLOW);
+ #else
+- n = *lsptr;
+- upper = *++lsptr;
++ memcpy(&n, sptr, 4);
++ memcpy(&upper, sptr + 4, 4);
+ if (upper == 0l) {
+ if ((unsigned long) n > 0x3FFFFFFFl) raise_Error(READ_ERROR_INT_OVERFLOW);
+ } else if (upper == -1) {
+@@ -640,9 +641,10 @@ CAMLprim inline value read_int64_bits_stub(char **sptr_ptr, char *eptr)
+ n = (*(long *) sptr);
+ #else
+ {
+- unsigned int *uisptr = (unsigned int *) sptr;
+- unsigned int lower = *uisptr++;
+- unsigned int upper = *uisptr;
++ unsigned int lower;
++ unsigned int upper;
++ memcpy(&lower, sptr, 4);
++ memcpy(&upper, sptr + 4, 4);
+ n = I64_or(I64_lsl(I64_of_int32(upper), 32), I64_of_int32(lower));
+ }
+ #endif
+@@ -656,9 +658,11 @@ CAMLprim inline value read_network16_int_stub(char **sptr_ptr, char *eptr)
+ {
+ char *sptr = *sptr_ptr;
+ char *next = sptr + 2;
++ uint16_t tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+ *sptr_ptr = next;
+- return (value) Val_int((uint16_t) ntohs(*((uint16_t *) sptr)));
++ memcpy(&tmp, sptr, 2);
++ return (value) Val_int(ntohs(tmp));
+ }
+ MK_ML_READER(network16_int)
+
+@@ -667,16 +671,18 @@ CAMLprim inline value read_network32_int_stub(char **sptr_ptr, char *eptr)
+ char *sptr = *sptr_ptr;
+ char *next = sptr + 4;
+ int n;
++ uint32_t tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- n = (int) ntohl(*(uint32_t *) sptr);
++ memcpy(&tmp, sptr, 4);
++ n = (int) ntohl(tmp);
+ #ifndef ARCH_SIXTYFOUR
+ if (unlikely(n < -0x40000000l || n > 0x3FFFFFFFl))
+ raise_Error(READ_ERROR_INT_OVERFLOW);
+ *sptr_ptr = next;
+- return (value) Val_int((int) ntohl(*((uint32_t *) sptr)));
++ return (value) Val_int((int) ntohl(tmp));
+ #else
+ *sptr_ptr = next;
+- return (value) Val_int((uint32_t) ntohl(*((uint32_t *) sptr)));
++ return (value) Val_int((uint32_t) ntohl(tmp));
+ #endif
+ }
+ MK_ML_READER(network32_int)
+@@ -685,9 +691,11 @@ CAMLprim inline value read_network32_int32_stub(char **sptr_ptr, char *eptr)
+ {
+ char *sptr = *sptr_ptr;
+ char *next = sptr + 4;
++ uint32_t tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+ *sptr_ptr = next;
+- return (value) caml_copy_int32((int) ntohl(*((uint32_t *) sptr)));
++ memcpy(&tmp, sptr, 4);
++ return (value) caml_copy_int32((int) ntohl(tmp));
+ }
+ MK_ML_READER(network32_int32)
+
+@@ -696,6 +704,7 @@ CAMLprim inline value read_network64_int_stub(char **sptr_ptr, char *eptr)
+ char *sptr = *sptr_ptr;
+ char *next = sptr + 8;
+ long n;
++ uint32_t tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+ #ifdef ARCH_SIXTYFOUR
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
+@@ -711,12 +720,14 @@ CAMLprim inline value read_network64_int_stub(char **sptr_ptr, char *eptr)
+ /* Read the upper 32 bits first. They must all be zero, otherwise we
+ consider this an overflow. On 32bit platforms the integer must
+ fit completely into one word. */
+- n = *((long *) sptr);
++ memcpy(&tmp, sptr, 4);
++ n = (long) tmp;
+ if (n != 0) raise_Error(READ_ERROR_INT_OVERFLOW);
++ memcpy(&tmp, sptr + 4, 4);
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
+- n = (long) bswap_32(*(((uint32_t *) sptr) + 1));
++ n = (long) bswap_32(tmp);
+ #elif __BYTE_ORDER == __BIG_ENDIAN
+- n = *(((long *) sptr) + 1);
++ n = (long) tmp;
+ #else
+ #error "unsupported endianness"
+ #endif
+@@ -746,9 +757,10 @@ CAMLprim inline value read_network64_int64_stub(char **sptr_ptr, char *eptr)
+ return (value) caml_copy_int64(n);
+ #else /* 32bit */
+ {
+- uint32_t *uisptr = (uint32_t *) sptr;
+- uint32_t upper = *uisptr++;
+- uint32_t lower = *uisptr;
++ uint32_t upper;
++ uint32_t lower;
++ memcpy(&upper, sptr, 4);
++ memcpy(&lower, sptr + 4, 4);
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
+ n =
+ I64_or(
diff --git a/lib/write_stubs.c b/lib/write_stubs.c
-index 68970ec..1cd94c4 100644
+index 68970ec..283dae1 100644
--- a/lib/write_stubs.c
+++ b/lib/write_stubs.c
-@@ -311,8 +311,9 @@ CAMLprim value write_string_stub(char *sptr, char *eptr, value v_str)
+@@ -73,7 +73,7 @@ static inline value write_neg_int8(char *sptr, char *eptr, char n)
+ static inline void do_write_int16(char *sptr, short n)
+ {
+ *sptr++ = CODE_INT16;
+- *(short *) sptr = n;
++ memcpy(sptr, &n, 2);
+ }
+
+ static inline value write_int16(char *sptr, char *eptr, short n)
+@@ -87,7 +87,7 @@ static inline value write_int16(char *sptr, char *eptr, short n)
+ static inline void do_write_int32(char *sptr, int n)
+ {
+ *sptr++ = CODE_INT32;
+- *(int *) sptr = n;
++ memcpy(sptr, &n, 4);
+ }
+
+ static inline value write_int32(char *sptr, char *eptr, int n)
+@@ -102,7 +102,7 @@ static inline value write_int32(char *sptr, char *eptr, int n)
+ static inline void do_write_int64(char *sptr, long n)
+ {
+ *sptr++ = CODE_INT64;
+- *(long *) sptr = n;
++ memcpy(sptr, &n, 8);
+ }
+
+ static inline value write_int64(char *sptr, char *eptr, long n)
+@@ -186,12 +186,13 @@ CAMLprim value write_int32_stub(char *sptr, char *eptr, value v_n)
+ static inline value write_int64_type(char *sptr, char *eptr, int64 n)
+ {
+ char *next = sptr + 9;
+- int *isptr;
++ int32 tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+ *sptr++ = CODE_INT64;
+- isptr = (int *) sptr;
+- *isptr++ = I64_to_int32(n);
+- *isptr = I64_to_int32(I64_lsr(n, 32));
++ tmp = I64_to_int32(n);
++ memcpy(sptr, &tmp, 4);
++ tmp = I64_to_int32(I64_lsr(n, 32));
++ memcpy(sptr + 4, &tmp, 4);
+ return (value) next;
+ }
+
+@@ -311,8 +312,9 @@ CAMLprim value write_string_stub(char *sptr, char *eptr, value v_str)
CAMLprim inline value write_float_stub(char *sptr, char *eptr, value v_n)
{
char *next = sptr + sizeof(double);
@@ -43,4 +237,139 @@ index 68970ec..1cd94c4 100644
return (value) next;
}
+@@ -373,8 +375,10 @@ MK_ML_WRITER(float_array)
+ CAMLprim inline value write_variant_tag_stub(char *sptr, char *eptr, value v)
+ {
+ char *next = sptr + 4;
++ int tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- *(int *) sptr = (int) (Is_block(v) ? Field(v, 0) : v);
++ tmp = (int) (Is_block(v) ? Field(v, 0) : v);
++ memcpy(sptr, &tmp, 4);
+ return (value) next;
+ }
+
+@@ -518,11 +522,11 @@ CAMLprim value write_int_64bit_stub(char *sptr, char *eptr, value v_n)
+ {
+ long n = Long_val(v_n);
+ char *next = sptr + 8;
+- long *lsptr = (long *) sptr;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- *lsptr = n;
++ memcpy(sptr, &n, sizeof(long));
+ #ifndef ARCH_SIXTYFOUR
+- *++lsptr = (n < 0) ? 0xFFFFFFFFl : 0l;
++ n = (n < 0) ? 0xFFFFFFFFl : 0l;
++ memcpy(sptr + 4, &n, sizeof(long));
+ #endif
+ return (value) next;
+ }
+@@ -537,10 +541,11 @@ CAMLprim inline value write_int64_bits_stub(char *sptr, char *eptr, value v_n)
+ #else
+ {
+ int64 n = Int64_val(v_n);
+- unsigned int *uisptr = (unsigned int *) sptr;
+- *uisptr = I64_to_int32(n);
+- uisptr++;
+- *uisptr = I64_to_int32(I64_lsr(n, 32));
++ unsigned int tmp;
++ tmp = I64_to_int32(n);
++ memcpy(sptr, &tmp, 4);
++ tmp = I64_to_int32(I64_lsr(n, 32));
++ memcpy(sptr + 4, &tmp, 4);
+ }
+ #endif
+ return (value) next;
+@@ -551,8 +556,10 @@ CAMLprim inline value write_network16_int_stub(
+ char *sptr, char *eptr, value v_n)
+ {
+ char *next = sptr + 2;
++ uint16_t tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- *((uint16_t *) sptr) = (uint16_t) htons(Int_val(v_n));
++ tmp = (uint16_t) htons(Int_val(v_n));
++ memcpy(sptr, &tmp, 2);
+ return (value) next;
+ }
+ MK_ML_WRITER(network16_int)
+@@ -561,8 +568,10 @@ CAMLprim inline value write_network32_int_stub(
+ char *sptr, char *eptr, value v_n)
+ {
+ char *next = sptr + 4;
++ uint32_t tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- *((uint32_t *) sptr) = (uint32_t) htonl(Int_val(v_n));
++ tmp = (uint32_t) htonl(Int_val(v_n));
++ memcpy(sptr, &tmp, 4);
+ return (value) next;
+ }
+ MK_ML_WRITER(network32_int)
+@@ -571,8 +580,10 @@ CAMLprim inline value write_network32_int32_stub(
+ char *sptr, char *eptr, value v_n)
+ {
+ char *next = sptr + 4;
++ uint32_t tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+- *((uint32_t *) sptr) = htonl(Int32_val(v_n));
++ tmp = htonl(Int32_val(v_n));
++ memcpy(sptr, &tmp, 4);
+ return (value) next;
+ }
+ MK_ML_WRITER(network32_int32)
+@@ -582,6 +593,7 @@ CAMLprim inline value write_network64_int_stub(
+ {
+ char *next = sptr + 8;
+ long n = Long_val(v_n);
++ unsigned int tmp;
+ if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
+ #ifdef ARCH_SIXTYFOUR
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
+@@ -592,13 +604,15 @@ CAMLprim inline value write_network64_int_stub(
+ #error "unsupported endianness"
+ #endif
+ #else /* 32bit */
+- *((unsigned int *) sptr) = 0;
++ tmp = 0;
++ memcpy(sptr, &tmp, 4);
+ sptr += 4;
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
+- *((unsigned int *) sptr) = bswap_32((unsigned int) n);
++ tmp = bswap_32((unsigned int) n);
+ #else
+- *((unsigned int *) sptr) = (unsigned int) n;
++ tmp = (unsigned int) n;
+ #endif
++ memcpy(sptr, &tmp, 4);
+ #endif
+ return (value) next;
+ }
+@@ -621,18 +635,20 @@ CAMLprim inline value write_network64_int64_stub(
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
+ {
+ int64 n = Int64_val(v_n);
+- uint32_t *uisptr = (uint32_t *) sptr;
+- *uisptr = bswap_32(I64_to_int32(I64_lsr(n, 32)));
+- uisptr++;
+- *uisptr = bswap_32(I64_to_int32(n));
++ uint32_t tmp;
++ tmp = bswap_32(I64_to_int32(I64_lsr(n, 32)));
++ memcpy(sptr, &tmp, 4);
++ tmp = bswap_32(I64_to_int32(n));
++ memcpy(sptr + 4, &tmp, 4);
+ }
+ #elif __BYTE_ORDER == __BIG_ENDIAN
+ {
+ int64 n = Int64_val(v_n);
+- uint32_t *uisptr = (uint32_t *) sptr;
+- *uisptr = I64_to_int32(I64_lsr(n, 32));
+- uisptr++;
+- *uisptr = I64_to_int32(n);
++ uint32_t tmp;
++ tmp = I64_to_int32(I64_lsr(n, 32));
++ memcpy(sptr, &tmp, 4);
++ tmp = I64_to_int32(n);
++ memcpy(sptr + 4, &tmp, 4);
+ }
+ #else
+ #error "unsupported endianness"
--
diff --git a/debian/patches/0004-Fix-endianness.patch b/debian/patches/0004-Fix-endianness.patch
index 586cbd6..4e5078b 100644
--- a/debian/patches/0004-Fix-endianness.patch
+++ b/debian/patches/0004-Fix-endianness.patch
@@ -7,12 +7,12 @@ on e.g. mips.
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=631829
---
- lib/read_stubs.c | 7 ++++++-
- lib/write_stubs.c | 13 ++++++++-----
- 2 files changed, 14 insertions(+), 6 deletions(-)
+ lib/read_stubs.c | 6 ++++++
+ lib/write_stubs.c | 10 ++++++++--
+ 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/lib/read_stubs.c b/lib/read_stubs.c
-index c8dac01..2ac14cb 100644
+index c6b6fee..3e9dc6e 100644
--- a/lib/read_stubs.c
+++ b/lib/read_stubs.c
@@ -22,6 +22,11 @@
@@ -27,17 +27,16 @@ index c8dac01..2ac14cb 100644
/* Stubs for reading basic values in the binary protocol */
#include "common_stubs.h"
-@@ -90,7 +95,7 @@ static inline void raise_Read_error(int loc, unsigned long pos)
- TYPE n; \
+@@ -91,6 +96,7 @@ static inline void raise_Read_error(int loc, unsigned long pos)
if (unlikely(next > eptr)) \
caml_raise_constant(*v_bin_prot_exc_Buffer_short); \
-- n = *(TYPE *) *sptr_ptr; \
-+ n = le##SIZE##toh(*(TYPE *) *sptr_ptr); \
+ memcpy(&n, sptr, LEN); \
++ n = le##SIZE##toh(n); \
CHECK \
*sptr_ptr = next; \
return n; \
diff --git a/lib/write_stubs.c b/lib/write_stubs.c
-index 1cd94c4..039e1b1 100644
+index 283dae1..bf7df10 100644
--- a/lib/write_stubs.c
+++ b/lib/write_stubs.c
@@ -22,6 +22,9 @@
@@ -50,42 +49,40 @@ index 1cd94c4..039e1b1 100644
/* Stubs for writing basic values in the binary protocol */
#include "common_stubs.h"
-@@ -73,7 +76,7 @@ static inline value write_neg_int8(char *sptr, char *eptr, char n)
+@@ -73,6 +76,7 @@ static inline value write_neg_int8(char *sptr, char *eptr, char n)
static inline void do_write_int16(char *sptr, short n)
{
*sptr++ = CODE_INT16;
-- *(short *) sptr = n;
-+ *(short *) sptr = htole16(n);
++ n = htole16(n);
+ memcpy(sptr, &n, 2);
}
- static inline value write_int16(char *sptr, char *eptr, short n)
-@@ -87,7 +90,7 @@ static inline value write_int16(char *sptr, char *eptr, short n)
+@@ -87,6 +91,7 @@ static inline value write_int16(char *sptr, char *eptr, short n)
static inline void do_write_int32(char *sptr, int n)
{
*sptr++ = CODE_INT32;
-- *(int *) sptr = n;
-+ *(int *) sptr = htole32(n);
++ n = htole32(n);
+ memcpy(sptr, &n, 4);
}
- static inline value write_int32(char *sptr, char *eptr, int n)
-@@ -102,7 +105,7 @@ static inline value write_int32(char *sptr, char *eptr, int n)
+@@ -102,6 +107,7 @@ static inline value write_int32(char *sptr, char *eptr, int n)
static inline void do_write_int64(char *sptr, long n)
{
*sptr++ = CODE_INT64;
-- *(long *) sptr = n;
-+ *(long *) sptr = htole64(n);
++ n = htole64(n);
+ memcpy(sptr, &n, 8);
}
- static inline value write_int64(char *sptr, char *eptr, long n)
-@@ -190,8 +193,8 @@ static inline value write_int64_type(char *sptr, char *eptr, int64 n)
+@@ -189,9 +195,9 @@ static inline value write_int64_type(char *sptr, char *eptr, int64 n)
+ int32 tmp;
if (unlikely(next > eptr)) caml_raise_constant(*v_bin_prot_exc_Buffer_short);
*sptr++ = CODE_INT64;
- isptr = (int *) sptr;
-- *isptr++ = I64_to_int32(n);
-- *isptr = I64_to_int32(I64_lsr(n, 32));
-+ *isptr++ = htole32(I64_to_int32(n));
-+ *isptr = htole32(I64_to_int32(I64_lsr(n, 32)));
+- tmp = I64_to_int32(n);
++ tmp = htole32(I64_to_int32(n));
+ memcpy(sptr, &tmp, 4);
+- tmp = I64_to_int32(I64_lsr(n, 32));
++ tmp = htole32(I64_to_int32(I64_lsr(n, 32)));
+ memcpy(sptr + 4, &tmp, 4);
return (value) next;
}
-
--
--
bin-prot packaging
More information about the Pkg-ocaml-maint-commits
mailing list