/pidgin/main: 65d585472765: Fix perl warnings or break the build

Tomasz Wasilczyk twasilczyk at pidgin.im
Wed Apr 30 16:42:29 EDT 2014


Changeset: 65d585472765ffc66d36579acf83d763337bb1e2
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-30 22:42 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/65d585472765

Description:

Fix perl warnings or break the build

diffstat:

 libpurple/internal.h                 |   6 ++++++
 libpurple/plugins/perl/perl-common.c |  23 +++++++++++++----------
 2 files changed, 19 insertions(+), 10 deletions(-)

diffs (64 lines):

diff --git a/libpurple/internal.h b/libpurple/internal.h
--- a/libpurple/internal.h
+++ b/libpurple/internal.h
@@ -144,6 +144,12 @@
 #endif
 #endif
 
+#define PURPLE_STATIC_ASSERT(condition, message) \
+	{ typedef char static_assertion_failed_ ## message \
+	[(condition) ? 1 : -1]; static_assertion_failed_ ## message dummy; \
+	(void)dummy; }
+
+
 #ifdef __clang__
 
 #define PURPLE_BEGIN_IGNORE_CAST_ALIGN \
diff --git a/libpurple/plugins/perl/perl-common.c b/libpurple/plugins/perl/perl-common.c
--- a/libpurple/plugins/perl/perl-common.c
+++ b/libpurple/plugins/perl/perl-common.c
@@ -44,7 +44,10 @@ create_sv_ptr(void *object)
 {
 	SV *sv;
 
-	sv = newSViv((IV)object);
+	PURPLE_STATIC_ASSERT(sizeof(IV) >= sizeof(void *),
+		sv_can_not_hold_a_pointer);
+
+	sv = newSViv((IV)(gintptr)object);
 
 	sv_magic(sv, NULL, '~', NULL, 0);
 
@@ -383,15 +386,15 @@ void *
 purple_perl_data_from_sv(GType type, SV *sv)
 {
 	switch (type) {
-		case G_TYPE_BOOLEAN: return (void *)SvIV(sv);
-		case G_TYPE_INT:     return (void *)SvIV(sv);
-		case G_TYPE_UINT:    return (void *)SvUV(sv);
-		case G_TYPE_LONG:    return (void *)SvIV(sv);
-		case G_TYPE_ULONG:   return (void *)SvUV(sv);
-		case G_TYPE_INT64:   return (void *)SvIV(sv);
-		case G_TYPE_UINT64:  return (void *)SvUV(sv);
+		case G_TYPE_BOOLEAN: return (void *)(gintptr)SvIV(sv);
+		case G_TYPE_INT:     return (void *)(gintptr)SvIV(sv);
+		case G_TYPE_UINT:    return (void *)(gintptr)SvUV(sv);
+		case G_TYPE_LONG:    return (void *)(gintptr)SvIV(sv);
+		case G_TYPE_ULONG:   return (void *)(gintptr)SvUV(sv);
+		case G_TYPE_INT64:   return (void *)(gintptr)SvIV(sv);
+		case G_TYPE_UINT64:  return (void *)(gintptr)SvUV(sv);
 		case G_TYPE_STRING:  return g_strdup(SvPVutf8_nolen(sv));
-		case G_TYPE_POINTER: return (void *)SvIV(sv);
+		case G_TYPE_POINTER: return (void *)(gintptr)SvIV(sv);
 	}
 
 	return NULL;
@@ -580,7 +583,7 @@ purple_perl_sv_from_vargs(GType type, va
 			if ((*copy_arg = (void *)va_arg(*args, void *)) == NULL)
 				return &PL_sv_undef;
 
-			return newSViv((IV)*copy_arg);
+			return newSViv((IV)(gintptr)*copy_arg);
 
 		default:
 			if ((*copy_arg = va_arg(*args, void *)) == NULL)



More information about the Commits mailing list