Christoph Gohlke added the comment:

Just to confirm: the following script fails with `ImportError: DLL load failed` 
on Python 3.5.0rc2. It fails around the 120th extension. The script passes on 
Python 3.4.3.

Also, Python 3.5.0rc2 (not Python 3.4.3) requires the `extra_postargs=['/DLL']` 
argument to the `link_shared_lib` function, otherwise the linker fails with 
`LINK : fatal error LNK1561: entry point must be defined`.

```
# test_issue24872.py
#
# Build up to 256 C extension modules and import them.
#
# On Python 3.5.0rc2 for Windows this raises "ImportError: DLL load failed:
#   A dynamic link library (DLL) initialization routine failed."
#
# http://bugs.python.org/issue24872

import os
import sys
from importlib import import_module
from distutils import ccompiler

assert sys.platform == 'win32'
assert sys.version_info > (3, 2)

c_source = """/* Minimal Python 3 extension module */
#include "Python.h"
static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT, "%s", NULL, -1, NULL, NULL, NULL, NULL, NULL
};
PyMODINIT_FUNC PyInit_%s(void) { return PyModule_Create(&moduledef); }
"""

cl = ccompiler.new_compiler()

for i in range(256):
    name = '_tmp%.3i' % i
    try:
        os.remove(name+'.pyd')
    except FileNotFoundError:
        pass
    with open(name+'.c', 'w') as fh:
        fh.write(c_source % (name, name))
    objects = cl.compile([name+'.c'])
    cl.link_shared_lib(objects, output_libname=name, extra_postargs=['/DLL'],
                       export_symbols=["PyInit_"+name])
    for ext in 'c', 'obj', 'exp', 'lib':
        os.remove(name+'.'+ext)
    os.rename(name+'.dll', name+'.pyd')
    import_module(name)
```

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24872>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to