惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
L
LINUX DO - 最新话题
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Visual Studio Blog
O
OpenAI News
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
Spread Privacy
Spread Privacy
Y
Y Combinator Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
T
The Blog of Author Tim Ferriss
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
Project Zero
Project Zero
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
G
Google Developers Blog

RSS feed of yihong0618's gitblog

12 月,姥姥,以及大模型 · Issue #344 · yihong0618/gitblog 不要自动化你的情感链接 · Issue #343 · yihong0618/gitblog 那些幸福的瞬间 · Issue #342 · yihong0618/gitblog 12 年过去了,你过得还好么? · Issue #341 · yihong0618/gitblog Be a human, not a claw. · Issue #339 · yihong0618/gitblog 新年快乐以及一些近况 · Issue #338 · yihong0618/gitblog 偶得的佳句与 AI · Issue #337 · yihong0618/gitblog 确定性的丧失 · Issue #336 · yihong0618/gitblog Something Boring or Interesting · Issue #335 · yihong0618/gitblog 2025 年我提了 500 个 Pull Requests · Issue #334 · yihong0618/gitblog 网友 · Issue #333 · yihong0618/gitblog 如何判断一个项目是个好的开源项目并且想贡献? · Issue #331 · yihong0618/gitblog Things I don’t like · Issue #329 · yihong0618/gitblog Notes on Pycon2025 · Issue #327 · yihong0618/gitblog 从错误中学习 · Issue #326 · yihong0618/gitblog 八月 · Issue #324 · yihong0618/gitblog 从给 Greptime 贡献代码的过程中,我都学到了什么 · Issue #320 · yihong0618/gitblog Notes on May · Issue #318 · yihong0618/gitblog Things I like · Issue #311 · yihong0618/gitblog 我的 35 岁 · Issue #309 · yihong0618/gitblog 连续跑了 365 天 · Issue #306 · yihong0618/gitblog 最近给开源项目贡献的记录 · Issue #304 · yihong0618/gitblog 2020-2025 最喜欢的 12 篇文章和一张图 · Issue #302 · yihong0618/gitblog 断章 · Issue #301 · yihong0618/gitblog 这两个月 · Issue #299 · yihong0618/gitblog 从给 RisingWave 提 PR 说起,聊聊怎么快速切入一个复杂的开源项目 · Issue #296 · yihong0618/gitblog 能几日,又中秋 · Issue #294 · yihong0618/gitblog 第一次 AI 尝试,完全用 AI(MarsCode) 做个需求 · Issue #293 · yihong0618/gitblog 一件趣事儿 · Issue #292 · yihong0618/gitblog 这玩意不是就__ · Issue #291 · yihong0618/gitblog 六月 · Issue #290 · yihong0618/gitblog 跑了 10000km 花了 13 年 · Issue #289 · yihong0618/gitblog 抉择 · Issue #287 · yihong0618/gitblog 三月 · Issue #283 · yihong0618/gitblog About Me · Issue #282 · yihong0618/gitblog 用小爱加手指机器人实现传统开关语音关灯 · Issue #281 · yihong0618/gitblog 记忆碎片 · Issue #280 · yihong0618/gitblog 开源值得么? · Issue #279 · yihong0618/gitblog 聊聊读书 · Issue #275 · yihong0618/gitblog 旧文,移动端最好的游戏,《Dream Quest》以及其它 · Issue #274 · yihong0618/gitblog 微信好友 · Issue #272 · yihong0618/gitblog 如何写一个 PostgreSQL Extension · Issue #270 · yihong0618/gitblog 五月病 · Issue #268 · yihong0618/gitblog 杂感 · Issue #262 · yihong0618/gitblog vm.overcommit_memory 学习笔记 · Issue #261 · yihong0618/gitblog 开源四年的一些记录 · Issue #259 · yihong0618/gitblog 不用 root 使用小爱同学和 ChatGPT 交互折腾记 · Issue #258 · yihong0618/gitblog 用 eBPF trace PostgreSQL 的几种姿势 · Issue #257 · yihong0618/gitblog 2022 失落的一年 · Issue #255 · yihong0618/gitblog 写诗吧 · Issue #254 · yihong0618/gitblog 利用 GitHubPoster 和 GitHub Actions 备份任意用户推特 · Issue #252 · yihong0618/gitblog 一杯敬月光 · Issue #251 · yihong0618/gitblog 如何判断一个数字帐号来自中国大陆 · Issue #248 · yihong0618/gitblog Random Thoughts · Issue #242 · yihong0618/gitblog 反思 · Issue #241 · yihong0618/gitblog 今天的跑步电台 · Issue #239 · yihong0618/gitblog LeetCode 是如何运行的--测试篇 · Issue #237 · yihong0618/gitblog 新冠纪元 · Issue #235 · yihong0618/gitblog Postgres 需要学的东西 · Issue #234 · yihong0618/gitblog Postgres 中 GUC 的一些记录 · Issue #233 · yihong0618/gitblog 运交华盖欲何求 · Issue #231 · yihong0618/gitblog 年终岁尾 · Issue #230 · yihong0618/gitblog 二零二二的三个小目标 · Issue #229 · yihong0618/gitblog 经历了人生体验最棒的一次面试 · Issue #228 · yihong0618/gitblog 参加了《开源面对面》《ByteTalk》《枫言枫语》播客的一些记录 · Issue #223 · yihong0618/gitblog 有趣与无趣 · Issue #221 · yihong0618/gitblog running_page 开源一周年的总结 · Issue #220 · yihong0618/gitblog 接下来要写的东西 · Issue #219 · yihong0618/gitblog 一点思考 · Issue #218 · yihong0618/gitblog 友情链接 · Issue #217 · yihong0618/gitblog 朋友圈 · Issue #216 · yihong0618/gitblog 张小龙的饭否 · Issue #215 · yihong0618/gitblog 一件小事 · Issue #214 · yihong0618/gitblog 从 Rich 作者的一个问题说起 · Issue #212 · yihong0618/gitblog 如何用一个仓库记录自己的一年 · Issue #209 · yihong0618/gitblog 逃离 · Issue #208 · yihong0618/gitblog 近况 · Issue #207 · yihong0618/gitblog 年过完了 · Issue #206 · yihong0618/gitblog 力扣的程序是如何运行的 · Issue #205 · yihong0618/gitblog 生存守则 · Issue #204 · yihong0618/gitblog 沮丧 · Issue #203 · yihong0618/gitblog 今年的三个小目标 · Issue #202 · yihong0618/gitblog 新年碎碎念 · Issue #201 · yihong0618/gitblog 二零二一开始 · Issue #200 · yihong0618/gitblog 记住这一刻 · Issue #199 · yihong0618/gitblog 巧妙利用 iOS 的快捷指令配合 GitHub Actions 实现自动化 · Issue #198 · yihong0618/gitblog 如何获取悦跑圈数据 · Issue #197 · yihong0618/gitblog 生的对立面 · Issue #196 · yihong0618/gitblog 推荐一些我一直关注的觉得不错的和 Python 相关的独立博客 · Issue #195 · yihong0618/gitblog 2020 年 10 月总结 11 月计划 · Issue #194 · yihong0618/gitblog 写在 0x20 岁之前 · Issue #193 · yihong0618/gitblog 如何获取 keep 跑步数据 · Issue #191 · yihong0618/gitblog 2020 年 9 月总结 10 月计划 · Issue #190 · yihong0618/gitblog 决定把gitblog和kb结合起来 · Issue #189 · yihong0618/gitblog 感冒了,真是难受 · Issue #188 · yihong0618/gitblog 把running page 变得通用必须提上日程了 · Issue #187 · yihong0618/gitblog 我转行程序员的经历 · Issue #186 · yihong0618/gitblog 普通人和天才之间的巨大鸿沟 · Issue #185 · yihong0618/gitblog 月跑 250 km计划 · Issue #184 · yihong0618/gitblog 2020年八月总结九月月展望 · Issue #182 · yihong0618/gitblog
一次艰难的 cpython issue 排查过程,以及我学到了什么 · Issue #325 · yihong0618/gitblog
yihong0618 · 2025-09-04 · via RSS feed of yihong0618's gitblog

引子

最近依然在尝试做一些大模型目前做不到的事儿,去满足一些存在感。但是 TiDB 的 issues 没有以前多了,恰好某一天 @kemingy 发现 cpython 源码里有些写的不好的地方,我想 cpython 也许也可以?但我万万没想到一个 patch 进入到 cpython 是多么的难,我已经前前后后修了 4 个 cpython 的 bug 但是每个都在过程中,过程中学到了不少东西,但更开心的是认识到了目前即使最强的大模型的局限。

bug ?

尝试的过程

下面是我尝试的过程,如果能同样帮到喜欢 bug 的朋友就更好了

  1. 当然是尝试复现,3.13 在 repl 使用 issue 中的语句 hang, 3.14 不 hang 住,是 3.13 only 的问题
  2. Claude Code 启动,先让大模型帮我定位下,大模型前前后后走了几圈,都是错的,而且大模型的思路有问题,它认为 3.14 修了就是有的 commit 修了,再不停的查 commit
  3. 自己来吧,首先先缩小范围
    • 在 repl 里必复现
    • 直接使用 ./python xxx.py 没事
    • pty 没事儿
    • subprocess 没事
    • 卧槽只有 repl 里?
    • 强制使用旧 repl PYTHON_BASIC_REPL=1 ./python 也没事儿!
  4. OK 那是 new repl only, 定位好了问题

能复现就是成功的一半?

  1. no 这个 issue 并不是
  2. 这个是 c 层面的还是 python 层面的?因为只有在 new repl 里我开始以为是 python 层面的
  3. 在所有可能是 memory error 的地方接上 except: nothing work
  4. 在源码里加 print 卧槽加上 print bug 消失了,妈的
  5. 因为上条我怀疑我走错路了,大概率是 c 层面的,但是我得定位到哪一行造成 c 层面的错误
  6. 再一顿 print debug 之后发现是 console.py 里的这一行 exec(code, self.locals)
  7. OK 找到这个 bug 就可以简化为在 new repl 里执行 exec("_testcapi.set_nomemory(0)")

但是但是

  1. 我在 c 层面一路找 memroy 相关的没头绪,能改的地方都改了
  2. 过程中还熟悉了一点 cpython 的代码
  3. 但是还是不行

先放弃了,但还想着

  • 然后我就把问题先搁置了去忙别的了
  • 但是跑步的过程中突然有了一点想法也许不是 3.13 only 的
  • git branch 启动!对不是!发现 3.14 第一个版本仍然有这个 bug
  • 那么是某个小 branch 给修了
  • branch 二分法启动!最后发现是 3.14a2 -> 3.14a3 之间某个 commit 给意外的修复了?
  • 既然 branch 能二分法我突然悟到了可以 bisect
  • 第一次用 bisect 在大模型的教学下一路找(这里有个坑就是 good 和 bad 是反的)最后发现是这个 commit 意外的给修了 5fc6bb2754a25157575efc0b37da78c629fea46e
  • 修的人好强啊
  • 能 cherry-pick 么?不能!因为改动太大了这之间的里
  • 能借住他修的一部分修复么?一路尝试,是不能的,因为本质上不是一个问题
  • 又尝试了好多。。。也不行,确性了 cpython 遗留的 bug 都是有难度的

找朋友吧

  • 当然是先找@kemingy 帮忙,他比我多走了两步但是也卡住了
  • @frostming 也试试
  • 暂时没结果,早上突然想到我要去 pycon 的机票还在拖延,不想麻烦 gray 帮忙了 ,等下 @Graymon 的演讲是 gdb 相关也许可以试试
  • gdb 启动
  • 这里也有个坑好像 gdb 会改变内存
  • 但是最后还是找到了是在 /Python/ceval.c b/Python/ceval.c 的 goto exception_unwind; 里陷入了无限的递归
  • 修复如果递归直接 pyerr clear 卧槽不 hang 了但是是 Segmentation fault
  • 继续,成功了!于是有了如下修复
  • 感谢朋友们的帮忙,开心

修复

diff --git a/Python/ceval.c b/Python/ceval.c
index 8c0cb29863c..3fe97a2c74c 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -912,7 +912,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
                 int frame_lasti = _PyInterpreterFrame_LASTI(frame);
                 PyObject *lasti = PyLong_FromLong(frame_lasti);
                 if (lasti == NULL) {
-                    goto exception_unwind;
+                    // If we can't allocate memory for lasti during exception handling,
+                    // this likely means we're in a severe memory shortage situation.
+                    // Instead of going back to exception_unwind (which would cause
+                    // infinite recursion), directly exit to let the original exception
+                    // propagate up and hopefully be handled at a higher level.
+                    _PyFrame_SetStackPointer(frame, stack_pointer);
+                    goto exit_unwind;
                 }
                 PUSH(lasti);
             }

修复的对么?

  • 不知道,先跑测试 3.13 都通过了
  • main 有这个问题么?没有,代码结构都改了
  • 对不对我先把过程分享出来,能解决一大部分也是开心的

感想

  • 谢谢朋友们
  • 大模型还是有局限的但还是能帮不少忙的
  • gray 好厉害
  • cpython 能遗留下来的 bug 都非常难
  • 还是开心

---- update ----

https://t.me/c/1459082815/900

和 gray 学习。

以防有人没有 tg

Image Image

以及 gray 非常精彩的 pycon

GDB for CPython - PyCon 25.pdf

ppt 在附件中