Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000644OCamlCamlIDLpublic2001-11-20 18:372002-01-16 10:45
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000644: Camlidl: a problem with encapsulated union
DescriptionThe following .idl definitions

[---cut---]
typedef enum _SwitchType
{
   FLOAT_ARRAY = 1,
   DOUBLE_ARRAY = 2
} SwitchType;

typedef struct _Array
{
    int len;
    SwitchType type;
    [switch_is(type)] union
    {
        case FLOAT_ARRAY: [size_is(len)] float* fl;
        case DOUBLE_ARRAY: [size_is(len)] double* db;
    } data;
} Array;
[---cut---]

generate incorrect .c file:

[---cut---]
void camlidl_ml2c_union3_struct__Array(value _v1, struct _Array * _c2, camlidl_ctx _ctx)
{
  value _v3;
  value _v4;
  value _v5;
  mlsize_t _c6;
  mlsize_t _c7;
  value _v8;
  mlsize_t _c9;
  mlsize_t _c10;
  _v3 = Field(_v1, 0);
  (*_c2).len = Int_val(_v3);
  _v4 = Field(_v1, 1);
  switch (Tag_val(_v4)) {
  case 0: /* FLOAT_ARRAY */
    (*_c2).type = FLOAT_ARRAY;
    _v5 = Field(_v4, 0);
    _c6 = Wosize_val(_v5) / Double_wosize;
    (*_c2).data.fl = camlidl_malloc(_c6 * sizeof(float ), _ctx);
    for (_c7 = 0; _c7 < _c6; _c7++) {
      (*_c2).data.fl[_c7] = Double_field(_v5, _c7);
    }
    _badprefix.len = _c6;
    break;
  case 1: /* DOUBLE_ARRAY */
    (*_c2).type = DOUBLE_ARRAY;
    _v8 = Field(_v4, 0);
    _c9 = Wosize_val(_v8) / Double_wosize;
    (*_c2).data.db = camlidl_malloc(_c9 * sizeof(double ), _ctx);
    for (_c10 = 0; _c10 < _c9; _c10++) {
      (*_c2).data.db[_c10] = Double_field(_v8, _c10);
    }
    _badprefix.len = _c9;
    break;
  }
}
[---cut---]

Note _badprefix instead of (*_c2) in the body. It looks like a bug ... Is
any workaround possible?

Hope to hear from you soon,
Dmitry


TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000080)
administrator (administrator)
2002-01-16 10:44

> The following .idl definitions
>
> [---cut---]
> typedef enum _SwitchType
> {
> FLOAT_ARRAY = 1,
> DOUBLE_ARRAY = 2
> } SwitchType;
>
> typedef struct _Array
> {
> int len;
> SwitchType type;
> [switch_is(type)] union
> {
> case FLOAT_ARRAY: [size_is(len)] float* fl;
> case DOUBLE_ARRAY: [size_is(len)] double* db;
> } data;
> } Array;
> [---cut---]
>
> generate incorrect .c file:

Right. There was a serious limitation in CamlIDL, namely that
dependent variables (such as "len" above) could only be defined in the
current struct type. Moreover, code that does not comply with this
requirement wasn't detected. I have fixed this so that all variables
and struct fields that are in scope can be used as dependent
variables. This took a bit of work, but is much cleaner (and expressive).

- Xavier Leroy

(0000081)
administrator (administrator)
2002-01-16 10:45

Fixed 2002-01-16 by XL
(0000082)
administrator (administrator)
2002-01-26 13:33

Xavier Leroy <xavier.leroy@inria.fr> writes:

> Right. There was a serious limitation in CamlIDL, namely that
> dependent variables (such as "len" above) could only be defined in the
> current struct type. Moreover, code that does not comply with this
> requirement wasn't detected. I have fixed this so that all variables
> and struct fields that are in scope can be used as dependent
> variables. This took a bit of work, but is much cleaner (and
> expressive).

Good job! Thank you very much. Frankly speaking, then I submitted that bug
report, I was not sure that IDL permits using such non-local (but in-scope)
variables. For instance, MIDL does not allow that. But now it's possible
with CamlIDL, so I will submit the bug report to Microsoft VC team :-)

BTW, why CamlIDL accepts

typedef struct _Array
{
    int len;
    SwitchType type;
    [switch_is(type)] union
    {
        case FLOAT_ARRAY: [size_is(len)] float* fl;
        case DOUBLE_ARRAY: [size_is(len)] double* db;
    } data;
} Array;

but not

typedef struct _Array
{
    int len;
    union switch(SwitchType type)
    {
        case FLOAT_ARRAY: [size_is(len)] float* fl;
        case DOUBLE_ARRAY: [size_is(len)] double* db;
    } data;
} Array;

(function struct _Array: Illegal reference to dependent variable len. This
variable is not in scope.)?

Hope to hear from you soon,
Dmitry



- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker