From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 031E1BC57 for ; Sun, 22 Aug 2010 01:46:15 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjIEAF0CcExbeZiogWdsb2JhbACDF50dFQEBFiIiqSqRA4EigyJzBA X-IronPort-AV: E=Sophos;i="4.56,248,1280700000"; d="scan'208";a="55871427" Received: from quare.fr ([91.121.152.168]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 22 Aug 2010 01:46:15 +0200 Received: from ast-lambert-152-1-13-106.w82-124.abo.wanadoo.fr ([82.124.43.106] helo=[192.168.1.11]) by quare.fr with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1OmxlO-0008L4-HT; Sun, 22 Aug 2010 01:46:14 +0200 Subject: Re: [Caml-list] caml_copy_string From: Mathias Kende To: Jeffrey Barber Cc: caml-list@inria.fr In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Sun, 22 Aug 2010 01:46:07 +0200 Message-ID: <1282434367.988.11.camel@mathias-ens> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; ocaml:01 ffi:01 byte:01 ocaml:01 alloc:01 pointer:01 val:01 mathias:98 mathias:98 caml-list:01 strings:01 caml:02 caml:02 string:02 string:02 Le samedi 21 ao=C3=BBt 2010 =C3=A0 18:30 -0500, Jeffrey Barber a =C3=A9crit= : > Is there a way to get a string from C to OCaml without the > caml_copy_string > function, or is there a version that doesn't copy the string? There is no such function in the Caml FFI. You could write one yourself but then the string must have been specially allocated because you need to add a one word header to the string and maybe some byte at the end. So, if you have to exchange strings between OCaml and C, the easiest way is to always allocate them with the caml_alloc_string function. That way you can use the pointer returned by String_val in your C code and the string remains a valid Caml string (except caml does not use zero as the end of string and will stick to its allocated size). Mathias