Commit graph

133 commits

Author SHA1 Message Date
Jonas Ådahl
2f666ee34f scanner: Add missing brackets
A statement was added at the same indentation level as the true branch
of the if statement, but since there were no brackets, it would be
executed independently of the result of the if condition.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
2016-01-12 12:05:47 +08:00
Peter Hutterer
f66e2d53dd Validate the protocol xml during scanning
Embed the wayland.dtd protocol data into the scanner binary so we can validate
external protocol files without requiring makefile changes. Hat-tip to Pekka
Paalanen for the embedding trick.
The embedding trick doesn't work well if the to-be-embedded file is in a
different location than the source file, so copy/link it during configure and
then build it in from the local directory.

The current expat parser is not a validating parser, moving scanner.c to
another parser has the risk of breaking compatibility. This patch adds libxml2
as extra (optional) dependency, but that also requires parsing the input
twice.

If the protocol fails validation a warning is printed but no error is returned
otherwise.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-11-17 14:36:21 +02:00
Auke Booij
1771299a5a scanner: enforce correct argument type for enums
The scanner now checks whether arguments that have an associated
<enum> have the right type.
An argument with an enum attribute must be of type int or uint,
and if the <enum> with that name has the bitfield attribute
set to true, then the argument must be of type uint.

Changes since v3:
 - Remove useless allow_null check
 - Switch to using bool
 - Clearer message on errorous input
 - Minor formatting fix

Signed-off-by: Auke Booij <auke@tulcod.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Nils Chr. Brause <nilschrbrause@googlemail.com>
2015-11-04 14:51:43 -08:00
Jon Cruz
1cf175eba4 scanner: stop adding trailing whitespace to copyright
Generated code was unconditionally adding a space to lines
in comments for copyright blocks even if the line was blank.
Updated to not add trailing whitespace for blank lines.

Signed-off-by: Jon A. Cruz <jonc@osg.samsung.com>
2015-10-26 10:51:20 -07:00
Jonas Ådahl
9ebdcab109 scanner: Generate 'since' macros for requests as well
We already generate WL_[INTERFACE]_[REQUEST]_SINCE_VERSION macros for
events in the server protocol headers. Lets do the same for requests in
the client protocol headers as well.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: David FORT <contact@hardening-consulting.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-10-09 21:02:03 +08:00
Bryce Harrington
e0b2166c99 scanner: Close input resource when done to prevent leak
Addresses this error reported by Denis Denisov:

  [src/scanner.c:1415]: (error) Resource leak: input

Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>

v2: Also close input for other exit points in main.
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: David FORT <contact@hardening-consulting.com>
2015-10-05 16:47:58 -05:00
Marek Chalupa
bbe6795d9b 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>
2015-07-30 18:33:31 -07:00
Marek Chalupa
765040d1a7 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>
2015-07-30 18:24:04 -07:00
Marek Chalupa
289a75739b 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>
2015-07-30 18:23:42 -07:00
Marek Chalupa
87fab2e36c 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>
2015-07-30 18:23:15 -07:00
Bryce Harrington
3c91b0878d src: Update boilerplate from MIT X11 license to MIT Expat license
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-12 15:31:24 -07:00
Giulio Camuffo
f0be757bfa scanner: don't emit the extern declarations for external types
We were emitting the extern declarations of all types used in the protocol,
even if not defined in it. This caused warnings to be produced when using
the -Wredundant-decls compiler flag when building an extension that uses
e.g. wl_surface. However we only need the extern declarations if the
protocol defines a factory for those external interfaces. That is a
bad design and can be however done by including the dependent protocol
header first.
So only emit the extern declarations for the types that the protocol
actually defines, this restoring the behavior we were using in 1.7.

Fixes https://bugs.freedesktop.org/show_bug.cgi?id=90677

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Tested-by: Arnaud Vrac <rawoul@gmail.com>
2015-06-01 11:47:39 +03:00
Michael Vetter
b409c919a2 remove trailing whitespaces
Remove trailing whitespaces because they are not needed and jumping to
the end of al ine should do just that and not jump to the whitespace.
2015-05-15 13:10:15 -07:00
Pekka Paalanen
d08c079739 scanner: simplify the getopt logic
Use the same retvals for both short and long options.

Whitespace fixes.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-05-08 14:21:55 -07:00
Giulio Camuffo
e799b1fa9c scanner: add a new --include-core-only option
When using this new option the generated code will include the new
core headers instead of the old ones. The default needs to remain
unchanged for backward compatibility with old code.
With this change the generated headers will now forward declare all
types and interfaces it uses; that is needed when generating headers
for a my-extension.xml with --include-core-only, since it may use
types defined in wayland.xml.
The same is done also without --include-core-only, since it is an
harmless change.
getopt_long() is used for the option handling.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-04-30 15:18:45 +03:00
Jonas Ådahl
0583ce741e scanner: Fail on empty enumerations
Without this patch, the scanner would generate invalid C which wouldn't
compile anyway, so lets be nice and fail earlier and point out where the
error is.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>
Reviewed-by: David Fort <contact@hardening-consulting.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-04-08 17:38:10 +08:00
Jussi Pakkanen
2d46da10d8 Add support for direct file reading and writing in wayland-scanner.
Add support for direct file reading and writing in wayland-scanner.

