[llvm] [OCaml] Use DataLayout instead of string in (set_)data_layout (PR #228445)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 3 04:03:22 PDT 2026
================
@@ -58,6 +58,7 @@ void *from_val_array(value Elements);
#define Use_val(v) ((LLVMUseRef)from_val(v))
#define BasicBlock_val(v) ((LLVMBasicBlockRef)from_val(v))
#define MemoryBuffer_val(v) ((LLVMMemoryBufferRef)from_val(v))
+#define DataLayout_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
----------------
nikic wrote:
This macro is just moved from the implementation to the header.
I *think* the reason why this one is using Data_custom_val is that DataLayout is managed as a "custom block" in https://github.com/nikic/llvm-project/blob/c99d6bd7f60cf18a3234fe87c7fd6cd61bf4dfb4/llvm/bindings/ocaml/llvm/llvm_ocaml.c#L2787-L2798
And I think the reason for that is so that resource management of DataLayout is automatic? I.e. the finalizer will free the DataLayout allocation, rather than requiring an explicit dispose call (if it's not part of some other structure that handles the resource management).
https://github.com/llvm/llvm-project/pull/228445
More information about the llvm-commits
mailing list