Skip to content

Commit

Permalink
Merge pull request ocaml#13591 from MisterDA/headers-cpp-extern-c-compat
Browse files Browse the repository at this point in the history
Audit the installed headers for C++ compatibility

(cherry picked from commit b0b5f92)
  • Loading branch information
NickBarnes committed Nov 26, 2024
1 parent 66b424d commit ec71759
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 81 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ ___________
were being included in the thread descriptors.
(David Allsopp, review by Sébastien Hinderer and Miod Vallat)

- #13541, #13591: Fix headers for C++ inclusion.
(Antonin Décimo, review by Nick Barnes, report by Kate Deplaix)

- #13579, #13583: Unsoundness involving non-injective types + gadts
(Jacques Garrigue, report by @v-gb,
review by Richard Eisenberg and Florian Angeletti)
Expand Down
8 changes: 8 additions & 0 deletions otherlibs/runtime_events/caml/runtime_events_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

#include "caml/runtime_events.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Create a cursor to read events from an runtime_events. Cursors can be created
for runtime_events in and out of process. An runtime_events may have
multiple cursors reading from it at any point in time and a program may have
Expand Down Expand Up @@ -95,4 +99,8 @@ CAMLextern runtime_events_error caml_runtime_events_read_poll(
void *callback_data,
uintnat max_events, uintnat *events_consumed);

#ifdef __cplusplus
}
#endif

#endif /* CAML_RUNTIME_EVENTS_CONSUMER_H */
8 changes: 8 additions & 0 deletions runtime/caml/address_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include "misc.h"
#include "mlvalues.h"

#ifdef __cplusplus
extern "C" {
#endif

CAMLextern uintnat caml_minor_heaps_start;
CAMLextern uintnat caml_minor_heaps_end;

Expand All @@ -59,4 +63,8 @@ CAMLextern uintnat caml_minor_heaps_end;
#define Is_in_heap_or_young(a) 1
#define Is_in_value_area(a) 1

#ifdef __cplusplus
}
#endif

#endif /* CAML_ADDRESS_CLASS_H */
12 changes: 10 additions & 2 deletions runtime/caml/addrmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/
#include "mlvalues.h"

#ifndef CAML_ADDRMAP_H
#define CAML_ADDRMAP_H

#include "mlvalues.h"

#ifdef __cplusplus
extern "C" {
#endif

/* An addrmap is a value -> value hashmap, where
the values are blocks */

Expand Down Expand Up @@ -94,5 +99,8 @@ Caml_inline addrmap_iterator caml_addrmap_iterator(struct addrmap* t)
return caml_addrmap_next(t, (uintnat)(-1));
}


#ifdef __cplusplus
}
#endif

#endif /* CAML_ADDRMAP_H */
1 change: 0 additions & 1 deletion runtime/caml/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#ifndef CAML_ALLOC_H
#define CAML_ALLOC_H


#include "misc.h"
#include "mlvalues.h"

Expand Down
8 changes: 8 additions & 0 deletions runtime/caml/backtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

#include "mlvalues.h"

#ifdef __cplusplus
extern "C" {
#endif

/* [caml_record_backtraces] controls backtrace recording.
* This function can be called at runtime by user-code, or during
* initialization if backtraces were requested.
Expand All @@ -27,6 +31,10 @@
*/
CAMLextern void caml_record_backtraces(int);

#ifdef __cplusplus
}
#endif

#ifdef CAML_INTERNALS

#include "exec.h"
Expand Down
2 changes: 1 addition & 1 deletion runtime/caml/bigarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ CAMLextern intnat caml_ba_hash(value v);
CAMLextern void caml_ba_serialize(value, uintnat *, uintnat *);
CAMLextern uintnat caml_ba_deserialize(void * dst);

#endif
#endif /* CAML_INTERNALS */

#endif /* CAML_BIGARRAY_H */
1 change: 1 addition & 0 deletions runtime/caml/camlatomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/

#ifndef CAML_ATOMIC_H
#define CAML_ATOMIC_H

Expand Down
4 changes: 2 additions & 2 deletions runtime/caml/codefrag.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ extern unsigned char * caml_digest_of_code_fragment(struct code_fragment *);
/* Cleans up (and frees) removed code fragments. */
extern void caml_code_fragment_cleanup_from_stw_single(void);

#endif
#endif /* CAML_INTERNALS */

#endif
#endif /* CAML_CODEFRAG_H */
9 changes: 4 additions & 5 deletions runtime/caml/custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ struct custom_operations {
extern "C" {
#endif


CAMLextern uintnat caml_custom_major_ratio;

CAMLextern value caml_alloc_custom(const struct custom_operations * ops,
Expand All @@ -76,6 +75,10 @@ CAMLextern mlsize_t caml_custom_get_max_major (void);
/* Global variable moved to Caml_state in 4.10 */
#define caml_compare_unordered (Caml_state_field(compare_unordered))

#ifdef __cplusplus
}
#endif

#ifdef CAML_INTERNALS
extern struct custom_operations *
caml_find_custom_operations(const char * ident);
Expand All @@ -90,8 +93,4 @@ extern const struct custom_operations caml_int64_ops;
extern const struct custom_operations caml_ba_ops;
#endif /* CAML_INTERNALS */

#ifdef __cplusplus
}
#endif

#endif /* CAML_CUSTOM_H */
8 changes: 0 additions & 8 deletions runtime/caml/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#ifndef CAML_DOMAIN_H
#define CAML_DOMAIN_H

#ifdef __cplusplus
extern "C" {
#endif

#ifdef CAML_INTERNALS

#include "camlatomic.h"
Expand Down Expand Up @@ -236,8 +232,4 @@ void caml_global_barrier_release_as_final(barrier_status status);

#endif /* CAML_INTERNALS */

#ifdef __cplusplus
}
#endif

#endif /* CAML_DOMAIN_H */
8 changes: 8 additions & 0 deletions runtime/caml/domain_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#include "misc.h"

#ifdef __cplusplus
extern "C" {
#endif

#define NUM_EXTRA_PARAMS 64
typedef value extra_params_area[NUM_EXTRA_PARAMS];

Expand Down Expand Up @@ -67,4 +71,8 @@ CAMLnoret CAMLextern void caml_bad_caml_state(void);

#define Caml_state_field(field) (Caml_state->field)

#ifdef __cplusplus
}
#endif

#endif /* CAML_STATE_H */
4 changes: 2 additions & 2 deletions runtime/caml/fail.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Caml_inline value caml_get_value_or_raise (struct caml_result_private result)
}

#ifdef CAML_INTERNALS
// internals only, provided for backward-compatibility
/* internals only, provided for backward-compatibility */
Caml_inline value caml_result_get_encoded_exception(
struct caml_result_private result)
{
Expand All @@ -149,7 +149,7 @@ Caml_inline value caml_result_get_encoded_exception(
else
return result.data;
}
#endif // CAML_INTERNALS
#endif /* CAML_INTERNALS */

#ifdef __cplusplus
}
Expand Down
8 changes: 0 additions & 8 deletions runtime/caml/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
#include "misc.h"
#include "memory.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef CAML_INTERNALS

#ifdef NATIVE_CODE
Expand All @@ -36,8 +32,4 @@ CAMLextern void (*caml_natdynlink_hook)(void* handle, const char* unit);

#endif /* CAML_INTERNALS */

#ifdef __cplusplus
}
#endif

#endif /* CAML_HOOKS_H */
6 changes: 3 additions & 3 deletions runtime/caml/instrtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

/* Trace the instructions executed */

#ifndef _instrtrace_
#define _instrtrace_
#ifndef CAML_INSTRTRACE_H
#define CAML_INSTRTRACE_H

#ifdef CAML_INTERNALS

Expand All @@ -33,4 +33,4 @@ void caml_event_trace (code_t pc);

#endif /* CAML_INTERNALS */

#endif
#endif /* CAML_INSTRTRACE_H */
8 changes: 3 additions & 5 deletions runtime/caml/intext.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ void caml_free_extern_state (void);
void caml_output_val (struct channel * chan, value v, value flags);
/* Output [v] with flags [flags] on the channel [chan]. */

value caml_input_val (struct channel * chan);
/* Read a structured value from the channel [chan]. */

void caml_free_intern_state (void);

/* Compression hooks */
Expand Down Expand Up @@ -160,11 +163,6 @@ CAMLextern intnat caml_output_value_to_block(value v, value flags,
in bytes. Return the number of bytes actually written in buffer.
Raise [Failure] if buffer is too short. */

#ifdef CAML_INTERNALS
value caml_input_val (struct channel * chan);
/* Read a structured value from the channel [chan]. */
#endif /* CAML_INTERNALS */

CAMLextern value caml_input_val_from_string (value str, intnat ofs);
/* Read a structured value from the OCaml string [str], starting
at offset [ofs]. */
Expand Down
2 changes: 1 addition & 1 deletion runtime/caml/memprof.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ CAMLextern void caml_memprof_enter_thread(memprof_thread_t);

CAMLextern void caml_memprof_delete_thread(memprof_thread_t);

#endif
#endif /* CAML_INTERNALS */

#endif /* CAML_MEMPROF_H */
8 changes: 8 additions & 0 deletions runtime/caml/minor_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
asize_t reserve; \
}

#ifdef __cplusplus
extern "C" {
#endif

/* Count of the total number of minor collections performed by the program */
CAMLextern atomic_uintnat caml_minor_collections_count;

Expand Down Expand Up @@ -69,6 +73,10 @@ struct caml_minor_tables {

CAMLextern void caml_minor_collection (void);

#ifdef __cplusplus
}
#endif

#ifdef CAML_INTERNALS
extern void caml_set_minor_heap_size (asize_t); /* size in bytes */
extern void caml_empty_minor_heap_no_major_slice_from_stw
Expand Down
24 changes: 15 additions & 9 deletions runtime/caml/osdeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
#ifndef CAML_OSDEPS_H
#define CAML_OSDEPS_H

#ifdef _WIN32
#include <time.h>

extern unsigned short caml_win32_major;
extern unsigned short caml_win32_minor;
extern unsigned short caml_win32_build;
extern unsigned short caml_win32_revision;
#endif

#ifdef CAML_INTERNALS

#include "misc.h"
Expand Down Expand Up @@ -106,6 +97,8 @@ void caml_plat_mem_unmap(void *, uintnat);

#ifdef _WIN32

#include <time.h>

/* Map a Win32 error code (as returned by GetLastError) to a POSIX error code
(from <errno.h>). Return 0 if no POSIX error code matches. */
CAMLextern int caml_posixerr_of_win32err(unsigned int win32err);
Expand Down Expand Up @@ -159,6 +152,15 @@ extern void caml_init_os_params(void);

#ifdef _WIN32

#ifdef __cplusplus
extern "C" {
#endif

extern unsigned short caml_win32_major;
extern unsigned short caml_win32_minor;
extern unsigned short caml_win32_build;
extern unsigned short caml_win32_revision;

/* [caml_stat_strdup_to_utf16(s)] returns a null-terminated copy of [s],
re-encoded in UTF-16. The encoding of [s] is assumed to be UTF-8 if
[caml_windows_unicode_runtime_enabled] is non-zero **and** [s] is valid
Expand Down Expand Up @@ -197,6 +199,10 @@ CAMLextern char* caml_stat_strdup_of_utf16(const wchar_t *s);
*/
CAMLextern value caml_copy_string_of_utf16(const wchar_t *s);

#ifdef __cplusplus
}
#endif

#endif /* _WIN32 */

#endif /* CAML_OSDEPS_H */
3 changes: 2 additions & 1 deletion runtime/caml/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
/* */
/**************************************************************************/

/* Platform-specific concurrency and memory primitives */

#ifndef CAML_PLAT_THREADS_H
#define CAML_PLAT_THREADS_H
/* Platform-specific concurrency and memory primitives */

#ifdef CAML_INTERNALS

Expand Down
9 changes: 4 additions & 5 deletions runtime/caml/printexc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@
#ifndef CAML_PRINTEXC_H
#define CAML_PRINTEXC_H


#include "misc.h"
#include "mlvalues.h"

#ifdef __cplusplus
extern "C" {
#endif


CAMLextern char * caml_format_exception (value);
#ifdef CAML_INTERNALS
CAMLnoret void caml_fatal_uncaught_exception (value);
#endif /* CAML_INTERNALS */

#ifdef __cplusplus
}
#endif

#ifdef CAML_INTERNALS
CAMLnoret void caml_fatal_uncaught_exception (value);
#endif /* CAML_INTERNALS */

#endif /* CAML_PRINTEXC_H */
Loading

0 comments on commit ec71759

Please sign in to comment.