| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a0e454b commit c0f59ad
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -530,13 +530,13 @@ def test_trailing_counter(self): | |||
| 530 | 530 | ||
| 531 | 531 | # format lists containing only count spec should result in an error | |
| 532 | 532 | self.assertRaises(struct.error, struct.pack, '12345') | |
| 533 | - self.assertRaises(struct.error, struct.unpack, '12345', '') | ||
| 533 | + self.assertRaises(struct.error, struct.unpack, '12345', b'') | ||
| 534 | 534 | self.assertRaises(struct.error, struct.pack_into, '12345', store, 0) | |
| 535 | 535 | self.assertRaises(struct.error, struct.unpack_from, '12345', store, 0) | |
| 536 | 536 | ||
| 537 | 537 | # Format lists with trailing count spec should result in an error | |
| 538 | 538 | self.assertRaises(struct.error, struct.pack, 'c12345', 'x') | |
| 539 | - self.assertRaises(struct.error, struct.unpack, 'c12345', 'x') | ||
| 539 | + self.assertRaises(struct.error, struct.unpack, 'c12345', b'x') | ||
| 540 | 540 | self.assertRaises(struct.error, struct.pack_into, 'c12345', store, 0, | |
| 541 | 541 | 'x') | |
| 542 | 542 | self.assertRaises(struct.error, struct.unpack_from, 'c12345', store, | |
@@ -545,7 +545,7 @@ def test_trailing_counter(self): | |||
| 545 | 545 | # Mixed format tests | |
| 546 | 546 | self.assertRaises(struct.error, struct.pack, '14s42', 'spam and eggs') | |
| 547 | 547 | self.assertRaises(struct.error, struct.unpack, '14s42', | |
| 548 | - 'spam and eggs') | ||
| 548 | + b'spam and eggs') | ||
| 549 | 549 | self.assertRaises(struct.error, struct.pack_into, '14s42', store, 0, | |
| 550 | 550 | 'spam and eggs') | |
| 551 | 551 | self.assertRaises(struct.error, struct.unpack_from, '14s42', store, 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2162,7 +2162,7 @@ pack_into(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | |||
| 2162 | 2162 | unpack | |
| 2163 | 2163 | ||
| 2164 | 2164 | format: object | |
| 2165 | - inputstr: object | ||
| 2165 | + buffer: Py_buffer | ||
| 2166 | 2166 | / | |
| 2167 | 2167 | ||
| 2168 | 2168 | Return a tuple containing values unpacked according to the format string. | |
@@ -2173,16 +2173,16 @@ See help(struct) for more on format strings. | |||
| 2173 | 2173 | [clinic start generated code]*/ | |
| 2174 | 2174 | ||
| 2175 | 2175 | static PyObject * | |
| 2176 | - unpack_impl(PyObject *module, PyObject *format, PyObject *inputstr) | ||
| 2177 | - /*[clinic end generated code: output=06951d66eae6d63b input=4b81d54988890f5e]*/ | ||
| 2176 | + unpack_impl(PyObject *module, PyObject *format, Py_buffer *buffer) | ||
| 2177 | + /*[clinic end generated code: output=f75ada02aaa33b3b input=654078e6660c2df0]*/ | ||
| 2178 | 2178 | { | |
| 2179 | 2179 | PyStructObject *s_object; | |
| 2180 | 2180 | PyObject *result; | |
| 2181 | 2181 | ||
| 2182 | 2182 | s_object = cache_struct(format); | |
| 2183 | 2183 | if (s_object == NULL) | |
| 2184 | 2184 | return NULL; | |
| 2185 | - result = Struct_unpack(s_object, inputstr); | ||
| 2185 | + result = Struct_unpack_impl(s_object, buffer); | ||
| 2186 | 2186 | Py_DECREF(s_object); | |
| 2187 | 2187 | return result; | |
| 2188 | 2188 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,7 +156,7 @@ PyDoc_STRVAR(calcsize__doc__, | |||
| 156 | 156 | {"calcsize", (PyCFunction)calcsize, METH_O, calcsize__doc__}, | |
| 157 | 157 | ||
| 158 | 158 | PyDoc_STRVAR(unpack__doc__, | |
| 159 | - "unpack($module, format, inputstr, /)\n" | ||
| 159 | + "unpack($module, format, buffer, /)\n" | ||
| 160 | 160 | "--\n" | |
| 161 | 161 | "\n" | |
| 162 | 162 | "Return a tuple containing values unpacked according to the format string.\n" | |
@@ -169,27 +169,31 @@ PyDoc_STRVAR(unpack__doc__, | |||
| 169 | 169 | {"unpack", (PyCFunction)unpack, METH_FASTCALL, unpack__doc__}, | |
| 170 | 170 | ||
| 171 | 171 | static PyObject * | |
| 172 | - unpack_impl(PyObject *module, PyObject *format, PyObject *inputstr); | ||
| 172 | + unpack_impl(PyObject *module, PyObject *format, Py_buffer *buffer); | ||
| 173 | 173 | ||
| 174 | 174 | static PyObject * | |
| 175 | 175 | unpack(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | |
| 176 | 176 | { | |
| 177 | 177 | PyObject *return_value = NULL; | |
| 178 | 178 | PyObject *format; | |
| 179 | - PyObject *inputstr; | ||
| 179 | + Py_buffer buffer = {NULL, NULL}; | ||
| 180 | 180 | ||
| 181 | - if (!_PyArg_UnpackStack(args, nargs, "unpack", | ||
| 182 | - 2, 2, | ||
| 183 | - &format, &inputstr)) { | ||
| 181 | + if (!_PyArg_ParseStack(args, nargs, "Oy*:unpack", | ||
| 182 | + &format, &buffer)) { | ||
| 184 | 183 | goto exit; | |
| 185 | 184 | } | |
| 186 | 185 | ||
| 187 | 186 | if (!_PyArg_NoStackKeywords("unpack", kwnames)) { | |
| 188 | 187 | goto exit; | |
| 189 | 188 | } | |
| 190 | - return_value = unpack_impl(module, format, inputstr); | ||
| 189 | + return_value = unpack_impl(module, format, &buffer); | ||
| 191 | 190 | ||
| 192 | 191 | exit: | |
| 192 | + /* Cleanup for buffer */ | ||
| 193 | + if (buffer.obj) { | ||
| 194 | + PyBuffer_Release(&buffer); | ||
| 195 | + } | ||
| 196 | + | ||
| 193 | 197 | return return_value; | |
| 194 | 198 | } | |
| 195 | 199 | ||
@@ -273,4 +277,4 @@ iter_unpack(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnam | |||
| 273 | 277 | exit: | |
| 274 | 278 | return return_value; | |
| 275 | 279 | } | |
| 276 | - /*[clinic end generated code: output=db8152ad222fa3d0 input=a9049054013a1b77]*/ | ||
| 280 | + /*[clinic end generated code: output=0714090a5d0ea8ce input=a9049054013a1b77]*/ | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments