Skip to content
Open
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
36 changes: 24 additions & 12 deletions src/bindings/lib/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,33 @@ static void finalize_tree(value v) {
}

static struct custom_operations tree_custom_ops = {
identifier : "tree handling",
finalize : finalize_tree,
compare : custom_compare_default,
hash : custom_hash_default,
serialize : custom_serialize_default,
deserialize : custom_deserialize_default
.identifier = "tree handling",
.finalize = finalize_tree,
.compare = custom_compare_default,
.hash = custom_hash_default,
.serialize = custom_serialize_default,
.deserialize = custom_deserialize_default,
#ifdef custom_compare_ext_default
.compare_ext = custom_compare_ext_default,
#endif
#ifdef custom_fixed_length_default
.fixed_length = custom_fixed_length_default,
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do the new fields under ifdefs come from? I expect this code to be copied from the original tree-sitter bindings for Reason. The project I found is oni2 and doesn't have the ifdefs: https://github.com/onivim/oni2/blob/161a92c2226728b37cd9a6f554b7397f4beb3d5e/src/reason-tree-sitter/bindings.c#L45-L61

Can you please include an authoritative source URL at the beginning of this file?

Copy link
Member

@mjambon mjambon Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also https://github.com/onivim/reason-tree-sitter/blob/master/src/bindings.c but the project was archived (and it also doesn't have the ifdefs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were introduced in OCaml 5.0, see caml/custom.h. Using the #ifdef allows the code to remain compatible with OCaml 4 (one could also use the OCAML_VERSION macro, but I find this pattern rather elegant). Some compilers in some settings complain if some fields are left uninitialized.

};

static struct custom_operations TSNode_custom_ops = {
identifier : "TSNode handling",
finalize : custom_finalize_default,
compare : custom_compare_default,
hash : custom_hash_default,
serialize : custom_serialize_default,
deserialize : custom_deserialize_default
.identifier = "TSNode handling",
.finalize = custom_finalize_default,
.compare = custom_compare_default,
.hash = custom_hash_default,
.serialize = custom_serialize_default,
.deserialize = custom_deserialize_default,
#ifdef custom_compare_ext_default
.compare_ext = custom_compare_ext_default,
#endif
#ifdef custom_fixed_length_default
.fixed_length = custom_fixed_length_default,
#endif
};

const char *octs_read(void *payload, uint32_t byte_offset, TSPoint position,
Expand Down