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 C3382BBAF for ; Sun, 22 Aug 2010 19:16:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhECAGv4cEzRVdivimdsb2JhbACDF49YjT4IFQEBAQoJDAcPBR+ePohcgk+FDIkCAQEDBYEdgyJzBIl2iEA X-IronPort-AV: E=Sophos;i="4.56,253,1280700000"; d="scan'208";a="55887996" Received: from mail-qy0-f175.google.com ([209.85.216.175]) by mail3-smtp-sop.national.inria.fr with ESMTP; 22 Aug 2010 19:16:45 +0200 Received: by qyk8 with SMTP id 8so2189812qyk.6 for ; Sun, 22 Aug 2010 10:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=WW9Z6vSsO+WwhjbLNGz4/WcTkKWPTs3MJaKHMXTO/lw=; b=UA1s4QK85HC2sd3TSFOPu7F9P1832BwRJfig0NjA1ZYPhxBCim1xlzq+qLQM55kMgO C7BL3hrRNcQuEV3QB7Mn7bJTV897X/paXFCPdqD92i1gZhZsD6Xg6acqCSMlsDdJ/g/A BPk1gU+hc8iPjgPbiupsmP+bEuY1gme2cr3aE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=OeAoqs0/Q+bi9YlXHLIECIdRF+dU3R7FTIzsrqfzohFas3yTJN3tBL6/h1RSDGny+h qfngjopPdyYEy9LMZri9EvSerJoDr9xjwSo634jfsh6+LQzQyRji9cWMUW1eFkPqnU95 R5LfL38N/I/GyCffhT1cMlEwE9pSNbiMl/+VQ= MIME-Version: 1.0 Received: by 10.224.10.211 with SMTP id q19mr58068qaq.394.1282497404411; Sun, 22 Aug 2010 10:16:44 -0700 (PDT) Sender: till.varoquaux@gmail.com Received: by 10.229.234.3 with HTTP; Sun, 22 Aug 2010 10:16:44 -0700 (PDT) In-Reply-To: <1282434367.988.11.camel@mathias-ens> References: <1282434367.988.11.camel@mathias-ens> Date: Sun, 22 Aug 2010 13:16:44 -0400 X-Google-Sender-Auth: VqL_aRbbHq6d57vUSVLh8IYX5ew Message-ID: Subject: Re: [Caml-list] caml_copy_string From: Till Varoquaux To: Mathias Kende Cc: Jeffrey Barber , caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; byterun:01 mlvalues:01 val:01 val:01 ocaml:01 ffi:01 byte:01 ocaml:01 alloc:01 pointer:01 beginner's:01 bug:01 mathias:98 mathias:98 char:01 In byterun/mlvalues.h #define Bp_val(v) ((char *) (v)) .... #define String_val(x) ((char *) Bp_val(x)) Doesn't look like String_val is doing much copying to me.... Till On Sat, Aug 21, 2010 at 7:46 PM, Mathias Kende wrote= : > Le samedi 21 ao=C3=BBt 2010 =C3=A0 18:30 -0500, Jeffrey Barber a =C3=A9cr= it : >> 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 > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >