Fix fuzzy.dll functions on Win32 prebuilt binary
a4lg opened this issue · comments
On fuzzy.dll (in the prebuilt Win32 archive), fuzzy_hash_file
and fuzzy_hash_stream
functions will not work properly if you normally build the program which uses fuzzy.dll with Visual C++.
Cause
Because struct FILE
is managed by separate instance of Microsoft CRT, mixing multiple CRTs (multiple versions or Debug/Release builds) causes problems. Internally, POSIX file descriptor is managed by __pioinfo
and its entry (struct __crt_lowio_handle_data
on UCRT) has corresponding Win32 handle and other information. Since every instance of Microsoft CRT has its own __pioinfo
(note: on universal CRT [VS2015 or later], __pioinfo
is no longer exported), mixing CRT can cause serious inconsistency problems:
- File opened by
fopen
is not considered open. - Different file is referenced.
Potential Errors Passing CRT Objects Across DLL Boundaries: https://msdn.microsoft.com/en-us/library/ms235460.aspx
Possible Resolution
fuzzy.dll references msvcrt.dll
and there's no problem if Win32 program also uses msvcrt.dll
. However, this is very unlikely. Programs built on Visual C++ are normally linked against version-specific CRT and/or universal CRT.
Although it's possible to link against version-specific CRT (but not universal CRT; as of September 2017), it's much safer to build fuzzy.dll on Visual C++. At least, linking against universal CRT (new CRT for Windows; ucrtbase.dll
and API sets) is required to resolve this issue because there will be no version-related issues anymore (there will be however, Debug/Release DLL issues).
- Fix
README
for CRT object sharing (adding/MD
or/MDd
option; will be committed later) - Make
fuzzy.c
,edit_distn.c
andfind-file-size.c
possible to compile on Visual C++ - Make build pipeline to use “platform toolset” feature on Visual C++
- Build fuzzy.dll with multiple platform toolsets (Debug build and Release build):
- Visual Studio 2015 (v140) (mandatory; linked against universal CRT)
- Visual Studio 2013 (v120) (optional)
- Visual Studio 2012 (v110) (optional)
After these changes, Windows build pipeline may be separated from this repository.