LEFT | RIGHT |
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 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 FREE_ARG_TUP(self); | 823 FREE_ARG_TUP(self); |
824 } | 824 } |
825 return result; | 825 return result; |
826 } | 826 } |
827 | 827 |
828 /* Returns the size of the input on success, -1 on failure. This takes its | 828 /* Returns the size of the input on success, -1 on failure. This takes its |
829 own reference to `input`. */ | 829 own reference to `input`. */ |
830 static Py_ssize_t | 830 static Py_ssize_t |
831 _Unpickler_SetStringInput(UnpicklerObject *self, PyObject *input) | 831 _Unpickler_SetStringInput(UnpicklerObject *self, PyObject *input) |
832 { | 832 { |
833 Py_buffer *buffer; | 833 PyBuffer_Release(self->buffer); |
834 | 834 if (PyObject_GetBuffer(input, self->buffer, PyBUF_CONTIG_RO) < 0) { |
835 buffer = PyMem_MALLOC(sizeof(Py_buffer)); | 835 return -1; |
836 if (buffer == NULL) { | 836 } |
837 PyErr_NoMemory(); | 837 self->input_buffer = self->buffer->buf; |
838 return -1; | 838 self->input_len = self->buffer->len; |
839 } | |
840 if (PyObject_GetBuffer(input, buffer, PyBUF_CONTIG_RO) < 0) { | |
841 return -1; | |
842 } | |
843 if (self->buffer != NULL) { | |
844 PyBuffer_Release(self->buffer); | |
845 } | |
846 self->buffer = buffer; | |
847 | |
848 self->input_buffer = buffer->buf; | |
849 self->input_len = buffer->len; | |
850 self->next_read_idx = 0; | 839 self->next_read_idx = 0; |
851 return self->input_len; | 840 return self->input_len; |
852 } | 841 } |
853 | 842 |
854 static const Py_ssize_t READ_WHOLE_LINE = -1; | 843 static const Py_ssize_t READ_WHOLE_LINE = -1; |
855 | 844 |
856 /* If reading from a file, we need to only pull the bytes we need, since there | 845 /* If reading from a file, we need to only pull the bytes we need, since there |
857 may be multiple pickle objects arranged contiguously in the same input | 846 may be multiple pickle objects arranged contiguously in the same input |
858 buffer. | 847 buffer. |
859 | 848 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 self = PyObject_GC_New(UnpicklerObject, &Unpickler_Type); | 1062 self = PyObject_GC_New(UnpicklerObject, &Unpickler_Type); |
1074 if (self == NULL) | 1063 if (self == NULL) |
1075 return NULL; | 1064 return NULL; |
1076 | 1065 |
1077 self->stack = (Pdata *)Pdata_New(); | 1066 self->stack = (Pdata *)Pdata_New(); |
1078 if (self->stack == NULL) { | 1067 if (self->stack == NULL) { |
1079 Py_DECREF(self); | 1068 Py_DECREF(self); |
1080 return NULL; | 1069 return NULL; |
1081 } | 1070 } |
1082 | 1071 |
| 1072 self->buffer = PyMem_MALLOC(sizeof(Py_buffer)); |
| 1073 if (self->buffer == NULL) { |
| 1074 PyErr_NoMemory(); |
| 1075 Py_DECREF(self); |
| 1076 Py_DECREF(self->stack); |
| 1077 return NULL; |
| 1078 } |
| 1079 memset(self->buffer, 0, sizeof(Py_buffer)); |
| 1080 |
1083 self->memo_size = 32; | 1081 self->memo_size = 32; |
1084 self->memo = _Unpickler_NewMemo(self->memo_size); | 1082 self->memo = _Unpickler_NewMemo(self->memo_size); |
1085 if (self->memo == NULL) { | 1083 if (self->memo == NULL) { |
1086 Py_DECREF(self); | 1084 Py_DECREF(self); |
1087 Py_DECREF(self->stack); | 1085 Py_DECREF(self->stack); |
| 1086 PyMem_FREE(self->buffer); |
1088 return NULL; | 1087 return NULL; |
1089 } | 1088 } |
1090 | 1089 |
1091 self->arg = NULL; | 1090 self->arg = NULL; |
1092 self->pers_func = NULL; | 1091 self->pers_func = NULL; |
1093 self->buffer = NULL; | |
1094 self->input_buffer = NULL; | 1092 self->input_buffer = NULL; |
1095 self->input_line = NULL; | 1093 self->input_line = NULL; |
1096 self->input_len = 0; | 1094 self->input_len = 0; |
1097 self->next_read_idx = 0; | 1095 self->next_read_idx = 0; |
1098 self->read = NULL; | 1096 self->read = NULL; |
1099 self->readline = NULL; | 1097 self->readline = NULL; |
1100 self->encoding = NULL; | 1098 self->encoding = NULL; |
1101 self->errors = NULL; | 1099 self->errors = NULL; |
1102 self->marks = NULL; | 1100 self->marks = NULL; |
1103 self->num_marks = 0; | 1101 self->num_marks = 0; |
(...skipping 5160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6264 if (PyModule_AddObject(m, "PicklingError", PicklingError) < 0) | 6262 if (PyModule_AddObject(m, "PicklingError", PicklingError) < 0) |
6265 return NULL; | 6263 return NULL; |
6266 if (PyModule_AddObject(m, "UnpicklingError", UnpicklingError) < 0) | 6264 if (PyModule_AddObject(m, "UnpicklingError", UnpicklingError) < 0) |
6267 return NULL; | 6265 return NULL; |
6268 | 6266 |
6269 if (initmodule() < 0) | 6267 if (initmodule() < 0) |
6270 return NULL; | 6268 return NULL; |
6271 | 6269 |
6272 return m; | 6270 return m; |
6273 } | 6271 } |
LEFT | RIGHT |