From 6e4a7fca431f53fdfd89afbe956212229cf52200 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sat, 19 Oct 2013 13:03:58 -0400 Subject: [PATCH] Require C90 compliance Assume all supported platforms implement C90, and therefore they (correctly) implement atexit(), memmove(), setlocale(), strerror(), and vprintf(), and have and . (Also remove the configure check testing that "do ... while (0)" works correctly; the non-do/while-based version of G_STMT_START and G_STMT_END was removed years ago, but the check remained. Also, remove some checks that configure.ac claimed were needed for libcharset, but aren't actually used.) Note that removing the g_memmove() function is not an ABI break even on systems where g_memmove() was previously not a macro, because it was never marked GLIB_AVAILABLE_IN_ALL or listed in glib.symbols, so it would have been glib-internal since 2004. https://bugzilla.gnome.org/show_bug.cgi?id=710519 --- config.h.win32.in | 33 -------- configure.ac | 154 +++++++----------------------------- gio/gbufferedinputstream.c | 2 +- gio/gbufferedoutputstream.c | 2 +- glib/garray.c | 32 ++++---- glib/gbsearcharray.h | 4 +- glib/gfileutils.c | 2 +- glib/gslice.c | 14 +--- glib/gstrfuncs.c | 15 +--- glib/gstring.c | 10 +-- glib/gutils.c | 56 ++----------- glib/gutils.h | 13 +-- glib/pcre/Makefile.am | 1 + glib/tests/test-printf.c | 2 - gobject/gtype.c | 18 ++--- gobject/gvaluearray.c | 8 +- 16 files changed, 80 insertions(+), 286 deletions(-) diff --git a/config.h.win32.in b/config.h.win32.in index 034880965..51b22f8d7 100644 --- a/config.h.win32.in +++ b/config.h.win32.in @@ -180,9 +180,6 @@ /* Define to 1 if you have the `fdwalk' function. */ /* #undef HAVE_FDWALK */ -/* Define to 1 if you have the header file. */ -#define HAVE_FLOAT_H 1 - /* Define to 1 if you have the header file. */ /* #undef HAVE_FSTAB_H */ @@ -314,9 +311,6 @@ /* Define if libelf is available */ /* #undef HAVE_LIBELF */ -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - /* Define to 1 if you have the `link' function. */ /* #undef HAVE_LINK */ @@ -354,9 +348,6 @@ /* Define to 1 if you have the `memmem' function. */ /* #undef HAVE_MEMMEM */ -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 @@ -381,9 +372,6 @@ /* Have non-POSIX function getpwuid_r */ /* #undef HAVE_NONPOSIX_GETPWUID_R */ -/* Define to 1 if you have the `on_exit' function. */ -/* #undef HAVE_ON_EXIT */ - /* Define to 1 if you have the `pipe2' function. */ /* #undef HAVE_PIPE2 */ @@ -438,9 +426,6 @@ /* Define to 1 if you have the `setenv' function. */ /* #undef HAVE_SETENV */ -/* Define to 1 if you have the `setlocale' function. */ -#define HAVE_SETLOCALE 1 - /* Define to 1 if you have the `setmntent' function. */ /* #undef HAVE_SETMNTENT */ @@ -466,9 +451,6 @@ /* Define to 1 if you have the `statvfs' function. */ /* #undef HAVE_STATVFS */ -/* Define to 1 if you have the header file. */ -#define HAVE_STDDEF_H 1 - /* Define to 1 if you have the header file. */ #ifndef _MSC_VER #define HAVE_STDINT_H 1 @@ -492,9 +474,6 @@ #endif #endif /* _MSC_VER */ -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - /* Define to 1 if you have the `stpcpy' function. */ /* #undef HAVE_STPCPY */ @@ -507,9 +486,6 @@ #define HAVE_STRCASECMP 1 #endif /* _MSC_VER or __gcc__ */ -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - /* Define to 1 if you have the header file. */ #if !defined(_MSC_VER) && !defined(__DMC__) #define HAVE_STRINGS_H 1 @@ -517,9 +493,6 @@ /* #undef HAVE_STRINGS_H */ #endif /* _MSC_VER or __DMC__ */ -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - /* Have functions strlcpy and strlcat */ /* #undef HAVE_STRLCPY */ @@ -723,9 +696,6 @@ /* Define to 1 if you have the `vasprintf' function. */ #define HAVE_VASPRINTF 1 -/* Define to 1 if you have the `vprintf' function. */ -#define HAVE_VPRINTF 1 - /* Define to 1 if you have the `vsnprintf' function. */ #ifndef _MSC_VER #define HAVE_VSNPRINTF 1 @@ -748,9 +718,6 @@ /* Define if you have the 'wint_t' type. */ #define HAVE_WINT_T 1 -/* Have a working bcopy */ -/* #undef HAVE_WORKING_BCOPY */ - /* Define to 1 if xattr is available */ /* #undef HAVE_XATTR */ diff --git a/configure.ac b/configure.ac index a7f1a23f2..608c3d05f 100644 --- a/configure.ac +++ b/configure.ac @@ -508,10 +508,9 @@ AS_IF([test "$glib_native_win32" = "yes"], [ AM_CONDITIONAL(OS_WIN32_AND_DLL_COMPILATION, [test x$glib_native_win32 = xyes -a x$glib_win32_static_compilation != xyes]) # Checks for library functions. -AC_FUNC_VPRINTF AC_FUNC_ALLOCA AC_CHECK_FUNCS(mmap posix_memalign memalign valloc fsync pipe2 issetugid) -AC_CHECK_FUNCS(atexit on_exit timegm gmtime_r) +AC_CHECK_FUNCS(timegm gmtime_r) AC_CACHE_CHECK([for __libc_enable_secure], glib_cv_have_libc_enable_secure, [AC_TRY_LINK([#include @@ -679,21 +678,6 @@ main (void) { }]])],[g_can_inline=yes],[g_can_inline=no]) AC_MSG_RESULT($g_can_inline) -dnl *** check for working do while(0) macros *** -AC_CACHE_CHECK([for working do while(0) macros], g_cv_support_dowhile_macros, [ - AC_TRY_COMPILE([],[ - #define STMT_START do - #define STMT_END while(0) - #define STMT_TEST STMT_START { i = 0; } STMT_END - int main(void) { int i = 1; STMT_TEST; return i; }], - [g_cv_support_dowhile_macros=yes], - [g_cv_support_dowhile_macros=no], - [g_cv_support_dowhile_macros=yes]) -]) -if test x$g_cv_support_dowhile_macros = xyes; then - AC_DEFINE(HAVE_DOWHILE_MACROS, 1, [define for working do while(0) macros]) -fi - # check for flavours of varargs macros AC_MSG_CHECKING(for ISO C99 varargs macros in C) AC_TRY_COMPILE([],[ @@ -788,8 +772,8 @@ fi # check for header files -AC_CHECK_HEADERS([dirent.h float.h limits.h pwd.h grp.h sys/param.h sys/poll.h sys/resource.h]) -AC_CHECK_HEADERS([sys/time.h sys/times.h sys/wait.h unistd.h values.h]) +AC_CHECK_HEADERS([dirent.h pwd.h grp.h sys/param.h sys/poll.h sys/resource.h]) +AC_CHECK_HEADERS([sys/time.h sys/times.h sys/wait.h unistd.h]) AC_CHECK_HEADERS([sys/select.h sys/types.h stdint.h inttypes.h sched.h malloc.h]) AC_CHECK_HEADERS([sys/vfs.h sys/vmount.h sys/statfs.h sys/statvfs.h sys/filio.h]) AC_CHECK_HEADERS([mntent.h sys/mnttab.h sys/vfstab.h sys/mntctl.h fstab.h]) @@ -797,6 +781,10 @@ AC_CHECK_HEADERS([sys/uio.h]) AC_CHECK_HEADERS([linux/magic.h]) AC_CHECK_HEADERS([sys/prctl.h]) +# We don't care about this, but we need to keep including it in +# glibconfig.h for backward compatibility +AC_CHECK_HEADERS([values.h]) + AC_CHECK_HEADERS([sys/mount.h sys/sysctl.h], [], [], [#if HAVE_SYS_PARAM_H #include @@ -830,8 +818,6 @@ AC_STRUCT_DIRENT_D_TYPE # Checks for libcharset AM_LANGINFO_CODESET -AC_CHECK_HEADERS([stddef.h stdlib.h string.h]) -AC_CHECK_FUNCS(setlocale) gl_GLIBC21 # check additional type sizes @@ -978,7 +964,7 @@ int main () AC_MSG_RESULT($glib_ssize_type) # Check for some functions -AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd vasprintf setenv unsetenv getc_unlocked readlink symlink fdwalk memmem) +AC_CHECK_FUNCS(lstat strsignal vsnprintf stpcpy strcasecmp strncasecmp poll getcwd vasprintf setenv unsetenv getc_unlocked readlink symlink fdwalk memmem) AC_CHECK_FUNCS(chown lchmod lchown fchmod fchown link utimes getgrgid getpwuid getresuid) AC_CHECK_FUNCS(getmntent_r setmntent endmntent hasmntopt getfsstat getvfsstat fallocate) # Check for high-resolution sleep functions @@ -1247,33 +1233,6 @@ jm_AC_TYPE_INTMAX_T AC_CHECK_FUNCS([snprintf wcslen]) AC_FUNC_SNPRINTF_C99 -# Check if bcopy can be used for overlapping copies, if memmove isn't found. -# The check is borrowed from the PERL Configure script. -AS_IF([test "$ac_cv_func_memmove" != "yes"], [ - 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)]) - - GLIB_ASSERT_SET(glib_cv_working_bcopy) - if test "$glib_cv_working_bcopy" = "yes"; then - AC_DEFINE(HAVE_WORKING_BCOPY,1,[Have a working bcopy]) - fi -]) - # Check if needs to be included for fd_set AC_MSG_CHECKING([for fd_set]) AC_TRY_COMPILE([#include ], @@ -2847,12 +2806,8 @@ AC_CONFIG_COMMANDS([glib/glibconfig.h], _______EOF - if test x$glib_limits_h = xyes; then - echo '#include ' >> $outfile - fi - if test x$glib_float_h = xyes; then - echo '#include ' >> $outfile - fi + echo '#include ' >> $outfile + echo '#include ' >> $outfile if test x$glib_values_h = xyes; then echo '#include ' >> $outfile fi @@ -2875,19 +2830,19 @@ _______EOF G_BEGIN_DECLS -#define G_MINFLOAT $glib_mf -#define G_MAXFLOAT $glib_Mf -#define G_MINDOUBLE $glib_md -#define G_MAXDOUBLE $glib_Md -#define G_MINSHORT $glib_ms -#define G_MAXSHORT $glib_Ms -#define G_MAXUSHORT $glib_Mus -#define G_MININT $glib_mi -#define G_MAXINT $glib_Mi -#define G_MAXUINT $glib_Mui -#define G_MINLONG $glib_ml -#define G_MAXLONG $glib_Ml -#define G_MAXULONG $glib_Mul +#define G_MINFLOAT FLT_MIN +#define G_MAXFLOAT FLT_MAX +#define G_MINDOUBLE DBL_MIN +#define G_MAXDOUBLE DBL_MAX +#define G_MINSHORT SHRT_MIN +#define G_MAXSHORT SHRT_MAX +#define G_MAXUSHORT USHRT_MAX +#define G_MININT INT_MIN +#define G_MAXINT INT_MAX +#define G_MAXUINT UINT_MAX +#define G_MINLONG LONG_MIN +#define G_MAXLONG LONG_MAX +#define G_MAXULONG ULONG_MAX _______EOF @@ -2998,8 +2953,10 @@ _______EOF cat >>$outfile <<_______EOF -$glib_atexit -$glib_memmove +#ifndef G_DISABLE_DEPRECATED +#define g_ATEXIT(proc) (atexit (proc)) +#define g_memmove(dest,src,len) G_STMT_START { memmove ((dest), (src), (len)); } G_STMT_END +#endif $glib_defines $glib_os $glib_static_compilation @@ -3178,34 +3135,6 @@ else glib_header_alloca_h="$ac_cv_header_alloca_h" fi -case xyes in -x$ac_cv_header_float_h) - glib_float_h=yes - glib_mf=FLT_MIN glib_Mf=FLT_MAX - glib_md=DBL_MIN glib_Md=DBL_MAX - ;; -x$ac_cv_header_values_h) - glib_values_h=yes - glib_mf=MINFLOAT glib_Mf=MAXFLOAT - glib_md=MINDOUBLE glib_Md=MAXDOUBLE - ;; -esac - -case xyes in -x$ac_cv_header_limits_h) - glib_limits_h=yes - glib_ms=SHRT_MIN glib_Ms=SHRT_MAX glib_Mus=USHRT_MAX - glib_mi=INT_MIN glib_Mi=INT_MAX glib_Mui=UINT_MAX - glib_ml=LONG_MIN glib_Ml=LONG_MAX glib_Mul=ULONG_MAX - ;; -x$ac_cv_header_values_h) - glib_values_h=yes - glib_ms=MINSHORT glib_Ms=MAXSHORT glib_Mus="(((gushort)G_MAXSHORT)*2+1)" - glib_mi=MININT glib_Mi=MAXINT glib_Mui="(((guint)G_MAXINT)*2+1)" - glib_ml=MINLONG glib_Ml=MAXLONG glib_Mul="(((gulong)G_MAXLONG)*2+1)" - ;; -esac - if test x$ac_cv_header_sys_poll_h = xyes ; then glib_sys_poll_h=yes fi @@ -3387,35 +3316,6 @@ $ac_cv_sizeof___int64) esac -case xyes in -x$ac_cv_func_atexit) - glib_atexit=" -#define g_ATEXIT(proc) (atexit (proc))" - ;; -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(dest,src,len) G_STMT_START { memmove ((dest), (src), (len)); } 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 - glib_defines=" #define GLIB_MAJOR_VERSION $GLIB_MAJOR_VERSION #define GLIB_MINOR_VERSION $GLIB_MINOR_VERSION diff --git a/gio/gbufferedinputstream.c b/gio/gbufferedinputstream.c index 6b9257ad7..1053b1cb9 100644 --- a/gio/gbufferedinputstream.c +++ b/gio/gbufferedinputstream.c @@ -639,7 +639,7 @@ compact_buffer (GBufferedInputStream *stream) current_size = priv->end - priv->pos; - g_memmove (priv->buffer, priv->buffer + priv->pos, current_size); + memmove (priv->buffer, priv->buffer + priv->pos, current_size); priv->pos = 0; priv->end = current_size; diff --git a/gio/gbufferedoutputstream.c b/gio/gbufferedoutputstream.c index d0798918e..6731b01fe 100644 --- a/gio/gbufferedoutputstream.c +++ b/gio/gbufferedoutputstream.c @@ -431,7 +431,7 @@ flush_buffer (GBufferedOutputStream *stream, count = priv->pos - bytes_written; if (count > 0) - g_memmove (priv->buffer, priv->buffer + bytes_written, count); + memmove (priv->buffer, priv->buffer + bytes_written, count); priv->pos -= bytes_written; diff --git a/glib/garray.c b/glib/garray.c index a93044b85..1446492f0 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -476,8 +476,8 @@ g_array_prepend_vals (GArray *farray, 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)); @@ -525,9 +525,9 @@ g_array_insert_vals (GArray *farray, 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)); @@ -597,9 +597,9 @@ g_array_remove_index (GArray *farray, array->clear_func (g_array_elt_pos (array, index_)); 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; @@ -684,9 +684,9 @@ g_array_remove_range (GArray *farray, } if (index_ + length != array->len) - g_memmove (g_array_elt_pos (array, index_), - g_array_elt_pos (array, index_ + length), - (array->len - (index_ + length)) * array->elt_size); + memmove (g_array_elt_pos (array, index_), + g_array_elt_pos (array, index_ + length), + (array->len - (index_ + length)) * array->elt_size); array->len -= length; if (G_UNLIKELY (g_mem_gc_friendly)) @@ -1185,8 +1185,8 @@ g_ptr_array_remove_index (GPtrArray *farray, array->element_free_func (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; @@ -1269,9 +1269,9 @@ g_ptr_array_remove_range (GPtrArray *farray, if (index_ + length != array->len) { - g_memmove (&array->pdata[index_], - &array->pdata[index_ + length], - (array->len - (index_ + length)) * sizeof (gpointer)); + memmove (&array->pdata[index_], + &array->pdata[index_ + length], + (array->len - (index_ + length)) * sizeof (gpointer)); } array->len -= length; diff --git a/glib/gbsearcharray.h b/glib/gbsearcharray.h index 98822cbc7..832522e27 100644 --- a/glib/gbsearcharray.h +++ b/glib/gbsearcharray.h @@ -215,7 +215,7 @@ g_bsearch_array_grow (GBSearchArray *barray, else barray = (GBSearchArray *) g_realloc (barray, sizeof (GBSearchArray) + new_size); node = G_BSEARCH_ARRAY_NODES (barray) + index_ * bconfig->sizeof_node; - g_memmove (node + bconfig->sizeof_node, node, (barray->n_nodes - index_) * bconfig->sizeof_node); + memmove (node + bconfig->sizeof_node, node, (barray->n_nodes - index_) * bconfig->sizeof_node); barray->n_nodes += 1; return barray; } @@ -271,7 +271,7 @@ g_bsearch_array_remove (GBSearchArray *barray, barray->n_nodes -= 1; node = G_BSEARCH_ARRAY_NODES (barray) + index_ * bconfig->sizeof_node; - g_memmove (node, node + bconfig->sizeof_node, (barray->n_nodes - index_) * bconfig->sizeof_node); + memmove (node, node + bconfig->sizeof_node, (barray->n_nodes - index_) * bconfig->sizeof_node); if (G_UNLIKELY (bconfig->flags & G_BSEARCH_ARRAY_AUTO_SHRINK)) { guint new_size = barray->n_nodes * bconfig->sizeof_node; diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 88a647d59..90fb40501 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -2419,7 +2419,7 @@ g_path_get_dirname (const gchar *file_name) 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; diff --git a/glib/gslice.c b/glib/gslice.c index 7a8268bb1..24ce62f69 100644 --- a/glib/gslice.c +++ b/glib/gslice.c @@ -1265,10 +1265,7 @@ allocator_add_slab (Allocator *allocator, guint i; if (!mem) { - const gchar *syserr = "unknown error"; -#if HAVE_STRERROR - syserr = strerror (errno); -#endif + const gchar *syserr = strerror (errno); mem_error ("failed to allocate %u bytes (alignment: %u): %s\n", (guint) (page_size - NATIVE_MALLOC_PADDING), (guint) page_size, syserr); } @@ -1534,10 +1531,7 @@ static SmcBranch **smc_tree_root = NULL; static void smc_tree_abort (int errval) { - const char *syserr = "unknown error"; -#if HAVE_STRERROR - syserr = strerror (errval); -#endif + const char *syserr = strerror (errval); mem_error ("MemChecker: failure in debugging tree: %s", syserr); } @@ -1553,7 +1547,7 @@ smc_tree_branch_grow_L (SmcBranch *branch, if (!branch->entries) smc_tree_abort (errno); entry = branch->entries + index; - g_memmove (entry + 1, entry, (branch->n_entries - index) * sizeof (entry[0])); + memmove (entry + 1, entry, (branch->n_entries - index) * sizeof (entry[0])); branch->n_entries += 1; return entry; } @@ -1652,7 +1646,7 @@ smc_tree_remove (SmcKType key) { unsigned int i = entry - smc_tree_root[ix0][ix1].entries; smc_tree_root[ix0][ix1].n_entries -= 1; - g_memmove (entry, entry + 1, (smc_tree_root[ix0][ix1].n_entries - i) * sizeof (entry[0])); + memmove (entry, entry + 1, (smc_tree_root[ix0][ix1].n_entries - i) * sizeof (entry[0])); if (!smc_tree_root[ix0][ix1].n_entries) { /* avoid useless pressure on the memory system */ diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index ad4132d64..a0b9dff38 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -1250,25 +1250,14 @@ g_ascii_strtoll (const gchar *nptr, const gchar * g_strerror (gint errnum) { - gchar buf[64]; gchar *msg; - gchar *tofree; + gchar *tofree = NULL; const gchar *ret; gint saved_errno = errno; - msg = tofree = NULL; - -#ifdef HAVE_STRERROR msg = strerror (errnum); if (!g_get_charset (NULL)) msg = tofree = g_locale_to_utf8 (msg, -1, NULL, NULL, NULL); -#endif - - if (!msg) - { - msg = buf; - _g_sprintf (msg, "unknown error (%d)", errnum); - } ret = g_intern_string (msg); g_free (tofree); @@ -2220,7 +2209,7 @@ g_strchug (gchar *string) for (start = (guchar*) string; *start && g_ascii_isspace (*start); start++) ; - g_memmove (string, start, strlen ((gchar *) start) + 1); + memmove (string, start, strlen ((gchar *) start) + 1); return string; } diff --git a/glib/gstring.c b/glib/gstring.c index 2f89551f6..ef77133c6 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -460,7 +460,7 @@ g_string_insert_len (GString *string, /* Open up space where we are going to insert. */ 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); /* Move the source part before the gap, if any. */ if (offset < pos) @@ -483,7 +483,7 @@ g_string_insert_len (GString *string, * 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 */ if (len == 1) @@ -805,7 +805,7 @@ g_string_insert_c (GString *string, /* 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; @@ -880,7 +880,7 @@ g_string_insert_unichar (GString *string, /* If not just an append, move the old stuff */ if (pos < string->len) - g_memmove (string->str + pos + charlen, string->str + pos, string->len - pos); + memmove (string->str + pos + charlen, string->str + pos, string->len - pos); dest = string->str + pos; /* Code copied from g_unichar_to_utf() */ @@ -997,7 +997,7 @@ g_string_erase (GString *string, g_return_val_if_fail (pos + len <= string->len, string); 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; diff --git a/glib/gutils.c b/glib/gutils.c index 898deb8cf..70301a139 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -172,7 +172,6 @@ _glib_get_dll_directory (void) #endif -#if !defined (HAVE_MEMMOVE) && !defined (HAVE_WORKING_BCOPY) /** * g_memmove: * @dest: the destination address to copy the bytes to. @@ -182,37 +181,8 @@ _glib_get_dll_directory (void) * Copies a block of memory @len bytes long, from @src to @dest. * The source and destination areas may overlap. * - * In order to use this function, you must include - * string.h yourself, because this macro will - * typically simply resolve to memmove() and GLib does not include - * string.h for you. + * Deprecated:2.40: Just use memmove(). */ -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 */ #ifdef G_OS_WIN32 #undef g_atexit @@ -259,29 +229,13 @@ void g_atexit (GVoidFunc func) { gint result; - const gchar *error = NULL; - /* keep this in sync with glib.h */ - -#ifdef G_NATIVE_ATEXIT - result = ATEXIT (func); - if (result) - error = g_strerror (errno); -#elif defined (HAVE_ATEXIT) result = atexit ((void (*)(void)) func); if (result) - error = g_strerror (errno); -#elif defined (HAVE_ON_EXIT) - result = on_exit ((void (*)(int, void *)) func, NULL); - if (result) - error = g_strerror (errno); -#else - result = 0; - error = "no implementation"; -#endif /* G_NATIVE_ATEXIT */ - - if (error) - g_error ("Could not register atexit() function: %s", error); + { + g_error ("Could not register atexit() function: %s", + g_strerror (errno)); + } } /* Based on execvp() from GNU Libc. diff --git a/glib/gutils.h b/glib/gutils.h index 472f3c262..3b29b574a 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -43,7 +43,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 */ @@ -239,16 +239,7 @@ gchar *g_format_size_for_display (goffset size); * function passed to g_atexit(). */ typedef void (*GVoidFunc) (void); -#ifndef ATEXIT -# define ATEXIT(proc) g_ATEXIT(proc) -#else -# define G_NATIVE_ATEXIT -#endif /* ATEXIT */ -/* we use a GLib function as a replacement for ATEXIT, so - * the programmer is not required to check the return value - * (if there is any in the implementation) and doesn't encounter - * missing include files. - */ +#define ATEXIT(proc) g_ATEXIT(proc) GLIB_DEPRECATED void g_atexit (GVoidFunc func); diff --git a/glib/pcre/Makefile.am b/glib/pcre/Makefile.am index 14442dcc0..386b7abea 100644 --- a/glib/pcre/Makefile.am +++ b/glib/pcre/Makefile.am @@ -5,6 +5,7 @@ noinst_LTLIBRARIES += libpcre.la libpcre_la_CPPFLAGS = \ -DG_LOG_DOMAIN=\"GLib-GRegex\" \ -DHAVE_CONFIG_H \ + -DHAVE_MEMMOVE \ -DSUPPORT_UCP \ -DSUPPORT_UTF \ -DSUPPORT_UTF8 \ diff --git a/glib/tests/test-printf.c b/glib/tests/test-printf.c index ef1ce1614..d845dfa7d 100644 --- a/glib/tests/test-printf.c +++ b/glib/tests/test-printf.c @@ -548,11 +548,9 @@ test_s (void) g_assert_cmpint (res, ==, 5); g_assert_cmpstr (buf, ==, " abc"); -#if 0 /* HP-UX doesn't get this right */ res = g_snprintf (buf, 128, "%*s", -5, "abc"); g_assert_cmpint (res, ==, 5); g_assert_cmpstr (buf, ==, "abc "); -#endif res = g_snprintf (buf, 128, "%*.*s", 5, 2, "abc"); g_assert_cmpint (res, ==, 5); diff --git a/gobject/gtype.c b/gobject/gtype.c index 505163928..6b1cf7d20 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -1525,8 +1525,8 @@ type_iface_add_prerequisite_W (TypeNode *iface, 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 */ @@ -2495,9 +2495,9 @@ g_type_remove_class_cache_func (gpointer cache_data, 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; @@ -2569,9 +2569,9 @@ g_type_remove_interface_check (gpointer check_data, static_iface_check_funcs[i].check_func == check_func) { static_n_iface_check_funcs--; - g_memmove (static_iface_check_funcs + i, - static_iface_check_funcs + i + 1, - sizeof (static_iface_check_funcs[0]) * (static_n_iface_check_funcs - i)); + memmove (static_iface_check_funcs + i, + static_iface_check_funcs + i + 1, + sizeof (static_iface_check_funcs[0]) * (static_n_iface_check_funcs - i)); static_iface_check_funcs = g_renew (IFaceCheckFunc, static_iface_check_funcs, static_n_iface_check_funcs); found_it = TRUE; break; @@ -3724,7 +3724,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; } diff --git a/gobject/gvaluearray.c b/gobject/gvaluearray.c index e3fe2554c..a3d2cb0d0 100644 --- a/gobject/gvaluearray.c +++ b/gobject/gvaluearray.c @@ -282,8 +282,8 @@ g_value_array_insert (GValueArray *value_array, i = value_array->n_values; value_array_grow (value_array, value_array->n_values + 1, FALSE); 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) { @@ -317,8 +317,8 @@ g_value_array_remove (GValueArray *value_array, 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_shrink (value_array); if (value_array->n_prealloced > value_array->n_values) memset (value_array->values + value_array->n_values, 0, sizeof (value_array->values[0]));