| 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 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 } | 1703 } |
| 1704 | 1704 |
| 1705 static int | 1705 static int |
| 1706 save_bytes(PicklerObject *self, PyObject *obj) | 1706 save_bytes(PicklerObject *self, PyObject *obj) |
| 1707 { | 1707 { |
| 1708 if (self->proto < 3) { | 1708 if (self->proto < 3) { |
| 1709 /* Older pickle protocols do not have an opcode for pickling bytes | 1709 /* Older pickle protocols do not have an opcode for pickling bytes |
| 1710 objects. Therefore, we need to fake the copy protocol (i.e., | 1710 objects. Therefore, we need to fake the copy protocol (i.e., |
| 1711 the __reduce__ method) to permit bytes object unpickling. */ | 1711 the __reduce__ method) to permit bytes object unpickling. */ |
| 1712 PyObject *reduce_value = NULL; | 1712 PyObject *reduce_value = NULL; |
| 1713 PyObject *bytelist = NULL; | 1713 PyObject *bytearray = NULL; |
| 1714 int status; | 1714 int status; |
| 1715 | 1715 |
| 1716 bytelist = PySequence_List(obj); | 1716 bytearray = PyByteArray_FromObject(obj); |
| 1717 if (bytelist == NULL) | 1717 if (bytearray == NULL) |
| 1718 return -1; | 1718 return -1; |
| 1719 | 1719 |
| 1720 reduce_value = Py_BuildValue("(O(O))", (PyObject *)&PyBytes_Type, | 1720 reduce_value = Py_BuildValue("(O(O))", (PyObject *)&PyBytes_Type, |
| 1721 bytelist); | 1721 bytearray); |
| 1722 if (reduce_value == NULL) { | 1722 if (reduce_value == NULL) { |
| 1723 Py_DECREF(bytelist); | 1723 Py_DECREF(bytearray); |
| 1724 return -1; | 1724 return -1; |
| 1725 } | 1725 } |
| 1726 | 1726 |
| 1727 /* save_reduce() will memoize the object automatically. */ | 1727 /* save_reduce() will memoize the object automatically. */ |
| 1728 status = save_reduce(self, reduce_value, obj); | 1728 status = save_reduce(self, reduce_value, obj); |
| 1729 Py_DECREF(reduce_value); | 1729 Py_DECREF(reduce_value); |
| 1730 Py_DECREF(bytelist); | 1730 Py_DECREF(bytearray); |
| 1731 return status; | 1731 return status; |
| 1732 } | 1732 } |
| 1733 else { | 1733 else { |
| 1734 Py_ssize_t size; | 1734 Py_ssize_t size; |
| 1735 char header[5]; | 1735 char header[5]; |
| 1736 Py_ssize_t len; | 1736 Py_ssize_t len; |
| 1737 | 1737 |
| 1738 size = PyBytes_Size(obj); | 1738 size = PyBytes_Size(obj); |
| 1739 if (size < 0) | 1739 if (size < 0) |
| 1740 return -1; | 1740 return -1; |
| (...skipping 4652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6393 if (PyModule_AddObject(m, "PicklingError", PicklingError) < 0) | 6393 if (PyModule_AddObject(m, "PicklingError", PicklingError) < 0) |
| 6394 return NULL; | 6394 return NULL; |
| 6395 if (PyModule_AddObject(m, "UnpicklingError", UnpicklingError) < 0) | 6395 if (PyModule_AddObject(m, "UnpicklingError", UnpicklingError) < 0) |
| 6396 return NULL; | 6396 return NULL; |
| 6397 | 6397 |
| 6398 if (initmodule() < 0) | 6398 if (initmodule() < 0) |
| 6399 return NULL; | 6399 return NULL; |
| 6400 | 6400 |
| 6401 return m; | 6401 return m; |
| 6402 } | 6402 } |
| OLD | NEW |