Skip to content

Commit dc52961

Browse files
committed
Tweaks from review feedback (thanks!)
1 parent b77cd2d commit dc52961

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Lib/test/test_marshal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ def test_deterministic_sets(self):
409409
self.assertEqual(dump_0, dump_1)
410410

411411
def test_unmarshallable(self):
412-
# gh-106287
412+
# Check no crash after encountering unmarshallable objects.
413+
# See https://github.com/python/cpython/issues/106287
413414
fset = frozenset([int])
414415
code = compile("a = 1", "<string>", "exec")
415416
code = code.replace(co_consts=(1, fset, None))
@@ -427,6 +428,7 @@ def test_unmarshallable(self):
427428
with self.assertRaisesRegex(ValueError, "unmarshallable object"):
428429
marshal.dumps((arg, memoryview(b'')))
429430

431+
430432
LARGE_SIZE = 2**31
431433
pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
432434

Python/marshal.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,9 @@ w_object(PyObject *v, WFILE *p)
431431
{
432432
char flag = '\0';
433433

434-
if (p->error != WFERR_OK)
434+
if (p->error != WFERR_OK) {
435435
return;
436+
}
436437

437438
p->depth++;
438439

@@ -753,10 +754,6 @@ PyMarshal_WriteLongToFile(long x, FILE *fp, int version)
753754
w_flush(&wf);
754755
}
755756

756-
/* TODO: Contrary to its documentation, this function does NOT set an error on
757-
* failure. It is not used internally except from test code, where this doesn't
758-
* matter, but this discrepancy might cause problems for any external code
759-
* using it. */
760757
void
761758
PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version)
762759
{

0 commit comments

Comments
 (0)