Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camlidl: a problem with encapsulated union #3044

Closed
vicuna opened this issue Nov 20, 2001 · 3 comments
Closed

Camlidl: a problem with encapsulated union #3044

vicuna opened this issue Nov 20, 2001 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Nov 20, 2001

Original bug ID: 644
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: -for CamlIDL use https://github.com/xavierleroy/camlidl/issues

Bug description

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:

[---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

@vicuna
Copy link
Author

vicuna commented Jan 16, 2002

Comment author: administrator

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

@vicuna
Copy link
Author

vicuna commented Jan 16, 2002

Comment author: administrator

Fixed 2002-01-16 by XL

@vicuna vicuna closed this as completed Jan 16, 2002
@vicuna
Copy link
Author

vicuna commented Jan 26, 2002

Comment author: administrator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant