MCPcopy Index your code
hub / github.com/python/mypy / emit_reuse_clear

Method emit_reuse_clear

mypyc/codegen/emit.py:1346–1369  ·  view source on GitHub ↗

Emit attribute clear before object is added into freelist. Assume that 'target' represents a C expression that refers to a struct member, such as 'self->x'. Unlike emit_gc_clear(), initialize attribute value to match a freshly allocated object.

(self, target: str, rtype: RType)

Source from the content-addressed store, hash-verified

1344 assert False, "emit_gc_clear() not implemented for %s" % repr(rtype)
1345
1346 def emit_reuse_clear(self, target: str, rtype: RType) -> None:
1347 """Emit attribute clear before object is added into freelist.
1348
1349 Assume that 'target' represents a C expression that refers to a
1350 struct member, such as 'self->x'.
1351
1352 Unlike emit_gc_clear(), initialize attribute value to match a freshly
1353 allocated object.
1354 """
1355 if isinstance(rtype, RTuple):
1356 for i, item_type in enumerate(rtype.types):
1357 self.emit_reuse_clear(f"{target}.f{i}", item_type)
1358 elif not rtype.is_refcounted:
1359 self.emit_line(f"{target} = {rtype.c_undefined};")
1360 elif isinstance(rtype, RPrimitive) and rtype.name == "builtins.int":
1361 self.emit_line(f"if (CPyTagged_CheckLong({target})) {{")
1362 self.emit_line(f"CPyTagged __tmp = {target};")
1363 self.emit_line(f"{target} = {self.c_undefined_value(rtype)};")
1364 self.emit_line("Py_XDECREF(CPyTagged_LongAsObject(__tmp));")
1365 self.emit_line("} else {")
1366 self.emit_line(f"{target} = {self.c_undefined_value(rtype)};")
1367 self.emit_line("}")
1368 else:
1369 self.emit_gc_clear(target, rtype)
1370
1371 def emit_traceback(
1372 self, source_path: str, module_name: str, traceback_entry: tuple[str, int]

Callers 1

emit_reuse_deallocFunction · 0.80

Calls 5

emit_lineMethod · 0.95
c_undefined_valueMethod · 0.95
emit_gc_clearMethod · 0.95
isinstanceFunction · 0.85
enumerateFunction · 0.85

Tested by

no test coverage detected