diff --git a/.clang-format b/.clang-format index 0d3ce2345..f3269088b 100644 --- a/.clang-format +++ b/.clang-format @@ -20,6 +20,7 @@ ColumnLimit: 120 ContinuationIndentWidth: 2 Cpp11BracedListStyle: false IndentCaseLabels: true +IndentPPDirectives: AfterHash IndentWidth: 2 InsertBraces: true InsertNewlineAtEOF: true diff --git a/ext/herb/extconf.rb b/ext/herb/extconf.rb index ac15be929..3e07accf6 100644 --- a/ext/herb/extconf.rb +++ b/ext/herb/extconf.rb @@ -24,7 +24,6 @@ $INCFLAGS << " -I#{prism_src_path}" $INCFLAGS << " -I#{prism_src_path}/util" -$CFLAGS << " -DPRISM_EXPORT_SYMBOLS=static" $CFLAGS << " -fvisibility=hidden" herb_src_files = Dir.glob("#{$srcdir}/../../src/**/*.c").map { |file| file.delete_prefix("../../../../ext/herb/") }.sort diff --git a/ext/herb/extension.c b/ext/herb/extension.c index dee8fec23..0ff90cf10 100644 --- a/ext/herb/extension.c +++ b/ext/herb/extension.c @@ -124,7 +124,7 @@ static VALUE Herb_version(VALUE self) { return rb_funcall(rb_mKernel, rb_intern("sprintf"), 4, format_string, gem_version, libprism_version, libherb_version); } -__attribute__((visibility("default"))) void Init_herb(void) { +__attribute__((__visibility__("default"))) void Init_herb(void) { mHerb = rb_define_module("Herb"); cPosition = rb_define_class_under(mHerb, "Position", rb_cObject); cLocation = rb_define_class_under(mHerb, "Location", rb_cObject); diff --git a/src/herb.c b/src/herb.c index 4c6238a52..2500f606c 100644 --- a/src/herb.c +++ b/src/herb.c @@ -10,7 +10,7 @@ #include #include -hb_array_T* herb_lex(const char* source) { +HERB_EXPORTED_FUNCTION hb_array_T* herb_lex(const char* source) { lexer_T lexer = { 0 }; lexer_init(&lexer, source); @@ -26,7 +26,7 @@ hb_array_T* herb_lex(const char* source) { return tokens; } -AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options) { +HERB_EXPORTED_FUNCTION AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options) { if (!source) { source = ""; } lexer_T lexer = { 0 }; @@ -46,7 +46,7 @@ AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options) { return document; } -hb_array_T* herb_lex_file(const char* path) { +HERB_EXPORTED_FUNCTION hb_array_T* herb_lex_file(const char* path) { char* source = herb_read_file(path); hb_array_T* tokens = herb_lex(source); @@ -55,7 +55,7 @@ hb_array_T* herb_lex_file(const char* path) { return tokens; } -void herb_lex_to_buffer(const char* source, hb_buffer_T* output) { +HERB_EXPORTED_FUNCTION void herb_lex_to_buffer(const char* source, hb_buffer_T* output) { hb_array_T* tokens = herb_lex(source); for (size_t i = 0; i < hb_array_size(tokens); i++) { @@ -71,7 +71,7 @@ void herb_lex_to_buffer(const char* source, hb_buffer_T* output) { herb_free_tokens(&tokens); } -void herb_free_tokens(hb_array_T** tokens) { +HERB_EXPORTED_FUNCTION void herb_free_tokens(hb_array_T** tokens) { if (!tokens || !*tokens) { return; } for (size_t i = 0; i < hb_array_size(*tokens); i++) { @@ -82,10 +82,10 @@ void herb_free_tokens(hb_array_T** tokens) { hb_array_free(tokens); } -const char* herb_version(void) { +HERB_EXPORTED_FUNCTION const char* herb_version(void) { return HERB_VERSION; } -const char* herb_prism_version(void) { +HERB_EXPORTED_FUNCTION const char* herb_prism_version(void) { return PRISM_VERSION; } diff --git a/src/include/herb.h b/src/include/herb.h index 207053e45..26a2dfa2c 100644 --- a/src/include/herb.h +++ b/src/include/herb.h @@ -3,6 +3,7 @@ #include "ast_node.h" #include "extract.h" +#include "macros.h" #include "parser.h" #include "util/hb_array.h" #include "util/hb_buffer.h" @@ -13,17 +14,17 @@ extern "C" { #endif -void herb_lex_to_buffer(const char* source, hb_buffer_T* output); +HERB_EXPORTED_FUNCTION void herb_lex_to_buffer(const char* source, hb_buffer_T* output); -hb_array_T* herb_lex(const char* source); -hb_array_T* herb_lex_file(const char* path); +HERB_EXPORTED_FUNCTION hb_array_T* herb_lex(const char* source); +HERB_EXPORTED_FUNCTION hb_array_T* herb_lex_file(const char* path); -AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options); +HERB_EXPORTED_FUNCTION AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options); -const char* herb_version(void); -const char* herb_prism_version(void); +HERB_EXPORTED_FUNCTION const char* herb_version(void); +HERB_EXPORTED_FUNCTION const char* herb_prism_version(void); -void herb_free_tokens(hb_array_T** tokens); +HERB_EXPORTED_FUNCTION void herb_free_tokens(hb_array_T** tokens); #ifdef __cplusplus } diff --git a/src/include/macros.h b/src/include/macros.h index 05fb61138..66c699535 100644 --- a/src/include/macros.h +++ b/src/include/macros.h @@ -1,6 +1,14 @@ #ifndef HERB_MACROS_H #define HERB_MACROS_H +#ifndef HERB_EXPORTED_FUNCTION +# ifdef HERB_EXPORT_SYMBOLS +# define HERB_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern +# else +# define HERB_EXPORTED_FUNCTION +# endif +#endif + #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) diff --git a/src/util/hb_system.c b/src/util/hb_system.c index e7b2c128b..efe31a9b5 100644 --- a/src/util/hb_system.c +++ b/src/util/hb_system.c @@ -1,13 +1,13 @@ #include "../include/util/hb_system.h" #ifdef __linux__ -#define _GNU_SOURCE +# define _GNU_SOURCE #endif #ifdef HB_USE_MALLOC -#include +# include #else -#include +# include #endif void* hb_system_allocate_memory(size_t size) {