Skip to content

Commit

Permalink
Avoid C++ name mangling in C code
Browse files Browse the repository at this point in the history
Now that a C++ compiler is used to support later versions of ICU, we
need to surround all C code with `extern "C"` to avoid name mangling
that would cause issues with symbol resolution on macOS.
  • Loading branch information
stanhu committed Jul 9, 2024
1 parent 7f026b4 commit 405d3c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ext/charlock_holmes/converter.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "unicode/ucnv.h"
#include "common.h"

extern "C" {

extern VALUE rb_mCharlockHolmes;
static VALUE rb_cConverter;

Expand Down Expand Up @@ -55,3 +57,5 @@ void _init_charlock_converter() {

rb_define_singleton_method(rb_cConverter, "convert", rb_converter_convert, 3);
}

}
4 changes: 4 additions & 0 deletions ext/charlock_holmes/encoding_detector.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "unicode/ucsdet.h"
#include "common.h"

extern "C" {

extern VALUE rb_mCharlockHolmes;
static VALUE rb_cEncodingDetector;

Expand Down Expand Up @@ -375,3 +377,5 @@ void _init_charlock_encoding_detector()

rb_define_singleton_method(rb_cEncodingDetector, "supported_encodings", rb_get_supported_encodings, 0);
}

}
8 changes: 6 additions & 2 deletions ext/charlock_holmes/ext.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#include "common.h"

extern "C" {

extern void _init_charlock_encoding_detector();
extern void _init_charlock_converter();
extern void _init_charlock_transliterator();

VALUE rb_mCharlockHolmes;

void Init_charlock_holmes() {
__attribute__((visibility ("default"))) void Init_charlock_holmes() {
rb_mCharlockHolmes = rb_define_module("CharlockHolmes");

_init_charlock_encoding_detector();
_init_charlock_converter();
_init_charlock_transliterator();
}
}

}

0 comments on commit 405d3c6

Please sign in to comment.