karelia / CurlHandle

Cocoa Class wrapping libcurl
54 stars 21 forks source link

error: unexpected '@' in program #8

Closed ryandesign closed 11 years ago

ryandesign commented 11 years ago

curlhandle 3.1.1 fails to compile in MacPorts on Lion with Xcode 4.3.3 and its clang compiler, which is:

$ clang -v
Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

The error is:

/Volumes/Data/macports/lion/var/macports/build/_Volumes_Data_macports_dports_devel_curlhandle/curlhandle/work/CurlHandle-3.1.1/CURLHandleSource/CURLFTPSession.m:353:40: error: unexpected '@' in program
    return [self executeCustomCommands:@[from, to]
                                       ^

It builds fine on OS X 10.8.2 with Xcode 4.6 and its clang, which is Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn).

ryandesign commented 11 years ago

I think this means you're using the new Objective-C array literals syntax introduced in Apple LLVM 4.0 or official clang 3.1. Can your code be rewritten to support older compilers? From that page, the new way, which you're using, is like this:

NSArray *elements = @[ @"H", @"He", @"O", @"C" ];

Whereas the old way, which would be equivalent except compatible with older compilers, is like this:

id objects[] = { @"H", @"He", @"O", @"C" };
NSArray *elements = [NSArray arrayWithObjects:objects count:4];
cooljeanius commented 11 years ago

(It also fails on older versions of OS X, too, but I'm guessing you guys probably don't support those anymore...)

ryandesign commented 11 years ago

There seems to be just this one use of array literals, so I think this patch would fix it:

--- CURLFTPSession.m.orig   2012-11-29 08:34:27.000000000 -0600
+++ CURLFTPSession.m    2013-03-11 20:07:51.000000000 -0500
@@ -350,7 +350,8 @@
 {
     NSString *from = [NSString stringWithFormat:@"RNFR %@", [fromPath lastPathComponent]];
     NSString *to = [NSString stringWithFormat:@"RNTO %@", toPath];
-    return [self executeCustomCommands:@[from, to]
+    id commands[] = {from, to};
+    return [self executeCustomCommands:[NSArray arrayWithObjects:commands count:2]
                            inDirectory:[fromPath stringByDeletingLastPathComponent]
          createIntermediateDirectories:NO
                                  error:error];
ryandesign commented 11 years ago

It compiles, at least, and is what we're now using in MacPorts:

https://trac.macports.org/browser/trunk/dports/devel/curlhandle/files/patch-CURLFTPSession.m.diff?rev=103987

mikeabdullah commented 11 years ago

OK, I've updated our master branch not to use array literals.