adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros so their

Mon Jan  4 14:38:11 1999  Tim Janik  <timj@gtk.org>

        * glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
        so their arguments get only evaluated once. changed g_strconcat3_a to
        have the same semantics as g_strconcat, i.e. if a certain argument is
        NULL, the rest of the parameter list is skipped.

        * tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
        able to compile on all systems. added test for g_strconcat() semantics.

        * we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
This commit is contained in:
Tim Janik 1999-01-04 13:49:05 +00:00 committed by Tim Janik
parent 887c4449d9
commit 72b139a74d
11 changed files with 195 additions and 67 deletions

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

View File

@ -1,3 +1,15 @@
Mon Jan 4 14:38:11 1999 Tim Janik <timj@gtk.org>
* glib.h: adjusted the g_strdup_a, g_strndup_a and g_strconcat3_a macros
so their arguments get only evaluated once. changed g_strconcat3_a to
have the same semantics as g_strconcat, i.e. if a certain argument is
NULL, the rest of the parameter list is skipped.
* tests/alloca-test.c: removed #if/#endif G_HAVE_ALLOCA, we need to be
able to compile on all systems. added test for g_strconcat() semantics.
* we need a alloca() replacement for !G_HAVE_ALLOCA rsn!
Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org> Mon Jan 4 02:58:13 CST 1999 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.12 * Released GLib 1.1.12

73
glib.h
View File

@ -309,7 +309,7 @@ extern "C" {
# define g_new0_a(type, count) \ # define g_new0_a(type, count) \
((type *) memset (alloca ((unsigned) sizeof (type) * (count)), 0, \ ((type *) memset (alloca ((unsigned) sizeof (type) * (count)), 0, \
((unsigned) sizeof (type) * (count)))) ((unsigned) sizeof (type) * (count))))
#endif #endif /* G_HAVE_ALLOCA */
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \ #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \ g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
@ -1469,47 +1469,64 @@ gpointer g_memdup (gconstpointer mem,
* All macros take a special first argument: the target gchar* string * All macros take a special first argument: the target gchar* string
*/ */
#if G_HAVE_ALLOCA #if G_HAVE_ALLOCA
# define g_strdup_a(newstr,str) G_STMT_START { \ # define g_strdup_a(newstr,str) G_STMT_START { \
if ((str) == NULL) (newstr) = NULL; \ gchar *__new; \
else { \ const gchar *__old = (str); \
const char *__old = (str); \ if (__old) \
char *__new; \ { \
size_t __len = strlen (__old) + 1; \ size_t __len = strlen (__old) + 1; \
__new = alloca (__len); \ __new = alloca (__len); \
memcpy (__new, __old, __len); \ memcpy (__new, __old, __len); \
(newstr) = __new; \
} \ } \
else \
__new = NULL; \
(newstr) = __new; \
} G_STMT_END } G_STMT_END
# define g_strndup_a(newstr,str,n) G_STMT_START { \ # define g_strndup_a(newstr,str,n) G_STMT_START { \
if ((str) == NULL) (newstr) = NULL; \ gchar *__new; \
else { \ const gchar *__old = (str); \
const char *__old = (str); \ if (__old) \
char *__new; \ { \
guint __n = (n); \
size_t __len = strlen (__old); \ size_t __len = strlen (__old); \
if (__len > (n)) __len = (n); \ if (__len > (__n)) \
__len = (__n); \
__new = alloca (__len + 1); \ __new = alloca (__len + 1); \
memcpy (__new, __old, __len); \ memcpy (__new, __old, __len); \
__new[__len] = 0; \ __new[__len] = 0; \
(newstr) = __new; \
} \ } \
} G_STMT_END else \
__new = NULL; \
# define g_strconcat3_a(newstr,str1,str2,str3) G_STMT_START { \ (newstr) = __new; \
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \ } G_STMT_END
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \ # define g_strconcat3_a(newstr,str1,str2,str3) G_STMT_START { \
size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \ const gchar *__str1 = (str1); \
char *__sptr, *__new = \ const gchar *__str2 = (str2); \
alloca (__len1 + __len2 + __len3 + 1); \ const gchar *__str3 = (str3); \
__sptr = __new; \ gchar *__new; \
if (__len1){memcpy (__sptr, (str1), __len1); __sptr += __len1;} \ if (__str1) { \
if (__len2){memcpy (__sptr, (str2), __len2); __sptr += __len2;} \ size_t __len1 = strlen (__str1); \
if (__len3){memcpy (__sptr, (str3), __len3); __sptr += __len3;} \ if (__str2) { \
*__sptr = '\0'; \ size_t __len2 = strlen (__str2); \
if (__str3) { \
size_t __len3 = strlen (__str3); \
__new = alloca (__len1 + __len2 + __len3 + 1); \
__new[__len1 + __len2 + __len3] = 0; \
memcpy (__new + __len1 + __len2, __str3, __len3); \
} else { \
__new = alloca (__len1 + __len2 + 1); \
__new[__len1 + __len2] = 0; \
} \
memcpy (__new + __len1, __str2, __len2); \
} else { \
__new = alloca (__len1 + 1); \
__new[__len1] = 0; \
} \
memcpy (__new, __str1, __len1); \
} else \
__new = NULL; \
(newstr) = __new; \ (newstr) = __new; \
} G_STMT_END } G_STMT_END
#endif /* G_HAVE_ALLOCA */ #endif /* G_HAVE_ALLOCA */

