diff options
author | Guido van Rossum <guido@python.org> | 1991-06-07 13:58:22 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-06-07 13:58:22 (GMT) |
commit | 64b4552069484c19c0127d3168931b38c557e039 (patch) | |
tree | 63f1d47cf6ef91da8b5fd0ec0f0d60f5d29776db /Python/marshal.c | |
parent | 65481401b18a78bbad41f712300047ed19355d38 (diff) | |
download | cpython-64b4552069484c19c0127d3168931b38c557e039.zip cpython-64b4552069484c19c0127d3168931b38c557e039.tar.gz cpython-64b4552069484c19c0127d3168931b38c557e039.tar.bz2 |
Add marshalling for dictionaries.
Diffstat (limited to 'Python/marshal.c')
-rw-r--r-- | Python/marshal.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index 94e6d3a..2049c9b 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -125,6 +125,22 @@ wr_object(v, fp) wr_object(getlistitem(v, (int)i), fp); } } + else if (is_dictobject(v)) { + wr_byte(TYPE_DICT, fp); + /* This one is NULL object terminated! */ + n = getdictsize(v); + for (i = 0; i < n; i++) { + object *key, *val; + extern object *getdict2key(); + key = getdict2key(v, (int)i); + if (key != NULL) { + val = dictlookup(v, getstringvalue(key)); + wr_object(key, fp); + wr_object(val, fp); + } + } + wr_object((object *)NULL, fp); + } else if (is_codeobject(v)) { codeobject *co = (codeobject *)v; wr_byte(TYPE_CODE, fp); @@ -261,6 +277,22 @@ rd_object(fp) setlistitem(v, (int)i, rd_object(fp)); return v; + case TYPE_DICT: + v = newdictobject(); + if (v == NULL) + return NULL; + for (;;) { + object *key, *val; + key = rd_object(fp); + if (key == NULL) + break; + val = rd_object(fp); + dict2insert(v, key, val); + DECREF(key); + XDECREF(val); + } + return v; + case TYPE_CODE: { object *code = rd_object(fp); @@ -288,7 +320,7 @@ rd_object(fp) } } -/* The rest is meant to test only... */ +/* And an interface for Python programs... */ static object * dump(self, args) |