Removing g_memmove from glib



According to bug 54411 you get warning when you use g_memmove without
including string.h. This is due to g_memmove being a macro. Since we don't
want glib.h to drag in any system headers we can't just include string.h.

If we turn this into a normal function we get extra overhead on every call
and loose the smart optimizations glibc does.

Instead I propose we should just remove g_memmove and require a full ANSI
C compiler (that should include memmove). There aren't many uses of
g_memmove anyway, so this is a relatively painless transition.

Here is a patch for glib, and i've got a patch with about 10 changes in
Gtk+ that I will check in when this goes in.

Is this OK?

/ Alex

Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.206
diff -u -p -r1.206 configure.in
--- configure.in	2001/06/08 12:48:44	1.206
+++ configure.in	2001/06/09 00:00:10
@@ -465,26 +465,7 @@ AC_CHECK_FUNCS(lstat strerror strsignal
 # 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,1,[Have a working bcopy])
-  fi
+  AC_MSG_ERROR([Cannot find function memmove. Glib requires a working memmove.])
 fi

 # Check for sys_errlist
@@ -1658,7 +1639,6 @@ _______EOF

 	cat >>$outfile <<_______EOF
 $glib_atexit
-$glib_memmove
 $glib_defines
 $glib_os

@@ -1923,24 +1903,6 @@ x$ac_cv_func_atexit)
 x$ac_cv_func_on_exit)
   glib_atexit="
 #define g_ATEXIT(proc)	(on_exit ((void (*)(int, void*))(proc), NULL))"
-  ;;
-esac
-
-case xyes in
-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="
-/* 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

Index: garray.c
===================================================================
RCS file: /cvs/gnome/glib/garray.c,v
retrieving revision 1.25
diff -u -p -r1.25 garray.c
--- garray.c	2001/05/23 10:20:54	1.25
+++ garray.c	2001/06/09 00:00:10
@@ -158,8 +158,8 @@ g_array_prepend_vals (GArray        *far

   g_array_maybe_expand (array, len);

-  g_memmove (g_array_elt_pos (array, len), g_array_elt_pos (array, 0),
-	     g_array_elt_len (array, array->len));
+  memmove (g_array_elt_pos (array, len), g_array_elt_pos (array, 0),
+	   g_array_elt_len (array, array->len));

   memcpy (g_array_elt_pos (array, 0), data, g_array_elt_len (array, len));

@@ -180,9 +180,9 @@ g_array_insert_vals (GArray        *farr

   g_array_maybe_expand (array, len);

-  g_memmove (g_array_elt_pos (array, len + index),
-	     g_array_elt_pos (array, index),
-	     g_array_elt_len (array, array->len - index));
+  memmove (g_array_elt_pos (array, len + index),
+	   g_array_elt_pos (array, index),
+	   g_array_elt_len (array, array->len - index));

   memcpy (g_array_elt_pos (array, index), data, g_array_elt_len (array, len));

@@ -228,9 +228,9 @@ g_array_remove_index (GArray* farray,
   g_return_val_if_fail (index < array->len, NULL);

   if (index != array->len - 1)
-    g_memmove (g_array_elt_pos (array, index),
-	       g_array_elt_pos (array, index + 1),
-	       g_array_elt_len (array, array->len - index - 1));
+    memmove (g_array_elt_pos (array, index),
+	     g_array_elt_pos (array, index + 1),
+	     g_array_elt_len (array, array->len - index - 1));

   array->len -= 1;

@@ -473,8 +473,8 @@ g_ptr_array_remove_index (GPtrArray* far
   result = array->pdata[index];

   if (index != array->len - 1)
-    g_memmove (array->pdata + index, array->pdata + index + 1,
-	       sizeof (gpointer) * (array->len - index - 1));
+    memmove (array->pdata + index, array->pdata + index + 1,
+	     sizeof (gpointer) * (array->len - index - 1));

   array->len -= 1;

Index: glibconfig.h.win32.in
===================================================================
RCS file: /cvs/gnome/glib/glibconfig.h.win32.in,v
retrieving revision 1.15
diff -u -p -r1.15 glibconfig.h.win32.in
--- glibconfig.h.win32.in	2001/05/22 12:28:05	1.15
+++ glibconfig.h.win32.in	2001/06/09 00:00:10
@@ -97,8 +97,6 @@ typedef guint32 gsize;

 #define g_ATEXIT(proc)	(atexit (proc))

-#define g_memmove(d,s,n) G_STMT_START { memmove ((d), (s), (n)); } G_STMT_END
-
 #define GLIB_MAJOR_VERSION @GLIB_MAJOR_VERSION@
 #define GLIB_MINOR_VERSION @GLIB_MINOR_VERSION@
 #define GLIB_MICRO_VERSION @GLIB_MICRO_VERSION@
Index: gstrfuncs.c
===================================================================
RCS file: /cvs/gnome/glib/gstrfuncs.c,v
retrieving revision 1.56
diff -u -p -r1.56 gstrfuncs.c
--- gstrfuncs.c	2001/06/08 23:14:02	1.56
+++ gstrfuncs.c	2001/06/09 00:00:10
@@ -1279,7 +1279,7 @@ g_strchug (gchar *string)
   for (start = (guchar*) string; *start && isspace (*start); start++)
     ;

-  g_memmove (string, start, strlen ((gchar *) start) + 1);
+  memmove (string, start, strlen ((gchar *) start) + 1);

   return string;
 }
Index: gstring.c
===================================================================
RCS file: /cvs/gnome/glib/gstring.c,v
retrieving revision 1.22
diff -u -p -r1.22 gstring.c
--- gstring.c	2001/03/07 14:46:41	1.22
+++ gstring.c	2001/06/09 00:00:10
@@ -387,10 +387,10 @@ g_string_insert_len (GString     *fstrin
    * of the old string to the end, opening up space
    */
   if (pos < string->len)