View File

@ -309,7 +309,7 @@ extern "C" {
# define g_new0_a(type, count) \ # define g_new0_a(type, count) \
((type *) memset (alloca ((unsigned) sizeof (type) * (count)), 0, \ ((type *) memset (alloca ((unsigned) sizeof (type) * (count)), 0, \
((unsigned) sizeof (type) * (count)))) ((unsigned) sizeof (type) * (count))))
#endif #endif /* G_HAVE_ALLOCA */
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \ #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \ g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
@ -1469,47 +1469,64 @@ gpointer g_memdup (gconstpointer mem,
* All macros take a special first argument: the target gchar* string * All macros take a special first argument: the target gchar* string
*/ */
#if G_HAVE_ALLOCA #if G_HAVE_ALLOCA
# define g_strdup_a(newstr,str) G_STMT_START { \ # define g_strdup_a(newstr,str) G_STMT_START { \
if ((str) == NULL) (newstr) = NULL; \ gchar *__new; \
else { \ const gchar *__old = (str); \
const char *__old = (str); \ if (__old) \
char *__new; \ { \
size_t __len = strlen (__old) + 1; \ size_t __len = strlen (__old) + 1; \
__new = alloca (__len); \ __new = alloca (__len); \
memcpy (__new, __old, __len); \ memcpy (__new, __old, __len); \
(newstr) = __new; \
} \ } \
else \
__new = NULL; \
(newstr) = __new; \
} G_STMT_END } G_STMT_END
# define g_strndup_a(newstr,str,n) G_STMT_START { \ # define g_strndup_a(newstr,str,n) G_STMT_START { \
if ((str) == NULL) (newstr) = NULL; \ gchar *__new; \
else { \ const gchar *__old = (str); \
const char *__old = (str); \ if (__old) \
char *__new; \ { \
guint __n = (n); \
size_t __len = strlen (__old); \ size_t __len = strlen (__old); \
if (__len > (n)) __len = (n); \ if (__len > (__n)) \
__len = (__n); \
__new = alloca (__len + 1); \ __new = alloca (__len + 1); \
memcpy (__new, __old, __len); \ memcpy (__new, __old, __len); \
__new[__len] = 0; \ __new[__len] = 0; \
(newstr) = __new; \
} \ } \
} G_STMT_END else \
__new = NULL; \
# define g_strconcat3_a(newstr,str1,str2,str3) G_STMT_START { \ (newstr) = __new; \
size_t __len1 = ((str1) == (gchar*)NULL) ? 0 : strlen((str1)); \ } G_STMT_END
size_t __len2 = ((str2) == (gchar*)NULL) ? 0 : strlen((str2)); \ # define g_strconcat3_a(newstr,str1,str2,str3) G_STMT_START { \
size_t __len3 = ((str3) == (gchar*)NULL) ? 0 : strlen((str3)); \ const gchar *__str1 = (str1); \
char *__sptr, *__new = \ const gchar *__str2 = (str2); \
alloca (__len1 + __len2 + __len3 + 1); \ const gchar *__str3 = (str3); \
__sptr = __new; \ gchar *__new; \
if (__len1){memcpy (__sptr, (str1), __len1); __sptr += __len1;} \ if (__str1) { \
if (__len2){memcpy (__sptr, (str2), __len2); __sptr += __len2;} \ size_t __len1 = strlen (__str1); \
if (__len3){memcpy (__sptr, (str3), __len3); __sptr += __len3;} \ if (__str2) { \
*__sptr = '\0'; \ size_t __len2 = strlen (__str2); \
if (__str3) { \
size_t __len3 = strlen (__str3); \
__new = alloca (__len1 + __len2 + __len3 + 1); \
__new[__len1 + __len2 + __len3] = 0; \
memcpy (__new + __len1 + __len2, __str3, __len3); \
} else { \
__new = alloca (__len1 + __len2 + 1); \
__new[__len1 + __len2] = 0; \
} \
memcpy (__new + __len1, __str2, __len2); \
} else { \
__new = alloca (__len1 + 1); \
__new[__len1] = 0; \
} \
memcpy (__new, __str1, __len1); \
} else \
__new = NULL; \
(newstr) = __new; \ (newstr) = __new; \
} G_STMT_END } G_STMT_END
#endif /* G_HAVE_ALLOCA */ #endif /* G_HAVE_ALLOCA */

View File

@ -34,7 +34,6 @@ int
main (int argc, main (int argc,
char *argv[]) char *argv[])
{ {
#ifdef G_HAVE_ALLOCA
gchar *string; gchar *string;
GlibTestInfo *gti; GlibTestInfo *gti;
gint i, j; gint i, j;
@ -80,10 +79,9 @@ main (int argc,
g_assert(string != NULL); g_assert(string != NULL);
g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING g_assert(strcmp(string, GLIB_TEST_STRING GLIB_TEST_STRING
GLIB_TEST_STRING) == 0); GLIB_TEST_STRING) == 0);
g_strconcat3_a (string, "1", NULL, "2");
g_assert (strcmp (string, "1") == 0);
#else
exit(77); /* tell automake test was skipped */
#endif
return 0; return 0;
} }