Added a g_memmove replacement for platforms without memmove, where bcopy
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Thu, 1 Jul 1999 09:30:18 +0000 (09:30 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Thu, 1 Jul 1999 09:30:18 +0000 (09:30 +0000)
1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* configure.in, acconfig.h, gutils.c: Added a g_memmove
replacement for platforms without memmove, where bcopy can't
handle overlapping copies and the corresponding checks, which is
taken form the PERL Configure routine.

* glib.h: Updated the commentary about g_memmove to be right and
more GLib-like.

* configure.in: Removed test for rand_r, as it isn't used anymore.

14 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
acconfig.h
configure.in
glib.h
glib/glib.h
glib/gutils.c
gutils.c

index 0794072..8f2665d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 0794072..8f2665d 100644 (file)
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 0794072..8f2665d 100644 (file)
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 0794072..8f2665d 100644 (file)
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 0794072..8f2665d 100644 (file)
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 0794072..8f2665d 100644 (file)
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 0794072..8f2665d 100644 (file)
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 0794072..8f2665d 100644 (file)
@@ -1,3 +1,15 @@
+1999-07-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * configure.in, acconfig.h, gutils.c: Added a g_memmove
+       replacement for platforms without memmove, where bcopy can't
+       handle overlapping copies and the corresponding checks, which is
+       taken form the PERL Configure routine.
+
+       * glib.h: Updated the commentary about g_memmove to be right and
+       more GLib-like.
+       
+       * configure.in: Removed test for rand_r, as it isn't used anymore.
+
 1999-06-30  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
 
        * glib.h, grand.c: Finally removed the g_random_normal and
index 1c630e1..1504065 100644 (file)
@@ -69,6 +69,7 @@
 #undef HAVE_VALUES_H
 #undef HAVE_WCHAR_H
 #undef HAVE_WCTYPE_H
+#undef HAVE_WORKING_BCOPY
 
 #undef NO_FD_SET
 #undef NO_SYS_ERRLIST
index 5bb16df..aa07911 100644 (file)
@@ -306,6 +306,31 @@ AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H))
 # Check for some functions
 AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp poll)
 
+# Check if bcopy can be used for overlapping copies, if memmove isn't found.
+# The check is borrowed from the PERL Configure script.
+if test "$ac_cv_func_memmove" != "yes"; then
+  AC_CACHE_CHECK(whether bcopy can handle overlapping copies,
+    glib_cv_working_bcopy,[AC_TRY_RUN([
+      int main() {
+        char buf[128], abc[128], *b;
+        int len, off, align;
+        bcopy("abcdefghijklmnopqrstuvwxyz0123456789", abc, 36);
+        for (align = 7; align >= 0; align--) {
+          for (len = 36; len; len--) {
+            b = buf+align; bcopy(abc, b, len);
+            for (off = 1; off <= len; off++) {
+              bcopy(b, b+off, len); bcopy(b+off, b, len);
+                if (bcmp(b, abc, len)) return(1);
+            }
+          }
+        }
+        return(0);
+      }],glib_cv_working_bcopy=yes,glib_cv_working_bcopy=no)])
+  if test "$glib_cv_working_bcopy" == "yes"; then
+    AC_DEFINE(HAVE_WORKING_BCOPY)
+  fi
+fi
+
 # Check for sys_errlist
 AC_MSG_CHECKING(for sys_errlist)
 AC_TRY_LINK(, [
@@ -787,7 +812,7 @@ if test x"$enable_threads" = xyes; then
        # to always be linked with the thread libs on some platforms. 
        # LIBS="$LIBS $G_THREAD_LIBS"
        CFLAGS="$CFLAGS $G_THREAD_CFLAGS"
-       AC_CHECK_FUNCS(localtime_r rand_r)
+       AC_CHECK_FUNCS(localtime_r)
        if test "$ac_cv_header_pwd_h" = "yes"; then
                AC_MSG_CHECKING([for getpwuid_r])
                AC_CACHE_VAL(ac_cv_func_getpwuid_r,
@@ -1330,13 +1355,17 @@ x$ac_cv_func_memmove)
   glib_memmove='
 #define g_memmove(d,s,n) G_STMT_START { memmove ((d), (s), (n)); } G_STMT_END'
   ;;
-*)
+x$glib_cv_working_bcopy)
   glib_memmove="
