summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-03-01 11:07:53 -0600
committerGitHub <noreply@github.com>2022-03-01 11:07:53 -0600
commit2f90f3c5abfd2f28b4888833ff33b1914adfc75c (patch)
tree66a5915cbc6cd8eb50d1871bd711dea5c3e13974
parent428a0ad258a7198edee0eced1023049fdc858b93 (diff)
parentee296ca445452d6a5021144cd8747d1456ae315e (diff)
downloadlibvyosconfig-2f90f3c5abfd2f28b4888833ff33b1914adfc75c.tar.gz
libvyosconfig-2f90f3c5abfd2f28b4888833ff33b1914adfc75c.zip
Merge pull request #4 from jestabro/subtree
T4235: bindings for modified return value of diff_tree, and for get_subtree
-rw-r--r--lib/bindings.ml32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/bindings.ml b/lib/bindings.ml
index 484a5d7..d9d2051 100644
--- a/lib/bindings.ml
+++ b/lib/bindings.ml
@@ -116,6 +116,12 @@ let is_tag c_ptr path =
let path = split_on_whitespace path in
if (CT.is_tag ct path) then 1 else 0
+let get_subtree c_ptr path with_node =
+ let ct = Root.get c_ptr in
+ let path = split_on_whitespace path in
+ let subt = CT.get_subtree ~with_node:with_node ct path in
+ Ctypes.Root.create subt
+
let exists c_ptr path =
let ct = Root.get c_ptr in
let path = split_on_whitespace path in
@@ -159,20 +165,26 @@ let copy_node c_ptr old_path new_path =
0
with Vytree.Nonexistent_path -> 1
-let diffs path c_ptr_l c_ptr_r =
+let diff_tree path c_ptr_l c_ptr_r =
let path = split_on_whitespace path in
let ct_l = Root.get c_ptr_l in
let ct_r = Root.get c_ptr_r in
try
- let ct_add, ct_del, ct_inter = CD.diffs path ct_l ct_r in
- let ptr_add = Ctypes.Root.create ct_add in
- let ptr_del = Ctypes.Root.create ct_del in
- let ptr_inter = Ctypes.Root.create ct_inter in
- let ptr_arr = Ctypes.CArray.make (ptr void) ~initial:ptr_add 3 in Ctypes.CArray.set ptr_arr 1 ptr_del; Ctypes.CArray.set ptr_arr 2 ptr_inter; Ctypes.CArray.start ptr_arr
+ let ct_ret = CD.diff_tree path ct_l ct_r in
+ Ctypes.Root.create ct_ret
+ with
+ | CD.Incommensurable -> error_message := "Incommensurable"; Ctypes.null
+ | CD.Empty_comparison -> error_message := "Empty comparison"; Ctypes.null
+let trim_tree c_ptr_l c_ptr_r =
+ let ct_l = Root.get c_ptr_l in
+ let ct_r = Root.get c_ptr_r in
+ try
+ let ct_ret = CD.trim_tree ct_l ct_r in
+ Ctypes.Root.create ct_ret
with
- | CD.Incommensurable -> error_message := "Incommensurable"; Ctypes.CArray.start (Ctypes.CArray.make (ptr void) 3)
- | CD.Empty_comparison -> error_message := "Empty comparison"; Ctypes.CArray.start (Ctypes.CArray.make (ptr void) 3)
+ | CD.Incommensurable -> error_message := "Incommensurable"; Ctypes.null
+ | CD.Empty_comparison -> error_message := "Empty comparison"; Ctypes.null
module Stubs(I : Cstubs_inverted.INTERNAL) =
struct
@@ -194,9 +206,11 @@ struct
let () = I.internal "copy_node" ((ptr void) @-> string @-> string @-> returning int) copy_node
let () = I.internal "set_tag" ((ptr void) @-> string @-> returning int) set_tag
let () = I.internal "is_tag" ((ptr void) @-> string @-> returning int) is_tag
+ let () = I.internal "get_subtree" ((ptr void) @-> string @-> bool @-> returning (ptr void)) get_subtree
let () = I.internal "exists" ((ptr void) @-> string @-> returning int) exists
let () = I.internal "list_nodes" ((ptr void) @-> string @-> returning string) list_nodes
let () = I.internal "return_value" ((ptr void) @-> string @-> returning string) return_value
let () = I.internal "return_values" ((ptr void) @-> string @-> returning string) return_values
- let () = I.internal "diffs" (string @-> (ptr void) @-> (ptr void) @-> returning (ptr (ptr void))) diffs
+ let () = I.internal "diff_tree" (string @-> (ptr void) @-> (ptr void) @-> returning (ptr void)) diff_tree
+ let () = I.internal "trim_tree" ((ptr void) @-> (ptr void) @-> returning (ptr void)) trim_tree
end