Skip to content

Commit

Permalink
Build: Implement hack for Cython 3.0.9 generated source file.
Browse files Browse the repository at this point in the history
  • Loading branch information
scoder committed Mar 24, 2024
1 parent 764b1ba commit 7757f46
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,32 @@ def prepare_extensions(use_cython=True):
if cythonize is not None:
ext_modules = cythonize(ext_modules)

# Fix compiler warning due to missing pragma-push in Cython 3.0.9.
for ext in ext_modules:
for source_file in ext.sources:
if not os.path.basename(source_file).startswith('lua') or not source_file.endswith('.c'):
continue
with open(source_file, 'rb') as f:
lines = f.readlines()
if b'Generated by Cython 3.0.9' not in lines[0]:
continue

modified = False
temp_file = source_file + ".tmp"
with open(temp_file, 'wb') as f:
last_was_push = False
for line in lines:
if b'#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"' in line and not last_was_push:
f.write(b"#pragma GCC diagnostic push\n")
modified = True
last_was_push = b'#pragma GCC diagnostic push' in line
f.write(line)
if modified:
print("Fixed Cython 3.0.9 generated source file " + source_file)
os.rename(temp_file, source_file)
else:
os.unlink(temp_file)

return ext_modules, ext_libraries


Expand Down

0 comments on commit 7757f46

Please sign in to comment.