-/* We make the assumption that if memmove isn't available, then
- * bcopy will do the job. This isn't safe everywhere. (bcopy can't
- * necessarily handle overlapping copies) */
+/* memmove isn't available, but bcopy can copy overlapping memory regions */
 #define g_memmove(d,s,n) G_STMT_START { bcopy ((s), (d), (n)); } G_STMT_END"
   ;;
+*)  
+  glib_memmove="
+/* memmove isn't found and bcopy can't copy overlapping memory regions, 
+ * so we have to roll our own copy routine. */
+void g_memmove (void* dest, const void * src, unsigned long len);"
+  ;;
 esac
 
 glib_defines="
diff --git a/glib.h b/glib.h
index 9d56225..0ce44a3 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -58,7 +58,7 @@
  *    To register hooks which are executed on exit().
  *    Usually a wrapper for STDC atexit.
  *
- *  void *g_memmove(void *dest, const void *src, guint count);
+ *  void g_memmove(gpointer dest, gconstpointer void *src, gulong count);
  *    A wrapper for STDC memmove, or an implementation, if memmove doesn't
  *    exist.  The prototype looks like the above, give or take a const,
  *    or size_t.
index 9d56225..0ce44a3 100644 (file)
@@ -58,7 +58,7 @@
  *    To register hooks which are executed on exit().
  *    Usually a wrapper for STDC atexit.
  *
- *  void *g_memmove(void *dest, const void *src, guint count);
+ *  void g_memmove(gpointer dest, gconstpointer void *src, gulong count);
  *    A wrapper for STDC memmove, or an implementation, if memmove doesn't
  *    exist.  The prototype looks like the above, give or take a const,
  *    or size_t.
index 1c80b15..513af9f 100644 (file)
@@ -81,6 +81,32 @@ const guint glib_micro_version = GLIB_MICRO_VERSION;
 const guint glib_interface_age = GLIB_INTERFACE_AGE;
 const guint glib_binary_age = GLIB_BINARY_AGE;
 
+#if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY)
+void 
+g_memmove (gpointer dest, gconstpointer src, gulong len)
+{
+  gchar* destptr = dest;
+  const gchar* srcptr = src;
+  if (src + len < dest || dest + len < src)
+    {
+      bcopy (src, dest, len);
+      return;
+    }
+  else if (dest <= src)
+    {
+      while (len--)
+       *(destptr++) = *(srcptr++);
+    }
+  else
+    {
+      destptr += len;
+      srcptr += len;
+      while (len--)
+       *(--destptr) = *(--srcptr);
+    }
+}
+#endif /* !HAVE_MEMMOVE && !HAVE_WORKING_BCOPY */
+
 void
 g_atexit (GVoidFunc func)
 {
index 1c80b15..513af9f 100644 (file)
--- a/gutils.c
+++ b/gutils.c
@@ -81,6 +81,32 @@ const guint glib_micro_version = GLIB_MICRO_VERSION;
 const guint glib_interface_age = GLIB_INTERFACE_AGE;
 const guint glib_binary_age = GLIB_BINARY_AGE;
 
+#if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY)
+void 
+g_memmove (gpointer dest, gconstpointer src, gulong len)
+{
+  gchar* destptr = dest;
+  const gchar* srcptr = src;
+  if (src + len < dest || dest + len < src)
+    {
+      bcopy (src, dest, len);
+      return;
+    }
+  else if (dest <= src)
+    {
+      while (len--)
+       *(destptr++) = *(srcptr++);
+    }
+  else
+    {
+      destptr += len;
+      srcptr += len;
+      while (len--)
+       *(--destptr) = *(--srcptr);
+    }
+}
+#endif /* !HAVE_MEMMOVE && !HAVE_WORKING_BCOPY */
+
 void
 g_atexit (GVoidFunc func)
 {