Older versions of GCC (<4.9) and LLVM (<3.6) do not have __atomic_load_n
which is part of the C11 standard. Fix by falling back to
__sync_fetch_and_add with a value of 0 when __atomic_load_n is not
available.
Fixes#423
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit stops using the monotonic clock API on macOS because it is
supported only on macOS >= 10.12. Instead, it uses the fallback clock
APIs for platforms without monotonic clock support.
The use of `clock_gettime` was causing issues on Atom because, even
though we build it on a new macOS version supporting such API, some
users may run Atom on older versions of macOS. On those platforms, Atom
would crash whenever opening a file parsed with a tree-sitter grammar.
Historically, `free(3)`-style functions have been NULL-safe, to make
resource handling functions more robust. This doesn't seem to be the
case with tree-sitter's `ts_tree_delete` and `ts_parser_delete` C
functions, which immediately dereference the passed pointer. This
leads to complexity in client libraries that have to ensure that trees
and parsers are cleaned up correctly.
This patch adds NULL checks to `parse_delete` and `tree_delete`. They
should have negligable performance impacts, since null checks are fast.
I didn't change the internal _delete functions, as arguably those
being NULL-unsafe is a feature, not a bug.
When debugging a test with 'script/test -D', the DOT-graph generation
code was sometimes causing reallocations that were not captured by the
allocation tracker, because we explicitly disable allocation-tracking
for that method in order to reduce noise when debugging memory leaks.
By growing the relevant array *prior* to turning off allocation
tracking, we can ensure that it is not reallocated within that function,
avoiding false positive memory leak errors.
Fixes#302
This allows you to assert about fields in tests. But if your test
s-expression does *not* include fields, the fields will be stripped from
the regexp before comparison.