groue / GRMustache

Flexible and production-ready Mustache templates for MacOS Cocoa and iOS
http://mustache.github.com/
MIT License
1.44k stars 190 forks source link

appledoc crashes in initialize metthod in GRMustacheImplicitIteratorExpression.m #84

Closed snowflake closed 10 years ago

snowflake commented 10 years ago

appledoc is crashing in GRMustacheImplicitIteratorExpression.m

I have filed a bug report at

https://github.com/tomaz/appledoc/issues/483

The offending code is here:

+ (void)initialize                                                              
{                                                                               
    instance = [[self alloc] init];  // <-- crashes here                                             
}         

The crash only seems to happen on OSX 10.8.5 compiled with Xcode Version 5.1.1 (5B1008) as others have not reported a crash.

I cannot see any problems with the code, but it just does not work.

Here is a suggested patch:

diff --git a/src/classes/Compiling/Expressions/GRMustacheImplicitIteratorExpression.m b/src/classes/Compiling/Expressions/GRMustacheImplicitIteratorExpression.m
index b28fc78..ffe049e 100644
--- a/src/classes/Compiling/Expressions/GRMustacheImplicitIteratorExpression.m
+++ b/src/classes/Compiling/Expressions/GRMustacheImplicitIteratorExpression.m
@@ -27,13 +27,12 @@ static GRMustacheImplicitIteratorExpression *instance;

 @implementation GRMustacheImplicitIteratorExpression

-+ (void)initialize
-{
-    instance = [[self alloc] init];
-}

 + (instancetype)expression
 {
+    if(instance == nil){
+        instance = [[GRMustacheImplicitIteratorExpression alloc] init];
+    }
     return instance;
 }

The only problem with it is that expression must be the first method called in the class.

groue commented 10 years ago

Hi @snowflake Are you able to reproduce the crash outside of AppleDoc?

snowflake commented 10 years ago

Are you able to reproduce the crash outside of AppleDoc?

No. Appledoc is the only app I know of that uses GRMustache.

groue commented 10 years ago

Hm. That's unfortunate. I mean: the line that crashes is very innocent. Upon further investigation, done by you or by @tomaz, I'm reluctant to consider that the issue belongs to GRMustache. I thus consider https://github.com/tomaz/appledoc/issues/483 the only relevant issue. Please open a new GRMustache issue when the responsibility has been elucidated.

snowflake commented 10 years ago

I suspect that the bug is due to an obscure operating system bug which Apple have quietly fixed in Mavericks. I accept that you want to close this issue, and I will just have to apply the patch locally until I get Mavericks or Yosemite.

Using the debugger, I established that the alloc and init were being applied to a self which was nil.

groue commented 10 years ago

Please, I beg you, put your comments in the appledoc issue. I'm being nice because I'm answering you. Yet the real repo with the real issue is Apoledoc. Please show me you understand.