tools/generate_stubs/generate_stubs.py
def StubFunction(cls, signature):
    """Generates a stub function definition for the given signature.

    The function definitions are created with __attribute__((weak)) so that
    they may be overridden by a real static link or mock versions to be used
    when testing.

    Args:
      signature: A signature hash, as produced by ParseSignatures,
                 representing the function signature.

    Returns:
      A string with the stub function definition.
    """
    return_prefix = ''
    if signature['return_type'] != 'void':
      return_prefix = 'return '

    # Generate the argument list.
    arguments = [
        re.split('[\*& ]', arg)[-1].strip() for arg in signature['params']
    ]
    # Remove square brackets from arrays, otherwise we will end with a
    # compilation failure.
    for i in range(0, len(arguments)):
      if arguments[i].endswith('[]'):
        arguments[i] = arguments[i][0:-2]

    arg_list = ', '.join(arguments)
    if arg_list == 'void':
      arg_list = ''

    if arg_list != '' and len(arguments) > 1 and arguments[-1] == '...':
      # If the last argument is ... then this is a variadic function.
      if return_prefix != '':
        return VARIADIC_STUB_FUNCTION_DEFINITION % {
            'return_type': signature['return_type'],
            'name': signature['name'],
            'params': ', '.join(signature['params']),
            'arg_list': ', '.join(arguments[0:-1]),
            'last_named_arg': arguments[-2],
            'export': signature.get('export', '')
        }
      else:
        return VOID_VARIADIC_STUB_FUNCTION_DEFINITION % {
            'name': signature['name'],
            'params': ', '.join(signature['params']),
            'arg_list': ', '.join(arguments[0:-1]),
            'last_named_arg': arguments[-2],
            'export': signature.get('export', '')
        }
    else:
      # This is a regular function.
      return STUB_FUNCTION_DEFINITION % {
          'return_type': signature['return_type'],
          'name': signature['name'],
          'params': ', '.join(signature['params']),
          'return_prefix': return_prefix,
          'arg_list': arg_list,
          'export': signature.get('export', '')
      }
Generates a stub function definition for the given signature.

    The function definitions are created with __attribute__((weak)) so that
    they may be overridden by a real static link or mock versions to be used
    when testing.

    Args:
      signature: A signature hash, as produced by ParseSignatures,
                 representing the function signature.

    Returns:
      A string with the stub function definition.
    
Generates a stub function definition for the given signature.
The function definitions are created with __attribute__((weak)) so that
they may be overridden by a real static link or mock versions to be used
when testing.
Generates a stub function definition for the given signature . The function definitions are created with __attribute__ (( weak )) so that they may be overridden by a real static link or mock versions to be used when testing .
def StubFunction(cls, signature):
    return_prefix = ''
    if signature['return_type'] != 'void':
      return_prefix = 'return '
    arguments = [
        re.split('[\*& ]', arg)[-1].strip() for arg in signature['params']
    ]
    for i in range(0, len(arguments)):
      if arguments[i].endswith('[]'):
        arguments[i] = arguments[i][0:-2]
    arg_list = ', '.join(arguments)
    if arg_list == 'void':
      arg_list = ''
    if arg_list != '' and len(arguments) > 1 and arguments[-1] == '...':
      if return_prefix != '':
        return VARIADIC_STUB_FUNCTION_DEFINITION % {
            'return_type': signature['return_type'],
            'name': signature['name'],
            'params': ', '.join(signature['params']),
            'arg_list': ', '.join(arguments[0:-1]),
            'last_named_arg': arguments[-2],
            'export': signature.get('export', '')
        }
      else:
        return VOID_VARIADIC_STUB_FUNCTION_DEFINITION % {
            'name': signature['name'],
            'params': ', '.join(signature['params']),
            'arg_list': ', '.join(arguments[0:-1]),
            'last_named_arg': arguments[-2],
            'export': signature.get('export', '')
        }
    else:
      return STUB_FUNCTION_DEFINITION % {
          'return_type': signature['return_type'],
          'name': signature['name'],
          'params': ', '.join(signature['params']),
          'return_prefix': return_prefix,
          'arg_list': arg_list,
          'export': signature.get('export', '')
      }
def StubFunction ( cls , signature ) : return_prefix = '' if signature [ 'return_type' ] != 'void' : return_prefix = 'return ' arguments = [ re . split ( '[\*& ]' , arg ) [ - 1 ] . strip ( ) for arg in signature [ 'params' ] ] for i in range ( 0 , len ( arguments ) ) : if arguments [ i ] . endswith ( '[]' ) : arguments [ i ] = arguments [ i ] [ 0 : - 2 ] arg_list = ', ' . join ( arguments ) if arg_list == 'void' : arg_list = '' if arg_list != '' and len ( arguments ) > 1 and arguments [ - 1 ] == '...' : if return_prefix != '' : return VARIADIC_STUB_FUNCTION_DEFINITION % { 'return_type' : signature [ 'return_type' ] , 'name' : signature [ 'name' ] , 'params' : ', ' . join ( signature [ 'params' ] ) , 'arg_list' : ', ' . join ( arguments [ 0 : - 1 ] ) , 'last_named_arg' : arguments [ - 2 ] , 'export' : signature . get ( 'export' , '' ) } else : return VOID_VARIADIC_STUB_FUNCTION_DEFINITION % { 'name' : signature [ 'name' ] , 'params' : ', ' . join ( signature [ 'params' ] ) , 'arg_list' : ', ' . join ( arguments [ 0 : - 1 ] ) , 'last_named_arg' : arguments [ - 2 ] , 'export' : signature . get ( 'export' , '' ) } else : return STUB_FUNCTION_DEFINITION % { 'return_type' : signature [ 'return_type' ] , 'name' : signature [ 'name' ] , 'params' : ', ' . join ( signature [ 'params' ] ) , 'return_prefix' : return_prefix , 'arg_list' : arg_list , 'export' : signature . get ( 'export' , '' ) }
Generates a stub function definition for the given signature.
Generates a stub function definition for the given signature .
"""Generates a stub function definition for the given signature.

    The function definitions are created with __attribute__((weak)) so that
    they may be overridden by a real static link or mock versions to be used
    when testing.

    Args:
      signature: A signature hash, as produced by ParseSignatures,
                 representing the function signature.

    Returns:
      A string with the stub function definition.
    """ # Generate the argument list. # Remove square brackets from arrays, otherwise we will end with a # compilation failure. # If the last argument is ... then this is a variadic function. # This is a regular function.
A string with the stub function definition.
A string with the stub function definition .
cls
signature
A signature hash, as produced by ParseSignatures,
representing the function signature.
A signature hash as produced by ParseSignatures representing the function signature .