Skip to content

Commit

Permalink
build(meson): enable -Wfloat-conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
andyholmes committed Oct 4, 2024
1 parent fecd4a5 commit 3bf252f
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 127 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ cc = meson.get_compiler('c')

release_args = []
project_c_args = [
'-Wfloat-conversion',
'-Wfloat-equal',
'-Wformat=2',
'-Wincompatible-pointer-types',
Expand Down
30 changes: 13 additions & 17 deletions src/libvalent/device/valent-device-transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,29 @@ enum {
static GParamSpec *properties[N_PROPERTIES] = { NULL, };


static inline void
static void
valent_device_transfer_update_packet (JsonNode *packet,
GFileInfo *info)
{
JsonObject *body;
uint64_t btime_s, mtime_s;
uint32_t btime_us, mtime_us;
uint64_t creation_time;
uint64_t last_modified;
goffset payload_size;
int64_t creation_time, last_modified;

g_assert (VALENT_IS_PACKET (packet));

btime_s = g_file_info_get_attribute_uint64 (info, "time::created");
btime_us = g_file_info_get_attribute_uint32 (info, "time::created-usec");
creation_time = (btime_s * 1000) + floor (btime_us / 1000);

mtime_s = g_file_info_get_attribute_uint64 (info, "time::created");
mtime_us = g_file_info_get_attribute_uint32 (info, "time::created-usec");
last_modified = (mtime_s * 1000) + floor (mtime_us / 1000);
btime_s = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_CREATED);
btime_us = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_CREATED_USEC);
creation_time = (int64_t)((btime_s * 1000) + floor (btime_us / 1000));

payload_size = g_file_info_get_size (info);
mtime_s = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
mtime_us = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC);
last_modified = (int64_t)((mtime_s * 1000) + floor (mtime_us / 1000));

body = valent_packet_get_body (packet);
json_object_set_int_member (body, "creationTime", creation_time);
json_object_set_int_member (body, "lastModified", last_modified);
valent_packet_set_payload_size (packet, payload_size);
valent_packet_set_payload_size (packet, g_file_info_get_size (info));
}

/*
Expand Down Expand Up @@ -230,7 +226,7 @@ valent_device_transfer_execute_task (GTask *task,

success = g_file_set_attribute_uint64 (file,
G_FILE_ATTRIBUTE_TIME_CREATED,
floor (creation_time / 1000),
(uint64_t)floor (creation_time / 1000),
G_FILE_QUERY_INFO_NONE,
cancellable,
&warn);
Expand All @@ -239,7 +235,7 @@ valent_device_transfer_execute_task (GTask *task,
{
g_file_set_attribute_uint32 (file,
G_FILE_ATTRIBUTE_TIME_CREATED_USEC,
(creation_time % 1000) * 1000,
(uint32_t)((creation_time % 1000) * 1000),
G_FILE_QUERY_INFO_NONE,
cancellable,
&warn);
Expand All @@ -256,7 +252,7 @@ valent_device_transfer_execute_task (GTask *task,

success = g_file_set_attribute_uint64 (file,
G_FILE_ATTRIBUTE_TIME_MODIFIED,
floor (last_modified / 1000),
(uint64_t)floor (last_modified / 1000),
G_FILE_QUERY_INFO_NONE,
cancellable,
&warn);
Expand All @@ -265,7 +261,7 @@ valent_device_transfer_execute_task (GTask *task,
{
g_file_set_attribute_uint32 (file,
G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC,
(last_modified % 1000) * 1000,
(uint32_t)((last_modified % 1000) * 1000),
G_FILE_QUERY_INFO_NONE,
cancellable,
&warn);
Expand Down
2 changes: 1 addition & 1 deletion src/libvalent/device/valent-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ valent_packet_get_boolean (JsonNode *packet,
return FALSE;

if (value)
*value = json_node_get_double (node);
*value = json_node_get_boolean (node);

return TRUE;
}
Expand Down
42 changes: 21 additions & 21 deletions src/plugins/battery/valent-battery-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,45 +169,45 @@ valent_battery_plugin_update_estimate (ValentBatteryPlugin *self,
int64_t current_charge,
gboolean is_charging)
{
int64_t rate;
double rate;
double percentage;
int64_t timestamp;
double timestamp;

g_return_if_fail (current_charge >= 0);

percentage = CLAMP (current_charge, 0.0, 100.0);
timestamp = floor (valent_timestamp_ms () / 1000);
rate = is_charging ? self->charge_rate : self->discharge_rate;

/* If the battery is present, we must have a timestamp and charge level to
* calculate the deltas and derive the (dis)charge rate. */
if (self->is_present)
{
double percentage_delta;
int64_t timestamp_delta;
int64_t new_rate;
double timestamp_delta;
double new_rate;

percentage_delta = ABS (percentage - self->percentage);
timestamp_delta = timestamp - self->timestamp;
new_rate = timestamp_delta / percentage_delta;
rate = floor ((rate * 0.4) + (new_rate * 0.6));

if (percentage_delta > 0 && timestamp_delta > 0)
{
new_rate = timestamp_delta / percentage_delta;
rate = floor ((rate * 0.4) + (new_rate * 0.6));
}
}

