From 4b6e5e811205b3b5e09ac534075aa3df2994420f Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sun, 10 Sep 2023 16:33:07 -0700 Subject: [PATCH] Silence warning if loading nonexistent resource We would previously log a warning here, but looking up a nonexistent resource number to see if it exists is a perfectly legal thing for a Glk program to do. Now the tests should pass without logging any warnings or criticals. --- libchimara/graphics.c | 5 +++-- libchimara/schannel.c | 9 ++++++--- libchimara/stream.c | 10 ++++++---- tests/meson.build | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libchimara/graphics.c b/libchimara/graphics.c index 0391779..2d81425 100644 --- a/libchimara/graphics.c +++ b/libchimara/graphics.c @@ -124,8 +124,9 @@ load_image_in_cache(glui32 image, gint width, gint height) } else { giblorb_result_t resource; giblorb_err_t blorb_error = giblorb_load_resource(glk_data->resource_map, giblorb_method_FilePos, &resource, giblorb_ID_Pict, image); - if(blorb_error != giblorb_err_None) { - WARNING_S( "Error loading resource", giblorb_get_error_message(blorb_error) ); + if (blorb_error != giblorb_err_None) { + if (blorb_error != giblorb_err_NotFound) + WARNING_S("Error loading resource", giblorb_get_error_message(blorb_error)); return NULL; } info = load_image_from_blorb(resource, image, width, height); diff --git a/libchimara/schannel.c b/libchimara/schannel.c index 49669be..93b459a 100644 --- a/libchimara/schannel.c +++ b/libchimara/schannel.c @@ -204,7 +204,8 @@ load_resource_into_giostream(glui32 snd) giblorb_result_t resource; giblorb_err_t result = giblorb_load_resource(glk_data->resource_map, giblorb_method_Memory, &resource, giblorb_ID_Snd, snd); if(result != giblorb_err_None) { - WARNING_S( "Error loading resource", giblorb_get_error_message(result) ); + if (result != giblorb_err_NotFound) + WARNING_S("Error loading resource", giblorb_get_error_message(result)); return NULL; } retval = g_memory_input_stream_new_from_data(resource.data.ptr, resource.length, NULL); @@ -888,7 +889,8 @@ glk_sound_load_hint(glui32 snd, glui32 flag) loading a chunk more than once does nothing */ result = giblorb_load_resource(glk_data->resource_map, giblorb_method_Memory, &resource, giblorb_ID_Snd, snd); if(result != giblorb_err_None) { - WARNING_S( "Error loading resource", giblorb_get_error_message(result) ); + if (result != giblorb_err_NotFound) + WARNING_S("Error loading resource", giblorb_get_error_message(result)); return; } } else { @@ -897,7 +899,8 @@ glk_sound_load_hint(glui32 snd, glui32 flag) isn't loaded */ result = giblorb_load_resource(glk_data->resource_map, giblorb_method_DontLoad, &resource, giblorb_ID_Snd, snd); if(result != giblorb_err_None) { - WARNING_S( "Error loading resource", giblorb_get_error_message(result) ); + if (result != giblorb_err_NotFound) + WARNING_S("Error loading resource", giblorb_get_error_message(result)); return; } result = giblorb_unload_chunk(glk_data->resource_map, resource.chunknum); diff --git a/libchimara/stream.c b/libchimara/stream.c index 9def3f5..06f7bb8 100644 --- a/libchimara/stream.c +++ b/libchimara/stream.c @@ -527,10 +527,12 @@ glk_stream_open_resource(glui32 filenum, glui32 rock) } err = giblorb_load_resource(map, giblorb_method_Memory, &res, giblorb_ID_Data, filenum); - if(err) { - WARNING_S("Could not create resource stream, because the resource " - "could not be loaded", giblorb_get_error_message(err)); - return 0; /* Not found, or some other error */ + if (err != giblorb_err_None) { + if (err != giblorb_err_NotFound) { + WARNING_S("Could not create resource stream, because the resource " + "could not be loaded", giblorb_get_error_message(err)); + } + return NULL; } /* We'll use the in-memory copy of the chunk data as the basis for diff --git a/tests/meson.build b/tests/meson.build index e04a2b8..175cec6 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -63,6 +63,7 @@ stream_test = shared_module('stream', 'unit/stream.c', 'unit/glkunit.c', test_env = environment() test_env.set('NO_AT_BRIDGE', '1') +test_env.set('G_DEBUG', 'fatal-warnings') test_env.set('SOURCE_DIR', meson.current_source_dir()) test('datetime', glkunit_runner, args: [datetime_test], suite: 'unit',