generator: Fix implementation of FUUID for OCaml functions

This was implemented wrongly.  In the XDR protocol, UUIDs are fixed
buffers of length 32.  We can just use memcpy to copy from the OCaml
string to the UUID, but we have to ensure the string length returned
by OCaml is correct (if not we just assert, it's an internal error).

(It didn't even compile before, so we know it was never used).

(cherry picked from commit bcd6b3ec3a)
(cherry picked from commit 1b64c54b8a)
This commit is contained in:
Richard W.M. Jones
2025-04-16 13:19:17 +01:00
parent a3ac31c6dc
commit af2e259ff7

View File

@@ -611,6 +611,7 @@ let generate_daemon_caml_stubs () =
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <assert.h>
#include <caml/alloc.h>
#include <caml/callback.h>
@@ -646,9 +647,12 @@ let generate_daemon_caml_stubs () =
fun i ->
pr " v = Field (retv, %d);\n" i;
function
| n, (FString|FDevice|FUUID) ->
| n, (FString|FDevice) ->
pr " ret->%s = strdup (String_val (v));\n" n;
pr " if (ret->%s == NULL) return NULL;\n" n
| n, FUUID ->
pr " assert (caml_string_length (v) == sizeof ret->%s);\n" n;
pr " memcpy (ret->%s, String_val (v), sizeof ret->%s);\n" n n
| n, FBuffer ->
pr " ret->%s_len = caml_string_length (v);\n" n;
pr " ret->%s = strdup (String_val (v));\n" n;