summaryrefslogtreecommitdiffstats
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-01-12 01:09:56 (GMT)
committerGuido van Rossum <guido@python.org>1996-01-12 01:09:56 (GMT)
commit8a5c5d277eba096c4f12fdcdf5b3550d63f6bc56 (patch)
tree61baa912d1a052436cda4215a6f53c856b9a6a95 /Python/marshal.c
parent0bfd6c33fa5af32a0e095bf2c3f645db259ef96c (diff)
downloadcpython-8a5c5d277eba096c4f12fdcdf5b3550d63f6bc56.zip
cpython-8a5c5d277eba096c4f12fdcdf5b3550d63f6bc56.tar.gz
cpython-8a5c5d277eba096c4f12fdcdf5b3550d63f6bc56.tar.bz2
changes for complex numbers
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 15c02c3..f3d7b5c 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -39,6 +39,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#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_object(v, p)
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 @@ r_object(p)
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);