[PATCH v2 wayland 2/3] client: Use a 0 version to mean indeterminate proxy version

Derek Foreman derekf at osg.samsung.com
Tue Jan 12 14:28:46 PST 2016


This sets wl_display's version (for proxy version query purposes)
to 0.  Any proxy created with unversioned API (this happens when
a client compiled with old headers links against new wayland)
will inherit this 0.

This gives us a way for new libraries linked by old clients to
realize they can't know a proxy's version.

wl_display's version being unqueryable (always returning 0) is
an acceptable side effect, since it's a special object you can't
bind specific versions of anyway.

Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
Changes from v1:
Removed \note from documentation for wl_proxy_get_version()

 src/wayland-client.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index d935f6c..e133f19 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -922,7 +922,25 @@ wl_display_connect_to_fd(int fd)
 	display->proxy.queue = &display->default_queue;
 	display->proxy.flags = 0;
 	display->proxy.refcount = 1;
-	display->proxy.version = 1;
+
+	/* We set this version to 0 for backwards compatibility.
+	 *
+	 * If a client is using old versions of protocol headers,
+	 * it will use unversioned API to create proxies.  Those
+	 * proxies will inherit this 0.
+	 *
+	 * A client could be passing these proxies into library
+	 * code newer than the headers that checks proxy
+	 * versions.  When the proxy version is reported as 0
+	 * the library will know that it can't reliably determine
+	 * the proxy version, and should do whatever fallback is
+	 * required.
+	 *
+	 * This trick forces wl_display to always report 0, but
+	 * since it's a special object that we can't bind
+	 * specific versions of anyway, this should be fine.
+	 */
+	display->proxy.version = 0;
 
 	display->connection = wl_connection_create(display->fd);
 	if (display->connection == NULL)
@@ -1917,7 +1935,16 @@ wl_proxy_get_user_data(struct wl_proxy *proxy)
 /** Get the protocol object version of a proxy object
  *
  * \param proxy The proxy object
- * \return The protocol object version of the proxy
+ * \return The protocol object version of the proxy or 0
+ *
+ * Gets the protocol object version of a proxy object, or 0
+ * if the proxy was created with unversioned API.
+ *
+ * A returned value of 0 means that no version information is
+ * available, so the caller must make safe assumptions about
+ * the object's real version.
+ *
+ * wl_display's version will always return 0.
  *
  * \memberof wl_proxy
  */
-- 
2.6.4



More information about the wayland-devel mailing list