Signed-off-by: Jussi Pakkanen <jpakkane@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Acked-by: David Fort <rdp.effort@gmail.com>
2015-03-27 15:02:38 +02:00
Mariusz Ceier
6197f32cad scanner: Fix header generation for server protocols
Server protocols headers should include wayland-server.h,
instead of wayland-util.h. Otherwise they're not useable
with C++ compiler unless wayland-server.h was included
earlier.

Signed-off-by: Mariusz Ceier <mceier+wayland@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-01-27 11:18:36 +00:00
Seedo Eldho Paul
93e352d058 scanner.c: Use WL_PRINTF instead of __attribute__((format(printf)))
Signed-off-by: Seedo Eldho Paul <seedoeldhopaul@gmail.com>
2014-11-28 12:37:20 +02:00
Imran Zaman
ff769d8fae scanner, client: Added more error checks when strtol function is used
Signed-off-by: Imran Zaman <imran.zaman@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-10 15:25:13 +02:00
Derek Foreman
322cd6dded cosmetic: convert some function returns from int to bool
[Pekka Paalanen: change is_nullable_type() return value to bool.]

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-04 13:01:58 +02:00
Jonas Ådahl
9dba854547 scanner: Remove stray newline
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-09-23 11:40:46 +03:00
Jonas Ådahl
2028227acc scanner: Improve XML parse error reporting
Print the parse error and exit with a failure if expat can't parse the
XML.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-09-23 11:40:46 +03:00
Jasper St. Pierre
edddb0f58e scanner: Make emit_structs more explicit
"is_interface" is a really terrible name for the client or server
variants, and instead of checking whether we were passed the requests or
the events, just pass an argument through.

Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-18 11:31:48 +03:00
Jasper St. Pierre
eb223cc2f6 scanner: Use an enum to determine the type of thing we're writing out
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-18 11:22:33 +03:00
Kristian Høgsberg
8511544e6b scanner: Downgrade non-increasing version error to warning
Commit 99a72777f9 introduced a new error
for when the 'since' version decreases.  It also reset the version for
messages without a version to 1.  Versioning semantics in the spec files
was a little under-specified and we don't want to break projects caught in
this grey zone.

This commits replaces previous configure.ac as the 1.4.93 tag and the
final 1.5 RC.
2014-05-12 15:35:04 -07:00
Jonas Ådahl
35be5a7c65 scanner: Generate macros for getting the 'since' version of an event
This could be useful for compositors who need to be able to not send
events if the client bound a version lower than the newest provided.

Event version numbers are exposed as
[INTERFACE_NAME]_[EVENT_NAME]_SINCE_VERSION for example wl_output.scale
will have the version macro WL_OUTPUT_SCALE_SINCE_VERSION.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-05-09 14:33:20 -07:00
Jonas Ådahl
99a72777f9 scanner: Also fail when an implicitly versioned message is out of order
Fail if a message with version implicitly set to 1 (i.e. not specified)
comes after a message with since-version > 1.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-05-09 14:31:28 -07:00
U. Artie Eoff
7a17b05187 scanner: check wl_array_add result
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-05-06 14:57:35 -07:00
Kristian Høgsberg
c1aa1291a1 scanner: Only output each forward declaration once
Just sort the types and only print unique type names.  We avoid using
the GCC pragma.
2014-04-03 15:58:06 -07:00
Jasper St. Pierre
859b3e41f5 scanner: Add GCC pragmas to disable -Wredundant-decls
The code very intentionally emits a lot of redundant declarations
to simplify the scanner code. Somebody building with -Wredundant-decls
would have compile errors, so emit special pragmas to turn those
warnings off.

These pragmas should be ignored outside of gcc/clang.
2014-02-18 14:28:08 -08:00
Adrian Negreanu
cd0dccd01e scanner: set errno=0 before strtol
POSIX says to set errno=0 before calling strtol since
the return value alne cannot tell a failure.

on ubuntu armel I get:

  ../src/wayland-scanner client-header < ../../protocol/wayland.xml > wayland-client-protocol.h
  <stdin>:1188: error: invalid integer (2)

Signed-off-by: Adrian Negreanu <adrian.m.negreanu@intel.com>
2013-12-17 10:57:52 -08:00
Kristian Høgsberg
853c24e699 client: Introduce functions to allocate and marshal proxies atomically
The server requires clients to only allocate one ID ahead of the previously
highest ID in order to keep the ID range tight.  Failure to do so will
make the server close the client connection.  However, the way we allocate
new IDs is racy.  The generated code looks like:

  new_proxy = wl_proxy_create(...);
  wl_proxy_marshal(proxy, ... new_proxy, ...);

If two threads do this at the same time, there's a chance that thread A
will allocate a proxy, then get pre-empted by thread B which then allocates
a proxy and then passes it to wl_proxy_marshal().  The ID for thread As
proxy will be one higher that the currently highest ID, but the ID for
thread Bs proxy will be two higher.  But since thread B prempted thread A
before it could send its new ID, B will send its new ID first, the server
will see the ID from thread Bs proxy first, and will reject it.

