Commit 8c01615
authored
marshal (#7467)
* CPython-compatible marshal format
Unify marshal to a single CPython-compatible format. No separate
"cpython_marshal" reader — one format for frozen modules, .pyc
files, and the Python-level marshal module.
- ComparisonOperator: `(cmp_index << 5) | mask` matching COMPARE_OP
- MakeFunctionFlag: bit-position matching SET_FUNCTION_ATTRIBUTE
- Exception table varint: big-endian (matching Python/assemble.c)
- Linetable varint: little-endian (unchanged)
- Integer: TYPE_INT (i32) / TYPE_LONG (base-2^15 digits)
- Code objects: CPython field order (argcount, posonlyargcount, ...,
co_localsplusnames, co_localspluskinds, ..., co_exceptiontable)
- FLAG_REF / TYPE_REF for object deduplication (version >= 3)
- allow_code keyword argument on dumps/loads/dump/load
- Subclass rejection (int/float/complex/tuple/list/dict/set/frozenset)
- Slice serialization (version >= 5)
- Buffer protocol fallback for memoryview/array
- Recursion depth limit (2000) for both reads and writes
- Streaming load (reads one object, seeks file position)
- TYPE_INT64, TYPE_FLOAT (text), TYPE_COMPLEX (text) for compat
serialize_code writes co_localsplusnames/co_localspluskinds from
split varnames/cellvars/freevars. deserialize_code splits them back.
Cell variable DEREF indices are translated between flat (wire) and
cell-relative (internal) representations in both directions.
Replace bitwise trick with match for new ComparisonOperator values.
21 -> 3 expected failures. Remaining: test_bad_reader (IO layer),
test_deterministic_sets (PYTHONHASHSEED), testIntern (string interning).
* Address code review: preserve CO_FAST_HIDDEN, fix varint overflow
- Use original localspluskinds from marshal data instead of
rebuilding, preserving CO_FAST_HIDDEN and other flags
- Fix write_varint_be to handle values >= 2^30 (add 6th chunk)
- Remove unused build_localspluskinds_from_split
* Add depth guard to deserialize_value_typed
Prevents usize underflow when dict key deserialization path calls
deserialize_value_typed with depth=0 on composite types.1 parent 907ce4d commit 8c01615
File tree
8 files changed
+1274
-357
lines changed- Lib/test
- crates
- compiler-core/src
- bytecode
- vm/src
- builtins
- stdlib
- types
8 files changed
+1274
-357
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
| |||
141 | 140 | | |
142 | 141 | | |
143 | 142 | | |
144 | | - | |
145 | 143 | | |
146 | 144 | | |
147 | 145 | | |
| |||
234 | 232 | | |
235 | 233 | | |
236 | 234 | | |
237 | | - | |
238 | 235 | | |
239 | 236 | | |
240 | 237 | | |
241 | 238 | | |
242 | 239 | | |
243 | 240 | | |
244 | | - | |
245 | 241 | | |
246 | 242 | | |
247 | 243 | | |
| |||
274 | 270 | | |
275 | 271 | | |
276 | 272 | | |
277 | | - | |
278 | 273 | | |
279 | 274 | | |
280 | 275 | | |
| |||
295 | 290 | | |
296 | 291 | | |
297 | 292 | | |
298 | | - | |
| 293 | + | |
299 | 294 | | |
300 | 295 | | |
301 | 296 | | |
| |||
324 | 319 | | |
325 | 320 | | |
326 | 321 | | |
327 | | - | |
328 | 322 | | |
329 | 323 | | |
330 | 324 | | |
| |||
348 | 342 | | |
349 | 343 | | |
350 | 344 | | |
351 | | - | |
352 | 345 | | |
353 | 346 | | |
354 | 347 | | |
| |||
532 | 525 | | |
533 | 526 | | |
534 | 527 | | |
535 | | - | |
536 | 528 | | |
537 | 529 | | |
538 | 530 | | |
539 | 531 | | |
540 | 532 | | |
541 | | - | |
542 | 533 | | |
543 | 534 | | |
544 | 535 | | |
545 | 536 | | |
546 | 537 | | |
547 | | - | |
548 | 538 | | |
549 | 539 | | |
550 | 540 | | |
551 | 541 | | |
552 | 542 | | |
553 | | - | |
554 | 543 | | |
555 | 544 | | |
556 | 545 | | |
557 | 546 | | |
558 | 547 | | |
559 | | - | |
560 | 548 | | |
561 | 549 | | |
562 | 550 | | |
563 | 551 | | |
564 | 552 | | |
565 | 553 | | |
566 | | - | |
567 | 554 | | |
568 | 555 | | |
569 | 556 | | |
570 | 557 | | |
571 | 558 | | |
572 | 559 | | |
573 | | - | |
574 | 560 | | |
575 | 561 | | |
576 | 562 | | |
577 | 563 | | |
578 | 564 | | |
579 | 565 | | |
580 | | - | |
581 | 566 | | |
582 | 567 | | |
583 | 568 | | |
584 | 569 | | |
585 | 570 | | |
586 | 571 | | |
587 | | - | |
588 | 572 | | |
589 | 573 | | |
590 | 574 | | |
591 | 575 | | |
592 | 576 | | |
593 | 577 | | |
594 | | - | |
595 | 578 | | |
596 | 579 | | |
597 | 580 | | |
| |||
651 | 634 | | |
652 | 635 | | |
653 | 636 | | |
654 | | - | |
655 | 637 | | |
656 | 638 | | |
657 | 639 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
76 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
570 | 578 | | |
571 | 579 | | |
572 | 580 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
385 | 389 | | |
386 | 390 | | |
387 | 391 | | |
| |||
426 | 430 | | |
427 | 431 | | |
428 | 432 | | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
441 | 450 | | |
442 | | - | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
443 | 490 | | |
444 | 491 | | |
445 | 492 | | |
| |||
0 commit comments