MCPcopy Create free account
hub / github.com/enthought/comtypes / ParseUnion

Method ParseUnion

comtypes/tools/tlbparser.py:545–576  ·  view source on GitHub ↗
(
        self, tinfo: typeinfo.ITypeInfo, ta: typeinfo.TYPEATTR
    )

Source from the content-addressed store, hash-verified

543
544 # TKIND_UNION = 7
545 def ParseUnion(
546 self, tinfo: typeinfo.ITypeInfo, ta: typeinfo.TYPEATTR
547 ) -> typedesc.Union:
548 union_name, doc, helpcntext, helpfile = tinfo.GetDocumentation(-1)
549 members = []
550 union = typedesc.Union(
551 union_name,
552 align=ta.cbAlignment * 8,
553 members=members,
554 bases=[],
555 size=ta.cbSizeInstance * 8,
556 )
557 self._register(union_name, union)
558
559 tlib, _ = tinfo.GetContainingTypeLib()
560 tlib_ta = tlib.GetLibAttr()
561 # If this is a 32-bit typlib being loaded in a 64-bit process, then the
562 # size and alignment are incorrect. Set the size to None to disable
563 # size checks and correct the alignment.
564 if is_64bits and tlib_ta.syskind == typeinfo.SYS_WIN32:
565 union.size = None
566 union.align = 64
567
568 for i in range(ta.cVars):
569 vd = tinfo.GetVarDesc(i)
570 name = tinfo.GetDocumentation(vd.memid)[0]
571 offset = vd._.oInst * 8
572 assert vd.varkind == typeinfo.VAR_PERINSTANCE
573 typ = self.make_type(vd.elemdescVar.tdesc, tinfo)
574 field = typedesc.Field(name, typ, None, offset) # bits
575 members.append(field)
576 return union
577
578 ################################################################
579

Callers 1

parse_typeinfoMethod · 0.95

Calls 7

_registerMethod · 0.95
make_typeMethod · 0.95
UnionMethod · 0.80
GetContainingTypeLibMethod · 0.80
GetLibAttrMethod · 0.80
GetVarDescMethod · 0.80
GetDocumentationMethod · 0.45

Tested by

no test coverage detected