From cbe805d82a7355ee4b7506dc8510abe56c7eb4b5 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Thu, 17 Aug 2023 15:00:58 +0300 Subject: [PATCH 1/4] Allow override Makefile CFLAGS by appending and not by overwriting --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 59554e1d..57f19da3 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,8 @@ endif OBJ := $(SRC:.c=.o) # define default flags, and override to append mandatory flags -CFLAGS ?= -O3 -Wall -Wextra -Werror -Wshadow -override CFLAGS += -std=gnu99 -fPIC -Ilib/src -Ilib/include +override CFLAGS := -O3 -std=gnu99 -fPIC -Wall -Wextra -Werror -Wshadow $(CFLAGS) +override CFLAGS += -Ilib/src -Ilib/include # ABI versioning SONAME_MAJOR := 0 From 5e3df64a460116b1a4480c29cf4a141d41b3ccf4 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Thu, 17 Aug 2023 15:01:47 +0300 Subject: [PATCH 2/4] fix(lib): expose only symbols defined in api.h --- Makefile | 2 +- lib/include/tree_sitter/api.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 57f19da3..f2afed00 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ endif OBJ := $(SRC:.c=.o) # define default flags, and override to append mandatory flags -override CFLAGS := -O3 -std=gnu99 -fPIC -Wall -Wextra -Werror -Wshadow $(CFLAGS) +override CFLAGS := -O3 -std=gnu99 -fPIC -fvisibility=hidden -Wall -Wextra -Werror -Wshadow $(CFLAGS) override CFLAGS += -Ilib/src -Ilib/include # ABI versioning diff --git a/lib/include/tree_sitter/api.h b/lib/include/tree_sitter/api.h index 9e936ff8..1cc6b3e9 100644 --- a/lib/include/tree_sitter/api.h +++ b/lib/include/tree_sitter/api.h @@ -1,6 +1,8 @@ #ifndef TREE_SITTER_API_H_ #define TREE_SITTER_API_H_ +#pragma GCC visibility push(default) + #ifdef __cplusplus extern "C" { #endif @@ -1163,4 +1165,6 @@ void ts_set_allocator( } #endif +#pragma GCC visibility pop + #endif // TREE_SITTER_API_H_ From 113d100250b08c47d421884a3a355aca7b6ef5f2 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Thu, 17 Aug 2023 15:39:14 +0300 Subject: [PATCH 3/4] Add an optional strip step to the Makefile It can be used like: > make clean && make -j CC=clang AR=llvm-ar STRIP=llvm-strip --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index f2afed00..5339d1e6 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,9 @@ libtree-sitter.$(SOEXTVER): $(OBJ) $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ ln -sf $@ libtree-sitter.$(SOEXT) ln -sf $@ libtree-sitter.$(SOEXTVER_MAJOR) +ifneq ($(STRIP),) + $(STRIP) $@ +endif install: all install -d '$(DESTDIR)$(LIBDIR)' From f9e8802234cbd692b1979cff3bea90f5103d4187 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Thu, 17 Aug 2023 16:27:52 +0300 Subject: [PATCH 4/4] Use the same flags in lib's build.rs as in Makefile --- lib/binding_rust/build.rs | 4 +++- lib/src/subtree.c | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/binding_rust/build.rs b/lib/binding_rust/build.rs index 5798cde3..c812c3b9 100644 --- a/lib/binding_rust/build.rs +++ b/lib/binding_rust/build.rs @@ -26,7 +26,9 @@ fn main() { cc::Build::new() .flag_if_supported("-std=c99") - .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-fvisibility=hidden") + .flag_if_supported("-Wshadow") + .flag_if_supported("-Werror") .include(src_path) .include("include") .file(src_path.join("lib.c")) diff --git a/lib/src/subtree.c b/lib/src/subtree.c index 5f39bd82..51bc2ef6 100644 --- a/lib/src/subtree.c +++ b/lib/src/subtree.c @@ -647,10 +647,10 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, SubtreePool typedef struct { Subtree *tree; Edit edit; - } StackEntry; + } EditEntry; - Array(StackEntry) stack = array_new(); - array_push(&stack, ((StackEntry) { + Array(EditEntry) stack = array_new(); + array_push(&stack, ((EditEntry) { .tree = &self, .edit = (Edit) { .start = {input_edit->start_byte, input_edit->start_point}, @@ -660,7 +660,7 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, SubtreePool })); while (stack.size) { - StackEntry entry = array_pop(&stack); + EditEntry entry = array_pop(&stack); Edit edit = entry.edit; bool is_noop = edit.old_end.bytes == edit.start.bytes && edit.new_end.bytes == edit.start.bytes; bool is_pure_insertion = edit.old_end.bytes == edit.start.bytes; @@ -788,7 +788,7 @@ Subtree ts_subtree_edit(Subtree self, const TSInputEdit *input_edit, SubtreePool } // Queue processing of this child's subtree. - array_push(&stack, ((StackEntry) { + array_push(&stack, ((EditEntry) { .tree = child, .edit = child_edit, }));