Skip to content

Escaping Inputs to regular expressions. #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tools/amd_build/pyHIPIFY/hipify-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def disable_asserts(input_string):


def replace_forceinline(input_string):
"""__forceinline__'d methods can cause 'symbol multiply defined' errors in HIP.
"""__forceinline__'d methods can cause 'symbol multiply defined' errors in HIP.
Adding 'static' to all such methods leads to compilation errors, so
replacing '__forceinline__' with 'inline' as a workaround
https://github.com/ROCm-Developer-Tools/HIP/blob/master/docs/markdown/hip_faq.md#what-if-hip-generates-error-of-symbol-multiply-defined-only-on-amd-machine
Expand Down Expand Up @@ -681,9 +681,9 @@ def preprocessor(filepath, stats, hipify_caffe2):

if cuda_type in output_source:
if hipify_caffe2:
pattern = r'({0})'.format(cuda_type)
pattern = r'({0})'.format(re.escape(cuda_type))
else:
pattern = r'(\b{0}\b)'.format(cuda_type)
pattern = r'(\b{0}\b)'.format(re.escape(cuda_type))
output_source = re.sub(pattern, hip_type, output_source)

# Perform Kernel Launch Replacements
Expand All @@ -706,7 +706,7 @@ def file_specific_replacement(filepath, search_string, replace_string, strict=Fa
with openf(filepath, "r+") as f:
contents = f.read()
if strict:
contents = re.sub(r'\b({0})\b'.format(search_string), lambda x: replace_string, contents)
contents = re.sub(r'\b({0})\b'.format(re.escape(search_string)), lambda x: replace_string, contents)
else:
contents = contents.replace(search_string, replace_string)
f.seek(0)
Expand Down Expand Up @@ -824,7 +824,7 @@ def disable_unsupported_function_call(function, input_string, replacement):
output_string = input_string

# Find all calls to the function
calls = re.finditer(r"\b{0}\b".format(function), input_string)
calls = re.finditer(r"\b{0}\b".format(re.escape(function)), input_string)

# Do replacements
for call in calls:
Expand Down Expand Up @@ -983,7 +983,7 @@ def replace_arg(match):
if "THCUNN" in filepath.split("/") and "generic" not in filepath.split("/"):
kernel_name_with_template = kernel_name_with_template.replace("<real>", "<Dtype>")

full_new_kernel_launch = re.sub(r'\b{0}\b'.format(original_kernel_name_with_template),
full_new_kernel_launch = re.sub(r'\b{0}\b'.format(re.escape(original_kernel_name_with_template)),
lambda x: kernel_name_with_template, full_new_kernel_launch)

# Replace Launch
Expand Down Expand Up @@ -1181,7 +1181,7 @@ def main():

# Disable Constants w\ Boundary.
for const in constants:
txt = re.sub(r"\b{0}\b".format(const), constants[const], txt)
txt = re.sub(r"\b{0}\b".format(re.escape(const)), constants[const], txt)

# Disable Constants
for s_const in s_constants:
Expand Down