You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2014/08/26 01:05:00 UTC

[jira] [Commented] (THRIFT-2676) Cocoa code generator emits reserved symbol, 'i386'

    [ https://issues.apache.org/jira/browse/THRIFT-2676?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14109933#comment-14109933 ] 

ASF GitHub Bot commented on THRIFT-2676:
----------------------------------------

GitHub user klazuka opened a pull request:

    https://github.com/apache/thrift/pull/202

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

    [THRIFT-2676](https://issues.apache.org/jira/browse/THRIFT-2676)
    
    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 = 42;
          ^
    <built-in>:143:14: note: expanded from here
                 ^
    1 error generated.
    ```

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/klazuka/thrift THRIFT-2676-cocoa-gen-name-collision

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/202.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #202
    
----
commit 4fc71285052ab04998d990a5de6b071ff53f3c47
Author: Keith Lazuka <kl...@acompli.com>
Date:   2014-08-25T22:31:49Z

    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.

----


> Cocoa code generator emits reserved symbol, 'i386'
> --------------------------------------------------
>
>                 Key: THRIFT-2676
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2676
>             Project: Thrift
>          Issue Type: Bug
>          Components: Cocoa - Compiler
>         Environment: Xcode 5 (iOS)
> Xcode 6 (iOS)
>            Reporter: Keith Lazuka
>
> The Cocoa code generator has a bug where it can generate a local variable that conflicts with a symbol defined in the iOS SDK. Specifically, it happens when the temporary variable counter reaches the value `386` when emitting an index variable for a for-loop in `t_cocoa_generator::generate_serialize_container()`. The offending symbol is `i386` which apparently is #define'd to equal `1` somewhere in the iOS toolchain.
> This test code demonstrates the problem, regardless of Thrift codegen.
> {noformat}
>     int i386 = 42;
>     printf("foobar %d\n", i386);
> {noformat}
> Which results in the following compiler error:
> {noformat}
> /Users/keith/Desktop/ReservedSymbolTest/ReservedSymbolTest/ViewController.m:22:7: error: expected identifier or '('
>   int i386 = 42;
>       ^
> <built-in>:143:14: note: expanded from here
>              ^
> 1 error generated.
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)