We fix this by introducing wl_proxy_marshal_constructor().  This
function is identical to wl_proxy_marshal(), except that it will
allocate a wl_proxy for NEW_ID arguments and send it, all under the
display mutex.  By introducing a new function, we maintain backwards
compatibility with older code from the generator, and make sure that
the new generated code has an explicit dependency on a new enough
libwayland-client.so.

A virtual Wayland merit badge goes to Kalle Vahlman, who tracked this
down and analyzed the issue.

Reported-by: Kalle Vahlman <kalle.vahlman@movial.com>
2013-11-15 20:49:36 -08:00
Kristian Høgsberg
a71cf48ce0 scanner: Add location to elements so we can give better errors/warnings 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
5a4dd76495 scanner: Make fail() function use va_list and elaborate a few errors 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
db8ae8903f scanner: Introduce struct location for tracking source locations 2013-11-15 14:44:39 -08:00
Kristian Høgsberg
3470fa17b5 scanner: Warn about requests with more than one new-id and don't generate stubs
The generated code only support one new-id per request, since the stubs
return the new proxy.  It's still possible to send requests with multiple
new-id arguments, but it must be done with
wl_proxy_marshal_array_constructor().
2013-11-15 14:44:39 -08:00
Kristian Høgsberg
bb6f6faaa2 scanner: Handle unrecognized invocation mode
Print usage if we don't recognize the invocation mode.  Also fixes
uninitialized variable warning.
2013-10-07 21:36:31 -07:00
Kristian Høgsberg
b76a6968fc scanner: Emit wl_*_destroy stub even if interface has a destructor
If an interface has a destructor but no 'destroy' method we used to
not emit a destroy method.  Now with the fix for missing destroy
requests for wl_pointer etc we need to emit the local wl_*_destroy
always.
2013-08-30 15:53:55 -07:00
Peter Hutterer
2b26edb877 scanner: expand help string
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2013-08-07 16:24:55 -07:00
Peter Hutterer
2d1ed470d9 scanner: support help and --help
wayland-scanner without arguments prints out usage. With help or --help it
waits for stdin to supply something which isn't quite as informative as
printing out the help.

This patch also moves the strcmp for args up to have all of them in one
location.
2013-08-07 16:24:44 -07:00
Kristian Høgsberg
8bd93c5c9d scanner: Fail more gracefully on out-of-memory
Failing with an error message and error code is little nicer.  I doubt we'll
hit this case much, but it makes the static analysis happy.
2013-07-13 00:35:21 -04:00
Jason Ekstrand
d35b6278c0 Add version information to wl_message signatures.
This commit adds version information to wl_message signatures and a
wl_message_get_since function to retrieve.  The since version comes in the
form of a (possible) integer at the begining of the message.  If the
message starts with an integer, then it specifies the "since" version of
that message.  Messages present in version one do not get this "since"
information.  In this way we can run-time detect the version information
for a structure on a per-message basis.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-07-02 15:52:47 -04:00
Kristian Høgsberg
d94a8722cb server: Make wl_object and wl_resource opaque structs
With the work to add wl_resource accessors and port weston to use them,
we're ready to make wl_resource and wl_object opaque structs.  We keep
wl_buffer in the header for EGL stacks to use, but don't expose it by
default.  In time we'll remove it completely, but for now it provides a
transition paths for code that still uses wl_buffer.

Reviewed-by: Jason Ekstrand<jason@jlekstrand.net>
2013-07-02 15:52:47 -04:00
Kristian Høgsberg
b581d13a7e scanner: Fix 'destroy)' typo in check for destroy request presence
This is there to enforce that we don't have interfaces with a destroy
request that isn't a destructor.  The check never worked because of the
typo, but we also don't have any interfaces like that.
2013-02-25 16:01:38 -05:00
Ran Benita
f53f42a1e7 scanner: remove list_length in favor of wl_list_length 2013-02-25 13:12:27 -05:00
Ander Conselvan de Oliveira
00639de120 scanner: Fix wrong restriction on since field
The scanner would not allow two consecutive requests on an interface to
have the same since number, so if a new version of an interface added
two new request the version number would have to be increased by two.
2012-11-27 11:13:36 -05:00
Kristian Høgsberg
3b7d7b0c80 scanner: Preserve paragraph breaks in input XML
If we have a blank line in the incoming XML documentation, keep that in
the emitted doxygen comments.
2012-10-21 22:24:33 -04:00
Kristian Høgsberg
1bade73b6b scanner: Fix valgrind errors 2012-10-20 11:38:57 -04:00
Kristian Høgsberg
bdd272f024 Move ARRAY_LENGTH out of public headers
Exporting unprefixed symbols is a pretty bad idea so don't do that.
Instea of redefining it WL_ARRAY_LENGTH, we just move the define to
our private header.  The scanner generates code that uses ARRAY_LENGTH,
but we can just make it count the number elements and emit an integer
constant instead.
2012-10-19 17:08:38 -04:00