modification de camlidl

From: Patrick Goldbronn - SYSCO (patrick.goldbronn@cea.fr)
Date: Fri Jan 28 2000 - 11:48:11 MET

  • Next message: Stéphane Baubillier: "Partial Evaluation"

    Hello,

    I modified 2 features in camlidl.
    This is a very bad work but it's enough for me use :)
    Perhaps some could make better.

    In attachment : the modified files in camlidl !

    1 Adding a custom parameter in function translation :
    ===================================================
      For instance there are 2 label for quote mark : 'call' and 'dealloc'.
      I have added the label 'init' to add custom initialization sequence if
    there are variable like error code we don't want to see in caml function
    (perhaps there are another mean to do that in standard ?)

    Example :
      I have the C function :

      void NP_initialize(int argc, char **argv, int *err) ;

      and I want the caml function initialize in module Np :
      
      external initialize : string array -> unit

      so I write the idl file :

     void initialize( [in] int argc, [in,size_is(argc),string*] char **argv
    )
    quote(init,"
      int err=0;
    ")
    quote(call,"
      NP_initialize( argc, argv, &err );
      if(err != 0)
        failwith(\"Np.initialize : error \");
    ");

    I think this part is right :)

    2 Modifing the in,out tag :
    =========================

      When I pass an array to a function that modify the value in the array,
    I don't want a new array.
      This modification work only with array and if you want another type
    in,out you must add it :).
      I'm not sure it works with all array type and what it do exactly with
    any array : I use it with double and int array.

    Example :

    idl file :

    void get_vector_D( vector vec, int ideb, int size, int n,
                         [in,out,size_is(n)] double tab[], int root )
    quote(init,"
      int err=0;
    ")
    quote(call,"
      NP_get_vector_D (vec,ideb,size,tab,root,&err) ;
      if(err != 0)
        failwith(\"Np.get_vector_D : error \") ;
    ") ;

    generated C file :

    value camlidl_np_get_vector_D(
            value _v_vec,
            value _v_ideb,
            value _v_size,
            value _v_tab,
            value _v_root)
    {
      vector vec; /*in*/
      int ideb; /*in*/
      int size; /*in*/
      int n; /*in*/
      double *tab; /*in,out*/
      int root; /*in*/
      mlsize_t _c1;
      mlsize_t _c2;
      mlsize_t _c3;
      struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL };
      camlidl_ctx _ctx = &_ctxs;
    /* begin user-supplied initialization sequence */

      int err=0;

    /* end user-supplied initialization sequence */
      camlidl_ml2c_np_vector(_v_vec, &vec, _ctx);
      ideb = Int_val(_v_ideb);
      size = Int_val(_v_size);
      _c1 = Wosize_val(_v_tab) / Double_wosize;
      tab = camlidl_malloc(_c1 * sizeof(double ), _ctx);
      for (_c2 = 0; _c2 < _c1; _c2++) {
        tab[_c2] = Double_field(_v_tab, _c2);
      }
      n = _c1;
      root = Int_val(_v_root);
      /* begin user-supplied calling sequence */

      NP_get_vector_D (vec,ideb,size,tab,root,&err) ;
      if(err != 0)
        failwith("Np.get_vector_D : error ") ;

      /* end user-supplied calling sequence */
      /* begin of InOut values */
      for (_c3 = 0; _c3 < n; _c3++) {
        Store_double_field(_v_tab, _c3, tab[_c3]);
      }
      /* end of InOut values */
      camlidl_free(_ctx);
      return Val_unit;
    }

    genereted ocaml file :

    external get_vector_D : vector -> int -> int -> float array -> int ->
    unit
            = "camlidl_np_get_vector_D"

    -- 
    #####################################
    # Patrick GOLDBRONN                 #
    # CEA - DRN/DMT/SYSCO               #
    # CE-Saclay, Bâtiment 460           #
    # 91191 GIF/YVETTE CEDEX (FRANCE)   #
    #                                   #
    # Tél : 01 69 08 73 55              #
    # Fax : 01 69 08 96 96              #
    #####################################
    



    This archive was generated by hypermail 2b29 : Fri Jan 28 2000 - 17:46:04 MET