question on msvcrt.dll versioning

"Martin v. Löwis" martin at v.loewis.de
Thu Mar 12 16:20:09 EDT 2009


rogerdpack wrote:
> It appears from sites like
> http://www.develer.com/oss/GccWinBinaries
> at the bottom that at least this developer made an effort to link
> against the same version of msvcrt.dll that the python exe was
> compiled with [ex: vc2008 -> msvcr90.dll].  Is this pain necessary?

It depends on fine details of your extension module whether it is
necessary or not.

> Are there known drawbacks to not doing this anyone can think of?

Sure. It might be that Python crashes if you use a different CRT.

More specifically, if you link several CRTs into a single operating
system process, they get each its own set of CRT global variables.
Modifying a global in one CRT doesn't affect the others; passing
pointers to such globals around may cause bad behavior.

Even more specifically, the following globals in the CRT are known
to be problematic:
- each CRT maintains its own heap. So memory allocated by malloc()
  in one CRT, and released with free() in a different one won't
  get back to the free list of the first CRT. As a consequence,
  the memory will fragment, and you get memory leaks.
- each CRT has its own locale and time zone settings. Setting the locale
  in one CRT won't have effect on the other CRTs.
- each CRT has its own set of struct FILE. As a consequence, passing
  FILE* across CRT boundaries will crash the CRT, as the MT fields
  of struct FILE won't be where the CRT expects them.

Yet more specifically: if the extension module or Python host opens
a file with fopen(), and passes it to PyRun_{Any|Simple}File[Ex][Flags],
Python will crash.

HTH,
Martin

P.S. There may be more cases in which you get crashes - the list above
includes just the known ones.



More information about the Python-list mailing list