desgard / ios-source-probe Goto Github PK
View Code? Open in Web Editor NEW🔎 iOS 源码探求系列
Home Page: http://www.desgard.com/iOS-Source-Probe/
License: MIT License
🔎 iOS 源码探求系列
Home Page: http://www.desgard.com/iOS-Source-Probe/
License: MIT License
看了你这篇 《weak 弱引用的实现方式》 文章 ,里面提到 :
“单步运行,发现会跳入 NSObject.mm 中的 objc_initWeak() 这个方法。在进行编译过程前,clang 其实对 __weak 做了转换,将声明方式做出了如下调整。”
我想问下 你是怎么知道 调用 objc_initWeak
这个函数的? 我自己尝试着 clang
, 转换的代码如下:
//转换前
{
NSObject *obj = [[NSObject alloc] init];
__weak id obj1 = obj;
}
//转换后
{
NSObject *obj = ((NSObject *(*)(id, SEL))(void *)objc_msgSend)((id)((NSObject *(*)(id, SEL))(void *)objc_msgSend)((id)objc_getClass("NSObject"), sel_registerName("alloc")), sel_registerName("init"));
__attribute__((objc_ownership(weak))) id obj1 = obj;
}
然后 objc_ownership()
又是啥? 我在 runtime
源码里木有搜到...
// Prevent a deadlock between the weak reference machinery
// and the +initialize machinery by ensuring that no
// weakly-referenced object has an un-+initialized isa.
if (haveNew && newObj) {
Class cls = newObj->getIsa();
if (cls != previouslyInitializedClass &&
!((objc_class *)cls)->isInitialized())
{
SideTable::unlockTwo<haveOld, haveNew>(oldTable, newTable);
_class_initialize(_class_getNonMetaClass(cls, (id)newObj));
// If this class is finished with +initialize then we're good.
// If this class is still running +initialize on this thread
// (i.e. +initialize called storeWeak on an instance of itself)
// then we may proceed but it will appear initializing and
// not yet initialized to the check above.
// Instead set previouslyInitializedClass to recognize it on retry.
previouslyInitializedClass = cls;
goto retry;
}
}
瓜哥你好~我想问下对于你而言 你觉得iOS看官方文档(例如guide)和看源码哪个优先度高一点?(或者说学得更多一点?)
建议采用 MachOView 看下 magic 的值,并非 magic = 0xcafebabe,而是 magic = 0xbebafeca,FAT_CIGAM。 这个涉及到内存大小端问题。官方文档对此也有详细的解释,参考官文: https://developer.apple.com/documentation/kernel/fat_header。iOS 是小端模式。
首先感谢你的分享,对sdwebimage分析的很好,能不能把带有中文详细注释的sdwebimage v3.8.1发布出来?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.