unpack() now returns a tuple, not a list

This commit is contained in:
Guido van Rossum 1992-08-19 16:44:15 +00:00
parent 3af03d8f3e
commit 90ddb7b5cb

View File

@ -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[] = {