R1:T | t.CPtr -> T*(40 文件 / 1121 处;含多级 **、强转位 (T*)(x)、下标内 list[AST*]);引号前向引用 'Rect' | t.CPtr 26 处按例外保留,T | t.CPtr | t.State 25 处因 T* 后不能接 | 保持原联合写法。 R12:i = 0 + while i < N: + 尾 i += 1 -> or i in range(N):(10 文件 / 42 处;含 <= -> range(EXPR + 1)、带注解初始化 i: int = 0、尾 i = i + 1)。余 20 处经守卫判定不可安全改写(复合条件 1、尾部非自增 8、体内重绑定/continue 5、while-else 2、循环后仍被读取 2、找不到初始化 2)。
37 lines
881 B
Plaintext
37 lines
881 B
Plaintext
import t
|
|
import stdio
|
|
import stdlib
|
|
import memhub
|
|
from g4node import G4Node, new_g4node
|
|
|
|
|
|
# ============================================================
|
|
# caller2: 另一个导入 G4Node 的模块
|
|
#
|
|
# 增加 G4Node 的跨模块引用次数,触发多模块竞争条件
|
|
# ============================================================
|
|
|
|
|
|
def caller2_reverse_chain(head: G4Node*) -> G4Node*:
|
|
"""反转链表,直接访问 Next 字段"""
|
|
if head is None:
|
|
return None
|
|
prev: G4Node* = None
|
|
cur: G4Node* = head
|
|
while cur is not None:
|
|
nxt: G4Node* = cur.Next
|
|
cur.Next = prev
|
|
prev = cur
|
|
cur = nxt
|
|
return prev
|
|
|
|
|
|
def caller2_count_nodes(head: G4Node*) -> int:
|
|
"""计算链表节点数"""
|
|
count: int = 0
|
|
cur: G4Node* = head
|
|
while cur is not None:
|
|
count = count + 1
|
|
cur = cur.Next
|
|
return count
|