Skip to content

Commit 87e4974

Browse files
committed
Reformat python script
1 parent 59dafb3 commit 87e4974

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/tools/rust-analyzer/lib/smol_str/src/gdb_smolstr_printer.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,25 @@
2525

2626
SMOL_INLINE_SIZE_RE = re.compile(r".*::_V(\d+)$")
2727

28+
2829
def _read_utf8(mem):
2930
try:
3031
return mem.tobytes().decode("utf-8", errors="replace")
3132
except Exception:
3233
return repr(mem.tobytes())
3334

35+
3436
def _active_variant(enum_val):
3537
"""Return (variant_name, variant_value) for a Rust enum value using discriminant logic.
36-
Assume layout: fields[0] is unnamed u8 discriminant; fields[1] is the active variant.
38+
Assume layout: fields[0] is unnamed u8 discriminant; fields[1] is the active variant.
3739
"""
3840
fields = enum_val.type.fields()
3941
if len(fields) < 2:
4042
return None, None
4143
variant_field = fields[1]
4244
return variant_field.name, enum_val[variant_field]
4345

46+
4447
class SmolStrProvider:
4548
def __init__(self, val):
4649
self.val = val
@@ -86,8 +89,10 @@ def to_string(self):
8689
length = int(inner["length"])
8790
# ArcInner layout:
8891
# strong: Atomic<usize>, weak: Atomic<usize> | unsized tail 'data' bytes.
89-
sizeof_AtomicUsize = gdb.lookup_type("core::sync::atomic::AtomicUsize").sizeof
90-
header_size = sizeof_AtomicUsize * 2 # strong + weak counters
92+
sizeof_AtomicUsize = gdb.lookup_type(
93+
"core::sync::atomic::AtomicUsize"
94+
).sizeof
95+
header_size = sizeof_AtomicUsize * 2 # strong + weak counters
9196
data_arr = int(data_ptr) + header_size
9297
mem = gdb.selected_inferior().read_memory(data_arr, length)
9398
return _read_utf8(mem)
@@ -99,6 +104,7 @@ def to_string(self):
99104
def display_hint(self):
100105
return "string"
101106

107+
102108
class SmolStrSubPrinter(gdb.printing.SubPrettyPrinter):
103109
def __init__(self):
104110
super(SmolStrSubPrinter, self).__init__("SmolStr")
@@ -114,6 +120,7 @@ def __call__(self, val):
114120
pass
115121
return None
116122

123+
117124
class SmolStrPrettyPrinter(gdb.printing.PrettyPrinter):
118125
def __init__(self):
119126
super(SmolStrPrettyPrinter, self).__init__("smol_str", [])
@@ -129,9 +136,12 @@ def __call__(self, val):
129136
return pp
130137
return None
131138

139+
132140
printer = SmolStrPrettyPrinter()
133141

142+
134143
def register_printers(objfile=None):
135144
gdb.printing.register_pretty_printer(objfile, printer, replace=True)
136145

146+
137147
register_printers()

0 commit comments

Comments
 (0)