[beast: 16/43] SFI: avoid g_error in library code
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 16/43] SFI: avoid g_error in library code
- Date: Mon, 26 Jun 2017 23:28:38 +0000 (UTC)
commit b8e39a5dcbcdf7fea4debd8ed405c670e894c2c8
Author: Tim Janik <timj gnu org>
Date: Sun Jun 25 17:01:37 2017 +0200
SFI: avoid g_error in library code
Signed-off-by: Tim Janik <timj gnu org>
sfi/glib-extra.cc | 4 ++--
sfi/sfiglue.cc | 13 +++++++++++++
sfi/sfiglue.hh | 17 ++++-------------
sfi/sfiserial.cc | 6 +++---
sfi/sfistore.cc | 14 ++++++++++----
sfi/sfitime.cc | 6 ++----
6 files changed, 34 insertions(+), 26 deletions(-)
---
diff --git a/sfi/glib-extra.cc b/sfi/glib-extra.cc
index 5720a99..95a0149 100644
--- a/sfi/glib-extra.cc
+++ b/sfi/glib-extra.cc
@@ -1021,8 +1021,8 @@ g_usignal_notify (gint8 usignal)
GScanner*
g_scanner_new64 (const GScannerConfig *config_templ)
{
- if (!config_templ->store_int64)
- g_error ("%s(): attempt to create 64bit scanner with store_int64==FALSE", __func__);
+ const bool gscanner_64bit_has_store_int64 = config_templ->store_int64 != false;
+ assert_return (gscanner_64bit_has_store_int64 == true, NULL);
return g_scanner_new (config_templ);
}
diff --git a/sfi/sfiglue.cc b/sfi/sfiglue.cc
index 6338c23..29a53ee 100644
--- a/sfi/sfiglue.cc
+++ b/sfi/sfiglue.cc
@@ -5,10 +5,13 @@
#include "sfiustore.hh"
#include <string.h>
#include <gobject/gvaluecollector.h>
+
/* --- prototype --- */
static GHashTable* glue_gc_hash_table_new (void);
+
/* --- variables --- */
static GQuark quark_context_stack = 0;
+
/* --- context functions --- */
void
_sfi_init_glue (void)
@@ -16,6 +19,7 @@ _sfi_init_glue (void)
assert_return (quark_context_stack == 0);
quark_context_stack = g_quark_from_static_string ("sfi-glue-context-stack");
}
+
void
sfi_glue_context_common_init (SfiGlueContext *context,
const SfiGlueContextTable *vtable)
@@ -28,6 +32,15 @@ sfi_glue_context_common_init (SfiGlueContext *context,
context->gc_hash = glue_gc_hash_table_new ();
}
+SfiGlueContext*
+sfi_glue_fetch_context (const gchar *floc)
+{
+ SfiGlueContext *context = sfi_glue_context_current ();
+ if (!context)
+ Bse::warning ("%s: SfiGlue function called without context (use sfi_glue_context_push())", floc);
+ return context;
+}
+
class RingPtrDataKey : public Rapicorn::DataKey<SfiRing*> {
virtual void destroy (SfiRing *ring) override
{
diff --git a/sfi/sfiglue.hh b/sfi/sfiglue.hh
index 2d4ad44..d8da359 100644
--- a/sfi/sfiglue.hh
+++ b/sfi/sfiglue.hh
@@ -201,19 +201,10 @@ gboolean _sfi_glue_proxy_request_notify (SfiProxy proxy,
/* --- implementations --- */
-void _sfi_init_glue (void);
-void sfi_glue_context_common_init (SfiGlueContext *context,
- const SfiGlueContextTable *vtable);
-static inline SfiGlueContext*
-sfi_glue_fetch_context (const gchar *floc);
-static inline SfiGlueContext*
-sfi_glue_fetch_context (const gchar *floc)
-{
- SfiGlueContext *context = sfi_glue_context_current ();
- if (!context)
- g_error ("%s: SfiGlue function called without context (use sfi_glue_context_push())", floc);
- return context;
-}
+void _sfi_init_glue (void);
+void sfi_glue_context_common_init (SfiGlueContext *context,
+ const SfiGlueContextTable *vtable);
+SfiGlueContext* sfi_glue_fetch_context (const gchar *floc);
#endif /* __SFI_GLUE_H__ */
diff --git a/sfi/sfiserial.cc b/sfi/sfiserial.cc
index efa74fb..346a167 100644
--- a/sfi/sfiserial.cc
+++ b/sfi/sfiserial.cc
@@ -539,7 +539,7 @@ sfi_serialize_primitives (SfiSCategory scat,
break;
default:
if (gstring)
- g_error ("%s: unimplemented category (%u)", G_STRLOC, scat);
+ assert_return_unreached (G_TOKEN_ERROR);
else
{
g_scanner_warn (scanner, "unimplemented category (%u)", scat);
@@ -605,7 +605,7 @@ sfi_value_store_typed (const GValue *value,
gstring_putc (gstring, ')');
break;
default:
- g_error ("%s: unimplemented category (%u)", G_STRLOC, scat);
+ assert_return_unreached ();
}
}
@@ -780,7 +780,7 @@ value_store_param (const GValue *value,
*needs_break = TRUE;
break;
default:
- g_error ("%s: unimplemented category (%u)", G_STRLOC, scat);
+ assert_return_unreached ();
}
}
diff --git a/sfi/sfistore.cc b/sfi/sfistore.cc
index 5aa462a..ba9a343 100644
--- a/sfi/sfistore.cc
+++ b/sfi/sfistore.cc
@@ -169,8 +169,11 @@ sfi_wstore_put_param (SfiWStore *wstore,
spspec = sfi_pspec_to_serializable (pspec);
if (!spspec) /* we really can't do anything here */
- g_error ("unable to (de-)serialize \"%s\" of type `%s'", pspec->name,
- g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
+ {
+ Bse::warning ("unable to (de-)serialize \"%s\" of type `%s'", pspec->name,
+ g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
+ return;
+ }
g_value_init (&svalue, G_PARAM_SPEC_VALUE_TYPE (spspec));
if (sfi_value_transform (value, &svalue))
@@ -569,8 +572,11 @@ sfi_rstore_parse_param (SfiRStore *rstore,
spspec = sfi_pspec_to_serializable (pspec);
if (!spspec) /* we really can't do anything here */
- g_error ("unable to (de-)serialize \"%s\" of type `%s'", pspec->name,
- g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
+ {
+ Bse::warning ("unable to (de-)serialize \"%s\" of type `%s'", pspec->name,
+ g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
+ return G_TOKEN_ERROR;
+ }
token = sfi_value_parse_param_rest (&pvalue, rstore->scanner, spspec);
if (token == G_TOKEN_NONE)
diff --git a/sfi/sfitime.cc b/sfi/sfitime.cc
index 20bf9cf..ec4e78f 100644
--- a/sfi/sfitime.cc
+++ b/sfi/sfitime.cc
@@ -33,14 +33,12 @@ _sfi_init_time (void)
static gboolean initialized = FALSE;
struct timeval tv = { 0, };
time_t t;
- gint error;
assert_return (initialized++ == FALSE);
tzset ();
- error = gettimeofday (&tv, NULL);
- if (error)
- g_error ("gettimeofday() failed: %s", g_strerror (errno));
+ const int gettimeofday_error = gettimeofday (&tv, NULL);
+ assert_return (gettimeofday_error == 0);
t = tv.tv_sec + tv.tv_usec / 1000000;
/* we need to find out the timezone offset relative to GMT here */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]