caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* CamlIDL and string options.
@ 2000-02-23 17:54 David Brown
  2000-02-24 10:21 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: David Brown @ 2000-02-23 17:54 UTC (permalink / raw)
  To: caml-list

I'm trying to write a camlidl interface for a function that returns a
char *.  I want the ML result to be a string option.  If the returned
pointer is null, then return None, otherwise return the string it
points to in Some.

I can make it work, but only by writing my own c2ml routine:

value field_to_ml (one_field *_c2, camlidl_ctx _ctx)
{
  value _v1;
  value _v3;
  if ((*_c2) == NULL) {
    _v1 = Val_int(0);
  } else {
    _v3 = copy_string (*_c2);
    Begin_root(_v3)
      _v1 = camlidl_alloc_small(1, 0);
      Field(_v1, 0) = _v3;
    End_roots();
  }
  return _v1;
}

Ideally, I would like to be able to use another field to get the
length, but that function needs another argument that the interface
function gets as an argument.

--------------------------------------------------
In actuality, the function is more complicated than even this.  It
actually returns a char**.  There is a function available that returns
the number of char*'s in it.  There is another function that returns
the length of each char* (provided they aren't NULL).

The other possibility is that someone else has already written an
interface of MySQL, and I'm duplicating their effort.

Dave Brown



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: CamlIDL and string options.
  2000-02-23 17:54 CamlIDL and string options David Brown
@ 2000-02-24 10:21 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2000-02-24 10:21 UTC (permalink / raw)
  To: David Brown, caml-list

> I'm trying to write a camlidl interface for a function that returns a
> char *.  I want the ML result to be a string option.  If the returned
> pointer is null, then return None, otherwise return the string it
> points to in Some.
> 
> I can make it work, but only by writing my own c2ml routine

I'm afraid this is the only solution with the current CamlIDL.  C strings
([string] char *) are treated internally like a special case of arrays
([string] char []), and arrays are assumed not to be "NULL" pointers.

In particular, the "obvious" CamlIDL declaration [string,unique] char *
doesn't work because the "unique" attribute is ignored.  

I'll keep that in mind for future versions of CamlIDL.

> In actuality, the function is more complicated than even this.  It
> actually returns a char**.  There is a function available that returns
> the number of char*'s in it.  There is another function that returns
> the length of each char* (provided they aren't NULL).

It looks like you'll really have to write a specialized c2ml routine!
I'm willing to help; just send me (personally, not to the list) some
more details on the C API you're interfacing with.

> The other possibility is that someone else has already written an
> interface of MySQL, and I'm duplicating their effort.

The Caml Hump (http://caml.inria.fr/) lists some OCaml database bindings,
but none for MySQL.

- Xavier Leroy



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-02-24 14:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-23 17:54 CamlIDL and string options David Brown
2000-02-24 10:21 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).