*: don't include standard C headers inside of extern "C"

Including C headers inside of `extern "C"` breaks use from C++. Hoist
the includes of standard C headers above the block so we don't try
to mangle the stdlib.

I initially tried to scope this with a targeted change but it's too
hard to do correctly that way. This way, we avoid whack-a-mole.

Firefox is working around this in their e21461b7b8b39cc31ba53c47d4f6f310c673ff2f
commit.

Bug: https://bugzilla.mozilla.org/1953080
This commit is contained in:
Sam James 2025-05-27 09:06:08 +01:00
parent e2731914ad
commit b943c31fd8
No known key found for this signature in database
GPG key ID: 738409F520DF9190
207 changed files with 753 additions and 752 deletions

View file

@ -5,6 +5,13 @@
#ifndef SPA_UTILS_DEFS_H
#define SPA_UTILS_DEFS_H
#include <inttypes.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
# if __cplusplus >= 201103L
@ -34,13 +41,6 @@ extern "C" {
#define SPA_CONCAT_NOEXPAND(a, b) a ## b
#define SPA_CONCAT(a, b) SPA_CONCAT_NOEXPAND(a, b)
#include <inttypes.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
/**
* \defgroup spa_utils_defs Miscellaneous
* Helper macros and functions

View file

@ -5,14 +5,14 @@
#ifndef SPA_DICT_H
#define SPA_DICT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include <spa/utils/defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_DICT
#ifdef SPA_API_IMPL
#define SPA_API_DICT SPA_API_IMPL

View file

@ -5,15 +5,15 @@
#ifndef SPA_DLL_H
#define SPA_DLL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <math.h>
#include <spa/utils/defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_DLL
#ifdef SPA_API_IMPL
#define SPA_API_DLL SPA_API_IMPL

View file

@ -5,13 +5,13 @@
#ifndef SPA_ENUM_TYPES_H
#define SPA_ENUM_TYPES_H
#include <spa/utils/type.h>
#include <spa/pod/pod.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/type.h>
#include <spa/pod/pod.h>
/**
* \addtogroup spa_types
* \{

View file

@ -5,13 +5,13 @@
#ifndef SPA_HOOK_H
#define SPA_HOOK_H
#include <spa/utils/defs.h>
#include <spa/utils/list.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/utils/list.h>
#ifndef SPA_API_HOOK
#ifdef SPA_API_IMPL
#define SPA_API_HOOK SPA_API_IMPL

View file

@ -5,11 +5,6 @@
#ifndef SPA_UTILS_JSON_H
#define SPA_UTILS_JSON_H
#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
@ -20,6 +15,12 @@ extern "C" {
#include <spa/utils/defs.h>
#include <spa/utils/string.h>
#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif
#ifndef SPA_API_JSON
#ifdef SPA_API_IMPL
#define SPA_API_JSON SPA_API_IMPL

View file

@ -5,16 +5,16 @@
#ifndef SPA_UTILS_JSON_POD_H
#define SPA_UTILS_JSON_POD_H
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/string.h>
#include <spa/utils/json.h>
#include <spa/pod/pod.h>
#include <spa/pod/builder.h>
#include <spa/debug/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_JSON_POD
#ifdef SPA_API_IMPL
#define SPA_API_JSON_POD SPA_API_IMPL

View file

@ -5,11 +5,6 @@
#ifndef SPA_UTILS_JSON_UTILS_H
#define SPA_UTILS_JSON_UTILS_H
#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
@ -19,6 +14,12 @@ extern "C" {
#include <spa/utils/json-core.h>
#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif
#ifndef SPA_API_JSON_UTILS
#ifdef SPA_API_IMPL
#define SPA_API_JSON_UTILS SPA_API_IMPL

View file

@ -5,12 +5,12 @@
#ifndef SPA_LIST_H
#define SPA_LIST_H
#include <spa/utils/defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#ifndef SPA_API_LIST
#ifdef SPA_API_IMPL
#define SPA_API_LIST SPA_API_IMPL

View file

@ -5,15 +5,15 @@
#ifndef SPA_RATELIMIT_H
#define SPA_RATELIMIT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <stddef.h>
#include <spa/utils/defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_RATELIMIT
#ifdef SPA_API_IMPL
#define SPA_API_RATELIMIT SPA_API_IMPL

View file

@ -5,6 +5,10 @@
#ifndef SPA_UTILS_RESULT_H
#define SPA_UTILS_RESULT_H
#include <errno.h>
#include <spa/utils/defs.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -19,10 +23,6 @@ extern "C" {
* \{
*/
#include <errno.h>
#include <spa/utils/defs.h>
#ifndef SPA_API_RESULT
#ifdef SPA_API_IMPL
#define SPA_API_RESULT SPA_API_IMPL

View file

@ -5,6 +5,8 @@
#ifndef SPA_RINGBUFFER_H
#define SPA_RINGBUFFER_H
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -21,8 +23,6 @@ extern "C" {
struct spa_ringbuffer;
#include <string.h>
#include <spa/utils/defs.h>
#ifndef SPA_API_RINGBUFFER

View file

@ -5,10 +5,6 @@
#ifndef SPA_UTILS_STRING_H
#define SPA_UTILS_STRING_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <stdbool.h>
#include <errno.h>
@ -17,6 +13,10 @@ extern "C" {
#include <spa/utils/defs.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SPA_API_STRING
#ifdef SPA_API_IMPL
#define SPA_API_STRING SPA_API_IMPL

View file

@ -5,12 +5,19 @@
#ifndef SPA_TYPE_INFO_H
#define SPA_TYPE_INFO_H
#include <spa/utils/defs.h>
#include <spa/utils/type.h>
#include <spa/utils/enum-types.h>
#include <spa/monitor/type-info.h>
#include <spa/node/type-info.h>
#include <spa/param/type-info.h>
#include <spa/control/type-info.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
/**
* \addtogroup spa_types
* \{
@ -20,15 +27,6 @@ extern "C" {
#define SPA_TYPE_ROOT spa_types
#endif
#include <spa/utils/type.h>
#include <spa/utils/enum-types.h>
#include <spa/monitor/type-info.h>
#include <spa/node/type-info.h>
#include <spa/param/type-info.h>
#include <spa/control/type-info.h>
static const struct spa_type_info spa_types[] = {
/* Basic types */
{ SPA_TYPE_START, SPA_TYPE_START, SPA_TYPE_INFO_BASE, NULL },

View file

@ -5,13 +5,13 @@
#ifndef SPA_TYPE_H
#define SPA_TYPE_H
#include <spa/utils/defs.h>
#include <spa/utils/string.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/utils/string.h>
#ifndef SPA_API_TYPE
#ifdef SPA_API_IMPL
#define SPA_API_TYPE SPA_API_IMPL