reverted my last changes, fixed unaligned access to make it work
authorRadek Doulik <rodo@mono-cvs.ximian.com>
Fri, 30 Nov 2001 11:09:16 +0000 (11:09 -0000)
committerRadek Doulik <rodo@mono-cvs.ximian.com>
Fri, 30 Nov 2001 11:09:16 +0000 (11:09 -0000)
2001-11-30  Radek Doulik  <rodo@ximian.com>

* mono-endian.h: reverted last change
added function prototypes

* Makefile.am (libmetadata_a_SOURCES): reverted my last change and
add mono-endian.c back

* mono-endian.c: returned back, as Paolo pointed out, it's needed
for unaligned access, I've mistaked it with endianess. I am
sorry.
(mono_read16): fix reverted endianess
(mono_read64): ditto
(mono_read32): ditto

svn path=/trunk/mono/; revision=1491

mono/metadata/ChangeLog
mono/metadata/Makefile.am
mono/metadata/mono-endian.c [new file with mode: 0644]
mono/metadata/mono-endian.h

index 347cdbf62b8de607fb6ee687bb00e1a4ee539823..afe68e75291481053ac74200112a7527a78e644b 100644 (file)
@@ -1,3 +1,18 @@
+2001-11-30  Radek Doulik  <rodo@ximian.com>
+
+       * mono-endian.h: reverted last change
+       added function prototypes
+
+       * Makefile.am (libmetadata_a_SOURCES): reverted my last change and
+       add mono-endian.c back
+
+       * mono-endian.c: returned back, as Paolo pointed out, it's needed
+       for unaligned access, I've mistaked it with endianess. I am
+       sorry.
+       (mono_read16): fix reverted endianess
+       (mono_read64): ditto
+       (mono_read32): ditto
+
 2001-11-30  Dick Porter  <dick@ximian.com>
 
        * exception.c: Implement mono_exception_from_name()
index 1af9a1ac78b5ba81d06883043fa75f0a4a47dc50..e75cca24083482df0febece076b31463e53f0453 100644 (file)
@@ -14,6 +14,7 @@ libmetadata_a_SOURCES = \
        assembly.c      \
        image.c         \
        metadata.c      \
+       mono-endian.c   \
        private.h       \
        rawbuffer.c     \
        reflection.c    \
diff --git a/mono/metadata/mono-endian.c b/mono/metadata/mono-endian.c
new file mode 100644 (file)
index 0000000..0cd01f2
--- /dev/null
@@ -0,0 +1,78 @@
+#include "mono-endian.h"
+
+#if NO_UNALIGNED_ACCESS
+
+typedef union {
+       char c [2];
+       guint16 i;
+} mono_rint16;
+
+typedef union {
+       char c [4];
+       guint32 i;
+} mono_rint32;
+
+typedef union {
+       char c [8];
+       guint64 i;
+} mono_rint64;
+
+guint16 
+mono_read16 (const unsigned char *x)
+{
+       mono_rint16 r;
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+       r.c [0] = x [0];
+       r.c [1] = x [1];
+#else
+       r.c [1] = x [0];
+       r.c [0] = x [1];
+#endif
+       return r.i;
+}
+
+guint32 
+mono_read32 (const unsigned char *x)
+{
+       mono_rint32 r;
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+       r.c [0] = x [0];
+       r.c [1] = x [1];
+       r.c [2] = x [2];
+       r.c [3] = x [3];
+#else
+       r.c [3] = x [0];
+       r.c [2] = x [1];
+       r.c [1] = x [2];
+       r.c [0] = x [3];
+#endif
+       return r.i;
+}
+
+guint64 
+mono_read64 (const unsigned char *x)
+{
+       mono_rint64 r;
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+       r.c [0] = x [0];
+       r.c [1] = x [1];
+       r.c [2] = x [2];
+       r.c [3] = x [3];
+       r.c [4] = x [4];
+       r.c [5] = x [5];
+       r.c [6] = x [6];
+       r.c [7] = x [7];
+#else
+       r.c [7] = x [0];
+       r.c [6] = x [1];
+       r.c [5] = x [2];
+       r.c [4] = x [3];
+       r.c [3] = x [4];
+       r.c [2] = x [5];
+       r.c [1] = x [6];
+       r.c [0] = x [7];
+#endif
+       return r.i;
+}
+
+#endif
index 1617f054dabb3fab95a442aac743bd5b039723f4..a51cdc0f77aca5195d48aa5fb02bc4816fc1ed21 100644 (file)
@@ -13,10 +13,24 @@ typedef union {
        double fval;
 } mono_rdouble;
 
+#if NO_UNALIGNED_ACCESS
+
+guint16 mono_read16 (const unsigned char *x);
+guint32 mono_read32 (const unsigned char *x);
+guint64 mono_read64 (const unsigned char *x);
+
+#define read16(x) (mono_read16 ((x)))
+#define read32(x) (mono_read32 ((x)))
+#define read64(x) (mono_read64 ((x)))
+
+#else
+
 #define read16(x) GUINT16_FROM_LE (*((guint16 *) (x)))
 #define read32(x) GUINT32_FROM_LE (*((guint32 *) (x)))
 #define read64(x) GUINT64_FROM_LE (*((guint64 *) (x)))
 
+#endif
+
 #define readr4(x,dest) \
        do {    \
                mono_rfloat mf; \