summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authortkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-29 14:11:54 +0000
committertkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-29 14:11:54 +0000
commitf399357911a59dfc338201ca8d3042c28047fc9d (patch)
tree81f90c25a880faf918acf808a610aad7f4ee86a3 /libgfortran
parentbe5e79fb4ff0f5bdbea57ecbe2bcab0b8c6b0f57 (diff)
downloadgcc-f399357911a59dfc338201ca8d3042c28047fc9d.tar.gz
2011-08-29 Thomas Koenig <tkoenig@gcc.gnu.org>
Backport from trunk PR libfortran/50192 * intrinsics/string_intrinsics.c (memcmp_char4): New function. * intrinsics/string_intrinsics_inc.c: New macro MEMCMP, either set to memcmp or memcmp_char4. (compare_string): Use MEMCMP, with correct size for it. * libgfortran.h: Add prototype for memcmp_char4. 2011-08-29 Thomas Koenig <tkoenig@gcc.gnu.org> Backport from trunk PR libfortran/50192 * gfortran.dg/widechar_compare_1.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@178238 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog10
-rw-r--r--libgfortran/intrinsics/string_intrinsics.c21
-rw-r--r--libgfortran/intrinsics/string_intrinsics_inc.c2
-rw-r--r--libgfortran/libgfortran.h4
4 files changed, 36 insertions, 1 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index dade7047bc8..df05fc26c53 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,13 @@
+2011-08-29 Thomas Koenig <tkoenig@gcc.gnu.org>
+
+ Backport from trunk
+ PR libfortran/50192
+ * intrinsics/string_intrinsics.c (memcmp_char4): New function.
+ * intrinsics/string_intrinsics_inc.c: New macro MEMCMP, either
+ set to memcmp or memcmp_char4.
+ (compare_string): Use MEMCMP, with correct size for it.
+ * libgfortran.h: Add prototype for memcmp_char4.
+
2011-08-19 Tobias Burnus <burnus@net-b.de>
PR fortran/50109
diff --git a/libgfortran/intrinsics/string_intrinsics.c b/libgfortran/intrinsics/string_intrinsics.c
index e2e14e0d0db..a1d3b31abbb 100644
--- a/libgfortran/intrinsics/string_intrinsics.c
+++ b/libgfortran/intrinsics/string_intrinsics.c
@@ -51,6 +51,23 @@ memset_char4 (gfc_char4_t *b, gfc_char4_t c, size_t len)
return b;
}
+/* Compare wide character types, which are handled internally as
+ unsigned 4-byte integers. */
+int
+memcmp_char4 (const void *a, const void *b, size_t len)
+{
+ const GFC_UINTEGER_4 *pa = a;
+ const GFC_UINTEGER_4 *pb = b;
+ while (len-- > 0)
+ {
+ if (*pa != *pb)
+ return *pa < *pb ? -1 : 1;
+ pa ++;
+ pb ++;
+ }
+ return 0;
+}
+
/* All other functions are defined using a few generic macros in
string_intrinsics_inc.c, so we avoid code duplication between the
@@ -64,6 +81,8 @@ memset_char4 (gfc_char4_t *b, gfc_char4_t c, size_t len)
#define SUFFIX(x) x
#undef MEMSET
#define MEMSET memset
+#undef MEMCMP
+#define MEMCMP memcmp
#include "string_intrinsics_inc.c"
@@ -76,6 +95,8 @@ memset_char4 (gfc_char4_t *b, gfc_char4_t c, size_t len)
#define SUFFIX(x) x ## _char4
#undef MEMSET
#define MEMSET memset_char4
+#undef MEMCMP
+#define MEMCMP memcmp_char4
#include "string_intrinsics_inc.c"
diff --git a/libgfortran/intrinsics/string_intrinsics_inc.c b/libgfortran/intrinsics/string_intrinsics_inc.c
index 64f5cd75a85..8335a38d949 100644
--- a/libgfortran/intrinsics/string_intrinsics_inc.c
+++ b/libgfortran/intrinsics/string_intrinsics_inc.c
@@ -90,7 +90,7 @@ compare_string (gfc_charlen_type len1, const CHARTYPE *s1,
gfc_charlen_type len;
int res;
- res = memcmp (s1, s2, ((len1 < len2) ? len1 : len2) * sizeof (CHARTYPE));
+ res = MEMCMP (s1, s2, ((len1 < len2) ? len1 : len2));
if (res != 0)
return res;
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index c9d3f371eab..87d5950389e 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -1284,6 +1284,10 @@ extern int compare_string_char4 (gfc_charlen_type, const gfc_char4_t *,
gfc_charlen_type, const gfc_char4_t *);
iexport_proto(compare_string_char4);
+extern int memcmp_char4 (const void *, const void *, size_t);
+internal_proto(memcmp_char4);
+
+
/* random.c */
extern void random_seed_i4 (GFC_INTEGER_4 * size, gfc_array_i4 * put,