/* Update the estimate and related values */
if (is_charging)
{
self->charge_rate = rate;
self->charge_rate = (int64_t)rate;
self->time_to_empty = 0;
self->time_to_full = floor (self->charge_rate * (100.0 - percentage));
self->timestamp = timestamp;
self->time_to_full = (int64_t)floor (self->charge_rate * (100.0 - percentage));
}
else
{
self->discharge_rate = rate;
self->time_to_empty = floor (self->discharge_rate * percentage);
self->discharge_rate = (int64_t)rate;
self->time_to_empty = (int64_t)floor (self->discharge_rate * percentage);
self->time_to_full = 0;
self->timestamp = timestamp;
}
self->timestamp = (int64_t)timestamp;
}

static void
Expand Down Expand Up @@ -279,16 +279,16 @@ valent_battery_plugin_update_notification (ValentBatteryPlugin *self,
/* Battery is now low */
else if (self->percentage <= low || threshold_event == 1)
{
int64_t total_minutes;
int minutes;
int hours;
unsigned int total_minutes;
unsigned int minutes;
unsigned int hours;

if (!g_settings_get_boolean (settings, "low-notification"))
return;

total_minutes = floor (self->time_to_empty / 60);
total_minutes = (unsigned int)floor (self->time_to_empty / 60);
minutes = total_minutes % 60;
hours = floor (total_minutes / 60);
hours = (unsigned int)floor (total_minutes / 60);

/* TRANSLATORS: This is <device name>: Battery Low */
title = g_strdup_printf (_("%s: Battery Low"), device_name);
Expand Down Expand Up @@ -322,7 +322,7 @@ valent_battery_plugin_handle_battery (ValentBatteryPlugin *self,
is_charging = self->charging;

if (!valent_packet_get_int (packet, "currentCharge", &current_charge))
current_charge = self->percentage;
current_charge = (int64_t)self->percentage;

if (!valent_packet_get_int (packet, "thresholdEvent", &threshold_event))
threshold_event = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/battery/valent-battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ valent_battery_load_properties (ValentBattery *self)
{
double percentage = g_variant_get_double (value);

self->current_charge = floor (percentage);
self->current_charge = (unsigned int)floor (percentage);
g_clear_pointer (&value, g_variant_unref);
}

Expand Down Expand Up @@ -208,7 +208,7 @@ on_properties_changed (GDBusProxy *proxy,

if (g_variant_lookup (changed_properties, "Percentage", "d", &percentage))
{
unsigned int current_charge = floor (percentage);
unsigned int current_charge = (unsigned int)floor (percentage);

if (self->current_charge != current_charge)
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/gnome/valent-conversation-row.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ on_menu_popup (GtkGestureClick *gesture,
ValentConversationRow *self)
{
gtk_popover_set_pointing_to (GTK_POPOVER (self->context_menu),
&(GdkRectangle){ x, y });
&(GdkRectangle){ (int)x, (int)y });
gtk_popover_popup (GTK_POPOVER (self->context_menu));
}
/* LCOV_EXCL_STOP */
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/gnome/valent-device-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ on_battery_state_changed (GActionGroup *action_group,
else
{
int64_t total_seconds = 0;
int64_t total_minutes;
int minutes;
int hours;
unsigned int total_minutes;
unsigned int minutes;
unsigned int hours;

if (charging)
g_variant_lookup (value, "time-to-full", "x", &total_seconds);
Expand All @@ -165,9 +165,9 @@ on_battery_state_changed (GActionGroup *action_group,

if (total_seconds > 0)
{
total_minutes = floor (total_seconds / 60);
total_minutes = (unsigned int)floor (total_seconds / 60);
minutes = total_minutes % 60;
hours = floor (total_minutes / 60);
hours = (unsigned int)floor (total_minutes / 60);
}

if (total_seconds <= 0)
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/gnome/valent-device-row.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ on_battery_state_changed (GActionGroup *action_group,
else
{
int64_t total_seconds = 0;
int64_t total_minutes;
int minutes;
int hours;
unsigned int total_minutes;
unsigned int minutes;
unsigned int hours;

if (charging)
g_variant_lookup (value, "time-to-full", "x", &total_seconds);
Expand All @@ -131,9 +131,9 @@ on_battery_state_changed (GActionGroup *action_group,

if (total_seconds > 0)
{
total_minutes = floor (total_seconds / 60);
total_minutes = (unsigned int)floor (total_seconds / 60);
minutes = total_minutes % 60;
hours = floor (total_minutes / 60);
hours = (unsigned int)floor (total_minutes / 60);
}

if (total_seconds <= 0)
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/gnome/valent-input-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ on_single_update (GtkGesture *gesture,
unsigned int button = 0;
uint32_t timestamp = 0;
double x, y;
double dx, dy, dt;
double dx, dy;
uint32_t dt;
double cx, cy;

g_assert (VALENT_IS_INPUT_REMOTE (self));
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/gnome/valent-media-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ valent_media_remote_timer_tick (gpointer data)
gtk_adjustment_set_value (self->media_position_adjustment, 1.0);
}

position_str = valent_media_time_to_string (position * 1000L, TOTEM_TIME_FLAG_NONE);
position_str = valent_media_time_to_string ((int64_t)(position * 1000L),
TOTEM_TIME_FLAG_NONE);
gtk_label_set_label (self->media_position_current, position_str);

length_str = valent_media_time_to_string (length * 1000L, TOTEM_TIME_FLAG_NONE);
length_str = valent_media_time_to_string ((int64_t)(length * 1000L),
TOTEM_TIME_FLAG_NONE);
gtk_label_set_label (self->media_position_length, length_str);

return G_SOURCE_CONTINUE;
Expand Down Expand Up @@ -134,7 +136,8 @@ valent_media_remote_update_position (ValentMediaRemote *self)
gtk_adjustment_set_value (self->media_position_adjustment, 1.0);
}

position_str = valent_media_time_to_string (position * 1000L, TOTEM_TIME_FLAG_NONE);
position_str = valent_media_time_to_string ((int64_t)(position * 1000L),
TOTEM_TIME_FLAG_NONE);
gtk_label_set_label (self->media_position_current, position_str);
}

Expand Down Expand Up @@ -191,7 +194,8 @@ valent_media_remote_update_metadata (ValentMediaRemote *self)
length = length_us / G_TIME_SPAN_SECOND;

gtk_adjustment_set_upper (self->media_position_adjustment, length);
length_str = valent_media_time_to_string (length * 1000L, TOTEM_TIME_FLAG_NONE);
length_str = valent_media_time_to_string ((int64_t)(length * 1000L),
TOTEM_TIME_FLAG_NONE);
gtk_label_set_label (self->media_position_length, length_str);

valent_media_remote_update_position (self);
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/mpris/valent-mpris-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ valent_mpris_device_set_position (ValentMediaPlayer *player,
json_builder_set_member_name (builder, "player");
json_builder_add_string_value (builder, self->name);
json_builder_set_member_name (builder, "SetPosition");
json_builder_add_int_value (builder, position * 1000L);
json_builder_add_int_value (builder, (int64_t)(position * 1000L));
packet = valent_packet_end (&builder);

valent_device_send_packet (self->device, packet, NULL, NULL, NULL);
Expand Down Expand Up @@ -186,7 +186,7 @@ valent_mpris_device_set_volume (ValentMediaPlayer *player,
json_builder_set_member_name (builder, "player");
json_builder_add_string_value (builder, self->name);
json_builder_set_member_name (builder, "setVolume");
json_builder_add_int_value (builder, floor (volume * 100));
json_builder_add_int_value (builder, (int64_t)floor (volume * 100));
packet = valent_packet_end (&builder);

valent_device_send_packet (self->device, packet, NULL, NULL, NULL);
Expand Down Expand Up @@ -292,7 +292,7 @@ valent_mpris_device_seek (ValentMediaPlayer *player,
json_builder_set_member_name (builder, "player");
json_builder_add_string_value (builder, self->name);
json_builder_set_member_name (builder, "Seek");
json_builder_add_int_value (builder, offset * G_TIME_SPAN_SECOND);
json_builder_add_int_value (builder, (int64_t)(offset * G_TIME_SPAN_SECOND));
packet = valent_packet_end (&builder);

valent_device_send_packet (self->device, packet, NULL, NULL, NULL);
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/mpris/valent-mpris-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ player_get_property (GDBusConnection *connection,
double position = valent_media_player_get_position (self->player);

/* Convert seconds to microseconds */
return g_variant_new_int64 (position * G_TIME_SPAN_SECOND);
return g_variant_new_int64 ((int64_t)(position * G_TIME_SPAN_SECOND));
}

/* Load properties */
Expand Down Expand Up @@ -514,13 +514,13 @@ valent_mpris_impl_propagate_notify (ValentMediaPlayer *player,
double position = valent_media_player_get_position (self->player);

/* Convert seconds to microseconds */
value = g_variant_new_int64 (position * G_TIME_SPAN_SECOND);
value = g_variant_new_int64 ((int64_t)(position * G_TIME_SPAN_SECOND));
g_hash_table_replace (self->cache,
g_strdup ("Position"),
g_variant_ref_sink (value));

/* Convert seconds to microseconds */
valent_mpris_impl_propagate_seeked (self, position * G_TIME_SPAN_SECOND);
valent_mpris_impl_propagate_seeked (self, (int64_t)(position * G_TIME_SPAN_SECOND));
}
else if (g_str_equal (name, "repeat"))
{
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/mpris/valent-mpris-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ on_player_seeked (ValentMediaPlayer *player,
json_builder_set_member_name (builder, "player");
json_builder_add_string_value (builder, name);
json_builder_set_member_name (builder, "pos");
json_builder_add_int_value (builder, position * 1000L);
json_builder_add_int_value (builder, (int64_t)(position * 1000L));
packet = valent_packet_end (&builder);

valent_device_plugin_queue_packet (VALENT_DEVICE_PLUGIN (self), packet);
Expand Down Expand Up @@ -420,7 +420,7 @@ valent_mpris_plugin_send_player_info (ValentMprisPlugin *self,
/* Convert seconds to milliseconds */
position = valent_media_player_get_position (player);
json_builder_set_member_name (builder, "pos");
json_builder_add_int_value (builder, position * 1000L);
json_builder_add_int_value (builder, (int64_t)(position * 1000L));

/* Track Metadata
*
Expand Down Expand Up @@ -475,7 +475,7 @@ valent_mpris_plugin_send_player_info (ValentMprisPlugin *self,
{
int64_t level;

level = floor (valent_media_player_get_volume (player) * 100);
level = (int64_t)floor (valent_media_player_get_volume (player) * 100);
json_builder_set_member_name (builder, "volume");
json_builder_add_int_value (builder, level);
}
Expand Down
Loading

0 comments on commit 3bf252f

Please sign in to comment.