-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I did some dubious work in the 4.1 migration, that is, I was using
withUnsafePointer(to:) and returning the address that was calculated, because I figured "I know this can not go away". Well, it turns out, that I did not know this very well to begin with, and when running the code in Optimize mode in some scenarios, the value did go away - just like the Swift documentation had warned. Let this be another lesson that hubris never pays off. What I was doing was generating something like this to pass a pointer to the handle of a parameter: func demo (parameter: SomeWrapped, another: SomeWrapped) { var args: [...] = [ withUnsafePointer (to: ¶meter.handle) { p in return p } withUnsafePointer (to: &another.handle) { p in return p } ] callGodotWith (args) } The value of `p` in the callback invoked by withUnsafePointer is only valid for the duration of the block, but like I said, I though I could get away with it. Now instead of generating code like this, I nest the calls to withUnsafePointer, like this: func demo (parameter: SomeWrapped, another: SomeWrapped) { var args: [] = [] withUnsafePointer (to: parameter.handle) { p1 in args.append (p1) withUnsafePointer (to: another.handle) { p2 in args.append (p2) callGodotWith (args) } } }
- Loading branch information
1 parent
70ed829
commit 4394cf4
Showing
4 changed files
with
46 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters