[Mesa-dev] [PATCH] c11/threads: don't include assert.h if the assert macro is already defined

Jose Fonseca jfonseca at vmware.com
Wed Mar 19 09:58:27 PDT 2014


Looks good.

This is yet another thing that would benefit if we moved things like u_debug.h's assert to a place it can be used everywhere -- the "shared runtime" idea.

Jose

----- Original Message -----
> In the gallium code, the assert() macro could come from either the
> system's assert.h file (via c11/threads.h) or from gallium's u_debug.h.
> It looks like all known assert.h files unconditionally #undef assert
> before defining their own version.  So the assert you get depends on
> whether threads.h or u_debug.h was included last.
> 
> In the gallium code we really want to use the assert() from u_debug.h
> (it behaves better on Windows).  In gallium, c11/threads.h is only
> included after u_debug.h in the os_thread.h wrapper.  So Adding
> an #ifndef assert test in the threads*.h files avoids using the system's
> assert().
> ---
>  include/c11/threads_posix.h |    2 ++
>  include/c11/threads_win32.h |    2 ++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h
> index 7e96715..f9c165d 100644
> --- a/include/c11/threads_posix.h
> +++ b/include/c11/threads_posix.h
> @@ -27,7 +27,9 @@
>   * DEALINGS IN THE SOFTWARE.
>   */
>  #include <stdlib.h>
> +#ifndef assert
>  #include <assert.h>
> +#endif
>  #include <limits.h>
>  #include <errno.h>
>  #include <unistd.h>
> diff --git a/include/c11/threads_win32.h b/include/c11/threads_win32.h
> index d4c2a72..5298a84 100644
> --- a/include/c11/threads_win32.h
> +++ b/include/c11/threads_win32.h
> @@ -26,7 +26,9 @@
>   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
>   OTHER
>   * DEALINGS IN THE SOFTWARE.
>   */
> +#ifndef assert
>  #include <assert.h>
> +#endif
>  #include <limits.h>
>  #include <errno.h>
>  #include <process.h>  // MSVCRT
> --
> 1.7.10.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://urldefense.proofpoint.com/v1/url?u=http://lists.freedesktop.org/mailman/listinfo/mesa-dev&k=oIvRg1%2BdGAgOoM1BIlLLqw%3D%3D%0A&r=NMr9uy2iTjWVixC0wOcYCWEIYhfo80qKwRgdodpoDzA%3D%0A&m=eaZGHreflnzApU1RHj9oenp5p%2BWkDfND%2FGLbVYKzyow%3D%0A&s=31f60c70a1ef0ca9a75ceca120d1a5ab5090a09f7e7751921078c3c80cedac3f
> 


More information about the mesa-dev mailing list