/soc/2013/ankitkv/gobjectification: 182a4df77539: Refactored tcl...
Ankit Vani
a at nevitus.org
Wed Jul 17 06:57:22 EDT 2013
Changeset: 182a4df775396bb1e09b50740c313cc0cf59f37c
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-17 16:27 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/182a4df77539
Description:
Refactored tcl plugins to use GType instead of PurpleValue.
Here, an assumption is made for purple_value_is_outgoing() to be FALSE.
diffstat:
libpurple/plugins/tcl/tcl_cmds.c | 12 +-
libpurple/plugins/tcl/tcl_purple.h | 4 +-
libpurple/plugins/tcl/tcl_signals.c | 151 +++++++++++++++++++----------------
3 files changed, 89 insertions(+), 78 deletions(-)
diffs (truncated from 322 to 300 lines):
diff --git a/libpurple/plugins/tcl/tcl_cmds.c b/libpurple/plugins/tcl/tcl_cmds.c
--- a/libpurple/plugins/tcl/tcl_cmds.c
+++ b/libpurple/plugins/tcl/tcl_cmds.c
@@ -118,7 +118,7 @@ int tcl_cmd_account(ClientData unused, T
PurpleAccount *account;
PurpleStatus *status;
PurpleStatusType *status_type;
- PurpleValue *value;
+ GValue *value;
char *attr_id;
int error;
int b, i;
@@ -292,27 +292,27 @@ int tcl_cmd_account(ClientData unused, T
Tcl_SetObjResult(interp, Tcl_NewStringObj("invalid attribute for account", -1));
return TCL_ERROR;
}
- switch (purple_value_get_type(value)) {
- case PURPLE_TYPE_BOOLEAN:
+ switch (G_VALUE_TYPE(value)) {
+ case G_TYPE_BOOLEAN:
error = Tcl_GetBooleanFromObj(interp, objv[i + 1], &b);
if (error != TCL_OK)
return error;
l = g_list_append(l, attr_id);
l = g_list_append(l, GINT_TO_POINTER(b));
break;
- case PURPLE_TYPE_INT:
+ case G_TYPE_INT:
error = Tcl_GetIntFromObj(interp, objv[i + 1], &b);
if (error != TCL_OK)
return error;
l = g_list_append(l, attr_id);
l = g_list_append(l, GINT_TO_POINTER(b));
break;
- case PURPLE_TYPE_STRING:
+ case G_TYPE_STRING:
l = g_list_append(l, attr_id);
l = g_list_append(l, Tcl_GetString(objv[i + 1]));
break;
default:
- Tcl_SetObjResult(interp, Tcl_NewStringObj("unknown PurpleValue type", -1));
+ Tcl_SetObjResult(interp, Tcl_NewStringObj("unknown GValue type", -1));
return TCL_ERROR;
}
}
diff --git a/libpurple/plugins/tcl/tcl_purple.h b/libpurple/plugins/tcl/tcl_purple.h
--- a/libpurple/plugins/tcl/tcl_purple.h
+++ b/libpurple/plugins/tcl/tcl_purple.h
@@ -40,9 +40,9 @@ struct tcl_signal_handler {
Tcl_Obj *args;
Tcl_Obj *proc;
- PurpleValue *returntype;
+ GType returntype;
int nargs;
- PurpleValue **argtypes;
+ GType *argtypes;
};
struct tcl_cmd_handler {
diff --git a/libpurple/plugins/tcl/tcl_signals.c b/libpurple/plugins/tcl/tcl_signals.c
--- a/libpurple/plugins/tcl/tcl_signals.c
+++ b/libpurple/plugins/tcl/tcl_signals.c
@@ -73,7 +73,7 @@ gboolean tcl_signal_connect(struct tcl_s
{
GString *proc;
- purple_signal_get_values(handler->instance,
+ purple_signal_get_types(handler->instance,
Tcl_GetString(handler->signal),
&handler->returntype, &handler->nargs,
&handler->argtypes);
@@ -135,24 +135,22 @@ void tcl_signal_disconnect(void *instanc
tcl_callbacks = g_list_remove_all(tcl_callbacks, NULL);
}
-static PurpleStringref *ref_type(PurpleSubType type)
+static PurpleStringref *ref_purple_type(GType type)
{
- switch (type) {
- case PURPLE_SUBTYPE_ACCOUNT:
+ if (type == PURPLE_TYPE_ACCOUNT)
return PurpleTclRefAccount;
- case PURPLE_SUBTYPE_CONNECTION:
+ else if (type == PURPLE_TYPE_CONNECTION)
return PurpleTclRefConnection;
- case PURPLE_SUBTYPE_CONVERSATION:
+ else if (type == PURPLE_TYPE_CONVERSATION)
return PurpleTclRefConversation;
- case PURPLE_SUBTYPE_PLUGIN:
+ else if (type == PURPLE_TYPE_PLUGIN)
return PurpleTclRefPlugin;
- case PURPLE_SUBTYPE_STATUS:
+ else if (type == PURPLE_TYPE_STATUS)
return PurpleTclRefStatus;
- case PURPLE_SUBTYPE_XFER:
+ else if (type == PURPLE_TYPE_XFER)
return PurpleTclRefXfer;
- default:
+ else
return NULL;
- }
}
static void *tcl_signal_callback(va_list args, struct tcl_signal_handler *handler)
@@ -178,58 +176,58 @@ static void *tcl_signal_callback(va_list
Tcl_ListObjAppendElement(handler->interp, cmd, arg);
for (i = 0; i < handler->nargs; i++) {
+#if 0
if (purple_value_is_outgoing(handler->argtypes[i]))
g_string_printf(name, "%s::arg%d",
Tcl_GetString(handler->namespace), i);
-
- switch(purple_value_get_type(handler->argtypes[i])) {
- case PURPLE_TYPE_UNKNOWN: /* What? I guess just pass the word ... */
- /* treat this as a pointer, but complain first */
- purple_debug(PURPLE_DEBUG_ERROR, "tcl", "unknown PurpleValue type %d\n",
- purple_value_get_type(handler->argtypes[i]));
- case PURPLE_TYPE_POINTER:
- case PURPLE_TYPE_OBJECT:
- case PURPLE_TYPE_BOXED:
+#endif
+ switch(handler->argtypes[i]) {
+ case G_TYPE_POINTER:
+#if 0
+ case G_TYPE_OBJECT:
+ case G_TYPE_BOXED:
/* These are all "pointer" types to us */
if (purple_value_is_outgoing(handler->argtypes[i]))
purple_debug_error("tcl", "pointer types do not currently support outgoing arguments\n");
+#endif
arg = purple_tcl_ref_new(PurpleTclRefPointer, va_arg(args, void *));
break;
- case PURPLE_TYPE_BOOLEAN:
+ case G_TYPE_BOOLEAN:
+#if 0
if (purple_value_is_outgoing(handler->argtypes[i])) {
vals[i] = va_arg(args, gboolean *);
Tcl_LinkVar(handler->interp, name->str,
(char *)&vals[i], TCL_LINK_BOOLEAN);
arg = Tcl_NewStringObj(name->str, -1);
- } else {
- arg = Tcl_NewBooleanObj(va_arg(args, gboolean));
- }
+ } else
+#endif
+ arg = Tcl_NewBooleanObj(va_arg(args, gboolean));
break;
- case PURPLE_TYPE_CHAR:
- case PURPLE_TYPE_UCHAR:
- case PURPLE_TYPE_SHORT:
- case PURPLE_TYPE_USHORT:
- case PURPLE_TYPE_INT:
- case PURPLE_TYPE_UINT:
- case PURPLE_TYPE_LONG:
- case PURPLE_TYPE_ULONG:
- case PURPLE_TYPE_ENUM:
+ case G_TYPE_CHAR:
+ case G_TYPE_UCHAR:
+ case G_TYPE_INT:
+ case G_TYPE_UINT:
+ case G_TYPE_LONG:
+ case G_TYPE_ULONG:
+ case G_TYPE_ENUM:
/* I should really cast these individually to
* preserve as much information as possible ...
* but heh */
+#if 0
if (purple_value_is_outgoing(handler->argtypes[i])) {
vals[i] = va_arg(args, int *);
Tcl_LinkVar(handler->interp, name->str,
vals[i], TCL_LINK_INT);
arg = Tcl_NewStringObj(name->str, -1);
- } else {
- arg = Tcl_NewIntObj(va_arg(args, int));
- }
+ } else
+#endif
+ arg = Tcl_NewIntObj(va_arg(args, int));
break;
- case PURPLE_TYPE_INT64:
- case PURPLE_TYPE_UINT64:
+ case G_TYPE_INT64:
+ case G_TYPE_UINT64:
/* Tcl < 8.4 doesn't have wide ints, so we have ugly
* ifdefs in here */
+#if 0
if (purple_value_is_outgoing(handler->argtypes[i])) {
vals[i] = (void *)va_arg(args, gint64 *);
#if (TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 4)
@@ -244,14 +242,15 @@ static void *tcl_signal_callback(va_list
#endif /* Tcl >= 8.4 */
arg = Tcl_NewStringObj(name->str, -1);
} else {
- #if (TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 4)
- arg = Tcl_NewWideIntObj(va_arg(args, gint64));
- #else
- arg = Tcl_NewIntObj((int)va_arg(args, int));
- #endif /* Tcl >= 8.4 */
- }
+#endif
+ #if (TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 4)
+ arg = Tcl_NewWideIntObj(va_arg(args, gint64));
+ #else
+ arg = Tcl_NewIntObj((int)va_arg(args, int));
+ #endif /* Tcl >= 8.4 */
break;
- case PURPLE_TYPE_STRING:
+ case G_TYPE_STRING:
+#if 0
if (purple_value_is_outgoing(handler->argtypes[i])) {
strs[i] = va_arg(args, char **);
if (strs[i] == NULL || *strs[i] == NULL) {
@@ -265,33 +264,37 @@ static void *tcl_signal_callback(va_list
Tcl_LinkVar(handler->interp, name->str,
(char *)&vals[i], TCL_LINK_STRING);
arg = Tcl_NewStringObj(name->str, -1);
- } else {
- arg = Tcl_NewStringObj(va_arg(args, char *), -1);
- }
+ } else
+#endif
+ arg = Tcl_NewStringObj(va_arg(args, char *), -1);
break;
- case PURPLE_TYPE_SUBTYPE:
- switch (purple_value_get_subtype(handler->argtypes[i])) {
- case PURPLE_SUBTYPE_UNKNOWN:
- purple_debug(PURPLE_DEBUG_ERROR, "tcl", "subtype unknown\n");
- case PURPLE_SUBTYPE_ACCOUNT:
- case PURPLE_SUBTYPE_CONNECTION:
- case PURPLE_SUBTYPE_CONVERSATION:
- case PURPLE_SUBTYPE_STATUS:
- case PURPLE_SUBTYPE_PLUGIN:
- case PURPLE_SUBTYPE_XFER:
+ default:
+ if (handler->argtypes[i] == PURPLE_TYPE_ACCOUNT ||
+ handler->argtypes[i] == PURPLE_TYPE_CONNECTION ||
+ handler->argtypes[i] == PURPLE_TYPE_CONVERSATION ||
+ handler->argtypes[i] == PURPLE_TYPE_STATUS ||
+ handler->argtypes[i] == PURPLE_TYPE_PLUGIN ||
+ handler->argtypes[i] == PURPLE_TYPE_XFER )
+ {
+#if 0
if (purple_value_is_outgoing(handler->argtypes[i]))
purple_debug_error("tcl", "pointer subtypes do not currently support outgoing arguments\n");
- arg = purple_tcl_ref_new(ref_type(purple_value_get_subtype(handler->argtypes[i])), va_arg(args, void *));
- break;
- case PURPLE_SUBTYPE_BLIST:
- case PURPLE_SUBTYPE_BLIST_BUDDY:
- case PURPLE_SUBTYPE_BLIST_GROUP:
- case PURPLE_SUBTYPE_BLIST_CHAT:
+#endif
+ arg = purple_tcl_ref_new(ref_purple_type(handler->argtypes[i]), va_arg(args, void *));
+ }
+ else
+ if (handler->argtypes[i] == PURPLE_TYPE_CONTACT ||
+ handler->argtypes[i] == PURPLE_TYPE_BUDDY ||
+ handler->argtypes[i] == PURPLE_TYPE_GROUP ||
+ handler->argtypes[i] == PURPLE_TYPE_CHAT )
+ {
/* We're going to switch again for code-deduping */
+#if 0
if (purple_value_is_outgoing(handler->argtypes[i]))
node = *va_arg(args, PurpleBListNode **);
else
- node = va_arg(args, PurpleBListNode *);
+#endif
+ node = va_arg(args, PurpleBListNode *);
if (PURPLE_IS_GROUP(node)) {
arg = Tcl_NewListObj(0, NULL);
@@ -322,6 +325,13 @@ static void *tcl_signal_callback(va_list
purple_chat_get_account(PURPLE_CHAT(node))));
}
}
+ else
+ {
+ /* What? I guess just pass the word ... */
+ /* treat this as a pointer, but complain first */
+ purple_debug(PURPLE_DEBUG_ERROR, "tcl", "unknown GType %lu\n",
+ handler->argtypes[i]);
+ }
}
Tcl_ListObjAppendElement(handler->interp, cmd, arg);
}
@@ -334,7 +344,7 @@ static void *tcl_signal_callback(va_list
result = Tcl_GetObjResult(handler->interp);
/* handle return values -- strings and words only */
if (handler->returntype) {
- if (purple_value_get_type(handler->returntype) == PURPLE_TYPE_STRING) {
+ if (handler->returntype == G_TYPE_STRING) {
retval = (void *)g_strdup(Tcl_GetString(result));
} else {
if (Tcl_GetIntFromObj(handler->interp, result, (int *)&retval) != TCL_OK) {
@@ -350,14 +360,14 @@ static void *tcl_signal_callback(va_list
for (i = 0; i < handler->nargs; i++) {
g_string_printf(name, "%s::arg%d",
Tcl_GetString(handler->namespace), i);
+#if 0
More information about the Commits
mailing list