Closed williampma closed 9 years ago
Here's a crashing UTest file.
https://github.com/williampma/atomspace/blob/PMTest/tests/query/PatternCrashUTest.cxxtest
Please push and commit the unit test.
Here's some guesses: p.second is probably Handle::UNDEFINED so p.second->toShortStrng crashed because its a null pointer dereference.
At some point, I'll bet that p.second was pointing at a real, valid atom that was not in the atomspace. Since its not in the atomsapce, it will have a UUID=-1 and both scheme and python get tripped up on atoms with UUID=-1 (even if they are otherwise valid atoms).
Ohh, here I think I see it:
PatternLinkPtr sl(createPatternLink(htarget_vardecl, htarget))
you're creating an atom here, but you are not putting it in the atomspace. That atom will have the variable-decls in its outgoing set, and so as the pattern matcher walks the incoming set of the variable decls, it will, at some point, look at the atom pointed at by PatternLinkPtr .. which is not in any atomspace!
I'm guessing this eventually leads to the crash. if its not this, it could be some other atom(s) that weren't inserted. I suppose that perhaps using mutliple atomspaces and addings/removing/deleteing in a weird order could also results in atoms that are not in atomspaces. ...
I just tried changing that part you mentioned to
Handle htarget_vardecl = _as->addAtom(createVariableList(vars));
Handle hpattern = _as->addAtom(createPatternLink(htarget_vardecl, htarget));
PatternLinkPtr sl = PatternLinkCast(hpattern);
PMCB pmcb(_as);
sl->satisfy(pmcb);
It still crashes with a Segmentation fault, so I guess it's not that.
Bummer. thought I got lucky. I wont have time to look at this for many days. try adding a #define DEBUG 1
to Pattern.h and compiling, and working backwards from the crash. somewhere is an atom that is not in the atomspace.
This bug might be my fault .. I did re-organize how atoms are placed into the atomspace, recently, and maybe something is not being inserted. That's my best guess.
Ok, I will take a look.
I just verified that indeed p.second was Handle::UNDEFINED when it crashes.
BTW, @williampma why do you use
PatternLinkPtr sl(createPatternLink(htarget_vardecl, htarget))
instead of
PatternLinkPtr sl(htarget_vardecl, htarget)
I'm especially asking because I've seen
// XXX temporary hack ...
#define createPatternLink std::make_shared<PatternLink>
in PatternLink.h, though I don't understand why it is a hack...
Hmmm, this temporary hack is used in AtomTable.cc, but that doesn't mean it should be used by users, I would assume. Users should use instead as->addLink(PATTERN_LINK, ...), that way the atom is added no matter what.
@linas do you know why it is a hack?
@linas https://github.com/linas do you know why it is a hack?
No. That warning should be removed It is cut-n-pasted across all Atom files. it was going to be replaced by something clever and pretty, but never was. Maybe some constructor overloading magic. Unrelated to this problem.
OK, so I looked at this. I think its a "feature" not a "bug". The code was written before c++11x came out, and that is a few places where the map uses [] instead of at() to look up an element. This causes a null handle to be inserted. It doesn't mean anything -- it just means that, during recursion, it tried looking at atoms that aren't variables. Such atoms are grounded by themselves, and weren't recorded.
Note also: the pattern matcher was written before VariableNodes existed; it assumed the user would deal with these things. I'll try to fix all the spots, meanwhile, just check for null, and don';t use it. Thats what thedebug prints do.
I just pushed a fix for this at fb41305e4f207a87694b3b8305299a5c43af43ee -- it was simply old code that was "working as designed", but maybe working a bit ugly.
I see. Thanks, Linas!
This one is tough. Need to write some custom code to test this.
First, assume the following are in the AtomSpace
Then, write a new PatternMatcherCallBack with a new
grounding
method that just print the var_soln mappingThen have some variable Handle
htarget
then contains the following additional atomAnd call the Pattern Matcher code like this
cogserver crash at the line printing var_soln (in particular, when printing p.second. Printing p.first was fine).
In my case, the crash code is like this