Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Regex: run-time error: object.Exception: Access Violation (while not using -g flag)

Moderators: kris

Posted: 01/06/09 11:49:40

hey, Im new to d and tango, I was playing arround with it when I stopped with a run-time error "object.Exception: Access Violation". I was trying the example at tango.text.Regex from the API, here goes:

foreach(m; Regex("ab").search("qwerabcabcababqwer") Stdout.formatln("{}[{}]{}", m.pre, m.match(0), m.post);

Tried whatever I could to make it working. I joined #d.tango @ irc asking for help and "larsivi" told me that it runs correctly for him under linux.

Finally, after some tests I realized that when compiling with -g flag everything runs correctly. "dmd -g file.d"

I'm under vista 32 bits.

Greetings, TA

Author Message

Posted: 01/06/09 22:55:18

Looks like ticket #956. No idea what causes it, I just avoid using Regex.

Posted: 01/06/09 23:28:52

As I said to TheAddicted in IRC - some people testing it with the latest Tango revisions were not able to reproduce - although they were with an earlier revision. Either this is a heisenbug, or it may be really gone by now.

Posted: 01/08/09 19:35:25

It's not really a heisenbug, I could reproduce it (WinXP Pro SP3).

dmd 1.033 + tango 0.99.7:
dmd test.d -> object.Exception
dmd -g test.d -> OK

dmd 1.036 or dmd 1.037 + tango-src-SNAPSHOT-20081216 (they wouldn't build tango 0.99.7):
dmd test.d -> object.Exception
dmd -g test.d -> OK

dmd 1.038 or dmd 1.039 + tango-trunk-r4237 (they wouldn't build SNAPSHOT-20081216):
dmd test.d -> OK

So it seems to be gone by now.

BTW
1. the exception is also gone, if you change the code from:

foreach(m; Regex("ab").search("qwerabcabcababqwer"))

to e.g.

scope r = new Regex("ab");
foreach(m; r.search("qwerabcabcababqwer"))

2. using jake or dsss there also was no object.Exception

Posted: 01/08/09 20:13:40

I closed #956 due to above report.

Posted: 01/08/09 20:55:19

I tried TheAddicted?'s code with 0.99.7 and r4237, both built with dmd 1.037. I get the crash with 0.99.7, but not with svn.

Since it's not clear why the bug is gone, it could probably reappear anytime. Looks a bit like a compiler or linker issue.

Posted: 01/08/09 21:30:37

It probably is a compiler bug that can reappear, but as it no longer is reproducable, I don't think it is worth the work to try figuring it out. Just be happy that it is currently solved :)

Posted: 01/09/09 12:50:24

torhu wrote:

I tried TheAddicted?'s code with 0.99.7 and r4237, both built with dmd 1.037.

This is strange - I couldn't build Tango from tango-0.99.7-src with dmd 1.037:
I got an error when running build-dmd.bat:

dmd -c -release -O -inline -w -nofloat  dmain2.d -ofdmain2.obj
warning - util\string.d(29):
Error: implicit conversion of expression (val % 10u + 48u) of type uint to char can cause loss of data

--- errorlevel 1

It wouldn't build tango-base-dmd.lib

Some more test results (including the code of #956):

dmd 1.037 + tango-src-SNAPSHOT-20081216:

dmd foreach(m; Regex("ab").search --> Exception
dmd #956 --> Exception
dmd -g foreach(m; Regex("ab").search --> OK
dmd -g #956 --> OK

dmd 1.037 + trunk-r4237:

dmd foreach(m; Regex("ab").search --> OK
dmd #956 --> OK

dmd 1.037 + trunk-r4239:

dmd foreach(m; Regex("ab").search --> OK
dmd #956 --> OK

dmd 1.039 + trunk-r4239:

dmd foreach(m; Regex("ab").search --> OK
dmd #956 --> OK

So it really seems to be gone by now. Dmd 1.037 showed this error with some version of Tango, but not with the newest versions. Dmd >= 1.038 wouldn't build these older versions of Tango anyway. So I think it's still not clear whether it's dmd or tango.

Posted: 01/09/09 15:34:18

DMD 1.037 builds 0.99.7 with a few extra casts, and maybe some other minor changes, can't remember the detils anymore.

Your test shows that the snapshot from Dec 16 has got the bug, but the Regex module hasn't been changed since Dec 10. So maybe changes in other modules somehow fixed the bug. Shouldn't be hard to narrow it down to a single revision using the 'bisect' method, if someone feels like it.

Posted: 01/09/09 17:15:18

One could start with looking at changes in modules used by tango.text.Regex

Posted: 11/30/10 15:57:38

Hi,

I'm running into the same problem.

import tango.io.Stdout;
import tango.text.Regex;

void main( char [][] args )
{
	auto x1 = Regex("typedef struct").search( "abcd efgh typedef struct asdf qwer asdf ycxv" );
	foreach( m; x1 )
	{
        Stdout.formatln("_{}_", m.match(0) );
	}
}

compiling with jake works.

Compiling with codeblocks fails with the message "Program received signal SIG Unhandle Exception: EXCEPTION_ACCESS_VIOlATOIN(0xc0000005) at 0x000;"

running the Debug version (same which was used for debugging withing codeblocks) from the dos command line, yields the error "object.Exception: Access Violation - Read at address 0x0".

I used tango-0.99.9-bin-win32-dmd.1.056 to use the newest available binaries.

The crash occurrs at line Regex("...")... .

If I do

void main( char [][] args )
{
	scope r = new Regex("typedef struct");
	foreach( m; r.search( "abcd efgh typedef struct asdf qwer asdf ycxv" ) )
	{
        Stdout.formatln("_{}_", m.match(0) );
	}
}

The crash occurrs at ...new Regex... .

Any ideas ?

SpaceRacer?

Posted: 12/01/10 12:25:00

Hm, works for me (WinXP SP3 / dmd 1.065 / tango-r5601):

E:\source\D\tango_0999>type re.d
module re;

import tango.io.Stdout;
import tango.text.Regex;

void main( char [][] args )
{
    scope r = new Regex("typedef struct");
    foreach( m; r.search( "abcd efgh typedef struct asdf qwer" ) )
    {
        Stdout.formatln("_{}_", m.match(0) );
    }
}

E:\source\D\tango_0999>dmd -O -release re.d

E:\source\D\tango_0999>dir re.exe
01.12.2010  13:05           218.652 re.exe

E:\source\D\tango_0999>re
_typedef struct_

E:\source\D\tango_0999>del re.exe
E:\source\D\tango_0999>dmd -g re.d

E:\source\D\tango_0999>dir re.exe
01.12.2010  13:05           469.412 re.exe

E:\source\D\tango_0999>re
_typedef struct_

But generally I avoid the tango regex stuff. It is broken. One can only use it with some fixed regular expressions. When you throw various regular expressions at it, some will work, some will give wrong results, some will take really loooong and some will crash.

When I need regular expressions I either use tangobos and phobos regex

import  std.regexp;
...
scope r = new RegExp("something");

or the pcre that comes with dwin

version(Windows) pragma(lib, "pcre.lib");
import  dwin.text.pcre.RegExp;
...
scope r = new RegExp("something");