changeset 29018:6288bbd53f44

Pass around a va_list instead of a pointer to a va_list. Refs #7404 This gets rid of a compile warning for me on x86_64. I don't have an i386 box to test on, but every bit of evidence I can find tells me that it's totally fine to pass around a va_list. We do it in status.c If this breaks compilation for you or you get a warning from perl-handlers.c then pleaes let me know! Or just disapprove this
author Mark Doliner <mark@kingant.net>
date Wed, 10 Feb 2010 09:04:15 +0000
parents f521dd7c75b5
children 64bee7ae306f 1e89206ed1ae 1e4781fb144b
files configure.ac libpurple/plugins/perl/perl-common.c libpurple/plugins/perl/perl-common.h libpurple/plugins/perl/perl-handlers.c
diffstat 4 files changed, 24 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Wed Feb 10 07:09:52 2010 +0000
+++ b/configure.ac	Wed Feb 10 09:04:15 2010 +0000
@@ -2393,30 +2393,6 @@
         AC_DEFINE(HAVE_TM_GMTOFF, 1, [Define if you have a tm_gmtoff member in struct tm])
 fi
 
-AC_CACHE_CHECK([whether va_lists can be copied by value], ac_cv_va_val_copy,[
-	AC_TRY_RUN([#include <stdarg.h>
-#include <stdlib.h>
-	void f (int i, ...) {
-	va_list args1, args2;
-	va_start (args1, i);
-	args2 = args1;
-	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
-	  exit (1);
-	va_end (args1); va_end (args2);
-	}
-	int main() {
-	  f (0, 42);
-	  return 0;
-	}],
-	[ac_cv_va_val_copy=yes],
-	[ac_cv_va_val_copy=no],
-	[ac_cv_va_val_copy=yes])
-])
-
-if test "x$ac_cv_va_val_copy" = "xno"; then
-	AC_DEFINE(VA_COPY_AS_ARRAY, 1, ['va_lists' cannot be copied as values])
-fi
-
 dnl #######################################################################
 dnl # Check for check
 dnl #######################################################################
--- a/libpurple/plugins/perl/perl-common.c	Wed Feb 10 07:09:52 2010 +0000
+++ b/libpurple/plugins/perl/perl-common.c	Wed Feb 10 09:04:15 2010 +0000
@@ -472,74 +472,74 @@
 }
 
 SV *
-purple_perl_sv_from_vargs(const PurpleValue *value, va_list *args, void ***copy_arg)
+purple_perl_sv_from_vargs(const PurpleValue *value, va_list args, void ***copy_arg)
 {
 	if (purple_value_is_outgoing(value)) {
 		switch (purple_value_get_type(value)) {
 			case PURPLE_TYPE_SUBTYPE:
-				if ((*copy_arg = va_arg(*args, void **)) == NULL)
+				if ((*copy_arg = va_arg(args, void **)) == NULL)
 					return &PL_sv_undef;
 
 				return purple_perl_sv_from_subtype(value, *(void **)*copy_arg);
 
 			case PURPLE_TYPE_BOOLEAN:
-				if ((*copy_arg = (void *)va_arg(*args, gboolean *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, gboolean *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSViv(*(gboolean *)*copy_arg);
 
 			case PURPLE_TYPE_INT:
-				if ((*copy_arg = (void *)va_arg(*args, int *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, int *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSViv(*(int *)*copy_arg);
 
 			case PURPLE_TYPE_UINT:
-				if ((*copy_arg = (void *)va_arg(*args, unsigned int *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, unsigned int *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSVuv(*(unsigned int *)*copy_arg);
 
 			case PURPLE_TYPE_LONG:
-				if ((*copy_arg = (void *)va_arg(*args, long *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, long *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSViv(*(long *)*copy_arg);
 
 			case PURPLE_TYPE_ULONG:
-				if ((*copy_arg = (void *)va_arg(*args,
+				if ((*copy_arg = (void *)va_arg(args,
 												unsigned long *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSVuv(*(unsigned long *)*copy_arg);
 
 			case PURPLE_TYPE_INT64:
-				if ((*copy_arg = (void *)va_arg(*args, gint64 *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, gint64 *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSViv(*(gint64 *)*copy_arg);
 
 			case PURPLE_TYPE_UINT64:
-				if ((*copy_arg = (void *)va_arg(*args, guint64 *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, guint64 *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSVuv(*(guint64 *)*copy_arg);
 
 			case PURPLE_TYPE_STRING:
-				if ((*copy_arg = (void *)va_arg(*args, char **)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, char **)) == NULL)
 					return &PL_sv_undef;
 
 				return newSVGChar(*(char **)*copy_arg);
 
 			case PURPLE_TYPE_POINTER:
-				if ((*copy_arg = va_arg(*args, void **)) == NULL)
+				if ((*copy_arg = va_arg(args, void **)) == NULL)
 					return &PL_sv_undef;
 
 				return newSViv((IV)*(void **)*copy_arg);
 
 			case PURPLE_TYPE_BOXED:
 				/* Uh.. I dunno. Try this? */
-				if ((*copy_arg = va_arg(*args, void **)) == NULL)
+				if ((*copy_arg = va_arg(args, void **)) == NULL)
 					return &PL_sv_undef;
 
 				return sv_2mortal(purple_perl_bless_object(
@@ -553,40 +553,40 @@
 	} else {
 		switch (purple_value_get_type(value)) {
 			case PURPLE_TYPE_SUBTYPE:
-				if ((*copy_arg = va_arg(*args, void *)) == NULL)
+				if ((*copy_arg = va_arg(args, void *)) == NULL)
 					return &PL_sv_undef;
 
 				return purple_perl_sv_from_subtype(value, *copy_arg);
 
 			case PURPLE_TYPE_BOOLEAN:
-				*copy_arg = GINT_TO_POINTER( va_arg(*args, gboolean) );
+				*copy_arg = GINT_TO_POINTER( va_arg(args, gboolean) );
 
 				return newSViv((gboolean)GPOINTER_TO_INT(*copy_arg));
 
 			case PURPLE_TYPE_INT:
-				*copy_arg = GINT_TO_POINTER( va_arg(*args, int) );
+				*copy_arg = GINT_TO_POINTER( va_arg(args, int) );
 
 				return newSViv(GPOINTER_TO_INT(*copy_arg));
 
 			case PURPLE_TYPE_UINT:
-				*copy_arg = GUINT_TO_POINTER(va_arg(*args, unsigned int));
+				*copy_arg = GUINT_TO_POINTER(va_arg(args, unsigned int));
 
 				return newSVuv(GPOINTER_TO_UINT(*copy_arg));
 
 			case PURPLE_TYPE_LONG:
-				*copy_arg = (void *)va_arg(*args, long);
+				*copy_arg = (void *)va_arg(args, long);
 
 				return newSViv((long)*copy_arg);
 
 			case PURPLE_TYPE_ULONG:
-				*copy_arg = (void *)va_arg(*args, unsigned long);
+				*copy_arg = (void *)va_arg(args, unsigned long);
 
 				return newSVuv((unsigned long)*copy_arg);
 
 			case PURPLE_TYPE_INT64:
 #if 0
 				/* XXX This yells and complains. */
-				*copy_arg = va_arg(*args, gint64);
+				*copy_arg = va_arg(args, gint64);
 
 				return newSViv(*copy_arg);
 #endif
@@ -595,27 +595,27 @@
 			case PURPLE_TYPE_UINT64:
 				/* XXX This also yells and complains. */
 #if 0
-				*copy_arg = (void *)va_arg(*args, guint64);
+				*copy_arg = (void *)va_arg(args, guint64);
 
 				return newSVuv(*copy_arg);
 #endif
 				break;
 
 			case PURPLE_TYPE_STRING:
-				if ((*copy_arg = (void *)va_arg(*args, char *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, char *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSVGChar((char *)*copy_arg);
 
 			case PURPLE_TYPE_POINTER:
-				if ((*copy_arg = (void *)va_arg(*args, void *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, void *)) == NULL)
 					return &PL_sv_undef;
 
 				return newSViv((IV)*copy_arg);
 
 			case PURPLE_TYPE_BOXED:
 				/* Uh.. I dunno. Try this? */
-				if ((*copy_arg = (void *)va_arg(*args, void *)) == NULL)
+				if ((*copy_arg = (void *)va_arg(args, void *)) == NULL)
 					return &PL_sv_undef;
 
 				return sv_2mortal(purple_perl_bless_object(*copy_arg,
--- a/libpurple/plugins/perl/perl-common.h	Wed Feb 10 07:09:52 2010 +0000
+++ b/libpurple/plugins/perl/perl-common.h	Wed Feb 10 09:04:15 2010 +0000
@@ -65,7 +65,7 @@
 #endif
 
 void *purple_perl_data_from_sv(PurpleValue *value, SV *sv);
-SV *purple_perl_sv_from_vargs(const PurpleValue *value, va_list *args,
+SV *purple_perl_sv_from_vargs(const PurpleValue *value, va_list args,
                             void ***copy_arg);
 SV *purple_perl_sv_from_fun(PurplePlugin *plugin, SV *callback);
 #endif /* _PURPLE_PERL_COMMON_H_ */
--- a/libpurple/plugins/perl/perl-handlers.c	Wed Feb 10 07:09:52 2010 +0000
+++ b/libpurple/plugins/perl/perl-handlers.c	Wed Feb 10 09:04:15 2010 +0000
@@ -298,11 +298,7 @@
 
 	for (i = 0; i < value_count; i++) {
 		sv_args[i] = purple_perl_sv_from_vargs(values[i],
-#ifdef VA_COPY_AS_ARRAY
 		                                       args,
-#else
-		                                       (va_list*)&args,
-#endif
 		                                       &copy_args[i]);
 
 		XPUSHs(sv_args[i]);