mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Segmentation fault when profiling #165
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sidmani on GitHub (Sep 10, 2017).
In ObjectObserver.swift (line 325) and ListMonitor.swift (line 714),
ObjectType.cs_fromRaw(object: rawObject)causes a segfault, but only when profiling, not regular building. The strange thing is I can't replicate the issue in the demo project. Do you have any idea what causes this? Commenting out the callback invocation fixes the problem.@sidmani commented on GitHub (Sep 10, 2017):
Here's the output:
@JohnEstropia commented on GitHub (Sep 10, 2017):
Which CoreStore branch are you using?
@sidmani commented on GitHub (Sep 10, 2017):
prototype/swift_4
@JohnEstropia commented on GitHub (Sep 10, 2017):
Thanks, will look into it
@sidmani commented on GitHub (Sep 12, 2017):
@JohnEstropia I made a mistake, the
[weak self]is to blame. Both that and[unowned self]cause a segfault. I still don't know why though.@JohnEstropia commented on GitHub (Sep 12, 2017):
@sidmani Are those [weak self] and [unowned self] within CoreStore's source file? If it's in external code, can you show an example pattern this occurs?
@sidmani commented on GitHub (Sep 12, 2017):
Yeah, they're in CoreStore's source (line 317 in ObjectMonitor.swift, for example). I'm debugging this right now, and by replacing the callback at line 325 with a function call to a temporary function:
I get the compiler error:
Cannot convert value of type 'ObjectMonitor<D>' to expected argument type 'ObjectMonitor<_>'. In theory there should be no difference between calling a closure and a function with the same input and return types, so I think this is the issue. Not sure how to fix yet.@SoyArpad commented on GitHub (Sep 21, 2017):
any update on this @JohnEstropia? im getting the same error while I'm trying to Archive, Thanks
@SoyArpad commented on GitHub (Sep 21, 2017):
it seems that ObjectType.cs_fromRaw (object: object) was doing weird casting and the compiler does not like when is archiving or profiling, so I think we can check if the object implements the ObjectType in the guard.
The same for ListMonitor
after the correction my app is archiving successfully @sidmani, just I want to know @JohnEstropia if this is a valid fix and doesn't affect to something else, it seems that my app runs perfect but I'm not using ListObserver or MonitorObserver, so just let me know any comment
@JohnEstropia commented on GitHub (Sep 22, 2017):
Thanks for investigating this. I hit this problem in the one of my projects as well and I'm still looking for an actual fix inside the
cs_fromRaw()method. The issue is that the compiler doesn't like it when you cast an object to it's own type (which happens on optimized builds due to inlining). @SoyArpad 's code above works because of the extra type-check, which prevents the optimizer from inlining. We can do that for allcs_fromRaw()calls but other usage of the method might still break.If I can't find a better workaround by the end of the week we'll go with the workaround above.
@JohnEstropia commented on GitHub (Sep 22, 2017):
@sidmani @SoyArpad I made an edit and it's on the
prototype/Swift_3_2andprototype/Swift_4_0branches. Let me know how it works for you.@SoyArpad commented on GitHub (Sep 23, 2017):
it works, thank you @JohnEstropia