add union support to js-ctypes




8 years ago
2 years ago


(Reporter:, Unassigned)



Firefox Tracking Flags

(Not tracked)




8 years ago
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.


8 years ago
Depends on: 513788

Comment 1

8 years ago
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.

Comment 3

8 years ago
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?

Comment 5

7 years ago
You can always typecast pointers, at least as long as you know which type is the biggest.

Comment 6

3 years ago
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:

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`?

Comment 7

2 years ago
We may use [] to represent union.

Comment 8

2 years ago
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;
You need to log in before you can comment on or make changes to this bug.