Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix library for proper Compiler-Level Optimization Setting (Release Build Crash Fix) #13

Closed
ghost opened this issue Jan 5, 2015 · 11 comments

Comments

@ghost
Copy link

ghost commented Jan 5, 2015

I recently submitted my app to the store not realizing this library requires the optimization level of the compiler to be set to 'None' or it crashes on launch for release build. As a result, it was rejected by Apple due to crashing on start up.
I have since changed it to 'None' and now the app runs fine on release build, but reading Apple's documentation it states specifically the following for Compiler-Level Optimization of type None:

 None - The compiler does not attempt to optimize code. Use this option during development when you are focused on solving logic errors and need a fast compile time. Do not use this option for shipping your executable.

The Do not use this option for shipping your executable concerns me a bit for releasing a non-optimized build to the App Store.
Is there any possibility of fixing this library to not require this setting?

@ghost
Copy link
Author

ghost commented Jan 5, 2015

From my brief research, I think the issue may be stemming from your use of these in the library:

 Unmanaged<AnyObject>? 
 UnsafeMutablePointer<Unmanaged<AnyObject>?>

Here are some related issues I found that discussed the same problem:
http://stackoverflow.com/questions/9431583/crash-at-any-optimization-level-other-than-o0-in-ios
http://stackoverflow.com/questions/24215757/using-unmanagedanyobject-as-key-in-nsmutabledictionary

@matthewpalmer
Copy link
Owner

Oh man I’m really sorry that this caused your app to be rejected :(. It's the worst when 3rd party libraries cause problems in your app.

The problem is that the Keychain Services API requires the use of an UnsafeMutablePointer to an Unmanaged AnyObject, i.e.

func SecItemCopyMatching(query: CFDictionary!, result: UnsafeMutablePointer<Unmanaged<AnyObject>?>) -> OSStatus

Unfortunately, I can't think of any way of getting around this requirement.

If possible, I recommend using @soffes's SSKeychain. It's really stable and written in Objective-C, so it shouldn't have any of these crazy issues. Hopefully Apple fixes this bug ASAP.

Sorry again,
Matt.

@beltex
Copy link

beltex commented Jan 14, 2015

Hi @NitWitStudios & @matthewpalmer,

I can't seem to reproduce the crash. Do you have a stack trace you could share?

Pinpointing these crashes and collecting them is what the swift-compiler-crashes project does, so finding and documenting everyone of these helps.

@matthewpalmer
Copy link
Owner

I think Issue #6 Is the original incarnation of this crash. That thread has a lot more information and ways to force the crash.
If you're still unable to reproduce the crash, let me know and I'll look into it.

Cheers,
Matt.

@beltex
Copy link

beltex commented Jan 14, 2015

Darn, I should have search for it, my mistake! Thanks Matt! :)

@moshegutman
Copy link

I was able to fix a similar issue with help from this link:
http://stackoverflow.com/questions/24145838/querying-ios-keychain-using-swift

var returnedData: AnyObject?
var results = withUnsafeMutablePointer(&returnedData) { SecItemCopyMatching(query, UnsafeMutablePointer($0)) }

@Arcrammer
Copy link

Would the compiler crash if you use withUnsafeMutablePointer()?

@moshegutman
Copy link

My project is compiling without issues. It is a valid Swift function:
http://swiftdoc.org/func/withUnsafeMutablePointer/

@olvidalo
Copy link

I replaced all the unmanaged objects with the withUnsafeMutablePointer function which seemed to have resolved at least my issue where I would get a duplicate item-error when trying to save data in the release configuration with something other than -Onone.

@matthewpalmer
Copy link
Owner

Thanks for all of the help everyone, and cheers to @olvidalo for the fix :)

@ghost
Copy link
Author

ghost commented Jan 22, 2015

Awesome! Thumbs up to everyone who got involved in this issue! 👍

matthewpalmer added a commit that referenced this issue Jan 25, 2015
* 'master' of https://github.com/matthewpalmer/Locksmith: (42 commits)
  Remove note on buggy release builds; fixed in #14
  replace unmanaged objects with withUnsafeMutablePointer to fix #13
  Update README.markdown
  Update README.markdown
  Update README.markdown
  Update README.markdown
  Update README.markdown
  Update README.markdown
  Update README.markdown
  Update README.markdown
  Update README.markdown
  Added support for iCloud sync. Added support for different forms of security classes.
  Added basic tests
  Update README.markdown
  Removed requirement for the redundant 'key' argument
  Added method to clear the keychain
  Improve installation instructions
  Update README.markdown
  Update README.markdown
  Fix typo in readme
  ...

Conflicts:
	.gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants