mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-20 12:40:47 +00:00
Guard the macro definition
It doesn't make sense to define a macro expanding to a non-existent function. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
d022093ea6
commit
f838eb2259
@ -277,21 +277,16 @@ extern "C" {{
|
||||
if wrapper.guard is not None:
|
||||
out.write('#endif /* {} */\n'.format(wrapper.guard))
|
||||
|
||||
def _write_h_function(self, out: typing_util.Writable,
|
||||
function: FunctionInfo,
|
||||
wrapper: WrapperInfo) -> None:
|
||||
def _write_h_function_declaration(self, out: typing_util.Writable,
|
||||
function: FunctionInfo,
|
||||
wrapper: WrapperInfo) -> None:
|
||||
"""Write the declaration of one wrapper function.
|
||||
"""
|
||||
out.write('\n')
|
||||
if wrapper.guard is not None:
|
||||
out.write('#if {}\n'.format(wrapper.guard))
|
||||
self._write_function_prototype(out, function, wrapper, True)
|
||||
if wrapper.guard is not None:
|
||||
out.write('#endif /* {} */\n'.format(wrapper.guard))
|
||||
|
||||
def _write_h_macro(self, out: typing_util.Writable,
|
||||
function: FunctionInfo,
|
||||
wrapper: WrapperInfo) -> None:
|
||||
def _write_h_macro_definition(self, out: typing_util.Writable,
|
||||
function: FunctionInfo,
|
||||
wrapper: WrapperInfo) -> None:
|
||||
"""Write the macro definition for one wrapper.
|
||||
"""
|
||||
arg_list = ', '.join(wrapper.argument_names)
|
||||
@ -300,6 +295,26 @@ extern "C" {{
|
||||
wrapper_name=wrapper.wrapper_name,
|
||||
args=arg_list))
|
||||
|
||||
def _write_h_function(self, out: typing_util.Writable,
|
||||
function: FunctionInfo) -> None:
|
||||
"""Write the complete header content for one wrapper.
|
||||
|
||||
This is the declaration of the wrapper function, and the
|
||||
definition of a function-like macro that calls the wrapper function.
|
||||
|
||||
Do nothing if the function is skipped.
|
||||
"""
|
||||
wrapper = self._wrapper_info(function)
|
||||
if wrapper is None:
|
||||
return
|
||||
out.write('\n')
|
||||
if wrapper.guard is not None:
|
||||
out.write('#if {}\n'.format(wrapper.guard))
|
||||
self._write_h_function_declaration(out, function, wrapper)
|
||||
self._write_h_macro_definition(out, function, wrapper)
|
||||
if wrapper.guard is not None:
|
||||
out.write('#endif /* {} */\n'.format(wrapper.guard))
|
||||
|
||||
def write_c_file(self, filename: str) -> None:
|
||||
"""Output a whole C file containing function wrapper definitions."""
|
||||
with open(filename, 'w', encoding='utf-8') as out:
|
||||
@ -319,13 +334,8 @@ extern "C" {{
|
||||
self.header_guard = self._header_guard_from_file_name(filename)
|
||||
with open(filename, 'w', encoding='utf-8') as out:
|
||||
self._write_prologue(out, True)
|
||||
for name in sorted(self.functions.keys()):
|
||||
function = self.functions[name]
|
||||
wrapper = self._wrapper_info(function)
|
||||
if wrapper is None:
|
||||
continue
|
||||
self._write_h_function(out, function, wrapper)
|
||||
self._write_h_macro(out, function, wrapper)
|
||||
for name in sorted(self.functions):
|
||||
self._write_h_function(out, self.functions[name])
|
||||
self._write_epilogue(out, True)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user