Browse thread
Passing `string option' values between OCaml and C
- Christian Lindig
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 1998-08-29 (16:46) |
From: | Christian Lindig <lindig@i...> |
Subject: | Passing `string option' values between OCaml and C |
After reading the manual, the mailing list archive, and some OCaml C sources I'm still not sure how to read and build constructed values in C. Two functions in the OCaml C source that receive optional values act quite differently: weak_set() in byterun/weak.c tests for value el != 1 to recognize the Some case: #define None_val 1 #define Some_tag 0 /* type 'a option = None | Some of 'a * val set : 'a t -> int -> 'a option -> unit */ value weak_set (value ar, value n, value el) /* ML */ { ... if (el != None_val){ Modify (&Field (ar, offset), Field (el, 0)); } ... } win_create_process() in otherlibs/win32unix/createprocess.c on the other hand tests optional value env != Val_int(0) to do this: /* * win_create_process : string -> string -> string option -> * file_descr -> file_descr -> file_descr -> int */ value win_create_process_native(value cmd, value cmdline, value env, value fd1, value fd2, value fd3) { ... if (env != Val_int(0)) { envp = String_val(Field(env, 0)); } else { envp = NULL; } ... } Could someone explain the general way how to read and build constructed values in C using optional values as an example? Starting with some #defines derived from the OCaml type definition to nail down the tags seems a good starting point to me. Christian ------------------------------------------------------------------------------ Christian Lindig http: www.cs.tu-bs.de/softech/people/lindig mail: lindig@ips.cs.tu-bs.de phone: +49 531 391 7465 fax: +49 531 391 8140