This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: get_msvcr() returns None rather than []
Type: Stage: resolved
Components: Distutils, Distutils2 Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7, 3rd party
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: eric.araujo Nosy List: eric.araujo, gesserat, lkcl, rpetrov, schmir, terry.reedy
Priority: normal Keywords:

Created on 2009-01-24 17:50 by lkcl, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg80466 - (view) Author: Luke Kenneth Casson Leighton (lkcl) Date: 2009-01-24 17:50
def get_msvcr():
    """Include the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    """
    msc_pos = sys.version.find('MSC v.')
    if msc_pos != -1:
        msc_ver = sys.version[msc_pos+6:msc_pos+10]
        if msc_ver == '1300':
            # MSVC 7.0
            return ['msvcr70']
        elif msc_ver == '1310':
            # MSVC 7.1
            return ['msvcr71']
        elif msc_ver == '1400':
            # VS2005 / MSVC 8.0
            return ['msvcr80']
        elif msc_ver == '1500':
            # VS2008 / MSVC 9.0
            return ['msvcr90']
        else:
            raise ValueError("Unknown MS Compiler version %i " % msc_Ver)

    return [] <<<<<<<<-----
msg80471 - (view) Author: Roumen Petrov (rpetrov) * Date: 2009-01-24 19:04
My comment on this part of code is( from issue3871): 
+    # FIXME: next code is from issue870382
+    # MS C-runtime libraries never support backward compatibility.
+    # Linking to a different library without to specify correct runtime
+    # version for the headers will link renamed functions to msvcrt.
+    # See issue3308: this piece of code is python problem even
+    # with correct w32api headers.
+    # Issue: for MSVC compiler we can get the version and from version
+    # to determine mcvcrt as code below. But what about if python is
+    # build with GCC compiler?
+    # Output of sys.version is information for python build on first
+    # line, on the next line is information for the compiler and the
+    # output lack information for the C-runtime.

My vote is to remove function get_msvcr() from cygwinccompiler.py.
msg122632 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-28 05:31
Can you explain what the bug is?  Thanks in advance.
msg122639 - (view) Author: Luke Kenneth Casson Leighton (lkcl) Date: 2010-11-28 07:53
i'm really sorry, eric, but the decision to ban me from interacting with python developers for 18 months+ has left me with zero working knowledge of many of these complex issues which i was heavily and actively involved in at the time, and could have answered immediately.

the opportunity to interact with me and to move the mingw32 port forward was "at the time", not 18+ months later.

i've since *removed* the highly complex development environment which was tricky as hell to set up (mingw32 cross compiler, mingw32 native compiler, python, native python, wine, MSYS under wine, python-win32 under wine) because it was declared that the work being carried out was worthless.

i'll have to leave it to roumen to answer this one.

l.
msg122680 - (view) Author: Roumen Petrov (rpetrov) * Date: 2010-11-28 16:37
a) NoneType object is not iterable. If the function don't return empty list later distutil will fail on the lines like  libraries.extend(self.dll_libraries)

b) method for detection of a msvc runtime is not correct. If the method return a library GCC will link to two c-runtimes. Also some function dearation are not visible if is not specified appropriate preprocessor directive.

So I could not found reason this method to exist .
msg137202 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-05-29 17:21
Thanks for explaining.

> a) NoneType object is not iterable. If the function don't return empty list
> later distutil will fail

Possible fix: self.dll_libraries = get_msvcr() or []

> method for detection of a msvc runtime is not correct. If the method
> return a library GCC will link to two c-runtimes. Also some function
> dearation are not visible if is not specified appropriate
> preprocessor directive.

Can you propose fixes for those?  Also, how to test it?

> So I could not found reason this method to exist .

“Include the appropriate MSVC runtime library if Python was built with MSVC 7.0 or later.”
msg379355 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-10-22 21:22
The claimed bug is that when msc_pos is -1 in the code as posted, 'return []' should be executed, but None is returned instead.  When I add 'msc_pos = -1 before the if statement, and call the function, after adding the needed sys import, [] is indeed returned.

The final elif return has two bugs, '%i' and 'Ver':
raise ValueError("Unknown MS Compiler version %i " % msc_Ver)  # Posted
raise ValueError("Unknown MS Compiler version %s " % msc_ver)  # Fixed

With this fix and without -1 forced, the ValueError is raised on all current versions, so this code is out of date in any case.
msg414526 - (view) Author: Alex Zunegin (gesserat) Date: 2022-03-04 13:49
This messes up building Cython extensions on MSYS2 and MINGW. Still here as of setuptools 60. 

There is no line 
```
    return [] <<<<<<<<-----
```
at the end. Adding it helps.
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49293
2022-03-04 13:49:52gesseratsetnosy: + gesserat
messages: + msg414526
2020-10-22 21:22:40terry.reedysetstatus: open -> closed

nosy: + terry.reedy
messages: + msg379355

resolution: not a bug
stage: resolved
2011-06-01 20:48:41schmirsetnosy: + schmir
2011-05-29 17:21:41eric.araujosetmessages: + msg137202
versions: + Python 3.3
2010-11-28 16:37:15rpetrovsetmessages: + msg122680
2010-11-28 07:53:55lkclsetmessages: + msg122639
2010-11-28 05:31:52eric.araujosetversions: + 3rd party, Python 3.1, Python 3.2
nosy: + eric.araujo

messages: + msg122632

assignee: eric.araujo
components: + Distutils, Distutils2, - Build
2009-01-24 19:04:53rpetrovsetnosy: + rpetrov
messages: + msg80471
2009-01-24 17:50:49lkclcreate