From d610460c2264273b9520c0a932a34431efb56887 Mon Sep 17 00:00:00 2001 From: Sebastian Wilhelmi Date: Thu, 1 Jul 1999 09:30:18 +0000 Subject: [PATCH] Added a g_memmove replacement for platforms without memmove, where bcopy 1999-07-01 Sebastian Wilhelmi * 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. --- ChangeLog | 12 ++++++++++++ ChangeLog.pre-2-0 | 12 ++++++++++++ ChangeLog.pre-2-10 | 12 ++++++++++++ ChangeLog.pre-2-12 | 12 ++++++++++++ ChangeLog.pre-2-2 | 12 ++++++++++++ ChangeLog.pre-2-4 | 12 ++++++++++++ ChangeLog.pre-2-6 | 12 ++++++++++++ ChangeLog.pre-2-8 | 12 ++++++++++++ acconfig.h | 1 + configure.in | 39 ++++++++++++++++++++++++++++++++++----- glib.h | 2 +- glib/glib.h | 2 +- glib/gutils.c | 26 ++++++++++++++++++++++++++ gutils.c | 26 ++++++++++++++++++++++++++ 14 files changed, 185 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 07940725..8f2665d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 07940725..8f2665d7 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 07940725..8f2665d7 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 07940725..8f2665d7 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 07940725..8f2665d7 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 07940725..8f2665d7 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 07940725..8f2665d7 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 07940725..8f2665d7 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +1999-07-01 Sebastian Wilhelmi + + * 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 * glib.h, grand.c: Finally removed the g_random_normal and diff --git a/acconfig.h b/acconfig.h index 1c630e11..15040657 100644 --- a/acconfig.h +++ b/acconfig.h @@ -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 diff --git a/configure.in b/configure.in index 5bb16dfc..aa079119 100644 --- a/configure.in +++ b/configure.in @@ -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 9d562258..0ce44a32 100644 --- 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. diff --git a/glib/glib.h b/glib/glib.h index 9d562258..0ce44a32 100644 --- a/glib/glib.h +++ b/glib/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. diff --git a/glib/gutils.c b/glib/gutils.c index 1c80b150..513af9f3 100644 --- a/glib/gutils.c +++ b/glib/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) { diff --git a/gutils.c b/gutils.c index 1c80b150..513af9f3 100644 --- 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) { -- 2.34.1