summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0dminnimda <0dminnimda@gmail.com>2021-08-31 19:56:12 +0300
committerGitHub <noreply@github.com>2021-08-31 18:56:12 +0200
commit1894e0f7b3e69531edccded47226f169b871dee8 (patch)
tree44eb4cde3c8a9037403ab8ae071a582e1dcd5066
parent8af0271186cc642436306274564986888d5e64c8 (diff)
downloadcython-1894e0f7b3e69531edccded47226f169b871dee8.tar.gz
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
-rw-r--r--Cython/Compiler/Buffer.py10
-rw-r--r--Cython/TestUtils.py41
2 files changed, 40 insertions, 11 deletions
diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py
index ce8503626..e33a95e29 100644
--- a/Cython/Compiler/Buffer.py
+++ b/Cython/Compiler/Buffer.py
@@ -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:
diff --git a/Cython/TestUtils.py b/Cython/TestUtils.py
index d5abacaa6..56f1dfa2e 100644
--- a/Cython/TestUtils.py
+++ b/Cython/TestUtils.py
@@ -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)