diff options
author | Erlend E. Aasland <erlend.aasland@protonmail.com> | 2023-05-07 21:55:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-07 21:55:37 (GMT) |
commit | ac020624b32820e8e6e272122b94883f8e75ac61 (patch) | |
tree | f6e92d3cd4a54e10df22f65efa3e2c17460788c3 | |
parent | 06c2a4858b8806abc700a0471434067910db54ec (diff) | |
download | cpython-ac020624b32820e8e6e272122b94883f8e75ac61.zip cpython-ac020624b32820e8e6e272122b94883f8e75ac61.tar.gz cpython-ac020624b32820e8e6e272122b94883f8e75ac61.tar.bz2 |
gh-64660: Don't hardcode Argument Clinic return converter result variable name (#104200)
-rwxr-xr-x | Tools/clinic/clinic.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 7043256..a6f330d 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -356,6 +356,7 @@ class CRenderData: # you should check the _return_value for errors, and # "goto exit" if there are any. self.return_conversion = [] + self.converter_retval = "_return_value" # The C statements required to do some operations # after the end of parsing but before cleaning up. @@ -3893,15 +3894,15 @@ class CReturnConverter(metaclass=CReturnConverterAutoRegister): def return_converter_init(self): pass - def declare(self, data, name="_return_value"): + def declare(self, data): line = [] add = line.append add(self.type) if not self.type.endswith('*'): add(' ') - add(name + ';') + add(data.converter_retval + ';') data.declarations.append(''.join(line)) - data.return_value = name + data.return_value = data.converter_retval def err_occurred_if(self, expr, data): data.return_conversion.append('if (({}) && PyErr_Occurred()) {{\n goto exit;\n}}\n'.format(expr)) @@ -3923,8 +3924,10 @@ class bool_return_converter(CReturnConverter): def render(self, function, data): self.declare(data) - self.err_occurred_if("_return_value == -1", data) - data.return_conversion.append('return_value = PyBool_FromLong((long)_return_value);\n') + self.err_occurred_if(f"{data.converter_retval} == -1", data) + data.return_conversion.append( + f'return_value = PyBool_FromLong((long){data.converter_retval});\n' + ) class long_return_converter(CReturnConverter): type = 'long' @@ -3934,9 +3937,10 @@ class long_return_converter(CReturnConverter): def render(self, function, data): self.declare(data) - self.err_occurred_if("_return_value == {}-1".format(self.unsigned_cast), data) + self.err_occurred_if(f"{data.converter_retval} == {self.unsigned_cast}-1", data) data.return_conversion.append( - ''.join(('return_value = ', self.conversion_fn, '(', self.cast, '_return_value);\n'))) + f'return_value = {self.conversion_fn}({self.cast}{data.converter_retval});\n' + ) class int_return_converter(long_return_converter): type = 'int' @@ -3978,9 +3982,10 @@ class double_return_converter(CReturnConverter): def render(self, function, data): self.declare(data) - self.err_occurred_if("_return_value == -1.0", data) + self.err_occurred_if(f"{data.converter_retval} == -1.0", data) data.return_conversion.append( - 'return_value = PyFloat_FromDouble(' + self.cast + '_return_value);\n') + f'return_value = PyFloat_FromDouble({self.cast}{data.converter_retval});\n' + ) class float_return_converter(double_return_converter): type = 'float' |