You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2014/09/01 22:04:52 UTC

git commit: THRIFT-2676 Avoid 'i386' name collision in generated Cocoa/objc code

Repository: thrift
Updated Branches:
  refs/heads/master b191ecc8d -> e26a19bba


THRIFT-2676 Avoid 'i386' name collision in generated Cocoa/objc code

This fixes a bug in the cocoa code generator where the variable
used by a for-loop can conflict with a built-in symbol when the
temporary variable counter is equal to 386. The generated variable
name, 'i386', conflicts with a macro built-in to the compiler.

I can reproduce this bug on Xcode 5 as well as Xcode 6. It appears
to only affect iOS projects, not OS X projects.

My fix simply prefixes the generated variable with 'idx' instead of 'i'.

This test code demonstrates the problem, regardless of Thrift codegen.

    int i386 = 42;
    printf("foobar %d\n", i386);

Which results in the following compiler error:

/Users/keith/Desktop/ReservedSymbolTest/ReservedSymbolTest/ViewController.m:22:7: error: expected identifier or '('
  int i386 = 99;
      ^
<built-in>:143:14: note: expanded from here
             ^
1 error generated.


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/e26a19bb
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/e26a19bb
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/e26a19bb

Branch: refs/heads/master
Commit: e26a19bba0a91e31d0ec8092940992534426a26f
Parents: b191ecc
Author: Keith Lazuka <kl...@acompli.com>
Authored: Mon Aug 25 15:31:49 2014 -0700
Committer: Roger Meier <ro...@apache.org>
Committed: Mon Sep 1 22:04:36 2014 +0200

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_cocoa_generator.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/e26a19bb/compiler/cpp/src/generate/t_cocoa_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_cocoa_generator.cc b/compiler/cpp/src/generate/t_cocoa_generator.cc
index 8f30ae9..20973a3 100644
--- a/compiler/cpp/src/generate/t_cocoa_generator.cc
+++ b/compiler/cpp/src/generate/t_cocoa_generator.cc
@@ -2098,7 +2098,7 @@ void t_cocoa_generator::generate_serialize_container(ofstream& out,
     indent(out) << "id " << key << ";" << endl;
     indent(out) << "while ((" << key << " = [" << iter << " nextObject]))" << endl;
   } else if (ttype->is_list()) {
-    key = tmp("i");
+    key = tmp("idx");
     indent(out) << "int " << key << ";" << endl;
     indent(out) <<
       "for (" << key << " = 0; " << key << " < [" << fieldName << " count]; " << key << "++)" << endl;