Open Bug 535378 Opened 15 years ago Updated 2 years ago

add union support to js-ctypes

Categories

(Core :: js-ctypes, defect, P3)

defect

Tracking

()

People

(Reporter: dwitte, Unassigned)

References

(Blocks 1 open bug)

Details

We'll want a ctypes.UnionType("my_union_t", ...) constructor, in much the same vein as ctypes.StructType. It can probably reuse much of the same code, the only difference being the method of computing member offsets. The API should be otherwise identical.
Depends on: 513788
P3, nice to have.
Priority: -- → P3
Is this something that's on the radar for Fx4?

We're spinning up the "general crypto API" concept in Labs again, and the additional NSS usage that's going to involve (over WeaveCrypto) is almost certainly going to need union support.
No immediate plans, but this would be pretty trivial to do.

Patches accepted!
This would be nice to have for calendar, we need this due to a union in libical. Is there a workaround for unions, or do I have to wait for/submit a patch?
You can always typecast pointers, at least as long as you know which type is the biggest.
I'm not sure but i think fieldName matters right?

So what im doing right now is pre-defining it based on what i need.

Having union would be real nice though, are their plans to bring support for it?

This is my pre-defining based on whether i need LPWSTR or BOOL: https://github.com/Noitidart/_scratchpad/blob/master/IPropertyStore%20COM%20jsctypes.js#L155

But by @bsmedberg's last reply, maybe setting this last field to `{ 'randomName': ctypes.voidptr_t }` and then doing ctypes.cast when i need to work with it. But the API's behind it won't run into trouble? As they'll see `randomName` as the field name instead of `pwszVal` or `boolVal`?
We may use [] to represent union.
For example:

 new StructType('_XPTTypeDescriptor', [
  { prefix: exports.XPTTypeDescriptorPrefix },
  { argnum: uint8_t },
  { argnum2: uint8_t },
  [
  { iface: uint16_t },
  { additional_type: uint16_t },
  ]
/*
    union {                         
        uint16_t iface;             // used for TD_INTERFACE_TYPE 
        uint16_t additional_type;   // used for TD_ARRAY
    } type;
  */
])
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.