| 93 | os.system(do_script) |
| 94 | |
| 95 | def fix_uplink(): |
| 96 | # uplink.c tries to find the OPENSSL_Applink function exported from the current |
| 97 | # executable. However, we export it from _ssl[_d].pyd instead. So we update the |
| 98 | # module name here before building. |
| 99 | with open('ms\\uplink.c', 'r', encoding='utf-8') as f1: |
| 100 | code = list(f1) |
| 101 | os.replace('ms\\uplink.c', 'ms\\uplink.c.orig') |
| 102 | already_patched = False |
| 103 | with open('ms\\uplink.c', 'w', encoding='utf-8') as f2: |
| 104 | for line in code: |
| 105 | if not already_patched: |
| 106 | if re.search('MODIFIED FOR CPYTHON _ssl MODULE', line): |
| 107 | already_patched = True |
| 108 | elif re.match(r'^\s+if\s*\(\(h\s*=\s*GetModuleHandle[AW]?\(NULL\)\)\s*==\s*NULL\)', line): |
| 109 | f2.write("/* MODIFIED FOR CPYTHON _ssl MODULE */\n") |
| 110 | f2.write('if ((h = GetModuleHandleW(L"_ssl.pyd")) == NULL) if ((h = GetModuleHandleW(L"_ssl_d.pyd")) == NULL)\n') |
| 111 | already_patched = True |
| 112 | f2.write(line) |
| 113 | if not already_patched: |
| 114 | print("WARN: failed to patch ms\\uplink.c") |
| 115 | |
| 116 | def prep(arch): |
| 117 | makefile_template = "ms\\ntdll{}.mak" |