Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: general maintenance #763

Merged
merged 4 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/libvalent/contacts/valent-contacts-adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static inline gboolean
find_item (gconstpointer a,
gconstpointer b)
{
g_autofree char *iri = valent_object_dup_iri ((ValentObject *)a);
const char *iri = valent_resource_get_iri ((ValentResource *)a);

return g_strcmp0 (iri, (const char *)b) == 0;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ valent_contacts_adapter_open (ValentContactsAdapter *self,
ValentContext *context = NULL;
g_autoptr (GFile) file = NULL;
g_autoptr (GFile) ontology = NULL;
g_autofree char *iri = NULL;
const char *iri = NULL;
g_autofree char *iri_pattern = NULL;

context = valent_extension_get_context (VALENT_EXTENSION (self));
Expand All @@ -317,7 +317,7 @@ valent_contacts_adapter_open (ValentContactsAdapter *self,
if (priv->connection == NULL)
return FALSE;

iri = valent_object_dup_iri (VALENT_OBJECT (self));
iri = valent_resource_get_iri (VALENT_RESOURCE (self));
iri_pattern = g_strdup_printf ("^%s:([^:]+)$", iri);
priv->iri_pattern = g_regex_new (iri_pattern,
G_REGEX_OPTIMIZE,
Expand Down
20 changes: 12 additions & 8 deletions src/libvalent/core/valent-component.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ valent_component_update_preferred (ValentComponent *self)
g_assert (VALENT_IS_COMPONENT (self));

g_hash_table_iter_init (&iter, priv->plugins);

while (g_hash_table_iter_next (&iter, (void **)&info, (void **)&plugin))
{
ValentPluginState state;
Expand Down Expand Up @@ -139,9 +138,10 @@ on_plugin_state_changed (ValentExtension *extension,
g_assert (VALENT_IS_COMPONENT (self));

state = valent_extension_plugin_state_check (extension, &error);

if (state == VALENT_PLUGIN_STATE_ERROR)
g_warning ("%s(): %s", G_OBJECT_TYPE_NAME (extension), error->message);
else if (error != NULL)
g_debug ("%s(): %s", G_OBJECT_TYPE_NAME (extension), error->message);

valent_component_update_preferred (self);
}
Expand Down Expand Up @@ -198,18 +198,18 @@ valent_component_enable_plugin (ValentComponent *self,
NULL);
g_return_if_fail (G_IS_OBJECT (plugin->extension));

valent_component_export_adapter (self, VALENT_EXTENSION (plugin->extension));
valent_component_update_preferred (self);

/* If the extension state changes, update the preferred adapter */
/* If the extension state changes, update the preferred adapter
*/
g_signal_connect_object (plugin->extension,
"notify::plugin-state",
G_CALLBACK (on_plugin_state_changed),
self,
G_CONNECT_DEFAULT);
valent_component_export_adapter (self, VALENT_EXTENSION (plugin->extension));

/* If the extension requires initialization, use a chained cancellable in case
* the plugin is unloaded or the component is destroyed. */
/* If the extension requires initialization, wait for the state to change
* before updating the primary adapter.
*/
if (G_IS_ASYNC_INITABLE (plugin->extension))
{
GAsyncInitable *initable = G_ASYNC_INITABLE (plugin->extension);
Expand Down Expand Up @@ -243,6 +243,10 @@ valent_component_enable_plugin (ValentComponent *self,
error->message);
}
}
else
{
valent_component_update_preferred (self);
}

VALENT_EXIT;
}
Expand Down
35 changes: 0 additions & 35 deletions src/libvalent/core/valent-debug.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -204,40 +204,5 @@ void valent_trace_mark (const char *strfunc,
# define VALENT_JSON(_node, _ctx) G_STMT_START { } G_STMT_END
#endif

/**
* V_GNUC_BEGIN_IGNORE_INFINITE_LOOP: (skip)
*
* Tells gcc (if it is a new enough version) to temporarily stop emitting
* warnings when functions employ an infinite loop. This is useful for functions
* that do so intentionally, such as [[email protected]].
*
* Since: 1.0
*/

/**
* V_GNUC_END_IGNORE_INFINITE_LOOP: (skip)
*
* Undoes the effect of [[email protected]_GNUC_BEGIN_IGNORE_INFINITE_LOOP], telling gcc
* to begin outputting warnings again (assuming those warnings had been enabled
* to begin with).
*
* Since: 1.0
*/

#if G_GNUC_CHECK_VERSION(14, 0)
#define V_GNUC_BEGIN_IGNORE_INFINITE_LOOP \
G_STMT_START { \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wanalyzer-infinite-loop\"") \
} G_STMT_END
#define V_GNUC_END_IGNORE_INFINITE_LOOP \
G_STMT_START { \
_Pragma("GCC diagnostic pop") \
} G_STMT_END
#else
#define V_GNUC_BEGIN_IGNORE_INFINITE_LOOP G_STMT_START { } G_STMT_END
#define V_GNUC_END_IGNORE_INFINITE_LOOP G_STMT_START { } G_STMT_END
#endif

G_END_DECLS

25 changes: 23 additions & 2 deletions src/libvalent/core/valent-extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
* `ValentExtension` is a base class for extensions with conveniences for
* [[email protected]], [[email protected]] backed by [[email protected]].
*
* ## Implementation Notes
*
* Implementations that also implement [[email protected]] or
* [[email protected]] are marked as `VALENT_PLUGIN_STATE_INACTIVE` during
* construction and must call [[email protected]_state_changed] to
* reflect the result of initialization.
*
* ## Plugin Actions
*
* `ValentExtension` implements the [[email protected]] and
Expand Down Expand Up @@ -315,6 +322,20 @@
* GObject
*/
static void
valent_extension_constructed (GObject *object)
{
ValentExtension *self = VALENT_EXTENSION (object);
ValentExtensionPrivate *priv = valent_extension_get_instance_private (self);

G_OBJECT_CLASS (valent_extension_parent_class)->constructed (object);

/* If this is an extension with failable initialization, it is

Check warning on line 332 in src/libvalent/core/valent-extension.c

View workflow job for this annotation

GitHub Actions / CSpell

Unknown word (failable)
* expected to update the state with the result.
*/
if (G_IS_INITABLE (object) || G_IS_ASYNC_INITABLE (object))
priv->plugin_state = VALENT_PLUGIN_STATE_INACTIVE;
}
static void
valent_extension_finalize (GObject *object)
{
ValentExtension *self = VALENT_EXTENSION (object);
Expand Down Expand Up @@ -393,6 +414,7 @@
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ValentObjectClass *vobject_class = VALENT_OBJECT_CLASS (klass);

object_class->constructed = valent_extension_constructed;
object_class->finalize = valent_extension_finalize;
object_class->get_property = valent_extension_get_property;
object_class->set_property = valent_extension_set_property;
Expand Down Expand Up @@ -581,15 +603,14 @@
void
valent_extension_plugin_state_changed (ValentExtension *extension,
ValentPluginState state,
GError *error)
const GError *error)
{
ValentExtensionPrivate *priv = valent_extension_get_instance_private (extension);

g_return_if_fail (VALENT_IS_EXTENSION (extension));
g_return_if_fail (state != VALENT_PLUGIN_STATE_ERROR || error != NULL);

g_clear_error (&priv->plugin_error);

if (state == VALENT_PLUGIN_STATE_ERROR && error != NULL)
priv->plugin_error = g_error_copy (error);

Expand Down
2 changes: 1 addition & 1 deletion src/libvalent/core/valent-extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ValentPluginState valent_extension_plugin_state_check (ValentExtension *e
VALENT_AVAILABLE_IN_1_0
void valent_extension_plugin_state_changed (ValentExtension *extension,
ValentPluginState state,
GError *error);
const GError *error);
VALENT_AVAILABLE_IN_1_0
void valent_extension_toggle_actions (ValentExtension *extension,
gboolean enabled);
Expand Down
69 changes: 3 additions & 66 deletions src/libvalent/core/valent-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@
* Instances have a `GRecMutex` and a `GCancellable` that is created on-demand
* and triggered when the object is destroyed.
*
* An IRI may be provided at construct-time to uniquely identify the object.
* Object IRIs should generally reflect the associated [[email protected]]
* and are most useful for well-known components and objects that represent
* SPARQL resources.
*
* Since: 1.0
*/

typedef struct
{
GRecMutex mutex;
GCancellable *cancellable;
char *iri;
unsigned int in_destruction : 1;
unsigned int destroyed : 1;
} ValentObjectPrivate;
Expand All @@ -43,10 +37,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (ValentObject, valent_object, G_TYPE_OBJECT)

typedef enum {
PROP_CANCELLABLE = 1,
PROP_IRI,
} ValentObjectProperty;

static GParamSpec *properties[PROP_IRI + 1] = { NULL, };
static GParamSpec *properties[PROP_CANCELLABLE + 1] = { NULL, };

enum {
DESTROY,
Expand Down Expand Up @@ -188,11 +181,8 @@ valent_object_constructed (GObject *object)
{
if G_UNLIKELY (G_OBJECT_GET_CLASS (object)->dispose != valent_object_dispose)
{
V_GNUC_BEGIN_IGNORE_INFINITE_LOOP;
g_error ("%s overrides GObject.Object.dispose() instead of "
"Valent.Object.destroy(), which is not thread safe",
G_OBJECT_TYPE_NAME (object));
V_GNUC_END_IGNORE_INFINITE_LOOP;
g_critical ("%s overrides dispose() instead of destroy()",
G_OBJECT_TYPE_NAME (object));
}

G_OBJECT_CLASS (valent_object_parent_class)->constructed (object);
Expand All @@ -205,7 +195,6 @@ valent_object_finalize (GObject *object)
ValentObjectPrivate *priv = valent_object_get_instance_private (self);

g_clear_object (&priv->cancellable);
g_clear_pointer (&priv->iri, g_free);
g_rec_mutex_clear (&priv->mutex);

G_OBJECT_CLASS (valent_object_parent_class)->finalize (object);
Expand All @@ -225,10 +214,6 @@ valent_object_get_property (GObject *object,
g_value_take_object (value, valent_object_ref_cancellable (self));
break;

case PROP_IRI:
g_value_take_string (value, valent_object_dup_iri (self));
break;

default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand All @@ -249,10 +234,6 @@ valent_object_set_property (GObject *object,
priv->cancellable = g_value_dup_object (value);
break;

case PROP_IRI:
priv->iri = g_value_dup_string (value);
break;

default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand Down Expand Up @@ -289,25 +270,6 @@ valent_object_class_init (ValentObjectClass *klass)
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));

/**
* ValentObject:iri: (getter dup_iri)
*
* The object IRI.
*
* An IRI that uniquely identifies the object as a resource. This is mostly
* useful for objects representing a SPARQL resource and well-known objects
* in Valent's architecture.
*
* Since: 1.0
*/
properties [PROP_IRI] =
g_param_spec_string ("iri", NULL, NULL,
NULL,
(G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS));

g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);

/**
Expand Down Expand Up @@ -474,31 +436,6 @@ valent_object_chain_cancellable (ValentObject *object,
return g_steal_pointer (&ret);
}

/**
* valent_object_dup_iri:
* @object: a `ValentObject`
*
* Get a copy of the IRI for the object.
*
* Returns: (transfer full) (nullable): @object's IRI
*
* Since: 1.0
*/
char *
valent_object_dup_iri (ValentObject *object)
{
ValentObjectPrivate *priv = valent_object_get_instance_private (object);
char *ret;

g_return_val_if_fail (VALENT_IS_OBJECT (object), NULL);

valent_object_private_lock (priv);
ret = g_strdup (priv->iri);
valent_object_private_unlock (priv);

return g_steal_pointer (&ret);
}

/**
* valent_object_destroy:
* @object: a `ValentObject`
Expand Down
2 changes: 0 additions & 2 deletions src/libvalent/core/valent-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ void valent_object_unlock (ValentObject *object);
VALENT_AVAILABLE_IN_1_0
GCancellable * valent_object_ref_cancellable (ValentObject *object);
VALENT_AVAILABLE_IN_1_0
char * valent_object_dup_iri (ValentObject *object);
VALENT_AVAILABLE_IN_1_0
GCancellable * valent_object_chain_cancellable (ValentObject *object,
GCancellable *cancellable);
VALENT_AVAILABLE_IN_1_0
Expand Down
Loading
Loading