-    g_memmove (string->str + pos + len, string->str + pos, string->len - pos);
+    memmove (string->str + pos + len, string->str + pos, string->len - pos);

   /* insert the new string */
-  g_memmove (string->str + pos, val, len);
+  memmove (string->str + pos, val, len);

   string->len += len;

@@ -488,7 +488,7 @@ g_string_insert_c (GString *fstring,

   /* If not just an append, move the old stuff */
   if (pos < string->len)
-    g_memmove (string->str + pos + 1, string->str + pos, string->len - pos);
+    memmove (string->str + pos + 1, string->str + pos, string->len - pos);

   string->str[pos] = c;

@@ -513,7 +513,7 @@ g_string_erase (GString *fstring,
   g_return_val_if_fail (pos + len <= string->len, fstring);

   if (pos + len < string->len)
-    g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
+    memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));

   string->len -= len;

Index: gutils.c
===================================================================
RCS file: /cvs/gnome/glib/gutils.c,v
retrieving revision 1.95
diff -u -p -r1.95 gutils.c
--- gutils.c	2001/05/14 14:53:59	1.95
+++ gutils.c	2001/06/09 00:00:10
@@ -85,32 +85,6 @@ const guint glib_micro_version = GLIB_MI
 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)
 {
@@ -607,7 +581,7 @@ g_path_get_dirname (const gchar	   *file
   len = (guint) 1 + base - file_name;

   base = g_new (gchar, len + 1);
-  g_memmove (base, file_name, len);
+  memmove (base, file_name, len);
   base[len] = 0;

   return base;
Index: gutils.h
===================================================================
RCS file: /cvs/gnome/glib/gutils.h,v
retrieving revision 1.8
diff -u -p -r1.8 gutils.h
--- gutils.h	2001/04/19 13:33:31	1.8
+++ gutils.h	2001/06/09 00:00:10
@@ -60,7 +60,7 @@ G_BEGIN_DECLS
 #  if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
 #    define G_VA_COPY(ap1, ap2)	  (*(ap1) = *(ap2))
 #  elif defined (G_VA_COPY_AS_ARRAY)
-#    define G_VA_COPY(ap1, ap2)	  g_memmove ((ap1), (ap2), sizeof (va_list))
+#    define G_VA_COPY(ap1, ap2)	  memmove ((ap1), (ap2), sizeof (va_list))
 #  else /* va_list is a pointer */
 #    define G_VA_COPY(ap1, ap2)	  ((ap1) = (ap2))
 #  endif /* va_list is a pointer */
Index: docs/Changes-2.0.txt
===================================================================
RCS file: /cvs/gnome/glib/docs/Changes-2.0.txt,v
retrieving revision 1.2
diff -u -p -r1.2 Changes-2.0.txt
--- docs/Changes-2.0.txt	2001/05/03 10:47:32	1.2
+++ docs/Changes-2.0.txt	2001/06/09 00:00:10
@@ -27,4 +27,8 @@
   are now safe against removal of the current item, not the next item.

   It's not recommended to mutate the list in the callback to these
-  functions in any case.
\ No newline at end of file
+  functions in any case.
+
+* g_memmove() was removed since using it caused warnings if you didn't #include
+  string.h. We now require a proper ANSI C compiler/library that includes a working
+  memmove().
Index: gobject/gbsearcharray.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gbsearcharray.c,v
retrieving revision 1.5
diff -u -p -r1.5 gbsearcharray.c
--- gobject/gbsearcharray.c	2001/03/18 04:44:37	1.5
+++ gobject/gbsearcharray.c	2001/06/09 00:00:10
@@ -139,7 +139,7 @@ bsearch_array_insert (GBSearchArray *bar
       else
 	barray->nodes = g_realloc (barray->nodes, barray->n_nodes * sizeof_node);
       check = ((guint8*) barray->nodes) + i * sizeof_node;
-      g_memmove (check + sizeof_node, check, (n_nodes - i) * sizeof_node);
+      memmove (check + sizeof_node, check, (n_nodes - i) * sizeof_node);
     }
   memcpy (check, key_node, sizeof_node);

@@ -179,7 +179,7 @@ g_bsearch_array_remove_node (GBSearchArr
 #endif
   bound -= barray->sizeof_node;
   barray->n_nodes -= 1;
-  g_memmove (node_in_array, node_in_array + barray->sizeof_node, (bound - node_in_array) / barray->sizeof_node);
+  memmove (node_in_array, node_in_array + barray->sizeof_node, (bound - node_in_array) / barray->sizeof_node);

   if ((barray->flags & G_BSEARCH_ARRAY_DEFER_SHRINK) == 0)
     {
Index: gobject/gclosure.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gclosure.c,v
retrieving revision 1.11
diff -u -p -r1.11 gclosure.c
--- gobject/gclosure.c	2001/04/09 17:03:55	1.11
+++ gobject/gclosure.c	2001/06/09 00:00:10
@@ -166,9 +166,9 @@ g_closure_set_meta_marshal (GClosure
   if (notifiers)
     {
       /* usually the meta marshal will be setup right after creation, so the
-       * g_memmove() should be rare-case scenario
+       * memmove() should be rare-case scenario
        */
-      g_memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
+      memmove (closure->notifiers + 1, notifiers, CLOSURE_N_NOTIFIERS (closure) * sizeof (notifiers[0]));
       g_free (notifiers);
     }
   closure->notifiers[0].data = marshal_data;
Index: gobject/gtype.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gtype.c,v
retrieving revision 1.27
diff -u -p -r1.27 gtype.c
--- gobject/gtype.c	2001/05/10 13:58:40	1.27
+++ gobject/gtype.c	2001/06/09 00:00:11
@@ -1055,7 +1055,7 @@ type_node_add_iface_entry_W (TypeNode *n
 						CLASSED_NODE_IFACES_ENTRIES (node),
 						CLASSED_NODE_N_IFACES (node));
   entries = CLASSED_NODE_IFACES_ENTRIES (node);
-  g_memmove (entries + i + 1, entries + i, sizeof (entries[0]) * (CLASSED_NODE_N_IFACES (node) - i - 1));
+  memmove (entries + i + 1, entries + i, sizeof (entries[0]) * (CLASSED_NODE_N_IFACES (node) - i - 1));
   entries[i].iface_type = iface_type;
   entries[i].vtable = NULL;

@@ -1108,8 +1108,8 @@ type_iface_add_prerequisite_W (TypeNode
 					      IFACE_NODE_PREREQUISITES (iface),
 					      IFACE_NODE_N_PREREQUISITES (iface));
   prerequisites = IFACE_NODE_PREREQUISITES (iface);
-  g_memmove (prerequisites + i + 1, prerequisites + i,
-	     sizeof (prerequisites[0]) * (IFACE_NODE_N_PREREQUISITES (iface) - i - 1));
+  memmove (prerequisites + i + 1, prerequisites + i,
+	   sizeof (prerequisites[0]) * (IFACE_NODE_N_PREREQUISITES (iface) - i - 1));
   prerequisites[i] = prerequisite_type;

   /* we want to get notified when prerequisites get added to prerequisite_node */
@@ -1674,9 +1674,9 @@ g_type_remove_class_cache_func (gpointer
 	static_class_cache_funcs[i].cache_func == cache_func)
       {
 	static_n_class_cache_funcs--;
-	g_memmove (static_class_cache_funcs + i,
-		   static_class_cache_funcs + i + 1,
-		   sizeof (static_class_cache_funcs[0]) * (static_n_class_cache_funcs - i));
+	memmove (static_class_cache_funcs + i,
+		 static_class_cache_funcs + i + 1,
+		 sizeof (static_class_cache_funcs[0]) * (static_n_class_cache_funcs - i));
 	static_class_cache_funcs = g_renew (ClassCacheFunc, static_class_cache_funcs, static_n_class_cache_funcs);
 	found_it = TRUE;
 	break;
@@ -2313,7 +2313,7 @@ type_set_qdata_W (TypeNode *node,
   for (i = 0; i < gdata->n_qdatas - 1; i++)
     if (qdata[i].quark > quark)
       break;
-  g_memmove (qdata + i + 1, qdata + i, sizeof (qdata[0]) * (gdata->n_qdatas - i - 1));
+  memmove (qdata + i + 1, qdata + i, sizeof (qdata[0]) * (gdata->n_qdatas - i - 1));
   qdata[i].quark = quark;
   qdata[i].data = data;
 }
Index: gobject/gvaluearray.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gvaluearray.c,v
retrieving revision 1.1
diff -u -p -r1.1 gvaluearray.c
--- gobject/gvaluearray.c	2001/03/07 14:46:45	1.1
+++ gobject/gvaluearray.c	2001/06/09 00:00:11
@@ -124,8 +124,8 @@ g_value_array_insert (GValueArray  *valu
   i = value_array->n_values++;
   value_array->values = g_renew (GValue, value_array->values, value_array->n_values);
   if (index + 1 < value_array->n_values)
-    g_memmove (value_array->values + index + 1, value_array->values + index,
-	       (i - index) * sizeof (value_array->values[0]));
+    memmove (value_array->values + index + 1, value_array->values + index,
+	     (i - index) * sizeof (value_array->values[0]));
   memset (value_array->values + index, 0, sizeof (value_array->values[0]));
   if (value)
     {
@@ -146,8 +146,8 @@ g_value_array_remove (GValueArray *value
     g_value_unset (value_array->values + index);
   value_array->n_values--;
   if (index < value_array->n_values)
-    g_memmove (value_array->values + index, value_array->values + index + 1,
-	       (value_array->n_values - index) * sizeof (value_array->values[0]));
+    memmove (value_array->values + index, value_array->values + index + 1,
+	     (value_array->n_values - index) * sizeof (value_array->values[0]));
   value_array->values = g_renew (GValue, value_array->values, value_array->n_values);

   return value_array;





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]