From 90ddb7b5cbf52a072a8a2718bbc7643a766f24ee Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 19 Aug 1992 16:44:15 +0000 Subject: [PATCH] unpack() now returns a tuple, not a list --- Modules/structmodule.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Modules/structmodule.c b/Modules/structmodule.c index 61122e47a0e..eaeee5013a2 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -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, ...) */ static object * @@ -409,13 +430,14 @@ struct_unpack(self, args) } } - return res; + return totuple(res); fail: DECREF(res); return NULL; } + /* List of functions */ static struct methodlist struct_methods[] = {