Commit 5208e1da authored by Guido van Rossum's avatar Guido van Rossum

unpack() now returns a tuple, not a list

parent 1b477403
...@@ -317,6 +317,27 @@ struct_pack(self, args) ...@@ -317,6 +317,27 @@ struct_pack(self, args)
} }
/* Helper to convert a list to a tuple */
static object *
totuple(list)
object *list;
{
int len = getlistsize(list);
object *tuple = newtupleobject(len);
if (tuple != NULL) {
int i;
for (i = 0; i < len; i++) {
object *v = getlistitem(list, i);
INCREF(v);
settupleitem(tuple, i, v);
}
}
DECREF(list);
return tuple;
}
/* unpack(fmt, string) --> (v1, v2, ...) */ /* unpack(fmt, string) --> (v1, v2, ...) */
static object * static object *
...@@ -409,13 +430,14 @@ struct_unpack(self, args) ...@@ -409,13 +430,14 @@ struct_unpack(self, args)
} }
} }
return res; return totuple(res);
fail: fail:
DECREF(res); DECREF(res);
return NULL; return NULL;
} }
/* List of functions */ /* List of functions */
static struct methodlist struct_methods[] = { static struct methodlist struct_methods[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment