/soc/2012/michael/android: 7aab64740ac4: Cleaned buddy code a bit.

Michael Zangl michael at soc.pidgin.im
Thu Aug 16 21:54:06 EDT 2012


Changeset: 7aab64740ac4b4bc1289b79c005d3ab068dccb9d
Author:	 Michael Zangl <michael at soc.pidgin.im>
Date:	 2012-08-17 02:28 +0200
Branch:	 soc.2012.android
URL: http://hg.pidgin.im/soc/2012/michael/android/rev/7aab64740ac4

Description:

Cleaned buddy code a bit.

diffstat:

 android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c |  34 +++++++++----
 1 files changed, 24 insertions(+), 10 deletions(-)

diffs (94 lines):

diff --git a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
--- a/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
+++ b/android/workspace/im.pidgin.libpurple/native/PurpleBuddy.c
@@ -16,7 +16,9 @@ getNativeBuddy(JNIEnv *env, jobject obj)
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_getName_1native(JNIEnv *env,
 		jobject obj)
 {
-	const char* name = purple_buddy_get_name(getNativeBuddy(env, obj));
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, NULL);
+	const char* name = purple_buddy_get_name(buddy_native);
 	return (*env)->NewStringUTF(env, name);
 }
 
@@ -28,7 +30,9 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_getAlias_1native(JNIEnv *env,
 		jobject obj)
 {
-	const char* alias = purple_buddy_get_alias(getNativeBuddy(env, obj));
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, NULL);
+	const char* alias = purple_buddy_get_alias(buddy_native);
 	return (*env)->NewStringUTF(env, alias);
 }
 
@@ -40,10 +44,12 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_setAlias_1native(JNIEnv *env,
 		jobject obj, jstring alias)
 {
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_if_fail(buddy_native != NULL);
 	const char* alias_native;
 	alias_native = (*env)->GetStringUTFChars(env, alias, NULL);
 	g_return_if_fail(alias_native != NULL);
-	purple_blist_alias_buddy(getNativeBuddy(env, obj), alias_native);
+	purple_blist_alias_buddy(buddy_native, alias_native);
 	(*env)->ReleaseStringUTFChars(env, alias, alias_native);
 }
 
@@ -55,8 +61,9 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_getServerAlias_1native(JNIEnv *env,
 		jobject obj)
 {
-	const char* server_alias = purple_buddy_get_server_alias(
-			getNativeBuddy(env, obj));
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, NULL);
+	const char* server_alias = purple_buddy_get_server_alias(buddy_native);
 	return (*env)->NewStringUTF(env, server_alias);
 }
 
@@ -68,8 +75,9 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_getDisplayName_1native(JNIEnv *env,
 		jobject obj)
 {
-	const char* contact_alias = purple_buddy_get_contact_alias(
-			getNativeBuddy(env, obj));
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, NULL);
+	const char* contact_alias = purple_buddy_get_contact_alias(buddy_native);
 	return (*env)->NewStringUTF(env, contact_alias);
 }
 
@@ -81,7 +89,9 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_getAccount_1native(JNIEnv *env,
 		jobject obj)
 {
-	return pToLong(purple_buddy_get_account(getNativeBuddy(env, obj)));
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, 0);
+	return pToLong(purple_buddy_get_account(buddy_native));
 }
 
 /*
@@ -92,7 +102,9 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_isOnline_1native(JNIEnv *env,
 		jobject obj)
 {
-	return PURPLE_BUDDY_IS_ONLINE(getNativeBuddy(env, obj));
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, FALSE);
+	return PURPLE_BUDDY_IS_ONLINE(buddy_native);
 }
 
 /*
@@ -103,5 +115,7 @@ Java_im_pidgin_libpurple_buddy_PurpleBud
 Java_im_pidgin_libpurple_buddy_PurpleBuddy_getContact_1native(JNIEnv *env,
 		jobject obj)
 {
-	return pToLong(purple_buddy_get_contact(getNativeBuddy(env, obj)));
+	PurpleBuddy *buddy_native = getNativeBuddy(env, obj);
+	g_return_val_if_fail(buddy_native != NULL, 0);
+	return pToLong(purple_buddy_get_contact(buddy_native));
 }



More information about the Commits mailing list