Esempio n. 1
0
def check_inline(cmd: Config) -> str:
    """Return the inline identifier (may be empty)."""
    body = textwrap.dedent("""
        #ifndef __cplusplus
        static %(inline)s int static_func (void)
        {
            return 0;
        }
        %(inline)s int nostatic_func (void)
        {
            return 0;
        }
        #endif
        int main(void) {
            int r1 = static_func();
            int r2 = nostatic_func();
            return r1 + r2;
        }
        """)

    for kw in ["inline", "__inline__", "__inline"]:
        st = cmd.try_compile(body % {"inline": kw}, None, None)
        if st:
            return kw

    return ""
Esempio n. 2
0
def check_gcc_function_attribute(cmd: Config, attribute: str, name: str) -> bool:
    """Return True if the given function attribute is supported."""
    if is_gcc(cmd):
        pragma = '#pragma GCC diagnostic error "-Wattributes"'
    elif is_clang(cmd):
        pragma = '#pragma clang diagnostic error "-Wattributes"'
    else:
        pragma = ""

    body = (
        textwrap.dedent(
            """
        %s

        int %s %s(void*);

        int main(void)
        {
            return 0;
        }
        """
        )
        % (pragma, attribute, name)
    )
    if cmd.try_compile(body, None, None):
        return True
    else:
        return False