Skip to content

Commit

Permalink
Disambiguate some attribute placement relative to gcc's more strict r…
Browse files Browse the repository at this point in the history
…ules.
  • Loading branch information
insertinterestingnamehere committed Jan 8, 2025
1 parent 371e07c commit 3b2a432
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros: ['Q_UNUSED', 'STACKLEFT_NOINLINE']
AttributeMacros: ['Q_UNUSED', 'STACKLEFT_NOINLINE', 'API_FUNC']
BinPackArguments: false
BinPackParameters: false
BreakArrays: false
Expand Down
29 changes: 14 additions & 15 deletions src/ds/dictionary/dictionary_shavit.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,12 @@ qt_hash_put(qt_hash h, qt_key_t key, void *value, int put_choice) {
return ret->value;
}

void *API_FUNC qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
API_FUNC void *qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
return qt_hash_put(dict, key, value, PUT_ALWAYS);
}

void *API_FUNC qt_dictionary_put_if_absent(qt_dictionary *dict,
void *key,
void *value) {
API_FUNC void *
qt_dictionary_put_if_absent(qt_dictionary *dict, void *key, void *value) {
return qt_hash_put(dict, key, value, PUT_IF_ABSENT);
}

Expand All @@ -368,7 +367,7 @@ static inline void *qt_hash_get(qt_hash h, qt_key_t const key) {
&(h->B[bucket]), so_regularkey(lkey), key, NULL, NULL, NULL, h->op_equals);
}

