[Mesa-dev] [PATCH] Fix invalid extern "C" around header inclusion.

Jose Fonseca jfonseca at vmware.com
Thu Mar 5 04:54:52 PST 2015


Thanks for doing this.  It looks great.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>


Feel free to push my patch or I'll push it after you push this one.

Jose


On 05/03/15 00:37, Mark Janes wrote:
> System headers may contain C++ declarations, which cannot be given C
> linkage.  For this reason, include statements should never occur
> inside extern "C".
>
> This patch moves the C linkage statements to enclose only the
> declarations within a single header.
> ---
>   src/gallium/auxiliary/util/u_math.h                      | 11 +++++------
>   src/gallium/drivers/r600/r600_shader.h                   | 12 ++++++++++++
>   src/gallium/drivers/r600/sb/sb_bc.h                      |  2 --
>   src/gallium/drivers/r600/sb/sb_bc_parser.cpp             |  2 --
>   src/gallium/drivers/r600/sb/sb_core.cpp                  |  2 --
>   src/gallium/drivers/r600/sb/sb_public.h                  | 12 ++++++++++++
>   src/glx/indirect_init.h                                  |  8 ++++++++
>   src/glx/tests/indirect_api.cpp                           |  2 --
>   src/mapi/shared-glapi/tests/check_table.cpp              |  2 --
>   src/mesa/drivers/common/driverfuncs.h                    |  7 +++++++
>   src/mesa/drivers/dri/i965/brw_fs.cpp                     |  3 ---
>   src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp |  2 --
>   src/mesa/drivers/dri/i965/brw_fs_generator.cpp           |  3 ---
>   src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp    |  2 --
>   src/mesa/drivers/dri/i965/brw_fs_visitor.cpp             |  3 ---
>   src/mesa/drivers/dri/i965/brw_shader.cpp                 |  2 --
>   src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp      |  3 ---
>   src/mesa/drivers/dri/i965/brw_wm.h                       |  8 ++++++++
>   src/mesa/main/api_exec.h                                 |  7 +++++++
>   src/mesa/main/tests/dispatch_sanity.cpp                  |  2 --
>   src/mesa/main/tests/program_state_string.cpp             |  2 --
>   src/mesa/main/vtxfmt.h                                   |  8 ++++++++
>   src/mesa/vbo/vbo.h                                       |  8 ++++++++
>   src/mesa/vbo/vbo_context.h                               |  8 ++++++++
>   src/util/Makefile.am                                     |  3 +++
>   src/util/register_allocate.h                             | 10 ++++++++++
>   26 files changed, 96 insertions(+), 38 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
> index 5400fce..8f62cac 100644
> --- a/src/gallium/auxiliary/util/u_math.h
> +++ b/src/gallium/auxiliary/util/u_math.h
> @@ -41,12 +41,6 @@
>
>   #include "pipe/p_compiler.h"
>
> -
> -#ifdef __cplusplus
> -extern "C" {
> -#endif
> -
> -
>   #include "c99_math.h"
>   #include <float.h>
>   #include <stdarg.h>
> @@ -56,6 +50,11 @@ extern "C" {
>   #endif
>
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +
>   #ifndef M_SQRT2
>   #define M_SQRT2 1.41421356237309504880
>   #endif
> diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h
> index b2559e9..dd359d7 100644
> --- a/src/gallium/drivers/r600/r600_shader.h
> +++ b/src/gallium/drivers/r600/r600_shader.h
> @@ -25,6 +25,12 @@
>
>   #include "r600_asm.h"
>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +
>   struct r600_shader_io {
>   	unsigned		name;
>   	unsigned		gpr;
> @@ -125,4 +131,10 @@ struct r600_pipe_shader {
>    TGSI_INTERPOLATE_LOC_CENTER/SAMPLE/COUNT. Other input values return -1. */
>   int eg_get_interpolator_index(unsigned interpolate, unsigned location);
>
> +
> +#ifdef __cplusplus
> +}  // extern "C"
> +#endif
> +
> +
>   #endif
> diff --git a/src/gallium/drivers/r600/sb/sb_bc.h b/src/gallium/drivers/r600/sb/sb_bc.h
> index 072d8f8..ab988f8 100644
> --- a/src/gallium/drivers/r600/sb/sb_bc.h
> +++ b/src/gallium/drivers/r600/sb/sb_bc.h
> @@ -27,10 +27,8 @@
>   #ifndef SB_BC_H_
>   #define SB_BC_H_
>
> -extern "C" {
>   #include <stdint.h>
>   #include "r600_isa.h"
> -}
>
>   #include <cstdio>
>   #include <string>
> diff --git a/src/gallium/drivers/r600/sb/sb_bc_parser.cpp b/src/gallium/drivers/r600/sb/sb_bc_parser.cpp
> index 403f938..08e7f5c 100644
> --- a/src/gallium/drivers/r600/sb/sb_bc_parser.cpp
> +++ b/src/gallium/drivers/r600/sb/sb_bc_parser.cpp
> @@ -32,10 +32,8 @@
>   #define BCP_DUMP(q)
>   #endif
>
> -extern "C" {
>   #include "r600_pipe.h"
>   #include "r600_shader.h"
> -}
>
>   #include <stack>
>
> diff --git a/src/gallium/drivers/r600/sb/sb_core.cpp b/src/gallium/drivers/r600/sb/sb_core.cpp
> index 9fd9d9a..7db8008 100644
> --- a/src/gallium/drivers/r600/sb/sb_core.cpp
> +++ b/src/gallium/drivers/r600/sb/sb_core.cpp
> @@ -26,13 +26,11 @@
>
>   #define SB_RA_SCHED_CHECK DEBUG
>
> -extern "C" {
>   #include "os/os_time.h"
>   #include "r600_pipe.h"
>   #include "r600_shader.h"
>
>   #include "sb_public.h"
> -}
>
>   #include <stack>
>   #include <map>
> diff --git a/src/gallium/drivers/r600/sb/sb_public.h b/src/gallium/drivers/r600/sb/sb_public.h
> index c9f5f97..a90771f 100644
> --- a/src/gallium/drivers/r600/sb/sb_public.h
> +++ b/src/gallium/drivers/r600/sb/sb_public.h
> @@ -27,6 +27,12 @@
>   #ifndef R600_SB_H_
>   #define R600_SB_H_
>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +
>   struct r600_shader;
>
>   void r600_sb_context_destroy(void *sctx);
> @@ -37,4 +43,10 @@ int r600_sb_bytecode_process(struct r600_context *rctx,
>                                int dump_source_bytecode,
>                                int optimize);
>
> +
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
> +
>   #endif //R600_SB_H_
> diff --git a/src/glx/indirect_init.h b/src/glx/indirect_init.h
> index 2ba01f5..7fe9a96 100644
> --- a/src/glx/indirect_init.h
> +++ b/src/glx/indirect_init.h
> @@ -36,6 +36,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
>
>   #include "glxclient.h"
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
>   extern struct _glapi_table *__glXNewIndirectAPI(void);
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
>   #endif /* _INDIRECT_INIT_H_ */
> diff --git a/src/glx/tests/indirect_api.cpp b/src/glx/tests/indirect_api.cpp
> index 52469a7..34304a1 100644
> --- a/src/glx/tests/indirect_api.cpp
> +++ b/src/glx/tests/indirect_api.cpp
> @@ -45,11 +45,9 @@
>
>   #include <gtest/gtest.h>
>   #include "main/glheader.h"
> -extern "C" {
>   #include "../indirect_init.h"
>   #include "glapi/glapi.h"
>   #include "../../mesa/main/dispatch.h"
> -}
>
>   static const void *nil = 0;
>
> diff --git a/src/mapi/shared-glapi/tests/check_table.cpp b/src/mapi/shared-glapi/tests/check_table.cpp
> index 47c0b27..02d313c 100644
> --- a/src/mapi/shared-glapi/tests/check_table.cpp
> +++ b/src/mapi/shared-glapi/tests/check_table.cpp
> @@ -24,10 +24,8 @@
>   #include <gtest/gtest.h>
>   #include "../../../mesa/main/glheader.h"
>
> -extern "C" {
>   #include "glapi/glapi.h"
>   #include "glapi/glapitable.h"
> -}
>
>   struct name_offset {
>      const char *name;
> diff --git a/src/mesa/drivers/common/driverfuncs.h b/src/mesa/drivers/common/driverfuncs.h
> index 6b9a900..385ccb8 100644
> --- a/src/mesa/drivers/common/driverfuncs.h
> +++ b/src/mesa/drivers/common/driverfuncs.h
> @@ -26,6 +26,10 @@
>   #ifndef DRIVERFUNCS_H
>   #define DRIVERFUNCS_H
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
>   extern void
>   _mesa_init_driver_functions(struct dd_function_table *driver);
>
> @@ -33,5 +37,8 @@ _mesa_init_driver_functions(struct dd_function_table *driver);
>   extern void
>   _mesa_init_driver_state(struct gl_context *ctx);
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
>
>   #endif
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
> index 533feb4..d6acc23 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
> @@ -28,8 +28,6 @@
>    * from the LIR.
>    */
>
> -extern "C" {
> -
>   #include <sys/types.h>
>
>   #include "util/hash_table.h"
> @@ -43,7 +41,6 @@ extern "C" {
>   #include "brw_context.h"
>   #include "brw_eu.h"
>   #include "brw_wm.h"
> -}
>   #include "brw_fs.h"
>   #include "brw_cfg.h"
>   #include "brw_dead_control_flow.h"
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp b/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> index c64742c..933fdde 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> @@ -41,10 +41,8 @@
>    * we do retain the vector types in that case.
>    */
>
> -extern "C" {
>   #include "main/core.h"
>   #include "brw_wm.h"
> -}
>   #include "glsl/ir.h"
>   #include "glsl/ir_expression_flattening.h"
>   #include "glsl/glsl_types.h"
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
> index cbe6191..02ea3b6 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
> @@ -27,12 +27,9 @@
>    * native instructions.
>    */
>
> -extern "C" {
>   #include "main/macros.h"
>   #include "brw_context.h"
>   #include "brw_eu.h"
> -} /* extern "C" */
> -
>   #include "brw_fs.h"
>   #include "brw_cfg.h"
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp b/src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp
> index 03e5fdb..01d3a56 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_vector_splitting.cpp
> @@ -37,10 +37,8 @@
>    * behavior we want for the results of texture lookups, but probably not for
>    */
>
> -extern "C" {
>   #include "main/core.h"
>   #include "brw_context.h"
> -}
>   #include "glsl/ir.h"
>   #include "glsl/ir_visitor.h"
>   #include "glsl/ir_rvalue_visitor.h"
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> index 57c4d66..6b48f70 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> @@ -27,8 +27,6 @@
>    * makes it easier to do backend-specific optimizations than doing so
>    * in the GLSL IR or in the native code.
>    */
> -extern "C" {
> -
>   #include <sys/types.h>
>
>   #include "main/macros.h"
> @@ -41,7 +39,6 @@ extern "C" {
>   #include "brw_context.h"
>   #include "brw_eu.h"
>   #include "brw_wm.h"
> -}
>   #include "brw_vec4.h"
>   #include "brw_fs.h"
>   #include "main/uniforms.h"
> diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
> index ec3cfcb..f2b4d82 100644
> --- a/src/mesa/drivers/dri/i965/brw_shader.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
> @@ -21,10 +21,8 @@
>    * IN THE SOFTWARE.
>    */
>
> -extern "C" {
>   #include "main/macros.h"
>   #include "brw_context.h"
> -}
>   #include "brw_vs.h"
>   #include "brw_gs.h"
>   #include "brw_fs.h"
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
> index a286f8a..3186824 100644
> --- a/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_vec4_reg_allocate.cpp
> @@ -21,11 +21,8 @@
>    * IN THE SOFTWARE.
>    */
>
> -extern "C" {
>   #include "main/macros.h"
>   #include "util/register_allocate.h"
> -} /* extern "C" */
> -
>   #include "brw_vec4.h"
>   #include "brw_vs.h"
>   #include "brw_cfg.h"
> diff --git a/src/mesa/drivers/dri/i965/brw_wm.h b/src/mesa/drivers/dri/i965/brw_wm.h
> index f54530f..32d1ce3 100644
> --- a/src/mesa/drivers/dri/i965/brw_wm.h
> +++ b/src/mesa/drivers/dri/i965/brw_wm.h
> @@ -57,6 +57,10 @@
>   #define AA_SOMETIMES 1
>   #define AA_ALWAYS    2
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
>   /**
>    * Compile a fragment shader.
>    *
> @@ -86,4 +90,8 @@ bool brw_wm_prog_data_compare(const void *a, const void *b);
>   void
>   brw_upload_wm_prog(struct brw_context *brw);
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
>   #endif
> diff --git a/src/mesa/main/api_exec.h b/src/mesa/main/api_exec.h
> index ff35b78..3f523fb 100644
> --- a/src/mesa/main/api_exec.h
> +++ b/src/mesa/main/api_exec.h
> @@ -26,6 +26,9 @@
>   #ifndef API_EXEC_H
>   #define API_EXEC_H
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
>
>   struct _glapi_table;
>   struct gl_context;
> @@ -39,4 +42,8 @@ _mesa_initialize_exec_table(struct gl_context *ctx);
>   extern void
>   _mesa_initialize_dispatch_tables(struct gl_context *ctx);
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
>   #endif
> diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
> index c14ad32..d25143f 100644
> --- a/src/mesa/main/tests/dispatch_sanity.cpp
> +++ b/src/mesa/main/tests/dispatch_sanity.cpp
> @@ -41,7 +41,6 @@
>
>   #include <gtest/gtest.h>
>
> -extern "C" {
>   #include "GL/gl.h"
>   #include "GL/glext.h"
>   #include "main/compiler.h"
> @@ -62,7 +61,6 @@ extern "C" {
>   #endif
>
>   #include "main/dispatch.h"
> -}
>
>   struct function {
>      const char *name;
> diff --git a/src/mesa/main/tests/program_state_string.cpp b/src/mesa/main/tests/program_state_string.cpp
> index 418c39c..ddfdb49 100644
> --- a/src/mesa/main/tests/program_state_string.cpp
> +++ b/src/mesa/main/tests/program_state_string.cpp
> @@ -23,11 +23,9 @@
>
>   #include <gtest/gtest.h>
>
> -extern "C" {
>   #include "GL/gl.h"
>   #include "GL/glext.h"
>   #include "main/compiler.h"
> -}
>
>   #include "program/prog_statevars.h"
>
> diff --git a/src/mesa/main/vtxfmt.h b/src/mesa/main/vtxfmt.h
> index efccd90..4f8bc9c 100644
> --- a/src/mesa/main/vtxfmt.h
> +++ b/src/mesa/main/vtxfmt.h
> @@ -35,8 +35,16 @@
>
>   #include "mtypes.h"
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
>   extern void _mesa_install_exec_vtxfmt( struct gl_context *ctx, const GLvertexformat *vfmt );
>   extern void _mesa_install_save_vtxfmt( struct gl_context *ctx, const GLvertexformat *vfmt );
>   extern void _mesa_initialize_vbo_vtxfmt(struct gl_context *ctx);
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
>   #endif /* _VTXFMT_H_ */
> diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h
> index 6e1a4aa..54dee6c 100644
> --- a/src/mesa/vbo/vbo.h
> +++ b/src/mesa/vbo/vbo.h
> @@ -35,6 +35,10 @@
>   #include <stdbool.h>
>   #include "main/glheader.h"
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
>   struct gl_client_array;
>   struct gl_context;
>   struct gl_transform_feedback_object;
> @@ -228,4 +232,8 @@ _es_VertexAttrib3fv(GLuint indx, const GLfloat* values);
>   void GLAPIENTRY
>   _es_VertexAttrib4fv(GLuint indx, const GLfloat* values);
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
>   #endif
> diff --git a/src/mesa/vbo/vbo_context.h b/src/mesa/vbo/vbo_context.h
> index 3b454be..6099b56 100644
> --- a/src/mesa/vbo/vbo_context.h
> +++ b/src/mesa/vbo/vbo_context.h
> @@ -58,6 +58,10 @@
>
>   #include "main/macros.h"
>
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
>   struct vbo_context {
>      struct gl_client_array currval[VBO_ATTRIB_MAX];
>
> @@ -175,4 +179,8 @@ vbo_get_default_vals_as_union(GLenum format)
>      }
>   }
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
>   #endif
> diff --git a/src/util/Makefile.am b/src/util/Makefile.am
> index 29b66e7..ec49dc6 100644
> --- a/src/util/Makefile.am
> +++ b/src/util/Makefile.am
> @@ -25,6 +25,9 @@ include Makefile.sources
>
>   noinst_LTLIBRARIES = libmesautil.la
>
> +AM_CPPFLAGS = \
> +	-I$(top_srcdir)/include
> +
>   libmesautil_la_CPPFLAGS = \
>   	$(DEFINES) \
>   	-I$(top_srcdir)/include \
> diff --git a/src/util/register_allocate.h b/src/util/register_allocate.h
> index dc68744..61f182e 100644
> --- a/src/util/register_allocate.h
> +++ b/src/util/register_allocate.h
> @@ -27,6 +27,12 @@
>
>   #include <stdbool.h>
>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +
>   struct ra_class;
>   struct ra_regs;
>
> @@ -77,3 +83,7 @@ void ra_set_node_spill_cost(struct ra_graph *g, unsigned int n, float cost);
>   int ra_get_best_spill_node(struct ra_graph *g);
>   /** @} */
>
> +
> +#ifdef __cplusplus
> +}  // extern "C"
> +#endif
>



More information about the mesa-dev mailing list