Mercurial > cpython-lru_cache-weakref
diff Python/marshal.c @ 3323:6098aaa8ae7f legacy-trunk
changes for complex numbers
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 12 Jan 1996 01:09:56 +0000 |
| parents | aafe7d634985 |
| children | 28c0df1ce284 |
line wrap: on
line diff
--- a/Python/marshal.c Fri Jan 12 01:00:58 1996 +0000 +++ b/Python/marshal.c Fri Jan 12 01:09:56 1996 +0000 @@ -39,6 +39,7 @@ #define TYPE_NONE 'N' #define TYPE_INT 'i' #define TYPE_FLOAT 'f' +#define TYPE_COMPLEX 'x' #define TYPE_LONG 'l' #define TYPE_STRING 's' #define TYPE_TUPLE '(' @@ -150,6 +151,26 @@ w_byte(n, p); w_string(buf, n, p); } +#ifndef WITHOUT_COMPLEX + else if (is_complexobject(v)) { + extern void float_buf_repr PROTO((char *, floatobject *)); + char buf[256]; /* Plenty to format any double */ + floatobject *temp; + w_byte(TYPE_COMPLEX, p); + temp = (floatobject*)newfloatobject(PyComplex_RealAsDouble(v)); + float_buf_repr(buf, temp); + DECREF(temp); + n = strlen(buf); + w_byte(n, p); + w_string(buf, n, p); + temp = (floatobject*)newfloatobject(PyComplex_ImagAsDouble(v)); + float_buf_repr(buf, temp); + DECREF(temp); + n = strlen(buf); + w_byte(n, p); + w_string(buf, n, p); + } +#endif else if (is_stringobject(v)) { w_byte(TYPE_STRING, p); n = getstringsize(v); @@ -329,6 +350,32 @@ return newfloatobject(atof(buf)); } +#ifndef WITHOUT_COMPLEX + case TYPE_COMPLEX: + { + extern double atof PROTO((const char *)); + char buf[256]; + complex c; + n = r_byte(p); + if (r_string(buf, (int)n, p) != n) { + err_setstr(EOFError, + "EOF read where object expected"); + return NULL; + } + buf[n] = '\0'; + c.real = atof(buf); + n = r_byte(p); + if (r_string(buf, (int)n, p) != n) { + err_setstr(EOFError, + "EOF read where object expected"); + return NULL; + } + buf[n] = '\0'; + c.imag = atof(buf); + return newcomplexobject(c); + } +#endif + case TYPE_STRING: n = r_long(p); v = newsizedstringobject((char *)NULL, n);
