Decrement reference count of C expression `dest`. For composite unboxed structures (e.g. tuples) recursively decrement reference counts for each component. If rare is True, optimize for code size and compilation speed.
(
self, dest: str, rtype: RType, *, is_xdec: bool = False, rare: bool = False
)
| 609 | # Otherwise assume it's an unboxed, pointerless value and do nothing. |
| 610 | |
| 611 | def emit_dec_ref( |
| 612 | self, dest: str, rtype: RType, *, is_xdec: bool = False, rare: bool = False |
| 613 | ) -> None: |
| 614 | """Decrement reference count of C expression `dest`. |
| 615 | |
| 616 | For composite unboxed structures (e.g. tuples) recursively |
| 617 | decrement reference counts for each component. |
| 618 | |
| 619 | If rare is True, optimize for code size and compilation speed. |
| 620 | """ |
| 621 | x = "X" if is_xdec else "" |
| 622 | if is_int_rprimitive(rtype): |
| 623 | if rare: |
| 624 | self.emit_line(f"CPyTagged_{x}DecRef({dest});") |
| 625 | else: |
| 626 | # Inlined |
| 627 | self.emit_line(f"CPyTagged_{x}DECREF({dest});") |
| 628 | elif isinstance(rtype, RTuple): |
| 629 | for i, item_type in enumerate(rtype.types): |
| 630 | self.emit_dec_ref(f"{dest}.f{i}", item_type, is_xdec=is_xdec, rare=rare) |
| 631 | elif isinstance(rtype, RVec): |
| 632 | prefix = VEC_MACRO_PREFIX[rtype._ctype] |
| 633 | self.emit_line(f"{prefix}_DECREF({dest});") |
| 634 | elif not rtype.is_unboxed: |
| 635 | if rare: |
| 636 | self.emit_line(f"CPy_{x}DecRef({dest});") |
| 637 | else: |
| 638 | # Inlined |
| 639 | if rtype.may_be_immortal or not HAVE_IMMORTAL: |
| 640 | self.emit_line(f"CPy_{x}DECREF({dest});") |
| 641 | else: |
| 642 | self.emit_line(f"CPy_{x}DECREF_NO_IMM({dest});") |
| 643 | elif rtype.is_refcounted: |
| 644 | assert False, f"dec_ref not implemented for {rtype}" |
| 645 | # Otherwise assume it's an unboxed, pointerless value and do nothing. |
| 646 | |
| 647 | def pretty_name(self, typ: RType) -> str: |
| 648 | value_type = optional_value_type(typ) |