summaryrefslogtreecommitdiffstats
path: root/Modules/structmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-08-19 16:44:15 (GMT)
committerGuido van Rossum <guido@python.org>1992-08-19 16:44:15 (GMT)
commit90ddb7b5cbf52a072a8a2718bbc7643a766f24ee (patch)
tree4a5a923c6a8996e1a4a9a3e8abba18ada83c0060 /Modules/structmodule.c
parent3af03d8f3ed9ba6035c119908c85c8bfe1d37822 (diff)
downloadcpython-90ddb7b5cbf52a072a8a2718bbc7643a766f24ee.zip
cpython-90ddb7b5cbf52a072a8a2718bbc7643a766f24ee.tar.gz
cpython-90ddb7b5cbf52a072a8a2718bbc7643a766f24ee.tar.bz2
unpack() now returns a tuple, not a list
Diffstat (limited to 'Modules/structmodule.c')
-rw-r--r--Modules/structmodule.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/Modules/structmodule.c b/Modules/structmodule.c
index 61122e4..eaeee50 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[] = {