Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/eglib
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnome.org>2006-10-14 22:05:33 +0400
committerMiguel de Icaza <miguel@gnome.org>2006-10-14 22:05:33 +0400
commitfb4751751c81a731d4cc166fe1a21b053d23836f (patch)
tree890a592209079af558d2464404a01329a0129988 /eglib
parentf166d355b6a897f35979b5183fa20be90713437a (diff)
2006-10-14 Miguel de Icaza <miguel@novell.com>
* src/glib.h: add various _TO_LE and _FROM_LE macros. * test/endian.c: tests for endian conversion macros. svn path=/trunk/mono/; revision=66680
Diffstat (limited to 'eglib')
-rw-r--r--eglib/ChangeLog6
-rw-r--r--eglib/TODO4
-rw-r--r--eglib/src/glib.h26
-rw-r--r--eglib/test/Makefile.am3
-rw-r--r--eglib/test/endian.c38
-rw-r--r--eglib/test/tests.h2
6 files changed, 74 insertions, 5 deletions
diff --git a/eglib/ChangeLog b/eglib/ChangeLog
index 8f46f2fbf23..87a912f7216 100644
--- a/eglib/ChangeLog
+++ b/eglib/ChangeLog
@@ -1,3 +1,9 @@
+2006-10-14 Miguel de Icaza <miguel@novell.com>
+
+ * src/glib.h: add various _TO_LE and _FROM_LE macros.
+
+ * test/endian.c: tests for endian conversion macros.
+
2006-10-09 Miguel de Icaza <miguel@novell.com>
* src/gmodule.h: Move definitions of gmodule to gmodule.h because
diff --git a/eglib/TODO b/eglib/TODO
index bba2ee7c1ac..aa6d6762f7a 100644
--- a/eglib/TODO
+++ b/eglib/TODO
@@ -11,11 +11,7 @@
* Miscelaneous
g_propagate_error
- GUINT32_FROM_LE
GLIB_CHECK_VERSION -- currently broken, but does not matterh much
- GUINT16_TO_LE
- GUINT32_TO_LE
- GUINT64_TO_LE
*rva = GUINT32_FROM_LE (assembly->text_rva + assembly->imp_names_offset + 14); /* 14 is hint+strlen+1 of func name */
diff --git a/eglib/src/glib.h b/eglib/src/glib.h
index 12741f4aeb0..cf68e4c027c 100644
--- a/eglib/src/glib.h
+++ b/eglib/src/glib.h
@@ -696,5 +696,31 @@ gboolean g_utf8_validate (const gchar *str, gssize max_len, const gchar **
#define g_thread_supported() TRUE
#define g_thread_init(x) G_STMT_START { if (x != NULL) { g_error ("No vtable supported in g_thread_init"); } G_STMT_END
+#define GUINT16_SWAP_LE_BE(x) ((guint16) (((guint16) x) >> 8) | ((((guint16)(x)) & 0xff) << 8))
+#define GUINT32_SWAP_LE_BE(x) ((guint32) \
+ ( (((guint32) (x)) << 24)| \
+ ((((guint32) (x)) & 0xff0000) >> 8) | \
+ ((((guint32) (x)) & 0xff00) << 8) | \
+ (((guint32) (x)) >> 24)) )
+
+#define GUINT64_SWAP_LE_BE(x) ((guint64) (((guint64)(GUINT32_SWAP_LE_BE(((guint64)x) & 0xffffffff))) << 32) | \
+ GUINT32_SWAP_LE_BE(((guint64)x) >> 32))
+
+
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+# define GUINT32_TO_LE(x) (x)
+# define GUINT64_TO_LE(x) (x)
+# define GUINT16_TO_LE(x) (x)
+#else
+# define GUINT32_TO_LE(x) GUINT32_SWAP_LE_BE(x)
+# define GUINT64_TO_LE(x) GUINT64_SWAP_LE_BE(x)
+# define GUINT16_TO_LE(x) GUINT16_SWAP_LE_BE(x)
+#endif
+
+#define GUINT32_FROM_LE(x) (GUINT32_TO_LE (x))
+#define GUINT64_FROM_LE(x) (GUIN64_TO_LE (x))
+#define GUINT16_FROM_LE(x) (GUINT16_TO_LE (x))
+
#endif
diff --git a/eglib/test/Makefile.am b/eglib/test/Makefile.am
index 579461453ce..3132ac765eb 100644
--- a/eglib/test/Makefile.am
+++ b/eglib/test/Makefile.am
@@ -23,7 +23,8 @@ SOURCES = \
pattern.c \
dir.c \
markup.c \
- utf8.c
+ utf8.c \
+ endian.c
test_eglib_SOURCES = $(SOURCES)
test_glib_SOURCES = $(SOURCES)
diff --git a/eglib/test/endian.c b/eglib/test/endian.c
new file mode 100644
index 00000000000..3347d765ffe
--- /dev/null
+++ b/eglib/test/endian.c
@@ -0,0 +1,38 @@
+#include "test.h"
+
+RESULT
+test_swap ()
+{
+ guint32 a = 0xabcdef01, res32;
+ guint64 b = (((guint64)a) << 32) | a, res64;
+ guint64 b_expect = (((guint64)0x1efcdab) << 32) | 0x01efcdab;
+ guint16 c = 0xabcd, res16;
+
+ res32 = GUINT32_SWAP_LE_BE (a);
+ if (res32 != 0x01efcdab)
+ return FAILED ("GUINT32_SWAP_LE_BE returned 0x%x", res32);
+ res32 = GUINT32_SWAP_LE_BE (1);
+ if (res32 != 0x1000000)
+ return FAILED ("GUINT32_SWAP_LE_BE returned 0x%x", res32);
+
+ res64 = GUINT64_SWAP_LE_BE(b);
+ if (res64 != b_expect)
+ return FAILED ("GUINT64_SWAP_LE_BE returned 0x%llx (had=0x%llx)", res64, b);
+ res16 = GUINT16_SWAP_LE_BE(c);
+ if (res16 != 0xcdab)
+ return FAILED ("GUINT16_SWAP_LE_BE returned 0x%x", (guint32) res16);
+
+ return OK;
+}
+
+/*
+ * test initialization
+ */
+
+static Test endian_tests [] = {
+ {"swap", test_swap},
+ {NULL, NULL}
+};
+
+DEFINE_TEST_GROUP_INIT(endian_tests_init, endian_tests)
+
diff --git a/eglib/test/tests.h b/eglib/test/tests.h
index 5a19072444c..f8e0ababcea 100644
--- a/eglib/test/tests.h
+++ b/eglib/test/tests.h
@@ -19,6 +19,7 @@ DEFINE_TEST_GROUP_INIT_H(pattern_tests_init);
DEFINE_TEST_GROUP_INIT_H(dir_tests_init);
DEFINE_TEST_GROUP_INIT_H(markup_tests_init);
DEFINE_TEST_GROUP_INIT_H(utf8_tests_init);
+DEFINE_TEST_GROUP_INIT_H(endian_tests_init);
static Group test_groups [] = {
{"string", string_tests_init},
@@ -40,6 +41,7 @@ static Group test_groups [] = {
{"pattern", pattern_tests_init},
{"dir", dir_tests_init},
{"utf8", utf8_tests_init},
+ {"endian", endian_tests_init},
{NULL, NULL}
};