Skip to content

Commit

Permalink
Autoconf: Better Unicode Python support in makedep
Browse files Browse the repository at this point in the history
The `open()` commands in `makedep` for reading Fortran source now
includes an `errors=` argument for catching bytes outside of the file
character set.  Unknown characters are replaced with the "unknown"
character (usually �) rather than raising an error.

This avoids problems with Unicode characters and older Pythons which do not
support them, as well as characters from legacy encodings which can
cause errors in Unicode.

Substitution does not break any behavior, since Unicode is only
permitted inside of comment blocks and strings.

This fixes several errors which were silent in `.testing` but were
observed by some users which using autoconf to build their own
executables.
  • Loading branch information
marshallward committed May 22, 2023
1 parent debe45e commit 761d781
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ac/makedep
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ from __future__ import print_function

import argparse
import glob
import io
import os
import re
import sys # used only to get path to current script
import sys


# Pre-compile re searches
Expand Down Expand Up @@ -255,7 +256,7 @@ def scan_fortran_file(src_file):
"""Scan the Fortran file "src_file" and return lists of module defined,
module used, and files included."""
module_decl, used_modules, cpp_includes, f90_includes, programs = [], [], [], [], []
with open(src_file, 'r') as file:
with io.open(src_file, 'r', errors='replace') as file:
lines = file.readlines()
for line in lines:
match = re_module.match(line.lower())
Expand Down

0 comments on commit 761d781

Please sign in to comment.