changeset 20165:506f0f7f4f21

Another fabulous patch to our Tcl loader from venks on irc.freenode.net. This one makes the 'handle' commands 64-bit safe, by moving away from Tcl integer objects, and using PurpleTclRefs instead.
author Ethan Blanton <elb@pidgin.im>
date Wed, 19 Sep 2007 02:33:08 +0000
parents 7d9391b94b1c
children 3287445c05a8
files libpurple/plugins/tcl/tcl.c libpurple/plugins/tcl/tcl_cmds.c libpurple/plugins/tcl/tcl_purple.h
diffstat 3 files changed, 25 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/plugins/tcl/tcl.c	Wed Sep 19 01:04:39 2007 +0000
+++ b/libpurple/plugins/tcl/tcl.c	Wed Sep 19 02:33:08 2007 +0000
@@ -60,6 +60,7 @@
 PurpleStringref *PurpleTclRefStatusAttr;
 PurpleStringref *PurpleTclRefStatusType;
 PurpleStringref *PurpleTclRefXfer;
+PurpleStringref *PurpleTclRefHandle;
 
 static GHashTable *tcl_plugins = NULL;
 
@@ -363,6 +364,7 @@
 	PurpleTclRefStatusAttr = purple_stringref_new("StatusAttr");
 	PurpleTclRefStatusType = purple_stringref_new("StatusType");
 	PurpleTclRefXfer = purple_stringref_new("Xfer");
+	PurpleTclRefHandle = purple_stringref_new("Handle");
 
 	tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal);
 
--- a/libpurple/plugins/tcl/tcl_cmds.c	Wed Sep 19 01:04:39 2007 +0000
+++ b/libpurple/plugins/tcl/tcl_cmds.c	Wed Sep 19 02:33:08 2007 +0000
@@ -207,7 +207,9 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "");
 			return TCL_ERROR;
 		}
-		Tcl_SetIntObj(result, (int)purple_accounts_get_handle());
+		Tcl_SetObjResult(interp, 
+				 purple_tcl_ref_new(PurpleTclRefHandle,
+						    purple_accounts_get_handle()));
 		break;
 	case CMD_ACCOUNT_ISCONNECTED:
 		if (objc != 3) {
@@ -443,7 +445,9 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "");
 			return TCL_ERROR;
 		}
-		Tcl_SetIntObj(result, (int)purple_blist_get_handle());
+		Tcl_SetObjResult(interp,
+				 purple_tcl_ref_new(PurpleTclRefHandle,
+						    purple_blist_get_handle()));
 		break;
 	case CMD_BUDDY_INFO:
 		if (objc != 3 && objc != 4) {
@@ -704,7 +708,8 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "");
 			return TCL_ERROR;
 		}
-		Tcl_SetIntObj(result, (int)purple_connections_get_handle());
+		Tcl_SetObjResult(interp, purple_tcl_ref_new(PurpleTclRefHandle,
+							    purple_connections_get_handle()));
 		break;
 	case CMD_CONN_LIST:
 		if (objc != 2) {
@@ -766,7 +771,9 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "");
 			return TCL_ERROR;
 		}
-		Tcl_SetIntObj(result, (int)purple_conversations_get_handle());
+		Tcl_SetObjResult(interp,
+		                 purple_tcl_ref_new(PurpleTclRefHandle,
+						    purple_conversations_get_handle()));
 		break;
 	case CMD_CONV_LIST:
 		list = Tcl_NewListObj(0, NULL);
@@ -879,7 +886,6 @@
 
 int tcl_cmd_core(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	Tcl_Obj *result = Tcl_GetObjResult(interp);
 	const char *cmds[] = { "handle", "quit", NULL };
 	enum { CMD_CORE_HANDLE, CMD_CORE_QUIT } cmd;
 	int error;
@@ -898,7 +904,9 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "");
 			return TCL_ERROR;
 		}
-		Tcl_SetIntObj(result, (int)purple_get_core());
+		Tcl_SetObjResult(interp,
+                                 purple_tcl_ref_new(PurpleTclRefHandle,
+						    purple_get_core()));
 		break;
 	case CMD_CORE_QUIT:
 		if (objc != 2) {
@@ -970,7 +978,6 @@
 
 int tcl_cmd_plugins(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	Tcl_Obj *result = Tcl_GetObjResult(interp);
 	const char *cmds[] = { "handle", NULL };
 	enum { CMD_PLUGINS_HANDLE } cmd;
 	int error;
@@ -989,7 +996,9 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "");
 			return TCL_ERROR;
 		}
-		Tcl_SetIntObj(result, (int)purple_plugins_get_handle());
+		Tcl_SetObjResult(interp,
+				purple_tcl_ref_new(PurpleTclRefHandle,
+						   purple_plugins_get_handle()));
 		break;
 	}
 
@@ -1363,7 +1372,9 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "");
 			return TCL_ERROR;
 		}
-		Tcl_SetIntObj(result, (int)purple_savedstatuses_get_handle());
+		Tcl_SetObjResult(interp, 
+				 purple_tcl_ref_new(PurpleTclRefHandle,
+						    purple_savedstatuses_get_handle()));
 		break;
 	}
 
@@ -1415,7 +1426,7 @@
 			return TCL_ERROR;
 		}
 		handler = g_new0(struct tcl_signal_handler, 1);
-		if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&handler->instance)) != TCL_OK) {
+		if ((handler->instance = purple_tcl_ref_get(interp, objv[2],PurpleTclRefHandle)) == NULL) {
 			g_free(handler);
 			return error;
 		}
@@ -1436,7 +1447,7 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "instance signal");
 			return TCL_ERROR;
 		}
-		if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&instance)) != TCL_OK)
+		if ((instance = purple_tcl_ref_get(interp, objv[2],PurpleTclRefHandle)) == NULL)
 			return error;
 		tcl_signal_disconnect(instance, Tcl_GetString(objv[3]), interp);
 		break;
--- a/libpurple/plugins/tcl/tcl_purple.h	Wed Sep 19 01:04:39 2007 +0000
+++ b/libpurple/plugins/tcl/tcl_purple.h	Wed Sep 19 02:33:08 2007 +0000
@@ -76,6 +76,7 @@
 extern PurpleStringref *PurpleTclRefStatusAttr;
 extern PurpleStringref *PurpleTclRefStatusType;
 extern PurpleStringref *PurpleTclRefXfer;
+extern PurpleStringref *PurpleTclRefHandle;
 
 PurplePlugin *tcl_interp_get_plugin(Tcl_Interp *interp);