void *API_FUNC qt_dictionary_get(qt_dictionary *dict, void *key) {
API_FUNC void *qt_dictionary_get(qt_dictionary *dict, void *key) {
return qt_hash_get(dict, key);
}

Expand All @@ -392,7 +391,7 @@ static inline int qt_hash_remove(qt_hash h, qt_key_t const key) {
return 1;
}

void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
API_FUNC void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *val = qt_hash_get(dict, key); // TODO : this is inefficient!
int ret = qt_hash_remove(dict, key);

Expand Down Expand Up @@ -472,7 +471,7 @@ static inline qt_hash qt_hash_create(qt_dict_key_equals_f eq,
return tmp;
}

qt_dictionary *API_FUNC qt_dictionary_create(qt_dict_key_equals_f eq,
API_FUNC qt_dictionary *qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
return qt_hash_create(eq, hash, cleanup);
Expand All @@ -499,7 +498,7 @@ static inline void qt_hash_destroy(qt_hash h) {
FREE(h, sizeof(qt_hash));
}

void API_FUNC qt_dictionary_destroy(qt_dictionary *d) { qt_hash_destroy(d); }
API_FUNC void qt_dictionary_destroy(qt_dictionary *d) { qt_hash_destroy(d); }

/*
* void qt_hash_destroy_deallocate(qt_hash h,
Expand Down Expand Up @@ -557,7 +556,7 @@ struct qt_dictionary_iterator {
int bkt; // = -1 if iterator is newly created; =1 otherwise.
};

qt_dictionary_iterator *API_FUNC
API_FUNC qt_dictionary_iterator *
qt_dictionary_iterator_create(qt_dictionary *dict) {
if (dict == NULL) { return ERROR; }
qt_dictionary_iterator *it =
Expand All @@ -568,7 +567,7 @@ qt_dictionary_iterator_create(qt_dictionary *dict) {
return it;
}

void API_FUNC qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
API_FUNC void qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
if (it == NULL) { return; }
FREE(it, sizeof(qt_dictionary_iterator));
}
Expand All @@ -595,7 +594,7 @@ qt_dictionary_iterator_next_element(qt_dictionary_iterator *it) {
return it->crt;
}

list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
API_FUNC list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
list_entry *ret = qt_dictionary_iterator_next_element(it);

while (ret != ERROR && ret != NULL && ret->key == NULL) {
Expand All @@ -604,28 +603,28 @@ list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
return ret;
}

list_entry *API_FUNC
API_FUNC list_entry *
qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
if ((it == NULL) || (it->dict == NULL)) { return ERROR; }
qt_dictionary *h = it->dict;
if ((h->count == 0) || (it->crt == UNINITIALIZED)) { return NULL; }
return it->crt;
}

qt_dictionary_iterator *API_FUNC qt_dictionary_end(qt_dictionary *dict) {
API_FUNC qt_dictionary_iterator *qt_dictionary_end(qt_dictionary *dict) {
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(dict);

ret->bkt = 1;
return ret;
}

int API_FUNC qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
API_FUNC int qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
if ((a == NULL) || (b == NULL)) { return a == b; }
return (a->crt == b->crt) && (a->dict == b->dict) && (a->bkt == b->bkt);
}

qt_dictionary_iterator *API_FUNC
API_FUNC qt_dictionary_iterator *
qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
if (b == NULL) { return NULL; }
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(b->dict);
Expand Down
29 changes: 14 additions & 15 deletions src/ds/dictionary/dictionary_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static int qthread_library_initialized = 1;
extern int qthread_library_initialized;
#endif

qt_dictionary *API_FUNC qt_dictionary_create(qt_dict_key_equals_f eq,
API_FUNC qt_dictionary *qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
assert(qthread_library_initialized &&
Expand All @@ -120,7 +120,7 @@ qt_dictionary *API_FUNC qt_dictionary_create(qt_dict_key_equals_f eq,
return ret;
}

void API_FUNC qt_dictionary_destroy(qt_dictionary *d) {
API_FUNC void qt_dictionary_destroy(qt_dictionary *d) {
int i;

for (i = 0; i < NO_BUCKETS; i++) {
Expand Down Expand Up @@ -256,17 +256,16 @@ void *qt_dictionary_put_helper(qt_dictionary *dict,
}
#endif /* ifdef DICTIONARY_ADD_TO_HEAD */

void *API_FUNC qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
API_FUNC void *qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
return qt_dictionary_put_helper(dict, key, value, PUT_ALWAYS);
}

void *API_FUNC qt_dictionary_put_if_absent(qt_dictionary *dict,
void *key,
void *value) {
API_FUNC void *
qt_dictionary_put_if_absent(qt_dictionary *dict, void *key, void *value) {
return qt_dictionary_put_helper(dict, key, value, PUT_IF_ABSENT);
}

void *API_FUNC qt_dictionary_get(qt_dictionary *dict, void *key) {
API_FUNC void *qt_dictionary_get(qt_dictionary *dict, void *key) {
int hash = dict->op_hash(key);
int bucket = GET_BUCKET(hash);

Expand All @@ -285,7 +284,7 @@ void *API_FUNC qt_dictionary_get(qt_dictionary *dict, void *key) {
return NULL;
}

void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
API_FUNC void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *to_ret = NULL;
list_entry *to_free = NULL;
int hash = dict->op_hash(key);
Expand Down Expand Up @@ -342,7 +341,7 @@ void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
return to_ret;
}

qt_dictionary_iterator *API_FUNC
API_FUNC qt_dictionary_iterator *
qt_dictionary_iterator_create(qt_dictionary *dict) {
if ((dict == NULL) || (dict->content == NULL)) { return ERROR; }
qt_dictionary_iterator *it =
Expand All @@ -356,12 +355,12 @@ qt_dictionary_iterator_create(qt_dictionary *dict) {
return it;
}

void API_FUNC qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
API_FUNC void qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
if (it == NULL) { return; }
FREE(it, sizeof(qt_dictionary_iterator));
}

list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
API_FUNC list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
if ((it == NULL) || (it->dict == NULL) || (it->dict->content == NULL)) {
return ERROR;
}
Expand Down Expand Up @@ -403,7 +402,7 @@ list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
return NULL;
}

list_entry *API_FUNC
API_FUNC list_entry *
qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
if ((it == NULL) || (it->dict == NULL) || (it->dict->content == NULL)) {
printf(" Inside dictionary get, found NULL, will return ERROR\n");
Expand All @@ -413,7 +412,7 @@ qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
return it->crt;
}

qt_dictionary_iterator *API_FUNC qt_dictionary_end(qt_dictionary *dict) {
API_FUNC qt_dictionary_iterator *qt_dictionary_end(qt_dictionary *dict) {
if ((dict == NULL) || (dict->content == NULL)) { return NULL; }
qt_dictionary_iterator *it = qt_dictionary_iterator_create(dict);
it->crt = NULL;
Expand All @@ -422,13 +421,13 @@ qt_dictionary_iterator *API_FUNC qt_dictionary_end(qt_dictionary *dict) {
return it;
}

int API_FUNC qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
API_FUNC int qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
if ((a == NULL) || (b == NULL)) { return a == b; }
return (a->crt == b->crt) && (a->dict == b->dict) && (a->bkt == b->bkt);
}

qt_dictionary_iterator *API_FUNC
API_FUNC qt_dictionary_iterator *
qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
if (b == NULL) { return NULL; }
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(b->dict);
Expand Down
33 changes: 16 additions & 17 deletions src/ds/dictionary/dictionary_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static inline qt_hash qt_hash_create(qt_dict_key_equals_f eq,
return tmp;
}

qt_dictionary *API_FUNC qt_dictionary_create(qt_dict_key_equals_f eq,
API_FUNC qt_dictionary *qt_dictionary_create(qt_dict_key_equals_f eq,
qt_dict_hash_f hash,
qt_dict_cleanup_f cleanup) {
return qt_hash_create(eq, hash, cleanup);
Expand Down Expand Up @@ -227,7 +227,7 @@ static void destroy_element(hash_entry *element, qt_dict_cleanup_f f) {
FREE(element, sizeof(hash_entry));
}

void API_FUNC qt_dictionary_destroy(qt_hash h) {
API_FUNC void qt_dictionary_destroy(qt_hash h) {
assert(h);
assert(h->spines);
for (size_t i = 0; i < BASE_SPINE_LENGTH; ++i) {
Expand Down Expand Up @@ -401,19 +401,18 @@ void *qt_hash_put_helper(qt_dictionary *h,
} while (1);
}

void *API_FUNC qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
API_FUNC void *qt_dictionary_put(qt_dictionary *dict, void *key, void *value) {
return qt_hash_put_helper(dict, key, value, PUT_ALWAYS);
}

void *API_FUNC qt_dictionary_put_if_absent(qt_dictionary *dict,
void *key,
void *value) {
API_FUNC void *
qt_dictionary_put_if_absent(qt_dictionary *dict, void *key, void *value) {
return qt_hash_put_helper(dict, key, value, PUT_IF_ABSENT);
}

int API_FUNC qt_dictionary_remove(qt_dictionary *h, qt_key_t const key);
API_FUNC int qt_dictionary_remove(qt_dictionary *h, qt_key_t const key);

int API_FUNC qt_dictionary_remove(qt_dictionary *h, qt_key_t const key) {
API_FUNC int qt_dictionary_remove(qt_dictionary *h, qt_key_t const key) {
uint64_t lkey = (uint64_t)(uintptr_t)(h->op_hash(key));

HASH_KEY(lkey);
Expand Down Expand Up @@ -495,7 +494,7 @@ int API_FUNC qt_dictionary_remove(qt_dictionary *h, qt_key_t const key) {
} while (1);
}

void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
API_FUNC void *qt_dictionary_delete(qt_dictionary *dict, void *key) {
void *val = qt_dictionary_get(dict, key); // TODO : this is inefficient!
int ret = qt_dictionary_remove(dict, key);

Expand All @@ -506,7 +505,7 @@ void *API_FUNC qt_dictionary_delete(qt_dictionary *dict, void *key) {
}
}

void *API_FUNC qt_dictionary_get(qt_dictionary *h, qt_key_t const key) {
API_FUNC void *qt_dictionary_get(qt_dictionary *h, qt_key_t const key) {
uint64_t lkey = (uint64_t)(uintptr_t)(h->op_hash(key));

HASH_KEY(lkey);
Expand Down Expand Up @@ -614,7 +613,7 @@ struct qt_dictionary_iterator {
int base_index;
};

qt_dictionary_iterator *API_FUNC
API_FUNC qt_dictionary_iterator *
qt_dictionary_iterator_create(qt_dictionary *dict) {
if (dict == NULL) { return ERROR; }
qt_dictionary_iterator *it =
Expand All @@ -627,12 +626,12 @@ qt_dictionary_iterator_create(qt_dictionary *dict) {
return it;
}

void API_FUNC qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
API_FUNC void qt_dictionary_iterator_destroy(qt_dictionary_iterator *it) {
if (it == NULL) { return; }
FREE(it, sizeof(qt_dictionary_iterator));
}

list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
API_FUNC list_entry *qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
if ((it == NULL) || (it->dict == NULL)) { return ERROR; }

if ((it->crt != NULL) && (it->crt->next != NULL)) {
Expand Down Expand Up @@ -674,26 +673,26 @@ list_entry *API_FUNC qt_dictionary_iterator_next(qt_dictionary_iterator *it) {
return NULL;
}

list_entry *API_FUNC
API_FUNC list_entry *
qt_dictionary_iterator_get(qt_dictionary_iterator const *it) {
if ((it == NULL) || (it->dict == NULL)) { return ERROR; }
return it->crt;
}

qt_dictionary_iterator *API_FUNC qt_dictionary_end(qt_dictionary *dict) {
API_FUNC qt_dictionary_iterator *qt_dictionary_end(qt_dictionary *dict) {
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(dict);

ret->bkt = ret->dict->maxspines;
return ret;
}

int API_FUNC qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
API_FUNC int qt_dictionary_iterator_equals(qt_dictionary_iterator *a,
qt_dictionary_iterator *b) {
if ((a == NULL) || (b == NULL)) { return a == b; }
return (a->crt == b->crt) && (a->dict == b->dict) && (a->bkt == b->bkt);
}

qt_dictionary_iterator *API_FUNC
API_FUNC qt_dictionary_iterator *
qt_dictionary_iterator_copy(qt_dictionary_iterator *b) {
if (b == NULL) { return NULL; }
qt_dictionary_iterator *ret = qt_dictionary_iterator_create(b->dict);
Expand Down
Loading

0 comments on commit 3b2a432

Please sign in to comment.