OLD | NEW |
1 #include "Python.h" | 1 #include "Python.h" |
2 #include "structmember.h" | 2 #include "structmember.h" |
3 | 3 |
4 PyDoc_STRVAR(pickle_module_doc, | 4 PyDoc_STRVAR(pickle_module_doc, |
5 "Optimized C implementation for the Python pickle module."); | 5 "Optimized C implementation for the Python pickle module."); |
6 | 6 |
7 /* Bump this when new opcodes are added to the pickle protocol. */ | 7 /* Bump this when new opcodes are added to the pickle protocol. */ |
8 enum { | 8 enum { |
9 HIGHEST_PROTOCOL = 3, | 9 HIGHEST_PROTOCOL = 3, |
10 DEFAULT_PROTOCOL = 3 | 10 DEFAULT_PROTOCOL = 3 |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 { | 1009 { |
1010 double x = PyFloat_AS_DOUBLE((PyFloatObject *)obj); | 1010 double x = PyFloat_AS_DOUBLE((PyFloatObject *)obj); |
1011 | 1011 |
1012 if (self->bin) { | 1012 if (self->bin) { |
1013 char pdata[9]; | 1013 char pdata[9]; |
1014 pdata[0] = BINFLOAT; | 1014 pdata[0] = BINFLOAT; |
1015 if (_PyFloat_Pack8(x, (unsigned char *)&pdata[1], 0) < 0) | 1015 if (_PyFloat_Pack8(x, (unsigned char *)&pdata[1], 0) < 0) |
1016 return -1; | 1016 return -1; |
1017 if (pickler_write(self, pdata, 9) < 0) | 1017 if (pickler_write(self, pdata, 9) < 0) |
1018 return -1; | 1018 return -1; |
1019 } | 1019 } |
1020 else { | 1020 else { |
1021 char pdata[250]; | 1021 int result = -1; |
1022 pdata[0] = FLOAT; | 1022 char *buf = NULL; |
1023 PyOS_ascii_formatd(pdata + 1, sizeof(pdata) - 2, "%.17g", x); | 1023 char op = FLOAT; |
1024 /* Extend the formatted string with a newline character */ | |
1025 strcat(pdata, "\n"); | |
1026 | 1024 |
1027 if (pickler_write(self, pdata, strlen(pdata)) < 0) | 1025 if (pickler_write(self, &op, 1) < 0) |
1028 return -1; | 1026 goto done; |
| 1027 |
| 1028 buf = PyOS_double_to_string(x, 'r', 0, 0, NULL); |
| 1029 if (!buf) { |
| 1030 PyErr_NoMemory(); |
| 1031 goto done; |
| 1032 } |
| 1033 |
| 1034 if (pickler_write(self, buf, strlen(buf)) < 0) |
| 1035 goto done; |
| 1036 |
| 1037 if (pickler_write(self, "\n", 1) < 0) |
| 1038 goto done; |
| 1039 |
| 1040 result = 0; |
| 1041 done: |
| 1042 PyMem_Free(buf); |
| 1043 return result; |
1029 } | 1044 } |
1030 | 1045 |
1031 return 0; | 1046 return 0; |
1032 } | 1047 } |
1033 | 1048 |
1034 static int | 1049 static int |
1035 save_bytes(PicklerObject *self, PyObject *obj) | 1050 save_bytes(PicklerObject *self, PyObject *obj) |
1036 { | 1051 { |
1037 if (self->proto < 3) { | 1052 if (self->proto < 3) { |
1038 /* Older pickle protocols do not have an opcode for pickling bytes | 1053 /* Older pickle protocols do not have an opcode for pickling bytes |
(...skipping 3632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4671 if (PyModule_AddObject(m, "PicklingError", PicklingError) < 0) | 4686 if (PyModule_AddObject(m, "PicklingError", PicklingError) < 0) |
4672 return NULL; | 4687 return NULL; |
4673 if (PyModule_AddObject(m, "UnpicklingError", UnpicklingError) < 0) | 4688 if (PyModule_AddObject(m, "UnpicklingError", UnpicklingError) < 0) |
4674 return NULL; | 4689 return NULL; |
4675 | 4690 |
4676 if (init_stuff() < 0) | 4691 if (init_stuff() < 0) |
4677 return NULL; | 4692 return NULL; |
4678 | 4693 |
4679 return m; | 4694 return m; |
4680 } | 4695 } |
OLD | NEW |