[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

wayland: Changes to 'upstream-unstable'



 .gitignore                         |    2 
 COPYING                            |   39 
 Makefile.am                        |   78 -
 configure.ac                       |   68 -
 cursor/convert_font.c              |   87 +
 cursor/cursor-data.h               |   34 
 cursor/os-compatibility.c          |   35 
 cursor/os-compatibility.h          |   35 
 cursor/wayland-cursor.c            |   35 
 cursor/wayland-cursor.h            |   35 
 cursor/xcursor.c                   |   35 
 cursor/xcursor.h                   |   35 
 doc/Contributing                   |   13 
 doc/doxygen/.gitignore             |    1 
 doc/doxygen/wayland.doxygen.in     | 1728 -------------------------------------
 doc/publican/sources/Book_Info.xml |   46 
 protocol/wayland.xml               |   40 
 src/connection.c                   |   35 
 src/event-loop.c                   |   37 
 src/scanner.c                      |  403 ++++++--
 src/wayland-client-core.h          |   37 
 src/wayland-client.c               |   47 -
 src/wayland-client.h               |   35 
 src/wayland-egl-core.h             |   35 
 src/wayland-egl.h                  |   35 
 src/wayland-os.c                   |   35 
 src/wayland-os.h                   |   35 
 src/wayland-private.h              |   35 
 src/wayland-server-core.h          |   35 
 src/wayland-server.c               |   40 
 src/wayland-server.h               |   35 
 src/wayland-shm.c                  |   35 
 src/wayland-util.c                 |   35 
 src/wayland-util.h                 |   35 
 src/wayland-version.h.in           |   35 
 tests/array-test.c                 |   44 
 tests/client-test.c                |   35 
 tests/connection-test.c            |   35 
 tests/display-test.c               |   35 
 tests/event-loop-test.c            |   35 
 tests/exec-fd-leak-checker.c       |   35 
 tests/fixed-benchmark.c            |   37 
 tests/fixed-test.c                 |   35 
 tests/headers-protocol-core-test.c |   35 
 tests/headers-protocol-test.c      |   35 
 tests/headers-test.c               |   35 
 tests/list-test.c                  |   35 
 tests/map-test.c                   |   35 
 tests/message-test.c               |   35 
 tests/os-wrappers-test.c           |   35 
 tests/queue-test.c                 |   35 
 tests/resources-test.c             |   35 
 tests/sanity-test.c                |   35 
 tests/signal-test.c                |   35 
 tests/socket-test.c                |   40 
 tests/test-compositor.c            |   35 
 tests/test-compositor.h            |   35 
 tests/test-helpers.c               |   35 
 tests/test-runner.c                |   35 
 tests/test-runner.h                |   24 
 60 files changed, 1465 insertions(+), 2780 deletions(-)

New commits:
commit b05668f0ad64ad9ba82e124965163daed4172ead
Author: Bryce Harrington <bryce@osg.samsung.com>
Date:   Mon Sep 21 16:51:16 2015 -0700

    configure.ac: bump to version 1.9.0 for the official release

diff --git a/configure.ac b/configure.ac
index 5580066..41cea2a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,8 +1,8 @@
 AC_PREREQ([2.64])
 
 m4_define([wayland_major_version], [1])
-m4_define([wayland_minor_version], [8])
-m4_define([wayland_micro_version], [93])
+m4_define([wayland_minor_version], [9])
+m4_define([wayland_micro_version], [0])
 m4_define([wayland_version],
           [wayland_major_version.wayland_minor_version.wayland_micro_version])
 

commit 8fd494995d000edbc9d4c1a1805d316ffdff8890
Author: Bryce Harrington <bryce@osg.samsung.com>
Date:   Tue Sep 15 20:16:37 2015 -0700

    configure.ac: bump to version 1.8.93 for the RC1 release

diff --git a/configure.ac b/configure.ac
index 40b0578..5580066 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ([2.64])
 
 m4_define([wayland_major_version], [1])
 m4_define([wayland_minor_version], [8])
-m4_define([wayland_micro_version], [92])
+m4_define([wayland_micro_version], [93])
 m4_define([wayland_version],
           [wayland_major_version.wayland_minor_version.wayland_micro_version])
 

commit b16c0a5dfa829ff6cef707ed72907c5f88acf3cf
Author: Bryce Harrington <bryce@osg.samsung.com>
Date:   Tue Sep 1 16:51:30 2015 -0700

    configure.ac: bump to version 1.8.92 for the beta release

diff --git a/configure.ac b/configure.ac
index 0009857..40b0578 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ([2.64])
 
 m4_define([wayland_major_version], [1])
 m4_define([wayland_minor_version], [8])
-m4_define([wayland_micro_version], [91])
+m4_define([wayland_micro_version], [92])
 m4_define([wayland_version],
           [wayland_major_version.wayland_minor_version.wayland_micro_version])
 

commit c7dbaa1cfda68185b3b0d3665efdf4620c66531e
Author: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Date:   Mon Aug 17 15:20:28 2015 +0300

    Revert "client: require WAYLAND_DISPLAY to be set"
    
    This reverts commit fb7e13021730d0a5516ecbd3712ea4235e05d24d.
    
    Developers have been trying to reduce the number of by default required
    environment variables, and the mentioned commit is a step backwards in
    that sense. The fundamental assumption is that a user has only one main
    (Wayland) display server where all programs should connect to by
    default, and do so with an a priori known socket name.
    
    The commit also broke various use cases in the wild, some accidentally
    due to other causes, some intentionally. This revert allows those use
    cases to continue.
    
    The original problem of running Weston in a window in an existing GNOME
    X11 session and getting applications unintentionally launched into
    Weston can be circumvented by letting Weston use a non-default socket
    name, leaving wayland-0 unused.
    
    Discussion:
    http://lists.freedesktop.org/archives/wayland-devel/2015-August/023927.html
    http://lists.freedesktop.org/archives/wayland-devel/2015-August/023937.html
    
    Cc: Dima Ryazanov <dima@gmail.com>
    Cc: Giulio Camuffo <giuliocamuffo@gmail.com>
    Cc: Daniel Stone <daniel@fooishbar.org>
    Cc: Jasper St. Pierre <jstpierre@mecheye.net>
    Cc: Ryo Munakata <ryomnktml@gmail.com>
    Cc: Ray Strode <halfline@gmail.com>
    Cc: Peter Hutterer <peter.hutterer@who-t.net>
    Cc: Matthias Clasen <mclasen@redhat.com>
    Cc: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
    Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
    Acked-by: Ray Strode <rstrode@redhat.com>
    Acked-by: Dima Ryazanov <dima@gmail.com>
    Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
    Acked-By: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
    Acked-By: Ryo Munakata <ryomnktml@gmail.com>
    Acked-by: Peter Hutterer <peter.hutterer@who-t.net>

diff --git a/doc/man/wl_display_connect.xml b/doc/man/wl_display_connect.xml
index ded3cbd..7e6e05c 100644
--- a/doc/man/wl_display_connect.xml
+++ b/doc/man/wl_display_connect.xml
@@ -57,8 +57,9 @@
           that was previously opened by a Wayland server. The server socket must
           be placed in <envar>XDG_RUNTIME_DIR</envar> for this function to
           find it. The <varname>name</varname> argument specifies the name of
-          the socket or <constant>NULL</constant> to use the default
-          (which is the value of <envar>WAYLAND_DISPLAY</envar>). If
+          the socket or <constant>NULL</constant> to use the default (which is
+          <constant>"wayland-0"</constant>). The environment variable
+          <envar>WAYLAND_DISPLAY</envar> replaces the default value. If
           <envar>WAYLAND_SOCKET</envar> is set, this function behaves like
           <function>wl_display_connect_to_fd</function> with the file-descriptor
           number taken from the environment variable.</para>
diff --git a/doc/publican/sources/Protocol.xml b/doc/publican/sources/Protocol.xml
index 9464953..477063b 100644
--- a/doc/publican/sources/Protocol.xml
+++ b/doc/publican/sources/Protocol.xml
@@ -60,10 +60,10 @@
     <title>Wire Format</title>
     <para>
       The protocol is sent over a UNIX domain stream socket, where the endpoint
-      name is determined by the <emphasis>WAYLAND_DISPLAY</emphasis>
-      environment variable.  Its value will usually be
-      <systemitem class="service">wayland-0</systemitem>.  The protocol is message-based.
-      A message sent by a client to the server is called request.  A message
+      usually is named <systemitem class="service">wayland-0</systemitem>
+      (although it can be changed via <emphasis>WAYLAND_DISPLAY</emphasis>
+      in the environment).  The protocol is message-based.  A
+      message sent by a client to the server is called request.  A message
       from the server to a client is called event.  Every message is
       structured as 32-bit words, values are represented in the host's
       byte-order.
diff --git a/src/wayland-client.c b/src/wayland-client.c
index ffbca4b..09c594a 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -764,11 +764,8 @@ connect_to_socket(const char *name)
 
 	if (name == NULL)
 		name = getenv("WAYLAND_DISPLAY");
-	if (name == NULL) {
-		wl_log("error: WAYLAND_DISPLAY not set in the environment.\n");
-		errno = ENOENT;
-		return -1;
-	}
+	if (name == NULL)
+		name = "wayland-0";
 
 	fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
 	if (fd < 0)
@@ -872,7 +869,8 @@ wl_display_connect_to_fd(int fd)
  * \return A \ref wl_display object or \c NULL on failure
  *
  * Connect to the Wayland display named \c name. If \c name is \c NULL,
- * its value will be replaced with the WAYLAND_DISPLAY environment variable.
+ * its value will be replaced with the WAYLAND_DISPLAY environment
+ * variable if it is set, otherwise display "wayland-0" will be used.
  *
  * \memberof wl_display
  */

commit c0636ddcacc72c34a773f170aabdb46a5a21c275
Author: Bryce Harrington <bryce@osg.samsung.com>
Date:   Sun Aug 16 13:54:50 2015 -0700

    configure.ac: bump to version 1.8.91 for the alpha release

diff --git a/configure.ac b/configure.ac
index 7166f52..0009857 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_PREREQ([2.64])
 
 m4_define([wayland_major_version], [1])
 m4_define([wayland_minor_version], [8])
-m4_define([wayland_micro_version],  [90])
+m4_define([wayland_micro_version], [91])
 m4_define([wayland_version],
           [wayland_major_version.wayland_minor_version.wayland_micro_version])
 

commit fb7e13021730d0a5516ecbd3712ea4235e05d24d
Author: Dima Ryazanov <dima@gmail.com>
Date:   Wed Aug 12 19:34:31 2015 -0700

    client: require WAYLAND_DISPLAY to be set
    
    Although defaulting to wayland-0 seems convenient, it has an undesirable
    side effect: clients may unintentionally connect to the wrong compositor.
    Generally, it's safer to fail instead. Here's a real example:
    
    In Fedora 22, Gtk+ prefers Wayland over X11, though the default session is still
    a normal X11 Gnome session. When you launch a Gtk+ app, it will try Wayland,
    fail, then try X11, and succesfully start up. That works fine.
    
    Now suppose you launch Weston while running the Gnome session. Suddenly, all
    of the Gtk+ apps launched from Gnome will show up inside Weston instead.
    That's unexpected. There's also no good way to prevent that from happening
    (other than perhaps setting WAYLAND_DISPLAY to an invalid value when launching
    an app).
    
    Not using wayland-0 as the default will solve that problem: an app launched
    from the X11 Gnome session will use the X11 backend regardless of whether
    there's a wayland compositor running at the same time.
    
    Everything else should work as before. The compositor already sets
    the WAYLAND_DISPLAY when starting the session, so the lack of the default value
    should not make a difference to the user.
    
    Signed-off-by: Dima Ryazanov <dima@gmail.com>
    Acked-by: Pekka Paalanen <ppaalanen@gmail.com>
    Acked-by: Giulio Camuffo <giuliocamuffo@gmail.com>
    Acked-by: Daniel Stone <daniel@fooishbar.org>
    Acked-by: Jasper St. Pierre <jstpierre@mecheye.net>
    Reviewed-by: Ryo Munakata <ryomnktml@gmail.com>
    
    [Pekka: dropped the wayland-server.c hunk, adjusted summary]
    
    Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>

diff --git a/doc/man/wl_display_connect.xml b/doc/man/wl_display_connect.xml
index 7e6e05c..ded3cbd 100644
--- a/doc/man/wl_display_connect.xml
+++ b/doc/man/wl_display_connect.xml
@@ -57,9 +57,8 @@
           that was previously opened by a Wayland server. The server socket must
           be placed in <envar>XDG_RUNTIME_DIR</envar> for this function to
           find it. The <varname>name</varname> argument specifies the name of
-          the socket or <constant>NULL</constant> to use the default (which is
-          <constant>"wayland-0"</constant>). The environment variable
-          <envar>WAYLAND_DISPLAY</envar> replaces the default value. If
+          the socket or <constant>NULL</constant> to use the default
+          (which is the value of <envar>WAYLAND_DISPLAY</envar>). If
           <envar>WAYLAND_SOCKET</envar> is set, this function behaves like
           <function>wl_display_connect_to_fd</function> with the file-descriptor
           number taken from the environment variable.</para>
diff --git a/doc/publican/sources/Protocol.xml b/doc/publican/sources/Protocol.xml
index 477063b..9464953 100644
--- a/doc/publican/sources/Protocol.xml
+++ b/doc/publican/sources/Protocol.xml
@@ -60,10 +60,10 @@
     <title>Wire Format</title>
     <para>
       The protocol is sent over a UNIX domain stream socket, where the endpoint
-      usually is named <systemitem class="service">wayland-0</systemitem>
-      (although it can be changed via <emphasis>WAYLAND_DISPLAY</emphasis>
-      in the environment).  The protocol is message-based.  A
-      message sent by a client to the server is called request.  A message
+      name is determined by the <emphasis>WAYLAND_DISPLAY</emphasis>
+      environment variable.  Its value will usually be
+      <systemitem class="service">wayland-0</systemitem>.  The protocol is message-based.
+      A message sent by a client to the server is called request.  A message
       from the server to a client is called event.  Every message is
       structured as 32-bit words, values are represented in the host's
       byte-order.
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 09c594a..ffbca4b 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -764,8 +764,11 @@ connect_to_socket(const char *name)
 
 	if (name == NULL)
 		name = getenv("WAYLAND_DISPLAY");
-	if (name == NULL)
-		name = "wayland-0";
+	if (name == NULL) {
+		wl_log("error: WAYLAND_DISPLAY not set in the environment.\n");
+		errno = ENOENT;
+		return -1;
+	}
 
 	fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
 	if (fd < 0)
@@ -869,8 +872,7 @@ wl_display_connect_to_fd(int fd)
  * \return A \ref wl_display object or \c NULL on failure
  *
  * Connect to the Wayland display named \c name. If \c name is \c NULL,
- * its value will be replaced with the WAYLAND_DISPLAY environment
- * variable if it is set, otherwise display "wayland-0" will be used.
+ * its value will be replaced with the WAYLAND_DISPLAY environment variable.
  *
  * \memberof wl_display
  */

commit 441f9bb144efd561f0ac4bc4e672acc9703b5126
Author: Elvis Lee <kwangwoong.lee@lge.com>
Date:   Fri Jul 31 18:02:54 2015 +0900

    wayland-client : Fix queue_release not to call proxy_destroy
    
    proxy_destroy could be called twice by wl_proxy_destroy and wl_event_queue_release.
    Then, wl_map_remove was called twice for same object id.
    
    Signed-off-by: Elvis Lee <kwangwoong.lee@lge.com>
    Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
    Reviewed-by: Daniel Stone <daniels@collabora.com>

diff --git a/src/wayland-client.c b/src/wayland-client.c
index 6450b67..09c594a 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -259,6 +259,7 @@ wl_event_queue_release(struct wl_event_queue *queue)
 {
 	struct wl_closure *closure;
 	struct wl_proxy *proxy;
+	bool proxy_destroyed;
 
 	while (!wl_list_empty(&queue->event_list)) {
 		closure = container_of(queue->event_list.next,
@@ -268,10 +269,11 @@ wl_event_queue_release(struct wl_event_queue *queue)
 		decrease_closure_args_refcount(closure);
 
 		proxy = closure->proxy;
-		if (proxy->refcount == 1)
-			proxy_destroy(proxy);
-		else
-			--proxy->refcount;
+		proxy_destroyed = !!(proxy->flags & WL_PROXY_FLAG_DESTROYED);
+
+		proxy->refcount--;
+		if (proxy_destroyed && !proxy->refcount)
+			free(proxy);
 
 		wl_closure_destroy(closure);
 	}

commit bbe6795d9b36efd59a3468cbfd6a5eb735ad1ad1
Author: Marek Chalupa <mchqwerty@gmail.com>
Date:   Thu Jul 30 16:42:00 2015 +0200

    scanner: check sanity of version
    
    scanner does not complain if we put into version attribute
    things like -1 1x 1:3 etc.
    
    Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
    Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>

diff --git a/src/scanner.c b/src/scanner.c
index b0e9ef7..9b41ae4 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -33,6 +33,7 @@
 #include <ctype.h>
 #include <expat.h>
 #include <getopt.h>
+#include <limits.h>
 
 #include "wayland-util.h"
 
@@ -499,6 +500,29 @@ free_interface(struct interface *interface)
 	free(interface);
 }
 
+/* convert string to unsigned integer,
+ * in the case of error, return -1 */
+static int
+strtouint(const char *str)
+{
+	long int ret;
+	char *end;
+	int prev_errno = errno;
+
+	errno = 0;
+	ret = strtol(str, &end, 10);
+	if (errno != 0 || end == str || *end != '\0')
+		return -1;
+
+	/* check range */
+	if (ret < 0 || ret > INT_MAX) {
+		return -1;
+	}
+
+	errno = prev_errno;
+	return (int)ret;
+}
+
 static void
 start_element(void *data, const char *element_name, const char **atts)
 {
@@ -516,7 +540,6 @@ start_element(void *data, const char *element_name, const char **atts)
 	const char *summary = NULL;
 	const char *since = NULL;
 	const char *allow_null = NULL;
-	char *end;
 	int i, version = 0;
 
 	ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser);
@@ -524,7 +547,9 @@ start_element(void *data, const char *element_name, const char **atts)
 		if (strcmp(atts[i], "name") == 0)
 			name = atts[i + 1];
 		if (strcmp(atts[i], "version") == 0)
-			version = atoi(atts[i + 1]);
+			version = strtouint(atts[i + 1]);
+			if (version == -1)
+				fail(&ctx->loc, "wrong version (%s)", atts[i + 1]);
 		if (strcmp(atts[i], "type") == 0)
 			type = atts[i + 1];
 		if (strcmp(atts[i], "value") == 0)
@@ -577,13 +602,9 @@ start_element(void *data, const char *element_name, const char **atts)
 			message->destructor = 1;
 
 		if (since != NULL) {
-			int prev_errno = errno;
-			errno = 0;
-			version = strtol(since, &end, 0);
-			if (errno != 0 || end == since || *end != '\0')
-				fail(&ctx->loc,
-				     "invalid integer (%s)\n", since);
-			errno = prev_errno;
+			version = strtouint(since);
+			if (version == -1)
+				fail(&ctx->loc, "invalid integer (%s)\n", since);
 		} else {
 			version = 1;
 		}

commit 765040d1a72e4e698d40874d181e1d9a4677213c
Author: Marek Chalupa <mchqwerty@gmail.com>
Date:   Thu Jul 30 15:07:22 2015 +0200

    scanner: use zxalloc
    
    Use xzalloc instead of xmalloc. This allows us to get rid
    of manual initializing the memory to 0s and the code is
    shorter and cleaner
    
    Suggested by Bryce Harrington
    
    Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
    Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>

diff --git a/src/scanner.c b/src/scanner.c
index 19755ec..b0e9ef7 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -169,9 +169,15 @@ fail_on_null(void *p)
 }
 
 static void *
-xmalloc(size_t s)
+zalloc(size_t s)
 {
-	return fail_on_null(malloc(s));
+	return calloc(s, 1);
+}
+
+static void *
+xzalloc(size_t s)
+{
+	return fail_on_null(zalloc(s));
 }
 
 static char *
@@ -321,14 +327,11 @@ create_message(struct location loc, const char *name)
 {
 	struct message *message;
 
-	message = xmalloc(sizeof *message);
+	message = xzalloc(sizeof *message);
 	message->loc = loc;
 	message->name = xstrdup(name);
 	message->uppercase_name = uppercase_dup(name);
 	wl_list_init(&message->arg_list);
-	message->arg_count = 0;
-	message->new_id_count = 0;
-	message->description = NULL;
 
 	return message;
 }
@@ -347,10 +350,8 @@ create_arg(const char *name)
 {
 	struct arg *arg;
 
-	arg = xmalloc(sizeof *arg);
+	arg = xzalloc(sizeof *arg);
 	arg->name = xstrdup(name);
-	arg->summary = NULL;
-	arg->interface_name = NULL;
 
 	return arg;
 }
@@ -412,10 +413,9 @@ create_enumeration(const char *name)
 {
 	struct enumeration *enumeration;
 
-	enumeration = xmalloc(sizeof *enumeration);
+	enumeration = xzalloc(sizeof *enumeration);
 	enumeration->name = xstrdup(name);
 	enumeration->uppercase_name = uppercase_dup(name);
-	enumeration->description = NULL;
 
 	wl_list_init(&enumeration->entry_list);
 
@@ -427,7 +427,7 @@ create_entry(const char *name, const char *value)
 {
 	struct entry *entry;
 
-	entry = xmalloc(sizeof *entry);
+	entry = xzalloc(sizeof *entry);
 	entry->name = xstrdup(name);
 	entry->uppercase_name = uppercase_dup(name);
 	entry->value = xstrdup(value);
@@ -466,12 +466,11 @@ create_interface(struct location loc, const char *name, int version)
 {
 	struct interface *interface;
 
-	interface = xmalloc(sizeof *interface);
+	interface = xzalloc(sizeof *interface);
 	interface->loc = loc;
 	interface->name = xstrdup(name);
 	interface->uppercase_name = uppercase_dup(name);
 	interface->version = version;
-	interface->description = NULL;
 	interface->since = 1;
 	wl_list_init(&interface->request_list);
 	wl_list_init(&interface->event_list);
@@ -509,22 +508,18 @@ start_element(void *data, const char *element_name, const char **atts)
 	struct arg *arg;
 	struct enumeration *enumeration;
 	struct entry *entry;
-	struct description *description;
-	const char *name, *type, *interface_name, *value, *summary, *since;
-	const char *allow_null;
+	struct description *description = NULL;
+	const char *name = NULL;
+	const char *type = NULL;
+	const char *interface_name = NULL;
+	const char *value = NULL;
+	const char *summary = NULL;
+	const char *since = NULL;
+	const char *allow_null = NULL;
 	char *end;
-	int i, version;
+	int i, version = 0;
 
 	ctx->loc.line_number = XML_GetCurrentLineNumber(ctx->parser);
-	name = NULL;
-	type = NULL;
-	version = 0;
-	interface_name = NULL;
-	value = NULL;
-	summary = NULL;
-	description = NULL;
-	since = NULL;
-	allow_null = NULL;
 	for (i = 0; atts[i]; i += 2) {
 		if (strcmp(atts[i], "name") == 0)
 			name = atts[i + 1];
@@ -551,7 +546,6 @@ start_element(void *data, const char *element_name, const char **atts)
 
 		ctx->protocol->name = xstrdup(name);
 		ctx->protocol->uppercase_name = uppercase_dup(name);
-		ctx->protocol->description = NULL;
 	} else if (strcmp(element_name, "copyright") == 0) {
 
 	} else if (strcmp(element_name, "interface") == 0) {
@@ -581,8 +575,6 @@ start_element(void *data, const char *element_name, const char **atts)
 
 		if (type != NULL && strcmp(type, "destructor") == 0)
 			message->destructor = 1;
-		else
-			message->destructor = 0;
 
 		if (since != NULL) {
 			int prev_errno = errno;
@@ -629,15 +621,18 @@ start_element(void *data, const char *element_name, const char **atts)
 			break;
 		}
 
-		if (allow_null == NULL || strcmp(allow_null, "false") == 0)
-			arg->nullable = 0;
-		else if (strcmp(allow_null, "true") == 0)
-			arg->nullable = 1;
-		else
-			fail(&ctx->loc, "invalid value for allow-null attribute (%s)", allow_null);
+		if (allow_null) {
+			if (strcmp(allow_null, "true") == 0)
+				arg->nullable = 1;
+			else if (strcmp(allow_null, "false") != 0)
+				fail(&ctx->loc,
+				     "invalid value for allow-null attribute (%s)",
+				     allow_null);
 
-		if (allow_null != NULL && !is_nullable_type(arg))
-			fail(&ctx->loc, "allow-null is only valid for objects, strings, and arrays");
+			if (!is_nullable_type(arg))
+				fail(&ctx->loc,
+				     "allow-null is only valid for objects, strings, and arrays");
+		}
 
 		if (summary)
 			arg->summary = xstrdup(summary);
@@ -669,7 +664,7 @@ start_element(void *data, const char *element_name, const char **atts)
 		if (summary == NULL)
 			fail(&ctx->loc, "description without summary");
 
-		description = xmalloc(sizeof *description);
+		description = xzalloc(sizeof *description);
 		description->summary = xstrdup(summary);
 
 		if (ctx->message)
@@ -1519,15 +1514,17 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	/* initialize protocol structure */
+	memset(&protocol, 0, sizeof protocol);
 	wl_list_init(&protocol.interface_list);
-	protocol.type_index = 0;
-	protocol.null_run_length = 0;
-	protocol.copyright = NULL;
 	protocol.core_headers = core_headers;
+
+	/* initialize context */
 	memset(&ctx, 0, sizeof ctx);
 	ctx.protocol = &protocol;
-
 	ctx.loc.filename = "<stdin>";
+
+	/* create XML parser */
 	ctx.parser = XML_ParserCreate(NULL);
 	XML_SetUserData(ctx.parser, &ctx);
 	if (ctx.parser == NULL) {

commit 289a75739b885821f94927caa50f8b1997130818
Author: Marek Chalupa <mchqwerty@gmail.com>
Date:   Thu Jul 30 15:07:21 2015 +0200

    scanner: get rid of leaks
    
    Free all the memory we have allocated during running.
    
    v2.: split creating objects and getting rid of leaks
         into two patches
    
         move check for NULL description into free_description
    
    v3.: rebase after previous patch fixes
    
    Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
    Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>

diff --git a/src/scanner.c b/src/scanner.c
index da33818..19755ec 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -333,6 +333,15 @@ create_message(struct location loc, const char *name)
 	return message;
 }
 
+static void
+free_arg(struct arg *arg)
+{
+	free(arg->name);
+	free(arg->interface_name);
+	free(arg->summary);
+	free(arg);
+}
+
 static struct arg *
 create_arg(const char *name)
 {
@@ -371,6 +380,33 @@ set_arg_type(struct arg *arg, const char *type)
 	return true;
 }
 
+static void
+free_description(struct description *desc)
+{
+	if (!desc)
+		return;
+
+	free(desc->summary);
+	free(desc->text);
+
+	free(desc);
+}
+
+static void
+free_message(struct message *message)
+{
+	struct arg *a, *a_next;
+
+	free(message->name);
+	free(message->uppercase_name);
+	free_description(message->description);
+
+	wl_list_for_each_safe(a, a_next, &message->arg_list, link)
+		free_arg(a);
+
+	free(message);
+}
+
 static struct enumeration *
 create_enumeration(const char *name)
 {
@@ -399,6 +435,32 @@ create_entry(const char *name, const char *value)
 	return entry;
 }
 
+static void
+free_entry(struct entry *entry)
+{
+	free(entry->name);
+	free(entry->uppercase_name);
+	free(entry->value);
+	free(entry->summary);
+
+	free(entry);
+}
+
+static void
+free_enumeration(struct enumeration *enumeration)
+{
+	struct entry *e, *e_next;
+
+	free(enumeration->name);
+	free(enumeration->uppercase_name);
+	free_description(enumeration->description);
+
+	wl_list_for_each_safe(e, e_next, &enumeration->entry_list, link)
+		free_entry(e);
+
+	free(enumeration);
+}
+
 static struct interface *
 create_interface(struct location loc, const char *name, int version)
 {
@@ -419,6 +481,26 @@ create_interface(struct location loc, const char *name, int version)
 }
 
 static void
+free_interface(struct interface *interface)
+{
+	struct message *m, *next_m;
+	struct enumeration *e, *next_e;
+
+	free(interface->name);
+	free(interface->uppercase_name);
+	free_description(interface->description);
+
+	wl_list_for_each_safe(m, next_m, &interface->request_list, link)
+		free_message(m);
+	wl_list_for_each_safe(m, next_m, &interface->event_list, link)
+		free_message(m);
+	wl_list_for_each_safe(e, next_e, &interface->enumeration_list, link)
+		free_enumeration(e);
+
+	free(interface);
+}
+
+static void
 start_element(void *data, const char *element_name, const char **atts)
 {
 	struct parse_context *ctx = data;
@@ -1107,7 +1189,7 @@ get_include_name(bool core, enum side side)
 static void
 emit_header(struct protocol *protocol, enum side side)
 {
-	struct interface *i;
+	struct interface *i, *i_next;
 	struct wl_array types;
 	const char *s = (side == SERVER) ? "SERVER" : "CLIENT";
 	char **p, *prev;
@@ -1160,7 +1242,7 @@ emit_header(struct protocol *protocol, enum side side)
 
 	printf("\n");
 
-	wl_list_for_each(i, &protocol->interface_list, link) {
+	wl_list_for_each_safe(i, i_next, &protocol->interface_list, link) {
 
 		emit_enumerations(i);
 
@@ -1174,6 +1256,8 @@ emit_header(struct protocol *protocol, enum side side)
 			emit_opcodes(&i->request_list, i);
 			emit_stubs(&i->request_list, i);
 		}
+
+		free_interface(i);
 	}
 
 	printf("#ifdef  __cplusplus\n"
@@ -1289,7 +1373,7 @@ emit_messages(struct wl_list *message_list,
 static void
 emit_code(struct protocol *protocol)
 {
-	struct interface *i;
+	struct interface *i, *next;
 	struct wl_array types;
 	char **p, *prev;
 
@@ -1324,7 +1408,7 @@ emit_code(struct protocol *protocol)
 	}
 	printf("};\n\n");
 
-	wl_list_for_each(i, &protocol->interface_list, link) {
+	wl_list_for_each_safe(i, next, &protocol->interface_list, link) {
 
 		emit_messages(&i->request_list, i, "requests");
 		emit_messages(&i->event_list, i, "events");
@@ -1347,9 +1431,21 @@ emit_code(struct protocol *protocol)
 			printf("\t0, NULL,\n");
 
 		printf("};\n\n");
+
+		/* we won't need it any further */
+		free_interface(i);
 	}
 }
 
+static void
+free_protocol(struct protocol *protocol)
+{
+	free(protocol->name);
+	free(protocol->uppercase_name);
+	free(protocol->copyright);
+	free_description(protocol->description);
+}
+
 int main(int argc, char *argv[])
 {
 	struct parse_context ctx;
@@ -1473,5 +1569,7 @@ int main(int argc, char *argv[])
 			break;
 	}
 
+	free_protocol(&protocol);
+
 	return 0;
 }

commit 87fab2e36cfc9b1ac782e26b5717518490176a2e
Author: Marek Chalupa <mchqwerty@gmail.com>
Date:   Thu Jul 30 15:07:20 2015 +0200

    scanner: refactor creating objects
    
    wrap creating and initializing objects (structures)
    into functions and use them in the code.
    
    v2. make create_.* functions consistent
        (no func will return NULL)
    
    Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
    Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>

diff --git a/src/scanner.c b/src/scanner.c
index 7d8cfb9..da33818 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1,6 +1,7 @@
 /*
  * Copyright © 2008-2011 Kristian Høgsberg
  * Copyright © 2011 Intel Corporation
+ * Copyright © 2015 Red Hat, Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -315,6 +316,108 @@ is_nullable_type(struct arg *arg)
 	}
 }
 
+static struct message *
+create_message(struct location loc, const char *name)
+{
+	struct message *message;
+
+	message = xmalloc(sizeof *message);
+	message->loc = loc;
+	message->name = xstrdup(name);
+	message->uppercase_name = uppercase_dup(name);
+	wl_list_init(&message->arg_list);
+	message->arg_count = 0;
+	message->new_id_count = 0;
+	message->description = NULL;
+
+	return message;
+}
+
+static struct arg *
+create_arg(const char *name)
+{
+	struct arg *arg;
+
+	arg = xmalloc(sizeof *arg);
+	arg->name = xstrdup(name);
+	arg->summary = NULL;
+	arg->interface_name = NULL;
+
+	return arg;
+}
+
+static bool
+set_arg_type(struct arg *arg, const char *type)
+{
+	if (strcmp(type, "int") == 0)
+		arg->type = INT;
+	else if (strcmp(type, "uint") == 0)
+		arg->type = UNSIGNED;
+	else if (strcmp(type, "fixed") == 0)
+		arg->type = FIXED;
+	else if (strcmp(type, "string") == 0)
+		arg->type = STRING;
+	else if (strcmp(type, "array") == 0)
+		arg->type = ARRAY;
+	else if (strcmp(type, "fd") == 0)
+		arg->type = FD;
+	else if (strcmp(type, "new_id") == 0)
+		arg->type = NEW_ID;
+	else if (strcmp(type, "object") == 0)
+		arg->type = OBJECT;
+	else
+		return false;
+
+	return true;
+}
+
+static struct enumeration *
+create_enumeration(const char *name)
+{
+	struct enumeration *enumeration;
+
+	enumeration = xmalloc(sizeof *enumeration);
+	enumeration->name = xstrdup(name);
+	enumeration->uppercase_name = uppercase_dup(name);
+	enumeration->description = NULL;


Reply to: