Bug 19910 – ImportVisitor example fails to parse random files
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2019-05-28T18:06:53Z
Last change time
2023-04-18T13:46:14Z
Assigned to
No Owner
Creator
GoaLitiuM
Comments
Comment #0 by goalitium — 2019-05-28T18:06:53Z
The Import Visitor example (from here: https://github.com/dlang/dmd/blob/master/src/examples/impvisitor.d ) with some slight modifications (here: https://gist.github.com/GoaLitiuM/841be5bf808a9b20f4b39ddcdf1edf70 )...
... Seems to fail parsing some files and usually print weird errors like these:
package.d(8): Error: Invalid trailing code unit
package.d(8): Error: Outside Unicode code space
package.d(8): Error: char 0x009b not allowed in identifier
package.d(8): Error: Outside Unicode code space
package.d(8): Error: character 0x9b is not a valid token
package.d(8): Error: character 0x02 is not a valid token
package.d(8): Error: no identifier for declarator `type`
Enabling garbage collector seems to cause different files to pass and other files to fail instead, usually followed by a crash. I was also suggested to try a slightly altered version of the example with the proper DMD initialization and deinitialization, but it had no effect on this issue.
Comment #1 by goalitium — 2019-10-06T14:12:29Z
It looks like the Parser expects the input string to be null-terminated, so the extra garbage is just random data past the given string. Simply appending the null character to the file content fixes this, so maybe the example needs to be adjusted for that?
Comment #2 by razvan.nitu1305 — 2023-04-18T13:46:14Z