Skip to content

Commit

Permalink
Generate extern C-block to be kind to C++ users.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Dec 19, 2019
1 parent 1237030 commit bcd6608
Show file tree
Hide file tree
Showing 42 changed files with 342 additions and 15 deletions.
8 changes: 8 additions & 0 deletions pbtools/c_source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#ifndef {include_guard}
#define {include_guard}
#ifdef __cplusplus
extern "C" {{
#endif
#include "pbtools.h"
{includes}\
Expand All @@ -46,6 +50,10 @@
/* Internal functions. Do not use! */
{internal_declarations}
#ifdef __cplusplus
}}
#endif
#endif
'''

Expand Down
8 changes: 8 additions & 0 deletions pbtools/c_source/pbtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#ifndef PBTOOLS_H
#define PBTOOLS_H

#ifdef __cplusplus
extern "C" {{
#endif

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
Expand Down Expand Up @@ -689,4 +693,8 @@ void pbtools_decoder_sub_message_decode(

const char *pbtools_error_code_to_string(int code);

#ifdef __cplusplus
}}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/address_book.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef ADDRESS_BOOK_H
#define ADDRESS_BOOK_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -218,4 +222,8 @@ void address_book_address_book_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct address_book_address_book_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef BENCHMARK_H
#define BENCHMARK_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -470,4 +474,8 @@ void benchmark_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct benchmark_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef BOOL_H
#define BOOL_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -95,4 +99,8 @@ void bool_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct bool_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef BYTES_H
#define BYTES_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -95,4 +99,8 @@ void bytes_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct bytes_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/double.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef DOUBLE_H
#define DOUBLE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -95,4 +99,8 @@ void double_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct double_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef ENUM_H
#define ENUM_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -249,4 +253,8 @@ void enum_limits_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct enum_limits_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/enum_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef ENUM_PROVIDER_H
#define ENUM_PROVIDER_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand All @@ -45,4 +49,8 @@ enum pkg_enum_e {
/* Internal functions. Do not use! */


#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/enum_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef ENUM_USER_H
#define ENUM_USER_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"
#include "enum_provider.h"

Expand Down Expand Up @@ -96,4 +100,8 @@ void pkg_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct pkg_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/field_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef FIELD_NAMES_H
#define FIELD_NAMES_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -654,4 +658,8 @@ void field_names_message_one_of_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct field_names_message_one_of_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/fixed32.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef FIXED32_H
#define FIXED32_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -95,4 +99,8 @@ void fixed32_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct fixed32_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/fixed64.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef FIXED64_H
#define FIXED64_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -95,4 +99,8 @@ void fixed64_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct fixed64_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/float.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef FLOAT_H
#define FLOAT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -95,4 +99,8 @@ void float_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct float_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/imported.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef IMPORTED_H
#define IMPORTED_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"
#include "imported_duplicated_package.h"

Expand Down Expand Up @@ -105,4 +109,8 @@ void imported_imported_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct imported_imported_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/imported1.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef IMPORTED1_H
#define IMPORTED1_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -162,4 +166,8 @@ void foo_bar_imported3_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct foo_bar_imported3_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/imported2.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef IMPORTED2_H
#define IMPORTED2_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"
#include "imported3.h"
#include "imported1.h"
Expand Down Expand Up @@ -233,4 +237,8 @@ void imported2_foo_bar_imported3_message_imported2_message_finalize_repeated_inn
struct pbtools_decoder_t *decoder_p,
struct imported2_foo_bar_imported3_message_imported2_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/imported3.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef IMPORTED3_H
#define IMPORTED3_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"
#include "imported1.h"

Expand Down Expand Up @@ -224,4 +228,8 @@ void bar_imported4_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct bar_imported4_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions tests/files/c_source/imported_duplicated_package.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#ifndef IMPORTED_DUPLICATED_PACKAGE_H
#define IMPORTED_DUPLICATED_PACKAGE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "pbtools.h"

/**
Expand Down Expand Up @@ -163,4 +167,8 @@ void imported_imported_duplicated_package_message_finalize_repeated_inner(
struct pbtools_decoder_t *decoder_p,
struct imported_imported_duplicated_package_message_repeated_t *repeated_p);

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit bcd6608

Please sign in to comment.