Increment reference count of C expression `dest`. For composite unboxed structures (e.g. tuples) recursively increment reference counts for each component. If rare is True, optimize for code size and compilation speed.
(self, dest: str, rtype: RType, *, rare: bool = False)
| 582 | ) |
| 583 | |
| 584 | def emit_inc_ref(self, dest: str, rtype: RType, *, rare: bool = False) -> None: |
| 585 | """Increment reference count of C expression `dest`. |
| 586 | |
| 587 | For composite unboxed structures (e.g. tuples) recursively |
| 588 | increment reference counts for each component. |
| 589 | |
| 590 | If rare is True, optimize for code size and compilation speed. |
| 591 | """ |
| 592 | if is_int_rprimitive(rtype): |
| 593 | if rare: |
| 594 | self.emit_line("CPyTagged_IncRef(%s);" % dest) |
| 595 | else: |
| 596 | self.emit_line("CPyTagged_INCREF(%s);" % dest) |
| 597 | elif isinstance(rtype, RTuple): |
| 598 | for i, item_type in enumerate(rtype.types): |
| 599 | self.emit_inc_ref(f"{dest}.f{i}", item_type) |
| 600 | elif isinstance(rtype, RVec): |
| 601 | prefix = VEC_MACRO_PREFIX[rtype._ctype] |
| 602 | self.emit_line(f"{prefix}_INCREF({dest});") |
| 603 | elif not rtype.is_unboxed: |
| 604 | # Always inline, since this is a simple but very hot op |
| 605 | if rtype.may_be_immortal or not HAVE_IMMORTAL: |
| 606 | self.emit_line("CPy_INCREF(%s);" % dest) |
| 607 | else: |
| 608 | self.emit_line("CPy_INCREF_NO_IMM(%s);" % dest) |
| 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 |