diff Modules/structmodule.c @ 976:31b018bda7e2 legacy-trunk

unpack() now returns a tuple, not a list
author Guido van Rossum <guido@python.org>
date Wed, 19 Aug 1992 16:44:15 +0000
parents 7d3a053c6765
children 1cabc2b6c970
line wrap: on
line diff
--- a/Modules/structmodule.c	Wed Aug 19 16:42:53 1992 +0000
+++ b/Modules/structmodule.c	Wed Aug 19 16:44:15 1992 +0000
@@ -317,6 +317,27 @@
 }
 
 
+/* 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 @@
 		}
 	}
 
-	return res;
+	return totuple(res);
 
  fail:
 	DECREF(res);
 	return NULL;
 }
 
+
 /* List of functions */
 
 static struct methodlist struct_methods[] = {