Implement missing xkb_state_ref and add return value 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.]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
diff --git a/include/xkbcommon/xkbcommon.h b/include/xkbcommon/xkbcommon.h
index 45e98e4..1391437 100644
--- a/include/xkbcommon/xkbcommon.h
+++ b/include/xkbcommon/xkbcommon.h
@@ -247,7 +247,7 @@ xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
/**
* Takes a new reference on an XKB context.
*/
-_X_EXPORT void
+_X_EXPORT struct xkb_context *
xkb_context_ref(struct xkb_context *context);
/**
@@ -315,7 +315,7 @@ xkb_map_new_from_string(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);
/**
@@ -412,9 +412,9 @@ _X_EXPORT struct xkb_state *
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);
/**
diff --git a/src/alloc.c b/src/alloc.c
index 52d7af2..a2a1330 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -266,8 +266,7 @@ XkbcAllocKeyboard(struct xkb_context *context)
return NULL;
xkb->refcnt = 1;
- xkb_context_ref(context);
- xkb->context = context;
+ xkb->context = xkb_context_ref(context);
return xkb;
}
diff --git a/src/context.c b/src/context.c
index cbad424..a2c8f56 100644
--- a/src/context.c
+++ b/src/context.c
@@ -158,10 +158,11 @@ xkb_context_include_path_get(struct xkb_context *context, unsigned int idx)
/**
* Take a new reference on the context.
*/
-void
+struct xkb_context *
xkb_context_ref(struct xkb_context *context)
{
context->refcnt++;
+ return context;
}
/**
diff --git a/src/state.c b/src/state.c
index 6a9505d..a9f748e 100644
--- a/src/state.c
+++ b/src/state.c
@@ -472,12 +472,18 @@ xkb_state_new(struct xkb_keymap *xkb)
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)
{
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 9534232..7ff22e1 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -312,10 +312,11 @@ xkb_map_new_from_fd(struct xkb_context *context,
return compile_keymap(context, file);
}
-void
+struct xkb_keymap *
xkb_map_ref(struct xkb_keymap *xkb)
{
xkb->refcnt++;
+ return xkb;
}
void