sapling/tests/test-check-win32-signature.py
Jun Wu 881e8a9831 win32: add explicit signature for GetProcessTimes
Summary:
Instead of relying on ctypes' default type guess being correct, let's provide
the function signature of GetProcessTimes explicitly.

This resolves an issue where the new interpreter raises
`WindowsError: [Error 6] The handle is invalid.`.

Reviewed By: ikostia

Differential Revision: D15912516

fbshipit-source-id: 4fbb0de918d8a95ff665ae1b89494ed91e3fa8d3
2019-06-20 11:18:24 -07:00

26 lines
807 B
Python

# Copyright 2019 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
import os
import re
def checkpath(path, dllnames):
content = open(path).read()
for name in dllnames:
for matched in sorted(set(re.findall(r"%s\.[^(.]*\(" % name, content))):
# remove tailing "("
funcname = matched[:-1]
for expected in ["%s.argtypes" % funcname, "%s.restype" % funcname]:
if expected not in content:
print("%s needs explicit argtypes and restype" % funcname)
break
checkpath(
"%s/../edenscm/mercurial/win32.py" % os.environ.get("RUNTESTDIR", "."),
["_kernel32", "_advapi32", "_user32", "_crypt32"],
)