ã¯ã©ãã·ã¥ãšNSLogãæ±ã£ãŠããŸãã å®äŸ¡ã§ãã é·å¹Žã®çµéšã 100ïŒ ä¿èšŒã
ãã®èŠåºãã®ãããªãã®ã§ã3ãæååã«ç§ã®ãããžã§ã¯ãã®1ã€ã§èµ·ãã£ãããšã説æã§ããŸãã ããããããã¯ç§ã®ãããžã§ã¯ãã§ãããããŸããã§ããããã¯ã©ãã·ã¥ã®åé¡ã«å¯ŸåŠããªããã°ãªããŸããã§ããã
ããã¯ãã¹ãŠãæ¯èŒç倧ããªãããžã§ã¯ãã®1ã€ã§ããŠãŒã¶ãŒèªèšŒäžã«äŸå€ãçºçãå§ãããšããäºå®ããå§ãŸããŸããã ããŸããããã¯äœã§ããïŒ èª°ããèµ·ãããŸãã 圌ãã¯ã nilã«ãã§ãã¯ãå ¥ããã®ãå¿ããããã©ããã§å°ç¡ãã«ããŸããã ããŸããç§ã«ãšã£ãŠå€§ããªã€ãã³ãã¯ãããžã§ã¯ãã®ã¯ã©ãã·ã¥ã§ãããšã»ãšãã©ã®ããã°ã©ããŒã¯èããŸãã ååãšããŠãç§ã¯å®å šã«åæããŸãã iPhoneã®ããã°ã©ãã³ã°ã§ã¯ãã¯ã©ãã·ã¥ã¯ããã»ã©çããããšã§ã¯ãªãã1æ¥ã«10åçºçããŸãã ããããããã¯ç¹å¥ãªãã®ã§ããã 圌ã¯ãããã€ãã®ãã©ã¡ãŒã¿ãŒãšæ©èœã«ã€ããŠåœŒã«èšããããšãããã§ã«ãéæ³ãã®åãããå§ããŠããŸããã
- ã·ãã¥ã¬ãŒã¿ãŒã®åçŸæ§ ïŒ100ïŒ
- ããã€ã¹ã§ã®ãã¬ã€ã¢ããªã㣠ïŒ0ïŒ
- ã¯ã©ãã·ã¥ãã¹ïŒã¯ã©ãã·ã¥ããŒã«ãªãŒãŒã·ã§ã³åŸïŒïŒã40ç§
- ã³ã³ãã€ã«æé©åèšå®ïŒ-O1ã-O2 ...ïŒã¯åçŸæ§ã«åœ±é¿ããŸãã
- XIBã¯ãããžã§ã¯ãã§ã¯äœ¿çšãããŸãã
ã¯ãã圌ã¯ããªãç¡å®³ã«èŠããŸããïŒ
// Code UITextView * textView = [ [UITextView alloc] initWithFrame:CGRectMake(0, 150, _width, _height)]; // Exception *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0; nan 200]'
ãããŠãããªããºãã¯ãã®å¹ ãç解ããŠããŸã -èšç®åŸ-NaNïŒããšæããŸããããã¥ãŒã®å¹ ãã©ãã§ã©ã®ããã«èšç®ãããããäžç®èŠãã ãã§ãç¹ã«å±éºãªãã®ã¯èŠã€ããããªãã®ã§ããã¥ãŒãäœæããåã«NSLogãèšå®ããŠç¢ºèªããŸãããã«ãèŠçŽ ã®äœæã«äŒŽãè¡ã®ãã¬ãŒã¯ãã€ã³ãã
// Source: NSLog(@"width = %f", _width); //Output: width = 200
ããããšãç§ã¯èªåèªèº«ã«èãããã¬ãŒã¯ãã€ã³ãã®åŸãããã°ã©ã ãå®è¡ãç¶ããŸããã ãããŠãã¯ã©ãã·ã¥ã¯èµ·ãããŸããã§ãã...
ãã®ã¯ã©ãã·ã¥ãåçŸããããã¹ããããžã§ã¯ã
ãã®ç£ãèªåã§èŠãããšã«èå³ã®ãã人ã ã®ããã«-ãã¹ããããžã§ã¯ããç§ã«ãã ã
iOSã·ãã¥ã¬ãŒã¿ãããŒãžã§ã³SDK 5.1ã§ã®ã¿åçãããŸãïŒSDK 6以éã§ã¯åçãããŸããããåçãã芪åãªäººãããå Žå-PMã«æžã蟌ã¿ãæçš¿ããŠãã ããïŒ
ããã§äœããäºçŽ°ãªããšã ãšãŸã æã£ãŠãããªããå·éã«èªã¿é²ããŠãã ããã 楜ãã¿ã«ãªã£ãããç§ã¯ç«ã¡æ¢ãŸã£ãŠãã¿ãã¬ã«ã€ããŠèŠåããŸãã
ç§ã¯äœãããŸãããïŒ
è«ççã«èãããšããã¹ãŠãæ確ã«ãªããŸãã ã¯ã©ãã·ã¥ãæ¶ããã®ã§ãããã¯äœããå€æŽããããã§ãïŒãã®åã¯åçŸæ§ã100ïŒ ã ã£ãããïŒã åé¡ã¯ãäœãæ£ç¢ºã«å€ãã£ããã ãã§ããã
- ãã¥ãŒãäœæããåã«ã³ãŒããè¿œå ããŸãã
- NSLogãè¿œå ããŸãã
- ã¹ããªãŒã ãäžæåæ¢ããŸãã
- ãã©ã¡ãŒã¿ãŒãšããŠæž¡ãåã«ãã¯ã©ã¹å€æ°_widthã«ã¢ã¯ã»ã¹ããŸãã
- ....
ç§ãäœãå€ããããšãã§ããããŸã ããªããèããæã£ãŠãããªãã°-ããªãã¯æžãçããããšãã§ããŸãã 次ã«ãæšæž¬ãæ£ãããã©ããã確èªããŸãã ããããã»ãšãã©ã®å Žå-ã»ãšãã©;ïŒ
ãã¹ãŠã®ã¢ã€ãã ã¯ç°¡åã«ãã§ãã¯ãããŸãã ãã¹ãŠã®å€æŽãåé€ããå®éšãéå§ããŸããã
ã¹ããªãŒã ãäžæåæ¢ããŸãã
ããã§ã®ã¢ã€ãã¢ã¯éåžžã«åçŽã§ãã æãå¯èœæ§ãé«ã-ãšã©ãŒã¯ãã«ãã¹ã¬ãããåå ã§çºçããŸãã
ããã¯ãã§ãã¯ããã®ãæãç°¡åã§ãããNSLog 'aãªãã§ãã¬ãŒã¯ãã€ã³ããèšå®ããŸããã åã100ïŒ ã§ãã³ãŒãã¯åŒãç¶ãã¯ã©ãã·ã¥ããŸããã
ã¯ã©ã¹å€æ°_widthã«ã¢ã¯ã»ã¹ãããããã¥ãŒãäœæããåã«ã³ãŒããè¿œå ããŸãã
ãããã®ãã€ã³ãã®ã¢ã€ãã¢ã¯ãã³ãŒãçæã®ãæ©èœãã«ãããå¥è·¡çã«ãäºæããªãçµæãæãå¯èœæ§ããããŸãã
ã¿ã³ããªã³ã䜿çšãããã³ã¹ã¯ãªããå€æ°_widthã«ã¢ã¯ã»ã¹ã§ããè¿œå ã®ã©ã³ãã ã«çæãããã³ãŒãè¡ã¯çµæãçæããŸããã§ããã ã¢ããªã±ãŒã·ã§ã³ã¯çå®ã«ã¯ã©ãã·ã¥ããŸããã
NSLogãè¿œå ããŸãã
ããããããŸããããªãã¯æ¬æ°ã§ã¯ãããŸãããïŒã
çå£ã«å€æããŸããã NSLogã¯ã¯ã©ãã·ã¥ããæ²»çãããç¶ããŸããã å®å®ãã æž¡ããããã©ã¡ãŒã¿ãŒã«é¢ä¿ãªãã ããã«æ³šç®ãã¹ãæ©èœãçºèŠãããŸããã ãã©ã¡ãŒã¿ãŒãšããŠ_width ã _heightã䜿çšããŠããªããŠããã¢ããªã±ãŒã·ã§ã³ã¯åŒãç¶ãã¯ã©ãã·ã¥ããŸãã ã NSLogããªãå Žåã -ïŒidïŒinitWithFrameïŒã«æž¡ãããå€ã¯åããšã©ãŒã§ã¢ããªã±ãŒã·ã§ã³ãã¯ã©ãã·ã¥ãããŸãã ç¹ã«ã NSLogããã¥ãŒã®åé¢ã«é 眮ããå¿ èŠã¯ãªãããšãå€æããŸããã ããã¯ããã¥ãŒãäœæãããã¡ãœããã®æåã«é 眮ãããããã®ã¡ãœãããåŒã³åºãã¡ãœããã«é 眮ãããããŸãã¯...ãåŒã³åºãã¡ãœãããåŒã³åºãã¡ãœããã«é 眮ããããšãã§ããŸãã äž»ãªããšã¯ãäœæåã®ããšã§ãã
æåïŒ
ããã ãã§ãã åé¡ã¯ã解決ãããŸãããã ãããã«ãŒãæé€ãããã·ãã¥ã¬ãŒã¿ã§ã¢ããªã±ãŒã·ã§ã³ãå·éã«ãã¹ãããããšã劚ãããã®ã¯äœããããŸããã ãŸããå€ãã®äœæ¥ãå¿ èŠã§ãããããã«åãæ¿ããå¿ èŠããããŸããã
åé¡ã¯è§£æ±ºããŸãããïŒ
ãã®è³ªåã¯ãç§ãäž»ãªãããžã§ã¯ããçµããŠããéãäœæ©ãç§ãæ©ãŸããŸããã åé¡ã¯è§£æ±ºãããŠããŸããããããšãNSLogã® ãæ²»çãã¯ããããžã§ã¯ãããªãªãŒã¹ãããã®ãåŸ ã¡ãåŸ ã£ãŠãã倧ããªåé¡ã®çç¶ãåãé€ãã ãã§ããïŒ ãããŠã誰ãããããå¿ããŠããã®ä¿®æ£ã®ããã«AppStoreã§ã®éä¿¡ã1é±éåŸ ã€å¿ èŠããããŸããããã¯ããèªäœãæ瀺ããã·ãã¥ã¬ãŒã¿ã§ã¯ãªããã¹ãŠãå£ããŠç Žå£ãå§ããŸããïŒ
éæ³ïŒ
äžæ¹ã§ã¯ãåé¡ãã³ãŒãã«ããããšãç解ããŸããã ãããŠãã»ãšãã©ã®å Žåãããã¯UIKitã©ã€ãã©ãªãšã©ãŒã§ã¯ãããŸããã ããªãã¿ã®ããã°ã©ããŒã¯ããèšã£ã-ããªãã®ã³ãŒãã®åé¡ãæ¢ããŠãã ããã ãããŠãç§ã¯åœŒãã«åæããŸããã ãããã圌女ãæ¢ãæ¹æ³ã¯ïŒ ãããžã§ã¯ãã¯ããªã倧ãããåé¡ãè€æ°ã®è¡ã«ããŒã«ã©ã€ãºããããšãããšå€±æããŸãã ç§ã¯ãã¹ãŠãèœãšãããéæ³ããšèšããåŸç¹ãããã£ãã ãããŠããããžã§ã¯ãã§éæ³ã®æèŠã§çããŸãã ãããŠãããã¥ã¡ã³ãã«ãããšãéæ³ã®ä»çµã¿ãç¥ã£ãŠããã°èå³ã倱ãããããããã¹ãŠãæ®éã«ãªããŸãã
ããã«ãããããããåé¡ã®åå ã«å¯Ÿããé¢å¿ãå§åãããç§ã¯æãå§ããŸããã ãã®æãŸã§ã«ãç§ã®èãã¯ç解ããããšãã欲æ±ãäžå¿ã«å±éããŸãããNSLogã®èå³æ·±ããšããã¯äœã§ãããããã°ã©ã ãã¯ã©ãã·ã¥ããã®ãã©ã®ããã«ãæ²»ããã®ã§ããããã ç§ãšéçºè ã®ããŒã«ã«ãã£ããã®äž¡æ¹ã§å€ãã®ãªãã·ã§ã³ããããŸããã æåŸã«ã ã¯ã©ãã·ã¥ã®æãå¯èœæ§ã®é«ãåå ã¯ã¹ã¿ãã¯ã¹ã¿ãã¯ã®åé¡ã§ããããšã«åæããŸããã ãã®åãã¯ãããã€ã¹ã®å®å®ããåäœã®çç±ã説æããŸããã§ããããã©ããããå§ããå¿ èŠããããŸããã ããããã¹ã¿ãã¯ã«ç®ãåããåã«ãçµå±ã®ãšããããã®NaNãã©ãã§çºçããã®ããææ¡ããããšããŸãããïŒ ã ã¡ããã©ãã®ãšããããªãã¿ã®ããŒã¯ããã¬ãŒã¯ ã dtraceã®ã¯ãŒã«ããå·Šå³ã«ç©æ¥µçã«äŒããŠããŸããã ãããŠãæ°æéåŸããã®ããŒã«ã䜿çšããŠã転åã®åå ã®æ€çŽ¢ããããã«æžããããšãã§ããŸããã
Dtraceããžãã¯
ãã®ç¬éãç§ãæã£ãŠããã®ã¯ãã¯ã©ãã·ã¥ãµã€ããžã®ã¹ã¿ãã¯ãã¬ãŒã¹ã ãã§ããã åé¡ã¯åœŒã®äžã®ã©ããã«ãã£ãã®ãããããšãäœããå®å šã«èœã¡ããšããäºå®ã«ã€ãªãã£ãã
#4 0x01d8b04a in -[CALayer setBounds:] () <---- NaN lives here #5 0x02d1d714 in WebCore::TileGrid::updateHostLayerSize() () #6 0x02d1af26 in WebCore::TileCache::TileCache(WAKWindow*) () #7 0x02d52507 in -[WAKWindow initWithLayer:] () #8 0x002ee5e9 in -[UIWebTiledView initWithFrame:] () #9 0x001af9b5 in -[UIWebDocumentView initWithWebView:frame:] () #10 0x001af89e in -[UIWebDocumentView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:] () #11 0x0012cb6a in -[UITextView commonInitWithWebDocumentView:isDecoding:] () #12 0x0012bf0e in -[UITextView initWithFrame:] ()
dtraceçšã®æ¯èŒçåçŽãªã¹ã¯ãªããã䜿çšããŠãäžéãªNaNã衚瀺ãããå ŽæãèŠã€ããããšãã§ããŸããã ãã©ã¡ãŒã¿ãŒã¯ãŸãã«æåŸã«ã倱ããããããšãå€æããŸããã
QuartzCore`-[CALayer setBounds :] <------ (0, 0, NaN, height) WebCore`WebCore::TileGrid::updateHostLayerSize()+0x140 WebCore`WebCore::TileCache::TileCache(WAKWindow*)+0x1c6 WebCore`-[WAKWindow initWithLayer:]+0xd7 UIKit`-[UIWebTiledView initWithFrame:]+0xec " <------ (0, 0, width, height)" UIKit`-[UIWebDocumentView initWithWebView:frame:]+0xb5 UIKit`-[UIWebDocumentView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]+0xfe UIKit`-[UITextView commonInitWithWebDocumentView:isDecoding:]+0x198 UIKit`-[UITextView initWithFrame:]+0x70 " <------ (0, 0, width, height)"
ã©ããã ã©ãããåé¡ã¯ç§ãã¡ã®ã³ãŒãã«ã¯ãªãããã§ãïŒ èªå·±éèŠæ§ã®æèŠãé«ãŸããç§ã¯ãã§ã«ãã°å ±åãã¢ããã«ã«éãæºåãããŠããŸãã ãããŠãç§ã¯ç»å±±ããŠãããã§ã¹ã¿ãã¯ãã©ã®ããã«åããŠãããã芳å¯ããŸã ã
ãã¿ãã¬æ³šæïŒ
ããã§ããã®åé¡ãèªåã§è§£æ±ºããããšããŠããã®ã§ããã°ããã®èšäºãèªãã®ãããããšãã§ã;ïŒèªåã§ãããç解ããããšããŠããŠãåé¡ã¯ã¹ã¿ãã¯ã§ã®äœæ¥ã«ãããšèããŠãã人ããŸãã¯ãã®éã®å Žåãåé¡ã¯ã¹ã¿ãã¯ã«ãŸã£ããé¢ä¿ãªããå°ããªãã¿ãã¬ã ãšæã
ç§ãèªãŸãªãã§ãã ããïŒ
åé¡ã¯ã¹ã¿ãã¯é¢é£ã§ã¯ãããŸãã*
ã¹ã¿ãã¯ã®ãã©ãã«ïŒ
ã¹ã¿ãã¯ã§çŸåšäœãèµ·ãã£ãŠããããXcodeã§ç¢ºèªããã«ã¯ã©ãããã°ããã§ããïŒ ã©ã®ãã©ã¡ãŒã¿ãŒãé¢æ°ã«æž¡ãããŸããïŒ ãããã¯ã©ã®ãããªã«ãŒã«ã§ã©ã®ããã«éä¿¡ãããŸããïŒ ãããŠãã¹ã¿ãã¯ãéããŠïŒ
ããã¯ãåœæç§ãçãããªãã£ã質åã®ã»ãã®äžéšã«ãããŸãããã darkprogerã¯åã³å©ããŸãã ïŒäžè¬çã«ãVovaã¯éåžžã«ç±å¿ã«ãèŸæ±åŒ·ãè³ãåŸãããŸãã¯èãããµããããŠãç§ã®ãã¹ãŠã®åŠæ³çã§ãããåå ãšçµæã®ããŸããªãã¢ã€ãã¢;ïŒéåžžã«äŸ¿å©ãªããã¥ã¡ã³ãã«éŒ»ãçªã£èŸŒãã ãããŠãããå ·äœçã«ã¯ããã®ç¹å®ã®éšåã« ã æè¡æ å ±ãç°¡åã«èªãã åŸãã¹ã¿ãã¯ã®å 容ã衚瀺ããããšãã§ããŸããã
ãã ãããããã®ããŒã¿ã¯ãäœãèµ·ãã£ãŠããã®ããç解ããã®ã«åœ¹ç«ã¡ãŸããã§ããã å®éã«ã¯ãã¹ã¿ãã¯ã¯äž¡æ¹ã®ã±ãŒã¹ã§åäžã§ããã éãã¯ãããŸããã ã¡ã¢ãªå ã®ãã¹ãŠã®å€ã¯ãŸã£ããåãã§ãããã¹ã¿ãã¯ã¬ãžã¹ã¿ã¯åãã¡ã¢ãªã¢ãã¬ã¹ãåç §ããŠããŸããã æ°åãã§ãã¯ããã¢ããªã±ãŒã·ã§ã³ãåèµ·åããã¡ã¢ãªã¢ãã¬ã¹Â±ããã§ãã¯ããŸããã ãã¹ãŠãäžèŽããŸããã
次ã¯ïŒ
å ã»ã©èšã£ãããã«ãã¡ã¢ãªã¢ãã¬ã¹ã®ãã¹ãŠã®å€ã¯äžèŽããŸãã ããããäœãããŸã ç°ãªã£ãŠããŸããã äœããéãã 確ãã«ããã®ãäœããã®æ€çŽ¢ã¯äžæçã«ããã¯ã°ã©ãŠã³ãã«ãã§ãŒãã€ã³ããŸãã-äžéãªNaNãèŠã€ããŸããã
FPUããã»ããµã®stã¬ãžã¹ã¿ã®1ã€ã«ãããŸããã ç§ã¯ãããã®ã¬ãžã¹ã¿ãäœã§ãããç¥ããªãã£ãã®ã§ãIntelã®ããã¥ã¡ã³ãã調ã¹ãªããã°ãªããŸããã§ããã ããã¥ã¡ã³ãã«ãããšãã¬ãžã¹ã¿ã°ã«ãŒãst0-st7ã¯FPUã®åŸªç°ã¹ã¿ãã¯ã§ããããããä»ããŠæµ®åå°æ°ç¹æŒç®ãåŠçããããã»ããµåœä»€ãæ©èœããŸãã ãã¹ãŠãçä»ãå§ããŸããã 誰ããNaNå€ãFPUã®ã¹ã¿ãã¯ã«é 眮ããæäœã®çµæãšããŠãããåé€ããŸãã 誰ããããè¡ãã®ããç¥ãã ãã§ãã
çŽ1æéãçªç¶çŸããéæ³ã§æ®ºããŸãããããã¯ãåçŽã«ãææžã泚ææ·±ãèªãã§ã説æãããŸããã ãã®éæ³ã¯æ¬¡ã®ããã«çŸããŸããã ã fstp ãåœä»€ã¯æ£ããæ©èœããŸããã§ãã ïŒ190ããŒãžïŒã ã³ãã³ãã¯æ¬¡ã®æäœãå®è¡ããå¿ èŠããããŸãïŒ st0ã¹ã¿ãã¯ã®FPUã®å é ããçŸåšã®å€ãååŸããæå®ãããã¢ãã¬ã¹ïŒç§ã®å Žåã¯$ ebp-0x64 ïŒã«æžã蟌㿠ãFPã¹ã¿ãã¯ããå€ãããã·ã¥ããŸãã
ãããããã®åœä»€ãå®äºããŠåããŠã $ ebp + 0x64ã¯ãå¿ èŠãªå€320ã®ä»£ããã«0ã«ãªããŸããã
fstpã³ãã³ããå®è¡ããåã«
fstpã³ãã³ããå®è¡ããåŸ
æ°é ãã®ããå°é家ã¯ãããããã§ã«åé¡ãèªèããŠããŸãã ãã®åäœãèªåã§ç¢ºèªããã人ã¯ããã¹ããããžã§ã¯ããããŠã³ããŒãããŠã WebCore :: TileGrid :: updateHostLayerSizeïŒïŒé¢æ°ã«ãã¬ãŒã¯ãã€ã³ãã眮ãããšãã§ããŸãã ãã®äžã«é©åãªäœåãèŠã€ããã®ã«ååç°¡åã§ãã ç§ã®ãã©ã°ã€ã³ã®çç±ã«åã«èå³ããã人ã¯èª°ã§ã-ã¹ãã€ã©ãŒãéããŠãã ããã
ãããŠã圌ãã¯èšãã$ ebp-0x64ã¯æ¬ç©ã§ã¯ãªãïŒ
çç±ã¯ããŒã¿åã§ãã fstpã³ãã³ãã¯40ãããã®æµ®åå°æ°ç¹æ°ãã¡ã¢ãªã«æžã蟌ã¿ãŸããããã¯äžè¬ã®äººã
ã§ã¯long doubleãšåŒã°ããŸãã ãã®äŸã§ã¯ããããã¬ãŒã§æ£ããã¢ãã¬ã¹ãèŠãŠããŸããã 40ãããã§ã¯ãªã32ããããã衚瀺ããŠããŸããã æ£ããããŒã¿åãæå®ãããšããã¹ãŠãé©åã«é
眮ãããŸããã ããã¥ã¡ã³ãããã泚ææ·±ãèªãã å Žåãæ€çŽ¢ã«1æéåããããšã©ãŒã¯çºçããªãã£ãå¯èœæ§ããããŸãã é埳ïŒããã¥ã¡ã³ããèªãã§ãã ããã 䟿å©ã§æéãç¯çŽã§ããŸãã
ã¹ã¿ãã¯ãªãŒããŒãããŒïŒ
fstpãšfldãç解ããåŸã ç§ã¯åã³éããæ¢ãå§ããŸããã ãããŠããã®çç±ãã¹ã¿ãã¯ã«é¢é£ããŠããªãããšã確信ããŠããã®ã§ãããã»ããµã¬ãžã¹ã¿ã®å€ã«éäžããŸããã ãããŠãéãããããŸããã ãããŠã NaNãã©ãããæ¥ãã®ãããæããã«ãªããŸããã æåã«ã $ ftagã¬ãžã¹ã¿ã調ã¹ãŸããããã®å€ã¯ãFPUã¬ãžã¹ã¿ã¹ã¿ãã¯ïŒããŒãž182ïŒã«äœãåé¡ãããããšãããã«æããŠãããŸããã
ãã¡ãããããã¯åã«$ st0- $ st7ãèŠãã ãã§èŠ³å¯ã§ããŸããã $ ftagã䜿çšãããšãã¬ãžã¹ã¿ã®çŸåšã®ç¶æ ïŒäœ¿çšäžã䜿çšäžã空ïŒã確èªã§ããŸãã ãã®äŸã¯ããã¹ãŠã®ã¬ãžã¹ã¿ãããžãŒïŒæå¹ïŒã§ããããã®ãã¡ã®1ã€ã ããç¹å¥ãªãã®ãæã£ãŠããããšã瀺ããŠããŸãã
ããããæåŸã«ã $ fstatã¬ãžã¹ã¿ïŒx87 FPUã¹ããŒã¿ã¹ã¬ãžã¹ã¿ã178ããŒãžïŒã®å€ãèŠããšãã«ãéæ³ã«é¢ãããã¹ãŠã®è³ªåãææãããŸããã
ã¹ã¿ãã¯ãªãŒããŒãããŒ
FPUããã»ããµã¬ãžã¹ã¿ã®ã¹ã¿ãã¯ãªãŒããŒãããŒã å®éã«ãã¹ã¿ãã¯ãªãŒããŒãããŒèªäœã¯äŸå€ãåŒãèµ·ããããäŸå€ãçºçããããšãå¶åŸ¡ã¯ãŒãã«ãã©ã°ãèšå®ããã ãã§ãã
ç¡å¹æäœäŸå€ããã¹ã¯ãããŠããå Žåãx87 FPUã¯ãå®è¡ãããåœä»€ã«å¿ããŠãæµ®åå°æ°ç¹ãæŽæ°ããŸãã¯ããã¯10é²æŽæ°ã®äžå®å€ãå®å ãªãã©ã³ãã«è¿ããŸãã ãã®å€ã¯ãåœä»€ã§æå®ãããå®å ã¬ãžã¹ã¿ãŸãã¯ã¡ã¢ãªäœçœ®ãäžæžãããŸãã
ãã ããç¡å¹ãªç¶æ ã®ã¬ãžã¹ã¿ã®å€ã䜿çšãããšãã¡ã¢ãªå ã«ãã£ããCALayerãäœæãããšãã«ãã©ã¡ãŒã¿ãšããŠå«ãŸããNaNãååŸãããŸãã
ã ãããç§ã¯åé¡ã®æäœã¬ãã«ã«è¡ããŸããã ããã°ã©ã å ã§éæ³ã®NaNãã©ãããæ¥ãããFPUã¹ã¿ãã¯ã¬ãžã¹ã¿ã®ã¹ã¿ãã¯ãªãŒããŒãããŒã«ã€ããŠæ£ç¢ºã«ç¥ã£ãŠããŸããã ããã¯çãã§ããããããèµ·ããå Žæãšææã¯ç§ã«ã¯ãããŸããã§ããã UIKitãå°ç¡ãã«ãããšããèããåã³é ã«æµ®ãã³ãŸããã ã蚌æ ãªãã«äž»åŒµããããšã¯ã§ããŸããã äžæ¹ã§ãã³ãŒããFPUã¹ã¿ãã¯ãªãŒããŒãããŒãåŒã³åºãæ¹æ³ãç¥ããŸããã§ããïŒãã®æ¥ã¯ãããåŠã³ãŸããïŒã
ç¯äºº
ããã«ãé¢ããããæ©èœã¯ããŒã«ã©ã€ãºãããŠããŸãããããããçºçãããã¹ãŠã®åå ã§ããã ããã«åœŒã¯ãèµ·ãããã¹ãŠã®ç¯äººã§ãïŒ
// ACLabel : UILabel - (CGFloat)resizeToContents { CGSize size = [self.text sizeWithFont:self.font forWidth:self.frame.size.width lineBreakMode:self.lineBreakMode]; CGRect oldFrame = self.frame; oldFrame.size.height = size.height; self.frame = oldFrame; return size.height; }
æããã®ãèŠã€ããããšããŠããŸããïŒ ãã£ãŠã¿ãŠã ç§ãè©ŠããŸããã é·ããŠéå±ã ã¡ãœãããæžãçŽããååãå€æŽããŠãã«ããŽãªã«ããŸããã ãããŠããã¹ãŠãç¡é§ã«ã ãã®ã¡ãœããã¯ãFPU Stack'eã«ãŽããæ®ããŸããã ããã«ãéæ³ã¯æ°ãã圢ããšã£ãŠããŸãã åãã¡ãœããã¯ãã¹ã¿ãã¯å ã«æ¯åãŽããæ®ããŸããã ã€ãŸããéåžžãã¡ãœãããã¯ã¹ã¿ãã¯ã®æäžéšããå€ããååŸãããæã«ã¯åœŒã¯ãããå®å šã«å¿ããŠç¡èŠããã¯ã©ãã·ã¥ãè¿äŒŒããŸãã ãã®ã³ãŒãã®äœãåé¡ã«ãªã£ãŠããŸããïŒ
IA-32ã¢ãŒããã¯ãã£ãŒã«åºã¥ãã·ã¹ãã ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ãæµ®åå°æ°ç¹å€ãè¿ãé¢æ°ãåŒã³åºããšãè¿ãããæµ®åå°æ°ç¹å€ã¯æµ®åå°æ°ç¹ã¹ã¿ãã¯ã®æäžéšã«ãããšæ³å®ãããŸãã æ»ãå€ã䜿çšãããªãå Žåãã³ã³ãã€ã©ã¯ãæµ®åå°æ°ç¹ã¹ã¿ãã¯ãæ£ããç¶æ ã«ä¿ã€ããã«ãæµ®åå°æ°ç¹ã¹ã¿ãã¯ããå€ããããããå¿ èŠããããŸãã
ãã©ã®ããã«ç§ã¯ããããããšããïŒãïŒãµãŒã«ã¹ïŒã ããã§ã眪æªæãã¯ãã«ãUIKitããããããŠåã³ã³ã³ãã€ã©ã«ã¹ã ãŒãºã«ç§»è¡ããŸãã ã çµå±ã®ãšãããFPUã¹ã¿ãã¯ããå€ãåé€ããå¿ èŠããããŸãã å¿ é ã§ãããããã§ã¯ãããŸããã ããããããã¯...ãããåžžã«ã§ã¯ãããŸããã ã ãããã€ïŒ
åå©ãžã®äžæ©
ãããŠãç§ã¯ããªãã®ããã«ãã®è³ªåã«çããŸãã ããããæåã«ããäŸã«ç€ºãããŠããè¡ã¯åãã§ããïŒããšããå°ããªè³ªåããããŸãã
// // â1 [obj someMethod]; // â2 [obj perfromSelector:@selector(someMethod)];
ãã®ãããªç°¡åãªè³ªåã 圌ã¯ã€ã³ã¿ãã¥ãŒã§ããå°ããããŸãã ãããŠãããªãã¯åœŒããç°ãªãæ¹æ³ã§åãããšãã§ãããšããã«èšãããšããã§ããŸããã çµå±ã®ãšãããå®éã«ã¯ãããã¯ãŸã£ããåãåŽé¢ãã¥ãŒã«ãããŸããã 確ãã«ããããã®ã¡ãœãããæ»ããšããäºå®ããªãããããã®äŸã¯å€§å¹ ã«ç°¡ç¥åãããŠããŸãã ããããvoidãè¿ãããšãæå³ããŸã ã ãããŠãã¡ãœãããidãŸãã¯intãŸãã¯floatãè¿ããå Žåã äœãå€ãããŸããïŒ
ããªãã質åãžã®çããèããŠããéãç§ã¯ããã¥ã¡ã³ãããå°ãæç²ããŸãïŒ
performSelectorïŒã¡ãœããã¯ãaSelectorã¡ãã»ãŒãžãçŽæ¥åä¿¡è ã«éä¿¡ããããšãšåçã§ãã ããšãã°ã次ã®3ã€ã®ã¡ãã»ãŒãžã¯ãã¹ãŠåãããšãè¡ããŸãã
id myClone = [anObject copy]; id myClone = [anObject performSelector:@selector(copy)]; id myClone = [anObject performSelector:sel_getUid("copy")];
ã ãªããžã§ã¯ã以å€ã®ãã®ãè¿ãã¡ãœããã®å Žåã¯ãNSInvocationã䜿çšããŸãã
ãªãŒãã倪åã§ããå Žåããã¡ããã圌ãã¯ããã«æ°ã¥ããŸãã ããã¥ã¡ã³ãã¯ãã¡ãœãããçªç¶id以å€ã®äœããè¿ãå¿ èŠãããå Žåã NSInvocationã䜿çšããå¿ èŠãããããšãéåžžã«æ確ã«ç€ºåããŠããŸãã ãããããªããžã§ã¯ããè¿ããªããŠãããã¹ãŠãæ©èœãããšèšããŸãã ãšã«ããããŸããããŸããã ãã®äžéãªæ¥ãŸã§ã
å©ç
ãããããå€ãã¯ãã§ã«ããã§äœãèµ·ãã£ãŠããããæšæž¬ããŠããŸãã ãã¹ãŠãéåžžã«ç°¡åã§ãïŒç¹ã«ãèšäºãèªãã åŸããŸãã¯dtraceããããã¬ãŒãããã¥ã¡ã³ãã®æãäžããªã©ã§2æ¥éåã®ã²ãŒã ïŒã
- ã³ã³ãã€ã©ãŒã¯ã floatãè¿ãã¡ãœãããæ€åºããã¡ãœãããåŒã³åºããåŸãFPUã¹ã¿ãã¯ããæ»ãå€ãåé€ããã³ãŒããæ£ããçæããŸãã
- performSelectorã¡ãœããã䜿çšããå Žåãã³ã³ãã€ã©ã¯ã¡ãœãããè¿ããã®ãç¥ããªããããããã°ã©ããŒã®èª æãæãã§ããŸããã¡ãœããã¯idãè¿ããšèããŠããŸãã
- ã³ãŒããïŒè¿ãããçµæã䜿çšããªãå Žåã§ãïŒ floatãè¿ãã¡ãœããã«performSelectorã䜿çšããå Žåãã³ã³ãã€ã©ãŒã¯FPUã¹ã¿ãã¯ããæ»ãå€ãåé€ããå¿
èŠãããããšãèªèããŸããã ãã®ããã performSelectorãä»ããŠreturn-floatã¡ãœãããåŒã³åºããã³ã«ãFPUã¹ã¿ãã¯ã¬ãžã¹ã¿ã®1ã€ããè©°ãŸã£ãŠããŸããã
- ãã®ãããª8åã®åŒã³åºãïŒ8ã€ã®stã¬ãžã¹ã¿ïŒã®åŸãããã»ããµã¯ã¹ã¿ãã¯ããã£ã±ãã§ããããšã瀺ããã©ã°ãèšå®ããäžéšã®éåžžã®æµ®åå°æ°ç¹æŒç®ã¯çµæãšããŠNaNãè¿ãå§ããŸãã ããã¯ãé çªã«ãäœã«ã€ãªãããŸãã æç«ãããªãã®èäžã®åŸãã§èµ°ãããšãã§ããç¹ãŸã§ã
é埳 ïŒããã¥ã¡ã³ãã泚ææ·±ãèªãã§ãã ããã ææžã«åããäœããæ©èœããå Žåãããã倧ããªåé¡ãåŒãèµ·ãããªãããšãæ¬åœã«èŠã€ããªãã§ãã ããã
NSLog
ãããããããããã§ã¯NSLogã®ç¶æ³ã¯ïŒã NSLogããã®åé¡ãã解決ãããã®ã¯ãªãã§ããïŒã
NSLogã¯æµ®åå°æ°ç¹æŒç®ã䜿çšããŸãã ããã«ãpokeã¡ãœããã䜿çšãããšããã®æäœã«ã¯FPUã¹ã¿ãã¯ã«2ã€ã®ã¬ãžã¹ã¿ãå¿ èŠã§ããããšãããããŸããã FPUã¹ã¿ãã¯ã¯ãå®å šã«èªã¿èŸŒãŸããŠããå Žåãé©åãªãªãŒããŒãããŒãã©ã°ãèšå®ããŸãã ãŸããã¹ã¿ãã¯ããå€ãåé€ããæäœã§ã¯ãã¹ã¿ãã¯ã¬ãžã¹ã¿ã®1ã€ããèªç±ã«äœ¿çšå¯èœããšããŠããŒã¯ããŸãã
// Tag word (state of st0 - st7 registers) // 00 - Used // 10 - Invalid // 11 - Unused // before NSLog st0 st1 st2 st3 st4 st5 st6 st7 10 00 00 00 00 00 00 00 // After NSLog st0 st1 st2 st3 st4 st5 st6 st7 11 11 00 00 00 00 00 00
ãã®ããã«ãç¡å¹ãªç¶æ ã¯ã¬ãžã¹ã¿st0ããæ¶ããŸã ãããã¯ãå€ãååŸããããšããŠã誰ãNaNãåãåãããããããã©ã¡ãŒã¿ãšããŠUITextViewã«ãã以äžæž¡ããªãããã§ã ã
ãããã£ãŠã NSLogã¯åé¡ã解決ããŸããã 圌ã¯åœŒå¥³ãããå°ãé·çããããã³ãŒãåãçªç¶ããŸã§ã¢ããªã±ãŒã·ã§ã³ã®æ»ãé ãããŸããã
ããããã®ãããªãéæ³ãã§ãã ããã§å±¥æŽæžã«å®å šã«è¡ãæžãããšãã§ããŸã
ã¯ã©ãã·ã¥ãšNSLogãæ±ã£ãŠããŸãã å®äŸ¡ã§ãã é·å¹Žã®çµéšã 100ïŒ ä¿èšŒã
èå³æ·±ãã ãã§ãªããããã€ãã®å Žæã§ãæçã ã£ãããšãé¡ã£ãŠããŸãã
PSç§ã®èãã®æµããå©ããŠèããŠãããdarkprogerãšvixentaelã«åã³æè¬ããŸãã