* thread #1: tid = 26059, 0x00007f6324bc91c3 llvmjit.so`llvm::Value::getContext() const + 3, name = 'postgres', stop reason = invalid address (fault address: 0x0)
* frame #0: 0x00007f6324bc91c3 llvmjit.so`llvm::Value::getContext() const + 3
frame #1: 0x00007f6324bca7ca llvmjit.so`llvm::Value::setNameImpl(llvm::Twine const&) + 26
frame #2: 0x00007f6324bcaa59 llvmjit.so`llvm::Value::setName(llvm::Twine const&) + 9
frame #3: 0x00007f6324adb928 llvmjit.so`LLVMBuildExtractValue + 456
source code: use llvm-c api to call intrinsic function
v_fn = LLVMGetNamedFunction(mod, "llvm.sadd.with.overflow.i64");
if (!v_fn)
{
LLVMTypeRef param_types[2];
LLVMTypeRef v_fn_type;
param_types[0] = LLVMInt64Type();
param_types[1] = LLVMInt64Type();
v_fn_type = LLVMFunctionType(LLVMInt64Type(), param_types, lengthof(param_types), 0);
v_fn = LLVMAddFunction(mod, "llvm.sadd.with.overflow.i64", v_fn_type);
}
params[0] = l_int64_const(1);
params[1] = l_int64_const(1);
v_res = LLVMBuildCall(b, v_fn,
params, lengthof(params), "");
v_flag = LLVMBuildExtractValue(b, v_res, 1, "");
v_flag = LLVMBuildIsNotNull(b, v_flag, "");
when i use LLVMBuildExtractValue to get result from intrinsic llvm.sadd.with.overflow.i64, got stack above.
i can only get that context is 0x0. but what cause this. Anyone can help pls?
Related
I'm trying to read http://www.tiwwdty.com/v with wxWidgets and C++. Here's what I've got:
wxString urlname = "http://www.tiwwdty.com/v";
wxURL url(urlname);
if (url.GetError()) abort();
wxInputStream *in = url.GetInputStream();
cout << "in " << in << endl;
if (!in || !in->IsOk()) return;
wxStringOutputStream strout;
in->Read(strout);
string vstr = strout.GetString().ToStdString();
cout << "vstr " << vstr << endl;
And the code actually segfaults in url.GetInputStream() [!?] Can anyone tell me what I'm doing wrong? Here's the backtrace (wxWidgets 3.1.4):
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x18)
* frame #0: 0x00007fff70cd75ad libsystem_pthread.dylib`pthread_mutex_lock
frame #1: 0x00007fff36acdd7d CoreFoundation`CFSocketDisableCallBacks + 79
frame #2: 0x00000001000456f3 nfl`wxSocketManagerMac::Uninstall_Callback(this=0x00000001005b42e8, socket_=0x0000000100f913a0, event=wxSOCKET_INPUT) at sockosx.cpp:274:5
frame #3: 0x0000000100044e71 nfl`wxSocketImplUnix::DoEnableEvents(this=0x0000000100f913a0, flags=3, enable=false) at sockunix.cpp:113:22
frame #4: 0x0000000100045d01 nfl`wxSocketImplUnix::UpdateBlockingState(this=0x0000000100f913a0) at sockunix.h:68:9
frame #5: 0x000000010003bb94 nfl`wxSocketBase::SetFlags(this=0x0000000101857d60, flags=28) at socket.cpp:1687:21
frame #6: 0x000000010004057b nfl`wxSocketWaitModeChanger::~wxSocketWaitModeChanger(this=0x00007ffeefbfe320) at socket.cpp:192:19
frame #7: 0x000000010003c905 nfl`wxSocketWaitModeChanger::~wxSocketWaitModeChanger(this=0x00007ffeefbfe320) at socket.cpp:191:5
frame #8: 0x000000010003c98d nfl`wxSocketBase::Peek(this=0x0000000101857d60, buffer=0x0000000101077000, nbytes=4095) at socket.cpp:1147:1
frame #9: 0x0000000100034770 nfl`wxProtocol::ReadLine(sock=0x0000000101857d60, result=0x00007ffeefbfe708) at protocol.cpp:130:15
frame #10: 0x00000001000316b4 nfl`wxHTTP::ParseHeaders(this=0x0000000101857d60) at http.cpp:261:23
frame #11: 0x0000000100032e29 nfl`wxHTTP::BuildRequest(this=0x0000000101857d60, path=0x00007ffeefbfeea0, method=0x00007ffeefbfed48) at http.cpp:428:17
frame #12: 0x00000001000331cd nfl`wxHTTP::GetInputStream(this=0x0000000101857d60, path=0x00007ffeefbfeea0) at http.cpp:516:10
frame #13: 0x0000000100042ab0 nfl`wxURL::GetInputStream(this=0x00007ffeefbff018) at url.cpp:348:47
frame #14: 0x00000001000058ee nfl`nfl_frame::check_version(this=<unavailable>) at nfl.cpp:384:27 [opt]
frame #15: 0x00000001000052f1 nfl`nfl_app::OnInit(this=<unavailable>) at nfl.cpp:165:10 [opt]
frame #16: 0x0000000100054cc1 nfl`wxApp::CallOnInit(this=0x0000000100f04750) at utils.mm:439:22
frame #17: 0x00000001003986d9 nfl`wxEntry(argc=0x00000001005cb508, argv=0x000000010191fcf0) at init.cpp:491:25
frame #18: 0x00000001003988fb nfl`wxEntry(argc=0x00007ffeefbff95c, argv=0x00007ffeefbff980) at init.cpp:519:12
frame #19: 0x0000000100004c44 nfl`main(argc=1, argv=<unavailable>) at nfl.cpp:138:1 [opt]
frame #20: 0x00007fff70ad7cc9 libdyld.dylib`start + 1
If it matters, the web address launches fine in a browser, but wget doesn't seem to like it. curl, however, is fine.
Thanks!
I have a static array metricsTransactionData in ServiceRequest class. I am invoking multiple request continuously and sometimes I get this error "error for object 0x10b874cb0: pointer being freed was not allocated" on this line ServiceRequest.metricsTransactionData.append(samp). Pls help
public func urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) {
for mem in metrics.transactionMetrics {
var samp = MetricsData()
samp.requestDate = mem.requestStartDate
samp.responseDate = mem.responseEndDate
samp.url = mem.request.url?.absoluteString
ServiceRequest.metricsTransactionData.append(samp)
}
}
Stack trace:
* thread #3, queue = 'NSOperationQueue 0x6000001edb20 (QOS: UNSPECIFIED)', stop reason = signal SIGABRT
frame #0: 0x0000000106897b66 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00000001068d1080 libsystem_pthread.dylib`pthread_kill + 333
frame #2: 0x0000000106644c45 libsystem_c.dylib`abort + 127
frame #3: 0x00000001067986e4 libsystem_malloc.dylib`malloc_vreport + 545
frame #4: 0x00000001067988d5 libsystem_malloc.dylib`malloc_report + 152
frame #5: 0x00000001049bd910 libswiftCore.dylib`_swift_release_dealloc + 16
frame #6: 0x0000000104980017 libswiftCore.dylib`assignWithTake value witness for Swift.Array + 23
frame #7: 0x00000001046f3a5a libswiftCore.dylib`(extension in Swift):Swift._ArrayBufferProtocol._arrayOutOfPlaceUpdate<A where A1: Swift._PointerFunction, A.Element == A1.Element>(inout Swift._ContiguousArrayBuffer<A.Element>, Swift.Int, Swift.Int, A1) -> () + 1146
frame #8: 0x000000010470aa11 libswiftCore.dylib`Swift.Array._copyToNewBuffer(oldCount: Swift.Int) -> () + 209
frame #9: 0x000000010470aaf0 libswiftCore.dylib`Swift.Array._makeUniqueAndReserveCapacityIfNotUnique() -> () + 192
frame #10: 0x000000010470ad98 libswiftCore.dylib`Swift.Array.append(A) -> () + 24
The error tells you that it is a very bad idea to use a static/global array that will be updated from various background tasks. Swift arrays are not thread-safe.
Means that your array gets resized by one task while another might already do the same, resulting in a bad memory access. Likely calling (at least) append in a DispatchQueue.main.async would fix the problem if you really have to do it that way, but if you want to maintain the order, you would need to handle synchronization yourself.
But in any way i strongly recommend that you find another solution that prevents that kind of write access to the array directly. Globally writable arrays are bad.
I've recently read The Swift Programming Language document, which introduced to me Extensions, and so I tried to implement this code:
extension SKTexture{
var size: CGSize {
return self.size()
}
}
Later in the same code, I try to access a property of the SKTexture:
someTexture.size.width
However, when I run the app, I get a EXC_BAD_ACCESS
I have also noticed that even if I don't try to access the width property via my new computed property, implementing someTexture.size().width instead of someTexture.size.width , I get this error. Could someone explain me what I'm doing wrong?
Short answer:
For a class derived from NSObject, a Swift property
which has the same name as an existing Objective-C method replaces that method.
Therefore in your case,
var size: CGSize {
return self.size()
}
calls itself recursively until the program aborts with a stack overflow
(well, that's what this site is for :).
If you choose a different name for the property, e.g.
var theSize: CGSize {
return self.size()
}
then everything works nicely.
Long answer:
SKTexture is a subclass of NSObject. Therefore all Swift properties are
"Objective-C compatible". As a consequence, the compiler generates a getter
method that can be called from Objective-C code. The getter method for the
size property is a -size method. So you have now two -size methods:
The original one from SKTexture and a second one defined in your Swift code.
If you do the same with your own Objective-C class defined in the same project
then you will get a linker warning:
instance method 'size' in category from /Users/.../main.o overrides
method from class in /Users/.../MyClass.o
If the Objective-C class is defined in a external framework (as in your case)
the linker does not notice the conflict.
Now return self.size() calls the generated Objective-C getter method, which in turn
calls the extension method. This leads to "infinite" recursion and ultimately
to a stack overflow.
This is confirmed by the stack backtrace which you can get with the lldb bt
command when the program has crashed:
* thread #1: tid = 0x3d2ef, 0x000000010fb15e01 libobjc.A.dylib`objc::DenseMapBase, unsigned long, true, objc::DenseMapInfo > >, DisguisedPtr, unsigned long, objc::DenseMapInfo >, true>::FindAndConstruct(DisguisedPtr const&) + 21, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7fff51b9cfe8)
frame #0: 0x000000010fb15e01 libobjc.A.dylib`objc::DenseMapBase, unsigned long, true, objc::DenseMapInfo > >, DisguisedPtr, unsigned long, objc::DenseMapInfo >, true>::FindAndConstruct(DisguisedPtr const&) + 21
frame #1: 0x000000010fb13e14 libobjc.A.dylib`objc_object::sidetable_retain() + 94
* frame #2: 0x000000010d8674d9 cdtest2`ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize(self=0x00007fcceea020f0) + 25 at AppDelegate.swift:19
frame #3: 0x000000010d867542 cdtest2`#objc ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize + 34 at AppDelegate.swift:0
frame #4: 0x000000010d8674ed cdtest2`ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize(self=0x00007fcceea020f0) + 45 at AppDelegate.swift:19
frame #5: 0x000000010d867542 cdtest2`#objc ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize + 34 at AppDelegate.swift:0
frame #6: 0x000000010d8674ed cdtest2`ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize(self=0x00007fcceea020f0) + 45 at AppDelegate.swift:19
frame #7: 0x000000010d867542 cdtest2`#objc ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize + 34 at AppDelegate.swift:0
frame #8: 0x000000010d8674ed cdtest2`ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize(self=0x00007fcceea020f0) + 45 at AppDelegate.swift:19
...
frame #149556: 0x000000010d8674ed cdtest2`ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize(self=0x00007fcceea020f0) + 45 at AppDelegate.swift:19
frame #149557: 0x000000010d867542 cdtest2`#objc ext.cdtest2.ObjectiveC.SKTexture.size.getter : C.CGSize + 34 at AppDelegate.swift:0
frame #149558: 0x000000010d8694e0 cdtest2`cdtest2.AppDelegate.application (application=0x00007fccee8005a0, launchOptions=None, self=0x00007fccebc06410)(ObjectiveC.UIApplication, didFinishLaunchingWithOptions : Swift.Optional>) -> Swift.Bool + 112 at AppDelegate.swift:83
frame #149559: 0x000000010d8697b0 cdtest2`#objc cdtest2.AppDelegate.application (cdtest2.AppDelegate)(ObjectiveC.UIApplication, didFinishLaunchingWithOptions : Swift.Optional>) -> Swift.Bool + 560 at AppDelegate.swift:0
...
frame #149572: 0x000000010d86bcaa cdtest2`main + 42 at AppDelegate.swift:0
frame #149573: 0x00000001102f0145 libdyld.dylib`start + 1
This (hopefully) explains also why the problem occurs with both someTexture.size().width and someTexture.size.width:
In both cases, the custom extension method is called.
I run into strange thing I'm getting a crash it this function:
func addQuestion(text:String!)
{
if let txt=text
{
let question=PFObject(className: "questions")
question["text"]=txt
question["userAdding"]=PFUser.currentUser()
question["answeredCount"]=0
question.setObject([], forKey: "answers")
question.setObject(NSDate(), forKey: "dateAdded")
question.setObject(Int(arc4random()) % 10, forKey: "random")
if debug
{question.saveInBackgroundWithBlock(nil)}
else
{question.saveEventually()}
}
}
I'm getting a crash in "if let txt=text"
here is a back trace:
thread #1: tid = 0x241c0c, 0x00063470 pytajnik`pytajnik.ApiClient.addQuestion (text=Some, self=(ObjectiveC.NSObject = {}, debug = true))(Swift.ImplicitlyUnwrappedOptional<Swift.String>) -> () + 10796 at ApiClient.swift:32, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xe7ffdefe)
frame #0: 0x00063470 pytajnik`pytajnik.ApiClient.addQuestion (text=Some, self=(ObjectiveC.NSObject = {}, debug = true))(Swift.ImplicitlyUnwrappedOptional<Swift.String>) -> () + 10796 at ApiClient.swift:32
frame #1: 0x00035428 pytajnik`pytajnik.AddQuestionViewController.addQuestion (sender=AnyObject at 0x006ca054, self=0x17ef85d0)(Swift.AnyObject) -> () + 796 at AddQuestionViewController.swift:17
frame #2: 0x00035a6c pytajnik`#objc pytajnik.AddQuestionViewController.addQuestion (pytajnik.AddQuestionViewController)(Swift.AnyObject) -> () + 100 at AddQuestionViewController.swift:0
frame #3: 0x2a5fdc2a UIKit`-[UIApplication sendAction:to:from:forEvent:] + 70
frame #4: 0x2a5fdbd0 UIKit`-[UIControl sendAction:to:forEvent:] + 44
...
The thing is, the app is not crashing always. Sometime it works sometime it doesn't. And I could't find a pattern.
Could somebody help me understand what is wrong?
UPDATE
thread #1: tid = 0x243f69, 0x0005d478 pytajnik`pytajnik.ApiClient.addQuestion (text=Some, self=(ObjectiveC.NSObject = {}, debug = true))(Swift.Optional<Swift.String>) -> () + 9820 at ApiClient.swift:35, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xe7ffdefe)
frame #0: 0x0005d478 pytajnik`pytajnik.ApiClient.addQuestion (text=Some, self=(ObjectiveC.NSObject = {}, debug = true))(Swift.Optional<Swift.String>) -> () + 9820 at ApiClient.swift:35
frame #1: 0x0002f80c pytajnik`pytajnik.AddQuestionViewController.addQuestion (sender=AnyObject at 0x006c4054, self=0x166a5560)(Swift.AnyObject) -> () + 1760 at AddQuestionViewController.swift:17
frame #2: 0x0002fe40 pytajnik`#objc pytajnik.AddQuestionViewController.addQuestion (pytajnik.AddQuestionViewController)(Swift.AnyObject) -> () + 100 at AddQuestionViewController.swift:0
frame #3: 0x2a5fdc2a UIKit`-[UIApplication sendAction:to:from:forEvent:] + 70
frame #4: 0x2a5fdbd0 UIKit`-[UIControl sendAction:to:forEvent:] + 44
frame #5: 0x2a5e8862 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 582
frame #6: 0x2a5fd63c UIKit`-[UIControl touchesEnded:withEvent:] + 588
frame #7: 0x2a5fd316 UIKit`-[UIWindow _sendTouchesForEvent:] + 522
frame #8: 0x2a5f6be0 UIKit`-[UIWindow sendEvent:] + 544
You declared the function parameter as implicitly unwrapped optional !, meaning you are sure it will never be nil.
If its possible that this parameter can be nil declare it as optional:
func addQuestion(text: String?) {
if let txt = text {
...
}
}
You have declared the text parameter as an implicitly unwrapped optional, which causes the app to crash if text is nil, and this is what's happening in your case.
Unless you have a specific reason to use an implicitly unwrapped optional, it's always better to use an optional String?, or a non optional String if the parameter can never be nil.
So to fix the problem just change your function signature to this:
func addQuestion(text:String?)
Suggested reading: Implicitly Unwrapped Optionals
From Apple docs:
“Each access-level modifier above optionally accepts a single
argument, which consists of the keyword set enclosed in parentheses
(for instance, private(set)). Use this form of an access-level
modifier when you want to specify an access level for the setter of a
variable or subscript that’s less than or equal to the access level of
the variable or subscript itself, as discussed in Getters and
Setters.”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.
https://itun.es/ru/jEUH0.l
An example which I try to test in Playground:
import UIKit
class A {
private(set) var name: String {
get { return "Hello, \(self.name)" }
set { self.name = "Unknown" }
}
init(_ name:String) {
self.name = name
}
}
let a = A("Andrew")
a.name = "Hello"
An error which I get in Console Output:
Playground execution failed: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=2, address=0x7fff5056eff8).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
* thread #1: tid = 0xea721, 0x00000001104f308c libsystem_pthread.dylib`__mtx_droplock + 222, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x7fff5056eff8)
* frame #0: 0x00000001104f308c libsystem_pthread.dylib`__mtx_droplock + 222
frame #1: 0x00000001104f2f07 libsystem_pthread.dylib`pthread_mutex_unlock + 68
frame #2: 0x000000010ffbd2b5 libc++.1.dylib`std::__1::mutex::unlock() + 9
frame #3: 0x000000010f040b94 libswift_stdlib_core.dylib`swift_getGenericMetadata + 260
frame #4: 0x000000010ef28a24 libswift_stdlib_core.dylib`Swift.IndexingGenerator.init <A : Swift._Collection>(Swift.IndexingGenerator<A>.Type)(A) -> Swift.IndexingGenerator<A> + 164
frame #5: 0x000000010ef55f1a libswift_stdlib_core.dylib`protocol witness for Swift._Sequence_.generate <A : Swift._Sequence_>(#inout Swift._Sequence_.Self)() -> Swift._Sequence_.Self.GeneratorType in conformance Swift._ContiguousArrayBuffer : Swift._Sequence_ + 154
frame #6: 0x000000010ef284d5 libswift_stdlib_core.dylib`Swift._copyCollectionToNativeArrayBuffer <A : protocol<Swift._Collection, Swift._Sequence_>>(A) -> Swift._ContiguousArrayBuffer<A.GeneratorType.Element> + 1061
frame #7: 0x000000010ef40281 libswift_stdlib_core.dylib`Swift.Array.convertFromArrayLiteral <A>(Swift.Array<A>.Type)(Swift.Array<A>...) -> Swift.Array<A> + 641
frame #8: 0x000000010f1eaae4 PlaygroundLogger`Swift.UInt64.toBytes (Swift.UInt64)() -> Swift.Array<Swift.UInt8> + 292
frame #9: 0x000000010f1eb6a4 PlaygroundLogger`protocol witness for PlaygroundLogger.ToBytes.toBytes <A : PlaygroundLogger.ToBytes>(#inout PlaygroundLogger.ToBytes.Self)() -> Swift.Array<Swift.UInt8> in conformance Swift.UInt64 : PlaygroundLogger.ToBytes + 20
frame #10: 0x000000010f1dbe3d PlaygroundLogger`PlaygroundLogger.BytesStream.write (PlaygroundLogger.BytesStream)(PlaygroundLogger.ToBytes) -> PlaygroundLogger.BytesStream + 77
frame #11: 0x000000010f1dbd74 PlaygroundLogger`PlaygroundLogger.BytesStream.write (PlaygroundLogger.BytesStream)(Swift.String) -> PlaygroundLogger.BytesStream + 164
frame #12: 0x000000010f20f04b PlaygroundLogger`PlaygroundLogger.PlaygroundWriter.encode_config_info (PlaygroundLogger.PlaygroundWriter)() -> () + 203
frame #13: 0x000000010f20f2bf PlaygroundLogger`PlaygroundLogger.PlaygroundWriter.encode_header (PlaygroundLogger.PlaygroundWriter)() -> () + 127
frame #14: 0x000000010f20ecda PlaygroundLogger`PlaygroundLogger.PlaygroundScopeWriter.encode_scope_event (PlaygroundLogger.PlaygroundScopeWriter)(PlaygroundLogger.ScopeEvent) -> () + 58
frame #15: 0x000000010f1eb997 PlaygroundLogger`playground_log_scope_entry + 87
frame #16: 0x000000011ae20771
What am I doing wrong? Am I missing something?
PS1
This example works fine:
struct TrackedString {
private(set) var numberOfEdits = 0
var value: String = "" {
didSet {
numberOfEdits++
}
}
}
var stringToEdit = TrackedString()
stringToEdit.value = "Hello"
stringToEdit
stringToEdit.numberOfEdits += 10
stringToEdit
More from docs:
“the access level for the numberOfEdits property is marked with a
private(set) modifier to indicate that the property should be settable
only from within the same source file as the TrackedString structure’s
definition.”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks.
https://itun.es/ru/jEUH0.l
But thats not what I need. Is it possible to disallow to set variable numberOfEdits outside the struct/class?
Your problem lies here:
set { self.name = "Unknown" }
You're setting the value of a computed property within its own setter. This causes infinite recursion. Don't forget that this is a computed property: it doesn't actually have storage. You don't have a variable "self.name" to put anything in; you only have a couple of functions to calculate it. Computed properties like this should use other, non-computed variables for storage. (That's why your structure example works, by the way: you're using a real property with storage.)
You're not being helped in your debugging by fact of running in a Playground. Don't get me wrong: Playgrounds are great. However, in this case, it's taking many seconds to crash, so the crash probably isn't showing up when you expect after an edit. It's also not showing you a full stack trace (which is massive for the problem you're getting, having reproduced it in a "real" app, and might have made it rather more obvious that you'd blown the stack.) When I built and ran the above as a console app, it finally blew up with a stack trace 104,832 calls deep, all but two of which were ...private_cmd.A.name.setter.... Bit of a clue :)