Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ColumnLimit: 120
ContinuationIndentWidth: 2
Cpp11BracedListStyle: false
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 2
InsertBraces: true
InsertNewlineAtEOF: true
Expand Down
1 change: 0 additions & 1 deletion ext/herb/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/herb/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions src/herb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <prism.h>
#include <stdlib.h>

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);

Expand All @@ -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 };
Expand All @@ -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);

Expand All @@ -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++) {
Expand All @@ -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++) {
Expand All @@ -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;
}
15 changes: 8 additions & 7 deletions src/include/herb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions src/include/macros.h
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
6 changes: 3 additions & 3 deletions src/util/hb_system.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "../include/util/hb_system.h"

#ifdef __linux__
#define _GNU_SOURCE
# define _GNU_SOURCE
#endif

#ifdef HB_USE_MALLOC
#include <stdlib.h>
# include <stdlib.h>
#else
#include <sys/mman.h>
# include <sys/mman.h>
#endif

void* hb_system_allocate_memory(size_t size) {
Expand Down
Loading