You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
it's a real-life example and it took me some time to understand what was not going on right,
it's nice to be able to change quickly Real from double to float,
for some reason, I could want Real to be an abstract type.
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.
Original bug ID: 3994
Reporter: smimram
Status: closed (set by @xavierleroy on 2011-12-17T08:27:38Z)
Resolution: won't fix
Priority: normal
Severity: major
Category: -for CamlIDL use https://github.com/xavierleroy/camlidl/issues
Monitored by: @hcarty smimram @db4
Bug description
Hello,
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:
Thanks for your help.
Additional information
test.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;
}
File attachments
The text was updated successfully, but these errors were encountered: