schveiguy at yahoo.com
Thu Nov 11 07:52:50 PST 2010
On Thu, 11 Nov 2010 10:34:41 -0500, spir <denis.spir at gmail.com> wrote:
> On Thu, 11 Nov 2010 07:47:01 -0500
> "Steven Schveighoffer" <schveiguy at yahoo.com> wrote:
>> This is not enough code to understand the problem. For instance,
>> writefln(pattern) prints a class, but we don't see Pattern's toString
>> function. We don't see the code that creates the object and then calls
>> check. Maybe something happens between calls?
>> It's impossible to diagnose something like this without a working
>> so you need to trim it down to something that still compiles and fails,
>> and then share that entire code.
> I tried to build a example mini-app to show the issue more simply, but
> couldn't. The point is the bug only shows when using the most
> complicated element of my code (class List), built on top of ~ 1000
> lines. I guess the best is to try to explain the case and provide
> example test. See code of the class and test case below.
This gives a little more information. From your code, it appears that the
constructor has this line:
Which succeeds. Then your test code looks like this:
auto addition = new List(number, PLUS);
// This check works fine:
writeln(addition); // --> List([0-9]+, "+", 2)
// But if I uncomment the following: segfault
Which means between constructor (first line in test code), you printed the
item itself, then print the item's pattern field.
What it looks like to me is that between printing it in the constructor,
and printing it outside the constructor, something bad happened. There
are several pieces of code running that I don't have the source for, so I
can assume either you have a compiler bug, or it's in one of those pieces.
Try this: inside the constructor do:
And see if that fails. If that fails, then we know it's one of those
three lines thats messing things up.
Comment out writeln(this), and see if it still fails. If it does, then
it's something being printed in your Tuple class that is causing it to
corrupt something so it can't be printed again. If not, then it's
something being printed in your List class. I don't have the code that
converts your Pattern class to a string, etc. so I can't say whether they
are an issue.
If those three lines work in the constructor, I'd say there is a possible
compiler error, because there is no difference between calling that code
from in the constructor or in the test code.
If that's the case, create a function that prints out all the addresses of
things (you can print out the address of a class by simply casting the
class reference to a void *). Print that out between each line and see
what changes, then focus there. Again, without more code, I can't say for
certain what's going on.
If you have a debugger, it might help even more than these little tricks.
More information about the Digitalmars-d-learn