Skip to content

Commit

Permalink
Merge pull request #7 from sgielen/cguard
Browse files Browse the repository at this point in the history
Ensure all prototypes in headers use C linkage.
  • Loading branch information
EdSchouten committed Apr 4, 2018
2 parents a3ae008 + 03343e1 commit f815fb2
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 2 deletions.
2 changes: 1 addition & 1 deletion generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def open_and_format(filename):
'#endif\n'
'\n'
'// Make this code build with g++.\n'
'#ifdef __cplusplus && defined(__GNUC__) && !defined(__clang__)\n'
'#if defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__)\n'
'#define _Alignas alignas\n'
'#define _Alignof alignof\n'
'#define _Atomic(x) x\n'
Expand Down
8 changes: 8 additions & 0 deletions generator/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ def generate_head(self, abi):
print()
if self.preamble != '':
print(self.preamble)
print('#ifdef __cplusplus')
print('extern "C" {')
print('#endif')
print()

def generate_foot(self, abi):
print('#ifdef __cplusplus')
print('} // extern "C"')
print('#endif')
print()
if self.postamble != '':
print(self.postamble)
if self.header_guard is not None:
Expand Down
8 changes: 8 additions & 0 deletions headers/cloudabi32_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "cloudabi_types_common.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
_Alignas(4) cloudabi_auxtype_t a_type;
union {
Expand Down Expand Up @@ -186,4 +190,8 @@ _Static_assert(offsetof(cloudabi32_threadattr_t, argument) == 12, "Incorrect lay
_Static_assert(sizeof(cloudabi32_threadattr_t) == 16, "Incorrect layout");
_Static_assert(_Alignof(cloudabi32_threadattr_t) == 4, "Incorrect layout");

#ifdef __cplusplus
} // extern "C"
#endif

#endif
8 changes: 8 additions & 0 deletions headers/cloudabi64_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "cloudabi_types_common.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
_Alignas(4) cloudabi_auxtype_t a_type;
union {
Expand Down Expand Up @@ -186,4 +190,8 @@ _Static_assert(offsetof(cloudabi64_threadattr_t, argument) == 24, "Incorrect lay
_Static_assert(sizeof(cloudabi64_threadattr_t) == 32, "Incorrect layout");
_Static_assert(_Alignof(cloudabi64_threadattr_t) == 8, "Incorrect layout");

#ifdef __cplusplus
} // extern "C"
#endif

#endif
8 changes: 8 additions & 0 deletions headers/cloudabi_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "cloudabi_types.h"

#ifdef __cplusplus
extern "C" {
#endif

cloudabi_errno_t cloudabi_sys_clock_res_get(cloudabi_clockid_t clock_id,
cloudabi_timestamp_t *resolution);

Expand Down Expand Up @@ -207,4 +211,8 @@ _Noreturn void cloudabi_sys_thread_exit(_Atomic(cloudabi_lock_t) * lock,

cloudabi_errno_t cloudabi_sys_thread_yield(void);

#ifdef __cplusplus
} // extern "C"
#endif

#endif
8 changes: 8 additions & 0 deletions headers/cloudabi_syscalls_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#ifndef CLOUDABI_SYSCALLS_INFO_H
#define CLOUDABI_SYSCALLS_INFO_H

#ifdef __cplusplus
extern "C" {
#endif

#define CLOUDABI_SYSCALL_NAMES(SYSCALL) \
SYSCALL(clock_res_get) \
SYSCALL(clock_time_get) \
Expand Down Expand Up @@ -580,4 +584,8 @@
#define CLOUDABI_SYSCALL_RETURNS_thread_exit(yes, no) no
#define CLOUDABI_SYSCALL_RETURNS_thread_yield(yes, no) yes

#ifdef __cplusplus
} // extern "C"
#endif

#endif
8 changes: 8 additions & 0 deletions headers/cloudabi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "cloudabi_types_common.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
_Alignas(4) cloudabi_auxtype_t a_type;
union {
Expand Down Expand Up @@ -226,4 +230,8 @@ _Static_assert(sizeof(void *) != 8 || sizeof(cloudabi_threadattr_t) == 32, "Inco
_Static_assert(sizeof(void *) != 4 || _Alignof(cloudabi_threadattr_t) == 4, "Incorrect layout");
_Static_assert(sizeof(void *) != 8 || _Alignof(cloudabi_threadattr_t) == 8, "Incorrect layout");

#ifdef __cplusplus
} // extern "C"
#endif

#endif
10 changes: 9 additions & 1 deletion headers/cloudabi_types_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@
#endif

// Make this code build with g++.
#ifdef __cplusplus && defined(__GNUC__) && !defined(__clang__)
#if defined(__cplusplus) && defined(__GNUC__) && !defined(__clang__)
#define _Alignas alignas
#define _Alignof alignof
#define _Atomic(x) x
#define _Static_assert static_assert
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef uint8_t cloudabi_advice_t;
#define CLOUDABI_ADVICE_DONTNEED 1
#define CLOUDABI_ADVICE_NOREUSE 2
Expand Down Expand Up @@ -434,4 +438,8 @@ _Static_assert(offsetof(cloudabi_lookup_t, flags) == 4, "Incorrect layout");
_Static_assert(sizeof(cloudabi_lookup_t) == 8, "Incorrect layout");
_Static_assert(_Alignof(cloudabi_lookup_t) == 4, "Incorrect layout");

#ifdef __cplusplus
} // extern "C"
#endif

#endif
8 changes: 8 additions & 0 deletions linux/cloudabi64_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "cloudabi64_types.h"

#ifdef __cplusplus
extern "C" {
#endif

cloudabi_errno_t cloudabi64_sys_fd_pread(cloudabi_fd_t fd,
const cloudabi64_iovec_t __user *iovs,
size_t iovs_len,
Expand Down Expand Up @@ -63,4 +67,8 @@ cloudabi_errno_t cloudabi64_sys_sock_send(cloudabi_fd_t sock,
cloudabi_errno_t cloudabi64_sys_thread_create(
cloudabi64_threadattr_t __user *attr, cloudabi_tid_t *tid);

#ifdef __cplusplus
} // extern "C"
#endif

#endif
7 changes: 7 additions & 0 deletions linux/cloudabi64_syscalls_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include "cloudabi64_syscalls.h"
#include "cloudabi_syscalls.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __LITTLE_ENDIAN
#define MEMBER(type, name) _Alignas(8) type name
#else
Expand Down Expand Up @@ -536,3 +540,6 @@ static cloudabi_errno_t (*syscalls[])(const void *, void *) = {
do_sock_send, do_sock_shutdown, do_thread_create, do_thread_exit,
do_thread_yield,
};
#ifdef __cplusplus
} // extern "C"
#endif
8 changes: 8 additions & 0 deletions linux/cloudabi_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

#include "cloudabi_types_common.h"

#ifdef __cplusplus
extern "C" {
#endif

cloudabi_errno_t cloudabi_sys_clock_res_get(cloudabi_clockid_t clock_id,
cloudabi_timestamp_t *resolution);

Expand Down Expand Up @@ -184,4 +188,8 @@ void cloudabi_sys_thread_exit(cloudabi_lock_t __user *lock,

cloudabi_errno_t cloudabi_sys_thread_yield(void);

#ifdef __cplusplus
} // extern "C"
#endif

#endif

0 comments on commit f815fb2

Please sign in to comment.