From 0e2f565f144415c95a721b483c062239f82f0894 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Fri, 1 Jan 1999 23:35:26 +0000 Subject: [PATCH] Added two new alloca-based function macros, g_strdup_a and g_strconcat_a. * configure.in, glib.h: Added two new alloca-based function macros, g_strdup_a and g_strconcat_a. These are stack-based and much faster than their g_malloc-based counterparts. Kudos to Ulrich Drepper for help on this one. --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-0 | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ ChangeLog.pre-2-2 | 8 ++++++++ ChangeLog.pre-2-4 | 8 ++++++++ ChangeLog.pre-2-6 | 8 ++++++++ ChangeLog.pre-2-8 | 8 ++++++++ configure.in | 47 ++++++++++++++++++++++++++++++++++++++++++++++ glib.h | 31 ++++++++++++++++++++++++++++++ glib/glib.h | 31 ++++++++++++++++++++++++++++++ 11 files changed, 173 insertions(+) diff --git a/ChangeLog b/ChangeLog index a663de9a4..3493f5fc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index a663de9a4..3493f5fc3 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a663de9a4..3493f5fc3 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index a663de9a4..3493f5fc3 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index a663de9a4..3493f5fc3 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index a663de9a4..3493f5fc3 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index a663de9a4..3493f5fc3 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index a663de9a4..3493f5fc3 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +Fri Jan 1 17:09:19 EST 1999 Jeff Garzik + + * configure.in, glib.h: + Added two new alloca-based function macros, g_strdup_a and + g_strconcat_a. These are stack-based and much faster than + their g_malloc-based counterparts. Kudos to Ulrich Drepper + for help on this one. + Wed Dec 30 18:24:57 CST 1998 Shawn T. Amundson * Released GLib 1.1.11 diff --git a/configure.in b/configure.in index 2b1bbd66b..ea05878c4 100644 --- a/configure.in +++ b/configure.in @@ -168,6 +168,12 @@ AC_HEADER_STDC # Checks for library functions. AC_FUNC_VPRINTF +AC_FUNC_ALLOCA +if test "x$ac_cv_func_alloca_works" = xyes; then + glib_have_alloca=yes +else + glib_have_alloca=no +fi AC_CHECK_FUNCS(atexit on_exit) @@ -245,6 +251,7 @@ AC_CHECK_HEADERS(sys/time.h, AC_DEFINE(HAVE_SYS_TIME_H)) AC_CHECK_HEADERS(sys/times.h, AC_DEFINE(HAVE_SYS_TIMES_H)) AC_CHECK_HEADERS(unistd.h, AC_DEFINE(HAVE_UNISTD_H)) AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H)) +AC_CHECK_HEADER(alloca.h, glib_have_alloca_h=yes, glib_have_alloca_h=no) # Check for some functions AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp poll) @@ -866,6 +873,7 @@ _______EOF cat >>$outfile <<_______EOF $glib_atexit $glib_memmove +$glib_alloca $glib_defines $glib_vacopy @@ -1129,6 +1137,45 @@ if test x$glib_working_wctype = xno; then #define G_HAVE_BROKEN_WCTYPE 1" fi +if test x$glib_have_alloca = xyes; then + glib_alloca=" + +/* alloca support */" + + if test x$glib_have_alloca_h = xyes; then + glib_alloca="\$glib_alloca +#define G_HAVE_ALLOCA_H 1" + fi + + glib_alloca="\$glib_alloca +#define G_HAVE_ALLOCA 1 + +/* BEGIN autoconf 2.13 alloca incantation + NOTE: Do not un-indent the #pragma below. */ +/* AIX requires this to be the first thing in the file. */ +#ifdef __GNUC__ +# ifndef alloca +# define alloca __builtin_alloca +# endif +#else +# if G_HAVE_ALLOCA_H +# include +# else +# ifdef _AIX + #pragma alloca +# else +# ifndef alloca /* predefined by HP cc +Olibcalls */ +char *alloca (); +# endif +# endif +# endif +#endif +/* END autoconf 2.13 alloca incantation */ + + +" +fi + case x$enable_threads in xyes) g_enable_threads_def="#define";; *) g_enable_threads_def="#undef ";; diff --git a/glib.h b/glib.h index b6d178a28..3e91c9ba3 100644 --- a/glib.h +++ b/glib.h @@ -1455,6 +1455,37 @@ gchar* g_strescape (gchar *string); gpointer g_memdup (gconstpointer mem, guint byte_size); +/* Macros for dynamic strings via fast stack allocation + * All macros take a special first argument: the target gchar* string + */ +#if G_HAVE_ALLOCA + +# define g_strdup_a(newstr,str) G_STMT_START { \ + const char *__old = (str); \ + char *__new; \ + size_t __len = strlen (__old) + 1; \ + __new = alloca (__len); \ + memcpy (__new, __old, __len); \ + (newstr) = __new; \ + } G_STMT_END + +# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \ + size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \ + size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \ + size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \ + char *__sptr, *__new = \ + alloca (__len1 + __len2 + __len3 + 1); \ + __sptr = __new; \ + if (__len1){memcpy (__sptr, (str1), __len1); __sptr += __len1;} \ + if (__len2){memcpy (__sptr, (str2), __len2); __sptr += __len2;} \ + if (__len3){memcpy (__sptr, (str3), __len3); __sptr += __len3;} \ + *__sptr = '\0'; \ + (newstr) = __new; \ + } G_STMT_END + +#endif /* G_HAVE_ALLOCA */ + + /* NULL terminated string arrays. * g_strsplit() splits up string into max_tokens tokens at delim and * returns a newly allocated string array. diff --git a/glib/glib.h b/glib/glib.h index b6d178a28..3e91c9ba3 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -1455,6 +1455,37 @@ gchar* g_strescape (gchar *string); gpointer g_memdup (gconstpointer mem, guint byte_size); +/* Macros for dynamic strings via fast stack allocation + * All macros take a special first argument: the target gchar* string + */ +#if G_HAVE_ALLOCA + +# define g_strdup_a(newstr,str) G_STMT_START { \ + const char *__old = (str); \ + char *__new; \ + size_t __len = strlen (__old) + 1; \ + __new = alloca (__len); \ + memcpy (__new, __old, __len); \ + (newstr) = __new; \ + } G_STMT_END + +# define g_strconcat_a(newstr,str1,str2,str3) G_STMT_START { \ + size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \ + size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \ + size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \ + char *__sptr, *__new = \ + alloca (__len1 + __len2 + __len3 + 1); \ + __sptr = __new; \ + if (__len1){memcpy (__sptr, (str1), __len1); __sptr += __len1;} \ + if (__len2){memcpy (__sptr, (str2), __len2); __sptr += __len2;} \ + if (__len3){memcpy (__sptr, (str3), __len3); __sptr += __len3;} \ + *__sptr = '\0'; \ + (newstr) = __new; \ + } G_STMT_END + +#endif /* G_HAVE_ALLOCA */ + + /* NULL terminated string arrays. * g_strsplit() splits up string into max_tokens tokens at delim and * returns a newly allocated string array.