Hugo Ferreira | 4 Nov 21:01
Favicon

Interfacing with C: array of integers as an ocaml string?

Hello,

I recall that the question has been discussed before,
but I cannot find the post. Maybe someone can point me
in the right direction?

I am attempting to interface with a C library. The
function I require fills in an array with integers.
I have coded the call so:

CAMLprim value camlidl_cudd_bdd_pick_one_cube(
         value _v_no)
{
   CAMLparam1(_v_no) ;
   bdd__t no; /*in*/
   char *cube;
   int result;
   int size;

   camlidl_cudd_node_ml2c(_v_no, &no);

   size = Cudd_ReadSize(no.man);
   printf("No of vars = %d\n", size);
   cube = malloc((size+1) * sizeof(char));
   cube[size] = 0 ;
   result = Cudd_bddPickOneCube(no.man,no.node,cube); <- call in question
   if (result!=1)
       { failwith("Bdd: pick cube failed!"); };

   for(int i = 0 ; i < size ; i++) {
(Continue reading)

Florent Monnier | 4 Nov 23:16
X-Face

Re: Interfacing with C: array of integers as an ocaml string?

> Hello,
>
> I recall that the question has been discussed before,
> but I cannot find the post. Maybe someone can point me
> in the right direction?
>
> I am attempting to interface with a C library. The
> function I require fills in an array with integers.
> I have coded the call so:
>
> CAMLprim value camlidl_cudd_bdd_pick_one_cube(
>          value _v_no)
> {
>    CAMLparam1(_v_no) ;
>    bdd__t no; /*in*/
>    char *cube;
>    int result;
>    int size;
>
>    camlidl_cudd_node_ml2c(_v_no, &no);
>
>    size = Cudd_ReadSize(no.man);
>    printf("No of vars = %d\n", size);
>    cube = malloc((size+1) * sizeof(char));
>    cube[size] = 0 ;
>    result = Cudd_bddPickOneCube(no.man,no.node,cube); <- call in question
>    if (result!=1)
>        { failwith("Bdd: pick cube failed!"); };
>
>    for(int i = 0 ; i < size ; i++) {
(Continue reading)

Hugo Ferreira | 5 Nov 10:10
Favicon

Re: Interfacing with C: array of integers as an ocaml string?

Hello,

First and foremost, appreciate the corrections and feedback.

Florent Monnier wrote:
>> Hello,
>>
>> I recall that the question has been discussed before,
>> but I cannot find the post. Maybe someone can point me
>> in the right direction?
>>
>> I am attempting to interface with a C library. The
>> function I require fills in an array with integers.
>> I have coded the call so:
>>
>> CAMLprim value camlidl_cudd_bdd_pick_one_cube(
>>          value _v_no)
>> {
>>    CAMLparam1(_v_no) ;
>>    bdd__t no; /*in*/
>>    char *cube;
>>    int result;
>>    int size;
>>
>>    camlidl_cudd_node_ml2c(_v_no, &no);
>>
>>    size = Cudd_ReadSize(no.man);
>>    printf("No of vars = %d\n", size);
>>    cube = malloc((size+1) * sizeof(char));
>>    cube[size] = 0 ;
(Continue reading)

Hugo Ferreira | 5 Nov 11:47
Favicon

DONE: Re: Interfacing with C: array of integers as an ocaml string?

Hello,

After some experimentation and reading up on
Florent Monnier's excellent tutorial [1] I have
the answers.

Thank you,
H.F.

[1] http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php

Hugo Ferreira wrote:
> Hello,
> 
> First and foremost, appreciate the corrections and feedback.
> 
> Florent Monnier wrote:
>>> Hello,
>>>
>>> I recall that the question has been discussed before,
>>> but I cannot find the post. Maybe someone can point me
>>> in the right direction?
>>>
>>> I am attempting to interface with a C library. The
>>> function I require fills in an array with integers.
>>> I have coded the call so:
>>>
>>> CAMLprim value camlidl_cudd_bdd_pick_one_cube(
>>>          value _v_no)
>>> {
(Continue reading)


Gmane