Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003994OCamlCamlIDLpublic2006-03-29 16:512011-12-17 09:27
Reportersmimram 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionwon't fix 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0003994: Incorrect handling of x arrays when x = float by CamlIDL
DescriptionHello,

I think there is a bug in camlidl. The code generated for an x array when the type x is float does not seem to be correct since it does not take the fact that x is float and therefore the elements of the array are not boxed.

For example consider the following idl file:

typedef double Real;
typedef [length_is(3)] double* DArray;
typedef [length_is(3)] Real* RArray;

The code generated for DArray is correct in the _ml2c_ and _c2ml_ functions (it knows that floats aren't boxed in float arrays) but the ones for RArray are wrong: they try to unbox the elements.

The identity Real = double is not used here whereas it should. In array.ml the check is namely only:

let is_float_type =
  function Type_float -> true | Type_double -> true | _ -> false

I know that I could replace all occurences of Real above by double. But:
1. it's a real-life example and it took me some time to understand what was not going on right,
2. it's nice to be able to change quickly Real from double to float,
3. for some reason, I could want Real to be an abstract type.

Thanks for your help.
Additional Informationtest.idl
--------

typedef double Real;

typedef [length_is(3)] double* DArray;

typedef [length_is(3)] Real* RArray;

==============================================
test.ml(i)
----------

(* File generated from darray.idl *)

type real = float
and dArray = float array
and rArray = real array

==============================================
test_stubs.c
------------

/* File generated from darray.idl */

#include <stddef.h>
#include <string.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/fail.h>
#include <caml/callback.h>
#ifdef Custom_tag
#include <caml/custom.h>
#include <caml/bigarray.h>
#endif
#include <caml/camlidlruntime.h>


#include "darray.h"

void camlidl_ml2c_darray_Real(value _v1, Real * _c2, camlidl_ctx _ctx)
{
  (*_c2) = Double_val(_v1);
}

value camlidl_c2ml_darray_Real(Real * _c2, camlidl_ctx _ctx)
{
value _v1;
  _v1 = copy_double((*_c2));
  return _v1;
}

void camlidl_ml2c_darray_DArray(value _v1, DArray * _c2, camlidl_ctx _ctx)
{
mlsize_t _c3;
mlsize_t _c4;
  _c3 = Wosize_val(_v1) / Double_wosize;
  (*_c2) = camlidl_malloc(_c3 * sizeof(double ), _ctx);
  for (_c4 = 0; _c4 < _c3; _c4++) {
    (*_c2)[_c4] = Double_field(_v1, _c4);
  }
}

value camlidl_c2ml_darray_DArray(DArray * _c2, camlidl_ctx _ctx)
{
value _v1;
mlsize_t _c3;
  _v1 = camlidl_alloc(3 * Double_wosize, Double_array_tag);
  for (_c3 = 0; _c3 < 3; _c3++) {
    Store_double_field(_v1, _c3, (*_c2)[_c3]);
  }
  return _v1;
}

void camlidl_ml2c_darray_RArray(value _v1, RArray * _c2, camlidl_ctx _ctx)
{
mlsize_t _c3;
mlsize_t _c4;
value _v5;
  _c3 = Wosize_val(_v1);
  (*_c2) = camlidl_malloc(_c3 * sizeof(Real ), _ctx);
  for (_c4 = 0; _c4 < _c3; _c4++) {
    _v5 = Field(_v1, _c4);
    camlidl_ml2c_darray_Real(_v5, &(*_c2)[_c4], _ctx);
  }
}

value camlidl_c2ml_darray_RArray(RArray * _c2, camlidl_ctx _ctx)
{
value _v1;
mlsize_t _c3;
value _v4;
  _v1 = camlidl_alloc(3, 0);
  Begin_root(_v1)
    for (_c3 = 0; _c3 < 3; _c3++) {
      _v4 = camlidl_c2ml_darray_Real(&(*_c2)[_c3], _ctx);
      modify(&Field(_v1, _c3), _v4);
    }
  End_roots()
  return _v1;
}
TagsNo tags attached.
Attached Filespatch file icon float-arrays.patch [^] (570 bytes) 2009-04-20 11:20 [Show Content]

- Relationships

-  Notes
(0004923)
db (reporter)
2009-04-20 11:21

The fix is trivial (see the attached file)
(0006348)
xleroy (administrator)
2011-12-17 09:27

I'm closing this PR because CamlIDL has been dormant since 2004. It now lives (or at least sleeps) on http://forge.ocamlcore.org/projects/camlidl/ [^] [^] . Anyone who still cares about CamlIDL after all these years is welcome to join the project on forge.ocamlcore.org and breathe some life in it.

- Issue History
Date Modified Username Field Change
2006-03-29 16:51 smimram New Issue
2006-08-29 17:42 doligez Status new => acknowledged
2009-04-20 11:20 db File Added: float-arrays.patch
2009-04-20 11:21 db Note Added: 0004923
2011-12-17 09:27 xleroy Note Added: 0006348
2011-12-17 09:27 xleroy Status acknowledged => closed
2011-12-17 09:27 xleroy Resolution open => won't fix


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker