TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Monkey Patching in Go

82 点作者 Sirupsen大约 10 年前

7 条评论

GauntletWizard大约 10 年前
This is awful, dangerous, and compiler designers and writers will yell at you. Well done :)<p>I&#x27;ve always wanted a way to monkey-patch otherwise statically and well-bound code, but only for testing. In C, it&#x27;s fairly easy to set up preprocessor rules to do so, though also litters your primary code with test specific stuff. I have mostly focused on how to integrate this into compiler logic; Building some functionality to replace specified symbols in the build phase. Simply replacing the function pointers in the runtime is brilliant, if more than a little hacky and prone to problems.<p>I look forward to playing around with this.
kylequest大约 10 年前
This is not monkey patching. This is the good old function&#x2F;api &quot;hooking&quot; that&#x27;s pretty common in the compiled language world: <a href="http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hooking" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hooking</a><p>Monkey patching is a less invasive version of hooking used in dynamic languages. Bottom line: if you are dealing with assembly it&#x27;s no longer monkey patching :-)
评论 #9291728 未加载
评论 #9292295 未加载
4ad大约 10 年前
This does not work for any non-trivial function because of missing stack map for the GC and stack copier.
mpnordland大约 10 年前
So, this is a step towards implementing plugins for go right? It seems to me like this could be used to implement dynamic code loading.
评论 #9292351 未加载
评论 #9293524 未加载
zik大约 10 年前
This is admirable work in the pursuit of evil.
infogulch大约 10 年前
Could this be expanded to hot-swap code as you write it?
marvy大约 10 年前
Is this safe for such short functions? What if the patch takes more space than the original code?
评论 #9292117 未加载