Menu

#2534 Bug in ucsim when compiled/run on Windows with msys2/mingw-w64

closed-fixed
None
Simulator
5
2016-08-08
2016-08-06
No

I building SDCC on Windows using the sdcc-src-20160804-9709.tar.bz2 snapshot.

My build setup is Windows 7 x64, running an up-to-date msys2/mingw-w64 environment, and using the 32-bit mingw toolchain.

SDCC/SDAS/SDLD all build and run fine, but I'm having trouble getting UCSIM running correctly.

When I run the simulator under msys2, for example SHC08.EXE, the screen hangs and then fill the screen with print outs of the error message "Can't select: 10093 fid=0 handle=000001fc type=3".

I've traced this to fwio.cc where the Winsock dll is being used in cl_io::determine_type() before the dll has been initialized by a call to the init_winsock() function.

It looks like this occurs when running under the msys2 terminal, but not when SHC08.EXE is run from a regular Windows command prompt, which looks to be because fwio.cc is not detecting the terminal environment as a character device when run inside the msys2 terminal.

Whatever the reason, the current code flow has a use-before-initialize problem that can occur in certain environments.

The init_winsock() function itself also has another bug in it, in that it never sets the is_initialized variable.

I've fixed is_initialized, and switched the code around so that Winsock is initialized in the cl_io::cl_io() constructor in order to be sure that it is initialized before the functions are used.

Prehaps you guys know a better location to do the initialization, perhaps in cl_io::determine_type()?

I wasn't sure that cl_io::determine_type() would always be called, so I put the initialization in the constructor, even though that's not generally good practice.

I'm attaching my patch.

1 Attachments

Discussion

  • Daniel Drotos

    Daniel Drotos - 2016-08-08
    • status: open --> open-fixed
    • assigned_to: Daniel Drotos
     
  • Daniel Drotos

    Daniel Drotos - 2016-08-08

    Thank you for the patch, applied in [r9714].

     
  • Ben Shi

    Ben Shi - 2016-08-08
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.