'Replace \'UNBOUND_METHOD(type, "name")\' by a constant Python identifier cname.'

def inject_unbound_methods(self, impl, output):

    if ('CALL_UNBOUND_METHOD(' not in impl):
        return (False, impl)
    utility_code = set()
    def externalise(matchobj):
        (type_cname, method_name, args) = matchobj.groups()
        args = [arg.strip() for arg in args[1:].split(',')]
        if (len(args) == 1):
            call = '__Pyx_CallUnboundCMethod0'
            utility_code.add('CallUnboundCMethod0')
        elif (len(args) == 2):
            call = '__Pyx_CallUnboundCMethod1'
            utility_code.add('CallUnboundCMethod1')
        else:
            assert False, 'CALL_UNBOUND_METHOD()    requires    1    or    2    call    arguments'
        cname = output.get_cached_unbound_method(type_cname, method_name, len(args))
        return ('%s(&%s,    %s)' % (call, cname, ',    '.join(args)))
    impl = re.sub('CALL_UNBOUND_METHOD\\(([a-zA-Z_]+),\\s*"([^"]+)"((?:,\\s*[^),]+)+)\\)', externalise, impl)
    assert ('CALL_UNBOUND_METHOD(' not in impl)
    for helper in sorted(utility_code):
        output.use_utility_code(UtilityCode.load_cached(helper, 'ObjectHandling.c'))
    return (bool(utility_code), impl)
