Skip to content

Commit 7e87987

Browse files
committed
Simplify code
1 parent 7c041e3 commit 7e87987

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/core/IronPython.Modules/_ctypes/StructType.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -414,24 +414,21 @@ private int UpdateSizeAndAlignment(INativeType cdata, int? bitCount, ref INative
414414
if (_pack != null) throw new NotImplementedException("pack with bitfields"); // TODO: implement
415415

416416
if (UseMsvcBitfieldAlignmentRules) {
417-
if (totalBitCount != null) {
418-
// this bitfield is not the first field in the struct
419-
if (totalBitCount != null) { // there is already a bitfield container open
420-
// under the MSVC rules, only bitfields of type that has the same size/alignment, are packed into the same container unit
421-
if (lastType!.Size != cdata.Size || lastType.Alignment != cdata.Alignment) {
422-
// if the bitfield type is not compatible with the type of the previous container unit, close the previous container unit
423-
size += lastType.Size;
424-
fieldOffset = size = PythonStruct.Align(size, cdata.Alignment); // TODO: _pack
425-
totalBitCount = null;
426-
}
417+
if (totalBitCount != null) { // there is already a bitfield container open
418+
// under the MSVC rules, only bitfields of type that has the same size/alignment, are packed into the same container unit
419+
if (lastType!.Size != cdata.Size || lastType.Alignment != cdata.Alignment) {
420+
// if the bitfield type is not compatible with the type of the previous container unit, close the previous container unit
421+
size += lastType.Size;
422+
fieldOffset = size = PythonStruct.Align(size, cdata.Alignment); // TODO: _pack
423+
totalBitCount = null;
427424
}
428425
}
429426
if (totalBitCount != null) {
430427
// container unit open
431428
if ((bitCount + totalBitCount + 7) / 8 <= cdata.Size) {
432429
// new bitfield fits into the container unit
433430
fieldOffset = size;
434-
totalBitCount = bitCount + totalBitCount;
431+
totalBitCount += bitCount;
435432
} else {
436433
// new bitfield does not fit into the container unit, close it
437434
size += lastType!.Size;
@@ -485,7 +482,7 @@ private int UpdateSizeAndAlignment(INativeType cdata, int? bitCount, ref INative
485482
lastType = cdata;
486483
}
487484

488-
return fieldOffset; // this is the offset of the field or the container unit for the bitfield
485+
return fieldOffset;
489486
}
490487

491488

0 commit comments

Comments
 (0)