Thread (3 messages) flat view 3 messages, 2 authors, 2016-10-13

Re: [PATCHv3] attr: convert to new threadsafe API

From: Stefan Beller <hidden>
Date: 2016-10-13 22:16:42

On Wed, Oct 12, 2016 at 4:33 PM, Junio C Hamano [off-list ref] wrote:
so I am hoping that we won't have to do this uglier variant
---8<--- attr.h:
...
struct git_attr_result {
    int check_nr;
    /* Whether is was statically allocated and cannot be resized. */
    int static_alloc;
    const char *value[FLEX_ARRAY];
};

/* create a pointer pointing to a git_attr_result with a given size: */
#define GIT_ATTR_RESULT_INIT_FOR(name, size) \
    struct { \
        int check_nr; \
        int static_alloc; \
        const char *value[size]; \
    } local_##name; \
    struct git_attr_result *name = \
        (struct git_attr_result *)&(local_##name); \
    local_##name.static_alloc = 1;
...
---8<--- e.g. ws.c:

    static struct git_attr_check *attr_whitespace_rule;
    GIT_ATTR_RESULT_INIT_FOR(result, 1);

    git_attr_check_initl(&attr_whitespace_rule, "whitespace", NULL);

    if (!git_check_attr(pathname, attr_whitespace_rule, result)) {
        if (ATTR_TRUE(result->value[0])) {
            ...
        } else if (ATTR_FALSE(result->value[0])) {
            ...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help