mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
sort-util: make bsearch_safe() actually typesafe, by returning the right type
This commit is contained in:
parent
2b5b25f123
commit
423e2400af
@ -18,7 +18,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
|
||||
({ \
|
||||
const typeof((b)[0]) *_k = k; \
|
||||
int (*_func_)(const typeof((b)[0])*, const typeof((b)[0])*, typeof(userdata)) = func; \
|
||||
xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
|
||||
(typeof((b)[0])*) xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
|
||||
})
|
||||
|
||||
/**
|
||||
@ -38,7 +38,7 @@ static inline void* bsearch_safe(const void *key, const void *base,
|
||||
({ \
|
||||
const typeof((b)[0]) *_k = k; \
|
||||
int (*_func_)(const typeof((b)[0])*, const typeof((b)[0])*) = func; \
|
||||
bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_fn_t) _func_); \
|
||||
(typeof((b)[0])*) bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_fn_t) _func_); \
|
||||
})
|
||||
|
||||
/**
|
||||
|
@ -22,12 +22,12 @@ static int partition_policy_compare(const PartitionPolicy *a, const PartitionPol
|
||||
return CMP(ASSERT_PTR(a)->designator, ASSERT_PTR(b)->designator);
|
||||
}
|
||||
|
||||
static PartitionPolicy* image_policy_bsearch(const ImagePolicy *policy, PartitionDesignator designator) {
|
||||
static const PartitionPolicy* image_policy_bsearch(const ImagePolicy *policy, PartitionDesignator designator) {
|
||||
if (!policy)
|
||||
return NULL;
|
||||
|
||||
return typesafe_bsearch(
|
||||
&(PartitionPolicy) { .designator = designator },
|
||||
&(const PartitionPolicy) { .designator = designator },
|
||||
ASSERT_PTR(policy)->policies,
|
||||
ASSERT_PTR(policy)->n_policies,
|
||||
partition_policy_compare);
|
||||
@ -78,7 +78,7 @@ static PartitionPolicyFlags partition_policy_normalized_flags(const PartitionPol
|
||||
|
||||
PartitionPolicyFlags image_policy_get(const ImagePolicy *policy, PartitionDesignator designator) {
|
||||
PartitionDesignator data_designator = _PARTITION_DESIGNATOR_INVALID;
|
||||
PartitionPolicy *pp;
|
||||
const PartitionPolicy *pp;
|
||||
|
||||
/* No policy means: everything may be used in any mode */
|
||||
if (!policy)
|
||||
|
@ -531,7 +531,12 @@ Instance* resource_find_instance(Resource *rr, const char *version) {
|
||||
.metadata.version = (char*) version,
|
||||
}, *k = &key;
|
||||
|
||||
return typesafe_bsearch(&k, rr->instances, rr->n_instances, instance_cmp);
|
||||
Instance **found;
|
||||
found = typesafe_bsearch(&k, rr->instances, rr->n_instances, instance_cmp);
|
||||
if (!found)
|
||||
return NULL;
|
||||
|
||||
return *found;
|
||||
}
|
||||
|
||||
int resource_resolve_path(
|
||||
|
@ -818,7 +818,7 @@ static int feature_to_string_compare_func(const FeatureToString *a, const Featur
|
||||
}
|
||||
|
||||
static void print_feature(Feature feature, const char *prefix) {
|
||||
FeatureToString *found, in = {
|
||||
const FeatureToString *found, in = {
|
||||
.feature = feature,
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user