xkb_state_ref was missing.
Also modify the _ref functions to return the object instead of being
void. This is a useful idiom:
struct my_object my_object_new(struct xkb_state *state)
{
[...]
my_object->state = xkb_state_ref(state);
[...]
}
Essentially "taking" a reference, such that you don't forget to
increment it and it's one line less (see example in our own code).
A case could also be made for _unref to return the object or NULL, but
this is quite uncommon.
Signed-off-by: Ran Benita <ran234@gmail.com>
[daniels: Updated for xkb_keymap changes.]
/**
* Takes a new reference on an XKB context.
*/
-_X_EXPORT void
+_X_EXPORT struct xkb_context *
xkb_context_ref(struct xkb_context *context);
/**
/**
* Takes a new reference on a keymap.
*/
-_X_EXPORT extern void
+_X_EXPORT extern struct xkb_keymap *
xkb_map_ref(struct xkb_keymap *xkb);
/**
xkb_state_new(struct xkb_keymap *xkb);
/**
- * Adds a reference to a state object, so it will not be freed until unref.
+ * Takes a new reference on a state object.
*/
-_X_EXPORT void
+_X_EXPORT struct xkb_state *
xkb_state_ref(struct xkb_state *state);
/**
return NULL;
xkb->refcnt = 1;
- xkb_context_ref(context);
- xkb->context = context;
+ xkb->context = xkb_context_ref(context);
return xkb;
}
/**
* Take a new reference on the context.
*/
-void
+struct xkb_context *
xkb_context_ref(struct xkb_context *context)
{
context->refcnt++;
+ return context;
}
/**
return NULL;
ret->refcnt = 1;
- ret->xkb = xkb;
- xkb_map_ref(xkb);
+ ret->xkb = xkb_map_ref(xkb);
return ret;
}
+struct xkb_state *
+xkb_state_ref(struct xkb_state *state)
+{
+ state->refcnt++;
+ return state;
+}
+
void
xkb_state_unref(struct xkb_state *state)
{
return compile_keymap(context, file);
}
-void
+struct xkb_keymap *
xkb_map_ref(struct xkb_keymap *xkb)
{
xkb->refcnt++;
+ return xkb;
}
void