Opened 14 years ago
Last modified 14 years ago
#1294 closed defect (fixed)
The new parser inserts a CR character before every CRLF in strings
Reported by: | Adrian Pop | Owned by: | Adrian Pop |
---|---|---|---|
Priority: | critical | Milestone: | Red October |
Component: | Parser | Version: | 1.6.0 |
Keywords: | Cc: | Adrian Pop, dhedberg, Martin Sjölund |
Description
From Daniel Hedberg @ MathCore.
We have encountered a nasty bug in the new Modelica parser.
I have attached a mo file and a corresponding mos file for you to test.
The script simply loads the mo file and saves it again, and then attempts to
load the mo file again, which fails!
If you take a look at the mo file before and after you will notice that the parser
or something inserts a CR character before every CRLF in strings for some reason.
This is of course a highly critical bug for us.
{{{model A
annotation(Documentation(info="line1
line2"));
end A;}}}
{{{loadFile("A.mo");
list();
save(A);
loadFile("A.mo");
getErrorString();}}}
Attachments (1)
Change History (7)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
I really need to see that script; possibly also run it in Windows since it seems to parse correctly in Linux...
{{{$ cat crlf.mos | hexdump -C
00000000 22 61 62 0d 0a 63 22 0d 0a |"ab..c"..|
00000009
trunk marsj@marsj-laptop:~/tmp
$ omc crlf.mos | hexdump -C
00000000 22 61 62 0d 0a 63 22 0a |"ab..c".|
00000008
}}}
(The trailing CRLF becomes LF, but that's because we separate statements with \n)
comment:3 by , 14 years ago
Added the mo and mos-file as Wiki markup since attachments seemed to fail for Daniel.
comment:4 by , 14 years ago
This is a bug in the MinGW (or Win32) runtime. fprintf(stderr, "\r\n") is printed as CRCRLF (why did it take me 4 hours to realize it was fprint that did this and not ANTLR?).
It's fixed in the trunk by postprocessing the string to replace CRLF with LF (only on Windows).
comment:5 by , 14 years ago
Well, it seems that if we open a file in text mode in Windows, writing {{\r\n}} to it
actually writes {{\r\r\n}} because the default {{\n}} in Windows is {{\r\n}}.
I now open System.writeFile and Print.writeBuf in binary modes "wb" and that writes
the actual string as it is.
comment:6 by , 14 years ago
Well, I now open the files in "rt" and "wt" in Windows and this should finally fix this problem.
Note that this will be fixed also by a new RML/MetaModelica where string literal \n
will be encoded as \r\n
in Windows. This will allow us to open all files in binary mode
which is a bit faster as you can fread the entire file size directly.
Daniel, can you attach the .mos script and .mo file to this bug?
You haven't send it in the email.