linux: plug a memory leak

In linux_platform_destroy we close all the handles for the different
libgl* providers, yet we do not free the memory for the base struct
linux_platform, causing a memory leak.

In reality the memory will never be freed ('still reachable' by valgrind)
as we do not have a API to call platform->destroy() and thus cleanup
this and other memory hunks.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
core: return false on failure in waffle_window_resize

The function return type is bool(ean) not a pointer.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
wflinfo: silence signed/unsigned comparison warning

The variable i is used as and compared vs unsigned int.
Change its type so silence the compiler warning.

Note: GLint is incorrectly typedeffed as unsigned and we're
using signed int where unsigned is required by the GL API
and vice versa. These will be addressed by followup patches.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
waffle_test: build as a static library

Will allow us to move the -fvisiblity=hidden flag to global scale,
without breaking the tests. It makes little sense to have a shared
library only for testing purposes anyway.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: move restrict keyword to c99_compat.h header

The header will be used to consolidate all the mayhem required in
order to get waffle building on compilers that are not fully c99
compliant (msvc 2013).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: define inline keyword and use it across waffle core

This brings us a step closer to getting waffle to build under msvc 2013.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: add snprintf and strcasecmp

Another two C99 functions missing from msvc 2013...

v2: Provide vsnprintf as well. Unused by waffle itself, yet
snprintf is implemented as a wrapper around it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com> [v1]
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
c99: use strerror_s over strerror_r under Windows

Windows/MS has dropped strerror_r support due to it _not_ being
thread-safe. At the same time, every *nix man page claims the
opposite.

The recommendation is to use strerror_s, although when building with
mingw-w64 we link against msvcrt.dll which does not provide the symbol
under Windows XP.

The issue is resolved in mingw-w64 master branch (Rev.6559), and
stable (v3.x). Any version after mingw-w64-crt 3.1.0 should be OK
(Archlinux users need v3.1.0-3 or later).

v2: Update the commit message - Archlinux package 3.1.0-3 has the fix.
v3: Move the definition to c99_compat.h
v4: Explain what the function is (if not C99 standard).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
third_party/threads: import c11 threads emulation wrappers

Will be used to simplify/abstract the threads differences
across posix/win32 waffle.

Based upon https://gist.github.com/2223710 with modifications from mesa:
 - retain XP compatability
 - add temporary hack for static mutex initializers (as they are not part
   of the stack but still widely used internally)
 - make TIME_UTC a conditional macro (some system headers already define
   it, so this prevents conflict)
 - fix missing pthread_mutex_timedlock declaration warnings on MacOSX
 - do not use pthread_mutex_timedlock on NetBSD
 - fix nano to milisecond conversion, per
   https://gist.github.com/yohhoy/2223710/#comment-710118
 - don't implement thrd_current on Windows
 - don't include assert.h if the assert macro is already defined

v2: Whitespace cleanup, enable PIC.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
third_party/threads: correct assertion

We should assert when either the function or the flag pointer
is null or we'll end up with a null reference a few lines later.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
third_party/threads: add missing brackets around _MTX_INITIALIZER_NP

... for win32 builds. Spotted by gcc(mingw-w64)

src/waffle/core/wcore_display.c:37:5: warning: missing braces around
initializer [-Wmissing-braces]
     static mtx_t mutex = _MTX_INITIALIZER_NP;
     ^

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
third_party/threads: use intptr_t for int<>void* typecasting

While the current code operates correctly, one needs to wrap
all the typecasting via intptr_t to prevent compiler warnings
such as

  warning: cast to pointer from integer of different size
  [-Wint-to-pointer-cast]

  warning: cast from pointer to integer of different size
  [-Wpointer-to-int-cast]

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
core: Convert to c11 threads

Will allow us more freedom wrt building/using waffle on
multiple OS's (mostly non-posix).

Note: pthreads_once has been converted to call_once which
"can never fail". This is a spec bug which will be addressed
in due time.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
core: convert wcore_error_unittest to c11 threads

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
third_party/getopt: include BSD licensed getopt implementation

This module has been ripped out of the apitrace project
https://github.com/apitrace/apitrace

Used by utils/wflinfo and examples/gl_basic.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
Android.mk: Fix version of 1.4.0

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
cmake: bump minimum cmake requirement to 2.8.11

commit 43f55fb150ac66498d29f33e5eaa49a1cb456f7e
Author: Emil Velikov <emil.l.velikov@gmail.com>
Date:   Fri Jul 18 14:09:03 2014 +0100

    cmake: rework cmocka build process

Reworked the cmocka build yet it introduced a dependency of
target_include_directories which does not exists in cmake up
until 2.8.11.

Reported-by: Dave Airlie <airlied@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Chad Versace <chad.versace@linux.intel.com>
waffle: Bump version to 1.4.90 for post-release

We always bump the version on master after a release and before merging
any non-trival patches.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Merge branch 'chadv/fix-waffle-version-on-android' into maint-1.4

* branch 'chadv/fix-waffle-version-on-android':
  Android.mk: Fix version of 1.4.0
Merge branch 'evelikov/cmake-fixes' into maint-1.4

* branch 'evelikov/cmake-fixes':
  cmake: bump minimum cmake requirement to 2.8.11