Skip to content

Commit

Permalink
change hashmap.c version to v0.7.0 and remove warnings from hashmap l…
Browse files Browse the repository at this point in the history
…ib by casting raw pointers to each original object

Signed-off-by: Iiqbal2000 <[email protected]>
  • Loading branch information
Iiqbal2000 authored and engelmi committed Nov 14, 2023
1 parent 11acd4e commit ab8a3f7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ inih_dep = inih.get_variable('inih_dep')

hashmapc = subproject('hashmap.c', default_options: [
'default_library=static', # include it as static library
'werror=false' # don't treat warnings as errors since it
])
hashmapc_dep = hashmapc.get_variable('hashmapc_dep')

Expand Down
8 changes: 4 additions & 4 deletions src/agent/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ bool agent_parse_config(Agent *agent, const char *configfile) {
static void agent_update_unit_infos_for(Agent *agent, AgentUnitInfo *info) {
if (!info->subscribed && !info->loaded) {
AgentUnitInfoKey key = { info->object_path };
AgentUnitInfo *info = hashmap_delete(agent->unit_infos, &key);
if (info) {
AgentUnitInfo *info = (AgentUnitInfo *) hashmap_delete(agent->unit_infos, &key);
if (info != NULL) {
unit_info_clear(info);
}
}
Expand All @@ -642,7 +642,7 @@ static void agent_update_unit_infos_for(Agent *agent, AgentUnitInfo *info) {
static AgentUnitInfo *agent_get_unit_info(Agent *agent, const char *unit_path) {
AgentUnitInfoKey key = { (char *) unit_path };

return hashmap_get(agent->unit_infos, &key);
return (AgentUnitInfo *) hashmap_get(agent->unit_infos, &key);
}

static AgentUnitInfo *agent_ensure_unit_info(Agent *agent, const char *unit) {
Expand All @@ -659,7 +659,7 @@ static AgentUnitInfo *agent_ensure_unit_info(Agent *agent, const char *unit) {

AgentUnitInfo v = { unit_path, unit_copy, false, false, -1, NULL };

AgentUnitInfo *replaced = hashmap_set(agent->unit_infos, &v);
AgentUnitInfo *replaced = (AgentUnitInfo *) hashmap_set(agent->unit_infos, &v);
if (replaced == NULL && hashmap_oom(agent->unit_infos)) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libbluechi/common/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int cfg_s_set_value(
return -ENOMEM;
}
}
struct config_option *replaced = hashmap_set(
struct config_option *replaced = (struct config_option *) hashmap_set(
config->cfg_store,
&(struct config_option){
.section = section_copy, .name = name_copy, .value = value_copy });
Expand Down
20 changes: 10 additions & 10 deletions src/manager/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ static struct hashmap *node_compute_unique_monitor_subscriptions(Node *node, con
}

const UnitSubscriptionsKey key = { (char *) unit };
UnitSubscriptions *usubs = hashmap_get(node->unit_subscriptions, &key);
const UnitSubscriptions *usubs = hashmap_get(node->unit_subscriptions, &key);
if (usubs != NULL) {
UnitSubscription *usub = NULL;
UnitSubscription *next_usub = NULL;
Expand All @@ -304,7 +304,7 @@ static struct hashmap *node_compute_unique_monitor_subscriptions(Node *node, con
/* Only check for wildcards if the unit itself is not one. */
if (!streq(unit, SYMBOL_WILDCARD)) {
const UnitSubscriptionsKey wildcard_key = { (char *) SYMBOL_WILDCARD };
UnitSubscriptions *usubs_wildcard = hashmap_get(node->unit_subscriptions, &wildcard_key);
const UnitSubscriptions *usubs_wildcard = hashmap_get(node->unit_subscriptions, &wildcard_key);
if (usubs_wildcard != NULL) {
UnitSubscription *usub = NULL;
UnitSubscription *next_usub = NULL;
Expand Down Expand Up @@ -386,7 +386,7 @@ static int node_match_unit_new(sd_bus_message *m, void *userdata, UNUSED sd_bus_
}

const UnitSubscriptionsKey key = { (char *) unit };
UnitSubscriptions *usubs = hashmap_get(node->unit_subscriptions, &key);
UnitSubscriptions *usubs = (UnitSubscriptions *) hashmap_get(node->unit_subscriptions, &key);
if (usubs != NULL) {
usubs->loaded = true;
if (is_wildcard(unit)) {
Expand Down Expand Up @@ -427,7 +427,7 @@ static int node_match_unit_state_changed(sd_bus_message *m, void *userdata, UNUS
}

const UnitSubscriptionsKey key = { (char *) unit };
UnitSubscriptions *usubs = hashmap_get(node->unit_subscriptions, &key);
UnitSubscriptions *usubs = (UnitSubscriptions *) hashmap_get(node->unit_subscriptions, &key);
if (usubs != NULL) {
usubs->loaded = true;
usubs->active_state = active_state_from_string(active_state);
Expand Down Expand Up @@ -464,7 +464,7 @@ static int node_match_unit_removed(sd_bus_message *m, void *userdata, UNUSED sd_
}

const UnitSubscriptionsKey key = { (char *) unit };
UnitSubscriptions *usubs = hashmap_get(node->unit_subscriptions, &key);
UnitSubscriptions *usubs = (UnitSubscriptions *) hashmap_get(node->unit_subscriptions, &key);
if (usubs != NULL) {
usubs->loaded = false;
}
Expand Down Expand Up @@ -1637,7 +1637,7 @@ void node_subscribe(Node *node, Subscription *sub) {
}
usub->sub = sub;

usubs = hashmap_get(node->unit_subscriptions, &key);
usubs = (UnitSubscriptions *) hashmap_get(node->unit_subscriptions, &key);
if (usubs == NULL) {
UnitSubscriptions v = { NULL, NULL, false, _UNIT_ACTIVE_STATE_INVALID, NULL };
v.unit = strdup(key.unit);
Expand All @@ -1646,7 +1646,7 @@ void node_subscribe(Node *node, Subscription *sub) {
return;
}

usubs = hashmap_set(node->unit_subscriptions, &v);
usubs = (UnitSubscriptions *) hashmap_set(node->unit_subscriptions, &v);
if (usubs == NULL && hashmap_oom(node->unit_subscriptions)) {
free(v.unit);
bc_log_error("Failed to subscribe to unit, OOM");
Expand All @@ -1656,7 +1656,7 @@ void node_subscribe(Node *node, Subscription *sub) {
/* First sub to this unit, pass to agent */
node_send_agent_subscribe(node, sub_unit->name);

usubs = hashmap_get(node->unit_subscriptions, &key);
usubs = (UnitSubscriptions *) hashmap_get(node->unit_subscriptions, &key);
}

LIST_APPEND(subs, usubs->subs, steal_pointer(&usub));
Expand Down Expand Up @@ -1699,7 +1699,7 @@ void node_unsubscribe(Node *node, Subscription *sub) {
call unsubscribe, so this must silently handle the
case of too many unsubscribes. */

usubs = hashmap_get(node->unit_subscriptions, &key);
usubs = (UnitSubscriptions *) hashmap_get(node->unit_subscriptions, &key);
if (usubs == NULL) {
continue;
}
Expand All @@ -1721,7 +1721,7 @@ void node_unsubscribe(Node *node, Subscription *sub) {
if (LIST_IS_EMPTY(usubs->subs)) {
/* Last subscription for this unit, tell agent */
node_send_agent_unsubscribe(node, sub_unit->name);
deleted = hashmap_delete(node->unit_subscriptions, &key);
deleted = (UnitSubscriptions *) hashmap_delete(node->unit_subscriptions, &key);
if (deleted) {
unit_subscriptions_clear(deleted);
}
Expand Down
2 changes: 1 addition & 1 deletion subprojects/hashmap.c
Submodule hashmap.c updated 3 files
+3 −0 .gitignore
+349 −195 hashmap.c
+28 −30 hashmap.h

0 comments on commit ab8a3f7

Please sign in to comment.