Skip to content

Using DICT Macro causes segmentation fault #2

Description

@jdewind

The DICT macro is never able to create a dictionary because a segmentation fault occurs in the static inlined function "MADictionaryWithKeysAndObjects". The compound literal (array of objects) keysAndObjs' elements points to objects on the heap that are no longer valid when that function attempts to subscript the array.

After a bit of investigation I found that if I made the "MADictionaryWithKeysAndObjects" a normal function that is not inlined the keysAndObjs array pointed to valid objects and the macro worked. I ensured that the compiler didn't optimize the MADictionaryWithKeysAndObjects into an inlined function by stepping through the assembly and ensuring that it used "call" instead of "jmp".

Oddly, it appears that the elements of keysAndObjs are being prematurely deallocated when MADictionaryWithKeysAndObjects is inlined. However, what is stranger, is that my dictionary contained a set of string literals as key/values which would make me think that those objects couldn't be deallocated anyhow since they are global strings.

This was happening consistently on the iOS Simulator 4.2 with both GCC 4.2 and LLVM GCC 4.2.

Code Snippet:

DICT(@"A", @"B", @"C", @"D");

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions