Commit 1894e0f7 authored by 0dminnimda's avatar 0dminnimda Committed by GitHub

Fix some bugs on Windows (GH-4331)

* Avoid usage of `const` or `volatile` in buffer struct field declarations.
* Avoid newline replacement in the test helper functions `write_file()` and `write_newer_file()`.

See https://github.com/cython/cython/pull/4324
parent 8af02711
......@@ -678,9 +678,17 @@ def get_type_information_cname(code, dtype, maxdepth=None):
types = [get_type_information_cname(code, f.type, maxdepth - 1)
for f in fields]
typecode.putln("static __Pyx_StructField %s[] = {" % structinfo_name, safe=True)
if dtype.is_cv_qualified:
# roughly speaking, remove "const" from struct_type
struct_type = dtype.cv_base_type.empty_declaration_code()
else:
struct_type = dtype.empty_declaration_code()
for f, typeinfo in zip(fields, types):
typecode.putln(' {&%s, "%s", offsetof(%s, %s)},' %
(typeinfo, f.name, dtype.empty_declaration_code(), f.cname), safe=True)
(typeinfo, f.name, struct_type, f.cname), safe=True)
typecode.putln(' {NULL, NULL, 0}', safe=True)
typecode.putln("};", safe=True)
else:
......
......@@ -228,23 +228,44 @@ def unpack_source_tree(tree_file, workdir, cython_root):
return workdir, header
def write_file(file_path, content, dedent=False):
"""
Write some content (text or bytes) to the file at "file_path".
def write_file(file_path, content, dedent=False, encoding=None):
r"""Write some content (text or bytes) to the file
at `file_path` without translating `'\n'` into `os.linesep`.
The default encoding is `'utf-8'`.
"""
mode = 'wb' if isinstance(content, bytes) else 'w'
if isinstance(content, bytes):
mode = "wb"
# binary mode doesn't take an encoding and newline arguments
newline = None
default_encoding = None
else:
mode = "w"
# any "\n" characters written are not translated
# to the system default line separator, os.linesep
newline = "\n"
default_encoding = "utf-8"
if encoding is None:
encoding = default_encoding
if dedent:
content = textwrap.dedent(content)
with open(file_path, mode=mode) as f:
with open(file_path, mode=mode, encoding=encoding, newline=newline) as f:
f.write(content)
def write_newer_file(file_path, newer_than, content, dedent=False):
"""
Write 'content' to the file 'file_path' and make sure it is newer than the file 'newer_than'.
def write_newer_file(file_path, newer_than, content, dedent=False, encoding=None):
r"""
Write `content` to the file `file_path` without translating `'\n'`
into `os.linesep` and make sure it is newer than the file `newer_than`.
The default encoding is `'utf-8'` (same as for `write_file`).
"""
write_file(file_path, content, dedent=dedent)
write_file(file_path, content, dedent=dedent, encoding=encoding)
try:
other_time = os.path.getmtime(newer_than)
......@@ -253,4 +274,4 @@ def write_newer_file(file_path, newer_than, content, dedent=False):
other_time = None
while other_time is None or other_time >= os.path.getmtime(file_path):
write_file(file_path, content, dedent=dedent)
write_file(file_path, content, dedent=dedent, encoding=encoding)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment