Skip to content

Commit

Permalink
Fix C++ compilation
Browse files Browse the repository at this point in the history
With ESP-IDF 5.2, some headers do not tolerate being included from an
extern "C" block. To avoid any similar issue, all includes are moved outside
of these blocks, thus fixing compilation of C++ code including our headers.

Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed May 15, 2024
1 parent dddd7d5 commit 4fbd290
Show file tree
Hide file tree
Showing 43 changed files with 204 additions and 134 deletions.
6 changes: 3 additions & 3 deletions src/libAtomVM/atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
#ifndef _ATOM_H_
#define _ATOM_H_

#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdlib.h>

/**
* @details no-op macro: just syntax sugar for avoiding mistakes or clang-format dividing atoms in multiple
* lines. Usage: ATOM_STR("\\x5", "hello").
Expand Down
8 changes: 8 additions & 0 deletions src/libAtomVM/atom_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

#include "atom.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ATOM_TABLE_NOT_FOUND -1
#define ATOM_TABLE_ALLOC_FAIL -2

Expand Down Expand Up @@ -63,4 +67,8 @@ void atom_table_write_bytes(struct AtomTable *table, atom_ref_t atom, size_t buf
void atom_table_write_cstring(
struct AtomTable *table, atom_ref_t atom, size_t buf_len, char *outbuf);

#ifdef __cplusplus
}
#endif

#endif
4 changes: 2 additions & 2 deletions src/libAtomVM/atomshashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#ifndef _ATOMSHASHTABLE_H_
#define _ATOMSHASHTABLE_H_

#include "atom.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "atom.h"

#ifndef AVM_NO_SMP
#ifndef TYPEDEF_RWLOCK
#define TYPEDEF_RWLOCK
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/avmpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
#ifndef _AVMPACK_H_
#define _AVMPACK_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "globalcontext.h"
#include "list.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define END_OF_FILE 0
#define BEAM_START_FLAG 1
#define BEAM_CODE_FLAG 2
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/bif.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
#ifndef _BIF_H_
#define _BIF_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

#include "atom.h"
#include "context.h"
#include "exportedfunction.h"
#include "module.h"

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_BIF_NAME_LEN 260

const struct ExportedFunction *bif_registry_get_handler(AtomString module, AtomString function, int arity);
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/bitstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#ifndef _BITSTRING_H_
#define _BITSTRING_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "term.h"

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __ORDER_LITTLE_ENDIAN__
#define READ_16LE_UNALIGNED(ptr) \
( (((uint8_t *)(ptr))[1] << 8) | ((uint8_t *)(ptr))[0] )
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
#ifndef _CONTEXT_H_
#define _CONTEXT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "globalcontext.h"
#include "list.h"
#include "mailbox.h"
#include "smp.h"
#include "term.h"
#include "timer_list.h"

#ifdef __cplusplus
extern "C" {
#endif

struct Module;

#ifndef TYPEDEF_MODULE
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_

#include "context.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "context.h"

/**
* @brief Print a repreentation of the context to stderr.
*
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/defaultatoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#ifndef _DEFAULTATOMS_H_
#define _DEFAULTATOMS_H_

#include "globalcontext.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "globalcontext.h"

#define FALSE_ATOM_INDEX 0
#define TRUE_ATOM_INDEX 1

Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_

#include "list.h"
#include "term.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "list.h"
#include "term.h"

typedef enum
{
DictionaryOk,
Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/erl_nif_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#ifndef _ERL_NIF_PRIV_H_
#define _ERL_NIF_PRIV_H_

#include "context.h"
#include "memory.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "context.h"
#include "memory.h"

struct ErlNifEnv
{
GlobalContext *global;
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/ets.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
#ifndef _ETS_H_
#define _ETS_H_

#ifdef __cplusplus
extern "C" {
#endif

struct Context;
struct GlobalContext;

#include "list.h"
#include "synclist.h"
#include "term.h"

#ifdef __cplusplus
extern "C" {
#endif

// N.B. Only EtsTableSet currently supported
typedef enum EtsTableType
{
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/ets_hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
#ifndef _ETS_HASHTABLE_H_
#define _ETS_HASHTABLE_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "globalcontext.h"
#include "term.h"
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

#define NUM_BUCKETS 16

struct EtsHashTable
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/externalterm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#ifndef _EXTERNALTERM_H_
#define _EXTERNALTERM_H_

#include "term.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "term.h"

enum ExternalTermResult
{
EXTERNAL_TERM_OK = 0,
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/globalcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
#ifndef _GLOBALCONTEXT_H_
#define _GLOBALCONTEXT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

#include "atom.h"
Expand All @@ -45,6 +41,10 @@ extern "C" {
#include "term.h"
#include "timer_list.h"

#ifdef __cplusplus
extern "C" {
#endif

#define INVALID_PROCESS_ID 0

struct Context;
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/iff.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#ifndef _IFF_H_
#define _IFF_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/** UTF-8 Atoms table section */
#define AT8U 0
/** Code chunk section */
Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#ifndef _INTEROP_H_
#define _INTEROP_H_

#include "context.h"
#include "term.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "context.h"
#include "term.h"

typedef enum
{
InteropOk,
Expand Down
8 changes: 8 additions & 0 deletions src/libAtomVM/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#ifndef _LIST_H_
#define _LIST_H_

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief gets a pointer to the struct that contains a certain list head
*
Expand Down Expand Up @@ -92,4 +96,8 @@ static inline struct ListHead *list_last(struct ListHead *head)
return head->prev;
}

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions src/libAtomVM/listeners.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@

#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Add an event listener to the set of polled events.
*
Expand Down Expand Up @@ -151,3 +155,7 @@ void sys_listener_destroy(struct ListHead *item)
free(listener);
}
#endif /* DOXYGEN_SKIP_SECTION */

#ifdef __cplusplus
}
#endif
8 changes: 4 additions & 4 deletions src/libAtomVM/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#ifndef _MAILBOX_H_
#define _MAILBOX_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

#include "list.h"
Expand All @@ -50,6 +46,10 @@ extern "C" {
#define ATOMIC
#endif

#ifdef __cplusplus
extern "C" {
#endif

struct Context;

#ifndef TYPEDEF_CONTEXT
Expand Down
Loading

0 comments on commit 4fbd290

Please sign in to comment.