Commit 4b456708 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Constify value

parent f0f3c8fd
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
static void static void
cb_window_icon(girara_session_t* session, const char* UNUSED(name), cb_window_icon(girara_session_t* session, const char* UNUSED(name),
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), const void* value, void* UNUSED(data))
{ {
g_return_if_fail(session != NULL && value != NULL); g_return_if_fail(session != NULL && value != NULL);
...@@ -32,7 +32,7 @@ cb_window_icon(girara_session_t* session, const char* UNUSED(name), ...@@ -32,7 +32,7 @@ cb_window_icon(girara_session_t* session, const char* UNUSED(name),
static void static void
cb_font(girara_session_t* session, const char* UNUSED(name), cb_font(girara_session_t* session, const char* UNUSED(name),
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), const void* value, void* UNUSED(data))
{ {
g_return_if_fail(session != NULL && value != NULL); g_return_if_fail(session != NULL && value != NULL);
...@@ -41,7 +41,7 @@ cb_font(girara_session_t* session, const char* UNUSED(name), ...@@ -41,7 +41,7 @@ cb_font(girara_session_t* session, const char* UNUSED(name),
static void static void
cb_color(girara_session_t* session, const char* name, cb_color(girara_session_t* session, const char* name,
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), const void* value, void* UNUSED(data))
{ {
g_return_if_fail(session != NULL && value != NULL); g_return_if_fail(session != NULL && value != NULL);
...@@ -57,7 +57,7 @@ cb_color(girara_session_t* session, const char* name, ...@@ -57,7 +57,7 @@ cb_color(girara_session_t* session, const char* name,
static void static void
cb_guioptions(girara_session_t* session, const char* UNUSED(name), cb_guioptions(girara_session_t* session, const char* UNUSED(name),
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), const void* value, void* UNUSED(data))
{ {
g_return_if_fail(session != NULL && value != NULL); g_return_if_fail(session != NULL && value != NULL);
...@@ -68,7 +68,7 @@ cb_guioptions(girara_session_t* session, const char* UNUSED(name), ...@@ -68,7 +68,7 @@ cb_guioptions(girara_session_t* session, const char* UNUSED(name),
bool show_vscrollbar = false; bool show_vscrollbar = false;
/* evaluate input */ /* evaluate input */
char* input = (char*) value; const char* input = value;
const size_t input_length = strlen(input); const size_t input_length = strlen(input);
for (size_t i = 0; i < input_length; i++) { for (size_t i = 0; i < input_length; i++) {
...@@ -113,11 +113,11 @@ cb_guioptions(girara_session_t* session, const char* UNUSED(name), ...@@ -113,11 +113,11 @@ cb_guioptions(girara_session_t* session, const char* UNUSED(name),
static void static void
cb_scrollbars(girara_session_t* session, const char* name, cb_scrollbars(girara_session_t* session, const char* name,
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) girara_setting_type_t UNUSED(type), const void* value, void* UNUSED(data))
{ {
g_return_if_fail(session != NULL && value != NULL); g_return_if_fail(session != NULL && value != NULL);
const bool val = *(bool*) value; const bool val = *(const bool*) value;
char* guioptions = NULL; char* guioptions = NULL;
girara_setting_get(session, "guioptions", &guioptions); girara_setting_get(session, "guioptions", &guioptions);
......
...@@ -36,19 +36,19 @@ struct girara_setting_s ...@@ -36,19 +36,19 @@ struct girara_setting_s
}; };
void void
girara_setting_set_value(girara_session_t* session, girara_setting_t* setting, void* value) girara_setting_set_value(girara_session_t* session, girara_setting_t* setting, const void* value)
{ {
g_return_if_fail(setting && (value || setting->type == STRING)); g_return_if_fail(setting && (value || setting->type == STRING));
switch(setting->type) { switch(setting->type) {
case BOOLEAN: case BOOLEAN:
setting->value.b = *((bool *) value); setting->value.b = *((const bool *) value);
break; break;
case FLOAT: case FLOAT:
setting->value.f = *((float *) value); setting->value.f = *((const float *) value);
break; break;
case INT: case INT:
setting->value.i = *((int *) value); setting->value.i = *((const int *) value);
break; break;
case STRING: case STRING:
if (setting->value.s != NULL) { if (setting->value.s != NULL) {
...@@ -97,7 +97,7 @@ girara_setting_add(girara_session_t* session, const char* name, void* value, gir ...@@ -97,7 +97,7 @@ girara_setting_add(girara_session_t* session, const char* name, void* value, gir
} }
bool bool
girara_setting_set(girara_session_t* session, const char* name, void* value) girara_setting_set(girara_session_t* session, const char* name, const void* value)
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(name != NULL, false); g_return_val_if_fail(name != NULL, false);
......
...@@ -33,7 +33,7 @@ bool girara_setting_add(girara_session_t* session, const char* name, ...@@ -33,7 +33,7 @@ bool girara_setting_add(girara_session_t* session, const char* name,
* @return TRUE No error occurred * @return TRUE No error occurred
* @return FALSE An error occurred * @return FALSE An error occurred
*/ */
bool girara_setting_set(girara_session_t* session, const char* name, void* value) GIRARA_VISIBLE; bool girara_setting_set(girara_session_t* session, const char* name, const void* value) GIRARA_VISIBLE;
/** /**
* Retrieve the value of a setting. If the setting is a string, the value stored * Retrieve the value of a setting. If the setting is a string, the value stored
...@@ -89,6 +89,6 @@ girara_setting_type_t girara_setting_get_type(girara_setting_t* setting) GIRARA_ ...@@ -89,6 +89,6 @@ girara_setting_type_t girara_setting_get_type(girara_setting_t* setting) GIRARA_
* @param value The new value * @param value The new value
*/ */
void girara_setting_set_value(girara_session_t* session, void girara_setting_set_value(girara_session_t* session,
girara_setting_t* setting, void* value) GIRARA_VISIBLE; girara_setting_t* setting, const void* value) GIRARA_VISIBLE;
#endif #endif
...@@ -144,7 +144,7 @@ typedef enum girara_setting_type_e ...@@ -144,7 +144,7 @@ typedef enum girara_setting_type_e
* @param data User data * @param data User data
*/ */
typedef void (*girara_setting_callback_t)(girara_session_t* session, typedef void (*girara_setting_callback_t)(girara_session_t* session,
const char* name, girara_setting_type_t type, void* value, void* data); const char* name, girara_setting_type_t type, const void* value, void* data);
/** /**
* Definition of an argument of a shortcut or buffered command * Definition of an argument of a shortcut or buffered command
......
...@@ -45,7 +45,7 @@ START_TEST(test_settings_basic) { ...@@ -45,7 +45,7 @@ START_TEST(test_settings_basic) {
static int callback_called = 0; static int callback_called = 0;
static void static void
setting_callback(girara_session_t* session, const char* name, girara_setting_type_t type, void* value, void* data) setting_callback(girara_session_t* session, const char* name, girara_setting_type_t type, const void* value, void* data)
{ {
fail_unless(callback_called == 0, NULL); fail_unless(callback_called == 0, NULL);
fail_unless(session != NULL, NULL); fail_unless(session != NULL, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment